1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
51 #include "gdb-demangle.h"
52 #include "filenames.h" /* for DOSish file names */
54 #include "complaints.h"
55 #include "dwarf2/expr.h"
56 #include "dwarf2/loc.h"
57 #include "cp-support.h"
63 #include "typeprint.h"
68 #include "gdbcore.h" /* for gnutarget */
69 #include "gdb/gdb-index.h"
74 #include "namespace.h"
75 #include "gdbsupport/function-view.h"
76 #include "gdbsupport/gdb_optional.h"
77 #include "gdbsupport/underlying.h"
78 #include "gdbsupport/hash_enum.h"
79 #include "filename-seen-cache.h"
83 #include <unordered_map>
84 #include "gdbsupport/selftest.h"
85 #include "rust-lang.h"
86 #include "gdbsupport/pathstuff.h"
87 #include "count-one-bits.h"
88 #include "debuginfod-support.h"
90 /* When == 1, print basic high level tracing messages.
91 When > 1, be more verbose.
92 This is in contrast to the low level DIE reading of dwarf_die_debug. */
93 static unsigned int dwarf_read_debug
= 0;
95 /* When non-zero, dump DIEs after they are read in. */
96 static unsigned int dwarf_die_debug
= 0;
98 /* When non-zero, dump line number entries as they are read in. */
99 unsigned int dwarf_line_debug
= 0;
101 /* When true, cross-check physname against demangler. */
102 static bool check_physname
= false;
104 /* When true, do not reject deprecated .gdb_index sections. */
105 static bool use_deprecated_index_sections
= false;
107 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
109 /* The "aclass" indices for various kinds of computed DWARF symbols. */
111 static int dwarf2_locexpr_index
;
112 static int dwarf2_loclist_index
;
113 static int dwarf2_locexpr_block_index
;
114 static int dwarf2_loclist_block_index
;
116 /* An index into a (C++) symbol name component in a symbol name as
117 recorded in the mapped_index's symbol table. For each C++ symbol
118 in the symbol table, we record one entry for the start of each
119 component in the symbol in a table of name components, and then
120 sort the table, in order to be able to binary search symbol names,
121 ignoring leading namespaces, both completion and regular look up.
122 For example, for symbol "A::B::C", we'll have an entry that points
123 to "A::B::C", another that points to "B::C", and another for "C".
124 Note that function symbols in GDB index have no parameter
125 information, just the function/method names. You can convert a
126 name_component to a "const char *" using the
127 'mapped_index::symbol_name_at(offset_type)' method. */
129 struct name_component
131 /* Offset in the symbol name where the component starts. Stored as
132 a (32-bit) offset instead of a pointer to save memory and improve
133 locality on 64-bit architectures. */
134 offset_type name_offset
;
136 /* The symbol's index in the symbol and constant pool tables of a
141 /* Base class containing bits shared by both .gdb_index and
142 .debug_name indexes. */
144 struct mapped_index_base
146 mapped_index_base () = default;
147 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
149 /* The name_component table (a sorted vector). See name_component's
150 description above. */
151 std::vector
<name_component
> name_components
;
153 /* How NAME_COMPONENTS is sorted. */
154 enum case_sensitivity name_components_casing
;
156 /* Return the number of names in the symbol table. */
157 virtual size_t symbol_name_count () const = 0;
159 /* Get the name of the symbol at IDX in the symbol table. */
160 virtual const char *symbol_name_at (offset_type idx
) const = 0;
162 /* Return whether the name at IDX in the symbol table should be
164 virtual bool symbol_name_slot_invalid (offset_type idx
) const
169 /* Build the symbol name component sorted vector, if we haven't
171 void build_name_components ();
173 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
174 possible matches for LN_NO_PARAMS in the name component
176 std::pair
<std::vector
<name_component
>::const_iterator
,
177 std::vector
<name_component
>::const_iterator
>
178 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
179 enum language lang
) const;
181 /* Prevent deleting/destroying via a base class pointer. */
183 ~mapped_index_base() = default;
186 /* A description of the mapped index. The file format is described in
187 a comment by the code that writes the index. */
188 struct mapped_index final
: public mapped_index_base
190 /* A slot/bucket in the symbol table hash. */
191 struct symbol_table_slot
193 const offset_type name
;
194 const offset_type vec
;
197 /* Index data format version. */
200 /* The address table data. */
201 gdb::array_view
<const gdb_byte
> address_table
;
203 /* The symbol table, implemented as a hash table. */
204 gdb::array_view
<symbol_table_slot
> symbol_table
;
206 /* A pointer to the constant pool. */
207 const char *constant_pool
= nullptr;
209 bool symbol_name_slot_invalid (offset_type idx
) const override
211 const auto &bucket
= this->symbol_table
[idx
];
212 return bucket
.name
== 0 && bucket
.vec
== 0;
215 /* Convenience method to get at the name of the symbol at IDX in the
217 const char *symbol_name_at (offset_type idx
) const override
218 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
220 size_t symbol_name_count () const override
221 { return this->symbol_table
.size (); }
224 /* A description of the mapped .debug_names.
225 Uninitialized map has CU_COUNT 0. */
226 struct mapped_debug_names final
: public mapped_index_base
228 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
229 : dwarf2_per_objfile (dwarf2_per_objfile_
)
232 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
233 bfd_endian dwarf5_byte_order
;
234 bool dwarf5_is_dwarf64
;
235 bool augmentation_is_gdb
;
237 uint32_t cu_count
= 0;
238 uint32_t tu_count
, bucket_count
, name_count
;
239 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
240 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
241 const gdb_byte
*name_table_string_offs_reordered
;
242 const gdb_byte
*name_table_entry_offs_reordered
;
243 const gdb_byte
*entry_pool
;
250 /* Attribute name DW_IDX_*. */
253 /* Attribute form DW_FORM_*. */
256 /* Value if FORM is DW_FORM_implicit_const. */
257 LONGEST implicit_const
;
259 std::vector
<attr
> attr_vec
;
262 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
264 const char *namei_to_name (uint32_t namei
) const;
266 /* Implementation of the mapped_index_base virtual interface, for
267 the name_components cache. */
269 const char *symbol_name_at (offset_type idx
) const override
270 { return namei_to_name (idx
); }
272 size_t symbol_name_count () const override
273 { return this->name_count
; }
276 /* See dwarf2read.h. */
279 get_dwarf2_per_objfile (struct objfile
*objfile
)
281 return dwarf2_objfile_data_key
.get (objfile
);
284 /* Default names of the debugging sections. */
286 /* Note that if the debugging section has been compressed, it might
287 have a name like .zdebug_info. */
289 static const struct dwarf2_debug_sections dwarf2_elf_names
=
291 { ".debug_info", ".zdebug_info" },
292 { ".debug_abbrev", ".zdebug_abbrev" },
293 { ".debug_line", ".zdebug_line" },
294 { ".debug_loc", ".zdebug_loc" },
295 { ".debug_loclists", ".zdebug_loclists" },
296 { ".debug_macinfo", ".zdebug_macinfo" },
297 { ".debug_macro", ".zdebug_macro" },
298 { ".debug_str", ".zdebug_str" },
299 { ".debug_str_offsets", ".zdebug_str_offsets" },
300 { ".debug_line_str", ".zdebug_line_str" },
301 { ".debug_ranges", ".zdebug_ranges" },
302 { ".debug_rnglists", ".zdebug_rnglists" },
303 { ".debug_types", ".zdebug_types" },
304 { ".debug_addr", ".zdebug_addr" },
305 { ".debug_frame", ".zdebug_frame" },
306 { ".eh_frame", NULL
},
307 { ".gdb_index", ".zgdb_index" },
308 { ".debug_names", ".zdebug_names" },
309 { ".debug_aranges", ".zdebug_aranges" },
313 /* List of DWO/DWP sections. */
315 static const struct dwop_section_names
317 struct dwarf2_section_names abbrev_dwo
;
318 struct dwarf2_section_names info_dwo
;
319 struct dwarf2_section_names line_dwo
;
320 struct dwarf2_section_names loc_dwo
;
321 struct dwarf2_section_names loclists_dwo
;
322 struct dwarf2_section_names macinfo_dwo
;
323 struct dwarf2_section_names macro_dwo
;
324 struct dwarf2_section_names str_dwo
;
325 struct dwarf2_section_names str_offsets_dwo
;
326 struct dwarf2_section_names types_dwo
;
327 struct dwarf2_section_names cu_index
;
328 struct dwarf2_section_names tu_index
;
332 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
333 { ".debug_info.dwo", ".zdebug_info.dwo" },
334 { ".debug_line.dwo", ".zdebug_line.dwo" },
335 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
336 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
337 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
338 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
339 { ".debug_str.dwo", ".zdebug_str.dwo" },
340 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
341 { ".debug_types.dwo", ".zdebug_types.dwo" },
342 { ".debug_cu_index", ".zdebug_cu_index" },
343 { ".debug_tu_index", ".zdebug_tu_index" },
346 /* local data types */
348 /* Type used for delaying computation of method physnames.
349 See comments for compute_delayed_physnames. */
350 struct delayed_method_info
352 /* The type to which the method is attached, i.e., its parent class. */
355 /* The index of the method in the type's function fieldlists. */
358 /* The index of the method in the fieldlist. */
361 /* The name of the DIE. */
364 /* The DIE associated with this method. */
365 struct die_info
*die
;
368 /* Internal state when decoding a particular compilation unit. */
371 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
374 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
376 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
377 Create the set of symtabs used by this TU, or if this TU is sharing
378 symtabs with another TU and the symtabs have already been created
379 then restore those symtabs in the line header.
380 We don't need the pc/line-number mapping for type units. */
381 void setup_type_unit_groups (struct die_info
*die
);
383 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
384 buildsym_compunit constructor. */
385 struct compunit_symtab
*start_symtab (const char *name
,
386 const char *comp_dir
,
389 /* Reset the builder. */
390 void reset_builder () { m_builder
.reset (); }
392 /* The header of the compilation unit. */
393 struct comp_unit_head header
{};
395 /* Base address of this compilation unit. */
396 gdb::optional
<CORE_ADDR
> base_address
;
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 struct dwarf2_per_cu_data per_cu
;
579 /* The TUs that share this DW_AT_stmt_list entry.
580 This is added to while parsing type units to build partial symtabs,
581 and is deleted afterwards and not used again. */
582 std::vector
<signatured_type
*> *tus
;
584 /* The compunit symtab.
585 Type units in a group needn't all be defined in the same source file,
586 so we create an essentially anonymous symtab as the compunit symtab. */
587 struct compunit_symtab
*compunit_symtab
;
589 /* The data used to construct the hash key. */
590 struct stmt_list_hash hash
;
592 /* The symbol tables for this TU (obtained from the files listed in
594 WARNING: The order of entries here must match the order of entries
595 in the line header. After the first TU using this type_unit_group, the
596 line header for the subsequent TUs is recreated from this. This is done
597 because we need to use the same symtabs for each TU using the same
598 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
599 there's no guarantee the line header doesn't have duplicate entries. */
600 struct symtab
**symtabs
;
603 /* These sections are what may appear in a (real or virtual) DWO file. */
607 struct dwarf2_section_info abbrev
;
608 struct dwarf2_section_info line
;
609 struct dwarf2_section_info loc
;
610 struct dwarf2_section_info loclists
;
611 struct dwarf2_section_info macinfo
;
612 struct dwarf2_section_info macro
;
613 struct dwarf2_section_info str
;
614 struct dwarf2_section_info str_offsets
;
615 /* In the case of a virtual DWO file, these two are unused. */
616 struct dwarf2_section_info info
;
617 std::vector
<dwarf2_section_info
> types
;
620 /* CUs/TUs in DWP/DWO files. */
624 /* Backlink to the containing struct dwo_file. */
625 struct dwo_file
*dwo_file
;
627 /* The "id" that distinguishes this CU/TU.
628 .debug_info calls this "dwo_id", .debug_types calls this "signature".
629 Since signatures came first, we stick with it for consistency. */
632 /* The section this CU/TU lives in, in the DWO file. */
633 struct dwarf2_section_info
*section
;
635 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
636 sect_offset sect_off
;
639 /* For types, offset in the type's DIE of the type defined by this TU. */
640 cu_offset type_offset_in_tu
;
643 /* include/dwarf2.h defines the DWP section codes.
644 It defines a max value but it doesn't define a min value, which we
645 use for error checking, so provide one. */
647 enum dwp_v2_section_ids
652 /* Data for one DWO file.
654 This includes virtual DWO files (a virtual DWO file is a DWO file as it
655 appears in a DWP file). DWP files don't really have DWO files per se -
656 comdat folding of types "loses" the DWO file they came from, and from
657 a high level view DWP files appear to contain a mass of random types.
658 However, to maintain consistency with the non-DWP case we pretend DWP
659 files contain virtual DWO files, and we assign each TU with one virtual
660 DWO file (generally based on the line and abbrev section offsets -
661 a heuristic that seems to work in practice). */
665 dwo_file () = default;
666 DISABLE_COPY_AND_ASSIGN (dwo_file
);
668 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
669 For virtual DWO files the name is constructed from the section offsets
670 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
671 from related CU+TUs. */
672 const char *dwo_name
= nullptr;
674 /* The DW_AT_comp_dir attribute. */
675 const char *comp_dir
= nullptr;
677 /* The bfd, when the file is open. Otherwise this is NULL.
678 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
679 gdb_bfd_ref_ptr dbfd
;
681 /* The sections that make up this DWO file.
682 Remember that for virtual DWO files in DWP V2, these are virtual
683 sections (for lack of a better name). */
684 struct dwo_sections sections
{};
686 /* The CUs in the file.
687 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
688 an extension to handle LLVM's Link Time Optimization output (where
689 multiple source files may be compiled into a single object/dwo pair). */
692 /* Table of TUs in the file.
693 Each element is a struct dwo_unit. */
697 /* These sections are what may appear in a DWP file. */
701 /* These are used by both DWP version 1 and 2. */
702 struct dwarf2_section_info str
;
703 struct dwarf2_section_info cu_index
;
704 struct dwarf2_section_info tu_index
;
706 /* These are only used by DWP version 2 files.
707 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
708 sections are referenced by section number, and are not recorded here.
709 In DWP version 2 there is at most one copy of all these sections, each
710 section being (effectively) comprised of the concatenation of all of the
711 individual sections that exist in the version 1 format.
712 To keep the code simple we treat each of these concatenated pieces as a
713 section itself (a virtual section?). */
714 struct dwarf2_section_info abbrev
;
715 struct dwarf2_section_info info
;
716 struct dwarf2_section_info line
;
717 struct dwarf2_section_info loc
;
718 struct dwarf2_section_info macinfo
;
719 struct dwarf2_section_info macro
;
720 struct dwarf2_section_info str_offsets
;
721 struct dwarf2_section_info types
;
724 /* These sections are what may appear in a virtual DWO file in DWP version 1.
725 A virtual DWO file is a DWO file as it appears in a DWP file. */
727 struct virtual_v1_dwo_sections
729 struct dwarf2_section_info abbrev
;
730 struct dwarf2_section_info line
;
731 struct dwarf2_section_info loc
;
732 struct dwarf2_section_info macinfo
;
733 struct dwarf2_section_info macro
;
734 struct dwarf2_section_info str_offsets
;
735 /* Each DWP hash table entry records one CU or one TU.
736 That is recorded here, and copied to dwo_unit.section. */
737 struct dwarf2_section_info info_or_types
;
740 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
741 In version 2, the sections of the DWO files are concatenated together
742 and stored in one section of that name. Thus each ELF section contains
743 several "virtual" sections. */
745 struct virtual_v2_dwo_sections
747 bfd_size_type abbrev_offset
;
748 bfd_size_type abbrev_size
;
750 bfd_size_type line_offset
;
751 bfd_size_type line_size
;
753 bfd_size_type loc_offset
;
754 bfd_size_type loc_size
;
756 bfd_size_type macinfo_offset
;
757 bfd_size_type macinfo_size
;
759 bfd_size_type macro_offset
;
760 bfd_size_type macro_size
;
762 bfd_size_type str_offsets_offset
;
763 bfd_size_type str_offsets_size
;
765 /* Each DWP hash table entry records one CU or one TU.
766 That is recorded here, and copied to dwo_unit.section. */
767 bfd_size_type info_or_types_offset
;
768 bfd_size_type info_or_types_size
;
771 /* Contents of DWP hash tables. */
773 struct dwp_hash_table
775 uint32_t version
, nr_columns
;
776 uint32_t nr_units
, nr_slots
;
777 const gdb_byte
*hash_table
, *unit_table
;
782 const gdb_byte
*indices
;
786 /* This is indexed by column number and gives the id of the section
788 #define MAX_NR_V2_DWO_SECTIONS \
789 (1 /* .debug_info or .debug_types */ \
790 + 1 /* .debug_abbrev */ \
791 + 1 /* .debug_line */ \
792 + 1 /* .debug_loc */ \
793 + 1 /* .debug_str_offsets */ \
794 + 1 /* .debug_macro or .debug_macinfo */)
795 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
796 const gdb_byte
*offsets
;
797 const gdb_byte
*sizes
;
802 /* Data for one DWP file. */
806 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
808 dbfd (std::move (abfd
))
812 /* Name of the file. */
815 /* File format version. */
819 gdb_bfd_ref_ptr dbfd
;
821 /* Section info for this file. */
822 struct dwp_sections sections
{};
824 /* Table of CUs in the file. */
825 const struct dwp_hash_table
*cus
= nullptr;
827 /* Table of TUs in the file. */
828 const struct dwp_hash_table
*tus
= nullptr;
830 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
834 /* Table to map ELF section numbers to their sections.
835 This is only needed for the DWP V1 file format. */
836 unsigned int num_sections
= 0;
837 asection
**elf_sections
= nullptr;
840 /* Struct used to pass misc. parameters to read_die_and_children, et
841 al. which are used for both .debug_info and .debug_types dies.
842 All parameters here are unchanging for the life of the call. This
843 struct exists to abstract away the constant parameters of die reading. */
845 struct die_reader_specs
847 /* The bfd of die_section. */
850 /* The CU of the DIE we are parsing. */
851 struct dwarf2_cu
*cu
;
853 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
854 struct dwo_file
*dwo_file
;
856 /* The section the die comes from.
857 This is either .debug_info or .debug_types, or the .dwo variants. */
858 struct dwarf2_section_info
*die_section
;
860 /* die_section->buffer. */
861 const gdb_byte
*buffer
;
863 /* The end of the buffer. */
864 const gdb_byte
*buffer_end
;
866 /* The abbreviation table to use when reading the DIEs. */
867 struct abbrev_table
*abbrev_table
;
870 /* A subclass of die_reader_specs that holds storage and has complex
871 constructor and destructor behavior. */
873 class cutu_reader
: public die_reader_specs
877 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
878 struct abbrev_table
*abbrev_table
,
882 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
883 struct dwarf2_cu
*parent_cu
= nullptr,
884 struct dwo_file
*dwo_file
= nullptr);
886 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
888 const gdb_byte
*info_ptr
= nullptr;
889 struct die_info
*comp_unit_die
= nullptr;
890 bool dummy_p
= false;
892 /* Release the new CU, putting it on the chain. This cannot be done
897 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
898 int use_existing_cu
);
900 struct dwarf2_per_cu_data
*m_this_cu
;
901 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
903 /* The ordinary abbreviation table. */
904 abbrev_table_up m_abbrev_table_holder
;
906 /* The DWO abbreviation table. */
907 abbrev_table_up m_dwo_abbrev_table
;
910 /* When we construct a partial symbol table entry we only
911 need this much information. */
912 struct partial_die_info
: public allocate_on_obstack
914 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
916 /* Disable assign but still keep copy ctor, which is needed
917 load_partial_dies. */
918 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
920 /* Adjust the partial die before generating a symbol for it. This
921 function may set the is_external flag or change the DIE's
923 void fixup (struct dwarf2_cu
*cu
);
925 /* Read a minimal amount of information into the minimal die
927 const gdb_byte
*read (const struct die_reader_specs
*reader
,
928 const struct abbrev_info
&abbrev
,
929 const gdb_byte
*info_ptr
);
931 /* Offset of this DIE. */
932 const sect_offset sect_off
;
934 /* DWARF-2 tag for this DIE. */
935 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
937 /* Assorted flags describing the data found in this DIE. */
938 const unsigned int has_children
: 1;
940 unsigned int is_external
: 1;
941 unsigned int is_declaration
: 1;
942 unsigned int has_type
: 1;
943 unsigned int has_specification
: 1;
944 unsigned int has_pc_info
: 1;
945 unsigned int may_be_inlined
: 1;
947 /* This DIE has been marked DW_AT_main_subprogram. */
948 unsigned int main_subprogram
: 1;
950 /* Flag set if the SCOPE field of this structure has been
952 unsigned int scope_set
: 1;
954 /* Flag set if the DIE has a byte_size attribute. */
955 unsigned int has_byte_size
: 1;
957 /* Flag set if the DIE has a DW_AT_const_value attribute. */
958 unsigned int has_const_value
: 1;
960 /* Flag set if any of the DIE's children are template arguments. */
961 unsigned int has_template_arguments
: 1;
963 /* Flag set if fixup has been called on this die. */
964 unsigned int fixup_called
: 1;
966 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
967 unsigned int is_dwz
: 1;
969 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
970 unsigned int spec_is_dwz
: 1;
972 /* The name of this DIE. Normally the value of DW_AT_name, but
973 sometimes a default name for unnamed DIEs. */
974 const char *name
= nullptr;
976 /* The linkage name, if present. */
977 const char *linkage_name
= nullptr;
979 /* The scope to prepend to our children. This is generally
980 allocated on the comp_unit_obstack, so will disappear
981 when this compilation unit leaves the cache. */
982 const char *scope
= nullptr;
984 /* Some data associated with the partial DIE. The tag determines
985 which field is live. */
988 /* The location description associated with this DIE, if any. */
989 struct dwarf_block
*locdesc
;
990 /* The offset of an import, for DW_TAG_imported_unit. */
991 sect_offset sect_off
;
994 /* If HAS_PC_INFO, the PC range associated with this DIE. */
996 CORE_ADDR highpc
= 0;
998 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
999 DW_AT_sibling, if any. */
1000 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1001 could return DW_AT_sibling values to its caller load_partial_dies. */
1002 const gdb_byte
*sibling
= nullptr;
1004 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1005 DW_AT_specification (or DW_AT_abstract_origin or
1006 DW_AT_extension). */
1007 sect_offset spec_offset
{};
1009 /* Pointers to this DIE's parent, first child, and next sibling,
1011 struct partial_die_info
*die_parent
= nullptr;
1012 struct partial_die_info
*die_child
= nullptr;
1013 struct partial_die_info
*die_sibling
= nullptr;
1015 friend struct partial_die_info
*
1016 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1019 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1020 partial_die_info (sect_offset sect_off
)
1021 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1025 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1027 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1032 has_specification
= 0;
1035 main_subprogram
= 0;
1038 has_const_value
= 0;
1039 has_template_arguments
= 0;
1046 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1047 but this would require a corresponding change in unpack_field_as_long
1049 static int bits_per_byte
= 8;
1051 /* When reading a variant or variant part, we track a bit more
1052 information about the field, and store it in an object of this
1055 struct variant_field
1057 /* If we see a DW_TAG_variant, then this will be the discriminant
1059 ULONGEST discriminant_value
;
1060 /* If we see a DW_TAG_variant, then this will be set if this is the
1062 bool default_branch
;
1063 /* While reading a DW_TAG_variant_part, this will be set if this
1064 field is the discriminant. */
1065 bool is_discriminant
;
1070 int accessibility
= 0;
1072 /* Extra information to describe a variant or variant part. */
1073 struct variant_field variant
{};
1074 struct field field
{};
1079 const char *name
= nullptr;
1080 std::vector
<struct fn_field
> fnfields
;
1083 /* The routines that read and process dies for a C struct or C++ class
1084 pass lists of data member fields and lists of member function fields
1085 in an instance of a field_info structure, as defined below. */
1088 /* List of data member and baseclasses fields. */
1089 std::vector
<struct nextfield
> fields
;
1090 std::vector
<struct nextfield
> baseclasses
;
1092 /* Set if the accessibility of one of the fields is not public. */
1093 int non_public_fields
= 0;
1095 /* Member function fieldlist array, contains name of possibly overloaded
1096 member function, number of overloaded member functions and a pointer
1097 to the head of the member function field chain. */
1098 std::vector
<struct fnfieldlist
> fnfieldlists
;
1100 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1101 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1102 std::vector
<struct decl_field
> typedef_field_list
;
1104 /* Nested types defined by this class and the number of elements in this
1106 std::vector
<struct decl_field
> nested_types_list
;
1108 /* Return the total number of fields (including baseclasses). */
1109 int nfields () const
1111 return fields
.size () + baseclasses
.size ();
1115 /* Loaded secondary compilation units are kept in memory until they
1116 have not been referenced for the processing of this many
1117 compilation units. Set this to zero to disable caching. Cache
1118 sizes of up to at least twenty will improve startup time for
1119 typical inter-CU-reference binaries, at an obvious memory cost. */
1120 static int dwarf_max_cache_age
= 5;
1122 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1123 struct cmd_list_element
*c
, const char *value
)
1125 fprintf_filtered (file
, _("The upper bound on the age of cached "
1126 "DWARF compilation units is %s.\n"),
1130 /* local function prototypes */
1132 static void dwarf2_find_base_address (struct die_info
*die
,
1133 struct dwarf2_cu
*cu
);
1135 static dwarf2_psymtab
*create_partial_symtab
1136 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1138 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1139 const gdb_byte
*info_ptr
,
1140 struct die_info
*type_unit_die
);
1142 static void dwarf2_build_psymtabs_hard
1143 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1145 static void scan_partial_symbols (struct partial_die_info
*,
1146 CORE_ADDR
*, CORE_ADDR
*,
1147 int, struct dwarf2_cu
*);
1149 static void add_partial_symbol (struct partial_die_info
*,
1150 struct dwarf2_cu
*);
1152 static void add_partial_namespace (struct partial_die_info
*pdi
,
1153 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1154 int set_addrmap
, struct dwarf2_cu
*cu
);
1156 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1157 CORE_ADDR
*highpc
, int set_addrmap
,
1158 struct dwarf2_cu
*cu
);
1160 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1161 struct dwarf2_cu
*cu
);
1163 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1164 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1165 int need_pc
, struct dwarf2_cu
*cu
);
1167 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1169 static struct partial_die_info
*load_partial_dies
1170 (const struct die_reader_specs
*, const gdb_byte
*, int);
1172 /* A pair of partial_die_info and compilation unit. */
1173 struct cu_partial_die_info
1175 /* The compilation unit of the partial_die_info. */
1176 struct dwarf2_cu
*cu
;
1177 /* A partial_die_info. */
1178 struct partial_die_info
*pdi
;
1180 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1186 cu_partial_die_info () = delete;
1189 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1190 struct dwarf2_cu
*);
1192 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1193 struct attribute
*, struct attr_abbrev
*,
1194 const gdb_byte
*, bool *need_reprocess
);
1196 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1197 struct attribute
*attr
);
1199 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1201 static sect_offset read_abbrev_offset
1202 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1203 struct dwarf2_section_info
*, sect_offset
);
1205 static const char *read_indirect_string
1206 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1207 const struct comp_unit_head
*, unsigned int *);
1209 static const char *read_indirect_string_at_offset
1210 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1212 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1216 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1217 ULONGEST str_index
);
1219 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1220 ULONGEST str_index
);
1222 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1224 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1225 struct dwarf2_cu
*);
1227 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1228 struct dwarf2_cu
*cu
);
1230 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1232 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1233 struct dwarf2_cu
*cu
);
1235 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1237 static struct die_info
*die_specification (struct die_info
*die
,
1238 struct dwarf2_cu
**);
1240 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1241 struct dwarf2_cu
*cu
);
1243 static void dwarf_decode_lines (struct line_header
*, const char *,
1244 struct dwarf2_cu
*, dwarf2_psymtab
*,
1245 CORE_ADDR
, int decode_mapping
);
1247 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1250 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1251 struct dwarf2_cu
*, struct symbol
* = NULL
);
1253 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1254 struct dwarf2_cu
*);
1256 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1259 struct obstack
*obstack
,
1260 struct dwarf2_cu
*cu
, LONGEST
*value
,
1261 const gdb_byte
**bytes
,
1262 struct dwarf2_locexpr_baton
**baton
);
1264 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1266 static int need_gnat_info (struct dwarf2_cu
*);
1268 static struct type
*die_descriptive_type (struct die_info
*,
1269 struct dwarf2_cu
*);
1271 static void set_descriptive_type (struct type
*, struct die_info
*,
1272 struct dwarf2_cu
*);
1274 static struct type
*die_containing_type (struct die_info
*,
1275 struct dwarf2_cu
*);
1277 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1278 struct dwarf2_cu
*);
1280 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1282 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1284 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1286 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1287 const char *suffix
, int physname
,
1288 struct dwarf2_cu
*cu
);
1290 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1292 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1294 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1296 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1298 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1300 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1302 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1303 struct dwarf2_cu
*, dwarf2_psymtab
*);
1305 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1306 values. Keep the items ordered with increasing constraints compliance. */
1309 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1310 PC_BOUNDS_NOT_PRESENT
,
1312 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1313 were present but they do not form a valid range of PC addresses. */
1316 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1319 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1323 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1324 CORE_ADDR
*, CORE_ADDR
*,
1328 static void get_scope_pc_bounds (struct die_info
*,
1329 CORE_ADDR
*, CORE_ADDR
*,
1330 struct dwarf2_cu
*);
1332 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1333 CORE_ADDR
, struct dwarf2_cu
*);
1335 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1336 struct dwarf2_cu
*);
1338 static void dwarf2_attach_fields_to_type (struct field_info
*,
1339 struct type
*, struct dwarf2_cu
*);
1341 static void dwarf2_add_member_fn (struct field_info
*,
1342 struct die_info
*, struct type
*,
1343 struct dwarf2_cu
*);
1345 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1347 struct dwarf2_cu
*);
1349 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1351 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1353 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1355 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1357 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1359 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1361 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1363 static struct type
*read_module_type (struct die_info
*die
,
1364 struct dwarf2_cu
*cu
);
1366 static const char *namespace_name (struct die_info
*die
,
1367 int *is_anonymous
, struct dwarf2_cu
*);
1369 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1371 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1373 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1374 struct dwarf2_cu
*);
1376 static struct die_info
*read_die_and_siblings_1
1377 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1380 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1381 const gdb_byte
*info_ptr
,
1382 const gdb_byte
**new_info_ptr
,
1383 struct die_info
*parent
);
1385 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1386 struct die_info
**, const gdb_byte
*,
1389 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1390 struct die_info
**, const gdb_byte
*);
1392 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1394 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1397 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1399 static const char *dwarf2_full_name (const char *name
,
1400 struct die_info
*die
,
1401 struct dwarf2_cu
*cu
);
1403 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1404 struct dwarf2_cu
*cu
);
1406 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1407 struct dwarf2_cu
**);
1409 static const char *dwarf_tag_name (unsigned int);
1411 static const char *dwarf_attr_name (unsigned int);
1413 static const char *dwarf_form_name (unsigned int);
1415 static const char *dwarf_bool_name (unsigned int);
1417 static const char *dwarf_type_encoding_name (unsigned int);
1419 static struct die_info
*sibling_die (struct die_info
*);
1421 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1423 static void dump_die_for_error (struct die_info
*);
1425 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1428 /*static*/ void dump_die (struct die_info
*, int max_level
);
1430 static void store_in_ref_table (struct die_info
*,
1431 struct dwarf2_cu
*);
1433 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1435 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1437 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1438 const struct attribute
*,
1439 struct dwarf2_cu
**);
1441 static struct die_info
*follow_die_ref (struct die_info
*,
1442 const struct attribute
*,
1443 struct dwarf2_cu
**);
1445 static struct die_info
*follow_die_sig (struct die_info
*,
1446 const struct attribute
*,
1447 struct dwarf2_cu
**);
1449 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1450 struct dwarf2_cu
*);
1452 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1453 const struct attribute
*,
1454 struct dwarf2_cu
*);
1456 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1458 static void read_signatured_type (struct signatured_type
*);
1460 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1461 struct die_info
*die
, struct dwarf2_cu
*cu
,
1462 struct dynamic_prop
*prop
, struct type
*type
);
1464 /* memory allocation interface */
1466 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1468 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1470 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1472 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1473 struct dwarf2_loclist_baton
*baton
,
1474 const struct attribute
*attr
);
1476 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1478 struct dwarf2_cu
*cu
,
1481 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1482 const gdb_byte
*info_ptr
,
1483 struct abbrev_info
*abbrev
);
1485 static hashval_t
partial_die_hash (const void *item
);
1487 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1489 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1490 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1491 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1493 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1494 struct die_info
*comp_unit_die
,
1495 enum language pretend_language
);
1497 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1499 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1501 static struct type
*set_die_type (struct die_info
*, struct type
*,
1502 struct dwarf2_cu
*);
1504 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1506 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1508 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1511 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1514 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1517 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1518 struct dwarf2_per_cu_data
*);
1520 static void dwarf2_mark (struct dwarf2_cu
*);
1522 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1524 static struct type
*get_die_type_at_offset (sect_offset
,
1525 struct dwarf2_per_cu_data
*);
1527 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1529 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1530 enum language pretend_language
);
1532 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1534 /* Class, the destructor of which frees all allocated queue entries. This
1535 will only have work to do if an error was thrown while processing the
1536 dwarf. If no error was thrown then the queue entries should have all
1537 been processed, and freed, as we went along. */
1539 class dwarf2_queue_guard
1542 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1543 : m_per_objfile (per_objfile
)
1547 /* Free any entries remaining on the queue. There should only be
1548 entries left if we hit an error while processing the dwarf. */
1549 ~dwarf2_queue_guard ()
1551 /* Ensure that no memory is allocated by the queue. */
1552 std::queue
<dwarf2_queue_item
> empty
;
1553 std::swap (m_per_objfile
->queue
, empty
);
1556 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1559 dwarf2_per_objfile
*m_per_objfile
;
1562 dwarf2_queue_item::~dwarf2_queue_item ()
1564 /* Anything still marked queued is likely to be in an
1565 inconsistent state, so discard it. */
1568 if (per_cu
->cu
!= NULL
)
1569 free_one_cached_comp_unit (per_cu
);
1574 /* The return type of find_file_and_directory. Note, the enclosed
1575 string pointers are only valid while this object is valid. */
1577 struct file_and_directory
1579 /* The filename. This is never NULL. */
1582 /* The compilation directory. NULL if not known. If we needed to
1583 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1584 points directly to the DW_AT_comp_dir string attribute owned by
1585 the obstack that owns the DIE. */
1586 const char *comp_dir
;
1588 /* If we needed to build a new string for comp_dir, this is what
1589 owns the storage. */
1590 std::string comp_dir_storage
;
1593 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1594 struct dwarf2_cu
*cu
);
1596 static htab_up
allocate_signatured_type_table ();
1598 static htab_up
allocate_dwo_unit_table ();
1600 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1601 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1602 struct dwp_file
*dwp_file
, const char *comp_dir
,
1603 ULONGEST signature
, int is_debug_types
);
1605 static struct dwp_file
*get_dwp_file
1606 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1608 static struct dwo_unit
*lookup_dwo_comp_unit
1609 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1611 static struct dwo_unit
*lookup_dwo_type_unit
1612 (struct signatured_type
*, const char *, const char *);
1614 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1616 /* A unique pointer to a dwo_file. */
1618 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1620 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1622 static void check_producer (struct dwarf2_cu
*cu
);
1624 static void free_line_header_voidp (void *arg
);
1626 /* Various complaints about symbol reading that don't abort the process. */
1629 dwarf2_debug_line_missing_file_complaint (void)
1631 complaint (_(".debug_line section has line data without a file"));
1635 dwarf2_debug_line_missing_end_sequence_complaint (void)
1637 complaint (_(".debug_line section has line "
1638 "program sequence without an end"));
1642 dwarf2_complex_location_expr_complaint (void)
1644 complaint (_("location expression too complex"));
1648 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1651 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1656 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1658 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1662 /* Hash function for line_header_hash. */
1665 line_header_hash (const struct line_header
*ofs
)
1667 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1670 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1673 line_header_hash_voidp (const void *item
)
1675 const struct line_header
*ofs
= (const struct line_header
*) item
;
1677 return line_header_hash (ofs
);
1680 /* Equality function for line_header_hash. */
1683 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1685 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1686 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1688 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1689 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1694 /* See declaration. */
1696 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1697 const dwarf2_debug_sections
*names
,
1699 : objfile (objfile_
),
1700 can_copy (can_copy_
)
1703 names
= &dwarf2_elf_names
;
1705 bfd
*obfd
= objfile
->obfd
;
1707 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1708 locate_sections (obfd
, sec
, *names
);
1711 dwarf2_per_objfile::~dwarf2_per_objfile ()
1713 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1714 free_cached_comp_units ();
1716 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1717 per_cu
->imported_symtabs_free ();
1719 for (signatured_type
*sig_type
: all_type_units
)
1720 sig_type
->per_cu
.imported_symtabs_free ();
1722 /* Everything else should be on the objfile obstack. */
1725 /* See declaration. */
1728 dwarf2_per_objfile::free_cached_comp_units ()
1730 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1731 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1732 while (per_cu
!= NULL
)
1734 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1737 *last_chain
= next_cu
;
1742 /* A helper class that calls free_cached_comp_units on
1745 class free_cached_comp_units
1749 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1750 : m_per_objfile (per_objfile
)
1754 ~free_cached_comp_units ()
1756 m_per_objfile
->free_cached_comp_units ();
1759 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1763 dwarf2_per_objfile
*m_per_objfile
;
1766 /* Try to locate the sections we need for DWARF 2 debugging
1767 information and return true if we have enough to do something.
1768 NAMES points to the dwarf2 section names, or is NULL if the standard
1769 ELF names are used. CAN_COPY is true for formats where symbol
1770 interposition is possible and so symbol values must follow copy
1771 relocation rules. */
1774 dwarf2_has_info (struct objfile
*objfile
,
1775 const struct dwarf2_debug_sections
*names
,
1778 if (objfile
->flags
& OBJF_READNEVER
)
1781 struct dwarf2_per_objfile
*dwarf2_per_objfile
1782 = get_dwarf2_per_objfile (objfile
);
1784 if (dwarf2_per_objfile
== NULL
)
1785 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1789 return (!dwarf2_per_objfile
->info
.is_virtual
1790 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1791 && !dwarf2_per_objfile
->abbrev
.is_virtual
1792 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1795 /* When loading sections, we look either for uncompressed section or for
1796 compressed section names. */
1799 section_is_p (const char *section_name
,
1800 const struct dwarf2_section_names
*names
)
1802 if (names
->normal
!= NULL
1803 && strcmp (section_name
, names
->normal
) == 0)
1805 if (names
->compressed
!= NULL
1806 && strcmp (section_name
, names
->compressed
) == 0)
1811 /* See declaration. */
1814 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1815 const dwarf2_debug_sections
&names
)
1817 flagword aflag
= bfd_section_flags (sectp
);
1819 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1822 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1823 > bfd_get_file_size (abfd
))
1825 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1826 warning (_("Discarding section %s which has a section size (%s"
1827 ") larger than the file size [in module %s]"),
1828 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1829 bfd_get_filename (abfd
));
1831 else if (section_is_p (sectp
->name
, &names
.info
))
1833 this->info
.s
.section
= sectp
;
1834 this->info
.size
= bfd_section_size (sectp
);
1836 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1838 this->abbrev
.s
.section
= sectp
;
1839 this->abbrev
.size
= bfd_section_size (sectp
);
1841 else if (section_is_p (sectp
->name
, &names
.line
))
1843 this->line
.s
.section
= sectp
;
1844 this->line
.size
= bfd_section_size (sectp
);
1846 else if (section_is_p (sectp
->name
, &names
.loc
))
1848 this->loc
.s
.section
= sectp
;
1849 this->loc
.size
= bfd_section_size (sectp
);
1851 else if (section_is_p (sectp
->name
, &names
.loclists
))
1853 this->loclists
.s
.section
= sectp
;
1854 this->loclists
.size
= bfd_section_size (sectp
);
1856 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1858 this->macinfo
.s
.section
= sectp
;
1859 this->macinfo
.size
= bfd_section_size (sectp
);
1861 else if (section_is_p (sectp
->name
, &names
.macro
))
1863 this->macro
.s
.section
= sectp
;
1864 this->macro
.size
= bfd_section_size (sectp
);
1866 else if (section_is_p (sectp
->name
, &names
.str
))
1868 this->str
.s
.section
= sectp
;
1869 this->str
.size
= bfd_section_size (sectp
);
1871 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1873 this->str_offsets
.s
.section
= sectp
;
1874 this->str_offsets
.size
= bfd_section_size (sectp
);
1876 else if (section_is_p (sectp
->name
, &names
.line_str
))
1878 this->line_str
.s
.section
= sectp
;
1879 this->line_str
.size
= bfd_section_size (sectp
);
1881 else if (section_is_p (sectp
->name
, &names
.addr
))
1883 this->addr
.s
.section
= sectp
;
1884 this->addr
.size
= bfd_section_size (sectp
);
1886 else if (section_is_p (sectp
->name
, &names
.frame
))
1888 this->frame
.s
.section
= sectp
;
1889 this->frame
.size
= bfd_section_size (sectp
);
1891 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1893 this->eh_frame
.s
.section
= sectp
;
1894 this->eh_frame
.size
= bfd_section_size (sectp
);
1896 else if (section_is_p (sectp
->name
, &names
.ranges
))
1898 this->ranges
.s
.section
= sectp
;
1899 this->ranges
.size
= bfd_section_size (sectp
);
1901 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1903 this->rnglists
.s
.section
= sectp
;
1904 this->rnglists
.size
= bfd_section_size (sectp
);
1906 else if (section_is_p (sectp
->name
, &names
.types
))
1908 struct dwarf2_section_info type_section
;
1910 memset (&type_section
, 0, sizeof (type_section
));
1911 type_section
.s
.section
= sectp
;
1912 type_section
.size
= bfd_section_size (sectp
);
1914 this->types
.push_back (type_section
);
1916 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1918 this->gdb_index
.s
.section
= sectp
;
1919 this->gdb_index
.size
= bfd_section_size (sectp
);
1921 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1923 this->debug_names
.s
.section
= sectp
;
1924 this->debug_names
.size
= bfd_section_size (sectp
);
1926 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1928 this->debug_aranges
.s
.section
= sectp
;
1929 this->debug_aranges
.size
= bfd_section_size (sectp
);
1932 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1933 && bfd_section_vma (sectp
) == 0)
1934 this->has_section_at_zero
= true;
1937 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1941 dwarf2_get_section_info (struct objfile
*objfile
,
1942 enum dwarf2_section_enum sect
,
1943 asection
**sectp
, const gdb_byte
**bufp
,
1944 bfd_size_type
*sizep
)
1946 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
1947 struct dwarf2_section_info
*info
;
1949 /* We may see an objfile without any DWARF, in which case we just
1960 case DWARF2_DEBUG_FRAME
:
1961 info
= &data
->frame
;
1963 case DWARF2_EH_FRAME
:
1964 info
= &data
->eh_frame
;
1967 gdb_assert_not_reached ("unexpected section");
1970 info
->read (objfile
);
1972 *sectp
= info
->get_bfd_section ();
1973 *bufp
= info
->buffer
;
1974 *sizep
= info
->size
;
1977 /* A helper function to find the sections for a .dwz file. */
1980 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
1982 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
1984 /* Note that we only support the standard ELF names, because .dwz
1985 is ELF-only (at the time of writing). */
1986 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
1988 dwz_file
->abbrev
.s
.section
= sectp
;
1989 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
1991 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
1993 dwz_file
->info
.s
.section
= sectp
;
1994 dwz_file
->info
.size
= bfd_section_size (sectp
);
1996 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
1998 dwz_file
->str
.s
.section
= sectp
;
1999 dwz_file
->str
.size
= bfd_section_size (sectp
);
2001 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2003 dwz_file
->line
.s
.section
= sectp
;
2004 dwz_file
->line
.size
= bfd_section_size (sectp
);
2006 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2008 dwz_file
->macro
.s
.section
= sectp
;
2009 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2011 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2013 dwz_file
->gdb_index
.s
.section
= sectp
;
2014 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2016 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2018 dwz_file
->debug_names
.s
.section
= sectp
;
2019 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2023 /* See dwarf2read.h. */
2026 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2028 const char *filename
;
2029 bfd_size_type buildid_len_arg
;
2033 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2034 return dwarf2_per_objfile
->dwz_file
.get ();
2036 bfd_set_error (bfd_error_no_error
);
2037 gdb::unique_xmalloc_ptr
<char> data
2038 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2039 &buildid_len_arg
, &buildid
));
2042 if (bfd_get_error () == bfd_error_no_error
)
2044 error (_("could not read '.gnu_debugaltlink' section: %s"),
2045 bfd_errmsg (bfd_get_error ()));
2048 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2050 buildid_len
= (size_t) buildid_len_arg
;
2052 filename
= data
.get ();
2054 std::string abs_storage
;
2055 if (!IS_ABSOLUTE_PATH (filename
))
2057 gdb::unique_xmalloc_ptr
<char> abs
2058 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2060 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2061 filename
= abs_storage
.c_str ();
2064 /* First try the file name given in the section. If that doesn't
2065 work, try to use the build-id instead. */
2066 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2067 if (dwz_bfd
!= NULL
)
2069 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2070 dwz_bfd
.reset (nullptr);
2073 if (dwz_bfd
== NULL
)
2074 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2076 if (dwz_bfd
== nullptr)
2078 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2079 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2081 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2088 /* File successfully retrieved from server. */
2089 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2091 if (dwz_bfd
== nullptr)
2092 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2093 alt_filename
.get ());
2094 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2095 dwz_bfd
.reset (nullptr);
2099 if (dwz_bfd
== NULL
)
2100 error (_("could not find '.gnu_debugaltlink' file for %s"),
2101 objfile_name (dwarf2_per_objfile
->objfile
));
2103 std::unique_ptr
<struct dwz_file
> result
2104 (new struct dwz_file (std::move (dwz_bfd
)));
2106 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2109 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2110 result
->dwz_bfd
.get ());
2111 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2112 return dwarf2_per_objfile
->dwz_file
.get ();
2115 /* DWARF quick_symbols_functions support. */
2117 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2118 unique line tables, so we maintain a separate table of all .debug_line
2119 derived entries to support the sharing.
2120 All the quick functions need is the list of file names. We discard the
2121 line_header when we're done and don't need to record it here. */
2122 struct quick_file_names
2124 /* The data used to construct the hash key. */
2125 struct stmt_list_hash hash
;
2127 /* The number of entries in file_names, real_names. */
2128 unsigned int num_file_names
;
2130 /* The file names from the line table, after being run through
2132 const char **file_names
;
2134 /* The file names from the line table after being run through
2135 gdb_realpath. These are computed lazily. */
2136 const char **real_names
;
2139 /* When using the index (and thus not using psymtabs), each CU has an
2140 object of this type. This is used to hold information needed by
2141 the various "quick" methods. */
2142 struct dwarf2_per_cu_quick_data
2144 /* The file table. This can be NULL if there was no file table
2145 or it's currently not read in.
2146 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2147 struct quick_file_names
*file_names
;
2149 /* The corresponding symbol table. This is NULL if symbols for this
2150 CU have not yet been read. */
2151 struct compunit_symtab
*compunit_symtab
;
2153 /* A temporary mark bit used when iterating over all CUs in
2154 expand_symtabs_matching. */
2155 unsigned int mark
: 1;
2157 /* True if we've tried to read the file table and found there isn't one.
2158 There will be no point in trying to read it again next time. */
2159 unsigned int no_file_data
: 1;
2162 /* Utility hash function for a stmt_list_hash. */
2165 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2169 if (stmt_list_hash
->dwo_unit
!= NULL
)
2170 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2171 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2175 /* Utility equality function for a stmt_list_hash. */
2178 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2179 const struct stmt_list_hash
*rhs
)
2181 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2183 if (lhs
->dwo_unit
!= NULL
2184 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2187 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2190 /* Hash function for a quick_file_names. */
2193 hash_file_name_entry (const void *e
)
2195 const struct quick_file_names
*file_data
2196 = (const struct quick_file_names
*) e
;
2198 return hash_stmt_list_entry (&file_data
->hash
);
2201 /* Equality function for a quick_file_names. */
2204 eq_file_name_entry (const void *a
, const void *b
)
2206 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2207 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2209 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2212 /* Delete function for a quick_file_names. */
2215 delete_file_name_entry (void *e
)
2217 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2220 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2222 xfree ((void*) file_data
->file_names
[i
]);
2223 if (file_data
->real_names
)
2224 xfree ((void*) file_data
->real_names
[i
]);
2227 /* The space for the struct itself lives on objfile_obstack,
2228 so we don't free it here. */
2231 /* Create a quick_file_names hash table. */
2234 create_quick_file_names_table (unsigned int nr_initial_entries
)
2236 return htab_up (htab_create_alloc (nr_initial_entries
,
2237 hash_file_name_entry
, eq_file_name_entry
,
2238 delete_file_name_entry
, xcalloc
, xfree
));
2241 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2242 have to be created afterwards. You should call age_cached_comp_units after
2243 processing PER_CU->CU. dw2_setup must have been already called. */
2246 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2248 if (per_cu
->is_debug_types
)
2249 load_full_type_unit (per_cu
);
2251 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2253 if (per_cu
->cu
== NULL
)
2254 return; /* Dummy CU. */
2256 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2259 /* Read in the symbols for PER_CU. */
2262 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2264 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2266 /* Skip type_unit_groups, reading the type units they contain
2267 is handled elsewhere. */
2268 if (per_cu
->type_unit_group_p ())
2271 /* The destructor of dwarf2_queue_guard frees any entries left on
2272 the queue. After this point we're guaranteed to leave this function
2273 with the dwarf queue empty. */
2274 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2276 if (dwarf2_per_objfile
->using_index
2277 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2278 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2280 queue_comp_unit (per_cu
, language_minimal
);
2281 load_cu (per_cu
, skip_partial
);
2283 /* If we just loaded a CU from a DWO, and we're working with an index
2284 that may badly handle TUs, load all the TUs in that DWO as well.
2285 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2286 if (!per_cu
->is_debug_types
2287 && per_cu
->cu
!= NULL
2288 && per_cu
->cu
->dwo_unit
!= NULL
2289 && dwarf2_per_objfile
->index_table
!= NULL
2290 && dwarf2_per_objfile
->index_table
->version
<= 7
2291 /* DWP files aren't supported yet. */
2292 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2293 queue_and_load_all_dwo_tus (per_cu
);
2296 process_queue (dwarf2_per_objfile
);
2298 /* Age the cache, releasing compilation units that have not
2299 been used recently. */
2300 age_cached_comp_units (dwarf2_per_objfile
);
2303 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2304 the objfile from which this CU came. Returns the resulting symbol
2307 static struct compunit_symtab
*
2308 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2310 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2312 gdb_assert (dwarf2_per_objfile
->using_index
);
2313 if (!per_cu
->v
.quick
->compunit_symtab
)
2315 free_cached_comp_units
freer (dwarf2_per_objfile
);
2316 scoped_restore decrementer
= increment_reading_symtab ();
2317 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2318 process_cu_includes (dwarf2_per_objfile
);
2321 return per_cu
->v
.quick
->compunit_symtab
;
2324 /* See declaration. */
2326 dwarf2_per_cu_data
*
2327 dwarf2_per_objfile::get_cutu (int index
)
2329 if (index
>= this->all_comp_units
.size ())
2331 index
-= this->all_comp_units
.size ();
2332 gdb_assert (index
< this->all_type_units
.size ());
2333 return &this->all_type_units
[index
]->per_cu
;
2336 return this->all_comp_units
[index
];
2339 /* See declaration. */
2341 dwarf2_per_cu_data
*
2342 dwarf2_per_objfile::get_cu (int index
)
2344 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2346 return this->all_comp_units
[index
];
2349 /* See declaration. */
2352 dwarf2_per_objfile::get_tu (int index
)
2354 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2356 return this->all_type_units
[index
];
2359 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2360 objfile_obstack, and constructed with the specified field
2363 static dwarf2_per_cu_data
*
2364 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2365 struct dwarf2_section_info
*section
,
2367 sect_offset sect_off
, ULONGEST length
)
2369 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2370 dwarf2_per_cu_data
*the_cu
2371 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2372 struct dwarf2_per_cu_data
);
2373 the_cu
->sect_off
= sect_off
;
2374 the_cu
->length
= length
;
2375 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2376 the_cu
->section
= section
;
2377 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2378 struct dwarf2_per_cu_quick_data
);
2379 the_cu
->is_dwz
= is_dwz
;
2383 /* A helper for create_cus_from_index that handles a given list of
2387 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2388 const gdb_byte
*cu_list
, offset_type n_elements
,
2389 struct dwarf2_section_info
*section
,
2392 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2394 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2396 sect_offset sect_off
2397 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2398 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2401 dwarf2_per_cu_data
*per_cu
2402 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2404 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2408 /* Read the CU list from the mapped index, and use it to create all
2409 the CU objects for this objfile. */
2412 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2413 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2414 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2416 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2417 dwarf2_per_objfile
->all_comp_units
.reserve
2418 ((cu_list_elements
+ dwz_elements
) / 2);
2420 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2421 &dwarf2_per_objfile
->info
, 0);
2423 if (dwz_elements
== 0)
2426 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2427 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2431 /* Create the signatured type hash table from the index. */
2434 create_signatured_type_table_from_index
2435 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2436 struct dwarf2_section_info
*section
,
2437 const gdb_byte
*bytes
,
2438 offset_type elements
)
2440 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2442 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2443 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2445 htab_up sig_types_hash
= allocate_signatured_type_table ();
2447 for (offset_type i
= 0; i
< elements
; i
+= 3)
2449 struct signatured_type
*sig_type
;
2452 cu_offset type_offset_in_tu
;
2454 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2455 sect_offset sect_off
2456 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2458 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2460 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2463 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2464 struct signatured_type
);
2465 sig_type
->signature
= signature
;
2466 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2467 sig_type
->per_cu
.is_debug_types
= 1;
2468 sig_type
->per_cu
.section
= section
;
2469 sig_type
->per_cu
.sect_off
= sect_off
;
2470 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2471 sig_type
->per_cu
.v
.quick
2472 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2473 struct dwarf2_per_cu_quick_data
);
2475 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2478 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2481 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2484 /* Create the signatured type hash table from .debug_names. */
2487 create_signatured_type_table_from_debug_names
2488 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2489 const mapped_debug_names
&map
,
2490 struct dwarf2_section_info
*section
,
2491 struct dwarf2_section_info
*abbrev_section
)
2493 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2495 section
->read (objfile
);
2496 abbrev_section
->read (objfile
);
2498 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2499 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2501 htab_up sig_types_hash
= allocate_signatured_type_table ();
2503 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2505 struct signatured_type
*sig_type
;
2508 sect_offset sect_off
2509 = (sect_offset
) (extract_unsigned_integer
2510 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2512 map
.dwarf5_byte_order
));
2514 comp_unit_head cu_header
;
2515 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2517 section
->buffer
+ to_underlying (sect_off
),
2520 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2521 struct signatured_type
);
2522 sig_type
->signature
= cu_header
.signature
;
2523 sig_type
->type_offset_in_tu
= cu_header
.type_cu_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 /* Read the address map data from the mapped index, and use it to
2542 populate the objfile's psymtabs_addrmap. */
2545 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2546 struct mapped_index
*index
)
2548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2549 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2550 const gdb_byte
*iter
, *end
;
2551 struct addrmap
*mutable_map
;
2554 auto_obstack temp_obstack
;
2556 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2558 iter
= index
->address_table
.data ();
2559 end
= iter
+ index
->address_table
.size ();
2561 baseaddr
= objfile
->text_section_offset ();
2565 ULONGEST hi
, lo
, cu_index
;
2566 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2568 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2570 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2575 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2576 hex_string (lo
), hex_string (hi
));
2580 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2582 complaint (_(".gdb_index address table has invalid CU number %u"),
2583 (unsigned) cu_index
);
2587 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2588 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2589 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2590 dwarf2_per_objfile
->get_cu (cu_index
));
2593 objfile
->partial_symtabs
->psymtabs_addrmap
2594 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2597 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2598 populate the objfile's psymtabs_addrmap. */
2601 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2602 struct dwarf2_section_info
*section
)
2604 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2605 bfd
*abfd
= objfile
->obfd
;
2606 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2607 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2609 auto_obstack temp_obstack
;
2610 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2612 std::unordered_map
<sect_offset
,
2613 dwarf2_per_cu_data
*,
2614 gdb::hash_enum
<sect_offset
>>
2615 debug_info_offset_to_per_cu
;
2616 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2618 const auto insertpair
2619 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2620 if (!insertpair
.second
)
2622 warning (_("Section .debug_aranges in %s has duplicate "
2623 "debug_info_offset %s, ignoring .debug_aranges."),
2624 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2629 section
->read (objfile
);
2631 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2633 const gdb_byte
*addr
= section
->buffer
;
2635 while (addr
< section
->buffer
+ section
->size
)
2637 const gdb_byte
*const entry_addr
= addr
;
2638 unsigned int bytes_read
;
2640 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2644 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2645 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2646 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2647 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2649 warning (_("Section .debug_aranges in %s entry at offset %s "
2650 "length %s exceeds section length %s, "
2651 "ignoring .debug_aranges."),
2652 objfile_name (objfile
),
2653 plongest (entry_addr
- section
->buffer
),
2654 plongest (bytes_read
+ entry_length
),
2655 pulongest (section
->size
));
2659 /* The version number. */
2660 const uint16_t version
= read_2_bytes (abfd
, addr
);
2664 warning (_("Section .debug_aranges in %s entry at offset %s "
2665 "has unsupported version %d, ignoring .debug_aranges."),
2666 objfile_name (objfile
),
2667 plongest (entry_addr
- section
->buffer
), version
);
2671 const uint64_t debug_info_offset
2672 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2673 addr
+= offset_size
;
2674 const auto per_cu_it
2675 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2676 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2678 warning (_("Section .debug_aranges in %s entry at offset %s "
2679 "debug_info_offset %s does not exists, "
2680 "ignoring .debug_aranges."),
2681 objfile_name (objfile
),
2682 plongest (entry_addr
- section
->buffer
),
2683 pulongest (debug_info_offset
));
2686 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2688 const uint8_t address_size
= *addr
++;
2689 if (address_size
< 1 || address_size
> 8)
2691 warning (_("Section .debug_aranges in %s entry at offset %s "
2692 "address_size %u is invalid, ignoring .debug_aranges."),
2693 objfile_name (objfile
),
2694 plongest (entry_addr
- section
->buffer
), address_size
);
2698 const uint8_t segment_selector_size
= *addr
++;
2699 if (segment_selector_size
!= 0)
2701 warning (_("Section .debug_aranges in %s entry at offset %s "
2702 "segment_selector_size %u is not supported, "
2703 "ignoring .debug_aranges."),
2704 objfile_name (objfile
),
2705 plongest (entry_addr
- section
->buffer
),
2706 segment_selector_size
);
2710 /* Must pad to an alignment boundary that is twice the address
2711 size. It is undocumented by the DWARF standard but GCC does
2713 for (size_t padding
= ((-(addr
- section
->buffer
))
2714 & (2 * address_size
- 1));
2715 padding
> 0; padding
--)
2718 warning (_("Section .debug_aranges in %s entry at offset %s "
2719 "padding is not zero, ignoring .debug_aranges."),
2720 objfile_name (objfile
),
2721 plongest (entry_addr
- section
->buffer
));
2727 if (addr
+ 2 * address_size
> entry_end
)
2729 warning (_("Section .debug_aranges in %s entry at offset %s "
2730 "address list is not properly terminated, "
2731 "ignoring .debug_aranges."),
2732 objfile_name (objfile
),
2733 plongest (entry_addr
- section
->buffer
));
2736 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2738 addr
+= address_size
;
2739 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2741 addr
+= address_size
;
2742 if (start
== 0 && length
== 0)
2744 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2746 /* Symbol was eliminated due to a COMDAT group. */
2749 ULONGEST end
= start
+ length
;
2750 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2752 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2754 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2758 objfile
->partial_symtabs
->psymtabs_addrmap
2759 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2762 /* Find a slot in the mapped index INDEX for the object named NAME.
2763 If NAME is found, set *VEC_OUT to point to the CU vector in the
2764 constant pool and return true. If NAME cannot be found, return
2768 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2769 offset_type
**vec_out
)
2772 offset_type slot
, step
;
2773 int (*cmp
) (const char *, const char *);
2775 gdb::unique_xmalloc_ptr
<char> without_params
;
2776 if (current_language
->la_language
== language_cplus
2777 || current_language
->la_language
== language_fortran
2778 || current_language
->la_language
== language_d
)
2780 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2783 if (strchr (name
, '(') != NULL
)
2785 without_params
= cp_remove_params (name
);
2787 if (without_params
!= NULL
)
2788 name
= without_params
.get ();
2792 /* Index version 4 did not support case insensitive searches. But the
2793 indices for case insensitive languages are built in lowercase, therefore
2794 simulate our NAME being searched is also lowercased. */
2795 hash
= mapped_index_string_hash ((index
->version
== 4
2796 && case_sensitivity
== case_sensitive_off
2797 ? 5 : index
->version
),
2800 slot
= hash
& (index
->symbol_table
.size () - 1);
2801 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2802 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2808 const auto &bucket
= index
->symbol_table
[slot
];
2809 if (bucket
.name
== 0 && bucket
.vec
== 0)
2812 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2813 if (!cmp (name
, str
))
2815 *vec_out
= (offset_type
*) (index
->constant_pool
2816 + MAYBE_SWAP (bucket
.vec
));
2820 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2824 /* A helper function that reads the .gdb_index from BUFFER and fills
2825 in MAP. FILENAME is the name of the file containing the data;
2826 it is used for error reporting. DEPRECATED_OK is true if it is
2827 ok to use deprecated sections.
2829 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2830 out parameters that are filled in with information about the CU and
2831 TU lists in the section.
2833 Returns true if all went well, false otherwise. */
2836 read_gdb_index_from_buffer (struct objfile
*objfile
,
2837 const char *filename
,
2839 gdb::array_view
<const gdb_byte
> buffer
,
2840 struct mapped_index
*map
,
2841 const gdb_byte
**cu_list
,
2842 offset_type
*cu_list_elements
,
2843 const gdb_byte
**types_list
,
2844 offset_type
*types_list_elements
)
2846 const gdb_byte
*addr
= &buffer
[0];
2848 /* Version check. */
2849 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2850 /* Versions earlier than 3 emitted every copy of a psymbol. This
2851 causes the index to behave very poorly for certain requests. Version 3
2852 contained incomplete addrmap. So, it seems better to just ignore such
2856 static int warning_printed
= 0;
2857 if (!warning_printed
)
2859 warning (_("Skipping obsolete .gdb_index section in %s."),
2861 warning_printed
= 1;
2865 /* Index version 4 uses a different hash function than index version
2868 Versions earlier than 6 did not emit psymbols for inlined
2869 functions. Using these files will cause GDB not to be able to
2870 set breakpoints on inlined functions by name, so we ignore these
2871 indices unless the user has done
2872 "set use-deprecated-index-sections on". */
2873 if (version
< 6 && !deprecated_ok
)
2875 static int warning_printed
= 0;
2876 if (!warning_printed
)
2879 Skipping deprecated .gdb_index section in %s.\n\
2880 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2881 to use the section anyway."),
2883 warning_printed
= 1;
2887 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2888 of the TU (for symbols coming from TUs),
2889 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2890 Plus gold-generated indices can have duplicate entries for global symbols,
2891 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2892 These are just performance bugs, and we can't distinguish gdb-generated
2893 indices from gold-generated ones, so issue no warning here. */
2895 /* Indexes with higher version than the one supported by GDB may be no
2896 longer backward compatible. */
2900 map
->version
= version
;
2902 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2905 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2906 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2910 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2911 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2912 - MAYBE_SWAP (metadata
[i
]))
2916 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2917 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2919 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2922 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2923 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2925 = gdb::array_view
<mapped_index::symbol_table_slot
>
2926 ((mapped_index::symbol_table_slot
*) symbol_table
,
2927 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2930 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2935 /* Callback types for dwarf2_read_gdb_index. */
2937 typedef gdb::function_view
2938 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2939 get_gdb_index_contents_ftype
;
2940 typedef gdb::function_view
2941 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2942 get_gdb_index_contents_dwz_ftype
;
2944 /* Read .gdb_index. If everything went ok, initialize the "quick"
2945 elements of all the CUs and return 1. Otherwise, return 0. */
2948 dwarf2_read_gdb_index
2949 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2950 get_gdb_index_contents_ftype get_gdb_index_contents
,
2951 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2953 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2954 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2955 struct dwz_file
*dwz
;
2956 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2958 gdb::array_view
<const gdb_byte
> main_index_contents
2959 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
2961 if (main_index_contents
.empty ())
2964 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2965 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
2966 use_deprecated_index_sections
,
2967 main_index_contents
, map
.get (), &cu_list
,
2968 &cu_list_elements
, &types_list
,
2969 &types_list_elements
))
2972 /* Don't use the index if it's empty. */
2973 if (map
->symbol_table
.empty ())
2976 /* If there is a .dwz file, read it so we can get its CU list as
2978 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2981 struct mapped_index dwz_map
;
2982 const gdb_byte
*dwz_types_ignore
;
2983 offset_type dwz_types_elements_ignore
;
2985 gdb::array_view
<const gdb_byte
> dwz_index_content
2986 = get_gdb_index_contents_dwz (objfile
, dwz
);
2988 if (dwz_index_content
.empty ())
2991 if (!read_gdb_index_from_buffer (objfile
,
2992 bfd_get_filename (dwz
->dwz_bfd
.get ()),
2993 1, dwz_index_content
, &dwz_map
,
2994 &dwz_list
, &dwz_list_elements
,
2996 &dwz_types_elements_ignore
))
2998 warning (_("could not read '.gdb_index' section from %s; skipping"),
2999 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3004 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3005 dwz_list
, dwz_list_elements
);
3007 if (types_list_elements
)
3009 /* We can only handle a single .debug_types when we have an
3011 if (dwarf2_per_objfile
->types
.size () != 1)
3014 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3016 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3017 types_list
, types_list_elements
);
3020 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3022 dwarf2_per_objfile
->index_table
= std::move (map
);
3023 dwarf2_per_objfile
->using_index
= 1;
3024 dwarf2_per_objfile
->quick_file_names_table
=
3025 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3030 /* die_reader_func for dw2_get_file_names. */
3033 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3034 const gdb_byte
*info_ptr
,
3035 struct die_info
*comp_unit_die
)
3037 struct dwarf2_cu
*cu
= reader
->cu
;
3038 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3039 struct dwarf2_per_objfile
*dwarf2_per_objfile
3040 = cu
->per_cu
->dwarf2_per_objfile
;
3041 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3042 struct dwarf2_per_cu_data
*lh_cu
;
3043 struct attribute
*attr
;
3045 struct quick_file_names
*qfn
;
3047 gdb_assert (! this_cu
->is_debug_types
);
3049 /* Our callers never want to match partial units -- instead they
3050 will match the enclosing full CU. */
3051 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3053 this_cu
->v
.quick
->no_file_data
= 1;
3061 sect_offset line_offset
{};
3063 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3064 if (attr
!= nullptr)
3066 struct quick_file_names find_entry
;
3068 line_offset
= (sect_offset
) DW_UNSND (attr
);
3070 /* We may have already read in this line header (TU line header sharing).
3071 If we have we're done. */
3072 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3073 find_entry
.hash
.line_sect_off
= line_offset
;
3074 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3075 &find_entry
, INSERT
);
3078 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3082 lh
= dwarf_decode_line_header (line_offset
, cu
);
3086 lh_cu
->v
.quick
->no_file_data
= 1;
3090 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3091 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3092 qfn
->hash
.line_sect_off
= line_offset
;
3093 gdb_assert (slot
!= NULL
);
3096 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3099 if (strcmp (fnd
.name
, "<unknown>") != 0)
3102 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3104 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3106 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3107 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3108 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3109 fnd
.comp_dir
).release ();
3110 qfn
->real_names
= NULL
;
3112 lh_cu
->v
.quick
->file_names
= qfn
;
3115 /* A helper for the "quick" functions which attempts to read the line
3116 table for THIS_CU. */
3118 static struct quick_file_names
*
3119 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3121 /* This should never be called for TUs. */
3122 gdb_assert (! this_cu
->is_debug_types
);
3123 /* Nor type unit groups. */
3124 gdb_assert (! this_cu
->type_unit_group_p ());
3126 if (this_cu
->v
.quick
->file_names
!= NULL
)
3127 return this_cu
->v
.quick
->file_names
;
3128 /* If we know there is no line data, no point in looking again. */
3129 if (this_cu
->v
.quick
->no_file_data
)
3132 cutu_reader
reader (this_cu
);
3133 if (!reader
.dummy_p
)
3134 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3136 if (this_cu
->v
.quick
->no_file_data
)
3138 return this_cu
->v
.quick
->file_names
;
3141 /* A helper for the "quick" functions which computes and caches the
3142 real path for a given file name from the line table. */
3145 dw2_get_real_path (struct objfile
*objfile
,
3146 struct quick_file_names
*qfn
, int index
)
3148 if (qfn
->real_names
== NULL
)
3149 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3150 qfn
->num_file_names
, const char *);
3152 if (qfn
->real_names
[index
] == NULL
)
3153 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3155 return qfn
->real_names
[index
];
3158 static struct symtab
*
3159 dw2_find_last_source_symtab (struct objfile
*objfile
)
3161 struct dwarf2_per_objfile
*dwarf2_per_objfile
3162 = get_dwarf2_per_objfile (objfile
);
3163 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3164 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3169 return compunit_primary_filetab (cust
);
3172 /* Traversal function for dw2_forget_cached_source_info. */
3175 dw2_free_cached_file_names (void **slot
, void *info
)
3177 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3179 if (file_data
->real_names
)
3183 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3185 xfree ((void*) file_data
->real_names
[i
]);
3186 file_data
->real_names
[i
] = NULL
;
3194 dw2_forget_cached_source_info (struct objfile
*objfile
)
3196 struct dwarf2_per_objfile
*dwarf2_per_objfile
3197 = get_dwarf2_per_objfile (objfile
);
3199 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3200 dw2_free_cached_file_names
, NULL
);
3203 /* Helper function for dw2_map_symtabs_matching_filename that expands
3204 the symtabs and calls the iterator. */
3207 dw2_map_expand_apply (struct objfile
*objfile
,
3208 struct dwarf2_per_cu_data
*per_cu
,
3209 const char *name
, const char *real_path
,
3210 gdb::function_view
<bool (symtab
*)> callback
)
3212 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3214 /* Don't visit already-expanded CUs. */
3215 if (per_cu
->v
.quick
->compunit_symtab
)
3218 /* This may expand more than one symtab, and we want to iterate over
3220 dw2_instantiate_symtab (per_cu
, false);
3222 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3223 last_made
, callback
);
3226 /* Implementation of the map_symtabs_matching_filename method. */
3229 dw2_map_symtabs_matching_filename
3230 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3231 gdb::function_view
<bool (symtab
*)> callback
)
3233 const char *name_basename
= lbasename (name
);
3234 struct dwarf2_per_objfile
*dwarf2_per_objfile
3235 = get_dwarf2_per_objfile (objfile
);
3237 /* The rule is CUs specify all the files, including those used by
3238 any TU, so there's no need to scan TUs here. */
3240 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3242 /* We only need to look at symtabs not already expanded. */
3243 if (per_cu
->v
.quick
->compunit_symtab
)
3246 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3247 if (file_data
== NULL
)
3250 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3252 const char *this_name
= file_data
->file_names
[j
];
3253 const char *this_real_name
;
3255 if (compare_filenames_for_search (this_name
, name
))
3257 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3263 /* Before we invoke realpath, which can get expensive when many
3264 files are involved, do a quick comparison of the basenames. */
3265 if (! basenames_may_differ
3266 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3269 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3270 if (compare_filenames_for_search (this_real_name
, name
))
3272 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3278 if (real_path
!= NULL
)
3280 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3281 gdb_assert (IS_ABSOLUTE_PATH (name
));
3282 if (this_real_name
!= NULL
3283 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3285 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3297 /* Struct used to manage iterating over all CUs looking for a symbol. */
3299 struct dw2_symtab_iterator
3301 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3302 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3303 /* If set, only look for symbols that match that block. Valid values are
3304 GLOBAL_BLOCK and STATIC_BLOCK. */
3305 gdb::optional
<block_enum
> block_index
;
3306 /* The kind of symbol we're looking for. */
3308 /* The list of CUs from the index entry of the symbol,
3309 or NULL if not found. */
3311 /* The next element in VEC to look at. */
3313 /* The number of elements in VEC, or zero if there is no match. */
3315 /* Have we seen a global version of the symbol?
3316 If so we can ignore all further global instances.
3317 This is to work around gold/15646, inefficient gold-generated
3322 /* Initialize the index symtab iterator ITER. */
3325 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3326 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3327 gdb::optional
<block_enum
> block_index
,
3331 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3332 iter
->block_index
= block_index
;
3333 iter
->domain
= domain
;
3335 iter
->global_seen
= 0;
3337 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3339 /* index is NULL if OBJF_READNOW. */
3340 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3341 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3349 /* Return the next matching CU or NULL if there are no more. */
3351 static struct dwarf2_per_cu_data
*
3352 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3354 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3356 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3358 offset_type cu_index_and_attrs
=
3359 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3360 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3361 gdb_index_symbol_kind symbol_kind
=
3362 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3363 /* Only check the symbol attributes if they're present.
3364 Indices prior to version 7 don't record them,
3365 and indices >= 7 may elide them for certain symbols
3366 (gold does this). */
3368 (dwarf2_per_objfile
->index_table
->version
>= 7
3369 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3371 /* Don't crash on bad data. */
3372 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3373 + dwarf2_per_objfile
->all_type_units
.size ()))
3375 complaint (_(".gdb_index entry has bad CU index"
3377 objfile_name (dwarf2_per_objfile
->objfile
));
3381 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3383 /* Skip if already read in. */
3384 if (per_cu
->v
.quick
->compunit_symtab
)
3387 /* Check static vs global. */
3390 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3392 if (iter
->block_index
.has_value ())
3394 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3396 if (is_static
!= want_static
)
3400 /* Work around gold/15646. */
3401 if (!is_static
&& iter
->global_seen
)
3404 iter
->global_seen
= 1;
3407 /* Only check the symbol's kind if it has one. */
3410 switch (iter
->domain
)
3413 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3414 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3415 /* Some types are also in VAR_DOMAIN. */
3416 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3420 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3424 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3428 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3443 static struct compunit_symtab
*
3444 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3445 const char *name
, domain_enum domain
)
3447 struct compunit_symtab
*stab_best
= NULL
;
3448 struct dwarf2_per_objfile
*dwarf2_per_objfile
3449 = get_dwarf2_per_objfile (objfile
);
3451 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3453 struct dw2_symtab_iterator iter
;
3454 struct dwarf2_per_cu_data
*per_cu
;
3456 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3458 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3460 struct symbol
*sym
, *with_opaque
= NULL
;
3461 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3462 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3463 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3465 sym
= block_find_symbol (block
, name
, domain
,
3466 block_find_non_opaque_type_preferred
,
3469 /* Some caution must be observed with overloaded functions
3470 and methods, since the index will not contain any overload
3471 information (but NAME might contain it). */
3474 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3476 if (with_opaque
!= NULL
3477 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3480 /* Keep looking through other CUs. */
3487 dw2_print_stats (struct objfile
*objfile
)
3489 struct dwarf2_per_objfile
*dwarf2_per_objfile
3490 = get_dwarf2_per_objfile (objfile
);
3491 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3492 + dwarf2_per_objfile
->all_type_units
.size ());
3495 for (int i
= 0; i
< total
; ++i
)
3497 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3499 if (!per_cu
->v
.quick
->compunit_symtab
)
3502 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3503 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3506 /* This dumps minimal information about the index.
3507 It is called via "mt print objfiles".
3508 One use is to verify .gdb_index has been loaded by the
3509 gdb.dwarf2/gdb-index.exp testcase. */
3512 dw2_dump (struct objfile
*objfile
)
3514 struct dwarf2_per_objfile
*dwarf2_per_objfile
3515 = get_dwarf2_per_objfile (objfile
);
3517 gdb_assert (dwarf2_per_objfile
->using_index
);
3518 printf_filtered (".gdb_index:");
3519 if (dwarf2_per_objfile
->index_table
!= NULL
)
3521 printf_filtered (" version %d\n",
3522 dwarf2_per_objfile
->index_table
->version
);
3525 printf_filtered (" faked for \"readnow\"\n");
3526 printf_filtered ("\n");
3530 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3531 const char *func_name
)
3533 struct dwarf2_per_objfile
*dwarf2_per_objfile
3534 = get_dwarf2_per_objfile (objfile
);
3536 struct dw2_symtab_iterator iter
;
3537 struct dwarf2_per_cu_data
*per_cu
;
3539 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3541 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3542 dw2_instantiate_symtab (per_cu
, false);
3547 dw2_expand_all_symtabs (struct objfile
*objfile
)
3549 struct dwarf2_per_objfile
*dwarf2_per_objfile
3550 = get_dwarf2_per_objfile (objfile
);
3551 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3552 + dwarf2_per_objfile
->all_type_units
.size ());
3554 for (int i
= 0; i
< total_units
; ++i
)
3556 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3558 /* We don't want to directly expand a partial CU, because if we
3559 read it with the wrong language, then assertion failures can
3560 be triggered later on. See PR symtab/23010. So, tell
3561 dw2_instantiate_symtab to skip partial CUs -- any important
3562 partial CU will be read via DW_TAG_imported_unit anyway. */
3563 dw2_instantiate_symtab (per_cu
, true);
3568 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3569 const char *fullname
)
3571 struct dwarf2_per_objfile
*dwarf2_per_objfile
3572 = get_dwarf2_per_objfile (objfile
);
3574 /* We don't need to consider type units here.
3575 This is only called for examining code, e.g. expand_line_sal.
3576 There can be an order of magnitude (or more) more type units
3577 than comp units, and we avoid them if we can. */
3579 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3581 /* We only need to look at symtabs not already expanded. */
3582 if (per_cu
->v
.quick
->compunit_symtab
)
3585 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3586 if (file_data
== NULL
)
3589 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3591 const char *this_fullname
= file_data
->file_names
[j
];
3593 if (filename_cmp (this_fullname
, fullname
) == 0)
3595 dw2_instantiate_symtab (per_cu
, false);
3603 dw2_map_matching_symbols
3604 (struct objfile
*objfile
,
3605 const lookup_name_info
&name
, domain_enum domain
,
3607 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3608 symbol_compare_ftype
*ordered_compare
)
3610 /* Currently unimplemented; used for Ada. The function can be called if the
3611 current language is Ada for a non-Ada objfile using GNU index. As Ada
3612 does not look for non-Ada symbols this function should just return. */
3615 /* Starting from a search name, return the string that finds the upper
3616 bound of all strings that start with SEARCH_NAME in a sorted name
3617 list. Returns the empty string to indicate that the upper bound is
3618 the end of the list. */
3621 make_sort_after_prefix_name (const char *search_name
)
3623 /* When looking to complete "func", we find the upper bound of all
3624 symbols that start with "func" by looking for where we'd insert
3625 the closest string that would follow "func" in lexicographical
3626 order. Usually, that's "func"-with-last-character-incremented,
3627 i.e. "fund". Mind non-ASCII characters, though. Usually those
3628 will be UTF-8 multi-byte sequences, but we can't be certain.
3629 Especially mind the 0xff character, which is a valid character in
3630 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3631 rule out compilers allowing it in identifiers. Note that
3632 conveniently, strcmp/strcasecmp are specified to compare
3633 characters interpreted as unsigned char. So what we do is treat
3634 the whole string as a base 256 number composed of a sequence of
3635 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3636 to 0, and carries 1 to the following more-significant position.
3637 If the very first character in SEARCH_NAME ends up incremented
3638 and carries/overflows, then the upper bound is the end of the
3639 list. The string after the empty string is also the empty
3642 Some examples of this operation:
3644 SEARCH_NAME => "+1" RESULT
3648 "\xff" "a" "\xff" => "\xff" "b"
3653 Then, with these symbols for example:
3659 completing "func" looks for symbols between "func" and
3660 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3661 which finds "func" and "func1", but not "fund".
3665 funcÿ (Latin1 'ÿ' [0xff])
3669 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3670 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3674 ÿÿ (Latin1 'ÿ' [0xff])
3677 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3678 the end of the list.
3680 std::string after
= search_name
;
3681 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3683 if (!after
.empty ())
3684 after
.back () = (unsigned char) after
.back () + 1;
3688 /* See declaration. */
3690 std::pair
<std::vector
<name_component
>::const_iterator
,
3691 std::vector
<name_component
>::const_iterator
>
3692 mapped_index_base::find_name_components_bounds
3693 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3696 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3698 const char *lang_name
3699 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3701 /* Comparison function object for lower_bound that matches against a
3702 given symbol name. */
3703 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3706 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3707 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3708 return name_cmp (elem_name
, name
) < 0;
3711 /* Comparison function object for upper_bound that matches against a
3712 given symbol name. */
3713 auto lookup_compare_upper
= [&] (const char *name
,
3714 const name_component
&elem
)
3716 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3717 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3718 return name_cmp (name
, elem_name
) < 0;
3721 auto begin
= this->name_components
.begin ();
3722 auto end
= this->name_components
.end ();
3724 /* Find the lower bound. */
3727 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3730 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3733 /* Find the upper bound. */
3736 if (lookup_name_without_params
.completion_mode ())
3738 /* In completion mode, we want UPPER to point past all
3739 symbols names that have the same prefix. I.e., with
3740 these symbols, and completing "func":
3742 function << lower bound
3744 other_function << upper bound
3746 We find the upper bound by looking for the insertion
3747 point of "func"-with-last-character-incremented,
3749 std::string after
= make_sort_after_prefix_name (lang_name
);
3752 return std::lower_bound (lower
, end
, after
.c_str (),
3753 lookup_compare_lower
);
3756 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3759 return {lower
, upper
};
3762 /* See declaration. */
3765 mapped_index_base::build_name_components ()
3767 if (!this->name_components
.empty ())
3770 this->name_components_casing
= case_sensitivity
;
3772 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3774 /* The code below only knows how to break apart components of C++
3775 symbol names (and other languages that use '::' as
3776 namespace/module separator) and Ada symbol names. */
3777 auto count
= this->symbol_name_count ();
3778 for (offset_type idx
= 0; idx
< count
; idx
++)
3780 if (this->symbol_name_slot_invalid (idx
))
3783 const char *name
= this->symbol_name_at (idx
);
3785 /* Add each name component to the name component table. */
3786 unsigned int previous_len
= 0;
3788 if (strstr (name
, "::") != nullptr)
3790 for (unsigned int current_len
= cp_find_first_component (name
);
3791 name
[current_len
] != '\0';
3792 current_len
+= cp_find_first_component (name
+ current_len
))
3794 gdb_assert (name
[current_len
] == ':');
3795 this->name_components
.push_back ({previous_len
, idx
});
3796 /* Skip the '::'. */
3798 previous_len
= current_len
;
3803 /* Handle the Ada encoded (aka mangled) form here. */
3804 for (const char *iter
= strstr (name
, "__");
3806 iter
= strstr (iter
, "__"))
3808 this->name_components
.push_back ({previous_len
, idx
});
3810 previous_len
= iter
- name
;
3814 this->name_components
.push_back ({previous_len
, idx
});
3817 /* Sort name_components elements by name. */
3818 auto name_comp_compare
= [&] (const name_component
&left
,
3819 const name_component
&right
)
3821 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3822 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3824 const char *left_name
= left_qualified
+ left
.name_offset
;
3825 const char *right_name
= right_qualified
+ right
.name_offset
;
3827 return name_cmp (left_name
, right_name
) < 0;
3830 std::sort (this->name_components
.begin (),
3831 this->name_components
.end (),
3835 /* Helper for dw2_expand_symtabs_matching that works with a
3836 mapped_index_base instead of the containing objfile. This is split
3837 to a separate function in order to be able to unit test the
3838 name_components matching using a mock mapped_index_base. For each
3839 symbol name that matches, calls MATCH_CALLBACK, passing it the
3840 symbol's index in the mapped_index_base symbol table. */
3843 dw2_expand_symtabs_matching_symbol
3844 (mapped_index_base
&index
,
3845 const lookup_name_info
&lookup_name_in
,
3846 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3847 enum search_domain kind
,
3848 gdb::function_view
<bool (offset_type
)> match_callback
)
3850 lookup_name_info lookup_name_without_params
3851 = lookup_name_in
.make_ignore_params ();
3853 /* Build the symbol name component sorted vector, if we haven't
3855 index
.build_name_components ();
3857 /* The same symbol may appear more than once in the range though.
3858 E.g., if we're looking for symbols that complete "w", and we have
3859 a symbol named "w1::w2", we'll find the two name components for
3860 that same symbol in the range. To be sure we only call the
3861 callback once per symbol, we first collect the symbol name
3862 indexes that matched in a temporary vector and ignore
3864 std::vector
<offset_type
> matches
;
3866 struct name_and_matcher
3868 symbol_name_matcher_ftype
*matcher
;
3869 const std::string
&name
;
3871 bool operator== (const name_and_matcher
&other
) const
3873 return matcher
== other
.matcher
&& name
== other
.name
;
3877 /* A vector holding all the different symbol name matchers, for all
3879 std::vector
<name_and_matcher
> matchers
;
3881 for (int i
= 0; i
< nr_languages
; i
++)
3883 enum language lang_e
= (enum language
) i
;
3885 const language_defn
*lang
= language_def (lang_e
);
3886 symbol_name_matcher_ftype
*name_matcher
3887 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3889 name_and_matcher key
{
3891 lookup_name_without_params
.language_lookup_name (lang_e
)
3894 /* Don't insert the same comparison routine more than once.
3895 Note that we do this linear walk. This is not a problem in
3896 practice because the number of supported languages is
3898 if (std::find (matchers
.begin (), matchers
.end (), key
)
3901 matchers
.push_back (std::move (key
));
3904 = index
.find_name_components_bounds (lookup_name_without_params
,
3907 /* Now for each symbol name in range, check to see if we have a name
3908 match, and if so, call the MATCH_CALLBACK callback. */
3910 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3912 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3914 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3915 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3918 matches
.push_back (bounds
.first
->idx
);
3922 std::sort (matches
.begin (), matches
.end ());
3924 /* Finally call the callback, once per match. */
3926 for (offset_type idx
: matches
)
3930 if (!match_callback (idx
))
3936 /* Above we use a type wider than idx's for 'prev', since 0 and
3937 (offset_type)-1 are both possible values. */
3938 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3943 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3945 /* A mock .gdb_index/.debug_names-like name index table, enough to
3946 exercise dw2_expand_symtabs_matching_symbol, which works with the
3947 mapped_index_base interface. Builds an index from the symbol list
3948 passed as parameter to the constructor. */
3949 class mock_mapped_index
: public mapped_index_base
3952 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3953 : m_symbol_table (symbols
)
3956 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3958 /* Return the number of names in the symbol table. */
3959 size_t symbol_name_count () const override
3961 return m_symbol_table
.size ();
3964 /* Get the name of the symbol at IDX in the symbol table. */
3965 const char *symbol_name_at (offset_type idx
) const override
3967 return m_symbol_table
[idx
];
3971 gdb::array_view
<const char *> m_symbol_table
;
3974 /* Convenience function that converts a NULL pointer to a "<null>"
3975 string, to pass to print routines. */
3978 string_or_null (const char *str
)
3980 return str
!= NULL
? str
: "<null>";
3983 /* Check if a lookup_name_info built from
3984 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3985 index. EXPECTED_LIST is the list of expected matches, in expected
3986 matching order. If no match expected, then an empty list is
3987 specified. Returns true on success. On failure prints a warning
3988 indicating the file:line that failed, and returns false. */
3991 check_match (const char *file
, int line
,
3992 mock_mapped_index
&mock_index
,
3993 const char *name
, symbol_name_match_type match_type
,
3994 bool completion_mode
,
3995 std::initializer_list
<const char *> expected_list
)
3997 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3999 bool matched
= true;
4001 auto mismatch
= [&] (const char *expected_str
,
4004 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4005 "expected=\"%s\", got=\"%s\"\n"),
4007 (match_type
== symbol_name_match_type::FULL
4009 name
, string_or_null (expected_str
), string_or_null (got
));
4013 auto expected_it
= expected_list
.begin ();
4014 auto expected_end
= expected_list
.end ();
4016 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4018 [&] (offset_type idx
)
4020 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4021 const char *expected_str
4022 = expected_it
== expected_end
? NULL
: *expected_it
++;
4024 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4025 mismatch (expected_str
, matched_name
);
4029 const char *expected_str
4030 = expected_it
== expected_end
? NULL
: *expected_it
++;
4031 if (expected_str
!= NULL
)
4032 mismatch (expected_str
, NULL
);
4037 /* The symbols added to the mock mapped_index for testing (in
4039 static const char *test_symbols
[] = {
4048 "ns2::tmpl<int>::foo2",
4049 "(anonymous namespace)::A::B::C",
4051 /* These are used to check that the increment-last-char in the
4052 matching algorithm for completion doesn't match "t1_fund" when
4053 completing "t1_func". */
4059 /* A UTF-8 name with multi-byte sequences to make sure that
4060 cp-name-parser understands this as a single identifier ("função"
4061 is "function" in PT). */
4064 /* \377 (0xff) is Latin1 'ÿ'. */
4067 /* \377 (0xff) is Latin1 'ÿ'. */
4071 /* A name with all sorts of complications. Starts with "z" to make
4072 it easier for the completion tests below. */
4073 #define Z_SYM_NAME \
4074 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4075 "::tuple<(anonymous namespace)::ui*, " \
4076 "std::default_delete<(anonymous namespace)::ui>, void>"
4081 /* Returns true if the mapped_index_base::find_name_component_bounds
4082 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4083 in completion mode. */
4086 check_find_bounds_finds (mapped_index_base
&index
,
4087 const char *search_name
,
4088 gdb::array_view
<const char *> expected_syms
)
4090 lookup_name_info
lookup_name (search_name
,
4091 symbol_name_match_type::FULL
, true);
4093 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4096 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4097 if (distance
!= expected_syms
.size ())
4100 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4102 auto nc_elem
= bounds
.first
+ exp_elem
;
4103 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4104 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4111 /* Test the lower-level mapped_index::find_name_component_bounds
4115 test_mapped_index_find_name_component_bounds ()
4117 mock_mapped_index
mock_index (test_symbols
);
4119 mock_index
.build_name_components ();
4121 /* Test the lower-level mapped_index::find_name_component_bounds
4122 method in completion mode. */
4124 static const char *expected_syms
[] = {
4129 SELF_CHECK (check_find_bounds_finds (mock_index
,
4130 "t1_func", expected_syms
));
4133 /* Check that the increment-last-char in the name matching algorithm
4134 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4136 static const char *expected_syms1
[] = {
4140 SELF_CHECK (check_find_bounds_finds (mock_index
,
4141 "\377", expected_syms1
));
4143 static const char *expected_syms2
[] = {
4146 SELF_CHECK (check_find_bounds_finds (mock_index
,
4147 "\377\377", expected_syms2
));
4151 /* Test dw2_expand_symtabs_matching_symbol. */
4154 test_dw2_expand_symtabs_matching_symbol ()
4156 mock_mapped_index
mock_index (test_symbols
);
4158 /* We let all tests run until the end even if some fails, for debug
4160 bool any_mismatch
= false;
4162 /* Create the expected symbols list (an initializer_list). Needed
4163 because lists have commas, and we need to pass them to CHECK,
4164 which is a macro. */
4165 #define EXPECT(...) { __VA_ARGS__ }
4167 /* Wrapper for check_match that passes down the current
4168 __FILE__/__LINE__. */
4169 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4170 any_mismatch |= !check_match (__FILE__, __LINE__, \
4172 NAME, MATCH_TYPE, COMPLETION_MODE, \
4175 /* Identity checks. */
4176 for (const char *sym
: test_symbols
)
4178 /* Should be able to match all existing symbols. */
4179 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4182 /* Should be able to match all existing symbols with
4184 std::string with_params
= std::string (sym
) + "(int)";
4185 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4188 /* Should be able to match all existing symbols with
4189 parameters and qualifiers. */
4190 with_params
= std::string (sym
) + " ( int ) const";
4191 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4194 /* This should really find sym, but cp-name-parser.y doesn't
4195 know about lvalue/rvalue qualifiers yet. */
4196 with_params
= std::string (sym
) + " ( int ) &&";
4197 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4201 /* Check that the name matching algorithm for completion doesn't get
4202 confused with Latin1 'ÿ' / 0xff. */
4204 static const char str
[] = "\377";
4205 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4206 EXPECT ("\377", "\377\377123"));
4209 /* Check that the increment-last-char in the matching algorithm for
4210 completion doesn't match "t1_fund" when completing "t1_func". */
4212 static const char str
[] = "t1_func";
4213 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4214 EXPECT ("t1_func", "t1_func1"));
4217 /* Check that completion mode works at each prefix of the expected
4220 static const char str
[] = "function(int)";
4221 size_t len
= strlen (str
);
4224 for (size_t i
= 1; i
< len
; i
++)
4226 lookup
.assign (str
, i
);
4227 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4228 EXPECT ("function"));
4232 /* While "w" is a prefix of both components, the match function
4233 should still only be called once. */
4235 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4237 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4241 /* Same, with a "complicated" symbol. */
4243 static const char str
[] = Z_SYM_NAME
;
4244 size_t len
= strlen (str
);
4247 for (size_t i
= 1; i
< len
; i
++)
4249 lookup
.assign (str
, i
);
4250 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4251 EXPECT (Z_SYM_NAME
));
4255 /* In FULL mode, an incomplete symbol doesn't match. */
4257 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4261 /* A complete symbol with parameters matches any overload, since the
4262 index has no overload info. */
4264 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4265 EXPECT ("std::zfunction", "std::zfunction2"));
4266 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4267 EXPECT ("std::zfunction", "std::zfunction2"));
4268 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4269 EXPECT ("std::zfunction", "std::zfunction2"));
4272 /* Check that whitespace is ignored appropriately. A symbol with a
4273 template argument list. */
4275 static const char expected
[] = "ns::foo<int>";
4276 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4278 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4282 /* Check that whitespace is ignored appropriately. A symbol with a
4283 template argument list that includes a pointer. */
4285 static const char expected
[] = "ns::foo<char*>";
4286 /* Try both completion and non-completion modes. */
4287 static const bool completion_mode
[2] = {false, true};
4288 for (size_t i
= 0; i
< 2; i
++)
4290 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4291 completion_mode
[i
], EXPECT (expected
));
4292 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4293 completion_mode
[i
], EXPECT (expected
));
4295 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4296 completion_mode
[i
], EXPECT (expected
));
4297 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4298 completion_mode
[i
], EXPECT (expected
));
4303 /* Check method qualifiers are ignored. */
4304 static const char expected
[] = "ns::foo<char*>";
4305 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4306 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4307 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4308 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4309 CHECK_MATCH ("foo < char * > ( int ) const",
4310 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4311 CHECK_MATCH ("foo < char * > ( int ) &&",
4312 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4315 /* Test lookup names that don't match anything. */
4317 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4320 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4324 /* Some wild matching tests, exercising "(anonymous namespace)",
4325 which should not be confused with a parameter list. */
4327 static const char *syms
[] = {
4331 "A :: B :: C ( int )",
4336 for (const char *s
: syms
)
4338 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4339 EXPECT ("(anonymous namespace)::A::B::C"));
4344 static const char expected
[] = "ns2::tmpl<int>::foo2";
4345 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4347 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4351 SELF_CHECK (!any_mismatch
);
4360 test_mapped_index_find_name_component_bounds ();
4361 test_dw2_expand_symtabs_matching_symbol ();
4364 }} // namespace selftests::dw2_expand_symtabs_matching
4366 #endif /* GDB_SELF_TEST */
4368 /* If FILE_MATCHER is NULL or if PER_CU has
4369 dwarf2_per_cu_quick_data::MARK set (see
4370 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4371 EXPANSION_NOTIFY on it. */
4374 dw2_expand_symtabs_matching_one
4375 (struct dwarf2_per_cu_data
*per_cu
,
4376 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4377 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4379 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4381 bool symtab_was_null
4382 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4384 dw2_instantiate_symtab (per_cu
, false);
4386 if (expansion_notify
!= NULL
4388 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4389 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4393 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4394 matched, to expand corresponding CUs that were marked. IDX is the
4395 index of the symbol name that matched. */
4398 dw2_expand_marked_cus
4399 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4400 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4401 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4404 offset_type
*vec
, vec_len
, vec_idx
;
4405 bool global_seen
= false;
4406 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4408 vec
= (offset_type
*) (index
.constant_pool
4409 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4410 vec_len
= MAYBE_SWAP (vec
[0]);
4411 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4413 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4414 /* This value is only valid for index versions >= 7. */
4415 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4416 gdb_index_symbol_kind symbol_kind
=
4417 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4418 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4419 /* Only check the symbol attributes if they're present.
4420 Indices prior to version 7 don't record them,
4421 and indices >= 7 may elide them for certain symbols
4422 (gold does this). */
4425 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4427 /* Work around gold/15646. */
4430 if (!is_static
&& global_seen
)
4436 /* Only check the symbol's kind if it has one. */
4441 case VARIABLES_DOMAIN
:
4442 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4445 case FUNCTIONS_DOMAIN
:
4446 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4450 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4453 case MODULES_DOMAIN
:
4454 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4462 /* Don't crash on bad data. */
4463 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4464 + dwarf2_per_objfile
->all_type_units
.size ()))
4466 complaint (_(".gdb_index entry has bad CU index"
4468 objfile_name (dwarf2_per_objfile
->objfile
));
4472 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4473 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4478 /* If FILE_MATCHER is non-NULL, set all the
4479 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4480 that match FILE_MATCHER. */
4483 dw_expand_symtabs_matching_file_matcher
4484 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4485 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4487 if (file_matcher
== NULL
)
4490 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4492 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4494 NULL
, xcalloc
, xfree
));
4495 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4497 NULL
, xcalloc
, xfree
));
4499 /* The rule is CUs specify all the files, including those used by
4500 any TU, so there's no need to scan TUs here. */
4502 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4506 per_cu
->v
.quick
->mark
= 0;
4508 /* We only need to look at symtabs not already expanded. */
4509 if (per_cu
->v
.quick
->compunit_symtab
)
4512 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4513 if (file_data
== NULL
)
4516 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4518 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4520 per_cu
->v
.quick
->mark
= 1;
4524 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4526 const char *this_real_name
;
4528 if (file_matcher (file_data
->file_names
[j
], false))
4530 per_cu
->v
.quick
->mark
= 1;
4534 /* Before we invoke realpath, which can get expensive when many
4535 files are involved, do a quick comparison of the basenames. */
4536 if (!basenames_may_differ
4537 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4541 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4542 if (file_matcher (this_real_name
, false))
4544 per_cu
->v
.quick
->mark
= 1;
4549 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4550 ? visited_found
.get ()
4551 : visited_not_found
.get (),
4558 dw2_expand_symtabs_matching
4559 (struct objfile
*objfile
,
4560 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4561 const lookup_name_info
&lookup_name
,
4562 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4563 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4564 enum search_domain kind
)
4566 struct dwarf2_per_objfile
*dwarf2_per_objfile
4567 = get_dwarf2_per_objfile (objfile
);
4569 /* index_table is NULL if OBJF_READNOW. */
4570 if (!dwarf2_per_objfile
->index_table
)
4573 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4575 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4577 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4579 kind
, [&] (offset_type idx
)
4581 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4582 expansion_notify
, kind
);
4587 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4590 static struct compunit_symtab
*
4591 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4596 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4597 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4600 if (cust
->includes
== NULL
)
4603 for (i
= 0; cust
->includes
[i
]; ++i
)
4605 struct compunit_symtab
*s
= cust
->includes
[i
];
4607 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4615 static struct compunit_symtab
*
4616 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4617 struct bound_minimal_symbol msymbol
,
4619 struct obj_section
*section
,
4622 struct dwarf2_per_cu_data
*data
;
4623 struct compunit_symtab
*result
;
4625 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4628 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4629 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4630 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4634 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4635 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4636 paddress (get_objfile_arch (objfile
), pc
));
4639 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4642 gdb_assert (result
!= NULL
);
4647 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4648 void *data
, int need_fullname
)
4650 struct dwarf2_per_objfile
*dwarf2_per_objfile
4651 = get_dwarf2_per_objfile (objfile
);
4653 if (!dwarf2_per_objfile
->filenames_cache
)
4655 dwarf2_per_objfile
->filenames_cache
.emplace ();
4657 htab_up
visited (htab_create_alloc (10,
4658 htab_hash_pointer
, htab_eq_pointer
,
4659 NULL
, xcalloc
, xfree
));
4661 /* The rule is CUs specify all the files, including those used
4662 by any TU, so there's no need to scan TUs here. We can
4663 ignore file names coming from already-expanded CUs. */
4665 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4667 if (per_cu
->v
.quick
->compunit_symtab
)
4669 void **slot
= htab_find_slot (visited
.get (),
4670 per_cu
->v
.quick
->file_names
,
4673 *slot
= per_cu
->v
.quick
->file_names
;
4677 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4679 /* We only need to look at symtabs not already expanded. */
4680 if (per_cu
->v
.quick
->compunit_symtab
)
4683 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4684 if (file_data
== NULL
)
4687 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4690 /* Already visited. */
4695 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4697 const char *filename
= file_data
->file_names
[j
];
4698 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4703 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4705 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4708 this_real_name
= gdb_realpath (filename
);
4709 (*fun
) (filename
, this_real_name
.get (), data
);
4714 dw2_has_symbols (struct objfile
*objfile
)
4719 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4722 dw2_find_last_source_symtab
,
4723 dw2_forget_cached_source_info
,
4724 dw2_map_symtabs_matching_filename
,
4728 dw2_expand_symtabs_for_function
,
4729 dw2_expand_all_symtabs
,
4730 dw2_expand_symtabs_with_fullname
,
4731 dw2_map_matching_symbols
,
4732 dw2_expand_symtabs_matching
,
4733 dw2_find_pc_sect_compunit_symtab
,
4735 dw2_map_symbol_filenames
4738 /* DWARF-5 debug_names reader. */
4740 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4741 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4743 /* A helper function that reads the .debug_names section in SECTION
4744 and fills in MAP. FILENAME is the name of the file containing the
4745 section; it is used for error reporting.
4747 Returns true if all went well, false otherwise. */
4750 read_debug_names_from_section (struct objfile
*objfile
,
4751 const char *filename
,
4752 struct dwarf2_section_info
*section
,
4753 mapped_debug_names
&map
)
4755 if (section
->empty ())
4758 /* Older elfutils strip versions could keep the section in the main
4759 executable while splitting it for the separate debug info file. */
4760 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4763 section
->read (objfile
);
4765 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4767 const gdb_byte
*addr
= section
->buffer
;
4769 bfd
*const abfd
= section
->get_bfd_owner ();
4771 unsigned int bytes_read
;
4772 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4775 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4776 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4777 if (bytes_read
+ length
!= section
->size
)
4779 /* There may be multiple per-CU indices. */
4780 warning (_("Section .debug_names in %s length %s does not match "
4781 "section length %s, ignoring .debug_names."),
4782 filename
, plongest (bytes_read
+ length
),
4783 pulongest (section
->size
));
4787 /* The version number. */
4788 uint16_t version
= read_2_bytes (abfd
, addr
);
4792 warning (_("Section .debug_names in %s has unsupported version %d, "
4793 "ignoring .debug_names."),
4799 uint16_t padding
= read_2_bytes (abfd
, addr
);
4803 warning (_("Section .debug_names in %s has unsupported padding %d, "
4804 "ignoring .debug_names."),
4809 /* comp_unit_count - The number of CUs in the CU list. */
4810 map
.cu_count
= read_4_bytes (abfd
, addr
);
4813 /* local_type_unit_count - The number of TUs in the local TU
4815 map
.tu_count
= read_4_bytes (abfd
, addr
);
4818 /* foreign_type_unit_count - The number of TUs in the foreign TU
4820 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4822 if (foreign_tu_count
!= 0)
4824 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4825 "ignoring .debug_names."),
4826 filename
, static_cast<unsigned long> (foreign_tu_count
));
4830 /* bucket_count - The number of hash buckets in the hash lookup
4832 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4835 /* name_count - The number of unique names in the index. */
4836 map
.name_count
= read_4_bytes (abfd
, addr
);
4839 /* abbrev_table_size - The size in bytes of the abbreviations
4841 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4844 /* augmentation_string_size - The size in bytes of the augmentation
4845 string. This value is rounded up to a multiple of 4. */
4846 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4848 map
.augmentation_is_gdb
= ((augmentation_string_size
4849 == sizeof (dwarf5_augmentation
))
4850 && memcmp (addr
, dwarf5_augmentation
,
4851 sizeof (dwarf5_augmentation
)) == 0);
4852 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4853 addr
+= augmentation_string_size
;
4856 map
.cu_table_reordered
= addr
;
4857 addr
+= map
.cu_count
* map
.offset_size
;
4859 /* List of Local TUs */
4860 map
.tu_table_reordered
= addr
;
4861 addr
+= map
.tu_count
* map
.offset_size
;
4863 /* Hash Lookup Table */
4864 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4865 addr
+= map
.bucket_count
* 4;
4866 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4867 addr
+= map
.name_count
* 4;
4870 map
.name_table_string_offs_reordered
= addr
;
4871 addr
+= map
.name_count
* map
.offset_size
;
4872 map
.name_table_entry_offs_reordered
= addr
;
4873 addr
+= map
.name_count
* map
.offset_size
;
4875 const gdb_byte
*abbrev_table_start
= addr
;
4878 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4883 const auto insertpair
4884 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4885 if (!insertpair
.second
)
4887 warning (_("Section .debug_names in %s has duplicate index %s, "
4888 "ignoring .debug_names."),
4889 filename
, pulongest (index_num
));
4892 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4893 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4898 mapped_debug_names::index_val::attr attr
;
4899 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4901 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4903 if (attr
.form
== DW_FORM_implicit_const
)
4905 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4909 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4911 indexval
.attr_vec
.push_back (std::move (attr
));
4914 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4916 warning (_("Section .debug_names in %s has abbreviation_table "
4917 "of size %s vs. written as %u, ignoring .debug_names."),
4918 filename
, plongest (addr
- abbrev_table_start
),
4922 map
.entry_pool
= addr
;
4927 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4931 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4932 const mapped_debug_names
&map
,
4933 dwarf2_section_info
§ion
,
4936 sect_offset sect_off_prev
;
4937 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4939 sect_offset sect_off_next
;
4940 if (i
< map
.cu_count
)
4943 = (sect_offset
) (extract_unsigned_integer
4944 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4946 map
.dwarf5_byte_order
));
4949 sect_off_next
= (sect_offset
) section
.size
;
4952 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4953 dwarf2_per_cu_data
*per_cu
4954 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
4955 sect_off_prev
, length
);
4956 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
4958 sect_off_prev
= sect_off_next
;
4962 /* Read the CU list from the mapped index, and use it to create all
4963 the CU objects for this dwarf2_per_objfile. */
4966 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4967 const mapped_debug_names
&map
,
4968 const mapped_debug_names
&dwz_map
)
4970 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
4971 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4973 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
4974 dwarf2_per_objfile
->info
,
4975 false /* is_dwz */);
4977 if (dwz_map
.cu_count
== 0)
4980 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
4981 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
4985 /* Read .debug_names. If everything went ok, initialize the "quick"
4986 elements of all the CUs and return true. Otherwise, return false. */
4989 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
4991 std::unique_ptr
<mapped_debug_names
> map
4992 (new mapped_debug_names (dwarf2_per_objfile
));
4993 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
4994 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4996 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4997 &dwarf2_per_objfile
->debug_names
,
5001 /* Don't use the index if it's empty. */
5002 if (map
->name_count
== 0)
5005 /* If there is a .dwz file, read it so we can get its CU list as
5007 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5010 if (!read_debug_names_from_section (objfile
,
5011 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5012 &dwz
->debug_names
, dwz_map
))
5014 warning (_("could not read '.debug_names' section from %s; skipping"),
5015 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5020 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5022 if (map
->tu_count
!= 0)
5024 /* We can only handle a single .debug_types when we have an
5026 if (dwarf2_per_objfile
->types
.size () != 1)
5029 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5031 create_signatured_type_table_from_debug_names
5032 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5035 create_addrmap_from_aranges (dwarf2_per_objfile
,
5036 &dwarf2_per_objfile
->debug_aranges
);
5038 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5039 dwarf2_per_objfile
->using_index
= 1;
5040 dwarf2_per_objfile
->quick_file_names_table
=
5041 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5046 /* Type used to manage iterating over all CUs looking for a symbol for
5049 class dw2_debug_names_iterator
5052 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5053 gdb::optional
<block_enum
> block_index
,
5056 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5057 m_addr (find_vec_in_debug_names (map
, name
))
5060 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5061 search_domain search
, uint32_t namei
)
5064 m_addr (find_vec_in_debug_names (map
, namei
))
5067 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5068 block_enum block_index
, domain_enum domain
,
5070 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5071 m_addr (find_vec_in_debug_names (map
, namei
))
5074 /* Return the next matching CU or NULL if there are no more. */
5075 dwarf2_per_cu_data
*next ();
5078 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5080 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5083 /* The internalized form of .debug_names. */
5084 const mapped_debug_names
&m_map
;
5086 /* If set, only look for symbols that match that block. Valid values are
5087 GLOBAL_BLOCK and STATIC_BLOCK. */
5088 const gdb::optional
<block_enum
> m_block_index
;
5090 /* The kind of symbol we're looking for. */
5091 const domain_enum m_domain
= UNDEF_DOMAIN
;
5092 const search_domain m_search
= ALL_DOMAIN
;
5094 /* The list of CUs from the index entry of the symbol, or NULL if
5096 const gdb_byte
*m_addr
;
5100 mapped_debug_names::namei_to_name (uint32_t namei
) const
5102 const ULONGEST namei_string_offs
5103 = extract_unsigned_integer ((name_table_string_offs_reordered
5104 + namei
* offset_size
),
5107 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5111 /* Find a slot in .debug_names for the object named NAME. If NAME is
5112 found, return pointer to its pool data. If NAME cannot be found,
5116 dw2_debug_names_iterator::find_vec_in_debug_names
5117 (const mapped_debug_names
&map
, const char *name
)
5119 int (*cmp
) (const char *, const char *);
5121 gdb::unique_xmalloc_ptr
<char> without_params
;
5122 if (current_language
->la_language
== language_cplus
5123 || current_language
->la_language
== language_fortran
5124 || current_language
->la_language
== language_d
)
5126 /* NAME is already canonical. Drop any qualifiers as
5127 .debug_names does not contain any. */
5129 if (strchr (name
, '(') != NULL
)
5131 without_params
= cp_remove_params (name
);
5132 if (without_params
!= NULL
)
5133 name
= without_params
.get ();
5137 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5139 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5141 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5142 (map
.bucket_table_reordered
5143 + (full_hash
% map
.bucket_count
)), 4,
5144 map
.dwarf5_byte_order
);
5148 if (namei
>= map
.name_count
)
5150 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5152 namei
, map
.name_count
,
5153 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5159 const uint32_t namei_full_hash
5160 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5161 (map
.hash_table_reordered
+ namei
), 4,
5162 map
.dwarf5_byte_order
);
5163 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5166 if (full_hash
== namei_full_hash
)
5168 const char *const namei_string
= map
.namei_to_name (namei
);
5170 #if 0 /* An expensive sanity check. */
5171 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5173 complaint (_("Wrong .debug_names hash for string at index %u "
5175 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5180 if (cmp (namei_string
, name
) == 0)
5182 const ULONGEST namei_entry_offs
5183 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5184 + namei
* map
.offset_size
),
5185 map
.offset_size
, map
.dwarf5_byte_order
);
5186 return map
.entry_pool
+ namei_entry_offs
;
5191 if (namei
>= map
.name_count
)
5197 dw2_debug_names_iterator::find_vec_in_debug_names
5198 (const mapped_debug_names
&map
, uint32_t namei
)
5200 if (namei
>= map
.name_count
)
5202 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5204 namei
, map
.name_count
,
5205 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5209 const ULONGEST namei_entry_offs
5210 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5211 + namei
* map
.offset_size
),
5212 map
.offset_size
, map
.dwarf5_byte_order
);
5213 return map
.entry_pool
+ namei_entry_offs
;
5216 /* See dw2_debug_names_iterator. */
5218 dwarf2_per_cu_data
*
5219 dw2_debug_names_iterator::next ()
5224 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5225 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5226 bfd
*const abfd
= objfile
->obfd
;
5230 unsigned int bytes_read
;
5231 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5232 m_addr
+= bytes_read
;
5236 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5237 if (indexval_it
== m_map
.abbrev_map
.cend ())
5239 complaint (_("Wrong .debug_names undefined abbrev code %s "
5241 pulongest (abbrev
), objfile_name (objfile
));
5244 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5245 enum class symbol_linkage
{
5249 } symbol_linkage_
= symbol_linkage::unknown
;
5250 dwarf2_per_cu_data
*per_cu
= NULL
;
5251 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5256 case DW_FORM_implicit_const
:
5257 ull
= attr
.implicit_const
;
5259 case DW_FORM_flag_present
:
5263 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5264 m_addr
+= bytes_read
;
5267 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5268 dwarf_form_name (attr
.form
),
5269 objfile_name (objfile
));
5272 switch (attr
.dw_idx
)
5274 case DW_IDX_compile_unit
:
5275 /* Don't crash on bad data. */
5276 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5278 complaint (_(".debug_names entry has bad CU index %s"
5281 objfile_name (dwarf2_per_objfile
->objfile
));
5284 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5286 case DW_IDX_type_unit
:
5287 /* Don't crash on bad data. */
5288 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5290 complaint (_(".debug_names entry has bad TU index %s"
5293 objfile_name (dwarf2_per_objfile
->objfile
));
5296 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5298 case DW_IDX_GNU_internal
:
5299 if (!m_map
.augmentation_is_gdb
)
5301 symbol_linkage_
= symbol_linkage::static_
;
5303 case DW_IDX_GNU_external
:
5304 if (!m_map
.augmentation_is_gdb
)
5306 symbol_linkage_
= symbol_linkage::extern_
;
5311 /* Skip if already read in. */
5312 if (per_cu
->v
.quick
->compunit_symtab
)
5315 /* Check static vs global. */
5316 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5318 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5319 const bool symbol_is_static
=
5320 symbol_linkage_
== symbol_linkage::static_
;
5321 if (want_static
!= symbol_is_static
)
5325 /* Match dw2_symtab_iter_next, symbol_kind
5326 and debug_names::psymbol_tag. */
5330 switch (indexval
.dwarf_tag
)
5332 case DW_TAG_variable
:
5333 case DW_TAG_subprogram
:
5334 /* Some types are also in VAR_DOMAIN. */
5335 case DW_TAG_typedef
:
5336 case DW_TAG_structure_type
:
5343 switch (indexval
.dwarf_tag
)
5345 case DW_TAG_typedef
:
5346 case DW_TAG_structure_type
:
5353 switch (indexval
.dwarf_tag
)
5356 case DW_TAG_variable
:
5363 switch (indexval
.dwarf_tag
)
5375 /* Match dw2_expand_symtabs_matching, symbol_kind and
5376 debug_names::psymbol_tag. */
5379 case VARIABLES_DOMAIN
:
5380 switch (indexval
.dwarf_tag
)
5382 case DW_TAG_variable
:
5388 case FUNCTIONS_DOMAIN
:
5389 switch (indexval
.dwarf_tag
)
5391 case DW_TAG_subprogram
:
5398 switch (indexval
.dwarf_tag
)
5400 case DW_TAG_typedef
:
5401 case DW_TAG_structure_type
:
5407 case MODULES_DOMAIN
:
5408 switch (indexval
.dwarf_tag
)
5422 static struct compunit_symtab
*
5423 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5424 const char *name
, domain_enum domain
)
5426 struct dwarf2_per_objfile
*dwarf2_per_objfile
5427 = get_dwarf2_per_objfile (objfile
);
5429 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5432 /* index is NULL if OBJF_READNOW. */
5435 const auto &map
= *mapp
;
5437 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5439 struct compunit_symtab
*stab_best
= NULL
;
5440 struct dwarf2_per_cu_data
*per_cu
;
5441 while ((per_cu
= iter
.next ()) != NULL
)
5443 struct symbol
*sym
, *with_opaque
= NULL
;
5444 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5445 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5446 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5448 sym
= block_find_symbol (block
, name
, domain
,
5449 block_find_non_opaque_type_preferred
,
5452 /* Some caution must be observed with overloaded functions and
5453 methods, since the index will not contain any overload
5454 information (but NAME might contain it). */
5457 && strcmp_iw (sym
->search_name (), name
) == 0)
5459 if (with_opaque
!= NULL
5460 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5463 /* Keep looking through other CUs. */
5469 /* This dumps minimal information about .debug_names. It is called
5470 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5471 uses this to verify that .debug_names has been loaded. */
5474 dw2_debug_names_dump (struct objfile
*objfile
)
5476 struct dwarf2_per_objfile
*dwarf2_per_objfile
5477 = get_dwarf2_per_objfile (objfile
);
5479 gdb_assert (dwarf2_per_objfile
->using_index
);
5480 printf_filtered (".debug_names:");
5481 if (dwarf2_per_objfile
->debug_names_table
)
5482 printf_filtered (" exists\n");
5484 printf_filtered (" faked for \"readnow\"\n");
5485 printf_filtered ("\n");
5489 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5490 const char *func_name
)
5492 struct dwarf2_per_objfile
*dwarf2_per_objfile
5493 = get_dwarf2_per_objfile (objfile
);
5495 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5496 if (dwarf2_per_objfile
->debug_names_table
)
5498 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5500 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5502 struct dwarf2_per_cu_data
*per_cu
;
5503 while ((per_cu
= iter
.next ()) != NULL
)
5504 dw2_instantiate_symtab (per_cu
, false);
5509 dw2_debug_names_map_matching_symbols
5510 (struct objfile
*objfile
,
5511 const lookup_name_info
&name
, domain_enum domain
,
5513 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5514 symbol_compare_ftype
*ordered_compare
)
5516 struct dwarf2_per_objfile
*dwarf2_per_objfile
5517 = get_dwarf2_per_objfile (objfile
);
5519 /* debug_names_table is NULL if OBJF_READNOW. */
5520 if (!dwarf2_per_objfile
->debug_names_table
)
5523 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5524 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5526 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5527 auto matcher
= [&] (const char *symname
)
5529 if (ordered_compare
== nullptr)
5531 return ordered_compare (symname
, match_name
) == 0;
5534 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5535 [&] (offset_type namei
)
5537 /* The name was matched, now expand corresponding CUs that were
5539 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5541 struct dwarf2_per_cu_data
*per_cu
;
5542 while ((per_cu
= iter
.next ()) != NULL
)
5543 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5547 /* It's a shame we couldn't do this inside the
5548 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5549 that have already been expanded. Instead, this loop matches what
5550 the psymtab code does. */
5551 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5553 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5554 if (cust
!= nullptr)
5556 const struct block
*block
5557 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5558 if (!iterate_over_symbols_terminated (block
, name
,
5566 dw2_debug_names_expand_symtabs_matching
5567 (struct objfile
*objfile
,
5568 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5569 const lookup_name_info
&lookup_name
,
5570 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5571 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5572 enum search_domain kind
)
5574 struct dwarf2_per_objfile
*dwarf2_per_objfile
5575 = get_dwarf2_per_objfile (objfile
);
5577 /* debug_names_table is NULL if OBJF_READNOW. */
5578 if (!dwarf2_per_objfile
->debug_names_table
)
5581 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5583 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5585 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5587 kind
, [&] (offset_type namei
)
5589 /* The name was matched, now expand corresponding CUs that were
5591 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5593 struct dwarf2_per_cu_data
*per_cu
;
5594 while ((per_cu
= iter
.next ()) != NULL
)
5595 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5601 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5604 dw2_find_last_source_symtab
,
5605 dw2_forget_cached_source_info
,
5606 dw2_map_symtabs_matching_filename
,
5607 dw2_debug_names_lookup_symbol
,
5609 dw2_debug_names_dump
,
5610 dw2_debug_names_expand_symtabs_for_function
,
5611 dw2_expand_all_symtabs
,
5612 dw2_expand_symtabs_with_fullname
,
5613 dw2_debug_names_map_matching_symbols
,
5614 dw2_debug_names_expand_symtabs_matching
,
5615 dw2_find_pc_sect_compunit_symtab
,
5617 dw2_map_symbol_filenames
5620 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5621 to either a dwarf2_per_objfile or dwz_file object. */
5623 template <typename T
>
5624 static gdb::array_view
<const gdb_byte
>
5625 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5627 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5629 if (section
->empty ())
5632 /* Older elfutils strip versions could keep the section in the main
5633 executable while splitting it for the separate debug info file. */
5634 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5637 section
->read (obj
);
5639 /* dwarf2_section_info::size is a bfd_size_type, while
5640 gdb::array_view works with size_t. On 32-bit hosts, with
5641 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5642 is 32-bit. So we need an explicit narrowing conversion here.
5643 This is fine, because it's impossible to allocate or mmap an
5644 array/buffer larger than what size_t can represent. */
5645 return gdb::make_array_view (section
->buffer
, section
->size
);
5648 /* Lookup the index cache for the contents of the index associated to
5651 static gdb::array_view
<const gdb_byte
>
5652 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5654 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5655 if (build_id
== nullptr)
5658 return global_index_cache
.lookup_gdb_index (build_id
,
5659 &dwarf2_obj
->index_cache_res
);
5662 /* Same as the above, but for DWZ. */
5664 static gdb::array_view
<const gdb_byte
>
5665 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5667 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5668 if (build_id
== nullptr)
5671 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5674 /* See symfile.h. */
5677 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5679 struct dwarf2_per_objfile
*dwarf2_per_objfile
5680 = get_dwarf2_per_objfile (objfile
);
5682 /* If we're about to read full symbols, don't bother with the
5683 indices. In this case we also don't care if some other debug
5684 format is making psymtabs, because they are all about to be
5686 if ((objfile
->flags
& OBJF_READNOW
))
5688 dwarf2_per_objfile
->using_index
= 1;
5689 create_all_comp_units (dwarf2_per_objfile
);
5690 create_all_type_units (dwarf2_per_objfile
);
5691 dwarf2_per_objfile
->quick_file_names_table
5692 = create_quick_file_names_table
5693 (dwarf2_per_objfile
->all_comp_units
.size ());
5695 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5696 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5698 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5700 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5701 struct dwarf2_per_cu_quick_data
);
5704 /* Return 1 so that gdb sees the "quick" functions. However,
5705 these functions will be no-ops because we will have expanded
5707 *index_kind
= dw_index_kind::GDB_INDEX
;
5711 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5713 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5717 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5718 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5719 get_gdb_index_contents_from_section
<dwz_file
>))
5721 *index_kind
= dw_index_kind::GDB_INDEX
;
5725 /* ... otherwise, try to find the index in the index cache. */
5726 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5727 get_gdb_index_contents_from_cache
,
5728 get_gdb_index_contents_from_cache_dwz
))
5730 global_index_cache
.hit ();
5731 *index_kind
= dw_index_kind::GDB_INDEX
;
5735 global_index_cache
.miss ();
5741 /* Build a partial symbol table. */
5744 dwarf2_build_psymtabs (struct objfile
*objfile
)
5746 struct dwarf2_per_objfile
*dwarf2_per_objfile
5747 = get_dwarf2_per_objfile (objfile
);
5749 init_psymbol_list (objfile
, 1024);
5753 /* This isn't really ideal: all the data we allocate on the
5754 objfile's obstack is still uselessly kept around. However,
5755 freeing it seems unsafe. */
5756 psymtab_discarder
psymtabs (objfile
);
5757 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5760 /* (maybe) store an index in the cache. */
5761 global_index_cache
.store (dwarf2_per_objfile
);
5763 catch (const gdb_exception_error
&except
)
5765 exception_print (gdb_stderr
, except
);
5769 /* Find the base address of the compilation unit for range lists and
5770 location lists. It will normally be specified by DW_AT_low_pc.
5771 In DWARF-3 draft 4, the base address could be overridden by
5772 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5773 compilation units with discontinuous ranges. */
5776 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5778 struct attribute
*attr
;
5780 cu
->base_address
.reset ();
5782 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5783 if (attr
!= nullptr)
5784 cu
->base_address
= attr
->value_as_address ();
5787 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5788 if (attr
!= nullptr)
5789 cu
->base_address
= attr
->value_as_address ();
5793 /* Helper function that returns the proper abbrev section for
5796 static struct dwarf2_section_info
*
5797 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5799 struct dwarf2_section_info
*abbrev
;
5800 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5802 if (this_cu
->is_dwz
)
5803 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5805 abbrev
= &dwarf2_per_objfile
->abbrev
;
5810 /* Fetch the abbreviation table offset from a comp or type unit header. */
5813 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5814 struct dwarf2_section_info
*section
,
5815 sect_offset sect_off
)
5817 bfd
*abfd
= section
->get_bfd_owner ();
5818 const gdb_byte
*info_ptr
;
5819 unsigned int initial_length_size
, offset_size
;
5822 section
->read (dwarf2_per_objfile
->objfile
);
5823 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5824 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5825 offset_size
= initial_length_size
== 4 ? 4 : 8;
5826 info_ptr
+= initial_length_size
;
5828 version
= read_2_bytes (abfd
, info_ptr
);
5832 /* Skip unit type and address size. */
5836 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5839 /* A partial symtab that is used only for include files. */
5840 struct dwarf2_include_psymtab
: public partial_symtab
5842 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5843 : partial_symtab (filename
, objfile
)
5847 void read_symtab (struct objfile
*objfile
) override
5849 expand_psymtab (objfile
);
5852 void expand_psymtab (struct objfile
*objfile
) override
5856 /* It's an include file, no symbols to read for it.
5857 Everything is in the parent symtab. */
5858 read_dependencies (objfile
);
5862 bool readin_p () const override
5867 struct compunit_symtab
*get_compunit_symtab () const override
5874 bool m_readin
= false;
5877 /* Allocate a new partial symtab for file named NAME and mark this new
5878 partial symtab as being an include of PST. */
5881 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5882 struct objfile
*objfile
)
5884 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5886 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5888 /* It shares objfile->objfile_obstack. */
5889 subpst
->dirname
= pst
->dirname
;
5892 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5893 subpst
->dependencies
[0] = pst
;
5894 subpst
->number_of_dependencies
= 1;
5897 /* Read the Line Number Program data and extract the list of files
5898 included by the source file represented by PST. Build an include
5899 partial symtab for each of these included files. */
5902 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5903 struct die_info
*die
,
5904 dwarf2_psymtab
*pst
)
5907 struct attribute
*attr
;
5909 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5910 if (attr
!= nullptr)
5911 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5913 return; /* No linetable, so no includes. */
5915 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5916 that we pass in the raw text_low here; that is ok because we're
5917 only decoding the line table to make include partial symtabs, and
5918 so the addresses aren't really used. */
5919 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5920 pst
->raw_text_low (), 1);
5924 hash_signatured_type (const void *item
)
5926 const struct signatured_type
*sig_type
5927 = (const struct signatured_type
*) item
;
5929 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5930 return sig_type
->signature
;
5934 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5936 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5937 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5939 return lhs
->signature
== rhs
->signature
;
5942 /* Allocate a hash table for signatured types. */
5945 allocate_signatured_type_table ()
5947 return htab_up (htab_create_alloc (41,
5948 hash_signatured_type
,
5950 NULL
, xcalloc
, xfree
));
5953 /* A helper function to add a signatured type CU to a table. */
5956 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5958 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5959 std::vector
<signatured_type
*> *all_type_units
5960 = (std::vector
<signatured_type
*> *) datum
;
5962 all_type_units
->push_back (sigt
);
5967 /* A helper for create_debug_types_hash_table. Read types from SECTION
5968 and fill them into TYPES_HTAB. It will process only type units,
5969 therefore DW_UT_type. */
5972 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5973 struct dwo_file
*dwo_file
,
5974 dwarf2_section_info
*section
, htab_up
&types_htab
,
5975 rcuh_kind section_kind
)
5977 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5978 struct dwarf2_section_info
*abbrev_section
;
5980 const gdb_byte
*info_ptr
, *end_ptr
;
5982 abbrev_section
= (dwo_file
!= NULL
5983 ? &dwo_file
->sections
.abbrev
5984 : &dwarf2_per_objfile
->abbrev
);
5986 if (dwarf_read_debug
)
5987 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
5988 section
->get_name (),
5989 abbrev_section
->get_file_name ());
5991 section
->read (objfile
);
5992 info_ptr
= section
->buffer
;
5994 if (info_ptr
== NULL
)
5997 /* We can't set abfd until now because the section may be empty or
5998 not present, in which case the bfd is unknown. */
5999 abfd
= section
->get_bfd_owner ();
6001 /* We don't use cutu_reader here because we don't need to read
6002 any dies: the signature is in the header. */
6004 end_ptr
= info_ptr
+ section
->size
;
6005 while (info_ptr
< end_ptr
)
6007 struct signatured_type
*sig_type
;
6008 struct dwo_unit
*dwo_tu
;
6010 const gdb_byte
*ptr
= info_ptr
;
6011 struct comp_unit_head header
;
6012 unsigned int length
;
6014 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6016 /* Initialize it due to a false compiler warning. */
6017 header
.signature
= -1;
6018 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6020 /* We need to read the type's signature in order to build the hash
6021 table, but we don't need anything else just yet. */
6023 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6024 abbrev_section
, ptr
, section_kind
);
6026 length
= header
.get_length ();
6028 /* Skip dummy type units. */
6029 if (ptr
>= info_ptr
+ length
6030 || peek_abbrev_code (abfd
, ptr
) == 0
6031 || header
.unit_type
!= DW_UT_type
)
6037 if (types_htab
== NULL
)
6040 types_htab
= allocate_dwo_unit_table ();
6042 types_htab
= allocate_signatured_type_table ();
6048 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6050 dwo_tu
->dwo_file
= dwo_file
;
6051 dwo_tu
->signature
= header
.signature
;
6052 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6053 dwo_tu
->section
= section
;
6054 dwo_tu
->sect_off
= sect_off
;
6055 dwo_tu
->length
= length
;
6059 /* N.B.: type_offset is not usable if this type uses a DWO file.
6060 The real type_offset is in the DWO file. */
6062 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6063 struct signatured_type
);
6064 sig_type
->signature
= header
.signature
;
6065 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6066 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6067 sig_type
->per_cu
.is_debug_types
= 1;
6068 sig_type
->per_cu
.section
= section
;
6069 sig_type
->per_cu
.sect_off
= sect_off
;
6070 sig_type
->per_cu
.length
= length
;
6073 slot
= htab_find_slot (types_htab
.get (),
6074 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6076 gdb_assert (slot
!= NULL
);
6079 sect_offset dup_sect_off
;
6083 const struct dwo_unit
*dup_tu
6084 = (const struct dwo_unit
*) *slot
;
6086 dup_sect_off
= dup_tu
->sect_off
;
6090 const struct signatured_type
*dup_tu
6091 = (const struct signatured_type
*) *slot
;
6093 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6096 complaint (_("debug type entry at offset %s is duplicate to"
6097 " the entry at offset %s, signature %s"),
6098 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6099 hex_string (header
.signature
));
6101 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6103 if (dwarf_read_debug
> 1)
6104 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6105 sect_offset_str (sect_off
),
6106 hex_string (header
.signature
));
6112 /* Create the hash table of all entries in the .debug_types
6113 (or .debug_types.dwo) section(s).
6114 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6115 otherwise it is NULL.
6117 The result is a pointer to the hash table or NULL if there are no types.
6119 Note: This function processes DWO files only, not DWP files. */
6122 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6123 struct dwo_file
*dwo_file
,
6124 gdb::array_view
<dwarf2_section_info
> type_sections
,
6125 htab_up
&types_htab
)
6127 for (dwarf2_section_info
§ion
: type_sections
)
6128 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6129 types_htab
, rcuh_kind::TYPE
);
6132 /* Create the hash table of all entries in the .debug_types section,
6133 and initialize all_type_units.
6134 The result is zero if there is an error (e.g. missing .debug_types section),
6135 otherwise non-zero. */
6138 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6142 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6143 &dwarf2_per_objfile
->info
, types_htab
,
6144 rcuh_kind::COMPILE
);
6145 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6146 dwarf2_per_objfile
->types
, types_htab
);
6147 if (types_htab
== NULL
)
6149 dwarf2_per_objfile
->signatured_types
= NULL
;
6153 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6155 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6156 dwarf2_per_objfile
->all_type_units
.reserve
6157 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6159 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6160 add_signatured_type_cu_to_table
,
6161 &dwarf2_per_objfile
->all_type_units
);
6166 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6167 If SLOT is non-NULL, it is the entry to use in the hash table.
6168 Otherwise we find one. */
6170 static struct signatured_type
*
6171 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6174 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6176 if (dwarf2_per_objfile
->all_type_units
.size ()
6177 == dwarf2_per_objfile
->all_type_units
.capacity ())
6178 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6180 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6181 struct signatured_type
);
6183 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6184 sig_type
->signature
= sig
;
6185 sig_type
->per_cu
.is_debug_types
= 1;
6186 if (dwarf2_per_objfile
->using_index
)
6188 sig_type
->per_cu
.v
.quick
=
6189 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6190 struct dwarf2_per_cu_quick_data
);
6195 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6198 gdb_assert (*slot
== NULL
);
6200 /* The rest of sig_type must be filled in by the caller. */
6204 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6205 Fill in SIG_ENTRY with DWO_ENTRY. */
6208 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6209 struct signatured_type
*sig_entry
,
6210 struct dwo_unit
*dwo_entry
)
6212 /* Make sure we're not clobbering something we don't expect to. */
6213 gdb_assert (! sig_entry
->per_cu
.queued
);
6214 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6215 if (dwarf2_per_objfile
->using_index
)
6217 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6218 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6221 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6222 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6223 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6224 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6225 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6227 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6228 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6229 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6230 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6231 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6232 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6233 sig_entry
->dwo_unit
= dwo_entry
;
6236 /* Subroutine of lookup_signatured_type.
6237 If we haven't read the TU yet, create the signatured_type data structure
6238 for a TU to be read in directly from a DWO file, bypassing the stub.
6239 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6240 using .gdb_index, then when reading a CU we want to stay in the DWO file
6241 containing that CU. Otherwise we could end up reading several other DWO
6242 files (due to comdat folding) to process the transitive closure of all the
6243 mentioned TUs, and that can be slow. The current DWO file will have every
6244 type signature that it needs.
6245 We only do this for .gdb_index because in the psymtab case we already have
6246 to read all the DWOs to build the type unit groups. */
6248 static struct signatured_type
*
6249 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6251 struct dwarf2_per_objfile
*dwarf2_per_objfile
6252 = cu
->per_cu
->dwarf2_per_objfile
;
6253 struct dwo_file
*dwo_file
;
6254 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6255 struct signatured_type find_sig_entry
, *sig_entry
;
6258 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6260 /* If TU skeletons have been removed then we may not have read in any
6262 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6263 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6265 /* We only ever need to read in one copy of a signatured type.
6266 Use the global signatured_types array to do our own comdat-folding
6267 of types. If this is the first time we're reading this TU, and
6268 the TU has an entry in .gdb_index, replace the recorded data from
6269 .gdb_index with this TU. */
6271 find_sig_entry
.signature
= sig
;
6272 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6273 &find_sig_entry
, INSERT
);
6274 sig_entry
= (struct signatured_type
*) *slot
;
6276 /* We can get here with the TU already read, *or* in the process of being
6277 read. Don't reassign the global entry to point to this DWO if that's
6278 the case. Also note that if the TU is already being read, it may not
6279 have come from a DWO, the program may be a mix of Fission-compiled
6280 code and non-Fission-compiled code. */
6282 /* Have we already tried to read this TU?
6283 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6284 needn't exist in the global table yet). */
6285 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6288 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6289 dwo_unit of the TU itself. */
6290 dwo_file
= cu
->dwo_unit
->dwo_file
;
6292 /* Ok, this is the first time we're reading this TU. */
6293 if (dwo_file
->tus
== NULL
)
6295 find_dwo_entry
.signature
= sig
;
6296 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6298 if (dwo_entry
== NULL
)
6301 /* If the global table doesn't have an entry for this TU, add one. */
6302 if (sig_entry
== NULL
)
6303 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6305 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6306 sig_entry
->per_cu
.tu_read
= 1;
6310 /* Subroutine of lookup_signatured_type.
6311 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6312 then try the DWP file. If the TU stub (skeleton) has been removed then
6313 it won't be in .gdb_index. */
6315 static struct signatured_type
*
6316 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6318 struct dwarf2_per_objfile
*dwarf2_per_objfile
6319 = cu
->per_cu
->dwarf2_per_objfile
;
6320 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6321 struct dwo_unit
*dwo_entry
;
6322 struct signatured_type find_sig_entry
, *sig_entry
;
6325 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6326 gdb_assert (dwp_file
!= NULL
);
6328 /* If TU skeletons have been removed then we may not have read in any
6330 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6331 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6333 find_sig_entry
.signature
= sig
;
6334 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6335 &find_sig_entry
, INSERT
);
6336 sig_entry
= (struct signatured_type
*) *slot
;
6338 /* Have we already tried to read this TU?
6339 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6340 needn't exist in the global table yet). */
6341 if (sig_entry
!= NULL
)
6344 if (dwp_file
->tus
== NULL
)
6346 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6347 sig
, 1 /* is_debug_types */);
6348 if (dwo_entry
== NULL
)
6351 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6352 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6357 /* Lookup a signature based type for DW_FORM_ref_sig8.
6358 Returns NULL if signature SIG is not present in the table.
6359 It is up to the caller to complain about this. */
6361 static struct signatured_type
*
6362 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6364 struct dwarf2_per_objfile
*dwarf2_per_objfile
6365 = cu
->per_cu
->dwarf2_per_objfile
;
6368 && dwarf2_per_objfile
->using_index
)
6370 /* We're in a DWO/DWP file, and we're using .gdb_index.
6371 These cases require special processing. */
6372 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6373 return lookup_dwo_signatured_type (cu
, sig
);
6375 return lookup_dwp_signatured_type (cu
, sig
);
6379 struct signatured_type find_entry
, *entry
;
6381 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6383 find_entry
.signature
= sig
;
6384 entry
= ((struct signatured_type
*)
6385 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6391 /* Return the address base of the compile unit, which, if exists, is stored
6392 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6393 static gdb::optional
<ULONGEST
>
6394 lookup_addr_base (struct die_info
*comp_unit_die
)
6396 struct attribute
*attr
;
6397 attr
= comp_unit_die
->attr (DW_AT_addr_base
);
6398 if (attr
== nullptr)
6399 attr
= comp_unit_die
->attr (DW_AT_GNU_addr_base
);
6400 if (attr
== nullptr)
6401 return gdb::optional
<ULONGEST
> ();
6402 return DW_UNSND (attr
);
6405 /* Return range lists base of the compile unit, which, if exists, is stored
6406 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6408 lookup_ranges_base (struct die_info
*comp_unit_die
)
6410 struct attribute
*attr
;
6411 attr
= comp_unit_die
->attr (DW_AT_rnglists_base
);
6412 if (attr
== nullptr)
6413 attr
= comp_unit_die
->attr (DW_AT_GNU_ranges_base
);
6414 if (attr
== nullptr)
6416 return DW_UNSND (attr
);
6419 /* Low level DIE reading support. */
6421 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6424 init_cu_die_reader (struct die_reader_specs
*reader
,
6425 struct dwarf2_cu
*cu
,
6426 struct dwarf2_section_info
*section
,
6427 struct dwo_file
*dwo_file
,
6428 struct abbrev_table
*abbrev_table
)
6430 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6431 reader
->abfd
= section
->get_bfd_owner ();
6433 reader
->dwo_file
= dwo_file
;
6434 reader
->die_section
= section
;
6435 reader
->buffer
= section
->buffer
;
6436 reader
->buffer_end
= section
->buffer
+ section
->size
;
6437 reader
->abbrev_table
= abbrev_table
;
6440 /* Subroutine of cutu_reader to simplify it.
6441 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6442 There's just a lot of work to do, and cutu_reader is big enough
6445 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6446 from it to the DIE in the DWO. If NULL we are skipping the stub.
6447 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6448 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6449 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6450 STUB_COMP_DIR may be non-NULL.
6451 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6452 are filled in with the info of the DIE from the DWO file.
6453 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6454 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6455 kept around for at least as long as *RESULT_READER.
6457 The result is non-zero if a valid (non-dummy) DIE was found. */
6460 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6461 struct dwo_unit
*dwo_unit
,
6462 struct die_info
*stub_comp_unit_die
,
6463 const char *stub_comp_dir
,
6464 struct die_reader_specs
*result_reader
,
6465 const gdb_byte
**result_info_ptr
,
6466 struct die_info
**result_comp_unit_die
,
6467 abbrev_table_up
*result_dwo_abbrev_table
)
6469 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6470 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6471 struct dwarf2_cu
*cu
= this_cu
->cu
;
6473 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6474 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6475 int i
,num_extra_attrs
;
6476 struct dwarf2_section_info
*dwo_abbrev_section
;
6477 struct die_info
*comp_unit_die
;
6479 /* At most one of these may be provided. */
6480 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6482 /* These attributes aren't processed until later:
6483 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6484 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6485 referenced later. However, these attributes are found in the stub
6486 which we won't have later. In order to not impose this complication
6487 on the rest of the code, we read them here and copy them to the
6496 if (stub_comp_unit_die
!= NULL
)
6498 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6500 if (! this_cu
->is_debug_types
)
6501 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6502 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6503 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6504 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6505 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6507 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6509 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6510 here (if needed). We need the value before we can process
6512 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6514 else if (stub_comp_dir
!= NULL
)
6516 /* Reconstruct the comp_dir attribute to simplify the code below. */
6517 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6518 comp_dir
->name
= DW_AT_comp_dir
;
6519 comp_dir
->form
= DW_FORM_string
;
6520 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6521 DW_STRING (comp_dir
) = stub_comp_dir
;
6524 /* Set up for reading the DWO CU/TU. */
6525 cu
->dwo_unit
= dwo_unit
;
6526 dwarf2_section_info
*section
= dwo_unit
->section
;
6527 section
->read (objfile
);
6528 abfd
= section
->get_bfd_owner ();
6529 begin_info_ptr
= info_ptr
= (section
->buffer
6530 + to_underlying (dwo_unit
->sect_off
));
6531 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6533 if (this_cu
->is_debug_types
)
6535 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6537 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6538 &cu
->header
, section
,
6540 info_ptr
, rcuh_kind::TYPE
);
6541 /* This is not an assert because it can be caused by bad debug info. */
6542 if (sig_type
->signature
!= cu
->header
.signature
)
6544 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6545 " TU at offset %s [in module %s]"),
6546 hex_string (sig_type
->signature
),
6547 hex_string (cu
->header
.signature
),
6548 sect_offset_str (dwo_unit
->sect_off
),
6549 bfd_get_filename (abfd
));
6551 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6552 /* For DWOs coming from DWP files, we don't know the CU length
6553 nor the type's offset in the TU until now. */
6554 dwo_unit
->length
= cu
->header
.get_length ();
6555 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6557 /* Establish the type offset that can be used to lookup the type.
6558 For DWO files, we don't know it until now. */
6559 sig_type
->type_offset_in_section
6560 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6564 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6565 &cu
->header
, section
,
6567 info_ptr
, rcuh_kind::COMPILE
);
6568 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6569 /* For DWOs coming from DWP files, we don't know the CU length
6571 dwo_unit
->length
= cu
->header
.get_length ();
6574 *result_dwo_abbrev_table
6575 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6576 cu
->header
.abbrev_sect_off
);
6577 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6578 result_dwo_abbrev_table
->get ());
6580 /* Read in the die, but leave space to copy over the attributes
6581 from the stub. This has the benefit of simplifying the rest of
6582 the code - all the work to maintain the illusion of a single
6583 DW_TAG_{compile,type}_unit DIE is done here. */
6584 num_extra_attrs
= ((stmt_list
!= NULL
)
6588 + (comp_dir
!= NULL
));
6589 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6592 /* Copy over the attributes from the stub to the DIE we just read in. */
6593 comp_unit_die
= *result_comp_unit_die
;
6594 i
= comp_unit_die
->num_attrs
;
6595 if (stmt_list
!= NULL
)
6596 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6598 comp_unit_die
->attrs
[i
++] = *low_pc
;
6599 if (high_pc
!= NULL
)
6600 comp_unit_die
->attrs
[i
++] = *high_pc
;
6602 comp_unit_die
->attrs
[i
++] = *ranges
;
6603 if (comp_dir
!= NULL
)
6604 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6605 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6607 if (dwarf_die_debug
)
6609 fprintf_unfiltered (gdb_stdlog
,
6610 "Read die from %s@0x%x of %s:\n",
6611 section
->get_name (),
6612 (unsigned) (begin_info_ptr
- section
->buffer
),
6613 bfd_get_filename (abfd
));
6614 dump_die (comp_unit_die
, dwarf_die_debug
);
6617 /* Skip dummy compilation units. */
6618 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6619 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6622 *result_info_ptr
= info_ptr
;
6626 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6627 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6628 signature is part of the header. */
6629 static gdb::optional
<ULONGEST
>
6630 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6632 if (cu
->header
.version
>= 5)
6633 return cu
->header
.signature
;
6634 struct attribute
*attr
;
6635 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6636 if (attr
== nullptr)
6637 return gdb::optional
<ULONGEST
> ();
6638 return DW_UNSND (attr
);
6641 /* Subroutine of cutu_reader to simplify it.
6642 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6643 Returns NULL if the specified DWO unit cannot be found. */
6645 static struct dwo_unit
*
6646 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6647 struct die_info
*comp_unit_die
,
6648 const char *dwo_name
)
6650 struct dwarf2_cu
*cu
= this_cu
->cu
;
6651 struct dwo_unit
*dwo_unit
;
6652 const char *comp_dir
;
6654 gdb_assert (cu
!= NULL
);
6656 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6657 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6658 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6660 if (this_cu
->is_debug_types
)
6662 struct signatured_type
*sig_type
;
6664 /* Since this_cu is the first member of struct signatured_type,
6665 we can go from a pointer to one to a pointer to the other. */
6666 sig_type
= (struct signatured_type
*) this_cu
;
6667 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6671 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6672 if (!signature
.has_value ())
6673 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6675 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6676 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6683 /* Subroutine of cutu_reader to simplify it.
6684 See it for a description of the parameters.
6685 Read a TU directly from a DWO file, bypassing the stub. */
6688 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6689 int use_existing_cu
)
6691 struct signatured_type
*sig_type
;
6693 /* Verify we can do the following downcast, and that we have the
6695 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6696 sig_type
= (struct signatured_type
*) this_cu
;
6697 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6699 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6701 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6702 /* There's no need to do the rereading_dwo_cu handling that
6703 cutu_reader does since we don't read the stub. */
6707 /* If !use_existing_cu, this_cu->cu must be NULL. */
6708 gdb_assert (this_cu
->cu
== NULL
);
6709 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6712 /* A future optimization, if needed, would be to use an existing
6713 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6714 could share abbrev tables. */
6716 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6717 NULL
/* stub_comp_unit_die */,
6718 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6721 &m_dwo_abbrev_table
) == 0)
6728 /* Initialize a CU (or TU) and read its DIEs.
6729 If the CU defers to a DWO file, read the DWO file as well.
6731 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6732 Otherwise the table specified in the comp unit header is read in and used.
6733 This is an optimization for when we already have the abbrev table.
6735 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6736 Otherwise, a new CU is allocated with xmalloc. */
6738 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6739 struct abbrev_table
*abbrev_table
,
6740 int use_existing_cu
,
6742 : die_reader_specs
{},
6745 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6746 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6747 struct dwarf2_section_info
*section
= this_cu
->section
;
6748 bfd
*abfd
= section
->get_bfd_owner ();
6749 struct dwarf2_cu
*cu
;
6750 const gdb_byte
*begin_info_ptr
;
6751 struct signatured_type
*sig_type
= NULL
;
6752 struct dwarf2_section_info
*abbrev_section
;
6753 /* Non-zero if CU currently points to a DWO file and we need to
6754 reread it. When this happens we need to reread the skeleton die
6755 before we can reread the DWO file (this only applies to CUs, not TUs). */
6756 int rereading_dwo_cu
= 0;
6758 if (dwarf_die_debug
)
6759 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6760 this_cu
->is_debug_types
? "type" : "comp",
6761 sect_offset_str (this_cu
->sect_off
));
6763 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6764 file (instead of going through the stub), short-circuit all of this. */
6765 if (this_cu
->reading_dwo_directly
)
6767 /* Narrow down the scope of possibilities to have to understand. */
6768 gdb_assert (this_cu
->is_debug_types
);
6769 gdb_assert (abbrev_table
== NULL
);
6770 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6774 /* This is cheap if the section is already read in. */
6775 section
->read (objfile
);
6777 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6779 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6781 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6784 /* If this CU is from a DWO file we need to start over, we need to
6785 refetch the attributes from the skeleton CU.
6786 This could be optimized by retrieving those attributes from when we
6787 were here the first time: the previous comp_unit_die was stored in
6788 comp_unit_obstack. But there's no data yet that we need this
6790 if (cu
->dwo_unit
!= NULL
)
6791 rereading_dwo_cu
= 1;
6795 /* If !use_existing_cu, this_cu->cu must be NULL. */
6796 gdb_assert (this_cu
->cu
== NULL
);
6797 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6798 cu
= m_new_cu
.get ();
6801 /* Get the header. */
6802 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6804 /* We already have the header, there's no need to read it in again. */
6805 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6809 if (this_cu
->is_debug_types
)
6811 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6812 &cu
->header
, section
,
6813 abbrev_section
, info_ptr
,
6816 /* Since per_cu is the first member of struct signatured_type,
6817 we can go from a pointer to one to a pointer to the other. */
6818 sig_type
= (struct signatured_type
*) this_cu
;
6819 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6820 gdb_assert (sig_type
->type_offset_in_tu
6821 == cu
->header
.type_cu_offset_in_tu
);
6822 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6824 /* LENGTH has not been set yet for type units if we're
6825 using .gdb_index. */
6826 this_cu
->length
= cu
->header
.get_length ();
6828 /* Establish the type offset that can be used to lookup the type. */
6829 sig_type
->type_offset_in_section
=
6830 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6832 this_cu
->dwarf_version
= cu
->header
.version
;
6836 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6837 &cu
->header
, section
,
6840 rcuh_kind::COMPILE
);
6842 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6843 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6844 this_cu
->dwarf_version
= cu
->header
.version
;
6848 /* Skip dummy compilation units. */
6849 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6850 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6856 /* If we don't have them yet, read the abbrevs for this compilation unit.
6857 And if we need to read them now, make sure they're freed when we're
6859 if (abbrev_table
!= NULL
)
6860 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6863 m_abbrev_table_holder
6864 = abbrev_table::read (objfile
, abbrev_section
,
6865 cu
->header
.abbrev_sect_off
);
6866 abbrev_table
= m_abbrev_table_holder
.get ();
6869 /* Read the top level CU/TU die. */
6870 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6871 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6873 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6879 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6880 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6881 table from the DWO file and pass the ownership over to us. It will be
6882 referenced from READER, so we must make sure to free it after we're done
6885 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6886 DWO CU, that this test will fail (the attribute will not be present). */
6887 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6888 if (dwo_name
!= nullptr)
6890 struct dwo_unit
*dwo_unit
;
6891 struct die_info
*dwo_comp_unit_die
;
6893 if (comp_unit_die
->has_children
)
6895 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6896 " has children (offset %s) [in module %s]"),
6897 sect_offset_str (this_cu
->sect_off
),
6898 bfd_get_filename (abfd
));
6900 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6901 if (dwo_unit
!= NULL
)
6903 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6904 comp_unit_die
, NULL
,
6907 &m_dwo_abbrev_table
) == 0)
6913 comp_unit_die
= dwo_comp_unit_die
;
6917 /* Yikes, we couldn't find the rest of the DIE, we only have
6918 the stub. A complaint has already been logged. There's
6919 not much more we can do except pass on the stub DIE to
6920 die_reader_func. We don't want to throw an error on bad
6927 cutu_reader::keep ()
6929 /* Done, clean up. */
6930 gdb_assert (!dummy_p
);
6931 if (m_new_cu
!= NULL
)
6933 struct dwarf2_per_objfile
*dwarf2_per_objfile
6934 = m_this_cu
->dwarf2_per_objfile
;
6935 /* Link this CU into read_in_chain. */
6936 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6937 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6938 /* The chain owns it now. */
6939 m_new_cu
.release ();
6943 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6944 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6945 assumed to have already done the lookup to find the DWO file).
6947 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6948 THIS_CU->is_debug_types, but nothing else.
6950 We fill in THIS_CU->length.
6952 THIS_CU->cu is always freed when done.
6953 This is done in order to not leave THIS_CU->cu in a state where we have
6954 to care whether it refers to the "main" CU or the DWO CU.
6956 When parent_cu is passed, it is used to provide a default value for
6957 str_offsets_base and addr_base from the parent. */
6959 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6960 struct dwarf2_cu
*parent_cu
,
6961 struct dwo_file
*dwo_file
)
6962 : die_reader_specs
{},
6965 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6966 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6967 struct dwarf2_section_info
*section
= this_cu
->section
;
6968 bfd
*abfd
= section
->get_bfd_owner ();
6969 struct dwarf2_section_info
*abbrev_section
;
6970 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6972 if (dwarf_die_debug
)
6973 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6974 this_cu
->is_debug_types
? "type" : "comp",
6975 sect_offset_str (this_cu
->sect_off
));
6977 gdb_assert (this_cu
->cu
== NULL
);
6979 abbrev_section
= (dwo_file
!= NULL
6980 ? &dwo_file
->sections
.abbrev
6981 : get_abbrev_section_for_cu (this_cu
));
6983 /* This is cheap if the section is already read in. */
6984 section
->read (objfile
);
6986 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6988 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6989 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6990 &m_new_cu
->header
, section
,
6991 abbrev_section
, info_ptr
,
6992 (this_cu
->is_debug_types
6994 : rcuh_kind::COMPILE
));
6996 if (parent_cu
!= nullptr)
6998 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6999 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7001 this_cu
->length
= m_new_cu
->header
.get_length ();
7003 /* Skip dummy compilation units. */
7004 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7005 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7011 m_abbrev_table_holder
7012 = abbrev_table::read (objfile
, abbrev_section
,
7013 m_new_cu
->header
.abbrev_sect_off
);
7015 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7016 m_abbrev_table_holder
.get ());
7017 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7021 /* Type Unit Groups.
7023 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7024 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7025 so that all types coming from the same compilation (.o file) are grouped
7026 together. A future step could be to put the types in the same symtab as
7027 the CU the types ultimately came from. */
7030 hash_type_unit_group (const void *item
)
7032 const struct type_unit_group
*tu_group
7033 = (const struct type_unit_group
*) item
;
7035 return hash_stmt_list_entry (&tu_group
->hash
);
7039 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7041 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7042 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7044 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7047 /* Allocate a hash table for type unit groups. */
7050 allocate_type_unit_groups_table ()
7052 return htab_up (htab_create_alloc (3,
7053 hash_type_unit_group
,
7055 NULL
, xcalloc
, xfree
));
7058 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7059 partial symtabs. We combine several TUs per psymtab to not let the size
7060 of any one psymtab grow too big. */
7061 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7062 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7064 /* Helper routine for get_type_unit_group.
7065 Create the type_unit_group object used to hold one or more TUs. */
7067 static struct type_unit_group
*
7068 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7070 struct dwarf2_per_objfile
*dwarf2_per_objfile
7071 = cu
->per_cu
->dwarf2_per_objfile
;
7072 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7073 struct dwarf2_per_cu_data
*per_cu
;
7074 struct type_unit_group
*tu_group
;
7076 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7077 struct type_unit_group
);
7078 per_cu
= &tu_group
->per_cu
;
7079 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7081 if (dwarf2_per_objfile
->using_index
)
7083 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7084 struct dwarf2_per_cu_quick_data
);
7088 unsigned int line_offset
= to_underlying (line_offset_struct
);
7089 dwarf2_psymtab
*pst
;
7092 /* Give the symtab a useful name for debug purposes. */
7093 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7094 name
= string_printf ("<type_units_%d>",
7095 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7097 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7099 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7100 pst
->anonymous
= true;
7103 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7104 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7109 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7110 STMT_LIST is a DW_AT_stmt_list attribute. */
7112 static struct type_unit_group
*
7113 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7115 struct dwarf2_per_objfile
*dwarf2_per_objfile
7116 = cu
->per_cu
->dwarf2_per_objfile
;
7117 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7118 struct type_unit_group
*tu_group
;
7120 unsigned int line_offset
;
7121 struct type_unit_group type_unit_group_for_lookup
;
7123 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7124 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7126 /* Do we need to create a new group, or can we use an existing one? */
7130 line_offset
= DW_UNSND (stmt_list
);
7131 ++tu_stats
->nr_symtab_sharers
;
7135 /* Ugh, no stmt_list. Rare, but we have to handle it.
7136 We can do various things here like create one group per TU or
7137 spread them over multiple groups to split up the expansion work.
7138 To avoid worst case scenarios (too many groups or too large groups)
7139 we, umm, group them in bunches. */
7140 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7141 | (tu_stats
->nr_stmt_less_type_units
7142 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7143 ++tu_stats
->nr_stmt_less_type_units
;
7146 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7147 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7148 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7149 &type_unit_group_for_lookup
, INSERT
);
7152 tu_group
= (struct type_unit_group
*) *slot
;
7153 gdb_assert (tu_group
!= NULL
);
7157 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7158 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7160 ++tu_stats
->nr_symtabs
;
7166 /* Partial symbol tables. */
7168 /* Create a psymtab named NAME and assign it to PER_CU.
7170 The caller must fill in the following details:
7171 dirname, textlow, texthigh. */
7173 static dwarf2_psymtab
*
7174 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7176 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7177 dwarf2_psymtab
*pst
;
7179 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7181 pst
->psymtabs_addrmap_supported
= true;
7183 /* This is the glue that links PST into GDB's symbol API. */
7184 pst
->per_cu_data
= per_cu
;
7185 per_cu
->v
.psymtab
= pst
;
7190 /* DIE reader function for process_psymtab_comp_unit. */
7193 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7194 const gdb_byte
*info_ptr
,
7195 struct die_info
*comp_unit_die
,
7196 enum language pretend_language
)
7198 struct dwarf2_cu
*cu
= reader
->cu
;
7199 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7200 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7201 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7203 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7204 dwarf2_psymtab
*pst
;
7205 enum pc_bounds_kind cu_bounds_kind
;
7206 const char *filename
;
7208 gdb_assert (! per_cu
->is_debug_types
);
7210 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7212 /* Allocate a new partial symbol table structure. */
7213 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7214 static const char artificial
[] = "<artificial>";
7215 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7216 if (filename
== NULL
)
7218 else if (strcmp (filename
, artificial
) == 0)
7220 debug_filename
.reset (concat (artificial
, "@",
7221 sect_offset_str (per_cu
->sect_off
),
7223 filename
= debug_filename
.get ();
7226 pst
= create_partial_symtab (per_cu
, filename
);
7228 /* This must be done before calling dwarf2_build_include_psymtabs. */
7229 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7231 baseaddr
= objfile
->text_section_offset ();
7233 dwarf2_find_base_address (comp_unit_die
, cu
);
7235 /* Possibly set the default values of LOWPC and HIGHPC from
7237 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7238 &best_highpc
, cu
, pst
);
7239 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7242 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7245 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7247 /* Store the contiguous range if it is not empty; it can be
7248 empty for CUs with no code. */
7249 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7253 /* Check if comp unit has_children.
7254 If so, read the rest of the partial symbols from this comp unit.
7255 If not, there's no more debug_info for this comp unit. */
7256 if (comp_unit_die
->has_children
)
7258 struct partial_die_info
*first_die
;
7259 CORE_ADDR lowpc
, highpc
;
7261 lowpc
= ((CORE_ADDR
) -1);
7262 highpc
= ((CORE_ADDR
) 0);
7264 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7266 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7267 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7269 /* If we didn't find a lowpc, set it to highpc to avoid
7270 complaints from `maint check'. */
7271 if (lowpc
== ((CORE_ADDR
) -1))
7274 /* If the compilation unit didn't have an explicit address range,
7275 then use the information extracted from its child dies. */
7276 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7279 best_highpc
= highpc
;
7282 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7283 best_lowpc
+ baseaddr
)
7285 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7286 best_highpc
+ baseaddr
)
7289 end_psymtab_common (objfile
, pst
);
7291 if (!cu
->per_cu
->imported_symtabs_empty ())
7294 int len
= cu
->per_cu
->imported_symtabs_size ();
7296 /* Fill in 'dependencies' here; we fill in 'users' in a
7298 pst
->number_of_dependencies
= len
;
7300 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7301 for (i
= 0; i
< len
; ++i
)
7303 pst
->dependencies
[i
]
7304 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7307 cu
->per_cu
->imported_symtabs_free ();
7310 /* Get the list of files included in the current compilation unit,
7311 and build a psymtab for each of them. */
7312 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7314 if (dwarf_read_debug
)
7315 fprintf_unfiltered (gdb_stdlog
,
7316 "Psymtab for %s unit @%s: %s - %s"
7317 ", %d global, %d static syms\n",
7318 per_cu
->is_debug_types
? "type" : "comp",
7319 sect_offset_str (per_cu
->sect_off
),
7320 paddress (gdbarch
, pst
->text_low (objfile
)),
7321 paddress (gdbarch
, pst
->text_high (objfile
)),
7322 pst
->n_global_syms
, pst
->n_static_syms
);
7325 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7326 Process compilation unit THIS_CU for a psymtab. */
7329 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7330 bool want_partial_unit
,
7331 enum language pretend_language
)
7333 /* If this compilation unit was already read in, free the
7334 cached copy in order to read it in again. This is
7335 necessary because we skipped some symbols when we first
7336 read in the compilation unit (see load_partial_dies).
7337 This problem could be avoided, but the benefit is unclear. */
7338 if (this_cu
->cu
!= NULL
)
7339 free_one_cached_comp_unit (this_cu
);
7341 cutu_reader
reader (this_cu
, NULL
, 0, false);
7343 switch (reader
.comp_unit_die
->tag
)
7345 case DW_TAG_compile_unit
:
7346 this_cu
->unit_type
= DW_UT_compile
;
7348 case DW_TAG_partial_unit
:
7349 this_cu
->unit_type
= DW_UT_partial
;
7359 else if (this_cu
->is_debug_types
)
7360 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7361 reader
.comp_unit_die
);
7362 else if (want_partial_unit
7363 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7364 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7365 reader
.comp_unit_die
,
7368 this_cu
->lang
= this_cu
->cu
->language
;
7370 /* Age out any secondary CUs. */
7371 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7374 /* Reader function for build_type_psymtabs. */
7377 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7378 const gdb_byte
*info_ptr
,
7379 struct die_info
*type_unit_die
)
7381 struct dwarf2_per_objfile
*dwarf2_per_objfile
7382 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7383 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7384 struct dwarf2_cu
*cu
= reader
->cu
;
7385 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7386 struct signatured_type
*sig_type
;
7387 struct type_unit_group
*tu_group
;
7388 struct attribute
*attr
;
7389 struct partial_die_info
*first_die
;
7390 CORE_ADDR lowpc
, highpc
;
7391 dwarf2_psymtab
*pst
;
7393 gdb_assert (per_cu
->is_debug_types
);
7394 sig_type
= (struct signatured_type
*) per_cu
;
7396 if (! type_unit_die
->has_children
)
7399 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7400 tu_group
= get_type_unit_group (cu
, attr
);
7402 if (tu_group
->tus
== nullptr)
7403 tu_group
->tus
= new std::vector
<signatured_type
*>;
7404 tu_group
->tus
->push_back (sig_type
);
7406 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7407 pst
= create_partial_symtab (per_cu
, "");
7408 pst
->anonymous
= true;
7410 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7412 lowpc
= (CORE_ADDR
) -1;
7413 highpc
= (CORE_ADDR
) 0;
7414 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7416 end_psymtab_common (objfile
, pst
);
7419 /* Struct used to sort TUs by their abbreviation table offset. */
7421 struct tu_abbrev_offset
7423 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7424 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7427 signatured_type
*sig_type
;
7428 sect_offset abbrev_offset
;
7431 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7434 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7435 const struct tu_abbrev_offset
&b
)
7437 return a
.abbrev_offset
< b
.abbrev_offset
;
7440 /* Efficiently read all the type units.
7441 This does the bulk of the work for build_type_psymtabs.
7443 The efficiency is because we sort TUs by the abbrev table they use and
7444 only read each abbrev table once. In one program there are 200K TUs
7445 sharing 8K abbrev tables.
7447 The main purpose of this function is to support building the
7448 dwarf2_per_objfile->type_unit_groups table.
7449 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7450 can collapse the search space by grouping them by stmt_list.
7451 The savings can be significant, in the same program from above the 200K TUs
7452 share 8K stmt_list tables.
7454 FUNC is expected to call get_type_unit_group, which will create the
7455 struct type_unit_group if necessary and add it to
7456 dwarf2_per_objfile->type_unit_groups. */
7459 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7461 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7462 abbrev_table_up abbrev_table
;
7463 sect_offset abbrev_offset
;
7465 /* It's up to the caller to not call us multiple times. */
7466 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7468 if (dwarf2_per_objfile
->all_type_units
.empty ())
7471 /* TUs typically share abbrev tables, and there can be way more TUs than
7472 abbrev tables. Sort by abbrev table to reduce the number of times we
7473 read each abbrev table in.
7474 Alternatives are to punt or to maintain a cache of abbrev tables.
7475 This is simpler and efficient enough for now.
7477 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7478 symtab to use). Typically TUs with the same abbrev offset have the same
7479 stmt_list value too so in practice this should work well.
7481 The basic algorithm here is:
7483 sort TUs by abbrev table
7484 for each TU with same abbrev table:
7485 read abbrev table if first user
7486 read TU top level DIE
7487 [IWBN if DWO skeletons had DW_AT_stmt_list]
7490 if (dwarf_read_debug
)
7491 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7493 /* Sort in a separate table to maintain the order of all_type_units
7494 for .gdb_index: TU indices directly index all_type_units. */
7495 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7496 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7498 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7499 sorted_by_abbrev
.emplace_back
7500 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7501 sig_type
->per_cu
.section
,
7502 sig_type
->per_cu
.sect_off
));
7504 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7505 sort_tu_by_abbrev_offset
);
7507 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7509 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7511 /* Switch to the next abbrev table if necessary. */
7512 if (abbrev_table
== NULL
7513 || tu
.abbrev_offset
!= abbrev_offset
)
7515 abbrev_offset
= tu
.abbrev_offset
;
7517 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7518 &dwarf2_per_objfile
->abbrev
,
7520 ++tu_stats
->nr_uniq_abbrev_tables
;
7523 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7525 if (!reader
.dummy_p
)
7526 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7527 reader
.comp_unit_die
);
7531 /* Print collected type unit statistics. */
7534 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7536 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7538 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7539 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7540 dwarf2_per_objfile
->all_type_units
.size ());
7541 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7542 tu_stats
->nr_uniq_abbrev_tables
);
7543 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7544 tu_stats
->nr_symtabs
);
7545 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7546 tu_stats
->nr_symtab_sharers
);
7547 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7548 tu_stats
->nr_stmt_less_type_units
);
7549 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7550 tu_stats
->nr_all_type_units_reallocs
);
7553 /* Traversal function for build_type_psymtabs. */
7556 build_type_psymtab_dependencies (void **slot
, void *info
)
7558 struct dwarf2_per_objfile
*dwarf2_per_objfile
7559 = (struct dwarf2_per_objfile
*) info
;
7560 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7561 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7562 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7563 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7564 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7567 gdb_assert (len
> 0);
7568 gdb_assert (per_cu
->type_unit_group_p ());
7570 pst
->number_of_dependencies
= len
;
7571 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7572 for (i
= 0; i
< len
; ++i
)
7574 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7575 gdb_assert (iter
->per_cu
.is_debug_types
);
7576 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7577 iter
->type_unit_group
= tu_group
;
7580 delete tu_group
->tus
;
7581 tu_group
->tus
= nullptr;
7586 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7587 Build partial symbol tables for the .debug_types comp-units. */
7590 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7592 if (! create_all_type_units (dwarf2_per_objfile
))
7595 build_type_psymtabs_1 (dwarf2_per_objfile
);
7598 /* Traversal function for process_skeletonless_type_unit.
7599 Read a TU in a DWO file and build partial symbols for it. */
7602 process_skeletonless_type_unit (void **slot
, void *info
)
7604 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7605 struct dwarf2_per_objfile
*dwarf2_per_objfile
7606 = (struct dwarf2_per_objfile
*) info
;
7607 struct signatured_type find_entry
, *entry
;
7609 /* If this TU doesn't exist in the global table, add it and read it in. */
7611 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7612 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7614 find_entry
.signature
= dwo_unit
->signature
;
7615 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7616 &find_entry
, INSERT
);
7617 /* If we've already seen this type there's nothing to do. What's happening
7618 is we're doing our own version of comdat-folding here. */
7622 /* This does the job that create_all_type_units would have done for
7624 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7625 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7628 /* This does the job that build_type_psymtabs_1 would have done. */
7629 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7630 if (!reader
.dummy_p
)
7631 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7632 reader
.comp_unit_die
);
7637 /* Traversal function for process_skeletonless_type_units. */
7640 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7642 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7644 if (dwo_file
->tus
!= NULL
)
7645 htab_traverse_noresize (dwo_file
->tus
.get (),
7646 process_skeletonless_type_unit
, info
);
7651 /* Scan all TUs of DWO files, verifying we've processed them.
7652 This is needed in case a TU was emitted without its skeleton.
7653 Note: This can't be done until we know what all the DWO files are. */
7656 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7658 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7659 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7660 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7662 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7663 process_dwo_file_for_skeletonless_type_units
,
7664 dwarf2_per_objfile
);
7668 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7671 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7673 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7675 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7680 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7682 /* Set the 'user' field only if it is not already set. */
7683 if (pst
->dependencies
[j
]->user
== NULL
)
7684 pst
->dependencies
[j
]->user
= pst
;
7689 /* Build the partial symbol table by doing a quick pass through the
7690 .debug_info and .debug_abbrev sections. */
7693 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7695 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7697 if (dwarf_read_debug
)
7699 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7700 objfile_name (objfile
));
7703 scoped_restore restore_reading_psyms
7704 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7707 dwarf2_per_objfile
->info
.read (objfile
);
7709 /* Any cached compilation units will be linked by the per-objfile
7710 read_in_chain. Make sure to free them when we're done. */
7711 free_cached_comp_units
freer (dwarf2_per_objfile
);
7713 build_type_psymtabs (dwarf2_per_objfile
);
7715 create_all_comp_units (dwarf2_per_objfile
);
7717 /* Create a temporary address map on a temporary obstack. We later
7718 copy this to the final obstack. */
7719 auto_obstack temp_obstack
;
7721 scoped_restore save_psymtabs_addrmap
7722 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7723 addrmap_create_mutable (&temp_obstack
));
7725 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7726 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7728 /* This has to wait until we read the CUs, we need the list of DWOs. */
7729 process_skeletonless_type_units (dwarf2_per_objfile
);
7731 /* Now that all TUs have been processed we can fill in the dependencies. */
7732 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7734 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7735 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7738 if (dwarf_read_debug
)
7739 print_tu_stats (dwarf2_per_objfile
);
7741 set_partial_user (dwarf2_per_objfile
);
7743 objfile
->partial_symtabs
->psymtabs_addrmap
7744 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7745 objfile
->partial_symtabs
->obstack ());
7746 /* At this point we want to keep the address map. */
7747 save_psymtabs_addrmap
.release ();
7749 if (dwarf_read_debug
)
7750 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7751 objfile_name (objfile
));
7754 /* Load the partial DIEs for a secondary CU into memory.
7755 This is also used when rereading a primary CU with load_all_dies. */
7758 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7760 cutu_reader
reader (this_cu
, NULL
, 1, false);
7762 if (!reader
.dummy_p
)
7764 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7767 /* Check if comp unit has_children.
7768 If so, read the rest of the partial symbols from this comp unit.
7769 If not, there's no more debug_info for this comp unit. */
7770 if (reader
.comp_unit_die
->has_children
)
7771 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7778 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7779 struct dwarf2_section_info
*section
,
7780 struct dwarf2_section_info
*abbrev_section
,
7781 unsigned int is_dwz
)
7783 const gdb_byte
*info_ptr
;
7784 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7786 if (dwarf_read_debug
)
7787 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7788 section
->get_name (),
7789 section
->get_file_name ());
7791 section
->read (objfile
);
7793 info_ptr
= section
->buffer
;
7795 while (info_ptr
< section
->buffer
+ section
->size
)
7797 struct dwarf2_per_cu_data
*this_cu
;
7799 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7801 comp_unit_head cu_header
;
7802 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7803 abbrev_section
, info_ptr
,
7804 rcuh_kind::COMPILE
);
7806 /* Save the compilation unit for later lookup. */
7807 if (cu_header
.unit_type
!= DW_UT_type
)
7809 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7810 struct dwarf2_per_cu_data
);
7811 memset (this_cu
, 0, sizeof (*this_cu
));
7815 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7816 struct signatured_type
);
7817 memset (sig_type
, 0, sizeof (*sig_type
));
7818 sig_type
->signature
= cu_header
.signature
;
7819 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7820 this_cu
= &sig_type
->per_cu
;
7822 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7823 this_cu
->sect_off
= sect_off
;
7824 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7825 this_cu
->is_dwz
= is_dwz
;
7826 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7827 this_cu
->section
= section
;
7829 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7831 info_ptr
= info_ptr
+ this_cu
->length
;
7835 /* Create a list of all compilation units in OBJFILE.
7836 This is only done for -readnow and building partial symtabs. */
7839 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7841 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7842 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7843 &dwarf2_per_objfile
->abbrev
, 0);
7845 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7847 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7851 /* Process all loaded DIEs for compilation unit CU, starting at
7852 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7853 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7854 DW_AT_ranges). See the comments of add_partial_subprogram on how
7855 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7858 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7859 CORE_ADDR
*highpc
, int set_addrmap
,
7860 struct dwarf2_cu
*cu
)
7862 struct partial_die_info
*pdi
;
7864 /* Now, march along the PDI's, descending into ones which have
7865 interesting children but skipping the children of the other ones,
7866 until we reach the end of the compilation unit. */
7874 /* Anonymous namespaces or modules have no name but have interesting
7875 children, so we need to look at them. Ditto for anonymous
7878 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7879 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7880 || pdi
->tag
== DW_TAG_imported_unit
7881 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7885 case DW_TAG_subprogram
:
7886 case DW_TAG_inlined_subroutine
:
7887 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7889 case DW_TAG_constant
:
7890 case DW_TAG_variable
:
7891 case DW_TAG_typedef
:
7892 case DW_TAG_union_type
:
7893 if (!pdi
->is_declaration
)
7895 add_partial_symbol (pdi
, cu
);
7898 case DW_TAG_class_type
:
7899 case DW_TAG_interface_type
:
7900 case DW_TAG_structure_type
:
7901 if (!pdi
->is_declaration
)
7903 add_partial_symbol (pdi
, cu
);
7905 if ((cu
->language
== language_rust
7906 || cu
->language
== language_cplus
) && pdi
->has_children
)
7907 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7910 case DW_TAG_enumeration_type
:
7911 if (!pdi
->is_declaration
)
7912 add_partial_enumeration (pdi
, cu
);
7914 case DW_TAG_base_type
:
7915 case DW_TAG_subrange_type
:
7916 /* File scope base type definitions are added to the partial
7918 add_partial_symbol (pdi
, cu
);
7920 case DW_TAG_namespace
:
7921 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7924 if (!pdi
->is_declaration
)
7925 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7927 case DW_TAG_imported_unit
:
7929 struct dwarf2_per_cu_data
*per_cu
;
7931 /* For now we don't handle imported units in type units. */
7932 if (cu
->per_cu
->is_debug_types
)
7934 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7935 " supported in type units [in module %s]"),
7936 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7939 per_cu
= dwarf2_find_containing_comp_unit
7940 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7941 cu
->per_cu
->dwarf2_per_objfile
);
7943 /* Go read the partial unit, if needed. */
7944 if (per_cu
->v
.psymtab
== NULL
)
7945 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7947 cu
->per_cu
->imported_symtabs_push (per_cu
);
7950 case DW_TAG_imported_declaration
:
7951 add_partial_symbol (pdi
, cu
);
7958 /* If the die has a sibling, skip to the sibling. */
7960 pdi
= pdi
->die_sibling
;
7964 /* Functions used to compute the fully scoped name of a partial DIE.
7966 Normally, this is simple. For C++, the parent DIE's fully scoped
7967 name is concatenated with "::" and the partial DIE's name.
7968 Enumerators are an exception; they use the scope of their parent
7969 enumeration type, i.e. the name of the enumeration type is not
7970 prepended to the enumerator.
7972 There are two complexities. One is DW_AT_specification; in this
7973 case "parent" means the parent of the target of the specification,
7974 instead of the direct parent of the DIE. The other is compilers
7975 which do not emit DW_TAG_namespace; in this case we try to guess
7976 the fully qualified name of structure types from their members'
7977 linkage names. This must be done using the DIE's children rather
7978 than the children of any DW_AT_specification target. We only need
7979 to do this for structures at the top level, i.e. if the target of
7980 any DW_AT_specification (if any; otherwise the DIE itself) does not
7983 /* Compute the scope prefix associated with PDI's parent, in
7984 compilation unit CU. The result will be allocated on CU's
7985 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7986 field. NULL is returned if no prefix is necessary. */
7988 partial_die_parent_scope (struct partial_die_info
*pdi
,
7989 struct dwarf2_cu
*cu
)
7991 const char *grandparent_scope
;
7992 struct partial_die_info
*parent
, *real_pdi
;
7994 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7995 then this means the parent of the specification DIE. */
7998 while (real_pdi
->has_specification
)
8000 auto res
= find_partial_die (real_pdi
->spec_offset
,
8001 real_pdi
->spec_is_dwz
, cu
);
8006 parent
= real_pdi
->die_parent
;
8010 if (parent
->scope_set
)
8011 return parent
->scope
;
8015 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8017 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8018 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8019 Work around this problem here. */
8020 if (cu
->language
== language_cplus
8021 && parent
->tag
== DW_TAG_namespace
8022 && strcmp (parent
->name
, "::") == 0
8023 && grandparent_scope
== NULL
)
8025 parent
->scope
= NULL
;
8026 parent
->scope_set
= 1;
8030 /* Nested subroutines in Fortran get a prefix. */
8031 if (pdi
->tag
== DW_TAG_enumerator
)
8032 /* Enumerators should not get the name of the enumeration as a prefix. */
8033 parent
->scope
= grandparent_scope
;
8034 else if (parent
->tag
== DW_TAG_namespace
8035 || parent
->tag
== DW_TAG_module
8036 || parent
->tag
== DW_TAG_structure_type
8037 || parent
->tag
== DW_TAG_class_type
8038 || parent
->tag
== DW_TAG_interface_type
8039 || parent
->tag
== DW_TAG_union_type
8040 || parent
->tag
== DW_TAG_enumeration_type
8041 || (cu
->language
== language_fortran
8042 && parent
->tag
== DW_TAG_subprogram
8043 && pdi
->tag
== DW_TAG_subprogram
))
8045 if (grandparent_scope
== NULL
)
8046 parent
->scope
= parent
->name
;
8048 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8050 parent
->name
, 0, cu
);
8054 /* FIXME drow/2004-04-01: What should we be doing with
8055 function-local names? For partial symbols, we should probably be
8057 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8058 dwarf_tag_name (parent
->tag
),
8059 sect_offset_str (pdi
->sect_off
));
8060 parent
->scope
= grandparent_scope
;
8063 parent
->scope_set
= 1;
8064 return parent
->scope
;
8067 /* Return the fully scoped name associated with PDI, from compilation unit
8068 CU. The result will be allocated with malloc. */
8070 static gdb::unique_xmalloc_ptr
<char>
8071 partial_die_full_name (struct partial_die_info
*pdi
,
8072 struct dwarf2_cu
*cu
)
8074 const char *parent_scope
;
8076 /* If this is a template instantiation, we can not work out the
8077 template arguments from partial DIEs. So, unfortunately, we have
8078 to go through the full DIEs. At least any work we do building
8079 types here will be reused if full symbols are loaded later. */
8080 if (pdi
->has_template_arguments
)
8084 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8086 struct die_info
*die
;
8087 struct attribute attr
;
8088 struct dwarf2_cu
*ref_cu
= cu
;
8090 /* DW_FORM_ref_addr is using section offset. */
8091 attr
.name
= (enum dwarf_attribute
) 0;
8092 attr
.form
= DW_FORM_ref_addr
;
8093 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8094 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8096 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8100 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8101 if (parent_scope
== NULL
)
8104 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8109 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8111 struct dwarf2_per_objfile
*dwarf2_per_objfile
8112 = cu
->per_cu
->dwarf2_per_objfile
;
8113 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8114 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8116 const char *actual_name
= NULL
;
8119 baseaddr
= objfile
->text_section_offset ();
8121 gdb::unique_xmalloc_ptr
<char> built_actual_name
8122 = partial_die_full_name (pdi
, cu
);
8123 if (built_actual_name
!= NULL
)
8124 actual_name
= built_actual_name
.get ();
8126 if (actual_name
== NULL
)
8127 actual_name
= pdi
->name
;
8131 case DW_TAG_inlined_subroutine
:
8132 case DW_TAG_subprogram
:
8133 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8135 if (pdi
->is_external
8136 || cu
->language
== language_ada
8137 || (cu
->language
== language_fortran
8138 && pdi
->die_parent
!= NULL
8139 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8141 /* Normally, only "external" DIEs are part of the global scope.
8142 But in Ada and Fortran, we want to be able to access nested
8143 procedures globally. So all Ada and Fortran subprograms are
8144 stored in the global scope. */
8145 add_psymbol_to_list (actual_name
,
8146 built_actual_name
!= NULL
,
8147 VAR_DOMAIN
, LOC_BLOCK
,
8148 SECT_OFF_TEXT (objfile
),
8149 psymbol_placement::GLOBAL
,
8151 cu
->language
, objfile
);
8155 add_psymbol_to_list (actual_name
,
8156 built_actual_name
!= NULL
,
8157 VAR_DOMAIN
, LOC_BLOCK
,
8158 SECT_OFF_TEXT (objfile
),
8159 psymbol_placement::STATIC
,
8160 addr
, cu
->language
, objfile
);
8163 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8164 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8166 case DW_TAG_constant
:
8167 add_psymbol_to_list (actual_name
,
8168 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8169 -1, (pdi
->is_external
8170 ? psymbol_placement::GLOBAL
8171 : psymbol_placement::STATIC
),
8172 0, cu
->language
, objfile
);
8174 case DW_TAG_variable
:
8176 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8180 && !dwarf2_per_objfile
->has_section_at_zero
)
8182 /* A global or static variable may also have been stripped
8183 out by the linker if unused, in which case its address
8184 will be nullified; do not add such variables into partial
8185 symbol table then. */
8187 else if (pdi
->is_external
)
8190 Don't enter into the minimal symbol tables as there is
8191 a minimal symbol table entry from the ELF symbols already.
8192 Enter into partial symbol table if it has a location
8193 descriptor or a type.
8194 If the location descriptor is missing, new_symbol will create
8195 a LOC_UNRESOLVED symbol, the address of the variable will then
8196 be determined from the minimal symbol table whenever the variable
8198 The address for the partial symbol table entry is not
8199 used by GDB, but it comes in handy for debugging partial symbol
8202 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8203 add_psymbol_to_list (actual_name
,
8204 built_actual_name
!= NULL
,
8205 VAR_DOMAIN
, LOC_STATIC
,
8206 SECT_OFF_TEXT (objfile
),
8207 psymbol_placement::GLOBAL
,
8208 addr
, cu
->language
, objfile
);
8212 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8214 /* Static Variable. Skip symbols whose value we cannot know (those
8215 without location descriptors or constant values). */
8216 if (!has_loc
&& !pdi
->has_const_value
)
8219 add_psymbol_to_list (actual_name
,
8220 built_actual_name
!= NULL
,
8221 VAR_DOMAIN
, LOC_STATIC
,
8222 SECT_OFF_TEXT (objfile
),
8223 psymbol_placement::STATIC
,
8225 cu
->language
, objfile
);
8228 case DW_TAG_typedef
:
8229 case DW_TAG_base_type
:
8230 case DW_TAG_subrange_type
:
8231 add_psymbol_to_list (actual_name
,
8232 built_actual_name
!= NULL
,
8233 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8234 psymbol_placement::STATIC
,
8235 0, cu
->language
, objfile
);
8237 case DW_TAG_imported_declaration
:
8238 case DW_TAG_namespace
:
8239 add_psymbol_to_list (actual_name
,
8240 built_actual_name
!= NULL
,
8241 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8242 psymbol_placement::GLOBAL
,
8243 0, cu
->language
, objfile
);
8246 /* With Fortran 77 there might be a "BLOCK DATA" module
8247 available without any name. If so, we skip the module as it
8248 doesn't bring any value. */
8249 if (actual_name
!= nullptr)
8250 add_psymbol_to_list (actual_name
,
8251 built_actual_name
!= NULL
,
8252 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8253 psymbol_placement::GLOBAL
,
8254 0, cu
->language
, objfile
);
8256 case DW_TAG_class_type
:
8257 case DW_TAG_interface_type
:
8258 case DW_TAG_structure_type
:
8259 case DW_TAG_union_type
:
8260 case DW_TAG_enumeration_type
:
8261 /* Skip external references. The DWARF standard says in the section
8262 about "Structure, Union, and Class Type Entries": "An incomplete
8263 structure, union or class type is represented by a structure,
8264 union or class entry that does not have a byte size attribute
8265 and that has a DW_AT_declaration attribute." */
8266 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8269 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8270 static vs. global. */
8271 add_psymbol_to_list (actual_name
,
8272 built_actual_name
!= NULL
,
8273 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8274 cu
->language
== language_cplus
8275 ? psymbol_placement::GLOBAL
8276 : psymbol_placement::STATIC
,
8277 0, cu
->language
, objfile
);
8280 case DW_TAG_enumerator
:
8281 add_psymbol_to_list (actual_name
,
8282 built_actual_name
!= NULL
,
8283 VAR_DOMAIN
, LOC_CONST
, -1,
8284 cu
->language
== language_cplus
8285 ? psymbol_placement::GLOBAL
8286 : psymbol_placement::STATIC
,
8287 0, cu
->language
, objfile
);
8294 /* Read a partial die corresponding to a namespace; also, add a symbol
8295 corresponding to that namespace to the symbol table. NAMESPACE is
8296 the name of the enclosing namespace. */
8299 add_partial_namespace (struct partial_die_info
*pdi
,
8300 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8301 int set_addrmap
, struct dwarf2_cu
*cu
)
8303 /* Add a symbol for the namespace. */
8305 add_partial_symbol (pdi
, cu
);
8307 /* Now scan partial symbols in that namespace. */
8309 if (pdi
->has_children
)
8310 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8313 /* Read a partial die corresponding to a Fortran module. */
8316 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8317 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8319 /* Add a symbol for the namespace. */
8321 add_partial_symbol (pdi
, cu
);
8323 /* Now scan partial symbols in that module. */
8325 if (pdi
->has_children
)
8326 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8329 /* Read a partial die corresponding to a subprogram or an inlined
8330 subprogram and create a partial symbol for that subprogram.
8331 When the CU language allows it, this routine also defines a partial
8332 symbol for each nested subprogram that this subprogram contains.
8333 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8334 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8336 PDI may also be a lexical block, in which case we simply search
8337 recursively for subprograms defined inside that lexical block.
8338 Again, this is only performed when the CU language allows this
8339 type of definitions. */
8342 add_partial_subprogram (struct partial_die_info
*pdi
,
8343 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8344 int set_addrmap
, struct dwarf2_cu
*cu
)
8346 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8348 if (pdi
->has_pc_info
)
8350 if (pdi
->lowpc
< *lowpc
)
8351 *lowpc
= pdi
->lowpc
;
8352 if (pdi
->highpc
> *highpc
)
8353 *highpc
= pdi
->highpc
;
8356 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8357 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8359 CORE_ADDR this_highpc
;
8360 CORE_ADDR this_lowpc
;
8362 baseaddr
= objfile
->text_section_offset ();
8364 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8365 pdi
->lowpc
+ baseaddr
)
8368 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8369 pdi
->highpc
+ baseaddr
)
8371 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8372 this_lowpc
, this_highpc
- 1,
8373 cu
->per_cu
->v
.psymtab
);
8377 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8379 if (!pdi
->is_declaration
)
8380 /* Ignore subprogram DIEs that do not have a name, they are
8381 illegal. Do not emit a complaint at this point, we will
8382 do so when we convert this psymtab into a symtab. */
8384 add_partial_symbol (pdi
, cu
);
8388 if (! pdi
->has_children
)
8391 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8393 pdi
= pdi
->die_child
;
8397 if (pdi
->tag
== DW_TAG_subprogram
8398 || pdi
->tag
== DW_TAG_inlined_subroutine
8399 || pdi
->tag
== DW_TAG_lexical_block
)
8400 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8401 pdi
= pdi
->die_sibling
;
8406 /* Read a partial die corresponding to an enumeration type. */
8409 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8410 struct dwarf2_cu
*cu
)
8412 struct partial_die_info
*pdi
;
8414 if (enum_pdi
->name
!= NULL
)
8415 add_partial_symbol (enum_pdi
, cu
);
8417 pdi
= enum_pdi
->die_child
;
8420 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8421 complaint (_("malformed enumerator DIE ignored"));
8423 add_partial_symbol (pdi
, cu
);
8424 pdi
= pdi
->die_sibling
;
8428 /* Return the initial uleb128 in the die at INFO_PTR. */
8431 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8433 unsigned int bytes_read
;
8435 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8438 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8439 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8441 Return the corresponding abbrev, or NULL if the number is zero (indicating
8442 an empty DIE). In either case *BYTES_READ will be set to the length of
8443 the initial number. */
8445 static struct abbrev_info
*
8446 peek_die_abbrev (const die_reader_specs
&reader
,
8447 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8449 dwarf2_cu
*cu
= reader
.cu
;
8450 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8451 unsigned int abbrev_number
8452 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8454 if (abbrev_number
== 0)
8457 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8460 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8461 " at offset %s [in module %s]"),
8462 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8463 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8469 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8470 Returns a pointer to the end of a series of DIEs, terminated by an empty
8471 DIE. Any children of the skipped DIEs will also be skipped. */
8473 static const gdb_byte
*
8474 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8478 unsigned int bytes_read
;
8479 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8482 return info_ptr
+ bytes_read
;
8484 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8488 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8489 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8490 abbrev corresponding to that skipped uleb128 should be passed in
8491 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8494 static const gdb_byte
*
8495 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8496 struct abbrev_info
*abbrev
)
8498 unsigned int bytes_read
;
8499 struct attribute attr
;
8500 bfd
*abfd
= reader
->abfd
;
8501 struct dwarf2_cu
*cu
= reader
->cu
;
8502 const gdb_byte
*buffer
= reader
->buffer
;
8503 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8504 unsigned int form
, i
;
8506 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8508 /* The only abbrev we care about is DW_AT_sibling. */
8509 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8512 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8514 if (attr
.form
== DW_FORM_ref_addr
)
8515 complaint (_("ignoring absolute DW_AT_sibling"));
8518 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8519 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8521 if (sibling_ptr
< info_ptr
)
8522 complaint (_("DW_AT_sibling points backwards"));
8523 else if (sibling_ptr
> reader
->buffer_end
)
8524 reader
->die_section
->overflow_complaint ();
8530 /* If it isn't DW_AT_sibling, skip this attribute. */
8531 form
= abbrev
->attrs
[i
].form
;
8535 case DW_FORM_ref_addr
:
8536 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8537 and later it is offset sized. */
8538 if (cu
->header
.version
== 2)
8539 info_ptr
+= cu
->header
.addr_size
;
8541 info_ptr
+= cu
->header
.offset_size
;
8543 case DW_FORM_GNU_ref_alt
:
8544 info_ptr
+= cu
->header
.offset_size
;
8547 info_ptr
+= cu
->header
.addr_size
;
8555 case DW_FORM_flag_present
:
8556 case DW_FORM_implicit_const
:
8573 case DW_FORM_ref_sig8
:
8576 case DW_FORM_data16
:
8579 case DW_FORM_string
:
8580 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8581 info_ptr
+= bytes_read
;
8583 case DW_FORM_sec_offset
:
8585 case DW_FORM_GNU_strp_alt
:
8586 info_ptr
+= cu
->header
.offset_size
;
8588 case DW_FORM_exprloc
:
8590 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8591 info_ptr
+= bytes_read
;
8593 case DW_FORM_block1
:
8594 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8596 case DW_FORM_block2
:
8597 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8599 case DW_FORM_block4
:
8600 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8606 case DW_FORM_ref_udata
:
8607 case DW_FORM_GNU_addr_index
:
8608 case DW_FORM_GNU_str_index
:
8609 case DW_FORM_rnglistx
:
8610 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8612 case DW_FORM_indirect
:
8613 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8614 info_ptr
+= bytes_read
;
8615 /* We need to continue parsing from here, so just go back to
8617 goto skip_attribute
;
8620 error (_("Dwarf Error: Cannot handle %s "
8621 "in DWARF reader [in module %s]"),
8622 dwarf_form_name (form
),
8623 bfd_get_filename (abfd
));
8627 if (abbrev
->has_children
)
8628 return skip_children (reader
, info_ptr
);
8633 /* Locate ORIG_PDI's sibling.
8634 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8636 static const gdb_byte
*
8637 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8638 struct partial_die_info
*orig_pdi
,
8639 const gdb_byte
*info_ptr
)
8641 /* Do we know the sibling already? */
8643 if (orig_pdi
->sibling
)
8644 return orig_pdi
->sibling
;
8646 /* Are there any children to deal with? */
8648 if (!orig_pdi
->has_children
)
8651 /* Skip the children the long way. */
8653 return skip_children (reader
, info_ptr
);
8656 /* Expand this partial symbol table into a full symbol table. SELF is
8660 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8662 struct dwarf2_per_objfile
*dwarf2_per_objfile
8663 = get_dwarf2_per_objfile (objfile
);
8665 gdb_assert (!readin
);
8666 /* If this psymtab is constructed from a debug-only objfile, the
8667 has_section_at_zero flag will not necessarily be correct. We
8668 can get the correct value for this flag by looking at the data
8669 associated with the (presumably stripped) associated objfile. */
8670 if (objfile
->separate_debug_objfile_backlink
)
8672 struct dwarf2_per_objfile
*dpo_backlink
8673 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8675 dwarf2_per_objfile
->has_section_at_zero
8676 = dpo_backlink
->has_section_at_zero
;
8679 expand_psymtab (objfile
);
8681 process_cu_includes (dwarf2_per_objfile
);
8684 /* Reading in full CUs. */
8686 /* Add PER_CU to the queue. */
8689 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8690 enum language pretend_language
)
8693 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8696 /* If PER_CU is not yet queued, add it to the queue.
8697 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8699 The result is non-zero if PER_CU was queued, otherwise the result is zero
8700 meaning either PER_CU is already queued or it is already loaded.
8702 N.B. There is an invariant here that if a CU is queued then it is loaded.
8703 The caller is required to load PER_CU if we return non-zero. */
8706 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8707 struct dwarf2_per_cu_data
*per_cu
,
8708 enum language pretend_language
)
8710 /* We may arrive here during partial symbol reading, if we need full
8711 DIEs to process an unusual case (e.g. template arguments). Do
8712 not queue PER_CU, just tell our caller to load its DIEs. */
8713 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8715 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8720 /* Mark the dependence relation so that we don't flush PER_CU
8722 if (dependent_cu
!= NULL
)
8723 dwarf2_add_dependence (dependent_cu
, per_cu
);
8725 /* If it's already on the queue, we have nothing to do. */
8729 /* If the compilation unit is already loaded, just mark it as
8731 if (per_cu
->cu
!= NULL
)
8733 per_cu
->cu
->last_used
= 0;
8737 /* Add it to the queue. */
8738 queue_comp_unit (per_cu
, pretend_language
);
8743 /* Process the queue. */
8746 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8748 if (dwarf_read_debug
)
8750 fprintf_unfiltered (gdb_stdlog
,
8751 "Expanding one or more symtabs of objfile %s ...\n",
8752 objfile_name (dwarf2_per_objfile
->objfile
));
8755 /* The queue starts out with one item, but following a DIE reference
8756 may load a new CU, adding it to the end of the queue. */
8757 while (!dwarf2_per_objfile
->queue
.empty ())
8759 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8761 if ((dwarf2_per_objfile
->using_index
8762 ? !item
.per_cu
->v
.quick
->compunit_symtab
8763 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8764 /* Skip dummy CUs. */
8765 && item
.per_cu
->cu
!= NULL
)
8767 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8768 unsigned int debug_print_threshold
;
8771 if (per_cu
->is_debug_types
)
8773 struct signatured_type
*sig_type
=
8774 (struct signatured_type
*) per_cu
;
8776 sprintf (buf
, "TU %s at offset %s",
8777 hex_string (sig_type
->signature
),
8778 sect_offset_str (per_cu
->sect_off
));
8779 /* There can be 100s of TUs.
8780 Only print them in verbose mode. */
8781 debug_print_threshold
= 2;
8785 sprintf (buf
, "CU at offset %s",
8786 sect_offset_str (per_cu
->sect_off
));
8787 debug_print_threshold
= 1;
8790 if (dwarf_read_debug
>= debug_print_threshold
)
8791 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8793 if (per_cu
->is_debug_types
)
8794 process_full_type_unit (per_cu
, item
.pretend_language
);
8796 process_full_comp_unit (per_cu
, item
.pretend_language
);
8798 if (dwarf_read_debug
>= debug_print_threshold
)
8799 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8802 item
.per_cu
->queued
= 0;
8803 dwarf2_per_objfile
->queue
.pop ();
8806 if (dwarf_read_debug
)
8808 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8809 objfile_name (dwarf2_per_objfile
->objfile
));
8813 /* Read in full symbols for PST, and anything it depends on. */
8816 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8821 read_dependencies (objfile
);
8823 dw2_do_instantiate_symtab (per_cu_data
, false);
8824 gdb_assert (get_compunit_symtab () != nullptr);
8827 /* Trivial hash function for die_info: the hash value of a DIE
8828 is its offset in .debug_info for this objfile. */
8831 die_hash (const void *item
)
8833 const struct die_info
*die
= (const struct die_info
*) item
;
8835 return to_underlying (die
->sect_off
);
8838 /* Trivial comparison function for die_info structures: two DIEs
8839 are equal if they have the same offset. */
8842 die_eq (const void *item_lhs
, const void *item_rhs
)
8844 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8845 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8847 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8850 /* Load the DIEs associated with PER_CU into memory. */
8853 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8855 enum language pretend_language
)
8857 gdb_assert (! this_cu
->is_debug_types
);
8859 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8863 struct dwarf2_cu
*cu
= reader
.cu
;
8864 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8866 gdb_assert (cu
->die_hash
== NULL
);
8868 htab_create_alloc_ex (cu
->header
.length
/ 12,
8872 &cu
->comp_unit_obstack
,
8873 hashtab_obstack_allocate
,
8874 dummy_obstack_deallocate
);
8876 if (reader
.comp_unit_die
->has_children
)
8877 reader
.comp_unit_die
->child
8878 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8879 &info_ptr
, reader
.comp_unit_die
);
8880 cu
->dies
= reader
.comp_unit_die
;
8881 /* comp_unit_die is not stored in die_hash, no need. */
8883 /* We try not to read any attributes in this function, because not
8884 all CUs needed for references have been loaded yet, and symbol
8885 table processing isn't initialized. But we have to set the CU language,
8886 or we won't be able to build types correctly.
8887 Similarly, if we do not read the producer, we can not apply
8888 producer-specific interpretation. */
8889 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8894 /* Add a DIE to the delayed physname list. */
8897 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8898 const char *name
, struct die_info
*die
,
8899 struct dwarf2_cu
*cu
)
8901 struct delayed_method_info mi
;
8903 mi
.fnfield_index
= fnfield_index
;
8907 cu
->method_list
.push_back (mi
);
8910 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8911 "const" / "volatile". If so, decrements LEN by the length of the
8912 modifier and return true. Otherwise return false. */
8916 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8918 size_t mod_len
= sizeof (mod
) - 1;
8919 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8927 /* Compute the physnames of any methods on the CU's method list.
8929 The computation of method physnames is delayed in order to avoid the
8930 (bad) condition that one of the method's formal parameters is of an as yet
8934 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8936 /* Only C++ delays computing physnames. */
8937 if (cu
->method_list
.empty ())
8939 gdb_assert (cu
->language
== language_cplus
);
8941 for (const delayed_method_info
&mi
: cu
->method_list
)
8943 const char *physname
;
8944 struct fn_fieldlist
*fn_flp
8945 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8946 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8947 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8948 = physname
? physname
: "";
8950 /* Since there's no tag to indicate whether a method is a
8951 const/volatile overload, extract that information out of the
8953 if (physname
!= NULL
)
8955 size_t len
= strlen (physname
);
8959 if (physname
[len
] == ')') /* shortcut */
8961 else if (check_modifier (physname
, len
, " const"))
8962 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8963 else if (check_modifier (physname
, len
, " volatile"))
8964 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8971 /* The list is no longer needed. */
8972 cu
->method_list
.clear ();
8975 /* Go objects should be embedded in a DW_TAG_module DIE,
8976 and it's not clear if/how imported objects will appear.
8977 To keep Go support simple until that's worked out,
8978 go back through what we've read and create something usable.
8979 We could do this while processing each DIE, and feels kinda cleaner,
8980 but that way is more invasive.
8981 This is to, for example, allow the user to type "p var" or "b main"
8982 without having to specify the package name, and allow lookups
8983 of module.object to work in contexts that use the expression
8987 fixup_go_packaging (struct dwarf2_cu
*cu
)
8989 gdb::unique_xmalloc_ptr
<char> package_name
;
8990 struct pending
*list
;
8993 for (list
= *cu
->get_builder ()->get_global_symbols ();
8997 for (i
= 0; i
< list
->nsyms
; ++i
)
8999 struct symbol
*sym
= list
->symbol
[i
];
9001 if (sym
->language () == language_go
9002 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9004 gdb::unique_xmalloc_ptr
<char> this_package_name
9005 (go_symbol_package_name (sym
));
9007 if (this_package_name
== NULL
)
9009 if (package_name
== NULL
)
9010 package_name
= std::move (this_package_name
);
9013 struct objfile
*objfile
9014 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9015 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9016 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9017 (symbol_symtab (sym
) != NULL
9018 ? symtab_to_filename_for_display
9019 (symbol_symtab (sym
))
9020 : objfile_name (objfile
)),
9021 this_package_name
.get (), package_name
.get ());
9027 if (package_name
!= NULL
)
9029 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9030 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9031 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9032 saved_package_name
);
9035 sym
= allocate_symbol (objfile
);
9036 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9037 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9038 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9039 e.g., "main" finds the "main" module and not C's main(). */
9040 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9041 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9042 SYMBOL_TYPE (sym
) = type
;
9044 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9048 /* Allocate a fully-qualified name consisting of the two parts on the
9052 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9054 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9057 /* A helper that allocates a struct discriminant_info to attach to a
9060 static struct discriminant_info
*
9061 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9064 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9065 gdb_assert (discriminant_index
== -1
9066 || (discriminant_index
>= 0
9067 && discriminant_index
< TYPE_NFIELDS (type
)));
9068 gdb_assert (default_index
== -1
9069 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9071 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9073 struct discriminant_info
*disc
9074 = ((struct discriminant_info
*)
9076 offsetof (struct discriminant_info
, discriminants
)
9077 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9078 disc
->default_index
= default_index
;
9079 disc
->discriminant_index
= discriminant_index
;
9081 struct dynamic_prop prop
;
9082 prop
.kind
= PROP_UNDEFINED
;
9083 prop
.data
.baton
= disc
;
9085 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9090 /* Some versions of rustc emitted enums in an unusual way.
9092 Ordinary enums were emitted as unions. The first element of each
9093 structure in the union was named "RUST$ENUM$DISR". This element
9094 held the discriminant.
9096 These versions of Rust also implemented the "non-zero"
9097 optimization. When the enum had two values, and one is empty and
9098 the other holds a pointer that cannot be zero, the pointer is used
9099 as the discriminant, with a zero value meaning the empty variant.
9100 Here, the union's first member is of the form
9101 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9102 where the fieldnos are the indices of the fields that should be
9103 traversed in order to find the field (which may be several fields deep)
9104 and the variantname is the name of the variant of the case when the
9107 This function recognizes whether TYPE is of one of these forms,
9108 and, if so, smashes it to be a variant type. */
9111 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9113 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9115 /* We don't need to deal with empty enums. */
9116 if (TYPE_NFIELDS (type
) == 0)
9119 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9120 if (TYPE_NFIELDS (type
) == 1
9121 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9123 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9125 /* Decode the field name to find the offset of the
9127 ULONGEST bit_offset
= 0;
9128 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9129 while (name
[0] >= '0' && name
[0] <= '9')
9132 unsigned long index
= strtoul (name
, &tail
, 10);
9135 || index
>= TYPE_NFIELDS (field_type
)
9136 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9137 != FIELD_LOC_KIND_BITPOS
))
9139 complaint (_("Could not parse Rust enum encoding string \"%s\""
9141 TYPE_FIELD_NAME (type
, 0),
9142 objfile_name (objfile
));
9147 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9148 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9151 /* Make a union to hold the variants. */
9152 struct type
*union_type
= alloc_type (objfile
);
9153 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9154 TYPE_NFIELDS (union_type
) = 3;
9155 TYPE_FIELDS (union_type
)
9156 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9157 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9158 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9160 /* Put the discriminant must at index 0. */
9161 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9162 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9163 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9164 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9166 /* The order of fields doesn't really matter, so put the real
9167 field at index 1 and the data-less field at index 2. */
9168 struct discriminant_info
*disc
9169 = alloc_discriminant_info (union_type
, 0, 1);
9170 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9171 TYPE_FIELD_NAME (union_type
, 1)
9172 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9173 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9174 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9175 TYPE_FIELD_NAME (union_type
, 1));
9177 const char *dataless_name
9178 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9180 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9182 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9183 /* NAME points into the original discriminant name, which
9184 already has the correct lifetime. */
9185 TYPE_FIELD_NAME (union_type
, 2) = name
;
9186 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9187 disc
->discriminants
[2] = 0;
9189 /* Smash this type to be a structure type. We have to do this
9190 because the type has already been recorded. */
9191 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9192 TYPE_NFIELDS (type
) = 1;
9194 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9196 /* Install the variant part. */
9197 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9198 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9199 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9201 /* A union with a single anonymous field is probably an old-style
9203 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9205 /* Smash this type to be a structure type. We have to do this
9206 because the type has already been recorded. */
9207 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9209 /* Make a union to hold the variants. */
9210 struct type
*union_type
= alloc_type (objfile
);
9211 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9212 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9213 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9214 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9215 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9217 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9218 const char *variant_name
9219 = rust_last_path_segment (TYPE_NAME (field_type
));
9220 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9221 TYPE_NAME (field_type
)
9222 = rust_fully_qualify (&objfile
->objfile_obstack
,
9223 TYPE_NAME (type
), variant_name
);
9225 /* Install the union in the outer struct type. */
9226 TYPE_NFIELDS (type
) = 1;
9228 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9229 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9230 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9231 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9233 alloc_discriminant_info (union_type
, -1, 0);
9237 struct type
*disr_type
= nullptr;
9238 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9240 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9242 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9244 /* All fields of a true enum will be structs. */
9247 else if (TYPE_NFIELDS (disr_type
) == 0)
9249 /* Could be data-less variant, so keep going. */
9250 disr_type
= nullptr;
9252 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9253 "RUST$ENUM$DISR") != 0)
9255 /* Not a Rust enum. */
9265 /* If we got here without a discriminant, then it's probably
9267 if (disr_type
== nullptr)
9270 /* Smash this type to be a structure type. We have to do this
9271 because the type has already been recorded. */
9272 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9274 /* Make a union to hold the variants. */
9275 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9276 struct type
*union_type
= alloc_type (objfile
);
9277 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9278 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9279 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9280 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9281 TYPE_FIELDS (union_type
)
9282 = (struct field
*) TYPE_ZALLOC (union_type
,
9283 (TYPE_NFIELDS (union_type
)
9284 * sizeof (struct field
)));
9286 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9287 TYPE_NFIELDS (type
) * sizeof (struct field
));
9289 /* Install the discriminant at index 0 in the union. */
9290 TYPE_FIELD (union_type
, 0) = *disr_field
;
9291 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9292 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9294 /* Install the union in the outer struct type. */
9295 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9296 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9297 TYPE_NFIELDS (type
) = 1;
9299 /* Set the size and offset of the union type. */
9300 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9302 /* We need a way to find the correct discriminant given a
9303 variant name. For convenience we build a map here. */
9304 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9305 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9306 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9308 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9311 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9312 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9316 int n_fields
= TYPE_NFIELDS (union_type
);
9317 struct discriminant_info
*disc
9318 = alloc_discriminant_info (union_type
, 0, -1);
9319 /* Skip the discriminant here. */
9320 for (int i
= 1; i
< n_fields
; ++i
)
9322 /* Find the final word in the name of this variant's type.
9323 That name can be used to look up the correct
9325 const char *variant_name
9326 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9329 auto iter
= discriminant_map
.find (variant_name
);
9330 if (iter
!= discriminant_map
.end ())
9331 disc
->discriminants
[i
] = iter
->second
;
9333 /* Remove the discriminant field, if it exists. */
9334 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9335 if (TYPE_NFIELDS (sub_type
) > 0)
9337 --TYPE_NFIELDS (sub_type
);
9338 ++TYPE_FIELDS (sub_type
);
9340 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9341 TYPE_NAME (sub_type
)
9342 = rust_fully_qualify (&objfile
->objfile_obstack
,
9343 TYPE_NAME (type
), variant_name
);
9348 /* Rewrite some Rust unions to be structures with variants parts. */
9351 rust_union_quirks (struct dwarf2_cu
*cu
)
9353 gdb_assert (cu
->language
== language_rust
);
9354 for (type
*type_
: cu
->rust_unions
)
9355 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9356 /* We don't need this any more. */
9357 cu
->rust_unions
.clear ();
9360 /* Return the symtab for PER_CU. This works properly regardless of
9361 whether we're using the index or psymtabs. */
9363 static struct compunit_symtab
*
9364 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9366 return (per_cu
->dwarf2_per_objfile
->using_index
9367 ? per_cu
->v
.quick
->compunit_symtab
9368 : per_cu
->v
.psymtab
->compunit_symtab
);
9371 /* A helper function for computing the list of all symbol tables
9372 included by PER_CU. */
9375 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9376 htab_t all_children
, htab_t all_type_symtabs
,
9377 struct dwarf2_per_cu_data
*per_cu
,
9378 struct compunit_symtab
*immediate_parent
)
9381 struct compunit_symtab
*cust
;
9383 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9386 /* This inclusion and its children have been processed. */
9391 /* Only add a CU if it has a symbol table. */
9392 cust
= get_compunit_symtab (per_cu
);
9395 /* If this is a type unit only add its symbol table if we haven't
9396 seen it yet (type unit per_cu's can share symtabs). */
9397 if (per_cu
->is_debug_types
)
9399 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9403 result
->push_back (cust
);
9404 if (cust
->user
== NULL
)
9405 cust
->user
= immediate_parent
;
9410 result
->push_back (cust
);
9411 if (cust
->user
== NULL
)
9412 cust
->user
= immediate_parent
;
9416 if (!per_cu
->imported_symtabs_empty ())
9417 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9419 recursively_compute_inclusions (result
, all_children
,
9420 all_type_symtabs
, ptr
, cust
);
9424 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9428 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9430 gdb_assert (! per_cu
->is_debug_types
);
9432 if (!per_cu
->imported_symtabs_empty ())
9435 std::vector
<compunit_symtab
*> result_symtabs
;
9436 htab_t all_children
, all_type_symtabs
;
9437 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9439 /* If we don't have a symtab, we can just skip this case. */
9443 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9444 NULL
, xcalloc
, xfree
);
9445 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9446 NULL
, xcalloc
, xfree
);
9448 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9450 recursively_compute_inclusions (&result_symtabs
, all_children
,
9451 all_type_symtabs
, ptr
, cust
);
9454 /* Now we have a transitive closure of all the included symtabs. */
9455 len
= result_symtabs
.size ();
9457 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9458 struct compunit_symtab
*, len
+ 1);
9459 memcpy (cust
->includes
, result_symtabs
.data (),
9460 len
* sizeof (compunit_symtab
*));
9461 cust
->includes
[len
] = NULL
;
9463 htab_delete (all_children
);
9464 htab_delete (all_type_symtabs
);
9468 /* Compute the 'includes' field for the symtabs of all the CUs we just
9472 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9474 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9476 if (! iter
->is_debug_types
)
9477 compute_compunit_symtab_includes (iter
);
9480 dwarf2_per_objfile
->just_read_cus
.clear ();
9483 /* Generate full symbol information for PER_CU, whose DIEs have
9484 already been loaded into memory. */
9487 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9488 enum language pretend_language
)
9490 struct dwarf2_cu
*cu
= per_cu
->cu
;
9491 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9492 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9493 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9494 CORE_ADDR lowpc
, highpc
;
9495 struct compunit_symtab
*cust
;
9497 struct block
*static_block
;
9500 baseaddr
= objfile
->text_section_offset ();
9502 /* Clear the list here in case something was left over. */
9503 cu
->method_list
.clear ();
9505 cu
->language
= pretend_language
;
9506 cu
->language_defn
= language_def (cu
->language
);
9508 /* Do line number decoding in read_file_scope () */
9509 process_die (cu
->dies
, cu
);
9511 /* For now fudge the Go package. */
9512 if (cu
->language
== language_go
)
9513 fixup_go_packaging (cu
);
9515 /* Now that we have processed all the DIEs in the CU, all the types
9516 should be complete, and it should now be safe to compute all of the
9518 compute_delayed_physnames (cu
);
9520 if (cu
->language
== language_rust
)
9521 rust_union_quirks (cu
);
9523 /* Some compilers don't define a DW_AT_high_pc attribute for the
9524 compilation unit. If the DW_AT_high_pc is missing, synthesize
9525 it, by scanning the DIE's below the compilation unit. */
9526 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9528 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9529 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9531 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9532 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9533 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9534 addrmap to help ensure it has an accurate map of pc values belonging to
9536 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9538 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9539 SECT_OFF_TEXT (objfile
),
9544 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9546 /* Set symtab language to language from DW_AT_language. If the
9547 compilation is from a C file generated by language preprocessors, do
9548 not set the language if it was already deduced by start_subfile. */
9549 if (!(cu
->language
== language_c
9550 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9551 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9553 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9554 produce DW_AT_location with location lists but it can be possibly
9555 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9556 there were bugs in prologue debug info, fixed later in GCC-4.5
9557 by "unwind info for epilogues" patch (which is not directly related).
9559 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9560 needed, it would be wrong due to missing DW_AT_producer there.
9562 Still one can confuse GDB by using non-standard GCC compilation
9563 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9565 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9566 cust
->locations_valid
= 1;
9568 if (gcc_4_minor
>= 5)
9569 cust
->epilogue_unwind_valid
= 1;
9571 cust
->call_site_htab
= cu
->call_site_htab
;
9574 if (dwarf2_per_objfile
->using_index
)
9575 per_cu
->v
.quick
->compunit_symtab
= cust
;
9578 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9579 pst
->compunit_symtab
= cust
;
9583 /* Push it for inclusion processing later. */
9584 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9586 /* Not needed any more. */
9587 cu
->reset_builder ();
9590 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9591 already been loaded into memory. */
9594 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9595 enum language pretend_language
)
9597 struct dwarf2_cu
*cu
= per_cu
->cu
;
9598 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9599 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9600 struct compunit_symtab
*cust
;
9601 struct signatured_type
*sig_type
;
9603 gdb_assert (per_cu
->is_debug_types
);
9604 sig_type
= (struct signatured_type
*) per_cu
;
9606 /* Clear the list here in case something was left over. */
9607 cu
->method_list
.clear ();
9609 cu
->language
= pretend_language
;
9610 cu
->language_defn
= language_def (cu
->language
);
9612 /* The symbol tables are set up in read_type_unit_scope. */
9613 process_die (cu
->dies
, cu
);
9615 /* For now fudge the Go package. */
9616 if (cu
->language
== language_go
)
9617 fixup_go_packaging (cu
);
9619 /* Now that we have processed all the DIEs in the CU, all the types
9620 should be complete, and it should now be safe to compute all of the
9622 compute_delayed_physnames (cu
);
9624 if (cu
->language
== language_rust
)
9625 rust_union_quirks (cu
);
9627 /* TUs share symbol tables.
9628 If this is the first TU to use this symtab, complete the construction
9629 of it with end_expandable_symtab. Otherwise, complete the addition of
9630 this TU's symbols to the existing symtab. */
9631 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9633 buildsym_compunit
*builder
= cu
->get_builder ();
9634 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9635 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9639 /* Set symtab language to language from DW_AT_language. If the
9640 compilation is from a C file generated by language preprocessors,
9641 do not set the language if it was already deduced by
9643 if (!(cu
->language
== language_c
9644 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9645 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9650 cu
->get_builder ()->augment_type_symtab ();
9651 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9654 if (dwarf2_per_objfile
->using_index
)
9655 per_cu
->v
.quick
->compunit_symtab
= cust
;
9658 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9659 pst
->compunit_symtab
= cust
;
9663 /* Not needed any more. */
9664 cu
->reset_builder ();
9667 /* Process an imported unit DIE. */
9670 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9672 struct attribute
*attr
;
9674 /* For now we don't handle imported units in type units. */
9675 if (cu
->per_cu
->is_debug_types
)
9677 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9678 " supported in type units [in module %s]"),
9679 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9682 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9685 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9686 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9687 dwarf2_per_cu_data
*per_cu
9688 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9689 cu
->per_cu
->dwarf2_per_objfile
);
9691 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9692 into another compilation unit, at root level. Regard this as a hint,
9694 if (die
->parent
&& die
->parent
->parent
== NULL
9695 && per_cu
->unit_type
== DW_UT_compile
9696 && per_cu
->lang
== language_cplus
)
9699 /* If necessary, add it to the queue and load its DIEs. */
9700 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9701 load_full_comp_unit (per_cu
, false, cu
->language
);
9703 cu
->per_cu
->imported_symtabs_push (per_cu
);
9707 /* RAII object that represents a process_die scope: i.e.,
9708 starts/finishes processing a DIE. */
9709 class process_die_scope
9712 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9713 : m_die (die
), m_cu (cu
)
9715 /* We should only be processing DIEs not already in process. */
9716 gdb_assert (!m_die
->in_process
);
9717 m_die
->in_process
= true;
9720 ~process_die_scope ()
9722 m_die
->in_process
= false;
9724 /* If we're done processing the DIE for the CU that owns the line
9725 header, we don't need the line header anymore. */
9726 if (m_cu
->line_header_die_owner
== m_die
)
9728 delete m_cu
->line_header
;
9729 m_cu
->line_header
= NULL
;
9730 m_cu
->line_header_die_owner
= NULL
;
9739 /* Process a die and its children. */
9742 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9744 process_die_scope
scope (die
, cu
);
9748 case DW_TAG_padding
:
9750 case DW_TAG_compile_unit
:
9751 case DW_TAG_partial_unit
:
9752 read_file_scope (die
, cu
);
9754 case DW_TAG_type_unit
:
9755 read_type_unit_scope (die
, cu
);
9757 case DW_TAG_subprogram
:
9758 /* Nested subprograms in Fortran get a prefix. */
9759 if (cu
->language
== language_fortran
9760 && die
->parent
!= NULL
9761 && die
->parent
->tag
== DW_TAG_subprogram
)
9762 cu
->processing_has_namespace_info
= true;
9764 case DW_TAG_inlined_subroutine
:
9765 read_func_scope (die
, cu
);
9767 case DW_TAG_lexical_block
:
9768 case DW_TAG_try_block
:
9769 case DW_TAG_catch_block
:
9770 read_lexical_block_scope (die
, cu
);
9772 case DW_TAG_call_site
:
9773 case DW_TAG_GNU_call_site
:
9774 read_call_site_scope (die
, cu
);
9776 case DW_TAG_class_type
:
9777 case DW_TAG_interface_type
:
9778 case DW_TAG_structure_type
:
9779 case DW_TAG_union_type
:
9780 process_structure_scope (die
, cu
);
9782 case DW_TAG_enumeration_type
:
9783 process_enumeration_scope (die
, cu
);
9786 /* These dies have a type, but processing them does not create
9787 a symbol or recurse to process the children. Therefore we can
9788 read them on-demand through read_type_die. */
9789 case DW_TAG_subroutine_type
:
9790 case DW_TAG_set_type
:
9791 case DW_TAG_array_type
:
9792 case DW_TAG_pointer_type
:
9793 case DW_TAG_ptr_to_member_type
:
9794 case DW_TAG_reference_type
:
9795 case DW_TAG_rvalue_reference_type
:
9796 case DW_TAG_string_type
:
9799 case DW_TAG_base_type
:
9800 case DW_TAG_subrange_type
:
9801 case DW_TAG_typedef
:
9802 /* Add a typedef symbol for the type definition, if it has a
9804 new_symbol (die
, read_type_die (die
, cu
), cu
);
9806 case DW_TAG_common_block
:
9807 read_common_block (die
, cu
);
9809 case DW_TAG_common_inclusion
:
9811 case DW_TAG_namespace
:
9812 cu
->processing_has_namespace_info
= true;
9813 read_namespace (die
, cu
);
9816 cu
->processing_has_namespace_info
= true;
9817 read_module (die
, cu
);
9819 case DW_TAG_imported_declaration
:
9820 cu
->processing_has_namespace_info
= true;
9821 if (read_namespace_alias (die
, cu
))
9823 /* The declaration is not a global namespace alias. */
9825 case DW_TAG_imported_module
:
9826 cu
->processing_has_namespace_info
= true;
9827 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9828 || cu
->language
!= language_fortran
))
9829 complaint (_("Tag '%s' has unexpected children"),
9830 dwarf_tag_name (die
->tag
));
9831 read_import_statement (die
, cu
);
9834 case DW_TAG_imported_unit
:
9835 process_imported_unit_die (die
, cu
);
9838 case DW_TAG_variable
:
9839 read_variable (die
, cu
);
9843 new_symbol (die
, NULL
, cu
);
9848 /* DWARF name computation. */
9850 /* A helper function for dwarf2_compute_name which determines whether DIE
9851 needs to have the name of the scope prepended to the name listed in the
9855 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9857 struct attribute
*attr
;
9861 case DW_TAG_namespace
:
9862 case DW_TAG_typedef
:
9863 case DW_TAG_class_type
:
9864 case DW_TAG_interface_type
:
9865 case DW_TAG_structure_type
:
9866 case DW_TAG_union_type
:
9867 case DW_TAG_enumeration_type
:
9868 case DW_TAG_enumerator
:
9869 case DW_TAG_subprogram
:
9870 case DW_TAG_inlined_subroutine
:
9872 case DW_TAG_imported_declaration
:
9875 case DW_TAG_variable
:
9876 case DW_TAG_constant
:
9877 /* We only need to prefix "globally" visible variables. These include
9878 any variable marked with DW_AT_external or any variable that
9879 lives in a namespace. [Variables in anonymous namespaces
9880 require prefixing, but they are not DW_AT_external.] */
9882 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9884 struct dwarf2_cu
*spec_cu
= cu
;
9886 return die_needs_namespace (die_specification (die
, &spec_cu
),
9890 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9891 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9892 && die
->parent
->tag
!= DW_TAG_module
)
9894 /* A variable in a lexical block of some kind does not need a
9895 namespace, even though in C++ such variables may be external
9896 and have a mangled name. */
9897 if (die
->parent
->tag
== DW_TAG_lexical_block
9898 || die
->parent
->tag
== DW_TAG_try_block
9899 || die
->parent
->tag
== DW_TAG_catch_block
9900 || die
->parent
->tag
== DW_TAG_subprogram
)
9909 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9910 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9911 defined for the given DIE. */
9913 static struct attribute
*
9914 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9916 struct attribute
*attr
;
9918 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9920 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9925 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9926 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9927 defined for the given DIE. */
9930 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9932 const char *linkage_name
;
9934 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9935 if (linkage_name
== NULL
)
9936 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9938 return linkage_name
;
9941 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9942 compute the physname for the object, which include a method's:
9943 - formal parameters (C++),
9944 - receiver type (Go),
9946 The term "physname" is a bit confusing.
9947 For C++, for example, it is the demangled name.
9948 For Go, for example, it's the mangled name.
9950 For Ada, return the DIE's linkage name rather than the fully qualified
9951 name. PHYSNAME is ignored..
9953 The result is allocated on the objfile_obstack and canonicalized. */
9956 dwarf2_compute_name (const char *name
,
9957 struct die_info
*die
, struct dwarf2_cu
*cu
,
9960 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9963 name
= dwarf2_name (die
, cu
);
9965 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9966 but otherwise compute it by typename_concat inside GDB.
9967 FIXME: Actually this is not really true, or at least not always true.
9968 It's all very confusing. compute_and_set_names doesn't try to demangle
9969 Fortran names because there is no mangling standard. So new_symbol
9970 will set the demangled name to the result of dwarf2_full_name, and it is
9971 the demangled name that GDB uses if it exists. */
9972 if (cu
->language
== language_ada
9973 || (cu
->language
== language_fortran
&& physname
))
9975 /* For Ada unit, we prefer the linkage name over the name, as
9976 the former contains the exported name, which the user expects
9977 to be able to reference. Ideally, we want the user to be able
9978 to reference this entity using either natural or linkage name,
9979 but we haven't started looking at this enhancement yet. */
9980 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9982 if (linkage_name
!= NULL
)
9983 return linkage_name
;
9986 /* These are the only languages we know how to qualify names in. */
9988 && (cu
->language
== language_cplus
9989 || cu
->language
== language_fortran
|| cu
->language
== language_d
9990 || cu
->language
== language_rust
))
9992 if (die_needs_namespace (die
, cu
))
9995 const char *canonical_name
= NULL
;
9999 prefix
= determine_prefix (die
, cu
);
10000 if (*prefix
!= '\0')
10002 gdb::unique_xmalloc_ptr
<char> prefixed_name
10003 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10005 buf
.puts (prefixed_name
.get ());
10010 /* Template parameters may be specified in the DIE's DW_AT_name, or
10011 as children with DW_TAG_template_type_param or
10012 DW_TAG_value_type_param. If the latter, add them to the name
10013 here. If the name already has template parameters, then
10014 skip this step; some versions of GCC emit both, and
10015 it is more efficient to use the pre-computed name.
10017 Something to keep in mind about this process: it is very
10018 unlikely, or in some cases downright impossible, to produce
10019 something that will match the mangled name of a function.
10020 If the definition of the function has the same debug info,
10021 we should be able to match up with it anyway. But fallbacks
10022 using the minimal symbol, for instance to find a method
10023 implemented in a stripped copy of libstdc++, will not work.
10024 If we do not have debug info for the definition, we will have to
10025 match them up some other way.
10027 When we do name matching there is a related problem with function
10028 templates; two instantiated function templates are allowed to
10029 differ only by their return types, which we do not add here. */
10031 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10033 struct attribute
*attr
;
10034 struct die_info
*child
;
10037 die
->building_fullname
= 1;
10039 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10043 const gdb_byte
*bytes
;
10044 struct dwarf2_locexpr_baton
*baton
;
10047 if (child
->tag
!= DW_TAG_template_type_param
10048 && child
->tag
!= DW_TAG_template_value_param
)
10059 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10062 complaint (_("template parameter missing DW_AT_type"));
10063 buf
.puts ("UNKNOWN_TYPE");
10066 type
= die_type (child
, cu
);
10068 if (child
->tag
== DW_TAG_template_type_param
)
10070 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10071 &type_print_raw_options
);
10075 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10078 complaint (_("template parameter missing "
10079 "DW_AT_const_value"));
10080 buf
.puts ("UNKNOWN_VALUE");
10084 dwarf2_const_value_attr (attr
, type
, name
,
10085 &cu
->comp_unit_obstack
, cu
,
10086 &value
, &bytes
, &baton
);
10088 if (TYPE_NOSIGN (type
))
10089 /* GDB prints characters as NUMBER 'CHAR'. If that's
10090 changed, this can use value_print instead. */
10091 c_printchar (value
, type
, &buf
);
10094 struct value_print_options opts
;
10097 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10101 else if (bytes
!= NULL
)
10103 v
= allocate_value (type
);
10104 memcpy (value_contents_writeable (v
), bytes
,
10105 TYPE_LENGTH (type
));
10108 v
= value_from_longest (type
, value
);
10110 /* Specify decimal so that we do not depend on
10112 get_formatted_print_options (&opts
, 'd');
10114 value_print (v
, &buf
, &opts
);
10119 die
->building_fullname
= 0;
10123 /* Close the argument list, with a space if necessary
10124 (nested templates). */
10125 if (!buf
.empty () && buf
.string ().back () == '>')
10132 /* For C++ methods, append formal parameter type
10133 information, if PHYSNAME. */
10135 if (physname
&& die
->tag
== DW_TAG_subprogram
10136 && cu
->language
== language_cplus
)
10138 struct type
*type
= read_type_die (die
, cu
);
10140 c_type_print_args (type
, &buf
, 1, cu
->language
,
10141 &type_print_raw_options
);
10143 if (cu
->language
== language_cplus
)
10145 /* Assume that an artificial first parameter is
10146 "this", but do not crash if it is not. RealView
10147 marks unnamed (and thus unused) parameters as
10148 artificial; there is no way to differentiate
10150 if (TYPE_NFIELDS (type
) > 0
10151 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10152 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10153 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10155 buf
.puts (" const");
10159 const std::string
&intermediate_name
= buf
.string ();
10161 if (cu
->language
== language_cplus
)
10163 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10166 /* If we only computed INTERMEDIATE_NAME, or if
10167 INTERMEDIATE_NAME is already canonical, then we need to
10169 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10170 name
= objfile
->intern (intermediate_name
);
10172 name
= canonical_name
;
10179 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10180 If scope qualifiers are appropriate they will be added. The result
10181 will be allocated on the storage_obstack, or NULL if the DIE does
10182 not have a name. NAME may either be from a previous call to
10183 dwarf2_name or NULL.
10185 The output string will be canonicalized (if C++). */
10187 static const char *
10188 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10190 return dwarf2_compute_name (name
, die
, cu
, 0);
10193 /* Construct a physname for the given DIE in CU. NAME may either be
10194 from a previous call to dwarf2_name or NULL. The result will be
10195 allocated on the objfile_objstack or NULL if the DIE does not have a
10198 The output string will be canonicalized (if C++). */
10200 static const char *
10201 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10203 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10204 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10207 /* In this case dwarf2_compute_name is just a shortcut not building anything
10209 if (!die_needs_namespace (die
, cu
))
10210 return dwarf2_compute_name (name
, die
, cu
, 1);
10212 mangled
= dw2_linkage_name (die
, cu
);
10214 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10215 See https://github.com/rust-lang/rust/issues/32925. */
10216 if (cu
->language
== language_rust
&& mangled
!= NULL
10217 && strchr (mangled
, '{') != NULL
)
10220 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10222 gdb::unique_xmalloc_ptr
<char> demangled
;
10223 if (mangled
!= NULL
)
10226 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10228 /* Do nothing (do not demangle the symbol name). */
10230 else if (cu
->language
== language_go
)
10232 /* This is a lie, but we already lie to the caller new_symbol.
10233 new_symbol assumes we return the mangled name.
10234 This just undoes that lie until things are cleaned up. */
10238 /* Use DMGL_RET_DROP for C++ template functions to suppress
10239 their return type. It is easier for GDB users to search
10240 for such functions as `name(params)' than `long name(params)'.
10241 In such case the minimal symbol names do not match the full
10242 symbol names but for template functions there is never a need
10243 to look up their definition from their declaration so
10244 the only disadvantage remains the minimal symbol variant
10245 `long name(params)' does not have the proper inferior type. */
10246 demangled
.reset (gdb_demangle (mangled
,
10247 (DMGL_PARAMS
| DMGL_ANSI
10248 | DMGL_RET_DROP
)));
10251 canon
= demangled
.get ();
10259 if (canon
== NULL
|| check_physname
)
10261 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10263 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10265 /* It may not mean a bug in GDB. The compiler could also
10266 compute DW_AT_linkage_name incorrectly. But in such case
10267 GDB would need to be bug-to-bug compatible. */
10269 complaint (_("Computed physname <%s> does not match demangled <%s> "
10270 "(from linkage <%s>) - DIE at %s [in module %s]"),
10271 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10272 objfile_name (objfile
));
10274 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10275 is available here - over computed PHYSNAME. It is safer
10276 against both buggy GDB and buggy compilers. */
10290 retval
= objfile
->intern (retval
);
10295 /* Inspect DIE in CU for a namespace alias. If one exists, record
10296 a new symbol for it.
10298 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10301 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10303 struct attribute
*attr
;
10305 /* If the die does not have a name, this is not a namespace
10307 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10311 struct die_info
*d
= die
;
10312 struct dwarf2_cu
*imported_cu
= cu
;
10314 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10315 keep inspecting DIEs until we hit the underlying import. */
10316 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10317 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10319 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10323 d
= follow_die_ref (d
, attr
, &imported_cu
);
10324 if (d
->tag
!= DW_TAG_imported_declaration
)
10328 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10330 complaint (_("DIE at %s has too many recursively imported "
10331 "declarations"), sect_offset_str (d
->sect_off
));
10338 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10340 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10341 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10343 /* This declaration is a global namespace alias. Add
10344 a symbol for it whose type is the aliased namespace. */
10345 new_symbol (die
, type
, cu
);
10354 /* Return the using directives repository (global or local?) to use in the
10355 current context for CU.
10357 For Ada, imported declarations can materialize renamings, which *may* be
10358 global. However it is impossible (for now?) in DWARF to distinguish
10359 "external" imported declarations and "static" ones. As all imported
10360 declarations seem to be static in all other languages, make them all CU-wide
10361 global only in Ada. */
10363 static struct using_direct
**
10364 using_directives (struct dwarf2_cu
*cu
)
10366 if (cu
->language
== language_ada
10367 && cu
->get_builder ()->outermost_context_p ())
10368 return cu
->get_builder ()->get_global_using_directives ();
10370 return cu
->get_builder ()->get_local_using_directives ();
10373 /* Read the import statement specified by the given die and record it. */
10376 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10378 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10379 struct attribute
*import_attr
;
10380 struct die_info
*imported_die
, *child_die
;
10381 struct dwarf2_cu
*imported_cu
;
10382 const char *imported_name
;
10383 const char *imported_name_prefix
;
10384 const char *canonical_name
;
10385 const char *import_alias
;
10386 const char *imported_declaration
= NULL
;
10387 const char *import_prefix
;
10388 std::vector
<const char *> excludes
;
10390 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10391 if (import_attr
== NULL
)
10393 complaint (_("Tag '%s' has no DW_AT_import"),
10394 dwarf_tag_name (die
->tag
));
10399 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10400 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10401 if (imported_name
== NULL
)
10403 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10405 The import in the following code:
10419 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10420 <52> DW_AT_decl_file : 1
10421 <53> DW_AT_decl_line : 6
10422 <54> DW_AT_import : <0x75>
10423 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10424 <59> DW_AT_name : B
10425 <5b> DW_AT_decl_file : 1
10426 <5c> DW_AT_decl_line : 2
10427 <5d> DW_AT_type : <0x6e>
10429 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10430 <76> DW_AT_byte_size : 4
10431 <77> DW_AT_encoding : 5 (signed)
10433 imports the wrong die ( 0x75 instead of 0x58 ).
10434 This case will be ignored until the gcc bug is fixed. */
10438 /* Figure out the local name after import. */
10439 import_alias
= dwarf2_name (die
, cu
);
10441 /* Figure out where the statement is being imported to. */
10442 import_prefix
= determine_prefix (die
, cu
);
10444 /* Figure out what the scope of the imported die is and prepend it
10445 to the name of the imported die. */
10446 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10448 if (imported_die
->tag
!= DW_TAG_namespace
10449 && imported_die
->tag
!= DW_TAG_module
)
10451 imported_declaration
= imported_name
;
10452 canonical_name
= imported_name_prefix
;
10454 else if (strlen (imported_name_prefix
) > 0)
10455 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10456 imported_name_prefix
,
10457 (cu
->language
== language_d
? "." : "::"),
10458 imported_name
, (char *) NULL
);
10460 canonical_name
= imported_name
;
10462 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10463 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10464 child_die
= sibling_die (child_die
))
10466 /* DWARF-4: A Fortran use statement with a “rename list” may be
10467 represented by an imported module entry with an import attribute
10468 referring to the module and owned entries corresponding to those
10469 entities that are renamed as part of being imported. */
10471 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10473 complaint (_("child DW_TAG_imported_declaration expected "
10474 "- DIE at %s [in module %s]"),
10475 sect_offset_str (child_die
->sect_off
),
10476 objfile_name (objfile
));
10480 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10481 if (import_attr
== NULL
)
10483 complaint (_("Tag '%s' has no DW_AT_import"),
10484 dwarf_tag_name (child_die
->tag
));
10489 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10491 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10492 if (imported_name
== NULL
)
10494 complaint (_("child DW_TAG_imported_declaration has unknown "
10495 "imported name - DIE at %s [in module %s]"),
10496 sect_offset_str (child_die
->sect_off
),
10497 objfile_name (objfile
));
10501 excludes
.push_back (imported_name
);
10503 process_die (child_die
, cu
);
10506 add_using_directive (using_directives (cu
),
10510 imported_declaration
,
10513 &objfile
->objfile_obstack
);
10516 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10517 types, but gives them a size of zero. Starting with version 14,
10518 ICC is compatible with GCC. */
10521 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10523 if (!cu
->checked_producer
)
10524 check_producer (cu
);
10526 return cu
->producer_is_icc_lt_14
;
10529 /* ICC generates a DW_AT_type for C void functions. This was observed on
10530 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10531 which says that void functions should not have a DW_AT_type. */
10534 producer_is_icc (struct dwarf2_cu
*cu
)
10536 if (!cu
->checked_producer
)
10537 check_producer (cu
);
10539 return cu
->producer_is_icc
;
10542 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10543 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10544 this, it was first present in GCC release 4.3.0. */
10547 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10549 if (!cu
->checked_producer
)
10550 check_producer (cu
);
10552 return cu
->producer_is_gcc_lt_4_3
;
10555 static file_and_directory
10556 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10558 file_and_directory res
;
10560 /* Find the filename. Do not use dwarf2_name here, since the filename
10561 is not a source language identifier. */
10562 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10563 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10565 if (res
.comp_dir
== NULL
10566 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10567 && IS_ABSOLUTE_PATH (res
.name
))
10569 res
.comp_dir_storage
= ldirname (res
.name
);
10570 if (!res
.comp_dir_storage
.empty ())
10571 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10573 if (res
.comp_dir
!= NULL
)
10575 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10576 directory, get rid of it. */
10577 const char *cp
= strchr (res
.comp_dir
, ':');
10579 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10580 res
.comp_dir
= cp
+ 1;
10583 if (res
.name
== NULL
)
10584 res
.name
= "<unknown>";
10589 /* Handle DW_AT_stmt_list for a compilation unit.
10590 DIE is the DW_TAG_compile_unit die for CU.
10591 COMP_DIR is the compilation directory. LOWPC is passed to
10592 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10595 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10596 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10598 struct dwarf2_per_objfile
*dwarf2_per_objfile
10599 = cu
->per_cu
->dwarf2_per_objfile
;
10600 struct attribute
*attr
;
10601 struct line_header line_header_local
;
10602 hashval_t line_header_local_hash
;
10604 int decode_mapping
;
10606 gdb_assert (! cu
->per_cu
->is_debug_types
);
10608 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10612 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10614 /* The line header hash table is only created if needed (it exists to
10615 prevent redundant reading of the line table for partial_units).
10616 If we're given a partial_unit, we'll need it. If we're given a
10617 compile_unit, then use the line header hash table if it's already
10618 created, but don't create one just yet. */
10620 if (dwarf2_per_objfile
->line_header_hash
== NULL
10621 && die
->tag
== DW_TAG_partial_unit
)
10623 dwarf2_per_objfile
->line_header_hash
10624 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10625 line_header_eq_voidp
,
10626 free_line_header_voidp
,
10630 line_header_local
.sect_off
= line_offset
;
10631 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10632 line_header_local_hash
= line_header_hash (&line_header_local
);
10633 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10635 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10636 &line_header_local
,
10637 line_header_local_hash
, NO_INSERT
);
10639 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10640 is not present in *SLOT (since if there is something in *SLOT then
10641 it will be for a partial_unit). */
10642 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10644 gdb_assert (*slot
!= NULL
);
10645 cu
->line_header
= (struct line_header
*) *slot
;
10650 /* dwarf_decode_line_header does not yet provide sufficient information.
10651 We always have to call also dwarf_decode_lines for it. */
10652 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10656 cu
->line_header
= lh
.release ();
10657 cu
->line_header_die_owner
= die
;
10659 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10663 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10664 &line_header_local
,
10665 line_header_local_hash
, INSERT
);
10666 gdb_assert (slot
!= NULL
);
10668 if (slot
!= NULL
&& *slot
== NULL
)
10670 /* This newly decoded line number information unit will be owned
10671 by line_header_hash hash table. */
10672 *slot
= cu
->line_header
;
10673 cu
->line_header_die_owner
= NULL
;
10677 /* We cannot free any current entry in (*slot) as that struct line_header
10678 may be already used by multiple CUs. Create only temporary decoded
10679 line_header for this CU - it may happen at most once for each line
10680 number information unit. And if we're not using line_header_hash
10681 then this is what we want as well. */
10682 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10684 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10685 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10690 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10693 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10695 struct dwarf2_per_objfile
*dwarf2_per_objfile
10696 = cu
->per_cu
->dwarf2_per_objfile
;
10697 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10698 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10699 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10700 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10701 struct attribute
*attr
;
10702 struct die_info
*child_die
;
10703 CORE_ADDR baseaddr
;
10705 prepare_one_comp_unit (cu
, die
, cu
->language
);
10706 baseaddr
= objfile
->text_section_offset ();
10708 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10710 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10711 from finish_block. */
10712 if (lowpc
== ((CORE_ADDR
) -1))
10714 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10716 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10718 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10719 standardised yet. As a workaround for the language detection we fall
10720 back to the DW_AT_producer string. */
10721 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10722 cu
->language
= language_opencl
;
10724 /* Similar hack for Go. */
10725 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10726 set_cu_language (DW_LANG_Go
, cu
);
10728 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10730 /* Decode line number information if present. We do this before
10731 processing child DIEs, so that the line header table is available
10732 for DW_AT_decl_file. */
10733 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10735 /* Process all dies in compilation unit. */
10736 if (die
->child
!= NULL
)
10738 child_die
= die
->child
;
10739 while (child_die
&& child_die
->tag
)
10741 process_die (child_die
, cu
);
10742 child_die
= sibling_die (child_die
);
10746 /* Decode macro information, if present. Dwarf 2 macro information
10747 refers to information in the line number info statement program
10748 header, so we can only read it if we've read the header
10750 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10752 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10753 if (attr
&& cu
->line_header
)
10755 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10756 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10758 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10762 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10763 if (attr
&& cu
->line_header
)
10765 unsigned int macro_offset
= DW_UNSND (attr
);
10767 dwarf_decode_macros (cu
, macro_offset
, 0);
10773 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10775 struct type_unit_group
*tu_group
;
10777 struct attribute
*attr
;
10779 struct signatured_type
*sig_type
;
10781 gdb_assert (per_cu
->is_debug_types
);
10782 sig_type
= (struct signatured_type
*) per_cu
;
10784 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10786 /* If we're using .gdb_index (includes -readnow) then
10787 per_cu->type_unit_group may not have been set up yet. */
10788 if (sig_type
->type_unit_group
== NULL
)
10789 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10790 tu_group
= sig_type
->type_unit_group
;
10792 /* If we've already processed this stmt_list there's no real need to
10793 do it again, we could fake it and just recreate the part we need
10794 (file name,index -> symtab mapping). If data shows this optimization
10795 is useful we can do it then. */
10796 first_time
= tu_group
->compunit_symtab
== NULL
;
10798 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10803 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10804 lh
= dwarf_decode_line_header (line_offset
, this);
10809 start_symtab ("", NULL
, 0);
10812 gdb_assert (tu_group
->symtabs
== NULL
);
10813 gdb_assert (m_builder
== nullptr);
10814 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10815 m_builder
.reset (new struct buildsym_compunit
10816 (COMPUNIT_OBJFILE (cust
), "",
10817 COMPUNIT_DIRNAME (cust
),
10818 compunit_language (cust
),
10824 line_header
= lh
.release ();
10825 line_header_die_owner
= die
;
10829 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10831 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10832 still initializing it, and our caller (a few levels up)
10833 process_full_type_unit still needs to know if this is the first
10837 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10838 struct symtab
*, line_header
->file_names_size ());
10840 auto &file_names
= line_header
->file_names ();
10841 for (i
= 0; i
< file_names
.size (); ++i
)
10843 file_entry
&fe
= file_names
[i
];
10844 dwarf2_start_subfile (this, fe
.name
,
10845 fe
.include_dir (line_header
));
10846 buildsym_compunit
*b
= get_builder ();
10847 if (b
->get_current_subfile ()->symtab
== NULL
)
10849 /* NOTE: start_subfile will recognize when it's been
10850 passed a file it has already seen. So we can't
10851 assume there's a simple mapping from
10852 cu->line_header->file_names to subfiles, plus
10853 cu->line_header->file_names may contain dups. */
10854 b
->get_current_subfile ()->symtab
10855 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10858 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10859 tu_group
->symtabs
[i
] = fe
.symtab
;
10864 gdb_assert (m_builder
== nullptr);
10865 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10866 m_builder
.reset (new struct buildsym_compunit
10867 (COMPUNIT_OBJFILE (cust
), "",
10868 COMPUNIT_DIRNAME (cust
),
10869 compunit_language (cust
),
10872 auto &file_names
= line_header
->file_names ();
10873 for (i
= 0; i
< file_names
.size (); ++i
)
10875 file_entry
&fe
= file_names
[i
];
10876 fe
.symtab
= tu_group
->symtabs
[i
];
10880 /* The main symtab is allocated last. Type units don't have DW_AT_name
10881 so they don't have a "real" (so to speak) symtab anyway.
10882 There is later code that will assign the main symtab to all symbols
10883 that don't have one. We need to handle the case of a symbol with a
10884 missing symtab (DW_AT_decl_file) anyway. */
10887 /* Process DW_TAG_type_unit.
10888 For TUs we want to skip the first top level sibling if it's not the
10889 actual type being defined by this TU. In this case the first top
10890 level sibling is there to provide context only. */
10893 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10895 struct die_info
*child_die
;
10897 prepare_one_comp_unit (cu
, die
, language_minimal
);
10899 /* Initialize (or reinitialize) the machinery for building symtabs.
10900 We do this before processing child DIEs, so that the line header table
10901 is available for DW_AT_decl_file. */
10902 cu
->setup_type_unit_groups (die
);
10904 if (die
->child
!= NULL
)
10906 child_die
= die
->child
;
10907 while (child_die
&& child_die
->tag
)
10909 process_die (child_die
, cu
);
10910 child_die
= sibling_die (child_die
);
10917 http://gcc.gnu.org/wiki/DebugFission
10918 http://gcc.gnu.org/wiki/DebugFissionDWP
10920 To simplify handling of both DWO files ("object" files with the DWARF info)
10921 and DWP files (a file with the DWOs packaged up into one file), we treat
10922 DWP files as having a collection of virtual DWO files. */
10925 hash_dwo_file (const void *item
)
10927 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10930 hash
= htab_hash_string (dwo_file
->dwo_name
);
10931 if (dwo_file
->comp_dir
!= NULL
)
10932 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10937 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10939 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10940 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10942 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10944 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10945 return lhs
->comp_dir
== rhs
->comp_dir
;
10946 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10949 /* Allocate a hash table for DWO files. */
10952 allocate_dwo_file_hash_table ()
10954 auto delete_dwo_file
= [] (void *item
)
10956 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10961 return htab_up (htab_create_alloc (41,
10968 /* Lookup DWO file DWO_NAME. */
10971 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
10972 const char *dwo_name
,
10973 const char *comp_dir
)
10975 struct dwo_file find_entry
;
10978 if (dwarf2_per_objfile
->dwo_files
== NULL
)
10979 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
10981 find_entry
.dwo_name
= dwo_name
;
10982 find_entry
.comp_dir
= comp_dir
;
10983 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
10990 hash_dwo_unit (const void *item
)
10992 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10994 /* This drops the top 32 bits of the id, but is ok for a hash. */
10995 return dwo_unit
->signature
;
10999 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11001 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11002 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11004 /* The signature is assumed to be unique within the DWO file.
11005 So while object file CU dwo_id's always have the value zero,
11006 that's OK, assuming each object file DWO file has only one CU,
11007 and that's the rule for now. */
11008 return lhs
->signature
== rhs
->signature
;
11011 /* Allocate a hash table for DWO CUs,TUs.
11012 There is one of these tables for each of CUs,TUs for each DWO file. */
11015 allocate_dwo_unit_table ()
11017 /* Start out with a pretty small number.
11018 Generally DWO files contain only one CU and maybe some TUs. */
11019 return htab_up (htab_create_alloc (3,
11022 NULL
, xcalloc
, xfree
));
11025 /* die_reader_func for create_dwo_cu. */
11028 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11029 const gdb_byte
*info_ptr
,
11030 struct die_info
*comp_unit_die
,
11031 struct dwo_file
*dwo_file
,
11032 struct dwo_unit
*dwo_unit
)
11034 struct dwarf2_cu
*cu
= reader
->cu
;
11035 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11036 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11038 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11039 if (!signature
.has_value ())
11041 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11042 " its dwo_id [in module %s]"),
11043 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11047 dwo_unit
->dwo_file
= dwo_file
;
11048 dwo_unit
->signature
= *signature
;
11049 dwo_unit
->section
= section
;
11050 dwo_unit
->sect_off
= sect_off
;
11051 dwo_unit
->length
= cu
->per_cu
->length
;
11053 if (dwarf_read_debug
)
11054 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11055 sect_offset_str (sect_off
),
11056 hex_string (dwo_unit
->signature
));
11059 /* Create the dwo_units for the CUs in a DWO_FILE.
11060 Note: This function processes DWO files only, not DWP files. */
11063 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11064 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11065 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11067 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11068 const gdb_byte
*info_ptr
, *end_ptr
;
11070 section
.read (objfile
);
11071 info_ptr
= section
.buffer
;
11073 if (info_ptr
== NULL
)
11076 if (dwarf_read_debug
)
11078 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11079 section
.get_name (),
11080 section
.get_file_name ());
11083 end_ptr
= info_ptr
+ section
.size
;
11084 while (info_ptr
< end_ptr
)
11086 struct dwarf2_per_cu_data per_cu
;
11087 struct dwo_unit read_unit
{};
11088 struct dwo_unit
*dwo_unit
;
11090 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11092 memset (&per_cu
, 0, sizeof (per_cu
));
11093 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11094 per_cu
.is_debug_types
= 0;
11095 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11096 per_cu
.section
= §ion
;
11098 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11099 if (!reader
.dummy_p
)
11100 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11101 &dwo_file
, &read_unit
);
11102 info_ptr
+= per_cu
.length
;
11104 // If the unit could not be parsed, skip it.
11105 if (read_unit
.dwo_file
== NULL
)
11108 if (cus_htab
== NULL
)
11109 cus_htab
= allocate_dwo_unit_table ();
11111 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11112 *dwo_unit
= read_unit
;
11113 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11114 gdb_assert (slot
!= NULL
);
11117 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11118 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11120 complaint (_("debug cu entry at offset %s is duplicate to"
11121 " the entry at offset %s, signature %s"),
11122 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11123 hex_string (dwo_unit
->signature
));
11125 *slot
= (void *)dwo_unit
;
11129 /* DWP file .debug_{cu,tu}_index section format:
11130 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11134 Both index sections have the same format, and serve to map a 64-bit
11135 signature to a set of section numbers. Each section begins with a header,
11136 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11137 indexes, and a pool of 32-bit section numbers. The index sections will be
11138 aligned at 8-byte boundaries in the file.
11140 The index section header consists of:
11142 V, 32 bit version number
11144 N, 32 bit number of compilation units or type units in the index
11145 M, 32 bit number of slots in the hash table
11147 Numbers are recorded using the byte order of the application binary.
11149 The hash table begins at offset 16 in the section, and consists of an array
11150 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11151 order of the application binary). Unused slots in the hash table are 0.
11152 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11154 The parallel table begins immediately after the hash table
11155 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11156 array of 32-bit indexes (using the byte order of the application binary),
11157 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11158 table contains a 32-bit index into the pool of section numbers. For unused
11159 hash table slots, the corresponding entry in the parallel table will be 0.
11161 The pool of section numbers begins immediately following the hash table
11162 (at offset 16 + 12 * M from the beginning of the section). The pool of
11163 section numbers consists of an array of 32-bit words (using the byte order
11164 of the application binary). Each item in the array is indexed starting
11165 from 0. The hash table entry provides the index of the first section
11166 number in the set. Additional section numbers in the set follow, and the
11167 set is terminated by a 0 entry (section number 0 is not used in ELF).
11169 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11170 section must be the first entry in the set, and the .debug_abbrev.dwo must
11171 be the second entry. Other members of the set may follow in any order.
11177 DWP Version 2 combines all the .debug_info, etc. sections into one,
11178 and the entries in the index tables are now offsets into these sections.
11179 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11182 Index Section Contents:
11184 Hash Table of Signatures dwp_hash_table.hash_table
11185 Parallel Table of Indices dwp_hash_table.unit_table
11186 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11187 Table of Section Sizes dwp_hash_table.v2.sizes
11189 The index section header consists of:
11191 V, 32 bit version number
11192 L, 32 bit number of columns in the table of section offsets
11193 N, 32 bit number of compilation units or type units in the index
11194 M, 32 bit number of slots in the hash table
11196 Numbers are recorded using the byte order of the application binary.
11198 The hash table has the same format as version 1.
11199 The parallel table of indices has the same format as version 1,
11200 except that the entries are origin-1 indices into the table of sections
11201 offsets and the table of section sizes.
11203 The table of offsets begins immediately following the parallel table
11204 (at offset 16 + 12 * M from the beginning of the section). The table is
11205 a two-dimensional array of 32-bit words (using the byte order of the
11206 application binary), with L columns and N+1 rows, in row-major order.
11207 Each row in the array is indexed starting from 0. The first row provides
11208 a key to the remaining rows: each column in this row provides an identifier
11209 for a debug section, and the offsets in the same column of subsequent rows
11210 refer to that section. The section identifiers are:
11212 DW_SECT_INFO 1 .debug_info.dwo
11213 DW_SECT_TYPES 2 .debug_types.dwo
11214 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11215 DW_SECT_LINE 4 .debug_line.dwo
11216 DW_SECT_LOC 5 .debug_loc.dwo
11217 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11218 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11219 DW_SECT_MACRO 8 .debug_macro.dwo
11221 The offsets provided by the CU and TU index sections are the base offsets
11222 for the contributions made by each CU or TU to the corresponding section
11223 in the package file. Each CU and TU header contains an abbrev_offset
11224 field, used to find the abbreviations table for that CU or TU within the
11225 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11226 be interpreted as relative to the base offset given in the index section.
11227 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11228 should be interpreted as relative to the base offset for .debug_line.dwo,
11229 and offsets into other debug sections obtained from DWARF attributes should
11230 also be interpreted as relative to the corresponding base offset.
11232 The table of sizes begins immediately following the table of offsets.
11233 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11234 with L columns and N rows, in row-major order. Each row in the array is
11235 indexed starting from 1 (row 0 is shared by the two tables).
11239 Hash table lookup is handled the same in version 1 and 2:
11241 We assume that N and M will not exceed 2^32 - 1.
11242 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11244 Given a 64-bit compilation unit signature or a type signature S, an entry
11245 in the hash table is located as follows:
11247 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11248 the low-order k bits all set to 1.
11250 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11252 3) If the hash table entry at index H matches the signature, use that
11253 entry. If the hash table entry at index H is unused (all zeroes),
11254 terminate the search: the signature is not present in the table.
11256 4) Let H = (H + H') modulo M. Repeat at Step 3.
11258 Because M > N and H' and M are relatively prime, the search is guaranteed
11259 to stop at an unused slot or find the match. */
11261 /* Create a hash table to map DWO IDs to their CU/TU entry in
11262 .debug_{info,types}.dwo in DWP_FILE.
11263 Returns NULL if there isn't one.
11264 Note: This function processes DWP files only, not DWO files. */
11266 static struct dwp_hash_table
*
11267 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11268 struct dwp_file
*dwp_file
, int is_debug_types
)
11270 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11271 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11272 const gdb_byte
*index_ptr
, *index_end
;
11273 struct dwarf2_section_info
*index
;
11274 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11275 struct dwp_hash_table
*htab
;
11277 if (is_debug_types
)
11278 index
= &dwp_file
->sections
.tu_index
;
11280 index
= &dwp_file
->sections
.cu_index
;
11282 if (index
->empty ())
11284 index
->read (objfile
);
11286 index_ptr
= index
->buffer
;
11287 index_end
= index_ptr
+ index
->size
;
11289 version
= read_4_bytes (dbfd
, index_ptr
);
11292 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11296 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11298 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11301 if (version
!= 1 && version
!= 2)
11303 error (_("Dwarf Error: unsupported DWP file version (%s)"
11304 " [in module %s]"),
11305 pulongest (version
), dwp_file
->name
);
11307 if (nr_slots
!= (nr_slots
& -nr_slots
))
11309 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11310 " is not power of 2 [in module %s]"),
11311 pulongest (nr_slots
), dwp_file
->name
);
11314 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11315 htab
->version
= version
;
11316 htab
->nr_columns
= nr_columns
;
11317 htab
->nr_units
= nr_units
;
11318 htab
->nr_slots
= nr_slots
;
11319 htab
->hash_table
= index_ptr
;
11320 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11322 /* Exit early if the table is empty. */
11323 if (nr_slots
== 0 || nr_units
== 0
11324 || (version
== 2 && nr_columns
== 0))
11326 /* All must be zero. */
11327 if (nr_slots
!= 0 || nr_units
!= 0
11328 || (version
== 2 && nr_columns
!= 0))
11330 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11331 " all zero [in modules %s]"),
11339 htab
->section_pool
.v1
.indices
=
11340 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11341 /* It's harder to decide whether the section is too small in v1.
11342 V1 is deprecated anyway so we punt. */
11346 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11347 int *ids
= htab
->section_pool
.v2
.section_ids
;
11348 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11349 /* Reverse map for error checking. */
11350 int ids_seen
[DW_SECT_MAX
+ 1];
11353 if (nr_columns
< 2)
11355 error (_("Dwarf Error: bad DWP hash table, too few columns"
11356 " in section table [in module %s]"),
11359 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11361 error (_("Dwarf Error: bad DWP hash table, too many columns"
11362 " in section table [in module %s]"),
11365 memset (ids
, 255, sizeof_ids
);
11366 memset (ids_seen
, 255, sizeof (ids_seen
));
11367 for (i
= 0; i
< nr_columns
; ++i
)
11369 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11371 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11373 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11374 " in section table [in module %s]"),
11375 id
, dwp_file
->name
);
11377 if (ids_seen
[id
] != -1)
11379 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11380 " id %d in section table [in module %s]"),
11381 id
, dwp_file
->name
);
11386 /* Must have exactly one info or types section. */
11387 if (((ids_seen
[DW_SECT_INFO
] != -1)
11388 + (ids_seen
[DW_SECT_TYPES
] != -1))
11391 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11392 " DWO info/types section [in module %s]"),
11395 /* Must have an abbrev section. */
11396 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11398 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11399 " section [in module %s]"),
11402 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11403 htab
->section_pool
.v2
.sizes
=
11404 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11405 * nr_units
* nr_columns
);
11406 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11407 * nr_units
* nr_columns
))
11410 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11411 " [in module %s]"),
11419 /* Update SECTIONS with the data from SECTP.
11421 This function is like the other "locate" section routines that are
11422 passed to bfd_map_over_sections, but in this context the sections to
11423 read comes from the DWP V1 hash table, not the full ELF section table.
11425 The result is non-zero for success, or zero if an error was found. */
11428 locate_v1_virtual_dwo_sections (asection
*sectp
,
11429 struct virtual_v1_dwo_sections
*sections
)
11431 const struct dwop_section_names
*names
= &dwop_section_names
;
11433 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11435 /* There can be only one. */
11436 if (sections
->abbrev
.s
.section
!= NULL
)
11438 sections
->abbrev
.s
.section
= sectp
;
11439 sections
->abbrev
.size
= bfd_section_size (sectp
);
11441 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11442 || section_is_p (sectp
->name
, &names
->types_dwo
))
11444 /* There can be only one. */
11445 if (sections
->info_or_types
.s
.section
!= NULL
)
11447 sections
->info_or_types
.s
.section
= sectp
;
11448 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11450 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11452 /* There can be only one. */
11453 if (sections
->line
.s
.section
!= NULL
)
11455 sections
->line
.s
.section
= sectp
;
11456 sections
->line
.size
= bfd_section_size (sectp
);
11458 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11460 /* There can be only one. */
11461 if (sections
->loc
.s
.section
!= NULL
)
11463 sections
->loc
.s
.section
= sectp
;
11464 sections
->loc
.size
= bfd_section_size (sectp
);
11466 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11468 /* There can be only one. */
11469 if (sections
->macinfo
.s
.section
!= NULL
)
11471 sections
->macinfo
.s
.section
= sectp
;
11472 sections
->macinfo
.size
= bfd_section_size (sectp
);
11474 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11476 /* There can be only one. */
11477 if (sections
->macro
.s
.section
!= NULL
)
11479 sections
->macro
.s
.section
= sectp
;
11480 sections
->macro
.size
= bfd_section_size (sectp
);
11482 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11484 /* There can be only one. */
11485 if (sections
->str_offsets
.s
.section
!= NULL
)
11487 sections
->str_offsets
.s
.section
= sectp
;
11488 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11492 /* No other kind of section is valid. */
11499 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11500 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11501 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11502 This is for DWP version 1 files. */
11504 static struct dwo_unit
*
11505 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11506 struct dwp_file
*dwp_file
,
11507 uint32_t unit_index
,
11508 const char *comp_dir
,
11509 ULONGEST signature
, int is_debug_types
)
11511 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11512 const struct dwp_hash_table
*dwp_htab
=
11513 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11514 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11515 const char *kind
= is_debug_types
? "TU" : "CU";
11516 struct dwo_file
*dwo_file
;
11517 struct dwo_unit
*dwo_unit
;
11518 struct virtual_v1_dwo_sections sections
;
11519 void **dwo_file_slot
;
11522 gdb_assert (dwp_file
->version
== 1);
11524 if (dwarf_read_debug
)
11526 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11528 pulongest (unit_index
), hex_string (signature
),
11532 /* Fetch the sections of this DWO unit.
11533 Put a limit on the number of sections we look for so that bad data
11534 doesn't cause us to loop forever. */
11536 #define MAX_NR_V1_DWO_SECTIONS \
11537 (1 /* .debug_info or .debug_types */ \
11538 + 1 /* .debug_abbrev */ \
11539 + 1 /* .debug_line */ \
11540 + 1 /* .debug_loc */ \
11541 + 1 /* .debug_str_offsets */ \
11542 + 1 /* .debug_macro or .debug_macinfo */ \
11543 + 1 /* trailing zero */)
11545 memset (§ions
, 0, sizeof (sections
));
11547 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11550 uint32_t section_nr
=
11551 read_4_bytes (dbfd
,
11552 dwp_htab
->section_pool
.v1
.indices
11553 + (unit_index
+ i
) * sizeof (uint32_t));
11555 if (section_nr
== 0)
11557 if (section_nr
>= dwp_file
->num_sections
)
11559 error (_("Dwarf Error: bad DWP hash table, section number too large"
11560 " [in module %s]"),
11564 sectp
= dwp_file
->elf_sections
[section_nr
];
11565 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11567 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11568 " [in module %s]"),
11574 || sections
.info_or_types
.empty ()
11575 || sections
.abbrev
.empty ())
11577 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11578 " [in module %s]"),
11581 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11583 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11584 " [in module %s]"),
11588 /* It's easier for the rest of the code if we fake a struct dwo_file and
11589 have dwo_unit "live" in that. At least for now.
11591 The DWP file can be made up of a random collection of CUs and TUs.
11592 However, for each CU + set of TUs that came from the same original DWO
11593 file, we can combine them back into a virtual DWO file to save space
11594 (fewer struct dwo_file objects to allocate). Remember that for really
11595 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11597 std::string virtual_dwo_name
=
11598 string_printf ("virtual-dwo/%d-%d-%d-%d",
11599 sections
.abbrev
.get_id (),
11600 sections
.line
.get_id (),
11601 sections
.loc
.get_id (),
11602 sections
.str_offsets
.get_id ());
11603 /* Can we use an existing virtual DWO file? */
11604 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11605 virtual_dwo_name
.c_str (),
11607 /* Create one if necessary. */
11608 if (*dwo_file_slot
== NULL
)
11610 if (dwarf_read_debug
)
11612 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11613 virtual_dwo_name
.c_str ());
11615 dwo_file
= new struct dwo_file
;
11616 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11617 dwo_file
->comp_dir
= comp_dir
;
11618 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11619 dwo_file
->sections
.line
= sections
.line
;
11620 dwo_file
->sections
.loc
= sections
.loc
;
11621 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11622 dwo_file
->sections
.macro
= sections
.macro
;
11623 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11624 /* The "str" section is global to the entire DWP file. */
11625 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11626 /* The info or types section is assigned below to dwo_unit,
11627 there's no need to record it in dwo_file.
11628 Also, we can't simply record type sections in dwo_file because
11629 we record a pointer into the vector in dwo_unit. As we collect more
11630 types we'll grow the vector and eventually have to reallocate space
11631 for it, invalidating all copies of pointers into the previous
11633 *dwo_file_slot
= dwo_file
;
11637 if (dwarf_read_debug
)
11639 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11640 virtual_dwo_name
.c_str ());
11642 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11645 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11646 dwo_unit
->dwo_file
= dwo_file
;
11647 dwo_unit
->signature
= signature
;
11648 dwo_unit
->section
=
11649 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11650 *dwo_unit
->section
= sections
.info_or_types
;
11651 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11656 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11657 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11658 piece within that section used by a TU/CU, return a virtual section
11659 of just that piece. */
11661 static struct dwarf2_section_info
11662 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11663 struct dwarf2_section_info
*section
,
11664 bfd_size_type offset
, bfd_size_type size
)
11666 struct dwarf2_section_info result
;
11669 gdb_assert (section
!= NULL
);
11670 gdb_assert (!section
->is_virtual
);
11672 memset (&result
, 0, sizeof (result
));
11673 result
.s
.containing_section
= section
;
11674 result
.is_virtual
= true;
11679 sectp
= section
->get_bfd_section ();
11681 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11682 bounds of the real section. This is a pretty-rare event, so just
11683 flag an error (easier) instead of a warning and trying to cope. */
11685 || offset
+ size
> bfd_section_size (sectp
))
11687 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11688 " in section %s [in module %s]"),
11689 sectp
? bfd_section_name (sectp
) : "<unknown>",
11690 objfile_name (dwarf2_per_objfile
->objfile
));
11693 result
.virtual_offset
= offset
;
11694 result
.size
= size
;
11698 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11699 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11700 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11701 This is for DWP version 2 files. */
11703 static struct dwo_unit
*
11704 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11705 struct dwp_file
*dwp_file
,
11706 uint32_t unit_index
,
11707 const char *comp_dir
,
11708 ULONGEST signature
, int is_debug_types
)
11710 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11711 const struct dwp_hash_table
*dwp_htab
=
11712 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11713 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11714 const char *kind
= is_debug_types
? "TU" : "CU";
11715 struct dwo_file
*dwo_file
;
11716 struct dwo_unit
*dwo_unit
;
11717 struct virtual_v2_dwo_sections sections
;
11718 void **dwo_file_slot
;
11721 gdb_assert (dwp_file
->version
== 2);
11723 if (dwarf_read_debug
)
11725 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11727 pulongest (unit_index
), hex_string (signature
),
11731 /* Fetch the section offsets of this DWO unit. */
11733 memset (§ions
, 0, sizeof (sections
));
11735 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11737 uint32_t offset
= read_4_bytes (dbfd
,
11738 dwp_htab
->section_pool
.v2
.offsets
11739 + (((unit_index
- 1) * dwp_htab
->nr_columns
11741 * sizeof (uint32_t)));
11742 uint32_t size
= read_4_bytes (dbfd
,
11743 dwp_htab
->section_pool
.v2
.sizes
11744 + (((unit_index
- 1) * dwp_htab
->nr_columns
11746 * sizeof (uint32_t)));
11748 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11751 case DW_SECT_TYPES
:
11752 sections
.info_or_types_offset
= offset
;
11753 sections
.info_or_types_size
= size
;
11755 case DW_SECT_ABBREV
:
11756 sections
.abbrev_offset
= offset
;
11757 sections
.abbrev_size
= size
;
11760 sections
.line_offset
= offset
;
11761 sections
.line_size
= size
;
11764 sections
.loc_offset
= offset
;
11765 sections
.loc_size
= size
;
11767 case DW_SECT_STR_OFFSETS
:
11768 sections
.str_offsets_offset
= offset
;
11769 sections
.str_offsets_size
= size
;
11771 case DW_SECT_MACINFO
:
11772 sections
.macinfo_offset
= offset
;
11773 sections
.macinfo_size
= size
;
11775 case DW_SECT_MACRO
:
11776 sections
.macro_offset
= offset
;
11777 sections
.macro_size
= size
;
11782 /* It's easier for the rest of the code if we fake a struct dwo_file and
11783 have dwo_unit "live" in that. At least for now.
11785 The DWP file can be made up of a random collection of CUs and TUs.
11786 However, for each CU + set of TUs that came from the same original DWO
11787 file, we can combine them back into a virtual DWO file to save space
11788 (fewer struct dwo_file objects to allocate). Remember that for really
11789 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11791 std::string virtual_dwo_name
=
11792 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11793 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11794 (long) (sections
.line_size
? sections
.line_offset
: 0),
11795 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11796 (long) (sections
.str_offsets_size
11797 ? sections
.str_offsets_offset
: 0));
11798 /* Can we use an existing virtual DWO file? */
11799 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11800 virtual_dwo_name
.c_str (),
11802 /* Create one if necessary. */
11803 if (*dwo_file_slot
== NULL
)
11805 if (dwarf_read_debug
)
11807 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11808 virtual_dwo_name
.c_str ());
11810 dwo_file
= new struct dwo_file
;
11811 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11812 dwo_file
->comp_dir
= comp_dir
;
11813 dwo_file
->sections
.abbrev
=
11814 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11815 sections
.abbrev_offset
, sections
.abbrev_size
);
11816 dwo_file
->sections
.line
=
11817 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11818 sections
.line_offset
, sections
.line_size
);
11819 dwo_file
->sections
.loc
=
11820 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11821 sections
.loc_offset
, sections
.loc_size
);
11822 dwo_file
->sections
.macinfo
=
11823 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11824 sections
.macinfo_offset
, sections
.macinfo_size
);
11825 dwo_file
->sections
.macro
=
11826 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11827 sections
.macro_offset
, sections
.macro_size
);
11828 dwo_file
->sections
.str_offsets
=
11829 create_dwp_v2_section (dwarf2_per_objfile
,
11830 &dwp_file
->sections
.str_offsets
,
11831 sections
.str_offsets_offset
,
11832 sections
.str_offsets_size
);
11833 /* The "str" section is global to the entire DWP file. */
11834 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11835 /* The info or types section is assigned below to dwo_unit,
11836 there's no need to record it in dwo_file.
11837 Also, we can't simply record type sections in dwo_file because
11838 we record a pointer into the vector in dwo_unit. As we collect more
11839 types we'll grow the vector and eventually have to reallocate space
11840 for it, invalidating all copies of pointers into the previous
11842 *dwo_file_slot
= dwo_file
;
11846 if (dwarf_read_debug
)
11848 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11849 virtual_dwo_name
.c_str ());
11851 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11854 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11855 dwo_unit
->dwo_file
= dwo_file
;
11856 dwo_unit
->signature
= signature
;
11857 dwo_unit
->section
=
11858 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11859 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11861 ? &dwp_file
->sections
.types
11862 : &dwp_file
->sections
.info
,
11863 sections
.info_or_types_offset
,
11864 sections
.info_or_types_size
);
11865 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11870 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11871 Returns NULL if the signature isn't found. */
11873 static struct dwo_unit
*
11874 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11875 struct dwp_file
*dwp_file
, const char *comp_dir
,
11876 ULONGEST signature
, int is_debug_types
)
11878 const struct dwp_hash_table
*dwp_htab
=
11879 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11880 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11881 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11882 uint32_t hash
= signature
& mask
;
11883 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11886 struct dwo_unit find_dwo_cu
;
11888 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11889 find_dwo_cu
.signature
= signature
;
11890 slot
= htab_find_slot (is_debug_types
11891 ? dwp_file
->loaded_tus
.get ()
11892 : dwp_file
->loaded_cus
.get (),
11893 &find_dwo_cu
, INSERT
);
11896 return (struct dwo_unit
*) *slot
;
11898 /* Use a for loop so that we don't loop forever on bad debug info. */
11899 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11901 ULONGEST signature_in_table
;
11903 signature_in_table
=
11904 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11905 if (signature_in_table
== signature
)
11907 uint32_t unit_index
=
11908 read_4_bytes (dbfd
,
11909 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11911 if (dwp_file
->version
== 1)
11913 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11914 dwp_file
, unit_index
,
11915 comp_dir
, signature
,
11920 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11921 dwp_file
, unit_index
,
11922 comp_dir
, signature
,
11925 return (struct dwo_unit
*) *slot
;
11927 if (signature_in_table
== 0)
11929 hash
= (hash
+ hash2
) & mask
;
11932 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11933 " [in module %s]"),
11937 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11938 Open the file specified by FILE_NAME and hand it off to BFD for
11939 preliminary analysis. Return a newly initialized bfd *, which
11940 includes a canonicalized copy of FILE_NAME.
11941 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11942 SEARCH_CWD is true if the current directory is to be searched.
11943 It will be searched before debug-file-directory.
11944 If successful, the file is added to the bfd include table of the
11945 objfile's bfd (see gdb_bfd_record_inclusion).
11946 If unable to find/open the file, return NULL.
11947 NOTE: This function is derived from symfile_bfd_open. */
11949 static gdb_bfd_ref_ptr
11950 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11951 const char *file_name
, int is_dwp
, int search_cwd
)
11954 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11955 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11956 to debug_file_directory. */
11957 const char *search_path
;
11958 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11960 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11963 if (*debug_file_directory
!= '\0')
11965 search_path_holder
.reset (concat (".", dirname_separator_string
,
11966 debug_file_directory
,
11968 search_path
= search_path_holder
.get ();
11974 search_path
= debug_file_directory
;
11976 openp_flags flags
= OPF_RETURN_REALPATH
;
11978 flags
|= OPF_SEARCH_IN_PATH
;
11980 gdb::unique_xmalloc_ptr
<char> absolute_name
;
11981 desc
= openp (search_path
, flags
, file_name
,
11982 O_RDONLY
| O_BINARY
, &absolute_name
);
11986 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
11988 if (sym_bfd
== NULL
)
11990 bfd_set_cacheable (sym_bfd
.get (), 1);
11992 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
11995 /* Success. Record the bfd as having been included by the objfile's bfd.
11996 This is important because things like demangled_names_hash lives in the
11997 objfile's per_bfd space and may have references to things like symbol
11998 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
11999 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12004 /* Try to open DWO file FILE_NAME.
12005 COMP_DIR is the DW_AT_comp_dir attribute.
12006 The result is the bfd handle of the file.
12007 If there is a problem finding or opening the file, return NULL.
12008 Upon success, the canonicalized path of the file is stored in the bfd,
12009 same as symfile_bfd_open. */
12011 static gdb_bfd_ref_ptr
12012 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12013 const char *file_name
, const char *comp_dir
)
12015 if (IS_ABSOLUTE_PATH (file_name
))
12016 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12017 0 /*is_dwp*/, 0 /*search_cwd*/);
12019 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12021 if (comp_dir
!= NULL
)
12023 gdb::unique_xmalloc_ptr
<char> path_to_try
12024 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12026 /* NOTE: If comp_dir is a relative path, this will also try the
12027 search path, which seems useful. */
12028 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12029 path_to_try
.get (),
12031 1 /*search_cwd*/));
12036 /* That didn't work, try debug-file-directory, which, despite its name,
12037 is a list of paths. */
12039 if (*debug_file_directory
== '\0')
12042 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12043 0 /*is_dwp*/, 1 /*search_cwd*/);
12046 /* This function is mapped across the sections and remembers the offset and
12047 size of each of the DWO debugging sections we are interested in. */
12050 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12052 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12053 const struct dwop_section_names
*names
= &dwop_section_names
;
12055 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12057 dwo_sections
->abbrev
.s
.section
= sectp
;
12058 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12060 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12062 dwo_sections
->info
.s
.section
= sectp
;
12063 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12065 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12067 dwo_sections
->line
.s
.section
= sectp
;
12068 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12070 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12072 dwo_sections
->loc
.s
.section
= sectp
;
12073 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12075 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12077 dwo_sections
->macinfo
.s
.section
= sectp
;
12078 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12080 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12082 dwo_sections
->macro
.s
.section
= sectp
;
12083 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12085 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12087 dwo_sections
->str
.s
.section
= sectp
;
12088 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12090 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12092 dwo_sections
->str_offsets
.s
.section
= sectp
;
12093 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12095 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12097 struct dwarf2_section_info type_section
;
12099 memset (&type_section
, 0, sizeof (type_section
));
12100 type_section
.s
.section
= sectp
;
12101 type_section
.size
= bfd_section_size (sectp
);
12102 dwo_sections
->types
.push_back (type_section
);
12106 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12107 by PER_CU. This is for the non-DWP case.
12108 The result is NULL if DWO_NAME can't be found. */
12110 static struct dwo_file
*
12111 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12112 const char *dwo_name
, const char *comp_dir
)
12114 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12116 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12119 if (dwarf_read_debug
)
12120 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12124 dwo_file_up
dwo_file (new struct dwo_file
);
12125 dwo_file
->dwo_name
= dwo_name
;
12126 dwo_file
->comp_dir
= comp_dir
;
12127 dwo_file
->dbfd
= std::move (dbfd
);
12129 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12130 &dwo_file
->sections
);
12132 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12133 dwo_file
->sections
.info
, dwo_file
->cus
);
12135 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12136 dwo_file
->sections
.types
, dwo_file
->tus
);
12138 if (dwarf_read_debug
)
12139 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12141 return dwo_file
.release ();
12144 /* This function is mapped across the sections and remembers the offset and
12145 size of each of the DWP debugging sections common to version 1 and 2 that
12146 we are interested in. */
12149 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12150 void *dwp_file_ptr
)
12152 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12153 const struct dwop_section_names
*names
= &dwop_section_names
;
12154 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12156 /* Record the ELF section number for later lookup: this is what the
12157 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12158 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12159 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12161 /* Look for specific sections that we need. */
12162 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12164 dwp_file
->sections
.str
.s
.section
= sectp
;
12165 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12167 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12169 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12170 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12172 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12174 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12175 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12179 /* This function is mapped across the sections and remembers the offset and
12180 size of each of the DWP version 2 debugging sections that we are interested
12181 in. This is split into a separate function because we don't know if we
12182 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12185 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12187 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12188 const struct dwop_section_names
*names
= &dwop_section_names
;
12189 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12191 /* Record the ELF section number for later lookup: this is what the
12192 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12193 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12194 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12196 /* Look for specific sections that we need. */
12197 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12199 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12200 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12202 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12204 dwp_file
->sections
.info
.s
.section
= sectp
;
12205 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12207 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12209 dwp_file
->sections
.line
.s
.section
= sectp
;
12210 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12212 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12214 dwp_file
->sections
.loc
.s
.section
= sectp
;
12215 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12217 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12219 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12220 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12222 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12224 dwp_file
->sections
.macro
.s
.section
= sectp
;
12225 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12227 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12229 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12230 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12232 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12234 dwp_file
->sections
.types
.s
.section
= sectp
;
12235 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12239 /* Hash function for dwp_file loaded CUs/TUs. */
12242 hash_dwp_loaded_cutus (const void *item
)
12244 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12246 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12247 return dwo_unit
->signature
;
12250 /* Equality function for dwp_file loaded CUs/TUs. */
12253 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12255 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12256 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12258 return dua
->signature
== dub
->signature
;
12261 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12264 allocate_dwp_loaded_cutus_table ()
12266 return htab_up (htab_create_alloc (3,
12267 hash_dwp_loaded_cutus
,
12268 eq_dwp_loaded_cutus
,
12269 NULL
, xcalloc
, xfree
));
12272 /* Try to open DWP file FILE_NAME.
12273 The result is the bfd handle of the file.
12274 If there is a problem finding or opening the file, return NULL.
12275 Upon success, the canonicalized path of the file is stored in the bfd,
12276 same as symfile_bfd_open. */
12278 static gdb_bfd_ref_ptr
12279 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12280 const char *file_name
)
12282 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12284 1 /*search_cwd*/));
12288 /* Work around upstream bug 15652.
12289 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12290 [Whether that's a "bug" is debatable, but it is getting in our way.]
12291 We have no real idea where the dwp file is, because gdb's realpath-ing
12292 of the executable's path may have discarded the needed info.
12293 [IWBN if the dwp file name was recorded in the executable, akin to
12294 .gnu_debuglink, but that doesn't exist yet.]
12295 Strip the directory from FILE_NAME and search again. */
12296 if (*debug_file_directory
!= '\0')
12298 /* Don't implicitly search the current directory here.
12299 If the user wants to search "." to handle this case,
12300 it must be added to debug-file-directory. */
12301 return try_open_dwop_file (dwarf2_per_objfile
,
12302 lbasename (file_name
), 1 /*is_dwp*/,
12309 /* Initialize the use of the DWP file for the current objfile.
12310 By convention the name of the DWP file is ${objfile}.dwp.
12311 The result is NULL if it can't be found. */
12313 static std::unique_ptr
<struct dwp_file
>
12314 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12316 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12318 /* Try to find first .dwp for the binary file before any symbolic links
12321 /* If the objfile is a debug file, find the name of the real binary
12322 file and get the name of dwp file from there. */
12323 std::string dwp_name
;
12324 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12326 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12327 const char *backlink_basename
= lbasename (backlink
->original_name
);
12329 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12332 dwp_name
= objfile
->original_name
;
12334 dwp_name
+= ".dwp";
12336 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12338 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12340 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12341 dwp_name
= objfile_name (objfile
);
12342 dwp_name
+= ".dwp";
12343 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12348 if (dwarf_read_debug
)
12349 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12350 return std::unique_ptr
<dwp_file
> ();
12353 const char *name
= bfd_get_filename (dbfd
.get ());
12354 std::unique_ptr
<struct dwp_file
> dwp_file
12355 (new struct dwp_file (name
, std::move (dbfd
)));
12357 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12358 dwp_file
->elf_sections
=
12359 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12360 dwp_file
->num_sections
, asection
*);
12362 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12363 dwarf2_locate_common_dwp_sections
,
12366 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12369 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12372 /* The DWP file version is stored in the hash table. Oh well. */
12373 if (dwp_file
->cus
&& dwp_file
->tus
12374 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12376 /* Technically speaking, we should try to limp along, but this is
12377 pretty bizarre. We use pulongest here because that's the established
12378 portability solution (e.g, we cannot use %u for uint32_t). */
12379 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12380 " TU version %s [in DWP file %s]"),
12381 pulongest (dwp_file
->cus
->version
),
12382 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12386 dwp_file
->version
= dwp_file
->cus
->version
;
12387 else if (dwp_file
->tus
)
12388 dwp_file
->version
= dwp_file
->tus
->version
;
12390 dwp_file
->version
= 2;
12392 if (dwp_file
->version
== 2)
12393 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12394 dwarf2_locate_v2_dwp_sections
,
12397 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12398 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12400 if (dwarf_read_debug
)
12402 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12403 fprintf_unfiltered (gdb_stdlog
,
12404 " %s CUs, %s TUs\n",
12405 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12406 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12412 /* Wrapper around open_and_init_dwp_file, only open it once. */
12414 static struct dwp_file
*
12415 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12417 if (! dwarf2_per_objfile
->dwp_checked
)
12419 dwarf2_per_objfile
->dwp_file
12420 = open_and_init_dwp_file (dwarf2_per_objfile
);
12421 dwarf2_per_objfile
->dwp_checked
= 1;
12423 return dwarf2_per_objfile
->dwp_file
.get ();
12426 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12427 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12428 or in the DWP file for the objfile, referenced by THIS_UNIT.
12429 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12430 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12432 This is called, for example, when wanting to read a variable with a
12433 complex location. Therefore we don't want to do file i/o for every call.
12434 Therefore we don't want to look for a DWO file on every call.
12435 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12436 then we check if we've already seen DWO_NAME, and only THEN do we check
12439 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12440 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12442 static struct dwo_unit
*
12443 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12444 const char *dwo_name
, const char *comp_dir
,
12445 ULONGEST signature
, int is_debug_types
)
12447 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12448 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12449 const char *kind
= is_debug_types
? "TU" : "CU";
12450 void **dwo_file_slot
;
12451 struct dwo_file
*dwo_file
;
12452 struct dwp_file
*dwp_file
;
12454 /* First see if there's a DWP file.
12455 If we have a DWP file but didn't find the DWO inside it, don't
12456 look for the original DWO file. It makes gdb behave differently
12457 depending on whether one is debugging in the build tree. */
12459 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12460 if (dwp_file
!= NULL
)
12462 const struct dwp_hash_table
*dwp_htab
=
12463 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12465 if (dwp_htab
!= NULL
)
12467 struct dwo_unit
*dwo_cutu
=
12468 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12469 signature
, is_debug_types
);
12471 if (dwo_cutu
!= NULL
)
12473 if (dwarf_read_debug
)
12475 fprintf_unfiltered (gdb_stdlog
,
12476 "Virtual DWO %s %s found: @%s\n",
12477 kind
, hex_string (signature
),
12478 host_address_to_string (dwo_cutu
));
12486 /* No DWP file, look for the DWO file. */
12488 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12489 dwo_name
, comp_dir
);
12490 if (*dwo_file_slot
== NULL
)
12492 /* Read in the file and build a table of the CUs/TUs it contains. */
12493 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12495 /* NOTE: This will be NULL if unable to open the file. */
12496 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12498 if (dwo_file
!= NULL
)
12500 struct dwo_unit
*dwo_cutu
= NULL
;
12502 if (is_debug_types
&& dwo_file
->tus
)
12504 struct dwo_unit find_dwo_cutu
;
12506 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12507 find_dwo_cutu
.signature
= signature
;
12509 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12512 else if (!is_debug_types
&& dwo_file
->cus
)
12514 struct dwo_unit find_dwo_cutu
;
12516 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12517 find_dwo_cutu
.signature
= signature
;
12518 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12522 if (dwo_cutu
!= NULL
)
12524 if (dwarf_read_debug
)
12526 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12527 kind
, dwo_name
, hex_string (signature
),
12528 host_address_to_string (dwo_cutu
));
12535 /* We didn't find it. This could mean a dwo_id mismatch, or
12536 someone deleted the DWO/DWP file, or the search path isn't set up
12537 correctly to find the file. */
12539 if (dwarf_read_debug
)
12541 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12542 kind
, dwo_name
, hex_string (signature
));
12545 /* This is a warning and not a complaint because it can be caused by
12546 pilot error (e.g., user accidentally deleting the DWO). */
12548 /* Print the name of the DWP file if we looked there, helps the user
12549 better diagnose the problem. */
12550 std::string dwp_text
;
12552 if (dwp_file
!= NULL
)
12553 dwp_text
= string_printf (" [in DWP file %s]",
12554 lbasename (dwp_file
->name
));
12556 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12557 " [in module %s]"),
12558 kind
, dwo_name
, hex_string (signature
),
12560 this_unit
->is_debug_types
? "TU" : "CU",
12561 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12566 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12567 See lookup_dwo_cutu_unit for details. */
12569 static struct dwo_unit
*
12570 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12571 const char *dwo_name
, const char *comp_dir
,
12572 ULONGEST signature
)
12574 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12577 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12578 See lookup_dwo_cutu_unit for details. */
12580 static struct dwo_unit
*
12581 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12582 const char *dwo_name
, const char *comp_dir
)
12584 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12587 /* Traversal function for queue_and_load_all_dwo_tus. */
12590 queue_and_load_dwo_tu (void **slot
, void *info
)
12592 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12593 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12594 ULONGEST signature
= dwo_unit
->signature
;
12595 struct signatured_type
*sig_type
=
12596 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12598 if (sig_type
!= NULL
)
12600 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12602 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12603 a real dependency of PER_CU on SIG_TYPE. That is detected later
12604 while processing PER_CU. */
12605 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12606 load_full_type_unit (sig_cu
);
12607 per_cu
->imported_symtabs_push (sig_cu
);
12613 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12614 The DWO may have the only definition of the type, though it may not be
12615 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12616 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12619 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12621 struct dwo_unit
*dwo_unit
;
12622 struct dwo_file
*dwo_file
;
12624 gdb_assert (!per_cu
->is_debug_types
);
12625 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12626 gdb_assert (per_cu
->cu
!= NULL
);
12628 dwo_unit
= per_cu
->cu
->dwo_unit
;
12629 gdb_assert (dwo_unit
!= NULL
);
12631 dwo_file
= dwo_unit
->dwo_file
;
12632 if (dwo_file
->tus
!= NULL
)
12633 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12637 /* Read in various DIEs. */
12639 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12640 Inherit only the children of the DW_AT_abstract_origin DIE not being
12641 already referenced by DW_AT_abstract_origin from the children of the
12645 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12647 struct die_info
*child_die
;
12648 sect_offset
*offsetp
;
12649 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12650 struct die_info
*origin_die
;
12651 /* Iterator of the ORIGIN_DIE children. */
12652 struct die_info
*origin_child_die
;
12653 struct attribute
*attr
;
12654 struct dwarf2_cu
*origin_cu
;
12655 struct pending
**origin_previous_list_in_scope
;
12657 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12661 /* Note that following die references may follow to a die in a
12665 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12667 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12669 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12670 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12672 if (die
->tag
!= origin_die
->tag
12673 && !(die
->tag
== DW_TAG_inlined_subroutine
12674 && origin_die
->tag
== DW_TAG_subprogram
))
12675 complaint (_("DIE %s and its abstract origin %s have different tags"),
12676 sect_offset_str (die
->sect_off
),
12677 sect_offset_str (origin_die
->sect_off
));
12679 std::vector
<sect_offset
> offsets
;
12681 for (child_die
= die
->child
;
12682 child_die
&& child_die
->tag
;
12683 child_die
= sibling_die (child_die
))
12685 struct die_info
*child_origin_die
;
12686 struct dwarf2_cu
*child_origin_cu
;
12688 /* We are trying to process concrete instance entries:
12689 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12690 it's not relevant to our analysis here. i.e. detecting DIEs that are
12691 present in the abstract instance but not referenced in the concrete
12693 if (child_die
->tag
== DW_TAG_call_site
12694 || child_die
->tag
== DW_TAG_GNU_call_site
)
12697 /* For each CHILD_DIE, find the corresponding child of
12698 ORIGIN_DIE. If there is more than one layer of
12699 DW_AT_abstract_origin, follow them all; there shouldn't be,
12700 but GCC versions at least through 4.4 generate this (GCC PR
12702 child_origin_die
= child_die
;
12703 child_origin_cu
= cu
;
12706 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12710 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12714 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12715 counterpart may exist. */
12716 if (child_origin_die
!= child_die
)
12718 if (child_die
->tag
!= child_origin_die
->tag
12719 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12720 && child_origin_die
->tag
== DW_TAG_subprogram
))
12721 complaint (_("Child DIE %s and its abstract origin %s have "
12723 sect_offset_str (child_die
->sect_off
),
12724 sect_offset_str (child_origin_die
->sect_off
));
12725 if (child_origin_die
->parent
!= origin_die
)
12726 complaint (_("Child DIE %s and its abstract origin %s have "
12727 "different parents"),
12728 sect_offset_str (child_die
->sect_off
),
12729 sect_offset_str (child_origin_die
->sect_off
));
12731 offsets
.push_back (child_origin_die
->sect_off
);
12734 std::sort (offsets
.begin (), offsets
.end ());
12735 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12736 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12737 if (offsetp
[-1] == *offsetp
)
12738 complaint (_("Multiple children of DIE %s refer "
12739 "to DIE %s as their abstract origin"),
12740 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12742 offsetp
= offsets
.data ();
12743 origin_child_die
= origin_die
->child
;
12744 while (origin_child_die
&& origin_child_die
->tag
)
12746 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12747 while (offsetp
< offsets_end
12748 && *offsetp
< origin_child_die
->sect_off
)
12750 if (offsetp
>= offsets_end
12751 || *offsetp
> origin_child_die
->sect_off
)
12753 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12754 Check whether we're already processing ORIGIN_CHILD_DIE.
12755 This can happen with mutually referenced abstract_origins.
12757 if (!origin_child_die
->in_process
)
12758 process_die (origin_child_die
, origin_cu
);
12760 origin_child_die
= sibling_die (origin_child_die
);
12762 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12764 if (cu
!= origin_cu
)
12765 compute_delayed_physnames (origin_cu
);
12769 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12771 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12772 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12773 struct context_stack
*newobj
;
12776 struct die_info
*child_die
;
12777 struct attribute
*attr
, *call_line
, *call_file
;
12779 CORE_ADDR baseaddr
;
12780 struct block
*block
;
12781 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12782 std::vector
<struct symbol
*> template_args
;
12783 struct template_symbol
*templ_func
= NULL
;
12787 /* If we do not have call site information, we can't show the
12788 caller of this inlined function. That's too confusing, so
12789 only use the scope for local variables. */
12790 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12791 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12792 if (call_line
== NULL
|| call_file
== NULL
)
12794 read_lexical_block_scope (die
, cu
);
12799 baseaddr
= objfile
->text_section_offset ();
12801 name
= dwarf2_name (die
, cu
);
12803 /* Ignore functions with missing or empty names. These are actually
12804 illegal according to the DWARF standard. */
12807 complaint (_("missing name for subprogram DIE at %s"),
12808 sect_offset_str (die
->sect_off
));
12812 /* Ignore functions with missing or invalid low and high pc attributes. */
12813 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12814 <= PC_BOUNDS_INVALID
)
12816 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12817 if (!attr
|| !DW_UNSND (attr
))
12818 complaint (_("cannot get low and high bounds "
12819 "for subprogram DIE at %s"),
12820 sect_offset_str (die
->sect_off
));
12824 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12825 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12827 /* If we have any template arguments, then we must allocate a
12828 different sort of symbol. */
12829 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12831 if (child_die
->tag
== DW_TAG_template_type_param
12832 || child_die
->tag
== DW_TAG_template_value_param
)
12834 templ_func
= allocate_template_symbol (objfile
);
12835 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12840 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12841 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12842 (struct symbol
*) templ_func
);
12844 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12845 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12848 /* If there is a location expression for DW_AT_frame_base, record
12850 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12851 if (attr
!= nullptr)
12852 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12854 /* If there is a location for the static link, record it. */
12855 newobj
->static_link
= NULL
;
12856 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12857 if (attr
!= nullptr)
12859 newobj
->static_link
12860 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12861 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12862 cu
->per_cu
->addr_type ());
12865 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12867 if (die
->child
!= NULL
)
12869 child_die
= die
->child
;
12870 while (child_die
&& child_die
->tag
)
12872 if (child_die
->tag
== DW_TAG_template_type_param
12873 || child_die
->tag
== DW_TAG_template_value_param
)
12875 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12878 template_args
.push_back (arg
);
12881 process_die (child_die
, cu
);
12882 child_die
= sibling_die (child_die
);
12886 inherit_abstract_dies (die
, cu
);
12888 /* If we have a DW_AT_specification, we might need to import using
12889 directives from the context of the specification DIE. See the
12890 comment in determine_prefix. */
12891 if (cu
->language
== language_cplus
12892 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12894 struct dwarf2_cu
*spec_cu
= cu
;
12895 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12899 child_die
= spec_die
->child
;
12900 while (child_die
&& child_die
->tag
)
12902 if (child_die
->tag
== DW_TAG_imported_module
)
12903 process_die (child_die
, spec_cu
);
12904 child_die
= sibling_die (child_die
);
12907 /* In some cases, GCC generates specification DIEs that
12908 themselves contain DW_AT_specification attributes. */
12909 spec_die
= die_specification (spec_die
, &spec_cu
);
12913 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12914 /* Make a block for the local symbols within. */
12915 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12916 cstk
.static_link
, lowpc
, highpc
);
12918 /* For C++, set the block's scope. */
12919 if ((cu
->language
== language_cplus
12920 || cu
->language
== language_fortran
12921 || cu
->language
== language_d
12922 || cu
->language
== language_rust
)
12923 && cu
->processing_has_namespace_info
)
12924 block_set_scope (block
, determine_prefix (die
, cu
),
12925 &objfile
->objfile_obstack
);
12927 /* If we have address ranges, record them. */
12928 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12930 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12932 /* Attach template arguments to function. */
12933 if (!template_args
.empty ())
12935 gdb_assert (templ_func
!= NULL
);
12937 templ_func
->n_template_arguments
= template_args
.size ();
12938 templ_func
->template_arguments
12939 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12940 templ_func
->n_template_arguments
);
12941 memcpy (templ_func
->template_arguments
,
12942 template_args
.data (),
12943 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12945 /* Make sure that the symtab is set on the new symbols. Even
12946 though they don't appear in this symtab directly, other parts
12947 of gdb assume that symbols do, and this is reasonably
12949 for (symbol
*sym
: template_args
)
12950 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12953 /* In C++, we can have functions nested inside functions (e.g., when
12954 a function declares a class that has methods). This means that
12955 when we finish processing a function scope, we may need to go
12956 back to building a containing block's symbol lists. */
12957 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12958 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12960 /* If we've finished processing a top-level function, subsequent
12961 symbols go in the file symbol list. */
12962 if (cu
->get_builder ()->outermost_context_p ())
12963 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12966 /* Process all the DIES contained within a lexical block scope. Start
12967 a new scope, process the dies, and then close the scope. */
12970 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12972 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12973 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12974 CORE_ADDR lowpc
, highpc
;
12975 struct die_info
*child_die
;
12976 CORE_ADDR baseaddr
;
12978 baseaddr
= objfile
->text_section_offset ();
12980 /* Ignore blocks with missing or invalid low and high pc attributes. */
12981 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12982 as multiple lexical blocks? Handling children in a sane way would
12983 be nasty. Might be easier to properly extend generic blocks to
12984 describe ranges. */
12985 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
12987 case PC_BOUNDS_NOT_PRESENT
:
12988 /* DW_TAG_lexical_block has no attributes, process its children as if
12989 there was no wrapping by that DW_TAG_lexical_block.
12990 GCC does no longer produces such DWARF since GCC r224161. */
12991 for (child_die
= die
->child
;
12992 child_die
!= NULL
&& child_die
->tag
;
12993 child_die
= sibling_die (child_die
))
12994 process_die (child_die
, cu
);
12996 case PC_BOUNDS_INVALID
:
12999 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13000 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13002 cu
->get_builder ()->push_context (0, lowpc
);
13003 if (die
->child
!= NULL
)
13005 child_die
= die
->child
;
13006 while (child_die
&& child_die
->tag
)
13008 process_die (child_die
, cu
);
13009 child_die
= sibling_die (child_die
);
13012 inherit_abstract_dies (die
, cu
);
13013 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13015 if (*cu
->get_builder ()->get_local_symbols () != NULL
13016 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13018 struct block
*block
13019 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13020 cstk
.start_addr
, highpc
);
13022 /* Note that recording ranges after traversing children, as we
13023 do here, means that recording a parent's ranges entails
13024 walking across all its children's ranges as they appear in
13025 the address map, which is quadratic behavior.
13027 It would be nicer to record the parent's ranges before
13028 traversing its children, simply overriding whatever you find
13029 there. But since we don't even decide whether to create a
13030 block until after we've traversed its children, that's hard
13032 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13034 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13035 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13038 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13041 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13043 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13044 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13045 CORE_ADDR pc
, baseaddr
;
13046 struct attribute
*attr
;
13047 struct call_site
*call_site
, call_site_local
;
13050 struct die_info
*child_die
;
13052 baseaddr
= objfile
->text_section_offset ();
13054 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13057 /* This was a pre-DWARF-5 GNU extension alias
13058 for DW_AT_call_return_pc. */
13059 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13063 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13064 "DIE %s [in module %s]"),
13065 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13068 pc
= attr
->value_as_address () + baseaddr
;
13069 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13071 if (cu
->call_site_htab
== NULL
)
13072 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13073 NULL
, &objfile
->objfile_obstack
,
13074 hashtab_obstack_allocate
, NULL
);
13075 call_site_local
.pc
= pc
;
13076 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13079 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13080 "DIE %s [in module %s]"),
13081 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13082 objfile_name (objfile
));
13086 /* Count parameters at the caller. */
13089 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13090 child_die
= sibling_die (child_die
))
13092 if (child_die
->tag
!= DW_TAG_call_site_parameter
13093 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13095 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13096 "DW_TAG_call_site child DIE %s [in module %s]"),
13097 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13098 objfile_name (objfile
));
13106 = ((struct call_site
*)
13107 obstack_alloc (&objfile
->objfile_obstack
,
13108 sizeof (*call_site
)
13109 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13111 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13112 call_site
->pc
= pc
;
13114 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13115 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13117 struct die_info
*func_die
;
13119 /* Skip also over DW_TAG_inlined_subroutine. */
13120 for (func_die
= die
->parent
;
13121 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13122 && func_die
->tag
!= DW_TAG_subroutine_type
;
13123 func_die
= func_die
->parent
);
13125 /* DW_AT_call_all_calls is a superset
13126 of DW_AT_call_all_tail_calls. */
13128 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13129 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13130 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13131 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13133 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13134 not complete. But keep CALL_SITE for look ups via call_site_htab,
13135 both the initial caller containing the real return address PC and
13136 the final callee containing the current PC of a chain of tail
13137 calls do not need to have the tail call list complete. But any
13138 function candidate for a virtual tail call frame searched via
13139 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13140 determined unambiguously. */
13144 struct type
*func_type
= NULL
;
13147 func_type
= get_die_type (func_die
, cu
);
13148 if (func_type
!= NULL
)
13150 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13152 /* Enlist this call site to the function. */
13153 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13154 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13157 complaint (_("Cannot find function owning DW_TAG_call_site "
13158 "DIE %s [in module %s]"),
13159 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13163 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13165 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13167 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13170 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13171 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13173 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13174 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13175 /* Keep NULL DWARF_BLOCK. */;
13176 else if (attr
->form_is_block ())
13178 struct dwarf2_locexpr_baton
*dlbaton
;
13180 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13181 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13182 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13183 dlbaton
->per_cu
= cu
->per_cu
;
13185 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13187 else if (attr
->form_is_ref ())
13189 struct dwarf2_cu
*target_cu
= cu
;
13190 struct die_info
*target_die
;
13192 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13193 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13194 if (die_is_declaration (target_die
, target_cu
))
13196 const char *target_physname
;
13198 /* Prefer the mangled name; otherwise compute the demangled one. */
13199 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13200 if (target_physname
== NULL
)
13201 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13202 if (target_physname
== NULL
)
13203 complaint (_("DW_AT_call_target target DIE has invalid "
13204 "physname, for referencing DIE %s [in module %s]"),
13205 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13207 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13213 /* DW_AT_entry_pc should be preferred. */
13214 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13215 <= PC_BOUNDS_INVALID
)
13216 complaint (_("DW_AT_call_target target DIE has invalid "
13217 "low pc, for referencing DIE %s [in module %s]"),
13218 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13221 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13222 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13227 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13228 "block nor reference, for DIE %s [in module %s]"),
13229 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13231 call_site
->per_cu
= cu
->per_cu
;
13233 for (child_die
= die
->child
;
13234 child_die
&& child_die
->tag
;
13235 child_die
= sibling_die (child_die
))
13237 struct call_site_parameter
*parameter
;
13238 struct attribute
*loc
, *origin
;
13240 if (child_die
->tag
!= DW_TAG_call_site_parameter
13241 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13243 /* Already printed the complaint above. */
13247 gdb_assert (call_site
->parameter_count
< nparams
);
13248 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13250 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13251 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13252 register is contained in DW_AT_call_value. */
13254 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13255 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13256 if (origin
== NULL
)
13258 /* This was a pre-DWARF-5 GNU extension alias
13259 for DW_AT_call_parameter. */
13260 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13262 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13264 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13266 sect_offset sect_off
13267 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13268 if (!cu
->header
.offset_in_cu_p (sect_off
))
13270 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13271 binding can be done only inside one CU. Such referenced DIE
13272 therefore cannot be even moved to DW_TAG_partial_unit. */
13273 complaint (_("DW_AT_call_parameter offset is not in CU for "
13274 "DW_TAG_call_site child DIE %s [in module %s]"),
13275 sect_offset_str (child_die
->sect_off
),
13276 objfile_name (objfile
));
13279 parameter
->u
.param_cu_off
13280 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13282 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13284 complaint (_("No DW_FORM_block* DW_AT_location for "
13285 "DW_TAG_call_site child DIE %s [in module %s]"),
13286 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13291 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13292 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13293 if (parameter
->u
.dwarf_reg
!= -1)
13294 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13295 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13296 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13297 ¶meter
->u
.fb_offset
))
13298 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13301 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13302 "for DW_FORM_block* DW_AT_location is supported for "
13303 "DW_TAG_call_site child DIE %s "
13305 sect_offset_str (child_die
->sect_off
),
13306 objfile_name (objfile
));
13311 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13313 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13314 if (attr
== NULL
|| !attr
->form_is_block ())
13316 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13317 "DW_TAG_call_site child DIE %s [in module %s]"),
13318 sect_offset_str (child_die
->sect_off
),
13319 objfile_name (objfile
));
13322 parameter
->value
= DW_BLOCK (attr
)->data
;
13323 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13325 /* Parameters are not pre-cleared by memset above. */
13326 parameter
->data_value
= NULL
;
13327 parameter
->data_value_size
= 0;
13328 call_site
->parameter_count
++;
13330 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13332 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13333 if (attr
!= nullptr)
13335 if (!attr
->form_is_block ())
13336 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13337 "DW_TAG_call_site child DIE %s [in module %s]"),
13338 sect_offset_str (child_die
->sect_off
),
13339 objfile_name (objfile
));
13342 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13343 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13349 /* Helper function for read_variable. If DIE represents a virtual
13350 table, then return the type of the concrete object that is
13351 associated with the virtual table. Otherwise, return NULL. */
13353 static struct type
*
13354 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13356 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13360 /* Find the type DIE. */
13361 struct die_info
*type_die
= NULL
;
13362 struct dwarf2_cu
*type_cu
= cu
;
13364 if (attr
->form_is_ref ())
13365 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13366 if (type_die
== NULL
)
13369 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13371 return die_containing_type (type_die
, type_cu
);
13374 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13377 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13379 struct rust_vtable_symbol
*storage
= NULL
;
13381 if (cu
->language
== language_rust
)
13383 struct type
*containing_type
= rust_containing_type (die
, cu
);
13385 if (containing_type
!= NULL
)
13387 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13389 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13390 initialize_objfile_symbol (storage
);
13391 storage
->concrete_type
= containing_type
;
13392 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13396 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13397 struct attribute
*abstract_origin
13398 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13399 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13400 if (res
== NULL
&& loc
&& abstract_origin
)
13402 /* We have a variable without a name, but with a location and an abstract
13403 origin. This may be a concrete instance of an abstract variable
13404 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13406 struct dwarf2_cu
*origin_cu
= cu
;
13407 struct die_info
*origin_die
13408 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13409 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13410 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13414 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13415 reading .debug_rnglists.
13416 Callback's type should be:
13417 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13418 Return true if the attributes are present and valid, otherwise,
13421 template <typename Callback
>
13423 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13424 Callback
&&callback
)
13426 struct dwarf2_per_objfile
*dwarf2_per_objfile
13427 = cu
->per_cu
->dwarf2_per_objfile
;
13428 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13429 bfd
*obfd
= objfile
->obfd
;
13430 /* Base address selection entry. */
13431 gdb::optional
<CORE_ADDR
> base
;
13432 const gdb_byte
*buffer
;
13433 CORE_ADDR baseaddr
;
13434 bool overflow
= false;
13436 base
= cu
->base_address
;
13438 dwarf2_per_objfile
->rnglists
.read (objfile
);
13439 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13441 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13445 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13447 baseaddr
= objfile
->text_section_offset ();
13451 /* Initialize it due to a false compiler warning. */
13452 CORE_ADDR range_beginning
= 0, range_end
= 0;
13453 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13454 + dwarf2_per_objfile
->rnglists
.size
);
13455 unsigned int bytes_read
;
13457 if (buffer
== buf_end
)
13462 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13465 case DW_RLE_end_of_list
:
13467 case DW_RLE_base_address
:
13468 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13473 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13474 buffer
+= bytes_read
;
13476 case DW_RLE_start_length
:
13477 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13482 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13484 buffer
+= bytes_read
;
13485 range_end
= (range_beginning
13486 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13487 buffer
+= bytes_read
;
13488 if (buffer
> buf_end
)
13494 case DW_RLE_offset_pair
:
13495 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13496 buffer
+= bytes_read
;
13497 if (buffer
> buf_end
)
13502 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13503 buffer
+= bytes_read
;
13504 if (buffer
> buf_end
)
13510 case DW_RLE_start_end
:
13511 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13516 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13518 buffer
+= bytes_read
;
13519 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13520 buffer
+= bytes_read
;
13523 complaint (_("Invalid .debug_rnglists data (no base address)"));
13526 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13528 if (rlet
== DW_RLE_base_address
)
13531 if (!base
.has_value ())
13533 /* We have no valid base address for the ranges
13535 complaint (_("Invalid .debug_rnglists data (no base address)"));
13539 if (range_beginning
> range_end
)
13541 /* Inverted range entries are invalid. */
13542 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13546 /* Empty range entries have no effect. */
13547 if (range_beginning
== range_end
)
13550 range_beginning
+= *base
;
13551 range_end
+= *base
;
13553 /* A not-uncommon case of bad debug info.
13554 Don't pollute the addrmap with bad data. */
13555 if (range_beginning
+ baseaddr
== 0
13556 && !dwarf2_per_objfile
->has_section_at_zero
)
13558 complaint (_(".debug_rnglists entry has start address of zero"
13559 " [in module %s]"), objfile_name (objfile
));
13563 callback (range_beginning
, range_end
);
13568 complaint (_("Offset %d is not terminated "
13569 "for DW_AT_ranges attribute"),
13577 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13578 Callback's type should be:
13579 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13580 Return 1 if the attributes are present and valid, otherwise, return 0. */
13582 template <typename Callback
>
13584 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13585 Callback
&&callback
)
13587 struct dwarf2_per_objfile
*dwarf2_per_objfile
13588 = cu
->per_cu
->dwarf2_per_objfile
;
13589 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13590 struct comp_unit_head
*cu_header
= &cu
->header
;
13591 bfd
*obfd
= objfile
->obfd
;
13592 unsigned int addr_size
= cu_header
->addr_size
;
13593 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13594 /* Base address selection entry. */
13595 gdb::optional
<CORE_ADDR
> base
;
13596 unsigned int dummy
;
13597 const gdb_byte
*buffer
;
13598 CORE_ADDR baseaddr
;
13600 if (cu_header
->version
>= 5)
13601 return dwarf2_rnglists_process (offset
, cu
, callback
);
13603 base
= cu
->base_address
;
13605 dwarf2_per_objfile
->ranges
.read (objfile
);
13606 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13608 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13612 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13614 baseaddr
= objfile
->text_section_offset ();
13618 CORE_ADDR range_beginning
, range_end
;
13620 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13621 buffer
+= addr_size
;
13622 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13623 buffer
+= addr_size
;
13624 offset
+= 2 * addr_size
;
13626 /* An end of list marker is a pair of zero addresses. */
13627 if (range_beginning
== 0 && range_end
== 0)
13628 /* Found the end of list entry. */
13631 /* Each base address selection entry is a pair of 2 values.
13632 The first is the largest possible address, the second is
13633 the base address. Check for a base address here. */
13634 if ((range_beginning
& mask
) == mask
)
13636 /* If we found the largest possible address, then we already
13637 have the base address in range_end. */
13642 if (!base
.has_value ())
13644 /* We have no valid base address for the ranges
13646 complaint (_("Invalid .debug_ranges data (no base address)"));
13650 if (range_beginning
> range_end
)
13652 /* Inverted range entries are invalid. */
13653 complaint (_("Invalid .debug_ranges data (inverted range)"));
13657 /* Empty range entries have no effect. */
13658 if (range_beginning
== range_end
)
13661 range_beginning
+= *base
;
13662 range_end
+= *base
;
13664 /* A not-uncommon case of bad debug info.
13665 Don't pollute the addrmap with bad data. */
13666 if (range_beginning
+ baseaddr
== 0
13667 && !dwarf2_per_objfile
->has_section_at_zero
)
13669 complaint (_(".debug_ranges entry has start address of zero"
13670 " [in module %s]"), objfile_name (objfile
));
13674 callback (range_beginning
, range_end
);
13680 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13681 Return 1 if the attributes are present and valid, otherwise, return 0.
13682 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13685 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13686 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13687 dwarf2_psymtab
*ranges_pst
)
13689 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13690 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13691 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13694 CORE_ADDR high
= 0;
13697 retval
= dwarf2_ranges_process (offset
, cu
,
13698 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13700 if (ranges_pst
!= NULL
)
13705 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13706 range_beginning
+ baseaddr
)
13708 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13709 range_end
+ baseaddr
)
13711 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13712 lowpc
, highpc
- 1, ranges_pst
);
13715 /* FIXME: This is recording everything as a low-high
13716 segment of consecutive addresses. We should have a
13717 data structure for discontiguous block ranges
13721 low
= range_beginning
;
13727 if (range_beginning
< low
)
13728 low
= range_beginning
;
13729 if (range_end
> high
)
13737 /* If the first entry is an end-of-list marker, the range
13738 describes an empty scope, i.e. no instructions. */
13744 *high_return
= high
;
13748 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13749 definition for the return value. *LOWPC and *HIGHPC are set iff
13750 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13752 static enum pc_bounds_kind
13753 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13754 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13755 dwarf2_psymtab
*pst
)
13757 struct dwarf2_per_objfile
*dwarf2_per_objfile
13758 = cu
->per_cu
->dwarf2_per_objfile
;
13759 struct attribute
*attr
;
13760 struct attribute
*attr_high
;
13762 CORE_ADDR high
= 0;
13763 enum pc_bounds_kind ret
;
13765 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13768 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13769 if (attr
!= nullptr)
13771 low
= attr
->value_as_address ();
13772 high
= attr_high
->value_as_address ();
13773 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13777 /* Found high w/o low attribute. */
13778 return PC_BOUNDS_INVALID
;
13780 /* Found consecutive range of addresses. */
13781 ret
= PC_BOUNDS_HIGH_LOW
;
13785 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13788 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13789 We take advantage of the fact that DW_AT_ranges does not appear
13790 in DW_TAG_compile_unit of DWO files. */
13791 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13792 unsigned int ranges_offset
= (DW_UNSND (attr
)
13793 + (need_ranges_base
13797 /* Value of the DW_AT_ranges attribute is the offset in the
13798 .debug_ranges section. */
13799 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13800 return PC_BOUNDS_INVALID
;
13801 /* Found discontinuous range of addresses. */
13802 ret
= PC_BOUNDS_RANGES
;
13805 return PC_BOUNDS_NOT_PRESENT
;
13808 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13810 return PC_BOUNDS_INVALID
;
13812 /* When using the GNU linker, .gnu.linkonce. sections are used to
13813 eliminate duplicate copies of functions and vtables and such.
13814 The linker will arbitrarily choose one and discard the others.
13815 The AT_*_pc values for such functions refer to local labels in
13816 these sections. If the section from that file was discarded, the
13817 labels are not in the output, so the relocs get a value of 0.
13818 If this is a discarded function, mark the pc bounds as invalid,
13819 so that GDB will ignore it. */
13820 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13821 return PC_BOUNDS_INVALID
;
13829 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13830 its low and high PC addresses. Do nothing if these addresses could not
13831 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13832 and HIGHPC to the high address if greater than HIGHPC. */
13835 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13836 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13837 struct dwarf2_cu
*cu
)
13839 CORE_ADDR low
, high
;
13840 struct die_info
*child
= die
->child
;
13842 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13844 *lowpc
= std::min (*lowpc
, low
);
13845 *highpc
= std::max (*highpc
, high
);
13848 /* If the language does not allow nested subprograms (either inside
13849 subprograms or lexical blocks), we're done. */
13850 if (cu
->language
!= language_ada
)
13853 /* Check all the children of the given DIE. If it contains nested
13854 subprograms, then check their pc bounds. Likewise, we need to
13855 check lexical blocks as well, as they may also contain subprogram
13857 while (child
&& child
->tag
)
13859 if (child
->tag
== DW_TAG_subprogram
13860 || child
->tag
== DW_TAG_lexical_block
)
13861 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13862 child
= sibling_die (child
);
13866 /* Get the low and high pc's represented by the scope DIE, and store
13867 them in *LOWPC and *HIGHPC. If the correct values can't be
13868 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13871 get_scope_pc_bounds (struct die_info
*die
,
13872 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13873 struct dwarf2_cu
*cu
)
13875 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13876 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13877 CORE_ADDR current_low
, current_high
;
13879 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13880 >= PC_BOUNDS_RANGES
)
13882 best_low
= current_low
;
13883 best_high
= current_high
;
13887 struct die_info
*child
= die
->child
;
13889 while (child
&& child
->tag
)
13891 switch (child
->tag
) {
13892 case DW_TAG_subprogram
:
13893 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13895 case DW_TAG_namespace
:
13896 case DW_TAG_module
:
13897 /* FIXME: carlton/2004-01-16: Should we do this for
13898 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13899 that current GCC's always emit the DIEs corresponding
13900 to definitions of methods of classes as children of a
13901 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13902 the DIEs giving the declarations, which could be
13903 anywhere). But I don't see any reason why the
13904 standards says that they have to be there. */
13905 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13907 if (current_low
!= ((CORE_ADDR
) -1))
13909 best_low
= std::min (best_low
, current_low
);
13910 best_high
= std::max (best_high
, current_high
);
13918 child
= sibling_die (child
);
13923 *highpc
= best_high
;
13926 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13930 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13931 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13933 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13934 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13935 struct attribute
*attr
;
13936 struct attribute
*attr_high
;
13938 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13941 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13942 if (attr
!= nullptr)
13944 CORE_ADDR low
= attr
->value_as_address ();
13945 CORE_ADDR high
= attr_high
->value_as_address ();
13947 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13950 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13951 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13952 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13956 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13957 if (attr
!= nullptr)
13959 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13960 We take advantage of the fact that DW_AT_ranges does not appear
13961 in DW_TAG_compile_unit of DWO files. */
13962 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13964 /* The value of the DW_AT_ranges attribute is the offset of the
13965 address range list in the .debug_ranges section. */
13966 unsigned long offset
= (DW_UNSND (attr
)
13967 + (need_ranges_base
? cu
->ranges_base
: 0));
13969 std::vector
<blockrange
> blockvec
;
13970 dwarf2_ranges_process (offset
, cu
,
13971 [&] (CORE_ADDR start
, CORE_ADDR end
)
13975 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
13976 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
13977 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
13978 blockvec
.emplace_back (start
, end
);
13981 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
13985 /* Check whether the producer field indicates either of GCC < 4.6, or the
13986 Intel C/C++ compiler, and cache the result in CU. */
13989 check_producer (struct dwarf2_cu
*cu
)
13993 if (cu
->producer
== NULL
)
13995 /* For unknown compilers expect their behavior is DWARF version
13998 GCC started to support .debug_types sections by -gdwarf-4 since
13999 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14000 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14001 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14002 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14004 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14006 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14007 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14009 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14011 cu
->producer_is_icc
= true;
14012 cu
->producer_is_icc_lt_14
= major
< 14;
14014 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14015 cu
->producer_is_codewarrior
= true;
14018 /* For other non-GCC compilers, expect their behavior is DWARF version
14022 cu
->checked_producer
= true;
14025 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14026 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14027 during 4.6.0 experimental. */
14030 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14032 if (!cu
->checked_producer
)
14033 check_producer (cu
);
14035 return cu
->producer_is_gxx_lt_4_6
;
14039 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14040 with incorrect is_stmt attributes. */
14043 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14045 if (!cu
->checked_producer
)
14046 check_producer (cu
);
14048 return cu
->producer_is_codewarrior
;
14051 /* Return the default accessibility type if it is not overridden by
14052 DW_AT_accessibility. */
14054 static enum dwarf_access_attribute
14055 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14057 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14059 /* The default DWARF 2 accessibility for members is public, the default
14060 accessibility for inheritance is private. */
14062 if (die
->tag
!= DW_TAG_inheritance
)
14063 return DW_ACCESS_public
;
14065 return DW_ACCESS_private
;
14069 /* DWARF 3+ defines the default accessibility a different way. The same
14070 rules apply now for DW_TAG_inheritance as for the members and it only
14071 depends on the container kind. */
14073 if (die
->parent
->tag
== DW_TAG_class_type
)
14074 return DW_ACCESS_private
;
14076 return DW_ACCESS_public
;
14080 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14081 offset. If the attribute was not found return 0, otherwise return
14082 1. If it was found but could not properly be handled, set *OFFSET
14086 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14089 struct attribute
*attr
;
14091 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14096 /* Note that we do not check for a section offset first here.
14097 This is because DW_AT_data_member_location is new in DWARF 4,
14098 so if we see it, we can assume that a constant form is really
14099 a constant and not a section offset. */
14100 if (attr
->form_is_constant ())
14101 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14102 else if (attr
->form_is_section_offset ())
14103 dwarf2_complex_location_expr_complaint ();
14104 else if (attr
->form_is_block ())
14105 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14107 dwarf2_complex_location_expr_complaint ();
14115 /* Add an aggregate field to the field list. */
14118 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14119 struct dwarf2_cu
*cu
)
14121 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14122 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14123 struct nextfield
*new_field
;
14124 struct attribute
*attr
;
14126 const char *fieldname
= "";
14128 if (die
->tag
== DW_TAG_inheritance
)
14130 fip
->baseclasses
.emplace_back ();
14131 new_field
= &fip
->baseclasses
.back ();
14135 fip
->fields
.emplace_back ();
14136 new_field
= &fip
->fields
.back ();
14139 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14140 if (attr
!= nullptr)
14141 new_field
->accessibility
= DW_UNSND (attr
);
14143 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14144 if (new_field
->accessibility
!= DW_ACCESS_public
)
14145 fip
->non_public_fields
= 1;
14147 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14148 if (attr
!= nullptr)
14149 new_field
->virtuality
= DW_UNSND (attr
);
14151 new_field
->virtuality
= DW_VIRTUALITY_none
;
14153 fp
= &new_field
->field
;
14155 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14159 /* Data member other than a C++ static data member. */
14161 /* Get type of field. */
14162 fp
->type
= die_type (die
, cu
);
14164 SET_FIELD_BITPOS (*fp
, 0);
14166 /* Get bit size of field (zero if none). */
14167 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14168 if (attr
!= nullptr)
14170 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14174 FIELD_BITSIZE (*fp
) = 0;
14177 /* Get bit offset of field. */
14178 if (handle_data_member_location (die
, cu
, &offset
))
14179 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14180 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14181 if (attr
!= nullptr)
14183 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14185 /* For big endian bits, the DW_AT_bit_offset gives the
14186 additional bit offset from the MSB of the containing
14187 anonymous object to the MSB of the field. We don't
14188 have to do anything special since we don't need to
14189 know the size of the anonymous object. */
14190 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14194 /* For little endian bits, compute the bit offset to the
14195 MSB of the anonymous object, subtract off the number of
14196 bits from the MSB of the field to the MSB of the
14197 object, and then subtract off the number of bits of
14198 the field itself. The result is the bit offset of
14199 the LSB of the field. */
14200 int anonymous_size
;
14201 int bit_offset
= DW_UNSND (attr
);
14203 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14204 if (attr
!= nullptr)
14206 /* The size of the anonymous object containing
14207 the bit field is explicit, so use the
14208 indicated size (in bytes). */
14209 anonymous_size
= DW_UNSND (attr
);
14213 /* The size of the anonymous object containing
14214 the bit field must be inferred from the type
14215 attribute of the data member containing the
14217 anonymous_size
= TYPE_LENGTH (fp
->type
);
14219 SET_FIELD_BITPOS (*fp
,
14220 (FIELD_BITPOS (*fp
)
14221 + anonymous_size
* bits_per_byte
14222 - bit_offset
- FIELD_BITSIZE (*fp
)));
14225 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14227 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14228 + dwarf2_get_attr_constant_value (attr
, 0)));
14230 /* Get name of field. */
14231 fieldname
= dwarf2_name (die
, cu
);
14232 if (fieldname
== NULL
)
14235 /* The name is already allocated along with this objfile, so we don't
14236 need to duplicate it for the type. */
14237 fp
->name
= fieldname
;
14239 /* Change accessibility for artificial fields (e.g. virtual table
14240 pointer or virtual base class pointer) to private. */
14241 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14243 FIELD_ARTIFICIAL (*fp
) = 1;
14244 new_field
->accessibility
= DW_ACCESS_private
;
14245 fip
->non_public_fields
= 1;
14248 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14250 /* C++ static member. */
14252 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14253 is a declaration, but all versions of G++ as of this writing
14254 (so through at least 3.2.1) incorrectly generate
14255 DW_TAG_variable tags. */
14257 const char *physname
;
14259 /* Get name of field. */
14260 fieldname
= dwarf2_name (die
, cu
);
14261 if (fieldname
== NULL
)
14264 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14266 /* Only create a symbol if this is an external value.
14267 new_symbol checks this and puts the value in the global symbol
14268 table, which we want. If it is not external, new_symbol
14269 will try to put the value in cu->list_in_scope which is wrong. */
14270 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14272 /* A static const member, not much different than an enum as far as
14273 we're concerned, except that we can support more types. */
14274 new_symbol (die
, NULL
, cu
);
14277 /* Get physical name. */
14278 physname
= dwarf2_physname (fieldname
, die
, cu
);
14280 /* The name is already allocated along with this objfile, so we don't
14281 need to duplicate it for the type. */
14282 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14283 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14284 FIELD_NAME (*fp
) = fieldname
;
14286 else if (die
->tag
== DW_TAG_inheritance
)
14290 /* C++ base class field. */
14291 if (handle_data_member_location (die
, cu
, &offset
))
14292 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14293 FIELD_BITSIZE (*fp
) = 0;
14294 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14295 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14297 else if (die
->tag
== DW_TAG_variant_part
)
14299 /* process_structure_scope will treat this DIE as a union. */
14300 process_structure_scope (die
, cu
);
14302 /* The variant part is relative to the start of the enclosing
14304 SET_FIELD_BITPOS (*fp
, 0);
14305 fp
->type
= get_die_type (die
, cu
);
14306 fp
->artificial
= 1;
14307 fp
->name
= "<<variant>>";
14309 /* Normally a DW_TAG_variant_part won't have a size, but our
14310 representation requires one, so set it to the maximum of the
14311 child sizes, being sure to account for the offset at which
14312 each child is seen. */
14313 if (TYPE_LENGTH (fp
->type
) == 0)
14316 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14318 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14319 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14323 TYPE_LENGTH (fp
->type
) = max
;
14327 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14330 /* Can the type given by DIE define another type? */
14333 type_can_define_types (const struct die_info
*die
)
14337 case DW_TAG_typedef
:
14338 case DW_TAG_class_type
:
14339 case DW_TAG_structure_type
:
14340 case DW_TAG_union_type
:
14341 case DW_TAG_enumeration_type
:
14349 /* Add a type definition defined in the scope of the FIP's class. */
14352 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14353 struct dwarf2_cu
*cu
)
14355 struct decl_field fp
;
14356 memset (&fp
, 0, sizeof (fp
));
14358 gdb_assert (type_can_define_types (die
));
14360 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14361 fp
.name
= dwarf2_name (die
, cu
);
14362 fp
.type
= read_type_die (die
, cu
);
14364 /* Save accessibility. */
14365 enum dwarf_access_attribute accessibility
;
14366 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14368 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14370 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14371 switch (accessibility
)
14373 case DW_ACCESS_public
:
14374 /* The assumed value if neither private nor protected. */
14376 case DW_ACCESS_private
:
14379 case DW_ACCESS_protected
:
14380 fp
.is_protected
= 1;
14383 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14386 if (die
->tag
== DW_TAG_typedef
)
14387 fip
->typedef_field_list
.push_back (fp
);
14389 fip
->nested_types_list
.push_back (fp
);
14392 /* Create the vector of fields, and attach it to the type. */
14395 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14396 struct dwarf2_cu
*cu
)
14398 int nfields
= fip
->nfields ();
14400 /* Record the field count, allocate space for the array of fields,
14401 and create blank accessibility bitfields if necessary. */
14402 TYPE_NFIELDS (type
) = nfields
;
14403 TYPE_FIELDS (type
) = (struct field
*)
14404 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14406 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14408 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14410 TYPE_FIELD_PRIVATE_BITS (type
) =
14411 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14412 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14414 TYPE_FIELD_PROTECTED_BITS (type
) =
14415 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14416 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14418 TYPE_FIELD_IGNORE_BITS (type
) =
14419 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14420 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14423 /* If the type has baseclasses, allocate and clear a bit vector for
14424 TYPE_FIELD_VIRTUAL_BITS. */
14425 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14427 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14428 unsigned char *pointer
;
14430 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14431 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14432 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14433 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14434 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14437 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14439 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14441 for (int index
= 0; index
< nfields
; ++index
)
14443 struct nextfield
&field
= fip
->fields
[index
];
14445 if (field
.variant
.is_discriminant
)
14446 di
->discriminant_index
= index
;
14447 else if (field
.variant
.default_branch
)
14448 di
->default_index
= index
;
14450 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14454 /* Copy the saved-up fields into the field vector. */
14455 for (int i
= 0; i
< nfields
; ++i
)
14457 struct nextfield
&field
14458 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14459 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14461 TYPE_FIELD (type
, i
) = field
.field
;
14462 switch (field
.accessibility
)
14464 case DW_ACCESS_private
:
14465 if (cu
->language
!= language_ada
)
14466 SET_TYPE_FIELD_PRIVATE (type
, i
);
14469 case DW_ACCESS_protected
:
14470 if (cu
->language
!= language_ada
)
14471 SET_TYPE_FIELD_PROTECTED (type
, i
);
14474 case DW_ACCESS_public
:
14478 /* Unknown accessibility. Complain and treat it as public. */
14480 complaint (_("unsupported accessibility %d"),
14481 field
.accessibility
);
14485 if (i
< fip
->baseclasses
.size ())
14487 switch (field
.virtuality
)
14489 case DW_VIRTUALITY_virtual
:
14490 case DW_VIRTUALITY_pure_virtual
:
14491 if (cu
->language
== language_ada
)
14492 error (_("unexpected virtuality in component of Ada type"));
14493 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14500 /* Return true if this member function is a constructor, false
14504 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14506 const char *fieldname
;
14507 const char *type_name
;
14510 if (die
->parent
== NULL
)
14513 if (die
->parent
->tag
!= DW_TAG_structure_type
14514 && die
->parent
->tag
!= DW_TAG_union_type
14515 && die
->parent
->tag
!= DW_TAG_class_type
)
14518 fieldname
= dwarf2_name (die
, cu
);
14519 type_name
= dwarf2_name (die
->parent
, cu
);
14520 if (fieldname
== NULL
|| type_name
== NULL
)
14523 len
= strlen (fieldname
);
14524 return (strncmp (fieldname
, type_name
, len
) == 0
14525 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14528 /* Check if the given VALUE is a recognized enum
14529 dwarf_defaulted_attribute constant according to DWARF5 spec,
14533 is_valid_DW_AT_defaulted (ULONGEST value
)
14537 case DW_DEFAULTED_no
:
14538 case DW_DEFAULTED_in_class
:
14539 case DW_DEFAULTED_out_of_class
:
14543 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14547 /* Add a member function to the proper fieldlist. */
14550 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14551 struct type
*type
, struct dwarf2_cu
*cu
)
14553 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14554 struct attribute
*attr
;
14556 struct fnfieldlist
*flp
= nullptr;
14557 struct fn_field
*fnp
;
14558 const char *fieldname
;
14559 struct type
*this_type
;
14560 enum dwarf_access_attribute accessibility
;
14562 if (cu
->language
== language_ada
)
14563 error (_("unexpected member function in Ada type"));
14565 /* Get name of member function. */
14566 fieldname
= dwarf2_name (die
, cu
);
14567 if (fieldname
== NULL
)
14570 /* Look up member function name in fieldlist. */
14571 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14573 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14575 flp
= &fip
->fnfieldlists
[i
];
14580 /* Create a new fnfieldlist if necessary. */
14581 if (flp
== nullptr)
14583 fip
->fnfieldlists
.emplace_back ();
14584 flp
= &fip
->fnfieldlists
.back ();
14585 flp
->name
= fieldname
;
14586 i
= fip
->fnfieldlists
.size () - 1;
14589 /* Create a new member function field and add it to the vector of
14591 flp
->fnfields
.emplace_back ();
14592 fnp
= &flp
->fnfields
.back ();
14594 /* Delay processing of the physname until later. */
14595 if (cu
->language
== language_cplus
)
14596 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14600 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14601 fnp
->physname
= physname
? physname
: "";
14604 fnp
->type
= alloc_type (objfile
);
14605 this_type
= read_type_die (die
, cu
);
14606 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14608 int nparams
= TYPE_NFIELDS (this_type
);
14610 /* TYPE is the domain of this method, and THIS_TYPE is the type
14611 of the method itself (TYPE_CODE_METHOD). */
14612 smash_to_method_type (fnp
->type
, type
,
14613 TYPE_TARGET_TYPE (this_type
),
14614 TYPE_FIELDS (this_type
),
14615 TYPE_NFIELDS (this_type
),
14616 TYPE_VARARGS (this_type
));
14618 /* Handle static member functions.
14619 Dwarf2 has no clean way to discern C++ static and non-static
14620 member functions. G++ helps GDB by marking the first
14621 parameter for non-static member functions (which is the this
14622 pointer) as artificial. We obtain this information from
14623 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14624 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14625 fnp
->voffset
= VOFFSET_STATIC
;
14628 complaint (_("member function type missing for '%s'"),
14629 dwarf2_full_name (fieldname
, die
, cu
));
14631 /* Get fcontext from DW_AT_containing_type if present. */
14632 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14633 fnp
->fcontext
= die_containing_type (die
, cu
);
14635 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14636 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14638 /* Get accessibility. */
14639 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14640 if (attr
!= nullptr)
14641 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14643 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14644 switch (accessibility
)
14646 case DW_ACCESS_private
:
14647 fnp
->is_private
= 1;
14649 case DW_ACCESS_protected
:
14650 fnp
->is_protected
= 1;
14654 /* Check for artificial methods. */
14655 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14656 if (attr
&& DW_UNSND (attr
) != 0)
14657 fnp
->is_artificial
= 1;
14659 /* Check for defaulted methods. */
14660 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14661 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14662 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14664 /* Check for deleted methods. */
14665 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14666 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14667 fnp
->is_deleted
= 1;
14669 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14671 /* Get index in virtual function table if it is a virtual member
14672 function. For older versions of GCC, this is an offset in the
14673 appropriate virtual table, as specified by DW_AT_containing_type.
14674 For everyone else, it is an expression to be evaluated relative
14675 to the object address. */
14677 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14678 if (attr
!= nullptr)
14680 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14682 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14684 /* Old-style GCC. */
14685 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14687 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14688 || (DW_BLOCK (attr
)->size
> 1
14689 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14690 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14692 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14693 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14694 dwarf2_complex_location_expr_complaint ();
14696 fnp
->voffset
/= cu
->header
.addr_size
;
14700 dwarf2_complex_location_expr_complaint ();
14702 if (!fnp
->fcontext
)
14704 /* If there is no `this' field and no DW_AT_containing_type,
14705 we cannot actually find a base class context for the
14707 if (TYPE_NFIELDS (this_type
) == 0
14708 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14710 complaint (_("cannot determine context for virtual member "
14711 "function \"%s\" (offset %s)"),
14712 fieldname
, sect_offset_str (die
->sect_off
));
14717 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14721 else if (attr
->form_is_section_offset ())
14723 dwarf2_complex_location_expr_complaint ();
14727 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14733 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14734 if (attr
&& DW_UNSND (attr
))
14736 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14737 complaint (_("Member function \"%s\" (offset %s) is virtual "
14738 "but the vtable offset is not specified"),
14739 fieldname
, sect_offset_str (die
->sect_off
));
14740 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14741 TYPE_CPLUS_DYNAMIC (type
) = 1;
14746 /* Create the vector of member function fields, and attach it to the type. */
14749 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14750 struct dwarf2_cu
*cu
)
14752 if (cu
->language
== language_ada
)
14753 error (_("unexpected member functions in Ada type"));
14755 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14756 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14758 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14760 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14762 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14763 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14765 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14766 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14767 fn_flp
->fn_fields
= (struct fn_field
*)
14768 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14770 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14771 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14774 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14777 /* Returns non-zero if NAME is the name of a vtable member in CU's
14778 language, zero otherwise. */
14780 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14782 static const char vptr
[] = "_vptr";
14784 /* Look for the C++ form of the vtable. */
14785 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14791 /* GCC outputs unnamed structures that are really pointers to member
14792 functions, with the ABI-specified layout. If TYPE describes
14793 such a structure, smash it into a member function type.
14795 GCC shouldn't do this; it should just output pointer to member DIEs.
14796 This is GCC PR debug/28767. */
14799 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14801 struct type
*pfn_type
, *self_type
, *new_type
;
14803 /* Check for a structure with no name and two children. */
14804 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14807 /* Check for __pfn and __delta members. */
14808 if (TYPE_FIELD_NAME (type
, 0) == NULL
14809 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14810 || TYPE_FIELD_NAME (type
, 1) == NULL
14811 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14814 /* Find the type of the method. */
14815 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14816 if (pfn_type
== NULL
14817 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14818 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14821 /* Look for the "this" argument. */
14822 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14823 if (TYPE_NFIELDS (pfn_type
) == 0
14824 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14825 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14828 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14829 new_type
= alloc_type (objfile
);
14830 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14831 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14832 TYPE_VARARGS (pfn_type
));
14833 smash_to_methodptr_type (type
, new_type
);
14836 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14837 appropriate error checking and issuing complaints if there is a
14841 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14843 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14845 if (attr
== nullptr)
14848 if (!attr
->form_is_constant ())
14850 complaint (_("DW_AT_alignment must have constant form"
14851 " - DIE at %s [in module %s]"),
14852 sect_offset_str (die
->sect_off
),
14853 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14858 if (attr
->form
== DW_FORM_sdata
)
14860 LONGEST val
= DW_SND (attr
);
14863 complaint (_("DW_AT_alignment value must not be negative"
14864 " - DIE at %s [in module %s]"),
14865 sect_offset_str (die
->sect_off
),
14866 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14872 align
= DW_UNSND (attr
);
14876 complaint (_("DW_AT_alignment value must not be zero"
14877 " - DIE at %s [in module %s]"),
14878 sect_offset_str (die
->sect_off
),
14879 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14882 if ((align
& (align
- 1)) != 0)
14884 complaint (_("DW_AT_alignment value must be a power of 2"
14885 " - DIE at %s [in module %s]"),
14886 sect_offset_str (die
->sect_off
),
14887 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14894 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14895 the alignment for TYPE. */
14898 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14901 if (!set_type_align (type
, get_alignment (cu
, die
)))
14902 complaint (_("DW_AT_alignment value too large"
14903 " - DIE at %s [in module %s]"),
14904 sect_offset_str (die
->sect_off
),
14905 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14908 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14909 constant for a type, according to DWARF5 spec, Table 5.5. */
14912 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14917 case DW_CC_pass_by_reference
:
14918 case DW_CC_pass_by_value
:
14922 complaint (_("unrecognized DW_AT_calling_convention value "
14923 "(%s) for a type"), pulongest (value
));
14928 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14929 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14930 also according to GNU-specific values (see include/dwarf2.h). */
14933 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14938 case DW_CC_program
:
14942 case DW_CC_GNU_renesas_sh
:
14943 case DW_CC_GNU_borland_fastcall_i386
:
14944 case DW_CC_GDB_IBM_OpenCL
:
14948 complaint (_("unrecognized DW_AT_calling_convention value "
14949 "(%s) for a subroutine"), pulongest (value
));
14954 /* Called when we find the DIE that starts a structure or union scope
14955 (definition) to create a type for the structure or union. Fill in
14956 the type's name and general properties; the members will not be
14957 processed until process_structure_scope. A symbol table entry for
14958 the type will also not be done until process_structure_scope (assuming
14959 the type has a name).
14961 NOTE: we need to call these functions regardless of whether or not the
14962 DIE has a DW_AT_name attribute, since it might be an anonymous
14963 structure or union. This gets the type entered into our set of
14964 user defined types. */
14966 static struct type
*
14967 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14969 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14971 struct attribute
*attr
;
14974 /* If the definition of this type lives in .debug_types, read that type.
14975 Don't follow DW_AT_specification though, that will take us back up
14976 the chain and we want to go down. */
14977 attr
= die
->attr (DW_AT_signature
);
14978 if (attr
!= nullptr)
14980 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14982 /* The type's CU may not be the same as CU.
14983 Ensure TYPE is recorded with CU in die_type_hash. */
14984 return set_die_type (die
, type
, cu
);
14987 type
= alloc_type (objfile
);
14988 INIT_CPLUS_SPECIFIC (type
);
14990 name
= dwarf2_name (die
, cu
);
14993 if (cu
->language
== language_cplus
14994 || cu
->language
== language_d
14995 || cu
->language
== language_rust
)
14997 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
14999 /* dwarf2_full_name might have already finished building the DIE's
15000 type. If so, there is no need to continue. */
15001 if (get_die_type (die
, cu
) != NULL
)
15002 return get_die_type (die
, cu
);
15004 TYPE_NAME (type
) = full_name
;
15008 /* The name is already allocated along with this objfile, so
15009 we don't need to duplicate it for the type. */
15010 TYPE_NAME (type
) = name
;
15014 if (die
->tag
== DW_TAG_structure_type
)
15016 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15018 else if (die
->tag
== DW_TAG_union_type
)
15020 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15022 else if (die
->tag
== DW_TAG_variant_part
)
15024 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15025 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15029 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15032 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15033 TYPE_DECLARED_CLASS (type
) = 1;
15035 /* Store the calling convention in the type if it's available in
15036 the die. Otherwise the calling convention remains set to
15037 the default value DW_CC_normal. */
15038 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15039 if (attr
!= nullptr
15040 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15042 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15043 TYPE_CPLUS_CALLING_CONVENTION (type
)
15044 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15047 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15048 if (attr
!= nullptr)
15050 if (attr
->form_is_constant ())
15051 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15054 /* For the moment, dynamic type sizes are not supported
15055 by GDB's struct type. The actual size is determined
15056 on-demand when resolving the type of a given object,
15057 so set the type's length to zero for now. Otherwise,
15058 we record an expression as the length, and that expression
15059 could lead to a very large value, which could eventually
15060 lead to us trying to allocate that much memory when creating
15061 a value of that type. */
15062 TYPE_LENGTH (type
) = 0;
15067 TYPE_LENGTH (type
) = 0;
15070 maybe_set_alignment (cu
, die
, type
);
15072 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15074 /* ICC<14 does not output the required DW_AT_declaration on
15075 incomplete types, but gives them a size of zero. */
15076 TYPE_STUB (type
) = 1;
15079 TYPE_STUB_SUPPORTED (type
) = 1;
15081 if (die_is_declaration (die
, cu
))
15082 TYPE_STUB (type
) = 1;
15083 else if (attr
== NULL
&& die
->child
== NULL
15084 && producer_is_realview (cu
->producer
))
15085 /* RealView does not output the required DW_AT_declaration
15086 on incomplete types. */
15087 TYPE_STUB (type
) = 1;
15089 /* We need to add the type field to the die immediately so we don't
15090 infinitely recurse when dealing with pointers to the structure
15091 type within the structure itself. */
15092 set_die_type (die
, type
, cu
);
15094 /* set_die_type should be already done. */
15095 set_descriptive_type (type
, die
, cu
);
15100 /* A helper for process_structure_scope that handles a single member
15104 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15105 struct field_info
*fi
,
15106 std::vector
<struct symbol
*> *template_args
,
15107 struct dwarf2_cu
*cu
)
15109 if (child_die
->tag
== DW_TAG_member
15110 || child_die
->tag
== DW_TAG_variable
15111 || child_die
->tag
== DW_TAG_variant_part
)
15113 /* NOTE: carlton/2002-11-05: A C++ static data member
15114 should be a DW_TAG_member that is a declaration, but
15115 all versions of G++ as of this writing (so through at
15116 least 3.2.1) incorrectly generate DW_TAG_variable
15117 tags for them instead. */
15118 dwarf2_add_field (fi
, child_die
, cu
);
15120 else if (child_die
->tag
== DW_TAG_subprogram
)
15122 /* Rust doesn't have member functions in the C++ sense.
15123 However, it does emit ordinary functions as children
15124 of a struct DIE. */
15125 if (cu
->language
== language_rust
)
15126 read_func_scope (child_die
, cu
);
15129 /* C++ member function. */
15130 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15133 else if (child_die
->tag
== DW_TAG_inheritance
)
15135 /* C++ base class field. */
15136 dwarf2_add_field (fi
, child_die
, cu
);
15138 else if (type_can_define_types (child_die
))
15139 dwarf2_add_type_defn (fi
, child_die
, cu
);
15140 else if (child_die
->tag
== DW_TAG_template_type_param
15141 || child_die
->tag
== DW_TAG_template_value_param
)
15143 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15146 template_args
->push_back (arg
);
15148 else if (child_die
->tag
== DW_TAG_variant
)
15150 /* In a variant we want to get the discriminant and also add a
15151 field for our sole member child. */
15152 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15154 for (die_info
*variant_child
= child_die
->child
;
15155 variant_child
!= NULL
;
15156 variant_child
= sibling_die (variant_child
))
15158 if (variant_child
->tag
== DW_TAG_member
)
15160 handle_struct_member_die (variant_child
, type
, fi
,
15161 template_args
, cu
);
15162 /* Only handle the one. */
15167 /* We don't handle this but we might as well report it if we see
15169 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15170 complaint (_("DW_AT_discr_list is not supported yet"
15171 " - DIE at %s [in module %s]"),
15172 sect_offset_str (child_die
->sect_off
),
15173 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15175 /* The first field was just added, so we can stash the
15176 discriminant there. */
15177 gdb_assert (!fi
->fields
.empty ());
15179 fi
->fields
.back ().variant
.default_branch
= true;
15181 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15185 /* Finish creating a structure or union type, including filling in
15186 its members and creating a symbol for it. */
15189 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15191 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15192 struct die_info
*child_die
;
15195 type
= get_die_type (die
, cu
);
15197 type
= read_structure_type (die
, cu
);
15199 /* When reading a DW_TAG_variant_part, we need to notice when we
15200 read the discriminant member, so we can record it later in the
15201 discriminant_info. */
15202 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15203 sect_offset discr_offset
{};
15204 bool has_template_parameters
= false;
15206 if (is_variant_part
)
15208 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15211 /* Maybe it's a univariant form, an extension we support.
15212 In this case arrange not to check the offset. */
15213 is_variant_part
= false;
15215 else if (discr
->form_is_ref ())
15217 struct dwarf2_cu
*target_cu
= cu
;
15218 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15220 discr_offset
= target_die
->sect_off
;
15224 complaint (_("DW_AT_discr does not have DIE reference form"
15225 " - DIE at %s [in module %s]"),
15226 sect_offset_str (die
->sect_off
),
15227 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15228 is_variant_part
= false;
15232 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15234 struct field_info fi
;
15235 std::vector
<struct symbol
*> template_args
;
15237 child_die
= die
->child
;
15239 while (child_die
&& child_die
->tag
)
15241 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15243 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15244 fi
.fields
.back ().variant
.is_discriminant
= true;
15246 child_die
= sibling_die (child_die
);
15249 /* Attach template arguments to type. */
15250 if (!template_args
.empty ())
15252 has_template_parameters
= true;
15253 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15254 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15255 TYPE_TEMPLATE_ARGUMENTS (type
)
15256 = XOBNEWVEC (&objfile
->objfile_obstack
,
15258 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15259 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15260 template_args
.data (),
15261 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15262 * sizeof (struct symbol
*)));
15265 /* Attach fields and member functions to the type. */
15266 if (fi
.nfields () > 0)
15267 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15268 if (!fi
.fnfieldlists
.empty ())
15270 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15272 /* Get the type which refers to the base class (possibly this
15273 class itself) which contains the vtable pointer for the current
15274 class from the DW_AT_containing_type attribute. This use of
15275 DW_AT_containing_type is a GNU extension. */
15277 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15279 struct type
*t
= die_containing_type (die
, cu
);
15281 set_type_vptr_basetype (type
, t
);
15286 /* Our own class provides vtbl ptr. */
15287 for (i
= TYPE_NFIELDS (t
) - 1;
15288 i
>= TYPE_N_BASECLASSES (t
);
15291 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15293 if (is_vtable_name (fieldname
, cu
))
15295 set_type_vptr_fieldno (type
, i
);
15300 /* Complain if virtual function table field not found. */
15301 if (i
< TYPE_N_BASECLASSES (t
))
15302 complaint (_("virtual function table pointer "
15303 "not found when defining class '%s'"),
15304 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15308 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15311 else if (cu
->producer
15312 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15314 /* The IBM XLC compiler does not provide direct indication
15315 of the containing type, but the vtable pointer is
15316 always named __vfp. */
15320 for (i
= TYPE_NFIELDS (type
) - 1;
15321 i
>= TYPE_N_BASECLASSES (type
);
15324 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15326 set_type_vptr_fieldno (type
, i
);
15327 set_type_vptr_basetype (type
, type
);
15334 /* Copy fi.typedef_field_list linked list elements content into the
15335 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15336 if (!fi
.typedef_field_list
.empty ())
15338 int count
= fi
.typedef_field_list
.size ();
15340 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15341 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15342 = ((struct decl_field
*)
15344 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15345 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15347 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15348 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15351 /* Copy fi.nested_types_list linked list elements content into the
15352 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15353 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15355 int count
= fi
.nested_types_list
.size ();
15357 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15358 TYPE_NESTED_TYPES_ARRAY (type
)
15359 = ((struct decl_field
*)
15360 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15361 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15363 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15364 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15368 quirk_gcc_member_function_pointer (type
, objfile
);
15369 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15370 cu
->rust_unions
.push_back (type
);
15372 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15373 snapshots) has been known to create a die giving a declaration
15374 for a class that has, as a child, a die giving a definition for a
15375 nested class. So we have to process our children even if the
15376 current die is a declaration. Normally, of course, a declaration
15377 won't have any children at all. */
15379 child_die
= die
->child
;
15381 while (child_die
!= NULL
&& child_die
->tag
)
15383 if (child_die
->tag
== DW_TAG_member
15384 || child_die
->tag
== DW_TAG_variable
15385 || child_die
->tag
== DW_TAG_inheritance
15386 || child_die
->tag
== DW_TAG_template_value_param
15387 || child_die
->tag
== DW_TAG_template_type_param
)
15392 process_die (child_die
, cu
);
15394 child_die
= sibling_die (child_die
);
15397 /* Do not consider external references. According to the DWARF standard,
15398 these DIEs are identified by the fact that they have no byte_size
15399 attribute, and a declaration attribute. */
15400 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15401 || !die_is_declaration (die
, cu
))
15403 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15405 if (has_template_parameters
)
15407 struct symtab
*symtab
;
15408 if (sym
!= nullptr)
15409 symtab
= symbol_symtab (sym
);
15410 else if (cu
->line_header
!= nullptr)
15412 /* Any related symtab will do. */
15414 = cu
->line_header
->file_names ()[0].symtab
;
15419 complaint (_("could not find suitable "
15420 "symtab for template parameter"
15421 " - DIE at %s [in module %s]"),
15422 sect_offset_str (die
->sect_off
),
15423 objfile_name (objfile
));
15426 if (symtab
!= nullptr)
15428 /* Make sure that the symtab is set on the new symbols.
15429 Even though they don't appear in this symtab directly,
15430 other parts of gdb assume that symbols do, and this is
15431 reasonably true. */
15432 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15433 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15439 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15440 update TYPE using some information only available in DIE's children. */
15443 update_enumeration_type_from_children (struct die_info
*die
,
15445 struct dwarf2_cu
*cu
)
15447 struct die_info
*child_die
;
15448 int unsigned_enum
= 1;
15451 auto_obstack obstack
;
15453 for (child_die
= die
->child
;
15454 child_die
!= NULL
&& child_die
->tag
;
15455 child_die
= sibling_die (child_die
))
15457 struct attribute
*attr
;
15459 const gdb_byte
*bytes
;
15460 struct dwarf2_locexpr_baton
*baton
;
15463 if (child_die
->tag
!= DW_TAG_enumerator
)
15466 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15470 name
= dwarf2_name (child_die
, cu
);
15472 name
= "<anonymous enumerator>";
15474 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15475 &value
, &bytes
, &baton
);
15483 if (count_one_bits_ll (value
) >= 2)
15487 /* If we already know that the enum type is neither unsigned, nor
15488 a flag type, no need to look at the rest of the enumerates. */
15489 if (!unsigned_enum
&& !flag_enum
)
15494 TYPE_UNSIGNED (type
) = 1;
15496 TYPE_FLAG_ENUM (type
) = 1;
15499 /* Given a DW_AT_enumeration_type die, set its type. We do not
15500 complete the type's fields yet, or create any symbols. */
15502 static struct type
*
15503 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15505 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15507 struct attribute
*attr
;
15510 /* If the definition of this type lives in .debug_types, read that type.
15511 Don't follow DW_AT_specification though, that will take us back up
15512 the chain and we want to go down. */
15513 attr
= die
->attr (DW_AT_signature
);
15514 if (attr
!= nullptr)
15516 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15518 /* The type's CU may not be the same as CU.
15519 Ensure TYPE is recorded with CU in die_type_hash. */
15520 return set_die_type (die
, type
, cu
);
15523 type
= alloc_type (objfile
);
15525 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15526 name
= dwarf2_full_name (NULL
, die
, cu
);
15528 TYPE_NAME (type
) = name
;
15530 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15533 struct type
*underlying_type
= die_type (die
, cu
);
15535 TYPE_TARGET_TYPE (type
) = underlying_type
;
15538 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15539 if (attr
!= nullptr)
15541 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15545 TYPE_LENGTH (type
) = 0;
15548 maybe_set_alignment (cu
, die
, type
);
15550 /* The enumeration DIE can be incomplete. In Ada, any type can be
15551 declared as private in the package spec, and then defined only
15552 inside the package body. Such types are known as Taft Amendment
15553 Types. When another package uses such a type, an incomplete DIE
15554 may be generated by the compiler. */
15555 if (die_is_declaration (die
, cu
))
15556 TYPE_STUB (type
) = 1;
15558 /* Finish the creation of this type by using the enum's children.
15559 We must call this even when the underlying type has been provided
15560 so that we can determine if we're looking at a "flag" enum. */
15561 update_enumeration_type_from_children (die
, type
, cu
);
15563 /* If this type has an underlying type that is not a stub, then we
15564 may use its attributes. We always use the "unsigned" attribute
15565 in this situation, because ordinarily we guess whether the type
15566 is unsigned -- but the guess can be wrong and the underlying type
15567 can tell us the reality. However, we defer to a local size
15568 attribute if one exists, because this lets the compiler override
15569 the underlying type if needed. */
15570 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15572 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15573 if (TYPE_LENGTH (type
) == 0)
15574 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15575 if (TYPE_RAW_ALIGN (type
) == 0
15576 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15577 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15580 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15582 return set_die_type (die
, type
, cu
);
15585 /* Given a pointer to a die which begins an enumeration, process all
15586 the dies that define the members of the enumeration, and create the
15587 symbol for the enumeration type.
15589 NOTE: We reverse the order of the element list. */
15592 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15594 struct type
*this_type
;
15596 this_type
= get_die_type (die
, cu
);
15597 if (this_type
== NULL
)
15598 this_type
= read_enumeration_type (die
, cu
);
15600 if (die
->child
!= NULL
)
15602 struct die_info
*child_die
;
15603 struct symbol
*sym
;
15604 std::vector
<struct field
> fields
;
15607 child_die
= die
->child
;
15608 while (child_die
&& child_die
->tag
)
15610 if (child_die
->tag
!= DW_TAG_enumerator
)
15612 process_die (child_die
, cu
);
15616 name
= dwarf2_name (child_die
, cu
);
15619 sym
= new_symbol (child_die
, this_type
, cu
);
15621 fields
.emplace_back ();
15622 struct field
&field
= fields
.back ();
15624 FIELD_NAME (field
) = sym
->linkage_name ();
15625 FIELD_TYPE (field
) = NULL
;
15626 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15627 FIELD_BITSIZE (field
) = 0;
15631 child_die
= sibling_die (child_die
);
15634 if (!fields
.empty ())
15636 TYPE_NFIELDS (this_type
) = fields
.size ();
15637 TYPE_FIELDS (this_type
) = (struct field
*)
15638 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15639 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15640 sizeof (struct field
) * fields
.size ());
15644 /* If we are reading an enum from a .debug_types unit, and the enum
15645 is a declaration, and the enum is not the signatured type in the
15646 unit, then we do not want to add a symbol for it. Adding a
15647 symbol would in some cases obscure the true definition of the
15648 enum, giving users an incomplete type when the definition is
15649 actually available. Note that we do not want to do this for all
15650 enums which are just declarations, because C++0x allows forward
15651 enum declarations. */
15652 if (cu
->per_cu
->is_debug_types
15653 && die_is_declaration (die
, cu
))
15655 struct signatured_type
*sig_type
;
15657 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15658 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15659 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15663 new_symbol (die
, this_type
, cu
);
15666 /* Extract all information from a DW_TAG_array_type DIE and put it in
15667 the DIE's type field. For now, this only handles one dimensional
15670 static struct type
*
15671 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15673 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15674 struct die_info
*child_die
;
15676 struct type
*element_type
, *range_type
, *index_type
;
15677 struct attribute
*attr
;
15679 struct dynamic_prop
*byte_stride_prop
= NULL
;
15680 unsigned int bit_stride
= 0;
15682 element_type
= die_type (die
, cu
);
15684 /* The die_type call above may have already set the type for this DIE. */
15685 type
= get_die_type (die
, cu
);
15689 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15693 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15696 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15697 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15701 complaint (_("unable to read array DW_AT_byte_stride "
15702 " - DIE at %s [in module %s]"),
15703 sect_offset_str (die
->sect_off
),
15704 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15705 /* Ignore this attribute. We will likely not be able to print
15706 arrays of this type correctly, but there is little we can do
15707 to help if we cannot read the attribute's value. */
15708 byte_stride_prop
= NULL
;
15712 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15714 bit_stride
= DW_UNSND (attr
);
15716 /* Irix 6.2 native cc creates array types without children for
15717 arrays with unspecified length. */
15718 if (die
->child
== NULL
)
15720 index_type
= objfile_type (objfile
)->builtin_int
;
15721 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15722 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15723 byte_stride_prop
, bit_stride
);
15724 return set_die_type (die
, type
, cu
);
15727 std::vector
<struct type
*> range_types
;
15728 child_die
= die
->child
;
15729 while (child_die
&& child_die
->tag
)
15731 if (child_die
->tag
== DW_TAG_subrange_type
)
15733 struct type
*child_type
= read_type_die (child_die
, cu
);
15735 if (child_type
!= NULL
)
15737 /* The range type was succesfully read. Save it for the
15738 array type creation. */
15739 range_types
.push_back (child_type
);
15742 child_die
= sibling_die (child_die
);
15745 /* Dwarf2 dimensions are output from left to right, create the
15746 necessary array types in backwards order. */
15748 type
= element_type
;
15750 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15754 while (i
< range_types
.size ())
15755 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15756 byte_stride_prop
, bit_stride
);
15760 size_t ndim
= range_types
.size ();
15762 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15763 byte_stride_prop
, bit_stride
);
15766 /* Understand Dwarf2 support for vector types (like they occur on
15767 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15768 array type. This is not part of the Dwarf2/3 standard yet, but a
15769 custom vendor extension. The main difference between a regular
15770 array and the vector variant is that vectors are passed by value
15772 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15773 if (attr
!= nullptr)
15774 make_vector_type (type
);
15776 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15777 implementation may choose to implement triple vectors using this
15779 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15780 if (attr
!= nullptr)
15782 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15783 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15785 complaint (_("DW_AT_byte_size for array type smaller "
15786 "than the total size of elements"));
15789 name
= dwarf2_name (die
, cu
);
15791 TYPE_NAME (type
) = name
;
15793 maybe_set_alignment (cu
, die
, type
);
15795 /* Install the type in the die. */
15796 set_die_type (die
, type
, cu
);
15798 /* set_die_type should be already done. */
15799 set_descriptive_type (type
, die
, cu
);
15804 static enum dwarf_array_dim_ordering
15805 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15807 struct attribute
*attr
;
15809 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15811 if (attr
!= nullptr)
15812 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15814 /* GNU F77 is a special case, as at 08/2004 array type info is the
15815 opposite order to the dwarf2 specification, but data is still
15816 laid out as per normal fortran.
15818 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15819 version checking. */
15821 if (cu
->language
== language_fortran
15822 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15824 return DW_ORD_row_major
;
15827 switch (cu
->language_defn
->la_array_ordering
)
15829 case array_column_major
:
15830 return DW_ORD_col_major
;
15831 case array_row_major
:
15833 return DW_ORD_row_major
;
15837 /* Extract all information from a DW_TAG_set_type DIE and put it in
15838 the DIE's type field. */
15840 static struct type
*
15841 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15843 struct type
*domain_type
, *set_type
;
15844 struct attribute
*attr
;
15846 domain_type
= die_type (die
, cu
);
15848 /* The die_type call above may have already set the type for this DIE. */
15849 set_type
= get_die_type (die
, cu
);
15853 set_type
= create_set_type (NULL
, domain_type
);
15855 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15856 if (attr
!= nullptr)
15857 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15859 maybe_set_alignment (cu
, die
, set_type
);
15861 return set_die_type (die
, set_type
, cu
);
15864 /* A helper for read_common_block that creates a locexpr baton.
15865 SYM is the symbol which we are marking as computed.
15866 COMMON_DIE is the DIE for the common block.
15867 COMMON_LOC is the location expression attribute for the common
15869 MEMBER_LOC is the location expression attribute for the particular
15870 member of the common block that we are processing.
15871 CU is the CU from which the above come. */
15874 mark_common_block_symbol_computed (struct symbol
*sym
,
15875 struct die_info
*common_die
,
15876 struct attribute
*common_loc
,
15877 struct attribute
*member_loc
,
15878 struct dwarf2_cu
*cu
)
15880 struct dwarf2_per_objfile
*dwarf2_per_objfile
15881 = cu
->per_cu
->dwarf2_per_objfile
;
15882 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15883 struct dwarf2_locexpr_baton
*baton
;
15885 unsigned int cu_off
;
15886 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15887 LONGEST offset
= 0;
15889 gdb_assert (common_loc
&& member_loc
);
15890 gdb_assert (common_loc
->form_is_block ());
15891 gdb_assert (member_loc
->form_is_block ()
15892 || member_loc
->form_is_constant ());
15894 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15895 baton
->per_cu
= cu
->per_cu
;
15896 gdb_assert (baton
->per_cu
);
15898 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15900 if (member_loc
->form_is_constant ())
15902 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15903 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15906 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15908 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15911 *ptr
++ = DW_OP_call4
;
15912 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15913 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15916 if (member_loc
->form_is_constant ())
15918 *ptr
++ = DW_OP_addr
;
15919 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15920 ptr
+= cu
->header
.addr_size
;
15924 /* We have to copy the data here, because DW_OP_call4 will only
15925 use a DW_AT_location attribute. */
15926 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15927 ptr
+= DW_BLOCK (member_loc
)->size
;
15930 *ptr
++ = DW_OP_plus
;
15931 gdb_assert (ptr
- baton
->data
== baton
->size
);
15933 SYMBOL_LOCATION_BATON (sym
) = baton
;
15934 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15937 /* Create appropriate locally-scoped variables for all the
15938 DW_TAG_common_block entries. Also create a struct common_block
15939 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15940 is used to separate the common blocks name namespace from regular
15944 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15946 struct attribute
*attr
;
15948 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15949 if (attr
!= nullptr)
15951 /* Support the .debug_loc offsets. */
15952 if (attr
->form_is_block ())
15956 else if (attr
->form_is_section_offset ())
15958 dwarf2_complex_location_expr_complaint ();
15963 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15964 "common block member");
15969 if (die
->child
!= NULL
)
15971 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15972 struct die_info
*child_die
;
15973 size_t n_entries
= 0, size
;
15974 struct common_block
*common_block
;
15975 struct symbol
*sym
;
15977 for (child_die
= die
->child
;
15978 child_die
&& child_die
->tag
;
15979 child_die
= sibling_die (child_die
))
15982 size
= (sizeof (struct common_block
)
15983 + (n_entries
- 1) * sizeof (struct symbol
*));
15985 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
15987 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
15988 common_block
->n_entries
= 0;
15990 for (child_die
= die
->child
;
15991 child_die
&& child_die
->tag
;
15992 child_die
= sibling_die (child_die
))
15994 /* Create the symbol in the DW_TAG_common_block block in the current
15996 sym
= new_symbol (child_die
, NULL
, cu
);
15999 struct attribute
*member_loc
;
16001 common_block
->contents
[common_block
->n_entries
++] = sym
;
16003 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16007 /* GDB has handled this for a long time, but it is
16008 not specified by DWARF. It seems to have been
16009 emitted by gfortran at least as recently as:
16010 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16011 complaint (_("Variable in common block has "
16012 "DW_AT_data_member_location "
16013 "- DIE at %s [in module %s]"),
16014 sect_offset_str (child_die
->sect_off
),
16015 objfile_name (objfile
));
16017 if (member_loc
->form_is_section_offset ())
16018 dwarf2_complex_location_expr_complaint ();
16019 else if (member_loc
->form_is_constant ()
16020 || member_loc
->form_is_block ())
16022 if (attr
!= nullptr)
16023 mark_common_block_symbol_computed (sym
, die
, attr
,
16027 dwarf2_complex_location_expr_complaint ();
16032 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16033 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16037 /* Create a type for a C++ namespace. */
16039 static struct type
*
16040 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16042 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16043 const char *previous_prefix
, *name
;
16047 /* For extensions, reuse the type of the original namespace. */
16048 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16050 struct die_info
*ext_die
;
16051 struct dwarf2_cu
*ext_cu
= cu
;
16053 ext_die
= dwarf2_extension (die
, &ext_cu
);
16054 type
= read_type_die (ext_die
, ext_cu
);
16056 /* EXT_CU may not be the same as CU.
16057 Ensure TYPE is recorded with CU in die_type_hash. */
16058 return set_die_type (die
, type
, cu
);
16061 name
= namespace_name (die
, &is_anonymous
, cu
);
16063 /* Now build the name of the current namespace. */
16065 previous_prefix
= determine_prefix (die
, cu
);
16066 if (previous_prefix
[0] != '\0')
16067 name
= typename_concat (&objfile
->objfile_obstack
,
16068 previous_prefix
, name
, 0, cu
);
16070 /* Create the type. */
16071 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16073 return set_die_type (die
, type
, cu
);
16076 /* Read a namespace scope. */
16079 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16081 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16084 /* Add a symbol associated to this if we haven't seen the namespace
16085 before. Also, add a using directive if it's an anonymous
16088 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16092 type
= read_type_die (die
, cu
);
16093 new_symbol (die
, type
, cu
);
16095 namespace_name (die
, &is_anonymous
, cu
);
16098 const char *previous_prefix
= determine_prefix (die
, cu
);
16100 std::vector
<const char *> excludes
;
16101 add_using_directive (using_directives (cu
),
16102 previous_prefix
, TYPE_NAME (type
), NULL
,
16103 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16107 if (die
->child
!= NULL
)
16109 struct die_info
*child_die
= die
->child
;
16111 while (child_die
&& child_die
->tag
)
16113 process_die (child_die
, cu
);
16114 child_die
= sibling_die (child_die
);
16119 /* Read a Fortran module as type. This DIE can be only a declaration used for
16120 imported module. Still we need that type as local Fortran "use ... only"
16121 declaration imports depend on the created type in determine_prefix. */
16123 static struct type
*
16124 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16126 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16127 const char *module_name
;
16130 module_name
= dwarf2_name (die
, cu
);
16131 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16133 return set_die_type (die
, type
, cu
);
16136 /* Read a Fortran module. */
16139 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16141 struct die_info
*child_die
= die
->child
;
16144 type
= read_type_die (die
, cu
);
16145 new_symbol (die
, type
, cu
);
16147 while (child_die
&& child_die
->tag
)
16149 process_die (child_die
, cu
);
16150 child_die
= sibling_die (child_die
);
16154 /* Return the name of the namespace represented by DIE. Set
16155 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16158 static const char *
16159 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16161 struct die_info
*current_die
;
16162 const char *name
= NULL
;
16164 /* Loop through the extensions until we find a name. */
16166 for (current_die
= die
;
16167 current_die
!= NULL
;
16168 current_die
= dwarf2_extension (die
, &cu
))
16170 /* We don't use dwarf2_name here so that we can detect the absence
16171 of a name -> anonymous namespace. */
16172 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16178 /* Is it an anonymous namespace? */
16180 *is_anonymous
= (name
== NULL
);
16182 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16187 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16188 the user defined type vector. */
16190 static struct type
*
16191 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16193 struct gdbarch
*gdbarch
16194 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16195 struct comp_unit_head
*cu_header
= &cu
->header
;
16197 struct attribute
*attr_byte_size
;
16198 struct attribute
*attr_address_class
;
16199 int byte_size
, addr_class
;
16200 struct type
*target_type
;
16202 target_type
= die_type (die
, cu
);
16204 /* The die_type call above may have already set the type for this DIE. */
16205 type
= get_die_type (die
, cu
);
16209 type
= lookup_pointer_type (target_type
);
16211 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16212 if (attr_byte_size
)
16213 byte_size
= DW_UNSND (attr_byte_size
);
16215 byte_size
= cu_header
->addr_size
;
16217 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16218 if (attr_address_class
)
16219 addr_class
= DW_UNSND (attr_address_class
);
16221 addr_class
= DW_ADDR_none
;
16223 ULONGEST alignment
= get_alignment (cu
, die
);
16225 /* If the pointer size, alignment, or address class is different
16226 than the default, create a type variant marked as such and set
16227 the length accordingly. */
16228 if (TYPE_LENGTH (type
) != byte_size
16229 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16230 && alignment
!= TYPE_RAW_ALIGN (type
))
16231 || addr_class
!= DW_ADDR_none
)
16233 if (gdbarch_address_class_type_flags_p (gdbarch
))
16237 type_flags
= gdbarch_address_class_type_flags
16238 (gdbarch
, byte_size
, addr_class
);
16239 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16241 type
= make_type_with_address_space (type
, type_flags
);
16243 else if (TYPE_LENGTH (type
) != byte_size
)
16245 complaint (_("invalid pointer size %d"), byte_size
);
16247 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16249 complaint (_("Invalid DW_AT_alignment"
16250 " - DIE at %s [in module %s]"),
16251 sect_offset_str (die
->sect_off
),
16252 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16256 /* Should we also complain about unhandled address classes? */
16260 TYPE_LENGTH (type
) = byte_size
;
16261 set_type_align (type
, alignment
);
16262 return set_die_type (die
, type
, cu
);
16265 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16266 the user defined type vector. */
16268 static struct type
*
16269 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16272 struct type
*to_type
;
16273 struct type
*domain
;
16275 to_type
= die_type (die
, cu
);
16276 domain
= die_containing_type (die
, cu
);
16278 /* The calls above may have already set the type for this DIE. */
16279 type
= get_die_type (die
, cu
);
16283 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16284 type
= lookup_methodptr_type (to_type
);
16285 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16287 struct type
*new_type
16288 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16290 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16291 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16292 TYPE_VARARGS (to_type
));
16293 type
= lookup_methodptr_type (new_type
);
16296 type
= lookup_memberptr_type (to_type
, domain
);
16298 return set_die_type (die
, type
, cu
);
16301 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16302 the user defined type vector. */
16304 static struct type
*
16305 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16306 enum type_code refcode
)
16308 struct comp_unit_head
*cu_header
= &cu
->header
;
16309 struct type
*type
, *target_type
;
16310 struct attribute
*attr
;
16312 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16314 target_type
= die_type (die
, cu
);
16316 /* The die_type call above may have already set the type for this DIE. */
16317 type
= get_die_type (die
, cu
);
16321 type
= lookup_reference_type (target_type
, refcode
);
16322 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16323 if (attr
!= nullptr)
16325 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16329 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16331 maybe_set_alignment (cu
, die
, type
);
16332 return set_die_type (die
, type
, cu
);
16335 /* Add the given cv-qualifiers to the element type of the array. GCC
16336 outputs DWARF type qualifiers that apply to an array, not the
16337 element type. But GDB relies on the array element type to carry
16338 the cv-qualifiers. This mimics section 6.7.3 of the C99
16341 static struct type
*
16342 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16343 struct type
*base_type
, int cnst
, int voltl
)
16345 struct type
*el_type
, *inner_array
;
16347 base_type
= copy_type (base_type
);
16348 inner_array
= base_type
;
16350 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16352 TYPE_TARGET_TYPE (inner_array
) =
16353 copy_type (TYPE_TARGET_TYPE (inner_array
));
16354 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16357 el_type
= TYPE_TARGET_TYPE (inner_array
);
16358 cnst
|= TYPE_CONST (el_type
);
16359 voltl
|= TYPE_VOLATILE (el_type
);
16360 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16362 return set_die_type (die
, base_type
, cu
);
16365 static struct type
*
16366 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16368 struct type
*base_type
, *cv_type
;
16370 base_type
= die_type (die
, cu
);
16372 /* The die_type call above may have already set the type for this DIE. */
16373 cv_type
= get_die_type (die
, cu
);
16377 /* In case the const qualifier is applied to an array type, the element type
16378 is so qualified, not the array type (section 6.7.3 of C99). */
16379 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16380 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16382 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16383 return set_die_type (die
, cv_type
, cu
);
16386 static struct type
*
16387 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16389 struct type
*base_type
, *cv_type
;
16391 base_type
= die_type (die
, cu
);
16393 /* The die_type call above may have already set the type for this DIE. */
16394 cv_type
= get_die_type (die
, cu
);
16398 /* In case the volatile qualifier is applied to an array type, the
16399 element type is so qualified, not the array type (section 6.7.3
16401 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16402 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16404 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16405 return set_die_type (die
, cv_type
, cu
);
16408 /* Handle DW_TAG_restrict_type. */
16410 static struct type
*
16411 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16413 struct type
*base_type
, *cv_type
;
16415 base_type
= die_type (die
, cu
);
16417 /* The die_type call above may have already set the type for this DIE. */
16418 cv_type
= get_die_type (die
, cu
);
16422 cv_type
= make_restrict_type (base_type
);
16423 return set_die_type (die
, cv_type
, cu
);
16426 /* Handle DW_TAG_atomic_type. */
16428 static struct type
*
16429 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16431 struct type
*base_type
, *cv_type
;
16433 base_type
= die_type (die
, cu
);
16435 /* The die_type call above may have already set the type for this DIE. */
16436 cv_type
= get_die_type (die
, cu
);
16440 cv_type
= make_atomic_type (base_type
);
16441 return set_die_type (die
, cv_type
, cu
);
16444 /* Extract all information from a DW_TAG_string_type DIE and add to
16445 the user defined type vector. It isn't really a user defined type,
16446 but it behaves like one, with other DIE's using an AT_user_def_type
16447 attribute to reference it. */
16449 static struct type
*
16450 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16452 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16453 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16454 struct type
*type
, *range_type
, *index_type
, *char_type
;
16455 struct attribute
*attr
;
16456 struct dynamic_prop prop
;
16457 bool length_is_constant
= true;
16460 /* There are a couple of places where bit sizes might be made use of
16461 when parsing a DW_TAG_string_type, however, no producer that we know
16462 of make use of these. Handling bit sizes that are a multiple of the
16463 byte size is easy enough, but what about other bit sizes? Lets deal
16464 with that problem when we have to. Warn about these attributes being
16465 unsupported, then parse the type and ignore them like we always
16467 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16468 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16470 static bool warning_printed
= false;
16471 if (!warning_printed
)
16473 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16474 "currently supported on DW_TAG_string_type."));
16475 warning_printed
= true;
16479 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16480 if (attr
!= nullptr && !attr
->form_is_constant ())
16482 /* The string length describes the location at which the length of
16483 the string can be found. The size of the length field can be
16484 specified with one of the attributes below. */
16485 struct type
*prop_type
;
16486 struct attribute
*len
16487 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16488 if (len
== nullptr)
16489 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16490 if (len
!= nullptr && len
->form_is_constant ())
16492 /* Pass 0 as the default as we know this attribute is constant
16493 and the default value will not be returned. */
16494 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16495 prop_type
= cu
->per_cu
->int_type (sz
, true);
16499 /* If the size is not specified then we assume it is the size of
16500 an address on this target. */
16501 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16504 /* Convert the attribute into a dynamic property. */
16505 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16508 length_is_constant
= false;
16510 else if (attr
!= nullptr)
16512 /* This DW_AT_string_length just contains the length with no
16513 indirection. There's no need to create a dynamic property in this
16514 case. Pass 0 for the default value as we know it will not be
16515 returned in this case. */
16516 length
= dwarf2_get_attr_constant_value (attr
, 0);
16518 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16520 /* We don't currently support non-constant byte sizes for strings. */
16521 length
= dwarf2_get_attr_constant_value (attr
, 1);
16525 /* Use 1 as a fallback length if we have nothing else. */
16529 index_type
= objfile_type (objfile
)->builtin_int
;
16530 if (length_is_constant
)
16531 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16534 struct dynamic_prop low_bound
;
16536 low_bound
.kind
= PROP_CONST
;
16537 low_bound
.data
.const_val
= 1;
16538 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16540 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16541 type
= create_string_type (NULL
, char_type
, range_type
);
16543 return set_die_type (die
, type
, cu
);
16546 /* Assuming that DIE corresponds to a function, returns nonzero
16547 if the function is prototyped. */
16550 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16552 struct attribute
*attr
;
16554 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16555 if (attr
&& (DW_UNSND (attr
) != 0))
16558 /* The DWARF standard implies that the DW_AT_prototyped attribute
16559 is only meaningful for C, but the concept also extends to other
16560 languages that allow unprototyped functions (Eg: Objective C).
16561 For all other languages, assume that functions are always
16563 if (cu
->language
!= language_c
16564 && cu
->language
!= language_objc
16565 && cu
->language
!= language_opencl
)
16568 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16569 prototyped and unprototyped functions; default to prototyped,
16570 since that is more common in modern code (and RealView warns
16571 about unprototyped functions). */
16572 if (producer_is_realview (cu
->producer
))
16578 /* Handle DIES due to C code like:
16582 int (*funcp)(int a, long l);
16586 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16588 static struct type
*
16589 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16591 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16592 struct type
*type
; /* Type that this function returns. */
16593 struct type
*ftype
; /* Function that returns above type. */
16594 struct attribute
*attr
;
16596 type
= die_type (die
, cu
);
16598 /* The die_type call above may have already set the type for this DIE. */
16599 ftype
= get_die_type (die
, cu
);
16603 ftype
= lookup_function_type (type
);
16605 if (prototyped_function_p (die
, cu
))
16606 TYPE_PROTOTYPED (ftype
) = 1;
16608 /* Store the calling convention in the type if it's available in
16609 the subroutine die. Otherwise set the calling convention to
16610 the default value DW_CC_normal. */
16611 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16612 if (attr
!= nullptr
16613 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16614 TYPE_CALLING_CONVENTION (ftype
)
16615 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16616 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16617 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16619 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16621 /* Record whether the function returns normally to its caller or not
16622 if the DWARF producer set that information. */
16623 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16624 if (attr
&& (DW_UNSND (attr
) != 0))
16625 TYPE_NO_RETURN (ftype
) = 1;
16627 /* We need to add the subroutine type to the die immediately so
16628 we don't infinitely recurse when dealing with parameters
16629 declared as the same subroutine type. */
16630 set_die_type (die
, ftype
, cu
);
16632 if (die
->child
!= NULL
)
16634 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16635 struct die_info
*child_die
;
16636 int nparams
, iparams
;
16638 /* Count the number of parameters.
16639 FIXME: GDB currently ignores vararg functions, but knows about
16640 vararg member functions. */
16642 child_die
= die
->child
;
16643 while (child_die
&& child_die
->tag
)
16645 if (child_die
->tag
== DW_TAG_formal_parameter
)
16647 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16648 TYPE_VARARGS (ftype
) = 1;
16649 child_die
= sibling_die (child_die
);
16652 /* Allocate storage for parameters and fill them in. */
16653 TYPE_NFIELDS (ftype
) = nparams
;
16654 TYPE_FIELDS (ftype
) = (struct field
*)
16655 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16657 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16658 even if we error out during the parameters reading below. */
16659 for (iparams
= 0; iparams
< nparams
; iparams
++)
16660 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16663 child_die
= die
->child
;
16664 while (child_die
&& child_die
->tag
)
16666 if (child_die
->tag
== DW_TAG_formal_parameter
)
16668 struct type
*arg_type
;
16670 /* DWARF version 2 has no clean way to discern C++
16671 static and non-static member functions. G++ helps
16672 GDB by marking the first parameter for non-static
16673 member functions (which is the this pointer) as
16674 artificial. We pass this information to
16675 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16677 DWARF version 3 added DW_AT_object_pointer, which GCC
16678 4.5 does not yet generate. */
16679 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16680 if (attr
!= nullptr)
16681 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16683 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16684 arg_type
= die_type (child_die
, cu
);
16686 /* RealView does not mark THIS as const, which the testsuite
16687 expects. GCC marks THIS as const in method definitions,
16688 but not in the class specifications (GCC PR 43053). */
16689 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16690 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16693 struct dwarf2_cu
*arg_cu
= cu
;
16694 const char *name
= dwarf2_name (child_die
, cu
);
16696 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16697 if (attr
!= nullptr)
16699 /* If the compiler emits this, use it. */
16700 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16703 else if (name
&& strcmp (name
, "this") == 0)
16704 /* Function definitions will have the argument names. */
16706 else if (name
== NULL
&& iparams
== 0)
16707 /* Declarations may not have the names, so like
16708 elsewhere in GDB, assume an artificial first
16709 argument is "this". */
16713 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16717 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16720 child_die
= sibling_die (child_die
);
16727 static struct type
*
16728 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16730 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16731 const char *name
= NULL
;
16732 struct type
*this_type
, *target_type
;
16734 name
= dwarf2_full_name (NULL
, die
, cu
);
16735 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16736 TYPE_TARGET_STUB (this_type
) = 1;
16737 set_die_type (die
, this_type
, cu
);
16738 target_type
= die_type (die
, cu
);
16739 if (target_type
!= this_type
)
16740 TYPE_TARGET_TYPE (this_type
) = target_type
;
16743 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16744 spec and cause infinite loops in GDB. */
16745 complaint (_("Self-referential DW_TAG_typedef "
16746 "- DIE at %s [in module %s]"),
16747 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16748 TYPE_TARGET_TYPE (this_type
) = NULL
;
16752 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16753 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16754 Handle these by just returning the target type, rather than
16755 constructing an anonymous typedef type and trying to handle this
16757 set_die_type (die
, target_type
, cu
);
16758 return target_type
;
16763 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16764 (which may be different from NAME) to the architecture back-end to allow
16765 it to guess the correct format if necessary. */
16767 static struct type
*
16768 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16769 const char *name_hint
, enum bfd_endian byte_order
)
16771 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16772 const struct floatformat
**format
;
16775 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16777 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16779 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16784 /* Allocate an integer type of size BITS and name NAME. */
16786 static struct type
*
16787 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16788 int bits
, int unsigned_p
, const char *name
)
16792 /* Versions of Intel's C Compiler generate an integer type called "void"
16793 instead of using DW_TAG_unspecified_type. This has been seen on
16794 at least versions 14, 17, and 18. */
16795 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16796 && strcmp (name
, "void") == 0)
16797 type
= objfile_type (objfile
)->builtin_void
;
16799 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16804 /* Initialise and return a floating point type of size BITS suitable for
16805 use as a component of a complex number. The NAME_HINT is passed through
16806 when initialising the floating point type and is the name of the complex
16809 As DWARF doesn't currently provide an explicit name for the components
16810 of a complex number, but it can be helpful to have these components
16811 named, we try to select a suitable name based on the size of the
16813 static struct type
*
16814 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16815 struct objfile
*objfile
,
16816 int bits
, const char *name_hint
,
16817 enum bfd_endian byte_order
)
16819 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16820 struct type
*tt
= nullptr;
16822 /* Try to find a suitable floating point builtin type of size BITS.
16823 We're going to use the name of this type as the name for the complex
16824 target type that we are about to create. */
16825 switch (cu
->language
)
16827 case language_fortran
:
16831 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16834 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16836 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16838 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16846 tt
= builtin_type (gdbarch
)->builtin_float
;
16849 tt
= builtin_type (gdbarch
)->builtin_double
;
16851 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16853 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16859 /* If the type we found doesn't match the size we were looking for, then
16860 pretend we didn't find a type at all, the complex target type we
16861 create will then be nameless. */
16862 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16865 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16866 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16869 /* Find a representation of a given base type and install
16870 it in the TYPE field of the die. */
16872 static struct type
*
16873 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16875 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16877 struct attribute
*attr
;
16878 int encoding
= 0, bits
= 0;
16882 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16883 if (attr
!= nullptr)
16884 encoding
= DW_UNSND (attr
);
16885 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16886 if (attr
!= nullptr)
16887 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16888 name
= dwarf2_name (die
, cu
);
16890 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16892 arch
= get_objfile_arch (objfile
);
16893 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16895 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16898 int endianity
= DW_UNSND (attr
);
16903 byte_order
= BFD_ENDIAN_BIG
;
16905 case DW_END_little
:
16906 byte_order
= BFD_ENDIAN_LITTLE
;
16909 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16916 case DW_ATE_address
:
16917 /* Turn DW_ATE_address into a void * pointer. */
16918 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16919 type
= init_pointer_type (objfile
, bits
, name
, type
);
16921 case DW_ATE_boolean
:
16922 type
= init_boolean_type (objfile
, bits
, 1, name
);
16924 case DW_ATE_complex_float
:
16925 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16927 type
= init_complex_type (objfile
, name
, type
);
16929 case DW_ATE_decimal_float
:
16930 type
= init_decfloat_type (objfile
, bits
, name
);
16933 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16935 case DW_ATE_signed
:
16936 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16938 case DW_ATE_unsigned
:
16939 if (cu
->language
== language_fortran
16941 && startswith (name
, "character("))
16942 type
= init_character_type (objfile
, bits
, 1, name
);
16944 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16946 case DW_ATE_signed_char
:
16947 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16948 || cu
->language
== language_pascal
16949 || cu
->language
== language_fortran
)
16950 type
= init_character_type (objfile
, bits
, 0, name
);
16952 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16954 case DW_ATE_unsigned_char
:
16955 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16956 || cu
->language
== language_pascal
16957 || cu
->language
== language_fortran
16958 || cu
->language
== language_rust
)
16959 type
= init_character_type (objfile
, bits
, 1, name
);
16961 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16966 type
= builtin_type (arch
)->builtin_char16
;
16967 else if (bits
== 32)
16968 type
= builtin_type (arch
)->builtin_char32
;
16971 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
16973 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16975 return set_die_type (die
, type
, cu
);
16980 complaint (_("unsupported DW_AT_encoding: '%s'"),
16981 dwarf_type_encoding_name (encoding
));
16982 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16986 if (name
&& strcmp (name
, "char") == 0)
16987 TYPE_NOSIGN (type
) = 1;
16989 maybe_set_alignment (cu
, die
, type
);
16991 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
16993 return set_die_type (die
, type
, cu
);
16996 /* Parse dwarf attribute if it's a block, reference or constant and put the
16997 resulting value of the attribute into struct bound_prop.
16998 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17001 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17002 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17003 struct type
*default_type
)
17005 struct dwarf2_property_baton
*baton
;
17006 struct obstack
*obstack
17007 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17009 gdb_assert (default_type
!= NULL
);
17011 if (attr
== NULL
|| prop
== NULL
)
17014 if (attr
->form_is_block ())
17016 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17017 baton
->property_type
= default_type
;
17018 baton
->locexpr
.per_cu
= cu
->per_cu
;
17019 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17020 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17021 switch (attr
->name
)
17023 case DW_AT_string_length
:
17024 baton
->locexpr
.is_reference
= true;
17027 baton
->locexpr
.is_reference
= false;
17030 prop
->data
.baton
= baton
;
17031 prop
->kind
= PROP_LOCEXPR
;
17032 gdb_assert (prop
->data
.baton
!= NULL
);
17034 else if (attr
->form_is_ref ())
17036 struct dwarf2_cu
*target_cu
= cu
;
17037 struct die_info
*target_die
;
17038 struct attribute
*target_attr
;
17040 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17041 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17042 if (target_attr
== NULL
)
17043 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17045 if (target_attr
== NULL
)
17048 switch (target_attr
->name
)
17050 case DW_AT_location
:
17051 if (target_attr
->form_is_section_offset ())
17053 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17054 baton
->property_type
= die_type (target_die
, target_cu
);
17055 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17056 prop
->data
.baton
= baton
;
17057 prop
->kind
= PROP_LOCLIST
;
17058 gdb_assert (prop
->data
.baton
!= NULL
);
17060 else if (target_attr
->form_is_block ())
17062 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17063 baton
->property_type
= die_type (target_die
, target_cu
);
17064 baton
->locexpr
.per_cu
= cu
->per_cu
;
17065 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17066 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17067 baton
->locexpr
.is_reference
= true;
17068 prop
->data
.baton
= baton
;
17069 prop
->kind
= PROP_LOCEXPR
;
17070 gdb_assert (prop
->data
.baton
!= NULL
);
17074 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17075 "dynamic property");
17079 case DW_AT_data_member_location
:
17083 if (!handle_data_member_location (target_die
, target_cu
,
17087 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17088 baton
->property_type
= read_type_die (target_die
->parent
,
17090 baton
->offset_info
.offset
= offset
;
17091 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17092 prop
->data
.baton
= baton
;
17093 prop
->kind
= PROP_ADDR_OFFSET
;
17098 else if (attr
->form_is_constant ())
17100 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17101 prop
->kind
= PROP_CONST
;
17105 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17106 dwarf2_name (die
, cu
));
17116 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17118 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17119 struct type
*int_type
;
17121 /* Helper macro to examine the various builtin types. */
17122 #define TRY_TYPE(F) \
17123 int_type = (unsigned_p \
17124 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17125 : objfile_type (objfile)->builtin_ ## F); \
17126 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17133 TRY_TYPE (long_long
);
17137 gdb_assert_not_reached ("unable to find suitable integer type");
17143 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17145 int addr_size
= this->addr_size ();
17146 return int_type (addr_size
, unsigned_p
);
17149 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17150 present (which is valid) then compute the default type based on the
17151 compilation units address size. */
17153 static struct type
*
17154 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17156 struct type
*index_type
= die_type (die
, cu
);
17158 /* Dwarf-2 specifications explicitly allows to create subrange types
17159 without specifying a base type.
17160 In that case, the base type must be set to the type of
17161 the lower bound, upper bound or count, in that order, if any of these
17162 three attributes references an object that has a type.
17163 If no base type is found, the Dwarf-2 specifications say that
17164 a signed integer type of size equal to the size of an address should
17166 For the following C code: `extern char gdb_int [];'
17167 GCC produces an empty range DIE.
17168 FIXME: muller/2010-05-28: Possible references to object for low bound,
17169 high bound or count are not yet handled by this code. */
17170 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17171 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17176 /* Read the given DW_AT_subrange DIE. */
17178 static struct type
*
17179 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17181 struct type
*base_type
, *orig_base_type
;
17182 struct type
*range_type
;
17183 struct attribute
*attr
;
17184 struct dynamic_prop low
, high
;
17185 int low_default_is_valid
;
17186 int high_bound_is_count
= 0;
17188 ULONGEST negative_mask
;
17190 orig_base_type
= read_subrange_index_type (die
, cu
);
17192 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17193 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17194 creating the range type, but we use the result of check_typedef
17195 when examining properties of the type. */
17196 base_type
= check_typedef (orig_base_type
);
17198 /* The die_type call above may have already set the type for this DIE. */
17199 range_type
= get_die_type (die
, cu
);
17203 low
.kind
= PROP_CONST
;
17204 high
.kind
= PROP_CONST
;
17205 high
.data
.const_val
= 0;
17207 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17208 omitting DW_AT_lower_bound. */
17209 switch (cu
->language
)
17212 case language_cplus
:
17213 low
.data
.const_val
= 0;
17214 low_default_is_valid
= 1;
17216 case language_fortran
:
17217 low
.data
.const_val
= 1;
17218 low_default_is_valid
= 1;
17221 case language_objc
:
17222 case language_rust
:
17223 low
.data
.const_val
= 0;
17224 low_default_is_valid
= (cu
->header
.version
>= 4);
17228 case language_pascal
:
17229 low
.data
.const_val
= 1;
17230 low_default_is_valid
= (cu
->header
.version
>= 4);
17233 low
.data
.const_val
= 0;
17234 low_default_is_valid
= 0;
17238 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17239 if (attr
!= nullptr)
17240 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17241 else if (!low_default_is_valid
)
17242 complaint (_("Missing DW_AT_lower_bound "
17243 "- DIE at %s [in module %s]"),
17244 sect_offset_str (die
->sect_off
),
17245 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17247 struct attribute
*attr_ub
, *attr_count
;
17248 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17249 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17251 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17252 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17254 /* If bounds are constant do the final calculation here. */
17255 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17256 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17258 high_bound_is_count
= 1;
17262 if (attr_ub
!= NULL
)
17263 complaint (_("Unresolved DW_AT_upper_bound "
17264 "- DIE at %s [in module %s]"),
17265 sect_offset_str (die
->sect_off
),
17266 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17267 if (attr_count
!= NULL
)
17268 complaint (_("Unresolved DW_AT_count "
17269 "- DIE at %s [in module %s]"),
17270 sect_offset_str (die
->sect_off
),
17271 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17276 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17277 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17278 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17280 /* Normally, the DWARF producers are expected to use a signed
17281 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17282 But this is unfortunately not always the case, as witnessed
17283 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17284 is used instead. To work around that ambiguity, we treat
17285 the bounds as signed, and thus sign-extend their values, when
17286 the base type is signed. */
17288 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17289 if (low
.kind
== PROP_CONST
17290 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17291 low
.data
.const_val
|= negative_mask
;
17292 if (high
.kind
== PROP_CONST
17293 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17294 high
.data
.const_val
|= negative_mask
;
17296 /* Check for bit and byte strides. */
17297 struct dynamic_prop byte_stride_prop
;
17298 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17299 if (attr_byte_stride
!= nullptr)
17301 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17302 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17306 struct dynamic_prop bit_stride_prop
;
17307 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17308 if (attr_bit_stride
!= nullptr)
17310 /* It only makes sense to have either a bit or byte stride. */
17311 if (attr_byte_stride
!= nullptr)
17313 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17314 "- DIE at %s [in module %s]"),
17315 sect_offset_str (die
->sect_off
),
17316 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17317 attr_bit_stride
= nullptr;
17321 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17322 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17327 if (attr_byte_stride
!= nullptr
17328 || attr_bit_stride
!= nullptr)
17330 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17331 struct dynamic_prop
*stride
17332 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17335 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17336 &high
, bias
, stride
, byte_stride_p
);
17339 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17341 if (high_bound_is_count
)
17342 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17344 /* Ada expects an empty array on no boundary attributes. */
17345 if (attr
== NULL
&& cu
->language
!= language_ada
)
17346 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17348 name
= dwarf2_name (die
, cu
);
17350 TYPE_NAME (range_type
) = name
;
17352 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17353 if (attr
!= nullptr)
17354 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17356 maybe_set_alignment (cu
, die
, range_type
);
17358 set_die_type (die
, range_type
, cu
);
17360 /* set_die_type should be already done. */
17361 set_descriptive_type (range_type
, die
, cu
);
17366 static struct type
*
17367 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17371 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17373 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17375 /* In Ada, an unspecified type is typically used when the description
17376 of the type is deferred to a different unit. When encountering
17377 such a type, we treat it as a stub, and try to resolve it later on,
17379 if (cu
->language
== language_ada
)
17380 TYPE_STUB (type
) = 1;
17382 return set_die_type (die
, type
, cu
);
17385 /* Read a single die and all its descendents. Set the die's sibling
17386 field to NULL; set other fields in the die correctly, and set all
17387 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17388 location of the info_ptr after reading all of those dies. PARENT
17389 is the parent of the die in question. */
17391 static struct die_info
*
17392 read_die_and_children (const struct die_reader_specs
*reader
,
17393 const gdb_byte
*info_ptr
,
17394 const gdb_byte
**new_info_ptr
,
17395 struct die_info
*parent
)
17397 struct die_info
*die
;
17398 const gdb_byte
*cur_ptr
;
17400 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17403 *new_info_ptr
= cur_ptr
;
17406 store_in_ref_table (die
, reader
->cu
);
17408 if (die
->has_children
)
17409 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17413 *new_info_ptr
= cur_ptr
;
17416 die
->sibling
= NULL
;
17417 die
->parent
= parent
;
17421 /* Read a die, all of its descendents, and all of its siblings; set
17422 all of the fields of all of the dies correctly. Arguments are as
17423 in read_die_and_children. */
17425 static struct die_info
*
17426 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17427 const gdb_byte
*info_ptr
,
17428 const gdb_byte
**new_info_ptr
,
17429 struct die_info
*parent
)
17431 struct die_info
*first_die
, *last_sibling
;
17432 const gdb_byte
*cur_ptr
;
17434 cur_ptr
= info_ptr
;
17435 first_die
= last_sibling
= NULL
;
17439 struct die_info
*die
17440 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17444 *new_info_ptr
= cur_ptr
;
17451 last_sibling
->sibling
= die
;
17453 last_sibling
= die
;
17457 /* Read a die, all of its descendents, and all of its siblings; set
17458 all of the fields of all of the dies correctly. Arguments are as
17459 in read_die_and_children.
17460 This the main entry point for reading a DIE and all its children. */
17462 static struct die_info
*
17463 read_die_and_siblings (const struct die_reader_specs
*reader
,
17464 const gdb_byte
*info_ptr
,
17465 const gdb_byte
**new_info_ptr
,
17466 struct die_info
*parent
)
17468 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17469 new_info_ptr
, parent
);
17471 if (dwarf_die_debug
)
17473 fprintf_unfiltered (gdb_stdlog
,
17474 "Read die from %s@0x%x of %s:\n",
17475 reader
->die_section
->get_name (),
17476 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17477 bfd_get_filename (reader
->abfd
));
17478 dump_die (die
, dwarf_die_debug
);
17484 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17486 The caller is responsible for filling in the extra attributes
17487 and updating (*DIEP)->num_attrs.
17488 Set DIEP to point to a newly allocated die with its information,
17489 except for its child, sibling, and parent fields. */
17491 static const gdb_byte
*
17492 read_full_die_1 (const struct die_reader_specs
*reader
,
17493 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17494 int num_extra_attrs
)
17496 unsigned int abbrev_number
, bytes_read
, i
;
17497 struct abbrev_info
*abbrev
;
17498 struct die_info
*die
;
17499 struct dwarf2_cu
*cu
= reader
->cu
;
17500 bfd
*abfd
= reader
->abfd
;
17502 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17503 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17504 info_ptr
+= bytes_read
;
17505 if (!abbrev_number
)
17511 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17513 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17515 bfd_get_filename (abfd
));
17517 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17518 die
->sect_off
= sect_off
;
17519 die
->tag
= abbrev
->tag
;
17520 die
->abbrev
= abbrev_number
;
17521 die
->has_children
= abbrev
->has_children
;
17523 /* Make the result usable.
17524 The caller needs to update num_attrs after adding the extra
17526 die
->num_attrs
= abbrev
->num_attrs
;
17528 std::vector
<int> indexes_that_need_reprocess
;
17529 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17531 bool need_reprocess
;
17533 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17534 info_ptr
, &need_reprocess
);
17535 if (need_reprocess
)
17536 indexes_that_need_reprocess
.push_back (i
);
17539 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17540 if (attr
!= nullptr)
17541 cu
->str_offsets_base
= DW_UNSND (attr
);
17543 auto maybe_addr_base
= lookup_addr_base(die
);
17544 if (maybe_addr_base
.has_value ())
17545 cu
->addr_base
= *maybe_addr_base
;
17546 for (int index
: indexes_that_need_reprocess
)
17547 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17552 /* Read a die and all its attributes.
17553 Set DIEP to point to a newly allocated die with its information,
17554 except for its child, sibling, and parent fields. */
17556 static const gdb_byte
*
17557 read_full_die (const struct die_reader_specs
*reader
,
17558 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17560 const gdb_byte
*result
;
17562 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17564 if (dwarf_die_debug
)
17566 fprintf_unfiltered (gdb_stdlog
,
17567 "Read die from %s@0x%x of %s:\n",
17568 reader
->die_section
->get_name (),
17569 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17570 bfd_get_filename (reader
->abfd
));
17571 dump_die (*diep
, dwarf_die_debug
);
17578 /* Returns nonzero if TAG represents a type that we might generate a partial
17582 is_type_tag_for_partial (int tag
)
17587 /* Some types that would be reasonable to generate partial symbols for,
17588 that we don't at present. */
17589 case DW_TAG_array_type
:
17590 case DW_TAG_file_type
:
17591 case DW_TAG_ptr_to_member_type
:
17592 case DW_TAG_set_type
:
17593 case DW_TAG_string_type
:
17594 case DW_TAG_subroutine_type
:
17596 case DW_TAG_base_type
:
17597 case DW_TAG_class_type
:
17598 case DW_TAG_interface_type
:
17599 case DW_TAG_enumeration_type
:
17600 case DW_TAG_structure_type
:
17601 case DW_TAG_subrange_type
:
17602 case DW_TAG_typedef
:
17603 case DW_TAG_union_type
:
17610 /* Load all DIEs that are interesting for partial symbols into memory. */
17612 static struct partial_die_info
*
17613 load_partial_dies (const struct die_reader_specs
*reader
,
17614 const gdb_byte
*info_ptr
, int building_psymtab
)
17616 struct dwarf2_cu
*cu
= reader
->cu
;
17617 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17618 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17619 unsigned int bytes_read
;
17620 unsigned int load_all
= 0;
17621 int nesting_level
= 1;
17626 gdb_assert (cu
->per_cu
!= NULL
);
17627 if (cu
->per_cu
->load_all_dies
)
17631 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17635 &cu
->comp_unit_obstack
,
17636 hashtab_obstack_allocate
,
17637 dummy_obstack_deallocate
);
17641 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17643 /* A NULL abbrev means the end of a series of children. */
17644 if (abbrev
== NULL
)
17646 if (--nesting_level
== 0)
17649 info_ptr
+= bytes_read
;
17650 last_die
= parent_die
;
17651 parent_die
= parent_die
->die_parent
;
17655 /* Check for template arguments. We never save these; if
17656 they're seen, we just mark the parent, and go on our way. */
17657 if (parent_die
!= NULL
17658 && cu
->language
== language_cplus
17659 && (abbrev
->tag
== DW_TAG_template_type_param
17660 || abbrev
->tag
== DW_TAG_template_value_param
))
17662 parent_die
->has_template_arguments
= 1;
17666 /* We don't need a partial DIE for the template argument. */
17667 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17672 /* We only recurse into c++ subprograms looking for template arguments.
17673 Skip their other children. */
17675 && cu
->language
== language_cplus
17676 && parent_die
!= NULL
17677 && parent_die
->tag
== DW_TAG_subprogram
)
17679 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17683 /* Check whether this DIE is interesting enough to save. Normally
17684 we would not be interested in members here, but there may be
17685 later variables referencing them via DW_AT_specification (for
17686 static members). */
17688 && !is_type_tag_for_partial (abbrev
->tag
)
17689 && abbrev
->tag
!= DW_TAG_constant
17690 && abbrev
->tag
!= DW_TAG_enumerator
17691 && abbrev
->tag
!= DW_TAG_subprogram
17692 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17693 && abbrev
->tag
!= DW_TAG_lexical_block
17694 && abbrev
->tag
!= DW_TAG_variable
17695 && abbrev
->tag
!= DW_TAG_namespace
17696 && abbrev
->tag
!= DW_TAG_module
17697 && abbrev
->tag
!= DW_TAG_member
17698 && abbrev
->tag
!= DW_TAG_imported_unit
17699 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17701 /* Otherwise we skip to the next sibling, if any. */
17702 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17706 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17709 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17711 /* This two-pass algorithm for processing partial symbols has a
17712 high cost in cache pressure. Thus, handle some simple cases
17713 here which cover the majority of C partial symbols. DIEs
17714 which neither have specification tags in them, nor could have
17715 specification tags elsewhere pointing at them, can simply be
17716 processed and discarded.
17718 This segment is also optional; scan_partial_symbols and
17719 add_partial_symbol will handle these DIEs if we chain
17720 them in normally. When compilers which do not emit large
17721 quantities of duplicate debug information are more common,
17722 this code can probably be removed. */
17724 /* Any complete simple types at the top level (pretty much all
17725 of them, for a language without namespaces), can be processed
17727 if (parent_die
== NULL
17728 && pdi
.has_specification
== 0
17729 && pdi
.is_declaration
== 0
17730 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17731 || pdi
.tag
== DW_TAG_base_type
17732 || pdi
.tag
== DW_TAG_subrange_type
))
17734 if (building_psymtab
&& pdi
.name
!= NULL
)
17735 add_psymbol_to_list (pdi
.name
, false,
17736 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17737 psymbol_placement::STATIC
,
17738 0, cu
->language
, objfile
);
17739 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17743 /* The exception for DW_TAG_typedef with has_children above is
17744 a workaround of GCC PR debug/47510. In the case of this complaint
17745 type_name_or_error will error on such types later.
17747 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17748 it could not find the child DIEs referenced later, this is checked
17749 above. In correct DWARF DW_TAG_typedef should have no children. */
17751 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17752 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17753 "- DIE at %s [in module %s]"),
17754 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17756 /* If we're at the second level, and we're an enumerator, and
17757 our parent has no specification (meaning possibly lives in a
17758 namespace elsewhere), then we can add the partial symbol now
17759 instead of queueing it. */
17760 if (pdi
.tag
== DW_TAG_enumerator
17761 && parent_die
!= NULL
17762 && parent_die
->die_parent
== NULL
17763 && parent_die
->tag
== DW_TAG_enumeration_type
17764 && parent_die
->has_specification
== 0)
17766 if (pdi
.name
== NULL
)
17767 complaint (_("malformed enumerator DIE ignored"));
17768 else if (building_psymtab
)
17769 add_psymbol_to_list (pdi
.name
, false,
17770 VAR_DOMAIN
, LOC_CONST
, -1,
17771 cu
->language
== language_cplus
17772 ? psymbol_placement::GLOBAL
17773 : psymbol_placement::STATIC
,
17774 0, cu
->language
, objfile
);
17776 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17780 struct partial_die_info
*part_die
17781 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17783 /* We'll save this DIE so link it in. */
17784 part_die
->die_parent
= parent_die
;
17785 part_die
->die_sibling
= NULL
;
17786 part_die
->die_child
= NULL
;
17788 if (last_die
&& last_die
== parent_die
)
17789 last_die
->die_child
= part_die
;
17791 last_die
->die_sibling
= part_die
;
17793 last_die
= part_die
;
17795 if (first_die
== NULL
)
17796 first_die
= part_die
;
17798 /* Maybe add the DIE to the hash table. Not all DIEs that we
17799 find interesting need to be in the hash table, because we
17800 also have the parent/sibling/child chains; only those that we
17801 might refer to by offset later during partial symbol reading.
17803 For now this means things that might have be the target of a
17804 DW_AT_specification, DW_AT_abstract_origin, or
17805 DW_AT_extension. DW_AT_extension will refer only to
17806 namespaces; DW_AT_abstract_origin refers to functions (and
17807 many things under the function DIE, but we do not recurse
17808 into function DIEs during partial symbol reading) and
17809 possibly variables as well; DW_AT_specification refers to
17810 declarations. Declarations ought to have the DW_AT_declaration
17811 flag. It happens that GCC forgets to put it in sometimes, but
17812 only for functions, not for types.
17814 Adding more things than necessary to the hash table is harmless
17815 except for the performance cost. Adding too few will result in
17816 wasted time in find_partial_die, when we reread the compilation
17817 unit with load_all_dies set. */
17820 || abbrev
->tag
== DW_TAG_constant
17821 || abbrev
->tag
== DW_TAG_subprogram
17822 || abbrev
->tag
== DW_TAG_variable
17823 || abbrev
->tag
== DW_TAG_namespace
17824 || part_die
->is_declaration
)
17828 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17829 to_underlying (part_die
->sect_off
),
17834 /* For some DIEs we want to follow their children (if any). For C
17835 we have no reason to follow the children of structures; for other
17836 languages we have to, so that we can get at method physnames
17837 to infer fully qualified class names, for DW_AT_specification,
17838 and for C++ template arguments. For C++, we also look one level
17839 inside functions to find template arguments (if the name of the
17840 function does not already contain the template arguments).
17842 For Ada and Fortran, we need to scan the children of subprograms
17843 and lexical blocks as well because these languages allow the
17844 definition of nested entities that could be interesting for the
17845 debugger, such as nested subprograms for instance. */
17846 if (last_die
->has_children
17848 || last_die
->tag
== DW_TAG_namespace
17849 || last_die
->tag
== DW_TAG_module
17850 || last_die
->tag
== DW_TAG_enumeration_type
17851 || (cu
->language
== language_cplus
17852 && last_die
->tag
== DW_TAG_subprogram
17853 && (last_die
->name
== NULL
17854 || strchr (last_die
->name
, '<') == NULL
))
17855 || (cu
->language
!= language_c
17856 && (last_die
->tag
== DW_TAG_class_type
17857 || last_die
->tag
== DW_TAG_interface_type
17858 || last_die
->tag
== DW_TAG_structure_type
17859 || last_die
->tag
== DW_TAG_union_type
))
17860 || ((cu
->language
== language_ada
17861 || cu
->language
== language_fortran
)
17862 && (last_die
->tag
== DW_TAG_subprogram
17863 || last_die
->tag
== DW_TAG_lexical_block
))))
17866 parent_die
= last_die
;
17870 /* Otherwise we skip to the next sibling, if any. */
17871 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17873 /* Back to the top, do it again. */
17877 partial_die_info::partial_die_info (sect_offset sect_off_
,
17878 struct abbrev_info
*abbrev
)
17879 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17883 /* Read a minimal amount of information into the minimal die structure.
17884 INFO_PTR should point just after the initial uleb128 of a DIE. */
17887 partial_die_info::read (const struct die_reader_specs
*reader
,
17888 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17890 struct dwarf2_cu
*cu
= reader
->cu
;
17891 struct dwarf2_per_objfile
*dwarf2_per_objfile
17892 = cu
->per_cu
->dwarf2_per_objfile
;
17894 int has_low_pc_attr
= 0;
17895 int has_high_pc_attr
= 0;
17896 int high_pc_relative
= 0;
17898 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17899 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17901 bool need_reprocess
;
17902 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17903 info_ptr
, &need_reprocess
);
17904 /* String and address offsets that need to do the reprocessing have
17905 already been read at this point, so there is no need to wait until
17906 the loop terminates to do the reprocessing. */
17907 if (need_reprocess
)
17908 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17909 attribute
&attr
= attr_vec
[i
];
17910 /* Store the data if it is of an attribute we want to keep in a
17911 partial symbol table. */
17917 case DW_TAG_compile_unit
:
17918 case DW_TAG_partial_unit
:
17919 case DW_TAG_type_unit
:
17920 /* Compilation units have a DW_AT_name that is a filename, not
17921 a source language identifier. */
17922 case DW_TAG_enumeration_type
:
17923 case DW_TAG_enumerator
:
17924 /* These tags always have simple identifiers already; no need
17925 to canonicalize them. */
17926 name
= DW_STRING (&attr
);
17930 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17933 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
17938 case DW_AT_linkage_name
:
17939 case DW_AT_MIPS_linkage_name
:
17940 /* Note that both forms of linkage name might appear. We
17941 assume they will be the same, and we only store the last
17943 linkage_name
= DW_STRING (&attr
);
17946 has_low_pc_attr
= 1;
17947 lowpc
= attr
.value_as_address ();
17949 case DW_AT_high_pc
:
17950 has_high_pc_attr
= 1;
17951 highpc
= attr
.value_as_address ();
17952 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17953 high_pc_relative
= 1;
17955 case DW_AT_location
:
17956 /* Support the .debug_loc offsets. */
17957 if (attr
.form_is_block ())
17959 d
.locdesc
= DW_BLOCK (&attr
);
17961 else if (attr
.form_is_section_offset ())
17963 dwarf2_complex_location_expr_complaint ();
17967 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17968 "partial symbol information");
17971 case DW_AT_external
:
17972 is_external
= DW_UNSND (&attr
);
17974 case DW_AT_declaration
:
17975 is_declaration
= DW_UNSND (&attr
);
17980 case DW_AT_abstract_origin
:
17981 case DW_AT_specification
:
17982 case DW_AT_extension
:
17983 has_specification
= 1;
17984 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
17985 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
17986 || cu
->per_cu
->is_dwz
);
17988 case DW_AT_sibling
:
17989 /* Ignore absolute siblings, they might point outside of
17990 the current compile unit. */
17991 if (attr
.form
== DW_FORM_ref_addr
)
17992 complaint (_("ignoring absolute DW_AT_sibling"));
17995 const gdb_byte
*buffer
= reader
->buffer
;
17996 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
17997 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
17999 if (sibling_ptr
< info_ptr
)
18000 complaint (_("DW_AT_sibling points backwards"));
18001 else if (sibling_ptr
> reader
->buffer_end
)
18002 reader
->die_section
->overflow_complaint ();
18004 sibling
= sibling_ptr
;
18007 case DW_AT_byte_size
:
18010 case DW_AT_const_value
:
18011 has_const_value
= 1;
18013 case DW_AT_calling_convention
:
18014 /* DWARF doesn't provide a way to identify a program's source-level
18015 entry point. DW_AT_calling_convention attributes are only meant
18016 to describe functions' calling conventions.
18018 However, because it's a necessary piece of information in
18019 Fortran, and before DWARF 4 DW_CC_program was the only
18020 piece of debugging information whose definition refers to
18021 a 'main program' at all, several compilers marked Fortran
18022 main programs with DW_CC_program --- even when those
18023 functions use the standard calling conventions.
18025 Although DWARF now specifies a way to provide this
18026 information, we support this practice for backward
18028 if (DW_UNSND (&attr
) == DW_CC_program
18029 && cu
->language
== language_fortran
)
18030 main_subprogram
= 1;
18033 if (DW_UNSND (&attr
) == DW_INL_inlined
18034 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18035 may_be_inlined
= 1;
18039 if (tag
== DW_TAG_imported_unit
)
18041 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18042 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18043 || cu
->per_cu
->is_dwz
);
18047 case DW_AT_main_subprogram
:
18048 main_subprogram
= DW_UNSND (&attr
);
18053 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18054 but that requires a full DIE, so instead we just
18056 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18057 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18058 + (need_ranges_base
18062 /* Value of the DW_AT_ranges attribute is the offset in the
18063 .debug_ranges section. */
18064 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18075 /* For Ada, if both the name and the linkage name appear, we prefer
18076 the latter. This lets "catch exception" work better, regardless
18077 of the order in which the name and linkage name were emitted.
18078 Really, though, this is just a workaround for the fact that gdb
18079 doesn't store both the name and the linkage name. */
18080 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18081 name
= linkage_name
;
18083 if (high_pc_relative
)
18086 if (has_low_pc_attr
&& has_high_pc_attr
)
18088 /* When using the GNU linker, .gnu.linkonce. sections are used to
18089 eliminate duplicate copies of functions and vtables and such.
18090 The linker will arbitrarily choose one and discard the others.
18091 The AT_*_pc values for such functions refer to local labels in
18092 these sections. If the section from that file was discarded, the
18093 labels are not in the output, so the relocs get a value of 0.
18094 If this is a discarded function, mark the pc bounds as invalid,
18095 so that GDB will ignore it. */
18096 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18098 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18099 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18101 complaint (_("DW_AT_low_pc %s is zero "
18102 "for DIE at %s [in module %s]"),
18103 paddress (gdbarch
, lowpc
),
18104 sect_offset_str (sect_off
),
18105 objfile_name (objfile
));
18107 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18108 else if (lowpc
>= highpc
)
18110 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18111 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18113 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18114 "for DIE at %s [in module %s]"),
18115 paddress (gdbarch
, lowpc
),
18116 paddress (gdbarch
, highpc
),
18117 sect_offset_str (sect_off
),
18118 objfile_name (objfile
));
18127 /* Find a cached partial DIE at OFFSET in CU. */
18129 struct partial_die_info
*
18130 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18132 struct partial_die_info
*lookup_die
= NULL
;
18133 struct partial_die_info
part_die (sect_off
);
18135 lookup_die
= ((struct partial_die_info
*)
18136 htab_find_with_hash (partial_dies
, &part_die
,
18137 to_underlying (sect_off
)));
18142 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18143 except in the case of .debug_types DIEs which do not reference
18144 outside their CU (they do however referencing other types via
18145 DW_FORM_ref_sig8). */
18147 static const struct cu_partial_die_info
18148 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18150 struct dwarf2_per_objfile
*dwarf2_per_objfile
18151 = cu
->per_cu
->dwarf2_per_objfile
;
18152 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18153 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18154 struct partial_die_info
*pd
= NULL
;
18156 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18157 && cu
->header
.offset_in_cu_p (sect_off
))
18159 pd
= cu
->find_partial_die (sect_off
);
18162 /* We missed recording what we needed.
18163 Load all dies and try again. */
18164 per_cu
= cu
->per_cu
;
18168 /* TUs don't reference other CUs/TUs (except via type signatures). */
18169 if (cu
->per_cu
->is_debug_types
)
18171 error (_("Dwarf Error: Type Unit at offset %s contains"
18172 " external reference to offset %s [in module %s].\n"),
18173 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18174 bfd_get_filename (objfile
->obfd
));
18176 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18177 dwarf2_per_objfile
);
18179 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18180 load_partial_comp_unit (per_cu
);
18182 per_cu
->cu
->last_used
= 0;
18183 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18186 /* If we didn't find it, and not all dies have been loaded,
18187 load them all and try again. */
18189 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18191 per_cu
->load_all_dies
= 1;
18193 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18194 THIS_CU->cu may already be in use. So we can't just free it and
18195 replace its DIEs with the ones we read in. Instead, we leave those
18196 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18197 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18199 load_partial_comp_unit (per_cu
);
18201 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18205 internal_error (__FILE__
, __LINE__
,
18206 _("could not find partial DIE %s "
18207 "in cache [from module %s]\n"),
18208 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18209 return { per_cu
->cu
, pd
};
18212 /* See if we can figure out if the class lives in a namespace. We do
18213 this by looking for a member function; its demangled name will
18214 contain namespace info, if there is any. */
18217 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18218 struct dwarf2_cu
*cu
)
18220 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18221 what template types look like, because the demangler
18222 frequently doesn't give the same name as the debug info. We
18223 could fix this by only using the demangled name to get the
18224 prefix (but see comment in read_structure_type). */
18226 struct partial_die_info
*real_pdi
;
18227 struct partial_die_info
*child_pdi
;
18229 /* If this DIE (this DIE's specification, if any) has a parent, then
18230 we should not do this. We'll prepend the parent's fully qualified
18231 name when we create the partial symbol. */
18233 real_pdi
= struct_pdi
;
18234 while (real_pdi
->has_specification
)
18236 auto res
= find_partial_die (real_pdi
->spec_offset
,
18237 real_pdi
->spec_is_dwz
, cu
);
18238 real_pdi
= res
.pdi
;
18242 if (real_pdi
->die_parent
!= NULL
)
18245 for (child_pdi
= struct_pdi
->die_child
;
18247 child_pdi
= child_pdi
->die_sibling
)
18249 if (child_pdi
->tag
== DW_TAG_subprogram
18250 && child_pdi
->linkage_name
!= NULL
)
18252 gdb::unique_xmalloc_ptr
<char> actual_class_name
18253 (language_class_name_from_physname (cu
->language_defn
,
18254 child_pdi
->linkage_name
));
18255 if (actual_class_name
!= NULL
)
18257 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18258 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18266 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18268 /* Once we've fixed up a die, there's no point in doing so again.
18269 This also avoids a memory leak if we were to call
18270 guess_partial_die_structure_name multiple times. */
18274 /* If we found a reference attribute and the DIE has no name, try
18275 to find a name in the referred to DIE. */
18277 if (name
== NULL
&& has_specification
)
18279 struct partial_die_info
*spec_die
;
18281 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18282 spec_die
= res
.pdi
;
18285 spec_die
->fixup (cu
);
18287 if (spec_die
->name
)
18289 name
= spec_die
->name
;
18291 /* Copy DW_AT_external attribute if it is set. */
18292 if (spec_die
->is_external
)
18293 is_external
= spec_die
->is_external
;
18297 /* Set default names for some unnamed DIEs. */
18299 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18300 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18302 /* If there is no parent die to provide a namespace, and there are
18303 children, see if we can determine the namespace from their linkage
18305 if (cu
->language
== language_cplus
18306 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18307 && die_parent
== NULL
18309 && (tag
== DW_TAG_class_type
18310 || tag
== DW_TAG_structure_type
18311 || tag
== DW_TAG_union_type
))
18312 guess_partial_die_structure_name (this, cu
);
18314 /* GCC might emit a nameless struct or union that has a linkage
18315 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18317 && (tag
== DW_TAG_class_type
18318 || tag
== DW_TAG_interface_type
18319 || tag
== DW_TAG_structure_type
18320 || tag
== DW_TAG_union_type
)
18321 && linkage_name
!= NULL
)
18323 gdb::unique_xmalloc_ptr
<char> demangled
18324 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18325 if (demangled
!= nullptr)
18329 /* Strip any leading namespaces/classes, keep only the base name.
18330 DW_AT_name for named DIEs does not contain the prefixes. */
18331 base
= strrchr (demangled
.get (), ':');
18332 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18335 base
= demangled
.get ();
18337 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18338 name
= objfile
->intern (base
);
18345 /* Process the attributes that had to be skipped in the first round. These
18346 attributes are the ones that need str_offsets_base or addr_base attributes.
18347 They could not have been processed in the first round, because at the time
18348 the values of str_offsets_base or addr_base may not have been known. */
18349 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18350 struct attribute
*attr
)
18352 struct dwarf2_cu
*cu
= reader
->cu
;
18353 switch (attr
->form
)
18355 case DW_FORM_addrx
:
18356 case DW_FORM_GNU_addr_index
:
18357 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18360 case DW_FORM_strx1
:
18361 case DW_FORM_strx2
:
18362 case DW_FORM_strx3
:
18363 case DW_FORM_strx4
:
18364 case DW_FORM_GNU_str_index
:
18366 unsigned int str_index
= DW_UNSND (attr
);
18367 if (reader
->dwo_file
!= NULL
)
18369 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18370 DW_STRING_IS_CANONICAL (attr
) = 0;
18374 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18375 DW_STRING_IS_CANONICAL (attr
) = 0;
18380 gdb_assert_not_reached (_("Unexpected DWARF form."));
18384 /* Read an attribute value described by an attribute form. */
18386 static const gdb_byte
*
18387 read_attribute_value (const struct die_reader_specs
*reader
,
18388 struct attribute
*attr
, unsigned form
,
18389 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18390 bool *need_reprocess
)
18392 struct dwarf2_cu
*cu
= reader
->cu
;
18393 struct dwarf2_per_objfile
*dwarf2_per_objfile
18394 = cu
->per_cu
->dwarf2_per_objfile
;
18395 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18396 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18397 bfd
*abfd
= reader
->abfd
;
18398 struct comp_unit_head
*cu_header
= &cu
->header
;
18399 unsigned int bytes_read
;
18400 struct dwarf_block
*blk
;
18401 *need_reprocess
= false;
18403 attr
->form
= (enum dwarf_form
) form
;
18406 case DW_FORM_ref_addr
:
18407 if (cu
->header
.version
== 2)
18408 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18411 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18413 info_ptr
+= bytes_read
;
18415 case DW_FORM_GNU_ref_alt
:
18416 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18417 info_ptr
+= bytes_read
;
18420 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18421 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18422 info_ptr
+= bytes_read
;
18424 case DW_FORM_block2
:
18425 blk
= dwarf_alloc_block (cu
);
18426 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18428 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18429 info_ptr
+= blk
->size
;
18430 DW_BLOCK (attr
) = blk
;
18432 case DW_FORM_block4
:
18433 blk
= dwarf_alloc_block (cu
);
18434 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18436 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18437 info_ptr
+= blk
->size
;
18438 DW_BLOCK (attr
) = blk
;
18440 case DW_FORM_data2
:
18441 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18444 case DW_FORM_data4
:
18445 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18448 case DW_FORM_data8
:
18449 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18452 case DW_FORM_data16
:
18453 blk
= dwarf_alloc_block (cu
);
18455 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18457 DW_BLOCK (attr
) = blk
;
18459 case DW_FORM_sec_offset
:
18460 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18461 info_ptr
+= bytes_read
;
18463 case DW_FORM_string
:
18464 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18465 DW_STRING_IS_CANONICAL (attr
) = 0;
18466 info_ptr
+= bytes_read
;
18469 if (!cu
->per_cu
->is_dwz
)
18471 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18472 abfd
, info_ptr
, cu_header
,
18474 DW_STRING_IS_CANONICAL (attr
) = 0;
18475 info_ptr
+= bytes_read
;
18479 case DW_FORM_line_strp
:
18480 if (!cu
->per_cu
->is_dwz
)
18483 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18485 DW_STRING_IS_CANONICAL (attr
) = 0;
18486 info_ptr
+= bytes_read
;
18490 case DW_FORM_GNU_strp_alt
:
18492 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18493 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18496 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18497 DW_STRING_IS_CANONICAL (attr
) = 0;
18498 info_ptr
+= bytes_read
;
18501 case DW_FORM_exprloc
:
18502 case DW_FORM_block
:
18503 blk
= dwarf_alloc_block (cu
);
18504 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18505 info_ptr
+= bytes_read
;
18506 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18507 info_ptr
+= blk
->size
;
18508 DW_BLOCK (attr
) = blk
;
18510 case DW_FORM_block1
:
18511 blk
= dwarf_alloc_block (cu
);
18512 blk
->size
= read_1_byte (abfd
, info_ptr
);
18514 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18515 info_ptr
+= blk
->size
;
18516 DW_BLOCK (attr
) = blk
;
18518 case DW_FORM_data1
:
18519 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18523 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18526 case DW_FORM_flag_present
:
18527 DW_UNSND (attr
) = 1;
18529 case DW_FORM_sdata
:
18530 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18531 info_ptr
+= bytes_read
;
18533 case DW_FORM_udata
:
18534 case DW_FORM_rnglistx
:
18535 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18536 info_ptr
+= bytes_read
;
18539 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18540 + read_1_byte (abfd
, info_ptr
));
18544 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18545 + read_2_bytes (abfd
, info_ptr
));
18549 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18550 + read_4_bytes (abfd
, info_ptr
));
18554 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18555 + read_8_bytes (abfd
, info_ptr
));
18558 case DW_FORM_ref_sig8
:
18559 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18562 case DW_FORM_ref_udata
:
18563 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18564 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18565 info_ptr
+= bytes_read
;
18567 case DW_FORM_indirect
:
18568 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18569 info_ptr
+= bytes_read
;
18570 if (form
== DW_FORM_implicit_const
)
18572 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18573 info_ptr
+= bytes_read
;
18575 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18576 info_ptr
, need_reprocess
);
18578 case DW_FORM_implicit_const
:
18579 DW_SND (attr
) = implicit_const
;
18581 case DW_FORM_addrx
:
18582 case DW_FORM_GNU_addr_index
:
18583 *need_reprocess
= true;
18584 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18585 info_ptr
+= bytes_read
;
18588 case DW_FORM_strx1
:
18589 case DW_FORM_strx2
:
18590 case DW_FORM_strx3
:
18591 case DW_FORM_strx4
:
18592 case DW_FORM_GNU_str_index
:
18594 ULONGEST str_index
;
18595 if (form
== DW_FORM_strx1
)
18597 str_index
= read_1_byte (abfd
, info_ptr
);
18600 else if (form
== DW_FORM_strx2
)
18602 str_index
= read_2_bytes (abfd
, info_ptr
);
18605 else if (form
== DW_FORM_strx3
)
18607 str_index
= read_3_bytes (abfd
, info_ptr
);
18610 else if (form
== DW_FORM_strx4
)
18612 str_index
= read_4_bytes (abfd
, info_ptr
);
18617 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18618 info_ptr
+= bytes_read
;
18620 *need_reprocess
= true;
18621 DW_UNSND (attr
) = str_index
;
18625 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18626 dwarf_form_name (form
),
18627 bfd_get_filename (abfd
));
18631 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18632 attr
->form
= DW_FORM_GNU_ref_alt
;
18634 /* We have seen instances where the compiler tried to emit a byte
18635 size attribute of -1 which ended up being encoded as an unsigned
18636 0xffffffff. Although 0xffffffff is technically a valid size value,
18637 an object of this size seems pretty unlikely so we can relatively
18638 safely treat these cases as if the size attribute was invalid and
18639 treat them as zero by default. */
18640 if (attr
->name
== DW_AT_byte_size
18641 && form
== DW_FORM_data4
18642 && DW_UNSND (attr
) >= 0xffffffff)
18645 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18646 hex_string (DW_UNSND (attr
)));
18647 DW_UNSND (attr
) = 0;
18653 /* Read an attribute described by an abbreviated attribute. */
18655 static const gdb_byte
*
18656 read_attribute (const struct die_reader_specs
*reader
,
18657 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18658 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18660 attr
->name
= abbrev
->name
;
18661 return read_attribute_value (reader
, attr
, abbrev
->form
,
18662 abbrev
->implicit_const
, info_ptr
,
18666 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18668 static const char *
18669 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18670 LONGEST str_offset
)
18672 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18673 str_offset
, "DW_FORM_strp");
18676 /* Return pointer to string at .debug_str offset as read from BUF.
18677 BUF is assumed to be in a compilation unit described by CU_HEADER.
18678 Return *BYTES_READ_PTR count of bytes read from BUF. */
18680 static const char *
18681 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18682 const gdb_byte
*buf
,
18683 const struct comp_unit_head
*cu_header
,
18684 unsigned int *bytes_read_ptr
)
18686 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18688 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18694 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18695 const struct comp_unit_head
*cu_header
,
18696 unsigned int *bytes_read_ptr
)
18698 bfd
*abfd
= objfile
->obfd
;
18699 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18701 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18704 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18705 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18706 ADDR_SIZE is the size of addresses from the CU header. */
18709 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18710 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18713 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18714 bfd
*abfd
= objfile
->obfd
;
18715 const gdb_byte
*info_ptr
;
18716 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18718 dwarf2_per_objfile
->addr
.read (objfile
);
18719 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18720 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18721 objfile_name (objfile
));
18722 if (addr_base_or_zero
+ addr_index
* addr_size
18723 >= dwarf2_per_objfile
->addr
.size
)
18724 error (_("DW_FORM_addr_index pointing outside of "
18725 ".debug_addr section [in module %s]"),
18726 objfile_name (objfile
));
18727 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18728 + addr_base_or_zero
+ addr_index
* addr_size
);
18729 if (addr_size
== 4)
18730 return bfd_get_32 (abfd
, info_ptr
);
18732 return bfd_get_64 (abfd
, info_ptr
);
18735 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18738 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18740 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18741 cu
->addr_base
, cu
->header
.addr_size
);
18744 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18747 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18748 unsigned int *bytes_read
)
18750 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18751 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18753 return read_addr_index (cu
, addr_index
);
18759 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18761 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18762 struct dwarf2_cu
*cu
= per_cu
->cu
;
18763 gdb::optional
<ULONGEST
> addr_base
;
18766 /* We need addr_base and addr_size.
18767 If we don't have PER_CU->cu, we have to get it.
18768 Nasty, but the alternative is storing the needed info in PER_CU,
18769 which at this point doesn't seem justified: it's not clear how frequently
18770 it would get used and it would increase the size of every PER_CU.
18771 Entry points like dwarf2_per_cu_addr_size do a similar thing
18772 so we're not in uncharted territory here.
18773 Alas we need to be a bit more complicated as addr_base is contained
18776 We don't need to read the entire CU(/TU).
18777 We just need the header and top level die.
18779 IWBN to use the aging mechanism to let us lazily later discard the CU.
18780 For now we skip this optimization. */
18784 addr_base
= cu
->addr_base
;
18785 addr_size
= cu
->header
.addr_size
;
18789 cutu_reader
reader (per_cu
, NULL
, 0, false);
18790 addr_base
= reader
.cu
->addr_base
;
18791 addr_size
= reader
.cu
->header
.addr_size
;
18794 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18798 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18799 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18802 static const char *
18803 read_str_index (struct dwarf2_cu
*cu
,
18804 struct dwarf2_section_info
*str_section
,
18805 struct dwarf2_section_info
*str_offsets_section
,
18806 ULONGEST str_offsets_base
, ULONGEST str_index
)
18808 struct dwarf2_per_objfile
*dwarf2_per_objfile
18809 = cu
->per_cu
->dwarf2_per_objfile
;
18810 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18811 const char *objf_name
= objfile_name (objfile
);
18812 bfd
*abfd
= objfile
->obfd
;
18813 const gdb_byte
*info_ptr
;
18814 ULONGEST str_offset
;
18815 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18817 str_section
->read (objfile
);
18818 str_offsets_section
->read (objfile
);
18819 if (str_section
->buffer
== NULL
)
18820 error (_("%s used without %s section"
18821 " in CU at offset %s [in module %s]"),
18822 form_name
, str_section
->get_name (),
18823 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18824 if (str_offsets_section
->buffer
== NULL
)
18825 error (_("%s used without %s section"
18826 " in CU at offset %s [in module %s]"),
18827 form_name
, str_section
->get_name (),
18828 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18829 info_ptr
= (str_offsets_section
->buffer
18831 + str_index
* cu
->header
.offset_size
);
18832 if (cu
->header
.offset_size
== 4)
18833 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18835 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18836 if (str_offset
>= str_section
->size
)
18837 error (_("Offset from %s pointing outside of"
18838 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18839 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18840 return (const char *) (str_section
->buffer
+ str_offset
);
18843 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18845 static const char *
18846 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18848 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18849 ? reader
->cu
->header
.addr_size
: 0;
18850 return read_str_index (reader
->cu
,
18851 &reader
->dwo_file
->sections
.str
,
18852 &reader
->dwo_file
->sections
.str_offsets
,
18853 str_offsets_base
, str_index
);
18856 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18858 static const char *
18859 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18861 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18862 const char *objf_name
= objfile_name (objfile
);
18863 static const char form_name
[] = "DW_FORM_GNU_str_index";
18864 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18866 if (!cu
->str_offsets_base
.has_value ())
18867 error (_("%s used in Fission stub without %s"
18868 " in CU at offset 0x%lx [in module %s]"),
18869 form_name
, str_offsets_attr_name
,
18870 (long) cu
->header
.offset_size
, objf_name
);
18872 return read_str_index (cu
,
18873 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18874 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18875 *cu
->str_offsets_base
, str_index
);
18878 /* Return the length of an LEB128 number in BUF. */
18881 leb128_size (const gdb_byte
*buf
)
18883 const gdb_byte
*begin
= buf
;
18889 if ((byte
& 128) == 0)
18890 return buf
- begin
;
18895 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
18904 cu
->language
= language_c
;
18907 case DW_LANG_C_plus_plus
:
18908 case DW_LANG_C_plus_plus_11
:
18909 case DW_LANG_C_plus_plus_14
:
18910 cu
->language
= language_cplus
;
18913 cu
->language
= language_d
;
18915 case DW_LANG_Fortran77
:
18916 case DW_LANG_Fortran90
:
18917 case DW_LANG_Fortran95
:
18918 case DW_LANG_Fortran03
:
18919 case DW_LANG_Fortran08
:
18920 cu
->language
= language_fortran
;
18923 cu
->language
= language_go
;
18925 case DW_LANG_Mips_Assembler
:
18926 cu
->language
= language_asm
;
18928 case DW_LANG_Ada83
:
18929 case DW_LANG_Ada95
:
18930 cu
->language
= language_ada
;
18932 case DW_LANG_Modula2
:
18933 cu
->language
= language_m2
;
18935 case DW_LANG_Pascal83
:
18936 cu
->language
= language_pascal
;
18939 cu
->language
= language_objc
;
18942 case DW_LANG_Rust_old
:
18943 cu
->language
= language_rust
;
18945 case DW_LANG_Cobol74
:
18946 case DW_LANG_Cobol85
:
18948 cu
->language
= language_minimal
;
18951 cu
->language_defn
= language_def (cu
->language
);
18954 /* Return the named attribute or NULL if not there. */
18956 static struct attribute
*
18957 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18962 struct attribute
*spec
= NULL
;
18964 for (i
= 0; i
< die
->num_attrs
; ++i
)
18966 if (die
->attrs
[i
].name
== name
)
18967 return &die
->attrs
[i
];
18968 if (die
->attrs
[i
].name
== DW_AT_specification
18969 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
18970 spec
= &die
->attrs
[i
];
18976 die
= follow_die_ref (die
, spec
, &cu
);
18982 /* Return the string associated with a string-typed attribute, or NULL if it
18983 is either not found or is of an incorrect type. */
18985 static const char *
18986 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18988 struct attribute
*attr
;
18989 const char *str
= NULL
;
18991 attr
= dwarf2_attr (die
, name
, cu
);
18995 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
18996 || attr
->form
== DW_FORM_string
18997 || attr
->form
== DW_FORM_strx
18998 || attr
->form
== DW_FORM_strx1
18999 || attr
->form
== DW_FORM_strx2
19000 || attr
->form
== DW_FORM_strx3
19001 || attr
->form
== DW_FORM_strx4
19002 || attr
->form
== DW_FORM_GNU_str_index
19003 || attr
->form
== DW_FORM_GNU_strp_alt
)
19004 str
= DW_STRING (attr
);
19006 complaint (_("string type expected for attribute %s for "
19007 "DIE at %s in module %s"),
19008 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19009 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19015 /* Return the dwo name or NULL if not present. If present, it is in either
19016 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19017 static const char *
19018 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19020 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19021 if (dwo_name
== nullptr)
19022 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19026 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19027 and holds a non-zero value. This function should only be used for
19028 DW_FORM_flag or DW_FORM_flag_present attributes. */
19031 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19033 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19035 return (attr
&& DW_UNSND (attr
));
19039 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19041 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19042 which value is non-zero. However, we have to be careful with
19043 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19044 (via dwarf2_flag_true_p) follows this attribute. So we may
19045 end up accidently finding a declaration attribute that belongs
19046 to a different DIE referenced by the specification attribute,
19047 even though the given DIE does not have a declaration attribute. */
19048 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19049 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19052 /* Return the die giving the specification for DIE, if there is
19053 one. *SPEC_CU is the CU containing DIE on input, and the CU
19054 containing the return value on output. If there is no
19055 specification, but there is an abstract origin, that is
19058 static struct die_info
*
19059 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19061 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19064 if (spec_attr
== NULL
)
19065 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19067 if (spec_attr
== NULL
)
19070 return follow_die_ref (die
, spec_attr
, spec_cu
);
19073 /* Stub for free_line_header to match void * callback types. */
19076 free_line_header_voidp (void *arg
)
19078 struct line_header
*lh
= (struct line_header
*) arg
;
19083 /* A convenience function to find the proper .debug_line section for a CU. */
19085 static struct dwarf2_section_info
*
19086 get_debug_line_section (struct dwarf2_cu
*cu
)
19088 struct dwarf2_section_info
*section
;
19089 struct dwarf2_per_objfile
*dwarf2_per_objfile
19090 = cu
->per_cu
->dwarf2_per_objfile
;
19092 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19094 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19095 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19096 else if (cu
->per_cu
->is_dwz
)
19098 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19100 section
= &dwz
->line
;
19103 section
= &dwarf2_per_objfile
->line
;
19108 /* Read the statement program header starting at OFFSET in
19109 .debug_line, or .debug_line.dwo. Return a pointer
19110 to a struct line_header, allocated using xmalloc.
19111 Returns NULL if there is a problem reading the header, e.g., if it
19112 has a version we don't understand.
19114 NOTE: the strings in the include directory and file name tables of
19115 the returned object point into the dwarf line section buffer,
19116 and must not be freed. */
19118 static line_header_up
19119 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19121 struct dwarf2_section_info
*section
;
19122 struct dwarf2_per_objfile
*dwarf2_per_objfile
19123 = cu
->per_cu
->dwarf2_per_objfile
;
19125 section
= get_debug_line_section (cu
);
19126 section
->read (dwarf2_per_objfile
->objfile
);
19127 if (section
->buffer
== NULL
)
19129 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19130 complaint (_("missing .debug_line.dwo section"));
19132 complaint (_("missing .debug_line section"));
19136 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19137 dwarf2_per_objfile
, section
,
19141 /* Subroutine of dwarf_decode_lines to simplify it.
19142 Return the file name of the psymtab for the given file_entry.
19143 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19144 If space for the result is malloc'd, *NAME_HOLDER will be set.
19145 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19147 static const char *
19148 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19149 const dwarf2_psymtab
*pst
,
19150 const char *comp_dir
,
19151 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19153 const char *include_name
= fe
.name
;
19154 const char *include_name_to_compare
= include_name
;
19155 const char *pst_filename
;
19158 const char *dir_name
= fe
.include_dir (lh
);
19160 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19161 if (!IS_ABSOLUTE_PATH (include_name
)
19162 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19164 /* Avoid creating a duplicate psymtab for PST.
19165 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19166 Before we do the comparison, however, we need to account
19167 for DIR_NAME and COMP_DIR.
19168 First prepend dir_name (if non-NULL). If we still don't
19169 have an absolute path prepend comp_dir (if non-NULL).
19170 However, the directory we record in the include-file's
19171 psymtab does not contain COMP_DIR (to match the
19172 corresponding symtab(s)).
19177 bash$ gcc -g ./hello.c
19178 include_name = "hello.c"
19180 DW_AT_comp_dir = comp_dir = "/tmp"
19181 DW_AT_name = "./hello.c"
19185 if (dir_name
!= NULL
)
19187 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19188 include_name
, (char *) NULL
));
19189 include_name
= name_holder
->get ();
19190 include_name_to_compare
= include_name
;
19192 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19194 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19195 include_name
, (char *) NULL
));
19196 include_name_to_compare
= hold_compare
.get ();
19200 pst_filename
= pst
->filename
;
19201 gdb::unique_xmalloc_ptr
<char> copied_name
;
19202 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19204 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19205 pst_filename
, (char *) NULL
));
19206 pst_filename
= copied_name
.get ();
19209 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19213 return include_name
;
19216 /* State machine to track the state of the line number program. */
19218 class lnp_state_machine
19221 /* Initialize a machine state for the start of a line number
19223 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19224 bool record_lines_p
);
19226 file_entry
*current_file ()
19228 /* lh->file_names is 0-based, but the file name numbers in the
19229 statement program are 1-based. */
19230 return m_line_header
->file_name_at (m_file
);
19233 /* Record the line in the state machine. END_SEQUENCE is true if
19234 we're processing the end of a sequence. */
19235 void record_line (bool end_sequence
);
19237 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19238 nop-out rest of the lines in this sequence. */
19239 void check_line_address (struct dwarf2_cu
*cu
,
19240 const gdb_byte
*line_ptr
,
19241 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19243 void handle_set_discriminator (unsigned int discriminator
)
19245 m_discriminator
= discriminator
;
19246 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19249 /* Handle DW_LNE_set_address. */
19250 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19253 address
+= baseaddr
;
19254 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19257 /* Handle DW_LNS_advance_pc. */
19258 void handle_advance_pc (CORE_ADDR adjust
);
19260 /* Handle a special opcode. */
19261 void handle_special_opcode (unsigned char op_code
);
19263 /* Handle DW_LNS_advance_line. */
19264 void handle_advance_line (int line_delta
)
19266 advance_line (line_delta
);
19269 /* Handle DW_LNS_set_file. */
19270 void handle_set_file (file_name_index file
);
19272 /* Handle DW_LNS_negate_stmt. */
19273 void handle_negate_stmt ()
19275 m_is_stmt
= !m_is_stmt
;
19278 /* Handle DW_LNS_const_add_pc. */
19279 void handle_const_add_pc ();
19281 /* Handle DW_LNS_fixed_advance_pc. */
19282 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19284 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19288 /* Handle DW_LNS_copy. */
19289 void handle_copy ()
19291 record_line (false);
19292 m_discriminator
= 0;
19295 /* Handle DW_LNE_end_sequence. */
19296 void handle_end_sequence ()
19298 m_currently_recording_lines
= true;
19302 /* Advance the line by LINE_DELTA. */
19303 void advance_line (int line_delta
)
19305 m_line
+= line_delta
;
19307 if (line_delta
!= 0)
19308 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19311 struct dwarf2_cu
*m_cu
;
19313 gdbarch
*m_gdbarch
;
19315 /* True if we're recording lines.
19316 Otherwise we're building partial symtabs and are just interested in
19317 finding include files mentioned by the line number program. */
19318 bool m_record_lines_p
;
19320 /* The line number header. */
19321 line_header
*m_line_header
;
19323 /* These are part of the standard DWARF line number state machine,
19324 and initialized according to the DWARF spec. */
19326 unsigned char m_op_index
= 0;
19327 /* The line table index of the current file. */
19328 file_name_index m_file
= 1;
19329 unsigned int m_line
= 1;
19331 /* These are initialized in the constructor. */
19333 CORE_ADDR m_address
;
19335 unsigned int m_discriminator
;
19337 /* Additional bits of state we need to track. */
19339 /* The last file that we called dwarf2_start_subfile for.
19340 This is only used for TLLs. */
19341 unsigned int m_last_file
= 0;
19342 /* The last file a line number was recorded for. */
19343 struct subfile
*m_last_subfile
= NULL
;
19345 /* When true, record the lines we decode. */
19346 bool m_currently_recording_lines
= false;
19348 /* The last line number that was recorded, used to coalesce
19349 consecutive entries for the same line. This can happen, for
19350 example, when discriminators are present. PR 17276. */
19351 unsigned int m_last_line
= 0;
19352 bool m_line_has_non_zero_discriminator
= false;
19356 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19358 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19359 / m_line_header
->maximum_ops_per_instruction
)
19360 * m_line_header
->minimum_instruction_length
);
19361 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19362 m_op_index
= ((m_op_index
+ adjust
)
19363 % m_line_header
->maximum_ops_per_instruction
);
19367 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19369 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19370 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19371 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19372 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19373 / m_line_header
->maximum_ops_per_instruction
)
19374 * m_line_header
->minimum_instruction_length
);
19375 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19376 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19377 % m_line_header
->maximum_ops_per_instruction
);
19379 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19380 advance_line (line_delta
);
19381 record_line (false);
19382 m_discriminator
= 0;
19386 lnp_state_machine::handle_set_file (file_name_index file
)
19390 const file_entry
*fe
= current_file ();
19392 dwarf2_debug_line_missing_file_complaint ();
19393 else if (m_record_lines_p
)
19395 const char *dir
= fe
->include_dir (m_line_header
);
19397 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19398 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19399 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19404 lnp_state_machine::handle_const_add_pc ()
19407 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19410 = (((m_op_index
+ adjust
)
19411 / m_line_header
->maximum_ops_per_instruction
)
19412 * m_line_header
->minimum_instruction_length
);
19414 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19415 m_op_index
= ((m_op_index
+ adjust
)
19416 % m_line_header
->maximum_ops_per_instruction
);
19419 /* Return non-zero if we should add LINE to the line number table.
19420 LINE is the line to add, LAST_LINE is the last line that was added,
19421 LAST_SUBFILE is the subfile for LAST_LINE.
19422 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19423 had a non-zero discriminator.
19425 We have to be careful in the presence of discriminators.
19426 E.g., for this line:
19428 for (i = 0; i < 100000; i++);
19430 clang can emit four line number entries for that one line,
19431 each with a different discriminator.
19432 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19434 However, we want gdb to coalesce all four entries into one.
19435 Otherwise the user could stepi into the middle of the line and
19436 gdb would get confused about whether the pc really was in the
19437 middle of the line.
19439 Things are further complicated by the fact that two consecutive
19440 line number entries for the same line is a heuristic used by gcc
19441 to denote the end of the prologue. So we can't just discard duplicate
19442 entries, we have to be selective about it. The heuristic we use is
19443 that we only collapse consecutive entries for the same line if at least
19444 one of those entries has a non-zero discriminator. PR 17276.
19446 Note: Addresses in the line number state machine can never go backwards
19447 within one sequence, thus this coalescing is ok. */
19450 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19451 unsigned int line
, unsigned int last_line
,
19452 int line_has_non_zero_discriminator
,
19453 struct subfile
*last_subfile
)
19455 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19457 if (line
!= last_line
)
19459 /* Same line for the same file that we've seen already.
19460 As a last check, for pr 17276, only record the line if the line
19461 has never had a non-zero discriminator. */
19462 if (!line_has_non_zero_discriminator
)
19467 /* Use the CU's builder to record line number LINE beginning at
19468 address ADDRESS in the line table of subfile SUBFILE. */
19471 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19472 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19473 struct dwarf2_cu
*cu
)
19475 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19477 if (dwarf_line_debug
)
19479 fprintf_unfiltered (gdb_stdlog
,
19480 "Recording line %u, file %s, address %s\n",
19481 line
, lbasename (subfile
->name
),
19482 paddress (gdbarch
, address
));
19486 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19489 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19490 Mark the end of a set of line number records.
19491 The arguments are the same as for dwarf_record_line_1.
19492 If SUBFILE is NULL the request is ignored. */
19495 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19496 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19498 if (subfile
== NULL
)
19501 if (dwarf_line_debug
)
19503 fprintf_unfiltered (gdb_stdlog
,
19504 "Finishing current line, file %s, address %s\n",
19505 lbasename (subfile
->name
),
19506 paddress (gdbarch
, address
));
19509 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19513 lnp_state_machine::record_line (bool end_sequence
)
19515 if (dwarf_line_debug
)
19517 fprintf_unfiltered (gdb_stdlog
,
19518 "Processing actual line %u: file %u,"
19519 " address %s, is_stmt %u, discrim %u%s\n",
19521 paddress (m_gdbarch
, m_address
),
19522 m_is_stmt
, m_discriminator
,
19523 (end_sequence
? "\t(end sequence)" : ""));
19526 file_entry
*fe
= current_file ();
19529 dwarf2_debug_line_missing_file_complaint ();
19530 /* For now we ignore lines not starting on an instruction boundary.
19531 But not when processing end_sequence for compatibility with the
19532 previous version of the code. */
19533 else if (m_op_index
== 0 || end_sequence
)
19535 fe
->included_p
= 1;
19536 if (m_record_lines_p
)
19538 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19541 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19542 m_currently_recording_lines
? m_cu
: nullptr);
19547 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19549 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19550 m_line_has_non_zero_discriminator
,
19553 buildsym_compunit
*builder
= m_cu
->get_builder ();
19554 dwarf_record_line_1 (m_gdbarch
,
19555 builder
->get_current_subfile (),
19556 m_line
, m_address
, is_stmt
,
19557 m_currently_recording_lines
? m_cu
: nullptr);
19559 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19560 m_last_line
= m_line
;
19566 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19567 line_header
*lh
, bool record_lines_p
)
19571 m_record_lines_p
= record_lines_p
;
19572 m_line_header
= lh
;
19574 m_currently_recording_lines
= true;
19576 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19577 was a line entry for it so that the backend has a chance to adjust it
19578 and also record it in case it needs it. This is currently used by MIPS
19579 code, cf. `mips_adjust_dwarf2_line'. */
19580 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19581 m_is_stmt
= lh
->default_is_stmt
;
19582 m_discriminator
= 0;
19586 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19587 const gdb_byte
*line_ptr
,
19588 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19590 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19591 the pc range of the CU. However, we restrict the test to only ADDRESS
19592 values of zero to preserve GDB's previous behaviour which is to handle
19593 the specific case of a function being GC'd by the linker. */
19595 if (address
== 0 && address
< unrelocated_lowpc
)
19597 /* This line table is for a function which has been
19598 GCd by the linker. Ignore it. PR gdb/12528 */
19600 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19601 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19603 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19604 line_offset
, objfile_name (objfile
));
19605 m_currently_recording_lines
= false;
19606 /* Note: m_currently_recording_lines is left as false until we see
19607 DW_LNE_end_sequence. */
19611 /* Subroutine of dwarf_decode_lines to simplify it.
19612 Process the line number information in LH.
19613 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19614 program in order to set included_p for every referenced header. */
19617 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19618 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19620 const gdb_byte
*line_ptr
, *extended_end
;
19621 const gdb_byte
*line_end
;
19622 unsigned int bytes_read
, extended_len
;
19623 unsigned char op_code
, extended_op
;
19624 CORE_ADDR baseaddr
;
19625 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19626 bfd
*abfd
= objfile
->obfd
;
19627 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19628 /* True if we're recording line info (as opposed to building partial
19629 symtabs and just interested in finding include files mentioned by
19630 the line number program). */
19631 bool record_lines_p
= !decode_for_pst_p
;
19633 baseaddr
= objfile
->text_section_offset ();
19635 line_ptr
= lh
->statement_program_start
;
19636 line_end
= lh
->statement_program_end
;
19638 /* Read the statement sequences until there's nothing left. */
19639 while (line_ptr
< line_end
)
19641 /* The DWARF line number program state machine. Reset the state
19642 machine at the start of each sequence. */
19643 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19644 bool end_sequence
= false;
19646 if (record_lines_p
)
19648 /* Start a subfile for the current file of the state
19650 const file_entry
*fe
= state_machine
.current_file ();
19653 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19656 /* Decode the table. */
19657 while (line_ptr
< line_end
&& !end_sequence
)
19659 op_code
= read_1_byte (abfd
, line_ptr
);
19662 if (op_code
>= lh
->opcode_base
)
19664 /* Special opcode. */
19665 state_machine
.handle_special_opcode (op_code
);
19667 else switch (op_code
)
19669 case DW_LNS_extended_op
:
19670 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19672 line_ptr
+= bytes_read
;
19673 extended_end
= line_ptr
+ extended_len
;
19674 extended_op
= read_1_byte (abfd
, line_ptr
);
19676 switch (extended_op
)
19678 case DW_LNE_end_sequence
:
19679 state_machine
.handle_end_sequence ();
19680 end_sequence
= true;
19682 case DW_LNE_set_address
:
19685 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19686 line_ptr
+= bytes_read
;
19688 state_machine
.check_line_address (cu
, line_ptr
,
19689 lowpc
- baseaddr
, address
);
19690 state_machine
.handle_set_address (baseaddr
, address
);
19693 case DW_LNE_define_file
:
19695 const char *cur_file
;
19696 unsigned int mod_time
, length
;
19699 cur_file
= read_direct_string (abfd
, line_ptr
,
19701 line_ptr
+= bytes_read
;
19702 dindex
= (dir_index
)
19703 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19704 line_ptr
+= bytes_read
;
19706 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19707 line_ptr
+= bytes_read
;
19709 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19710 line_ptr
+= bytes_read
;
19711 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19714 case DW_LNE_set_discriminator
:
19716 /* The discriminator is not interesting to the
19717 debugger; just ignore it. We still need to
19718 check its value though:
19719 if there are consecutive entries for the same
19720 (non-prologue) line we want to coalesce them.
19723 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19724 line_ptr
+= bytes_read
;
19726 state_machine
.handle_set_discriminator (discr
);
19730 complaint (_("mangled .debug_line section"));
19733 /* Make sure that we parsed the extended op correctly. If e.g.
19734 we expected a different address size than the producer used,
19735 we may have read the wrong number of bytes. */
19736 if (line_ptr
!= extended_end
)
19738 complaint (_("mangled .debug_line section"));
19743 state_machine
.handle_copy ();
19745 case DW_LNS_advance_pc
:
19748 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19749 line_ptr
+= bytes_read
;
19751 state_machine
.handle_advance_pc (adjust
);
19754 case DW_LNS_advance_line
:
19757 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19758 line_ptr
+= bytes_read
;
19760 state_machine
.handle_advance_line (line_delta
);
19763 case DW_LNS_set_file
:
19765 file_name_index file
19766 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19768 line_ptr
+= bytes_read
;
19770 state_machine
.handle_set_file (file
);
19773 case DW_LNS_set_column
:
19774 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19775 line_ptr
+= bytes_read
;
19777 case DW_LNS_negate_stmt
:
19778 state_machine
.handle_negate_stmt ();
19780 case DW_LNS_set_basic_block
:
19782 /* Add to the address register of the state machine the
19783 address increment value corresponding to special opcode
19784 255. I.e., this value is scaled by the minimum
19785 instruction length since special opcode 255 would have
19786 scaled the increment. */
19787 case DW_LNS_const_add_pc
:
19788 state_machine
.handle_const_add_pc ();
19790 case DW_LNS_fixed_advance_pc
:
19792 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19795 state_machine
.handle_fixed_advance_pc (addr_adj
);
19800 /* Unknown standard opcode, ignore it. */
19803 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19805 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19806 line_ptr
+= bytes_read
;
19813 dwarf2_debug_line_missing_end_sequence_complaint ();
19815 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19816 in which case we still finish recording the last line). */
19817 state_machine
.record_line (true);
19821 /* Decode the Line Number Program (LNP) for the given line_header
19822 structure and CU. The actual information extracted and the type
19823 of structures created from the LNP depends on the value of PST.
19825 1. If PST is NULL, then this procedure uses the data from the program
19826 to create all necessary symbol tables, and their linetables.
19828 2. If PST is not NULL, this procedure reads the program to determine
19829 the list of files included by the unit represented by PST, and
19830 builds all the associated partial symbol tables.
19832 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19833 It is used for relative paths in the line table.
19834 NOTE: When processing partial symtabs (pst != NULL),
19835 comp_dir == pst->dirname.
19837 NOTE: It is important that psymtabs have the same file name (via strcmp)
19838 as the corresponding symtab. Since COMP_DIR is not used in the name of the
19839 symtab we don't use it in the name of the psymtabs we create.
19840 E.g. expand_line_sal requires this when finding psymtabs to expand.
19841 A good testcase for this is mb-inline.exp.
19843 LOWPC is the lowest address in CU (or 0 if not known).
19845 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
19846 for its PC<->lines mapping information. Otherwise only the filename
19847 table is read in. */
19850 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
19851 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
19852 CORE_ADDR lowpc
, int decode_mapping
)
19854 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19855 const int decode_for_pst_p
= (pst
!= NULL
);
19857 if (decode_mapping
)
19858 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
19860 if (decode_for_pst_p
)
19862 /* Now that we're done scanning the Line Header Program, we can
19863 create the psymtab of each included file. */
19864 for (auto &file_entry
: lh
->file_names ())
19865 if (file_entry
.included_p
== 1)
19867 gdb::unique_xmalloc_ptr
<char> name_holder
;
19868 const char *include_name
=
19869 psymtab_include_file_name (lh
, file_entry
, pst
,
19870 comp_dir
, &name_holder
);
19871 if (include_name
!= NULL
)
19872 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
19877 /* Make sure a symtab is created for every file, even files
19878 which contain only variables (i.e. no code with associated
19880 buildsym_compunit
*builder
= cu
->get_builder ();
19881 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
19883 for (auto &fe
: lh
->file_names ())
19885 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
19886 if (builder
->get_current_subfile ()->symtab
== NULL
)
19888 builder
->get_current_subfile ()->symtab
19889 = allocate_symtab (cust
,
19890 builder
->get_current_subfile ()->name
);
19892 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
19897 /* Start a subfile for DWARF. FILENAME is the name of the file and
19898 DIRNAME the name of the source directory which contains FILENAME
19899 or NULL if not known.
19900 This routine tries to keep line numbers from identical absolute and
19901 relative file names in a common subfile.
19903 Using the `list' example from the GDB testsuite, which resides in
19904 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
19905 of /srcdir/list0.c yields the following debugging information for list0.c:
19907 DW_AT_name: /srcdir/list0.c
19908 DW_AT_comp_dir: /compdir
19909 files.files[0].name: list0.h
19910 files.files[0].dir: /srcdir
19911 files.files[1].name: list0.c
19912 files.files[1].dir: /srcdir
19914 The line number information for list0.c has to end up in a single
19915 subfile, so that `break /srcdir/list0.c:1' works as expected.
19916 start_subfile will ensure that this happens provided that we pass the
19917 concatenation of files.files[1].dir and files.files[1].name as the
19921 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
19922 const char *dirname
)
19924 gdb::unique_xmalloc_ptr
<char> copy
;
19926 /* In order not to lose the line information directory,
19927 we concatenate it to the filename when it makes sense.
19928 Note that the Dwarf3 standard says (speaking of filenames in line
19929 information): ``The directory index is ignored for file names
19930 that represent full path names''. Thus ignoring dirname in the
19931 `else' branch below isn't an issue. */
19933 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
19935 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
19936 filename
= copy
.get ();
19939 cu
->get_builder ()->start_subfile (filename
);
19942 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
19943 buildsym_compunit constructor. */
19945 struct compunit_symtab
*
19946 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
19949 gdb_assert (m_builder
== nullptr);
19951 m_builder
.reset (new struct buildsym_compunit
19952 (per_cu
->dwarf2_per_objfile
->objfile
,
19953 name
, comp_dir
, language
, low_pc
));
19955 list_in_scope
= get_builder ()->get_file_symbols ();
19957 get_builder ()->record_debugformat ("DWARF 2");
19958 get_builder ()->record_producer (producer
);
19960 processing_has_namespace_info
= false;
19962 return get_builder ()->get_compunit_symtab ();
19966 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
19967 struct dwarf2_cu
*cu
)
19969 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19970 struct comp_unit_head
*cu_header
= &cu
->header
;
19972 /* NOTE drow/2003-01-30: There used to be a comment and some special
19973 code here to turn a symbol with DW_AT_external and a
19974 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
19975 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
19976 with some versions of binutils) where shared libraries could have
19977 relocations against symbols in their debug information - the
19978 minimal symbol would have the right address, but the debug info
19979 would not. It's no longer necessary, because we will explicitly
19980 apply relocations when we read in the debug information now. */
19982 /* A DW_AT_location attribute with no contents indicates that a
19983 variable has been optimized away. */
19984 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
19986 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
19990 /* Handle one degenerate form of location expression specially, to
19991 preserve GDB's previous behavior when section offsets are
19992 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
19993 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
19995 if (attr
->form_is_block ()
19996 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
19997 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
19998 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
19999 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20000 && (DW_BLOCK (attr
)->size
20001 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20003 unsigned int dummy
;
20005 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20006 SET_SYMBOL_VALUE_ADDRESS
20007 (sym
, cu
->header
.read_address (objfile
->obfd
,
20008 DW_BLOCK (attr
)->data
+ 1,
20011 SET_SYMBOL_VALUE_ADDRESS
20012 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20014 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20015 fixup_symbol_section (sym
, objfile
);
20016 SET_SYMBOL_VALUE_ADDRESS
20018 SYMBOL_VALUE_ADDRESS (sym
)
20019 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20023 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20024 expression evaluator, and use LOC_COMPUTED only when necessary
20025 (i.e. when the value of a register or memory location is
20026 referenced, or a thread-local block, etc.). Then again, it might
20027 not be worthwhile. I'm assuming that it isn't unless performance
20028 or memory numbers show me otherwise. */
20030 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20032 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20033 cu
->has_loclist
= true;
20036 /* Given a pointer to a DWARF information entry, figure out if we need
20037 to make a symbol table entry for it, and if so, create a new entry
20038 and return a pointer to it.
20039 If TYPE is NULL, determine symbol type from the die, otherwise
20040 used the passed type.
20041 If SPACE is not NULL, use it to hold the new symbol. If it is
20042 NULL, allocate a new symbol on the objfile's obstack. */
20044 static struct symbol
*
20045 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20046 struct symbol
*space
)
20048 struct dwarf2_per_objfile
*dwarf2_per_objfile
20049 = cu
->per_cu
->dwarf2_per_objfile
;
20050 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20051 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20052 struct symbol
*sym
= NULL
;
20054 struct attribute
*attr
= NULL
;
20055 struct attribute
*attr2
= NULL
;
20056 CORE_ADDR baseaddr
;
20057 struct pending
**list_to_add
= NULL
;
20059 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20061 baseaddr
= objfile
->text_section_offset ();
20063 name
= dwarf2_name (die
, cu
);
20066 const char *linkagename
;
20067 int suppress_add
= 0;
20072 sym
= allocate_symbol (objfile
);
20073 OBJSTAT (objfile
, n_syms
++);
20075 /* Cache this symbol's name and the name's demangled form (if any). */
20076 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20077 linkagename
= dwarf2_physname (name
, die
, cu
);
20078 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20080 /* Fortran does not have mangling standard and the mangling does differ
20081 between gfortran, iFort etc. */
20082 if (cu
->language
== language_fortran
20083 && symbol_get_demangled_name (sym
) == NULL
)
20084 symbol_set_demangled_name (sym
,
20085 dwarf2_full_name (name
, die
, cu
),
20088 /* Default assumptions.
20089 Use the passed type or decode it from the die. */
20090 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20091 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20093 SYMBOL_TYPE (sym
) = type
;
20095 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20096 attr
= dwarf2_attr (die
,
20097 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20099 if (attr
!= nullptr)
20101 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20104 attr
= dwarf2_attr (die
,
20105 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20107 if (attr
!= nullptr)
20109 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20110 struct file_entry
*fe
;
20112 if (cu
->line_header
!= NULL
)
20113 fe
= cu
->line_header
->file_name_at (file_index
);
20118 complaint (_("file index out of range"));
20120 symbol_set_symtab (sym
, fe
->symtab
);
20126 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20127 if (attr
!= nullptr)
20131 addr
= attr
->value_as_address ();
20132 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20133 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20135 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20136 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20137 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20138 add_symbol_to_list (sym
, cu
->list_in_scope
);
20140 case DW_TAG_subprogram
:
20141 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20143 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20144 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20145 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20146 || cu
->language
== language_ada
20147 || cu
->language
== language_fortran
)
20149 /* Subprograms marked external are stored as a global symbol.
20150 Ada and Fortran subprograms, whether marked external or
20151 not, are always stored as a global symbol, because we want
20152 to be able to access them globally. For instance, we want
20153 to be able to break on a nested subprogram without having
20154 to specify the context. */
20155 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20159 list_to_add
= cu
->list_in_scope
;
20162 case DW_TAG_inlined_subroutine
:
20163 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20165 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20166 SYMBOL_INLINED (sym
) = 1;
20167 list_to_add
= cu
->list_in_scope
;
20169 case DW_TAG_template_value_param
:
20171 /* Fall through. */
20172 case DW_TAG_constant
:
20173 case DW_TAG_variable
:
20174 case DW_TAG_member
:
20175 /* Compilation with minimal debug info may result in
20176 variables with missing type entries. Change the
20177 misleading `void' type to something sensible. */
20178 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20179 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20181 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20182 /* In the case of DW_TAG_member, we should only be called for
20183 static const members. */
20184 if (die
->tag
== DW_TAG_member
)
20186 /* dwarf2_add_field uses die_is_declaration,
20187 so we do the same. */
20188 gdb_assert (die_is_declaration (die
, cu
));
20191 if (attr
!= nullptr)
20193 dwarf2_const_value (attr
, sym
, cu
);
20194 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20197 if (attr2
&& (DW_UNSND (attr2
) != 0))
20198 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20200 list_to_add
= cu
->list_in_scope
;
20204 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20205 if (attr
!= nullptr)
20207 var_decode_location (attr
, sym
, cu
);
20208 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20210 /* Fortran explicitly imports any global symbols to the local
20211 scope by DW_TAG_common_block. */
20212 if (cu
->language
== language_fortran
&& die
->parent
20213 && die
->parent
->tag
== DW_TAG_common_block
)
20216 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20217 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20218 && !dwarf2_per_objfile
->has_section_at_zero
)
20220 /* When a static variable is eliminated by the linker,
20221 the corresponding debug information is not stripped
20222 out, but the variable address is set to null;
20223 do not add such variables into symbol table. */
20225 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20227 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20228 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20229 && dwarf2_per_objfile
->can_copy
)
20231 /* A global static variable might be subject to
20232 copy relocation. We first check for a local
20233 minsym, though, because maybe the symbol was
20234 marked hidden, in which case this would not
20236 bound_minimal_symbol found
20237 = (lookup_minimal_symbol_linkage
20238 (sym
->linkage_name (), objfile
));
20239 if (found
.minsym
!= nullptr)
20240 sym
->maybe_copied
= 1;
20243 /* A variable with DW_AT_external is never static,
20244 but it may be block-scoped. */
20246 = ((cu
->list_in_scope
20247 == cu
->get_builder ()->get_file_symbols ())
20248 ? cu
->get_builder ()->get_global_symbols ()
20249 : cu
->list_in_scope
);
20252 list_to_add
= cu
->list_in_scope
;
20256 /* We do not know the address of this symbol.
20257 If it is an external symbol and we have type information
20258 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20259 The address of the variable will then be determined from
20260 the minimal symbol table whenever the variable is
20262 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20264 /* Fortran explicitly imports any global symbols to the local
20265 scope by DW_TAG_common_block. */
20266 if (cu
->language
== language_fortran
&& die
->parent
20267 && die
->parent
->tag
== DW_TAG_common_block
)
20269 /* SYMBOL_CLASS doesn't matter here because
20270 read_common_block is going to reset it. */
20272 list_to_add
= cu
->list_in_scope
;
20274 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20275 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20277 /* A variable with DW_AT_external is never static, but it
20278 may be block-scoped. */
20280 = ((cu
->list_in_scope
20281 == cu
->get_builder ()->get_file_symbols ())
20282 ? cu
->get_builder ()->get_global_symbols ()
20283 : cu
->list_in_scope
);
20285 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20287 else if (!die_is_declaration (die
, cu
))
20289 /* Use the default LOC_OPTIMIZED_OUT class. */
20290 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20292 list_to_add
= cu
->list_in_scope
;
20296 case DW_TAG_formal_parameter
:
20298 /* If we are inside a function, mark this as an argument. If
20299 not, we might be looking at an argument to an inlined function
20300 when we do not have enough information to show inlined frames;
20301 pretend it's a local variable in that case so that the user can
20303 struct context_stack
*curr
20304 = cu
->get_builder ()->get_current_context_stack ();
20305 if (curr
!= nullptr && curr
->name
!= nullptr)
20306 SYMBOL_IS_ARGUMENT (sym
) = 1;
20307 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20308 if (attr
!= nullptr)
20310 var_decode_location (attr
, sym
, cu
);
20312 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20313 if (attr
!= nullptr)
20315 dwarf2_const_value (attr
, sym
, cu
);
20318 list_to_add
= cu
->list_in_scope
;
20321 case DW_TAG_unspecified_parameters
:
20322 /* From varargs functions; gdb doesn't seem to have any
20323 interest in this information, so just ignore it for now.
20326 case DW_TAG_template_type_param
:
20328 /* Fall through. */
20329 case DW_TAG_class_type
:
20330 case DW_TAG_interface_type
:
20331 case DW_TAG_structure_type
:
20332 case DW_TAG_union_type
:
20333 case DW_TAG_set_type
:
20334 case DW_TAG_enumeration_type
:
20335 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20336 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20339 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20340 really ever be static objects: otherwise, if you try
20341 to, say, break of a class's method and you're in a file
20342 which doesn't mention that class, it won't work unless
20343 the check for all static symbols in lookup_symbol_aux
20344 saves you. See the OtherFileClass tests in
20345 gdb.c++/namespace.exp. */
20349 buildsym_compunit
*builder
= cu
->get_builder ();
20351 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20352 && cu
->language
== language_cplus
20353 ? builder
->get_global_symbols ()
20354 : cu
->list_in_scope
);
20356 /* The semantics of C++ state that "struct foo {
20357 ... }" also defines a typedef for "foo". */
20358 if (cu
->language
== language_cplus
20359 || cu
->language
== language_ada
20360 || cu
->language
== language_d
20361 || cu
->language
== language_rust
)
20363 /* The symbol's name is already allocated along
20364 with this objfile, so we don't need to
20365 duplicate it for the type. */
20366 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20367 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20372 case DW_TAG_typedef
:
20373 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20374 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20375 list_to_add
= cu
->list_in_scope
;
20377 case DW_TAG_base_type
:
20378 case DW_TAG_subrange_type
:
20379 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20380 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20381 list_to_add
= cu
->list_in_scope
;
20383 case DW_TAG_enumerator
:
20384 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20385 if (attr
!= nullptr)
20387 dwarf2_const_value (attr
, sym
, cu
);
20390 /* NOTE: carlton/2003-11-10: See comment above in the
20391 DW_TAG_class_type, etc. block. */
20394 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20395 && cu
->language
== language_cplus
20396 ? cu
->get_builder ()->get_global_symbols ()
20397 : cu
->list_in_scope
);
20400 case DW_TAG_imported_declaration
:
20401 case DW_TAG_namespace
:
20402 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20403 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20405 case DW_TAG_module
:
20406 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20407 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20408 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20410 case DW_TAG_common_block
:
20411 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20412 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20413 add_symbol_to_list (sym
, cu
->list_in_scope
);
20416 /* Not a tag we recognize. Hopefully we aren't processing
20417 trash data, but since we must specifically ignore things
20418 we don't recognize, there is nothing else we should do at
20420 complaint (_("unsupported tag: '%s'"),
20421 dwarf_tag_name (die
->tag
));
20427 sym
->hash_next
= objfile
->template_symbols
;
20428 objfile
->template_symbols
= sym
;
20429 list_to_add
= NULL
;
20432 if (list_to_add
!= NULL
)
20433 add_symbol_to_list (sym
, list_to_add
);
20435 /* For the benefit of old versions of GCC, check for anonymous
20436 namespaces based on the demangled name. */
20437 if (!cu
->processing_has_namespace_info
20438 && cu
->language
== language_cplus
)
20439 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20444 /* Given an attr with a DW_FORM_dataN value in host byte order,
20445 zero-extend it as appropriate for the symbol's type. The DWARF
20446 standard (v4) is not entirely clear about the meaning of using
20447 DW_FORM_dataN for a constant with a signed type, where the type is
20448 wider than the data. The conclusion of a discussion on the DWARF
20449 list was that this is unspecified. We choose to always zero-extend
20450 because that is the interpretation long in use by GCC. */
20453 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20454 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20456 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20457 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20458 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20459 LONGEST l
= DW_UNSND (attr
);
20461 if (bits
< sizeof (*value
) * 8)
20463 l
&= ((LONGEST
) 1 << bits
) - 1;
20466 else if (bits
== sizeof (*value
) * 8)
20470 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20471 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20478 /* Read a constant value from an attribute. Either set *VALUE, or if
20479 the value does not fit in *VALUE, set *BYTES - either already
20480 allocated on the objfile obstack, or newly allocated on OBSTACK,
20481 or, set *BATON, if we translated the constant to a location
20485 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20486 const char *name
, struct obstack
*obstack
,
20487 struct dwarf2_cu
*cu
,
20488 LONGEST
*value
, const gdb_byte
**bytes
,
20489 struct dwarf2_locexpr_baton
**baton
)
20491 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20492 struct comp_unit_head
*cu_header
= &cu
->header
;
20493 struct dwarf_block
*blk
;
20494 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20495 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20501 switch (attr
->form
)
20504 case DW_FORM_addrx
:
20505 case DW_FORM_GNU_addr_index
:
20509 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20510 dwarf2_const_value_length_mismatch_complaint (name
,
20511 cu_header
->addr_size
,
20512 TYPE_LENGTH (type
));
20513 /* Symbols of this form are reasonably rare, so we just
20514 piggyback on the existing location code rather than writing
20515 a new implementation of symbol_computed_ops. */
20516 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20517 (*baton
)->per_cu
= cu
->per_cu
;
20518 gdb_assert ((*baton
)->per_cu
);
20520 (*baton
)->size
= 2 + cu_header
->addr_size
;
20521 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20522 (*baton
)->data
= data
;
20524 data
[0] = DW_OP_addr
;
20525 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20526 byte_order
, DW_ADDR (attr
));
20527 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20530 case DW_FORM_string
:
20533 case DW_FORM_GNU_str_index
:
20534 case DW_FORM_GNU_strp_alt
:
20535 /* DW_STRING is already allocated on the objfile obstack, point
20537 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20539 case DW_FORM_block1
:
20540 case DW_FORM_block2
:
20541 case DW_FORM_block4
:
20542 case DW_FORM_block
:
20543 case DW_FORM_exprloc
:
20544 case DW_FORM_data16
:
20545 blk
= DW_BLOCK (attr
);
20546 if (TYPE_LENGTH (type
) != blk
->size
)
20547 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20548 TYPE_LENGTH (type
));
20549 *bytes
= blk
->data
;
20552 /* The DW_AT_const_value attributes are supposed to carry the
20553 symbol's value "represented as it would be on the target
20554 architecture." By the time we get here, it's already been
20555 converted to host endianness, so we just need to sign- or
20556 zero-extend it as appropriate. */
20557 case DW_FORM_data1
:
20558 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20560 case DW_FORM_data2
:
20561 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20563 case DW_FORM_data4
:
20564 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20566 case DW_FORM_data8
:
20567 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20570 case DW_FORM_sdata
:
20571 case DW_FORM_implicit_const
:
20572 *value
= DW_SND (attr
);
20575 case DW_FORM_udata
:
20576 *value
= DW_UNSND (attr
);
20580 complaint (_("unsupported const value attribute form: '%s'"),
20581 dwarf_form_name (attr
->form
));
20588 /* Copy constant value from an attribute to a symbol. */
20591 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20592 struct dwarf2_cu
*cu
)
20594 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20596 const gdb_byte
*bytes
;
20597 struct dwarf2_locexpr_baton
*baton
;
20599 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20600 sym
->print_name (),
20601 &objfile
->objfile_obstack
, cu
,
20602 &value
, &bytes
, &baton
);
20606 SYMBOL_LOCATION_BATON (sym
) = baton
;
20607 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20609 else if (bytes
!= NULL
)
20611 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20612 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20616 SYMBOL_VALUE (sym
) = value
;
20617 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20621 /* Return the type of the die in question using its DW_AT_type attribute. */
20623 static struct type
*
20624 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20626 struct attribute
*type_attr
;
20628 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20631 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20632 /* A missing DW_AT_type represents a void type. */
20633 return objfile_type (objfile
)->builtin_void
;
20636 return lookup_die_type (die
, type_attr
, cu
);
20639 /* True iff CU's producer generates GNAT Ada auxiliary information
20640 that allows to find parallel types through that information instead
20641 of having to do expensive parallel lookups by type name. */
20644 need_gnat_info (struct dwarf2_cu
*cu
)
20646 /* Assume that the Ada compiler was GNAT, which always produces
20647 the auxiliary information. */
20648 return (cu
->language
== language_ada
);
20651 /* Return the auxiliary type of the die in question using its
20652 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20653 attribute is not present. */
20655 static struct type
*
20656 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20658 struct attribute
*type_attr
;
20660 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20664 return lookup_die_type (die
, type_attr
, cu
);
20667 /* If DIE has a descriptive_type attribute, then set the TYPE's
20668 descriptive type accordingly. */
20671 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20672 struct dwarf2_cu
*cu
)
20674 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20676 if (descriptive_type
)
20678 ALLOCATE_GNAT_AUX_TYPE (type
);
20679 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20683 /* Return the containing type of the die in question using its
20684 DW_AT_containing_type attribute. */
20686 static struct type
*
20687 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20689 struct attribute
*type_attr
;
20690 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20692 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20694 error (_("Dwarf Error: Problem turning containing type into gdb type "
20695 "[in module %s]"), objfile_name (objfile
));
20697 return lookup_die_type (die
, type_attr
, cu
);
20700 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20702 static struct type
*
20703 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20705 struct dwarf2_per_objfile
*dwarf2_per_objfile
20706 = cu
->per_cu
->dwarf2_per_objfile
;
20707 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20710 std::string message
20711 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20712 objfile_name (objfile
),
20713 sect_offset_str (cu
->header
.sect_off
),
20714 sect_offset_str (die
->sect_off
));
20715 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20717 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20720 /* Look up the type of DIE in CU using its type attribute ATTR.
20721 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20722 DW_AT_containing_type.
20723 If there is no type substitute an error marker. */
20725 static struct type
*
20726 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20727 struct dwarf2_cu
*cu
)
20729 struct dwarf2_per_objfile
*dwarf2_per_objfile
20730 = cu
->per_cu
->dwarf2_per_objfile
;
20731 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20732 struct type
*this_type
;
20734 gdb_assert (attr
->name
== DW_AT_type
20735 || attr
->name
== DW_AT_GNAT_descriptive_type
20736 || attr
->name
== DW_AT_containing_type
);
20738 /* First see if we have it cached. */
20740 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20742 struct dwarf2_per_cu_data
*per_cu
;
20743 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20745 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20746 dwarf2_per_objfile
);
20747 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20749 else if (attr
->form_is_ref ())
20751 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20753 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20755 else if (attr
->form
== DW_FORM_ref_sig8
)
20757 ULONGEST signature
= DW_SIGNATURE (attr
);
20759 return get_signatured_type (die
, signature
, cu
);
20763 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20764 " at %s [in module %s]"),
20765 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20766 objfile_name (objfile
));
20767 return build_error_marker_type (cu
, die
);
20770 /* If not cached we need to read it in. */
20772 if (this_type
== NULL
)
20774 struct die_info
*type_die
= NULL
;
20775 struct dwarf2_cu
*type_cu
= cu
;
20777 if (attr
->form_is_ref ())
20778 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20779 if (type_die
== NULL
)
20780 return build_error_marker_type (cu
, die
);
20781 /* If we find the type now, it's probably because the type came
20782 from an inter-CU reference and the type's CU got expanded before
20784 this_type
= read_type_die (type_die
, type_cu
);
20787 /* If we still don't have a type use an error marker. */
20789 if (this_type
== NULL
)
20790 return build_error_marker_type (cu
, die
);
20795 /* Return the type in DIE, CU.
20796 Returns NULL for invalid types.
20798 This first does a lookup in die_type_hash,
20799 and only reads the die in if necessary.
20801 NOTE: This can be called when reading in partial or full symbols. */
20803 static struct type
*
20804 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20806 struct type
*this_type
;
20808 this_type
= get_die_type (die
, cu
);
20812 return read_type_die_1 (die
, cu
);
20815 /* Read the type in DIE, CU.
20816 Returns NULL for invalid types. */
20818 static struct type
*
20819 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20821 struct type
*this_type
= NULL
;
20825 case DW_TAG_class_type
:
20826 case DW_TAG_interface_type
:
20827 case DW_TAG_structure_type
:
20828 case DW_TAG_union_type
:
20829 this_type
= read_structure_type (die
, cu
);
20831 case DW_TAG_enumeration_type
:
20832 this_type
= read_enumeration_type (die
, cu
);
20834 case DW_TAG_subprogram
:
20835 case DW_TAG_subroutine_type
:
20836 case DW_TAG_inlined_subroutine
:
20837 this_type
= read_subroutine_type (die
, cu
);
20839 case DW_TAG_array_type
:
20840 this_type
= read_array_type (die
, cu
);
20842 case DW_TAG_set_type
:
20843 this_type
= read_set_type (die
, cu
);
20845 case DW_TAG_pointer_type
:
20846 this_type
= read_tag_pointer_type (die
, cu
);
20848 case DW_TAG_ptr_to_member_type
:
20849 this_type
= read_tag_ptr_to_member_type (die
, cu
);
20851 case DW_TAG_reference_type
:
20852 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
20854 case DW_TAG_rvalue_reference_type
:
20855 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
20857 case DW_TAG_const_type
:
20858 this_type
= read_tag_const_type (die
, cu
);
20860 case DW_TAG_volatile_type
:
20861 this_type
= read_tag_volatile_type (die
, cu
);
20863 case DW_TAG_restrict_type
:
20864 this_type
= read_tag_restrict_type (die
, cu
);
20866 case DW_TAG_string_type
:
20867 this_type
= read_tag_string_type (die
, cu
);
20869 case DW_TAG_typedef
:
20870 this_type
= read_typedef (die
, cu
);
20872 case DW_TAG_subrange_type
:
20873 this_type
= read_subrange_type (die
, cu
);
20875 case DW_TAG_base_type
:
20876 this_type
= read_base_type (die
, cu
);
20878 case DW_TAG_unspecified_type
:
20879 this_type
= read_unspecified_type (die
, cu
);
20881 case DW_TAG_namespace
:
20882 this_type
= read_namespace_type (die
, cu
);
20884 case DW_TAG_module
:
20885 this_type
= read_module_type (die
, cu
);
20887 case DW_TAG_atomic_type
:
20888 this_type
= read_tag_atomic_type (die
, cu
);
20891 complaint (_("unexpected tag in read_type_die: '%s'"),
20892 dwarf_tag_name (die
->tag
));
20899 /* See if we can figure out if the class lives in a namespace. We do
20900 this by looking for a member function; its demangled name will
20901 contain namespace info, if there is any.
20902 Return the computed name or NULL.
20903 Space for the result is allocated on the objfile's obstack.
20904 This is the full-die version of guess_partial_die_structure_name.
20905 In this case we know DIE has no useful parent. */
20907 static const char *
20908 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20910 struct die_info
*spec_die
;
20911 struct dwarf2_cu
*spec_cu
;
20912 struct die_info
*child
;
20913 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20916 spec_die
= die_specification (die
, &spec_cu
);
20917 if (spec_die
!= NULL
)
20923 for (child
= die
->child
;
20925 child
= child
->sibling
)
20927 if (child
->tag
== DW_TAG_subprogram
)
20929 const char *linkage_name
= dw2_linkage_name (child
, cu
);
20931 if (linkage_name
!= NULL
)
20933 gdb::unique_xmalloc_ptr
<char> actual_name
20934 (language_class_name_from_physname (cu
->language_defn
,
20936 const char *name
= NULL
;
20938 if (actual_name
!= NULL
)
20940 const char *die_name
= dwarf2_name (die
, cu
);
20942 if (die_name
!= NULL
20943 && strcmp (die_name
, actual_name
.get ()) != 0)
20945 /* Strip off the class name from the full name.
20946 We want the prefix. */
20947 int die_name_len
= strlen (die_name
);
20948 int actual_name_len
= strlen (actual_name
.get ());
20949 const char *ptr
= actual_name
.get ();
20951 /* Test for '::' as a sanity check. */
20952 if (actual_name_len
> die_name_len
+ 2
20953 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
20954 name
= obstack_strndup (
20955 &objfile
->per_bfd
->storage_obstack
,
20956 ptr
, actual_name_len
- die_name_len
- 2);
20967 /* GCC might emit a nameless typedef that has a linkage name. Determine the
20968 prefix part in such case. See
20969 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20971 static const char *
20972 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20974 struct attribute
*attr
;
20977 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
20978 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
20981 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
20984 attr
= dw2_linkage_name_attr (die
, cu
);
20985 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20988 /* dwarf2_name had to be already called. */
20989 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
20991 /* Strip the base name, keep any leading namespaces/classes. */
20992 base
= strrchr (DW_STRING (attr
), ':');
20993 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
20996 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20997 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
20999 &base
[-1] - DW_STRING (attr
));
21002 /* Return the name of the namespace/class that DIE is defined within,
21003 or "" if we can't tell. The caller should not xfree the result.
21005 For example, if we're within the method foo() in the following
21015 then determine_prefix on foo's die will return "N::C". */
21017 static const char *
21018 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21020 struct dwarf2_per_objfile
*dwarf2_per_objfile
21021 = cu
->per_cu
->dwarf2_per_objfile
;
21022 struct die_info
*parent
, *spec_die
;
21023 struct dwarf2_cu
*spec_cu
;
21024 struct type
*parent_type
;
21025 const char *retval
;
21027 if (cu
->language
!= language_cplus
21028 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21029 && cu
->language
!= language_rust
)
21032 retval
= anonymous_struct_prefix (die
, cu
);
21036 /* We have to be careful in the presence of DW_AT_specification.
21037 For example, with GCC 3.4, given the code
21041 // Definition of N::foo.
21045 then we'll have a tree of DIEs like this:
21047 1: DW_TAG_compile_unit
21048 2: DW_TAG_namespace // N
21049 3: DW_TAG_subprogram // declaration of N::foo
21050 4: DW_TAG_subprogram // definition of N::foo
21051 DW_AT_specification // refers to die #3
21053 Thus, when processing die #4, we have to pretend that we're in
21054 the context of its DW_AT_specification, namely the contex of die
21057 spec_die
= die_specification (die
, &spec_cu
);
21058 if (spec_die
== NULL
)
21059 parent
= die
->parent
;
21062 parent
= spec_die
->parent
;
21066 if (parent
== NULL
)
21068 else if (parent
->building_fullname
)
21071 const char *parent_name
;
21073 /* It has been seen on RealView 2.2 built binaries,
21074 DW_TAG_template_type_param types actually _defined_ as
21075 children of the parent class:
21078 template class <class Enum> Class{};
21079 Class<enum E> class_e;
21081 1: DW_TAG_class_type (Class)
21082 2: DW_TAG_enumeration_type (E)
21083 3: DW_TAG_enumerator (enum1:0)
21084 3: DW_TAG_enumerator (enum2:1)
21086 2: DW_TAG_template_type_param
21087 DW_AT_type DW_FORM_ref_udata (E)
21089 Besides being broken debug info, it can put GDB into an
21090 infinite loop. Consider:
21092 When we're building the full name for Class<E>, we'll start
21093 at Class, and go look over its template type parameters,
21094 finding E. We'll then try to build the full name of E, and
21095 reach here. We're now trying to build the full name of E,
21096 and look over the parent DIE for containing scope. In the
21097 broken case, if we followed the parent DIE of E, we'd again
21098 find Class, and once again go look at its template type
21099 arguments, etc., etc. Simply don't consider such parent die
21100 as source-level parent of this die (it can't be, the language
21101 doesn't allow it), and break the loop here. */
21102 name
= dwarf2_name (die
, cu
);
21103 parent_name
= dwarf2_name (parent
, cu
);
21104 complaint (_("template param type '%s' defined within parent '%s'"),
21105 name
? name
: "<unknown>",
21106 parent_name
? parent_name
: "<unknown>");
21110 switch (parent
->tag
)
21112 case DW_TAG_namespace
:
21113 parent_type
= read_type_die (parent
, cu
);
21114 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21115 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21116 Work around this problem here. */
21117 if (cu
->language
== language_cplus
21118 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21120 /* We give a name to even anonymous namespaces. */
21121 return TYPE_NAME (parent_type
);
21122 case DW_TAG_class_type
:
21123 case DW_TAG_interface_type
:
21124 case DW_TAG_structure_type
:
21125 case DW_TAG_union_type
:
21126 case DW_TAG_module
:
21127 parent_type
= read_type_die (parent
, cu
);
21128 if (TYPE_NAME (parent_type
) != NULL
)
21129 return TYPE_NAME (parent_type
);
21131 /* An anonymous structure is only allowed non-static data
21132 members; no typedefs, no member functions, et cetera.
21133 So it does not need a prefix. */
21135 case DW_TAG_compile_unit
:
21136 case DW_TAG_partial_unit
:
21137 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21138 if (cu
->language
== language_cplus
21139 && !dwarf2_per_objfile
->types
.empty ()
21140 && die
->child
!= NULL
21141 && (die
->tag
== DW_TAG_class_type
21142 || die
->tag
== DW_TAG_structure_type
21143 || die
->tag
== DW_TAG_union_type
))
21145 const char *name
= guess_full_die_structure_name (die
, cu
);
21150 case DW_TAG_subprogram
:
21151 /* Nested subroutines in Fortran get a prefix with the name
21152 of the parent's subroutine. */
21153 if (cu
->language
== language_fortran
)
21155 if ((die
->tag
== DW_TAG_subprogram
)
21156 && (dwarf2_name (parent
, cu
) != NULL
))
21157 return dwarf2_name (parent
, cu
);
21159 return determine_prefix (parent
, cu
);
21160 case DW_TAG_enumeration_type
:
21161 parent_type
= read_type_die (parent
, cu
);
21162 if (TYPE_DECLARED_CLASS (parent_type
))
21164 if (TYPE_NAME (parent_type
) != NULL
)
21165 return TYPE_NAME (parent_type
);
21168 /* Fall through. */
21170 return determine_prefix (parent
, cu
);
21174 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21175 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21176 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21177 an obconcat, otherwise allocate storage for the result. The CU argument is
21178 used to determine the language and hence, the appropriate separator. */
21180 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21183 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21184 int physname
, struct dwarf2_cu
*cu
)
21186 const char *lead
= "";
21189 if (suffix
== NULL
|| suffix
[0] == '\0'
21190 || prefix
== NULL
|| prefix
[0] == '\0')
21192 else if (cu
->language
== language_d
)
21194 /* For D, the 'main' function could be defined in any module, but it
21195 should never be prefixed. */
21196 if (strcmp (suffix
, "D main") == 0)
21204 else if (cu
->language
== language_fortran
&& physname
)
21206 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21207 DW_AT_MIPS_linkage_name is preferred and used instead. */
21215 if (prefix
== NULL
)
21217 if (suffix
== NULL
)
21224 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21226 strcpy (retval
, lead
);
21227 strcat (retval
, prefix
);
21228 strcat (retval
, sep
);
21229 strcat (retval
, suffix
);
21234 /* We have an obstack. */
21235 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21239 /* Return sibling of die, NULL if no sibling. */
21241 static struct die_info
*
21242 sibling_die (struct die_info
*die
)
21244 return die
->sibling
;
21247 /* Get name of a die, return NULL if not found. */
21249 static const char *
21250 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21251 struct objfile
*objfile
)
21253 if (name
&& cu
->language
== language_cplus
)
21255 std::string canon_name
= cp_canonicalize_string (name
);
21257 if (!canon_name
.empty ())
21259 if (canon_name
!= name
)
21260 name
= objfile
->intern (canon_name
);
21267 /* Get name of a die, return NULL if not found.
21268 Anonymous namespaces are converted to their magic string. */
21270 static const char *
21271 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21273 struct attribute
*attr
;
21274 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21276 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21277 if ((!attr
|| !DW_STRING (attr
))
21278 && die
->tag
!= DW_TAG_namespace
21279 && die
->tag
!= DW_TAG_class_type
21280 && die
->tag
!= DW_TAG_interface_type
21281 && die
->tag
!= DW_TAG_structure_type
21282 && die
->tag
!= DW_TAG_union_type
)
21287 case DW_TAG_compile_unit
:
21288 case DW_TAG_partial_unit
:
21289 /* Compilation units have a DW_AT_name that is a filename, not
21290 a source language identifier. */
21291 case DW_TAG_enumeration_type
:
21292 case DW_TAG_enumerator
:
21293 /* These tags always have simple identifiers already; no need
21294 to canonicalize them. */
21295 return DW_STRING (attr
);
21297 case DW_TAG_namespace
:
21298 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21299 return DW_STRING (attr
);
21300 return CP_ANONYMOUS_NAMESPACE_STR
;
21302 case DW_TAG_class_type
:
21303 case DW_TAG_interface_type
:
21304 case DW_TAG_structure_type
:
21305 case DW_TAG_union_type
:
21306 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21307 structures or unions. These were of the form "._%d" in GCC 4.1,
21308 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21309 and GCC 4.4. We work around this problem by ignoring these. */
21310 if (attr
&& DW_STRING (attr
)
21311 && (startswith (DW_STRING (attr
), "._")
21312 || startswith (DW_STRING (attr
), "<anonymous")))
21315 /* GCC might emit a nameless typedef that has a linkage name. See
21316 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21317 if (!attr
|| DW_STRING (attr
) == NULL
)
21319 attr
= dw2_linkage_name_attr (die
, cu
);
21320 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21323 /* Avoid demangling DW_STRING (attr) the second time on a second
21324 call for the same DIE. */
21325 if (!DW_STRING_IS_CANONICAL (attr
))
21327 gdb::unique_xmalloc_ptr
<char> demangled
21328 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21329 if (demangled
== nullptr)
21332 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21333 DW_STRING_IS_CANONICAL (attr
) = 1;
21336 /* Strip any leading namespaces/classes, keep only the base name.
21337 DW_AT_name for named DIEs does not contain the prefixes. */
21338 const char *base
= strrchr (DW_STRING (attr
), ':');
21339 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21342 return DW_STRING (attr
);
21350 if (!DW_STRING_IS_CANONICAL (attr
))
21352 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21354 DW_STRING_IS_CANONICAL (attr
) = 1;
21356 return DW_STRING (attr
);
21359 /* Return the die that this die in an extension of, or NULL if there
21360 is none. *EXT_CU is the CU containing DIE on input, and the CU
21361 containing the return value on output. */
21363 static struct die_info
*
21364 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21366 struct attribute
*attr
;
21368 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21372 return follow_die_ref (die
, attr
, ext_cu
);
21375 /* A convenience function that returns an "unknown" DWARF name,
21376 including the value of V. STR is the name of the entity being
21377 printed, e.g., "TAG". */
21379 static const char *
21380 dwarf_unknown (const char *str
, unsigned v
)
21382 char *cell
= get_print_cell ();
21383 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21387 /* Convert a DIE tag into its string name. */
21389 static const char *
21390 dwarf_tag_name (unsigned tag
)
21392 const char *name
= get_DW_TAG_name (tag
);
21395 return dwarf_unknown ("TAG", tag
);
21400 /* Convert a DWARF attribute code into its string name. */
21402 static const char *
21403 dwarf_attr_name (unsigned attr
)
21407 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21408 if (attr
== DW_AT_MIPS_fde
)
21409 return "DW_AT_MIPS_fde";
21411 if (attr
== DW_AT_HP_block_index
)
21412 return "DW_AT_HP_block_index";
21415 name
= get_DW_AT_name (attr
);
21418 return dwarf_unknown ("AT", attr
);
21423 /* Convert a DWARF value form code into its string name. */
21425 static const char *
21426 dwarf_form_name (unsigned form
)
21428 const char *name
= get_DW_FORM_name (form
);
21431 return dwarf_unknown ("FORM", form
);
21436 static const char *
21437 dwarf_bool_name (unsigned mybool
)
21445 /* Convert a DWARF type code into its string name. */
21447 static const char *
21448 dwarf_type_encoding_name (unsigned enc
)
21450 const char *name
= get_DW_ATE_name (enc
);
21453 return dwarf_unknown ("ATE", enc
);
21459 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21463 print_spaces (indent
, f
);
21464 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21465 dwarf_tag_name (die
->tag
), die
->abbrev
,
21466 sect_offset_str (die
->sect_off
));
21468 if (die
->parent
!= NULL
)
21470 print_spaces (indent
, f
);
21471 fprintf_unfiltered (f
, " parent at offset: %s\n",
21472 sect_offset_str (die
->parent
->sect_off
));
21475 print_spaces (indent
, f
);
21476 fprintf_unfiltered (f
, " has children: %s\n",
21477 dwarf_bool_name (die
->child
!= NULL
));
21479 print_spaces (indent
, f
);
21480 fprintf_unfiltered (f
, " attributes:\n");
21482 for (i
= 0; i
< die
->num_attrs
; ++i
)
21484 print_spaces (indent
, f
);
21485 fprintf_unfiltered (f
, " %s (%s) ",
21486 dwarf_attr_name (die
->attrs
[i
].name
),
21487 dwarf_form_name (die
->attrs
[i
].form
));
21489 switch (die
->attrs
[i
].form
)
21492 case DW_FORM_addrx
:
21493 case DW_FORM_GNU_addr_index
:
21494 fprintf_unfiltered (f
, "address: ");
21495 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21497 case DW_FORM_block2
:
21498 case DW_FORM_block4
:
21499 case DW_FORM_block
:
21500 case DW_FORM_block1
:
21501 fprintf_unfiltered (f
, "block: size %s",
21502 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21504 case DW_FORM_exprloc
:
21505 fprintf_unfiltered (f
, "expression: size %s",
21506 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21508 case DW_FORM_data16
:
21509 fprintf_unfiltered (f
, "constant of 16 bytes");
21511 case DW_FORM_ref_addr
:
21512 fprintf_unfiltered (f
, "ref address: ");
21513 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21515 case DW_FORM_GNU_ref_alt
:
21516 fprintf_unfiltered (f
, "alt ref address: ");
21517 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21523 case DW_FORM_ref_udata
:
21524 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21525 (long) (DW_UNSND (&die
->attrs
[i
])));
21527 case DW_FORM_data1
:
21528 case DW_FORM_data2
:
21529 case DW_FORM_data4
:
21530 case DW_FORM_data8
:
21531 case DW_FORM_udata
:
21532 case DW_FORM_sdata
:
21533 fprintf_unfiltered (f
, "constant: %s",
21534 pulongest (DW_UNSND (&die
->attrs
[i
])));
21536 case DW_FORM_sec_offset
:
21537 fprintf_unfiltered (f
, "section offset: %s",
21538 pulongest (DW_UNSND (&die
->attrs
[i
])));
21540 case DW_FORM_ref_sig8
:
21541 fprintf_unfiltered (f
, "signature: %s",
21542 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21544 case DW_FORM_string
:
21546 case DW_FORM_line_strp
:
21548 case DW_FORM_GNU_str_index
:
21549 case DW_FORM_GNU_strp_alt
:
21550 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21551 DW_STRING (&die
->attrs
[i
])
21552 ? DW_STRING (&die
->attrs
[i
]) : "",
21553 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21556 if (DW_UNSND (&die
->attrs
[i
]))
21557 fprintf_unfiltered (f
, "flag: TRUE");
21559 fprintf_unfiltered (f
, "flag: FALSE");
21561 case DW_FORM_flag_present
:
21562 fprintf_unfiltered (f
, "flag: TRUE");
21564 case DW_FORM_indirect
:
21565 /* The reader will have reduced the indirect form to
21566 the "base form" so this form should not occur. */
21567 fprintf_unfiltered (f
,
21568 "unexpected attribute form: DW_FORM_indirect");
21570 case DW_FORM_implicit_const
:
21571 fprintf_unfiltered (f
, "constant: %s",
21572 plongest (DW_SND (&die
->attrs
[i
])));
21575 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21576 die
->attrs
[i
].form
);
21579 fprintf_unfiltered (f
, "\n");
21584 dump_die_for_error (struct die_info
*die
)
21586 dump_die_shallow (gdb_stderr
, 0, die
);
21590 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21592 int indent
= level
* 4;
21594 gdb_assert (die
!= NULL
);
21596 if (level
>= max_level
)
21599 dump_die_shallow (f
, indent
, die
);
21601 if (die
->child
!= NULL
)
21603 print_spaces (indent
, f
);
21604 fprintf_unfiltered (f
, " Children:");
21605 if (level
+ 1 < max_level
)
21607 fprintf_unfiltered (f
, "\n");
21608 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21612 fprintf_unfiltered (f
,
21613 " [not printed, max nesting level reached]\n");
21617 if (die
->sibling
!= NULL
&& level
> 0)
21619 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21623 /* This is called from the pdie macro in gdbinit.in.
21624 It's not static so gcc will keep a copy callable from gdb. */
21627 dump_die (struct die_info
*die
, int max_level
)
21629 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21633 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21637 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21638 to_underlying (die
->sect_off
),
21644 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
21648 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
21650 if (attr
->form_is_ref ())
21651 return (sect_offset
) DW_UNSND (attr
);
21653 complaint (_("unsupported die ref attribute form: '%s'"),
21654 dwarf_form_name (attr
->form
));
21658 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
21659 * the value held by the attribute is not constant. */
21662 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
21664 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
21665 return DW_SND (attr
);
21666 else if (attr
->form
== DW_FORM_udata
21667 || attr
->form
== DW_FORM_data1
21668 || attr
->form
== DW_FORM_data2
21669 || attr
->form
== DW_FORM_data4
21670 || attr
->form
== DW_FORM_data8
)
21671 return DW_UNSND (attr
);
21674 /* For DW_FORM_data16 see attribute::form_is_constant. */
21675 complaint (_("Attribute value is not a constant (%s)"),
21676 dwarf_form_name (attr
->form
));
21677 return default_value
;
21681 /* Follow reference or signature attribute ATTR of SRC_DIE.
21682 On entry *REF_CU is the CU of SRC_DIE.
21683 On exit *REF_CU is the CU of the result. */
21685 static struct die_info
*
21686 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21687 struct dwarf2_cu
**ref_cu
)
21689 struct die_info
*die
;
21691 if (attr
->form_is_ref ())
21692 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21693 else if (attr
->form
== DW_FORM_ref_sig8
)
21694 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21697 dump_die_for_error (src_die
);
21698 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21699 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21705 /* Follow reference OFFSET.
21706 On entry *REF_CU is the CU of the source die referencing OFFSET.
21707 On exit *REF_CU is the CU of the result.
21708 Returns NULL if OFFSET is invalid. */
21710 static struct die_info
*
21711 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21712 struct dwarf2_cu
**ref_cu
)
21714 struct die_info temp_die
;
21715 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21716 struct dwarf2_per_objfile
*dwarf2_per_objfile
21717 = cu
->per_cu
->dwarf2_per_objfile
;
21719 gdb_assert (cu
->per_cu
!= NULL
);
21723 if (cu
->per_cu
->is_debug_types
)
21725 /* .debug_types CUs cannot reference anything outside their CU.
21726 If they need to, they have to reference a signatured type via
21727 DW_FORM_ref_sig8. */
21728 if (!cu
->header
.offset_in_cu_p (sect_off
))
21731 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21732 || !cu
->header
.offset_in_cu_p (sect_off
))
21734 struct dwarf2_per_cu_data
*per_cu
;
21736 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21737 dwarf2_per_objfile
);
21739 /* If necessary, add it to the queue and load its DIEs. */
21740 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21741 load_full_comp_unit (per_cu
, false, cu
->language
);
21743 target_cu
= per_cu
->cu
;
21745 else if (cu
->dies
== NULL
)
21747 /* We're loading full DIEs during partial symbol reading. */
21748 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21749 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21752 *ref_cu
= target_cu
;
21753 temp_die
.sect_off
= sect_off
;
21755 if (target_cu
!= cu
)
21756 target_cu
->ancestor
= cu
;
21758 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21760 to_underlying (sect_off
));
21763 /* Follow reference attribute ATTR of SRC_DIE.
21764 On entry *REF_CU is the CU of SRC_DIE.
21765 On exit *REF_CU is the CU of the result. */
21767 static struct die_info
*
21768 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21769 struct dwarf2_cu
**ref_cu
)
21771 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21772 struct dwarf2_cu
*cu
= *ref_cu
;
21773 struct die_info
*die
;
21775 die
= follow_die_offset (sect_off
,
21776 (attr
->form
== DW_FORM_GNU_ref_alt
21777 || cu
->per_cu
->is_dwz
),
21780 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21781 "at %s [in module %s]"),
21782 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21783 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21790 struct dwarf2_locexpr_baton
21791 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21792 dwarf2_per_cu_data
*per_cu
,
21793 CORE_ADDR (*get_frame_pc
) (void *baton
),
21794 void *baton
, bool resolve_abstract_p
)
21796 struct dwarf2_cu
*cu
;
21797 struct die_info
*die
;
21798 struct attribute
*attr
;
21799 struct dwarf2_locexpr_baton retval
;
21800 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21801 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21803 if (per_cu
->cu
== NULL
)
21804 load_cu (per_cu
, false);
21808 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21809 Instead just throw an error, not much else we can do. */
21810 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21811 sect_offset_str (sect_off
), objfile_name (objfile
));
21814 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21816 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21817 sect_offset_str (sect_off
), objfile_name (objfile
));
21819 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21820 if (!attr
&& resolve_abstract_p
21821 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21822 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21824 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21825 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21826 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21828 for (const auto &cand_off
21829 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21831 struct dwarf2_cu
*cand_cu
= cu
;
21832 struct die_info
*cand
21833 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21836 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21839 CORE_ADDR pc_low
, pc_high
;
21840 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21841 if (pc_low
== ((CORE_ADDR
) -1))
21843 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21844 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21845 if (!(pc_low
<= pc
&& pc
< pc_high
))
21849 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21856 /* DWARF: "If there is no such attribute, then there is no effect.".
21857 DATA is ignored if SIZE is 0. */
21859 retval
.data
= NULL
;
21862 else if (attr
->form_is_section_offset ())
21864 struct dwarf2_loclist_baton loclist_baton
;
21865 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21868 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21870 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21872 retval
.size
= size
;
21876 if (!attr
->form_is_block ())
21877 error (_("Dwarf Error: DIE at %s referenced in module %s "
21878 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21879 sect_offset_str (sect_off
), objfile_name (objfile
));
21881 retval
.data
= DW_BLOCK (attr
)->data
;
21882 retval
.size
= DW_BLOCK (attr
)->size
;
21884 retval
.per_cu
= cu
->per_cu
;
21886 age_cached_comp_units (dwarf2_per_objfile
);
21893 struct dwarf2_locexpr_baton
21894 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21895 dwarf2_per_cu_data
*per_cu
,
21896 CORE_ADDR (*get_frame_pc
) (void *baton
),
21899 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21901 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21904 /* Write a constant of a given type as target-ordered bytes into
21907 static const gdb_byte
*
21908 write_constant_as_bytes (struct obstack
*obstack
,
21909 enum bfd_endian byte_order
,
21916 *len
= TYPE_LENGTH (type
);
21917 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21918 store_unsigned_integer (result
, *len
, byte_order
, value
);
21926 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21927 dwarf2_per_cu_data
*per_cu
,
21931 struct dwarf2_cu
*cu
;
21932 struct die_info
*die
;
21933 struct attribute
*attr
;
21934 const gdb_byte
*result
= NULL
;
21937 enum bfd_endian byte_order
;
21938 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
21940 if (per_cu
->cu
== NULL
)
21941 load_cu (per_cu
, false);
21945 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21946 Instead just throw an error, not much else we can do. */
21947 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21948 sect_offset_str (sect_off
), objfile_name (objfile
));
21951 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21953 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21954 sect_offset_str (sect_off
), objfile_name (objfile
));
21956 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21960 byte_order
= (bfd_big_endian (objfile
->obfd
)
21961 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21963 switch (attr
->form
)
21966 case DW_FORM_addrx
:
21967 case DW_FORM_GNU_addr_index
:
21971 *len
= cu
->header
.addr_size
;
21972 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21973 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
21977 case DW_FORM_string
:
21980 case DW_FORM_GNU_str_index
:
21981 case DW_FORM_GNU_strp_alt
:
21982 /* DW_STRING is already allocated on the objfile obstack, point
21984 result
= (const gdb_byte
*) DW_STRING (attr
);
21985 *len
= strlen (DW_STRING (attr
));
21987 case DW_FORM_block1
:
21988 case DW_FORM_block2
:
21989 case DW_FORM_block4
:
21990 case DW_FORM_block
:
21991 case DW_FORM_exprloc
:
21992 case DW_FORM_data16
:
21993 result
= DW_BLOCK (attr
)->data
;
21994 *len
= DW_BLOCK (attr
)->size
;
21997 /* The DW_AT_const_value attributes are supposed to carry the
21998 symbol's value "represented as it would be on the target
21999 architecture." By the time we get here, it's already been
22000 converted to host endianness, so we just need to sign- or
22001 zero-extend it as appropriate. */
22002 case DW_FORM_data1
:
22003 type
= die_type (die
, cu
);
22004 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22005 if (result
== NULL
)
22006 result
= write_constant_as_bytes (obstack
, byte_order
,
22009 case DW_FORM_data2
:
22010 type
= die_type (die
, cu
);
22011 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22012 if (result
== NULL
)
22013 result
= write_constant_as_bytes (obstack
, byte_order
,
22016 case DW_FORM_data4
:
22017 type
= die_type (die
, cu
);
22018 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22019 if (result
== NULL
)
22020 result
= write_constant_as_bytes (obstack
, byte_order
,
22023 case DW_FORM_data8
:
22024 type
= die_type (die
, cu
);
22025 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22026 if (result
== NULL
)
22027 result
= write_constant_as_bytes (obstack
, byte_order
,
22031 case DW_FORM_sdata
:
22032 case DW_FORM_implicit_const
:
22033 type
= die_type (die
, cu
);
22034 result
= write_constant_as_bytes (obstack
, byte_order
,
22035 type
, DW_SND (attr
), len
);
22038 case DW_FORM_udata
:
22039 type
= die_type (die
, cu
);
22040 result
= write_constant_as_bytes (obstack
, byte_order
,
22041 type
, DW_UNSND (attr
), len
);
22045 complaint (_("unsupported const value attribute form: '%s'"),
22046 dwarf_form_name (attr
->form
));
22056 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22057 dwarf2_per_cu_data
*per_cu
)
22059 struct dwarf2_cu
*cu
;
22060 struct die_info
*die
;
22062 if (per_cu
->cu
== NULL
)
22063 load_cu (per_cu
, false);
22068 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22072 return die_type (die
, cu
);
22078 dwarf2_get_die_type (cu_offset die_offset
,
22079 struct dwarf2_per_cu_data
*per_cu
)
22081 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22082 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22085 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22086 On entry *REF_CU is the CU of SRC_DIE.
22087 On exit *REF_CU is the CU of the result.
22088 Returns NULL if the referenced DIE isn't found. */
22090 static struct die_info
*
22091 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22092 struct dwarf2_cu
**ref_cu
)
22094 struct die_info temp_die
;
22095 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22096 struct die_info
*die
;
22098 /* While it might be nice to assert sig_type->type == NULL here,
22099 we can get here for DW_AT_imported_declaration where we need
22100 the DIE not the type. */
22102 /* If necessary, add it to the queue and load its DIEs. */
22104 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22105 read_signatured_type (sig_type
);
22107 sig_cu
= sig_type
->per_cu
.cu
;
22108 gdb_assert (sig_cu
!= NULL
);
22109 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22110 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22111 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22112 to_underlying (temp_die
.sect_off
));
22115 struct dwarf2_per_objfile
*dwarf2_per_objfile
22116 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22118 /* For .gdb_index version 7 keep track of included TUs.
22119 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22120 if (dwarf2_per_objfile
->index_table
!= NULL
22121 && dwarf2_per_objfile
->index_table
->version
<= 7)
22123 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22128 sig_cu
->ancestor
= cu
;
22136 /* Follow signatured type referenced by ATTR in SRC_DIE.
22137 On entry *REF_CU is the CU of SRC_DIE.
22138 On exit *REF_CU is the CU of the result.
22139 The result is the DIE of the type.
22140 If the referenced type cannot be found an error is thrown. */
22142 static struct die_info
*
22143 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22144 struct dwarf2_cu
**ref_cu
)
22146 ULONGEST signature
= DW_SIGNATURE (attr
);
22147 struct signatured_type
*sig_type
;
22148 struct die_info
*die
;
22150 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22152 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22153 /* sig_type will be NULL if the signatured type is missing from
22155 if (sig_type
== NULL
)
22157 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22158 " from DIE at %s [in module %s]"),
22159 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22160 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22163 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22166 dump_die_for_error (src_die
);
22167 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22168 " from DIE at %s [in module %s]"),
22169 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22170 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22176 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22177 reading in and processing the type unit if necessary. */
22179 static struct type
*
22180 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22181 struct dwarf2_cu
*cu
)
22183 struct dwarf2_per_objfile
*dwarf2_per_objfile
22184 = cu
->per_cu
->dwarf2_per_objfile
;
22185 struct signatured_type
*sig_type
;
22186 struct dwarf2_cu
*type_cu
;
22187 struct die_info
*type_die
;
22190 sig_type
= lookup_signatured_type (cu
, signature
);
22191 /* sig_type will be NULL if the signatured type is missing from
22193 if (sig_type
== NULL
)
22195 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22196 " from DIE at %s [in module %s]"),
22197 hex_string (signature
), sect_offset_str (die
->sect_off
),
22198 objfile_name (dwarf2_per_objfile
->objfile
));
22199 return build_error_marker_type (cu
, die
);
22202 /* If we already know the type we're done. */
22203 if (sig_type
->type
!= NULL
)
22204 return sig_type
->type
;
22207 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22208 if (type_die
!= NULL
)
22210 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22211 is created. This is important, for example, because for c++ classes
22212 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22213 type
= read_type_die (type_die
, type_cu
);
22216 complaint (_("Dwarf Error: Cannot build signatured type %s"
22217 " referenced from DIE at %s [in module %s]"),
22218 hex_string (signature
), sect_offset_str (die
->sect_off
),
22219 objfile_name (dwarf2_per_objfile
->objfile
));
22220 type
= build_error_marker_type (cu
, die
);
22225 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22226 " from DIE at %s [in module %s]"),
22227 hex_string (signature
), sect_offset_str (die
->sect_off
),
22228 objfile_name (dwarf2_per_objfile
->objfile
));
22229 type
= build_error_marker_type (cu
, die
);
22231 sig_type
->type
= type
;
22236 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22237 reading in and processing the type unit if necessary. */
22239 static struct type
*
22240 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22241 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22243 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22244 if (attr
->form_is_ref ())
22246 struct dwarf2_cu
*type_cu
= cu
;
22247 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22249 return read_type_die (type_die
, type_cu
);
22251 else if (attr
->form
== DW_FORM_ref_sig8
)
22253 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22257 struct dwarf2_per_objfile
*dwarf2_per_objfile
22258 = cu
->per_cu
->dwarf2_per_objfile
;
22260 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22261 " at %s [in module %s]"),
22262 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22263 objfile_name (dwarf2_per_objfile
->objfile
));
22264 return build_error_marker_type (cu
, die
);
22268 /* Load the DIEs associated with type unit PER_CU into memory. */
22271 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22273 struct signatured_type
*sig_type
;
22275 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22276 gdb_assert (! per_cu
->type_unit_group_p ());
22278 /* We have the per_cu, but we need the signatured_type.
22279 Fortunately this is an easy translation. */
22280 gdb_assert (per_cu
->is_debug_types
);
22281 sig_type
= (struct signatured_type
*) per_cu
;
22283 gdb_assert (per_cu
->cu
== NULL
);
22285 read_signatured_type (sig_type
);
22287 gdb_assert (per_cu
->cu
!= NULL
);
22290 /* Read in a signatured type and build its CU and DIEs.
22291 If the type is a stub for the real type in a DWO file,
22292 read in the real type from the DWO file as well. */
22295 read_signatured_type (struct signatured_type
*sig_type
)
22297 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22299 gdb_assert (per_cu
->is_debug_types
);
22300 gdb_assert (per_cu
->cu
== NULL
);
22302 cutu_reader
reader (per_cu
, NULL
, 0, false);
22304 if (!reader
.dummy_p
)
22306 struct dwarf2_cu
*cu
= reader
.cu
;
22307 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22309 gdb_assert (cu
->die_hash
== NULL
);
22311 htab_create_alloc_ex (cu
->header
.length
/ 12,
22315 &cu
->comp_unit_obstack
,
22316 hashtab_obstack_allocate
,
22317 dummy_obstack_deallocate
);
22319 if (reader
.comp_unit_die
->has_children
)
22320 reader
.comp_unit_die
->child
22321 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22322 reader
.comp_unit_die
);
22323 cu
->dies
= reader
.comp_unit_die
;
22324 /* comp_unit_die is not stored in die_hash, no need. */
22326 /* We try not to read any attributes in this function, because
22327 not all CUs needed for references have been loaded yet, and
22328 symbol table processing isn't initialized. But we have to
22329 set the CU language, or we won't be able to build types
22330 correctly. Similarly, if we do not read the producer, we can
22331 not apply producer-specific interpretation. */
22332 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22337 sig_type
->per_cu
.tu_read
= 1;
22340 /* Decode simple location descriptions.
22341 Given a pointer to a dwarf block that defines a location, compute
22342 the location and return the value.
22344 NOTE drow/2003-11-18: This function is called in two situations
22345 now: for the address of static or global variables (partial symbols
22346 only) and for offsets into structures which are expected to be
22347 (more or less) constant. The partial symbol case should go away,
22348 and only the constant case should remain. That will let this
22349 function complain more accurately. A few special modes are allowed
22350 without complaint for global variables (for instance, global
22351 register values and thread-local values).
22353 A location description containing no operations indicates that the
22354 object is optimized out. The return value is 0 for that case.
22355 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22356 callers will only want a very basic result and this can become a
22359 Note that stack[0] is unused except as a default error return. */
22362 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22364 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22366 size_t size
= blk
->size
;
22367 const gdb_byte
*data
= blk
->data
;
22368 CORE_ADDR stack
[64];
22370 unsigned int bytes_read
, unsnd
;
22376 stack
[++stacki
] = 0;
22415 stack
[++stacki
] = op
- DW_OP_lit0
;
22450 stack
[++stacki
] = op
- DW_OP_reg0
;
22452 dwarf2_complex_location_expr_complaint ();
22456 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22458 stack
[++stacki
] = unsnd
;
22460 dwarf2_complex_location_expr_complaint ();
22464 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22469 case DW_OP_const1u
:
22470 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22474 case DW_OP_const1s
:
22475 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22479 case DW_OP_const2u
:
22480 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22484 case DW_OP_const2s
:
22485 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22489 case DW_OP_const4u
:
22490 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22494 case DW_OP_const4s
:
22495 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22499 case DW_OP_const8u
:
22500 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22505 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22511 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22516 stack
[stacki
+ 1] = stack
[stacki
];
22521 stack
[stacki
- 1] += stack
[stacki
];
22525 case DW_OP_plus_uconst
:
22526 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22532 stack
[stacki
- 1] -= stack
[stacki
];
22537 /* If we're not the last op, then we definitely can't encode
22538 this using GDB's address_class enum. This is valid for partial
22539 global symbols, although the variable's address will be bogus
22542 dwarf2_complex_location_expr_complaint ();
22545 case DW_OP_GNU_push_tls_address
:
22546 case DW_OP_form_tls_address
:
22547 /* The top of the stack has the offset from the beginning
22548 of the thread control block at which the variable is located. */
22549 /* Nothing should follow this operator, so the top of stack would
22551 /* This is valid for partial global symbols, but the variable's
22552 address will be bogus in the psymtab. Make it always at least
22553 non-zero to not look as a variable garbage collected by linker
22554 which have DW_OP_addr 0. */
22556 dwarf2_complex_location_expr_complaint ();
22560 case DW_OP_GNU_uninit
:
22564 case DW_OP_GNU_addr_index
:
22565 case DW_OP_GNU_const_index
:
22566 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22573 const char *name
= get_DW_OP_name (op
);
22576 complaint (_("unsupported stack op: '%s'"),
22579 complaint (_("unsupported stack op: '%02x'"),
22583 return (stack
[stacki
]);
22586 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22587 outside of the allocated space. Also enforce minimum>0. */
22588 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22590 complaint (_("location description stack overflow"));
22596 complaint (_("location description stack underflow"));
22600 return (stack
[stacki
]);
22603 /* memory allocation interface */
22605 static struct dwarf_block
*
22606 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22608 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22611 static struct die_info
*
22612 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22614 struct die_info
*die
;
22615 size_t size
= sizeof (struct die_info
);
22618 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22620 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22621 memset (die
, 0, sizeof (struct die_info
));
22627 /* Macro support. */
22629 /* An overload of dwarf_decode_macros that finds the correct section
22630 and ensures it is read in before calling the other overload. */
22633 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22634 int section_is_gnu
)
22636 struct dwarf2_per_objfile
*dwarf2_per_objfile
22637 = cu
->per_cu
->dwarf2_per_objfile
;
22638 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22639 const struct line_header
*lh
= cu
->line_header
;
22640 unsigned int offset_size
= cu
->header
.offset_size
;
22641 struct dwarf2_section_info
*section
;
22642 const char *section_name
;
22644 if (cu
->dwo_unit
!= nullptr)
22646 if (section_is_gnu
)
22648 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22649 section_name
= ".debug_macro.dwo";
22653 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22654 section_name
= ".debug_macinfo.dwo";
22659 if (section_is_gnu
)
22661 section
= &dwarf2_per_objfile
->macro
;
22662 section_name
= ".debug_macro";
22666 section
= &dwarf2_per_objfile
->macinfo
;
22667 section_name
= ".debug_macinfo";
22671 section
->read (objfile
);
22672 if (section
->buffer
== nullptr)
22674 complaint (_("missing %s section"), section_name
);
22678 buildsym_compunit
*builder
= cu
->get_builder ();
22680 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22681 offset_size
, offset
, section_is_gnu
);
22684 /* Return the .debug_loc section to use for CU.
22685 For DWO files use .debug_loc.dwo. */
22687 static struct dwarf2_section_info
*
22688 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22690 struct dwarf2_per_objfile
*dwarf2_per_objfile
22691 = cu
->per_cu
->dwarf2_per_objfile
;
22695 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22697 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22699 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22700 : &dwarf2_per_objfile
->loc
);
22703 /* A helper function that fills in a dwarf2_loclist_baton. */
22706 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22707 struct dwarf2_loclist_baton
*baton
,
22708 const struct attribute
*attr
)
22710 struct dwarf2_per_objfile
*dwarf2_per_objfile
22711 = cu
->per_cu
->dwarf2_per_objfile
;
22712 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22714 section
->read (dwarf2_per_objfile
->objfile
);
22716 baton
->per_cu
= cu
->per_cu
;
22717 gdb_assert (baton
->per_cu
);
22718 /* We don't know how long the location list is, but make sure we
22719 don't run off the edge of the section. */
22720 baton
->size
= section
->size
- DW_UNSND (attr
);
22721 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22722 if (cu
->base_address
.has_value ())
22723 baton
->base_address
= *cu
->base_address
;
22725 baton
->base_address
= 0;
22726 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22730 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22731 struct dwarf2_cu
*cu
, int is_block
)
22733 struct dwarf2_per_objfile
*dwarf2_per_objfile
22734 = cu
->per_cu
->dwarf2_per_objfile
;
22735 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22736 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22738 if (attr
->form_is_section_offset ()
22739 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22740 the section. If so, fall through to the complaint in the
22742 && DW_UNSND (attr
) < section
->get_size (objfile
))
22744 struct dwarf2_loclist_baton
*baton
;
22746 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22748 fill_in_loclist_baton (cu
, baton
, attr
);
22750 if (!cu
->base_address
.has_value ())
22751 complaint (_("Location list used without "
22752 "specifying the CU base address."));
22754 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22755 ? dwarf2_loclist_block_index
22756 : dwarf2_loclist_index
);
22757 SYMBOL_LOCATION_BATON (sym
) = baton
;
22761 struct dwarf2_locexpr_baton
*baton
;
22763 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22764 baton
->per_cu
= cu
->per_cu
;
22765 gdb_assert (baton
->per_cu
);
22767 if (attr
->form_is_block ())
22769 /* Note that we're just copying the block's data pointer
22770 here, not the actual data. We're still pointing into the
22771 info_buffer for SYM's objfile; right now we never release
22772 that buffer, but when we do clean up properly this may
22774 baton
->size
= DW_BLOCK (attr
)->size
;
22775 baton
->data
= DW_BLOCK (attr
)->data
;
22779 dwarf2_invalid_attrib_class_complaint ("location description",
22780 sym
->natural_name ());
22784 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22785 ? dwarf2_locexpr_block_index
22786 : dwarf2_locexpr_index
);
22787 SYMBOL_LOCATION_BATON (sym
) = baton
;
22794 dwarf2_per_cu_data::objfile () const
22796 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22798 /* Return the master objfile, so that we can report and look up the
22799 correct file containing this variable. */
22800 if (objfile
->separate_debug_objfile_backlink
)
22801 objfile
= objfile
->separate_debug_objfile_backlink
;
22806 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22807 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22808 CU_HEADERP first. */
22810 static const struct comp_unit_head
*
22811 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22812 const struct dwarf2_per_cu_data
*per_cu
)
22814 const gdb_byte
*info_ptr
;
22817 return &per_cu
->cu
->header
;
22819 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22821 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22822 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22823 rcuh_kind::COMPILE
);
22831 dwarf2_per_cu_data::addr_size () const
22833 struct comp_unit_head cu_header_local
;
22834 const struct comp_unit_head
*cu_headerp
;
22836 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22838 return cu_headerp
->addr_size
;
22844 dwarf2_per_cu_data::offset_size () const
22846 struct comp_unit_head cu_header_local
;
22847 const struct comp_unit_head
*cu_headerp
;
22849 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22851 return cu_headerp
->offset_size
;
22857 dwarf2_per_cu_data::ref_addr_size () const
22859 struct comp_unit_head cu_header_local
;
22860 const struct comp_unit_head
*cu_headerp
;
22862 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22864 if (cu_headerp
->version
== 2)
22865 return cu_headerp
->addr_size
;
22867 return cu_headerp
->offset_size
;
22873 dwarf2_per_cu_data::text_offset () const
22875 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22877 return objfile
->text_section_offset ();
22883 dwarf2_per_cu_data::addr_type () const
22885 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22886 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22887 struct type
*addr_type
= lookup_pointer_type (void_type
);
22888 int addr_size
= this->addr_size ();
22890 if (TYPE_LENGTH (addr_type
) == addr_size
)
22893 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22897 /* A helper function for dwarf2_find_containing_comp_unit that returns
22898 the index of the result, and that searches a vector. It will
22899 return a result even if the offset in question does not actually
22900 occur in any CU. This is separate so that it can be unit
22904 dwarf2_find_containing_comp_unit
22905 (sect_offset sect_off
,
22906 unsigned int offset_in_dwz
,
22907 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22912 high
= all_comp_units
.size () - 1;
22915 struct dwarf2_per_cu_data
*mid_cu
;
22916 int mid
= low
+ (high
- low
) / 2;
22918 mid_cu
= all_comp_units
[mid
];
22919 if (mid_cu
->is_dwz
> offset_in_dwz
22920 || (mid_cu
->is_dwz
== offset_in_dwz
22921 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
22926 gdb_assert (low
== high
);
22930 /* Locate the .debug_info compilation unit from CU's objfile which contains
22931 the DIE at OFFSET. Raises an error on failure. */
22933 static struct dwarf2_per_cu_data
*
22934 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22935 unsigned int offset_in_dwz
,
22936 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22939 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22940 dwarf2_per_objfile
->all_comp_units
);
22941 struct dwarf2_per_cu_data
*this_cu
22942 = dwarf2_per_objfile
->all_comp_units
[low
];
22944 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
22946 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22947 error (_("Dwarf Error: could not find partial DIE containing "
22948 "offset %s [in module %s]"),
22949 sect_offset_str (sect_off
),
22950 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
22952 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22954 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22958 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
22959 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
22960 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
22961 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
22968 namespace selftests
{
22969 namespace find_containing_comp_unit
{
22974 struct dwarf2_per_cu_data one
{};
22975 struct dwarf2_per_cu_data two
{};
22976 struct dwarf2_per_cu_data three
{};
22977 struct dwarf2_per_cu_data four
{};
22980 two
.sect_off
= sect_offset (one
.length
);
22985 four
.sect_off
= sect_offset (three
.length
);
22989 std::vector
<dwarf2_per_cu_data
*> units
;
22990 units
.push_back (&one
);
22991 units
.push_back (&two
);
22992 units
.push_back (&three
);
22993 units
.push_back (&four
);
22997 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
22998 SELF_CHECK (units
[result
] == &one
);
22999 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23000 SELF_CHECK (units
[result
] == &one
);
23001 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23002 SELF_CHECK (units
[result
] == &two
);
23004 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23005 SELF_CHECK (units
[result
] == &three
);
23006 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23007 SELF_CHECK (units
[result
] == &three
);
23008 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23009 SELF_CHECK (units
[result
] == &four
);
23015 #endif /* GDB_SELF_TEST */
23017 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23019 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23020 : per_cu (per_cu_
),
23022 has_loclist (false),
23023 checked_producer (false),
23024 producer_is_gxx_lt_4_6 (false),
23025 producer_is_gcc_lt_4_3 (false),
23026 producer_is_icc (false),
23027 producer_is_icc_lt_14 (false),
23028 producer_is_codewarrior (false),
23029 processing_has_namespace_info (false)
23034 /* Destroy a dwarf2_cu. */
23036 dwarf2_cu::~dwarf2_cu ()
23041 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23044 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23045 enum language pretend_language
)
23047 struct attribute
*attr
;
23049 /* Set the language we're debugging. */
23050 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23051 if (attr
!= nullptr)
23052 set_cu_language (DW_UNSND (attr
), cu
);
23055 cu
->language
= pretend_language
;
23056 cu
->language_defn
= language_def (cu
->language
);
23059 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23062 /* Increase the age counter on each cached compilation unit, and free
23063 any that are too old. */
23066 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23068 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23070 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23071 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23072 while (per_cu
!= NULL
)
23074 per_cu
->cu
->last_used
++;
23075 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23076 dwarf2_mark (per_cu
->cu
);
23077 per_cu
= per_cu
->cu
->read_in_chain
;
23080 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23081 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23082 while (per_cu
!= NULL
)
23084 struct dwarf2_per_cu_data
*next_cu
;
23086 next_cu
= per_cu
->cu
->read_in_chain
;
23088 if (!per_cu
->cu
->mark
)
23091 *last_chain
= next_cu
;
23094 last_chain
= &per_cu
->cu
->read_in_chain
;
23100 /* Remove a single compilation unit from the cache. */
23103 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23105 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23106 struct dwarf2_per_objfile
*dwarf2_per_objfile
23107 = target_per_cu
->dwarf2_per_objfile
;
23109 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23110 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23111 while (per_cu
!= NULL
)
23113 struct dwarf2_per_cu_data
*next_cu
;
23115 next_cu
= per_cu
->cu
->read_in_chain
;
23117 if (per_cu
== target_per_cu
)
23121 *last_chain
= next_cu
;
23125 last_chain
= &per_cu
->cu
->read_in_chain
;
23131 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23132 We store these in a hash table separate from the DIEs, and preserve them
23133 when the DIEs are flushed out of cache.
23135 The CU "per_cu" pointer is needed because offset alone is not enough to
23136 uniquely identify the type. A file may have multiple .debug_types sections,
23137 or the type may come from a DWO file. Furthermore, while it's more logical
23138 to use per_cu->section+offset, with Fission the section with the data is in
23139 the DWO file but we don't know that section at the point we need it.
23140 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23141 because we can enter the lookup routine, get_die_type_at_offset, from
23142 outside this file, and thus won't necessarily have PER_CU->cu.
23143 Fortunately, PER_CU is stable for the life of the objfile. */
23145 struct dwarf2_per_cu_offset_and_type
23147 const struct dwarf2_per_cu_data
*per_cu
;
23148 sect_offset sect_off
;
23152 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23155 per_cu_offset_and_type_hash (const void *item
)
23157 const struct dwarf2_per_cu_offset_and_type
*ofs
23158 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23160 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23163 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23166 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23168 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23169 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23170 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23171 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23173 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23174 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23177 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23178 table if necessary. For convenience, return TYPE.
23180 The DIEs reading must have careful ordering to:
23181 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23182 reading current DIE.
23183 * Not trying to dereference contents of still incompletely read in types
23184 while reading in other DIEs.
23185 * Enable referencing still incompletely read in types just by a pointer to
23186 the type without accessing its fields.
23188 Therefore caller should follow these rules:
23189 * Try to fetch any prerequisite types we may need to build this DIE type
23190 before building the type and calling set_die_type.
23191 * After building type call set_die_type for current DIE as soon as
23192 possible before fetching more types to complete the current type.
23193 * Make the type as complete as possible before fetching more types. */
23195 static struct type
*
23196 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23198 struct dwarf2_per_objfile
*dwarf2_per_objfile
23199 = cu
->per_cu
->dwarf2_per_objfile
;
23200 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23201 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23202 struct attribute
*attr
;
23203 struct dynamic_prop prop
;
23205 /* For Ada types, make sure that the gnat-specific data is always
23206 initialized (if not already set). There are a few types where
23207 we should not be doing so, because the type-specific area is
23208 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23209 where the type-specific area is used to store the floatformat).
23210 But this is not a problem, because the gnat-specific information
23211 is actually not needed for these types. */
23212 if (need_gnat_info (cu
)
23213 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23214 && TYPE_CODE (type
) != TYPE_CODE_FLT
23215 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23216 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23217 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23218 && !HAVE_GNAT_AUX_INFO (type
))
23219 INIT_GNAT_SPECIFIC (type
);
23221 /* Read DW_AT_allocated and set in type. */
23222 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23223 if (attr
!= NULL
&& attr
->form_is_block ())
23225 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23226 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23227 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23229 else if (attr
!= NULL
)
23231 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23232 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23233 sect_offset_str (die
->sect_off
));
23236 /* Read DW_AT_associated and set in type. */
23237 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23238 if (attr
!= NULL
&& attr
->form_is_block ())
23240 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23241 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23242 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23244 else if (attr
!= NULL
)
23246 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23247 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23248 sect_offset_str (die
->sect_off
));
23251 /* Read DW_AT_data_location and set in type. */
23252 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23253 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23254 cu
->per_cu
->addr_type ()))
23255 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23257 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23258 dwarf2_per_objfile
->die_type_hash
23259 = htab_up (htab_create_alloc (127,
23260 per_cu_offset_and_type_hash
,
23261 per_cu_offset_and_type_eq
,
23262 NULL
, xcalloc
, xfree
));
23264 ofs
.per_cu
= cu
->per_cu
;
23265 ofs
.sect_off
= die
->sect_off
;
23267 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23268 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23270 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23271 sect_offset_str (die
->sect_off
));
23272 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23273 struct dwarf2_per_cu_offset_and_type
);
23278 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23279 or return NULL if the die does not have a saved type. */
23281 static struct type
*
23282 get_die_type_at_offset (sect_offset sect_off
,
23283 struct dwarf2_per_cu_data
*per_cu
)
23285 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23286 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23288 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23291 ofs
.per_cu
= per_cu
;
23292 ofs
.sect_off
= sect_off
;
23293 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23294 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23301 /* Look up the type for DIE in CU in die_type_hash,
23302 or return NULL if DIE does not have a saved type. */
23304 static struct type
*
23305 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23307 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23310 /* Add a dependence relationship from CU to REF_PER_CU. */
23313 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23314 struct dwarf2_per_cu_data
*ref_per_cu
)
23318 if (cu
->dependencies
== NULL
)
23320 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23321 NULL
, &cu
->comp_unit_obstack
,
23322 hashtab_obstack_allocate
,
23323 dummy_obstack_deallocate
);
23325 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23327 *slot
= ref_per_cu
;
23330 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23331 Set the mark field in every compilation unit in the
23332 cache that we must keep because we are keeping CU. */
23335 dwarf2_mark_helper (void **slot
, void *data
)
23337 struct dwarf2_per_cu_data
*per_cu
;
23339 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23341 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23342 reading of the chain. As such dependencies remain valid it is not much
23343 useful to track and undo them during QUIT cleanups. */
23344 if (per_cu
->cu
== NULL
)
23347 if (per_cu
->cu
->mark
)
23349 per_cu
->cu
->mark
= true;
23351 if (per_cu
->cu
->dependencies
!= NULL
)
23352 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23357 /* Set the mark field in CU and in every other compilation unit in the
23358 cache that we must keep because we are keeping CU. */
23361 dwarf2_mark (struct dwarf2_cu
*cu
)
23366 if (cu
->dependencies
!= NULL
)
23367 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23371 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23375 per_cu
->cu
->mark
= false;
23376 per_cu
= per_cu
->cu
->read_in_chain
;
23380 /* Trivial hash function for partial_die_info: the hash value of a DIE
23381 is its offset in .debug_info for this objfile. */
23384 partial_die_hash (const void *item
)
23386 const struct partial_die_info
*part_die
23387 = (const struct partial_die_info
*) item
;
23389 return to_underlying (part_die
->sect_off
);
23392 /* Trivial comparison function for partial_die_info structures: two DIEs
23393 are equal if they have the same offset. */
23396 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23398 const struct partial_die_info
*part_die_lhs
23399 = (const struct partial_die_info
*) item_lhs
;
23400 const struct partial_die_info
*part_die_rhs
23401 = (const struct partial_die_info
*) item_rhs
;
23403 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23406 struct cmd_list_element
*set_dwarf_cmdlist
;
23407 struct cmd_list_element
*show_dwarf_cmdlist
;
23410 set_dwarf_cmd (const char *args
, int from_tty
)
23412 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23417 show_dwarf_cmd (const char *args
, int from_tty
)
23419 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23423 show_check_physname (struct ui_file
*file
, int from_tty
,
23424 struct cmd_list_element
*c
, const char *value
)
23426 fprintf_filtered (file
,
23427 _("Whether to check \"physname\" is %s.\n"),
23431 void _initialize_dwarf2_read ();
23433 _initialize_dwarf2_read ()
23435 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23436 Set DWARF specific variables.\n\
23437 Configure DWARF variables such as the cache size."),
23438 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23439 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23441 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23442 Show DWARF specific variables.\n\
23443 Show DWARF variables such as the cache size."),
23444 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23445 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23447 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23448 &dwarf_max_cache_age
, _("\
23449 Set the upper bound on the age of cached DWARF compilation units."), _("\
23450 Show the upper bound on the age of cached DWARF compilation units."), _("\
23451 A higher limit means that cached compilation units will be stored\n\
23452 in memory longer, and more total memory will be used. Zero disables\n\
23453 caching, which can slow down startup."),
23455 show_dwarf_max_cache_age
,
23456 &set_dwarf_cmdlist
,
23457 &show_dwarf_cmdlist
);
23459 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23460 Set debugging of the DWARF reader."), _("\
23461 Show debugging of the DWARF reader."), _("\
23462 When enabled (non-zero), debugging messages are printed during DWARF\n\
23463 reading and symtab expansion. A value of 1 (one) provides basic\n\
23464 information. A value greater than 1 provides more verbose information."),
23467 &setdebuglist
, &showdebuglist
);
23469 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23470 Set debugging of the DWARF DIE reader."), _("\
23471 Show debugging of the DWARF DIE reader."), _("\
23472 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23473 The value is the maximum depth to print."),
23476 &setdebuglist
, &showdebuglist
);
23478 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23479 Set debugging of the dwarf line reader."), _("\
23480 Show debugging of the dwarf line reader."), _("\
23481 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23482 A value of 1 (one) provides basic information.\n\
23483 A value greater than 1 provides more verbose information."),
23486 &setdebuglist
, &showdebuglist
);
23488 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23489 Set cross-checking of \"physname\" code against demangler."), _("\
23490 Show cross-checking of \"physname\" code against demangler."), _("\
23491 When enabled, GDB's internal \"physname\" code is checked against\n\
23493 NULL
, show_check_physname
,
23494 &setdebuglist
, &showdebuglist
);
23496 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23497 no_class
, &use_deprecated_index_sections
, _("\
23498 Set whether to use deprecated gdb_index sections."), _("\
23499 Show whether to use deprecated gdb_index sections."), _("\
23500 When enabled, deprecated .gdb_index sections are used anyway.\n\
23501 Normally they are ignored either because of a missing feature or\n\
23502 performance issue.\n\
23503 Warning: This option must be enabled before gdb reads the file."),
23506 &setlist
, &showlist
);
23508 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23509 &dwarf2_locexpr_funcs
);
23510 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23511 &dwarf2_loclist_funcs
);
23513 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23514 &dwarf2_block_frame_base_locexpr_funcs
);
23515 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23516 &dwarf2_block_frame_base_loclist_funcs
);
23519 selftests::register_test ("dw2_expand_symtabs_matching",
23520 selftests::dw2_expand_symtabs_matching::run_test
);
23521 selftests::register_test ("dwarf2_find_containing_comp_unit",
23522 selftests::find_containing_comp_unit::run_test
);