1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
49 #include "gdb-demangle.h"
50 #include "filenames.h" /* for DOSish file names */
53 #include "complaints.h"
54 #include "dwarf2/expr.h"
55 #include "dwarf2/loc.h"
56 #include "cp-support.h"
62 #include "typeprint.h"
67 #include "gdbcore.h" /* for gnutarget */
68 #include "gdb/gdb-index.h"
73 #include "namespace.h"
74 #include "gdbsupport/function-view.h"
75 #include "gdbsupport/gdb_optional.h"
76 #include "gdbsupport/underlying.h"
77 #include "gdbsupport/hash_enum.h"
78 #include "filename-seen-cache.h"
82 #include <unordered_map>
83 #include "gdbsupport/selftest.h"
84 #include "rust-lang.h"
85 #include "gdbsupport/pathstuff.h"
86 #include "count-one-bits.h"
87 #include "debuginfod-support.h"
89 /* When == 1, print basic high level tracing messages.
90 When > 1, be more verbose.
91 This is in contrast to the low level DIE reading of dwarf_die_debug. */
92 static unsigned int dwarf_read_debug
= 0;
94 /* When non-zero, dump DIEs after they are read in. */
95 static unsigned int dwarf_die_debug
= 0;
97 /* When non-zero, dump line number entries as they are read in. */
98 unsigned int dwarf_line_debug
= 0;
100 /* When true, cross-check physname against demangler. */
101 static bool check_physname
= false;
103 /* When true, do not reject deprecated .gdb_index sections. */
104 static bool use_deprecated_index_sections
= false;
106 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
108 /* The "aclass" indices for various kinds of computed DWARF symbols. */
110 static int dwarf2_locexpr_index
;
111 static int dwarf2_loclist_index
;
112 static int dwarf2_locexpr_block_index
;
113 static int dwarf2_loclist_block_index
;
115 /* An index into a (C++) symbol name component in a symbol name as
116 recorded in the mapped_index's symbol table. For each C++ symbol
117 in the symbol table, we record one entry for the start of each
118 component in the symbol in a table of name components, and then
119 sort the table, in order to be able to binary search symbol names,
120 ignoring leading namespaces, both completion and regular look up.
121 For example, for symbol "A::B::C", we'll have an entry that points
122 to "A::B::C", another that points to "B::C", and another for "C".
123 Note that function symbols in GDB index have no parameter
124 information, just the function/method names. You can convert a
125 name_component to a "const char *" using the
126 'mapped_index::symbol_name_at(offset_type)' method. */
128 struct name_component
130 /* Offset in the symbol name where the component starts. Stored as
131 a (32-bit) offset instead of a pointer to save memory and improve
132 locality on 64-bit architectures. */
133 offset_type name_offset
;
135 /* The symbol's index in the symbol and constant pool tables of a
140 /* Base class containing bits shared by both .gdb_index and
141 .debug_name indexes. */
143 struct mapped_index_base
145 mapped_index_base () = default;
146 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
148 /* The name_component table (a sorted vector). See name_component's
149 description above. */
150 std::vector
<name_component
> name_components
;
152 /* How NAME_COMPONENTS is sorted. */
153 enum case_sensitivity name_components_casing
;
155 /* Return the number of names in the symbol table. */
156 virtual size_t symbol_name_count () const = 0;
158 /* Get the name of the symbol at IDX in the symbol table. */
159 virtual const char *symbol_name_at (offset_type idx
) const = 0;
161 /* Return whether the name at IDX in the symbol table should be
163 virtual bool symbol_name_slot_invalid (offset_type idx
) const
168 /* Build the symbol name component sorted vector, if we haven't
170 void build_name_components ();
172 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
173 possible matches for LN_NO_PARAMS in the name component
175 std::pair
<std::vector
<name_component
>::const_iterator
,
176 std::vector
<name_component
>::const_iterator
>
177 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
178 enum language lang
) const;
180 /* Prevent deleting/destroying via a base class pointer. */
182 ~mapped_index_base() = default;
185 /* A description of the mapped index. The file format is described in
186 a comment by the code that writes the index. */
187 struct mapped_index final
: public mapped_index_base
189 /* A slot/bucket in the symbol table hash. */
190 struct symbol_table_slot
192 const offset_type name
;
193 const offset_type vec
;
196 /* Index data format version. */
199 /* The address table data. */
200 gdb::array_view
<const gdb_byte
> address_table
;
202 /* The symbol table, implemented as a hash table. */
203 gdb::array_view
<symbol_table_slot
> symbol_table
;
205 /* A pointer to the constant pool. */
206 const char *constant_pool
= nullptr;
208 bool symbol_name_slot_invalid (offset_type idx
) const override
210 const auto &bucket
= this->symbol_table
[idx
];
211 return bucket
.name
== 0 && bucket
.vec
== 0;
214 /* Convenience method to get at the name of the symbol at IDX in the
216 const char *symbol_name_at (offset_type idx
) const override
217 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
219 size_t symbol_name_count () const override
220 { return this->symbol_table
.size (); }
223 /* A description of the mapped .debug_names.
224 Uninitialized map has CU_COUNT 0. */
225 struct mapped_debug_names final
: public mapped_index_base
227 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
228 : dwarf2_per_objfile (dwarf2_per_objfile_
)
231 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
232 bfd_endian dwarf5_byte_order
;
233 bool dwarf5_is_dwarf64
;
234 bool augmentation_is_gdb
;
236 uint32_t cu_count
= 0;
237 uint32_t tu_count
, bucket_count
, name_count
;
238 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
239 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
240 const gdb_byte
*name_table_string_offs_reordered
;
241 const gdb_byte
*name_table_entry_offs_reordered
;
242 const gdb_byte
*entry_pool
;
249 /* Attribute name DW_IDX_*. */
252 /* Attribute form DW_FORM_*. */
255 /* Value if FORM is DW_FORM_implicit_const. */
256 LONGEST implicit_const
;
258 std::vector
<attr
> attr_vec
;
261 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
263 const char *namei_to_name (uint32_t namei
) const;
265 /* Implementation of the mapped_index_base virtual interface, for
266 the name_components cache. */
268 const char *symbol_name_at (offset_type idx
) const override
269 { return namei_to_name (idx
); }
271 size_t symbol_name_count () const override
272 { return this->name_count
; }
275 /* See dwarf2read.h. */
278 get_dwarf2_per_objfile (struct objfile
*objfile
)
280 return dwarf2_objfile_data_key
.get (objfile
);
283 /* Default names of the debugging sections. */
285 /* Note that if the debugging section has been compressed, it might
286 have a name like .zdebug_info. */
288 static const struct dwarf2_debug_sections dwarf2_elf_names
=
290 { ".debug_info", ".zdebug_info" },
291 { ".debug_abbrev", ".zdebug_abbrev" },
292 { ".debug_line", ".zdebug_line" },
293 { ".debug_loc", ".zdebug_loc" },
294 { ".debug_loclists", ".zdebug_loclists" },
295 { ".debug_macinfo", ".zdebug_macinfo" },
296 { ".debug_macro", ".zdebug_macro" },
297 { ".debug_str", ".zdebug_str" },
298 { ".debug_str_offsets", ".zdebug_str_offsets" },
299 { ".debug_line_str", ".zdebug_line_str" },
300 { ".debug_ranges", ".zdebug_ranges" },
301 { ".debug_rnglists", ".zdebug_rnglists" },
302 { ".debug_types", ".zdebug_types" },
303 { ".debug_addr", ".zdebug_addr" },
304 { ".debug_frame", ".zdebug_frame" },
305 { ".eh_frame", NULL
},
306 { ".gdb_index", ".zgdb_index" },
307 { ".debug_names", ".zdebug_names" },
308 { ".debug_aranges", ".zdebug_aranges" },
312 /* List of DWO/DWP sections. */
314 static const struct dwop_section_names
316 struct dwarf2_section_names abbrev_dwo
;
317 struct dwarf2_section_names info_dwo
;
318 struct dwarf2_section_names line_dwo
;
319 struct dwarf2_section_names loc_dwo
;
320 struct dwarf2_section_names loclists_dwo
;
321 struct dwarf2_section_names macinfo_dwo
;
322 struct dwarf2_section_names macro_dwo
;
323 struct dwarf2_section_names str_dwo
;
324 struct dwarf2_section_names str_offsets_dwo
;
325 struct dwarf2_section_names types_dwo
;
326 struct dwarf2_section_names cu_index
;
327 struct dwarf2_section_names tu_index
;
331 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
332 { ".debug_info.dwo", ".zdebug_info.dwo" },
333 { ".debug_line.dwo", ".zdebug_line.dwo" },
334 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
335 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
336 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
337 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
338 { ".debug_str.dwo", ".zdebug_str.dwo" },
339 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
340 { ".debug_types.dwo", ".zdebug_types.dwo" },
341 { ".debug_cu_index", ".zdebug_cu_index" },
342 { ".debug_tu_index", ".zdebug_tu_index" },
345 /* local data types */
347 /* Type used for delaying computation of method physnames.
348 See comments for compute_delayed_physnames. */
349 struct delayed_method_info
351 /* The type to which the method is attached, i.e., its parent class. */
354 /* The index of the method in the type's function fieldlists. */
357 /* The index of the method in the fieldlist. */
360 /* The name of the DIE. */
363 /* The DIE associated with this method. */
364 struct die_info
*die
;
367 /* Internal state when decoding a particular compilation unit. */
370 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
373 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
375 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
376 Create the set of symtabs used by this TU, or if this TU is sharing
377 symtabs with another TU and the symtabs have already been created
378 then restore those symtabs in the line header.
379 We don't need the pc/line-number mapping for type units. */
380 void setup_type_unit_groups (struct die_info
*die
);
382 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
383 buildsym_compunit constructor. */
384 struct compunit_symtab
*start_symtab (const char *name
,
385 const char *comp_dir
,
388 /* Reset the builder. */
389 void reset_builder () { m_builder
.reset (); }
391 /* The header of the compilation unit. */
392 struct comp_unit_head header
{};
394 /* Base address of this compilation unit. */
395 CORE_ADDR base_address
= 0;
397 /* Non-zero if base_address has been set. */
400 /* The language we are debugging. */
401 enum language language
= language_unknown
;
402 const struct language_defn
*language_defn
= nullptr;
404 const char *producer
= nullptr;
407 /* The symtab builder for this CU. This is only non-NULL when full
408 symbols are being read. */
409 std::unique_ptr
<buildsym_compunit
> m_builder
;
412 /* The generic symbol table building routines have separate lists for
413 file scope symbols and all all other scopes (local scopes). So
414 we need to select the right one to pass to add_symbol_to_list().
415 We do it by keeping a pointer to the correct list in list_in_scope.
417 FIXME: The original dwarf code just treated the file scope as the
418 first local scope, and all other local scopes as nested local
419 scopes, and worked fine. Check to see if we really need to
420 distinguish these in buildsym.c. */
421 struct pending
**list_in_scope
= nullptr;
423 /* Hash table holding all the loaded partial DIEs
424 with partial_die->offset.SECT_OFF as hash. */
425 htab_t partial_dies
= nullptr;
427 /* Storage for things with the same lifetime as this read-in compilation
428 unit, including partial DIEs. */
429 auto_obstack comp_unit_obstack
;
431 /* When multiple dwarf2_cu structures are living in memory, this field
432 chains them all together, so that they can be released efficiently.
433 We will probably also want a generation counter so that most-recently-used
434 compilation units are cached... */
435 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
437 /* Backlink to our per_cu entry. */
438 struct dwarf2_per_cu_data
*per_cu
;
440 /* How many compilation units ago was this CU last referenced? */
443 /* A hash table of DIE cu_offset for following references with
444 die_info->offset.sect_off as hash. */
445 htab_t die_hash
= nullptr;
447 /* Full DIEs if read in. */
448 struct die_info
*dies
= nullptr;
450 /* A set of pointers to dwarf2_per_cu_data objects for compilation
451 units referenced by this one. Only set during full symbol processing;
452 partial symbol tables do not have dependencies. */
453 htab_t dependencies
= nullptr;
455 /* Header data from the line table, during full symbol processing. */
456 struct line_header
*line_header
= nullptr;
457 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
458 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
459 this is the DW_TAG_compile_unit die for this CU. We'll hold on
460 to the line header as long as this DIE is being processed. See
461 process_die_scope. */
462 die_info
*line_header_die_owner
= nullptr;
464 /* A list of methods which need to have physnames computed
465 after all type information has been read. */
466 std::vector
<delayed_method_info
> method_list
;
468 /* To be copied to symtab->call_site_htab. */
469 htab_t call_site_htab
= nullptr;
471 /* Non-NULL if this CU came from a DWO file.
472 There is an invariant here that is important to remember:
473 Except for attributes copied from the top level DIE in the "main"
474 (or "stub") file in preparation for reading the DWO file
475 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
476 Either there isn't a DWO file (in which case this is NULL and the point
477 is moot), or there is and either we're not going to read it (in which
478 case this is NULL) or there is and we are reading it (in which case this
480 struct dwo_unit
*dwo_unit
= nullptr;
482 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
483 Note this value comes from the Fission stub CU/TU's DIE. */
484 gdb::optional
<ULONGEST
> addr_base
;
486 /* The DW_AT_rnglists_base attribute if present.
487 Note this value comes from the Fission stub CU/TU's DIE.
488 Also note that the value is zero in the non-DWO case so this value can
489 be used without needing to know whether DWO files are in use or not.
490 N.B. This does not apply to DW_AT_ranges appearing in
491 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
492 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
493 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
494 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
495 ULONGEST ranges_base
= 0;
497 /* When reading debug info generated by older versions of rustc, we
498 have to rewrite some union types to be struct types with a
499 variant part. This rewriting must be done after the CU is fully
500 read in, because otherwise at the point of rewriting some struct
501 type might not have been fully processed. So, we keep a list of
502 all such types here and process them after expansion. */
503 std::vector
<struct type
*> rust_unions
;
505 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
506 files, the value is implicitly zero. For DWARF 5 version DWO files, the
507 value is often implicit and is the size of the header of
508 .debug_str_offsets section (8 or 4, depending on the address size). */
509 gdb::optional
<ULONGEST
> str_offsets_base
;
511 /* Mark used when releasing cached dies. */
514 /* This CU references .debug_loc. See the symtab->locations_valid field.
515 This test is imperfect as there may exist optimized debug code not using
516 any location list and still facing inlining issues if handled as
517 unoptimized code. For a future better test see GCC PR other/32998. */
518 bool has_loclist
: 1;
520 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
521 if all the producer_is_* fields are valid. This information is cached
522 because profiling CU expansion showed excessive time spent in
523 producer_is_gxx_lt_4_6. */
524 bool checked_producer
: 1;
525 bool producer_is_gxx_lt_4_6
: 1;
526 bool producer_is_gcc_lt_4_3
: 1;
527 bool producer_is_icc
: 1;
528 bool producer_is_icc_lt_14
: 1;
529 bool producer_is_codewarrior
: 1;
531 /* When true, the file that we're processing is known to have
532 debugging info for C++ namespaces. GCC 3.3.x did not produce
533 this information, but later versions do. */
535 bool processing_has_namespace_info
: 1;
537 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
539 /* If this CU was inherited by another CU (via specification,
540 abstract_origin, etc), this is the ancestor CU. */
543 /* Get the buildsym_compunit for this CU. */
544 buildsym_compunit
*get_builder ()
546 /* If this CU has a builder associated with it, use that. */
547 if (m_builder
!= nullptr)
548 return m_builder
.get ();
550 /* Otherwise, search ancestors for a valid builder. */
551 if (ancestor
!= nullptr)
552 return ancestor
->get_builder ();
558 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
559 This includes type_unit_group and quick_file_names. */
561 struct stmt_list_hash
563 /* The DWO unit this table is from or NULL if there is none. */
564 struct dwo_unit
*dwo_unit
;
566 /* Offset in .debug_line or .debug_line.dwo. */
567 sect_offset line_sect_off
;
570 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
571 an object of this type. */
573 struct type_unit_group
575 /* dwarf2read.c's main "handle" on a TU symtab.
576 To simplify things we create an artificial CU that "includes" all the
577 type units using this stmt_list so that the rest of the code still has
578 a "per_cu" handle on the symtab. */
579 struct dwarf2_per_cu_data per_cu
;
581 /* The TUs that share this DW_AT_stmt_list entry.
582 This is added to while parsing type units to build partial symtabs,
583 and is deleted afterwards and not used again. */
584 std::vector
<signatured_type
*> *tus
;
586 /* The compunit symtab.
587 Type units in a group needn't all be defined in the same source file,
588 so we create an essentially anonymous symtab as the compunit symtab. */
589 struct compunit_symtab
*compunit_symtab
;
591 /* The data used to construct the hash key. */
592 struct stmt_list_hash hash
;
594 /* The symbol tables for this TU (obtained from the files listed in
596 WARNING: The order of entries here must match the order of entries
597 in the line header. After the first TU using this type_unit_group, the
598 line header for the subsequent TUs is recreated from this. This is done
599 because we need to use the same symtabs for each TU using the same
600 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
601 there's no guarantee the line header doesn't have duplicate entries. */
602 struct symtab
**symtabs
;
605 /* These sections are what may appear in a (real or virtual) DWO file. */
609 struct dwarf2_section_info abbrev
;
610 struct dwarf2_section_info line
;
611 struct dwarf2_section_info loc
;
612 struct dwarf2_section_info loclists
;
613 struct dwarf2_section_info macinfo
;
614 struct dwarf2_section_info macro
;
615 struct dwarf2_section_info str
;
616 struct dwarf2_section_info str_offsets
;
617 /* In the case of a virtual DWO file, these two are unused. */
618 struct dwarf2_section_info info
;
619 std::vector
<dwarf2_section_info
> types
;
622 /* CUs/TUs in DWP/DWO files. */
626 /* Backlink to the containing struct dwo_file. */
627 struct dwo_file
*dwo_file
;
629 /* The "id" that distinguishes this CU/TU.
630 .debug_info calls this "dwo_id", .debug_types calls this "signature".
631 Since signatures came first, we stick with it for consistency. */
634 /* The section this CU/TU lives in, in the DWO file. */
635 struct dwarf2_section_info
*section
;
637 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
638 sect_offset sect_off
;
641 /* For types, offset in the type's DIE of the type defined by this TU. */
642 cu_offset type_offset_in_tu
;
645 /* include/dwarf2.h defines the DWP section codes.
646 It defines a max value but it doesn't define a min value, which we
647 use for error checking, so provide one. */
649 enum dwp_v2_section_ids
654 /* Data for one DWO file.
656 This includes virtual DWO files (a virtual DWO file is a DWO file as it
657 appears in a DWP file). DWP files don't really have DWO files per se -
658 comdat folding of types "loses" the DWO file they came from, and from
659 a high level view DWP files appear to contain a mass of random types.
660 However, to maintain consistency with the non-DWP case we pretend DWP
661 files contain virtual DWO files, and we assign each TU with one virtual
662 DWO file (generally based on the line and abbrev section offsets -
663 a heuristic that seems to work in practice). */
667 dwo_file () = default;
668 DISABLE_COPY_AND_ASSIGN (dwo_file
);
670 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
671 For virtual DWO files the name is constructed from the section offsets
672 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
673 from related CU+TUs. */
674 const char *dwo_name
= nullptr;
676 /* The DW_AT_comp_dir attribute. */
677 const char *comp_dir
= nullptr;
679 /* The bfd, when the file is open. Otherwise this is NULL.
680 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
681 gdb_bfd_ref_ptr dbfd
;
683 /* The sections that make up this DWO file.
684 Remember that for virtual DWO files in DWP V2, these are virtual
685 sections (for lack of a better name). */
686 struct dwo_sections sections
{};
688 /* The CUs in the file.
689 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
690 an extension to handle LLVM's Link Time Optimization output (where
691 multiple source files may be compiled into a single object/dwo pair). */
694 /* Table of TUs in the file.
695 Each element is a struct dwo_unit. */
699 /* These sections are what may appear in a DWP file. */
703 /* These are used by both DWP version 1 and 2. */
704 struct dwarf2_section_info str
;
705 struct dwarf2_section_info cu_index
;
706 struct dwarf2_section_info tu_index
;
708 /* These are only used by DWP version 2 files.
709 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
710 sections are referenced by section number, and are not recorded here.
711 In DWP version 2 there is at most one copy of all these sections, each
712 section being (effectively) comprised of the concatenation of all of the
713 individual sections that exist in the version 1 format.
714 To keep the code simple we treat each of these concatenated pieces as a
715 section itself (a virtual section?). */
716 struct dwarf2_section_info abbrev
;
717 struct dwarf2_section_info info
;
718 struct dwarf2_section_info line
;
719 struct dwarf2_section_info loc
;
720 struct dwarf2_section_info macinfo
;
721 struct dwarf2_section_info macro
;
722 struct dwarf2_section_info str_offsets
;
723 struct dwarf2_section_info types
;
726 /* These sections are what may appear in a virtual DWO file in DWP version 1.
727 A virtual DWO file is a DWO file as it appears in a DWP file. */
729 struct virtual_v1_dwo_sections
731 struct dwarf2_section_info abbrev
;
732 struct dwarf2_section_info line
;
733 struct dwarf2_section_info loc
;
734 struct dwarf2_section_info macinfo
;
735 struct dwarf2_section_info macro
;
736 struct dwarf2_section_info str_offsets
;
737 /* Each DWP hash table entry records one CU or one TU.
738 That is recorded here, and copied to dwo_unit.section. */
739 struct dwarf2_section_info info_or_types
;
742 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
743 In version 2, the sections of the DWO files are concatenated together
744 and stored in one section of that name. Thus each ELF section contains
745 several "virtual" sections. */
747 struct virtual_v2_dwo_sections
749 bfd_size_type abbrev_offset
;
750 bfd_size_type abbrev_size
;
752 bfd_size_type line_offset
;
753 bfd_size_type line_size
;
755 bfd_size_type loc_offset
;
756 bfd_size_type loc_size
;
758 bfd_size_type macinfo_offset
;
759 bfd_size_type macinfo_size
;
761 bfd_size_type macro_offset
;
762 bfd_size_type macro_size
;
764 bfd_size_type str_offsets_offset
;
765 bfd_size_type str_offsets_size
;
767 /* Each DWP hash table entry records one CU or one TU.
768 That is recorded here, and copied to dwo_unit.section. */
769 bfd_size_type info_or_types_offset
;
770 bfd_size_type info_or_types_size
;
773 /* Contents of DWP hash tables. */
775 struct dwp_hash_table
777 uint32_t version
, nr_columns
;
778 uint32_t nr_units
, nr_slots
;
779 const gdb_byte
*hash_table
, *unit_table
;
784 const gdb_byte
*indices
;
788 /* This is indexed by column number and gives the id of the section
790 #define MAX_NR_V2_DWO_SECTIONS \
791 (1 /* .debug_info or .debug_types */ \
792 + 1 /* .debug_abbrev */ \
793 + 1 /* .debug_line */ \
794 + 1 /* .debug_loc */ \
795 + 1 /* .debug_str_offsets */ \
796 + 1 /* .debug_macro or .debug_macinfo */)
797 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
798 const gdb_byte
*offsets
;
799 const gdb_byte
*sizes
;
804 /* Data for one DWP file. */
808 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
810 dbfd (std::move (abfd
))
814 /* Name of the file. */
817 /* File format version. */
821 gdb_bfd_ref_ptr dbfd
;
823 /* Section info for this file. */
824 struct dwp_sections sections
{};
826 /* Table of CUs in the file. */
827 const struct dwp_hash_table
*cus
= nullptr;
829 /* Table of TUs in the file. */
830 const struct dwp_hash_table
*tus
= nullptr;
832 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
836 /* Table to map ELF section numbers to their sections.
837 This is only needed for the DWP V1 file format. */
838 unsigned int num_sections
= 0;
839 asection
**elf_sections
= nullptr;
842 /* Struct used to pass misc. parameters to read_die_and_children, et
843 al. which are used for both .debug_info and .debug_types dies.
844 All parameters here are unchanging for the life of the call. This
845 struct exists to abstract away the constant parameters of die reading. */
847 struct die_reader_specs
849 /* The bfd of die_section. */
852 /* The CU of the DIE we are parsing. */
853 struct dwarf2_cu
*cu
;
855 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
856 struct dwo_file
*dwo_file
;
858 /* The section the die comes from.
859 This is either .debug_info or .debug_types, or the .dwo variants. */
860 struct dwarf2_section_info
*die_section
;
862 /* die_section->buffer. */
863 const gdb_byte
*buffer
;
865 /* The end of the buffer. */
866 const gdb_byte
*buffer_end
;
868 /* The abbreviation table to use when reading the DIEs. */
869 struct abbrev_table
*abbrev_table
;
872 /* A subclass of die_reader_specs that holds storage and has complex
873 constructor and destructor behavior. */
875 class cutu_reader
: public die_reader_specs
879 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
880 struct abbrev_table
*abbrev_table
,
884 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
885 struct dwarf2_cu
*parent_cu
= nullptr,
886 struct dwo_file
*dwo_file
= nullptr);
888 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
890 const gdb_byte
*info_ptr
= nullptr;
891 struct die_info
*comp_unit_die
= nullptr;
892 bool dummy_p
= false;
894 /* Release the new CU, putting it on the chain. This cannot be done
899 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
900 int use_existing_cu
);
902 struct dwarf2_per_cu_data
*m_this_cu
;
903 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
905 /* The ordinary abbreviation table. */
906 abbrev_table_up m_abbrev_table_holder
;
908 /* The DWO abbreviation table. */
909 abbrev_table_up m_dwo_abbrev_table
;
912 /* When we construct a partial symbol table entry we only
913 need this much information. */
914 struct partial_die_info
: public allocate_on_obstack
916 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
918 /* Disable assign but still keep copy ctor, which is needed
919 load_partial_dies. */
920 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
922 /* Adjust the partial die before generating a symbol for it. This
923 function may set the is_external flag or change the DIE's
925 void fixup (struct dwarf2_cu
*cu
);
927 /* Read a minimal amount of information into the minimal die
929 const gdb_byte
*read (const struct die_reader_specs
*reader
,
930 const struct abbrev_info
&abbrev
,
931 const gdb_byte
*info_ptr
);
933 /* Offset of this DIE. */
934 const sect_offset sect_off
;
936 /* DWARF-2 tag for this DIE. */
937 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
939 /* Assorted flags describing the data found in this DIE. */
940 const unsigned int has_children
: 1;
942 unsigned int is_external
: 1;
943 unsigned int is_declaration
: 1;
944 unsigned int has_type
: 1;
945 unsigned int has_specification
: 1;
946 unsigned int has_pc_info
: 1;
947 unsigned int may_be_inlined
: 1;
949 /* This DIE has been marked DW_AT_main_subprogram. */
950 unsigned int main_subprogram
: 1;
952 /* Flag set if the SCOPE field of this structure has been
954 unsigned int scope_set
: 1;
956 /* Flag set if the DIE has a byte_size attribute. */
957 unsigned int has_byte_size
: 1;
959 /* Flag set if the DIE has a DW_AT_const_value attribute. */
960 unsigned int has_const_value
: 1;
962 /* Flag set if any of the DIE's children are template arguments. */
963 unsigned int has_template_arguments
: 1;
965 /* Flag set if fixup has been called on this die. */
966 unsigned int fixup_called
: 1;
968 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
969 unsigned int is_dwz
: 1;
971 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
972 unsigned int spec_is_dwz
: 1;
974 /* The name of this DIE. Normally the value of DW_AT_name, but
975 sometimes a default name for unnamed DIEs. */
976 const char *name
= nullptr;
978 /* The linkage name, if present. */
979 const char *linkage_name
= nullptr;
981 /* The scope to prepend to our children. This is generally
982 allocated on the comp_unit_obstack, so will disappear
983 when this compilation unit leaves the cache. */
984 const char *scope
= nullptr;
986 /* Some data associated with the partial DIE. The tag determines
987 which field is live. */
990 /* The location description associated with this DIE, if any. */
991 struct dwarf_block
*locdesc
;
992 /* The offset of an import, for DW_TAG_imported_unit. */
993 sect_offset sect_off
;
996 /* If HAS_PC_INFO, the PC range associated with this DIE. */
998 CORE_ADDR highpc
= 0;
1000 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1001 DW_AT_sibling, if any. */
1002 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1003 could return DW_AT_sibling values to its caller load_partial_dies. */
1004 const gdb_byte
*sibling
= nullptr;
1006 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1007 DW_AT_specification (or DW_AT_abstract_origin or
1008 DW_AT_extension). */
1009 sect_offset spec_offset
{};
1011 /* Pointers to this DIE's parent, first child, and next sibling,
1013 struct partial_die_info
*die_parent
= nullptr;
1014 struct partial_die_info
*die_child
= nullptr;
1015 struct partial_die_info
*die_sibling
= nullptr;
1017 friend struct partial_die_info
*
1018 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1021 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1022 partial_die_info (sect_offset sect_off
)
1023 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1027 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1029 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1034 has_specification
= 0;
1037 main_subprogram
= 0;
1040 has_const_value
= 0;
1041 has_template_arguments
= 0;
1048 /* This data structure holds a complete die structure. */
1051 /* DWARF-2 tag for this DIE. */
1052 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1054 /* Number of attributes */
1055 unsigned char num_attrs
;
1057 /* True if we're presently building the full type name for the
1058 type derived from this DIE. */
1059 unsigned char building_fullname
: 1;
1061 /* True if this die is in process. PR 16581. */
1062 unsigned char in_process
: 1;
1064 /* True if this DIE has children. */
1065 unsigned char has_children
: 1;
1068 unsigned int abbrev
;
1070 /* Offset in .debug_info or .debug_types section. */
1071 sect_offset sect_off
;
1073 /* The dies in a compilation unit form an n-ary tree. PARENT
1074 points to this die's parent; CHILD points to the first child of
1075 this node; and all the children of a given node are chained
1076 together via their SIBLING fields. */
1077 struct die_info
*child
; /* Its first child, if any. */
1078 struct die_info
*sibling
; /* Its next sibling, if any. */
1079 struct die_info
*parent
; /* Its parent, if any. */
1081 /* An array of attributes, with NUM_ATTRS elements. There may be
1082 zero, but it's not common and zero-sized arrays are not
1083 sufficiently portable C. */
1084 struct attribute attrs
[1];
1087 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1088 but this would require a corresponding change in unpack_field_as_long
1090 static int bits_per_byte
= 8;
1092 /* When reading a variant or variant part, we track a bit more
1093 information about the field, and store it in an object of this
1096 struct variant_field
1098 /* If we see a DW_TAG_variant, then this will be the discriminant
1100 ULONGEST discriminant_value
;
1101 /* If we see a DW_TAG_variant, then this will be set if this is the
1103 bool default_branch
;
1104 /* While reading a DW_TAG_variant_part, this will be set if this
1105 field is the discriminant. */
1106 bool is_discriminant
;
1111 int accessibility
= 0;
1113 /* Extra information to describe a variant or variant part. */
1114 struct variant_field variant
{};
1115 struct field field
{};
1120 const char *name
= nullptr;
1121 std::vector
<struct fn_field
> fnfields
;
1124 /* The routines that read and process dies for a C struct or C++ class
1125 pass lists of data member fields and lists of member function fields
1126 in an instance of a field_info structure, as defined below. */
1129 /* List of data member and baseclasses fields. */
1130 std::vector
<struct nextfield
> fields
;
1131 std::vector
<struct nextfield
> baseclasses
;
1133 /* Set if the accessibility of one of the fields is not public. */
1134 int non_public_fields
= 0;
1136 /* Member function fieldlist array, contains name of possibly overloaded
1137 member function, number of overloaded member functions and a pointer
1138 to the head of the member function field chain. */
1139 std::vector
<struct fnfieldlist
> fnfieldlists
;
1141 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1142 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1143 std::vector
<struct decl_field
> typedef_field_list
;
1145 /* Nested types defined by this class and the number of elements in this
1147 std::vector
<struct decl_field
> nested_types_list
;
1149 /* Return the total number of fields (including baseclasses). */
1150 int nfields () const
1152 return fields
.size () + baseclasses
.size ();
1156 /* Loaded secondary compilation units are kept in memory until they
1157 have not been referenced for the processing of this many
1158 compilation units. Set this to zero to disable caching. Cache
1159 sizes of up to at least twenty will improve startup time for
1160 typical inter-CU-reference binaries, at an obvious memory cost. */
1161 static int dwarf_max_cache_age
= 5;
1163 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1164 struct cmd_list_element
*c
, const char *value
)
1166 fprintf_filtered (file
, _("The upper bound on the age of cached "
1167 "DWARF compilation units is %s.\n"),
1171 /* local function prototypes */
1173 static void dwarf2_find_base_address (struct die_info
*die
,
1174 struct dwarf2_cu
*cu
);
1176 static dwarf2_psymtab
*create_partial_symtab
1177 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1179 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1180 const gdb_byte
*info_ptr
,
1181 struct die_info
*type_unit_die
);
1183 static void dwarf2_build_psymtabs_hard
1184 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1186 static void scan_partial_symbols (struct partial_die_info
*,
1187 CORE_ADDR
*, CORE_ADDR
*,
1188 int, struct dwarf2_cu
*);
1190 static void add_partial_symbol (struct partial_die_info
*,
1191 struct dwarf2_cu
*);
1193 static void add_partial_namespace (struct partial_die_info
*pdi
,
1194 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1195 int set_addrmap
, struct dwarf2_cu
*cu
);
1197 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1198 CORE_ADDR
*highpc
, int set_addrmap
,
1199 struct dwarf2_cu
*cu
);
1201 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1202 struct dwarf2_cu
*cu
);
1204 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1205 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1206 int need_pc
, struct dwarf2_cu
*cu
);
1208 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1210 static struct partial_die_info
*load_partial_dies
1211 (const struct die_reader_specs
*, const gdb_byte
*, int);
1213 /* A pair of partial_die_info and compilation unit. */
1214 struct cu_partial_die_info
1216 /* The compilation unit of the partial_die_info. */
1217 struct dwarf2_cu
*cu
;
1218 /* A partial_die_info. */
1219 struct partial_die_info
*pdi
;
1221 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1227 cu_partial_die_info () = delete;
1230 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1231 struct dwarf2_cu
*);
1233 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1234 struct attribute
*, struct attr_abbrev
*,
1235 const gdb_byte
*, bool *need_reprocess
);
1237 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1238 struct attribute
*attr
);
1240 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1242 static LONGEST read_checked_initial_length_and_offset
1243 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1244 unsigned int *, unsigned int *);
1246 static sect_offset read_abbrev_offset
1247 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1248 struct dwarf2_section_info
*, sect_offset
);
1250 static const char *read_indirect_string
1251 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1252 const struct comp_unit_head
*, unsigned int *);
1254 static const char *read_indirect_line_string
1255 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1256 const struct comp_unit_head
*, unsigned int *);
1258 static const char *read_indirect_string_at_offset
1259 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1260 LONGEST str_offset
);
1262 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1266 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1267 ULONGEST str_index
);
1269 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1270 ULONGEST str_index
);
1272 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1274 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1275 struct dwarf2_cu
*);
1277 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1280 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1281 struct dwarf2_cu
*cu
);
1283 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1285 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1286 struct dwarf2_cu
*cu
);
1288 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1290 static struct die_info
*die_specification (struct die_info
*die
,
1291 struct dwarf2_cu
**);
1293 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1294 struct dwarf2_cu
*cu
);
1296 static void dwarf_decode_lines (struct line_header
*, const char *,
1297 struct dwarf2_cu
*, dwarf2_psymtab
*,
1298 CORE_ADDR
, int decode_mapping
);
1300 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1303 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1304 struct dwarf2_cu
*, struct symbol
* = NULL
);
1306 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1307 struct dwarf2_cu
*);
1309 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1312 struct obstack
*obstack
,
1313 struct dwarf2_cu
*cu
, LONGEST
*value
,
1314 const gdb_byte
**bytes
,
1315 struct dwarf2_locexpr_baton
**baton
);
1317 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1319 static int need_gnat_info (struct dwarf2_cu
*);
1321 static struct type
*die_descriptive_type (struct die_info
*,
1322 struct dwarf2_cu
*);
1324 static void set_descriptive_type (struct type
*, struct die_info
*,
1325 struct dwarf2_cu
*);
1327 static struct type
*die_containing_type (struct die_info
*,
1328 struct dwarf2_cu
*);
1330 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1331 struct dwarf2_cu
*);
1333 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1335 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1337 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1339 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1340 const char *suffix
, int physname
,
1341 struct dwarf2_cu
*cu
);
1343 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1345 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1347 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1349 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1351 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1353 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1355 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1356 struct dwarf2_cu
*, dwarf2_psymtab
*);
1358 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1359 values. Keep the items ordered with increasing constraints compliance. */
1362 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1363 PC_BOUNDS_NOT_PRESENT
,
1365 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1366 were present but they do not form a valid range of PC addresses. */
1369 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1372 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1376 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1377 CORE_ADDR
*, CORE_ADDR
*,
1381 static void get_scope_pc_bounds (struct die_info
*,
1382 CORE_ADDR
*, CORE_ADDR
*,
1383 struct dwarf2_cu
*);
1385 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1386 CORE_ADDR
, struct dwarf2_cu
*);
1388 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1389 struct dwarf2_cu
*);
1391 static void dwarf2_attach_fields_to_type (struct field_info
*,
1392 struct type
*, struct dwarf2_cu
*);
1394 static void dwarf2_add_member_fn (struct field_info
*,
1395 struct die_info
*, struct type
*,
1396 struct dwarf2_cu
*);
1398 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1400 struct dwarf2_cu
*);
1402 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1404 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1406 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1408 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1410 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1412 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1414 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1416 static struct type
*read_module_type (struct die_info
*die
,
1417 struct dwarf2_cu
*cu
);
1419 static const char *namespace_name (struct die_info
*die
,
1420 int *is_anonymous
, struct dwarf2_cu
*);
1422 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1424 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1426 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1427 struct dwarf2_cu
*);
1429 static struct die_info
*read_die_and_siblings_1
1430 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1433 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1434 const gdb_byte
*info_ptr
,
1435 const gdb_byte
**new_info_ptr
,
1436 struct die_info
*parent
);
1438 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1439 struct die_info
**, const gdb_byte
*,
1442 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1443 struct die_info
**, const gdb_byte
*);
1445 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1447 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1450 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1452 static const char *dwarf2_full_name (const char *name
,
1453 struct die_info
*die
,
1454 struct dwarf2_cu
*cu
);
1456 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1457 struct dwarf2_cu
*cu
);
1459 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1460 struct dwarf2_cu
**);
1462 static const char *dwarf_tag_name (unsigned int);
1464 static const char *dwarf_attr_name (unsigned int);
1466 static const char *dwarf_form_name (unsigned int);
1468 static const char *dwarf_bool_name (unsigned int);
1470 static const char *dwarf_type_encoding_name (unsigned int);
1472 static struct die_info
*sibling_die (struct die_info
*);
1474 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1476 static void dump_die_for_error (struct die_info
*);
1478 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1481 /*static*/ void dump_die (struct die_info
*, int max_level
);
1483 static void store_in_ref_table (struct die_info
*,
1484 struct dwarf2_cu
*);
1486 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1488 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1490 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1491 const struct attribute
*,
1492 struct dwarf2_cu
**);
1494 static struct die_info
*follow_die_ref (struct die_info
*,
1495 const struct attribute
*,
1496 struct dwarf2_cu
**);
1498 static struct die_info
*follow_die_sig (struct die_info
*,
1499 const struct attribute
*,
1500 struct dwarf2_cu
**);
1502 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1503 struct dwarf2_cu
*);
1505 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1506 const struct attribute
*,
1507 struct dwarf2_cu
*);
1509 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1511 static void read_signatured_type (struct signatured_type
*);
1513 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1514 struct die_info
*die
, struct dwarf2_cu
*cu
,
1515 struct dynamic_prop
*prop
, struct type
*type
);
1517 /* memory allocation interface */
1519 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1521 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1523 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1525 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1526 struct dwarf2_loclist_baton
*baton
,
1527 const struct attribute
*attr
);
1529 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1531 struct dwarf2_cu
*cu
,
1534 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1535 const gdb_byte
*info_ptr
,
1536 struct abbrev_info
*abbrev
);
1538 static hashval_t
partial_die_hash (const void *item
);
1540 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1542 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1543 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1544 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1546 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1547 struct die_info
*comp_unit_die
,
1548 enum language pretend_language
);
1550 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1552 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1554 static struct type
*set_die_type (struct die_info
*, struct type
*,
1555 struct dwarf2_cu
*);
1557 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1559 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1561 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1564 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1567 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1570 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1571 struct dwarf2_per_cu_data
*);
1573 static void dwarf2_mark (struct dwarf2_cu
*);
1575 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1577 static struct type
*get_die_type_at_offset (sect_offset
,
1578 struct dwarf2_per_cu_data
*);
1580 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1582 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1583 enum language pretend_language
);
1585 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1587 /* Class, the destructor of which frees all allocated queue entries. This
1588 will only have work to do if an error was thrown while processing the
1589 dwarf. If no error was thrown then the queue entries should have all
1590 been processed, and freed, as we went along. */
1592 class dwarf2_queue_guard
1595 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1596 : m_per_objfile (per_objfile
)
1600 /* Free any entries remaining on the queue. There should only be
1601 entries left if we hit an error while processing the dwarf. */
1602 ~dwarf2_queue_guard ()
1604 /* Ensure that no memory is allocated by the queue. */
1605 std::queue
<dwarf2_queue_item
> empty
;
1606 std::swap (m_per_objfile
->queue
, empty
);
1609 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1612 dwarf2_per_objfile
*m_per_objfile
;
1615 dwarf2_queue_item::~dwarf2_queue_item ()
1617 /* Anything still marked queued is likely to be in an
1618 inconsistent state, so discard it. */
1621 if (per_cu
->cu
!= NULL
)
1622 free_one_cached_comp_unit (per_cu
);
1627 /* The return type of find_file_and_directory. Note, the enclosed
1628 string pointers are only valid while this object is valid. */
1630 struct file_and_directory
1632 /* The filename. This is never NULL. */
1635 /* The compilation directory. NULL if not known. If we needed to
1636 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1637 points directly to the DW_AT_comp_dir string attribute owned by
1638 the obstack that owns the DIE. */
1639 const char *comp_dir
;
1641 /* If we needed to build a new string for comp_dir, this is what
1642 owns the storage. */
1643 std::string comp_dir_storage
;
1646 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1647 struct dwarf2_cu
*cu
);
1649 static htab_up
allocate_signatured_type_table ();
1651 static htab_up
allocate_dwo_unit_table ();
1653 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1654 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1655 struct dwp_file
*dwp_file
, const char *comp_dir
,
1656 ULONGEST signature
, int is_debug_types
);
1658 static struct dwp_file
*get_dwp_file
1659 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1661 static struct dwo_unit
*lookup_dwo_comp_unit
1662 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1664 static struct dwo_unit
*lookup_dwo_type_unit
1665 (struct signatured_type
*, const char *, const char *);
1667 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1669 /* A unique pointer to a dwo_file. */
1671 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1673 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1675 static void check_producer (struct dwarf2_cu
*cu
);
1677 static void free_line_header_voidp (void *arg
);
1679 /* Various complaints about symbol reading that don't abort the process. */
1682 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1684 complaint (_("statement list doesn't fit in .debug_line section"));
1688 dwarf2_debug_line_missing_file_complaint (void)
1690 complaint (_(".debug_line section has line data without a file"));
1694 dwarf2_debug_line_missing_end_sequence_complaint (void)
1696 complaint (_(".debug_line section has line "
1697 "program sequence without an end"));
1701 dwarf2_complex_location_expr_complaint (void)
1703 complaint (_("location expression too complex"));
1707 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1710 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1715 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1717 complaint (_("debug info runs off end of %s section"
1719 section
->get_name (),
1720 section
->get_file_name ());
1724 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1726 complaint (_("macro debug info contains a "
1727 "malformed macro definition:\n`%s'"),
1732 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1734 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1738 /* Hash function for line_header_hash. */
1741 line_header_hash (const struct line_header
*ofs
)
1743 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1746 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1749 line_header_hash_voidp (const void *item
)
1751 const struct line_header
*ofs
= (const struct line_header
*) item
;
1753 return line_header_hash (ofs
);
1756 /* Equality function for line_header_hash. */
1759 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1761 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1762 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1764 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1765 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1770 /* See declaration. */
1772 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1773 const dwarf2_debug_sections
*names
,
1775 : objfile (objfile_
),
1776 can_copy (can_copy_
)
1779 names
= &dwarf2_elf_names
;
1781 bfd
*obfd
= objfile
->obfd
;
1783 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1784 locate_sections (obfd
, sec
, *names
);
1787 dwarf2_per_objfile::~dwarf2_per_objfile ()
1789 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1790 free_cached_comp_units ();
1792 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1793 per_cu
->imported_symtabs_free ();
1795 for (signatured_type
*sig_type
: all_type_units
)
1796 sig_type
->per_cu
.imported_symtabs_free ();
1798 /* Everything else should be on the objfile obstack. */
1801 /* See declaration. */
1804 dwarf2_per_objfile::free_cached_comp_units ()
1806 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1807 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1808 while (per_cu
!= NULL
)
1810 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1813 *last_chain
= next_cu
;
1818 /* A helper class that calls free_cached_comp_units on
1821 class free_cached_comp_units
1825 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1826 : m_per_objfile (per_objfile
)
1830 ~free_cached_comp_units ()
1832 m_per_objfile
->free_cached_comp_units ();
1835 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1839 dwarf2_per_objfile
*m_per_objfile
;
1842 /* Try to locate the sections we need for DWARF 2 debugging
1843 information and return true if we have enough to do something.
1844 NAMES points to the dwarf2 section names, or is NULL if the standard
1845 ELF names are used. CAN_COPY is true for formats where symbol
1846 interposition is possible and so symbol values must follow copy
1847 relocation rules. */
1850 dwarf2_has_info (struct objfile
*objfile
,
1851 const struct dwarf2_debug_sections
*names
,
1854 if (objfile
->flags
& OBJF_READNEVER
)
1857 struct dwarf2_per_objfile
*dwarf2_per_objfile
1858 = get_dwarf2_per_objfile (objfile
);
1860 if (dwarf2_per_objfile
== NULL
)
1861 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1865 return (!dwarf2_per_objfile
->info
.is_virtual
1866 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1867 && !dwarf2_per_objfile
->abbrev
.is_virtual
1868 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1871 /* When loading sections, we look either for uncompressed section or for
1872 compressed section names. */
1875 section_is_p (const char *section_name
,
1876 const struct dwarf2_section_names
*names
)
1878 if (names
->normal
!= NULL
1879 && strcmp (section_name
, names
->normal
) == 0)
1881 if (names
->compressed
!= NULL
1882 && strcmp (section_name
, names
->compressed
) == 0)
1887 /* See declaration. */
1890 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1891 const dwarf2_debug_sections
&names
)
1893 flagword aflag
= bfd_section_flags (sectp
);
1895 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1898 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1899 > bfd_get_file_size (abfd
))
1901 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1902 warning (_("Discarding section %s which has a section size (%s"
1903 ") larger than the file size [in module %s]"),
1904 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1905 bfd_get_filename (abfd
));
1907 else if (section_is_p (sectp
->name
, &names
.info
))
1909 this->info
.s
.section
= sectp
;
1910 this->info
.size
= bfd_section_size (sectp
);
1912 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1914 this->abbrev
.s
.section
= sectp
;
1915 this->abbrev
.size
= bfd_section_size (sectp
);
1917 else if (section_is_p (sectp
->name
, &names
.line
))
1919 this->line
.s
.section
= sectp
;
1920 this->line
.size
= bfd_section_size (sectp
);
1922 else if (section_is_p (sectp
->name
, &names
.loc
))
1924 this->loc
.s
.section
= sectp
;
1925 this->loc
.size
= bfd_section_size (sectp
);
1927 else if (section_is_p (sectp
->name
, &names
.loclists
))
1929 this->loclists
.s
.section
= sectp
;
1930 this->loclists
.size
= bfd_section_size (sectp
);
1932 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1934 this->macinfo
.s
.section
= sectp
;
1935 this->macinfo
.size
= bfd_section_size (sectp
);
1937 else if (section_is_p (sectp
->name
, &names
.macro
))
1939 this->macro
.s
.section
= sectp
;
1940 this->macro
.size
= bfd_section_size (sectp
);
1942 else if (section_is_p (sectp
->name
, &names
.str
))
1944 this->str
.s
.section
= sectp
;
1945 this->str
.size
= bfd_section_size (sectp
);
1947 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1949 this->str_offsets
.s
.section
= sectp
;
1950 this->str_offsets
.size
= bfd_section_size (sectp
);
1952 else if (section_is_p (sectp
->name
, &names
.line_str
))
1954 this->line_str
.s
.section
= sectp
;
1955 this->line_str
.size
= bfd_section_size (sectp
);
1957 else if (section_is_p (sectp
->name
, &names
.addr
))
1959 this->addr
.s
.section
= sectp
;
1960 this->addr
.size
= bfd_section_size (sectp
);
1962 else if (section_is_p (sectp
->name
, &names
.frame
))
1964 this->frame
.s
.section
= sectp
;
1965 this->frame
.size
= bfd_section_size (sectp
);
1967 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1969 this->eh_frame
.s
.section
= sectp
;
1970 this->eh_frame
.size
= bfd_section_size (sectp
);
1972 else if (section_is_p (sectp
->name
, &names
.ranges
))
1974 this->ranges
.s
.section
= sectp
;
1975 this->ranges
.size
= bfd_section_size (sectp
);
1977 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1979 this->rnglists
.s
.section
= sectp
;
1980 this->rnglists
.size
= bfd_section_size (sectp
);
1982 else if (section_is_p (sectp
->name
, &names
.types
))
1984 struct dwarf2_section_info type_section
;
1986 memset (&type_section
, 0, sizeof (type_section
));
1987 type_section
.s
.section
= sectp
;
1988 type_section
.size
= bfd_section_size (sectp
);
1990 this->types
.push_back (type_section
);
1992 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1994 this->gdb_index
.s
.section
= sectp
;
1995 this->gdb_index
.size
= bfd_section_size (sectp
);
1997 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1999 this->debug_names
.s
.section
= sectp
;
2000 this->debug_names
.size
= bfd_section_size (sectp
);
2002 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2004 this->debug_aranges
.s
.section
= sectp
;
2005 this->debug_aranges
.size
= bfd_section_size (sectp
);
2008 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2009 && bfd_section_vma (sectp
) == 0)
2010 this->has_section_at_zero
= true;
2013 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2017 dwarf2_get_section_info (struct objfile
*objfile
,
2018 enum dwarf2_section_enum sect
,
2019 asection
**sectp
, const gdb_byte
**bufp
,
2020 bfd_size_type
*sizep
)
2022 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2023 struct dwarf2_section_info
*info
;
2025 /* We may see an objfile without any DWARF, in which case we just
2036 case DWARF2_DEBUG_FRAME
:
2037 info
= &data
->frame
;
2039 case DWARF2_EH_FRAME
:
2040 info
= &data
->eh_frame
;
2043 gdb_assert_not_reached ("unexpected section");
2046 info
->read (objfile
);
2048 *sectp
= info
->get_bfd_section ();
2049 *bufp
= info
->buffer
;
2050 *sizep
= info
->size
;
2053 /* A helper function to find the sections for a .dwz file. */
2056 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2058 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2060 /* Note that we only support the standard ELF names, because .dwz
2061 is ELF-only (at the time of writing). */
2062 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2064 dwz_file
->abbrev
.s
.section
= sectp
;
2065 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2067 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2069 dwz_file
->info
.s
.section
= sectp
;
2070 dwz_file
->info
.size
= bfd_section_size (sectp
);
2072 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2074 dwz_file
->str
.s
.section
= sectp
;
2075 dwz_file
->str
.size
= bfd_section_size (sectp
);
2077 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2079 dwz_file
->line
.s
.section
= sectp
;
2080 dwz_file
->line
.size
= bfd_section_size (sectp
);
2082 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2084 dwz_file
->macro
.s
.section
= sectp
;
2085 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2087 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2089 dwz_file
->gdb_index
.s
.section
= sectp
;
2090 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2092 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2094 dwz_file
->debug_names
.s
.section
= sectp
;
2095 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2099 /* See dwarf2read.h. */
2102 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2104 const char *filename
;
2105 bfd_size_type buildid_len_arg
;
2109 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2110 return dwarf2_per_objfile
->dwz_file
.get ();
2112 bfd_set_error (bfd_error_no_error
);
2113 gdb::unique_xmalloc_ptr
<char> data
2114 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2115 &buildid_len_arg
, &buildid
));
2118 if (bfd_get_error () == bfd_error_no_error
)
2120 error (_("could not read '.gnu_debugaltlink' section: %s"),
2121 bfd_errmsg (bfd_get_error ()));
2124 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2126 buildid_len
= (size_t) buildid_len_arg
;
2128 filename
= data
.get ();
2130 std::string abs_storage
;
2131 if (!IS_ABSOLUTE_PATH (filename
))
2133 gdb::unique_xmalloc_ptr
<char> abs
2134 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2136 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2137 filename
= abs_storage
.c_str ();
2140 /* First try the file name given in the section. If that doesn't
2141 work, try to use the build-id instead. */
2142 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2143 if (dwz_bfd
!= NULL
)
2145 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2146 dwz_bfd
.reset (nullptr);
2149 if (dwz_bfd
== NULL
)
2150 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2152 if (dwz_bfd
== nullptr)
2154 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2155 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2157 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2164 /* File successfully retrieved from server. */
2165 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2167 if (dwz_bfd
== nullptr)
2168 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2169 alt_filename
.get ());
2170 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2171 dwz_bfd
.reset (nullptr);
2175 if (dwz_bfd
== NULL
)
2176 error (_("could not find '.gnu_debugaltlink' file for %s"),
2177 objfile_name (dwarf2_per_objfile
->objfile
));
2179 std::unique_ptr
<struct dwz_file
> result
2180 (new struct dwz_file (std::move (dwz_bfd
)));
2182 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2185 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2186 result
->dwz_bfd
.get ());
2187 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2188 return dwarf2_per_objfile
->dwz_file
.get ();
2191 /* DWARF quick_symbols_functions support. */
2193 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2194 unique line tables, so we maintain a separate table of all .debug_line
2195 derived entries to support the sharing.
2196 All the quick functions need is the list of file names. We discard the
2197 line_header when we're done and don't need to record it here. */
2198 struct quick_file_names
2200 /* The data used to construct the hash key. */
2201 struct stmt_list_hash hash
;
2203 /* The number of entries in file_names, real_names. */
2204 unsigned int num_file_names
;
2206 /* The file names from the line table, after being run through
2208 const char **file_names
;
2210 /* The file names from the line table after being run through
2211 gdb_realpath. These are computed lazily. */
2212 const char **real_names
;
2215 /* When using the index (and thus not using psymtabs), each CU has an
2216 object of this type. This is used to hold information needed by
2217 the various "quick" methods. */
2218 struct dwarf2_per_cu_quick_data
2220 /* The file table. This can be NULL if there was no file table
2221 or it's currently not read in.
2222 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2223 struct quick_file_names
*file_names
;
2225 /* The corresponding symbol table. This is NULL if symbols for this
2226 CU have not yet been read. */
2227 struct compunit_symtab
*compunit_symtab
;
2229 /* A temporary mark bit used when iterating over all CUs in
2230 expand_symtabs_matching. */
2231 unsigned int mark
: 1;
2233 /* True if we've tried to read the file table and found there isn't one.
2234 There will be no point in trying to read it again next time. */
2235 unsigned int no_file_data
: 1;
2238 /* Utility hash function for a stmt_list_hash. */
2241 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2245 if (stmt_list_hash
->dwo_unit
!= NULL
)
2246 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2247 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2251 /* Utility equality function for a stmt_list_hash. */
2254 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2255 const struct stmt_list_hash
*rhs
)
2257 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2259 if (lhs
->dwo_unit
!= NULL
2260 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2263 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2266 /* Hash function for a quick_file_names. */
2269 hash_file_name_entry (const void *e
)
2271 const struct quick_file_names
*file_data
2272 = (const struct quick_file_names
*) e
;
2274 return hash_stmt_list_entry (&file_data
->hash
);
2277 /* Equality function for a quick_file_names. */
2280 eq_file_name_entry (const void *a
, const void *b
)
2282 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2283 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2285 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2288 /* Delete function for a quick_file_names. */
2291 delete_file_name_entry (void *e
)
2293 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2296 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2298 xfree ((void*) file_data
->file_names
[i
]);
2299 if (file_data
->real_names
)
2300 xfree ((void*) file_data
->real_names
[i
]);
2303 /* The space for the struct itself lives on objfile_obstack,
2304 so we don't free it here. */
2307 /* Create a quick_file_names hash table. */
2310 create_quick_file_names_table (unsigned int nr_initial_entries
)
2312 return htab_up (htab_create_alloc (nr_initial_entries
,
2313 hash_file_name_entry
, eq_file_name_entry
,
2314 delete_file_name_entry
, xcalloc
, xfree
));
2317 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2318 have to be created afterwards. You should call age_cached_comp_units after
2319 processing PER_CU->CU. dw2_setup must have been already called. */
2322 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2324 if (per_cu
->is_debug_types
)
2325 load_full_type_unit (per_cu
);
2327 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2329 if (per_cu
->cu
== NULL
)
2330 return; /* Dummy CU. */
2332 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2335 /* Read in the symbols for PER_CU. */
2338 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2340 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2342 /* Skip type_unit_groups, reading the type units they contain
2343 is handled elsewhere. */
2344 if (per_cu
->type_unit_group_p ())
2347 /* The destructor of dwarf2_queue_guard frees any entries left on
2348 the queue. After this point we're guaranteed to leave this function
2349 with the dwarf queue empty. */
2350 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2352 if (dwarf2_per_objfile
->using_index
2353 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2354 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2356 queue_comp_unit (per_cu
, language_minimal
);
2357 load_cu (per_cu
, skip_partial
);
2359 /* If we just loaded a CU from a DWO, and we're working with an index
2360 that may badly handle TUs, load all the TUs in that DWO as well.
2361 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2362 if (!per_cu
->is_debug_types
2363 && per_cu
->cu
!= NULL
2364 && per_cu
->cu
->dwo_unit
!= NULL
2365 && dwarf2_per_objfile
->index_table
!= NULL
2366 && dwarf2_per_objfile
->index_table
->version
<= 7
2367 /* DWP files aren't supported yet. */
2368 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2369 queue_and_load_all_dwo_tus (per_cu
);
2372 process_queue (dwarf2_per_objfile
);
2374 /* Age the cache, releasing compilation units that have not
2375 been used recently. */
2376 age_cached_comp_units (dwarf2_per_objfile
);
2379 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2380 the objfile from which this CU came. Returns the resulting symbol
2383 static struct compunit_symtab
*
2384 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2386 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2388 gdb_assert (dwarf2_per_objfile
->using_index
);
2389 if (!per_cu
->v
.quick
->compunit_symtab
)
2391 free_cached_comp_units
freer (dwarf2_per_objfile
);
2392 scoped_restore decrementer
= increment_reading_symtab ();
2393 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2394 process_cu_includes (dwarf2_per_objfile
);
2397 return per_cu
->v
.quick
->compunit_symtab
;
2400 /* See declaration. */
2402 dwarf2_per_cu_data
*
2403 dwarf2_per_objfile::get_cutu (int index
)
2405 if (index
>= this->all_comp_units
.size ())
2407 index
-= this->all_comp_units
.size ();
2408 gdb_assert (index
< this->all_type_units
.size ());
2409 return &this->all_type_units
[index
]->per_cu
;
2412 return this->all_comp_units
[index
];
2415 /* See declaration. */
2417 dwarf2_per_cu_data
*
2418 dwarf2_per_objfile::get_cu (int index
)
2420 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2422 return this->all_comp_units
[index
];
2425 /* See declaration. */
2428 dwarf2_per_objfile::get_tu (int index
)
2430 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2432 return this->all_type_units
[index
];
2435 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2436 objfile_obstack, and constructed with the specified field
2439 static dwarf2_per_cu_data
*
2440 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2441 struct dwarf2_section_info
*section
,
2443 sect_offset sect_off
, ULONGEST length
)
2445 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2446 dwarf2_per_cu_data
*the_cu
2447 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2448 struct dwarf2_per_cu_data
);
2449 the_cu
->sect_off
= sect_off
;
2450 the_cu
->length
= length
;
2451 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2452 the_cu
->section
= section
;
2453 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2454 struct dwarf2_per_cu_quick_data
);
2455 the_cu
->is_dwz
= is_dwz
;
2459 /* A helper for create_cus_from_index that handles a given list of
2463 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2464 const gdb_byte
*cu_list
, offset_type n_elements
,
2465 struct dwarf2_section_info
*section
,
2468 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2470 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2472 sect_offset sect_off
2473 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2474 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2477 dwarf2_per_cu_data
*per_cu
2478 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2480 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2484 /* Read the CU list from the mapped index, and use it to create all
2485 the CU objects for this objfile. */
2488 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2489 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2490 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2492 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2493 dwarf2_per_objfile
->all_comp_units
.reserve
2494 ((cu_list_elements
+ dwz_elements
) / 2);
2496 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2497 &dwarf2_per_objfile
->info
, 0);
2499 if (dwz_elements
== 0)
2502 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2503 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2507 /* Create the signatured type hash table from the index. */
2510 create_signatured_type_table_from_index
2511 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2512 struct dwarf2_section_info
*section
,
2513 const gdb_byte
*bytes
,
2514 offset_type elements
)
2516 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2518 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2519 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2521 htab_up sig_types_hash
= allocate_signatured_type_table ();
2523 for (offset_type i
= 0; i
< elements
; i
+= 3)
2525 struct signatured_type
*sig_type
;
2528 cu_offset type_offset_in_tu
;
2530 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2531 sect_offset sect_off
2532 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2534 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2536 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2539 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2540 struct signatured_type
);
2541 sig_type
->signature
= signature
;
2542 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2543 sig_type
->per_cu
.is_debug_types
= 1;
2544 sig_type
->per_cu
.section
= section
;
2545 sig_type
->per_cu
.sect_off
= sect_off
;
2546 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2547 sig_type
->per_cu
.v
.quick
2548 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2549 struct dwarf2_per_cu_quick_data
);
2551 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2554 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2557 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2560 /* Create the signatured type hash table from .debug_names. */
2563 create_signatured_type_table_from_debug_names
2564 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2565 const mapped_debug_names
&map
,
2566 struct dwarf2_section_info
*section
,
2567 struct dwarf2_section_info
*abbrev_section
)
2569 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2571 section
->read (objfile
);
2572 abbrev_section
->read (objfile
);
2574 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2575 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2577 htab_up sig_types_hash
= allocate_signatured_type_table ();
2579 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2581 struct signatured_type
*sig_type
;
2584 sect_offset sect_off
2585 = (sect_offset
) (extract_unsigned_integer
2586 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2588 map
.dwarf5_byte_order
));
2590 comp_unit_head cu_header
;
2591 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2593 section
->buffer
+ to_underlying (sect_off
),
2596 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2597 struct signatured_type
);
2598 sig_type
->signature
= cu_header
.signature
;
2599 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2600 sig_type
->per_cu
.is_debug_types
= 1;
2601 sig_type
->per_cu
.section
= section
;
2602 sig_type
->per_cu
.sect_off
= sect_off
;
2603 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2604 sig_type
->per_cu
.v
.quick
2605 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2606 struct dwarf2_per_cu_quick_data
);
2608 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2611 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2614 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2617 /* Read the address map data from the mapped index, and use it to
2618 populate the objfile's psymtabs_addrmap. */
2621 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2622 struct mapped_index
*index
)
2624 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2625 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2626 const gdb_byte
*iter
, *end
;
2627 struct addrmap
*mutable_map
;
2630 auto_obstack temp_obstack
;
2632 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2634 iter
= index
->address_table
.data ();
2635 end
= iter
+ index
->address_table
.size ();
2637 baseaddr
= objfile
->text_section_offset ();
2641 ULONGEST hi
, lo
, cu_index
;
2642 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2644 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2646 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2651 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2652 hex_string (lo
), hex_string (hi
));
2656 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2658 complaint (_(".gdb_index address table has invalid CU number %u"),
2659 (unsigned) cu_index
);
2663 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2664 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2665 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2666 dwarf2_per_objfile
->get_cu (cu_index
));
2669 objfile
->partial_symtabs
->psymtabs_addrmap
2670 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2673 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2674 populate the objfile's psymtabs_addrmap. */
2677 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2678 struct dwarf2_section_info
*section
)
2680 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2681 bfd
*abfd
= objfile
->obfd
;
2682 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2683 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2685 auto_obstack temp_obstack
;
2686 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2688 std::unordered_map
<sect_offset
,
2689 dwarf2_per_cu_data
*,
2690 gdb::hash_enum
<sect_offset
>>
2691 debug_info_offset_to_per_cu
;
2692 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2694 const auto insertpair
2695 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2696 if (!insertpair
.second
)
2698 warning (_("Section .debug_aranges in %s has duplicate "
2699 "debug_info_offset %s, ignoring .debug_aranges."),
2700 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2705 section
->read (objfile
);
2707 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2709 const gdb_byte
*addr
= section
->buffer
;
2711 while (addr
< section
->buffer
+ section
->size
)
2713 const gdb_byte
*const entry_addr
= addr
;
2714 unsigned int bytes_read
;
2716 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2720 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2721 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2722 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2723 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2725 warning (_("Section .debug_aranges in %s entry at offset %s "
2726 "length %s exceeds section length %s, "
2727 "ignoring .debug_aranges."),
2728 objfile_name (objfile
),
2729 plongest (entry_addr
- section
->buffer
),
2730 plongest (bytes_read
+ entry_length
),
2731 pulongest (section
->size
));
2735 /* The version number. */
2736 const uint16_t version
= read_2_bytes (abfd
, addr
);
2740 warning (_("Section .debug_aranges in %s entry at offset %s "
2741 "has unsupported version %d, ignoring .debug_aranges."),
2742 objfile_name (objfile
),
2743 plongest (entry_addr
- section
->buffer
), version
);
2747 const uint64_t debug_info_offset
2748 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2749 addr
+= offset_size
;
2750 const auto per_cu_it
2751 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2752 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2754 warning (_("Section .debug_aranges in %s entry at offset %s "
2755 "debug_info_offset %s does not exists, "
2756 "ignoring .debug_aranges."),
2757 objfile_name (objfile
),
2758 plongest (entry_addr
- section
->buffer
),
2759 pulongest (debug_info_offset
));
2762 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2764 const uint8_t address_size
= *addr
++;
2765 if (address_size
< 1 || address_size
> 8)
2767 warning (_("Section .debug_aranges in %s entry at offset %s "
2768 "address_size %u is invalid, ignoring .debug_aranges."),
2769 objfile_name (objfile
),
2770 plongest (entry_addr
- section
->buffer
), address_size
);
2774 const uint8_t segment_selector_size
= *addr
++;
2775 if (segment_selector_size
!= 0)
2777 warning (_("Section .debug_aranges in %s entry at offset %s "
2778 "segment_selector_size %u is not supported, "
2779 "ignoring .debug_aranges."),
2780 objfile_name (objfile
),
2781 plongest (entry_addr
- section
->buffer
),
2782 segment_selector_size
);
2786 /* Must pad to an alignment boundary that is twice the address
2787 size. It is undocumented by the DWARF standard but GCC does
2789 for (size_t padding
= ((-(addr
- section
->buffer
))
2790 & (2 * address_size
- 1));
2791 padding
> 0; padding
--)
2794 warning (_("Section .debug_aranges in %s entry at offset %s "
2795 "padding is not zero, ignoring .debug_aranges."),
2796 objfile_name (objfile
),
2797 plongest (entry_addr
- section
->buffer
));
2803 if (addr
+ 2 * address_size
> entry_end
)
2805 warning (_("Section .debug_aranges in %s entry at offset %s "
2806 "address list is not properly terminated, "
2807 "ignoring .debug_aranges."),
2808 objfile_name (objfile
),
2809 plongest (entry_addr
- section
->buffer
));
2812 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2814 addr
+= address_size
;
2815 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2817 addr
+= address_size
;
2818 if (start
== 0 && length
== 0)
2820 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2822 /* Symbol was eliminated due to a COMDAT group. */
2825 ULONGEST end
= start
+ length
;
2826 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2828 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2830 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2834 objfile
->partial_symtabs
->psymtabs_addrmap
2835 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2838 /* Find a slot in the mapped index INDEX for the object named NAME.
2839 If NAME is found, set *VEC_OUT to point to the CU vector in the
2840 constant pool and return true. If NAME cannot be found, return
2844 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2845 offset_type
**vec_out
)
2848 offset_type slot
, step
;
2849 int (*cmp
) (const char *, const char *);
2851 gdb::unique_xmalloc_ptr
<char> without_params
;
2852 if (current_language
->la_language
== language_cplus
2853 || current_language
->la_language
== language_fortran
2854 || current_language
->la_language
== language_d
)
2856 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2859 if (strchr (name
, '(') != NULL
)
2861 without_params
= cp_remove_params (name
);
2863 if (without_params
!= NULL
)
2864 name
= without_params
.get ();
2868 /* Index version 4 did not support case insensitive searches. But the
2869 indices for case insensitive languages are built in lowercase, therefore
2870 simulate our NAME being searched is also lowercased. */
2871 hash
= mapped_index_string_hash ((index
->version
== 4
2872 && case_sensitivity
== case_sensitive_off
2873 ? 5 : index
->version
),
2876 slot
= hash
& (index
->symbol_table
.size () - 1);
2877 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2878 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2884 const auto &bucket
= index
->symbol_table
[slot
];
2885 if (bucket
.name
== 0 && bucket
.vec
== 0)
2888 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2889 if (!cmp (name
, str
))
2891 *vec_out
= (offset_type
*) (index
->constant_pool
2892 + MAYBE_SWAP (bucket
.vec
));
2896 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2900 /* A helper function that reads the .gdb_index from BUFFER and fills
2901 in MAP. FILENAME is the name of the file containing the data;
2902 it is used for error reporting. DEPRECATED_OK is true if it is
2903 ok to use deprecated sections.
2905 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2906 out parameters that are filled in with information about the CU and
2907 TU lists in the section.
2909 Returns true if all went well, false otherwise. */
2912 read_gdb_index_from_buffer (struct objfile
*objfile
,
2913 const char *filename
,
2915 gdb::array_view
<const gdb_byte
> buffer
,
2916 struct mapped_index
*map
,
2917 const gdb_byte
**cu_list
,
2918 offset_type
*cu_list_elements
,
2919 const gdb_byte
**types_list
,
2920 offset_type
*types_list_elements
)
2922 const gdb_byte
*addr
= &buffer
[0];
2924 /* Version check. */
2925 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2926 /* Versions earlier than 3 emitted every copy of a psymbol. This
2927 causes the index to behave very poorly for certain requests. Version 3
2928 contained incomplete addrmap. So, it seems better to just ignore such
2932 static int warning_printed
= 0;
2933 if (!warning_printed
)
2935 warning (_("Skipping obsolete .gdb_index section in %s."),
2937 warning_printed
= 1;
2941 /* Index version 4 uses a different hash function than index version
2944 Versions earlier than 6 did not emit psymbols for inlined
2945 functions. Using these files will cause GDB not to be able to
2946 set breakpoints on inlined functions by name, so we ignore these
2947 indices unless the user has done
2948 "set use-deprecated-index-sections on". */
2949 if (version
< 6 && !deprecated_ok
)
2951 static int warning_printed
= 0;
2952 if (!warning_printed
)
2955 Skipping deprecated .gdb_index section in %s.\n\
2956 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2957 to use the section anyway."),
2959 warning_printed
= 1;
2963 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2964 of the TU (for symbols coming from TUs),
2965 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2966 Plus gold-generated indices can have duplicate entries for global symbols,
2967 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2968 These are just performance bugs, and we can't distinguish gdb-generated
2969 indices from gold-generated ones, so issue no warning here. */
2971 /* Indexes with higher version than the one supported by GDB may be no
2972 longer backward compatible. */
2976 map
->version
= version
;
2978 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2981 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2982 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2986 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2987 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2988 - MAYBE_SWAP (metadata
[i
]))
2992 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2993 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2995 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2998 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2999 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3001 = gdb::array_view
<mapped_index::symbol_table_slot
>
3002 ((mapped_index::symbol_table_slot
*) symbol_table
,
3003 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3006 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3011 /* Callback types for dwarf2_read_gdb_index. */
3013 typedef gdb::function_view
3014 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3015 get_gdb_index_contents_ftype
;
3016 typedef gdb::function_view
3017 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3018 get_gdb_index_contents_dwz_ftype
;
3020 /* Read .gdb_index. If everything went ok, initialize the "quick"
3021 elements of all the CUs and return 1. Otherwise, return 0. */
3024 dwarf2_read_gdb_index
3025 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3026 get_gdb_index_contents_ftype get_gdb_index_contents
,
3027 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3029 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3030 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3031 struct dwz_file
*dwz
;
3032 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3034 gdb::array_view
<const gdb_byte
> main_index_contents
3035 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3037 if (main_index_contents
.empty ())
3040 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3041 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3042 use_deprecated_index_sections
,
3043 main_index_contents
, map
.get (), &cu_list
,
3044 &cu_list_elements
, &types_list
,
3045 &types_list_elements
))
3048 /* Don't use the index if it's empty. */
3049 if (map
->symbol_table
.empty ())
3052 /* If there is a .dwz file, read it so we can get its CU list as
3054 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3057 struct mapped_index dwz_map
;
3058 const gdb_byte
*dwz_types_ignore
;
3059 offset_type dwz_types_elements_ignore
;
3061 gdb::array_view
<const gdb_byte
> dwz_index_content
3062 = get_gdb_index_contents_dwz (objfile
, dwz
);
3064 if (dwz_index_content
.empty ())
3067 if (!read_gdb_index_from_buffer (objfile
,
3068 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3069 1, dwz_index_content
, &dwz_map
,
3070 &dwz_list
, &dwz_list_elements
,
3072 &dwz_types_elements_ignore
))
3074 warning (_("could not read '.gdb_index' section from %s; skipping"),
3075 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3080 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3081 dwz_list
, dwz_list_elements
);
3083 if (types_list_elements
)
3085 /* We can only handle a single .debug_types when we have an
3087 if (dwarf2_per_objfile
->types
.size () != 1)
3090 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3092 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3093 types_list
, types_list_elements
);
3096 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3098 dwarf2_per_objfile
->index_table
= std::move (map
);
3099 dwarf2_per_objfile
->using_index
= 1;
3100 dwarf2_per_objfile
->quick_file_names_table
=
3101 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3106 /* die_reader_func for dw2_get_file_names. */
3109 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3110 const gdb_byte
*info_ptr
,
3111 struct die_info
*comp_unit_die
)
3113 struct dwarf2_cu
*cu
= reader
->cu
;
3114 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3115 struct dwarf2_per_objfile
*dwarf2_per_objfile
3116 = cu
->per_cu
->dwarf2_per_objfile
;
3117 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3118 struct dwarf2_per_cu_data
*lh_cu
;
3119 struct attribute
*attr
;
3121 struct quick_file_names
*qfn
;
3123 gdb_assert (! this_cu
->is_debug_types
);
3125 /* Our callers never want to match partial units -- instead they
3126 will match the enclosing full CU. */
3127 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3129 this_cu
->v
.quick
->no_file_data
= 1;
3137 sect_offset line_offset
{};
3139 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3140 if (attr
!= nullptr)
3142 struct quick_file_names find_entry
;
3144 line_offset
= (sect_offset
) DW_UNSND (attr
);
3146 /* We may have already read in this line header (TU line header sharing).
3147 If we have we're done. */
3148 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3149 find_entry
.hash
.line_sect_off
= line_offset
;
3150 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3151 &find_entry
, INSERT
);
3154 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3158 lh
= dwarf_decode_line_header (line_offset
, cu
);
3162 lh_cu
->v
.quick
->no_file_data
= 1;
3166 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3167 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3168 qfn
->hash
.line_sect_off
= line_offset
;
3169 gdb_assert (slot
!= NULL
);
3172 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3175 if (strcmp (fnd
.name
, "<unknown>") != 0)
3178 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3180 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3182 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3183 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3184 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3185 fnd
.comp_dir
).release ();
3186 qfn
->real_names
= NULL
;
3188 lh_cu
->v
.quick
->file_names
= qfn
;
3191 /* A helper for the "quick" functions which attempts to read the line
3192 table for THIS_CU. */
3194 static struct quick_file_names
*
3195 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3197 /* This should never be called for TUs. */
3198 gdb_assert (! this_cu
->is_debug_types
);
3199 /* Nor type unit groups. */
3200 gdb_assert (! this_cu
->type_unit_group_p ());
3202 if (this_cu
->v
.quick
->file_names
!= NULL
)
3203 return this_cu
->v
.quick
->file_names
;
3204 /* If we know there is no line data, no point in looking again. */
3205 if (this_cu
->v
.quick
->no_file_data
)
3208 cutu_reader
reader (this_cu
);
3209 if (!reader
.dummy_p
)
3210 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3212 if (this_cu
->v
.quick
->no_file_data
)
3214 return this_cu
->v
.quick
->file_names
;
3217 /* A helper for the "quick" functions which computes and caches the
3218 real path for a given file name from the line table. */
3221 dw2_get_real_path (struct objfile
*objfile
,
3222 struct quick_file_names
*qfn
, int index
)
3224 if (qfn
->real_names
== NULL
)
3225 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3226 qfn
->num_file_names
, const char *);
3228 if (qfn
->real_names
[index
] == NULL
)
3229 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3231 return qfn
->real_names
[index
];
3234 static struct symtab
*
3235 dw2_find_last_source_symtab (struct objfile
*objfile
)
3237 struct dwarf2_per_objfile
*dwarf2_per_objfile
3238 = get_dwarf2_per_objfile (objfile
);
3239 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3240 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3245 return compunit_primary_filetab (cust
);
3248 /* Traversal function for dw2_forget_cached_source_info. */
3251 dw2_free_cached_file_names (void **slot
, void *info
)
3253 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3255 if (file_data
->real_names
)
3259 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3261 xfree ((void*) file_data
->real_names
[i
]);
3262 file_data
->real_names
[i
] = NULL
;
3270 dw2_forget_cached_source_info (struct objfile
*objfile
)
3272 struct dwarf2_per_objfile
*dwarf2_per_objfile
3273 = get_dwarf2_per_objfile (objfile
);
3275 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3276 dw2_free_cached_file_names
, NULL
);
3279 /* Helper function for dw2_map_symtabs_matching_filename that expands
3280 the symtabs and calls the iterator. */
3283 dw2_map_expand_apply (struct objfile
*objfile
,
3284 struct dwarf2_per_cu_data
*per_cu
,
3285 const char *name
, const char *real_path
,
3286 gdb::function_view
<bool (symtab
*)> callback
)
3288 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3290 /* Don't visit already-expanded CUs. */
3291 if (per_cu
->v
.quick
->compunit_symtab
)
3294 /* This may expand more than one symtab, and we want to iterate over
3296 dw2_instantiate_symtab (per_cu
, false);
3298 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3299 last_made
, callback
);
3302 /* Implementation of the map_symtabs_matching_filename method. */
3305 dw2_map_symtabs_matching_filename
3306 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3307 gdb::function_view
<bool (symtab
*)> callback
)
3309 const char *name_basename
= lbasename (name
);
3310 struct dwarf2_per_objfile
*dwarf2_per_objfile
3311 = get_dwarf2_per_objfile (objfile
);
3313 /* The rule is CUs specify all the files, including those used by
3314 any TU, so there's no need to scan TUs here. */
3316 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3318 /* We only need to look at symtabs not already expanded. */
3319 if (per_cu
->v
.quick
->compunit_symtab
)
3322 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3323 if (file_data
== NULL
)
3326 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3328 const char *this_name
= file_data
->file_names
[j
];
3329 const char *this_real_name
;
3331 if (compare_filenames_for_search (this_name
, name
))
3333 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3339 /* Before we invoke realpath, which can get expensive when many
3340 files are involved, do a quick comparison of the basenames. */
3341 if (! basenames_may_differ
3342 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3345 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3346 if (compare_filenames_for_search (this_real_name
, name
))
3348 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3354 if (real_path
!= NULL
)
3356 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3357 gdb_assert (IS_ABSOLUTE_PATH (name
));
3358 if (this_real_name
!= NULL
3359 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3361 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3373 /* Struct used to manage iterating over all CUs looking for a symbol. */
3375 struct dw2_symtab_iterator
3377 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3378 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3379 /* If set, only look for symbols that match that block. Valid values are
3380 GLOBAL_BLOCK and STATIC_BLOCK. */
3381 gdb::optional
<block_enum
> block_index
;
3382 /* The kind of symbol we're looking for. */
3384 /* The list of CUs from the index entry of the symbol,
3385 or NULL if not found. */
3387 /* The next element in VEC to look at. */
3389 /* The number of elements in VEC, or zero if there is no match. */
3391 /* Have we seen a global version of the symbol?
3392 If so we can ignore all further global instances.
3393 This is to work around gold/15646, inefficient gold-generated
3398 /* Initialize the index symtab iterator ITER. */
3401 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3402 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3403 gdb::optional
<block_enum
> block_index
,
3407 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3408 iter
->block_index
= block_index
;
3409 iter
->domain
= domain
;
3411 iter
->global_seen
= 0;
3413 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3415 /* index is NULL if OBJF_READNOW. */
3416 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3417 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3425 /* Return the next matching CU or NULL if there are no more. */
3427 static struct dwarf2_per_cu_data
*
3428 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3430 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3432 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3434 offset_type cu_index_and_attrs
=
3435 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3436 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3437 gdb_index_symbol_kind symbol_kind
=
3438 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3439 /* Only check the symbol attributes if they're present.
3440 Indices prior to version 7 don't record them,
3441 and indices >= 7 may elide them for certain symbols
3442 (gold does this). */
3444 (dwarf2_per_objfile
->index_table
->version
>= 7
3445 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3447 /* Don't crash on bad data. */
3448 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3449 + dwarf2_per_objfile
->all_type_units
.size ()))
3451 complaint (_(".gdb_index entry has bad CU index"
3453 objfile_name (dwarf2_per_objfile
->objfile
));
3457 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3459 /* Skip if already read in. */
3460 if (per_cu
->v
.quick
->compunit_symtab
)
3463 /* Check static vs global. */
3466 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3468 if (iter
->block_index
.has_value ())
3470 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3472 if (is_static
!= want_static
)
3476 /* Work around gold/15646. */
3477 if (!is_static
&& iter
->global_seen
)
3480 iter
->global_seen
= 1;
3483 /* Only check the symbol's kind if it has one. */
3486 switch (iter
->domain
)
3489 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3490 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3491 /* Some types are also in VAR_DOMAIN. */
3492 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3496 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3500 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3504 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3519 static struct compunit_symtab
*
3520 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3521 const char *name
, domain_enum domain
)
3523 struct compunit_symtab
*stab_best
= NULL
;
3524 struct dwarf2_per_objfile
*dwarf2_per_objfile
3525 = get_dwarf2_per_objfile (objfile
);
3527 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3529 struct dw2_symtab_iterator iter
;
3530 struct dwarf2_per_cu_data
*per_cu
;
3532 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3534 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3536 struct symbol
*sym
, *with_opaque
= NULL
;
3537 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3538 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3539 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3541 sym
= block_find_symbol (block
, name
, domain
,
3542 block_find_non_opaque_type_preferred
,
3545 /* Some caution must be observed with overloaded functions
3546 and methods, since the index will not contain any overload
3547 information (but NAME might contain it). */
3550 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3552 if (with_opaque
!= NULL
3553 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3556 /* Keep looking through other CUs. */
3563 dw2_print_stats (struct objfile
*objfile
)
3565 struct dwarf2_per_objfile
*dwarf2_per_objfile
3566 = get_dwarf2_per_objfile (objfile
);
3567 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3568 + dwarf2_per_objfile
->all_type_units
.size ());
3571 for (int i
= 0; i
< total
; ++i
)
3573 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3575 if (!per_cu
->v
.quick
->compunit_symtab
)
3578 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3579 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3582 /* This dumps minimal information about the index.
3583 It is called via "mt print objfiles".
3584 One use is to verify .gdb_index has been loaded by the
3585 gdb.dwarf2/gdb-index.exp testcase. */
3588 dw2_dump (struct objfile
*objfile
)
3590 struct dwarf2_per_objfile
*dwarf2_per_objfile
3591 = get_dwarf2_per_objfile (objfile
);
3593 gdb_assert (dwarf2_per_objfile
->using_index
);
3594 printf_filtered (".gdb_index:");
3595 if (dwarf2_per_objfile
->index_table
!= NULL
)
3597 printf_filtered (" version %d\n",
3598 dwarf2_per_objfile
->index_table
->version
);
3601 printf_filtered (" faked for \"readnow\"\n");
3602 printf_filtered ("\n");
3606 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3607 const char *func_name
)
3609 struct dwarf2_per_objfile
*dwarf2_per_objfile
3610 = get_dwarf2_per_objfile (objfile
);
3612 struct dw2_symtab_iterator iter
;
3613 struct dwarf2_per_cu_data
*per_cu
;
3615 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3617 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3618 dw2_instantiate_symtab (per_cu
, false);
3623 dw2_expand_all_symtabs (struct objfile
*objfile
)
3625 struct dwarf2_per_objfile
*dwarf2_per_objfile
3626 = get_dwarf2_per_objfile (objfile
);
3627 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3628 + dwarf2_per_objfile
->all_type_units
.size ());
3630 for (int i
= 0; i
< total_units
; ++i
)
3632 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3634 /* We don't want to directly expand a partial CU, because if we
3635 read it with the wrong language, then assertion failures can
3636 be triggered later on. See PR symtab/23010. So, tell
3637 dw2_instantiate_symtab to skip partial CUs -- any important
3638 partial CU will be read via DW_TAG_imported_unit anyway. */
3639 dw2_instantiate_symtab (per_cu
, true);
3644 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3645 const char *fullname
)
3647 struct dwarf2_per_objfile
*dwarf2_per_objfile
3648 = get_dwarf2_per_objfile (objfile
);
3650 /* We don't need to consider type units here.
3651 This is only called for examining code, e.g. expand_line_sal.
3652 There can be an order of magnitude (or more) more type units
3653 than comp units, and we avoid them if we can. */
3655 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3657 /* We only need to look at symtabs not already expanded. */
3658 if (per_cu
->v
.quick
->compunit_symtab
)
3661 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3662 if (file_data
== NULL
)
3665 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3667 const char *this_fullname
= file_data
->file_names
[j
];
3669 if (filename_cmp (this_fullname
, fullname
) == 0)
3671 dw2_instantiate_symtab (per_cu
, false);
3679 dw2_map_matching_symbols
3680 (struct objfile
*objfile
,
3681 const lookup_name_info
&name
, domain_enum domain
,
3683 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3684 symbol_compare_ftype
*ordered_compare
)
3686 /* Currently unimplemented; used for Ada. The function can be called if the
3687 current language is Ada for a non-Ada objfile using GNU index. As Ada
3688 does not look for non-Ada symbols this function should just return. */
3691 /* Starting from a search name, return the string that finds the upper
3692 bound of all strings that start with SEARCH_NAME in a sorted name
3693 list. Returns the empty string to indicate that the upper bound is
3694 the end of the list. */
3697 make_sort_after_prefix_name (const char *search_name
)
3699 /* When looking to complete "func", we find the upper bound of all
3700 symbols that start with "func" by looking for where we'd insert
3701 the closest string that would follow "func" in lexicographical
3702 order. Usually, that's "func"-with-last-character-incremented,
3703 i.e. "fund". Mind non-ASCII characters, though. Usually those
3704 will be UTF-8 multi-byte sequences, but we can't be certain.
3705 Especially mind the 0xff character, which is a valid character in
3706 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3707 rule out compilers allowing it in identifiers. Note that
3708 conveniently, strcmp/strcasecmp are specified to compare
3709 characters interpreted as unsigned char. So what we do is treat
3710 the whole string as a base 256 number composed of a sequence of
3711 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3712 to 0, and carries 1 to the following more-significant position.
3713 If the very first character in SEARCH_NAME ends up incremented
3714 and carries/overflows, then the upper bound is the end of the
3715 list. The string after the empty string is also the empty
3718 Some examples of this operation:
3720 SEARCH_NAME => "+1" RESULT
3724 "\xff" "a" "\xff" => "\xff" "b"
3729 Then, with these symbols for example:
3735 completing "func" looks for symbols between "func" and
3736 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3737 which finds "func" and "func1", but not "fund".
3741 funcÿ (Latin1 'ÿ' [0xff])
3745 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3746 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3750 ÿÿ (Latin1 'ÿ' [0xff])
3753 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3754 the end of the list.
3756 std::string after
= search_name
;
3757 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3759 if (!after
.empty ())
3760 after
.back () = (unsigned char) after
.back () + 1;
3764 /* See declaration. */
3766 std::pair
<std::vector
<name_component
>::const_iterator
,
3767 std::vector
<name_component
>::const_iterator
>
3768 mapped_index_base::find_name_components_bounds
3769 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3772 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3774 const char *lang_name
3775 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3777 /* Comparison function object for lower_bound that matches against a
3778 given symbol name. */
3779 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3782 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3783 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3784 return name_cmp (elem_name
, name
) < 0;
3787 /* Comparison function object for upper_bound that matches against a
3788 given symbol name. */
3789 auto lookup_compare_upper
= [&] (const char *name
,
3790 const name_component
&elem
)
3792 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3793 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3794 return name_cmp (name
, elem_name
) < 0;
3797 auto begin
= this->name_components
.begin ();
3798 auto end
= this->name_components
.end ();
3800 /* Find the lower bound. */
3803 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3806 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3809 /* Find the upper bound. */
3812 if (lookup_name_without_params
.completion_mode ())
3814 /* In completion mode, we want UPPER to point past all
3815 symbols names that have the same prefix. I.e., with
3816 these symbols, and completing "func":
3818 function << lower bound
3820 other_function << upper bound
3822 We find the upper bound by looking for the insertion
3823 point of "func"-with-last-character-incremented,
3825 std::string after
= make_sort_after_prefix_name (lang_name
);
3828 return std::lower_bound (lower
, end
, after
.c_str (),
3829 lookup_compare_lower
);
3832 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3835 return {lower
, upper
};
3838 /* See declaration. */
3841 mapped_index_base::build_name_components ()
3843 if (!this->name_components
.empty ())
3846 this->name_components_casing
= case_sensitivity
;
3848 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3850 /* The code below only knows how to break apart components of C++
3851 symbol names (and other languages that use '::' as
3852 namespace/module separator) and Ada symbol names. */
3853 auto count
= this->symbol_name_count ();
3854 for (offset_type idx
= 0; idx
< count
; idx
++)
3856 if (this->symbol_name_slot_invalid (idx
))
3859 const char *name
= this->symbol_name_at (idx
);
3861 /* Add each name component to the name component table. */
3862 unsigned int previous_len
= 0;
3864 if (strstr (name
, "::") != nullptr)
3866 for (unsigned int current_len
= cp_find_first_component (name
);
3867 name
[current_len
] != '\0';
3868 current_len
+= cp_find_first_component (name
+ current_len
))
3870 gdb_assert (name
[current_len
] == ':');
3871 this->name_components
.push_back ({previous_len
, idx
});
3872 /* Skip the '::'. */
3874 previous_len
= current_len
;
3879 /* Handle the Ada encoded (aka mangled) form here. */
3880 for (const char *iter
= strstr (name
, "__");
3882 iter
= strstr (iter
, "__"))
3884 this->name_components
.push_back ({previous_len
, idx
});
3886 previous_len
= iter
- name
;
3890 this->name_components
.push_back ({previous_len
, idx
});
3893 /* Sort name_components elements by name. */
3894 auto name_comp_compare
= [&] (const name_component
&left
,
3895 const name_component
&right
)
3897 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3898 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3900 const char *left_name
= left_qualified
+ left
.name_offset
;
3901 const char *right_name
= right_qualified
+ right
.name_offset
;
3903 return name_cmp (left_name
, right_name
) < 0;
3906 std::sort (this->name_components
.begin (),
3907 this->name_components
.end (),
3911 /* Helper for dw2_expand_symtabs_matching that works with a
3912 mapped_index_base instead of the containing objfile. This is split
3913 to a separate function in order to be able to unit test the
3914 name_components matching using a mock mapped_index_base. For each
3915 symbol name that matches, calls MATCH_CALLBACK, passing it the
3916 symbol's index in the mapped_index_base symbol table. */
3919 dw2_expand_symtabs_matching_symbol
3920 (mapped_index_base
&index
,
3921 const lookup_name_info
&lookup_name_in
,
3922 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3923 enum search_domain kind
,
3924 gdb::function_view
<bool (offset_type
)> match_callback
)
3926 lookup_name_info lookup_name_without_params
3927 = lookup_name_in
.make_ignore_params ();
3929 /* Build the symbol name component sorted vector, if we haven't
3931 index
.build_name_components ();
3933 /* The same symbol may appear more than once in the range though.
3934 E.g., if we're looking for symbols that complete "w", and we have
3935 a symbol named "w1::w2", we'll find the two name components for
3936 that same symbol in the range. To be sure we only call the
3937 callback once per symbol, we first collect the symbol name
3938 indexes that matched in a temporary vector and ignore
3940 std::vector
<offset_type
> matches
;
3942 struct name_and_matcher
3944 symbol_name_matcher_ftype
*matcher
;
3945 const std::string
&name
;
3947 bool operator== (const name_and_matcher
&other
) const
3949 return matcher
== other
.matcher
&& name
== other
.name
;
3953 /* A vector holding all the different symbol name matchers, for all
3955 std::vector
<name_and_matcher
> matchers
;
3957 for (int i
= 0; i
< nr_languages
; i
++)
3959 enum language lang_e
= (enum language
) i
;
3961 const language_defn
*lang
= language_def (lang_e
);
3962 symbol_name_matcher_ftype
*name_matcher
3963 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3965 name_and_matcher key
{
3967 lookup_name_without_params
.language_lookup_name (lang_e
)
3970 /* Don't insert the same comparison routine more than once.
3971 Note that we do this linear walk. This is not a problem in
3972 practice because the number of supported languages is
3974 if (std::find (matchers
.begin (), matchers
.end (), key
)
3977 matchers
.push_back (std::move (key
));
3980 = index
.find_name_components_bounds (lookup_name_without_params
,
3983 /* Now for each symbol name in range, check to see if we have a name
3984 match, and if so, call the MATCH_CALLBACK callback. */
3986 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3988 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3990 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3991 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3994 matches
.push_back (bounds
.first
->idx
);
3998 std::sort (matches
.begin (), matches
.end ());
4000 /* Finally call the callback, once per match. */
4002 for (offset_type idx
: matches
)
4006 if (!match_callback (idx
))
4012 /* Above we use a type wider than idx's for 'prev', since 0 and
4013 (offset_type)-1 are both possible values. */
4014 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4019 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4021 /* A mock .gdb_index/.debug_names-like name index table, enough to
4022 exercise dw2_expand_symtabs_matching_symbol, which works with the
4023 mapped_index_base interface. Builds an index from the symbol list
4024 passed as parameter to the constructor. */
4025 class mock_mapped_index
: public mapped_index_base
4028 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4029 : m_symbol_table (symbols
)
4032 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4034 /* Return the number of names in the symbol table. */
4035 size_t symbol_name_count () const override
4037 return m_symbol_table
.size ();
4040 /* Get the name of the symbol at IDX in the symbol table. */
4041 const char *symbol_name_at (offset_type idx
) const override
4043 return m_symbol_table
[idx
];
4047 gdb::array_view
<const char *> m_symbol_table
;
4050 /* Convenience function that converts a NULL pointer to a "<null>"
4051 string, to pass to print routines. */
4054 string_or_null (const char *str
)
4056 return str
!= NULL
? str
: "<null>";
4059 /* Check if a lookup_name_info built from
4060 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4061 index. EXPECTED_LIST is the list of expected matches, in expected
4062 matching order. If no match expected, then an empty list is
4063 specified. Returns true on success. On failure prints a warning
4064 indicating the file:line that failed, and returns false. */
4067 check_match (const char *file
, int line
,
4068 mock_mapped_index
&mock_index
,
4069 const char *name
, symbol_name_match_type match_type
,
4070 bool completion_mode
,
4071 std::initializer_list
<const char *> expected_list
)
4073 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4075 bool matched
= true;
4077 auto mismatch
= [&] (const char *expected_str
,
4080 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4081 "expected=\"%s\", got=\"%s\"\n"),
4083 (match_type
== symbol_name_match_type::FULL
4085 name
, string_or_null (expected_str
), string_or_null (got
));
4089 auto expected_it
= expected_list
.begin ();
4090 auto expected_end
= expected_list
.end ();
4092 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4094 [&] (offset_type idx
)
4096 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4097 const char *expected_str
4098 = expected_it
== expected_end
? NULL
: *expected_it
++;
4100 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4101 mismatch (expected_str
, matched_name
);
4105 const char *expected_str
4106 = expected_it
== expected_end
? NULL
: *expected_it
++;
4107 if (expected_str
!= NULL
)
4108 mismatch (expected_str
, NULL
);
4113 /* The symbols added to the mock mapped_index for testing (in
4115 static const char *test_symbols
[] = {
4124 "ns2::tmpl<int>::foo2",
4125 "(anonymous namespace)::A::B::C",
4127 /* These are used to check that the increment-last-char in the
4128 matching algorithm for completion doesn't match "t1_fund" when
4129 completing "t1_func". */
4135 /* A UTF-8 name with multi-byte sequences to make sure that
4136 cp-name-parser understands this as a single identifier ("função"
4137 is "function" in PT). */
4140 /* \377 (0xff) is Latin1 'ÿ'. */
4143 /* \377 (0xff) is Latin1 'ÿ'. */
4147 /* A name with all sorts of complications. Starts with "z" to make
4148 it easier for the completion tests below. */
4149 #define Z_SYM_NAME \
4150 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4151 "::tuple<(anonymous namespace)::ui*, " \
4152 "std::default_delete<(anonymous namespace)::ui>, void>"
4157 /* Returns true if the mapped_index_base::find_name_component_bounds
4158 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4159 in completion mode. */
4162 check_find_bounds_finds (mapped_index_base
&index
,
4163 const char *search_name
,
4164 gdb::array_view
<const char *> expected_syms
)
4166 lookup_name_info
lookup_name (search_name
,
4167 symbol_name_match_type::FULL
, true);
4169 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4172 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4173 if (distance
!= expected_syms
.size ())
4176 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4178 auto nc_elem
= bounds
.first
+ exp_elem
;
4179 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4180 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4187 /* Test the lower-level mapped_index::find_name_component_bounds
4191 test_mapped_index_find_name_component_bounds ()
4193 mock_mapped_index
mock_index (test_symbols
);
4195 mock_index
.build_name_components ();
4197 /* Test the lower-level mapped_index::find_name_component_bounds
4198 method in completion mode. */
4200 static const char *expected_syms
[] = {
4205 SELF_CHECK (check_find_bounds_finds (mock_index
,
4206 "t1_func", expected_syms
));
4209 /* Check that the increment-last-char in the name matching algorithm
4210 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4212 static const char *expected_syms1
[] = {
4216 SELF_CHECK (check_find_bounds_finds (mock_index
,
4217 "\377", expected_syms1
));
4219 static const char *expected_syms2
[] = {
4222 SELF_CHECK (check_find_bounds_finds (mock_index
,
4223 "\377\377", expected_syms2
));
4227 /* Test dw2_expand_symtabs_matching_symbol. */
4230 test_dw2_expand_symtabs_matching_symbol ()
4232 mock_mapped_index
mock_index (test_symbols
);
4234 /* We let all tests run until the end even if some fails, for debug
4236 bool any_mismatch
= false;
4238 /* Create the expected symbols list (an initializer_list). Needed
4239 because lists have commas, and we need to pass them to CHECK,
4240 which is a macro. */
4241 #define EXPECT(...) { __VA_ARGS__ }
4243 /* Wrapper for check_match that passes down the current
4244 __FILE__/__LINE__. */
4245 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4246 any_mismatch |= !check_match (__FILE__, __LINE__, \
4248 NAME, MATCH_TYPE, COMPLETION_MODE, \
4251 /* Identity checks. */
4252 for (const char *sym
: test_symbols
)
4254 /* Should be able to match all existing symbols. */
4255 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4258 /* Should be able to match all existing symbols with
4260 std::string with_params
= std::string (sym
) + "(int)";
4261 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4264 /* Should be able to match all existing symbols with
4265 parameters and qualifiers. */
4266 with_params
= std::string (sym
) + " ( int ) const";
4267 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4270 /* This should really find sym, but cp-name-parser.y doesn't
4271 know about lvalue/rvalue qualifiers yet. */
4272 with_params
= std::string (sym
) + " ( int ) &&";
4273 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4277 /* Check that the name matching algorithm for completion doesn't get
4278 confused with Latin1 'ÿ' / 0xff. */
4280 static const char str
[] = "\377";
4281 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4282 EXPECT ("\377", "\377\377123"));
4285 /* Check that the increment-last-char in the matching algorithm for
4286 completion doesn't match "t1_fund" when completing "t1_func". */
4288 static const char str
[] = "t1_func";
4289 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4290 EXPECT ("t1_func", "t1_func1"));
4293 /* Check that completion mode works at each prefix of the expected
4296 static const char str
[] = "function(int)";
4297 size_t len
= strlen (str
);
4300 for (size_t i
= 1; i
< len
; i
++)
4302 lookup
.assign (str
, i
);
4303 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4304 EXPECT ("function"));
4308 /* While "w" is a prefix of both components, the match function
4309 should still only be called once. */
4311 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4313 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4317 /* Same, with a "complicated" symbol. */
4319 static const char str
[] = Z_SYM_NAME
;
4320 size_t len
= strlen (str
);
4323 for (size_t i
= 1; i
< len
; i
++)
4325 lookup
.assign (str
, i
);
4326 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4327 EXPECT (Z_SYM_NAME
));
4331 /* In FULL mode, an incomplete symbol doesn't match. */
4333 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4337 /* A complete symbol with parameters matches any overload, since the
4338 index has no overload info. */
4340 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4341 EXPECT ("std::zfunction", "std::zfunction2"));
4342 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4343 EXPECT ("std::zfunction", "std::zfunction2"));
4344 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4345 EXPECT ("std::zfunction", "std::zfunction2"));
4348 /* Check that whitespace is ignored appropriately. A symbol with a
4349 template argument list. */
4351 static const char expected
[] = "ns::foo<int>";
4352 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4354 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4358 /* Check that whitespace is ignored appropriately. A symbol with a
4359 template argument list that includes a pointer. */
4361 static const char expected
[] = "ns::foo<char*>";
4362 /* Try both completion and non-completion modes. */
4363 static const bool completion_mode
[2] = {false, true};
4364 for (size_t i
= 0; i
< 2; i
++)
4366 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4367 completion_mode
[i
], EXPECT (expected
));
4368 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4369 completion_mode
[i
], EXPECT (expected
));
4371 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4372 completion_mode
[i
], EXPECT (expected
));
4373 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4374 completion_mode
[i
], EXPECT (expected
));
4379 /* Check method qualifiers are ignored. */
4380 static const char expected
[] = "ns::foo<char*>";
4381 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4382 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4383 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4384 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4385 CHECK_MATCH ("foo < char * > ( int ) const",
4386 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4387 CHECK_MATCH ("foo < char * > ( int ) &&",
4388 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4391 /* Test lookup names that don't match anything. */
4393 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4396 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4400 /* Some wild matching tests, exercising "(anonymous namespace)",
4401 which should not be confused with a parameter list. */
4403 static const char *syms
[] = {
4407 "A :: B :: C ( int )",
4412 for (const char *s
: syms
)
4414 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4415 EXPECT ("(anonymous namespace)::A::B::C"));
4420 static const char expected
[] = "ns2::tmpl<int>::foo2";
4421 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4423 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4427 SELF_CHECK (!any_mismatch
);
4436 test_mapped_index_find_name_component_bounds ();
4437 test_dw2_expand_symtabs_matching_symbol ();
4440 }} // namespace selftests::dw2_expand_symtabs_matching
4442 #endif /* GDB_SELF_TEST */
4444 /* If FILE_MATCHER is NULL or if PER_CU has
4445 dwarf2_per_cu_quick_data::MARK set (see
4446 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4447 EXPANSION_NOTIFY on it. */
4450 dw2_expand_symtabs_matching_one
4451 (struct dwarf2_per_cu_data
*per_cu
,
4452 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4453 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4455 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4457 bool symtab_was_null
4458 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4460 dw2_instantiate_symtab (per_cu
, false);
4462 if (expansion_notify
!= NULL
4464 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4465 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4469 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4470 matched, to expand corresponding CUs that were marked. IDX is the
4471 index of the symbol name that matched. */
4474 dw2_expand_marked_cus
4475 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4476 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4477 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4480 offset_type
*vec
, vec_len
, vec_idx
;
4481 bool global_seen
= false;
4482 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4484 vec
= (offset_type
*) (index
.constant_pool
4485 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4486 vec_len
= MAYBE_SWAP (vec
[0]);
4487 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4489 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4490 /* This value is only valid for index versions >= 7. */
4491 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4492 gdb_index_symbol_kind symbol_kind
=
4493 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4494 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4495 /* Only check the symbol attributes if they're present.
4496 Indices prior to version 7 don't record them,
4497 and indices >= 7 may elide them for certain symbols
4498 (gold does this). */
4501 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4503 /* Work around gold/15646. */
4506 if (!is_static
&& global_seen
)
4512 /* Only check the symbol's kind if it has one. */
4517 case VARIABLES_DOMAIN
:
4518 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4521 case FUNCTIONS_DOMAIN
:
4522 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4526 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4529 case MODULES_DOMAIN
:
4530 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4538 /* Don't crash on bad data. */
4539 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4540 + dwarf2_per_objfile
->all_type_units
.size ()))
4542 complaint (_(".gdb_index entry has bad CU index"
4544 objfile_name (dwarf2_per_objfile
->objfile
));
4548 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4549 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4554 /* If FILE_MATCHER is non-NULL, set all the
4555 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4556 that match FILE_MATCHER. */
4559 dw_expand_symtabs_matching_file_matcher
4560 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4561 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4563 if (file_matcher
== NULL
)
4566 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4568 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4570 NULL
, xcalloc
, xfree
));
4571 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4573 NULL
, xcalloc
, xfree
));
4575 /* The rule is CUs specify all the files, including those used by
4576 any TU, so there's no need to scan TUs here. */
4578 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4582 per_cu
->v
.quick
->mark
= 0;
4584 /* We only need to look at symtabs not already expanded. */
4585 if (per_cu
->v
.quick
->compunit_symtab
)
4588 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4589 if (file_data
== NULL
)
4592 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4594 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4596 per_cu
->v
.quick
->mark
= 1;
4600 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4602 const char *this_real_name
;
4604 if (file_matcher (file_data
->file_names
[j
], false))
4606 per_cu
->v
.quick
->mark
= 1;
4610 /* Before we invoke realpath, which can get expensive when many
4611 files are involved, do a quick comparison of the basenames. */
4612 if (!basenames_may_differ
4613 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4617 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4618 if (file_matcher (this_real_name
, false))
4620 per_cu
->v
.quick
->mark
= 1;
4625 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4626 ? visited_found
.get ()
4627 : visited_not_found
.get (),
4634 dw2_expand_symtabs_matching
4635 (struct objfile
*objfile
,
4636 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4637 const lookup_name_info
&lookup_name
,
4638 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4639 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4640 enum search_domain kind
)
4642 struct dwarf2_per_objfile
*dwarf2_per_objfile
4643 = get_dwarf2_per_objfile (objfile
);
4645 /* index_table is NULL if OBJF_READNOW. */
4646 if (!dwarf2_per_objfile
->index_table
)
4649 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4651 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4653 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4655 kind
, [&] (offset_type idx
)
4657 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4658 expansion_notify
, kind
);
4663 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4666 static struct compunit_symtab
*
4667 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4672 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4673 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4676 if (cust
->includes
== NULL
)
4679 for (i
= 0; cust
->includes
[i
]; ++i
)
4681 struct compunit_symtab
*s
= cust
->includes
[i
];
4683 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4691 static struct compunit_symtab
*
4692 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4693 struct bound_minimal_symbol msymbol
,
4695 struct obj_section
*section
,
4698 struct dwarf2_per_cu_data
*data
;
4699 struct compunit_symtab
*result
;
4701 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4704 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4705 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4706 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4710 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4711 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4712 paddress (get_objfile_arch (objfile
), pc
));
4715 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4718 gdb_assert (result
!= NULL
);
4723 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4724 void *data
, int need_fullname
)
4726 struct dwarf2_per_objfile
*dwarf2_per_objfile
4727 = get_dwarf2_per_objfile (objfile
);
4729 if (!dwarf2_per_objfile
->filenames_cache
)
4731 dwarf2_per_objfile
->filenames_cache
.emplace ();
4733 htab_up
visited (htab_create_alloc (10,
4734 htab_hash_pointer
, htab_eq_pointer
,
4735 NULL
, xcalloc
, xfree
));
4737 /* The rule is CUs specify all the files, including those used
4738 by any TU, so there's no need to scan TUs here. We can
4739 ignore file names coming from already-expanded CUs. */
4741 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4743 if (per_cu
->v
.quick
->compunit_symtab
)
4745 void **slot
= htab_find_slot (visited
.get (),
4746 per_cu
->v
.quick
->file_names
,
4749 *slot
= per_cu
->v
.quick
->file_names
;
4753 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4755 /* We only need to look at symtabs not already expanded. */
4756 if (per_cu
->v
.quick
->compunit_symtab
)
4759 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4760 if (file_data
== NULL
)
4763 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4766 /* Already visited. */
4771 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4773 const char *filename
= file_data
->file_names
[j
];
4774 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4779 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4781 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4784 this_real_name
= gdb_realpath (filename
);
4785 (*fun
) (filename
, this_real_name
.get (), data
);
4790 dw2_has_symbols (struct objfile
*objfile
)
4795 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4798 dw2_find_last_source_symtab
,
4799 dw2_forget_cached_source_info
,
4800 dw2_map_symtabs_matching_filename
,
4804 dw2_expand_symtabs_for_function
,
4805 dw2_expand_all_symtabs
,
4806 dw2_expand_symtabs_with_fullname
,
4807 dw2_map_matching_symbols
,
4808 dw2_expand_symtabs_matching
,
4809 dw2_find_pc_sect_compunit_symtab
,
4811 dw2_map_symbol_filenames
4814 /* DWARF-5 debug_names reader. */
4816 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4817 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4819 /* A helper function that reads the .debug_names section in SECTION
4820 and fills in MAP. FILENAME is the name of the file containing the
4821 section; it is used for error reporting.
4823 Returns true if all went well, false otherwise. */
4826 read_debug_names_from_section (struct objfile
*objfile
,
4827 const char *filename
,
4828 struct dwarf2_section_info
*section
,
4829 mapped_debug_names
&map
)
4831 if (section
->empty ())
4834 /* Older elfutils strip versions could keep the section in the main
4835 executable while splitting it for the separate debug info file. */
4836 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4839 section
->read (objfile
);
4841 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4843 const gdb_byte
*addr
= section
->buffer
;
4845 bfd
*const abfd
= section
->get_bfd_owner ();
4847 unsigned int bytes_read
;
4848 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4851 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4852 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4853 if (bytes_read
+ length
!= section
->size
)
4855 /* There may be multiple per-CU indices. */
4856 warning (_("Section .debug_names in %s length %s does not match "
4857 "section length %s, ignoring .debug_names."),
4858 filename
, plongest (bytes_read
+ length
),
4859 pulongest (section
->size
));
4863 /* The version number. */
4864 uint16_t version
= read_2_bytes (abfd
, addr
);
4868 warning (_("Section .debug_names in %s has unsupported version %d, "
4869 "ignoring .debug_names."),
4875 uint16_t padding
= read_2_bytes (abfd
, addr
);
4879 warning (_("Section .debug_names in %s has unsupported padding %d, "
4880 "ignoring .debug_names."),
4885 /* comp_unit_count - The number of CUs in the CU list. */
4886 map
.cu_count
= read_4_bytes (abfd
, addr
);
4889 /* local_type_unit_count - The number of TUs in the local TU
4891 map
.tu_count
= read_4_bytes (abfd
, addr
);
4894 /* foreign_type_unit_count - The number of TUs in the foreign TU
4896 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4898 if (foreign_tu_count
!= 0)
4900 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4901 "ignoring .debug_names."),
4902 filename
, static_cast<unsigned long> (foreign_tu_count
));
4906 /* bucket_count - The number of hash buckets in the hash lookup
4908 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4911 /* name_count - The number of unique names in the index. */
4912 map
.name_count
= read_4_bytes (abfd
, addr
);
4915 /* abbrev_table_size - The size in bytes of the abbreviations
4917 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4920 /* augmentation_string_size - The size in bytes of the augmentation
4921 string. This value is rounded up to a multiple of 4. */
4922 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4924 map
.augmentation_is_gdb
= ((augmentation_string_size
4925 == sizeof (dwarf5_augmentation
))
4926 && memcmp (addr
, dwarf5_augmentation
,
4927 sizeof (dwarf5_augmentation
)) == 0);
4928 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4929 addr
+= augmentation_string_size
;
4932 map
.cu_table_reordered
= addr
;
4933 addr
+= map
.cu_count
* map
.offset_size
;
4935 /* List of Local TUs */
4936 map
.tu_table_reordered
= addr
;
4937 addr
+= map
.tu_count
* map
.offset_size
;
4939 /* Hash Lookup Table */
4940 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4941 addr
+= map
.bucket_count
* 4;
4942 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4943 addr
+= map
.name_count
* 4;
4946 map
.name_table_string_offs_reordered
= addr
;
4947 addr
+= map
.name_count
* map
.offset_size
;
4948 map
.name_table_entry_offs_reordered
= addr
;
4949 addr
+= map
.name_count
* map
.offset_size
;
4951 const gdb_byte
*abbrev_table_start
= addr
;
4954 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4959 const auto insertpair
4960 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4961 if (!insertpair
.second
)
4963 warning (_("Section .debug_names in %s has duplicate index %s, "
4964 "ignoring .debug_names."),
4965 filename
, pulongest (index_num
));
4968 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4969 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4974 mapped_debug_names::index_val::attr attr
;
4975 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4977 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4979 if (attr
.form
== DW_FORM_implicit_const
)
4981 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4985 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4987 indexval
.attr_vec
.push_back (std::move (attr
));
4990 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4992 warning (_("Section .debug_names in %s has abbreviation_table "
4993 "of size %s vs. written as %u, ignoring .debug_names."),
4994 filename
, plongest (addr
- abbrev_table_start
),
4998 map
.entry_pool
= addr
;
5003 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5007 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5008 const mapped_debug_names
&map
,
5009 dwarf2_section_info
§ion
,
5012 sect_offset sect_off_prev
;
5013 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5015 sect_offset sect_off_next
;
5016 if (i
< map
.cu_count
)
5019 = (sect_offset
) (extract_unsigned_integer
5020 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5022 map
.dwarf5_byte_order
));
5025 sect_off_next
= (sect_offset
) section
.size
;
5028 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5029 dwarf2_per_cu_data
*per_cu
5030 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5031 sect_off_prev
, length
);
5032 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5034 sect_off_prev
= sect_off_next
;
5038 /* Read the CU list from the mapped index, and use it to create all
5039 the CU objects for this dwarf2_per_objfile. */
5042 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5043 const mapped_debug_names
&map
,
5044 const mapped_debug_names
&dwz_map
)
5046 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5047 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5049 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5050 dwarf2_per_objfile
->info
,
5051 false /* is_dwz */);
5053 if (dwz_map
.cu_count
== 0)
5056 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5057 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5061 /* Read .debug_names. If everything went ok, initialize the "quick"
5062 elements of all the CUs and return true. Otherwise, return false. */
5065 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5067 std::unique_ptr
<mapped_debug_names
> map
5068 (new mapped_debug_names (dwarf2_per_objfile
));
5069 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5070 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5072 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5073 &dwarf2_per_objfile
->debug_names
,
5077 /* Don't use the index if it's empty. */
5078 if (map
->name_count
== 0)
5081 /* If there is a .dwz file, read it so we can get its CU list as
5083 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5086 if (!read_debug_names_from_section (objfile
,
5087 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5088 &dwz
->debug_names
, dwz_map
))
5090 warning (_("could not read '.debug_names' section from %s; skipping"),
5091 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5096 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5098 if (map
->tu_count
!= 0)
5100 /* We can only handle a single .debug_types when we have an
5102 if (dwarf2_per_objfile
->types
.size () != 1)
5105 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5107 create_signatured_type_table_from_debug_names
5108 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5111 create_addrmap_from_aranges (dwarf2_per_objfile
,
5112 &dwarf2_per_objfile
->debug_aranges
);
5114 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5115 dwarf2_per_objfile
->using_index
= 1;
5116 dwarf2_per_objfile
->quick_file_names_table
=
5117 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5122 /* Type used to manage iterating over all CUs looking for a symbol for
5125 class dw2_debug_names_iterator
5128 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5129 gdb::optional
<block_enum
> block_index
,
5132 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5133 m_addr (find_vec_in_debug_names (map
, name
))
5136 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5137 search_domain search
, uint32_t namei
)
5140 m_addr (find_vec_in_debug_names (map
, namei
))
5143 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5144 block_enum block_index
, domain_enum domain
,
5146 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5147 m_addr (find_vec_in_debug_names (map
, namei
))
5150 /* Return the next matching CU or NULL if there are no more. */
5151 dwarf2_per_cu_data
*next ();
5154 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5156 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5159 /* The internalized form of .debug_names. */
5160 const mapped_debug_names
&m_map
;
5162 /* If set, only look for symbols that match that block. Valid values are
5163 GLOBAL_BLOCK and STATIC_BLOCK. */
5164 const gdb::optional
<block_enum
> m_block_index
;
5166 /* The kind of symbol we're looking for. */
5167 const domain_enum m_domain
= UNDEF_DOMAIN
;
5168 const search_domain m_search
= ALL_DOMAIN
;
5170 /* The list of CUs from the index entry of the symbol, or NULL if
5172 const gdb_byte
*m_addr
;
5176 mapped_debug_names::namei_to_name (uint32_t namei
) const
5178 const ULONGEST namei_string_offs
5179 = extract_unsigned_integer ((name_table_string_offs_reordered
5180 + namei
* offset_size
),
5183 return read_indirect_string_at_offset
5184 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5187 /* Find a slot in .debug_names for the object named NAME. If NAME is
5188 found, return pointer to its pool data. If NAME cannot be found,
5192 dw2_debug_names_iterator::find_vec_in_debug_names
5193 (const mapped_debug_names
&map
, const char *name
)
5195 int (*cmp
) (const char *, const char *);
5197 gdb::unique_xmalloc_ptr
<char> without_params
;
5198 if (current_language
->la_language
== language_cplus
5199 || current_language
->la_language
== language_fortran
5200 || current_language
->la_language
== language_d
)
5202 /* NAME is already canonical. Drop any qualifiers as
5203 .debug_names does not contain any. */
5205 if (strchr (name
, '(') != NULL
)
5207 without_params
= cp_remove_params (name
);
5208 if (without_params
!= NULL
)
5209 name
= without_params
.get ();
5213 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5215 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5217 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5218 (map
.bucket_table_reordered
5219 + (full_hash
% map
.bucket_count
)), 4,
5220 map
.dwarf5_byte_order
);
5224 if (namei
>= map
.name_count
)
5226 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5228 namei
, map
.name_count
,
5229 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5235 const uint32_t namei_full_hash
5236 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5237 (map
.hash_table_reordered
+ namei
), 4,
5238 map
.dwarf5_byte_order
);
5239 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5242 if (full_hash
== namei_full_hash
)
5244 const char *const namei_string
= map
.namei_to_name (namei
);
5246 #if 0 /* An expensive sanity check. */
5247 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5249 complaint (_("Wrong .debug_names hash for string at index %u "
5251 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5256 if (cmp (namei_string
, name
) == 0)
5258 const ULONGEST namei_entry_offs
5259 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5260 + namei
* map
.offset_size
),
5261 map
.offset_size
, map
.dwarf5_byte_order
);
5262 return map
.entry_pool
+ namei_entry_offs
;
5267 if (namei
>= map
.name_count
)
5273 dw2_debug_names_iterator::find_vec_in_debug_names
5274 (const mapped_debug_names
&map
, uint32_t namei
)
5276 if (namei
>= map
.name_count
)
5278 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5280 namei
, map
.name_count
,
5281 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5285 const ULONGEST namei_entry_offs
5286 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5287 + namei
* map
.offset_size
),
5288 map
.offset_size
, map
.dwarf5_byte_order
);
5289 return map
.entry_pool
+ namei_entry_offs
;
5292 /* See dw2_debug_names_iterator. */
5294 dwarf2_per_cu_data
*
5295 dw2_debug_names_iterator::next ()
5300 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5301 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5302 bfd
*const abfd
= objfile
->obfd
;
5306 unsigned int bytes_read
;
5307 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5308 m_addr
+= bytes_read
;
5312 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5313 if (indexval_it
== m_map
.abbrev_map
.cend ())
5315 complaint (_("Wrong .debug_names undefined abbrev code %s "
5317 pulongest (abbrev
), objfile_name (objfile
));
5320 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5321 enum class symbol_linkage
{
5325 } symbol_linkage_
= symbol_linkage::unknown
;
5326 dwarf2_per_cu_data
*per_cu
= NULL
;
5327 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5332 case DW_FORM_implicit_const
:
5333 ull
= attr
.implicit_const
;
5335 case DW_FORM_flag_present
:
5339 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5340 m_addr
+= bytes_read
;
5343 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5344 dwarf_form_name (attr
.form
),
5345 objfile_name (objfile
));
5348 switch (attr
.dw_idx
)
5350 case DW_IDX_compile_unit
:
5351 /* Don't crash on bad data. */
5352 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5354 complaint (_(".debug_names entry has bad CU index %s"
5357 objfile_name (dwarf2_per_objfile
->objfile
));
5360 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5362 case DW_IDX_type_unit
:
5363 /* Don't crash on bad data. */
5364 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5366 complaint (_(".debug_names entry has bad TU index %s"
5369 objfile_name (dwarf2_per_objfile
->objfile
));
5372 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5374 case DW_IDX_GNU_internal
:
5375 if (!m_map
.augmentation_is_gdb
)
5377 symbol_linkage_
= symbol_linkage::static_
;
5379 case DW_IDX_GNU_external
:
5380 if (!m_map
.augmentation_is_gdb
)
5382 symbol_linkage_
= symbol_linkage::extern_
;
5387 /* Skip if already read in. */
5388 if (per_cu
->v
.quick
->compunit_symtab
)
5391 /* Check static vs global. */
5392 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5394 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5395 const bool symbol_is_static
=
5396 symbol_linkage_
== symbol_linkage::static_
;
5397 if (want_static
!= symbol_is_static
)
5401 /* Match dw2_symtab_iter_next, symbol_kind
5402 and debug_names::psymbol_tag. */
5406 switch (indexval
.dwarf_tag
)
5408 case DW_TAG_variable
:
5409 case DW_TAG_subprogram
:
5410 /* Some types are also in VAR_DOMAIN. */
5411 case DW_TAG_typedef
:
5412 case DW_TAG_structure_type
:
5419 switch (indexval
.dwarf_tag
)
5421 case DW_TAG_typedef
:
5422 case DW_TAG_structure_type
:
5429 switch (indexval
.dwarf_tag
)
5432 case DW_TAG_variable
:
5439 switch (indexval
.dwarf_tag
)
5451 /* Match dw2_expand_symtabs_matching, symbol_kind and
5452 debug_names::psymbol_tag. */
5455 case VARIABLES_DOMAIN
:
5456 switch (indexval
.dwarf_tag
)
5458 case DW_TAG_variable
:
5464 case FUNCTIONS_DOMAIN
:
5465 switch (indexval
.dwarf_tag
)
5467 case DW_TAG_subprogram
:
5474 switch (indexval
.dwarf_tag
)
5476 case DW_TAG_typedef
:
5477 case DW_TAG_structure_type
:
5483 case MODULES_DOMAIN
:
5484 switch (indexval
.dwarf_tag
)
5498 static struct compunit_symtab
*
5499 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5500 const char *name
, domain_enum domain
)
5502 struct dwarf2_per_objfile
*dwarf2_per_objfile
5503 = get_dwarf2_per_objfile (objfile
);
5505 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5508 /* index is NULL if OBJF_READNOW. */
5511 const auto &map
= *mapp
;
5513 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5515 struct compunit_symtab
*stab_best
= NULL
;
5516 struct dwarf2_per_cu_data
*per_cu
;
5517 while ((per_cu
= iter
.next ()) != NULL
)
5519 struct symbol
*sym
, *with_opaque
= NULL
;
5520 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5521 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5522 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5524 sym
= block_find_symbol (block
, name
, domain
,
5525 block_find_non_opaque_type_preferred
,
5528 /* Some caution must be observed with overloaded functions and
5529 methods, since the index will not contain any overload
5530 information (but NAME might contain it). */
5533 && strcmp_iw (sym
->search_name (), name
) == 0)
5535 if (with_opaque
!= NULL
5536 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5539 /* Keep looking through other CUs. */
5545 /* This dumps minimal information about .debug_names. It is called
5546 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5547 uses this to verify that .debug_names has been loaded. */
5550 dw2_debug_names_dump (struct objfile
*objfile
)
5552 struct dwarf2_per_objfile
*dwarf2_per_objfile
5553 = get_dwarf2_per_objfile (objfile
);
5555 gdb_assert (dwarf2_per_objfile
->using_index
);
5556 printf_filtered (".debug_names:");
5557 if (dwarf2_per_objfile
->debug_names_table
)
5558 printf_filtered (" exists\n");
5560 printf_filtered (" faked for \"readnow\"\n");
5561 printf_filtered ("\n");
5565 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5566 const char *func_name
)
5568 struct dwarf2_per_objfile
*dwarf2_per_objfile
5569 = get_dwarf2_per_objfile (objfile
);
5571 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5572 if (dwarf2_per_objfile
->debug_names_table
)
5574 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5576 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5578 struct dwarf2_per_cu_data
*per_cu
;
5579 while ((per_cu
= iter
.next ()) != NULL
)
5580 dw2_instantiate_symtab (per_cu
, false);
5585 dw2_debug_names_map_matching_symbols
5586 (struct objfile
*objfile
,
5587 const lookup_name_info
&name
, domain_enum domain
,
5589 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5590 symbol_compare_ftype
*ordered_compare
)
5592 struct dwarf2_per_objfile
*dwarf2_per_objfile
5593 = get_dwarf2_per_objfile (objfile
);
5595 /* debug_names_table is NULL if OBJF_READNOW. */
5596 if (!dwarf2_per_objfile
->debug_names_table
)
5599 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5600 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5602 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5603 auto matcher
= [&] (const char *symname
)
5605 if (ordered_compare
== nullptr)
5607 return ordered_compare (symname
, match_name
) == 0;
5610 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5611 [&] (offset_type namei
)
5613 /* The name was matched, now expand corresponding CUs that were
5615 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5617 struct dwarf2_per_cu_data
*per_cu
;
5618 while ((per_cu
= iter
.next ()) != NULL
)
5619 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5623 /* It's a shame we couldn't do this inside the
5624 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5625 that have already been expanded. Instead, this loop matches what
5626 the psymtab code does. */
5627 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5629 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5630 if (cust
!= nullptr)
5632 const struct block
*block
5633 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5634 if (!iterate_over_symbols_terminated (block
, name
,
5642 dw2_debug_names_expand_symtabs_matching
5643 (struct objfile
*objfile
,
5644 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5645 const lookup_name_info
&lookup_name
,
5646 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5647 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5648 enum search_domain kind
)
5650 struct dwarf2_per_objfile
*dwarf2_per_objfile
5651 = get_dwarf2_per_objfile (objfile
);
5653 /* debug_names_table is NULL if OBJF_READNOW. */
5654 if (!dwarf2_per_objfile
->debug_names_table
)
5657 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5659 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5661 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5663 kind
, [&] (offset_type namei
)
5665 /* The name was matched, now expand corresponding CUs that were
5667 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5669 struct dwarf2_per_cu_data
*per_cu
;
5670 while ((per_cu
= iter
.next ()) != NULL
)
5671 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5677 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5680 dw2_find_last_source_symtab
,
5681 dw2_forget_cached_source_info
,
5682 dw2_map_symtabs_matching_filename
,
5683 dw2_debug_names_lookup_symbol
,
5685 dw2_debug_names_dump
,
5686 dw2_debug_names_expand_symtabs_for_function
,
5687 dw2_expand_all_symtabs
,
5688 dw2_expand_symtabs_with_fullname
,
5689 dw2_debug_names_map_matching_symbols
,
5690 dw2_debug_names_expand_symtabs_matching
,
5691 dw2_find_pc_sect_compunit_symtab
,
5693 dw2_map_symbol_filenames
5696 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5697 to either a dwarf2_per_objfile or dwz_file object. */
5699 template <typename T
>
5700 static gdb::array_view
<const gdb_byte
>
5701 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5703 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5705 if (section
->empty ())
5708 /* Older elfutils strip versions could keep the section in the main
5709 executable while splitting it for the separate debug info file. */
5710 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5713 section
->read (obj
);
5715 /* dwarf2_section_info::size is a bfd_size_type, while
5716 gdb::array_view works with size_t. On 32-bit hosts, with
5717 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5718 is 32-bit. So we need an explicit narrowing conversion here.
5719 This is fine, because it's impossible to allocate or mmap an
5720 array/buffer larger than what size_t can represent. */
5721 return gdb::make_array_view (section
->buffer
, section
->size
);
5724 /* Lookup the index cache for the contents of the index associated to
5727 static gdb::array_view
<const gdb_byte
>
5728 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5730 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5731 if (build_id
== nullptr)
5734 return global_index_cache
.lookup_gdb_index (build_id
,
5735 &dwarf2_obj
->index_cache_res
);
5738 /* Same as the above, but for DWZ. */
5740 static gdb::array_view
<const gdb_byte
>
5741 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5743 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5744 if (build_id
== nullptr)
5747 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5750 /* See symfile.h. */
5753 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5755 struct dwarf2_per_objfile
*dwarf2_per_objfile
5756 = get_dwarf2_per_objfile (objfile
);
5758 /* If we're about to read full symbols, don't bother with the
5759 indices. In this case we also don't care if some other debug
5760 format is making psymtabs, because they are all about to be
5762 if ((objfile
->flags
& OBJF_READNOW
))
5764 dwarf2_per_objfile
->using_index
= 1;
5765 create_all_comp_units (dwarf2_per_objfile
);
5766 create_all_type_units (dwarf2_per_objfile
);
5767 dwarf2_per_objfile
->quick_file_names_table
5768 = create_quick_file_names_table
5769 (dwarf2_per_objfile
->all_comp_units
.size ());
5771 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5772 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5774 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5776 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5777 struct dwarf2_per_cu_quick_data
);
5780 /* Return 1 so that gdb sees the "quick" functions. However,
5781 these functions will be no-ops because we will have expanded
5783 *index_kind
= dw_index_kind::GDB_INDEX
;
5787 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5789 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5793 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5794 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5795 get_gdb_index_contents_from_section
<dwz_file
>))
5797 *index_kind
= dw_index_kind::GDB_INDEX
;
5801 /* ... otherwise, try to find the index in the index cache. */
5802 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5803 get_gdb_index_contents_from_cache
,
5804 get_gdb_index_contents_from_cache_dwz
))
5806 global_index_cache
.hit ();
5807 *index_kind
= dw_index_kind::GDB_INDEX
;
5811 global_index_cache
.miss ();
5817 /* Build a partial symbol table. */
5820 dwarf2_build_psymtabs (struct objfile
*objfile
)
5822 struct dwarf2_per_objfile
*dwarf2_per_objfile
5823 = get_dwarf2_per_objfile (objfile
);
5825 init_psymbol_list (objfile
, 1024);
5829 /* This isn't really ideal: all the data we allocate on the
5830 objfile's obstack is still uselessly kept around. However,
5831 freeing it seems unsafe. */
5832 psymtab_discarder
psymtabs (objfile
);
5833 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5836 /* (maybe) store an index in the cache. */
5837 global_index_cache
.store (dwarf2_per_objfile
);
5839 catch (const gdb_exception_error
&except
)
5841 exception_print (gdb_stderr
, except
);
5845 /* Find the base address of the compilation unit for range lists and
5846 location lists. It will normally be specified by DW_AT_low_pc.
5847 In DWARF-3 draft 4, the base address could be overridden by
5848 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5849 compilation units with discontinuous ranges. */
5852 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5854 struct attribute
*attr
;
5857 cu
->base_address
= 0;
5859 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5860 if (attr
!= nullptr)
5862 cu
->base_address
= attr
->value_as_address ();
5867 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5868 if (attr
!= nullptr)
5870 cu
->base_address
= attr
->value_as_address ();
5876 /* Helper function that returns the proper abbrev section for
5879 static struct dwarf2_section_info
*
5880 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5882 struct dwarf2_section_info
*abbrev
;
5883 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5885 if (this_cu
->is_dwz
)
5886 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5888 abbrev
= &dwarf2_per_objfile
->abbrev
;
5893 /* Fetch the abbreviation table offset from a comp or type unit header. */
5896 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5897 struct dwarf2_section_info
*section
,
5898 sect_offset sect_off
)
5900 bfd
*abfd
= section
->get_bfd_owner ();
5901 const gdb_byte
*info_ptr
;
5902 unsigned int initial_length_size
, offset_size
;
5905 section
->read (dwarf2_per_objfile
->objfile
);
5906 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5907 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5908 offset_size
= initial_length_size
== 4 ? 4 : 8;
5909 info_ptr
+= initial_length_size
;
5911 version
= read_2_bytes (abfd
, info_ptr
);
5915 /* Skip unit type and address size. */
5919 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5922 /* A partial symtab that is used only for include files. */
5923 struct dwarf2_include_psymtab
: public partial_symtab
5925 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5926 : partial_symtab (filename
, objfile
)
5930 void read_symtab (struct objfile
*objfile
) override
5932 expand_psymtab (objfile
);
5935 void expand_psymtab (struct objfile
*objfile
) override
5939 /* It's an include file, no symbols to read for it.
5940 Everything is in the parent symtab. */
5941 read_dependencies (objfile
);
5945 bool readin_p () const override
5950 struct compunit_symtab
*get_compunit_symtab () const override
5957 bool m_readin
= false;
5960 /* Allocate a new partial symtab for file named NAME and mark this new
5961 partial symtab as being an include of PST. */
5964 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5965 struct objfile
*objfile
)
5967 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5969 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5971 /* It shares objfile->objfile_obstack. */
5972 subpst
->dirname
= pst
->dirname
;
5975 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5976 subpst
->dependencies
[0] = pst
;
5977 subpst
->number_of_dependencies
= 1;
5980 /* Read the Line Number Program data and extract the list of files
5981 included by the source file represented by PST. Build an include
5982 partial symtab for each of these included files. */
5985 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5986 struct die_info
*die
,
5987 dwarf2_psymtab
*pst
)
5990 struct attribute
*attr
;
5992 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5993 if (attr
!= nullptr)
5994 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5996 return; /* No linetable, so no includes. */
5998 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5999 that we pass in the raw text_low here; that is ok because we're
6000 only decoding the line table to make include partial symtabs, and
6001 so the addresses aren't really used. */
6002 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6003 pst
->raw_text_low (), 1);
6007 hash_signatured_type (const void *item
)
6009 const struct signatured_type
*sig_type
6010 = (const struct signatured_type
*) item
;
6012 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6013 return sig_type
->signature
;
6017 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6019 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6020 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6022 return lhs
->signature
== rhs
->signature
;
6025 /* Allocate a hash table for signatured types. */
6028 allocate_signatured_type_table ()
6030 return htab_up (htab_create_alloc (41,
6031 hash_signatured_type
,
6033 NULL
, xcalloc
, xfree
));
6036 /* A helper function to add a signatured type CU to a table. */
6039 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6041 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6042 std::vector
<signatured_type
*> *all_type_units
6043 = (std::vector
<signatured_type
*> *) datum
;
6045 all_type_units
->push_back (sigt
);
6050 /* A helper for create_debug_types_hash_table. Read types from SECTION
6051 and fill them into TYPES_HTAB. It will process only type units,
6052 therefore DW_UT_type. */
6055 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6056 struct dwo_file
*dwo_file
,
6057 dwarf2_section_info
*section
, htab_up
&types_htab
,
6058 rcuh_kind section_kind
)
6060 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6061 struct dwarf2_section_info
*abbrev_section
;
6063 const gdb_byte
*info_ptr
, *end_ptr
;
6065 abbrev_section
= (dwo_file
!= NULL
6066 ? &dwo_file
->sections
.abbrev
6067 : &dwarf2_per_objfile
->abbrev
);
6069 if (dwarf_read_debug
)
6070 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6071 section
->get_name (),
6072 abbrev_section
->get_file_name ());
6074 section
->read (objfile
);
6075 info_ptr
= section
->buffer
;
6077 if (info_ptr
== NULL
)
6080 /* We can't set abfd until now because the section may be empty or
6081 not present, in which case the bfd is unknown. */
6082 abfd
= section
->get_bfd_owner ();
6084 /* We don't use cutu_reader here because we don't need to read
6085 any dies: the signature is in the header. */
6087 end_ptr
= info_ptr
+ section
->size
;
6088 while (info_ptr
< end_ptr
)
6090 struct signatured_type
*sig_type
;
6091 struct dwo_unit
*dwo_tu
;
6093 const gdb_byte
*ptr
= info_ptr
;
6094 struct comp_unit_head header
;
6095 unsigned int length
;
6097 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6099 /* Initialize it due to a false compiler warning. */
6100 header
.signature
= -1;
6101 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6103 /* We need to read the type's signature in order to build the hash
6104 table, but we don't need anything else just yet. */
6106 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6107 abbrev_section
, ptr
, section_kind
);
6109 length
= header
.get_length ();
6111 /* Skip dummy type units. */
6112 if (ptr
>= info_ptr
+ length
6113 || peek_abbrev_code (abfd
, ptr
) == 0
6114 || header
.unit_type
!= DW_UT_type
)
6120 if (types_htab
== NULL
)
6123 types_htab
= allocate_dwo_unit_table ();
6125 types_htab
= allocate_signatured_type_table ();
6131 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6133 dwo_tu
->dwo_file
= dwo_file
;
6134 dwo_tu
->signature
= header
.signature
;
6135 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6136 dwo_tu
->section
= section
;
6137 dwo_tu
->sect_off
= sect_off
;
6138 dwo_tu
->length
= length
;
6142 /* N.B.: type_offset is not usable if this type uses a DWO file.
6143 The real type_offset is in the DWO file. */
6145 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6146 struct signatured_type
);
6147 sig_type
->signature
= header
.signature
;
6148 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6149 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6150 sig_type
->per_cu
.is_debug_types
= 1;
6151 sig_type
->per_cu
.section
= section
;
6152 sig_type
->per_cu
.sect_off
= sect_off
;
6153 sig_type
->per_cu
.length
= length
;
6156 slot
= htab_find_slot (types_htab
.get (),
6157 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6159 gdb_assert (slot
!= NULL
);
6162 sect_offset dup_sect_off
;
6166 const struct dwo_unit
*dup_tu
6167 = (const struct dwo_unit
*) *slot
;
6169 dup_sect_off
= dup_tu
->sect_off
;
6173 const struct signatured_type
*dup_tu
6174 = (const struct signatured_type
*) *slot
;
6176 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6179 complaint (_("debug type entry at offset %s is duplicate to"
6180 " the entry at offset %s, signature %s"),
6181 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6182 hex_string (header
.signature
));
6184 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6186 if (dwarf_read_debug
> 1)
6187 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6188 sect_offset_str (sect_off
),
6189 hex_string (header
.signature
));
6195 /* Create the hash table of all entries in the .debug_types
6196 (or .debug_types.dwo) section(s).
6197 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6198 otherwise it is NULL.
6200 The result is a pointer to the hash table or NULL if there are no types.
6202 Note: This function processes DWO files only, not DWP files. */
6205 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6206 struct dwo_file
*dwo_file
,
6207 gdb::array_view
<dwarf2_section_info
> type_sections
,
6208 htab_up
&types_htab
)
6210 for (dwarf2_section_info
§ion
: type_sections
)
6211 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6212 types_htab
, rcuh_kind::TYPE
);
6215 /* Create the hash table of all entries in the .debug_types section,
6216 and initialize all_type_units.
6217 The result is zero if there is an error (e.g. missing .debug_types section),
6218 otherwise non-zero. */
6221 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6225 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6226 &dwarf2_per_objfile
->info
, types_htab
,
6227 rcuh_kind::COMPILE
);
6228 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6229 dwarf2_per_objfile
->types
, types_htab
);
6230 if (types_htab
== NULL
)
6232 dwarf2_per_objfile
->signatured_types
= NULL
;
6236 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6238 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6239 dwarf2_per_objfile
->all_type_units
.reserve
6240 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6242 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6243 add_signatured_type_cu_to_table
,
6244 &dwarf2_per_objfile
->all_type_units
);
6249 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6250 If SLOT is non-NULL, it is the entry to use in the hash table.
6251 Otherwise we find one. */
6253 static struct signatured_type
*
6254 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6257 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6259 if (dwarf2_per_objfile
->all_type_units
.size ()
6260 == dwarf2_per_objfile
->all_type_units
.capacity ())
6261 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6263 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6264 struct signatured_type
);
6266 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6267 sig_type
->signature
= sig
;
6268 sig_type
->per_cu
.is_debug_types
= 1;
6269 if (dwarf2_per_objfile
->using_index
)
6271 sig_type
->per_cu
.v
.quick
=
6272 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6273 struct dwarf2_per_cu_quick_data
);
6278 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6281 gdb_assert (*slot
== NULL
);
6283 /* The rest of sig_type must be filled in by the caller. */
6287 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6288 Fill in SIG_ENTRY with DWO_ENTRY. */
6291 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6292 struct signatured_type
*sig_entry
,
6293 struct dwo_unit
*dwo_entry
)
6295 /* Make sure we're not clobbering something we don't expect to. */
6296 gdb_assert (! sig_entry
->per_cu
.queued
);
6297 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6298 if (dwarf2_per_objfile
->using_index
)
6300 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6301 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6304 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6305 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6306 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6307 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6308 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6310 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6311 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6312 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6313 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6314 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6315 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6316 sig_entry
->dwo_unit
= dwo_entry
;
6319 /* Subroutine of lookup_signatured_type.
6320 If we haven't read the TU yet, create the signatured_type data structure
6321 for a TU to be read in directly from a DWO file, bypassing the stub.
6322 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6323 using .gdb_index, then when reading a CU we want to stay in the DWO file
6324 containing that CU. Otherwise we could end up reading several other DWO
6325 files (due to comdat folding) to process the transitive closure of all the
6326 mentioned TUs, and that can be slow. The current DWO file will have every
6327 type signature that it needs.
6328 We only do this for .gdb_index because in the psymtab case we already have
6329 to read all the DWOs to build the type unit groups. */
6331 static struct signatured_type
*
6332 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6334 struct dwarf2_per_objfile
*dwarf2_per_objfile
6335 = cu
->per_cu
->dwarf2_per_objfile
;
6336 struct dwo_file
*dwo_file
;
6337 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6338 struct signatured_type find_sig_entry
, *sig_entry
;
6341 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6343 /* If TU skeletons have been removed then we may not have read in any
6345 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6346 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6348 /* We only ever need to read in one copy of a signatured type.
6349 Use the global signatured_types array to do our own comdat-folding
6350 of types. If this is the first time we're reading this TU, and
6351 the TU has an entry in .gdb_index, replace the recorded data from
6352 .gdb_index with this TU. */
6354 find_sig_entry
.signature
= sig
;
6355 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6356 &find_sig_entry
, INSERT
);
6357 sig_entry
= (struct signatured_type
*) *slot
;
6359 /* We can get here with the TU already read, *or* in the process of being
6360 read. Don't reassign the global entry to point to this DWO if that's
6361 the case. Also note that if the TU is already being read, it may not
6362 have come from a DWO, the program may be a mix of Fission-compiled
6363 code and non-Fission-compiled code. */
6365 /* Have we already tried to read this TU?
6366 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6367 needn't exist in the global table yet). */
6368 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6371 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6372 dwo_unit of the TU itself. */
6373 dwo_file
= cu
->dwo_unit
->dwo_file
;
6375 /* Ok, this is the first time we're reading this TU. */
6376 if (dwo_file
->tus
== NULL
)
6378 find_dwo_entry
.signature
= sig
;
6379 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6381 if (dwo_entry
== NULL
)
6384 /* If the global table doesn't have an entry for this TU, add one. */
6385 if (sig_entry
== NULL
)
6386 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6388 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6389 sig_entry
->per_cu
.tu_read
= 1;
6393 /* Subroutine of lookup_signatured_type.
6394 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6395 then try the DWP file. If the TU stub (skeleton) has been removed then
6396 it won't be in .gdb_index. */
6398 static struct signatured_type
*
6399 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6401 struct dwarf2_per_objfile
*dwarf2_per_objfile
6402 = cu
->per_cu
->dwarf2_per_objfile
;
6403 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6404 struct dwo_unit
*dwo_entry
;
6405 struct signatured_type find_sig_entry
, *sig_entry
;
6408 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6409 gdb_assert (dwp_file
!= NULL
);
6411 /* If TU skeletons have been removed then we may not have read in any
6413 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6414 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6416 find_sig_entry
.signature
= sig
;
6417 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6418 &find_sig_entry
, INSERT
);
6419 sig_entry
= (struct signatured_type
*) *slot
;
6421 /* Have we already tried to read this TU?
6422 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6423 needn't exist in the global table yet). */
6424 if (sig_entry
!= NULL
)
6427 if (dwp_file
->tus
== NULL
)
6429 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6430 sig
, 1 /* is_debug_types */);
6431 if (dwo_entry
== NULL
)
6434 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6435 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6440 /* Lookup a signature based type for DW_FORM_ref_sig8.
6441 Returns NULL if signature SIG is not present in the table.
6442 It is up to the caller to complain about this. */
6444 static struct signatured_type
*
6445 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6447 struct dwarf2_per_objfile
*dwarf2_per_objfile
6448 = cu
->per_cu
->dwarf2_per_objfile
;
6451 && dwarf2_per_objfile
->using_index
)
6453 /* We're in a DWO/DWP file, and we're using .gdb_index.
6454 These cases require special processing. */
6455 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6456 return lookup_dwo_signatured_type (cu
, sig
);
6458 return lookup_dwp_signatured_type (cu
, sig
);
6462 struct signatured_type find_entry
, *entry
;
6464 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6466 find_entry
.signature
= sig
;
6467 entry
= ((struct signatured_type
*)
6468 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6474 /* Return the address base of the compile unit, which, if exists, is stored
6475 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6476 static gdb::optional
<ULONGEST
>
6477 lookup_addr_base (struct die_info
*comp_unit_die
)
6479 struct attribute
*attr
;
6480 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6481 if (attr
== nullptr)
6482 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6483 if (attr
== nullptr)
6484 return gdb::optional
<ULONGEST
> ();
6485 return DW_UNSND (attr
);
6488 /* Return range lists base of the compile unit, which, if exists, is stored
6489 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6491 lookup_ranges_base (struct die_info
*comp_unit_die
)
6493 struct attribute
*attr
;
6494 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6495 if (attr
== nullptr)
6496 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6497 if (attr
== nullptr)
6499 return DW_UNSND (attr
);
6502 /* Low level DIE reading support. */
6504 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6507 init_cu_die_reader (struct die_reader_specs
*reader
,
6508 struct dwarf2_cu
*cu
,
6509 struct dwarf2_section_info
*section
,
6510 struct dwo_file
*dwo_file
,
6511 struct abbrev_table
*abbrev_table
)
6513 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6514 reader
->abfd
= section
->get_bfd_owner ();
6516 reader
->dwo_file
= dwo_file
;
6517 reader
->die_section
= section
;
6518 reader
->buffer
= section
->buffer
;
6519 reader
->buffer_end
= section
->buffer
+ section
->size
;
6520 reader
->abbrev_table
= abbrev_table
;
6523 /* Subroutine of cutu_reader to simplify it.
6524 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6525 There's just a lot of work to do, and cutu_reader is big enough
6528 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6529 from it to the DIE in the DWO. If NULL we are skipping the stub.
6530 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6531 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6532 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6533 STUB_COMP_DIR may be non-NULL.
6534 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6535 are filled in with the info of the DIE from the DWO file.
6536 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6537 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6538 kept around for at least as long as *RESULT_READER.
6540 The result is non-zero if a valid (non-dummy) DIE was found. */
6543 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6544 struct dwo_unit
*dwo_unit
,
6545 struct die_info
*stub_comp_unit_die
,
6546 const char *stub_comp_dir
,
6547 struct die_reader_specs
*result_reader
,
6548 const gdb_byte
**result_info_ptr
,
6549 struct die_info
**result_comp_unit_die
,
6550 abbrev_table_up
*result_dwo_abbrev_table
)
6552 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6553 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6554 struct dwarf2_cu
*cu
= this_cu
->cu
;
6556 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6557 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6558 int i
,num_extra_attrs
;
6559 struct dwarf2_section_info
*dwo_abbrev_section
;
6560 struct die_info
*comp_unit_die
;
6562 /* At most one of these may be provided. */
6563 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6565 /* These attributes aren't processed until later:
6566 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6567 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6568 referenced later. However, these attributes are found in the stub
6569 which we won't have later. In order to not impose this complication
6570 on the rest of the code, we read them here and copy them to the
6579 if (stub_comp_unit_die
!= NULL
)
6581 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6583 if (! this_cu
->is_debug_types
)
6584 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6585 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6586 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6587 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6588 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6590 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6592 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6593 here (if needed). We need the value before we can process
6595 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6597 else if (stub_comp_dir
!= NULL
)
6599 /* Reconstruct the comp_dir attribute to simplify the code below. */
6600 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6601 comp_dir
->name
= DW_AT_comp_dir
;
6602 comp_dir
->form
= DW_FORM_string
;
6603 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6604 DW_STRING (comp_dir
) = stub_comp_dir
;
6607 /* Set up for reading the DWO CU/TU. */
6608 cu
->dwo_unit
= dwo_unit
;
6609 dwarf2_section_info
*section
= dwo_unit
->section
;
6610 section
->read (objfile
);
6611 abfd
= section
->get_bfd_owner ();
6612 begin_info_ptr
= info_ptr
= (section
->buffer
6613 + to_underlying (dwo_unit
->sect_off
));
6614 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6616 if (this_cu
->is_debug_types
)
6618 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6620 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6621 &cu
->header
, section
,
6623 info_ptr
, rcuh_kind::TYPE
);
6624 /* This is not an assert because it can be caused by bad debug info. */
6625 if (sig_type
->signature
!= cu
->header
.signature
)
6627 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6628 " TU at offset %s [in module %s]"),
6629 hex_string (sig_type
->signature
),
6630 hex_string (cu
->header
.signature
),
6631 sect_offset_str (dwo_unit
->sect_off
),
6632 bfd_get_filename (abfd
));
6634 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6635 /* For DWOs coming from DWP files, we don't know the CU length
6636 nor the type's offset in the TU until now. */
6637 dwo_unit
->length
= cu
->header
.get_length ();
6638 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6640 /* Establish the type offset that can be used to lookup the type.
6641 For DWO files, we don't know it until now. */
6642 sig_type
->type_offset_in_section
6643 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6647 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6648 &cu
->header
, section
,
6650 info_ptr
, rcuh_kind::COMPILE
);
6651 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6652 /* For DWOs coming from DWP files, we don't know the CU length
6654 dwo_unit
->length
= cu
->header
.get_length ();
6657 *result_dwo_abbrev_table
6658 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6659 cu
->header
.abbrev_sect_off
);
6660 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6661 result_dwo_abbrev_table
->get ());
6663 /* Read in the die, but leave space to copy over the attributes
6664 from the stub. This has the benefit of simplifying the rest of
6665 the code - all the work to maintain the illusion of a single
6666 DW_TAG_{compile,type}_unit DIE is done here. */
6667 num_extra_attrs
= ((stmt_list
!= NULL
)
6671 + (comp_dir
!= NULL
));
6672 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6675 /* Copy over the attributes from the stub to the DIE we just read in. */
6676 comp_unit_die
= *result_comp_unit_die
;
6677 i
= comp_unit_die
->num_attrs
;
6678 if (stmt_list
!= NULL
)
6679 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6681 comp_unit_die
->attrs
[i
++] = *low_pc
;
6682 if (high_pc
!= NULL
)
6683 comp_unit_die
->attrs
[i
++] = *high_pc
;
6685 comp_unit_die
->attrs
[i
++] = *ranges
;
6686 if (comp_dir
!= NULL
)
6687 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6688 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6690 if (dwarf_die_debug
)
6692 fprintf_unfiltered (gdb_stdlog
,
6693 "Read die from %s@0x%x of %s:\n",
6694 section
->get_name (),
6695 (unsigned) (begin_info_ptr
- section
->buffer
),
6696 bfd_get_filename (abfd
));
6697 dump_die (comp_unit_die
, dwarf_die_debug
);
6700 /* Skip dummy compilation units. */
6701 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6702 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6705 *result_info_ptr
= info_ptr
;
6709 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6710 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6711 signature is part of the header. */
6712 static gdb::optional
<ULONGEST
>
6713 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6715 if (cu
->header
.version
>= 5)
6716 return cu
->header
.signature
;
6717 struct attribute
*attr
;
6718 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6719 if (attr
== nullptr)
6720 return gdb::optional
<ULONGEST
> ();
6721 return DW_UNSND (attr
);
6724 /* Subroutine of cutu_reader to simplify it.
6725 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6726 Returns NULL if the specified DWO unit cannot be found. */
6728 static struct dwo_unit
*
6729 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6730 struct die_info
*comp_unit_die
,
6731 const char *dwo_name
)
6733 struct dwarf2_cu
*cu
= this_cu
->cu
;
6734 struct dwo_unit
*dwo_unit
;
6735 const char *comp_dir
;
6737 gdb_assert (cu
!= NULL
);
6739 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6740 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6741 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6743 if (this_cu
->is_debug_types
)
6745 struct signatured_type
*sig_type
;
6747 /* Since this_cu is the first member of struct signatured_type,
6748 we can go from a pointer to one to a pointer to the other. */
6749 sig_type
= (struct signatured_type
*) this_cu
;
6750 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6754 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6755 if (!signature
.has_value ())
6756 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6758 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6759 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6766 /* Subroutine of cutu_reader to simplify it.
6767 See it for a description of the parameters.
6768 Read a TU directly from a DWO file, bypassing the stub. */
6771 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6772 int use_existing_cu
)
6774 struct signatured_type
*sig_type
;
6776 /* Verify we can do the following downcast, and that we have the
6778 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6779 sig_type
= (struct signatured_type
*) this_cu
;
6780 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6782 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6784 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6785 /* There's no need to do the rereading_dwo_cu handling that
6786 cutu_reader does since we don't read the stub. */
6790 /* If !use_existing_cu, this_cu->cu must be NULL. */
6791 gdb_assert (this_cu
->cu
== NULL
);
6792 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6795 /* A future optimization, if needed, would be to use an existing
6796 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6797 could share abbrev tables. */
6799 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6800 NULL
/* stub_comp_unit_die */,
6801 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6804 &m_dwo_abbrev_table
) == 0)
6811 /* Initialize a CU (or TU) and read its DIEs.
6812 If the CU defers to a DWO file, read the DWO file as well.
6814 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6815 Otherwise the table specified in the comp unit header is read in and used.
6816 This is an optimization for when we already have the abbrev table.
6818 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6819 Otherwise, a new CU is allocated with xmalloc. */
6821 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6822 struct abbrev_table
*abbrev_table
,
6823 int use_existing_cu
,
6825 : die_reader_specs
{},
6828 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6829 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6830 struct dwarf2_section_info
*section
= this_cu
->section
;
6831 bfd
*abfd
= section
->get_bfd_owner ();
6832 struct dwarf2_cu
*cu
;
6833 const gdb_byte
*begin_info_ptr
;
6834 struct signatured_type
*sig_type
= NULL
;
6835 struct dwarf2_section_info
*abbrev_section
;
6836 /* Non-zero if CU currently points to a DWO file and we need to
6837 reread it. When this happens we need to reread the skeleton die
6838 before we can reread the DWO file (this only applies to CUs, not TUs). */
6839 int rereading_dwo_cu
= 0;
6841 if (dwarf_die_debug
)
6842 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6843 this_cu
->is_debug_types
? "type" : "comp",
6844 sect_offset_str (this_cu
->sect_off
));
6846 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6847 file (instead of going through the stub), short-circuit all of this. */
6848 if (this_cu
->reading_dwo_directly
)
6850 /* Narrow down the scope of possibilities to have to understand. */
6851 gdb_assert (this_cu
->is_debug_types
);
6852 gdb_assert (abbrev_table
== NULL
);
6853 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6857 /* This is cheap if the section is already read in. */
6858 section
->read (objfile
);
6860 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6862 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6864 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6867 /* If this CU is from a DWO file we need to start over, we need to
6868 refetch the attributes from the skeleton CU.
6869 This could be optimized by retrieving those attributes from when we
6870 were here the first time: the previous comp_unit_die was stored in
6871 comp_unit_obstack. But there's no data yet that we need this
6873 if (cu
->dwo_unit
!= NULL
)
6874 rereading_dwo_cu
= 1;
6878 /* If !use_existing_cu, this_cu->cu must be NULL. */
6879 gdb_assert (this_cu
->cu
== NULL
);
6880 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6881 cu
= m_new_cu
.get ();
6884 /* Get the header. */
6885 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6887 /* We already have the header, there's no need to read it in again. */
6888 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6892 if (this_cu
->is_debug_types
)
6894 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6895 &cu
->header
, section
,
6896 abbrev_section
, info_ptr
,
6899 /* Since per_cu is the first member of struct signatured_type,
6900 we can go from a pointer to one to a pointer to the other. */
6901 sig_type
= (struct signatured_type
*) this_cu
;
6902 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6903 gdb_assert (sig_type
->type_offset_in_tu
6904 == cu
->header
.type_cu_offset_in_tu
);
6905 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6907 /* LENGTH has not been set yet for type units if we're
6908 using .gdb_index. */
6909 this_cu
->length
= cu
->header
.get_length ();
6911 /* Establish the type offset that can be used to lookup the type. */
6912 sig_type
->type_offset_in_section
=
6913 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6915 this_cu
->dwarf_version
= cu
->header
.version
;
6919 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6920 &cu
->header
, section
,
6923 rcuh_kind::COMPILE
);
6925 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6926 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6927 this_cu
->dwarf_version
= cu
->header
.version
;
6931 /* Skip dummy compilation units. */
6932 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6933 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6939 /* If we don't have them yet, read the abbrevs for this compilation unit.
6940 And if we need to read them now, make sure they're freed when we're
6942 if (abbrev_table
!= NULL
)
6943 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6946 m_abbrev_table_holder
6947 = abbrev_table::read (objfile
, abbrev_section
,
6948 cu
->header
.abbrev_sect_off
);
6949 abbrev_table
= m_abbrev_table_holder
.get ();
6952 /* Read the top level CU/TU die. */
6953 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6954 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6956 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6962 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6963 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6964 table from the DWO file and pass the ownership over to us. It will be
6965 referenced from READER, so we must make sure to free it after we're done
6968 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6969 DWO CU, that this test will fail (the attribute will not be present). */
6970 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6971 if (dwo_name
!= nullptr)
6973 struct dwo_unit
*dwo_unit
;
6974 struct die_info
*dwo_comp_unit_die
;
6976 if (comp_unit_die
->has_children
)
6978 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6979 " has children (offset %s) [in module %s]"),
6980 sect_offset_str (this_cu
->sect_off
),
6981 bfd_get_filename (abfd
));
6983 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6984 if (dwo_unit
!= NULL
)
6986 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6987 comp_unit_die
, NULL
,
6990 &m_dwo_abbrev_table
) == 0)
6996 comp_unit_die
= dwo_comp_unit_die
;
7000 /* Yikes, we couldn't find the rest of the DIE, we only have
7001 the stub. A complaint has already been logged. There's
7002 not much more we can do except pass on the stub DIE to
7003 die_reader_func. We don't want to throw an error on bad
7010 cutu_reader::keep ()
7012 /* Done, clean up. */
7013 gdb_assert (!dummy_p
);
7014 if (m_new_cu
!= NULL
)
7016 struct dwarf2_per_objfile
*dwarf2_per_objfile
7017 = m_this_cu
->dwarf2_per_objfile
;
7018 /* Link this CU into read_in_chain. */
7019 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7020 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7021 /* The chain owns it now. */
7022 m_new_cu
.release ();
7026 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7027 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7028 assumed to have already done the lookup to find the DWO file).
7030 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7031 THIS_CU->is_debug_types, but nothing else.
7033 We fill in THIS_CU->length.
7035 THIS_CU->cu is always freed when done.
7036 This is done in order to not leave THIS_CU->cu in a state where we have
7037 to care whether it refers to the "main" CU or the DWO CU.
7039 When parent_cu is passed, it is used to provide a default value for
7040 str_offsets_base and addr_base from the parent. */
7042 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7043 struct dwarf2_cu
*parent_cu
,
7044 struct dwo_file
*dwo_file
)
7045 : die_reader_specs
{},
7048 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7049 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7050 struct dwarf2_section_info
*section
= this_cu
->section
;
7051 bfd
*abfd
= section
->get_bfd_owner ();
7052 struct dwarf2_section_info
*abbrev_section
;
7053 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7055 if (dwarf_die_debug
)
7056 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7057 this_cu
->is_debug_types
? "type" : "comp",
7058 sect_offset_str (this_cu
->sect_off
));
7060 gdb_assert (this_cu
->cu
== NULL
);
7062 abbrev_section
= (dwo_file
!= NULL
7063 ? &dwo_file
->sections
.abbrev
7064 : get_abbrev_section_for_cu (this_cu
));
7066 /* This is cheap if the section is already read in. */
7067 section
->read (objfile
);
7069 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7071 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7072 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7073 &m_new_cu
->header
, section
,
7074 abbrev_section
, info_ptr
,
7075 (this_cu
->is_debug_types
7077 : rcuh_kind::COMPILE
));
7079 if (parent_cu
!= nullptr)
7081 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7082 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7084 this_cu
->length
= m_new_cu
->header
.get_length ();
7086 /* Skip dummy compilation units. */
7087 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7088 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7094 m_abbrev_table_holder
7095 = abbrev_table::read (objfile
, abbrev_section
,
7096 m_new_cu
->header
.abbrev_sect_off
);
7098 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7099 m_abbrev_table_holder
.get ());
7100 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7104 /* Type Unit Groups.
7106 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7107 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7108 so that all types coming from the same compilation (.o file) are grouped
7109 together. A future step could be to put the types in the same symtab as
7110 the CU the types ultimately came from. */
7113 hash_type_unit_group (const void *item
)
7115 const struct type_unit_group
*tu_group
7116 = (const struct type_unit_group
*) item
;
7118 return hash_stmt_list_entry (&tu_group
->hash
);
7122 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7124 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7125 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7127 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7130 /* Allocate a hash table for type unit groups. */
7133 allocate_type_unit_groups_table ()
7135 return htab_up (htab_create_alloc (3,
7136 hash_type_unit_group
,
7138 NULL
, xcalloc
, xfree
));
7141 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7142 partial symtabs. We combine several TUs per psymtab to not let the size
7143 of any one psymtab grow too big. */
7144 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7145 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7147 /* Helper routine for get_type_unit_group.
7148 Create the type_unit_group object used to hold one or more TUs. */
7150 static struct type_unit_group
*
7151 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7153 struct dwarf2_per_objfile
*dwarf2_per_objfile
7154 = cu
->per_cu
->dwarf2_per_objfile
;
7155 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7156 struct dwarf2_per_cu_data
*per_cu
;
7157 struct type_unit_group
*tu_group
;
7159 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7160 struct type_unit_group
);
7161 per_cu
= &tu_group
->per_cu
;
7162 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7164 if (dwarf2_per_objfile
->using_index
)
7166 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7167 struct dwarf2_per_cu_quick_data
);
7171 unsigned int line_offset
= to_underlying (line_offset_struct
);
7172 dwarf2_psymtab
*pst
;
7175 /* Give the symtab a useful name for debug purposes. */
7176 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7177 name
= string_printf ("<type_units_%d>",
7178 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7180 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7182 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7183 pst
->anonymous
= true;
7186 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7187 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7192 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7193 STMT_LIST is a DW_AT_stmt_list attribute. */
7195 static struct type_unit_group
*
7196 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7198 struct dwarf2_per_objfile
*dwarf2_per_objfile
7199 = cu
->per_cu
->dwarf2_per_objfile
;
7200 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7201 struct type_unit_group
*tu_group
;
7203 unsigned int line_offset
;
7204 struct type_unit_group type_unit_group_for_lookup
;
7206 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7207 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7209 /* Do we need to create a new group, or can we use an existing one? */
7213 line_offset
= DW_UNSND (stmt_list
);
7214 ++tu_stats
->nr_symtab_sharers
;
7218 /* Ugh, no stmt_list. Rare, but we have to handle it.
7219 We can do various things here like create one group per TU or
7220 spread them over multiple groups to split up the expansion work.
7221 To avoid worst case scenarios (too many groups or too large groups)
7222 we, umm, group them in bunches. */
7223 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7224 | (tu_stats
->nr_stmt_less_type_units
7225 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7226 ++tu_stats
->nr_stmt_less_type_units
;
7229 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7230 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7231 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7232 &type_unit_group_for_lookup
, INSERT
);
7235 tu_group
= (struct type_unit_group
*) *slot
;
7236 gdb_assert (tu_group
!= NULL
);
7240 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7241 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7243 ++tu_stats
->nr_symtabs
;
7249 /* Partial symbol tables. */
7251 /* Create a psymtab named NAME and assign it to PER_CU.
7253 The caller must fill in the following details:
7254 dirname, textlow, texthigh. */
7256 static dwarf2_psymtab
*
7257 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7259 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7260 dwarf2_psymtab
*pst
;
7262 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7264 pst
->psymtabs_addrmap_supported
= true;
7266 /* This is the glue that links PST into GDB's symbol API. */
7267 pst
->per_cu_data
= per_cu
;
7268 per_cu
->v
.psymtab
= pst
;
7273 /* DIE reader function for process_psymtab_comp_unit. */
7276 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7277 const gdb_byte
*info_ptr
,
7278 struct die_info
*comp_unit_die
,
7279 enum language pretend_language
)
7281 struct dwarf2_cu
*cu
= reader
->cu
;
7282 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7283 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7284 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7286 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7287 dwarf2_psymtab
*pst
;
7288 enum pc_bounds_kind cu_bounds_kind
;
7289 const char *filename
;
7291 gdb_assert (! per_cu
->is_debug_types
);
7293 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7295 /* Allocate a new partial symbol table structure. */
7296 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7297 static const char artificial
[] = "<artificial>";
7298 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7299 if (filename
== NULL
)
7301 else if (strcmp (filename
, artificial
) == 0)
7303 debug_filename
.reset (concat (artificial
, "@",
7304 sect_offset_str (per_cu
->sect_off
),
7306 filename
= debug_filename
.get ();
7309 pst
= create_partial_symtab (per_cu
, filename
);
7311 /* This must be done before calling dwarf2_build_include_psymtabs. */
7312 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7314 baseaddr
= objfile
->text_section_offset ();
7316 dwarf2_find_base_address (comp_unit_die
, cu
);
7318 /* Possibly set the default values of LOWPC and HIGHPC from
7320 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7321 &best_highpc
, cu
, pst
);
7322 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7325 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7328 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7330 /* Store the contiguous range if it is not empty; it can be
7331 empty for CUs with no code. */
7332 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7336 /* Check if comp unit has_children.
7337 If so, read the rest of the partial symbols from this comp unit.
7338 If not, there's no more debug_info for this comp unit. */
7339 if (comp_unit_die
->has_children
)
7341 struct partial_die_info
*first_die
;
7342 CORE_ADDR lowpc
, highpc
;
7344 lowpc
= ((CORE_ADDR
) -1);
7345 highpc
= ((CORE_ADDR
) 0);
7347 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7349 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7350 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7352 /* If we didn't find a lowpc, set it to highpc to avoid
7353 complaints from `maint check'. */
7354 if (lowpc
== ((CORE_ADDR
) -1))
7357 /* If the compilation unit didn't have an explicit address range,
7358 then use the information extracted from its child dies. */
7359 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7362 best_highpc
= highpc
;
7365 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7366 best_lowpc
+ baseaddr
)
7368 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7369 best_highpc
+ baseaddr
)
7372 end_psymtab_common (objfile
, pst
);
7374 if (!cu
->per_cu
->imported_symtabs_empty ())
7377 int len
= cu
->per_cu
->imported_symtabs_size ();
7379 /* Fill in 'dependencies' here; we fill in 'users' in a
7381 pst
->number_of_dependencies
= len
;
7383 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7384 for (i
= 0; i
< len
; ++i
)
7386 pst
->dependencies
[i
]
7387 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7390 cu
->per_cu
->imported_symtabs_free ();
7393 /* Get the list of files included in the current compilation unit,
7394 and build a psymtab for each of them. */
7395 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7397 if (dwarf_read_debug
)
7398 fprintf_unfiltered (gdb_stdlog
,
7399 "Psymtab for %s unit @%s: %s - %s"
7400 ", %d global, %d static syms\n",
7401 per_cu
->is_debug_types
? "type" : "comp",
7402 sect_offset_str (per_cu
->sect_off
),
7403 paddress (gdbarch
, pst
->text_low (objfile
)),
7404 paddress (gdbarch
, pst
->text_high (objfile
)),
7405 pst
->n_global_syms
, pst
->n_static_syms
);
7408 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7409 Process compilation unit THIS_CU for a psymtab. */
7412 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7413 bool want_partial_unit
,
7414 enum language pretend_language
)
7416 /* If this compilation unit was already read in, free the
7417 cached copy in order to read it in again. This is
7418 necessary because we skipped some symbols when we first
7419 read in the compilation unit (see load_partial_dies).
7420 This problem could be avoided, but the benefit is unclear. */
7421 if (this_cu
->cu
!= NULL
)
7422 free_one_cached_comp_unit (this_cu
);
7424 cutu_reader
reader (this_cu
, NULL
, 0, false);
7426 switch (reader
.comp_unit_die
->tag
)
7428 case DW_TAG_compile_unit
:
7429 this_cu
->unit_type
= DW_UT_compile
;
7431 case DW_TAG_partial_unit
:
7432 this_cu
->unit_type
= DW_UT_partial
;
7442 else if (this_cu
->is_debug_types
)
7443 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7444 reader
.comp_unit_die
);
7445 else if (want_partial_unit
7446 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7447 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7448 reader
.comp_unit_die
,
7451 this_cu
->lang
= this_cu
->cu
->language
;
7453 /* Age out any secondary CUs. */
7454 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7457 /* Reader function for build_type_psymtabs. */
7460 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7461 const gdb_byte
*info_ptr
,
7462 struct die_info
*type_unit_die
)
7464 struct dwarf2_per_objfile
*dwarf2_per_objfile
7465 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7466 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7467 struct dwarf2_cu
*cu
= reader
->cu
;
7468 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7469 struct signatured_type
*sig_type
;
7470 struct type_unit_group
*tu_group
;
7471 struct attribute
*attr
;
7472 struct partial_die_info
*first_die
;
7473 CORE_ADDR lowpc
, highpc
;
7474 dwarf2_psymtab
*pst
;
7476 gdb_assert (per_cu
->is_debug_types
);
7477 sig_type
= (struct signatured_type
*) per_cu
;
7479 if (! type_unit_die
->has_children
)
7482 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7483 tu_group
= get_type_unit_group (cu
, attr
);
7485 if (tu_group
->tus
== nullptr)
7486 tu_group
->tus
= new std::vector
<signatured_type
*>;
7487 tu_group
->tus
->push_back (sig_type
);
7489 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7490 pst
= create_partial_symtab (per_cu
, "");
7491 pst
->anonymous
= true;
7493 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7495 lowpc
= (CORE_ADDR
) -1;
7496 highpc
= (CORE_ADDR
) 0;
7497 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7499 end_psymtab_common (objfile
, pst
);
7502 /* Struct used to sort TUs by their abbreviation table offset. */
7504 struct tu_abbrev_offset
7506 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7507 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7510 signatured_type
*sig_type
;
7511 sect_offset abbrev_offset
;
7514 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7517 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7518 const struct tu_abbrev_offset
&b
)
7520 return a
.abbrev_offset
< b
.abbrev_offset
;
7523 /* Efficiently read all the type units.
7524 This does the bulk of the work for build_type_psymtabs.
7526 The efficiency is because we sort TUs by the abbrev table they use and
7527 only read each abbrev table once. In one program there are 200K TUs
7528 sharing 8K abbrev tables.
7530 The main purpose of this function is to support building the
7531 dwarf2_per_objfile->type_unit_groups table.
7532 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7533 can collapse the search space by grouping them by stmt_list.
7534 The savings can be significant, in the same program from above the 200K TUs
7535 share 8K stmt_list tables.
7537 FUNC is expected to call get_type_unit_group, which will create the
7538 struct type_unit_group if necessary and add it to
7539 dwarf2_per_objfile->type_unit_groups. */
7542 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7544 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7545 abbrev_table_up abbrev_table
;
7546 sect_offset abbrev_offset
;
7548 /* It's up to the caller to not call us multiple times. */
7549 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7551 if (dwarf2_per_objfile
->all_type_units
.empty ())
7554 /* TUs typically share abbrev tables, and there can be way more TUs than
7555 abbrev tables. Sort by abbrev table to reduce the number of times we
7556 read each abbrev table in.
7557 Alternatives are to punt or to maintain a cache of abbrev tables.
7558 This is simpler and efficient enough for now.
7560 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7561 symtab to use). Typically TUs with the same abbrev offset have the same
7562 stmt_list value too so in practice this should work well.
7564 The basic algorithm here is:
7566 sort TUs by abbrev table
7567 for each TU with same abbrev table:
7568 read abbrev table if first user
7569 read TU top level DIE
7570 [IWBN if DWO skeletons had DW_AT_stmt_list]
7573 if (dwarf_read_debug
)
7574 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7576 /* Sort in a separate table to maintain the order of all_type_units
7577 for .gdb_index: TU indices directly index all_type_units. */
7578 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7579 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7581 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7582 sorted_by_abbrev
.emplace_back
7583 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7584 sig_type
->per_cu
.section
,
7585 sig_type
->per_cu
.sect_off
));
7587 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7588 sort_tu_by_abbrev_offset
);
7590 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7592 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7594 /* Switch to the next abbrev table if necessary. */
7595 if (abbrev_table
== NULL
7596 || tu
.abbrev_offset
!= abbrev_offset
)
7598 abbrev_offset
= tu
.abbrev_offset
;
7600 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7601 &dwarf2_per_objfile
->abbrev
,
7603 ++tu_stats
->nr_uniq_abbrev_tables
;
7606 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7608 if (!reader
.dummy_p
)
7609 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7610 reader
.comp_unit_die
);
7614 /* Print collected type unit statistics. */
7617 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7619 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7621 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7622 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7623 dwarf2_per_objfile
->all_type_units
.size ());
7624 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7625 tu_stats
->nr_uniq_abbrev_tables
);
7626 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7627 tu_stats
->nr_symtabs
);
7628 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7629 tu_stats
->nr_symtab_sharers
);
7630 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7631 tu_stats
->nr_stmt_less_type_units
);
7632 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7633 tu_stats
->nr_all_type_units_reallocs
);
7636 /* Traversal function for build_type_psymtabs. */
7639 build_type_psymtab_dependencies (void **slot
, void *info
)
7641 struct dwarf2_per_objfile
*dwarf2_per_objfile
7642 = (struct dwarf2_per_objfile
*) info
;
7643 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7644 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7645 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7646 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7647 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7650 gdb_assert (len
> 0);
7651 gdb_assert (per_cu
->type_unit_group_p ());
7653 pst
->number_of_dependencies
= len
;
7654 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7655 for (i
= 0; i
< len
; ++i
)
7657 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7658 gdb_assert (iter
->per_cu
.is_debug_types
);
7659 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7660 iter
->type_unit_group
= tu_group
;
7663 delete tu_group
->tus
;
7664 tu_group
->tus
= nullptr;
7669 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7670 Build partial symbol tables for the .debug_types comp-units. */
7673 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7675 if (! create_all_type_units (dwarf2_per_objfile
))
7678 build_type_psymtabs_1 (dwarf2_per_objfile
);
7681 /* Traversal function for process_skeletonless_type_unit.
7682 Read a TU in a DWO file and build partial symbols for it. */
7685 process_skeletonless_type_unit (void **slot
, void *info
)
7687 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7688 struct dwarf2_per_objfile
*dwarf2_per_objfile
7689 = (struct dwarf2_per_objfile
*) info
;
7690 struct signatured_type find_entry
, *entry
;
7692 /* If this TU doesn't exist in the global table, add it and read it in. */
7694 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7695 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7697 find_entry
.signature
= dwo_unit
->signature
;
7698 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7699 &find_entry
, INSERT
);
7700 /* If we've already seen this type there's nothing to do. What's happening
7701 is we're doing our own version of comdat-folding here. */
7705 /* This does the job that create_all_type_units would have done for
7707 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7708 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7711 /* This does the job that build_type_psymtabs_1 would have done. */
7712 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7713 if (!reader
.dummy_p
)
7714 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7715 reader
.comp_unit_die
);
7720 /* Traversal function for process_skeletonless_type_units. */
7723 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7725 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7727 if (dwo_file
->tus
!= NULL
)
7728 htab_traverse_noresize (dwo_file
->tus
.get (),
7729 process_skeletonless_type_unit
, info
);
7734 /* Scan all TUs of DWO files, verifying we've processed them.
7735 This is needed in case a TU was emitted without its skeleton.
7736 Note: This can't be done until we know what all the DWO files are. */
7739 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7741 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7742 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7743 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7745 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7746 process_dwo_file_for_skeletonless_type_units
,
7747 dwarf2_per_objfile
);
7751 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7754 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7756 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7758 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7763 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7765 /* Set the 'user' field only if it is not already set. */
7766 if (pst
->dependencies
[j
]->user
== NULL
)
7767 pst
->dependencies
[j
]->user
= pst
;
7772 /* Build the partial symbol table by doing a quick pass through the
7773 .debug_info and .debug_abbrev sections. */
7776 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7778 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7780 if (dwarf_read_debug
)
7782 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7783 objfile_name (objfile
));
7786 scoped_restore restore_reading_psyms
7787 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7790 dwarf2_per_objfile
->info
.read (objfile
);
7792 /* Any cached compilation units will be linked by the per-objfile
7793 read_in_chain. Make sure to free them when we're done. */
7794 free_cached_comp_units
freer (dwarf2_per_objfile
);
7796 build_type_psymtabs (dwarf2_per_objfile
);
7798 create_all_comp_units (dwarf2_per_objfile
);
7800 /* Create a temporary address map on a temporary obstack. We later
7801 copy this to the final obstack. */
7802 auto_obstack temp_obstack
;
7804 scoped_restore save_psymtabs_addrmap
7805 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7806 addrmap_create_mutable (&temp_obstack
));
7808 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7809 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7811 /* This has to wait until we read the CUs, we need the list of DWOs. */
7812 process_skeletonless_type_units (dwarf2_per_objfile
);
7814 /* Now that all TUs have been processed we can fill in the dependencies. */
7815 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7817 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7818 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7821 if (dwarf_read_debug
)
7822 print_tu_stats (dwarf2_per_objfile
);
7824 set_partial_user (dwarf2_per_objfile
);
7826 objfile
->partial_symtabs
->psymtabs_addrmap
7827 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7828 objfile
->partial_symtabs
->obstack ());
7829 /* At this point we want to keep the address map. */
7830 save_psymtabs_addrmap
.release ();
7832 if (dwarf_read_debug
)
7833 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7834 objfile_name (objfile
));
7837 /* Load the partial DIEs for a secondary CU into memory.
7838 This is also used when rereading a primary CU with load_all_dies. */
7841 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7843 cutu_reader
reader (this_cu
, NULL
, 1, false);
7845 if (!reader
.dummy_p
)
7847 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7850 /* Check if comp unit has_children.
7851 If so, read the rest of the partial symbols from this comp unit.
7852 If not, there's no more debug_info for this comp unit. */
7853 if (reader
.comp_unit_die
->has_children
)
7854 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7861 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7862 struct dwarf2_section_info
*section
,
7863 struct dwarf2_section_info
*abbrev_section
,
7864 unsigned int is_dwz
)
7866 const gdb_byte
*info_ptr
;
7867 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7869 if (dwarf_read_debug
)
7870 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7871 section
->get_name (),
7872 section
->get_file_name ());
7874 section
->read (objfile
);
7876 info_ptr
= section
->buffer
;
7878 while (info_ptr
< section
->buffer
+ section
->size
)
7880 struct dwarf2_per_cu_data
*this_cu
;
7882 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7884 comp_unit_head cu_header
;
7885 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7886 abbrev_section
, info_ptr
,
7887 rcuh_kind::COMPILE
);
7889 /* Save the compilation unit for later lookup. */
7890 if (cu_header
.unit_type
!= DW_UT_type
)
7892 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7893 struct dwarf2_per_cu_data
);
7894 memset (this_cu
, 0, sizeof (*this_cu
));
7898 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7899 struct signatured_type
);
7900 memset (sig_type
, 0, sizeof (*sig_type
));
7901 sig_type
->signature
= cu_header
.signature
;
7902 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7903 this_cu
= &sig_type
->per_cu
;
7905 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7906 this_cu
->sect_off
= sect_off
;
7907 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7908 this_cu
->is_dwz
= is_dwz
;
7909 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7910 this_cu
->section
= section
;
7912 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7914 info_ptr
= info_ptr
+ this_cu
->length
;
7918 /* Create a list of all compilation units in OBJFILE.
7919 This is only done for -readnow and building partial symtabs. */
7922 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7924 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7925 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7926 &dwarf2_per_objfile
->abbrev
, 0);
7928 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7930 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7934 /* Process all loaded DIEs for compilation unit CU, starting at
7935 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7936 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7937 DW_AT_ranges). See the comments of add_partial_subprogram on how
7938 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7941 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7942 CORE_ADDR
*highpc
, int set_addrmap
,
7943 struct dwarf2_cu
*cu
)
7945 struct partial_die_info
*pdi
;
7947 /* Now, march along the PDI's, descending into ones which have
7948 interesting children but skipping the children of the other ones,
7949 until we reach the end of the compilation unit. */
7957 /* Anonymous namespaces or modules have no name but have interesting
7958 children, so we need to look at them. Ditto for anonymous
7961 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7962 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7963 || pdi
->tag
== DW_TAG_imported_unit
7964 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7968 case DW_TAG_subprogram
:
7969 case DW_TAG_inlined_subroutine
:
7970 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7972 case DW_TAG_constant
:
7973 case DW_TAG_variable
:
7974 case DW_TAG_typedef
:
7975 case DW_TAG_union_type
:
7976 if (!pdi
->is_declaration
)
7978 add_partial_symbol (pdi
, cu
);
7981 case DW_TAG_class_type
:
7982 case DW_TAG_interface_type
:
7983 case DW_TAG_structure_type
:
7984 if (!pdi
->is_declaration
)
7986 add_partial_symbol (pdi
, cu
);
7988 if ((cu
->language
== language_rust
7989 || cu
->language
== language_cplus
) && pdi
->has_children
)
7990 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7993 case DW_TAG_enumeration_type
:
7994 if (!pdi
->is_declaration
)
7995 add_partial_enumeration (pdi
, cu
);
7997 case DW_TAG_base_type
:
7998 case DW_TAG_subrange_type
:
7999 /* File scope base type definitions are added to the partial
8001 add_partial_symbol (pdi
, cu
);
8003 case DW_TAG_namespace
:
8004 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8007 if (!pdi
->is_declaration
)
8008 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8010 case DW_TAG_imported_unit
:
8012 struct dwarf2_per_cu_data
*per_cu
;
8014 /* For now we don't handle imported units in type units. */
8015 if (cu
->per_cu
->is_debug_types
)
8017 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8018 " supported in type units [in module %s]"),
8019 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8022 per_cu
= dwarf2_find_containing_comp_unit
8023 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8024 cu
->per_cu
->dwarf2_per_objfile
);
8026 /* Go read the partial unit, if needed. */
8027 if (per_cu
->v
.psymtab
== NULL
)
8028 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
8030 cu
->per_cu
->imported_symtabs_push (per_cu
);
8033 case DW_TAG_imported_declaration
:
8034 add_partial_symbol (pdi
, cu
);
8041 /* If the die has a sibling, skip to the sibling. */
8043 pdi
= pdi
->die_sibling
;
8047 /* Functions used to compute the fully scoped name of a partial DIE.
8049 Normally, this is simple. For C++, the parent DIE's fully scoped
8050 name is concatenated with "::" and the partial DIE's name.
8051 Enumerators are an exception; they use the scope of their parent
8052 enumeration type, i.e. the name of the enumeration type is not
8053 prepended to the enumerator.
8055 There are two complexities. One is DW_AT_specification; in this
8056 case "parent" means the parent of the target of the specification,
8057 instead of the direct parent of the DIE. The other is compilers
8058 which do not emit DW_TAG_namespace; in this case we try to guess
8059 the fully qualified name of structure types from their members'
8060 linkage names. This must be done using the DIE's children rather
8061 than the children of any DW_AT_specification target. We only need
8062 to do this for structures at the top level, i.e. if the target of
8063 any DW_AT_specification (if any; otherwise the DIE itself) does not
8066 /* Compute the scope prefix associated with PDI's parent, in
8067 compilation unit CU. The result will be allocated on CU's
8068 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8069 field. NULL is returned if no prefix is necessary. */
8071 partial_die_parent_scope (struct partial_die_info
*pdi
,
8072 struct dwarf2_cu
*cu
)
8074 const char *grandparent_scope
;
8075 struct partial_die_info
*parent
, *real_pdi
;
8077 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8078 then this means the parent of the specification DIE. */
8081 while (real_pdi
->has_specification
)
8083 auto res
= find_partial_die (real_pdi
->spec_offset
,
8084 real_pdi
->spec_is_dwz
, cu
);
8089 parent
= real_pdi
->die_parent
;
8093 if (parent
->scope_set
)
8094 return parent
->scope
;
8098 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8100 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8101 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8102 Work around this problem here. */
8103 if (cu
->language
== language_cplus
8104 && parent
->tag
== DW_TAG_namespace
8105 && strcmp (parent
->name
, "::") == 0
8106 && grandparent_scope
== NULL
)
8108 parent
->scope
= NULL
;
8109 parent
->scope_set
= 1;
8113 /* Nested subroutines in Fortran get a prefix. */
8114 if (pdi
->tag
== DW_TAG_enumerator
)
8115 /* Enumerators should not get the name of the enumeration as a prefix. */
8116 parent
->scope
= grandparent_scope
;
8117 else if (parent
->tag
== DW_TAG_namespace
8118 || parent
->tag
== DW_TAG_module
8119 || parent
->tag
== DW_TAG_structure_type
8120 || parent
->tag
== DW_TAG_class_type
8121 || parent
->tag
== DW_TAG_interface_type
8122 || parent
->tag
== DW_TAG_union_type
8123 || parent
->tag
== DW_TAG_enumeration_type
8124 || (cu
->language
== language_fortran
8125 && parent
->tag
== DW_TAG_subprogram
8126 && pdi
->tag
== DW_TAG_subprogram
))
8128 if (grandparent_scope
== NULL
)
8129 parent
->scope
= parent
->name
;
8131 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8133 parent
->name
, 0, cu
);
8137 /* FIXME drow/2004-04-01: What should we be doing with
8138 function-local names? For partial symbols, we should probably be
8140 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8141 dwarf_tag_name (parent
->tag
),
8142 sect_offset_str (pdi
->sect_off
));
8143 parent
->scope
= grandparent_scope
;
8146 parent
->scope_set
= 1;
8147 return parent
->scope
;
8150 /* Return the fully scoped name associated with PDI, from compilation unit
8151 CU. The result will be allocated with malloc. */
8153 static gdb::unique_xmalloc_ptr
<char>
8154 partial_die_full_name (struct partial_die_info
*pdi
,
8155 struct dwarf2_cu
*cu
)
8157 const char *parent_scope
;
8159 /* If this is a template instantiation, we can not work out the
8160 template arguments from partial DIEs. So, unfortunately, we have
8161 to go through the full DIEs. At least any work we do building
8162 types here will be reused if full symbols are loaded later. */
8163 if (pdi
->has_template_arguments
)
8167 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8169 struct die_info
*die
;
8170 struct attribute attr
;
8171 struct dwarf2_cu
*ref_cu
= cu
;
8173 /* DW_FORM_ref_addr is using section offset. */
8174 attr
.name
= (enum dwarf_attribute
) 0;
8175 attr
.form
= DW_FORM_ref_addr
;
8176 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8177 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8179 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8183 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8184 if (parent_scope
== NULL
)
8187 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8192 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8194 struct dwarf2_per_objfile
*dwarf2_per_objfile
8195 = cu
->per_cu
->dwarf2_per_objfile
;
8196 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8197 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8199 const char *actual_name
= NULL
;
8202 baseaddr
= objfile
->text_section_offset ();
8204 gdb::unique_xmalloc_ptr
<char> built_actual_name
8205 = partial_die_full_name (pdi
, cu
);
8206 if (built_actual_name
!= NULL
)
8207 actual_name
= built_actual_name
.get ();
8209 if (actual_name
== NULL
)
8210 actual_name
= pdi
->name
;
8214 case DW_TAG_inlined_subroutine
:
8215 case DW_TAG_subprogram
:
8216 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8218 if (pdi
->is_external
8219 || cu
->language
== language_ada
8220 || (cu
->language
== language_fortran
8221 && pdi
->die_parent
!= NULL
8222 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8224 /* Normally, only "external" DIEs are part of the global scope.
8225 But in Ada and Fortran, we want to be able to access nested
8226 procedures globally. So all Ada and Fortran subprograms are
8227 stored in the global scope. */
8228 add_psymbol_to_list (actual_name
,
8229 built_actual_name
!= NULL
,
8230 VAR_DOMAIN
, LOC_BLOCK
,
8231 SECT_OFF_TEXT (objfile
),
8232 psymbol_placement::GLOBAL
,
8234 cu
->language
, objfile
);
8238 add_psymbol_to_list (actual_name
,
8239 built_actual_name
!= NULL
,
8240 VAR_DOMAIN
, LOC_BLOCK
,
8241 SECT_OFF_TEXT (objfile
),
8242 psymbol_placement::STATIC
,
8243 addr
, cu
->language
, objfile
);
8246 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8247 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8249 case DW_TAG_constant
:
8250 add_psymbol_to_list (actual_name
,
8251 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8252 -1, (pdi
->is_external
8253 ? psymbol_placement::GLOBAL
8254 : psymbol_placement::STATIC
),
8255 0, cu
->language
, objfile
);
8257 case DW_TAG_variable
:
8259 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8263 && !dwarf2_per_objfile
->has_section_at_zero
)
8265 /* A global or static variable may also have been stripped
8266 out by the linker if unused, in which case its address
8267 will be nullified; do not add such variables into partial
8268 symbol table then. */
8270 else if (pdi
->is_external
)
8273 Don't enter into the minimal symbol tables as there is
8274 a minimal symbol table entry from the ELF symbols already.
8275 Enter into partial symbol table if it has a location
8276 descriptor or a type.
8277 If the location descriptor is missing, new_symbol will create
8278 a LOC_UNRESOLVED symbol, the address of the variable will then
8279 be determined from the minimal symbol table whenever the variable
8281 The address for the partial symbol table entry is not
8282 used by GDB, but it comes in handy for debugging partial symbol
8285 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8286 add_psymbol_to_list (actual_name
,
8287 built_actual_name
!= NULL
,
8288 VAR_DOMAIN
, LOC_STATIC
,
8289 SECT_OFF_TEXT (objfile
),
8290 psymbol_placement::GLOBAL
,
8291 addr
, cu
->language
, objfile
);
8295 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8297 /* Static Variable. Skip symbols whose value we cannot know (those
8298 without location descriptors or constant values). */
8299 if (!has_loc
&& !pdi
->has_const_value
)
8302 add_psymbol_to_list (actual_name
,
8303 built_actual_name
!= NULL
,
8304 VAR_DOMAIN
, LOC_STATIC
,
8305 SECT_OFF_TEXT (objfile
),
8306 psymbol_placement::STATIC
,
8308 cu
->language
, objfile
);
8311 case DW_TAG_typedef
:
8312 case DW_TAG_base_type
:
8313 case DW_TAG_subrange_type
:
8314 add_psymbol_to_list (actual_name
,
8315 built_actual_name
!= NULL
,
8316 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8317 psymbol_placement::STATIC
,
8318 0, cu
->language
, objfile
);
8320 case DW_TAG_imported_declaration
:
8321 case DW_TAG_namespace
:
8322 add_psymbol_to_list (actual_name
,
8323 built_actual_name
!= NULL
,
8324 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8325 psymbol_placement::GLOBAL
,
8326 0, cu
->language
, objfile
);
8329 /* With Fortran 77 there might be a "BLOCK DATA" module
8330 available without any name. If so, we skip the module as it
8331 doesn't bring any value. */
8332 if (actual_name
!= nullptr)
8333 add_psymbol_to_list (actual_name
,
8334 built_actual_name
!= NULL
,
8335 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8336 psymbol_placement::GLOBAL
,
8337 0, cu
->language
, objfile
);
8339 case DW_TAG_class_type
:
8340 case DW_TAG_interface_type
:
8341 case DW_TAG_structure_type
:
8342 case DW_TAG_union_type
:
8343 case DW_TAG_enumeration_type
:
8344 /* Skip external references. The DWARF standard says in the section
8345 about "Structure, Union, and Class Type Entries": "An incomplete
8346 structure, union or class type is represented by a structure,
8347 union or class entry that does not have a byte size attribute
8348 and that has a DW_AT_declaration attribute." */
8349 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8352 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8353 static vs. global. */
8354 add_psymbol_to_list (actual_name
,
8355 built_actual_name
!= NULL
,
8356 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8357 cu
->language
== language_cplus
8358 ? psymbol_placement::GLOBAL
8359 : psymbol_placement::STATIC
,
8360 0, cu
->language
, objfile
);
8363 case DW_TAG_enumerator
:
8364 add_psymbol_to_list (actual_name
,
8365 built_actual_name
!= NULL
,
8366 VAR_DOMAIN
, LOC_CONST
, -1,
8367 cu
->language
== language_cplus
8368 ? psymbol_placement::GLOBAL
8369 : psymbol_placement::STATIC
,
8370 0, cu
->language
, objfile
);
8377 /* Read a partial die corresponding to a namespace; also, add a symbol
8378 corresponding to that namespace to the symbol table. NAMESPACE is
8379 the name of the enclosing namespace. */
8382 add_partial_namespace (struct partial_die_info
*pdi
,
8383 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8384 int set_addrmap
, struct dwarf2_cu
*cu
)
8386 /* Add a symbol for the namespace. */
8388 add_partial_symbol (pdi
, cu
);
8390 /* Now scan partial symbols in that namespace. */
8392 if (pdi
->has_children
)
8393 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8396 /* Read a partial die corresponding to a Fortran module. */
8399 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8400 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8402 /* Add a symbol for the namespace. */
8404 add_partial_symbol (pdi
, cu
);
8406 /* Now scan partial symbols in that module. */
8408 if (pdi
->has_children
)
8409 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8412 /* Read a partial die corresponding to a subprogram or an inlined
8413 subprogram and create a partial symbol for that subprogram.
8414 When the CU language allows it, this routine also defines a partial
8415 symbol for each nested subprogram that this subprogram contains.
8416 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8417 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8419 PDI may also be a lexical block, in which case we simply search
8420 recursively for subprograms defined inside that lexical block.
8421 Again, this is only performed when the CU language allows this
8422 type of definitions. */
8425 add_partial_subprogram (struct partial_die_info
*pdi
,
8426 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8427 int set_addrmap
, struct dwarf2_cu
*cu
)
8429 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8431 if (pdi
->has_pc_info
)
8433 if (pdi
->lowpc
< *lowpc
)
8434 *lowpc
= pdi
->lowpc
;
8435 if (pdi
->highpc
> *highpc
)
8436 *highpc
= pdi
->highpc
;
8439 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8440 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8442 CORE_ADDR this_highpc
;
8443 CORE_ADDR this_lowpc
;
8445 baseaddr
= objfile
->text_section_offset ();
8447 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8448 pdi
->lowpc
+ baseaddr
)
8451 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8452 pdi
->highpc
+ baseaddr
)
8454 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8455 this_lowpc
, this_highpc
- 1,
8456 cu
->per_cu
->v
.psymtab
);
8460 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8462 if (!pdi
->is_declaration
)
8463 /* Ignore subprogram DIEs that do not have a name, they are
8464 illegal. Do not emit a complaint at this point, we will
8465 do so when we convert this psymtab into a symtab. */
8467 add_partial_symbol (pdi
, cu
);
8471 if (! pdi
->has_children
)
8474 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8476 pdi
= pdi
->die_child
;
8480 if (pdi
->tag
== DW_TAG_subprogram
8481 || pdi
->tag
== DW_TAG_inlined_subroutine
8482 || pdi
->tag
== DW_TAG_lexical_block
)
8483 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8484 pdi
= pdi
->die_sibling
;
8489 /* Read a partial die corresponding to an enumeration type. */
8492 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8493 struct dwarf2_cu
*cu
)
8495 struct partial_die_info
*pdi
;
8497 if (enum_pdi
->name
!= NULL
)
8498 add_partial_symbol (enum_pdi
, cu
);
8500 pdi
= enum_pdi
->die_child
;
8503 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8504 complaint (_("malformed enumerator DIE ignored"));
8506 add_partial_symbol (pdi
, cu
);
8507 pdi
= pdi
->die_sibling
;
8511 /* Return the initial uleb128 in the die at INFO_PTR. */
8514 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8516 unsigned int bytes_read
;
8518 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8521 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8522 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8524 Return the corresponding abbrev, or NULL if the number is zero (indicating
8525 an empty DIE). In either case *BYTES_READ will be set to the length of
8526 the initial number. */
8528 static struct abbrev_info
*
8529 peek_die_abbrev (const die_reader_specs
&reader
,
8530 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8532 dwarf2_cu
*cu
= reader
.cu
;
8533 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8534 unsigned int abbrev_number
8535 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8537 if (abbrev_number
== 0)
8540 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8543 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8544 " at offset %s [in module %s]"),
8545 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8546 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8552 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8553 Returns a pointer to the end of a series of DIEs, terminated by an empty
8554 DIE. Any children of the skipped DIEs will also be skipped. */
8556 static const gdb_byte
*
8557 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8561 unsigned int bytes_read
;
8562 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8565 return info_ptr
+ bytes_read
;
8567 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8571 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8572 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8573 abbrev corresponding to that skipped uleb128 should be passed in
8574 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8577 static const gdb_byte
*
8578 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8579 struct abbrev_info
*abbrev
)
8581 unsigned int bytes_read
;
8582 struct attribute attr
;
8583 bfd
*abfd
= reader
->abfd
;
8584 struct dwarf2_cu
*cu
= reader
->cu
;
8585 const gdb_byte
*buffer
= reader
->buffer
;
8586 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8587 unsigned int form
, i
;
8589 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8591 /* The only abbrev we care about is DW_AT_sibling. */
8592 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8595 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8597 if (attr
.form
== DW_FORM_ref_addr
)
8598 complaint (_("ignoring absolute DW_AT_sibling"));
8601 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8602 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8604 if (sibling_ptr
< info_ptr
)
8605 complaint (_("DW_AT_sibling points backwards"));
8606 else if (sibling_ptr
> reader
->buffer_end
)
8607 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8613 /* If it isn't DW_AT_sibling, skip this attribute. */
8614 form
= abbrev
->attrs
[i
].form
;
8618 case DW_FORM_ref_addr
:
8619 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8620 and later it is offset sized. */
8621 if (cu
->header
.version
== 2)
8622 info_ptr
+= cu
->header
.addr_size
;
8624 info_ptr
+= cu
->header
.offset_size
;
8626 case DW_FORM_GNU_ref_alt
:
8627 info_ptr
+= cu
->header
.offset_size
;
8630 info_ptr
+= cu
->header
.addr_size
;
8638 case DW_FORM_flag_present
:
8639 case DW_FORM_implicit_const
:
8656 case DW_FORM_ref_sig8
:
8659 case DW_FORM_data16
:
8662 case DW_FORM_string
:
8663 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8664 info_ptr
+= bytes_read
;
8666 case DW_FORM_sec_offset
:
8668 case DW_FORM_GNU_strp_alt
:
8669 info_ptr
+= cu
->header
.offset_size
;
8671 case DW_FORM_exprloc
:
8673 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8674 info_ptr
+= bytes_read
;
8676 case DW_FORM_block1
:
8677 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8679 case DW_FORM_block2
:
8680 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8682 case DW_FORM_block4
:
8683 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8689 case DW_FORM_ref_udata
:
8690 case DW_FORM_GNU_addr_index
:
8691 case DW_FORM_GNU_str_index
:
8692 case DW_FORM_rnglistx
:
8693 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8695 case DW_FORM_indirect
:
8696 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8697 info_ptr
+= bytes_read
;
8698 /* We need to continue parsing from here, so just go back to
8700 goto skip_attribute
;
8703 error (_("Dwarf Error: Cannot handle %s "
8704 "in DWARF reader [in module %s]"),
8705 dwarf_form_name (form
),
8706 bfd_get_filename (abfd
));
8710 if (abbrev
->has_children
)
8711 return skip_children (reader
, info_ptr
);
8716 /* Locate ORIG_PDI's sibling.
8717 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8719 static const gdb_byte
*
8720 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8721 struct partial_die_info
*orig_pdi
,
8722 const gdb_byte
*info_ptr
)
8724 /* Do we know the sibling already? */
8726 if (orig_pdi
->sibling
)
8727 return orig_pdi
->sibling
;
8729 /* Are there any children to deal with? */
8731 if (!orig_pdi
->has_children
)
8734 /* Skip the children the long way. */
8736 return skip_children (reader
, info_ptr
);
8739 /* Expand this partial symbol table into a full symbol table. SELF is
8743 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8745 struct dwarf2_per_objfile
*dwarf2_per_objfile
8746 = get_dwarf2_per_objfile (objfile
);
8748 gdb_assert (!readin
);
8749 /* If this psymtab is constructed from a debug-only objfile, the
8750 has_section_at_zero flag will not necessarily be correct. We
8751 can get the correct value for this flag by looking at the data
8752 associated with the (presumably stripped) associated objfile. */
8753 if (objfile
->separate_debug_objfile_backlink
)
8755 struct dwarf2_per_objfile
*dpo_backlink
8756 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8758 dwarf2_per_objfile
->has_section_at_zero
8759 = dpo_backlink
->has_section_at_zero
;
8762 expand_psymtab (objfile
);
8764 process_cu_includes (dwarf2_per_objfile
);
8767 /* Reading in full CUs. */
8769 /* Add PER_CU to the queue. */
8772 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8773 enum language pretend_language
)
8776 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8779 /* If PER_CU is not yet queued, add it to the queue.
8780 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8782 The result is non-zero if PER_CU was queued, otherwise the result is zero
8783 meaning either PER_CU is already queued or it is already loaded.
8785 N.B. There is an invariant here that if a CU is queued then it is loaded.
8786 The caller is required to load PER_CU if we return non-zero. */
8789 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8790 struct dwarf2_per_cu_data
*per_cu
,
8791 enum language pretend_language
)
8793 /* We may arrive here during partial symbol reading, if we need full
8794 DIEs to process an unusual case (e.g. template arguments). Do
8795 not queue PER_CU, just tell our caller to load its DIEs. */
8796 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8798 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8803 /* Mark the dependence relation so that we don't flush PER_CU
8805 if (dependent_cu
!= NULL
)
8806 dwarf2_add_dependence (dependent_cu
, per_cu
);
8808 /* If it's already on the queue, we have nothing to do. */
8812 /* If the compilation unit is already loaded, just mark it as
8814 if (per_cu
->cu
!= NULL
)
8816 per_cu
->cu
->last_used
= 0;
8820 /* Add it to the queue. */
8821 queue_comp_unit (per_cu
, pretend_language
);
8826 /* Process the queue. */
8829 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8831 if (dwarf_read_debug
)
8833 fprintf_unfiltered (gdb_stdlog
,
8834 "Expanding one or more symtabs of objfile %s ...\n",
8835 objfile_name (dwarf2_per_objfile
->objfile
));
8838 /* The queue starts out with one item, but following a DIE reference
8839 may load a new CU, adding it to the end of the queue. */
8840 while (!dwarf2_per_objfile
->queue
.empty ())
8842 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8844 if ((dwarf2_per_objfile
->using_index
8845 ? !item
.per_cu
->v
.quick
->compunit_symtab
8846 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8847 /* Skip dummy CUs. */
8848 && item
.per_cu
->cu
!= NULL
)
8850 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8851 unsigned int debug_print_threshold
;
8854 if (per_cu
->is_debug_types
)
8856 struct signatured_type
*sig_type
=
8857 (struct signatured_type
*) per_cu
;
8859 sprintf (buf
, "TU %s at offset %s",
8860 hex_string (sig_type
->signature
),
8861 sect_offset_str (per_cu
->sect_off
));
8862 /* There can be 100s of TUs.
8863 Only print them in verbose mode. */
8864 debug_print_threshold
= 2;
8868 sprintf (buf
, "CU at offset %s",
8869 sect_offset_str (per_cu
->sect_off
));
8870 debug_print_threshold
= 1;
8873 if (dwarf_read_debug
>= debug_print_threshold
)
8874 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8876 if (per_cu
->is_debug_types
)
8877 process_full_type_unit (per_cu
, item
.pretend_language
);
8879 process_full_comp_unit (per_cu
, item
.pretend_language
);
8881 if (dwarf_read_debug
>= debug_print_threshold
)
8882 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8885 item
.per_cu
->queued
= 0;
8886 dwarf2_per_objfile
->queue
.pop ();
8889 if (dwarf_read_debug
)
8891 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8892 objfile_name (dwarf2_per_objfile
->objfile
));
8896 /* Read in full symbols for PST, and anything it depends on. */
8899 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8904 read_dependencies (objfile
);
8906 dw2_do_instantiate_symtab (per_cu_data
, false);
8907 gdb_assert (get_compunit_symtab () != nullptr);
8910 /* Trivial hash function for die_info: the hash value of a DIE
8911 is its offset in .debug_info for this objfile. */
8914 die_hash (const void *item
)
8916 const struct die_info
*die
= (const struct die_info
*) item
;
8918 return to_underlying (die
->sect_off
);
8921 /* Trivial comparison function for die_info structures: two DIEs
8922 are equal if they have the same offset. */
8925 die_eq (const void *item_lhs
, const void *item_rhs
)
8927 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8928 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8930 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8933 /* Load the DIEs associated with PER_CU into memory. */
8936 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8938 enum language pretend_language
)
8940 gdb_assert (! this_cu
->is_debug_types
);
8942 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8946 struct dwarf2_cu
*cu
= reader
.cu
;
8947 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8949 gdb_assert (cu
->die_hash
== NULL
);
8951 htab_create_alloc_ex (cu
->header
.length
/ 12,
8955 &cu
->comp_unit_obstack
,
8956 hashtab_obstack_allocate
,
8957 dummy_obstack_deallocate
);
8959 if (reader
.comp_unit_die
->has_children
)
8960 reader
.comp_unit_die
->child
8961 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8962 &info_ptr
, reader
.comp_unit_die
);
8963 cu
->dies
= reader
.comp_unit_die
;
8964 /* comp_unit_die is not stored in die_hash, no need. */
8966 /* We try not to read any attributes in this function, because not
8967 all CUs needed for references have been loaded yet, and symbol
8968 table processing isn't initialized. But we have to set the CU language,
8969 or we won't be able to build types correctly.
8970 Similarly, if we do not read the producer, we can not apply
8971 producer-specific interpretation. */
8972 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8977 /* Add a DIE to the delayed physname list. */
8980 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8981 const char *name
, struct die_info
*die
,
8982 struct dwarf2_cu
*cu
)
8984 struct delayed_method_info mi
;
8986 mi
.fnfield_index
= fnfield_index
;
8990 cu
->method_list
.push_back (mi
);
8993 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8994 "const" / "volatile". If so, decrements LEN by the length of the
8995 modifier and return true. Otherwise return false. */
8999 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9001 size_t mod_len
= sizeof (mod
) - 1;
9002 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9010 /* Compute the physnames of any methods on the CU's method list.
9012 The computation of method physnames is delayed in order to avoid the
9013 (bad) condition that one of the method's formal parameters is of an as yet
9017 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9019 /* Only C++ delays computing physnames. */
9020 if (cu
->method_list
.empty ())
9022 gdb_assert (cu
->language
== language_cplus
);
9024 for (const delayed_method_info
&mi
: cu
->method_list
)
9026 const char *physname
;
9027 struct fn_fieldlist
*fn_flp
9028 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9029 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9030 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9031 = physname
? physname
: "";
9033 /* Since there's no tag to indicate whether a method is a
9034 const/volatile overload, extract that information out of the
9036 if (physname
!= NULL
)
9038 size_t len
= strlen (physname
);
9042 if (physname
[len
] == ')') /* shortcut */
9044 else if (check_modifier (physname
, len
, " const"))
9045 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9046 else if (check_modifier (physname
, len
, " volatile"))
9047 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9054 /* The list is no longer needed. */
9055 cu
->method_list
.clear ();
9058 /* Go objects should be embedded in a DW_TAG_module DIE,
9059 and it's not clear if/how imported objects will appear.
9060 To keep Go support simple until that's worked out,
9061 go back through what we've read and create something usable.
9062 We could do this while processing each DIE, and feels kinda cleaner,
9063 but that way is more invasive.
9064 This is to, for example, allow the user to type "p var" or "b main"
9065 without having to specify the package name, and allow lookups
9066 of module.object to work in contexts that use the expression
9070 fixup_go_packaging (struct dwarf2_cu
*cu
)
9072 gdb::unique_xmalloc_ptr
<char> package_name
;
9073 struct pending
*list
;
9076 for (list
= *cu
->get_builder ()->get_global_symbols ();
9080 for (i
= 0; i
< list
->nsyms
; ++i
)
9082 struct symbol
*sym
= list
->symbol
[i
];
9084 if (sym
->language () == language_go
9085 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9087 gdb::unique_xmalloc_ptr
<char> this_package_name
9088 (go_symbol_package_name (sym
));
9090 if (this_package_name
== NULL
)
9092 if (package_name
== NULL
)
9093 package_name
= std::move (this_package_name
);
9096 struct objfile
*objfile
9097 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9098 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9099 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9100 (symbol_symtab (sym
) != NULL
9101 ? symtab_to_filename_for_display
9102 (symbol_symtab (sym
))
9103 : objfile_name (objfile
)),
9104 this_package_name
.get (), package_name
.get ());
9110 if (package_name
!= NULL
)
9112 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9113 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9114 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9115 saved_package_name
);
9118 sym
= allocate_symbol (objfile
);
9119 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9120 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9121 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9122 e.g., "main" finds the "main" module and not C's main(). */
9123 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9124 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9125 SYMBOL_TYPE (sym
) = type
;
9127 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9131 /* Allocate a fully-qualified name consisting of the two parts on the
9135 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9137 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9140 /* A helper that allocates a struct discriminant_info to attach to a
9143 static struct discriminant_info
*
9144 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9147 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9148 gdb_assert (discriminant_index
== -1
9149 || (discriminant_index
>= 0
9150 && discriminant_index
< TYPE_NFIELDS (type
)));
9151 gdb_assert (default_index
== -1
9152 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9154 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9156 struct discriminant_info
*disc
9157 = ((struct discriminant_info
*)
9159 offsetof (struct discriminant_info
, discriminants
)
9160 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9161 disc
->default_index
= default_index
;
9162 disc
->discriminant_index
= discriminant_index
;
9164 struct dynamic_prop prop
;
9165 prop
.kind
= PROP_UNDEFINED
;
9166 prop
.data
.baton
= disc
;
9168 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9173 /* Some versions of rustc emitted enums in an unusual way.
9175 Ordinary enums were emitted as unions. The first element of each
9176 structure in the union was named "RUST$ENUM$DISR". This element
9177 held the discriminant.
9179 These versions of Rust also implemented the "non-zero"
9180 optimization. When the enum had two values, and one is empty and
9181 the other holds a pointer that cannot be zero, the pointer is used
9182 as the discriminant, with a zero value meaning the empty variant.
9183 Here, the union's first member is of the form
9184 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9185 where the fieldnos are the indices of the fields that should be
9186 traversed in order to find the field (which may be several fields deep)
9187 and the variantname is the name of the variant of the case when the
9190 This function recognizes whether TYPE is of one of these forms,
9191 and, if so, smashes it to be a variant type. */
9194 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9196 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9198 /* We don't need to deal with empty enums. */
9199 if (TYPE_NFIELDS (type
) == 0)
9202 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9203 if (TYPE_NFIELDS (type
) == 1
9204 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9206 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9208 /* Decode the field name to find the offset of the
9210 ULONGEST bit_offset
= 0;
9211 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9212 while (name
[0] >= '0' && name
[0] <= '9')
9215 unsigned long index
= strtoul (name
, &tail
, 10);
9218 || index
>= TYPE_NFIELDS (field_type
)
9219 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9220 != FIELD_LOC_KIND_BITPOS
))
9222 complaint (_("Could not parse Rust enum encoding string \"%s\""
9224 TYPE_FIELD_NAME (type
, 0),
9225 objfile_name (objfile
));
9230 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9231 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9234 /* Make a union to hold the variants. */
9235 struct type
*union_type
= alloc_type (objfile
);
9236 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9237 TYPE_NFIELDS (union_type
) = 3;
9238 TYPE_FIELDS (union_type
)
9239 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9240 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9241 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9243 /* Put the discriminant must at index 0. */
9244 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9245 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9246 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9247 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9249 /* The order of fields doesn't really matter, so put the real
9250 field at index 1 and the data-less field at index 2. */
9251 struct discriminant_info
*disc
9252 = alloc_discriminant_info (union_type
, 0, 1);
9253 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9254 TYPE_FIELD_NAME (union_type
, 1)
9255 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9256 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9257 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9258 TYPE_FIELD_NAME (union_type
, 1));
9260 const char *dataless_name
9261 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9263 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9265 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9266 /* NAME points into the original discriminant name, which
9267 already has the correct lifetime. */
9268 TYPE_FIELD_NAME (union_type
, 2) = name
;
9269 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9270 disc
->discriminants
[2] = 0;
9272 /* Smash this type to be a structure type. We have to do this
9273 because the type has already been recorded. */
9274 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9275 TYPE_NFIELDS (type
) = 1;
9277 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9279 /* Install the variant part. */
9280 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9281 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9282 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9284 /* A union with a single anonymous field is probably an old-style
9286 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9288 /* Smash this type to be a structure type. We have to do this
9289 because the type has already been recorded. */
9290 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9292 /* Make a union to hold the variants. */
9293 struct type
*union_type
= alloc_type (objfile
);
9294 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9295 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9296 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9297 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9298 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9300 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9301 const char *variant_name
9302 = rust_last_path_segment (TYPE_NAME (field_type
));
9303 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9304 TYPE_NAME (field_type
)
9305 = rust_fully_qualify (&objfile
->objfile_obstack
,
9306 TYPE_NAME (type
), variant_name
);
9308 /* Install the union in the outer struct type. */
9309 TYPE_NFIELDS (type
) = 1;
9311 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9312 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9313 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9314 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9316 alloc_discriminant_info (union_type
, -1, 0);
9320 struct type
*disr_type
= nullptr;
9321 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9323 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9325 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9327 /* All fields of a true enum will be structs. */
9330 else if (TYPE_NFIELDS (disr_type
) == 0)
9332 /* Could be data-less variant, so keep going. */
9333 disr_type
= nullptr;
9335 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9336 "RUST$ENUM$DISR") != 0)
9338 /* Not a Rust enum. */
9348 /* If we got here without a discriminant, then it's probably
9350 if (disr_type
== nullptr)
9353 /* Smash this type to be a structure type. We have to do this
9354 because the type has already been recorded. */
9355 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9357 /* Make a union to hold the variants. */
9358 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9359 struct type
*union_type
= alloc_type (objfile
);
9360 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9361 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9362 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9363 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9364 TYPE_FIELDS (union_type
)
9365 = (struct field
*) TYPE_ZALLOC (union_type
,
9366 (TYPE_NFIELDS (union_type
)
9367 * sizeof (struct field
)));
9369 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9370 TYPE_NFIELDS (type
) * sizeof (struct field
));
9372 /* Install the discriminant at index 0 in the union. */
9373 TYPE_FIELD (union_type
, 0) = *disr_field
;
9374 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9375 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9377 /* Install the union in the outer struct type. */
9378 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9379 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9380 TYPE_NFIELDS (type
) = 1;
9382 /* Set the size and offset of the union type. */
9383 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9385 /* We need a way to find the correct discriminant given a
9386 variant name. For convenience we build a map here. */
9387 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9388 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9389 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9391 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9394 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9395 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9399 int n_fields
= TYPE_NFIELDS (union_type
);
9400 struct discriminant_info
*disc
9401 = alloc_discriminant_info (union_type
, 0, -1);
9402 /* Skip the discriminant here. */
9403 for (int i
= 1; i
< n_fields
; ++i
)
9405 /* Find the final word in the name of this variant's type.
9406 That name can be used to look up the correct
9408 const char *variant_name
9409 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9412 auto iter
= discriminant_map
.find (variant_name
);
9413 if (iter
!= discriminant_map
.end ())
9414 disc
->discriminants
[i
] = iter
->second
;
9416 /* Remove the discriminant field, if it exists. */
9417 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9418 if (TYPE_NFIELDS (sub_type
) > 0)
9420 --TYPE_NFIELDS (sub_type
);
9421 ++TYPE_FIELDS (sub_type
);
9423 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9424 TYPE_NAME (sub_type
)
9425 = rust_fully_qualify (&objfile
->objfile_obstack
,
9426 TYPE_NAME (type
), variant_name
);
9431 /* Rewrite some Rust unions to be structures with variants parts. */
9434 rust_union_quirks (struct dwarf2_cu
*cu
)
9436 gdb_assert (cu
->language
== language_rust
);
9437 for (type
*type_
: cu
->rust_unions
)
9438 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9439 /* We don't need this any more. */
9440 cu
->rust_unions
.clear ();
9443 /* Return the symtab for PER_CU. This works properly regardless of
9444 whether we're using the index or psymtabs. */
9446 static struct compunit_symtab
*
9447 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9449 return (per_cu
->dwarf2_per_objfile
->using_index
9450 ? per_cu
->v
.quick
->compunit_symtab
9451 : per_cu
->v
.psymtab
->compunit_symtab
);
9454 /* A helper function for computing the list of all symbol tables
9455 included by PER_CU. */
9458 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9459 htab_t all_children
, htab_t all_type_symtabs
,
9460 struct dwarf2_per_cu_data
*per_cu
,
9461 struct compunit_symtab
*immediate_parent
)
9464 struct compunit_symtab
*cust
;
9466 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9469 /* This inclusion and its children have been processed. */
9474 /* Only add a CU if it has a symbol table. */
9475 cust
= get_compunit_symtab (per_cu
);
9478 /* If this is a type unit only add its symbol table if we haven't
9479 seen it yet (type unit per_cu's can share symtabs). */
9480 if (per_cu
->is_debug_types
)
9482 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9486 result
->push_back (cust
);
9487 if (cust
->user
== NULL
)
9488 cust
->user
= immediate_parent
;
9493 result
->push_back (cust
);
9494 if (cust
->user
== NULL
)
9495 cust
->user
= immediate_parent
;
9499 if (!per_cu
->imported_symtabs_empty ())
9500 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9502 recursively_compute_inclusions (result
, all_children
,
9503 all_type_symtabs
, ptr
, cust
);
9507 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9511 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9513 gdb_assert (! per_cu
->is_debug_types
);
9515 if (!per_cu
->imported_symtabs_empty ())
9518 std::vector
<compunit_symtab
*> result_symtabs
;
9519 htab_t all_children
, all_type_symtabs
;
9520 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9522 /* If we don't have a symtab, we can just skip this case. */
9526 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9527 NULL
, xcalloc
, xfree
);
9528 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9529 NULL
, xcalloc
, xfree
);
9531 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9533 recursively_compute_inclusions (&result_symtabs
, all_children
,
9534 all_type_symtabs
, ptr
, cust
);
9537 /* Now we have a transitive closure of all the included symtabs. */
9538 len
= result_symtabs
.size ();
9540 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9541 struct compunit_symtab
*, len
+ 1);
9542 memcpy (cust
->includes
, result_symtabs
.data (),
9543 len
* sizeof (compunit_symtab
*));
9544 cust
->includes
[len
] = NULL
;
9546 htab_delete (all_children
);
9547 htab_delete (all_type_symtabs
);
9551 /* Compute the 'includes' field for the symtabs of all the CUs we just
9555 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9557 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9559 if (! iter
->is_debug_types
)
9560 compute_compunit_symtab_includes (iter
);
9563 dwarf2_per_objfile
->just_read_cus
.clear ();
9566 /* Generate full symbol information for PER_CU, whose DIEs have
9567 already been loaded into memory. */
9570 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9571 enum language pretend_language
)
9573 struct dwarf2_cu
*cu
= per_cu
->cu
;
9574 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9575 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9576 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9577 CORE_ADDR lowpc
, highpc
;
9578 struct compunit_symtab
*cust
;
9580 struct block
*static_block
;
9583 baseaddr
= objfile
->text_section_offset ();
9585 /* Clear the list here in case something was left over. */
9586 cu
->method_list
.clear ();
9588 cu
->language
= pretend_language
;
9589 cu
->language_defn
= language_def (cu
->language
);
9591 /* Do line number decoding in read_file_scope () */
9592 process_die (cu
->dies
, cu
);
9594 /* For now fudge the Go package. */
9595 if (cu
->language
== language_go
)
9596 fixup_go_packaging (cu
);
9598 /* Now that we have processed all the DIEs in the CU, all the types
9599 should be complete, and it should now be safe to compute all of the
9601 compute_delayed_physnames (cu
);
9603 if (cu
->language
== language_rust
)
9604 rust_union_quirks (cu
);
9606 /* Some compilers don't define a DW_AT_high_pc attribute for the
9607 compilation unit. If the DW_AT_high_pc is missing, synthesize
9608 it, by scanning the DIE's below the compilation unit. */
9609 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9611 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9612 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9614 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9615 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9616 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9617 addrmap to help ensure it has an accurate map of pc values belonging to
9619 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9621 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9622 SECT_OFF_TEXT (objfile
),
9627 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9629 /* Set symtab language to language from DW_AT_language. If the
9630 compilation is from a C file generated by language preprocessors, do
9631 not set the language if it was already deduced by start_subfile. */
9632 if (!(cu
->language
== language_c
9633 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9634 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9636 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9637 produce DW_AT_location with location lists but it can be possibly
9638 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9639 there were bugs in prologue debug info, fixed later in GCC-4.5
9640 by "unwind info for epilogues" patch (which is not directly related).
9642 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9643 needed, it would be wrong due to missing DW_AT_producer there.
9645 Still one can confuse GDB by using non-standard GCC compilation
9646 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9648 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9649 cust
->locations_valid
= 1;
9651 if (gcc_4_minor
>= 5)
9652 cust
->epilogue_unwind_valid
= 1;
9654 cust
->call_site_htab
= cu
->call_site_htab
;
9657 if (dwarf2_per_objfile
->using_index
)
9658 per_cu
->v
.quick
->compunit_symtab
= cust
;
9661 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9662 pst
->compunit_symtab
= cust
;
9666 /* Push it for inclusion processing later. */
9667 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9669 /* Not needed any more. */
9670 cu
->reset_builder ();
9673 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9674 already been loaded into memory. */
9677 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9678 enum language pretend_language
)
9680 struct dwarf2_cu
*cu
= per_cu
->cu
;
9681 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9682 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9683 struct compunit_symtab
*cust
;
9684 struct signatured_type
*sig_type
;
9686 gdb_assert (per_cu
->is_debug_types
);
9687 sig_type
= (struct signatured_type
*) per_cu
;
9689 /* Clear the list here in case something was left over. */
9690 cu
->method_list
.clear ();
9692 cu
->language
= pretend_language
;
9693 cu
->language_defn
= language_def (cu
->language
);
9695 /* The symbol tables are set up in read_type_unit_scope. */
9696 process_die (cu
->dies
, cu
);
9698 /* For now fudge the Go package. */
9699 if (cu
->language
== language_go
)
9700 fixup_go_packaging (cu
);
9702 /* Now that we have processed all the DIEs in the CU, all the types
9703 should be complete, and it should now be safe to compute all of the
9705 compute_delayed_physnames (cu
);
9707 if (cu
->language
== language_rust
)
9708 rust_union_quirks (cu
);
9710 /* TUs share symbol tables.
9711 If this is the first TU to use this symtab, complete the construction
9712 of it with end_expandable_symtab. Otherwise, complete the addition of
9713 this TU's symbols to the existing symtab. */
9714 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9716 buildsym_compunit
*builder
= cu
->get_builder ();
9717 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9718 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9722 /* Set symtab language to language from DW_AT_language. If the
9723 compilation is from a C file generated by language preprocessors,
9724 do not set the language if it was already deduced by
9726 if (!(cu
->language
== language_c
9727 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9728 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9733 cu
->get_builder ()->augment_type_symtab ();
9734 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9737 if (dwarf2_per_objfile
->using_index
)
9738 per_cu
->v
.quick
->compunit_symtab
= cust
;
9741 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9742 pst
->compunit_symtab
= cust
;
9746 /* Not needed any more. */
9747 cu
->reset_builder ();
9750 /* Process an imported unit DIE. */
9753 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9755 struct attribute
*attr
;
9757 /* For now we don't handle imported units in type units. */
9758 if (cu
->per_cu
->is_debug_types
)
9760 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9761 " supported in type units [in module %s]"),
9762 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9765 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9768 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9769 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9770 dwarf2_per_cu_data
*per_cu
9771 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9772 cu
->per_cu
->dwarf2_per_objfile
);
9774 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9775 into another compilation unit, at root level. Regard this as a hint,
9777 if (die
->parent
&& die
->parent
->parent
== NULL
9778 && per_cu
->unit_type
== DW_UT_compile
9779 && per_cu
->lang
== language_cplus
)
9782 /* If necessary, add it to the queue and load its DIEs. */
9783 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9784 load_full_comp_unit (per_cu
, false, cu
->language
);
9786 cu
->per_cu
->imported_symtabs_push (per_cu
);
9790 /* RAII object that represents a process_die scope: i.e.,
9791 starts/finishes processing a DIE. */
9792 class process_die_scope
9795 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9796 : m_die (die
), m_cu (cu
)
9798 /* We should only be processing DIEs not already in process. */
9799 gdb_assert (!m_die
->in_process
);
9800 m_die
->in_process
= true;
9803 ~process_die_scope ()
9805 m_die
->in_process
= false;
9807 /* If we're done processing the DIE for the CU that owns the line
9808 header, we don't need the line header anymore. */
9809 if (m_cu
->line_header_die_owner
== m_die
)
9811 delete m_cu
->line_header
;
9812 m_cu
->line_header
= NULL
;
9813 m_cu
->line_header_die_owner
= NULL
;
9822 /* Process a die and its children. */
9825 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9827 process_die_scope
scope (die
, cu
);
9831 case DW_TAG_padding
:
9833 case DW_TAG_compile_unit
:
9834 case DW_TAG_partial_unit
:
9835 read_file_scope (die
, cu
);
9837 case DW_TAG_type_unit
:
9838 read_type_unit_scope (die
, cu
);
9840 case DW_TAG_subprogram
:
9841 /* Nested subprograms in Fortran get a prefix. */
9842 if (cu
->language
== language_fortran
9843 && die
->parent
!= NULL
9844 && die
->parent
->tag
== DW_TAG_subprogram
)
9845 cu
->processing_has_namespace_info
= true;
9847 case DW_TAG_inlined_subroutine
:
9848 read_func_scope (die
, cu
);
9850 case DW_TAG_lexical_block
:
9851 case DW_TAG_try_block
:
9852 case DW_TAG_catch_block
:
9853 read_lexical_block_scope (die
, cu
);
9855 case DW_TAG_call_site
:
9856 case DW_TAG_GNU_call_site
:
9857 read_call_site_scope (die
, cu
);
9859 case DW_TAG_class_type
:
9860 case DW_TAG_interface_type
:
9861 case DW_TAG_structure_type
:
9862 case DW_TAG_union_type
:
9863 process_structure_scope (die
, cu
);
9865 case DW_TAG_enumeration_type
:
9866 process_enumeration_scope (die
, cu
);
9869 /* These dies have a type, but processing them does not create
9870 a symbol or recurse to process the children. Therefore we can
9871 read them on-demand through read_type_die. */
9872 case DW_TAG_subroutine_type
:
9873 case DW_TAG_set_type
:
9874 case DW_TAG_array_type
:
9875 case DW_TAG_pointer_type
:
9876 case DW_TAG_ptr_to_member_type
:
9877 case DW_TAG_reference_type
:
9878 case DW_TAG_rvalue_reference_type
:
9879 case DW_TAG_string_type
:
9882 case DW_TAG_base_type
:
9883 case DW_TAG_subrange_type
:
9884 case DW_TAG_typedef
:
9885 /* Add a typedef symbol for the type definition, if it has a
9887 new_symbol (die
, read_type_die (die
, cu
), cu
);
9889 case DW_TAG_common_block
:
9890 read_common_block (die
, cu
);
9892 case DW_TAG_common_inclusion
:
9894 case DW_TAG_namespace
:
9895 cu
->processing_has_namespace_info
= true;
9896 read_namespace (die
, cu
);
9899 cu
->processing_has_namespace_info
= true;
9900 read_module (die
, cu
);
9902 case DW_TAG_imported_declaration
:
9903 cu
->processing_has_namespace_info
= true;
9904 if (read_namespace_alias (die
, cu
))
9906 /* The declaration is not a global namespace alias. */
9908 case DW_TAG_imported_module
:
9909 cu
->processing_has_namespace_info
= true;
9910 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9911 || cu
->language
!= language_fortran
))
9912 complaint (_("Tag '%s' has unexpected children"),
9913 dwarf_tag_name (die
->tag
));
9914 read_import_statement (die
, cu
);
9917 case DW_TAG_imported_unit
:
9918 process_imported_unit_die (die
, cu
);
9921 case DW_TAG_variable
:
9922 read_variable (die
, cu
);
9926 new_symbol (die
, NULL
, cu
);
9931 /* DWARF name computation. */
9933 /* A helper function for dwarf2_compute_name which determines whether DIE
9934 needs to have the name of the scope prepended to the name listed in the
9938 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9940 struct attribute
*attr
;
9944 case DW_TAG_namespace
:
9945 case DW_TAG_typedef
:
9946 case DW_TAG_class_type
:
9947 case DW_TAG_interface_type
:
9948 case DW_TAG_structure_type
:
9949 case DW_TAG_union_type
:
9950 case DW_TAG_enumeration_type
:
9951 case DW_TAG_enumerator
:
9952 case DW_TAG_subprogram
:
9953 case DW_TAG_inlined_subroutine
:
9955 case DW_TAG_imported_declaration
:
9958 case DW_TAG_variable
:
9959 case DW_TAG_constant
:
9960 /* We only need to prefix "globally" visible variables. These include
9961 any variable marked with DW_AT_external or any variable that
9962 lives in a namespace. [Variables in anonymous namespaces
9963 require prefixing, but they are not DW_AT_external.] */
9965 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9967 struct dwarf2_cu
*spec_cu
= cu
;
9969 return die_needs_namespace (die_specification (die
, &spec_cu
),
9973 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9974 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9975 && die
->parent
->tag
!= DW_TAG_module
)
9977 /* A variable in a lexical block of some kind does not need a
9978 namespace, even though in C++ such variables may be external
9979 and have a mangled name. */
9980 if (die
->parent
->tag
== DW_TAG_lexical_block
9981 || die
->parent
->tag
== DW_TAG_try_block
9982 || die
->parent
->tag
== DW_TAG_catch_block
9983 || die
->parent
->tag
== DW_TAG_subprogram
)
9992 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9993 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9994 defined for the given DIE. */
9996 static struct attribute
*
9997 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9999 struct attribute
*attr
;
10001 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10003 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10008 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10009 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10010 defined for the given DIE. */
10012 static const char *
10013 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10015 const char *linkage_name
;
10017 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10018 if (linkage_name
== NULL
)
10019 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10021 return linkage_name
;
10024 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10025 compute the physname for the object, which include a method's:
10026 - formal parameters (C++),
10027 - receiver type (Go),
10029 The term "physname" is a bit confusing.
10030 For C++, for example, it is the demangled name.
10031 For Go, for example, it's the mangled name.
10033 For Ada, return the DIE's linkage name rather than the fully qualified
10034 name. PHYSNAME is ignored..
10036 The result is allocated on the objfile_obstack and canonicalized. */
10038 static const char *
10039 dwarf2_compute_name (const char *name
,
10040 struct die_info
*die
, struct dwarf2_cu
*cu
,
10043 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10046 name
= dwarf2_name (die
, cu
);
10048 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10049 but otherwise compute it by typename_concat inside GDB.
10050 FIXME: Actually this is not really true, or at least not always true.
10051 It's all very confusing. compute_and_set_names doesn't try to demangle
10052 Fortran names because there is no mangling standard. So new_symbol
10053 will set the demangled name to the result of dwarf2_full_name, and it is
10054 the demangled name that GDB uses if it exists. */
10055 if (cu
->language
== language_ada
10056 || (cu
->language
== language_fortran
&& physname
))
10058 /* For Ada unit, we prefer the linkage name over the name, as
10059 the former contains the exported name, which the user expects
10060 to be able to reference. Ideally, we want the user to be able
10061 to reference this entity using either natural or linkage name,
10062 but we haven't started looking at this enhancement yet. */
10063 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10065 if (linkage_name
!= NULL
)
10066 return linkage_name
;
10069 /* These are the only languages we know how to qualify names in. */
10071 && (cu
->language
== language_cplus
10072 || cu
->language
== language_fortran
|| cu
->language
== language_d
10073 || cu
->language
== language_rust
))
10075 if (die_needs_namespace (die
, cu
))
10077 const char *prefix
;
10078 const char *canonical_name
= NULL
;
10082 prefix
= determine_prefix (die
, cu
);
10083 if (*prefix
!= '\0')
10085 gdb::unique_xmalloc_ptr
<char> prefixed_name
10086 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10088 buf
.puts (prefixed_name
.get ());
10093 /* Template parameters may be specified in the DIE's DW_AT_name, or
10094 as children with DW_TAG_template_type_param or
10095 DW_TAG_value_type_param. If the latter, add them to the name
10096 here. If the name already has template parameters, then
10097 skip this step; some versions of GCC emit both, and
10098 it is more efficient to use the pre-computed name.
10100 Something to keep in mind about this process: it is very
10101 unlikely, or in some cases downright impossible, to produce
10102 something that will match the mangled name of a function.
10103 If the definition of the function has the same debug info,
10104 we should be able to match up with it anyway. But fallbacks
10105 using the minimal symbol, for instance to find a method
10106 implemented in a stripped copy of libstdc++, will not work.
10107 If we do not have debug info for the definition, we will have to
10108 match them up some other way.
10110 When we do name matching there is a related problem with function
10111 templates; two instantiated function templates are allowed to
10112 differ only by their return types, which we do not add here. */
10114 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10116 struct attribute
*attr
;
10117 struct die_info
*child
;
10120 die
->building_fullname
= 1;
10122 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10126 const gdb_byte
*bytes
;
10127 struct dwarf2_locexpr_baton
*baton
;
10130 if (child
->tag
!= DW_TAG_template_type_param
10131 && child
->tag
!= DW_TAG_template_value_param
)
10142 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10145 complaint (_("template parameter missing DW_AT_type"));
10146 buf
.puts ("UNKNOWN_TYPE");
10149 type
= die_type (child
, cu
);
10151 if (child
->tag
== DW_TAG_template_type_param
)
10153 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10154 &type_print_raw_options
);
10158 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10161 complaint (_("template parameter missing "
10162 "DW_AT_const_value"));
10163 buf
.puts ("UNKNOWN_VALUE");
10167 dwarf2_const_value_attr (attr
, type
, name
,
10168 &cu
->comp_unit_obstack
, cu
,
10169 &value
, &bytes
, &baton
);
10171 if (TYPE_NOSIGN (type
))
10172 /* GDB prints characters as NUMBER 'CHAR'. If that's
10173 changed, this can use value_print instead. */
10174 c_printchar (value
, type
, &buf
);
10177 struct value_print_options opts
;
10180 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10184 else if (bytes
!= NULL
)
10186 v
= allocate_value (type
);
10187 memcpy (value_contents_writeable (v
), bytes
,
10188 TYPE_LENGTH (type
));
10191 v
= value_from_longest (type
, value
);
10193 /* Specify decimal so that we do not depend on
10195 get_formatted_print_options (&opts
, 'd');
10197 value_print (v
, &buf
, &opts
);
10202 die
->building_fullname
= 0;
10206 /* Close the argument list, with a space if necessary
10207 (nested templates). */
10208 if (!buf
.empty () && buf
.string ().back () == '>')
10215 /* For C++ methods, append formal parameter type
10216 information, if PHYSNAME. */
10218 if (physname
&& die
->tag
== DW_TAG_subprogram
10219 && cu
->language
== language_cplus
)
10221 struct type
*type
= read_type_die (die
, cu
);
10223 c_type_print_args (type
, &buf
, 1, cu
->language
,
10224 &type_print_raw_options
);
10226 if (cu
->language
== language_cplus
)
10228 /* Assume that an artificial first parameter is
10229 "this", but do not crash if it is not. RealView
10230 marks unnamed (and thus unused) parameters as
10231 artificial; there is no way to differentiate
10233 if (TYPE_NFIELDS (type
) > 0
10234 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10235 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10236 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10238 buf
.puts (" const");
10242 const std::string
&intermediate_name
= buf
.string ();
10244 if (cu
->language
== language_cplus
)
10246 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10249 /* If we only computed INTERMEDIATE_NAME, or if
10250 INTERMEDIATE_NAME is already canonical, then we need to
10252 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10253 name
= objfile
->intern (intermediate_name
);
10255 name
= canonical_name
;
10262 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10263 If scope qualifiers are appropriate they will be added. The result
10264 will be allocated on the storage_obstack, or NULL if the DIE does
10265 not have a name. NAME may either be from a previous call to
10266 dwarf2_name or NULL.
10268 The output string will be canonicalized (if C++). */
10270 static const char *
10271 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10273 return dwarf2_compute_name (name
, die
, cu
, 0);
10276 /* Construct a physname for the given DIE in CU. NAME may either be
10277 from a previous call to dwarf2_name or NULL. The result will be
10278 allocated on the objfile_objstack or NULL if the DIE does not have a
10281 The output string will be canonicalized (if C++). */
10283 static const char *
10284 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10286 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10287 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10290 /* In this case dwarf2_compute_name is just a shortcut not building anything
10292 if (!die_needs_namespace (die
, cu
))
10293 return dwarf2_compute_name (name
, die
, cu
, 1);
10295 mangled
= dw2_linkage_name (die
, cu
);
10297 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10298 See https://github.com/rust-lang/rust/issues/32925. */
10299 if (cu
->language
== language_rust
&& mangled
!= NULL
10300 && strchr (mangled
, '{') != NULL
)
10303 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10305 gdb::unique_xmalloc_ptr
<char> demangled
;
10306 if (mangled
!= NULL
)
10309 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10311 /* Do nothing (do not demangle the symbol name). */
10313 else if (cu
->language
== language_go
)
10315 /* This is a lie, but we already lie to the caller new_symbol.
10316 new_symbol assumes we return the mangled name.
10317 This just undoes that lie until things are cleaned up. */
10321 /* Use DMGL_RET_DROP for C++ template functions to suppress
10322 their return type. It is easier for GDB users to search
10323 for such functions as `name(params)' than `long name(params)'.
10324 In such case the minimal symbol names do not match the full
10325 symbol names but for template functions there is never a need
10326 to look up their definition from their declaration so
10327 the only disadvantage remains the minimal symbol variant
10328 `long name(params)' does not have the proper inferior type. */
10329 demangled
.reset (gdb_demangle (mangled
,
10330 (DMGL_PARAMS
| DMGL_ANSI
10331 | DMGL_RET_DROP
)));
10334 canon
= demangled
.get ();
10342 if (canon
== NULL
|| check_physname
)
10344 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10346 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10348 /* It may not mean a bug in GDB. The compiler could also
10349 compute DW_AT_linkage_name incorrectly. But in such case
10350 GDB would need to be bug-to-bug compatible. */
10352 complaint (_("Computed physname <%s> does not match demangled <%s> "
10353 "(from linkage <%s>) - DIE at %s [in module %s]"),
10354 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10355 objfile_name (objfile
));
10357 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10358 is available here - over computed PHYSNAME. It is safer
10359 against both buggy GDB and buggy compilers. */
10373 retval
= objfile
->intern (retval
);
10378 /* Inspect DIE in CU for a namespace alias. If one exists, record
10379 a new symbol for it.
10381 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10384 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10386 struct attribute
*attr
;
10388 /* If the die does not have a name, this is not a namespace
10390 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10394 struct die_info
*d
= die
;
10395 struct dwarf2_cu
*imported_cu
= cu
;
10397 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10398 keep inspecting DIEs until we hit the underlying import. */
10399 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10400 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10402 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10406 d
= follow_die_ref (d
, attr
, &imported_cu
);
10407 if (d
->tag
!= DW_TAG_imported_declaration
)
10411 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10413 complaint (_("DIE at %s has too many recursively imported "
10414 "declarations"), sect_offset_str (d
->sect_off
));
10421 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10423 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10424 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10426 /* This declaration is a global namespace alias. Add
10427 a symbol for it whose type is the aliased namespace. */
10428 new_symbol (die
, type
, cu
);
10437 /* Return the using directives repository (global or local?) to use in the
10438 current context for CU.
10440 For Ada, imported declarations can materialize renamings, which *may* be
10441 global. However it is impossible (for now?) in DWARF to distinguish
10442 "external" imported declarations and "static" ones. As all imported
10443 declarations seem to be static in all other languages, make them all CU-wide
10444 global only in Ada. */
10446 static struct using_direct
**
10447 using_directives (struct dwarf2_cu
*cu
)
10449 if (cu
->language
== language_ada
10450 && cu
->get_builder ()->outermost_context_p ())
10451 return cu
->get_builder ()->get_global_using_directives ();
10453 return cu
->get_builder ()->get_local_using_directives ();
10456 /* Read the import statement specified by the given die and record it. */
10459 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10461 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10462 struct attribute
*import_attr
;
10463 struct die_info
*imported_die
, *child_die
;
10464 struct dwarf2_cu
*imported_cu
;
10465 const char *imported_name
;
10466 const char *imported_name_prefix
;
10467 const char *canonical_name
;
10468 const char *import_alias
;
10469 const char *imported_declaration
= NULL
;
10470 const char *import_prefix
;
10471 std::vector
<const char *> excludes
;
10473 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10474 if (import_attr
== NULL
)
10476 complaint (_("Tag '%s' has no DW_AT_import"),
10477 dwarf_tag_name (die
->tag
));
10482 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10483 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10484 if (imported_name
== NULL
)
10486 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10488 The import in the following code:
10502 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10503 <52> DW_AT_decl_file : 1
10504 <53> DW_AT_decl_line : 6
10505 <54> DW_AT_import : <0x75>
10506 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10507 <59> DW_AT_name : B
10508 <5b> DW_AT_decl_file : 1
10509 <5c> DW_AT_decl_line : 2
10510 <5d> DW_AT_type : <0x6e>
10512 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10513 <76> DW_AT_byte_size : 4
10514 <77> DW_AT_encoding : 5 (signed)
10516 imports the wrong die ( 0x75 instead of 0x58 ).
10517 This case will be ignored until the gcc bug is fixed. */
10521 /* Figure out the local name after import. */
10522 import_alias
= dwarf2_name (die
, cu
);
10524 /* Figure out where the statement is being imported to. */
10525 import_prefix
= determine_prefix (die
, cu
);
10527 /* Figure out what the scope of the imported die is and prepend it
10528 to the name of the imported die. */
10529 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10531 if (imported_die
->tag
!= DW_TAG_namespace
10532 && imported_die
->tag
!= DW_TAG_module
)
10534 imported_declaration
= imported_name
;
10535 canonical_name
= imported_name_prefix
;
10537 else if (strlen (imported_name_prefix
) > 0)
10538 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10539 imported_name_prefix
,
10540 (cu
->language
== language_d
? "." : "::"),
10541 imported_name
, (char *) NULL
);
10543 canonical_name
= imported_name
;
10545 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10546 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10547 child_die
= sibling_die (child_die
))
10549 /* DWARF-4: A Fortran use statement with a “rename list” may be
10550 represented by an imported module entry with an import attribute
10551 referring to the module and owned entries corresponding to those
10552 entities that are renamed as part of being imported. */
10554 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10556 complaint (_("child DW_TAG_imported_declaration expected "
10557 "- DIE at %s [in module %s]"),
10558 sect_offset_str (child_die
->sect_off
),
10559 objfile_name (objfile
));
10563 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10564 if (import_attr
== NULL
)
10566 complaint (_("Tag '%s' has no DW_AT_import"),
10567 dwarf_tag_name (child_die
->tag
));
10572 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10574 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10575 if (imported_name
== NULL
)
10577 complaint (_("child DW_TAG_imported_declaration has unknown "
10578 "imported name - DIE at %s [in module %s]"),
10579 sect_offset_str (child_die
->sect_off
),
10580 objfile_name (objfile
));
10584 excludes
.push_back (imported_name
);
10586 process_die (child_die
, cu
);
10589 add_using_directive (using_directives (cu
),
10593 imported_declaration
,
10596 &objfile
->objfile_obstack
);
10599 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10600 types, but gives them a size of zero. Starting with version 14,
10601 ICC is compatible with GCC. */
10604 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10606 if (!cu
->checked_producer
)
10607 check_producer (cu
);
10609 return cu
->producer_is_icc_lt_14
;
10612 /* ICC generates a DW_AT_type for C void functions. This was observed on
10613 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10614 which says that void functions should not have a DW_AT_type. */
10617 producer_is_icc (struct dwarf2_cu
*cu
)
10619 if (!cu
->checked_producer
)
10620 check_producer (cu
);
10622 return cu
->producer_is_icc
;
10625 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10626 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10627 this, it was first present in GCC release 4.3.0. */
10630 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10632 if (!cu
->checked_producer
)
10633 check_producer (cu
);
10635 return cu
->producer_is_gcc_lt_4_3
;
10638 static file_and_directory
10639 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10641 file_and_directory res
;
10643 /* Find the filename. Do not use dwarf2_name here, since the filename
10644 is not a source language identifier. */
10645 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10646 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10648 if (res
.comp_dir
== NULL
10649 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10650 && IS_ABSOLUTE_PATH (res
.name
))
10652 res
.comp_dir_storage
= ldirname (res
.name
);
10653 if (!res
.comp_dir_storage
.empty ())
10654 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10656 if (res
.comp_dir
!= NULL
)
10658 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10659 directory, get rid of it. */
10660 const char *cp
= strchr (res
.comp_dir
, ':');
10662 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10663 res
.comp_dir
= cp
+ 1;
10666 if (res
.name
== NULL
)
10667 res
.name
= "<unknown>";
10672 /* Handle DW_AT_stmt_list for a compilation unit.
10673 DIE is the DW_TAG_compile_unit die for CU.
10674 COMP_DIR is the compilation directory. LOWPC is passed to
10675 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10678 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10679 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10681 struct dwarf2_per_objfile
*dwarf2_per_objfile
10682 = cu
->per_cu
->dwarf2_per_objfile
;
10683 struct attribute
*attr
;
10684 struct line_header line_header_local
;
10685 hashval_t line_header_local_hash
;
10687 int decode_mapping
;
10689 gdb_assert (! cu
->per_cu
->is_debug_types
);
10691 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10695 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10697 /* The line header hash table is only created if needed (it exists to
10698 prevent redundant reading of the line table for partial_units).
10699 If we're given a partial_unit, we'll need it. If we're given a
10700 compile_unit, then use the line header hash table if it's already
10701 created, but don't create one just yet. */
10703 if (dwarf2_per_objfile
->line_header_hash
== NULL
10704 && die
->tag
== DW_TAG_partial_unit
)
10706 dwarf2_per_objfile
->line_header_hash
10707 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10708 line_header_eq_voidp
,
10709 free_line_header_voidp
,
10713 line_header_local
.sect_off
= line_offset
;
10714 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10715 line_header_local_hash
= line_header_hash (&line_header_local
);
10716 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10718 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10719 &line_header_local
,
10720 line_header_local_hash
, NO_INSERT
);
10722 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10723 is not present in *SLOT (since if there is something in *SLOT then
10724 it will be for a partial_unit). */
10725 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10727 gdb_assert (*slot
!= NULL
);
10728 cu
->line_header
= (struct line_header
*) *slot
;
10733 /* dwarf_decode_line_header does not yet provide sufficient information.
10734 We always have to call also dwarf_decode_lines for it. */
10735 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10739 cu
->line_header
= lh
.release ();
10740 cu
->line_header_die_owner
= die
;
10742 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10746 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10747 &line_header_local
,
10748 line_header_local_hash
, INSERT
);
10749 gdb_assert (slot
!= NULL
);
10751 if (slot
!= NULL
&& *slot
== NULL
)
10753 /* This newly decoded line number information unit will be owned
10754 by line_header_hash hash table. */
10755 *slot
= cu
->line_header
;
10756 cu
->line_header_die_owner
= NULL
;
10760 /* We cannot free any current entry in (*slot) as that struct line_header
10761 may be already used by multiple CUs. Create only temporary decoded
10762 line_header for this CU - it may happen at most once for each line
10763 number information unit. And if we're not using line_header_hash
10764 then this is what we want as well. */
10765 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10767 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10768 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10773 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10776 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10778 struct dwarf2_per_objfile
*dwarf2_per_objfile
10779 = cu
->per_cu
->dwarf2_per_objfile
;
10780 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10781 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10782 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10783 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10784 struct attribute
*attr
;
10785 struct die_info
*child_die
;
10786 CORE_ADDR baseaddr
;
10788 prepare_one_comp_unit (cu
, die
, cu
->language
);
10789 baseaddr
= objfile
->text_section_offset ();
10791 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10793 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10794 from finish_block. */
10795 if (lowpc
== ((CORE_ADDR
) -1))
10797 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10799 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10801 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10802 standardised yet. As a workaround for the language detection we fall
10803 back to the DW_AT_producer string. */
10804 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10805 cu
->language
= language_opencl
;
10807 /* Similar hack for Go. */
10808 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10809 set_cu_language (DW_LANG_Go
, cu
);
10811 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10813 /* Decode line number information if present. We do this before
10814 processing child DIEs, so that the line header table is available
10815 for DW_AT_decl_file. */
10816 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10818 /* Process all dies in compilation unit. */
10819 if (die
->child
!= NULL
)
10821 child_die
= die
->child
;
10822 while (child_die
&& child_die
->tag
)
10824 process_die (child_die
, cu
);
10825 child_die
= sibling_die (child_die
);
10829 /* Decode macro information, if present. Dwarf 2 macro information
10830 refers to information in the line number info statement program
10831 header, so we can only read it if we've read the header
10833 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10835 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10836 if (attr
&& cu
->line_header
)
10838 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10839 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10841 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10845 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10846 if (attr
&& cu
->line_header
)
10848 unsigned int macro_offset
= DW_UNSND (attr
);
10850 dwarf_decode_macros (cu
, macro_offset
, 0);
10856 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10858 struct type_unit_group
*tu_group
;
10860 struct attribute
*attr
;
10862 struct signatured_type
*sig_type
;
10864 gdb_assert (per_cu
->is_debug_types
);
10865 sig_type
= (struct signatured_type
*) per_cu
;
10867 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10869 /* If we're using .gdb_index (includes -readnow) then
10870 per_cu->type_unit_group may not have been set up yet. */
10871 if (sig_type
->type_unit_group
== NULL
)
10872 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10873 tu_group
= sig_type
->type_unit_group
;
10875 /* If we've already processed this stmt_list there's no real need to
10876 do it again, we could fake it and just recreate the part we need
10877 (file name,index -> symtab mapping). If data shows this optimization
10878 is useful we can do it then. */
10879 first_time
= tu_group
->compunit_symtab
== NULL
;
10881 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10886 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10887 lh
= dwarf_decode_line_header (line_offset
, this);
10892 start_symtab ("", NULL
, 0);
10895 gdb_assert (tu_group
->symtabs
== NULL
);
10896 gdb_assert (m_builder
== nullptr);
10897 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10898 m_builder
.reset (new struct buildsym_compunit
10899 (COMPUNIT_OBJFILE (cust
), "",
10900 COMPUNIT_DIRNAME (cust
),
10901 compunit_language (cust
),
10907 line_header
= lh
.release ();
10908 line_header_die_owner
= die
;
10912 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10914 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10915 still initializing it, and our caller (a few levels up)
10916 process_full_type_unit still needs to know if this is the first
10920 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10921 struct symtab
*, line_header
->file_names_size ());
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 dwarf2_start_subfile (this, fe
.name
,
10928 fe
.include_dir (line_header
));
10929 buildsym_compunit
*b
= get_builder ();
10930 if (b
->get_current_subfile ()->symtab
== NULL
)
10932 /* NOTE: start_subfile will recognize when it's been
10933 passed a file it has already seen. So we can't
10934 assume there's a simple mapping from
10935 cu->line_header->file_names to subfiles, plus
10936 cu->line_header->file_names may contain dups. */
10937 b
->get_current_subfile ()->symtab
10938 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10941 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10942 tu_group
->symtabs
[i
] = fe
.symtab
;
10947 gdb_assert (m_builder
== nullptr);
10948 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10949 m_builder
.reset (new struct buildsym_compunit
10950 (COMPUNIT_OBJFILE (cust
), "",
10951 COMPUNIT_DIRNAME (cust
),
10952 compunit_language (cust
),
10955 auto &file_names
= line_header
->file_names ();
10956 for (i
= 0; i
< file_names
.size (); ++i
)
10958 file_entry
&fe
= file_names
[i
];
10959 fe
.symtab
= tu_group
->symtabs
[i
];
10963 /* The main symtab is allocated last. Type units don't have DW_AT_name
10964 so they don't have a "real" (so to speak) symtab anyway.
10965 There is later code that will assign the main symtab to all symbols
10966 that don't have one. We need to handle the case of a symbol with a
10967 missing symtab (DW_AT_decl_file) anyway. */
10970 /* Process DW_TAG_type_unit.
10971 For TUs we want to skip the first top level sibling if it's not the
10972 actual type being defined by this TU. In this case the first top
10973 level sibling is there to provide context only. */
10976 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10978 struct die_info
*child_die
;
10980 prepare_one_comp_unit (cu
, die
, language_minimal
);
10982 /* Initialize (or reinitialize) the machinery for building symtabs.
10983 We do this before processing child DIEs, so that the line header table
10984 is available for DW_AT_decl_file. */
10985 cu
->setup_type_unit_groups (die
);
10987 if (die
->child
!= NULL
)
10989 child_die
= die
->child
;
10990 while (child_die
&& child_die
->tag
)
10992 process_die (child_die
, cu
);
10993 child_die
= sibling_die (child_die
);
11000 http://gcc.gnu.org/wiki/DebugFission
11001 http://gcc.gnu.org/wiki/DebugFissionDWP
11003 To simplify handling of both DWO files ("object" files with the DWARF info)
11004 and DWP files (a file with the DWOs packaged up into one file), we treat
11005 DWP files as having a collection of virtual DWO files. */
11008 hash_dwo_file (const void *item
)
11010 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11013 hash
= htab_hash_string (dwo_file
->dwo_name
);
11014 if (dwo_file
->comp_dir
!= NULL
)
11015 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11020 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11022 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11023 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11025 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11027 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11028 return lhs
->comp_dir
== rhs
->comp_dir
;
11029 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11032 /* Allocate a hash table for DWO files. */
11035 allocate_dwo_file_hash_table ()
11037 auto delete_dwo_file
= [] (void *item
)
11039 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11044 return htab_up (htab_create_alloc (41,
11051 /* Lookup DWO file DWO_NAME. */
11054 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11055 const char *dwo_name
,
11056 const char *comp_dir
)
11058 struct dwo_file find_entry
;
11061 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11062 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11064 find_entry
.dwo_name
= dwo_name
;
11065 find_entry
.comp_dir
= comp_dir
;
11066 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11073 hash_dwo_unit (const void *item
)
11075 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11077 /* This drops the top 32 bits of the id, but is ok for a hash. */
11078 return dwo_unit
->signature
;
11082 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11084 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11085 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11087 /* The signature is assumed to be unique within the DWO file.
11088 So while object file CU dwo_id's always have the value zero,
11089 that's OK, assuming each object file DWO file has only one CU,
11090 and that's the rule for now. */
11091 return lhs
->signature
== rhs
->signature
;
11094 /* Allocate a hash table for DWO CUs,TUs.
11095 There is one of these tables for each of CUs,TUs for each DWO file. */
11098 allocate_dwo_unit_table ()
11100 /* Start out with a pretty small number.
11101 Generally DWO files contain only one CU and maybe some TUs. */
11102 return htab_up (htab_create_alloc (3,
11105 NULL
, xcalloc
, xfree
));
11108 /* die_reader_func for create_dwo_cu. */
11111 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11112 const gdb_byte
*info_ptr
,
11113 struct die_info
*comp_unit_die
,
11114 struct dwo_file
*dwo_file
,
11115 struct dwo_unit
*dwo_unit
)
11117 struct dwarf2_cu
*cu
= reader
->cu
;
11118 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11119 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11121 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11122 if (!signature
.has_value ())
11124 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11125 " its dwo_id [in module %s]"),
11126 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11130 dwo_unit
->dwo_file
= dwo_file
;
11131 dwo_unit
->signature
= *signature
;
11132 dwo_unit
->section
= section
;
11133 dwo_unit
->sect_off
= sect_off
;
11134 dwo_unit
->length
= cu
->per_cu
->length
;
11136 if (dwarf_read_debug
)
11137 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11138 sect_offset_str (sect_off
),
11139 hex_string (dwo_unit
->signature
));
11142 /* Create the dwo_units for the CUs in a DWO_FILE.
11143 Note: This function processes DWO files only, not DWP files. */
11146 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11147 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11148 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11150 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11151 const gdb_byte
*info_ptr
, *end_ptr
;
11153 section
.read (objfile
);
11154 info_ptr
= section
.buffer
;
11156 if (info_ptr
== NULL
)
11159 if (dwarf_read_debug
)
11161 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11162 section
.get_name (),
11163 section
.get_file_name ());
11166 end_ptr
= info_ptr
+ section
.size
;
11167 while (info_ptr
< end_ptr
)
11169 struct dwarf2_per_cu_data per_cu
;
11170 struct dwo_unit read_unit
{};
11171 struct dwo_unit
*dwo_unit
;
11173 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11175 memset (&per_cu
, 0, sizeof (per_cu
));
11176 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11177 per_cu
.is_debug_types
= 0;
11178 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11179 per_cu
.section
= §ion
;
11181 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11182 if (!reader
.dummy_p
)
11183 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11184 &dwo_file
, &read_unit
);
11185 info_ptr
+= per_cu
.length
;
11187 // If the unit could not be parsed, skip it.
11188 if (read_unit
.dwo_file
== NULL
)
11191 if (cus_htab
== NULL
)
11192 cus_htab
= allocate_dwo_unit_table ();
11194 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11195 *dwo_unit
= read_unit
;
11196 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11197 gdb_assert (slot
!= NULL
);
11200 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11201 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11203 complaint (_("debug cu entry at offset %s is duplicate to"
11204 " the entry at offset %s, signature %s"),
11205 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11206 hex_string (dwo_unit
->signature
));
11208 *slot
= (void *)dwo_unit
;
11212 /* DWP file .debug_{cu,tu}_index section format:
11213 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11217 Both index sections have the same format, and serve to map a 64-bit
11218 signature to a set of section numbers. Each section begins with a header,
11219 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11220 indexes, and a pool of 32-bit section numbers. The index sections will be
11221 aligned at 8-byte boundaries in the file.
11223 The index section header consists of:
11225 V, 32 bit version number
11227 N, 32 bit number of compilation units or type units in the index
11228 M, 32 bit number of slots in the hash table
11230 Numbers are recorded using the byte order of the application binary.
11232 The hash table begins at offset 16 in the section, and consists of an array
11233 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11234 order of the application binary). Unused slots in the hash table are 0.
11235 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11237 The parallel table begins immediately after the hash table
11238 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11239 array of 32-bit indexes (using the byte order of the application binary),
11240 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11241 table contains a 32-bit index into the pool of section numbers. For unused
11242 hash table slots, the corresponding entry in the parallel table will be 0.
11244 The pool of section numbers begins immediately following the hash table
11245 (at offset 16 + 12 * M from the beginning of the section). The pool of
11246 section numbers consists of an array of 32-bit words (using the byte order
11247 of the application binary). Each item in the array is indexed starting
11248 from 0. The hash table entry provides the index of the first section
11249 number in the set. Additional section numbers in the set follow, and the
11250 set is terminated by a 0 entry (section number 0 is not used in ELF).
11252 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11253 section must be the first entry in the set, and the .debug_abbrev.dwo must
11254 be the second entry. Other members of the set may follow in any order.
11260 DWP Version 2 combines all the .debug_info, etc. sections into one,
11261 and the entries in the index tables are now offsets into these sections.
11262 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11265 Index Section Contents:
11267 Hash Table of Signatures dwp_hash_table.hash_table
11268 Parallel Table of Indices dwp_hash_table.unit_table
11269 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11270 Table of Section Sizes dwp_hash_table.v2.sizes
11272 The index section header consists of:
11274 V, 32 bit version number
11275 L, 32 bit number of columns in the table of section offsets
11276 N, 32 bit number of compilation units or type units in the index
11277 M, 32 bit number of slots in the hash table
11279 Numbers are recorded using the byte order of the application binary.
11281 The hash table has the same format as version 1.
11282 The parallel table of indices has the same format as version 1,
11283 except that the entries are origin-1 indices into the table of sections
11284 offsets and the table of section sizes.
11286 The table of offsets begins immediately following the parallel table
11287 (at offset 16 + 12 * M from the beginning of the section). The table is
11288 a two-dimensional array of 32-bit words (using the byte order of the
11289 application binary), with L columns and N+1 rows, in row-major order.
11290 Each row in the array is indexed starting from 0. The first row provides
11291 a key to the remaining rows: each column in this row provides an identifier
11292 for a debug section, and the offsets in the same column of subsequent rows
11293 refer to that section. The section identifiers are:
11295 DW_SECT_INFO 1 .debug_info.dwo
11296 DW_SECT_TYPES 2 .debug_types.dwo
11297 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11298 DW_SECT_LINE 4 .debug_line.dwo
11299 DW_SECT_LOC 5 .debug_loc.dwo
11300 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11301 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11302 DW_SECT_MACRO 8 .debug_macro.dwo
11304 The offsets provided by the CU and TU index sections are the base offsets
11305 for the contributions made by each CU or TU to the corresponding section
11306 in the package file. Each CU and TU header contains an abbrev_offset
11307 field, used to find the abbreviations table for that CU or TU within the
11308 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11309 be interpreted as relative to the base offset given in the index section.
11310 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11311 should be interpreted as relative to the base offset for .debug_line.dwo,
11312 and offsets into other debug sections obtained from DWARF attributes should
11313 also be interpreted as relative to the corresponding base offset.
11315 The table of sizes begins immediately following the table of offsets.
11316 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11317 with L columns and N rows, in row-major order. Each row in the array is
11318 indexed starting from 1 (row 0 is shared by the two tables).
11322 Hash table lookup is handled the same in version 1 and 2:
11324 We assume that N and M will not exceed 2^32 - 1.
11325 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11327 Given a 64-bit compilation unit signature or a type signature S, an entry
11328 in the hash table is located as follows:
11330 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11331 the low-order k bits all set to 1.
11333 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11335 3) If the hash table entry at index H matches the signature, use that
11336 entry. If the hash table entry at index H is unused (all zeroes),
11337 terminate the search: the signature is not present in the table.
11339 4) Let H = (H + H') modulo M. Repeat at Step 3.
11341 Because M > N and H' and M are relatively prime, the search is guaranteed
11342 to stop at an unused slot or find the match. */
11344 /* Create a hash table to map DWO IDs to their CU/TU entry in
11345 .debug_{info,types}.dwo in DWP_FILE.
11346 Returns NULL if there isn't one.
11347 Note: This function processes DWP files only, not DWO files. */
11349 static struct dwp_hash_table
*
11350 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11351 struct dwp_file
*dwp_file
, int is_debug_types
)
11353 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11354 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11355 const gdb_byte
*index_ptr
, *index_end
;
11356 struct dwarf2_section_info
*index
;
11357 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11358 struct dwp_hash_table
*htab
;
11360 if (is_debug_types
)
11361 index
= &dwp_file
->sections
.tu_index
;
11363 index
= &dwp_file
->sections
.cu_index
;
11365 if (index
->empty ())
11367 index
->read (objfile
);
11369 index_ptr
= index
->buffer
;
11370 index_end
= index_ptr
+ index
->size
;
11372 version
= read_4_bytes (dbfd
, index_ptr
);
11375 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11379 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11381 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11384 if (version
!= 1 && version
!= 2)
11386 error (_("Dwarf Error: unsupported DWP file version (%s)"
11387 " [in module %s]"),
11388 pulongest (version
), dwp_file
->name
);
11390 if (nr_slots
!= (nr_slots
& -nr_slots
))
11392 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11393 " is not power of 2 [in module %s]"),
11394 pulongest (nr_slots
), dwp_file
->name
);
11397 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11398 htab
->version
= version
;
11399 htab
->nr_columns
= nr_columns
;
11400 htab
->nr_units
= nr_units
;
11401 htab
->nr_slots
= nr_slots
;
11402 htab
->hash_table
= index_ptr
;
11403 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11405 /* Exit early if the table is empty. */
11406 if (nr_slots
== 0 || nr_units
== 0
11407 || (version
== 2 && nr_columns
== 0))
11409 /* All must be zero. */
11410 if (nr_slots
!= 0 || nr_units
!= 0
11411 || (version
== 2 && nr_columns
!= 0))
11413 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11414 " all zero [in modules %s]"),
11422 htab
->section_pool
.v1
.indices
=
11423 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11424 /* It's harder to decide whether the section is too small in v1.
11425 V1 is deprecated anyway so we punt. */
11429 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11430 int *ids
= htab
->section_pool
.v2
.section_ids
;
11431 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11432 /* Reverse map for error checking. */
11433 int ids_seen
[DW_SECT_MAX
+ 1];
11436 if (nr_columns
< 2)
11438 error (_("Dwarf Error: bad DWP hash table, too few columns"
11439 " in section table [in module %s]"),
11442 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11444 error (_("Dwarf Error: bad DWP hash table, too many columns"
11445 " in section table [in module %s]"),
11448 memset (ids
, 255, sizeof_ids
);
11449 memset (ids_seen
, 255, sizeof (ids_seen
));
11450 for (i
= 0; i
< nr_columns
; ++i
)
11452 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11454 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11456 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11457 " in section table [in module %s]"),
11458 id
, dwp_file
->name
);
11460 if (ids_seen
[id
] != -1)
11462 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11463 " id %d in section table [in module %s]"),
11464 id
, dwp_file
->name
);
11469 /* Must have exactly one info or types section. */
11470 if (((ids_seen
[DW_SECT_INFO
] != -1)
11471 + (ids_seen
[DW_SECT_TYPES
] != -1))
11474 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11475 " DWO info/types section [in module %s]"),
11478 /* Must have an abbrev section. */
11479 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11481 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11482 " section [in module %s]"),
11485 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11486 htab
->section_pool
.v2
.sizes
=
11487 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11488 * nr_units
* nr_columns
);
11489 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11490 * nr_units
* nr_columns
))
11493 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11494 " [in module %s]"),
11502 /* Update SECTIONS with the data from SECTP.
11504 This function is like the other "locate" section routines that are
11505 passed to bfd_map_over_sections, but in this context the sections to
11506 read comes from the DWP V1 hash table, not the full ELF section table.
11508 The result is non-zero for success, or zero if an error was found. */
11511 locate_v1_virtual_dwo_sections (asection
*sectp
,
11512 struct virtual_v1_dwo_sections
*sections
)
11514 const struct dwop_section_names
*names
= &dwop_section_names
;
11516 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11518 /* There can be only one. */
11519 if (sections
->abbrev
.s
.section
!= NULL
)
11521 sections
->abbrev
.s
.section
= sectp
;
11522 sections
->abbrev
.size
= bfd_section_size (sectp
);
11524 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11525 || section_is_p (sectp
->name
, &names
->types_dwo
))
11527 /* There can be only one. */
11528 if (sections
->info_or_types
.s
.section
!= NULL
)
11530 sections
->info_or_types
.s
.section
= sectp
;
11531 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11533 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11535 /* There can be only one. */
11536 if (sections
->line
.s
.section
!= NULL
)
11538 sections
->line
.s
.section
= sectp
;
11539 sections
->line
.size
= bfd_section_size (sectp
);
11541 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11543 /* There can be only one. */
11544 if (sections
->loc
.s
.section
!= NULL
)
11546 sections
->loc
.s
.section
= sectp
;
11547 sections
->loc
.size
= bfd_section_size (sectp
);
11549 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11551 /* There can be only one. */
11552 if (sections
->macinfo
.s
.section
!= NULL
)
11554 sections
->macinfo
.s
.section
= sectp
;
11555 sections
->macinfo
.size
= bfd_section_size (sectp
);
11557 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11559 /* There can be only one. */
11560 if (sections
->macro
.s
.section
!= NULL
)
11562 sections
->macro
.s
.section
= sectp
;
11563 sections
->macro
.size
= bfd_section_size (sectp
);
11565 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11567 /* There can be only one. */
11568 if (sections
->str_offsets
.s
.section
!= NULL
)
11570 sections
->str_offsets
.s
.section
= sectp
;
11571 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11575 /* No other kind of section is valid. */
11582 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11583 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11584 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11585 This is for DWP version 1 files. */
11587 static struct dwo_unit
*
11588 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11589 struct dwp_file
*dwp_file
,
11590 uint32_t unit_index
,
11591 const char *comp_dir
,
11592 ULONGEST signature
, int is_debug_types
)
11594 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11595 const struct dwp_hash_table
*dwp_htab
=
11596 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11597 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11598 const char *kind
= is_debug_types
? "TU" : "CU";
11599 struct dwo_file
*dwo_file
;
11600 struct dwo_unit
*dwo_unit
;
11601 struct virtual_v1_dwo_sections sections
;
11602 void **dwo_file_slot
;
11605 gdb_assert (dwp_file
->version
== 1);
11607 if (dwarf_read_debug
)
11609 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11611 pulongest (unit_index
), hex_string (signature
),
11615 /* Fetch the sections of this DWO unit.
11616 Put a limit on the number of sections we look for so that bad data
11617 doesn't cause us to loop forever. */
11619 #define MAX_NR_V1_DWO_SECTIONS \
11620 (1 /* .debug_info or .debug_types */ \
11621 + 1 /* .debug_abbrev */ \
11622 + 1 /* .debug_line */ \
11623 + 1 /* .debug_loc */ \
11624 + 1 /* .debug_str_offsets */ \
11625 + 1 /* .debug_macro or .debug_macinfo */ \
11626 + 1 /* trailing zero */)
11628 memset (§ions
, 0, sizeof (sections
));
11630 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11633 uint32_t section_nr
=
11634 read_4_bytes (dbfd
,
11635 dwp_htab
->section_pool
.v1
.indices
11636 + (unit_index
+ i
) * sizeof (uint32_t));
11638 if (section_nr
== 0)
11640 if (section_nr
>= dwp_file
->num_sections
)
11642 error (_("Dwarf Error: bad DWP hash table, section number too large"
11643 " [in module %s]"),
11647 sectp
= dwp_file
->elf_sections
[section_nr
];
11648 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11650 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11651 " [in module %s]"),
11657 || sections
.info_or_types
.empty ()
11658 || sections
.abbrev
.empty ())
11660 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11661 " [in module %s]"),
11664 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11666 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11667 " [in module %s]"),
11671 /* It's easier for the rest of the code if we fake a struct dwo_file and
11672 have dwo_unit "live" in that. At least for now.
11674 The DWP file can be made up of a random collection of CUs and TUs.
11675 However, for each CU + set of TUs that came from the same original DWO
11676 file, we can combine them back into a virtual DWO file to save space
11677 (fewer struct dwo_file objects to allocate). Remember that for really
11678 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11680 std::string virtual_dwo_name
=
11681 string_printf ("virtual-dwo/%d-%d-%d-%d",
11682 sections
.abbrev
.get_id (),
11683 sections
.line
.get_id (),
11684 sections
.loc
.get_id (),
11685 sections
.str_offsets
.get_id ());
11686 /* Can we use an existing virtual DWO file? */
11687 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11688 virtual_dwo_name
.c_str (),
11690 /* Create one if necessary. */
11691 if (*dwo_file_slot
== NULL
)
11693 if (dwarf_read_debug
)
11695 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11696 virtual_dwo_name
.c_str ());
11698 dwo_file
= new struct dwo_file
;
11699 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11700 dwo_file
->comp_dir
= comp_dir
;
11701 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11702 dwo_file
->sections
.line
= sections
.line
;
11703 dwo_file
->sections
.loc
= sections
.loc
;
11704 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11705 dwo_file
->sections
.macro
= sections
.macro
;
11706 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11707 /* The "str" section is global to the entire DWP file. */
11708 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11709 /* The info or types section is assigned below to dwo_unit,
11710 there's no need to record it in dwo_file.
11711 Also, we can't simply record type sections in dwo_file because
11712 we record a pointer into the vector in dwo_unit. As we collect more
11713 types we'll grow the vector and eventually have to reallocate space
11714 for it, invalidating all copies of pointers into the previous
11716 *dwo_file_slot
= dwo_file
;
11720 if (dwarf_read_debug
)
11722 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11723 virtual_dwo_name
.c_str ());
11725 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11728 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11729 dwo_unit
->dwo_file
= dwo_file
;
11730 dwo_unit
->signature
= signature
;
11731 dwo_unit
->section
=
11732 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11733 *dwo_unit
->section
= sections
.info_or_types
;
11734 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11739 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11740 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11741 piece within that section used by a TU/CU, return a virtual section
11742 of just that piece. */
11744 static struct dwarf2_section_info
11745 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11746 struct dwarf2_section_info
*section
,
11747 bfd_size_type offset
, bfd_size_type size
)
11749 struct dwarf2_section_info result
;
11752 gdb_assert (section
!= NULL
);
11753 gdb_assert (!section
->is_virtual
);
11755 memset (&result
, 0, sizeof (result
));
11756 result
.s
.containing_section
= section
;
11757 result
.is_virtual
= true;
11762 sectp
= section
->get_bfd_section ();
11764 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11765 bounds of the real section. This is a pretty-rare event, so just
11766 flag an error (easier) instead of a warning and trying to cope. */
11768 || offset
+ size
> bfd_section_size (sectp
))
11770 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11771 " in section %s [in module %s]"),
11772 sectp
? bfd_section_name (sectp
) : "<unknown>",
11773 objfile_name (dwarf2_per_objfile
->objfile
));
11776 result
.virtual_offset
= offset
;
11777 result
.size
= size
;
11781 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11782 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11783 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11784 This is for DWP version 2 files. */
11786 static struct dwo_unit
*
11787 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11788 struct dwp_file
*dwp_file
,
11789 uint32_t unit_index
,
11790 const char *comp_dir
,
11791 ULONGEST signature
, int is_debug_types
)
11793 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11794 const struct dwp_hash_table
*dwp_htab
=
11795 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11796 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11797 const char *kind
= is_debug_types
? "TU" : "CU";
11798 struct dwo_file
*dwo_file
;
11799 struct dwo_unit
*dwo_unit
;
11800 struct virtual_v2_dwo_sections sections
;
11801 void **dwo_file_slot
;
11804 gdb_assert (dwp_file
->version
== 2);
11806 if (dwarf_read_debug
)
11808 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11810 pulongest (unit_index
), hex_string (signature
),
11814 /* Fetch the section offsets of this DWO unit. */
11816 memset (§ions
, 0, sizeof (sections
));
11818 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11820 uint32_t offset
= read_4_bytes (dbfd
,
11821 dwp_htab
->section_pool
.v2
.offsets
11822 + (((unit_index
- 1) * dwp_htab
->nr_columns
11824 * sizeof (uint32_t)));
11825 uint32_t size
= read_4_bytes (dbfd
,
11826 dwp_htab
->section_pool
.v2
.sizes
11827 + (((unit_index
- 1) * dwp_htab
->nr_columns
11829 * sizeof (uint32_t)));
11831 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11834 case DW_SECT_TYPES
:
11835 sections
.info_or_types_offset
= offset
;
11836 sections
.info_or_types_size
= size
;
11838 case DW_SECT_ABBREV
:
11839 sections
.abbrev_offset
= offset
;
11840 sections
.abbrev_size
= size
;
11843 sections
.line_offset
= offset
;
11844 sections
.line_size
= size
;
11847 sections
.loc_offset
= offset
;
11848 sections
.loc_size
= size
;
11850 case DW_SECT_STR_OFFSETS
:
11851 sections
.str_offsets_offset
= offset
;
11852 sections
.str_offsets_size
= size
;
11854 case DW_SECT_MACINFO
:
11855 sections
.macinfo_offset
= offset
;
11856 sections
.macinfo_size
= size
;
11858 case DW_SECT_MACRO
:
11859 sections
.macro_offset
= offset
;
11860 sections
.macro_size
= size
;
11865 /* It's easier for the rest of the code if we fake a struct dwo_file and
11866 have dwo_unit "live" in that. At least for now.
11868 The DWP file can be made up of a random collection of CUs and TUs.
11869 However, for each CU + set of TUs that came from the same original DWO
11870 file, we can combine them back into a virtual DWO file to save space
11871 (fewer struct dwo_file objects to allocate). Remember that for really
11872 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11874 std::string virtual_dwo_name
=
11875 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11876 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11877 (long) (sections
.line_size
? sections
.line_offset
: 0),
11878 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11879 (long) (sections
.str_offsets_size
11880 ? sections
.str_offsets_offset
: 0));
11881 /* Can we use an existing virtual DWO file? */
11882 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11883 virtual_dwo_name
.c_str (),
11885 /* Create one if necessary. */
11886 if (*dwo_file_slot
== NULL
)
11888 if (dwarf_read_debug
)
11890 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11891 virtual_dwo_name
.c_str ());
11893 dwo_file
= new struct dwo_file
;
11894 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11895 dwo_file
->comp_dir
= comp_dir
;
11896 dwo_file
->sections
.abbrev
=
11897 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11898 sections
.abbrev_offset
, sections
.abbrev_size
);
11899 dwo_file
->sections
.line
=
11900 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11901 sections
.line_offset
, sections
.line_size
);
11902 dwo_file
->sections
.loc
=
11903 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11904 sections
.loc_offset
, sections
.loc_size
);
11905 dwo_file
->sections
.macinfo
=
11906 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11907 sections
.macinfo_offset
, sections
.macinfo_size
);
11908 dwo_file
->sections
.macro
=
11909 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11910 sections
.macro_offset
, sections
.macro_size
);
11911 dwo_file
->sections
.str_offsets
=
11912 create_dwp_v2_section (dwarf2_per_objfile
,
11913 &dwp_file
->sections
.str_offsets
,
11914 sections
.str_offsets_offset
,
11915 sections
.str_offsets_size
);
11916 /* The "str" section is global to the entire DWP file. */
11917 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11918 /* The info or types section is assigned below to dwo_unit,
11919 there's no need to record it in dwo_file.
11920 Also, we can't simply record type sections in dwo_file because
11921 we record a pointer into the vector in dwo_unit. As we collect more
11922 types we'll grow the vector and eventually have to reallocate space
11923 for it, invalidating all copies of pointers into the previous
11925 *dwo_file_slot
= dwo_file
;
11929 if (dwarf_read_debug
)
11931 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11932 virtual_dwo_name
.c_str ());
11934 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11937 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11938 dwo_unit
->dwo_file
= dwo_file
;
11939 dwo_unit
->signature
= signature
;
11940 dwo_unit
->section
=
11941 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11942 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11944 ? &dwp_file
->sections
.types
11945 : &dwp_file
->sections
.info
,
11946 sections
.info_or_types_offset
,
11947 sections
.info_or_types_size
);
11948 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11953 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11954 Returns NULL if the signature isn't found. */
11956 static struct dwo_unit
*
11957 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11958 struct dwp_file
*dwp_file
, const char *comp_dir
,
11959 ULONGEST signature
, int is_debug_types
)
11961 const struct dwp_hash_table
*dwp_htab
=
11962 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11963 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11964 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11965 uint32_t hash
= signature
& mask
;
11966 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11969 struct dwo_unit find_dwo_cu
;
11971 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11972 find_dwo_cu
.signature
= signature
;
11973 slot
= htab_find_slot (is_debug_types
11974 ? dwp_file
->loaded_tus
.get ()
11975 : dwp_file
->loaded_cus
.get (),
11976 &find_dwo_cu
, INSERT
);
11979 return (struct dwo_unit
*) *slot
;
11981 /* Use a for loop so that we don't loop forever on bad debug info. */
11982 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11984 ULONGEST signature_in_table
;
11986 signature_in_table
=
11987 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11988 if (signature_in_table
== signature
)
11990 uint32_t unit_index
=
11991 read_4_bytes (dbfd
,
11992 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11994 if (dwp_file
->version
== 1)
11996 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11997 dwp_file
, unit_index
,
11998 comp_dir
, signature
,
12003 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12004 dwp_file
, unit_index
,
12005 comp_dir
, signature
,
12008 return (struct dwo_unit
*) *slot
;
12010 if (signature_in_table
== 0)
12012 hash
= (hash
+ hash2
) & mask
;
12015 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12016 " [in module %s]"),
12020 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12021 Open the file specified by FILE_NAME and hand it off to BFD for
12022 preliminary analysis. Return a newly initialized bfd *, which
12023 includes a canonicalized copy of FILE_NAME.
12024 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12025 SEARCH_CWD is true if the current directory is to be searched.
12026 It will be searched before debug-file-directory.
12027 If successful, the file is added to the bfd include table of the
12028 objfile's bfd (see gdb_bfd_record_inclusion).
12029 If unable to find/open the file, return NULL.
12030 NOTE: This function is derived from symfile_bfd_open. */
12032 static gdb_bfd_ref_ptr
12033 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12034 const char *file_name
, int is_dwp
, int search_cwd
)
12037 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12038 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12039 to debug_file_directory. */
12040 const char *search_path
;
12041 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12043 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12046 if (*debug_file_directory
!= '\0')
12048 search_path_holder
.reset (concat (".", dirname_separator_string
,
12049 debug_file_directory
,
12051 search_path
= search_path_holder
.get ();
12057 search_path
= debug_file_directory
;
12059 openp_flags flags
= OPF_RETURN_REALPATH
;
12061 flags
|= OPF_SEARCH_IN_PATH
;
12063 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12064 desc
= openp (search_path
, flags
, file_name
,
12065 O_RDONLY
| O_BINARY
, &absolute_name
);
12069 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12071 if (sym_bfd
== NULL
)
12073 bfd_set_cacheable (sym_bfd
.get (), 1);
12075 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12078 /* Success. Record the bfd as having been included by the objfile's bfd.
12079 This is important because things like demangled_names_hash lives in the
12080 objfile's per_bfd space and may have references to things like symbol
12081 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12082 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12087 /* Try to open DWO file FILE_NAME.
12088 COMP_DIR is the DW_AT_comp_dir attribute.
12089 The result is the bfd handle of the file.
12090 If there is a problem finding or opening the file, return NULL.
12091 Upon success, the canonicalized path of the file is stored in the bfd,
12092 same as symfile_bfd_open. */
12094 static gdb_bfd_ref_ptr
12095 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12096 const char *file_name
, const char *comp_dir
)
12098 if (IS_ABSOLUTE_PATH (file_name
))
12099 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12100 0 /*is_dwp*/, 0 /*search_cwd*/);
12102 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12104 if (comp_dir
!= NULL
)
12106 gdb::unique_xmalloc_ptr
<char> path_to_try
12107 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12109 /* NOTE: If comp_dir is a relative path, this will also try the
12110 search path, which seems useful. */
12111 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12112 path_to_try
.get (),
12114 1 /*search_cwd*/));
12119 /* That didn't work, try debug-file-directory, which, despite its name,
12120 is a list of paths. */
12122 if (*debug_file_directory
== '\0')
12125 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12126 0 /*is_dwp*/, 1 /*search_cwd*/);
12129 /* This function is mapped across the sections and remembers the offset and
12130 size of each of the DWO debugging sections we are interested in. */
12133 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12135 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12136 const struct dwop_section_names
*names
= &dwop_section_names
;
12138 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12140 dwo_sections
->abbrev
.s
.section
= sectp
;
12141 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12143 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12145 dwo_sections
->info
.s
.section
= sectp
;
12146 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12148 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12150 dwo_sections
->line
.s
.section
= sectp
;
12151 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12153 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12155 dwo_sections
->loc
.s
.section
= sectp
;
12156 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12158 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12160 dwo_sections
->macinfo
.s
.section
= sectp
;
12161 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12163 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12165 dwo_sections
->macro
.s
.section
= sectp
;
12166 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12168 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12170 dwo_sections
->str
.s
.section
= sectp
;
12171 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12173 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12175 dwo_sections
->str_offsets
.s
.section
= sectp
;
12176 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12178 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12180 struct dwarf2_section_info type_section
;
12182 memset (&type_section
, 0, sizeof (type_section
));
12183 type_section
.s
.section
= sectp
;
12184 type_section
.size
= bfd_section_size (sectp
);
12185 dwo_sections
->types
.push_back (type_section
);
12189 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12190 by PER_CU. This is for the non-DWP case.
12191 The result is NULL if DWO_NAME can't be found. */
12193 static struct dwo_file
*
12194 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12195 const char *dwo_name
, const char *comp_dir
)
12197 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12199 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12202 if (dwarf_read_debug
)
12203 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12207 dwo_file_up
dwo_file (new struct dwo_file
);
12208 dwo_file
->dwo_name
= dwo_name
;
12209 dwo_file
->comp_dir
= comp_dir
;
12210 dwo_file
->dbfd
= std::move (dbfd
);
12212 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12213 &dwo_file
->sections
);
12215 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12216 dwo_file
->sections
.info
, dwo_file
->cus
);
12218 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12219 dwo_file
->sections
.types
, dwo_file
->tus
);
12221 if (dwarf_read_debug
)
12222 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12224 return dwo_file
.release ();
12227 /* This function is mapped across the sections and remembers the offset and
12228 size of each of the DWP debugging sections common to version 1 and 2 that
12229 we are interested in. */
12232 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12233 void *dwp_file_ptr
)
12235 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12236 const struct dwop_section_names
*names
= &dwop_section_names
;
12237 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12239 /* Record the ELF section number for later lookup: this is what the
12240 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12241 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12242 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12244 /* Look for specific sections that we need. */
12245 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12247 dwp_file
->sections
.str
.s
.section
= sectp
;
12248 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12250 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12252 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12253 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12255 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12257 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12258 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12262 /* This function is mapped across the sections and remembers the offset and
12263 size of each of the DWP version 2 debugging sections that we are interested
12264 in. This is split into a separate function because we don't know if we
12265 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12268 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12270 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12271 const struct dwop_section_names
*names
= &dwop_section_names
;
12272 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12274 /* Record the ELF section number for later lookup: this is what the
12275 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12276 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12277 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12279 /* Look for specific sections that we need. */
12280 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12282 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12283 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12285 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12287 dwp_file
->sections
.info
.s
.section
= sectp
;
12288 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12290 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12292 dwp_file
->sections
.line
.s
.section
= sectp
;
12293 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12295 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12297 dwp_file
->sections
.loc
.s
.section
= sectp
;
12298 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12300 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12302 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12303 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12305 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12307 dwp_file
->sections
.macro
.s
.section
= sectp
;
12308 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12310 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12312 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12313 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12315 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12317 dwp_file
->sections
.types
.s
.section
= sectp
;
12318 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12322 /* Hash function for dwp_file loaded CUs/TUs. */
12325 hash_dwp_loaded_cutus (const void *item
)
12327 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12329 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12330 return dwo_unit
->signature
;
12333 /* Equality function for dwp_file loaded CUs/TUs. */
12336 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12338 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12339 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12341 return dua
->signature
== dub
->signature
;
12344 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12347 allocate_dwp_loaded_cutus_table ()
12349 return htab_up (htab_create_alloc (3,
12350 hash_dwp_loaded_cutus
,
12351 eq_dwp_loaded_cutus
,
12352 NULL
, xcalloc
, xfree
));
12355 /* Try to open DWP file FILE_NAME.
12356 The result is the bfd handle of the file.
12357 If there is a problem finding or opening the file, return NULL.
12358 Upon success, the canonicalized path of the file is stored in the bfd,
12359 same as symfile_bfd_open. */
12361 static gdb_bfd_ref_ptr
12362 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12363 const char *file_name
)
12365 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12367 1 /*search_cwd*/));
12371 /* Work around upstream bug 15652.
12372 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12373 [Whether that's a "bug" is debatable, but it is getting in our way.]
12374 We have no real idea where the dwp file is, because gdb's realpath-ing
12375 of the executable's path may have discarded the needed info.
12376 [IWBN if the dwp file name was recorded in the executable, akin to
12377 .gnu_debuglink, but that doesn't exist yet.]
12378 Strip the directory from FILE_NAME and search again. */
12379 if (*debug_file_directory
!= '\0')
12381 /* Don't implicitly search the current directory here.
12382 If the user wants to search "." to handle this case,
12383 it must be added to debug-file-directory. */
12384 return try_open_dwop_file (dwarf2_per_objfile
,
12385 lbasename (file_name
), 1 /*is_dwp*/,
12392 /* Initialize the use of the DWP file for the current objfile.
12393 By convention the name of the DWP file is ${objfile}.dwp.
12394 The result is NULL if it can't be found. */
12396 static std::unique_ptr
<struct dwp_file
>
12397 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12399 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12401 /* Try to find first .dwp for the binary file before any symbolic links
12404 /* If the objfile is a debug file, find the name of the real binary
12405 file and get the name of dwp file from there. */
12406 std::string dwp_name
;
12407 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12409 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12410 const char *backlink_basename
= lbasename (backlink
->original_name
);
12412 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12415 dwp_name
= objfile
->original_name
;
12417 dwp_name
+= ".dwp";
12419 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12421 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12423 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12424 dwp_name
= objfile_name (objfile
);
12425 dwp_name
+= ".dwp";
12426 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12431 if (dwarf_read_debug
)
12432 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12433 return std::unique_ptr
<dwp_file
> ();
12436 const char *name
= bfd_get_filename (dbfd
.get ());
12437 std::unique_ptr
<struct dwp_file
> dwp_file
12438 (new struct dwp_file (name
, std::move (dbfd
)));
12440 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12441 dwp_file
->elf_sections
=
12442 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12443 dwp_file
->num_sections
, asection
*);
12445 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12446 dwarf2_locate_common_dwp_sections
,
12449 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12452 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12455 /* The DWP file version is stored in the hash table. Oh well. */
12456 if (dwp_file
->cus
&& dwp_file
->tus
12457 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12459 /* Technically speaking, we should try to limp along, but this is
12460 pretty bizarre. We use pulongest here because that's the established
12461 portability solution (e.g, we cannot use %u for uint32_t). */
12462 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12463 " TU version %s [in DWP file %s]"),
12464 pulongest (dwp_file
->cus
->version
),
12465 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12469 dwp_file
->version
= dwp_file
->cus
->version
;
12470 else if (dwp_file
->tus
)
12471 dwp_file
->version
= dwp_file
->tus
->version
;
12473 dwp_file
->version
= 2;
12475 if (dwp_file
->version
== 2)
12476 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12477 dwarf2_locate_v2_dwp_sections
,
12480 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12481 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12483 if (dwarf_read_debug
)
12485 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12486 fprintf_unfiltered (gdb_stdlog
,
12487 " %s CUs, %s TUs\n",
12488 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12489 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12495 /* Wrapper around open_and_init_dwp_file, only open it once. */
12497 static struct dwp_file
*
12498 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12500 if (! dwarf2_per_objfile
->dwp_checked
)
12502 dwarf2_per_objfile
->dwp_file
12503 = open_and_init_dwp_file (dwarf2_per_objfile
);
12504 dwarf2_per_objfile
->dwp_checked
= 1;
12506 return dwarf2_per_objfile
->dwp_file
.get ();
12509 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12510 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12511 or in the DWP file for the objfile, referenced by THIS_UNIT.
12512 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12513 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12515 This is called, for example, when wanting to read a variable with a
12516 complex location. Therefore we don't want to do file i/o for every call.
12517 Therefore we don't want to look for a DWO file on every call.
12518 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12519 then we check if we've already seen DWO_NAME, and only THEN do we check
12522 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12523 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12525 static struct dwo_unit
*
12526 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12527 const char *dwo_name
, const char *comp_dir
,
12528 ULONGEST signature
, int is_debug_types
)
12530 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12531 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12532 const char *kind
= is_debug_types
? "TU" : "CU";
12533 void **dwo_file_slot
;
12534 struct dwo_file
*dwo_file
;
12535 struct dwp_file
*dwp_file
;
12537 /* First see if there's a DWP file.
12538 If we have a DWP file but didn't find the DWO inside it, don't
12539 look for the original DWO file. It makes gdb behave differently
12540 depending on whether one is debugging in the build tree. */
12542 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12543 if (dwp_file
!= NULL
)
12545 const struct dwp_hash_table
*dwp_htab
=
12546 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12548 if (dwp_htab
!= NULL
)
12550 struct dwo_unit
*dwo_cutu
=
12551 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12552 signature
, is_debug_types
);
12554 if (dwo_cutu
!= NULL
)
12556 if (dwarf_read_debug
)
12558 fprintf_unfiltered (gdb_stdlog
,
12559 "Virtual DWO %s %s found: @%s\n",
12560 kind
, hex_string (signature
),
12561 host_address_to_string (dwo_cutu
));
12569 /* No DWP file, look for the DWO file. */
12571 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12572 dwo_name
, comp_dir
);
12573 if (*dwo_file_slot
== NULL
)
12575 /* Read in the file and build a table of the CUs/TUs it contains. */
12576 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12578 /* NOTE: This will be NULL if unable to open the file. */
12579 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12581 if (dwo_file
!= NULL
)
12583 struct dwo_unit
*dwo_cutu
= NULL
;
12585 if (is_debug_types
&& dwo_file
->tus
)
12587 struct dwo_unit find_dwo_cutu
;
12589 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12590 find_dwo_cutu
.signature
= signature
;
12592 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12595 else if (!is_debug_types
&& dwo_file
->cus
)
12597 struct dwo_unit find_dwo_cutu
;
12599 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12600 find_dwo_cutu
.signature
= signature
;
12601 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12605 if (dwo_cutu
!= NULL
)
12607 if (dwarf_read_debug
)
12609 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12610 kind
, dwo_name
, hex_string (signature
),
12611 host_address_to_string (dwo_cutu
));
12618 /* We didn't find it. This could mean a dwo_id mismatch, or
12619 someone deleted the DWO/DWP file, or the search path isn't set up
12620 correctly to find the file. */
12622 if (dwarf_read_debug
)
12624 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12625 kind
, dwo_name
, hex_string (signature
));
12628 /* This is a warning and not a complaint because it can be caused by
12629 pilot error (e.g., user accidentally deleting the DWO). */
12631 /* Print the name of the DWP file if we looked there, helps the user
12632 better diagnose the problem. */
12633 std::string dwp_text
;
12635 if (dwp_file
!= NULL
)
12636 dwp_text
= string_printf (" [in DWP file %s]",
12637 lbasename (dwp_file
->name
));
12639 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12640 " [in module %s]"),
12641 kind
, dwo_name
, hex_string (signature
),
12643 this_unit
->is_debug_types
? "TU" : "CU",
12644 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12649 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12650 See lookup_dwo_cutu_unit for details. */
12652 static struct dwo_unit
*
12653 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12654 const char *dwo_name
, const char *comp_dir
,
12655 ULONGEST signature
)
12657 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12660 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12661 See lookup_dwo_cutu_unit for details. */
12663 static struct dwo_unit
*
12664 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12665 const char *dwo_name
, const char *comp_dir
)
12667 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12670 /* Traversal function for queue_and_load_all_dwo_tus. */
12673 queue_and_load_dwo_tu (void **slot
, void *info
)
12675 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12676 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12677 ULONGEST signature
= dwo_unit
->signature
;
12678 struct signatured_type
*sig_type
=
12679 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12681 if (sig_type
!= NULL
)
12683 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12685 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12686 a real dependency of PER_CU on SIG_TYPE. That is detected later
12687 while processing PER_CU. */
12688 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12689 load_full_type_unit (sig_cu
);
12690 per_cu
->imported_symtabs_push (sig_cu
);
12696 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12697 The DWO may have the only definition of the type, though it may not be
12698 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12699 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12702 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12704 struct dwo_unit
*dwo_unit
;
12705 struct dwo_file
*dwo_file
;
12707 gdb_assert (!per_cu
->is_debug_types
);
12708 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12709 gdb_assert (per_cu
->cu
!= NULL
);
12711 dwo_unit
= per_cu
->cu
->dwo_unit
;
12712 gdb_assert (dwo_unit
!= NULL
);
12714 dwo_file
= dwo_unit
->dwo_file
;
12715 if (dwo_file
->tus
!= NULL
)
12716 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12720 /* Read in various DIEs. */
12722 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12723 Inherit only the children of the DW_AT_abstract_origin DIE not being
12724 already referenced by DW_AT_abstract_origin from the children of the
12728 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12730 struct die_info
*child_die
;
12731 sect_offset
*offsetp
;
12732 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12733 struct die_info
*origin_die
;
12734 /* Iterator of the ORIGIN_DIE children. */
12735 struct die_info
*origin_child_die
;
12736 struct attribute
*attr
;
12737 struct dwarf2_cu
*origin_cu
;
12738 struct pending
**origin_previous_list_in_scope
;
12740 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12744 /* Note that following die references may follow to a die in a
12748 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12750 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12752 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12753 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12755 if (die
->tag
!= origin_die
->tag
12756 && !(die
->tag
== DW_TAG_inlined_subroutine
12757 && origin_die
->tag
== DW_TAG_subprogram
))
12758 complaint (_("DIE %s and its abstract origin %s have different tags"),
12759 sect_offset_str (die
->sect_off
),
12760 sect_offset_str (origin_die
->sect_off
));
12762 std::vector
<sect_offset
> offsets
;
12764 for (child_die
= die
->child
;
12765 child_die
&& child_die
->tag
;
12766 child_die
= sibling_die (child_die
))
12768 struct die_info
*child_origin_die
;
12769 struct dwarf2_cu
*child_origin_cu
;
12771 /* We are trying to process concrete instance entries:
12772 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12773 it's not relevant to our analysis here. i.e. detecting DIEs that are
12774 present in the abstract instance but not referenced in the concrete
12776 if (child_die
->tag
== DW_TAG_call_site
12777 || child_die
->tag
== DW_TAG_GNU_call_site
)
12780 /* For each CHILD_DIE, find the corresponding child of
12781 ORIGIN_DIE. If there is more than one layer of
12782 DW_AT_abstract_origin, follow them all; there shouldn't be,
12783 but GCC versions at least through 4.4 generate this (GCC PR
12785 child_origin_die
= child_die
;
12786 child_origin_cu
= cu
;
12789 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12793 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12797 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12798 counterpart may exist. */
12799 if (child_origin_die
!= child_die
)
12801 if (child_die
->tag
!= child_origin_die
->tag
12802 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12803 && child_origin_die
->tag
== DW_TAG_subprogram
))
12804 complaint (_("Child DIE %s and its abstract origin %s have "
12806 sect_offset_str (child_die
->sect_off
),
12807 sect_offset_str (child_origin_die
->sect_off
));
12808 if (child_origin_die
->parent
!= origin_die
)
12809 complaint (_("Child DIE %s and its abstract origin %s have "
12810 "different parents"),
12811 sect_offset_str (child_die
->sect_off
),
12812 sect_offset_str (child_origin_die
->sect_off
));
12814 offsets
.push_back (child_origin_die
->sect_off
);
12817 std::sort (offsets
.begin (), offsets
.end ());
12818 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12819 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12820 if (offsetp
[-1] == *offsetp
)
12821 complaint (_("Multiple children of DIE %s refer "
12822 "to DIE %s as their abstract origin"),
12823 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12825 offsetp
= offsets
.data ();
12826 origin_child_die
= origin_die
->child
;
12827 while (origin_child_die
&& origin_child_die
->tag
)
12829 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12830 while (offsetp
< offsets_end
12831 && *offsetp
< origin_child_die
->sect_off
)
12833 if (offsetp
>= offsets_end
12834 || *offsetp
> origin_child_die
->sect_off
)
12836 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12837 Check whether we're already processing ORIGIN_CHILD_DIE.
12838 This can happen with mutually referenced abstract_origins.
12840 if (!origin_child_die
->in_process
)
12841 process_die (origin_child_die
, origin_cu
);
12843 origin_child_die
= sibling_die (origin_child_die
);
12845 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12847 if (cu
!= origin_cu
)
12848 compute_delayed_physnames (origin_cu
);
12852 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12854 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12855 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12856 struct context_stack
*newobj
;
12859 struct die_info
*child_die
;
12860 struct attribute
*attr
, *call_line
, *call_file
;
12862 CORE_ADDR baseaddr
;
12863 struct block
*block
;
12864 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12865 std::vector
<struct symbol
*> template_args
;
12866 struct template_symbol
*templ_func
= NULL
;
12870 /* If we do not have call site information, we can't show the
12871 caller of this inlined function. That's too confusing, so
12872 only use the scope for local variables. */
12873 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12874 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12875 if (call_line
== NULL
|| call_file
== NULL
)
12877 read_lexical_block_scope (die
, cu
);
12882 baseaddr
= objfile
->text_section_offset ();
12884 name
= dwarf2_name (die
, cu
);
12886 /* Ignore functions with missing or empty names. These are actually
12887 illegal according to the DWARF standard. */
12890 complaint (_("missing name for subprogram DIE at %s"),
12891 sect_offset_str (die
->sect_off
));
12895 /* Ignore functions with missing or invalid low and high pc attributes. */
12896 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12897 <= PC_BOUNDS_INVALID
)
12899 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12900 if (!attr
|| !DW_UNSND (attr
))
12901 complaint (_("cannot get low and high bounds "
12902 "for subprogram DIE at %s"),
12903 sect_offset_str (die
->sect_off
));
12907 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12908 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12910 /* If we have any template arguments, then we must allocate a
12911 different sort of symbol. */
12912 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12914 if (child_die
->tag
== DW_TAG_template_type_param
12915 || child_die
->tag
== DW_TAG_template_value_param
)
12917 templ_func
= allocate_template_symbol (objfile
);
12918 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12923 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12924 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12925 (struct symbol
*) templ_func
);
12927 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12928 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12931 /* If there is a location expression for DW_AT_frame_base, record
12933 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12934 if (attr
!= nullptr)
12935 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12937 /* If there is a location for the static link, record it. */
12938 newobj
->static_link
= NULL
;
12939 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12940 if (attr
!= nullptr)
12942 newobj
->static_link
12943 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12944 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12945 cu
->per_cu
->addr_type ());
12948 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12950 if (die
->child
!= NULL
)
12952 child_die
= die
->child
;
12953 while (child_die
&& child_die
->tag
)
12955 if (child_die
->tag
== DW_TAG_template_type_param
12956 || child_die
->tag
== DW_TAG_template_value_param
)
12958 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12961 template_args
.push_back (arg
);
12964 process_die (child_die
, cu
);
12965 child_die
= sibling_die (child_die
);
12969 inherit_abstract_dies (die
, cu
);
12971 /* If we have a DW_AT_specification, we might need to import using
12972 directives from the context of the specification DIE. See the
12973 comment in determine_prefix. */
12974 if (cu
->language
== language_cplus
12975 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12977 struct dwarf2_cu
*spec_cu
= cu
;
12978 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12982 child_die
= spec_die
->child
;
12983 while (child_die
&& child_die
->tag
)
12985 if (child_die
->tag
== DW_TAG_imported_module
)
12986 process_die (child_die
, spec_cu
);
12987 child_die
= sibling_die (child_die
);
12990 /* In some cases, GCC generates specification DIEs that
12991 themselves contain DW_AT_specification attributes. */
12992 spec_die
= die_specification (spec_die
, &spec_cu
);
12996 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12997 /* Make a block for the local symbols within. */
12998 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12999 cstk
.static_link
, lowpc
, highpc
);
13001 /* For C++, set the block's scope. */
13002 if ((cu
->language
== language_cplus
13003 || cu
->language
== language_fortran
13004 || cu
->language
== language_d
13005 || cu
->language
== language_rust
)
13006 && cu
->processing_has_namespace_info
)
13007 block_set_scope (block
, determine_prefix (die
, cu
),
13008 &objfile
->objfile_obstack
);
13010 /* If we have address ranges, record them. */
13011 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13013 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13015 /* Attach template arguments to function. */
13016 if (!template_args
.empty ())
13018 gdb_assert (templ_func
!= NULL
);
13020 templ_func
->n_template_arguments
= template_args
.size ();
13021 templ_func
->template_arguments
13022 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13023 templ_func
->n_template_arguments
);
13024 memcpy (templ_func
->template_arguments
,
13025 template_args
.data (),
13026 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13028 /* Make sure that the symtab is set on the new symbols. Even
13029 though they don't appear in this symtab directly, other parts
13030 of gdb assume that symbols do, and this is reasonably
13032 for (symbol
*sym
: template_args
)
13033 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13036 /* In C++, we can have functions nested inside functions (e.g., when
13037 a function declares a class that has methods). This means that
13038 when we finish processing a function scope, we may need to go
13039 back to building a containing block's symbol lists. */
13040 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13041 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13043 /* If we've finished processing a top-level function, subsequent
13044 symbols go in the file symbol list. */
13045 if (cu
->get_builder ()->outermost_context_p ())
13046 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13049 /* Process all the DIES contained within a lexical block scope. Start
13050 a new scope, process the dies, and then close the scope. */
13053 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13055 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13056 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13057 CORE_ADDR lowpc
, highpc
;
13058 struct die_info
*child_die
;
13059 CORE_ADDR baseaddr
;
13061 baseaddr
= objfile
->text_section_offset ();
13063 /* Ignore blocks with missing or invalid low and high pc attributes. */
13064 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13065 as multiple lexical blocks? Handling children in a sane way would
13066 be nasty. Might be easier to properly extend generic blocks to
13067 describe ranges. */
13068 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13070 case PC_BOUNDS_NOT_PRESENT
:
13071 /* DW_TAG_lexical_block has no attributes, process its children as if
13072 there was no wrapping by that DW_TAG_lexical_block.
13073 GCC does no longer produces such DWARF since GCC r224161. */
13074 for (child_die
= die
->child
;
13075 child_die
!= NULL
&& child_die
->tag
;
13076 child_die
= sibling_die (child_die
))
13077 process_die (child_die
, cu
);
13079 case PC_BOUNDS_INVALID
:
13082 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13083 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13085 cu
->get_builder ()->push_context (0, lowpc
);
13086 if (die
->child
!= NULL
)
13088 child_die
= die
->child
;
13089 while (child_die
&& child_die
->tag
)
13091 process_die (child_die
, cu
);
13092 child_die
= sibling_die (child_die
);
13095 inherit_abstract_dies (die
, cu
);
13096 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13098 if (*cu
->get_builder ()->get_local_symbols () != NULL
13099 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13101 struct block
*block
13102 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13103 cstk
.start_addr
, highpc
);
13105 /* Note that recording ranges after traversing children, as we
13106 do here, means that recording a parent's ranges entails
13107 walking across all its children's ranges as they appear in
13108 the address map, which is quadratic behavior.
13110 It would be nicer to record the parent's ranges before
13111 traversing its children, simply overriding whatever you find
13112 there. But since we don't even decide whether to create a
13113 block until after we've traversed its children, that's hard
13115 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13117 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13118 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13121 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13124 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13126 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13127 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13128 CORE_ADDR pc
, baseaddr
;
13129 struct attribute
*attr
;
13130 struct call_site
*call_site
, call_site_local
;
13133 struct die_info
*child_die
;
13135 baseaddr
= objfile
->text_section_offset ();
13137 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13140 /* This was a pre-DWARF-5 GNU extension alias
13141 for DW_AT_call_return_pc. */
13142 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13146 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13147 "DIE %s [in module %s]"),
13148 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13151 pc
= attr
->value_as_address () + baseaddr
;
13152 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13154 if (cu
->call_site_htab
== NULL
)
13155 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13156 NULL
, &objfile
->objfile_obstack
,
13157 hashtab_obstack_allocate
, NULL
);
13158 call_site_local
.pc
= pc
;
13159 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13162 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13163 "DIE %s [in module %s]"),
13164 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13165 objfile_name (objfile
));
13169 /* Count parameters at the caller. */
13172 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13173 child_die
= sibling_die (child_die
))
13175 if (child_die
->tag
!= DW_TAG_call_site_parameter
13176 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13178 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13179 "DW_TAG_call_site child DIE %s [in module %s]"),
13180 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13181 objfile_name (objfile
));
13189 = ((struct call_site
*)
13190 obstack_alloc (&objfile
->objfile_obstack
,
13191 sizeof (*call_site
)
13192 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13194 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13195 call_site
->pc
= pc
;
13197 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13198 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13200 struct die_info
*func_die
;
13202 /* Skip also over DW_TAG_inlined_subroutine. */
13203 for (func_die
= die
->parent
;
13204 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13205 && func_die
->tag
!= DW_TAG_subroutine_type
;
13206 func_die
= func_die
->parent
);
13208 /* DW_AT_call_all_calls is a superset
13209 of DW_AT_call_all_tail_calls. */
13211 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13212 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13213 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13214 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13216 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13217 not complete. But keep CALL_SITE for look ups via call_site_htab,
13218 both the initial caller containing the real return address PC and
13219 the final callee containing the current PC of a chain of tail
13220 calls do not need to have the tail call list complete. But any
13221 function candidate for a virtual tail call frame searched via
13222 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13223 determined unambiguously. */
13227 struct type
*func_type
= NULL
;
13230 func_type
= get_die_type (func_die
, cu
);
13231 if (func_type
!= NULL
)
13233 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13235 /* Enlist this call site to the function. */
13236 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13237 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13240 complaint (_("Cannot find function owning DW_TAG_call_site "
13241 "DIE %s [in module %s]"),
13242 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13246 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13248 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13250 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13253 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13254 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13256 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13257 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13258 /* Keep NULL DWARF_BLOCK. */;
13259 else if (attr
->form_is_block ())
13261 struct dwarf2_locexpr_baton
*dlbaton
;
13263 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13264 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13265 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13266 dlbaton
->per_cu
= cu
->per_cu
;
13268 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13270 else if (attr
->form_is_ref ())
13272 struct dwarf2_cu
*target_cu
= cu
;
13273 struct die_info
*target_die
;
13275 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13276 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13277 if (die_is_declaration (target_die
, target_cu
))
13279 const char *target_physname
;
13281 /* Prefer the mangled name; otherwise compute the demangled one. */
13282 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13283 if (target_physname
== NULL
)
13284 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13285 if (target_physname
== NULL
)
13286 complaint (_("DW_AT_call_target target DIE has invalid "
13287 "physname, for referencing DIE %s [in module %s]"),
13288 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13290 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13296 /* DW_AT_entry_pc should be preferred. */
13297 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13298 <= PC_BOUNDS_INVALID
)
13299 complaint (_("DW_AT_call_target target DIE has invalid "
13300 "low pc, for referencing DIE %s [in module %s]"),
13301 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13304 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13305 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13310 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13311 "block nor reference, for DIE %s [in module %s]"),
13312 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13314 call_site
->per_cu
= cu
->per_cu
;
13316 for (child_die
= die
->child
;
13317 child_die
&& child_die
->tag
;
13318 child_die
= sibling_die (child_die
))
13320 struct call_site_parameter
*parameter
;
13321 struct attribute
*loc
, *origin
;
13323 if (child_die
->tag
!= DW_TAG_call_site_parameter
13324 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13326 /* Already printed the complaint above. */
13330 gdb_assert (call_site
->parameter_count
< nparams
);
13331 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13333 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13334 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13335 register is contained in DW_AT_call_value. */
13337 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13338 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13339 if (origin
== NULL
)
13341 /* This was a pre-DWARF-5 GNU extension alias
13342 for DW_AT_call_parameter. */
13343 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13345 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13347 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13349 sect_offset sect_off
13350 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13351 if (!cu
->header
.offset_in_cu_p (sect_off
))
13353 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13354 binding can be done only inside one CU. Such referenced DIE
13355 therefore cannot be even moved to DW_TAG_partial_unit. */
13356 complaint (_("DW_AT_call_parameter offset is not in CU for "
13357 "DW_TAG_call_site child DIE %s [in module %s]"),
13358 sect_offset_str (child_die
->sect_off
),
13359 objfile_name (objfile
));
13362 parameter
->u
.param_cu_off
13363 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13365 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13367 complaint (_("No DW_FORM_block* DW_AT_location for "
13368 "DW_TAG_call_site child DIE %s [in module %s]"),
13369 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13374 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13375 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13376 if (parameter
->u
.dwarf_reg
!= -1)
13377 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13378 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13379 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13380 ¶meter
->u
.fb_offset
))
13381 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13384 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13385 "for DW_FORM_block* DW_AT_location is supported for "
13386 "DW_TAG_call_site child DIE %s "
13388 sect_offset_str (child_die
->sect_off
),
13389 objfile_name (objfile
));
13394 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13396 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13397 if (attr
== NULL
|| !attr
->form_is_block ())
13399 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13400 "DW_TAG_call_site child DIE %s [in module %s]"),
13401 sect_offset_str (child_die
->sect_off
),
13402 objfile_name (objfile
));
13405 parameter
->value
= DW_BLOCK (attr
)->data
;
13406 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13408 /* Parameters are not pre-cleared by memset above. */
13409 parameter
->data_value
= NULL
;
13410 parameter
->data_value_size
= 0;
13411 call_site
->parameter_count
++;
13413 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13415 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13416 if (attr
!= nullptr)
13418 if (!attr
->form_is_block ())
13419 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13420 "DW_TAG_call_site child DIE %s [in module %s]"),
13421 sect_offset_str (child_die
->sect_off
),
13422 objfile_name (objfile
));
13425 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13426 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13432 /* Helper function for read_variable. If DIE represents a virtual
13433 table, then return the type of the concrete object that is
13434 associated with the virtual table. Otherwise, return NULL. */
13436 static struct type
*
13437 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13439 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13443 /* Find the type DIE. */
13444 struct die_info
*type_die
= NULL
;
13445 struct dwarf2_cu
*type_cu
= cu
;
13447 if (attr
->form_is_ref ())
13448 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13449 if (type_die
== NULL
)
13452 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13454 return die_containing_type (type_die
, type_cu
);
13457 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13460 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13462 struct rust_vtable_symbol
*storage
= NULL
;
13464 if (cu
->language
== language_rust
)
13466 struct type
*containing_type
= rust_containing_type (die
, cu
);
13468 if (containing_type
!= NULL
)
13470 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13472 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13473 initialize_objfile_symbol (storage
);
13474 storage
->concrete_type
= containing_type
;
13475 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13479 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13480 struct attribute
*abstract_origin
13481 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13482 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13483 if (res
== NULL
&& loc
&& abstract_origin
)
13485 /* We have a variable without a name, but with a location and an abstract
13486 origin. This may be a concrete instance of an abstract variable
13487 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13489 struct dwarf2_cu
*origin_cu
= cu
;
13490 struct die_info
*origin_die
13491 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13492 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13493 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13497 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13498 reading .debug_rnglists.
13499 Callback's type should be:
13500 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13501 Return true if the attributes are present and valid, otherwise,
13504 template <typename Callback
>
13506 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13507 Callback
&&callback
)
13509 struct dwarf2_per_objfile
*dwarf2_per_objfile
13510 = cu
->per_cu
->dwarf2_per_objfile
;
13511 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13512 bfd
*obfd
= objfile
->obfd
;
13513 /* Base address selection entry. */
13516 const gdb_byte
*buffer
;
13517 CORE_ADDR baseaddr
;
13518 bool overflow
= false;
13520 found_base
= cu
->base_known
;
13521 base
= cu
->base_address
;
13523 dwarf2_per_objfile
->rnglists
.read (objfile
);
13524 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13526 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13530 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13532 baseaddr
= objfile
->text_section_offset ();
13536 /* Initialize it due to a false compiler warning. */
13537 CORE_ADDR range_beginning
= 0, range_end
= 0;
13538 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13539 + dwarf2_per_objfile
->rnglists
.size
);
13540 unsigned int bytes_read
;
13542 if (buffer
== buf_end
)
13547 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13550 case DW_RLE_end_of_list
:
13552 case DW_RLE_base_address
:
13553 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13558 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13560 buffer
+= bytes_read
;
13562 case DW_RLE_start_length
:
13563 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13568 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13570 buffer
+= bytes_read
;
13571 range_end
= (range_beginning
13572 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13573 buffer
+= bytes_read
;
13574 if (buffer
> buf_end
)
13580 case DW_RLE_offset_pair
:
13581 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13582 buffer
+= bytes_read
;
13583 if (buffer
> buf_end
)
13588 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13589 buffer
+= bytes_read
;
13590 if (buffer
> buf_end
)
13596 case DW_RLE_start_end
:
13597 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13602 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13604 buffer
+= bytes_read
;
13605 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13606 buffer
+= bytes_read
;
13609 complaint (_("Invalid .debug_rnglists data (no base address)"));
13612 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13614 if (rlet
== DW_RLE_base_address
)
13619 /* We have no valid base address for the ranges
13621 complaint (_("Invalid .debug_rnglists data (no base address)"));
13625 if (range_beginning
> range_end
)
13627 /* Inverted range entries are invalid. */
13628 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13632 /* Empty range entries have no effect. */
13633 if (range_beginning
== range_end
)
13636 range_beginning
+= base
;
13639 /* A not-uncommon case of bad debug info.
13640 Don't pollute the addrmap with bad data. */
13641 if (range_beginning
+ baseaddr
== 0
13642 && !dwarf2_per_objfile
->has_section_at_zero
)
13644 complaint (_(".debug_rnglists entry has start address of zero"
13645 " [in module %s]"), objfile_name (objfile
));
13649 callback (range_beginning
, range_end
);
13654 complaint (_("Offset %d is not terminated "
13655 "for DW_AT_ranges attribute"),
13663 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13664 Callback's type should be:
13665 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13666 Return 1 if the attributes are present and valid, otherwise, return 0. */
13668 template <typename Callback
>
13670 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13671 Callback
&&callback
)
13673 struct dwarf2_per_objfile
*dwarf2_per_objfile
13674 = cu
->per_cu
->dwarf2_per_objfile
;
13675 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13676 struct comp_unit_head
*cu_header
= &cu
->header
;
13677 bfd
*obfd
= objfile
->obfd
;
13678 unsigned int addr_size
= cu_header
->addr_size
;
13679 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13680 /* Base address selection entry. */
13683 unsigned int dummy
;
13684 const gdb_byte
*buffer
;
13685 CORE_ADDR baseaddr
;
13687 if (cu_header
->version
>= 5)
13688 return dwarf2_rnglists_process (offset
, cu
, callback
);
13690 found_base
= cu
->base_known
;
13691 base
= cu
->base_address
;
13693 dwarf2_per_objfile
->ranges
.read (objfile
);
13694 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13696 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13700 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13702 baseaddr
= objfile
->text_section_offset ();
13706 CORE_ADDR range_beginning
, range_end
;
13708 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13709 buffer
+= addr_size
;
13710 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13711 buffer
+= addr_size
;
13712 offset
+= 2 * addr_size
;
13714 /* An end of list marker is a pair of zero addresses. */
13715 if (range_beginning
== 0 && range_end
== 0)
13716 /* Found the end of list entry. */
13719 /* Each base address selection entry is a pair of 2 values.
13720 The first is the largest possible address, the second is
13721 the base address. Check for a base address here. */
13722 if ((range_beginning
& mask
) == mask
)
13724 /* If we found the largest possible address, then we already
13725 have the base address in range_end. */
13733 /* We have no valid base address for the ranges
13735 complaint (_("Invalid .debug_ranges data (no base address)"));
13739 if (range_beginning
> range_end
)
13741 /* Inverted range entries are invalid. */
13742 complaint (_("Invalid .debug_ranges data (inverted range)"));
13746 /* Empty range entries have no effect. */
13747 if (range_beginning
== range_end
)
13750 range_beginning
+= base
;
13753 /* A not-uncommon case of bad debug info.
13754 Don't pollute the addrmap with bad data. */
13755 if (range_beginning
+ baseaddr
== 0
13756 && !dwarf2_per_objfile
->has_section_at_zero
)
13758 complaint (_(".debug_ranges entry has start address of zero"
13759 " [in module %s]"), objfile_name (objfile
));
13763 callback (range_beginning
, range_end
);
13769 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13770 Return 1 if the attributes are present and valid, otherwise, return 0.
13771 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13774 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13775 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13776 dwarf2_psymtab
*ranges_pst
)
13778 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13779 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13780 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13783 CORE_ADDR high
= 0;
13786 retval
= dwarf2_ranges_process (offset
, cu
,
13787 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13789 if (ranges_pst
!= NULL
)
13794 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13795 range_beginning
+ baseaddr
)
13797 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13798 range_end
+ baseaddr
)
13800 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13801 lowpc
, highpc
- 1, ranges_pst
);
13804 /* FIXME: This is recording everything as a low-high
13805 segment of consecutive addresses. We should have a
13806 data structure for discontiguous block ranges
13810 low
= range_beginning
;
13816 if (range_beginning
< low
)
13817 low
= range_beginning
;
13818 if (range_end
> high
)
13826 /* If the first entry is an end-of-list marker, the range
13827 describes an empty scope, i.e. no instructions. */
13833 *high_return
= high
;
13837 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13838 definition for the return value. *LOWPC and *HIGHPC are set iff
13839 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13841 static enum pc_bounds_kind
13842 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13843 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13844 dwarf2_psymtab
*pst
)
13846 struct dwarf2_per_objfile
*dwarf2_per_objfile
13847 = cu
->per_cu
->dwarf2_per_objfile
;
13848 struct attribute
*attr
;
13849 struct attribute
*attr_high
;
13851 CORE_ADDR high
= 0;
13852 enum pc_bounds_kind ret
;
13854 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13857 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13858 if (attr
!= nullptr)
13860 low
= attr
->value_as_address ();
13861 high
= attr_high
->value_as_address ();
13862 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13866 /* Found high w/o low attribute. */
13867 return PC_BOUNDS_INVALID
;
13869 /* Found consecutive range of addresses. */
13870 ret
= PC_BOUNDS_HIGH_LOW
;
13874 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13877 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13878 We take advantage of the fact that DW_AT_ranges does not appear
13879 in DW_TAG_compile_unit of DWO files. */
13880 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13881 unsigned int ranges_offset
= (DW_UNSND (attr
)
13882 + (need_ranges_base
13886 /* Value of the DW_AT_ranges attribute is the offset in the
13887 .debug_ranges section. */
13888 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13889 return PC_BOUNDS_INVALID
;
13890 /* Found discontinuous range of addresses. */
13891 ret
= PC_BOUNDS_RANGES
;
13894 return PC_BOUNDS_NOT_PRESENT
;
13897 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13899 return PC_BOUNDS_INVALID
;
13901 /* When using the GNU linker, .gnu.linkonce. sections are used to
13902 eliminate duplicate copies of functions and vtables and such.
13903 The linker will arbitrarily choose one and discard the others.
13904 The AT_*_pc values for such functions refer to local labels in
13905 these sections. If the section from that file was discarded, the
13906 labels are not in the output, so the relocs get a value of 0.
13907 If this is a discarded function, mark the pc bounds as invalid,
13908 so that GDB will ignore it. */
13909 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13910 return PC_BOUNDS_INVALID
;
13918 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13919 its low and high PC addresses. Do nothing if these addresses could not
13920 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13921 and HIGHPC to the high address if greater than HIGHPC. */
13924 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13925 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13926 struct dwarf2_cu
*cu
)
13928 CORE_ADDR low
, high
;
13929 struct die_info
*child
= die
->child
;
13931 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13933 *lowpc
= std::min (*lowpc
, low
);
13934 *highpc
= std::max (*highpc
, high
);
13937 /* If the language does not allow nested subprograms (either inside
13938 subprograms or lexical blocks), we're done. */
13939 if (cu
->language
!= language_ada
)
13942 /* Check all the children of the given DIE. If it contains nested
13943 subprograms, then check their pc bounds. Likewise, we need to
13944 check lexical blocks as well, as they may also contain subprogram
13946 while (child
&& child
->tag
)
13948 if (child
->tag
== DW_TAG_subprogram
13949 || child
->tag
== DW_TAG_lexical_block
)
13950 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13951 child
= sibling_die (child
);
13955 /* Get the low and high pc's represented by the scope DIE, and store
13956 them in *LOWPC and *HIGHPC. If the correct values can't be
13957 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13960 get_scope_pc_bounds (struct die_info
*die
,
13961 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13962 struct dwarf2_cu
*cu
)
13964 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13965 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13966 CORE_ADDR current_low
, current_high
;
13968 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13969 >= PC_BOUNDS_RANGES
)
13971 best_low
= current_low
;
13972 best_high
= current_high
;
13976 struct die_info
*child
= die
->child
;
13978 while (child
&& child
->tag
)
13980 switch (child
->tag
) {
13981 case DW_TAG_subprogram
:
13982 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13984 case DW_TAG_namespace
:
13985 case DW_TAG_module
:
13986 /* FIXME: carlton/2004-01-16: Should we do this for
13987 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13988 that current GCC's always emit the DIEs corresponding
13989 to definitions of methods of classes as children of a
13990 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13991 the DIEs giving the declarations, which could be
13992 anywhere). But I don't see any reason why the
13993 standards says that they have to be there. */
13994 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13996 if (current_low
!= ((CORE_ADDR
) -1))
13998 best_low
= std::min (best_low
, current_low
);
13999 best_high
= std::max (best_high
, current_high
);
14007 child
= sibling_die (child
);
14012 *highpc
= best_high
;
14015 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14019 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14020 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14022 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14023 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14024 struct attribute
*attr
;
14025 struct attribute
*attr_high
;
14027 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14030 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14031 if (attr
!= nullptr)
14033 CORE_ADDR low
= attr
->value_as_address ();
14034 CORE_ADDR high
= attr_high
->value_as_address ();
14036 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14039 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14040 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14041 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14045 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14046 if (attr
!= nullptr)
14048 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14049 We take advantage of the fact that DW_AT_ranges does not appear
14050 in DW_TAG_compile_unit of DWO files. */
14051 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14053 /* The value of the DW_AT_ranges attribute is the offset of the
14054 address range list in the .debug_ranges section. */
14055 unsigned long offset
= (DW_UNSND (attr
)
14056 + (need_ranges_base
? cu
->ranges_base
: 0));
14058 std::vector
<blockrange
> blockvec
;
14059 dwarf2_ranges_process (offset
, cu
,
14060 [&] (CORE_ADDR start
, CORE_ADDR end
)
14064 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14065 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14066 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14067 blockvec
.emplace_back (start
, end
);
14070 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14074 /* Check whether the producer field indicates either of GCC < 4.6, or the
14075 Intel C/C++ compiler, and cache the result in CU. */
14078 check_producer (struct dwarf2_cu
*cu
)
14082 if (cu
->producer
== NULL
)
14084 /* For unknown compilers expect their behavior is DWARF version
14087 GCC started to support .debug_types sections by -gdwarf-4 since
14088 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14089 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14090 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14091 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14093 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14095 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14096 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14098 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14100 cu
->producer_is_icc
= true;
14101 cu
->producer_is_icc_lt_14
= major
< 14;
14103 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14104 cu
->producer_is_codewarrior
= true;
14107 /* For other non-GCC compilers, expect their behavior is DWARF version
14111 cu
->checked_producer
= true;
14114 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14115 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14116 during 4.6.0 experimental. */
14119 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14121 if (!cu
->checked_producer
)
14122 check_producer (cu
);
14124 return cu
->producer_is_gxx_lt_4_6
;
14128 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14129 with incorrect is_stmt attributes. */
14132 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14134 if (!cu
->checked_producer
)
14135 check_producer (cu
);
14137 return cu
->producer_is_codewarrior
;
14140 /* Return the default accessibility type if it is not overridden by
14141 DW_AT_accessibility. */
14143 static enum dwarf_access_attribute
14144 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14146 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14148 /* The default DWARF 2 accessibility for members is public, the default
14149 accessibility for inheritance is private. */
14151 if (die
->tag
!= DW_TAG_inheritance
)
14152 return DW_ACCESS_public
;
14154 return DW_ACCESS_private
;
14158 /* DWARF 3+ defines the default accessibility a different way. The same
14159 rules apply now for DW_TAG_inheritance as for the members and it only
14160 depends on the container kind. */
14162 if (die
->parent
->tag
== DW_TAG_class_type
)
14163 return DW_ACCESS_private
;
14165 return DW_ACCESS_public
;
14169 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14170 offset. If the attribute was not found return 0, otherwise return
14171 1. If it was found but could not properly be handled, set *OFFSET
14175 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14178 struct attribute
*attr
;
14180 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14185 /* Note that we do not check for a section offset first here.
14186 This is because DW_AT_data_member_location is new in DWARF 4,
14187 so if we see it, we can assume that a constant form is really
14188 a constant and not a section offset. */
14189 if (attr
->form_is_constant ())
14190 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14191 else if (attr
->form_is_section_offset ())
14192 dwarf2_complex_location_expr_complaint ();
14193 else if (attr
->form_is_block ())
14194 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14196 dwarf2_complex_location_expr_complaint ();
14204 /* Add an aggregate field to the field list. */
14207 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14208 struct dwarf2_cu
*cu
)
14210 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14211 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14212 struct nextfield
*new_field
;
14213 struct attribute
*attr
;
14215 const char *fieldname
= "";
14217 if (die
->tag
== DW_TAG_inheritance
)
14219 fip
->baseclasses
.emplace_back ();
14220 new_field
= &fip
->baseclasses
.back ();
14224 fip
->fields
.emplace_back ();
14225 new_field
= &fip
->fields
.back ();
14228 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14229 if (attr
!= nullptr)
14230 new_field
->accessibility
= DW_UNSND (attr
);
14232 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14233 if (new_field
->accessibility
!= DW_ACCESS_public
)
14234 fip
->non_public_fields
= 1;
14236 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14237 if (attr
!= nullptr)
14238 new_field
->virtuality
= DW_UNSND (attr
);
14240 new_field
->virtuality
= DW_VIRTUALITY_none
;
14242 fp
= &new_field
->field
;
14244 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14248 /* Data member other than a C++ static data member. */
14250 /* Get type of field. */
14251 fp
->type
= die_type (die
, cu
);
14253 SET_FIELD_BITPOS (*fp
, 0);
14255 /* Get bit size of field (zero if none). */
14256 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14257 if (attr
!= nullptr)
14259 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14263 FIELD_BITSIZE (*fp
) = 0;
14266 /* Get bit offset of field. */
14267 if (handle_data_member_location (die
, cu
, &offset
))
14268 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14269 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14270 if (attr
!= nullptr)
14272 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14274 /* For big endian bits, the DW_AT_bit_offset gives the
14275 additional bit offset from the MSB of the containing
14276 anonymous object to the MSB of the field. We don't
14277 have to do anything special since we don't need to
14278 know the size of the anonymous object. */
14279 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14283 /* For little endian bits, compute the bit offset to the
14284 MSB of the anonymous object, subtract off the number of
14285 bits from the MSB of the field to the MSB of the
14286 object, and then subtract off the number of bits of
14287 the field itself. The result is the bit offset of
14288 the LSB of the field. */
14289 int anonymous_size
;
14290 int bit_offset
= DW_UNSND (attr
);
14292 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14293 if (attr
!= nullptr)
14295 /* The size of the anonymous object containing
14296 the bit field is explicit, so use the
14297 indicated size (in bytes). */
14298 anonymous_size
= DW_UNSND (attr
);
14302 /* The size of the anonymous object containing
14303 the bit field must be inferred from the type
14304 attribute of the data member containing the
14306 anonymous_size
= TYPE_LENGTH (fp
->type
);
14308 SET_FIELD_BITPOS (*fp
,
14309 (FIELD_BITPOS (*fp
)
14310 + anonymous_size
* bits_per_byte
14311 - bit_offset
- FIELD_BITSIZE (*fp
)));
14314 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14316 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14317 + dwarf2_get_attr_constant_value (attr
, 0)));
14319 /* Get name of field. */
14320 fieldname
= dwarf2_name (die
, cu
);
14321 if (fieldname
== NULL
)
14324 /* The name is already allocated along with this objfile, so we don't
14325 need to duplicate it for the type. */
14326 fp
->name
= fieldname
;
14328 /* Change accessibility for artificial fields (e.g. virtual table
14329 pointer or virtual base class pointer) to private. */
14330 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14332 FIELD_ARTIFICIAL (*fp
) = 1;
14333 new_field
->accessibility
= DW_ACCESS_private
;
14334 fip
->non_public_fields
= 1;
14337 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14339 /* C++ static member. */
14341 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14342 is a declaration, but all versions of G++ as of this writing
14343 (so through at least 3.2.1) incorrectly generate
14344 DW_TAG_variable tags. */
14346 const char *physname
;
14348 /* Get name of field. */
14349 fieldname
= dwarf2_name (die
, cu
);
14350 if (fieldname
== NULL
)
14353 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14355 /* Only create a symbol if this is an external value.
14356 new_symbol checks this and puts the value in the global symbol
14357 table, which we want. If it is not external, new_symbol
14358 will try to put the value in cu->list_in_scope which is wrong. */
14359 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14361 /* A static const member, not much different than an enum as far as
14362 we're concerned, except that we can support more types. */
14363 new_symbol (die
, NULL
, cu
);
14366 /* Get physical name. */
14367 physname
= dwarf2_physname (fieldname
, die
, cu
);
14369 /* The name is already allocated along with this objfile, so we don't
14370 need to duplicate it for the type. */
14371 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14372 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14373 FIELD_NAME (*fp
) = fieldname
;
14375 else if (die
->tag
== DW_TAG_inheritance
)
14379 /* C++ base class field. */
14380 if (handle_data_member_location (die
, cu
, &offset
))
14381 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14382 FIELD_BITSIZE (*fp
) = 0;
14383 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14384 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14386 else if (die
->tag
== DW_TAG_variant_part
)
14388 /* process_structure_scope will treat this DIE as a union. */
14389 process_structure_scope (die
, cu
);
14391 /* The variant part is relative to the start of the enclosing
14393 SET_FIELD_BITPOS (*fp
, 0);
14394 fp
->type
= get_die_type (die
, cu
);
14395 fp
->artificial
= 1;
14396 fp
->name
= "<<variant>>";
14398 /* Normally a DW_TAG_variant_part won't have a size, but our
14399 representation requires one, so set it to the maximum of the
14400 child sizes, being sure to account for the offset at which
14401 each child is seen. */
14402 if (TYPE_LENGTH (fp
->type
) == 0)
14405 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14407 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14408 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14412 TYPE_LENGTH (fp
->type
) = max
;
14416 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14419 /* Can the type given by DIE define another type? */
14422 type_can_define_types (const struct die_info
*die
)
14426 case DW_TAG_typedef
:
14427 case DW_TAG_class_type
:
14428 case DW_TAG_structure_type
:
14429 case DW_TAG_union_type
:
14430 case DW_TAG_enumeration_type
:
14438 /* Add a type definition defined in the scope of the FIP's class. */
14441 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14442 struct dwarf2_cu
*cu
)
14444 struct decl_field fp
;
14445 memset (&fp
, 0, sizeof (fp
));
14447 gdb_assert (type_can_define_types (die
));
14449 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14450 fp
.name
= dwarf2_name (die
, cu
);
14451 fp
.type
= read_type_die (die
, cu
);
14453 /* Save accessibility. */
14454 enum dwarf_access_attribute accessibility
;
14455 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14457 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14459 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14460 switch (accessibility
)
14462 case DW_ACCESS_public
:
14463 /* The assumed value if neither private nor protected. */
14465 case DW_ACCESS_private
:
14468 case DW_ACCESS_protected
:
14469 fp
.is_protected
= 1;
14472 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14475 if (die
->tag
== DW_TAG_typedef
)
14476 fip
->typedef_field_list
.push_back (fp
);
14478 fip
->nested_types_list
.push_back (fp
);
14481 /* Create the vector of fields, and attach it to the type. */
14484 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14485 struct dwarf2_cu
*cu
)
14487 int nfields
= fip
->nfields ();
14489 /* Record the field count, allocate space for the array of fields,
14490 and create blank accessibility bitfields if necessary. */
14491 TYPE_NFIELDS (type
) = nfields
;
14492 TYPE_FIELDS (type
) = (struct field
*)
14493 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14495 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14497 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14499 TYPE_FIELD_PRIVATE_BITS (type
) =
14500 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14501 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14503 TYPE_FIELD_PROTECTED_BITS (type
) =
14504 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14505 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14507 TYPE_FIELD_IGNORE_BITS (type
) =
14508 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14509 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14512 /* If the type has baseclasses, allocate and clear a bit vector for
14513 TYPE_FIELD_VIRTUAL_BITS. */
14514 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14516 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14517 unsigned char *pointer
;
14519 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14520 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14521 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14522 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14523 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14526 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14528 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14530 for (int index
= 0; index
< nfields
; ++index
)
14532 struct nextfield
&field
= fip
->fields
[index
];
14534 if (field
.variant
.is_discriminant
)
14535 di
->discriminant_index
= index
;
14536 else if (field
.variant
.default_branch
)
14537 di
->default_index
= index
;
14539 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14543 /* Copy the saved-up fields into the field vector. */
14544 for (int i
= 0; i
< nfields
; ++i
)
14546 struct nextfield
&field
14547 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14548 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14550 TYPE_FIELD (type
, i
) = field
.field
;
14551 switch (field
.accessibility
)
14553 case DW_ACCESS_private
:
14554 if (cu
->language
!= language_ada
)
14555 SET_TYPE_FIELD_PRIVATE (type
, i
);
14558 case DW_ACCESS_protected
:
14559 if (cu
->language
!= language_ada
)
14560 SET_TYPE_FIELD_PROTECTED (type
, i
);
14563 case DW_ACCESS_public
:
14567 /* Unknown accessibility. Complain and treat it as public. */
14569 complaint (_("unsupported accessibility %d"),
14570 field
.accessibility
);
14574 if (i
< fip
->baseclasses
.size ())
14576 switch (field
.virtuality
)
14578 case DW_VIRTUALITY_virtual
:
14579 case DW_VIRTUALITY_pure_virtual
:
14580 if (cu
->language
== language_ada
)
14581 error (_("unexpected virtuality in component of Ada type"));
14582 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14589 /* Return true if this member function is a constructor, false
14593 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14595 const char *fieldname
;
14596 const char *type_name
;
14599 if (die
->parent
== NULL
)
14602 if (die
->parent
->tag
!= DW_TAG_structure_type
14603 && die
->parent
->tag
!= DW_TAG_union_type
14604 && die
->parent
->tag
!= DW_TAG_class_type
)
14607 fieldname
= dwarf2_name (die
, cu
);
14608 type_name
= dwarf2_name (die
->parent
, cu
);
14609 if (fieldname
== NULL
|| type_name
== NULL
)
14612 len
= strlen (fieldname
);
14613 return (strncmp (fieldname
, type_name
, len
) == 0
14614 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14617 /* Check if the given VALUE is a recognized enum
14618 dwarf_defaulted_attribute constant according to DWARF5 spec,
14622 is_valid_DW_AT_defaulted (ULONGEST value
)
14626 case DW_DEFAULTED_no
:
14627 case DW_DEFAULTED_in_class
:
14628 case DW_DEFAULTED_out_of_class
:
14632 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14636 /* Add a member function to the proper fieldlist. */
14639 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14640 struct type
*type
, struct dwarf2_cu
*cu
)
14642 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14643 struct attribute
*attr
;
14645 struct fnfieldlist
*flp
= nullptr;
14646 struct fn_field
*fnp
;
14647 const char *fieldname
;
14648 struct type
*this_type
;
14649 enum dwarf_access_attribute accessibility
;
14651 if (cu
->language
== language_ada
)
14652 error (_("unexpected member function in Ada type"));
14654 /* Get name of member function. */
14655 fieldname
= dwarf2_name (die
, cu
);
14656 if (fieldname
== NULL
)
14659 /* Look up member function name in fieldlist. */
14660 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14662 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14664 flp
= &fip
->fnfieldlists
[i
];
14669 /* Create a new fnfieldlist if necessary. */
14670 if (flp
== nullptr)
14672 fip
->fnfieldlists
.emplace_back ();
14673 flp
= &fip
->fnfieldlists
.back ();
14674 flp
->name
= fieldname
;
14675 i
= fip
->fnfieldlists
.size () - 1;
14678 /* Create a new member function field and add it to the vector of
14680 flp
->fnfields
.emplace_back ();
14681 fnp
= &flp
->fnfields
.back ();
14683 /* Delay processing of the physname until later. */
14684 if (cu
->language
== language_cplus
)
14685 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14689 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14690 fnp
->physname
= physname
? physname
: "";
14693 fnp
->type
= alloc_type (objfile
);
14694 this_type
= read_type_die (die
, cu
);
14695 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14697 int nparams
= TYPE_NFIELDS (this_type
);
14699 /* TYPE is the domain of this method, and THIS_TYPE is the type
14700 of the method itself (TYPE_CODE_METHOD). */
14701 smash_to_method_type (fnp
->type
, type
,
14702 TYPE_TARGET_TYPE (this_type
),
14703 TYPE_FIELDS (this_type
),
14704 TYPE_NFIELDS (this_type
),
14705 TYPE_VARARGS (this_type
));
14707 /* Handle static member functions.
14708 Dwarf2 has no clean way to discern C++ static and non-static
14709 member functions. G++ helps GDB by marking the first
14710 parameter for non-static member functions (which is the this
14711 pointer) as artificial. We obtain this information from
14712 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14713 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14714 fnp
->voffset
= VOFFSET_STATIC
;
14717 complaint (_("member function type missing for '%s'"),
14718 dwarf2_full_name (fieldname
, die
, cu
));
14720 /* Get fcontext from DW_AT_containing_type if present. */
14721 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14722 fnp
->fcontext
= die_containing_type (die
, cu
);
14724 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14725 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14727 /* Get accessibility. */
14728 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14729 if (attr
!= nullptr)
14730 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14732 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14733 switch (accessibility
)
14735 case DW_ACCESS_private
:
14736 fnp
->is_private
= 1;
14738 case DW_ACCESS_protected
:
14739 fnp
->is_protected
= 1;
14743 /* Check for artificial methods. */
14744 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14745 if (attr
&& DW_UNSND (attr
) != 0)
14746 fnp
->is_artificial
= 1;
14748 /* Check for defaulted methods. */
14749 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14750 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14751 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14753 /* Check for deleted methods. */
14754 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14755 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14756 fnp
->is_deleted
= 1;
14758 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14760 /* Get index in virtual function table if it is a virtual member
14761 function. For older versions of GCC, this is an offset in the
14762 appropriate virtual table, as specified by DW_AT_containing_type.
14763 For everyone else, it is an expression to be evaluated relative
14764 to the object address. */
14766 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14767 if (attr
!= nullptr)
14769 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14771 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14773 /* Old-style GCC. */
14774 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14776 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14777 || (DW_BLOCK (attr
)->size
> 1
14778 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14779 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14781 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14782 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14783 dwarf2_complex_location_expr_complaint ();
14785 fnp
->voffset
/= cu
->header
.addr_size
;
14789 dwarf2_complex_location_expr_complaint ();
14791 if (!fnp
->fcontext
)
14793 /* If there is no `this' field and no DW_AT_containing_type,
14794 we cannot actually find a base class context for the
14796 if (TYPE_NFIELDS (this_type
) == 0
14797 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14799 complaint (_("cannot determine context for virtual member "
14800 "function \"%s\" (offset %s)"),
14801 fieldname
, sect_offset_str (die
->sect_off
));
14806 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14810 else if (attr
->form_is_section_offset ())
14812 dwarf2_complex_location_expr_complaint ();
14816 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14822 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14823 if (attr
&& DW_UNSND (attr
))
14825 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14826 complaint (_("Member function \"%s\" (offset %s) is virtual "
14827 "but the vtable offset is not specified"),
14828 fieldname
, sect_offset_str (die
->sect_off
));
14829 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14830 TYPE_CPLUS_DYNAMIC (type
) = 1;
14835 /* Create the vector of member function fields, and attach it to the type. */
14838 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14839 struct dwarf2_cu
*cu
)
14841 if (cu
->language
== language_ada
)
14842 error (_("unexpected member functions in Ada type"));
14844 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14845 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14847 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14849 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14851 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14852 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14854 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14855 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14856 fn_flp
->fn_fields
= (struct fn_field
*)
14857 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14859 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14860 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14863 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14866 /* Returns non-zero if NAME is the name of a vtable member in CU's
14867 language, zero otherwise. */
14869 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14871 static const char vptr
[] = "_vptr";
14873 /* Look for the C++ form of the vtable. */
14874 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14880 /* GCC outputs unnamed structures that are really pointers to member
14881 functions, with the ABI-specified layout. If TYPE describes
14882 such a structure, smash it into a member function type.
14884 GCC shouldn't do this; it should just output pointer to member DIEs.
14885 This is GCC PR debug/28767. */
14888 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14890 struct type
*pfn_type
, *self_type
, *new_type
;
14892 /* Check for a structure with no name and two children. */
14893 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14896 /* Check for __pfn and __delta members. */
14897 if (TYPE_FIELD_NAME (type
, 0) == NULL
14898 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14899 || TYPE_FIELD_NAME (type
, 1) == NULL
14900 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14903 /* Find the type of the method. */
14904 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14905 if (pfn_type
== NULL
14906 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14907 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14910 /* Look for the "this" argument. */
14911 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14912 if (TYPE_NFIELDS (pfn_type
) == 0
14913 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14914 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14917 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14918 new_type
= alloc_type (objfile
);
14919 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14920 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14921 TYPE_VARARGS (pfn_type
));
14922 smash_to_methodptr_type (type
, new_type
);
14925 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14926 appropriate error checking and issuing complaints if there is a
14930 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14932 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14934 if (attr
== nullptr)
14937 if (!attr
->form_is_constant ())
14939 complaint (_("DW_AT_alignment must have constant form"
14940 " - DIE at %s [in module %s]"),
14941 sect_offset_str (die
->sect_off
),
14942 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14947 if (attr
->form
== DW_FORM_sdata
)
14949 LONGEST val
= DW_SND (attr
);
14952 complaint (_("DW_AT_alignment value must not be negative"
14953 " - DIE at %s [in module %s]"),
14954 sect_offset_str (die
->sect_off
),
14955 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14961 align
= DW_UNSND (attr
);
14965 complaint (_("DW_AT_alignment value must not be zero"
14966 " - DIE at %s [in module %s]"),
14967 sect_offset_str (die
->sect_off
),
14968 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14971 if ((align
& (align
- 1)) != 0)
14973 complaint (_("DW_AT_alignment value must be a power of 2"
14974 " - DIE at %s [in module %s]"),
14975 sect_offset_str (die
->sect_off
),
14976 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14983 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14984 the alignment for TYPE. */
14987 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14990 if (!set_type_align (type
, get_alignment (cu
, die
)))
14991 complaint (_("DW_AT_alignment value too large"
14992 " - DIE at %s [in module %s]"),
14993 sect_offset_str (die
->sect_off
),
14994 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14997 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14998 constant for a type, according to DWARF5 spec, Table 5.5. */
15001 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15006 case DW_CC_pass_by_reference
:
15007 case DW_CC_pass_by_value
:
15011 complaint (_("unrecognized DW_AT_calling_convention value "
15012 "(%s) for a type"), pulongest (value
));
15017 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15018 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15019 also according to GNU-specific values (see include/dwarf2.h). */
15022 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15027 case DW_CC_program
:
15031 case DW_CC_GNU_renesas_sh
:
15032 case DW_CC_GNU_borland_fastcall_i386
:
15033 case DW_CC_GDB_IBM_OpenCL
:
15037 complaint (_("unrecognized DW_AT_calling_convention value "
15038 "(%s) for a subroutine"), pulongest (value
));
15043 /* Called when we find the DIE that starts a structure or union scope
15044 (definition) to create a type for the structure or union. Fill in
15045 the type's name and general properties; the members will not be
15046 processed until process_structure_scope. A symbol table entry for
15047 the type will also not be done until process_structure_scope (assuming
15048 the type has a name).
15050 NOTE: we need to call these functions regardless of whether or not the
15051 DIE has a DW_AT_name attribute, since it might be an anonymous
15052 structure or union. This gets the type entered into our set of
15053 user defined types. */
15055 static struct type
*
15056 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15058 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15060 struct attribute
*attr
;
15063 /* If the definition of this type lives in .debug_types, read that type.
15064 Don't follow DW_AT_specification though, that will take us back up
15065 the chain and we want to go down. */
15066 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15067 if (attr
!= nullptr)
15069 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15071 /* The type's CU may not be the same as CU.
15072 Ensure TYPE is recorded with CU in die_type_hash. */
15073 return set_die_type (die
, type
, cu
);
15076 type
= alloc_type (objfile
);
15077 INIT_CPLUS_SPECIFIC (type
);
15079 name
= dwarf2_name (die
, cu
);
15082 if (cu
->language
== language_cplus
15083 || cu
->language
== language_d
15084 || cu
->language
== language_rust
)
15086 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15088 /* dwarf2_full_name might have already finished building the DIE's
15089 type. If so, there is no need to continue. */
15090 if (get_die_type (die
, cu
) != NULL
)
15091 return get_die_type (die
, cu
);
15093 TYPE_NAME (type
) = full_name
;
15097 /* The name is already allocated along with this objfile, so
15098 we don't need to duplicate it for the type. */
15099 TYPE_NAME (type
) = name
;
15103 if (die
->tag
== DW_TAG_structure_type
)
15105 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15107 else if (die
->tag
== DW_TAG_union_type
)
15109 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15111 else if (die
->tag
== DW_TAG_variant_part
)
15113 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15114 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15118 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15121 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15122 TYPE_DECLARED_CLASS (type
) = 1;
15124 /* Store the calling convention in the type if it's available in
15125 the die. Otherwise the calling convention remains set to
15126 the default value DW_CC_normal. */
15127 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15128 if (attr
!= nullptr
15129 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15131 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15132 TYPE_CPLUS_CALLING_CONVENTION (type
)
15133 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15136 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15137 if (attr
!= nullptr)
15139 if (attr
->form_is_constant ())
15140 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15143 /* For the moment, dynamic type sizes are not supported
15144 by GDB's struct type. The actual size is determined
15145 on-demand when resolving the type of a given object,
15146 so set the type's length to zero for now. Otherwise,
15147 we record an expression as the length, and that expression
15148 could lead to a very large value, which could eventually
15149 lead to us trying to allocate that much memory when creating
15150 a value of that type. */
15151 TYPE_LENGTH (type
) = 0;
15156 TYPE_LENGTH (type
) = 0;
15159 maybe_set_alignment (cu
, die
, type
);
15161 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15163 /* ICC<14 does not output the required DW_AT_declaration on
15164 incomplete types, but gives them a size of zero. */
15165 TYPE_STUB (type
) = 1;
15168 TYPE_STUB_SUPPORTED (type
) = 1;
15170 if (die_is_declaration (die
, cu
))
15171 TYPE_STUB (type
) = 1;
15172 else if (attr
== NULL
&& die
->child
== NULL
15173 && producer_is_realview (cu
->producer
))
15174 /* RealView does not output the required DW_AT_declaration
15175 on incomplete types. */
15176 TYPE_STUB (type
) = 1;
15178 /* We need to add the type field to the die immediately so we don't
15179 infinitely recurse when dealing with pointers to the structure
15180 type within the structure itself. */
15181 set_die_type (die
, type
, cu
);
15183 /* set_die_type should be already done. */
15184 set_descriptive_type (type
, die
, cu
);
15189 /* A helper for process_structure_scope that handles a single member
15193 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15194 struct field_info
*fi
,
15195 std::vector
<struct symbol
*> *template_args
,
15196 struct dwarf2_cu
*cu
)
15198 if (child_die
->tag
== DW_TAG_member
15199 || child_die
->tag
== DW_TAG_variable
15200 || child_die
->tag
== DW_TAG_variant_part
)
15202 /* NOTE: carlton/2002-11-05: A C++ static data member
15203 should be a DW_TAG_member that is a declaration, but
15204 all versions of G++ as of this writing (so through at
15205 least 3.2.1) incorrectly generate DW_TAG_variable
15206 tags for them instead. */
15207 dwarf2_add_field (fi
, child_die
, cu
);
15209 else if (child_die
->tag
== DW_TAG_subprogram
)
15211 /* Rust doesn't have member functions in the C++ sense.
15212 However, it does emit ordinary functions as children
15213 of a struct DIE. */
15214 if (cu
->language
== language_rust
)
15215 read_func_scope (child_die
, cu
);
15218 /* C++ member function. */
15219 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15222 else if (child_die
->tag
== DW_TAG_inheritance
)
15224 /* C++ base class field. */
15225 dwarf2_add_field (fi
, child_die
, cu
);
15227 else if (type_can_define_types (child_die
))
15228 dwarf2_add_type_defn (fi
, child_die
, cu
);
15229 else if (child_die
->tag
== DW_TAG_template_type_param
15230 || child_die
->tag
== DW_TAG_template_value_param
)
15232 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15235 template_args
->push_back (arg
);
15237 else if (child_die
->tag
== DW_TAG_variant
)
15239 /* In a variant we want to get the discriminant and also add a
15240 field for our sole member child. */
15241 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15243 for (die_info
*variant_child
= child_die
->child
;
15244 variant_child
!= NULL
;
15245 variant_child
= sibling_die (variant_child
))
15247 if (variant_child
->tag
== DW_TAG_member
)
15249 handle_struct_member_die (variant_child
, type
, fi
,
15250 template_args
, cu
);
15251 /* Only handle the one. */
15256 /* We don't handle this but we might as well report it if we see
15258 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15259 complaint (_("DW_AT_discr_list is not supported yet"
15260 " - DIE at %s [in module %s]"),
15261 sect_offset_str (child_die
->sect_off
),
15262 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15264 /* The first field was just added, so we can stash the
15265 discriminant there. */
15266 gdb_assert (!fi
->fields
.empty ());
15268 fi
->fields
.back ().variant
.default_branch
= true;
15270 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15274 /* Finish creating a structure or union type, including filling in
15275 its members and creating a symbol for it. */
15278 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15280 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15281 struct die_info
*child_die
;
15284 type
= get_die_type (die
, cu
);
15286 type
= read_structure_type (die
, cu
);
15288 /* When reading a DW_TAG_variant_part, we need to notice when we
15289 read the discriminant member, so we can record it later in the
15290 discriminant_info. */
15291 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15292 sect_offset discr_offset
{};
15293 bool has_template_parameters
= false;
15295 if (is_variant_part
)
15297 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15300 /* Maybe it's a univariant form, an extension we support.
15301 In this case arrange not to check the offset. */
15302 is_variant_part
= false;
15304 else if (discr
->form_is_ref ())
15306 struct dwarf2_cu
*target_cu
= cu
;
15307 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15309 discr_offset
= target_die
->sect_off
;
15313 complaint (_("DW_AT_discr does not have DIE reference form"
15314 " - DIE at %s [in module %s]"),
15315 sect_offset_str (die
->sect_off
),
15316 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15317 is_variant_part
= false;
15321 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15323 struct field_info fi
;
15324 std::vector
<struct symbol
*> template_args
;
15326 child_die
= die
->child
;
15328 while (child_die
&& child_die
->tag
)
15330 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15332 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15333 fi
.fields
.back ().variant
.is_discriminant
= true;
15335 child_die
= sibling_die (child_die
);
15338 /* Attach template arguments to type. */
15339 if (!template_args
.empty ())
15341 has_template_parameters
= true;
15342 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15343 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15344 TYPE_TEMPLATE_ARGUMENTS (type
)
15345 = XOBNEWVEC (&objfile
->objfile_obstack
,
15347 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15348 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15349 template_args
.data (),
15350 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15351 * sizeof (struct symbol
*)));
15354 /* Attach fields and member functions to the type. */
15355 if (fi
.nfields () > 0)
15356 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15357 if (!fi
.fnfieldlists
.empty ())
15359 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15361 /* Get the type which refers to the base class (possibly this
15362 class itself) which contains the vtable pointer for the current
15363 class from the DW_AT_containing_type attribute. This use of
15364 DW_AT_containing_type is a GNU extension. */
15366 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15368 struct type
*t
= die_containing_type (die
, cu
);
15370 set_type_vptr_basetype (type
, t
);
15375 /* Our own class provides vtbl ptr. */
15376 for (i
= TYPE_NFIELDS (t
) - 1;
15377 i
>= TYPE_N_BASECLASSES (t
);
15380 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15382 if (is_vtable_name (fieldname
, cu
))
15384 set_type_vptr_fieldno (type
, i
);
15389 /* Complain if virtual function table field not found. */
15390 if (i
< TYPE_N_BASECLASSES (t
))
15391 complaint (_("virtual function table pointer "
15392 "not found when defining class '%s'"),
15393 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15397 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15400 else if (cu
->producer
15401 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15403 /* The IBM XLC compiler does not provide direct indication
15404 of the containing type, but the vtable pointer is
15405 always named __vfp. */
15409 for (i
= TYPE_NFIELDS (type
) - 1;
15410 i
>= TYPE_N_BASECLASSES (type
);
15413 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15415 set_type_vptr_fieldno (type
, i
);
15416 set_type_vptr_basetype (type
, type
);
15423 /* Copy fi.typedef_field_list linked list elements content into the
15424 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15425 if (!fi
.typedef_field_list
.empty ())
15427 int count
= fi
.typedef_field_list
.size ();
15429 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15430 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15431 = ((struct decl_field
*)
15433 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15434 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15436 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15437 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15440 /* Copy fi.nested_types_list linked list elements content into the
15441 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15442 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15444 int count
= fi
.nested_types_list
.size ();
15446 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15447 TYPE_NESTED_TYPES_ARRAY (type
)
15448 = ((struct decl_field
*)
15449 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15450 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15452 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15453 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15457 quirk_gcc_member_function_pointer (type
, objfile
);
15458 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15459 cu
->rust_unions
.push_back (type
);
15461 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15462 snapshots) has been known to create a die giving a declaration
15463 for a class that has, as a child, a die giving a definition for a
15464 nested class. So we have to process our children even if the
15465 current die is a declaration. Normally, of course, a declaration
15466 won't have any children at all. */
15468 child_die
= die
->child
;
15470 while (child_die
!= NULL
&& child_die
->tag
)
15472 if (child_die
->tag
== DW_TAG_member
15473 || child_die
->tag
== DW_TAG_variable
15474 || child_die
->tag
== DW_TAG_inheritance
15475 || child_die
->tag
== DW_TAG_template_value_param
15476 || child_die
->tag
== DW_TAG_template_type_param
)
15481 process_die (child_die
, cu
);
15483 child_die
= sibling_die (child_die
);
15486 /* Do not consider external references. According to the DWARF standard,
15487 these DIEs are identified by the fact that they have no byte_size
15488 attribute, and a declaration attribute. */
15489 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15490 || !die_is_declaration (die
, cu
))
15492 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15494 if (has_template_parameters
)
15496 struct symtab
*symtab
;
15497 if (sym
!= nullptr)
15498 symtab
= symbol_symtab (sym
);
15499 else if (cu
->line_header
!= nullptr)
15501 /* Any related symtab will do. */
15503 = cu
->line_header
->file_names ()[0].symtab
;
15508 complaint (_("could not find suitable "
15509 "symtab for template parameter"
15510 " - DIE at %s [in module %s]"),
15511 sect_offset_str (die
->sect_off
),
15512 objfile_name (objfile
));
15515 if (symtab
!= nullptr)
15517 /* Make sure that the symtab is set on the new symbols.
15518 Even though they don't appear in this symtab directly,
15519 other parts of gdb assume that symbols do, and this is
15520 reasonably true. */
15521 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15522 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15528 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15529 update TYPE using some information only available in DIE's children. */
15532 update_enumeration_type_from_children (struct die_info
*die
,
15534 struct dwarf2_cu
*cu
)
15536 struct die_info
*child_die
;
15537 int unsigned_enum
= 1;
15540 auto_obstack obstack
;
15542 for (child_die
= die
->child
;
15543 child_die
!= NULL
&& child_die
->tag
;
15544 child_die
= sibling_die (child_die
))
15546 struct attribute
*attr
;
15548 const gdb_byte
*bytes
;
15549 struct dwarf2_locexpr_baton
*baton
;
15552 if (child_die
->tag
!= DW_TAG_enumerator
)
15555 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15559 name
= dwarf2_name (child_die
, cu
);
15561 name
= "<anonymous enumerator>";
15563 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15564 &value
, &bytes
, &baton
);
15572 if (count_one_bits_ll (value
) >= 2)
15576 /* If we already know that the enum type is neither unsigned, nor
15577 a flag type, no need to look at the rest of the enumerates. */
15578 if (!unsigned_enum
&& !flag_enum
)
15583 TYPE_UNSIGNED (type
) = 1;
15585 TYPE_FLAG_ENUM (type
) = 1;
15588 /* Given a DW_AT_enumeration_type die, set its type. We do not
15589 complete the type's fields yet, or create any symbols. */
15591 static struct type
*
15592 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15594 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15596 struct attribute
*attr
;
15599 /* If the definition of this type lives in .debug_types, read that type.
15600 Don't follow DW_AT_specification though, that will take us back up
15601 the chain and we want to go down. */
15602 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15603 if (attr
!= nullptr)
15605 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15607 /* The type's CU may not be the same as CU.
15608 Ensure TYPE is recorded with CU in die_type_hash. */
15609 return set_die_type (die
, type
, cu
);
15612 type
= alloc_type (objfile
);
15614 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15615 name
= dwarf2_full_name (NULL
, die
, cu
);
15617 TYPE_NAME (type
) = name
;
15619 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15622 struct type
*underlying_type
= die_type (die
, cu
);
15624 TYPE_TARGET_TYPE (type
) = underlying_type
;
15627 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15628 if (attr
!= nullptr)
15630 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15634 TYPE_LENGTH (type
) = 0;
15637 maybe_set_alignment (cu
, die
, type
);
15639 /* The enumeration DIE can be incomplete. In Ada, any type can be
15640 declared as private in the package spec, and then defined only
15641 inside the package body. Such types are known as Taft Amendment
15642 Types. When another package uses such a type, an incomplete DIE
15643 may be generated by the compiler. */
15644 if (die_is_declaration (die
, cu
))
15645 TYPE_STUB (type
) = 1;
15647 /* Finish the creation of this type by using the enum's children.
15648 We must call this even when the underlying type has been provided
15649 so that we can determine if we're looking at a "flag" enum. */
15650 update_enumeration_type_from_children (die
, type
, cu
);
15652 /* If this type has an underlying type that is not a stub, then we
15653 may use its attributes. We always use the "unsigned" attribute
15654 in this situation, because ordinarily we guess whether the type
15655 is unsigned -- but the guess can be wrong and the underlying type
15656 can tell us the reality. However, we defer to a local size
15657 attribute if one exists, because this lets the compiler override
15658 the underlying type if needed. */
15659 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15661 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15662 if (TYPE_LENGTH (type
) == 0)
15663 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15664 if (TYPE_RAW_ALIGN (type
) == 0
15665 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15666 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15669 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15671 return set_die_type (die
, type
, cu
);
15674 /* Given a pointer to a die which begins an enumeration, process all
15675 the dies that define the members of the enumeration, and create the
15676 symbol for the enumeration type.
15678 NOTE: We reverse the order of the element list. */
15681 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15683 struct type
*this_type
;
15685 this_type
= get_die_type (die
, cu
);
15686 if (this_type
== NULL
)
15687 this_type
= read_enumeration_type (die
, cu
);
15689 if (die
->child
!= NULL
)
15691 struct die_info
*child_die
;
15692 struct symbol
*sym
;
15693 std::vector
<struct field
> fields
;
15696 child_die
= die
->child
;
15697 while (child_die
&& child_die
->tag
)
15699 if (child_die
->tag
!= DW_TAG_enumerator
)
15701 process_die (child_die
, cu
);
15705 name
= dwarf2_name (child_die
, cu
);
15708 sym
= new_symbol (child_die
, this_type
, cu
);
15710 fields
.emplace_back ();
15711 struct field
&field
= fields
.back ();
15713 FIELD_NAME (field
) = sym
->linkage_name ();
15714 FIELD_TYPE (field
) = NULL
;
15715 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15716 FIELD_BITSIZE (field
) = 0;
15720 child_die
= sibling_die (child_die
);
15723 if (!fields
.empty ())
15725 TYPE_NFIELDS (this_type
) = fields
.size ();
15726 TYPE_FIELDS (this_type
) = (struct field
*)
15727 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15728 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15729 sizeof (struct field
) * fields
.size ());
15733 /* If we are reading an enum from a .debug_types unit, and the enum
15734 is a declaration, and the enum is not the signatured type in the
15735 unit, then we do not want to add a symbol for it. Adding a
15736 symbol would in some cases obscure the true definition of the
15737 enum, giving users an incomplete type when the definition is
15738 actually available. Note that we do not want to do this for all
15739 enums which are just declarations, because C++0x allows forward
15740 enum declarations. */
15741 if (cu
->per_cu
->is_debug_types
15742 && die_is_declaration (die
, cu
))
15744 struct signatured_type
*sig_type
;
15746 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15747 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15748 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15752 new_symbol (die
, this_type
, cu
);
15755 /* Extract all information from a DW_TAG_array_type DIE and put it in
15756 the DIE's type field. For now, this only handles one dimensional
15759 static struct type
*
15760 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15762 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15763 struct die_info
*child_die
;
15765 struct type
*element_type
, *range_type
, *index_type
;
15766 struct attribute
*attr
;
15768 struct dynamic_prop
*byte_stride_prop
= NULL
;
15769 unsigned int bit_stride
= 0;
15771 element_type
= die_type (die
, cu
);
15773 /* The die_type call above may have already set the type for this DIE. */
15774 type
= get_die_type (die
, cu
);
15778 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15782 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15785 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15786 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15790 complaint (_("unable to read array DW_AT_byte_stride "
15791 " - DIE at %s [in module %s]"),
15792 sect_offset_str (die
->sect_off
),
15793 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15794 /* Ignore this attribute. We will likely not be able to print
15795 arrays of this type correctly, but there is little we can do
15796 to help if we cannot read the attribute's value. */
15797 byte_stride_prop
= NULL
;
15801 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15803 bit_stride
= DW_UNSND (attr
);
15805 /* Irix 6.2 native cc creates array types without children for
15806 arrays with unspecified length. */
15807 if (die
->child
== NULL
)
15809 index_type
= objfile_type (objfile
)->builtin_int
;
15810 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15811 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15812 byte_stride_prop
, bit_stride
);
15813 return set_die_type (die
, type
, cu
);
15816 std::vector
<struct type
*> range_types
;
15817 child_die
= die
->child
;
15818 while (child_die
&& child_die
->tag
)
15820 if (child_die
->tag
== DW_TAG_subrange_type
)
15822 struct type
*child_type
= read_type_die (child_die
, cu
);
15824 if (child_type
!= NULL
)
15826 /* The range type was succesfully read. Save it for the
15827 array type creation. */
15828 range_types
.push_back (child_type
);
15831 child_die
= sibling_die (child_die
);
15834 /* Dwarf2 dimensions are output from left to right, create the
15835 necessary array types in backwards order. */
15837 type
= element_type
;
15839 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15843 while (i
< range_types
.size ())
15844 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15845 byte_stride_prop
, bit_stride
);
15849 size_t ndim
= range_types
.size ();
15851 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15852 byte_stride_prop
, bit_stride
);
15855 /* Understand Dwarf2 support for vector types (like they occur on
15856 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15857 array type. This is not part of the Dwarf2/3 standard yet, but a
15858 custom vendor extension. The main difference between a regular
15859 array and the vector variant is that vectors are passed by value
15861 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15862 if (attr
!= nullptr)
15863 make_vector_type (type
);
15865 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15866 implementation may choose to implement triple vectors using this
15868 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15869 if (attr
!= nullptr)
15871 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15872 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15874 complaint (_("DW_AT_byte_size for array type smaller "
15875 "than the total size of elements"));
15878 name
= dwarf2_name (die
, cu
);
15880 TYPE_NAME (type
) = name
;
15882 maybe_set_alignment (cu
, die
, type
);
15884 /* Install the type in the die. */
15885 set_die_type (die
, type
, cu
);
15887 /* set_die_type should be already done. */
15888 set_descriptive_type (type
, die
, cu
);
15893 static enum dwarf_array_dim_ordering
15894 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15896 struct attribute
*attr
;
15898 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15900 if (attr
!= nullptr)
15901 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15903 /* GNU F77 is a special case, as at 08/2004 array type info is the
15904 opposite order to the dwarf2 specification, but data is still
15905 laid out as per normal fortran.
15907 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15908 version checking. */
15910 if (cu
->language
== language_fortran
15911 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15913 return DW_ORD_row_major
;
15916 switch (cu
->language_defn
->la_array_ordering
)
15918 case array_column_major
:
15919 return DW_ORD_col_major
;
15920 case array_row_major
:
15922 return DW_ORD_row_major
;
15926 /* Extract all information from a DW_TAG_set_type DIE and put it in
15927 the DIE's type field. */
15929 static struct type
*
15930 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15932 struct type
*domain_type
, *set_type
;
15933 struct attribute
*attr
;
15935 domain_type
= die_type (die
, cu
);
15937 /* The die_type call above may have already set the type for this DIE. */
15938 set_type
= get_die_type (die
, cu
);
15942 set_type
= create_set_type (NULL
, domain_type
);
15944 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15945 if (attr
!= nullptr)
15946 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15948 maybe_set_alignment (cu
, die
, set_type
);
15950 return set_die_type (die
, set_type
, cu
);
15953 /* A helper for read_common_block that creates a locexpr baton.
15954 SYM is the symbol which we are marking as computed.
15955 COMMON_DIE is the DIE for the common block.
15956 COMMON_LOC is the location expression attribute for the common
15958 MEMBER_LOC is the location expression attribute for the particular
15959 member of the common block that we are processing.
15960 CU is the CU from which the above come. */
15963 mark_common_block_symbol_computed (struct symbol
*sym
,
15964 struct die_info
*common_die
,
15965 struct attribute
*common_loc
,
15966 struct attribute
*member_loc
,
15967 struct dwarf2_cu
*cu
)
15969 struct dwarf2_per_objfile
*dwarf2_per_objfile
15970 = cu
->per_cu
->dwarf2_per_objfile
;
15971 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15972 struct dwarf2_locexpr_baton
*baton
;
15974 unsigned int cu_off
;
15975 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15976 LONGEST offset
= 0;
15978 gdb_assert (common_loc
&& member_loc
);
15979 gdb_assert (common_loc
->form_is_block ());
15980 gdb_assert (member_loc
->form_is_block ()
15981 || member_loc
->form_is_constant ());
15983 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15984 baton
->per_cu
= cu
->per_cu
;
15985 gdb_assert (baton
->per_cu
);
15987 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15989 if (member_loc
->form_is_constant ())
15991 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15992 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15995 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15997 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16000 *ptr
++ = DW_OP_call4
;
16001 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16002 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16005 if (member_loc
->form_is_constant ())
16007 *ptr
++ = DW_OP_addr
;
16008 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16009 ptr
+= cu
->header
.addr_size
;
16013 /* We have to copy the data here, because DW_OP_call4 will only
16014 use a DW_AT_location attribute. */
16015 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16016 ptr
+= DW_BLOCK (member_loc
)->size
;
16019 *ptr
++ = DW_OP_plus
;
16020 gdb_assert (ptr
- baton
->data
== baton
->size
);
16022 SYMBOL_LOCATION_BATON (sym
) = baton
;
16023 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16026 /* Create appropriate locally-scoped variables for all the
16027 DW_TAG_common_block entries. Also create a struct common_block
16028 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16029 is used to separate the common blocks name namespace from regular
16033 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16035 struct attribute
*attr
;
16037 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16038 if (attr
!= nullptr)
16040 /* Support the .debug_loc offsets. */
16041 if (attr
->form_is_block ())
16045 else if (attr
->form_is_section_offset ())
16047 dwarf2_complex_location_expr_complaint ();
16052 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16053 "common block member");
16058 if (die
->child
!= NULL
)
16060 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16061 struct die_info
*child_die
;
16062 size_t n_entries
= 0, size
;
16063 struct common_block
*common_block
;
16064 struct symbol
*sym
;
16066 for (child_die
= die
->child
;
16067 child_die
&& child_die
->tag
;
16068 child_die
= sibling_die (child_die
))
16071 size
= (sizeof (struct common_block
)
16072 + (n_entries
- 1) * sizeof (struct symbol
*));
16074 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16076 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16077 common_block
->n_entries
= 0;
16079 for (child_die
= die
->child
;
16080 child_die
&& child_die
->tag
;
16081 child_die
= sibling_die (child_die
))
16083 /* Create the symbol in the DW_TAG_common_block block in the current
16085 sym
= new_symbol (child_die
, NULL
, cu
);
16088 struct attribute
*member_loc
;
16090 common_block
->contents
[common_block
->n_entries
++] = sym
;
16092 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16096 /* GDB has handled this for a long time, but it is
16097 not specified by DWARF. It seems to have been
16098 emitted by gfortran at least as recently as:
16099 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16100 complaint (_("Variable in common block has "
16101 "DW_AT_data_member_location "
16102 "- DIE at %s [in module %s]"),
16103 sect_offset_str (child_die
->sect_off
),
16104 objfile_name (objfile
));
16106 if (member_loc
->form_is_section_offset ())
16107 dwarf2_complex_location_expr_complaint ();
16108 else if (member_loc
->form_is_constant ()
16109 || member_loc
->form_is_block ())
16111 if (attr
!= nullptr)
16112 mark_common_block_symbol_computed (sym
, die
, attr
,
16116 dwarf2_complex_location_expr_complaint ();
16121 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16122 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16126 /* Create a type for a C++ namespace. */
16128 static struct type
*
16129 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16131 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16132 const char *previous_prefix
, *name
;
16136 /* For extensions, reuse the type of the original namespace. */
16137 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16139 struct die_info
*ext_die
;
16140 struct dwarf2_cu
*ext_cu
= cu
;
16142 ext_die
= dwarf2_extension (die
, &ext_cu
);
16143 type
= read_type_die (ext_die
, ext_cu
);
16145 /* EXT_CU may not be the same as CU.
16146 Ensure TYPE is recorded with CU in die_type_hash. */
16147 return set_die_type (die
, type
, cu
);
16150 name
= namespace_name (die
, &is_anonymous
, cu
);
16152 /* Now build the name of the current namespace. */
16154 previous_prefix
= determine_prefix (die
, cu
);
16155 if (previous_prefix
[0] != '\0')
16156 name
= typename_concat (&objfile
->objfile_obstack
,
16157 previous_prefix
, name
, 0, cu
);
16159 /* Create the type. */
16160 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16162 return set_die_type (die
, type
, cu
);
16165 /* Read a namespace scope. */
16168 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16170 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16173 /* Add a symbol associated to this if we haven't seen the namespace
16174 before. Also, add a using directive if it's an anonymous
16177 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16181 type
= read_type_die (die
, cu
);
16182 new_symbol (die
, type
, cu
);
16184 namespace_name (die
, &is_anonymous
, cu
);
16187 const char *previous_prefix
= determine_prefix (die
, cu
);
16189 std::vector
<const char *> excludes
;
16190 add_using_directive (using_directives (cu
),
16191 previous_prefix
, TYPE_NAME (type
), NULL
,
16192 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16196 if (die
->child
!= NULL
)
16198 struct die_info
*child_die
= die
->child
;
16200 while (child_die
&& child_die
->tag
)
16202 process_die (child_die
, cu
);
16203 child_die
= sibling_die (child_die
);
16208 /* Read a Fortran module as type. This DIE can be only a declaration used for
16209 imported module. Still we need that type as local Fortran "use ... only"
16210 declaration imports depend on the created type in determine_prefix. */
16212 static struct type
*
16213 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16215 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16216 const char *module_name
;
16219 module_name
= dwarf2_name (die
, cu
);
16220 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16222 return set_die_type (die
, type
, cu
);
16225 /* Read a Fortran module. */
16228 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16230 struct die_info
*child_die
= die
->child
;
16233 type
= read_type_die (die
, cu
);
16234 new_symbol (die
, type
, cu
);
16236 while (child_die
&& child_die
->tag
)
16238 process_die (child_die
, cu
);
16239 child_die
= sibling_die (child_die
);
16243 /* Return the name of the namespace represented by DIE. Set
16244 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16247 static const char *
16248 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16250 struct die_info
*current_die
;
16251 const char *name
= NULL
;
16253 /* Loop through the extensions until we find a name. */
16255 for (current_die
= die
;
16256 current_die
!= NULL
;
16257 current_die
= dwarf2_extension (die
, &cu
))
16259 /* We don't use dwarf2_name here so that we can detect the absence
16260 of a name -> anonymous namespace. */
16261 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16267 /* Is it an anonymous namespace? */
16269 *is_anonymous
= (name
== NULL
);
16271 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16276 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16277 the user defined type vector. */
16279 static struct type
*
16280 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16282 struct gdbarch
*gdbarch
16283 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16284 struct comp_unit_head
*cu_header
= &cu
->header
;
16286 struct attribute
*attr_byte_size
;
16287 struct attribute
*attr_address_class
;
16288 int byte_size
, addr_class
;
16289 struct type
*target_type
;
16291 target_type
= die_type (die
, cu
);
16293 /* The die_type call above may have already set the type for this DIE. */
16294 type
= get_die_type (die
, cu
);
16298 type
= lookup_pointer_type (target_type
);
16300 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16301 if (attr_byte_size
)
16302 byte_size
= DW_UNSND (attr_byte_size
);
16304 byte_size
= cu_header
->addr_size
;
16306 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16307 if (attr_address_class
)
16308 addr_class
= DW_UNSND (attr_address_class
);
16310 addr_class
= DW_ADDR_none
;
16312 ULONGEST alignment
= get_alignment (cu
, die
);
16314 /* If the pointer size, alignment, or address class is different
16315 than the default, create a type variant marked as such and set
16316 the length accordingly. */
16317 if (TYPE_LENGTH (type
) != byte_size
16318 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16319 && alignment
!= TYPE_RAW_ALIGN (type
))
16320 || addr_class
!= DW_ADDR_none
)
16322 if (gdbarch_address_class_type_flags_p (gdbarch
))
16326 type_flags
= gdbarch_address_class_type_flags
16327 (gdbarch
, byte_size
, addr_class
);
16328 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16330 type
= make_type_with_address_space (type
, type_flags
);
16332 else if (TYPE_LENGTH (type
) != byte_size
)
16334 complaint (_("invalid pointer size %d"), byte_size
);
16336 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16338 complaint (_("Invalid DW_AT_alignment"
16339 " - DIE at %s [in module %s]"),
16340 sect_offset_str (die
->sect_off
),
16341 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16345 /* Should we also complain about unhandled address classes? */
16349 TYPE_LENGTH (type
) = byte_size
;
16350 set_type_align (type
, alignment
);
16351 return set_die_type (die
, type
, cu
);
16354 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16355 the user defined type vector. */
16357 static struct type
*
16358 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16361 struct type
*to_type
;
16362 struct type
*domain
;
16364 to_type
= die_type (die
, cu
);
16365 domain
= die_containing_type (die
, cu
);
16367 /* The calls above may have already set the type for this DIE. */
16368 type
= get_die_type (die
, cu
);
16372 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16373 type
= lookup_methodptr_type (to_type
);
16374 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16376 struct type
*new_type
16377 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16379 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16380 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16381 TYPE_VARARGS (to_type
));
16382 type
= lookup_methodptr_type (new_type
);
16385 type
= lookup_memberptr_type (to_type
, domain
);
16387 return set_die_type (die
, type
, cu
);
16390 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16391 the user defined type vector. */
16393 static struct type
*
16394 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16395 enum type_code refcode
)
16397 struct comp_unit_head
*cu_header
= &cu
->header
;
16398 struct type
*type
, *target_type
;
16399 struct attribute
*attr
;
16401 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16403 target_type
= die_type (die
, cu
);
16405 /* The die_type call above may have already set the type for this DIE. */
16406 type
= get_die_type (die
, cu
);
16410 type
= lookup_reference_type (target_type
, refcode
);
16411 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16412 if (attr
!= nullptr)
16414 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16418 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16420 maybe_set_alignment (cu
, die
, type
);
16421 return set_die_type (die
, type
, cu
);
16424 /* Add the given cv-qualifiers to the element type of the array. GCC
16425 outputs DWARF type qualifiers that apply to an array, not the
16426 element type. But GDB relies on the array element type to carry
16427 the cv-qualifiers. This mimics section 6.7.3 of the C99
16430 static struct type
*
16431 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16432 struct type
*base_type
, int cnst
, int voltl
)
16434 struct type
*el_type
, *inner_array
;
16436 base_type
= copy_type (base_type
);
16437 inner_array
= base_type
;
16439 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16441 TYPE_TARGET_TYPE (inner_array
) =
16442 copy_type (TYPE_TARGET_TYPE (inner_array
));
16443 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16446 el_type
= TYPE_TARGET_TYPE (inner_array
);
16447 cnst
|= TYPE_CONST (el_type
);
16448 voltl
|= TYPE_VOLATILE (el_type
);
16449 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16451 return set_die_type (die
, base_type
, cu
);
16454 static struct type
*
16455 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16457 struct type
*base_type
, *cv_type
;
16459 base_type
= die_type (die
, cu
);
16461 /* The die_type call above may have already set the type for this DIE. */
16462 cv_type
= get_die_type (die
, cu
);
16466 /* In case the const qualifier is applied to an array type, the element type
16467 is so qualified, not the array type (section 6.7.3 of C99). */
16468 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16469 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16471 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16472 return set_die_type (die
, cv_type
, cu
);
16475 static struct type
*
16476 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16478 struct type
*base_type
, *cv_type
;
16480 base_type
= die_type (die
, cu
);
16482 /* The die_type call above may have already set the type for this DIE. */
16483 cv_type
= get_die_type (die
, cu
);
16487 /* In case the volatile qualifier is applied to an array type, the
16488 element type is so qualified, not the array type (section 6.7.3
16490 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16491 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16493 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16494 return set_die_type (die
, cv_type
, cu
);
16497 /* Handle DW_TAG_restrict_type. */
16499 static struct type
*
16500 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16502 struct type
*base_type
, *cv_type
;
16504 base_type
= die_type (die
, cu
);
16506 /* The die_type call above may have already set the type for this DIE. */
16507 cv_type
= get_die_type (die
, cu
);
16511 cv_type
= make_restrict_type (base_type
);
16512 return set_die_type (die
, cv_type
, cu
);
16515 /* Handle DW_TAG_atomic_type. */
16517 static struct type
*
16518 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16520 struct type
*base_type
, *cv_type
;
16522 base_type
= die_type (die
, cu
);
16524 /* The die_type call above may have already set the type for this DIE. */
16525 cv_type
= get_die_type (die
, cu
);
16529 cv_type
= make_atomic_type (base_type
);
16530 return set_die_type (die
, cv_type
, cu
);
16533 /* Extract all information from a DW_TAG_string_type DIE and add to
16534 the user defined type vector. It isn't really a user defined type,
16535 but it behaves like one, with other DIE's using an AT_user_def_type
16536 attribute to reference it. */
16538 static struct type
*
16539 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16541 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16542 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16543 struct type
*type
, *range_type
, *index_type
, *char_type
;
16544 struct attribute
*attr
;
16545 struct dynamic_prop prop
;
16546 bool length_is_constant
= true;
16549 /* There are a couple of places where bit sizes might be made use of
16550 when parsing a DW_TAG_string_type, however, no producer that we know
16551 of make use of these. Handling bit sizes that are a multiple of the
16552 byte size is easy enough, but what about other bit sizes? Lets deal
16553 with that problem when we have to. Warn about these attributes being
16554 unsupported, then parse the type and ignore them like we always
16556 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16557 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16559 static bool warning_printed
= false;
16560 if (!warning_printed
)
16562 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16563 "currently supported on DW_TAG_string_type."));
16564 warning_printed
= true;
16568 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16569 if (attr
!= nullptr && !attr
->form_is_constant ())
16571 /* The string length describes the location at which the length of
16572 the string can be found. The size of the length field can be
16573 specified with one of the attributes below. */
16574 struct type
*prop_type
;
16575 struct attribute
*len
16576 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16577 if (len
== nullptr)
16578 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16579 if (len
!= nullptr && len
->form_is_constant ())
16581 /* Pass 0 as the default as we know this attribute is constant
16582 and the default value will not be returned. */
16583 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16584 prop_type
= cu
->per_cu
->int_type (sz
, true);
16588 /* If the size is not specified then we assume it is the size of
16589 an address on this target. */
16590 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16593 /* Convert the attribute into a dynamic property. */
16594 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16597 length_is_constant
= false;
16599 else if (attr
!= nullptr)
16601 /* This DW_AT_string_length just contains the length with no
16602 indirection. There's no need to create a dynamic property in this
16603 case. Pass 0 for the default value as we know it will not be
16604 returned in this case. */
16605 length
= dwarf2_get_attr_constant_value (attr
, 0);
16607 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16609 /* We don't currently support non-constant byte sizes for strings. */
16610 length
= dwarf2_get_attr_constant_value (attr
, 1);
16614 /* Use 1 as a fallback length if we have nothing else. */
16618 index_type
= objfile_type (objfile
)->builtin_int
;
16619 if (length_is_constant
)
16620 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16623 struct dynamic_prop low_bound
;
16625 low_bound
.kind
= PROP_CONST
;
16626 low_bound
.data
.const_val
= 1;
16627 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16629 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16630 type
= create_string_type (NULL
, char_type
, range_type
);
16632 return set_die_type (die
, type
, cu
);
16635 /* Assuming that DIE corresponds to a function, returns nonzero
16636 if the function is prototyped. */
16639 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16641 struct attribute
*attr
;
16643 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16644 if (attr
&& (DW_UNSND (attr
) != 0))
16647 /* The DWARF standard implies that the DW_AT_prototyped attribute
16648 is only meaningful for C, but the concept also extends to other
16649 languages that allow unprototyped functions (Eg: Objective C).
16650 For all other languages, assume that functions are always
16652 if (cu
->language
!= language_c
16653 && cu
->language
!= language_objc
16654 && cu
->language
!= language_opencl
)
16657 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16658 prototyped and unprototyped functions; default to prototyped,
16659 since that is more common in modern code (and RealView warns
16660 about unprototyped functions). */
16661 if (producer_is_realview (cu
->producer
))
16667 /* Handle DIES due to C code like:
16671 int (*funcp)(int a, long l);
16675 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16677 static struct type
*
16678 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16680 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16681 struct type
*type
; /* Type that this function returns. */
16682 struct type
*ftype
; /* Function that returns above type. */
16683 struct attribute
*attr
;
16685 type
= die_type (die
, cu
);
16687 /* The die_type call above may have already set the type for this DIE. */
16688 ftype
= get_die_type (die
, cu
);
16692 ftype
= lookup_function_type (type
);
16694 if (prototyped_function_p (die
, cu
))
16695 TYPE_PROTOTYPED (ftype
) = 1;
16697 /* Store the calling convention in the type if it's available in
16698 the subroutine die. Otherwise set the calling convention to
16699 the default value DW_CC_normal. */
16700 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16701 if (attr
!= nullptr
16702 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16703 TYPE_CALLING_CONVENTION (ftype
)
16704 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16705 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16706 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16708 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16710 /* Record whether the function returns normally to its caller or not
16711 if the DWARF producer set that information. */
16712 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16713 if (attr
&& (DW_UNSND (attr
) != 0))
16714 TYPE_NO_RETURN (ftype
) = 1;
16716 /* We need to add the subroutine type to the die immediately so
16717 we don't infinitely recurse when dealing with parameters
16718 declared as the same subroutine type. */
16719 set_die_type (die
, ftype
, cu
);
16721 if (die
->child
!= NULL
)
16723 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16724 struct die_info
*child_die
;
16725 int nparams
, iparams
;
16727 /* Count the number of parameters.
16728 FIXME: GDB currently ignores vararg functions, but knows about
16729 vararg member functions. */
16731 child_die
= die
->child
;
16732 while (child_die
&& child_die
->tag
)
16734 if (child_die
->tag
== DW_TAG_formal_parameter
)
16736 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16737 TYPE_VARARGS (ftype
) = 1;
16738 child_die
= sibling_die (child_die
);
16741 /* Allocate storage for parameters and fill them in. */
16742 TYPE_NFIELDS (ftype
) = nparams
;
16743 TYPE_FIELDS (ftype
) = (struct field
*)
16744 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16746 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16747 even if we error out during the parameters reading below. */
16748 for (iparams
= 0; iparams
< nparams
; iparams
++)
16749 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16752 child_die
= die
->child
;
16753 while (child_die
&& child_die
->tag
)
16755 if (child_die
->tag
== DW_TAG_formal_parameter
)
16757 struct type
*arg_type
;
16759 /* DWARF version 2 has no clean way to discern C++
16760 static and non-static member functions. G++ helps
16761 GDB by marking the first parameter for non-static
16762 member functions (which is the this pointer) as
16763 artificial. We pass this information to
16764 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16766 DWARF version 3 added DW_AT_object_pointer, which GCC
16767 4.5 does not yet generate. */
16768 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16769 if (attr
!= nullptr)
16770 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16772 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16773 arg_type
= die_type (child_die
, cu
);
16775 /* RealView does not mark THIS as const, which the testsuite
16776 expects. GCC marks THIS as const in method definitions,
16777 but not in the class specifications (GCC PR 43053). */
16778 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16779 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16782 struct dwarf2_cu
*arg_cu
= cu
;
16783 const char *name
= dwarf2_name (child_die
, cu
);
16785 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16786 if (attr
!= nullptr)
16788 /* If the compiler emits this, use it. */
16789 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16792 else if (name
&& strcmp (name
, "this") == 0)
16793 /* Function definitions will have the argument names. */
16795 else if (name
== NULL
&& iparams
== 0)
16796 /* Declarations may not have the names, so like
16797 elsewhere in GDB, assume an artificial first
16798 argument is "this". */
16802 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16806 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16809 child_die
= sibling_die (child_die
);
16816 static struct type
*
16817 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16819 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16820 const char *name
= NULL
;
16821 struct type
*this_type
, *target_type
;
16823 name
= dwarf2_full_name (NULL
, die
, cu
);
16824 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16825 TYPE_TARGET_STUB (this_type
) = 1;
16826 set_die_type (die
, this_type
, cu
);
16827 target_type
= die_type (die
, cu
);
16828 if (target_type
!= this_type
)
16829 TYPE_TARGET_TYPE (this_type
) = target_type
;
16832 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16833 spec and cause infinite loops in GDB. */
16834 complaint (_("Self-referential DW_TAG_typedef "
16835 "- DIE at %s [in module %s]"),
16836 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16837 TYPE_TARGET_TYPE (this_type
) = NULL
;
16841 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16842 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16843 Handle these by just returning the target type, rather than
16844 constructing an anonymous typedef type and trying to handle this
16846 set_die_type (die
, target_type
, cu
);
16847 return target_type
;
16852 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16853 (which may be different from NAME) to the architecture back-end to allow
16854 it to guess the correct format if necessary. */
16856 static struct type
*
16857 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16858 const char *name_hint
, enum bfd_endian byte_order
)
16860 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16861 const struct floatformat
**format
;
16864 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16866 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16868 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16873 /* Allocate an integer type of size BITS and name NAME. */
16875 static struct type
*
16876 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16877 int bits
, int unsigned_p
, const char *name
)
16881 /* Versions of Intel's C Compiler generate an integer type called "void"
16882 instead of using DW_TAG_unspecified_type. This has been seen on
16883 at least versions 14, 17, and 18. */
16884 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16885 && strcmp (name
, "void") == 0)
16886 type
= objfile_type (objfile
)->builtin_void
;
16888 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16893 /* Initialise and return a floating point type of size BITS suitable for
16894 use as a component of a complex number. The NAME_HINT is passed through
16895 when initialising the floating point type and is the name of the complex
16898 As DWARF doesn't currently provide an explicit name for the components
16899 of a complex number, but it can be helpful to have these components
16900 named, we try to select a suitable name based on the size of the
16902 static struct type
*
16903 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16904 struct objfile
*objfile
,
16905 int bits
, const char *name_hint
,
16906 enum bfd_endian byte_order
)
16908 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16909 struct type
*tt
= nullptr;
16911 /* Try to find a suitable floating point builtin type of size BITS.
16912 We're going to use the name of this type as the name for the complex
16913 target type that we are about to create. */
16914 switch (cu
->language
)
16916 case language_fortran
:
16920 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16923 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16925 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16927 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16935 tt
= builtin_type (gdbarch
)->builtin_float
;
16938 tt
= builtin_type (gdbarch
)->builtin_double
;
16940 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16942 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16948 /* If the type we found doesn't match the size we were looking for, then
16949 pretend we didn't find a type at all, the complex target type we
16950 create will then be nameless. */
16951 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16954 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16955 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16958 /* Find a representation of a given base type and install
16959 it in the TYPE field of the die. */
16961 static struct type
*
16962 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16964 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16966 struct attribute
*attr
;
16967 int encoding
= 0, bits
= 0;
16971 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16972 if (attr
!= nullptr)
16973 encoding
= DW_UNSND (attr
);
16974 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16975 if (attr
!= nullptr)
16976 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16977 name
= dwarf2_name (die
, cu
);
16979 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16981 arch
= get_objfile_arch (objfile
);
16982 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16984 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16987 int endianity
= DW_UNSND (attr
);
16992 byte_order
= BFD_ENDIAN_BIG
;
16994 case DW_END_little
:
16995 byte_order
= BFD_ENDIAN_LITTLE
;
16998 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17005 case DW_ATE_address
:
17006 /* Turn DW_ATE_address into a void * pointer. */
17007 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17008 type
= init_pointer_type (objfile
, bits
, name
, type
);
17010 case DW_ATE_boolean
:
17011 type
= init_boolean_type (objfile
, bits
, 1, name
);
17013 case DW_ATE_complex_float
:
17014 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17016 type
= init_complex_type (objfile
, name
, type
);
17018 case DW_ATE_decimal_float
:
17019 type
= init_decfloat_type (objfile
, bits
, name
);
17022 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17024 case DW_ATE_signed
:
17025 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17027 case DW_ATE_unsigned
:
17028 if (cu
->language
== language_fortran
17030 && startswith (name
, "character("))
17031 type
= init_character_type (objfile
, bits
, 1, name
);
17033 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17035 case DW_ATE_signed_char
:
17036 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17037 || cu
->language
== language_pascal
17038 || cu
->language
== language_fortran
)
17039 type
= init_character_type (objfile
, bits
, 0, name
);
17041 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17043 case DW_ATE_unsigned_char
:
17044 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17045 || cu
->language
== language_pascal
17046 || cu
->language
== language_fortran
17047 || cu
->language
== language_rust
)
17048 type
= init_character_type (objfile
, bits
, 1, name
);
17050 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17055 type
= builtin_type (arch
)->builtin_char16
;
17056 else if (bits
== 32)
17057 type
= builtin_type (arch
)->builtin_char32
;
17060 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17062 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17064 return set_die_type (die
, type
, cu
);
17069 complaint (_("unsupported DW_AT_encoding: '%s'"),
17070 dwarf_type_encoding_name (encoding
));
17071 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17075 if (name
&& strcmp (name
, "char") == 0)
17076 TYPE_NOSIGN (type
) = 1;
17078 maybe_set_alignment (cu
, die
, type
);
17080 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17082 return set_die_type (die
, type
, cu
);
17085 /* Parse dwarf attribute if it's a block, reference or constant and put the
17086 resulting value of the attribute into struct bound_prop.
17087 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17090 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17091 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17092 struct type
*default_type
)
17094 struct dwarf2_property_baton
*baton
;
17095 struct obstack
*obstack
17096 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17098 gdb_assert (default_type
!= NULL
);
17100 if (attr
== NULL
|| prop
== NULL
)
17103 if (attr
->form_is_block ())
17105 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17106 baton
->property_type
= default_type
;
17107 baton
->locexpr
.per_cu
= cu
->per_cu
;
17108 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17109 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17110 switch (attr
->name
)
17112 case DW_AT_string_length
:
17113 baton
->locexpr
.is_reference
= true;
17116 baton
->locexpr
.is_reference
= false;
17119 prop
->data
.baton
= baton
;
17120 prop
->kind
= PROP_LOCEXPR
;
17121 gdb_assert (prop
->data
.baton
!= NULL
);
17123 else if (attr
->form_is_ref ())
17125 struct dwarf2_cu
*target_cu
= cu
;
17126 struct die_info
*target_die
;
17127 struct attribute
*target_attr
;
17129 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17130 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17131 if (target_attr
== NULL
)
17132 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17134 if (target_attr
== NULL
)
17137 switch (target_attr
->name
)
17139 case DW_AT_location
:
17140 if (target_attr
->form_is_section_offset ())
17142 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17143 baton
->property_type
= die_type (target_die
, target_cu
);
17144 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17145 prop
->data
.baton
= baton
;
17146 prop
->kind
= PROP_LOCLIST
;
17147 gdb_assert (prop
->data
.baton
!= NULL
);
17149 else if (target_attr
->form_is_block ())
17151 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17152 baton
->property_type
= die_type (target_die
, target_cu
);
17153 baton
->locexpr
.per_cu
= cu
->per_cu
;
17154 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17155 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17156 baton
->locexpr
.is_reference
= true;
17157 prop
->data
.baton
= baton
;
17158 prop
->kind
= PROP_LOCEXPR
;
17159 gdb_assert (prop
->data
.baton
!= NULL
);
17163 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17164 "dynamic property");
17168 case DW_AT_data_member_location
:
17172 if (!handle_data_member_location (target_die
, target_cu
,
17176 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17177 baton
->property_type
= read_type_die (target_die
->parent
,
17179 baton
->offset_info
.offset
= offset
;
17180 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17181 prop
->data
.baton
= baton
;
17182 prop
->kind
= PROP_ADDR_OFFSET
;
17187 else if (attr
->form_is_constant ())
17189 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17190 prop
->kind
= PROP_CONST
;
17194 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17195 dwarf2_name (die
, cu
));
17205 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17207 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17208 struct type
*int_type
;
17210 /* Helper macro to examine the various builtin types. */
17211 #define TRY_TYPE(F) \
17212 int_type = (unsigned_p \
17213 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17214 : objfile_type (objfile)->builtin_ ## F); \
17215 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17222 TRY_TYPE (long_long
);
17226 gdb_assert_not_reached ("unable to find suitable integer type");
17232 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17234 int addr_size
= this->addr_size ();
17235 return int_type (addr_size
, unsigned_p
);
17238 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17239 present (which is valid) then compute the default type based on the
17240 compilation units address size. */
17242 static struct type
*
17243 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17245 struct type
*index_type
= die_type (die
, cu
);
17247 /* Dwarf-2 specifications explicitly allows to create subrange types
17248 without specifying a base type.
17249 In that case, the base type must be set to the type of
17250 the lower bound, upper bound or count, in that order, if any of these
17251 three attributes references an object that has a type.
17252 If no base type is found, the Dwarf-2 specifications say that
17253 a signed integer type of size equal to the size of an address should
17255 For the following C code: `extern char gdb_int [];'
17256 GCC produces an empty range DIE.
17257 FIXME: muller/2010-05-28: Possible references to object for low bound,
17258 high bound or count are not yet handled by this code. */
17259 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17260 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17265 /* Read the given DW_AT_subrange DIE. */
17267 static struct type
*
17268 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17270 struct type
*base_type
, *orig_base_type
;
17271 struct type
*range_type
;
17272 struct attribute
*attr
;
17273 struct dynamic_prop low
, high
;
17274 int low_default_is_valid
;
17275 int high_bound_is_count
= 0;
17277 ULONGEST negative_mask
;
17279 orig_base_type
= read_subrange_index_type (die
, cu
);
17281 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17282 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17283 creating the range type, but we use the result of check_typedef
17284 when examining properties of the type. */
17285 base_type
= check_typedef (orig_base_type
);
17287 /* The die_type call above may have already set the type for this DIE. */
17288 range_type
= get_die_type (die
, cu
);
17292 low
.kind
= PROP_CONST
;
17293 high
.kind
= PROP_CONST
;
17294 high
.data
.const_val
= 0;
17296 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17297 omitting DW_AT_lower_bound. */
17298 switch (cu
->language
)
17301 case language_cplus
:
17302 low
.data
.const_val
= 0;
17303 low_default_is_valid
= 1;
17305 case language_fortran
:
17306 low
.data
.const_val
= 1;
17307 low_default_is_valid
= 1;
17310 case language_objc
:
17311 case language_rust
:
17312 low
.data
.const_val
= 0;
17313 low_default_is_valid
= (cu
->header
.version
>= 4);
17317 case language_pascal
:
17318 low
.data
.const_val
= 1;
17319 low_default_is_valid
= (cu
->header
.version
>= 4);
17322 low
.data
.const_val
= 0;
17323 low_default_is_valid
= 0;
17327 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17328 if (attr
!= nullptr)
17329 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17330 else if (!low_default_is_valid
)
17331 complaint (_("Missing DW_AT_lower_bound "
17332 "- DIE at %s [in module %s]"),
17333 sect_offset_str (die
->sect_off
),
17334 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17336 struct attribute
*attr_ub
, *attr_count
;
17337 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17338 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17340 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17341 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17343 /* If bounds are constant do the final calculation here. */
17344 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17345 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17347 high_bound_is_count
= 1;
17351 if (attr_ub
!= NULL
)
17352 complaint (_("Unresolved DW_AT_upper_bound "
17353 "- DIE at %s [in module %s]"),
17354 sect_offset_str (die
->sect_off
),
17355 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17356 if (attr_count
!= NULL
)
17357 complaint (_("Unresolved DW_AT_count "
17358 "- DIE at %s [in module %s]"),
17359 sect_offset_str (die
->sect_off
),
17360 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17365 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17366 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17367 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17369 /* Normally, the DWARF producers are expected to use a signed
17370 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17371 But this is unfortunately not always the case, as witnessed
17372 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17373 is used instead. To work around that ambiguity, we treat
17374 the bounds as signed, and thus sign-extend their values, when
17375 the base type is signed. */
17377 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17378 if (low
.kind
== PROP_CONST
17379 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17380 low
.data
.const_val
|= negative_mask
;
17381 if (high
.kind
== PROP_CONST
17382 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17383 high
.data
.const_val
|= negative_mask
;
17385 /* Check for bit and byte strides. */
17386 struct dynamic_prop byte_stride_prop
;
17387 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17388 if (attr_byte_stride
!= nullptr)
17390 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17391 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17395 struct dynamic_prop bit_stride_prop
;
17396 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17397 if (attr_bit_stride
!= nullptr)
17399 /* It only makes sense to have either a bit or byte stride. */
17400 if (attr_byte_stride
!= nullptr)
17402 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17403 "- DIE at %s [in module %s]"),
17404 sect_offset_str (die
->sect_off
),
17405 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17406 attr_bit_stride
= nullptr;
17410 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17411 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17416 if (attr_byte_stride
!= nullptr
17417 || attr_bit_stride
!= nullptr)
17419 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17420 struct dynamic_prop
*stride
17421 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17424 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17425 &high
, bias
, stride
, byte_stride_p
);
17428 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17430 if (high_bound_is_count
)
17431 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17433 /* Ada expects an empty array on no boundary attributes. */
17434 if (attr
== NULL
&& cu
->language
!= language_ada
)
17435 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17437 name
= dwarf2_name (die
, cu
);
17439 TYPE_NAME (range_type
) = name
;
17441 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17442 if (attr
!= nullptr)
17443 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17445 maybe_set_alignment (cu
, die
, range_type
);
17447 set_die_type (die
, range_type
, cu
);
17449 /* set_die_type should be already done. */
17450 set_descriptive_type (range_type
, die
, cu
);
17455 static struct type
*
17456 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17460 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17462 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17464 /* In Ada, an unspecified type is typically used when the description
17465 of the type is deferred to a different unit. When encountering
17466 such a type, we treat it as a stub, and try to resolve it later on,
17468 if (cu
->language
== language_ada
)
17469 TYPE_STUB (type
) = 1;
17471 return set_die_type (die
, type
, cu
);
17474 /* Read a single die and all its descendents. Set the die's sibling
17475 field to NULL; set other fields in the die correctly, and set all
17476 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17477 location of the info_ptr after reading all of those dies. PARENT
17478 is the parent of the die in question. */
17480 static struct die_info
*
17481 read_die_and_children (const struct die_reader_specs
*reader
,
17482 const gdb_byte
*info_ptr
,
17483 const gdb_byte
**new_info_ptr
,
17484 struct die_info
*parent
)
17486 struct die_info
*die
;
17487 const gdb_byte
*cur_ptr
;
17489 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17492 *new_info_ptr
= cur_ptr
;
17495 store_in_ref_table (die
, reader
->cu
);
17497 if (die
->has_children
)
17498 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17502 *new_info_ptr
= cur_ptr
;
17505 die
->sibling
= NULL
;
17506 die
->parent
= parent
;
17510 /* Read a die, all of its descendents, and all of its siblings; set
17511 all of the fields of all of the dies correctly. Arguments are as
17512 in read_die_and_children. */
17514 static struct die_info
*
17515 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17516 const gdb_byte
*info_ptr
,
17517 const gdb_byte
**new_info_ptr
,
17518 struct die_info
*parent
)
17520 struct die_info
*first_die
, *last_sibling
;
17521 const gdb_byte
*cur_ptr
;
17523 cur_ptr
= info_ptr
;
17524 first_die
= last_sibling
= NULL
;
17528 struct die_info
*die
17529 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17533 *new_info_ptr
= cur_ptr
;
17540 last_sibling
->sibling
= die
;
17542 last_sibling
= die
;
17546 /* Read a die, all of its descendents, and all of its siblings; set
17547 all of the fields of all of the dies correctly. Arguments are as
17548 in read_die_and_children.
17549 This the main entry point for reading a DIE and all its children. */
17551 static struct die_info
*
17552 read_die_and_siblings (const struct die_reader_specs
*reader
,
17553 const gdb_byte
*info_ptr
,
17554 const gdb_byte
**new_info_ptr
,
17555 struct die_info
*parent
)
17557 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17558 new_info_ptr
, parent
);
17560 if (dwarf_die_debug
)
17562 fprintf_unfiltered (gdb_stdlog
,
17563 "Read die from %s@0x%x of %s:\n",
17564 reader
->die_section
->get_name (),
17565 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17566 bfd_get_filename (reader
->abfd
));
17567 dump_die (die
, dwarf_die_debug
);
17573 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17575 The caller is responsible for filling in the extra attributes
17576 and updating (*DIEP)->num_attrs.
17577 Set DIEP to point to a newly allocated die with its information,
17578 except for its child, sibling, and parent fields. */
17580 static const gdb_byte
*
17581 read_full_die_1 (const struct die_reader_specs
*reader
,
17582 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17583 int num_extra_attrs
)
17585 unsigned int abbrev_number
, bytes_read
, i
;
17586 struct abbrev_info
*abbrev
;
17587 struct die_info
*die
;
17588 struct dwarf2_cu
*cu
= reader
->cu
;
17589 bfd
*abfd
= reader
->abfd
;
17591 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17592 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17593 info_ptr
+= bytes_read
;
17594 if (!abbrev_number
)
17600 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17602 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17604 bfd_get_filename (abfd
));
17606 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17607 die
->sect_off
= sect_off
;
17608 die
->tag
= abbrev
->tag
;
17609 die
->abbrev
= abbrev_number
;
17610 die
->has_children
= abbrev
->has_children
;
17612 /* Make the result usable.
17613 The caller needs to update num_attrs after adding the extra
17615 die
->num_attrs
= abbrev
->num_attrs
;
17617 std::vector
<int> indexes_that_need_reprocess
;
17618 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17620 bool need_reprocess
;
17622 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17623 info_ptr
, &need_reprocess
);
17624 if (need_reprocess
)
17625 indexes_that_need_reprocess
.push_back (i
);
17628 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17629 if (attr
!= nullptr)
17630 cu
->str_offsets_base
= DW_UNSND (attr
);
17632 auto maybe_addr_base
= lookup_addr_base(die
);
17633 if (maybe_addr_base
.has_value ())
17634 cu
->addr_base
= *maybe_addr_base
;
17635 for (int index
: indexes_that_need_reprocess
)
17636 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17641 /* Read a die and all its attributes.
17642 Set DIEP to point to a newly allocated die with its information,
17643 except for its child, sibling, and parent fields. */
17645 static const gdb_byte
*
17646 read_full_die (const struct die_reader_specs
*reader
,
17647 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17649 const gdb_byte
*result
;
17651 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17653 if (dwarf_die_debug
)
17655 fprintf_unfiltered (gdb_stdlog
,
17656 "Read die from %s@0x%x of %s:\n",
17657 reader
->die_section
->get_name (),
17658 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17659 bfd_get_filename (reader
->abfd
));
17660 dump_die (*diep
, dwarf_die_debug
);
17667 /* Returns nonzero if TAG represents a type that we might generate a partial
17671 is_type_tag_for_partial (int tag
)
17676 /* Some types that would be reasonable to generate partial symbols for,
17677 that we don't at present. */
17678 case DW_TAG_array_type
:
17679 case DW_TAG_file_type
:
17680 case DW_TAG_ptr_to_member_type
:
17681 case DW_TAG_set_type
:
17682 case DW_TAG_string_type
:
17683 case DW_TAG_subroutine_type
:
17685 case DW_TAG_base_type
:
17686 case DW_TAG_class_type
:
17687 case DW_TAG_interface_type
:
17688 case DW_TAG_enumeration_type
:
17689 case DW_TAG_structure_type
:
17690 case DW_TAG_subrange_type
:
17691 case DW_TAG_typedef
:
17692 case DW_TAG_union_type
:
17699 /* Load all DIEs that are interesting for partial symbols into memory. */
17701 static struct partial_die_info
*
17702 load_partial_dies (const struct die_reader_specs
*reader
,
17703 const gdb_byte
*info_ptr
, int building_psymtab
)
17705 struct dwarf2_cu
*cu
= reader
->cu
;
17706 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17707 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17708 unsigned int bytes_read
;
17709 unsigned int load_all
= 0;
17710 int nesting_level
= 1;
17715 gdb_assert (cu
->per_cu
!= NULL
);
17716 if (cu
->per_cu
->load_all_dies
)
17720 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17724 &cu
->comp_unit_obstack
,
17725 hashtab_obstack_allocate
,
17726 dummy_obstack_deallocate
);
17730 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17732 /* A NULL abbrev means the end of a series of children. */
17733 if (abbrev
== NULL
)
17735 if (--nesting_level
== 0)
17738 info_ptr
+= bytes_read
;
17739 last_die
= parent_die
;
17740 parent_die
= parent_die
->die_parent
;
17744 /* Check for template arguments. We never save these; if
17745 they're seen, we just mark the parent, and go on our way. */
17746 if (parent_die
!= NULL
17747 && cu
->language
== language_cplus
17748 && (abbrev
->tag
== DW_TAG_template_type_param
17749 || abbrev
->tag
== DW_TAG_template_value_param
))
17751 parent_die
->has_template_arguments
= 1;
17755 /* We don't need a partial DIE for the template argument. */
17756 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17761 /* We only recurse into c++ subprograms looking for template arguments.
17762 Skip their other children. */
17764 && cu
->language
== language_cplus
17765 && parent_die
!= NULL
17766 && parent_die
->tag
== DW_TAG_subprogram
)
17768 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17772 /* Check whether this DIE is interesting enough to save. Normally
17773 we would not be interested in members here, but there may be
17774 later variables referencing them via DW_AT_specification (for
17775 static members). */
17777 && !is_type_tag_for_partial (abbrev
->tag
)
17778 && abbrev
->tag
!= DW_TAG_constant
17779 && abbrev
->tag
!= DW_TAG_enumerator
17780 && abbrev
->tag
!= DW_TAG_subprogram
17781 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17782 && abbrev
->tag
!= DW_TAG_lexical_block
17783 && abbrev
->tag
!= DW_TAG_variable
17784 && abbrev
->tag
!= DW_TAG_namespace
17785 && abbrev
->tag
!= DW_TAG_module
17786 && abbrev
->tag
!= DW_TAG_member
17787 && abbrev
->tag
!= DW_TAG_imported_unit
17788 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17790 /* Otherwise we skip to the next sibling, if any. */
17791 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17795 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17798 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17800 /* This two-pass algorithm for processing partial symbols has a
17801 high cost in cache pressure. Thus, handle some simple cases
17802 here which cover the majority of C partial symbols. DIEs
17803 which neither have specification tags in them, nor could have
17804 specification tags elsewhere pointing at them, can simply be
17805 processed and discarded.
17807 This segment is also optional; scan_partial_symbols and
17808 add_partial_symbol will handle these DIEs if we chain
17809 them in normally. When compilers which do not emit large
17810 quantities of duplicate debug information are more common,
17811 this code can probably be removed. */
17813 /* Any complete simple types at the top level (pretty much all
17814 of them, for a language without namespaces), can be processed
17816 if (parent_die
== NULL
17817 && pdi
.has_specification
== 0
17818 && pdi
.is_declaration
== 0
17819 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17820 || pdi
.tag
== DW_TAG_base_type
17821 || pdi
.tag
== DW_TAG_subrange_type
))
17823 if (building_psymtab
&& pdi
.name
!= NULL
)
17824 add_psymbol_to_list (pdi
.name
, false,
17825 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17826 psymbol_placement::STATIC
,
17827 0, cu
->language
, objfile
);
17828 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17832 /* The exception for DW_TAG_typedef with has_children above is
17833 a workaround of GCC PR debug/47510. In the case of this complaint
17834 type_name_or_error will error on such types later.
17836 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17837 it could not find the child DIEs referenced later, this is checked
17838 above. In correct DWARF DW_TAG_typedef should have no children. */
17840 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17841 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17842 "- DIE at %s [in module %s]"),
17843 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17845 /* If we're at the second level, and we're an enumerator, and
17846 our parent has no specification (meaning possibly lives in a
17847 namespace elsewhere), then we can add the partial symbol now
17848 instead of queueing it. */
17849 if (pdi
.tag
== DW_TAG_enumerator
17850 && parent_die
!= NULL
17851 && parent_die
->die_parent
== NULL
17852 && parent_die
->tag
== DW_TAG_enumeration_type
17853 && parent_die
->has_specification
== 0)
17855 if (pdi
.name
== NULL
)
17856 complaint (_("malformed enumerator DIE ignored"));
17857 else if (building_psymtab
)
17858 add_psymbol_to_list (pdi
.name
, false,
17859 VAR_DOMAIN
, LOC_CONST
, -1,
17860 cu
->language
== language_cplus
17861 ? psymbol_placement::GLOBAL
17862 : psymbol_placement::STATIC
,
17863 0, cu
->language
, objfile
);
17865 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17869 struct partial_die_info
*part_die
17870 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17872 /* We'll save this DIE so link it in. */
17873 part_die
->die_parent
= parent_die
;
17874 part_die
->die_sibling
= NULL
;
17875 part_die
->die_child
= NULL
;
17877 if (last_die
&& last_die
== parent_die
)
17878 last_die
->die_child
= part_die
;
17880 last_die
->die_sibling
= part_die
;
17882 last_die
= part_die
;
17884 if (first_die
== NULL
)
17885 first_die
= part_die
;
17887 /* Maybe add the DIE to the hash table. Not all DIEs that we
17888 find interesting need to be in the hash table, because we
17889 also have the parent/sibling/child chains; only those that we
17890 might refer to by offset later during partial symbol reading.
17892 For now this means things that might have be the target of a
17893 DW_AT_specification, DW_AT_abstract_origin, or
17894 DW_AT_extension. DW_AT_extension will refer only to
17895 namespaces; DW_AT_abstract_origin refers to functions (and
17896 many things under the function DIE, but we do not recurse
17897 into function DIEs during partial symbol reading) and
17898 possibly variables as well; DW_AT_specification refers to
17899 declarations. Declarations ought to have the DW_AT_declaration
17900 flag. It happens that GCC forgets to put it in sometimes, but
17901 only for functions, not for types.
17903 Adding more things than necessary to the hash table is harmless
17904 except for the performance cost. Adding too few will result in
17905 wasted time in find_partial_die, when we reread the compilation
17906 unit with load_all_dies set. */
17909 || abbrev
->tag
== DW_TAG_constant
17910 || abbrev
->tag
== DW_TAG_subprogram
17911 || abbrev
->tag
== DW_TAG_variable
17912 || abbrev
->tag
== DW_TAG_namespace
17913 || part_die
->is_declaration
)
17917 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17918 to_underlying (part_die
->sect_off
),
17923 /* For some DIEs we want to follow their children (if any). For C
17924 we have no reason to follow the children of structures; for other
17925 languages we have to, so that we can get at method physnames
17926 to infer fully qualified class names, for DW_AT_specification,
17927 and for C++ template arguments. For C++, we also look one level
17928 inside functions to find template arguments (if the name of the
17929 function does not already contain the template arguments).
17931 For Ada and Fortran, we need to scan the children of subprograms
17932 and lexical blocks as well because these languages allow the
17933 definition of nested entities that could be interesting for the
17934 debugger, such as nested subprograms for instance. */
17935 if (last_die
->has_children
17937 || last_die
->tag
== DW_TAG_namespace
17938 || last_die
->tag
== DW_TAG_module
17939 || last_die
->tag
== DW_TAG_enumeration_type
17940 || (cu
->language
== language_cplus
17941 && last_die
->tag
== DW_TAG_subprogram
17942 && (last_die
->name
== NULL
17943 || strchr (last_die
->name
, '<') == NULL
))
17944 || (cu
->language
!= language_c
17945 && (last_die
->tag
== DW_TAG_class_type
17946 || last_die
->tag
== DW_TAG_interface_type
17947 || last_die
->tag
== DW_TAG_structure_type
17948 || last_die
->tag
== DW_TAG_union_type
))
17949 || ((cu
->language
== language_ada
17950 || cu
->language
== language_fortran
)
17951 && (last_die
->tag
== DW_TAG_subprogram
17952 || last_die
->tag
== DW_TAG_lexical_block
))))
17955 parent_die
= last_die
;
17959 /* Otherwise we skip to the next sibling, if any. */
17960 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17962 /* Back to the top, do it again. */
17966 partial_die_info::partial_die_info (sect_offset sect_off_
,
17967 struct abbrev_info
*abbrev
)
17968 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17972 /* Read a minimal amount of information into the minimal die structure.
17973 INFO_PTR should point just after the initial uleb128 of a DIE. */
17976 partial_die_info::read (const struct die_reader_specs
*reader
,
17977 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17979 struct dwarf2_cu
*cu
= reader
->cu
;
17980 struct dwarf2_per_objfile
*dwarf2_per_objfile
17981 = cu
->per_cu
->dwarf2_per_objfile
;
17983 int has_low_pc_attr
= 0;
17984 int has_high_pc_attr
= 0;
17985 int high_pc_relative
= 0;
17987 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17988 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17990 bool need_reprocess
;
17991 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17992 info_ptr
, &need_reprocess
);
17993 /* String and address offsets that need to do the reprocessing have
17994 already been read at this point, so there is no need to wait until
17995 the loop terminates to do the reprocessing. */
17996 if (need_reprocess
)
17997 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17998 attribute
&attr
= attr_vec
[i
];
17999 /* Store the data if it is of an attribute we want to keep in a
18000 partial symbol table. */
18006 case DW_TAG_compile_unit
:
18007 case DW_TAG_partial_unit
:
18008 case DW_TAG_type_unit
:
18009 /* Compilation units have a DW_AT_name that is a filename, not
18010 a source language identifier. */
18011 case DW_TAG_enumeration_type
:
18012 case DW_TAG_enumerator
:
18013 /* These tags always have simple identifiers already; no need
18014 to canonicalize them. */
18015 name
= DW_STRING (&attr
);
18019 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18022 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18027 case DW_AT_linkage_name
:
18028 case DW_AT_MIPS_linkage_name
:
18029 /* Note that both forms of linkage name might appear. We
18030 assume they will be the same, and we only store the last
18032 linkage_name
= DW_STRING (&attr
);
18035 has_low_pc_attr
= 1;
18036 lowpc
= attr
.value_as_address ();
18038 case DW_AT_high_pc
:
18039 has_high_pc_attr
= 1;
18040 highpc
= attr
.value_as_address ();
18041 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18042 high_pc_relative
= 1;
18044 case DW_AT_location
:
18045 /* Support the .debug_loc offsets. */
18046 if (attr
.form_is_block ())
18048 d
.locdesc
= DW_BLOCK (&attr
);
18050 else if (attr
.form_is_section_offset ())
18052 dwarf2_complex_location_expr_complaint ();
18056 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18057 "partial symbol information");
18060 case DW_AT_external
:
18061 is_external
= DW_UNSND (&attr
);
18063 case DW_AT_declaration
:
18064 is_declaration
= DW_UNSND (&attr
);
18069 case DW_AT_abstract_origin
:
18070 case DW_AT_specification
:
18071 case DW_AT_extension
:
18072 has_specification
= 1;
18073 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18074 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18075 || cu
->per_cu
->is_dwz
);
18077 case DW_AT_sibling
:
18078 /* Ignore absolute siblings, they might point outside of
18079 the current compile unit. */
18080 if (attr
.form
== DW_FORM_ref_addr
)
18081 complaint (_("ignoring absolute DW_AT_sibling"));
18084 const gdb_byte
*buffer
= reader
->buffer
;
18085 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18086 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18088 if (sibling_ptr
< info_ptr
)
18089 complaint (_("DW_AT_sibling points backwards"));
18090 else if (sibling_ptr
> reader
->buffer_end
)
18091 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18093 sibling
= sibling_ptr
;
18096 case DW_AT_byte_size
:
18099 case DW_AT_const_value
:
18100 has_const_value
= 1;
18102 case DW_AT_calling_convention
:
18103 /* DWARF doesn't provide a way to identify a program's source-level
18104 entry point. DW_AT_calling_convention attributes are only meant
18105 to describe functions' calling conventions.
18107 However, because it's a necessary piece of information in
18108 Fortran, and before DWARF 4 DW_CC_program was the only
18109 piece of debugging information whose definition refers to
18110 a 'main program' at all, several compilers marked Fortran
18111 main programs with DW_CC_program --- even when those
18112 functions use the standard calling conventions.
18114 Although DWARF now specifies a way to provide this
18115 information, we support this practice for backward
18117 if (DW_UNSND (&attr
) == DW_CC_program
18118 && cu
->language
== language_fortran
)
18119 main_subprogram
= 1;
18122 if (DW_UNSND (&attr
) == DW_INL_inlined
18123 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18124 may_be_inlined
= 1;
18128 if (tag
== DW_TAG_imported_unit
)
18130 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18131 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18132 || cu
->per_cu
->is_dwz
);
18136 case DW_AT_main_subprogram
:
18137 main_subprogram
= DW_UNSND (&attr
);
18142 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18143 but that requires a full DIE, so instead we just
18145 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18146 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18147 + (need_ranges_base
18151 /* Value of the DW_AT_ranges attribute is the offset in the
18152 .debug_ranges section. */
18153 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18164 /* For Ada, if both the name and the linkage name appear, we prefer
18165 the latter. This lets "catch exception" work better, regardless
18166 of the order in which the name and linkage name were emitted.
18167 Really, though, this is just a workaround for the fact that gdb
18168 doesn't store both the name and the linkage name. */
18169 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18170 name
= linkage_name
;
18172 if (high_pc_relative
)
18175 if (has_low_pc_attr
&& has_high_pc_attr
)
18177 /* When using the GNU linker, .gnu.linkonce. sections are used to
18178 eliminate duplicate copies of functions and vtables and such.
18179 The linker will arbitrarily choose one and discard the others.
18180 The AT_*_pc values for such functions refer to local labels in
18181 these sections. If the section from that file was discarded, the
18182 labels are not in the output, so the relocs get a value of 0.
18183 If this is a discarded function, mark the pc bounds as invalid,
18184 so that GDB will ignore it. */
18185 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18187 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18188 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18190 complaint (_("DW_AT_low_pc %s is zero "
18191 "for DIE at %s [in module %s]"),
18192 paddress (gdbarch
, lowpc
),
18193 sect_offset_str (sect_off
),
18194 objfile_name (objfile
));
18196 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18197 else if (lowpc
>= highpc
)
18199 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18200 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18202 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18203 "for DIE at %s [in module %s]"),
18204 paddress (gdbarch
, lowpc
),
18205 paddress (gdbarch
, highpc
),
18206 sect_offset_str (sect_off
),
18207 objfile_name (objfile
));
18216 /* Find a cached partial DIE at OFFSET in CU. */
18218 struct partial_die_info
*
18219 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18221 struct partial_die_info
*lookup_die
= NULL
;
18222 struct partial_die_info
part_die (sect_off
);
18224 lookup_die
= ((struct partial_die_info
*)
18225 htab_find_with_hash (partial_dies
, &part_die
,
18226 to_underlying (sect_off
)));
18231 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18232 except in the case of .debug_types DIEs which do not reference
18233 outside their CU (they do however referencing other types via
18234 DW_FORM_ref_sig8). */
18236 static const struct cu_partial_die_info
18237 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18239 struct dwarf2_per_objfile
*dwarf2_per_objfile
18240 = cu
->per_cu
->dwarf2_per_objfile
;
18241 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18242 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18243 struct partial_die_info
*pd
= NULL
;
18245 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18246 && cu
->header
.offset_in_cu_p (sect_off
))
18248 pd
= cu
->find_partial_die (sect_off
);
18251 /* We missed recording what we needed.
18252 Load all dies and try again. */
18253 per_cu
= cu
->per_cu
;
18257 /* TUs don't reference other CUs/TUs (except via type signatures). */
18258 if (cu
->per_cu
->is_debug_types
)
18260 error (_("Dwarf Error: Type Unit at offset %s contains"
18261 " external reference to offset %s [in module %s].\n"),
18262 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18263 bfd_get_filename (objfile
->obfd
));
18265 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18266 dwarf2_per_objfile
);
18268 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18269 load_partial_comp_unit (per_cu
);
18271 per_cu
->cu
->last_used
= 0;
18272 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18275 /* If we didn't find it, and not all dies have been loaded,
18276 load them all and try again. */
18278 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18280 per_cu
->load_all_dies
= 1;
18282 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18283 THIS_CU->cu may already be in use. So we can't just free it and
18284 replace its DIEs with the ones we read in. Instead, we leave those
18285 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18286 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18288 load_partial_comp_unit (per_cu
);
18290 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18294 internal_error (__FILE__
, __LINE__
,
18295 _("could not find partial DIE %s "
18296 "in cache [from module %s]\n"),
18297 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18298 return { per_cu
->cu
, pd
};
18301 /* See if we can figure out if the class lives in a namespace. We do
18302 this by looking for a member function; its demangled name will
18303 contain namespace info, if there is any. */
18306 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18307 struct dwarf2_cu
*cu
)
18309 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18310 what template types look like, because the demangler
18311 frequently doesn't give the same name as the debug info. We
18312 could fix this by only using the demangled name to get the
18313 prefix (but see comment in read_structure_type). */
18315 struct partial_die_info
*real_pdi
;
18316 struct partial_die_info
*child_pdi
;
18318 /* If this DIE (this DIE's specification, if any) has a parent, then
18319 we should not do this. We'll prepend the parent's fully qualified
18320 name when we create the partial symbol. */
18322 real_pdi
= struct_pdi
;
18323 while (real_pdi
->has_specification
)
18325 auto res
= find_partial_die (real_pdi
->spec_offset
,
18326 real_pdi
->spec_is_dwz
, cu
);
18327 real_pdi
= res
.pdi
;
18331 if (real_pdi
->die_parent
!= NULL
)
18334 for (child_pdi
= struct_pdi
->die_child
;
18336 child_pdi
= child_pdi
->die_sibling
)
18338 if (child_pdi
->tag
== DW_TAG_subprogram
18339 && child_pdi
->linkage_name
!= NULL
)
18341 gdb::unique_xmalloc_ptr
<char> actual_class_name
18342 (language_class_name_from_physname (cu
->language_defn
,
18343 child_pdi
->linkage_name
));
18344 if (actual_class_name
!= NULL
)
18346 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18347 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18355 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18357 /* Once we've fixed up a die, there's no point in doing so again.
18358 This also avoids a memory leak if we were to call
18359 guess_partial_die_structure_name multiple times. */
18363 /* If we found a reference attribute and the DIE has no name, try
18364 to find a name in the referred to DIE. */
18366 if (name
== NULL
&& has_specification
)
18368 struct partial_die_info
*spec_die
;
18370 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18371 spec_die
= res
.pdi
;
18374 spec_die
->fixup (cu
);
18376 if (spec_die
->name
)
18378 name
= spec_die
->name
;
18380 /* Copy DW_AT_external attribute if it is set. */
18381 if (spec_die
->is_external
)
18382 is_external
= spec_die
->is_external
;
18386 /* Set default names for some unnamed DIEs. */
18388 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18389 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18391 /* If there is no parent die to provide a namespace, and there are
18392 children, see if we can determine the namespace from their linkage
18394 if (cu
->language
== language_cplus
18395 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18396 && die_parent
== NULL
18398 && (tag
== DW_TAG_class_type
18399 || tag
== DW_TAG_structure_type
18400 || tag
== DW_TAG_union_type
))
18401 guess_partial_die_structure_name (this, cu
);
18403 /* GCC might emit a nameless struct or union that has a linkage
18404 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18406 && (tag
== DW_TAG_class_type
18407 || tag
== DW_TAG_interface_type
18408 || tag
== DW_TAG_structure_type
18409 || tag
== DW_TAG_union_type
)
18410 && linkage_name
!= NULL
)
18412 gdb::unique_xmalloc_ptr
<char> demangled
18413 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18414 if (demangled
!= nullptr)
18418 /* Strip any leading namespaces/classes, keep only the base name.
18419 DW_AT_name for named DIEs does not contain the prefixes. */
18420 base
= strrchr (demangled
.get (), ':');
18421 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18424 base
= demangled
.get ();
18426 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18427 name
= objfile
->intern (base
);
18434 /* Process the attributes that had to be skipped in the first round. These
18435 attributes are the ones that need str_offsets_base or addr_base attributes.
18436 They could not have been processed in the first round, because at the time
18437 the values of str_offsets_base or addr_base may not have been known. */
18438 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18439 struct attribute
*attr
)
18441 struct dwarf2_cu
*cu
= reader
->cu
;
18442 switch (attr
->form
)
18444 case DW_FORM_addrx
:
18445 case DW_FORM_GNU_addr_index
:
18446 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18449 case DW_FORM_strx1
:
18450 case DW_FORM_strx2
:
18451 case DW_FORM_strx3
:
18452 case DW_FORM_strx4
:
18453 case DW_FORM_GNU_str_index
:
18455 unsigned int str_index
= DW_UNSND (attr
);
18456 if (reader
->dwo_file
!= NULL
)
18458 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18459 DW_STRING_IS_CANONICAL (attr
) = 0;
18463 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18464 DW_STRING_IS_CANONICAL (attr
) = 0;
18469 gdb_assert_not_reached (_("Unexpected DWARF form."));
18473 /* Read an attribute value described by an attribute form. */
18475 static const gdb_byte
*
18476 read_attribute_value (const struct die_reader_specs
*reader
,
18477 struct attribute
*attr
, unsigned form
,
18478 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18479 bool *need_reprocess
)
18481 struct dwarf2_cu
*cu
= reader
->cu
;
18482 struct dwarf2_per_objfile
*dwarf2_per_objfile
18483 = cu
->per_cu
->dwarf2_per_objfile
;
18484 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18485 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18486 bfd
*abfd
= reader
->abfd
;
18487 struct comp_unit_head
*cu_header
= &cu
->header
;
18488 unsigned int bytes_read
;
18489 struct dwarf_block
*blk
;
18490 *need_reprocess
= false;
18492 attr
->form
= (enum dwarf_form
) form
;
18495 case DW_FORM_ref_addr
:
18496 if (cu
->header
.version
== 2)
18497 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18500 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18502 info_ptr
+= bytes_read
;
18504 case DW_FORM_GNU_ref_alt
:
18505 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18506 info_ptr
+= bytes_read
;
18509 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18510 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18511 info_ptr
+= bytes_read
;
18513 case DW_FORM_block2
:
18514 blk
= dwarf_alloc_block (cu
);
18515 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18517 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18518 info_ptr
+= blk
->size
;
18519 DW_BLOCK (attr
) = blk
;
18521 case DW_FORM_block4
:
18522 blk
= dwarf_alloc_block (cu
);
18523 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18525 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18526 info_ptr
+= blk
->size
;
18527 DW_BLOCK (attr
) = blk
;
18529 case DW_FORM_data2
:
18530 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18533 case DW_FORM_data4
:
18534 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18537 case DW_FORM_data8
:
18538 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18541 case DW_FORM_data16
:
18542 blk
= dwarf_alloc_block (cu
);
18544 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18546 DW_BLOCK (attr
) = blk
;
18548 case DW_FORM_sec_offset
:
18549 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18550 info_ptr
+= bytes_read
;
18552 case DW_FORM_string
:
18553 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18554 DW_STRING_IS_CANONICAL (attr
) = 0;
18555 info_ptr
+= bytes_read
;
18558 if (!cu
->per_cu
->is_dwz
)
18560 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18561 abfd
, info_ptr
, cu_header
,
18563 DW_STRING_IS_CANONICAL (attr
) = 0;
18564 info_ptr
+= bytes_read
;
18568 case DW_FORM_line_strp
:
18569 if (!cu
->per_cu
->is_dwz
)
18571 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18573 cu_header
, &bytes_read
);
18574 DW_STRING_IS_CANONICAL (attr
) = 0;
18575 info_ptr
+= bytes_read
;
18579 case DW_FORM_GNU_strp_alt
:
18581 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18582 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18585 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18586 DW_STRING_IS_CANONICAL (attr
) = 0;
18587 info_ptr
+= bytes_read
;
18590 case DW_FORM_exprloc
:
18591 case DW_FORM_block
:
18592 blk
= dwarf_alloc_block (cu
);
18593 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18594 info_ptr
+= bytes_read
;
18595 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18596 info_ptr
+= blk
->size
;
18597 DW_BLOCK (attr
) = blk
;
18599 case DW_FORM_block1
:
18600 blk
= dwarf_alloc_block (cu
);
18601 blk
->size
= read_1_byte (abfd
, info_ptr
);
18603 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18604 info_ptr
+= blk
->size
;
18605 DW_BLOCK (attr
) = blk
;
18607 case DW_FORM_data1
:
18608 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18612 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18615 case DW_FORM_flag_present
:
18616 DW_UNSND (attr
) = 1;
18618 case DW_FORM_sdata
:
18619 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18620 info_ptr
+= bytes_read
;
18622 case DW_FORM_udata
:
18623 case DW_FORM_rnglistx
:
18624 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18625 info_ptr
+= bytes_read
;
18628 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18629 + read_1_byte (abfd
, info_ptr
));
18633 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18634 + read_2_bytes (abfd
, info_ptr
));
18638 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18639 + read_4_bytes (abfd
, info_ptr
));
18643 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18644 + read_8_bytes (abfd
, info_ptr
));
18647 case DW_FORM_ref_sig8
:
18648 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18651 case DW_FORM_ref_udata
:
18652 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18653 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18654 info_ptr
+= bytes_read
;
18656 case DW_FORM_indirect
:
18657 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18658 info_ptr
+= bytes_read
;
18659 if (form
== DW_FORM_implicit_const
)
18661 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18662 info_ptr
+= bytes_read
;
18664 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18665 info_ptr
, need_reprocess
);
18667 case DW_FORM_implicit_const
:
18668 DW_SND (attr
) = implicit_const
;
18670 case DW_FORM_addrx
:
18671 case DW_FORM_GNU_addr_index
:
18672 *need_reprocess
= true;
18673 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18674 info_ptr
+= bytes_read
;
18677 case DW_FORM_strx1
:
18678 case DW_FORM_strx2
:
18679 case DW_FORM_strx3
:
18680 case DW_FORM_strx4
:
18681 case DW_FORM_GNU_str_index
:
18683 ULONGEST str_index
;
18684 if (form
== DW_FORM_strx1
)
18686 str_index
= read_1_byte (abfd
, info_ptr
);
18689 else if (form
== DW_FORM_strx2
)
18691 str_index
= read_2_bytes (abfd
, info_ptr
);
18694 else if (form
== DW_FORM_strx3
)
18696 str_index
= read_3_bytes (abfd
, info_ptr
);
18699 else if (form
== DW_FORM_strx4
)
18701 str_index
= read_4_bytes (abfd
, info_ptr
);
18706 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18707 info_ptr
+= bytes_read
;
18709 *need_reprocess
= true;
18710 DW_UNSND (attr
) = str_index
;
18714 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18715 dwarf_form_name (form
),
18716 bfd_get_filename (abfd
));
18720 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18721 attr
->form
= DW_FORM_GNU_ref_alt
;
18723 /* We have seen instances where the compiler tried to emit a byte
18724 size attribute of -1 which ended up being encoded as an unsigned
18725 0xffffffff. Although 0xffffffff is technically a valid size value,
18726 an object of this size seems pretty unlikely so we can relatively
18727 safely treat these cases as if the size attribute was invalid and
18728 treat them as zero by default. */
18729 if (attr
->name
== DW_AT_byte_size
18730 && form
== DW_FORM_data4
18731 && DW_UNSND (attr
) >= 0xffffffff)
18734 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18735 hex_string (DW_UNSND (attr
)));
18736 DW_UNSND (attr
) = 0;
18742 /* Read an attribute described by an abbreviated attribute. */
18744 static const gdb_byte
*
18745 read_attribute (const struct die_reader_specs
*reader
,
18746 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18747 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18749 attr
->name
= abbrev
->name
;
18750 return read_attribute_value (reader
, attr
, abbrev
->form
,
18751 abbrev
->implicit_const
, info_ptr
,
18755 /* Cover function for read_initial_length.
18756 Returns the length of the object at BUF, and stores the size of the
18757 initial length in *BYTES_READ and stores the size that offsets will be in
18759 If the initial length size is not equivalent to that specified in
18760 CU_HEADER then issue a complaint.
18761 This is useful when reading non-comp-unit headers. */
18764 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18765 const struct comp_unit_head
*cu_header
,
18766 unsigned int *bytes_read
,
18767 unsigned int *offset_size
)
18769 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18771 gdb_assert (cu_header
->initial_length_size
== 4
18772 || cu_header
->initial_length_size
== 8
18773 || cu_header
->initial_length_size
== 12);
18775 if (cu_header
->initial_length_size
!= *bytes_read
)
18776 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18778 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18782 /* Return pointer to string at section SECT offset STR_OFFSET with error
18783 reporting strings FORM_NAME and SECT_NAME. */
18785 static const char *
18786 read_indirect_string_at_offset_from (struct objfile
*objfile
,
18787 bfd
*abfd
, LONGEST str_offset
,
18788 struct dwarf2_section_info
*sect
,
18789 const char *form_name
,
18790 const char *sect_name
)
18792 sect
->read (objfile
);
18793 if (sect
->buffer
== NULL
)
18794 error (_("%s used without %s section [in module %s]"),
18795 form_name
, sect_name
, bfd_get_filename (abfd
));
18796 if (str_offset
>= sect
->size
)
18797 error (_("%s pointing outside of %s section [in module %s]"),
18798 form_name
, sect_name
, bfd_get_filename (abfd
));
18799 gdb_assert (HOST_CHAR_BIT
== 8);
18800 if (sect
->buffer
[str_offset
] == '\0')
18802 return (const char *) (sect
->buffer
+ str_offset
);
18805 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18807 static const char *
18808 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18809 bfd
*abfd
, LONGEST str_offset
)
18811 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18813 &dwarf2_per_objfile
->str
,
18814 "DW_FORM_strp", ".debug_str");
18817 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
18819 static const char *
18820 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18821 bfd
*abfd
, LONGEST str_offset
)
18823 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18825 &dwarf2_per_objfile
->line_str
,
18826 "DW_FORM_line_strp",
18827 ".debug_line_str");
18830 /* Return pointer to string at .debug_str offset as read from BUF.
18831 BUF is assumed to be in a compilation unit described by CU_HEADER.
18832 Return *BYTES_READ_PTR count of bytes read from BUF. */
18834 static const char *
18835 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18836 const gdb_byte
*buf
,
18837 const struct comp_unit_head
*cu_header
,
18838 unsigned int *bytes_read_ptr
)
18840 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18842 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
18845 /* Return pointer to string at .debug_line_str offset as read from BUF.
18846 BUF is assumed to be in a compilation unit described by CU_HEADER.
18847 Return *BYTES_READ_PTR count of bytes read from BUF. */
18849 static const char *
18850 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18851 bfd
*abfd
, const gdb_byte
*buf
,
18852 const struct comp_unit_head
*cu_header
,
18853 unsigned int *bytes_read_ptr
)
18855 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18857 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
18861 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18862 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18863 ADDR_SIZE is the size of addresses from the CU header. */
18866 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18867 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18870 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18871 bfd
*abfd
= objfile
->obfd
;
18872 const gdb_byte
*info_ptr
;
18873 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18875 dwarf2_per_objfile
->addr
.read (objfile
);
18876 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18877 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18878 objfile_name (objfile
));
18879 if (addr_base_or_zero
+ addr_index
* addr_size
18880 >= dwarf2_per_objfile
->addr
.size
)
18881 error (_("DW_FORM_addr_index pointing outside of "
18882 ".debug_addr section [in module %s]"),
18883 objfile_name (objfile
));
18884 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18885 + addr_base_or_zero
+ addr_index
* addr_size
);
18886 if (addr_size
== 4)
18887 return bfd_get_32 (abfd
, info_ptr
);
18889 return bfd_get_64 (abfd
, info_ptr
);
18892 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18895 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18897 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18898 cu
->addr_base
, cu
->header
.addr_size
);
18901 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18904 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18905 unsigned int *bytes_read
)
18907 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18908 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18910 return read_addr_index (cu
, addr_index
);
18916 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18918 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18919 struct dwarf2_cu
*cu
= per_cu
->cu
;
18920 gdb::optional
<ULONGEST
> addr_base
;
18923 /* We need addr_base and addr_size.
18924 If we don't have PER_CU->cu, we have to get it.
18925 Nasty, but the alternative is storing the needed info in PER_CU,
18926 which at this point doesn't seem justified: it's not clear how frequently
18927 it would get used and it would increase the size of every PER_CU.
18928 Entry points like dwarf2_per_cu_addr_size do a similar thing
18929 so we're not in uncharted territory here.
18930 Alas we need to be a bit more complicated as addr_base is contained
18933 We don't need to read the entire CU(/TU).
18934 We just need the header and top level die.
18936 IWBN to use the aging mechanism to let us lazily later discard the CU.
18937 For now we skip this optimization. */
18941 addr_base
= cu
->addr_base
;
18942 addr_size
= cu
->header
.addr_size
;
18946 cutu_reader
reader (per_cu
, NULL
, 0, false);
18947 addr_base
= reader
.cu
->addr_base
;
18948 addr_size
= reader
.cu
->header
.addr_size
;
18951 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18955 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18956 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18959 static const char *
18960 read_str_index (struct dwarf2_cu
*cu
,
18961 struct dwarf2_section_info
*str_section
,
18962 struct dwarf2_section_info
*str_offsets_section
,
18963 ULONGEST str_offsets_base
, ULONGEST str_index
)
18965 struct dwarf2_per_objfile
*dwarf2_per_objfile
18966 = cu
->per_cu
->dwarf2_per_objfile
;
18967 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18968 const char *objf_name
= objfile_name (objfile
);
18969 bfd
*abfd
= objfile
->obfd
;
18970 const gdb_byte
*info_ptr
;
18971 ULONGEST str_offset
;
18972 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18974 str_section
->read (objfile
);
18975 str_offsets_section
->read (objfile
);
18976 if (str_section
->buffer
== NULL
)
18977 error (_("%s used without %s section"
18978 " in CU at offset %s [in module %s]"),
18979 form_name
, str_section
->get_name (),
18980 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18981 if (str_offsets_section
->buffer
== NULL
)
18982 error (_("%s used without %s section"
18983 " in CU at offset %s [in module %s]"),
18984 form_name
, str_section
->get_name (),
18985 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18986 info_ptr
= (str_offsets_section
->buffer
18988 + str_index
* cu
->header
.offset_size
);
18989 if (cu
->header
.offset_size
== 4)
18990 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18992 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18993 if (str_offset
>= str_section
->size
)
18994 error (_("Offset from %s pointing outside of"
18995 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18996 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18997 return (const char *) (str_section
->buffer
+ str_offset
);
19000 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19002 static const char *
19003 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19005 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19006 ? reader
->cu
->header
.addr_size
: 0;
19007 return read_str_index (reader
->cu
,
19008 &reader
->dwo_file
->sections
.str
,
19009 &reader
->dwo_file
->sections
.str_offsets
,
19010 str_offsets_base
, str_index
);
19013 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19015 static const char *
19016 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19018 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19019 const char *objf_name
= objfile_name (objfile
);
19020 static const char form_name
[] = "DW_FORM_GNU_str_index";
19021 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19023 if (!cu
->str_offsets_base
.has_value ())
19024 error (_("%s used in Fission stub without %s"
19025 " in CU at offset 0x%lx [in module %s]"),
19026 form_name
, str_offsets_attr_name
,
19027 (long) cu
->header
.offset_size
, objf_name
);
19029 return read_str_index (cu
,
19030 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19031 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19032 *cu
->str_offsets_base
, str_index
);
19035 /* Return the length of an LEB128 number in BUF. */
19038 leb128_size (const gdb_byte
*buf
)
19040 const gdb_byte
*begin
= buf
;
19046 if ((byte
& 128) == 0)
19047 return buf
- begin
;
19052 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19061 cu
->language
= language_c
;
19064 case DW_LANG_C_plus_plus
:
19065 case DW_LANG_C_plus_plus_11
:
19066 case DW_LANG_C_plus_plus_14
:
19067 cu
->language
= language_cplus
;
19070 cu
->language
= language_d
;
19072 case DW_LANG_Fortran77
:
19073 case DW_LANG_Fortran90
:
19074 case DW_LANG_Fortran95
:
19075 case DW_LANG_Fortran03
:
19076 case DW_LANG_Fortran08
:
19077 cu
->language
= language_fortran
;
19080 cu
->language
= language_go
;
19082 case DW_LANG_Mips_Assembler
:
19083 cu
->language
= language_asm
;
19085 case DW_LANG_Ada83
:
19086 case DW_LANG_Ada95
:
19087 cu
->language
= language_ada
;
19089 case DW_LANG_Modula2
:
19090 cu
->language
= language_m2
;
19092 case DW_LANG_Pascal83
:
19093 cu
->language
= language_pascal
;
19096 cu
->language
= language_objc
;
19099 case DW_LANG_Rust_old
:
19100 cu
->language
= language_rust
;
19102 case DW_LANG_Cobol74
:
19103 case DW_LANG_Cobol85
:
19105 cu
->language
= language_minimal
;
19108 cu
->language_defn
= language_def (cu
->language
);
19111 /* Return the named attribute or NULL if not there. */
19113 static struct attribute
*
19114 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19119 struct attribute
*spec
= NULL
;
19121 for (i
= 0; i
< die
->num_attrs
; ++i
)
19123 if (die
->attrs
[i
].name
== name
)
19124 return &die
->attrs
[i
];
19125 if (die
->attrs
[i
].name
== DW_AT_specification
19126 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19127 spec
= &die
->attrs
[i
];
19133 die
= follow_die_ref (die
, spec
, &cu
);
19139 /* Return the named attribute or NULL if not there,
19140 but do not follow DW_AT_specification, etc.
19141 This is for use in contexts where we're reading .debug_types dies.
19142 Following DW_AT_specification, DW_AT_abstract_origin will take us
19143 back up the chain, and we want to go down. */
19145 static struct attribute
*
19146 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19150 for (i
= 0; i
< die
->num_attrs
; ++i
)
19151 if (die
->attrs
[i
].name
== name
)
19152 return &die
->attrs
[i
];
19157 /* Return the string associated with a string-typed attribute, or NULL if it
19158 is either not found or is of an incorrect type. */
19160 static const char *
19161 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19163 struct attribute
*attr
;
19164 const char *str
= NULL
;
19166 attr
= dwarf2_attr (die
, name
, cu
);
19170 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19171 || attr
->form
== DW_FORM_string
19172 || attr
->form
== DW_FORM_strx
19173 || attr
->form
== DW_FORM_strx1
19174 || attr
->form
== DW_FORM_strx2
19175 || attr
->form
== DW_FORM_strx3
19176 || attr
->form
== DW_FORM_strx4
19177 || attr
->form
== DW_FORM_GNU_str_index
19178 || attr
->form
== DW_FORM_GNU_strp_alt
)
19179 str
= DW_STRING (attr
);
19181 complaint (_("string type expected for attribute %s for "
19182 "DIE at %s in module %s"),
19183 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19184 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19190 /* Return the dwo name or NULL if not present. If present, it is in either
19191 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19192 static const char *
19193 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19195 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19196 if (dwo_name
== nullptr)
19197 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19201 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19202 and holds a non-zero value. This function should only be used for
19203 DW_FORM_flag or DW_FORM_flag_present attributes. */
19206 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19208 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19210 return (attr
&& DW_UNSND (attr
));
19214 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19216 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19217 which value is non-zero. However, we have to be careful with
19218 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19219 (via dwarf2_flag_true_p) follows this attribute. So we may
19220 end up accidently finding a declaration attribute that belongs
19221 to a different DIE referenced by the specification attribute,
19222 even though the given DIE does not have a declaration attribute. */
19223 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19224 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19227 /* Return the die giving the specification for DIE, if there is
19228 one. *SPEC_CU is the CU containing DIE on input, and the CU
19229 containing the return value on output. If there is no
19230 specification, but there is an abstract origin, that is
19233 static struct die_info
*
19234 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19236 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19239 if (spec_attr
== NULL
)
19240 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19242 if (spec_attr
== NULL
)
19245 return follow_die_ref (die
, spec_attr
, spec_cu
);
19248 /* Stub for free_line_header to match void * callback types. */
19251 free_line_header_voidp (void *arg
)
19253 struct line_header
*lh
= (struct line_header
*) arg
;
19258 /* A convenience function to find the proper .debug_line section for a CU. */
19260 static struct dwarf2_section_info
*
19261 get_debug_line_section (struct dwarf2_cu
*cu
)
19263 struct dwarf2_section_info
*section
;
19264 struct dwarf2_per_objfile
*dwarf2_per_objfile
19265 = cu
->per_cu
->dwarf2_per_objfile
;
19267 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19269 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19270 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19271 else if (cu
->per_cu
->is_dwz
)
19273 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19275 section
= &dwz
->line
;
19278 section
= &dwarf2_per_objfile
->line
;
19283 /* Read directory or file name entry format, starting with byte of
19284 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19285 entries count and the entries themselves in the described entry
19289 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19290 bfd
*abfd
, const gdb_byte
**bufp
,
19291 struct line_header
*lh
,
19292 const struct comp_unit_head
*cu_header
,
19293 void (*callback
) (struct line_header
*lh
,
19296 unsigned int mod_time
,
19297 unsigned int length
))
19299 gdb_byte format_count
, formati
;
19300 ULONGEST data_count
, datai
;
19301 const gdb_byte
*buf
= *bufp
;
19302 const gdb_byte
*format_header_data
;
19303 unsigned int bytes_read
;
19305 format_count
= read_1_byte (abfd
, buf
);
19307 format_header_data
= buf
;
19308 for (formati
= 0; formati
< format_count
; formati
++)
19310 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19312 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19316 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19318 for (datai
= 0; datai
< data_count
; datai
++)
19320 const gdb_byte
*format
= format_header_data
;
19321 struct file_entry fe
;
19323 for (formati
= 0; formati
< format_count
; formati
++)
19325 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19326 format
+= bytes_read
;
19328 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19329 format
+= bytes_read
;
19331 gdb::optional
<const char *> string
;
19332 gdb::optional
<unsigned int> uint
;
19336 case DW_FORM_string
:
19337 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19341 case DW_FORM_line_strp
:
19342 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19349 case DW_FORM_data1
:
19350 uint
.emplace (read_1_byte (abfd
, buf
));
19354 case DW_FORM_data2
:
19355 uint
.emplace (read_2_bytes (abfd
, buf
));
19359 case DW_FORM_data4
:
19360 uint
.emplace (read_4_bytes (abfd
, buf
));
19364 case DW_FORM_data8
:
19365 uint
.emplace (read_8_bytes (abfd
, buf
));
19369 case DW_FORM_data16
:
19370 /* This is used for MD5, but file_entry does not record MD5s. */
19374 case DW_FORM_udata
:
19375 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19379 case DW_FORM_block
:
19380 /* It is valid only for DW_LNCT_timestamp which is ignored by
19385 switch (content_type
)
19388 if (string
.has_value ())
19391 case DW_LNCT_directory_index
:
19392 if (uint
.has_value ())
19393 fe
.d_index
= (dir_index
) *uint
;
19395 case DW_LNCT_timestamp
:
19396 if (uint
.has_value ())
19397 fe
.mod_time
= *uint
;
19400 if (uint
.has_value ())
19406 complaint (_("Unknown format content type %s"),
19407 pulongest (content_type
));
19411 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19417 /* Read the statement program header starting at OFFSET in
19418 .debug_line, or .debug_line.dwo. Return a pointer
19419 to a struct line_header, allocated using xmalloc.
19420 Returns NULL if there is a problem reading the header, e.g., if it
19421 has a version we don't understand.
19423 NOTE: the strings in the include directory and file name tables of
19424 the returned object point into the dwarf line section buffer,
19425 and must not be freed. */
19427 static line_header_up
19428 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19430 const gdb_byte
*line_ptr
;
19431 unsigned int bytes_read
, offset_size
;
19433 const char *cur_dir
, *cur_file
;
19434 struct dwarf2_section_info
*section
;
19436 struct dwarf2_per_objfile
*dwarf2_per_objfile
19437 = cu
->per_cu
->dwarf2_per_objfile
;
19439 section
= get_debug_line_section (cu
);
19440 section
->read (dwarf2_per_objfile
->objfile
);
19441 if (section
->buffer
== NULL
)
19443 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19444 complaint (_("missing .debug_line.dwo section"));
19446 complaint (_("missing .debug_line section"));
19450 /* We can't do this until we know the section is non-empty.
19451 Only then do we know we have such a section. */
19452 abfd
= section
->get_bfd_owner ();
19454 /* Make sure that at least there's room for the total_length field.
19455 That could be 12 bytes long, but we're just going to fudge that. */
19456 if (to_underlying (sect_off
) + 4 >= section
->size
)
19458 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19462 line_header_up
lh (new line_header ());
19464 lh
->sect_off
= sect_off
;
19465 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19467 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19469 /* Read in the header. */
19471 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19472 &bytes_read
, &offset_size
);
19473 line_ptr
+= bytes_read
;
19475 const gdb_byte
*start_here
= line_ptr
;
19477 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19479 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19482 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19483 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19485 if (lh
->version
> 5)
19487 /* This is a version we don't understand. The format could have
19488 changed in ways we don't handle properly so just punt. */
19489 complaint (_("unsupported version in .debug_line section"));
19492 if (lh
->version
>= 5)
19494 gdb_byte segment_selector_size
;
19496 /* Skip address size. */
19497 read_1_byte (abfd
, line_ptr
);
19500 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19502 if (segment_selector_size
!= 0)
19504 complaint (_("unsupported segment selector size %u "
19505 "in .debug_line section"),
19506 segment_selector_size
);
19510 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19511 line_ptr
+= offset_size
;
19512 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19513 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19515 if (lh
->version
>= 4)
19517 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19521 lh
->maximum_ops_per_instruction
= 1;
19523 if (lh
->maximum_ops_per_instruction
== 0)
19525 lh
->maximum_ops_per_instruction
= 1;
19526 complaint (_("invalid maximum_ops_per_instruction "
19527 "in `.debug_line' section"));
19530 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19532 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19534 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19536 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19538 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19540 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19541 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19543 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19547 if (lh
->version
>= 5)
19549 /* Read directory table. */
19550 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19552 [] (struct line_header
*header
, const char *name
,
19553 dir_index d_index
, unsigned int mod_time
,
19554 unsigned int length
)
19556 header
->add_include_dir (name
);
19559 /* Read file name table. */
19560 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19562 [] (struct line_header
*header
, const char *name
,
19563 dir_index d_index
, unsigned int mod_time
,
19564 unsigned int length
)
19566 header
->add_file_name (name
, d_index
, mod_time
, length
);
19571 /* Read directory table. */
19572 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19574 line_ptr
+= bytes_read
;
19575 lh
->add_include_dir (cur_dir
);
19577 line_ptr
+= bytes_read
;
19579 /* Read file name table. */
19580 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19582 unsigned int mod_time
, length
;
19585 line_ptr
+= bytes_read
;
19586 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19587 line_ptr
+= bytes_read
;
19588 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19589 line_ptr
+= bytes_read
;
19590 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19591 line_ptr
+= bytes_read
;
19593 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19595 line_ptr
+= bytes_read
;
19598 if (line_ptr
> (section
->buffer
+ section
->size
))
19599 complaint (_("line number info header doesn't "
19600 "fit in `.debug_line' section"));
19605 /* Subroutine of dwarf_decode_lines to simplify it.
19606 Return the file name of the psymtab for the given file_entry.
19607 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19608 If space for the result is malloc'd, *NAME_HOLDER will be set.
19609 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19611 static const char *
19612 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19613 const dwarf2_psymtab
*pst
,
19614 const char *comp_dir
,
19615 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19617 const char *include_name
= fe
.name
;
19618 const char *include_name_to_compare
= include_name
;
19619 const char *pst_filename
;
19622 const char *dir_name
= fe
.include_dir (lh
);
19624 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19625 if (!IS_ABSOLUTE_PATH (include_name
)
19626 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19628 /* Avoid creating a duplicate psymtab for PST.
19629 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19630 Before we do the comparison, however, we need to account
19631 for DIR_NAME and COMP_DIR.
19632 First prepend dir_name (if non-NULL). If we still don't
19633 have an absolute path prepend comp_dir (if non-NULL).
19634 However, the directory we record in the include-file's
19635 psymtab does not contain COMP_DIR (to match the
19636 corresponding symtab(s)).
19641 bash$ gcc -g ./hello.c
19642 include_name = "hello.c"
19644 DW_AT_comp_dir = comp_dir = "/tmp"
19645 DW_AT_name = "./hello.c"
19649 if (dir_name
!= NULL
)
19651 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19652 include_name
, (char *) NULL
));
19653 include_name
= name_holder
->get ();
19654 include_name_to_compare
= include_name
;
19656 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19658 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19659 include_name
, (char *) NULL
));
19660 include_name_to_compare
= hold_compare
.get ();
19664 pst_filename
= pst
->filename
;
19665 gdb::unique_xmalloc_ptr
<char> copied_name
;
19666 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19668 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19669 pst_filename
, (char *) NULL
));
19670 pst_filename
= copied_name
.get ();
19673 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19677 return include_name
;
19680 /* State machine to track the state of the line number program. */
19682 class lnp_state_machine
19685 /* Initialize a machine state for the start of a line number
19687 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19688 bool record_lines_p
);
19690 file_entry
*current_file ()
19692 /* lh->file_names is 0-based, but the file name numbers in the
19693 statement program are 1-based. */
19694 return m_line_header
->file_name_at (m_file
);
19697 /* Record the line in the state machine. END_SEQUENCE is true if
19698 we're processing the end of a sequence. */
19699 void record_line (bool end_sequence
);
19701 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19702 nop-out rest of the lines in this sequence. */
19703 void check_line_address (struct dwarf2_cu
*cu
,
19704 const gdb_byte
*line_ptr
,
19705 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19707 void handle_set_discriminator (unsigned int discriminator
)
19709 m_discriminator
= discriminator
;
19710 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19713 /* Handle DW_LNE_set_address. */
19714 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19717 address
+= baseaddr
;
19718 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19721 /* Handle DW_LNS_advance_pc. */
19722 void handle_advance_pc (CORE_ADDR adjust
);
19724 /* Handle a special opcode. */
19725 void handle_special_opcode (unsigned char op_code
);
19727 /* Handle DW_LNS_advance_line. */
19728 void handle_advance_line (int line_delta
)
19730 advance_line (line_delta
);
19733 /* Handle DW_LNS_set_file. */
19734 void handle_set_file (file_name_index file
);
19736 /* Handle DW_LNS_negate_stmt. */
19737 void handle_negate_stmt ()
19739 m_is_stmt
= !m_is_stmt
;
19742 /* Handle DW_LNS_const_add_pc. */
19743 void handle_const_add_pc ();
19745 /* Handle DW_LNS_fixed_advance_pc. */
19746 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19748 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19752 /* Handle DW_LNS_copy. */
19753 void handle_copy ()
19755 record_line (false);
19756 m_discriminator
= 0;
19759 /* Handle DW_LNE_end_sequence. */
19760 void handle_end_sequence ()
19762 m_currently_recording_lines
= true;
19766 /* Advance the line by LINE_DELTA. */
19767 void advance_line (int line_delta
)
19769 m_line
+= line_delta
;
19771 if (line_delta
!= 0)
19772 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19775 struct dwarf2_cu
*m_cu
;
19777 gdbarch
*m_gdbarch
;
19779 /* True if we're recording lines.
19780 Otherwise we're building partial symtabs and are just interested in
19781 finding include files mentioned by the line number program. */
19782 bool m_record_lines_p
;
19784 /* The line number header. */
19785 line_header
*m_line_header
;
19787 /* These are part of the standard DWARF line number state machine,
19788 and initialized according to the DWARF spec. */
19790 unsigned char m_op_index
= 0;
19791 /* The line table index of the current file. */
19792 file_name_index m_file
= 1;
19793 unsigned int m_line
= 1;
19795 /* These are initialized in the constructor. */
19797 CORE_ADDR m_address
;
19799 unsigned int m_discriminator
;
19801 /* Additional bits of state we need to track. */
19803 /* The last file that we called dwarf2_start_subfile for.
19804 This is only used for TLLs. */
19805 unsigned int m_last_file
= 0;
19806 /* The last file a line number was recorded for. */
19807 struct subfile
*m_last_subfile
= NULL
;
19809 /* When true, record the lines we decode. */
19810 bool m_currently_recording_lines
= false;
19812 /* The last line number that was recorded, used to coalesce
19813 consecutive entries for the same line. This can happen, for
19814 example, when discriminators are present. PR 17276. */
19815 unsigned int m_last_line
= 0;
19816 bool m_line_has_non_zero_discriminator
= false;
19820 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19822 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19823 / m_line_header
->maximum_ops_per_instruction
)
19824 * m_line_header
->minimum_instruction_length
);
19825 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19826 m_op_index
= ((m_op_index
+ adjust
)
19827 % m_line_header
->maximum_ops_per_instruction
);
19831 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19833 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19834 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19835 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19836 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19837 / m_line_header
->maximum_ops_per_instruction
)
19838 * m_line_header
->minimum_instruction_length
);
19839 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19840 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19841 % m_line_header
->maximum_ops_per_instruction
);
19843 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19844 advance_line (line_delta
);
19845 record_line (false);
19846 m_discriminator
= 0;
19850 lnp_state_machine::handle_set_file (file_name_index file
)
19854 const file_entry
*fe
= current_file ();
19856 dwarf2_debug_line_missing_file_complaint ();
19857 else if (m_record_lines_p
)
19859 const char *dir
= fe
->include_dir (m_line_header
);
19861 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19862 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19863 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19868 lnp_state_machine::handle_const_add_pc ()
19871 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19874 = (((m_op_index
+ adjust
)
19875 / m_line_header
->maximum_ops_per_instruction
)
19876 * m_line_header
->minimum_instruction_length
);
19878 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19879 m_op_index
= ((m_op_index
+ adjust
)
19880 % m_line_header
->maximum_ops_per_instruction
);
19883 /* Return non-zero if we should add LINE to the line number table.
19884 LINE is the line to add, LAST_LINE is the last line that was added,
19885 LAST_SUBFILE is the subfile for LAST_LINE.
19886 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19887 had a non-zero discriminator.
19889 We have to be careful in the presence of discriminators.
19890 E.g., for this line:
19892 for (i = 0; i < 100000; i++);
19894 clang can emit four line number entries for that one line,
19895 each with a different discriminator.
19896 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19898 However, we want gdb to coalesce all four entries into one.
19899 Otherwise the user could stepi into the middle of the line and
19900 gdb would get confused about whether the pc really was in the
19901 middle of the line.
19903 Things are further complicated by the fact that two consecutive
19904 line number entries for the same line is a heuristic used by gcc
19905 to denote the end of the prologue. So we can't just discard duplicate
19906 entries, we have to be selective about it. The heuristic we use is
19907 that we only collapse consecutive entries for the same line if at least
19908 one of those entries has a non-zero discriminator. PR 17276.
19910 Note: Addresses in the line number state machine can never go backwards
19911 within one sequence, thus this coalescing is ok. */
19914 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19915 unsigned int line
, unsigned int last_line
,
19916 int line_has_non_zero_discriminator
,
19917 struct subfile
*last_subfile
)
19919 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19921 if (line
!= last_line
)
19923 /* Same line for the same file that we've seen already.
19924 As a last check, for pr 17276, only record the line if the line
19925 has never had a non-zero discriminator. */
19926 if (!line_has_non_zero_discriminator
)
19931 /* Use the CU's builder to record line number LINE beginning at
19932 address ADDRESS in the line table of subfile SUBFILE. */
19935 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19936 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19937 struct dwarf2_cu
*cu
)
19939 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19941 if (dwarf_line_debug
)
19943 fprintf_unfiltered (gdb_stdlog
,
19944 "Recording line %u, file %s, address %s\n",
19945 line
, lbasename (subfile
->name
),
19946 paddress (gdbarch
, address
));
19950 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19953 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19954 Mark the end of a set of line number records.
19955 The arguments are the same as for dwarf_record_line_1.
19956 If SUBFILE is NULL the request is ignored. */
19959 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19960 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19962 if (subfile
== NULL
)
19965 if (dwarf_line_debug
)
19967 fprintf_unfiltered (gdb_stdlog
,
19968 "Finishing current line, file %s, address %s\n",
19969 lbasename (subfile
->name
),
19970 paddress (gdbarch
, address
));
19973 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19977 lnp_state_machine::record_line (bool end_sequence
)
19979 if (dwarf_line_debug
)
19981 fprintf_unfiltered (gdb_stdlog
,
19982 "Processing actual line %u: file %u,"
19983 " address %s, is_stmt %u, discrim %u%s\n",
19985 paddress (m_gdbarch
, m_address
),
19986 m_is_stmt
, m_discriminator
,
19987 (end_sequence
? "\t(end sequence)" : ""));
19990 file_entry
*fe
= current_file ();
19993 dwarf2_debug_line_missing_file_complaint ();
19994 /* For now we ignore lines not starting on an instruction boundary.
19995 But not when processing end_sequence for compatibility with the
19996 previous version of the code. */
19997 else if (m_op_index
== 0 || end_sequence
)
19999 fe
->included_p
= 1;
20000 if (m_record_lines_p
)
20002 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20005 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20006 m_currently_recording_lines
? m_cu
: nullptr);
20011 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20013 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20014 m_line_has_non_zero_discriminator
,
20017 buildsym_compunit
*builder
= m_cu
->get_builder ();
20018 dwarf_record_line_1 (m_gdbarch
,
20019 builder
->get_current_subfile (),
20020 m_line
, m_address
, is_stmt
,
20021 m_currently_recording_lines
? m_cu
: nullptr);
20023 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20024 m_last_line
= m_line
;
20030 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20031 line_header
*lh
, bool record_lines_p
)
20035 m_record_lines_p
= record_lines_p
;
20036 m_line_header
= lh
;
20038 m_currently_recording_lines
= true;
20040 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20041 was a line entry for it so that the backend has a chance to adjust it
20042 and also record it in case it needs it. This is currently used by MIPS
20043 code, cf. `mips_adjust_dwarf2_line'. */
20044 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20045 m_is_stmt
= lh
->default_is_stmt
;
20046 m_discriminator
= 0;
20050 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20051 const gdb_byte
*line_ptr
,
20052 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20054 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20055 the pc range of the CU. However, we restrict the test to only ADDRESS
20056 values of zero to preserve GDB's previous behaviour which is to handle
20057 the specific case of a function being GC'd by the linker. */
20059 if (address
== 0 && address
< unrelocated_lowpc
)
20061 /* This line table is for a function which has been
20062 GCd by the linker. Ignore it. PR gdb/12528 */
20064 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20065 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20067 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20068 line_offset
, objfile_name (objfile
));
20069 m_currently_recording_lines
= false;
20070 /* Note: m_currently_recording_lines is left as false until we see
20071 DW_LNE_end_sequence. */
20075 /* Subroutine of dwarf_decode_lines to simplify it.
20076 Process the line number information in LH.
20077 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20078 program in order to set included_p for every referenced header. */
20081 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20082 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20084 const gdb_byte
*line_ptr
, *extended_end
;
20085 const gdb_byte
*line_end
;
20086 unsigned int bytes_read
, extended_len
;
20087 unsigned char op_code
, extended_op
;
20088 CORE_ADDR baseaddr
;
20089 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20090 bfd
*abfd
= objfile
->obfd
;
20091 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20092 /* True if we're recording line info (as opposed to building partial
20093 symtabs and just interested in finding include files mentioned by
20094 the line number program). */
20095 bool record_lines_p
= !decode_for_pst_p
;
20097 baseaddr
= objfile
->text_section_offset ();
20099 line_ptr
= lh
->statement_program_start
;
20100 line_end
= lh
->statement_program_end
;
20102 /* Read the statement sequences until there's nothing left. */
20103 while (line_ptr
< line_end
)
20105 /* The DWARF line number program state machine. Reset the state
20106 machine at the start of each sequence. */
20107 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20108 bool end_sequence
= false;
20110 if (record_lines_p
)
20112 /* Start a subfile for the current file of the state
20114 const file_entry
*fe
= state_machine
.current_file ();
20117 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20120 /* Decode the table. */
20121 while (line_ptr
< line_end
&& !end_sequence
)
20123 op_code
= read_1_byte (abfd
, line_ptr
);
20126 if (op_code
>= lh
->opcode_base
)
20128 /* Special opcode. */
20129 state_machine
.handle_special_opcode (op_code
);
20131 else switch (op_code
)
20133 case DW_LNS_extended_op
:
20134 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20136 line_ptr
+= bytes_read
;
20137 extended_end
= line_ptr
+ extended_len
;
20138 extended_op
= read_1_byte (abfd
, line_ptr
);
20140 switch (extended_op
)
20142 case DW_LNE_end_sequence
:
20143 state_machine
.handle_end_sequence ();
20144 end_sequence
= true;
20146 case DW_LNE_set_address
:
20149 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20150 line_ptr
+= bytes_read
;
20152 state_machine
.check_line_address (cu
, line_ptr
,
20153 lowpc
- baseaddr
, address
);
20154 state_machine
.handle_set_address (baseaddr
, address
);
20157 case DW_LNE_define_file
:
20159 const char *cur_file
;
20160 unsigned int mod_time
, length
;
20163 cur_file
= read_direct_string (abfd
, line_ptr
,
20165 line_ptr
+= bytes_read
;
20166 dindex
= (dir_index
)
20167 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20168 line_ptr
+= bytes_read
;
20170 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20171 line_ptr
+= bytes_read
;
20173 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20174 line_ptr
+= bytes_read
;
20175 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20178 case DW_LNE_set_discriminator
:
20180 /* The discriminator is not interesting to the
20181 debugger; just ignore it. We still need to
20182 check its value though:
20183 if there are consecutive entries for the same
20184 (non-prologue) line we want to coalesce them.
20187 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20188 line_ptr
+= bytes_read
;
20190 state_machine
.handle_set_discriminator (discr
);
20194 complaint (_("mangled .debug_line section"));
20197 /* Make sure that we parsed the extended op correctly. If e.g.
20198 we expected a different address size than the producer used,
20199 we may have read the wrong number of bytes. */
20200 if (line_ptr
!= extended_end
)
20202 complaint (_("mangled .debug_line section"));
20207 state_machine
.handle_copy ();
20209 case DW_LNS_advance_pc
:
20212 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20213 line_ptr
+= bytes_read
;
20215 state_machine
.handle_advance_pc (adjust
);
20218 case DW_LNS_advance_line
:
20221 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20222 line_ptr
+= bytes_read
;
20224 state_machine
.handle_advance_line (line_delta
);
20227 case DW_LNS_set_file
:
20229 file_name_index file
20230 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20232 line_ptr
+= bytes_read
;
20234 state_machine
.handle_set_file (file
);
20237 case DW_LNS_set_column
:
20238 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20239 line_ptr
+= bytes_read
;
20241 case DW_LNS_negate_stmt
:
20242 state_machine
.handle_negate_stmt ();
20244 case DW_LNS_set_basic_block
:
20246 /* Add to the address register of the state machine the
20247 address increment value corresponding to special opcode
20248 255. I.e., this value is scaled by the minimum
20249 instruction length since special opcode 255 would have
20250 scaled the increment. */
20251 case DW_LNS_const_add_pc
:
20252 state_machine
.handle_const_add_pc ();
20254 case DW_LNS_fixed_advance_pc
:
20256 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20259 state_machine
.handle_fixed_advance_pc (addr_adj
);
20264 /* Unknown standard opcode, ignore it. */
20267 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20269 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20270 line_ptr
+= bytes_read
;
20277 dwarf2_debug_line_missing_end_sequence_complaint ();
20279 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20280 in which case we still finish recording the last line). */
20281 state_machine
.record_line (true);
20285 /* Decode the Line Number Program (LNP) for the given line_header
20286 structure and CU. The actual information extracted and the type
20287 of structures created from the LNP depends on the value of PST.
20289 1. If PST is NULL, then this procedure uses the data from the program
20290 to create all necessary symbol tables, and their linetables.
20292 2. If PST is not NULL, this procedure reads the program to determine
20293 the list of files included by the unit represented by PST, and
20294 builds all the associated partial symbol tables.
20296 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20297 It is used for relative paths in the line table.
20298 NOTE: When processing partial symtabs (pst != NULL),
20299 comp_dir == pst->dirname.
20301 NOTE: It is important that psymtabs have the same file name (via strcmp)
20302 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20303 symtab we don't use it in the name of the psymtabs we create.
20304 E.g. expand_line_sal requires this when finding psymtabs to expand.
20305 A good testcase for this is mb-inline.exp.
20307 LOWPC is the lowest address in CU (or 0 if not known).
20309 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20310 for its PC<->lines mapping information. Otherwise only the filename
20311 table is read in. */
20314 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20315 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20316 CORE_ADDR lowpc
, int decode_mapping
)
20318 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20319 const int decode_for_pst_p
= (pst
!= NULL
);
20321 if (decode_mapping
)
20322 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20324 if (decode_for_pst_p
)
20326 /* Now that we're done scanning the Line Header Program, we can
20327 create the psymtab of each included file. */
20328 for (auto &file_entry
: lh
->file_names ())
20329 if (file_entry
.included_p
== 1)
20331 gdb::unique_xmalloc_ptr
<char> name_holder
;
20332 const char *include_name
=
20333 psymtab_include_file_name (lh
, file_entry
, pst
,
20334 comp_dir
, &name_holder
);
20335 if (include_name
!= NULL
)
20336 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20341 /* Make sure a symtab is created for every file, even files
20342 which contain only variables (i.e. no code with associated
20344 buildsym_compunit
*builder
= cu
->get_builder ();
20345 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20347 for (auto &fe
: lh
->file_names ())
20349 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20350 if (builder
->get_current_subfile ()->symtab
== NULL
)
20352 builder
->get_current_subfile ()->symtab
20353 = allocate_symtab (cust
,
20354 builder
->get_current_subfile ()->name
);
20356 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20361 /* Start a subfile for DWARF. FILENAME is the name of the file and
20362 DIRNAME the name of the source directory which contains FILENAME
20363 or NULL if not known.
20364 This routine tries to keep line numbers from identical absolute and
20365 relative file names in a common subfile.
20367 Using the `list' example from the GDB testsuite, which resides in
20368 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20369 of /srcdir/list0.c yields the following debugging information for list0.c:
20371 DW_AT_name: /srcdir/list0.c
20372 DW_AT_comp_dir: /compdir
20373 files.files[0].name: list0.h
20374 files.files[0].dir: /srcdir
20375 files.files[1].name: list0.c
20376 files.files[1].dir: /srcdir
20378 The line number information for list0.c has to end up in a single
20379 subfile, so that `break /srcdir/list0.c:1' works as expected.
20380 start_subfile will ensure that this happens provided that we pass the
20381 concatenation of files.files[1].dir and files.files[1].name as the
20385 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20386 const char *dirname
)
20388 gdb::unique_xmalloc_ptr
<char> copy
;
20390 /* In order not to lose the line information directory,
20391 we concatenate it to the filename when it makes sense.
20392 Note that the Dwarf3 standard says (speaking of filenames in line
20393 information): ``The directory index is ignored for file names
20394 that represent full path names''. Thus ignoring dirname in the
20395 `else' branch below isn't an issue. */
20397 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20399 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20400 filename
= copy
.get ();
20403 cu
->get_builder ()->start_subfile (filename
);
20406 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20407 buildsym_compunit constructor. */
20409 struct compunit_symtab
*
20410 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20413 gdb_assert (m_builder
== nullptr);
20415 m_builder
.reset (new struct buildsym_compunit
20416 (per_cu
->dwarf2_per_objfile
->objfile
,
20417 name
, comp_dir
, language
, low_pc
));
20419 list_in_scope
= get_builder ()->get_file_symbols ();
20421 get_builder ()->record_debugformat ("DWARF 2");
20422 get_builder ()->record_producer (producer
);
20424 processing_has_namespace_info
= false;
20426 return get_builder ()->get_compunit_symtab ();
20430 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20431 struct dwarf2_cu
*cu
)
20433 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20434 struct comp_unit_head
*cu_header
= &cu
->header
;
20436 /* NOTE drow/2003-01-30: There used to be a comment and some special
20437 code here to turn a symbol with DW_AT_external and a
20438 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20439 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20440 with some versions of binutils) where shared libraries could have
20441 relocations against symbols in their debug information - the
20442 minimal symbol would have the right address, but the debug info
20443 would not. It's no longer necessary, because we will explicitly
20444 apply relocations when we read in the debug information now. */
20446 /* A DW_AT_location attribute with no contents indicates that a
20447 variable has been optimized away. */
20448 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20450 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20454 /* Handle one degenerate form of location expression specially, to
20455 preserve GDB's previous behavior when section offsets are
20456 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20457 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20459 if (attr
->form_is_block ()
20460 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20461 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20462 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20463 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20464 && (DW_BLOCK (attr
)->size
20465 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20467 unsigned int dummy
;
20469 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20470 SET_SYMBOL_VALUE_ADDRESS
20471 (sym
, cu
->header
.read_address (objfile
->obfd
,
20472 DW_BLOCK (attr
)->data
+ 1,
20475 SET_SYMBOL_VALUE_ADDRESS
20476 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20478 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20479 fixup_symbol_section (sym
, objfile
);
20480 SET_SYMBOL_VALUE_ADDRESS
20482 SYMBOL_VALUE_ADDRESS (sym
)
20483 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20487 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20488 expression evaluator, and use LOC_COMPUTED only when necessary
20489 (i.e. when the value of a register or memory location is
20490 referenced, or a thread-local block, etc.). Then again, it might
20491 not be worthwhile. I'm assuming that it isn't unless performance
20492 or memory numbers show me otherwise. */
20494 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20496 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20497 cu
->has_loclist
= true;
20500 /* Given a pointer to a DWARF information entry, figure out if we need
20501 to make a symbol table entry for it, and if so, create a new entry
20502 and return a pointer to it.
20503 If TYPE is NULL, determine symbol type from the die, otherwise
20504 used the passed type.
20505 If SPACE is not NULL, use it to hold the new symbol. If it is
20506 NULL, allocate a new symbol on the objfile's obstack. */
20508 static struct symbol
*
20509 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20510 struct symbol
*space
)
20512 struct dwarf2_per_objfile
*dwarf2_per_objfile
20513 = cu
->per_cu
->dwarf2_per_objfile
;
20514 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20515 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20516 struct symbol
*sym
= NULL
;
20518 struct attribute
*attr
= NULL
;
20519 struct attribute
*attr2
= NULL
;
20520 CORE_ADDR baseaddr
;
20521 struct pending
**list_to_add
= NULL
;
20523 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20525 baseaddr
= objfile
->text_section_offset ();
20527 name
= dwarf2_name (die
, cu
);
20530 const char *linkagename
;
20531 int suppress_add
= 0;
20536 sym
= allocate_symbol (objfile
);
20537 OBJSTAT (objfile
, n_syms
++);
20539 /* Cache this symbol's name and the name's demangled form (if any). */
20540 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20541 linkagename
= dwarf2_physname (name
, die
, cu
);
20542 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20544 /* Fortran does not have mangling standard and the mangling does differ
20545 between gfortran, iFort etc. */
20546 if (cu
->language
== language_fortran
20547 && symbol_get_demangled_name (sym
) == NULL
)
20548 symbol_set_demangled_name (sym
,
20549 dwarf2_full_name (name
, die
, cu
),
20552 /* Default assumptions.
20553 Use the passed type or decode it from the die. */
20554 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20555 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20557 SYMBOL_TYPE (sym
) = type
;
20559 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20560 attr
= dwarf2_attr (die
,
20561 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20563 if (attr
!= nullptr)
20565 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20568 attr
= dwarf2_attr (die
,
20569 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20571 if (attr
!= nullptr)
20573 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20574 struct file_entry
*fe
;
20576 if (cu
->line_header
!= NULL
)
20577 fe
= cu
->line_header
->file_name_at (file_index
);
20582 complaint (_("file index out of range"));
20584 symbol_set_symtab (sym
, fe
->symtab
);
20590 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20591 if (attr
!= nullptr)
20595 addr
= attr
->value_as_address ();
20596 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20597 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20599 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20600 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20601 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20602 add_symbol_to_list (sym
, cu
->list_in_scope
);
20604 case DW_TAG_subprogram
:
20605 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20607 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20608 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20609 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20610 || cu
->language
== language_ada
20611 || cu
->language
== language_fortran
)
20613 /* Subprograms marked external are stored as a global symbol.
20614 Ada and Fortran subprograms, whether marked external or
20615 not, are always stored as a global symbol, because we want
20616 to be able to access them globally. For instance, we want
20617 to be able to break on a nested subprogram without having
20618 to specify the context. */
20619 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20623 list_to_add
= cu
->list_in_scope
;
20626 case DW_TAG_inlined_subroutine
:
20627 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20629 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20630 SYMBOL_INLINED (sym
) = 1;
20631 list_to_add
= cu
->list_in_scope
;
20633 case DW_TAG_template_value_param
:
20635 /* Fall through. */
20636 case DW_TAG_constant
:
20637 case DW_TAG_variable
:
20638 case DW_TAG_member
:
20639 /* Compilation with minimal debug info may result in
20640 variables with missing type entries. Change the
20641 misleading `void' type to something sensible. */
20642 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20643 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20645 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20646 /* In the case of DW_TAG_member, we should only be called for
20647 static const members. */
20648 if (die
->tag
== DW_TAG_member
)
20650 /* dwarf2_add_field uses die_is_declaration,
20651 so we do the same. */
20652 gdb_assert (die_is_declaration (die
, cu
));
20655 if (attr
!= nullptr)
20657 dwarf2_const_value (attr
, sym
, cu
);
20658 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20661 if (attr2
&& (DW_UNSND (attr2
) != 0))
20662 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20664 list_to_add
= cu
->list_in_scope
;
20668 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20669 if (attr
!= nullptr)
20671 var_decode_location (attr
, sym
, cu
);
20672 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20674 /* Fortran explicitly imports any global symbols to the local
20675 scope by DW_TAG_common_block. */
20676 if (cu
->language
== language_fortran
&& die
->parent
20677 && die
->parent
->tag
== DW_TAG_common_block
)
20680 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20681 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20682 && !dwarf2_per_objfile
->has_section_at_zero
)
20684 /* When a static variable is eliminated by the linker,
20685 the corresponding debug information is not stripped
20686 out, but the variable address is set to null;
20687 do not add such variables into symbol table. */
20689 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20691 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20692 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20693 && dwarf2_per_objfile
->can_copy
)
20695 /* A global static variable might be subject to
20696 copy relocation. We first check for a local
20697 minsym, though, because maybe the symbol was
20698 marked hidden, in which case this would not
20700 bound_minimal_symbol found
20701 = (lookup_minimal_symbol_linkage
20702 (sym
->linkage_name (), objfile
));
20703 if (found
.minsym
!= nullptr)
20704 sym
->maybe_copied
= 1;
20707 /* A variable with DW_AT_external is never static,
20708 but it may be block-scoped. */
20710 = ((cu
->list_in_scope
20711 == cu
->get_builder ()->get_file_symbols ())
20712 ? cu
->get_builder ()->get_global_symbols ()
20713 : cu
->list_in_scope
);
20716 list_to_add
= cu
->list_in_scope
;
20720 /* We do not know the address of this symbol.
20721 If it is an external symbol and we have type information
20722 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20723 The address of the variable will then be determined from
20724 the minimal symbol table whenever the variable is
20726 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20728 /* Fortran explicitly imports any global symbols to the local
20729 scope by DW_TAG_common_block. */
20730 if (cu
->language
== language_fortran
&& die
->parent
20731 && die
->parent
->tag
== DW_TAG_common_block
)
20733 /* SYMBOL_CLASS doesn't matter here because
20734 read_common_block is going to reset it. */
20736 list_to_add
= cu
->list_in_scope
;
20738 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20739 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20741 /* A variable with DW_AT_external is never static, but it
20742 may be block-scoped. */
20744 = ((cu
->list_in_scope
20745 == cu
->get_builder ()->get_file_symbols ())
20746 ? cu
->get_builder ()->get_global_symbols ()
20747 : cu
->list_in_scope
);
20749 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20751 else if (!die_is_declaration (die
, cu
))
20753 /* Use the default LOC_OPTIMIZED_OUT class. */
20754 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20756 list_to_add
= cu
->list_in_scope
;
20760 case DW_TAG_formal_parameter
:
20762 /* If we are inside a function, mark this as an argument. If
20763 not, we might be looking at an argument to an inlined function
20764 when we do not have enough information to show inlined frames;
20765 pretend it's a local variable in that case so that the user can
20767 struct context_stack
*curr
20768 = cu
->get_builder ()->get_current_context_stack ();
20769 if (curr
!= nullptr && curr
->name
!= nullptr)
20770 SYMBOL_IS_ARGUMENT (sym
) = 1;
20771 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20772 if (attr
!= nullptr)
20774 var_decode_location (attr
, sym
, cu
);
20776 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20777 if (attr
!= nullptr)
20779 dwarf2_const_value (attr
, sym
, cu
);
20782 list_to_add
= cu
->list_in_scope
;
20785 case DW_TAG_unspecified_parameters
:
20786 /* From varargs functions; gdb doesn't seem to have any
20787 interest in this information, so just ignore it for now.
20790 case DW_TAG_template_type_param
:
20792 /* Fall through. */
20793 case DW_TAG_class_type
:
20794 case DW_TAG_interface_type
:
20795 case DW_TAG_structure_type
:
20796 case DW_TAG_union_type
:
20797 case DW_TAG_set_type
:
20798 case DW_TAG_enumeration_type
:
20799 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20800 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20803 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20804 really ever be static objects: otherwise, if you try
20805 to, say, break of a class's method and you're in a file
20806 which doesn't mention that class, it won't work unless
20807 the check for all static symbols in lookup_symbol_aux
20808 saves you. See the OtherFileClass tests in
20809 gdb.c++/namespace.exp. */
20813 buildsym_compunit
*builder
= cu
->get_builder ();
20815 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20816 && cu
->language
== language_cplus
20817 ? builder
->get_global_symbols ()
20818 : cu
->list_in_scope
);
20820 /* The semantics of C++ state that "struct foo {
20821 ... }" also defines a typedef for "foo". */
20822 if (cu
->language
== language_cplus
20823 || cu
->language
== language_ada
20824 || cu
->language
== language_d
20825 || cu
->language
== language_rust
)
20827 /* The symbol's name is already allocated along
20828 with this objfile, so we don't need to
20829 duplicate it for the type. */
20830 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20831 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20836 case DW_TAG_typedef
:
20837 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20838 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20839 list_to_add
= cu
->list_in_scope
;
20841 case DW_TAG_base_type
:
20842 case DW_TAG_subrange_type
:
20843 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20844 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20845 list_to_add
= cu
->list_in_scope
;
20847 case DW_TAG_enumerator
:
20848 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20849 if (attr
!= nullptr)
20851 dwarf2_const_value (attr
, sym
, cu
);
20854 /* NOTE: carlton/2003-11-10: See comment above in the
20855 DW_TAG_class_type, etc. block. */
20858 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20859 && cu
->language
== language_cplus
20860 ? cu
->get_builder ()->get_global_symbols ()
20861 : cu
->list_in_scope
);
20864 case DW_TAG_imported_declaration
:
20865 case DW_TAG_namespace
:
20866 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20867 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20869 case DW_TAG_module
:
20870 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20871 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20872 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20874 case DW_TAG_common_block
:
20875 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20876 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20877 add_symbol_to_list (sym
, cu
->list_in_scope
);
20880 /* Not a tag we recognize. Hopefully we aren't processing
20881 trash data, but since we must specifically ignore things
20882 we don't recognize, there is nothing else we should do at
20884 complaint (_("unsupported tag: '%s'"),
20885 dwarf_tag_name (die
->tag
));
20891 sym
->hash_next
= objfile
->template_symbols
;
20892 objfile
->template_symbols
= sym
;
20893 list_to_add
= NULL
;
20896 if (list_to_add
!= NULL
)
20897 add_symbol_to_list (sym
, list_to_add
);
20899 /* For the benefit of old versions of GCC, check for anonymous
20900 namespaces based on the demangled name. */
20901 if (!cu
->processing_has_namespace_info
20902 && cu
->language
== language_cplus
)
20903 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20908 /* Given an attr with a DW_FORM_dataN value in host byte order,
20909 zero-extend it as appropriate for the symbol's type. The DWARF
20910 standard (v4) is not entirely clear about the meaning of using
20911 DW_FORM_dataN for a constant with a signed type, where the type is
20912 wider than the data. The conclusion of a discussion on the DWARF
20913 list was that this is unspecified. We choose to always zero-extend
20914 because that is the interpretation long in use by GCC. */
20917 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20918 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20920 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20921 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20922 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20923 LONGEST l
= DW_UNSND (attr
);
20925 if (bits
< sizeof (*value
) * 8)
20927 l
&= ((LONGEST
) 1 << bits
) - 1;
20930 else if (bits
== sizeof (*value
) * 8)
20934 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20935 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20942 /* Read a constant value from an attribute. Either set *VALUE, or if
20943 the value does not fit in *VALUE, set *BYTES - either already
20944 allocated on the objfile obstack, or newly allocated on OBSTACK,
20945 or, set *BATON, if we translated the constant to a location
20949 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20950 const char *name
, struct obstack
*obstack
,
20951 struct dwarf2_cu
*cu
,
20952 LONGEST
*value
, const gdb_byte
**bytes
,
20953 struct dwarf2_locexpr_baton
**baton
)
20955 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20956 struct comp_unit_head
*cu_header
= &cu
->header
;
20957 struct dwarf_block
*blk
;
20958 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20959 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20965 switch (attr
->form
)
20968 case DW_FORM_addrx
:
20969 case DW_FORM_GNU_addr_index
:
20973 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20974 dwarf2_const_value_length_mismatch_complaint (name
,
20975 cu_header
->addr_size
,
20976 TYPE_LENGTH (type
));
20977 /* Symbols of this form are reasonably rare, so we just
20978 piggyback on the existing location code rather than writing
20979 a new implementation of symbol_computed_ops. */
20980 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20981 (*baton
)->per_cu
= cu
->per_cu
;
20982 gdb_assert ((*baton
)->per_cu
);
20984 (*baton
)->size
= 2 + cu_header
->addr_size
;
20985 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20986 (*baton
)->data
= data
;
20988 data
[0] = DW_OP_addr
;
20989 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20990 byte_order
, DW_ADDR (attr
));
20991 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20994 case DW_FORM_string
:
20997 case DW_FORM_GNU_str_index
:
20998 case DW_FORM_GNU_strp_alt
:
20999 /* DW_STRING is already allocated on the objfile obstack, point
21001 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21003 case DW_FORM_block1
:
21004 case DW_FORM_block2
:
21005 case DW_FORM_block4
:
21006 case DW_FORM_block
:
21007 case DW_FORM_exprloc
:
21008 case DW_FORM_data16
:
21009 blk
= DW_BLOCK (attr
);
21010 if (TYPE_LENGTH (type
) != blk
->size
)
21011 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21012 TYPE_LENGTH (type
));
21013 *bytes
= blk
->data
;
21016 /* The DW_AT_const_value attributes are supposed to carry the
21017 symbol's value "represented as it would be on the target
21018 architecture." By the time we get here, it's already been
21019 converted to host endianness, so we just need to sign- or
21020 zero-extend it as appropriate. */
21021 case DW_FORM_data1
:
21022 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21024 case DW_FORM_data2
:
21025 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21027 case DW_FORM_data4
:
21028 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21030 case DW_FORM_data8
:
21031 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21034 case DW_FORM_sdata
:
21035 case DW_FORM_implicit_const
:
21036 *value
= DW_SND (attr
);
21039 case DW_FORM_udata
:
21040 *value
= DW_UNSND (attr
);
21044 complaint (_("unsupported const value attribute form: '%s'"),
21045 dwarf_form_name (attr
->form
));
21052 /* Copy constant value from an attribute to a symbol. */
21055 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21056 struct dwarf2_cu
*cu
)
21058 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21060 const gdb_byte
*bytes
;
21061 struct dwarf2_locexpr_baton
*baton
;
21063 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21064 sym
->print_name (),
21065 &objfile
->objfile_obstack
, cu
,
21066 &value
, &bytes
, &baton
);
21070 SYMBOL_LOCATION_BATON (sym
) = baton
;
21071 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21073 else if (bytes
!= NULL
)
21075 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21076 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21080 SYMBOL_VALUE (sym
) = value
;
21081 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21085 /* Return the type of the die in question using its DW_AT_type attribute. */
21087 static struct type
*
21088 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21090 struct attribute
*type_attr
;
21092 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21095 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21096 /* A missing DW_AT_type represents a void type. */
21097 return objfile_type (objfile
)->builtin_void
;
21100 return lookup_die_type (die
, type_attr
, cu
);
21103 /* True iff CU's producer generates GNAT Ada auxiliary information
21104 that allows to find parallel types through that information instead
21105 of having to do expensive parallel lookups by type name. */
21108 need_gnat_info (struct dwarf2_cu
*cu
)
21110 /* Assume that the Ada compiler was GNAT, which always produces
21111 the auxiliary information. */
21112 return (cu
->language
== language_ada
);
21115 /* Return the auxiliary type of the die in question using its
21116 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21117 attribute is not present. */
21119 static struct type
*
21120 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21122 struct attribute
*type_attr
;
21124 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21128 return lookup_die_type (die
, type_attr
, cu
);
21131 /* If DIE has a descriptive_type attribute, then set the TYPE's
21132 descriptive type accordingly. */
21135 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21136 struct dwarf2_cu
*cu
)
21138 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21140 if (descriptive_type
)
21142 ALLOCATE_GNAT_AUX_TYPE (type
);
21143 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21147 /* Return the containing type of the die in question using its
21148 DW_AT_containing_type attribute. */
21150 static struct type
*
21151 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21153 struct attribute
*type_attr
;
21154 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21156 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21158 error (_("Dwarf Error: Problem turning containing type into gdb type "
21159 "[in module %s]"), objfile_name (objfile
));
21161 return lookup_die_type (die
, type_attr
, cu
);
21164 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21166 static struct type
*
21167 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21169 struct dwarf2_per_objfile
*dwarf2_per_objfile
21170 = cu
->per_cu
->dwarf2_per_objfile
;
21171 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21174 std::string message
21175 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21176 objfile_name (objfile
),
21177 sect_offset_str (cu
->header
.sect_off
),
21178 sect_offset_str (die
->sect_off
));
21179 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21181 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21184 /* Look up the type of DIE in CU using its type attribute ATTR.
21185 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21186 DW_AT_containing_type.
21187 If there is no type substitute an error marker. */
21189 static struct type
*
21190 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21191 struct dwarf2_cu
*cu
)
21193 struct dwarf2_per_objfile
*dwarf2_per_objfile
21194 = cu
->per_cu
->dwarf2_per_objfile
;
21195 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21196 struct type
*this_type
;
21198 gdb_assert (attr
->name
== DW_AT_type
21199 || attr
->name
== DW_AT_GNAT_descriptive_type
21200 || attr
->name
== DW_AT_containing_type
);
21202 /* First see if we have it cached. */
21204 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21206 struct dwarf2_per_cu_data
*per_cu
;
21207 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21209 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21210 dwarf2_per_objfile
);
21211 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21213 else if (attr
->form_is_ref ())
21215 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21217 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21219 else if (attr
->form
== DW_FORM_ref_sig8
)
21221 ULONGEST signature
= DW_SIGNATURE (attr
);
21223 return get_signatured_type (die
, signature
, cu
);
21227 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21228 " at %s [in module %s]"),
21229 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21230 objfile_name (objfile
));
21231 return build_error_marker_type (cu
, die
);
21234 /* If not cached we need to read it in. */
21236 if (this_type
== NULL
)
21238 struct die_info
*type_die
= NULL
;
21239 struct dwarf2_cu
*type_cu
= cu
;
21241 if (attr
->form_is_ref ())
21242 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21243 if (type_die
== NULL
)
21244 return build_error_marker_type (cu
, die
);
21245 /* If we find the type now, it's probably because the type came
21246 from an inter-CU reference and the type's CU got expanded before
21248 this_type
= read_type_die (type_die
, type_cu
);
21251 /* If we still don't have a type use an error marker. */
21253 if (this_type
== NULL
)
21254 return build_error_marker_type (cu
, die
);
21259 /* Return the type in DIE, CU.
21260 Returns NULL for invalid types.
21262 This first does a lookup in die_type_hash,
21263 and only reads the die in if necessary.
21265 NOTE: This can be called when reading in partial or full symbols. */
21267 static struct type
*
21268 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21270 struct type
*this_type
;
21272 this_type
= get_die_type (die
, cu
);
21276 return read_type_die_1 (die
, cu
);
21279 /* Read the type in DIE, CU.
21280 Returns NULL for invalid types. */
21282 static struct type
*
21283 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21285 struct type
*this_type
= NULL
;
21289 case DW_TAG_class_type
:
21290 case DW_TAG_interface_type
:
21291 case DW_TAG_structure_type
:
21292 case DW_TAG_union_type
:
21293 this_type
= read_structure_type (die
, cu
);
21295 case DW_TAG_enumeration_type
:
21296 this_type
= read_enumeration_type (die
, cu
);
21298 case DW_TAG_subprogram
:
21299 case DW_TAG_subroutine_type
:
21300 case DW_TAG_inlined_subroutine
:
21301 this_type
= read_subroutine_type (die
, cu
);
21303 case DW_TAG_array_type
:
21304 this_type
= read_array_type (die
, cu
);
21306 case DW_TAG_set_type
:
21307 this_type
= read_set_type (die
, cu
);
21309 case DW_TAG_pointer_type
:
21310 this_type
= read_tag_pointer_type (die
, cu
);
21312 case DW_TAG_ptr_to_member_type
:
21313 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21315 case DW_TAG_reference_type
:
21316 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21318 case DW_TAG_rvalue_reference_type
:
21319 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21321 case DW_TAG_const_type
:
21322 this_type
= read_tag_const_type (die
, cu
);
21324 case DW_TAG_volatile_type
:
21325 this_type
= read_tag_volatile_type (die
, cu
);
21327 case DW_TAG_restrict_type
:
21328 this_type
= read_tag_restrict_type (die
, cu
);
21330 case DW_TAG_string_type
:
21331 this_type
= read_tag_string_type (die
, cu
);
21333 case DW_TAG_typedef
:
21334 this_type
= read_typedef (die
, cu
);
21336 case DW_TAG_subrange_type
:
21337 this_type
= read_subrange_type (die
, cu
);
21339 case DW_TAG_base_type
:
21340 this_type
= read_base_type (die
, cu
);
21342 case DW_TAG_unspecified_type
:
21343 this_type
= read_unspecified_type (die
, cu
);
21345 case DW_TAG_namespace
:
21346 this_type
= read_namespace_type (die
, cu
);
21348 case DW_TAG_module
:
21349 this_type
= read_module_type (die
, cu
);
21351 case DW_TAG_atomic_type
:
21352 this_type
= read_tag_atomic_type (die
, cu
);
21355 complaint (_("unexpected tag in read_type_die: '%s'"),
21356 dwarf_tag_name (die
->tag
));
21363 /* See if we can figure out if the class lives in a namespace. We do
21364 this by looking for a member function; its demangled name will
21365 contain namespace info, if there is any.
21366 Return the computed name or NULL.
21367 Space for the result is allocated on the objfile's obstack.
21368 This is the full-die version of guess_partial_die_structure_name.
21369 In this case we know DIE has no useful parent. */
21371 static const char *
21372 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21374 struct die_info
*spec_die
;
21375 struct dwarf2_cu
*spec_cu
;
21376 struct die_info
*child
;
21377 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21380 spec_die
= die_specification (die
, &spec_cu
);
21381 if (spec_die
!= NULL
)
21387 for (child
= die
->child
;
21389 child
= child
->sibling
)
21391 if (child
->tag
== DW_TAG_subprogram
)
21393 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21395 if (linkage_name
!= NULL
)
21397 gdb::unique_xmalloc_ptr
<char> actual_name
21398 (language_class_name_from_physname (cu
->language_defn
,
21400 const char *name
= NULL
;
21402 if (actual_name
!= NULL
)
21404 const char *die_name
= dwarf2_name (die
, cu
);
21406 if (die_name
!= NULL
21407 && strcmp (die_name
, actual_name
.get ()) != 0)
21409 /* Strip off the class name from the full name.
21410 We want the prefix. */
21411 int die_name_len
= strlen (die_name
);
21412 int actual_name_len
= strlen (actual_name
.get ());
21413 const char *ptr
= actual_name
.get ();
21415 /* Test for '::' as a sanity check. */
21416 if (actual_name_len
> die_name_len
+ 2
21417 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21418 name
= obstack_strndup (
21419 &objfile
->per_bfd
->storage_obstack
,
21420 ptr
, actual_name_len
- die_name_len
- 2);
21431 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21432 prefix part in such case. See
21433 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21435 static const char *
21436 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21438 struct attribute
*attr
;
21441 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21442 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21445 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21448 attr
= dw2_linkage_name_attr (die
, cu
);
21449 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21452 /* dwarf2_name had to be already called. */
21453 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21455 /* Strip the base name, keep any leading namespaces/classes. */
21456 base
= strrchr (DW_STRING (attr
), ':');
21457 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21460 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21461 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21463 &base
[-1] - DW_STRING (attr
));
21466 /* Return the name of the namespace/class that DIE is defined within,
21467 or "" if we can't tell. The caller should not xfree the result.
21469 For example, if we're within the method foo() in the following
21479 then determine_prefix on foo's die will return "N::C". */
21481 static const char *
21482 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21484 struct dwarf2_per_objfile
*dwarf2_per_objfile
21485 = cu
->per_cu
->dwarf2_per_objfile
;
21486 struct die_info
*parent
, *spec_die
;
21487 struct dwarf2_cu
*spec_cu
;
21488 struct type
*parent_type
;
21489 const char *retval
;
21491 if (cu
->language
!= language_cplus
21492 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21493 && cu
->language
!= language_rust
)
21496 retval
= anonymous_struct_prefix (die
, cu
);
21500 /* We have to be careful in the presence of DW_AT_specification.
21501 For example, with GCC 3.4, given the code
21505 // Definition of N::foo.
21509 then we'll have a tree of DIEs like this:
21511 1: DW_TAG_compile_unit
21512 2: DW_TAG_namespace // N
21513 3: DW_TAG_subprogram // declaration of N::foo
21514 4: DW_TAG_subprogram // definition of N::foo
21515 DW_AT_specification // refers to die #3
21517 Thus, when processing die #4, we have to pretend that we're in
21518 the context of its DW_AT_specification, namely the contex of die
21521 spec_die
= die_specification (die
, &spec_cu
);
21522 if (spec_die
== NULL
)
21523 parent
= die
->parent
;
21526 parent
= spec_die
->parent
;
21530 if (parent
== NULL
)
21532 else if (parent
->building_fullname
)
21535 const char *parent_name
;
21537 /* It has been seen on RealView 2.2 built binaries,
21538 DW_TAG_template_type_param types actually _defined_ as
21539 children of the parent class:
21542 template class <class Enum> Class{};
21543 Class<enum E> class_e;
21545 1: DW_TAG_class_type (Class)
21546 2: DW_TAG_enumeration_type (E)
21547 3: DW_TAG_enumerator (enum1:0)
21548 3: DW_TAG_enumerator (enum2:1)
21550 2: DW_TAG_template_type_param
21551 DW_AT_type DW_FORM_ref_udata (E)
21553 Besides being broken debug info, it can put GDB into an
21554 infinite loop. Consider:
21556 When we're building the full name for Class<E>, we'll start
21557 at Class, and go look over its template type parameters,
21558 finding E. We'll then try to build the full name of E, and
21559 reach here. We're now trying to build the full name of E,
21560 and look over the parent DIE for containing scope. In the
21561 broken case, if we followed the parent DIE of E, we'd again
21562 find Class, and once again go look at its template type
21563 arguments, etc., etc. Simply don't consider such parent die
21564 as source-level parent of this die (it can't be, the language
21565 doesn't allow it), and break the loop here. */
21566 name
= dwarf2_name (die
, cu
);
21567 parent_name
= dwarf2_name (parent
, cu
);
21568 complaint (_("template param type '%s' defined within parent '%s'"),
21569 name
? name
: "<unknown>",
21570 parent_name
? parent_name
: "<unknown>");
21574 switch (parent
->tag
)
21576 case DW_TAG_namespace
:
21577 parent_type
= read_type_die (parent
, cu
);
21578 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21579 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21580 Work around this problem here. */
21581 if (cu
->language
== language_cplus
21582 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21584 /* We give a name to even anonymous namespaces. */
21585 return TYPE_NAME (parent_type
);
21586 case DW_TAG_class_type
:
21587 case DW_TAG_interface_type
:
21588 case DW_TAG_structure_type
:
21589 case DW_TAG_union_type
:
21590 case DW_TAG_module
:
21591 parent_type
= read_type_die (parent
, cu
);
21592 if (TYPE_NAME (parent_type
) != NULL
)
21593 return TYPE_NAME (parent_type
);
21595 /* An anonymous structure is only allowed non-static data
21596 members; no typedefs, no member functions, et cetera.
21597 So it does not need a prefix. */
21599 case DW_TAG_compile_unit
:
21600 case DW_TAG_partial_unit
:
21601 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21602 if (cu
->language
== language_cplus
21603 && !dwarf2_per_objfile
->types
.empty ()
21604 && die
->child
!= NULL
21605 && (die
->tag
== DW_TAG_class_type
21606 || die
->tag
== DW_TAG_structure_type
21607 || die
->tag
== DW_TAG_union_type
))
21609 const char *name
= guess_full_die_structure_name (die
, cu
);
21614 case DW_TAG_subprogram
:
21615 /* Nested subroutines in Fortran get a prefix with the name
21616 of the parent's subroutine. */
21617 if (cu
->language
== language_fortran
)
21619 if ((die
->tag
== DW_TAG_subprogram
)
21620 && (dwarf2_name (parent
, cu
) != NULL
))
21621 return dwarf2_name (parent
, cu
);
21623 return determine_prefix (parent
, cu
);
21624 case DW_TAG_enumeration_type
:
21625 parent_type
= read_type_die (parent
, cu
);
21626 if (TYPE_DECLARED_CLASS (parent_type
))
21628 if (TYPE_NAME (parent_type
) != NULL
)
21629 return TYPE_NAME (parent_type
);
21632 /* Fall through. */
21634 return determine_prefix (parent
, cu
);
21638 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21639 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21640 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21641 an obconcat, otherwise allocate storage for the result. The CU argument is
21642 used to determine the language and hence, the appropriate separator. */
21644 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21647 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21648 int physname
, struct dwarf2_cu
*cu
)
21650 const char *lead
= "";
21653 if (suffix
== NULL
|| suffix
[0] == '\0'
21654 || prefix
== NULL
|| prefix
[0] == '\0')
21656 else if (cu
->language
== language_d
)
21658 /* For D, the 'main' function could be defined in any module, but it
21659 should never be prefixed. */
21660 if (strcmp (suffix
, "D main") == 0)
21668 else if (cu
->language
== language_fortran
&& physname
)
21670 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21671 DW_AT_MIPS_linkage_name is preferred and used instead. */
21679 if (prefix
== NULL
)
21681 if (suffix
== NULL
)
21688 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21690 strcpy (retval
, lead
);
21691 strcat (retval
, prefix
);
21692 strcat (retval
, sep
);
21693 strcat (retval
, suffix
);
21698 /* We have an obstack. */
21699 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21703 /* Return sibling of die, NULL if no sibling. */
21705 static struct die_info
*
21706 sibling_die (struct die_info
*die
)
21708 return die
->sibling
;
21711 /* Get name of a die, return NULL if not found. */
21713 static const char *
21714 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21715 struct objfile
*objfile
)
21717 if (name
&& cu
->language
== language_cplus
)
21719 std::string canon_name
= cp_canonicalize_string (name
);
21721 if (!canon_name
.empty ())
21723 if (canon_name
!= name
)
21724 name
= objfile
->intern (canon_name
);
21731 /* Get name of a die, return NULL if not found.
21732 Anonymous namespaces are converted to their magic string. */
21734 static const char *
21735 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21737 struct attribute
*attr
;
21738 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21740 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21741 if ((!attr
|| !DW_STRING (attr
))
21742 && die
->tag
!= DW_TAG_namespace
21743 && die
->tag
!= DW_TAG_class_type
21744 && die
->tag
!= DW_TAG_interface_type
21745 && die
->tag
!= DW_TAG_structure_type
21746 && die
->tag
!= DW_TAG_union_type
)
21751 case DW_TAG_compile_unit
:
21752 case DW_TAG_partial_unit
:
21753 /* Compilation units have a DW_AT_name that is a filename, not
21754 a source language identifier. */
21755 case DW_TAG_enumeration_type
:
21756 case DW_TAG_enumerator
:
21757 /* These tags always have simple identifiers already; no need
21758 to canonicalize them. */
21759 return DW_STRING (attr
);
21761 case DW_TAG_namespace
:
21762 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21763 return DW_STRING (attr
);
21764 return CP_ANONYMOUS_NAMESPACE_STR
;
21766 case DW_TAG_class_type
:
21767 case DW_TAG_interface_type
:
21768 case DW_TAG_structure_type
:
21769 case DW_TAG_union_type
:
21770 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21771 structures or unions. These were of the form "._%d" in GCC 4.1,
21772 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21773 and GCC 4.4. We work around this problem by ignoring these. */
21774 if (attr
&& DW_STRING (attr
)
21775 && (startswith (DW_STRING (attr
), "._")
21776 || startswith (DW_STRING (attr
), "<anonymous")))
21779 /* GCC might emit a nameless typedef that has a linkage name. See
21780 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21781 if (!attr
|| DW_STRING (attr
) == NULL
)
21783 attr
= dw2_linkage_name_attr (die
, cu
);
21784 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21787 /* Avoid demangling DW_STRING (attr) the second time on a second
21788 call for the same DIE. */
21789 if (!DW_STRING_IS_CANONICAL (attr
))
21791 gdb::unique_xmalloc_ptr
<char> demangled
21792 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21793 if (demangled
== nullptr)
21796 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21797 DW_STRING_IS_CANONICAL (attr
) = 1;
21800 /* Strip any leading namespaces/classes, keep only the base name.
21801 DW_AT_name for named DIEs does not contain the prefixes. */
21802 const char *base
= strrchr (DW_STRING (attr
), ':');
21803 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21806 return DW_STRING (attr
);
21814 if (!DW_STRING_IS_CANONICAL (attr
))
21816 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21818 DW_STRING_IS_CANONICAL (attr
) = 1;
21820 return DW_STRING (attr
);
21823 /* Return the die that this die in an extension of, or NULL if there
21824 is none. *EXT_CU is the CU containing DIE on input, and the CU
21825 containing the return value on output. */
21827 static struct die_info
*
21828 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21830 struct attribute
*attr
;
21832 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21836 return follow_die_ref (die
, attr
, ext_cu
);
21839 /* A convenience function that returns an "unknown" DWARF name,
21840 including the value of V. STR is the name of the entity being
21841 printed, e.g., "TAG". */
21843 static const char *
21844 dwarf_unknown (const char *str
, unsigned v
)
21846 char *cell
= get_print_cell ();
21847 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21851 /* Convert a DIE tag into its string name. */
21853 static const char *
21854 dwarf_tag_name (unsigned tag
)
21856 const char *name
= get_DW_TAG_name (tag
);
21859 return dwarf_unknown ("TAG", tag
);
21864 /* Convert a DWARF attribute code into its string name. */
21866 static const char *
21867 dwarf_attr_name (unsigned attr
)
21871 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21872 if (attr
== DW_AT_MIPS_fde
)
21873 return "DW_AT_MIPS_fde";
21875 if (attr
== DW_AT_HP_block_index
)
21876 return "DW_AT_HP_block_index";
21879 name
= get_DW_AT_name (attr
);
21882 return dwarf_unknown ("AT", attr
);
21887 /* Convert a DWARF value form code into its string name. */
21889 static const char *
21890 dwarf_form_name (unsigned form
)
21892 const char *name
= get_DW_FORM_name (form
);
21895 return dwarf_unknown ("FORM", form
);
21900 static const char *
21901 dwarf_bool_name (unsigned mybool
)
21909 /* Convert a DWARF type code into its string name. */
21911 static const char *
21912 dwarf_type_encoding_name (unsigned enc
)
21914 const char *name
= get_DW_ATE_name (enc
);
21917 return dwarf_unknown ("ATE", enc
);
21923 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21927 print_spaces (indent
, f
);
21928 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21929 dwarf_tag_name (die
->tag
), die
->abbrev
,
21930 sect_offset_str (die
->sect_off
));
21932 if (die
->parent
!= NULL
)
21934 print_spaces (indent
, f
);
21935 fprintf_unfiltered (f
, " parent at offset: %s\n",
21936 sect_offset_str (die
->parent
->sect_off
));
21939 print_spaces (indent
, f
);
21940 fprintf_unfiltered (f
, " has children: %s\n",
21941 dwarf_bool_name (die
->child
!= NULL
));
21943 print_spaces (indent
, f
);
21944 fprintf_unfiltered (f
, " attributes:\n");
21946 for (i
= 0; i
< die
->num_attrs
; ++i
)
21948 print_spaces (indent
, f
);
21949 fprintf_unfiltered (f
, " %s (%s) ",
21950 dwarf_attr_name (die
->attrs
[i
].name
),
21951 dwarf_form_name (die
->attrs
[i
].form
));
21953 switch (die
->attrs
[i
].form
)
21956 case DW_FORM_addrx
:
21957 case DW_FORM_GNU_addr_index
:
21958 fprintf_unfiltered (f
, "address: ");
21959 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21961 case DW_FORM_block2
:
21962 case DW_FORM_block4
:
21963 case DW_FORM_block
:
21964 case DW_FORM_block1
:
21965 fprintf_unfiltered (f
, "block: size %s",
21966 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21968 case DW_FORM_exprloc
:
21969 fprintf_unfiltered (f
, "expression: size %s",
21970 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21972 case DW_FORM_data16
:
21973 fprintf_unfiltered (f
, "constant of 16 bytes");
21975 case DW_FORM_ref_addr
:
21976 fprintf_unfiltered (f
, "ref address: ");
21977 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21979 case DW_FORM_GNU_ref_alt
:
21980 fprintf_unfiltered (f
, "alt ref address: ");
21981 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21987 case DW_FORM_ref_udata
:
21988 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21989 (long) (DW_UNSND (&die
->attrs
[i
])));
21991 case DW_FORM_data1
:
21992 case DW_FORM_data2
:
21993 case DW_FORM_data4
:
21994 case DW_FORM_data8
:
21995 case DW_FORM_udata
:
21996 case DW_FORM_sdata
:
21997 fprintf_unfiltered (f
, "constant: %s",
21998 pulongest (DW_UNSND (&die
->attrs
[i
])));
22000 case DW_FORM_sec_offset
:
22001 fprintf_unfiltered (f
, "section offset: %s",
22002 pulongest (DW_UNSND (&die
->attrs
[i
])));
22004 case DW_FORM_ref_sig8
:
22005 fprintf_unfiltered (f
, "signature: %s",
22006 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22008 case DW_FORM_string
:
22010 case DW_FORM_line_strp
:
22012 case DW_FORM_GNU_str_index
:
22013 case DW_FORM_GNU_strp_alt
:
22014 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22015 DW_STRING (&die
->attrs
[i
])
22016 ? DW_STRING (&die
->attrs
[i
]) : "",
22017 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22020 if (DW_UNSND (&die
->attrs
[i
]))
22021 fprintf_unfiltered (f
, "flag: TRUE");
22023 fprintf_unfiltered (f
, "flag: FALSE");
22025 case DW_FORM_flag_present
:
22026 fprintf_unfiltered (f
, "flag: TRUE");
22028 case DW_FORM_indirect
:
22029 /* The reader will have reduced the indirect form to
22030 the "base form" so this form should not occur. */
22031 fprintf_unfiltered (f
,
22032 "unexpected attribute form: DW_FORM_indirect");
22034 case DW_FORM_implicit_const
:
22035 fprintf_unfiltered (f
, "constant: %s",
22036 plongest (DW_SND (&die
->attrs
[i
])));
22039 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22040 die
->attrs
[i
].form
);
22043 fprintf_unfiltered (f
, "\n");
22048 dump_die_for_error (struct die_info
*die
)
22050 dump_die_shallow (gdb_stderr
, 0, die
);
22054 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22056 int indent
= level
* 4;
22058 gdb_assert (die
!= NULL
);
22060 if (level
>= max_level
)
22063 dump_die_shallow (f
, indent
, die
);
22065 if (die
->child
!= NULL
)
22067 print_spaces (indent
, f
);
22068 fprintf_unfiltered (f
, " Children:");
22069 if (level
+ 1 < max_level
)
22071 fprintf_unfiltered (f
, "\n");
22072 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22076 fprintf_unfiltered (f
,
22077 " [not printed, max nesting level reached]\n");
22081 if (die
->sibling
!= NULL
&& level
> 0)
22083 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22087 /* This is called from the pdie macro in gdbinit.in.
22088 It's not static so gcc will keep a copy callable from gdb. */
22091 dump_die (struct die_info
*die
, int max_level
)
22093 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22097 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22101 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22102 to_underlying (die
->sect_off
),
22108 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22112 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22114 if (attr
->form_is_ref ())
22115 return (sect_offset
) DW_UNSND (attr
);
22117 complaint (_("unsupported die ref attribute form: '%s'"),
22118 dwarf_form_name (attr
->form
));
22122 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22123 * the value held by the attribute is not constant. */
22126 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22128 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22129 return DW_SND (attr
);
22130 else if (attr
->form
== DW_FORM_udata
22131 || attr
->form
== DW_FORM_data1
22132 || attr
->form
== DW_FORM_data2
22133 || attr
->form
== DW_FORM_data4
22134 || attr
->form
== DW_FORM_data8
)
22135 return DW_UNSND (attr
);
22138 /* For DW_FORM_data16 see attribute::form_is_constant. */
22139 complaint (_("Attribute value is not a constant (%s)"),
22140 dwarf_form_name (attr
->form
));
22141 return default_value
;
22145 /* Follow reference or signature attribute ATTR of SRC_DIE.
22146 On entry *REF_CU is the CU of SRC_DIE.
22147 On exit *REF_CU is the CU of the result. */
22149 static struct die_info
*
22150 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22151 struct dwarf2_cu
**ref_cu
)
22153 struct die_info
*die
;
22155 if (attr
->form_is_ref ())
22156 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22157 else if (attr
->form
== DW_FORM_ref_sig8
)
22158 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22161 dump_die_for_error (src_die
);
22162 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22163 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22169 /* Follow reference OFFSET.
22170 On entry *REF_CU is the CU of the source die referencing OFFSET.
22171 On exit *REF_CU is the CU of the result.
22172 Returns NULL if OFFSET is invalid. */
22174 static struct die_info
*
22175 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22176 struct dwarf2_cu
**ref_cu
)
22178 struct die_info temp_die
;
22179 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22180 struct dwarf2_per_objfile
*dwarf2_per_objfile
22181 = cu
->per_cu
->dwarf2_per_objfile
;
22183 gdb_assert (cu
->per_cu
!= NULL
);
22187 if (cu
->per_cu
->is_debug_types
)
22189 /* .debug_types CUs cannot reference anything outside their CU.
22190 If they need to, they have to reference a signatured type via
22191 DW_FORM_ref_sig8. */
22192 if (!cu
->header
.offset_in_cu_p (sect_off
))
22195 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22196 || !cu
->header
.offset_in_cu_p (sect_off
))
22198 struct dwarf2_per_cu_data
*per_cu
;
22200 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22201 dwarf2_per_objfile
);
22203 /* If necessary, add it to the queue and load its DIEs. */
22204 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22205 load_full_comp_unit (per_cu
, false, cu
->language
);
22207 target_cu
= per_cu
->cu
;
22209 else if (cu
->dies
== NULL
)
22211 /* We're loading full DIEs during partial symbol reading. */
22212 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22213 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22216 *ref_cu
= target_cu
;
22217 temp_die
.sect_off
= sect_off
;
22219 if (target_cu
!= cu
)
22220 target_cu
->ancestor
= cu
;
22222 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22224 to_underlying (sect_off
));
22227 /* Follow reference attribute ATTR of SRC_DIE.
22228 On entry *REF_CU is the CU of SRC_DIE.
22229 On exit *REF_CU is the CU of the result. */
22231 static struct die_info
*
22232 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22233 struct dwarf2_cu
**ref_cu
)
22235 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22236 struct dwarf2_cu
*cu
= *ref_cu
;
22237 struct die_info
*die
;
22239 die
= follow_die_offset (sect_off
,
22240 (attr
->form
== DW_FORM_GNU_ref_alt
22241 || cu
->per_cu
->is_dwz
),
22244 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22245 "at %s [in module %s]"),
22246 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22247 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22254 struct dwarf2_locexpr_baton
22255 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22256 dwarf2_per_cu_data
*per_cu
,
22257 CORE_ADDR (*get_frame_pc
) (void *baton
),
22258 void *baton
, bool resolve_abstract_p
)
22260 struct dwarf2_cu
*cu
;
22261 struct die_info
*die
;
22262 struct attribute
*attr
;
22263 struct dwarf2_locexpr_baton retval
;
22264 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22265 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22267 if (per_cu
->cu
== NULL
)
22268 load_cu (per_cu
, false);
22272 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22273 Instead just throw an error, not much else we can do. */
22274 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22275 sect_offset_str (sect_off
), objfile_name (objfile
));
22278 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22280 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22281 sect_offset_str (sect_off
), objfile_name (objfile
));
22283 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22284 if (!attr
&& resolve_abstract_p
22285 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22286 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22288 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22289 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22290 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22292 for (const auto &cand_off
22293 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22295 struct dwarf2_cu
*cand_cu
= cu
;
22296 struct die_info
*cand
22297 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22300 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22303 CORE_ADDR pc_low
, pc_high
;
22304 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22305 if (pc_low
== ((CORE_ADDR
) -1))
22307 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22308 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22309 if (!(pc_low
<= pc
&& pc
< pc_high
))
22313 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22320 /* DWARF: "If there is no such attribute, then there is no effect.".
22321 DATA is ignored if SIZE is 0. */
22323 retval
.data
= NULL
;
22326 else if (attr
->form_is_section_offset ())
22328 struct dwarf2_loclist_baton loclist_baton
;
22329 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22332 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22334 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22336 retval
.size
= size
;
22340 if (!attr
->form_is_block ())
22341 error (_("Dwarf Error: DIE at %s referenced in module %s "
22342 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22343 sect_offset_str (sect_off
), objfile_name (objfile
));
22345 retval
.data
= DW_BLOCK (attr
)->data
;
22346 retval
.size
= DW_BLOCK (attr
)->size
;
22348 retval
.per_cu
= cu
->per_cu
;
22350 age_cached_comp_units (dwarf2_per_objfile
);
22357 struct dwarf2_locexpr_baton
22358 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22359 dwarf2_per_cu_data
*per_cu
,
22360 CORE_ADDR (*get_frame_pc
) (void *baton
),
22363 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22365 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22368 /* Write a constant of a given type as target-ordered bytes into
22371 static const gdb_byte
*
22372 write_constant_as_bytes (struct obstack
*obstack
,
22373 enum bfd_endian byte_order
,
22380 *len
= TYPE_LENGTH (type
);
22381 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22382 store_unsigned_integer (result
, *len
, byte_order
, value
);
22390 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22391 dwarf2_per_cu_data
*per_cu
,
22395 struct dwarf2_cu
*cu
;
22396 struct die_info
*die
;
22397 struct attribute
*attr
;
22398 const gdb_byte
*result
= NULL
;
22401 enum bfd_endian byte_order
;
22402 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22404 if (per_cu
->cu
== NULL
)
22405 load_cu (per_cu
, false);
22409 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22410 Instead just throw an error, not much else we can do. */
22411 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22412 sect_offset_str (sect_off
), objfile_name (objfile
));
22415 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22417 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22418 sect_offset_str (sect_off
), objfile_name (objfile
));
22420 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22424 byte_order
= (bfd_big_endian (objfile
->obfd
)
22425 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22427 switch (attr
->form
)
22430 case DW_FORM_addrx
:
22431 case DW_FORM_GNU_addr_index
:
22435 *len
= cu
->header
.addr_size
;
22436 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22437 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22441 case DW_FORM_string
:
22444 case DW_FORM_GNU_str_index
:
22445 case DW_FORM_GNU_strp_alt
:
22446 /* DW_STRING is already allocated on the objfile obstack, point
22448 result
= (const gdb_byte
*) DW_STRING (attr
);
22449 *len
= strlen (DW_STRING (attr
));
22451 case DW_FORM_block1
:
22452 case DW_FORM_block2
:
22453 case DW_FORM_block4
:
22454 case DW_FORM_block
:
22455 case DW_FORM_exprloc
:
22456 case DW_FORM_data16
:
22457 result
= DW_BLOCK (attr
)->data
;
22458 *len
= DW_BLOCK (attr
)->size
;
22461 /* The DW_AT_const_value attributes are supposed to carry the
22462 symbol's value "represented as it would be on the target
22463 architecture." By the time we get here, it's already been
22464 converted to host endianness, so we just need to sign- or
22465 zero-extend it as appropriate. */
22466 case DW_FORM_data1
:
22467 type
= die_type (die
, cu
);
22468 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22469 if (result
== NULL
)
22470 result
= write_constant_as_bytes (obstack
, byte_order
,
22473 case DW_FORM_data2
:
22474 type
= die_type (die
, cu
);
22475 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22476 if (result
== NULL
)
22477 result
= write_constant_as_bytes (obstack
, byte_order
,
22480 case DW_FORM_data4
:
22481 type
= die_type (die
, cu
);
22482 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22483 if (result
== NULL
)
22484 result
= write_constant_as_bytes (obstack
, byte_order
,
22487 case DW_FORM_data8
:
22488 type
= die_type (die
, cu
);
22489 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22490 if (result
== NULL
)
22491 result
= write_constant_as_bytes (obstack
, byte_order
,
22495 case DW_FORM_sdata
:
22496 case DW_FORM_implicit_const
:
22497 type
= die_type (die
, cu
);
22498 result
= write_constant_as_bytes (obstack
, byte_order
,
22499 type
, DW_SND (attr
), len
);
22502 case DW_FORM_udata
:
22503 type
= die_type (die
, cu
);
22504 result
= write_constant_as_bytes (obstack
, byte_order
,
22505 type
, DW_UNSND (attr
), len
);
22509 complaint (_("unsupported const value attribute form: '%s'"),
22510 dwarf_form_name (attr
->form
));
22520 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22521 dwarf2_per_cu_data
*per_cu
)
22523 struct dwarf2_cu
*cu
;
22524 struct die_info
*die
;
22526 if (per_cu
->cu
== NULL
)
22527 load_cu (per_cu
, false);
22532 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22536 return die_type (die
, cu
);
22542 dwarf2_get_die_type (cu_offset die_offset
,
22543 struct dwarf2_per_cu_data
*per_cu
)
22545 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22546 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22549 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22550 On entry *REF_CU is the CU of SRC_DIE.
22551 On exit *REF_CU is the CU of the result.
22552 Returns NULL if the referenced DIE isn't found. */
22554 static struct die_info
*
22555 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22556 struct dwarf2_cu
**ref_cu
)
22558 struct die_info temp_die
;
22559 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22560 struct die_info
*die
;
22562 /* While it might be nice to assert sig_type->type == NULL here,
22563 we can get here for DW_AT_imported_declaration where we need
22564 the DIE not the type. */
22566 /* If necessary, add it to the queue and load its DIEs. */
22568 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22569 read_signatured_type (sig_type
);
22571 sig_cu
= sig_type
->per_cu
.cu
;
22572 gdb_assert (sig_cu
!= NULL
);
22573 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22574 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22575 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22576 to_underlying (temp_die
.sect_off
));
22579 struct dwarf2_per_objfile
*dwarf2_per_objfile
22580 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22582 /* For .gdb_index version 7 keep track of included TUs.
22583 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22584 if (dwarf2_per_objfile
->index_table
!= NULL
22585 && dwarf2_per_objfile
->index_table
->version
<= 7)
22587 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22592 sig_cu
->ancestor
= cu
;
22600 /* Follow signatured type referenced by ATTR in SRC_DIE.
22601 On entry *REF_CU is the CU of SRC_DIE.
22602 On exit *REF_CU is the CU of the result.
22603 The result is the DIE of the type.
22604 If the referenced type cannot be found an error is thrown. */
22606 static struct die_info
*
22607 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22608 struct dwarf2_cu
**ref_cu
)
22610 ULONGEST signature
= DW_SIGNATURE (attr
);
22611 struct signatured_type
*sig_type
;
22612 struct die_info
*die
;
22614 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22616 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22617 /* sig_type will be NULL if the signatured type is missing from
22619 if (sig_type
== NULL
)
22621 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22622 " from DIE at %s [in module %s]"),
22623 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22624 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22627 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22630 dump_die_for_error (src_die
);
22631 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22632 " from DIE at %s [in module %s]"),
22633 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22634 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22640 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22641 reading in and processing the type unit if necessary. */
22643 static struct type
*
22644 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22645 struct dwarf2_cu
*cu
)
22647 struct dwarf2_per_objfile
*dwarf2_per_objfile
22648 = cu
->per_cu
->dwarf2_per_objfile
;
22649 struct signatured_type
*sig_type
;
22650 struct dwarf2_cu
*type_cu
;
22651 struct die_info
*type_die
;
22654 sig_type
= lookup_signatured_type (cu
, signature
);
22655 /* sig_type will be NULL if the signatured type is missing from
22657 if (sig_type
== NULL
)
22659 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22660 " from DIE at %s [in module %s]"),
22661 hex_string (signature
), sect_offset_str (die
->sect_off
),
22662 objfile_name (dwarf2_per_objfile
->objfile
));
22663 return build_error_marker_type (cu
, die
);
22666 /* If we already know the type we're done. */
22667 if (sig_type
->type
!= NULL
)
22668 return sig_type
->type
;
22671 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22672 if (type_die
!= NULL
)
22674 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22675 is created. This is important, for example, because for c++ classes
22676 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22677 type
= read_type_die (type_die
, type_cu
);
22680 complaint (_("Dwarf Error: Cannot build signatured type %s"
22681 " referenced from DIE at %s [in module %s]"),
22682 hex_string (signature
), sect_offset_str (die
->sect_off
),
22683 objfile_name (dwarf2_per_objfile
->objfile
));
22684 type
= build_error_marker_type (cu
, die
);
22689 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22690 " from DIE at %s [in module %s]"),
22691 hex_string (signature
), sect_offset_str (die
->sect_off
),
22692 objfile_name (dwarf2_per_objfile
->objfile
));
22693 type
= build_error_marker_type (cu
, die
);
22695 sig_type
->type
= type
;
22700 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22701 reading in and processing the type unit if necessary. */
22703 static struct type
*
22704 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22705 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22707 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22708 if (attr
->form_is_ref ())
22710 struct dwarf2_cu
*type_cu
= cu
;
22711 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22713 return read_type_die (type_die
, type_cu
);
22715 else if (attr
->form
== DW_FORM_ref_sig8
)
22717 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22721 struct dwarf2_per_objfile
*dwarf2_per_objfile
22722 = cu
->per_cu
->dwarf2_per_objfile
;
22724 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22725 " at %s [in module %s]"),
22726 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22727 objfile_name (dwarf2_per_objfile
->objfile
));
22728 return build_error_marker_type (cu
, die
);
22732 /* Load the DIEs associated with type unit PER_CU into memory. */
22735 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22737 struct signatured_type
*sig_type
;
22739 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22740 gdb_assert (! per_cu
->type_unit_group_p ());
22742 /* We have the per_cu, but we need the signatured_type.
22743 Fortunately this is an easy translation. */
22744 gdb_assert (per_cu
->is_debug_types
);
22745 sig_type
= (struct signatured_type
*) per_cu
;
22747 gdb_assert (per_cu
->cu
== NULL
);
22749 read_signatured_type (sig_type
);
22751 gdb_assert (per_cu
->cu
!= NULL
);
22754 /* Read in a signatured type and build its CU and DIEs.
22755 If the type is a stub for the real type in a DWO file,
22756 read in the real type from the DWO file as well. */
22759 read_signatured_type (struct signatured_type
*sig_type
)
22761 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22763 gdb_assert (per_cu
->is_debug_types
);
22764 gdb_assert (per_cu
->cu
== NULL
);
22766 cutu_reader
reader (per_cu
, NULL
, 0, false);
22768 if (!reader
.dummy_p
)
22770 struct dwarf2_cu
*cu
= reader
.cu
;
22771 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22773 gdb_assert (cu
->die_hash
== NULL
);
22775 htab_create_alloc_ex (cu
->header
.length
/ 12,
22779 &cu
->comp_unit_obstack
,
22780 hashtab_obstack_allocate
,
22781 dummy_obstack_deallocate
);
22783 if (reader
.comp_unit_die
->has_children
)
22784 reader
.comp_unit_die
->child
22785 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22786 reader
.comp_unit_die
);
22787 cu
->dies
= reader
.comp_unit_die
;
22788 /* comp_unit_die is not stored in die_hash, no need. */
22790 /* We try not to read any attributes in this function, because
22791 not all CUs needed for references have been loaded yet, and
22792 symbol table processing isn't initialized. But we have to
22793 set the CU language, or we won't be able to build types
22794 correctly. Similarly, if we do not read the producer, we can
22795 not apply producer-specific interpretation. */
22796 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22801 sig_type
->per_cu
.tu_read
= 1;
22804 /* Decode simple location descriptions.
22805 Given a pointer to a dwarf block that defines a location, compute
22806 the location and return the value.
22808 NOTE drow/2003-11-18: This function is called in two situations
22809 now: for the address of static or global variables (partial symbols
22810 only) and for offsets into structures which are expected to be
22811 (more or less) constant. The partial symbol case should go away,
22812 and only the constant case should remain. That will let this
22813 function complain more accurately. A few special modes are allowed
22814 without complaint for global variables (for instance, global
22815 register values and thread-local values).
22817 A location description containing no operations indicates that the
22818 object is optimized out. The return value is 0 for that case.
22819 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22820 callers will only want a very basic result and this can become a
22823 Note that stack[0] is unused except as a default error return. */
22826 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22828 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22830 size_t size
= blk
->size
;
22831 const gdb_byte
*data
= blk
->data
;
22832 CORE_ADDR stack
[64];
22834 unsigned int bytes_read
, unsnd
;
22840 stack
[++stacki
] = 0;
22879 stack
[++stacki
] = op
- DW_OP_lit0
;
22914 stack
[++stacki
] = op
- DW_OP_reg0
;
22916 dwarf2_complex_location_expr_complaint ();
22920 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22922 stack
[++stacki
] = unsnd
;
22924 dwarf2_complex_location_expr_complaint ();
22928 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22933 case DW_OP_const1u
:
22934 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22938 case DW_OP_const1s
:
22939 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22943 case DW_OP_const2u
:
22944 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22948 case DW_OP_const2s
:
22949 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22953 case DW_OP_const4u
:
22954 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22958 case DW_OP_const4s
:
22959 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22963 case DW_OP_const8u
:
22964 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22969 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22975 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22980 stack
[stacki
+ 1] = stack
[stacki
];
22985 stack
[stacki
- 1] += stack
[stacki
];
22989 case DW_OP_plus_uconst
:
22990 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22996 stack
[stacki
- 1] -= stack
[stacki
];
23001 /* If we're not the last op, then we definitely can't encode
23002 this using GDB's address_class enum. This is valid for partial
23003 global symbols, although the variable's address will be bogus
23006 dwarf2_complex_location_expr_complaint ();
23009 case DW_OP_GNU_push_tls_address
:
23010 case DW_OP_form_tls_address
:
23011 /* The top of the stack has the offset from the beginning
23012 of the thread control block at which the variable is located. */
23013 /* Nothing should follow this operator, so the top of stack would
23015 /* This is valid for partial global symbols, but the variable's
23016 address will be bogus in the psymtab. Make it always at least
23017 non-zero to not look as a variable garbage collected by linker
23018 which have DW_OP_addr 0. */
23020 dwarf2_complex_location_expr_complaint ();
23024 case DW_OP_GNU_uninit
:
23028 case DW_OP_GNU_addr_index
:
23029 case DW_OP_GNU_const_index
:
23030 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23037 const char *name
= get_DW_OP_name (op
);
23040 complaint (_("unsupported stack op: '%s'"),
23043 complaint (_("unsupported stack op: '%02x'"),
23047 return (stack
[stacki
]);
23050 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23051 outside of the allocated space. Also enforce minimum>0. */
23052 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23054 complaint (_("location description stack overflow"));
23060 complaint (_("location description stack underflow"));
23064 return (stack
[stacki
]);
23067 /* memory allocation interface */
23069 static struct dwarf_block
*
23070 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23072 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23075 static struct die_info
*
23076 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23078 struct die_info
*die
;
23079 size_t size
= sizeof (struct die_info
);
23082 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23084 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23085 memset (die
, 0, sizeof (struct die_info
));
23090 /* Macro support. */
23092 static struct macro_source_file
*
23093 macro_start_file (struct dwarf2_cu
*cu
,
23094 int file
, int line
,
23095 struct macro_source_file
*current_file
,
23096 struct line_header
*lh
)
23098 /* File name relative to the compilation directory of this source file. */
23099 gdb::unique_xmalloc_ptr
<char> file_name
= lh
->file_file_name (file
);
23101 if (! current_file
)
23103 /* Note: We don't create a macro table for this compilation unit
23104 at all until we actually get a filename. */
23105 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23107 /* If we have no current file, then this must be the start_file
23108 directive for the compilation unit's main source file. */
23109 current_file
= macro_set_main (macro_table
, file_name
.get ());
23110 macro_define_special (macro_table
);
23113 current_file
= macro_include (current_file
, line
, file_name
.get ());
23115 return current_file
;
23118 static const char *
23119 consume_improper_spaces (const char *p
, const char *body
)
23123 complaint (_("macro definition contains spaces "
23124 "in formal argument list:\n`%s'"),
23136 parse_macro_definition (struct macro_source_file
*file
, int line
,
23141 /* The body string takes one of two forms. For object-like macro
23142 definitions, it should be:
23144 <macro name> " " <definition>
23146 For function-like macro definitions, it should be:
23148 <macro name> "() " <definition>
23150 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23152 Spaces may appear only where explicitly indicated, and in the
23155 The Dwarf 2 spec says that an object-like macro's name is always
23156 followed by a space, but versions of GCC around March 2002 omit
23157 the space when the macro's definition is the empty string.
23159 The Dwarf 2 spec says that there should be no spaces between the
23160 formal arguments in a function-like macro's formal argument list,
23161 but versions of GCC around March 2002 include spaces after the
23165 /* Find the extent of the macro name. The macro name is terminated
23166 by either a space or null character (for an object-like macro) or
23167 an opening paren (for a function-like macro). */
23168 for (p
= body
; *p
; p
++)
23169 if (*p
== ' ' || *p
== '(')
23172 if (*p
== ' ' || *p
== '\0')
23174 /* It's an object-like macro. */
23175 int name_len
= p
- body
;
23176 std::string
name (body
, name_len
);
23177 const char *replacement
;
23180 replacement
= body
+ name_len
+ 1;
23183 dwarf2_macro_malformed_definition_complaint (body
);
23184 replacement
= body
+ name_len
;
23187 macro_define_object (file
, line
, name
.c_str (), replacement
);
23189 else if (*p
== '(')
23191 /* It's a function-like macro. */
23192 std::string
name (body
, p
- body
);
23195 char **argv
= XNEWVEC (char *, argv_size
);
23199 p
= consume_improper_spaces (p
, body
);
23201 /* Parse the formal argument list. */
23202 while (*p
&& *p
!= ')')
23204 /* Find the extent of the current argument name. */
23205 const char *arg_start
= p
;
23207 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23210 if (! *p
|| p
== arg_start
)
23211 dwarf2_macro_malformed_definition_complaint (body
);
23214 /* Make sure argv has room for the new argument. */
23215 if (argc
>= argv_size
)
23218 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23221 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23224 p
= consume_improper_spaces (p
, body
);
23226 /* Consume the comma, if present. */
23231 p
= consume_improper_spaces (p
, body
);
23240 /* Perfectly formed definition, no complaints. */
23241 macro_define_function (file
, line
, name
.c_str (),
23242 argc
, (const char **) argv
,
23244 else if (*p
== '\0')
23246 /* Complain, but do define it. */
23247 dwarf2_macro_malformed_definition_complaint (body
);
23248 macro_define_function (file
, line
, name
.c_str (),
23249 argc
, (const char **) argv
,
23253 /* Just complain. */
23254 dwarf2_macro_malformed_definition_complaint (body
);
23257 /* Just complain. */
23258 dwarf2_macro_malformed_definition_complaint (body
);
23263 for (i
= 0; i
< argc
; i
++)
23269 dwarf2_macro_malformed_definition_complaint (body
);
23272 /* Skip some bytes from BYTES according to the form given in FORM.
23273 Returns the new pointer. */
23275 static const gdb_byte
*
23276 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23277 enum dwarf_form form
,
23278 unsigned int offset_size
,
23279 struct dwarf2_section_info
*section
)
23281 unsigned int bytes_read
;
23285 case DW_FORM_data1
:
23290 case DW_FORM_data2
:
23294 case DW_FORM_data4
:
23298 case DW_FORM_data8
:
23302 case DW_FORM_data16
:
23306 case DW_FORM_string
:
23307 read_direct_string (abfd
, bytes
, &bytes_read
);
23308 bytes
+= bytes_read
;
23311 case DW_FORM_sec_offset
:
23313 case DW_FORM_GNU_strp_alt
:
23314 bytes
+= offset_size
;
23317 case DW_FORM_block
:
23318 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23319 bytes
+= bytes_read
;
23322 case DW_FORM_block1
:
23323 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23325 case DW_FORM_block2
:
23326 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23328 case DW_FORM_block4
:
23329 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23332 case DW_FORM_addrx
:
23333 case DW_FORM_sdata
:
23335 case DW_FORM_udata
:
23336 case DW_FORM_GNU_addr_index
:
23337 case DW_FORM_GNU_str_index
:
23338 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23341 dwarf2_section_buffer_overflow_complaint (section
);
23346 case DW_FORM_implicit_const
:
23351 complaint (_("invalid form 0x%x in `%s'"),
23352 form
, section
->get_name ());
23360 /* A helper for dwarf_decode_macros that handles skipping an unknown
23361 opcode. Returns an updated pointer to the macro data buffer; or,
23362 on error, issues a complaint and returns NULL. */
23364 static const gdb_byte
*
23365 skip_unknown_opcode (unsigned int opcode
,
23366 const gdb_byte
**opcode_definitions
,
23367 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23369 unsigned int offset_size
,
23370 struct dwarf2_section_info
*section
)
23372 unsigned int bytes_read
, i
;
23374 const gdb_byte
*defn
;
23376 if (opcode_definitions
[opcode
] == NULL
)
23378 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
23383 defn
= opcode_definitions
[opcode
];
23384 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
23385 defn
+= bytes_read
;
23387 for (i
= 0; i
< arg
; ++i
)
23389 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
23390 (enum dwarf_form
) defn
[i
], offset_size
,
23392 if (mac_ptr
== NULL
)
23394 /* skip_form_bytes already issued the complaint. */
23402 /* A helper function which parses the header of a macro section.
23403 If the macro section is the extended (for now called "GNU") type,
23404 then this updates *OFFSET_SIZE. Returns a pointer to just after
23405 the header, or issues a complaint and returns NULL on error. */
23407 static const gdb_byte
*
23408 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
23410 const gdb_byte
*mac_ptr
,
23411 unsigned int *offset_size
,
23412 int section_is_gnu
)
23414 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
23416 if (section_is_gnu
)
23418 unsigned int version
, flags
;
23420 version
= read_2_bytes (abfd
, mac_ptr
);
23421 if (version
!= 4 && version
!= 5)
23423 complaint (_("unrecognized version `%d' in .debug_macro section"),
23429 flags
= read_1_byte (abfd
, mac_ptr
);
23431 *offset_size
= (flags
& 1) ? 8 : 4;
23433 if ((flags
& 2) != 0)
23434 /* We don't need the line table offset. */
23435 mac_ptr
+= *offset_size
;
23437 /* Vendor opcode descriptions. */
23438 if ((flags
& 4) != 0)
23440 unsigned int i
, count
;
23442 count
= read_1_byte (abfd
, mac_ptr
);
23444 for (i
= 0; i
< count
; ++i
)
23446 unsigned int opcode
, bytes_read
;
23449 opcode
= read_1_byte (abfd
, mac_ptr
);
23451 opcode_definitions
[opcode
] = mac_ptr
;
23452 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23453 mac_ptr
+= bytes_read
;
23462 /* A helper for dwarf_decode_macros that handles the GNU extensions,
23463 including DW_MACRO_import. */
23466 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
23468 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23469 struct macro_source_file
*current_file
,
23470 struct line_header
*lh
,
23471 struct dwarf2_section_info
*section
,
23472 int section_is_gnu
, int section_is_dwz
,
23473 unsigned int offset_size
,
23474 htab_t include_hash
)
23476 struct dwarf2_per_objfile
*dwarf2_per_objfile
23477 = cu
->per_cu
->dwarf2_per_objfile
;
23478 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23479 enum dwarf_macro_record_type macinfo_type
;
23480 int at_commandline
;
23481 const gdb_byte
*opcode_definitions
[256];
23483 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23484 &offset_size
, section_is_gnu
);
23485 if (mac_ptr
== NULL
)
23487 /* We already issued a complaint. */
23491 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
23492 GDB is still reading the definitions from command line. First
23493 DW_MACINFO_start_file will need to be ignored as it was already executed
23494 to create CURRENT_FILE for the main source holding also the command line
23495 definitions. On first met DW_MACINFO_start_file this flag is reset to
23496 normally execute all the remaining DW_MACINFO_start_file macinfos. */
23498 at_commandline
= 1;
23502 /* Do we at least have room for a macinfo type byte? */
23503 if (mac_ptr
>= mac_end
)
23505 dwarf2_section_buffer_overflow_complaint (section
);
23509 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23512 /* Note that we rely on the fact that the corresponding GNU and
23513 DWARF constants are the same. */
23515 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23516 switch (macinfo_type
)
23518 /* A zero macinfo type indicates the end of the macro
23523 case DW_MACRO_define
:
23524 case DW_MACRO_undef
:
23525 case DW_MACRO_define_strp
:
23526 case DW_MACRO_undef_strp
:
23527 case DW_MACRO_define_sup
:
23528 case DW_MACRO_undef_sup
:
23530 unsigned int bytes_read
;
23535 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23536 mac_ptr
+= bytes_read
;
23538 if (macinfo_type
== DW_MACRO_define
23539 || macinfo_type
== DW_MACRO_undef
)
23541 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23542 mac_ptr
+= bytes_read
;
23546 LONGEST str_offset
;
23548 str_offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23549 mac_ptr
+= offset_size
;
23551 if (macinfo_type
== DW_MACRO_define_sup
23552 || macinfo_type
== DW_MACRO_undef_sup
23555 struct dwz_file
*dwz
23556 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
23558 body
= dwz
->read_string (objfile
, str_offset
);
23561 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
23565 is_define
= (macinfo_type
== DW_MACRO_define
23566 || macinfo_type
== DW_MACRO_define_strp
23567 || macinfo_type
== DW_MACRO_define_sup
);
23568 if (! current_file
)
23570 /* DWARF violation as no main source is present. */
23571 complaint (_("debug info with no main source gives macro %s "
23573 is_define
? _("definition") : _("undefinition"),
23577 if ((line
== 0 && !at_commandline
)
23578 || (line
!= 0 && at_commandline
))
23579 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
23580 at_commandline
? _("command-line") : _("in-file"),
23581 is_define
? _("definition") : _("undefinition"),
23582 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
23586 /* Fedora's rpm-build's "debugedit" binary
23587 corrupted .debug_macro sections.
23590 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
23591 complaint (_("debug info gives %s invalid macro %s "
23592 "without body (corrupted?) at line %d "
23594 at_commandline
? _("command-line") : _("in-file"),
23595 is_define
? _("definition") : _("undefinition"),
23596 line
, current_file
->filename
);
23598 else if (is_define
)
23599 parse_macro_definition (current_file
, line
, body
);
23602 gdb_assert (macinfo_type
== DW_MACRO_undef
23603 || macinfo_type
== DW_MACRO_undef_strp
23604 || macinfo_type
== DW_MACRO_undef_sup
);
23605 macro_undef (current_file
, line
, body
);
23610 case DW_MACRO_start_file
:
23612 unsigned int bytes_read
;
23615 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23616 mac_ptr
+= bytes_read
;
23617 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23618 mac_ptr
+= bytes_read
;
23620 if ((line
== 0 && !at_commandline
)
23621 || (line
!= 0 && at_commandline
))
23622 complaint (_("debug info gives source %d included "
23623 "from %s at %s line %d"),
23624 file
, at_commandline
? _("command-line") : _("file"),
23625 line
== 0 ? _("zero") : _("non-zero"), line
);
23627 if (at_commandline
)
23629 /* This DW_MACRO_start_file was executed in the
23631 at_commandline
= 0;
23634 current_file
= macro_start_file (cu
, file
, line
, current_file
,
23639 case DW_MACRO_end_file
:
23640 if (! current_file
)
23641 complaint (_("macro debug info has an unmatched "
23642 "`close_file' directive"));
23645 current_file
= current_file
->included_by
;
23646 if (! current_file
)
23648 enum dwarf_macro_record_type next_type
;
23650 /* GCC circa March 2002 doesn't produce the zero
23651 type byte marking the end of the compilation
23652 unit. Complain if it's not there, but exit no
23655 /* Do we at least have room for a macinfo type byte? */
23656 if (mac_ptr
>= mac_end
)
23658 dwarf2_section_buffer_overflow_complaint (section
);
23662 /* We don't increment mac_ptr here, so this is just
23665 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
23667 if (next_type
!= 0)
23668 complaint (_("no terminating 0-type entry for "
23669 "macros in `.debug_macinfo' section"));
23676 case DW_MACRO_import
:
23677 case DW_MACRO_import_sup
:
23681 bfd
*include_bfd
= abfd
;
23682 struct dwarf2_section_info
*include_section
= section
;
23683 const gdb_byte
*include_mac_end
= mac_end
;
23684 int is_dwz
= section_is_dwz
;
23685 const gdb_byte
*new_mac_ptr
;
23687 offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23688 mac_ptr
+= offset_size
;
23690 if (macinfo_type
== DW_MACRO_import_sup
)
23692 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
23694 dwz
->macro
.read (objfile
);
23696 include_section
= &dwz
->macro
;
23697 include_bfd
= include_section
->get_bfd_owner ();
23698 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
23702 new_mac_ptr
= include_section
->buffer
+ offset
;
23703 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
23707 /* This has actually happened; see
23708 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
23709 complaint (_("recursive DW_MACRO_import in "
23710 ".debug_macro section"));
23714 *slot
= (void *) new_mac_ptr
;
23716 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
23717 include_mac_end
, current_file
, lh
,
23718 section
, section_is_gnu
, is_dwz
,
23719 offset_size
, include_hash
);
23721 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
23726 case DW_MACINFO_vendor_ext
:
23727 if (!section_is_gnu
)
23729 unsigned int bytes_read
;
23731 /* This reads the constant, but since we don't recognize
23732 any vendor extensions, we ignore it. */
23733 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23734 mac_ptr
+= bytes_read
;
23735 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23736 mac_ptr
+= bytes_read
;
23738 /* We don't recognize any vendor extensions. */
23744 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23745 mac_ptr
, mac_end
, abfd
, offset_size
,
23747 if (mac_ptr
== NULL
)
23752 } while (macinfo_type
!= 0);
23756 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23757 int section_is_gnu
)
23759 struct dwarf2_per_objfile
*dwarf2_per_objfile
23760 = cu
->per_cu
->dwarf2_per_objfile
;
23761 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23762 struct line_header
*lh
= cu
->line_header
;
23764 const gdb_byte
*mac_ptr
, *mac_end
;
23765 struct macro_source_file
*current_file
= 0;
23766 enum dwarf_macro_record_type macinfo_type
;
23767 unsigned int offset_size
= cu
->header
.offset_size
;
23768 const gdb_byte
*opcode_definitions
[256];
23770 struct dwarf2_section_info
*section
;
23771 const char *section_name
;
23773 if (cu
->dwo_unit
!= NULL
)
23775 if (section_is_gnu
)
23777 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23778 section_name
= ".debug_macro.dwo";
23782 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23783 section_name
= ".debug_macinfo.dwo";
23788 if (section_is_gnu
)
23790 section
= &dwarf2_per_objfile
->macro
;
23791 section_name
= ".debug_macro";
23795 section
= &dwarf2_per_objfile
->macinfo
;
23796 section_name
= ".debug_macinfo";
23800 section
->read (objfile
);
23801 if (section
->buffer
== NULL
)
23803 complaint (_("missing %s section"), section_name
);
23806 abfd
= section
->get_bfd_owner ();
23808 /* First pass: Find the name of the base filename.
23809 This filename is needed in order to process all macros whose definition
23810 (or undefinition) comes from the command line. These macros are defined
23811 before the first DW_MACINFO_start_file entry, and yet still need to be
23812 associated to the base file.
23814 To determine the base file name, we scan the macro definitions until we
23815 reach the first DW_MACINFO_start_file entry. We then initialize
23816 CURRENT_FILE accordingly so that any macro definition found before the
23817 first DW_MACINFO_start_file can still be associated to the base file. */
23819 mac_ptr
= section
->buffer
+ offset
;
23820 mac_end
= section
->buffer
+ section
->size
;
23822 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23823 &offset_size
, section_is_gnu
);
23824 if (mac_ptr
== NULL
)
23826 /* We already issued a complaint. */
23832 /* Do we at least have room for a macinfo type byte? */
23833 if (mac_ptr
>= mac_end
)
23835 /* Complaint is printed during the second pass as GDB will probably
23836 stop the first pass earlier upon finding
23837 DW_MACINFO_start_file. */
23841 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23844 /* Note that we rely on the fact that the corresponding GNU and
23845 DWARF constants are the same. */
23847 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23848 switch (macinfo_type
)
23850 /* A zero macinfo type indicates the end of the macro
23855 case DW_MACRO_define
:
23856 case DW_MACRO_undef
:
23857 /* Only skip the data by MAC_PTR. */
23859 unsigned int bytes_read
;
23861 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23862 mac_ptr
+= bytes_read
;
23863 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23864 mac_ptr
+= bytes_read
;
23868 case DW_MACRO_start_file
:
23870 unsigned int bytes_read
;
23873 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23874 mac_ptr
+= bytes_read
;
23875 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23876 mac_ptr
+= bytes_read
;
23878 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
23882 case DW_MACRO_end_file
:
23883 /* No data to skip by MAC_PTR. */
23886 case DW_MACRO_define_strp
:
23887 case DW_MACRO_undef_strp
:
23888 case DW_MACRO_define_sup
:
23889 case DW_MACRO_undef_sup
:
23891 unsigned int bytes_read
;
23893 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23894 mac_ptr
+= bytes_read
;
23895 mac_ptr
+= offset_size
;
23899 case DW_MACRO_import
:
23900 case DW_MACRO_import_sup
:
23901 /* Note that, according to the spec, a transparent include
23902 chain cannot call DW_MACRO_start_file. So, we can just
23903 skip this opcode. */
23904 mac_ptr
+= offset_size
;
23907 case DW_MACINFO_vendor_ext
:
23908 /* Only skip the data by MAC_PTR. */
23909 if (!section_is_gnu
)
23911 unsigned int bytes_read
;
23913 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23914 mac_ptr
+= bytes_read
;
23915 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23916 mac_ptr
+= bytes_read
;
23921 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23922 mac_ptr
, mac_end
, abfd
, offset_size
,
23924 if (mac_ptr
== NULL
)
23929 } while (macinfo_type
!= 0 && current_file
== NULL
);
23931 /* Second pass: Process all entries.
23933 Use the AT_COMMAND_LINE flag to determine whether we are still processing
23934 command-line macro definitions/undefinitions. This flag is unset when we
23935 reach the first DW_MACINFO_start_file entry. */
23937 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
23939 NULL
, xcalloc
, xfree
));
23940 mac_ptr
= section
->buffer
+ offset
;
23941 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
23942 *slot
= (void *) mac_ptr
;
23943 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
23944 current_file
, lh
, section
,
23945 section_is_gnu
, 0, offset_size
,
23946 include_hash
.get ());
23949 /* Return the .debug_loc section to use for CU.
23950 For DWO files use .debug_loc.dwo. */
23952 static struct dwarf2_section_info
*
23953 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23955 struct dwarf2_per_objfile
*dwarf2_per_objfile
23956 = cu
->per_cu
->dwarf2_per_objfile
;
23960 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23962 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23964 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23965 : &dwarf2_per_objfile
->loc
);
23968 /* A helper function that fills in a dwarf2_loclist_baton. */
23971 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23972 struct dwarf2_loclist_baton
*baton
,
23973 const struct attribute
*attr
)
23975 struct dwarf2_per_objfile
*dwarf2_per_objfile
23976 = cu
->per_cu
->dwarf2_per_objfile
;
23977 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23979 section
->read (dwarf2_per_objfile
->objfile
);
23981 baton
->per_cu
= cu
->per_cu
;
23982 gdb_assert (baton
->per_cu
);
23983 /* We don't know how long the location list is, but make sure we
23984 don't run off the edge of the section. */
23985 baton
->size
= section
->size
- DW_UNSND (attr
);
23986 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23987 baton
->base_address
= cu
->base_address
;
23988 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23992 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23993 struct dwarf2_cu
*cu
, int is_block
)
23995 struct dwarf2_per_objfile
*dwarf2_per_objfile
23996 = cu
->per_cu
->dwarf2_per_objfile
;
23997 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23998 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24000 if (attr
->form_is_section_offset ()
24001 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24002 the section. If so, fall through to the complaint in the
24004 && DW_UNSND (attr
) < section
->get_size (objfile
))
24006 struct dwarf2_loclist_baton
*baton
;
24008 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24010 fill_in_loclist_baton (cu
, baton
, attr
);
24012 if (cu
->base_known
== 0)
24013 complaint (_("Location list used without "
24014 "specifying the CU base address."));
24016 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24017 ? dwarf2_loclist_block_index
24018 : dwarf2_loclist_index
);
24019 SYMBOL_LOCATION_BATON (sym
) = baton
;
24023 struct dwarf2_locexpr_baton
*baton
;
24025 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24026 baton
->per_cu
= cu
->per_cu
;
24027 gdb_assert (baton
->per_cu
);
24029 if (attr
->form_is_block ())
24031 /* Note that we're just copying the block's data pointer
24032 here, not the actual data. We're still pointing into the
24033 info_buffer for SYM's objfile; right now we never release
24034 that buffer, but when we do clean up properly this may
24036 baton
->size
= DW_BLOCK (attr
)->size
;
24037 baton
->data
= DW_BLOCK (attr
)->data
;
24041 dwarf2_invalid_attrib_class_complaint ("location description",
24042 sym
->natural_name ());
24046 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24047 ? dwarf2_locexpr_block_index
24048 : dwarf2_locexpr_index
);
24049 SYMBOL_LOCATION_BATON (sym
) = baton
;
24056 dwarf2_per_cu_data::objfile () const
24058 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24060 /* Return the master objfile, so that we can report and look up the
24061 correct file containing this variable. */
24062 if (objfile
->separate_debug_objfile_backlink
)
24063 objfile
= objfile
->separate_debug_objfile_backlink
;
24068 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24069 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24070 CU_HEADERP first. */
24072 static const struct comp_unit_head
*
24073 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24074 const struct dwarf2_per_cu_data
*per_cu
)
24076 const gdb_byte
*info_ptr
;
24079 return &per_cu
->cu
->header
;
24081 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24083 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24084 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24085 rcuh_kind::COMPILE
);
24093 dwarf2_per_cu_data::addr_size () const
24095 struct comp_unit_head cu_header_local
;
24096 const struct comp_unit_head
*cu_headerp
;
24098 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24100 return cu_headerp
->addr_size
;
24106 dwarf2_per_cu_data::offset_size () const
24108 struct comp_unit_head cu_header_local
;
24109 const struct comp_unit_head
*cu_headerp
;
24111 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24113 return cu_headerp
->offset_size
;
24119 dwarf2_per_cu_data::ref_addr_size () const
24121 struct comp_unit_head cu_header_local
;
24122 const struct comp_unit_head
*cu_headerp
;
24124 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24126 if (cu_headerp
->version
== 2)
24127 return cu_headerp
->addr_size
;
24129 return cu_headerp
->offset_size
;
24135 dwarf2_per_cu_data::text_offset () const
24137 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24139 return objfile
->text_section_offset ();
24145 dwarf2_per_cu_data::addr_type () const
24147 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24148 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24149 struct type
*addr_type
= lookup_pointer_type (void_type
);
24150 int addr_size
= this->addr_size ();
24152 if (TYPE_LENGTH (addr_type
) == addr_size
)
24155 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
24159 /* A helper function for dwarf2_find_containing_comp_unit that returns
24160 the index of the result, and that searches a vector. It will
24161 return a result even if the offset in question does not actually
24162 occur in any CU. This is separate so that it can be unit
24166 dwarf2_find_containing_comp_unit
24167 (sect_offset sect_off
,
24168 unsigned int offset_in_dwz
,
24169 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24174 high
= all_comp_units
.size () - 1;
24177 struct dwarf2_per_cu_data
*mid_cu
;
24178 int mid
= low
+ (high
- low
) / 2;
24180 mid_cu
= all_comp_units
[mid
];
24181 if (mid_cu
->is_dwz
> offset_in_dwz
24182 || (mid_cu
->is_dwz
== offset_in_dwz
24183 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24188 gdb_assert (low
== high
);
24192 /* Locate the .debug_info compilation unit from CU's objfile which contains
24193 the DIE at OFFSET. Raises an error on failure. */
24195 static struct dwarf2_per_cu_data
*
24196 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24197 unsigned int offset_in_dwz
,
24198 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24201 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
24202 dwarf2_per_objfile
->all_comp_units
);
24203 struct dwarf2_per_cu_data
*this_cu
24204 = dwarf2_per_objfile
->all_comp_units
[low
];
24206 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24208 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24209 error (_("Dwarf Error: could not find partial DIE containing "
24210 "offset %s [in module %s]"),
24211 sect_offset_str (sect_off
),
24212 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24214 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24216 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24220 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24221 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24222 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24223 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24230 namespace selftests
{
24231 namespace find_containing_comp_unit
{
24236 struct dwarf2_per_cu_data one
{};
24237 struct dwarf2_per_cu_data two
{};
24238 struct dwarf2_per_cu_data three
{};
24239 struct dwarf2_per_cu_data four
{};
24242 two
.sect_off
= sect_offset (one
.length
);
24247 four
.sect_off
= sect_offset (three
.length
);
24251 std::vector
<dwarf2_per_cu_data
*> units
;
24252 units
.push_back (&one
);
24253 units
.push_back (&two
);
24254 units
.push_back (&three
);
24255 units
.push_back (&four
);
24259 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24260 SELF_CHECK (units
[result
] == &one
);
24261 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24262 SELF_CHECK (units
[result
] == &one
);
24263 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24264 SELF_CHECK (units
[result
] == &two
);
24266 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24267 SELF_CHECK (units
[result
] == &three
);
24268 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24269 SELF_CHECK (units
[result
] == &three
);
24270 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24271 SELF_CHECK (units
[result
] == &four
);
24277 #endif /* GDB_SELF_TEST */
24279 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24281 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24282 : per_cu (per_cu_
),
24284 has_loclist (false),
24285 checked_producer (false),
24286 producer_is_gxx_lt_4_6 (false),
24287 producer_is_gcc_lt_4_3 (false),
24288 producer_is_icc (false),
24289 producer_is_icc_lt_14 (false),
24290 producer_is_codewarrior (false),
24291 processing_has_namespace_info (false)
24296 /* Destroy a dwarf2_cu. */
24298 dwarf2_cu::~dwarf2_cu ()
24303 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24306 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24307 enum language pretend_language
)
24309 struct attribute
*attr
;
24311 /* Set the language we're debugging. */
24312 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24313 if (attr
!= nullptr)
24314 set_cu_language (DW_UNSND (attr
), cu
);
24317 cu
->language
= pretend_language
;
24318 cu
->language_defn
= language_def (cu
->language
);
24321 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24324 /* Increase the age counter on each cached compilation unit, and free
24325 any that are too old. */
24328 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24330 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24332 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24333 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24334 while (per_cu
!= NULL
)
24336 per_cu
->cu
->last_used
++;
24337 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24338 dwarf2_mark (per_cu
->cu
);
24339 per_cu
= per_cu
->cu
->read_in_chain
;
24342 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24343 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24344 while (per_cu
!= NULL
)
24346 struct dwarf2_per_cu_data
*next_cu
;
24348 next_cu
= per_cu
->cu
->read_in_chain
;
24350 if (!per_cu
->cu
->mark
)
24353 *last_chain
= next_cu
;
24356 last_chain
= &per_cu
->cu
->read_in_chain
;
24362 /* Remove a single compilation unit from the cache. */
24365 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
24367 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24368 struct dwarf2_per_objfile
*dwarf2_per_objfile
24369 = target_per_cu
->dwarf2_per_objfile
;
24371 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24372 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24373 while (per_cu
!= NULL
)
24375 struct dwarf2_per_cu_data
*next_cu
;
24377 next_cu
= per_cu
->cu
->read_in_chain
;
24379 if (per_cu
== target_per_cu
)
24383 *last_chain
= next_cu
;
24387 last_chain
= &per_cu
->cu
->read_in_chain
;
24393 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24394 We store these in a hash table separate from the DIEs, and preserve them
24395 when the DIEs are flushed out of cache.
24397 The CU "per_cu" pointer is needed because offset alone is not enough to
24398 uniquely identify the type. A file may have multiple .debug_types sections,
24399 or the type may come from a DWO file. Furthermore, while it's more logical
24400 to use per_cu->section+offset, with Fission the section with the data is in
24401 the DWO file but we don't know that section at the point we need it.
24402 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24403 because we can enter the lookup routine, get_die_type_at_offset, from
24404 outside this file, and thus won't necessarily have PER_CU->cu.
24405 Fortunately, PER_CU is stable for the life of the objfile. */
24407 struct dwarf2_per_cu_offset_and_type
24409 const struct dwarf2_per_cu_data
*per_cu
;
24410 sect_offset sect_off
;
24414 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24417 per_cu_offset_and_type_hash (const void *item
)
24419 const struct dwarf2_per_cu_offset_and_type
*ofs
24420 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24422 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24425 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24428 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24430 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24431 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24432 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24433 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24435 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24436 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24439 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24440 table if necessary. For convenience, return TYPE.
24442 The DIEs reading must have careful ordering to:
24443 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24444 reading current DIE.
24445 * Not trying to dereference contents of still incompletely read in types
24446 while reading in other DIEs.
24447 * Enable referencing still incompletely read in types just by a pointer to
24448 the type without accessing its fields.
24450 Therefore caller should follow these rules:
24451 * Try to fetch any prerequisite types we may need to build this DIE type
24452 before building the type and calling set_die_type.
24453 * After building type call set_die_type for current DIE as soon as
24454 possible before fetching more types to complete the current type.
24455 * Make the type as complete as possible before fetching more types. */
24457 static struct type
*
24458 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24460 struct dwarf2_per_objfile
*dwarf2_per_objfile
24461 = cu
->per_cu
->dwarf2_per_objfile
;
24462 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24463 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24464 struct attribute
*attr
;
24465 struct dynamic_prop prop
;
24467 /* For Ada types, make sure that the gnat-specific data is always
24468 initialized (if not already set). There are a few types where
24469 we should not be doing so, because the type-specific area is
24470 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24471 where the type-specific area is used to store the floatformat).
24472 But this is not a problem, because the gnat-specific information
24473 is actually not needed for these types. */
24474 if (need_gnat_info (cu
)
24475 && TYPE_CODE (type
) != TYPE_CODE_FUNC
24476 && TYPE_CODE (type
) != TYPE_CODE_FLT
24477 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
24478 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
24479 && TYPE_CODE (type
) != TYPE_CODE_METHOD
24480 && !HAVE_GNAT_AUX_INFO (type
))
24481 INIT_GNAT_SPECIFIC (type
);
24483 /* Read DW_AT_allocated and set in type. */
24484 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24485 if (attr
!= NULL
&& attr
->form_is_block ())
24487 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24488 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24489 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
24491 else if (attr
!= NULL
)
24493 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
24494 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24495 sect_offset_str (die
->sect_off
));
24498 /* Read DW_AT_associated and set in type. */
24499 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24500 if (attr
!= NULL
&& attr
->form_is_block ())
24502 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24503 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24504 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
24506 else if (attr
!= NULL
)
24508 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
24509 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24510 sect_offset_str (die
->sect_off
));
24513 /* Read DW_AT_data_location and set in type. */
24514 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24515 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
24516 cu
->per_cu
->addr_type ()))
24517 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
24519 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24520 dwarf2_per_objfile
->die_type_hash
24521 = htab_up (htab_create_alloc (127,
24522 per_cu_offset_and_type_hash
,
24523 per_cu_offset_and_type_eq
,
24524 NULL
, xcalloc
, xfree
));
24526 ofs
.per_cu
= cu
->per_cu
;
24527 ofs
.sect_off
= die
->sect_off
;
24529 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24530 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24532 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24533 sect_offset_str (die
->sect_off
));
24534 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24535 struct dwarf2_per_cu_offset_and_type
);
24540 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24541 or return NULL if the die does not have a saved type. */
24543 static struct type
*
24544 get_die_type_at_offset (sect_offset sect_off
,
24545 struct dwarf2_per_cu_data
*per_cu
)
24547 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24548 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
24550 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24553 ofs
.per_cu
= per_cu
;
24554 ofs
.sect_off
= sect_off
;
24555 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24556 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
24563 /* Look up the type for DIE in CU in die_type_hash,
24564 or return NULL if DIE does not have a saved type. */
24566 static struct type
*
24567 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24569 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
24572 /* Add a dependence relationship from CU to REF_PER_CU. */
24575 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24576 struct dwarf2_per_cu_data
*ref_per_cu
)
24580 if (cu
->dependencies
== NULL
)
24582 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24583 NULL
, &cu
->comp_unit_obstack
,
24584 hashtab_obstack_allocate
,
24585 dummy_obstack_deallocate
);
24587 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24589 *slot
= ref_per_cu
;
24592 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24593 Set the mark field in every compilation unit in the
24594 cache that we must keep because we are keeping CU. */
24597 dwarf2_mark_helper (void **slot
, void *data
)
24599 struct dwarf2_per_cu_data
*per_cu
;
24601 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
24603 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24604 reading of the chain. As such dependencies remain valid it is not much
24605 useful to track and undo them during QUIT cleanups. */
24606 if (per_cu
->cu
== NULL
)
24609 if (per_cu
->cu
->mark
)
24611 per_cu
->cu
->mark
= true;
24613 if (per_cu
->cu
->dependencies
!= NULL
)
24614 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24619 /* Set the mark field in CU and in every other compilation unit in the
24620 cache that we must keep because we are keeping CU. */
24623 dwarf2_mark (struct dwarf2_cu
*cu
)
24628 if (cu
->dependencies
!= NULL
)
24629 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24633 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
24637 per_cu
->cu
->mark
= false;
24638 per_cu
= per_cu
->cu
->read_in_chain
;
24642 /* Trivial hash function for partial_die_info: the hash value of a DIE
24643 is its offset in .debug_info for this objfile. */
24646 partial_die_hash (const void *item
)
24648 const struct partial_die_info
*part_die
24649 = (const struct partial_die_info
*) item
;
24651 return to_underlying (part_die
->sect_off
);
24654 /* Trivial comparison function for partial_die_info structures: two DIEs
24655 are equal if they have the same offset. */
24658 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24660 const struct partial_die_info
*part_die_lhs
24661 = (const struct partial_die_info
*) item_lhs
;
24662 const struct partial_die_info
*part_die_rhs
24663 = (const struct partial_die_info
*) item_rhs
;
24665 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24668 struct cmd_list_element
*set_dwarf_cmdlist
;
24669 struct cmd_list_element
*show_dwarf_cmdlist
;
24672 set_dwarf_cmd (const char *args
, int from_tty
)
24674 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
24679 show_dwarf_cmd (const char *args
, int from_tty
)
24681 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
24685 show_check_physname (struct ui_file
*file
, int from_tty
,
24686 struct cmd_list_element
*c
, const char *value
)
24688 fprintf_filtered (file
,
24689 _("Whether to check \"physname\" is %s.\n"),
24693 void _initialize_dwarf2_read ();
24695 _initialize_dwarf2_read ()
24697 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24698 Set DWARF specific variables.\n\
24699 Configure DWARF variables such as the cache size."),
24700 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24701 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24703 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24704 Show DWARF specific variables.\n\
24705 Show DWARF variables such as the cache size."),
24706 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24707 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24709 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24710 &dwarf_max_cache_age
, _("\
24711 Set the upper bound on the age of cached DWARF compilation units."), _("\
24712 Show the upper bound on the age of cached DWARF compilation units."), _("\
24713 A higher limit means that cached compilation units will be stored\n\
24714 in memory longer, and more total memory will be used. Zero disables\n\
24715 caching, which can slow down startup."),
24717 show_dwarf_max_cache_age
,
24718 &set_dwarf_cmdlist
,
24719 &show_dwarf_cmdlist
);
24721 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24722 Set debugging of the DWARF reader."), _("\
24723 Show debugging of the DWARF reader."), _("\
24724 When enabled (non-zero), debugging messages are printed during DWARF\n\
24725 reading and symtab expansion. A value of 1 (one) provides basic\n\
24726 information. A value greater than 1 provides more verbose information."),
24729 &setdebuglist
, &showdebuglist
);
24731 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24732 Set debugging of the DWARF DIE reader."), _("\
24733 Show debugging of the DWARF DIE reader."), _("\
24734 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24735 The value is the maximum depth to print."),
24738 &setdebuglist
, &showdebuglist
);
24740 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24741 Set debugging of the dwarf line reader."), _("\
24742 Show debugging of the dwarf line reader."), _("\
24743 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24744 A value of 1 (one) provides basic information.\n\
24745 A value greater than 1 provides more verbose information."),
24748 &setdebuglist
, &showdebuglist
);
24750 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24751 Set cross-checking of \"physname\" code against demangler."), _("\
24752 Show cross-checking of \"physname\" code against demangler."), _("\
24753 When enabled, GDB's internal \"physname\" code is checked against\n\
24755 NULL
, show_check_physname
,
24756 &setdebuglist
, &showdebuglist
);
24758 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24759 no_class
, &use_deprecated_index_sections
, _("\
24760 Set whether to use deprecated gdb_index sections."), _("\
24761 Show whether to use deprecated gdb_index sections."), _("\
24762 When enabled, deprecated .gdb_index sections are used anyway.\n\
24763 Normally they are ignored either because of a missing feature or\n\
24764 performance issue.\n\
24765 Warning: This option must be enabled before gdb reads the file."),
24768 &setlist
, &showlist
);
24770 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24771 &dwarf2_locexpr_funcs
);
24772 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24773 &dwarf2_loclist_funcs
);
24775 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24776 &dwarf2_block_frame_base_locexpr_funcs
);
24777 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24778 &dwarf2_block_frame_base_loclist_funcs
);
24781 selftests::register_test ("dw2_expand_symtabs_matching",
24782 selftests::dw2_expand_symtabs_matching::run_test
);
24783 selftests::register_test ("dwarf2_find_containing_comp_unit",
24784 selftests::find_containing_comp_unit::run_test
);