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"
48 #include "gdb-demangle.h"
49 #include "filenames.h" /* for DOSish file names */
52 #include "complaints.h"
53 #include "dwarf2/expr.h"
54 #include "dwarf2/loc.h"
55 #include "cp-support.h"
61 #include "typeprint.h"
66 #include "gdbcore.h" /* for gnutarget */
67 #include "gdb/gdb-index.h"
72 #include "namespace.h"
73 #include "gdbsupport/function-view.h"
74 #include "gdbsupport/gdb_optional.h"
75 #include "gdbsupport/underlying.h"
76 #include "gdbsupport/hash_enum.h"
77 #include "filename-seen-cache.h"
81 #include <unordered_map>
82 #include "gdbsupport/selftest.h"
83 #include "rust-lang.h"
84 #include "gdbsupport/pathstuff.h"
85 #include "count-one-bits.h"
87 /* When == 1, print basic high level tracing messages.
88 When > 1, be more verbose.
89 This is in contrast to the low level DIE reading of dwarf_die_debug. */
90 static unsigned int dwarf_read_debug
= 0;
92 /* When non-zero, dump DIEs after they are read in. */
93 static unsigned int dwarf_die_debug
= 0;
95 /* When non-zero, dump line number entries as they are read in. */
96 unsigned int dwarf_line_debug
= 0;
98 /* When true, cross-check physname against demangler. */
99 static bool check_physname
= false;
101 /* When true, do not reject deprecated .gdb_index sections. */
102 static bool use_deprecated_index_sections
= false;
104 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
106 /* The "aclass" indices for various kinds of computed DWARF symbols. */
108 static int dwarf2_locexpr_index
;
109 static int dwarf2_loclist_index
;
110 static int dwarf2_locexpr_block_index
;
111 static int dwarf2_loclist_block_index
;
113 /* An index into a (C++) symbol name component in a symbol name as
114 recorded in the mapped_index's symbol table. For each C++ symbol
115 in the symbol table, we record one entry for the start of each
116 component in the symbol in a table of name components, and then
117 sort the table, in order to be able to binary search symbol names,
118 ignoring leading namespaces, both completion and regular look up.
119 For example, for symbol "A::B::C", we'll have an entry that points
120 to "A::B::C", another that points to "B::C", and another for "C".
121 Note that function symbols in GDB index have no parameter
122 information, just the function/method names. You can convert a
123 name_component to a "const char *" using the
124 'mapped_index::symbol_name_at(offset_type)' method. */
126 struct name_component
128 /* Offset in the symbol name where the component starts. Stored as
129 a (32-bit) offset instead of a pointer to save memory and improve
130 locality on 64-bit architectures. */
131 offset_type name_offset
;
133 /* The symbol's index in the symbol and constant pool tables of a
138 /* Base class containing bits shared by both .gdb_index and
139 .debug_name indexes. */
141 struct mapped_index_base
143 mapped_index_base () = default;
144 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
146 /* The name_component table (a sorted vector). See name_component's
147 description above. */
148 std::vector
<name_component
> name_components
;
150 /* How NAME_COMPONENTS is sorted. */
151 enum case_sensitivity name_components_casing
;
153 /* Return the number of names in the symbol table. */
154 virtual size_t symbol_name_count () const = 0;
156 /* Get the name of the symbol at IDX in the symbol table. */
157 virtual const char *symbol_name_at (offset_type idx
) const = 0;
159 /* Return whether the name at IDX in the symbol table should be
161 virtual bool symbol_name_slot_invalid (offset_type idx
) const
166 /* Build the symbol name component sorted vector, if we haven't
168 void build_name_components ();
170 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
171 possible matches for LN_NO_PARAMS in the name component
173 std::pair
<std::vector
<name_component
>::const_iterator
,
174 std::vector
<name_component
>::const_iterator
>
175 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
176 enum language lang
) const;
178 /* Prevent deleting/destroying via a base class pointer. */
180 ~mapped_index_base() = default;
183 /* A description of the mapped index. The file format is described in
184 a comment by the code that writes the index. */
185 struct mapped_index final
: public mapped_index_base
187 /* A slot/bucket in the symbol table hash. */
188 struct symbol_table_slot
190 const offset_type name
;
191 const offset_type vec
;
194 /* Index data format version. */
197 /* The address table data. */
198 gdb::array_view
<const gdb_byte
> address_table
;
200 /* The symbol table, implemented as a hash table. */
201 gdb::array_view
<symbol_table_slot
> symbol_table
;
203 /* A pointer to the constant pool. */
204 const char *constant_pool
= nullptr;
206 bool symbol_name_slot_invalid (offset_type idx
) const override
208 const auto &bucket
= this->symbol_table
[idx
];
209 return bucket
.name
== 0 && bucket
.vec
== 0;
212 /* Convenience method to get at the name of the symbol at IDX in the
214 const char *symbol_name_at (offset_type idx
) const override
215 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
217 size_t symbol_name_count () const override
218 { return this->symbol_table
.size (); }
221 /* A description of the mapped .debug_names.
222 Uninitialized map has CU_COUNT 0. */
223 struct mapped_debug_names final
: public mapped_index_base
225 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
226 : dwarf2_per_objfile (dwarf2_per_objfile_
)
229 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
230 bfd_endian dwarf5_byte_order
;
231 bool dwarf5_is_dwarf64
;
232 bool augmentation_is_gdb
;
234 uint32_t cu_count
= 0;
235 uint32_t tu_count
, bucket_count
, name_count
;
236 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
237 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
238 const gdb_byte
*name_table_string_offs_reordered
;
239 const gdb_byte
*name_table_entry_offs_reordered
;
240 const gdb_byte
*entry_pool
;
247 /* Attribute name DW_IDX_*. */
250 /* Attribute form DW_FORM_*. */
253 /* Value if FORM is DW_FORM_implicit_const. */
254 LONGEST implicit_const
;
256 std::vector
<attr
> attr_vec
;
259 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
261 const char *namei_to_name (uint32_t namei
) const;
263 /* Implementation of the mapped_index_base virtual interface, for
264 the name_components cache. */
266 const char *symbol_name_at (offset_type idx
) const override
267 { return namei_to_name (idx
); }
269 size_t symbol_name_count () const override
270 { return this->name_count
; }
273 /* See dwarf2read.h. */
276 get_dwarf2_per_objfile (struct objfile
*objfile
)
278 return dwarf2_objfile_data_key
.get (objfile
);
281 /* Default names of the debugging sections. */
283 /* Note that if the debugging section has been compressed, it might
284 have a name like .zdebug_info. */
286 static const struct dwarf2_debug_sections dwarf2_elf_names
=
288 { ".debug_info", ".zdebug_info" },
289 { ".debug_abbrev", ".zdebug_abbrev" },
290 { ".debug_line", ".zdebug_line" },
291 { ".debug_loc", ".zdebug_loc" },
292 { ".debug_loclists", ".zdebug_loclists" },
293 { ".debug_macinfo", ".zdebug_macinfo" },
294 { ".debug_macro", ".zdebug_macro" },
295 { ".debug_str", ".zdebug_str" },
296 { ".debug_str_offsets", ".zdebug_str_offsets" },
297 { ".debug_line_str", ".zdebug_line_str" },
298 { ".debug_ranges", ".zdebug_ranges" },
299 { ".debug_rnglists", ".zdebug_rnglists" },
300 { ".debug_types", ".zdebug_types" },
301 { ".debug_addr", ".zdebug_addr" },
302 { ".debug_frame", ".zdebug_frame" },
303 { ".eh_frame", NULL
},
304 { ".gdb_index", ".zgdb_index" },
305 { ".debug_names", ".zdebug_names" },
306 { ".debug_aranges", ".zdebug_aranges" },
310 /* List of DWO/DWP sections. */
312 static const struct dwop_section_names
314 struct dwarf2_section_names abbrev_dwo
;
315 struct dwarf2_section_names info_dwo
;
316 struct dwarf2_section_names line_dwo
;
317 struct dwarf2_section_names loc_dwo
;
318 struct dwarf2_section_names loclists_dwo
;
319 struct dwarf2_section_names macinfo_dwo
;
320 struct dwarf2_section_names macro_dwo
;
321 struct dwarf2_section_names str_dwo
;
322 struct dwarf2_section_names str_offsets_dwo
;
323 struct dwarf2_section_names types_dwo
;
324 struct dwarf2_section_names cu_index
;
325 struct dwarf2_section_names tu_index
;
329 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
330 { ".debug_info.dwo", ".zdebug_info.dwo" },
331 { ".debug_line.dwo", ".zdebug_line.dwo" },
332 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
333 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
334 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
335 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
336 { ".debug_str.dwo", ".zdebug_str.dwo" },
337 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
338 { ".debug_types.dwo", ".zdebug_types.dwo" },
339 { ".debug_cu_index", ".zdebug_cu_index" },
340 { ".debug_tu_index", ".zdebug_tu_index" },
343 /* local data types */
345 /* Type used for delaying computation of method physnames.
346 See comments for compute_delayed_physnames. */
347 struct delayed_method_info
349 /* The type to which the method is attached, i.e., its parent class. */
352 /* The index of the method in the type's function fieldlists. */
355 /* The index of the method in the fieldlist. */
358 /* The name of the DIE. */
361 /* The DIE associated with this method. */
362 struct die_info
*die
;
365 /* Internal state when decoding a particular compilation unit. */
368 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
371 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
373 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
374 Create the set of symtabs used by this TU, or if this TU is sharing
375 symtabs with another TU and the symtabs have already been created
376 then restore those symtabs in the line header.
377 We don't need the pc/line-number mapping for type units. */
378 void setup_type_unit_groups (struct die_info
*die
);
380 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
381 buildsym_compunit constructor. */
382 struct compunit_symtab
*start_symtab (const char *name
,
383 const char *comp_dir
,
386 /* Reset the builder. */
387 void reset_builder () { m_builder
.reset (); }
389 /* The header of the compilation unit. */
390 struct comp_unit_head header
{};
392 /* Base address of this compilation unit. */
393 CORE_ADDR base_address
= 0;
395 /* Non-zero if base_address has been set. */
398 /* The language we are debugging. */
399 enum language language
= language_unknown
;
400 const struct language_defn
*language_defn
= nullptr;
402 const char *producer
= nullptr;
405 /* The symtab builder for this CU. This is only non-NULL when full
406 symbols are being read. */
407 std::unique_ptr
<buildsym_compunit
> m_builder
;
410 /* The generic symbol table building routines have separate lists for
411 file scope symbols and all all other scopes (local scopes). So
412 we need to select the right one to pass to add_symbol_to_list().
413 We do it by keeping a pointer to the correct list in list_in_scope.
415 FIXME: The original dwarf code just treated the file scope as the
416 first local scope, and all other local scopes as nested local
417 scopes, and worked fine. Check to see if we really need to
418 distinguish these in buildsym.c. */
419 struct pending
**list_in_scope
= nullptr;
421 /* Hash table holding all the loaded partial DIEs
422 with partial_die->offset.SECT_OFF as hash. */
423 htab_t partial_dies
= nullptr;
425 /* Storage for things with the same lifetime as this read-in compilation
426 unit, including partial DIEs. */
427 auto_obstack comp_unit_obstack
;
429 /* When multiple dwarf2_cu structures are living in memory, this field
430 chains them all together, so that they can be released efficiently.
431 We will probably also want a generation counter so that most-recently-used
432 compilation units are cached... */
433 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
435 /* Backlink to our per_cu entry. */
436 struct dwarf2_per_cu_data
*per_cu
;
438 /* How many compilation units ago was this CU last referenced? */
441 /* A hash table of DIE cu_offset for following references with
442 die_info->offset.sect_off as hash. */
443 htab_t die_hash
= nullptr;
445 /* Full DIEs if read in. */
446 struct die_info
*dies
= nullptr;
448 /* A set of pointers to dwarf2_per_cu_data objects for compilation
449 units referenced by this one. Only set during full symbol processing;
450 partial symbol tables do not have dependencies. */
451 htab_t dependencies
= nullptr;
453 /* Header data from the line table, during full symbol processing. */
454 struct line_header
*line_header
= nullptr;
455 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
456 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
457 this is the DW_TAG_compile_unit die for this CU. We'll hold on
458 to the line header as long as this DIE is being processed. See
459 process_die_scope. */
460 die_info
*line_header_die_owner
= nullptr;
462 /* A list of methods which need to have physnames computed
463 after all type information has been read. */
464 std::vector
<delayed_method_info
> method_list
;
466 /* To be copied to symtab->call_site_htab. */
467 htab_t call_site_htab
= nullptr;
469 /* Non-NULL if this CU came from a DWO file.
470 There is an invariant here that is important to remember:
471 Except for attributes copied from the top level DIE in the "main"
472 (or "stub") file in preparation for reading the DWO file
473 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
474 Either there isn't a DWO file (in which case this is NULL and the point
475 is moot), or there is and either we're not going to read it (in which
476 case this is NULL) or there is and we are reading it (in which case this
478 struct dwo_unit
*dwo_unit
= nullptr;
480 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
481 Note this value comes from the Fission stub CU/TU's DIE. */
482 gdb::optional
<ULONGEST
> addr_base
;
484 /* The DW_AT_rnglists_base attribute if present.
485 Note this value comes from the Fission stub CU/TU's DIE.
486 Also note that the value is zero in the non-DWO case so this value can
487 be used without needing to know whether DWO files are in use or not.
488 N.B. This does not apply to DW_AT_ranges appearing in
489 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
490 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
491 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
492 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
493 ULONGEST ranges_base
= 0;
495 /* When reading debug info generated by older versions of rustc, we
496 have to rewrite some union types to be struct types with a
497 variant part. This rewriting must be done after the CU is fully
498 read in, because otherwise at the point of rewriting some struct
499 type might not have been fully processed. So, we keep a list of
500 all such types here and process them after expansion. */
501 std::vector
<struct type
*> rust_unions
;
503 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
504 files, the value is implicitly zero. For DWARF 5 version DWO files, the
505 value is often implicit and is the size of the header of
506 .debug_str_offsets section (8 or 4, depending on the address size). */
507 gdb::optional
<ULONGEST
> str_offsets_base
;
509 /* Mark used when releasing cached dies. */
512 /* This CU references .debug_loc. See the symtab->locations_valid field.
513 This test is imperfect as there may exist optimized debug code not using
514 any location list and still facing inlining issues if handled as
515 unoptimized code. For a future better test see GCC PR other/32998. */
516 bool has_loclist
: 1;
518 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
519 if all the producer_is_* fields are valid. This information is cached
520 because profiling CU expansion showed excessive time spent in
521 producer_is_gxx_lt_4_6. */
522 bool checked_producer
: 1;
523 bool producer_is_gxx_lt_4_6
: 1;
524 bool producer_is_gcc_lt_4_3
: 1;
525 bool producer_is_icc
: 1;
526 bool producer_is_icc_lt_14
: 1;
527 bool producer_is_codewarrior
: 1;
529 /* When true, the file that we're processing is known to have
530 debugging info for C++ namespaces. GCC 3.3.x did not produce
531 this information, but later versions do. */
533 bool processing_has_namespace_info
: 1;
535 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
537 /* If this CU was inherited by another CU (via specification,
538 abstract_origin, etc), this is the ancestor CU. */
541 /* Get the buildsym_compunit for this CU. */
542 buildsym_compunit
*get_builder ()
544 /* If this CU has a builder associated with it, use that. */
545 if (m_builder
!= nullptr)
546 return m_builder
.get ();
548 /* Otherwise, search ancestors for a valid builder. */
549 if (ancestor
!= nullptr)
550 return ancestor
->get_builder ();
556 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
557 This includes type_unit_group and quick_file_names. */
559 struct stmt_list_hash
561 /* The DWO unit this table is from or NULL if there is none. */
562 struct dwo_unit
*dwo_unit
;
564 /* Offset in .debug_line or .debug_line.dwo. */
565 sect_offset line_sect_off
;
568 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
569 an object of this type. */
571 struct type_unit_group
573 /* dwarf2read.c's main "handle" on a TU symtab.
574 To simplify things we create an artificial CU that "includes" all the
575 type units using this stmt_list so that the rest of the code still has
576 a "per_cu" handle on the symtab.
577 This PER_CU is recognized by having no section. */
578 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
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 number of symtabs from the line header.
595 The value here must match line_header.num_file_names. */
596 unsigned int num_symtabs
;
598 /* The symbol tables for this TU (obtained from the files listed in
600 WARNING: The order of entries here must match the order of entries
601 in the line header. After the first TU using this type_unit_group, the
602 line header for the subsequent TUs is recreated from this. This is done
603 because we need to use the same symtabs for each TU using the same
604 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
605 there's no guarantee the line header doesn't have duplicate entries. */
606 struct symtab
**symtabs
;
609 /* These sections are what may appear in a (real or virtual) DWO file. */
613 struct dwarf2_section_info abbrev
;
614 struct dwarf2_section_info line
;
615 struct dwarf2_section_info loc
;
616 struct dwarf2_section_info loclists
;
617 struct dwarf2_section_info macinfo
;
618 struct dwarf2_section_info macro
;
619 struct dwarf2_section_info str
;
620 struct dwarf2_section_info str_offsets
;
621 /* In the case of a virtual DWO file, these two are unused. */
622 struct dwarf2_section_info info
;
623 std::vector
<dwarf2_section_info
> types
;
626 /* CUs/TUs in DWP/DWO files. */
630 /* Backlink to the containing struct dwo_file. */
631 struct dwo_file
*dwo_file
;
633 /* The "id" that distinguishes this CU/TU.
634 .debug_info calls this "dwo_id", .debug_types calls this "signature".
635 Since signatures came first, we stick with it for consistency. */
638 /* The section this CU/TU lives in, in the DWO file. */
639 struct dwarf2_section_info
*section
;
641 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
642 sect_offset sect_off
;
645 /* For types, offset in the type's DIE of the type defined by this TU. */
646 cu_offset type_offset_in_tu
;
649 /* include/dwarf2.h defines the DWP section codes.
650 It defines a max value but it doesn't define a min value, which we
651 use for error checking, so provide one. */
653 enum dwp_v2_section_ids
658 /* Data for one DWO file.
660 This includes virtual DWO files (a virtual DWO file is a DWO file as it
661 appears in a DWP file). DWP files don't really have DWO files per se -
662 comdat folding of types "loses" the DWO file they came from, and from
663 a high level view DWP files appear to contain a mass of random types.
664 However, to maintain consistency with the non-DWP case we pretend DWP
665 files contain virtual DWO files, and we assign each TU with one virtual
666 DWO file (generally based on the line and abbrev section offsets -
667 a heuristic that seems to work in practice). */
671 dwo_file () = default;
672 DISABLE_COPY_AND_ASSIGN (dwo_file
);
674 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
675 For virtual DWO files the name is constructed from the section offsets
676 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
677 from related CU+TUs. */
678 const char *dwo_name
= nullptr;
680 /* The DW_AT_comp_dir attribute. */
681 const char *comp_dir
= nullptr;
683 /* The bfd, when the file is open. Otherwise this is NULL.
684 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
685 gdb_bfd_ref_ptr dbfd
;
687 /* The sections that make up this DWO file.
688 Remember that for virtual DWO files in DWP V2, these are virtual
689 sections (for lack of a better name). */
690 struct dwo_sections sections
{};
692 /* The CUs in the file.
693 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
694 an extension to handle LLVM's Link Time Optimization output (where
695 multiple source files may be compiled into a single object/dwo pair). */
698 /* Table of TUs in the file.
699 Each element is a struct dwo_unit. */
703 /* These sections are what may appear in a DWP file. */
707 /* These are used by both DWP version 1 and 2. */
708 struct dwarf2_section_info str
;
709 struct dwarf2_section_info cu_index
;
710 struct dwarf2_section_info tu_index
;
712 /* These are only used by DWP version 2 files.
713 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
714 sections are referenced by section number, and are not recorded here.
715 In DWP version 2 there is at most one copy of all these sections, each
716 section being (effectively) comprised of the concatenation of all of the
717 individual sections that exist in the version 1 format.
718 To keep the code simple we treat each of these concatenated pieces as a
719 section itself (a virtual section?). */
720 struct dwarf2_section_info abbrev
;
721 struct dwarf2_section_info info
;
722 struct dwarf2_section_info line
;
723 struct dwarf2_section_info loc
;
724 struct dwarf2_section_info macinfo
;
725 struct dwarf2_section_info macro
;
726 struct dwarf2_section_info str_offsets
;
727 struct dwarf2_section_info types
;
730 /* These sections are what may appear in a virtual DWO file in DWP version 1.
731 A virtual DWO file is a DWO file as it appears in a DWP file. */
733 struct virtual_v1_dwo_sections
735 struct dwarf2_section_info abbrev
;
736 struct dwarf2_section_info line
;
737 struct dwarf2_section_info loc
;
738 struct dwarf2_section_info macinfo
;
739 struct dwarf2_section_info macro
;
740 struct dwarf2_section_info str_offsets
;
741 /* Each DWP hash table entry records one CU or one TU.
742 That is recorded here, and copied to dwo_unit.section. */
743 struct dwarf2_section_info info_or_types
;
746 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
747 In version 2, the sections of the DWO files are concatenated together
748 and stored in one section of that name. Thus each ELF section contains
749 several "virtual" sections. */
751 struct virtual_v2_dwo_sections
753 bfd_size_type abbrev_offset
;
754 bfd_size_type abbrev_size
;
756 bfd_size_type line_offset
;
757 bfd_size_type line_size
;
759 bfd_size_type loc_offset
;
760 bfd_size_type loc_size
;
762 bfd_size_type macinfo_offset
;
763 bfd_size_type macinfo_size
;
765 bfd_size_type macro_offset
;
766 bfd_size_type macro_size
;
768 bfd_size_type str_offsets_offset
;
769 bfd_size_type str_offsets_size
;
771 /* Each DWP hash table entry records one CU or one TU.
772 That is recorded here, and copied to dwo_unit.section. */
773 bfd_size_type info_or_types_offset
;
774 bfd_size_type info_or_types_size
;
777 /* Contents of DWP hash tables. */
779 struct dwp_hash_table
781 uint32_t version
, nr_columns
;
782 uint32_t nr_units
, nr_slots
;
783 const gdb_byte
*hash_table
, *unit_table
;
788 const gdb_byte
*indices
;
792 /* This is indexed by column number and gives the id of the section
794 #define MAX_NR_V2_DWO_SECTIONS \
795 (1 /* .debug_info or .debug_types */ \
796 + 1 /* .debug_abbrev */ \
797 + 1 /* .debug_line */ \
798 + 1 /* .debug_loc */ \
799 + 1 /* .debug_str_offsets */ \
800 + 1 /* .debug_macro or .debug_macinfo */)
801 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
802 const gdb_byte
*offsets
;
803 const gdb_byte
*sizes
;
808 /* Data for one DWP file. */
812 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
814 dbfd (std::move (abfd
))
818 /* Name of the file. */
821 /* File format version. */
825 gdb_bfd_ref_ptr dbfd
;
827 /* Section info for this file. */
828 struct dwp_sections sections
{};
830 /* Table of CUs in the file. */
831 const struct dwp_hash_table
*cus
= nullptr;
833 /* Table of TUs in the file. */
834 const struct dwp_hash_table
*tus
= nullptr;
836 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
840 /* Table to map ELF section numbers to their sections.
841 This is only needed for the DWP V1 file format. */
842 unsigned int num_sections
= 0;
843 asection
**elf_sections
= nullptr;
846 /* Struct used to pass misc. parameters to read_die_and_children, et
847 al. which are used for both .debug_info and .debug_types dies.
848 All parameters here are unchanging for the life of the call. This
849 struct exists to abstract away the constant parameters of die reading. */
851 struct die_reader_specs
853 /* The bfd of die_section. */
856 /* The CU of the DIE we are parsing. */
857 struct dwarf2_cu
*cu
;
859 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
860 struct dwo_file
*dwo_file
;
862 /* The section the die comes from.
863 This is either .debug_info or .debug_types, or the .dwo variants. */
864 struct dwarf2_section_info
*die_section
;
866 /* die_section->buffer. */
867 const gdb_byte
*buffer
;
869 /* The end of the buffer. */
870 const gdb_byte
*buffer_end
;
872 /* The abbreviation table to use when reading the DIEs. */
873 struct abbrev_table
*abbrev_table
;
876 /* A subclass of die_reader_specs that holds storage and has complex
877 constructor and destructor behavior. */
879 class cutu_reader
: public die_reader_specs
883 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
884 struct abbrev_table
*abbrev_table
,
888 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
889 struct dwarf2_cu
*parent_cu
= nullptr,
890 struct dwo_file
*dwo_file
= nullptr);
892 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
894 const gdb_byte
*info_ptr
= nullptr;
895 struct die_info
*comp_unit_die
= nullptr;
896 bool dummy_p
= false;
898 /* Release the new CU, putting it on the chain. This cannot be done
903 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
904 int use_existing_cu
);
906 struct dwarf2_per_cu_data
*m_this_cu
;
907 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
909 /* The ordinary abbreviation table. */
910 abbrev_table_up m_abbrev_table_holder
;
912 /* The DWO abbreviation table. */
913 abbrev_table_up m_dwo_abbrev_table
;
916 /* When we construct a partial symbol table entry we only
917 need this much information. */
918 struct partial_die_info
: public allocate_on_obstack
920 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
922 /* Disable assign but still keep copy ctor, which is needed
923 load_partial_dies. */
924 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
926 /* Adjust the partial die before generating a symbol for it. This
927 function may set the is_external flag or change the DIE's
929 void fixup (struct dwarf2_cu
*cu
);
931 /* Read a minimal amount of information into the minimal die
933 const gdb_byte
*read (const struct die_reader_specs
*reader
,
934 const struct abbrev_info
&abbrev
,
935 const gdb_byte
*info_ptr
);
937 /* Offset of this DIE. */
938 const sect_offset sect_off
;
940 /* DWARF-2 tag for this DIE. */
941 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
943 /* Assorted flags describing the data found in this DIE. */
944 const unsigned int has_children
: 1;
946 unsigned int is_external
: 1;
947 unsigned int is_declaration
: 1;
948 unsigned int has_type
: 1;
949 unsigned int has_specification
: 1;
950 unsigned int has_pc_info
: 1;
951 unsigned int may_be_inlined
: 1;
953 /* This DIE has been marked DW_AT_main_subprogram. */
954 unsigned int main_subprogram
: 1;
956 /* Flag set if the SCOPE field of this structure has been
958 unsigned int scope_set
: 1;
960 /* Flag set if the DIE has a byte_size attribute. */
961 unsigned int has_byte_size
: 1;
963 /* Flag set if the DIE has a DW_AT_const_value attribute. */
964 unsigned int has_const_value
: 1;
966 /* Flag set if any of the DIE's children are template arguments. */
967 unsigned int has_template_arguments
: 1;
969 /* Flag set if fixup has been called on this die. */
970 unsigned int fixup_called
: 1;
972 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
973 unsigned int is_dwz
: 1;
975 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
976 unsigned int spec_is_dwz
: 1;
978 /* The name of this DIE. Normally the value of DW_AT_name, but
979 sometimes a default name for unnamed DIEs. */
980 const char *name
= nullptr;
982 /* The linkage name, if present. */
983 const char *linkage_name
= nullptr;
985 /* The scope to prepend to our children. This is generally
986 allocated on the comp_unit_obstack, so will disappear
987 when this compilation unit leaves the cache. */
988 const char *scope
= nullptr;
990 /* Some data associated with the partial DIE. The tag determines
991 which field is live. */
994 /* The location description associated with this DIE, if any. */
995 struct dwarf_block
*locdesc
;
996 /* The offset of an import, for DW_TAG_imported_unit. */
997 sect_offset sect_off
;
1000 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1001 CORE_ADDR lowpc
= 0;
1002 CORE_ADDR highpc
= 0;
1004 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1005 DW_AT_sibling, if any. */
1006 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1007 could return DW_AT_sibling values to its caller load_partial_dies. */
1008 const gdb_byte
*sibling
= nullptr;
1010 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1011 DW_AT_specification (or DW_AT_abstract_origin or
1012 DW_AT_extension). */
1013 sect_offset spec_offset
{};
1015 /* Pointers to this DIE's parent, first child, and next sibling,
1017 struct partial_die_info
*die_parent
= nullptr;
1018 struct partial_die_info
*die_child
= nullptr;
1019 struct partial_die_info
*die_sibling
= nullptr;
1021 friend struct partial_die_info
*
1022 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1025 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1026 partial_die_info (sect_offset sect_off
)
1027 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1031 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1033 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1038 has_specification
= 0;
1041 main_subprogram
= 0;
1044 has_const_value
= 0;
1045 has_template_arguments
= 0;
1052 /* This data structure holds a complete die structure. */
1055 /* DWARF-2 tag for this DIE. */
1056 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1058 /* Number of attributes */
1059 unsigned char num_attrs
;
1061 /* True if we're presently building the full type name for the
1062 type derived from this DIE. */
1063 unsigned char building_fullname
: 1;
1065 /* True if this die is in process. PR 16581. */
1066 unsigned char in_process
: 1;
1068 /* True if this DIE has children. */
1069 unsigned char has_children
: 1;
1072 unsigned int abbrev
;
1074 /* Offset in .debug_info or .debug_types section. */
1075 sect_offset sect_off
;
1077 /* The dies in a compilation unit form an n-ary tree. PARENT
1078 points to this die's parent; CHILD points to the first child of
1079 this node; and all the children of a given node are chained
1080 together via their SIBLING fields. */
1081 struct die_info
*child
; /* Its first child, if any. */
1082 struct die_info
*sibling
; /* Its next sibling, if any. */
1083 struct die_info
*parent
; /* Its parent, if any. */
1085 /* An array of attributes, with NUM_ATTRS elements. There may be
1086 zero, but it's not common and zero-sized arrays are not
1087 sufficiently portable C. */
1088 struct attribute attrs
[1];
1091 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1092 but this would require a corresponding change in unpack_field_as_long
1094 static int bits_per_byte
= 8;
1096 /* When reading a variant or variant part, we track a bit more
1097 information about the field, and store it in an object of this
1100 struct variant_field
1102 /* If we see a DW_TAG_variant, then this will be the discriminant
1104 ULONGEST discriminant_value
;
1105 /* If we see a DW_TAG_variant, then this will be set if this is the
1107 bool default_branch
;
1108 /* While reading a DW_TAG_variant_part, this will be set if this
1109 field is the discriminant. */
1110 bool is_discriminant
;
1115 int accessibility
= 0;
1117 /* Extra information to describe a variant or variant part. */
1118 struct variant_field variant
{};
1119 struct field field
{};
1124 const char *name
= nullptr;
1125 std::vector
<struct fn_field
> fnfields
;
1128 /* The routines that read and process dies for a C struct or C++ class
1129 pass lists of data member fields and lists of member function fields
1130 in an instance of a field_info structure, as defined below. */
1133 /* List of data member and baseclasses fields. */
1134 std::vector
<struct nextfield
> fields
;
1135 std::vector
<struct nextfield
> baseclasses
;
1137 /* Number of fields (including baseclasses). */
1140 /* Set if the accessibility of one of the fields is not public. */
1141 int non_public_fields
= 0;
1143 /* Member function fieldlist array, contains name of possibly overloaded
1144 member function, number of overloaded member functions and a pointer
1145 to the head of the member function field chain. */
1146 std::vector
<struct fnfieldlist
> fnfieldlists
;
1148 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1149 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1150 std::vector
<struct decl_field
> typedef_field_list
;
1152 /* Nested types defined by this class and the number of elements in this
1154 std::vector
<struct decl_field
> nested_types_list
;
1157 /* Loaded secondary compilation units are kept in memory until they
1158 have not been referenced for the processing of this many
1159 compilation units. Set this to zero to disable caching. Cache
1160 sizes of up to at least twenty will improve startup time for
1161 typical inter-CU-reference binaries, at an obvious memory cost. */
1162 static int dwarf_max_cache_age
= 5;
1164 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1165 struct cmd_list_element
*c
, const char *value
)
1167 fprintf_filtered (file
, _("The upper bound on the age of cached "
1168 "DWARF compilation units is %s.\n"),
1172 /* local function prototypes */
1174 static void dwarf2_find_base_address (struct die_info
*die
,
1175 struct dwarf2_cu
*cu
);
1177 static dwarf2_psymtab
*create_partial_symtab
1178 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1180 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1181 const gdb_byte
*info_ptr
,
1182 struct die_info
*type_unit_die
);
1184 static void dwarf2_build_psymtabs_hard
1185 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1187 static void scan_partial_symbols (struct partial_die_info
*,
1188 CORE_ADDR
*, CORE_ADDR
*,
1189 int, struct dwarf2_cu
*);
1191 static void add_partial_symbol (struct partial_die_info
*,
1192 struct dwarf2_cu
*);
1194 static void add_partial_namespace (struct partial_die_info
*pdi
,
1195 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1196 int set_addrmap
, struct dwarf2_cu
*cu
);
1198 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1199 CORE_ADDR
*highpc
, int set_addrmap
,
1200 struct dwarf2_cu
*cu
);
1202 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1203 struct dwarf2_cu
*cu
);
1205 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1206 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1207 int need_pc
, struct dwarf2_cu
*cu
);
1209 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1211 static struct partial_die_info
*load_partial_dies
1212 (const struct die_reader_specs
*, const gdb_byte
*, int);
1214 /* A pair of partial_die_info and compilation unit. */
1215 struct cu_partial_die_info
1217 /* The compilation unit of the partial_die_info. */
1218 struct dwarf2_cu
*cu
;
1219 /* A partial_die_info. */
1220 struct partial_die_info
*pdi
;
1222 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1228 cu_partial_die_info () = delete;
1231 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1232 struct dwarf2_cu
*);
1234 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1235 struct attribute
*, struct attr_abbrev
*,
1236 const gdb_byte
*, bool *need_reprocess
);
1238 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1239 struct attribute
*attr
);
1241 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1243 static LONGEST read_checked_initial_length_and_offset
1244 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1245 unsigned int *, unsigned int *);
1247 static sect_offset read_abbrev_offset
1248 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1249 struct dwarf2_section_info
*, sect_offset
);
1251 static const char *read_indirect_string
1252 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1253 const struct comp_unit_head
*, unsigned int *);
1255 static const char *read_indirect_line_string
1256 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1257 const struct comp_unit_head
*, unsigned int *);
1259 static const char *read_indirect_string_at_offset
1260 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1261 LONGEST str_offset
);
1263 static const char *read_indirect_string_from_dwz
1264 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1266 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1270 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1271 ULONGEST str_index
);
1273 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1274 ULONGEST str_index
);
1276 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1278 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1279 struct dwarf2_cu
*);
1281 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1284 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1285 struct dwarf2_cu
*cu
);
1287 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1289 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1290 struct dwarf2_cu
*cu
);
1292 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1294 static struct die_info
*die_specification (struct die_info
*die
,
1295 struct dwarf2_cu
**);
1297 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1298 struct dwarf2_cu
*cu
);
1300 static void dwarf_decode_lines (struct line_header
*, const char *,
1301 struct dwarf2_cu
*, dwarf2_psymtab
*,
1302 CORE_ADDR
, int decode_mapping
);
1304 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1307 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1308 struct dwarf2_cu
*, struct symbol
* = NULL
);
1310 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1311 struct dwarf2_cu
*);
1313 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1316 struct obstack
*obstack
,
1317 struct dwarf2_cu
*cu
, LONGEST
*value
,
1318 const gdb_byte
**bytes
,
1319 struct dwarf2_locexpr_baton
**baton
);
1321 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1323 static int need_gnat_info (struct dwarf2_cu
*);
1325 static struct type
*die_descriptive_type (struct die_info
*,
1326 struct dwarf2_cu
*);
1328 static void set_descriptive_type (struct type
*, struct die_info
*,
1329 struct dwarf2_cu
*);
1331 static struct type
*die_containing_type (struct die_info
*,
1332 struct dwarf2_cu
*);
1334 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1335 struct dwarf2_cu
*);
1337 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1339 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1341 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1343 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1344 const char *suffix
, int physname
,
1345 struct dwarf2_cu
*cu
);
1347 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1349 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1351 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1353 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1355 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1357 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1359 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1360 struct dwarf2_cu
*, dwarf2_psymtab
*);
1362 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1363 values. Keep the items ordered with increasing constraints compliance. */
1366 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1367 PC_BOUNDS_NOT_PRESENT
,
1369 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1370 were present but they do not form a valid range of PC addresses. */
1373 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1376 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1380 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1381 CORE_ADDR
*, CORE_ADDR
*,
1385 static void get_scope_pc_bounds (struct die_info
*,
1386 CORE_ADDR
*, CORE_ADDR
*,
1387 struct dwarf2_cu
*);
1389 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1390 CORE_ADDR
, struct dwarf2_cu
*);
1392 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1393 struct dwarf2_cu
*);
1395 static void dwarf2_attach_fields_to_type (struct field_info
*,
1396 struct type
*, struct dwarf2_cu
*);
1398 static void dwarf2_add_member_fn (struct field_info
*,
1399 struct die_info
*, struct type
*,
1400 struct dwarf2_cu
*);
1402 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1404 struct dwarf2_cu
*);
1406 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1408 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1410 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1412 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1414 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1416 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1418 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1420 static struct type
*read_module_type (struct die_info
*die
,
1421 struct dwarf2_cu
*cu
);
1423 static const char *namespace_name (struct die_info
*die
,
1424 int *is_anonymous
, struct dwarf2_cu
*);
1426 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1428 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1430 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1431 struct dwarf2_cu
*);
1433 static struct die_info
*read_die_and_siblings_1
1434 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1437 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1438 const gdb_byte
*info_ptr
,
1439 const gdb_byte
**new_info_ptr
,
1440 struct die_info
*parent
);
1442 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1443 struct die_info
**, const gdb_byte
*,
1446 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1447 struct die_info
**, const gdb_byte
*);
1449 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1451 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1454 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1456 static const char *dwarf2_full_name (const char *name
,
1457 struct die_info
*die
,
1458 struct dwarf2_cu
*cu
);
1460 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1461 struct dwarf2_cu
*cu
);
1463 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1464 struct dwarf2_cu
**);
1466 static const char *dwarf_tag_name (unsigned int);
1468 static const char *dwarf_attr_name (unsigned int);
1470 static const char *dwarf_form_name (unsigned int);
1472 static const char *dwarf_bool_name (unsigned int);
1474 static const char *dwarf_type_encoding_name (unsigned int);
1476 static struct die_info
*sibling_die (struct die_info
*);
1478 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1480 static void dump_die_for_error (struct die_info
*);
1482 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1485 /*static*/ void dump_die (struct die_info
*, int max_level
);
1487 static void store_in_ref_table (struct die_info
*,
1488 struct dwarf2_cu
*);
1490 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1492 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1494 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1495 const struct attribute
*,
1496 struct dwarf2_cu
**);
1498 static struct die_info
*follow_die_ref (struct die_info
*,
1499 const struct attribute
*,
1500 struct dwarf2_cu
**);
1502 static struct die_info
*follow_die_sig (struct die_info
*,
1503 const struct attribute
*,
1504 struct dwarf2_cu
**);
1506 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1507 struct dwarf2_cu
*);
1509 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1510 const struct attribute
*,
1511 struct dwarf2_cu
*);
1513 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1515 static void read_signatured_type (struct signatured_type
*);
1517 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1518 struct die_info
*die
, struct dwarf2_cu
*cu
,
1519 struct dynamic_prop
*prop
, struct type
*type
);
1521 /* memory allocation interface */
1523 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1525 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1527 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1529 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1530 struct dwarf2_loclist_baton
*baton
,
1531 const struct attribute
*attr
);
1533 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1535 struct dwarf2_cu
*cu
,
1538 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1539 const gdb_byte
*info_ptr
,
1540 struct abbrev_info
*abbrev
);
1542 static hashval_t
partial_die_hash (const void *item
);
1544 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1546 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1547 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1548 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1550 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1551 struct die_info
*comp_unit_die
,
1552 enum language pretend_language
);
1554 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1556 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1558 static struct type
*set_die_type (struct die_info
*, struct type
*,
1559 struct dwarf2_cu
*);
1561 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1563 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1565 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1568 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1571 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1574 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1575 struct dwarf2_per_cu_data
*);
1577 static void dwarf2_mark (struct dwarf2_cu
*);
1579 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1581 static struct type
*get_die_type_at_offset (sect_offset
,
1582 struct dwarf2_per_cu_data
*);
1584 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1586 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1587 enum language pretend_language
);
1589 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1591 /* Class, the destructor of which frees all allocated queue entries. This
1592 will only have work to do if an error was thrown while processing the
1593 dwarf. If no error was thrown then the queue entries should have all
1594 been processed, and freed, as we went along. */
1596 class dwarf2_queue_guard
1599 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1600 : m_per_objfile (per_objfile
)
1604 /* Free any entries remaining on the queue. There should only be
1605 entries left if we hit an error while processing the dwarf. */
1606 ~dwarf2_queue_guard ()
1608 /* Ensure that no memory is allocated by the queue. */
1609 std::queue
<dwarf2_queue_item
> empty
;
1610 std::swap (m_per_objfile
->queue
, empty
);
1613 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1616 dwarf2_per_objfile
*m_per_objfile
;
1619 dwarf2_queue_item::~dwarf2_queue_item ()
1621 /* Anything still marked queued is likely to be in an
1622 inconsistent state, so discard it. */
1625 if (per_cu
->cu
!= NULL
)
1626 free_one_cached_comp_unit (per_cu
);
1631 /* The return type of find_file_and_directory. Note, the enclosed
1632 string pointers are only valid while this object is valid. */
1634 struct file_and_directory
1636 /* The filename. This is never NULL. */
1639 /* The compilation directory. NULL if not known. If we needed to
1640 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1641 points directly to the DW_AT_comp_dir string attribute owned by
1642 the obstack that owns the DIE. */
1643 const char *comp_dir
;
1645 /* If we needed to build a new string for comp_dir, this is what
1646 owns the storage. */
1647 std::string comp_dir_storage
;
1650 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1651 struct dwarf2_cu
*cu
);
1653 static htab_up
allocate_signatured_type_table (struct objfile
*objfile
);
1655 static htab_up
allocate_dwo_unit_table (struct objfile
*objfile
);
1657 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1658 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1659 struct dwp_file
*dwp_file
, const char *comp_dir
,
1660 ULONGEST signature
, int is_debug_types
);
1662 static struct dwp_file
*get_dwp_file
1663 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1665 static struct dwo_unit
*lookup_dwo_comp_unit
1666 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1668 static struct dwo_unit
*lookup_dwo_type_unit
1669 (struct signatured_type
*, const char *, const char *);
1671 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1673 /* A unique pointer to a dwo_file. */
1675 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1677 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1679 static void check_producer (struct dwarf2_cu
*cu
);
1681 static void free_line_header_voidp (void *arg
);
1683 /* Various complaints about symbol reading that don't abort the process. */
1686 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1688 complaint (_("statement list doesn't fit in .debug_line section"));
1692 dwarf2_debug_line_missing_file_complaint (void)
1694 complaint (_(".debug_line section has line data without a file"));
1698 dwarf2_debug_line_missing_end_sequence_complaint (void)
1700 complaint (_(".debug_line section has line "
1701 "program sequence without an end"));
1705 dwarf2_complex_location_expr_complaint (void)
1707 complaint (_("location expression too complex"));
1711 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1714 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1719 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1721 complaint (_("debug info runs off end of %s section"
1723 section
->get_name (),
1724 section
->get_file_name ());
1728 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1730 complaint (_("macro debug info contains a "
1731 "malformed macro definition:\n`%s'"),
1736 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1738 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1742 /* Hash function for line_header_hash. */
1745 line_header_hash (const struct line_header
*ofs
)
1747 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1750 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1753 line_header_hash_voidp (const void *item
)
1755 const struct line_header
*ofs
= (const struct line_header
*) item
;
1757 return line_header_hash (ofs
);
1760 /* Equality function for line_header_hash. */
1763 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1765 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1766 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1768 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1769 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1774 /* See declaration. */
1776 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1777 const dwarf2_debug_sections
*names
,
1779 : objfile (objfile_
),
1780 can_copy (can_copy_
)
1783 names
= &dwarf2_elf_names
;
1785 bfd
*obfd
= objfile
->obfd
;
1787 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1788 locate_sections (obfd
, sec
, *names
);
1791 dwarf2_per_objfile::~dwarf2_per_objfile ()
1793 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1794 free_cached_comp_units ();
1796 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1797 per_cu
->imported_symtabs_free ();
1799 for (signatured_type
*sig_type
: all_type_units
)
1800 sig_type
->per_cu
.imported_symtabs_free ();
1802 /* Everything else should be on the objfile obstack. */
1805 /* See declaration. */
1808 dwarf2_per_objfile::free_cached_comp_units ()
1810 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1811 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1812 while (per_cu
!= NULL
)
1814 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1817 *last_chain
= next_cu
;
1822 /* A helper class that calls free_cached_comp_units on
1825 class free_cached_comp_units
1829 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1830 : m_per_objfile (per_objfile
)
1834 ~free_cached_comp_units ()
1836 m_per_objfile
->free_cached_comp_units ();
1839 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1843 dwarf2_per_objfile
*m_per_objfile
;
1846 /* Try to locate the sections we need for DWARF 2 debugging
1847 information and return true if we have enough to do something.
1848 NAMES points to the dwarf2 section names, or is NULL if the standard
1849 ELF names are used. CAN_COPY is true for formats where symbol
1850 interposition is possible and so symbol values must follow copy
1851 relocation rules. */
1854 dwarf2_has_info (struct objfile
*objfile
,
1855 const struct dwarf2_debug_sections
*names
,
1858 if (objfile
->flags
& OBJF_READNEVER
)
1861 struct dwarf2_per_objfile
*dwarf2_per_objfile
1862 = get_dwarf2_per_objfile (objfile
);
1864 if (dwarf2_per_objfile
== NULL
)
1865 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1869 return (!dwarf2_per_objfile
->info
.is_virtual
1870 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1871 && !dwarf2_per_objfile
->abbrev
.is_virtual
1872 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1875 /* When loading sections, we look either for uncompressed section or for
1876 compressed section names. */
1879 section_is_p (const char *section_name
,
1880 const struct dwarf2_section_names
*names
)
1882 if (names
->normal
!= NULL
1883 && strcmp (section_name
, names
->normal
) == 0)
1885 if (names
->compressed
!= NULL
1886 && strcmp (section_name
, names
->compressed
) == 0)
1891 /* See declaration. */
1894 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1895 const dwarf2_debug_sections
&names
)
1897 flagword aflag
= bfd_section_flags (sectp
);
1899 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1902 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1903 > bfd_get_file_size (abfd
))
1905 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1906 warning (_("Discarding section %s which has a section size (%s"
1907 ") larger than the file size [in module %s]"),
1908 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1909 bfd_get_filename (abfd
));
1911 else if (section_is_p (sectp
->name
, &names
.info
))
1913 this->info
.s
.section
= sectp
;
1914 this->info
.size
= bfd_section_size (sectp
);
1916 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1918 this->abbrev
.s
.section
= sectp
;
1919 this->abbrev
.size
= bfd_section_size (sectp
);
1921 else if (section_is_p (sectp
->name
, &names
.line
))
1923 this->line
.s
.section
= sectp
;
1924 this->line
.size
= bfd_section_size (sectp
);
1926 else if (section_is_p (sectp
->name
, &names
.loc
))
1928 this->loc
.s
.section
= sectp
;
1929 this->loc
.size
= bfd_section_size (sectp
);
1931 else if (section_is_p (sectp
->name
, &names
.loclists
))
1933 this->loclists
.s
.section
= sectp
;
1934 this->loclists
.size
= bfd_section_size (sectp
);
1936 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1938 this->macinfo
.s
.section
= sectp
;
1939 this->macinfo
.size
= bfd_section_size (sectp
);
1941 else if (section_is_p (sectp
->name
, &names
.macro
))
1943 this->macro
.s
.section
= sectp
;
1944 this->macro
.size
= bfd_section_size (sectp
);
1946 else if (section_is_p (sectp
->name
, &names
.str
))
1948 this->str
.s
.section
= sectp
;
1949 this->str
.size
= bfd_section_size (sectp
);
1951 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1953 this->str_offsets
.s
.section
= sectp
;
1954 this->str_offsets
.size
= bfd_section_size (sectp
);
1956 else if (section_is_p (sectp
->name
, &names
.line_str
))
1958 this->line_str
.s
.section
= sectp
;
1959 this->line_str
.size
= bfd_section_size (sectp
);
1961 else if (section_is_p (sectp
->name
, &names
.addr
))
1963 this->addr
.s
.section
= sectp
;
1964 this->addr
.size
= bfd_section_size (sectp
);
1966 else if (section_is_p (sectp
->name
, &names
.frame
))
1968 this->frame
.s
.section
= sectp
;
1969 this->frame
.size
= bfd_section_size (sectp
);
1971 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1973 this->eh_frame
.s
.section
= sectp
;
1974 this->eh_frame
.size
= bfd_section_size (sectp
);
1976 else if (section_is_p (sectp
->name
, &names
.ranges
))
1978 this->ranges
.s
.section
= sectp
;
1979 this->ranges
.size
= bfd_section_size (sectp
);
1981 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1983 this->rnglists
.s
.section
= sectp
;
1984 this->rnglists
.size
= bfd_section_size (sectp
);
1986 else if (section_is_p (sectp
->name
, &names
.types
))
1988 struct dwarf2_section_info type_section
;
1990 memset (&type_section
, 0, sizeof (type_section
));
1991 type_section
.s
.section
= sectp
;
1992 type_section
.size
= bfd_section_size (sectp
);
1994 this->types
.push_back (type_section
);
1996 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1998 this->gdb_index
.s
.section
= sectp
;
1999 this->gdb_index
.size
= bfd_section_size (sectp
);
2001 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2003 this->debug_names
.s
.section
= sectp
;
2004 this->debug_names
.size
= bfd_section_size (sectp
);
2006 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2008 this->debug_aranges
.s
.section
= sectp
;
2009 this->debug_aranges
.size
= bfd_section_size (sectp
);
2012 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2013 && bfd_section_vma (sectp
) == 0)
2014 this->has_section_at_zero
= true;
2017 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2021 dwarf2_get_section_info (struct objfile
*objfile
,
2022 enum dwarf2_section_enum sect
,
2023 asection
**sectp
, const gdb_byte
**bufp
,
2024 bfd_size_type
*sizep
)
2026 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2027 struct dwarf2_section_info
*info
;
2029 /* We may see an objfile without any DWARF, in which case we just
2040 case DWARF2_DEBUG_FRAME
:
2041 info
= &data
->frame
;
2043 case DWARF2_EH_FRAME
:
2044 info
= &data
->eh_frame
;
2047 gdb_assert_not_reached ("unexpected section");
2050 info
->read (objfile
);
2052 *sectp
= info
->get_bfd_section ();
2053 *bufp
= info
->buffer
;
2054 *sizep
= info
->size
;
2057 /* A helper function to find the sections for a .dwz file. */
2060 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2062 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2064 /* Note that we only support the standard ELF names, because .dwz
2065 is ELF-only (at the time of writing). */
2066 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2068 dwz_file
->abbrev
.s
.section
= sectp
;
2069 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2071 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2073 dwz_file
->info
.s
.section
= sectp
;
2074 dwz_file
->info
.size
= bfd_section_size (sectp
);
2076 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2078 dwz_file
->str
.s
.section
= sectp
;
2079 dwz_file
->str
.size
= bfd_section_size (sectp
);
2081 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2083 dwz_file
->line
.s
.section
= sectp
;
2084 dwz_file
->line
.size
= bfd_section_size (sectp
);
2086 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2088 dwz_file
->macro
.s
.section
= sectp
;
2089 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2091 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2093 dwz_file
->gdb_index
.s
.section
= sectp
;
2094 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2096 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2098 dwz_file
->debug_names
.s
.section
= sectp
;
2099 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2103 /* See dwarf2read.h. */
2106 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2108 const char *filename
;
2109 bfd_size_type buildid_len_arg
;
2113 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2114 return dwarf2_per_objfile
->dwz_file
.get ();
2116 bfd_set_error (bfd_error_no_error
);
2117 gdb::unique_xmalloc_ptr
<char> data
2118 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2119 &buildid_len_arg
, &buildid
));
2122 if (bfd_get_error () == bfd_error_no_error
)
2124 error (_("could not read '.gnu_debugaltlink' section: %s"),
2125 bfd_errmsg (bfd_get_error ()));
2128 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2130 buildid_len
= (size_t) buildid_len_arg
;
2132 filename
= data
.get ();
2134 std::string abs_storage
;
2135 if (!IS_ABSOLUTE_PATH (filename
))
2137 gdb::unique_xmalloc_ptr
<char> abs
2138 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2140 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2141 filename
= abs_storage
.c_str ();
2144 /* First try the file name given in the section. If that doesn't
2145 work, try to use the build-id instead. */
2146 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2147 if (dwz_bfd
!= NULL
)
2149 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2150 dwz_bfd
.reset (nullptr);
2153 if (dwz_bfd
== NULL
)
2154 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2156 if (dwz_bfd
== NULL
)
2157 error (_("could not find '.gnu_debugaltlink' file for %s"),
2158 objfile_name (dwarf2_per_objfile
->objfile
));
2160 std::unique_ptr
<struct dwz_file
> result
2161 (new struct dwz_file (std::move (dwz_bfd
)));
2163 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2166 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2167 result
->dwz_bfd
.get ());
2168 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2169 return dwarf2_per_objfile
->dwz_file
.get ();
2172 /* DWARF quick_symbols_functions support. */
2174 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2175 unique line tables, so we maintain a separate table of all .debug_line
2176 derived entries to support the sharing.
2177 All the quick functions need is the list of file names. We discard the
2178 line_header when we're done and don't need to record it here. */
2179 struct quick_file_names
2181 /* The data used to construct the hash key. */
2182 struct stmt_list_hash hash
;
2184 /* The number of entries in file_names, real_names. */
2185 unsigned int num_file_names
;
2187 /* The file names from the line table, after being run through
2189 const char **file_names
;
2191 /* The file names from the line table after being run through
2192 gdb_realpath. These are computed lazily. */
2193 const char **real_names
;
2196 /* When using the index (and thus not using psymtabs), each CU has an
2197 object of this type. This is used to hold information needed by
2198 the various "quick" methods. */
2199 struct dwarf2_per_cu_quick_data
2201 /* The file table. This can be NULL if there was no file table
2202 or it's currently not read in.
2203 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2204 struct quick_file_names
*file_names
;
2206 /* The corresponding symbol table. This is NULL if symbols for this
2207 CU have not yet been read. */
2208 struct compunit_symtab
*compunit_symtab
;
2210 /* A temporary mark bit used when iterating over all CUs in
2211 expand_symtabs_matching. */
2212 unsigned int mark
: 1;
2214 /* True if we've tried to read the file table and found there isn't one.
2215 There will be no point in trying to read it again next time. */
2216 unsigned int no_file_data
: 1;
2219 /* Utility hash function for a stmt_list_hash. */
2222 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2226 if (stmt_list_hash
->dwo_unit
!= NULL
)
2227 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2228 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2232 /* Utility equality function for a stmt_list_hash. */
2235 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2236 const struct stmt_list_hash
*rhs
)
2238 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2240 if (lhs
->dwo_unit
!= NULL
2241 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2244 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2247 /* Hash function for a quick_file_names. */
2250 hash_file_name_entry (const void *e
)
2252 const struct quick_file_names
*file_data
2253 = (const struct quick_file_names
*) e
;
2255 return hash_stmt_list_entry (&file_data
->hash
);
2258 /* Equality function for a quick_file_names. */
2261 eq_file_name_entry (const void *a
, const void *b
)
2263 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2264 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2266 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2269 /* Delete function for a quick_file_names. */
2272 delete_file_name_entry (void *e
)
2274 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2277 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2279 xfree ((void*) file_data
->file_names
[i
]);
2280 if (file_data
->real_names
)
2281 xfree ((void*) file_data
->real_names
[i
]);
2284 /* The space for the struct itself lives on objfile_obstack,
2285 so we don't free it here. */
2288 /* Create a quick_file_names hash table. */
2291 create_quick_file_names_table (unsigned int nr_initial_entries
)
2293 return htab_up (htab_create_alloc (nr_initial_entries
,
2294 hash_file_name_entry
, eq_file_name_entry
,
2295 delete_file_name_entry
, xcalloc
, xfree
));
2298 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2299 have to be created afterwards. You should call age_cached_comp_units after
2300 processing PER_CU->CU. dw2_setup must have been already called. */
2303 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2305 if (per_cu
->is_debug_types
)
2306 load_full_type_unit (per_cu
);
2308 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2310 if (per_cu
->cu
== NULL
)
2311 return; /* Dummy CU. */
2313 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2316 /* Read in the symbols for PER_CU. */
2319 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2321 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2323 /* Skip type_unit_groups, reading the type units they contain
2324 is handled elsewhere. */
2325 if (IS_TYPE_UNIT_GROUP (per_cu
))
2328 /* The destructor of dwarf2_queue_guard frees any entries left on
2329 the queue. After this point we're guaranteed to leave this function
2330 with the dwarf queue empty. */
2331 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2333 if (dwarf2_per_objfile
->using_index
2334 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2335 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2337 queue_comp_unit (per_cu
, language_minimal
);
2338 load_cu (per_cu
, skip_partial
);
2340 /* If we just loaded a CU from a DWO, and we're working with an index
2341 that may badly handle TUs, load all the TUs in that DWO as well.
2342 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2343 if (!per_cu
->is_debug_types
2344 && per_cu
->cu
!= NULL
2345 && per_cu
->cu
->dwo_unit
!= NULL
2346 && dwarf2_per_objfile
->index_table
!= NULL
2347 && dwarf2_per_objfile
->index_table
->version
<= 7
2348 /* DWP files aren't supported yet. */
2349 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2350 queue_and_load_all_dwo_tus (per_cu
);
2353 process_queue (dwarf2_per_objfile
);
2355 /* Age the cache, releasing compilation units that have not
2356 been used recently. */
2357 age_cached_comp_units (dwarf2_per_objfile
);
2360 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2361 the objfile from which this CU came. Returns the resulting symbol
2364 static struct compunit_symtab
*
2365 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2367 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2369 gdb_assert (dwarf2_per_objfile
->using_index
);
2370 if (!per_cu
->v
.quick
->compunit_symtab
)
2372 free_cached_comp_units
freer (dwarf2_per_objfile
);
2373 scoped_restore decrementer
= increment_reading_symtab ();
2374 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2375 process_cu_includes (dwarf2_per_objfile
);
2378 return per_cu
->v
.quick
->compunit_symtab
;
2381 /* See declaration. */
2383 dwarf2_per_cu_data
*
2384 dwarf2_per_objfile::get_cutu (int index
)
2386 if (index
>= this->all_comp_units
.size ())
2388 index
-= this->all_comp_units
.size ();
2389 gdb_assert (index
< this->all_type_units
.size ());
2390 return &this->all_type_units
[index
]->per_cu
;
2393 return this->all_comp_units
[index
];
2396 /* See declaration. */
2398 dwarf2_per_cu_data
*
2399 dwarf2_per_objfile::get_cu (int index
)
2401 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2403 return this->all_comp_units
[index
];
2406 /* See declaration. */
2409 dwarf2_per_objfile::get_tu (int index
)
2411 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2413 return this->all_type_units
[index
];
2416 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2417 objfile_obstack, and constructed with the specified field
2420 static dwarf2_per_cu_data
*
2421 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2422 struct dwarf2_section_info
*section
,
2424 sect_offset sect_off
, ULONGEST length
)
2426 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2427 dwarf2_per_cu_data
*the_cu
2428 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2429 struct dwarf2_per_cu_data
);
2430 the_cu
->sect_off
= sect_off
;
2431 the_cu
->length
= length
;
2432 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2433 the_cu
->section
= section
;
2434 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2435 struct dwarf2_per_cu_quick_data
);
2436 the_cu
->is_dwz
= is_dwz
;
2440 /* A helper for create_cus_from_index that handles a given list of
2444 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2445 const gdb_byte
*cu_list
, offset_type n_elements
,
2446 struct dwarf2_section_info
*section
,
2449 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2451 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2453 sect_offset sect_off
2454 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2455 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2458 dwarf2_per_cu_data
*per_cu
2459 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2461 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2465 /* Read the CU list from the mapped index, and use it to create all
2466 the CU objects for this objfile. */
2469 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2470 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2471 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2473 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2474 dwarf2_per_objfile
->all_comp_units
.reserve
2475 ((cu_list_elements
+ dwz_elements
) / 2);
2477 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2478 &dwarf2_per_objfile
->info
, 0);
2480 if (dwz_elements
== 0)
2483 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2484 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2488 /* Create the signatured type hash table from the index. */
2491 create_signatured_type_table_from_index
2492 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2493 struct dwarf2_section_info
*section
,
2494 const gdb_byte
*bytes
,
2495 offset_type elements
)
2497 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2499 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2500 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2502 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2504 for (offset_type i
= 0; i
< elements
; i
+= 3)
2506 struct signatured_type
*sig_type
;
2509 cu_offset type_offset_in_tu
;
2511 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2512 sect_offset sect_off
2513 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2515 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2517 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2520 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2521 struct signatured_type
);
2522 sig_type
->signature
= signature
;
2523 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2524 sig_type
->per_cu
.is_debug_types
= 1;
2525 sig_type
->per_cu
.section
= section
;
2526 sig_type
->per_cu
.sect_off
= sect_off
;
2527 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2528 sig_type
->per_cu
.v
.quick
2529 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2530 struct dwarf2_per_cu_quick_data
);
2532 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2535 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2538 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2541 /* Create the signatured type hash table from .debug_names. */
2544 create_signatured_type_table_from_debug_names
2545 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2546 const mapped_debug_names
&map
,
2547 struct dwarf2_section_info
*section
,
2548 struct dwarf2_section_info
*abbrev_section
)
2550 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2552 section
->read (objfile
);
2553 abbrev_section
->read (objfile
);
2555 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2556 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2558 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2560 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2562 struct signatured_type
*sig_type
;
2565 sect_offset sect_off
2566 = (sect_offset
) (extract_unsigned_integer
2567 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2569 map
.dwarf5_byte_order
));
2571 comp_unit_head cu_header
;
2572 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2574 section
->buffer
+ to_underlying (sect_off
),
2577 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2578 struct signatured_type
);
2579 sig_type
->signature
= cu_header
.signature
;
2580 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2581 sig_type
->per_cu
.is_debug_types
= 1;
2582 sig_type
->per_cu
.section
= section
;
2583 sig_type
->per_cu
.sect_off
= sect_off
;
2584 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2585 sig_type
->per_cu
.v
.quick
2586 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2587 struct dwarf2_per_cu_quick_data
);
2589 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2592 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2595 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2598 /* Read the address map data from the mapped index, and use it to
2599 populate the objfile's psymtabs_addrmap. */
2602 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2603 struct mapped_index
*index
)
2605 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2606 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2607 const gdb_byte
*iter
, *end
;
2608 struct addrmap
*mutable_map
;
2611 auto_obstack temp_obstack
;
2613 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2615 iter
= index
->address_table
.data ();
2616 end
= iter
+ index
->address_table
.size ();
2618 baseaddr
= objfile
->text_section_offset ();
2622 ULONGEST hi
, lo
, cu_index
;
2623 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2625 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2627 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2632 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2633 hex_string (lo
), hex_string (hi
));
2637 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2639 complaint (_(".gdb_index address table has invalid CU number %u"),
2640 (unsigned) cu_index
);
2644 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2645 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2646 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2647 dwarf2_per_objfile
->get_cu (cu_index
));
2650 objfile
->partial_symtabs
->psymtabs_addrmap
2651 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2654 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2655 populate the objfile's psymtabs_addrmap. */
2658 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2659 struct dwarf2_section_info
*section
)
2661 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2662 bfd
*abfd
= objfile
->obfd
;
2663 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2664 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2666 auto_obstack temp_obstack
;
2667 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2669 std::unordered_map
<sect_offset
,
2670 dwarf2_per_cu_data
*,
2671 gdb::hash_enum
<sect_offset
>>
2672 debug_info_offset_to_per_cu
;
2673 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2675 const auto insertpair
2676 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2677 if (!insertpair
.second
)
2679 warning (_("Section .debug_aranges in %s has duplicate "
2680 "debug_info_offset %s, ignoring .debug_aranges."),
2681 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2686 section
->read (objfile
);
2688 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2690 const gdb_byte
*addr
= section
->buffer
;
2692 while (addr
< section
->buffer
+ section
->size
)
2694 const gdb_byte
*const entry_addr
= addr
;
2695 unsigned int bytes_read
;
2697 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2701 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2702 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2703 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2704 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2706 warning (_("Section .debug_aranges in %s entry at offset %s "
2707 "length %s exceeds section length %s, "
2708 "ignoring .debug_aranges."),
2709 objfile_name (objfile
),
2710 plongest (entry_addr
- section
->buffer
),
2711 plongest (bytes_read
+ entry_length
),
2712 pulongest (section
->size
));
2716 /* The version number. */
2717 const uint16_t version
= read_2_bytes (abfd
, addr
);
2721 warning (_("Section .debug_aranges in %s entry at offset %s "
2722 "has unsupported version %d, ignoring .debug_aranges."),
2723 objfile_name (objfile
),
2724 plongest (entry_addr
- section
->buffer
), version
);
2728 const uint64_t debug_info_offset
2729 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2730 addr
+= offset_size
;
2731 const auto per_cu_it
2732 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2733 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2735 warning (_("Section .debug_aranges in %s entry at offset %s "
2736 "debug_info_offset %s does not exists, "
2737 "ignoring .debug_aranges."),
2738 objfile_name (objfile
),
2739 plongest (entry_addr
- section
->buffer
),
2740 pulongest (debug_info_offset
));
2743 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2745 const uint8_t address_size
= *addr
++;
2746 if (address_size
< 1 || address_size
> 8)
2748 warning (_("Section .debug_aranges in %s entry at offset %s "
2749 "address_size %u is invalid, ignoring .debug_aranges."),
2750 objfile_name (objfile
),
2751 plongest (entry_addr
- section
->buffer
), address_size
);
2755 const uint8_t segment_selector_size
= *addr
++;
2756 if (segment_selector_size
!= 0)
2758 warning (_("Section .debug_aranges in %s entry at offset %s "
2759 "segment_selector_size %u is not supported, "
2760 "ignoring .debug_aranges."),
2761 objfile_name (objfile
),
2762 plongest (entry_addr
- section
->buffer
),
2763 segment_selector_size
);
2767 /* Must pad to an alignment boundary that is twice the address
2768 size. It is undocumented by the DWARF standard but GCC does
2770 for (size_t padding
= ((-(addr
- section
->buffer
))
2771 & (2 * address_size
- 1));
2772 padding
> 0; padding
--)
2775 warning (_("Section .debug_aranges in %s entry at offset %s "
2776 "padding is not zero, ignoring .debug_aranges."),
2777 objfile_name (objfile
),
2778 plongest (entry_addr
- section
->buffer
));
2784 if (addr
+ 2 * address_size
> entry_end
)
2786 warning (_("Section .debug_aranges in %s entry at offset %s "
2787 "address list is not properly terminated, "
2788 "ignoring .debug_aranges."),
2789 objfile_name (objfile
),
2790 plongest (entry_addr
- section
->buffer
));
2793 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2795 addr
+= address_size
;
2796 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2798 addr
+= address_size
;
2799 if (start
== 0 && length
== 0)
2801 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2803 /* Symbol was eliminated due to a COMDAT group. */
2806 ULONGEST end
= start
+ length
;
2807 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2809 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2811 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2815 objfile
->partial_symtabs
->psymtabs_addrmap
2816 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2819 /* Find a slot in the mapped index INDEX for the object named NAME.
2820 If NAME is found, set *VEC_OUT to point to the CU vector in the
2821 constant pool and return true. If NAME cannot be found, return
2825 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2826 offset_type
**vec_out
)
2829 offset_type slot
, step
;
2830 int (*cmp
) (const char *, const char *);
2832 gdb::unique_xmalloc_ptr
<char> without_params
;
2833 if (current_language
->la_language
== language_cplus
2834 || current_language
->la_language
== language_fortran
2835 || current_language
->la_language
== language_d
)
2837 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2840 if (strchr (name
, '(') != NULL
)
2842 without_params
= cp_remove_params (name
);
2844 if (without_params
!= NULL
)
2845 name
= without_params
.get ();
2849 /* Index version 4 did not support case insensitive searches. But the
2850 indices for case insensitive languages are built in lowercase, therefore
2851 simulate our NAME being searched is also lowercased. */
2852 hash
= mapped_index_string_hash ((index
->version
== 4
2853 && case_sensitivity
== case_sensitive_off
2854 ? 5 : index
->version
),
2857 slot
= hash
& (index
->symbol_table
.size () - 1);
2858 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2859 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2865 const auto &bucket
= index
->symbol_table
[slot
];
2866 if (bucket
.name
== 0 && bucket
.vec
== 0)
2869 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2870 if (!cmp (name
, str
))
2872 *vec_out
= (offset_type
*) (index
->constant_pool
2873 + MAYBE_SWAP (bucket
.vec
));
2877 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2881 /* A helper function that reads the .gdb_index from BUFFER and fills
2882 in MAP. FILENAME is the name of the file containing the data;
2883 it is used for error reporting. DEPRECATED_OK is true if it is
2884 ok to use deprecated sections.
2886 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2887 out parameters that are filled in with information about the CU and
2888 TU lists in the section.
2890 Returns true if all went well, false otherwise. */
2893 read_gdb_index_from_buffer (struct objfile
*objfile
,
2894 const char *filename
,
2896 gdb::array_view
<const gdb_byte
> buffer
,
2897 struct mapped_index
*map
,
2898 const gdb_byte
**cu_list
,
2899 offset_type
*cu_list_elements
,
2900 const gdb_byte
**types_list
,
2901 offset_type
*types_list_elements
)
2903 const gdb_byte
*addr
= &buffer
[0];
2905 /* Version check. */
2906 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2907 /* Versions earlier than 3 emitted every copy of a psymbol. This
2908 causes the index to behave very poorly for certain requests. Version 3
2909 contained incomplete addrmap. So, it seems better to just ignore such
2913 static int warning_printed
= 0;
2914 if (!warning_printed
)
2916 warning (_("Skipping obsolete .gdb_index section in %s."),
2918 warning_printed
= 1;
2922 /* Index version 4 uses a different hash function than index version
2925 Versions earlier than 6 did not emit psymbols for inlined
2926 functions. Using these files will cause GDB not to be able to
2927 set breakpoints on inlined functions by name, so we ignore these
2928 indices unless the user has done
2929 "set use-deprecated-index-sections on". */
2930 if (version
< 6 && !deprecated_ok
)
2932 static int warning_printed
= 0;
2933 if (!warning_printed
)
2936 Skipping deprecated .gdb_index section in %s.\n\
2937 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2938 to use the section anyway."),
2940 warning_printed
= 1;
2944 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2945 of the TU (for symbols coming from TUs),
2946 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2947 Plus gold-generated indices can have duplicate entries for global symbols,
2948 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2949 These are just performance bugs, and we can't distinguish gdb-generated
2950 indices from gold-generated ones, so issue no warning here. */
2952 /* Indexes with higher version than the one supported by GDB may be no
2953 longer backward compatible. */
2957 map
->version
= version
;
2959 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2962 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2963 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2967 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2968 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2969 - MAYBE_SWAP (metadata
[i
]))
2973 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2974 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2976 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2979 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2980 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2982 = gdb::array_view
<mapped_index::symbol_table_slot
>
2983 ((mapped_index::symbol_table_slot
*) symbol_table
,
2984 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2987 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2992 /* Callback types for dwarf2_read_gdb_index. */
2994 typedef gdb::function_view
2995 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2996 get_gdb_index_contents_ftype
;
2997 typedef gdb::function_view
2998 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2999 get_gdb_index_contents_dwz_ftype
;
3001 /* Read .gdb_index. If everything went ok, initialize the "quick"
3002 elements of all the CUs and return 1. Otherwise, return 0. */
3005 dwarf2_read_gdb_index
3006 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3007 get_gdb_index_contents_ftype get_gdb_index_contents
,
3008 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3010 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3011 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3012 struct dwz_file
*dwz
;
3013 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3015 gdb::array_view
<const gdb_byte
> main_index_contents
3016 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3018 if (main_index_contents
.empty ())
3021 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3022 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3023 use_deprecated_index_sections
,
3024 main_index_contents
, map
.get (), &cu_list
,
3025 &cu_list_elements
, &types_list
,
3026 &types_list_elements
))
3029 /* Don't use the index if it's empty. */
3030 if (map
->symbol_table
.empty ())
3033 /* If there is a .dwz file, read it so we can get its CU list as
3035 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3038 struct mapped_index dwz_map
;
3039 const gdb_byte
*dwz_types_ignore
;
3040 offset_type dwz_types_elements_ignore
;
3042 gdb::array_view
<const gdb_byte
> dwz_index_content
3043 = get_gdb_index_contents_dwz (objfile
, dwz
);
3045 if (dwz_index_content
.empty ())
3048 if (!read_gdb_index_from_buffer (objfile
,
3049 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3050 1, dwz_index_content
, &dwz_map
,
3051 &dwz_list
, &dwz_list_elements
,
3053 &dwz_types_elements_ignore
))
3055 warning (_("could not read '.gdb_index' section from %s; skipping"),
3056 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3061 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3062 dwz_list
, dwz_list_elements
);
3064 if (types_list_elements
)
3066 /* We can only handle a single .debug_types when we have an
3068 if (dwarf2_per_objfile
->types
.size () != 1)
3071 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3073 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3074 types_list
, types_list_elements
);
3077 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3079 dwarf2_per_objfile
->index_table
= std::move (map
);
3080 dwarf2_per_objfile
->using_index
= 1;
3081 dwarf2_per_objfile
->quick_file_names_table
=
3082 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3087 /* die_reader_func for dw2_get_file_names. */
3090 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3091 const gdb_byte
*info_ptr
,
3092 struct die_info
*comp_unit_die
)
3094 struct dwarf2_cu
*cu
= reader
->cu
;
3095 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3096 struct dwarf2_per_objfile
*dwarf2_per_objfile
3097 = cu
->per_cu
->dwarf2_per_objfile
;
3098 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3099 struct dwarf2_per_cu_data
*lh_cu
;
3100 struct attribute
*attr
;
3102 struct quick_file_names
*qfn
;
3104 gdb_assert (! this_cu
->is_debug_types
);
3106 /* Our callers never want to match partial units -- instead they
3107 will match the enclosing full CU. */
3108 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3110 this_cu
->v
.quick
->no_file_data
= 1;
3118 sect_offset line_offset
{};
3120 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3121 if (attr
!= nullptr)
3123 struct quick_file_names find_entry
;
3125 line_offset
= (sect_offset
) DW_UNSND (attr
);
3127 /* We may have already read in this line header (TU line header sharing).
3128 If we have we're done. */
3129 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3130 find_entry
.hash
.line_sect_off
= line_offset
;
3131 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3132 &find_entry
, INSERT
);
3135 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3139 lh
= dwarf_decode_line_header (line_offset
, cu
);
3143 lh_cu
->v
.quick
->no_file_data
= 1;
3147 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3148 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3149 qfn
->hash
.line_sect_off
= line_offset
;
3150 gdb_assert (slot
!= NULL
);
3153 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3156 if (strcmp (fnd
.name
, "<unknown>") != 0)
3159 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3161 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3163 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3164 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3165 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3166 fnd
.comp_dir
).release ();
3167 qfn
->real_names
= NULL
;
3169 lh_cu
->v
.quick
->file_names
= qfn
;
3172 /* A helper for the "quick" functions which attempts to read the line
3173 table for THIS_CU. */
3175 static struct quick_file_names
*
3176 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3178 /* This should never be called for TUs. */
3179 gdb_assert (! this_cu
->is_debug_types
);
3180 /* Nor type unit groups. */
3181 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3183 if (this_cu
->v
.quick
->file_names
!= NULL
)
3184 return this_cu
->v
.quick
->file_names
;
3185 /* If we know there is no line data, no point in looking again. */
3186 if (this_cu
->v
.quick
->no_file_data
)
3189 cutu_reader
reader (this_cu
);
3190 if (!reader
.dummy_p
)
3191 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3193 if (this_cu
->v
.quick
->no_file_data
)
3195 return this_cu
->v
.quick
->file_names
;
3198 /* A helper for the "quick" functions which computes and caches the
3199 real path for a given file name from the line table. */
3202 dw2_get_real_path (struct objfile
*objfile
,
3203 struct quick_file_names
*qfn
, int index
)
3205 if (qfn
->real_names
== NULL
)
3206 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3207 qfn
->num_file_names
, const char *);
3209 if (qfn
->real_names
[index
] == NULL
)
3210 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3212 return qfn
->real_names
[index
];
3215 static struct symtab
*
3216 dw2_find_last_source_symtab (struct objfile
*objfile
)
3218 struct dwarf2_per_objfile
*dwarf2_per_objfile
3219 = get_dwarf2_per_objfile (objfile
);
3220 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3221 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3226 return compunit_primary_filetab (cust
);
3229 /* Traversal function for dw2_forget_cached_source_info. */
3232 dw2_free_cached_file_names (void **slot
, void *info
)
3234 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3236 if (file_data
->real_names
)
3240 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3242 xfree ((void*) file_data
->real_names
[i
]);
3243 file_data
->real_names
[i
] = NULL
;
3251 dw2_forget_cached_source_info (struct objfile
*objfile
)
3253 struct dwarf2_per_objfile
*dwarf2_per_objfile
3254 = get_dwarf2_per_objfile (objfile
);
3256 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3257 dw2_free_cached_file_names
, NULL
);
3260 /* Helper function for dw2_map_symtabs_matching_filename that expands
3261 the symtabs and calls the iterator. */
3264 dw2_map_expand_apply (struct objfile
*objfile
,
3265 struct dwarf2_per_cu_data
*per_cu
,
3266 const char *name
, const char *real_path
,
3267 gdb::function_view
<bool (symtab
*)> callback
)
3269 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3271 /* Don't visit already-expanded CUs. */
3272 if (per_cu
->v
.quick
->compunit_symtab
)
3275 /* This may expand more than one symtab, and we want to iterate over
3277 dw2_instantiate_symtab (per_cu
, false);
3279 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3280 last_made
, callback
);
3283 /* Implementation of the map_symtabs_matching_filename method. */
3286 dw2_map_symtabs_matching_filename
3287 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3288 gdb::function_view
<bool (symtab
*)> callback
)
3290 const char *name_basename
= lbasename (name
);
3291 struct dwarf2_per_objfile
*dwarf2_per_objfile
3292 = get_dwarf2_per_objfile (objfile
);
3294 /* The rule is CUs specify all the files, including those used by
3295 any TU, so there's no need to scan TUs here. */
3297 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3299 /* We only need to look at symtabs not already expanded. */
3300 if (per_cu
->v
.quick
->compunit_symtab
)
3303 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3304 if (file_data
== NULL
)
3307 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3309 const char *this_name
= file_data
->file_names
[j
];
3310 const char *this_real_name
;
3312 if (compare_filenames_for_search (this_name
, name
))
3314 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3320 /* Before we invoke realpath, which can get expensive when many
3321 files are involved, do a quick comparison of the basenames. */
3322 if (! basenames_may_differ
3323 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3326 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3327 if (compare_filenames_for_search (this_real_name
, name
))
3329 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3335 if (real_path
!= NULL
)
3337 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3338 gdb_assert (IS_ABSOLUTE_PATH (name
));
3339 if (this_real_name
!= NULL
3340 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3342 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3354 /* Struct used to manage iterating over all CUs looking for a symbol. */
3356 struct dw2_symtab_iterator
3358 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3359 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3360 /* If set, only look for symbols that match that block. Valid values are
3361 GLOBAL_BLOCK and STATIC_BLOCK. */
3362 gdb::optional
<block_enum
> block_index
;
3363 /* The kind of symbol we're looking for. */
3365 /* The list of CUs from the index entry of the symbol,
3366 or NULL if not found. */
3368 /* The next element in VEC to look at. */
3370 /* The number of elements in VEC, or zero if there is no match. */
3372 /* Have we seen a global version of the symbol?
3373 If so we can ignore all further global instances.
3374 This is to work around gold/15646, inefficient gold-generated
3379 /* Initialize the index symtab iterator ITER. */
3382 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3383 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3384 gdb::optional
<block_enum
> block_index
,
3388 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3389 iter
->block_index
= block_index
;
3390 iter
->domain
= domain
;
3392 iter
->global_seen
= 0;
3394 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3396 /* index is NULL if OBJF_READNOW. */
3397 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3398 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3406 /* Return the next matching CU or NULL if there are no more. */
3408 static struct dwarf2_per_cu_data
*
3409 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3411 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3413 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3415 offset_type cu_index_and_attrs
=
3416 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3417 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3418 gdb_index_symbol_kind symbol_kind
=
3419 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3420 /* Only check the symbol attributes if they're present.
3421 Indices prior to version 7 don't record them,
3422 and indices >= 7 may elide them for certain symbols
3423 (gold does this). */
3425 (dwarf2_per_objfile
->index_table
->version
>= 7
3426 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3428 /* Don't crash on bad data. */
3429 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3430 + dwarf2_per_objfile
->all_type_units
.size ()))
3432 complaint (_(".gdb_index entry has bad CU index"
3434 objfile_name (dwarf2_per_objfile
->objfile
));
3438 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3440 /* Skip if already read in. */
3441 if (per_cu
->v
.quick
->compunit_symtab
)
3444 /* Check static vs global. */
3447 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3449 if (iter
->block_index
.has_value ())
3451 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3453 if (is_static
!= want_static
)
3457 /* Work around gold/15646. */
3458 if (!is_static
&& iter
->global_seen
)
3461 iter
->global_seen
= 1;
3464 /* Only check the symbol's kind if it has one. */
3467 switch (iter
->domain
)
3470 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3471 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3472 /* Some types are also in VAR_DOMAIN. */
3473 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3477 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3481 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3485 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3500 static struct compunit_symtab
*
3501 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3502 const char *name
, domain_enum domain
)
3504 struct compunit_symtab
*stab_best
= NULL
;
3505 struct dwarf2_per_objfile
*dwarf2_per_objfile
3506 = get_dwarf2_per_objfile (objfile
);
3508 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3510 struct dw2_symtab_iterator iter
;
3511 struct dwarf2_per_cu_data
*per_cu
;
3513 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3515 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3517 struct symbol
*sym
, *with_opaque
= NULL
;
3518 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3519 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3520 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3522 sym
= block_find_symbol (block
, name
, domain
,
3523 block_find_non_opaque_type_preferred
,
3526 /* Some caution must be observed with overloaded functions
3527 and methods, since the index will not contain any overload
3528 information (but NAME might contain it). */
3531 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3533 if (with_opaque
!= NULL
3534 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3537 /* Keep looking through other CUs. */
3544 dw2_print_stats (struct objfile
*objfile
)
3546 struct dwarf2_per_objfile
*dwarf2_per_objfile
3547 = get_dwarf2_per_objfile (objfile
);
3548 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3549 + dwarf2_per_objfile
->all_type_units
.size ());
3552 for (int i
= 0; i
< total
; ++i
)
3554 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3556 if (!per_cu
->v
.quick
->compunit_symtab
)
3559 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3560 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3563 /* This dumps minimal information about the index.
3564 It is called via "mt print objfiles".
3565 One use is to verify .gdb_index has been loaded by the
3566 gdb.dwarf2/gdb-index.exp testcase. */
3569 dw2_dump (struct objfile
*objfile
)
3571 struct dwarf2_per_objfile
*dwarf2_per_objfile
3572 = get_dwarf2_per_objfile (objfile
);
3574 gdb_assert (dwarf2_per_objfile
->using_index
);
3575 printf_filtered (".gdb_index:");
3576 if (dwarf2_per_objfile
->index_table
!= NULL
)
3578 printf_filtered (" version %d\n",
3579 dwarf2_per_objfile
->index_table
->version
);
3582 printf_filtered (" faked for \"readnow\"\n");
3583 printf_filtered ("\n");
3587 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3588 const char *func_name
)
3590 struct dwarf2_per_objfile
*dwarf2_per_objfile
3591 = get_dwarf2_per_objfile (objfile
);
3593 struct dw2_symtab_iterator iter
;
3594 struct dwarf2_per_cu_data
*per_cu
;
3596 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3598 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3599 dw2_instantiate_symtab (per_cu
, false);
3604 dw2_expand_all_symtabs (struct objfile
*objfile
)
3606 struct dwarf2_per_objfile
*dwarf2_per_objfile
3607 = get_dwarf2_per_objfile (objfile
);
3608 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3609 + dwarf2_per_objfile
->all_type_units
.size ());
3611 for (int i
= 0; i
< total_units
; ++i
)
3613 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3615 /* We don't want to directly expand a partial CU, because if we
3616 read it with the wrong language, then assertion failures can
3617 be triggered later on. See PR symtab/23010. So, tell
3618 dw2_instantiate_symtab to skip partial CUs -- any important
3619 partial CU will be read via DW_TAG_imported_unit anyway. */
3620 dw2_instantiate_symtab (per_cu
, true);
3625 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3626 const char *fullname
)
3628 struct dwarf2_per_objfile
*dwarf2_per_objfile
3629 = get_dwarf2_per_objfile (objfile
);
3631 /* We don't need to consider type units here.
3632 This is only called for examining code, e.g. expand_line_sal.
3633 There can be an order of magnitude (or more) more type units
3634 than comp units, and we avoid them if we can. */
3636 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3638 /* We only need to look at symtabs not already expanded. */
3639 if (per_cu
->v
.quick
->compunit_symtab
)
3642 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3643 if (file_data
== NULL
)
3646 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3648 const char *this_fullname
= file_data
->file_names
[j
];
3650 if (filename_cmp (this_fullname
, fullname
) == 0)
3652 dw2_instantiate_symtab (per_cu
, false);
3660 dw2_map_matching_symbols
3661 (struct objfile
*objfile
,
3662 const lookup_name_info
&name
, domain_enum domain
,
3664 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3665 symbol_compare_ftype
*ordered_compare
)
3667 /* Currently unimplemented; used for Ada. The function can be called if the
3668 current language is Ada for a non-Ada objfile using GNU index. As Ada
3669 does not look for non-Ada symbols this function should just return. */
3672 /* Starting from a search name, return the string that finds the upper
3673 bound of all strings that start with SEARCH_NAME in a sorted name
3674 list. Returns the empty string to indicate that the upper bound is
3675 the end of the list. */
3678 make_sort_after_prefix_name (const char *search_name
)
3680 /* When looking to complete "func", we find the upper bound of all
3681 symbols that start with "func" by looking for where we'd insert
3682 the closest string that would follow "func" in lexicographical
3683 order. Usually, that's "func"-with-last-character-incremented,
3684 i.e. "fund". Mind non-ASCII characters, though. Usually those
3685 will be UTF-8 multi-byte sequences, but we can't be certain.
3686 Especially mind the 0xff character, which is a valid character in
3687 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3688 rule out compilers allowing it in identifiers. Note that
3689 conveniently, strcmp/strcasecmp are specified to compare
3690 characters interpreted as unsigned char. So what we do is treat
3691 the whole string as a base 256 number composed of a sequence of
3692 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3693 to 0, and carries 1 to the following more-significant position.
3694 If the very first character in SEARCH_NAME ends up incremented
3695 and carries/overflows, then the upper bound is the end of the
3696 list. The string after the empty string is also the empty
3699 Some examples of this operation:
3701 SEARCH_NAME => "+1" RESULT
3705 "\xff" "a" "\xff" => "\xff" "b"
3710 Then, with these symbols for example:
3716 completing "func" looks for symbols between "func" and
3717 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3718 which finds "func" and "func1", but not "fund".
3722 funcÿ (Latin1 'ÿ' [0xff])
3726 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3727 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3731 ÿÿ (Latin1 'ÿ' [0xff])
3734 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3735 the end of the list.
3737 std::string after
= search_name
;
3738 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3740 if (!after
.empty ())
3741 after
.back () = (unsigned char) after
.back () + 1;
3745 /* See declaration. */
3747 std::pair
<std::vector
<name_component
>::const_iterator
,
3748 std::vector
<name_component
>::const_iterator
>
3749 mapped_index_base::find_name_components_bounds
3750 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3753 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3755 const char *lang_name
3756 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3758 /* Comparison function object for lower_bound that matches against a
3759 given symbol name. */
3760 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3763 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3764 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3765 return name_cmp (elem_name
, name
) < 0;
3768 /* Comparison function object for upper_bound that matches against a
3769 given symbol name. */
3770 auto lookup_compare_upper
= [&] (const char *name
,
3771 const name_component
&elem
)
3773 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3774 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3775 return name_cmp (name
, elem_name
) < 0;
3778 auto begin
= this->name_components
.begin ();
3779 auto end
= this->name_components
.end ();
3781 /* Find the lower bound. */
3784 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3787 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3790 /* Find the upper bound. */
3793 if (lookup_name_without_params
.completion_mode ())
3795 /* In completion mode, we want UPPER to point past all
3796 symbols names that have the same prefix. I.e., with
3797 these symbols, and completing "func":
3799 function << lower bound
3801 other_function << upper bound
3803 We find the upper bound by looking for the insertion
3804 point of "func"-with-last-character-incremented,
3806 std::string after
= make_sort_after_prefix_name (lang_name
);
3809 return std::lower_bound (lower
, end
, after
.c_str (),
3810 lookup_compare_lower
);
3813 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3816 return {lower
, upper
};
3819 /* See declaration. */
3822 mapped_index_base::build_name_components ()
3824 if (!this->name_components
.empty ())
3827 this->name_components_casing
= case_sensitivity
;
3829 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3831 /* The code below only knows how to break apart components of C++
3832 symbol names (and other languages that use '::' as
3833 namespace/module separator) and Ada symbol names. */
3834 auto count
= this->symbol_name_count ();
3835 for (offset_type idx
= 0; idx
< count
; idx
++)
3837 if (this->symbol_name_slot_invalid (idx
))
3840 const char *name
= this->symbol_name_at (idx
);
3842 /* Add each name component to the name component table. */
3843 unsigned int previous_len
= 0;
3845 if (strstr (name
, "::") != nullptr)
3847 for (unsigned int current_len
= cp_find_first_component (name
);
3848 name
[current_len
] != '\0';
3849 current_len
+= cp_find_first_component (name
+ current_len
))
3851 gdb_assert (name
[current_len
] == ':');
3852 this->name_components
.push_back ({previous_len
, idx
});
3853 /* Skip the '::'. */
3855 previous_len
= current_len
;
3860 /* Handle the Ada encoded (aka mangled) form here. */
3861 for (const char *iter
= strstr (name
, "__");
3863 iter
= strstr (iter
, "__"))
3865 this->name_components
.push_back ({previous_len
, idx
});
3867 previous_len
= iter
- name
;
3871 this->name_components
.push_back ({previous_len
, idx
});
3874 /* Sort name_components elements by name. */
3875 auto name_comp_compare
= [&] (const name_component
&left
,
3876 const name_component
&right
)
3878 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3879 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3881 const char *left_name
= left_qualified
+ left
.name_offset
;
3882 const char *right_name
= right_qualified
+ right
.name_offset
;
3884 return name_cmp (left_name
, right_name
) < 0;
3887 std::sort (this->name_components
.begin (),
3888 this->name_components
.end (),
3892 /* Helper for dw2_expand_symtabs_matching that works with a
3893 mapped_index_base instead of the containing objfile. This is split
3894 to a separate function in order to be able to unit test the
3895 name_components matching using a mock mapped_index_base. For each
3896 symbol name that matches, calls MATCH_CALLBACK, passing it the
3897 symbol's index in the mapped_index_base symbol table. */
3900 dw2_expand_symtabs_matching_symbol
3901 (mapped_index_base
&index
,
3902 const lookup_name_info
&lookup_name_in
,
3903 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3904 enum search_domain kind
,
3905 gdb::function_view
<bool (offset_type
)> match_callback
)
3907 lookup_name_info lookup_name_without_params
3908 = lookup_name_in
.make_ignore_params ();
3910 /* Build the symbol name component sorted vector, if we haven't
3912 index
.build_name_components ();
3914 /* The same symbol may appear more than once in the range though.
3915 E.g., if we're looking for symbols that complete "w", and we have
3916 a symbol named "w1::w2", we'll find the two name components for
3917 that same symbol in the range. To be sure we only call the
3918 callback once per symbol, we first collect the symbol name
3919 indexes that matched in a temporary vector and ignore
3921 std::vector
<offset_type
> matches
;
3923 struct name_and_matcher
3925 symbol_name_matcher_ftype
*matcher
;
3926 const std::string
&name
;
3928 bool operator== (const name_and_matcher
&other
) const
3930 return matcher
== other
.matcher
&& name
== other
.name
;
3934 /* A vector holding all the different symbol name matchers, for all
3936 std::vector
<name_and_matcher
> matchers
;
3938 for (int i
= 0; i
< nr_languages
; i
++)
3940 enum language lang_e
= (enum language
) i
;
3942 const language_defn
*lang
= language_def (lang_e
);
3943 symbol_name_matcher_ftype
*name_matcher
3944 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3946 name_and_matcher key
{
3948 lookup_name_without_params
.language_lookup_name (lang_e
)
3951 /* Don't insert the same comparison routine more than once.
3952 Note that we do this linear walk. This is not a problem in
3953 practice because the number of supported languages is
3955 if (std::find (matchers
.begin (), matchers
.end (), key
)
3958 matchers
.push_back (std::move (key
));
3961 = index
.find_name_components_bounds (lookup_name_without_params
,
3964 /* Now for each symbol name in range, check to see if we have a name
3965 match, and if so, call the MATCH_CALLBACK callback. */
3967 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3969 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3971 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3972 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3975 matches
.push_back (bounds
.first
->idx
);
3979 std::sort (matches
.begin (), matches
.end ());
3981 /* Finally call the callback, once per match. */
3983 for (offset_type idx
: matches
)
3987 if (!match_callback (idx
))
3993 /* Above we use a type wider than idx's for 'prev', since 0 and
3994 (offset_type)-1 are both possible values. */
3995 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4000 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4002 /* A mock .gdb_index/.debug_names-like name index table, enough to
4003 exercise dw2_expand_symtabs_matching_symbol, which works with the
4004 mapped_index_base interface. Builds an index from the symbol list
4005 passed as parameter to the constructor. */
4006 class mock_mapped_index
: public mapped_index_base
4009 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4010 : m_symbol_table (symbols
)
4013 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4015 /* Return the number of names in the symbol table. */
4016 size_t symbol_name_count () const override
4018 return m_symbol_table
.size ();
4021 /* Get the name of the symbol at IDX in the symbol table. */
4022 const char *symbol_name_at (offset_type idx
) const override
4024 return m_symbol_table
[idx
];
4028 gdb::array_view
<const char *> m_symbol_table
;
4031 /* Convenience function that converts a NULL pointer to a "<null>"
4032 string, to pass to print routines. */
4035 string_or_null (const char *str
)
4037 return str
!= NULL
? str
: "<null>";
4040 /* Check if a lookup_name_info built from
4041 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4042 index. EXPECTED_LIST is the list of expected matches, in expected
4043 matching order. If no match expected, then an empty list is
4044 specified. Returns true on success. On failure prints a warning
4045 indicating the file:line that failed, and returns false. */
4048 check_match (const char *file
, int line
,
4049 mock_mapped_index
&mock_index
,
4050 const char *name
, symbol_name_match_type match_type
,
4051 bool completion_mode
,
4052 std::initializer_list
<const char *> expected_list
)
4054 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4056 bool matched
= true;
4058 auto mismatch
= [&] (const char *expected_str
,
4061 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4062 "expected=\"%s\", got=\"%s\"\n"),
4064 (match_type
== symbol_name_match_type::FULL
4066 name
, string_or_null (expected_str
), string_or_null (got
));
4070 auto expected_it
= expected_list
.begin ();
4071 auto expected_end
= expected_list
.end ();
4073 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4075 [&] (offset_type idx
)
4077 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4078 const char *expected_str
4079 = expected_it
== expected_end
? NULL
: *expected_it
++;
4081 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4082 mismatch (expected_str
, matched_name
);
4086 const char *expected_str
4087 = expected_it
== expected_end
? NULL
: *expected_it
++;
4088 if (expected_str
!= NULL
)
4089 mismatch (expected_str
, NULL
);
4094 /* The symbols added to the mock mapped_index for testing (in
4096 static const char *test_symbols
[] = {
4105 "ns2::tmpl<int>::foo2",
4106 "(anonymous namespace)::A::B::C",
4108 /* These are used to check that the increment-last-char in the
4109 matching algorithm for completion doesn't match "t1_fund" when
4110 completing "t1_func". */
4116 /* A UTF-8 name with multi-byte sequences to make sure that
4117 cp-name-parser understands this as a single identifier ("função"
4118 is "function" in PT). */
4121 /* \377 (0xff) is Latin1 'ÿ'. */
4124 /* \377 (0xff) is Latin1 'ÿ'. */
4128 /* A name with all sorts of complications. Starts with "z" to make
4129 it easier for the completion tests below. */
4130 #define Z_SYM_NAME \
4131 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4132 "::tuple<(anonymous namespace)::ui*, " \
4133 "std::default_delete<(anonymous namespace)::ui>, void>"
4138 /* Returns true if the mapped_index_base::find_name_component_bounds
4139 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4140 in completion mode. */
4143 check_find_bounds_finds (mapped_index_base
&index
,
4144 const char *search_name
,
4145 gdb::array_view
<const char *> expected_syms
)
4147 lookup_name_info
lookup_name (search_name
,
4148 symbol_name_match_type::FULL
, true);
4150 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4153 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4154 if (distance
!= expected_syms
.size ())
4157 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4159 auto nc_elem
= bounds
.first
+ exp_elem
;
4160 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4161 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4168 /* Test the lower-level mapped_index::find_name_component_bounds
4172 test_mapped_index_find_name_component_bounds ()
4174 mock_mapped_index
mock_index (test_symbols
);
4176 mock_index
.build_name_components ();
4178 /* Test the lower-level mapped_index::find_name_component_bounds
4179 method in completion mode. */
4181 static const char *expected_syms
[] = {
4186 SELF_CHECK (check_find_bounds_finds (mock_index
,
4187 "t1_func", expected_syms
));
4190 /* Check that the increment-last-char in the name matching algorithm
4191 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4193 static const char *expected_syms1
[] = {
4197 SELF_CHECK (check_find_bounds_finds (mock_index
,
4198 "\377", expected_syms1
));
4200 static const char *expected_syms2
[] = {
4203 SELF_CHECK (check_find_bounds_finds (mock_index
,
4204 "\377\377", expected_syms2
));
4208 /* Test dw2_expand_symtabs_matching_symbol. */
4211 test_dw2_expand_symtabs_matching_symbol ()
4213 mock_mapped_index
mock_index (test_symbols
);
4215 /* We let all tests run until the end even if some fails, for debug
4217 bool any_mismatch
= false;
4219 /* Create the expected symbols list (an initializer_list). Needed
4220 because lists have commas, and we need to pass them to CHECK,
4221 which is a macro. */
4222 #define EXPECT(...) { __VA_ARGS__ }
4224 /* Wrapper for check_match that passes down the current
4225 __FILE__/__LINE__. */
4226 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4227 any_mismatch |= !check_match (__FILE__, __LINE__, \
4229 NAME, MATCH_TYPE, COMPLETION_MODE, \
4232 /* Identity checks. */
4233 for (const char *sym
: test_symbols
)
4235 /* Should be able to match all existing symbols. */
4236 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4239 /* Should be able to match all existing symbols with
4241 std::string with_params
= std::string (sym
) + "(int)";
4242 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4245 /* Should be able to match all existing symbols with
4246 parameters and qualifiers. */
4247 with_params
= std::string (sym
) + " ( int ) const";
4248 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4251 /* This should really find sym, but cp-name-parser.y doesn't
4252 know about lvalue/rvalue qualifiers yet. */
4253 with_params
= std::string (sym
) + " ( int ) &&";
4254 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4258 /* Check that the name matching algorithm for completion doesn't get
4259 confused with Latin1 'ÿ' / 0xff. */
4261 static const char str
[] = "\377";
4262 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4263 EXPECT ("\377", "\377\377123"));
4266 /* Check that the increment-last-char in the matching algorithm for
4267 completion doesn't match "t1_fund" when completing "t1_func". */
4269 static const char str
[] = "t1_func";
4270 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4271 EXPECT ("t1_func", "t1_func1"));
4274 /* Check that completion mode works at each prefix of the expected
4277 static const char str
[] = "function(int)";
4278 size_t len
= strlen (str
);
4281 for (size_t i
= 1; i
< len
; i
++)
4283 lookup
.assign (str
, i
);
4284 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4285 EXPECT ("function"));
4289 /* While "w" is a prefix of both components, the match function
4290 should still only be called once. */
4292 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4294 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4298 /* Same, with a "complicated" symbol. */
4300 static const char str
[] = Z_SYM_NAME
;
4301 size_t len
= strlen (str
);
4304 for (size_t i
= 1; i
< len
; i
++)
4306 lookup
.assign (str
, i
);
4307 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4308 EXPECT (Z_SYM_NAME
));
4312 /* In FULL mode, an incomplete symbol doesn't match. */
4314 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4318 /* A complete symbol with parameters matches any overload, since the
4319 index has no overload info. */
4321 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4322 EXPECT ("std::zfunction", "std::zfunction2"));
4323 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4324 EXPECT ("std::zfunction", "std::zfunction2"));
4325 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4326 EXPECT ("std::zfunction", "std::zfunction2"));
4329 /* Check that whitespace is ignored appropriately. A symbol with a
4330 template argument list. */
4332 static const char expected
[] = "ns::foo<int>";
4333 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4335 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4339 /* Check that whitespace is ignored appropriately. A symbol with a
4340 template argument list that includes a pointer. */
4342 static const char expected
[] = "ns::foo<char*>";
4343 /* Try both completion and non-completion modes. */
4344 static const bool completion_mode
[2] = {false, true};
4345 for (size_t i
= 0; i
< 2; i
++)
4347 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4348 completion_mode
[i
], EXPECT (expected
));
4349 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4350 completion_mode
[i
], EXPECT (expected
));
4352 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4353 completion_mode
[i
], EXPECT (expected
));
4354 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4355 completion_mode
[i
], EXPECT (expected
));
4360 /* Check method qualifiers are ignored. */
4361 static const char expected
[] = "ns::foo<char*>";
4362 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4363 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4364 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4365 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4366 CHECK_MATCH ("foo < char * > ( int ) const",
4367 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4368 CHECK_MATCH ("foo < char * > ( int ) &&",
4369 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4372 /* Test lookup names that don't match anything. */
4374 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4377 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4381 /* Some wild matching tests, exercising "(anonymous namespace)",
4382 which should not be confused with a parameter list. */
4384 static const char *syms
[] = {
4388 "A :: B :: C ( int )",
4393 for (const char *s
: syms
)
4395 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4396 EXPECT ("(anonymous namespace)::A::B::C"));
4401 static const char expected
[] = "ns2::tmpl<int>::foo2";
4402 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4404 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4408 SELF_CHECK (!any_mismatch
);
4417 test_mapped_index_find_name_component_bounds ();
4418 test_dw2_expand_symtabs_matching_symbol ();
4421 }} // namespace selftests::dw2_expand_symtabs_matching
4423 #endif /* GDB_SELF_TEST */
4425 /* If FILE_MATCHER is NULL or if PER_CU has
4426 dwarf2_per_cu_quick_data::MARK set (see
4427 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4428 EXPANSION_NOTIFY on it. */
4431 dw2_expand_symtabs_matching_one
4432 (struct dwarf2_per_cu_data
*per_cu
,
4433 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4434 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4436 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4438 bool symtab_was_null
4439 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4441 dw2_instantiate_symtab (per_cu
, false);
4443 if (expansion_notify
!= NULL
4445 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4446 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4450 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4451 matched, to expand corresponding CUs that were marked. IDX is the
4452 index of the symbol name that matched. */
4455 dw2_expand_marked_cus
4456 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4457 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4458 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4461 offset_type
*vec
, vec_len
, vec_idx
;
4462 bool global_seen
= false;
4463 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4465 vec
= (offset_type
*) (index
.constant_pool
4466 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4467 vec_len
= MAYBE_SWAP (vec
[0]);
4468 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4470 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4471 /* This value is only valid for index versions >= 7. */
4472 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4473 gdb_index_symbol_kind symbol_kind
=
4474 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4475 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4476 /* Only check the symbol attributes if they're present.
4477 Indices prior to version 7 don't record them,
4478 and indices >= 7 may elide them for certain symbols
4479 (gold does this). */
4482 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4484 /* Work around gold/15646. */
4487 if (!is_static
&& global_seen
)
4493 /* Only check the symbol's kind if it has one. */
4498 case VARIABLES_DOMAIN
:
4499 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4502 case FUNCTIONS_DOMAIN
:
4503 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4507 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4510 case MODULES_DOMAIN
:
4511 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4519 /* Don't crash on bad data. */
4520 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4521 + dwarf2_per_objfile
->all_type_units
.size ()))
4523 complaint (_(".gdb_index entry has bad CU index"
4525 objfile_name (dwarf2_per_objfile
->objfile
));
4529 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4530 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4535 /* If FILE_MATCHER is non-NULL, set all the
4536 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4537 that match FILE_MATCHER. */
4540 dw_expand_symtabs_matching_file_matcher
4541 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4542 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4544 if (file_matcher
== NULL
)
4547 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4549 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4551 NULL
, xcalloc
, xfree
));
4552 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4554 NULL
, xcalloc
, xfree
));
4556 /* The rule is CUs specify all the files, including those used by
4557 any TU, so there's no need to scan TUs here. */
4559 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4563 per_cu
->v
.quick
->mark
= 0;
4565 /* We only need to look at symtabs not already expanded. */
4566 if (per_cu
->v
.quick
->compunit_symtab
)
4569 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4570 if (file_data
== NULL
)
4573 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4575 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4577 per_cu
->v
.quick
->mark
= 1;
4581 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4583 const char *this_real_name
;
4585 if (file_matcher (file_data
->file_names
[j
], false))
4587 per_cu
->v
.quick
->mark
= 1;
4591 /* Before we invoke realpath, which can get expensive when many
4592 files are involved, do a quick comparison of the basenames. */
4593 if (!basenames_may_differ
4594 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4598 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4599 if (file_matcher (this_real_name
, false))
4601 per_cu
->v
.quick
->mark
= 1;
4606 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4607 ? visited_found
.get ()
4608 : visited_not_found
.get (),
4615 dw2_expand_symtabs_matching
4616 (struct objfile
*objfile
,
4617 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4618 const lookup_name_info
&lookup_name
,
4619 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4620 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4621 enum search_domain kind
)
4623 struct dwarf2_per_objfile
*dwarf2_per_objfile
4624 = get_dwarf2_per_objfile (objfile
);
4626 /* index_table is NULL if OBJF_READNOW. */
4627 if (!dwarf2_per_objfile
->index_table
)
4630 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4632 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4634 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4636 kind
, [&] (offset_type idx
)
4638 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4639 expansion_notify
, kind
);
4644 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4647 static struct compunit_symtab
*
4648 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4653 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4654 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4657 if (cust
->includes
== NULL
)
4660 for (i
= 0; cust
->includes
[i
]; ++i
)
4662 struct compunit_symtab
*s
= cust
->includes
[i
];
4664 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4672 static struct compunit_symtab
*
4673 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4674 struct bound_minimal_symbol msymbol
,
4676 struct obj_section
*section
,
4679 struct dwarf2_per_cu_data
*data
;
4680 struct compunit_symtab
*result
;
4682 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4685 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4686 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4687 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4691 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4692 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4693 paddress (get_objfile_arch (objfile
), pc
));
4696 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4699 gdb_assert (result
!= NULL
);
4704 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4705 void *data
, int need_fullname
)
4707 struct dwarf2_per_objfile
*dwarf2_per_objfile
4708 = get_dwarf2_per_objfile (objfile
);
4710 if (!dwarf2_per_objfile
->filenames_cache
)
4712 dwarf2_per_objfile
->filenames_cache
.emplace ();
4714 htab_up
visited (htab_create_alloc (10,
4715 htab_hash_pointer
, htab_eq_pointer
,
4716 NULL
, xcalloc
, xfree
));
4718 /* The rule is CUs specify all the files, including those used
4719 by any TU, so there's no need to scan TUs here. We can
4720 ignore file names coming from already-expanded CUs. */
4722 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4724 if (per_cu
->v
.quick
->compunit_symtab
)
4726 void **slot
= htab_find_slot (visited
.get (),
4727 per_cu
->v
.quick
->file_names
,
4730 *slot
= per_cu
->v
.quick
->file_names
;
4734 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4736 /* We only need to look at symtabs not already expanded. */
4737 if (per_cu
->v
.quick
->compunit_symtab
)
4740 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4741 if (file_data
== NULL
)
4744 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4747 /* Already visited. */
4752 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4754 const char *filename
= file_data
->file_names
[j
];
4755 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4760 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4762 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4765 this_real_name
= gdb_realpath (filename
);
4766 (*fun
) (filename
, this_real_name
.get (), data
);
4771 dw2_has_symbols (struct objfile
*objfile
)
4776 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4779 dw2_find_last_source_symtab
,
4780 dw2_forget_cached_source_info
,
4781 dw2_map_symtabs_matching_filename
,
4785 dw2_expand_symtabs_for_function
,
4786 dw2_expand_all_symtabs
,
4787 dw2_expand_symtabs_with_fullname
,
4788 dw2_map_matching_symbols
,
4789 dw2_expand_symtabs_matching
,
4790 dw2_find_pc_sect_compunit_symtab
,
4792 dw2_map_symbol_filenames
4795 /* DWARF-5 debug_names reader. */
4797 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4798 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4800 /* A helper function that reads the .debug_names section in SECTION
4801 and fills in MAP. FILENAME is the name of the file containing the
4802 section; it is used for error reporting.
4804 Returns true if all went well, false otherwise. */
4807 read_debug_names_from_section (struct objfile
*objfile
,
4808 const char *filename
,
4809 struct dwarf2_section_info
*section
,
4810 mapped_debug_names
&map
)
4812 if (section
->empty ())
4815 /* Older elfutils strip versions could keep the section in the main
4816 executable while splitting it for the separate debug info file. */
4817 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4820 section
->read (objfile
);
4822 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4824 const gdb_byte
*addr
= section
->buffer
;
4826 bfd
*const abfd
= section
->get_bfd_owner ();
4828 unsigned int bytes_read
;
4829 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4832 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4833 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4834 if (bytes_read
+ length
!= section
->size
)
4836 /* There may be multiple per-CU indices. */
4837 warning (_("Section .debug_names in %s length %s does not match "
4838 "section length %s, ignoring .debug_names."),
4839 filename
, plongest (bytes_read
+ length
),
4840 pulongest (section
->size
));
4844 /* The version number. */
4845 uint16_t version
= read_2_bytes (abfd
, addr
);
4849 warning (_("Section .debug_names in %s has unsupported version %d, "
4850 "ignoring .debug_names."),
4856 uint16_t padding
= read_2_bytes (abfd
, addr
);
4860 warning (_("Section .debug_names in %s has unsupported padding %d, "
4861 "ignoring .debug_names."),
4866 /* comp_unit_count - The number of CUs in the CU list. */
4867 map
.cu_count
= read_4_bytes (abfd
, addr
);
4870 /* local_type_unit_count - The number of TUs in the local TU
4872 map
.tu_count
= read_4_bytes (abfd
, addr
);
4875 /* foreign_type_unit_count - The number of TUs in the foreign TU
4877 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4879 if (foreign_tu_count
!= 0)
4881 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4882 "ignoring .debug_names."),
4883 filename
, static_cast<unsigned long> (foreign_tu_count
));
4887 /* bucket_count - The number of hash buckets in the hash lookup
4889 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4892 /* name_count - The number of unique names in the index. */
4893 map
.name_count
= read_4_bytes (abfd
, addr
);
4896 /* abbrev_table_size - The size in bytes of the abbreviations
4898 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4901 /* augmentation_string_size - The size in bytes of the augmentation
4902 string. This value is rounded up to a multiple of 4. */
4903 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4905 map
.augmentation_is_gdb
= ((augmentation_string_size
4906 == sizeof (dwarf5_augmentation
))
4907 && memcmp (addr
, dwarf5_augmentation
,
4908 sizeof (dwarf5_augmentation
)) == 0);
4909 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4910 addr
+= augmentation_string_size
;
4913 map
.cu_table_reordered
= addr
;
4914 addr
+= map
.cu_count
* map
.offset_size
;
4916 /* List of Local TUs */
4917 map
.tu_table_reordered
= addr
;
4918 addr
+= map
.tu_count
* map
.offset_size
;
4920 /* Hash Lookup Table */
4921 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4922 addr
+= map
.bucket_count
* 4;
4923 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4924 addr
+= map
.name_count
* 4;
4927 map
.name_table_string_offs_reordered
= addr
;
4928 addr
+= map
.name_count
* map
.offset_size
;
4929 map
.name_table_entry_offs_reordered
= addr
;
4930 addr
+= map
.name_count
* map
.offset_size
;
4932 const gdb_byte
*abbrev_table_start
= addr
;
4935 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4940 const auto insertpair
4941 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4942 if (!insertpair
.second
)
4944 warning (_("Section .debug_names in %s has duplicate index %s, "
4945 "ignoring .debug_names."),
4946 filename
, pulongest (index_num
));
4949 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4950 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4955 mapped_debug_names::index_val::attr attr
;
4956 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4958 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4960 if (attr
.form
== DW_FORM_implicit_const
)
4962 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4966 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4968 indexval
.attr_vec
.push_back (std::move (attr
));
4971 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4973 warning (_("Section .debug_names in %s has abbreviation_table "
4974 "of size %s vs. written as %u, ignoring .debug_names."),
4975 filename
, plongest (addr
- abbrev_table_start
),
4979 map
.entry_pool
= addr
;
4984 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4988 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4989 const mapped_debug_names
&map
,
4990 dwarf2_section_info
§ion
,
4993 sect_offset sect_off_prev
;
4994 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4996 sect_offset sect_off_next
;
4997 if (i
< map
.cu_count
)
5000 = (sect_offset
) (extract_unsigned_integer
5001 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5003 map
.dwarf5_byte_order
));
5006 sect_off_next
= (sect_offset
) section
.size
;
5009 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5010 dwarf2_per_cu_data
*per_cu
5011 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5012 sect_off_prev
, length
);
5013 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5015 sect_off_prev
= sect_off_next
;
5019 /* Read the CU list from the mapped index, and use it to create all
5020 the CU objects for this dwarf2_per_objfile. */
5023 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5024 const mapped_debug_names
&map
,
5025 const mapped_debug_names
&dwz_map
)
5027 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5028 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5030 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5031 dwarf2_per_objfile
->info
,
5032 false /* is_dwz */);
5034 if (dwz_map
.cu_count
== 0)
5037 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5038 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5042 /* Read .debug_names. If everything went ok, initialize the "quick"
5043 elements of all the CUs and return true. Otherwise, return false. */
5046 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5048 std::unique_ptr
<mapped_debug_names
> map
5049 (new mapped_debug_names (dwarf2_per_objfile
));
5050 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5051 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5053 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5054 &dwarf2_per_objfile
->debug_names
,
5058 /* Don't use the index if it's empty. */
5059 if (map
->name_count
== 0)
5062 /* If there is a .dwz file, read it so we can get its CU list as
5064 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5067 if (!read_debug_names_from_section (objfile
,
5068 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5069 &dwz
->debug_names
, dwz_map
))
5071 warning (_("could not read '.debug_names' section from %s; skipping"),
5072 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5077 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5079 if (map
->tu_count
!= 0)
5081 /* We can only handle a single .debug_types when we have an
5083 if (dwarf2_per_objfile
->types
.size () != 1)
5086 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5088 create_signatured_type_table_from_debug_names
5089 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5092 create_addrmap_from_aranges (dwarf2_per_objfile
,
5093 &dwarf2_per_objfile
->debug_aranges
);
5095 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5096 dwarf2_per_objfile
->using_index
= 1;
5097 dwarf2_per_objfile
->quick_file_names_table
=
5098 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5103 /* Type used to manage iterating over all CUs looking for a symbol for
5106 class dw2_debug_names_iterator
5109 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5110 gdb::optional
<block_enum
> block_index
,
5113 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5114 m_addr (find_vec_in_debug_names (map
, name
))
5117 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5118 search_domain search
, uint32_t namei
)
5121 m_addr (find_vec_in_debug_names (map
, namei
))
5124 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5125 block_enum block_index
, domain_enum domain
,
5127 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5128 m_addr (find_vec_in_debug_names (map
, namei
))
5131 /* Return the next matching CU or NULL if there are no more. */
5132 dwarf2_per_cu_data
*next ();
5135 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5137 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5140 /* The internalized form of .debug_names. */
5141 const mapped_debug_names
&m_map
;
5143 /* If set, only look for symbols that match that block. Valid values are
5144 GLOBAL_BLOCK and STATIC_BLOCK. */
5145 const gdb::optional
<block_enum
> m_block_index
;
5147 /* The kind of symbol we're looking for. */
5148 const domain_enum m_domain
= UNDEF_DOMAIN
;
5149 const search_domain m_search
= ALL_DOMAIN
;
5151 /* The list of CUs from the index entry of the symbol, or NULL if
5153 const gdb_byte
*m_addr
;
5157 mapped_debug_names::namei_to_name (uint32_t namei
) const
5159 const ULONGEST namei_string_offs
5160 = extract_unsigned_integer ((name_table_string_offs_reordered
5161 + namei
* offset_size
),
5164 return read_indirect_string_at_offset
5165 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5168 /* Find a slot in .debug_names for the object named NAME. If NAME is
5169 found, return pointer to its pool data. If NAME cannot be found,
5173 dw2_debug_names_iterator::find_vec_in_debug_names
5174 (const mapped_debug_names
&map
, const char *name
)
5176 int (*cmp
) (const char *, const char *);
5178 gdb::unique_xmalloc_ptr
<char> without_params
;
5179 if (current_language
->la_language
== language_cplus
5180 || current_language
->la_language
== language_fortran
5181 || current_language
->la_language
== language_d
)
5183 /* NAME is already canonical. Drop any qualifiers as
5184 .debug_names does not contain any. */
5186 if (strchr (name
, '(') != NULL
)
5188 without_params
= cp_remove_params (name
);
5189 if (without_params
!= NULL
)
5190 name
= without_params
.get ();
5194 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5196 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5198 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5199 (map
.bucket_table_reordered
5200 + (full_hash
% map
.bucket_count
)), 4,
5201 map
.dwarf5_byte_order
);
5205 if (namei
>= map
.name_count
)
5207 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5209 namei
, map
.name_count
,
5210 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5216 const uint32_t namei_full_hash
5217 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5218 (map
.hash_table_reordered
+ namei
), 4,
5219 map
.dwarf5_byte_order
);
5220 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5223 if (full_hash
== namei_full_hash
)
5225 const char *const namei_string
= map
.namei_to_name (namei
);
5227 #if 0 /* An expensive sanity check. */
5228 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5230 complaint (_("Wrong .debug_names hash for string at index %u "
5232 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5237 if (cmp (namei_string
, name
) == 0)
5239 const ULONGEST namei_entry_offs
5240 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5241 + namei
* map
.offset_size
),
5242 map
.offset_size
, map
.dwarf5_byte_order
);
5243 return map
.entry_pool
+ namei_entry_offs
;
5248 if (namei
>= map
.name_count
)
5254 dw2_debug_names_iterator::find_vec_in_debug_names
5255 (const mapped_debug_names
&map
, uint32_t namei
)
5257 if (namei
>= map
.name_count
)
5259 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5261 namei
, map
.name_count
,
5262 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5266 const ULONGEST namei_entry_offs
5267 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5268 + namei
* map
.offset_size
),
5269 map
.offset_size
, map
.dwarf5_byte_order
);
5270 return map
.entry_pool
+ namei_entry_offs
;
5273 /* See dw2_debug_names_iterator. */
5275 dwarf2_per_cu_data
*
5276 dw2_debug_names_iterator::next ()
5281 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5282 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5283 bfd
*const abfd
= objfile
->obfd
;
5287 unsigned int bytes_read
;
5288 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5289 m_addr
+= bytes_read
;
5293 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5294 if (indexval_it
== m_map
.abbrev_map
.cend ())
5296 complaint (_("Wrong .debug_names undefined abbrev code %s "
5298 pulongest (abbrev
), objfile_name (objfile
));
5301 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5302 enum class symbol_linkage
{
5306 } symbol_linkage_
= symbol_linkage::unknown
;
5307 dwarf2_per_cu_data
*per_cu
= NULL
;
5308 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5313 case DW_FORM_implicit_const
:
5314 ull
= attr
.implicit_const
;
5316 case DW_FORM_flag_present
:
5320 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5321 m_addr
+= bytes_read
;
5324 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5325 dwarf_form_name (attr
.form
),
5326 objfile_name (objfile
));
5329 switch (attr
.dw_idx
)
5331 case DW_IDX_compile_unit
:
5332 /* Don't crash on bad data. */
5333 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5335 complaint (_(".debug_names entry has bad CU index %s"
5338 objfile_name (dwarf2_per_objfile
->objfile
));
5341 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5343 case DW_IDX_type_unit
:
5344 /* Don't crash on bad data. */
5345 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5347 complaint (_(".debug_names entry has bad TU index %s"
5350 objfile_name (dwarf2_per_objfile
->objfile
));
5353 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5355 case DW_IDX_GNU_internal
:
5356 if (!m_map
.augmentation_is_gdb
)
5358 symbol_linkage_
= symbol_linkage::static_
;
5360 case DW_IDX_GNU_external
:
5361 if (!m_map
.augmentation_is_gdb
)
5363 symbol_linkage_
= symbol_linkage::extern_
;
5368 /* Skip if already read in. */
5369 if (per_cu
->v
.quick
->compunit_symtab
)
5372 /* Check static vs global. */
5373 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5375 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5376 const bool symbol_is_static
=
5377 symbol_linkage_
== symbol_linkage::static_
;
5378 if (want_static
!= symbol_is_static
)
5382 /* Match dw2_symtab_iter_next, symbol_kind
5383 and debug_names::psymbol_tag. */
5387 switch (indexval
.dwarf_tag
)
5389 case DW_TAG_variable
:
5390 case DW_TAG_subprogram
:
5391 /* Some types are also in VAR_DOMAIN. */
5392 case DW_TAG_typedef
:
5393 case DW_TAG_structure_type
:
5400 switch (indexval
.dwarf_tag
)
5402 case DW_TAG_typedef
:
5403 case DW_TAG_structure_type
:
5410 switch (indexval
.dwarf_tag
)
5413 case DW_TAG_variable
:
5420 switch (indexval
.dwarf_tag
)
5432 /* Match dw2_expand_symtabs_matching, symbol_kind and
5433 debug_names::psymbol_tag. */
5436 case VARIABLES_DOMAIN
:
5437 switch (indexval
.dwarf_tag
)
5439 case DW_TAG_variable
:
5445 case FUNCTIONS_DOMAIN
:
5446 switch (indexval
.dwarf_tag
)
5448 case DW_TAG_subprogram
:
5455 switch (indexval
.dwarf_tag
)
5457 case DW_TAG_typedef
:
5458 case DW_TAG_structure_type
:
5464 case MODULES_DOMAIN
:
5465 switch (indexval
.dwarf_tag
)
5479 static struct compunit_symtab
*
5480 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5481 const char *name
, domain_enum domain
)
5483 struct dwarf2_per_objfile
*dwarf2_per_objfile
5484 = get_dwarf2_per_objfile (objfile
);
5486 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5489 /* index is NULL if OBJF_READNOW. */
5492 const auto &map
= *mapp
;
5494 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5496 struct compunit_symtab
*stab_best
= NULL
;
5497 struct dwarf2_per_cu_data
*per_cu
;
5498 while ((per_cu
= iter
.next ()) != NULL
)
5500 struct symbol
*sym
, *with_opaque
= NULL
;
5501 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5502 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5503 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5505 sym
= block_find_symbol (block
, name
, domain
,
5506 block_find_non_opaque_type_preferred
,
5509 /* Some caution must be observed with overloaded functions and
5510 methods, since the index will not contain any overload
5511 information (but NAME might contain it). */
5514 && strcmp_iw (sym
->search_name (), name
) == 0)
5516 if (with_opaque
!= NULL
5517 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5520 /* Keep looking through other CUs. */
5526 /* This dumps minimal information about .debug_names. It is called
5527 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5528 uses this to verify that .debug_names has been loaded. */
5531 dw2_debug_names_dump (struct objfile
*objfile
)
5533 struct dwarf2_per_objfile
*dwarf2_per_objfile
5534 = get_dwarf2_per_objfile (objfile
);
5536 gdb_assert (dwarf2_per_objfile
->using_index
);
5537 printf_filtered (".debug_names:");
5538 if (dwarf2_per_objfile
->debug_names_table
)
5539 printf_filtered (" exists\n");
5541 printf_filtered (" faked for \"readnow\"\n");
5542 printf_filtered ("\n");
5546 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5547 const char *func_name
)
5549 struct dwarf2_per_objfile
*dwarf2_per_objfile
5550 = get_dwarf2_per_objfile (objfile
);
5552 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5553 if (dwarf2_per_objfile
->debug_names_table
)
5555 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5557 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5559 struct dwarf2_per_cu_data
*per_cu
;
5560 while ((per_cu
= iter
.next ()) != NULL
)
5561 dw2_instantiate_symtab (per_cu
, false);
5566 dw2_debug_names_map_matching_symbols
5567 (struct objfile
*objfile
,
5568 const lookup_name_info
&name
, domain_enum domain
,
5570 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5571 symbol_compare_ftype
*ordered_compare
)
5573 struct dwarf2_per_objfile
*dwarf2_per_objfile
5574 = get_dwarf2_per_objfile (objfile
);
5576 /* debug_names_table is NULL if OBJF_READNOW. */
5577 if (!dwarf2_per_objfile
->debug_names_table
)
5580 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5581 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5583 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5584 auto matcher
= [&] (const char *symname
)
5586 if (ordered_compare
== nullptr)
5588 return ordered_compare (symname
, match_name
) == 0;
5591 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5592 [&] (offset_type namei
)
5594 /* The name was matched, now expand corresponding CUs that were
5596 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5598 struct dwarf2_per_cu_data
*per_cu
;
5599 while ((per_cu
= iter
.next ()) != NULL
)
5600 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5604 /* It's a shame we couldn't do this inside the
5605 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5606 that have already been expanded. Instead, this loop matches what
5607 the psymtab code does. */
5608 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5610 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5611 if (cust
!= nullptr)
5613 const struct block
*block
5614 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5615 if (!iterate_over_symbols_terminated (block
, name
,
5623 dw2_debug_names_expand_symtabs_matching
5624 (struct objfile
*objfile
,
5625 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5626 const lookup_name_info
&lookup_name
,
5627 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5628 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5629 enum search_domain kind
)
5631 struct dwarf2_per_objfile
*dwarf2_per_objfile
5632 = get_dwarf2_per_objfile (objfile
);
5634 /* debug_names_table is NULL if OBJF_READNOW. */
5635 if (!dwarf2_per_objfile
->debug_names_table
)
5638 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5640 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5642 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5644 kind
, [&] (offset_type namei
)
5646 /* The name was matched, now expand corresponding CUs that were
5648 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5650 struct dwarf2_per_cu_data
*per_cu
;
5651 while ((per_cu
= iter
.next ()) != NULL
)
5652 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5658 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5661 dw2_find_last_source_symtab
,
5662 dw2_forget_cached_source_info
,
5663 dw2_map_symtabs_matching_filename
,
5664 dw2_debug_names_lookup_symbol
,
5666 dw2_debug_names_dump
,
5667 dw2_debug_names_expand_symtabs_for_function
,
5668 dw2_expand_all_symtabs
,
5669 dw2_expand_symtabs_with_fullname
,
5670 dw2_debug_names_map_matching_symbols
,
5671 dw2_debug_names_expand_symtabs_matching
,
5672 dw2_find_pc_sect_compunit_symtab
,
5674 dw2_map_symbol_filenames
5677 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5678 to either a dwarf2_per_objfile or dwz_file object. */
5680 template <typename T
>
5681 static gdb::array_view
<const gdb_byte
>
5682 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5684 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5686 if (section
->empty ())
5689 /* Older elfutils strip versions could keep the section in the main
5690 executable while splitting it for the separate debug info file. */
5691 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5694 section
->read (obj
);
5696 /* dwarf2_section_info::size is a bfd_size_type, while
5697 gdb::array_view works with size_t. On 32-bit hosts, with
5698 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5699 is 32-bit. So we need an explicit narrowing conversion here.
5700 This is fine, because it's impossible to allocate or mmap an
5701 array/buffer larger than what size_t can represent. */
5702 return gdb::make_array_view (section
->buffer
, section
->size
);
5705 /* Lookup the index cache for the contents of the index associated to
5708 static gdb::array_view
<const gdb_byte
>
5709 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5711 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5712 if (build_id
== nullptr)
5715 return global_index_cache
.lookup_gdb_index (build_id
,
5716 &dwarf2_obj
->index_cache_res
);
5719 /* Same as the above, but for DWZ. */
5721 static gdb::array_view
<const gdb_byte
>
5722 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5724 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5725 if (build_id
== nullptr)
5728 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5731 /* See symfile.h. */
5734 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5736 struct dwarf2_per_objfile
*dwarf2_per_objfile
5737 = get_dwarf2_per_objfile (objfile
);
5739 /* If we're about to read full symbols, don't bother with the
5740 indices. In this case we also don't care if some other debug
5741 format is making psymtabs, because they are all about to be
5743 if ((objfile
->flags
& OBJF_READNOW
))
5745 dwarf2_per_objfile
->using_index
= 1;
5746 create_all_comp_units (dwarf2_per_objfile
);
5747 create_all_type_units (dwarf2_per_objfile
);
5748 dwarf2_per_objfile
->quick_file_names_table
5749 = create_quick_file_names_table
5750 (dwarf2_per_objfile
->all_comp_units
.size ());
5752 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5753 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5755 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5757 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5758 struct dwarf2_per_cu_quick_data
);
5761 /* Return 1 so that gdb sees the "quick" functions. However,
5762 these functions will be no-ops because we will have expanded
5764 *index_kind
= dw_index_kind::GDB_INDEX
;
5768 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5770 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5774 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5775 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5776 get_gdb_index_contents_from_section
<dwz_file
>))
5778 *index_kind
= dw_index_kind::GDB_INDEX
;
5782 /* ... otherwise, try to find the index in the index cache. */
5783 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5784 get_gdb_index_contents_from_cache
,
5785 get_gdb_index_contents_from_cache_dwz
))
5787 global_index_cache
.hit ();
5788 *index_kind
= dw_index_kind::GDB_INDEX
;
5792 global_index_cache
.miss ();
5798 /* Build a partial symbol table. */
5801 dwarf2_build_psymtabs (struct objfile
*objfile
)
5803 struct dwarf2_per_objfile
*dwarf2_per_objfile
5804 = get_dwarf2_per_objfile (objfile
);
5806 init_psymbol_list (objfile
, 1024);
5810 /* This isn't really ideal: all the data we allocate on the
5811 objfile's obstack is still uselessly kept around. However,
5812 freeing it seems unsafe. */
5813 psymtab_discarder
psymtabs (objfile
);
5814 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5817 /* (maybe) store an index in the cache. */
5818 global_index_cache
.store (dwarf2_per_objfile
);
5820 catch (const gdb_exception_error
&except
)
5822 exception_print (gdb_stderr
, except
);
5826 /* Find the base address of the compilation unit for range lists and
5827 location lists. It will normally be specified by DW_AT_low_pc.
5828 In DWARF-3 draft 4, the base address could be overridden by
5829 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5830 compilation units with discontinuous ranges. */
5833 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5835 struct attribute
*attr
;
5838 cu
->base_address
= 0;
5840 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5841 if (attr
!= nullptr)
5843 cu
->base_address
= attr
->value_as_address ();
5848 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5849 if (attr
!= nullptr)
5851 cu
->base_address
= attr
->value_as_address ();
5857 /* Helper function that returns the proper abbrev section for
5860 static struct dwarf2_section_info
*
5861 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5863 struct dwarf2_section_info
*abbrev
;
5864 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5866 if (this_cu
->is_dwz
)
5867 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5869 abbrev
= &dwarf2_per_objfile
->abbrev
;
5874 /* Fetch the abbreviation table offset from a comp or type unit header. */
5877 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5878 struct dwarf2_section_info
*section
,
5879 sect_offset sect_off
)
5881 bfd
*abfd
= section
->get_bfd_owner ();
5882 const gdb_byte
*info_ptr
;
5883 unsigned int initial_length_size
, offset_size
;
5886 section
->read (dwarf2_per_objfile
->objfile
);
5887 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5888 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5889 offset_size
= initial_length_size
== 4 ? 4 : 8;
5890 info_ptr
+= initial_length_size
;
5892 version
= read_2_bytes (abfd
, info_ptr
);
5896 /* Skip unit type and address size. */
5900 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5903 /* Allocate a new partial symtab for file named NAME and mark this new
5904 partial symtab as being an include of PST. */
5907 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5908 struct objfile
*objfile
)
5910 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
5912 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5914 /* It shares objfile->objfile_obstack. */
5915 subpst
->dirname
= pst
->dirname
;
5918 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5919 subpst
->dependencies
[0] = pst
;
5920 subpst
->number_of_dependencies
= 1;
5922 /* No private part is necessary for include psymtabs. This property
5923 can be used to differentiate between such include psymtabs and
5924 the regular ones. */
5925 subpst
->per_cu_data
= nullptr;
5928 /* Read the Line Number Program data and extract the list of files
5929 included by the source file represented by PST. Build an include
5930 partial symtab for each of these included files. */
5933 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5934 struct die_info
*die
,
5935 dwarf2_psymtab
*pst
)
5938 struct attribute
*attr
;
5940 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5941 if (attr
!= nullptr)
5942 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5944 return; /* No linetable, so no includes. */
5946 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5947 that we pass in the raw text_low here; that is ok because we're
5948 only decoding the line table to make include partial symtabs, and
5949 so the addresses aren't really used. */
5950 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5951 pst
->raw_text_low (), 1);
5955 hash_signatured_type (const void *item
)
5957 const struct signatured_type
*sig_type
5958 = (const struct signatured_type
*) item
;
5960 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5961 return sig_type
->signature
;
5965 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5967 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5968 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5970 return lhs
->signature
== rhs
->signature
;
5973 /* Allocate a hash table for signatured types. */
5976 allocate_signatured_type_table (struct objfile
*objfile
)
5978 return htab_up (htab_create_alloc (41,
5979 hash_signatured_type
,
5981 NULL
, xcalloc
, xfree
));
5984 /* A helper function to add a signatured type CU to a table. */
5987 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5989 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5990 std::vector
<signatured_type
*> *all_type_units
5991 = (std::vector
<signatured_type
*> *) datum
;
5993 all_type_units
->push_back (sigt
);
5998 /* A helper for create_debug_types_hash_table. Read types from SECTION
5999 and fill them into TYPES_HTAB. It will process only type units,
6000 therefore DW_UT_type. */
6003 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6004 struct dwo_file
*dwo_file
,
6005 dwarf2_section_info
*section
, htab_up
&types_htab
,
6006 rcuh_kind section_kind
)
6008 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6009 struct dwarf2_section_info
*abbrev_section
;
6011 const gdb_byte
*info_ptr
, *end_ptr
;
6013 abbrev_section
= (dwo_file
!= NULL
6014 ? &dwo_file
->sections
.abbrev
6015 : &dwarf2_per_objfile
->abbrev
);
6017 if (dwarf_read_debug
)
6018 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6019 section
->get_name (),
6020 abbrev_section
->get_file_name ());
6022 section
->read (objfile
);
6023 info_ptr
= section
->buffer
;
6025 if (info_ptr
== NULL
)
6028 /* We can't set abfd until now because the section may be empty or
6029 not present, in which case the bfd is unknown. */
6030 abfd
= section
->get_bfd_owner ();
6032 /* We don't use cutu_reader here because we don't need to read
6033 any dies: the signature is in the header. */
6035 end_ptr
= info_ptr
+ section
->size
;
6036 while (info_ptr
< end_ptr
)
6038 struct signatured_type
*sig_type
;
6039 struct dwo_unit
*dwo_tu
;
6041 const gdb_byte
*ptr
= info_ptr
;
6042 struct comp_unit_head header
;
6043 unsigned int length
;
6045 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6047 /* Initialize it due to a false compiler warning. */
6048 header
.signature
= -1;
6049 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6051 /* We need to read the type's signature in order to build the hash
6052 table, but we don't need anything else just yet. */
6054 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6055 abbrev_section
, ptr
, section_kind
);
6057 length
= header
.get_length ();
6059 /* Skip dummy type units. */
6060 if (ptr
>= info_ptr
+ length
6061 || peek_abbrev_code (abfd
, ptr
) == 0
6062 || header
.unit_type
!= DW_UT_type
)
6068 if (types_htab
== NULL
)
6071 types_htab
= allocate_dwo_unit_table (objfile
);
6073 types_htab
= allocate_signatured_type_table (objfile
);
6079 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6081 dwo_tu
->dwo_file
= dwo_file
;
6082 dwo_tu
->signature
= header
.signature
;
6083 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6084 dwo_tu
->section
= section
;
6085 dwo_tu
->sect_off
= sect_off
;
6086 dwo_tu
->length
= length
;
6090 /* N.B.: type_offset is not usable if this type uses a DWO file.
6091 The real type_offset is in the DWO file. */
6093 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6094 struct signatured_type
);
6095 sig_type
->signature
= header
.signature
;
6096 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6097 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6098 sig_type
->per_cu
.is_debug_types
= 1;
6099 sig_type
->per_cu
.section
= section
;
6100 sig_type
->per_cu
.sect_off
= sect_off
;
6101 sig_type
->per_cu
.length
= length
;
6104 slot
= htab_find_slot (types_htab
.get (),
6105 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6107 gdb_assert (slot
!= NULL
);
6110 sect_offset dup_sect_off
;
6114 const struct dwo_unit
*dup_tu
6115 = (const struct dwo_unit
*) *slot
;
6117 dup_sect_off
= dup_tu
->sect_off
;
6121 const struct signatured_type
*dup_tu
6122 = (const struct signatured_type
*) *slot
;
6124 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6127 complaint (_("debug type entry at offset %s is duplicate to"
6128 " the entry at offset %s, signature %s"),
6129 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6130 hex_string (header
.signature
));
6132 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6134 if (dwarf_read_debug
> 1)
6135 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6136 sect_offset_str (sect_off
),
6137 hex_string (header
.signature
));
6143 /* Create the hash table of all entries in the .debug_types
6144 (or .debug_types.dwo) section(s).
6145 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6146 otherwise it is NULL.
6148 The result is a pointer to the hash table or NULL if there are no types.
6150 Note: This function processes DWO files only, not DWP files. */
6153 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6154 struct dwo_file
*dwo_file
,
6155 gdb::array_view
<dwarf2_section_info
> type_sections
,
6156 htab_up
&types_htab
)
6158 for (dwarf2_section_info
§ion
: type_sections
)
6159 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6160 types_htab
, rcuh_kind::TYPE
);
6163 /* Create the hash table of all entries in the .debug_types section,
6164 and initialize all_type_units.
6165 The result is zero if there is an error (e.g. missing .debug_types section),
6166 otherwise non-zero. */
6169 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6173 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6174 &dwarf2_per_objfile
->info
, types_htab
,
6175 rcuh_kind::COMPILE
);
6176 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6177 dwarf2_per_objfile
->types
, types_htab
);
6178 if (types_htab
== NULL
)
6180 dwarf2_per_objfile
->signatured_types
= NULL
;
6184 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6186 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6187 dwarf2_per_objfile
->all_type_units
.reserve
6188 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6190 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6191 add_signatured_type_cu_to_table
,
6192 &dwarf2_per_objfile
->all_type_units
);
6197 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6198 If SLOT is non-NULL, it is the entry to use in the hash table.
6199 Otherwise we find one. */
6201 static struct signatured_type
*
6202 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6205 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6207 if (dwarf2_per_objfile
->all_type_units
.size ()
6208 == dwarf2_per_objfile
->all_type_units
.capacity ())
6209 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6211 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6212 struct signatured_type
);
6214 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6215 sig_type
->signature
= sig
;
6216 sig_type
->per_cu
.is_debug_types
= 1;
6217 if (dwarf2_per_objfile
->using_index
)
6219 sig_type
->per_cu
.v
.quick
=
6220 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6221 struct dwarf2_per_cu_quick_data
);
6226 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6229 gdb_assert (*slot
== NULL
);
6231 /* The rest of sig_type must be filled in by the caller. */
6235 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6236 Fill in SIG_ENTRY with DWO_ENTRY. */
6239 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6240 struct signatured_type
*sig_entry
,
6241 struct dwo_unit
*dwo_entry
)
6243 /* Make sure we're not clobbering something we don't expect to. */
6244 gdb_assert (! sig_entry
->per_cu
.queued
);
6245 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6246 if (dwarf2_per_objfile
->using_index
)
6248 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6249 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6252 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6253 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6254 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6255 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6256 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6258 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6259 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6260 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6261 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6262 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6263 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6264 sig_entry
->dwo_unit
= dwo_entry
;
6267 /* Subroutine of lookup_signatured_type.
6268 If we haven't read the TU yet, create the signatured_type data structure
6269 for a TU to be read in directly from a DWO file, bypassing the stub.
6270 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6271 using .gdb_index, then when reading a CU we want to stay in the DWO file
6272 containing that CU. Otherwise we could end up reading several other DWO
6273 files (due to comdat folding) to process the transitive closure of all the
6274 mentioned TUs, and that can be slow. The current DWO file will have every
6275 type signature that it needs.
6276 We only do this for .gdb_index because in the psymtab case we already have
6277 to read all the DWOs to build the type unit groups. */
6279 static struct signatured_type
*
6280 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6282 struct dwarf2_per_objfile
*dwarf2_per_objfile
6283 = cu
->per_cu
->dwarf2_per_objfile
;
6284 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6285 struct dwo_file
*dwo_file
;
6286 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6287 struct signatured_type find_sig_entry
, *sig_entry
;
6290 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6292 /* If TU skeletons have been removed then we may not have read in any
6294 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6296 dwarf2_per_objfile
->signatured_types
6297 = allocate_signatured_type_table (objfile
);
6300 /* We only ever need to read in one copy of a signatured type.
6301 Use the global signatured_types array to do our own comdat-folding
6302 of types. If this is the first time we're reading this TU, and
6303 the TU has an entry in .gdb_index, replace the recorded data from
6304 .gdb_index with this TU. */
6306 find_sig_entry
.signature
= sig
;
6307 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6308 &find_sig_entry
, INSERT
);
6309 sig_entry
= (struct signatured_type
*) *slot
;
6311 /* We can get here with the TU already read, *or* in the process of being
6312 read. Don't reassign the global entry to point to this DWO if that's
6313 the case. Also note that if the TU is already being read, it may not
6314 have come from a DWO, the program may be a mix of Fission-compiled
6315 code and non-Fission-compiled code. */
6317 /* Have we already tried to read this TU?
6318 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6319 needn't exist in the global table yet). */
6320 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6323 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6324 dwo_unit of the TU itself. */
6325 dwo_file
= cu
->dwo_unit
->dwo_file
;
6327 /* Ok, this is the first time we're reading this TU. */
6328 if (dwo_file
->tus
== NULL
)
6330 find_dwo_entry
.signature
= sig
;
6331 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6333 if (dwo_entry
== NULL
)
6336 /* If the global table doesn't have an entry for this TU, add one. */
6337 if (sig_entry
== NULL
)
6338 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6340 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6341 sig_entry
->per_cu
.tu_read
= 1;
6345 /* Subroutine of lookup_signatured_type.
6346 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6347 then try the DWP file. If the TU stub (skeleton) has been removed then
6348 it won't be in .gdb_index. */
6350 static struct signatured_type
*
6351 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6353 struct dwarf2_per_objfile
*dwarf2_per_objfile
6354 = cu
->per_cu
->dwarf2_per_objfile
;
6355 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6356 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6357 struct dwo_unit
*dwo_entry
;
6358 struct signatured_type find_sig_entry
, *sig_entry
;
6361 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6362 gdb_assert (dwp_file
!= NULL
);
6364 /* If TU skeletons have been removed then we may not have read in any
6366 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6368 dwarf2_per_objfile
->signatured_types
6369 = allocate_signatured_type_table (objfile
);
6372 find_sig_entry
.signature
= sig
;
6373 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6374 &find_sig_entry
, INSERT
);
6375 sig_entry
= (struct signatured_type
*) *slot
;
6377 /* Have we already tried to read this TU?
6378 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6379 needn't exist in the global table yet). */
6380 if (sig_entry
!= NULL
)
6383 if (dwp_file
->tus
== NULL
)
6385 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6386 sig
, 1 /* is_debug_types */);
6387 if (dwo_entry
== NULL
)
6390 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6391 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6396 /* Lookup a signature based type for DW_FORM_ref_sig8.
6397 Returns NULL if signature SIG is not present in the table.
6398 It is up to the caller to complain about this. */
6400 static struct signatured_type
*
6401 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6403 struct dwarf2_per_objfile
*dwarf2_per_objfile
6404 = cu
->per_cu
->dwarf2_per_objfile
;
6407 && dwarf2_per_objfile
->using_index
)
6409 /* We're in a DWO/DWP file, and we're using .gdb_index.
6410 These cases require special processing. */
6411 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6412 return lookup_dwo_signatured_type (cu
, sig
);
6414 return lookup_dwp_signatured_type (cu
, sig
);
6418 struct signatured_type find_entry
, *entry
;
6420 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6422 find_entry
.signature
= sig
;
6423 entry
= ((struct signatured_type
*)
6424 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6430 /* Return the address base of the compile unit, which, if exists, is stored
6431 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6432 static gdb::optional
<ULONGEST
>
6433 lookup_addr_base (struct die_info
*comp_unit_die
)
6435 struct attribute
*attr
;
6436 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6437 if (attr
== nullptr)
6438 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6439 if (attr
== nullptr)
6440 return gdb::optional
<ULONGEST
> ();
6441 return DW_UNSND (attr
);
6444 /* Return range lists base of the compile unit, which, if exists, is stored
6445 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6447 lookup_ranges_base (struct die_info
*comp_unit_die
)
6449 struct attribute
*attr
;
6450 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6451 if (attr
== nullptr)
6452 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6453 if (attr
== nullptr)
6455 return DW_UNSND (attr
);
6458 /* Low level DIE reading support. */
6460 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6463 init_cu_die_reader (struct die_reader_specs
*reader
,
6464 struct dwarf2_cu
*cu
,
6465 struct dwarf2_section_info
*section
,
6466 struct dwo_file
*dwo_file
,
6467 struct abbrev_table
*abbrev_table
)
6469 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6470 reader
->abfd
= section
->get_bfd_owner ();
6472 reader
->dwo_file
= dwo_file
;
6473 reader
->die_section
= section
;
6474 reader
->buffer
= section
->buffer
;
6475 reader
->buffer_end
= section
->buffer
+ section
->size
;
6476 reader
->abbrev_table
= abbrev_table
;
6479 /* Subroutine of cutu_reader to simplify it.
6480 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6481 There's just a lot of work to do, and cutu_reader is big enough
6484 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6485 from it to the DIE in the DWO. If NULL we are skipping the stub.
6486 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6487 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6488 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6489 STUB_COMP_DIR may be non-NULL.
6490 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6491 are filled in with the info of the DIE from the DWO file.
6492 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6493 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6494 kept around for at least as long as *RESULT_READER.
6496 The result is non-zero if a valid (non-dummy) DIE was found. */
6499 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6500 struct dwo_unit
*dwo_unit
,
6501 struct die_info
*stub_comp_unit_die
,
6502 const char *stub_comp_dir
,
6503 struct die_reader_specs
*result_reader
,
6504 const gdb_byte
**result_info_ptr
,
6505 struct die_info
**result_comp_unit_die
,
6506 abbrev_table_up
*result_dwo_abbrev_table
)
6508 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6509 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6510 struct dwarf2_cu
*cu
= this_cu
->cu
;
6512 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6513 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6514 int i
,num_extra_attrs
;
6515 struct dwarf2_section_info
*dwo_abbrev_section
;
6516 struct die_info
*comp_unit_die
;
6518 /* At most one of these may be provided. */
6519 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6521 /* These attributes aren't processed until later:
6522 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6523 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6524 referenced later. However, these attributes are found in the stub
6525 which we won't have later. In order to not impose this complication
6526 on the rest of the code, we read them here and copy them to the
6535 if (stub_comp_unit_die
!= NULL
)
6537 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6539 if (! this_cu
->is_debug_types
)
6540 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6541 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6542 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6543 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6544 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6546 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6548 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6549 here (if needed). We need the value before we can process
6551 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6553 else if (stub_comp_dir
!= NULL
)
6555 /* Reconstruct the comp_dir attribute to simplify the code below. */
6556 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6557 comp_dir
->name
= DW_AT_comp_dir
;
6558 comp_dir
->form
= DW_FORM_string
;
6559 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6560 DW_STRING (comp_dir
) = stub_comp_dir
;
6563 /* Set up for reading the DWO CU/TU. */
6564 cu
->dwo_unit
= dwo_unit
;
6565 dwarf2_section_info
*section
= dwo_unit
->section
;
6566 section
->read (objfile
);
6567 abfd
= section
->get_bfd_owner ();
6568 begin_info_ptr
= info_ptr
= (section
->buffer
6569 + to_underlying (dwo_unit
->sect_off
));
6570 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6572 if (this_cu
->is_debug_types
)
6574 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6576 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6577 &cu
->header
, section
,
6579 info_ptr
, rcuh_kind::TYPE
);
6580 /* This is not an assert because it can be caused by bad debug info. */
6581 if (sig_type
->signature
!= cu
->header
.signature
)
6583 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6584 " TU at offset %s [in module %s]"),
6585 hex_string (sig_type
->signature
),
6586 hex_string (cu
->header
.signature
),
6587 sect_offset_str (dwo_unit
->sect_off
),
6588 bfd_get_filename (abfd
));
6590 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6591 /* For DWOs coming from DWP files, we don't know the CU length
6592 nor the type's offset in the TU until now. */
6593 dwo_unit
->length
= cu
->header
.get_length ();
6594 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6596 /* Establish the type offset that can be used to lookup the type.
6597 For DWO files, we don't know it until now. */
6598 sig_type
->type_offset_in_section
6599 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6603 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6604 &cu
->header
, section
,
6606 info_ptr
, rcuh_kind::COMPILE
);
6607 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6608 /* For DWOs coming from DWP files, we don't know the CU length
6610 dwo_unit
->length
= cu
->header
.get_length ();
6613 *result_dwo_abbrev_table
6614 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6615 cu
->header
.abbrev_sect_off
);
6616 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6617 result_dwo_abbrev_table
->get ());
6619 /* Read in the die, but leave space to copy over the attributes
6620 from the stub. This has the benefit of simplifying the rest of
6621 the code - all the work to maintain the illusion of a single
6622 DW_TAG_{compile,type}_unit DIE is done here. */
6623 num_extra_attrs
= ((stmt_list
!= NULL
)
6627 + (comp_dir
!= NULL
));
6628 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6631 /* Copy over the attributes from the stub to the DIE we just read in. */
6632 comp_unit_die
= *result_comp_unit_die
;
6633 i
= comp_unit_die
->num_attrs
;
6634 if (stmt_list
!= NULL
)
6635 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6637 comp_unit_die
->attrs
[i
++] = *low_pc
;
6638 if (high_pc
!= NULL
)
6639 comp_unit_die
->attrs
[i
++] = *high_pc
;
6641 comp_unit_die
->attrs
[i
++] = *ranges
;
6642 if (comp_dir
!= NULL
)
6643 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6644 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6646 if (dwarf_die_debug
)
6648 fprintf_unfiltered (gdb_stdlog
,
6649 "Read die from %s@0x%x of %s:\n",
6650 section
->get_name (),
6651 (unsigned) (begin_info_ptr
- section
->buffer
),
6652 bfd_get_filename (abfd
));
6653 dump_die (comp_unit_die
, dwarf_die_debug
);
6656 /* Skip dummy compilation units. */
6657 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6658 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6661 *result_info_ptr
= info_ptr
;
6665 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6666 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6667 signature is part of the header. */
6668 static gdb::optional
<ULONGEST
>
6669 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6671 if (cu
->header
.version
>= 5)
6672 return cu
->header
.signature
;
6673 struct attribute
*attr
;
6674 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6675 if (attr
== nullptr)
6676 return gdb::optional
<ULONGEST
> ();
6677 return DW_UNSND (attr
);
6680 /* Subroutine of cutu_reader to simplify it.
6681 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6682 Returns NULL if the specified DWO unit cannot be found. */
6684 static struct dwo_unit
*
6685 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6686 struct die_info
*comp_unit_die
,
6687 const char *dwo_name
)
6689 struct dwarf2_cu
*cu
= this_cu
->cu
;
6690 struct dwo_unit
*dwo_unit
;
6691 const char *comp_dir
;
6693 gdb_assert (cu
!= NULL
);
6695 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6696 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6697 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6699 if (this_cu
->is_debug_types
)
6701 struct signatured_type
*sig_type
;
6703 /* Since this_cu is the first member of struct signatured_type,
6704 we can go from a pointer to one to a pointer to the other. */
6705 sig_type
= (struct signatured_type
*) this_cu
;
6706 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6710 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6711 if (!signature
.has_value ())
6712 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6714 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6715 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6722 /* Subroutine of cutu_reader to simplify it.
6723 See it for a description of the parameters.
6724 Read a TU directly from a DWO file, bypassing the stub. */
6727 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6728 int use_existing_cu
)
6730 struct signatured_type
*sig_type
;
6731 struct die_reader_specs reader
;
6733 /* Verify we can do the following downcast, and that we have the
6735 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6736 sig_type
= (struct signatured_type
*) this_cu
;
6737 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6739 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6741 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6742 /* There's no need to do the rereading_dwo_cu handling that
6743 cutu_reader does since we don't read the stub. */
6747 /* If !use_existing_cu, this_cu->cu must be NULL. */
6748 gdb_assert (this_cu
->cu
== NULL
);
6749 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6752 /* A future optimization, if needed, would be to use an existing
6753 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6754 could share abbrev tables. */
6756 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6757 NULL
/* stub_comp_unit_die */,
6758 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6761 &m_dwo_abbrev_table
) == 0)
6768 /* Initialize a CU (or TU) and read its DIEs.
6769 If the CU defers to a DWO file, read the DWO file as well.
6771 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6772 Otherwise the table specified in the comp unit header is read in and used.
6773 This is an optimization for when we already have the abbrev table.
6775 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6776 Otherwise, a new CU is allocated with xmalloc. */
6778 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6779 struct abbrev_table
*abbrev_table
,
6780 int use_existing_cu
,
6782 : die_reader_specs
{},
6785 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6786 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6787 struct dwarf2_section_info
*section
= this_cu
->section
;
6788 bfd
*abfd
= section
->get_bfd_owner ();
6789 struct dwarf2_cu
*cu
;
6790 const gdb_byte
*begin_info_ptr
;
6791 struct signatured_type
*sig_type
= NULL
;
6792 struct dwarf2_section_info
*abbrev_section
;
6793 /* Non-zero if CU currently points to a DWO file and we need to
6794 reread it. When this happens we need to reread the skeleton die
6795 before we can reread the DWO file (this only applies to CUs, not TUs). */
6796 int rereading_dwo_cu
= 0;
6798 if (dwarf_die_debug
)
6799 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6800 this_cu
->is_debug_types
? "type" : "comp",
6801 sect_offset_str (this_cu
->sect_off
));
6803 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6804 file (instead of going through the stub), short-circuit all of this. */
6805 if (this_cu
->reading_dwo_directly
)
6807 /* Narrow down the scope of possibilities to have to understand. */
6808 gdb_assert (this_cu
->is_debug_types
);
6809 gdb_assert (abbrev_table
== NULL
);
6810 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6814 /* This is cheap if the section is already read in. */
6815 section
->read (objfile
);
6817 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6819 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6821 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6824 /* If this CU is from a DWO file we need to start over, we need to
6825 refetch the attributes from the skeleton CU.
6826 This could be optimized by retrieving those attributes from when we
6827 were here the first time: the previous comp_unit_die was stored in
6828 comp_unit_obstack. But there's no data yet that we need this
6830 if (cu
->dwo_unit
!= NULL
)
6831 rereading_dwo_cu
= 1;
6835 /* If !use_existing_cu, this_cu->cu must be NULL. */
6836 gdb_assert (this_cu
->cu
== NULL
);
6837 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6838 cu
= m_new_cu
.get ();
6841 /* Get the header. */
6842 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6844 /* We already have the header, there's no need to read it in again. */
6845 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6849 if (this_cu
->is_debug_types
)
6851 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6852 &cu
->header
, section
,
6853 abbrev_section
, info_ptr
,
6856 /* Since per_cu is the first member of struct signatured_type,
6857 we can go from a pointer to one to a pointer to the other. */
6858 sig_type
= (struct signatured_type
*) this_cu
;
6859 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6860 gdb_assert (sig_type
->type_offset_in_tu
6861 == cu
->header
.type_cu_offset_in_tu
);
6862 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6864 /* LENGTH has not been set yet for type units if we're
6865 using .gdb_index. */
6866 this_cu
->length
= cu
->header
.get_length ();
6868 /* Establish the type offset that can be used to lookup the type. */
6869 sig_type
->type_offset_in_section
=
6870 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6872 this_cu
->dwarf_version
= cu
->header
.version
;
6876 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6877 &cu
->header
, section
,
6880 rcuh_kind::COMPILE
);
6882 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6883 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6884 this_cu
->dwarf_version
= cu
->header
.version
;
6888 /* Skip dummy compilation units. */
6889 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6890 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6896 /* If we don't have them yet, read the abbrevs for this compilation unit.
6897 And if we need to read them now, make sure they're freed when we're
6899 if (abbrev_table
!= NULL
)
6900 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6903 m_abbrev_table_holder
6904 = abbrev_table::read (objfile
, abbrev_section
,
6905 cu
->header
.abbrev_sect_off
);
6906 abbrev_table
= m_abbrev_table_holder
.get ();
6909 /* Read the top level CU/TU die. */
6910 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6911 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6913 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6919 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6920 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6921 table from the DWO file and pass the ownership over to us. It will be
6922 referenced from READER, so we must make sure to free it after we're done
6925 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6926 DWO CU, that this test will fail (the attribute will not be present). */
6927 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6928 if (dwo_name
!= nullptr)
6930 struct dwo_unit
*dwo_unit
;
6931 struct die_info
*dwo_comp_unit_die
;
6933 if (comp_unit_die
->has_children
)
6935 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6936 " has children (offset %s) [in module %s]"),
6937 sect_offset_str (this_cu
->sect_off
),
6938 bfd_get_filename (abfd
));
6940 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6941 if (dwo_unit
!= NULL
)
6943 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6944 comp_unit_die
, NULL
,
6947 &m_dwo_abbrev_table
) == 0)
6953 comp_unit_die
= dwo_comp_unit_die
;
6957 /* Yikes, we couldn't find the rest of the DIE, we only have
6958 the stub. A complaint has already been logged. There's
6959 not much more we can do except pass on the stub DIE to
6960 die_reader_func. We don't want to throw an error on bad
6967 cutu_reader::keep ()
6969 /* Done, clean up. */
6970 gdb_assert (!dummy_p
);
6971 if (m_new_cu
!= NULL
)
6973 struct dwarf2_per_objfile
*dwarf2_per_objfile
6974 = m_this_cu
->dwarf2_per_objfile
;
6975 /* Link this CU into read_in_chain. */
6976 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6977 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6978 /* The chain owns it now. */
6979 m_new_cu
.release ();
6983 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6984 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6985 assumed to have already done the lookup to find the DWO file).
6987 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6988 THIS_CU->is_debug_types, but nothing else.
6990 We fill in THIS_CU->length.
6992 THIS_CU->cu is always freed when done.
6993 This is done in order to not leave THIS_CU->cu in a state where we have
6994 to care whether it refers to the "main" CU or the DWO CU.
6996 When parent_cu is passed, it is used to provide a default value for
6997 str_offsets_base and addr_base from the parent. */
6999 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7000 struct dwarf2_cu
*parent_cu
,
7001 struct dwo_file
*dwo_file
)
7002 : die_reader_specs
{},
7005 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7006 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7007 struct dwarf2_section_info
*section
= this_cu
->section
;
7008 bfd
*abfd
= section
->get_bfd_owner ();
7009 struct dwarf2_section_info
*abbrev_section
;
7010 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7012 if (dwarf_die_debug
)
7013 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7014 this_cu
->is_debug_types
? "type" : "comp",
7015 sect_offset_str (this_cu
->sect_off
));
7017 gdb_assert (this_cu
->cu
== NULL
);
7019 abbrev_section
= (dwo_file
!= NULL
7020 ? &dwo_file
->sections
.abbrev
7021 : get_abbrev_section_for_cu (this_cu
));
7023 /* This is cheap if the section is already read in. */
7024 section
->read (objfile
);
7026 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7028 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7029 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7030 &m_new_cu
->header
, section
,
7031 abbrev_section
, info_ptr
,
7032 (this_cu
->is_debug_types
7034 : rcuh_kind::COMPILE
));
7036 if (parent_cu
!= nullptr)
7038 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7039 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7041 this_cu
->length
= m_new_cu
->header
.get_length ();
7043 /* Skip dummy compilation units. */
7044 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7045 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7051 m_abbrev_table_holder
7052 = abbrev_table::read (objfile
, abbrev_section
,
7053 m_new_cu
->header
.abbrev_sect_off
);
7055 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7056 m_abbrev_table_holder
.get ());
7057 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7061 /* Type Unit Groups.
7063 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7064 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7065 so that all types coming from the same compilation (.o file) are grouped
7066 together. A future step could be to put the types in the same symtab as
7067 the CU the types ultimately came from. */
7070 hash_type_unit_group (const void *item
)
7072 const struct type_unit_group
*tu_group
7073 = (const struct type_unit_group
*) item
;
7075 return hash_stmt_list_entry (&tu_group
->hash
);
7079 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7081 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7082 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7084 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7087 /* Allocate a hash table for type unit groups. */
7090 allocate_type_unit_groups_table (struct objfile
*objfile
)
7092 return htab_up (htab_create_alloc (3,
7093 hash_type_unit_group
,
7095 NULL
, xcalloc
, xfree
));
7098 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7099 partial symtabs. We combine several TUs per psymtab to not let the size
7100 of any one psymtab grow too big. */
7101 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7102 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7104 /* Helper routine for get_type_unit_group.
7105 Create the type_unit_group object used to hold one or more TUs. */
7107 static struct type_unit_group
*
7108 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7110 struct dwarf2_per_objfile
*dwarf2_per_objfile
7111 = cu
->per_cu
->dwarf2_per_objfile
;
7112 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7113 struct dwarf2_per_cu_data
*per_cu
;
7114 struct type_unit_group
*tu_group
;
7116 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7117 struct type_unit_group
);
7118 per_cu
= &tu_group
->per_cu
;
7119 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7121 if (dwarf2_per_objfile
->using_index
)
7123 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7124 struct dwarf2_per_cu_quick_data
);
7128 unsigned int line_offset
= to_underlying (line_offset_struct
);
7129 dwarf2_psymtab
*pst
;
7132 /* Give the symtab a useful name for debug purposes. */
7133 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7134 name
= string_printf ("<type_units_%d>",
7135 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7137 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7139 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7140 pst
->anonymous
= true;
7143 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7144 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7149 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7150 STMT_LIST is a DW_AT_stmt_list attribute. */
7152 static struct type_unit_group
*
7153 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7155 struct dwarf2_per_objfile
*dwarf2_per_objfile
7156 = cu
->per_cu
->dwarf2_per_objfile
;
7157 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7158 struct type_unit_group
*tu_group
;
7160 unsigned int line_offset
;
7161 struct type_unit_group type_unit_group_for_lookup
;
7163 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7165 dwarf2_per_objfile
->type_unit_groups
=
7166 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7169 /* Do we need to create a new group, or can we use an existing one? */
7173 line_offset
= DW_UNSND (stmt_list
);
7174 ++tu_stats
->nr_symtab_sharers
;
7178 /* Ugh, no stmt_list. Rare, but we have to handle it.
7179 We can do various things here like create one group per TU or
7180 spread them over multiple groups to split up the expansion work.
7181 To avoid worst case scenarios (too many groups or too large groups)
7182 we, umm, group them in bunches. */
7183 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7184 | (tu_stats
->nr_stmt_less_type_units
7185 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7186 ++tu_stats
->nr_stmt_less_type_units
;
7189 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7190 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7191 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7192 &type_unit_group_for_lookup
, INSERT
);
7195 tu_group
= (struct type_unit_group
*) *slot
;
7196 gdb_assert (tu_group
!= NULL
);
7200 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7201 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7203 ++tu_stats
->nr_symtabs
;
7209 /* Partial symbol tables. */
7211 /* Create a psymtab named NAME and assign it to PER_CU.
7213 The caller must fill in the following details:
7214 dirname, textlow, texthigh. */
7216 static dwarf2_psymtab
*
7217 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7219 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7220 dwarf2_psymtab
*pst
;
7222 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7224 pst
->psymtabs_addrmap_supported
= true;
7226 /* This is the glue that links PST into GDB's symbol API. */
7227 pst
->per_cu_data
= per_cu
;
7228 per_cu
->v
.psymtab
= pst
;
7233 /* DIE reader function for process_psymtab_comp_unit. */
7236 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7237 const gdb_byte
*info_ptr
,
7238 struct die_info
*comp_unit_die
,
7239 enum language pretend_language
)
7241 struct dwarf2_cu
*cu
= reader
->cu
;
7242 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7243 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7244 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7246 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7247 dwarf2_psymtab
*pst
;
7248 enum pc_bounds_kind cu_bounds_kind
;
7249 const char *filename
;
7251 gdb_assert (! per_cu
->is_debug_types
);
7253 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7255 /* Allocate a new partial symbol table structure. */
7256 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7257 static const char artificial
[] = "<artificial>";
7258 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7259 if (filename
== NULL
)
7261 else if (strcmp (filename
, artificial
) == 0)
7263 debug_filename
.reset (concat (artificial
, "@",
7264 sect_offset_str (per_cu
->sect_off
),
7266 filename
= debug_filename
.get ();
7269 pst
= create_partial_symtab (per_cu
, filename
);
7271 /* This must be done before calling dwarf2_build_include_psymtabs. */
7272 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7274 baseaddr
= objfile
->text_section_offset ();
7276 dwarf2_find_base_address (comp_unit_die
, cu
);
7278 /* Possibly set the default values of LOWPC and HIGHPC from
7280 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7281 &best_highpc
, cu
, pst
);
7282 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7285 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7288 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7290 /* Store the contiguous range if it is not empty; it can be
7291 empty for CUs with no code. */
7292 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7296 /* Check if comp unit has_children.
7297 If so, read the rest of the partial symbols from this comp unit.
7298 If not, there's no more debug_info for this comp unit. */
7299 if (comp_unit_die
->has_children
)
7301 struct partial_die_info
*first_die
;
7302 CORE_ADDR lowpc
, highpc
;
7304 lowpc
= ((CORE_ADDR
) -1);
7305 highpc
= ((CORE_ADDR
) 0);
7307 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7309 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7310 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7312 /* If we didn't find a lowpc, set it to highpc to avoid
7313 complaints from `maint check'. */
7314 if (lowpc
== ((CORE_ADDR
) -1))
7317 /* If the compilation unit didn't have an explicit address range,
7318 then use the information extracted from its child dies. */
7319 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7322 best_highpc
= highpc
;
7325 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7326 best_lowpc
+ baseaddr
)
7328 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7329 best_highpc
+ baseaddr
)
7332 end_psymtab_common (objfile
, pst
);
7334 if (!cu
->per_cu
->imported_symtabs_empty ())
7337 int len
= cu
->per_cu
->imported_symtabs_size ();
7339 /* Fill in 'dependencies' here; we fill in 'users' in a
7341 pst
->number_of_dependencies
= len
;
7343 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7344 for (i
= 0; i
< len
; ++i
)
7346 pst
->dependencies
[i
]
7347 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7350 cu
->per_cu
->imported_symtabs_free ();
7353 /* Get the list of files included in the current compilation unit,
7354 and build a psymtab for each of them. */
7355 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7357 if (dwarf_read_debug
)
7358 fprintf_unfiltered (gdb_stdlog
,
7359 "Psymtab for %s unit @%s: %s - %s"
7360 ", %d global, %d static syms\n",
7361 per_cu
->is_debug_types
? "type" : "comp",
7362 sect_offset_str (per_cu
->sect_off
),
7363 paddress (gdbarch
, pst
->text_low (objfile
)),
7364 paddress (gdbarch
, pst
->text_high (objfile
)),
7365 pst
->n_global_syms
, pst
->n_static_syms
);
7368 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7369 Process compilation unit THIS_CU for a psymtab. */
7372 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7373 bool want_partial_unit
,
7374 enum language pretend_language
)
7376 /* If this compilation unit was already read in, free the
7377 cached copy in order to read it in again. This is
7378 necessary because we skipped some symbols when we first
7379 read in the compilation unit (see load_partial_dies).
7380 This problem could be avoided, but the benefit is unclear. */
7381 if (this_cu
->cu
!= NULL
)
7382 free_one_cached_comp_unit (this_cu
);
7384 cutu_reader
reader (this_cu
, NULL
, 0, false);
7390 else if (this_cu
->is_debug_types
)
7391 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7392 reader
.comp_unit_die
);
7393 else if (want_partial_unit
7394 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7395 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7396 reader
.comp_unit_die
,
7399 /* Age out any secondary CUs. */
7400 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7403 /* Reader function for build_type_psymtabs. */
7406 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7407 const gdb_byte
*info_ptr
,
7408 struct die_info
*type_unit_die
)
7410 struct dwarf2_per_objfile
*dwarf2_per_objfile
7411 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7412 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7413 struct dwarf2_cu
*cu
= reader
->cu
;
7414 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7415 struct signatured_type
*sig_type
;
7416 struct type_unit_group
*tu_group
;
7417 struct attribute
*attr
;
7418 struct partial_die_info
*first_die
;
7419 CORE_ADDR lowpc
, highpc
;
7420 dwarf2_psymtab
*pst
;
7422 gdb_assert (per_cu
->is_debug_types
);
7423 sig_type
= (struct signatured_type
*) per_cu
;
7425 if (! type_unit_die
->has_children
)
7428 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7429 tu_group
= get_type_unit_group (cu
, attr
);
7431 if (tu_group
->tus
== nullptr)
7432 tu_group
->tus
= new std::vector
<signatured_type
*>;
7433 tu_group
->tus
->push_back (sig_type
);
7435 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7436 pst
= create_partial_symtab (per_cu
, "");
7437 pst
->anonymous
= true;
7439 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7441 lowpc
= (CORE_ADDR
) -1;
7442 highpc
= (CORE_ADDR
) 0;
7443 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7445 end_psymtab_common (objfile
, pst
);
7448 /* Struct used to sort TUs by their abbreviation table offset. */
7450 struct tu_abbrev_offset
7452 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7453 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7456 signatured_type
*sig_type
;
7457 sect_offset abbrev_offset
;
7460 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7463 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7464 const struct tu_abbrev_offset
&b
)
7466 return a
.abbrev_offset
< b
.abbrev_offset
;
7469 /* Efficiently read all the type units.
7470 This does the bulk of the work for build_type_psymtabs.
7472 The efficiency is because we sort TUs by the abbrev table they use and
7473 only read each abbrev table once. In one program there are 200K TUs
7474 sharing 8K abbrev tables.
7476 The main purpose of this function is to support building the
7477 dwarf2_per_objfile->type_unit_groups table.
7478 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7479 can collapse the search space by grouping them by stmt_list.
7480 The savings can be significant, in the same program from above the 200K TUs
7481 share 8K stmt_list tables.
7483 FUNC is expected to call get_type_unit_group, which will create the
7484 struct type_unit_group if necessary and add it to
7485 dwarf2_per_objfile->type_unit_groups. */
7488 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7490 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7491 abbrev_table_up abbrev_table
;
7492 sect_offset abbrev_offset
;
7494 /* It's up to the caller to not call us multiple times. */
7495 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7497 if (dwarf2_per_objfile
->all_type_units
.empty ())
7500 /* TUs typically share abbrev tables, and there can be way more TUs than
7501 abbrev tables. Sort by abbrev table to reduce the number of times we
7502 read each abbrev table in.
7503 Alternatives are to punt or to maintain a cache of abbrev tables.
7504 This is simpler and efficient enough for now.
7506 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7507 symtab to use). Typically TUs with the same abbrev offset have the same
7508 stmt_list value too so in practice this should work well.
7510 The basic algorithm here is:
7512 sort TUs by abbrev table
7513 for each TU with same abbrev table:
7514 read abbrev table if first user
7515 read TU top level DIE
7516 [IWBN if DWO skeletons had DW_AT_stmt_list]
7519 if (dwarf_read_debug
)
7520 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7522 /* Sort in a separate table to maintain the order of all_type_units
7523 for .gdb_index: TU indices directly index all_type_units. */
7524 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7525 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7527 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7528 sorted_by_abbrev
.emplace_back
7529 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7530 sig_type
->per_cu
.section
,
7531 sig_type
->per_cu
.sect_off
));
7533 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7534 sort_tu_by_abbrev_offset
);
7536 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7538 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7540 /* Switch to the next abbrev table if necessary. */
7541 if (abbrev_table
== NULL
7542 || tu
.abbrev_offset
!= abbrev_offset
)
7544 abbrev_offset
= tu
.abbrev_offset
;
7546 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7547 &dwarf2_per_objfile
->abbrev
,
7549 ++tu_stats
->nr_uniq_abbrev_tables
;
7552 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7554 if (!reader
.dummy_p
)
7555 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7556 reader
.comp_unit_die
);
7560 /* Print collected type unit statistics. */
7563 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7565 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7567 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7568 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7569 dwarf2_per_objfile
->all_type_units
.size ());
7570 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7571 tu_stats
->nr_uniq_abbrev_tables
);
7572 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7573 tu_stats
->nr_symtabs
);
7574 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7575 tu_stats
->nr_symtab_sharers
);
7576 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7577 tu_stats
->nr_stmt_less_type_units
);
7578 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7579 tu_stats
->nr_all_type_units_reallocs
);
7582 /* Traversal function for build_type_psymtabs. */
7585 build_type_psymtab_dependencies (void **slot
, void *info
)
7587 struct dwarf2_per_objfile
*dwarf2_per_objfile
7588 = (struct dwarf2_per_objfile
*) info
;
7589 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7590 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7591 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7592 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7593 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7596 gdb_assert (len
> 0);
7597 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
7599 pst
->number_of_dependencies
= len
;
7600 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7601 for (i
= 0; i
< len
; ++i
)
7603 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7604 gdb_assert (iter
->per_cu
.is_debug_types
);
7605 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7606 iter
->type_unit_group
= tu_group
;
7609 delete tu_group
->tus
;
7610 tu_group
->tus
= nullptr;
7615 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7616 Build partial symbol tables for the .debug_types comp-units. */
7619 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7621 if (! create_all_type_units (dwarf2_per_objfile
))
7624 build_type_psymtabs_1 (dwarf2_per_objfile
);
7627 /* Traversal function for process_skeletonless_type_unit.
7628 Read a TU in a DWO file and build partial symbols for it. */
7631 process_skeletonless_type_unit (void **slot
, void *info
)
7633 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7634 struct dwarf2_per_objfile
*dwarf2_per_objfile
7635 = (struct dwarf2_per_objfile
*) info
;
7636 struct signatured_type find_entry
, *entry
;
7638 /* If this TU doesn't exist in the global table, add it and read it in. */
7640 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7642 dwarf2_per_objfile
->signatured_types
7643 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
7646 find_entry
.signature
= dwo_unit
->signature
;
7647 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7648 &find_entry
, INSERT
);
7649 /* If we've already seen this type there's nothing to do. What's happening
7650 is we're doing our own version of comdat-folding here. */
7654 /* This does the job that create_all_type_units would have done for
7656 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7657 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7660 /* This does the job that build_type_psymtabs_1 would have done. */
7661 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7662 if (!reader
.dummy_p
)
7663 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7664 reader
.comp_unit_die
);
7669 /* Traversal function for process_skeletonless_type_units. */
7672 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7674 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7676 if (dwo_file
->tus
!= NULL
)
7677 htab_traverse_noresize (dwo_file
->tus
.get (),
7678 process_skeletonless_type_unit
, info
);
7683 /* Scan all TUs of DWO files, verifying we've processed them.
7684 This is needed in case a TU was emitted without its skeleton.
7685 Note: This can't be done until we know what all the DWO files are. */
7688 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7690 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7691 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7692 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7694 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7695 process_dwo_file_for_skeletonless_type_units
,
7696 dwarf2_per_objfile
);
7700 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7703 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7705 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7707 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7712 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7714 /* Set the 'user' field only if it is not already set. */
7715 if (pst
->dependencies
[j
]->user
== NULL
)
7716 pst
->dependencies
[j
]->user
= pst
;
7721 /* Build the partial symbol table by doing a quick pass through the
7722 .debug_info and .debug_abbrev sections. */
7725 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7727 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7729 if (dwarf_read_debug
)
7731 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7732 objfile_name (objfile
));
7735 dwarf2_per_objfile
->reading_partial_symbols
= 1;
7737 dwarf2_per_objfile
->info
.read (objfile
);
7739 /* Any cached compilation units will be linked by the per-objfile
7740 read_in_chain. Make sure to free them when we're done. */
7741 free_cached_comp_units
freer (dwarf2_per_objfile
);
7743 build_type_psymtabs (dwarf2_per_objfile
);
7745 create_all_comp_units (dwarf2_per_objfile
);
7747 /* Create a temporary address map on a temporary obstack. We later
7748 copy this to the final obstack. */
7749 auto_obstack temp_obstack
;
7751 scoped_restore save_psymtabs_addrmap
7752 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7753 addrmap_create_mutable (&temp_obstack
));
7755 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7756 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7758 /* This has to wait until we read the CUs, we need the list of DWOs. */
7759 process_skeletonless_type_units (dwarf2_per_objfile
);
7761 /* Now that all TUs have been processed we can fill in the dependencies. */
7762 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7764 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7765 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7768 if (dwarf_read_debug
)
7769 print_tu_stats (dwarf2_per_objfile
);
7771 set_partial_user (dwarf2_per_objfile
);
7773 objfile
->partial_symtabs
->psymtabs_addrmap
7774 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7775 objfile
->partial_symtabs
->obstack ());
7776 /* At this point we want to keep the address map. */
7777 save_psymtabs_addrmap
.release ();
7779 if (dwarf_read_debug
)
7780 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7781 objfile_name (objfile
));
7784 /* Load the partial DIEs for a secondary CU into memory.
7785 This is also used when rereading a primary CU with load_all_dies. */
7788 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7790 cutu_reader
reader (this_cu
, NULL
, 1, false);
7792 if (!reader
.dummy_p
)
7794 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7797 /* Check if comp unit has_children.
7798 If so, read the rest of the partial symbols from this comp unit.
7799 If not, there's no more debug_info for this comp unit. */
7800 if (reader
.comp_unit_die
->has_children
)
7801 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7808 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7809 struct dwarf2_section_info
*section
,
7810 struct dwarf2_section_info
*abbrev_section
,
7811 unsigned int is_dwz
)
7813 const gdb_byte
*info_ptr
;
7814 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7816 if (dwarf_read_debug
)
7817 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7818 section
->get_name (),
7819 section
->get_file_name ());
7821 section
->read (objfile
);
7823 info_ptr
= section
->buffer
;
7825 while (info_ptr
< section
->buffer
+ section
->size
)
7827 struct dwarf2_per_cu_data
*this_cu
;
7829 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7831 comp_unit_head cu_header
;
7832 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7833 abbrev_section
, info_ptr
,
7834 rcuh_kind::COMPILE
);
7836 /* Save the compilation unit for later lookup. */
7837 if (cu_header
.unit_type
!= DW_UT_type
)
7839 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7840 struct dwarf2_per_cu_data
);
7841 memset (this_cu
, 0, sizeof (*this_cu
));
7845 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7846 struct signatured_type
);
7847 memset (sig_type
, 0, sizeof (*sig_type
));
7848 sig_type
->signature
= cu_header
.signature
;
7849 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7850 this_cu
= &sig_type
->per_cu
;
7852 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7853 this_cu
->sect_off
= sect_off
;
7854 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7855 this_cu
->is_dwz
= is_dwz
;
7856 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7857 this_cu
->section
= section
;
7859 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7861 info_ptr
= info_ptr
+ this_cu
->length
;
7865 /* Create a list of all compilation units in OBJFILE.
7866 This is only done for -readnow and building partial symtabs. */
7869 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7871 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7872 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7873 &dwarf2_per_objfile
->abbrev
, 0);
7875 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7877 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7881 /* Process all loaded DIEs for compilation unit CU, starting at
7882 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7883 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7884 DW_AT_ranges). See the comments of add_partial_subprogram on how
7885 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7888 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7889 CORE_ADDR
*highpc
, int set_addrmap
,
7890 struct dwarf2_cu
*cu
)
7892 struct partial_die_info
*pdi
;
7894 /* Now, march along the PDI's, descending into ones which have
7895 interesting children but skipping the children of the other ones,
7896 until we reach the end of the compilation unit. */
7904 /* Anonymous namespaces or modules have no name but have interesting
7905 children, so we need to look at them. Ditto for anonymous
7908 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7909 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7910 || pdi
->tag
== DW_TAG_imported_unit
7911 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7915 case DW_TAG_subprogram
:
7916 case DW_TAG_inlined_subroutine
:
7917 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7919 case DW_TAG_constant
:
7920 case DW_TAG_variable
:
7921 case DW_TAG_typedef
:
7922 case DW_TAG_union_type
:
7923 if (!pdi
->is_declaration
)
7925 add_partial_symbol (pdi
, cu
);
7928 case DW_TAG_class_type
:
7929 case DW_TAG_interface_type
:
7930 case DW_TAG_structure_type
:
7931 if (!pdi
->is_declaration
)
7933 add_partial_symbol (pdi
, cu
);
7935 if ((cu
->language
== language_rust
7936 || cu
->language
== language_cplus
) && pdi
->has_children
)
7937 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7940 case DW_TAG_enumeration_type
:
7941 if (!pdi
->is_declaration
)
7942 add_partial_enumeration (pdi
, cu
);
7944 case DW_TAG_base_type
:
7945 case DW_TAG_subrange_type
:
7946 /* File scope base type definitions are added to the partial
7948 add_partial_symbol (pdi
, cu
);
7950 case DW_TAG_namespace
:
7951 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7954 if (!pdi
->is_declaration
)
7955 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7957 case DW_TAG_imported_unit
:
7959 struct dwarf2_per_cu_data
*per_cu
;
7961 /* For now we don't handle imported units in type units. */
7962 if (cu
->per_cu
->is_debug_types
)
7964 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7965 " supported in type units [in module %s]"),
7966 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7969 per_cu
= dwarf2_find_containing_comp_unit
7970 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7971 cu
->per_cu
->dwarf2_per_objfile
);
7973 /* Go read the partial unit, if needed. */
7974 if (per_cu
->v
.psymtab
== NULL
)
7975 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7977 cu
->per_cu
->imported_symtabs_push (per_cu
);
7980 case DW_TAG_imported_declaration
:
7981 add_partial_symbol (pdi
, cu
);
7988 /* If the die has a sibling, skip to the sibling. */
7990 pdi
= pdi
->die_sibling
;
7994 /* Functions used to compute the fully scoped name of a partial DIE.
7996 Normally, this is simple. For C++, the parent DIE's fully scoped
7997 name is concatenated with "::" and the partial DIE's name.
7998 Enumerators are an exception; they use the scope of their parent
7999 enumeration type, i.e. the name of the enumeration type is not
8000 prepended to the enumerator.
8002 There are two complexities. One is DW_AT_specification; in this
8003 case "parent" means the parent of the target of the specification,
8004 instead of the direct parent of the DIE. The other is compilers
8005 which do not emit DW_TAG_namespace; in this case we try to guess
8006 the fully qualified name of structure types from their members'
8007 linkage names. This must be done using the DIE's children rather
8008 than the children of any DW_AT_specification target. We only need
8009 to do this for structures at the top level, i.e. if the target of
8010 any DW_AT_specification (if any; otherwise the DIE itself) does not
8013 /* Compute the scope prefix associated with PDI's parent, in
8014 compilation unit CU. The result will be allocated on CU's
8015 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8016 field. NULL is returned if no prefix is necessary. */
8018 partial_die_parent_scope (struct partial_die_info
*pdi
,
8019 struct dwarf2_cu
*cu
)
8021 const char *grandparent_scope
;
8022 struct partial_die_info
*parent
, *real_pdi
;
8024 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8025 then this means the parent of the specification DIE. */
8028 while (real_pdi
->has_specification
)
8030 auto res
= find_partial_die (real_pdi
->spec_offset
,
8031 real_pdi
->spec_is_dwz
, cu
);
8036 parent
= real_pdi
->die_parent
;
8040 if (parent
->scope_set
)
8041 return parent
->scope
;
8045 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8047 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8048 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8049 Work around this problem here. */
8050 if (cu
->language
== language_cplus
8051 && parent
->tag
== DW_TAG_namespace
8052 && strcmp (parent
->name
, "::") == 0
8053 && grandparent_scope
== NULL
)
8055 parent
->scope
= NULL
;
8056 parent
->scope_set
= 1;
8060 /* Nested subroutines in Fortran get a prefix. */
8061 if (pdi
->tag
== DW_TAG_enumerator
)
8062 /* Enumerators should not get the name of the enumeration as a prefix. */
8063 parent
->scope
= grandparent_scope
;
8064 else if (parent
->tag
== DW_TAG_namespace
8065 || parent
->tag
== DW_TAG_module
8066 || parent
->tag
== DW_TAG_structure_type
8067 || parent
->tag
== DW_TAG_class_type
8068 || parent
->tag
== DW_TAG_interface_type
8069 || parent
->tag
== DW_TAG_union_type
8070 || parent
->tag
== DW_TAG_enumeration_type
8071 || (cu
->language
== language_fortran
8072 && parent
->tag
== DW_TAG_subprogram
8073 && pdi
->tag
== DW_TAG_subprogram
))
8075 if (grandparent_scope
== NULL
)
8076 parent
->scope
= parent
->name
;
8078 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8080 parent
->name
, 0, cu
);
8084 /* FIXME drow/2004-04-01: What should we be doing with
8085 function-local names? For partial symbols, we should probably be
8087 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8088 dwarf_tag_name (parent
->tag
),
8089 sect_offset_str (pdi
->sect_off
));
8090 parent
->scope
= grandparent_scope
;
8093 parent
->scope_set
= 1;
8094 return parent
->scope
;
8097 /* Return the fully scoped name associated with PDI, from compilation unit
8098 CU. The result will be allocated with malloc. */
8100 static gdb::unique_xmalloc_ptr
<char>
8101 partial_die_full_name (struct partial_die_info
*pdi
,
8102 struct dwarf2_cu
*cu
)
8104 const char *parent_scope
;
8106 /* If this is a template instantiation, we can not work out the
8107 template arguments from partial DIEs. So, unfortunately, we have
8108 to go through the full DIEs. At least any work we do building
8109 types here will be reused if full symbols are loaded later. */
8110 if (pdi
->has_template_arguments
)
8114 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8116 struct die_info
*die
;
8117 struct attribute attr
;
8118 struct dwarf2_cu
*ref_cu
= cu
;
8120 /* DW_FORM_ref_addr is using section offset. */
8121 attr
.name
= (enum dwarf_attribute
) 0;
8122 attr
.form
= DW_FORM_ref_addr
;
8123 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8124 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8126 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8130 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8131 if (parent_scope
== NULL
)
8134 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8139 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8141 struct dwarf2_per_objfile
*dwarf2_per_objfile
8142 = cu
->per_cu
->dwarf2_per_objfile
;
8143 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8144 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8146 const char *actual_name
= NULL
;
8149 baseaddr
= objfile
->text_section_offset ();
8151 gdb::unique_xmalloc_ptr
<char> built_actual_name
8152 = partial_die_full_name (pdi
, cu
);
8153 if (built_actual_name
!= NULL
)
8154 actual_name
= built_actual_name
.get ();
8156 if (actual_name
== NULL
)
8157 actual_name
= pdi
->name
;
8161 case DW_TAG_inlined_subroutine
:
8162 case DW_TAG_subprogram
:
8163 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8165 if (pdi
->is_external
8166 || cu
->language
== language_ada
8167 || (cu
->language
== language_fortran
8168 && pdi
->die_parent
!= NULL
8169 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8171 /* Normally, only "external" DIEs are part of the global scope.
8172 But in Ada and Fortran, we want to be able to access nested
8173 procedures globally. So all Ada and Fortran subprograms are
8174 stored in the global scope. */
8175 add_psymbol_to_list (actual_name
,
8176 built_actual_name
!= NULL
,
8177 VAR_DOMAIN
, LOC_BLOCK
,
8178 SECT_OFF_TEXT (objfile
),
8179 psymbol_placement::GLOBAL
,
8181 cu
->language
, objfile
);
8185 add_psymbol_to_list (actual_name
,
8186 built_actual_name
!= NULL
,
8187 VAR_DOMAIN
, LOC_BLOCK
,
8188 SECT_OFF_TEXT (objfile
),
8189 psymbol_placement::STATIC
,
8190 addr
, cu
->language
, objfile
);
8193 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8194 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8196 case DW_TAG_constant
:
8197 add_psymbol_to_list (actual_name
,
8198 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8199 -1, (pdi
->is_external
8200 ? psymbol_placement::GLOBAL
8201 : psymbol_placement::STATIC
),
8202 0, cu
->language
, objfile
);
8204 case DW_TAG_variable
:
8206 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8210 && !dwarf2_per_objfile
->has_section_at_zero
)
8212 /* A global or static variable may also have been stripped
8213 out by the linker if unused, in which case its address
8214 will be nullified; do not add such variables into partial
8215 symbol table then. */
8217 else if (pdi
->is_external
)
8220 Don't enter into the minimal symbol tables as there is
8221 a minimal symbol table entry from the ELF symbols already.
8222 Enter into partial symbol table if it has a location
8223 descriptor or a type.
8224 If the location descriptor is missing, new_symbol will create
8225 a LOC_UNRESOLVED symbol, the address of the variable will then
8226 be determined from the minimal symbol table whenever the variable
8228 The address for the partial symbol table entry is not
8229 used by GDB, but it comes in handy for debugging partial symbol
8232 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8233 add_psymbol_to_list (actual_name
,
8234 built_actual_name
!= NULL
,
8235 VAR_DOMAIN
, LOC_STATIC
,
8236 SECT_OFF_TEXT (objfile
),
8237 psymbol_placement::GLOBAL
,
8238 addr
, cu
->language
, objfile
);
8242 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8244 /* Static Variable. Skip symbols whose value we cannot know (those
8245 without location descriptors or constant values). */
8246 if (!has_loc
&& !pdi
->has_const_value
)
8249 add_psymbol_to_list (actual_name
,
8250 built_actual_name
!= NULL
,
8251 VAR_DOMAIN
, LOC_STATIC
,
8252 SECT_OFF_TEXT (objfile
),
8253 psymbol_placement::STATIC
,
8255 cu
->language
, objfile
);
8258 case DW_TAG_typedef
:
8259 case DW_TAG_base_type
:
8260 case DW_TAG_subrange_type
:
8261 add_psymbol_to_list (actual_name
,
8262 built_actual_name
!= NULL
,
8263 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8264 psymbol_placement::STATIC
,
8265 0, cu
->language
, objfile
);
8267 case DW_TAG_imported_declaration
:
8268 case DW_TAG_namespace
:
8269 add_psymbol_to_list (actual_name
,
8270 built_actual_name
!= NULL
,
8271 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8272 psymbol_placement::GLOBAL
,
8273 0, cu
->language
, objfile
);
8276 /* With Fortran 77 there might be a "BLOCK DATA" module
8277 available without any name. If so, we skip the module as it
8278 doesn't bring any value. */
8279 if (actual_name
!= nullptr)
8280 add_psymbol_to_list (actual_name
,
8281 built_actual_name
!= NULL
,
8282 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8283 psymbol_placement::GLOBAL
,
8284 0, cu
->language
, objfile
);
8286 case DW_TAG_class_type
:
8287 case DW_TAG_interface_type
:
8288 case DW_TAG_structure_type
:
8289 case DW_TAG_union_type
:
8290 case DW_TAG_enumeration_type
:
8291 /* Skip external references. The DWARF standard says in the section
8292 about "Structure, Union, and Class Type Entries": "An incomplete
8293 structure, union or class type is represented by a structure,
8294 union or class entry that does not have a byte size attribute
8295 and that has a DW_AT_declaration attribute." */
8296 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8299 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8300 static vs. global. */
8301 add_psymbol_to_list (actual_name
,
8302 built_actual_name
!= NULL
,
8303 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8304 cu
->language
== language_cplus
8305 ? psymbol_placement::GLOBAL
8306 : psymbol_placement::STATIC
,
8307 0, cu
->language
, objfile
);
8310 case DW_TAG_enumerator
:
8311 add_psymbol_to_list (actual_name
,
8312 built_actual_name
!= NULL
,
8313 VAR_DOMAIN
, LOC_CONST
, -1,
8314 cu
->language
== language_cplus
8315 ? psymbol_placement::GLOBAL
8316 : psymbol_placement::STATIC
,
8317 0, cu
->language
, objfile
);
8324 /* Read a partial die corresponding to a namespace; also, add a symbol
8325 corresponding to that namespace to the symbol table. NAMESPACE is
8326 the name of the enclosing namespace. */
8329 add_partial_namespace (struct partial_die_info
*pdi
,
8330 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8331 int set_addrmap
, struct dwarf2_cu
*cu
)
8333 /* Add a symbol for the namespace. */
8335 add_partial_symbol (pdi
, cu
);
8337 /* Now scan partial symbols in that namespace. */
8339 if (pdi
->has_children
)
8340 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8343 /* Read a partial die corresponding to a Fortran module. */
8346 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8347 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8349 /* Add a symbol for the namespace. */
8351 add_partial_symbol (pdi
, cu
);
8353 /* Now scan partial symbols in that module. */
8355 if (pdi
->has_children
)
8356 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8359 /* Read a partial die corresponding to a subprogram or an inlined
8360 subprogram and create a partial symbol for that subprogram.
8361 When the CU language allows it, this routine also defines a partial
8362 symbol for each nested subprogram that this subprogram contains.
8363 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8364 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8366 PDI may also be a lexical block, in which case we simply search
8367 recursively for subprograms defined inside that lexical block.
8368 Again, this is only performed when the CU language allows this
8369 type of definitions. */
8372 add_partial_subprogram (struct partial_die_info
*pdi
,
8373 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8374 int set_addrmap
, struct dwarf2_cu
*cu
)
8376 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8378 if (pdi
->has_pc_info
)
8380 if (pdi
->lowpc
< *lowpc
)
8381 *lowpc
= pdi
->lowpc
;
8382 if (pdi
->highpc
> *highpc
)
8383 *highpc
= pdi
->highpc
;
8386 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8387 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8389 CORE_ADDR this_highpc
;
8390 CORE_ADDR this_lowpc
;
8392 baseaddr
= objfile
->text_section_offset ();
8394 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8395 pdi
->lowpc
+ baseaddr
)
8398 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8399 pdi
->highpc
+ baseaddr
)
8401 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8402 this_lowpc
, this_highpc
- 1,
8403 cu
->per_cu
->v
.psymtab
);
8407 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8409 if (!pdi
->is_declaration
)
8410 /* Ignore subprogram DIEs that do not have a name, they are
8411 illegal. Do not emit a complaint at this point, we will
8412 do so when we convert this psymtab into a symtab. */
8414 add_partial_symbol (pdi
, cu
);
8418 if (! pdi
->has_children
)
8421 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8423 pdi
= pdi
->die_child
;
8427 if (pdi
->tag
== DW_TAG_subprogram
8428 || pdi
->tag
== DW_TAG_inlined_subroutine
8429 || pdi
->tag
== DW_TAG_lexical_block
)
8430 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8431 pdi
= pdi
->die_sibling
;
8436 /* Read a partial die corresponding to an enumeration type. */
8439 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8440 struct dwarf2_cu
*cu
)
8442 struct partial_die_info
*pdi
;
8444 if (enum_pdi
->name
!= NULL
)
8445 add_partial_symbol (enum_pdi
, cu
);
8447 pdi
= enum_pdi
->die_child
;
8450 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8451 complaint (_("malformed enumerator DIE ignored"));
8453 add_partial_symbol (pdi
, cu
);
8454 pdi
= pdi
->die_sibling
;
8458 /* Return the initial uleb128 in the die at INFO_PTR. */
8461 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8463 unsigned int bytes_read
;
8465 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8468 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8469 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8471 Return the corresponding abbrev, or NULL if the number is zero (indicating
8472 an empty DIE). In either case *BYTES_READ will be set to the length of
8473 the initial number. */
8475 static struct abbrev_info
*
8476 peek_die_abbrev (const die_reader_specs
&reader
,
8477 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8479 dwarf2_cu
*cu
= reader
.cu
;
8480 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8481 unsigned int abbrev_number
8482 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8484 if (abbrev_number
== 0)
8487 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8490 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8491 " at offset %s [in module %s]"),
8492 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8493 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8499 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8500 Returns a pointer to the end of a series of DIEs, terminated by an empty
8501 DIE. Any children of the skipped DIEs will also be skipped. */
8503 static const gdb_byte
*
8504 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8508 unsigned int bytes_read
;
8509 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8512 return info_ptr
+ bytes_read
;
8514 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8518 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8519 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8520 abbrev corresponding to that skipped uleb128 should be passed in
8521 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8524 static const gdb_byte
*
8525 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8526 struct abbrev_info
*abbrev
)
8528 unsigned int bytes_read
;
8529 struct attribute attr
;
8530 bfd
*abfd
= reader
->abfd
;
8531 struct dwarf2_cu
*cu
= reader
->cu
;
8532 const gdb_byte
*buffer
= reader
->buffer
;
8533 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8534 unsigned int form
, i
;
8536 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8538 /* The only abbrev we care about is DW_AT_sibling. */
8539 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8542 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8544 if (attr
.form
== DW_FORM_ref_addr
)
8545 complaint (_("ignoring absolute DW_AT_sibling"));
8548 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8549 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8551 if (sibling_ptr
< info_ptr
)
8552 complaint (_("DW_AT_sibling points backwards"));
8553 else if (sibling_ptr
> reader
->buffer_end
)
8554 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8560 /* If it isn't DW_AT_sibling, skip this attribute. */
8561 form
= abbrev
->attrs
[i
].form
;
8565 case DW_FORM_ref_addr
:
8566 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8567 and later it is offset sized. */
8568 if (cu
->header
.version
== 2)
8569 info_ptr
+= cu
->header
.addr_size
;
8571 info_ptr
+= cu
->header
.offset_size
;
8573 case DW_FORM_GNU_ref_alt
:
8574 info_ptr
+= cu
->header
.offset_size
;
8577 info_ptr
+= cu
->header
.addr_size
;
8585 case DW_FORM_flag_present
:
8586 case DW_FORM_implicit_const
:
8603 case DW_FORM_ref_sig8
:
8606 case DW_FORM_data16
:
8609 case DW_FORM_string
:
8610 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8611 info_ptr
+= bytes_read
;
8613 case DW_FORM_sec_offset
:
8615 case DW_FORM_GNU_strp_alt
:
8616 info_ptr
+= cu
->header
.offset_size
;
8618 case DW_FORM_exprloc
:
8620 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8621 info_ptr
+= bytes_read
;
8623 case DW_FORM_block1
:
8624 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8626 case DW_FORM_block2
:
8627 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8629 case DW_FORM_block4
:
8630 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8636 case DW_FORM_ref_udata
:
8637 case DW_FORM_GNU_addr_index
:
8638 case DW_FORM_GNU_str_index
:
8639 case DW_FORM_rnglistx
:
8640 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8642 case DW_FORM_indirect
:
8643 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8644 info_ptr
+= bytes_read
;
8645 /* We need to continue parsing from here, so just go back to
8647 goto skip_attribute
;
8650 error (_("Dwarf Error: Cannot handle %s "
8651 "in DWARF reader [in module %s]"),
8652 dwarf_form_name (form
),
8653 bfd_get_filename (abfd
));
8657 if (abbrev
->has_children
)
8658 return skip_children (reader
, info_ptr
);
8663 /* Locate ORIG_PDI's sibling.
8664 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8666 static const gdb_byte
*
8667 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8668 struct partial_die_info
*orig_pdi
,
8669 const gdb_byte
*info_ptr
)
8671 /* Do we know the sibling already? */
8673 if (orig_pdi
->sibling
)
8674 return orig_pdi
->sibling
;
8676 /* Are there any children to deal with? */
8678 if (!orig_pdi
->has_children
)
8681 /* Skip the children the long way. */
8683 return skip_children (reader
, info_ptr
);
8686 /* Expand this partial symbol table into a full symbol table. SELF is
8690 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8692 struct dwarf2_per_objfile
*dwarf2_per_objfile
8693 = get_dwarf2_per_objfile (objfile
);
8695 gdb_assert (!readin
);
8696 /* If this psymtab is constructed from a debug-only objfile, the
8697 has_section_at_zero flag will not necessarily be correct. We
8698 can get the correct value for this flag by looking at the data
8699 associated with the (presumably stripped) associated objfile. */
8700 if (objfile
->separate_debug_objfile_backlink
)
8702 struct dwarf2_per_objfile
*dpo_backlink
8703 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8705 dwarf2_per_objfile
->has_section_at_zero
8706 = dpo_backlink
->has_section_at_zero
;
8709 dwarf2_per_objfile
->reading_partial_symbols
= 0;
8711 expand_psymtab (objfile
);
8713 process_cu_includes (dwarf2_per_objfile
);
8716 /* Reading in full CUs. */
8718 /* Add PER_CU to the queue. */
8721 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8722 enum language pretend_language
)
8725 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8728 /* If PER_CU is not yet queued, add it to the queue.
8729 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8731 The result is non-zero if PER_CU was queued, otherwise the result is zero
8732 meaning either PER_CU is already queued or it is already loaded.
8734 N.B. There is an invariant here that if a CU is queued then it is loaded.
8735 The caller is required to load PER_CU if we return non-zero. */
8738 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8739 struct dwarf2_per_cu_data
*per_cu
,
8740 enum language pretend_language
)
8742 /* We may arrive here during partial symbol reading, if we need full
8743 DIEs to process an unusual case (e.g. template arguments). Do
8744 not queue PER_CU, just tell our caller to load its DIEs. */
8745 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8747 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8752 /* Mark the dependence relation so that we don't flush PER_CU
8754 if (dependent_cu
!= NULL
)
8755 dwarf2_add_dependence (dependent_cu
, per_cu
);
8757 /* If it's already on the queue, we have nothing to do. */
8761 /* If the compilation unit is already loaded, just mark it as
8763 if (per_cu
->cu
!= NULL
)
8765 per_cu
->cu
->last_used
= 0;
8769 /* Add it to the queue. */
8770 queue_comp_unit (per_cu
, pretend_language
);
8775 /* Process the queue. */
8778 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8780 if (dwarf_read_debug
)
8782 fprintf_unfiltered (gdb_stdlog
,
8783 "Expanding one or more symtabs of objfile %s ...\n",
8784 objfile_name (dwarf2_per_objfile
->objfile
));
8787 /* The queue starts out with one item, but following a DIE reference
8788 may load a new CU, adding it to the end of the queue. */
8789 while (!dwarf2_per_objfile
->queue
.empty ())
8791 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8793 if ((dwarf2_per_objfile
->using_index
8794 ? !item
.per_cu
->v
.quick
->compunit_symtab
8795 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8796 /* Skip dummy CUs. */
8797 && item
.per_cu
->cu
!= NULL
)
8799 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8800 unsigned int debug_print_threshold
;
8803 if (per_cu
->is_debug_types
)
8805 struct signatured_type
*sig_type
=
8806 (struct signatured_type
*) per_cu
;
8808 sprintf (buf
, "TU %s at offset %s",
8809 hex_string (sig_type
->signature
),
8810 sect_offset_str (per_cu
->sect_off
));
8811 /* There can be 100s of TUs.
8812 Only print them in verbose mode. */
8813 debug_print_threshold
= 2;
8817 sprintf (buf
, "CU at offset %s",
8818 sect_offset_str (per_cu
->sect_off
));
8819 debug_print_threshold
= 1;
8822 if (dwarf_read_debug
>= debug_print_threshold
)
8823 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8825 if (per_cu
->is_debug_types
)
8826 process_full_type_unit (per_cu
, item
.pretend_language
);
8828 process_full_comp_unit (per_cu
, item
.pretend_language
);
8830 if (dwarf_read_debug
>= debug_print_threshold
)
8831 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8834 item
.per_cu
->queued
= 0;
8835 dwarf2_per_objfile
->queue
.pop ();
8838 if (dwarf_read_debug
)
8840 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8841 objfile_name (dwarf2_per_objfile
->objfile
));
8845 /* Read in full symbols for PST, and anything it depends on. */
8848 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8850 struct dwarf2_per_cu_data
*per_cu
;
8855 read_dependencies (objfile
);
8857 per_cu
= per_cu_data
;
8861 /* It's an include file, no symbols to read for it.
8862 Everything is in the parent symtab. */
8867 dw2_do_instantiate_symtab (per_cu
, false);
8870 /* Trivial hash function for die_info: the hash value of a DIE
8871 is its offset in .debug_info for this objfile. */
8874 die_hash (const void *item
)
8876 const struct die_info
*die
= (const struct die_info
*) item
;
8878 return to_underlying (die
->sect_off
);
8881 /* Trivial comparison function for die_info structures: two DIEs
8882 are equal if they have the same offset. */
8885 die_eq (const void *item_lhs
, const void *item_rhs
)
8887 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8888 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8890 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8893 /* Load the DIEs associated with PER_CU into memory. */
8896 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8898 enum language pretend_language
)
8900 gdb_assert (! this_cu
->is_debug_types
);
8902 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8906 struct dwarf2_cu
*cu
= reader
.cu
;
8907 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8909 gdb_assert (cu
->die_hash
== NULL
);
8911 htab_create_alloc_ex (cu
->header
.length
/ 12,
8915 &cu
->comp_unit_obstack
,
8916 hashtab_obstack_allocate
,
8917 dummy_obstack_deallocate
);
8919 if (reader
.comp_unit_die
->has_children
)
8920 reader
.comp_unit_die
->child
8921 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8922 &info_ptr
, reader
.comp_unit_die
);
8923 cu
->dies
= reader
.comp_unit_die
;
8924 /* comp_unit_die is not stored in die_hash, no need. */
8926 /* We try not to read any attributes in this function, because not
8927 all CUs needed for references have been loaded yet, and symbol
8928 table processing isn't initialized. But we have to set the CU language,
8929 or we won't be able to build types correctly.
8930 Similarly, if we do not read the producer, we can not apply
8931 producer-specific interpretation. */
8932 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8937 /* Add a DIE to the delayed physname list. */
8940 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8941 const char *name
, struct die_info
*die
,
8942 struct dwarf2_cu
*cu
)
8944 struct delayed_method_info mi
;
8946 mi
.fnfield_index
= fnfield_index
;
8950 cu
->method_list
.push_back (mi
);
8953 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8954 "const" / "volatile". If so, decrements LEN by the length of the
8955 modifier and return true. Otherwise return false. */
8959 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8961 size_t mod_len
= sizeof (mod
) - 1;
8962 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8970 /* Compute the physnames of any methods on the CU's method list.
8972 The computation of method physnames is delayed in order to avoid the
8973 (bad) condition that one of the method's formal parameters is of an as yet
8977 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8979 /* Only C++ delays computing physnames. */
8980 if (cu
->method_list
.empty ())
8982 gdb_assert (cu
->language
== language_cplus
);
8984 for (const delayed_method_info
&mi
: cu
->method_list
)
8986 const char *physname
;
8987 struct fn_fieldlist
*fn_flp
8988 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8989 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8990 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8991 = physname
? physname
: "";
8993 /* Since there's no tag to indicate whether a method is a
8994 const/volatile overload, extract that information out of the
8996 if (physname
!= NULL
)
8998 size_t len
= strlen (physname
);
9002 if (physname
[len
] == ')') /* shortcut */
9004 else if (check_modifier (physname
, len
, " const"))
9005 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9006 else if (check_modifier (physname
, len
, " volatile"))
9007 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9014 /* The list is no longer needed. */
9015 cu
->method_list
.clear ();
9018 /* Go objects should be embedded in a DW_TAG_module DIE,
9019 and it's not clear if/how imported objects will appear.
9020 To keep Go support simple until that's worked out,
9021 go back through what we've read and create something usable.
9022 We could do this while processing each DIE, and feels kinda cleaner,
9023 but that way is more invasive.
9024 This is to, for example, allow the user to type "p var" or "b main"
9025 without having to specify the package name, and allow lookups
9026 of module.object to work in contexts that use the expression
9030 fixup_go_packaging (struct dwarf2_cu
*cu
)
9032 gdb::unique_xmalloc_ptr
<char> package_name
;
9033 struct pending
*list
;
9036 for (list
= *cu
->get_builder ()->get_global_symbols ();
9040 for (i
= 0; i
< list
->nsyms
; ++i
)
9042 struct symbol
*sym
= list
->symbol
[i
];
9044 if (sym
->language () == language_go
9045 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9047 gdb::unique_xmalloc_ptr
<char> this_package_name
9048 (go_symbol_package_name (sym
));
9050 if (this_package_name
== NULL
)
9052 if (package_name
== NULL
)
9053 package_name
= std::move (this_package_name
);
9056 struct objfile
*objfile
9057 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9058 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9059 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9060 (symbol_symtab (sym
) != NULL
9061 ? symtab_to_filename_for_display
9062 (symbol_symtab (sym
))
9063 : objfile_name (objfile
)),
9064 this_package_name
.get (), package_name
.get ());
9070 if (package_name
!= NULL
)
9072 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9073 const char *saved_package_name
9074 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9075 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9076 saved_package_name
);
9079 sym
= allocate_symbol (objfile
);
9080 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9081 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9082 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9083 e.g., "main" finds the "main" module and not C's main(). */
9084 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9085 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9086 SYMBOL_TYPE (sym
) = type
;
9088 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9092 /* Allocate a fully-qualified name consisting of the two parts on the
9096 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9098 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9101 /* A helper that allocates a struct discriminant_info to attach to a
9104 static struct discriminant_info
*
9105 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9108 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9109 gdb_assert (discriminant_index
== -1
9110 || (discriminant_index
>= 0
9111 && discriminant_index
< TYPE_NFIELDS (type
)));
9112 gdb_assert (default_index
== -1
9113 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9115 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9117 struct discriminant_info
*disc
9118 = ((struct discriminant_info
*)
9120 offsetof (struct discriminant_info
, discriminants
)
9121 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9122 disc
->default_index
= default_index
;
9123 disc
->discriminant_index
= discriminant_index
;
9125 struct dynamic_prop prop
;
9126 prop
.kind
= PROP_UNDEFINED
;
9127 prop
.data
.baton
= disc
;
9129 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9134 /* Some versions of rustc emitted enums in an unusual way.
9136 Ordinary enums were emitted as unions. The first element of each
9137 structure in the union was named "RUST$ENUM$DISR". This element
9138 held the discriminant.
9140 These versions of Rust also implemented the "non-zero"
9141 optimization. When the enum had two values, and one is empty and
9142 the other holds a pointer that cannot be zero, the pointer is used
9143 as the discriminant, with a zero value meaning the empty variant.
9144 Here, the union's first member is of the form
9145 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9146 where the fieldnos are the indices of the fields that should be
9147 traversed in order to find the field (which may be several fields deep)
9148 and the variantname is the name of the variant of the case when the
9151 This function recognizes whether TYPE is of one of these forms,
9152 and, if so, smashes it to be a variant type. */
9155 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9157 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9159 /* We don't need to deal with empty enums. */
9160 if (TYPE_NFIELDS (type
) == 0)
9163 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9164 if (TYPE_NFIELDS (type
) == 1
9165 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9167 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9169 /* Decode the field name to find the offset of the
9171 ULONGEST bit_offset
= 0;
9172 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9173 while (name
[0] >= '0' && name
[0] <= '9')
9176 unsigned long index
= strtoul (name
, &tail
, 10);
9179 || index
>= TYPE_NFIELDS (field_type
)
9180 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9181 != FIELD_LOC_KIND_BITPOS
))
9183 complaint (_("Could not parse Rust enum encoding string \"%s\""
9185 TYPE_FIELD_NAME (type
, 0),
9186 objfile_name (objfile
));
9191 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9192 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9195 /* Make a union to hold the variants. */
9196 struct type
*union_type
= alloc_type (objfile
);
9197 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9198 TYPE_NFIELDS (union_type
) = 3;
9199 TYPE_FIELDS (union_type
)
9200 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9201 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9202 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9204 /* Put the discriminant must at index 0. */
9205 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9206 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9207 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9208 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9210 /* The order of fields doesn't really matter, so put the real
9211 field at index 1 and the data-less field at index 2. */
9212 struct discriminant_info
*disc
9213 = alloc_discriminant_info (union_type
, 0, 1);
9214 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9215 TYPE_FIELD_NAME (union_type
, 1)
9216 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9217 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9218 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9219 TYPE_FIELD_NAME (union_type
, 1));
9221 const char *dataless_name
9222 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9224 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9226 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9227 /* NAME points into the original discriminant name, which
9228 already has the correct lifetime. */
9229 TYPE_FIELD_NAME (union_type
, 2) = name
;
9230 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9231 disc
->discriminants
[2] = 0;
9233 /* Smash this type to be a structure type. We have to do this
9234 because the type has already been recorded. */
9235 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9236 TYPE_NFIELDS (type
) = 1;
9238 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9240 /* Install the variant part. */
9241 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9242 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9243 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9245 /* A union with a single anonymous field is probably an old-style
9247 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9249 /* Smash this type to be a structure type. We have to do this
9250 because the type has already been recorded. */
9251 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9253 /* Make a union to hold the variants. */
9254 struct type
*union_type
= alloc_type (objfile
);
9255 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9256 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9257 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9258 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9259 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9261 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9262 const char *variant_name
9263 = rust_last_path_segment (TYPE_NAME (field_type
));
9264 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9265 TYPE_NAME (field_type
)
9266 = rust_fully_qualify (&objfile
->objfile_obstack
,
9267 TYPE_NAME (type
), variant_name
);
9269 /* Install the union in the outer struct type. */
9270 TYPE_NFIELDS (type
) = 1;
9272 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9273 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9274 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9275 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9277 alloc_discriminant_info (union_type
, -1, 0);
9281 struct type
*disr_type
= nullptr;
9282 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9284 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9286 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9288 /* All fields of a true enum will be structs. */
9291 else if (TYPE_NFIELDS (disr_type
) == 0)
9293 /* Could be data-less variant, so keep going. */
9294 disr_type
= nullptr;
9296 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9297 "RUST$ENUM$DISR") != 0)
9299 /* Not a Rust enum. */
9309 /* If we got here without a discriminant, then it's probably
9311 if (disr_type
== nullptr)
9314 /* Smash this type to be a structure type. We have to do this
9315 because the type has already been recorded. */
9316 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9318 /* Make a union to hold the variants. */
9319 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9320 struct type
*union_type
= alloc_type (objfile
);
9321 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9322 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9323 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9324 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9325 TYPE_FIELDS (union_type
)
9326 = (struct field
*) TYPE_ZALLOC (union_type
,
9327 (TYPE_NFIELDS (union_type
)
9328 * sizeof (struct field
)));
9330 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9331 TYPE_NFIELDS (type
) * sizeof (struct field
));
9333 /* Install the discriminant at index 0 in the union. */
9334 TYPE_FIELD (union_type
, 0) = *disr_field
;
9335 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9336 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9338 /* Install the union in the outer struct type. */
9339 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9340 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9341 TYPE_NFIELDS (type
) = 1;
9343 /* Set the size and offset of the union type. */
9344 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9346 /* We need a way to find the correct discriminant given a
9347 variant name. For convenience we build a map here. */
9348 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9349 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9350 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9352 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9355 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9356 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9360 int n_fields
= TYPE_NFIELDS (union_type
);
9361 struct discriminant_info
*disc
9362 = alloc_discriminant_info (union_type
, 0, -1);
9363 /* Skip the discriminant here. */
9364 for (int i
= 1; i
< n_fields
; ++i
)
9366 /* Find the final word in the name of this variant's type.
9367 That name can be used to look up the correct
9369 const char *variant_name
9370 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9373 auto iter
= discriminant_map
.find (variant_name
);
9374 if (iter
!= discriminant_map
.end ())
9375 disc
->discriminants
[i
] = iter
->second
;
9377 /* Remove the discriminant field, if it exists. */
9378 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9379 if (TYPE_NFIELDS (sub_type
) > 0)
9381 --TYPE_NFIELDS (sub_type
);
9382 ++TYPE_FIELDS (sub_type
);
9384 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9385 TYPE_NAME (sub_type
)
9386 = rust_fully_qualify (&objfile
->objfile_obstack
,
9387 TYPE_NAME (type
), variant_name
);
9392 /* Rewrite some Rust unions to be structures with variants parts. */
9395 rust_union_quirks (struct dwarf2_cu
*cu
)
9397 gdb_assert (cu
->language
== language_rust
);
9398 for (type
*type_
: cu
->rust_unions
)
9399 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9400 /* We don't need this any more. */
9401 cu
->rust_unions
.clear ();
9404 /* Return the symtab for PER_CU. This works properly regardless of
9405 whether we're using the index or psymtabs. */
9407 static struct compunit_symtab
*
9408 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9410 return (per_cu
->dwarf2_per_objfile
->using_index
9411 ? per_cu
->v
.quick
->compunit_symtab
9412 : per_cu
->v
.psymtab
->compunit_symtab
);
9415 /* A helper function for computing the list of all symbol tables
9416 included by PER_CU. */
9419 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9420 htab_t all_children
, htab_t all_type_symtabs
,
9421 struct dwarf2_per_cu_data
*per_cu
,
9422 struct compunit_symtab
*immediate_parent
)
9425 struct compunit_symtab
*cust
;
9427 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9430 /* This inclusion and its children have been processed. */
9435 /* Only add a CU if it has a symbol table. */
9436 cust
= get_compunit_symtab (per_cu
);
9439 /* If this is a type unit only add its symbol table if we haven't
9440 seen it yet (type unit per_cu's can share symtabs). */
9441 if (per_cu
->is_debug_types
)
9443 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9447 result
->push_back (cust
);
9448 if (cust
->user
== NULL
)
9449 cust
->user
= immediate_parent
;
9454 result
->push_back (cust
);
9455 if (cust
->user
== NULL
)
9456 cust
->user
= immediate_parent
;
9460 if (!per_cu
->imported_symtabs_empty ())
9461 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9463 recursively_compute_inclusions (result
, all_children
,
9464 all_type_symtabs
, ptr
, cust
);
9468 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9472 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9474 gdb_assert (! per_cu
->is_debug_types
);
9476 if (!per_cu
->imported_symtabs_empty ())
9479 std::vector
<compunit_symtab
*> result_symtabs
;
9480 htab_t all_children
, all_type_symtabs
;
9481 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9483 /* If we don't have a symtab, we can just skip this case. */
9487 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9488 NULL
, xcalloc
, xfree
);
9489 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9490 NULL
, xcalloc
, xfree
);
9492 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9494 recursively_compute_inclusions (&result_symtabs
, all_children
,
9495 all_type_symtabs
, ptr
, cust
);
9498 /* Now we have a transitive closure of all the included symtabs. */
9499 len
= result_symtabs
.size ();
9501 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9502 struct compunit_symtab
*, len
+ 1);
9503 memcpy (cust
->includes
, result_symtabs
.data (),
9504 len
* sizeof (compunit_symtab
*));
9505 cust
->includes
[len
] = NULL
;
9507 htab_delete (all_children
);
9508 htab_delete (all_type_symtabs
);
9512 /* Compute the 'includes' field for the symtabs of all the CUs we just
9516 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9518 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9520 if (! iter
->is_debug_types
)
9521 compute_compunit_symtab_includes (iter
);
9524 dwarf2_per_objfile
->just_read_cus
.clear ();
9527 /* Generate full symbol information for PER_CU, whose DIEs have
9528 already been loaded into memory. */
9531 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9532 enum language pretend_language
)
9534 struct dwarf2_cu
*cu
= per_cu
->cu
;
9535 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9536 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9537 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9538 CORE_ADDR lowpc
, highpc
;
9539 struct compunit_symtab
*cust
;
9541 struct block
*static_block
;
9544 baseaddr
= objfile
->text_section_offset ();
9546 /* Clear the list here in case something was left over. */
9547 cu
->method_list
.clear ();
9549 cu
->language
= pretend_language
;
9550 cu
->language_defn
= language_def (cu
->language
);
9552 /* Do line number decoding in read_file_scope () */
9553 process_die (cu
->dies
, cu
);
9555 /* For now fudge the Go package. */
9556 if (cu
->language
== language_go
)
9557 fixup_go_packaging (cu
);
9559 /* Now that we have processed all the DIEs in the CU, all the types
9560 should be complete, and it should now be safe to compute all of the
9562 compute_delayed_physnames (cu
);
9564 if (cu
->language
== language_rust
)
9565 rust_union_quirks (cu
);
9567 /* Some compilers don't define a DW_AT_high_pc attribute for the
9568 compilation unit. If the DW_AT_high_pc is missing, synthesize
9569 it, by scanning the DIE's below the compilation unit. */
9570 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9572 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9573 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9575 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9576 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9577 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9578 addrmap to help ensure it has an accurate map of pc values belonging to
9580 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9582 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9583 SECT_OFF_TEXT (objfile
),
9588 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9590 /* Set symtab language to language from DW_AT_language. If the
9591 compilation is from a C file generated by language preprocessors, do
9592 not set the language if it was already deduced by start_subfile. */
9593 if (!(cu
->language
== language_c
9594 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9595 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9597 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9598 produce DW_AT_location with location lists but it can be possibly
9599 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9600 there were bugs in prologue debug info, fixed later in GCC-4.5
9601 by "unwind info for epilogues" patch (which is not directly related).
9603 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9604 needed, it would be wrong due to missing DW_AT_producer there.
9606 Still one can confuse GDB by using non-standard GCC compilation
9607 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9609 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9610 cust
->locations_valid
= 1;
9612 if (gcc_4_minor
>= 5)
9613 cust
->epilogue_unwind_valid
= 1;
9615 cust
->call_site_htab
= cu
->call_site_htab
;
9618 if (dwarf2_per_objfile
->using_index
)
9619 per_cu
->v
.quick
->compunit_symtab
= cust
;
9622 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9623 pst
->compunit_symtab
= cust
;
9627 /* Push it for inclusion processing later. */
9628 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9630 /* Not needed any more. */
9631 cu
->reset_builder ();
9634 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9635 already been loaded into memory. */
9638 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9639 enum language pretend_language
)
9641 struct dwarf2_cu
*cu
= per_cu
->cu
;
9642 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9643 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9644 struct compunit_symtab
*cust
;
9645 struct signatured_type
*sig_type
;
9647 gdb_assert (per_cu
->is_debug_types
);
9648 sig_type
= (struct signatured_type
*) per_cu
;
9650 /* Clear the list here in case something was left over. */
9651 cu
->method_list
.clear ();
9653 cu
->language
= pretend_language
;
9654 cu
->language_defn
= language_def (cu
->language
);
9656 /* The symbol tables are set up in read_type_unit_scope. */
9657 process_die (cu
->dies
, cu
);
9659 /* For now fudge the Go package. */
9660 if (cu
->language
== language_go
)
9661 fixup_go_packaging (cu
);
9663 /* Now that we have processed all the DIEs in the CU, all the types
9664 should be complete, and it should now be safe to compute all of the
9666 compute_delayed_physnames (cu
);
9668 if (cu
->language
== language_rust
)
9669 rust_union_quirks (cu
);
9671 /* TUs share symbol tables.
9672 If this is the first TU to use this symtab, complete the construction
9673 of it with end_expandable_symtab. Otherwise, complete the addition of
9674 this TU's symbols to the existing symtab. */
9675 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9677 buildsym_compunit
*builder
= cu
->get_builder ();
9678 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9679 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9683 /* Set symtab language to language from DW_AT_language. If the
9684 compilation is from a C file generated by language preprocessors,
9685 do not set the language if it was already deduced by
9687 if (!(cu
->language
== language_c
9688 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9689 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9694 cu
->get_builder ()->augment_type_symtab ();
9695 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9698 if (dwarf2_per_objfile
->using_index
)
9699 per_cu
->v
.quick
->compunit_symtab
= cust
;
9702 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9703 pst
->compunit_symtab
= cust
;
9707 /* Not needed any more. */
9708 cu
->reset_builder ();
9711 /* Process an imported unit DIE. */
9714 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9716 struct attribute
*attr
;
9718 /* For now we don't handle imported units in type units. */
9719 if (cu
->per_cu
->is_debug_types
)
9721 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9722 " supported in type units [in module %s]"),
9723 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9726 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9729 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9730 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9731 dwarf2_per_cu_data
*per_cu
9732 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9733 cu
->per_cu
->dwarf2_per_objfile
);
9735 /* If necessary, add it to the queue and load its DIEs. */
9736 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9737 load_full_comp_unit (per_cu
, false, cu
->language
);
9739 cu
->per_cu
->imported_symtabs_push (per_cu
);
9743 /* RAII object that represents a process_die scope: i.e.,
9744 starts/finishes processing a DIE. */
9745 class process_die_scope
9748 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9749 : m_die (die
), m_cu (cu
)
9751 /* We should only be processing DIEs not already in process. */
9752 gdb_assert (!m_die
->in_process
);
9753 m_die
->in_process
= true;
9756 ~process_die_scope ()
9758 m_die
->in_process
= false;
9760 /* If we're done processing the DIE for the CU that owns the line
9761 header, we don't need the line header anymore. */
9762 if (m_cu
->line_header_die_owner
== m_die
)
9764 delete m_cu
->line_header
;
9765 m_cu
->line_header
= NULL
;
9766 m_cu
->line_header_die_owner
= NULL
;
9775 /* Process a die and its children. */
9778 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9780 process_die_scope
scope (die
, cu
);
9784 case DW_TAG_padding
:
9786 case DW_TAG_compile_unit
:
9787 case DW_TAG_partial_unit
:
9788 read_file_scope (die
, cu
);
9790 case DW_TAG_type_unit
:
9791 read_type_unit_scope (die
, cu
);
9793 case DW_TAG_subprogram
:
9794 /* Nested subprograms in Fortran get a prefix. */
9795 if (cu
->language
== language_fortran
9796 && die
->parent
!= NULL
9797 && die
->parent
->tag
== DW_TAG_subprogram
)
9798 cu
->processing_has_namespace_info
= true;
9800 case DW_TAG_inlined_subroutine
:
9801 read_func_scope (die
, cu
);
9803 case DW_TAG_lexical_block
:
9804 case DW_TAG_try_block
:
9805 case DW_TAG_catch_block
:
9806 read_lexical_block_scope (die
, cu
);
9808 case DW_TAG_call_site
:
9809 case DW_TAG_GNU_call_site
:
9810 read_call_site_scope (die
, cu
);
9812 case DW_TAG_class_type
:
9813 case DW_TAG_interface_type
:
9814 case DW_TAG_structure_type
:
9815 case DW_TAG_union_type
:
9816 process_structure_scope (die
, cu
);
9818 case DW_TAG_enumeration_type
:
9819 process_enumeration_scope (die
, cu
);
9822 /* These dies have a type, but processing them does not create
9823 a symbol or recurse to process the children. Therefore we can
9824 read them on-demand through read_type_die. */
9825 case DW_TAG_subroutine_type
:
9826 case DW_TAG_set_type
:
9827 case DW_TAG_array_type
:
9828 case DW_TAG_pointer_type
:
9829 case DW_TAG_ptr_to_member_type
:
9830 case DW_TAG_reference_type
:
9831 case DW_TAG_rvalue_reference_type
:
9832 case DW_TAG_string_type
:
9835 case DW_TAG_base_type
:
9836 case DW_TAG_subrange_type
:
9837 case DW_TAG_typedef
:
9838 /* Add a typedef symbol for the type definition, if it has a
9840 new_symbol (die
, read_type_die (die
, cu
), cu
);
9842 case DW_TAG_common_block
:
9843 read_common_block (die
, cu
);
9845 case DW_TAG_common_inclusion
:
9847 case DW_TAG_namespace
:
9848 cu
->processing_has_namespace_info
= true;
9849 read_namespace (die
, cu
);
9852 cu
->processing_has_namespace_info
= true;
9853 read_module (die
, cu
);
9855 case DW_TAG_imported_declaration
:
9856 cu
->processing_has_namespace_info
= true;
9857 if (read_namespace_alias (die
, cu
))
9859 /* The declaration is not a global namespace alias. */
9861 case DW_TAG_imported_module
:
9862 cu
->processing_has_namespace_info
= true;
9863 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9864 || cu
->language
!= language_fortran
))
9865 complaint (_("Tag '%s' has unexpected children"),
9866 dwarf_tag_name (die
->tag
));
9867 read_import_statement (die
, cu
);
9870 case DW_TAG_imported_unit
:
9871 process_imported_unit_die (die
, cu
);
9874 case DW_TAG_variable
:
9875 read_variable (die
, cu
);
9879 new_symbol (die
, NULL
, cu
);
9884 /* DWARF name computation. */
9886 /* A helper function for dwarf2_compute_name which determines whether DIE
9887 needs to have the name of the scope prepended to the name listed in the
9891 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9893 struct attribute
*attr
;
9897 case DW_TAG_namespace
:
9898 case DW_TAG_typedef
:
9899 case DW_TAG_class_type
:
9900 case DW_TAG_interface_type
:
9901 case DW_TAG_structure_type
:
9902 case DW_TAG_union_type
:
9903 case DW_TAG_enumeration_type
:
9904 case DW_TAG_enumerator
:
9905 case DW_TAG_subprogram
:
9906 case DW_TAG_inlined_subroutine
:
9908 case DW_TAG_imported_declaration
:
9911 case DW_TAG_variable
:
9912 case DW_TAG_constant
:
9913 /* We only need to prefix "globally" visible variables. These include
9914 any variable marked with DW_AT_external or any variable that
9915 lives in a namespace. [Variables in anonymous namespaces
9916 require prefixing, but they are not DW_AT_external.] */
9918 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9920 struct dwarf2_cu
*spec_cu
= cu
;
9922 return die_needs_namespace (die_specification (die
, &spec_cu
),
9926 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9927 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9928 && die
->parent
->tag
!= DW_TAG_module
)
9930 /* A variable in a lexical block of some kind does not need a
9931 namespace, even though in C++ such variables may be external
9932 and have a mangled name. */
9933 if (die
->parent
->tag
== DW_TAG_lexical_block
9934 || die
->parent
->tag
== DW_TAG_try_block
9935 || die
->parent
->tag
== DW_TAG_catch_block
9936 || die
->parent
->tag
== DW_TAG_subprogram
)
9945 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9946 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9947 defined for the given DIE. */
9949 static struct attribute
*
9950 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9952 struct attribute
*attr
;
9954 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9956 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9961 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9962 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9963 defined for the given DIE. */
9966 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9968 const char *linkage_name
;
9970 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9971 if (linkage_name
== NULL
)
9972 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9974 return linkage_name
;
9977 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9978 compute the physname for the object, which include a method's:
9979 - formal parameters (C++),
9980 - receiver type (Go),
9982 The term "physname" is a bit confusing.
9983 For C++, for example, it is the demangled name.
9984 For Go, for example, it's the mangled name.
9986 For Ada, return the DIE's linkage name rather than the fully qualified
9987 name. PHYSNAME is ignored..
9989 The result is allocated on the objfile_obstack and canonicalized. */
9992 dwarf2_compute_name (const char *name
,
9993 struct die_info
*die
, struct dwarf2_cu
*cu
,
9996 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9999 name
= dwarf2_name (die
, cu
);
10001 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10002 but otherwise compute it by typename_concat inside GDB.
10003 FIXME: Actually this is not really true, or at least not always true.
10004 It's all very confusing. compute_and_set_names doesn't try to demangle
10005 Fortran names because there is no mangling standard. So new_symbol
10006 will set the demangled name to the result of dwarf2_full_name, and it is
10007 the demangled name that GDB uses if it exists. */
10008 if (cu
->language
== language_ada
10009 || (cu
->language
== language_fortran
&& physname
))
10011 /* For Ada unit, we prefer the linkage name over the name, as
10012 the former contains the exported name, which the user expects
10013 to be able to reference. Ideally, we want the user to be able
10014 to reference this entity using either natural or linkage name,
10015 but we haven't started looking at this enhancement yet. */
10016 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10018 if (linkage_name
!= NULL
)
10019 return linkage_name
;
10022 /* These are the only languages we know how to qualify names in. */
10024 && (cu
->language
== language_cplus
10025 || cu
->language
== language_fortran
|| cu
->language
== language_d
10026 || cu
->language
== language_rust
))
10028 if (die_needs_namespace (die
, cu
))
10030 const char *prefix
;
10031 const char *canonical_name
= NULL
;
10035 prefix
= determine_prefix (die
, cu
);
10036 if (*prefix
!= '\0')
10038 gdb::unique_xmalloc_ptr
<char> prefixed_name
10039 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10041 buf
.puts (prefixed_name
.get ());
10046 /* Template parameters may be specified in the DIE's DW_AT_name, or
10047 as children with DW_TAG_template_type_param or
10048 DW_TAG_value_type_param. If the latter, add them to the name
10049 here. If the name already has template parameters, then
10050 skip this step; some versions of GCC emit both, and
10051 it is more efficient to use the pre-computed name.
10053 Something to keep in mind about this process: it is very
10054 unlikely, or in some cases downright impossible, to produce
10055 something that will match the mangled name of a function.
10056 If the definition of the function has the same debug info,
10057 we should be able to match up with it anyway. But fallbacks
10058 using the minimal symbol, for instance to find a method
10059 implemented in a stripped copy of libstdc++, will not work.
10060 If we do not have debug info for the definition, we will have to
10061 match them up some other way.
10063 When we do name matching there is a related problem with function
10064 templates; two instantiated function templates are allowed to
10065 differ only by their return types, which we do not add here. */
10067 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10069 struct attribute
*attr
;
10070 struct die_info
*child
;
10073 die
->building_fullname
= 1;
10075 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10079 const gdb_byte
*bytes
;
10080 struct dwarf2_locexpr_baton
*baton
;
10083 if (child
->tag
!= DW_TAG_template_type_param
10084 && child
->tag
!= DW_TAG_template_value_param
)
10095 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10098 complaint (_("template parameter missing DW_AT_type"));
10099 buf
.puts ("UNKNOWN_TYPE");
10102 type
= die_type (child
, cu
);
10104 if (child
->tag
== DW_TAG_template_type_param
)
10106 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10107 &type_print_raw_options
);
10111 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10114 complaint (_("template parameter missing "
10115 "DW_AT_const_value"));
10116 buf
.puts ("UNKNOWN_VALUE");
10120 dwarf2_const_value_attr (attr
, type
, name
,
10121 &cu
->comp_unit_obstack
, cu
,
10122 &value
, &bytes
, &baton
);
10124 if (TYPE_NOSIGN (type
))
10125 /* GDB prints characters as NUMBER 'CHAR'. If that's
10126 changed, this can use value_print instead. */
10127 c_printchar (value
, type
, &buf
);
10130 struct value_print_options opts
;
10133 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10137 else if (bytes
!= NULL
)
10139 v
= allocate_value (type
);
10140 memcpy (value_contents_writeable (v
), bytes
,
10141 TYPE_LENGTH (type
));
10144 v
= value_from_longest (type
, value
);
10146 /* Specify decimal so that we do not depend on
10148 get_formatted_print_options (&opts
, 'd');
10150 value_print (v
, &buf
, &opts
);
10155 die
->building_fullname
= 0;
10159 /* Close the argument list, with a space if necessary
10160 (nested templates). */
10161 if (!buf
.empty () && buf
.string ().back () == '>')
10168 /* For C++ methods, append formal parameter type
10169 information, if PHYSNAME. */
10171 if (physname
&& die
->tag
== DW_TAG_subprogram
10172 && cu
->language
== language_cplus
)
10174 struct type
*type
= read_type_die (die
, cu
);
10176 c_type_print_args (type
, &buf
, 1, cu
->language
,
10177 &type_print_raw_options
);
10179 if (cu
->language
== language_cplus
)
10181 /* Assume that an artificial first parameter is
10182 "this", but do not crash if it is not. RealView
10183 marks unnamed (and thus unused) parameters as
10184 artificial; there is no way to differentiate
10186 if (TYPE_NFIELDS (type
) > 0
10187 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10188 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10189 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10191 buf
.puts (" const");
10195 const std::string
&intermediate_name
= buf
.string ();
10197 if (cu
->language
== language_cplus
)
10199 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10200 &objfile
->per_bfd
->storage_obstack
);
10202 /* If we only computed INTERMEDIATE_NAME, or if
10203 INTERMEDIATE_NAME is already canonical, then we need to
10204 copy it to the appropriate obstack. */
10205 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10206 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10207 intermediate_name
);
10209 name
= canonical_name
;
10216 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10217 If scope qualifiers are appropriate they will be added. The result
10218 will be allocated on the storage_obstack, or NULL if the DIE does
10219 not have a name. NAME may either be from a previous call to
10220 dwarf2_name or NULL.
10222 The output string will be canonicalized (if C++). */
10224 static const char *
10225 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10227 return dwarf2_compute_name (name
, die
, cu
, 0);
10230 /* Construct a physname for the given DIE in CU. NAME may either be
10231 from a previous call to dwarf2_name or NULL. The result will be
10232 allocated on the objfile_objstack or NULL if the DIE does not have a
10235 The output string will be canonicalized (if C++). */
10237 static const char *
10238 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10240 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10241 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10244 /* In this case dwarf2_compute_name is just a shortcut not building anything
10246 if (!die_needs_namespace (die
, cu
))
10247 return dwarf2_compute_name (name
, die
, cu
, 1);
10249 mangled
= dw2_linkage_name (die
, cu
);
10251 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10252 See https://github.com/rust-lang/rust/issues/32925. */
10253 if (cu
->language
== language_rust
&& mangled
!= NULL
10254 && strchr (mangled
, '{') != NULL
)
10257 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10259 gdb::unique_xmalloc_ptr
<char> demangled
;
10260 if (mangled
!= NULL
)
10263 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10265 /* Do nothing (do not demangle the symbol name). */
10267 else if (cu
->language
== language_go
)
10269 /* This is a lie, but we already lie to the caller new_symbol.
10270 new_symbol assumes we return the mangled name.
10271 This just undoes that lie until things are cleaned up. */
10275 /* Use DMGL_RET_DROP for C++ template functions to suppress
10276 their return type. It is easier for GDB users to search
10277 for such functions as `name(params)' than `long name(params)'.
10278 In such case the minimal symbol names do not match the full
10279 symbol names but for template functions there is never a need
10280 to look up their definition from their declaration so
10281 the only disadvantage remains the minimal symbol variant
10282 `long name(params)' does not have the proper inferior type. */
10283 demangled
.reset (gdb_demangle (mangled
,
10284 (DMGL_PARAMS
| DMGL_ANSI
10285 | DMGL_RET_DROP
)));
10288 canon
= demangled
.get ();
10296 if (canon
== NULL
|| check_physname
)
10298 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10300 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10302 /* It may not mean a bug in GDB. The compiler could also
10303 compute DW_AT_linkage_name incorrectly. But in such case
10304 GDB would need to be bug-to-bug compatible. */
10306 complaint (_("Computed physname <%s> does not match demangled <%s> "
10307 "(from linkage <%s>) - DIE at %s [in module %s]"),
10308 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10309 objfile_name (objfile
));
10311 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10312 is available here - over computed PHYSNAME. It is safer
10313 against both buggy GDB and buggy compilers. */
10327 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
10332 /* Inspect DIE in CU for a namespace alias. If one exists, record
10333 a new symbol for it.
10335 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10338 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10340 struct attribute
*attr
;
10342 /* If the die does not have a name, this is not a namespace
10344 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10348 struct die_info
*d
= die
;
10349 struct dwarf2_cu
*imported_cu
= cu
;
10351 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10352 keep inspecting DIEs until we hit the underlying import. */
10353 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10354 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10356 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10360 d
= follow_die_ref (d
, attr
, &imported_cu
);
10361 if (d
->tag
!= DW_TAG_imported_declaration
)
10365 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10367 complaint (_("DIE at %s has too many recursively imported "
10368 "declarations"), sect_offset_str (d
->sect_off
));
10375 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10377 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10378 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10380 /* This declaration is a global namespace alias. Add
10381 a symbol for it whose type is the aliased namespace. */
10382 new_symbol (die
, type
, cu
);
10391 /* Return the using directives repository (global or local?) to use in the
10392 current context for CU.
10394 For Ada, imported declarations can materialize renamings, which *may* be
10395 global. However it is impossible (for now?) in DWARF to distinguish
10396 "external" imported declarations and "static" ones. As all imported
10397 declarations seem to be static in all other languages, make them all CU-wide
10398 global only in Ada. */
10400 static struct using_direct
**
10401 using_directives (struct dwarf2_cu
*cu
)
10403 if (cu
->language
== language_ada
10404 && cu
->get_builder ()->outermost_context_p ())
10405 return cu
->get_builder ()->get_global_using_directives ();
10407 return cu
->get_builder ()->get_local_using_directives ();
10410 /* Read the import statement specified by the given die and record it. */
10413 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10415 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10416 struct attribute
*import_attr
;
10417 struct die_info
*imported_die
, *child_die
;
10418 struct dwarf2_cu
*imported_cu
;
10419 const char *imported_name
;
10420 const char *imported_name_prefix
;
10421 const char *canonical_name
;
10422 const char *import_alias
;
10423 const char *imported_declaration
= NULL
;
10424 const char *import_prefix
;
10425 std::vector
<const char *> excludes
;
10427 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10428 if (import_attr
== NULL
)
10430 complaint (_("Tag '%s' has no DW_AT_import"),
10431 dwarf_tag_name (die
->tag
));
10436 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10437 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10438 if (imported_name
== NULL
)
10440 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10442 The import in the following code:
10456 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10457 <52> DW_AT_decl_file : 1
10458 <53> DW_AT_decl_line : 6
10459 <54> DW_AT_import : <0x75>
10460 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10461 <59> DW_AT_name : B
10462 <5b> DW_AT_decl_file : 1
10463 <5c> DW_AT_decl_line : 2
10464 <5d> DW_AT_type : <0x6e>
10466 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10467 <76> DW_AT_byte_size : 4
10468 <77> DW_AT_encoding : 5 (signed)
10470 imports the wrong die ( 0x75 instead of 0x58 ).
10471 This case will be ignored until the gcc bug is fixed. */
10475 /* Figure out the local name after import. */
10476 import_alias
= dwarf2_name (die
, cu
);
10478 /* Figure out where the statement is being imported to. */
10479 import_prefix
= determine_prefix (die
, cu
);
10481 /* Figure out what the scope of the imported die is and prepend it
10482 to the name of the imported die. */
10483 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10485 if (imported_die
->tag
!= DW_TAG_namespace
10486 && imported_die
->tag
!= DW_TAG_module
)
10488 imported_declaration
= imported_name
;
10489 canonical_name
= imported_name_prefix
;
10491 else if (strlen (imported_name_prefix
) > 0)
10492 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10493 imported_name_prefix
,
10494 (cu
->language
== language_d
? "." : "::"),
10495 imported_name
, (char *) NULL
);
10497 canonical_name
= imported_name
;
10499 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10500 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10501 child_die
= sibling_die (child_die
))
10503 /* DWARF-4: A Fortran use statement with a “rename list” may be
10504 represented by an imported module entry with an import attribute
10505 referring to the module and owned entries corresponding to those
10506 entities that are renamed as part of being imported. */
10508 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10510 complaint (_("child DW_TAG_imported_declaration expected "
10511 "- DIE at %s [in module %s]"),
10512 sect_offset_str (child_die
->sect_off
),
10513 objfile_name (objfile
));
10517 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10518 if (import_attr
== NULL
)
10520 complaint (_("Tag '%s' has no DW_AT_import"),
10521 dwarf_tag_name (child_die
->tag
));
10526 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10528 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10529 if (imported_name
== NULL
)
10531 complaint (_("child DW_TAG_imported_declaration has unknown "
10532 "imported name - DIE at %s [in module %s]"),
10533 sect_offset_str (child_die
->sect_off
),
10534 objfile_name (objfile
));
10538 excludes
.push_back (imported_name
);
10540 process_die (child_die
, cu
);
10543 add_using_directive (using_directives (cu
),
10547 imported_declaration
,
10550 &objfile
->objfile_obstack
);
10553 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10554 types, but gives them a size of zero. Starting with version 14,
10555 ICC is compatible with GCC. */
10558 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10560 if (!cu
->checked_producer
)
10561 check_producer (cu
);
10563 return cu
->producer_is_icc_lt_14
;
10566 /* ICC generates a DW_AT_type for C void functions. This was observed on
10567 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10568 which says that void functions should not have a DW_AT_type. */
10571 producer_is_icc (struct dwarf2_cu
*cu
)
10573 if (!cu
->checked_producer
)
10574 check_producer (cu
);
10576 return cu
->producer_is_icc
;
10579 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10580 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10581 this, it was first present in GCC release 4.3.0. */
10584 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10586 if (!cu
->checked_producer
)
10587 check_producer (cu
);
10589 return cu
->producer_is_gcc_lt_4_3
;
10592 static file_and_directory
10593 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10595 file_and_directory res
;
10597 /* Find the filename. Do not use dwarf2_name here, since the filename
10598 is not a source language identifier. */
10599 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10600 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10602 if (res
.comp_dir
== NULL
10603 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10604 && IS_ABSOLUTE_PATH (res
.name
))
10606 res
.comp_dir_storage
= ldirname (res
.name
);
10607 if (!res
.comp_dir_storage
.empty ())
10608 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10610 if (res
.comp_dir
!= NULL
)
10612 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10613 directory, get rid of it. */
10614 const char *cp
= strchr (res
.comp_dir
, ':');
10616 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10617 res
.comp_dir
= cp
+ 1;
10620 if (res
.name
== NULL
)
10621 res
.name
= "<unknown>";
10626 /* Handle DW_AT_stmt_list for a compilation unit.
10627 DIE is the DW_TAG_compile_unit die for CU.
10628 COMP_DIR is the compilation directory. LOWPC is passed to
10629 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10632 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10633 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10635 struct dwarf2_per_objfile
*dwarf2_per_objfile
10636 = cu
->per_cu
->dwarf2_per_objfile
;
10637 struct attribute
*attr
;
10638 struct line_header line_header_local
;
10639 hashval_t line_header_local_hash
;
10641 int decode_mapping
;
10643 gdb_assert (! cu
->per_cu
->is_debug_types
);
10645 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10649 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10651 /* The line header hash table is only created if needed (it exists to
10652 prevent redundant reading of the line table for partial_units).
10653 If we're given a partial_unit, we'll need it. If we're given a
10654 compile_unit, then use the line header hash table if it's already
10655 created, but don't create one just yet. */
10657 if (dwarf2_per_objfile
->line_header_hash
== NULL
10658 && die
->tag
== DW_TAG_partial_unit
)
10660 dwarf2_per_objfile
->line_header_hash
10661 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10662 line_header_eq_voidp
,
10663 free_line_header_voidp
,
10667 line_header_local
.sect_off
= line_offset
;
10668 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10669 line_header_local_hash
= line_header_hash (&line_header_local
);
10670 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10672 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10673 &line_header_local
,
10674 line_header_local_hash
, NO_INSERT
);
10676 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10677 is not present in *SLOT (since if there is something in *SLOT then
10678 it will be for a partial_unit). */
10679 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10681 gdb_assert (*slot
!= NULL
);
10682 cu
->line_header
= (struct line_header
*) *slot
;
10687 /* dwarf_decode_line_header does not yet provide sufficient information.
10688 We always have to call also dwarf_decode_lines for it. */
10689 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10693 cu
->line_header
= lh
.release ();
10694 cu
->line_header_die_owner
= die
;
10696 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10700 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10701 &line_header_local
,
10702 line_header_local_hash
, INSERT
);
10703 gdb_assert (slot
!= NULL
);
10705 if (slot
!= NULL
&& *slot
== NULL
)
10707 /* This newly decoded line number information unit will be owned
10708 by line_header_hash hash table. */
10709 *slot
= cu
->line_header
;
10710 cu
->line_header_die_owner
= NULL
;
10714 /* We cannot free any current entry in (*slot) as that struct line_header
10715 may be already used by multiple CUs. Create only temporary decoded
10716 line_header for this CU - it may happen at most once for each line
10717 number information unit. And if we're not using line_header_hash
10718 then this is what we want as well. */
10719 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10721 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10722 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10727 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10730 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10732 struct dwarf2_per_objfile
*dwarf2_per_objfile
10733 = cu
->per_cu
->dwarf2_per_objfile
;
10734 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10735 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10736 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10737 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10738 struct attribute
*attr
;
10739 struct die_info
*child_die
;
10740 CORE_ADDR baseaddr
;
10742 prepare_one_comp_unit (cu
, die
, cu
->language
);
10743 baseaddr
= objfile
->text_section_offset ();
10745 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10747 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10748 from finish_block. */
10749 if (lowpc
== ((CORE_ADDR
) -1))
10751 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10753 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10755 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10756 standardised yet. As a workaround for the language detection we fall
10757 back to the DW_AT_producer string. */
10758 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10759 cu
->language
= language_opencl
;
10761 /* Similar hack for Go. */
10762 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10763 set_cu_language (DW_LANG_Go
, cu
);
10765 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10767 /* Decode line number information if present. We do this before
10768 processing child DIEs, so that the line header table is available
10769 for DW_AT_decl_file. */
10770 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10772 /* Process all dies in compilation unit. */
10773 if (die
->child
!= NULL
)
10775 child_die
= die
->child
;
10776 while (child_die
&& child_die
->tag
)
10778 process_die (child_die
, cu
);
10779 child_die
= sibling_die (child_die
);
10783 /* Decode macro information, if present. Dwarf 2 macro information
10784 refers to information in the line number info statement program
10785 header, so we can only read it if we've read the header
10787 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10789 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10790 if (attr
&& cu
->line_header
)
10792 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10793 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10795 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10799 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10800 if (attr
&& cu
->line_header
)
10802 unsigned int macro_offset
= DW_UNSND (attr
);
10804 dwarf_decode_macros (cu
, macro_offset
, 0);
10810 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10812 struct type_unit_group
*tu_group
;
10814 struct attribute
*attr
;
10816 struct signatured_type
*sig_type
;
10818 gdb_assert (per_cu
->is_debug_types
);
10819 sig_type
= (struct signatured_type
*) per_cu
;
10821 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10823 /* If we're using .gdb_index (includes -readnow) then
10824 per_cu->type_unit_group may not have been set up yet. */
10825 if (sig_type
->type_unit_group
== NULL
)
10826 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10827 tu_group
= sig_type
->type_unit_group
;
10829 /* If we've already processed this stmt_list there's no real need to
10830 do it again, we could fake it and just recreate the part we need
10831 (file name,index -> symtab mapping). If data shows this optimization
10832 is useful we can do it then. */
10833 first_time
= tu_group
->compunit_symtab
== NULL
;
10835 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10840 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10841 lh
= dwarf_decode_line_header (line_offset
, this);
10846 start_symtab ("", NULL
, 0);
10849 gdb_assert (tu_group
->symtabs
== NULL
);
10850 gdb_assert (m_builder
== nullptr);
10851 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10852 m_builder
.reset (new struct buildsym_compunit
10853 (COMPUNIT_OBJFILE (cust
), "",
10854 COMPUNIT_DIRNAME (cust
),
10855 compunit_language (cust
),
10861 line_header
= lh
.release ();
10862 line_header_die_owner
= die
;
10866 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10868 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10869 still initializing it, and our caller (a few levels up)
10870 process_full_type_unit still needs to know if this is the first
10873 tu_group
->num_symtabs
= line_header
->file_names_size ();
10874 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
10875 line_header
->file_names_size ());
10877 auto &file_names
= line_header
->file_names ();
10878 for (i
= 0; i
< file_names
.size (); ++i
)
10880 file_entry
&fe
= file_names
[i
];
10881 dwarf2_start_subfile (this, fe
.name
,
10882 fe
.include_dir (line_header
));
10883 buildsym_compunit
*b
= get_builder ();
10884 if (b
->get_current_subfile ()->symtab
== NULL
)
10886 /* NOTE: start_subfile will recognize when it's been
10887 passed a file it has already seen. So we can't
10888 assume there's a simple mapping from
10889 cu->line_header->file_names to subfiles, plus
10890 cu->line_header->file_names may contain dups. */
10891 b
->get_current_subfile ()->symtab
10892 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10895 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10896 tu_group
->symtabs
[i
] = fe
.symtab
;
10901 gdb_assert (m_builder
== nullptr);
10902 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10903 m_builder
.reset (new struct buildsym_compunit
10904 (COMPUNIT_OBJFILE (cust
), "",
10905 COMPUNIT_DIRNAME (cust
),
10906 compunit_language (cust
),
10909 auto &file_names
= line_header
->file_names ();
10910 for (i
= 0; i
< file_names
.size (); ++i
)
10912 file_entry
&fe
= file_names
[i
];
10913 fe
.symtab
= tu_group
->symtabs
[i
];
10917 /* The main symtab is allocated last. Type units don't have DW_AT_name
10918 so they don't have a "real" (so to speak) symtab anyway.
10919 There is later code that will assign the main symtab to all symbols
10920 that don't have one. We need to handle the case of a symbol with a
10921 missing symtab (DW_AT_decl_file) anyway. */
10924 /* Process DW_TAG_type_unit.
10925 For TUs we want to skip the first top level sibling if it's not the
10926 actual type being defined by this TU. In this case the first top
10927 level sibling is there to provide context only. */
10930 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10932 struct die_info
*child_die
;
10934 prepare_one_comp_unit (cu
, die
, language_minimal
);
10936 /* Initialize (or reinitialize) the machinery for building symtabs.
10937 We do this before processing child DIEs, so that the line header table
10938 is available for DW_AT_decl_file. */
10939 cu
->setup_type_unit_groups (die
);
10941 if (die
->child
!= NULL
)
10943 child_die
= die
->child
;
10944 while (child_die
&& child_die
->tag
)
10946 process_die (child_die
, cu
);
10947 child_die
= sibling_die (child_die
);
10954 http://gcc.gnu.org/wiki/DebugFission
10955 http://gcc.gnu.org/wiki/DebugFissionDWP
10957 To simplify handling of both DWO files ("object" files with the DWARF info)
10958 and DWP files (a file with the DWOs packaged up into one file), we treat
10959 DWP files as having a collection of virtual DWO files. */
10962 hash_dwo_file (const void *item
)
10964 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10967 hash
= htab_hash_string (dwo_file
->dwo_name
);
10968 if (dwo_file
->comp_dir
!= NULL
)
10969 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10974 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10976 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10977 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10979 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10981 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10982 return lhs
->comp_dir
== rhs
->comp_dir
;
10983 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10986 /* Allocate a hash table for DWO files. */
10989 allocate_dwo_file_hash_table (struct objfile
*objfile
)
10991 auto delete_dwo_file
= [] (void *item
)
10993 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10998 return htab_up (htab_create_alloc (41,
11005 /* Lookup DWO file DWO_NAME. */
11008 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11009 const char *dwo_name
,
11010 const char *comp_dir
)
11012 struct dwo_file find_entry
;
11015 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11016 dwarf2_per_objfile
->dwo_files
11017 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11019 find_entry
.dwo_name
= dwo_name
;
11020 find_entry
.comp_dir
= comp_dir
;
11021 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11028 hash_dwo_unit (const void *item
)
11030 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11032 /* This drops the top 32 bits of the id, but is ok for a hash. */
11033 return dwo_unit
->signature
;
11037 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11039 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11040 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11042 /* The signature is assumed to be unique within the DWO file.
11043 So while object file CU dwo_id's always have the value zero,
11044 that's OK, assuming each object file DWO file has only one CU,
11045 and that's the rule for now. */
11046 return lhs
->signature
== rhs
->signature
;
11049 /* Allocate a hash table for DWO CUs,TUs.
11050 There is one of these tables for each of CUs,TUs for each DWO file. */
11053 allocate_dwo_unit_table (struct objfile
*objfile
)
11055 /* Start out with a pretty small number.
11056 Generally DWO files contain only one CU and maybe some TUs. */
11057 return htab_up (htab_create_alloc (3,
11060 NULL
, xcalloc
, xfree
));
11063 /* die_reader_func for create_dwo_cu. */
11066 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11067 const gdb_byte
*info_ptr
,
11068 struct die_info
*comp_unit_die
,
11069 struct dwo_file
*dwo_file
,
11070 struct dwo_unit
*dwo_unit
)
11072 struct dwarf2_cu
*cu
= reader
->cu
;
11073 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11074 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11076 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11077 if (!signature
.has_value ())
11079 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11080 " its dwo_id [in module %s]"),
11081 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11085 dwo_unit
->dwo_file
= dwo_file
;
11086 dwo_unit
->signature
= *signature
;
11087 dwo_unit
->section
= section
;
11088 dwo_unit
->sect_off
= sect_off
;
11089 dwo_unit
->length
= cu
->per_cu
->length
;
11091 if (dwarf_read_debug
)
11092 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11093 sect_offset_str (sect_off
),
11094 hex_string (dwo_unit
->signature
));
11097 /* Create the dwo_units for the CUs in a DWO_FILE.
11098 Note: This function processes DWO files only, not DWP files. */
11101 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11102 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11103 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11105 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11106 const gdb_byte
*info_ptr
, *end_ptr
;
11108 section
.read (objfile
);
11109 info_ptr
= section
.buffer
;
11111 if (info_ptr
== NULL
)
11114 if (dwarf_read_debug
)
11116 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11117 section
.get_name (),
11118 section
.get_file_name ());
11121 end_ptr
= info_ptr
+ section
.size
;
11122 while (info_ptr
< end_ptr
)
11124 struct dwarf2_per_cu_data per_cu
;
11125 struct dwo_unit read_unit
{};
11126 struct dwo_unit
*dwo_unit
;
11128 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11130 memset (&per_cu
, 0, sizeof (per_cu
));
11131 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11132 per_cu
.is_debug_types
= 0;
11133 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11134 per_cu
.section
= §ion
;
11136 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11137 if (!reader
.dummy_p
)
11138 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11139 &dwo_file
, &read_unit
);
11140 info_ptr
+= per_cu
.length
;
11142 // If the unit could not be parsed, skip it.
11143 if (read_unit
.dwo_file
== NULL
)
11146 if (cus_htab
== NULL
)
11147 cus_htab
= allocate_dwo_unit_table (objfile
);
11149 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11150 *dwo_unit
= read_unit
;
11151 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11152 gdb_assert (slot
!= NULL
);
11155 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11156 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11158 complaint (_("debug cu entry at offset %s is duplicate to"
11159 " the entry at offset %s, signature %s"),
11160 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11161 hex_string (dwo_unit
->signature
));
11163 *slot
= (void *)dwo_unit
;
11167 /* DWP file .debug_{cu,tu}_index section format:
11168 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11172 Both index sections have the same format, and serve to map a 64-bit
11173 signature to a set of section numbers. Each section begins with a header,
11174 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11175 indexes, and a pool of 32-bit section numbers. The index sections will be
11176 aligned at 8-byte boundaries in the file.
11178 The index section header consists of:
11180 V, 32 bit version number
11182 N, 32 bit number of compilation units or type units in the index
11183 M, 32 bit number of slots in the hash table
11185 Numbers are recorded using the byte order of the application binary.
11187 The hash table begins at offset 16 in the section, and consists of an array
11188 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11189 order of the application binary). Unused slots in the hash table are 0.
11190 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11192 The parallel table begins immediately after the hash table
11193 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11194 array of 32-bit indexes (using the byte order of the application binary),
11195 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11196 table contains a 32-bit index into the pool of section numbers. For unused
11197 hash table slots, the corresponding entry in the parallel table will be 0.
11199 The pool of section numbers begins immediately following the hash table
11200 (at offset 16 + 12 * M from the beginning of the section). The pool of
11201 section numbers consists of an array of 32-bit words (using the byte order
11202 of the application binary). Each item in the array is indexed starting
11203 from 0. The hash table entry provides the index of the first section
11204 number in the set. Additional section numbers in the set follow, and the
11205 set is terminated by a 0 entry (section number 0 is not used in ELF).
11207 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11208 section must be the first entry in the set, and the .debug_abbrev.dwo must
11209 be the second entry. Other members of the set may follow in any order.
11215 DWP Version 2 combines all the .debug_info, etc. sections into one,
11216 and the entries in the index tables are now offsets into these sections.
11217 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11220 Index Section Contents:
11222 Hash Table of Signatures dwp_hash_table.hash_table
11223 Parallel Table of Indices dwp_hash_table.unit_table
11224 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11225 Table of Section Sizes dwp_hash_table.v2.sizes
11227 The index section header consists of:
11229 V, 32 bit version number
11230 L, 32 bit number of columns in the table of section offsets
11231 N, 32 bit number of compilation units or type units in the index
11232 M, 32 bit number of slots in the hash table
11234 Numbers are recorded using the byte order of the application binary.
11236 The hash table has the same format as version 1.
11237 The parallel table of indices has the same format as version 1,
11238 except that the entries are origin-1 indices into the table of sections
11239 offsets and the table of section sizes.
11241 The table of offsets begins immediately following the parallel table
11242 (at offset 16 + 12 * M from the beginning of the section). The table is
11243 a two-dimensional array of 32-bit words (using the byte order of the
11244 application binary), with L columns and N+1 rows, in row-major order.
11245 Each row in the array is indexed starting from 0. The first row provides
11246 a key to the remaining rows: each column in this row provides an identifier
11247 for a debug section, and the offsets in the same column of subsequent rows
11248 refer to that section. The section identifiers are:
11250 DW_SECT_INFO 1 .debug_info.dwo
11251 DW_SECT_TYPES 2 .debug_types.dwo
11252 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11253 DW_SECT_LINE 4 .debug_line.dwo
11254 DW_SECT_LOC 5 .debug_loc.dwo
11255 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11256 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11257 DW_SECT_MACRO 8 .debug_macro.dwo
11259 The offsets provided by the CU and TU index sections are the base offsets
11260 for the contributions made by each CU or TU to the corresponding section
11261 in the package file. Each CU and TU header contains an abbrev_offset
11262 field, used to find the abbreviations table for that CU or TU within the
11263 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11264 be interpreted as relative to the base offset given in the index section.
11265 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11266 should be interpreted as relative to the base offset for .debug_line.dwo,
11267 and offsets into other debug sections obtained from DWARF attributes should
11268 also be interpreted as relative to the corresponding base offset.
11270 The table of sizes begins immediately following the table of offsets.
11271 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11272 with L columns and N rows, in row-major order. Each row in the array is
11273 indexed starting from 1 (row 0 is shared by the two tables).
11277 Hash table lookup is handled the same in version 1 and 2:
11279 We assume that N and M will not exceed 2^32 - 1.
11280 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11282 Given a 64-bit compilation unit signature or a type signature S, an entry
11283 in the hash table is located as follows:
11285 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11286 the low-order k bits all set to 1.
11288 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11290 3) If the hash table entry at index H matches the signature, use that
11291 entry. If the hash table entry at index H is unused (all zeroes),
11292 terminate the search: the signature is not present in the table.
11294 4) Let H = (H + H') modulo M. Repeat at Step 3.
11296 Because M > N and H' and M are relatively prime, the search is guaranteed
11297 to stop at an unused slot or find the match. */
11299 /* Create a hash table to map DWO IDs to their CU/TU entry in
11300 .debug_{info,types}.dwo in DWP_FILE.
11301 Returns NULL if there isn't one.
11302 Note: This function processes DWP files only, not DWO files. */
11304 static struct dwp_hash_table
*
11305 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11306 struct dwp_file
*dwp_file
, int is_debug_types
)
11308 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11309 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11310 const gdb_byte
*index_ptr
, *index_end
;
11311 struct dwarf2_section_info
*index
;
11312 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11313 struct dwp_hash_table
*htab
;
11315 if (is_debug_types
)
11316 index
= &dwp_file
->sections
.tu_index
;
11318 index
= &dwp_file
->sections
.cu_index
;
11320 if (index
->empty ())
11322 index
->read (objfile
);
11324 index_ptr
= index
->buffer
;
11325 index_end
= index_ptr
+ index
->size
;
11327 version
= read_4_bytes (dbfd
, index_ptr
);
11330 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11334 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11336 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11339 if (version
!= 1 && version
!= 2)
11341 error (_("Dwarf Error: unsupported DWP file version (%s)"
11342 " [in module %s]"),
11343 pulongest (version
), dwp_file
->name
);
11345 if (nr_slots
!= (nr_slots
& -nr_slots
))
11347 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11348 " is not power of 2 [in module %s]"),
11349 pulongest (nr_slots
), dwp_file
->name
);
11352 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11353 htab
->version
= version
;
11354 htab
->nr_columns
= nr_columns
;
11355 htab
->nr_units
= nr_units
;
11356 htab
->nr_slots
= nr_slots
;
11357 htab
->hash_table
= index_ptr
;
11358 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11360 /* Exit early if the table is empty. */
11361 if (nr_slots
== 0 || nr_units
== 0
11362 || (version
== 2 && nr_columns
== 0))
11364 /* All must be zero. */
11365 if (nr_slots
!= 0 || nr_units
!= 0
11366 || (version
== 2 && nr_columns
!= 0))
11368 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11369 " all zero [in modules %s]"),
11377 htab
->section_pool
.v1
.indices
=
11378 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11379 /* It's harder to decide whether the section is too small in v1.
11380 V1 is deprecated anyway so we punt. */
11384 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11385 int *ids
= htab
->section_pool
.v2
.section_ids
;
11386 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11387 /* Reverse map for error checking. */
11388 int ids_seen
[DW_SECT_MAX
+ 1];
11391 if (nr_columns
< 2)
11393 error (_("Dwarf Error: bad DWP hash table, too few columns"
11394 " in section table [in module %s]"),
11397 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11399 error (_("Dwarf Error: bad DWP hash table, too many columns"
11400 " in section table [in module %s]"),
11403 memset (ids
, 255, sizeof_ids
);
11404 memset (ids_seen
, 255, sizeof (ids_seen
));
11405 for (i
= 0; i
< nr_columns
; ++i
)
11407 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11409 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11411 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11412 " in section table [in module %s]"),
11413 id
, dwp_file
->name
);
11415 if (ids_seen
[id
] != -1)
11417 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11418 " id %d in section table [in module %s]"),
11419 id
, dwp_file
->name
);
11424 /* Must have exactly one info or types section. */
11425 if (((ids_seen
[DW_SECT_INFO
] != -1)
11426 + (ids_seen
[DW_SECT_TYPES
] != -1))
11429 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11430 " DWO info/types section [in module %s]"),
11433 /* Must have an abbrev section. */
11434 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11436 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11437 " section [in module %s]"),
11440 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11441 htab
->section_pool
.v2
.sizes
=
11442 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11443 * nr_units
* nr_columns
);
11444 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11445 * nr_units
* nr_columns
))
11448 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11449 " [in module %s]"),
11457 /* Update SECTIONS with the data from SECTP.
11459 This function is like the other "locate" section routines that are
11460 passed to bfd_map_over_sections, but in this context the sections to
11461 read comes from the DWP V1 hash table, not the full ELF section table.
11463 The result is non-zero for success, or zero if an error was found. */
11466 locate_v1_virtual_dwo_sections (asection
*sectp
,
11467 struct virtual_v1_dwo_sections
*sections
)
11469 const struct dwop_section_names
*names
= &dwop_section_names
;
11471 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11473 /* There can be only one. */
11474 if (sections
->abbrev
.s
.section
!= NULL
)
11476 sections
->abbrev
.s
.section
= sectp
;
11477 sections
->abbrev
.size
= bfd_section_size (sectp
);
11479 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11480 || section_is_p (sectp
->name
, &names
->types_dwo
))
11482 /* There can be only one. */
11483 if (sections
->info_or_types
.s
.section
!= NULL
)
11485 sections
->info_or_types
.s
.section
= sectp
;
11486 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11488 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11490 /* There can be only one. */
11491 if (sections
->line
.s
.section
!= NULL
)
11493 sections
->line
.s
.section
= sectp
;
11494 sections
->line
.size
= bfd_section_size (sectp
);
11496 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11498 /* There can be only one. */
11499 if (sections
->loc
.s
.section
!= NULL
)
11501 sections
->loc
.s
.section
= sectp
;
11502 sections
->loc
.size
= bfd_section_size (sectp
);
11504 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11506 /* There can be only one. */
11507 if (sections
->macinfo
.s
.section
!= NULL
)
11509 sections
->macinfo
.s
.section
= sectp
;
11510 sections
->macinfo
.size
= bfd_section_size (sectp
);
11512 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11514 /* There can be only one. */
11515 if (sections
->macro
.s
.section
!= NULL
)
11517 sections
->macro
.s
.section
= sectp
;
11518 sections
->macro
.size
= bfd_section_size (sectp
);
11520 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11522 /* There can be only one. */
11523 if (sections
->str_offsets
.s
.section
!= NULL
)
11525 sections
->str_offsets
.s
.section
= sectp
;
11526 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11530 /* No other kind of section is valid. */
11537 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11538 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11539 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11540 This is for DWP version 1 files. */
11542 static struct dwo_unit
*
11543 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11544 struct dwp_file
*dwp_file
,
11545 uint32_t unit_index
,
11546 const char *comp_dir
,
11547 ULONGEST signature
, int is_debug_types
)
11549 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11550 const struct dwp_hash_table
*dwp_htab
=
11551 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11552 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11553 const char *kind
= is_debug_types
? "TU" : "CU";
11554 struct dwo_file
*dwo_file
;
11555 struct dwo_unit
*dwo_unit
;
11556 struct virtual_v1_dwo_sections sections
;
11557 void **dwo_file_slot
;
11560 gdb_assert (dwp_file
->version
== 1);
11562 if (dwarf_read_debug
)
11564 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11566 pulongest (unit_index
), hex_string (signature
),
11570 /* Fetch the sections of this DWO unit.
11571 Put a limit on the number of sections we look for so that bad data
11572 doesn't cause us to loop forever. */
11574 #define MAX_NR_V1_DWO_SECTIONS \
11575 (1 /* .debug_info or .debug_types */ \
11576 + 1 /* .debug_abbrev */ \
11577 + 1 /* .debug_line */ \
11578 + 1 /* .debug_loc */ \
11579 + 1 /* .debug_str_offsets */ \
11580 + 1 /* .debug_macro or .debug_macinfo */ \
11581 + 1 /* trailing zero */)
11583 memset (§ions
, 0, sizeof (sections
));
11585 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11588 uint32_t section_nr
=
11589 read_4_bytes (dbfd
,
11590 dwp_htab
->section_pool
.v1
.indices
11591 + (unit_index
+ i
) * sizeof (uint32_t));
11593 if (section_nr
== 0)
11595 if (section_nr
>= dwp_file
->num_sections
)
11597 error (_("Dwarf Error: bad DWP hash table, section number too large"
11598 " [in module %s]"),
11602 sectp
= dwp_file
->elf_sections
[section_nr
];
11603 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11605 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11606 " [in module %s]"),
11612 || sections
.info_or_types
.empty ()
11613 || sections
.abbrev
.empty ())
11615 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11616 " [in module %s]"),
11619 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11621 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11622 " [in module %s]"),
11626 /* It's easier for the rest of the code if we fake a struct dwo_file and
11627 have dwo_unit "live" in that. At least for now.
11629 The DWP file can be made up of a random collection of CUs and TUs.
11630 However, for each CU + set of TUs that came from the same original DWO
11631 file, we can combine them back into a virtual DWO file to save space
11632 (fewer struct dwo_file objects to allocate). Remember that for really
11633 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11635 std::string virtual_dwo_name
=
11636 string_printf ("virtual-dwo/%d-%d-%d-%d",
11637 sections
.abbrev
.get_id (),
11638 sections
.line
.get_id (),
11639 sections
.loc
.get_id (),
11640 sections
.str_offsets
.get_id ());
11641 /* Can we use an existing virtual DWO file? */
11642 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11643 virtual_dwo_name
.c_str (),
11645 /* Create one if necessary. */
11646 if (*dwo_file_slot
== NULL
)
11648 if (dwarf_read_debug
)
11650 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11651 virtual_dwo_name
.c_str ());
11653 dwo_file
= new struct dwo_file
;
11654 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11656 dwo_file
->comp_dir
= comp_dir
;
11657 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11658 dwo_file
->sections
.line
= sections
.line
;
11659 dwo_file
->sections
.loc
= sections
.loc
;
11660 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11661 dwo_file
->sections
.macro
= sections
.macro
;
11662 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11663 /* The "str" section is global to the entire DWP file. */
11664 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11665 /* The info or types section is assigned below to dwo_unit,
11666 there's no need to record it in dwo_file.
11667 Also, we can't simply record type sections in dwo_file because
11668 we record a pointer into the vector in dwo_unit. As we collect more
11669 types we'll grow the vector and eventually have to reallocate space
11670 for it, invalidating all copies of pointers into the previous
11672 *dwo_file_slot
= dwo_file
;
11676 if (dwarf_read_debug
)
11678 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11679 virtual_dwo_name
.c_str ());
11681 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11684 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11685 dwo_unit
->dwo_file
= dwo_file
;
11686 dwo_unit
->signature
= signature
;
11687 dwo_unit
->section
=
11688 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11689 *dwo_unit
->section
= sections
.info_or_types
;
11690 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11695 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11696 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11697 piece within that section used by a TU/CU, return a virtual section
11698 of just that piece. */
11700 static struct dwarf2_section_info
11701 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11702 struct dwarf2_section_info
*section
,
11703 bfd_size_type offset
, bfd_size_type size
)
11705 struct dwarf2_section_info result
;
11708 gdb_assert (section
!= NULL
);
11709 gdb_assert (!section
->is_virtual
);
11711 memset (&result
, 0, sizeof (result
));
11712 result
.s
.containing_section
= section
;
11713 result
.is_virtual
= true;
11718 sectp
= section
->get_bfd_section ();
11720 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11721 bounds of the real section. This is a pretty-rare event, so just
11722 flag an error (easier) instead of a warning and trying to cope. */
11724 || offset
+ size
> bfd_section_size (sectp
))
11726 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11727 " in section %s [in module %s]"),
11728 sectp
? bfd_section_name (sectp
) : "<unknown>",
11729 objfile_name (dwarf2_per_objfile
->objfile
));
11732 result
.virtual_offset
= offset
;
11733 result
.size
= size
;
11737 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11738 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11739 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11740 This is for DWP version 2 files. */
11742 static struct dwo_unit
*
11743 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11744 struct dwp_file
*dwp_file
,
11745 uint32_t unit_index
,
11746 const char *comp_dir
,
11747 ULONGEST signature
, int is_debug_types
)
11749 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11750 const struct dwp_hash_table
*dwp_htab
=
11751 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11752 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11753 const char *kind
= is_debug_types
? "TU" : "CU";
11754 struct dwo_file
*dwo_file
;
11755 struct dwo_unit
*dwo_unit
;
11756 struct virtual_v2_dwo_sections sections
;
11757 void **dwo_file_slot
;
11760 gdb_assert (dwp_file
->version
== 2);
11762 if (dwarf_read_debug
)
11764 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11766 pulongest (unit_index
), hex_string (signature
),
11770 /* Fetch the section offsets of this DWO unit. */
11772 memset (§ions
, 0, sizeof (sections
));
11774 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11776 uint32_t offset
= read_4_bytes (dbfd
,
11777 dwp_htab
->section_pool
.v2
.offsets
11778 + (((unit_index
- 1) * dwp_htab
->nr_columns
11780 * sizeof (uint32_t)));
11781 uint32_t size
= read_4_bytes (dbfd
,
11782 dwp_htab
->section_pool
.v2
.sizes
11783 + (((unit_index
- 1) * dwp_htab
->nr_columns
11785 * sizeof (uint32_t)));
11787 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11790 case DW_SECT_TYPES
:
11791 sections
.info_or_types_offset
= offset
;
11792 sections
.info_or_types_size
= size
;
11794 case DW_SECT_ABBREV
:
11795 sections
.abbrev_offset
= offset
;
11796 sections
.abbrev_size
= size
;
11799 sections
.line_offset
= offset
;
11800 sections
.line_size
= size
;
11803 sections
.loc_offset
= offset
;
11804 sections
.loc_size
= size
;
11806 case DW_SECT_STR_OFFSETS
:
11807 sections
.str_offsets_offset
= offset
;
11808 sections
.str_offsets_size
= size
;
11810 case DW_SECT_MACINFO
:
11811 sections
.macinfo_offset
= offset
;
11812 sections
.macinfo_size
= size
;
11814 case DW_SECT_MACRO
:
11815 sections
.macro_offset
= offset
;
11816 sections
.macro_size
= size
;
11821 /* It's easier for the rest of the code if we fake a struct dwo_file and
11822 have dwo_unit "live" in that. At least for now.
11824 The DWP file can be made up of a random collection of CUs and TUs.
11825 However, for each CU + set of TUs that came from the same original DWO
11826 file, we can combine them back into a virtual DWO file to save space
11827 (fewer struct dwo_file objects to allocate). Remember that for really
11828 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11830 std::string virtual_dwo_name
=
11831 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11832 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11833 (long) (sections
.line_size
? sections
.line_offset
: 0),
11834 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11835 (long) (sections
.str_offsets_size
11836 ? sections
.str_offsets_offset
: 0));
11837 /* Can we use an existing virtual DWO file? */
11838 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11839 virtual_dwo_name
.c_str (),
11841 /* Create one if necessary. */
11842 if (*dwo_file_slot
== NULL
)
11844 if (dwarf_read_debug
)
11846 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11847 virtual_dwo_name
.c_str ());
11849 dwo_file
= new struct dwo_file
;
11850 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11852 dwo_file
->comp_dir
= comp_dir
;
11853 dwo_file
->sections
.abbrev
=
11854 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11855 sections
.abbrev_offset
, sections
.abbrev_size
);
11856 dwo_file
->sections
.line
=
11857 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11858 sections
.line_offset
, sections
.line_size
);
11859 dwo_file
->sections
.loc
=
11860 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11861 sections
.loc_offset
, sections
.loc_size
);
11862 dwo_file
->sections
.macinfo
=
11863 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11864 sections
.macinfo_offset
, sections
.macinfo_size
);
11865 dwo_file
->sections
.macro
=
11866 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11867 sections
.macro_offset
, sections
.macro_size
);
11868 dwo_file
->sections
.str_offsets
=
11869 create_dwp_v2_section (dwarf2_per_objfile
,
11870 &dwp_file
->sections
.str_offsets
,
11871 sections
.str_offsets_offset
,
11872 sections
.str_offsets_size
);
11873 /* The "str" section is global to the entire DWP file. */
11874 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11875 /* The info or types section is assigned below to dwo_unit,
11876 there's no need to record it in dwo_file.
11877 Also, we can't simply record type sections in dwo_file because
11878 we record a pointer into the vector in dwo_unit. As we collect more
11879 types we'll grow the vector and eventually have to reallocate space
11880 for it, invalidating all copies of pointers into the previous
11882 *dwo_file_slot
= dwo_file
;
11886 if (dwarf_read_debug
)
11888 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11889 virtual_dwo_name
.c_str ());
11891 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11894 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11895 dwo_unit
->dwo_file
= dwo_file
;
11896 dwo_unit
->signature
= signature
;
11897 dwo_unit
->section
=
11898 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11899 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11901 ? &dwp_file
->sections
.types
11902 : &dwp_file
->sections
.info
,
11903 sections
.info_or_types_offset
,
11904 sections
.info_or_types_size
);
11905 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11910 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11911 Returns NULL if the signature isn't found. */
11913 static struct dwo_unit
*
11914 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11915 struct dwp_file
*dwp_file
, const char *comp_dir
,
11916 ULONGEST signature
, int is_debug_types
)
11918 const struct dwp_hash_table
*dwp_htab
=
11919 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11920 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11921 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11922 uint32_t hash
= signature
& mask
;
11923 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11926 struct dwo_unit find_dwo_cu
;
11928 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11929 find_dwo_cu
.signature
= signature
;
11930 slot
= htab_find_slot (is_debug_types
11931 ? dwp_file
->loaded_tus
.get ()
11932 : dwp_file
->loaded_cus
.get (),
11933 &find_dwo_cu
, INSERT
);
11936 return (struct dwo_unit
*) *slot
;
11938 /* Use a for loop so that we don't loop forever on bad debug info. */
11939 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11941 ULONGEST signature_in_table
;
11943 signature_in_table
=
11944 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11945 if (signature_in_table
== signature
)
11947 uint32_t unit_index
=
11948 read_4_bytes (dbfd
,
11949 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11951 if (dwp_file
->version
== 1)
11953 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11954 dwp_file
, unit_index
,
11955 comp_dir
, signature
,
11960 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11961 dwp_file
, unit_index
,
11962 comp_dir
, signature
,
11965 return (struct dwo_unit
*) *slot
;
11967 if (signature_in_table
== 0)
11969 hash
= (hash
+ hash2
) & mask
;
11972 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11973 " [in module %s]"),
11977 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11978 Open the file specified by FILE_NAME and hand it off to BFD for
11979 preliminary analysis. Return a newly initialized bfd *, which
11980 includes a canonicalized copy of FILE_NAME.
11981 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11982 SEARCH_CWD is true if the current directory is to be searched.
11983 It will be searched before debug-file-directory.
11984 If successful, the file is added to the bfd include table of the
11985 objfile's bfd (see gdb_bfd_record_inclusion).
11986 If unable to find/open the file, return NULL.
11987 NOTE: This function is derived from symfile_bfd_open. */
11989 static gdb_bfd_ref_ptr
11990 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11991 const char *file_name
, int is_dwp
, int search_cwd
)
11994 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11995 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11996 to debug_file_directory. */
11997 const char *search_path
;
11998 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12000 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12003 if (*debug_file_directory
!= '\0')
12005 search_path_holder
.reset (concat (".", dirname_separator_string
,
12006 debug_file_directory
,
12008 search_path
= search_path_holder
.get ();
12014 search_path
= debug_file_directory
;
12016 openp_flags flags
= OPF_RETURN_REALPATH
;
12018 flags
|= OPF_SEARCH_IN_PATH
;
12020 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12021 desc
= openp (search_path
, flags
, file_name
,
12022 O_RDONLY
| O_BINARY
, &absolute_name
);
12026 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12028 if (sym_bfd
== NULL
)
12030 bfd_set_cacheable (sym_bfd
.get (), 1);
12032 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12035 /* Success. Record the bfd as having been included by the objfile's bfd.
12036 This is important because things like demangled_names_hash lives in the
12037 objfile's per_bfd space and may have references to things like symbol
12038 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12039 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12044 /* Try to open DWO file FILE_NAME.
12045 COMP_DIR is the DW_AT_comp_dir attribute.
12046 The result is the bfd handle of the file.
12047 If there is a problem finding or opening the file, return NULL.
12048 Upon success, the canonicalized path of the file is stored in the bfd,
12049 same as symfile_bfd_open. */
12051 static gdb_bfd_ref_ptr
12052 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12053 const char *file_name
, const char *comp_dir
)
12055 if (IS_ABSOLUTE_PATH (file_name
))
12056 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12057 0 /*is_dwp*/, 0 /*search_cwd*/);
12059 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12061 if (comp_dir
!= NULL
)
12063 gdb::unique_xmalloc_ptr
<char> path_to_try
12064 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12066 /* NOTE: If comp_dir is a relative path, this will also try the
12067 search path, which seems useful. */
12068 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12069 path_to_try
.get (),
12071 1 /*search_cwd*/));
12076 /* That didn't work, try debug-file-directory, which, despite its name,
12077 is a list of paths. */
12079 if (*debug_file_directory
== '\0')
12082 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12083 0 /*is_dwp*/, 1 /*search_cwd*/);
12086 /* This function is mapped across the sections and remembers the offset and
12087 size of each of the DWO debugging sections we are interested in. */
12090 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12092 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12093 const struct dwop_section_names
*names
= &dwop_section_names
;
12095 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12097 dwo_sections
->abbrev
.s
.section
= sectp
;
12098 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12100 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12102 dwo_sections
->info
.s
.section
= sectp
;
12103 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12105 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12107 dwo_sections
->line
.s
.section
= sectp
;
12108 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12110 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12112 dwo_sections
->loc
.s
.section
= sectp
;
12113 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12115 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12117 dwo_sections
->macinfo
.s
.section
= sectp
;
12118 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12120 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12122 dwo_sections
->macro
.s
.section
= sectp
;
12123 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12125 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12127 dwo_sections
->str
.s
.section
= sectp
;
12128 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12130 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12132 dwo_sections
->str_offsets
.s
.section
= sectp
;
12133 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12135 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12137 struct dwarf2_section_info type_section
;
12139 memset (&type_section
, 0, sizeof (type_section
));
12140 type_section
.s
.section
= sectp
;
12141 type_section
.size
= bfd_section_size (sectp
);
12142 dwo_sections
->types
.push_back (type_section
);
12146 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12147 by PER_CU. This is for the non-DWP case.
12148 The result is NULL if DWO_NAME can't be found. */
12150 static struct dwo_file
*
12151 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12152 const char *dwo_name
, const char *comp_dir
)
12154 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12156 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12159 if (dwarf_read_debug
)
12160 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12164 dwo_file_up
dwo_file (new struct dwo_file
);
12165 dwo_file
->dwo_name
= dwo_name
;
12166 dwo_file
->comp_dir
= comp_dir
;
12167 dwo_file
->dbfd
= std::move (dbfd
);
12169 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12170 &dwo_file
->sections
);
12172 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12173 dwo_file
->sections
.info
, dwo_file
->cus
);
12175 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12176 dwo_file
->sections
.types
, dwo_file
->tus
);
12178 if (dwarf_read_debug
)
12179 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12181 return dwo_file
.release ();
12184 /* This function is mapped across the sections and remembers the offset and
12185 size of each of the DWP debugging sections common to version 1 and 2 that
12186 we are interested in. */
12189 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12190 void *dwp_file_ptr
)
12192 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12193 const struct dwop_section_names
*names
= &dwop_section_names
;
12194 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12196 /* Record the ELF section number for later lookup: this is what the
12197 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12198 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12199 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12201 /* Look for specific sections that we need. */
12202 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12204 dwp_file
->sections
.str
.s
.section
= sectp
;
12205 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12207 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12209 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12210 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12212 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12214 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12215 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12219 /* This function is mapped across the sections and remembers the offset and
12220 size of each of the DWP version 2 debugging sections that we are interested
12221 in. This is split into a separate function because we don't know if we
12222 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12225 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12227 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12228 const struct dwop_section_names
*names
= &dwop_section_names
;
12229 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12231 /* Record the ELF section number for later lookup: this is what the
12232 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12233 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12234 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12236 /* Look for specific sections that we need. */
12237 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12239 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12240 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12242 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12244 dwp_file
->sections
.info
.s
.section
= sectp
;
12245 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12247 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12249 dwp_file
->sections
.line
.s
.section
= sectp
;
12250 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12252 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12254 dwp_file
->sections
.loc
.s
.section
= sectp
;
12255 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12257 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12259 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12260 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12262 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12264 dwp_file
->sections
.macro
.s
.section
= sectp
;
12265 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12267 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12269 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12270 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12272 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12274 dwp_file
->sections
.types
.s
.section
= sectp
;
12275 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12279 /* Hash function for dwp_file loaded CUs/TUs. */
12282 hash_dwp_loaded_cutus (const void *item
)
12284 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12286 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12287 return dwo_unit
->signature
;
12290 /* Equality function for dwp_file loaded CUs/TUs. */
12293 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12295 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12296 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12298 return dua
->signature
== dub
->signature
;
12301 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12304 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
12306 return htab_up (htab_create_alloc (3,
12307 hash_dwp_loaded_cutus
,
12308 eq_dwp_loaded_cutus
,
12309 NULL
, xcalloc
, xfree
));
12312 /* Try to open DWP file FILE_NAME.
12313 The result is the bfd handle of the file.
12314 If there is a problem finding or opening the file, return NULL.
12315 Upon success, the canonicalized path of the file is stored in the bfd,
12316 same as symfile_bfd_open. */
12318 static gdb_bfd_ref_ptr
12319 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12320 const char *file_name
)
12322 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12324 1 /*search_cwd*/));
12328 /* Work around upstream bug 15652.
12329 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12330 [Whether that's a "bug" is debatable, but it is getting in our way.]
12331 We have no real idea where the dwp file is, because gdb's realpath-ing
12332 of the executable's path may have discarded the needed info.
12333 [IWBN if the dwp file name was recorded in the executable, akin to
12334 .gnu_debuglink, but that doesn't exist yet.]
12335 Strip the directory from FILE_NAME and search again. */
12336 if (*debug_file_directory
!= '\0')
12338 /* Don't implicitly search the current directory here.
12339 If the user wants to search "." to handle this case,
12340 it must be added to debug-file-directory. */
12341 return try_open_dwop_file (dwarf2_per_objfile
,
12342 lbasename (file_name
), 1 /*is_dwp*/,
12349 /* Initialize the use of the DWP file for the current objfile.
12350 By convention the name of the DWP file is ${objfile}.dwp.
12351 The result is NULL if it can't be found. */
12353 static std::unique_ptr
<struct dwp_file
>
12354 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12356 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12358 /* Try to find first .dwp for the binary file before any symbolic links
12361 /* If the objfile is a debug file, find the name of the real binary
12362 file and get the name of dwp file from there. */
12363 std::string dwp_name
;
12364 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12366 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12367 const char *backlink_basename
= lbasename (backlink
->original_name
);
12369 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12372 dwp_name
= objfile
->original_name
;
12374 dwp_name
+= ".dwp";
12376 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12378 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12380 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12381 dwp_name
= objfile_name (objfile
);
12382 dwp_name
+= ".dwp";
12383 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12388 if (dwarf_read_debug
)
12389 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12390 return std::unique_ptr
<dwp_file
> ();
12393 const char *name
= bfd_get_filename (dbfd
.get ());
12394 std::unique_ptr
<struct dwp_file
> dwp_file
12395 (new struct dwp_file (name
, std::move (dbfd
)));
12397 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12398 dwp_file
->elf_sections
=
12399 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12400 dwp_file
->num_sections
, asection
*);
12402 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12403 dwarf2_locate_common_dwp_sections
,
12406 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12409 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12412 /* The DWP file version is stored in the hash table. Oh well. */
12413 if (dwp_file
->cus
&& dwp_file
->tus
12414 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12416 /* Technically speaking, we should try to limp along, but this is
12417 pretty bizarre. We use pulongest here because that's the established
12418 portability solution (e.g, we cannot use %u for uint32_t). */
12419 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12420 " TU version %s [in DWP file %s]"),
12421 pulongest (dwp_file
->cus
->version
),
12422 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12426 dwp_file
->version
= dwp_file
->cus
->version
;
12427 else if (dwp_file
->tus
)
12428 dwp_file
->version
= dwp_file
->tus
->version
;
12430 dwp_file
->version
= 2;
12432 if (dwp_file
->version
== 2)
12433 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12434 dwarf2_locate_v2_dwp_sections
,
12437 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
12438 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
12440 if (dwarf_read_debug
)
12442 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12443 fprintf_unfiltered (gdb_stdlog
,
12444 " %s CUs, %s TUs\n",
12445 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12446 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12452 /* Wrapper around open_and_init_dwp_file, only open it once. */
12454 static struct dwp_file
*
12455 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12457 if (! dwarf2_per_objfile
->dwp_checked
)
12459 dwarf2_per_objfile
->dwp_file
12460 = open_and_init_dwp_file (dwarf2_per_objfile
);
12461 dwarf2_per_objfile
->dwp_checked
= 1;
12463 return dwarf2_per_objfile
->dwp_file
.get ();
12466 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12467 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12468 or in the DWP file for the objfile, referenced by THIS_UNIT.
12469 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12470 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12472 This is called, for example, when wanting to read a variable with a
12473 complex location. Therefore we don't want to do file i/o for every call.
12474 Therefore we don't want to look for a DWO file on every call.
12475 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12476 then we check if we've already seen DWO_NAME, and only THEN do we check
12479 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12480 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12482 static struct dwo_unit
*
12483 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12484 const char *dwo_name
, const char *comp_dir
,
12485 ULONGEST signature
, int is_debug_types
)
12487 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12488 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12489 const char *kind
= is_debug_types
? "TU" : "CU";
12490 void **dwo_file_slot
;
12491 struct dwo_file
*dwo_file
;
12492 struct dwp_file
*dwp_file
;
12494 /* First see if there's a DWP file.
12495 If we have a DWP file but didn't find the DWO inside it, don't
12496 look for the original DWO file. It makes gdb behave differently
12497 depending on whether one is debugging in the build tree. */
12499 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12500 if (dwp_file
!= NULL
)
12502 const struct dwp_hash_table
*dwp_htab
=
12503 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12505 if (dwp_htab
!= NULL
)
12507 struct dwo_unit
*dwo_cutu
=
12508 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12509 signature
, is_debug_types
);
12511 if (dwo_cutu
!= NULL
)
12513 if (dwarf_read_debug
)
12515 fprintf_unfiltered (gdb_stdlog
,
12516 "Virtual DWO %s %s found: @%s\n",
12517 kind
, hex_string (signature
),
12518 host_address_to_string (dwo_cutu
));
12526 /* No DWP file, look for the DWO file. */
12528 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12529 dwo_name
, comp_dir
);
12530 if (*dwo_file_slot
== NULL
)
12532 /* Read in the file and build a table of the CUs/TUs it contains. */
12533 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12535 /* NOTE: This will be NULL if unable to open the file. */
12536 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12538 if (dwo_file
!= NULL
)
12540 struct dwo_unit
*dwo_cutu
= NULL
;
12542 if (is_debug_types
&& dwo_file
->tus
)
12544 struct dwo_unit find_dwo_cutu
;
12546 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12547 find_dwo_cutu
.signature
= signature
;
12549 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12552 else if (!is_debug_types
&& dwo_file
->cus
)
12554 struct dwo_unit find_dwo_cutu
;
12556 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12557 find_dwo_cutu
.signature
= signature
;
12558 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12562 if (dwo_cutu
!= NULL
)
12564 if (dwarf_read_debug
)
12566 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12567 kind
, dwo_name
, hex_string (signature
),
12568 host_address_to_string (dwo_cutu
));
12575 /* We didn't find it. This could mean a dwo_id mismatch, or
12576 someone deleted the DWO/DWP file, or the search path isn't set up
12577 correctly to find the file. */
12579 if (dwarf_read_debug
)
12581 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12582 kind
, dwo_name
, hex_string (signature
));
12585 /* This is a warning and not a complaint because it can be caused by
12586 pilot error (e.g., user accidentally deleting the DWO). */
12588 /* Print the name of the DWP file if we looked there, helps the user
12589 better diagnose the problem. */
12590 std::string dwp_text
;
12592 if (dwp_file
!= NULL
)
12593 dwp_text
= string_printf (" [in DWP file %s]",
12594 lbasename (dwp_file
->name
));
12596 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12597 " [in module %s]"),
12598 kind
, dwo_name
, hex_string (signature
),
12600 this_unit
->is_debug_types
? "TU" : "CU",
12601 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12606 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12607 See lookup_dwo_cutu_unit for details. */
12609 static struct dwo_unit
*
12610 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12611 const char *dwo_name
, const char *comp_dir
,
12612 ULONGEST signature
)
12614 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12617 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12618 See lookup_dwo_cutu_unit for details. */
12620 static struct dwo_unit
*
12621 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12622 const char *dwo_name
, const char *comp_dir
)
12624 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12627 /* Traversal function for queue_and_load_all_dwo_tus. */
12630 queue_and_load_dwo_tu (void **slot
, void *info
)
12632 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12633 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12634 ULONGEST signature
= dwo_unit
->signature
;
12635 struct signatured_type
*sig_type
=
12636 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12638 if (sig_type
!= NULL
)
12640 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12642 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12643 a real dependency of PER_CU on SIG_TYPE. That is detected later
12644 while processing PER_CU. */
12645 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12646 load_full_type_unit (sig_cu
);
12647 per_cu
->imported_symtabs_push (sig_cu
);
12653 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12654 The DWO may have the only definition of the type, though it may not be
12655 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12656 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12659 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12661 struct dwo_unit
*dwo_unit
;
12662 struct dwo_file
*dwo_file
;
12664 gdb_assert (!per_cu
->is_debug_types
);
12665 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12666 gdb_assert (per_cu
->cu
!= NULL
);
12668 dwo_unit
= per_cu
->cu
->dwo_unit
;
12669 gdb_assert (dwo_unit
!= NULL
);
12671 dwo_file
= dwo_unit
->dwo_file
;
12672 if (dwo_file
->tus
!= NULL
)
12673 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12677 /* Read in various DIEs. */
12679 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12680 Inherit only the children of the DW_AT_abstract_origin DIE not being
12681 already referenced by DW_AT_abstract_origin from the children of the
12685 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12687 struct die_info
*child_die
;
12688 sect_offset
*offsetp
;
12689 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12690 struct die_info
*origin_die
;
12691 /* Iterator of the ORIGIN_DIE children. */
12692 struct die_info
*origin_child_die
;
12693 struct attribute
*attr
;
12694 struct dwarf2_cu
*origin_cu
;
12695 struct pending
**origin_previous_list_in_scope
;
12697 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12701 /* Note that following die references may follow to a die in a
12705 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12707 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12709 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12710 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12712 if (die
->tag
!= origin_die
->tag
12713 && !(die
->tag
== DW_TAG_inlined_subroutine
12714 && origin_die
->tag
== DW_TAG_subprogram
))
12715 complaint (_("DIE %s and its abstract origin %s have different tags"),
12716 sect_offset_str (die
->sect_off
),
12717 sect_offset_str (origin_die
->sect_off
));
12719 std::vector
<sect_offset
> offsets
;
12721 for (child_die
= die
->child
;
12722 child_die
&& child_die
->tag
;
12723 child_die
= sibling_die (child_die
))
12725 struct die_info
*child_origin_die
;
12726 struct dwarf2_cu
*child_origin_cu
;
12728 /* We are trying to process concrete instance entries:
12729 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12730 it's not relevant to our analysis here. i.e. detecting DIEs that are
12731 present in the abstract instance but not referenced in the concrete
12733 if (child_die
->tag
== DW_TAG_call_site
12734 || child_die
->tag
== DW_TAG_GNU_call_site
)
12737 /* For each CHILD_DIE, find the corresponding child of
12738 ORIGIN_DIE. If there is more than one layer of
12739 DW_AT_abstract_origin, follow them all; there shouldn't be,
12740 but GCC versions at least through 4.4 generate this (GCC PR
12742 child_origin_die
= child_die
;
12743 child_origin_cu
= cu
;
12746 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12750 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12754 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12755 counterpart may exist. */
12756 if (child_origin_die
!= child_die
)
12758 if (child_die
->tag
!= child_origin_die
->tag
12759 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12760 && child_origin_die
->tag
== DW_TAG_subprogram
))
12761 complaint (_("Child DIE %s and its abstract origin %s have "
12763 sect_offset_str (child_die
->sect_off
),
12764 sect_offset_str (child_origin_die
->sect_off
));
12765 if (child_origin_die
->parent
!= origin_die
)
12766 complaint (_("Child DIE %s and its abstract origin %s have "
12767 "different parents"),
12768 sect_offset_str (child_die
->sect_off
),
12769 sect_offset_str (child_origin_die
->sect_off
));
12771 offsets
.push_back (child_origin_die
->sect_off
);
12774 std::sort (offsets
.begin (), offsets
.end ());
12775 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12776 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12777 if (offsetp
[-1] == *offsetp
)
12778 complaint (_("Multiple children of DIE %s refer "
12779 "to DIE %s as their abstract origin"),
12780 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12782 offsetp
= offsets
.data ();
12783 origin_child_die
= origin_die
->child
;
12784 while (origin_child_die
&& origin_child_die
->tag
)
12786 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12787 while (offsetp
< offsets_end
12788 && *offsetp
< origin_child_die
->sect_off
)
12790 if (offsetp
>= offsets_end
12791 || *offsetp
> origin_child_die
->sect_off
)
12793 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12794 Check whether we're already processing ORIGIN_CHILD_DIE.
12795 This can happen with mutually referenced abstract_origins.
12797 if (!origin_child_die
->in_process
)
12798 process_die (origin_child_die
, origin_cu
);
12800 origin_child_die
= sibling_die (origin_child_die
);
12802 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12804 if (cu
!= origin_cu
)
12805 compute_delayed_physnames (origin_cu
);
12809 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12811 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12812 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12813 struct context_stack
*newobj
;
12816 struct die_info
*child_die
;
12817 struct attribute
*attr
, *call_line
, *call_file
;
12819 CORE_ADDR baseaddr
;
12820 struct block
*block
;
12821 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12822 std::vector
<struct symbol
*> template_args
;
12823 struct template_symbol
*templ_func
= NULL
;
12827 /* If we do not have call site information, we can't show the
12828 caller of this inlined function. That's too confusing, so
12829 only use the scope for local variables. */
12830 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12831 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12832 if (call_line
== NULL
|| call_file
== NULL
)
12834 read_lexical_block_scope (die
, cu
);
12839 baseaddr
= objfile
->text_section_offset ();
12841 name
= dwarf2_name (die
, cu
);
12843 /* Ignore functions with missing or empty names. These are actually
12844 illegal according to the DWARF standard. */
12847 complaint (_("missing name for subprogram DIE at %s"),
12848 sect_offset_str (die
->sect_off
));
12852 /* Ignore functions with missing or invalid low and high pc attributes. */
12853 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12854 <= PC_BOUNDS_INVALID
)
12856 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12857 if (!attr
|| !DW_UNSND (attr
))
12858 complaint (_("cannot get low and high bounds "
12859 "for subprogram DIE at %s"),
12860 sect_offset_str (die
->sect_off
));
12864 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12865 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12867 /* If we have any template arguments, then we must allocate a
12868 different sort of symbol. */
12869 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12871 if (child_die
->tag
== DW_TAG_template_type_param
12872 || child_die
->tag
== DW_TAG_template_value_param
)
12874 templ_func
= allocate_template_symbol (objfile
);
12875 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12880 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12881 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12882 (struct symbol
*) templ_func
);
12884 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12885 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12888 /* If there is a location expression for DW_AT_frame_base, record
12890 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12891 if (attr
!= nullptr)
12892 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12894 /* If there is a location for the static link, record it. */
12895 newobj
->static_link
= NULL
;
12896 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12897 if (attr
!= nullptr)
12899 newobj
->static_link
12900 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12901 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12902 cu
->per_cu
->addr_type ());
12905 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12907 if (die
->child
!= NULL
)
12909 child_die
= die
->child
;
12910 while (child_die
&& child_die
->tag
)
12912 if (child_die
->tag
== DW_TAG_template_type_param
12913 || child_die
->tag
== DW_TAG_template_value_param
)
12915 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12918 template_args
.push_back (arg
);
12921 process_die (child_die
, cu
);
12922 child_die
= sibling_die (child_die
);
12926 inherit_abstract_dies (die
, cu
);
12928 /* If we have a DW_AT_specification, we might need to import using
12929 directives from the context of the specification DIE. See the
12930 comment in determine_prefix. */
12931 if (cu
->language
== language_cplus
12932 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12934 struct dwarf2_cu
*spec_cu
= cu
;
12935 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12939 child_die
= spec_die
->child
;
12940 while (child_die
&& child_die
->tag
)
12942 if (child_die
->tag
== DW_TAG_imported_module
)
12943 process_die (child_die
, spec_cu
);
12944 child_die
= sibling_die (child_die
);
12947 /* In some cases, GCC generates specification DIEs that
12948 themselves contain DW_AT_specification attributes. */
12949 spec_die
= die_specification (spec_die
, &spec_cu
);
12953 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12954 /* Make a block for the local symbols within. */
12955 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12956 cstk
.static_link
, lowpc
, highpc
);
12958 /* For C++, set the block's scope. */
12959 if ((cu
->language
== language_cplus
12960 || cu
->language
== language_fortran
12961 || cu
->language
== language_d
12962 || cu
->language
== language_rust
)
12963 && cu
->processing_has_namespace_info
)
12964 block_set_scope (block
, determine_prefix (die
, cu
),
12965 &objfile
->objfile_obstack
);
12967 /* If we have address ranges, record them. */
12968 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12970 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12972 /* Attach template arguments to function. */
12973 if (!template_args
.empty ())
12975 gdb_assert (templ_func
!= NULL
);
12977 templ_func
->n_template_arguments
= template_args
.size ();
12978 templ_func
->template_arguments
12979 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12980 templ_func
->n_template_arguments
);
12981 memcpy (templ_func
->template_arguments
,
12982 template_args
.data (),
12983 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12985 /* Make sure that the symtab is set on the new symbols. Even
12986 though they don't appear in this symtab directly, other parts
12987 of gdb assume that symbols do, and this is reasonably
12989 for (symbol
*sym
: template_args
)
12990 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12993 /* In C++, we can have functions nested inside functions (e.g., when
12994 a function declares a class that has methods). This means that
12995 when we finish processing a function scope, we may need to go
12996 back to building a containing block's symbol lists. */
12997 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12998 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13000 /* If we've finished processing a top-level function, subsequent
13001 symbols go in the file symbol list. */
13002 if (cu
->get_builder ()->outermost_context_p ())
13003 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13006 /* Process all the DIES contained within a lexical block scope. Start
13007 a new scope, process the dies, and then close the scope. */
13010 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13012 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13013 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13014 CORE_ADDR lowpc
, highpc
;
13015 struct die_info
*child_die
;
13016 CORE_ADDR baseaddr
;
13018 baseaddr
= objfile
->text_section_offset ();
13020 /* Ignore blocks with missing or invalid low and high pc attributes. */
13021 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13022 as multiple lexical blocks? Handling children in a sane way would
13023 be nasty. Might be easier to properly extend generic blocks to
13024 describe ranges. */
13025 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13027 case PC_BOUNDS_NOT_PRESENT
:
13028 /* DW_TAG_lexical_block has no attributes, process its children as if
13029 there was no wrapping by that DW_TAG_lexical_block.
13030 GCC does no longer produces such DWARF since GCC r224161. */
13031 for (child_die
= die
->child
;
13032 child_die
!= NULL
&& child_die
->tag
;
13033 child_die
= sibling_die (child_die
))
13034 process_die (child_die
, cu
);
13036 case PC_BOUNDS_INVALID
:
13039 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13040 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13042 cu
->get_builder ()->push_context (0, lowpc
);
13043 if (die
->child
!= NULL
)
13045 child_die
= die
->child
;
13046 while (child_die
&& child_die
->tag
)
13048 process_die (child_die
, cu
);
13049 child_die
= sibling_die (child_die
);
13052 inherit_abstract_dies (die
, cu
);
13053 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13055 if (*cu
->get_builder ()->get_local_symbols () != NULL
13056 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13058 struct block
*block
13059 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13060 cstk
.start_addr
, highpc
);
13062 /* Note that recording ranges after traversing children, as we
13063 do here, means that recording a parent's ranges entails
13064 walking across all its children's ranges as they appear in
13065 the address map, which is quadratic behavior.
13067 It would be nicer to record the parent's ranges before
13068 traversing its children, simply overriding whatever you find
13069 there. But since we don't even decide whether to create a
13070 block until after we've traversed its children, that's hard
13072 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13074 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13075 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13078 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13081 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13083 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13084 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13085 CORE_ADDR pc
, baseaddr
;
13086 struct attribute
*attr
;
13087 struct call_site
*call_site
, call_site_local
;
13090 struct die_info
*child_die
;
13092 baseaddr
= objfile
->text_section_offset ();
13094 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13097 /* This was a pre-DWARF-5 GNU extension alias
13098 for DW_AT_call_return_pc. */
13099 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13103 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13104 "DIE %s [in module %s]"),
13105 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13108 pc
= attr
->value_as_address () + baseaddr
;
13109 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13111 if (cu
->call_site_htab
== NULL
)
13112 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13113 NULL
, &objfile
->objfile_obstack
,
13114 hashtab_obstack_allocate
, NULL
);
13115 call_site_local
.pc
= pc
;
13116 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13119 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13120 "DIE %s [in module %s]"),
13121 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13122 objfile_name (objfile
));
13126 /* Count parameters at the caller. */
13129 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13130 child_die
= sibling_die (child_die
))
13132 if (child_die
->tag
!= DW_TAG_call_site_parameter
13133 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13135 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13136 "DW_TAG_call_site child DIE %s [in module %s]"),
13137 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13138 objfile_name (objfile
));
13146 = ((struct call_site
*)
13147 obstack_alloc (&objfile
->objfile_obstack
,
13148 sizeof (*call_site
)
13149 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13151 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13152 call_site
->pc
= pc
;
13154 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13155 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13157 struct die_info
*func_die
;
13159 /* Skip also over DW_TAG_inlined_subroutine. */
13160 for (func_die
= die
->parent
;
13161 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13162 && func_die
->tag
!= DW_TAG_subroutine_type
;
13163 func_die
= func_die
->parent
);
13165 /* DW_AT_call_all_calls is a superset
13166 of DW_AT_call_all_tail_calls. */
13168 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13169 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13170 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13171 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13173 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13174 not complete. But keep CALL_SITE for look ups via call_site_htab,
13175 both the initial caller containing the real return address PC and
13176 the final callee containing the current PC of a chain of tail
13177 calls do not need to have the tail call list complete. But any
13178 function candidate for a virtual tail call frame searched via
13179 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13180 determined unambiguously. */
13184 struct type
*func_type
= NULL
;
13187 func_type
= get_die_type (func_die
, cu
);
13188 if (func_type
!= NULL
)
13190 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13192 /* Enlist this call site to the function. */
13193 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13194 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13197 complaint (_("Cannot find function owning DW_TAG_call_site "
13198 "DIE %s [in module %s]"),
13199 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13203 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13205 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13207 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13210 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13211 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13213 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13214 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13215 /* Keep NULL DWARF_BLOCK. */;
13216 else if (attr
->form_is_block ())
13218 struct dwarf2_locexpr_baton
*dlbaton
;
13220 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13221 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13222 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13223 dlbaton
->per_cu
= cu
->per_cu
;
13225 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13227 else if (attr
->form_is_ref ())
13229 struct dwarf2_cu
*target_cu
= cu
;
13230 struct die_info
*target_die
;
13232 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13233 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13234 if (die_is_declaration (target_die
, target_cu
))
13236 const char *target_physname
;
13238 /* Prefer the mangled name; otherwise compute the demangled one. */
13239 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13240 if (target_physname
== NULL
)
13241 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13242 if (target_physname
== NULL
)
13243 complaint (_("DW_AT_call_target target DIE has invalid "
13244 "physname, for referencing DIE %s [in module %s]"),
13245 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13247 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13253 /* DW_AT_entry_pc should be preferred. */
13254 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13255 <= PC_BOUNDS_INVALID
)
13256 complaint (_("DW_AT_call_target target DIE has invalid "
13257 "low pc, for referencing DIE %s [in module %s]"),
13258 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13261 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13262 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13267 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13268 "block nor reference, for DIE %s [in module %s]"),
13269 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13271 call_site
->per_cu
= cu
->per_cu
;
13273 for (child_die
= die
->child
;
13274 child_die
&& child_die
->tag
;
13275 child_die
= sibling_die (child_die
))
13277 struct call_site_parameter
*parameter
;
13278 struct attribute
*loc
, *origin
;
13280 if (child_die
->tag
!= DW_TAG_call_site_parameter
13281 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13283 /* Already printed the complaint above. */
13287 gdb_assert (call_site
->parameter_count
< nparams
);
13288 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13290 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13291 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13292 register is contained in DW_AT_call_value. */
13294 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13295 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13296 if (origin
== NULL
)
13298 /* This was a pre-DWARF-5 GNU extension alias
13299 for DW_AT_call_parameter. */
13300 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13302 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13304 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13306 sect_offset sect_off
13307 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13308 if (!cu
->header
.offset_in_cu_p (sect_off
))
13310 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13311 binding can be done only inside one CU. Such referenced DIE
13312 therefore cannot be even moved to DW_TAG_partial_unit. */
13313 complaint (_("DW_AT_call_parameter offset is not in CU for "
13314 "DW_TAG_call_site child DIE %s [in module %s]"),
13315 sect_offset_str (child_die
->sect_off
),
13316 objfile_name (objfile
));
13319 parameter
->u
.param_cu_off
13320 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13322 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13324 complaint (_("No DW_FORM_block* DW_AT_location for "
13325 "DW_TAG_call_site child DIE %s [in module %s]"),
13326 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13331 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13332 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13333 if (parameter
->u
.dwarf_reg
!= -1)
13334 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13335 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13336 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13337 ¶meter
->u
.fb_offset
))
13338 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13341 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13342 "for DW_FORM_block* DW_AT_location is supported for "
13343 "DW_TAG_call_site child DIE %s "
13345 sect_offset_str (child_die
->sect_off
),
13346 objfile_name (objfile
));
13351 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13353 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13354 if (attr
== NULL
|| !attr
->form_is_block ())
13356 complaint (_("No DW_FORM_block* DW_AT_call_value 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
->value
= DW_BLOCK (attr
)->data
;
13363 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13365 /* Parameters are not pre-cleared by memset above. */
13366 parameter
->data_value
= NULL
;
13367 parameter
->data_value_size
= 0;
13368 call_site
->parameter_count
++;
13370 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13372 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13373 if (attr
!= nullptr)
13375 if (!attr
->form_is_block ())
13376 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13377 "DW_TAG_call_site child DIE %s [in module %s]"),
13378 sect_offset_str (child_die
->sect_off
),
13379 objfile_name (objfile
));
13382 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13383 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13389 /* Helper function for read_variable. If DIE represents a virtual
13390 table, then return the type of the concrete object that is
13391 associated with the virtual table. Otherwise, return NULL. */
13393 static struct type
*
13394 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13396 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13400 /* Find the type DIE. */
13401 struct die_info
*type_die
= NULL
;
13402 struct dwarf2_cu
*type_cu
= cu
;
13404 if (attr
->form_is_ref ())
13405 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13406 if (type_die
== NULL
)
13409 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13411 return die_containing_type (type_die
, type_cu
);
13414 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13417 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13419 struct rust_vtable_symbol
*storage
= NULL
;
13421 if (cu
->language
== language_rust
)
13423 struct type
*containing_type
= rust_containing_type (die
, cu
);
13425 if (containing_type
!= NULL
)
13427 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13429 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13430 initialize_objfile_symbol (storage
);
13431 storage
->concrete_type
= containing_type
;
13432 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13436 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13437 struct attribute
*abstract_origin
13438 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13439 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13440 if (res
== NULL
&& loc
&& abstract_origin
)
13442 /* We have a variable without a name, but with a location and an abstract
13443 origin. This may be a concrete instance of an abstract variable
13444 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13446 struct dwarf2_cu
*origin_cu
= cu
;
13447 struct die_info
*origin_die
13448 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13449 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13450 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13454 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13455 reading .debug_rnglists.
13456 Callback's type should be:
13457 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13458 Return true if the attributes are present and valid, otherwise,
13461 template <typename Callback
>
13463 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13464 Callback
&&callback
)
13466 struct dwarf2_per_objfile
*dwarf2_per_objfile
13467 = cu
->per_cu
->dwarf2_per_objfile
;
13468 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13469 bfd
*obfd
= objfile
->obfd
;
13470 /* Base address selection entry. */
13473 const gdb_byte
*buffer
;
13474 CORE_ADDR baseaddr
;
13475 bool overflow
= false;
13477 found_base
= cu
->base_known
;
13478 base
= cu
->base_address
;
13480 dwarf2_per_objfile
->rnglists
.read (objfile
);
13481 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13483 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13487 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13489 baseaddr
= objfile
->text_section_offset ();
13493 /* Initialize it due to a false compiler warning. */
13494 CORE_ADDR range_beginning
= 0, range_end
= 0;
13495 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13496 + dwarf2_per_objfile
->rnglists
.size
);
13497 unsigned int bytes_read
;
13499 if (buffer
== buf_end
)
13504 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13507 case DW_RLE_end_of_list
:
13509 case DW_RLE_base_address
:
13510 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13515 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13517 buffer
+= bytes_read
;
13519 case DW_RLE_start_length
:
13520 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13525 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13527 buffer
+= bytes_read
;
13528 range_end
= (range_beginning
13529 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13530 buffer
+= bytes_read
;
13531 if (buffer
> buf_end
)
13537 case DW_RLE_offset_pair
:
13538 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13539 buffer
+= bytes_read
;
13540 if (buffer
> buf_end
)
13545 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13546 buffer
+= bytes_read
;
13547 if (buffer
> buf_end
)
13553 case DW_RLE_start_end
:
13554 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13559 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13561 buffer
+= bytes_read
;
13562 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13563 buffer
+= bytes_read
;
13566 complaint (_("Invalid .debug_rnglists data (no base address)"));
13569 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13571 if (rlet
== DW_RLE_base_address
)
13576 /* We have no valid base address for the ranges
13578 complaint (_("Invalid .debug_rnglists data (no base address)"));
13582 if (range_beginning
> range_end
)
13584 /* Inverted range entries are invalid. */
13585 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13589 /* Empty range entries have no effect. */
13590 if (range_beginning
== range_end
)
13593 range_beginning
+= base
;
13596 /* A not-uncommon case of bad debug info.
13597 Don't pollute the addrmap with bad data. */
13598 if (range_beginning
+ baseaddr
== 0
13599 && !dwarf2_per_objfile
->has_section_at_zero
)
13601 complaint (_(".debug_rnglists entry has start address of zero"
13602 " [in module %s]"), objfile_name (objfile
));
13606 callback (range_beginning
, range_end
);
13611 complaint (_("Offset %d is not terminated "
13612 "for DW_AT_ranges attribute"),
13620 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13621 Callback's type should be:
13622 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13623 Return 1 if the attributes are present and valid, otherwise, return 0. */
13625 template <typename Callback
>
13627 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13628 Callback
&&callback
)
13630 struct dwarf2_per_objfile
*dwarf2_per_objfile
13631 = cu
->per_cu
->dwarf2_per_objfile
;
13632 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13633 struct comp_unit_head
*cu_header
= &cu
->header
;
13634 bfd
*obfd
= objfile
->obfd
;
13635 unsigned int addr_size
= cu_header
->addr_size
;
13636 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13637 /* Base address selection entry. */
13640 unsigned int dummy
;
13641 const gdb_byte
*buffer
;
13642 CORE_ADDR baseaddr
;
13644 if (cu_header
->version
>= 5)
13645 return dwarf2_rnglists_process (offset
, cu
, callback
);
13647 found_base
= cu
->base_known
;
13648 base
= cu
->base_address
;
13650 dwarf2_per_objfile
->ranges
.read (objfile
);
13651 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13653 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13657 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13659 baseaddr
= objfile
->text_section_offset ();
13663 CORE_ADDR range_beginning
, range_end
;
13665 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13666 buffer
+= addr_size
;
13667 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13668 buffer
+= addr_size
;
13669 offset
+= 2 * addr_size
;
13671 /* An end of list marker is a pair of zero addresses. */
13672 if (range_beginning
== 0 && range_end
== 0)
13673 /* Found the end of list entry. */
13676 /* Each base address selection entry is a pair of 2 values.
13677 The first is the largest possible address, the second is
13678 the base address. Check for a base address here. */
13679 if ((range_beginning
& mask
) == mask
)
13681 /* If we found the largest possible address, then we already
13682 have the base address in range_end. */
13690 /* We have no valid base address for the ranges
13692 complaint (_("Invalid .debug_ranges data (no base address)"));
13696 if (range_beginning
> range_end
)
13698 /* Inverted range entries are invalid. */
13699 complaint (_("Invalid .debug_ranges data (inverted range)"));
13703 /* Empty range entries have no effect. */
13704 if (range_beginning
== range_end
)
13707 range_beginning
+= base
;
13710 /* A not-uncommon case of bad debug info.
13711 Don't pollute the addrmap with bad data. */
13712 if (range_beginning
+ baseaddr
== 0
13713 && !dwarf2_per_objfile
->has_section_at_zero
)
13715 complaint (_(".debug_ranges entry has start address of zero"
13716 " [in module %s]"), objfile_name (objfile
));
13720 callback (range_beginning
, range_end
);
13726 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13727 Return 1 if the attributes are present and valid, otherwise, return 0.
13728 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13731 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13732 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13733 dwarf2_psymtab
*ranges_pst
)
13735 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13736 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13737 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13740 CORE_ADDR high
= 0;
13743 retval
= dwarf2_ranges_process (offset
, cu
,
13744 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13746 if (ranges_pst
!= NULL
)
13751 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13752 range_beginning
+ baseaddr
)
13754 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13755 range_end
+ baseaddr
)
13757 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13758 lowpc
, highpc
- 1, ranges_pst
);
13761 /* FIXME: This is recording everything as a low-high
13762 segment of consecutive addresses. We should have a
13763 data structure for discontiguous block ranges
13767 low
= range_beginning
;
13773 if (range_beginning
< low
)
13774 low
= range_beginning
;
13775 if (range_end
> high
)
13783 /* If the first entry is an end-of-list marker, the range
13784 describes an empty scope, i.e. no instructions. */
13790 *high_return
= high
;
13794 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13795 definition for the return value. *LOWPC and *HIGHPC are set iff
13796 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13798 static enum pc_bounds_kind
13799 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13800 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13801 dwarf2_psymtab
*pst
)
13803 struct dwarf2_per_objfile
*dwarf2_per_objfile
13804 = cu
->per_cu
->dwarf2_per_objfile
;
13805 struct attribute
*attr
;
13806 struct attribute
*attr_high
;
13808 CORE_ADDR high
= 0;
13809 enum pc_bounds_kind ret
;
13811 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13814 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13815 if (attr
!= nullptr)
13817 low
= attr
->value_as_address ();
13818 high
= attr_high
->value_as_address ();
13819 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13823 /* Found high w/o low attribute. */
13824 return PC_BOUNDS_INVALID
;
13826 /* Found consecutive range of addresses. */
13827 ret
= PC_BOUNDS_HIGH_LOW
;
13831 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13834 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13835 We take advantage of the fact that DW_AT_ranges does not appear
13836 in DW_TAG_compile_unit of DWO files. */
13837 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13838 unsigned int ranges_offset
= (DW_UNSND (attr
)
13839 + (need_ranges_base
13843 /* Value of the DW_AT_ranges attribute is the offset in the
13844 .debug_ranges section. */
13845 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13846 return PC_BOUNDS_INVALID
;
13847 /* Found discontinuous range of addresses. */
13848 ret
= PC_BOUNDS_RANGES
;
13851 return PC_BOUNDS_NOT_PRESENT
;
13854 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13856 return PC_BOUNDS_INVALID
;
13858 /* When using the GNU linker, .gnu.linkonce. sections are used to
13859 eliminate duplicate copies of functions and vtables and such.
13860 The linker will arbitrarily choose one and discard the others.
13861 The AT_*_pc values for such functions refer to local labels in
13862 these sections. If the section from that file was discarded, the
13863 labels are not in the output, so the relocs get a value of 0.
13864 If this is a discarded function, mark the pc bounds as invalid,
13865 so that GDB will ignore it. */
13866 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13867 return PC_BOUNDS_INVALID
;
13875 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13876 its low and high PC addresses. Do nothing if these addresses could not
13877 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13878 and HIGHPC to the high address if greater than HIGHPC. */
13881 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13882 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13883 struct dwarf2_cu
*cu
)
13885 CORE_ADDR low
, high
;
13886 struct die_info
*child
= die
->child
;
13888 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13890 *lowpc
= std::min (*lowpc
, low
);
13891 *highpc
= std::max (*highpc
, high
);
13894 /* If the language does not allow nested subprograms (either inside
13895 subprograms or lexical blocks), we're done. */
13896 if (cu
->language
!= language_ada
)
13899 /* Check all the children of the given DIE. If it contains nested
13900 subprograms, then check their pc bounds. Likewise, we need to
13901 check lexical blocks as well, as they may also contain subprogram
13903 while (child
&& child
->tag
)
13905 if (child
->tag
== DW_TAG_subprogram
13906 || child
->tag
== DW_TAG_lexical_block
)
13907 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13908 child
= sibling_die (child
);
13912 /* Get the low and high pc's represented by the scope DIE, and store
13913 them in *LOWPC and *HIGHPC. If the correct values can't be
13914 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13917 get_scope_pc_bounds (struct die_info
*die
,
13918 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13919 struct dwarf2_cu
*cu
)
13921 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13922 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13923 CORE_ADDR current_low
, current_high
;
13925 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13926 >= PC_BOUNDS_RANGES
)
13928 best_low
= current_low
;
13929 best_high
= current_high
;
13933 struct die_info
*child
= die
->child
;
13935 while (child
&& child
->tag
)
13937 switch (child
->tag
) {
13938 case DW_TAG_subprogram
:
13939 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13941 case DW_TAG_namespace
:
13942 case DW_TAG_module
:
13943 /* FIXME: carlton/2004-01-16: Should we do this for
13944 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13945 that current GCC's always emit the DIEs corresponding
13946 to definitions of methods of classes as children of a
13947 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13948 the DIEs giving the declarations, which could be
13949 anywhere). But I don't see any reason why the
13950 standards says that they have to be there. */
13951 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13953 if (current_low
!= ((CORE_ADDR
) -1))
13955 best_low
= std::min (best_low
, current_low
);
13956 best_high
= std::max (best_high
, current_high
);
13964 child
= sibling_die (child
);
13969 *highpc
= best_high
;
13972 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13976 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13977 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13979 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13980 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13981 struct attribute
*attr
;
13982 struct attribute
*attr_high
;
13984 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13987 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13988 if (attr
!= nullptr)
13990 CORE_ADDR low
= attr
->value_as_address ();
13991 CORE_ADDR high
= attr_high
->value_as_address ();
13993 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13996 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13997 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13998 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14002 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14003 if (attr
!= nullptr)
14005 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14006 We take advantage of the fact that DW_AT_ranges does not appear
14007 in DW_TAG_compile_unit of DWO files. */
14008 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14010 /* The value of the DW_AT_ranges attribute is the offset of the
14011 address range list in the .debug_ranges section. */
14012 unsigned long offset
= (DW_UNSND (attr
)
14013 + (need_ranges_base
? cu
->ranges_base
: 0));
14015 std::vector
<blockrange
> blockvec
;
14016 dwarf2_ranges_process (offset
, cu
,
14017 [&] (CORE_ADDR start
, CORE_ADDR end
)
14021 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14022 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14023 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14024 blockvec
.emplace_back (start
, end
);
14027 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14031 /* Check whether the producer field indicates either of GCC < 4.6, or the
14032 Intel C/C++ compiler, and cache the result in CU. */
14035 check_producer (struct dwarf2_cu
*cu
)
14039 if (cu
->producer
== NULL
)
14041 /* For unknown compilers expect their behavior is DWARF version
14044 GCC started to support .debug_types sections by -gdwarf-4 since
14045 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14046 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14047 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14048 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14050 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14052 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14053 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14055 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14057 cu
->producer_is_icc
= true;
14058 cu
->producer_is_icc_lt_14
= major
< 14;
14060 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14061 cu
->producer_is_codewarrior
= true;
14064 /* For other non-GCC compilers, expect their behavior is DWARF version
14068 cu
->checked_producer
= true;
14071 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14072 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14073 during 4.6.0 experimental. */
14076 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14078 if (!cu
->checked_producer
)
14079 check_producer (cu
);
14081 return cu
->producer_is_gxx_lt_4_6
;
14085 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14086 with incorrect is_stmt attributes. */
14089 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14091 if (!cu
->checked_producer
)
14092 check_producer (cu
);
14094 return cu
->producer_is_codewarrior
;
14097 /* Return the default accessibility type if it is not overridden by
14098 DW_AT_accessibility. */
14100 static enum dwarf_access_attribute
14101 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14103 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14105 /* The default DWARF 2 accessibility for members is public, the default
14106 accessibility for inheritance is private. */
14108 if (die
->tag
!= DW_TAG_inheritance
)
14109 return DW_ACCESS_public
;
14111 return DW_ACCESS_private
;
14115 /* DWARF 3+ defines the default accessibility a different way. The same
14116 rules apply now for DW_TAG_inheritance as for the members and it only
14117 depends on the container kind. */
14119 if (die
->parent
->tag
== DW_TAG_class_type
)
14120 return DW_ACCESS_private
;
14122 return DW_ACCESS_public
;
14126 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14127 offset. If the attribute was not found return 0, otherwise return
14128 1. If it was found but could not properly be handled, set *OFFSET
14132 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14135 struct attribute
*attr
;
14137 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14142 /* Note that we do not check for a section offset first here.
14143 This is because DW_AT_data_member_location is new in DWARF 4,
14144 so if we see it, we can assume that a constant form is really
14145 a constant and not a section offset. */
14146 if (attr
->form_is_constant ())
14147 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14148 else if (attr
->form_is_section_offset ())
14149 dwarf2_complex_location_expr_complaint ();
14150 else if (attr
->form_is_block ())
14151 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14153 dwarf2_complex_location_expr_complaint ();
14161 /* Add an aggregate field to the field list. */
14164 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14165 struct dwarf2_cu
*cu
)
14167 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14168 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14169 struct nextfield
*new_field
;
14170 struct attribute
*attr
;
14172 const char *fieldname
= "";
14174 if (die
->tag
== DW_TAG_inheritance
)
14176 fip
->baseclasses
.emplace_back ();
14177 new_field
= &fip
->baseclasses
.back ();
14181 fip
->fields
.emplace_back ();
14182 new_field
= &fip
->fields
.back ();
14187 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14188 if (attr
!= nullptr)
14189 new_field
->accessibility
= DW_UNSND (attr
);
14191 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14192 if (new_field
->accessibility
!= DW_ACCESS_public
)
14193 fip
->non_public_fields
= 1;
14195 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14196 if (attr
!= nullptr)
14197 new_field
->virtuality
= DW_UNSND (attr
);
14199 new_field
->virtuality
= DW_VIRTUALITY_none
;
14201 fp
= &new_field
->field
;
14203 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14207 /* Data member other than a C++ static data member. */
14209 /* Get type of field. */
14210 fp
->type
= die_type (die
, cu
);
14212 SET_FIELD_BITPOS (*fp
, 0);
14214 /* Get bit size of field (zero if none). */
14215 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14216 if (attr
!= nullptr)
14218 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14222 FIELD_BITSIZE (*fp
) = 0;
14225 /* Get bit offset of field. */
14226 if (handle_data_member_location (die
, cu
, &offset
))
14227 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14228 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14229 if (attr
!= nullptr)
14231 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14233 /* For big endian bits, the DW_AT_bit_offset gives the
14234 additional bit offset from the MSB of the containing
14235 anonymous object to the MSB of the field. We don't
14236 have to do anything special since we don't need to
14237 know the size of the anonymous object. */
14238 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14242 /* For little endian bits, compute the bit offset to the
14243 MSB of the anonymous object, subtract off the number of
14244 bits from the MSB of the field to the MSB of the
14245 object, and then subtract off the number of bits of
14246 the field itself. The result is the bit offset of
14247 the LSB of the field. */
14248 int anonymous_size
;
14249 int bit_offset
= DW_UNSND (attr
);
14251 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14252 if (attr
!= nullptr)
14254 /* The size of the anonymous object containing
14255 the bit field is explicit, so use the
14256 indicated size (in bytes). */
14257 anonymous_size
= DW_UNSND (attr
);
14261 /* The size of the anonymous object containing
14262 the bit field must be inferred from the type
14263 attribute of the data member containing the
14265 anonymous_size
= TYPE_LENGTH (fp
->type
);
14267 SET_FIELD_BITPOS (*fp
,
14268 (FIELD_BITPOS (*fp
)
14269 + anonymous_size
* bits_per_byte
14270 - bit_offset
- FIELD_BITSIZE (*fp
)));
14273 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14275 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14276 + dwarf2_get_attr_constant_value (attr
, 0)));
14278 /* Get name of field. */
14279 fieldname
= dwarf2_name (die
, cu
);
14280 if (fieldname
== NULL
)
14283 /* The name is already allocated along with this objfile, so we don't
14284 need to duplicate it for the type. */
14285 fp
->name
= fieldname
;
14287 /* Change accessibility for artificial fields (e.g. virtual table
14288 pointer or virtual base class pointer) to private. */
14289 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14291 FIELD_ARTIFICIAL (*fp
) = 1;
14292 new_field
->accessibility
= DW_ACCESS_private
;
14293 fip
->non_public_fields
= 1;
14296 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14298 /* C++ static member. */
14300 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14301 is a declaration, but all versions of G++ as of this writing
14302 (so through at least 3.2.1) incorrectly generate
14303 DW_TAG_variable tags. */
14305 const char *physname
;
14307 /* Get name of field. */
14308 fieldname
= dwarf2_name (die
, cu
);
14309 if (fieldname
== NULL
)
14312 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14314 /* Only create a symbol if this is an external value.
14315 new_symbol checks this and puts the value in the global symbol
14316 table, which we want. If it is not external, new_symbol
14317 will try to put the value in cu->list_in_scope which is wrong. */
14318 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14320 /* A static const member, not much different than an enum as far as
14321 we're concerned, except that we can support more types. */
14322 new_symbol (die
, NULL
, cu
);
14325 /* Get physical name. */
14326 physname
= dwarf2_physname (fieldname
, die
, cu
);
14328 /* The name is already allocated along with this objfile, so we don't
14329 need to duplicate it for the type. */
14330 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14331 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14332 FIELD_NAME (*fp
) = fieldname
;
14334 else if (die
->tag
== DW_TAG_inheritance
)
14338 /* C++ base class field. */
14339 if (handle_data_member_location (die
, cu
, &offset
))
14340 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14341 FIELD_BITSIZE (*fp
) = 0;
14342 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14343 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14345 else if (die
->tag
== DW_TAG_variant_part
)
14347 /* process_structure_scope will treat this DIE as a union. */
14348 process_structure_scope (die
, cu
);
14350 /* The variant part is relative to the start of the enclosing
14352 SET_FIELD_BITPOS (*fp
, 0);
14353 fp
->type
= get_die_type (die
, cu
);
14354 fp
->artificial
= 1;
14355 fp
->name
= "<<variant>>";
14357 /* Normally a DW_TAG_variant_part won't have a size, but our
14358 representation requires one, so set it to the maximum of the
14359 child sizes, being sure to account for the offset at which
14360 each child is seen. */
14361 if (TYPE_LENGTH (fp
->type
) == 0)
14364 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14366 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14367 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14371 TYPE_LENGTH (fp
->type
) = max
;
14375 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14378 /* Can the type given by DIE define another type? */
14381 type_can_define_types (const struct die_info
*die
)
14385 case DW_TAG_typedef
:
14386 case DW_TAG_class_type
:
14387 case DW_TAG_structure_type
:
14388 case DW_TAG_union_type
:
14389 case DW_TAG_enumeration_type
:
14397 /* Add a type definition defined in the scope of the FIP's class. */
14400 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14401 struct dwarf2_cu
*cu
)
14403 struct decl_field fp
;
14404 memset (&fp
, 0, sizeof (fp
));
14406 gdb_assert (type_can_define_types (die
));
14408 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14409 fp
.name
= dwarf2_name (die
, cu
);
14410 fp
.type
= read_type_die (die
, cu
);
14412 /* Save accessibility. */
14413 enum dwarf_access_attribute accessibility
;
14414 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14416 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14418 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14419 switch (accessibility
)
14421 case DW_ACCESS_public
:
14422 /* The assumed value if neither private nor protected. */
14424 case DW_ACCESS_private
:
14427 case DW_ACCESS_protected
:
14428 fp
.is_protected
= 1;
14431 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14434 if (die
->tag
== DW_TAG_typedef
)
14435 fip
->typedef_field_list
.push_back (fp
);
14437 fip
->nested_types_list
.push_back (fp
);
14440 /* Create the vector of fields, and attach it to the type. */
14443 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14444 struct dwarf2_cu
*cu
)
14446 int nfields
= fip
->nfields
;
14448 /* Record the field count, allocate space for the array of fields,
14449 and create blank accessibility bitfields if necessary. */
14450 TYPE_NFIELDS (type
) = nfields
;
14451 TYPE_FIELDS (type
) = (struct field
*)
14452 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14454 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14456 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14458 TYPE_FIELD_PRIVATE_BITS (type
) =
14459 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14460 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14462 TYPE_FIELD_PROTECTED_BITS (type
) =
14463 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14464 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14466 TYPE_FIELD_IGNORE_BITS (type
) =
14467 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14468 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14471 /* If the type has baseclasses, allocate and clear a bit vector for
14472 TYPE_FIELD_VIRTUAL_BITS. */
14473 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14475 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14476 unsigned char *pointer
;
14478 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14479 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14480 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14481 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14482 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14485 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14487 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14489 for (int index
= 0; index
< nfields
; ++index
)
14491 struct nextfield
&field
= fip
->fields
[index
];
14493 if (field
.variant
.is_discriminant
)
14494 di
->discriminant_index
= index
;
14495 else if (field
.variant
.default_branch
)
14496 di
->default_index
= index
;
14498 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14502 /* Copy the saved-up fields into the field vector. */
14503 for (int i
= 0; i
< nfields
; ++i
)
14505 struct nextfield
&field
14506 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14507 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14509 TYPE_FIELD (type
, i
) = field
.field
;
14510 switch (field
.accessibility
)
14512 case DW_ACCESS_private
:
14513 if (cu
->language
!= language_ada
)
14514 SET_TYPE_FIELD_PRIVATE (type
, i
);
14517 case DW_ACCESS_protected
:
14518 if (cu
->language
!= language_ada
)
14519 SET_TYPE_FIELD_PROTECTED (type
, i
);
14522 case DW_ACCESS_public
:
14526 /* Unknown accessibility. Complain and treat it as public. */
14528 complaint (_("unsupported accessibility %d"),
14529 field
.accessibility
);
14533 if (i
< fip
->baseclasses
.size ())
14535 switch (field
.virtuality
)
14537 case DW_VIRTUALITY_virtual
:
14538 case DW_VIRTUALITY_pure_virtual
:
14539 if (cu
->language
== language_ada
)
14540 error (_("unexpected virtuality in component of Ada type"));
14541 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14548 /* Return true if this member function is a constructor, false
14552 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14554 const char *fieldname
;
14555 const char *type_name
;
14558 if (die
->parent
== NULL
)
14561 if (die
->parent
->tag
!= DW_TAG_structure_type
14562 && die
->parent
->tag
!= DW_TAG_union_type
14563 && die
->parent
->tag
!= DW_TAG_class_type
)
14566 fieldname
= dwarf2_name (die
, cu
);
14567 type_name
= dwarf2_name (die
->parent
, cu
);
14568 if (fieldname
== NULL
|| type_name
== NULL
)
14571 len
= strlen (fieldname
);
14572 return (strncmp (fieldname
, type_name
, len
) == 0
14573 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14576 /* Check if the given VALUE is a recognized enum
14577 dwarf_defaulted_attribute constant according to DWARF5 spec,
14581 is_valid_DW_AT_defaulted (ULONGEST value
)
14585 case DW_DEFAULTED_no
:
14586 case DW_DEFAULTED_in_class
:
14587 case DW_DEFAULTED_out_of_class
:
14591 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14595 /* Add a member function to the proper fieldlist. */
14598 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14599 struct type
*type
, struct dwarf2_cu
*cu
)
14601 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14602 struct attribute
*attr
;
14604 struct fnfieldlist
*flp
= nullptr;
14605 struct fn_field
*fnp
;
14606 const char *fieldname
;
14607 struct type
*this_type
;
14608 enum dwarf_access_attribute accessibility
;
14610 if (cu
->language
== language_ada
)
14611 error (_("unexpected member function in Ada type"));
14613 /* Get name of member function. */
14614 fieldname
= dwarf2_name (die
, cu
);
14615 if (fieldname
== NULL
)
14618 /* Look up member function name in fieldlist. */
14619 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14621 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14623 flp
= &fip
->fnfieldlists
[i
];
14628 /* Create a new fnfieldlist if necessary. */
14629 if (flp
== nullptr)
14631 fip
->fnfieldlists
.emplace_back ();
14632 flp
= &fip
->fnfieldlists
.back ();
14633 flp
->name
= fieldname
;
14634 i
= fip
->fnfieldlists
.size () - 1;
14637 /* Create a new member function field and add it to the vector of
14639 flp
->fnfields
.emplace_back ();
14640 fnp
= &flp
->fnfields
.back ();
14642 /* Delay processing of the physname until later. */
14643 if (cu
->language
== language_cplus
)
14644 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14648 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14649 fnp
->physname
= physname
? physname
: "";
14652 fnp
->type
= alloc_type (objfile
);
14653 this_type
= read_type_die (die
, cu
);
14654 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14656 int nparams
= TYPE_NFIELDS (this_type
);
14658 /* TYPE is the domain of this method, and THIS_TYPE is the type
14659 of the method itself (TYPE_CODE_METHOD). */
14660 smash_to_method_type (fnp
->type
, type
,
14661 TYPE_TARGET_TYPE (this_type
),
14662 TYPE_FIELDS (this_type
),
14663 TYPE_NFIELDS (this_type
),
14664 TYPE_VARARGS (this_type
));
14666 /* Handle static member functions.
14667 Dwarf2 has no clean way to discern C++ static and non-static
14668 member functions. G++ helps GDB by marking the first
14669 parameter for non-static member functions (which is the this
14670 pointer) as artificial. We obtain this information from
14671 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14672 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14673 fnp
->voffset
= VOFFSET_STATIC
;
14676 complaint (_("member function type missing for '%s'"),
14677 dwarf2_full_name (fieldname
, die
, cu
));
14679 /* Get fcontext from DW_AT_containing_type if present. */
14680 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14681 fnp
->fcontext
= die_containing_type (die
, cu
);
14683 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14684 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14686 /* Get accessibility. */
14687 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14688 if (attr
!= nullptr)
14689 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14691 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14692 switch (accessibility
)
14694 case DW_ACCESS_private
:
14695 fnp
->is_private
= 1;
14697 case DW_ACCESS_protected
:
14698 fnp
->is_protected
= 1;
14702 /* Check for artificial methods. */
14703 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14704 if (attr
&& DW_UNSND (attr
) != 0)
14705 fnp
->is_artificial
= 1;
14707 /* Check for defaulted methods. */
14708 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14709 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14710 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14712 /* Check for deleted methods. */
14713 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14714 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14715 fnp
->is_deleted
= 1;
14717 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14719 /* Get index in virtual function table if it is a virtual member
14720 function. For older versions of GCC, this is an offset in the
14721 appropriate virtual table, as specified by DW_AT_containing_type.
14722 For everyone else, it is an expression to be evaluated relative
14723 to the object address. */
14725 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14726 if (attr
!= nullptr)
14728 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14730 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14732 /* Old-style GCC. */
14733 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14735 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14736 || (DW_BLOCK (attr
)->size
> 1
14737 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14738 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14740 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14741 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14742 dwarf2_complex_location_expr_complaint ();
14744 fnp
->voffset
/= cu
->header
.addr_size
;
14748 dwarf2_complex_location_expr_complaint ();
14750 if (!fnp
->fcontext
)
14752 /* If there is no `this' field and no DW_AT_containing_type,
14753 we cannot actually find a base class context for the
14755 if (TYPE_NFIELDS (this_type
) == 0
14756 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14758 complaint (_("cannot determine context for virtual member "
14759 "function \"%s\" (offset %s)"),
14760 fieldname
, sect_offset_str (die
->sect_off
));
14765 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14769 else if (attr
->form_is_section_offset ())
14771 dwarf2_complex_location_expr_complaint ();
14775 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14781 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14782 if (attr
&& DW_UNSND (attr
))
14784 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14785 complaint (_("Member function \"%s\" (offset %s) is virtual "
14786 "but the vtable offset is not specified"),
14787 fieldname
, sect_offset_str (die
->sect_off
));
14788 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14789 TYPE_CPLUS_DYNAMIC (type
) = 1;
14794 /* Create the vector of member function fields, and attach it to the type. */
14797 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14798 struct dwarf2_cu
*cu
)
14800 if (cu
->language
== language_ada
)
14801 error (_("unexpected member functions in Ada type"));
14803 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14804 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14806 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14808 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14810 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14811 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14813 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14814 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14815 fn_flp
->fn_fields
= (struct fn_field
*)
14816 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14818 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14819 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14822 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14825 /* Returns non-zero if NAME is the name of a vtable member in CU's
14826 language, zero otherwise. */
14828 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14830 static const char vptr
[] = "_vptr";
14832 /* Look for the C++ form of the vtable. */
14833 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14839 /* GCC outputs unnamed structures that are really pointers to member
14840 functions, with the ABI-specified layout. If TYPE describes
14841 such a structure, smash it into a member function type.
14843 GCC shouldn't do this; it should just output pointer to member DIEs.
14844 This is GCC PR debug/28767. */
14847 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14849 struct type
*pfn_type
, *self_type
, *new_type
;
14851 /* Check for a structure with no name and two children. */
14852 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14855 /* Check for __pfn and __delta members. */
14856 if (TYPE_FIELD_NAME (type
, 0) == NULL
14857 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14858 || TYPE_FIELD_NAME (type
, 1) == NULL
14859 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14862 /* Find the type of the method. */
14863 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14864 if (pfn_type
== NULL
14865 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14866 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14869 /* Look for the "this" argument. */
14870 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14871 if (TYPE_NFIELDS (pfn_type
) == 0
14872 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14873 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14876 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14877 new_type
= alloc_type (objfile
);
14878 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14879 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14880 TYPE_VARARGS (pfn_type
));
14881 smash_to_methodptr_type (type
, new_type
);
14884 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14885 appropriate error checking and issuing complaints if there is a
14889 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14891 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14893 if (attr
== nullptr)
14896 if (!attr
->form_is_constant ())
14898 complaint (_("DW_AT_alignment must have constant form"
14899 " - DIE at %s [in module %s]"),
14900 sect_offset_str (die
->sect_off
),
14901 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14906 if (attr
->form
== DW_FORM_sdata
)
14908 LONGEST val
= DW_SND (attr
);
14911 complaint (_("DW_AT_alignment value must not be negative"
14912 " - DIE at %s [in module %s]"),
14913 sect_offset_str (die
->sect_off
),
14914 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14920 align
= DW_UNSND (attr
);
14924 complaint (_("DW_AT_alignment value must not be zero"
14925 " - DIE at %s [in module %s]"),
14926 sect_offset_str (die
->sect_off
),
14927 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14930 if ((align
& (align
- 1)) != 0)
14932 complaint (_("DW_AT_alignment value must be a power of 2"
14933 " - DIE at %s [in module %s]"),
14934 sect_offset_str (die
->sect_off
),
14935 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14942 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14943 the alignment for TYPE. */
14946 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14949 if (!set_type_align (type
, get_alignment (cu
, die
)))
14950 complaint (_("DW_AT_alignment value too large"
14951 " - DIE at %s [in module %s]"),
14952 sect_offset_str (die
->sect_off
),
14953 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14956 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14957 constant for a type, according to DWARF5 spec, Table 5.5. */
14960 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14965 case DW_CC_pass_by_reference
:
14966 case DW_CC_pass_by_value
:
14970 complaint (_("unrecognized DW_AT_calling_convention value "
14971 "(%s) for a type"), pulongest (value
));
14976 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14977 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14978 also according to GNU-specific values (see include/dwarf2.h). */
14981 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14986 case DW_CC_program
:
14990 case DW_CC_GNU_renesas_sh
:
14991 case DW_CC_GNU_borland_fastcall_i386
:
14992 case DW_CC_GDB_IBM_OpenCL
:
14996 complaint (_("unrecognized DW_AT_calling_convention value "
14997 "(%s) for a subroutine"), pulongest (value
));
15002 /* Called when we find the DIE that starts a structure or union scope
15003 (definition) to create a type for the structure or union. Fill in
15004 the type's name and general properties; the members will not be
15005 processed until process_structure_scope. A symbol table entry for
15006 the type will also not be done until process_structure_scope (assuming
15007 the type has a name).
15009 NOTE: we need to call these functions regardless of whether or not the
15010 DIE has a DW_AT_name attribute, since it might be an anonymous
15011 structure or union. This gets the type entered into our set of
15012 user defined types. */
15014 static struct type
*
15015 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15017 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15019 struct attribute
*attr
;
15022 /* If the definition of this type lives in .debug_types, read that type.
15023 Don't follow DW_AT_specification though, that will take us back up
15024 the chain and we want to go down. */
15025 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15026 if (attr
!= nullptr)
15028 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15030 /* The type's CU may not be the same as CU.
15031 Ensure TYPE is recorded with CU in die_type_hash. */
15032 return set_die_type (die
, type
, cu
);
15035 type
= alloc_type (objfile
);
15036 INIT_CPLUS_SPECIFIC (type
);
15038 name
= dwarf2_name (die
, cu
);
15041 if (cu
->language
== language_cplus
15042 || cu
->language
== language_d
15043 || cu
->language
== language_rust
)
15045 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15047 /* dwarf2_full_name might have already finished building the DIE's
15048 type. If so, there is no need to continue. */
15049 if (get_die_type (die
, cu
) != NULL
)
15050 return get_die_type (die
, cu
);
15052 TYPE_NAME (type
) = full_name
;
15056 /* The name is already allocated along with this objfile, so
15057 we don't need to duplicate it for the type. */
15058 TYPE_NAME (type
) = name
;
15062 if (die
->tag
== DW_TAG_structure_type
)
15064 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15066 else if (die
->tag
== DW_TAG_union_type
)
15068 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15070 else if (die
->tag
== DW_TAG_variant_part
)
15072 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15073 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15077 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15080 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15081 TYPE_DECLARED_CLASS (type
) = 1;
15083 /* Store the calling convention in the type if it's available in
15084 the die. Otherwise the calling convention remains set to
15085 the default value DW_CC_normal. */
15086 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15087 if (attr
!= nullptr
15088 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15090 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15091 TYPE_CPLUS_CALLING_CONVENTION (type
)
15092 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15095 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15096 if (attr
!= nullptr)
15098 if (attr
->form_is_constant ())
15099 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15102 /* For the moment, dynamic type sizes are not supported
15103 by GDB's struct type. The actual size is determined
15104 on-demand when resolving the type of a given object,
15105 so set the type's length to zero for now. Otherwise,
15106 we record an expression as the length, and that expression
15107 could lead to a very large value, which could eventually
15108 lead to us trying to allocate that much memory when creating
15109 a value of that type. */
15110 TYPE_LENGTH (type
) = 0;
15115 TYPE_LENGTH (type
) = 0;
15118 maybe_set_alignment (cu
, die
, type
);
15120 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15122 /* ICC<14 does not output the required DW_AT_declaration on
15123 incomplete types, but gives them a size of zero. */
15124 TYPE_STUB (type
) = 1;
15127 TYPE_STUB_SUPPORTED (type
) = 1;
15129 if (die_is_declaration (die
, cu
))
15130 TYPE_STUB (type
) = 1;
15131 else if (attr
== NULL
&& die
->child
== NULL
15132 && producer_is_realview (cu
->producer
))
15133 /* RealView does not output the required DW_AT_declaration
15134 on incomplete types. */
15135 TYPE_STUB (type
) = 1;
15137 /* We need to add the type field to the die immediately so we don't
15138 infinitely recurse when dealing with pointers to the structure
15139 type within the structure itself. */
15140 set_die_type (die
, type
, cu
);
15142 /* set_die_type should be already done. */
15143 set_descriptive_type (type
, die
, cu
);
15148 /* A helper for process_structure_scope that handles a single member
15152 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15153 struct field_info
*fi
,
15154 std::vector
<struct symbol
*> *template_args
,
15155 struct dwarf2_cu
*cu
)
15157 if (child_die
->tag
== DW_TAG_member
15158 || child_die
->tag
== DW_TAG_variable
15159 || child_die
->tag
== DW_TAG_variant_part
)
15161 /* NOTE: carlton/2002-11-05: A C++ static data member
15162 should be a DW_TAG_member that is a declaration, but
15163 all versions of G++ as of this writing (so through at
15164 least 3.2.1) incorrectly generate DW_TAG_variable
15165 tags for them instead. */
15166 dwarf2_add_field (fi
, child_die
, cu
);
15168 else if (child_die
->tag
== DW_TAG_subprogram
)
15170 /* Rust doesn't have member functions in the C++ sense.
15171 However, it does emit ordinary functions as children
15172 of a struct DIE. */
15173 if (cu
->language
== language_rust
)
15174 read_func_scope (child_die
, cu
);
15177 /* C++ member function. */
15178 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15181 else if (child_die
->tag
== DW_TAG_inheritance
)
15183 /* C++ base class field. */
15184 dwarf2_add_field (fi
, child_die
, cu
);
15186 else if (type_can_define_types (child_die
))
15187 dwarf2_add_type_defn (fi
, child_die
, cu
);
15188 else if (child_die
->tag
== DW_TAG_template_type_param
15189 || child_die
->tag
== DW_TAG_template_value_param
)
15191 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15194 template_args
->push_back (arg
);
15196 else if (child_die
->tag
== DW_TAG_variant
)
15198 /* In a variant we want to get the discriminant and also add a
15199 field for our sole member child. */
15200 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15202 for (die_info
*variant_child
= child_die
->child
;
15203 variant_child
!= NULL
;
15204 variant_child
= sibling_die (variant_child
))
15206 if (variant_child
->tag
== DW_TAG_member
)
15208 handle_struct_member_die (variant_child
, type
, fi
,
15209 template_args
, cu
);
15210 /* Only handle the one. */
15215 /* We don't handle this but we might as well report it if we see
15217 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15218 complaint (_("DW_AT_discr_list is not supported yet"
15219 " - DIE at %s [in module %s]"),
15220 sect_offset_str (child_die
->sect_off
),
15221 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15223 /* The first field was just added, so we can stash the
15224 discriminant there. */
15225 gdb_assert (!fi
->fields
.empty ());
15227 fi
->fields
.back ().variant
.default_branch
= true;
15229 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15233 /* Finish creating a structure or union type, including filling in
15234 its members and creating a symbol for it. */
15237 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15239 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15240 struct die_info
*child_die
;
15243 type
= get_die_type (die
, cu
);
15245 type
= read_structure_type (die
, cu
);
15247 /* When reading a DW_TAG_variant_part, we need to notice when we
15248 read the discriminant member, so we can record it later in the
15249 discriminant_info. */
15250 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15251 sect_offset discr_offset
{};
15252 bool has_template_parameters
= false;
15254 if (is_variant_part
)
15256 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15259 /* Maybe it's a univariant form, an extension we support.
15260 In this case arrange not to check the offset. */
15261 is_variant_part
= false;
15263 else if (discr
->form_is_ref ())
15265 struct dwarf2_cu
*target_cu
= cu
;
15266 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15268 discr_offset
= target_die
->sect_off
;
15272 complaint (_("DW_AT_discr does not have DIE reference form"
15273 " - DIE at %s [in module %s]"),
15274 sect_offset_str (die
->sect_off
),
15275 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15276 is_variant_part
= false;
15280 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15282 struct field_info fi
;
15283 std::vector
<struct symbol
*> template_args
;
15285 child_die
= die
->child
;
15287 while (child_die
&& child_die
->tag
)
15289 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15291 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15292 fi
.fields
.back ().variant
.is_discriminant
= true;
15294 child_die
= sibling_die (child_die
);
15297 /* Attach template arguments to type. */
15298 if (!template_args
.empty ())
15300 has_template_parameters
= true;
15301 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15302 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15303 TYPE_TEMPLATE_ARGUMENTS (type
)
15304 = XOBNEWVEC (&objfile
->objfile_obstack
,
15306 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15307 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15308 template_args
.data (),
15309 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15310 * sizeof (struct symbol
*)));
15313 /* Attach fields and member functions to the type. */
15315 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15316 if (!fi
.fnfieldlists
.empty ())
15318 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15320 /* Get the type which refers to the base class (possibly this
15321 class itself) which contains the vtable pointer for the current
15322 class from the DW_AT_containing_type attribute. This use of
15323 DW_AT_containing_type is a GNU extension. */
15325 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15327 struct type
*t
= die_containing_type (die
, cu
);
15329 set_type_vptr_basetype (type
, t
);
15334 /* Our own class provides vtbl ptr. */
15335 for (i
= TYPE_NFIELDS (t
) - 1;
15336 i
>= TYPE_N_BASECLASSES (t
);
15339 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15341 if (is_vtable_name (fieldname
, cu
))
15343 set_type_vptr_fieldno (type
, i
);
15348 /* Complain if virtual function table field not found. */
15349 if (i
< TYPE_N_BASECLASSES (t
))
15350 complaint (_("virtual function table pointer "
15351 "not found when defining class '%s'"),
15352 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15356 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15359 else if (cu
->producer
15360 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15362 /* The IBM XLC compiler does not provide direct indication
15363 of the containing type, but the vtable pointer is
15364 always named __vfp. */
15368 for (i
= TYPE_NFIELDS (type
) - 1;
15369 i
>= TYPE_N_BASECLASSES (type
);
15372 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15374 set_type_vptr_fieldno (type
, i
);
15375 set_type_vptr_basetype (type
, type
);
15382 /* Copy fi.typedef_field_list linked list elements content into the
15383 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15384 if (!fi
.typedef_field_list
.empty ())
15386 int count
= fi
.typedef_field_list
.size ();
15388 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15389 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15390 = ((struct decl_field
*)
15392 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15393 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15395 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15396 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15399 /* Copy fi.nested_types_list linked list elements content into the
15400 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15401 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15403 int count
= fi
.nested_types_list
.size ();
15405 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15406 TYPE_NESTED_TYPES_ARRAY (type
)
15407 = ((struct decl_field
*)
15408 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15409 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15411 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15412 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15416 quirk_gcc_member_function_pointer (type
, objfile
);
15417 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15418 cu
->rust_unions
.push_back (type
);
15420 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15421 snapshots) has been known to create a die giving a declaration
15422 for a class that has, as a child, a die giving a definition for a
15423 nested class. So we have to process our children even if the
15424 current die is a declaration. Normally, of course, a declaration
15425 won't have any children at all. */
15427 child_die
= die
->child
;
15429 while (child_die
!= NULL
&& child_die
->tag
)
15431 if (child_die
->tag
== DW_TAG_member
15432 || child_die
->tag
== DW_TAG_variable
15433 || child_die
->tag
== DW_TAG_inheritance
15434 || child_die
->tag
== DW_TAG_template_value_param
15435 || child_die
->tag
== DW_TAG_template_type_param
)
15440 process_die (child_die
, cu
);
15442 child_die
= sibling_die (child_die
);
15445 /* Do not consider external references. According to the DWARF standard,
15446 these DIEs are identified by the fact that they have no byte_size
15447 attribute, and a declaration attribute. */
15448 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15449 || !die_is_declaration (die
, cu
))
15451 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15453 if (has_template_parameters
)
15455 struct symtab
*symtab
;
15456 if (sym
!= nullptr)
15457 symtab
= symbol_symtab (sym
);
15458 else if (cu
->line_header
!= nullptr)
15460 /* Any related symtab will do. */
15462 = cu
->line_header
->file_names ()[0].symtab
;
15467 complaint (_("could not find suitable "
15468 "symtab for template parameter"
15469 " - DIE at %s [in module %s]"),
15470 sect_offset_str (die
->sect_off
),
15471 objfile_name (objfile
));
15474 if (symtab
!= nullptr)
15476 /* Make sure that the symtab is set on the new symbols.
15477 Even though they don't appear in this symtab directly,
15478 other parts of gdb assume that symbols do, and this is
15479 reasonably true. */
15480 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15481 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15487 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15488 update TYPE using some information only available in DIE's children. */
15491 update_enumeration_type_from_children (struct die_info
*die
,
15493 struct dwarf2_cu
*cu
)
15495 struct die_info
*child_die
;
15496 int unsigned_enum
= 1;
15500 auto_obstack obstack
;
15502 for (child_die
= die
->child
;
15503 child_die
!= NULL
&& child_die
->tag
;
15504 child_die
= sibling_die (child_die
))
15506 struct attribute
*attr
;
15508 const gdb_byte
*bytes
;
15509 struct dwarf2_locexpr_baton
*baton
;
15512 if (child_die
->tag
!= DW_TAG_enumerator
)
15515 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15519 name
= dwarf2_name (child_die
, cu
);
15521 name
= "<anonymous enumerator>";
15523 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15524 &value
, &bytes
, &baton
);
15532 if (count_one_bits_ll (value
) >= 2)
15534 else if ((mask
& value
) != 0)
15540 /* If we already know that the enum type is neither unsigned, nor
15541 a flag type, no need to look at the rest of the enumerates. */
15542 if (!unsigned_enum
&& !flag_enum
)
15547 TYPE_UNSIGNED (type
) = 1;
15549 TYPE_FLAG_ENUM (type
) = 1;
15552 /* Given a DW_AT_enumeration_type die, set its type. We do not
15553 complete the type's fields yet, or create any symbols. */
15555 static struct type
*
15556 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15558 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15560 struct attribute
*attr
;
15563 /* If the definition of this type lives in .debug_types, read that type.
15564 Don't follow DW_AT_specification though, that will take us back up
15565 the chain and we want to go down. */
15566 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15567 if (attr
!= nullptr)
15569 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15571 /* The type's CU may not be the same as CU.
15572 Ensure TYPE is recorded with CU in die_type_hash. */
15573 return set_die_type (die
, type
, cu
);
15576 type
= alloc_type (objfile
);
15578 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15579 name
= dwarf2_full_name (NULL
, die
, cu
);
15581 TYPE_NAME (type
) = name
;
15583 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15586 struct type
*underlying_type
= die_type (die
, cu
);
15588 TYPE_TARGET_TYPE (type
) = underlying_type
;
15591 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15592 if (attr
!= nullptr)
15594 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15598 TYPE_LENGTH (type
) = 0;
15601 maybe_set_alignment (cu
, die
, type
);
15603 /* The enumeration DIE can be incomplete. In Ada, any type can be
15604 declared as private in the package spec, and then defined only
15605 inside the package body. Such types are known as Taft Amendment
15606 Types. When another package uses such a type, an incomplete DIE
15607 may be generated by the compiler. */
15608 if (die_is_declaration (die
, cu
))
15609 TYPE_STUB (type
) = 1;
15611 /* Finish the creation of this type by using the enum's children.
15612 We must call this even when the underlying type has been provided
15613 so that we can determine if we're looking at a "flag" enum. */
15614 update_enumeration_type_from_children (die
, type
, cu
);
15616 /* If this type has an underlying type that is not a stub, then we
15617 may use its attributes. We always use the "unsigned" attribute
15618 in this situation, because ordinarily we guess whether the type
15619 is unsigned -- but the guess can be wrong and the underlying type
15620 can tell us the reality. However, we defer to a local size
15621 attribute if one exists, because this lets the compiler override
15622 the underlying type if needed. */
15623 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15625 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15626 if (TYPE_LENGTH (type
) == 0)
15627 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15628 if (TYPE_RAW_ALIGN (type
) == 0
15629 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15630 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15633 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15635 return set_die_type (die
, type
, cu
);
15638 /* Given a pointer to a die which begins an enumeration, process all
15639 the dies that define the members of the enumeration, and create the
15640 symbol for the enumeration type.
15642 NOTE: We reverse the order of the element list. */
15645 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15647 struct type
*this_type
;
15649 this_type
= get_die_type (die
, cu
);
15650 if (this_type
== NULL
)
15651 this_type
= read_enumeration_type (die
, cu
);
15653 if (die
->child
!= NULL
)
15655 struct die_info
*child_die
;
15656 struct symbol
*sym
;
15657 std::vector
<struct field
> fields
;
15660 child_die
= die
->child
;
15661 while (child_die
&& child_die
->tag
)
15663 if (child_die
->tag
!= DW_TAG_enumerator
)
15665 process_die (child_die
, cu
);
15669 name
= dwarf2_name (child_die
, cu
);
15672 sym
= new_symbol (child_die
, this_type
, cu
);
15674 fields
.emplace_back ();
15675 struct field
&field
= fields
.back ();
15677 FIELD_NAME (field
) = sym
->linkage_name ();
15678 FIELD_TYPE (field
) = NULL
;
15679 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15680 FIELD_BITSIZE (field
) = 0;
15684 child_die
= sibling_die (child_die
);
15687 if (!fields
.empty ())
15689 TYPE_NFIELDS (this_type
) = fields
.size ();
15690 TYPE_FIELDS (this_type
) = (struct field
*)
15691 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15692 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15693 sizeof (struct field
) * fields
.size ());
15697 /* If we are reading an enum from a .debug_types unit, and the enum
15698 is a declaration, and the enum is not the signatured type in the
15699 unit, then we do not want to add a symbol for it. Adding a
15700 symbol would in some cases obscure the true definition of the
15701 enum, giving users an incomplete type when the definition is
15702 actually available. Note that we do not want to do this for all
15703 enums which are just declarations, because C++0x allows forward
15704 enum declarations. */
15705 if (cu
->per_cu
->is_debug_types
15706 && die_is_declaration (die
, cu
))
15708 struct signatured_type
*sig_type
;
15710 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15711 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15712 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15716 new_symbol (die
, this_type
, cu
);
15719 /* Extract all information from a DW_TAG_array_type DIE and put it in
15720 the DIE's type field. For now, this only handles one dimensional
15723 static struct type
*
15724 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15726 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15727 struct die_info
*child_die
;
15729 struct type
*element_type
, *range_type
, *index_type
;
15730 struct attribute
*attr
;
15732 struct dynamic_prop
*byte_stride_prop
= NULL
;
15733 unsigned int bit_stride
= 0;
15735 element_type
= die_type (die
, cu
);
15737 /* The die_type call above may have already set the type for this DIE. */
15738 type
= get_die_type (die
, cu
);
15742 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15746 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15749 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15750 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15754 complaint (_("unable to read array DW_AT_byte_stride "
15755 " - DIE at %s [in module %s]"),
15756 sect_offset_str (die
->sect_off
),
15757 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15758 /* Ignore this attribute. We will likely not be able to print
15759 arrays of this type correctly, but there is little we can do
15760 to help if we cannot read the attribute's value. */
15761 byte_stride_prop
= NULL
;
15765 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15767 bit_stride
= DW_UNSND (attr
);
15769 /* Irix 6.2 native cc creates array types without children for
15770 arrays with unspecified length. */
15771 if (die
->child
== NULL
)
15773 index_type
= objfile_type (objfile
)->builtin_int
;
15774 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15775 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15776 byte_stride_prop
, bit_stride
);
15777 return set_die_type (die
, type
, cu
);
15780 std::vector
<struct type
*> range_types
;
15781 child_die
= die
->child
;
15782 while (child_die
&& child_die
->tag
)
15784 if (child_die
->tag
== DW_TAG_subrange_type
)
15786 struct type
*child_type
= read_type_die (child_die
, cu
);
15788 if (child_type
!= NULL
)
15790 /* The range type was succesfully read. Save it for the
15791 array type creation. */
15792 range_types
.push_back (child_type
);
15795 child_die
= sibling_die (child_die
);
15798 /* Dwarf2 dimensions are output from left to right, create the
15799 necessary array types in backwards order. */
15801 type
= element_type
;
15803 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15807 while (i
< range_types
.size ())
15808 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15809 byte_stride_prop
, bit_stride
);
15813 size_t ndim
= range_types
.size ();
15815 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15816 byte_stride_prop
, bit_stride
);
15819 /* Understand Dwarf2 support for vector types (like they occur on
15820 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15821 array type. This is not part of the Dwarf2/3 standard yet, but a
15822 custom vendor extension. The main difference between a regular
15823 array and the vector variant is that vectors are passed by value
15825 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15826 if (attr
!= nullptr)
15827 make_vector_type (type
);
15829 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15830 implementation may choose to implement triple vectors using this
15832 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15833 if (attr
!= nullptr)
15835 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15836 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15838 complaint (_("DW_AT_byte_size for array type smaller "
15839 "than the total size of elements"));
15842 name
= dwarf2_name (die
, cu
);
15844 TYPE_NAME (type
) = name
;
15846 maybe_set_alignment (cu
, die
, type
);
15848 /* Install the type in the die. */
15849 set_die_type (die
, type
, cu
);
15851 /* set_die_type should be already done. */
15852 set_descriptive_type (type
, die
, cu
);
15857 static enum dwarf_array_dim_ordering
15858 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15860 struct attribute
*attr
;
15862 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15864 if (attr
!= nullptr)
15865 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15867 /* GNU F77 is a special case, as at 08/2004 array type info is the
15868 opposite order to the dwarf2 specification, but data is still
15869 laid out as per normal fortran.
15871 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15872 version checking. */
15874 if (cu
->language
== language_fortran
15875 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15877 return DW_ORD_row_major
;
15880 switch (cu
->language_defn
->la_array_ordering
)
15882 case array_column_major
:
15883 return DW_ORD_col_major
;
15884 case array_row_major
:
15886 return DW_ORD_row_major
;
15890 /* Extract all information from a DW_TAG_set_type DIE and put it in
15891 the DIE's type field. */
15893 static struct type
*
15894 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15896 struct type
*domain_type
, *set_type
;
15897 struct attribute
*attr
;
15899 domain_type
= die_type (die
, cu
);
15901 /* The die_type call above may have already set the type for this DIE. */
15902 set_type
= get_die_type (die
, cu
);
15906 set_type
= create_set_type (NULL
, domain_type
);
15908 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15909 if (attr
!= nullptr)
15910 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15912 maybe_set_alignment (cu
, die
, set_type
);
15914 return set_die_type (die
, set_type
, cu
);
15917 /* A helper for read_common_block that creates a locexpr baton.
15918 SYM is the symbol which we are marking as computed.
15919 COMMON_DIE is the DIE for the common block.
15920 COMMON_LOC is the location expression attribute for the common
15922 MEMBER_LOC is the location expression attribute for the particular
15923 member of the common block that we are processing.
15924 CU is the CU from which the above come. */
15927 mark_common_block_symbol_computed (struct symbol
*sym
,
15928 struct die_info
*common_die
,
15929 struct attribute
*common_loc
,
15930 struct attribute
*member_loc
,
15931 struct dwarf2_cu
*cu
)
15933 struct dwarf2_per_objfile
*dwarf2_per_objfile
15934 = cu
->per_cu
->dwarf2_per_objfile
;
15935 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15936 struct dwarf2_locexpr_baton
*baton
;
15938 unsigned int cu_off
;
15939 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15940 LONGEST offset
= 0;
15942 gdb_assert (common_loc
&& member_loc
);
15943 gdb_assert (common_loc
->form_is_block ());
15944 gdb_assert (member_loc
->form_is_block ()
15945 || member_loc
->form_is_constant ());
15947 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15948 baton
->per_cu
= cu
->per_cu
;
15949 gdb_assert (baton
->per_cu
);
15951 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15953 if (member_loc
->form_is_constant ())
15955 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15956 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15959 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15961 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15964 *ptr
++ = DW_OP_call4
;
15965 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15966 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15969 if (member_loc
->form_is_constant ())
15971 *ptr
++ = DW_OP_addr
;
15972 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15973 ptr
+= cu
->header
.addr_size
;
15977 /* We have to copy the data here, because DW_OP_call4 will only
15978 use a DW_AT_location attribute. */
15979 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15980 ptr
+= DW_BLOCK (member_loc
)->size
;
15983 *ptr
++ = DW_OP_plus
;
15984 gdb_assert (ptr
- baton
->data
== baton
->size
);
15986 SYMBOL_LOCATION_BATON (sym
) = baton
;
15987 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15990 /* Create appropriate locally-scoped variables for all the
15991 DW_TAG_common_block entries. Also create a struct common_block
15992 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15993 is used to separate the common blocks name namespace from regular
15997 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15999 struct attribute
*attr
;
16001 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16002 if (attr
!= nullptr)
16004 /* Support the .debug_loc offsets. */
16005 if (attr
->form_is_block ())
16009 else if (attr
->form_is_section_offset ())
16011 dwarf2_complex_location_expr_complaint ();
16016 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16017 "common block member");
16022 if (die
->child
!= NULL
)
16024 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16025 struct die_info
*child_die
;
16026 size_t n_entries
= 0, size
;
16027 struct common_block
*common_block
;
16028 struct symbol
*sym
;
16030 for (child_die
= die
->child
;
16031 child_die
&& child_die
->tag
;
16032 child_die
= sibling_die (child_die
))
16035 size
= (sizeof (struct common_block
)
16036 + (n_entries
- 1) * sizeof (struct symbol
*));
16038 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16040 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16041 common_block
->n_entries
= 0;
16043 for (child_die
= die
->child
;
16044 child_die
&& child_die
->tag
;
16045 child_die
= sibling_die (child_die
))
16047 /* Create the symbol in the DW_TAG_common_block block in the current
16049 sym
= new_symbol (child_die
, NULL
, cu
);
16052 struct attribute
*member_loc
;
16054 common_block
->contents
[common_block
->n_entries
++] = sym
;
16056 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16060 /* GDB has handled this for a long time, but it is
16061 not specified by DWARF. It seems to have been
16062 emitted by gfortran at least as recently as:
16063 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16064 complaint (_("Variable in common block has "
16065 "DW_AT_data_member_location "
16066 "- DIE at %s [in module %s]"),
16067 sect_offset_str (child_die
->sect_off
),
16068 objfile_name (objfile
));
16070 if (member_loc
->form_is_section_offset ())
16071 dwarf2_complex_location_expr_complaint ();
16072 else if (member_loc
->form_is_constant ()
16073 || member_loc
->form_is_block ())
16075 if (attr
!= nullptr)
16076 mark_common_block_symbol_computed (sym
, die
, attr
,
16080 dwarf2_complex_location_expr_complaint ();
16085 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16086 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16090 /* Create a type for a C++ namespace. */
16092 static struct type
*
16093 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16095 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16096 const char *previous_prefix
, *name
;
16100 /* For extensions, reuse the type of the original namespace. */
16101 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16103 struct die_info
*ext_die
;
16104 struct dwarf2_cu
*ext_cu
= cu
;
16106 ext_die
= dwarf2_extension (die
, &ext_cu
);
16107 type
= read_type_die (ext_die
, ext_cu
);
16109 /* EXT_CU may not be the same as CU.
16110 Ensure TYPE is recorded with CU in die_type_hash. */
16111 return set_die_type (die
, type
, cu
);
16114 name
= namespace_name (die
, &is_anonymous
, cu
);
16116 /* Now build the name of the current namespace. */
16118 previous_prefix
= determine_prefix (die
, cu
);
16119 if (previous_prefix
[0] != '\0')
16120 name
= typename_concat (&objfile
->objfile_obstack
,
16121 previous_prefix
, name
, 0, cu
);
16123 /* Create the type. */
16124 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16126 return set_die_type (die
, type
, cu
);
16129 /* Read a namespace scope. */
16132 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16134 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16137 /* Add a symbol associated to this if we haven't seen the namespace
16138 before. Also, add a using directive if it's an anonymous
16141 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16145 type
= read_type_die (die
, cu
);
16146 new_symbol (die
, type
, cu
);
16148 namespace_name (die
, &is_anonymous
, cu
);
16151 const char *previous_prefix
= determine_prefix (die
, cu
);
16153 std::vector
<const char *> excludes
;
16154 add_using_directive (using_directives (cu
),
16155 previous_prefix
, TYPE_NAME (type
), NULL
,
16156 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16160 if (die
->child
!= NULL
)
16162 struct die_info
*child_die
= die
->child
;
16164 while (child_die
&& child_die
->tag
)
16166 process_die (child_die
, cu
);
16167 child_die
= sibling_die (child_die
);
16172 /* Read a Fortran module as type. This DIE can be only a declaration used for
16173 imported module. Still we need that type as local Fortran "use ... only"
16174 declaration imports depend on the created type in determine_prefix. */
16176 static struct type
*
16177 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16179 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16180 const char *module_name
;
16183 module_name
= dwarf2_name (die
, cu
);
16184 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16186 return set_die_type (die
, type
, cu
);
16189 /* Read a Fortran module. */
16192 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16194 struct die_info
*child_die
= die
->child
;
16197 type
= read_type_die (die
, cu
);
16198 new_symbol (die
, type
, cu
);
16200 while (child_die
&& child_die
->tag
)
16202 process_die (child_die
, cu
);
16203 child_die
= sibling_die (child_die
);
16207 /* Return the name of the namespace represented by DIE. Set
16208 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16211 static const char *
16212 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16214 struct die_info
*current_die
;
16215 const char *name
= NULL
;
16217 /* Loop through the extensions until we find a name. */
16219 for (current_die
= die
;
16220 current_die
!= NULL
;
16221 current_die
= dwarf2_extension (die
, &cu
))
16223 /* We don't use dwarf2_name here so that we can detect the absence
16224 of a name -> anonymous namespace. */
16225 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16231 /* Is it an anonymous namespace? */
16233 *is_anonymous
= (name
== NULL
);
16235 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16240 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16241 the user defined type vector. */
16243 static struct type
*
16244 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16246 struct gdbarch
*gdbarch
16247 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16248 struct comp_unit_head
*cu_header
= &cu
->header
;
16250 struct attribute
*attr_byte_size
;
16251 struct attribute
*attr_address_class
;
16252 int byte_size
, addr_class
;
16253 struct type
*target_type
;
16255 target_type
= die_type (die
, cu
);
16257 /* The die_type call above may have already set the type for this DIE. */
16258 type
= get_die_type (die
, cu
);
16262 type
= lookup_pointer_type (target_type
);
16264 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16265 if (attr_byte_size
)
16266 byte_size
= DW_UNSND (attr_byte_size
);
16268 byte_size
= cu_header
->addr_size
;
16270 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16271 if (attr_address_class
)
16272 addr_class
= DW_UNSND (attr_address_class
);
16274 addr_class
= DW_ADDR_none
;
16276 ULONGEST alignment
= get_alignment (cu
, die
);
16278 /* If the pointer size, alignment, or address class is different
16279 than the default, create a type variant marked as such and set
16280 the length accordingly. */
16281 if (TYPE_LENGTH (type
) != byte_size
16282 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16283 && alignment
!= TYPE_RAW_ALIGN (type
))
16284 || addr_class
!= DW_ADDR_none
)
16286 if (gdbarch_address_class_type_flags_p (gdbarch
))
16290 type_flags
= gdbarch_address_class_type_flags
16291 (gdbarch
, byte_size
, addr_class
);
16292 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16294 type
= make_type_with_address_space (type
, type_flags
);
16296 else if (TYPE_LENGTH (type
) != byte_size
)
16298 complaint (_("invalid pointer size %d"), byte_size
);
16300 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16302 complaint (_("Invalid DW_AT_alignment"
16303 " - DIE at %s [in module %s]"),
16304 sect_offset_str (die
->sect_off
),
16305 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16309 /* Should we also complain about unhandled address classes? */
16313 TYPE_LENGTH (type
) = byte_size
;
16314 set_type_align (type
, alignment
);
16315 return set_die_type (die
, type
, cu
);
16318 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16319 the user defined type vector. */
16321 static struct type
*
16322 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16325 struct type
*to_type
;
16326 struct type
*domain
;
16328 to_type
= die_type (die
, cu
);
16329 domain
= die_containing_type (die
, cu
);
16331 /* The calls above may have already set the type for this DIE. */
16332 type
= get_die_type (die
, cu
);
16336 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16337 type
= lookup_methodptr_type (to_type
);
16338 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16340 struct type
*new_type
16341 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16343 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16344 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16345 TYPE_VARARGS (to_type
));
16346 type
= lookup_methodptr_type (new_type
);
16349 type
= lookup_memberptr_type (to_type
, domain
);
16351 return set_die_type (die
, type
, cu
);
16354 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16355 the user defined type vector. */
16357 static struct type
*
16358 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16359 enum type_code refcode
)
16361 struct comp_unit_head
*cu_header
= &cu
->header
;
16362 struct type
*type
, *target_type
;
16363 struct attribute
*attr
;
16365 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16367 target_type
= die_type (die
, cu
);
16369 /* The die_type call above may have already set the type for this DIE. */
16370 type
= get_die_type (die
, cu
);
16374 type
= lookup_reference_type (target_type
, refcode
);
16375 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16376 if (attr
!= nullptr)
16378 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16382 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16384 maybe_set_alignment (cu
, die
, type
);
16385 return set_die_type (die
, type
, cu
);
16388 /* Add the given cv-qualifiers to the element type of the array. GCC
16389 outputs DWARF type qualifiers that apply to an array, not the
16390 element type. But GDB relies on the array element type to carry
16391 the cv-qualifiers. This mimics section 6.7.3 of the C99
16394 static struct type
*
16395 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16396 struct type
*base_type
, int cnst
, int voltl
)
16398 struct type
*el_type
, *inner_array
;
16400 base_type
= copy_type (base_type
);
16401 inner_array
= base_type
;
16403 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16405 TYPE_TARGET_TYPE (inner_array
) =
16406 copy_type (TYPE_TARGET_TYPE (inner_array
));
16407 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16410 el_type
= TYPE_TARGET_TYPE (inner_array
);
16411 cnst
|= TYPE_CONST (el_type
);
16412 voltl
|= TYPE_VOLATILE (el_type
);
16413 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16415 return set_die_type (die
, base_type
, cu
);
16418 static struct type
*
16419 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16421 struct type
*base_type
, *cv_type
;
16423 base_type
= die_type (die
, cu
);
16425 /* The die_type call above may have already set the type for this DIE. */
16426 cv_type
= get_die_type (die
, cu
);
16430 /* In case the const qualifier is applied to an array type, the element type
16431 is so qualified, not the array type (section 6.7.3 of C99). */
16432 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16433 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16435 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16436 return set_die_type (die
, cv_type
, cu
);
16439 static struct type
*
16440 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16442 struct type
*base_type
, *cv_type
;
16444 base_type
= die_type (die
, cu
);
16446 /* The die_type call above may have already set the type for this DIE. */
16447 cv_type
= get_die_type (die
, cu
);
16451 /* In case the volatile qualifier is applied to an array type, the
16452 element type is so qualified, not the array type (section 6.7.3
16454 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16455 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16457 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16458 return set_die_type (die
, cv_type
, cu
);
16461 /* Handle DW_TAG_restrict_type. */
16463 static struct type
*
16464 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16466 struct type
*base_type
, *cv_type
;
16468 base_type
= die_type (die
, cu
);
16470 /* The die_type call above may have already set the type for this DIE. */
16471 cv_type
= get_die_type (die
, cu
);
16475 cv_type
= make_restrict_type (base_type
);
16476 return set_die_type (die
, cv_type
, cu
);
16479 /* Handle DW_TAG_atomic_type. */
16481 static struct type
*
16482 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16484 struct type
*base_type
, *cv_type
;
16486 base_type
= die_type (die
, cu
);
16488 /* The die_type call above may have already set the type for this DIE. */
16489 cv_type
= get_die_type (die
, cu
);
16493 cv_type
= make_atomic_type (base_type
);
16494 return set_die_type (die
, cv_type
, cu
);
16497 /* Extract all information from a DW_TAG_string_type DIE and add to
16498 the user defined type vector. It isn't really a user defined type,
16499 but it behaves like one, with other DIE's using an AT_user_def_type
16500 attribute to reference it. */
16502 static struct type
*
16503 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16505 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16506 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16507 struct type
*type
, *range_type
, *index_type
, *char_type
;
16508 struct attribute
*attr
;
16509 struct dynamic_prop prop
;
16510 bool length_is_constant
= true;
16513 /* There are a couple of places where bit sizes might be made use of
16514 when parsing a DW_TAG_string_type, however, no producer that we know
16515 of make use of these. Handling bit sizes that are a multiple of the
16516 byte size is easy enough, but what about other bit sizes? Lets deal
16517 with that problem when we have to. Warn about these attributes being
16518 unsupported, then parse the type and ignore them like we always
16520 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16521 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16523 static bool warning_printed
= false;
16524 if (!warning_printed
)
16526 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16527 "currently supported on DW_TAG_string_type."));
16528 warning_printed
= true;
16532 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16533 if (attr
!= nullptr && !attr
->form_is_constant ())
16535 /* The string length describes the location at which the length of
16536 the string can be found. The size of the length field can be
16537 specified with one of the attributes below. */
16538 struct type
*prop_type
;
16539 struct attribute
*len
16540 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16541 if (len
== nullptr)
16542 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16543 if (len
!= nullptr && len
->form_is_constant ())
16545 /* Pass 0 as the default as we know this attribute is constant
16546 and the default value will not be returned. */
16547 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16548 prop_type
= cu
->per_cu
->int_type (sz
, true);
16552 /* If the size is not specified then we assume it is the size of
16553 an address on this target. */
16554 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16557 /* Convert the attribute into a dynamic property. */
16558 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16561 length_is_constant
= false;
16563 else if (attr
!= nullptr)
16565 /* This DW_AT_string_length just contains the length with no
16566 indirection. There's no need to create a dynamic property in this
16567 case. Pass 0 for the default value as we know it will not be
16568 returned in this case. */
16569 length
= dwarf2_get_attr_constant_value (attr
, 0);
16571 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16573 /* We don't currently support non-constant byte sizes for strings. */
16574 length
= dwarf2_get_attr_constant_value (attr
, 1);
16578 /* Use 1 as a fallback length if we have nothing else. */
16582 index_type
= objfile_type (objfile
)->builtin_int
;
16583 if (length_is_constant
)
16584 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16587 struct dynamic_prop low_bound
;
16589 low_bound
.kind
= PROP_CONST
;
16590 low_bound
.data
.const_val
= 1;
16591 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16593 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16594 type
= create_string_type (NULL
, char_type
, range_type
);
16596 return set_die_type (die
, type
, cu
);
16599 /* Assuming that DIE corresponds to a function, returns nonzero
16600 if the function is prototyped. */
16603 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16605 struct attribute
*attr
;
16607 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16608 if (attr
&& (DW_UNSND (attr
) != 0))
16611 /* The DWARF standard implies that the DW_AT_prototyped attribute
16612 is only meaningful for C, but the concept also extends to other
16613 languages that allow unprototyped functions (Eg: Objective C).
16614 For all other languages, assume that functions are always
16616 if (cu
->language
!= language_c
16617 && cu
->language
!= language_objc
16618 && cu
->language
!= language_opencl
)
16621 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16622 prototyped and unprototyped functions; default to prototyped,
16623 since that is more common in modern code (and RealView warns
16624 about unprototyped functions). */
16625 if (producer_is_realview (cu
->producer
))
16631 /* Handle DIES due to C code like:
16635 int (*funcp)(int a, long l);
16639 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16641 static struct type
*
16642 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16644 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16645 struct type
*type
; /* Type that this function returns. */
16646 struct type
*ftype
; /* Function that returns above type. */
16647 struct attribute
*attr
;
16649 type
= die_type (die
, cu
);
16651 /* The die_type call above may have already set the type for this DIE. */
16652 ftype
= get_die_type (die
, cu
);
16656 ftype
= lookup_function_type (type
);
16658 if (prototyped_function_p (die
, cu
))
16659 TYPE_PROTOTYPED (ftype
) = 1;
16661 /* Store the calling convention in the type if it's available in
16662 the subroutine die. Otherwise set the calling convention to
16663 the default value DW_CC_normal. */
16664 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16665 if (attr
!= nullptr
16666 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16667 TYPE_CALLING_CONVENTION (ftype
)
16668 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16669 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16670 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16672 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16674 /* Record whether the function returns normally to its caller or not
16675 if the DWARF producer set that information. */
16676 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16677 if (attr
&& (DW_UNSND (attr
) != 0))
16678 TYPE_NO_RETURN (ftype
) = 1;
16680 /* We need to add the subroutine type to the die immediately so
16681 we don't infinitely recurse when dealing with parameters
16682 declared as the same subroutine type. */
16683 set_die_type (die
, ftype
, cu
);
16685 if (die
->child
!= NULL
)
16687 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16688 struct die_info
*child_die
;
16689 int nparams
, iparams
;
16691 /* Count the number of parameters.
16692 FIXME: GDB currently ignores vararg functions, but knows about
16693 vararg member functions. */
16695 child_die
= die
->child
;
16696 while (child_die
&& child_die
->tag
)
16698 if (child_die
->tag
== DW_TAG_formal_parameter
)
16700 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16701 TYPE_VARARGS (ftype
) = 1;
16702 child_die
= sibling_die (child_die
);
16705 /* Allocate storage for parameters and fill them in. */
16706 TYPE_NFIELDS (ftype
) = nparams
;
16707 TYPE_FIELDS (ftype
) = (struct field
*)
16708 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16710 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16711 even if we error out during the parameters reading below. */
16712 for (iparams
= 0; iparams
< nparams
; iparams
++)
16713 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16716 child_die
= die
->child
;
16717 while (child_die
&& child_die
->tag
)
16719 if (child_die
->tag
== DW_TAG_formal_parameter
)
16721 struct type
*arg_type
;
16723 /* DWARF version 2 has no clean way to discern C++
16724 static and non-static member functions. G++ helps
16725 GDB by marking the first parameter for non-static
16726 member functions (which is the this pointer) as
16727 artificial. We pass this information to
16728 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16730 DWARF version 3 added DW_AT_object_pointer, which GCC
16731 4.5 does not yet generate. */
16732 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16733 if (attr
!= nullptr)
16734 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16736 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16737 arg_type
= die_type (child_die
, cu
);
16739 /* RealView does not mark THIS as const, which the testsuite
16740 expects. GCC marks THIS as const in method definitions,
16741 but not in the class specifications (GCC PR 43053). */
16742 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16743 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16746 struct dwarf2_cu
*arg_cu
= cu
;
16747 const char *name
= dwarf2_name (child_die
, cu
);
16749 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16750 if (attr
!= nullptr)
16752 /* If the compiler emits this, use it. */
16753 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16756 else if (name
&& strcmp (name
, "this") == 0)
16757 /* Function definitions will have the argument names. */
16759 else if (name
== NULL
&& iparams
== 0)
16760 /* Declarations may not have the names, so like
16761 elsewhere in GDB, assume an artificial first
16762 argument is "this". */
16766 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16770 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16773 child_die
= sibling_die (child_die
);
16780 static struct type
*
16781 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16783 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16784 const char *name
= NULL
;
16785 struct type
*this_type
, *target_type
;
16787 name
= dwarf2_full_name (NULL
, die
, cu
);
16788 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16789 TYPE_TARGET_STUB (this_type
) = 1;
16790 set_die_type (die
, this_type
, cu
);
16791 target_type
= die_type (die
, cu
);
16792 if (target_type
!= this_type
)
16793 TYPE_TARGET_TYPE (this_type
) = target_type
;
16796 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16797 spec and cause infinite loops in GDB. */
16798 complaint (_("Self-referential DW_TAG_typedef "
16799 "- DIE at %s [in module %s]"),
16800 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16801 TYPE_TARGET_TYPE (this_type
) = NULL
;
16806 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16807 (which may be different from NAME) to the architecture back-end to allow
16808 it to guess the correct format if necessary. */
16810 static struct type
*
16811 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16812 const char *name_hint
, enum bfd_endian byte_order
)
16814 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16815 const struct floatformat
**format
;
16818 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16820 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16822 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16827 /* Allocate an integer type of size BITS and name NAME. */
16829 static struct type
*
16830 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16831 int bits
, int unsigned_p
, const char *name
)
16835 /* Versions of Intel's C Compiler generate an integer type called "void"
16836 instead of using DW_TAG_unspecified_type. This has been seen on
16837 at least versions 14, 17, and 18. */
16838 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16839 && strcmp (name
, "void") == 0)
16840 type
= objfile_type (objfile
)->builtin_void
;
16842 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16847 /* Initialise and return a floating point type of size BITS suitable for
16848 use as a component of a complex number. The NAME_HINT is passed through
16849 when initialising the floating point type and is the name of the complex
16852 As DWARF doesn't currently provide an explicit name for the components
16853 of a complex number, but it can be helpful to have these components
16854 named, we try to select a suitable name based on the size of the
16856 static struct type
*
16857 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16858 struct objfile
*objfile
,
16859 int bits
, const char *name_hint
,
16860 enum bfd_endian byte_order
)
16862 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16863 struct type
*tt
= nullptr;
16865 /* Try to find a suitable floating point builtin type of size BITS.
16866 We're going to use the name of this type as the name for the complex
16867 target type that we are about to create. */
16868 switch (cu
->language
)
16870 case language_fortran
:
16874 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16877 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16879 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16881 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16889 tt
= builtin_type (gdbarch
)->builtin_float
;
16892 tt
= builtin_type (gdbarch
)->builtin_double
;
16894 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16896 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16902 /* If the type we found doesn't match the size we were looking for, then
16903 pretend we didn't find a type at all, the complex target type we
16904 create will then be nameless. */
16905 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16908 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16909 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16912 /* Find a representation of a given base type and install
16913 it in the TYPE field of the die. */
16915 static struct type
*
16916 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16918 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16920 struct attribute
*attr
;
16921 int encoding
= 0, bits
= 0;
16925 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16926 if (attr
!= nullptr)
16927 encoding
= DW_UNSND (attr
);
16928 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16929 if (attr
!= nullptr)
16930 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16931 name
= dwarf2_name (die
, cu
);
16933 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16935 arch
= get_objfile_arch (objfile
);
16936 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16938 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16941 int endianity
= DW_UNSND (attr
);
16946 byte_order
= BFD_ENDIAN_BIG
;
16948 case DW_END_little
:
16949 byte_order
= BFD_ENDIAN_LITTLE
;
16952 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16959 case DW_ATE_address
:
16960 /* Turn DW_ATE_address into a void * pointer. */
16961 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16962 type
= init_pointer_type (objfile
, bits
, name
, type
);
16964 case DW_ATE_boolean
:
16965 type
= init_boolean_type (objfile
, bits
, 1, name
);
16967 case DW_ATE_complex_float
:
16968 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16970 type
= init_complex_type (objfile
, name
, type
);
16972 case DW_ATE_decimal_float
:
16973 type
= init_decfloat_type (objfile
, bits
, name
);
16976 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16978 case DW_ATE_signed
:
16979 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16981 case DW_ATE_unsigned
:
16982 if (cu
->language
== language_fortran
16984 && startswith (name
, "character("))
16985 type
= init_character_type (objfile
, bits
, 1, name
);
16987 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16989 case DW_ATE_signed_char
:
16990 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16991 || cu
->language
== language_pascal
16992 || cu
->language
== language_fortran
)
16993 type
= init_character_type (objfile
, bits
, 0, name
);
16995 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16997 case DW_ATE_unsigned_char
:
16998 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16999 || cu
->language
== language_pascal
17000 || cu
->language
== language_fortran
17001 || cu
->language
== language_rust
)
17002 type
= init_character_type (objfile
, bits
, 1, name
);
17004 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17009 type
= builtin_type (arch
)->builtin_char16
;
17010 else if (bits
== 32)
17011 type
= builtin_type (arch
)->builtin_char32
;
17014 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17016 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17018 return set_die_type (die
, type
, cu
);
17023 complaint (_("unsupported DW_AT_encoding: '%s'"),
17024 dwarf_type_encoding_name (encoding
));
17025 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17029 if (name
&& strcmp (name
, "char") == 0)
17030 TYPE_NOSIGN (type
) = 1;
17032 maybe_set_alignment (cu
, die
, type
);
17034 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17036 return set_die_type (die
, type
, cu
);
17039 /* Parse dwarf attribute if it's a block, reference or constant and put the
17040 resulting value of the attribute into struct bound_prop.
17041 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17044 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17045 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17046 struct type
*default_type
)
17048 struct dwarf2_property_baton
*baton
;
17049 struct obstack
*obstack
17050 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17052 gdb_assert (default_type
!= NULL
);
17054 if (attr
== NULL
|| prop
== NULL
)
17057 if (attr
->form_is_block ())
17059 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17060 baton
->property_type
= default_type
;
17061 baton
->locexpr
.per_cu
= cu
->per_cu
;
17062 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17063 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17064 switch (attr
->name
)
17066 case DW_AT_string_length
:
17067 baton
->locexpr
.is_reference
= true;
17070 baton
->locexpr
.is_reference
= false;
17073 prop
->data
.baton
= baton
;
17074 prop
->kind
= PROP_LOCEXPR
;
17075 gdb_assert (prop
->data
.baton
!= NULL
);
17077 else if (attr
->form_is_ref ())
17079 struct dwarf2_cu
*target_cu
= cu
;
17080 struct die_info
*target_die
;
17081 struct attribute
*target_attr
;
17083 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17084 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17085 if (target_attr
== NULL
)
17086 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17088 if (target_attr
== NULL
)
17091 switch (target_attr
->name
)
17093 case DW_AT_location
:
17094 if (target_attr
->form_is_section_offset ())
17096 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17097 baton
->property_type
= die_type (target_die
, target_cu
);
17098 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17099 prop
->data
.baton
= baton
;
17100 prop
->kind
= PROP_LOCLIST
;
17101 gdb_assert (prop
->data
.baton
!= NULL
);
17103 else if (target_attr
->form_is_block ())
17105 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17106 baton
->property_type
= die_type (target_die
, target_cu
);
17107 baton
->locexpr
.per_cu
= cu
->per_cu
;
17108 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17109 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17110 baton
->locexpr
.is_reference
= true;
17111 prop
->data
.baton
= baton
;
17112 prop
->kind
= PROP_LOCEXPR
;
17113 gdb_assert (prop
->data
.baton
!= NULL
);
17117 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17118 "dynamic property");
17122 case DW_AT_data_member_location
:
17126 if (!handle_data_member_location (target_die
, target_cu
,
17130 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17131 baton
->property_type
= read_type_die (target_die
->parent
,
17133 baton
->offset_info
.offset
= offset
;
17134 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17135 prop
->data
.baton
= baton
;
17136 prop
->kind
= PROP_ADDR_OFFSET
;
17141 else if (attr
->form_is_constant ())
17143 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17144 prop
->kind
= PROP_CONST
;
17148 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17149 dwarf2_name (die
, cu
));
17159 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17161 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17162 struct type
*int_type
;
17164 /* Helper macro to examine the various builtin types. */
17165 #define TRY_TYPE(F) \
17166 int_type = (unsigned_p \
17167 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17168 : objfile_type (objfile)->builtin_ ## F); \
17169 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17176 TRY_TYPE (long_long
);
17180 gdb_assert_not_reached ("unable to find suitable integer type");
17186 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17188 int addr_size
= this->addr_size ();
17189 return int_type (addr_size
, unsigned_p
);
17192 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17193 present (which is valid) then compute the default type based on the
17194 compilation units address size. */
17196 static struct type
*
17197 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17199 struct type
*index_type
= die_type (die
, cu
);
17201 /* Dwarf-2 specifications explicitly allows to create subrange types
17202 without specifying a base type.
17203 In that case, the base type must be set to the type of
17204 the lower bound, upper bound or count, in that order, if any of these
17205 three attributes references an object that has a type.
17206 If no base type is found, the Dwarf-2 specifications say that
17207 a signed integer type of size equal to the size of an address should
17209 For the following C code: `extern char gdb_int [];'
17210 GCC produces an empty range DIE.
17211 FIXME: muller/2010-05-28: Possible references to object for low bound,
17212 high bound or count are not yet handled by this code. */
17213 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17214 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17219 /* Read the given DW_AT_subrange DIE. */
17221 static struct type
*
17222 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17224 struct type
*base_type
, *orig_base_type
;
17225 struct type
*range_type
;
17226 struct attribute
*attr
;
17227 struct dynamic_prop low
, high
;
17228 int low_default_is_valid
;
17229 int high_bound_is_count
= 0;
17231 ULONGEST negative_mask
;
17233 orig_base_type
= read_subrange_index_type (die
, cu
);
17235 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17236 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17237 creating the range type, but we use the result of check_typedef
17238 when examining properties of the type. */
17239 base_type
= check_typedef (orig_base_type
);
17241 /* The die_type call above may have already set the type for this DIE. */
17242 range_type
= get_die_type (die
, cu
);
17246 low
.kind
= PROP_CONST
;
17247 high
.kind
= PROP_CONST
;
17248 high
.data
.const_val
= 0;
17250 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17251 omitting DW_AT_lower_bound. */
17252 switch (cu
->language
)
17255 case language_cplus
:
17256 low
.data
.const_val
= 0;
17257 low_default_is_valid
= 1;
17259 case language_fortran
:
17260 low
.data
.const_val
= 1;
17261 low_default_is_valid
= 1;
17264 case language_objc
:
17265 case language_rust
:
17266 low
.data
.const_val
= 0;
17267 low_default_is_valid
= (cu
->header
.version
>= 4);
17271 case language_pascal
:
17272 low
.data
.const_val
= 1;
17273 low_default_is_valid
= (cu
->header
.version
>= 4);
17276 low
.data
.const_val
= 0;
17277 low_default_is_valid
= 0;
17281 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17282 if (attr
!= nullptr)
17283 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17284 else if (!low_default_is_valid
)
17285 complaint (_("Missing DW_AT_lower_bound "
17286 "- DIE at %s [in module %s]"),
17287 sect_offset_str (die
->sect_off
),
17288 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17290 struct attribute
*attr_ub
, *attr_count
;
17291 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17292 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17294 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17295 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17297 /* If bounds are constant do the final calculation here. */
17298 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17299 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17301 high_bound_is_count
= 1;
17305 if (attr_ub
!= NULL
)
17306 complaint (_("Unresolved DW_AT_upper_bound "
17307 "- DIE at %s [in module %s]"),
17308 sect_offset_str (die
->sect_off
),
17309 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17310 if (attr_count
!= NULL
)
17311 complaint (_("Unresolved DW_AT_count "
17312 "- DIE at %s [in module %s]"),
17313 sect_offset_str (die
->sect_off
),
17314 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17319 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17320 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17321 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17323 /* Normally, the DWARF producers are expected to use a signed
17324 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17325 But this is unfortunately not always the case, as witnessed
17326 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17327 is used instead. To work around that ambiguity, we treat
17328 the bounds as signed, and thus sign-extend their values, when
17329 the base type is signed. */
17331 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17332 if (low
.kind
== PROP_CONST
17333 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17334 low
.data
.const_val
|= negative_mask
;
17335 if (high
.kind
== PROP_CONST
17336 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17337 high
.data
.const_val
|= negative_mask
;
17339 /* Check for bit and byte strides. */
17340 struct dynamic_prop byte_stride_prop
;
17341 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17342 if (attr_byte_stride
!= nullptr)
17344 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17345 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17349 struct dynamic_prop bit_stride_prop
;
17350 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17351 if (attr_bit_stride
!= nullptr)
17353 /* It only makes sense to have either a bit or byte stride. */
17354 if (attr_byte_stride
!= nullptr)
17356 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17357 "- DIE at %s [in module %s]"),
17358 sect_offset_str (die
->sect_off
),
17359 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17360 attr_bit_stride
= nullptr;
17364 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17365 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17370 if (attr_byte_stride
!= nullptr
17371 || attr_bit_stride
!= nullptr)
17373 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17374 struct dynamic_prop
*stride
17375 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17378 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17379 &high
, bias
, stride
, byte_stride_p
);
17382 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17384 if (high_bound_is_count
)
17385 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17387 /* Ada expects an empty array on no boundary attributes. */
17388 if (attr
== NULL
&& cu
->language
!= language_ada
)
17389 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17391 name
= dwarf2_name (die
, cu
);
17393 TYPE_NAME (range_type
) = name
;
17395 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17396 if (attr
!= nullptr)
17397 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17399 maybe_set_alignment (cu
, die
, range_type
);
17401 set_die_type (die
, range_type
, cu
);
17403 /* set_die_type should be already done. */
17404 set_descriptive_type (range_type
, die
, cu
);
17409 static struct type
*
17410 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17414 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17416 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17418 /* In Ada, an unspecified type is typically used when the description
17419 of the type is deferred to a different unit. When encountering
17420 such a type, we treat it as a stub, and try to resolve it later on,
17422 if (cu
->language
== language_ada
)
17423 TYPE_STUB (type
) = 1;
17425 return set_die_type (die
, type
, cu
);
17428 /* Read a single die and all its descendents. Set the die's sibling
17429 field to NULL; set other fields in the die correctly, and set all
17430 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17431 location of the info_ptr after reading all of those dies. PARENT
17432 is the parent of the die in question. */
17434 static struct die_info
*
17435 read_die_and_children (const struct die_reader_specs
*reader
,
17436 const gdb_byte
*info_ptr
,
17437 const gdb_byte
**new_info_ptr
,
17438 struct die_info
*parent
)
17440 struct die_info
*die
;
17441 const gdb_byte
*cur_ptr
;
17443 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17446 *new_info_ptr
= cur_ptr
;
17449 store_in_ref_table (die
, reader
->cu
);
17451 if (die
->has_children
)
17452 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17456 *new_info_ptr
= cur_ptr
;
17459 die
->sibling
= NULL
;
17460 die
->parent
= parent
;
17464 /* Read a die, all of its descendents, and all of its siblings; set
17465 all of the fields of all of the dies correctly. Arguments are as
17466 in read_die_and_children. */
17468 static struct die_info
*
17469 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17470 const gdb_byte
*info_ptr
,
17471 const gdb_byte
**new_info_ptr
,
17472 struct die_info
*parent
)
17474 struct die_info
*first_die
, *last_sibling
;
17475 const gdb_byte
*cur_ptr
;
17477 cur_ptr
= info_ptr
;
17478 first_die
= last_sibling
= NULL
;
17482 struct die_info
*die
17483 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17487 *new_info_ptr
= cur_ptr
;
17494 last_sibling
->sibling
= die
;
17496 last_sibling
= die
;
17500 /* Read a die, all of its descendents, and all of its siblings; set
17501 all of the fields of all of the dies correctly. Arguments are as
17502 in read_die_and_children.
17503 This the main entry point for reading a DIE and all its children. */
17505 static struct die_info
*
17506 read_die_and_siblings (const struct die_reader_specs
*reader
,
17507 const gdb_byte
*info_ptr
,
17508 const gdb_byte
**new_info_ptr
,
17509 struct die_info
*parent
)
17511 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17512 new_info_ptr
, parent
);
17514 if (dwarf_die_debug
)
17516 fprintf_unfiltered (gdb_stdlog
,
17517 "Read die from %s@0x%x of %s:\n",
17518 reader
->die_section
->get_name (),
17519 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17520 bfd_get_filename (reader
->abfd
));
17521 dump_die (die
, dwarf_die_debug
);
17527 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17529 The caller is responsible for filling in the extra attributes
17530 and updating (*DIEP)->num_attrs.
17531 Set DIEP to point to a newly allocated die with its information,
17532 except for its child, sibling, and parent fields. */
17534 static const gdb_byte
*
17535 read_full_die_1 (const struct die_reader_specs
*reader
,
17536 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17537 int num_extra_attrs
)
17539 unsigned int abbrev_number
, bytes_read
, i
;
17540 struct abbrev_info
*abbrev
;
17541 struct die_info
*die
;
17542 struct dwarf2_cu
*cu
= reader
->cu
;
17543 bfd
*abfd
= reader
->abfd
;
17545 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17546 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17547 info_ptr
+= bytes_read
;
17548 if (!abbrev_number
)
17554 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17556 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17558 bfd_get_filename (abfd
));
17560 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17561 die
->sect_off
= sect_off
;
17562 die
->tag
= abbrev
->tag
;
17563 die
->abbrev
= abbrev_number
;
17564 die
->has_children
= abbrev
->has_children
;
17566 /* Make the result usable.
17567 The caller needs to update num_attrs after adding the extra
17569 die
->num_attrs
= abbrev
->num_attrs
;
17571 std::vector
<int> indexes_that_need_reprocess
;
17572 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17574 bool need_reprocess
;
17576 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17577 info_ptr
, &need_reprocess
);
17578 if (need_reprocess
)
17579 indexes_that_need_reprocess
.push_back (i
);
17582 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17583 if (attr
!= nullptr)
17584 cu
->str_offsets_base
= DW_UNSND (attr
);
17586 auto maybe_addr_base
= lookup_addr_base(die
);
17587 if (maybe_addr_base
.has_value ())
17588 cu
->addr_base
= *maybe_addr_base
;
17589 for (int index
: indexes_that_need_reprocess
)
17590 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17595 /* Read a die and all its attributes.
17596 Set DIEP to point to a newly allocated die with its information,
17597 except for its child, sibling, and parent fields. */
17599 static const gdb_byte
*
17600 read_full_die (const struct die_reader_specs
*reader
,
17601 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17603 const gdb_byte
*result
;
17605 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17607 if (dwarf_die_debug
)
17609 fprintf_unfiltered (gdb_stdlog
,
17610 "Read die from %s@0x%x of %s:\n",
17611 reader
->die_section
->get_name (),
17612 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17613 bfd_get_filename (reader
->abfd
));
17614 dump_die (*diep
, dwarf_die_debug
);
17621 /* Returns nonzero if TAG represents a type that we might generate a partial
17625 is_type_tag_for_partial (int tag
)
17630 /* Some types that would be reasonable to generate partial symbols for,
17631 that we don't at present. */
17632 case DW_TAG_array_type
:
17633 case DW_TAG_file_type
:
17634 case DW_TAG_ptr_to_member_type
:
17635 case DW_TAG_set_type
:
17636 case DW_TAG_string_type
:
17637 case DW_TAG_subroutine_type
:
17639 case DW_TAG_base_type
:
17640 case DW_TAG_class_type
:
17641 case DW_TAG_interface_type
:
17642 case DW_TAG_enumeration_type
:
17643 case DW_TAG_structure_type
:
17644 case DW_TAG_subrange_type
:
17645 case DW_TAG_typedef
:
17646 case DW_TAG_union_type
:
17653 /* Load all DIEs that are interesting for partial symbols into memory. */
17655 static struct partial_die_info
*
17656 load_partial_dies (const struct die_reader_specs
*reader
,
17657 const gdb_byte
*info_ptr
, int building_psymtab
)
17659 struct dwarf2_cu
*cu
= reader
->cu
;
17660 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17661 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17662 unsigned int bytes_read
;
17663 unsigned int load_all
= 0;
17664 int nesting_level
= 1;
17669 gdb_assert (cu
->per_cu
!= NULL
);
17670 if (cu
->per_cu
->load_all_dies
)
17674 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17678 &cu
->comp_unit_obstack
,
17679 hashtab_obstack_allocate
,
17680 dummy_obstack_deallocate
);
17684 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17686 /* A NULL abbrev means the end of a series of children. */
17687 if (abbrev
== NULL
)
17689 if (--nesting_level
== 0)
17692 info_ptr
+= bytes_read
;
17693 last_die
= parent_die
;
17694 parent_die
= parent_die
->die_parent
;
17698 /* Check for template arguments. We never save these; if
17699 they're seen, we just mark the parent, and go on our way. */
17700 if (parent_die
!= NULL
17701 && cu
->language
== language_cplus
17702 && (abbrev
->tag
== DW_TAG_template_type_param
17703 || abbrev
->tag
== DW_TAG_template_value_param
))
17705 parent_die
->has_template_arguments
= 1;
17709 /* We don't need a partial DIE for the template argument. */
17710 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17715 /* We only recurse into c++ subprograms looking for template arguments.
17716 Skip their other children. */
17718 && cu
->language
== language_cplus
17719 && parent_die
!= NULL
17720 && parent_die
->tag
== DW_TAG_subprogram
)
17722 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17726 /* Check whether this DIE is interesting enough to save. Normally
17727 we would not be interested in members here, but there may be
17728 later variables referencing them via DW_AT_specification (for
17729 static members). */
17731 && !is_type_tag_for_partial (abbrev
->tag
)
17732 && abbrev
->tag
!= DW_TAG_constant
17733 && abbrev
->tag
!= DW_TAG_enumerator
17734 && abbrev
->tag
!= DW_TAG_subprogram
17735 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17736 && abbrev
->tag
!= DW_TAG_lexical_block
17737 && abbrev
->tag
!= DW_TAG_variable
17738 && abbrev
->tag
!= DW_TAG_namespace
17739 && abbrev
->tag
!= DW_TAG_module
17740 && abbrev
->tag
!= DW_TAG_member
17741 && abbrev
->tag
!= DW_TAG_imported_unit
17742 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17744 /* Otherwise we skip to the next sibling, if any. */
17745 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17749 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17752 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17754 /* This two-pass algorithm for processing partial symbols has a
17755 high cost in cache pressure. Thus, handle some simple cases
17756 here which cover the majority of C partial symbols. DIEs
17757 which neither have specification tags in them, nor could have
17758 specification tags elsewhere pointing at them, can simply be
17759 processed and discarded.
17761 This segment is also optional; scan_partial_symbols and
17762 add_partial_symbol will handle these DIEs if we chain
17763 them in normally. When compilers which do not emit large
17764 quantities of duplicate debug information are more common,
17765 this code can probably be removed. */
17767 /* Any complete simple types at the top level (pretty much all
17768 of them, for a language without namespaces), can be processed
17770 if (parent_die
== NULL
17771 && pdi
.has_specification
== 0
17772 && pdi
.is_declaration
== 0
17773 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17774 || pdi
.tag
== DW_TAG_base_type
17775 || pdi
.tag
== DW_TAG_subrange_type
))
17777 if (building_psymtab
&& pdi
.name
!= NULL
)
17778 add_psymbol_to_list (pdi
.name
, false,
17779 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17780 psymbol_placement::STATIC
,
17781 0, cu
->language
, objfile
);
17782 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17786 /* The exception for DW_TAG_typedef with has_children above is
17787 a workaround of GCC PR debug/47510. In the case of this complaint
17788 type_name_or_error will error on such types later.
17790 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17791 it could not find the child DIEs referenced later, this is checked
17792 above. In correct DWARF DW_TAG_typedef should have no children. */
17794 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17795 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17796 "- DIE at %s [in module %s]"),
17797 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17799 /* If we're at the second level, and we're an enumerator, and
17800 our parent has no specification (meaning possibly lives in a
17801 namespace elsewhere), then we can add the partial symbol now
17802 instead of queueing it. */
17803 if (pdi
.tag
== DW_TAG_enumerator
17804 && parent_die
!= NULL
17805 && parent_die
->die_parent
== NULL
17806 && parent_die
->tag
== DW_TAG_enumeration_type
17807 && parent_die
->has_specification
== 0)
17809 if (pdi
.name
== NULL
)
17810 complaint (_("malformed enumerator DIE ignored"));
17811 else if (building_psymtab
)
17812 add_psymbol_to_list (pdi
.name
, false,
17813 VAR_DOMAIN
, LOC_CONST
, -1,
17814 cu
->language
== language_cplus
17815 ? psymbol_placement::GLOBAL
17816 : psymbol_placement::STATIC
,
17817 0, cu
->language
, objfile
);
17819 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17823 struct partial_die_info
*part_die
17824 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17826 /* We'll save this DIE so link it in. */
17827 part_die
->die_parent
= parent_die
;
17828 part_die
->die_sibling
= NULL
;
17829 part_die
->die_child
= NULL
;
17831 if (last_die
&& last_die
== parent_die
)
17832 last_die
->die_child
= part_die
;
17834 last_die
->die_sibling
= part_die
;
17836 last_die
= part_die
;
17838 if (first_die
== NULL
)
17839 first_die
= part_die
;
17841 /* Maybe add the DIE to the hash table. Not all DIEs that we
17842 find interesting need to be in the hash table, because we
17843 also have the parent/sibling/child chains; only those that we
17844 might refer to by offset later during partial symbol reading.
17846 For now this means things that might have be the target of a
17847 DW_AT_specification, DW_AT_abstract_origin, or
17848 DW_AT_extension. DW_AT_extension will refer only to
17849 namespaces; DW_AT_abstract_origin refers to functions (and
17850 many things under the function DIE, but we do not recurse
17851 into function DIEs during partial symbol reading) and
17852 possibly variables as well; DW_AT_specification refers to
17853 declarations. Declarations ought to have the DW_AT_declaration
17854 flag. It happens that GCC forgets to put it in sometimes, but
17855 only for functions, not for types.
17857 Adding more things than necessary to the hash table is harmless
17858 except for the performance cost. Adding too few will result in
17859 wasted time in find_partial_die, when we reread the compilation
17860 unit with load_all_dies set. */
17863 || abbrev
->tag
== DW_TAG_constant
17864 || abbrev
->tag
== DW_TAG_subprogram
17865 || abbrev
->tag
== DW_TAG_variable
17866 || abbrev
->tag
== DW_TAG_namespace
17867 || part_die
->is_declaration
)
17871 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17872 to_underlying (part_die
->sect_off
),
17877 /* For some DIEs we want to follow their children (if any). For C
17878 we have no reason to follow the children of structures; for other
17879 languages we have to, so that we can get at method physnames
17880 to infer fully qualified class names, for DW_AT_specification,
17881 and for C++ template arguments. For C++, we also look one level
17882 inside functions to find template arguments (if the name of the
17883 function does not already contain the template arguments).
17885 For Ada and Fortran, we need to scan the children of subprograms
17886 and lexical blocks as well because these languages allow the
17887 definition of nested entities that could be interesting for the
17888 debugger, such as nested subprograms for instance. */
17889 if (last_die
->has_children
17891 || last_die
->tag
== DW_TAG_namespace
17892 || last_die
->tag
== DW_TAG_module
17893 || last_die
->tag
== DW_TAG_enumeration_type
17894 || (cu
->language
== language_cplus
17895 && last_die
->tag
== DW_TAG_subprogram
17896 && (last_die
->name
== NULL
17897 || strchr (last_die
->name
, '<') == NULL
))
17898 || (cu
->language
!= language_c
17899 && (last_die
->tag
== DW_TAG_class_type
17900 || last_die
->tag
== DW_TAG_interface_type
17901 || last_die
->tag
== DW_TAG_structure_type
17902 || last_die
->tag
== DW_TAG_union_type
))
17903 || ((cu
->language
== language_ada
17904 || cu
->language
== language_fortran
)
17905 && (last_die
->tag
== DW_TAG_subprogram
17906 || last_die
->tag
== DW_TAG_lexical_block
))))
17909 parent_die
= last_die
;
17913 /* Otherwise we skip to the next sibling, if any. */
17914 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17916 /* Back to the top, do it again. */
17920 partial_die_info::partial_die_info (sect_offset sect_off_
,
17921 struct abbrev_info
*abbrev
)
17922 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17926 /* Read a minimal amount of information into the minimal die structure.
17927 INFO_PTR should point just after the initial uleb128 of a DIE. */
17930 partial_die_info::read (const struct die_reader_specs
*reader
,
17931 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17933 struct dwarf2_cu
*cu
= reader
->cu
;
17934 struct dwarf2_per_objfile
*dwarf2_per_objfile
17935 = cu
->per_cu
->dwarf2_per_objfile
;
17937 int has_low_pc_attr
= 0;
17938 int has_high_pc_attr
= 0;
17939 int high_pc_relative
= 0;
17941 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17942 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17944 bool need_reprocess
;
17945 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17946 info_ptr
, &need_reprocess
);
17947 /* String and address offsets that need to do the reprocessing have
17948 already been read at this point, so there is no need to wait until
17949 the loop terminates to do the reprocessing. */
17950 if (need_reprocess
)
17951 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17952 attribute
&attr
= attr_vec
[i
];
17953 /* Store the data if it is of an attribute we want to keep in a
17954 partial symbol table. */
17960 case DW_TAG_compile_unit
:
17961 case DW_TAG_partial_unit
:
17962 case DW_TAG_type_unit
:
17963 /* Compilation units have a DW_AT_name that is a filename, not
17964 a source language identifier. */
17965 case DW_TAG_enumeration_type
:
17966 case DW_TAG_enumerator
:
17967 /* These tags always have simple identifiers already; no need
17968 to canonicalize them. */
17969 name
= DW_STRING (&attr
);
17973 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17976 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
17977 &objfile
->per_bfd
->storage_obstack
);
17982 case DW_AT_linkage_name
:
17983 case DW_AT_MIPS_linkage_name
:
17984 /* Note that both forms of linkage name might appear. We
17985 assume they will be the same, and we only store the last
17987 linkage_name
= DW_STRING (&attr
);
17990 has_low_pc_attr
= 1;
17991 lowpc
= attr
.value_as_address ();
17993 case DW_AT_high_pc
:
17994 has_high_pc_attr
= 1;
17995 highpc
= attr
.value_as_address ();
17996 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17997 high_pc_relative
= 1;
17999 case DW_AT_location
:
18000 /* Support the .debug_loc offsets. */
18001 if (attr
.form_is_block ())
18003 d
.locdesc
= DW_BLOCK (&attr
);
18005 else if (attr
.form_is_section_offset ())
18007 dwarf2_complex_location_expr_complaint ();
18011 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18012 "partial symbol information");
18015 case DW_AT_external
:
18016 is_external
= DW_UNSND (&attr
);
18018 case DW_AT_declaration
:
18019 is_declaration
= DW_UNSND (&attr
);
18024 case DW_AT_abstract_origin
:
18025 case DW_AT_specification
:
18026 case DW_AT_extension
:
18027 has_specification
= 1;
18028 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18029 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18030 || cu
->per_cu
->is_dwz
);
18032 case DW_AT_sibling
:
18033 /* Ignore absolute siblings, they might point outside of
18034 the current compile unit. */
18035 if (attr
.form
== DW_FORM_ref_addr
)
18036 complaint (_("ignoring absolute DW_AT_sibling"));
18039 const gdb_byte
*buffer
= reader
->buffer
;
18040 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18041 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18043 if (sibling_ptr
< info_ptr
)
18044 complaint (_("DW_AT_sibling points backwards"));
18045 else if (sibling_ptr
> reader
->buffer_end
)
18046 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18048 sibling
= sibling_ptr
;
18051 case DW_AT_byte_size
:
18054 case DW_AT_const_value
:
18055 has_const_value
= 1;
18057 case DW_AT_calling_convention
:
18058 /* DWARF doesn't provide a way to identify a program's source-level
18059 entry point. DW_AT_calling_convention attributes are only meant
18060 to describe functions' calling conventions.
18062 However, because it's a necessary piece of information in
18063 Fortran, and before DWARF 4 DW_CC_program was the only
18064 piece of debugging information whose definition refers to
18065 a 'main program' at all, several compilers marked Fortran
18066 main programs with DW_CC_program --- even when those
18067 functions use the standard calling conventions.
18069 Although DWARF now specifies a way to provide this
18070 information, we support this practice for backward
18072 if (DW_UNSND (&attr
) == DW_CC_program
18073 && cu
->language
== language_fortran
)
18074 main_subprogram
= 1;
18077 if (DW_UNSND (&attr
) == DW_INL_inlined
18078 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18079 may_be_inlined
= 1;
18083 if (tag
== DW_TAG_imported_unit
)
18085 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18086 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18087 || cu
->per_cu
->is_dwz
);
18091 case DW_AT_main_subprogram
:
18092 main_subprogram
= DW_UNSND (&attr
);
18097 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18098 but that requires a full DIE, so instead we just
18100 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18101 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18102 + (need_ranges_base
18106 /* Value of the DW_AT_ranges attribute is the offset in the
18107 .debug_ranges section. */
18108 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18119 /* For Ada, if both the name and the linkage name appear, we prefer
18120 the latter. This lets "catch exception" work better, regardless
18121 of the order in which the name and linkage name were emitted.
18122 Really, though, this is just a workaround for the fact that gdb
18123 doesn't store both the name and the linkage name. */
18124 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18125 name
= linkage_name
;
18127 if (high_pc_relative
)
18130 if (has_low_pc_attr
&& has_high_pc_attr
)
18132 /* When using the GNU linker, .gnu.linkonce. sections are used to
18133 eliminate duplicate copies of functions and vtables and such.
18134 The linker will arbitrarily choose one and discard the others.
18135 The AT_*_pc values for such functions refer to local labels in
18136 these sections. If the section from that file was discarded, the
18137 labels are not in the output, so the relocs get a value of 0.
18138 If this is a discarded function, mark the pc bounds as invalid,
18139 so that GDB will ignore it. */
18140 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18142 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18143 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18145 complaint (_("DW_AT_low_pc %s is zero "
18146 "for DIE at %s [in module %s]"),
18147 paddress (gdbarch
, lowpc
),
18148 sect_offset_str (sect_off
),
18149 objfile_name (objfile
));
18151 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18152 else if (lowpc
>= highpc
)
18154 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18155 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18157 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18158 "for DIE at %s [in module %s]"),
18159 paddress (gdbarch
, lowpc
),
18160 paddress (gdbarch
, highpc
),
18161 sect_offset_str (sect_off
),
18162 objfile_name (objfile
));
18171 /* Find a cached partial DIE at OFFSET in CU. */
18173 struct partial_die_info
*
18174 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18176 struct partial_die_info
*lookup_die
= NULL
;
18177 struct partial_die_info
part_die (sect_off
);
18179 lookup_die
= ((struct partial_die_info
*)
18180 htab_find_with_hash (partial_dies
, &part_die
,
18181 to_underlying (sect_off
)));
18186 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18187 except in the case of .debug_types DIEs which do not reference
18188 outside their CU (they do however referencing other types via
18189 DW_FORM_ref_sig8). */
18191 static const struct cu_partial_die_info
18192 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18194 struct dwarf2_per_objfile
*dwarf2_per_objfile
18195 = cu
->per_cu
->dwarf2_per_objfile
;
18196 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18197 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18198 struct partial_die_info
*pd
= NULL
;
18200 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18201 && cu
->header
.offset_in_cu_p (sect_off
))
18203 pd
= cu
->find_partial_die (sect_off
);
18206 /* We missed recording what we needed.
18207 Load all dies and try again. */
18208 per_cu
= cu
->per_cu
;
18212 /* TUs don't reference other CUs/TUs (except via type signatures). */
18213 if (cu
->per_cu
->is_debug_types
)
18215 error (_("Dwarf Error: Type Unit at offset %s contains"
18216 " external reference to offset %s [in module %s].\n"),
18217 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18218 bfd_get_filename (objfile
->obfd
));
18220 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18221 dwarf2_per_objfile
);
18223 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18224 load_partial_comp_unit (per_cu
);
18226 per_cu
->cu
->last_used
= 0;
18227 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18230 /* If we didn't find it, and not all dies have been loaded,
18231 load them all and try again. */
18233 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18235 per_cu
->load_all_dies
= 1;
18237 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18238 THIS_CU->cu may already be in use. So we can't just free it and
18239 replace its DIEs with the ones we read in. Instead, we leave those
18240 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18241 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18243 load_partial_comp_unit (per_cu
);
18245 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18249 internal_error (__FILE__
, __LINE__
,
18250 _("could not find partial DIE %s "
18251 "in cache [from module %s]\n"),
18252 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18253 return { per_cu
->cu
, pd
};
18256 /* See if we can figure out if the class lives in a namespace. We do
18257 this by looking for a member function; its demangled name will
18258 contain namespace info, if there is any. */
18261 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18262 struct dwarf2_cu
*cu
)
18264 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18265 what template types look like, because the demangler
18266 frequently doesn't give the same name as the debug info. We
18267 could fix this by only using the demangled name to get the
18268 prefix (but see comment in read_structure_type). */
18270 struct partial_die_info
*real_pdi
;
18271 struct partial_die_info
*child_pdi
;
18273 /* If this DIE (this DIE's specification, if any) has a parent, then
18274 we should not do this. We'll prepend the parent's fully qualified
18275 name when we create the partial symbol. */
18277 real_pdi
= struct_pdi
;
18278 while (real_pdi
->has_specification
)
18280 auto res
= find_partial_die (real_pdi
->spec_offset
,
18281 real_pdi
->spec_is_dwz
, cu
);
18282 real_pdi
= res
.pdi
;
18286 if (real_pdi
->die_parent
!= NULL
)
18289 for (child_pdi
= struct_pdi
->die_child
;
18291 child_pdi
= child_pdi
->die_sibling
)
18293 if (child_pdi
->tag
== DW_TAG_subprogram
18294 && child_pdi
->linkage_name
!= NULL
)
18296 gdb::unique_xmalloc_ptr
<char> actual_class_name
18297 (language_class_name_from_physname (cu
->language_defn
,
18298 child_pdi
->linkage_name
));
18299 if (actual_class_name
!= NULL
)
18301 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18303 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
18304 actual_class_name
.get ());
18312 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18314 /* Once we've fixed up a die, there's no point in doing so again.
18315 This also avoids a memory leak if we were to call
18316 guess_partial_die_structure_name multiple times. */
18320 /* If we found a reference attribute and the DIE has no name, try
18321 to find a name in the referred to DIE. */
18323 if (name
== NULL
&& has_specification
)
18325 struct partial_die_info
*spec_die
;
18327 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18328 spec_die
= res
.pdi
;
18331 spec_die
->fixup (cu
);
18333 if (spec_die
->name
)
18335 name
= spec_die
->name
;
18337 /* Copy DW_AT_external attribute if it is set. */
18338 if (spec_die
->is_external
)
18339 is_external
= spec_die
->is_external
;
18343 /* Set default names for some unnamed DIEs. */
18345 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18346 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18348 /* If there is no parent die to provide a namespace, and there are
18349 children, see if we can determine the namespace from their linkage
18351 if (cu
->language
== language_cplus
18352 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18353 && die_parent
== NULL
18355 && (tag
== DW_TAG_class_type
18356 || tag
== DW_TAG_structure_type
18357 || tag
== DW_TAG_union_type
))
18358 guess_partial_die_structure_name (this, cu
);
18360 /* GCC might emit a nameless struct or union that has a linkage
18361 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18363 && (tag
== DW_TAG_class_type
18364 || tag
== DW_TAG_interface_type
18365 || tag
== DW_TAG_structure_type
18366 || tag
== DW_TAG_union_type
)
18367 && linkage_name
!= NULL
)
18369 gdb::unique_xmalloc_ptr
<char> demangled
18370 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18371 if (demangled
!= nullptr)
18375 /* Strip any leading namespaces/classes, keep only the base name.
18376 DW_AT_name for named DIEs does not contain the prefixes. */
18377 base
= strrchr (demangled
.get (), ':');
18378 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18381 base
= demangled
.get ();
18383 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18384 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
18391 /* Process the attributes that had to be skipped in the first round. These
18392 attributes are the ones that need str_offsets_base or addr_base attributes.
18393 They could not have been processed in the first round, because at the time
18394 the values of str_offsets_base or addr_base may not have been known. */
18395 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18396 struct attribute
*attr
)
18398 struct dwarf2_cu
*cu
= reader
->cu
;
18399 switch (attr
->form
)
18401 case DW_FORM_addrx
:
18402 case DW_FORM_GNU_addr_index
:
18403 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18406 case DW_FORM_strx1
:
18407 case DW_FORM_strx2
:
18408 case DW_FORM_strx3
:
18409 case DW_FORM_strx4
:
18410 case DW_FORM_GNU_str_index
:
18412 unsigned int str_index
= DW_UNSND (attr
);
18413 if (reader
->dwo_file
!= NULL
)
18415 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18416 DW_STRING_IS_CANONICAL (attr
) = 0;
18420 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18421 DW_STRING_IS_CANONICAL (attr
) = 0;
18426 gdb_assert_not_reached (_("Unexpected DWARF form."));
18430 /* Read an attribute value described by an attribute form. */
18432 static const gdb_byte
*
18433 read_attribute_value (const struct die_reader_specs
*reader
,
18434 struct attribute
*attr
, unsigned form
,
18435 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18436 bool *need_reprocess
)
18438 struct dwarf2_cu
*cu
= reader
->cu
;
18439 struct dwarf2_per_objfile
*dwarf2_per_objfile
18440 = cu
->per_cu
->dwarf2_per_objfile
;
18441 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18442 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18443 bfd
*abfd
= reader
->abfd
;
18444 struct comp_unit_head
*cu_header
= &cu
->header
;
18445 unsigned int bytes_read
;
18446 struct dwarf_block
*blk
;
18447 *need_reprocess
= false;
18449 attr
->form
= (enum dwarf_form
) form
;
18452 case DW_FORM_ref_addr
:
18453 if (cu
->header
.version
== 2)
18454 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18457 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18459 info_ptr
+= bytes_read
;
18461 case DW_FORM_GNU_ref_alt
:
18462 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18463 info_ptr
+= bytes_read
;
18466 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18467 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18468 info_ptr
+= bytes_read
;
18470 case DW_FORM_block2
:
18471 blk
= dwarf_alloc_block (cu
);
18472 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18474 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18475 info_ptr
+= blk
->size
;
18476 DW_BLOCK (attr
) = blk
;
18478 case DW_FORM_block4
:
18479 blk
= dwarf_alloc_block (cu
);
18480 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18482 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18483 info_ptr
+= blk
->size
;
18484 DW_BLOCK (attr
) = blk
;
18486 case DW_FORM_data2
:
18487 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18490 case DW_FORM_data4
:
18491 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18494 case DW_FORM_data8
:
18495 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18498 case DW_FORM_data16
:
18499 blk
= dwarf_alloc_block (cu
);
18501 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18503 DW_BLOCK (attr
) = blk
;
18505 case DW_FORM_sec_offset
:
18506 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18507 info_ptr
+= bytes_read
;
18509 case DW_FORM_string
:
18510 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18511 DW_STRING_IS_CANONICAL (attr
) = 0;
18512 info_ptr
+= bytes_read
;
18515 if (!cu
->per_cu
->is_dwz
)
18517 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18518 abfd
, info_ptr
, cu_header
,
18520 DW_STRING_IS_CANONICAL (attr
) = 0;
18521 info_ptr
+= bytes_read
;
18525 case DW_FORM_line_strp
:
18526 if (!cu
->per_cu
->is_dwz
)
18528 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18530 cu_header
, &bytes_read
);
18531 DW_STRING_IS_CANONICAL (attr
) = 0;
18532 info_ptr
+= bytes_read
;
18536 case DW_FORM_GNU_strp_alt
:
18538 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18539 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18542 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
18544 DW_STRING_IS_CANONICAL (attr
) = 0;
18545 info_ptr
+= bytes_read
;
18548 case DW_FORM_exprloc
:
18549 case DW_FORM_block
:
18550 blk
= dwarf_alloc_block (cu
);
18551 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18552 info_ptr
+= bytes_read
;
18553 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18554 info_ptr
+= blk
->size
;
18555 DW_BLOCK (attr
) = blk
;
18557 case DW_FORM_block1
:
18558 blk
= dwarf_alloc_block (cu
);
18559 blk
->size
= read_1_byte (abfd
, info_ptr
);
18561 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18562 info_ptr
+= blk
->size
;
18563 DW_BLOCK (attr
) = blk
;
18565 case DW_FORM_data1
:
18566 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18570 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18573 case DW_FORM_flag_present
:
18574 DW_UNSND (attr
) = 1;
18576 case DW_FORM_sdata
:
18577 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18578 info_ptr
+= bytes_read
;
18580 case DW_FORM_udata
:
18581 case DW_FORM_rnglistx
:
18582 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18583 info_ptr
+= bytes_read
;
18586 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18587 + read_1_byte (abfd
, info_ptr
));
18591 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18592 + read_2_bytes (abfd
, info_ptr
));
18596 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18597 + read_4_bytes (abfd
, info_ptr
));
18601 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18602 + read_8_bytes (abfd
, info_ptr
));
18605 case DW_FORM_ref_sig8
:
18606 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18609 case DW_FORM_ref_udata
:
18610 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18611 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18612 info_ptr
+= bytes_read
;
18614 case DW_FORM_indirect
:
18615 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18616 info_ptr
+= bytes_read
;
18617 if (form
== DW_FORM_implicit_const
)
18619 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18620 info_ptr
+= bytes_read
;
18622 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18623 info_ptr
, need_reprocess
);
18625 case DW_FORM_implicit_const
:
18626 DW_SND (attr
) = implicit_const
;
18628 case DW_FORM_addrx
:
18629 case DW_FORM_GNU_addr_index
:
18630 *need_reprocess
= true;
18631 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18632 info_ptr
+= bytes_read
;
18635 case DW_FORM_strx1
:
18636 case DW_FORM_strx2
:
18637 case DW_FORM_strx3
:
18638 case DW_FORM_strx4
:
18639 case DW_FORM_GNU_str_index
:
18641 ULONGEST str_index
;
18642 if (form
== DW_FORM_strx1
)
18644 str_index
= read_1_byte (abfd
, info_ptr
);
18647 else if (form
== DW_FORM_strx2
)
18649 str_index
= read_2_bytes (abfd
, info_ptr
);
18652 else if (form
== DW_FORM_strx3
)
18654 str_index
= read_3_bytes (abfd
, info_ptr
);
18657 else if (form
== DW_FORM_strx4
)
18659 str_index
= read_4_bytes (abfd
, info_ptr
);
18664 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18665 info_ptr
+= bytes_read
;
18667 *need_reprocess
= true;
18668 DW_UNSND (attr
) = str_index
;
18672 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18673 dwarf_form_name (form
),
18674 bfd_get_filename (abfd
));
18678 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18679 attr
->form
= DW_FORM_GNU_ref_alt
;
18681 /* We have seen instances where the compiler tried to emit a byte
18682 size attribute of -1 which ended up being encoded as an unsigned
18683 0xffffffff. Although 0xffffffff is technically a valid size value,
18684 an object of this size seems pretty unlikely so we can relatively
18685 safely treat these cases as if the size attribute was invalid and
18686 treat them as zero by default. */
18687 if (attr
->name
== DW_AT_byte_size
18688 && form
== DW_FORM_data4
18689 && DW_UNSND (attr
) >= 0xffffffff)
18692 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18693 hex_string (DW_UNSND (attr
)));
18694 DW_UNSND (attr
) = 0;
18700 /* Read an attribute described by an abbreviated attribute. */
18702 static const gdb_byte
*
18703 read_attribute (const struct die_reader_specs
*reader
,
18704 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18705 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18707 attr
->name
= abbrev
->name
;
18708 return read_attribute_value (reader
, attr
, abbrev
->form
,
18709 abbrev
->implicit_const
, info_ptr
,
18713 /* Cover function for read_initial_length.
18714 Returns the length of the object at BUF, and stores the size of the
18715 initial length in *BYTES_READ and stores the size that offsets will be in
18717 If the initial length size is not equivalent to that specified in
18718 CU_HEADER then issue a complaint.
18719 This is useful when reading non-comp-unit headers. */
18722 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18723 const struct comp_unit_head
*cu_header
,
18724 unsigned int *bytes_read
,
18725 unsigned int *offset_size
)
18727 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18729 gdb_assert (cu_header
->initial_length_size
== 4
18730 || cu_header
->initial_length_size
== 8
18731 || cu_header
->initial_length_size
== 12);
18733 if (cu_header
->initial_length_size
!= *bytes_read
)
18734 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18736 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18740 /* Return pointer to string at section SECT offset STR_OFFSET with error
18741 reporting strings FORM_NAME and SECT_NAME. */
18743 static const char *
18744 read_indirect_string_at_offset_from (struct objfile
*objfile
,
18745 bfd
*abfd
, LONGEST str_offset
,
18746 struct dwarf2_section_info
*sect
,
18747 const char *form_name
,
18748 const char *sect_name
)
18750 sect
->read (objfile
);
18751 if (sect
->buffer
== NULL
)
18752 error (_("%s used without %s section [in module %s]"),
18753 form_name
, sect_name
, bfd_get_filename (abfd
));
18754 if (str_offset
>= sect
->size
)
18755 error (_("%s pointing outside of %s section [in module %s]"),
18756 form_name
, sect_name
, bfd_get_filename (abfd
));
18757 gdb_assert (HOST_CHAR_BIT
== 8);
18758 if (sect
->buffer
[str_offset
] == '\0')
18760 return (const char *) (sect
->buffer
+ str_offset
);
18763 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18765 static const char *
18766 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18767 bfd
*abfd
, LONGEST str_offset
)
18769 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18771 &dwarf2_per_objfile
->str
,
18772 "DW_FORM_strp", ".debug_str");
18775 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
18777 static const char *
18778 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18779 bfd
*abfd
, LONGEST str_offset
)
18781 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18783 &dwarf2_per_objfile
->line_str
,
18784 "DW_FORM_line_strp",
18785 ".debug_line_str");
18788 /* Read a string at offset STR_OFFSET in the .debug_str section from
18789 the .dwz file DWZ. Throw an error if the offset is too large. If
18790 the string consists of a single NUL byte, return NULL; otherwise
18791 return a pointer to the string. */
18793 static const char *
18794 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
18795 LONGEST str_offset
)
18797 dwz
->str
.read (objfile
);
18799 if (dwz
->str
.buffer
== NULL
)
18800 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
18801 "section [in module %s]"),
18802 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18803 if (str_offset
>= dwz
->str
.size
)
18804 error (_("DW_FORM_GNU_strp_alt pointing outside of "
18805 ".debug_str section [in module %s]"),
18806 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18807 gdb_assert (HOST_CHAR_BIT
== 8);
18808 if (dwz
->str
.buffer
[str_offset
] == '\0')
18810 return (const char *) (dwz
->str
.buffer
+ str_offset
);
18813 /* Return pointer to string at .debug_str offset as read from BUF.
18814 BUF is assumed to be in a compilation unit described by CU_HEADER.
18815 Return *BYTES_READ_PTR count of bytes read from BUF. */
18817 static const char *
18818 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18819 const gdb_byte
*buf
,
18820 const struct comp_unit_head
*cu_header
,
18821 unsigned int *bytes_read_ptr
)
18823 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18825 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
18828 /* Return pointer to string at .debug_line_str offset as read from BUF.
18829 BUF is assumed to be in a compilation unit described by CU_HEADER.
18830 Return *BYTES_READ_PTR count of bytes read from BUF. */
18832 static const char *
18833 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18834 bfd
*abfd
, const gdb_byte
*buf
,
18835 const struct comp_unit_head
*cu_header
,
18836 unsigned int *bytes_read_ptr
)
18838 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18840 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
18844 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18845 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18846 ADDR_SIZE is the size of addresses from the CU header. */
18849 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18850 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18853 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18854 bfd
*abfd
= objfile
->obfd
;
18855 const gdb_byte
*info_ptr
;
18856 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18858 dwarf2_per_objfile
->addr
.read (objfile
);
18859 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18860 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18861 objfile_name (objfile
));
18862 if (addr_base_or_zero
+ addr_index
* addr_size
18863 >= dwarf2_per_objfile
->addr
.size
)
18864 error (_("DW_FORM_addr_index pointing outside of "
18865 ".debug_addr section [in module %s]"),
18866 objfile_name (objfile
));
18867 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18868 + addr_base_or_zero
+ addr_index
* addr_size
);
18869 if (addr_size
== 4)
18870 return bfd_get_32 (abfd
, info_ptr
);
18872 return bfd_get_64 (abfd
, info_ptr
);
18875 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18878 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18880 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18881 cu
->addr_base
, cu
->header
.addr_size
);
18884 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18887 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18888 unsigned int *bytes_read
)
18890 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18891 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18893 return read_addr_index (cu
, addr_index
);
18896 /* Given an index in .debug_addr, fetch the value.
18897 NOTE: This can be called during dwarf expression evaluation,
18898 long after the debug information has been read, and thus per_cu->cu
18899 may no longer exist. */
18902 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
18903 unsigned int addr_index
)
18905 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18906 struct dwarf2_cu
*cu
= per_cu
->cu
;
18907 gdb::optional
<ULONGEST
> addr_base
;
18910 /* We need addr_base and addr_size.
18911 If we don't have PER_CU->cu, we have to get it.
18912 Nasty, but the alternative is storing the needed info in PER_CU,
18913 which at this point doesn't seem justified: it's not clear how frequently
18914 it would get used and it would increase the size of every PER_CU.
18915 Entry points like dwarf2_per_cu_addr_size do a similar thing
18916 so we're not in uncharted territory here.
18917 Alas we need to be a bit more complicated as addr_base is contained
18920 We don't need to read the entire CU(/TU).
18921 We just need the header and top level die.
18923 IWBN to use the aging mechanism to let us lazily later discard the CU.
18924 For now we skip this optimization. */
18928 addr_base
= cu
->addr_base
;
18929 addr_size
= cu
->header
.addr_size
;
18933 cutu_reader
reader (per_cu
, NULL
, 0, false);
18934 addr_base
= reader
.cu
->addr_base
;
18935 addr_size
= reader
.cu
->header
.addr_size
;
18938 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18942 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18943 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18946 static const char *
18947 read_str_index (struct dwarf2_cu
*cu
,
18948 struct dwarf2_section_info
*str_section
,
18949 struct dwarf2_section_info
*str_offsets_section
,
18950 ULONGEST str_offsets_base
, ULONGEST str_index
)
18952 struct dwarf2_per_objfile
*dwarf2_per_objfile
18953 = cu
->per_cu
->dwarf2_per_objfile
;
18954 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18955 const char *objf_name
= objfile_name (objfile
);
18956 bfd
*abfd
= objfile
->obfd
;
18957 const gdb_byte
*info_ptr
;
18958 ULONGEST str_offset
;
18959 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18961 str_section
->read (objfile
);
18962 str_offsets_section
->read (objfile
);
18963 if (str_section
->buffer
== NULL
)
18964 error (_("%s used without %s section"
18965 " in CU at offset %s [in module %s]"),
18966 form_name
, str_section
->get_name (),
18967 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18968 if (str_offsets_section
->buffer
== NULL
)
18969 error (_("%s used without %s section"
18970 " in CU at offset %s [in module %s]"),
18971 form_name
, str_section
->get_name (),
18972 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18973 info_ptr
= (str_offsets_section
->buffer
18975 + str_index
* cu
->header
.offset_size
);
18976 if (cu
->header
.offset_size
== 4)
18977 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18979 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18980 if (str_offset
>= str_section
->size
)
18981 error (_("Offset from %s pointing outside of"
18982 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18983 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18984 return (const char *) (str_section
->buffer
+ str_offset
);
18987 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18989 static const char *
18990 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18992 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18993 ? reader
->cu
->header
.addr_size
: 0;
18994 return read_str_index (reader
->cu
,
18995 &reader
->dwo_file
->sections
.str
,
18996 &reader
->dwo_file
->sections
.str_offsets
,
18997 str_offsets_base
, str_index
);
19000 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19002 static const char *
19003 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19005 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19006 const char *objf_name
= objfile_name (objfile
);
19007 static const char form_name
[] = "DW_FORM_GNU_str_index";
19008 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19010 if (!cu
->str_offsets_base
.has_value ())
19011 error (_("%s used in Fission stub without %s"
19012 " in CU at offset 0x%lx [in module %s]"),
19013 form_name
, str_offsets_attr_name
,
19014 (long) cu
->header
.offset_size
, objf_name
);
19016 return read_str_index (cu
,
19017 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19018 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19019 *cu
->str_offsets_base
, str_index
);
19022 /* Return the length of an LEB128 number in BUF. */
19025 leb128_size (const gdb_byte
*buf
)
19027 const gdb_byte
*begin
= buf
;
19033 if ((byte
& 128) == 0)
19034 return buf
- begin
;
19039 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19048 cu
->language
= language_c
;
19051 case DW_LANG_C_plus_plus
:
19052 case DW_LANG_C_plus_plus_11
:
19053 case DW_LANG_C_plus_plus_14
:
19054 cu
->language
= language_cplus
;
19057 cu
->language
= language_d
;
19059 case DW_LANG_Fortran77
:
19060 case DW_LANG_Fortran90
:
19061 case DW_LANG_Fortran95
:
19062 case DW_LANG_Fortran03
:
19063 case DW_LANG_Fortran08
:
19064 cu
->language
= language_fortran
;
19067 cu
->language
= language_go
;
19069 case DW_LANG_Mips_Assembler
:
19070 cu
->language
= language_asm
;
19072 case DW_LANG_Ada83
:
19073 case DW_LANG_Ada95
:
19074 cu
->language
= language_ada
;
19076 case DW_LANG_Modula2
:
19077 cu
->language
= language_m2
;
19079 case DW_LANG_Pascal83
:
19080 cu
->language
= language_pascal
;
19083 cu
->language
= language_objc
;
19086 case DW_LANG_Rust_old
:
19087 cu
->language
= language_rust
;
19089 case DW_LANG_Cobol74
:
19090 case DW_LANG_Cobol85
:
19092 cu
->language
= language_minimal
;
19095 cu
->language_defn
= language_def (cu
->language
);
19098 /* Return the named attribute or NULL if not there. */
19100 static struct attribute
*
19101 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19106 struct attribute
*spec
= NULL
;
19108 for (i
= 0; i
< die
->num_attrs
; ++i
)
19110 if (die
->attrs
[i
].name
== name
)
19111 return &die
->attrs
[i
];
19112 if (die
->attrs
[i
].name
== DW_AT_specification
19113 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19114 spec
= &die
->attrs
[i
];
19120 die
= follow_die_ref (die
, spec
, &cu
);
19126 /* Return the named attribute or NULL if not there,
19127 but do not follow DW_AT_specification, etc.
19128 This is for use in contexts where we're reading .debug_types dies.
19129 Following DW_AT_specification, DW_AT_abstract_origin will take us
19130 back up the chain, and we want to go down. */
19132 static struct attribute
*
19133 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19137 for (i
= 0; i
< die
->num_attrs
; ++i
)
19138 if (die
->attrs
[i
].name
== name
)
19139 return &die
->attrs
[i
];
19144 /* Return the string associated with a string-typed attribute, or NULL if it
19145 is either not found or is of an incorrect type. */
19147 static const char *
19148 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19150 struct attribute
*attr
;
19151 const char *str
= NULL
;
19153 attr
= dwarf2_attr (die
, name
, cu
);
19157 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19158 || attr
->form
== DW_FORM_string
19159 || attr
->form
== DW_FORM_strx
19160 || attr
->form
== DW_FORM_strx1
19161 || attr
->form
== DW_FORM_strx2
19162 || attr
->form
== DW_FORM_strx3
19163 || attr
->form
== DW_FORM_strx4
19164 || attr
->form
== DW_FORM_GNU_str_index
19165 || attr
->form
== DW_FORM_GNU_strp_alt
)
19166 str
= DW_STRING (attr
);
19168 complaint (_("string type expected for attribute %s for "
19169 "DIE at %s in module %s"),
19170 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19171 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19177 /* Return the dwo name or NULL if not present. If present, it is in either
19178 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19179 static const char *
19180 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19182 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19183 if (dwo_name
== nullptr)
19184 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19188 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19189 and holds a non-zero value. This function should only be used for
19190 DW_FORM_flag or DW_FORM_flag_present attributes. */
19193 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19195 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19197 return (attr
&& DW_UNSND (attr
));
19201 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19203 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19204 which value is non-zero. However, we have to be careful with
19205 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19206 (via dwarf2_flag_true_p) follows this attribute. So we may
19207 end up accidently finding a declaration attribute that belongs
19208 to a different DIE referenced by the specification attribute,
19209 even though the given DIE does not have a declaration attribute. */
19210 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19211 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19214 /* Return the die giving the specification for DIE, if there is
19215 one. *SPEC_CU is the CU containing DIE on input, and the CU
19216 containing the return value on output. If there is no
19217 specification, but there is an abstract origin, that is
19220 static struct die_info
*
19221 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19223 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19226 if (spec_attr
== NULL
)
19227 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19229 if (spec_attr
== NULL
)
19232 return follow_die_ref (die
, spec_attr
, spec_cu
);
19235 /* Stub for free_line_header to match void * callback types. */
19238 free_line_header_voidp (void *arg
)
19240 struct line_header
*lh
= (struct line_header
*) arg
;
19245 /* A convenience function to find the proper .debug_line section for a CU. */
19247 static struct dwarf2_section_info
*
19248 get_debug_line_section (struct dwarf2_cu
*cu
)
19250 struct dwarf2_section_info
*section
;
19251 struct dwarf2_per_objfile
*dwarf2_per_objfile
19252 = cu
->per_cu
->dwarf2_per_objfile
;
19254 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19256 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19257 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19258 else if (cu
->per_cu
->is_dwz
)
19260 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19262 section
= &dwz
->line
;
19265 section
= &dwarf2_per_objfile
->line
;
19270 /* Read directory or file name entry format, starting with byte of
19271 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19272 entries count and the entries themselves in the described entry
19276 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19277 bfd
*abfd
, const gdb_byte
**bufp
,
19278 struct line_header
*lh
,
19279 const struct comp_unit_head
*cu_header
,
19280 void (*callback
) (struct line_header
*lh
,
19283 unsigned int mod_time
,
19284 unsigned int length
))
19286 gdb_byte format_count
, formati
;
19287 ULONGEST data_count
, datai
;
19288 const gdb_byte
*buf
= *bufp
;
19289 const gdb_byte
*format_header_data
;
19290 unsigned int bytes_read
;
19292 format_count
= read_1_byte (abfd
, buf
);
19294 format_header_data
= buf
;
19295 for (formati
= 0; formati
< format_count
; formati
++)
19297 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19299 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19303 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19305 for (datai
= 0; datai
< data_count
; datai
++)
19307 const gdb_byte
*format
= format_header_data
;
19308 struct file_entry fe
;
19310 for (formati
= 0; formati
< format_count
; formati
++)
19312 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19313 format
+= bytes_read
;
19315 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19316 format
+= bytes_read
;
19318 gdb::optional
<const char *> string
;
19319 gdb::optional
<unsigned int> uint
;
19323 case DW_FORM_string
:
19324 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19328 case DW_FORM_line_strp
:
19329 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19336 case DW_FORM_data1
:
19337 uint
.emplace (read_1_byte (abfd
, buf
));
19341 case DW_FORM_data2
:
19342 uint
.emplace (read_2_bytes (abfd
, buf
));
19346 case DW_FORM_data4
:
19347 uint
.emplace (read_4_bytes (abfd
, buf
));
19351 case DW_FORM_data8
:
19352 uint
.emplace (read_8_bytes (abfd
, buf
));
19356 case DW_FORM_data16
:
19357 /* This is used for MD5, but file_entry does not record MD5s. */
19361 case DW_FORM_udata
:
19362 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19366 case DW_FORM_block
:
19367 /* It is valid only for DW_LNCT_timestamp which is ignored by
19372 switch (content_type
)
19375 if (string
.has_value ())
19378 case DW_LNCT_directory_index
:
19379 if (uint
.has_value ())
19380 fe
.d_index
= (dir_index
) *uint
;
19382 case DW_LNCT_timestamp
:
19383 if (uint
.has_value ())
19384 fe
.mod_time
= *uint
;
19387 if (uint
.has_value ())
19393 complaint (_("Unknown format content type %s"),
19394 pulongest (content_type
));
19398 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19404 /* Read the statement program header starting at OFFSET in
19405 .debug_line, or .debug_line.dwo. Return a pointer
19406 to a struct line_header, allocated using xmalloc.
19407 Returns NULL if there is a problem reading the header, e.g., if it
19408 has a version we don't understand.
19410 NOTE: the strings in the include directory and file name tables of
19411 the returned object point into the dwarf line section buffer,
19412 and must not be freed. */
19414 static line_header_up
19415 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19417 const gdb_byte
*line_ptr
;
19418 unsigned int bytes_read
, offset_size
;
19420 const char *cur_dir
, *cur_file
;
19421 struct dwarf2_section_info
*section
;
19423 struct dwarf2_per_objfile
*dwarf2_per_objfile
19424 = cu
->per_cu
->dwarf2_per_objfile
;
19426 section
= get_debug_line_section (cu
);
19427 section
->read (dwarf2_per_objfile
->objfile
);
19428 if (section
->buffer
== NULL
)
19430 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19431 complaint (_("missing .debug_line.dwo section"));
19433 complaint (_("missing .debug_line section"));
19437 /* We can't do this until we know the section is non-empty.
19438 Only then do we know we have such a section. */
19439 abfd
= section
->get_bfd_owner ();
19441 /* Make sure that at least there's room for the total_length field.
19442 That could be 12 bytes long, but we're just going to fudge that. */
19443 if (to_underlying (sect_off
) + 4 >= section
->size
)
19445 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19449 line_header_up
lh (new line_header ());
19451 lh
->sect_off
= sect_off
;
19452 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19454 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19456 /* Read in the header. */
19458 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19459 &bytes_read
, &offset_size
);
19460 line_ptr
+= bytes_read
;
19462 const gdb_byte
*start_here
= line_ptr
;
19464 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19466 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19469 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19470 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19472 if (lh
->version
> 5)
19474 /* This is a version we don't understand. The format could have
19475 changed in ways we don't handle properly so just punt. */
19476 complaint (_("unsupported version in .debug_line section"));
19479 if (lh
->version
>= 5)
19481 gdb_byte segment_selector_size
;
19483 /* Skip address size. */
19484 read_1_byte (abfd
, line_ptr
);
19487 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19489 if (segment_selector_size
!= 0)
19491 complaint (_("unsupported segment selector size %u "
19492 "in .debug_line section"),
19493 segment_selector_size
);
19497 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19498 line_ptr
+= offset_size
;
19499 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19500 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19502 if (lh
->version
>= 4)
19504 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19508 lh
->maximum_ops_per_instruction
= 1;
19510 if (lh
->maximum_ops_per_instruction
== 0)
19512 lh
->maximum_ops_per_instruction
= 1;
19513 complaint (_("invalid maximum_ops_per_instruction "
19514 "in `.debug_line' section"));
19517 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19519 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19521 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19523 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19525 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19527 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19528 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19530 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19534 if (lh
->version
>= 5)
19536 /* Read directory table. */
19537 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19539 [] (struct line_header
*header
, const char *name
,
19540 dir_index d_index
, unsigned int mod_time
,
19541 unsigned int length
)
19543 header
->add_include_dir (name
);
19546 /* Read file name table. */
19547 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19549 [] (struct line_header
*header
, const char *name
,
19550 dir_index d_index
, unsigned int mod_time
,
19551 unsigned int length
)
19553 header
->add_file_name (name
, d_index
, mod_time
, length
);
19558 /* Read directory table. */
19559 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19561 line_ptr
+= bytes_read
;
19562 lh
->add_include_dir (cur_dir
);
19564 line_ptr
+= bytes_read
;
19566 /* Read file name table. */
19567 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19569 unsigned int mod_time
, length
;
19572 line_ptr
+= bytes_read
;
19573 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19574 line_ptr
+= bytes_read
;
19575 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19576 line_ptr
+= bytes_read
;
19577 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19578 line_ptr
+= bytes_read
;
19580 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19582 line_ptr
+= bytes_read
;
19585 if (line_ptr
> (section
->buffer
+ section
->size
))
19586 complaint (_("line number info header doesn't "
19587 "fit in `.debug_line' section"));
19592 /* Subroutine of dwarf_decode_lines to simplify it.
19593 Return the file name of the psymtab for the given file_entry.
19594 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19595 If space for the result is malloc'd, *NAME_HOLDER will be set.
19596 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19598 static const char *
19599 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19600 const dwarf2_psymtab
*pst
,
19601 const char *comp_dir
,
19602 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19604 const char *include_name
= fe
.name
;
19605 const char *include_name_to_compare
= include_name
;
19606 const char *pst_filename
;
19609 const char *dir_name
= fe
.include_dir (lh
);
19611 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19612 if (!IS_ABSOLUTE_PATH (include_name
)
19613 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19615 /* Avoid creating a duplicate psymtab for PST.
19616 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19617 Before we do the comparison, however, we need to account
19618 for DIR_NAME and COMP_DIR.
19619 First prepend dir_name (if non-NULL). If we still don't
19620 have an absolute path prepend comp_dir (if non-NULL).
19621 However, the directory we record in the include-file's
19622 psymtab does not contain COMP_DIR (to match the
19623 corresponding symtab(s)).
19628 bash$ gcc -g ./hello.c
19629 include_name = "hello.c"
19631 DW_AT_comp_dir = comp_dir = "/tmp"
19632 DW_AT_name = "./hello.c"
19636 if (dir_name
!= NULL
)
19638 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19639 include_name
, (char *) NULL
));
19640 include_name
= name_holder
->get ();
19641 include_name_to_compare
= include_name
;
19643 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19645 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19646 include_name
, (char *) NULL
));
19647 include_name_to_compare
= hold_compare
.get ();
19651 pst_filename
= pst
->filename
;
19652 gdb::unique_xmalloc_ptr
<char> copied_name
;
19653 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19655 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19656 pst_filename
, (char *) NULL
));
19657 pst_filename
= copied_name
.get ();
19660 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19664 return include_name
;
19667 /* State machine to track the state of the line number program. */
19669 class lnp_state_machine
19672 /* Initialize a machine state for the start of a line number
19674 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19675 bool record_lines_p
);
19677 file_entry
*current_file ()
19679 /* lh->file_names is 0-based, but the file name numbers in the
19680 statement program are 1-based. */
19681 return m_line_header
->file_name_at (m_file
);
19684 /* Record the line in the state machine. END_SEQUENCE is true if
19685 we're processing the end of a sequence. */
19686 void record_line (bool end_sequence
);
19688 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19689 nop-out rest of the lines in this sequence. */
19690 void check_line_address (struct dwarf2_cu
*cu
,
19691 const gdb_byte
*line_ptr
,
19692 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19694 void handle_set_discriminator (unsigned int discriminator
)
19696 m_discriminator
= discriminator
;
19697 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19700 /* Handle DW_LNE_set_address. */
19701 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19704 address
+= baseaddr
;
19705 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19708 /* Handle DW_LNS_advance_pc. */
19709 void handle_advance_pc (CORE_ADDR adjust
);
19711 /* Handle a special opcode. */
19712 void handle_special_opcode (unsigned char op_code
);
19714 /* Handle DW_LNS_advance_line. */
19715 void handle_advance_line (int line_delta
)
19717 advance_line (line_delta
);
19720 /* Handle DW_LNS_set_file. */
19721 void handle_set_file (file_name_index file
);
19723 /* Handle DW_LNS_negate_stmt. */
19724 void handle_negate_stmt ()
19726 m_is_stmt
= !m_is_stmt
;
19729 /* Handle DW_LNS_const_add_pc. */
19730 void handle_const_add_pc ();
19732 /* Handle DW_LNS_fixed_advance_pc. */
19733 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19735 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19739 /* Handle DW_LNS_copy. */
19740 void handle_copy ()
19742 record_line (false);
19743 m_discriminator
= 0;
19746 /* Handle DW_LNE_end_sequence. */
19747 void handle_end_sequence ()
19749 m_currently_recording_lines
= true;
19753 /* Advance the line by LINE_DELTA. */
19754 void advance_line (int line_delta
)
19756 m_line
+= line_delta
;
19758 if (line_delta
!= 0)
19759 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19762 struct dwarf2_cu
*m_cu
;
19764 gdbarch
*m_gdbarch
;
19766 /* True if we're recording lines.
19767 Otherwise we're building partial symtabs and are just interested in
19768 finding include files mentioned by the line number program. */
19769 bool m_record_lines_p
;
19771 /* The line number header. */
19772 line_header
*m_line_header
;
19774 /* These are part of the standard DWARF line number state machine,
19775 and initialized according to the DWARF spec. */
19777 unsigned char m_op_index
= 0;
19778 /* The line table index of the current file. */
19779 file_name_index m_file
= 1;
19780 unsigned int m_line
= 1;
19782 /* These are initialized in the constructor. */
19784 CORE_ADDR m_address
;
19786 unsigned int m_discriminator
;
19788 /* Additional bits of state we need to track. */
19790 /* The last file that we called dwarf2_start_subfile for.
19791 This is only used for TLLs. */
19792 unsigned int m_last_file
= 0;
19793 /* The last file a line number was recorded for. */
19794 struct subfile
*m_last_subfile
= NULL
;
19796 /* When true, record the lines we decode. */
19797 bool m_currently_recording_lines
= false;
19799 /* The last line number that was recorded, used to coalesce
19800 consecutive entries for the same line. This can happen, for
19801 example, when discriminators are present. PR 17276. */
19802 unsigned int m_last_line
= 0;
19803 bool m_line_has_non_zero_discriminator
= false;
19807 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19809 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19810 / m_line_header
->maximum_ops_per_instruction
)
19811 * m_line_header
->minimum_instruction_length
);
19812 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19813 m_op_index
= ((m_op_index
+ adjust
)
19814 % m_line_header
->maximum_ops_per_instruction
);
19818 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19820 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19821 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19822 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19823 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19824 / m_line_header
->maximum_ops_per_instruction
)
19825 * m_line_header
->minimum_instruction_length
);
19826 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19827 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19828 % m_line_header
->maximum_ops_per_instruction
);
19830 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19831 advance_line (line_delta
);
19832 record_line (false);
19833 m_discriminator
= 0;
19837 lnp_state_machine::handle_set_file (file_name_index file
)
19841 const file_entry
*fe
= current_file ();
19843 dwarf2_debug_line_missing_file_complaint ();
19844 else if (m_record_lines_p
)
19846 const char *dir
= fe
->include_dir (m_line_header
);
19848 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19849 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19850 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19855 lnp_state_machine::handle_const_add_pc ()
19858 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19861 = (((m_op_index
+ adjust
)
19862 / m_line_header
->maximum_ops_per_instruction
)
19863 * m_line_header
->minimum_instruction_length
);
19865 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19866 m_op_index
= ((m_op_index
+ adjust
)
19867 % m_line_header
->maximum_ops_per_instruction
);
19870 /* Return non-zero if we should add LINE to the line number table.
19871 LINE is the line to add, LAST_LINE is the last line that was added,
19872 LAST_SUBFILE is the subfile for LAST_LINE.
19873 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19874 had a non-zero discriminator.
19876 We have to be careful in the presence of discriminators.
19877 E.g., for this line:
19879 for (i = 0; i < 100000; i++);
19881 clang can emit four line number entries for that one line,
19882 each with a different discriminator.
19883 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19885 However, we want gdb to coalesce all four entries into one.
19886 Otherwise the user could stepi into the middle of the line and
19887 gdb would get confused about whether the pc really was in the
19888 middle of the line.
19890 Things are further complicated by the fact that two consecutive
19891 line number entries for the same line is a heuristic used by gcc
19892 to denote the end of the prologue. So we can't just discard duplicate
19893 entries, we have to be selective about it. The heuristic we use is
19894 that we only collapse consecutive entries for the same line if at least
19895 one of those entries has a non-zero discriminator. PR 17276.
19897 Note: Addresses in the line number state machine can never go backwards
19898 within one sequence, thus this coalescing is ok. */
19901 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19902 unsigned int line
, unsigned int last_line
,
19903 int line_has_non_zero_discriminator
,
19904 struct subfile
*last_subfile
)
19906 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19908 if (line
!= last_line
)
19910 /* Same line for the same file that we've seen already.
19911 As a last check, for pr 17276, only record the line if the line
19912 has never had a non-zero discriminator. */
19913 if (!line_has_non_zero_discriminator
)
19918 /* Use the CU's builder to record line number LINE beginning at
19919 address ADDRESS in the line table of subfile SUBFILE. */
19922 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19923 unsigned int line
, CORE_ADDR address
,
19924 struct dwarf2_cu
*cu
)
19926 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19928 if (dwarf_line_debug
)
19930 fprintf_unfiltered (gdb_stdlog
,
19931 "Recording line %u, file %s, address %s\n",
19932 line
, lbasename (subfile
->name
),
19933 paddress (gdbarch
, address
));
19937 cu
->get_builder ()->record_line (subfile
, line
, addr
);
19940 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19941 Mark the end of a set of line number records.
19942 The arguments are the same as for dwarf_record_line_1.
19943 If SUBFILE is NULL the request is ignored. */
19946 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19947 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19949 if (subfile
== NULL
)
19952 if (dwarf_line_debug
)
19954 fprintf_unfiltered (gdb_stdlog
,
19955 "Finishing current line, file %s, address %s\n",
19956 lbasename (subfile
->name
),
19957 paddress (gdbarch
, address
));
19960 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
19964 lnp_state_machine::record_line (bool end_sequence
)
19966 if (dwarf_line_debug
)
19968 fprintf_unfiltered (gdb_stdlog
,
19969 "Processing actual line %u: file %u,"
19970 " address %s, is_stmt %u, discrim %u%s\n",
19972 paddress (m_gdbarch
, m_address
),
19973 m_is_stmt
, m_discriminator
,
19974 (end_sequence
? "\t(end sequence)" : ""));
19977 file_entry
*fe
= current_file ();
19980 dwarf2_debug_line_missing_file_complaint ();
19981 /* For now we ignore lines not starting on an instruction boundary.
19982 But not when processing end_sequence for compatibility with the
19983 previous version of the code. */
19984 else if (m_op_index
== 0 || end_sequence
)
19986 fe
->included_p
= 1;
19987 if (m_record_lines_p
19988 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
19990 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19993 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19994 m_currently_recording_lines
? m_cu
: nullptr);
19999 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20000 m_line_has_non_zero_discriminator
,
20003 buildsym_compunit
*builder
= m_cu
->get_builder ();
20004 dwarf_record_line_1 (m_gdbarch
,
20005 builder
->get_current_subfile (),
20007 m_currently_recording_lines
? m_cu
: nullptr);
20009 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20010 m_last_line
= m_line
;
20016 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20017 line_header
*lh
, bool record_lines_p
)
20021 m_record_lines_p
= record_lines_p
;
20022 m_line_header
= lh
;
20024 m_currently_recording_lines
= true;
20026 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20027 was a line entry for it so that the backend has a chance to adjust it
20028 and also record it in case it needs it. This is currently used by MIPS
20029 code, cf. `mips_adjust_dwarf2_line'. */
20030 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20031 m_is_stmt
= lh
->default_is_stmt
;
20032 m_discriminator
= 0;
20036 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20037 const gdb_byte
*line_ptr
,
20038 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20040 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20041 the pc range of the CU. However, we restrict the test to only ADDRESS
20042 values of zero to preserve GDB's previous behaviour which is to handle
20043 the specific case of a function being GC'd by the linker. */
20045 if (address
== 0 && address
< unrelocated_lowpc
)
20047 /* This line table is for a function which has been
20048 GCd by the linker. Ignore it. PR gdb/12528 */
20050 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20051 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20053 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20054 line_offset
, objfile_name (objfile
));
20055 m_currently_recording_lines
= false;
20056 /* Note: m_currently_recording_lines is left as false until we see
20057 DW_LNE_end_sequence. */
20061 /* Subroutine of dwarf_decode_lines to simplify it.
20062 Process the line number information in LH.
20063 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20064 program in order to set included_p for every referenced header. */
20067 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20068 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20070 const gdb_byte
*line_ptr
, *extended_end
;
20071 const gdb_byte
*line_end
;
20072 unsigned int bytes_read
, extended_len
;
20073 unsigned char op_code
, extended_op
;
20074 CORE_ADDR baseaddr
;
20075 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20076 bfd
*abfd
= objfile
->obfd
;
20077 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20078 /* True if we're recording line info (as opposed to building partial
20079 symtabs and just interested in finding include files mentioned by
20080 the line number program). */
20081 bool record_lines_p
= !decode_for_pst_p
;
20083 baseaddr
= objfile
->text_section_offset ();
20085 line_ptr
= lh
->statement_program_start
;
20086 line_end
= lh
->statement_program_end
;
20088 /* Read the statement sequences until there's nothing left. */
20089 while (line_ptr
< line_end
)
20091 /* The DWARF line number program state machine. Reset the state
20092 machine at the start of each sequence. */
20093 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20094 bool end_sequence
= false;
20096 if (record_lines_p
)
20098 /* Start a subfile for the current file of the state
20100 const file_entry
*fe
= state_machine
.current_file ();
20103 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20106 /* Decode the table. */
20107 while (line_ptr
< line_end
&& !end_sequence
)
20109 op_code
= read_1_byte (abfd
, line_ptr
);
20112 if (op_code
>= lh
->opcode_base
)
20114 /* Special opcode. */
20115 state_machine
.handle_special_opcode (op_code
);
20117 else switch (op_code
)
20119 case DW_LNS_extended_op
:
20120 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20122 line_ptr
+= bytes_read
;
20123 extended_end
= line_ptr
+ extended_len
;
20124 extended_op
= read_1_byte (abfd
, line_ptr
);
20126 switch (extended_op
)
20128 case DW_LNE_end_sequence
:
20129 state_machine
.handle_end_sequence ();
20130 end_sequence
= true;
20132 case DW_LNE_set_address
:
20135 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20136 line_ptr
+= bytes_read
;
20138 state_machine
.check_line_address (cu
, line_ptr
,
20139 lowpc
- baseaddr
, address
);
20140 state_machine
.handle_set_address (baseaddr
, address
);
20143 case DW_LNE_define_file
:
20145 const char *cur_file
;
20146 unsigned int mod_time
, length
;
20149 cur_file
= read_direct_string (abfd
, line_ptr
,
20151 line_ptr
+= bytes_read
;
20152 dindex
= (dir_index
)
20153 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20154 line_ptr
+= bytes_read
;
20156 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20157 line_ptr
+= bytes_read
;
20159 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20160 line_ptr
+= bytes_read
;
20161 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20164 case DW_LNE_set_discriminator
:
20166 /* The discriminator is not interesting to the
20167 debugger; just ignore it. We still need to
20168 check its value though:
20169 if there are consecutive entries for the same
20170 (non-prologue) line we want to coalesce them.
20173 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20174 line_ptr
+= bytes_read
;
20176 state_machine
.handle_set_discriminator (discr
);
20180 complaint (_("mangled .debug_line section"));
20183 /* Make sure that we parsed the extended op correctly. If e.g.
20184 we expected a different address size than the producer used,
20185 we may have read the wrong number of bytes. */
20186 if (line_ptr
!= extended_end
)
20188 complaint (_("mangled .debug_line section"));
20193 state_machine
.handle_copy ();
20195 case DW_LNS_advance_pc
:
20198 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20199 line_ptr
+= bytes_read
;
20201 state_machine
.handle_advance_pc (adjust
);
20204 case DW_LNS_advance_line
:
20207 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20208 line_ptr
+= bytes_read
;
20210 state_machine
.handle_advance_line (line_delta
);
20213 case DW_LNS_set_file
:
20215 file_name_index file
20216 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20218 line_ptr
+= bytes_read
;
20220 state_machine
.handle_set_file (file
);
20223 case DW_LNS_set_column
:
20224 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20225 line_ptr
+= bytes_read
;
20227 case DW_LNS_negate_stmt
:
20228 state_machine
.handle_negate_stmt ();
20230 case DW_LNS_set_basic_block
:
20232 /* Add to the address register of the state machine the
20233 address increment value corresponding to special opcode
20234 255. I.e., this value is scaled by the minimum
20235 instruction length since special opcode 255 would have
20236 scaled the increment. */
20237 case DW_LNS_const_add_pc
:
20238 state_machine
.handle_const_add_pc ();
20240 case DW_LNS_fixed_advance_pc
:
20242 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20245 state_machine
.handle_fixed_advance_pc (addr_adj
);
20250 /* Unknown standard opcode, ignore it. */
20253 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20255 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20256 line_ptr
+= bytes_read
;
20263 dwarf2_debug_line_missing_end_sequence_complaint ();
20265 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20266 in which case we still finish recording the last line). */
20267 state_machine
.record_line (true);
20271 /* Decode the Line Number Program (LNP) for the given line_header
20272 structure and CU. The actual information extracted and the type
20273 of structures created from the LNP depends on the value of PST.
20275 1. If PST is NULL, then this procedure uses the data from the program
20276 to create all necessary symbol tables, and their linetables.
20278 2. If PST is not NULL, this procedure reads the program to determine
20279 the list of files included by the unit represented by PST, and
20280 builds all the associated partial symbol tables.
20282 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20283 It is used for relative paths in the line table.
20284 NOTE: When processing partial symtabs (pst != NULL),
20285 comp_dir == pst->dirname.
20287 NOTE: It is important that psymtabs have the same file name (via strcmp)
20288 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20289 symtab we don't use it in the name of the psymtabs we create.
20290 E.g. expand_line_sal requires this when finding psymtabs to expand.
20291 A good testcase for this is mb-inline.exp.
20293 LOWPC is the lowest address in CU (or 0 if not known).
20295 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20296 for its PC<->lines mapping information. Otherwise only the filename
20297 table is read in. */
20300 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20301 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20302 CORE_ADDR lowpc
, int decode_mapping
)
20304 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20305 const int decode_for_pst_p
= (pst
!= NULL
);
20307 if (decode_mapping
)
20308 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20310 if (decode_for_pst_p
)
20312 /* Now that we're done scanning the Line Header Program, we can
20313 create the psymtab of each included file. */
20314 for (auto &file_entry
: lh
->file_names ())
20315 if (file_entry
.included_p
== 1)
20317 gdb::unique_xmalloc_ptr
<char> name_holder
;
20318 const char *include_name
=
20319 psymtab_include_file_name (lh
, file_entry
, pst
,
20320 comp_dir
, &name_holder
);
20321 if (include_name
!= NULL
)
20322 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20327 /* Make sure a symtab is created for every file, even files
20328 which contain only variables (i.e. no code with associated
20330 buildsym_compunit
*builder
= cu
->get_builder ();
20331 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20333 for (auto &fe
: lh
->file_names ())
20335 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20336 if (builder
->get_current_subfile ()->symtab
== NULL
)
20338 builder
->get_current_subfile ()->symtab
20339 = allocate_symtab (cust
,
20340 builder
->get_current_subfile ()->name
);
20342 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20347 /* Start a subfile for DWARF. FILENAME is the name of the file and
20348 DIRNAME the name of the source directory which contains FILENAME
20349 or NULL if not known.
20350 This routine tries to keep line numbers from identical absolute and
20351 relative file names in a common subfile.
20353 Using the `list' example from the GDB testsuite, which resides in
20354 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20355 of /srcdir/list0.c yields the following debugging information for list0.c:
20357 DW_AT_name: /srcdir/list0.c
20358 DW_AT_comp_dir: /compdir
20359 files.files[0].name: list0.h
20360 files.files[0].dir: /srcdir
20361 files.files[1].name: list0.c
20362 files.files[1].dir: /srcdir
20364 The line number information for list0.c has to end up in a single
20365 subfile, so that `break /srcdir/list0.c:1' works as expected.
20366 start_subfile will ensure that this happens provided that we pass the
20367 concatenation of files.files[1].dir and files.files[1].name as the
20371 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20372 const char *dirname
)
20374 gdb::unique_xmalloc_ptr
<char> copy
;
20376 /* In order not to lose the line information directory,
20377 we concatenate it to the filename when it makes sense.
20378 Note that the Dwarf3 standard says (speaking of filenames in line
20379 information): ``The directory index is ignored for file names
20380 that represent full path names''. Thus ignoring dirname in the
20381 `else' branch below isn't an issue. */
20383 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20385 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20386 filename
= copy
.get ();
20389 cu
->get_builder ()->start_subfile (filename
);
20392 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20393 buildsym_compunit constructor. */
20395 struct compunit_symtab
*
20396 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20399 gdb_assert (m_builder
== nullptr);
20401 m_builder
.reset (new struct buildsym_compunit
20402 (per_cu
->dwarf2_per_objfile
->objfile
,
20403 name
, comp_dir
, language
, low_pc
));
20405 list_in_scope
= get_builder ()->get_file_symbols ();
20407 get_builder ()->record_debugformat ("DWARF 2");
20408 get_builder ()->record_producer (producer
);
20410 processing_has_namespace_info
= false;
20412 return get_builder ()->get_compunit_symtab ();
20416 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20417 struct dwarf2_cu
*cu
)
20419 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20420 struct comp_unit_head
*cu_header
= &cu
->header
;
20422 /* NOTE drow/2003-01-30: There used to be a comment and some special
20423 code here to turn a symbol with DW_AT_external and a
20424 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20425 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20426 with some versions of binutils) where shared libraries could have
20427 relocations against symbols in their debug information - the
20428 minimal symbol would have the right address, but the debug info
20429 would not. It's no longer necessary, because we will explicitly
20430 apply relocations when we read in the debug information now. */
20432 /* A DW_AT_location attribute with no contents indicates that a
20433 variable has been optimized away. */
20434 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20436 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20440 /* Handle one degenerate form of location expression specially, to
20441 preserve GDB's previous behavior when section offsets are
20442 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20443 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20445 if (attr
->form_is_block ()
20446 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20447 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20448 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20449 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20450 && (DW_BLOCK (attr
)->size
20451 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20453 unsigned int dummy
;
20455 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20456 SET_SYMBOL_VALUE_ADDRESS
20457 (sym
, cu
->header
.read_address (objfile
->obfd
,
20458 DW_BLOCK (attr
)->data
+ 1,
20461 SET_SYMBOL_VALUE_ADDRESS
20462 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20464 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20465 fixup_symbol_section (sym
, objfile
);
20466 SET_SYMBOL_VALUE_ADDRESS
20468 SYMBOL_VALUE_ADDRESS (sym
)
20469 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20473 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20474 expression evaluator, and use LOC_COMPUTED only when necessary
20475 (i.e. when the value of a register or memory location is
20476 referenced, or a thread-local block, etc.). Then again, it might
20477 not be worthwhile. I'm assuming that it isn't unless performance
20478 or memory numbers show me otherwise. */
20480 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20482 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20483 cu
->has_loclist
= true;
20486 /* Given a pointer to a DWARF information entry, figure out if we need
20487 to make a symbol table entry for it, and if so, create a new entry
20488 and return a pointer to it.
20489 If TYPE is NULL, determine symbol type from the die, otherwise
20490 used the passed type.
20491 If SPACE is not NULL, use it to hold the new symbol. If it is
20492 NULL, allocate a new symbol on the objfile's obstack. */
20494 static struct symbol
*
20495 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20496 struct symbol
*space
)
20498 struct dwarf2_per_objfile
*dwarf2_per_objfile
20499 = cu
->per_cu
->dwarf2_per_objfile
;
20500 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20501 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20502 struct symbol
*sym
= NULL
;
20504 struct attribute
*attr
= NULL
;
20505 struct attribute
*attr2
= NULL
;
20506 CORE_ADDR baseaddr
;
20507 struct pending
**list_to_add
= NULL
;
20509 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20511 baseaddr
= objfile
->text_section_offset ();
20513 name
= dwarf2_name (die
, cu
);
20516 const char *linkagename
;
20517 int suppress_add
= 0;
20522 sym
= allocate_symbol (objfile
);
20523 OBJSTAT (objfile
, n_syms
++);
20525 /* Cache this symbol's name and the name's demangled form (if any). */
20526 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20527 linkagename
= dwarf2_physname (name
, die
, cu
);
20528 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20530 /* Fortran does not have mangling standard and the mangling does differ
20531 between gfortran, iFort etc. */
20532 if (cu
->language
== language_fortran
20533 && symbol_get_demangled_name (sym
) == NULL
)
20534 symbol_set_demangled_name (sym
,
20535 dwarf2_full_name (name
, die
, cu
),
20538 /* Default assumptions.
20539 Use the passed type or decode it from the die. */
20540 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20541 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20543 SYMBOL_TYPE (sym
) = type
;
20545 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20546 attr
= dwarf2_attr (die
,
20547 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20549 if (attr
!= nullptr)
20551 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20554 attr
= dwarf2_attr (die
,
20555 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20557 if (attr
!= nullptr)
20559 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20560 struct file_entry
*fe
;
20562 if (cu
->line_header
!= NULL
)
20563 fe
= cu
->line_header
->file_name_at (file_index
);
20568 complaint (_("file index out of range"));
20570 symbol_set_symtab (sym
, fe
->symtab
);
20576 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20577 if (attr
!= nullptr)
20581 addr
= attr
->value_as_address ();
20582 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20583 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20585 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20586 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20587 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20588 add_symbol_to_list (sym
, cu
->list_in_scope
);
20590 case DW_TAG_subprogram
:
20591 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20593 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20594 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20595 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20596 || cu
->language
== language_ada
20597 || cu
->language
== language_fortran
)
20599 /* Subprograms marked external are stored as a global symbol.
20600 Ada and Fortran subprograms, whether marked external or
20601 not, are always stored as a global symbol, because we want
20602 to be able to access them globally. For instance, we want
20603 to be able to break on a nested subprogram without having
20604 to specify the context. */
20605 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20609 list_to_add
= cu
->list_in_scope
;
20612 case DW_TAG_inlined_subroutine
:
20613 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20615 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20616 SYMBOL_INLINED (sym
) = 1;
20617 list_to_add
= cu
->list_in_scope
;
20619 case DW_TAG_template_value_param
:
20621 /* Fall through. */
20622 case DW_TAG_constant
:
20623 case DW_TAG_variable
:
20624 case DW_TAG_member
:
20625 /* Compilation with minimal debug info may result in
20626 variables with missing type entries. Change the
20627 misleading `void' type to something sensible. */
20628 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20629 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20631 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20632 /* In the case of DW_TAG_member, we should only be called for
20633 static const members. */
20634 if (die
->tag
== DW_TAG_member
)
20636 /* dwarf2_add_field uses die_is_declaration,
20637 so we do the same. */
20638 gdb_assert (die_is_declaration (die
, cu
));
20641 if (attr
!= nullptr)
20643 dwarf2_const_value (attr
, sym
, cu
);
20644 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20647 if (attr2
&& (DW_UNSND (attr2
) != 0))
20648 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20650 list_to_add
= cu
->list_in_scope
;
20654 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20655 if (attr
!= nullptr)
20657 var_decode_location (attr
, sym
, cu
);
20658 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20660 /* Fortran explicitly imports any global symbols to the local
20661 scope by DW_TAG_common_block. */
20662 if (cu
->language
== language_fortran
&& die
->parent
20663 && die
->parent
->tag
== DW_TAG_common_block
)
20666 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20667 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20668 && !dwarf2_per_objfile
->has_section_at_zero
)
20670 /* When a static variable is eliminated by the linker,
20671 the corresponding debug information is not stripped
20672 out, but the variable address is set to null;
20673 do not add such variables into symbol table. */
20675 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20677 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20678 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20679 && dwarf2_per_objfile
->can_copy
)
20681 /* A global static variable might be subject to
20682 copy relocation. We first check for a local
20683 minsym, though, because maybe the symbol was
20684 marked hidden, in which case this would not
20686 bound_minimal_symbol found
20687 = (lookup_minimal_symbol_linkage
20688 (sym
->linkage_name (), objfile
));
20689 if (found
.minsym
!= nullptr)
20690 sym
->maybe_copied
= 1;
20693 /* A variable with DW_AT_external is never static,
20694 but it may be block-scoped. */
20696 = ((cu
->list_in_scope
20697 == cu
->get_builder ()->get_file_symbols ())
20698 ? cu
->get_builder ()->get_global_symbols ()
20699 : cu
->list_in_scope
);
20702 list_to_add
= cu
->list_in_scope
;
20706 /* We do not know the address of this symbol.
20707 If it is an external symbol and we have type information
20708 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20709 The address of the variable will then be determined from
20710 the minimal symbol table whenever the variable is
20712 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20714 /* Fortran explicitly imports any global symbols to the local
20715 scope by DW_TAG_common_block. */
20716 if (cu
->language
== language_fortran
&& die
->parent
20717 && die
->parent
->tag
== DW_TAG_common_block
)
20719 /* SYMBOL_CLASS doesn't matter here because
20720 read_common_block is going to reset it. */
20722 list_to_add
= cu
->list_in_scope
;
20724 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20725 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20727 /* A variable with DW_AT_external is never static, but it
20728 may be block-scoped. */
20730 = ((cu
->list_in_scope
20731 == cu
->get_builder ()->get_file_symbols ())
20732 ? cu
->get_builder ()->get_global_symbols ()
20733 : cu
->list_in_scope
);
20735 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20737 else if (!die_is_declaration (die
, cu
))
20739 /* Use the default LOC_OPTIMIZED_OUT class. */
20740 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20742 list_to_add
= cu
->list_in_scope
;
20746 case DW_TAG_formal_parameter
:
20748 /* If we are inside a function, mark this as an argument. If
20749 not, we might be looking at an argument to an inlined function
20750 when we do not have enough information to show inlined frames;
20751 pretend it's a local variable in that case so that the user can
20753 struct context_stack
*curr
20754 = cu
->get_builder ()->get_current_context_stack ();
20755 if (curr
!= nullptr && curr
->name
!= nullptr)
20756 SYMBOL_IS_ARGUMENT (sym
) = 1;
20757 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20758 if (attr
!= nullptr)
20760 var_decode_location (attr
, sym
, cu
);
20762 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20763 if (attr
!= nullptr)
20765 dwarf2_const_value (attr
, sym
, cu
);
20768 list_to_add
= cu
->list_in_scope
;
20771 case DW_TAG_unspecified_parameters
:
20772 /* From varargs functions; gdb doesn't seem to have any
20773 interest in this information, so just ignore it for now.
20776 case DW_TAG_template_type_param
:
20778 /* Fall through. */
20779 case DW_TAG_class_type
:
20780 case DW_TAG_interface_type
:
20781 case DW_TAG_structure_type
:
20782 case DW_TAG_union_type
:
20783 case DW_TAG_set_type
:
20784 case DW_TAG_enumeration_type
:
20785 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20786 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20789 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20790 really ever be static objects: otherwise, if you try
20791 to, say, break of a class's method and you're in a file
20792 which doesn't mention that class, it won't work unless
20793 the check for all static symbols in lookup_symbol_aux
20794 saves you. See the OtherFileClass tests in
20795 gdb.c++/namespace.exp. */
20799 buildsym_compunit
*builder
= cu
->get_builder ();
20801 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20802 && cu
->language
== language_cplus
20803 ? builder
->get_global_symbols ()
20804 : cu
->list_in_scope
);
20806 /* The semantics of C++ state that "struct foo {
20807 ... }" also defines a typedef for "foo". */
20808 if (cu
->language
== language_cplus
20809 || cu
->language
== language_ada
20810 || cu
->language
== language_d
20811 || cu
->language
== language_rust
)
20813 /* The symbol's name is already allocated along
20814 with this objfile, so we don't need to
20815 duplicate it for the type. */
20816 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20817 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20822 case DW_TAG_typedef
:
20823 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20824 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20825 list_to_add
= cu
->list_in_scope
;
20827 case DW_TAG_base_type
:
20828 case DW_TAG_subrange_type
:
20829 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20830 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20831 list_to_add
= cu
->list_in_scope
;
20833 case DW_TAG_enumerator
:
20834 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20835 if (attr
!= nullptr)
20837 dwarf2_const_value (attr
, sym
, cu
);
20840 /* NOTE: carlton/2003-11-10: See comment above in the
20841 DW_TAG_class_type, etc. block. */
20844 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20845 && cu
->language
== language_cplus
20846 ? cu
->get_builder ()->get_global_symbols ()
20847 : cu
->list_in_scope
);
20850 case DW_TAG_imported_declaration
:
20851 case DW_TAG_namespace
:
20852 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20853 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20855 case DW_TAG_module
:
20856 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20857 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20858 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20860 case DW_TAG_common_block
:
20861 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20862 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20863 add_symbol_to_list (sym
, cu
->list_in_scope
);
20866 /* Not a tag we recognize. Hopefully we aren't processing
20867 trash data, but since we must specifically ignore things
20868 we don't recognize, there is nothing else we should do at
20870 complaint (_("unsupported tag: '%s'"),
20871 dwarf_tag_name (die
->tag
));
20877 sym
->hash_next
= objfile
->template_symbols
;
20878 objfile
->template_symbols
= sym
;
20879 list_to_add
= NULL
;
20882 if (list_to_add
!= NULL
)
20883 add_symbol_to_list (sym
, list_to_add
);
20885 /* For the benefit of old versions of GCC, check for anonymous
20886 namespaces based on the demangled name. */
20887 if (!cu
->processing_has_namespace_info
20888 && cu
->language
== language_cplus
)
20889 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20894 /* Given an attr with a DW_FORM_dataN value in host byte order,
20895 zero-extend it as appropriate for the symbol's type. The DWARF
20896 standard (v4) is not entirely clear about the meaning of using
20897 DW_FORM_dataN for a constant with a signed type, where the type is
20898 wider than the data. The conclusion of a discussion on the DWARF
20899 list was that this is unspecified. We choose to always zero-extend
20900 because that is the interpretation long in use by GCC. */
20903 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20904 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20906 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20907 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20908 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20909 LONGEST l
= DW_UNSND (attr
);
20911 if (bits
< sizeof (*value
) * 8)
20913 l
&= ((LONGEST
) 1 << bits
) - 1;
20916 else if (bits
== sizeof (*value
) * 8)
20920 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20921 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20928 /* Read a constant value from an attribute. Either set *VALUE, or if
20929 the value does not fit in *VALUE, set *BYTES - either already
20930 allocated on the objfile obstack, or newly allocated on OBSTACK,
20931 or, set *BATON, if we translated the constant to a location
20935 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20936 const char *name
, struct obstack
*obstack
,
20937 struct dwarf2_cu
*cu
,
20938 LONGEST
*value
, const gdb_byte
**bytes
,
20939 struct dwarf2_locexpr_baton
**baton
)
20941 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20942 struct comp_unit_head
*cu_header
= &cu
->header
;
20943 struct dwarf_block
*blk
;
20944 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20945 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20951 switch (attr
->form
)
20954 case DW_FORM_addrx
:
20955 case DW_FORM_GNU_addr_index
:
20959 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20960 dwarf2_const_value_length_mismatch_complaint (name
,
20961 cu_header
->addr_size
,
20962 TYPE_LENGTH (type
));
20963 /* Symbols of this form are reasonably rare, so we just
20964 piggyback on the existing location code rather than writing
20965 a new implementation of symbol_computed_ops. */
20966 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20967 (*baton
)->per_cu
= cu
->per_cu
;
20968 gdb_assert ((*baton
)->per_cu
);
20970 (*baton
)->size
= 2 + cu_header
->addr_size
;
20971 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20972 (*baton
)->data
= data
;
20974 data
[0] = DW_OP_addr
;
20975 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20976 byte_order
, DW_ADDR (attr
));
20977 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20980 case DW_FORM_string
:
20983 case DW_FORM_GNU_str_index
:
20984 case DW_FORM_GNU_strp_alt
:
20985 /* DW_STRING is already allocated on the objfile obstack, point
20987 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20989 case DW_FORM_block1
:
20990 case DW_FORM_block2
:
20991 case DW_FORM_block4
:
20992 case DW_FORM_block
:
20993 case DW_FORM_exprloc
:
20994 case DW_FORM_data16
:
20995 blk
= DW_BLOCK (attr
);
20996 if (TYPE_LENGTH (type
) != blk
->size
)
20997 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20998 TYPE_LENGTH (type
));
20999 *bytes
= blk
->data
;
21002 /* The DW_AT_const_value attributes are supposed to carry the
21003 symbol's value "represented as it would be on the target
21004 architecture." By the time we get here, it's already been
21005 converted to host endianness, so we just need to sign- or
21006 zero-extend it as appropriate. */
21007 case DW_FORM_data1
:
21008 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21010 case DW_FORM_data2
:
21011 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21013 case DW_FORM_data4
:
21014 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21016 case DW_FORM_data8
:
21017 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21020 case DW_FORM_sdata
:
21021 case DW_FORM_implicit_const
:
21022 *value
= DW_SND (attr
);
21025 case DW_FORM_udata
:
21026 *value
= DW_UNSND (attr
);
21030 complaint (_("unsupported const value attribute form: '%s'"),
21031 dwarf_form_name (attr
->form
));
21038 /* Copy constant value from an attribute to a symbol. */
21041 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21042 struct dwarf2_cu
*cu
)
21044 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21046 const gdb_byte
*bytes
;
21047 struct dwarf2_locexpr_baton
*baton
;
21049 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21050 sym
->print_name (),
21051 &objfile
->objfile_obstack
, cu
,
21052 &value
, &bytes
, &baton
);
21056 SYMBOL_LOCATION_BATON (sym
) = baton
;
21057 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21059 else if (bytes
!= NULL
)
21061 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21062 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21066 SYMBOL_VALUE (sym
) = value
;
21067 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21071 /* Return the type of the die in question using its DW_AT_type attribute. */
21073 static struct type
*
21074 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21076 struct attribute
*type_attr
;
21078 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21081 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21082 /* A missing DW_AT_type represents a void type. */
21083 return objfile_type (objfile
)->builtin_void
;
21086 return lookup_die_type (die
, type_attr
, cu
);
21089 /* True iff CU's producer generates GNAT Ada auxiliary information
21090 that allows to find parallel types through that information instead
21091 of having to do expensive parallel lookups by type name. */
21094 need_gnat_info (struct dwarf2_cu
*cu
)
21096 /* Assume that the Ada compiler was GNAT, which always produces
21097 the auxiliary information. */
21098 return (cu
->language
== language_ada
);
21101 /* Return the auxiliary type of the die in question using its
21102 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21103 attribute is not present. */
21105 static struct type
*
21106 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21108 struct attribute
*type_attr
;
21110 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21114 return lookup_die_type (die
, type_attr
, cu
);
21117 /* If DIE has a descriptive_type attribute, then set the TYPE's
21118 descriptive type accordingly. */
21121 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21122 struct dwarf2_cu
*cu
)
21124 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21126 if (descriptive_type
)
21128 ALLOCATE_GNAT_AUX_TYPE (type
);
21129 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21133 /* Return the containing type of the die in question using its
21134 DW_AT_containing_type attribute. */
21136 static struct type
*
21137 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21139 struct attribute
*type_attr
;
21140 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21142 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21144 error (_("Dwarf Error: Problem turning containing type into gdb type "
21145 "[in module %s]"), objfile_name (objfile
));
21147 return lookup_die_type (die
, type_attr
, cu
);
21150 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21152 static struct type
*
21153 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21155 struct dwarf2_per_objfile
*dwarf2_per_objfile
21156 = cu
->per_cu
->dwarf2_per_objfile
;
21157 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21160 std::string message
21161 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21162 objfile_name (objfile
),
21163 sect_offset_str (cu
->header
.sect_off
),
21164 sect_offset_str (die
->sect_off
));
21165 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21167 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21170 /* Look up the type of DIE in CU using its type attribute ATTR.
21171 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21172 DW_AT_containing_type.
21173 If there is no type substitute an error marker. */
21175 static struct type
*
21176 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21177 struct dwarf2_cu
*cu
)
21179 struct dwarf2_per_objfile
*dwarf2_per_objfile
21180 = cu
->per_cu
->dwarf2_per_objfile
;
21181 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21182 struct type
*this_type
;
21184 gdb_assert (attr
->name
== DW_AT_type
21185 || attr
->name
== DW_AT_GNAT_descriptive_type
21186 || attr
->name
== DW_AT_containing_type
);
21188 /* First see if we have it cached. */
21190 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21192 struct dwarf2_per_cu_data
*per_cu
;
21193 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21195 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21196 dwarf2_per_objfile
);
21197 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21199 else if (attr
->form_is_ref ())
21201 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21203 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21205 else if (attr
->form
== DW_FORM_ref_sig8
)
21207 ULONGEST signature
= DW_SIGNATURE (attr
);
21209 return get_signatured_type (die
, signature
, cu
);
21213 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21214 " at %s [in module %s]"),
21215 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21216 objfile_name (objfile
));
21217 return build_error_marker_type (cu
, die
);
21220 /* If not cached we need to read it in. */
21222 if (this_type
== NULL
)
21224 struct die_info
*type_die
= NULL
;
21225 struct dwarf2_cu
*type_cu
= cu
;
21227 if (attr
->form_is_ref ())
21228 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21229 if (type_die
== NULL
)
21230 return build_error_marker_type (cu
, die
);
21231 /* If we find the type now, it's probably because the type came
21232 from an inter-CU reference and the type's CU got expanded before
21234 this_type
= read_type_die (type_die
, type_cu
);
21237 /* If we still don't have a type use an error marker. */
21239 if (this_type
== NULL
)
21240 return build_error_marker_type (cu
, die
);
21245 /* Return the type in DIE, CU.
21246 Returns NULL for invalid types.
21248 This first does a lookup in die_type_hash,
21249 and only reads the die in if necessary.
21251 NOTE: This can be called when reading in partial or full symbols. */
21253 static struct type
*
21254 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21256 struct type
*this_type
;
21258 this_type
= get_die_type (die
, cu
);
21262 return read_type_die_1 (die
, cu
);
21265 /* Read the type in DIE, CU.
21266 Returns NULL for invalid types. */
21268 static struct type
*
21269 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21271 struct type
*this_type
= NULL
;
21275 case DW_TAG_class_type
:
21276 case DW_TAG_interface_type
:
21277 case DW_TAG_structure_type
:
21278 case DW_TAG_union_type
:
21279 this_type
= read_structure_type (die
, cu
);
21281 case DW_TAG_enumeration_type
:
21282 this_type
= read_enumeration_type (die
, cu
);
21284 case DW_TAG_subprogram
:
21285 case DW_TAG_subroutine_type
:
21286 case DW_TAG_inlined_subroutine
:
21287 this_type
= read_subroutine_type (die
, cu
);
21289 case DW_TAG_array_type
:
21290 this_type
= read_array_type (die
, cu
);
21292 case DW_TAG_set_type
:
21293 this_type
= read_set_type (die
, cu
);
21295 case DW_TAG_pointer_type
:
21296 this_type
= read_tag_pointer_type (die
, cu
);
21298 case DW_TAG_ptr_to_member_type
:
21299 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21301 case DW_TAG_reference_type
:
21302 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21304 case DW_TAG_rvalue_reference_type
:
21305 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21307 case DW_TAG_const_type
:
21308 this_type
= read_tag_const_type (die
, cu
);
21310 case DW_TAG_volatile_type
:
21311 this_type
= read_tag_volatile_type (die
, cu
);
21313 case DW_TAG_restrict_type
:
21314 this_type
= read_tag_restrict_type (die
, cu
);
21316 case DW_TAG_string_type
:
21317 this_type
= read_tag_string_type (die
, cu
);
21319 case DW_TAG_typedef
:
21320 this_type
= read_typedef (die
, cu
);
21322 case DW_TAG_subrange_type
:
21323 this_type
= read_subrange_type (die
, cu
);
21325 case DW_TAG_base_type
:
21326 this_type
= read_base_type (die
, cu
);
21328 case DW_TAG_unspecified_type
:
21329 this_type
= read_unspecified_type (die
, cu
);
21331 case DW_TAG_namespace
:
21332 this_type
= read_namespace_type (die
, cu
);
21334 case DW_TAG_module
:
21335 this_type
= read_module_type (die
, cu
);
21337 case DW_TAG_atomic_type
:
21338 this_type
= read_tag_atomic_type (die
, cu
);
21341 complaint (_("unexpected tag in read_type_die: '%s'"),
21342 dwarf_tag_name (die
->tag
));
21349 /* See if we can figure out if the class lives in a namespace. We do
21350 this by looking for a member function; its demangled name will
21351 contain namespace info, if there is any.
21352 Return the computed name or NULL.
21353 Space for the result is allocated on the objfile's obstack.
21354 This is the full-die version of guess_partial_die_structure_name.
21355 In this case we know DIE has no useful parent. */
21357 static const char *
21358 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21360 struct die_info
*spec_die
;
21361 struct dwarf2_cu
*spec_cu
;
21362 struct die_info
*child
;
21363 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21366 spec_die
= die_specification (die
, &spec_cu
);
21367 if (spec_die
!= NULL
)
21373 for (child
= die
->child
;
21375 child
= child
->sibling
)
21377 if (child
->tag
== DW_TAG_subprogram
)
21379 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21381 if (linkage_name
!= NULL
)
21383 gdb::unique_xmalloc_ptr
<char> actual_name
21384 (language_class_name_from_physname (cu
->language_defn
,
21386 const char *name
= NULL
;
21388 if (actual_name
!= NULL
)
21390 const char *die_name
= dwarf2_name (die
, cu
);
21392 if (die_name
!= NULL
21393 && strcmp (die_name
, actual_name
.get ()) != 0)
21395 /* Strip off the class name from the full name.
21396 We want the prefix. */
21397 int die_name_len
= strlen (die_name
);
21398 int actual_name_len
= strlen (actual_name
.get ());
21399 const char *ptr
= actual_name
.get ();
21401 /* Test for '::' as a sanity check. */
21402 if (actual_name_len
> die_name_len
+ 2
21403 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21404 name
= obstack_strndup (
21405 &objfile
->per_bfd
->storage_obstack
,
21406 ptr
, actual_name_len
- die_name_len
- 2);
21417 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21418 prefix part in such case. See
21419 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21421 static const char *
21422 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21424 struct attribute
*attr
;
21427 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21428 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21431 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21434 attr
= dw2_linkage_name_attr (die
, cu
);
21435 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21438 /* dwarf2_name had to be already called. */
21439 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21441 /* Strip the base name, keep any leading namespaces/classes. */
21442 base
= strrchr (DW_STRING (attr
), ':');
21443 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21446 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21447 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21449 &base
[-1] - DW_STRING (attr
));
21452 /* Return the name of the namespace/class that DIE is defined within,
21453 or "" if we can't tell. The caller should not xfree the result.
21455 For example, if we're within the method foo() in the following
21465 then determine_prefix on foo's die will return "N::C". */
21467 static const char *
21468 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21470 struct dwarf2_per_objfile
*dwarf2_per_objfile
21471 = cu
->per_cu
->dwarf2_per_objfile
;
21472 struct die_info
*parent
, *spec_die
;
21473 struct dwarf2_cu
*spec_cu
;
21474 struct type
*parent_type
;
21475 const char *retval
;
21477 if (cu
->language
!= language_cplus
21478 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21479 && cu
->language
!= language_rust
)
21482 retval
= anonymous_struct_prefix (die
, cu
);
21486 /* We have to be careful in the presence of DW_AT_specification.
21487 For example, with GCC 3.4, given the code
21491 // Definition of N::foo.
21495 then we'll have a tree of DIEs like this:
21497 1: DW_TAG_compile_unit
21498 2: DW_TAG_namespace // N
21499 3: DW_TAG_subprogram // declaration of N::foo
21500 4: DW_TAG_subprogram // definition of N::foo
21501 DW_AT_specification // refers to die #3
21503 Thus, when processing die #4, we have to pretend that we're in
21504 the context of its DW_AT_specification, namely the contex of die
21507 spec_die
= die_specification (die
, &spec_cu
);
21508 if (spec_die
== NULL
)
21509 parent
= die
->parent
;
21512 parent
= spec_die
->parent
;
21516 if (parent
== NULL
)
21518 else if (parent
->building_fullname
)
21521 const char *parent_name
;
21523 /* It has been seen on RealView 2.2 built binaries,
21524 DW_TAG_template_type_param types actually _defined_ as
21525 children of the parent class:
21528 template class <class Enum> Class{};
21529 Class<enum E> class_e;
21531 1: DW_TAG_class_type (Class)
21532 2: DW_TAG_enumeration_type (E)
21533 3: DW_TAG_enumerator (enum1:0)
21534 3: DW_TAG_enumerator (enum2:1)
21536 2: DW_TAG_template_type_param
21537 DW_AT_type DW_FORM_ref_udata (E)
21539 Besides being broken debug info, it can put GDB into an
21540 infinite loop. Consider:
21542 When we're building the full name for Class<E>, we'll start
21543 at Class, and go look over its template type parameters,
21544 finding E. We'll then try to build the full name of E, and
21545 reach here. We're now trying to build the full name of E,
21546 and look over the parent DIE for containing scope. In the
21547 broken case, if we followed the parent DIE of E, we'd again
21548 find Class, and once again go look at its template type
21549 arguments, etc., etc. Simply don't consider such parent die
21550 as source-level parent of this die (it can't be, the language
21551 doesn't allow it), and break the loop here. */
21552 name
= dwarf2_name (die
, cu
);
21553 parent_name
= dwarf2_name (parent
, cu
);
21554 complaint (_("template param type '%s' defined within parent '%s'"),
21555 name
? name
: "<unknown>",
21556 parent_name
? parent_name
: "<unknown>");
21560 switch (parent
->tag
)
21562 case DW_TAG_namespace
:
21563 parent_type
= read_type_die (parent
, cu
);
21564 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21565 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21566 Work around this problem here. */
21567 if (cu
->language
== language_cplus
21568 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21570 /* We give a name to even anonymous namespaces. */
21571 return TYPE_NAME (parent_type
);
21572 case DW_TAG_class_type
:
21573 case DW_TAG_interface_type
:
21574 case DW_TAG_structure_type
:
21575 case DW_TAG_union_type
:
21576 case DW_TAG_module
:
21577 parent_type
= read_type_die (parent
, cu
);
21578 if (TYPE_NAME (parent_type
) != NULL
)
21579 return TYPE_NAME (parent_type
);
21581 /* An anonymous structure is only allowed non-static data
21582 members; no typedefs, no member functions, et cetera.
21583 So it does not need a prefix. */
21585 case DW_TAG_compile_unit
:
21586 case DW_TAG_partial_unit
:
21587 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21588 if (cu
->language
== language_cplus
21589 && !dwarf2_per_objfile
->types
.empty ()
21590 && die
->child
!= NULL
21591 && (die
->tag
== DW_TAG_class_type
21592 || die
->tag
== DW_TAG_structure_type
21593 || die
->tag
== DW_TAG_union_type
))
21595 const char *name
= guess_full_die_structure_name (die
, cu
);
21600 case DW_TAG_subprogram
:
21601 /* Nested subroutines in Fortran get a prefix with the name
21602 of the parent's subroutine. */
21603 if (cu
->language
== language_fortran
)
21605 if ((die
->tag
== DW_TAG_subprogram
)
21606 && (dwarf2_name (parent
, cu
) != NULL
))
21607 return dwarf2_name (parent
, cu
);
21609 return determine_prefix (parent
, cu
);
21610 case DW_TAG_enumeration_type
:
21611 parent_type
= read_type_die (parent
, cu
);
21612 if (TYPE_DECLARED_CLASS (parent_type
))
21614 if (TYPE_NAME (parent_type
) != NULL
)
21615 return TYPE_NAME (parent_type
);
21618 /* Fall through. */
21620 return determine_prefix (parent
, cu
);
21624 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21625 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21626 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21627 an obconcat, otherwise allocate storage for the result. The CU argument is
21628 used to determine the language and hence, the appropriate separator. */
21630 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21633 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21634 int physname
, struct dwarf2_cu
*cu
)
21636 const char *lead
= "";
21639 if (suffix
== NULL
|| suffix
[0] == '\0'
21640 || prefix
== NULL
|| prefix
[0] == '\0')
21642 else if (cu
->language
== language_d
)
21644 /* For D, the 'main' function could be defined in any module, but it
21645 should never be prefixed. */
21646 if (strcmp (suffix
, "D main") == 0)
21654 else if (cu
->language
== language_fortran
&& physname
)
21656 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21657 DW_AT_MIPS_linkage_name is preferred and used instead. */
21665 if (prefix
== NULL
)
21667 if (suffix
== NULL
)
21674 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21676 strcpy (retval
, lead
);
21677 strcat (retval
, prefix
);
21678 strcat (retval
, sep
);
21679 strcat (retval
, suffix
);
21684 /* We have an obstack. */
21685 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21689 /* Return sibling of die, NULL if no sibling. */
21691 static struct die_info
*
21692 sibling_die (struct die_info
*die
)
21694 return die
->sibling
;
21697 /* Get name of a die, return NULL if not found. */
21699 static const char *
21700 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21701 struct obstack
*obstack
)
21703 if (name
&& cu
->language
== language_cplus
)
21705 std::string canon_name
= cp_canonicalize_string (name
);
21707 if (!canon_name
.empty ())
21709 if (canon_name
!= name
)
21710 name
= obstack_strdup (obstack
, canon_name
);
21717 /* Get name of a die, return NULL if not found.
21718 Anonymous namespaces are converted to their magic string. */
21720 static const char *
21721 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21723 struct attribute
*attr
;
21724 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21726 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21727 if ((!attr
|| !DW_STRING (attr
))
21728 && die
->tag
!= DW_TAG_namespace
21729 && die
->tag
!= DW_TAG_class_type
21730 && die
->tag
!= DW_TAG_interface_type
21731 && die
->tag
!= DW_TAG_structure_type
21732 && die
->tag
!= DW_TAG_union_type
)
21737 case DW_TAG_compile_unit
:
21738 case DW_TAG_partial_unit
:
21739 /* Compilation units have a DW_AT_name that is a filename, not
21740 a source language identifier. */
21741 case DW_TAG_enumeration_type
:
21742 case DW_TAG_enumerator
:
21743 /* These tags always have simple identifiers already; no need
21744 to canonicalize them. */
21745 return DW_STRING (attr
);
21747 case DW_TAG_namespace
:
21748 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21749 return DW_STRING (attr
);
21750 return CP_ANONYMOUS_NAMESPACE_STR
;
21752 case DW_TAG_class_type
:
21753 case DW_TAG_interface_type
:
21754 case DW_TAG_structure_type
:
21755 case DW_TAG_union_type
:
21756 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21757 structures or unions. These were of the form "._%d" in GCC 4.1,
21758 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21759 and GCC 4.4. We work around this problem by ignoring these. */
21760 if (attr
&& DW_STRING (attr
)
21761 && (startswith (DW_STRING (attr
), "._")
21762 || startswith (DW_STRING (attr
), "<anonymous")))
21765 /* GCC might emit a nameless typedef that has a linkage name. See
21766 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21767 if (!attr
|| DW_STRING (attr
) == NULL
)
21769 attr
= dw2_linkage_name_attr (die
, cu
);
21770 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21773 /* Avoid demangling DW_STRING (attr) the second time on a second
21774 call for the same DIE. */
21775 if (!DW_STRING_IS_CANONICAL (attr
))
21777 gdb::unique_xmalloc_ptr
<char> demangled
21778 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21782 /* FIXME: we already did this for the partial symbol... */
21784 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
21786 DW_STRING_IS_CANONICAL (attr
) = 1;
21788 /* Strip any leading namespaces/classes, keep only the base name.
21789 DW_AT_name for named DIEs does not contain the prefixes. */
21790 base
= strrchr (DW_STRING (attr
), ':');
21791 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21794 return DW_STRING (attr
);
21803 if (!DW_STRING_IS_CANONICAL (attr
))
21806 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21807 &objfile
->per_bfd
->storage_obstack
);
21808 DW_STRING_IS_CANONICAL (attr
) = 1;
21810 return DW_STRING (attr
);
21813 /* Return the die that this die in an extension of, or NULL if there
21814 is none. *EXT_CU is the CU containing DIE on input, and the CU
21815 containing the return value on output. */
21817 static struct die_info
*
21818 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21820 struct attribute
*attr
;
21822 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21826 return follow_die_ref (die
, attr
, ext_cu
);
21829 /* A convenience function that returns an "unknown" DWARF name,
21830 including the value of V. STR is the name of the entity being
21831 printed, e.g., "TAG". */
21833 static const char *
21834 dwarf_unknown (const char *str
, unsigned v
)
21836 char *cell
= get_print_cell ();
21837 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21841 /* Convert a DIE tag into its string name. */
21843 static const char *
21844 dwarf_tag_name (unsigned tag
)
21846 const char *name
= get_DW_TAG_name (tag
);
21849 return dwarf_unknown ("TAG", tag
);
21854 /* Convert a DWARF attribute code into its string name. */
21856 static const char *
21857 dwarf_attr_name (unsigned attr
)
21861 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21862 if (attr
== DW_AT_MIPS_fde
)
21863 return "DW_AT_MIPS_fde";
21865 if (attr
== DW_AT_HP_block_index
)
21866 return "DW_AT_HP_block_index";
21869 name
= get_DW_AT_name (attr
);
21872 return dwarf_unknown ("AT", attr
);
21877 /* Convert a DWARF value form code into its string name. */
21879 static const char *
21880 dwarf_form_name (unsigned form
)
21882 const char *name
= get_DW_FORM_name (form
);
21885 return dwarf_unknown ("FORM", form
);
21890 static const char *
21891 dwarf_bool_name (unsigned mybool
)
21899 /* Convert a DWARF type code into its string name. */
21901 static const char *
21902 dwarf_type_encoding_name (unsigned enc
)
21904 const char *name
= get_DW_ATE_name (enc
);
21907 return dwarf_unknown ("ATE", enc
);
21913 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21917 print_spaces (indent
, f
);
21918 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21919 dwarf_tag_name (die
->tag
), die
->abbrev
,
21920 sect_offset_str (die
->sect_off
));
21922 if (die
->parent
!= NULL
)
21924 print_spaces (indent
, f
);
21925 fprintf_unfiltered (f
, " parent at offset: %s\n",
21926 sect_offset_str (die
->parent
->sect_off
));
21929 print_spaces (indent
, f
);
21930 fprintf_unfiltered (f
, " has children: %s\n",
21931 dwarf_bool_name (die
->child
!= NULL
));
21933 print_spaces (indent
, f
);
21934 fprintf_unfiltered (f
, " attributes:\n");
21936 for (i
= 0; i
< die
->num_attrs
; ++i
)
21938 print_spaces (indent
, f
);
21939 fprintf_unfiltered (f
, " %s (%s) ",
21940 dwarf_attr_name (die
->attrs
[i
].name
),
21941 dwarf_form_name (die
->attrs
[i
].form
));
21943 switch (die
->attrs
[i
].form
)
21946 case DW_FORM_addrx
:
21947 case DW_FORM_GNU_addr_index
:
21948 fprintf_unfiltered (f
, "address: ");
21949 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21951 case DW_FORM_block2
:
21952 case DW_FORM_block4
:
21953 case DW_FORM_block
:
21954 case DW_FORM_block1
:
21955 fprintf_unfiltered (f
, "block: size %s",
21956 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21958 case DW_FORM_exprloc
:
21959 fprintf_unfiltered (f
, "expression: size %s",
21960 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21962 case DW_FORM_data16
:
21963 fprintf_unfiltered (f
, "constant of 16 bytes");
21965 case DW_FORM_ref_addr
:
21966 fprintf_unfiltered (f
, "ref address: ");
21967 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21969 case DW_FORM_GNU_ref_alt
:
21970 fprintf_unfiltered (f
, "alt ref address: ");
21971 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21977 case DW_FORM_ref_udata
:
21978 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21979 (long) (DW_UNSND (&die
->attrs
[i
])));
21981 case DW_FORM_data1
:
21982 case DW_FORM_data2
:
21983 case DW_FORM_data4
:
21984 case DW_FORM_data8
:
21985 case DW_FORM_udata
:
21986 case DW_FORM_sdata
:
21987 fprintf_unfiltered (f
, "constant: %s",
21988 pulongest (DW_UNSND (&die
->attrs
[i
])));
21990 case DW_FORM_sec_offset
:
21991 fprintf_unfiltered (f
, "section offset: %s",
21992 pulongest (DW_UNSND (&die
->attrs
[i
])));
21994 case DW_FORM_ref_sig8
:
21995 fprintf_unfiltered (f
, "signature: %s",
21996 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21998 case DW_FORM_string
:
22000 case DW_FORM_line_strp
:
22002 case DW_FORM_GNU_str_index
:
22003 case DW_FORM_GNU_strp_alt
:
22004 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22005 DW_STRING (&die
->attrs
[i
])
22006 ? DW_STRING (&die
->attrs
[i
]) : "",
22007 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22010 if (DW_UNSND (&die
->attrs
[i
]))
22011 fprintf_unfiltered (f
, "flag: TRUE");
22013 fprintf_unfiltered (f
, "flag: FALSE");
22015 case DW_FORM_flag_present
:
22016 fprintf_unfiltered (f
, "flag: TRUE");
22018 case DW_FORM_indirect
:
22019 /* The reader will have reduced the indirect form to
22020 the "base form" so this form should not occur. */
22021 fprintf_unfiltered (f
,
22022 "unexpected attribute form: DW_FORM_indirect");
22024 case DW_FORM_implicit_const
:
22025 fprintf_unfiltered (f
, "constant: %s",
22026 plongest (DW_SND (&die
->attrs
[i
])));
22029 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22030 die
->attrs
[i
].form
);
22033 fprintf_unfiltered (f
, "\n");
22038 dump_die_for_error (struct die_info
*die
)
22040 dump_die_shallow (gdb_stderr
, 0, die
);
22044 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22046 int indent
= level
* 4;
22048 gdb_assert (die
!= NULL
);
22050 if (level
>= max_level
)
22053 dump_die_shallow (f
, indent
, die
);
22055 if (die
->child
!= NULL
)
22057 print_spaces (indent
, f
);
22058 fprintf_unfiltered (f
, " Children:");
22059 if (level
+ 1 < max_level
)
22061 fprintf_unfiltered (f
, "\n");
22062 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22066 fprintf_unfiltered (f
,
22067 " [not printed, max nesting level reached]\n");
22071 if (die
->sibling
!= NULL
&& level
> 0)
22073 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22077 /* This is called from the pdie macro in gdbinit.in.
22078 It's not static so gcc will keep a copy callable from gdb. */
22081 dump_die (struct die_info
*die
, int max_level
)
22083 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22087 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22091 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22092 to_underlying (die
->sect_off
),
22098 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22102 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22104 if (attr
->form_is_ref ())
22105 return (sect_offset
) DW_UNSND (attr
);
22107 complaint (_("unsupported die ref attribute form: '%s'"),
22108 dwarf_form_name (attr
->form
));
22112 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22113 * the value held by the attribute is not constant. */
22116 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22118 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22119 return DW_SND (attr
);
22120 else if (attr
->form
== DW_FORM_udata
22121 || attr
->form
== DW_FORM_data1
22122 || attr
->form
== DW_FORM_data2
22123 || attr
->form
== DW_FORM_data4
22124 || attr
->form
== DW_FORM_data8
)
22125 return DW_UNSND (attr
);
22128 /* For DW_FORM_data16 see attribute::form_is_constant. */
22129 complaint (_("Attribute value is not a constant (%s)"),
22130 dwarf_form_name (attr
->form
));
22131 return default_value
;
22135 /* Follow reference or signature attribute ATTR of SRC_DIE.
22136 On entry *REF_CU is the CU of SRC_DIE.
22137 On exit *REF_CU is the CU of the result. */
22139 static struct die_info
*
22140 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22141 struct dwarf2_cu
**ref_cu
)
22143 struct die_info
*die
;
22145 if (attr
->form_is_ref ())
22146 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22147 else if (attr
->form
== DW_FORM_ref_sig8
)
22148 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22151 dump_die_for_error (src_die
);
22152 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22153 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22159 /* Follow reference OFFSET.
22160 On entry *REF_CU is the CU of the source die referencing OFFSET.
22161 On exit *REF_CU is the CU of the result.
22162 Returns NULL if OFFSET is invalid. */
22164 static struct die_info
*
22165 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22166 struct dwarf2_cu
**ref_cu
)
22168 struct die_info temp_die
;
22169 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22170 struct dwarf2_per_objfile
*dwarf2_per_objfile
22171 = cu
->per_cu
->dwarf2_per_objfile
;
22173 gdb_assert (cu
->per_cu
!= NULL
);
22177 if (cu
->per_cu
->is_debug_types
)
22179 /* .debug_types CUs cannot reference anything outside their CU.
22180 If they need to, they have to reference a signatured type via
22181 DW_FORM_ref_sig8. */
22182 if (!cu
->header
.offset_in_cu_p (sect_off
))
22185 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22186 || !cu
->header
.offset_in_cu_p (sect_off
))
22188 struct dwarf2_per_cu_data
*per_cu
;
22190 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22191 dwarf2_per_objfile
);
22193 /* If necessary, add it to the queue and load its DIEs. */
22194 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22195 load_full_comp_unit (per_cu
, false, cu
->language
);
22197 target_cu
= per_cu
->cu
;
22199 else if (cu
->dies
== NULL
)
22201 /* We're loading full DIEs during partial symbol reading. */
22202 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22203 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22206 *ref_cu
= target_cu
;
22207 temp_die
.sect_off
= sect_off
;
22209 if (target_cu
!= cu
)
22210 target_cu
->ancestor
= cu
;
22212 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22214 to_underlying (sect_off
));
22217 /* Follow reference attribute ATTR of SRC_DIE.
22218 On entry *REF_CU is the CU of SRC_DIE.
22219 On exit *REF_CU is the CU of the result. */
22221 static struct die_info
*
22222 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22223 struct dwarf2_cu
**ref_cu
)
22225 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22226 struct dwarf2_cu
*cu
= *ref_cu
;
22227 struct die_info
*die
;
22229 die
= follow_die_offset (sect_off
,
22230 (attr
->form
== DW_FORM_GNU_ref_alt
22231 || cu
->per_cu
->is_dwz
),
22234 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22235 "at %s [in module %s]"),
22236 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22237 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22242 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22243 Returned value is intended for DW_OP_call*. Returned
22244 dwarf2_locexpr_baton->data has lifetime of
22245 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22247 struct dwarf2_locexpr_baton
22248 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22249 struct dwarf2_per_cu_data
*per_cu
,
22250 CORE_ADDR (*get_frame_pc
) (void *baton
),
22251 void *baton
, bool resolve_abstract_p
)
22253 struct dwarf2_cu
*cu
;
22254 struct die_info
*die
;
22255 struct attribute
*attr
;
22256 struct dwarf2_locexpr_baton retval
;
22257 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22258 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22260 if (per_cu
->cu
== NULL
)
22261 load_cu (per_cu
, false);
22265 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22266 Instead just throw an error, not much else we can do. */
22267 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22268 sect_offset_str (sect_off
), objfile_name (objfile
));
22271 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22273 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22274 sect_offset_str (sect_off
), objfile_name (objfile
));
22276 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22277 if (!attr
&& resolve_abstract_p
22278 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22279 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22281 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22282 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22283 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22285 for (const auto &cand_off
22286 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22288 struct dwarf2_cu
*cand_cu
= cu
;
22289 struct die_info
*cand
22290 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22293 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22296 CORE_ADDR pc_low
, pc_high
;
22297 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22298 if (pc_low
== ((CORE_ADDR
) -1))
22300 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22301 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22302 if (!(pc_low
<= pc
&& pc
< pc_high
))
22306 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22313 /* DWARF: "If there is no such attribute, then there is no effect.".
22314 DATA is ignored if SIZE is 0. */
22316 retval
.data
= NULL
;
22319 else if (attr
->form_is_section_offset ())
22321 struct dwarf2_loclist_baton loclist_baton
;
22322 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22325 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22327 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22329 retval
.size
= size
;
22333 if (!attr
->form_is_block ())
22334 error (_("Dwarf Error: DIE at %s referenced in module %s "
22335 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22336 sect_offset_str (sect_off
), objfile_name (objfile
));
22338 retval
.data
= DW_BLOCK (attr
)->data
;
22339 retval
.size
= DW_BLOCK (attr
)->size
;
22341 retval
.per_cu
= cu
->per_cu
;
22343 age_cached_comp_units (dwarf2_per_objfile
);
22348 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
22351 struct dwarf2_locexpr_baton
22352 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22353 struct dwarf2_per_cu_data
*per_cu
,
22354 CORE_ADDR (*get_frame_pc
) (void *baton
),
22357 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22359 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22362 /* Write a constant of a given type as target-ordered bytes into
22365 static const gdb_byte
*
22366 write_constant_as_bytes (struct obstack
*obstack
,
22367 enum bfd_endian byte_order
,
22374 *len
= TYPE_LENGTH (type
);
22375 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22376 store_unsigned_integer (result
, *len
, byte_order
, value
);
22381 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
22382 pointer to the constant bytes and set LEN to the length of the
22383 data. If memory is needed, allocate it on OBSTACK. If the DIE
22384 does not have a DW_AT_const_value, return NULL. */
22387 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22388 struct dwarf2_per_cu_data
*per_cu
,
22389 struct obstack
*obstack
,
22392 struct dwarf2_cu
*cu
;
22393 struct die_info
*die
;
22394 struct attribute
*attr
;
22395 const gdb_byte
*result
= NULL
;
22398 enum bfd_endian byte_order
;
22399 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22401 if (per_cu
->cu
== NULL
)
22402 load_cu (per_cu
, false);
22406 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22407 Instead just throw an error, not much else we can do. */
22408 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22409 sect_offset_str (sect_off
), objfile_name (objfile
));
22412 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22414 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22415 sect_offset_str (sect_off
), objfile_name (objfile
));
22417 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22421 byte_order
= (bfd_big_endian (objfile
->obfd
)
22422 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22424 switch (attr
->form
)
22427 case DW_FORM_addrx
:
22428 case DW_FORM_GNU_addr_index
:
22432 *len
= cu
->header
.addr_size
;
22433 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22434 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22438 case DW_FORM_string
:
22441 case DW_FORM_GNU_str_index
:
22442 case DW_FORM_GNU_strp_alt
:
22443 /* DW_STRING is already allocated on the objfile obstack, point
22445 result
= (const gdb_byte
*) DW_STRING (attr
);
22446 *len
= strlen (DW_STRING (attr
));
22448 case DW_FORM_block1
:
22449 case DW_FORM_block2
:
22450 case DW_FORM_block4
:
22451 case DW_FORM_block
:
22452 case DW_FORM_exprloc
:
22453 case DW_FORM_data16
:
22454 result
= DW_BLOCK (attr
)->data
;
22455 *len
= DW_BLOCK (attr
)->size
;
22458 /* The DW_AT_const_value attributes are supposed to carry the
22459 symbol's value "represented as it would be on the target
22460 architecture." By the time we get here, it's already been
22461 converted to host endianness, so we just need to sign- or
22462 zero-extend it as appropriate. */
22463 case DW_FORM_data1
:
22464 type
= die_type (die
, cu
);
22465 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22466 if (result
== NULL
)
22467 result
= write_constant_as_bytes (obstack
, byte_order
,
22470 case DW_FORM_data2
:
22471 type
= die_type (die
, cu
);
22472 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22473 if (result
== NULL
)
22474 result
= write_constant_as_bytes (obstack
, byte_order
,
22477 case DW_FORM_data4
:
22478 type
= die_type (die
, cu
);
22479 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22480 if (result
== NULL
)
22481 result
= write_constant_as_bytes (obstack
, byte_order
,
22484 case DW_FORM_data8
:
22485 type
= die_type (die
, cu
);
22486 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22487 if (result
== NULL
)
22488 result
= write_constant_as_bytes (obstack
, byte_order
,
22492 case DW_FORM_sdata
:
22493 case DW_FORM_implicit_const
:
22494 type
= die_type (die
, cu
);
22495 result
= write_constant_as_bytes (obstack
, byte_order
,
22496 type
, DW_SND (attr
), len
);
22499 case DW_FORM_udata
:
22500 type
= die_type (die
, cu
);
22501 result
= write_constant_as_bytes (obstack
, byte_order
,
22502 type
, DW_UNSND (attr
), len
);
22506 complaint (_("unsupported const value attribute form: '%s'"),
22507 dwarf_form_name (attr
->form
));
22514 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
22515 valid type for this die is found. */
22518 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22519 struct dwarf2_per_cu_data
*per_cu
)
22521 struct dwarf2_cu
*cu
;
22522 struct die_info
*die
;
22524 if (per_cu
->cu
== NULL
)
22525 load_cu (per_cu
, false);
22530 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22534 return die_type (die
, cu
);
22537 /* Return the type of the DIE at DIE_OFFSET in the CU named by
22541 dwarf2_get_die_type (cu_offset die_offset
,
22542 struct dwarf2_per_cu_data
*per_cu
)
22544 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22545 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22548 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22549 On entry *REF_CU is the CU of SRC_DIE.
22550 On exit *REF_CU is the CU of the result.
22551 Returns NULL if the referenced DIE isn't found. */
22553 static struct die_info
*
22554 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22555 struct dwarf2_cu
**ref_cu
)
22557 struct die_info temp_die
;
22558 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22559 struct die_info
*die
;
22561 /* While it might be nice to assert sig_type->type == NULL here,
22562 we can get here for DW_AT_imported_declaration where we need
22563 the DIE not the type. */
22565 /* If necessary, add it to the queue and load its DIEs. */
22567 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22568 read_signatured_type (sig_type
);
22570 sig_cu
= sig_type
->per_cu
.cu
;
22571 gdb_assert (sig_cu
!= NULL
);
22572 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22573 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22574 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22575 to_underlying (temp_die
.sect_off
));
22578 struct dwarf2_per_objfile
*dwarf2_per_objfile
22579 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22581 /* For .gdb_index version 7 keep track of included TUs.
22582 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22583 if (dwarf2_per_objfile
->index_table
!= NULL
22584 && dwarf2_per_objfile
->index_table
->version
<= 7)
22586 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22591 sig_cu
->ancestor
= cu
;
22599 /* Follow signatured type referenced by ATTR in SRC_DIE.
22600 On entry *REF_CU is the CU of SRC_DIE.
22601 On exit *REF_CU is the CU of the result.
22602 The result is the DIE of the type.
22603 If the referenced type cannot be found an error is thrown. */
22605 static struct die_info
*
22606 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22607 struct dwarf2_cu
**ref_cu
)
22609 ULONGEST signature
= DW_SIGNATURE (attr
);
22610 struct signatured_type
*sig_type
;
22611 struct die_info
*die
;
22613 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22615 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22616 /* sig_type will be NULL if the signatured type is missing from
22618 if (sig_type
== NULL
)
22620 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22621 " from DIE at %s [in module %s]"),
22622 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22623 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22626 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22629 dump_die_for_error (src_die
);
22630 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22631 " from DIE at %s [in module %s]"),
22632 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22633 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22639 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22640 reading in and processing the type unit if necessary. */
22642 static struct type
*
22643 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22644 struct dwarf2_cu
*cu
)
22646 struct dwarf2_per_objfile
*dwarf2_per_objfile
22647 = cu
->per_cu
->dwarf2_per_objfile
;
22648 struct signatured_type
*sig_type
;
22649 struct dwarf2_cu
*type_cu
;
22650 struct die_info
*type_die
;
22653 sig_type
= lookup_signatured_type (cu
, signature
);
22654 /* sig_type will be NULL if the signatured type is missing from
22656 if (sig_type
== NULL
)
22658 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22659 " from DIE at %s [in module %s]"),
22660 hex_string (signature
), sect_offset_str (die
->sect_off
),
22661 objfile_name (dwarf2_per_objfile
->objfile
));
22662 return build_error_marker_type (cu
, die
);
22665 /* If we already know the type we're done. */
22666 if (sig_type
->type
!= NULL
)
22667 return sig_type
->type
;
22670 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22671 if (type_die
!= NULL
)
22673 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22674 is created. This is important, for example, because for c++ classes
22675 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22676 type
= read_type_die (type_die
, type_cu
);
22679 complaint (_("Dwarf Error: Cannot build signatured type %s"
22680 " referenced from DIE at %s [in module %s]"),
22681 hex_string (signature
), sect_offset_str (die
->sect_off
),
22682 objfile_name (dwarf2_per_objfile
->objfile
));
22683 type
= build_error_marker_type (cu
, die
);
22688 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22689 " from DIE at %s [in module %s]"),
22690 hex_string (signature
), sect_offset_str (die
->sect_off
),
22691 objfile_name (dwarf2_per_objfile
->objfile
));
22692 type
= build_error_marker_type (cu
, die
);
22694 sig_type
->type
= type
;
22699 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22700 reading in and processing the type unit if necessary. */
22702 static struct type
*
22703 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22704 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22706 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22707 if (attr
->form_is_ref ())
22709 struct dwarf2_cu
*type_cu
= cu
;
22710 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22712 return read_type_die (type_die
, type_cu
);
22714 else if (attr
->form
== DW_FORM_ref_sig8
)
22716 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22720 struct dwarf2_per_objfile
*dwarf2_per_objfile
22721 = cu
->per_cu
->dwarf2_per_objfile
;
22723 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22724 " at %s [in module %s]"),
22725 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22726 objfile_name (dwarf2_per_objfile
->objfile
));
22727 return build_error_marker_type (cu
, die
);
22731 /* Load the DIEs associated with type unit PER_CU into memory. */
22734 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22736 struct signatured_type
*sig_type
;
22738 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22739 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
22741 /* We have the per_cu, but we need the signatured_type.
22742 Fortunately this is an easy translation. */
22743 gdb_assert (per_cu
->is_debug_types
);
22744 sig_type
= (struct signatured_type
*) per_cu
;
22746 gdb_assert (per_cu
->cu
== NULL
);
22748 read_signatured_type (sig_type
);
22750 gdb_assert (per_cu
->cu
!= NULL
);
22753 /* Read in a signatured type and build its CU and DIEs.
22754 If the type is a stub for the real type in a DWO file,
22755 read in the real type from the DWO file as well. */
22758 read_signatured_type (struct signatured_type
*sig_type
)
22760 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22762 gdb_assert (per_cu
->is_debug_types
);
22763 gdb_assert (per_cu
->cu
== NULL
);
22765 cutu_reader
reader (per_cu
, NULL
, 0, false);
22767 if (!reader
.dummy_p
)
22769 struct dwarf2_cu
*cu
= reader
.cu
;
22770 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22772 gdb_assert (cu
->die_hash
== NULL
);
22774 htab_create_alloc_ex (cu
->header
.length
/ 12,
22778 &cu
->comp_unit_obstack
,
22779 hashtab_obstack_allocate
,
22780 dummy_obstack_deallocate
);
22782 if (reader
.comp_unit_die
->has_children
)
22783 reader
.comp_unit_die
->child
22784 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22785 reader
.comp_unit_die
);
22786 cu
->dies
= reader
.comp_unit_die
;
22787 /* comp_unit_die is not stored in die_hash, no need. */
22789 /* We try not to read any attributes in this function, because
22790 not all CUs needed for references have been loaded yet, and
22791 symbol table processing isn't initialized. But we have to
22792 set the CU language, or we won't be able to build types
22793 correctly. Similarly, if we do not read the producer, we can
22794 not apply producer-specific interpretation. */
22795 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22800 sig_type
->per_cu
.tu_read
= 1;
22803 /* Decode simple location descriptions.
22804 Given a pointer to a dwarf block that defines a location, compute
22805 the location and return the value.
22807 NOTE drow/2003-11-18: This function is called in two situations
22808 now: for the address of static or global variables (partial symbols
22809 only) and for offsets into structures which are expected to be
22810 (more or less) constant. The partial symbol case should go away,
22811 and only the constant case should remain. That will let this
22812 function complain more accurately. A few special modes are allowed
22813 without complaint for global variables (for instance, global
22814 register values and thread-local values).
22816 A location description containing no operations indicates that the
22817 object is optimized out. The return value is 0 for that case.
22818 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22819 callers will only want a very basic result and this can become a
22822 Note that stack[0] is unused except as a default error return. */
22825 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22827 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22829 size_t size
= blk
->size
;
22830 const gdb_byte
*data
= blk
->data
;
22831 CORE_ADDR stack
[64];
22833 unsigned int bytes_read
, unsnd
;
22839 stack
[++stacki
] = 0;
22878 stack
[++stacki
] = op
- DW_OP_lit0
;
22913 stack
[++stacki
] = op
- DW_OP_reg0
;
22915 dwarf2_complex_location_expr_complaint ();
22919 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22921 stack
[++stacki
] = unsnd
;
22923 dwarf2_complex_location_expr_complaint ();
22927 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22932 case DW_OP_const1u
:
22933 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22937 case DW_OP_const1s
:
22938 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22942 case DW_OP_const2u
:
22943 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22947 case DW_OP_const2s
:
22948 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22952 case DW_OP_const4u
:
22953 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22957 case DW_OP_const4s
:
22958 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22962 case DW_OP_const8u
:
22963 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22968 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22974 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22979 stack
[stacki
+ 1] = stack
[stacki
];
22984 stack
[stacki
- 1] += stack
[stacki
];
22988 case DW_OP_plus_uconst
:
22989 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22995 stack
[stacki
- 1] -= stack
[stacki
];
23000 /* If we're not the last op, then we definitely can't encode
23001 this using GDB's address_class enum. This is valid for partial
23002 global symbols, although the variable's address will be bogus
23005 dwarf2_complex_location_expr_complaint ();
23008 case DW_OP_GNU_push_tls_address
:
23009 case DW_OP_form_tls_address
:
23010 /* The top of the stack has the offset from the beginning
23011 of the thread control block at which the variable is located. */
23012 /* Nothing should follow this operator, so the top of stack would
23014 /* This is valid for partial global symbols, but the variable's
23015 address will be bogus in the psymtab. Make it always at least
23016 non-zero to not look as a variable garbage collected by linker
23017 which have DW_OP_addr 0. */
23019 dwarf2_complex_location_expr_complaint ();
23023 case DW_OP_GNU_uninit
:
23027 case DW_OP_GNU_addr_index
:
23028 case DW_OP_GNU_const_index
:
23029 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23036 const char *name
= get_DW_OP_name (op
);
23039 complaint (_("unsupported stack op: '%s'"),
23042 complaint (_("unsupported stack op: '%02x'"),
23046 return (stack
[stacki
]);
23049 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23050 outside of the allocated space. Also enforce minimum>0. */
23051 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23053 complaint (_("location description stack overflow"));
23059 complaint (_("location description stack underflow"));
23063 return (stack
[stacki
]);
23066 /* memory allocation interface */
23068 static struct dwarf_block
*
23069 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23071 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23074 static struct die_info
*
23075 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23077 struct die_info
*die
;
23078 size_t size
= sizeof (struct die_info
);
23081 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23083 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23084 memset (die
, 0, sizeof (struct die_info
));
23089 /* Macro support. */
23091 static struct macro_source_file
*
23092 macro_start_file (struct dwarf2_cu
*cu
,
23093 int file
, int line
,
23094 struct macro_source_file
*current_file
,
23095 struct line_header
*lh
)
23097 /* File name relative to the compilation directory of this source file. */
23098 gdb::unique_xmalloc_ptr
<char> file_name
= lh
->file_file_name (file
);
23100 if (! current_file
)
23102 /* Note: We don't create a macro table for this compilation unit
23103 at all until we actually get a filename. */
23104 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23106 /* If we have no current file, then this must be the start_file
23107 directive for the compilation unit's main source file. */
23108 current_file
= macro_set_main (macro_table
, file_name
.get ());
23109 macro_define_special (macro_table
);
23112 current_file
= macro_include (current_file
, line
, file_name
.get ());
23114 return current_file
;
23117 static const char *
23118 consume_improper_spaces (const char *p
, const char *body
)
23122 complaint (_("macro definition contains spaces "
23123 "in formal argument list:\n`%s'"),
23135 parse_macro_definition (struct macro_source_file
*file
, int line
,
23140 /* The body string takes one of two forms. For object-like macro
23141 definitions, it should be:
23143 <macro name> " " <definition>
23145 For function-like macro definitions, it should be:
23147 <macro name> "() " <definition>
23149 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23151 Spaces may appear only where explicitly indicated, and in the
23154 The Dwarf 2 spec says that an object-like macro's name is always
23155 followed by a space, but versions of GCC around March 2002 omit
23156 the space when the macro's definition is the empty string.
23158 The Dwarf 2 spec says that there should be no spaces between the
23159 formal arguments in a function-like macro's formal argument list,
23160 but versions of GCC around March 2002 include spaces after the
23164 /* Find the extent of the macro name. The macro name is terminated
23165 by either a space or null character (for an object-like macro) or
23166 an opening paren (for a function-like macro). */
23167 for (p
= body
; *p
; p
++)
23168 if (*p
== ' ' || *p
== '(')
23171 if (*p
== ' ' || *p
== '\0')
23173 /* It's an object-like macro. */
23174 int name_len
= p
- body
;
23175 std::string
name (body
, name_len
);
23176 const char *replacement
;
23179 replacement
= body
+ name_len
+ 1;
23182 dwarf2_macro_malformed_definition_complaint (body
);
23183 replacement
= body
+ name_len
;
23186 macro_define_object (file
, line
, name
.c_str (), replacement
);
23188 else if (*p
== '(')
23190 /* It's a function-like macro. */
23191 std::string
name (body
, p
- body
);
23194 char **argv
= XNEWVEC (char *, argv_size
);
23198 p
= consume_improper_spaces (p
, body
);
23200 /* Parse the formal argument list. */
23201 while (*p
&& *p
!= ')')
23203 /* Find the extent of the current argument name. */
23204 const char *arg_start
= p
;
23206 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23209 if (! *p
|| p
== arg_start
)
23210 dwarf2_macro_malformed_definition_complaint (body
);
23213 /* Make sure argv has room for the new argument. */
23214 if (argc
>= argv_size
)
23217 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23220 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23223 p
= consume_improper_spaces (p
, body
);
23225 /* Consume the comma, if present. */
23230 p
= consume_improper_spaces (p
, body
);
23239 /* Perfectly formed definition, no complaints. */
23240 macro_define_function (file
, line
, name
.c_str (),
23241 argc
, (const char **) argv
,
23243 else if (*p
== '\0')
23245 /* Complain, but do define it. */
23246 dwarf2_macro_malformed_definition_complaint (body
);
23247 macro_define_function (file
, line
, name
.c_str (),
23248 argc
, (const char **) argv
,
23252 /* Just complain. */
23253 dwarf2_macro_malformed_definition_complaint (body
);
23256 /* Just complain. */
23257 dwarf2_macro_malformed_definition_complaint (body
);
23262 for (i
= 0; i
< argc
; i
++)
23268 dwarf2_macro_malformed_definition_complaint (body
);
23271 /* Skip some bytes from BYTES according to the form given in FORM.
23272 Returns the new pointer. */
23274 static const gdb_byte
*
23275 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23276 enum dwarf_form form
,
23277 unsigned int offset_size
,
23278 struct dwarf2_section_info
*section
)
23280 unsigned int bytes_read
;
23284 case DW_FORM_data1
:
23289 case DW_FORM_data2
:
23293 case DW_FORM_data4
:
23297 case DW_FORM_data8
:
23301 case DW_FORM_data16
:
23305 case DW_FORM_string
:
23306 read_direct_string (abfd
, bytes
, &bytes_read
);
23307 bytes
+= bytes_read
;
23310 case DW_FORM_sec_offset
:
23312 case DW_FORM_GNU_strp_alt
:
23313 bytes
+= offset_size
;
23316 case DW_FORM_block
:
23317 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23318 bytes
+= bytes_read
;
23321 case DW_FORM_block1
:
23322 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23324 case DW_FORM_block2
:
23325 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23327 case DW_FORM_block4
:
23328 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23331 case DW_FORM_addrx
:
23332 case DW_FORM_sdata
:
23334 case DW_FORM_udata
:
23335 case DW_FORM_GNU_addr_index
:
23336 case DW_FORM_GNU_str_index
:
23337 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23340 dwarf2_section_buffer_overflow_complaint (section
);
23345 case DW_FORM_implicit_const
:
23350 complaint (_("invalid form 0x%x in `%s'"),
23351 form
, section
->get_name ());
23359 /* A helper for dwarf_decode_macros that handles skipping an unknown
23360 opcode. Returns an updated pointer to the macro data buffer; or,
23361 on error, issues a complaint and returns NULL. */
23363 static const gdb_byte
*
23364 skip_unknown_opcode (unsigned int opcode
,
23365 const gdb_byte
**opcode_definitions
,
23366 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23368 unsigned int offset_size
,
23369 struct dwarf2_section_info
*section
)
23371 unsigned int bytes_read
, i
;
23373 const gdb_byte
*defn
;
23375 if (opcode_definitions
[opcode
] == NULL
)
23377 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
23382 defn
= opcode_definitions
[opcode
];
23383 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
23384 defn
+= bytes_read
;
23386 for (i
= 0; i
< arg
; ++i
)
23388 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
23389 (enum dwarf_form
) defn
[i
], offset_size
,
23391 if (mac_ptr
== NULL
)
23393 /* skip_form_bytes already issued the complaint. */
23401 /* A helper function which parses the header of a macro section.
23402 If the macro section is the extended (for now called "GNU") type,
23403 then this updates *OFFSET_SIZE. Returns a pointer to just after
23404 the header, or issues a complaint and returns NULL on error. */
23406 static const gdb_byte
*
23407 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
23409 const gdb_byte
*mac_ptr
,
23410 unsigned int *offset_size
,
23411 int section_is_gnu
)
23413 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
23415 if (section_is_gnu
)
23417 unsigned int version
, flags
;
23419 version
= read_2_bytes (abfd
, mac_ptr
);
23420 if (version
!= 4 && version
!= 5)
23422 complaint (_("unrecognized version `%d' in .debug_macro section"),
23428 flags
= read_1_byte (abfd
, mac_ptr
);
23430 *offset_size
= (flags
& 1) ? 8 : 4;
23432 if ((flags
& 2) != 0)
23433 /* We don't need the line table offset. */
23434 mac_ptr
+= *offset_size
;
23436 /* Vendor opcode descriptions. */
23437 if ((flags
& 4) != 0)
23439 unsigned int i
, count
;
23441 count
= read_1_byte (abfd
, mac_ptr
);
23443 for (i
= 0; i
< count
; ++i
)
23445 unsigned int opcode
, bytes_read
;
23448 opcode
= read_1_byte (abfd
, mac_ptr
);
23450 opcode_definitions
[opcode
] = mac_ptr
;
23451 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23452 mac_ptr
+= bytes_read
;
23461 /* A helper for dwarf_decode_macros that handles the GNU extensions,
23462 including DW_MACRO_import. */
23465 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
23467 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23468 struct macro_source_file
*current_file
,
23469 struct line_header
*lh
,
23470 struct dwarf2_section_info
*section
,
23471 int section_is_gnu
, int section_is_dwz
,
23472 unsigned int offset_size
,
23473 htab_t include_hash
)
23475 struct dwarf2_per_objfile
*dwarf2_per_objfile
23476 = cu
->per_cu
->dwarf2_per_objfile
;
23477 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23478 enum dwarf_macro_record_type macinfo_type
;
23479 int at_commandline
;
23480 const gdb_byte
*opcode_definitions
[256];
23482 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23483 &offset_size
, section_is_gnu
);
23484 if (mac_ptr
== NULL
)
23486 /* We already issued a complaint. */
23490 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
23491 GDB is still reading the definitions from command line. First
23492 DW_MACINFO_start_file will need to be ignored as it was already executed
23493 to create CURRENT_FILE for the main source holding also the command line
23494 definitions. On first met DW_MACINFO_start_file this flag is reset to
23495 normally execute all the remaining DW_MACINFO_start_file macinfos. */
23497 at_commandline
= 1;
23501 /* Do we at least have room for a macinfo type byte? */
23502 if (mac_ptr
>= mac_end
)
23504 dwarf2_section_buffer_overflow_complaint (section
);
23508 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23511 /* Note that we rely on the fact that the corresponding GNU and
23512 DWARF constants are the same. */
23514 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23515 switch (macinfo_type
)
23517 /* A zero macinfo type indicates the end of the macro
23522 case DW_MACRO_define
:
23523 case DW_MACRO_undef
:
23524 case DW_MACRO_define_strp
:
23525 case DW_MACRO_undef_strp
:
23526 case DW_MACRO_define_sup
:
23527 case DW_MACRO_undef_sup
:
23529 unsigned int bytes_read
;
23534 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23535 mac_ptr
+= bytes_read
;
23537 if (macinfo_type
== DW_MACRO_define
23538 || macinfo_type
== DW_MACRO_undef
)
23540 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23541 mac_ptr
+= bytes_read
;
23545 LONGEST str_offset
;
23547 str_offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23548 mac_ptr
+= offset_size
;
23550 if (macinfo_type
== DW_MACRO_define_sup
23551 || macinfo_type
== DW_MACRO_undef_sup
23554 struct dwz_file
*dwz
23555 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
23557 body
= read_indirect_string_from_dwz (objfile
,
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 /* Locate the .debug_info compilation unit from CU's objfile which contains
24160 the DIE at OFFSET. Raises an error on failure. */
24162 static struct dwarf2_per_cu_data
*
24163 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24164 unsigned int offset_in_dwz
,
24165 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24167 struct dwarf2_per_cu_data
*this_cu
;
24171 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24174 struct dwarf2_per_cu_data
*mid_cu
;
24175 int mid
= low
+ (high
- low
) / 2;
24177 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24178 if (mid_cu
->is_dwz
> offset_in_dwz
24179 || (mid_cu
->is_dwz
== offset_in_dwz
24180 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
24185 gdb_assert (low
== high
);
24186 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24187 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24189 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24190 error (_("Dwarf Error: could not find partial DIE containing "
24191 "offset %s [in module %s]"),
24192 sect_offset_str (sect_off
),
24193 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24195 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24197 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24201 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24202 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24203 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24204 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24209 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24211 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24212 : per_cu (per_cu_
),
24214 has_loclist (false),
24215 checked_producer (false),
24216 producer_is_gxx_lt_4_6 (false),
24217 producer_is_gcc_lt_4_3 (false),
24218 producer_is_icc (false),
24219 producer_is_icc_lt_14 (false),
24220 producer_is_codewarrior (false),
24221 processing_has_namespace_info (false)
24226 /* Destroy a dwarf2_cu. */
24228 dwarf2_cu::~dwarf2_cu ()
24233 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24236 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24237 enum language pretend_language
)
24239 struct attribute
*attr
;
24241 /* Set the language we're debugging. */
24242 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24243 if (attr
!= nullptr)
24244 set_cu_language (DW_UNSND (attr
), cu
);
24247 cu
->language
= pretend_language
;
24248 cu
->language_defn
= language_def (cu
->language
);
24251 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24254 /* Increase the age counter on each cached compilation unit, and free
24255 any that are too old. */
24258 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24260 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24262 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24263 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24264 while (per_cu
!= NULL
)
24266 per_cu
->cu
->last_used
++;
24267 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24268 dwarf2_mark (per_cu
->cu
);
24269 per_cu
= per_cu
->cu
->read_in_chain
;
24272 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24273 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24274 while (per_cu
!= NULL
)
24276 struct dwarf2_per_cu_data
*next_cu
;
24278 next_cu
= per_cu
->cu
->read_in_chain
;
24280 if (!per_cu
->cu
->mark
)
24283 *last_chain
= next_cu
;
24286 last_chain
= &per_cu
->cu
->read_in_chain
;
24292 /* Remove a single compilation unit from the cache. */
24295 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
24297 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24298 struct dwarf2_per_objfile
*dwarf2_per_objfile
24299 = target_per_cu
->dwarf2_per_objfile
;
24301 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24302 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24303 while (per_cu
!= NULL
)
24305 struct dwarf2_per_cu_data
*next_cu
;
24307 next_cu
= per_cu
->cu
->read_in_chain
;
24309 if (per_cu
== target_per_cu
)
24313 *last_chain
= next_cu
;
24317 last_chain
= &per_cu
->cu
->read_in_chain
;
24323 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24324 We store these in a hash table separate from the DIEs, and preserve them
24325 when the DIEs are flushed out of cache.
24327 The CU "per_cu" pointer is needed because offset alone is not enough to
24328 uniquely identify the type. A file may have multiple .debug_types sections,
24329 or the type may come from a DWO file. Furthermore, while it's more logical
24330 to use per_cu->section+offset, with Fission the section with the data is in
24331 the DWO file but we don't know that section at the point we need it.
24332 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24333 because we can enter the lookup routine, get_die_type_at_offset, from
24334 outside this file, and thus won't necessarily have PER_CU->cu.
24335 Fortunately, PER_CU is stable for the life of the objfile. */
24337 struct dwarf2_per_cu_offset_and_type
24339 const struct dwarf2_per_cu_data
*per_cu
;
24340 sect_offset sect_off
;
24344 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24347 per_cu_offset_and_type_hash (const void *item
)
24349 const struct dwarf2_per_cu_offset_and_type
*ofs
24350 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24352 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24355 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24358 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24360 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24361 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24362 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24363 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24365 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24366 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24369 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24370 table if necessary. For convenience, return TYPE.
24372 The DIEs reading must have careful ordering to:
24373 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24374 reading current DIE.
24375 * Not trying to dereference contents of still incompletely read in types
24376 while reading in other DIEs.
24377 * Enable referencing still incompletely read in types just by a pointer to
24378 the type without accessing its fields.
24380 Therefore caller should follow these rules:
24381 * Try to fetch any prerequisite types we may need to build this DIE type
24382 before building the type and calling set_die_type.
24383 * After building type call set_die_type for current DIE as soon as
24384 possible before fetching more types to complete the current type.
24385 * Make the type as complete as possible before fetching more types. */
24387 static struct type
*
24388 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24390 struct dwarf2_per_objfile
*dwarf2_per_objfile
24391 = cu
->per_cu
->dwarf2_per_objfile
;
24392 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24393 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24394 struct attribute
*attr
;
24395 struct dynamic_prop prop
;
24397 /* For Ada types, make sure that the gnat-specific data is always
24398 initialized (if not already set). There are a few types where
24399 we should not be doing so, because the type-specific area is
24400 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24401 where the type-specific area is used to store the floatformat).
24402 But this is not a problem, because the gnat-specific information
24403 is actually not needed for these types. */
24404 if (need_gnat_info (cu
)
24405 && TYPE_CODE (type
) != TYPE_CODE_FUNC
24406 && TYPE_CODE (type
) != TYPE_CODE_FLT
24407 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
24408 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
24409 && TYPE_CODE (type
) != TYPE_CODE_METHOD
24410 && !HAVE_GNAT_AUX_INFO (type
))
24411 INIT_GNAT_SPECIFIC (type
);
24413 /* Read DW_AT_allocated and set in type. */
24414 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24415 if (attr
!= NULL
&& attr
->form_is_block ())
24417 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24418 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24419 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
24421 else if (attr
!= NULL
)
24423 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
24424 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24425 sect_offset_str (die
->sect_off
));
24428 /* Read DW_AT_associated and set in type. */
24429 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24430 if (attr
!= NULL
&& attr
->form_is_block ())
24432 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24433 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24434 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
24436 else if (attr
!= NULL
)
24438 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
24439 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24440 sect_offset_str (die
->sect_off
));
24443 /* Read DW_AT_data_location and set in type. */
24444 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24445 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
24446 cu
->per_cu
->addr_type ()))
24447 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
24449 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24450 dwarf2_per_objfile
->die_type_hash
24451 = htab_up (htab_create_alloc (127,
24452 per_cu_offset_and_type_hash
,
24453 per_cu_offset_and_type_eq
,
24454 NULL
, xcalloc
, xfree
));
24456 ofs
.per_cu
= cu
->per_cu
;
24457 ofs
.sect_off
= die
->sect_off
;
24459 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24460 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24462 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24463 sect_offset_str (die
->sect_off
));
24464 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24465 struct dwarf2_per_cu_offset_and_type
);
24470 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24471 or return NULL if the die does not have a saved type. */
24473 static struct type
*
24474 get_die_type_at_offset (sect_offset sect_off
,
24475 struct dwarf2_per_cu_data
*per_cu
)
24477 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24478 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
24480 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24483 ofs
.per_cu
= per_cu
;
24484 ofs
.sect_off
= sect_off
;
24485 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24486 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
24493 /* Look up the type for DIE in CU in die_type_hash,
24494 or return NULL if DIE does not have a saved type. */
24496 static struct type
*
24497 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24499 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
24502 /* Add a dependence relationship from CU to REF_PER_CU. */
24505 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24506 struct dwarf2_per_cu_data
*ref_per_cu
)
24510 if (cu
->dependencies
== NULL
)
24512 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24513 NULL
, &cu
->comp_unit_obstack
,
24514 hashtab_obstack_allocate
,
24515 dummy_obstack_deallocate
);
24517 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24519 *slot
= ref_per_cu
;
24522 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24523 Set the mark field in every compilation unit in the
24524 cache that we must keep because we are keeping CU. */
24527 dwarf2_mark_helper (void **slot
, void *data
)
24529 struct dwarf2_per_cu_data
*per_cu
;
24531 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
24533 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24534 reading of the chain. As such dependencies remain valid it is not much
24535 useful to track and undo them during QUIT cleanups. */
24536 if (per_cu
->cu
== NULL
)
24539 if (per_cu
->cu
->mark
)
24541 per_cu
->cu
->mark
= true;
24543 if (per_cu
->cu
->dependencies
!= NULL
)
24544 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24549 /* Set the mark field in CU and in every other compilation unit in the
24550 cache that we must keep because we are keeping CU. */
24553 dwarf2_mark (struct dwarf2_cu
*cu
)
24558 if (cu
->dependencies
!= NULL
)
24559 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24563 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
24567 per_cu
->cu
->mark
= false;
24568 per_cu
= per_cu
->cu
->read_in_chain
;
24572 /* Trivial hash function for partial_die_info: the hash value of a DIE
24573 is its offset in .debug_info for this objfile. */
24576 partial_die_hash (const void *item
)
24578 const struct partial_die_info
*part_die
24579 = (const struct partial_die_info
*) item
;
24581 return to_underlying (part_die
->sect_off
);
24584 /* Trivial comparison function for partial_die_info structures: two DIEs
24585 are equal if they have the same offset. */
24588 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24590 const struct partial_die_info
*part_die_lhs
24591 = (const struct partial_die_info
*) item_lhs
;
24592 const struct partial_die_info
*part_die_rhs
24593 = (const struct partial_die_info
*) item_rhs
;
24595 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24598 struct cmd_list_element
*set_dwarf_cmdlist
;
24599 struct cmd_list_element
*show_dwarf_cmdlist
;
24602 set_dwarf_cmd (const char *args
, int from_tty
)
24604 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
24609 show_dwarf_cmd (const char *args
, int from_tty
)
24611 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
24615 show_check_physname (struct ui_file
*file
, int from_tty
,
24616 struct cmd_list_element
*c
, const char *value
)
24618 fprintf_filtered (file
,
24619 _("Whether to check \"physname\" is %s.\n"),
24623 void _initialize_dwarf2_read ();
24625 _initialize_dwarf2_read ()
24627 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24628 Set DWARF specific variables.\n\
24629 Configure DWARF variables such as the cache size."),
24630 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24631 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24633 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24634 Show DWARF specific variables.\n\
24635 Show DWARF variables such as the cache size."),
24636 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24637 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24639 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24640 &dwarf_max_cache_age
, _("\
24641 Set the upper bound on the age of cached DWARF compilation units."), _("\
24642 Show the upper bound on the age of cached DWARF compilation units."), _("\
24643 A higher limit means that cached compilation units will be stored\n\
24644 in memory longer, and more total memory will be used. Zero disables\n\
24645 caching, which can slow down startup."),
24647 show_dwarf_max_cache_age
,
24648 &set_dwarf_cmdlist
,
24649 &show_dwarf_cmdlist
);
24651 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24652 Set debugging of the DWARF reader."), _("\
24653 Show debugging of the DWARF reader."), _("\
24654 When enabled (non-zero), debugging messages are printed during DWARF\n\
24655 reading and symtab expansion. A value of 1 (one) provides basic\n\
24656 information. A value greater than 1 provides more verbose information."),
24659 &setdebuglist
, &showdebuglist
);
24661 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24662 Set debugging of the DWARF DIE reader."), _("\
24663 Show debugging of the DWARF DIE reader."), _("\
24664 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24665 The value is the maximum depth to print."),
24668 &setdebuglist
, &showdebuglist
);
24670 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24671 Set debugging of the dwarf line reader."), _("\
24672 Show debugging of the dwarf line reader."), _("\
24673 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24674 A value of 1 (one) provides basic information.\n\
24675 A value greater than 1 provides more verbose information."),
24678 &setdebuglist
, &showdebuglist
);
24680 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24681 Set cross-checking of \"physname\" code against demangler."), _("\
24682 Show cross-checking of \"physname\" code against demangler."), _("\
24683 When enabled, GDB's internal \"physname\" code is checked against\n\
24685 NULL
, show_check_physname
,
24686 &setdebuglist
, &showdebuglist
);
24688 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24689 no_class
, &use_deprecated_index_sections
, _("\
24690 Set whether to use deprecated gdb_index sections."), _("\
24691 Show whether to use deprecated gdb_index sections."), _("\
24692 When enabled, deprecated .gdb_index sections are used anyway.\n\
24693 Normally they are ignored either because of a missing feature or\n\
24694 performance issue.\n\
24695 Warning: This option must be enabled before gdb reads the file."),
24698 &setlist
, &showlist
);
24700 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24701 &dwarf2_locexpr_funcs
);
24702 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24703 &dwarf2_loclist_funcs
);
24705 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24706 &dwarf2_block_frame_base_locexpr_funcs
);
24707 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24708 &dwarf2_block_frame_base_loclist_funcs
);
24711 selftests::register_test ("dw2_expand_symtabs_matching",
24712 selftests::dw2_expand_symtabs_matching::run_test
);