1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
50 #include "gdb-demangle.h"
51 #include "filenames.h" /* for DOSish file names */
53 #include "complaints.h"
54 #include "dwarf2/expr.h"
55 #include "dwarf2/loc.h"
56 #include "cp-support.h"
62 #include "typeprint.h"
67 #include "gdbcore.h" /* for gnutarget */
68 #include "gdb/gdb-index.h"
73 #include "namespace.h"
74 #include "gdbsupport/function-view.h"
75 #include "gdbsupport/gdb_optional.h"
76 #include "gdbsupport/underlying.h"
77 #include "gdbsupport/hash_enum.h"
78 #include "filename-seen-cache.h"
82 #include <unordered_map>
83 #include "gdbsupport/selftest.h"
84 #include "rust-lang.h"
85 #include "gdbsupport/pathstuff.h"
86 #include "count-one-bits.h"
87 #include "debuginfod-support.h"
89 /* When == 1, print basic high level tracing messages.
90 When > 1, be more verbose.
91 This is in contrast to the low level DIE reading of dwarf_die_debug. */
92 static unsigned int dwarf_read_debug
= 0;
94 /* When non-zero, dump DIEs after they are read in. */
95 static unsigned int dwarf_die_debug
= 0;
97 /* When non-zero, dump line number entries as they are read in. */
98 unsigned int dwarf_line_debug
= 0;
100 /* When true, cross-check physname against demangler. */
101 static bool check_physname
= false;
103 /* When true, do not reject deprecated .gdb_index sections. */
104 static bool use_deprecated_index_sections
= false;
106 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
108 /* The "aclass" indices for various kinds of computed DWARF symbols. */
110 static int dwarf2_locexpr_index
;
111 static int dwarf2_loclist_index
;
112 static int dwarf2_locexpr_block_index
;
113 static int dwarf2_loclist_block_index
;
115 /* An index into a (C++) symbol name component in a symbol name as
116 recorded in the mapped_index's symbol table. For each C++ symbol
117 in the symbol table, we record one entry for the start of each
118 component in the symbol in a table of name components, and then
119 sort the table, in order to be able to binary search symbol names,
120 ignoring leading namespaces, both completion and regular look up.
121 For example, for symbol "A::B::C", we'll have an entry that points
122 to "A::B::C", another that points to "B::C", and another for "C".
123 Note that function symbols in GDB index have no parameter
124 information, just the function/method names. You can convert a
125 name_component to a "const char *" using the
126 'mapped_index::symbol_name_at(offset_type)' method. */
128 struct name_component
130 /* Offset in the symbol name where the component starts. Stored as
131 a (32-bit) offset instead of a pointer to save memory and improve
132 locality on 64-bit architectures. */
133 offset_type name_offset
;
135 /* The symbol's index in the symbol and constant pool tables of a
140 /* Base class containing bits shared by both .gdb_index and
141 .debug_name indexes. */
143 struct mapped_index_base
145 mapped_index_base () = default;
146 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
148 /* The name_component table (a sorted vector). See name_component's
149 description above. */
150 std::vector
<name_component
> name_components
;
152 /* How NAME_COMPONENTS is sorted. */
153 enum case_sensitivity name_components_casing
;
155 /* Return the number of names in the symbol table. */
156 virtual size_t symbol_name_count () const = 0;
158 /* Get the name of the symbol at IDX in the symbol table. */
159 virtual const char *symbol_name_at (offset_type idx
) const = 0;
161 /* Return whether the name at IDX in the symbol table should be
163 virtual bool symbol_name_slot_invalid (offset_type idx
) const
168 /* Build the symbol name component sorted vector, if we haven't
170 void build_name_components ();
172 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
173 possible matches for LN_NO_PARAMS in the name component
175 std::pair
<std::vector
<name_component
>::const_iterator
,
176 std::vector
<name_component
>::const_iterator
>
177 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
178 enum language lang
) const;
180 /* Prevent deleting/destroying via a base class pointer. */
182 ~mapped_index_base() = default;
185 /* A description of the mapped index. The file format is described in
186 a comment by the code that writes the index. */
187 struct mapped_index final
: public mapped_index_base
189 /* A slot/bucket in the symbol table hash. */
190 struct symbol_table_slot
192 const offset_type name
;
193 const offset_type vec
;
196 /* Index data format version. */
199 /* The address table data. */
200 gdb::array_view
<const gdb_byte
> address_table
;
202 /* The symbol table, implemented as a hash table. */
203 gdb::array_view
<symbol_table_slot
> symbol_table
;
205 /* A pointer to the constant pool. */
206 const char *constant_pool
= nullptr;
208 bool symbol_name_slot_invalid (offset_type idx
) const override
210 const auto &bucket
= this->symbol_table
[idx
];
211 return bucket
.name
== 0 && bucket
.vec
== 0;
214 /* Convenience method to get at the name of the symbol at IDX in the
216 const char *symbol_name_at (offset_type idx
) const override
217 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
219 size_t symbol_name_count () const override
220 { return this->symbol_table
.size (); }
223 /* A description of the mapped .debug_names.
224 Uninitialized map has CU_COUNT 0. */
225 struct mapped_debug_names final
: public mapped_index_base
227 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
228 : dwarf2_per_objfile (dwarf2_per_objfile_
)
231 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
232 bfd_endian dwarf5_byte_order
;
233 bool dwarf5_is_dwarf64
;
234 bool augmentation_is_gdb
;
236 uint32_t cu_count
= 0;
237 uint32_t tu_count
, bucket_count
, name_count
;
238 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
239 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
240 const gdb_byte
*name_table_string_offs_reordered
;
241 const gdb_byte
*name_table_entry_offs_reordered
;
242 const gdb_byte
*entry_pool
;
249 /* Attribute name DW_IDX_*. */
252 /* Attribute form DW_FORM_*. */
255 /* Value if FORM is DW_FORM_implicit_const. */
256 LONGEST implicit_const
;
258 std::vector
<attr
> attr_vec
;
261 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
263 const char *namei_to_name (uint32_t namei
) const;
265 /* Implementation of the mapped_index_base virtual interface, for
266 the name_components cache. */
268 const char *symbol_name_at (offset_type idx
) const override
269 { return namei_to_name (idx
); }
271 size_t symbol_name_count () const override
272 { return this->name_count
; }
275 /* See dwarf2read.h. */
278 get_dwarf2_per_objfile (struct objfile
*objfile
)
280 return dwarf2_objfile_data_key
.get (objfile
);
283 /* Default names of the debugging sections. */
285 /* Note that if the debugging section has been compressed, it might
286 have a name like .zdebug_info. */
288 static const struct dwarf2_debug_sections dwarf2_elf_names
=
290 { ".debug_info", ".zdebug_info" },
291 { ".debug_abbrev", ".zdebug_abbrev" },
292 { ".debug_line", ".zdebug_line" },
293 { ".debug_loc", ".zdebug_loc" },
294 { ".debug_loclists", ".zdebug_loclists" },
295 { ".debug_macinfo", ".zdebug_macinfo" },
296 { ".debug_macro", ".zdebug_macro" },
297 { ".debug_str", ".zdebug_str" },
298 { ".debug_str_offsets", ".zdebug_str_offsets" },
299 { ".debug_line_str", ".zdebug_line_str" },
300 { ".debug_ranges", ".zdebug_ranges" },
301 { ".debug_rnglists", ".zdebug_rnglists" },
302 { ".debug_types", ".zdebug_types" },
303 { ".debug_addr", ".zdebug_addr" },
304 { ".debug_frame", ".zdebug_frame" },
305 { ".eh_frame", NULL
},
306 { ".gdb_index", ".zgdb_index" },
307 { ".debug_names", ".zdebug_names" },
308 { ".debug_aranges", ".zdebug_aranges" },
312 /* List of DWO/DWP sections. */
314 static const struct dwop_section_names
316 struct dwarf2_section_names abbrev_dwo
;
317 struct dwarf2_section_names info_dwo
;
318 struct dwarf2_section_names line_dwo
;
319 struct dwarf2_section_names loc_dwo
;
320 struct dwarf2_section_names loclists_dwo
;
321 struct dwarf2_section_names macinfo_dwo
;
322 struct dwarf2_section_names macro_dwo
;
323 struct dwarf2_section_names str_dwo
;
324 struct dwarf2_section_names str_offsets_dwo
;
325 struct dwarf2_section_names types_dwo
;
326 struct dwarf2_section_names cu_index
;
327 struct dwarf2_section_names tu_index
;
331 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
332 { ".debug_info.dwo", ".zdebug_info.dwo" },
333 { ".debug_line.dwo", ".zdebug_line.dwo" },
334 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
335 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
336 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
337 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
338 { ".debug_str.dwo", ".zdebug_str.dwo" },
339 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
340 { ".debug_types.dwo", ".zdebug_types.dwo" },
341 { ".debug_cu_index", ".zdebug_cu_index" },
342 { ".debug_tu_index", ".zdebug_tu_index" },
345 /* local data types */
347 /* Type used for delaying computation of method physnames.
348 See comments for compute_delayed_physnames. */
349 struct delayed_method_info
351 /* The type to which the method is attached, i.e., its parent class. */
354 /* The index of the method in the type's function fieldlists. */
357 /* The index of the method in the fieldlist. */
360 /* The name of the DIE. */
363 /* The DIE associated with this method. */
364 struct die_info
*die
;
367 /* Internal state when decoding a particular compilation unit. */
370 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
373 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
375 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
376 Create the set of symtabs used by this TU, or if this TU is sharing
377 symtabs with another TU and the symtabs have already been created
378 then restore those symtabs in the line header.
379 We don't need the pc/line-number mapping for type units. */
380 void setup_type_unit_groups (struct die_info
*die
);
382 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
383 buildsym_compunit constructor. */
384 struct compunit_symtab
*start_symtab (const char *name
,
385 const char *comp_dir
,
388 /* Reset the builder. */
389 void reset_builder () { m_builder
.reset (); }
391 /* The header of the compilation unit. */
392 struct comp_unit_head header
{};
394 /* Base address of this compilation unit. */
395 CORE_ADDR base_address
= 0;
397 /* Non-zero if base_address has been set. */
400 /* The language we are debugging. */
401 enum language language
= language_unknown
;
402 const struct language_defn
*language_defn
= nullptr;
404 const char *producer
= nullptr;
407 /* The symtab builder for this CU. This is only non-NULL when full
408 symbols are being read. */
409 std::unique_ptr
<buildsym_compunit
> m_builder
;
412 /* The generic symbol table building routines have separate lists for
413 file scope symbols and all all other scopes (local scopes). So
414 we need to select the right one to pass to add_symbol_to_list().
415 We do it by keeping a pointer to the correct list in list_in_scope.
417 FIXME: The original dwarf code just treated the file scope as the
418 first local scope, and all other local scopes as nested local
419 scopes, and worked fine. Check to see if we really need to
420 distinguish these in buildsym.c. */
421 struct pending
**list_in_scope
= nullptr;
423 /* Hash table holding all the loaded partial DIEs
424 with partial_die->offset.SECT_OFF as hash. */
425 htab_t partial_dies
= nullptr;
427 /* Storage for things with the same lifetime as this read-in compilation
428 unit, including partial DIEs. */
429 auto_obstack comp_unit_obstack
;
431 /* When multiple dwarf2_cu structures are living in memory, this field
432 chains them all together, so that they can be released efficiently.
433 We will probably also want a generation counter so that most-recently-used
434 compilation units are cached... */
435 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
437 /* Backlink to our per_cu entry. */
438 struct dwarf2_per_cu_data
*per_cu
;
440 /* How many compilation units ago was this CU last referenced? */
443 /* A hash table of DIE cu_offset for following references with
444 die_info->offset.sect_off as hash. */
445 htab_t die_hash
= nullptr;
447 /* Full DIEs if read in. */
448 struct die_info
*dies
= nullptr;
450 /* A set of pointers to dwarf2_per_cu_data objects for compilation
451 units referenced by this one. Only set during full symbol processing;
452 partial symbol tables do not have dependencies. */
453 htab_t dependencies
= nullptr;
455 /* Header data from the line table, during full symbol processing. */
456 struct line_header
*line_header
= nullptr;
457 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
458 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
459 this is the DW_TAG_compile_unit die for this CU. We'll hold on
460 to the line header as long as this DIE is being processed. See
461 process_die_scope. */
462 die_info
*line_header_die_owner
= nullptr;
464 /* A list of methods which need to have physnames computed
465 after all type information has been read. */
466 std::vector
<delayed_method_info
> method_list
;
468 /* To be copied to symtab->call_site_htab. */
469 htab_t call_site_htab
= nullptr;
471 /* Non-NULL if this CU came from a DWO file.
472 There is an invariant here that is important to remember:
473 Except for attributes copied from the top level DIE in the "main"
474 (or "stub") file in preparation for reading the DWO file
475 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
476 Either there isn't a DWO file (in which case this is NULL and the point
477 is moot), or there is and either we're not going to read it (in which
478 case this is NULL) or there is and we are reading it (in which case this
480 struct dwo_unit
*dwo_unit
= nullptr;
482 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
483 Note this value comes from the Fission stub CU/TU's DIE. */
484 gdb::optional
<ULONGEST
> addr_base
;
486 /* The DW_AT_rnglists_base attribute if present.
487 Note this value comes from the Fission stub CU/TU's DIE.
488 Also note that the value is zero in the non-DWO case so this value can
489 be used without needing to know whether DWO files are in use or not.
490 N.B. This does not apply to DW_AT_ranges appearing in
491 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
492 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
493 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
494 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
495 ULONGEST ranges_base
= 0;
497 /* When reading debug info generated by older versions of rustc, we
498 have to rewrite some union types to be struct types with a
499 variant part. This rewriting must be done after the CU is fully
500 read in, because otherwise at the point of rewriting some struct
501 type might not have been fully processed. So, we keep a list of
502 all such types here and process them after expansion. */
503 std::vector
<struct type
*> rust_unions
;
505 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
506 files, the value is implicitly zero. For DWARF 5 version DWO files, the
507 value is often implicit and is the size of the header of
508 .debug_str_offsets section (8 or 4, depending on the address size). */
509 gdb::optional
<ULONGEST
> str_offsets_base
;
511 /* Mark used when releasing cached dies. */
514 /* This CU references .debug_loc. See the symtab->locations_valid field.
515 This test is imperfect as there may exist optimized debug code not using
516 any location list and still facing inlining issues if handled as
517 unoptimized code. For a future better test see GCC PR other/32998. */
518 bool has_loclist
: 1;
520 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
521 if all the producer_is_* fields are valid. This information is cached
522 because profiling CU expansion showed excessive time spent in
523 producer_is_gxx_lt_4_6. */
524 bool checked_producer
: 1;
525 bool producer_is_gxx_lt_4_6
: 1;
526 bool producer_is_gcc_lt_4_3
: 1;
527 bool producer_is_icc
: 1;
528 bool producer_is_icc_lt_14
: 1;
529 bool producer_is_codewarrior
: 1;
531 /* When true, the file that we're processing is known to have
532 debugging info for C++ namespaces. GCC 3.3.x did not produce
533 this information, but later versions do. */
535 bool processing_has_namespace_info
: 1;
537 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
539 /* If this CU was inherited by another CU (via specification,
540 abstract_origin, etc), this is the ancestor CU. */
543 /* Get the buildsym_compunit for this CU. */
544 buildsym_compunit
*get_builder ()
546 /* If this CU has a builder associated with it, use that. */
547 if (m_builder
!= nullptr)
548 return m_builder
.get ();
550 /* Otherwise, search ancestors for a valid builder. */
551 if (ancestor
!= nullptr)
552 return ancestor
->get_builder ();
558 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
559 This includes type_unit_group and quick_file_names. */
561 struct stmt_list_hash
563 /* The DWO unit this table is from or NULL if there is none. */
564 struct dwo_unit
*dwo_unit
;
566 /* Offset in .debug_line or .debug_line.dwo. */
567 sect_offset line_sect_off
;
570 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
571 an object of this type. */
573 struct type_unit_group
575 /* dwarf2read.c's main "handle" on a TU symtab.
576 To simplify things we create an artificial CU that "includes" all the
577 type units using this stmt_list so that the rest of the code still has
578 a "per_cu" handle on the symtab. */
579 struct dwarf2_per_cu_data per_cu
;
581 /* The TUs that share this DW_AT_stmt_list entry.
582 This is added to while parsing type units to build partial symtabs,
583 and is deleted afterwards and not used again. */
584 std::vector
<signatured_type
*> *tus
;
586 /* The compunit symtab.
587 Type units in a group needn't all be defined in the same source file,
588 so we create an essentially anonymous symtab as the compunit symtab. */
589 struct compunit_symtab
*compunit_symtab
;
591 /* The data used to construct the hash key. */
592 struct stmt_list_hash hash
;
594 /* The symbol tables for this TU (obtained from the files listed in
596 WARNING: The order of entries here must match the order of entries
597 in the line header. After the first TU using this type_unit_group, the
598 line header for the subsequent TUs is recreated from this. This is done
599 because we need to use the same symtabs for each TU using the same
600 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
601 there's no guarantee the line header doesn't have duplicate entries. */
602 struct symtab
**symtabs
;
605 /* These sections are what may appear in a (real or virtual) DWO file. */
609 struct dwarf2_section_info abbrev
;
610 struct dwarf2_section_info line
;
611 struct dwarf2_section_info loc
;
612 struct dwarf2_section_info loclists
;
613 struct dwarf2_section_info macinfo
;
614 struct dwarf2_section_info macro
;
615 struct dwarf2_section_info str
;
616 struct dwarf2_section_info str_offsets
;
617 /* In the case of a virtual DWO file, these two are unused. */
618 struct dwarf2_section_info info
;
619 std::vector
<dwarf2_section_info
> types
;
622 /* CUs/TUs in DWP/DWO files. */
626 /* Backlink to the containing struct dwo_file. */
627 struct dwo_file
*dwo_file
;
629 /* The "id" that distinguishes this CU/TU.
630 .debug_info calls this "dwo_id", .debug_types calls this "signature".
631 Since signatures came first, we stick with it for consistency. */
634 /* The section this CU/TU lives in, in the DWO file. */
635 struct dwarf2_section_info
*section
;
637 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
638 sect_offset sect_off
;
641 /* For types, offset in the type's DIE of the type defined by this TU. */
642 cu_offset type_offset_in_tu
;
645 /* include/dwarf2.h defines the DWP section codes.
646 It defines a max value but it doesn't define a min value, which we
647 use for error checking, so provide one. */
649 enum dwp_v2_section_ids
654 /* Data for one DWO file.
656 This includes virtual DWO files (a virtual DWO file is a DWO file as it
657 appears in a DWP file). DWP files don't really have DWO files per se -
658 comdat folding of types "loses" the DWO file they came from, and from
659 a high level view DWP files appear to contain a mass of random types.
660 However, to maintain consistency with the non-DWP case we pretend DWP
661 files contain virtual DWO files, and we assign each TU with one virtual
662 DWO file (generally based on the line and abbrev section offsets -
663 a heuristic that seems to work in practice). */
667 dwo_file () = default;
668 DISABLE_COPY_AND_ASSIGN (dwo_file
);
670 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
671 For virtual DWO files the name is constructed from the section offsets
672 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
673 from related CU+TUs. */
674 const char *dwo_name
= nullptr;
676 /* The DW_AT_comp_dir attribute. */
677 const char *comp_dir
= nullptr;
679 /* The bfd, when the file is open. Otherwise this is NULL.
680 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
681 gdb_bfd_ref_ptr dbfd
;
683 /* The sections that make up this DWO file.
684 Remember that for virtual DWO files in DWP V2, these are virtual
685 sections (for lack of a better name). */
686 struct dwo_sections sections
{};
688 /* The CUs in the file.
689 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
690 an extension to handle LLVM's Link Time Optimization output (where
691 multiple source files may be compiled into a single object/dwo pair). */
694 /* Table of TUs in the file.
695 Each element is a struct dwo_unit. */
699 /* These sections are what may appear in a DWP file. */
703 /* These are used by both DWP version 1 and 2. */
704 struct dwarf2_section_info str
;
705 struct dwarf2_section_info cu_index
;
706 struct dwarf2_section_info tu_index
;
708 /* These are only used by DWP version 2 files.
709 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
710 sections are referenced by section number, and are not recorded here.
711 In DWP version 2 there is at most one copy of all these sections, each
712 section being (effectively) comprised of the concatenation of all of the
713 individual sections that exist in the version 1 format.
714 To keep the code simple we treat each of these concatenated pieces as a
715 section itself (a virtual section?). */
716 struct dwarf2_section_info abbrev
;
717 struct dwarf2_section_info info
;
718 struct dwarf2_section_info line
;
719 struct dwarf2_section_info loc
;
720 struct dwarf2_section_info macinfo
;
721 struct dwarf2_section_info macro
;
722 struct dwarf2_section_info str_offsets
;
723 struct dwarf2_section_info types
;
726 /* These sections are what may appear in a virtual DWO file in DWP version 1.
727 A virtual DWO file is a DWO file as it appears in a DWP file. */
729 struct virtual_v1_dwo_sections
731 struct dwarf2_section_info abbrev
;
732 struct dwarf2_section_info line
;
733 struct dwarf2_section_info loc
;
734 struct dwarf2_section_info macinfo
;
735 struct dwarf2_section_info macro
;
736 struct dwarf2_section_info str_offsets
;
737 /* Each DWP hash table entry records one CU or one TU.
738 That is recorded here, and copied to dwo_unit.section. */
739 struct dwarf2_section_info info_or_types
;
742 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
743 In version 2, the sections of the DWO files are concatenated together
744 and stored in one section of that name. Thus each ELF section contains
745 several "virtual" sections. */
747 struct virtual_v2_dwo_sections
749 bfd_size_type abbrev_offset
;
750 bfd_size_type abbrev_size
;
752 bfd_size_type line_offset
;
753 bfd_size_type line_size
;
755 bfd_size_type loc_offset
;
756 bfd_size_type loc_size
;
758 bfd_size_type macinfo_offset
;
759 bfd_size_type macinfo_size
;
761 bfd_size_type macro_offset
;
762 bfd_size_type macro_size
;
764 bfd_size_type str_offsets_offset
;
765 bfd_size_type str_offsets_size
;
767 /* Each DWP hash table entry records one CU or one TU.
768 That is recorded here, and copied to dwo_unit.section. */
769 bfd_size_type info_or_types_offset
;
770 bfd_size_type info_or_types_size
;
773 /* Contents of DWP hash tables. */
775 struct dwp_hash_table
777 uint32_t version
, nr_columns
;
778 uint32_t nr_units
, nr_slots
;
779 const gdb_byte
*hash_table
, *unit_table
;
784 const gdb_byte
*indices
;
788 /* This is indexed by column number and gives the id of the section
790 #define MAX_NR_V2_DWO_SECTIONS \
791 (1 /* .debug_info or .debug_types */ \
792 + 1 /* .debug_abbrev */ \
793 + 1 /* .debug_line */ \
794 + 1 /* .debug_loc */ \
795 + 1 /* .debug_str_offsets */ \
796 + 1 /* .debug_macro or .debug_macinfo */)
797 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
798 const gdb_byte
*offsets
;
799 const gdb_byte
*sizes
;
804 /* Data for one DWP file. */
808 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
810 dbfd (std::move (abfd
))
814 /* Name of the file. */
817 /* File format version. */
821 gdb_bfd_ref_ptr dbfd
;
823 /* Section info for this file. */
824 struct dwp_sections sections
{};
826 /* Table of CUs in the file. */
827 const struct dwp_hash_table
*cus
= nullptr;
829 /* Table of TUs in the file. */
830 const struct dwp_hash_table
*tus
= nullptr;
832 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
836 /* Table to map ELF section numbers to their sections.
837 This is only needed for the DWP V1 file format. */
838 unsigned int num_sections
= 0;
839 asection
**elf_sections
= nullptr;
842 /* Struct used to pass misc. parameters to read_die_and_children, et
843 al. which are used for both .debug_info and .debug_types dies.
844 All parameters here are unchanging for the life of the call. This
845 struct exists to abstract away the constant parameters of die reading. */
847 struct die_reader_specs
849 /* The bfd of die_section. */
852 /* The CU of the DIE we are parsing. */
853 struct dwarf2_cu
*cu
;
855 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
856 struct dwo_file
*dwo_file
;
858 /* The section the die comes from.
859 This is either .debug_info or .debug_types, or the .dwo variants. */
860 struct dwarf2_section_info
*die_section
;
862 /* die_section->buffer. */
863 const gdb_byte
*buffer
;
865 /* The end of the buffer. */
866 const gdb_byte
*buffer_end
;
868 /* The abbreviation table to use when reading the DIEs. */
869 struct abbrev_table
*abbrev_table
;
872 /* A subclass of die_reader_specs that holds storage and has complex
873 constructor and destructor behavior. */
875 class cutu_reader
: public die_reader_specs
879 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
880 struct abbrev_table
*abbrev_table
,
884 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
885 struct dwarf2_cu
*parent_cu
= nullptr,
886 struct dwo_file
*dwo_file
= nullptr);
888 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
890 const gdb_byte
*info_ptr
= nullptr;
891 struct die_info
*comp_unit_die
= nullptr;
892 bool dummy_p
= false;
894 /* Release the new CU, putting it on the chain. This cannot be done
899 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
900 int use_existing_cu
);
902 struct dwarf2_per_cu_data
*m_this_cu
;
903 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
905 /* The ordinary abbreviation table. */
906 abbrev_table_up m_abbrev_table_holder
;
908 /* The DWO abbreviation table. */
909 abbrev_table_up m_dwo_abbrev_table
;
912 /* When we construct a partial symbol table entry we only
913 need this much information. */
914 struct partial_die_info
: public allocate_on_obstack
916 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
918 /* Disable assign but still keep copy ctor, which is needed
919 load_partial_dies. */
920 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
922 /* Adjust the partial die before generating a symbol for it. This
923 function may set the is_external flag or change the DIE's
925 void fixup (struct dwarf2_cu
*cu
);
927 /* Read a minimal amount of information into the minimal die
929 const gdb_byte
*read (const struct die_reader_specs
*reader
,
930 const struct abbrev_info
&abbrev
,
931 const gdb_byte
*info_ptr
);
933 /* Offset of this DIE. */
934 const sect_offset sect_off
;
936 /* DWARF-2 tag for this DIE. */
937 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
939 /* Assorted flags describing the data found in this DIE. */
940 const unsigned int has_children
: 1;
942 unsigned int is_external
: 1;
943 unsigned int is_declaration
: 1;
944 unsigned int has_type
: 1;
945 unsigned int has_specification
: 1;
946 unsigned int has_pc_info
: 1;
947 unsigned int may_be_inlined
: 1;
949 /* This DIE has been marked DW_AT_main_subprogram. */
950 unsigned int main_subprogram
: 1;
952 /* Flag set if the SCOPE field of this structure has been
954 unsigned int scope_set
: 1;
956 /* Flag set if the DIE has a byte_size attribute. */
957 unsigned int has_byte_size
: 1;
959 /* Flag set if the DIE has a DW_AT_const_value attribute. */
960 unsigned int has_const_value
: 1;
962 /* Flag set if any of the DIE's children are template arguments. */
963 unsigned int has_template_arguments
: 1;
965 /* Flag set if fixup has been called on this die. */
966 unsigned int fixup_called
: 1;
968 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
969 unsigned int is_dwz
: 1;
971 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
972 unsigned int spec_is_dwz
: 1;
974 /* The name of this DIE. Normally the value of DW_AT_name, but
975 sometimes a default name for unnamed DIEs. */
976 const char *name
= nullptr;
978 /* The linkage name, if present. */
979 const char *linkage_name
= nullptr;
981 /* The scope to prepend to our children. This is generally
982 allocated on the comp_unit_obstack, so will disappear
983 when this compilation unit leaves the cache. */
984 const char *scope
= nullptr;
986 /* Some data associated with the partial DIE. The tag determines
987 which field is live. */
990 /* The location description associated with this DIE, if any. */
991 struct dwarf_block
*locdesc
;
992 /* The offset of an import, for DW_TAG_imported_unit. */
993 sect_offset sect_off
;
996 /* If HAS_PC_INFO, the PC range associated with this DIE. */
998 CORE_ADDR highpc
= 0;
1000 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1001 DW_AT_sibling, if any. */
1002 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1003 could return DW_AT_sibling values to its caller load_partial_dies. */
1004 const gdb_byte
*sibling
= nullptr;
1006 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1007 DW_AT_specification (or DW_AT_abstract_origin or
1008 DW_AT_extension). */
1009 sect_offset spec_offset
{};
1011 /* Pointers to this DIE's parent, first child, and next sibling,
1013 struct partial_die_info
*die_parent
= nullptr;
1014 struct partial_die_info
*die_child
= nullptr;
1015 struct partial_die_info
*die_sibling
= nullptr;
1017 friend struct partial_die_info
*
1018 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1021 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1022 partial_die_info (sect_offset sect_off
)
1023 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1027 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1029 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1034 has_specification
= 0;
1037 main_subprogram
= 0;
1040 has_const_value
= 0;
1041 has_template_arguments
= 0;
1048 /* This data structure holds a complete die structure. */
1051 /* DWARF-2 tag for this DIE. */
1052 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1054 /* Number of attributes */
1055 unsigned char num_attrs
;
1057 /* True if we're presently building the full type name for the
1058 type derived from this DIE. */
1059 unsigned char building_fullname
: 1;
1061 /* True if this die is in process. PR 16581. */
1062 unsigned char in_process
: 1;
1064 /* True if this DIE has children. */
1065 unsigned char has_children
: 1;
1068 unsigned int abbrev
;
1070 /* Offset in .debug_info or .debug_types section. */
1071 sect_offset sect_off
;
1073 /* The dies in a compilation unit form an n-ary tree. PARENT
1074 points to this die's parent; CHILD points to the first child of
1075 this node; and all the children of a given node are chained
1076 together via their SIBLING fields. */
1077 struct die_info
*child
; /* Its first child, if any. */
1078 struct die_info
*sibling
; /* Its next sibling, if any. */
1079 struct die_info
*parent
; /* Its parent, if any. */
1081 /* An array of attributes, with NUM_ATTRS elements. There may be
1082 zero, but it's not common and zero-sized arrays are not
1083 sufficiently portable C. */
1084 struct attribute attrs
[1];
1087 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1088 but this would require a corresponding change in unpack_field_as_long
1090 static int bits_per_byte
= 8;
1092 /* When reading a variant or variant part, we track a bit more
1093 information about the field, and store it in an object of this
1096 struct variant_field
1098 /* If we see a DW_TAG_variant, then this will be the discriminant
1100 ULONGEST discriminant_value
;
1101 /* If we see a DW_TAG_variant, then this will be set if this is the
1103 bool default_branch
;
1104 /* While reading a DW_TAG_variant_part, this will be set if this
1105 field is the discriminant. */
1106 bool is_discriminant
;
1111 int accessibility
= 0;
1113 /* Extra information to describe a variant or variant part. */
1114 struct variant_field variant
{};
1115 struct field field
{};
1120 const char *name
= nullptr;
1121 std::vector
<struct fn_field
> fnfields
;
1124 /* The routines that read and process dies for a C struct or C++ class
1125 pass lists of data member fields and lists of member function fields
1126 in an instance of a field_info structure, as defined below. */
1129 /* List of data member and baseclasses fields. */
1130 std::vector
<struct nextfield
> fields
;
1131 std::vector
<struct nextfield
> baseclasses
;
1133 /* Set if the accessibility of one of the fields is not public. */
1134 int non_public_fields
= 0;
1136 /* Member function fieldlist array, contains name of possibly overloaded
1137 member function, number of overloaded member functions and a pointer
1138 to the head of the member function field chain. */
1139 std::vector
<struct fnfieldlist
> fnfieldlists
;
1141 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1142 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1143 std::vector
<struct decl_field
> typedef_field_list
;
1145 /* Nested types defined by this class and the number of elements in this
1147 std::vector
<struct decl_field
> nested_types_list
;
1149 /* Return the total number of fields (including baseclasses). */
1150 int nfields () const
1152 return fields
.size () + baseclasses
.size ();
1156 /* Loaded secondary compilation units are kept in memory until they
1157 have not been referenced for the processing of this many
1158 compilation units. Set this to zero to disable caching. Cache
1159 sizes of up to at least twenty will improve startup time for
1160 typical inter-CU-reference binaries, at an obvious memory cost. */
1161 static int dwarf_max_cache_age
= 5;
1163 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1164 struct cmd_list_element
*c
, const char *value
)
1166 fprintf_filtered (file
, _("The upper bound on the age of cached "
1167 "DWARF compilation units is %s.\n"),
1171 /* local function prototypes */
1173 static void dwarf2_find_base_address (struct die_info
*die
,
1174 struct dwarf2_cu
*cu
);
1176 static dwarf2_psymtab
*create_partial_symtab
1177 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1179 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1180 const gdb_byte
*info_ptr
,
1181 struct die_info
*type_unit_die
);
1183 static void dwarf2_build_psymtabs_hard
1184 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1186 static void scan_partial_symbols (struct partial_die_info
*,
1187 CORE_ADDR
*, CORE_ADDR
*,
1188 int, struct dwarf2_cu
*);
1190 static void add_partial_symbol (struct partial_die_info
*,
1191 struct dwarf2_cu
*);
1193 static void add_partial_namespace (struct partial_die_info
*pdi
,
1194 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1195 int set_addrmap
, struct dwarf2_cu
*cu
);
1197 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1198 CORE_ADDR
*highpc
, int set_addrmap
,
1199 struct dwarf2_cu
*cu
);
1201 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1202 struct dwarf2_cu
*cu
);
1204 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1205 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1206 int need_pc
, struct dwarf2_cu
*cu
);
1208 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1210 static struct partial_die_info
*load_partial_dies
1211 (const struct die_reader_specs
*, const gdb_byte
*, int);
1213 /* A pair of partial_die_info and compilation unit. */
1214 struct cu_partial_die_info
1216 /* The compilation unit of the partial_die_info. */
1217 struct dwarf2_cu
*cu
;
1218 /* A partial_die_info. */
1219 struct partial_die_info
*pdi
;
1221 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1227 cu_partial_die_info () = delete;
1230 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1231 struct dwarf2_cu
*);
1233 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1234 struct attribute
*, struct attr_abbrev
*,
1235 const gdb_byte
*, bool *need_reprocess
);
1237 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1238 struct attribute
*attr
);
1240 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1242 static sect_offset read_abbrev_offset
1243 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1244 struct dwarf2_section_info
*, sect_offset
);
1246 static const char *read_indirect_string
1247 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1248 const struct comp_unit_head
*, unsigned int *);
1250 static const char *read_indirect_string_at_offset
1251 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1253 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1257 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1258 ULONGEST str_index
);
1260 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1261 ULONGEST str_index
);
1263 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1265 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1266 struct dwarf2_cu
*);
1268 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1271 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1272 struct dwarf2_cu
*cu
);
1274 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1276 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1277 struct dwarf2_cu
*cu
);
1279 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1281 static struct die_info
*die_specification (struct die_info
*die
,
1282 struct dwarf2_cu
**);
1284 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1285 struct dwarf2_cu
*cu
);
1287 static void dwarf_decode_lines (struct line_header
*, const char *,
1288 struct dwarf2_cu
*, dwarf2_psymtab
*,
1289 CORE_ADDR
, int decode_mapping
);
1291 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1294 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1295 struct dwarf2_cu
*, struct symbol
* = NULL
);
1297 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1298 struct dwarf2_cu
*);
1300 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1303 struct obstack
*obstack
,
1304 struct dwarf2_cu
*cu
, LONGEST
*value
,
1305 const gdb_byte
**bytes
,
1306 struct dwarf2_locexpr_baton
**baton
);
1308 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1310 static int need_gnat_info (struct dwarf2_cu
*);
1312 static struct type
*die_descriptive_type (struct die_info
*,
1313 struct dwarf2_cu
*);
1315 static void set_descriptive_type (struct type
*, struct die_info
*,
1316 struct dwarf2_cu
*);
1318 static struct type
*die_containing_type (struct die_info
*,
1319 struct dwarf2_cu
*);
1321 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1322 struct dwarf2_cu
*);
1324 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1326 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1328 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1330 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1331 const char *suffix
, int physname
,
1332 struct dwarf2_cu
*cu
);
1334 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1336 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1338 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1340 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1342 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1344 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1346 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1347 struct dwarf2_cu
*, dwarf2_psymtab
*);
1349 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1350 values. Keep the items ordered with increasing constraints compliance. */
1353 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1354 PC_BOUNDS_NOT_PRESENT
,
1356 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1357 were present but they do not form a valid range of PC addresses. */
1360 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1363 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1367 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1368 CORE_ADDR
*, CORE_ADDR
*,
1372 static void get_scope_pc_bounds (struct die_info
*,
1373 CORE_ADDR
*, CORE_ADDR
*,
1374 struct dwarf2_cu
*);
1376 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1377 CORE_ADDR
, struct dwarf2_cu
*);
1379 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1380 struct dwarf2_cu
*);
1382 static void dwarf2_attach_fields_to_type (struct field_info
*,
1383 struct type
*, struct dwarf2_cu
*);
1385 static void dwarf2_add_member_fn (struct field_info
*,
1386 struct die_info
*, struct type
*,
1387 struct dwarf2_cu
*);
1389 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1391 struct dwarf2_cu
*);
1393 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1395 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1397 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1399 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1401 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1403 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1405 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1407 static struct type
*read_module_type (struct die_info
*die
,
1408 struct dwarf2_cu
*cu
);
1410 static const char *namespace_name (struct die_info
*die
,
1411 int *is_anonymous
, struct dwarf2_cu
*);
1413 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1415 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1417 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1418 struct dwarf2_cu
*);
1420 static struct die_info
*read_die_and_siblings_1
1421 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1424 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1425 const gdb_byte
*info_ptr
,
1426 const gdb_byte
**new_info_ptr
,
1427 struct die_info
*parent
);
1429 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1430 struct die_info
**, const gdb_byte
*,
1433 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1434 struct die_info
**, const gdb_byte
*);
1436 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1438 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1441 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1443 static const char *dwarf2_full_name (const char *name
,
1444 struct die_info
*die
,
1445 struct dwarf2_cu
*cu
);
1447 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1448 struct dwarf2_cu
*cu
);
1450 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1451 struct dwarf2_cu
**);
1453 static const char *dwarf_tag_name (unsigned int);
1455 static const char *dwarf_attr_name (unsigned int);
1457 static const char *dwarf_form_name (unsigned int);
1459 static const char *dwarf_bool_name (unsigned int);
1461 static const char *dwarf_type_encoding_name (unsigned int);
1463 static struct die_info
*sibling_die (struct die_info
*);
1465 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1467 static void dump_die_for_error (struct die_info
*);
1469 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1472 /*static*/ void dump_die (struct die_info
*, int max_level
);
1474 static void store_in_ref_table (struct die_info
*,
1475 struct dwarf2_cu
*);
1477 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1479 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1481 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1482 const struct attribute
*,
1483 struct dwarf2_cu
**);
1485 static struct die_info
*follow_die_ref (struct die_info
*,
1486 const struct attribute
*,
1487 struct dwarf2_cu
**);
1489 static struct die_info
*follow_die_sig (struct die_info
*,
1490 const struct attribute
*,
1491 struct dwarf2_cu
**);
1493 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1494 struct dwarf2_cu
*);
1496 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1497 const struct attribute
*,
1498 struct dwarf2_cu
*);
1500 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1502 static void read_signatured_type (struct signatured_type
*);
1504 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1505 struct die_info
*die
, struct dwarf2_cu
*cu
,
1506 struct dynamic_prop
*prop
, struct type
*type
);
1508 /* memory allocation interface */
1510 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1512 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1514 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1516 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1517 struct dwarf2_loclist_baton
*baton
,
1518 const struct attribute
*attr
);
1520 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1522 struct dwarf2_cu
*cu
,
1525 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1526 const gdb_byte
*info_ptr
,
1527 struct abbrev_info
*abbrev
);
1529 static hashval_t
partial_die_hash (const void *item
);
1531 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1533 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1534 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1535 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1537 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1538 struct die_info
*comp_unit_die
,
1539 enum language pretend_language
);
1541 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1543 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1545 static struct type
*set_die_type (struct die_info
*, struct type
*,
1546 struct dwarf2_cu
*);
1548 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1550 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1552 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1555 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1558 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1561 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1562 struct dwarf2_per_cu_data
*);
1564 static void dwarf2_mark (struct dwarf2_cu
*);
1566 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1568 static struct type
*get_die_type_at_offset (sect_offset
,
1569 struct dwarf2_per_cu_data
*);
1571 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1573 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1574 enum language pretend_language
);
1576 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1578 /* Class, the destructor of which frees all allocated queue entries. This
1579 will only have work to do if an error was thrown while processing the
1580 dwarf. If no error was thrown then the queue entries should have all
1581 been processed, and freed, as we went along. */
1583 class dwarf2_queue_guard
1586 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1587 : m_per_objfile (per_objfile
)
1591 /* Free any entries remaining on the queue. There should only be
1592 entries left if we hit an error while processing the dwarf. */
1593 ~dwarf2_queue_guard ()
1595 /* Ensure that no memory is allocated by the queue. */
1596 std::queue
<dwarf2_queue_item
> empty
;
1597 std::swap (m_per_objfile
->queue
, empty
);
1600 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1603 dwarf2_per_objfile
*m_per_objfile
;
1606 dwarf2_queue_item::~dwarf2_queue_item ()
1608 /* Anything still marked queued is likely to be in an
1609 inconsistent state, so discard it. */
1612 if (per_cu
->cu
!= NULL
)
1613 free_one_cached_comp_unit (per_cu
);
1618 /* The return type of find_file_and_directory. Note, the enclosed
1619 string pointers are only valid while this object is valid. */
1621 struct file_and_directory
1623 /* The filename. This is never NULL. */
1626 /* The compilation directory. NULL if not known. If we needed to
1627 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1628 points directly to the DW_AT_comp_dir string attribute owned by
1629 the obstack that owns the DIE. */
1630 const char *comp_dir
;
1632 /* If we needed to build a new string for comp_dir, this is what
1633 owns the storage. */
1634 std::string comp_dir_storage
;
1637 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1638 struct dwarf2_cu
*cu
);
1640 static htab_up
allocate_signatured_type_table ();
1642 static htab_up
allocate_dwo_unit_table ();
1644 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1645 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1646 struct dwp_file
*dwp_file
, const char *comp_dir
,
1647 ULONGEST signature
, int is_debug_types
);
1649 static struct dwp_file
*get_dwp_file
1650 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1652 static struct dwo_unit
*lookup_dwo_comp_unit
1653 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1655 static struct dwo_unit
*lookup_dwo_type_unit
1656 (struct signatured_type
*, const char *, const char *);
1658 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1660 /* A unique pointer to a dwo_file. */
1662 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1664 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1666 static void check_producer (struct dwarf2_cu
*cu
);
1668 static void free_line_header_voidp (void *arg
);
1670 /* Various complaints about symbol reading that don't abort the process. */
1673 dwarf2_debug_line_missing_file_complaint (void)
1675 complaint (_(".debug_line section has line data without a file"));
1679 dwarf2_debug_line_missing_end_sequence_complaint (void)
1681 complaint (_(".debug_line section has line "
1682 "program sequence without an end"));
1686 dwarf2_complex_location_expr_complaint (void)
1688 complaint (_("location expression too complex"));
1692 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1695 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1700 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1702 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1706 /* Hash function for line_header_hash. */
1709 line_header_hash (const struct line_header
*ofs
)
1711 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1714 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1717 line_header_hash_voidp (const void *item
)
1719 const struct line_header
*ofs
= (const struct line_header
*) item
;
1721 return line_header_hash (ofs
);
1724 /* Equality function for line_header_hash. */
1727 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1729 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1730 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1732 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1733 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1738 /* See declaration. */
1740 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1741 const dwarf2_debug_sections
*names
,
1743 : objfile (objfile_
),
1744 can_copy (can_copy_
)
1747 names
= &dwarf2_elf_names
;
1749 bfd
*obfd
= objfile
->obfd
;
1751 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1752 locate_sections (obfd
, sec
, *names
);
1755 dwarf2_per_objfile::~dwarf2_per_objfile ()
1757 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1758 free_cached_comp_units ();
1760 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1761 per_cu
->imported_symtabs_free ();
1763 for (signatured_type
*sig_type
: all_type_units
)
1764 sig_type
->per_cu
.imported_symtabs_free ();
1766 /* Everything else should be on the objfile obstack. */
1769 /* See declaration. */
1772 dwarf2_per_objfile::free_cached_comp_units ()
1774 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1775 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1776 while (per_cu
!= NULL
)
1778 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1781 *last_chain
= next_cu
;
1786 /* A helper class that calls free_cached_comp_units on
1789 class free_cached_comp_units
1793 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1794 : m_per_objfile (per_objfile
)
1798 ~free_cached_comp_units ()
1800 m_per_objfile
->free_cached_comp_units ();
1803 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1807 dwarf2_per_objfile
*m_per_objfile
;
1810 /* Try to locate the sections we need for DWARF 2 debugging
1811 information and return true if we have enough to do something.
1812 NAMES points to the dwarf2 section names, or is NULL if the standard
1813 ELF names are used. CAN_COPY is true for formats where symbol
1814 interposition is possible and so symbol values must follow copy
1815 relocation rules. */
1818 dwarf2_has_info (struct objfile
*objfile
,
1819 const struct dwarf2_debug_sections
*names
,
1822 if (objfile
->flags
& OBJF_READNEVER
)
1825 struct dwarf2_per_objfile
*dwarf2_per_objfile
1826 = get_dwarf2_per_objfile (objfile
);
1828 if (dwarf2_per_objfile
== NULL
)
1829 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1833 return (!dwarf2_per_objfile
->info
.is_virtual
1834 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1835 && !dwarf2_per_objfile
->abbrev
.is_virtual
1836 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1839 /* When loading sections, we look either for uncompressed section or for
1840 compressed section names. */
1843 section_is_p (const char *section_name
,
1844 const struct dwarf2_section_names
*names
)
1846 if (names
->normal
!= NULL
1847 && strcmp (section_name
, names
->normal
) == 0)
1849 if (names
->compressed
!= NULL
1850 && strcmp (section_name
, names
->compressed
) == 0)
1855 /* See declaration. */
1858 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1859 const dwarf2_debug_sections
&names
)
1861 flagword aflag
= bfd_section_flags (sectp
);
1863 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1866 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1867 > bfd_get_file_size (abfd
))
1869 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1870 warning (_("Discarding section %s which has a section size (%s"
1871 ") larger than the file size [in module %s]"),
1872 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1873 bfd_get_filename (abfd
));
1875 else if (section_is_p (sectp
->name
, &names
.info
))
1877 this->info
.s
.section
= sectp
;
1878 this->info
.size
= bfd_section_size (sectp
);
1880 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1882 this->abbrev
.s
.section
= sectp
;
1883 this->abbrev
.size
= bfd_section_size (sectp
);
1885 else if (section_is_p (sectp
->name
, &names
.line
))
1887 this->line
.s
.section
= sectp
;
1888 this->line
.size
= bfd_section_size (sectp
);
1890 else if (section_is_p (sectp
->name
, &names
.loc
))
1892 this->loc
.s
.section
= sectp
;
1893 this->loc
.size
= bfd_section_size (sectp
);
1895 else if (section_is_p (sectp
->name
, &names
.loclists
))
1897 this->loclists
.s
.section
= sectp
;
1898 this->loclists
.size
= bfd_section_size (sectp
);
1900 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1902 this->macinfo
.s
.section
= sectp
;
1903 this->macinfo
.size
= bfd_section_size (sectp
);
1905 else if (section_is_p (sectp
->name
, &names
.macro
))
1907 this->macro
.s
.section
= sectp
;
1908 this->macro
.size
= bfd_section_size (sectp
);
1910 else if (section_is_p (sectp
->name
, &names
.str
))
1912 this->str
.s
.section
= sectp
;
1913 this->str
.size
= bfd_section_size (sectp
);
1915 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1917 this->str_offsets
.s
.section
= sectp
;
1918 this->str_offsets
.size
= bfd_section_size (sectp
);
1920 else if (section_is_p (sectp
->name
, &names
.line_str
))
1922 this->line_str
.s
.section
= sectp
;
1923 this->line_str
.size
= bfd_section_size (sectp
);
1925 else if (section_is_p (sectp
->name
, &names
.addr
))
1927 this->addr
.s
.section
= sectp
;
1928 this->addr
.size
= bfd_section_size (sectp
);
1930 else if (section_is_p (sectp
->name
, &names
.frame
))
1932 this->frame
.s
.section
= sectp
;
1933 this->frame
.size
= bfd_section_size (sectp
);
1935 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1937 this->eh_frame
.s
.section
= sectp
;
1938 this->eh_frame
.size
= bfd_section_size (sectp
);
1940 else if (section_is_p (sectp
->name
, &names
.ranges
))
1942 this->ranges
.s
.section
= sectp
;
1943 this->ranges
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1947 this->rnglists
.s
.section
= sectp
;
1948 this->rnglists
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.types
))
1952 struct dwarf2_section_info type_section
;
1954 memset (&type_section
, 0, sizeof (type_section
));
1955 type_section
.s
.section
= sectp
;
1956 type_section
.size
= bfd_section_size (sectp
);
1958 this->types
.push_back (type_section
);
1960 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1962 this->gdb_index
.s
.section
= sectp
;
1963 this->gdb_index
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1967 this->debug_names
.s
.section
= sectp
;
1968 this->debug_names
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1972 this->debug_aranges
.s
.section
= sectp
;
1973 this->debug_aranges
.size
= bfd_section_size (sectp
);
1976 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1977 && bfd_section_vma (sectp
) == 0)
1978 this->has_section_at_zero
= true;
1981 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1985 dwarf2_get_section_info (struct objfile
*objfile
,
1986 enum dwarf2_section_enum sect
,
1987 asection
**sectp
, const gdb_byte
**bufp
,
1988 bfd_size_type
*sizep
)
1990 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
1991 struct dwarf2_section_info
*info
;
1993 /* We may see an objfile without any DWARF, in which case we just
2004 case DWARF2_DEBUG_FRAME
:
2005 info
= &data
->frame
;
2007 case DWARF2_EH_FRAME
:
2008 info
= &data
->eh_frame
;
2011 gdb_assert_not_reached ("unexpected section");
2014 info
->read (objfile
);
2016 *sectp
= info
->get_bfd_section ();
2017 *bufp
= info
->buffer
;
2018 *sizep
= info
->size
;
2021 /* A helper function to find the sections for a .dwz file. */
2024 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2026 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2028 /* Note that we only support the standard ELF names, because .dwz
2029 is ELF-only (at the time of writing). */
2030 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2032 dwz_file
->abbrev
.s
.section
= sectp
;
2033 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2037 dwz_file
->info
.s
.section
= sectp
;
2038 dwz_file
->info
.size
= bfd_section_size (sectp
);
2040 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2042 dwz_file
->str
.s
.section
= sectp
;
2043 dwz_file
->str
.size
= bfd_section_size (sectp
);
2045 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2047 dwz_file
->line
.s
.section
= sectp
;
2048 dwz_file
->line
.size
= bfd_section_size (sectp
);
2050 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2052 dwz_file
->macro
.s
.section
= sectp
;
2053 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2055 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2057 dwz_file
->gdb_index
.s
.section
= sectp
;
2058 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2060 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2062 dwz_file
->debug_names
.s
.section
= sectp
;
2063 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2067 /* See dwarf2read.h. */
2070 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2072 const char *filename
;
2073 bfd_size_type buildid_len_arg
;
2077 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2078 return dwarf2_per_objfile
->dwz_file
.get ();
2080 bfd_set_error (bfd_error_no_error
);
2081 gdb::unique_xmalloc_ptr
<char> data
2082 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2083 &buildid_len_arg
, &buildid
));
2086 if (bfd_get_error () == bfd_error_no_error
)
2088 error (_("could not read '.gnu_debugaltlink' section: %s"),
2089 bfd_errmsg (bfd_get_error ()));
2092 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2094 buildid_len
= (size_t) buildid_len_arg
;
2096 filename
= data
.get ();
2098 std::string abs_storage
;
2099 if (!IS_ABSOLUTE_PATH (filename
))
2101 gdb::unique_xmalloc_ptr
<char> abs
2102 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2104 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2105 filename
= abs_storage
.c_str ();
2108 /* First try the file name given in the section. If that doesn't
2109 work, try to use the build-id instead. */
2110 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2111 if (dwz_bfd
!= NULL
)
2113 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2114 dwz_bfd
.reset (nullptr);
2117 if (dwz_bfd
== NULL
)
2118 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2120 if (dwz_bfd
== nullptr)
2122 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2123 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2125 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2132 /* File successfully retrieved from server. */
2133 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2135 if (dwz_bfd
== nullptr)
2136 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2137 alt_filename
.get ());
2138 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2139 dwz_bfd
.reset (nullptr);
2143 if (dwz_bfd
== NULL
)
2144 error (_("could not find '.gnu_debugaltlink' file for %s"),
2145 objfile_name (dwarf2_per_objfile
->objfile
));
2147 std::unique_ptr
<struct dwz_file
> result
2148 (new struct dwz_file (std::move (dwz_bfd
)));
2150 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2153 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2154 result
->dwz_bfd
.get ());
2155 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2156 return dwarf2_per_objfile
->dwz_file
.get ();
2159 /* DWARF quick_symbols_functions support. */
2161 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2162 unique line tables, so we maintain a separate table of all .debug_line
2163 derived entries to support the sharing.
2164 All the quick functions need is the list of file names. We discard the
2165 line_header when we're done and don't need to record it here. */
2166 struct quick_file_names
2168 /* The data used to construct the hash key. */
2169 struct stmt_list_hash hash
;
2171 /* The number of entries in file_names, real_names. */
2172 unsigned int num_file_names
;
2174 /* The file names from the line table, after being run through
2176 const char **file_names
;
2178 /* The file names from the line table after being run through
2179 gdb_realpath. These are computed lazily. */
2180 const char **real_names
;
2183 /* When using the index (and thus not using psymtabs), each CU has an
2184 object of this type. This is used to hold information needed by
2185 the various "quick" methods. */
2186 struct dwarf2_per_cu_quick_data
2188 /* The file table. This can be NULL if there was no file table
2189 or it's currently not read in.
2190 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2191 struct quick_file_names
*file_names
;
2193 /* The corresponding symbol table. This is NULL if symbols for this
2194 CU have not yet been read. */
2195 struct compunit_symtab
*compunit_symtab
;
2197 /* A temporary mark bit used when iterating over all CUs in
2198 expand_symtabs_matching. */
2199 unsigned int mark
: 1;
2201 /* True if we've tried to read the file table and found there isn't one.
2202 There will be no point in trying to read it again next time. */
2203 unsigned int no_file_data
: 1;
2206 /* Utility hash function for a stmt_list_hash. */
2209 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2213 if (stmt_list_hash
->dwo_unit
!= NULL
)
2214 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2215 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2219 /* Utility equality function for a stmt_list_hash. */
2222 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2223 const struct stmt_list_hash
*rhs
)
2225 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2227 if (lhs
->dwo_unit
!= NULL
2228 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2231 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2234 /* Hash function for a quick_file_names. */
2237 hash_file_name_entry (const void *e
)
2239 const struct quick_file_names
*file_data
2240 = (const struct quick_file_names
*) e
;
2242 return hash_stmt_list_entry (&file_data
->hash
);
2245 /* Equality function for a quick_file_names. */
2248 eq_file_name_entry (const void *a
, const void *b
)
2250 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2251 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2253 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2256 /* Delete function for a quick_file_names. */
2259 delete_file_name_entry (void *e
)
2261 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2264 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2266 xfree ((void*) file_data
->file_names
[i
]);
2267 if (file_data
->real_names
)
2268 xfree ((void*) file_data
->real_names
[i
]);
2271 /* The space for the struct itself lives on objfile_obstack,
2272 so we don't free it here. */
2275 /* Create a quick_file_names hash table. */
2278 create_quick_file_names_table (unsigned int nr_initial_entries
)
2280 return htab_up (htab_create_alloc (nr_initial_entries
,
2281 hash_file_name_entry
, eq_file_name_entry
,
2282 delete_file_name_entry
, xcalloc
, xfree
));
2285 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2286 have to be created afterwards. You should call age_cached_comp_units after
2287 processing PER_CU->CU. dw2_setup must have been already called. */
2290 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2292 if (per_cu
->is_debug_types
)
2293 load_full_type_unit (per_cu
);
2295 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2297 if (per_cu
->cu
== NULL
)
2298 return; /* Dummy CU. */
2300 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2303 /* Read in the symbols for PER_CU. */
2306 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2308 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2310 /* Skip type_unit_groups, reading the type units they contain
2311 is handled elsewhere. */
2312 if (per_cu
->type_unit_group_p ())
2315 /* The destructor of dwarf2_queue_guard frees any entries left on
2316 the queue. After this point we're guaranteed to leave this function
2317 with the dwarf queue empty. */
2318 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2320 if (dwarf2_per_objfile
->using_index
2321 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2322 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2324 queue_comp_unit (per_cu
, language_minimal
);
2325 load_cu (per_cu
, skip_partial
);
2327 /* If we just loaded a CU from a DWO, and we're working with an index
2328 that may badly handle TUs, load all the TUs in that DWO as well.
2329 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2330 if (!per_cu
->is_debug_types
2331 && per_cu
->cu
!= NULL
2332 && per_cu
->cu
->dwo_unit
!= NULL
2333 && dwarf2_per_objfile
->index_table
!= NULL
2334 && dwarf2_per_objfile
->index_table
->version
<= 7
2335 /* DWP files aren't supported yet. */
2336 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2337 queue_and_load_all_dwo_tus (per_cu
);
2340 process_queue (dwarf2_per_objfile
);
2342 /* Age the cache, releasing compilation units that have not
2343 been used recently. */
2344 age_cached_comp_units (dwarf2_per_objfile
);
2347 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2348 the objfile from which this CU came. Returns the resulting symbol
2351 static struct compunit_symtab
*
2352 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2354 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2356 gdb_assert (dwarf2_per_objfile
->using_index
);
2357 if (!per_cu
->v
.quick
->compunit_symtab
)
2359 free_cached_comp_units
freer (dwarf2_per_objfile
);
2360 scoped_restore decrementer
= increment_reading_symtab ();
2361 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2362 process_cu_includes (dwarf2_per_objfile
);
2365 return per_cu
->v
.quick
->compunit_symtab
;
2368 /* See declaration. */
2370 dwarf2_per_cu_data
*
2371 dwarf2_per_objfile::get_cutu (int index
)
2373 if (index
>= this->all_comp_units
.size ())
2375 index
-= this->all_comp_units
.size ();
2376 gdb_assert (index
< this->all_type_units
.size ());
2377 return &this->all_type_units
[index
]->per_cu
;
2380 return this->all_comp_units
[index
];
2383 /* See declaration. */
2385 dwarf2_per_cu_data
*
2386 dwarf2_per_objfile::get_cu (int index
)
2388 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2390 return this->all_comp_units
[index
];
2393 /* See declaration. */
2396 dwarf2_per_objfile::get_tu (int index
)
2398 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2400 return this->all_type_units
[index
];
2403 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2404 objfile_obstack, and constructed with the specified field
2407 static dwarf2_per_cu_data
*
2408 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2409 struct dwarf2_section_info
*section
,
2411 sect_offset sect_off
, ULONGEST length
)
2413 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2414 dwarf2_per_cu_data
*the_cu
2415 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2416 struct dwarf2_per_cu_data
);
2417 the_cu
->sect_off
= sect_off
;
2418 the_cu
->length
= length
;
2419 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2420 the_cu
->section
= section
;
2421 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2422 struct dwarf2_per_cu_quick_data
);
2423 the_cu
->is_dwz
= is_dwz
;
2427 /* A helper for create_cus_from_index that handles a given list of
2431 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2432 const gdb_byte
*cu_list
, offset_type n_elements
,
2433 struct dwarf2_section_info
*section
,
2436 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2438 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2440 sect_offset sect_off
2441 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2442 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2445 dwarf2_per_cu_data
*per_cu
2446 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2448 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2452 /* Read the CU list from the mapped index, and use it to create all
2453 the CU objects for this objfile. */
2456 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2457 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2458 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2460 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2461 dwarf2_per_objfile
->all_comp_units
.reserve
2462 ((cu_list_elements
+ dwz_elements
) / 2);
2464 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2465 &dwarf2_per_objfile
->info
, 0);
2467 if (dwz_elements
== 0)
2470 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2471 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2475 /* Create the signatured type hash table from the index. */
2478 create_signatured_type_table_from_index
2479 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2480 struct dwarf2_section_info
*section
,
2481 const gdb_byte
*bytes
,
2482 offset_type elements
)
2484 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2486 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2487 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2489 htab_up sig_types_hash
= allocate_signatured_type_table ();
2491 for (offset_type i
= 0; i
< elements
; i
+= 3)
2493 struct signatured_type
*sig_type
;
2496 cu_offset type_offset_in_tu
;
2498 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2499 sect_offset sect_off
2500 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2502 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2504 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2507 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2508 struct signatured_type
);
2509 sig_type
->signature
= signature
;
2510 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2511 sig_type
->per_cu
.is_debug_types
= 1;
2512 sig_type
->per_cu
.section
= section
;
2513 sig_type
->per_cu
.sect_off
= sect_off
;
2514 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2515 sig_type
->per_cu
.v
.quick
2516 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2517 struct dwarf2_per_cu_quick_data
);
2519 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2522 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2525 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2528 /* Create the signatured type hash table from .debug_names. */
2531 create_signatured_type_table_from_debug_names
2532 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2533 const mapped_debug_names
&map
,
2534 struct dwarf2_section_info
*section
,
2535 struct dwarf2_section_info
*abbrev_section
)
2537 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2539 section
->read (objfile
);
2540 abbrev_section
->read (objfile
);
2542 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2543 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2545 htab_up sig_types_hash
= allocate_signatured_type_table ();
2547 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2549 struct signatured_type
*sig_type
;
2552 sect_offset sect_off
2553 = (sect_offset
) (extract_unsigned_integer
2554 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2556 map
.dwarf5_byte_order
));
2558 comp_unit_head cu_header
;
2559 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2561 section
->buffer
+ to_underlying (sect_off
),
2564 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2565 struct signatured_type
);
2566 sig_type
->signature
= cu_header
.signature
;
2567 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2568 sig_type
->per_cu
.is_debug_types
= 1;
2569 sig_type
->per_cu
.section
= section
;
2570 sig_type
->per_cu
.sect_off
= sect_off
;
2571 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2572 sig_type
->per_cu
.v
.quick
2573 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2574 struct dwarf2_per_cu_quick_data
);
2576 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2579 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2582 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2585 /* Read the address map data from the mapped index, and use it to
2586 populate the objfile's psymtabs_addrmap. */
2589 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2590 struct mapped_index
*index
)
2592 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2593 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2594 const gdb_byte
*iter
, *end
;
2595 struct addrmap
*mutable_map
;
2598 auto_obstack temp_obstack
;
2600 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2602 iter
= index
->address_table
.data ();
2603 end
= iter
+ index
->address_table
.size ();
2605 baseaddr
= objfile
->text_section_offset ();
2609 ULONGEST hi
, lo
, cu_index
;
2610 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2612 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2614 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2619 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2620 hex_string (lo
), hex_string (hi
));
2624 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2626 complaint (_(".gdb_index address table has invalid CU number %u"),
2627 (unsigned) cu_index
);
2631 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2632 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2633 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2634 dwarf2_per_objfile
->get_cu (cu_index
));
2637 objfile
->partial_symtabs
->psymtabs_addrmap
2638 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2641 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2642 populate the objfile's psymtabs_addrmap. */
2645 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2646 struct dwarf2_section_info
*section
)
2648 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2649 bfd
*abfd
= objfile
->obfd
;
2650 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2651 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2653 auto_obstack temp_obstack
;
2654 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2656 std::unordered_map
<sect_offset
,
2657 dwarf2_per_cu_data
*,
2658 gdb::hash_enum
<sect_offset
>>
2659 debug_info_offset_to_per_cu
;
2660 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2662 const auto insertpair
2663 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2664 if (!insertpair
.second
)
2666 warning (_("Section .debug_aranges in %s has duplicate "
2667 "debug_info_offset %s, ignoring .debug_aranges."),
2668 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2673 section
->read (objfile
);
2675 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2677 const gdb_byte
*addr
= section
->buffer
;
2679 while (addr
< section
->buffer
+ section
->size
)
2681 const gdb_byte
*const entry_addr
= addr
;
2682 unsigned int bytes_read
;
2684 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2688 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2689 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2690 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2691 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2693 warning (_("Section .debug_aranges in %s entry at offset %s "
2694 "length %s exceeds section length %s, "
2695 "ignoring .debug_aranges."),
2696 objfile_name (objfile
),
2697 plongest (entry_addr
- section
->buffer
),
2698 plongest (bytes_read
+ entry_length
),
2699 pulongest (section
->size
));
2703 /* The version number. */
2704 const uint16_t version
= read_2_bytes (abfd
, addr
);
2708 warning (_("Section .debug_aranges in %s entry at offset %s "
2709 "has unsupported version %d, ignoring .debug_aranges."),
2710 objfile_name (objfile
),
2711 plongest (entry_addr
- section
->buffer
), version
);
2715 const uint64_t debug_info_offset
2716 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2717 addr
+= offset_size
;
2718 const auto per_cu_it
2719 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2720 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2722 warning (_("Section .debug_aranges in %s entry at offset %s "
2723 "debug_info_offset %s does not exists, "
2724 "ignoring .debug_aranges."),
2725 objfile_name (objfile
),
2726 plongest (entry_addr
- section
->buffer
),
2727 pulongest (debug_info_offset
));
2730 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2732 const uint8_t address_size
= *addr
++;
2733 if (address_size
< 1 || address_size
> 8)
2735 warning (_("Section .debug_aranges in %s entry at offset %s "
2736 "address_size %u is invalid, ignoring .debug_aranges."),
2737 objfile_name (objfile
),
2738 plongest (entry_addr
- section
->buffer
), address_size
);
2742 const uint8_t segment_selector_size
= *addr
++;
2743 if (segment_selector_size
!= 0)
2745 warning (_("Section .debug_aranges in %s entry at offset %s "
2746 "segment_selector_size %u is not supported, "
2747 "ignoring .debug_aranges."),
2748 objfile_name (objfile
),
2749 plongest (entry_addr
- section
->buffer
),
2750 segment_selector_size
);
2754 /* Must pad to an alignment boundary that is twice the address
2755 size. It is undocumented by the DWARF standard but GCC does
2757 for (size_t padding
= ((-(addr
- section
->buffer
))
2758 & (2 * address_size
- 1));
2759 padding
> 0; padding
--)
2762 warning (_("Section .debug_aranges in %s entry at offset %s "
2763 "padding is not zero, ignoring .debug_aranges."),
2764 objfile_name (objfile
),
2765 plongest (entry_addr
- section
->buffer
));
2771 if (addr
+ 2 * address_size
> entry_end
)
2773 warning (_("Section .debug_aranges in %s entry at offset %s "
2774 "address list is not properly terminated, "
2775 "ignoring .debug_aranges."),
2776 objfile_name (objfile
),
2777 plongest (entry_addr
- section
->buffer
));
2780 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2782 addr
+= address_size
;
2783 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2785 addr
+= address_size
;
2786 if (start
== 0 && length
== 0)
2788 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2790 /* Symbol was eliminated due to a COMDAT group. */
2793 ULONGEST end
= start
+ length
;
2794 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2796 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2798 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2802 objfile
->partial_symtabs
->psymtabs_addrmap
2803 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2806 /* Find a slot in the mapped index INDEX for the object named NAME.
2807 If NAME is found, set *VEC_OUT to point to the CU vector in the
2808 constant pool and return true. If NAME cannot be found, return
2812 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2813 offset_type
**vec_out
)
2816 offset_type slot
, step
;
2817 int (*cmp
) (const char *, const char *);
2819 gdb::unique_xmalloc_ptr
<char> without_params
;
2820 if (current_language
->la_language
== language_cplus
2821 || current_language
->la_language
== language_fortran
2822 || current_language
->la_language
== language_d
)
2824 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2827 if (strchr (name
, '(') != NULL
)
2829 without_params
= cp_remove_params (name
);
2831 if (without_params
!= NULL
)
2832 name
= without_params
.get ();
2836 /* Index version 4 did not support case insensitive searches. But the
2837 indices for case insensitive languages are built in lowercase, therefore
2838 simulate our NAME being searched is also lowercased. */
2839 hash
= mapped_index_string_hash ((index
->version
== 4
2840 && case_sensitivity
== case_sensitive_off
2841 ? 5 : index
->version
),
2844 slot
= hash
& (index
->symbol_table
.size () - 1);
2845 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2846 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2852 const auto &bucket
= index
->symbol_table
[slot
];
2853 if (bucket
.name
== 0 && bucket
.vec
== 0)
2856 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2857 if (!cmp (name
, str
))
2859 *vec_out
= (offset_type
*) (index
->constant_pool
2860 + MAYBE_SWAP (bucket
.vec
));
2864 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2868 /* A helper function that reads the .gdb_index from BUFFER and fills
2869 in MAP. FILENAME is the name of the file containing the data;
2870 it is used for error reporting. DEPRECATED_OK is true if it is
2871 ok to use deprecated sections.
2873 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2874 out parameters that are filled in with information about the CU and
2875 TU lists in the section.
2877 Returns true if all went well, false otherwise. */
2880 read_gdb_index_from_buffer (struct objfile
*objfile
,
2881 const char *filename
,
2883 gdb::array_view
<const gdb_byte
> buffer
,
2884 struct mapped_index
*map
,
2885 const gdb_byte
**cu_list
,
2886 offset_type
*cu_list_elements
,
2887 const gdb_byte
**types_list
,
2888 offset_type
*types_list_elements
)
2890 const gdb_byte
*addr
= &buffer
[0];
2892 /* Version check. */
2893 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2894 /* Versions earlier than 3 emitted every copy of a psymbol. This
2895 causes the index to behave very poorly for certain requests. Version 3
2896 contained incomplete addrmap. So, it seems better to just ignore such
2900 static int warning_printed
= 0;
2901 if (!warning_printed
)
2903 warning (_("Skipping obsolete .gdb_index section in %s."),
2905 warning_printed
= 1;
2909 /* Index version 4 uses a different hash function than index version
2912 Versions earlier than 6 did not emit psymbols for inlined
2913 functions. Using these files will cause GDB not to be able to
2914 set breakpoints on inlined functions by name, so we ignore these
2915 indices unless the user has done
2916 "set use-deprecated-index-sections on". */
2917 if (version
< 6 && !deprecated_ok
)
2919 static int warning_printed
= 0;
2920 if (!warning_printed
)
2923 Skipping deprecated .gdb_index section in %s.\n\
2924 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2925 to use the section anyway."),
2927 warning_printed
= 1;
2931 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2932 of the TU (for symbols coming from TUs),
2933 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2934 Plus gold-generated indices can have duplicate entries for global symbols,
2935 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2936 These are just performance bugs, and we can't distinguish gdb-generated
2937 indices from gold-generated ones, so issue no warning here. */
2939 /* Indexes with higher version than the one supported by GDB may be no
2940 longer backward compatible. */
2944 map
->version
= version
;
2946 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2949 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2950 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2954 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2955 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2956 - MAYBE_SWAP (metadata
[i
]))
2960 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2961 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2963 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2966 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2967 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2969 = gdb::array_view
<mapped_index::symbol_table_slot
>
2970 ((mapped_index::symbol_table_slot
*) symbol_table
,
2971 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2974 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2979 /* Callback types for dwarf2_read_gdb_index. */
2981 typedef gdb::function_view
2982 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2983 get_gdb_index_contents_ftype
;
2984 typedef gdb::function_view
2985 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2986 get_gdb_index_contents_dwz_ftype
;
2988 /* Read .gdb_index. If everything went ok, initialize the "quick"
2989 elements of all the CUs and return 1. Otherwise, return 0. */
2992 dwarf2_read_gdb_index
2993 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2994 get_gdb_index_contents_ftype get_gdb_index_contents
,
2995 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2997 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2998 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2999 struct dwz_file
*dwz
;
3000 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3002 gdb::array_view
<const gdb_byte
> main_index_contents
3003 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3005 if (main_index_contents
.empty ())
3008 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3009 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3010 use_deprecated_index_sections
,
3011 main_index_contents
, map
.get (), &cu_list
,
3012 &cu_list_elements
, &types_list
,
3013 &types_list_elements
))
3016 /* Don't use the index if it's empty. */
3017 if (map
->symbol_table
.empty ())
3020 /* If there is a .dwz file, read it so we can get its CU list as
3022 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3025 struct mapped_index dwz_map
;
3026 const gdb_byte
*dwz_types_ignore
;
3027 offset_type dwz_types_elements_ignore
;
3029 gdb::array_view
<const gdb_byte
> dwz_index_content
3030 = get_gdb_index_contents_dwz (objfile
, dwz
);
3032 if (dwz_index_content
.empty ())
3035 if (!read_gdb_index_from_buffer (objfile
,
3036 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3037 1, dwz_index_content
, &dwz_map
,
3038 &dwz_list
, &dwz_list_elements
,
3040 &dwz_types_elements_ignore
))
3042 warning (_("could not read '.gdb_index' section from %s; skipping"),
3043 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3048 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3049 dwz_list
, dwz_list_elements
);
3051 if (types_list_elements
)
3053 /* We can only handle a single .debug_types when we have an
3055 if (dwarf2_per_objfile
->types
.size () != 1)
3058 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3060 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3061 types_list
, types_list_elements
);
3064 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3066 dwarf2_per_objfile
->index_table
= std::move (map
);
3067 dwarf2_per_objfile
->using_index
= 1;
3068 dwarf2_per_objfile
->quick_file_names_table
=
3069 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3074 /* die_reader_func for dw2_get_file_names. */
3077 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3078 const gdb_byte
*info_ptr
,
3079 struct die_info
*comp_unit_die
)
3081 struct dwarf2_cu
*cu
= reader
->cu
;
3082 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3083 struct dwarf2_per_objfile
*dwarf2_per_objfile
3084 = cu
->per_cu
->dwarf2_per_objfile
;
3085 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3086 struct dwarf2_per_cu_data
*lh_cu
;
3087 struct attribute
*attr
;
3089 struct quick_file_names
*qfn
;
3091 gdb_assert (! this_cu
->is_debug_types
);
3093 /* Our callers never want to match partial units -- instead they
3094 will match the enclosing full CU. */
3095 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3097 this_cu
->v
.quick
->no_file_data
= 1;
3105 sect_offset line_offset
{};
3107 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3108 if (attr
!= nullptr)
3110 struct quick_file_names find_entry
;
3112 line_offset
= (sect_offset
) DW_UNSND (attr
);
3114 /* We may have already read in this line header (TU line header sharing).
3115 If we have we're done. */
3116 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3117 find_entry
.hash
.line_sect_off
= line_offset
;
3118 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3119 &find_entry
, INSERT
);
3122 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3126 lh
= dwarf_decode_line_header (line_offset
, cu
);
3130 lh_cu
->v
.quick
->no_file_data
= 1;
3134 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3135 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3136 qfn
->hash
.line_sect_off
= line_offset
;
3137 gdb_assert (slot
!= NULL
);
3140 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3143 if (strcmp (fnd
.name
, "<unknown>") != 0)
3146 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3148 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3150 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3151 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3152 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3153 fnd
.comp_dir
).release ();
3154 qfn
->real_names
= NULL
;
3156 lh_cu
->v
.quick
->file_names
= qfn
;
3159 /* A helper for the "quick" functions which attempts to read the line
3160 table for THIS_CU. */
3162 static struct quick_file_names
*
3163 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3165 /* This should never be called for TUs. */
3166 gdb_assert (! this_cu
->is_debug_types
);
3167 /* Nor type unit groups. */
3168 gdb_assert (! this_cu
->type_unit_group_p ());
3170 if (this_cu
->v
.quick
->file_names
!= NULL
)
3171 return this_cu
->v
.quick
->file_names
;
3172 /* If we know there is no line data, no point in looking again. */
3173 if (this_cu
->v
.quick
->no_file_data
)
3176 cutu_reader
reader (this_cu
);
3177 if (!reader
.dummy_p
)
3178 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3180 if (this_cu
->v
.quick
->no_file_data
)
3182 return this_cu
->v
.quick
->file_names
;
3185 /* A helper for the "quick" functions which computes and caches the
3186 real path for a given file name from the line table. */
3189 dw2_get_real_path (struct objfile
*objfile
,
3190 struct quick_file_names
*qfn
, int index
)
3192 if (qfn
->real_names
== NULL
)
3193 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3194 qfn
->num_file_names
, const char *);
3196 if (qfn
->real_names
[index
] == NULL
)
3197 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3199 return qfn
->real_names
[index
];
3202 static struct symtab
*
3203 dw2_find_last_source_symtab (struct objfile
*objfile
)
3205 struct dwarf2_per_objfile
*dwarf2_per_objfile
3206 = get_dwarf2_per_objfile (objfile
);
3207 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3208 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3213 return compunit_primary_filetab (cust
);
3216 /* Traversal function for dw2_forget_cached_source_info. */
3219 dw2_free_cached_file_names (void **slot
, void *info
)
3221 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3223 if (file_data
->real_names
)
3227 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3229 xfree ((void*) file_data
->real_names
[i
]);
3230 file_data
->real_names
[i
] = NULL
;
3238 dw2_forget_cached_source_info (struct objfile
*objfile
)
3240 struct dwarf2_per_objfile
*dwarf2_per_objfile
3241 = get_dwarf2_per_objfile (objfile
);
3243 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3244 dw2_free_cached_file_names
, NULL
);
3247 /* Helper function for dw2_map_symtabs_matching_filename that expands
3248 the symtabs and calls the iterator. */
3251 dw2_map_expand_apply (struct objfile
*objfile
,
3252 struct dwarf2_per_cu_data
*per_cu
,
3253 const char *name
, const char *real_path
,
3254 gdb::function_view
<bool (symtab
*)> callback
)
3256 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3258 /* Don't visit already-expanded CUs. */
3259 if (per_cu
->v
.quick
->compunit_symtab
)
3262 /* This may expand more than one symtab, and we want to iterate over
3264 dw2_instantiate_symtab (per_cu
, false);
3266 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3267 last_made
, callback
);
3270 /* Implementation of the map_symtabs_matching_filename method. */
3273 dw2_map_symtabs_matching_filename
3274 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3275 gdb::function_view
<bool (symtab
*)> callback
)
3277 const char *name_basename
= lbasename (name
);
3278 struct dwarf2_per_objfile
*dwarf2_per_objfile
3279 = get_dwarf2_per_objfile (objfile
);
3281 /* The rule is CUs specify all the files, including those used by
3282 any TU, so there's no need to scan TUs here. */
3284 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3286 /* We only need to look at symtabs not already expanded. */
3287 if (per_cu
->v
.quick
->compunit_symtab
)
3290 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3291 if (file_data
== NULL
)
3294 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3296 const char *this_name
= file_data
->file_names
[j
];
3297 const char *this_real_name
;
3299 if (compare_filenames_for_search (this_name
, name
))
3301 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3307 /* Before we invoke realpath, which can get expensive when many
3308 files are involved, do a quick comparison of the basenames. */
3309 if (! basenames_may_differ
3310 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3313 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3314 if (compare_filenames_for_search (this_real_name
, name
))
3316 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3322 if (real_path
!= NULL
)
3324 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3325 gdb_assert (IS_ABSOLUTE_PATH (name
));
3326 if (this_real_name
!= NULL
3327 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3329 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3341 /* Struct used to manage iterating over all CUs looking for a symbol. */
3343 struct dw2_symtab_iterator
3345 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3346 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3347 /* If set, only look for symbols that match that block. Valid values are
3348 GLOBAL_BLOCK and STATIC_BLOCK. */
3349 gdb::optional
<block_enum
> block_index
;
3350 /* The kind of symbol we're looking for. */
3352 /* The list of CUs from the index entry of the symbol,
3353 or NULL if not found. */
3355 /* The next element in VEC to look at. */
3357 /* The number of elements in VEC, or zero if there is no match. */
3359 /* Have we seen a global version of the symbol?
3360 If so we can ignore all further global instances.
3361 This is to work around gold/15646, inefficient gold-generated
3366 /* Initialize the index symtab iterator ITER. */
3369 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3370 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3371 gdb::optional
<block_enum
> block_index
,
3375 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3376 iter
->block_index
= block_index
;
3377 iter
->domain
= domain
;
3379 iter
->global_seen
= 0;
3381 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3383 /* index is NULL if OBJF_READNOW. */
3384 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3385 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3393 /* Return the next matching CU or NULL if there are no more. */
3395 static struct dwarf2_per_cu_data
*
3396 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3398 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3400 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3402 offset_type cu_index_and_attrs
=
3403 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3404 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3405 gdb_index_symbol_kind symbol_kind
=
3406 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3407 /* Only check the symbol attributes if they're present.
3408 Indices prior to version 7 don't record them,
3409 and indices >= 7 may elide them for certain symbols
3410 (gold does this). */
3412 (dwarf2_per_objfile
->index_table
->version
>= 7
3413 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3415 /* Don't crash on bad data. */
3416 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3417 + dwarf2_per_objfile
->all_type_units
.size ()))
3419 complaint (_(".gdb_index entry has bad CU index"
3421 objfile_name (dwarf2_per_objfile
->objfile
));
3425 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3427 /* Skip if already read in. */
3428 if (per_cu
->v
.quick
->compunit_symtab
)
3431 /* Check static vs global. */
3434 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3436 if (iter
->block_index
.has_value ())
3438 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3440 if (is_static
!= want_static
)
3444 /* Work around gold/15646. */
3445 if (!is_static
&& iter
->global_seen
)
3448 iter
->global_seen
= 1;
3451 /* Only check the symbol's kind if it has one. */
3454 switch (iter
->domain
)
3457 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3458 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3459 /* Some types are also in VAR_DOMAIN. */
3460 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3464 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3468 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3472 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3487 static struct compunit_symtab
*
3488 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3489 const char *name
, domain_enum domain
)
3491 struct compunit_symtab
*stab_best
= NULL
;
3492 struct dwarf2_per_objfile
*dwarf2_per_objfile
3493 = get_dwarf2_per_objfile (objfile
);
3495 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3497 struct dw2_symtab_iterator iter
;
3498 struct dwarf2_per_cu_data
*per_cu
;
3500 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3502 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3504 struct symbol
*sym
, *with_opaque
= NULL
;
3505 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3506 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3507 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3509 sym
= block_find_symbol (block
, name
, domain
,
3510 block_find_non_opaque_type_preferred
,
3513 /* Some caution must be observed with overloaded functions
3514 and methods, since the index will not contain any overload
3515 information (but NAME might contain it). */
3518 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3520 if (with_opaque
!= NULL
3521 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3524 /* Keep looking through other CUs. */
3531 dw2_print_stats (struct objfile
*objfile
)
3533 struct dwarf2_per_objfile
*dwarf2_per_objfile
3534 = get_dwarf2_per_objfile (objfile
);
3535 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3536 + dwarf2_per_objfile
->all_type_units
.size ());
3539 for (int i
= 0; i
< total
; ++i
)
3541 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3543 if (!per_cu
->v
.quick
->compunit_symtab
)
3546 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3547 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3550 /* This dumps minimal information about the index.
3551 It is called via "mt print objfiles".
3552 One use is to verify .gdb_index has been loaded by the
3553 gdb.dwarf2/gdb-index.exp testcase. */
3556 dw2_dump (struct objfile
*objfile
)
3558 struct dwarf2_per_objfile
*dwarf2_per_objfile
3559 = get_dwarf2_per_objfile (objfile
);
3561 gdb_assert (dwarf2_per_objfile
->using_index
);
3562 printf_filtered (".gdb_index:");
3563 if (dwarf2_per_objfile
->index_table
!= NULL
)
3565 printf_filtered (" version %d\n",
3566 dwarf2_per_objfile
->index_table
->version
);
3569 printf_filtered (" faked for \"readnow\"\n");
3570 printf_filtered ("\n");
3574 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3575 const char *func_name
)
3577 struct dwarf2_per_objfile
*dwarf2_per_objfile
3578 = get_dwarf2_per_objfile (objfile
);
3580 struct dw2_symtab_iterator iter
;
3581 struct dwarf2_per_cu_data
*per_cu
;
3583 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3585 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3586 dw2_instantiate_symtab (per_cu
, false);
3591 dw2_expand_all_symtabs (struct objfile
*objfile
)
3593 struct dwarf2_per_objfile
*dwarf2_per_objfile
3594 = get_dwarf2_per_objfile (objfile
);
3595 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3596 + dwarf2_per_objfile
->all_type_units
.size ());
3598 for (int i
= 0; i
< total_units
; ++i
)
3600 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3602 /* We don't want to directly expand a partial CU, because if we
3603 read it with the wrong language, then assertion failures can
3604 be triggered later on. See PR symtab/23010. So, tell
3605 dw2_instantiate_symtab to skip partial CUs -- any important
3606 partial CU will be read via DW_TAG_imported_unit anyway. */
3607 dw2_instantiate_symtab (per_cu
, true);
3612 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3613 const char *fullname
)
3615 struct dwarf2_per_objfile
*dwarf2_per_objfile
3616 = get_dwarf2_per_objfile (objfile
);
3618 /* We don't need to consider type units here.
3619 This is only called for examining code, e.g. expand_line_sal.
3620 There can be an order of magnitude (or more) more type units
3621 than comp units, and we avoid them if we can. */
3623 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3625 /* We only need to look at symtabs not already expanded. */
3626 if (per_cu
->v
.quick
->compunit_symtab
)
3629 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3630 if (file_data
== NULL
)
3633 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3635 const char *this_fullname
= file_data
->file_names
[j
];
3637 if (filename_cmp (this_fullname
, fullname
) == 0)
3639 dw2_instantiate_symtab (per_cu
, false);
3647 dw2_map_matching_symbols
3648 (struct objfile
*objfile
,
3649 const lookup_name_info
&name
, domain_enum domain
,
3651 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3652 symbol_compare_ftype
*ordered_compare
)
3654 /* Currently unimplemented; used for Ada. The function can be called if the
3655 current language is Ada for a non-Ada objfile using GNU index. As Ada
3656 does not look for non-Ada symbols this function should just return. */
3659 /* Starting from a search name, return the string that finds the upper
3660 bound of all strings that start with SEARCH_NAME in a sorted name
3661 list. Returns the empty string to indicate that the upper bound is
3662 the end of the list. */
3665 make_sort_after_prefix_name (const char *search_name
)
3667 /* When looking to complete "func", we find the upper bound of all
3668 symbols that start with "func" by looking for where we'd insert
3669 the closest string that would follow "func" in lexicographical
3670 order. Usually, that's "func"-with-last-character-incremented,
3671 i.e. "fund". Mind non-ASCII characters, though. Usually those
3672 will be UTF-8 multi-byte sequences, but we can't be certain.
3673 Especially mind the 0xff character, which is a valid character in
3674 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3675 rule out compilers allowing it in identifiers. Note that
3676 conveniently, strcmp/strcasecmp are specified to compare
3677 characters interpreted as unsigned char. So what we do is treat
3678 the whole string as a base 256 number composed of a sequence of
3679 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3680 to 0, and carries 1 to the following more-significant position.
3681 If the very first character in SEARCH_NAME ends up incremented
3682 and carries/overflows, then the upper bound is the end of the
3683 list. The string after the empty string is also the empty
3686 Some examples of this operation:
3688 SEARCH_NAME => "+1" RESULT
3692 "\xff" "a" "\xff" => "\xff" "b"
3697 Then, with these symbols for example:
3703 completing "func" looks for symbols between "func" and
3704 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3705 which finds "func" and "func1", but not "fund".
3709 funcÿ (Latin1 'ÿ' [0xff])
3713 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3714 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3718 ÿÿ (Latin1 'ÿ' [0xff])
3721 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3722 the end of the list.
3724 std::string after
= search_name
;
3725 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3727 if (!after
.empty ())
3728 after
.back () = (unsigned char) after
.back () + 1;
3732 /* See declaration. */
3734 std::pair
<std::vector
<name_component
>::const_iterator
,
3735 std::vector
<name_component
>::const_iterator
>
3736 mapped_index_base::find_name_components_bounds
3737 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3740 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3742 const char *lang_name
3743 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3745 /* Comparison function object for lower_bound that matches against a
3746 given symbol name. */
3747 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3750 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3751 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3752 return name_cmp (elem_name
, name
) < 0;
3755 /* Comparison function object for upper_bound that matches against a
3756 given symbol name. */
3757 auto lookup_compare_upper
= [&] (const char *name
,
3758 const name_component
&elem
)
3760 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3761 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3762 return name_cmp (name
, elem_name
) < 0;
3765 auto begin
= this->name_components
.begin ();
3766 auto end
= this->name_components
.end ();
3768 /* Find the lower bound. */
3771 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3774 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3777 /* Find the upper bound. */
3780 if (lookup_name_without_params
.completion_mode ())
3782 /* In completion mode, we want UPPER to point past all
3783 symbols names that have the same prefix. I.e., with
3784 these symbols, and completing "func":
3786 function << lower bound
3788 other_function << upper bound
3790 We find the upper bound by looking for the insertion
3791 point of "func"-with-last-character-incremented,
3793 std::string after
= make_sort_after_prefix_name (lang_name
);
3796 return std::lower_bound (lower
, end
, after
.c_str (),
3797 lookup_compare_lower
);
3800 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3803 return {lower
, upper
};
3806 /* See declaration. */
3809 mapped_index_base::build_name_components ()
3811 if (!this->name_components
.empty ())
3814 this->name_components_casing
= case_sensitivity
;
3816 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3818 /* The code below only knows how to break apart components of C++
3819 symbol names (and other languages that use '::' as
3820 namespace/module separator) and Ada symbol names. */
3821 auto count
= this->symbol_name_count ();
3822 for (offset_type idx
= 0; idx
< count
; idx
++)
3824 if (this->symbol_name_slot_invalid (idx
))
3827 const char *name
= this->symbol_name_at (idx
);
3829 /* Add each name component to the name component table. */
3830 unsigned int previous_len
= 0;
3832 if (strstr (name
, "::") != nullptr)
3834 for (unsigned int current_len
= cp_find_first_component (name
);
3835 name
[current_len
] != '\0';
3836 current_len
+= cp_find_first_component (name
+ current_len
))
3838 gdb_assert (name
[current_len
] == ':');
3839 this->name_components
.push_back ({previous_len
, idx
});
3840 /* Skip the '::'. */
3842 previous_len
= current_len
;
3847 /* Handle the Ada encoded (aka mangled) form here. */
3848 for (const char *iter
= strstr (name
, "__");
3850 iter
= strstr (iter
, "__"))
3852 this->name_components
.push_back ({previous_len
, idx
});
3854 previous_len
= iter
- name
;
3858 this->name_components
.push_back ({previous_len
, idx
});
3861 /* Sort name_components elements by name. */
3862 auto name_comp_compare
= [&] (const name_component
&left
,
3863 const name_component
&right
)
3865 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3866 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3868 const char *left_name
= left_qualified
+ left
.name_offset
;
3869 const char *right_name
= right_qualified
+ right
.name_offset
;
3871 return name_cmp (left_name
, right_name
) < 0;
3874 std::sort (this->name_components
.begin (),
3875 this->name_components
.end (),
3879 /* Helper for dw2_expand_symtabs_matching that works with a
3880 mapped_index_base instead of the containing objfile. This is split
3881 to a separate function in order to be able to unit test the
3882 name_components matching using a mock mapped_index_base. For each
3883 symbol name that matches, calls MATCH_CALLBACK, passing it the
3884 symbol's index in the mapped_index_base symbol table. */
3887 dw2_expand_symtabs_matching_symbol
3888 (mapped_index_base
&index
,
3889 const lookup_name_info
&lookup_name_in
,
3890 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3891 enum search_domain kind
,
3892 gdb::function_view
<bool (offset_type
)> match_callback
)
3894 lookup_name_info lookup_name_without_params
3895 = lookup_name_in
.make_ignore_params ();
3897 /* Build the symbol name component sorted vector, if we haven't
3899 index
.build_name_components ();
3901 /* The same symbol may appear more than once in the range though.
3902 E.g., if we're looking for symbols that complete "w", and we have
3903 a symbol named "w1::w2", we'll find the two name components for
3904 that same symbol in the range. To be sure we only call the
3905 callback once per symbol, we first collect the symbol name
3906 indexes that matched in a temporary vector and ignore
3908 std::vector
<offset_type
> matches
;
3910 struct name_and_matcher
3912 symbol_name_matcher_ftype
*matcher
;
3913 const std::string
&name
;
3915 bool operator== (const name_and_matcher
&other
) const
3917 return matcher
== other
.matcher
&& name
== other
.name
;
3921 /* A vector holding all the different symbol name matchers, for all
3923 std::vector
<name_and_matcher
> matchers
;
3925 for (int i
= 0; i
< nr_languages
; i
++)
3927 enum language lang_e
= (enum language
) i
;
3929 const language_defn
*lang
= language_def (lang_e
);
3930 symbol_name_matcher_ftype
*name_matcher
3931 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3933 name_and_matcher key
{
3935 lookup_name_without_params
.language_lookup_name (lang_e
)
3938 /* Don't insert the same comparison routine more than once.
3939 Note that we do this linear walk. This is not a problem in
3940 practice because the number of supported languages is
3942 if (std::find (matchers
.begin (), matchers
.end (), key
)
3945 matchers
.push_back (std::move (key
));
3948 = index
.find_name_components_bounds (lookup_name_without_params
,
3951 /* Now for each symbol name in range, check to see if we have a name
3952 match, and if so, call the MATCH_CALLBACK callback. */
3954 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3956 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3958 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3959 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3962 matches
.push_back (bounds
.first
->idx
);
3966 std::sort (matches
.begin (), matches
.end ());
3968 /* Finally call the callback, once per match. */
3970 for (offset_type idx
: matches
)
3974 if (!match_callback (idx
))
3980 /* Above we use a type wider than idx's for 'prev', since 0 and
3981 (offset_type)-1 are both possible values. */
3982 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3987 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3989 /* A mock .gdb_index/.debug_names-like name index table, enough to
3990 exercise dw2_expand_symtabs_matching_symbol, which works with the
3991 mapped_index_base interface. Builds an index from the symbol list
3992 passed as parameter to the constructor. */
3993 class mock_mapped_index
: public mapped_index_base
3996 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3997 : m_symbol_table (symbols
)
4000 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4002 /* Return the number of names in the symbol table. */
4003 size_t symbol_name_count () const override
4005 return m_symbol_table
.size ();
4008 /* Get the name of the symbol at IDX in the symbol table. */
4009 const char *symbol_name_at (offset_type idx
) const override
4011 return m_symbol_table
[idx
];
4015 gdb::array_view
<const char *> m_symbol_table
;
4018 /* Convenience function that converts a NULL pointer to a "<null>"
4019 string, to pass to print routines. */
4022 string_or_null (const char *str
)
4024 return str
!= NULL
? str
: "<null>";
4027 /* Check if a lookup_name_info built from
4028 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4029 index. EXPECTED_LIST is the list of expected matches, in expected
4030 matching order. If no match expected, then an empty list is
4031 specified. Returns true on success. On failure prints a warning
4032 indicating the file:line that failed, and returns false. */
4035 check_match (const char *file
, int line
,
4036 mock_mapped_index
&mock_index
,
4037 const char *name
, symbol_name_match_type match_type
,
4038 bool completion_mode
,
4039 std::initializer_list
<const char *> expected_list
)
4041 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4043 bool matched
= true;
4045 auto mismatch
= [&] (const char *expected_str
,
4048 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4049 "expected=\"%s\", got=\"%s\"\n"),
4051 (match_type
== symbol_name_match_type::FULL
4053 name
, string_or_null (expected_str
), string_or_null (got
));
4057 auto expected_it
= expected_list
.begin ();
4058 auto expected_end
= expected_list
.end ();
4060 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4062 [&] (offset_type idx
)
4064 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4065 const char *expected_str
4066 = expected_it
== expected_end
? NULL
: *expected_it
++;
4068 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4069 mismatch (expected_str
, matched_name
);
4073 const char *expected_str
4074 = expected_it
== expected_end
? NULL
: *expected_it
++;
4075 if (expected_str
!= NULL
)
4076 mismatch (expected_str
, NULL
);
4081 /* The symbols added to the mock mapped_index for testing (in
4083 static const char *test_symbols
[] = {
4092 "ns2::tmpl<int>::foo2",
4093 "(anonymous namespace)::A::B::C",
4095 /* These are used to check that the increment-last-char in the
4096 matching algorithm for completion doesn't match "t1_fund" when
4097 completing "t1_func". */
4103 /* A UTF-8 name with multi-byte sequences to make sure that
4104 cp-name-parser understands this as a single identifier ("função"
4105 is "function" in PT). */
4108 /* \377 (0xff) is Latin1 'ÿ'. */
4111 /* \377 (0xff) is Latin1 'ÿ'. */
4115 /* A name with all sorts of complications. Starts with "z" to make
4116 it easier for the completion tests below. */
4117 #define Z_SYM_NAME \
4118 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4119 "::tuple<(anonymous namespace)::ui*, " \
4120 "std::default_delete<(anonymous namespace)::ui>, void>"
4125 /* Returns true if the mapped_index_base::find_name_component_bounds
4126 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4127 in completion mode. */
4130 check_find_bounds_finds (mapped_index_base
&index
,
4131 const char *search_name
,
4132 gdb::array_view
<const char *> expected_syms
)
4134 lookup_name_info
lookup_name (search_name
,
4135 symbol_name_match_type::FULL
, true);
4137 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4140 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4141 if (distance
!= expected_syms
.size ())
4144 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4146 auto nc_elem
= bounds
.first
+ exp_elem
;
4147 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4148 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4155 /* Test the lower-level mapped_index::find_name_component_bounds
4159 test_mapped_index_find_name_component_bounds ()
4161 mock_mapped_index
mock_index (test_symbols
);
4163 mock_index
.build_name_components ();
4165 /* Test the lower-level mapped_index::find_name_component_bounds
4166 method in completion mode. */
4168 static const char *expected_syms
[] = {
4173 SELF_CHECK (check_find_bounds_finds (mock_index
,
4174 "t1_func", expected_syms
));
4177 /* Check that the increment-last-char in the name matching algorithm
4178 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4180 static const char *expected_syms1
[] = {
4184 SELF_CHECK (check_find_bounds_finds (mock_index
,
4185 "\377", expected_syms1
));
4187 static const char *expected_syms2
[] = {
4190 SELF_CHECK (check_find_bounds_finds (mock_index
,
4191 "\377\377", expected_syms2
));
4195 /* Test dw2_expand_symtabs_matching_symbol. */
4198 test_dw2_expand_symtabs_matching_symbol ()
4200 mock_mapped_index
mock_index (test_symbols
);
4202 /* We let all tests run until the end even if some fails, for debug
4204 bool any_mismatch
= false;
4206 /* Create the expected symbols list (an initializer_list). Needed
4207 because lists have commas, and we need to pass them to CHECK,
4208 which is a macro. */
4209 #define EXPECT(...) { __VA_ARGS__ }
4211 /* Wrapper for check_match that passes down the current
4212 __FILE__/__LINE__. */
4213 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4214 any_mismatch |= !check_match (__FILE__, __LINE__, \
4216 NAME, MATCH_TYPE, COMPLETION_MODE, \
4219 /* Identity checks. */
4220 for (const char *sym
: test_symbols
)
4222 /* Should be able to match all existing symbols. */
4223 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4226 /* Should be able to match all existing symbols with
4228 std::string with_params
= std::string (sym
) + "(int)";
4229 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4232 /* Should be able to match all existing symbols with
4233 parameters and qualifiers. */
4234 with_params
= std::string (sym
) + " ( int ) const";
4235 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4238 /* This should really find sym, but cp-name-parser.y doesn't
4239 know about lvalue/rvalue qualifiers yet. */
4240 with_params
= std::string (sym
) + " ( int ) &&";
4241 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4245 /* Check that the name matching algorithm for completion doesn't get
4246 confused with Latin1 'ÿ' / 0xff. */
4248 static const char str
[] = "\377";
4249 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4250 EXPECT ("\377", "\377\377123"));
4253 /* Check that the increment-last-char in the matching algorithm for
4254 completion doesn't match "t1_fund" when completing "t1_func". */
4256 static const char str
[] = "t1_func";
4257 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4258 EXPECT ("t1_func", "t1_func1"));
4261 /* Check that completion mode works at each prefix of the expected
4264 static const char str
[] = "function(int)";
4265 size_t len
= strlen (str
);
4268 for (size_t i
= 1; i
< len
; i
++)
4270 lookup
.assign (str
, i
);
4271 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4272 EXPECT ("function"));
4276 /* While "w" is a prefix of both components, the match function
4277 should still only be called once. */
4279 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4281 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4285 /* Same, with a "complicated" symbol. */
4287 static const char str
[] = Z_SYM_NAME
;
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 (Z_SYM_NAME
));
4299 /* In FULL mode, an incomplete symbol doesn't match. */
4301 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4305 /* A complete symbol with parameters matches any overload, since the
4306 index has no overload info. */
4308 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4309 EXPECT ("std::zfunction", "std::zfunction2"));
4310 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4311 EXPECT ("std::zfunction", "std::zfunction2"));
4312 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4313 EXPECT ("std::zfunction", "std::zfunction2"));
4316 /* Check that whitespace is ignored appropriately. A symbol with a
4317 template argument list. */
4319 static const char expected
[] = "ns::foo<int>";
4320 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4322 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4326 /* Check that whitespace is ignored appropriately. A symbol with a
4327 template argument list that includes a pointer. */
4329 static const char expected
[] = "ns::foo<char*>";
4330 /* Try both completion and non-completion modes. */
4331 static const bool completion_mode
[2] = {false, true};
4332 for (size_t i
= 0; i
< 2; i
++)
4334 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4335 completion_mode
[i
], EXPECT (expected
));
4336 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4337 completion_mode
[i
], EXPECT (expected
));
4339 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4340 completion_mode
[i
], EXPECT (expected
));
4341 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4342 completion_mode
[i
], EXPECT (expected
));
4347 /* Check method qualifiers are ignored. */
4348 static const char expected
[] = "ns::foo<char*>";
4349 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4350 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4351 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4352 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4353 CHECK_MATCH ("foo < char * > ( int ) const",
4354 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4355 CHECK_MATCH ("foo < char * > ( int ) &&",
4356 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4359 /* Test lookup names that don't match anything. */
4361 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4364 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4368 /* Some wild matching tests, exercising "(anonymous namespace)",
4369 which should not be confused with a parameter list. */
4371 static const char *syms
[] = {
4375 "A :: B :: C ( int )",
4380 for (const char *s
: syms
)
4382 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4383 EXPECT ("(anonymous namespace)::A::B::C"));
4388 static const char expected
[] = "ns2::tmpl<int>::foo2";
4389 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4391 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4395 SELF_CHECK (!any_mismatch
);
4404 test_mapped_index_find_name_component_bounds ();
4405 test_dw2_expand_symtabs_matching_symbol ();
4408 }} // namespace selftests::dw2_expand_symtabs_matching
4410 #endif /* GDB_SELF_TEST */
4412 /* If FILE_MATCHER is NULL or if PER_CU has
4413 dwarf2_per_cu_quick_data::MARK set (see
4414 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4415 EXPANSION_NOTIFY on it. */
4418 dw2_expand_symtabs_matching_one
4419 (struct dwarf2_per_cu_data
*per_cu
,
4420 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4421 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4423 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4425 bool symtab_was_null
4426 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4428 dw2_instantiate_symtab (per_cu
, false);
4430 if (expansion_notify
!= NULL
4432 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4433 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4437 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4438 matched, to expand corresponding CUs that were marked. IDX is the
4439 index of the symbol name that matched. */
4442 dw2_expand_marked_cus
4443 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4444 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4445 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4448 offset_type
*vec
, vec_len
, vec_idx
;
4449 bool global_seen
= false;
4450 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4452 vec
= (offset_type
*) (index
.constant_pool
4453 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4454 vec_len
= MAYBE_SWAP (vec
[0]);
4455 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4457 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4458 /* This value is only valid for index versions >= 7. */
4459 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4460 gdb_index_symbol_kind symbol_kind
=
4461 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4462 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4463 /* Only check the symbol attributes if they're present.
4464 Indices prior to version 7 don't record them,
4465 and indices >= 7 may elide them for certain symbols
4466 (gold does this). */
4469 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4471 /* Work around gold/15646. */
4474 if (!is_static
&& global_seen
)
4480 /* Only check the symbol's kind if it has one. */
4485 case VARIABLES_DOMAIN
:
4486 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4489 case FUNCTIONS_DOMAIN
:
4490 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4494 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4497 case MODULES_DOMAIN
:
4498 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4506 /* Don't crash on bad data. */
4507 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4508 + dwarf2_per_objfile
->all_type_units
.size ()))
4510 complaint (_(".gdb_index entry has bad CU index"
4512 objfile_name (dwarf2_per_objfile
->objfile
));
4516 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4517 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4522 /* If FILE_MATCHER is non-NULL, set all the
4523 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4524 that match FILE_MATCHER. */
4527 dw_expand_symtabs_matching_file_matcher
4528 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4529 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4531 if (file_matcher
== NULL
)
4534 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4536 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4538 NULL
, xcalloc
, xfree
));
4539 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4541 NULL
, xcalloc
, xfree
));
4543 /* The rule is CUs specify all the files, including those used by
4544 any TU, so there's no need to scan TUs here. */
4546 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4550 per_cu
->v
.quick
->mark
= 0;
4552 /* We only need to look at symtabs not already expanded. */
4553 if (per_cu
->v
.quick
->compunit_symtab
)
4556 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4557 if (file_data
== NULL
)
4560 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4562 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4564 per_cu
->v
.quick
->mark
= 1;
4568 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4570 const char *this_real_name
;
4572 if (file_matcher (file_data
->file_names
[j
], false))
4574 per_cu
->v
.quick
->mark
= 1;
4578 /* Before we invoke realpath, which can get expensive when many
4579 files are involved, do a quick comparison of the basenames. */
4580 if (!basenames_may_differ
4581 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4585 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4586 if (file_matcher (this_real_name
, false))
4588 per_cu
->v
.quick
->mark
= 1;
4593 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4594 ? visited_found
.get ()
4595 : visited_not_found
.get (),
4602 dw2_expand_symtabs_matching
4603 (struct objfile
*objfile
,
4604 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4605 const lookup_name_info
&lookup_name
,
4606 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4607 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4608 enum search_domain kind
)
4610 struct dwarf2_per_objfile
*dwarf2_per_objfile
4611 = get_dwarf2_per_objfile (objfile
);
4613 /* index_table is NULL if OBJF_READNOW. */
4614 if (!dwarf2_per_objfile
->index_table
)
4617 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4619 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4621 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4623 kind
, [&] (offset_type idx
)
4625 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4626 expansion_notify
, kind
);
4631 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4634 static struct compunit_symtab
*
4635 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4640 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4641 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4644 if (cust
->includes
== NULL
)
4647 for (i
= 0; cust
->includes
[i
]; ++i
)
4649 struct compunit_symtab
*s
= cust
->includes
[i
];
4651 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4659 static struct compunit_symtab
*
4660 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4661 struct bound_minimal_symbol msymbol
,
4663 struct obj_section
*section
,
4666 struct dwarf2_per_cu_data
*data
;
4667 struct compunit_symtab
*result
;
4669 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4672 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4673 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4674 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4678 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4679 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4680 paddress (get_objfile_arch (objfile
), pc
));
4683 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4686 gdb_assert (result
!= NULL
);
4691 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4692 void *data
, int need_fullname
)
4694 struct dwarf2_per_objfile
*dwarf2_per_objfile
4695 = get_dwarf2_per_objfile (objfile
);
4697 if (!dwarf2_per_objfile
->filenames_cache
)
4699 dwarf2_per_objfile
->filenames_cache
.emplace ();
4701 htab_up
visited (htab_create_alloc (10,
4702 htab_hash_pointer
, htab_eq_pointer
,
4703 NULL
, xcalloc
, xfree
));
4705 /* The rule is CUs specify all the files, including those used
4706 by any TU, so there's no need to scan TUs here. We can
4707 ignore file names coming from already-expanded CUs. */
4709 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4711 if (per_cu
->v
.quick
->compunit_symtab
)
4713 void **slot
= htab_find_slot (visited
.get (),
4714 per_cu
->v
.quick
->file_names
,
4717 *slot
= per_cu
->v
.quick
->file_names
;
4721 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4723 /* We only need to look at symtabs not already expanded. */
4724 if (per_cu
->v
.quick
->compunit_symtab
)
4727 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4728 if (file_data
== NULL
)
4731 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4734 /* Already visited. */
4739 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4741 const char *filename
= file_data
->file_names
[j
];
4742 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4747 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4749 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4752 this_real_name
= gdb_realpath (filename
);
4753 (*fun
) (filename
, this_real_name
.get (), data
);
4758 dw2_has_symbols (struct objfile
*objfile
)
4763 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4766 dw2_find_last_source_symtab
,
4767 dw2_forget_cached_source_info
,
4768 dw2_map_symtabs_matching_filename
,
4772 dw2_expand_symtabs_for_function
,
4773 dw2_expand_all_symtabs
,
4774 dw2_expand_symtabs_with_fullname
,
4775 dw2_map_matching_symbols
,
4776 dw2_expand_symtabs_matching
,
4777 dw2_find_pc_sect_compunit_symtab
,
4779 dw2_map_symbol_filenames
4782 /* DWARF-5 debug_names reader. */
4784 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4785 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4787 /* A helper function that reads the .debug_names section in SECTION
4788 and fills in MAP. FILENAME is the name of the file containing the
4789 section; it is used for error reporting.
4791 Returns true if all went well, false otherwise. */
4794 read_debug_names_from_section (struct objfile
*objfile
,
4795 const char *filename
,
4796 struct dwarf2_section_info
*section
,
4797 mapped_debug_names
&map
)
4799 if (section
->empty ())
4802 /* Older elfutils strip versions could keep the section in the main
4803 executable while splitting it for the separate debug info file. */
4804 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4807 section
->read (objfile
);
4809 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4811 const gdb_byte
*addr
= section
->buffer
;
4813 bfd
*const abfd
= section
->get_bfd_owner ();
4815 unsigned int bytes_read
;
4816 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4819 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4820 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4821 if (bytes_read
+ length
!= section
->size
)
4823 /* There may be multiple per-CU indices. */
4824 warning (_("Section .debug_names in %s length %s does not match "
4825 "section length %s, ignoring .debug_names."),
4826 filename
, plongest (bytes_read
+ length
),
4827 pulongest (section
->size
));
4831 /* The version number. */
4832 uint16_t version
= read_2_bytes (abfd
, addr
);
4836 warning (_("Section .debug_names in %s has unsupported version %d, "
4837 "ignoring .debug_names."),
4843 uint16_t padding
= read_2_bytes (abfd
, addr
);
4847 warning (_("Section .debug_names in %s has unsupported padding %d, "
4848 "ignoring .debug_names."),
4853 /* comp_unit_count - The number of CUs in the CU list. */
4854 map
.cu_count
= read_4_bytes (abfd
, addr
);
4857 /* local_type_unit_count - The number of TUs in the local TU
4859 map
.tu_count
= read_4_bytes (abfd
, addr
);
4862 /* foreign_type_unit_count - The number of TUs in the foreign TU
4864 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4866 if (foreign_tu_count
!= 0)
4868 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4869 "ignoring .debug_names."),
4870 filename
, static_cast<unsigned long> (foreign_tu_count
));
4874 /* bucket_count - The number of hash buckets in the hash lookup
4876 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4879 /* name_count - The number of unique names in the index. */
4880 map
.name_count
= read_4_bytes (abfd
, addr
);
4883 /* abbrev_table_size - The size in bytes of the abbreviations
4885 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4888 /* augmentation_string_size - The size in bytes of the augmentation
4889 string. This value is rounded up to a multiple of 4. */
4890 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4892 map
.augmentation_is_gdb
= ((augmentation_string_size
4893 == sizeof (dwarf5_augmentation
))
4894 && memcmp (addr
, dwarf5_augmentation
,
4895 sizeof (dwarf5_augmentation
)) == 0);
4896 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4897 addr
+= augmentation_string_size
;
4900 map
.cu_table_reordered
= addr
;
4901 addr
+= map
.cu_count
* map
.offset_size
;
4903 /* List of Local TUs */
4904 map
.tu_table_reordered
= addr
;
4905 addr
+= map
.tu_count
* map
.offset_size
;
4907 /* Hash Lookup Table */
4908 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4909 addr
+= map
.bucket_count
* 4;
4910 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4911 addr
+= map
.name_count
* 4;
4914 map
.name_table_string_offs_reordered
= addr
;
4915 addr
+= map
.name_count
* map
.offset_size
;
4916 map
.name_table_entry_offs_reordered
= addr
;
4917 addr
+= map
.name_count
* map
.offset_size
;
4919 const gdb_byte
*abbrev_table_start
= addr
;
4922 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4927 const auto insertpair
4928 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4929 if (!insertpair
.second
)
4931 warning (_("Section .debug_names in %s has duplicate index %s, "
4932 "ignoring .debug_names."),
4933 filename
, pulongest (index_num
));
4936 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4937 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4942 mapped_debug_names::index_val::attr attr
;
4943 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4945 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4947 if (attr
.form
== DW_FORM_implicit_const
)
4949 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4953 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4955 indexval
.attr_vec
.push_back (std::move (attr
));
4958 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4960 warning (_("Section .debug_names in %s has abbreviation_table "
4961 "of size %s vs. written as %u, ignoring .debug_names."),
4962 filename
, plongest (addr
- abbrev_table_start
),
4966 map
.entry_pool
= addr
;
4971 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4975 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4976 const mapped_debug_names
&map
,
4977 dwarf2_section_info
§ion
,
4980 sect_offset sect_off_prev
;
4981 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4983 sect_offset sect_off_next
;
4984 if (i
< map
.cu_count
)
4987 = (sect_offset
) (extract_unsigned_integer
4988 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4990 map
.dwarf5_byte_order
));
4993 sect_off_next
= (sect_offset
) section
.size
;
4996 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4997 dwarf2_per_cu_data
*per_cu
4998 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
4999 sect_off_prev
, length
);
5000 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5002 sect_off_prev
= sect_off_next
;
5006 /* Read the CU list from the mapped index, and use it to create all
5007 the CU objects for this dwarf2_per_objfile. */
5010 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5011 const mapped_debug_names
&map
,
5012 const mapped_debug_names
&dwz_map
)
5014 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5015 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5017 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5018 dwarf2_per_objfile
->info
,
5019 false /* is_dwz */);
5021 if (dwz_map
.cu_count
== 0)
5024 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5025 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5029 /* Read .debug_names. If everything went ok, initialize the "quick"
5030 elements of all the CUs and return true. Otherwise, return false. */
5033 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5035 std::unique_ptr
<mapped_debug_names
> map
5036 (new mapped_debug_names (dwarf2_per_objfile
));
5037 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5038 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5040 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5041 &dwarf2_per_objfile
->debug_names
,
5045 /* Don't use the index if it's empty. */
5046 if (map
->name_count
== 0)
5049 /* If there is a .dwz file, read it so we can get its CU list as
5051 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5054 if (!read_debug_names_from_section (objfile
,
5055 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5056 &dwz
->debug_names
, dwz_map
))
5058 warning (_("could not read '.debug_names' section from %s; skipping"),
5059 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5064 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5066 if (map
->tu_count
!= 0)
5068 /* We can only handle a single .debug_types when we have an
5070 if (dwarf2_per_objfile
->types
.size () != 1)
5073 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5075 create_signatured_type_table_from_debug_names
5076 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5079 create_addrmap_from_aranges (dwarf2_per_objfile
,
5080 &dwarf2_per_objfile
->debug_aranges
);
5082 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5083 dwarf2_per_objfile
->using_index
= 1;
5084 dwarf2_per_objfile
->quick_file_names_table
=
5085 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5090 /* Type used to manage iterating over all CUs looking for a symbol for
5093 class dw2_debug_names_iterator
5096 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5097 gdb::optional
<block_enum
> block_index
,
5100 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5101 m_addr (find_vec_in_debug_names (map
, name
))
5104 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5105 search_domain search
, uint32_t namei
)
5108 m_addr (find_vec_in_debug_names (map
, namei
))
5111 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5112 block_enum block_index
, domain_enum domain
,
5114 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5115 m_addr (find_vec_in_debug_names (map
, namei
))
5118 /* Return the next matching CU or NULL if there are no more. */
5119 dwarf2_per_cu_data
*next ();
5122 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5124 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5127 /* The internalized form of .debug_names. */
5128 const mapped_debug_names
&m_map
;
5130 /* If set, only look for symbols that match that block. Valid values are
5131 GLOBAL_BLOCK and STATIC_BLOCK. */
5132 const gdb::optional
<block_enum
> m_block_index
;
5134 /* The kind of symbol we're looking for. */
5135 const domain_enum m_domain
= UNDEF_DOMAIN
;
5136 const search_domain m_search
= ALL_DOMAIN
;
5138 /* The list of CUs from the index entry of the symbol, or NULL if
5140 const gdb_byte
*m_addr
;
5144 mapped_debug_names::namei_to_name (uint32_t namei
) const
5146 const ULONGEST namei_string_offs
5147 = extract_unsigned_integer ((name_table_string_offs_reordered
5148 + namei
* offset_size
),
5151 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5155 /* Find a slot in .debug_names for the object named NAME. If NAME is
5156 found, return pointer to its pool data. If NAME cannot be found,
5160 dw2_debug_names_iterator::find_vec_in_debug_names
5161 (const mapped_debug_names
&map
, const char *name
)
5163 int (*cmp
) (const char *, const char *);
5165 gdb::unique_xmalloc_ptr
<char> without_params
;
5166 if (current_language
->la_language
== language_cplus
5167 || current_language
->la_language
== language_fortran
5168 || current_language
->la_language
== language_d
)
5170 /* NAME is already canonical. Drop any qualifiers as
5171 .debug_names does not contain any. */
5173 if (strchr (name
, '(') != NULL
)
5175 without_params
= cp_remove_params (name
);
5176 if (without_params
!= NULL
)
5177 name
= without_params
.get ();
5181 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5183 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5185 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5186 (map
.bucket_table_reordered
5187 + (full_hash
% map
.bucket_count
)), 4,
5188 map
.dwarf5_byte_order
);
5192 if (namei
>= map
.name_count
)
5194 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5196 namei
, map
.name_count
,
5197 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5203 const uint32_t namei_full_hash
5204 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5205 (map
.hash_table_reordered
+ namei
), 4,
5206 map
.dwarf5_byte_order
);
5207 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5210 if (full_hash
== namei_full_hash
)
5212 const char *const namei_string
= map
.namei_to_name (namei
);
5214 #if 0 /* An expensive sanity check. */
5215 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5217 complaint (_("Wrong .debug_names hash for string at index %u "
5219 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5224 if (cmp (namei_string
, name
) == 0)
5226 const ULONGEST namei_entry_offs
5227 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5228 + namei
* map
.offset_size
),
5229 map
.offset_size
, map
.dwarf5_byte_order
);
5230 return map
.entry_pool
+ namei_entry_offs
;
5235 if (namei
>= map
.name_count
)
5241 dw2_debug_names_iterator::find_vec_in_debug_names
5242 (const mapped_debug_names
&map
, uint32_t namei
)
5244 if (namei
>= map
.name_count
)
5246 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5248 namei
, map
.name_count
,
5249 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5253 const ULONGEST namei_entry_offs
5254 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5255 + namei
* map
.offset_size
),
5256 map
.offset_size
, map
.dwarf5_byte_order
);
5257 return map
.entry_pool
+ namei_entry_offs
;
5260 /* See dw2_debug_names_iterator. */
5262 dwarf2_per_cu_data
*
5263 dw2_debug_names_iterator::next ()
5268 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5269 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5270 bfd
*const abfd
= objfile
->obfd
;
5274 unsigned int bytes_read
;
5275 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5276 m_addr
+= bytes_read
;
5280 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5281 if (indexval_it
== m_map
.abbrev_map
.cend ())
5283 complaint (_("Wrong .debug_names undefined abbrev code %s "
5285 pulongest (abbrev
), objfile_name (objfile
));
5288 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5289 enum class symbol_linkage
{
5293 } symbol_linkage_
= symbol_linkage::unknown
;
5294 dwarf2_per_cu_data
*per_cu
= NULL
;
5295 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5300 case DW_FORM_implicit_const
:
5301 ull
= attr
.implicit_const
;
5303 case DW_FORM_flag_present
:
5307 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5308 m_addr
+= bytes_read
;
5311 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5312 dwarf_form_name (attr
.form
),
5313 objfile_name (objfile
));
5316 switch (attr
.dw_idx
)
5318 case DW_IDX_compile_unit
:
5319 /* Don't crash on bad data. */
5320 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5322 complaint (_(".debug_names entry has bad CU index %s"
5325 objfile_name (dwarf2_per_objfile
->objfile
));
5328 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5330 case DW_IDX_type_unit
:
5331 /* Don't crash on bad data. */
5332 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5334 complaint (_(".debug_names entry has bad TU index %s"
5337 objfile_name (dwarf2_per_objfile
->objfile
));
5340 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5342 case DW_IDX_GNU_internal
:
5343 if (!m_map
.augmentation_is_gdb
)
5345 symbol_linkage_
= symbol_linkage::static_
;
5347 case DW_IDX_GNU_external
:
5348 if (!m_map
.augmentation_is_gdb
)
5350 symbol_linkage_
= symbol_linkage::extern_
;
5355 /* Skip if already read in. */
5356 if (per_cu
->v
.quick
->compunit_symtab
)
5359 /* Check static vs global. */
5360 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5362 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5363 const bool symbol_is_static
=
5364 symbol_linkage_
== symbol_linkage::static_
;
5365 if (want_static
!= symbol_is_static
)
5369 /* Match dw2_symtab_iter_next, symbol_kind
5370 and debug_names::psymbol_tag. */
5374 switch (indexval
.dwarf_tag
)
5376 case DW_TAG_variable
:
5377 case DW_TAG_subprogram
:
5378 /* Some types are also in VAR_DOMAIN. */
5379 case DW_TAG_typedef
:
5380 case DW_TAG_structure_type
:
5387 switch (indexval
.dwarf_tag
)
5389 case DW_TAG_typedef
:
5390 case DW_TAG_structure_type
:
5397 switch (indexval
.dwarf_tag
)
5400 case DW_TAG_variable
:
5407 switch (indexval
.dwarf_tag
)
5419 /* Match dw2_expand_symtabs_matching, symbol_kind and
5420 debug_names::psymbol_tag. */
5423 case VARIABLES_DOMAIN
:
5424 switch (indexval
.dwarf_tag
)
5426 case DW_TAG_variable
:
5432 case FUNCTIONS_DOMAIN
:
5433 switch (indexval
.dwarf_tag
)
5435 case DW_TAG_subprogram
:
5442 switch (indexval
.dwarf_tag
)
5444 case DW_TAG_typedef
:
5445 case DW_TAG_structure_type
:
5451 case MODULES_DOMAIN
:
5452 switch (indexval
.dwarf_tag
)
5466 static struct compunit_symtab
*
5467 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5468 const char *name
, domain_enum domain
)
5470 struct dwarf2_per_objfile
*dwarf2_per_objfile
5471 = get_dwarf2_per_objfile (objfile
);
5473 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5476 /* index is NULL if OBJF_READNOW. */
5479 const auto &map
= *mapp
;
5481 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5483 struct compunit_symtab
*stab_best
= NULL
;
5484 struct dwarf2_per_cu_data
*per_cu
;
5485 while ((per_cu
= iter
.next ()) != NULL
)
5487 struct symbol
*sym
, *with_opaque
= NULL
;
5488 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5489 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5490 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5492 sym
= block_find_symbol (block
, name
, domain
,
5493 block_find_non_opaque_type_preferred
,
5496 /* Some caution must be observed with overloaded functions and
5497 methods, since the index will not contain any overload
5498 information (but NAME might contain it). */
5501 && strcmp_iw (sym
->search_name (), name
) == 0)
5503 if (with_opaque
!= NULL
5504 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5507 /* Keep looking through other CUs. */
5513 /* This dumps minimal information about .debug_names. It is called
5514 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5515 uses this to verify that .debug_names has been loaded. */
5518 dw2_debug_names_dump (struct objfile
*objfile
)
5520 struct dwarf2_per_objfile
*dwarf2_per_objfile
5521 = get_dwarf2_per_objfile (objfile
);
5523 gdb_assert (dwarf2_per_objfile
->using_index
);
5524 printf_filtered (".debug_names:");
5525 if (dwarf2_per_objfile
->debug_names_table
)
5526 printf_filtered (" exists\n");
5528 printf_filtered (" faked for \"readnow\"\n");
5529 printf_filtered ("\n");
5533 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5534 const char *func_name
)
5536 struct dwarf2_per_objfile
*dwarf2_per_objfile
5537 = get_dwarf2_per_objfile (objfile
);
5539 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5540 if (dwarf2_per_objfile
->debug_names_table
)
5542 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5544 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5546 struct dwarf2_per_cu_data
*per_cu
;
5547 while ((per_cu
= iter
.next ()) != NULL
)
5548 dw2_instantiate_symtab (per_cu
, false);
5553 dw2_debug_names_map_matching_symbols
5554 (struct objfile
*objfile
,
5555 const lookup_name_info
&name
, domain_enum domain
,
5557 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5558 symbol_compare_ftype
*ordered_compare
)
5560 struct dwarf2_per_objfile
*dwarf2_per_objfile
5561 = get_dwarf2_per_objfile (objfile
);
5563 /* debug_names_table is NULL if OBJF_READNOW. */
5564 if (!dwarf2_per_objfile
->debug_names_table
)
5567 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5568 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5570 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5571 auto matcher
= [&] (const char *symname
)
5573 if (ordered_compare
== nullptr)
5575 return ordered_compare (symname
, match_name
) == 0;
5578 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5579 [&] (offset_type namei
)
5581 /* The name was matched, now expand corresponding CUs that were
5583 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5585 struct dwarf2_per_cu_data
*per_cu
;
5586 while ((per_cu
= iter
.next ()) != NULL
)
5587 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5591 /* It's a shame we couldn't do this inside the
5592 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5593 that have already been expanded. Instead, this loop matches what
5594 the psymtab code does. */
5595 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5597 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5598 if (cust
!= nullptr)
5600 const struct block
*block
5601 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5602 if (!iterate_over_symbols_terminated (block
, name
,
5610 dw2_debug_names_expand_symtabs_matching
5611 (struct objfile
*objfile
,
5612 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5613 const lookup_name_info
&lookup_name
,
5614 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5615 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5616 enum search_domain kind
)
5618 struct dwarf2_per_objfile
*dwarf2_per_objfile
5619 = get_dwarf2_per_objfile (objfile
);
5621 /* debug_names_table is NULL if OBJF_READNOW. */
5622 if (!dwarf2_per_objfile
->debug_names_table
)
5625 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5627 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5629 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5631 kind
, [&] (offset_type namei
)
5633 /* The name was matched, now expand corresponding CUs that were
5635 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5637 struct dwarf2_per_cu_data
*per_cu
;
5638 while ((per_cu
= iter
.next ()) != NULL
)
5639 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5645 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5648 dw2_find_last_source_symtab
,
5649 dw2_forget_cached_source_info
,
5650 dw2_map_symtabs_matching_filename
,
5651 dw2_debug_names_lookup_symbol
,
5653 dw2_debug_names_dump
,
5654 dw2_debug_names_expand_symtabs_for_function
,
5655 dw2_expand_all_symtabs
,
5656 dw2_expand_symtabs_with_fullname
,
5657 dw2_debug_names_map_matching_symbols
,
5658 dw2_debug_names_expand_symtabs_matching
,
5659 dw2_find_pc_sect_compunit_symtab
,
5661 dw2_map_symbol_filenames
5664 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5665 to either a dwarf2_per_objfile or dwz_file object. */
5667 template <typename T
>
5668 static gdb::array_view
<const gdb_byte
>
5669 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5671 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5673 if (section
->empty ())
5676 /* Older elfutils strip versions could keep the section in the main
5677 executable while splitting it for the separate debug info file. */
5678 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5681 section
->read (obj
);
5683 /* dwarf2_section_info::size is a bfd_size_type, while
5684 gdb::array_view works with size_t. On 32-bit hosts, with
5685 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5686 is 32-bit. So we need an explicit narrowing conversion here.
5687 This is fine, because it's impossible to allocate or mmap an
5688 array/buffer larger than what size_t can represent. */
5689 return gdb::make_array_view (section
->buffer
, section
->size
);
5692 /* Lookup the index cache for the contents of the index associated to
5695 static gdb::array_view
<const gdb_byte
>
5696 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5698 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5699 if (build_id
== nullptr)
5702 return global_index_cache
.lookup_gdb_index (build_id
,
5703 &dwarf2_obj
->index_cache_res
);
5706 /* Same as the above, but for DWZ. */
5708 static gdb::array_view
<const gdb_byte
>
5709 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5711 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5712 if (build_id
== nullptr)
5715 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5718 /* See symfile.h. */
5721 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5723 struct dwarf2_per_objfile
*dwarf2_per_objfile
5724 = get_dwarf2_per_objfile (objfile
);
5726 /* If we're about to read full symbols, don't bother with the
5727 indices. In this case we also don't care if some other debug
5728 format is making psymtabs, because they are all about to be
5730 if ((objfile
->flags
& OBJF_READNOW
))
5732 dwarf2_per_objfile
->using_index
= 1;
5733 create_all_comp_units (dwarf2_per_objfile
);
5734 create_all_type_units (dwarf2_per_objfile
);
5735 dwarf2_per_objfile
->quick_file_names_table
5736 = create_quick_file_names_table
5737 (dwarf2_per_objfile
->all_comp_units
.size ());
5739 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5740 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5742 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5744 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5745 struct dwarf2_per_cu_quick_data
);
5748 /* Return 1 so that gdb sees the "quick" functions. However,
5749 these functions will be no-ops because we will have expanded
5751 *index_kind
= dw_index_kind::GDB_INDEX
;
5755 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5757 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5761 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5762 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5763 get_gdb_index_contents_from_section
<dwz_file
>))
5765 *index_kind
= dw_index_kind::GDB_INDEX
;
5769 /* ... otherwise, try to find the index in the index cache. */
5770 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5771 get_gdb_index_contents_from_cache
,
5772 get_gdb_index_contents_from_cache_dwz
))
5774 global_index_cache
.hit ();
5775 *index_kind
= dw_index_kind::GDB_INDEX
;
5779 global_index_cache
.miss ();
5785 /* Build a partial symbol table. */
5788 dwarf2_build_psymtabs (struct objfile
*objfile
)
5790 struct dwarf2_per_objfile
*dwarf2_per_objfile
5791 = get_dwarf2_per_objfile (objfile
);
5793 init_psymbol_list (objfile
, 1024);
5797 /* This isn't really ideal: all the data we allocate on the
5798 objfile's obstack is still uselessly kept around. However,
5799 freeing it seems unsafe. */
5800 psymtab_discarder
psymtabs (objfile
);
5801 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5804 /* (maybe) store an index in the cache. */
5805 global_index_cache
.store (dwarf2_per_objfile
);
5807 catch (const gdb_exception_error
&except
)
5809 exception_print (gdb_stderr
, except
);
5813 /* Find the base address of the compilation unit for range lists and
5814 location lists. It will normally be specified by DW_AT_low_pc.
5815 In DWARF-3 draft 4, the base address could be overridden by
5816 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5817 compilation units with discontinuous ranges. */
5820 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5822 struct attribute
*attr
;
5825 cu
->base_address
= 0;
5827 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5828 if (attr
!= nullptr)
5830 cu
->base_address
= attr
->value_as_address ();
5835 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5836 if (attr
!= nullptr)
5838 cu
->base_address
= attr
->value_as_address ();
5844 /* Helper function that returns the proper abbrev section for
5847 static struct dwarf2_section_info
*
5848 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5850 struct dwarf2_section_info
*abbrev
;
5851 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5853 if (this_cu
->is_dwz
)
5854 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5856 abbrev
= &dwarf2_per_objfile
->abbrev
;
5861 /* Fetch the abbreviation table offset from a comp or type unit header. */
5864 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5865 struct dwarf2_section_info
*section
,
5866 sect_offset sect_off
)
5868 bfd
*abfd
= section
->get_bfd_owner ();
5869 const gdb_byte
*info_ptr
;
5870 unsigned int initial_length_size
, offset_size
;
5873 section
->read (dwarf2_per_objfile
->objfile
);
5874 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5875 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5876 offset_size
= initial_length_size
== 4 ? 4 : 8;
5877 info_ptr
+= initial_length_size
;
5879 version
= read_2_bytes (abfd
, info_ptr
);
5883 /* Skip unit type and address size. */
5887 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5890 /* A partial symtab that is used only for include files. */
5891 struct dwarf2_include_psymtab
: public partial_symtab
5893 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5894 : partial_symtab (filename
, objfile
)
5898 void read_symtab (struct objfile
*objfile
) override
5900 expand_psymtab (objfile
);
5903 void expand_psymtab (struct objfile
*objfile
) override
5907 /* It's an include file, no symbols to read for it.
5908 Everything is in the parent symtab. */
5909 read_dependencies (objfile
);
5913 bool readin_p () const override
5918 struct compunit_symtab
*get_compunit_symtab () const override
5925 bool m_readin
= false;
5928 /* Allocate a new partial symtab for file named NAME and mark this new
5929 partial symtab as being an include of PST. */
5932 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5933 struct objfile
*objfile
)
5935 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5937 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5939 /* It shares objfile->objfile_obstack. */
5940 subpst
->dirname
= pst
->dirname
;
5943 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5944 subpst
->dependencies
[0] = pst
;
5945 subpst
->number_of_dependencies
= 1;
5948 /* Read the Line Number Program data and extract the list of files
5949 included by the source file represented by PST. Build an include
5950 partial symtab for each of these included files. */
5953 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5954 struct die_info
*die
,
5955 dwarf2_psymtab
*pst
)
5958 struct attribute
*attr
;
5960 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5961 if (attr
!= nullptr)
5962 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5964 return; /* No linetable, so no includes. */
5966 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5967 that we pass in the raw text_low here; that is ok because we're
5968 only decoding the line table to make include partial symtabs, and
5969 so the addresses aren't really used. */
5970 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5971 pst
->raw_text_low (), 1);
5975 hash_signatured_type (const void *item
)
5977 const struct signatured_type
*sig_type
5978 = (const struct signatured_type
*) item
;
5980 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5981 return sig_type
->signature
;
5985 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5987 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5988 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5990 return lhs
->signature
== rhs
->signature
;
5993 /* Allocate a hash table for signatured types. */
5996 allocate_signatured_type_table ()
5998 return htab_up (htab_create_alloc (41,
5999 hash_signatured_type
,
6001 NULL
, xcalloc
, xfree
));
6004 /* A helper function to add a signatured type CU to a table. */
6007 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6009 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6010 std::vector
<signatured_type
*> *all_type_units
6011 = (std::vector
<signatured_type
*> *) datum
;
6013 all_type_units
->push_back (sigt
);
6018 /* A helper for create_debug_types_hash_table. Read types from SECTION
6019 and fill them into TYPES_HTAB. It will process only type units,
6020 therefore DW_UT_type. */
6023 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6024 struct dwo_file
*dwo_file
,
6025 dwarf2_section_info
*section
, htab_up
&types_htab
,
6026 rcuh_kind section_kind
)
6028 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6029 struct dwarf2_section_info
*abbrev_section
;
6031 const gdb_byte
*info_ptr
, *end_ptr
;
6033 abbrev_section
= (dwo_file
!= NULL
6034 ? &dwo_file
->sections
.abbrev
6035 : &dwarf2_per_objfile
->abbrev
);
6037 if (dwarf_read_debug
)
6038 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6039 section
->get_name (),
6040 abbrev_section
->get_file_name ());
6042 section
->read (objfile
);
6043 info_ptr
= section
->buffer
;
6045 if (info_ptr
== NULL
)
6048 /* We can't set abfd until now because the section may be empty or
6049 not present, in which case the bfd is unknown. */
6050 abfd
= section
->get_bfd_owner ();
6052 /* We don't use cutu_reader here because we don't need to read
6053 any dies: the signature is in the header. */
6055 end_ptr
= info_ptr
+ section
->size
;
6056 while (info_ptr
< end_ptr
)
6058 struct signatured_type
*sig_type
;
6059 struct dwo_unit
*dwo_tu
;
6061 const gdb_byte
*ptr
= info_ptr
;
6062 struct comp_unit_head header
;
6063 unsigned int length
;
6065 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6067 /* Initialize it due to a false compiler warning. */
6068 header
.signature
= -1;
6069 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6071 /* We need to read the type's signature in order to build the hash
6072 table, but we don't need anything else just yet. */
6074 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6075 abbrev_section
, ptr
, section_kind
);
6077 length
= header
.get_length ();
6079 /* Skip dummy type units. */
6080 if (ptr
>= info_ptr
+ length
6081 || peek_abbrev_code (abfd
, ptr
) == 0
6082 || header
.unit_type
!= DW_UT_type
)
6088 if (types_htab
== NULL
)
6091 types_htab
= allocate_dwo_unit_table ();
6093 types_htab
= allocate_signatured_type_table ();
6099 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6101 dwo_tu
->dwo_file
= dwo_file
;
6102 dwo_tu
->signature
= header
.signature
;
6103 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6104 dwo_tu
->section
= section
;
6105 dwo_tu
->sect_off
= sect_off
;
6106 dwo_tu
->length
= length
;
6110 /* N.B.: type_offset is not usable if this type uses a DWO file.
6111 The real type_offset is in the DWO file. */
6113 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6114 struct signatured_type
);
6115 sig_type
->signature
= header
.signature
;
6116 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6117 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6118 sig_type
->per_cu
.is_debug_types
= 1;
6119 sig_type
->per_cu
.section
= section
;
6120 sig_type
->per_cu
.sect_off
= sect_off
;
6121 sig_type
->per_cu
.length
= length
;
6124 slot
= htab_find_slot (types_htab
.get (),
6125 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6127 gdb_assert (slot
!= NULL
);
6130 sect_offset dup_sect_off
;
6134 const struct dwo_unit
*dup_tu
6135 = (const struct dwo_unit
*) *slot
;
6137 dup_sect_off
= dup_tu
->sect_off
;
6141 const struct signatured_type
*dup_tu
6142 = (const struct signatured_type
*) *slot
;
6144 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6147 complaint (_("debug type entry at offset %s is duplicate to"
6148 " the entry at offset %s, signature %s"),
6149 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6150 hex_string (header
.signature
));
6152 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6154 if (dwarf_read_debug
> 1)
6155 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6156 sect_offset_str (sect_off
),
6157 hex_string (header
.signature
));
6163 /* Create the hash table of all entries in the .debug_types
6164 (or .debug_types.dwo) section(s).
6165 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6166 otherwise it is NULL.
6168 The result is a pointer to the hash table or NULL if there are no types.
6170 Note: This function processes DWO files only, not DWP files. */
6173 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6174 struct dwo_file
*dwo_file
,
6175 gdb::array_view
<dwarf2_section_info
> type_sections
,
6176 htab_up
&types_htab
)
6178 for (dwarf2_section_info
§ion
: type_sections
)
6179 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6180 types_htab
, rcuh_kind::TYPE
);
6183 /* Create the hash table of all entries in the .debug_types section,
6184 and initialize all_type_units.
6185 The result is zero if there is an error (e.g. missing .debug_types section),
6186 otherwise non-zero. */
6189 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6193 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6194 &dwarf2_per_objfile
->info
, types_htab
,
6195 rcuh_kind::COMPILE
);
6196 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6197 dwarf2_per_objfile
->types
, types_htab
);
6198 if (types_htab
== NULL
)
6200 dwarf2_per_objfile
->signatured_types
= NULL
;
6204 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6206 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6207 dwarf2_per_objfile
->all_type_units
.reserve
6208 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6210 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6211 add_signatured_type_cu_to_table
,
6212 &dwarf2_per_objfile
->all_type_units
);
6217 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6218 If SLOT is non-NULL, it is the entry to use in the hash table.
6219 Otherwise we find one. */
6221 static struct signatured_type
*
6222 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6225 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6227 if (dwarf2_per_objfile
->all_type_units
.size ()
6228 == dwarf2_per_objfile
->all_type_units
.capacity ())
6229 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6231 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6232 struct signatured_type
);
6234 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6235 sig_type
->signature
= sig
;
6236 sig_type
->per_cu
.is_debug_types
= 1;
6237 if (dwarf2_per_objfile
->using_index
)
6239 sig_type
->per_cu
.v
.quick
=
6240 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6241 struct dwarf2_per_cu_quick_data
);
6246 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6249 gdb_assert (*slot
== NULL
);
6251 /* The rest of sig_type must be filled in by the caller. */
6255 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6256 Fill in SIG_ENTRY with DWO_ENTRY. */
6259 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6260 struct signatured_type
*sig_entry
,
6261 struct dwo_unit
*dwo_entry
)
6263 /* Make sure we're not clobbering something we don't expect to. */
6264 gdb_assert (! sig_entry
->per_cu
.queued
);
6265 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6266 if (dwarf2_per_objfile
->using_index
)
6268 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6269 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6272 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6273 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6274 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6275 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6276 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6278 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6279 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6280 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6281 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6282 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6283 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6284 sig_entry
->dwo_unit
= dwo_entry
;
6287 /* Subroutine of lookup_signatured_type.
6288 If we haven't read the TU yet, create the signatured_type data structure
6289 for a TU to be read in directly from a DWO file, bypassing the stub.
6290 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6291 using .gdb_index, then when reading a CU we want to stay in the DWO file
6292 containing that CU. Otherwise we could end up reading several other DWO
6293 files (due to comdat folding) to process the transitive closure of all the
6294 mentioned TUs, and that can be slow. The current DWO file will have every
6295 type signature that it needs.
6296 We only do this for .gdb_index because in the psymtab case we already have
6297 to read all the DWOs to build the type unit groups. */
6299 static struct signatured_type
*
6300 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6302 struct dwarf2_per_objfile
*dwarf2_per_objfile
6303 = cu
->per_cu
->dwarf2_per_objfile
;
6304 struct dwo_file
*dwo_file
;
6305 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6306 struct signatured_type find_sig_entry
, *sig_entry
;
6309 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6311 /* If TU skeletons have been removed then we may not have read in any
6313 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6314 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6316 /* We only ever need to read in one copy of a signatured type.
6317 Use the global signatured_types array to do our own comdat-folding
6318 of types. If this is the first time we're reading this TU, and
6319 the TU has an entry in .gdb_index, replace the recorded data from
6320 .gdb_index with this TU. */
6322 find_sig_entry
.signature
= sig
;
6323 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6324 &find_sig_entry
, INSERT
);
6325 sig_entry
= (struct signatured_type
*) *slot
;
6327 /* We can get here with the TU already read, *or* in the process of being
6328 read. Don't reassign the global entry to point to this DWO if that's
6329 the case. Also note that if the TU is already being read, it may not
6330 have come from a DWO, the program may be a mix of Fission-compiled
6331 code and non-Fission-compiled code. */
6333 /* Have we already tried to read this TU?
6334 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6335 needn't exist in the global table yet). */
6336 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6339 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6340 dwo_unit of the TU itself. */
6341 dwo_file
= cu
->dwo_unit
->dwo_file
;
6343 /* Ok, this is the first time we're reading this TU. */
6344 if (dwo_file
->tus
== NULL
)
6346 find_dwo_entry
.signature
= sig
;
6347 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6349 if (dwo_entry
== NULL
)
6352 /* If the global table doesn't have an entry for this TU, add one. */
6353 if (sig_entry
== NULL
)
6354 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6356 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6357 sig_entry
->per_cu
.tu_read
= 1;
6361 /* Subroutine of lookup_signatured_type.
6362 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6363 then try the DWP file. If the TU stub (skeleton) has been removed then
6364 it won't be in .gdb_index. */
6366 static struct signatured_type
*
6367 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6369 struct dwarf2_per_objfile
*dwarf2_per_objfile
6370 = cu
->per_cu
->dwarf2_per_objfile
;
6371 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6372 struct dwo_unit
*dwo_entry
;
6373 struct signatured_type find_sig_entry
, *sig_entry
;
6376 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6377 gdb_assert (dwp_file
!= NULL
);
6379 /* If TU skeletons have been removed then we may not have read in any
6381 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6382 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6384 find_sig_entry
.signature
= sig
;
6385 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6386 &find_sig_entry
, INSERT
);
6387 sig_entry
= (struct signatured_type
*) *slot
;
6389 /* Have we already tried to read this TU?
6390 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6391 needn't exist in the global table yet). */
6392 if (sig_entry
!= NULL
)
6395 if (dwp_file
->tus
== NULL
)
6397 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6398 sig
, 1 /* is_debug_types */);
6399 if (dwo_entry
== NULL
)
6402 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6403 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6408 /* Lookup a signature based type for DW_FORM_ref_sig8.
6409 Returns NULL if signature SIG is not present in the table.
6410 It is up to the caller to complain about this. */
6412 static struct signatured_type
*
6413 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6415 struct dwarf2_per_objfile
*dwarf2_per_objfile
6416 = cu
->per_cu
->dwarf2_per_objfile
;
6419 && dwarf2_per_objfile
->using_index
)
6421 /* We're in a DWO/DWP file, and we're using .gdb_index.
6422 These cases require special processing. */
6423 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6424 return lookup_dwo_signatured_type (cu
, sig
);
6426 return lookup_dwp_signatured_type (cu
, sig
);
6430 struct signatured_type find_entry
, *entry
;
6432 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6434 find_entry
.signature
= sig
;
6435 entry
= ((struct signatured_type
*)
6436 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6442 /* Return the address base of the compile unit, which, if exists, is stored
6443 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6444 static gdb::optional
<ULONGEST
>
6445 lookup_addr_base (struct die_info
*comp_unit_die
)
6447 struct attribute
*attr
;
6448 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6449 if (attr
== nullptr)
6450 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6451 if (attr
== nullptr)
6452 return gdb::optional
<ULONGEST
> ();
6453 return DW_UNSND (attr
);
6456 /* Return range lists base of the compile unit, which, if exists, is stored
6457 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6459 lookup_ranges_base (struct die_info
*comp_unit_die
)
6461 struct attribute
*attr
;
6462 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6463 if (attr
== nullptr)
6464 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6465 if (attr
== nullptr)
6467 return DW_UNSND (attr
);
6470 /* Low level DIE reading support. */
6472 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6475 init_cu_die_reader (struct die_reader_specs
*reader
,
6476 struct dwarf2_cu
*cu
,
6477 struct dwarf2_section_info
*section
,
6478 struct dwo_file
*dwo_file
,
6479 struct abbrev_table
*abbrev_table
)
6481 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6482 reader
->abfd
= section
->get_bfd_owner ();
6484 reader
->dwo_file
= dwo_file
;
6485 reader
->die_section
= section
;
6486 reader
->buffer
= section
->buffer
;
6487 reader
->buffer_end
= section
->buffer
+ section
->size
;
6488 reader
->abbrev_table
= abbrev_table
;
6491 /* Subroutine of cutu_reader to simplify it.
6492 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6493 There's just a lot of work to do, and cutu_reader is big enough
6496 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6497 from it to the DIE in the DWO. If NULL we are skipping the stub.
6498 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6499 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6500 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6501 STUB_COMP_DIR may be non-NULL.
6502 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6503 are filled in with the info of the DIE from the DWO file.
6504 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6505 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6506 kept around for at least as long as *RESULT_READER.
6508 The result is non-zero if a valid (non-dummy) DIE was found. */
6511 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6512 struct dwo_unit
*dwo_unit
,
6513 struct die_info
*stub_comp_unit_die
,
6514 const char *stub_comp_dir
,
6515 struct die_reader_specs
*result_reader
,
6516 const gdb_byte
**result_info_ptr
,
6517 struct die_info
**result_comp_unit_die
,
6518 abbrev_table_up
*result_dwo_abbrev_table
)
6520 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6521 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6522 struct dwarf2_cu
*cu
= this_cu
->cu
;
6524 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6525 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6526 int i
,num_extra_attrs
;
6527 struct dwarf2_section_info
*dwo_abbrev_section
;
6528 struct die_info
*comp_unit_die
;
6530 /* At most one of these may be provided. */
6531 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6533 /* These attributes aren't processed until later:
6534 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6535 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6536 referenced later. However, these attributes are found in the stub
6537 which we won't have later. In order to not impose this complication
6538 on the rest of the code, we read them here and copy them to the
6547 if (stub_comp_unit_die
!= NULL
)
6549 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6551 if (! this_cu
->is_debug_types
)
6552 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6553 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6554 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6555 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6556 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6558 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6560 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6561 here (if needed). We need the value before we can process
6563 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6565 else if (stub_comp_dir
!= NULL
)
6567 /* Reconstruct the comp_dir attribute to simplify the code below. */
6568 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6569 comp_dir
->name
= DW_AT_comp_dir
;
6570 comp_dir
->form
= DW_FORM_string
;
6571 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6572 DW_STRING (comp_dir
) = stub_comp_dir
;
6575 /* Set up for reading the DWO CU/TU. */
6576 cu
->dwo_unit
= dwo_unit
;
6577 dwarf2_section_info
*section
= dwo_unit
->section
;
6578 section
->read (objfile
);
6579 abfd
= section
->get_bfd_owner ();
6580 begin_info_ptr
= info_ptr
= (section
->buffer
6581 + to_underlying (dwo_unit
->sect_off
));
6582 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6584 if (this_cu
->is_debug_types
)
6586 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6588 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6589 &cu
->header
, section
,
6591 info_ptr
, rcuh_kind::TYPE
);
6592 /* This is not an assert because it can be caused by bad debug info. */
6593 if (sig_type
->signature
!= cu
->header
.signature
)
6595 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6596 " TU at offset %s [in module %s]"),
6597 hex_string (sig_type
->signature
),
6598 hex_string (cu
->header
.signature
),
6599 sect_offset_str (dwo_unit
->sect_off
),
6600 bfd_get_filename (abfd
));
6602 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6603 /* For DWOs coming from DWP files, we don't know the CU length
6604 nor the type's offset in the TU until now. */
6605 dwo_unit
->length
= cu
->header
.get_length ();
6606 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6608 /* Establish the type offset that can be used to lookup the type.
6609 For DWO files, we don't know it until now. */
6610 sig_type
->type_offset_in_section
6611 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6615 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6616 &cu
->header
, section
,
6618 info_ptr
, rcuh_kind::COMPILE
);
6619 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6620 /* For DWOs coming from DWP files, we don't know the CU length
6622 dwo_unit
->length
= cu
->header
.get_length ();
6625 *result_dwo_abbrev_table
6626 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6627 cu
->header
.abbrev_sect_off
);
6628 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6629 result_dwo_abbrev_table
->get ());
6631 /* Read in the die, but leave space to copy over the attributes
6632 from the stub. This has the benefit of simplifying the rest of
6633 the code - all the work to maintain the illusion of a single
6634 DW_TAG_{compile,type}_unit DIE is done here. */
6635 num_extra_attrs
= ((stmt_list
!= NULL
)
6639 + (comp_dir
!= NULL
));
6640 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6643 /* Copy over the attributes from the stub to the DIE we just read in. */
6644 comp_unit_die
= *result_comp_unit_die
;
6645 i
= comp_unit_die
->num_attrs
;
6646 if (stmt_list
!= NULL
)
6647 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6649 comp_unit_die
->attrs
[i
++] = *low_pc
;
6650 if (high_pc
!= NULL
)
6651 comp_unit_die
->attrs
[i
++] = *high_pc
;
6653 comp_unit_die
->attrs
[i
++] = *ranges
;
6654 if (comp_dir
!= NULL
)
6655 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6656 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6658 if (dwarf_die_debug
)
6660 fprintf_unfiltered (gdb_stdlog
,
6661 "Read die from %s@0x%x of %s:\n",
6662 section
->get_name (),
6663 (unsigned) (begin_info_ptr
- section
->buffer
),
6664 bfd_get_filename (abfd
));
6665 dump_die (comp_unit_die
, dwarf_die_debug
);
6668 /* Skip dummy compilation units. */
6669 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6670 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6673 *result_info_ptr
= info_ptr
;
6677 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6678 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6679 signature is part of the header. */
6680 static gdb::optional
<ULONGEST
>
6681 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6683 if (cu
->header
.version
>= 5)
6684 return cu
->header
.signature
;
6685 struct attribute
*attr
;
6686 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6687 if (attr
== nullptr)
6688 return gdb::optional
<ULONGEST
> ();
6689 return DW_UNSND (attr
);
6692 /* Subroutine of cutu_reader to simplify it.
6693 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6694 Returns NULL if the specified DWO unit cannot be found. */
6696 static struct dwo_unit
*
6697 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6698 struct die_info
*comp_unit_die
,
6699 const char *dwo_name
)
6701 struct dwarf2_cu
*cu
= this_cu
->cu
;
6702 struct dwo_unit
*dwo_unit
;
6703 const char *comp_dir
;
6705 gdb_assert (cu
!= NULL
);
6707 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6708 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6709 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6711 if (this_cu
->is_debug_types
)
6713 struct signatured_type
*sig_type
;
6715 /* Since this_cu is the first member of struct signatured_type,
6716 we can go from a pointer to one to a pointer to the other. */
6717 sig_type
= (struct signatured_type
*) this_cu
;
6718 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6722 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6723 if (!signature
.has_value ())
6724 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6726 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6727 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6734 /* Subroutine of cutu_reader to simplify it.
6735 See it for a description of the parameters.
6736 Read a TU directly from a DWO file, bypassing the stub. */
6739 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6740 int use_existing_cu
)
6742 struct signatured_type
*sig_type
;
6744 /* Verify we can do the following downcast, and that we have the
6746 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6747 sig_type
= (struct signatured_type
*) this_cu
;
6748 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6750 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6752 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6753 /* There's no need to do the rereading_dwo_cu handling that
6754 cutu_reader does since we don't read the stub. */
6758 /* If !use_existing_cu, this_cu->cu must be NULL. */
6759 gdb_assert (this_cu
->cu
== NULL
);
6760 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6763 /* A future optimization, if needed, would be to use an existing
6764 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6765 could share abbrev tables. */
6767 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6768 NULL
/* stub_comp_unit_die */,
6769 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6772 &m_dwo_abbrev_table
) == 0)
6779 /* Initialize a CU (or TU) and read its DIEs.
6780 If the CU defers to a DWO file, read the DWO file as well.
6782 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6783 Otherwise the table specified in the comp unit header is read in and used.
6784 This is an optimization for when we already have the abbrev table.
6786 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6787 Otherwise, a new CU is allocated with xmalloc. */
6789 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6790 struct abbrev_table
*abbrev_table
,
6791 int use_existing_cu
,
6793 : die_reader_specs
{},
6796 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6797 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6798 struct dwarf2_section_info
*section
= this_cu
->section
;
6799 bfd
*abfd
= section
->get_bfd_owner ();
6800 struct dwarf2_cu
*cu
;
6801 const gdb_byte
*begin_info_ptr
;
6802 struct signatured_type
*sig_type
= NULL
;
6803 struct dwarf2_section_info
*abbrev_section
;
6804 /* Non-zero if CU currently points to a DWO file and we need to
6805 reread it. When this happens we need to reread the skeleton die
6806 before we can reread the DWO file (this only applies to CUs, not TUs). */
6807 int rereading_dwo_cu
= 0;
6809 if (dwarf_die_debug
)
6810 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6811 this_cu
->is_debug_types
? "type" : "comp",
6812 sect_offset_str (this_cu
->sect_off
));
6814 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6815 file (instead of going through the stub), short-circuit all of this. */
6816 if (this_cu
->reading_dwo_directly
)
6818 /* Narrow down the scope of possibilities to have to understand. */
6819 gdb_assert (this_cu
->is_debug_types
);
6820 gdb_assert (abbrev_table
== NULL
);
6821 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6825 /* This is cheap if the section is already read in. */
6826 section
->read (objfile
);
6828 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6830 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6832 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6835 /* If this CU is from a DWO file we need to start over, we need to
6836 refetch the attributes from the skeleton CU.
6837 This could be optimized by retrieving those attributes from when we
6838 were here the first time: the previous comp_unit_die was stored in
6839 comp_unit_obstack. But there's no data yet that we need this
6841 if (cu
->dwo_unit
!= NULL
)
6842 rereading_dwo_cu
= 1;
6846 /* If !use_existing_cu, this_cu->cu must be NULL. */
6847 gdb_assert (this_cu
->cu
== NULL
);
6848 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6849 cu
= m_new_cu
.get ();
6852 /* Get the header. */
6853 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6855 /* We already have the header, there's no need to read it in again. */
6856 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6860 if (this_cu
->is_debug_types
)
6862 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6863 &cu
->header
, section
,
6864 abbrev_section
, info_ptr
,
6867 /* Since per_cu is the first member of struct signatured_type,
6868 we can go from a pointer to one to a pointer to the other. */
6869 sig_type
= (struct signatured_type
*) this_cu
;
6870 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6871 gdb_assert (sig_type
->type_offset_in_tu
6872 == cu
->header
.type_cu_offset_in_tu
);
6873 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6875 /* LENGTH has not been set yet for type units if we're
6876 using .gdb_index. */
6877 this_cu
->length
= cu
->header
.get_length ();
6879 /* Establish the type offset that can be used to lookup the type. */
6880 sig_type
->type_offset_in_section
=
6881 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6883 this_cu
->dwarf_version
= cu
->header
.version
;
6887 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6888 &cu
->header
, section
,
6891 rcuh_kind::COMPILE
);
6893 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6894 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6895 this_cu
->dwarf_version
= cu
->header
.version
;
6899 /* Skip dummy compilation units. */
6900 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6901 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6907 /* If we don't have them yet, read the abbrevs for this compilation unit.
6908 And if we need to read them now, make sure they're freed when we're
6910 if (abbrev_table
!= NULL
)
6911 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6914 m_abbrev_table_holder
6915 = abbrev_table::read (objfile
, abbrev_section
,
6916 cu
->header
.abbrev_sect_off
);
6917 abbrev_table
= m_abbrev_table_holder
.get ();
6920 /* Read the top level CU/TU die. */
6921 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6922 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6924 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6930 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6931 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6932 table from the DWO file and pass the ownership over to us. It will be
6933 referenced from READER, so we must make sure to free it after we're done
6936 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6937 DWO CU, that this test will fail (the attribute will not be present). */
6938 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6939 if (dwo_name
!= nullptr)
6941 struct dwo_unit
*dwo_unit
;
6942 struct die_info
*dwo_comp_unit_die
;
6944 if (comp_unit_die
->has_children
)
6946 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6947 " has children (offset %s) [in module %s]"),
6948 sect_offset_str (this_cu
->sect_off
),
6949 bfd_get_filename (abfd
));
6951 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6952 if (dwo_unit
!= NULL
)
6954 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6955 comp_unit_die
, NULL
,
6958 &m_dwo_abbrev_table
) == 0)
6964 comp_unit_die
= dwo_comp_unit_die
;
6968 /* Yikes, we couldn't find the rest of the DIE, we only have
6969 the stub. A complaint has already been logged. There's
6970 not much more we can do except pass on the stub DIE to
6971 die_reader_func. We don't want to throw an error on bad
6978 cutu_reader::keep ()
6980 /* Done, clean up. */
6981 gdb_assert (!dummy_p
);
6982 if (m_new_cu
!= NULL
)
6984 struct dwarf2_per_objfile
*dwarf2_per_objfile
6985 = m_this_cu
->dwarf2_per_objfile
;
6986 /* Link this CU into read_in_chain. */
6987 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6988 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6989 /* The chain owns it now. */
6990 m_new_cu
.release ();
6994 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6995 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6996 assumed to have already done the lookup to find the DWO file).
6998 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6999 THIS_CU->is_debug_types, but nothing else.
7001 We fill in THIS_CU->length.
7003 THIS_CU->cu is always freed when done.
7004 This is done in order to not leave THIS_CU->cu in a state where we have
7005 to care whether it refers to the "main" CU or the DWO CU.
7007 When parent_cu is passed, it is used to provide a default value for
7008 str_offsets_base and addr_base from the parent. */
7010 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7011 struct dwarf2_cu
*parent_cu
,
7012 struct dwo_file
*dwo_file
)
7013 : die_reader_specs
{},
7016 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7017 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7018 struct dwarf2_section_info
*section
= this_cu
->section
;
7019 bfd
*abfd
= section
->get_bfd_owner ();
7020 struct dwarf2_section_info
*abbrev_section
;
7021 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7023 if (dwarf_die_debug
)
7024 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7025 this_cu
->is_debug_types
? "type" : "comp",
7026 sect_offset_str (this_cu
->sect_off
));
7028 gdb_assert (this_cu
->cu
== NULL
);
7030 abbrev_section
= (dwo_file
!= NULL
7031 ? &dwo_file
->sections
.abbrev
7032 : get_abbrev_section_for_cu (this_cu
));
7034 /* This is cheap if the section is already read in. */
7035 section
->read (objfile
);
7037 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7039 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7040 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7041 &m_new_cu
->header
, section
,
7042 abbrev_section
, info_ptr
,
7043 (this_cu
->is_debug_types
7045 : rcuh_kind::COMPILE
));
7047 if (parent_cu
!= nullptr)
7049 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7050 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7052 this_cu
->length
= m_new_cu
->header
.get_length ();
7054 /* Skip dummy compilation units. */
7055 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7056 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7062 m_abbrev_table_holder
7063 = abbrev_table::read (objfile
, abbrev_section
,
7064 m_new_cu
->header
.abbrev_sect_off
);
7066 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7067 m_abbrev_table_holder
.get ());
7068 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7072 /* Type Unit Groups.
7074 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7075 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7076 so that all types coming from the same compilation (.o file) are grouped
7077 together. A future step could be to put the types in the same symtab as
7078 the CU the types ultimately came from. */
7081 hash_type_unit_group (const void *item
)
7083 const struct type_unit_group
*tu_group
7084 = (const struct type_unit_group
*) item
;
7086 return hash_stmt_list_entry (&tu_group
->hash
);
7090 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7092 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7093 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7095 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7098 /* Allocate a hash table for type unit groups. */
7101 allocate_type_unit_groups_table ()
7103 return htab_up (htab_create_alloc (3,
7104 hash_type_unit_group
,
7106 NULL
, xcalloc
, xfree
));
7109 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7110 partial symtabs. We combine several TUs per psymtab to not let the size
7111 of any one psymtab grow too big. */
7112 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7113 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7115 /* Helper routine for get_type_unit_group.
7116 Create the type_unit_group object used to hold one or more TUs. */
7118 static struct type_unit_group
*
7119 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7121 struct dwarf2_per_objfile
*dwarf2_per_objfile
7122 = cu
->per_cu
->dwarf2_per_objfile
;
7123 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7124 struct dwarf2_per_cu_data
*per_cu
;
7125 struct type_unit_group
*tu_group
;
7127 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7128 struct type_unit_group
);
7129 per_cu
= &tu_group
->per_cu
;
7130 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7132 if (dwarf2_per_objfile
->using_index
)
7134 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7135 struct dwarf2_per_cu_quick_data
);
7139 unsigned int line_offset
= to_underlying (line_offset_struct
);
7140 dwarf2_psymtab
*pst
;
7143 /* Give the symtab a useful name for debug purposes. */
7144 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7145 name
= string_printf ("<type_units_%d>",
7146 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7148 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7150 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7151 pst
->anonymous
= true;
7154 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7155 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7160 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7161 STMT_LIST is a DW_AT_stmt_list attribute. */
7163 static struct type_unit_group
*
7164 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7166 struct dwarf2_per_objfile
*dwarf2_per_objfile
7167 = cu
->per_cu
->dwarf2_per_objfile
;
7168 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7169 struct type_unit_group
*tu_group
;
7171 unsigned int line_offset
;
7172 struct type_unit_group type_unit_group_for_lookup
;
7174 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7175 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7177 /* Do we need to create a new group, or can we use an existing one? */
7181 line_offset
= DW_UNSND (stmt_list
);
7182 ++tu_stats
->nr_symtab_sharers
;
7186 /* Ugh, no stmt_list. Rare, but we have to handle it.
7187 We can do various things here like create one group per TU or
7188 spread them over multiple groups to split up the expansion work.
7189 To avoid worst case scenarios (too many groups or too large groups)
7190 we, umm, group them in bunches. */
7191 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7192 | (tu_stats
->nr_stmt_less_type_units
7193 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7194 ++tu_stats
->nr_stmt_less_type_units
;
7197 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7198 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7199 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7200 &type_unit_group_for_lookup
, INSERT
);
7203 tu_group
= (struct type_unit_group
*) *slot
;
7204 gdb_assert (tu_group
!= NULL
);
7208 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7209 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7211 ++tu_stats
->nr_symtabs
;
7217 /* Partial symbol tables. */
7219 /* Create a psymtab named NAME and assign it to PER_CU.
7221 The caller must fill in the following details:
7222 dirname, textlow, texthigh. */
7224 static dwarf2_psymtab
*
7225 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7227 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7228 dwarf2_psymtab
*pst
;
7230 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7232 pst
->psymtabs_addrmap_supported
= true;
7234 /* This is the glue that links PST into GDB's symbol API. */
7235 pst
->per_cu_data
= per_cu
;
7236 per_cu
->v
.psymtab
= pst
;
7241 /* DIE reader function for process_psymtab_comp_unit. */
7244 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7245 const gdb_byte
*info_ptr
,
7246 struct die_info
*comp_unit_die
,
7247 enum language pretend_language
)
7249 struct dwarf2_cu
*cu
= reader
->cu
;
7250 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7251 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7252 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7254 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7255 dwarf2_psymtab
*pst
;
7256 enum pc_bounds_kind cu_bounds_kind
;
7257 const char *filename
;
7259 gdb_assert (! per_cu
->is_debug_types
);
7261 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7263 /* Allocate a new partial symbol table structure. */
7264 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7265 static const char artificial
[] = "<artificial>";
7266 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7267 if (filename
== NULL
)
7269 else if (strcmp (filename
, artificial
) == 0)
7271 debug_filename
.reset (concat (artificial
, "@",
7272 sect_offset_str (per_cu
->sect_off
),
7274 filename
= debug_filename
.get ();
7277 pst
= create_partial_symtab (per_cu
, filename
);
7279 /* This must be done before calling dwarf2_build_include_psymtabs. */
7280 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7282 baseaddr
= objfile
->text_section_offset ();
7284 dwarf2_find_base_address (comp_unit_die
, cu
);
7286 /* Possibly set the default values of LOWPC and HIGHPC from
7288 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7289 &best_highpc
, cu
, pst
);
7290 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7293 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7296 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7298 /* Store the contiguous range if it is not empty; it can be
7299 empty for CUs with no code. */
7300 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7304 /* Check if comp unit has_children.
7305 If so, read the rest of the partial symbols from this comp unit.
7306 If not, there's no more debug_info for this comp unit. */
7307 if (comp_unit_die
->has_children
)
7309 struct partial_die_info
*first_die
;
7310 CORE_ADDR lowpc
, highpc
;
7312 lowpc
= ((CORE_ADDR
) -1);
7313 highpc
= ((CORE_ADDR
) 0);
7315 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7317 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7318 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7320 /* If we didn't find a lowpc, set it to highpc to avoid
7321 complaints from `maint check'. */
7322 if (lowpc
== ((CORE_ADDR
) -1))
7325 /* If the compilation unit didn't have an explicit address range,
7326 then use the information extracted from its child dies. */
7327 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7330 best_highpc
= highpc
;
7333 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7334 best_lowpc
+ baseaddr
)
7336 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7337 best_highpc
+ baseaddr
)
7340 end_psymtab_common (objfile
, pst
);
7342 if (!cu
->per_cu
->imported_symtabs_empty ())
7345 int len
= cu
->per_cu
->imported_symtabs_size ();
7347 /* Fill in 'dependencies' here; we fill in 'users' in a
7349 pst
->number_of_dependencies
= len
;
7351 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7352 for (i
= 0; i
< len
; ++i
)
7354 pst
->dependencies
[i
]
7355 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7358 cu
->per_cu
->imported_symtabs_free ();
7361 /* Get the list of files included in the current compilation unit,
7362 and build a psymtab for each of them. */
7363 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7365 if (dwarf_read_debug
)
7366 fprintf_unfiltered (gdb_stdlog
,
7367 "Psymtab for %s unit @%s: %s - %s"
7368 ", %d global, %d static syms\n",
7369 per_cu
->is_debug_types
? "type" : "comp",
7370 sect_offset_str (per_cu
->sect_off
),
7371 paddress (gdbarch
, pst
->text_low (objfile
)),
7372 paddress (gdbarch
, pst
->text_high (objfile
)),
7373 pst
->n_global_syms
, pst
->n_static_syms
);
7376 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7377 Process compilation unit THIS_CU for a psymtab. */
7380 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7381 bool want_partial_unit
,
7382 enum language pretend_language
)
7384 /* If this compilation unit was already read in, free the
7385 cached copy in order to read it in again. This is
7386 necessary because we skipped some symbols when we first
7387 read in the compilation unit (see load_partial_dies).
7388 This problem could be avoided, but the benefit is unclear. */
7389 if (this_cu
->cu
!= NULL
)
7390 free_one_cached_comp_unit (this_cu
);
7392 cutu_reader
reader (this_cu
, NULL
, 0, false);
7394 switch (reader
.comp_unit_die
->tag
)
7396 case DW_TAG_compile_unit
:
7397 this_cu
->unit_type
= DW_UT_compile
;
7399 case DW_TAG_partial_unit
:
7400 this_cu
->unit_type
= DW_UT_partial
;
7410 else if (this_cu
->is_debug_types
)
7411 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7412 reader
.comp_unit_die
);
7413 else if (want_partial_unit
7414 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7415 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7416 reader
.comp_unit_die
,
7419 this_cu
->lang
= this_cu
->cu
->language
;
7421 /* Age out any secondary CUs. */
7422 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7425 /* Reader function for build_type_psymtabs. */
7428 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7429 const gdb_byte
*info_ptr
,
7430 struct die_info
*type_unit_die
)
7432 struct dwarf2_per_objfile
*dwarf2_per_objfile
7433 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7434 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7435 struct dwarf2_cu
*cu
= reader
->cu
;
7436 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7437 struct signatured_type
*sig_type
;
7438 struct type_unit_group
*tu_group
;
7439 struct attribute
*attr
;
7440 struct partial_die_info
*first_die
;
7441 CORE_ADDR lowpc
, highpc
;
7442 dwarf2_psymtab
*pst
;
7444 gdb_assert (per_cu
->is_debug_types
);
7445 sig_type
= (struct signatured_type
*) per_cu
;
7447 if (! type_unit_die
->has_children
)
7450 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7451 tu_group
= get_type_unit_group (cu
, attr
);
7453 if (tu_group
->tus
== nullptr)
7454 tu_group
->tus
= new std::vector
<signatured_type
*>;
7455 tu_group
->tus
->push_back (sig_type
);
7457 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7458 pst
= create_partial_symtab (per_cu
, "");
7459 pst
->anonymous
= true;
7461 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7463 lowpc
= (CORE_ADDR
) -1;
7464 highpc
= (CORE_ADDR
) 0;
7465 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7467 end_psymtab_common (objfile
, pst
);
7470 /* Struct used to sort TUs by their abbreviation table offset. */
7472 struct tu_abbrev_offset
7474 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7475 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7478 signatured_type
*sig_type
;
7479 sect_offset abbrev_offset
;
7482 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7485 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7486 const struct tu_abbrev_offset
&b
)
7488 return a
.abbrev_offset
< b
.abbrev_offset
;
7491 /* Efficiently read all the type units.
7492 This does the bulk of the work for build_type_psymtabs.
7494 The efficiency is because we sort TUs by the abbrev table they use and
7495 only read each abbrev table once. In one program there are 200K TUs
7496 sharing 8K abbrev tables.
7498 The main purpose of this function is to support building the
7499 dwarf2_per_objfile->type_unit_groups table.
7500 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7501 can collapse the search space by grouping them by stmt_list.
7502 The savings can be significant, in the same program from above the 200K TUs
7503 share 8K stmt_list tables.
7505 FUNC is expected to call get_type_unit_group, which will create the
7506 struct type_unit_group if necessary and add it to
7507 dwarf2_per_objfile->type_unit_groups. */
7510 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7512 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7513 abbrev_table_up abbrev_table
;
7514 sect_offset abbrev_offset
;
7516 /* It's up to the caller to not call us multiple times. */
7517 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7519 if (dwarf2_per_objfile
->all_type_units
.empty ())
7522 /* TUs typically share abbrev tables, and there can be way more TUs than
7523 abbrev tables. Sort by abbrev table to reduce the number of times we
7524 read each abbrev table in.
7525 Alternatives are to punt or to maintain a cache of abbrev tables.
7526 This is simpler and efficient enough for now.
7528 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7529 symtab to use). Typically TUs with the same abbrev offset have the same
7530 stmt_list value too so in practice this should work well.
7532 The basic algorithm here is:
7534 sort TUs by abbrev table
7535 for each TU with same abbrev table:
7536 read abbrev table if first user
7537 read TU top level DIE
7538 [IWBN if DWO skeletons had DW_AT_stmt_list]
7541 if (dwarf_read_debug
)
7542 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7544 /* Sort in a separate table to maintain the order of all_type_units
7545 for .gdb_index: TU indices directly index all_type_units. */
7546 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7547 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7549 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7550 sorted_by_abbrev
.emplace_back
7551 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7552 sig_type
->per_cu
.section
,
7553 sig_type
->per_cu
.sect_off
));
7555 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7556 sort_tu_by_abbrev_offset
);
7558 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7560 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7562 /* Switch to the next abbrev table if necessary. */
7563 if (abbrev_table
== NULL
7564 || tu
.abbrev_offset
!= abbrev_offset
)
7566 abbrev_offset
= tu
.abbrev_offset
;
7568 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7569 &dwarf2_per_objfile
->abbrev
,
7571 ++tu_stats
->nr_uniq_abbrev_tables
;
7574 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7576 if (!reader
.dummy_p
)
7577 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7578 reader
.comp_unit_die
);
7582 /* Print collected type unit statistics. */
7585 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7587 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7589 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7590 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7591 dwarf2_per_objfile
->all_type_units
.size ());
7592 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7593 tu_stats
->nr_uniq_abbrev_tables
);
7594 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7595 tu_stats
->nr_symtabs
);
7596 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7597 tu_stats
->nr_symtab_sharers
);
7598 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7599 tu_stats
->nr_stmt_less_type_units
);
7600 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7601 tu_stats
->nr_all_type_units_reallocs
);
7604 /* Traversal function for build_type_psymtabs. */
7607 build_type_psymtab_dependencies (void **slot
, void *info
)
7609 struct dwarf2_per_objfile
*dwarf2_per_objfile
7610 = (struct dwarf2_per_objfile
*) info
;
7611 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7612 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7613 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7614 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7615 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7618 gdb_assert (len
> 0);
7619 gdb_assert (per_cu
->type_unit_group_p ());
7621 pst
->number_of_dependencies
= len
;
7622 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7623 for (i
= 0; i
< len
; ++i
)
7625 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7626 gdb_assert (iter
->per_cu
.is_debug_types
);
7627 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7628 iter
->type_unit_group
= tu_group
;
7631 delete tu_group
->tus
;
7632 tu_group
->tus
= nullptr;
7637 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7638 Build partial symbol tables for the .debug_types comp-units. */
7641 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7643 if (! create_all_type_units (dwarf2_per_objfile
))
7646 build_type_psymtabs_1 (dwarf2_per_objfile
);
7649 /* Traversal function for process_skeletonless_type_unit.
7650 Read a TU in a DWO file and build partial symbols for it. */
7653 process_skeletonless_type_unit (void **slot
, void *info
)
7655 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7656 struct dwarf2_per_objfile
*dwarf2_per_objfile
7657 = (struct dwarf2_per_objfile
*) info
;
7658 struct signatured_type find_entry
, *entry
;
7660 /* If this TU doesn't exist in the global table, add it and read it in. */
7662 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7663 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7665 find_entry
.signature
= dwo_unit
->signature
;
7666 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7667 &find_entry
, INSERT
);
7668 /* If we've already seen this type there's nothing to do. What's happening
7669 is we're doing our own version of comdat-folding here. */
7673 /* This does the job that create_all_type_units would have done for
7675 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7676 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7679 /* This does the job that build_type_psymtabs_1 would have done. */
7680 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7681 if (!reader
.dummy_p
)
7682 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7683 reader
.comp_unit_die
);
7688 /* Traversal function for process_skeletonless_type_units. */
7691 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7693 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7695 if (dwo_file
->tus
!= NULL
)
7696 htab_traverse_noresize (dwo_file
->tus
.get (),
7697 process_skeletonless_type_unit
, info
);
7702 /* Scan all TUs of DWO files, verifying we've processed them.
7703 This is needed in case a TU was emitted without its skeleton.
7704 Note: This can't be done until we know what all the DWO files are. */
7707 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7709 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7710 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7711 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7713 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7714 process_dwo_file_for_skeletonless_type_units
,
7715 dwarf2_per_objfile
);
7719 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7722 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7724 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7726 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7731 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7733 /* Set the 'user' field only if it is not already set. */
7734 if (pst
->dependencies
[j
]->user
== NULL
)
7735 pst
->dependencies
[j
]->user
= pst
;
7740 /* Build the partial symbol table by doing a quick pass through the
7741 .debug_info and .debug_abbrev sections. */
7744 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7746 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7748 if (dwarf_read_debug
)
7750 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7751 objfile_name (objfile
));
7754 scoped_restore restore_reading_psyms
7755 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7758 dwarf2_per_objfile
->info
.read (objfile
);
7760 /* Any cached compilation units will be linked by the per-objfile
7761 read_in_chain. Make sure to free them when we're done. */
7762 free_cached_comp_units
freer (dwarf2_per_objfile
);
7764 build_type_psymtabs (dwarf2_per_objfile
);
7766 create_all_comp_units (dwarf2_per_objfile
);
7768 /* Create a temporary address map on a temporary obstack. We later
7769 copy this to the final obstack. */
7770 auto_obstack temp_obstack
;
7772 scoped_restore save_psymtabs_addrmap
7773 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7774 addrmap_create_mutable (&temp_obstack
));
7776 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7777 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7779 /* This has to wait until we read the CUs, we need the list of DWOs. */
7780 process_skeletonless_type_units (dwarf2_per_objfile
);
7782 /* Now that all TUs have been processed we can fill in the dependencies. */
7783 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7785 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7786 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7789 if (dwarf_read_debug
)
7790 print_tu_stats (dwarf2_per_objfile
);
7792 set_partial_user (dwarf2_per_objfile
);
7794 objfile
->partial_symtabs
->psymtabs_addrmap
7795 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7796 objfile
->partial_symtabs
->obstack ());
7797 /* At this point we want to keep the address map. */
7798 save_psymtabs_addrmap
.release ();
7800 if (dwarf_read_debug
)
7801 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7802 objfile_name (objfile
));
7805 /* Load the partial DIEs for a secondary CU into memory.
7806 This is also used when rereading a primary CU with load_all_dies. */
7809 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7811 cutu_reader
reader (this_cu
, NULL
, 1, false);
7813 if (!reader
.dummy_p
)
7815 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7818 /* Check if comp unit has_children.
7819 If so, read the rest of the partial symbols from this comp unit.
7820 If not, there's no more debug_info for this comp unit. */
7821 if (reader
.comp_unit_die
->has_children
)
7822 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7829 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7830 struct dwarf2_section_info
*section
,
7831 struct dwarf2_section_info
*abbrev_section
,
7832 unsigned int is_dwz
)
7834 const gdb_byte
*info_ptr
;
7835 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7837 if (dwarf_read_debug
)
7838 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7839 section
->get_name (),
7840 section
->get_file_name ());
7842 section
->read (objfile
);
7844 info_ptr
= section
->buffer
;
7846 while (info_ptr
< section
->buffer
+ section
->size
)
7848 struct dwarf2_per_cu_data
*this_cu
;
7850 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7852 comp_unit_head cu_header
;
7853 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7854 abbrev_section
, info_ptr
,
7855 rcuh_kind::COMPILE
);
7857 /* Save the compilation unit for later lookup. */
7858 if (cu_header
.unit_type
!= DW_UT_type
)
7860 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7861 struct dwarf2_per_cu_data
);
7862 memset (this_cu
, 0, sizeof (*this_cu
));
7866 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7867 struct signatured_type
);
7868 memset (sig_type
, 0, sizeof (*sig_type
));
7869 sig_type
->signature
= cu_header
.signature
;
7870 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7871 this_cu
= &sig_type
->per_cu
;
7873 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7874 this_cu
->sect_off
= sect_off
;
7875 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7876 this_cu
->is_dwz
= is_dwz
;
7877 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7878 this_cu
->section
= section
;
7880 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7882 info_ptr
= info_ptr
+ this_cu
->length
;
7886 /* Create a list of all compilation units in OBJFILE.
7887 This is only done for -readnow and building partial symtabs. */
7890 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7892 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7893 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7894 &dwarf2_per_objfile
->abbrev
, 0);
7896 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7898 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7902 /* Process all loaded DIEs for compilation unit CU, starting at
7903 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7904 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7905 DW_AT_ranges). See the comments of add_partial_subprogram on how
7906 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7909 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7910 CORE_ADDR
*highpc
, int set_addrmap
,
7911 struct dwarf2_cu
*cu
)
7913 struct partial_die_info
*pdi
;
7915 /* Now, march along the PDI's, descending into ones which have
7916 interesting children but skipping the children of the other ones,
7917 until we reach the end of the compilation unit. */
7925 /* Anonymous namespaces or modules have no name but have interesting
7926 children, so we need to look at them. Ditto for anonymous
7929 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7930 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7931 || pdi
->tag
== DW_TAG_imported_unit
7932 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7936 case DW_TAG_subprogram
:
7937 case DW_TAG_inlined_subroutine
:
7938 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7940 case DW_TAG_constant
:
7941 case DW_TAG_variable
:
7942 case DW_TAG_typedef
:
7943 case DW_TAG_union_type
:
7944 if (!pdi
->is_declaration
)
7946 add_partial_symbol (pdi
, cu
);
7949 case DW_TAG_class_type
:
7950 case DW_TAG_interface_type
:
7951 case DW_TAG_structure_type
:
7952 if (!pdi
->is_declaration
)
7954 add_partial_symbol (pdi
, cu
);
7956 if ((cu
->language
== language_rust
7957 || cu
->language
== language_cplus
) && pdi
->has_children
)
7958 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7961 case DW_TAG_enumeration_type
:
7962 if (!pdi
->is_declaration
)
7963 add_partial_enumeration (pdi
, cu
);
7965 case DW_TAG_base_type
:
7966 case DW_TAG_subrange_type
:
7967 /* File scope base type definitions are added to the partial
7969 add_partial_symbol (pdi
, cu
);
7971 case DW_TAG_namespace
:
7972 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7975 if (!pdi
->is_declaration
)
7976 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7978 case DW_TAG_imported_unit
:
7980 struct dwarf2_per_cu_data
*per_cu
;
7982 /* For now we don't handle imported units in type units. */
7983 if (cu
->per_cu
->is_debug_types
)
7985 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7986 " supported in type units [in module %s]"),
7987 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7990 per_cu
= dwarf2_find_containing_comp_unit
7991 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7992 cu
->per_cu
->dwarf2_per_objfile
);
7994 /* Go read the partial unit, if needed. */
7995 if (per_cu
->v
.psymtab
== NULL
)
7996 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7998 cu
->per_cu
->imported_symtabs_push (per_cu
);
8001 case DW_TAG_imported_declaration
:
8002 add_partial_symbol (pdi
, cu
);
8009 /* If the die has a sibling, skip to the sibling. */
8011 pdi
= pdi
->die_sibling
;
8015 /* Functions used to compute the fully scoped name of a partial DIE.
8017 Normally, this is simple. For C++, the parent DIE's fully scoped
8018 name is concatenated with "::" and the partial DIE's name.
8019 Enumerators are an exception; they use the scope of their parent
8020 enumeration type, i.e. the name of the enumeration type is not
8021 prepended to the enumerator.
8023 There are two complexities. One is DW_AT_specification; in this
8024 case "parent" means the parent of the target of the specification,
8025 instead of the direct parent of the DIE. The other is compilers
8026 which do not emit DW_TAG_namespace; in this case we try to guess
8027 the fully qualified name of structure types from their members'
8028 linkage names. This must be done using the DIE's children rather
8029 than the children of any DW_AT_specification target. We only need
8030 to do this for structures at the top level, i.e. if the target of
8031 any DW_AT_specification (if any; otherwise the DIE itself) does not
8034 /* Compute the scope prefix associated with PDI's parent, in
8035 compilation unit CU. The result will be allocated on CU's
8036 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8037 field. NULL is returned if no prefix is necessary. */
8039 partial_die_parent_scope (struct partial_die_info
*pdi
,
8040 struct dwarf2_cu
*cu
)
8042 const char *grandparent_scope
;
8043 struct partial_die_info
*parent
, *real_pdi
;
8045 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8046 then this means the parent of the specification DIE. */
8049 while (real_pdi
->has_specification
)
8051 auto res
= find_partial_die (real_pdi
->spec_offset
,
8052 real_pdi
->spec_is_dwz
, cu
);
8057 parent
= real_pdi
->die_parent
;
8061 if (parent
->scope_set
)
8062 return parent
->scope
;
8066 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8068 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8069 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8070 Work around this problem here. */
8071 if (cu
->language
== language_cplus
8072 && parent
->tag
== DW_TAG_namespace
8073 && strcmp (parent
->name
, "::") == 0
8074 && grandparent_scope
== NULL
)
8076 parent
->scope
= NULL
;
8077 parent
->scope_set
= 1;
8081 /* Nested subroutines in Fortran get a prefix. */
8082 if (pdi
->tag
== DW_TAG_enumerator
)
8083 /* Enumerators should not get the name of the enumeration as a prefix. */
8084 parent
->scope
= grandparent_scope
;
8085 else if (parent
->tag
== DW_TAG_namespace
8086 || parent
->tag
== DW_TAG_module
8087 || parent
->tag
== DW_TAG_structure_type
8088 || parent
->tag
== DW_TAG_class_type
8089 || parent
->tag
== DW_TAG_interface_type
8090 || parent
->tag
== DW_TAG_union_type
8091 || parent
->tag
== DW_TAG_enumeration_type
8092 || (cu
->language
== language_fortran
8093 && parent
->tag
== DW_TAG_subprogram
8094 && pdi
->tag
== DW_TAG_subprogram
))
8096 if (grandparent_scope
== NULL
)
8097 parent
->scope
= parent
->name
;
8099 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8101 parent
->name
, 0, cu
);
8105 /* FIXME drow/2004-04-01: What should we be doing with
8106 function-local names? For partial symbols, we should probably be
8108 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8109 dwarf_tag_name (parent
->tag
),
8110 sect_offset_str (pdi
->sect_off
));
8111 parent
->scope
= grandparent_scope
;
8114 parent
->scope_set
= 1;
8115 return parent
->scope
;
8118 /* Return the fully scoped name associated with PDI, from compilation unit
8119 CU. The result will be allocated with malloc. */
8121 static gdb::unique_xmalloc_ptr
<char>
8122 partial_die_full_name (struct partial_die_info
*pdi
,
8123 struct dwarf2_cu
*cu
)
8125 const char *parent_scope
;
8127 /* If this is a template instantiation, we can not work out the
8128 template arguments from partial DIEs. So, unfortunately, we have
8129 to go through the full DIEs. At least any work we do building
8130 types here will be reused if full symbols are loaded later. */
8131 if (pdi
->has_template_arguments
)
8135 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8137 struct die_info
*die
;
8138 struct attribute attr
;
8139 struct dwarf2_cu
*ref_cu
= cu
;
8141 /* DW_FORM_ref_addr is using section offset. */
8142 attr
.name
= (enum dwarf_attribute
) 0;
8143 attr
.form
= DW_FORM_ref_addr
;
8144 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8145 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8147 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8151 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8152 if (parent_scope
== NULL
)
8155 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8160 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8162 struct dwarf2_per_objfile
*dwarf2_per_objfile
8163 = cu
->per_cu
->dwarf2_per_objfile
;
8164 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8165 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8167 const char *actual_name
= NULL
;
8170 baseaddr
= objfile
->text_section_offset ();
8172 gdb::unique_xmalloc_ptr
<char> built_actual_name
8173 = partial_die_full_name (pdi
, cu
);
8174 if (built_actual_name
!= NULL
)
8175 actual_name
= built_actual_name
.get ();
8177 if (actual_name
== NULL
)
8178 actual_name
= pdi
->name
;
8182 case DW_TAG_inlined_subroutine
:
8183 case DW_TAG_subprogram
:
8184 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8186 if (pdi
->is_external
8187 || cu
->language
== language_ada
8188 || (cu
->language
== language_fortran
8189 && pdi
->die_parent
!= NULL
8190 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8192 /* Normally, only "external" DIEs are part of the global scope.
8193 But in Ada and Fortran, we want to be able to access nested
8194 procedures globally. So all Ada and Fortran subprograms are
8195 stored in the global scope. */
8196 add_psymbol_to_list (actual_name
,
8197 built_actual_name
!= NULL
,
8198 VAR_DOMAIN
, LOC_BLOCK
,
8199 SECT_OFF_TEXT (objfile
),
8200 psymbol_placement::GLOBAL
,
8202 cu
->language
, objfile
);
8206 add_psymbol_to_list (actual_name
,
8207 built_actual_name
!= NULL
,
8208 VAR_DOMAIN
, LOC_BLOCK
,
8209 SECT_OFF_TEXT (objfile
),
8210 psymbol_placement::STATIC
,
8211 addr
, cu
->language
, objfile
);
8214 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8215 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8217 case DW_TAG_constant
:
8218 add_psymbol_to_list (actual_name
,
8219 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8220 -1, (pdi
->is_external
8221 ? psymbol_placement::GLOBAL
8222 : psymbol_placement::STATIC
),
8223 0, cu
->language
, objfile
);
8225 case DW_TAG_variable
:
8227 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8231 && !dwarf2_per_objfile
->has_section_at_zero
)
8233 /* A global or static variable may also have been stripped
8234 out by the linker if unused, in which case its address
8235 will be nullified; do not add such variables into partial
8236 symbol table then. */
8238 else if (pdi
->is_external
)
8241 Don't enter into the minimal symbol tables as there is
8242 a minimal symbol table entry from the ELF symbols already.
8243 Enter into partial symbol table if it has a location
8244 descriptor or a type.
8245 If the location descriptor is missing, new_symbol will create
8246 a LOC_UNRESOLVED symbol, the address of the variable will then
8247 be determined from the minimal symbol table whenever the variable
8249 The address for the partial symbol table entry is not
8250 used by GDB, but it comes in handy for debugging partial symbol
8253 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8254 add_psymbol_to_list (actual_name
,
8255 built_actual_name
!= NULL
,
8256 VAR_DOMAIN
, LOC_STATIC
,
8257 SECT_OFF_TEXT (objfile
),
8258 psymbol_placement::GLOBAL
,
8259 addr
, cu
->language
, objfile
);
8263 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8265 /* Static Variable. Skip symbols whose value we cannot know (those
8266 without location descriptors or constant values). */
8267 if (!has_loc
&& !pdi
->has_const_value
)
8270 add_psymbol_to_list (actual_name
,
8271 built_actual_name
!= NULL
,
8272 VAR_DOMAIN
, LOC_STATIC
,
8273 SECT_OFF_TEXT (objfile
),
8274 psymbol_placement::STATIC
,
8276 cu
->language
, objfile
);
8279 case DW_TAG_typedef
:
8280 case DW_TAG_base_type
:
8281 case DW_TAG_subrange_type
:
8282 add_psymbol_to_list (actual_name
,
8283 built_actual_name
!= NULL
,
8284 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8285 psymbol_placement::STATIC
,
8286 0, cu
->language
, objfile
);
8288 case DW_TAG_imported_declaration
:
8289 case DW_TAG_namespace
:
8290 add_psymbol_to_list (actual_name
,
8291 built_actual_name
!= NULL
,
8292 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8293 psymbol_placement::GLOBAL
,
8294 0, cu
->language
, objfile
);
8297 /* With Fortran 77 there might be a "BLOCK DATA" module
8298 available without any name. If so, we skip the module as it
8299 doesn't bring any value. */
8300 if (actual_name
!= nullptr)
8301 add_psymbol_to_list (actual_name
,
8302 built_actual_name
!= NULL
,
8303 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8304 psymbol_placement::GLOBAL
,
8305 0, cu
->language
, objfile
);
8307 case DW_TAG_class_type
:
8308 case DW_TAG_interface_type
:
8309 case DW_TAG_structure_type
:
8310 case DW_TAG_union_type
:
8311 case DW_TAG_enumeration_type
:
8312 /* Skip external references. The DWARF standard says in the section
8313 about "Structure, Union, and Class Type Entries": "An incomplete
8314 structure, union or class type is represented by a structure,
8315 union or class entry that does not have a byte size attribute
8316 and that has a DW_AT_declaration attribute." */
8317 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8320 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8321 static vs. global. */
8322 add_psymbol_to_list (actual_name
,
8323 built_actual_name
!= NULL
,
8324 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8325 cu
->language
== language_cplus
8326 ? psymbol_placement::GLOBAL
8327 : psymbol_placement::STATIC
,
8328 0, cu
->language
, objfile
);
8331 case DW_TAG_enumerator
:
8332 add_psymbol_to_list (actual_name
,
8333 built_actual_name
!= NULL
,
8334 VAR_DOMAIN
, LOC_CONST
, -1,
8335 cu
->language
== language_cplus
8336 ? psymbol_placement::GLOBAL
8337 : psymbol_placement::STATIC
,
8338 0, cu
->language
, objfile
);
8345 /* Read a partial die corresponding to a namespace; also, add a symbol
8346 corresponding to that namespace to the symbol table. NAMESPACE is
8347 the name of the enclosing namespace. */
8350 add_partial_namespace (struct partial_die_info
*pdi
,
8351 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8352 int set_addrmap
, struct dwarf2_cu
*cu
)
8354 /* Add a symbol for the namespace. */
8356 add_partial_symbol (pdi
, cu
);
8358 /* Now scan partial symbols in that namespace. */
8360 if (pdi
->has_children
)
8361 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8364 /* Read a partial die corresponding to a Fortran module. */
8367 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8368 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8370 /* Add a symbol for the namespace. */
8372 add_partial_symbol (pdi
, cu
);
8374 /* Now scan partial symbols in that module. */
8376 if (pdi
->has_children
)
8377 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8380 /* Read a partial die corresponding to a subprogram or an inlined
8381 subprogram and create a partial symbol for that subprogram.
8382 When the CU language allows it, this routine also defines a partial
8383 symbol for each nested subprogram that this subprogram contains.
8384 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8385 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8387 PDI may also be a lexical block, in which case we simply search
8388 recursively for subprograms defined inside that lexical block.
8389 Again, this is only performed when the CU language allows this
8390 type of definitions. */
8393 add_partial_subprogram (struct partial_die_info
*pdi
,
8394 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8395 int set_addrmap
, struct dwarf2_cu
*cu
)
8397 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8399 if (pdi
->has_pc_info
)
8401 if (pdi
->lowpc
< *lowpc
)
8402 *lowpc
= pdi
->lowpc
;
8403 if (pdi
->highpc
> *highpc
)
8404 *highpc
= pdi
->highpc
;
8407 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8408 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8410 CORE_ADDR this_highpc
;
8411 CORE_ADDR this_lowpc
;
8413 baseaddr
= objfile
->text_section_offset ();
8415 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8416 pdi
->lowpc
+ baseaddr
)
8419 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8420 pdi
->highpc
+ baseaddr
)
8422 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8423 this_lowpc
, this_highpc
- 1,
8424 cu
->per_cu
->v
.psymtab
);
8428 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8430 if (!pdi
->is_declaration
)
8431 /* Ignore subprogram DIEs that do not have a name, they are
8432 illegal. Do not emit a complaint at this point, we will
8433 do so when we convert this psymtab into a symtab. */
8435 add_partial_symbol (pdi
, cu
);
8439 if (! pdi
->has_children
)
8442 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8444 pdi
= pdi
->die_child
;
8448 if (pdi
->tag
== DW_TAG_subprogram
8449 || pdi
->tag
== DW_TAG_inlined_subroutine
8450 || pdi
->tag
== DW_TAG_lexical_block
)
8451 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8452 pdi
= pdi
->die_sibling
;
8457 /* Read a partial die corresponding to an enumeration type. */
8460 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8461 struct dwarf2_cu
*cu
)
8463 struct partial_die_info
*pdi
;
8465 if (enum_pdi
->name
!= NULL
)
8466 add_partial_symbol (enum_pdi
, cu
);
8468 pdi
= enum_pdi
->die_child
;
8471 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8472 complaint (_("malformed enumerator DIE ignored"));
8474 add_partial_symbol (pdi
, cu
);
8475 pdi
= pdi
->die_sibling
;
8479 /* Return the initial uleb128 in the die at INFO_PTR. */
8482 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8484 unsigned int bytes_read
;
8486 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8489 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8490 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8492 Return the corresponding abbrev, or NULL if the number is zero (indicating
8493 an empty DIE). In either case *BYTES_READ will be set to the length of
8494 the initial number. */
8496 static struct abbrev_info
*
8497 peek_die_abbrev (const die_reader_specs
&reader
,
8498 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8500 dwarf2_cu
*cu
= reader
.cu
;
8501 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8502 unsigned int abbrev_number
8503 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8505 if (abbrev_number
== 0)
8508 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8511 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8512 " at offset %s [in module %s]"),
8513 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8514 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8520 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8521 Returns a pointer to the end of a series of DIEs, terminated by an empty
8522 DIE. Any children of the skipped DIEs will also be skipped. */
8524 static const gdb_byte
*
8525 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8529 unsigned int bytes_read
;
8530 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8533 return info_ptr
+ bytes_read
;
8535 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8539 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8540 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8541 abbrev corresponding to that skipped uleb128 should be passed in
8542 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8545 static const gdb_byte
*
8546 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8547 struct abbrev_info
*abbrev
)
8549 unsigned int bytes_read
;
8550 struct attribute attr
;
8551 bfd
*abfd
= reader
->abfd
;
8552 struct dwarf2_cu
*cu
= reader
->cu
;
8553 const gdb_byte
*buffer
= reader
->buffer
;
8554 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8555 unsigned int form
, i
;
8557 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8559 /* The only abbrev we care about is DW_AT_sibling. */
8560 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8563 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8565 if (attr
.form
== DW_FORM_ref_addr
)
8566 complaint (_("ignoring absolute DW_AT_sibling"));
8569 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8570 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8572 if (sibling_ptr
< info_ptr
)
8573 complaint (_("DW_AT_sibling points backwards"));
8574 else if (sibling_ptr
> reader
->buffer_end
)
8575 reader
->die_section
->overflow_complaint ();
8581 /* If it isn't DW_AT_sibling, skip this attribute. */
8582 form
= abbrev
->attrs
[i
].form
;
8586 case DW_FORM_ref_addr
:
8587 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8588 and later it is offset sized. */
8589 if (cu
->header
.version
== 2)
8590 info_ptr
+= cu
->header
.addr_size
;
8592 info_ptr
+= cu
->header
.offset_size
;
8594 case DW_FORM_GNU_ref_alt
:
8595 info_ptr
+= cu
->header
.offset_size
;
8598 info_ptr
+= cu
->header
.addr_size
;
8606 case DW_FORM_flag_present
:
8607 case DW_FORM_implicit_const
:
8624 case DW_FORM_ref_sig8
:
8627 case DW_FORM_data16
:
8630 case DW_FORM_string
:
8631 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8632 info_ptr
+= bytes_read
;
8634 case DW_FORM_sec_offset
:
8636 case DW_FORM_GNU_strp_alt
:
8637 info_ptr
+= cu
->header
.offset_size
;
8639 case DW_FORM_exprloc
:
8641 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8642 info_ptr
+= bytes_read
;
8644 case DW_FORM_block1
:
8645 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8647 case DW_FORM_block2
:
8648 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8650 case DW_FORM_block4
:
8651 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8657 case DW_FORM_ref_udata
:
8658 case DW_FORM_GNU_addr_index
:
8659 case DW_FORM_GNU_str_index
:
8660 case DW_FORM_rnglistx
:
8661 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8663 case DW_FORM_indirect
:
8664 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8665 info_ptr
+= bytes_read
;
8666 /* We need to continue parsing from here, so just go back to
8668 goto skip_attribute
;
8671 error (_("Dwarf Error: Cannot handle %s "
8672 "in DWARF reader [in module %s]"),
8673 dwarf_form_name (form
),
8674 bfd_get_filename (abfd
));
8678 if (abbrev
->has_children
)
8679 return skip_children (reader
, info_ptr
);
8684 /* Locate ORIG_PDI's sibling.
8685 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8687 static const gdb_byte
*
8688 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8689 struct partial_die_info
*orig_pdi
,
8690 const gdb_byte
*info_ptr
)
8692 /* Do we know the sibling already? */
8694 if (orig_pdi
->sibling
)
8695 return orig_pdi
->sibling
;
8697 /* Are there any children to deal with? */
8699 if (!orig_pdi
->has_children
)
8702 /* Skip the children the long way. */
8704 return skip_children (reader
, info_ptr
);
8707 /* Expand this partial symbol table into a full symbol table. SELF is
8711 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8713 struct dwarf2_per_objfile
*dwarf2_per_objfile
8714 = get_dwarf2_per_objfile (objfile
);
8716 gdb_assert (!readin
);
8717 /* If this psymtab is constructed from a debug-only objfile, the
8718 has_section_at_zero flag will not necessarily be correct. We
8719 can get the correct value for this flag by looking at the data
8720 associated with the (presumably stripped) associated objfile. */
8721 if (objfile
->separate_debug_objfile_backlink
)
8723 struct dwarf2_per_objfile
*dpo_backlink
8724 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8726 dwarf2_per_objfile
->has_section_at_zero
8727 = dpo_backlink
->has_section_at_zero
;
8730 expand_psymtab (objfile
);
8732 process_cu_includes (dwarf2_per_objfile
);
8735 /* Reading in full CUs. */
8737 /* Add PER_CU to the queue. */
8740 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8741 enum language pretend_language
)
8744 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8747 /* If PER_CU is not yet queued, add it to the queue.
8748 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8750 The result is non-zero if PER_CU was queued, otherwise the result is zero
8751 meaning either PER_CU is already queued or it is already loaded.
8753 N.B. There is an invariant here that if a CU is queued then it is loaded.
8754 The caller is required to load PER_CU if we return non-zero. */
8757 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8758 struct dwarf2_per_cu_data
*per_cu
,
8759 enum language pretend_language
)
8761 /* We may arrive here during partial symbol reading, if we need full
8762 DIEs to process an unusual case (e.g. template arguments). Do
8763 not queue PER_CU, just tell our caller to load its DIEs. */
8764 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8766 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8771 /* Mark the dependence relation so that we don't flush PER_CU
8773 if (dependent_cu
!= NULL
)
8774 dwarf2_add_dependence (dependent_cu
, per_cu
);
8776 /* If it's already on the queue, we have nothing to do. */
8780 /* If the compilation unit is already loaded, just mark it as
8782 if (per_cu
->cu
!= NULL
)
8784 per_cu
->cu
->last_used
= 0;
8788 /* Add it to the queue. */
8789 queue_comp_unit (per_cu
, pretend_language
);
8794 /* Process the queue. */
8797 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8799 if (dwarf_read_debug
)
8801 fprintf_unfiltered (gdb_stdlog
,
8802 "Expanding one or more symtabs of objfile %s ...\n",
8803 objfile_name (dwarf2_per_objfile
->objfile
));
8806 /* The queue starts out with one item, but following a DIE reference
8807 may load a new CU, adding it to the end of the queue. */
8808 while (!dwarf2_per_objfile
->queue
.empty ())
8810 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8812 if ((dwarf2_per_objfile
->using_index
8813 ? !item
.per_cu
->v
.quick
->compunit_symtab
8814 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8815 /* Skip dummy CUs. */
8816 && item
.per_cu
->cu
!= NULL
)
8818 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8819 unsigned int debug_print_threshold
;
8822 if (per_cu
->is_debug_types
)
8824 struct signatured_type
*sig_type
=
8825 (struct signatured_type
*) per_cu
;
8827 sprintf (buf
, "TU %s at offset %s",
8828 hex_string (sig_type
->signature
),
8829 sect_offset_str (per_cu
->sect_off
));
8830 /* There can be 100s of TUs.
8831 Only print them in verbose mode. */
8832 debug_print_threshold
= 2;
8836 sprintf (buf
, "CU at offset %s",
8837 sect_offset_str (per_cu
->sect_off
));
8838 debug_print_threshold
= 1;
8841 if (dwarf_read_debug
>= debug_print_threshold
)
8842 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8844 if (per_cu
->is_debug_types
)
8845 process_full_type_unit (per_cu
, item
.pretend_language
);
8847 process_full_comp_unit (per_cu
, item
.pretend_language
);
8849 if (dwarf_read_debug
>= debug_print_threshold
)
8850 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8853 item
.per_cu
->queued
= 0;
8854 dwarf2_per_objfile
->queue
.pop ();
8857 if (dwarf_read_debug
)
8859 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8860 objfile_name (dwarf2_per_objfile
->objfile
));
8864 /* Read in full symbols for PST, and anything it depends on. */
8867 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8872 read_dependencies (objfile
);
8874 dw2_do_instantiate_symtab (per_cu_data
, false);
8875 gdb_assert (get_compunit_symtab () != nullptr);
8878 /* Trivial hash function for die_info: the hash value of a DIE
8879 is its offset in .debug_info for this objfile. */
8882 die_hash (const void *item
)
8884 const struct die_info
*die
= (const struct die_info
*) item
;
8886 return to_underlying (die
->sect_off
);
8889 /* Trivial comparison function for die_info structures: two DIEs
8890 are equal if they have the same offset. */
8893 die_eq (const void *item_lhs
, const void *item_rhs
)
8895 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8896 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8898 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8901 /* Load the DIEs associated with PER_CU into memory. */
8904 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8906 enum language pretend_language
)
8908 gdb_assert (! this_cu
->is_debug_types
);
8910 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8914 struct dwarf2_cu
*cu
= reader
.cu
;
8915 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8917 gdb_assert (cu
->die_hash
== NULL
);
8919 htab_create_alloc_ex (cu
->header
.length
/ 12,
8923 &cu
->comp_unit_obstack
,
8924 hashtab_obstack_allocate
,
8925 dummy_obstack_deallocate
);
8927 if (reader
.comp_unit_die
->has_children
)
8928 reader
.comp_unit_die
->child
8929 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8930 &info_ptr
, reader
.comp_unit_die
);
8931 cu
->dies
= reader
.comp_unit_die
;
8932 /* comp_unit_die is not stored in die_hash, no need. */
8934 /* We try not to read any attributes in this function, because not
8935 all CUs needed for references have been loaded yet, and symbol
8936 table processing isn't initialized. But we have to set the CU language,
8937 or we won't be able to build types correctly.
8938 Similarly, if we do not read the producer, we can not apply
8939 producer-specific interpretation. */
8940 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8945 /* Add a DIE to the delayed physname list. */
8948 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8949 const char *name
, struct die_info
*die
,
8950 struct dwarf2_cu
*cu
)
8952 struct delayed_method_info mi
;
8954 mi
.fnfield_index
= fnfield_index
;
8958 cu
->method_list
.push_back (mi
);
8961 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8962 "const" / "volatile". If so, decrements LEN by the length of the
8963 modifier and return true. Otherwise return false. */
8967 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8969 size_t mod_len
= sizeof (mod
) - 1;
8970 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8978 /* Compute the physnames of any methods on the CU's method list.
8980 The computation of method physnames is delayed in order to avoid the
8981 (bad) condition that one of the method's formal parameters is of an as yet
8985 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8987 /* Only C++ delays computing physnames. */
8988 if (cu
->method_list
.empty ())
8990 gdb_assert (cu
->language
== language_cplus
);
8992 for (const delayed_method_info
&mi
: cu
->method_list
)
8994 const char *physname
;
8995 struct fn_fieldlist
*fn_flp
8996 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8997 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8998 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8999 = physname
? physname
: "";
9001 /* Since there's no tag to indicate whether a method is a
9002 const/volatile overload, extract that information out of the
9004 if (physname
!= NULL
)
9006 size_t len
= strlen (physname
);
9010 if (physname
[len
] == ')') /* shortcut */
9012 else if (check_modifier (physname
, len
, " const"))
9013 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9014 else if (check_modifier (physname
, len
, " volatile"))
9015 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9022 /* The list is no longer needed. */
9023 cu
->method_list
.clear ();
9026 /* Go objects should be embedded in a DW_TAG_module DIE,
9027 and it's not clear if/how imported objects will appear.
9028 To keep Go support simple until that's worked out,
9029 go back through what we've read and create something usable.
9030 We could do this while processing each DIE, and feels kinda cleaner,
9031 but that way is more invasive.
9032 This is to, for example, allow the user to type "p var" or "b main"
9033 without having to specify the package name, and allow lookups
9034 of module.object to work in contexts that use the expression
9038 fixup_go_packaging (struct dwarf2_cu
*cu
)
9040 gdb::unique_xmalloc_ptr
<char> package_name
;
9041 struct pending
*list
;
9044 for (list
= *cu
->get_builder ()->get_global_symbols ();
9048 for (i
= 0; i
< list
->nsyms
; ++i
)
9050 struct symbol
*sym
= list
->symbol
[i
];
9052 if (sym
->language () == language_go
9053 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9055 gdb::unique_xmalloc_ptr
<char> this_package_name
9056 (go_symbol_package_name (sym
));
9058 if (this_package_name
== NULL
)
9060 if (package_name
== NULL
)
9061 package_name
= std::move (this_package_name
);
9064 struct objfile
*objfile
9065 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9066 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9067 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9068 (symbol_symtab (sym
) != NULL
9069 ? symtab_to_filename_for_display
9070 (symbol_symtab (sym
))
9071 : objfile_name (objfile
)),
9072 this_package_name
.get (), package_name
.get ());
9078 if (package_name
!= NULL
)
9080 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9081 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9082 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9083 saved_package_name
);
9086 sym
= allocate_symbol (objfile
);
9087 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9088 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9089 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9090 e.g., "main" finds the "main" module and not C's main(). */
9091 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9092 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9093 SYMBOL_TYPE (sym
) = type
;
9095 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9099 /* Allocate a fully-qualified name consisting of the two parts on the
9103 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9105 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9108 /* A helper that allocates a struct discriminant_info to attach to a
9111 static struct discriminant_info
*
9112 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9115 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9116 gdb_assert (discriminant_index
== -1
9117 || (discriminant_index
>= 0
9118 && discriminant_index
< TYPE_NFIELDS (type
)));
9119 gdb_assert (default_index
== -1
9120 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9122 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9124 struct discriminant_info
*disc
9125 = ((struct discriminant_info
*)
9127 offsetof (struct discriminant_info
, discriminants
)
9128 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9129 disc
->default_index
= default_index
;
9130 disc
->discriminant_index
= discriminant_index
;
9132 struct dynamic_prop prop
;
9133 prop
.kind
= PROP_UNDEFINED
;
9134 prop
.data
.baton
= disc
;
9136 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9141 /* Some versions of rustc emitted enums in an unusual way.
9143 Ordinary enums were emitted as unions. The first element of each
9144 structure in the union was named "RUST$ENUM$DISR". This element
9145 held the discriminant.
9147 These versions of Rust also implemented the "non-zero"
9148 optimization. When the enum had two values, and one is empty and
9149 the other holds a pointer that cannot be zero, the pointer is used
9150 as the discriminant, with a zero value meaning the empty variant.
9151 Here, the union's first member is of the form
9152 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9153 where the fieldnos are the indices of the fields that should be
9154 traversed in order to find the field (which may be several fields deep)
9155 and the variantname is the name of the variant of the case when the
9158 This function recognizes whether TYPE is of one of these forms,
9159 and, if so, smashes it to be a variant type. */
9162 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9164 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9166 /* We don't need to deal with empty enums. */
9167 if (TYPE_NFIELDS (type
) == 0)
9170 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9171 if (TYPE_NFIELDS (type
) == 1
9172 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9174 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9176 /* Decode the field name to find the offset of the
9178 ULONGEST bit_offset
= 0;
9179 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9180 while (name
[0] >= '0' && name
[0] <= '9')
9183 unsigned long index
= strtoul (name
, &tail
, 10);
9186 || index
>= TYPE_NFIELDS (field_type
)
9187 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9188 != FIELD_LOC_KIND_BITPOS
))
9190 complaint (_("Could not parse Rust enum encoding string \"%s\""
9192 TYPE_FIELD_NAME (type
, 0),
9193 objfile_name (objfile
));
9198 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9199 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9202 /* Make a union to hold the variants. */
9203 struct type
*union_type
= alloc_type (objfile
);
9204 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9205 TYPE_NFIELDS (union_type
) = 3;
9206 TYPE_FIELDS (union_type
)
9207 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9208 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9209 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9211 /* Put the discriminant must at index 0. */
9212 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9213 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9214 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9215 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9217 /* The order of fields doesn't really matter, so put the real
9218 field at index 1 and the data-less field at index 2. */
9219 struct discriminant_info
*disc
9220 = alloc_discriminant_info (union_type
, 0, 1);
9221 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9222 TYPE_FIELD_NAME (union_type
, 1)
9223 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9224 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9225 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9226 TYPE_FIELD_NAME (union_type
, 1));
9228 const char *dataless_name
9229 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9231 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9233 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9234 /* NAME points into the original discriminant name, which
9235 already has the correct lifetime. */
9236 TYPE_FIELD_NAME (union_type
, 2) = name
;
9237 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9238 disc
->discriminants
[2] = 0;
9240 /* Smash this type to be a structure type. We have to do this
9241 because the type has already been recorded. */
9242 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9243 TYPE_NFIELDS (type
) = 1;
9245 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9247 /* Install the variant part. */
9248 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9249 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9250 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9252 /* A union with a single anonymous field is probably an old-style
9254 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9256 /* Smash this type to be a structure type. We have to do this
9257 because the type has already been recorded. */
9258 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9260 /* Make a union to hold the variants. */
9261 struct type
*union_type
= alloc_type (objfile
);
9262 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9263 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9264 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9265 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9266 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9268 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9269 const char *variant_name
9270 = rust_last_path_segment (TYPE_NAME (field_type
));
9271 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9272 TYPE_NAME (field_type
)
9273 = rust_fully_qualify (&objfile
->objfile_obstack
,
9274 TYPE_NAME (type
), variant_name
);
9276 /* Install the union in the outer struct type. */
9277 TYPE_NFIELDS (type
) = 1;
9279 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9280 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9281 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9282 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9284 alloc_discriminant_info (union_type
, -1, 0);
9288 struct type
*disr_type
= nullptr;
9289 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9291 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9293 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9295 /* All fields of a true enum will be structs. */
9298 else if (TYPE_NFIELDS (disr_type
) == 0)
9300 /* Could be data-less variant, so keep going. */
9301 disr_type
= nullptr;
9303 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9304 "RUST$ENUM$DISR") != 0)
9306 /* Not a Rust enum. */
9316 /* If we got here without a discriminant, then it's probably
9318 if (disr_type
== nullptr)
9321 /* Smash this type to be a structure type. We have to do this
9322 because the type has already been recorded. */
9323 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9325 /* Make a union to hold the variants. */
9326 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9327 struct type
*union_type
= alloc_type (objfile
);
9328 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9329 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9330 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9331 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9332 TYPE_FIELDS (union_type
)
9333 = (struct field
*) TYPE_ZALLOC (union_type
,
9334 (TYPE_NFIELDS (union_type
)
9335 * sizeof (struct field
)));
9337 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9338 TYPE_NFIELDS (type
) * sizeof (struct field
));
9340 /* Install the discriminant at index 0 in the union. */
9341 TYPE_FIELD (union_type
, 0) = *disr_field
;
9342 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9343 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9345 /* Install the union in the outer struct type. */
9346 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9347 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9348 TYPE_NFIELDS (type
) = 1;
9350 /* Set the size and offset of the union type. */
9351 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9353 /* We need a way to find the correct discriminant given a
9354 variant name. For convenience we build a map here. */
9355 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9356 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9357 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9359 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9362 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9363 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9367 int n_fields
= TYPE_NFIELDS (union_type
);
9368 struct discriminant_info
*disc
9369 = alloc_discriminant_info (union_type
, 0, -1);
9370 /* Skip the discriminant here. */
9371 for (int i
= 1; i
< n_fields
; ++i
)
9373 /* Find the final word in the name of this variant's type.
9374 That name can be used to look up the correct
9376 const char *variant_name
9377 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9380 auto iter
= discriminant_map
.find (variant_name
);
9381 if (iter
!= discriminant_map
.end ())
9382 disc
->discriminants
[i
] = iter
->second
;
9384 /* Remove the discriminant field, if it exists. */
9385 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9386 if (TYPE_NFIELDS (sub_type
) > 0)
9388 --TYPE_NFIELDS (sub_type
);
9389 ++TYPE_FIELDS (sub_type
);
9391 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9392 TYPE_NAME (sub_type
)
9393 = rust_fully_qualify (&objfile
->objfile_obstack
,
9394 TYPE_NAME (type
), variant_name
);
9399 /* Rewrite some Rust unions to be structures with variants parts. */
9402 rust_union_quirks (struct dwarf2_cu
*cu
)
9404 gdb_assert (cu
->language
== language_rust
);
9405 for (type
*type_
: cu
->rust_unions
)
9406 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9407 /* We don't need this any more. */
9408 cu
->rust_unions
.clear ();
9411 /* Return the symtab for PER_CU. This works properly regardless of
9412 whether we're using the index or psymtabs. */
9414 static struct compunit_symtab
*
9415 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9417 return (per_cu
->dwarf2_per_objfile
->using_index
9418 ? per_cu
->v
.quick
->compunit_symtab
9419 : per_cu
->v
.psymtab
->compunit_symtab
);
9422 /* A helper function for computing the list of all symbol tables
9423 included by PER_CU. */
9426 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9427 htab_t all_children
, htab_t all_type_symtabs
,
9428 struct dwarf2_per_cu_data
*per_cu
,
9429 struct compunit_symtab
*immediate_parent
)
9432 struct compunit_symtab
*cust
;
9434 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9437 /* This inclusion and its children have been processed. */
9442 /* Only add a CU if it has a symbol table. */
9443 cust
= get_compunit_symtab (per_cu
);
9446 /* If this is a type unit only add its symbol table if we haven't
9447 seen it yet (type unit per_cu's can share symtabs). */
9448 if (per_cu
->is_debug_types
)
9450 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9454 result
->push_back (cust
);
9455 if (cust
->user
== NULL
)
9456 cust
->user
= immediate_parent
;
9461 result
->push_back (cust
);
9462 if (cust
->user
== NULL
)
9463 cust
->user
= immediate_parent
;
9467 if (!per_cu
->imported_symtabs_empty ())
9468 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9470 recursively_compute_inclusions (result
, all_children
,
9471 all_type_symtabs
, ptr
, cust
);
9475 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9479 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9481 gdb_assert (! per_cu
->is_debug_types
);
9483 if (!per_cu
->imported_symtabs_empty ())
9486 std::vector
<compunit_symtab
*> result_symtabs
;
9487 htab_t all_children
, all_type_symtabs
;
9488 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9490 /* If we don't have a symtab, we can just skip this case. */
9494 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9495 NULL
, xcalloc
, xfree
);
9496 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9497 NULL
, xcalloc
, xfree
);
9499 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9501 recursively_compute_inclusions (&result_symtabs
, all_children
,
9502 all_type_symtabs
, ptr
, cust
);
9505 /* Now we have a transitive closure of all the included symtabs. */
9506 len
= result_symtabs
.size ();
9508 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9509 struct compunit_symtab
*, len
+ 1);
9510 memcpy (cust
->includes
, result_symtabs
.data (),
9511 len
* sizeof (compunit_symtab
*));
9512 cust
->includes
[len
] = NULL
;
9514 htab_delete (all_children
);
9515 htab_delete (all_type_symtabs
);
9519 /* Compute the 'includes' field for the symtabs of all the CUs we just
9523 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9525 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9527 if (! iter
->is_debug_types
)
9528 compute_compunit_symtab_includes (iter
);
9531 dwarf2_per_objfile
->just_read_cus
.clear ();
9534 /* Generate full symbol information for PER_CU, whose DIEs have
9535 already been loaded into memory. */
9538 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9539 enum language pretend_language
)
9541 struct dwarf2_cu
*cu
= per_cu
->cu
;
9542 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9543 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9544 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9545 CORE_ADDR lowpc
, highpc
;
9546 struct compunit_symtab
*cust
;
9548 struct block
*static_block
;
9551 baseaddr
= objfile
->text_section_offset ();
9553 /* Clear the list here in case something was left over. */
9554 cu
->method_list
.clear ();
9556 cu
->language
= pretend_language
;
9557 cu
->language_defn
= language_def (cu
->language
);
9559 /* Do line number decoding in read_file_scope () */
9560 process_die (cu
->dies
, cu
);
9562 /* For now fudge the Go package. */
9563 if (cu
->language
== language_go
)
9564 fixup_go_packaging (cu
);
9566 /* Now that we have processed all the DIEs in the CU, all the types
9567 should be complete, and it should now be safe to compute all of the
9569 compute_delayed_physnames (cu
);
9571 if (cu
->language
== language_rust
)
9572 rust_union_quirks (cu
);
9574 /* Some compilers don't define a DW_AT_high_pc attribute for the
9575 compilation unit. If the DW_AT_high_pc is missing, synthesize
9576 it, by scanning the DIE's below the compilation unit. */
9577 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9579 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9580 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9582 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9583 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9584 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9585 addrmap to help ensure it has an accurate map of pc values belonging to
9587 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9589 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9590 SECT_OFF_TEXT (objfile
),
9595 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9597 /* Set symtab language to language from DW_AT_language. If the
9598 compilation is from a C file generated by language preprocessors, do
9599 not set the language if it was already deduced by start_subfile. */
9600 if (!(cu
->language
== language_c
9601 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9602 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9604 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9605 produce DW_AT_location with location lists but it can be possibly
9606 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9607 there were bugs in prologue debug info, fixed later in GCC-4.5
9608 by "unwind info for epilogues" patch (which is not directly related).
9610 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9611 needed, it would be wrong due to missing DW_AT_producer there.
9613 Still one can confuse GDB by using non-standard GCC compilation
9614 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9616 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9617 cust
->locations_valid
= 1;
9619 if (gcc_4_minor
>= 5)
9620 cust
->epilogue_unwind_valid
= 1;
9622 cust
->call_site_htab
= cu
->call_site_htab
;
9625 if (dwarf2_per_objfile
->using_index
)
9626 per_cu
->v
.quick
->compunit_symtab
= cust
;
9629 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9630 pst
->compunit_symtab
= cust
;
9634 /* Push it for inclusion processing later. */
9635 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9637 /* Not needed any more. */
9638 cu
->reset_builder ();
9641 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9642 already been loaded into memory. */
9645 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9646 enum language pretend_language
)
9648 struct dwarf2_cu
*cu
= per_cu
->cu
;
9649 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9650 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9651 struct compunit_symtab
*cust
;
9652 struct signatured_type
*sig_type
;
9654 gdb_assert (per_cu
->is_debug_types
);
9655 sig_type
= (struct signatured_type
*) per_cu
;
9657 /* Clear the list here in case something was left over. */
9658 cu
->method_list
.clear ();
9660 cu
->language
= pretend_language
;
9661 cu
->language_defn
= language_def (cu
->language
);
9663 /* The symbol tables are set up in read_type_unit_scope. */
9664 process_die (cu
->dies
, cu
);
9666 /* For now fudge the Go package. */
9667 if (cu
->language
== language_go
)
9668 fixup_go_packaging (cu
);
9670 /* Now that we have processed all the DIEs in the CU, all the types
9671 should be complete, and it should now be safe to compute all of the
9673 compute_delayed_physnames (cu
);
9675 if (cu
->language
== language_rust
)
9676 rust_union_quirks (cu
);
9678 /* TUs share symbol tables.
9679 If this is the first TU to use this symtab, complete the construction
9680 of it with end_expandable_symtab. Otherwise, complete the addition of
9681 this TU's symbols to the existing symtab. */
9682 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9684 buildsym_compunit
*builder
= cu
->get_builder ();
9685 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9686 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9690 /* Set symtab language to language from DW_AT_language. If the
9691 compilation is from a C file generated by language preprocessors,
9692 do not set the language if it was already deduced by
9694 if (!(cu
->language
== language_c
9695 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9696 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9701 cu
->get_builder ()->augment_type_symtab ();
9702 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9705 if (dwarf2_per_objfile
->using_index
)
9706 per_cu
->v
.quick
->compunit_symtab
= cust
;
9709 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9710 pst
->compunit_symtab
= cust
;
9714 /* Not needed any more. */
9715 cu
->reset_builder ();
9718 /* Process an imported unit DIE. */
9721 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9723 struct attribute
*attr
;
9725 /* For now we don't handle imported units in type units. */
9726 if (cu
->per_cu
->is_debug_types
)
9728 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9729 " supported in type units [in module %s]"),
9730 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9733 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9736 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9737 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9738 dwarf2_per_cu_data
*per_cu
9739 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9740 cu
->per_cu
->dwarf2_per_objfile
);
9742 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9743 into another compilation unit, at root level. Regard this as a hint,
9745 if (die
->parent
&& die
->parent
->parent
== NULL
9746 && per_cu
->unit_type
== DW_UT_compile
9747 && per_cu
->lang
== language_cplus
)
9750 /* If necessary, add it to the queue and load its DIEs. */
9751 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9752 load_full_comp_unit (per_cu
, false, cu
->language
);
9754 cu
->per_cu
->imported_symtabs_push (per_cu
);
9758 /* RAII object that represents a process_die scope: i.e.,
9759 starts/finishes processing a DIE. */
9760 class process_die_scope
9763 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9764 : m_die (die
), m_cu (cu
)
9766 /* We should only be processing DIEs not already in process. */
9767 gdb_assert (!m_die
->in_process
);
9768 m_die
->in_process
= true;
9771 ~process_die_scope ()
9773 m_die
->in_process
= false;
9775 /* If we're done processing the DIE for the CU that owns the line
9776 header, we don't need the line header anymore. */
9777 if (m_cu
->line_header_die_owner
== m_die
)
9779 delete m_cu
->line_header
;
9780 m_cu
->line_header
= NULL
;
9781 m_cu
->line_header_die_owner
= NULL
;
9790 /* Process a die and its children. */
9793 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9795 process_die_scope
scope (die
, cu
);
9799 case DW_TAG_padding
:
9801 case DW_TAG_compile_unit
:
9802 case DW_TAG_partial_unit
:
9803 read_file_scope (die
, cu
);
9805 case DW_TAG_type_unit
:
9806 read_type_unit_scope (die
, cu
);
9808 case DW_TAG_subprogram
:
9809 /* Nested subprograms in Fortran get a prefix. */
9810 if (cu
->language
== language_fortran
9811 && die
->parent
!= NULL
9812 && die
->parent
->tag
== DW_TAG_subprogram
)
9813 cu
->processing_has_namespace_info
= true;
9815 case DW_TAG_inlined_subroutine
:
9816 read_func_scope (die
, cu
);
9818 case DW_TAG_lexical_block
:
9819 case DW_TAG_try_block
:
9820 case DW_TAG_catch_block
:
9821 read_lexical_block_scope (die
, cu
);
9823 case DW_TAG_call_site
:
9824 case DW_TAG_GNU_call_site
:
9825 read_call_site_scope (die
, cu
);
9827 case DW_TAG_class_type
:
9828 case DW_TAG_interface_type
:
9829 case DW_TAG_structure_type
:
9830 case DW_TAG_union_type
:
9831 process_structure_scope (die
, cu
);
9833 case DW_TAG_enumeration_type
:
9834 process_enumeration_scope (die
, cu
);
9837 /* These dies have a type, but processing them does not create
9838 a symbol or recurse to process the children. Therefore we can
9839 read them on-demand through read_type_die. */
9840 case DW_TAG_subroutine_type
:
9841 case DW_TAG_set_type
:
9842 case DW_TAG_array_type
:
9843 case DW_TAG_pointer_type
:
9844 case DW_TAG_ptr_to_member_type
:
9845 case DW_TAG_reference_type
:
9846 case DW_TAG_rvalue_reference_type
:
9847 case DW_TAG_string_type
:
9850 case DW_TAG_base_type
:
9851 case DW_TAG_subrange_type
:
9852 case DW_TAG_typedef
:
9853 /* Add a typedef symbol for the type definition, if it has a
9855 new_symbol (die
, read_type_die (die
, cu
), cu
);
9857 case DW_TAG_common_block
:
9858 read_common_block (die
, cu
);
9860 case DW_TAG_common_inclusion
:
9862 case DW_TAG_namespace
:
9863 cu
->processing_has_namespace_info
= true;
9864 read_namespace (die
, cu
);
9867 cu
->processing_has_namespace_info
= true;
9868 read_module (die
, cu
);
9870 case DW_TAG_imported_declaration
:
9871 cu
->processing_has_namespace_info
= true;
9872 if (read_namespace_alias (die
, cu
))
9874 /* The declaration is not a global namespace alias. */
9876 case DW_TAG_imported_module
:
9877 cu
->processing_has_namespace_info
= true;
9878 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9879 || cu
->language
!= language_fortran
))
9880 complaint (_("Tag '%s' has unexpected children"),
9881 dwarf_tag_name (die
->tag
));
9882 read_import_statement (die
, cu
);
9885 case DW_TAG_imported_unit
:
9886 process_imported_unit_die (die
, cu
);
9889 case DW_TAG_variable
:
9890 read_variable (die
, cu
);
9894 new_symbol (die
, NULL
, cu
);
9899 /* DWARF name computation. */
9901 /* A helper function for dwarf2_compute_name which determines whether DIE
9902 needs to have the name of the scope prepended to the name listed in the
9906 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9908 struct attribute
*attr
;
9912 case DW_TAG_namespace
:
9913 case DW_TAG_typedef
:
9914 case DW_TAG_class_type
:
9915 case DW_TAG_interface_type
:
9916 case DW_TAG_structure_type
:
9917 case DW_TAG_union_type
:
9918 case DW_TAG_enumeration_type
:
9919 case DW_TAG_enumerator
:
9920 case DW_TAG_subprogram
:
9921 case DW_TAG_inlined_subroutine
:
9923 case DW_TAG_imported_declaration
:
9926 case DW_TAG_variable
:
9927 case DW_TAG_constant
:
9928 /* We only need to prefix "globally" visible variables. These include
9929 any variable marked with DW_AT_external or any variable that
9930 lives in a namespace. [Variables in anonymous namespaces
9931 require prefixing, but they are not DW_AT_external.] */
9933 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9935 struct dwarf2_cu
*spec_cu
= cu
;
9937 return die_needs_namespace (die_specification (die
, &spec_cu
),
9941 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9942 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9943 && die
->parent
->tag
!= DW_TAG_module
)
9945 /* A variable in a lexical block of some kind does not need a
9946 namespace, even though in C++ such variables may be external
9947 and have a mangled name. */
9948 if (die
->parent
->tag
== DW_TAG_lexical_block
9949 || die
->parent
->tag
== DW_TAG_try_block
9950 || die
->parent
->tag
== DW_TAG_catch_block
9951 || die
->parent
->tag
== DW_TAG_subprogram
)
9960 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9961 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9962 defined for the given DIE. */
9964 static struct attribute
*
9965 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9967 struct attribute
*attr
;
9969 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9971 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9976 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9977 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9978 defined for the given DIE. */
9981 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9983 const char *linkage_name
;
9985 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9986 if (linkage_name
== NULL
)
9987 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9989 return linkage_name
;
9992 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9993 compute the physname for the object, which include a method's:
9994 - formal parameters (C++),
9995 - receiver type (Go),
9997 The term "physname" is a bit confusing.
9998 For C++, for example, it is the demangled name.
9999 For Go, for example, it's the mangled name.
10001 For Ada, return the DIE's linkage name rather than the fully qualified
10002 name. PHYSNAME is ignored..
10004 The result is allocated on the objfile_obstack and canonicalized. */
10006 static const char *
10007 dwarf2_compute_name (const char *name
,
10008 struct die_info
*die
, struct dwarf2_cu
*cu
,
10011 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10014 name
= dwarf2_name (die
, cu
);
10016 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10017 but otherwise compute it by typename_concat inside GDB.
10018 FIXME: Actually this is not really true, or at least not always true.
10019 It's all very confusing. compute_and_set_names doesn't try to demangle
10020 Fortran names because there is no mangling standard. So new_symbol
10021 will set the demangled name to the result of dwarf2_full_name, and it is
10022 the demangled name that GDB uses if it exists. */
10023 if (cu
->language
== language_ada
10024 || (cu
->language
== language_fortran
&& physname
))
10026 /* For Ada unit, we prefer the linkage name over the name, as
10027 the former contains the exported name, which the user expects
10028 to be able to reference. Ideally, we want the user to be able
10029 to reference this entity using either natural or linkage name,
10030 but we haven't started looking at this enhancement yet. */
10031 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10033 if (linkage_name
!= NULL
)
10034 return linkage_name
;
10037 /* These are the only languages we know how to qualify names in. */
10039 && (cu
->language
== language_cplus
10040 || cu
->language
== language_fortran
|| cu
->language
== language_d
10041 || cu
->language
== language_rust
))
10043 if (die_needs_namespace (die
, cu
))
10045 const char *prefix
;
10046 const char *canonical_name
= NULL
;
10050 prefix
= determine_prefix (die
, cu
);
10051 if (*prefix
!= '\0')
10053 gdb::unique_xmalloc_ptr
<char> prefixed_name
10054 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10056 buf
.puts (prefixed_name
.get ());
10061 /* Template parameters may be specified in the DIE's DW_AT_name, or
10062 as children with DW_TAG_template_type_param or
10063 DW_TAG_value_type_param. If the latter, add them to the name
10064 here. If the name already has template parameters, then
10065 skip this step; some versions of GCC emit both, and
10066 it is more efficient to use the pre-computed name.
10068 Something to keep in mind about this process: it is very
10069 unlikely, or in some cases downright impossible, to produce
10070 something that will match the mangled name of a function.
10071 If the definition of the function has the same debug info,
10072 we should be able to match up with it anyway. But fallbacks
10073 using the minimal symbol, for instance to find a method
10074 implemented in a stripped copy of libstdc++, will not work.
10075 If we do not have debug info for the definition, we will have to
10076 match them up some other way.
10078 When we do name matching there is a related problem with function
10079 templates; two instantiated function templates are allowed to
10080 differ only by their return types, which we do not add here. */
10082 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10084 struct attribute
*attr
;
10085 struct die_info
*child
;
10088 die
->building_fullname
= 1;
10090 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10094 const gdb_byte
*bytes
;
10095 struct dwarf2_locexpr_baton
*baton
;
10098 if (child
->tag
!= DW_TAG_template_type_param
10099 && child
->tag
!= DW_TAG_template_value_param
)
10110 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10113 complaint (_("template parameter missing DW_AT_type"));
10114 buf
.puts ("UNKNOWN_TYPE");
10117 type
= die_type (child
, cu
);
10119 if (child
->tag
== DW_TAG_template_type_param
)
10121 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10122 &type_print_raw_options
);
10126 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10129 complaint (_("template parameter missing "
10130 "DW_AT_const_value"));
10131 buf
.puts ("UNKNOWN_VALUE");
10135 dwarf2_const_value_attr (attr
, type
, name
,
10136 &cu
->comp_unit_obstack
, cu
,
10137 &value
, &bytes
, &baton
);
10139 if (TYPE_NOSIGN (type
))
10140 /* GDB prints characters as NUMBER 'CHAR'. If that's
10141 changed, this can use value_print instead. */
10142 c_printchar (value
, type
, &buf
);
10145 struct value_print_options opts
;
10148 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10152 else if (bytes
!= NULL
)
10154 v
= allocate_value (type
);
10155 memcpy (value_contents_writeable (v
), bytes
,
10156 TYPE_LENGTH (type
));
10159 v
= value_from_longest (type
, value
);
10161 /* Specify decimal so that we do not depend on
10163 get_formatted_print_options (&opts
, 'd');
10165 value_print (v
, &buf
, &opts
);
10170 die
->building_fullname
= 0;
10174 /* Close the argument list, with a space if necessary
10175 (nested templates). */
10176 if (!buf
.empty () && buf
.string ().back () == '>')
10183 /* For C++ methods, append formal parameter type
10184 information, if PHYSNAME. */
10186 if (physname
&& die
->tag
== DW_TAG_subprogram
10187 && cu
->language
== language_cplus
)
10189 struct type
*type
= read_type_die (die
, cu
);
10191 c_type_print_args (type
, &buf
, 1, cu
->language
,
10192 &type_print_raw_options
);
10194 if (cu
->language
== language_cplus
)
10196 /* Assume that an artificial first parameter is
10197 "this", but do not crash if it is not. RealView
10198 marks unnamed (and thus unused) parameters as
10199 artificial; there is no way to differentiate
10201 if (TYPE_NFIELDS (type
) > 0
10202 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10203 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10204 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10206 buf
.puts (" const");
10210 const std::string
&intermediate_name
= buf
.string ();
10212 if (cu
->language
== language_cplus
)
10214 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10217 /* If we only computed INTERMEDIATE_NAME, or if
10218 INTERMEDIATE_NAME is already canonical, then we need to
10220 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10221 name
= objfile
->intern (intermediate_name
);
10223 name
= canonical_name
;
10230 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10231 If scope qualifiers are appropriate they will be added. The result
10232 will be allocated on the storage_obstack, or NULL if the DIE does
10233 not have a name. NAME may either be from a previous call to
10234 dwarf2_name or NULL.
10236 The output string will be canonicalized (if C++). */
10238 static const char *
10239 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10241 return dwarf2_compute_name (name
, die
, cu
, 0);
10244 /* Construct a physname for the given DIE in CU. NAME may either be
10245 from a previous call to dwarf2_name or NULL. The result will be
10246 allocated on the objfile_objstack or NULL if the DIE does not have a
10249 The output string will be canonicalized (if C++). */
10251 static const char *
10252 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10254 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10255 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10258 /* In this case dwarf2_compute_name is just a shortcut not building anything
10260 if (!die_needs_namespace (die
, cu
))
10261 return dwarf2_compute_name (name
, die
, cu
, 1);
10263 mangled
= dw2_linkage_name (die
, cu
);
10265 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10266 See https://github.com/rust-lang/rust/issues/32925. */
10267 if (cu
->language
== language_rust
&& mangled
!= NULL
10268 && strchr (mangled
, '{') != NULL
)
10271 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10273 gdb::unique_xmalloc_ptr
<char> demangled
;
10274 if (mangled
!= NULL
)
10277 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10279 /* Do nothing (do not demangle the symbol name). */
10281 else if (cu
->language
== language_go
)
10283 /* This is a lie, but we already lie to the caller new_symbol.
10284 new_symbol assumes we return the mangled name.
10285 This just undoes that lie until things are cleaned up. */
10289 /* Use DMGL_RET_DROP for C++ template functions to suppress
10290 their return type. It is easier for GDB users to search
10291 for such functions as `name(params)' than `long name(params)'.
10292 In such case the minimal symbol names do not match the full
10293 symbol names but for template functions there is never a need
10294 to look up their definition from their declaration so
10295 the only disadvantage remains the minimal symbol variant
10296 `long name(params)' does not have the proper inferior type. */
10297 demangled
.reset (gdb_demangle (mangled
,
10298 (DMGL_PARAMS
| DMGL_ANSI
10299 | DMGL_RET_DROP
)));
10302 canon
= demangled
.get ();
10310 if (canon
== NULL
|| check_physname
)
10312 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10314 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10316 /* It may not mean a bug in GDB. The compiler could also
10317 compute DW_AT_linkage_name incorrectly. But in such case
10318 GDB would need to be bug-to-bug compatible. */
10320 complaint (_("Computed physname <%s> does not match demangled <%s> "
10321 "(from linkage <%s>) - DIE at %s [in module %s]"),
10322 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10323 objfile_name (objfile
));
10325 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10326 is available here - over computed PHYSNAME. It is safer
10327 against both buggy GDB and buggy compilers. */
10341 retval
= objfile
->intern (retval
);
10346 /* Inspect DIE in CU for a namespace alias. If one exists, record
10347 a new symbol for it.
10349 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10352 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10354 struct attribute
*attr
;
10356 /* If the die does not have a name, this is not a namespace
10358 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10362 struct die_info
*d
= die
;
10363 struct dwarf2_cu
*imported_cu
= cu
;
10365 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10366 keep inspecting DIEs until we hit the underlying import. */
10367 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10368 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10370 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10374 d
= follow_die_ref (d
, attr
, &imported_cu
);
10375 if (d
->tag
!= DW_TAG_imported_declaration
)
10379 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10381 complaint (_("DIE at %s has too many recursively imported "
10382 "declarations"), sect_offset_str (d
->sect_off
));
10389 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10391 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10392 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10394 /* This declaration is a global namespace alias. Add
10395 a symbol for it whose type is the aliased namespace. */
10396 new_symbol (die
, type
, cu
);
10405 /* Return the using directives repository (global or local?) to use in the
10406 current context for CU.
10408 For Ada, imported declarations can materialize renamings, which *may* be
10409 global. However it is impossible (for now?) in DWARF to distinguish
10410 "external" imported declarations and "static" ones. As all imported
10411 declarations seem to be static in all other languages, make them all CU-wide
10412 global only in Ada. */
10414 static struct using_direct
**
10415 using_directives (struct dwarf2_cu
*cu
)
10417 if (cu
->language
== language_ada
10418 && cu
->get_builder ()->outermost_context_p ())
10419 return cu
->get_builder ()->get_global_using_directives ();
10421 return cu
->get_builder ()->get_local_using_directives ();
10424 /* Read the import statement specified by the given die and record it. */
10427 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10429 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10430 struct attribute
*import_attr
;
10431 struct die_info
*imported_die
, *child_die
;
10432 struct dwarf2_cu
*imported_cu
;
10433 const char *imported_name
;
10434 const char *imported_name_prefix
;
10435 const char *canonical_name
;
10436 const char *import_alias
;
10437 const char *imported_declaration
= NULL
;
10438 const char *import_prefix
;
10439 std::vector
<const char *> excludes
;
10441 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10442 if (import_attr
== NULL
)
10444 complaint (_("Tag '%s' has no DW_AT_import"),
10445 dwarf_tag_name (die
->tag
));
10450 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10451 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10452 if (imported_name
== NULL
)
10454 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10456 The import in the following code:
10470 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10471 <52> DW_AT_decl_file : 1
10472 <53> DW_AT_decl_line : 6
10473 <54> DW_AT_import : <0x75>
10474 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10475 <59> DW_AT_name : B
10476 <5b> DW_AT_decl_file : 1
10477 <5c> DW_AT_decl_line : 2
10478 <5d> DW_AT_type : <0x6e>
10480 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10481 <76> DW_AT_byte_size : 4
10482 <77> DW_AT_encoding : 5 (signed)
10484 imports the wrong die ( 0x75 instead of 0x58 ).
10485 This case will be ignored until the gcc bug is fixed. */
10489 /* Figure out the local name after import. */
10490 import_alias
= dwarf2_name (die
, cu
);
10492 /* Figure out where the statement is being imported to. */
10493 import_prefix
= determine_prefix (die
, cu
);
10495 /* Figure out what the scope of the imported die is and prepend it
10496 to the name of the imported die. */
10497 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10499 if (imported_die
->tag
!= DW_TAG_namespace
10500 && imported_die
->tag
!= DW_TAG_module
)
10502 imported_declaration
= imported_name
;
10503 canonical_name
= imported_name_prefix
;
10505 else if (strlen (imported_name_prefix
) > 0)
10506 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10507 imported_name_prefix
,
10508 (cu
->language
== language_d
? "." : "::"),
10509 imported_name
, (char *) NULL
);
10511 canonical_name
= imported_name
;
10513 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10514 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10515 child_die
= sibling_die (child_die
))
10517 /* DWARF-4: A Fortran use statement with a “rename list” may be
10518 represented by an imported module entry with an import attribute
10519 referring to the module and owned entries corresponding to those
10520 entities that are renamed as part of being imported. */
10522 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10524 complaint (_("child DW_TAG_imported_declaration expected "
10525 "- DIE at %s [in module %s]"),
10526 sect_offset_str (child_die
->sect_off
),
10527 objfile_name (objfile
));
10531 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10532 if (import_attr
== NULL
)
10534 complaint (_("Tag '%s' has no DW_AT_import"),
10535 dwarf_tag_name (child_die
->tag
));
10540 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10542 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10543 if (imported_name
== NULL
)
10545 complaint (_("child DW_TAG_imported_declaration has unknown "
10546 "imported name - DIE at %s [in module %s]"),
10547 sect_offset_str (child_die
->sect_off
),
10548 objfile_name (objfile
));
10552 excludes
.push_back (imported_name
);
10554 process_die (child_die
, cu
);
10557 add_using_directive (using_directives (cu
),
10561 imported_declaration
,
10564 &objfile
->objfile_obstack
);
10567 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10568 types, but gives them a size of zero. Starting with version 14,
10569 ICC is compatible with GCC. */
10572 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10574 if (!cu
->checked_producer
)
10575 check_producer (cu
);
10577 return cu
->producer_is_icc_lt_14
;
10580 /* ICC generates a DW_AT_type for C void functions. This was observed on
10581 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10582 which says that void functions should not have a DW_AT_type. */
10585 producer_is_icc (struct dwarf2_cu
*cu
)
10587 if (!cu
->checked_producer
)
10588 check_producer (cu
);
10590 return cu
->producer_is_icc
;
10593 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10594 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10595 this, it was first present in GCC release 4.3.0. */
10598 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10600 if (!cu
->checked_producer
)
10601 check_producer (cu
);
10603 return cu
->producer_is_gcc_lt_4_3
;
10606 static file_and_directory
10607 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10609 file_and_directory res
;
10611 /* Find the filename. Do not use dwarf2_name here, since the filename
10612 is not a source language identifier. */
10613 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10614 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10616 if (res
.comp_dir
== NULL
10617 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10618 && IS_ABSOLUTE_PATH (res
.name
))
10620 res
.comp_dir_storage
= ldirname (res
.name
);
10621 if (!res
.comp_dir_storage
.empty ())
10622 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10624 if (res
.comp_dir
!= NULL
)
10626 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10627 directory, get rid of it. */
10628 const char *cp
= strchr (res
.comp_dir
, ':');
10630 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10631 res
.comp_dir
= cp
+ 1;
10634 if (res
.name
== NULL
)
10635 res
.name
= "<unknown>";
10640 /* Handle DW_AT_stmt_list for a compilation unit.
10641 DIE is the DW_TAG_compile_unit die for CU.
10642 COMP_DIR is the compilation directory. LOWPC is passed to
10643 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10646 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10647 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10649 struct dwarf2_per_objfile
*dwarf2_per_objfile
10650 = cu
->per_cu
->dwarf2_per_objfile
;
10651 struct attribute
*attr
;
10652 struct line_header line_header_local
;
10653 hashval_t line_header_local_hash
;
10655 int decode_mapping
;
10657 gdb_assert (! cu
->per_cu
->is_debug_types
);
10659 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10663 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10665 /* The line header hash table is only created if needed (it exists to
10666 prevent redundant reading of the line table for partial_units).
10667 If we're given a partial_unit, we'll need it. If we're given a
10668 compile_unit, then use the line header hash table if it's already
10669 created, but don't create one just yet. */
10671 if (dwarf2_per_objfile
->line_header_hash
== NULL
10672 && die
->tag
== DW_TAG_partial_unit
)
10674 dwarf2_per_objfile
->line_header_hash
10675 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10676 line_header_eq_voidp
,
10677 free_line_header_voidp
,
10681 line_header_local
.sect_off
= line_offset
;
10682 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10683 line_header_local_hash
= line_header_hash (&line_header_local
);
10684 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10686 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10687 &line_header_local
,
10688 line_header_local_hash
, NO_INSERT
);
10690 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10691 is not present in *SLOT (since if there is something in *SLOT then
10692 it will be for a partial_unit). */
10693 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10695 gdb_assert (*slot
!= NULL
);
10696 cu
->line_header
= (struct line_header
*) *slot
;
10701 /* dwarf_decode_line_header does not yet provide sufficient information.
10702 We always have to call also dwarf_decode_lines for it. */
10703 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10707 cu
->line_header
= lh
.release ();
10708 cu
->line_header_die_owner
= die
;
10710 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10714 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10715 &line_header_local
,
10716 line_header_local_hash
, INSERT
);
10717 gdb_assert (slot
!= NULL
);
10719 if (slot
!= NULL
&& *slot
== NULL
)
10721 /* This newly decoded line number information unit will be owned
10722 by line_header_hash hash table. */
10723 *slot
= cu
->line_header
;
10724 cu
->line_header_die_owner
= NULL
;
10728 /* We cannot free any current entry in (*slot) as that struct line_header
10729 may be already used by multiple CUs. Create only temporary decoded
10730 line_header for this CU - it may happen at most once for each line
10731 number information unit. And if we're not using line_header_hash
10732 then this is what we want as well. */
10733 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10735 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10736 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10741 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10744 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10746 struct dwarf2_per_objfile
*dwarf2_per_objfile
10747 = cu
->per_cu
->dwarf2_per_objfile
;
10748 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10749 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10750 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10751 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10752 struct attribute
*attr
;
10753 struct die_info
*child_die
;
10754 CORE_ADDR baseaddr
;
10756 prepare_one_comp_unit (cu
, die
, cu
->language
);
10757 baseaddr
= objfile
->text_section_offset ();
10759 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10761 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10762 from finish_block. */
10763 if (lowpc
== ((CORE_ADDR
) -1))
10765 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10767 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10769 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10770 standardised yet. As a workaround for the language detection we fall
10771 back to the DW_AT_producer string. */
10772 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10773 cu
->language
= language_opencl
;
10775 /* Similar hack for Go. */
10776 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10777 set_cu_language (DW_LANG_Go
, cu
);
10779 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10781 /* Decode line number information if present. We do this before
10782 processing child DIEs, so that the line header table is available
10783 for DW_AT_decl_file. */
10784 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10786 /* Process all dies in compilation unit. */
10787 if (die
->child
!= NULL
)
10789 child_die
= die
->child
;
10790 while (child_die
&& child_die
->tag
)
10792 process_die (child_die
, cu
);
10793 child_die
= sibling_die (child_die
);
10797 /* Decode macro information, if present. Dwarf 2 macro information
10798 refers to information in the line number info statement program
10799 header, so we can only read it if we've read the header
10801 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10803 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10804 if (attr
&& cu
->line_header
)
10806 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10807 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10809 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10813 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10814 if (attr
&& cu
->line_header
)
10816 unsigned int macro_offset
= DW_UNSND (attr
);
10818 dwarf_decode_macros (cu
, macro_offset
, 0);
10824 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10826 struct type_unit_group
*tu_group
;
10828 struct attribute
*attr
;
10830 struct signatured_type
*sig_type
;
10832 gdb_assert (per_cu
->is_debug_types
);
10833 sig_type
= (struct signatured_type
*) per_cu
;
10835 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10837 /* If we're using .gdb_index (includes -readnow) then
10838 per_cu->type_unit_group may not have been set up yet. */
10839 if (sig_type
->type_unit_group
== NULL
)
10840 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10841 tu_group
= sig_type
->type_unit_group
;
10843 /* If we've already processed this stmt_list there's no real need to
10844 do it again, we could fake it and just recreate the part we need
10845 (file name,index -> symtab mapping). If data shows this optimization
10846 is useful we can do it then. */
10847 first_time
= tu_group
->compunit_symtab
== NULL
;
10849 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10854 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10855 lh
= dwarf_decode_line_header (line_offset
, this);
10860 start_symtab ("", NULL
, 0);
10863 gdb_assert (tu_group
->symtabs
== NULL
);
10864 gdb_assert (m_builder
== nullptr);
10865 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10866 m_builder
.reset (new struct buildsym_compunit
10867 (COMPUNIT_OBJFILE (cust
), "",
10868 COMPUNIT_DIRNAME (cust
),
10869 compunit_language (cust
),
10875 line_header
= lh
.release ();
10876 line_header_die_owner
= die
;
10880 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10882 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10883 still initializing it, and our caller (a few levels up)
10884 process_full_type_unit still needs to know if this is the first
10888 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10889 struct symtab
*, line_header
->file_names_size ());
10891 auto &file_names
= line_header
->file_names ();
10892 for (i
= 0; i
< file_names
.size (); ++i
)
10894 file_entry
&fe
= file_names
[i
];
10895 dwarf2_start_subfile (this, fe
.name
,
10896 fe
.include_dir (line_header
));
10897 buildsym_compunit
*b
= get_builder ();
10898 if (b
->get_current_subfile ()->symtab
== NULL
)
10900 /* NOTE: start_subfile will recognize when it's been
10901 passed a file it has already seen. So we can't
10902 assume there's a simple mapping from
10903 cu->line_header->file_names to subfiles, plus
10904 cu->line_header->file_names may contain dups. */
10905 b
->get_current_subfile ()->symtab
10906 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10909 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10910 tu_group
->symtabs
[i
] = fe
.symtab
;
10915 gdb_assert (m_builder
== nullptr);
10916 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10917 m_builder
.reset (new struct buildsym_compunit
10918 (COMPUNIT_OBJFILE (cust
), "",
10919 COMPUNIT_DIRNAME (cust
),
10920 compunit_language (cust
),
10923 auto &file_names
= line_header
->file_names ();
10924 for (i
= 0; i
< file_names
.size (); ++i
)
10926 file_entry
&fe
= file_names
[i
];
10927 fe
.symtab
= tu_group
->symtabs
[i
];
10931 /* The main symtab is allocated last. Type units don't have DW_AT_name
10932 so they don't have a "real" (so to speak) symtab anyway.
10933 There is later code that will assign the main symtab to all symbols
10934 that don't have one. We need to handle the case of a symbol with a
10935 missing symtab (DW_AT_decl_file) anyway. */
10938 /* Process DW_TAG_type_unit.
10939 For TUs we want to skip the first top level sibling if it's not the
10940 actual type being defined by this TU. In this case the first top
10941 level sibling is there to provide context only. */
10944 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10946 struct die_info
*child_die
;
10948 prepare_one_comp_unit (cu
, die
, language_minimal
);
10950 /* Initialize (or reinitialize) the machinery for building symtabs.
10951 We do this before processing child DIEs, so that the line header table
10952 is available for DW_AT_decl_file. */
10953 cu
->setup_type_unit_groups (die
);
10955 if (die
->child
!= NULL
)
10957 child_die
= die
->child
;
10958 while (child_die
&& child_die
->tag
)
10960 process_die (child_die
, cu
);
10961 child_die
= sibling_die (child_die
);
10968 http://gcc.gnu.org/wiki/DebugFission
10969 http://gcc.gnu.org/wiki/DebugFissionDWP
10971 To simplify handling of both DWO files ("object" files with the DWARF info)
10972 and DWP files (a file with the DWOs packaged up into one file), we treat
10973 DWP files as having a collection of virtual DWO files. */
10976 hash_dwo_file (const void *item
)
10978 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10981 hash
= htab_hash_string (dwo_file
->dwo_name
);
10982 if (dwo_file
->comp_dir
!= NULL
)
10983 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10988 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10990 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10991 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10993 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10995 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10996 return lhs
->comp_dir
== rhs
->comp_dir
;
10997 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11000 /* Allocate a hash table for DWO files. */
11003 allocate_dwo_file_hash_table ()
11005 auto delete_dwo_file
= [] (void *item
)
11007 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11012 return htab_up (htab_create_alloc (41,
11019 /* Lookup DWO file DWO_NAME. */
11022 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11023 const char *dwo_name
,
11024 const char *comp_dir
)
11026 struct dwo_file find_entry
;
11029 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11030 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11032 find_entry
.dwo_name
= dwo_name
;
11033 find_entry
.comp_dir
= comp_dir
;
11034 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11041 hash_dwo_unit (const void *item
)
11043 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11045 /* This drops the top 32 bits of the id, but is ok for a hash. */
11046 return dwo_unit
->signature
;
11050 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11052 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11053 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11055 /* The signature is assumed to be unique within the DWO file.
11056 So while object file CU dwo_id's always have the value zero,
11057 that's OK, assuming each object file DWO file has only one CU,
11058 and that's the rule for now. */
11059 return lhs
->signature
== rhs
->signature
;
11062 /* Allocate a hash table for DWO CUs,TUs.
11063 There is one of these tables for each of CUs,TUs for each DWO file. */
11066 allocate_dwo_unit_table ()
11068 /* Start out with a pretty small number.
11069 Generally DWO files contain only one CU and maybe some TUs. */
11070 return htab_up (htab_create_alloc (3,
11073 NULL
, xcalloc
, xfree
));
11076 /* die_reader_func for create_dwo_cu. */
11079 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11080 const gdb_byte
*info_ptr
,
11081 struct die_info
*comp_unit_die
,
11082 struct dwo_file
*dwo_file
,
11083 struct dwo_unit
*dwo_unit
)
11085 struct dwarf2_cu
*cu
= reader
->cu
;
11086 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11087 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11089 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11090 if (!signature
.has_value ())
11092 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11093 " its dwo_id [in module %s]"),
11094 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11098 dwo_unit
->dwo_file
= dwo_file
;
11099 dwo_unit
->signature
= *signature
;
11100 dwo_unit
->section
= section
;
11101 dwo_unit
->sect_off
= sect_off
;
11102 dwo_unit
->length
= cu
->per_cu
->length
;
11104 if (dwarf_read_debug
)
11105 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11106 sect_offset_str (sect_off
),
11107 hex_string (dwo_unit
->signature
));
11110 /* Create the dwo_units for the CUs in a DWO_FILE.
11111 Note: This function processes DWO files only, not DWP files. */
11114 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11115 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11116 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11118 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11119 const gdb_byte
*info_ptr
, *end_ptr
;
11121 section
.read (objfile
);
11122 info_ptr
= section
.buffer
;
11124 if (info_ptr
== NULL
)
11127 if (dwarf_read_debug
)
11129 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11130 section
.get_name (),
11131 section
.get_file_name ());
11134 end_ptr
= info_ptr
+ section
.size
;
11135 while (info_ptr
< end_ptr
)
11137 struct dwarf2_per_cu_data per_cu
;
11138 struct dwo_unit read_unit
{};
11139 struct dwo_unit
*dwo_unit
;
11141 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11143 memset (&per_cu
, 0, sizeof (per_cu
));
11144 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11145 per_cu
.is_debug_types
= 0;
11146 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11147 per_cu
.section
= §ion
;
11149 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11150 if (!reader
.dummy_p
)
11151 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11152 &dwo_file
, &read_unit
);
11153 info_ptr
+= per_cu
.length
;
11155 // If the unit could not be parsed, skip it.
11156 if (read_unit
.dwo_file
== NULL
)
11159 if (cus_htab
== NULL
)
11160 cus_htab
= allocate_dwo_unit_table ();
11162 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11163 *dwo_unit
= read_unit
;
11164 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11165 gdb_assert (slot
!= NULL
);
11168 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11169 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11171 complaint (_("debug cu entry at offset %s is duplicate to"
11172 " the entry at offset %s, signature %s"),
11173 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11174 hex_string (dwo_unit
->signature
));
11176 *slot
= (void *)dwo_unit
;
11180 /* DWP file .debug_{cu,tu}_index section format:
11181 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11185 Both index sections have the same format, and serve to map a 64-bit
11186 signature to a set of section numbers. Each section begins with a header,
11187 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11188 indexes, and a pool of 32-bit section numbers. The index sections will be
11189 aligned at 8-byte boundaries in the file.
11191 The index section header consists of:
11193 V, 32 bit version number
11195 N, 32 bit number of compilation units or type units in the index
11196 M, 32 bit number of slots in the hash table
11198 Numbers are recorded using the byte order of the application binary.
11200 The hash table begins at offset 16 in the section, and consists of an array
11201 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11202 order of the application binary). Unused slots in the hash table are 0.
11203 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11205 The parallel table begins immediately after the hash table
11206 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11207 array of 32-bit indexes (using the byte order of the application binary),
11208 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11209 table contains a 32-bit index into the pool of section numbers. For unused
11210 hash table slots, the corresponding entry in the parallel table will be 0.
11212 The pool of section numbers begins immediately following the hash table
11213 (at offset 16 + 12 * M from the beginning of the section). The pool of
11214 section numbers consists of an array of 32-bit words (using the byte order
11215 of the application binary). Each item in the array is indexed starting
11216 from 0. The hash table entry provides the index of the first section
11217 number in the set. Additional section numbers in the set follow, and the
11218 set is terminated by a 0 entry (section number 0 is not used in ELF).
11220 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11221 section must be the first entry in the set, and the .debug_abbrev.dwo must
11222 be the second entry. Other members of the set may follow in any order.
11228 DWP Version 2 combines all the .debug_info, etc. sections into one,
11229 and the entries in the index tables are now offsets into these sections.
11230 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11233 Index Section Contents:
11235 Hash Table of Signatures dwp_hash_table.hash_table
11236 Parallel Table of Indices dwp_hash_table.unit_table
11237 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11238 Table of Section Sizes dwp_hash_table.v2.sizes
11240 The index section header consists of:
11242 V, 32 bit version number
11243 L, 32 bit number of columns in the table of section offsets
11244 N, 32 bit number of compilation units or type units in the index
11245 M, 32 bit number of slots in the hash table
11247 Numbers are recorded using the byte order of the application binary.
11249 The hash table has the same format as version 1.
11250 The parallel table of indices has the same format as version 1,
11251 except that the entries are origin-1 indices into the table of sections
11252 offsets and the table of section sizes.
11254 The table of offsets begins immediately following the parallel table
11255 (at offset 16 + 12 * M from the beginning of the section). The table is
11256 a two-dimensional array of 32-bit words (using the byte order of the
11257 application binary), with L columns and N+1 rows, in row-major order.
11258 Each row in the array is indexed starting from 0. The first row provides
11259 a key to the remaining rows: each column in this row provides an identifier
11260 for a debug section, and the offsets in the same column of subsequent rows
11261 refer to that section. The section identifiers are:
11263 DW_SECT_INFO 1 .debug_info.dwo
11264 DW_SECT_TYPES 2 .debug_types.dwo
11265 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11266 DW_SECT_LINE 4 .debug_line.dwo
11267 DW_SECT_LOC 5 .debug_loc.dwo
11268 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11269 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11270 DW_SECT_MACRO 8 .debug_macro.dwo
11272 The offsets provided by the CU and TU index sections are the base offsets
11273 for the contributions made by each CU or TU to the corresponding section
11274 in the package file. Each CU and TU header contains an abbrev_offset
11275 field, used to find the abbreviations table for that CU or TU within the
11276 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11277 be interpreted as relative to the base offset given in the index section.
11278 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11279 should be interpreted as relative to the base offset for .debug_line.dwo,
11280 and offsets into other debug sections obtained from DWARF attributes should
11281 also be interpreted as relative to the corresponding base offset.
11283 The table of sizes begins immediately following the table of offsets.
11284 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11285 with L columns and N rows, in row-major order. Each row in the array is
11286 indexed starting from 1 (row 0 is shared by the two tables).
11290 Hash table lookup is handled the same in version 1 and 2:
11292 We assume that N and M will not exceed 2^32 - 1.
11293 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11295 Given a 64-bit compilation unit signature or a type signature S, an entry
11296 in the hash table is located as follows:
11298 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11299 the low-order k bits all set to 1.
11301 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11303 3) If the hash table entry at index H matches the signature, use that
11304 entry. If the hash table entry at index H is unused (all zeroes),
11305 terminate the search: the signature is not present in the table.
11307 4) Let H = (H + H') modulo M. Repeat at Step 3.
11309 Because M > N and H' and M are relatively prime, the search is guaranteed
11310 to stop at an unused slot or find the match. */
11312 /* Create a hash table to map DWO IDs to their CU/TU entry in
11313 .debug_{info,types}.dwo in DWP_FILE.
11314 Returns NULL if there isn't one.
11315 Note: This function processes DWP files only, not DWO files. */
11317 static struct dwp_hash_table
*
11318 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11319 struct dwp_file
*dwp_file
, int is_debug_types
)
11321 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11322 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11323 const gdb_byte
*index_ptr
, *index_end
;
11324 struct dwarf2_section_info
*index
;
11325 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11326 struct dwp_hash_table
*htab
;
11328 if (is_debug_types
)
11329 index
= &dwp_file
->sections
.tu_index
;
11331 index
= &dwp_file
->sections
.cu_index
;
11333 if (index
->empty ())
11335 index
->read (objfile
);
11337 index_ptr
= index
->buffer
;
11338 index_end
= index_ptr
+ index
->size
;
11340 version
= read_4_bytes (dbfd
, index_ptr
);
11343 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11347 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11349 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11352 if (version
!= 1 && version
!= 2)
11354 error (_("Dwarf Error: unsupported DWP file version (%s)"
11355 " [in module %s]"),
11356 pulongest (version
), dwp_file
->name
);
11358 if (nr_slots
!= (nr_slots
& -nr_slots
))
11360 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11361 " is not power of 2 [in module %s]"),
11362 pulongest (nr_slots
), dwp_file
->name
);
11365 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11366 htab
->version
= version
;
11367 htab
->nr_columns
= nr_columns
;
11368 htab
->nr_units
= nr_units
;
11369 htab
->nr_slots
= nr_slots
;
11370 htab
->hash_table
= index_ptr
;
11371 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11373 /* Exit early if the table is empty. */
11374 if (nr_slots
== 0 || nr_units
== 0
11375 || (version
== 2 && nr_columns
== 0))
11377 /* All must be zero. */
11378 if (nr_slots
!= 0 || nr_units
!= 0
11379 || (version
== 2 && nr_columns
!= 0))
11381 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11382 " all zero [in modules %s]"),
11390 htab
->section_pool
.v1
.indices
=
11391 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11392 /* It's harder to decide whether the section is too small in v1.
11393 V1 is deprecated anyway so we punt. */
11397 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11398 int *ids
= htab
->section_pool
.v2
.section_ids
;
11399 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11400 /* Reverse map for error checking. */
11401 int ids_seen
[DW_SECT_MAX
+ 1];
11404 if (nr_columns
< 2)
11406 error (_("Dwarf Error: bad DWP hash table, too few columns"
11407 " in section table [in module %s]"),
11410 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11412 error (_("Dwarf Error: bad DWP hash table, too many columns"
11413 " in section table [in module %s]"),
11416 memset (ids
, 255, sizeof_ids
);
11417 memset (ids_seen
, 255, sizeof (ids_seen
));
11418 for (i
= 0; i
< nr_columns
; ++i
)
11420 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11422 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11424 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11425 " in section table [in module %s]"),
11426 id
, dwp_file
->name
);
11428 if (ids_seen
[id
] != -1)
11430 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11431 " id %d in section table [in module %s]"),
11432 id
, dwp_file
->name
);
11437 /* Must have exactly one info or types section. */
11438 if (((ids_seen
[DW_SECT_INFO
] != -1)
11439 + (ids_seen
[DW_SECT_TYPES
] != -1))
11442 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11443 " DWO info/types section [in module %s]"),
11446 /* Must have an abbrev section. */
11447 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11449 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11450 " section [in module %s]"),
11453 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11454 htab
->section_pool
.v2
.sizes
=
11455 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11456 * nr_units
* nr_columns
);
11457 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11458 * nr_units
* nr_columns
))
11461 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11462 " [in module %s]"),
11470 /* Update SECTIONS with the data from SECTP.
11472 This function is like the other "locate" section routines that are
11473 passed to bfd_map_over_sections, but in this context the sections to
11474 read comes from the DWP V1 hash table, not the full ELF section table.
11476 The result is non-zero for success, or zero if an error was found. */
11479 locate_v1_virtual_dwo_sections (asection
*sectp
,
11480 struct virtual_v1_dwo_sections
*sections
)
11482 const struct dwop_section_names
*names
= &dwop_section_names
;
11484 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11486 /* There can be only one. */
11487 if (sections
->abbrev
.s
.section
!= NULL
)
11489 sections
->abbrev
.s
.section
= sectp
;
11490 sections
->abbrev
.size
= bfd_section_size (sectp
);
11492 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11493 || section_is_p (sectp
->name
, &names
->types_dwo
))
11495 /* There can be only one. */
11496 if (sections
->info_or_types
.s
.section
!= NULL
)
11498 sections
->info_or_types
.s
.section
= sectp
;
11499 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11501 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11503 /* There can be only one. */
11504 if (sections
->line
.s
.section
!= NULL
)
11506 sections
->line
.s
.section
= sectp
;
11507 sections
->line
.size
= bfd_section_size (sectp
);
11509 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11511 /* There can be only one. */
11512 if (sections
->loc
.s
.section
!= NULL
)
11514 sections
->loc
.s
.section
= sectp
;
11515 sections
->loc
.size
= bfd_section_size (sectp
);
11517 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11519 /* There can be only one. */
11520 if (sections
->macinfo
.s
.section
!= NULL
)
11522 sections
->macinfo
.s
.section
= sectp
;
11523 sections
->macinfo
.size
= bfd_section_size (sectp
);
11525 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11527 /* There can be only one. */
11528 if (sections
->macro
.s
.section
!= NULL
)
11530 sections
->macro
.s
.section
= sectp
;
11531 sections
->macro
.size
= bfd_section_size (sectp
);
11533 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11535 /* There can be only one. */
11536 if (sections
->str_offsets
.s
.section
!= NULL
)
11538 sections
->str_offsets
.s
.section
= sectp
;
11539 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11543 /* No other kind of section is valid. */
11550 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11551 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11552 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11553 This is for DWP version 1 files. */
11555 static struct dwo_unit
*
11556 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11557 struct dwp_file
*dwp_file
,
11558 uint32_t unit_index
,
11559 const char *comp_dir
,
11560 ULONGEST signature
, int is_debug_types
)
11562 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11563 const struct dwp_hash_table
*dwp_htab
=
11564 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11565 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11566 const char *kind
= is_debug_types
? "TU" : "CU";
11567 struct dwo_file
*dwo_file
;
11568 struct dwo_unit
*dwo_unit
;
11569 struct virtual_v1_dwo_sections sections
;
11570 void **dwo_file_slot
;
11573 gdb_assert (dwp_file
->version
== 1);
11575 if (dwarf_read_debug
)
11577 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11579 pulongest (unit_index
), hex_string (signature
),
11583 /* Fetch the sections of this DWO unit.
11584 Put a limit on the number of sections we look for so that bad data
11585 doesn't cause us to loop forever. */
11587 #define MAX_NR_V1_DWO_SECTIONS \
11588 (1 /* .debug_info or .debug_types */ \
11589 + 1 /* .debug_abbrev */ \
11590 + 1 /* .debug_line */ \
11591 + 1 /* .debug_loc */ \
11592 + 1 /* .debug_str_offsets */ \
11593 + 1 /* .debug_macro or .debug_macinfo */ \
11594 + 1 /* trailing zero */)
11596 memset (§ions
, 0, sizeof (sections
));
11598 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11601 uint32_t section_nr
=
11602 read_4_bytes (dbfd
,
11603 dwp_htab
->section_pool
.v1
.indices
11604 + (unit_index
+ i
) * sizeof (uint32_t));
11606 if (section_nr
== 0)
11608 if (section_nr
>= dwp_file
->num_sections
)
11610 error (_("Dwarf Error: bad DWP hash table, section number too large"
11611 " [in module %s]"),
11615 sectp
= dwp_file
->elf_sections
[section_nr
];
11616 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11618 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11619 " [in module %s]"),
11625 || sections
.info_or_types
.empty ()
11626 || sections
.abbrev
.empty ())
11628 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11629 " [in module %s]"),
11632 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11634 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11635 " [in module %s]"),
11639 /* It's easier for the rest of the code if we fake a struct dwo_file and
11640 have dwo_unit "live" in that. At least for now.
11642 The DWP file can be made up of a random collection of CUs and TUs.
11643 However, for each CU + set of TUs that came from the same original DWO
11644 file, we can combine them back into a virtual DWO file to save space
11645 (fewer struct dwo_file objects to allocate). Remember that for really
11646 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11648 std::string virtual_dwo_name
=
11649 string_printf ("virtual-dwo/%d-%d-%d-%d",
11650 sections
.abbrev
.get_id (),
11651 sections
.line
.get_id (),
11652 sections
.loc
.get_id (),
11653 sections
.str_offsets
.get_id ());
11654 /* Can we use an existing virtual DWO file? */
11655 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11656 virtual_dwo_name
.c_str (),
11658 /* Create one if necessary. */
11659 if (*dwo_file_slot
== NULL
)
11661 if (dwarf_read_debug
)
11663 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11664 virtual_dwo_name
.c_str ());
11666 dwo_file
= new struct dwo_file
;
11667 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11668 dwo_file
->comp_dir
= comp_dir
;
11669 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11670 dwo_file
->sections
.line
= sections
.line
;
11671 dwo_file
->sections
.loc
= sections
.loc
;
11672 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11673 dwo_file
->sections
.macro
= sections
.macro
;
11674 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11675 /* The "str" section is global to the entire DWP file. */
11676 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11677 /* The info or types section is assigned below to dwo_unit,
11678 there's no need to record it in dwo_file.
11679 Also, we can't simply record type sections in dwo_file because
11680 we record a pointer into the vector in dwo_unit. As we collect more
11681 types we'll grow the vector and eventually have to reallocate space
11682 for it, invalidating all copies of pointers into the previous
11684 *dwo_file_slot
= dwo_file
;
11688 if (dwarf_read_debug
)
11690 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11691 virtual_dwo_name
.c_str ());
11693 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11696 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11697 dwo_unit
->dwo_file
= dwo_file
;
11698 dwo_unit
->signature
= signature
;
11699 dwo_unit
->section
=
11700 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11701 *dwo_unit
->section
= sections
.info_or_types
;
11702 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11707 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11708 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11709 piece within that section used by a TU/CU, return a virtual section
11710 of just that piece. */
11712 static struct dwarf2_section_info
11713 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11714 struct dwarf2_section_info
*section
,
11715 bfd_size_type offset
, bfd_size_type size
)
11717 struct dwarf2_section_info result
;
11720 gdb_assert (section
!= NULL
);
11721 gdb_assert (!section
->is_virtual
);
11723 memset (&result
, 0, sizeof (result
));
11724 result
.s
.containing_section
= section
;
11725 result
.is_virtual
= true;
11730 sectp
= section
->get_bfd_section ();
11732 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11733 bounds of the real section. This is a pretty-rare event, so just
11734 flag an error (easier) instead of a warning and trying to cope. */
11736 || offset
+ size
> bfd_section_size (sectp
))
11738 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11739 " in section %s [in module %s]"),
11740 sectp
? bfd_section_name (sectp
) : "<unknown>",
11741 objfile_name (dwarf2_per_objfile
->objfile
));
11744 result
.virtual_offset
= offset
;
11745 result
.size
= size
;
11749 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11750 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11751 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11752 This is for DWP version 2 files. */
11754 static struct dwo_unit
*
11755 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11756 struct dwp_file
*dwp_file
,
11757 uint32_t unit_index
,
11758 const char *comp_dir
,
11759 ULONGEST signature
, int is_debug_types
)
11761 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11762 const struct dwp_hash_table
*dwp_htab
=
11763 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11764 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11765 const char *kind
= is_debug_types
? "TU" : "CU";
11766 struct dwo_file
*dwo_file
;
11767 struct dwo_unit
*dwo_unit
;
11768 struct virtual_v2_dwo_sections sections
;
11769 void **dwo_file_slot
;
11772 gdb_assert (dwp_file
->version
== 2);
11774 if (dwarf_read_debug
)
11776 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11778 pulongest (unit_index
), hex_string (signature
),
11782 /* Fetch the section offsets of this DWO unit. */
11784 memset (§ions
, 0, sizeof (sections
));
11786 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11788 uint32_t offset
= read_4_bytes (dbfd
,
11789 dwp_htab
->section_pool
.v2
.offsets
11790 + (((unit_index
- 1) * dwp_htab
->nr_columns
11792 * sizeof (uint32_t)));
11793 uint32_t size
= read_4_bytes (dbfd
,
11794 dwp_htab
->section_pool
.v2
.sizes
11795 + (((unit_index
- 1) * dwp_htab
->nr_columns
11797 * sizeof (uint32_t)));
11799 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11802 case DW_SECT_TYPES
:
11803 sections
.info_or_types_offset
= offset
;
11804 sections
.info_or_types_size
= size
;
11806 case DW_SECT_ABBREV
:
11807 sections
.abbrev_offset
= offset
;
11808 sections
.abbrev_size
= size
;
11811 sections
.line_offset
= offset
;
11812 sections
.line_size
= size
;
11815 sections
.loc_offset
= offset
;
11816 sections
.loc_size
= size
;
11818 case DW_SECT_STR_OFFSETS
:
11819 sections
.str_offsets_offset
= offset
;
11820 sections
.str_offsets_size
= size
;
11822 case DW_SECT_MACINFO
:
11823 sections
.macinfo_offset
= offset
;
11824 sections
.macinfo_size
= size
;
11826 case DW_SECT_MACRO
:
11827 sections
.macro_offset
= offset
;
11828 sections
.macro_size
= size
;
11833 /* It's easier for the rest of the code if we fake a struct dwo_file and
11834 have dwo_unit "live" in that. At least for now.
11836 The DWP file can be made up of a random collection of CUs and TUs.
11837 However, for each CU + set of TUs that came from the same original DWO
11838 file, we can combine them back into a virtual DWO file to save space
11839 (fewer struct dwo_file objects to allocate). Remember that for really
11840 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11842 std::string virtual_dwo_name
=
11843 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11844 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11845 (long) (sections
.line_size
? sections
.line_offset
: 0),
11846 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11847 (long) (sections
.str_offsets_size
11848 ? sections
.str_offsets_offset
: 0));
11849 /* Can we use an existing virtual DWO file? */
11850 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11851 virtual_dwo_name
.c_str (),
11853 /* Create one if necessary. */
11854 if (*dwo_file_slot
== NULL
)
11856 if (dwarf_read_debug
)
11858 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11859 virtual_dwo_name
.c_str ());
11861 dwo_file
= new struct dwo_file
;
11862 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11863 dwo_file
->comp_dir
= comp_dir
;
11864 dwo_file
->sections
.abbrev
=
11865 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11866 sections
.abbrev_offset
, sections
.abbrev_size
);
11867 dwo_file
->sections
.line
=
11868 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11869 sections
.line_offset
, sections
.line_size
);
11870 dwo_file
->sections
.loc
=
11871 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11872 sections
.loc_offset
, sections
.loc_size
);
11873 dwo_file
->sections
.macinfo
=
11874 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11875 sections
.macinfo_offset
, sections
.macinfo_size
);
11876 dwo_file
->sections
.macro
=
11877 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11878 sections
.macro_offset
, sections
.macro_size
);
11879 dwo_file
->sections
.str_offsets
=
11880 create_dwp_v2_section (dwarf2_per_objfile
,
11881 &dwp_file
->sections
.str_offsets
,
11882 sections
.str_offsets_offset
,
11883 sections
.str_offsets_size
);
11884 /* The "str" section is global to the entire DWP file. */
11885 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11886 /* The info or types section is assigned below to dwo_unit,
11887 there's no need to record it in dwo_file.
11888 Also, we can't simply record type sections in dwo_file because
11889 we record a pointer into the vector in dwo_unit. As we collect more
11890 types we'll grow the vector and eventually have to reallocate space
11891 for it, invalidating all copies of pointers into the previous
11893 *dwo_file_slot
= dwo_file
;
11897 if (dwarf_read_debug
)
11899 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11900 virtual_dwo_name
.c_str ());
11902 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11905 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11906 dwo_unit
->dwo_file
= dwo_file
;
11907 dwo_unit
->signature
= signature
;
11908 dwo_unit
->section
=
11909 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11910 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11912 ? &dwp_file
->sections
.types
11913 : &dwp_file
->sections
.info
,
11914 sections
.info_or_types_offset
,
11915 sections
.info_or_types_size
);
11916 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11921 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11922 Returns NULL if the signature isn't found. */
11924 static struct dwo_unit
*
11925 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11926 struct dwp_file
*dwp_file
, const char *comp_dir
,
11927 ULONGEST signature
, int is_debug_types
)
11929 const struct dwp_hash_table
*dwp_htab
=
11930 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11931 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11932 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11933 uint32_t hash
= signature
& mask
;
11934 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11937 struct dwo_unit find_dwo_cu
;
11939 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11940 find_dwo_cu
.signature
= signature
;
11941 slot
= htab_find_slot (is_debug_types
11942 ? dwp_file
->loaded_tus
.get ()
11943 : dwp_file
->loaded_cus
.get (),
11944 &find_dwo_cu
, INSERT
);
11947 return (struct dwo_unit
*) *slot
;
11949 /* Use a for loop so that we don't loop forever on bad debug info. */
11950 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11952 ULONGEST signature_in_table
;
11954 signature_in_table
=
11955 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11956 if (signature_in_table
== signature
)
11958 uint32_t unit_index
=
11959 read_4_bytes (dbfd
,
11960 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11962 if (dwp_file
->version
== 1)
11964 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11965 dwp_file
, unit_index
,
11966 comp_dir
, signature
,
11971 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11972 dwp_file
, unit_index
,
11973 comp_dir
, signature
,
11976 return (struct dwo_unit
*) *slot
;
11978 if (signature_in_table
== 0)
11980 hash
= (hash
+ hash2
) & mask
;
11983 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11984 " [in module %s]"),
11988 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11989 Open the file specified by FILE_NAME and hand it off to BFD for
11990 preliminary analysis. Return a newly initialized bfd *, which
11991 includes a canonicalized copy of FILE_NAME.
11992 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11993 SEARCH_CWD is true if the current directory is to be searched.
11994 It will be searched before debug-file-directory.
11995 If successful, the file is added to the bfd include table of the
11996 objfile's bfd (see gdb_bfd_record_inclusion).
11997 If unable to find/open the file, return NULL.
11998 NOTE: This function is derived from symfile_bfd_open. */
12000 static gdb_bfd_ref_ptr
12001 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12002 const char *file_name
, int is_dwp
, int search_cwd
)
12005 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12006 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12007 to debug_file_directory. */
12008 const char *search_path
;
12009 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12011 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12014 if (*debug_file_directory
!= '\0')
12016 search_path_holder
.reset (concat (".", dirname_separator_string
,
12017 debug_file_directory
,
12019 search_path
= search_path_holder
.get ();
12025 search_path
= debug_file_directory
;
12027 openp_flags flags
= OPF_RETURN_REALPATH
;
12029 flags
|= OPF_SEARCH_IN_PATH
;
12031 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12032 desc
= openp (search_path
, flags
, file_name
,
12033 O_RDONLY
| O_BINARY
, &absolute_name
);
12037 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12039 if (sym_bfd
== NULL
)
12041 bfd_set_cacheable (sym_bfd
.get (), 1);
12043 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12046 /* Success. Record the bfd as having been included by the objfile's bfd.
12047 This is important because things like demangled_names_hash lives in the
12048 objfile's per_bfd space and may have references to things like symbol
12049 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12050 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12055 /* Try to open DWO file FILE_NAME.
12056 COMP_DIR is the DW_AT_comp_dir attribute.
12057 The result is the bfd handle of the file.
12058 If there is a problem finding or opening the file, return NULL.
12059 Upon success, the canonicalized path of the file is stored in the bfd,
12060 same as symfile_bfd_open. */
12062 static gdb_bfd_ref_ptr
12063 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12064 const char *file_name
, const char *comp_dir
)
12066 if (IS_ABSOLUTE_PATH (file_name
))
12067 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12068 0 /*is_dwp*/, 0 /*search_cwd*/);
12070 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12072 if (comp_dir
!= NULL
)
12074 gdb::unique_xmalloc_ptr
<char> path_to_try
12075 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12077 /* NOTE: If comp_dir is a relative path, this will also try the
12078 search path, which seems useful. */
12079 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12080 path_to_try
.get (),
12082 1 /*search_cwd*/));
12087 /* That didn't work, try debug-file-directory, which, despite its name,
12088 is a list of paths. */
12090 if (*debug_file_directory
== '\0')
12093 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12094 0 /*is_dwp*/, 1 /*search_cwd*/);
12097 /* This function is mapped across the sections and remembers the offset and
12098 size of each of the DWO debugging sections we are interested in. */
12101 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12103 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12104 const struct dwop_section_names
*names
= &dwop_section_names
;
12106 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12108 dwo_sections
->abbrev
.s
.section
= sectp
;
12109 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12111 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12113 dwo_sections
->info
.s
.section
= sectp
;
12114 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12116 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12118 dwo_sections
->line
.s
.section
= sectp
;
12119 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12121 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12123 dwo_sections
->loc
.s
.section
= sectp
;
12124 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12126 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12128 dwo_sections
->macinfo
.s
.section
= sectp
;
12129 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12131 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12133 dwo_sections
->macro
.s
.section
= sectp
;
12134 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12136 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12138 dwo_sections
->str
.s
.section
= sectp
;
12139 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12141 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12143 dwo_sections
->str_offsets
.s
.section
= sectp
;
12144 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12146 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12148 struct dwarf2_section_info type_section
;
12150 memset (&type_section
, 0, sizeof (type_section
));
12151 type_section
.s
.section
= sectp
;
12152 type_section
.size
= bfd_section_size (sectp
);
12153 dwo_sections
->types
.push_back (type_section
);
12157 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12158 by PER_CU. This is for the non-DWP case.
12159 The result is NULL if DWO_NAME can't be found. */
12161 static struct dwo_file
*
12162 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12163 const char *dwo_name
, const char *comp_dir
)
12165 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12167 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12170 if (dwarf_read_debug
)
12171 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12175 dwo_file_up
dwo_file (new struct dwo_file
);
12176 dwo_file
->dwo_name
= dwo_name
;
12177 dwo_file
->comp_dir
= comp_dir
;
12178 dwo_file
->dbfd
= std::move (dbfd
);
12180 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12181 &dwo_file
->sections
);
12183 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12184 dwo_file
->sections
.info
, dwo_file
->cus
);
12186 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12187 dwo_file
->sections
.types
, dwo_file
->tus
);
12189 if (dwarf_read_debug
)
12190 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12192 return dwo_file
.release ();
12195 /* This function is mapped across the sections and remembers the offset and
12196 size of each of the DWP debugging sections common to version 1 and 2 that
12197 we are interested in. */
12200 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12201 void *dwp_file_ptr
)
12203 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12204 const struct dwop_section_names
*names
= &dwop_section_names
;
12205 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12207 /* Record the ELF section number for later lookup: this is what the
12208 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12209 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12210 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12212 /* Look for specific sections that we need. */
12213 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12215 dwp_file
->sections
.str
.s
.section
= sectp
;
12216 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12218 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12220 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12221 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12223 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12225 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12226 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12230 /* This function is mapped across the sections and remembers the offset and
12231 size of each of the DWP version 2 debugging sections that we are interested
12232 in. This is split into a separate function because we don't know if we
12233 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12236 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12238 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12239 const struct dwop_section_names
*names
= &dwop_section_names
;
12240 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12242 /* Record the ELF section number for later lookup: this is what the
12243 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12244 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12245 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12247 /* Look for specific sections that we need. */
12248 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12250 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12251 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12253 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12255 dwp_file
->sections
.info
.s
.section
= sectp
;
12256 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12258 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12260 dwp_file
->sections
.line
.s
.section
= sectp
;
12261 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12263 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12265 dwp_file
->sections
.loc
.s
.section
= sectp
;
12266 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12268 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12270 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12271 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12273 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12275 dwp_file
->sections
.macro
.s
.section
= sectp
;
12276 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12278 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12280 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12281 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12283 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12285 dwp_file
->sections
.types
.s
.section
= sectp
;
12286 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12290 /* Hash function for dwp_file loaded CUs/TUs. */
12293 hash_dwp_loaded_cutus (const void *item
)
12295 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12297 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12298 return dwo_unit
->signature
;
12301 /* Equality function for dwp_file loaded CUs/TUs. */
12304 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12306 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12307 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12309 return dua
->signature
== dub
->signature
;
12312 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12315 allocate_dwp_loaded_cutus_table ()
12317 return htab_up (htab_create_alloc (3,
12318 hash_dwp_loaded_cutus
,
12319 eq_dwp_loaded_cutus
,
12320 NULL
, xcalloc
, xfree
));
12323 /* Try to open DWP file FILE_NAME.
12324 The result is the bfd handle of the file.
12325 If there is a problem finding or opening the file, return NULL.
12326 Upon success, the canonicalized path of the file is stored in the bfd,
12327 same as symfile_bfd_open. */
12329 static gdb_bfd_ref_ptr
12330 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12331 const char *file_name
)
12333 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12335 1 /*search_cwd*/));
12339 /* Work around upstream bug 15652.
12340 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12341 [Whether that's a "bug" is debatable, but it is getting in our way.]
12342 We have no real idea where the dwp file is, because gdb's realpath-ing
12343 of the executable's path may have discarded the needed info.
12344 [IWBN if the dwp file name was recorded in the executable, akin to
12345 .gnu_debuglink, but that doesn't exist yet.]
12346 Strip the directory from FILE_NAME and search again. */
12347 if (*debug_file_directory
!= '\0')
12349 /* Don't implicitly search the current directory here.
12350 If the user wants to search "." to handle this case,
12351 it must be added to debug-file-directory. */
12352 return try_open_dwop_file (dwarf2_per_objfile
,
12353 lbasename (file_name
), 1 /*is_dwp*/,
12360 /* Initialize the use of the DWP file for the current objfile.
12361 By convention the name of the DWP file is ${objfile}.dwp.
12362 The result is NULL if it can't be found. */
12364 static std::unique_ptr
<struct dwp_file
>
12365 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12367 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12369 /* Try to find first .dwp for the binary file before any symbolic links
12372 /* If the objfile is a debug file, find the name of the real binary
12373 file and get the name of dwp file from there. */
12374 std::string dwp_name
;
12375 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12377 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12378 const char *backlink_basename
= lbasename (backlink
->original_name
);
12380 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12383 dwp_name
= objfile
->original_name
;
12385 dwp_name
+= ".dwp";
12387 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12389 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12391 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12392 dwp_name
= objfile_name (objfile
);
12393 dwp_name
+= ".dwp";
12394 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12399 if (dwarf_read_debug
)
12400 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12401 return std::unique_ptr
<dwp_file
> ();
12404 const char *name
= bfd_get_filename (dbfd
.get ());
12405 std::unique_ptr
<struct dwp_file
> dwp_file
12406 (new struct dwp_file (name
, std::move (dbfd
)));
12408 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12409 dwp_file
->elf_sections
=
12410 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12411 dwp_file
->num_sections
, asection
*);
12413 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12414 dwarf2_locate_common_dwp_sections
,
12417 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12420 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12423 /* The DWP file version is stored in the hash table. Oh well. */
12424 if (dwp_file
->cus
&& dwp_file
->tus
12425 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12427 /* Technically speaking, we should try to limp along, but this is
12428 pretty bizarre. We use pulongest here because that's the established
12429 portability solution (e.g, we cannot use %u for uint32_t). */
12430 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12431 " TU version %s [in DWP file %s]"),
12432 pulongest (dwp_file
->cus
->version
),
12433 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12437 dwp_file
->version
= dwp_file
->cus
->version
;
12438 else if (dwp_file
->tus
)
12439 dwp_file
->version
= dwp_file
->tus
->version
;
12441 dwp_file
->version
= 2;
12443 if (dwp_file
->version
== 2)
12444 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12445 dwarf2_locate_v2_dwp_sections
,
12448 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12449 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12451 if (dwarf_read_debug
)
12453 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12454 fprintf_unfiltered (gdb_stdlog
,
12455 " %s CUs, %s TUs\n",
12456 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12457 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12463 /* Wrapper around open_and_init_dwp_file, only open it once. */
12465 static struct dwp_file
*
12466 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12468 if (! dwarf2_per_objfile
->dwp_checked
)
12470 dwarf2_per_objfile
->dwp_file
12471 = open_and_init_dwp_file (dwarf2_per_objfile
);
12472 dwarf2_per_objfile
->dwp_checked
= 1;
12474 return dwarf2_per_objfile
->dwp_file
.get ();
12477 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12478 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12479 or in the DWP file for the objfile, referenced by THIS_UNIT.
12480 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12481 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12483 This is called, for example, when wanting to read a variable with a
12484 complex location. Therefore we don't want to do file i/o for every call.
12485 Therefore we don't want to look for a DWO file on every call.
12486 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12487 then we check if we've already seen DWO_NAME, and only THEN do we check
12490 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12491 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12493 static struct dwo_unit
*
12494 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12495 const char *dwo_name
, const char *comp_dir
,
12496 ULONGEST signature
, int is_debug_types
)
12498 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12499 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12500 const char *kind
= is_debug_types
? "TU" : "CU";
12501 void **dwo_file_slot
;
12502 struct dwo_file
*dwo_file
;
12503 struct dwp_file
*dwp_file
;
12505 /* First see if there's a DWP file.
12506 If we have a DWP file but didn't find the DWO inside it, don't
12507 look for the original DWO file. It makes gdb behave differently
12508 depending on whether one is debugging in the build tree. */
12510 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12511 if (dwp_file
!= NULL
)
12513 const struct dwp_hash_table
*dwp_htab
=
12514 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12516 if (dwp_htab
!= NULL
)
12518 struct dwo_unit
*dwo_cutu
=
12519 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12520 signature
, is_debug_types
);
12522 if (dwo_cutu
!= NULL
)
12524 if (dwarf_read_debug
)
12526 fprintf_unfiltered (gdb_stdlog
,
12527 "Virtual DWO %s %s found: @%s\n",
12528 kind
, hex_string (signature
),
12529 host_address_to_string (dwo_cutu
));
12537 /* No DWP file, look for the DWO file. */
12539 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12540 dwo_name
, comp_dir
);
12541 if (*dwo_file_slot
== NULL
)
12543 /* Read in the file and build a table of the CUs/TUs it contains. */
12544 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12546 /* NOTE: This will be NULL if unable to open the file. */
12547 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12549 if (dwo_file
!= NULL
)
12551 struct dwo_unit
*dwo_cutu
= NULL
;
12553 if (is_debug_types
&& dwo_file
->tus
)
12555 struct dwo_unit find_dwo_cutu
;
12557 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12558 find_dwo_cutu
.signature
= signature
;
12560 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12563 else if (!is_debug_types
&& dwo_file
->cus
)
12565 struct dwo_unit find_dwo_cutu
;
12567 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12568 find_dwo_cutu
.signature
= signature
;
12569 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12573 if (dwo_cutu
!= NULL
)
12575 if (dwarf_read_debug
)
12577 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12578 kind
, dwo_name
, hex_string (signature
),
12579 host_address_to_string (dwo_cutu
));
12586 /* We didn't find it. This could mean a dwo_id mismatch, or
12587 someone deleted the DWO/DWP file, or the search path isn't set up
12588 correctly to find the file. */
12590 if (dwarf_read_debug
)
12592 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12593 kind
, dwo_name
, hex_string (signature
));
12596 /* This is a warning and not a complaint because it can be caused by
12597 pilot error (e.g., user accidentally deleting the DWO). */
12599 /* Print the name of the DWP file if we looked there, helps the user
12600 better diagnose the problem. */
12601 std::string dwp_text
;
12603 if (dwp_file
!= NULL
)
12604 dwp_text
= string_printf (" [in DWP file %s]",
12605 lbasename (dwp_file
->name
));
12607 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12608 " [in module %s]"),
12609 kind
, dwo_name
, hex_string (signature
),
12611 this_unit
->is_debug_types
? "TU" : "CU",
12612 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12617 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12618 See lookup_dwo_cutu_unit for details. */
12620 static struct dwo_unit
*
12621 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12622 const char *dwo_name
, const char *comp_dir
,
12623 ULONGEST signature
)
12625 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12628 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12629 See lookup_dwo_cutu_unit for details. */
12631 static struct dwo_unit
*
12632 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12633 const char *dwo_name
, const char *comp_dir
)
12635 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12638 /* Traversal function for queue_and_load_all_dwo_tus. */
12641 queue_and_load_dwo_tu (void **slot
, void *info
)
12643 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12644 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12645 ULONGEST signature
= dwo_unit
->signature
;
12646 struct signatured_type
*sig_type
=
12647 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12649 if (sig_type
!= NULL
)
12651 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12653 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12654 a real dependency of PER_CU on SIG_TYPE. That is detected later
12655 while processing PER_CU. */
12656 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12657 load_full_type_unit (sig_cu
);
12658 per_cu
->imported_symtabs_push (sig_cu
);
12664 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12665 The DWO may have the only definition of the type, though it may not be
12666 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12667 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12670 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12672 struct dwo_unit
*dwo_unit
;
12673 struct dwo_file
*dwo_file
;
12675 gdb_assert (!per_cu
->is_debug_types
);
12676 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12677 gdb_assert (per_cu
->cu
!= NULL
);
12679 dwo_unit
= per_cu
->cu
->dwo_unit
;
12680 gdb_assert (dwo_unit
!= NULL
);
12682 dwo_file
= dwo_unit
->dwo_file
;
12683 if (dwo_file
->tus
!= NULL
)
12684 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12688 /* Read in various DIEs. */
12690 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12691 Inherit only the children of the DW_AT_abstract_origin DIE not being
12692 already referenced by DW_AT_abstract_origin from the children of the
12696 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12698 struct die_info
*child_die
;
12699 sect_offset
*offsetp
;
12700 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12701 struct die_info
*origin_die
;
12702 /* Iterator of the ORIGIN_DIE children. */
12703 struct die_info
*origin_child_die
;
12704 struct attribute
*attr
;
12705 struct dwarf2_cu
*origin_cu
;
12706 struct pending
**origin_previous_list_in_scope
;
12708 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12712 /* Note that following die references may follow to a die in a
12716 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12718 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12720 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12721 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12723 if (die
->tag
!= origin_die
->tag
12724 && !(die
->tag
== DW_TAG_inlined_subroutine
12725 && origin_die
->tag
== DW_TAG_subprogram
))
12726 complaint (_("DIE %s and its abstract origin %s have different tags"),
12727 sect_offset_str (die
->sect_off
),
12728 sect_offset_str (origin_die
->sect_off
));
12730 std::vector
<sect_offset
> offsets
;
12732 for (child_die
= die
->child
;
12733 child_die
&& child_die
->tag
;
12734 child_die
= sibling_die (child_die
))
12736 struct die_info
*child_origin_die
;
12737 struct dwarf2_cu
*child_origin_cu
;
12739 /* We are trying to process concrete instance entries:
12740 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12741 it's not relevant to our analysis here. i.e. detecting DIEs that are
12742 present in the abstract instance but not referenced in the concrete
12744 if (child_die
->tag
== DW_TAG_call_site
12745 || child_die
->tag
== DW_TAG_GNU_call_site
)
12748 /* For each CHILD_DIE, find the corresponding child of
12749 ORIGIN_DIE. If there is more than one layer of
12750 DW_AT_abstract_origin, follow them all; there shouldn't be,
12751 but GCC versions at least through 4.4 generate this (GCC PR
12753 child_origin_die
= child_die
;
12754 child_origin_cu
= cu
;
12757 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12761 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12765 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12766 counterpart may exist. */
12767 if (child_origin_die
!= child_die
)
12769 if (child_die
->tag
!= child_origin_die
->tag
12770 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12771 && child_origin_die
->tag
== DW_TAG_subprogram
))
12772 complaint (_("Child DIE %s and its abstract origin %s have "
12774 sect_offset_str (child_die
->sect_off
),
12775 sect_offset_str (child_origin_die
->sect_off
));
12776 if (child_origin_die
->parent
!= origin_die
)
12777 complaint (_("Child DIE %s and its abstract origin %s have "
12778 "different parents"),
12779 sect_offset_str (child_die
->sect_off
),
12780 sect_offset_str (child_origin_die
->sect_off
));
12782 offsets
.push_back (child_origin_die
->sect_off
);
12785 std::sort (offsets
.begin (), offsets
.end ());
12786 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12787 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12788 if (offsetp
[-1] == *offsetp
)
12789 complaint (_("Multiple children of DIE %s refer "
12790 "to DIE %s as their abstract origin"),
12791 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12793 offsetp
= offsets
.data ();
12794 origin_child_die
= origin_die
->child
;
12795 while (origin_child_die
&& origin_child_die
->tag
)
12797 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12798 while (offsetp
< offsets_end
12799 && *offsetp
< origin_child_die
->sect_off
)
12801 if (offsetp
>= offsets_end
12802 || *offsetp
> origin_child_die
->sect_off
)
12804 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12805 Check whether we're already processing ORIGIN_CHILD_DIE.
12806 This can happen with mutually referenced abstract_origins.
12808 if (!origin_child_die
->in_process
)
12809 process_die (origin_child_die
, origin_cu
);
12811 origin_child_die
= sibling_die (origin_child_die
);
12813 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12815 if (cu
!= origin_cu
)
12816 compute_delayed_physnames (origin_cu
);
12820 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12822 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12823 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12824 struct context_stack
*newobj
;
12827 struct die_info
*child_die
;
12828 struct attribute
*attr
, *call_line
, *call_file
;
12830 CORE_ADDR baseaddr
;
12831 struct block
*block
;
12832 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12833 std::vector
<struct symbol
*> template_args
;
12834 struct template_symbol
*templ_func
= NULL
;
12838 /* If we do not have call site information, we can't show the
12839 caller of this inlined function. That's too confusing, so
12840 only use the scope for local variables. */
12841 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12842 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12843 if (call_line
== NULL
|| call_file
== NULL
)
12845 read_lexical_block_scope (die
, cu
);
12850 baseaddr
= objfile
->text_section_offset ();
12852 name
= dwarf2_name (die
, cu
);
12854 /* Ignore functions with missing or empty names. These are actually
12855 illegal according to the DWARF standard. */
12858 complaint (_("missing name for subprogram DIE at %s"),
12859 sect_offset_str (die
->sect_off
));
12863 /* Ignore functions with missing or invalid low and high pc attributes. */
12864 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12865 <= PC_BOUNDS_INVALID
)
12867 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12868 if (!attr
|| !DW_UNSND (attr
))
12869 complaint (_("cannot get low and high bounds "
12870 "for subprogram DIE at %s"),
12871 sect_offset_str (die
->sect_off
));
12875 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12876 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12878 /* If we have any template arguments, then we must allocate a
12879 different sort of symbol. */
12880 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12882 if (child_die
->tag
== DW_TAG_template_type_param
12883 || child_die
->tag
== DW_TAG_template_value_param
)
12885 templ_func
= allocate_template_symbol (objfile
);
12886 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12891 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12892 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12893 (struct symbol
*) templ_func
);
12895 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12896 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12899 /* If there is a location expression for DW_AT_frame_base, record
12901 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12902 if (attr
!= nullptr)
12903 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12905 /* If there is a location for the static link, record it. */
12906 newobj
->static_link
= NULL
;
12907 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12908 if (attr
!= nullptr)
12910 newobj
->static_link
12911 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12912 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12913 cu
->per_cu
->addr_type ());
12916 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12918 if (die
->child
!= NULL
)
12920 child_die
= die
->child
;
12921 while (child_die
&& child_die
->tag
)
12923 if (child_die
->tag
== DW_TAG_template_type_param
12924 || child_die
->tag
== DW_TAG_template_value_param
)
12926 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12929 template_args
.push_back (arg
);
12932 process_die (child_die
, cu
);
12933 child_die
= sibling_die (child_die
);
12937 inherit_abstract_dies (die
, cu
);
12939 /* If we have a DW_AT_specification, we might need to import using
12940 directives from the context of the specification DIE. See the
12941 comment in determine_prefix. */
12942 if (cu
->language
== language_cplus
12943 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12945 struct dwarf2_cu
*spec_cu
= cu
;
12946 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12950 child_die
= spec_die
->child
;
12951 while (child_die
&& child_die
->tag
)
12953 if (child_die
->tag
== DW_TAG_imported_module
)
12954 process_die (child_die
, spec_cu
);
12955 child_die
= sibling_die (child_die
);
12958 /* In some cases, GCC generates specification DIEs that
12959 themselves contain DW_AT_specification attributes. */
12960 spec_die
= die_specification (spec_die
, &spec_cu
);
12964 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12965 /* Make a block for the local symbols within. */
12966 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12967 cstk
.static_link
, lowpc
, highpc
);
12969 /* For C++, set the block's scope. */
12970 if ((cu
->language
== language_cplus
12971 || cu
->language
== language_fortran
12972 || cu
->language
== language_d
12973 || cu
->language
== language_rust
)
12974 && cu
->processing_has_namespace_info
)
12975 block_set_scope (block
, determine_prefix (die
, cu
),
12976 &objfile
->objfile_obstack
);
12978 /* If we have address ranges, record them. */
12979 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12981 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12983 /* Attach template arguments to function. */
12984 if (!template_args
.empty ())
12986 gdb_assert (templ_func
!= NULL
);
12988 templ_func
->n_template_arguments
= template_args
.size ();
12989 templ_func
->template_arguments
12990 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12991 templ_func
->n_template_arguments
);
12992 memcpy (templ_func
->template_arguments
,
12993 template_args
.data (),
12994 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12996 /* Make sure that the symtab is set on the new symbols. Even
12997 though they don't appear in this symtab directly, other parts
12998 of gdb assume that symbols do, and this is reasonably
13000 for (symbol
*sym
: template_args
)
13001 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13004 /* In C++, we can have functions nested inside functions (e.g., when
13005 a function declares a class that has methods). This means that
13006 when we finish processing a function scope, we may need to go
13007 back to building a containing block's symbol lists. */
13008 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13009 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13011 /* If we've finished processing a top-level function, subsequent
13012 symbols go in the file symbol list. */
13013 if (cu
->get_builder ()->outermost_context_p ())
13014 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13017 /* Process all the DIES contained within a lexical block scope. Start
13018 a new scope, process the dies, and then close the scope. */
13021 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13023 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13024 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13025 CORE_ADDR lowpc
, highpc
;
13026 struct die_info
*child_die
;
13027 CORE_ADDR baseaddr
;
13029 baseaddr
= objfile
->text_section_offset ();
13031 /* Ignore blocks with missing or invalid low and high pc attributes. */
13032 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13033 as multiple lexical blocks? Handling children in a sane way would
13034 be nasty. Might be easier to properly extend generic blocks to
13035 describe ranges. */
13036 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13038 case PC_BOUNDS_NOT_PRESENT
:
13039 /* DW_TAG_lexical_block has no attributes, process its children as if
13040 there was no wrapping by that DW_TAG_lexical_block.
13041 GCC does no longer produces such DWARF since GCC r224161. */
13042 for (child_die
= die
->child
;
13043 child_die
!= NULL
&& child_die
->tag
;
13044 child_die
= sibling_die (child_die
))
13045 process_die (child_die
, cu
);
13047 case PC_BOUNDS_INVALID
:
13050 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13051 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13053 cu
->get_builder ()->push_context (0, lowpc
);
13054 if (die
->child
!= NULL
)
13056 child_die
= die
->child
;
13057 while (child_die
&& child_die
->tag
)
13059 process_die (child_die
, cu
);
13060 child_die
= sibling_die (child_die
);
13063 inherit_abstract_dies (die
, cu
);
13064 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13066 if (*cu
->get_builder ()->get_local_symbols () != NULL
13067 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13069 struct block
*block
13070 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13071 cstk
.start_addr
, highpc
);
13073 /* Note that recording ranges after traversing children, as we
13074 do here, means that recording a parent's ranges entails
13075 walking across all its children's ranges as they appear in
13076 the address map, which is quadratic behavior.
13078 It would be nicer to record the parent's ranges before
13079 traversing its children, simply overriding whatever you find
13080 there. But since we don't even decide whether to create a
13081 block until after we've traversed its children, that's hard
13083 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13085 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13086 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13089 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13092 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13094 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13095 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13096 CORE_ADDR pc
, baseaddr
;
13097 struct attribute
*attr
;
13098 struct call_site
*call_site
, call_site_local
;
13101 struct die_info
*child_die
;
13103 baseaddr
= objfile
->text_section_offset ();
13105 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13108 /* This was a pre-DWARF-5 GNU extension alias
13109 for DW_AT_call_return_pc. */
13110 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13114 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13115 "DIE %s [in module %s]"),
13116 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13119 pc
= attr
->value_as_address () + baseaddr
;
13120 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13122 if (cu
->call_site_htab
== NULL
)
13123 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13124 NULL
, &objfile
->objfile_obstack
,
13125 hashtab_obstack_allocate
, NULL
);
13126 call_site_local
.pc
= pc
;
13127 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13130 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13131 "DIE %s [in module %s]"),
13132 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13133 objfile_name (objfile
));
13137 /* Count parameters at the caller. */
13140 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13141 child_die
= sibling_die (child_die
))
13143 if (child_die
->tag
!= DW_TAG_call_site_parameter
13144 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13146 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13147 "DW_TAG_call_site child DIE %s [in module %s]"),
13148 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13149 objfile_name (objfile
));
13157 = ((struct call_site
*)
13158 obstack_alloc (&objfile
->objfile_obstack
,
13159 sizeof (*call_site
)
13160 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13162 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13163 call_site
->pc
= pc
;
13165 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13166 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13168 struct die_info
*func_die
;
13170 /* Skip also over DW_TAG_inlined_subroutine. */
13171 for (func_die
= die
->parent
;
13172 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13173 && func_die
->tag
!= DW_TAG_subroutine_type
;
13174 func_die
= func_die
->parent
);
13176 /* DW_AT_call_all_calls is a superset
13177 of DW_AT_call_all_tail_calls. */
13179 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13180 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13181 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13182 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13184 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13185 not complete. But keep CALL_SITE for look ups via call_site_htab,
13186 both the initial caller containing the real return address PC and
13187 the final callee containing the current PC of a chain of tail
13188 calls do not need to have the tail call list complete. But any
13189 function candidate for a virtual tail call frame searched via
13190 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13191 determined unambiguously. */
13195 struct type
*func_type
= NULL
;
13198 func_type
= get_die_type (func_die
, cu
);
13199 if (func_type
!= NULL
)
13201 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13203 /* Enlist this call site to the function. */
13204 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13205 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13208 complaint (_("Cannot find function owning DW_TAG_call_site "
13209 "DIE %s [in module %s]"),
13210 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13214 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13216 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13218 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13221 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13222 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13224 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13225 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13226 /* Keep NULL DWARF_BLOCK. */;
13227 else if (attr
->form_is_block ())
13229 struct dwarf2_locexpr_baton
*dlbaton
;
13231 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13232 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13233 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13234 dlbaton
->per_cu
= cu
->per_cu
;
13236 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13238 else if (attr
->form_is_ref ())
13240 struct dwarf2_cu
*target_cu
= cu
;
13241 struct die_info
*target_die
;
13243 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13244 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13245 if (die_is_declaration (target_die
, target_cu
))
13247 const char *target_physname
;
13249 /* Prefer the mangled name; otherwise compute the demangled one. */
13250 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13251 if (target_physname
== NULL
)
13252 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13253 if (target_physname
== NULL
)
13254 complaint (_("DW_AT_call_target target DIE has invalid "
13255 "physname, for referencing DIE %s [in module %s]"),
13256 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13258 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13264 /* DW_AT_entry_pc should be preferred. */
13265 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13266 <= PC_BOUNDS_INVALID
)
13267 complaint (_("DW_AT_call_target target DIE has invalid "
13268 "low pc, for referencing DIE %s [in module %s]"),
13269 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13272 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13273 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13278 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13279 "block nor reference, for DIE %s [in module %s]"),
13280 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13282 call_site
->per_cu
= cu
->per_cu
;
13284 for (child_die
= die
->child
;
13285 child_die
&& child_die
->tag
;
13286 child_die
= sibling_die (child_die
))
13288 struct call_site_parameter
*parameter
;
13289 struct attribute
*loc
, *origin
;
13291 if (child_die
->tag
!= DW_TAG_call_site_parameter
13292 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13294 /* Already printed the complaint above. */
13298 gdb_assert (call_site
->parameter_count
< nparams
);
13299 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13301 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13302 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13303 register is contained in DW_AT_call_value. */
13305 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13306 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13307 if (origin
== NULL
)
13309 /* This was a pre-DWARF-5 GNU extension alias
13310 for DW_AT_call_parameter. */
13311 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13313 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13315 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13317 sect_offset sect_off
13318 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13319 if (!cu
->header
.offset_in_cu_p (sect_off
))
13321 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13322 binding can be done only inside one CU. Such referenced DIE
13323 therefore cannot be even moved to DW_TAG_partial_unit. */
13324 complaint (_("DW_AT_call_parameter offset is not in CU for "
13325 "DW_TAG_call_site child DIE %s [in module %s]"),
13326 sect_offset_str (child_die
->sect_off
),
13327 objfile_name (objfile
));
13330 parameter
->u
.param_cu_off
13331 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13333 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13335 complaint (_("No DW_FORM_block* DW_AT_location for "
13336 "DW_TAG_call_site child DIE %s [in module %s]"),
13337 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13342 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13343 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13344 if (parameter
->u
.dwarf_reg
!= -1)
13345 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13346 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13347 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13348 ¶meter
->u
.fb_offset
))
13349 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13352 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13353 "for DW_FORM_block* DW_AT_location is supported for "
13354 "DW_TAG_call_site child DIE %s "
13356 sect_offset_str (child_die
->sect_off
),
13357 objfile_name (objfile
));
13362 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13364 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13365 if (attr
== NULL
|| !attr
->form_is_block ())
13367 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13368 "DW_TAG_call_site child DIE %s [in module %s]"),
13369 sect_offset_str (child_die
->sect_off
),
13370 objfile_name (objfile
));
13373 parameter
->value
= DW_BLOCK (attr
)->data
;
13374 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13376 /* Parameters are not pre-cleared by memset above. */
13377 parameter
->data_value
= NULL
;
13378 parameter
->data_value_size
= 0;
13379 call_site
->parameter_count
++;
13381 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13383 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13384 if (attr
!= nullptr)
13386 if (!attr
->form_is_block ())
13387 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13388 "DW_TAG_call_site child DIE %s [in module %s]"),
13389 sect_offset_str (child_die
->sect_off
),
13390 objfile_name (objfile
));
13393 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13394 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13400 /* Helper function for read_variable. If DIE represents a virtual
13401 table, then return the type of the concrete object that is
13402 associated with the virtual table. Otherwise, return NULL. */
13404 static struct type
*
13405 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13407 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13411 /* Find the type DIE. */
13412 struct die_info
*type_die
= NULL
;
13413 struct dwarf2_cu
*type_cu
= cu
;
13415 if (attr
->form_is_ref ())
13416 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13417 if (type_die
== NULL
)
13420 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13422 return die_containing_type (type_die
, type_cu
);
13425 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13428 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13430 struct rust_vtable_symbol
*storage
= NULL
;
13432 if (cu
->language
== language_rust
)
13434 struct type
*containing_type
= rust_containing_type (die
, cu
);
13436 if (containing_type
!= NULL
)
13438 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13440 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13441 initialize_objfile_symbol (storage
);
13442 storage
->concrete_type
= containing_type
;
13443 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13447 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13448 struct attribute
*abstract_origin
13449 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13450 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13451 if (res
== NULL
&& loc
&& abstract_origin
)
13453 /* We have a variable without a name, but with a location and an abstract
13454 origin. This may be a concrete instance of an abstract variable
13455 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13457 struct dwarf2_cu
*origin_cu
= cu
;
13458 struct die_info
*origin_die
13459 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13460 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13461 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13465 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13466 reading .debug_rnglists.
13467 Callback's type should be:
13468 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13469 Return true if the attributes are present and valid, otherwise,
13472 template <typename Callback
>
13474 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13475 Callback
&&callback
)
13477 struct dwarf2_per_objfile
*dwarf2_per_objfile
13478 = cu
->per_cu
->dwarf2_per_objfile
;
13479 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13480 bfd
*obfd
= objfile
->obfd
;
13481 /* Base address selection entry. */
13484 const gdb_byte
*buffer
;
13485 CORE_ADDR baseaddr
;
13486 bool overflow
= false;
13488 found_base
= cu
->base_known
;
13489 base
= cu
->base_address
;
13491 dwarf2_per_objfile
->rnglists
.read (objfile
);
13492 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13494 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13498 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13500 baseaddr
= objfile
->text_section_offset ();
13504 /* Initialize it due to a false compiler warning. */
13505 CORE_ADDR range_beginning
= 0, range_end
= 0;
13506 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13507 + dwarf2_per_objfile
->rnglists
.size
);
13508 unsigned int bytes_read
;
13510 if (buffer
== buf_end
)
13515 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13518 case DW_RLE_end_of_list
:
13520 case DW_RLE_base_address
:
13521 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13526 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13528 buffer
+= bytes_read
;
13530 case DW_RLE_start_length
:
13531 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13536 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13538 buffer
+= bytes_read
;
13539 range_end
= (range_beginning
13540 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13541 buffer
+= bytes_read
;
13542 if (buffer
> buf_end
)
13548 case DW_RLE_offset_pair
:
13549 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13550 buffer
+= bytes_read
;
13551 if (buffer
> buf_end
)
13556 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13557 buffer
+= bytes_read
;
13558 if (buffer
> buf_end
)
13564 case DW_RLE_start_end
:
13565 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13570 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13572 buffer
+= bytes_read
;
13573 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13574 buffer
+= bytes_read
;
13577 complaint (_("Invalid .debug_rnglists data (no base address)"));
13580 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13582 if (rlet
== DW_RLE_base_address
)
13587 /* We have no valid base address for the ranges
13589 complaint (_("Invalid .debug_rnglists data (no base address)"));
13593 if (range_beginning
> range_end
)
13595 /* Inverted range entries are invalid. */
13596 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13600 /* Empty range entries have no effect. */
13601 if (range_beginning
== range_end
)
13604 range_beginning
+= base
;
13607 /* A not-uncommon case of bad debug info.
13608 Don't pollute the addrmap with bad data. */
13609 if (range_beginning
+ baseaddr
== 0
13610 && !dwarf2_per_objfile
->has_section_at_zero
)
13612 complaint (_(".debug_rnglists entry has start address of zero"
13613 " [in module %s]"), objfile_name (objfile
));
13617 callback (range_beginning
, range_end
);
13622 complaint (_("Offset %d is not terminated "
13623 "for DW_AT_ranges attribute"),
13631 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13632 Callback's type should be:
13633 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13634 Return 1 if the attributes are present and valid, otherwise, return 0. */
13636 template <typename Callback
>
13638 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13639 Callback
&&callback
)
13641 struct dwarf2_per_objfile
*dwarf2_per_objfile
13642 = cu
->per_cu
->dwarf2_per_objfile
;
13643 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13644 struct comp_unit_head
*cu_header
= &cu
->header
;
13645 bfd
*obfd
= objfile
->obfd
;
13646 unsigned int addr_size
= cu_header
->addr_size
;
13647 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13648 /* Base address selection entry. */
13651 unsigned int dummy
;
13652 const gdb_byte
*buffer
;
13653 CORE_ADDR baseaddr
;
13655 if (cu_header
->version
>= 5)
13656 return dwarf2_rnglists_process (offset
, cu
, callback
);
13658 found_base
= cu
->base_known
;
13659 base
= cu
->base_address
;
13661 dwarf2_per_objfile
->ranges
.read (objfile
);
13662 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13664 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13668 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13670 baseaddr
= objfile
->text_section_offset ();
13674 CORE_ADDR range_beginning
, range_end
;
13676 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13677 buffer
+= addr_size
;
13678 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13679 buffer
+= addr_size
;
13680 offset
+= 2 * addr_size
;
13682 /* An end of list marker is a pair of zero addresses. */
13683 if (range_beginning
== 0 && range_end
== 0)
13684 /* Found the end of list entry. */
13687 /* Each base address selection entry is a pair of 2 values.
13688 The first is the largest possible address, the second is
13689 the base address. Check for a base address here. */
13690 if ((range_beginning
& mask
) == mask
)
13692 /* If we found the largest possible address, then we already
13693 have the base address in range_end. */
13701 /* We have no valid base address for the ranges
13703 complaint (_("Invalid .debug_ranges data (no base address)"));
13707 if (range_beginning
> range_end
)
13709 /* Inverted range entries are invalid. */
13710 complaint (_("Invalid .debug_ranges data (inverted range)"));
13714 /* Empty range entries have no effect. */
13715 if (range_beginning
== range_end
)
13718 range_beginning
+= base
;
13721 /* A not-uncommon case of bad debug info.
13722 Don't pollute the addrmap with bad data. */
13723 if (range_beginning
+ baseaddr
== 0
13724 && !dwarf2_per_objfile
->has_section_at_zero
)
13726 complaint (_(".debug_ranges entry has start address of zero"
13727 " [in module %s]"), objfile_name (objfile
));
13731 callback (range_beginning
, range_end
);
13737 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13738 Return 1 if the attributes are present and valid, otherwise, return 0.
13739 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13742 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13743 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13744 dwarf2_psymtab
*ranges_pst
)
13746 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13747 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13748 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13751 CORE_ADDR high
= 0;
13754 retval
= dwarf2_ranges_process (offset
, cu
,
13755 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13757 if (ranges_pst
!= NULL
)
13762 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13763 range_beginning
+ baseaddr
)
13765 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13766 range_end
+ baseaddr
)
13768 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13769 lowpc
, highpc
- 1, ranges_pst
);
13772 /* FIXME: This is recording everything as a low-high
13773 segment of consecutive addresses. We should have a
13774 data structure for discontiguous block ranges
13778 low
= range_beginning
;
13784 if (range_beginning
< low
)
13785 low
= range_beginning
;
13786 if (range_end
> high
)
13794 /* If the first entry is an end-of-list marker, the range
13795 describes an empty scope, i.e. no instructions. */
13801 *high_return
= high
;
13805 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13806 definition for the return value. *LOWPC and *HIGHPC are set iff
13807 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13809 static enum pc_bounds_kind
13810 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13811 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13812 dwarf2_psymtab
*pst
)
13814 struct dwarf2_per_objfile
*dwarf2_per_objfile
13815 = cu
->per_cu
->dwarf2_per_objfile
;
13816 struct attribute
*attr
;
13817 struct attribute
*attr_high
;
13819 CORE_ADDR high
= 0;
13820 enum pc_bounds_kind ret
;
13822 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13825 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13826 if (attr
!= nullptr)
13828 low
= attr
->value_as_address ();
13829 high
= attr_high
->value_as_address ();
13830 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13834 /* Found high w/o low attribute. */
13835 return PC_BOUNDS_INVALID
;
13837 /* Found consecutive range of addresses. */
13838 ret
= PC_BOUNDS_HIGH_LOW
;
13842 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13845 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13846 We take advantage of the fact that DW_AT_ranges does not appear
13847 in DW_TAG_compile_unit of DWO files. */
13848 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13849 unsigned int ranges_offset
= (DW_UNSND (attr
)
13850 + (need_ranges_base
13854 /* Value of the DW_AT_ranges attribute is the offset in the
13855 .debug_ranges section. */
13856 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13857 return PC_BOUNDS_INVALID
;
13858 /* Found discontinuous range of addresses. */
13859 ret
= PC_BOUNDS_RANGES
;
13862 return PC_BOUNDS_NOT_PRESENT
;
13865 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13867 return PC_BOUNDS_INVALID
;
13869 /* When using the GNU linker, .gnu.linkonce. sections are used to
13870 eliminate duplicate copies of functions and vtables and such.
13871 The linker will arbitrarily choose one and discard the others.
13872 The AT_*_pc values for such functions refer to local labels in
13873 these sections. If the section from that file was discarded, the
13874 labels are not in the output, so the relocs get a value of 0.
13875 If this is a discarded function, mark the pc bounds as invalid,
13876 so that GDB will ignore it. */
13877 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13878 return PC_BOUNDS_INVALID
;
13886 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13887 its low and high PC addresses. Do nothing if these addresses could not
13888 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13889 and HIGHPC to the high address if greater than HIGHPC. */
13892 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13893 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13894 struct dwarf2_cu
*cu
)
13896 CORE_ADDR low
, high
;
13897 struct die_info
*child
= die
->child
;
13899 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13901 *lowpc
= std::min (*lowpc
, low
);
13902 *highpc
= std::max (*highpc
, high
);
13905 /* If the language does not allow nested subprograms (either inside
13906 subprograms or lexical blocks), we're done. */
13907 if (cu
->language
!= language_ada
)
13910 /* Check all the children of the given DIE. If it contains nested
13911 subprograms, then check their pc bounds. Likewise, we need to
13912 check lexical blocks as well, as they may also contain subprogram
13914 while (child
&& child
->tag
)
13916 if (child
->tag
== DW_TAG_subprogram
13917 || child
->tag
== DW_TAG_lexical_block
)
13918 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13919 child
= sibling_die (child
);
13923 /* Get the low and high pc's represented by the scope DIE, and store
13924 them in *LOWPC and *HIGHPC. If the correct values can't be
13925 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13928 get_scope_pc_bounds (struct die_info
*die
,
13929 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13930 struct dwarf2_cu
*cu
)
13932 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13933 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13934 CORE_ADDR current_low
, current_high
;
13936 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13937 >= PC_BOUNDS_RANGES
)
13939 best_low
= current_low
;
13940 best_high
= current_high
;
13944 struct die_info
*child
= die
->child
;
13946 while (child
&& child
->tag
)
13948 switch (child
->tag
) {
13949 case DW_TAG_subprogram
:
13950 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13952 case DW_TAG_namespace
:
13953 case DW_TAG_module
:
13954 /* FIXME: carlton/2004-01-16: Should we do this for
13955 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13956 that current GCC's always emit the DIEs corresponding
13957 to definitions of methods of classes as children of a
13958 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13959 the DIEs giving the declarations, which could be
13960 anywhere). But I don't see any reason why the
13961 standards says that they have to be there. */
13962 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13964 if (current_low
!= ((CORE_ADDR
) -1))
13966 best_low
= std::min (best_low
, current_low
);
13967 best_high
= std::max (best_high
, current_high
);
13975 child
= sibling_die (child
);
13980 *highpc
= best_high
;
13983 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13987 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13988 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13990 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13991 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13992 struct attribute
*attr
;
13993 struct attribute
*attr_high
;
13995 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13998 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13999 if (attr
!= nullptr)
14001 CORE_ADDR low
= attr
->value_as_address ();
14002 CORE_ADDR high
= attr_high
->value_as_address ();
14004 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14007 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14008 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14009 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14013 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14014 if (attr
!= nullptr)
14016 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14017 We take advantage of the fact that DW_AT_ranges does not appear
14018 in DW_TAG_compile_unit of DWO files. */
14019 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14021 /* The value of the DW_AT_ranges attribute is the offset of the
14022 address range list in the .debug_ranges section. */
14023 unsigned long offset
= (DW_UNSND (attr
)
14024 + (need_ranges_base
? cu
->ranges_base
: 0));
14026 std::vector
<blockrange
> blockvec
;
14027 dwarf2_ranges_process (offset
, cu
,
14028 [&] (CORE_ADDR start
, CORE_ADDR end
)
14032 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14033 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14034 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14035 blockvec
.emplace_back (start
, end
);
14038 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14042 /* Check whether the producer field indicates either of GCC < 4.6, or the
14043 Intel C/C++ compiler, and cache the result in CU. */
14046 check_producer (struct dwarf2_cu
*cu
)
14050 if (cu
->producer
== NULL
)
14052 /* For unknown compilers expect their behavior is DWARF version
14055 GCC started to support .debug_types sections by -gdwarf-4 since
14056 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14057 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14058 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14059 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14061 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14063 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14064 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14066 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14068 cu
->producer_is_icc
= true;
14069 cu
->producer_is_icc_lt_14
= major
< 14;
14071 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14072 cu
->producer_is_codewarrior
= true;
14075 /* For other non-GCC compilers, expect their behavior is DWARF version
14079 cu
->checked_producer
= true;
14082 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14083 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14084 during 4.6.0 experimental. */
14087 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14089 if (!cu
->checked_producer
)
14090 check_producer (cu
);
14092 return cu
->producer_is_gxx_lt_4_6
;
14096 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14097 with incorrect is_stmt attributes. */
14100 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14102 if (!cu
->checked_producer
)
14103 check_producer (cu
);
14105 return cu
->producer_is_codewarrior
;
14108 /* Return the default accessibility type if it is not overridden by
14109 DW_AT_accessibility. */
14111 static enum dwarf_access_attribute
14112 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14114 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14116 /* The default DWARF 2 accessibility for members is public, the default
14117 accessibility for inheritance is private. */
14119 if (die
->tag
!= DW_TAG_inheritance
)
14120 return DW_ACCESS_public
;
14122 return DW_ACCESS_private
;
14126 /* DWARF 3+ defines the default accessibility a different way. The same
14127 rules apply now for DW_TAG_inheritance as for the members and it only
14128 depends on the container kind. */
14130 if (die
->parent
->tag
== DW_TAG_class_type
)
14131 return DW_ACCESS_private
;
14133 return DW_ACCESS_public
;
14137 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14138 offset. If the attribute was not found return 0, otherwise return
14139 1. If it was found but could not properly be handled, set *OFFSET
14143 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14146 struct attribute
*attr
;
14148 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14153 /* Note that we do not check for a section offset first here.
14154 This is because DW_AT_data_member_location is new in DWARF 4,
14155 so if we see it, we can assume that a constant form is really
14156 a constant and not a section offset. */
14157 if (attr
->form_is_constant ())
14158 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14159 else if (attr
->form_is_section_offset ())
14160 dwarf2_complex_location_expr_complaint ();
14161 else if (attr
->form_is_block ())
14162 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14164 dwarf2_complex_location_expr_complaint ();
14172 /* Add an aggregate field to the field list. */
14175 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14176 struct dwarf2_cu
*cu
)
14178 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14179 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14180 struct nextfield
*new_field
;
14181 struct attribute
*attr
;
14183 const char *fieldname
= "";
14185 if (die
->tag
== DW_TAG_inheritance
)
14187 fip
->baseclasses
.emplace_back ();
14188 new_field
= &fip
->baseclasses
.back ();
14192 fip
->fields
.emplace_back ();
14193 new_field
= &fip
->fields
.back ();
14196 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14197 if (attr
!= nullptr)
14198 new_field
->accessibility
= DW_UNSND (attr
);
14200 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14201 if (new_field
->accessibility
!= DW_ACCESS_public
)
14202 fip
->non_public_fields
= 1;
14204 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14205 if (attr
!= nullptr)
14206 new_field
->virtuality
= DW_UNSND (attr
);
14208 new_field
->virtuality
= DW_VIRTUALITY_none
;
14210 fp
= &new_field
->field
;
14212 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14216 /* Data member other than a C++ static data member. */
14218 /* Get type of field. */
14219 fp
->type
= die_type (die
, cu
);
14221 SET_FIELD_BITPOS (*fp
, 0);
14223 /* Get bit size of field (zero if none). */
14224 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14225 if (attr
!= nullptr)
14227 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14231 FIELD_BITSIZE (*fp
) = 0;
14234 /* Get bit offset of field. */
14235 if (handle_data_member_location (die
, cu
, &offset
))
14236 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14237 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14238 if (attr
!= nullptr)
14240 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14242 /* For big endian bits, the DW_AT_bit_offset gives the
14243 additional bit offset from the MSB of the containing
14244 anonymous object to the MSB of the field. We don't
14245 have to do anything special since we don't need to
14246 know the size of the anonymous object. */
14247 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14251 /* For little endian bits, compute the bit offset to the
14252 MSB of the anonymous object, subtract off the number of
14253 bits from the MSB of the field to the MSB of the
14254 object, and then subtract off the number of bits of
14255 the field itself. The result is the bit offset of
14256 the LSB of the field. */
14257 int anonymous_size
;
14258 int bit_offset
= DW_UNSND (attr
);
14260 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14261 if (attr
!= nullptr)
14263 /* The size of the anonymous object containing
14264 the bit field is explicit, so use the
14265 indicated size (in bytes). */
14266 anonymous_size
= DW_UNSND (attr
);
14270 /* The size of the anonymous object containing
14271 the bit field must be inferred from the type
14272 attribute of the data member containing the
14274 anonymous_size
= TYPE_LENGTH (fp
->type
);
14276 SET_FIELD_BITPOS (*fp
,
14277 (FIELD_BITPOS (*fp
)
14278 + anonymous_size
* bits_per_byte
14279 - bit_offset
- FIELD_BITSIZE (*fp
)));
14282 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14284 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14285 + dwarf2_get_attr_constant_value (attr
, 0)));
14287 /* Get name of field. */
14288 fieldname
= dwarf2_name (die
, cu
);
14289 if (fieldname
== NULL
)
14292 /* The name is already allocated along with this objfile, so we don't
14293 need to duplicate it for the type. */
14294 fp
->name
= fieldname
;
14296 /* Change accessibility for artificial fields (e.g. virtual table
14297 pointer or virtual base class pointer) to private. */
14298 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14300 FIELD_ARTIFICIAL (*fp
) = 1;
14301 new_field
->accessibility
= DW_ACCESS_private
;
14302 fip
->non_public_fields
= 1;
14305 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14307 /* C++ static member. */
14309 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14310 is a declaration, but all versions of G++ as of this writing
14311 (so through at least 3.2.1) incorrectly generate
14312 DW_TAG_variable tags. */
14314 const char *physname
;
14316 /* Get name of field. */
14317 fieldname
= dwarf2_name (die
, cu
);
14318 if (fieldname
== NULL
)
14321 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14323 /* Only create a symbol if this is an external value.
14324 new_symbol checks this and puts the value in the global symbol
14325 table, which we want. If it is not external, new_symbol
14326 will try to put the value in cu->list_in_scope which is wrong. */
14327 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14329 /* A static const member, not much different than an enum as far as
14330 we're concerned, except that we can support more types. */
14331 new_symbol (die
, NULL
, cu
);
14334 /* Get physical name. */
14335 physname
= dwarf2_physname (fieldname
, die
, cu
);
14337 /* The name is already allocated along with this objfile, so we don't
14338 need to duplicate it for the type. */
14339 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14340 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14341 FIELD_NAME (*fp
) = fieldname
;
14343 else if (die
->tag
== DW_TAG_inheritance
)
14347 /* C++ base class field. */
14348 if (handle_data_member_location (die
, cu
, &offset
))
14349 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14350 FIELD_BITSIZE (*fp
) = 0;
14351 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14352 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14354 else if (die
->tag
== DW_TAG_variant_part
)
14356 /* process_structure_scope will treat this DIE as a union. */
14357 process_structure_scope (die
, cu
);
14359 /* The variant part is relative to the start of the enclosing
14361 SET_FIELD_BITPOS (*fp
, 0);
14362 fp
->type
= get_die_type (die
, cu
);
14363 fp
->artificial
= 1;
14364 fp
->name
= "<<variant>>";
14366 /* Normally a DW_TAG_variant_part won't have a size, but our
14367 representation requires one, so set it to the maximum of the
14368 child sizes, being sure to account for the offset at which
14369 each child is seen. */
14370 if (TYPE_LENGTH (fp
->type
) == 0)
14373 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14375 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14376 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14380 TYPE_LENGTH (fp
->type
) = max
;
14384 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14387 /* Can the type given by DIE define another type? */
14390 type_can_define_types (const struct die_info
*die
)
14394 case DW_TAG_typedef
:
14395 case DW_TAG_class_type
:
14396 case DW_TAG_structure_type
:
14397 case DW_TAG_union_type
:
14398 case DW_TAG_enumeration_type
:
14406 /* Add a type definition defined in the scope of the FIP's class. */
14409 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14410 struct dwarf2_cu
*cu
)
14412 struct decl_field fp
;
14413 memset (&fp
, 0, sizeof (fp
));
14415 gdb_assert (type_can_define_types (die
));
14417 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14418 fp
.name
= dwarf2_name (die
, cu
);
14419 fp
.type
= read_type_die (die
, cu
);
14421 /* Save accessibility. */
14422 enum dwarf_access_attribute accessibility
;
14423 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14425 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14427 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14428 switch (accessibility
)
14430 case DW_ACCESS_public
:
14431 /* The assumed value if neither private nor protected. */
14433 case DW_ACCESS_private
:
14436 case DW_ACCESS_protected
:
14437 fp
.is_protected
= 1;
14440 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14443 if (die
->tag
== DW_TAG_typedef
)
14444 fip
->typedef_field_list
.push_back (fp
);
14446 fip
->nested_types_list
.push_back (fp
);
14449 /* Create the vector of fields, and attach it to the type. */
14452 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14453 struct dwarf2_cu
*cu
)
14455 int nfields
= fip
->nfields ();
14457 /* Record the field count, allocate space for the array of fields,
14458 and create blank accessibility bitfields if necessary. */
14459 TYPE_NFIELDS (type
) = nfields
;
14460 TYPE_FIELDS (type
) = (struct field
*)
14461 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14463 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14465 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14467 TYPE_FIELD_PRIVATE_BITS (type
) =
14468 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14469 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14471 TYPE_FIELD_PROTECTED_BITS (type
) =
14472 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14473 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14475 TYPE_FIELD_IGNORE_BITS (type
) =
14476 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14477 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14480 /* If the type has baseclasses, allocate and clear a bit vector for
14481 TYPE_FIELD_VIRTUAL_BITS. */
14482 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14484 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14485 unsigned char *pointer
;
14487 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14488 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14489 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14490 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14491 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14494 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14496 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14498 for (int index
= 0; index
< nfields
; ++index
)
14500 struct nextfield
&field
= fip
->fields
[index
];
14502 if (field
.variant
.is_discriminant
)
14503 di
->discriminant_index
= index
;
14504 else if (field
.variant
.default_branch
)
14505 di
->default_index
= index
;
14507 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14511 /* Copy the saved-up fields into the field vector. */
14512 for (int i
= 0; i
< nfields
; ++i
)
14514 struct nextfield
&field
14515 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14516 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14518 TYPE_FIELD (type
, i
) = field
.field
;
14519 switch (field
.accessibility
)
14521 case DW_ACCESS_private
:
14522 if (cu
->language
!= language_ada
)
14523 SET_TYPE_FIELD_PRIVATE (type
, i
);
14526 case DW_ACCESS_protected
:
14527 if (cu
->language
!= language_ada
)
14528 SET_TYPE_FIELD_PROTECTED (type
, i
);
14531 case DW_ACCESS_public
:
14535 /* Unknown accessibility. Complain and treat it as public. */
14537 complaint (_("unsupported accessibility %d"),
14538 field
.accessibility
);
14542 if (i
< fip
->baseclasses
.size ())
14544 switch (field
.virtuality
)
14546 case DW_VIRTUALITY_virtual
:
14547 case DW_VIRTUALITY_pure_virtual
:
14548 if (cu
->language
== language_ada
)
14549 error (_("unexpected virtuality in component of Ada type"));
14550 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14557 /* Return true if this member function is a constructor, false
14561 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14563 const char *fieldname
;
14564 const char *type_name
;
14567 if (die
->parent
== NULL
)
14570 if (die
->parent
->tag
!= DW_TAG_structure_type
14571 && die
->parent
->tag
!= DW_TAG_union_type
14572 && die
->parent
->tag
!= DW_TAG_class_type
)
14575 fieldname
= dwarf2_name (die
, cu
);
14576 type_name
= dwarf2_name (die
->parent
, cu
);
14577 if (fieldname
== NULL
|| type_name
== NULL
)
14580 len
= strlen (fieldname
);
14581 return (strncmp (fieldname
, type_name
, len
) == 0
14582 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14585 /* Check if the given VALUE is a recognized enum
14586 dwarf_defaulted_attribute constant according to DWARF5 spec,
14590 is_valid_DW_AT_defaulted (ULONGEST value
)
14594 case DW_DEFAULTED_no
:
14595 case DW_DEFAULTED_in_class
:
14596 case DW_DEFAULTED_out_of_class
:
14600 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14604 /* Add a member function to the proper fieldlist. */
14607 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14608 struct type
*type
, struct dwarf2_cu
*cu
)
14610 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14611 struct attribute
*attr
;
14613 struct fnfieldlist
*flp
= nullptr;
14614 struct fn_field
*fnp
;
14615 const char *fieldname
;
14616 struct type
*this_type
;
14617 enum dwarf_access_attribute accessibility
;
14619 if (cu
->language
== language_ada
)
14620 error (_("unexpected member function in Ada type"));
14622 /* Get name of member function. */
14623 fieldname
= dwarf2_name (die
, cu
);
14624 if (fieldname
== NULL
)
14627 /* Look up member function name in fieldlist. */
14628 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14630 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14632 flp
= &fip
->fnfieldlists
[i
];
14637 /* Create a new fnfieldlist if necessary. */
14638 if (flp
== nullptr)
14640 fip
->fnfieldlists
.emplace_back ();
14641 flp
= &fip
->fnfieldlists
.back ();
14642 flp
->name
= fieldname
;
14643 i
= fip
->fnfieldlists
.size () - 1;
14646 /* Create a new member function field and add it to the vector of
14648 flp
->fnfields
.emplace_back ();
14649 fnp
= &flp
->fnfields
.back ();
14651 /* Delay processing of the physname until later. */
14652 if (cu
->language
== language_cplus
)
14653 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14657 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14658 fnp
->physname
= physname
? physname
: "";
14661 fnp
->type
= alloc_type (objfile
);
14662 this_type
= read_type_die (die
, cu
);
14663 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14665 int nparams
= TYPE_NFIELDS (this_type
);
14667 /* TYPE is the domain of this method, and THIS_TYPE is the type
14668 of the method itself (TYPE_CODE_METHOD). */
14669 smash_to_method_type (fnp
->type
, type
,
14670 TYPE_TARGET_TYPE (this_type
),
14671 TYPE_FIELDS (this_type
),
14672 TYPE_NFIELDS (this_type
),
14673 TYPE_VARARGS (this_type
));
14675 /* Handle static member functions.
14676 Dwarf2 has no clean way to discern C++ static and non-static
14677 member functions. G++ helps GDB by marking the first
14678 parameter for non-static member functions (which is the this
14679 pointer) as artificial. We obtain this information from
14680 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14681 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14682 fnp
->voffset
= VOFFSET_STATIC
;
14685 complaint (_("member function type missing for '%s'"),
14686 dwarf2_full_name (fieldname
, die
, cu
));
14688 /* Get fcontext from DW_AT_containing_type if present. */
14689 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14690 fnp
->fcontext
= die_containing_type (die
, cu
);
14692 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14693 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14695 /* Get accessibility. */
14696 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14697 if (attr
!= nullptr)
14698 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14700 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14701 switch (accessibility
)
14703 case DW_ACCESS_private
:
14704 fnp
->is_private
= 1;
14706 case DW_ACCESS_protected
:
14707 fnp
->is_protected
= 1;
14711 /* Check for artificial methods. */
14712 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14713 if (attr
&& DW_UNSND (attr
) != 0)
14714 fnp
->is_artificial
= 1;
14716 /* Check for defaulted methods. */
14717 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14718 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14719 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14721 /* Check for deleted methods. */
14722 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14723 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14724 fnp
->is_deleted
= 1;
14726 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14728 /* Get index in virtual function table if it is a virtual member
14729 function. For older versions of GCC, this is an offset in the
14730 appropriate virtual table, as specified by DW_AT_containing_type.
14731 For everyone else, it is an expression to be evaluated relative
14732 to the object address. */
14734 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14735 if (attr
!= nullptr)
14737 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14739 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14741 /* Old-style GCC. */
14742 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14744 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14745 || (DW_BLOCK (attr
)->size
> 1
14746 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14747 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14749 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14750 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14751 dwarf2_complex_location_expr_complaint ();
14753 fnp
->voffset
/= cu
->header
.addr_size
;
14757 dwarf2_complex_location_expr_complaint ();
14759 if (!fnp
->fcontext
)
14761 /* If there is no `this' field and no DW_AT_containing_type,
14762 we cannot actually find a base class context for the
14764 if (TYPE_NFIELDS (this_type
) == 0
14765 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14767 complaint (_("cannot determine context for virtual member "
14768 "function \"%s\" (offset %s)"),
14769 fieldname
, sect_offset_str (die
->sect_off
));
14774 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14778 else if (attr
->form_is_section_offset ())
14780 dwarf2_complex_location_expr_complaint ();
14784 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14790 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14791 if (attr
&& DW_UNSND (attr
))
14793 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14794 complaint (_("Member function \"%s\" (offset %s) is virtual "
14795 "but the vtable offset is not specified"),
14796 fieldname
, sect_offset_str (die
->sect_off
));
14797 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14798 TYPE_CPLUS_DYNAMIC (type
) = 1;
14803 /* Create the vector of member function fields, and attach it to the type. */
14806 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14807 struct dwarf2_cu
*cu
)
14809 if (cu
->language
== language_ada
)
14810 error (_("unexpected member functions in Ada type"));
14812 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14813 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14815 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14817 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14819 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14820 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14822 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14823 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14824 fn_flp
->fn_fields
= (struct fn_field
*)
14825 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14827 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14828 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14831 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14834 /* Returns non-zero if NAME is the name of a vtable member in CU's
14835 language, zero otherwise. */
14837 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14839 static const char vptr
[] = "_vptr";
14841 /* Look for the C++ form of the vtable. */
14842 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14848 /* GCC outputs unnamed structures that are really pointers to member
14849 functions, with the ABI-specified layout. If TYPE describes
14850 such a structure, smash it into a member function type.
14852 GCC shouldn't do this; it should just output pointer to member DIEs.
14853 This is GCC PR debug/28767. */
14856 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14858 struct type
*pfn_type
, *self_type
, *new_type
;
14860 /* Check for a structure with no name and two children. */
14861 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14864 /* Check for __pfn and __delta members. */
14865 if (TYPE_FIELD_NAME (type
, 0) == NULL
14866 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14867 || TYPE_FIELD_NAME (type
, 1) == NULL
14868 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14871 /* Find the type of the method. */
14872 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14873 if (pfn_type
== NULL
14874 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14875 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14878 /* Look for the "this" argument. */
14879 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14880 if (TYPE_NFIELDS (pfn_type
) == 0
14881 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14882 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14885 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14886 new_type
= alloc_type (objfile
);
14887 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14888 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14889 TYPE_VARARGS (pfn_type
));
14890 smash_to_methodptr_type (type
, new_type
);
14893 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14894 appropriate error checking and issuing complaints if there is a
14898 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14900 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14902 if (attr
== nullptr)
14905 if (!attr
->form_is_constant ())
14907 complaint (_("DW_AT_alignment must have constant form"
14908 " - DIE at %s [in module %s]"),
14909 sect_offset_str (die
->sect_off
),
14910 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14915 if (attr
->form
== DW_FORM_sdata
)
14917 LONGEST val
= DW_SND (attr
);
14920 complaint (_("DW_AT_alignment value must not be negative"
14921 " - DIE at %s [in module %s]"),
14922 sect_offset_str (die
->sect_off
),
14923 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14929 align
= DW_UNSND (attr
);
14933 complaint (_("DW_AT_alignment value must not be zero"
14934 " - DIE at %s [in module %s]"),
14935 sect_offset_str (die
->sect_off
),
14936 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14939 if ((align
& (align
- 1)) != 0)
14941 complaint (_("DW_AT_alignment value must be a power of 2"
14942 " - DIE at %s [in module %s]"),
14943 sect_offset_str (die
->sect_off
),
14944 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14951 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14952 the alignment for TYPE. */
14955 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14958 if (!set_type_align (type
, get_alignment (cu
, die
)))
14959 complaint (_("DW_AT_alignment value too large"
14960 " - DIE at %s [in module %s]"),
14961 sect_offset_str (die
->sect_off
),
14962 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14965 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14966 constant for a type, according to DWARF5 spec, Table 5.5. */
14969 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14974 case DW_CC_pass_by_reference
:
14975 case DW_CC_pass_by_value
:
14979 complaint (_("unrecognized DW_AT_calling_convention value "
14980 "(%s) for a type"), pulongest (value
));
14985 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14986 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14987 also according to GNU-specific values (see include/dwarf2.h). */
14990 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14995 case DW_CC_program
:
14999 case DW_CC_GNU_renesas_sh
:
15000 case DW_CC_GNU_borland_fastcall_i386
:
15001 case DW_CC_GDB_IBM_OpenCL
:
15005 complaint (_("unrecognized DW_AT_calling_convention value "
15006 "(%s) for a subroutine"), pulongest (value
));
15011 /* Called when we find the DIE that starts a structure or union scope
15012 (definition) to create a type for the structure or union. Fill in
15013 the type's name and general properties; the members will not be
15014 processed until process_structure_scope. A symbol table entry for
15015 the type will also not be done until process_structure_scope (assuming
15016 the type has a name).
15018 NOTE: we need to call these functions regardless of whether or not the
15019 DIE has a DW_AT_name attribute, since it might be an anonymous
15020 structure or union. This gets the type entered into our set of
15021 user defined types. */
15023 static struct type
*
15024 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15026 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15028 struct attribute
*attr
;
15031 /* If the definition of this type lives in .debug_types, read that type.
15032 Don't follow DW_AT_specification though, that will take us back up
15033 the chain and we want to go down. */
15034 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15035 if (attr
!= nullptr)
15037 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15039 /* The type's CU may not be the same as CU.
15040 Ensure TYPE is recorded with CU in die_type_hash. */
15041 return set_die_type (die
, type
, cu
);
15044 type
= alloc_type (objfile
);
15045 INIT_CPLUS_SPECIFIC (type
);
15047 name
= dwarf2_name (die
, cu
);
15050 if (cu
->language
== language_cplus
15051 || cu
->language
== language_d
15052 || cu
->language
== language_rust
)
15054 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15056 /* dwarf2_full_name might have already finished building the DIE's
15057 type. If so, there is no need to continue. */
15058 if (get_die_type (die
, cu
) != NULL
)
15059 return get_die_type (die
, cu
);
15061 TYPE_NAME (type
) = full_name
;
15065 /* The name is already allocated along with this objfile, so
15066 we don't need to duplicate it for the type. */
15067 TYPE_NAME (type
) = name
;
15071 if (die
->tag
== DW_TAG_structure_type
)
15073 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15075 else if (die
->tag
== DW_TAG_union_type
)
15077 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15079 else if (die
->tag
== DW_TAG_variant_part
)
15081 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15082 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15086 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15089 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15090 TYPE_DECLARED_CLASS (type
) = 1;
15092 /* Store the calling convention in the type if it's available in
15093 the die. Otherwise the calling convention remains set to
15094 the default value DW_CC_normal. */
15095 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15096 if (attr
!= nullptr
15097 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15099 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15100 TYPE_CPLUS_CALLING_CONVENTION (type
)
15101 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15104 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15105 if (attr
!= nullptr)
15107 if (attr
->form_is_constant ())
15108 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15111 /* For the moment, dynamic type sizes are not supported
15112 by GDB's struct type. The actual size is determined
15113 on-demand when resolving the type of a given object,
15114 so set the type's length to zero for now. Otherwise,
15115 we record an expression as the length, and that expression
15116 could lead to a very large value, which could eventually
15117 lead to us trying to allocate that much memory when creating
15118 a value of that type. */
15119 TYPE_LENGTH (type
) = 0;
15124 TYPE_LENGTH (type
) = 0;
15127 maybe_set_alignment (cu
, die
, type
);
15129 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15131 /* ICC<14 does not output the required DW_AT_declaration on
15132 incomplete types, but gives them a size of zero. */
15133 TYPE_STUB (type
) = 1;
15136 TYPE_STUB_SUPPORTED (type
) = 1;
15138 if (die_is_declaration (die
, cu
))
15139 TYPE_STUB (type
) = 1;
15140 else if (attr
== NULL
&& die
->child
== NULL
15141 && producer_is_realview (cu
->producer
))
15142 /* RealView does not output the required DW_AT_declaration
15143 on incomplete types. */
15144 TYPE_STUB (type
) = 1;
15146 /* We need to add the type field to the die immediately so we don't
15147 infinitely recurse when dealing with pointers to the structure
15148 type within the structure itself. */
15149 set_die_type (die
, type
, cu
);
15151 /* set_die_type should be already done. */
15152 set_descriptive_type (type
, die
, cu
);
15157 /* A helper for process_structure_scope that handles a single member
15161 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15162 struct field_info
*fi
,
15163 std::vector
<struct symbol
*> *template_args
,
15164 struct dwarf2_cu
*cu
)
15166 if (child_die
->tag
== DW_TAG_member
15167 || child_die
->tag
== DW_TAG_variable
15168 || child_die
->tag
== DW_TAG_variant_part
)
15170 /* NOTE: carlton/2002-11-05: A C++ static data member
15171 should be a DW_TAG_member that is a declaration, but
15172 all versions of G++ as of this writing (so through at
15173 least 3.2.1) incorrectly generate DW_TAG_variable
15174 tags for them instead. */
15175 dwarf2_add_field (fi
, child_die
, cu
);
15177 else if (child_die
->tag
== DW_TAG_subprogram
)
15179 /* Rust doesn't have member functions in the C++ sense.
15180 However, it does emit ordinary functions as children
15181 of a struct DIE. */
15182 if (cu
->language
== language_rust
)
15183 read_func_scope (child_die
, cu
);
15186 /* C++ member function. */
15187 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15190 else if (child_die
->tag
== DW_TAG_inheritance
)
15192 /* C++ base class field. */
15193 dwarf2_add_field (fi
, child_die
, cu
);
15195 else if (type_can_define_types (child_die
))
15196 dwarf2_add_type_defn (fi
, child_die
, cu
);
15197 else if (child_die
->tag
== DW_TAG_template_type_param
15198 || child_die
->tag
== DW_TAG_template_value_param
)
15200 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15203 template_args
->push_back (arg
);
15205 else if (child_die
->tag
== DW_TAG_variant
)
15207 /* In a variant we want to get the discriminant and also add a
15208 field for our sole member child. */
15209 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15211 for (die_info
*variant_child
= child_die
->child
;
15212 variant_child
!= NULL
;
15213 variant_child
= sibling_die (variant_child
))
15215 if (variant_child
->tag
== DW_TAG_member
)
15217 handle_struct_member_die (variant_child
, type
, fi
,
15218 template_args
, cu
);
15219 /* Only handle the one. */
15224 /* We don't handle this but we might as well report it if we see
15226 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15227 complaint (_("DW_AT_discr_list is not supported yet"
15228 " - DIE at %s [in module %s]"),
15229 sect_offset_str (child_die
->sect_off
),
15230 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15232 /* The first field was just added, so we can stash the
15233 discriminant there. */
15234 gdb_assert (!fi
->fields
.empty ());
15236 fi
->fields
.back ().variant
.default_branch
= true;
15238 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15242 /* Finish creating a structure or union type, including filling in
15243 its members and creating a symbol for it. */
15246 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15248 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15249 struct die_info
*child_die
;
15252 type
= get_die_type (die
, cu
);
15254 type
= read_structure_type (die
, cu
);
15256 /* When reading a DW_TAG_variant_part, we need to notice when we
15257 read the discriminant member, so we can record it later in the
15258 discriminant_info. */
15259 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15260 sect_offset discr_offset
{};
15261 bool has_template_parameters
= false;
15263 if (is_variant_part
)
15265 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15268 /* Maybe it's a univariant form, an extension we support.
15269 In this case arrange not to check the offset. */
15270 is_variant_part
= false;
15272 else if (discr
->form_is_ref ())
15274 struct dwarf2_cu
*target_cu
= cu
;
15275 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15277 discr_offset
= target_die
->sect_off
;
15281 complaint (_("DW_AT_discr does not have DIE reference form"
15282 " - DIE at %s [in module %s]"),
15283 sect_offset_str (die
->sect_off
),
15284 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15285 is_variant_part
= false;
15289 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15291 struct field_info fi
;
15292 std::vector
<struct symbol
*> template_args
;
15294 child_die
= die
->child
;
15296 while (child_die
&& child_die
->tag
)
15298 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15300 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15301 fi
.fields
.back ().variant
.is_discriminant
= true;
15303 child_die
= sibling_die (child_die
);
15306 /* Attach template arguments to type. */
15307 if (!template_args
.empty ())
15309 has_template_parameters
= true;
15310 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15311 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15312 TYPE_TEMPLATE_ARGUMENTS (type
)
15313 = XOBNEWVEC (&objfile
->objfile_obstack
,
15315 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15316 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15317 template_args
.data (),
15318 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15319 * sizeof (struct symbol
*)));
15322 /* Attach fields and member functions to the type. */
15323 if (fi
.nfields () > 0)
15324 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15325 if (!fi
.fnfieldlists
.empty ())
15327 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15329 /* Get the type which refers to the base class (possibly this
15330 class itself) which contains the vtable pointer for the current
15331 class from the DW_AT_containing_type attribute. This use of
15332 DW_AT_containing_type is a GNU extension. */
15334 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15336 struct type
*t
= die_containing_type (die
, cu
);
15338 set_type_vptr_basetype (type
, t
);
15343 /* Our own class provides vtbl ptr. */
15344 for (i
= TYPE_NFIELDS (t
) - 1;
15345 i
>= TYPE_N_BASECLASSES (t
);
15348 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15350 if (is_vtable_name (fieldname
, cu
))
15352 set_type_vptr_fieldno (type
, i
);
15357 /* Complain if virtual function table field not found. */
15358 if (i
< TYPE_N_BASECLASSES (t
))
15359 complaint (_("virtual function table pointer "
15360 "not found when defining class '%s'"),
15361 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15365 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15368 else if (cu
->producer
15369 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15371 /* The IBM XLC compiler does not provide direct indication
15372 of the containing type, but the vtable pointer is
15373 always named __vfp. */
15377 for (i
= TYPE_NFIELDS (type
) - 1;
15378 i
>= TYPE_N_BASECLASSES (type
);
15381 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15383 set_type_vptr_fieldno (type
, i
);
15384 set_type_vptr_basetype (type
, type
);
15391 /* Copy fi.typedef_field_list linked list elements content into the
15392 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15393 if (!fi
.typedef_field_list
.empty ())
15395 int count
= fi
.typedef_field_list
.size ();
15397 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15398 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15399 = ((struct decl_field
*)
15401 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15402 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15404 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15405 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15408 /* Copy fi.nested_types_list linked list elements content into the
15409 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15410 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15412 int count
= fi
.nested_types_list
.size ();
15414 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15415 TYPE_NESTED_TYPES_ARRAY (type
)
15416 = ((struct decl_field
*)
15417 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15418 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15420 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15421 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15425 quirk_gcc_member_function_pointer (type
, objfile
);
15426 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15427 cu
->rust_unions
.push_back (type
);
15429 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15430 snapshots) has been known to create a die giving a declaration
15431 for a class that has, as a child, a die giving a definition for a
15432 nested class. So we have to process our children even if the
15433 current die is a declaration. Normally, of course, a declaration
15434 won't have any children at all. */
15436 child_die
= die
->child
;
15438 while (child_die
!= NULL
&& child_die
->tag
)
15440 if (child_die
->tag
== DW_TAG_member
15441 || child_die
->tag
== DW_TAG_variable
15442 || child_die
->tag
== DW_TAG_inheritance
15443 || child_die
->tag
== DW_TAG_template_value_param
15444 || child_die
->tag
== DW_TAG_template_type_param
)
15449 process_die (child_die
, cu
);
15451 child_die
= sibling_die (child_die
);
15454 /* Do not consider external references. According to the DWARF standard,
15455 these DIEs are identified by the fact that they have no byte_size
15456 attribute, and a declaration attribute. */
15457 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15458 || !die_is_declaration (die
, cu
))
15460 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15462 if (has_template_parameters
)
15464 struct symtab
*symtab
;
15465 if (sym
!= nullptr)
15466 symtab
= symbol_symtab (sym
);
15467 else if (cu
->line_header
!= nullptr)
15469 /* Any related symtab will do. */
15471 = cu
->line_header
->file_names ()[0].symtab
;
15476 complaint (_("could not find suitable "
15477 "symtab for template parameter"
15478 " - DIE at %s [in module %s]"),
15479 sect_offset_str (die
->sect_off
),
15480 objfile_name (objfile
));
15483 if (symtab
!= nullptr)
15485 /* Make sure that the symtab is set on the new symbols.
15486 Even though they don't appear in this symtab directly,
15487 other parts of gdb assume that symbols do, and this is
15488 reasonably true. */
15489 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15490 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15496 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15497 update TYPE using some information only available in DIE's children. */
15500 update_enumeration_type_from_children (struct die_info
*die
,
15502 struct dwarf2_cu
*cu
)
15504 struct die_info
*child_die
;
15505 int unsigned_enum
= 1;
15508 auto_obstack obstack
;
15510 for (child_die
= die
->child
;
15511 child_die
!= NULL
&& child_die
->tag
;
15512 child_die
= sibling_die (child_die
))
15514 struct attribute
*attr
;
15516 const gdb_byte
*bytes
;
15517 struct dwarf2_locexpr_baton
*baton
;
15520 if (child_die
->tag
!= DW_TAG_enumerator
)
15523 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15527 name
= dwarf2_name (child_die
, cu
);
15529 name
= "<anonymous enumerator>";
15531 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15532 &value
, &bytes
, &baton
);
15540 if (count_one_bits_ll (value
) >= 2)
15544 /* If we already know that the enum type is neither unsigned, nor
15545 a flag type, no need to look at the rest of the enumerates. */
15546 if (!unsigned_enum
&& !flag_enum
)
15551 TYPE_UNSIGNED (type
) = 1;
15553 TYPE_FLAG_ENUM (type
) = 1;
15556 /* Given a DW_AT_enumeration_type die, set its type. We do not
15557 complete the type's fields yet, or create any symbols. */
15559 static struct type
*
15560 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15562 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15564 struct attribute
*attr
;
15567 /* If the definition of this type lives in .debug_types, read that type.
15568 Don't follow DW_AT_specification though, that will take us back up
15569 the chain and we want to go down. */
15570 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15571 if (attr
!= nullptr)
15573 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15575 /* The type's CU may not be the same as CU.
15576 Ensure TYPE is recorded with CU in die_type_hash. */
15577 return set_die_type (die
, type
, cu
);
15580 type
= alloc_type (objfile
);
15582 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15583 name
= dwarf2_full_name (NULL
, die
, cu
);
15585 TYPE_NAME (type
) = name
;
15587 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15590 struct type
*underlying_type
= die_type (die
, cu
);
15592 TYPE_TARGET_TYPE (type
) = underlying_type
;
15595 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15596 if (attr
!= nullptr)
15598 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15602 TYPE_LENGTH (type
) = 0;
15605 maybe_set_alignment (cu
, die
, type
);
15607 /* The enumeration DIE can be incomplete. In Ada, any type can be
15608 declared as private in the package spec, and then defined only
15609 inside the package body. Such types are known as Taft Amendment
15610 Types. When another package uses such a type, an incomplete DIE
15611 may be generated by the compiler. */
15612 if (die_is_declaration (die
, cu
))
15613 TYPE_STUB (type
) = 1;
15615 /* Finish the creation of this type by using the enum's children.
15616 We must call this even when the underlying type has been provided
15617 so that we can determine if we're looking at a "flag" enum. */
15618 update_enumeration_type_from_children (die
, type
, cu
);
15620 /* If this type has an underlying type that is not a stub, then we
15621 may use its attributes. We always use the "unsigned" attribute
15622 in this situation, because ordinarily we guess whether the type
15623 is unsigned -- but the guess can be wrong and the underlying type
15624 can tell us the reality. However, we defer to a local size
15625 attribute if one exists, because this lets the compiler override
15626 the underlying type if needed. */
15627 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15629 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15630 if (TYPE_LENGTH (type
) == 0)
15631 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15632 if (TYPE_RAW_ALIGN (type
) == 0
15633 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15634 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15637 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15639 return set_die_type (die
, type
, cu
);
15642 /* Given a pointer to a die which begins an enumeration, process all
15643 the dies that define the members of the enumeration, and create the
15644 symbol for the enumeration type.
15646 NOTE: We reverse the order of the element list. */
15649 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15651 struct type
*this_type
;
15653 this_type
= get_die_type (die
, cu
);
15654 if (this_type
== NULL
)
15655 this_type
= read_enumeration_type (die
, cu
);
15657 if (die
->child
!= NULL
)
15659 struct die_info
*child_die
;
15660 struct symbol
*sym
;
15661 std::vector
<struct field
> fields
;
15664 child_die
= die
->child
;
15665 while (child_die
&& child_die
->tag
)
15667 if (child_die
->tag
!= DW_TAG_enumerator
)
15669 process_die (child_die
, cu
);
15673 name
= dwarf2_name (child_die
, cu
);
15676 sym
= new_symbol (child_die
, this_type
, cu
);
15678 fields
.emplace_back ();
15679 struct field
&field
= fields
.back ();
15681 FIELD_NAME (field
) = sym
->linkage_name ();
15682 FIELD_TYPE (field
) = NULL
;
15683 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15684 FIELD_BITSIZE (field
) = 0;
15688 child_die
= sibling_die (child_die
);
15691 if (!fields
.empty ())
15693 TYPE_NFIELDS (this_type
) = fields
.size ();
15694 TYPE_FIELDS (this_type
) = (struct field
*)
15695 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15696 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15697 sizeof (struct field
) * fields
.size ());
15701 /* If we are reading an enum from a .debug_types unit, and the enum
15702 is a declaration, and the enum is not the signatured type in the
15703 unit, then we do not want to add a symbol for it. Adding a
15704 symbol would in some cases obscure the true definition of the
15705 enum, giving users an incomplete type when the definition is
15706 actually available. Note that we do not want to do this for all
15707 enums which are just declarations, because C++0x allows forward
15708 enum declarations. */
15709 if (cu
->per_cu
->is_debug_types
15710 && die_is_declaration (die
, cu
))
15712 struct signatured_type
*sig_type
;
15714 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15715 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15716 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15720 new_symbol (die
, this_type
, cu
);
15723 /* Extract all information from a DW_TAG_array_type DIE and put it in
15724 the DIE's type field. For now, this only handles one dimensional
15727 static struct type
*
15728 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15730 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15731 struct die_info
*child_die
;
15733 struct type
*element_type
, *range_type
, *index_type
;
15734 struct attribute
*attr
;
15736 struct dynamic_prop
*byte_stride_prop
= NULL
;
15737 unsigned int bit_stride
= 0;
15739 element_type
= die_type (die
, cu
);
15741 /* The die_type call above may have already set the type for this DIE. */
15742 type
= get_die_type (die
, cu
);
15746 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15750 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15753 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15754 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15758 complaint (_("unable to read array DW_AT_byte_stride "
15759 " - DIE at %s [in module %s]"),
15760 sect_offset_str (die
->sect_off
),
15761 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15762 /* Ignore this attribute. We will likely not be able to print
15763 arrays of this type correctly, but there is little we can do
15764 to help if we cannot read the attribute's value. */
15765 byte_stride_prop
= NULL
;
15769 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15771 bit_stride
= DW_UNSND (attr
);
15773 /* Irix 6.2 native cc creates array types without children for
15774 arrays with unspecified length. */
15775 if (die
->child
== NULL
)
15777 index_type
= objfile_type (objfile
)->builtin_int
;
15778 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15779 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15780 byte_stride_prop
, bit_stride
);
15781 return set_die_type (die
, type
, cu
);
15784 std::vector
<struct type
*> range_types
;
15785 child_die
= die
->child
;
15786 while (child_die
&& child_die
->tag
)
15788 if (child_die
->tag
== DW_TAG_subrange_type
)
15790 struct type
*child_type
= read_type_die (child_die
, cu
);
15792 if (child_type
!= NULL
)
15794 /* The range type was succesfully read. Save it for the
15795 array type creation. */
15796 range_types
.push_back (child_type
);
15799 child_die
= sibling_die (child_die
);
15802 /* Dwarf2 dimensions are output from left to right, create the
15803 necessary array types in backwards order. */
15805 type
= element_type
;
15807 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15811 while (i
< range_types
.size ())
15812 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15813 byte_stride_prop
, bit_stride
);
15817 size_t ndim
= range_types
.size ();
15819 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15820 byte_stride_prop
, bit_stride
);
15823 /* Understand Dwarf2 support for vector types (like they occur on
15824 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15825 array type. This is not part of the Dwarf2/3 standard yet, but a
15826 custom vendor extension. The main difference between a regular
15827 array and the vector variant is that vectors are passed by value
15829 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15830 if (attr
!= nullptr)
15831 make_vector_type (type
);
15833 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15834 implementation may choose to implement triple vectors using this
15836 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15837 if (attr
!= nullptr)
15839 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15840 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15842 complaint (_("DW_AT_byte_size for array type smaller "
15843 "than the total size of elements"));
15846 name
= dwarf2_name (die
, cu
);
15848 TYPE_NAME (type
) = name
;
15850 maybe_set_alignment (cu
, die
, type
);
15852 /* Install the type in the die. */
15853 set_die_type (die
, type
, cu
);
15855 /* set_die_type should be already done. */
15856 set_descriptive_type (type
, die
, cu
);
15861 static enum dwarf_array_dim_ordering
15862 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15864 struct attribute
*attr
;
15866 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15868 if (attr
!= nullptr)
15869 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15871 /* GNU F77 is a special case, as at 08/2004 array type info is the
15872 opposite order to the dwarf2 specification, but data is still
15873 laid out as per normal fortran.
15875 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15876 version checking. */
15878 if (cu
->language
== language_fortran
15879 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15881 return DW_ORD_row_major
;
15884 switch (cu
->language_defn
->la_array_ordering
)
15886 case array_column_major
:
15887 return DW_ORD_col_major
;
15888 case array_row_major
:
15890 return DW_ORD_row_major
;
15894 /* Extract all information from a DW_TAG_set_type DIE and put it in
15895 the DIE's type field. */
15897 static struct type
*
15898 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15900 struct type
*domain_type
, *set_type
;
15901 struct attribute
*attr
;
15903 domain_type
= die_type (die
, cu
);
15905 /* The die_type call above may have already set the type for this DIE. */
15906 set_type
= get_die_type (die
, cu
);
15910 set_type
= create_set_type (NULL
, domain_type
);
15912 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15913 if (attr
!= nullptr)
15914 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15916 maybe_set_alignment (cu
, die
, set_type
);
15918 return set_die_type (die
, set_type
, cu
);
15921 /* A helper for read_common_block that creates a locexpr baton.
15922 SYM is the symbol which we are marking as computed.
15923 COMMON_DIE is the DIE for the common block.
15924 COMMON_LOC is the location expression attribute for the common
15926 MEMBER_LOC is the location expression attribute for the particular
15927 member of the common block that we are processing.
15928 CU is the CU from which the above come. */
15931 mark_common_block_symbol_computed (struct symbol
*sym
,
15932 struct die_info
*common_die
,
15933 struct attribute
*common_loc
,
15934 struct attribute
*member_loc
,
15935 struct dwarf2_cu
*cu
)
15937 struct dwarf2_per_objfile
*dwarf2_per_objfile
15938 = cu
->per_cu
->dwarf2_per_objfile
;
15939 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15940 struct dwarf2_locexpr_baton
*baton
;
15942 unsigned int cu_off
;
15943 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15944 LONGEST offset
= 0;
15946 gdb_assert (common_loc
&& member_loc
);
15947 gdb_assert (common_loc
->form_is_block ());
15948 gdb_assert (member_loc
->form_is_block ()
15949 || member_loc
->form_is_constant ());
15951 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15952 baton
->per_cu
= cu
->per_cu
;
15953 gdb_assert (baton
->per_cu
);
15955 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15957 if (member_loc
->form_is_constant ())
15959 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15960 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15963 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15965 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15968 *ptr
++ = DW_OP_call4
;
15969 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15970 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15973 if (member_loc
->form_is_constant ())
15975 *ptr
++ = DW_OP_addr
;
15976 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15977 ptr
+= cu
->header
.addr_size
;
15981 /* We have to copy the data here, because DW_OP_call4 will only
15982 use a DW_AT_location attribute. */
15983 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15984 ptr
+= DW_BLOCK (member_loc
)->size
;
15987 *ptr
++ = DW_OP_plus
;
15988 gdb_assert (ptr
- baton
->data
== baton
->size
);
15990 SYMBOL_LOCATION_BATON (sym
) = baton
;
15991 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15994 /* Create appropriate locally-scoped variables for all the
15995 DW_TAG_common_block entries. Also create a struct common_block
15996 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15997 is used to separate the common blocks name namespace from regular
16001 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16003 struct attribute
*attr
;
16005 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16006 if (attr
!= nullptr)
16008 /* Support the .debug_loc offsets. */
16009 if (attr
->form_is_block ())
16013 else if (attr
->form_is_section_offset ())
16015 dwarf2_complex_location_expr_complaint ();
16020 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16021 "common block member");
16026 if (die
->child
!= NULL
)
16028 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16029 struct die_info
*child_die
;
16030 size_t n_entries
= 0, size
;
16031 struct common_block
*common_block
;
16032 struct symbol
*sym
;
16034 for (child_die
= die
->child
;
16035 child_die
&& child_die
->tag
;
16036 child_die
= sibling_die (child_die
))
16039 size
= (sizeof (struct common_block
)
16040 + (n_entries
- 1) * sizeof (struct symbol
*));
16042 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16044 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16045 common_block
->n_entries
= 0;
16047 for (child_die
= die
->child
;
16048 child_die
&& child_die
->tag
;
16049 child_die
= sibling_die (child_die
))
16051 /* Create the symbol in the DW_TAG_common_block block in the current
16053 sym
= new_symbol (child_die
, NULL
, cu
);
16056 struct attribute
*member_loc
;
16058 common_block
->contents
[common_block
->n_entries
++] = sym
;
16060 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16064 /* GDB has handled this for a long time, but it is
16065 not specified by DWARF. It seems to have been
16066 emitted by gfortran at least as recently as:
16067 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16068 complaint (_("Variable in common block has "
16069 "DW_AT_data_member_location "
16070 "- DIE at %s [in module %s]"),
16071 sect_offset_str (child_die
->sect_off
),
16072 objfile_name (objfile
));
16074 if (member_loc
->form_is_section_offset ())
16075 dwarf2_complex_location_expr_complaint ();
16076 else if (member_loc
->form_is_constant ()
16077 || member_loc
->form_is_block ())
16079 if (attr
!= nullptr)
16080 mark_common_block_symbol_computed (sym
, die
, attr
,
16084 dwarf2_complex_location_expr_complaint ();
16089 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16090 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16094 /* Create a type for a C++ namespace. */
16096 static struct type
*
16097 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16099 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16100 const char *previous_prefix
, *name
;
16104 /* For extensions, reuse the type of the original namespace. */
16105 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16107 struct die_info
*ext_die
;
16108 struct dwarf2_cu
*ext_cu
= cu
;
16110 ext_die
= dwarf2_extension (die
, &ext_cu
);
16111 type
= read_type_die (ext_die
, ext_cu
);
16113 /* EXT_CU may not be the same as CU.
16114 Ensure TYPE is recorded with CU in die_type_hash. */
16115 return set_die_type (die
, type
, cu
);
16118 name
= namespace_name (die
, &is_anonymous
, cu
);
16120 /* Now build the name of the current namespace. */
16122 previous_prefix
= determine_prefix (die
, cu
);
16123 if (previous_prefix
[0] != '\0')
16124 name
= typename_concat (&objfile
->objfile_obstack
,
16125 previous_prefix
, name
, 0, cu
);
16127 /* Create the type. */
16128 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16130 return set_die_type (die
, type
, cu
);
16133 /* Read a namespace scope. */
16136 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16138 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16141 /* Add a symbol associated to this if we haven't seen the namespace
16142 before. Also, add a using directive if it's an anonymous
16145 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16149 type
= read_type_die (die
, cu
);
16150 new_symbol (die
, type
, cu
);
16152 namespace_name (die
, &is_anonymous
, cu
);
16155 const char *previous_prefix
= determine_prefix (die
, cu
);
16157 std::vector
<const char *> excludes
;
16158 add_using_directive (using_directives (cu
),
16159 previous_prefix
, TYPE_NAME (type
), NULL
,
16160 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16164 if (die
->child
!= NULL
)
16166 struct die_info
*child_die
= die
->child
;
16168 while (child_die
&& child_die
->tag
)
16170 process_die (child_die
, cu
);
16171 child_die
= sibling_die (child_die
);
16176 /* Read a Fortran module as type. This DIE can be only a declaration used for
16177 imported module. Still we need that type as local Fortran "use ... only"
16178 declaration imports depend on the created type in determine_prefix. */
16180 static struct type
*
16181 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16183 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16184 const char *module_name
;
16187 module_name
= dwarf2_name (die
, cu
);
16188 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16190 return set_die_type (die
, type
, cu
);
16193 /* Read a Fortran module. */
16196 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16198 struct die_info
*child_die
= die
->child
;
16201 type
= read_type_die (die
, cu
);
16202 new_symbol (die
, type
, cu
);
16204 while (child_die
&& child_die
->tag
)
16206 process_die (child_die
, cu
);
16207 child_die
= sibling_die (child_die
);
16211 /* Return the name of the namespace represented by DIE. Set
16212 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16215 static const char *
16216 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16218 struct die_info
*current_die
;
16219 const char *name
= NULL
;
16221 /* Loop through the extensions until we find a name. */
16223 for (current_die
= die
;
16224 current_die
!= NULL
;
16225 current_die
= dwarf2_extension (die
, &cu
))
16227 /* We don't use dwarf2_name here so that we can detect the absence
16228 of a name -> anonymous namespace. */
16229 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16235 /* Is it an anonymous namespace? */
16237 *is_anonymous
= (name
== NULL
);
16239 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16244 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16245 the user defined type vector. */
16247 static struct type
*
16248 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16250 struct gdbarch
*gdbarch
16251 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16252 struct comp_unit_head
*cu_header
= &cu
->header
;
16254 struct attribute
*attr_byte_size
;
16255 struct attribute
*attr_address_class
;
16256 int byte_size
, addr_class
;
16257 struct type
*target_type
;
16259 target_type
= die_type (die
, cu
);
16261 /* The die_type call above may have already set the type for this DIE. */
16262 type
= get_die_type (die
, cu
);
16266 type
= lookup_pointer_type (target_type
);
16268 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16269 if (attr_byte_size
)
16270 byte_size
= DW_UNSND (attr_byte_size
);
16272 byte_size
= cu_header
->addr_size
;
16274 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16275 if (attr_address_class
)
16276 addr_class
= DW_UNSND (attr_address_class
);
16278 addr_class
= DW_ADDR_none
;
16280 ULONGEST alignment
= get_alignment (cu
, die
);
16282 /* If the pointer size, alignment, or address class is different
16283 than the default, create a type variant marked as such and set
16284 the length accordingly. */
16285 if (TYPE_LENGTH (type
) != byte_size
16286 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16287 && alignment
!= TYPE_RAW_ALIGN (type
))
16288 || addr_class
!= DW_ADDR_none
)
16290 if (gdbarch_address_class_type_flags_p (gdbarch
))
16294 type_flags
= gdbarch_address_class_type_flags
16295 (gdbarch
, byte_size
, addr_class
);
16296 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16298 type
= make_type_with_address_space (type
, type_flags
);
16300 else if (TYPE_LENGTH (type
) != byte_size
)
16302 complaint (_("invalid pointer size %d"), byte_size
);
16304 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16306 complaint (_("Invalid DW_AT_alignment"
16307 " - DIE at %s [in module %s]"),
16308 sect_offset_str (die
->sect_off
),
16309 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16313 /* Should we also complain about unhandled address classes? */
16317 TYPE_LENGTH (type
) = byte_size
;
16318 set_type_align (type
, alignment
);
16319 return set_die_type (die
, type
, cu
);
16322 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16323 the user defined type vector. */
16325 static struct type
*
16326 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16329 struct type
*to_type
;
16330 struct type
*domain
;
16332 to_type
= die_type (die
, cu
);
16333 domain
= die_containing_type (die
, cu
);
16335 /* The calls above may have already set the type for this DIE. */
16336 type
= get_die_type (die
, cu
);
16340 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16341 type
= lookup_methodptr_type (to_type
);
16342 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16344 struct type
*new_type
16345 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16347 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16348 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16349 TYPE_VARARGS (to_type
));
16350 type
= lookup_methodptr_type (new_type
);
16353 type
= lookup_memberptr_type (to_type
, domain
);
16355 return set_die_type (die
, type
, cu
);
16358 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16359 the user defined type vector. */
16361 static struct type
*
16362 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16363 enum type_code refcode
)
16365 struct comp_unit_head
*cu_header
= &cu
->header
;
16366 struct type
*type
, *target_type
;
16367 struct attribute
*attr
;
16369 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16371 target_type
= die_type (die
, cu
);
16373 /* The die_type call above may have already set the type for this DIE. */
16374 type
= get_die_type (die
, cu
);
16378 type
= lookup_reference_type (target_type
, refcode
);
16379 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16380 if (attr
!= nullptr)
16382 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16386 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16388 maybe_set_alignment (cu
, die
, type
);
16389 return set_die_type (die
, type
, cu
);
16392 /* Add the given cv-qualifiers to the element type of the array. GCC
16393 outputs DWARF type qualifiers that apply to an array, not the
16394 element type. But GDB relies on the array element type to carry
16395 the cv-qualifiers. This mimics section 6.7.3 of the C99
16398 static struct type
*
16399 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16400 struct type
*base_type
, int cnst
, int voltl
)
16402 struct type
*el_type
, *inner_array
;
16404 base_type
= copy_type (base_type
);
16405 inner_array
= base_type
;
16407 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16409 TYPE_TARGET_TYPE (inner_array
) =
16410 copy_type (TYPE_TARGET_TYPE (inner_array
));
16411 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16414 el_type
= TYPE_TARGET_TYPE (inner_array
);
16415 cnst
|= TYPE_CONST (el_type
);
16416 voltl
|= TYPE_VOLATILE (el_type
);
16417 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16419 return set_die_type (die
, base_type
, cu
);
16422 static struct type
*
16423 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16425 struct type
*base_type
, *cv_type
;
16427 base_type
= die_type (die
, cu
);
16429 /* The die_type call above may have already set the type for this DIE. */
16430 cv_type
= get_die_type (die
, cu
);
16434 /* In case the const qualifier is applied to an array type, the element type
16435 is so qualified, not the array type (section 6.7.3 of C99). */
16436 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16437 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16439 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16440 return set_die_type (die
, cv_type
, cu
);
16443 static struct type
*
16444 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16446 struct type
*base_type
, *cv_type
;
16448 base_type
= die_type (die
, cu
);
16450 /* The die_type call above may have already set the type for this DIE. */
16451 cv_type
= get_die_type (die
, cu
);
16455 /* In case the volatile qualifier is applied to an array type, the
16456 element type is so qualified, not the array type (section 6.7.3
16458 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16459 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16461 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16462 return set_die_type (die
, cv_type
, cu
);
16465 /* Handle DW_TAG_restrict_type. */
16467 static struct type
*
16468 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16470 struct type
*base_type
, *cv_type
;
16472 base_type
= die_type (die
, cu
);
16474 /* The die_type call above may have already set the type for this DIE. */
16475 cv_type
= get_die_type (die
, cu
);
16479 cv_type
= make_restrict_type (base_type
);
16480 return set_die_type (die
, cv_type
, cu
);
16483 /* Handle DW_TAG_atomic_type. */
16485 static struct type
*
16486 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16488 struct type
*base_type
, *cv_type
;
16490 base_type
= die_type (die
, cu
);
16492 /* The die_type call above may have already set the type for this DIE. */
16493 cv_type
= get_die_type (die
, cu
);
16497 cv_type
= make_atomic_type (base_type
);
16498 return set_die_type (die
, cv_type
, cu
);
16501 /* Extract all information from a DW_TAG_string_type DIE and add to
16502 the user defined type vector. It isn't really a user defined type,
16503 but it behaves like one, with other DIE's using an AT_user_def_type
16504 attribute to reference it. */
16506 static struct type
*
16507 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16509 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16510 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16511 struct type
*type
, *range_type
, *index_type
, *char_type
;
16512 struct attribute
*attr
;
16513 struct dynamic_prop prop
;
16514 bool length_is_constant
= true;
16517 /* There are a couple of places where bit sizes might be made use of
16518 when parsing a DW_TAG_string_type, however, no producer that we know
16519 of make use of these. Handling bit sizes that are a multiple of the
16520 byte size is easy enough, but what about other bit sizes? Lets deal
16521 with that problem when we have to. Warn about these attributes being
16522 unsupported, then parse the type and ignore them like we always
16524 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16525 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16527 static bool warning_printed
= false;
16528 if (!warning_printed
)
16530 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16531 "currently supported on DW_TAG_string_type."));
16532 warning_printed
= true;
16536 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16537 if (attr
!= nullptr && !attr
->form_is_constant ())
16539 /* The string length describes the location at which the length of
16540 the string can be found. The size of the length field can be
16541 specified with one of the attributes below. */
16542 struct type
*prop_type
;
16543 struct attribute
*len
16544 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16545 if (len
== nullptr)
16546 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16547 if (len
!= nullptr && len
->form_is_constant ())
16549 /* Pass 0 as the default as we know this attribute is constant
16550 and the default value will not be returned. */
16551 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16552 prop_type
= cu
->per_cu
->int_type (sz
, true);
16556 /* If the size is not specified then we assume it is the size of
16557 an address on this target. */
16558 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16561 /* Convert the attribute into a dynamic property. */
16562 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16565 length_is_constant
= false;
16567 else if (attr
!= nullptr)
16569 /* This DW_AT_string_length just contains the length with no
16570 indirection. There's no need to create a dynamic property in this
16571 case. Pass 0 for the default value as we know it will not be
16572 returned in this case. */
16573 length
= dwarf2_get_attr_constant_value (attr
, 0);
16575 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16577 /* We don't currently support non-constant byte sizes for strings. */
16578 length
= dwarf2_get_attr_constant_value (attr
, 1);
16582 /* Use 1 as a fallback length if we have nothing else. */
16586 index_type
= objfile_type (objfile
)->builtin_int
;
16587 if (length_is_constant
)
16588 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16591 struct dynamic_prop low_bound
;
16593 low_bound
.kind
= PROP_CONST
;
16594 low_bound
.data
.const_val
= 1;
16595 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16597 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16598 type
= create_string_type (NULL
, char_type
, range_type
);
16600 return set_die_type (die
, type
, cu
);
16603 /* Assuming that DIE corresponds to a function, returns nonzero
16604 if the function is prototyped. */
16607 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16609 struct attribute
*attr
;
16611 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16612 if (attr
&& (DW_UNSND (attr
) != 0))
16615 /* The DWARF standard implies that the DW_AT_prototyped attribute
16616 is only meaningful for C, but the concept also extends to other
16617 languages that allow unprototyped functions (Eg: Objective C).
16618 For all other languages, assume that functions are always
16620 if (cu
->language
!= language_c
16621 && cu
->language
!= language_objc
16622 && cu
->language
!= language_opencl
)
16625 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16626 prototyped and unprototyped functions; default to prototyped,
16627 since that is more common in modern code (and RealView warns
16628 about unprototyped functions). */
16629 if (producer_is_realview (cu
->producer
))
16635 /* Handle DIES due to C code like:
16639 int (*funcp)(int a, long l);
16643 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16645 static struct type
*
16646 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16648 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16649 struct type
*type
; /* Type that this function returns. */
16650 struct type
*ftype
; /* Function that returns above type. */
16651 struct attribute
*attr
;
16653 type
= die_type (die
, cu
);
16655 /* The die_type call above may have already set the type for this DIE. */
16656 ftype
= get_die_type (die
, cu
);
16660 ftype
= lookup_function_type (type
);
16662 if (prototyped_function_p (die
, cu
))
16663 TYPE_PROTOTYPED (ftype
) = 1;
16665 /* Store the calling convention in the type if it's available in
16666 the subroutine die. Otherwise set the calling convention to
16667 the default value DW_CC_normal. */
16668 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16669 if (attr
!= nullptr
16670 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16671 TYPE_CALLING_CONVENTION (ftype
)
16672 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16673 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16674 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16676 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16678 /* Record whether the function returns normally to its caller or not
16679 if the DWARF producer set that information. */
16680 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16681 if (attr
&& (DW_UNSND (attr
) != 0))
16682 TYPE_NO_RETURN (ftype
) = 1;
16684 /* We need to add the subroutine type to the die immediately so
16685 we don't infinitely recurse when dealing with parameters
16686 declared as the same subroutine type. */
16687 set_die_type (die
, ftype
, cu
);
16689 if (die
->child
!= NULL
)
16691 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16692 struct die_info
*child_die
;
16693 int nparams
, iparams
;
16695 /* Count the number of parameters.
16696 FIXME: GDB currently ignores vararg functions, but knows about
16697 vararg member functions. */
16699 child_die
= die
->child
;
16700 while (child_die
&& child_die
->tag
)
16702 if (child_die
->tag
== DW_TAG_formal_parameter
)
16704 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16705 TYPE_VARARGS (ftype
) = 1;
16706 child_die
= sibling_die (child_die
);
16709 /* Allocate storage for parameters and fill them in. */
16710 TYPE_NFIELDS (ftype
) = nparams
;
16711 TYPE_FIELDS (ftype
) = (struct field
*)
16712 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16714 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16715 even if we error out during the parameters reading below. */
16716 for (iparams
= 0; iparams
< nparams
; iparams
++)
16717 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16720 child_die
= die
->child
;
16721 while (child_die
&& child_die
->tag
)
16723 if (child_die
->tag
== DW_TAG_formal_parameter
)
16725 struct type
*arg_type
;
16727 /* DWARF version 2 has no clean way to discern C++
16728 static and non-static member functions. G++ helps
16729 GDB by marking the first parameter for non-static
16730 member functions (which is the this pointer) as
16731 artificial. We pass this information to
16732 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16734 DWARF version 3 added DW_AT_object_pointer, which GCC
16735 4.5 does not yet generate. */
16736 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16737 if (attr
!= nullptr)
16738 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16740 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16741 arg_type
= die_type (child_die
, cu
);
16743 /* RealView does not mark THIS as const, which the testsuite
16744 expects. GCC marks THIS as const in method definitions,
16745 but not in the class specifications (GCC PR 43053). */
16746 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16747 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16750 struct dwarf2_cu
*arg_cu
= cu
;
16751 const char *name
= dwarf2_name (child_die
, cu
);
16753 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16754 if (attr
!= nullptr)
16756 /* If the compiler emits this, use it. */
16757 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16760 else if (name
&& strcmp (name
, "this") == 0)
16761 /* Function definitions will have the argument names. */
16763 else if (name
== NULL
&& iparams
== 0)
16764 /* Declarations may not have the names, so like
16765 elsewhere in GDB, assume an artificial first
16766 argument is "this". */
16770 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16774 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16777 child_die
= sibling_die (child_die
);
16784 static struct type
*
16785 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16787 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16788 const char *name
= NULL
;
16789 struct type
*this_type
, *target_type
;
16791 name
= dwarf2_full_name (NULL
, die
, cu
);
16792 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16793 TYPE_TARGET_STUB (this_type
) = 1;
16794 set_die_type (die
, this_type
, cu
);
16795 target_type
= die_type (die
, cu
);
16796 if (target_type
!= this_type
)
16797 TYPE_TARGET_TYPE (this_type
) = target_type
;
16800 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16801 spec and cause infinite loops in GDB. */
16802 complaint (_("Self-referential DW_TAG_typedef "
16803 "- DIE at %s [in module %s]"),
16804 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16805 TYPE_TARGET_TYPE (this_type
) = NULL
;
16809 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16810 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16811 Handle these by just returning the target type, rather than
16812 constructing an anonymous typedef type and trying to handle this
16814 set_die_type (die
, target_type
, cu
);
16815 return target_type
;
16820 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16821 (which may be different from NAME) to the architecture back-end to allow
16822 it to guess the correct format if necessary. */
16824 static struct type
*
16825 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16826 const char *name_hint
, enum bfd_endian byte_order
)
16828 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16829 const struct floatformat
**format
;
16832 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16834 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16836 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16841 /* Allocate an integer type of size BITS and name NAME. */
16843 static struct type
*
16844 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16845 int bits
, int unsigned_p
, const char *name
)
16849 /* Versions of Intel's C Compiler generate an integer type called "void"
16850 instead of using DW_TAG_unspecified_type. This has been seen on
16851 at least versions 14, 17, and 18. */
16852 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16853 && strcmp (name
, "void") == 0)
16854 type
= objfile_type (objfile
)->builtin_void
;
16856 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16861 /* Initialise and return a floating point type of size BITS suitable for
16862 use as a component of a complex number. The NAME_HINT is passed through
16863 when initialising the floating point type and is the name of the complex
16866 As DWARF doesn't currently provide an explicit name for the components
16867 of a complex number, but it can be helpful to have these components
16868 named, we try to select a suitable name based on the size of the
16870 static struct type
*
16871 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16872 struct objfile
*objfile
,
16873 int bits
, const char *name_hint
,
16874 enum bfd_endian byte_order
)
16876 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16877 struct type
*tt
= nullptr;
16879 /* Try to find a suitable floating point builtin type of size BITS.
16880 We're going to use the name of this type as the name for the complex
16881 target type that we are about to create. */
16882 switch (cu
->language
)
16884 case language_fortran
:
16888 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16891 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16893 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16895 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16903 tt
= builtin_type (gdbarch
)->builtin_float
;
16906 tt
= builtin_type (gdbarch
)->builtin_double
;
16908 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16910 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16916 /* If the type we found doesn't match the size we were looking for, then
16917 pretend we didn't find a type at all, the complex target type we
16918 create will then be nameless. */
16919 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16922 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16923 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16926 /* Find a representation of a given base type and install
16927 it in the TYPE field of the die. */
16929 static struct type
*
16930 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16932 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16934 struct attribute
*attr
;
16935 int encoding
= 0, bits
= 0;
16939 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16940 if (attr
!= nullptr)
16941 encoding
= DW_UNSND (attr
);
16942 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16943 if (attr
!= nullptr)
16944 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16945 name
= dwarf2_name (die
, cu
);
16947 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16949 arch
= get_objfile_arch (objfile
);
16950 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16952 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16955 int endianity
= DW_UNSND (attr
);
16960 byte_order
= BFD_ENDIAN_BIG
;
16962 case DW_END_little
:
16963 byte_order
= BFD_ENDIAN_LITTLE
;
16966 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16973 case DW_ATE_address
:
16974 /* Turn DW_ATE_address into a void * pointer. */
16975 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16976 type
= init_pointer_type (objfile
, bits
, name
, type
);
16978 case DW_ATE_boolean
:
16979 type
= init_boolean_type (objfile
, bits
, 1, name
);
16981 case DW_ATE_complex_float
:
16982 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16984 type
= init_complex_type (objfile
, name
, type
);
16986 case DW_ATE_decimal_float
:
16987 type
= init_decfloat_type (objfile
, bits
, name
);
16990 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16992 case DW_ATE_signed
:
16993 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16995 case DW_ATE_unsigned
:
16996 if (cu
->language
== language_fortran
16998 && startswith (name
, "character("))
16999 type
= init_character_type (objfile
, bits
, 1, name
);
17001 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17003 case DW_ATE_signed_char
:
17004 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17005 || cu
->language
== language_pascal
17006 || cu
->language
== language_fortran
)
17007 type
= init_character_type (objfile
, bits
, 0, name
);
17009 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17011 case DW_ATE_unsigned_char
:
17012 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17013 || cu
->language
== language_pascal
17014 || cu
->language
== language_fortran
17015 || cu
->language
== language_rust
)
17016 type
= init_character_type (objfile
, bits
, 1, name
);
17018 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17023 type
= builtin_type (arch
)->builtin_char16
;
17024 else if (bits
== 32)
17025 type
= builtin_type (arch
)->builtin_char32
;
17028 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17030 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17032 return set_die_type (die
, type
, cu
);
17037 complaint (_("unsupported DW_AT_encoding: '%s'"),
17038 dwarf_type_encoding_name (encoding
));
17039 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17043 if (name
&& strcmp (name
, "char") == 0)
17044 TYPE_NOSIGN (type
) = 1;
17046 maybe_set_alignment (cu
, die
, type
);
17048 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17050 return set_die_type (die
, type
, cu
);
17053 /* Parse dwarf attribute if it's a block, reference or constant and put the
17054 resulting value of the attribute into struct bound_prop.
17055 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17058 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17059 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17060 struct type
*default_type
)
17062 struct dwarf2_property_baton
*baton
;
17063 struct obstack
*obstack
17064 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17066 gdb_assert (default_type
!= NULL
);
17068 if (attr
== NULL
|| prop
== NULL
)
17071 if (attr
->form_is_block ())
17073 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17074 baton
->property_type
= default_type
;
17075 baton
->locexpr
.per_cu
= cu
->per_cu
;
17076 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17077 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17078 switch (attr
->name
)
17080 case DW_AT_string_length
:
17081 baton
->locexpr
.is_reference
= true;
17084 baton
->locexpr
.is_reference
= false;
17087 prop
->data
.baton
= baton
;
17088 prop
->kind
= PROP_LOCEXPR
;
17089 gdb_assert (prop
->data
.baton
!= NULL
);
17091 else if (attr
->form_is_ref ())
17093 struct dwarf2_cu
*target_cu
= cu
;
17094 struct die_info
*target_die
;
17095 struct attribute
*target_attr
;
17097 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17098 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17099 if (target_attr
== NULL
)
17100 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17102 if (target_attr
== NULL
)
17105 switch (target_attr
->name
)
17107 case DW_AT_location
:
17108 if (target_attr
->form_is_section_offset ())
17110 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17111 baton
->property_type
= die_type (target_die
, target_cu
);
17112 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17113 prop
->data
.baton
= baton
;
17114 prop
->kind
= PROP_LOCLIST
;
17115 gdb_assert (prop
->data
.baton
!= NULL
);
17117 else if (target_attr
->form_is_block ())
17119 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17120 baton
->property_type
= die_type (target_die
, target_cu
);
17121 baton
->locexpr
.per_cu
= cu
->per_cu
;
17122 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17123 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17124 baton
->locexpr
.is_reference
= true;
17125 prop
->data
.baton
= baton
;
17126 prop
->kind
= PROP_LOCEXPR
;
17127 gdb_assert (prop
->data
.baton
!= NULL
);
17131 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17132 "dynamic property");
17136 case DW_AT_data_member_location
:
17140 if (!handle_data_member_location (target_die
, target_cu
,
17144 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17145 baton
->property_type
= read_type_die (target_die
->parent
,
17147 baton
->offset_info
.offset
= offset
;
17148 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17149 prop
->data
.baton
= baton
;
17150 prop
->kind
= PROP_ADDR_OFFSET
;
17155 else if (attr
->form_is_constant ())
17157 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17158 prop
->kind
= PROP_CONST
;
17162 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17163 dwarf2_name (die
, cu
));
17173 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17175 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17176 struct type
*int_type
;
17178 /* Helper macro to examine the various builtin types. */
17179 #define TRY_TYPE(F) \
17180 int_type = (unsigned_p \
17181 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17182 : objfile_type (objfile)->builtin_ ## F); \
17183 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17190 TRY_TYPE (long_long
);
17194 gdb_assert_not_reached ("unable to find suitable integer type");
17200 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17202 int addr_size
= this->addr_size ();
17203 return int_type (addr_size
, unsigned_p
);
17206 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17207 present (which is valid) then compute the default type based on the
17208 compilation units address size. */
17210 static struct type
*
17211 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17213 struct type
*index_type
= die_type (die
, cu
);
17215 /* Dwarf-2 specifications explicitly allows to create subrange types
17216 without specifying a base type.
17217 In that case, the base type must be set to the type of
17218 the lower bound, upper bound or count, in that order, if any of these
17219 three attributes references an object that has a type.
17220 If no base type is found, the Dwarf-2 specifications say that
17221 a signed integer type of size equal to the size of an address should
17223 For the following C code: `extern char gdb_int [];'
17224 GCC produces an empty range DIE.
17225 FIXME: muller/2010-05-28: Possible references to object for low bound,
17226 high bound or count are not yet handled by this code. */
17227 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17228 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17233 /* Read the given DW_AT_subrange DIE. */
17235 static struct type
*
17236 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17238 struct type
*base_type
, *orig_base_type
;
17239 struct type
*range_type
;
17240 struct attribute
*attr
;
17241 struct dynamic_prop low
, high
;
17242 int low_default_is_valid
;
17243 int high_bound_is_count
= 0;
17245 ULONGEST negative_mask
;
17247 orig_base_type
= read_subrange_index_type (die
, cu
);
17249 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17250 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17251 creating the range type, but we use the result of check_typedef
17252 when examining properties of the type. */
17253 base_type
= check_typedef (orig_base_type
);
17255 /* The die_type call above may have already set the type for this DIE. */
17256 range_type
= get_die_type (die
, cu
);
17260 low
.kind
= PROP_CONST
;
17261 high
.kind
= PROP_CONST
;
17262 high
.data
.const_val
= 0;
17264 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17265 omitting DW_AT_lower_bound. */
17266 switch (cu
->language
)
17269 case language_cplus
:
17270 low
.data
.const_val
= 0;
17271 low_default_is_valid
= 1;
17273 case language_fortran
:
17274 low
.data
.const_val
= 1;
17275 low_default_is_valid
= 1;
17278 case language_objc
:
17279 case language_rust
:
17280 low
.data
.const_val
= 0;
17281 low_default_is_valid
= (cu
->header
.version
>= 4);
17285 case language_pascal
:
17286 low
.data
.const_val
= 1;
17287 low_default_is_valid
= (cu
->header
.version
>= 4);
17290 low
.data
.const_val
= 0;
17291 low_default_is_valid
= 0;
17295 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17296 if (attr
!= nullptr)
17297 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17298 else if (!low_default_is_valid
)
17299 complaint (_("Missing DW_AT_lower_bound "
17300 "- DIE at %s [in module %s]"),
17301 sect_offset_str (die
->sect_off
),
17302 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17304 struct attribute
*attr_ub
, *attr_count
;
17305 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17306 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17308 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17309 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17311 /* If bounds are constant do the final calculation here. */
17312 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17313 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17315 high_bound_is_count
= 1;
17319 if (attr_ub
!= NULL
)
17320 complaint (_("Unresolved DW_AT_upper_bound "
17321 "- DIE at %s [in module %s]"),
17322 sect_offset_str (die
->sect_off
),
17323 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17324 if (attr_count
!= NULL
)
17325 complaint (_("Unresolved DW_AT_count "
17326 "- DIE at %s [in module %s]"),
17327 sect_offset_str (die
->sect_off
),
17328 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17333 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17334 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17335 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17337 /* Normally, the DWARF producers are expected to use a signed
17338 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17339 But this is unfortunately not always the case, as witnessed
17340 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17341 is used instead. To work around that ambiguity, we treat
17342 the bounds as signed, and thus sign-extend their values, when
17343 the base type is signed. */
17345 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17346 if (low
.kind
== PROP_CONST
17347 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17348 low
.data
.const_val
|= negative_mask
;
17349 if (high
.kind
== PROP_CONST
17350 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17351 high
.data
.const_val
|= negative_mask
;
17353 /* Check for bit and byte strides. */
17354 struct dynamic_prop byte_stride_prop
;
17355 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17356 if (attr_byte_stride
!= nullptr)
17358 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17359 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17363 struct dynamic_prop bit_stride_prop
;
17364 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17365 if (attr_bit_stride
!= nullptr)
17367 /* It only makes sense to have either a bit or byte stride. */
17368 if (attr_byte_stride
!= nullptr)
17370 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17371 "- DIE at %s [in module %s]"),
17372 sect_offset_str (die
->sect_off
),
17373 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17374 attr_bit_stride
= nullptr;
17378 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17379 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17384 if (attr_byte_stride
!= nullptr
17385 || attr_bit_stride
!= nullptr)
17387 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17388 struct dynamic_prop
*stride
17389 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17392 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17393 &high
, bias
, stride
, byte_stride_p
);
17396 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17398 if (high_bound_is_count
)
17399 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17401 /* Ada expects an empty array on no boundary attributes. */
17402 if (attr
== NULL
&& cu
->language
!= language_ada
)
17403 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17405 name
= dwarf2_name (die
, cu
);
17407 TYPE_NAME (range_type
) = name
;
17409 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17410 if (attr
!= nullptr)
17411 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17413 maybe_set_alignment (cu
, die
, range_type
);
17415 set_die_type (die
, range_type
, cu
);
17417 /* set_die_type should be already done. */
17418 set_descriptive_type (range_type
, die
, cu
);
17423 static struct type
*
17424 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17428 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17430 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17432 /* In Ada, an unspecified type is typically used when the description
17433 of the type is deferred to a different unit. When encountering
17434 such a type, we treat it as a stub, and try to resolve it later on,
17436 if (cu
->language
== language_ada
)
17437 TYPE_STUB (type
) = 1;
17439 return set_die_type (die
, type
, cu
);
17442 /* Read a single die and all its descendents. Set the die's sibling
17443 field to NULL; set other fields in the die correctly, and set all
17444 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17445 location of the info_ptr after reading all of those dies. PARENT
17446 is the parent of the die in question. */
17448 static struct die_info
*
17449 read_die_and_children (const struct die_reader_specs
*reader
,
17450 const gdb_byte
*info_ptr
,
17451 const gdb_byte
**new_info_ptr
,
17452 struct die_info
*parent
)
17454 struct die_info
*die
;
17455 const gdb_byte
*cur_ptr
;
17457 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17460 *new_info_ptr
= cur_ptr
;
17463 store_in_ref_table (die
, reader
->cu
);
17465 if (die
->has_children
)
17466 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17470 *new_info_ptr
= cur_ptr
;
17473 die
->sibling
= NULL
;
17474 die
->parent
= parent
;
17478 /* Read a die, all of its descendents, and all of its siblings; set
17479 all of the fields of all of the dies correctly. Arguments are as
17480 in read_die_and_children. */
17482 static struct die_info
*
17483 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17484 const gdb_byte
*info_ptr
,
17485 const gdb_byte
**new_info_ptr
,
17486 struct die_info
*parent
)
17488 struct die_info
*first_die
, *last_sibling
;
17489 const gdb_byte
*cur_ptr
;
17491 cur_ptr
= info_ptr
;
17492 first_die
= last_sibling
= NULL
;
17496 struct die_info
*die
17497 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17501 *new_info_ptr
= cur_ptr
;
17508 last_sibling
->sibling
= die
;
17510 last_sibling
= die
;
17514 /* Read a die, all of its descendents, and all of its siblings; set
17515 all of the fields of all of the dies correctly. Arguments are as
17516 in read_die_and_children.
17517 This the main entry point for reading a DIE and all its children. */
17519 static struct die_info
*
17520 read_die_and_siblings (const struct die_reader_specs
*reader
,
17521 const gdb_byte
*info_ptr
,
17522 const gdb_byte
**new_info_ptr
,
17523 struct die_info
*parent
)
17525 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17526 new_info_ptr
, parent
);
17528 if (dwarf_die_debug
)
17530 fprintf_unfiltered (gdb_stdlog
,
17531 "Read die from %s@0x%x of %s:\n",
17532 reader
->die_section
->get_name (),
17533 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17534 bfd_get_filename (reader
->abfd
));
17535 dump_die (die
, dwarf_die_debug
);
17541 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17543 The caller is responsible for filling in the extra attributes
17544 and updating (*DIEP)->num_attrs.
17545 Set DIEP to point to a newly allocated die with its information,
17546 except for its child, sibling, and parent fields. */
17548 static const gdb_byte
*
17549 read_full_die_1 (const struct die_reader_specs
*reader
,
17550 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17551 int num_extra_attrs
)
17553 unsigned int abbrev_number
, bytes_read
, i
;
17554 struct abbrev_info
*abbrev
;
17555 struct die_info
*die
;
17556 struct dwarf2_cu
*cu
= reader
->cu
;
17557 bfd
*abfd
= reader
->abfd
;
17559 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17560 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17561 info_ptr
+= bytes_read
;
17562 if (!abbrev_number
)
17568 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17570 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17572 bfd_get_filename (abfd
));
17574 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17575 die
->sect_off
= sect_off
;
17576 die
->tag
= abbrev
->tag
;
17577 die
->abbrev
= abbrev_number
;
17578 die
->has_children
= abbrev
->has_children
;
17580 /* Make the result usable.
17581 The caller needs to update num_attrs after adding the extra
17583 die
->num_attrs
= abbrev
->num_attrs
;
17585 std::vector
<int> indexes_that_need_reprocess
;
17586 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17588 bool need_reprocess
;
17590 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17591 info_ptr
, &need_reprocess
);
17592 if (need_reprocess
)
17593 indexes_that_need_reprocess
.push_back (i
);
17596 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17597 if (attr
!= nullptr)
17598 cu
->str_offsets_base
= DW_UNSND (attr
);
17600 auto maybe_addr_base
= lookup_addr_base(die
);
17601 if (maybe_addr_base
.has_value ())
17602 cu
->addr_base
= *maybe_addr_base
;
17603 for (int index
: indexes_that_need_reprocess
)
17604 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17609 /* Read a die and all its attributes.
17610 Set DIEP to point to a newly allocated die with its information,
17611 except for its child, sibling, and parent fields. */
17613 static const gdb_byte
*
17614 read_full_die (const struct die_reader_specs
*reader
,
17615 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17617 const gdb_byte
*result
;
17619 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17621 if (dwarf_die_debug
)
17623 fprintf_unfiltered (gdb_stdlog
,
17624 "Read die from %s@0x%x of %s:\n",
17625 reader
->die_section
->get_name (),
17626 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17627 bfd_get_filename (reader
->abfd
));
17628 dump_die (*diep
, dwarf_die_debug
);
17635 /* Returns nonzero if TAG represents a type that we might generate a partial
17639 is_type_tag_for_partial (int tag
)
17644 /* Some types that would be reasonable to generate partial symbols for,
17645 that we don't at present. */
17646 case DW_TAG_array_type
:
17647 case DW_TAG_file_type
:
17648 case DW_TAG_ptr_to_member_type
:
17649 case DW_TAG_set_type
:
17650 case DW_TAG_string_type
:
17651 case DW_TAG_subroutine_type
:
17653 case DW_TAG_base_type
:
17654 case DW_TAG_class_type
:
17655 case DW_TAG_interface_type
:
17656 case DW_TAG_enumeration_type
:
17657 case DW_TAG_structure_type
:
17658 case DW_TAG_subrange_type
:
17659 case DW_TAG_typedef
:
17660 case DW_TAG_union_type
:
17667 /* Load all DIEs that are interesting for partial symbols into memory. */
17669 static struct partial_die_info
*
17670 load_partial_dies (const struct die_reader_specs
*reader
,
17671 const gdb_byte
*info_ptr
, int building_psymtab
)
17673 struct dwarf2_cu
*cu
= reader
->cu
;
17674 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17675 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17676 unsigned int bytes_read
;
17677 unsigned int load_all
= 0;
17678 int nesting_level
= 1;
17683 gdb_assert (cu
->per_cu
!= NULL
);
17684 if (cu
->per_cu
->load_all_dies
)
17688 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17692 &cu
->comp_unit_obstack
,
17693 hashtab_obstack_allocate
,
17694 dummy_obstack_deallocate
);
17698 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17700 /* A NULL abbrev means the end of a series of children. */
17701 if (abbrev
== NULL
)
17703 if (--nesting_level
== 0)
17706 info_ptr
+= bytes_read
;
17707 last_die
= parent_die
;
17708 parent_die
= parent_die
->die_parent
;
17712 /* Check for template arguments. We never save these; if
17713 they're seen, we just mark the parent, and go on our way. */
17714 if (parent_die
!= NULL
17715 && cu
->language
== language_cplus
17716 && (abbrev
->tag
== DW_TAG_template_type_param
17717 || abbrev
->tag
== DW_TAG_template_value_param
))
17719 parent_die
->has_template_arguments
= 1;
17723 /* We don't need a partial DIE for the template argument. */
17724 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17729 /* We only recurse into c++ subprograms looking for template arguments.
17730 Skip their other children. */
17732 && cu
->language
== language_cplus
17733 && parent_die
!= NULL
17734 && parent_die
->tag
== DW_TAG_subprogram
)
17736 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17740 /* Check whether this DIE is interesting enough to save. Normally
17741 we would not be interested in members here, but there may be
17742 later variables referencing them via DW_AT_specification (for
17743 static members). */
17745 && !is_type_tag_for_partial (abbrev
->tag
)
17746 && abbrev
->tag
!= DW_TAG_constant
17747 && abbrev
->tag
!= DW_TAG_enumerator
17748 && abbrev
->tag
!= DW_TAG_subprogram
17749 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17750 && abbrev
->tag
!= DW_TAG_lexical_block
17751 && abbrev
->tag
!= DW_TAG_variable
17752 && abbrev
->tag
!= DW_TAG_namespace
17753 && abbrev
->tag
!= DW_TAG_module
17754 && abbrev
->tag
!= DW_TAG_member
17755 && abbrev
->tag
!= DW_TAG_imported_unit
17756 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17758 /* Otherwise we skip to the next sibling, if any. */
17759 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17763 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17766 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17768 /* This two-pass algorithm for processing partial symbols has a
17769 high cost in cache pressure. Thus, handle some simple cases
17770 here which cover the majority of C partial symbols. DIEs
17771 which neither have specification tags in them, nor could have
17772 specification tags elsewhere pointing at them, can simply be
17773 processed and discarded.
17775 This segment is also optional; scan_partial_symbols and
17776 add_partial_symbol will handle these DIEs if we chain
17777 them in normally. When compilers which do not emit large
17778 quantities of duplicate debug information are more common,
17779 this code can probably be removed. */
17781 /* Any complete simple types at the top level (pretty much all
17782 of them, for a language without namespaces), can be processed
17784 if (parent_die
== NULL
17785 && pdi
.has_specification
== 0
17786 && pdi
.is_declaration
== 0
17787 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17788 || pdi
.tag
== DW_TAG_base_type
17789 || pdi
.tag
== DW_TAG_subrange_type
))
17791 if (building_psymtab
&& pdi
.name
!= NULL
)
17792 add_psymbol_to_list (pdi
.name
, false,
17793 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17794 psymbol_placement::STATIC
,
17795 0, cu
->language
, objfile
);
17796 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17800 /* The exception for DW_TAG_typedef with has_children above is
17801 a workaround of GCC PR debug/47510. In the case of this complaint
17802 type_name_or_error will error on such types later.
17804 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17805 it could not find the child DIEs referenced later, this is checked
17806 above. In correct DWARF DW_TAG_typedef should have no children. */
17808 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17809 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17810 "- DIE at %s [in module %s]"),
17811 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17813 /* If we're at the second level, and we're an enumerator, and
17814 our parent has no specification (meaning possibly lives in a
17815 namespace elsewhere), then we can add the partial symbol now
17816 instead of queueing it. */
17817 if (pdi
.tag
== DW_TAG_enumerator
17818 && parent_die
!= NULL
17819 && parent_die
->die_parent
== NULL
17820 && parent_die
->tag
== DW_TAG_enumeration_type
17821 && parent_die
->has_specification
== 0)
17823 if (pdi
.name
== NULL
)
17824 complaint (_("malformed enumerator DIE ignored"));
17825 else if (building_psymtab
)
17826 add_psymbol_to_list (pdi
.name
, false,
17827 VAR_DOMAIN
, LOC_CONST
, -1,
17828 cu
->language
== language_cplus
17829 ? psymbol_placement::GLOBAL
17830 : psymbol_placement::STATIC
,
17831 0, cu
->language
, objfile
);
17833 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17837 struct partial_die_info
*part_die
17838 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17840 /* We'll save this DIE so link it in. */
17841 part_die
->die_parent
= parent_die
;
17842 part_die
->die_sibling
= NULL
;
17843 part_die
->die_child
= NULL
;
17845 if (last_die
&& last_die
== parent_die
)
17846 last_die
->die_child
= part_die
;
17848 last_die
->die_sibling
= part_die
;
17850 last_die
= part_die
;
17852 if (first_die
== NULL
)
17853 first_die
= part_die
;
17855 /* Maybe add the DIE to the hash table. Not all DIEs that we
17856 find interesting need to be in the hash table, because we
17857 also have the parent/sibling/child chains; only those that we
17858 might refer to by offset later during partial symbol reading.
17860 For now this means things that might have be the target of a
17861 DW_AT_specification, DW_AT_abstract_origin, or
17862 DW_AT_extension. DW_AT_extension will refer only to
17863 namespaces; DW_AT_abstract_origin refers to functions (and
17864 many things under the function DIE, but we do not recurse
17865 into function DIEs during partial symbol reading) and
17866 possibly variables as well; DW_AT_specification refers to
17867 declarations. Declarations ought to have the DW_AT_declaration
17868 flag. It happens that GCC forgets to put it in sometimes, but
17869 only for functions, not for types.
17871 Adding more things than necessary to the hash table is harmless
17872 except for the performance cost. Adding too few will result in
17873 wasted time in find_partial_die, when we reread the compilation
17874 unit with load_all_dies set. */
17877 || abbrev
->tag
== DW_TAG_constant
17878 || abbrev
->tag
== DW_TAG_subprogram
17879 || abbrev
->tag
== DW_TAG_variable
17880 || abbrev
->tag
== DW_TAG_namespace
17881 || part_die
->is_declaration
)
17885 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17886 to_underlying (part_die
->sect_off
),
17891 /* For some DIEs we want to follow their children (if any). For C
17892 we have no reason to follow the children of structures; for other
17893 languages we have to, so that we can get at method physnames
17894 to infer fully qualified class names, for DW_AT_specification,
17895 and for C++ template arguments. For C++, we also look one level
17896 inside functions to find template arguments (if the name of the
17897 function does not already contain the template arguments).
17899 For Ada and Fortran, we need to scan the children of subprograms
17900 and lexical blocks as well because these languages allow the
17901 definition of nested entities that could be interesting for the
17902 debugger, such as nested subprograms for instance. */
17903 if (last_die
->has_children
17905 || last_die
->tag
== DW_TAG_namespace
17906 || last_die
->tag
== DW_TAG_module
17907 || last_die
->tag
== DW_TAG_enumeration_type
17908 || (cu
->language
== language_cplus
17909 && last_die
->tag
== DW_TAG_subprogram
17910 && (last_die
->name
== NULL
17911 || strchr (last_die
->name
, '<') == NULL
))
17912 || (cu
->language
!= language_c
17913 && (last_die
->tag
== DW_TAG_class_type
17914 || last_die
->tag
== DW_TAG_interface_type
17915 || last_die
->tag
== DW_TAG_structure_type
17916 || last_die
->tag
== DW_TAG_union_type
))
17917 || ((cu
->language
== language_ada
17918 || cu
->language
== language_fortran
)
17919 && (last_die
->tag
== DW_TAG_subprogram
17920 || last_die
->tag
== DW_TAG_lexical_block
))))
17923 parent_die
= last_die
;
17927 /* Otherwise we skip to the next sibling, if any. */
17928 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17930 /* Back to the top, do it again. */
17934 partial_die_info::partial_die_info (sect_offset sect_off_
,
17935 struct abbrev_info
*abbrev
)
17936 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17940 /* Read a minimal amount of information into the minimal die structure.
17941 INFO_PTR should point just after the initial uleb128 of a DIE. */
17944 partial_die_info::read (const struct die_reader_specs
*reader
,
17945 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17947 struct dwarf2_cu
*cu
= reader
->cu
;
17948 struct dwarf2_per_objfile
*dwarf2_per_objfile
17949 = cu
->per_cu
->dwarf2_per_objfile
;
17951 int has_low_pc_attr
= 0;
17952 int has_high_pc_attr
= 0;
17953 int high_pc_relative
= 0;
17955 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17956 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17958 bool need_reprocess
;
17959 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17960 info_ptr
, &need_reprocess
);
17961 /* String and address offsets that need to do the reprocessing have
17962 already been read at this point, so there is no need to wait until
17963 the loop terminates to do the reprocessing. */
17964 if (need_reprocess
)
17965 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17966 attribute
&attr
= attr_vec
[i
];
17967 /* Store the data if it is of an attribute we want to keep in a
17968 partial symbol table. */
17974 case DW_TAG_compile_unit
:
17975 case DW_TAG_partial_unit
:
17976 case DW_TAG_type_unit
:
17977 /* Compilation units have a DW_AT_name that is a filename, not
17978 a source language identifier. */
17979 case DW_TAG_enumeration_type
:
17980 case DW_TAG_enumerator
:
17981 /* These tags always have simple identifiers already; no need
17982 to canonicalize them. */
17983 name
= DW_STRING (&attr
);
17987 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17990 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
17995 case DW_AT_linkage_name
:
17996 case DW_AT_MIPS_linkage_name
:
17997 /* Note that both forms of linkage name might appear. We
17998 assume they will be the same, and we only store the last
18000 linkage_name
= DW_STRING (&attr
);
18003 has_low_pc_attr
= 1;
18004 lowpc
= attr
.value_as_address ();
18006 case DW_AT_high_pc
:
18007 has_high_pc_attr
= 1;
18008 highpc
= attr
.value_as_address ();
18009 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18010 high_pc_relative
= 1;
18012 case DW_AT_location
:
18013 /* Support the .debug_loc offsets. */
18014 if (attr
.form_is_block ())
18016 d
.locdesc
= DW_BLOCK (&attr
);
18018 else if (attr
.form_is_section_offset ())
18020 dwarf2_complex_location_expr_complaint ();
18024 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18025 "partial symbol information");
18028 case DW_AT_external
:
18029 is_external
= DW_UNSND (&attr
);
18031 case DW_AT_declaration
:
18032 is_declaration
= DW_UNSND (&attr
);
18037 case DW_AT_abstract_origin
:
18038 case DW_AT_specification
:
18039 case DW_AT_extension
:
18040 has_specification
= 1;
18041 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18042 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18043 || cu
->per_cu
->is_dwz
);
18045 case DW_AT_sibling
:
18046 /* Ignore absolute siblings, they might point outside of
18047 the current compile unit. */
18048 if (attr
.form
== DW_FORM_ref_addr
)
18049 complaint (_("ignoring absolute DW_AT_sibling"));
18052 const gdb_byte
*buffer
= reader
->buffer
;
18053 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18054 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18056 if (sibling_ptr
< info_ptr
)
18057 complaint (_("DW_AT_sibling points backwards"));
18058 else if (sibling_ptr
> reader
->buffer_end
)
18059 reader
->die_section
->overflow_complaint ();
18061 sibling
= sibling_ptr
;
18064 case DW_AT_byte_size
:
18067 case DW_AT_const_value
:
18068 has_const_value
= 1;
18070 case DW_AT_calling_convention
:
18071 /* DWARF doesn't provide a way to identify a program's source-level
18072 entry point. DW_AT_calling_convention attributes are only meant
18073 to describe functions' calling conventions.
18075 However, because it's a necessary piece of information in
18076 Fortran, and before DWARF 4 DW_CC_program was the only
18077 piece of debugging information whose definition refers to
18078 a 'main program' at all, several compilers marked Fortran
18079 main programs with DW_CC_program --- even when those
18080 functions use the standard calling conventions.
18082 Although DWARF now specifies a way to provide this
18083 information, we support this practice for backward
18085 if (DW_UNSND (&attr
) == DW_CC_program
18086 && cu
->language
== language_fortran
)
18087 main_subprogram
= 1;
18090 if (DW_UNSND (&attr
) == DW_INL_inlined
18091 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18092 may_be_inlined
= 1;
18096 if (tag
== DW_TAG_imported_unit
)
18098 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18099 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18100 || cu
->per_cu
->is_dwz
);
18104 case DW_AT_main_subprogram
:
18105 main_subprogram
= DW_UNSND (&attr
);
18110 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18111 but that requires a full DIE, so instead we just
18113 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18114 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18115 + (need_ranges_base
18119 /* Value of the DW_AT_ranges attribute is the offset in the
18120 .debug_ranges section. */
18121 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18132 /* For Ada, if both the name and the linkage name appear, we prefer
18133 the latter. This lets "catch exception" work better, regardless
18134 of the order in which the name and linkage name were emitted.
18135 Really, though, this is just a workaround for the fact that gdb
18136 doesn't store both the name and the linkage name. */
18137 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18138 name
= linkage_name
;
18140 if (high_pc_relative
)
18143 if (has_low_pc_attr
&& has_high_pc_attr
)
18145 /* When using the GNU linker, .gnu.linkonce. sections are used to
18146 eliminate duplicate copies of functions and vtables and such.
18147 The linker will arbitrarily choose one and discard the others.
18148 The AT_*_pc values for such functions refer to local labels in
18149 these sections. If the section from that file was discarded, the
18150 labels are not in the output, so the relocs get a value of 0.
18151 If this is a discarded function, mark the pc bounds as invalid,
18152 so that GDB will ignore it. */
18153 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18155 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18156 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18158 complaint (_("DW_AT_low_pc %s is zero "
18159 "for DIE at %s [in module %s]"),
18160 paddress (gdbarch
, lowpc
),
18161 sect_offset_str (sect_off
),
18162 objfile_name (objfile
));
18164 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18165 else if (lowpc
>= highpc
)
18167 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18168 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18170 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18171 "for DIE at %s [in module %s]"),
18172 paddress (gdbarch
, lowpc
),
18173 paddress (gdbarch
, highpc
),
18174 sect_offset_str (sect_off
),
18175 objfile_name (objfile
));
18184 /* Find a cached partial DIE at OFFSET in CU. */
18186 struct partial_die_info
*
18187 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18189 struct partial_die_info
*lookup_die
= NULL
;
18190 struct partial_die_info
part_die (sect_off
);
18192 lookup_die
= ((struct partial_die_info
*)
18193 htab_find_with_hash (partial_dies
, &part_die
,
18194 to_underlying (sect_off
)));
18199 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18200 except in the case of .debug_types DIEs which do not reference
18201 outside their CU (they do however referencing other types via
18202 DW_FORM_ref_sig8). */
18204 static const struct cu_partial_die_info
18205 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18207 struct dwarf2_per_objfile
*dwarf2_per_objfile
18208 = cu
->per_cu
->dwarf2_per_objfile
;
18209 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18210 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18211 struct partial_die_info
*pd
= NULL
;
18213 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18214 && cu
->header
.offset_in_cu_p (sect_off
))
18216 pd
= cu
->find_partial_die (sect_off
);
18219 /* We missed recording what we needed.
18220 Load all dies and try again. */
18221 per_cu
= cu
->per_cu
;
18225 /* TUs don't reference other CUs/TUs (except via type signatures). */
18226 if (cu
->per_cu
->is_debug_types
)
18228 error (_("Dwarf Error: Type Unit at offset %s contains"
18229 " external reference to offset %s [in module %s].\n"),
18230 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18231 bfd_get_filename (objfile
->obfd
));
18233 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18234 dwarf2_per_objfile
);
18236 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18237 load_partial_comp_unit (per_cu
);
18239 per_cu
->cu
->last_used
= 0;
18240 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18243 /* If we didn't find it, and not all dies have been loaded,
18244 load them all and try again. */
18246 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18248 per_cu
->load_all_dies
= 1;
18250 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18251 THIS_CU->cu may already be in use. So we can't just free it and
18252 replace its DIEs with the ones we read in. Instead, we leave those
18253 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18254 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18256 load_partial_comp_unit (per_cu
);
18258 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18262 internal_error (__FILE__
, __LINE__
,
18263 _("could not find partial DIE %s "
18264 "in cache [from module %s]\n"),
18265 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18266 return { per_cu
->cu
, pd
};
18269 /* See if we can figure out if the class lives in a namespace. We do
18270 this by looking for a member function; its demangled name will
18271 contain namespace info, if there is any. */
18274 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18275 struct dwarf2_cu
*cu
)
18277 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18278 what template types look like, because the demangler
18279 frequently doesn't give the same name as the debug info. We
18280 could fix this by only using the demangled name to get the
18281 prefix (but see comment in read_structure_type). */
18283 struct partial_die_info
*real_pdi
;
18284 struct partial_die_info
*child_pdi
;
18286 /* If this DIE (this DIE's specification, if any) has a parent, then
18287 we should not do this. We'll prepend the parent's fully qualified
18288 name when we create the partial symbol. */
18290 real_pdi
= struct_pdi
;
18291 while (real_pdi
->has_specification
)
18293 auto res
= find_partial_die (real_pdi
->spec_offset
,
18294 real_pdi
->spec_is_dwz
, cu
);
18295 real_pdi
= res
.pdi
;
18299 if (real_pdi
->die_parent
!= NULL
)
18302 for (child_pdi
= struct_pdi
->die_child
;
18304 child_pdi
= child_pdi
->die_sibling
)
18306 if (child_pdi
->tag
== DW_TAG_subprogram
18307 && child_pdi
->linkage_name
!= NULL
)
18309 gdb::unique_xmalloc_ptr
<char> actual_class_name
18310 (language_class_name_from_physname (cu
->language_defn
,
18311 child_pdi
->linkage_name
));
18312 if (actual_class_name
!= NULL
)
18314 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18315 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18323 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18325 /* Once we've fixed up a die, there's no point in doing so again.
18326 This also avoids a memory leak if we were to call
18327 guess_partial_die_structure_name multiple times. */
18331 /* If we found a reference attribute and the DIE has no name, try
18332 to find a name in the referred to DIE. */
18334 if (name
== NULL
&& has_specification
)
18336 struct partial_die_info
*spec_die
;
18338 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18339 spec_die
= res
.pdi
;
18342 spec_die
->fixup (cu
);
18344 if (spec_die
->name
)
18346 name
= spec_die
->name
;
18348 /* Copy DW_AT_external attribute if it is set. */
18349 if (spec_die
->is_external
)
18350 is_external
= spec_die
->is_external
;
18354 /* Set default names for some unnamed DIEs. */
18356 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18357 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18359 /* If there is no parent die to provide a namespace, and there are
18360 children, see if we can determine the namespace from their linkage
18362 if (cu
->language
== language_cplus
18363 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18364 && die_parent
== NULL
18366 && (tag
== DW_TAG_class_type
18367 || tag
== DW_TAG_structure_type
18368 || tag
== DW_TAG_union_type
))
18369 guess_partial_die_structure_name (this, cu
);
18371 /* GCC might emit a nameless struct or union that has a linkage
18372 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18374 && (tag
== DW_TAG_class_type
18375 || tag
== DW_TAG_interface_type
18376 || tag
== DW_TAG_structure_type
18377 || tag
== DW_TAG_union_type
)
18378 && linkage_name
!= NULL
)
18380 gdb::unique_xmalloc_ptr
<char> demangled
18381 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18382 if (demangled
!= nullptr)
18386 /* Strip any leading namespaces/classes, keep only the base name.
18387 DW_AT_name for named DIEs does not contain the prefixes. */
18388 base
= strrchr (demangled
.get (), ':');
18389 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18392 base
= demangled
.get ();
18394 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18395 name
= objfile
->intern (base
);
18402 /* Process the attributes that had to be skipped in the first round. These
18403 attributes are the ones that need str_offsets_base or addr_base attributes.
18404 They could not have been processed in the first round, because at the time
18405 the values of str_offsets_base or addr_base may not have been known. */
18406 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18407 struct attribute
*attr
)
18409 struct dwarf2_cu
*cu
= reader
->cu
;
18410 switch (attr
->form
)
18412 case DW_FORM_addrx
:
18413 case DW_FORM_GNU_addr_index
:
18414 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18417 case DW_FORM_strx1
:
18418 case DW_FORM_strx2
:
18419 case DW_FORM_strx3
:
18420 case DW_FORM_strx4
:
18421 case DW_FORM_GNU_str_index
:
18423 unsigned int str_index
= DW_UNSND (attr
);
18424 if (reader
->dwo_file
!= NULL
)
18426 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18427 DW_STRING_IS_CANONICAL (attr
) = 0;
18431 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18432 DW_STRING_IS_CANONICAL (attr
) = 0;
18437 gdb_assert_not_reached (_("Unexpected DWARF form."));
18441 /* Read an attribute value described by an attribute form. */
18443 static const gdb_byte
*
18444 read_attribute_value (const struct die_reader_specs
*reader
,
18445 struct attribute
*attr
, unsigned form
,
18446 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18447 bool *need_reprocess
)
18449 struct dwarf2_cu
*cu
= reader
->cu
;
18450 struct dwarf2_per_objfile
*dwarf2_per_objfile
18451 = cu
->per_cu
->dwarf2_per_objfile
;
18452 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18453 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18454 bfd
*abfd
= reader
->abfd
;
18455 struct comp_unit_head
*cu_header
= &cu
->header
;
18456 unsigned int bytes_read
;
18457 struct dwarf_block
*blk
;
18458 *need_reprocess
= false;
18460 attr
->form
= (enum dwarf_form
) form
;
18463 case DW_FORM_ref_addr
:
18464 if (cu
->header
.version
== 2)
18465 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18468 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18470 info_ptr
+= bytes_read
;
18472 case DW_FORM_GNU_ref_alt
:
18473 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18474 info_ptr
+= bytes_read
;
18477 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18478 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18479 info_ptr
+= bytes_read
;
18481 case DW_FORM_block2
:
18482 blk
= dwarf_alloc_block (cu
);
18483 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18485 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18486 info_ptr
+= blk
->size
;
18487 DW_BLOCK (attr
) = blk
;
18489 case DW_FORM_block4
:
18490 blk
= dwarf_alloc_block (cu
);
18491 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18493 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18494 info_ptr
+= blk
->size
;
18495 DW_BLOCK (attr
) = blk
;
18497 case DW_FORM_data2
:
18498 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18501 case DW_FORM_data4
:
18502 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18505 case DW_FORM_data8
:
18506 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18509 case DW_FORM_data16
:
18510 blk
= dwarf_alloc_block (cu
);
18512 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18514 DW_BLOCK (attr
) = blk
;
18516 case DW_FORM_sec_offset
:
18517 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18518 info_ptr
+= bytes_read
;
18520 case DW_FORM_string
:
18521 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18522 DW_STRING_IS_CANONICAL (attr
) = 0;
18523 info_ptr
+= bytes_read
;
18526 if (!cu
->per_cu
->is_dwz
)
18528 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18529 abfd
, info_ptr
, cu_header
,
18531 DW_STRING_IS_CANONICAL (attr
) = 0;
18532 info_ptr
+= bytes_read
;
18536 case DW_FORM_line_strp
:
18537 if (!cu
->per_cu
->is_dwz
)
18540 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18542 DW_STRING_IS_CANONICAL (attr
) = 0;
18543 info_ptr
+= bytes_read
;
18547 case DW_FORM_GNU_strp_alt
:
18549 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18550 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18553 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18554 DW_STRING_IS_CANONICAL (attr
) = 0;
18555 info_ptr
+= bytes_read
;
18558 case DW_FORM_exprloc
:
18559 case DW_FORM_block
:
18560 blk
= dwarf_alloc_block (cu
);
18561 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18562 info_ptr
+= bytes_read
;
18563 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18564 info_ptr
+= blk
->size
;
18565 DW_BLOCK (attr
) = blk
;
18567 case DW_FORM_block1
:
18568 blk
= dwarf_alloc_block (cu
);
18569 blk
->size
= read_1_byte (abfd
, info_ptr
);
18571 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18572 info_ptr
+= blk
->size
;
18573 DW_BLOCK (attr
) = blk
;
18575 case DW_FORM_data1
:
18576 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18580 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18583 case DW_FORM_flag_present
:
18584 DW_UNSND (attr
) = 1;
18586 case DW_FORM_sdata
:
18587 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18588 info_ptr
+= bytes_read
;
18590 case DW_FORM_udata
:
18591 case DW_FORM_rnglistx
:
18592 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18593 info_ptr
+= bytes_read
;
18596 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18597 + read_1_byte (abfd
, info_ptr
));
18601 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18602 + read_2_bytes (abfd
, info_ptr
));
18606 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18607 + read_4_bytes (abfd
, info_ptr
));
18611 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18612 + read_8_bytes (abfd
, info_ptr
));
18615 case DW_FORM_ref_sig8
:
18616 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18619 case DW_FORM_ref_udata
:
18620 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18621 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18622 info_ptr
+= bytes_read
;
18624 case DW_FORM_indirect
:
18625 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18626 info_ptr
+= bytes_read
;
18627 if (form
== DW_FORM_implicit_const
)
18629 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18630 info_ptr
+= bytes_read
;
18632 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18633 info_ptr
, need_reprocess
);
18635 case DW_FORM_implicit_const
:
18636 DW_SND (attr
) = implicit_const
;
18638 case DW_FORM_addrx
:
18639 case DW_FORM_GNU_addr_index
:
18640 *need_reprocess
= true;
18641 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18642 info_ptr
+= bytes_read
;
18645 case DW_FORM_strx1
:
18646 case DW_FORM_strx2
:
18647 case DW_FORM_strx3
:
18648 case DW_FORM_strx4
:
18649 case DW_FORM_GNU_str_index
:
18651 ULONGEST str_index
;
18652 if (form
== DW_FORM_strx1
)
18654 str_index
= read_1_byte (abfd
, info_ptr
);
18657 else if (form
== DW_FORM_strx2
)
18659 str_index
= read_2_bytes (abfd
, info_ptr
);
18662 else if (form
== DW_FORM_strx3
)
18664 str_index
= read_3_bytes (abfd
, info_ptr
);
18667 else if (form
== DW_FORM_strx4
)
18669 str_index
= read_4_bytes (abfd
, info_ptr
);
18674 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18675 info_ptr
+= bytes_read
;
18677 *need_reprocess
= true;
18678 DW_UNSND (attr
) = str_index
;
18682 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18683 dwarf_form_name (form
),
18684 bfd_get_filename (abfd
));
18688 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18689 attr
->form
= DW_FORM_GNU_ref_alt
;
18691 /* We have seen instances where the compiler tried to emit a byte
18692 size attribute of -1 which ended up being encoded as an unsigned
18693 0xffffffff. Although 0xffffffff is technically a valid size value,
18694 an object of this size seems pretty unlikely so we can relatively
18695 safely treat these cases as if the size attribute was invalid and
18696 treat them as zero by default. */
18697 if (attr
->name
== DW_AT_byte_size
18698 && form
== DW_FORM_data4
18699 && DW_UNSND (attr
) >= 0xffffffff)
18702 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18703 hex_string (DW_UNSND (attr
)));
18704 DW_UNSND (attr
) = 0;
18710 /* Read an attribute described by an abbreviated attribute. */
18712 static const gdb_byte
*
18713 read_attribute (const struct die_reader_specs
*reader
,
18714 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18715 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18717 attr
->name
= abbrev
->name
;
18718 return read_attribute_value (reader
, attr
, abbrev
->form
,
18719 abbrev
->implicit_const
, info_ptr
,
18723 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18725 static const char *
18726 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18727 LONGEST str_offset
)
18729 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18730 str_offset
, "DW_FORM_strp");
18733 /* Return pointer to string at .debug_str offset as read from BUF.
18734 BUF is assumed to be in a compilation unit described by CU_HEADER.
18735 Return *BYTES_READ_PTR count of bytes read from BUF. */
18737 static const char *
18738 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18739 const gdb_byte
*buf
,
18740 const struct comp_unit_head
*cu_header
,
18741 unsigned int *bytes_read_ptr
)
18743 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18745 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18751 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18752 const struct comp_unit_head
*cu_header
,
18753 unsigned int *bytes_read_ptr
)
18755 bfd
*abfd
= objfile
->obfd
;
18756 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18758 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18761 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18762 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18763 ADDR_SIZE is the size of addresses from the CU header. */
18766 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18767 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18770 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18771 bfd
*abfd
= objfile
->obfd
;
18772 const gdb_byte
*info_ptr
;
18773 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18775 dwarf2_per_objfile
->addr
.read (objfile
);
18776 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18777 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18778 objfile_name (objfile
));
18779 if (addr_base_or_zero
+ addr_index
* addr_size
18780 >= dwarf2_per_objfile
->addr
.size
)
18781 error (_("DW_FORM_addr_index pointing outside of "
18782 ".debug_addr section [in module %s]"),
18783 objfile_name (objfile
));
18784 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18785 + addr_base_or_zero
+ addr_index
* addr_size
);
18786 if (addr_size
== 4)
18787 return bfd_get_32 (abfd
, info_ptr
);
18789 return bfd_get_64 (abfd
, info_ptr
);
18792 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18795 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18797 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18798 cu
->addr_base
, cu
->header
.addr_size
);
18801 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18804 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18805 unsigned int *bytes_read
)
18807 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18808 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18810 return read_addr_index (cu
, addr_index
);
18816 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18818 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18819 struct dwarf2_cu
*cu
= per_cu
->cu
;
18820 gdb::optional
<ULONGEST
> addr_base
;
18823 /* We need addr_base and addr_size.
18824 If we don't have PER_CU->cu, we have to get it.
18825 Nasty, but the alternative is storing the needed info in PER_CU,
18826 which at this point doesn't seem justified: it's not clear how frequently
18827 it would get used and it would increase the size of every PER_CU.
18828 Entry points like dwarf2_per_cu_addr_size do a similar thing
18829 so we're not in uncharted territory here.
18830 Alas we need to be a bit more complicated as addr_base is contained
18833 We don't need to read the entire CU(/TU).
18834 We just need the header and top level die.
18836 IWBN to use the aging mechanism to let us lazily later discard the CU.
18837 For now we skip this optimization. */
18841 addr_base
= cu
->addr_base
;
18842 addr_size
= cu
->header
.addr_size
;
18846 cutu_reader
reader (per_cu
, NULL
, 0, false);
18847 addr_base
= reader
.cu
->addr_base
;
18848 addr_size
= reader
.cu
->header
.addr_size
;
18851 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18855 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18856 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18859 static const char *
18860 read_str_index (struct dwarf2_cu
*cu
,
18861 struct dwarf2_section_info
*str_section
,
18862 struct dwarf2_section_info
*str_offsets_section
,
18863 ULONGEST str_offsets_base
, ULONGEST str_index
)
18865 struct dwarf2_per_objfile
*dwarf2_per_objfile
18866 = cu
->per_cu
->dwarf2_per_objfile
;
18867 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18868 const char *objf_name
= objfile_name (objfile
);
18869 bfd
*abfd
= objfile
->obfd
;
18870 const gdb_byte
*info_ptr
;
18871 ULONGEST str_offset
;
18872 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18874 str_section
->read (objfile
);
18875 str_offsets_section
->read (objfile
);
18876 if (str_section
->buffer
== NULL
)
18877 error (_("%s used without %s section"
18878 " in CU at offset %s [in module %s]"),
18879 form_name
, str_section
->get_name (),
18880 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18881 if (str_offsets_section
->buffer
== NULL
)
18882 error (_("%s used without %s section"
18883 " in CU at offset %s [in module %s]"),
18884 form_name
, str_section
->get_name (),
18885 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18886 info_ptr
= (str_offsets_section
->buffer
18888 + str_index
* cu
->header
.offset_size
);
18889 if (cu
->header
.offset_size
== 4)
18890 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18892 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18893 if (str_offset
>= str_section
->size
)
18894 error (_("Offset from %s pointing outside of"
18895 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18896 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18897 return (const char *) (str_section
->buffer
+ str_offset
);
18900 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18902 static const char *
18903 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18905 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18906 ? reader
->cu
->header
.addr_size
: 0;
18907 return read_str_index (reader
->cu
,
18908 &reader
->dwo_file
->sections
.str
,
18909 &reader
->dwo_file
->sections
.str_offsets
,
18910 str_offsets_base
, str_index
);
18913 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18915 static const char *
18916 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18918 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18919 const char *objf_name
= objfile_name (objfile
);
18920 static const char form_name
[] = "DW_FORM_GNU_str_index";
18921 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18923 if (!cu
->str_offsets_base
.has_value ())
18924 error (_("%s used in Fission stub without %s"
18925 " in CU at offset 0x%lx [in module %s]"),
18926 form_name
, str_offsets_attr_name
,
18927 (long) cu
->header
.offset_size
, objf_name
);
18929 return read_str_index (cu
,
18930 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18931 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18932 *cu
->str_offsets_base
, str_index
);
18935 /* Return the length of an LEB128 number in BUF. */
18938 leb128_size (const gdb_byte
*buf
)
18940 const gdb_byte
*begin
= buf
;
18946 if ((byte
& 128) == 0)
18947 return buf
- begin
;
18952 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
18961 cu
->language
= language_c
;
18964 case DW_LANG_C_plus_plus
:
18965 case DW_LANG_C_plus_plus_11
:
18966 case DW_LANG_C_plus_plus_14
:
18967 cu
->language
= language_cplus
;
18970 cu
->language
= language_d
;
18972 case DW_LANG_Fortran77
:
18973 case DW_LANG_Fortran90
:
18974 case DW_LANG_Fortran95
:
18975 case DW_LANG_Fortran03
:
18976 case DW_LANG_Fortran08
:
18977 cu
->language
= language_fortran
;
18980 cu
->language
= language_go
;
18982 case DW_LANG_Mips_Assembler
:
18983 cu
->language
= language_asm
;
18985 case DW_LANG_Ada83
:
18986 case DW_LANG_Ada95
:
18987 cu
->language
= language_ada
;
18989 case DW_LANG_Modula2
:
18990 cu
->language
= language_m2
;
18992 case DW_LANG_Pascal83
:
18993 cu
->language
= language_pascal
;
18996 cu
->language
= language_objc
;
18999 case DW_LANG_Rust_old
:
19000 cu
->language
= language_rust
;
19002 case DW_LANG_Cobol74
:
19003 case DW_LANG_Cobol85
:
19005 cu
->language
= language_minimal
;
19008 cu
->language_defn
= language_def (cu
->language
);
19011 /* Return the named attribute or NULL if not there. */
19013 static struct attribute
*
19014 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19019 struct attribute
*spec
= NULL
;
19021 for (i
= 0; i
< die
->num_attrs
; ++i
)
19023 if (die
->attrs
[i
].name
== name
)
19024 return &die
->attrs
[i
];
19025 if (die
->attrs
[i
].name
== DW_AT_specification
19026 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19027 spec
= &die
->attrs
[i
];
19033 die
= follow_die_ref (die
, spec
, &cu
);
19039 /* Return the named attribute or NULL if not there,
19040 but do not follow DW_AT_specification, etc.
19041 This is for use in contexts where we're reading .debug_types dies.
19042 Following DW_AT_specification, DW_AT_abstract_origin will take us
19043 back up the chain, and we want to go down. */
19045 static struct attribute
*
19046 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19050 for (i
= 0; i
< die
->num_attrs
; ++i
)
19051 if (die
->attrs
[i
].name
== name
)
19052 return &die
->attrs
[i
];
19057 /* Return the string associated with a string-typed attribute, or NULL if it
19058 is either not found or is of an incorrect type. */
19060 static const char *
19061 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19063 struct attribute
*attr
;
19064 const char *str
= NULL
;
19066 attr
= dwarf2_attr (die
, name
, cu
);
19070 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19071 || attr
->form
== DW_FORM_string
19072 || attr
->form
== DW_FORM_strx
19073 || attr
->form
== DW_FORM_strx1
19074 || attr
->form
== DW_FORM_strx2
19075 || attr
->form
== DW_FORM_strx3
19076 || attr
->form
== DW_FORM_strx4
19077 || attr
->form
== DW_FORM_GNU_str_index
19078 || attr
->form
== DW_FORM_GNU_strp_alt
)
19079 str
= DW_STRING (attr
);
19081 complaint (_("string type expected for attribute %s for "
19082 "DIE at %s in module %s"),
19083 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19084 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19090 /* Return the dwo name or NULL if not present. If present, it is in either
19091 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19092 static const char *
19093 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19095 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19096 if (dwo_name
== nullptr)
19097 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19101 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19102 and holds a non-zero value. This function should only be used for
19103 DW_FORM_flag or DW_FORM_flag_present attributes. */
19106 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19108 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19110 return (attr
&& DW_UNSND (attr
));
19114 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19116 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19117 which value is non-zero. However, we have to be careful with
19118 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19119 (via dwarf2_flag_true_p) follows this attribute. So we may
19120 end up accidently finding a declaration attribute that belongs
19121 to a different DIE referenced by the specification attribute,
19122 even though the given DIE does not have a declaration attribute. */
19123 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19124 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19127 /* Return the die giving the specification for DIE, if there is
19128 one. *SPEC_CU is the CU containing DIE on input, and the CU
19129 containing the return value on output. If there is no
19130 specification, but there is an abstract origin, that is
19133 static struct die_info
*
19134 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19136 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19139 if (spec_attr
== NULL
)
19140 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19142 if (spec_attr
== NULL
)
19145 return follow_die_ref (die
, spec_attr
, spec_cu
);
19148 /* Stub for free_line_header to match void * callback types. */
19151 free_line_header_voidp (void *arg
)
19153 struct line_header
*lh
= (struct line_header
*) arg
;
19158 /* A convenience function to find the proper .debug_line section for a CU. */
19160 static struct dwarf2_section_info
*
19161 get_debug_line_section (struct dwarf2_cu
*cu
)
19163 struct dwarf2_section_info
*section
;
19164 struct dwarf2_per_objfile
*dwarf2_per_objfile
19165 = cu
->per_cu
->dwarf2_per_objfile
;
19167 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19169 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19170 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19171 else if (cu
->per_cu
->is_dwz
)
19173 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19175 section
= &dwz
->line
;
19178 section
= &dwarf2_per_objfile
->line
;
19183 /* Read the statement program header starting at OFFSET in
19184 .debug_line, or .debug_line.dwo. Return a pointer
19185 to a struct line_header, allocated using xmalloc.
19186 Returns NULL if there is a problem reading the header, e.g., if it
19187 has a version we don't understand.
19189 NOTE: the strings in the include directory and file name tables of
19190 the returned object point into the dwarf line section buffer,
19191 and must not be freed. */
19193 static line_header_up
19194 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19196 struct dwarf2_section_info
*section
;
19197 struct dwarf2_per_objfile
*dwarf2_per_objfile
19198 = cu
->per_cu
->dwarf2_per_objfile
;
19200 section
= get_debug_line_section (cu
);
19201 section
->read (dwarf2_per_objfile
->objfile
);
19202 if (section
->buffer
== NULL
)
19204 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19205 complaint (_("missing .debug_line.dwo section"));
19207 complaint (_("missing .debug_line section"));
19211 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19212 dwarf2_per_objfile
, section
,
19216 /* Subroutine of dwarf_decode_lines to simplify it.
19217 Return the file name of the psymtab for the given file_entry.
19218 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19219 If space for the result is malloc'd, *NAME_HOLDER will be set.
19220 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19222 static const char *
19223 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19224 const dwarf2_psymtab
*pst
,
19225 const char *comp_dir
,
19226 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19228 const char *include_name
= fe
.name
;
19229 const char *include_name_to_compare
= include_name
;
19230 const char *pst_filename
;
19233 const char *dir_name
= fe
.include_dir (lh
);
19235 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19236 if (!IS_ABSOLUTE_PATH (include_name
)
19237 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19239 /* Avoid creating a duplicate psymtab for PST.
19240 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19241 Before we do the comparison, however, we need to account
19242 for DIR_NAME and COMP_DIR.
19243 First prepend dir_name (if non-NULL). If we still don't
19244 have an absolute path prepend comp_dir (if non-NULL).
19245 However, the directory we record in the include-file's
19246 psymtab does not contain COMP_DIR (to match the
19247 corresponding symtab(s)).
19252 bash$ gcc -g ./hello.c
19253 include_name = "hello.c"
19255 DW_AT_comp_dir = comp_dir = "/tmp"
19256 DW_AT_name = "./hello.c"
19260 if (dir_name
!= NULL
)
19262 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19263 include_name
, (char *) NULL
));
19264 include_name
= name_holder
->get ();
19265 include_name_to_compare
= include_name
;
19267 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19269 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19270 include_name
, (char *) NULL
));
19271 include_name_to_compare
= hold_compare
.get ();
19275 pst_filename
= pst
->filename
;
19276 gdb::unique_xmalloc_ptr
<char> copied_name
;
19277 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19279 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19280 pst_filename
, (char *) NULL
));
19281 pst_filename
= copied_name
.get ();
19284 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19288 return include_name
;
19291 /* State machine to track the state of the line number program. */
19293 class lnp_state_machine
19296 /* Initialize a machine state for the start of a line number
19298 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19299 bool record_lines_p
);
19301 file_entry
*current_file ()
19303 /* lh->file_names is 0-based, but the file name numbers in the
19304 statement program are 1-based. */
19305 return m_line_header
->file_name_at (m_file
);
19308 /* Record the line in the state machine. END_SEQUENCE is true if
19309 we're processing the end of a sequence. */
19310 void record_line (bool end_sequence
);
19312 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19313 nop-out rest of the lines in this sequence. */
19314 void check_line_address (struct dwarf2_cu
*cu
,
19315 const gdb_byte
*line_ptr
,
19316 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19318 void handle_set_discriminator (unsigned int discriminator
)
19320 m_discriminator
= discriminator
;
19321 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19324 /* Handle DW_LNE_set_address. */
19325 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19328 address
+= baseaddr
;
19329 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19332 /* Handle DW_LNS_advance_pc. */
19333 void handle_advance_pc (CORE_ADDR adjust
);
19335 /* Handle a special opcode. */
19336 void handle_special_opcode (unsigned char op_code
);
19338 /* Handle DW_LNS_advance_line. */
19339 void handle_advance_line (int line_delta
)
19341 advance_line (line_delta
);
19344 /* Handle DW_LNS_set_file. */
19345 void handle_set_file (file_name_index file
);
19347 /* Handle DW_LNS_negate_stmt. */
19348 void handle_negate_stmt ()
19350 m_is_stmt
= !m_is_stmt
;
19353 /* Handle DW_LNS_const_add_pc. */
19354 void handle_const_add_pc ();
19356 /* Handle DW_LNS_fixed_advance_pc. */
19357 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19359 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19363 /* Handle DW_LNS_copy. */
19364 void handle_copy ()
19366 record_line (false);
19367 m_discriminator
= 0;
19370 /* Handle DW_LNE_end_sequence. */
19371 void handle_end_sequence ()
19373 m_currently_recording_lines
= true;
19377 /* Advance the line by LINE_DELTA. */
19378 void advance_line (int line_delta
)
19380 m_line
+= line_delta
;
19382 if (line_delta
!= 0)
19383 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19386 struct dwarf2_cu
*m_cu
;
19388 gdbarch
*m_gdbarch
;
19390 /* True if we're recording lines.
19391 Otherwise we're building partial symtabs and are just interested in
19392 finding include files mentioned by the line number program. */
19393 bool m_record_lines_p
;
19395 /* The line number header. */
19396 line_header
*m_line_header
;
19398 /* These are part of the standard DWARF line number state machine,
19399 and initialized according to the DWARF spec. */
19401 unsigned char m_op_index
= 0;
19402 /* The line table index of the current file. */
19403 file_name_index m_file
= 1;
19404 unsigned int m_line
= 1;
19406 /* These are initialized in the constructor. */
19408 CORE_ADDR m_address
;
19410 unsigned int m_discriminator
;
19412 /* Additional bits of state we need to track. */
19414 /* The last file that we called dwarf2_start_subfile for.
19415 This is only used for TLLs. */
19416 unsigned int m_last_file
= 0;
19417 /* The last file a line number was recorded for. */
19418 struct subfile
*m_last_subfile
= NULL
;
19420 /* When true, record the lines we decode. */
19421 bool m_currently_recording_lines
= false;
19423 /* The last line number that was recorded, used to coalesce
19424 consecutive entries for the same line. This can happen, for
19425 example, when discriminators are present. PR 17276. */
19426 unsigned int m_last_line
= 0;
19427 bool m_line_has_non_zero_discriminator
= false;
19431 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19433 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19434 / m_line_header
->maximum_ops_per_instruction
)
19435 * m_line_header
->minimum_instruction_length
);
19436 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19437 m_op_index
= ((m_op_index
+ adjust
)
19438 % m_line_header
->maximum_ops_per_instruction
);
19442 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19444 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19445 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19446 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19447 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19448 / m_line_header
->maximum_ops_per_instruction
)
19449 * m_line_header
->minimum_instruction_length
);
19450 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19451 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19452 % m_line_header
->maximum_ops_per_instruction
);
19454 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19455 advance_line (line_delta
);
19456 record_line (false);
19457 m_discriminator
= 0;
19461 lnp_state_machine::handle_set_file (file_name_index file
)
19465 const file_entry
*fe
= current_file ();
19467 dwarf2_debug_line_missing_file_complaint ();
19468 else if (m_record_lines_p
)
19470 const char *dir
= fe
->include_dir (m_line_header
);
19472 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19473 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19474 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19479 lnp_state_machine::handle_const_add_pc ()
19482 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19485 = (((m_op_index
+ adjust
)
19486 / m_line_header
->maximum_ops_per_instruction
)
19487 * m_line_header
->minimum_instruction_length
);
19489 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19490 m_op_index
= ((m_op_index
+ adjust
)
19491 % m_line_header
->maximum_ops_per_instruction
);
19494 /* Return non-zero if we should add LINE to the line number table.
19495 LINE is the line to add, LAST_LINE is the last line that was added,
19496 LAST_SUBFILE is the subfile for LAST_LINE.
19497 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19498 had a non-zero discriminator.
19500 We have to be careful in the presence of discriminators.
19501 E.g., for this line:
19503 for (i = 0; i < 100000; i++);
19505 clang can emit four line number entries for that one line,
19506 each with a different discriminator.
19507 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19509 However, we want gdb to coalesce all four entries into one.
19510 Otherwise the user could stepi into the middle of the line and
19511 gdb would get confused about whether the pc really was in the
19512 middle of the line.
19514 Things are further complicated by the fact that two consecutive
19515 line number entries for the same line is a heuristic used by gcc
19516 to denote the end of the prologue. So we can't just discard duplicate
19517 entries, we have to be selective about it. The heuristic we use is
19518 that we only collapse consecutive entries for the same line if at least
19519 one of those entries has a non-zero discriminator. PR 17276.
19521 Note: Addresses in the line number state machine can never go backwards
19522 within one sequence, thus this coalescing is ok. */
19525 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19526 unsigned int line
, unsigned int last_line
,
19527 int line_has_non_zero_discriminator
,
19528 struct subfile
*last_subfile
)
19530 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19532 if (line
!= last_line
)
19534 /* Same line for the same file that we've seen already.
19535 As a last check, for pr 17276, only record the line if the line
19536 has never had a non-zero discriminator. */
19537 if (!line_has_non_zero_discriminator
)
19542 /* Use the CU's builder to record line number LINE beginning at
19543 address ADDRESS in the line table of subfile SUBFILE. */
19546 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19547 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19548 struct dwarf2_cu
*cu
)
19550 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19552 if (dwarf_line_debug
)
19554 fprintf_unfiltered (gdb_stdlog
,
19555 "Recording line %u, file %s, address %s\n",
19556 line
, lbasename (subfile
->name
),
19557 paddress (gdbarch
, address
));
19561 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19564 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19565 Mark the end of a set of line number records.
19566 The arguments are the same as for dwarf_record_line_1.
19567 If SUBFILE is NULL the request is ignored. */
19570 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19571 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19573 if (subfile
== NULL
)
19576 if (dwarf_line_debug
)
19578 fprintf_unfiltered (gdb_stdlog
,
19579 "Finishing current line, file %s, address %s\n",
19580 lbasename (subfile
->name
),
19581 paddress (gdbarch
, address
));
19584 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19588 lnp_state_machine::record_line (bool end_sequence
)
19590 if (dwarf_line_debug
)
19592 fprintf_unfiltered (gdb_stdlog
,
19593 "Processing actual line %u: file %u,"
19594 " address %s, is_stmt %u, discrim %u%s\n",
19596 paddress (m_gdbarch
, m_address
),
19597 m_is_stmt
, m_discriminator
,
19598 (end_sequence
? "\t(end sequence)" : ""));
19601 file_entry
*fe
= current_file ();
19604 dwarf2_debug_line_missing_file_complaint ();
19605 /* For now we ignore lines not starting on an instruction boundary.
19606 But not when processing end_sequence for compatibility with the
19607 previous version of the code. */
19608 else if (m_op_index
== 0 || end_sequence
)
19610 fe
->included_p
= 1;
19611 if (m_record_lines_p
)
19613 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19616 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19617 m_currently_recording_lines
? m_cu
: nullptr);
19622 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19624 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19625 m_line_has_non_zero_discriminator
,
19628 buildsym_compunit
*builder
= m_cu
->get_builder ();
19629 dwarf_record_line_1 (m_gdbarch
,
19630 builder
->get_current_subfile (),
19631 m_line
, m_address
, is_stmt
,
19632 m_currently_recording_lines
? m_cu
: nullptr);
19634 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19635 m_last_line
= m_line
;
19641 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19642 line_header
*lh
, bool record_lines_p
)
19646 m_record_lines_p
= record_lines_p
;
19647 m_line_header
= lh
;
19649 m_currently_recording_lines
= true;
19651 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19652 was a line entry for it so that the backend has a chance to adjust it
19653 and also record it in case it needs it. This is currently used by MIPS
19654 code, cf. `mips_adjust_dwarf2_line'. */
19655 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19656 m_is_stmt
= lh
->default_is_stmt
;
19657 m_discriminator
= 0;
19661 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19662 const gdb_byte
*line_ptr
,
19663 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19665 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19666 the pc range of the CU. However, we restrict the test to only ADDRESS
19667 values of zero to preserve GDB's previous behaviour which is to handle
19668 the specific case of a function being GC'd by the linker. */
19670 if (address
== 0 && address
< unrelocated_lowpc
)
19672 /* This line table is for a function which has been
19673 GCd by the linker. Ignore it. PR gdb/12528 */
19675 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19676 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19678 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19679 line_offset
, objfile_name (objfile
));
19680 m_currently_recording_lines
= false;
19681 /* Note: m_currently_recording_lines is left as false until we see
19682 DW_LNE_end_sequence. */
19686 /* Subroutine of dwarf_decode_lines to simplify it.
19687 Process the line number information in LH.
19688 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19689 program in order to set included_p for every referenced header. */
19692 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19693 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19695 const gdb_byte
*line_ptr
, *extended_end
;
19696 const gdb_byte
*line_end
;
19697 unsigned int bytes_read
, extended_len
;
19698 unsigned char op_code
, extended_op
;
19699 CORE_ADDR baseaddr
;
19700 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19701 bfd
*abfd
= objfile
->obfd
;
19702 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19703 /* True if we're recording line info (as opposed to building partial
19704 symtabs and just interested in finding include files mentioned by
19705 the line number program). */
19706 bool record_lines_p
= !decode_for_pst_p
;
19708 baseaddr
= objfile
->text_section_offset ();
19710 line_ptr
= lh
->statement_program_start
;
19711 line_end
= lh
->statement_program_end
;
19713 /* Read the statement sequences until there's nothing left. */
19714 while (line_ptr
< line_end
)
19716 /* The DWARF line number program state machine. Reset the state
19717 machine at the start of each sequence. */
19718 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19719 bool end_sequence
= false;
19721 if (record_lines_p
)
19723 /* Start a subfile for the current file of the state
19725 const file_entry
*fe
= state_machine
.current_file ();
19728 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19731 /* Decode the table. */
19732 while (line_ptr
< line_end
&& !end_sequence
)
19734 op_code
= read_1_byte (abfd
, line_ptr
);
19737 if (op_code
>= lh
->opcode_base
)
19739 /* Special opcode. */
19740 state_machine
.handle_special_opcode (op_code
);
19742 else switch (op_code
)
19744 case DW_LNS_extended_op
:
19745 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19747 line_ptr
+= bytes_read
;
19748 extended_end
= line_ptr
+ extended_len
;
19749 extended_op
= read_1_byte (abfd
, line_ptr
);
19751 switch (extended_op
)
19753 case DW_LNE_end_sequence
:
19754 state_machine
.handle_end_sequence ();
19755 end_sequence
= true;
19757 case DW_LNE_set_address
:
19760 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19761 line_ptr
+= bytes_read
;
19763 state_machine
.check_line_address (cu
, line_ptr
,
19764 lowpc
- baseaddr
, address
);
19765 state_machine
.handle_set_address (baseaddr
, address
);
19768 case DW_LNE_define_file
:
19770 const char *cur_file
;
19771 unsigned int mod_time
, length
;
19774 cur_file
= read_direct_string (abfd
, line_ptr
,
19776 line_ptr
+= bytes_read
;
19777 dindex
= (dir_index
)
19778 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19779 line_ptr
+= bytes_read
;
19781 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19782 line_ptr
+= bytes_read
;
19784 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19785 line_ptr
+= bytes_read
;
19786 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19789 case DW_LNE_set_discriminator
:
19791 /* The discriminator is not interesting to the
19792 debugger; just ignore it. We still need to
19793 check its value though:
19794 if there are consecutive entries for the same
19795 (non-prologue) line we want to coalesce them.
19798 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19799 line_ptr
+= bytes_read
;
19801 state_machine
.handle_set_discriminator (discr
);
19805 complaint (_("mangled .debug_line section"));
19808 /* Make sure that we parsed the extended op correctly. If e.g.
19809 we expected a different address size than the producer used,
19810 we may have read the wrong number of bytes. */
19811 if (line_ptr
!= extended_end
)
19813 complaint (_("mangled .debug_line section"));
19818 state_machine
.handle_copy ();
19820 case DW_LNS_advance_pc
:
19823 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19824 line_ptr
+= bytes_read
;
19826 state_machine
.handle_advance_pc (adjust
);
19829 case DW_LNS_advance_line
:
19832 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19833 line_ptr
+= bytes_read
;
19835 state_machine
.handle_advance_line (line_delta
);
19838 case DW_LNS_set_file
:
19840 file_name_index file
19841 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19843 line_ptr
+= bytes_read
;
19845 state_machine
.handle_set_file (file
);
19848 case DW_LNS_set_column
:
19849 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19850 line_ptr
+= bytes_read
;
19852 case DW_LNS_negate_stmt
:
19853 state_machine
.handle_negate_stmt ();
19855 case DW_LNS_set_basic_block
:
19857 /* Add to the address register of the state machine the
19858 address increment value corresponding to special opcode
19859 255. I.e., this value is scaled by the minimum
19860 instruction length since special opcode 255 would have
19861 scaled the increment. */
19862 case DW_LNS_const_add_pc
:
19863 state_machine
.handle_const_add_pc ();
19865 case DW_LNS_fixed_advance_pc
:
19867 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19870 state_machine
.handle_fixed_advance_pc (addr_adj
);
19875 /* Unknown standard opcode, ignore it. */
19878 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19880 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19881 line_ptr
+= bytes_read
;
19888 dwarf2_debug_line_missing_end_sequence_complaint ();
19890 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19891 in which case we still finish recording the last line). */
19892 state_machine
.record_line (true);
19896 /* Decode the Line Number Program (LNP) for the given line_header
19897 structure and CU. The actual information extracted and the type
19898 of structures created from the LNP depends on the value of PST.
19900 1. If PST is NULL, then this procedure uses the data from the program
19901 to create all necessary symbol tables, and their linetables.
19903 2. If PST is not NULL, this procedure reads the program to determine
19904 the list of files included by the unit represented by PST, and
19905 builds all the associated partial symbol tables.
19907 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19908 It is used for relative paths in the line table.
19909 NOTE: When processing partial symtabs (pst != NULL),
19910 comp_dir == pst->dirname.
19912 NOTE: It is important that psymtabs have the same file name (via strcmp)
19913 as the corresponding symtab. Since COMP_DIR is not used in the name of the
19914 symtab we don't use it in the name of the psymtabs we create.
19915 E.g. expand_line_sal requires this when finding psymtabs to expand.
19916 A good testcase for this is mb-inline.exp.
19918 LOWPC is the lowest address in CU (or 0 if not known).
19920 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
19921 for its PC<->lines mapping information. Otherwise only the filename
19922 table is read in. */
19925 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
19926 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
19927 CORE_ADDR lowpc
, int decode_mapping
)
19929 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19930 const int decode_for_pst_p
= (pst
!= NULL
);
19932 if (decode_mapping
)
19933 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
19935 if (decode_for_pst_p
)
19937 /* Now that we're done scanning the Line Header Program, we can
19938 create the psymtab of each included file. */
19939 for (auto &file_entry
: lh
->file_names ())
19940 if (file_entry
.included_p
== 1)
19942 gdb::unique_xmalloc_ptr
<char> name_holder
;
19943 const char *include_name
=
19944 psymtab_include_file_name (lh
, file_entry
, pst
,
19945 comp_dir
, &name_holder
);
19946 if (include_name
!= NULL
)
19947 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
19952 /* Make sure a symtab is created for every file, even files
19953 which contain only variables (i.e. no code with associated
19955 buildsym_compunit
*builder
= cu
->get_builder ();
19956 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
19958 for (auto &fe
: lh
->file_names ())
19960 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
19961 if (builder
->get_current_subfile ()->symtab
== NULL
)
19963 builder
->get_current_subfile ()->symtab
19964 = allocate_symtab (cust
,
19965 builder
->get_current_subfile ()->name
);
19967 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
19972 /* Start a subfile for DWARF. FILENAME is the name of the file and
19973 DIRNAME the name of the source directory which contains FILENAME
19974 or NULL if not known.
19975 This routine tries to keep line numbers from identical absolute and
19976 relative file names in a common subfile.
19978 Using the `list' example from the GDB testsuite, which resides in
19979 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
19980 of /srcdir/list0.c yields the following debugging information for list0.c:
19982 DW_AT_name: /srcdir/list0.c
19983 DW_AT_comp_dir: /compdir
19984 files.files[0].name: list0.h
19985 files.files[0].dir: /srcdir
19986 files.files[1].name: list0.c
19987 files.files[1].dir: /srcdir
19989 The line number information for list0.c has to end up in a single
19990 subfile, so that `break /srcdir/list0.c:1' works as expected.
19991 start_subfile will ensure that this happens provided that we pass the
19992 concatenation of files.files[1].dir and files.files[1].name as the
19996 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
19997 const char *dirname
)
19999 gdb::unique_xmalloc_ptr
<char> copy
;
20001 /* In order not to lose the line information directory,
20002 we concatenate it to the filename when it makes sense.
20003 Note that the Dwarf3 standard says (speaking of filenames in line
20004 information): ``The directory index is ignored for file names
20005 that represent full path names''. Thus ignoring dirname in the
20006 `else' branch below isn't an issue. */
20008 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20010 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20011 filename
= copy
.get ();
20014 cu
->get_builder ()->start_subfile (filename
);
20017 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20018 buildsym_compunit constructor. */
20020 struct compunit_symtab
*
20021 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20024 gdb_assert (m_builder
== nullptr);
20026 m_builder
.reset (new struct buildsym_compunit
20027 (per_cu
->dwarf2_per_objfile
->objfile
,
20028 name
, comp_dir
, language
, low_pc
));
20030 list_in_scope
= get_builder ()->get_file_symbols ();
20032 get_builder ()->record_debugformat ("DWARF 2");
20033 get_builder ()->record_producer (producer
);
20035 processing_has_namespace_info
= false;
20037 return get_builder ()->get_compunit_symtab ();
20041 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20042 struct dwarf2_cu
*cu
)
20044 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20045 struct comp_unit_head
*cu_header
= &cu
->header
;
20047 /* NOTE drow/2003-01-30: There used to be a comment and some special
20048 code here to turn a symbol with DW_AT_external and a
20049 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20050 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20051 with some versions of binutils) where shared libraries could have
20052 relocations against symbols in their debug information - the
20053 minimal symbol would have the right address, but the debug info
20054 would not. It's no longer necessary, because we will explicitly
20055 apply relocations when we read in the debug information now. */
20057 /* A DW_AT_location attribute with no contents indicates that a
20058 variable has been optimized away. */
20059 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20061 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20065 /* Handle one degenerate form of location expression specially, to
20066 preserve GDB's previous behavior when section offsets are
20067 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20068 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20070 if (attr
->form_is_block ()
20071 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20072 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20073 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20074 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20075 && (DW_BLOCK (attr
)->size
20076 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20078 unsigned int dummy
;
20080 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20081 SET_SYMBOL_VALUE_ADDRESS
20082 (sym
, cu
->header
.read_address (objfile
->obfd
,
20083 DW_BLOCK (attr
)->data
+ 1,
20086 SET_SYMBOL_VALUE_ADDRESS
20087 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20089 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20090 fixup_symbol_section (sym
, objfile
);
20091 SET_SYMBOL_VALUE_ADDRESS
20093 SYMBOL_VALUE_ADDRESS (sym
)
20094 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20098 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20099 expression evaluator, and use LOC_COMPUTED only when necessary
20100 (i.e. when the value of a register or memory location is
20101 referenced, or a thread-local block, etc.). Then again, it might
20102 not be worthwhile. I'm assuming that it isn't unless performance
20103 or memory numbers show me otherwise. */
20105 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20107 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20108 cu
->has_loclist
= true;
20111 /* Given a pointer to a DWARF information entry, figure out if we need
20112 to make a symbol table entry for it, and if so, create a new entry
20113 and return a pointer to it.
20114 If TYPE is NULL, determine symbol type from the die, otherwise
20115 used the passed type.
20116 If SPACE is not NULL, use it to hold the new symbol. If it is
20117 NULL, allocate a new symbol on the objfile's obstack. */
20119 static struct symbol
*
20120 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20121 struct symbol
*space
)
20123 struct dwarf2_per_objfile
*dwarf2_per_objfile
20124 = cu
->per_cu
->dwarf2_per_objfile
;
20125 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20126 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20127 struct symbol
*sym
= NULL
;
20129 struct attribute
*attr
= NULL
;
20130 struct attribute
*attr2
= NULL
;
20131 CORE_ADDR baseaddr
;
20132 struct pending
**list_to_add
= NULL
;
20134 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20136 baseaddr
= objfile
->text_section_offset ();
20138 name
= dwarf2_name (die
, cu
);
20141 const char *linkagename
;
20142 int suppress_add
= 0;
20147 sym
= allocate_symbol (objfile
);
20148 OBJSTAT (objfile
, n_syms
++);
20150 /* Cache this symbol's name and the name's demangled form (if any). */
20151 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20152 linkagename
= dwarf2_physname (name
, die
, cu
);
20153 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20155 /* Fortran does not have mangling standard and the mangling does differ
20156 between gfortran, iFort etc. */
20157 if (cu
->language
== language_fortran
20158 && symbol_get_demangled_name (sym
) == NULL
)
20159 symbol_set_demangled_name (sym
,
20160 dwarf2_full_name (name
, die
, cu
),
20163 /* Default assumptions.
20164 Use the passed type or decode it from the die. */
20165 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20166 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20168 SYMBOL_TYPE (sym
) = type
;
20170 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20171 attr
= dwarf2_attr (die
,
20172 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20174 if (attr
!= nullptr)
20176 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20179 attr
= dwarf2_attr (die
,
20180 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20182 if (attr
!= nullptr)
20184 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20185 struct file_entry
*fe
;
20187 if (cu
->line_header
!= NULL
)
20188 fe
= cu
->line_header
->file_name_at (file_index
);
20193 complaint (_("file index out of range"));
20195 symbol_set_symtab (sym
, fe
->symtab
);
20201 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20202 if (attr
!= nullptr)
20206 addr
= attr
->value_as_address ();
20207 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20208 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20210 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20211 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20212 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20213 add_symbol_to_list (sym
, cu
->list_in_scope
);
20215 case DW_TAG_subprogram
:
20216 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20218 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20219 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20220 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20221 || cu
->language
== language_ada
20222 || cu
->language
== language_fortran
)
20224 /* Subprograms marked external are stored as a global symbol.
20225 Ada and Fortran subprograms, whether marked external or
20226 not, are always stored as a global symbol, because we want
20227 to be able to access them globally. For instance, we want
20228 to be able to break on a nested subprogram without having
20229 to specify the context. */
20230 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20234 list_to_add
= cu
->list_in_scope
;
20237 case DW_TAG_inlined_subroutine
:
20238 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20240 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20241 SYMBOL_INLINED (sym
) = 1;
20242 list_to_add
= cu
->list_in_scope
;
20244 case DW_TAG_template_value_param
:
20246 /* Fall through. */
20247 case DW_TAG_constant
:
20248 case DW_TAG_variable
:
20249 case DW_TAG_member
:
20250 /* Compilation with minimal debug info may result in
20251 variables with missing type entries. Change the
20252 misleading `void' type to something sensible. */
20253 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20254 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20256 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20257 /* In the case of DW_TAG_member, we should only be called for
20258 static const members. */
20259 if (die
->tag
== DW_TAG_member
)
20261 /* dwarf2_add_field uses die_is_declaration,
20262 so we do the same. */
20263 gdb_assert (die_is_declaration (die
, cu
));
20266 if (attr
!= nullptr)
20268 dwarf2_const_value (attr
, sym
, cu
);
20269 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20272 if (attr2
&& (DW_UNSND (attr2
) != 0))
20273 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20275 list_to_add
= cu
->list_in_scope
;
20279 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20280 if (attr
!= nullptr)
20282 var_decode_location (attr
, sym
, cu
);
20283 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20285 /* Fortran explicitly imports any global symbols to the local
20286 scope by DW_TAG_common_block. */
20287 if (cu
->language
== language_fortran
&& die
->parent
20288 && die
->parent
->tag
== DW_TAG_common_block
)
20291 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20292 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20293 && !dwarf2_per_objfile
->has_section_at_zero
)
20295 /* When a static variable is eliminated by the linker,
20296 the corresponding debug information is not stripped
20297 out, but the variable address is set to null;
20298 do not add such variables into symbol table. */
20300 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20302 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20303 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20304 && dwarf2_per_objfile
->can_copy
)
20306 /* A global static variable might be subject to
20307 copy relocation. We first check for a local
20308 minsym, though, because maybe the symbol was
20309 marked hidden, in which case this would not
20311 bound_minimal_symbol found
20312 = (lookup_minimal_symbol_linkage
20313 (sym
->linkage_name (), objfile
));
20314 if (found
.minsym
!= nullptr)
20315 sym
->maybe_copied
= 1;
20318 /* A variable with DW_AT_external is never static,
20319 but it may be block-scoped. */
20321 = ((cu
->list_in_scope
20322 == cu
->get_builder ()->get_file_symbols ())
20323 ? cu
->get_builder ()->get_global_symbols ()
20324 : cu
->list_in_scope
);
20327 list_to_add
= cu
->list_in_scope
;
20331 /* We do not know the address of this symbol.
20332 If it is an external symbol and we have type information
20333 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20334 The address of the variable will then be determined from
20335 the minimal symbol table whenever the variable is
20337 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20339 /* Fortran explicitly imports any global symbols to the local
20340 scope by DW_TAG_common_block. */
20341 if (cu
->language
== language_fortran
&& die
->parent
20342 && die
->parent
->tag
== DW_TAG_common_block
)
20344 /* SYMBOL_CLASS doesn't matter here because
20345 read_common_block is going to reset it. */
20347 list_to_add
= cu
->list_in_scope
;
20349 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20350 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20352 /* A variable with DW_AT_external is never static, but it
20353 may be block-scoped. */
20355 = ((cu
->list_in_scope
20356 == cu
->get_builder ()->get_file_symbols ())
20357 ? cu
->get_builder ()->get_global_symbols ()
20358 : cu
->list_in_scope
);
20360 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20362 else if (!die_is_declaration (die
, cu
))
20364 /* Use the default LOC_OPTIMIZED_OUT class. */
20365 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20367 list_to_add
= cu
->list_in_scope
;
20371 case DW_TAG_formal_parameter
:
20373 /* If we are inside a function, mark this as an argument. If
20374 not, we might be looking at an argument to an inlined function
20375 when we do not have enough information to show inlined frames;
20376 pretend it's a local variable in that case so that the user can
20378 struct context_stack
*curr
20379 = cu
->get_builder ()->get_current_context_stack ();
20380 if (curr
!= nullptr && curr
->name
!= nullptr)
20381 SYMBOL_IS_ARGUMENT (sym
) = 1;
20382 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20383 if (attr
!= nullptr)
20385 var_decode_location (attr
, sym
, cu
);
20387 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20388 if (attr
!= nullptr)
20390 dwarf2_const_value (attr
, sym
, cu
);
20393 list_to_add
= cu
->list_in_scope
;
20396 case DW_TAG_unspecified_parameters
:
20397 /* From varargs functions; gdb doesn't seem to have any
20398 interest in this information, so just ignore it for now.
20401 case DW_TAG_template_type_param
:
20403 /* Fall through. */
20404 case DW_TAG_class_type
:
20405 case DW_TAG_interface_type
:
20406 case DW_TAG_structure_type
:
20407 case DW_TAG_union_type
:
20408 case DW_TAG_set_type
:
20409 case DW_TAG_enumeration_type
:
20410 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20411 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20414 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20415 really ever be static objects: otherwise, if you try
20416 to, say, break of a class's method and you're in a file
20417 which doesn't mention that class, it won't work unless
20418 the check for all static symbols in lookup_symbol_aux
20419 saves you. See the OtherFileClass tests in
20420 gdb.c++/namespace.exp. */
20424 buildsym_compunit
*builder
= cu
->get_builder ();
20426 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20427 && cu
->language
== language_cplus
20428 ? builder
->get_global_symbols ()
20429 : cu
->list_in_scope
);
20431 /* The semantics of C++ state that "struct foo {
20432 ... }" also defines a typedef for "foo". */
20433 if (cu
->language
== language_cplus
20434 || cu
->language
== language_ada
20435 || cu
->language
== language_d
20436 || cu
->language
== language_rust
)
20438 /* The symbol's name is already allocated along
20439 with this objfile, so we don't need to
20440 duplicate it for the type. */
20441 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20442 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20447 case DW_TAG_typedef
:
20448 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20449 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20450 list_to_add
= cu
->list_in_scope
;
20452 case DW_TAG_base_type
:
20453 case DW_TAG_subrange_type
:
20454 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20455 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20456 list_to_add
= cu
->list_in_scope
;
20458 case DW_TAG_enumerator
:
20459 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20460 if (attr
!= nullptr)
20462 dwarf2_const_value (attr
, sym
, cu
);
20465 /* NOTE: carlton/2003-11-10: See comment above in the
20466 DW_TAG_class_type, etc. block. */
20469 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20470 && cu
->language
== language_cplus
20471 ? cu
->get_builder ()->get_global_symbols ()
20472 : cu
->list_in_scope
);
20475 case DW_TAG_imported_declaration
:
20476 case DW_TAG_namespace
:
20477 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20478 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20480 case DW_TAG_module
:
20481 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20482 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20483 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20485 case DW_TAG_common_block
:
20486 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20487 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20488 add_symbol_to_list (sym
, cu
->list_in_scope
);
20491 /* Not a tag we recognize. Hopefully we aren't processing
20492 trash data, but since we must specifically ignore things
20493 we don't recognize, there is nothing else we should do at
20495 complaint (_("unsupported tag: '%s'"),
20496 dwarf_tag_name (die
->tag
));
20502 sym
->hash_next
= objfile
->template_symbols
;
20503 objfile
->template_symbols
= sym
;
20504 list_to_add
= NULL
;
20507 if (list_to_add
!= NULL
)
20508 add_symbol_to_list (sym
, list_to_add
);
20510 /* For the benefit of old versions of GCC, check for anonymous
20511 namespaces based on the demangled name. */
20512 if (!cu
->processing_has_namespace_info
20513 && cu
->language
== language_cplus
)
20514 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20519 /* Given an attr with a DW_FORM_dataN value in host byte order,
20520 zero-extend it as appropriate for the symbol's type. The DWARF
20521 standard (v4) is not entirely clear about the meaning of using
20522 DW_FORM_dataN for a constant with a signed type, where the type is
20523 wider than the data. The conclusion of a discussion on the DWARF
20524 list was that this is unspecified. We choose to always zero-extend
20525 because that is the interpretation long in use by GCC. */
20528 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20529 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20531 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20532 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20533 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20534 LONGEST l
= DW_UNSND (attr
);
20536 if (bits
< sizeof (*value
) * 8)
20538 l
&= ((LONGEST
) 1 << bits
) - 1;
20541 else if (bits
== sizeof (*value
) * 8)
20545 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20546 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20553 /* Read a constant value from an attribute. Either set *VALUE, or if
20554 the value does not fit in *VALUE, set *BYTES - either already
20555 allocated on the objfile obstack, or newly allocated on OBSTACK,
20556 or, set *BATON, if we translated the constant to a location
20560 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20561 const char *name
, struct obstack
*obstack
,
20562 struct dwarf2_cu
*cu
,
20563 LONGEST
*value
, const gdb_byte
**bytes
,
20564 struct dwarf2_locexpr_baton
**baton
)
20566 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20567 struct comp_unit_head
*cu_header
= &cu
->header
;
20568 struct dwarf_block
*blk
;
20569 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20570 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20576 switch (attr
->form
)
20579 case DW_FORM_addrx
:
20580 case DW_FORM_GNU_addr_index
:
20584 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20585 dwarf2_const_value_length_mismatch_complaint (name
,
20586 cu_header
->addr_size
,
20587 TYPE_LENGTH (type
));
20588 /* Symbols of this form are reasonably rare, so we just
20589 piggyback on the existing location code rather than writing
20590 a new implementation of symbol_computed_ops. */
20591 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20592 (*baton
)->per_cu
= cu
->per_cu
;
20593 gdb_assert ((*baton
)->per_cu
);
20595 (*baton
)->size
= 2 + cu_header
->addr_size
;
20596 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20597 (*baton
)->data
= data
;
20599 data
[0] = DW_OP_addr
;
20600 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20601 byte_order
, DW_ADDR (attr
));
20602 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20605 case DW_FORM_string
:
20608 case DW_FORM_GNU_str_index
:
20609 case DW_FORM_GNU_strp_alt
:
20610 /* DW_STRING is already allocated on the objfile obstack, point
20612 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20614 case DW_FORM_block1
:
20615 case DW_FORM_block2
:
20616 case DW_FORM_block4
:
20617 case DW_FORM_block
:
20618 case DW_FORM_exprloc
:
20619 case DW_FORM_data16
:
20620 blk
= DW_BLOCK (attr
);
20621 if (TYPE_LENGTH (type
) != blk
->size
)
20622 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20623 TYPE_LENGTH (type
));
20624 *bytes
= blk
->data
;
20627 /* The DW_AT_const_value attributes are supposed to carry the
20628 symbol's value "represented as it would be on the target
20629 architecture." By the time we get here, it's already been
20630 converted to host endianness, so we just need to sign- or
20631 zero-extend it as appropriate. */
20632 case DW_FORM_data1
:
20633 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20635 case DW_FORM_data2
:
20636 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20638 case DW_FORM_data4
:
20639 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20641 case DW_FORM_data8
:
20642 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20645 case DW_FORM_sdata
:
20646 case DW_FORM_implicit_const
:
20647 *value
= DW_SND (attr
);
20650 case DW_FORM_udata
:
20651 *value
= DW_UNSND (attr
);
20655 complaint (_("unsupported const value attribute form: '%s'"),
20656 dwarf_form_name (attr
->form
));
20663 /* Copy constant value from an attribute to a symbol. */
20666 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20667 struct dwarf2_cu
*cu
)
20669 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20671 const gdb_byte
*bytes
;
20672 struct dwarf2_locexpr_baton
*baton
;
20674 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20675 sym
->print_name (),
20676 &objfile
->objfile_obstack
, cu
,
20677 &value
, &bytes
, &baton
);
20681 SYMBOL_LOCATION_BATON (sym
) = baton
;
20682 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20684 else if (bytes
!= NULL
)
20686 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20687 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20691 SYMBOL_VALUE (sym
) = value
;
20692 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20696 /* Return the type of the die in question using its DW_AT_type attribute. */
20698 static struct type
*
20699 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20701 struct attribute
*type_attr
;
20703 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20706 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20707 /* A missing DW_AT_type represents a void type. */
20708 return objfile_type (objfile
)->builtin_void
;
20711 return lookup_die_type (die
, type_attr
, cu
);
20714 /* True iff CU's producer generates GNAT Ada auxiliary information
20715 that allows to find parallel types through that information instead
20716 of having to do expensive parallel lookups by type name. */
20719 need_gnat_info (struct dwarf2_cu
*cu
)
20721 /* Assume that the Ada compiler was GNAT, which always produces
20722 the auxiliary information. */
20723 return (cu
->language
== language_ada
);
20726 /* Return the auxiliary type of the die in question using its
20727 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20728 attribute is not present. */
20730 static struct type
*
20731 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20733 struct attribute
*type_attr
;
20735 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20739 return lookup_die_type (die
, type_attr
, cu
);
20742 /* If DIE has a descriptive_type attribute, then set the TYPE's
20743 descriptive type accordingly. */
20746 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20747 struct dwarf2_cu
*cu
)
20749 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20751 if (descriptive_type
)
20753 ALLOCATE_GNAT_AUX_TYPE (type
);
20754 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20758 /* Return the containing type of the die in question using its
20759 DW_AT_containing_type attribute. */
20761 static struct type
*
20762 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20764 struct attribute
*type_attr
;
20765 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20767 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20769 error (_("Dwarf Error: Problem turning containing type into gdb type "
20770 "[in module %s]"), objfile_name (objfile
));
20772 return lookup_die_type (die
, type_attr
, cu
);
20775 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20777 static struct type
*
20778 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20780 struct dwarf2_per_objfile
*dwarf2_per_objfile
20781 = cu
->per_cu
->dwarf2_per_objfile
;
20782 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20785 std::string message
20786 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20787 objfile_name (objfile
),
20788 sect_offset_str (cu
->header
.sect_off
),
20789 sect_offset_str (die
->sect_off
));
20790 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20792 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20795 /* Look up the type of DIE in CU using its type attribute ATTR.
20796 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20797 DW_AT_containing_type.
20798 If there is no type substitute an error marker. */
20800 static struct type
*
20801 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20802 struct dwarf2_cu
*cu
)
20804 struct dwarf2_per_objfile
*dwarf2_per_objfile
20805 = cu
->per_cu
->dwarf2_per_objfile
;
20806 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20807 struct type
*this_type
;
20809 gdb_assert (attr
->name
== DW_AT_type
20810 || attr
->name
== DW_AT_GNAT_descriptive_type
20811 || attr
->name
== DW_AT_containing_type
);
20813 /* First see if we have it cached. */
20815 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20817 struct dwarf2_per_cu_data
*per_cu
;
20818 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20820 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20821 dwarf2_per_objfile
);
20822 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20824 else if (attr
->form_is_ref ())
20826 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20828 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20830 else if (attr
->form
== DW_FORM_ref_sig8
)
20832 ULONGEST signature
= DW_SIGNATURE (attr
);
20834 return get_signatured_type (die
, signature
, cu
);
20838 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20839 " at %s [in module %s]"),
20840 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20841 objfile_name (objfile
));
20842 return build_error_marker_type (cu
, die
);
20845 /* If not cached we need to read it in. */
20847 if (this_type
== NULL
)
20849 struct die_info
*type_die
= NULL
;
20850 struct dwarf2_cu
*type_cu
= cu
;
20852 if (attr
->form_is_ref ())
20853 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20854 if (type_die
== NULL
)
20855 return build_error_marker_type (cu
, die
);
20856 /* If we find the type now, it's probably because the type came
20857 from an inter-CU reference and the type's CU got expanded before
20859 this_type
= read_type_die (type_die
, type_cu
);
20862 /* If we still don't have a type use an error marker. */
20864 if (this_type
== NULL
)
20865 return build_error_marker_type (cu
, die
);
20870 /* Return the type in DIE, CU.
20871 Returns NULL for invalid types.
20873 This first does a lookup in die_type_hash,
20874 and only reads the die in if necessary.
20876 NOTE: This can be called when reading in partial or full symbols. */
20878 static struct type
*
20879 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20881 struct type
*this_type
;
20883 this_type
= get_die_type (die
, cu
);
20887 return read_type_die_1 (die
, cu
);
20890 /* Read the type in DIE, CU.
20891 Returns NULL for invalid types. */
20893 static struct type
*
20894 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20896 struct type
*this_type
= NULL
;
20900 case DW_TAG_class_type
:
20901 case DW_TAG_interface_type
:
20902 case DW_TAG_structure_type
:
20903 case DW_TAG_union_type
:
20904 this_type
= read_structure_type (die
, cu
);
20906 case DW_TAG_enumeration_type
:
20907 this_type
= read_enumeration_type (die
, cu
);
20909 case DW_TAG_subprogram
:
20910 case DW_TAG_subroutine_type
:
20911 case DW_TAG_inlined_subroutine
:
20912 this_type
= read_subroutine_type (die
, cu
);
20914 case DW_TAG_array_type
:
20915 this_type
= read_array_type (die
, cu
);
20917 case DW_TAG_set_type
:
20918 this_type
= read_set_type (die
, cu
);
20920 case DW_TAG_pointer_type
:
20921 this_type
= read_tag_pointer_type (die
, cu
);
20923 case DW_TAG_ptr_to_member_type
:
20924 this_type
= read_tag_ptr_to_member_type (die
, cu
);
20926 case DW_TAG_reference_type
:
20927 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
20929 case DW_TAG_rvalue_reference_type
:
20930 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
20932 case DW_TAG_const_type
:
20933 this_type
= read_tag_const_type (die
, cu
);
20935 case DW_TAG_volatile_type
:
20936 this_type
= read_tag_volatile_type (die
, cu
);
20938 case DW_TAG_restrict_type
:
20939 this_type
= read_tag_restrict_type (die
, cu
);
20941 case DW_TAG_string_type
:
20942 this_type
= read_tag_string_type (die
, cu
);
20944 case DW_TAG_typedef
:
20945 this_type
= read_typedef (die
, cu
);
20947 case DW_TAG_subrange_type
:
20948 this_type
= read_subrange_type (die
, cu
);
20950 case DW_TAG_base_type
:
20951 this_type
= read_base_type (die
, cu
);
20953 case DW_TAG_unspecified_type
:
20954 this_type
= read_unspecified_type (die
, cu
);
20956 case DW_TAG_namespace
:
20957 this_type
= read_namespace_type (die
, cu
);
20959 case DW_TAG_module
:
20960 this_type
= read_module_type (die
, cu
);
20962 case DW_TAG_atomic_type
:
20963 this_type
= read_tag_atomic_type (die
, cu
);
20966 complaint (_("unexpected tag in read_type_die: '%s'"),
20967 dwarf_tag_name (die
->tag
));
20974 /* See if we can figure out if the class lives in a namespace. We do
20975 this by looking for a member function; its demangled name will
20976 contain namespace info, if there is any.
20977 Return the computed name or NULL.
20978 Space for the result is allocated on the objfile's obstack.
20979 This is the full-die version of guess_partial_die_structure_name.
20980 In this case we know DIE has no useful parent. */
20982 static const char *
20983 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20985 struct die_info
*spec_die
;
20986 struct dwarf2_cu
*spec_cu
;
20987 struct die_info
*child
;
20988 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20991 spec_die
= die_specification (die
, &spec_cu
);
20992 if (spec_die
!= NULL
)
20998 for (child
= die
->child
;
21000 child
= child
->sibling
)
21002 if (child
->tag
== DW_TAG_subprogram
)
21004 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21006 if (linkage_name
!= NULL
)
21008 gdb::unique_xmalloc_ptr
<char> actual_name
21009 (language_class_name_from_physname (cu
->language_defn
,
21011 const char *name
= NULL
;
21013 if (actual_name
!= NULL
)
21015 const char *die_name
= dwarf2_name (die
, cu
);
21017 if (die_name
!= NULL
21018 && strcmp (die_name
, actual_name
.get ()) != 0)
21020 /* Strip off the class name from the full name.
21021 We want the prefix. */
21022 int die_name_len
= strlen (die_name
);
21023 int actual_name_len
= strlen (actual_name
.get ());
21024 const char *ptr
= actual_name
.get ();
21026 /* Test for '::' as a sanity check. */
21027 if (actual_name_len
> die_name_len
+ 2
21028 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21029 name
= obstack_strndup (
21030 &objfile
->per_bfd
->storage_obstack
,
21031 ptr
, actual_name_len
- die_name_len
- 2);
21042 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21043 prefix part in such case. See
21044 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21046 static const char *
21047 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21049 struct attribute
*attr
;
21052 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21053 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21056 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21059 attr
= dw2_linkage_name_attr (die
, cu
);
21060 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21063 /* dwarf2_name had to be already called. */
21064 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21066 /* Strip the base name, keep any leading namespaces/classes. */
21067 base
= strrchr (DW_STRING (attr
), ':');
21068 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21071 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21072 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21074 &base
[-1] - DW_STRING (attr
));
21077 /* Return the name of the namespace/class that DIE is defined within,
21078 or "" if we can't tell. The caller should not xfree the result.
21080 For example, if we're within the method foo() in the following
21090 then determine_prefix on foo's die will return "N::C". */
21092 static const char *
21093 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21095 struct dwarf2_per_objfile
*dwarf2_per_objfile
21096 = cu
->per_cu
->dwarf2_per_objfile
;
21097 struct die_info
*parent
, *spec_die
;
21098 struct dwarf2_cu
*spec_cu
;
21099 struct type
*parent_type
;
21100 const char *retval
;
21102 if (cu
->language
!= language_cplus
21103 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21104 && cu
->language
!= language_rust
)
21107 retval
= anonymous_struct_prefix (die
, cu
);
21111 /* We have to be careful in the presence of DW_AT_specification.
21112 For example, with GCC 3.4, given the code
21116 // Definition of N::foo.
21120 then we'll have a tree of DIEs like this:
21122 1: DW_TAG_compile_unit
21123 2: DW_TAG_namespace // N
21124 3: DW_TAG_subprogram // declaration of N::foo
21125 4: DW_TAG_subprogram // definition of N::foo
21126 DW_AT_specification // refers to die #3
21128 Thus, when processing die #4, we have to pretend that we're in
21129 the context of its DW_AT_specification, namely the contex of die
21132 spec_die
= die_specification (die
, &spec_cu
);
21133 if (spec_die
== NULL
)
21134 parent
= die
->parent
;
21137 parent
= spec_die
->parent
;
21141 if (parent
== NULL
)
21143 else if (parent
->building_fullname
)
21146 const char *parent_name
;
21148 /* It has been seen on RealView 2.2 built binaries,
21149 DW_TAG_template_type_param types actually _defined_ as
21150 children of the parent class:
21153 template class <class Enum> Class{};
21154 Class<enum E> class_e;
21156 1: DW_TAG_class_type (Class)
21157 2: DW_TAG_enumeration_type (E)
21158 3: DW_TAG_enumerator (enum1:0)
21159 3: DW_TAG_enumerator (enum2:1)
21161 2: DW_TAG_template_type_param
21162 DW_AT_type DW_FORM_ref_udata (E)
21164 Besides being broken debug info, it can put GDB into an
21165 infinite loop. Consider:
21167 When we're building the full name for Class<E>, we'll start
21168 at Class, and go look over its template type parameters,
21169 finding E. We'll then try to build the full name of E, and
21170 reach here. We're now trying to build the full name of E,
21171 and look over the parent DIE for containing scope. In the
21172 broken case, if we followed the parent DIE of E, we'd again
21173 find Class, and once again go look at its template type
21174 arguments, etc., etc. Simply don't consider such parent die
21175 as source-level parent of this die (it can't be, the language
21176 doesn't allow it), and break the loop here. */
21177 name
= dwarf2_name (die
, cu
);
21178 parent_name
= dwarf2_name (parent
, cu
);
21179 complaint (_("template param type '%s' defined within parent '%s'"),
21180 name
? name
: "<unknown>",
21181 parent_name
? parent_name
: "<unknown>");
21185 switch (parent
->tag
)
21187 case DW_TAG_namespace
:
21188 parent_type
= read_type_die (parent
, cu
);
21189 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21190 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21191 Work around this problem here. */
21192 if (cu
->language
== language_cplus
21193 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21195 /* We give a name to even anonymous namespaces. */
21196 return TYPE_NAME (parent_type
);
21197 case DW_TAG_class_type
:
21198 case DW_TAG_interface_type
:
21199 case DW_TAG_structure_type
:
21200 case DW_TAG_union_type
:
21201 case DW_TAG_module
:
21202 parent_type
= read_type_die (parent
, cu
);
21203 if (TYPE_NAME (parent_type
) != NULL
)
21204 return TYPE_NAME (parent_type
);
21206 /* An anonymous structure is only allowed non-static data
21207 members; no typedefs, no member functions, et cetera.
21208 So it does not need a prefix. */
21210 case DW_TAG_compile_unit
:
21211 case DW_TAG_partial_unit
:
21212 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21213 if (cu
->language
== language_cplus
21214 && !dwarf2_per_objfile
->types
.empty ()
21215 && die
->child
!= NULL
21216 && (die
->tag
== DW_TAG_class_type
21217 || die
->tag
== DW_TAG_structure_type
21218 || die
->tag
== DW_TAG_union_type
))
21220 const char *name
= guess_full_die_structure_name (die
, cu
);
21225 case DW_TAG_subprogram
:
21226 /* Nested subroutines in Fortran get a prefix with the name
21227 of the parent's subroutine. */
21228 if (cu
->language
== language_fortran
)
21230 if ((die
->tag
== DW_TAG_subprogram
)
21231 && (dwarf2_name (parent
, cu
) != NULL
))
21232 return dwarf2_name (parent
, cu
);
21234 return determine_prefix (parent
, cu
);
21235 case DW_TAG_enumeration_type
:
21236 parent_type
= read_type_die (parent
, cu
);
21237 if (TYPE_DECLARED_CLASS (parent_type
))
21239 if (TYPE_NAME (parent_type
) != NULL
)
21240 return TYPE_NAME (parent_type
);
21243 /* Fall through. */
21245 return determine_prefix (parent
, cu
);
21249 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21250 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21251 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21252 an obconcat, otherwise allocate storage for the result. The CU argument is
21253 used to determine the language and hence, the appropriate separator. */
21255 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21258 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21259 int physname
, struct dwarf2_cu
*cu
)
21261 const char *lead
= "";
21264 if (suffix
== NULL
|| suffix
[0] == '\0'
21265 || prefix
== NULL
|| prefix
[0] == '\0')
21267 else if (cu
->language
== language_d
)
21269 /* For D, the 'main' function could be defined in any module, but it
21270 should never be prefixed. */
21271 if (strcmp (suffix
, "D main") == 0)
21279 else if (cu
->language
== language_fortran
&& physname
)
21281 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21282 DW_AT_MIPS_linkage_name is preferred and used instead. */
21290 if (prefix
== NULL
)
21292 if (suffix
== NULL
)
21299 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21301 strcpy (retval
, lead
);
21302 strcat (retval
, prefix
);
21303 strcat (retval
, sep
);
21304 strcat (retval
, suffix
);
21309 /* We have an obstack. */
21310 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21314 /* Return sibling of die, NULL if no sibling. */
21316 static struct die_info
*
21317 sibling_die (struct die_info
*die
)
21319 return die
->sibling
;
21322 /* Get name of a die, return NULL if not found. */
21324 static const char *
21325 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21326 struct objfile
*objfile
)
21328 if (name
&& cu
->language
== language_cplus
)
21330 std::string canon_name
= cp_canonicalize_string (name
);
21332 if (!canon_name
.empty ())
21334 if (canon_name
!= name
)
21335 name
= objfile
->intern (canon_name
);
21342 /* Get name of a die, return NULL if not found.
21343 Anonymous namespaces are converted to their magic string. */
21345 static const char *
21346 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21348 struct attribute
*attr
;
21349 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21351 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21352 if ((!attr
|| !DW_STRING (attr
))
21353 && die
->tag
!= DW_TAG_namespace
21354 && die
->tag
!= DW_TAG_class_type
21355 && die
->tag
!= DW_TAG_interface_type
21356 && die
->tag
!= DW_TAG_structure_type
21357 && die
->tag
!= DW_TAG_union_type
)
21362 case DW_TAG_compile_unit
:
21363 case DW_TAG_partial_unit
:
21364 /* Compilation units have a DW_AT_name that is a filename, not
21365 a source language identifier. */
21366 case DW_TAG_enumeration_type
:
21367 case DW_TAG_enumerator
:
21368 /* These tags always have simple identifiers already; no need
21369 to canonicalize them. */
21370 return DW_STRING (attr
);
21372 case DW_TAG_namespace
:
21373 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21374 return DW_STRING (attr
);
21375 return CP_ANONYMOUS_NAMESPACE_STR
;
21377 case DW_TAG_class_type
:
21378 case DW_TAG_interface_type
:
21379 case DW_TAG_structure_type
:
21380 case DW_TAG_union_type
:
21381 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21382 structures or unions. These were of the form "._%d" in GCC 4.1,
21383 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21384 and GCC 4.4. We work around this problem by ignoring these. */
21385 if (attr
&& DW_STRING (attr
)
21386 && (startswith (DW_STRING (attr
), "._")
21387 || startswith (DW_STRING (attr
), "<anonymous")))
21390 /* GCC might emit a nameless typedef that has a linkage name. See
21391 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21392 if (!attr
|| DW_STRING (attr
) == NULL
)
21394 attr
= dw2_linkage_name_attr (die
, cu
);
21395 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21398 /* Avoid demangling DW_STRING (attr) the second time on a second
21399 call for the same DIE. */
21400 if (!DW_STRING_IS_CANONICAL (attr
))
21402 gdb::unique_xmalloc_ptr
<char> demangled
21403 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21404 if (demangled
== nullptr)
21407 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21408 DW_STRING_IS_CANONICAL (attr
) = 1;
21411 /* Strip any leading namespaces/classes, keep only the base name.
21412 DW_AT_name for named DIEs does not contain the prefixes. */
21413 const char *base
= strrchr (DW_STRING (attr
), ':');
21414 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21417 return DW_STRING (attr
);
21425 if (!DW_STRING_IS_CANONICAL (attr
))
21427 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21429 DW_STRING_IS_CANONICAL (attr
) = 1;
21431 return DW_STRING (attr
);
21434 /* Return the die that this die in an extension of, or NULL if there
21435 is none. *EXT_CU is the CU containing DIE on input, and the CU
21436 containing the return value on output. */
21438 static struct die_info
*
21439 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21441 struct attribute
*attr
;
21443 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21447 return follow_die_ref (die
, attr
, ext_cu
);
21450 /* A convenience function that returns an "unknown" DWARF name,
21451 including the value of V. STR is the name of the entity being
21452 printed, e.g., "TAG". */
21454 static const char *
21455 dwarf_unknown (const char *str
, unsigned v
)
21457 char *cell
= get_print_cell ();
21458 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21462 /* Convert a DIE tag into its string name. */
21464 static const char *
21465 dwarf_tag_name (unsigned tag
)
21467 const char *name
= get_DW_TAG_name (tag
);
21470 return dwarf_unknown ("TAG", tag
);
21475 /* Convert a DWARF attribute code into its string name. */
21477 static const char *
21478 dwarf_attr_name (unsigned attr
)
21482 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21483 if (attr
== DW_AT_MIPS_fde
)
21484 return "DW_AT_MIPS_fde";
21486 if (attr
== DW_AT_HP_block_index
)
21487 return "DW_AT_HP_block_index";
21490 name
= get_DW_AT_name (attr
);
21493 return dwarf_unknown ("AT", attr
);
21498 /* Convert a DWARF value form code into its string name. */
21500 static const char *
21501 dwarf_form_name (unsigned form
)
21503 const char *name
= get_DW_FORM_name (form
);
21506 return dwarf_unknown ("FORM", form
);
21511 static const char *
21512 dwarf_bool_name (unsigned mybool
)
21520 /* Convert a DWARF type code into its string name. */
21522 static const char *
21523 dwarf_type_encoding_name (unsigned enc
)
21525 const char *name
= get_DW_ATE_name (enc
);
21528 return dwarf_unknown ("ATE", enc
);
21534 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21538 print_spaces (indent
, f
);
21539 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21540 dwarf_tag_name (die
->tag
), die
->abbrev
,
21541 sect_offset_str (die
->sect_off
));
21543 if (die
->parent
!= NULL
)
21545 print_spaces (indent
, f
);
21546 fprintf_unfiltered (f
, " parent at offset: %s\n",
21547 sect_offset_str (die
->parent
->sect_off
));
21550 print_spaces (indent
, f
);
21551 fprintf_unfiltered (f
, " has children: %s\n",
21552 dwarf_bool_name (die
->child
!= NULL
));
21554 print_spaces (indent
, f
);
21555 fprintf_unfiltered (f
, " attributes:\n");
21557 for (i
= 0; i
< die
->num_attrs
; ++i
)
21559 print_spaces (indent
, f
);
21560 fprintf_unfiltered (f
, " %s (%s) ",
21561 dwarf_attr_name (die
->attrs
[i
].name
),
21562 dwarf_form_name (die
->attrs
[i
].form
));
21564 switch (die
->attrs
[i
].form
)
21567 case DW_FORM_addrx
:
21568 case DW_FORM_GNU_addr_index
:
21569 fprintf_unfiltered (f
, "address: ");
21570 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21572 case DW_FORM_block2
:
21573 case DW_FORM_block4
:
21574 case DW_FORM_block
:
21575 case DW_FORM_block1
:
21576 fprintf_unfiltered (f
, "block: size %s",
21577 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21579 case DW_FORM_exprloc
:
21580 fprintf_unfiltered (f
, "expression: size %s",
21581 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21583 case DW_FORM_data16
:
21584 fprintf_unfiltered (f
, "constant of 16 bytes");
21586 case DW_FORM_ref_addr
:
21587 fprintf_unfiltered (f
, "ref address: ");
21588 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21590 case DW_FORM_GNU_ref_alt
:
21591 fprintf_unfiltered (f
, "alt ref address: ");
21592 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21598 case DW_FORM_ref_udata
:
21599 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21600 (long) (DW_UNSND (&die
->attrs
[i
])));
21602 case DW_FORM_data1
:
21603 case DW_FORM_data2
:
21604 case DW_FORM_data4
:
21605 case DW_FORM_data8
:
21606 case DW_FORM_udata
:
21607 case DW_FORM_sdata
:
21608 fprintf_unfiltered (f
, "constant: %s",
21609 pulongest (DW_UNSND (&die
->attrs
[i
])));
21611 case DW_FORM_sec_offset
:
21612 fprintf_unfiltered (f
, "section offset: %s",
21613 pulongest (DW_UNSND (&die
->attrs
[i
])));
21615 case DW_FORM_ref_sig8
:
21616 fprintf_unfiltered (f
, "signature: %s",
21617 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21619 case DW_FORM_string
:
21621 case DW_FORM_line_strp
:
21623 case DW_FORM_GNU_str_index
:
21624 case DW_FORM_GNU_strp_alt
:
21625 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21626 DW_STRING (&die
->attrs
[i
])
21627 ? DW_STRING (&die
->attrs
[i
]) : "",
21628 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21631 if (DW_UNSND (&die
->attrs
[i
]))
21632 fprintf_unfiltered (f
, "flag: TRUE");
21634 fprintf_unfiltered (f
, "flag: FALSE");
21636 case DW_FORM_flag_present
:
21637 fprintf_unfiltered (f
, "flag: TRUE");
21639 case DW_FORM_indirect
:
21640 /* The reader will have reduced the indirect form to
21641 the "base form" so this form should not occur. */
21642 fprintf_unfiltered (f
,
21643 "unexpected attribute form: DW_FORM_indirect");
21645 case DW_FORM_implicit_const
:
21646 fprintf_unfiltered (f
, "constant: %s",
21647 plongest (DW_SND (&die
->attrs
[i
])));
21650 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21651 die
->attrs
[i
].form
);
21654 fprintf_unfiltered (f
, "\n");
21659 dump_die_for_error (struct die_info
*die
)
21661 dump_die_shallow (gdb_stderr
, 0, die
);
21665 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21667 int indent
= level
* 4;
21669 gdb_assert (die
!= NULL
);
21671 if (level
>= max_level
)
21674 dump_die_shallow (f
, indent
, die
);
21676 if (die
->child
!= NULL
)
21678 print_spaces (indent
, f
);
21679 fprintf_unfiltered (f
, " Children:");
21680 if (level
+ 1 < max_level
)
21682 fprintf_unfiltered (f
, "\n");
21683 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21687 fprintf_unfiltered (f
,
21688 " [not printed, max nesting level reached]\n");
21692 if (die
->sibling
!= NULL
&& level
> 0)
21694 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21698 /* This is called from the pdie macro in gdbinit.in.
21699 It's not static so gcc will keep a copy callable from gdb. */
21702 dump_die (struct die_info
*die
, int max_level
)
21704 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21708 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21712 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21713 to_underlying (die
->sect_off
),
21719 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
21723 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
21725 if (attr
->form_is_ref ())
21726 return (sect_offset
) DW_UNSND (attr
);
21728 complaint (_("unsupported die ref attribute form: '%s'"),
21729 dwarf_form_name (attr
->form
));
21733 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
21734 * the value held by the attribute is not constant. */
21737 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
21739 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
21740 return DW_SND (attr
);
21741 else if (attr
->form
== DW_FORM_udata
21742 || attr
->form
== DW_FORM_data1
21743 || attr
->form
== DW_FORM_data2
21744 || attr
->form
== DW_FORM_data4
21745 || attr
->form
== DW_FORM_data8
)
21746 return DW_UNSND (attr
);
21749 /* For DW_FORM_data16 see attribute::form_is_constant. */
21750 complaint (_("Attribute value is not a constant (%s)"),
21751 dwarf_form_name (attr
->form
));
21752 return default_value
;
21756 /* Follow reference or signature attribute ATTR of SRC_DIE.
21757 On entry *REF_CU is the CU of SRC_DIE.
21758 On exit *REF_CU is the CU of the result. */
21760 static struct die_info
*
21761 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21762 struct dwarf2_cu
**ref_cu
)
21764 struct die_info
*die
;
21766 if (attr
->form_is_ref ())
21767 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21768 else if (attr
->form
== DW_FORM_ref_sig8
)
21769 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21772 dump_die_for_error (src_die
);
21773 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21774 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21780 /* Follow reference OFFSET.
21781 On entry *REF_CU is the CU of the source die referencing OFFSET.
21782 On exit *REF_CU is the CU of the result.
21783 Returns NULL if OFFSET is invalid. */
21785 static struct die_info
*
21786 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21787 struct dwarf2_cu
**ref_cu
)
21789 struct die_info temp_die
;
21790 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21791 struct dwarf2_per_objfile
*dwarf2_per_objfile
21792 = cu
->per_cu
->dwarf2_per_objfile
;
21794 gdb_assert (cu
->per_cu
!= NULL
);
21798 if (cu
->per_cu
->is_debug_types
)
21800 /* .debug_types CUs cannot reference anything outside their CU.
21801 If they need to, they have to reference a signatured type via
21802 DW_FORM_ref_sig8. */
21803 if (!cu
->header
.offset_in_cu_p (sect_off
))
21806 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21807 || !cu
->header
.offset_in_cu_p (sect_off
))
21809 struct dwarf2_per_cu_data
*per_cu
;
21811 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21812 dwarf2_per_objfile
);
21814 /* If necessary, add it to the queue and load its DIEs. */
21815 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21816 load_full_comp_unit (per_cu
, false, cu
->language
);
21818 target_cu
= per_cu
->cu
;
21820 else if (cu
->dies
== NULL
)
21822 /* We're loading full DIEs during partial symbol reading. */
21823 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21824 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21827 *ref_cu
= target_cu
;
21828 temp_die
.sect_off
= sect_off
;
21830 if (target_cu
!= cu
)
21831 target_cu
->ancestor
= cu
;
21833 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21835 to_underlying (sect_off
));
21838 /* Follow reference attribute ATTR of SRC_DIE.
21839 On entry *REF_CU is the CU of SRC_DIE.
21840 On exit *REF_CU is the CU of the result. */
21842 static struct die_info
*
21843 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21844 struct dwarf2_cu
**ref_cu
)
21846 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21847 struct dwarf2_cu
*cu
= *ref_cu
;
21848 struct die_info
*die
;
21850 die
= follow_die_offset (sect_off
,
21851 (attr
->form
== DW_FORM_GNU_ref_alt
21852 || cu
->per_cu
->is_dwz
),
21855 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21856 "at %s [in module %s]"),
21857 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21858 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21865 struct dwarf2_locexpr_baton
21866 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21867 dwarf2_per_cu_data
*per_cu
,
21868 CORE_ADDR (*get_frame_pc
) (void *baton
),
21869 void *baton
, bool resolve_abstract_p
)
21871 struct dwarf2_cu
*cu
;
21872 struct die_info
*die
;
21873 struct attribute
*attr
;
21874 struct dwarf2_locexpr_baton retval
;
21875 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21876 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21878 if (per_cu
->cu
== NULL
)
21879 load_cu (per_cu
, false);
21883 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21884 Instead just throw an error, not much else we can do. */
21885 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21886 sect_offset_str (sect_off
), objfile_name (objfile
));
21889 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21891 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21892 sect_offset_str (sect_off
), objfile_name (objfile
));
21894 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21895 if (!attr
&& resolve_abstract_p
21896 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21897 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21899 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21900 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21901 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21903 for (const auto &cand_off
21904 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21906 struct dwarf2_cu
*cand_cu
= cu
;
21907 struct die_info
*cand
21908 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21911 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21914 CORE_ADDR pc_low
, pc_high
;
21915 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21916 if (pc_low
== ((CORE_ADDR
) -1))
21918 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21919 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21920 if (!(pc_low
<= pc
&& pc
< pc_high
))
21924 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21931 /* DWARF: "If there is no such attribute, then there is no effect.".
21932 DATA is ignored if SIZE is 0. */
21934 retval
.data
= NULL
;
21937 else if (attr
->form_is_section_offset ())
21939 struct dwarf2_loclist_baton loclist_baton
;
21940 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21943 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21945 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21947 retval
.size
= size
;
21951 if (!attr
->form_is_block ())
21952 error (_("Dwarf Error: DIE at %s referenced in module %s "
21953 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21954 sect_offset_str (sect_off
), objfile_name (objfile
));
21956 retval
.data
= DW_BLOCK (attr
)->data
;
21957 retval
.size
= DW_BLOCK (attr
)->size
;
21959 retval
.per_cu
= cu
->per_cu
;
21961 age_cached_comp_units (dwarf2_per_objfile
);
21968 struct dwarf2_locexpr_baton
21969 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21970 dwarf2_per_cu_data
*per_cu
,
21971 CORE_ADDR (*get_frame_pc
) (void *baton
),
21974 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21976 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21979 /* Write a constant of a given type as target-ordered bytes into
21982 static const gdb_byte
*
21983 write_constant_as_bytes (struct obstack
*obstack
,
21984 enum bfd_endian byte_order
,
21991 *len
= TYPE_LENGTH (type
);
21992 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21993 store_unsigned_integer (result
, *len
, byte_order
, value
);
22001 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22002 dwarf2_per_cu_data
*per_cu
,
22006 struct dwarf2_cu
*cu
;
22007 struct die_info
*die
;
22008 struct attribute
*attr
;
22009 const gdb_byte
*result
= NULL
;
22012 enum bfd_endian byte_order
;
22013 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22015 if (per_cu
->cu
== NULL
)
22016 load_cu (per_cu
, false);
22020 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22021 Instead just throw an error, not much else we can do. */
22022 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22023 sect_offset_str (sect_off
), objfile_name (objfile
));
22026 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22028 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22029 sect_offset_str (sect_off
), objfile_name (objfile
));
22031 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22035 byte_order
= (bfd_big_endian (objfile
->obfd
)
22036 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22038 switch (attr
->form
)
22041 case DW_FORM_addrx
:
22042 case DW_FORM_GNU_addr_index
:
22046 *len
= cu
->header
.addr_size
;
22047 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22048 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22052 case DW_FORM_string
:
22055 case DW_FORM_GNU_str_index
:
22056 case DW_FORM_GNU_strp_alt
:
22057 /* DW_STRING is already allocated on the objfile obstack, point
22059 result
= (const gdb_byte
*) DW_STRING (attr
);
22060 *len
= strlen (DW_STRING (attr
));
22062 case DW_FORM_block1
:
22063 case DW_FORM_block2
:
22064 case DW_FORM_block4
:
22065 case DW_FORM_block
:
22066 case DW_FORM_exprloc
:
22067 case DW_FORM_data16
:
22068 result
= DW_BLOCK (attr
)->data
;
22069 *len
= DW_BLOCK (attr
)->size
;
22072 /* The DW_AT_const_value attributes are supposed to carry the
22073 symbol's value "represented as it would be on the target
22074 architecture." By the time we get here, it's already been
22075 converted to host endianness, so we just need to sign- or
22076 zero-extend it as appropriate. */
22077 case DW_FORM_data1
:
22078 type
= die_type (die
, cu
);
22079 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22080 if (result
== NULL
)
22081 result
= write_constant_as_bytes (obstack
, byte_order
,
22084 case DW_FORM_data2
:
22085 type
= die_type (die
, cu
);
22086 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22087 if (result
== NULL
)
22088 result
= write_constant_as_bytes (obstack
, byte_order
,
22091 case DW_FORM_data4
:
22092 type
= die_type (die
, cu
);
22093 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22094 if (result
== NULL
)
22095 result
= write_constant_as_bytes (obstack
, byte_order
,
22098 case DW_FORM_data8
:
22099 type
= die_type (die
, cu
);
22100 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22101 if (result
== NULL
)
22102 result
= write_constant_as_bytes (obstack
, byte_order
,
22106 case DW_FORM_sdata
:
22107 case DW_FORM_implicit_const
:
22108 type
= die_type (die
, cu
);
22109 result
= write_constant_as_bytes (obstack
, byte_order
,
22110 type
, DW_SND (attr
), len
);
22113 case DW_FORM_udata
:
22114 type
= die_type (die
, cu
);
22115 result
= write_constant_as_bytes (obstack
, byte_order
,
22116 type
, DW_UNSND (attr
), len
);
22120 complaint (_("unsupported const value attribute form: '%s'"),
22121 dwarf_form_name (attr
->form
));
22131 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22132 dwarf2_per_cu_data
*per_cu
)
22134 struct dwarf2_cu
*cu
;
22135 struct die_info
*die
;
22137 if (per_cu
->cu
== NULL
)
22138 load_cu (per_cu
, false);
22143 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22147 return die_type (die
, cu
);
22153 dwarf2_get_die_type (cu_offset die_offset
,
22154 struct dwarf2_per_cu_data
*per_cu
)
22156 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22157 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22160 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22161 On entry *REF_CU is the CU of SRC_DIE.
22162 On exit *REF_CU is the CU of the result.
22163 Returns NULL if the referenced DIE isn't found. */
22165 static struct die_info
*
22166 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22167 struct dwarf2_cu
**ref_cu
)
22169 struct die_info temp_die
;
22170 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22171 struct die_info
*die
;
22173 /* While it might be nice to assert sig_type->type == NULL here,
22174 we can get here for DW_AT_imported_declaration where we need
22175 the DIE not the type. */
22177 /* If necessary, add it to the queue and load its DIEs. */
22179 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22180 read_signatured_type (sig_type
);
22182 sig_cu
= sig_type
->per_cu
.cu
;
22183 gdb_assert (sig_cu
!= NULL
);
22184 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22185 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22186 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22187 to_underlying (temp_die
.sect_off
));
22190 struct dwarf2_per_objfile
*dwarf2_per_objfile
22191 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22193 /* For .gdb_index version 7 keep track of included TUs.
22194 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22195 if (dwarf2_per_objfile
->index_table
!= NULL
22196 && dwarf2_per_objfile
->index_table
->version
<= 7)
22198 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22203 sig_cu
->ancestor
= cu
;
22211 /* Follow signatured type referenced by ATTR in SRC_DIE.
22212 On entry *REF_CU is the CU of SRC_DIE.
22213 On exit *REF_CU is the CU of the result.
22214 The result is the DIE of the type.
22215 If the referenced type cannot be found an error is thrown. */
22217 static struct die_info
*
22218 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22219 struct dwarf2_cu
**ref_cu
)
22221 ULONGEST signature
= DW_SIGNATURE (attr
);
22222 struct signatured_type
*sig_type
;
22223 struct die_info
*die
;
22225 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22227 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22228 /* sig_type will be NULL if the signatured type is missing from
22230 if (sig_type
== NULL
)
22232 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22233 " from DIE at %s [in module %s]"),
22234 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22235 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22238 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22241 dump_die_for_error (src_die
);
22242 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22243 " from DIE at %s [in module %s]"),
22244 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22245 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22251 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22252 reading in and processing the type unit if necessary. */
22254 static struct type
*
22255 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22256 struct dwarf2_cu
*cu
)
22258 struct dwarf2_per_objfile
*dwarf2_per_objfile
22259 = cu
->per_cu
->dwarf2_per_objfile
;
22260 struct signatured_type
*sig_type
;
22261 struct dwarf2_cu
*type_cu
;
22262 struct die_info
*type_die
;
22265 sig_type
= lookup_signatured_type (cu
, signature
);
22266 /* sig_type will be NULL if the signatured type is missing from
22268 if (sig_type
== NULL
)
22270 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22271 " from DIE at %s [in module %s]"),
22272 hex_string (signature
), sect_offset_str (die
->sect_off
),
22273 objfile_name (dwarf2_per_objfile
->objfile
));
22274 return build_error_marker_type (cu
, die
);
22277 /* If we already know the type we're done. */
22278 if (sig_type
->type
!= NULL
)
22279 return sig_type
->type
;
22282 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22283 if (type_die
!= NULL
)
22285 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22286 is created. This is important, for example, because for c++ classes
22287 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22288 type
= read_type_die (type_die
, type_cu
);
22291 complaint (_("Dwarf Error: Cannot build signatured type %s"
22292 " referenced from DIE at %s [in module %s]"),
22293 hex_string (signature
), sect_offset_str (die
->sect_off
),
22294 objfile_name (dwarf2_per_objfile
->objfile
));
22295 type
= build_error_marker_type (cu
, die
);
22300 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22301 " from DIE at %s [in module %s]"),
22302 hex_string (signature
), sect_offset_str (die
->sect_off
),
22303 objfile_name (dwarf2_per_objfile
->objfile
));
22304 type
= build_error_marker_type (cu
, die
);
22306 sig_type
->type
= type
;
22311 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22312 reading in and processing the type unit if necessary. */
22314 static struct type
*
22315 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22316 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22318 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22319 if (attr
->form_is_ref ())
22321 struct dwarf2_cu
*type_cu
= cu
;
22322 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22324 return read_type_die (type_die
, type_cu
);
22326 else if (attr
->form
== DW_FORM_ref_sig8
)
22328 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22332 struct dwarf2_per_objfile
*dwarf2_per_objfile
22333 = cu
->per_cu
->dwarf2_per_objfile
;
22335 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22336 " at %s [in module %s]"),
22337 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22338 objfile_name (dwarf2_per_objfile
->objfile
));
22339 return build_error_marker_type (cu
, die
);
22343 /* Load the DIEs associated with type unit PER_CU into memory. */
22346 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22348 struct signatured_type
*sig_type
;
22350 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22351 gdb_assert (! per_cu
->type_unit_group_p ());
22353 /* We have the per_cu, but we need the signatured_type.
22354 Fortunately this is an easy translation. */
22355 gdb_assert (per_cu
->is_debug_types
);
22356 sig_type
= (struct signatured_type
*) per_cu
;
22358 gdb_assert (per_cu
->cu
== NULL
);
22360 read_signatured_type (sig_type
);
22362 gdb_assert (per_cu
->cu
!= NULL
);
22365 /* Read in a signatured type and build its CU and DIEs.
22366 If the type is a stub for the real type in a DWO file,
22367 read in the real type from the DWO file as well. */
22370 read_signatured_type (struct signatured_type
*sig_type
)
22372 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22374 gdb_assert (per_cu
->is_debug_types
);
22375 gdb_assert (per_cu
->cu
== NULL
);
22377 cutu_reader
reader (per_cu
, NULL
, 0, false);
22379 if (!reader
.dummy_p
)
22381 struct dwarf2_cu
*cu
= reader
.cu
;
22382 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22384 gdb_assert (cu
->die_hash
== NULL
);
22386 htab_create_alloc_ex (cu
->header
.length
/ 12,
22390 &cu
->comp_unit_obstack
,
22391 hashtab_obstack_allocate
,
22392 dummy_obstack_deallocate
);
22394 if (reader
.comp_unit_die
->has_children
)
22395 reader
.comp_unit_die
->child
22396 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22397 reader
.comp_unit_die
);
22398 cu
->dies
= reader
.comp_unit_die
;
22399 /* comp_unit_die is not stored in die_hash, no need. */
22401 /* We try not to read any attributes in this function, because
22402 not all CUs needed for references have been loaded yet, and
22403 symbol table processing isn't initialized. But we have to
22404 set the CU language, or we won't be able to build types
22405 correctly. Similarly, if we do not read the producer, we can
22406 not apply producer-specific interpretation. */
22407 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22412 sig_type
->per_cu
.tu_read
= 1;
22415 /* Decode simple location descriptions.
22416 Given a pointer to a dwarf block that defines a location, compute
22417 the location and return the value.
22419 NOTE drow/2003-11-18: This function is called in two situations
22420 now: for the address of static or global variables (partial symbols
22421 only) and for offsets into structures which are expected to be
22422 (more or less) constant. The partial symbol case should go away,
22423 and only the constant case should remain. That will let this
22424 function complain more accurately. A few special modes are allowed
22425 without complaint for global variables (for instance, global
22426 register values and thread-local values).
22428 A location description containing no operations indicates that the
22429 object is optimized out. The return value is 0 for that case.
22430 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22431 callers will only want a very basic result and this can become a
22434 Note that stack[0] is unused except as a default error return. */
22437 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22439 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22441 size_t size
= blk
->size
;
22442 const gdb_byte
*data
= blk
->data
;
22443 CORE_ADDR stack
[64];
22445 unsigned int bytes_read
, unsnd
;
22451 stack
[++stacki
] = 0;
22490 stack
[++stacki
] = op
- DW_OP_lit0
;
22525 stack
[++stacki
] = op
- DW_OP_reg0
;
22527 dwarf2_complex_location_expr_complaint ();
22531 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22533 stack
[++stacki
] = unsnd
;
22535 dwarf2_complex_location_expr_complaint ();
22539 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22544 case DW_OP_const1u
:
22545 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22549 case DW_OP_const1s
:
22550 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22554 case DW_OP_const2u
:
22555 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22559 case DW_OP_const2s
:
22560 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22564 case DW_OP_const4u
:
22565 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22569 case DW_OP_const4s
:
22570 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22574 case DW_OP_const8u
:
22575 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22580 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22586 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22591 stack
[stacki
+ 1] = stack
[stacki
];
22596 stack
[stacki
- 1] += stack
[stacki
];
22600 case DW_OP_plus_uconst
:
22601 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22607 stack
[stacki
- 1] -= stack
[stacki
];
22612 /* If we're not the last op, then we definitely can't encode
22613 this using GDB's address_class enum. This is valid for partial
22614 global symbols, although the variable's address will be bogus
22617 dwarf2_complex_location_expr_complaint ();
22620 case DW_OP_GNU_push_tls_address
:
22621 case DW_OP_form_tls_address
:
22622 /* The top of the stack has the offset from the beginning
22623 of the thread control block at which the variable is located. */
22624 /* Nothing should follow this operator, so the top of stack would
22626 /* This is valid for partial global symbols, but the variable's
22627 address will be bogus in the psymtab. Make it always at least
22628 non-zero to not look as a variable garbage collected by linker
22629 which have DW_OP_addr 0. */
22631 dwarf2_complex_location_expr_complaint ();
22635 case DW_OP_GNU_uninit
:
22639 case DW_OP_GNU_addr_index
:
22640 case DW_OP_GNU_const_index
:
22641 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22648 const char *name
= get_DW_OP_name (op
);
22651 complaint (_("unsupported stack op: '%s'"),
22654 complaint (_("unsupported stack op: '%02x'"),
22658 return (stack
[stacki
]);
22661 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22662 outside of the allocated space. Also enforce minimum>0. */
22663 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22665 complaint (_("location description stack overflow"));
22671 complaint (_("location description stack underflow"));
22675 return (stack
[stacki
]);
22678 /* memory allocation interface */
22680 static struct dwarf_block
*
22681 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22683 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22686 static struct die_info
*
22687 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22689 struct die_info
*die
;
22690 size_t size
= sizeof (struct die_info
);
22693 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22695 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22696 memset (die
, 0, sizeof (struct die_info
));
22702 /* Macro support. */
22704 /* An overload of dwarf_decode_macros that finds the correct section
22705 and ensures it is read in before calling the other overload. */
22708 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22709 int section_is_gnu
)
22711 struct dwarf2_per_objfile
*dwarf2_per_objfile
22712 = cu
->per_cu
->dwarf2_per_objfile
;
22713 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22714 const struct line_header
*lh
= cu
->line_header
;
22715 unsigned int offset_size
= cu
->header
.offset_size
;
22716 struct dwarf2_section_info
*section
;
22717 const char *section_name
;
22719 if (cu
->dwo_unit
!= nullptr)
22721 if (section_is_gnu
)
22723 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22724 section_name
= ".debug_macro.dwo";
22728 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22729 section_name
= ".debug_macinfo.dwo";
22734 if (section_is_gnu
)
22736 section
= &dwarf2_per_objfile
->macro
;
22737 section_name
= ".debug_macro";
22741 section
= &dwarf2_per_objfile
->macinfo
;
22742 section_name
= ".debug_macinfo";
22746 section
->read (objfile
);
22747 if (section
->buffer
== nullptr)
22749 complaint (_("missing %s section"), section_name
);
22753 buildsym_compunit
*builder
= cu
->get_builder ();
22755 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22756 offset_size
, offset
, section_is_gnu
);
22759 /* Return the .debug_loc section to use for CU.
22760 For DWO files use .debug_loc.dwo. */
22762 static struct dwarf2_section_info
*
22763 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22765 struct dwarf2_per_objfile
*dwarf2_per_objfile
22766 = cu
->per_cu
->dwarf2_per_objfile
;
22770 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22772 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22774 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22775 : &dwarf2_per_objfile
->loc
);
22778 /* A helper function that fills in a dwarf2_loclist_baton. */
22781 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22782 struct dwarf2_loclist_baton
*baton
,
22783 const struct attribute
*attr
)
22785 struct dwarf2_per_objfile
*dwarf2_per_objfile
22786 = cu
->per_cu
->dwarf2_per_objfile
;
22787 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22789 section
->read (dwarf2_per_objfile
->objfile
);
22791 baton
->per_cu
= cu
->per_cu
;
22792 gdb_assert (baton
->per_cu
);
22793 /* We don't know how long the location list is, but make sure we
22794 don't run off the edge of the section. */
22795 baton
->size
= section
->size
- DW_UNSND (attr
);
22796 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22797 baton
->base_address
= cu
->base_address
;
22798 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22802 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22803 struct dwarf2_cu
*cu
, int is_block
)
22805 struct dwarf2_per_objfile
*dwarf2_per_objfile
22806 = cu
->per_cu
->dwarf2_per_objfile
;
22807 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22808 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22810 if (attr
->form_is_section_offset ()
22811 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22812 the section. If so, fall through to the complaint in the
22814 && DW_UNSND (attr
) < section
->get_size (objfile
))
22816 struct dwarf2_loclist_baton
*baton
;
22818 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22820 fill_in_loclist_baton (cu
, baton
, attr
);
22822 if (cu
->base_known
== 0)
22823 complaint (_("Location list used without "
22824 "specifying the CU base address."));
22826 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22827 ? dwarf2_loclist_block_index
22828 : dwarf2_loclist_index
);
22829 SYMBOL_LOCATION_BATON (sym
) = baton
;
22833 struct dwarf2_locexpr_baton
*baton
;
22835 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22836 baton
->per_cu
= cu
->per_cu
;
22837 gdb_assert (baton
->per_cu
);
22839 if (attr
->form_is_block ())
22841 /* Note that we're just copying the block's data pointer
22842 here, not the actual data. We're still pointing into the
22843 info_buffer for SYM's objfile; right now we never release
22844 that buffer, but when we do clean up properly this may
22846 baton
->size
= DW_BLOCK (attr
)->size
;
22847 baton
->data
= DW_BLOCK (attr
)->data
;
22851 dwarf2_invalid_attrib_class_complaint ("location description",
22852 sym
->natural_name ());
22856 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22857 ? dwarf2_locexpr_block_index
22858 : dwarf2_locexpr_index
);
22859 SYMBOL_LOCATION_BATON (sym
) = baton
;
22866 dwarf2_per_cu_data::objfile () const
22868 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22870 /* Return the master objfile, so that we can report and look up the
22871 correct file containing this variable. */
22872 if (objfile
->separate_debug_objfile_backlink
)
22873 objfile
= objfile
->separate_debug_objfile_backlink
;
22878 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22879 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22880 CU_HEADERP first. */
22882 static const struct comp_unit_head
*
22883 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22884 const struct dwarf2_per_cu_data
*per_cu
)
22886 const gdb_byte
*info_ptr
;
22889 return &per_cu
->cu
->header
;
22891 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22893 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22894 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22895 rcuh_kind::COMPILE
);
22903 dwarf2_per_cu_data::addr_size () const
22905 struct comp_unit_head cu_header_local
;
22906 const struct comp_unit_head
*cu_headerp
;
22908 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22910 return cu_headerp
->addr_size
;
22916 dwarf2_per_cu_data::offset_size () const
22918 struct comp_unit_head cu_header_local
;
22919 const struct comp_unit_head
*cu_headerp
;
22921 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22923 return cu_headerp
->offset_size
;
22929 dwarf2_per_cu_data::ref_addr_size () const
22931 struct comp_unit_head cu_header_local
;
22932 const struct comp_unit_head
*cu_headerp
;
22934 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22936 if (cu_headerp
->version
== 2)
22937 return cu_headerp
->addr_size
;
22939 return cu_headerp
->offset_size
;
22945 dwarf2_per_cu_data::text_offset () const
22947 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22949 return objfile
->text_section_offset ();
22955 dwarf2_per_cu_data::addr_type () const
22957 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22958 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22959 struct type
*addr_type
= lookup_pointer_type (void_type
);
22960 int addr_size
= this->addr_size ();
22962 if (TYPE_LENGTH (addr_type
) == addr_size
)
22965 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22969 /* A helper function for dwarf2_find_containing_comp_unit that returns
22970 the index of the result, and that searches a vector. It will
22971 return a result even if the offset in question does not actually
22972 occur in any CU. This is separate so that it can be unit
22976 dwarf2_find_containing_comp_unit
22977 (sect_offset sect_off
,
22978 unsigned int offset_in_dwz
,
22979 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22984 high
= all_comp_units
.size () - 1;
22987 struct dwarf2_per_cu_data
*mid_cu
;
22988 int mid
= low
+ (high
- low
) / 2;
22990 mid_cu
= all_comp_units
[mid
];
22991 if (mid_cu
->is_dwz
> offset_in_dwz
22992 || (mid_cu
->is_dwz
== offset_in_dwz
22993 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
22998 gdb_assert (low
== high
);
23002 /* Locate the .debug_info compilation unit from CU's objfile which contains
23003 the DIE at OFFSET. Raises an error on failure. */
23005 static struct dwarf2_per_cu_data
*
23006 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23007 unsigned int offset_in_dwz
,
23008 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23011 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23012 dwarf2_per_objfile
->all_comp_units
);
23013 struct dwarf2_per_cu_data
*this_cu
23014 = dwarf2_per_objfile
->all_comp_units
[low
];
23016 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23018 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23019 error (_("Dwarf Error: could not find partial DIE containing "
23020 "offset %s [in module %s]"),
23021 sect_offset_str (sect_off
),
23022 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23024 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
23026 return dwarf2_per_objfile
->all_comp_units
[low
-1];
23030 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
23031 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23032 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23033 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23040 namespace selftests
{
23041 namespace find_containing_comp_unit
{
23046 struct dwarf2_per_cu_data one
{};
23047 struct dwarf2_per_cu_data two
{};
23048 struct dwarf2_per_cu_data three
{};
23049 struct dwarf2_per_cu_data four
{};
23052 two
.sect_off
= sect_offset (one
.length
);
23057 four
.sect_off
= sect_offset (three
.length
);
23061 std::vector
<dwarf2_per_cu_data
*> units
;
23062 units
.push_back (&one
);
23063 units
.push_back (&two
);
23064 units
.push_back (&three
);
23065 units
.push_back (&four
);
23069 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23070 SELF_CHECK (units
[result
] == &one
);
23071 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23072 SELF_CHECK (units
[result
] == &one
);
23073 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23074 SELF_CHECK (units
[result
] == &two
);
23076 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23077 SELF_CHECK (units
[result
] == &three
);
23078 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23079 SELF_CHECK (units
[result
] == &three
);
23080 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23081 SELF_CHECK (units
[result
] == &four
);
23087 #endif /* GDB_SELF_TEST */
23089 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23091 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23092 : per_cu (per_cu_
),
23094 has_loclist (false),
23095 checked_producer (false),
23096 producer_is_gxx_lt_4_6 (false),
23097 producer_is_gcc_lt_4_3 (false),
23098 producer_is_icc (false),
23099 producer_is_icc_lt_14 (false),
23100 producer_is_codewarrior (false),
23101 processing_has_namespace_info (false)
23106 /* Destroy a dwarf2_cu. */
23108 dwarf2_cu::~dwarf2_cu ()
23113 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23116 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23117 enum language pretend_language
)
23119 struct attribute
*attr
;
23121 /* Set the language we're debugging. */
23122 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23123 if (attr
!= nullptr)
23124 set_cu_language (DW_UNSND (attr
), cu
);
23127 cu
->language
= pretend_language
;
23128 cu
->language_defn
= language_def (cu
->language
);
23131 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23134 /* Increase the age counter on each cached compilation unit, and free
23135 any that are too old. */
23138 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23140 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23142 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23143 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23144 while (per_cu
!= NULL
)
23146 per_cu
->cu
->last_used
++;
23147 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23148 dwarf2_mark (per_cu
->cu
);
23149 per_cu
= per_cu
->cu
->read_in_chain
;
23152 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23153 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23154 while (per_cu
!= NULL
)
23156 struct dwarf2_per_cu_data
*next_cu
;
23158 next_cu
= per_cu
->cu
->read_in_chain
;
23160 if (!per_cu
->cu
->mark
)
23163 *last_chain
= next_cu
;
23166 last_chain
= &per_cu
->cu
->read_in_chain
;
23172 /* Remove a single compilation unit from the cache. */
23175 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23177 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23178 struct dwarf2_per_objfile
*dwarf2_per_objfile
23179 = target_per_cu
->dwarf2_per_objfile
;
23181 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23182 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23183 while (per_cu
!= NULL
)
23185 struct dwarf2_per_cu_data
*next_cu
;
23187 next_cu
= per_cu
->cu
->read_in_chain
;
23189 if (per_cu
== target_per_cu
)
23193 *last_chain
= next_cu
;
23197 last_chain
= &per_cu
->cu
->read_in_chain
;
23203 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23204 We store these in a hash table separate from the DIEs, and preserve them
23205 when the DIEs are flushed out of cache.
23207 The CU "per_cu" pointer is needed because offset alone is not enough to
23208 uniquely identify the type. A file may have multiple .debug_types sections,
23209 or the type may come from a DWO file. Furthermore, while it's more logical
23210 to use per_cu->section+offset, with Fission the section with the data is in
23211 the DWO file but we don't know that section at the point we need it.
23212 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23213 because we can enter the lookup routine, get_die_type_at_offset, from
23214 outside this file, and thus won't necessarily have PER_CU->cu.
23215 Fortunately, PER_CU is stable for the life of the objfile. */
23217 struct dwarf2_per_cu_offset_and_type
23219 const struct dwarf2_per_cu_data
*per_cu
;
23220 sect_offset sect_off
;
23224 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23227 per_cu_offset_and_type_hash (const void *item
)
23229 const struct dwarf2_per_cu_offset_and_type
*ofs
23230 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23232 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23235 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23238 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23240 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23241 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23242 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23243 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23245 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23246 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23249 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23250 table if necessary. For convenience, return TYPE.
23252 The DIEs reading must have careful ordering to:
23253 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23254 reading current DIE.
23255 * Not trying to dereference contents of still incompletely read in types
23256 while reading in other DIEs.
23257 * Enable referencing still incompletely read in types just by a pointer to
23258 the type without accessing its fields.
23260 Therefore caller should follow these rules:
23261 * Try to fetch any prerequisite types we may need to build this DIE type
23262 before building the type and calling set_die_type.
23263 * After building type call set_die_type for current DIE as soon as
23264 possible before fetching more types to complete the current type.
23265 * Make the type as complete as possible before fetching more types. */
23267 static struct type
*
23268 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23270 struct dwarf2_per_objfile
*dwarf2_per_objfile
23271 = cu
->per_cu
->dwarf2_per_objfile
;
23272 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23273 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23274 struct attribute
*attr
;
23275 struct dynamic_prop prop
;
23277 /* For Ada types, make sure that the gnat-specific data is always
23278 initialized (if not already set). There are a few types where
23279 we should not be doing so, because the type-specific area is
23280 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23281 where the type-specific area is used to store the floatformat).
23282 But this is not a problem, because the gnat-specific information
23283 is actually not needed for these types. */
23284 if (need_gnat_info (cu
)
23285 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23286 && TYPE_CODE (type
) != TYPE_CODE_FLT
23287 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23288 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23289 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23290 && !HAVE_GNAT_AUX_INFO (type
))
23291 INIT_GNAT_SPECIFIC (type
);
23293 /* Read DW_AT_allocated and set in type. */
23294 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23295 if (attr
!= NULL
&& attr
->form_is_block ())
23297 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23298 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23299 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23301 else if (attr
!= NULL
)
23303 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23304 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23305 sect_offset_str (die
->sect_off
));
23308 /* Read DW_AT_associated and set in type. */
23309 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23310 if (attr
!= NULL
&& attr
->form_is_block ())
23312 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23313 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23314 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23316 else if (attr
!= NULL
)
23318 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23319 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23320 sect_offset_str (die
->sect_off
));
23323 /* Read DW_AT_data_location and set in type. */
23324 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23325 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23326 cu
->per_cu
->addr_type ()))
23327 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23329 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23330 dwarf2_per_objfile
->die_type_hash
23331 = htab_up (htab_create_alloc (127,
23332 per_cu_offset_and_type_hash
,
23333 per_cu_offset_and_type_eq
,
23334 NULL
, xcalloc
, xfree
));
23336 ofs
.per_cu
= cu
->per_cu
;
23337 ofs
.sect_off
= die
->sect_off
;
23339 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23340 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23342 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23343 sect_offset_str (die
->sect_off
));
23344 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23345 struct dwarf2_per_cu_offset_and_type
);
23350 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23351 or return NULL if the die does not have a saved type. */
23353 static struct type
*
23354 get_die_type_at_offset (sect_offset sect_off
,
23355 struct dwarf2_per_cu_data
*per_cu
)
23357 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23358 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23360 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23363 ofs
.per_cu
= per_cu
;
23364 ofs
.sect_off
= sect_off
;
23365 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23366 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23373 /* Look up the type for DIE in CU in die_type_hash,
23374 or return NULL if DIE does not have a saved type. */
23376 static struct type
*
23377 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23379 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23382 /* Add a dependence relationship from CU to REF_PER_CU. */
23385 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23386 struct dwarf2_per_cu_data
*ref_per_cu
)
23390 if (cu
->dependencies
== NULL
)
23392 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23393 NULL
, &cu
->comp_unit_obstack
,
23394 hashtab_obstack_allocate
,
23395 dummy_obstack_deallocate
);
23397 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23399 *slot
= ref_per_cu
;
23402 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23403 Set the mark field in every compilation unit in the
23404 cache that we must keep because we are keeping CU. */
23407 dwarf2_mark_helper (void **slot
, void *data
)
23409 struct dwarf2_per_cu_data
*per_cu
;
23411 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23413 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23414 reading of the chain. As such dependencies remain valid it is not much
23415 useful to track and undo them during QUIT cleanups. */
23416 if (per_cu
->cu
== NULL
)
23419 if (per_cu
->cu
->mark
)
23421 per_cu
->cu
->mark
= true;
23423 if (per_cu
->cu
->dependencies
!= NULL
)
23424 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23429 /* Set the mark field in CU and in every other compilation unit in the
23430 cache that we must keep because we are keeping CU. */
23433 dwarf2_mark (struct dwarf2_cu
*cu
)
23438 if (cu
->dependencies
!= NULL
)
23439 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23443 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23447 per_cu
->cu
->mark
= false;
23448 per_cu
= per_cu
->cu
->read_in_chain
;
23452 /* Trivial hash function for partial_die_info: the hash value of a DIE
23453 is its offset in .debug_info for this objfile. */
23456 partial_die_hash (const void *item
)
23458 const struct partial_die_info
*part_die
23459 = (const struct partial_die_info
*) item
;
23461 return to_underlying (part_die
->sect_off
);
23464 /* Trivial comparison function for partial_die_info structures: two DIEs
23465 are equal if they have the same offset. */
23468 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23470 const struct partial_die_info
*part_die_lhs
23471 = (const struct partial_die_info
*) item_lhs
;
23472 const struct partial_die_info
*part_die_rhs
23473 = (const struct partial_die_info
*) item_rhs
;
23475 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23478 struct cmd_list_element
*set_dwarf_cmdlist
;
23479 struct cmd_list_element
*show_dwarf_cmdlist
;
23482 set_dwarf_cmd (const char *args
, int from_tty
)
23484 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23489 show_dwarf_cmd (const char *args
, int from_tty
)
23491 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23495 show_check_physname (struct ui_file
*file
, int from_tty
,
23496 struct cmd_list_element
*c
, const char *value
)
23498 fprintf_filtered (file
,
23499 _("Whether to check \"physname\" is %s.\n"),
23503 void _initialize_dwarf2_read ();
23505 _initialize_dwarf2_read ()
23507 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23508 Set DWARF specific variables.\n\
23509 Configure DWARF variables such as the cache size."),
23510 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23511 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23513 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23514 Show DWARF specific variables.\n\
23515 Show DWARF variables such as the cache size."),
23516 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23517 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23519 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23520 &dwarf_max_cache_age
, _("\
23521 Set the upper bound on the age of cached DWARF compilation units."), _("\
23522 Show the upper bound on the age of cached DWARF compilation units."), _("\
23523 A higher limit means that cached compilation units will be stored\n\
23524 in memory longer, and more total memory will be used. Zero disables\n\
23525 caching, which can slow down startup."),
23527 show_dwarf_max_cache_age
,
23528 &set_dwarf_cmdlist
,
23529 &show_dwarf_cmdlist
);
23531 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23532 Set debugging of the DWARF reader."), _("\
23533 Show debugging of the DWARF reader."), _("\
23534 When enabled (non-zero), debugging messages are printed during DWARF\n\
23535 reading and symtab expansion. A value of 1 (one) provides basic\n\
23536 information. A value greater than 1 provides more verbose information."),
23539 &setdebuglist
, &showdebuglist
);
23541 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23542 Set debugging of the DWARF DIE reader."), _("\
23543 Show debugging of the DWARF DIE reader."), _("\
23544 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23545 The value is the maximum depth to print."),
23548 &setdebuglist
, &showdebuglist
);
23550 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23551 Set debugging of the dwarf line reader."), _("\
23552 Show debugging of the dwarf line reader."), _("\
23553 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23554 A value of 1 (one) provides basic information.\n\
23555 A value greater than 1 provides more verbose information."),
23558 &setdebuglist
, &showdebuglist
);
23560 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23561 Set cross-checking of \"physname\" code against demangler."), _("\
23562 Show cross-checking of \"physname\" code against demangler."), _("\
23563 When enabled, GDB's internal \"physname\" code is checked against\n\
23565 NULL
, show_check_physname
,
23566 &setdebuglist
, &showdebuglist
);
23568 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23569 no_class
, &use_deprecated_index_sections
, _("\
23570 Set whether to use deprecated gdb_index sections."), _("\
23571 Show whether to use deprecated gdb_index sections."), _("\
23572 When enabled, deprecated .gdb_index sections are used anyway.\n\
23573 Normally they are ignored either because of a missing feature or\n\
23574 performance issue.\n\
23575 Warning: This option must be enabled before gdb reads the file."),
23578 &setlist
, &showlist
);
23580 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23581 &dwarf2_locexpr_funcs
);
23582 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23583 &dwarf2_loclist_funcs
);
23585 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23586 &dwarf2_block_frame_base_locexpr_funcs
);
23587 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23588 &dwarf2_block_frame_base_loclist_funcs
);
23591 selftests::register_test ("dw2_expand_symtabs_matching",
23592 selftests::dw2_expand_symtabs_matching::run_test
);
23593 selftests::register_test ("dwarf2_find_containing_comp_unit",
23594 selftests::find_containing_comp_unit::run_test
);