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 void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1421 static void dump_die_for_error (struct die_info
*);
1423 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1426 /*static*/ void dump_die (struct die_info
*, int max_level
);
1428 static void store_in_ref_table (struct die_info
*,
1429 struct dwarf2_cu
*);
1431 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1433 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1435 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1436 const struct attribute
*,
1437 struct dwarf2_cu
**);
1439 static struct die_info
*follow_die_ref (struct die_info
*,
1440 const struct attribute
*,
1441 struct dwarf2_cu
**);
1443 static struct die_info
*follow_die_sig (struct die_info
*,
1444 const struct attribute
*,
1445 struct dwarf2_cu
**);
1447 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1448 struct dwarf2_cu
*);
1450 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1451 const struct attribute
*,
1452 struct dwarf2_cu
*);
1454 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1456 static void read_signatured_type (struct signatured_type
*);
1458 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1459 struct die_info
*die
, struct dwarf2_cu
*cu
,
1460 struct dynamic_prop
*prop
, struct type
*type
);
1462 /* memory allocation interface */
1464 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1466 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1468 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1470 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1471 struct dwarf2_loclist_baton
*baton
,
1472 const struct attribute
*attr
);
1474 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1476 struct dwarf2_cu
*cu
,
1479 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1480 const gdb_byte
*info_ptr
,
1481 struct abbrev_info
*abbrev
);
1483 static hashval_t
partial_die_hash (const void *item
);
1485 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1487 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1488 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1489 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1491 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1492 struct die_info
*comp_unit_die
,
1493 enum language pretend_language
);
1495 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1497 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1499 static struct type
*set_die_type (struct die_info
*, struct type
*,
1500 struct dwarf2_cu
*);
1502 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1504 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1506 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1509 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1512 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1515 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1516 struct dwarf2_per_cu_data
*);
1518 static void dwarf2_mark (struct dwarf2_cu
*);
1520 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1522 static struct type
*get_die_type_at_offset (sect_offset
,
1523 struct dwarf2_per_cu_data
*);
1525 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1527 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1528 enum language pretend_language
);
1530 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1532 /* Class, the destructor of which frees all allocated queue entries. This
1533 will only have work to do if an error was thrown while processing the
1534 dwarf. If no error was thrown then the queue entries should have all
1535 been processed, and freed, as we went along. */
1537 class dwarf2_queue_guard
1540 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1541 : m_per_objfile (per_objfile
)
1545 /* Free any entries remaining on the queue. There should only be
1546 entries left if we hit an error while processing the dwarf. */
1547 ~dwarf2_queue_guard ()
1549 /* Ensure that no memory is allocated by the queue. */
1550 std::queue
<dwarf2_queue_item
> empty
;
1551 std::swap (m_per_objfile
->queue
, empty
);
1554 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1557 dwarf2_per_objfile
*m_per_objfile
;
1560 dwarf2_queue_item::~dwarf2_queue_item ()
1562 /* Anything still marked queued is likely to be in an
1563 inconsistent state, so discard it. */
1566 if (per_cu
->cu
!= NULL
)
1567 free_one_cached_comp_unit (per_cu
);
1572 /* The return type of find_file_and_directory. Note, the enclosed
1573 string pointers are only valid while this object is valid. */
1575 struct file_and_directory
1577 /* The filename. This is never NULL. */
1580 /* The compilation directory. NULL if not known. If we needed to
1581 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1582 points directly to the DW_AT_comp_dir string attribute owned by
1583 the obstack that owns the DIE. */
1584 const char *comp_dir
;
1586 /* If we needed to build a new string for comp_dir, this is what
1587 owns the storage. */
1588 std::string comp_dir_storage
;
1591 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1592 struct dwarf2_cu
*cu
);
1594 static htab_up
allocate_signatured_type_table ();
1596 static htab_up
allocate_dwo_unit_table ();
1598 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1599 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1600 struct dwp_file
*dwp_file
, const char *comp_dir
,
1601 ULONGEST signature
, int is_debug_types
);
1603 static struct dwp_file
*get_dwp_file
1604 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1606 static struct dwo_unit
*lookup_dwo_comp_unit
1607 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1609 static struct dwo_unit
*lookup_dwo_type_unit
1610 (struct signatured_type
*, const char *, const char *);
1612 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1614 /* A unique pointer to a dwo_file. */
1616 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1618 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1620 static void check_producer (struct dwarf2_cu
*cu
);
1622 static void free_line_header_voidp (void *arg
);
1624 /* Various complaints about symbol reading that don't abort the process. */
1627 dwarf2_debug_line_missing_file_complaint (void)
1629 complaint (_(".debug_line section has line data without a file"));
1633 dwarf2_debug_line_missing_end_sequence_complaint (void)
1635 complaint (_(".debug_line section has line "
1636 "program sequence without an end"));
1640 dwarf2_complex_location_expr_complaint (void)
1642 complaint (_("location expression too complex"));
1646 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1649 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1654 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1656 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1660 /* Hash function for line_header_hash. */
1663 line_header_hash (const struct line_header
*ofs
)
1665 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1668 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1671 line_header_hash_voidp (const void *item
)
1673 const struct line_header
*ofs
= (const struct line_header
*) item
;
1675 return line_header_hash (ofs
);
1678 /* Equality function for line_header_hash. */
1681 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1683 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1684 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1686 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1687 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1692 /* See declaration. */
1694 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1695 const dwarf2_debug_sections
*names
,
1697 : objfile (objfile_
),
1698 can_copy (can_copy_
)
1701 names
= &dwarf2_elf_names
;
1703 bfd
*obfd
= objfile
->obfd
;
1705 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1706 locate_sections (obfd
, sec
, *names
);
1709 dwarf2_per_objfile::~dwarf2_per_objfile ()
1711 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1712 free_cached_comp_units ();
1714 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1715 per_cu
->imported_symtabs_free ();
1717 for (signatured_type
*sig_type
: all_type_units
)
1718 sig_type
->per_cu
.imported_symtabs_free ();
1720 /* Everything else should be on the objfile obstack. */
1723 /* See declaration. */
1726 dwarf2_per_objfile::free_cached_comp_units ()
1728 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1729 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1730 while (per_cu
!= NULL
)
1732 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1735 *last_chain
= next_cu
;
1740 /* A helper class that calls free_cached_comp_units on
1743 class free_cached_comp_units
1747 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1748 : m_per_objfile (per_objfile
)
1752 ~free_cached_comp_units ()
1754 m_per_objfile
->free_cached_comp_units ();
1757 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1761 dwarf2_per_objfile
*m_per_objfile
;
1764 /* Try to locate the sections we need for DWARF 2 debugging
1765 information and return true if we have enough to do something.
1766 NAMES points to the dwarf2 section names, or is NULL if the standard
1767 ELF names are used. CAN_COPY is true for formats where symbol
1768 interposition is possible and so symbol values must follow copy
1769 relocation rules. */
1772 dwarf2_has_info (struct objfile
*objfile
,
1773 const struct dwarf2_debug_sections
*names
,
1776 if (objfile
->flags
& OBJF_READNEVER
)
1779 struct dwarf2_per_objfile
*dwarf2_per_objfile
1780 = get_dwarf2_per_objfile (objfile
);
1782 if (dwarf2_per_objfile
== NULL
)
1783 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1787 return (!dwarf2_per_objfile
->info
.is_virtual
1788 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1789 && !dwarf2_per_objfile
->abbrev
.is_virtual
1790 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1793 /* When loading sections, we look either for uncompressed section or for
1794 compressed section names. */
1797 section_is_p (const char *section_name
,
1798 const struct dwarf2_section_names
*names
)
1800 if (names
->normal
!= NULL
1801 && strcmp (section_name
, names
->normal
) == 0)
1803 if (names
->compressed
!= NULL
1804 && strcmp (section_name
, names
->compressed
) == 0)
1809 /* See declaration. */
1812 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1813 const dwarf2_debug_sections
&names
)
1815 flagword aflag
= bfd_section_flags (sectp
);
1817 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1820 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1821 > bfd_get_file_size (abfd
))
1823 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1824 warning (_("Discarding section %s which has a section size (%s"
1825 ") larger than the file size [in module %s]"),
1826 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1827 bfd_get_filename (abfd
));
1829 else if (section_is_p (sectp
->name
, &names
.info
))
1831 this->info
.s
.section
= sectp
;
1832 this->info
.size
= bfd_section_size (sectp
);
1834 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1836 this->abbrev
.s
.section
= sectp
;
1837 this->abbrev
.size
= bfd_section_size (sectp
);
1839 else if (section_is_p (sectp
->name
, &names
.line
))
1841 this->line
.s
.section
= sectp
;
1842 this->line
.size
= bfd_section_size (sectp
);
1844 else if (section_is_p (sectp
->name
, &names
.loc
))
1846 this->loc
.s
.section
= sectp
;
1847 this->loc
.size
= bfd_section_size (sectp
);
1849 else if (section_is_p (sectp
->name
, &names
.loclists
))
1851 this->loclists
.s
.section
= sectp
;
1852 this->loclists
.size
= bfd_section_size (sectp
);
1854 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1856 this->macinfo
.s
.section
= sectp
;
1857 this->macinfo
.size
= bfd_section_size (sectp
);
1859 else if (section_is_p (sectp
->name
, &names
.macro
))
1861 this->macro
.s
.section
= sectp
;
1862 this->macro
.size
= bfd_section_size (sectp
);
1864 else if (section_is_p (sectp
->name
, &names
.str
))
1866 this->str
.s
.section
= sectp
;
1867 this->str
.size
= bfd_section_size (sectp
);
1869 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1871 this->str_offsets
.s
.section
= sectp
;
1872 this->str_offsets
.size
= bfd_section_size (sectp
);
1874 else if (section_is_p (sectp
->name
, &names
.line_str
))
1876 this->line_str
.s
.section
= sectp
;
1877 this->line_str
.size
= bfd_section_size (sectp
);
1879 else if (section_is_p (sectp
->name
, &names
.addr
))
1881 this->addr
.s
.section
= sectp
;
1882 this->addr
.size
= bfd_section_size (sectp
);
1884 else if (section_is_p (sectp
->name
, &names
.frame
))
1886 this->frame
.s
.section
= sectp
;
1887 this->frame
.size
= bfd_section_size (sectp
);
1889 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1891 this->eh_frame
.s
.section
= sectp
;
1892 this->eh_frame
.size
= bfd_section_size (sectp
);
1894 else if (section_is_p (sectp
->name
, &names
.ranges
))
1896 this->ranges
.s
.section
= sectp
;
1897 this->ranges
.size
= bfd_section_size (sectp
);
1899 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1901 this->rnglists
.s
.section
= sectp
;
1902 this->rnglists
.size
= bfd_section_size (sectp
);
1904 else if (section_is_p (sectp
->name
, &names
.types
))
1906 struct dwarf2_section_info type_section
;
1908 memset (&type_section
, 0, sizeof (type_section
));
1909 type_section
.s
.section
= sectp
;
1910 type_section
.size
= bfd_section_size (sectp
);
1912 this->types
.push_back (type_section
);
1914 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1916 this->gdb_index
.s
.section
= sectp
;
1917 this->gdb_index
.size
= bfd_section_size (sectp
);
1919 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1921 this->debug_names
.s
.section
= sectp
;
1922 this->debug_names
.size
= bfd_section_size (sectp
);
1924 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1926 this->debug_aranges
.s
.section
= sectp
;
1927 this->debug_aranges
.size
= bfd_section_size (sectp
);
1930 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1931 && bfd_section_vma (sectp
) == 0)
1932 this->has_section_at_zero
= true;
1935 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1939 dwarf2_get_section_info (struct objfile
*objfile
,
1940 enum dwarf2_section_enum sect
,
1941 asection
**sectp
, const gdb_byte
**bufp
,
1942 bfd_size_type
*sizep
)
1944 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
1945 struct dwarf2_section_info
*info
;
1947 /* We may see an objfile without any DWARF, in which case we just
1958 case DWARF2_DEBUG_FRAME
:
1959 info
= &data
->frame
;
1961 case DWARF2_EH_FRAME
:
1962 info
= &data
->eh_frame
;
1965 gdb_assert_not_reached ("unexpected section");
1968 info
->read (objfile
);
1970 *sectp
= info
->get_bfd_section ();
1971 *bufp
= info
->buffer
;
1972 *sizep
= info
->size
;
1975 /* A helper function to find the sections for a .dwz file. */
1978 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
1980 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
1982 /* Note that we only support the standard ELF names, because .dwz
1983 is ELF-only (at the time of writing). */
1984 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
1986 dwz_file
->abbrev
.s
.section
= sectp
;
1987 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
1989 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
1991 dwz_file
->info
.s
.section
= sectp
;
1992 dwz_file
->info
.size
= bfd_section_size (sectp
);
1994 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
1996 dwz_file
->str
.s
.section
= sectp
;
1997 dwz_file
->str
.size
= bfd_section_size (sectp
);
1999 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2001 dwz_file
->line
.s
.section
= sectp
;
2002 dwz_file
->line
.size
= bfd_section_size (sectp
);
2004 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2006 dwz_file
->macro
.s
.section
= sectp
;
2007 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2009 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2011 dwz_file
->gdb_index
.s
.section
= sectp
;
2012 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2014 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2016 dwz_file
->debug_names
.s
.section
= sectp
;
2017 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2021 /* See dwarf2read.h. */
2024 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2026 const char *filename
;
2027 bfd_size_type buildid_len_arg
;
2031 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2032 return dwarf2_per_objfile
->dwz_file
.get ();
2034 bfd_set_error (bfd_error_no_error
);
2035 gdb::unique_xmalloc_ptr
<char> data
2036 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2037 &buildid_len_arg
, &buildid
));
2040 if (bfd_get_error () == bfd_error_no_error
)
2042 error (_("could not read '.gnu_debugaltlink' section: %s"),
2043 bfd_errmsg (bfd_get_error ()));
2046 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2048 buildid_len
= (size_t) buildid_len_arg
;
2050 filename
= data
.get ();
2052 std::string abs_storage
;
2053 if (!IS_ABSOLUTE_PATH (filename
))
2055 gdb::unique_xmalloc_ptr
<char> abs
2056 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2058 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2059 filename
= abs_storage
.c_str ();
2062 /* First try the file name given in the section. If that doesn't
2063 work, try to use the build-id instead. */
2064 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2065 if (dwz_bfd
!= NULL
)
2067 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2068 dwz_bfd
.reset (nullptr);
2071 if (dwz_bfd
== NULL
)
2072 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2074 if (dwz_bfd
== nullptr)
2076 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2077 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2079 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2086 /* File successfully retrieved from server. */
2087 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2089 if (dwz_bfd
== nullptr)
2090 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2091 alt_filename
.get ());
2092 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2093 dwz_bfd
.reset (nullptr);
2097 if (dwz_bfd
== NULL
)
2098 error (_("could not find '.gnu_debugaltlink' file for %s"),
2099 objfile_name (dwarf2_per_objfile
->objfile
));
2101 std::unique_ptr
<struct dwz_file
> result
2102 (new struct dwz_file (std::move (dwz_bfd
)));
2104 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2107 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2108 result
->dwz_bfd
.get ());
2109 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2110 return dwarf2_per_objfile
->dwz_file
.get ();
2113 /* DWARF quick_symbols_functions support. */
2115 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2116 unique line tables, so we maintain a separate table of all .debug_line
2117 derived entries to support the sharing.
2118 All the quick functions need is the list of file names. We discard the
2119 line_header when we're done and don't need to record it here. */
2120 struct quick_file_names
2122 /* The data used to construct the hash key. */
2123 struct stmt_list_hash hash
;
2125 /* The number of entries in file_names, real_names. */
2126 unsigned int num_file_names
;
2128 /* The file names from the line table, after being run through
2130 const char **file_names
;
2132 /* The file names from the line table after being run through
2133 gdb_realpath. These are computed lazily. */
2134 const char **real_names
;
2137 /* When using the index (and thus not using psymtabs), each CU has an
2138 object of this type. This is used to hold information needed by
2139 the various "quick" methods. */
2140 struct dwarf2_per_cu_quick_data
2142 /* The file table. This can be NULL if there was no file table
2143 or it's currently not read in.
2144 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2145 struct quick_file_names
*file_names
;
2147 /* The corresponding symbol table. This is NULL if symbols for this
2148 CU have not yet been read. */
2149 struct compunit_symtab
*compunit_symtab
;
2151 /* A temporary mark bit used when iterating over all CUs in
2152 expand_symtabs_matching. */
2153 unsigned int mark
: 1;
2155 /* True if we've tried to read the file table and found there isn't one.
2156 There will be no point in trying to read it again next time. */
2157 unsigned int no_file_data
: 1;
2160 /* Utility hash function for a stmt_list_hash. */
2163 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2167 if (stmt_list_hash
->dwo_unit
!= NULL
)
2168 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2169 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2173 /* Utility equality function for a stmt_list_hash. */
2176 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2177 const struct stmt_list_hash
*rhs
)
2179 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2181 if (lhs
->dwo_unit
!= NULL
2182 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2185 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2188 /* Hash function for a quick_file_names. */
2191 hash_file_name_entry (const void *e
)
2193 const struct quick_file_names
*file_data
2194 = (const struct quick_file_names
*) e
;
2196 return hash_stmt_list_entry (&file_data
->hash
);
2199 /* Equality function for a quick_file_names. */
2202 eq_file_name_entry (const void *a
, const void *b
)
2204 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2205 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2207 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2210 /* Delete function for a quick_file_names. */
2213 delete_file_name_entry (void *e
)
2215 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2218 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2220 xfree ((void*) file_data
->file_names
[i
]);
2221 if (file_data
->real_names
)
2222 xfree ((void*) file_data
->real_names
[i
]);
2225 /* The space for the struct itself lives on objfile_obstack,
2226 so we don't free it here. */
2229 /* Create a quick_file_names hash table. */
2232 create_quick_file_names_table (unsigned int nr_initial_entries
)
2234 return htab_up (htab_create_alloc (nr_initial_entries
,
2235 hash_file_name_entry
, eq_file_name_entry
,
2236 delete_file_name_entry
, xcalloc
, xfree
));
2239 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2240 have to be created afterwards. You should call age_cached_comp_units after
2241 processing PER_CU->CU. dw2_setup must have been already called. */
2244 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2246 if (per_cu
->is_debug_types
)
2247 load_full_type_unit (per_cu
);
2249 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2251 if (per_cu
->cu
== NULL
)
2252 return; /* Dummy CU. */
2254 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2257 /* Read in the symbols for PER_CU. */
2260 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2262 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2264 /* Skip type_unit_groups, reading the type units they contain
2265 is handled elsewhere. */
2266 if (per_cu
->type_unit_group_p ())
2269 /* The destructor of dwarf2_queue_guard frees any entries left on
2270 the queue. After this point we're guaranteed to leave this function
2271 with the dwarf queue empty. */
2272 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2274 if (dwarf2_per_objfile
->using_index
2275 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2276 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2278 queue_comp_unit (per_cu
, language_minimal
);
2279 load_cu (per_cu
, skip_partial
);
2281 /* If we just loaded a CU from a DWO, and we're working with an index
2282 that may badly handle TUs, load all the TUs in that DWO as well.
2283 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2284 if (!per_cu
->is_debug_types
2285 && per_cu
->cu
!= NULL
2286 && per_cu
->cu
->dwo_unit
!= NULL
2287 && dwarf2_per_objfile
->index_table
!= NULL
2288 && dwarf2_per_objfile
->index_table
->version
<= 7
2289 /* DWP files aren't supported yet. */
2290 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2291 queue_and_load_all_dwo_tus (per_cu
);
2294 process_queue (dwarf2_per_objfile
);
2296 /* Age the cache, releasing compilation units that have not
2297 been used recently. */
2298 age_cached_comp_units (dwarf2_per_objfile
);
2301 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2302 the objfile from which this CU came. Returns the resulting symbol
2305 static struct compunit_symtab
*
2306 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2308 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2310 gdb_assert (dwarf2_per_objfile
->using_index
);
2311 if (!per_cu
->v
.quick
->compunit_symtab
)
2313 free_cached_comp_units
freer (dwarf2_per_objfile
);
2314 scoped_restore decrementer
= increment_reading_symtab ();
2315 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2316 process_cu_includes (dwarf2_per_objfile
);
2319 return per_cu
->v
.quick
->compunit_symtab
;
2322 /* See declaration. */
2324 dwarf2_per_cu_data
*
2325 dwarf2_per_objfile::get_cutu (int index
)
2327 if (index
>= this->all_comp_units
.size ())
2329 index
-= this->all_comp_units
.size ();
2330 gdb_assert (index
< this->all_type_units
.size ());
2331 return &this->all_type_units
[index
]->per_cu
;
2334 return this->all_comp_units
[index
];
2337 /* See declaration. */
2339 dwarf2_per_cu_data
*
2340 dwarf2_per_objfile::get_cu (int index
)
2342 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2344 return this->all_comp_units
[index
];
2347 /* See declaration. */
2350 dwarf2_per_objfile::get_tu (int index
)
2352 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2354 return this->all_type_units
[index
];
2357 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2358 objfile_obstack, and constructed with the specified field
2361 static dwarf2_per_cu_data
*
2362 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2363 struct dwarf2_section_info
*section
,
2365 sect_offset sect_off
, ULONGEST length
)
2367 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2368 dwarf2_per_cu_data
*the_cu
2369 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2370 struct dwarf2_per_cu_data
);
2371 the_cu
->sect_off
= sect_off
;
2372 the_cu
->length
= length
;
2373 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2374 the_cu
->section
= section
;
2375 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2376 struct dwarf2_per_cu_quick_data
);
2377 the_cu
->is_dwz
= is_dwz
;
2381 /* A helper for create_cus_from_index that handles a given list of
2385 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2386 const gdb_byte
*cu_list
, offset_type n_elements
,
2387 struct dwarf2_section_info
*section
,
2390 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2392 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2394 sect_offset sect_off
2395 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2396 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2399 dwarf2_per_cu_data
*per_cu
2400 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2402 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2406 /* Read the CU list from the mapped index, and use it to create all
2407 the CU objects for this objfile. */
2410 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2411 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2412 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2414 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2415 dwarf2_per_objfile
->all_comp_units
.reserve
2416 ((cu_list_elements
+ dwz_elements
) / 2);
2418 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2419 &dwarf2_per_objfile
->info
, 0);
2421 if (dwz_elements
== 0)
2424 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2425 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2429 /* Create the signatured type hash table from the index. */
2432 create_signatured_type_table_from_index
2433 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2434 struct dwarf2_section_info
*section
,
2435 const gdb_byte
*bytes
,
2436 offset_type elements
)
2438 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2440 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2441 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2443 htab_up sig_types_hash
= allocate_signatured_type_table ();
2445 for (offset_type i
= 0; i
< elements
; i
+= 3)
2447 struct signatured_type
*sig_type
;
2450 cu_offset type_offset_in_tu
;
2452 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2453 sect_offset sect_off
2454 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2456 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2458 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2461 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2462 struct signatured_type
);
2463 sig_type
->signature
= signature
;
2464 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2465 sig_type
->per_cu
.is_debug_types
= 1;
2466 sig_type
->per_cu
.section
= section
;
2467 sig_type
->per_cu
.sect_off
= sect_off
;
2468 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2469 sig_type
->per_cu
.v
.quick
2470 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2471 struct dwarf2_per_cu_quick_data
);
2473 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2476 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2479 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2482 /* Create the signatured type hash table from .debug_names. */
2485 create_signatured_type_table_from_debug_names
2486 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2487 const mapped_debug_names
&map
,
2488 struct dwarf2_section_info
*section
,
2489 struct dwarf2_section_info
*abbrev_section
)
2491 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2493 section
->read (objfile
);
2494 abbrev_section
->read (objfile
);
2496 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2497 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2499 htab_up sig_types_hash
= allocate_signatured_type_table ();
2501 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2503 struct signatured_type
*sig_type
;
2506 sect_offset sect_off
2507 = (sect_offset
) (extract_unsigned_integer
2508 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2510 map
.dwarf5_byte_order
));
2512 comp_unit_head cu_header
;
2513 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2515 section
->buffer
+ to_underlying (sect_off
),
2518 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2519 struct signatured_type
);
2520 sig_type
->signature
= cu_header
.signature
;
2521 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2522 sig_type
->per_cu
.is_debug_types
= 1;
2523 sig_type
->per_cu
.section
= section
;
2524 sig_type
->per_cu
.sect_off
= sect_off
;
2525 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2526 sig_type
->per_cu
.v
.quick
2527 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2528 struct dwarf2_per_cu_quick_data
);
2530 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2533 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2536 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2539 /* Read the address map data from the mapped index, and use it to
2540 populate the objfile's psymtabs_addrmap. */
2543 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2544 struct mapped_index
*index
)
2546 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2547 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2548 const gdb_byte
*iter
, *end
;
2549 struct addrmap
*mutable_map
;
2552 auto_obstack temp_obstack
;
2554 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2556 iter
= index
->address_table
.data ();
2557 end
= iter
+ index
->address_table
.size ();
2559 baseaddr
= objfile
->text_section_offset ();
2563 ULONGEST hi
, lo
, cu_index
;
2564 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2566 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2568 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2573 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2574 hex_string (lo
), hex_string (hi
));
2578 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2580 complaint (_(".gdb_index address table has invalid CU number %u"),
2581 (unsigned) cu_index
);
2585 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2586 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2587 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2588 dwarf2_per_objfile
->get_cu (cu_index
));
2591 objfile
->partial_symtabs
->psymtabs_addrmap
2592 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2595 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2596 populate the objfile's psymtabs_addrmap. */
2599 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2600 struct dwarf2_section_info
*section
)
2602 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2603 bfd
*abfd
= objfile
->obfd
;
2604 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2605 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2607 auto_obstack temp_obstack
;
2608 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2610 std::unordered_map
<sect_offset
,
2611 dwarf2_per_cu_data
*,
2612 gdb::hash_enum
<sect_offset
>>
2613 debug_info_offset_to_per_cu
;
2614 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2616 const auto insertpair
2617 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2618 if (!insertpair
.second
)
2620 warning (_("Section .debug_aranges in %s has duplicate "
2621 "debug_info_offset %s, ignoring .debug_aranges."),
2622 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2627 section
->read (objfile
);
2629 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2631 const gdb_byte
*addr
= section
->buffer
;
2633 while (addr
< section
->buffer
+ section
->size
)
2635 const gdb_byte
*const entry_addr
= addr
;
2636 unsigned int bytes_read
;
2638 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2642 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2643 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2644 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2645 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2647 warning (_("Section .debug_aranges in %s entry at offset %s "
2648 "length %s exceeds section length %s, "
2649 "ignoring .debug_aranges."),
2650 objfile_name (objfile
),
2651 plongest (entry_addr
- section
->buffer
),
2652 plongest (bytes_read
+ entry_length
),
2653 pulongest (section
->size
));
2657 /* The version number. */
2658 const uint16_t version
= read_2_bytes (abfd
, addr
);
2662 warning (_("Section .debug_aranges in %s entry at offset %s "
2663 "has unsupported version %d, ignoring .debug_aranges."),
2664 objfile_name (objfile
),
2665 plongest (entry_addr
- section
->buffer
), version
);
2669 const uint64_t debug_info_offset
2670 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2671 addr
+= offset_size
;
2672 const auto per_cu_it
2673 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2674 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2676 warning (_("Section .debug_aranges in %s entry at offset %s "
2677 "debug_info_offset %s does not exists, "
2678 "ignoring .debug_aranges."),
2679 objfile_name (objfile
),
2680 plongest (entry_addr
- section
->buffer
),
2681 pulongest (debug_info_offset
));
2684 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2686 const uint8_t address_size
= *addr
++;
2687 if (address_size
< 1 || address_size
> 8)
2689 warning (_("Section .debug_aranges in %s entry at offset %s "
2690 "address_size %u is invalid, ignoring .debug_aranges."),
2691 objfile_name (objfile
),
2692 plongest (entry_addr
- section
->buffer
), address_size
);
2696 const uint8_t segment_selector_size
= *addr
++;
2697 if (segment_selector_size
!= 0)
2699 warning (_("Section .debug_aranges in %s entry at offset %s "
2700 "segment_selector_size %u is not supported, "
2701 "ignoring .debug_aranges."),
2702 objfile_name (objfile
),
2703 plongest (entry_addr
- section
->buffer
),
2704 segment_selector_size
);
2708 /* Must pad to an alignment boundary that is twice the address
2709 size. It is undocumented by the DWARF standard but GCC does
2711 for (size_t padding
= ((-(addr
- section
->buffer
))
2712 & (2 * address_size
- 1));
2713 padding
> 0; padding
--)
2716 warning (_("Section .debug_aranges in %s entry at offset %s "
2717 "padding is not zero, ignoring .debug_aranges."),
2718 objfile_name (objfile
),
2719 plongest (entry_addr
- section
->buffer
));
2725 if (addr
+ 2 * address_size
> entry_end
)
2727 warning (_("Section .debug_aranges in %s entry at offset %s "
2728 "address list is not properly terminated, "
2729 "ignoring .debug_aranges."),
2730 objfile_name (objfile
),
2731 plongest (entry_addr
- section
->buffer
));
2734 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2736 addr
+= address_size
;
2737 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2739 addr
+= address_size
;
2740 if (start
== 0 && length
== 0)
2742 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2744 /* Symbol was eliminated due to a COMDAT group. */
2747 ULONGEST end
= start
+ length
;
2748 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2750 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2752 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2756 objfile
->partial_symtabs
->psymtabs_addrmap
2757 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2760 /* Find a slot in the mapped index INDEX for the object named NAME.
2761 If NAME is found, set *VEC_OUT to point to the CU vector in the
2762 constant pool and return true. If NAME cannot be found, return
2766 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2767 offset_type
**vec_out
)
2770 offset_type slot
, step
;
2771 int (*cmp
) (const char *, const char *);
2773 gdb::unique_xmalloc_ptr
<char> without_params
;
2774 if (current_language
->la_language
== language_cplus
2775 || current_language
->la_language
== language_fortran
2776 || current_language
->la_language
== language_d
)
2778 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2781 if (strchr (name
, '(') != NULL
)
2783 without_params
= cp_remove_params (name
);
2785 if (without_params
!= NULL
)
2786 name
= without_params
.get ();
2790 /* Index version 4 did not support case insensitive searches. But the
2791 indices for case insensitive languages are built in lowercase, therefore
2792 simulate our NAME being searched is also lowercased. */
2793 hash
= mapped_index_string_hash ((index
->version
== 4
2794 && case_sensitivity
== case_sensitive_off
2795 ? 5 : index
->version
),
2798 slot
= hash
& (index
->symbol_table
.size () - 1);
2799 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2800 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2806 const auto &bucket
= index
->symbol_table
[slot
];
2807 if (bucket
.name
== 0 && bucket
.vec
== 0)
2810 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2811 if (!cmp (name
, str
))
2813 *vec_out
= (offset_type
*) (index
->constant_pool
2814 + MAYBE_SWAP (bucket
.vec
));
2818 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2822 /* A helper function that reads the .gdb_index from BUFFER and fills
2823 in MAP. FILENAME is the name of the file containing the data;
2824 it is used for error reporting. DEPRECATED_OK is true if it is
2825 ok to use deprecated sections.
2827 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2828 out parameters that are filled in with information about the CU and
2829 TU lists in the section.
2831 Returns true if all went well, false otherwise. */
2834 read_gdb_index_from_buffer (struct objfile
*objfile
,
2835 const char *filename
,
2837 gdb::array_view
<const gdb_byte
> buffer
,
2838 struct mapped_index
*map
,
2839 const gdb_byte
**cu_list
,
2840 offset_type
*cu_list_elements
,
2841 const gdb_byte
**types_list
,
2842 offset_type
*types_list_elements
)
2844 const gdb_byte
*addr
= &buffer
[0];
2846 /* Version check. */
2847 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2848 /* Versions earlier than 3 emitted every copy of a psymbol. This
2849 causes the index to behave very poorly for certain requests. Version 3
2850 contained incomplete addrmap. So, it seems better to just ignore such
2854 static int warning_printed
= 0;
2855 if (!warning_printed
)
2857 warning (_("Skipping obsolete .gdb_index section in %s."),
2859 warning_printed
= 1;
2863 /* Index version 4 uses a different hash function than index version
2866 Versions earlier than 6 did not emit psymbols for inlined
2867 functions. Using these files will cause GDB not to be able to
2868 set breakpoints on inlined functions by name, so we ignore these
2869 indices unless the user has done
2870 "set use-deprecated-index-sections on". */
2871 if (version
< 6 && !deprecated_ok
)
2873 static int warning_printed
= 0;
2874 if (!warning_printed
)
2877 Skipping deprecated .gdb_index section in %s.\n\
2878 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2879 to use the section anyway."),
2881 warning_printed
= 1;
2885 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2886 of the TU (for symbols coming from TUs),
2887 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2888 Plus gold-generated indices can have duplicate entries for global symbols,
2889 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2890 These are just performance bugs, and we can't distinguish gdb-generated
2891 indices from gold-generated ones, so issue no warning here. */
2893 /* Indexes with higher version than the one supported by GDB may be no
2894 longer backward compatible. */
2898 map
->version
= version
;
2900 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2903 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2904 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2908 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2909 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2910 - MAYBE_SWAP (metadata
[i
]))
2914 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2915 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2917 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2920 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2921 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2923 = gdb::array_view
<mapped_index::symbol_table_slot
>
2924 ((mapped_index::symbol_table_slot
*) symbol_table
,
2925 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2928 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2933 /* Callback types for dwarf2_read_gdb_index. */
2935 typedef gdb::function_view
2936 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2937 get_gdb_index_contents_ftype
;
2938 typedef gdb::function_view
2939 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2940 get_gdb_index_contents_dwz_ftype
;
2942 /* Read .gdb_index. If everything went ok, initialize the "quick"
2943 elements of all the CUs and return 1. Otherwise, return 0. */
2946 dwarf2_read_gdb_index
2947 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2948 get_gdb_index_contents_ftype get_gdb_index_contents
,
2949 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2951 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2952 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2953 struct dwz_file
*dwz
;
2954 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2956 gdb::array_view
<const gdb_byte
> main_index_contents
2957 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
2959 if (main_index_contents
.empty ())
2962 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2963 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
2964 use_deprecated_index_sections
,
2965 main_index_contents
, map
.get (), &cu_list
,
2966 &cu_list_elements
, &types_list
,
2967 &types_list_elements
))
2970 /* Don't use the index if it's empty. */
2971 if (map
->symbol_table
.empty ())
2974 /* If there is a .dwz file, read it so we can get its CU list as
2976 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2979 struct mapped_index dwz_map
;
2980 const gdb_byte
*dwz_types_ignore
;
2981 offset_type dwz_types_elements_ignore
;
2983 gdb::array_view
<const gdb_byte
> dwz_index_content
2984 = get_gdb_index_contents_dwz (objfile
, dwz
);
2986 if (dwz_index_content
.empty ())
2989 if (!read_gdb_index_from_buffer (objfile
,
2990 bfd_get_filename (dwz
->dwz_bfd
.get ()),
2991 1, dwz_index_content
, &dwz_map
,
2992 &dwz_list
, &dwz_list_elements
,
2994 &dwz_types_elements_ignore
))
2996 warning (_("could not read '.gdb_index' section from %s; skipping"),
2997 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3002 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3003 dwz_list
, dwz_list_elements
);
3005 if (types_list_elements
)
3007 /* We can only handle a single .debug_types when we have an
3009 if (dwarf2_per_objfile
->types
.size () != 1)
3012 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3014 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3015 types_list
, types_list_elements
);
3018 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3020 dwarf2_per_objfile
->index_table
= std::move (map
);
3021 dwarf2_per_objfile
->using_index
= 1;
3022 dwarf2_per_objfile
->quick_file_names_table
=
3023 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3028 /* die_reader_func for dw2_get_file_names. */
3031 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3032 const gdb_byte
*info_ptr
,
3033 struct die_info
*comp_unit_die
)
3035 struct dwarf2_cu
*cu
= reader
->cu
;
3036 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3037 struct dwarf2_per_objfile
*dwarf2_per_objfile
3038 = cu
->per_cu
->dwarf2_per_objfile
;
3039 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3040 struct dwarf2_per_cu_data
*lh_cu
;
3041 struct attribute
*attr
;
3043 struct quick_file_names
*qfn
;
3045 gdb_assert (! this_cu
->is_debug_types
);
3047 /* Our callers never want to match partial units -- instead they
3048 will match the enclosing full CU. */
3049 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3051 this_cu
->v
.quick
->no_file_data
= 1;
3059 sect_offset line_offset
{};
3061 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3062 if (attr
!= nullptr)
3064 struct quick_file_names find_entry
;
3066 line_offset
= (sect_offset
) DW_UNSND (attr
);
3068 /* We may have already read in this line header (TU line header sharing).
3069 If we have we're done. */
3070 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3071 find_entry
.hash
.line_sect_off
= line_offset
;
3072 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3073 &find_entry
, INSERT
);
3076 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3080 lh
= dwarf_decode_line_header (line_offset
, cu
);
3084 lh_cu
->v
.quick
->no_file_data
= 1;
3088 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3089 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3090 qfn
->hash
.line_sect_off
= line_offset
;
3091 gdb_assert (slot
!= NULL
);
3094 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3097 if (strcmp (fnd
.name
, "<unknown>") != 0)
3100 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3102 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3104 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3105 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3106 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3107 fnd
.comp_dir
).release ();
3108 qfn
->real_names
= NULL
;
3110 lh_cu
->v
.quick
->file_names
= qfn
;
3113 /* A helper for the "quick" functions which attempts to read the line
3114 table for THIS_CU. */
3116 static struct quick_file_names
*
3117 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3119 /* This should never be called for TUs. */
3120 gdb_assert (! this_cu
->is_debug_types
);
3121 /* Nor type unit groups. */
3122 gdb_assert (! this_cu
->type_unit_group_p ());
3124 if (this_cu
->v
.quick
->file_names
!= NULL
)
3125 return this_cu
->v
.quick
->file_names
;
3126 /* If we know there is no line data, no point in looking again. */
3127 if (this_cu
->v
.quick
->no_file_data
)
3130 cutu_reader
reader (this_cu
);
3131 if (!reader
.dummy_p
)
3132 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3134 if (this_cu
->v
.quick
->no_file_data
)
3136 return this_cu
->v
.quick
->file_names
;
3139 /* A helper for the "quick" functions which computes and caches the
3140 real path for a given file name from the line table. */
3143 dw2_get_real_path (struct objfile
*objfile
,
3144 struct quick_file_names
*qfn
, int index
)
3146 if (qfn
->real_names
== NULL
)
3147 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3148 qfn
->num_file_names
, const char *);
3150 if (qfn
->real_names
[index
] == NULL
)
3151 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3153 return qfn
->real_names
[index
];
3156 static struct symtab
*
3157 dw2_find_last_source_symtab (struct objfile
*objfile
)
3159 struct dwarf2_per_objfile
*dwarf2_per_objfile
3160 = get_dwarf2_per_objfile (objfile
);
3161 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3162 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3167 return compunit_primary_filetab (cust
);
3170 /* Traversal function for dw2_forget_cached_source_info. */
3173 dw2_free_cached_file_names (void **slot
, void *info
)
3175 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3177 if (file_data
->real_names
)
3181 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3183 xfree ((void*) file_data
->real_names
[i
]);
3184 file_data
->real_names
[i
] = NULL
;
3192 dw2_forget_cached_source_info (struct objfile
*objfile
)
3194 struct dwarf2_per_objfile
*dwarf2_per_objfile
3195 = get_dwarf2_per_objfile (objfile
);
3197 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3198 dw2_free_cached_file_names
, NULL
);
3201 /* Helper function for dw2_map_symtabs_matching_filename that expands
3202 the symtabs and calls the iterator. */
3205 dw2_map_expand_apply (struct objfile
*objfile
,
3206 struct dwarf2_per_cu_data
*per_cu
,
3207 const char *name
, const char *real_path
,
3208 gdb::function_view
<bool (symtab
*)> callback
)
3210 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3212 /* Don't visit already-expanded CUs. */
3213 if (per_cu
->v
.quick
->compunit_symtab
)
3216 /* This may expand more than one symtab, and we want to iterate over
3218 dw2_instantiate_symtab (per_cu
, false);
3220 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3221 last_made
, callback
);
3224 /* Implementation of the map_symtabs_matching_filename method. */
3227 dw2_map_symtabs_matching_filename
3228 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3229 gdb::function_view
<bool (symtab
*)> callback
)
3231 const char *name_basename
= lbasename (name
);
3232 struct dwarf2_per_objfile
*dwarf2_per_objfile
3233 = get_dwarf2_per_objfile (objfile
);
3235 /* The rule is CUs specify all the files, including those used by
3236 any TU, so there's no need to scan TUs here. */
3238 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3240 /* We only need to look at symtabs not already expanded. */
3241 if (per_cu
->v
.quick
->compunit_symtab
)
3244 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3245 if (file_data
== NULL
)
3248 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3250 const char *this_name
= file_data
->file_names
[j
];
3251 const char *this_real_name
;
3253 if (compare_filenames_for_search (this_name
, name
))
3255 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3261 /* Before we invoke realpath, which can get expensive when many
3262 files are involved, do a quick comparison of the basenames. */
3263 if (! basenames_may_differ
3264 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3267 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3268 if (compare_filenames_for_search (this_real_name
, name
))
3270 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3276 if (real_path
!= NULL
)
3278 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3279 gdb_assert (IS_ABSOLUTE_PATH (name
));
3280 if (this_real_name
!= NULL
3281 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3283 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3295 /* Struct used to manage iterating over all CUs looking for a symbol. */
3297 struct dw2_symtab_iterator
3299 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3300 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3301 /* If set, only look for symbols that match that block. Valid values are
3302 GLOBAL_BLOCK and STATIC_BLOCK. */
3303 gdb::optional
<block_enum
> block_index
;
3304 /* The kind of symbol we're looking for. */
3306 /* The list of CUs from the index entry of the symbol,
3307 or NULL if not found. */
3309 /* The next element in VEC to look at. */
3311 /* The number of elements in VEC, or zero if there is no match. */
3313 /* Have we seen a global version of the symbol?
3314 If so we can ignore all further global instances.
3315 This is to work around gold/15646, inefficient gold-generated
3320 /* Initialize the index symtab iterator ITER. */
3323 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3324 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3325 gdb::optional
<block_enum
> block_index
,
3329 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3330 iter
->block_index
= block_index
;
3331 iter
->domain
= domain
;
3333 iter
->global_seen
= 0;
3335 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3337 /* index is NULL if OBJF_READNOW. */
3338 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3339 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3347 /* Return the next matching CU or NULL if there are no more. */
3349 static struct dwarf2_per_cu_data
*
3350 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3352 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3354 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3356 offset_type cu_index_and_attrs
=
3357 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3358 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3359 gdb_index_symbol_kind symbol_kind
=
3360 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3361 /* Only check the symbol attributes if they're present.
3362 Indices prior to version 7 don't record them,
3363 and indices >= 7 may elide them for certain symbols
3364 (gold does this). */
3366 (dwarf2_per_objfile
->index_table
->version
>= 7
3367 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3369 /* Don't crash on bad data. */
3370 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3371 + dwarf2_per_objfile
->all_type_units
.size ()))
3373 complaint (_(".gdb_index entry has bad CU index"
3375 objfile_name (dwarf2_per_objfile
->objfile
));
3379 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3381 /* Skip if already read in. */
3382 if (per_cu
->v
.quick
->compunit_symtab
)
3385 /* Check static vs global. */
3388 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3390 if (iter
->block_index
.has_value ())
3392 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3394 if (is_static
!= want_static
)
3398 /* Work around gold/15646. */
3399 if (!is_static
&& iter
->global_seen
)
3402 iter
->global_seen
= 1;
3405 /* Only check the symbol's kind if it has one. */
3408 switch (iter
->domain
)
3411 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3412 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3413 /* Some types are also in VAR_DOMAIN. */
3414 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3418 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3422 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3426 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3441 static struct compunit_symtab
*
3442 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3443 const char *name
, domain_enum domain
)
3445 struct compunit_symtab
*stab_best
= NULL
;
3446 struct dwarf2_per_objfile
*dwarf2_per_objfile
3447 = get_dwarf2_per_objfile (objfile
);
3449 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3451 struct dw2_symtab_iterator iter
;
3452 struct dwarf2_per_cu_data
*per_cu
;
3454 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3456 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3458 struct symbol
*sym
, *with_opaque
= NULL
;
3459 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3460 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3461 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3463 sym
= block_find_symbol (block
, name
, domain
,
3464 block_find_non_opaque_type_preferred
,
3467 /* Some caution must be observed with overloaded functions
3468 and methods, since the index will not contain any overload
3469 information (but NAME might contain it). */
3472 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3474 if (with_opaque
!= NULL
3475 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3478 /* Keep looking through other CUs. */
3485 dw2_print_stats (struct objfile
*objfile
)
3487 struct dwarf2_per_objfile
*dwarf2_per_objfile
3488 = get_dwarf2_per_objfile (objfile
);
3489 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3490 + dwarf2_per_objfile
->all_type_units
.size ());
3493 for (int i
= 0; i
< total
; ++i
)
3495 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3497 if (!per_cu
->v
.quick
->compunit_symtab
)
3500 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3501 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3504 /* This dumps minimal information about the index.
3505 It is called via "mt print objfiles".
3506 One use is to verify .gdb_index has been loaded by the
3507 gdb.dwarf2/gdb-index.exp testcase. */
3510 dw2_dump (struct objfile
*objfile
)
3512 struct dwarf2_per_objfile
*dwarf2_per_objfile
3513 = get_dwarf2_per_objfile (objfile
);
3515 gdb_assert (dwarf2_per_objfile
->using_index
);
3516 printf_filtered (".gdb_index:");
3517 if (dwarf2_per_objfile
->index_table
!= NULL
)
3519 printf_filtered (" version %d\n",
3520 dwarf2_per_objfile
->index_table
->version
);
3523 printf_filtered (" faked for \"readnow\"\n");
3524 printf_filtered ("\n");
3528 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3529 const char *func_name
)
3531 struct dwarf2_per_objfile
*dwarf2_per_objfile
3532 = get_dwarf2_per_objfile (objfile
);
3534 struct dw2_symtab_iterator iter
;
3535 struct dwarf2_per_cu_data
*per_cu
;
3537 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3539 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3540 dw2_instantiate_symtab (per_cu
, false);
3545 dw2_expand_all_symtabs (struct objfile
*objfile
)
3547 struct dwarf2_per_objfile
*dwarf2_per_objfile
3548 = get_dwarf2_per_objfile (objfile
);
3549 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3550 + dwarf2_per_objfile
->all_type_units
.size ());
3552 for (int i
= 0; i
< total_units
; ++i
)
3554 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3556 /* We don't want to directly expand a partial CU, because if we
3557 read it with the wrong language, then assertion failures can
3558 be triggered later on. See PR symtab/23010. So, tell
3559 dw2_instantiate_symtab to skip partial CUs -- any important
3560 partial CU will be read via DW_TAG_imported_unit anyway. */
3561 dw2_instantiate_symtab (per_cu
, true);
3566 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3567 const char *fullname
)
3569 struct dwarf2_per_objfile
*dwarf2_per_objfile
3570 = get_dwarf2_per_objfile (objfile
);
3572 /* We don't need to consider type units here.
3573 This is only called for examining code, e.g. expand_line_sal.
3574 There can be an order of magnitude (or more) more type units
3575 than comp units, and we avoid them if we can. */
3577 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3579 /* We only need to look at symtabs not already expanded. */
3580 if (per_cu
->v
.quick
->compunit_symtab
)
3583 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3584 if (file_data
== NULL
)
3587 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3589 const char *this_fullname
= file_data
->file_names
[j
];
3591 if (filename_cmp (this_fullname
, fullname
) == 0)
3593 dw2_instantiate_symtab (per_cu
, false);
3601 dw2_map_matching_symbols
3602 (struct objfile
*objfile
,
3603 const lookup_name_info
&name
, domain_enum domain
,
3605 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3606 symbol_compare_ftype
*ordered_compare
)
3608 /* Currently unimplemented; used for Ada. The function can be called if the
3609 current language is Ada for a non-Ada objfile using GNU index. As Ada
3610 does not look for non-Ada symbols this function should just return. */
3613 /* Starting from a search name, return the string that finds the upper
3614 bound of all strings that start with SEARCH_NAME in a sorted name
3615 list. Returns the empty string to indicate that the upper bound is
3616 the end of the list. */
3619 make_sort_after_prefix_name (const char *search_name
)
3621 /* When looking to complete "func", we find the upper bound of all
3622 symbols that start with "func" by looking for where we'd insert
3623 the closest string that would follow "func" in lexicographical
3624 order. Usually, that's "func"-with-last-character-incremented,
3625 i.e. "fund". Mind non-ASCII characters, though. Usually those
3626 will be UTF-8 multi-byte sequences, but we can't be certain.
3627 Especially mind the 0xff character, which is a valid character in
3628 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3629 rule out compilers allowing it in identifiers. Note that
3630 conveniently, strcmp/strcasecmp are specified to compare
3631 characters interpreted as unsigned char. So what we do is treat
3632 the whole string as a base 256 number composed of a sequence of
3633 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3634 to 0, and carries 1 to the following more-significant position.
3635 If the very first character in SEARCH_NAME ends up incremented
3636 and carries/overflows, then the upper bound is the end of the
3637 list. The string after the empty string is also the empty
3640 Some examples of this operation:
3642 SEARCH_NAME => "+1" RESULT
3646 "\xff" "a" "\xff" => "\xff" "b"
3651 Then, with these symbols for example:
3657 completing "func" looks for symbols between "func" and
3658 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3659 which finds "func" and "func1", but not "fund".
3663 funcÿ (Latin1 'ÿ' [0xff])
3667 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3668 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3672 ÿÿ (Latin1 'ÿ' [0xff])
3675 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3676 the end of the list.
3678 std::string after
= search_name
;
3679 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3681 if (!after
.empty ())
3682 after
.back () = (unsigned char) after
.back () + 1;
3686 /* See declaration. */
3688 std::pair
<std::vector
<name_component
>::const_iterator
,
3689 std::vector
<name_component
>::const_iterator
>
3690 mapped_index_base::find_name_components_bounds
3691 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3694 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3696 const char *lang_name
3697 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3699 /* Comparison function object for lower_bound that matches against a
3700 given symbol name. */
3701 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3704 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3705 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3706 return name_cmp (elem_name
, name
) < 0;
3709 /* Comparison function object for upper_bound that matches against a
3710 given symbol name. */
3711 auto lookup_compare_upper
= [&] (const char *name
,
3712 const name_component
&elem
)
3714 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3715 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3716 return name_cmp (name
, elem_name
) < 0;
3719 auto begin
= this->name_components
.begin ();
3720 auto end
= this->name_components
.end ();
3722 /* Find the lower bound. */
3725 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3728 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3731 /* Find the upper bound. */
3734 if (lookup_name_without_params
.completion_mode ())
3736 /* In completion mode, we want UPPER to point past all
3737 symbols names that have the same prefix. I.e., with
3738 these symbols, and completing "func":
3740 function << lower bound
3742 other_function << upper bound
3744 We find the upper bound by looking for the insertion
3745 point of "func"-with-last-character-incremented,
3747 std::string after
= make_sort_after_prefix_name (lang_name
);
3750 return std::lower_bound (lower
, end
, after
.c_str (),
3751 lookup_compare_lower
);
3754 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3757 return {lower
, upper
};
3760 /* See declaration. */
3763 mapped_index_base::build_name_components ()
3765 if (!this->name_components
.empty ())
3768 this->name_components_casing
= case_sensitivity
;
3770 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3772 /* The code below only knows how to break apart components of C++
3773 symbol names (and other languages that use '::' as
3774 namespace/module separator) and Ada symbol names. */
3775 auto count
= this->symbol_name_count ();
3776 for (offset_type idx
= 0; idx
< count
; idx
++)
3778 if (this->symbol_name_slot_invalid (idx
))
3781 const char *name
= this->symbol_name_at (idx
);
3783 /* Add each name component to the name component table. */
3784 unsigned int previous_len
= 0;
3786 if (strstr (name
, "::") != nullptr)
3788 for (unsigned int current_len
= cp_find_first_component (name
);
3789 name
[current_len
] != '\0';
3790 current_len
+= cp_find_first_component (name
+ current_len
))
3792 gdb_assert (name
[current_len
] == ':');
3793 this->name_components
.push_back ({previous_len
, idx
});
3794 /* Skip the '::'. */
3796 previous_len
= current_len
;
3801 /* Handle the Ada encoded (aka mangled) form here. */
3802 for (const char *iter
= strstr (name
, "__");
3804 iter
= strstr (iter
, "__"))
3806 this->name_components
.push_back ({previous_len
, idx
});
3808 previous_len
= iter
- name
;
3812 this->name_components
.push_back ({previous_len
, idx
});
3815 /* Sort name_components elements by name. */
3816 auto name_comp_compare
= [&] (const name_component
&left
,
3817 const name_component
&right
)
3819 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3820 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3822 const char *left_name
= left_qualified
+ left
.name_offset
;
3823 const char *right_name
= right_qualified
+ right
.name_offset
;
3825 return name_cmp (left_name
, right_name
) < 0;
3828 std::sort (this->name_components
.begin (),
3829 this->name_components
.end (),
3833 /* Helper for dw2_expand_symtabs_matching that works with a
3834 mapped_index_base instead of the containing objfile. This is split
3835 to a separate function in order to be able to unit test the
3836 name_components matching using a mock mapped_index_base. For each
3837 symbol name that matches, calls MATCH_CALLBACK, passing it the
3838 symbol's index in the mapped_index_base symbol table. */
3841 dw2_expand_symtabs_matching_symbol
3842 (mapped_index_base
&index
,
3843 const lookup_name_info
&lookup_name_in
,
3844 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3845 enum search_domain kind
,
3846 gdb::function_view
<bool (offset_type
)> match_callback
)
3848 lookup_name_info lookup_name_without_params
3849 = lookup_name_in
.make_ignore_params ();
3851 /* Build the symbol name component sorted vector, if we haven't
3853 index
.build_name_components ();
3855 /* The same symbol may appear more than once in the range though.
3856 E.g., if we're looking for symbols that complete "w", and we have
3857 a symbol named "w1::w2", we'll find the two name components for
3858 that same symbol in the range. To be sure we only call the
3859 callback once per symbol, we first collect the symbol name
3860 indexes that matched in a temporary vector and ignore
3862 std::vector
<offset_type
> matches
;
3864 struct name_and_matcher
3866 symbol_name_matcher_ftype
*matcher
;
3867 const std::string
&name
;
3869 bool operator== (const name_and_matcher
&other
) const
3871 return matcher
== other
.matcher
&& name
== other
.name
;
3875 /* A vector holding all the different symbol name matchers, for all
3877 std::vector
<name_and_matcher
> matchers
;
3879 for (int i
= 0; i
< nr_languages
; i
++)
3881 enum language lang_e
= (enum language
) i
;
3883 const language_defn
*lang
= language_def (lang_e
);
3884 symbol_name_matcher_ftype
*name_matcher
3885 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3887 name_and_matcher key
{
3889 lookup_name_without_params
.language_lookup_name (lang_e
)
3892 /* Don't insert the same comparison routine more than once.
3893 Note that we do this linear walk. This is not a problem in
3894 practice because the number of supported languages is
3896 if (std::find (matchers
.begin (), matchers
.end (), key
)
3899 matchers
.push_back (std::move (key
));
3902 = index
.find_name_components_bounds (lookup_name_without_params
,
3905 /* Now for each symbol name in range, check to see if we have a name
3906 match, and if so, call the MATCH_CALLBACK callback. */
3908 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3910 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3912 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3913 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3916 matches
.push_back (bounds
.first
->idx
);
3920 std::sort (matches
.begin (), matches
.end ());
3922 /* Finally call the callback, once per match. */
3924 for (offset_type idx
: matches
)
3928 if (!match_callback (idx
))
3934 /* Above we use a type wider than idx's for 'prev', since 0 and
3935 (offset_type)-1 are both possible values. */
3936 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3941 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3943 /* A mock .gdb_index/.debug_names-like name index table, enough to
3944 exercise dw2_expand_symtabs_matching_symbol, which works with the
3945 mapped_index_base interface. Builds an index from the symbol list
3946 passed as parameter to the constructor. */
3947 class mock_mapped_index
: public mapped_index_base
3950 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3951 : m_symbol_table (symbols
)
3954 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3956 /* Return the number of names in the symbol table. */
3957 size_t symbol_name_count () const override
3959 return m_symbol_table
.size ();
3962 /* Get the name of the symbol at IDX in the symbol table. */
3963 const char *symbol_name_at (offset_type idx
) const override
3965 return m_symbol_table
[idx
];
3969 gdb::array_view
<const char *> m_symbol_table
;
3972 /* Convenience function that converts a NULL pointer to a "<null>"
3973 string, to pass to print routines. */
3976 string_or_null (const char *str
)
3978 return str
!= NULL
? str
: "<null>";
3981 /* Check if a lookup_name_info built from
3982 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3983 index. EXPECTED_LIST is the list of expected matches, in expected
3984 matching order. If no match expected, then an empty list is
3985 specified. Returns true on success. On failure prints a warning
3986 indicating the file:line that failed, and returns false. */
3989 check_match (const char *file
, int line
,
3990 mock_mapped_index
&mock_index
,
3991 const char *name
, symbol_name_match_type match_type
,
3992 bool completion_mode
,
3993 std::initializer_list
<const char *> expected_list
)
3995 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3997 bool matched
= true;
3999 auto mismatch
= [&] (const char *expected_str
,
4002 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4003 "expected=\"%s\", got=\"%s\"\n"),
4005 (match_type
== symbol_name_match_type::FULL
4007 name
, string_or_null (expected_str
), string_or_null (got
));
4011 auto expected_it
= expected_list
.begin ();
4012 auto expected_end
= expected_list
.end ();
4014 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4016 [&] (offset_type idx
)
4018 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4019 const char *expected_str
4020 = expected_it
== expected_end
? NULL
: *expected_it
++;
4022 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4023 mismatch (expected_str
, matched_name
);
4027 const char *expected_str
4028 = expected_it
== expected_end
? NULL
: *expected_it
++;
4029 if (expected_str
!= NULL
)
4030 mismatch (expected_str
, NULL
);
4035 /* The symbols added to the mock mapped_index for testing (in
4037 static const char *test_symbols
[] = {
4046 "ns2::tmpl<int>::foo2",
4047 "(anonymous namespace)::A::B::C",
4049 /* These are used to check that the increment-last-char in the
4050 matching algorithm for completion doesn't match "t1_fund" when
4051 completing "t1_func". */
4057 /* A UTF-8 name with multi-byte sequences to make sure that
4058 cp-name-parser understands this as a single identifier ("função"
4059 is "function" in PT). */
4062 /* \377 (0xff) is Latin1 'ÿ'. */
4065 /* \377 (0xff) is Latin1 'ÿ'. */
4069 /* A name with all sorts of complications. Starts with "z" to make
4070 it easier for the completion tests below. */
4071 #define Z_SYM_NAME \
4072 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4073 "::tuple<(anonymous namespace)::ui*, " \
4074 "std::default_delete<(anonymous namespace)::ui>, void>"
4079 /* Returns true if the mapped_index_base::find_name_component_bounds
4080 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4081 in completion mode. */
4084 check_find_bounds_finds (mapped_index_base
&index
,
4085 const char *search_name
,
4086 gdb::array_view
<const char *> expected_syms
)
4088 lookup_name_info
lookup_name (search_name
,
4089 symbol_name_match_type::FULL
, true);
4091 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4094 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4095 if (distance
!= expected_syms
.size ())
4098 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4100 auto nc_elem
= bounds
.first
+ exp_elem
;
4101 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4102 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4109 /* Test the lower-level mapped_index::find_name_component_bounds
4113 test_mapped_index_find_name_component_bounds ()
4115 mock_mapped_index
mock_index (test_symbols
);
4117 mock_index
.build_name_components ();
4119 /* Test the lower-level mapped_index::find_name_component_bounds
4120 method in completion mode. */
4122 static const char *expected_syms
[] = {
4127 SELF_CHECK (check_find_bounds_finds (mock_index
,
4128 "t1_func", expected_syms
));
4131 /* Check that the increment-last-char in the name matching algorithm
4132 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4134 static const char *expected_syms1
[] = {
4138 SELF_CHECK (check_find_bounds_finds (mock_index
,
4139 "\377", expected_syms1
));
4141 static const char *expected_syms2
[] = {
4144 SELF_CHECK (check_find_bounds_finds (mock_index
,
4145 "\377\377", expected_syms2
));
4149 /* Test dw2_expand_symtabs_matching_symbol. */
4152 test_dw2_expand_symtabs_matching_symbol ()
4154 mock_mapped_index
mock_index (test_symbols
);
4156 /* We let all tests run until the end even if some fails, for debug
4158 bool any_mismatch
= false;
4160 /* Create the expected symbols list (an initializer_list). Needed
4161 because lists have commas, and we need to pass them to CHECK,
4162 which is a macro. */
4163 #define EXPECT(...) { __VA_ARGS__ }
4165 /* Wrapper for check_match that passes down the current
4166 __FILE__/__LINE__. */
4167 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4168 any_mismatch |= !check_match (__FILE__, __LINE__, \
4170 NAME, MATCH_TYPE, COMPLETION_MODE, \
4173 /* Identity checks. */
4174 for (const char *sym
: test_symbols
)
4176 /* Should be able to match all existing symbols. */
4177 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4180 /* Should be able to match all existing symbols with
4182 std::string with_params
= std::string (sym
) + "(int)";
4183 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4186 /* Should be able to match all existing symbols with
4187 parameters and qualifiers. */
4188 with_params
= std::string (sym
) + " ( int ) const";
4189 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4192 /* This should really find sym, but cp-name-parser.y doesn't
4193 know about lvalue/rvalue qualifiers yet. */
4194 with_params
= std::string (sym
) + " ( int ) &&";
4195 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4199 /* Check that the name matching algorithm for completion doesn't get
4200 confused with Latin1 'ÿ' / 0xff. */
4202 static const char str
[] = "\377";
4203 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4204 EXPECT ("\377", "\377\377123"));
4207 /* Check that the increment-last-char in the matching algorithm for
4208 completion doesn't match "t1_fund" when completing "t1_func". */
4210 static const char str
[] = "t1_func";
4211 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4212 EXPECT ("t1_func", "t1_func1"));
4215 /* Check that completion mode works at each prefix of the expected
4218 static const char str
[] = "function(int)";
4219 size_t len
= strlen (str
);
4222 for (size_t i
= 1; i
< len
; i
++)
4224 lookup
.assign (str
, i
);
4225 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4226 EXPECT ("function"));
4230 /* While "w" is a prefix of both components, the match function
4231 should still only be called once. */
4233 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4235 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4239 /* Same, with a "complicated" symbol. */
4241 static const char str
[] = Z_SYM_NAME
;
4242 size_t len
= strlen (str
);
4245 for (size_t i
= 1; i
< len
; i
++)
4247 lookup
.assign (str
, i
);
4248 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4249 EXPECT (Z_SYM_NAME
));
4253 /* In FULL mode, an incomplete symbol doesn't match. */
4255 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4259 /* A complete symbol with parameters matches any overload, since the
4260 index has no overload info. */
4262 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4263 EXPECT ("std::zfunction", "std::zfunction2"));
4264 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4265 EXPECT ("std::zfunction", "std::zfunction2"));
4266 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4267 EXPECT ("std::zfunction", "std::zfunction2"));
4270 /* Check that whitespace is ignored appropriately. A symbol with a
4271 template argument list. */
4273 static const char expected
[] = "ns::foo<int>";
4274 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4276 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4280 /* Check that whitespace is ignored appropriately. A symbol with a
4281 template argument list that includes a pointer. */
4283 static const char expected
[] = "ns::foo<char*>";
4284 /* Try both completion and non-completion modes. */
4285 static const bool completion_mode
[2] = {false, true};
4286 for (size_t i
= 0; i
< 2; i
++)
4288 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4289 completion_mode
[i
], EXPECT (expected
));
4290 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4291 completion_mode
[i
], EXPECT (expected
));
4293 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4294 completion_mode
[i
], EXPECT (expected
));
4295 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4296 completion_mode
[i
], EXPECT (expected
));
4301 /* Check method qualifiers are ignored. */
4302 static const char expected
[] = "ns::foo<char*>";
4303 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4304 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4305 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4306 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4307 CHECK_MATCH ("foo < char * > ( int ) const",
4308 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4309 CHECK_MATCH ("foo < char * > ( int ) &&",
4310 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4313 /* Test lookup names that don't match anything. */
4315 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4318 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4322 /* Some wild matching tests, exercising "(anonymous namespace)",
4323 which should not be confused with a parameter list. */
4325 static const char *syms
[] = {
4329 "A :: B :: C ( int )",
4334 for (const char *s
: syms
)
4336 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4337 EXPECT ("(anonymous namespace)::A::B::C"));
4342 static const char expected
[] = "ns2::tmpl<int>::foo2";
4343 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4345 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4349 SELF_CHECK (!any_mismatch
);
4358 test_mapped_index_find_name_component_bounds ();
4359 test_dw2_expand_symtabs_matching_symbol ();
4362 }} // namespace selftests::dw2_expand_symtabs_matching
4364 #endif /* GDB_SELF_TEST */
4366 /* If FILE_MATCHER is NULL or if PER_CU has
4367 dwarf2_per_cu_quick_data::MARK set (see
4368 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4369 EXPANSION_NOTIFY on it. */
4372 dw2_expand_symtabs_matching_one
4373 (struct dwarf2_per_cu_data
*per_cu
,
4374 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4375 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4377 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4379 bool symtab_was_null
4380 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4382 dw2_instantiate_symtab (per_cu
, false);
4384 if (expansion_notify
!= NULL
4386 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4387 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4391 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4392 matched, to expand corresponding CUs that were marked. IDX is the
4393 index of the symbol name that matched. */
4396 dw2_expand_marked_cus
4397 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4398 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4399 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4402 offset_type
*vec
, vec_len
, vec_idx
;
4403 bool global_seen
= false;
4404 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4406 vec
= (offset_type
*) (index
.constant_pool
4407 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4408 vec_len
= MAYBE_SWAP (vec
[0]);
4409 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4411 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4412 /* This value is only valid for index versions >= 7. */
4413 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4414 gdb_index_symbol_kind symbol_kind
=
4415 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4416 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4417 /* Only check the symbol attributes if they're present.
4418 Indices prior to version 7 don't record them,
4419 and indices >= 7 may elide them for certain symbols
4420 (gold does this). */
4423 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4425 /* Work around gold/15646. */
4428 if (!is_static
&& global_seen
)
4434 /* Only check the symbol's kind if it has one. */
4439 case VARIABLES_DOMAIN
:
4440 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4443 case FUNCTIONS_DOMAIN
:
4444 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4448 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4451 case MODULES_DOMAIN
:
4452 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4460 /* Don't crash on bad data. */
4461 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4462 + dwarf2_per_objfile
->all_type_units
.size ()))
4464 complaint (_(".gdb_index entry has bad CU index"
4466 objfile_name (dwarf2_per_objfile
->objfile
));
4470 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4471 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4476 /* If FILE_MATCHER is non-NULL, set all the
4477 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4478 that match FILE_MATCHER. */
4481 dw_expand_symtabs_matching_file_matcher
4482 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4483 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4485 if (file_matcher
== NULL
)
4488 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4490 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4492 NULL
, xcalloc
, xfree
));
4493 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4495 NULL
, xcalloc
, xfree
));
4497 /* The rule is CUs specify all the files, including those used by
4498 any TU, so there's no need to scan TUs here. */
4500 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4504 per_cu
->v
.quick
->mark
= 0;
4506 /* We only need to look at symtabs not already expanded. */
4507 if (per_cu
->v
.quick
->compunit_symtab
)
4510 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4511 if (file_data
== NULL
)
4514 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4516 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4518 per_cu
->v
.quick
->mark
= 1;
4522 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4524 const char *this_real_name
;
4526 if (file_matcher (file_data
->file_names
[j
], false))
4528 per_cu
->v
.quick
->mark
= 1;
4532 /* Before we invoke realpath, which can get expensive when many
4533 files are involved, do a quick comparison of the basenames. */
4534 if (!basenames_may_differ
4535 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4539 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4540 if (file_matcher (this_real_name
, false))
4542 per_cu
->v
.quick
->mark
= 1;
4547 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4548 ? visited_found
.get ()
4549 : visited_not_found
.get (),
4556 dw2_expand_symtabs_matching
4557 (struct objfile
*objfile
,
4558 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4559 const lookup_name_info
&lookup_name
,
4560 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4561 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4562 enum search_domain kind
)
4564 struct dwarf2_per_objfile
*dwarf2_per_objfile
4565 = get_dwarf2_per_objfile (objfile
);
4567 /* index_table is NULL if OBJF_READNOW. */
4568 if (!dwarf2_per_objfile
->index_table
)
4571 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4573 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4575 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4577 kind
, [&] (offset_type idx
)
4579 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4580 expansion_notify
, kind
);
4585 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4588 static struct compunit_symtab
*
4589 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4594 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4595 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4598 if (cust
->includes
== NULL
)
4601 for (i
= 0; cust
->includes
[i
]; ++i
)
4603 struct compunit_symtab
*s
= cust
->includes
[i
];
4605 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4613 static struct compunit_symtab
*
4614 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4615 struct bound_minimal_symbol msymbol
,
4617 struct obj_section
*section
,
4620 struct dwarf2_per_cu_data
*data
;
4621 struct compunit_symtab
*result
;
4623 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4626 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4627 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4628 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4632 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4633 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4634 paddress (get_objfile_arch (objfile
), pc
));
4637 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4640 gdb_assert (result
!= NULL
);
4645 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4646 void *data
, int need_fullname
)
4648 struct dwarf2_per_objfile
*dwarf2_per_objfile
4649 = get_dwarf2_per_objfile (objfile
);
4651 if (!dwarf2_per_objfile
->filenames_cache
)
4653 dwarf2_per_objfile
->filenames_cache
.emplace ();
4655 htab_up
visited (htab_create_alloc (10,
4656 htab_hash_pointer
, htab_eq_pointer
,
4657 NULL
, xcalloc
, xfree
));
4659 /* The rule is CUs specify all the files, including those used
4660 by any TU, so there's no need to scan TUs here. We can
4661 ignore file names coming from already-expanded CUs. */
4663 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4665 if (per_cu
->v
.quick
->compunit_symtab
)
4667 void **slot
= htab_find_slot (visited
.get (),
4668 per_cu
->v
.quick
->file_names
,
4671 *slot
= per_cu
->v
.quick
->file_names
;
4675 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4677 /* We only need to look at symtabs not already expanded. */
4678 if (per_cu
->v
.quick
->compunit_symtab
)
4681 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4682 if (file_data
== NULL
)
4685 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4688 /* Already visited. */
4693 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4695 const char *filename
= file_data
->file_names
[j
];
4696 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4701 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4703 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4706 this_real_name
= gdb_realpath (filename
);
4707 (*fun
) (filename
, this_real_name
.get (), data
);
4712 dw2_has_symbols (struct objfile
*objfile
)
4717 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4720 dw2_find_last_source_symtab
,
4721 dw2_forget_cached_source_info
,
4722 dw2_map_symtabs_matching_filename
,
4726 dw2_expand_symtabs_for_function
,
4727 dw2_expand_all_symtabs
,
4728 dw2_expand_symtabs_with_fullname
,
4729 dw2_map_matching_symbols
,
4730 dw2_expand_symtabs_matching
,
4731 dw2_find_pc_sect_compunit_symtab
,
4733 dw2_map_symbol_filenames
4736 /* DWARF-5 debug_names reader. */
4738 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4739 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4741 /* A helper function that reads the .debug_names section in SECTION
4742 and fills in MAP. FILENAME is the name of the file containing the
4743 section; it is used for error reporting.
4745 Returns true if all went well, false otherwise. */
4748 read_debug_names_from_section (struct objfile
*objfile
,
4749 const char *filename
,
4750 struct dwarf2_section_info
*section
,
4751 mapped_debug_names
&map
)
4753 if (section
->empty ())
4756 /* Older elfutils strip versions could keep the section in the main
4757 executable while splitting it for the separate debug info file. */
4758 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4761 section
->read (objfile
);
4763 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4765 const gdb_byte
*addr
= section
->buffer
;
4767 bfd
*const abfd
= section
->get_bfd_owner ();
4769 unsigned int bytes_read
;
4770 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4773 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4774 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4775 if (bytes_read
+ length
!= section
->size
)
4777 /* There may be multiple per-CU indices. */
4778 warning (_("Section .debug_names in %s length %s does not match "
4779 "section length %s, ignoring .debug_names."),
4780 filename
, plongest (bytes_read
+ length
),
4781 pulongest (section
->size
));
4785 /* The version number. */
4786 uint16_t version
= read_2_bytes (abfd
, addr
);
4790 warning (_("Section .debug_names in %s has unsupported version %d, "
4791 "ignoring .debug_names."),
4797 uint16_t padding
= read_2_bytes (abfd
, addr
);
4801 warning (_("Section .debug_names in %s has unsupported padding %d, "
4802 "ignoring .debug_names."),
4807 /* comp_unit_count - The number of CUs in the CU list. */
4808 map
.cu_count
= read_4_bytes (abfd
, addr
);
4811 /* local_type_unit_count - The number of TUs in the local TU
4813 map
.tu_count
= read_4_bytes (abfd
, addr
);
4816 /* foreign_type_unit_count - The number of TUs in the foreign TU
4818 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4820 if (foreign_tu_count
!= 0)
4822 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4823 "ignoring .debug_names."),
4824 filename
, static_cast<unsigned long> (foreign_tu_count
));
4828 /* bucket_count - The number of hash buckets in the hash lookup
4830 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4833 /* name_count - The number of unique names in the index. */
4834 map
.name_count
= read_4_bytes (abfd
, addr
);
4837 /* abbrev_table_size - The size in bytes of the abbreviations
4839 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4842 /* augmentation_string_size - The size in bytes of the augmentation
4843 string. This value is rounded up to a multiple of 4. */
4844 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4846 map
.augmentation_is_gdb
= ((augmentation_string_size
4847 == sizeof (dwarf5_augmentation
))
4848 && memcmp (addr
, dwarf5_augmentation
,
4849 sizeof (dwarf5_augmentation
)) == 0);
4850 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4851 addr
+= augmentation_string_size
;
4854 map
.cu_table_reordered
= addr
;
4855 addr
+= map
.cu_count
* map
.offset_size
;
4857 /* List of Local TUs */
4858 map
.tu_table_reordered
= addr
;
4859 addr
+= map
.tu_count
* map
.offset_size
;
4861 /* Hash Lookup Table */
4862 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4863 addr
+= map
.bucket_count
* 4;
4864 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4865 addr
+= map
.name_count
* 4;
4868 map
.name_table_string_offs_reordered
= addr
;
4869 addr
+= map
.name_count
* map
.offset_size
;
4870 map
.name_table_entry_offs_reordered
= addr
;
4871 addr
+= map
.name_count
* map
.offset_size
;
4873 const gdb_byte
*abbrev_table_start
= addr
;
4876 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4881 const auto insertpair
4882 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4883 if (!insertpair
.second
)
4885 warning (_("Section .debug_names in %s has duplicate index %s, "
4886 "ignoring .debug_names."),
4887 filename
, pulongest (index_num
));
4890 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4891 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4896 mapped_debug_names::index_val::attr attr
;
4897 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4899 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4901 if (attr
.form
== DW_FORM_implicit_const
)
4903 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4907 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4909 indexval
.attr_vec
.push_back (std::move (attr
));
4912 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4914 warning (_("Section .debug_names in %s has abbreviation_table "
4915 "of size %s vs. written as %u, ignoring .debug_names."),
4916 filename
, plongest (addr
- abbrev_table_start
),
4920 map
.entry_pool
= addr
;
4925 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4929 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4930 const mapped_debug_names
&map
,
4931 dwarf2_section_info
§ion
,
4934 sect_offset sect_off_prev
;
4935 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4937 sect_offset sect_off_next
;
4938 if (i
< map
.cu_count
)
4941 = (sect_offset
) (extract_unsigned_integer
4942 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4944 map
.dwarf5_byte_order
));
4947 sect_off_next
= (sect_offset
) section
.size
;
4950 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4951 dwarf2_per_cu_data
*per_cu
4952 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
4953 sect_off_prev
, length
);
4954 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
4956 sect_off_prev
= sect_off_next
;
4960 /* Read the CU list from the mapped index, and use it to create all
4961 the CU objects for this dwarf2_per_objfile. */
4964 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4965 const mapped_debug_names
&map
,
4966 const mapped_debug_names
&dwz_map
)
4968 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
4969 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4971 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
4972 dwarf2_per_objfile
->info
,
4973 false /* is_dwz */);
4975 if (dwz_map
.cu_count
== 0)
4978 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
4979 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
4983 /* Read .debug_names. If everything went ok, initialize the "quick"
4984 elements of all the CUs and return true. Otherwise, return false. */
4987 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
4989 std::unique_ptr
<mapped_debug_names
> map
4990 (new mapped_debug_names (dwarf2_per_objfile
));
4991 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
4992 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4994 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4995 &dwarf2_per_objfile
->debug_names
,
4999 /* Don't use the index if it's empty. */
5000 if (map
->name_count
== 0)
5003 /* If there is a .dwz file, read it so we can get its CU list as
5005 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5008 if (!read_debug_names_from_section (objfile
,
5009 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5010 &dwz
->debug_names
, dwz_map
))
5012 warning (_("could not read '.debug_names' section from %s; skipping"),
5013 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5018 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5020 if (map
->tu_count
!= 0)
5022 /* We can only handle a single .debug_types when we have an
5024 if (dwarf2_per_objfile
->types
.size () != 1)
5027 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5029 create_signatured_type_table_from_debug_names
5030 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5033 create_addrmap_from_aranges (dwarf2_per_objfile
,
5034 &dwarf2_per_objfile
->debug_aranges
);
5036 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5037 dwarf2_per_objfile
->using_index
= 1;
5038 dwarf2_per_objfile
->quick_file_names_table
=
5039 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5044 /* Type used to manage iterating over all CUs looking for a symbol for
5047 class dw2_debug_names_iterator
5050 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5051 gdb::optional
<block_enum
> block_index
,
5054 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5055 m_addr (find_vec_in_debug_names (map
, name
))
5058 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5059 search_domain search
, uint32_t namei
)
5062 m_addr (find_vec_in_debug_names (map
, namei
))
5065 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5066 block_enum block_index
, domain_enum domain
,
5068 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5069 m_addr (find_vec_in_debug_names (map
, namei
))
5072 /* Return the next matching CU or NULL if there are no more. */
5073 dwarf2_per_cu_data
*next ();
5076 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5078 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5081 /* The internalized form of .debug_names. */
5082 const mapped_debug_names
&m_map
;
5084 /* If set, only look for symbols that match that block. Valid values are
5085 GLOBAL_BLOCK and STATIC_BLOCK. */
5086 const gdb::optional
<block_enum
> m_block_index
;
5088 /* The kind of symbol we're looking for. */
5089 const domain_enum m_domain
= UNDEF_DOMAIN
;
5090 const search_domain m_search
= ALL_DOMAIN
;
5092 /* The list of CUs from the index entry of the symbol, or NULL if
5094 const gdb_byte
*m_addr
;
5098 mapped_debug_names::namei_to_name (uint32_t namei
) const
5100 const ULONGEST namei_string_offs
5101 = extract_unsigned_integer ((name_table_string_offs_reordered
5102 + namei
* offset_size
),
5105 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5109 /* Find a slot in .debug_names for the object named NAME. If NAME is
5110 found, return pointer to its pool data. If NAME cannot be found,
5114 dw2_debug_names_iterator::find_vec_in_debug_names
5115 (const mapped_debug_names
&map
, const char *name
)
5117 int (*cmp
) (const char *, const char *);
5119 gdb::unique_xmalloc_ptr
<char> without_params
;
5120 if (current_language
->la_language
== language_cplus
5121 || current_language
->la_language
== language_fortran
5122 || current_language
->la_language
== language_d
)
5124 /* NAME is already canonical. Drop any qualifiers as
5125 .debug_names does not contain any. */
5127 if (strchr (name
, '(') != NULL
)
5129 without_params
= cp_remove_params (name
);
5130 if (without_params
!= NULL
)
5131 name
= without_params
.get ();
5135 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5137 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5139 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5140 (map
.bucket_table_reordered
5141 + (full_hash
% map
.bucket_count
)), 4,
5142 map
.dwarf5_byte_order
);
5146 if (namei
>= map
.name_count
)
5148 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5150 namei
, map
.name_count
,
5151 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5157 const uint32_t namei_full_hash
5158 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5159 (map
.hash_table_reordered
+ namei
), 4,
5160 map
.dwarf5_byte_order
);
5161 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5164 if (full_hash
== namei_full_hash
)
5166 const char *const namei_string
= map
.namei_to_name (namei
);
5168 #if 0 /* An expensive sanity check. */
5169 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5171 complaint (_("Wrong .debug_names hash for string at index %u "
5173 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5178 if (cmp (namei_string
, name
) == 0)
5180 const ULONGEST namei_entry_offs
5181 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5182 + namei
* map
.offset_size
),
5183 map
.offset_size
, map
.dwarf5_byte_order
);
5184 return map
.entry_pool
+ namei_entry_offs
;
5189 if (namei
>= map
.name_count
)
5195 dw2_debug_names_iterator::find_vec_in_debug_names
5196 (const mapped_debug_names
&map
, uint32_t namei
)
5198 if (namei
>= map
.name_count
)
5200 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5202 namei
, map
.name_count
,
5203 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5207 const ULONGEST namei_entry_offs
5208 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5209 + namei
* map
.offset_size
),
5210 map
.offset_size
, map
.dwarf5_byte_order
);
5211 return map
.entry_pool
+ namei_entry_offs
;
5214 /* See dw2_debug_names_iterator. */
5216 dwarf2_per_cu_data
*
5217 dw2_debug_names_iterator::next ()
5222 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5223 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5224 bfd
*const abfd
= objfile
->obfd
;
5228 unsigned int bytes_read
;
5229 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5230 m_addr
+= bytes_read
;
5234 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5235 if (indexval_it
== m_map
.abbrev_map
.cend ())
5237 complaint (_("Wrong .debug_names undefined abbrev code %s "
5239 pulongest (abbrev
), objfile_name (objfile
));
5242 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5243 enum class symbol_linkage
{
5247 } symbol_linkage_
= symbol_linkage::unknown
;
5248 dwarf2_per_cu_data
*per_cu
= NULL
;
5249 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5254 case DW_FORM_implicit_const
:
5255 ull
= attr
.implicit_const
;
5257 case DW_FORM_flag_present
:
5261 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5262 m_addr
+= bytes_read
;
5265 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5266 dwarf_form_name (attr
.form
),
5267 objfile_name (objfile
));
5270 switch (attr
.dw_idx
)
5272 case DW_IDX_compile_unit
:
5273 /* Don't crash on bad data. */
5274 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5276 complaint (_(".debug_names entry has bad CU index %s"
5279 objfile_name (dwarf2_per_objfile
->objfile
));
5282 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5284 case DW_IDX_type_unit
:
5285 /* Don't crash on bad data. */
5286 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5288 complaint (_(".debug_names entry has bad TU index %s"
5291 objfile_name (dwarf2_per_objfile
->objfile
));
5294 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5296 case DW_IDX_GNU_internal
:
5297 if (!m_map
.augmentation_is_gdb
)
5299 symbol_linkage_
= symbol_linkage::static_
;
5301 case DW_IDX_GNU_external
:
5302 if (!m_map
.augmentation_is_gdb
)
5304 symbol_linkage_
= symbol_linkage::extern_
;
5309 /* Skip if already read in. */
5310 if (per_cu
->v
.quick
->compunit_symtab
)
5313 /* Check static vs global. */
5314 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5316 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5317 const bool symbol_is_static
=
5318 symbol_linkage_
== symbol_linkage::static_
;
5319 if (want_static
!= symbol_is_static
)
5323 /* Match dw2_symtab_iter_next, symbol_kind
5324 and debug_names::psymbol_tag. */
5328 switch (indexval
.dwarf_tag
)
5330 case DW_TAG_variable
:
5331 case DW_TAG_subprogram
:
5332 /* Some types are also in VAR_DOMAIN. */
5333 case DW_TAG_typedef
:
5334 case DW_TAG_structure_type
:
5341 switch (indexval
.dwarf_tag
)
5343 case DW_TAG_typedef
:
5344 case DW_TAG_structure_type
:
5351 switch (indexval
.dwarf_tag
)
5354 case DW_TAG_variable
:
5361 switch (indexval
.dwarf_tag
)
5373 /* Match dw2_expand_symtabs_matching, symbol_kind and
5374 debug_names::psymbol_tag. */
5377 case VARIABLES_DOMAIN
:
5378 switch (indexval
.dwarf_tag
)
5380 case DW_TAG_variable
:
5386 case FUNCTIONS_DOMAIN
:
5387 switch (indexval
.dwarf_tag
)
5389 case DW_TAG_subprogram
:
5396 switch (indexval
.dwarf_tag
)
5398 case DW_TAG_typedef
:
5399 case DW_TAG_structure_type
:
5405 case MODULES_DOMAIN
:
5406 switch (indexval
.dwarf_tag
)
5420 static struct compunit_symtab
*
5421 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5422 const char *name
, domain_enum domain
)
5424 struct dwarf2_per_objfile
*dwarf2_per_objfile
5425 = get_dwarf2_per_objfile (objfile
);
5427 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5430 /* index is NULL if OBJF_READNOW. */
5433 const auto &map
= *mapp
;
5435 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5437 struct compunit_symtab
*stab_best
= NULL
;
5438 struct dwarf2_per_cu_data
*per_cu
;
5439 while ((per_cu
= iter
.next ()) != NULL
)
5441 struct symbol
*sym
, *with_opaque
= NULL
;
5442 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5443 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5444 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5446 sym
= block_find_symbol (block
, name
, domain
,
5447 block_find_non_opaque_type_preferred
,
5450 /* Some caution must be observed with overloaded functions and
5451 methods, since the index will not contain any overload
5452 information (but NAME might contain it). */
5455 && strcmp_iw (sym
->search_name (), name
) == 0)
5457 if (with_opaque
!= NULL
5458 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5461 /* Keep looking through other CUs. */
5467 /* This dumps minimal information about .debug_names. It is called
5468 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5469 uses this to verify that .debug_names has been loaded. */
5472 dw2_debug_names_dump (struct objfile
*objfile
)
5474 struct dwarf2_per_objfile
*dwarf2_per_objfile
5475 = get_dwarf2_per_objfile (objfile
);
5477 gdb_assert (dwarf2_per_objfile
->using_index
);
5478 printf_filtered (".debug_names:");
5479 if (dwarf2_per_objfile
->debug_names_table
)
5480 printf_filtered (" exists\n");
5482 printf_filtered (" faked for \"readnow\"\n");
5483 printf_filtered ("\n");
5487 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5488 const char *func_name
)
5490 struct dwarf2_per_objfile
*dwarf2_per_objfile
5491 = get_dwarf2_per_objfile (objfile
);
5493 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5494 if (dwarf2_per_objfile
->debug_names_table
)
5496 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5498 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5500 struct dwarf2_per_cu_data
*per_cu
;
5501 while ((per_cu
= iter
.next ()) != NULL
)
5502 dw2_instantiate_symtab (per_cu
, false);
5507 dw2_debug_names_map_matching_symbols
5508 (struct objfile
*objfile
,
5509 const lookup_name_info
&name
, domain_enum domain
,
5511 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5512 symbol_compare_ftype
*ordered_compare
)
5514 struct dwarf2_per_objfile
*dwarf2_per_objfile
5515 = get_dwarf2_per_objfile (objfile
);
5517 /* debug_names_table is NULL if OBJF_READNOW. */
5518 if (!dwarf2_per_objfile
->debug_names_table
)
5521 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5522 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5524 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5525 auto matcher
= [&] (const char *symname
)
5527 if (ordered_compare
== nullptr)
5529 return ordered_compare (symname
, match_name
) == 0;
5532 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5533 [&] (offset_type namei
)
5535 /* The name was matched, now expand corresponding CUs that were
5537 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5539 struct dwarf2_per_cu_data
*per_cu
;
5540 while ((per_cu
= iter
.next ()) != NULL
)
5541 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5545 /* It's a shame we couldn't do this inside the
5546 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5547 that have already been expanded. Instead, this loop matches what
5548 the psymtab code does. */
5549 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5551 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5552 if (cust
!= nullptr)
5554 const struct block
*block
5555 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5556 if (!iterate_over_symbols_terminated (block
, name
,
5564 dw2_debug_names_expand_symtabs_matching
5565 (struct objfile
*objfile
,
5566 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5567 const lookup_name_info
&lookup_name
,
5568 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5569 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5570 enum search_domain kind
)
5572 struct dwarf2_per_objfile
*dwarf2_per_objfile
5573 = get_dwarf2_per_objfile (objfile
);
5575 /* debug_names_table is NULL if OBJF_READNOW. */
5576 if (!dwarf2_per_objfile
->debug_names_table
)
5579 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5581 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5583 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5585 kind
, [&] (offset_type namei
)
5587 /* The name was matched, now expand corresponding CUs that were
5589 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5591 struct dwarf2_per_cu_data
*per_cu
;
5592 while ((per_cu
= iter
.next ()) != NULL
)
5593 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5599 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5602 dw2_find_last_source_symtab
,
5603 dw2_forget_cached_source_info
,
5604 dw2_map_symtabs_matching_filename
,
5605 dw2_debug_names_lookup_symbol
,
5607 dw2_debug_names_dump
,
5608 dw2_debug_names_expand_symtabs_for_function
,
5609 dw2_expand_all_symtabs
,
5610 dw2_expand_symtabs_with_fullname
,
5611 dw2_debug_names_map_matching_symbols
,
5612 dw2_debug_names_expand_symtabs_matching
,
5613 dw2_find_pc_sect_compunit_symtab
,
5615 dw2_map_symbol_filenames
5618 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5619 to either a dwarf2_per_objfile or dwz_file object. */
5621 template <typename T
>
5622 static gdb::array_view
<const gdb_byte
>
5623 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5625 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5627 if (section
->empty ())
5630 /* Older elfutils strip versions could keep the section in the main
5631 executable while splitting it for the separate debug info file. */
5632 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5635 section
->read (obj
);
5637 /* dwarf2_section_info::size is a bfd_size_type, while
5638 gdb::array_view works with size_t. On 32-bit hosts, with
5639 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5640 is 32-bit. So we need an explicit narrowing conversion here.
5641 This is fine, because it's impossible to allocate or mmap an
5642 array/buffer larger than what size_t can represent. */
5643 return gdb::make_array_view (section
->buffer
, section
->size
);
5646 /* Lookup the index cache for the contents of the index associated to
5649 static gdb::array_view
<const gdb_byte
>
5650 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5652 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5653 if (build_id
== nullptr)
5656 return global_index_cache
.lookup_gdb_index (build_id
,
5657 &dwarf2_obj
->index_cache_res
);
5660 /* Same as the above, but for DWZ. */
5662 static gdb::array_view
<const gdb_byte
>
5663 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5665 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5666 if (build_id
== nullptr)
5669 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5672 /* See symfile.h. */
5675 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5677 struct dwarf2_per_objfile
*dwarf2_per_objfile
5678 = get_dwarf2_per_objfile (objfile
);
5680 /* If we're about to read full symbols, don't bother with the
5681 indices. In this case we also don't care if some other debug
5682 format is making psymtabs, because they are all about to be
5684 if ((objfile
->flags
& OBJF_READNOW
))
5686 dwarf2_per_objfile
->using_index
= 1;
5687 create_all_comp_units (dwarf2_per_objfile
);
5688 create_all_type_units (dwarf2_per_objfile
);
5689 dwarf2_per_objfile
->quick_file_names_table
5690 = create_quick_file_names_table
5691 (dwarf2_per_objfile
->all_comp_units
.size ());
5693 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5694 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5696 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5698 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5699 struct dwarf2_per_cu_quick_data
);
5702 /* Return 1 so that gdb sees the "quick" functions. However,
5703 these functions will be no-ops because we will have expanded
5705 *index_kind
= dw_index_kind::GDB_INDEX
;
5709 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5711 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5715 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5716 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5717 get_gdb_index_contents_from_section
<dwz_file
>))
5719 *index_kind
= dw_index_kind::GDB_INDEX
;
5723 /* ... otherwise, try to find the index in the index cache. */
5724 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5725 get_gdb_index_contents_from_cache
,
5726 get_gdb_index_contents_from_cache_dwz
))
5728 global_index_cache
.hit ();
5729 *index_kind
= dw_index_kind::GDB_INDEX
;
5733 global_index_cache
.miss ();
5739 /* Build a partial symbol table. */
5742 dwarf2_build_psymtabs (struct objfile
*objfile
)
5744 struct dwarf2_per_objfile
*dwarf2_per_objfile
5745 = get_dwarf2_per_objfile (objfile
);
5747 init_psymbol_list (objfile
, 1024);
5751 /* This isn't really ideal: all the data we allocate on the
5752 objfile's obstack is still uselessly kept around. However,
5753 freeing it seems unsafe. */
5754 psymtab_discarder
psymtabs (objfile
);
5755 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5758 /* (maybe) store an index in the cache. */
5759 global_index_cache
.store (dwarf2_per_objfile
);
5761 catch (const gdb_exception_error
&except
)
5763 exception_print (gdb_stderr
, except
);
5767 /* Find the base address of the compilation unit for range lists and
5768 location lists. It will normally be specified by DW_AT_low_pc.
5769 In DWARF-3 draft 4, the base address could be overridden by
5770 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5771 compilation units with discontinuous ranges. */
5774 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5776 struct attribute
*attr
;
5778 cu
->base_address
.reset ();
5780 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5781 if (attr
!= nullptr)
5782 cu
->base_address
= attr
->value_as_address ();
5785 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5786 if (attr
!= nullptr)
5787 cu
->base_address
= attr
->value_as_address ();
5791 /* Helper function that returns the proper abbrev section for
5794 static struct dwarf2_section_info
*
5795 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5797 struct dwarf2_section_info
*abbrev
;
5798 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5800 if (this_cu
->is_dwz
)
5801 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5803 abbrev
= &dwarf2_per_objfile
->abbrev
;
5808 /* Fetch the abbreviation table offset from a comp or type unit header. */
5811 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5812 struct dwarf2_section_info
*section
,
5813 sect_offset sect_off
)
5815 bfd
*abfd
= section
->get_bfd_owner ();
5816 const gdb_byte
*info_ptr
;
5817 unsigned int initial_length_size
, offset_size
;
5820 section
->read (dwarf2_per_objfile
->objfile
);
5821 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5822 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5823 offset_size
= initial_length_size
== 4 ? 4 : 8;
5824 info_ptr
+= initial_length_size
;
5826 version
= read_2_bytes (abfd
, info_ptr
);
5830 /* Skip unit type and address size. */
5834 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5837 /* A partial symtab that is used only for include files. */
5838 struct dwarf2_include_psymtab
: public partial_symtab
5840 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5841 : partial_symtab (filename
, objfile
)
5845 void read_symtab (struct objfile
*objfile
) override
5847 expand_psymtab (objfile
);
5850 void expand_psymtab (struct objfile
*objfile
) override
5854 /* It's an include file, no symbols to read for it.
5855 Everything is in the parent symtab. */
5856 read_dependencies (objfile
);
5860 bool readin_p () const override
5865 struct compunit_symtab
*get_compunit_symtab () const override
5872 bool m_readin
= false;
5875 /* Allocate a new partial symtab for file named NAME and mark this new
5876 partial symtab as being an include of PST. */
5879 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5880 struct objfile
*objfile
)
5882 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5884 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5886 /* It shares objfile->objfile_obstack. */
5887 subpst
->dirname
= pst
->dirname
;
5890 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5891 subpst
->dependencies
[0] = pst
;
5892 subpst
->number_of_dependencies
= 1;
5895 /* Read the Line Number Program data and extract the list of files
5896 included by the source file represented by PST. Build an include
5897 partial symtab for each of these included files. */
5900 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5901 struct die_info
*die
,
5902 dwarf2_psymtab
*pst
)
5905 struct attribute
*attr
;
5907 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5908 if (attr
!= nullptr)
5909 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5911 return; /* No linetable, so no includes. */
5913 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5914 that we pass in the raw text_low here; that is ok because we're
5915 only decoding the line table to make include partial symtabs, and
5916 so the addresses aren't really used. */
5917 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5918 pst
->raw_text_low (), 1);
5922 hash_signatured_type (const void *item
)
5924 const struct signatured_type
*sig_type
5925 = (const struct signatured_type
*) item
;
5927 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5928 return sig_type
->signature
;
5932 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5934 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5935 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5937 return lhs
->signature
== rhs
->signature
;
5940 /* Allocate a hash table for signatured types. */
5943 allocate_signatured_type_table ()
5945 return htab_up (htab_create_alloc (41,
5946 hash_signatured_type
,
5948 NULL
, xcalloc
, xfree
));
5951 /* A helper function to add a signatured type CU to a table. */
5954 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5956 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5957 std::vector
<signatured_type
*> *all_type_units
5958 = (std::vector
<signatured_type
*> *) datum
;
5960 all_type_units
->push_back (sigt
);
5965 /* A helper for create_debug_types_hash_table. Read types from SECTION
5966 and fill them into TYPES_HTAB. It will process only type units,
5967 therefore DW_UT_type. */
5970 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5971 struct dwo_file
*dwo_file
,
5972 dwarf2_section_info
*section
, htab_up
&types_htab
,
5973 rcuh_kind section_kind
)
5975 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5976 struct dwarf2_section_info
*abbrev_section
;
5978 const gdb_byte
*info_ptr
, *end_ptr
;
5980 abbrev_section
= (dwo_file
!= NULL
5981 ? &dwo_file
->sections
.abbrev
5982 : &dwarf2_per_objfile
->abbrev
);
5984 if (dwarf_read_debug
)
5985 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
5986 section
->get_name (),
5987 abbrev_section
->get_file_name ());
5989 section
->read (objfile
);
5990 info_ptr
= section
->buffer
;
5992 if (info_ptr
== NULL
)
5995 /* We can't set abfd until now because the section may be empty or
5996 not present, in which case the bfd is unknown. */
5997 abfd
= section
->get_bfd_owner ();
5999 /* We don't use cutu_reader here because we don't need to read
6000 any dies: the signature is in the header. */
6002 end_ptr
= info_ptr
+ section
->size
;
6003 while (info_ptr
< end_ptr
)
6005 struct signatured_type
*sig_type
;
6006 struct dwo_unit
*dwo_tu
;
6008 const gdb_byte
*ptr
= info_ptr
;
6009 struct comp_unit_head header
;
6010 unsigned int length
;
6012 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6014 /* Initialize it due to a false compiler warning. */
6015 header
.signature
= -1;
6016 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6018 /* We need to read the type's signature in order to build the hash
6019 table, but we don't need anything else just yet. */
6021 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6022 abbrev_section
, ptr
, section_kind
);
6024 length
= header
.get_length ();
6026 /* Skip dummy type units. */
6027 if (ptr
>= info_ptr
+ length
6028 || peek_abbrev_code (abfd
, ptr
) == 0
6029 || header
.unit_type
!= DW_UT_type
)
6035 if (types_htab
== NULL
)
6038 types_htab
= allocate_dwo_unit_table ();
6040 types_htab
= allocate_signatured_type_table ();
6046 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6048 dwo_tu
->dwo_file
= dwo_file
;
6049 dwo_tu
->signature
= header
.signature
;
6050 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6051 dwo_tu
->section
= section
;
6052 dwo_tu
->sect_off
= sect_off
;
6053 dwo_tu
->length
= length
;
6057 /* N.B.: type_offset is not usable if this type uses a DWO file.
6058 The real type_offset is in the DWO file. */
6060 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6061 struct signatured_type
);
6062 sig_type
->signature
= header
.signature
;
6063 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6064 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6065 sig_type
->per_cu
.is_debug_types
= 1;
6066 sig_type
->per_cu
.section
= section
;
6067 sig_type
->per_cu
.sect_off
= sect_off
;
6068 sig_type
->per_cu
.length
= length
;
6071 slot
= htab_find_slot (types_htab
.get (),
6072 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6074 gdb_assert (slot
!= NULL
);
6077 sect_offset dup_sect_off
;
6081 const struct dwo_unit
*dup_tu
6082 = (const struct dwo_unit
*) *slot
;
6084 dup_sect_off
= dup_tu
->sect_off
;
6088 const struct signatured_type
*dup_tu
6089 = (const struct signatured_type
*) *slot
;
6091 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6094 complaint (_("debug type entry at offset %s is duplicate to"
6095 " the entry at offset %s, signature %s"),
6096 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6097 hex_string (header
.signature
));
6099 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6101 if (dwarf_read_debug
> 1)
6102 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6103 sect_offset_str (sect_off
),
6104 hex_string (header
.signature
));
6110 /* Create the hash table of all entries in the .debug_types
6111 (or .debug_types.dwo) section(s).
6112 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6113 otherwise it is NULL.
6115 The result is a pointer to the hash table or NULL if there are no types.
6117 Note: This function processes DWO files only, not DWP files. */
6120 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6121 struct dwo_file
*dwo_file
,
6122 gdb::array_view
<dwarf2_section_info
> type_sections
,
6123 htab_up
&types_htab
)
6125 for (dwarf2_section_info
§ion
: type_sections
)
6126 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6127 types_htab
, rcuh_kind::TYPE
);
6130 /* Create the hash table of all entries in the .debug_types section,
6131 and initialize all_type_units.
6132 The result is zero if there is an error (e.g. missing .debug_types section),
6133 otherwise non-zero. */
6136 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6140 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6141 &dwarf2_per_objfile
->info
, types_htab
,
6142 rcuh_kind::COMPILE
);
6143 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6144 dwarf2_per_objfile
->types
, types_htab
);
6145 if (types_htab
== NULL
)
6147 dwarf2_per_objfile
->signatured_types
= NULL
;
6151 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6153 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6154 dwarf2_per_objfile
->all_type_units
.reserve
6155 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6157 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6158 add_signatured_type_cu_to_table
,
6159 &dwarf2_per_objfile
->all_type_units
);
6164 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6165 If SLOT is non-NULL, it is the entry to use in the hash table.
6166 Otherwise we find one. */
6168 static struct signatured_type
*
6169 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6172 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6174 if (dwarf2_per_objfile
->all_type_units
.size ()
6175 == dwarf2_per_objfile
->all_type_units
.capacity ())
6176 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6178 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6179 struct signatured_type
);
6181 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6182 sig_type
->signature
= sig
;
6183 sig_type
->per_cu
.is_debug_types
= 1;
6184 if (dwarf2_per_objfile
->using_index
)
6186 sig_type
->per_cu
.v
.quick
=
6187 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6188 struct dwarf2_per_cu_quick_data
);
6193 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6196 gdb_assert (*slot
== NULL
);
6198 /* The rest of sig_type must be filled in by the caller. */
6202 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6203 Fill in SIG_ENTRY with DWO_ENTRY. */
6206 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6207 struct signatured_type
*sig_entry
,
6208 struct dwo_unit
*dwo_entry
)
6210 /* Make sure we're not clobbering something we don't expect to. */
6211 gdb_assert (! sig_entry
->per_cu
.queued
);
6212 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6213 if (dwarf2_per_objfile
->using_index
)
6215 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6216 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6219 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6220 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6221 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6222 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6223 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6225 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6226 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6227 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6228 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6229 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6230 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6231 sig_entry
->dwo_unit
= dwo_entry
;
6234 /* Subroutine of lookup_signatured_type.
6235 If we haven't read the TU yet, create the signatured_type data structure
6236 for a TU to be read in directly from a DWO file, bypassing the stub.
6237 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6238 using .gdb_index, then when reading a CU we want to stay in the DWO file
6239 containing that CU. Otherwise we could end up reading several other DWO
6240 files (due to comdat folding) to process the transitive closure of all the
6241 mentioned TUs, and that can be slow. The current DWO file will have every
6242 type signature that it needs.
6243 We only do this for .gdb_index because in the psymtab case we already have
6244 to read all the DWOs to build the type unit groups. */
6246 static struct signatured_type
*
6247 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6249 struct dwarf2_per_objfile
*dwarf2_per_objfile
6250 = cu
->per_cu
->dwarf2_per_objfile
;
6251 struct dwo_file
*dwo_file
;
6252 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6253 struct signatured_type find_sig_entry
, *sig_entry
;
6256 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6258 /* If TU skeletons have been removed then we may not have read in any
6260 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6261 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6263 /* We only ever need to read in one copy of a signatured type.
6264 Use the global signatured_types array to do our own comdat-folding
6265 of types. If this is the first time we're reading this TU, and
6266 the TU has an entry in .gdb_index, replace the recorded data from
6267 .gdb_index with this TU. */
6269 find_sig_entry
.signature
= sig
;
6270 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6271 &find_sig_entry
, INSERT
);
6272 sig_entry
= (struct signatured_type
*) *slot
;
6274 /* We can get here with the TU already read, *or* in the process of being
6275 read. Don't reassign the global entry to point to this DWO if that's
6276 the case. Also note that if the TU is already being read, it may not
6277 have come from a DWO, the program may be a mix of Fission-compiled
6278 code and non-Fission-compiled code. */
6280 /* Have we already tried to read this TU?
6281 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6282 needn't exist in the global table yet). */
6283 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6286 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6287 dwo_unit of the TU itself. */
6288 dwo_file
= cu
->dwo_unit
->dwo_file
;
6290 /* Ok, this is the first time we're reading this TU. */
6291 if (dwo_file
->tus
== NULL
)
6293 find_dwo_entry
.signature
= sig
;
6294 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6296 if (dwo_entry
== NULL
)
6299 /* If the global table doesn't have an entry for this TU, add one. */
6300 if (sig_entry
== NULL
)
6301 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6303 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6304 sig_entry
->per_cu
.tu_read
= 1;
6308 /* Subroutine of lookup_signatured_type.
6309 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6310 then try the DWP file. If the TU stub (skeleton) has been removed then
6311 it won't be in .gdb_index. */
6313 static struct signatured_type
*
6314 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6316 struct dwarf2_per_objfile
*dwarf2_per_objfile
6317 = cu
->per_cu
->dwarf2_per_objfile
;
6318 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6319 struct dwo_unit
*dwo_entry
;
6320 struct signatured_type find_sig_entry
, *sig_entry
;
6323 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6324 gdb_assert (dwp_file
!= NULL
);
6326 /* If TU skeletons have been removed then we may not have read in any
6328 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6329 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6331 find_sig_entry
.signature
= sig
;
6332 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6333 &find_sig_entry
, INSERT
);
6334 sig_entry
= (struct signatured_type
*) *slot
;
6336 /* Have we already tried to read this TU?
6337 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6338 needn't exist in the global table yet). */
6339 if (sig_entry
!= NULL
)
6342 if (dwp_file
->tus
== NULL
)
6344 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6345 sig
, 1 /* is_debug_types */);
6346 if (dwo_entry
== NULL
)
6349 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6350 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6355 /* Lookup a signature based type for DW_FORM_ref_sig8.
6356 Returns NULL if signature SIG is not present in the table.
6357 It is up to the caller to complain about this. */
6359 static struct signatured_type
*
6360 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6362 struct dwarf2_per_objfile
*dwarf2_per_objfile
6363 = cu
->per_cu
->dwarf2_per_objfile
;
6366 && dwarf2_per_objfile
->using_index
)
6368 /* We're in a DWO/DWP file, and we're using .gdb_index.
6369 These cases require special processing. */
6370 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6371 return lookup_dwo_signatured_type (cu
, sig
);
6373 return lookup_dwp_signatured_type (cu
, sig
);
6377 struct signatured_type find_entry
, *entry
;
6379 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6381 find_entry
.signature
= sig
;
6382 entry
= ((struct signatured_type
*)
6383 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6389 /* Low level DIE reading support. */
6391 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6394 init_cu_die_reader (struct die_reader_specs
*reader
,
6395 struct dwarf2_cu
*cu
,
6396 struct dwarf2_section_info
*section
,
6397 struct dwo_file
*dwo_file
,
6398 struct abbrev_table
*abbrev_table
)
6400 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6401 reader
->abfd
= section
->get_bfd_owner ();
6403 reader
->dwo_file
= dwo_file
;
6404 reader
->die_section
= section
;
6405 reader
->buffer
= section
->buffer
;
6406 reader
->buffer_end
= section
->buffer
+ section
->size
;
6407 reader
->abbrev_table
= abbrev_table
;
6410 /* Subroutine of cutu_reader to simplify it.
6411 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6412 There's just a lot of work to do, and cutu_reader is big enough
6415 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6416 from it to the DIE in the DWO. If NULL we are skipping the stub.
6417 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6418 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6419 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6420 STUB_COMP_DIR may be non-NULL.
6421 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6422 are filled in with the info of the DIE from the DWO file.
6423 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6424 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6425 kept around for at least as long as *RESULT_READER.
6427 The result is non-zero if a valid (non-dummy) DIE was found. */
6430 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6431 struct dwo_unit
*dwo_unit
,
6432 struct die_info
*stub_comp_unit_die
,
6433 const char *stub_comp_dir
,
6434 struct die_reader_specs
*result_reader
,
6435 const gdb_byte
**result_info_ptr
,
6436 struct die_info
**result_comp_unit_die
,
6437 abbrev_table_up
*result_dwo_abbrev_table
)
6439 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6440 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6441 struct dwarf2_cu
*cu
= this_cu
->cu
;
6443 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6444 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6445 int i
,num_extra_attrs
;
6446 struct dwarf2_section_info
*dwo_abbrev_section
;
6447 struct die_info
*comp_unit_die
;
6449 /* At most one of these may be provided. */
6450 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6452 /* These attributes aren't processed until later:
6453 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6454 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6455 referenced later. However, these attributes are found in the stub
6456 which we won't have later. In order to not impose this complication
6457 on the rest of the code, we read them here and copy them to the
6466 if (stub_comp_unit_die
!= NULL
)
6468 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6470 if (! this_cu
->is_debug_types
)
6471 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6472 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6473 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6474 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6475 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6477 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6479 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6480 here (if needed). We need the value before we can process
6482 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6484 else if (stub_comp_dir
!= NULL
)
6486 /* Reconstruct the comp_dir attribute to simplify the code below. */
6487 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6488 comp_dir
->name
= DW_AT_comp_dir
;
6489 comp_dir
->form
= DW_FORM_string
;
6490 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6491 DW_STRING (comp_dir
) = stub_comp_dir
;
6494 /* Set up for reading the DWO CU/TU. */
6495 cu
->dwo_unit
= dwo_unit
;
6496 dwarf2_section_info
*section
= dwo_unit
->section
;
6497 section
->read (objfile
);
6498 abfd
= section
->get_bfd_owner ();
6499 begin_info_ptr
= info_ptr
= (section
->buffer
6500 + to_underlying (dwo_unit
->sect_off
));
6501 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6503 if (this_cu
->is_debug_types
)
6505 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6507 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6508 &cu
->header
, section
,
6510 info_ptr
, rcuh_kind::TYPE
);
6511 /* This is not an assert because it can be caused by bad debug info. */
6512 if (sig_type
->signature
!= cu
->header
.signature
)
6514 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6515 " TU at offset %s [in module %s]"),
6516 hex_string (sig_type
->signature
),
6517 hex_string (cu
->header
.signature
),
6518 sect_offset_str (dwo_unit
->sect_off
),
6519 bfd_get_filename (abfd
));
6521 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6522 /* For DWOs coming from DWP files, we don't know the CU length
6523 nor the type's offset in the TU until now. */
6524 dwo_unit
->length
= cu
->header
.get_length ();
6525 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6527 /* Establish the type offset that can be used to lookup the type.
6528 For DWO files, we don't know it until now. */
6529 sig_type
->type_offset_in_section
6530 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6534 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6535 &cu
->header
, section
,
6537 info_ptr
, rcuh_kind::COMPILE
);
6538 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6539 /* For DWOs coming from DWP files, we don't know the CU length
6541 dwo_unit
->length
= cu
->header
.get_length ();
6544 *result_dwo_abbrev_table
6545 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6546 cu
->header
.abbrev_sect_off
);
6547 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6548 result_dwo_abbrev_table
->get ());
6550 /* Read in the die, but leave space to copy over the attributes
6551 from the stub. This has the benefit of simplifying the rest of
6552 the code - all the work to maintain the illusion of a single
6553 DW_TAG_{compile,type}_unit DIE is done here. */
6554 num_extra_attrs
= ((stmt_list
!= NULL
)
6558 + (comp_dir
!= NULL
));
6559 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6562 /* Copy over the attributes from the stub to the DIE we just read in. */
6563 comp_unit_die
= *result_comp_unit_die
;
6564 i
= comp_unit_die
->num_attrs
;
6565 if (stmt_list
!= NULL
)
6566 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6568 comp_unit_die
->attrs
[i
++] = *low_pc
;
6569 if (high_pc
!= NULL
)
6570 comp_unit_die
->attrs
[i
++] = *high_pc
;
6572 comp_unit_die
->attrs
[i
++] = *ranges
;
6573 if (comp_dir
!= NULL
)
6574 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6575 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6577 if (dwarf_die_debug
)
6579 fprintf_unfiltered (gdb_stdlog
,
6580 "Read die from %s@0x%x of %s:\n",
6581 section
->get_name (),
6582 (unsigned) (begin_info_ptr
- section
->buffer
),
6583 bfd_get_filename (abfd
));
6584 dump_die (comp_unit_die
, dwarf_die_debug
);
6587 /* Skip dummy compilation units. */
6588 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6589 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6592 *result_info_ptr
= info_ptr
;
6596 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6597 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6598 signature is part of the header. */
6599 static gdb::optional
<ULONGEST
>
6600 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6602 if (cu
->header
.version
>= 5)
6603 return cu
->header
.signature
;
6604 struct attribute
*attr
;
6605 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6606 if (attr
== nullptr)
6607 return gdb::optional
<ULONGEST
> ();
6608 return DW_UNSND (attr
);
6611 /* Subroutine of cutu_reader to simplify it.
6612 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6613 Returns NULL if the specified DWO unit cannot be found. */
6615 static struct dwo_unit
*
6616 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6617 struct die_info
*comp_unit_die
,
6618 const char *dwo_name
)
6620 struct dwarf2_cu
*cu
= this_cu
->cu
;
6621 struct dwo_unit
*dwo_unit
;
6622 const char *comp_dir
;
6624 gdb_assert (cu
!= NULL
);
6626 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6627 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6628 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6630 if (this_cu
->is_debug_types
)
6632 struct signatured_type
*sig_type
;
6634 /* Since this_cu is the first member of struct signatured_type,
6635 we can go from a pointer to one to a pointer to the other. */
6636 sig_type
= (struct signatured_type
*) this_cu
;
6637 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6641 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6642 if (!signature
.has_value ())
6643 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6645 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6646 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6653 /* Subroutine of cutu_reader to simplify it.
6654 See it for a description of the parameters.
6655 Read a TU directly from a DWO file, bypassing the stub. */
6658 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6659 int use_existing_cu
)
6661 struct signatured_type
*sig_type
;
6663 /* Verify we can do the following downcast, and that we have the
6665 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6666 sig_type
= (struct signatured_type
*) this_cu
;
6667 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6669 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6671 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6672 /* There's no need to do the rereading_dwo_cu handling that
6673 cutu_reader does since we don't read the stub. */
6677 /* If !use_existing_cu, this_cu->cu must be NULL. */
6678 gdb_assert (this_cu
->cu
== NULL
);
6679 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6682 /* A future optimization, if needed, would be to use an existing
6683 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6684 could share abbrev tables. */
6686 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6687 NULL
/* stub_comp_unit_die */,
6688 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6691 &m_dwo_abbrev_table
) == 0)
6698 /* Initialize a CU (or TU) and read its DIEs.
6699 If the CU defers to a DWO file, read the DWO file as well.
6701 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6702 Otherwise the table specified in the comp unit header is read in and used.
6703 This is an optimization for when we already have the abbrev table.
6705 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6706 Otherwise, a new CU is allocated with xmalloc. */
6708 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6709 struct abbrev_table
*abbrev_table
,
6710 int use_existing_cu
,
6712 : die_reader_specs
{},
6715 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6716 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6717 struct dwarf2_section_info
*section
= this_cu
->section
;
6718 bfd
*abfd
= section
->get_bfd_owner ();
6719 struct dwarf2_cu
*cu
;
6720 const gdb_byte
*begin_info_ptr
;
6721 struct signatured_type
*sig_type
= NULL
;
6722 struct dwarf2_section_info
*abbrev_section
;
6723 /* Non-zero if CU currently points to a DWO file and we need to
6724 reread it. When this happens we need to reread the skeleton die
6725 before we can reread the DWO file (this only applies to CUs, not TUs). */
6726 int rereading_dwo_cu
= 0;
6728 if (dwarf_die_debug
)
6729 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6730 this_cu
->is_debug_types
? "type" : "comp",
6731 sect_offset_str (this_cu
->sect_off
));
6733 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6734 file (instead of going through the stub), short-circuit all of this. */
6735 if (this_cu
->reading_dwo_directly
)
6737 /* Narrow down the scope of possibilities to have to understand. */
6738 gdb_assert (this_cu
->is_debug_types
);
6739 gdb_assert (abbrev_table
== NULL
);
6740 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6744 /* This is cheap if the section is already read in. */
6745 section
->read (objfile
);
6747 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6749 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6751 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6754 /* If this CU is from a DWO file we need to start over, we need to
6755 refetch the attributes from the skeleton CU.
6756 This could be optimized by retrieving those attributes from when we
6757 were here the first time: the previous comp_unit_die was stored in
6758 comp_unit_obstack. But there's no data yet that we need this
6760 if (cu
->dwo_unit
!= NULL
)
6761 rereading_dwo_cu
= 1;
6765 /* If !use_existing_cu, this_cu->cu must be NULL. */
6766 gdb_assert (this_cu
->cu
== NULL
);
6767 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6768 cu
= m_new_cu
.get ();
6771 /* Get the header. */
6772 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6774 /* We already have the header, there's no need to read it in again. */
6775 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6779 if (this_cu
->is_debug_types
)
6781 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6782 &cu
->header
, section
,
6783 abbrev_section
, info_ptr
,
6786 /* Since per_cu is the first member of struct signatured_type,
6787 we can go from a pointer to one to a pointer to the other. */
6788 sig_type
= (struct signatured_type
*) this_cu
;
6789 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6790 gdb_assert (sig_type
->type_offset_in_tu
6791 == cu
->header
.type_cu_offset_in_tu
);
6792 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6794 /* LENGTH has not been set yet for type units if we're
6795 using .gdb_index. */
6796 this_cu
->length
= cu
->header
.get_length ();
6798 /* Establish the type offset that can be used to lookup the type. */
6799 sig_type
->type_offset_in_section
=
6800 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6802 this_cu
->dwarf_version
= cu
->header
.version
;
6806 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6807 &cu
->header
, section
,
6810 rcuh_kind::COMPILE
);
6812 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6813 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6814 this_cu
->dwarf_version
= cu
->header
.version
;
6818 /* Skip dummy compilation units. */
6819 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6820 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6826 /* If we don't have them yet, read the abbrevs for this compilation unit.
6827 And if we need to read them now, make sure they're freed when we're
6829 if (abbrev_table
!= NULL
)
6830 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6833 m_abbrev_table_holder
6834 = abbrev_table::read (objfile
, abbrev_section
,
6835 cu
->header
.abbrev_sect_off
);
6836 abbrev_table
= m_abbrev_table_holder
.get ();
6839 /* Read the top level CU/TU die. */
6840 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6841 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6843 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6849 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6850 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6851 table from the DWO file and pass the ownership over to us. It will be
6852 referenced from READER, so we must make sure to free it after we're done
6855 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6856 DWO CU, that this test will fail (the attribute will not be present). */
6857 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6858 if (dwo_name
!= nullptr)
6860 struct dwo_unit
*dwo_unit
;
6861 struct die_info
*dwo_comp_unit_die
;
6863 if (comp_unit_die
->has_children
)
6865 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6866 " has children (offset %s) [in module %s]"),
6867 sect_offset_str (this_cu
->sect_off
),
6868 bfd_get_filename (abfd
));
6870 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6871 if (dwo_unit
!= NULL
)
6873 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6874 comp_unit_die
, NULL
,
6877 &m_dwo_abbrev_table
) == 0)
6883 comp_unit_die
= dwo_comp_unit_die
;
6887 /* Yikes, we couldn't find the rest of the DIE, we only have
6888 the stub. A complaint has already been logged. There's
6889 not much more we can do except pass on the stub DIE to
6890 die_reader_func. We don't want to throw an error on bad
6897 cutu_reader::keep ()
6899 /* Done, clean up. */
6900 gdb_assert (!dummy_p
);
6901 if (m_new_cu
!= NULL
)
6903 struct dwarf2_per_objfile
*dwarf2_per_objfile
6904 = m_this_cu
->dwarf2_per_objfile
;
6905 /* Link this CU into read_in_chain. */
6906 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6907 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6908 /* The chain owns it now. */
6909 m_new_cu
.release ();
6913 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6914 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6915 assumed to have already done the lookup to find the DWO file).
6917 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6918 THIS_CU->is_debug_types, but nothing else.
6920 We fill in THIS_CU->length.
6922 THIS_CU->cu is always freed when done.
6923 This is done in order to not leave THIS_CU->cu in a state where we have
6924 to care whether it refers to the "main" CU or the DWO CU.
6926 When parent_cu is passed, it is used to provide a default value for
6927 str_offsets_base and addr_base from the parent. */
6929 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6930 struct dwarf2_cu
*parent_cu
,
6931 struct dwo_file
*dwo_file
)
6932 : die_reader_specs
{},
6935 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6936 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6937 struct dwarf2_section_info
*section
= this_cu
->section
;
6938 bfd
*abfd
= section
->get_bfd_owner ();
6939 struct dwarf2_section_info
*abbrev_section
;
6940 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6942 if (dwarf_die_debug
)
6943 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6944 this_cu
->is_debug_types
? "type" : "comp",
6945 sect_offset_str (this_cu
->sect_off
));
6947 gdb_assert (this_cu
->cu
== NULL
);
6949 abbrev_section
= (dwo_file
!= NULL
6950 ? &dwo_file
->sections
.abbrev
6951 : get_abbrev_section_for_cu (this_cu
));
6953 /* This is cheap if the section is already read in. */
6954 section
->read (objfile
);
6956 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6958 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6959 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6960 &m_new_cu
->header
, section
,
6961 abbrev_section
, info_ptr
,
6962 (this_cu
->is_debug_types
6964 : rcuh_kind::COMPILE
));
6966 if (parent_cu
!= nullptr)
6968 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6969 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6971 this_cu
->length
= m_new_cu
->header
.get_length ();
6973 /* Skip dummy compilation units. */
6974 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6975 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6981 m_abbrev_table_holder
6982 = abbrev_table::read (objfile
, abbrev_section
,
6983 m_new_cu
->header
.abbrev_sect_off
);
6985 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6986 m_abbrev_table_holder
.get ());
6987 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6991 /* Type Unit Groups.
6993 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6994 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6995 so that all types coming from the same compilation (.o file) are grouped
6996 together. A future step could be to put the types in the same symtab as
6997 the CU the types ultimately came from. */
7000 hash_type_unit_group (const void *item
)
7002 const struct type_unit_group
*tu_group
7003 = (const struct type_unit_group
*) item
;
7005 return hash_stmt_list_entry (&tu_group
->hash
);
7009 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7011 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7012 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7014 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7017 /* Allocate a hash table for type unit groups. */
7020 allocate_type_unit_groups_table ()
7022 return htab_up (htab_create_alloc (3,
7023 hash_type_unit_group
,
7025 NULL
, xcalloc
, xfree
));
7028 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7029 partial symtabs. We combine several TUs per psymtab to not let the size
7030 of any one psymtab grow too big. */
7031 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7032 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7034 /* Helper routine for get_type_unit_group.
7035 Create the type_unit_group object used to hold one or more TUs. */
7037 static struct type_unit_group
*
7038 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7040 struct dwarf2_per_objfile
*dwarf2_per_objfile
7041 = cu
->per_cu
->dwarf2_per_objfile
;
7042 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7043 struct dwarf2_per_cu_data
*per_cu
;
7044 struct type_unit_group
*tu_group
;
7046 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7047 struct type_unit_group
);
7048 per_cu
= &tu_group
->per_cu
;
7049 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7051 if (dwarf2_per_objfile
->using_index
)
7053 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7054 struct dwarf2_per_cu_quick_data
);
7058 unsigned int line_offset
= to_underlying (line_offset_struct
);
7059 dwarf2_psymtab
*pst
;
7062 /* Give the symtab a useful name for debug purposes. */
7063 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7064 name
= string_printf ("<type_units_%d>",
7065 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7067 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7069 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7070 pst
->anonymous
= true;
7073 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7074 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7079 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7080 STMT_LIST is a DW_AT_stmt_list attribute. */
7082 static struct type_unit_group
*
7083 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7085 struct dwarf2_per_objfile
*dwarf2_per_objfile
7086 = cu
->per_cu
->dwarf2_per_objfile
;
7087 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7088 struct type_unit_group
*tu_group
;
7090 unsigned int line_offset
;
7091 struct type_unit_group type_unit_group_for_lookup
;
7093 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7094 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7096 /* Do we need to create a new group, or can we use an existing one? */
7100 line_offset
= DW_UNSND (stmt_list
);
7101 ++tu_stats
->nr_symtab_sharers
;
7105 /* Ugh, no stmt_list. Rare, but we have to handle it.
7106 We can do various things here like create one group per TU or
7107 spread them over multiple groups to split up the expansion work.
7108 To avoid worst case scenarios (too many groups or too large groups)
7109 we, umm, group them in bunches. */
7110 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7111 | (tu_stats
->nr_stmt_less_type_units
7112 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7113 ++tu_stats
->nr_stmt_less_type_units
;
7116 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7117 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7118 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7119 &type_unit_group_for_lookup
, INSERT
);
7122 tu_group
= (struct type_unit_group
*) *slot
;
7123 gdb_assert (tu_group
!= NULL
);
7127 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7128 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7130 ++tu_stats
->nr_symtabs
;
7136 /* Partial symbol tables. */
7138 /* Create a psymtab named NAME and assign it to PER_CU.
7140 The caller must fill in the following details:
7141 dirname, textlow, texthigh. */
7143 static dwarf2_psymtab
*
7144 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7146 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7147 dwarf2_psymtab
*pst
;
7149 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7151 pst
->psymtabs_addrmap_supported
= true;
7153 /* This is the glue that links PST into GDB's symbol API. */
7154 pst
->per_cu_data
= per_cu
;
7155 per_cu
->v
.psymtab
= pst
;
7160 /* DIE reader function for process_psymtab_comp_unit. */
7163 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7164 const gdb_byte
*info_ptr
,
7165 struct die_info
*comp_unit_die
,
7166 enum language pretend_language
)
7168 struct dwarf2_cu
*cu
= reader
->cu
;
7169 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7170 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7171 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7173 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7174 dwarf2_psymtab
*pst
;
7175 enum pc_bounds_kind cu_bounds_kind
;
7176 const char *filename
;
7178 gdb_assert (! per_cu
->is_debug_types
);
7180 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7182 /* Allocate a new partial symbol table structure. */
7183 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7184 static const char artificial
[] = "<artificial>";
7185 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7186 if (filename
== NULL
)
7188 else if (strcmp (filename
, artificial
) == 0)
7190 debug_filename
.reset (concat (artificial
, "@",
7191 sect_offset_str (per_cu
->sect_off
),
7193 filename
= debug_filename
.get ();
7196 pst
= create_partial_symtab (per_cu
, filename
);
7198 /* This must be done before calling dwarf2_build_include_psymtabs. */
7199 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7201 baseaddr
= objfile
->text_section_offset ();
7203 dwarf2_find_base_address (comp_unit_die
, cu
);
7205 /* Possibly set the default values of LOWPC and HIGHPC from
7207 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7208 &best_highpc
, cu
, pst
);
7209 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7212 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7215 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7217 /* Store the contiguous range if it is not empty; it can be
7218 empty for CUs with no code. */
7219 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7223 /* Check if comp unit has_children.
7224 If so, read the rest of the partial symbols from this comp unit.
7225 If not, there's no more debug_info for this comp unit. */
7226 if (comp_unit_die
->has_children
)
7228 struct partial_die_info
*first_die
;
7229 CORE_ADDR lowpc
, highpc
;
7231 lowpc
= ((CORE_ADDR
) -1);
7232 highpc
= ((CORE_ADDR
) 0);
7234 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7236 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7237 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7239 /* If we didn't find a lowpc, set it to highpc to avoid
7240 complaints from `maint check'. */
7241 if (lowpc
== ((CORE_ADDR
) -1))
7244 /* If the compilation unit didn't have an explicit address range,
7245 then use the information extracted from its child dies. */
7246 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7249 best_highpc
= highpc
;
7252 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7253 best_lowpc
+ baseaddr
)
7255 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7256 best_highpc
+ baseaddr
)
7259 end_psymtab_common (objfile
, pst
);
7261 if (!cu
->per_cu
->imported_symtabs_empty ())
7264 int len
= cu
->per_cu
->imported_symtabs_size ();
7266 /* Fill in 'dependencies' here; we fill in 'users' in a
7268 pst
->number_of_dependencies
= len
;
7270 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7271 for (i
= 0; i
< len
; ++i
)
7273 pst
->dependencies
[i
]
7274 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7277 cu
->per_cu
->imported_symtabs_free ();
7280 /* Get the list of files included in the current compilation unit,
7281 and build a psymtab for each of them. */
7282 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7284 if (dwarf_read_debug
)
7285 fprintf_unfiltered (gdb_stdlog
,
7286 "Psymtab for %s unit @%s: %s - %s"
7287 ", %d global, %d static syms\n",
7288 per_cu
->is_debug_types
? "type" : "comp",
7289 sect_offset_str (per_cu
->sect_off
),
7290 paddress (gdbarch
, pst
->text_low (objfile
)),
7291 paddress (gdbarch
, pst
->text_high (objfile
)),
7292 pst
->n_global_syms
, pst
->n_static_syms
);
7295 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7296 Process compilation unit THIS_CU for a psymtab. */
7299 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7300 bool want_partial_unit
,
7301 enum language pretend_language
)
7303 /* If this compilation unit was already read in, free the
7304 cached copy in order to read it in again. This is
7305 necessary because we skipped some symbols when we first
7306 read in the compilation unit (see load_partial_dies).
7307 This problem could be avoided, but the benefit is unclear. */
7308 if (this_cu
->cu
!= NULL
)
7309 free_one_cached_comp_unit (this_cu
);
7311 cutu_reader
reader (this_cu
, NULL
, 0, false);
7313 switch (reader
.comp_unit_die
->tag
)
7315 case DW_TAG_compile_unit
:
7316 this_cu
->unit_type
= DW_UT_compile
;
7318 case DW_TAG_partial_unit
:
7319 this_cu
->unit_type
= DW_UT_partial
;
7329 else if (this_cu
->is_debug_types
)
7330 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7331 reader
.comp_unit_die
);
7332 else if (want_partial_unit
7333 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7334 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7335 reader
.comp_unit_die
,
7338 this_cu
->lang
= this_cu
->cu
->language
;
7340 /* Age out any secondary CUs. */
7341 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7344 /* Reader function for build_type_psymtabs. */
7347 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7348 const gdb_byte
*info_ptr
,
7349 struct die_info
*type_unit_die
)
7351 struct dwarf2_per_objfile
*dwarf2_per_objfile
7352 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7353 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7354 struct dwarf2_cu
*cu
= reader
->cu
;
7355 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7356 struct signatured_type
*sig_type
;
7357 struct type_unit_group
*tu_group
;
7358 struct attribute
*attr
;
7359 struct partial_die_info
*first_die
;
7360 CORE_ADDR lowpc
, highpc
;
7361 dwarf2_psymtab
*pst
;
7363 gdb_assert (per_cu
->is_debug_types
);
7364 sig_type
= (struct signatured_type
*) per_cu
;
7366 if (! type_unit_die
->has_children
)
7369 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7370 tu_group
= get_type_unit_group (cu
, attr
);
7372 if (tu_group
->tus
== nullptr)
7373 tu_group
->tus
= new std::vector
<signatured_type
*>;
7374 tu_group
->tus
->push_back (sig_type
);
7376 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7377 pst
= create_partial_symtab (per_cu
, "");
7378 pst
->anonymous
= true;
7380 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7382 lowpc
= (CORE_ADDR
) -1;
7383 highpc
= (CORE_ADDR
) 0;
7384 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7386 end_psymtab_common (objfile
, pst
);
7389 /* Struct used to sort TUs by their abbreviation table offset. */
7391 struct tu_abbrev_offset
7393 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7394 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7397 signatured_type
*sig_type
;
7398 sect_offset abbrev_offset
;
7401 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7404 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7405 const struct tu_abbrev_offset
&b
)
7407 return a
.abbrev_offset
< b
.abbrev_offset
;
7410 /* Efficiently read all the type units.
7411 This does the bulk of the work for build_type_psymtabs.
7413 The efficiency is because we sort TUs by the abbrev table they use and
7414 only read each abbrev table once. In one program there are 200K TUs
7415 sharing 8K abbrev tables.
7417 The main purpose of this function is to support building the
7418 dwarf2_per_objfile->type_unit_groups table.
7419 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7420 can collapse the search space by grouping them by stmt_list.
7421 The savings can be significant, in the same program from above the 200K TUs
7422 share 8K stmt_list tables.
7424 FUNC is expected to call get_type_unit_group, which will create the
7425 struct type_unit_group if necessary and add it to
7426 dwarf2_per_objfile->type_unit_groups. */
7429 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7431 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7432 abbrev_table_up abbrev_table
;
7433 sect_offset abbrev_offset
;
7435 /* It's up to the caller to not call us multiple times. */
7436 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7438 if (dwarf2_per_objfile
->all_type_units
.empty ())
7441 /* TUs typically share abbrev tables, and there can be way more TUs than
7442 abbrev tables. Sort by abbrev table to reduce the number of times we
7443 read each abbrev table in.
7444 Alternatives are to punt or to maintain a cache of abbrev tables.
7445 This is simpler and efficient enough for now.
7447 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7448 symtab to use). Typically TUs with the same abbrev offset have the same
7449 stmt_list value too so in practice this should work well.
7451 The basic algorithm here is:
7453 sort TUs by abbrev table
7454 for each TU with same abbrev table:
7455 read abbrev table if first user
7456 read TU top level DIE
7457 [IWBN if DWO skeletons had DW_AT_stmt_list]
7460 if (dwarf_read_debug
)
7461 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7463 /* Sort in a separate table to maintain the order of all_type_units
7464 for .gdb_index: TU indices directly index all_type_units. */
7465 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7466 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7468 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7469 sorted_by_abbrev
.emplace_back
7470 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7471 sig_type
->per_cu
.section
,
7472 sig_type
->per_cu
.sect_off
));
7474 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7475 sort_tu_by_abbrev_offset
);
7477 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7479 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7481 /* Switch to the next abbrev table if necessary. */
7482 if (abbrev_table
== NULL
7483 || tu
.abbrev_offset
!= abbrev_offset
)
7485 abbrev_offset
= tu
.abbrev_offset
;
7487 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7488 &dwarf2_per_objfile
->abbrev
,
7490 ++tu_stats
->nr_uniq_abbrev_tables
;
7493 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7495 if (!reader
.dummy_p
)
7496 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7497 reader
.comp_unit_die
);
7501 /* Print collected type unit statistics. */
7504 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7506 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7508 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7509 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7510 dwarf2_per_objfile
->all_type_units
.size ());
7511 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7512 tu_stats
->nr_uniq_abbrev_tables
);
7513 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7514 tu_stats
->nr_symtabs
);
7515 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7516 tu_stats
->nr_symtab_sharers
);
7517 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7518 tu_stats
->nr_stmt_less_type_units
);
7519 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7520 tu_stats
->nr_all_type_units_reallocs
);
7523 /* Traversal function for build_type_psymtabs. */
7526 build_type_psymtab_dependencies (void **slot
, void *info
)
7528 struct dwarf2_per_objfile
*dwarf2_per_objfile
7529 = (struct dwarf2_per_objfile
*) info
;
7530 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7531 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7532 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7533 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7534 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7537 gdb_assert (len
> 0);
7538 gdb_assert (per_cu
->type_unit_group_p ());
7540 pst
->number_of_dependencies
= len
;
7541 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7542 for (i
= 0; i
< len
; ++i
)
7544 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7545 gdb_assert (iter
->per_cu
.is_debug_types
);
7546 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7547 iter
->type_unit_group
= tu_group
;
7550 delete tu_group
->tus
;
7551 tu_group
->tus
= nullptr;
7556 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7557 Build partial symbol tables for the .debug_types comp-units. */
7560 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7562 if (! create_all_type_units (dwarf2_per_objfile
))
7565 build_type_psymtabs_1 (dwarf2_per_objfile
);
7568 /* Traversal function for process_skeletonless_type_unit.
7569 Read a TU in a DWO file and build partial symbols for it. */
7572 process_skeletonless_type_unit (void **slot
, void *info
)
7574 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7575 struct dwarf2_per_objfile
*dwarf2_per_objfile
7576 = (struct dwarf2_per_objfile
*) info
;
7577 struct signatured_type find_entry
, *entry
;
7579 /* If this TU doesn't exist in the global table, add it and read it in. */
7581 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7582 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7584 find_entry
.signature
= dwo_unit
->signature
;
7585 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7586 &find_entry
, INSERT
);
7587 /* If we've already seen this type there's nothing to do. What's happening
7588 is we're doing our own version of comdat-folding here. */
7592 /* This does the job that create_all_type_units would have done for
7594 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7595 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7598 /* This does the job that build_type_psymtabs_1 would have done. */
7599 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7600 if (!reader
.dummy_p
)
7601 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7602 reader
.comp_unit_die
);
7607 /* Traversal function for process_skeletonless_type_units. */
7610 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7612 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7614 if (dwo_file
->tus
!= NULL
)
7615 htab_traverse_noresize (dwo_file
->tus
.get (),
7616 process_skeletonless_type_unit
, info
);
7621 /* Scan all TUs of DWO files, verifying we've processed them.
7622 This is needed in case a TU was emitted without its skeleton.
7623 Note: This can't be done until we know what all the DWO files are. */
7626 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7628 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7629 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7630 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7632 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7633 process_dwo_file_for_skeletonless_type_units
,
7634 dwarf2_per_objfile
);
7638 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7641 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7643 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7645 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7650 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7652 /* Set the 'user' field only if it is not already set. */
7653 if (pst
->dependencies
[j
]->user
== NULL
)
7654 pst
->dependencies
[j
]->user
= pst
;
7659 /* Build the partial symbol table by doing a quick pass through the
7660 .debug_info and .debug_abbrev sections. */
7663 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7665 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7667 if (dwarf_read_debug
)
7669 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7670 objfile_name (objfile
));
7673 scoped_restore restore_reading_psyms
7674 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7677 dwarf2_per_objfile
->info
.read (objfile
);
7679 /* Any cached compilation units will be linked by the per-objfile
7680 read_in_chain. Make sure to free them when we're done. */
7681 free_cached_comp_units
freer (dwarf2_per_objfile
);
7683 build_type_psymtabs (dwarf2_per_objfile
);
7685 create_all_comp_units (dwarf2_per_objfile
);
7687 /* Create a temporary address map on a temporary obstack. We later
7688 copy this to the final obstack. */
7689 auto_obstack temp_obstack
;
7691 scoped_restore save_psymtabs_addrmap
7692 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7693 addrmap_create_mutable (&temp_obstack
));
7695 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7696 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7698 /* This has to wait until we read the CUs, we need the list of DWOs. */
7699 process_skeletonless_type_units (dwarf2_per_objfile
);
7701 /* Now that all TUs have been processed we can fill in the dependencies. */
7702 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7704 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7705 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7708 if (dwarf_read_debug
)
7709 print_tu_stats (dwarf2_per_objfile
);
7711 set_partial_user (dwarf2_per_objfile
);
7713 objfile
->partial_symtabs
->psymtabs_addrmap
7714 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7715 objfile
->partial_symtabs
->obstack ());
7716 /* At this point we want to keep the address map. */
7717 save_psymtabs_addrmap
.release ();
7719 if (dwarf_read_debug
)
7720 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7721 objfile_name (objfile
));
7724 /* Load the partial DIEs for a secondary CU into memory.
7725 This is also used when rereading a primary CU with load_all_dies. */
7728 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7730 cutu_reader
reader (this_cu
, NULL
, 1, false);
7732 if (!reader
.dummy_p
)
7734 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7737 /* Check if comp unit has_children.
7738 If so, read the rest of the partial symbols from this comp unit.
7739 If not, there's no more debug_info for this comp unit. */
7740 if (reader
.comp_unit_die
->has_children
)
7741 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7748 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7749 struct dwarf2_section_info
*section
,
7750 struct dwarf2_section_info
*abbrev_section
,
7751 unsigned int is_dwz
)
7753 const gdb_byte
*info_ptr
;
7754 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7756 if (dwarf_read_debug
)
7757 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7758 section
->get_name (),
7759 section
->get_file_name ());
7761 section
->read (objfile
);
7763 info_ptr
= section
->buffer
;
7765 while (info_ptr
< section
->buffer
+ section
->size
)
7767 struct dwarf2_per_cu_data
*this_cu
;
7769 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7771 comp_unit_head cu_header
;
7772 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7773 abbrev_section
, info_ptr
,
7774 rcuh_kind::COMPILE
);
7776 /* Save the compilation unit for later lookup. */
7777 if (cu_header
.unit_type
!= DW_UT_type
)
7779 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7780 struct dwarf2_per_cu_data
);
7781 memset (this_cu
, 0, sizeof (*this_cu
));
7785 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7786 struct signatured_type
);
7787 memset (sig_type
, 0, sizeof (*sig_type
));
7788 sig_type
->signature
= cu_header
.signature
;
7789 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7790 this_cu
= &sig_type
->per_cu
;
7792 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7793 this_cu
->sect_off
= sect_off
;
7794 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7795 this_cu
->is_dwz
= is_dwz
;
7796 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7797 this_cu
->section
= section
;
7799 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7801 info_ptr
= info_ptr
+ this_cu
->length
;
7805 /* Create a list of all compilation units in OBJFILE.
7806 This is only done for -readnow and building partial symtabs. */
7809 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7811 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7812 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7813 &dwarf2_per_objfile
->abbrev
, 0);
7815 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7817 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7821 /* Process all loaded DIEs for compilation unit CU, starting at
7822 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7823 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7824 DW_AT_ranges). See the comments of add_partial_subprogram on how
7825 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7828 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7829 CORE_ADDR
*highpc
, int set_addrmap
,
7830 struct dwarf2_cu
*cu
)
7832 struct partial_die_info
*pdi
;
7834 /* Now, march along the PDI's, descending into ones which have
7835 interesting children but skipping the children of the other ones,
7836 until we reach the end of the compilation unit. */
7844 /* Anonymous namespaces or modules have no name but have interesting
7845 children, so we need to look at them. Ditto for anonymous
7848 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7849 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7850 || pdi
->tag
== DW_TAG_imported_unit
7851 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7855 case DW_TAG_subprogram
:
7856 case DW_TAG_inlined_subroutine
:
7857 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7859 case DW_TAG_constant
:
7860 case DW_TAG_variable
:
7861 case DW_TAG_typedef
:
7862 case DW_TAG_union_type
:
7863 if (!pdi
->is_declaration
)
7865 add_partial_symbol (pdi
, cu
);
7868 case DW_TAG_class_type
:
7869 case DW_TAG_interface_type
:
7870 case DW_TAG_structure_type
:
7871 if (!pdi
->is_declaration
)
7873 add_partial_symbol (pdi
, cu
);
7875 if ((cu
->language
== language_rust
7876 || cu
->language
== language_cplus
) && pdi
->has_children
)
7877 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7880 case DW_TAG_enumeration_type
:
7881 if (!pdi
->is_declaration
)
7882 add_partial_enumeration (pdi
, cu
);
7884 case DW_TAG_base_type
:
7885 case DW_TAG_subrange_type
:
7886 /* File scope base type definitions are added to the partial
7888 add_partial_symbol (pdi
, cu
);
7890 case DW_TAG_namespace
:
7891 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7894 if (!pdi
->is_declaration
)
7895 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7897 case DW_TAG_imported_unit
:
7899 struct dwarf2_per_cu_data
*per_cu
;
7901 /* For now we don't handle imported units in type units. */
7902 if (cu
->per_cu
->is_debug_types
)
7904 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7905 " supported in type units [in module %s]"),
7906 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7909 per_cu
= dwarf2_find_containing_comp_unit
7910 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7911 cu
->per_cu
->dwarf2_per_objfile
);
7913 /* Go read the partial unit, if needed. */
7914 if (per_cu
->v
.psymtab
== NULL
)
7915 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7917 cu
->per_cu
->imported_symtabs_push (per_cu
);
7920 case DW_TAG_imported_declaration
:
7921 add_partial_symbol (pdi
, cu
);
7928 /* If the die has a sibling, skip to the sibling. */
7930 pdi
= pdi
->die_sibling
;
7934 /* Functions used to compute the fully scoped name of a partial DIE.
7936 Normally, this is simple. For C++, the parent DIE's fully scoped
7937 name is concatenated with "::" and the partial DIE's name.
7938 Enumerators are an exception; they use the scope of their parent
7939 enumeration type, i.e. the name of the enumeration type is not
7940 prepended to the enumerator.
7942 There are two complexities. One is DW_AT_specification; in this
7943 case "parent" means the parent of the target of the specification,
7944 instead of the direct parent of the DIE. The other is compilers
7945 which do not emit DW_TAG_namespace; in this case we try to guess
7946 the fully qualified name of structure types from their members'
7947 linkage names. This must be done using the DIE's children rather
7948 than the children of any DW_AT_specification target. We only need
7949 to do this for structures at the top level, i.e. if the target of
7950 any DW_AT_specification (if any; otherwise the DIE itself) does not
7953 /* Compute the scope prefix associated with PDI's parent, in
7954 compilation unit CU. The result will be allocated on CU's
7955 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7956 field. NULL is returned if no prefix is necessary. */
7958 partial_die_parent_scope (struct partial_die_info
*pdi
,
7959 struct dwarf2_cu
*cu
)
7961 const char *grandparent_scope
;
7962 struct partial_die_info
*parent
, *real_pdi
;
7964 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7965 then this means the parent of the specification DIE. */
7968 while (real_pdi
->has_specification
)
7970 auto res
= find_partial_die (real_pdi
->spec_offset
,
7971 real_pdi
->spec_is_dwz
, cu
);
7976 parent
= real_pdi
->die_parent
;
7980 if (parent
->scope_set
)
7981 return parent
->scope
;
7985 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7987 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7988 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7989 Work around this problem here. */
7990 if (cu
->language
== language_cplus
7991 && parent
->tag
== DW_TAG_namespace
7992 && strcmp (parent
->name
, "::") == 0
7993 && grandparent_scope
== NULL
)
7995 parent
->scope
= NULL
;
7996 parent
->scope_set
= 1;
8000 /* Nested subroutines in Fortran get a prefix. */
8001 if (pdi
->tag
== DW_TAG_enumerator
)
8002 /* Enumerators should not get the name of the enumeration as a prefix. */
8003 parent
->scope
= grandparent_scope
;
8004 else if (parent
->tag
== DW_TAG_namespace
8005 || parent
->tag
== DW_TAG_module
8006 || parent
->tag
== DW_TAG_structure_type
8007 || parent
->tag
== DW_TAG_class_type
8008 || parent
->tag
== DW_TAG_interface_type
8009 || parent
->tag
== DW_TAG_union_type
8010 || parent
->tag
== DW_TAG_enumeration_type
8011 || (cu
->language
== language_fortran
8012 && parent
->tag
== DW_TAG_subprogram
8013 && pdi
->tag
== DW_TAG_subprogram
))
8015 if (grandparent_scope
== NULL
)
8016 parent
->scope
= parent
->name
;
8018 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8020 parent
->name
, 0, cu
);
8024 /* FIXME drow/2004-04-01: What should we be doing with
8025 function-local names? For partial symbols, we should probably be
8027 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8028 dwarf_tag_name (parent
->tag
),
8029 sect_offset_str (pdi
->sect_off
));
8030 parent
->scope
= grandparent_scope
;
8033 parent
->scope_set
= 1;
8034 return parent
->scope
;
8037 /* Return the fully scoped name associated with PDI, from compilation unit
8038 CU. The result will be allocated with malloc. */
8040 static gdb::unique_xmalloc_ptr
<char>
8041 partial_die_full_name (struct partial_die_info
*pdi
,
8042 struct dwarf2_cu
*cu
)
8044 const char *parent_scope
;
8046 /* If this is a template instantiation, we can not work out the
8047 template arguments from partial DIEs. So, unfortunately, we have
8048 to go through the full DIEs. At least any work we do building
8049 types here will be reused if full symbols are loaded later. */
8050 if (pdi
->has_template_arguments
)
8054 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8056 struct die_info
*die
;
8057 struct attribute attr
;
8058 struct dwarf2_cu
*ref_cu
= cu
;
8060 /* DW_FORM_ref_addr is using section offset. */
8061 attr
.name
= (enum dwarf_attribute
) 0;
8062 attr
.form
= DW_FORM_ref_addr
;
8063 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8064 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8066 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8070 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8071 if (parent_scope
== NULL
)
8074 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8079 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8081 struct dwarf2_per_objfile
*dwarf2_per_objfile
8082 = cu
->per_cu
->dwarf2_per_objfile
;
8083 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8084 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8086 const char *actual_name
= NULL
;
8089 baseaddr
= objfile
->text_section_offset ();
8091 gdb::unique_xmalloc_ptr
<char> built_actual_name
8092 = partial_die_full_name (pdi
, cu
);
8093 if (built_actual_name
!= NULL
)
8094 actual_name
= built_actual_name
.get ();
8096 if (actual_name
== NULL
)
8097 actual_name
= pdi
->name
;
8101 case DW_TAG_inlined_subroutine
:
8102 case DW_TAG_subprogram
:
8103 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8105 if (pdi
->is_external
8106 || cu
->language
== language_ada
8107 || (cu
->language
== language_fortran
8108 && pdi
->die_parent
!= NULL
8109 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8111 /* Normally, only "external" DIEs are part of the global scope.
8112 But in Ada and Fortran, we want to be able to access nested
8113 procedures globally. So all Ada and Fortran subprograms are
8114 stored in the global scope. */
8115 add_psymbol_to_list (actual_name
,
8116 built_actual_name
!= NULL
,
8117 VAR_DOMAIN
, LOC_BLOCK
,
8118 SECT_OFF_TEXT (objfile
),
8119 psymbol_placement::GLOBAL
,
8121 cu
->language
, objfile
);
8125 add_psymbol_to_list (actual_name
,
8126 built_actual_name
!= NULL
,
8127 VAR_DOMAIN
, LOC_BLOCK
,
8128 SECT_OFF_TEXT (objfile
),
8129 psymbol_placement::STATIC
,
8130 addr
, cu
->language
, objfile
);
8133 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8134 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8136 case DW_TAG_constant
:
8137 add_psymbol_to_list (actual_name
,
8138 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8139 -1, (pdi
->is_external
8140 ? psymbol_placement::GLOBAL
8141 : psymbol_placement::STATIC
),
8142 0, cu
->language
, objfile
);
8144 case DW_TAG_variable
:
8146 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8150 && !dwarf2_per_objfile
->has_section_at_zero
)
8152 /* A global or static variable may also have been stripped
8153 out by the linker if unused, in which case its address
8154 will be nullified; do not add such variables into partial
8155 symbol table then. */
8157 else if (pdi
->is_external
)
8160 Don't enter into the minimal symbol tables as there is
8161 a minimal symbol table entry from the ELF symbols already.
8162 Enter into partial symbol table if it has a location
8163 descriptor or a type.
8164 If the location descriptor is missing, new_symbol will create
8165 a LOC_UNRESOLVED symbol, the address of the variable will then
8166 be determined from the minimal symbol table whenever the variable
8168 The address for the partial symbol table entry is not
8169 used by GDB, but it comes in handy for debugging partial symbol
8172 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8173 add_psymbol_to_list (actual_name
,
8174 built_actual_name
!= NULL
,
8175 VAR_DOMAIN
, LOC_STATIC
,
8176 SECT_OFF_TEXT (objfile
),
8177 psymbol_placement::GLOBAL
,
8178 addr
, cu
->language
, objfile
);
8182 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8184 /* Static Variable. Skip symbols whose value we cannot know (those
8185 without location descriptors or constant values). */
8186 if (!has_loc
&& !pdi
->has_const_value
)
8189 add_psymbol_to_list (actual_name
,
8190 built_actual_name
!= NULL
,
8191 VAR_DOMAIN
, LOC_STATIC
,
8192 SECT_OFF_TEXT (objfile
),
8193 psymbol_placement::STATIC
,
8195 cu
->language
, objfile
);
8198 case DW_TAG_typedef
:
8199 case DW_TAG_base_type
:
8200 case DW_TAG_subrange_type
:
8201 add_psymbol_to_list (actual_name
,
8202 built_actual_name
!= NULL
,
8203 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8204 psymbol_placement::STATIC
,
8205 0, cu
->language
, objfile
);
8207 case DW_TAG_imported_declaration
:
8208 case DW_TAG_namespace
:
8209 add_psymbol_to_list (actual_name
,
8210 built_actual_name
!= NULL
,
8211 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8212 psymbol_placement::GLOBAL
,
8213 0, cu
->language
, objfile
);
8216 /* With Fortran 77 there might be a "BLOCK DATA" module
8217 available without any name. If so, we skip the module as it
8218 doesn't bring any value. */
8219 if (actual_name
!= nullptr)
8220 add_psymbol_to_list (actual_name
,
8221 built_actual_name
!= NULL
,
8222 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8223 psymbol_placement::GLOBAL
,
8224 0, cu
->language
, objfile
);
8226 case DW_TAG_class_type
:
8227 case DW_TAG_interface_type
:
8228 case DW_TAG_structure_type
:
8229 case DW_TAG_union_type
:
8230 case DW_TAG_enumeration_type
:
8231 /* Skip external references. The DWARF standard says in the section
8232 about "Structure, Union, and Class Type Entries": "An incomplete
8233 structure, union or class type is represented by a structure,
8234 union or class entry that does not have a byte size attribute
8235 and that has a DW_AT_declaration attribute." */
8236 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8239 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8240 static vs. global. */
8241 add_psymbol_to_list (actual_name
,
8242 built_actual_name
!= NULL
,
8243 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8244 cu
->language
== language_cplus
8245 ? psymbol_placement::GLOBAL
8246 : psymbol_placement::STATIC
,
8247 0, cu
->language
, objfile
);
8250 case DW_TAG_enumerator
:
8251 add_psymbol_to_list (actual_name
,
8252 built_actual_name
!= NULL
,
8253 VAR_DOMAIN
, LOC_CONST
, -1,
8254 cu
->language
== language_cplus
8255 ? psymbol_placement::GLOBAL
8256 : psymbol_placement::STATIC
,
8257 0, cu
->language
, objfile
);
8264 /* Read a partial die corresponding to a namespace; also, add a symbol
8265 corresponding to that namespace to the symbol table. NAMESPACE is
8266 the name of the enclosing namespace. */
8269 add_partial_namespace (struct partial_die_info
*pdi
,
8270 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8271 int set_addrmap
, struct dwarf2_cu
*cu
)
8273 /* Add a symbol for the namespace. */
8275 add_partial_symbol (pdi
, cu
);
8277 /* Now scan partial symbols in that namespace. */
8279 if (pdi
->has_children
)
8280 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8283 /* Read a partial die corresponding to a Fortran module. */
8286 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8287 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8289 /* Add a symbol for the namespace. */
8291 add_partial_symbol (pdi
, cu
);
8293 /* Now scan partial symbols in that module. */
8295 if (pdi
->has_children
)
8296 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8299 /* Read a partial die corresponding to a subprogram or an inlined
8300 subprogram and create a partial symbol for that subprogram.
8301 When the CU language allows it, this routine also defines a partial
8302 symbol for each nested subprogram that this subprogram contains.
8303 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8304 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8306 PDI may also be a lexical block, in which case we simply search
8307 recursively for subprograms defined inside that lexical block.
8308 Again, this is only performed when the CU language allows this
8309 type of definitions. */
8312 add_partial_subprogram (struct partial_die_info
*pdi
,
8313 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8314 int set_addrmap
, struct dwarf2_cu
*cu
)
8316 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8318 if (pdi
->has_pc_info
)
8320 if (pdi
->lowpc
< *lowpc
)
8321 *lowpc
= pdi
->lowpc
;
8322 if (pdi
->highpc
> *highpc
)
8323 *highpc
= pdi
->highpc
;
8326 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8327 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8329 CORE_ADDR this_highpc
;
8330 CORE_ADDR this_lowpc
;
8332 baseaddr
= objfile
->text_section_offset ();
8334 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8335 pdi
->lowpc
+ baseaddr
)
8338 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8339 pdi
->highpc
+ baseaddr
)
8341 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8342 this_lowpc
, this_highpc
- 1,
8343 cu
->per_cu
->v
.psymtab
);
8347 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8349 if (!pdi
->is_declaration
)
8350 /* Ignore subprogram DIEs that do not have a name, they are
8351 illegal. Do not emit a complaint at this point, we will
8352 do so when we convert this psymtab into a symtab. */
8354 add_partial_symbol (pdi
, cu
);
8358 if (! pdi
->has_children
)
8361 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8363 pdi
= pdi
->die_child
;
8367 if (pdi
->tag
== DW_TAG_subprogram
8368 || pdi
->tag
== DW_TAG_inlined_subroutine
8369 || pdi
->tag
== DW_TAG_lexical_block
)
8370 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8371 pdi
= pdi
->die_sibling
;
8376 /* Read a partial die corresponding to an enumeration type. */
8379 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8380 struct dwarf2_cu
*cu
)
8382 struct partial_die_info
*pdi
;
8384 if (enum_pdi
->name
!= NULL
)
8385 add_partial_symbol (enum_pdi
, cu
);
8387 pdi
= enum_pdi
->die_child
;
8390 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8391 complaint (_("malformed enumerator DIE ignored"));
8393 add_partial_symbol (pdi
, cu
);
8394 pdi
= pdi
->die_sibling
;
8398 /* Return the initial uleb128 in the die at INFO_PTR. */
8401 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8403 unsigned int bytes_read
;
8405 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8408 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8409 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8411 Return the corresponding abbrev, or NULL if the number is zero (indicating
8412 an empty DIE). In either case *BYTES_READ will be set to the length of
8413 the initial number. */
8415 static struct abbrev_info
*
8416 peek_die_abbrev (const die_reader_specs
&reader
,
8417 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8419 dwarf2_cu
*cu
= reader
.cu
;
8420 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8421 unsigned int abbrev_number
8422 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8424 if (abbrev_number
== 0)
8427 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8430 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8431 " at offset %s [in module %s]"),
8432 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8433 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8439 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8440 Returns a pointer to the end of a series of DIEs, terminated by an empty
8441 DIE. Any children of the skipped DIEs will also be skipped. */
8443 static const gdb_byte
*
8444 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8448 unsigned int bytes_read
;
8449 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8452 return info_ptr
+ bytes_read
;
8454 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8458 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8459 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8460 abbrev corresponding to that skipped uleb128 should be passed in
8461 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8464 static const gdb_byte
*
8465 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8466 struct abbrev_info
*abbrev
)
8468 unsigned int bytes_read
;
8469 struct attribute attr
;
8470 bfd
*abfd
= reader
->abfd
;
8471 struct dwarf2_cu
*cu
= reader
->cu
;
8472 const gdb_byte
*buffer
= reader
->buffer
;
8473 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8474 unsigned int form
, i
;
8476 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8478 /* The only abbrev we care about is DW_AT_sibling. */
8479 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8482 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8484 if (attr
.form
== DW_FORM_ref_addr
)
8485 complaint (_("ignoring absolute DW_AT_sibling"));
8488 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8489 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8491 if (sibling_ptr
< info_ptr
)
8492 complaint (_("DW_AT_sibling points backwards"));
8493 else if (sibling_ptr
> reader
->buffer_end
)
8494 reader
->die_section
->overflow_complaint ();
8500 /* If it isn't DW_AT_sibling, skip this attribute. */
8501 form
= abbrev
->attrs
[i
].form
;
8505 case DW_FORM_ref_addr
:
8506 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8507 and later it is offset sized. */
8508 if (cu
->header
.version
== 2)
8509 info_ptr
+= cu
->header
.addr_size
;
8511 info_ptr
+= cu
->header
.offset_size
;
8513 case DW_FORM_GNU_ref_alt
:
8514 info_ptr
+= cu
->header
.offset_size
;
8517 info_ptr
+= cu
->header
.addr_size
;
8525 case DW_FORM_flag_present
:
8526 case DW_FORM_implicit_const
:
8543 case DW_FORM_ref_sig8
:
8546 case DW_FORM_data16
:
8549 case DW_FORM_string
:
8550 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8551 info_ptr
+= bytes_read
;
8553 case DW_FORM_sec_offset
:
8555 case DW_FORM_GNU_strp_alt
:
8556 info_ptr
+= cu
->header
.offset_size
;
8558 case DW_FORM_exprloc
:
8560 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8561 info_ptr
+= bytes_read
;
8563 case DW_FORM_block1
:
8564 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8566 case DW_FORM_block2
:
8567 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8569 case DW_FORM_block4
:
8570 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8576 case DW_FORM_ref_udata
:
8577 case DW_FORM_GNU_addr_index
:
8578 case DW_FORM_GNU_str_index
:
8579 case DW_FORM_rnglistx
:
8580 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8582 case DW_FORM_indirect
:
8583 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8584 info_ptr
+= bytes_read
;
8585 /* We need to continue parsing from here, so just go back to
8587 goto skip_attribute
;
8590 error (_("Dwarf Error: Cannot handle %s "
8591 "in DWARF reader [in module %s]"),
8592 dwarf_form_name (form
),
8593 bfd_get_filename (abfd
));
8597 if (abbrev
->has_children
)
8598 return skip_children (reader
, info_ptr
);
8603 /* Locate ORIG_PDI's sibling.
8604 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8606 static const gdb_byte
*
8607 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8608 struct partial_die_info
*orig_pdi
,
8609 const gdb_byte
*info_ptr
)
8611 /* Do we know the sibling already? */
8613 if (orig_pdi
->sibling
)
8614 return orig_pdi
->sibling
;
8616 /* Are there any children to deal with? */
8618 if (!orig_pdi
->has_children
)
8621 /* Skip the children the long way. */
8623 return skip_children (reader
, info_ptr
);
8626 /* Expand this partial symbol table into a full symbol table. SELF is
8630 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8632 struct dwarf2_per_objfile
*dwarf2_per_objfile
8633 = get_dwarf2_per_objfile (objfile
);
8635 gdb_assert (!readin
);
8636 /* If this psymtab is constructed from a debug-only objfile, the
8637 has_section_at_zero flag will not necessarily be correct. We
8638 can get the correct value for this flag by looking at the data
8639 associated with the (presumably stripped) associated objfile. */
8640 if (objfile
->separate_debug_objfile_backlink
)
8642 struct dwarf2_per_objfile
*dpo_backlink
8643 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8645 dwarf2_per_objfile
->has_section_at_zero
8646 = dpo_backlink
->has_section_at_zero
;
8649 expand_psymtab (objfile
);
8651 process_cu_includes (dwarf2_per_objfile
);
8654 /* Reading in full CUs. */
8656 /* Add PER_CU to the queue. */
8659 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8660 enum language pretend_language
)
8663 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8666 /* If PER_CU is not yet queued, add it to the queue.
8667 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8669 The result is non-zero if PER_CU was queued, otherwise the result is zero
8670 meaning either PER_CU is already queued or it is already loaded.
8672 N.B. There is an invariant here that if a CU is queued then it is loaded.
8673 The caller is required to load PER_CU if we return non-zero. */
8676 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8677 struct dwarf2_per_cu_data
*per_cu
,
8678 enum language pretend_language
)
8680 /* We may arrive here during partial symbol reading, if we need full
8681 DIEs to process an unusual case (e.g. template arguments). Do
8682 not queue PER_CU, just tell our caller to load its DIEs. */
8683 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8685 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8690 /* Mark the dependence relation so that we don't flush PER_CU
8692 if (dependent_cu
!= NULL
)
8693 dwarf2_add_dependence (dependent_cu
, per_cu
);
8695 /* If it's already on the queue, we have nothing to do. */
8699 /* If the compilation unit is already loaded, just mark it as
8701 if (per_cu
->cu
!= NULL
)
8703 per_cu
->cu
->last_used
= 0;
8707 /* Add it to the queue. */
8708 queue_comp_unit (per_cu
, pretend_language
);
8713 /* Process the queue. */
8716 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8718 if (dwarf_read_debug
)
8720 fprintf_unfiltered (gdb_stdlog
,
8721 "Expanding one or more symtabs of objfile %s ...\n",
8722 objfile_name (dwarf2_per_objfile
->objfile
));
8725 /* The queue starts out with one item, but following a DIE reference
8726 may load a new CU, adding it to the end of the queue. */
8727 while (!dwarf2_per_objfile
->queue
.empty ())
8729 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8731 if ((dwarf2_per_objfile
->using_index
8732 ? !item
.per_cu
->v
.quick
->compunit_symtab
8733 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8734 /* Skip dummy CUs. */
8735 && item
.per_cu
->cu
!= NULL
)
8737 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8738 unsigned int debug_print_threshold
;
8741 if (per_cu
->is_debug_types
)
8743 struct signatured_type
*sig_type
=
8744 (struct signatured_type
*) per_cu
;
8746 sprintf (buf
, "TU %s at offset %s",
8747 hex_string (sig_type
->signature
),
8748 sect_offset_str (per_cu
->sect_off
));
8749 /* There can be 100s of TUs.
8750 Only print them in verbose mode. */
8751 debug_print_threshold
= 2;
8755 sprintf (buf
, "CU at offset %s",
8756 sect_offset_str (per_cu
->sect_off
));
8757 debug_print_threshold
= 1;
8760 if (dwarf_read_debug
>= debug_print_threshold
)
8761 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8763 if (per_cu
->is_debug_types
)
8764 process_full_type_unit (per_cu
, item
.pretend_language
);
8766 process_full_comp_unit (per_cu
, item
.pretend_language
);
8768 if (dwarf_read_debug
>= debug_print_threshold
)
8769 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8772 item
.per_cu
->queued
= 0;
8773 dwarf2_per_objfile
->queue
.pop ();
8776 if (dwarf_read_debug
)
8778 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8779 objfile_name (dwarf2_per_objfile
->objfile
));
8783 /* Read in full symbols for PST, and anything it depends on. */
8786 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8791 read_dependencies (objfile
);
8793 dw2_do_instantiate_symtab (per_cu_data
, false);
8794 gdb_assert (get_compunit_symtab () != nullptr);
8797 /* Trivial hash function for die_info: the hash value of a DIE
8798 is its offset in .debug_info for this objfile. */
8801 die_hash (const void *item
)
8803 const struct die_info
*die
= (const struct die_info
*) item
;
8805 return to_underlying (die
->sect_off
);
8808 /* Trivial comparison function for die_info structures: two DIEs
8809 are equal if they have the same offset. */
8812 die_eq (const void *item_lhs
, const void *item_rhs
)
8814 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8815 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8817 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8820 /* Load the DIEs associated with PER_CU into memory. */
8823 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8825 enum language pretend_language
)
8827 gdb_assert (! this_cu
->is_debug_types
);
8829 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8833 struct dwarf2_cu
*cu
= reader
.cu
;
8834 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8836 gdb_assert (cu
->die_hash
== NULL
);
8838 htab_create_alloc_ex (cu
->header
.length
/ 12,
8842 &cu
->comp_unit_obstack
,
8843 hashtab_obstack_allocate
,
8844 dummy_obstack_deallocate
);
8846 if (reader
.comp_unit_die
->has_children
)
8847 reader
.comp_unit_die
->child
8848 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8849 &info_ptr
, reader
.comp_unit_die
);
8850 cu
->dies
= reader
.comp_unit_die
;
8851 /* comp_unit_die is not stored in die_hash, no need. */
8853 /* We try not to read any attributes in this function, because not
8854 all CUs needed for references have been loaded yet, and symbol
8855 table processing isn't initialized. But we have to set the CU language,
8856 or we won't be able to build types correctly.
8857 Similarly, if we do not read the producer, we can not apply
8858 producer-specific interpretation. */
8859 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8864 /* Add a DIE to the delayed physname list. */
8867 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8868 const char *name
, struct die_info
*die
,
8869 struct dwarf2_cu
*cu
)
8871 struct delayed_method_info mi
;
8873 mi
.fnfield_index
= fnfield_index
;
8877 cu
->method_list
.push_back (mi
);
8880 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8881 "const" / "volatile". If so, decrements LEN by the length of the
8882 modifier and return true. Otherwise return false. */
8886 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8888 size_t mod_len
= sizeof (mod
) - 1;
8889 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8897 /* Compute the physnames of any methods on the CU's method list.
8899 The computation of method physnames is delayed in order to avoid the
8900 (bad) condition that one of the method's formal parameters is of an as yet
8904 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8906 /* Only C++ delays computing physnames. */
8907 if (cu
->method_list
.empty ())
8909 gdb_assert (cu
->language
== language_cplus
);
8911 for (const delayed_method_info
&mi
: cu
->method_list
)
8913 const char *physname
;
8914 struct fn_fieldlist
*fn_flp
8915 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8916 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8917 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8918 = physname
? physname
: "";
8920 /* Since there's no tag to indicate whether a method is a
8921 const/volatile overload, extract that information out of the
8923 if (physname
!= NULL
)
8925 size_t len
= strlen (physname
);
8929 if (physname
[len
] == ')') /* shortcut */
8931 else if (check_modifier (physname
, len
, " const"))
8932 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8933 else if (check_modifier (physname
, len
, " volatile"))
8934 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8941 /* The list is no longer needed. */
8942 cu
->method_list
.clear ();
8945 /* Go objects should be embedded in a DW_TAG_module DIE,
8946 and it's not clear if/how imported objects will appear.
8947 To keep Go support simple until that's worked out,
8948 go back through what we've read and create something usable.
8949 We could do this while processing each DIE, and feels kinda cleaner,
8950 but that way is more invasive.
8951 This is to, for example, allow the user to type "p var" or "b main"
8952 without having to specify the package name, and allow lookups
8953 of module.object to work in contexts that use the expression
8957 fixup_go_packaging (struct dwarf2_cu
*cu
)
8959 gdb::unique_xmalloc_ptr
<char> package_name
;
8960 struct pending
*list
;
8963 for (list
= *cu
->get_builder ()->get_global_symbols ();
8967 for (i
= 0; i
< list
->nsyms
; ++i
)
8969 struct symbol
*sym
= list
->symbol
[i
];
8971 if (sym
->language () == language_go
8972 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8974 gdb::unique_xmalloc_ptr
<char> this_package_name
8975 (go_symbol_package_name (sym
));
8977 if (this_package_name
== NULL
)
8979 if (package_name
== NULL
)
8980 package_name
= std::move (this_package_name
);
8983 struct objfile
*objfile
8984 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8985 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8986 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8987 (symbol_symtab (sym
) != NULL
8988 ? symtab_to_filename_for_display
8989 (symbol_symtab (sym
))
8990 : objfile_name (objfile
)),
8991 this_package_name
.get (), package_name
.get ());
8997 if (package_name
!= NULL
)
8999 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9000 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9001 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9002 saved_package_name
);
9005 sym
= allocate_symbol (objfile
);
9006 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9007 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9008 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9009 e.g., "main" finds the "main" module and not C's main(). */
9010 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9011 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9012 SYMBOL_TYPE (sym
) = type
;
9014 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9018 /* Allocate a fully-qualified name consisting of the two parts on the
9022 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9024 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9027 /* A helper that allocates a struct discriminant_info to attach to a
9030 static struct discriminant_info
*
9031 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9034 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9035 gdb_assert (discriminant_index
== -1
9036 || (discriminant_index
>= 0
9037 && discriminant_index
< TYPE_NFIELDS (type
)));
9038 gdb_assert (default_index
== -1
9039 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9041 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9043 struct discriminant_info
*disc
9044 = ((struct discriminant_info
*)
9046 offsetof (struct discriminant_info
, discriminants
)
9047 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9048 disc
->default_index
= default_index
;
9049 disc
->discriminant_index
= discriminant_index
;
9051 struct dynamic_prop prop
;
9052 prop
.kind
= PROP_UNDEFINED
;
9053 prop
.data
.baton
= disc
;
9055 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9060 /* Some versions of rustc emitted enums in an unusual way.
9062 Ordinary enums were emitted as unions. The first element of each
9063 structure in the union was named "RUST$ENUM$DISR". This element
9064 held the discriminant.
9066 These versions of Rust also implemented the "non-zero"
9067 optimization. When the enum had two values, and one is empty and
9068 the other holds a pointer that cannot be zero, the pointer is used
9069 as the discriminant, with a zero value meaning the empty variant.
9070 Here, the union's first member is of the form
9071 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9072 where the fieldnos are the indices of the fields that should be
9073 traversed in order to find the field (which may be several fields deep)
9074 and the variantname is the name of the variant of the case when the
9077 This function recognizes whether TYPE is of one of these forms,
9078 and, if so, smashes it to be a variant type. */
9081 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9083 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9085 /* We don't need to deal with empty enums. */
9086 if (TYPE_NFIELDS (type
) == 0)
9089 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9090 if (TYPE_NFIELDS (type
) == 1
9091 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9093 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9095 /* Decode the field name to find the offset of the
9097 ULONGEST bit_offset
= 0;
9098 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9099 while (name
[0] >= '0' && name
[0] <= '9')
9102 unsigned long index
= strtoul (name
, &tail
, 10);
9105 || index
>= TYPE_NFIELDS (field_type
)
9106 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9107 != FIELD_LOC_KIND_BITPOS
))
9109 complaint (_("Could not parse Rust enum encoding string \"%s\""
9111 TYPE_FIELD_NAME (type
, 0),
9112 objfile_name (objfile
));
9117 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9118 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9121 /* Make a union to hold the variants. */
9122 struct type
*union_type
= alloc_type (objfile
);
9123 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9124 TYPE_NFIELDS (union_type
) = 3;
9125 TYPE_FIELDS (union_type
)
9126 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9127 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9128 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9130 /* Put the discriminant must at index 0. */
9131 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9132 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9133 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9134 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9136 /* The order of fields doesn't really matter, so put the real
9137 field at index 1 and the data-less field at index 2. */
9138 struct discriminant_info
*disc
9139 = alloc_discriminant_info (union_type
, 0, 1);
9140 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9141 TYPE_FIELD_NAME (union_type
, 1)
9142 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9143 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9144 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9145 TYPE_FIELD_NAME (union_type
, 1));
9147 const char *dataless_name
9148 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9150 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9152 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9153 /* NAME points into the original discriminant name, which
9154 already has the correct lifetime. */
9155 TYPE_FIELD_NAME (union_type
, 2) = name
;
9156 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9157 disc
->discriminants
[2] = 0;
9159 /* Smash this type to be a structure type. We have to do this
9160 because the type has already been recorded. */
9161 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9162 TYPE_NFIELDS (type
) = 1;
9164 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9166 /* Install the variant part. */
9167 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9168 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9169 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9171 /* A union with a single anonymous field is probably an old-style
9173 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9175 /* Smash this type to be a structure type. We have to do this
9176 because the type has already been recorded. */
9177 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9179 /* Make a union to hold the variants. */
9180 struct type
*union_type
= alloc_type (objfile
);
9181 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9182 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9183 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9184 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9185 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9187 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9188 const char *variant_name
9189 = rust_last_path_segment (TYPE_NAME (field_type
));
9190 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9191 TYPE_NAME (field_type
)
9192 = rust_fully_qualify (&objfile
->objfile_obstack
,
9193 TYPE_NAME (type
), variant_name
);
9195 /* Install the union in the outer struct type. */
9196 TYPE_NFIELDS (type
) = 1;
9198 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9199 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9200 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9201 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9203 alloc_discriminant_info (union_type
, -1, 0);
9207 struct type
*disr_type
= nullptr;
9208 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9210 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9212 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9214 /* All fields of a true enum will be structs. */
9217 else if (TYPE_NFIELDS (disr_type
) == 0)
9219 /* Could be data-less variant, so keep going. */
9220 disr_type
= nullptr;
9222 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9223 "RUST$ENUM$DISR") != 0)
9225 /* Not a Rust enum. */
9235 /* If we got here without a discriminant, then it's probably
9237 if (disr_type
== nullptr)
9240 /* Smash this type to be a structure type. We have to do this
9241 because the type has already been recorded. */
9242 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9244 /* Make a union to hold the variants. */
9245 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9246 struct type
*union_type
= alloc_type (objfile
);
9247 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9248 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9249 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9250 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9251 TYPE_FIELDS (union_type
)
9252 = (struct field
*) TYPE_ZALLOC (union_type
,
9253 (TYPE_NFIELDS (union_type
)
9254 * sizeof (struct field
)));
9256 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9257 TYPE_NFIELDS (type
) * sizeof (struct field
));
9259 /* Install the discriminant at index 0 in the union. */
9260 TYPE_FIELD (union_type
, 0) = *disr_field
;
9261 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9262 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9264 /* Install the union in the outer struct type. */
9265 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9266 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9267 TYPE_NFIELDS (type
) = 1;
9269 /* Set the size and offset of the union type. */
9270 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9272 /* We need a way to find the correct discriminant given a
9273 variant name. For convenience we build a map here. */
9274 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9275 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9276 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9278 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9281 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9282 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9286 int n_fields
= TYPE_NFIELDS (union_type
);
9287 struct discriminant_info
*disc
9288 = alloc_discriminant_info (union_type
, 0, -1);
9289 /* Skip the discriminant here. */
9290 for (int i
= 1; i
< n_fields
; ++i
)
9292 /* Find the final word in the name of this variant's type.
9293 That name can be used to look up the correct
9295 const char *variant_name
9296 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9299 auto iter
= discriminant_map
.find (variant_name
);
9300 if (iter
!= discriminant_map
.end ())
9301 disc
->discriminants
[i
] = iter
->second
;
9303 /* Remove the discriminant field, if it exists. */
9304 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9305 if (TYPE_NFIELDS (sub_type
) > 0)
9307 --TYPE_NFIELDS (sub_type
);
9308 ++TYPE_FIELDS (sub_type
);
9310 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9311 TYPE_NAME (sub_type
)
9312 = rust_fully_qualify (&objfile
->objfile_obstack
,
9313 TYPE_NAME (type
), variant_name
);
9318 /* Rewrite some Rust unions to be structures with variants parts. */
9321 rust_union_quirks (struct dwarf2_cu
*cu
)
9323 gdb_assert (cu
->language
== language_rust
);
9324 for (type
*type_
: cu
->rust_unions
)
9325 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9326 /* We don't need this any more. */
9327 cu
->rust_unions
.clear ();
9330 /* Return the symtab for PER_CU. This works properly regardless of
9331 whether we're using the index or psymtabs. */
9333 static struct compunit_symtab
*
9334 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9336 return (per_cu
->dwarf2_per_objfile
->using_index
9337 ? per_cu
->v
.quick
->compunit_symtab
9338 : per_cu
->v
.psymtab
->compunit_symtab
);
9341 /* A helper function for computing the list of all symbol tables
9342 included by PER_CU. */
9345 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9346 htab_t all_children
, htab_t all_type_symtabs
,
9347 struct dwarf2_per_cu_data
*per_cu
,
9348 struct compunit_symtab
*immediate_parent
)
9351 struct compunit_symtab
*cust
;
9353 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9356 /* This inclusion and its children have been processed. */
9361 /* Only add a CU if it has a symbol table. */
9362 cust
= get_compunit_symtab (per_cu
);
9365 /* If this is a type unit only add its symbol table if we haven't
9366 seen it yet (type unit per_cu's can share symtabs). */
9367 if (per_cu
->is_debug_types
)
9369 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9373 result
->push_back (cust
);
9374 if (cust
->user
== NULL
)
9375 cust
->user
= immediate_parent
;
9380 result
->push_back (cust
);
9381 if (cust
->user
== NULL
)
9382 cust
->user
= immediate_parent
;
9386 if (!per_cu
->imported_symtabs_empty ())
9387 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9389 recursively_compute_inclusions (result
, all_children
,
9390 all_type_symtabs
, ptr
, cust
);
9394 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9398 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9400 gdb_assert (! per_cu
->is_debug_types
);
9402 if (!per_cu
->imported_symtabs_empty ())
9405 std::vector
<compunit_symtab
*> result_symtabs
;
9406 htab_t all_children
, all_type_symtabs
;
9407 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9409 /* If we don't have a symtab, we can just skip this case. */
9413 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9414 NULL
, xcalloc
, xfree
);
9415 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9416 NULL
, xcalloc
, xfree
);
9418 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9420 recursively_compute_inclusions (&result_symtabs
, all_children
,
9421 all_type_symtabs
, ptr
, cust
);
9424 /* Now we have a transitive closure of all the included symtabs. */
9425 len
= result_symtabs
.size ();
9427 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9428 struct compunit_symtab
*, len
+ 1);
9429 memcpy (cust
->includes
, result_symtabs
.data (),
9430 len
* sizeof (compunit_symtab
*));
9431 cust
->includes
[len
] = NULL
;
9433 htab_delete (all_children
);
9434 htab_delete (all_type_symtabs
);
9438 /* Compute the 'includes' field for the symtabs of all the CUs we just
9442 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9444 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9446 if (! iter
->is_debug_types
)
9447 compute_compunit_symtab_includes (iter
);
9450 dwarf2_per_objfile
->just_read_cus
.clear ();
9453 /* Generate full symbol information for PER_CU, whose DIEs have
9454 already been loaded into memory. */
9457 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9458 enum language pretend_language
)
9460 struct dwarf2_cu
*cu
= per_cu
->cu
;
9461 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9462 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9463 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9464 CORE_ADDR lowpc
, highpc
;
9465 struct compunit_symtab
*cust
;
9467 struct block
*static_block
;
9470 baseaddr
= objfile
->text_section_offset ();
9472 /* Clear the list here in case something was left over. */
9473 cu
->method_list
.clear ();
9475 cu
->language
= pretend_language
;
9476 cu
->language_defn
= language_def (cu
->language
);
9478 /* Do line number decoding in read_file_scope () */
9479 process_die (cu
->dies
, cu
);
9481 /* For now fudge the Go package. */
9482 if (cu
->language
== language_go
)
9483 fixup_go_packaging (cu
);
9485 /* Now that we have processed all the DIEs in the CU, all the types
9486 should be complete, and it should now be safe to compute all of the
9488 compute_delayed_physnames (cu
);
9490 if (cu
->language
== language_rust
)
9491 rust_union_quirks (cu
);
9493 /* Some compilers don't define a DW_AT_high_pc attribute for the
9494 compilation unit. If the DW_AT_high_pc is missing, synthesize
9495 it, by scanning the DIE's below the compilation unit. */
9496 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9498 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9499 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9501 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9502 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9503 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9504 addrmap to help ensure it has an accurate map of pc values belonging to
9506 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9508 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9509 SECT_OFF_TEXT (objfile
),
9514 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9516 /* Set symtab language to language from DW_AT_language. If the
9517 compilation is from a C file generated by language preprocessors, do
9518 not set the language if it was already deduced by start_subfile. */
9519 if (!(cu
->language
== language_c
9520 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9521 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9523 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9524 produce DW_AT_location with location lists but it can be possibly
9525 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9526 there were bugs in prologue debug info, fixed later in GCC-4.5
9527 by "unwind info for epilogues" patch (which is not directly related).
9529 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9530 needed, it would be wrong due to missing DW_AT_producer there.
9532 Still one can confuse GDB by using non-standard GCC compilation
9533 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9535 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9536 cust
->locations_valid
= 1;
9538 if (gcc_4_minor
>= 5)
9539 cust
->epilogue_unwind_valid
= 1;
9541 cust
->call_site_htab
= cu
->call_site_htab
;
9544 if (dwarf2_per_objfile
->using_index
)
9545 per_cu
->v
.quick
->compunit_symtab
= cust
;
9548 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9549 pst
->compunit_symtab
= cust
;
9553 /* Push it for inclusion processing later. */
9554 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9556 /* Not needed any more. */
9557 cu
->reset_builder ();
9560 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9561 already been loaded into memory. */
9564 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9565 enum language pretend_language
)
9567 struct dwarf2_cu
*cu
= per_cu
->cu
;
9568 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9569 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9570 struct compunit_symtab
*cust
;
9571 struct signatured_type
*sig_type
;
9573 gdb_assert (per_cu
->is_debug_types
);
9574 sig_type
= (struct signatured_type
*) per_cu
;
9576 /* Clear the list here in case something was left over. */
9577 cu
->method_list
.clear ();
9579 cu
->language
= pretend_language
;
9580 cu
->language_defn
= language_def (cu
->language
);
9582 /* The symbol tables are set up in read_type_unit_scope. */
9583 process_die (cu
->dies
, cu
);
9585 /* For now fudge the Go package. */
9586 if (cu
->language
== language_go
)
9587 fixup_go_packaging (cu
);
9589 /* Now that we have processed all the DIEs in the CU, all the types
9590 should be complete, and it should now be safe to compute all of the
9592 compute_delayed_physnames (cu
);
9594 if (cu
->language
== language_rust
)
9595 rust_union_quirks (cu
);
9597 /* TUs share symbol tables.
9598 If this is the first TU to use this symtab, complete the construction
9599 of it with end_expandable_symtab. Otherwise, complete the addition of
9600 this TU's symbols to the existing symtab. */
9601 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9603 buildsym_compunit
*builder
= cu
->get_builder ();
9604 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9605 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9609 /* Set symtab language to language from DW_AT_language. If the
9610 compilation is from a C file generated by language preprocessors,
9611 do not set the language if it was already deduced by
9613 if (!(cu
->language
== language_c
9614 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9615 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9620 cu
->get_builder ()->augment_type_symtab ();
9621 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9624 if (dwarf2_per_objfile
->using_index
)
9625 per_cu
->v
.quick
->compunit_symtab
= cust
;
9628 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9629 pst
->compunit_symtab
= cust
;
9633 /* Not needed any more. */
9634 cu
->reset_builder ();
9637 /* Process an imported unit DIE. */
9640 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9642 struct attribute
*attr
;
9644 /* For now we don't handle imported units in type units. */
9645 if (cu
->per_cu
->is_debug_types
)
9647 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9648 " supported in type units [in module %s]"),
9649 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9652 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9655 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9656 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9657 dwarf2_per_cu_data
*per_cu
9658 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9659 cu
->per_cu
->dwarf2_per_objfile
);
9661 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9662 into another compilation unit, at root level. Regard this as a hint,
9664 if (die
->parent
&& die
->parent
->parent
== NULL
9665 && per_cu
->unit_type
== DW_UT_compile
9666 && per_cu
->lang
== language_cplus
)
9669 /* If necessary, add it to the queue and load its DIEs. */
9670 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9671 load_full_comp_unit (per_cu
, false, cu
->language
);
9673 cu
->per_cu
->imported_symtabs_push (per_cu
);
9677 /* RAII object that represents a process_die scope: i.e.,
9678 starts/finishes processing a DIE. */
9679 class process_die_scope
9682 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9683 : m_die (die
), m_cu (cu
)
9685 /* We should only be processing DIEs not already in process. */
9686 gdb_assert (!m_die
->in_process
);
9687 m_die
->in_process
= true;
9690 ~process_die_scope ()
9692 m_die
->in_process
= false;
9694 /* If we're done processing the DIE for the CU that owns the line
9695 header, we don't need the line header anymore. */
9696 if (m_cu
->line_header_die_owner
== m_die
)
9698 delete m_cu
->line_header
;
9699 m_cu
->line_header
= NULL
;
9700 m_cu
->line_header_die_owner
= NULL
;
9709 /* Process a die and its children. */
9712 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9714 process_die_scope
scope (die
, cu
);
9718 case DW_TAG_padding
:
9720 case DW_TAG_compile_unit
:
9721 case DW_TAG_partial_unit
:
9722 read_file_scope (die
, cu
);
9724 case DW_TAG_type_unit
:
9725 read_type_unit_scope (die
, cu
);
9727 case DW_TAG_subprogram
:
9728 /* Nested subprograms in Fortran get a prefix. */
9729 if (cu
->language
== language_fortran
9730 && die
->parent
!= NULL
9731 && die
->parent
->tag
== DW_TAG_subprogram
)
9732 cu
->processing_has_namespace_info
= true;
9734 case DW_TAG_inlined_subroutine
:
9735 read_func_scope (die
, cu
);
9737 case DW_TAG_lexical_block
:
9738 case DW_TAG_try_block
:
9739 case DW_TAG_catch_block
:
9740 read_lexical_block_scope (die
, cu
);
9742 case DW_TAG_call_site
:
9743 case DW_TAG_GNU_call_site
:
9744 read_call_site_scope (die
, cu
);
9746 case DW_TAG_class_type
:
9747 case DW_TAG_interface_type
:
9748 case DW_TAG_structure_type
:
9749 case DW_TAG_union_type
:
9750 process_structure_scope (die
, cu
);
9752 case DW_TAG_enumeration_type
:
9753 process_enumeration_scope (die
, cu
);
9756 /* These dies have a type, but processing them does not create
9757 a symbol or recurse to process the children. Therefore we can
9758 read them on-demand through read_type_die. */
9759 case DW_TAG_subroutine_type
:
9760 case DW_TAG_set_type
:
9761 case DW_TAG_array_type
:
9762 case DW_TAG_pointer_type
:
9763 case DW_TAG_ptr_to_member_type
:
9764 case DW_TAG_reference_type
:
9765 case DW_TAG_rvalue_reference_type
:
9766 case DW_TAG_string_type
:
9769 case DW_TAG_base_type
:
9770 case DW_TAG_subrange_type
:
9771 case DW_TAG_typedef
:
9772 /* Add a typedef symbol for the type definition, if it has a
9774 new_symbol (die
, read_type_die (die
, cu
), cu
);
9776 case DW_TAG_common_block
:
9777 read_common_block (die
, cu
);
9779 case DW_TAG_common_inclusion
:
9781 case DW_TAG_namespace
:
9782 cu
->processing_has_namespace_info
= true;
9783 read_namespace (die
, cu
);
9786 cu
->processing_has_namespace_info
= true;
9787 read_module (die
, cu
);
9789 case DW_TAG_imported_declaration
:
9790 cu
->processing_has_namespace_info
= true;
9791 if (read_namespace_alias (die
, cu
))
9793 /* The declaration is not a global namespace alias. */
9795 case DW_TAG_imported_module
:
9796 cu
->processing_has_namespace_info
= true;
9797 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9798 || cu
->language
!= language_fortran
))
9799 complaint (_("Tag '%s' has unexpected children"),
9800 dwarf_tag_name (die
->tag
));
9801 read_import_statement (die
, cu
);
9804 case DW_TAG_imported_unit
:
9805 process_imported_unit_die (die
, cu
);
9808 case DW_TAG_variable
:
9809 read_variable (die
, cu
);
9813 new_symbol (die
, NULL
, cu
);
9818 /* DWARF name computation. */
9820 /* A helper function for dwarf2_compute_name which determines whether DIE
9821 needs to have the name of the scope prepended to the name listed in the
9825 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9827 struct attribute
*attr
;
9831 case DW_TAG_namespace
:
9832 case DW_TAG_typedef
:
9833 case DW_TAG_class_type
:
9834 case DW_TAG_interface_type
:
9835 case DW_TAG_structure_type
:
9836 case DW_TAG_union_type
:
9837 case DW_TAG_enumeration_type
:
9838 case DW_TAG_enumerator
:
9839 case DW_TAG_subprogram
:
9840 case DW_TAG_inlined_subroutine
:
9842 case DW_TAG_imported_declaration
:
9845 case DW_TAG_variable
:
9846 case DW_TAG_constant
:
9847 /* We only need to prefix "globally" visible variables. These include
9848 any variable marked with DW_AT_external or any variable that
9849 lives in a namespace. [Variables in anonymous namespaces
9850 require prefixing, but they are not DW_AT_external.] */
9852 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9854 struct dwarf2_cu
*spec_cu
= cu
;
9856 return die_needs_namespace (die_specification (die
, &spec_cu
),
9860 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9861 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9862 && die
->parent
->tag
!= DW_TAG_module
)
9864 /* A variable in a lexical block of some kind does not need a
9865 namespace, even though in C++ such variables may be external
9866 and have a mangled name. */
9867 if (die
->parent
->tag
== DW_TAG_lexical_block
9868 || die
->parent
->tag
== DW_TAG_try_block
9869 || die
->parent
->tag
== DW_TAG_catch_block
9870 || die
->parent
->tag
== DW_TAG_subprogram
)
9879 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9880 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9881 defined for the given DIE. */
9883 static struct attribute
*
9884 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9886 struct attribute
*attr
;
9888 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9890 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9895 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9896 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9897 defined for the given DIE. */
9900 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9902 const char *linkage_name
;
9904 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9905 if (linkage_name
== NULL
)
9906 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9908 return linkage_name
;
9911 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9912 compute the physname for the object, which include a method's:
9913 - formal parameters (C++),
9914 - receiver type (Go),
9916 The term "physname" is a bit confusing.
9917 For C++, for example, it is the demangled name.
9918 For Go, for example, it's the mangled name.
9920 For Ada, return the DIE's linkage name rather than the fully qualified
9921 name. PHYSNAME is ignored..
9923 The result is allocated on the objfile_obstack and canonicalized. */
9926 dwarf2_compute_name (const char *name
,
9927 struct die_info
*die
, struct dwarf2_cu
*cu
,
9930 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9933 name
= dwarf2_name (die
, cu
);
9935 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9936 but otherwise compute it by typename_concat inside GDB.
9937 FIXME: Actually this is not really true, or at least not always true.
9938 It's all very confusing. compute_and_set_names doesn't try to demangle
9939 Fortran names because there is no mangling standard. So new_symbol
9940 will set the demangled name to the result of dwarf2_full_name, and it is
9941 the demangled name that GDB uses if it exists. */
9942 if (cu
->language
== language_ada
9943 || (cu
->language
== language_fortran
&& physname
))
9945 /* For Ada unit, we prefer the linkage name over the name, as
9946 the former contains the exported name, which the user expects
9947 to be able to reference. Ideally, we want the user to be able
9948 to reference this entity using either natural or linkage name,
9949 but we haven't started looking at this enhancement yet. */
9950 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9952 if (linkage_name
!= NULL
)
9953 return linkage_name
;
9956 /* These are the only languages we know how to qualify names in. */
9958 && (cu
->language
== language_cplus
9959 || cu
->language
== language_fortran
|| cu
->language
== language_d
9960 || cu
->language
== language_rust
))
9962 if (die_needs_namespace (die
, cu
))
9965 const char *canonical_name
= NULL
;
9969 prefix
= determine_prefix (die
, cu
);
9970 if (*prefix
!= '\0')
9972 gdb::unique_xmalloc_ptr
<char> prefixed_name
9973 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9975 buf
.puts (prefixed_name
.get ());
9980 /* Template parameters may be specified in the DIE's DW_AT_name, or
9981 as children with DW_TAG_template_type_param or
9982 DW_TAG_value_type_param. If the latter, add them to the name
9983 here. If the name already has template parameters, then
9984 skip this step; some versions of GCC emit both, and
9985 it is more efficient to use the pre-computed name.
9987 Something to keep in mind about this process: it is very
9988 unlikely, or in some cases downright impossible, to produce
9989 something that will match the mangled name of a function.
9990 If the definition of the function has the same debug info,
9991 we should be able to match up with it anyway. But fallbacks
9992 using the minimal symbol, for instance to find a method
9993 implemented in a stripped copy of libstdc++, will not work.
9994 If we do not have debug info for the definition, we will have to
9995 match them up some other way.
9997 When we do name matching there is a related problem with function
9998 templates; two instantiated function templates are allowed to
9999 differ only by their return types, which we do not add here. */
10001 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10003 struct attribute
*attr
;
10004 struct die_info
*child
;
10007 die
->building_fullname
= 1;
10009 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10013 const gdb_byte
*bytes
;
10014 struct dwarf2_locexpr_baton
*baton
;
10017 if (child
->tag
!= DW_TAG_template_type_param
10018 && child
->tag
!= DW_TAG_template_value_param
)
10029 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10032 complaint (_("template parameter missing DW_AT_type"));
10033 buf
.puts ("UNKNOWN_TYPE");
10036 type
= die_type (child
, cu
);
10038 if (child
->tag
== DW_TAG_template_type_param
)
10040 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10041 &type_print_raw_options
);
10045 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10048 complaint (_("template parameter missing "
10049 "DW_AT_const_value"));
10050 buf
.puts ("UNKNOWN_VALUE");
10054 dwarf2_const_value_attr (attr
, type
, name
,
10055 &cu
->comp_unit_obstack
, cu
,
10056 &value
, &bytes
, &baton
);
10058 if (TYPE_NOSIGN (type
))
10059 /* GDB prints characters as NUMBER 'CHAR'. If that's
10060 changed, this can use value_print instead. */
10061 c_printchar (value
, type
, &buf
);
10064 struct value_print_options opts
;
10067 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10071 else if (bytes
!= NULL
)
10073 v
= allocate_value (type
);
10074 memcpy (value_contents_writeable (v
), bytes
,
10075 TYPE_LENGTH (type
));
10078 v
= value_from_longest (type
, value
);
10080 /* Specify decimal so that we do not depend on
10082 get_formatted_print_options (&opts
, 'd');
10084 value_print (v
, &buf
, &opts
);
10089 die
->building_fullname
= 0;
10093 /* Close the argument list, with a space if necessary
10094 (nested templates). */
10095 if (!buf
.empty () && buf
.string ().back () == '>')
10102 /* For C++ methods, append formal parameter type
10103 information, if PHYSNAME. */
10105 if (physname
&& die
->tag
== DW_TAG_subprogram
10106 && cu
->language
== language_cplus
)
10108 struct type
*type
= read_type_die (die
, cu
);
10110 c_type_print_args (type
, &buf
, 1, cu
->language
,
10111 &type_print_raw_options
);
10113 if (cu
->language
== language_cplus
)
10115 /* Assume that an artificial first parameter is
10116 "this", but do not crash if it is not. RealView
10117 marks unnamed (and thus unused) parameters as
10118 artificial; there is no way to differentiate
10120 if (TYPE_NFIELDS (type
) > 0
10121 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10122 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10123 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10125 buf
.puts (" const");
10129 const std::string
&intermediate_name
= buf
.string ();
10131 if (cu
->language
== language_cplus
)
10133 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10136 /* If we only computed INTERMEDIATE_NAME, or if
10137 INTERMEDIATE_NAME is already canonical, then we need to
10139 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10140 name
= objfile
->intern (intermediate_name
);
10142 name
= canonical_name
;
10149 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10150 If scope qualifiers are appropriate they will be added. The result
10151 will be allocated on the storage_obstack, or NULL if the DIE does
10152 not have a name. NAME may either be from a previous call to
10153 dwarf2_name or NULL.
10155 The output string will be canonicalized (if C++). */
10157 static const char *
10158 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10160 return dwarf2_compute_name (name
, die
, cu
, 0);
10163 /* Construct a physname for the given DIE in CU. NAME may either be
10164 from a previous call to dwarf2_name or NULL. The result will be
10165 allocated on the objfile_objstack or NULL if the DIE does not have a
10168 The output string will be canonicalized (if C++). */
10170 static const char *
10171 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10173 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10174 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10177 /* In this case dwarf2_compute_name is just a shortcut not building anything
10179 if (!die_needs_namespace (die
, cu
))
10180 return dwarf2_compute_name (name
, die
, cu
, 1);
10182 mangled
= dw2_linkage_name (die
, cu
);
10184 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10185 See https://github.com/rust-lang/rust/issues/32925. */
10186 if (cu
->language
== language_rust
&& mangled
!= NULL
10187 && strchr (mangled
, '{') != NULL
)
10190 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10192 gdb::unique_xmalloc_ptr
<char> demangled
;
10193 if (mangled
!= NULL
)
10196 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10198 /* Do nothing (do not demangle the symbol name). */
10200 else if (cu
->language
== language_go
)
10202 /* This is a lie, but we already lie to the caller new_symbol.
10203 new_symbol assumes we return the mangled name.
10204 This just undoes that lie until things are cleaned up. */
10208 /* Use DMGL_RET_DROP for C++ template functions to suppress
10209 their return type. It is easier for GDB users to search
10210 for such functions as `name(params)' than `long name(params)'.
10211 In such case the minimal symbol names do not match the full
10212 symbol names but for template functions there is never a need
10213 to look up their definition from their declaration so
10214 the only disadvantage remains the minimal symbol variant
10215 `long name(params)' does not have the proper inferior type. */
10216 demangled
.reset (gdb_demangle (mangled
,
10217 (DMGL_PARAMS
| DMGL_ANSI
10218 | DMGL_RET_DROP
)));
10221 canon
= demangled
.get ();
10229 if (canon
== NULL
|| check_physname
)
10231 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10233 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10235 /* It may not mean a bug in GDB. The compiler could also
10236 compute DW_AT_linkage_name incorrectly. But in such case
10237 GDB would need to be bug-to-bug compatible. */
10239 complaint (_("Computed physname <%s> does not match demangled <%s> "
10240 "(from linkage <%s>) - DIE at %s [in module %s]"),
10241 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10242 objfile_name (objfile
));
10244 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10245 is available here - over computed PHYSNAME. It is safer
10246 against both buggy GDB and buggy compilers. */
10260 retval
= objfile
->intern (retval
);
10265 /* Inspect DIE in CU for a namespace alias. If one exists, record
10266 a new symbol for it.
10268 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10271 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10273 struct attribute
*attr
;
10275 /* If the die does not have a name, this is not a namespace
10277 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10281 struct die_info
*d
= die
;
10282 struct dwarf2_cu
*imported_cu
= cu
;
10284 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10285 keep inspecting DIEs until we hit the underlying import. */
10286 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10287 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10289 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10293 d
= follow_die_ref (d
, attr
, &imported_cu
);
10294 if (d
->tag
!= DW_TAG_imported_declaration
)
10298 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10300 complaint (_("DIE at %s has too many recursively imported "
10301 "declarations"), sect_offset_str (d
->sect_off
));
10308 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10310 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10311 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10313 /* This declaration is a global namespace alias. Add
10314 a symbol for it whose type is the aliased namespace. */
10315 new_symbol (die
, type
, cu
);
10324 /* Return the using directives repository (global or local?) to use in the
10325 current context for CU.
10327 For Ada, imported declarations can materialize renamings, which *may* be
10328 global. However it is impossible (for now?) in DWARF to distinguish
10329 "external" imported declarations and "static" ones. As all imported
10330 declarations seem to be static in all other languages, make them all CU-wide
10331 global only in Ada. */
10333 static struct using_direct
**
10334 using_directives (struct dwarf2_cu
*cu
)
10336 if (cu
->language
== language_ada
10337 && cu
->get_builder ()->outermost_context_p ())
10338 return cu
->get_builder ()->get_global_using_directives ();
10340 return cu
->get_builder ()->get_local_using_directives ();
10343 /* Read the import statement specified by the given die and record it. */
10346 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10348 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10349 struct attribute
*import_attr
;
10350 struct die_info
*imported_die
, *child_die
;
10351 struct dwarf2_cu
*imported_cu
;
10352 const char *imported_name
;
10353 const char *imported_name_prefix
;
10354 const char *canonical_name
;
10355 const char *import_alias
;
10356 const char *imported_declaration
= NULL
;
10357 const char *import_prefix
;
10358 std::vector
<const char *> excludes
;
10360 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10361 if (import_attr
== NULL
)
10363 complaint (_("Tag '%s' has no DW_AT_import"),
10364 dwarf_tag_name (die
->tag
));
10369 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10370 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10371 if (imported_name
== NULL
)
10373 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10375 The import in the following code:
10389 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10390 <52> DW_AT_decl_file : 1
10391 <53> DW_AT_decl_line : 6
10392 <54> DW_AT_import : <0x75>
10393 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10394 <59> DW_AT_name : B
10395 <5b> DW_AT_decl_file : 1
10396 <5c> DW_AT_decl_line : 2
10397 <5d> DW_AT_type : <0x6e>
10399 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10400 <76> DW_AT_byte_size : 4
10401 <77> DW_AT_encoding : 5 (signed)
10403 imports the wrong die ( 0x75 instead of 0x58 ).
10404 This case will be ignored until the gcc bug is fixed. */
10408 /* Figure out the local name after import. */
10409 import_alias
= dwarf2_name (die
, cu
);
10411 /* Figure out where the statement is being imported to. */
10412 import_prefix
= determine_prefix (die
, cu
);
10414 /* Figure out what the scope of the imported die is and prepend it
10415 to the name of the imported die. */
10416 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10418 if (imported_die
->tag
!= DW_TAG_namespace
10419 && imported_die
->tag
!= DW_TAG_module
)
10421 imported_declaration
= imported_name
;
10422 canonical_name
= imported_name_prefix
;
10424 else if (strlen (imported_name_prefix
) > 0)
10425 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10426 imported_name_prefix
,
10427 (cu
->language
== language_d
? "." : "::"),
10428 imported_name
, (char *) NULL
);
10430 canonical_name
= imported_name
;
10432 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10433 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10434 child_die
= child_die
->sibling
)
10436 /* DWARF-4: A Fortran use statement with a “rename list” may be
10437 represented by an imported module entry with an import attribute
10438 referring to the module and owned entries corresponding to those
10439 entities that are renamed as part of being imported. */
10441 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10443 complaint (_("child DW_TAG_imported_declaration expected "
10444 "- DIE at %s [in module %s]"),
10445 sect_offset_str (child_die
->sect_off
),
10446 objfile_name (objfile
));
10450 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10451 if (import_attr
== NULL
)
10453 complaint (_("Tag '%s' has no DW_AT_import"),
10454 dwarf_tag_name (child_die
->tag
));
10459 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10461 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10462 if (imported_name
== NULL
)
10464 complaint (_("child DW_TAG_imported_declaration has unknown "
10465 "imported name - DIE at %s [in module %s]"),
10466 sect_offset_str (child_die
->sect_off
),
10467 objfile_name (objfile
));
10471 excludes
.push_back (imported_name
);
10473 process_die (child_die
, cu
);
10476 add_using_directive (using_directives (cu
),
10480 imported_declaration
,
10483 &objfile
->objfile_obstack
);
10486 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10487 types, but gives them a size of zero. Starting with version 14,
10488 ICC is compatible with GCC. */
10491 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10493 if (!cu
->checked_producer
)
10494 check_producer (cu
);
10496 return cu
->producer_is_icc_lt_14
;
10499 /* ICC generates a DW_AT_type for C void functions. This was observed on
10500 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10501 which says that void functions should not have a DW_AT_type. */
10504 producer_is_icc (struct dwarf2_cu
*cu
)
10506 if (!cu
->checked_producer
)
10507 check_producer (cu
);
10509 return cu
->producer_is_icc
;
10512 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10513 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10514 this, it was first present in GCC release 4.3.0. */
10517 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10519 if (!cu
->checked_producer
)
10520 check_producer (cu
);
10522 return cu
->producer_is_gcc_lt_4_3
;
10525 static file_and_directory
10526 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10528 file_and_directory res
;
10530 /* Find the filename. Do not use dwarf2_name here, since the filename
10531 is not a source language identifier. */
10532 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10533 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10535 if (res
.comp_dir
== NULL
10536 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10537 && IS_ABSOLUTE_PATH (res
.name
))
10539 res
.comp_dir_storage
= ldirname (res
.name
);
10540 if (!res
.comp_dir_storage
.empty ())
10541 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10543 if (res
.comp_dir
!= NULL
)
10545 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10546 directory, get rid of it. */
10547 const char *cp
= strchr (res
.comp_dir
, ':');
10549 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10550 res
.comp_dir
= cp
+ 1;
10553 if (res
.name
== NULL
)
10554 res
.name
= "<unknown>";
10559 /* Handle DW_AT_stmt_list for a compilation unit.
10560 DIE is the DW_TAG_compile_unit die for CU.
10561 COMP_DIR is the compilation directory. LOWPC is passed to
10562 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10565 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10566 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10568 struct dwarf2_per_objfile
*dwarf2_per_objfile
10569 = cu
->per_cu
->dwarf2_per_objfile
;
10570 struct attribute
*attr
;
10571 struct line_header line_header_local
;
10572 hashval_t line_header_local_hash
;
10574 int decode_mapping
;
10576 gdb_assert (! cu
->per_cu
->is_debug_types
);
10578 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10582 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10584 /* The line header hash table is only created if needed (it exists to
10585 prevent redundant reading of the line table for partial_units).
10586 If we're given a partial_unit, we'll need it. If we're given a
10587 compile_unit, then use the line header hash table if it's already
10588 created, but don't create one just yet. */
10590 if (dwarf2_per_objfile
->line_header_hash
== NULL
10591 && die
->tag
== DW_TAG_partial_unit
)
10593 dwarf2_per_objfile
->line_header_hash
10594 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10595 line_header_eq_voidp
,
10596 free_line_header_voidp
,
10600 line_header_local
.sect_off
= line_offset
;
10601 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10602 line_header_local_hash
= line_header_hash (&line_header_local
);
10603 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10605 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10606 &line_header_local
,
10607 line_header_local_hash
, NO_INSERT
);
10609 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10610 is not present in *SLOT (since if there is something in *SLOT then
10611 it will be for a partial_unit). */
10612 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10614 gdb_assert (*slot
!= NULL
);
10615 cu
->line_header
= (struct line_header
*) *slot
;
10620 /* dwarf_decode_line_header does not yet provide sufficient information.
10621 We always have to call also dwarf_decode_lines for it. */
10622 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10626 cu
->line_header
= lh
.release ();
10627 cu
->line_header_die_owner
= die
;
10629 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10633 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10634 &line_header_local
,
10635 line_header_local_hash
, INSERT
);
10636 gdb_assert (slot
!= NULL
);
10638 if (slot
!= NULL
&& *slot
== NULL
)
10640 /* This newly decoded line number information unit will be owned
10641 by line_header_hash hash table. */
10642 *slot
= cu
->line_header
;
10643 cu
->line_header_die_owner
= NULL
;
10647 /* We cannot free any current entry in (*slot) as that struct line_header
10648 may be already used by multiple CUs. Create only temporary decoded
10649 line_header for this CU - it may happen at most once for each line
10650 number information unit. And if we're not using line_header_hash
10651 then this is what we want as well. */
10652 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10654 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10655 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10660 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10663 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10665 struct dwarf2_per_objfile
*dwarf2_per_objfile
10666 = cu
->per_cu
->dwarf2_per_objfile
;
10667 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10668 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10669 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10670 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10671 struct attribute
*attr
;
10672 struct die_info
*child_die
;
10673 CORE_ADDR baseaddr
;
10675 prepare_one_comp_unit (cu
, die
, cu
->language
);
10676 baseaddr
= objfile
->text_section_offset ();
10678 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10680 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10681 from finish_block. */
10682 if (lowpc
== ((CORE_ADDR
) -1))
10684 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10686 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10688 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10689 standardised yet. As a workaround for the language detection we fall
10690 back to the DW_AT_producer string. */
10691 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10692 cu
->language
= language_opencl
;
10694 /* Similar hack for Go. */
10695 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10696 set_cu_language (DW_LANG_Go
, cu
);
10698 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10700 /* Decode line number information if present. We do this before
10701 processing child DIEs, so that the line header table is available
10702 for DW_AT_decl_file. */
10703 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10705 /* Process all dies in compilation unit. */
10706 if (die
->child
!= NULL
)
10708 child_die
= die
->child
;
10709 while (child_die
&& child_die
->tag
)
10711 process_die (child_die
, cu
);
10712 child_die
= child_die
->sibling
;
10716 /* Decode macro information, if present. Dwarf 2 macro information
10717 refers to information in the line number info statement program
10718 header, so we can only read it if we've read the header
10720 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10722 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10723 if (attr
&& cu
->line_header
)
10725 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10726 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10728 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10732 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10733 if (attr
&& cu
->line_header
)
10735 unsigned int macro_offset
= DW_UNSND (attr
);
10737 dwarf_decode_macros (cu
, macro_offset
, 0);
10743 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10745 struct type_unit_group
*tu_group
;
10747 struct attribute
*attr
;
10749 struct signatured_type
*sig_type
;
10751 gdb_assert (per_cu
->is_debug_types
);
10752 sig_type
= (struct signatured_type
*) per_cu
;
10754 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10756 /* If we're using .gdb_index (includes -readnow) then
10757 per_cu->type_unit_group may not have been set up yet. */
10758 if (sig_type
->type_unit_group
== NULL
)
10759 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10760 tu_group
= sig_type
->type_unit_group
;
10762 /* If we've already processed this stmt_list there's no real need to
10763 do it again, we could fake it and just recreate the part we need
10764 (file name,index -> symtab mapping). If data shows this optimization
10765 is useful we can do it then. */
10766 first_time
= tu_group
->compunit_symtab
== NULL
;
10768 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10773 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10774 lh
= dwarf_decode_line_header (line_offset
, this);
10779 start_symtab ("", NULL
, 0);
10782 gdb_assert (tu_group
->symtabs
== NULL
);
10783 gdb_assert (m_builder
== nullptr);
10784 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10785 m_builder
.reset (new struct buildsym_compunit
10786 (COMPUNIT_OBJFILE (cust
), "",
10787 COMPUNIT_DIRNAME (cust
),
10788 compunit_language (cust
),
10794 line_header
= lh
.release ();
10795 line_header_die_owner
= die
;
10799 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10801 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10802 still initializing it, and our caller (a few levels up)
10803 process_full_type_unit still needs to know if this is the first
10807 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10808 struct symtab
*, line_header
->file_names_size ());
10810 auto &file_names
= line_header
->file_names ();
10811 for (i
= 0; i
< file_names
.size (); ++i
)
10813 file_entry
&fe
= file_names
[i
];
10814 dwarf2_start_subfile (this, fe
.name
,
10815 fe
.include_dir (line_header
));
10816 buildsym_compunit
*b
= get_builder ();
10817 if (b
->get_current_subfile ()->symtab
== NULL
)
10819 /* NOTE: start_subfile will recognize when it's been
10820 passed a file it has already seen. So we can't
10821 assume there's a simple mapping from
10822 cu->line_header->file_names to subfiles, plus
10823 cu->line_header->file_names may contain dups. */
10824 b
->get_current_subfile ()->symtab
10825 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10828 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10829 tu_group
->symtabs
[i
] = fe
.symtab
;
10834 gdb_assert (m_builder
== nullptr);
10835 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10836 m_builder
.reset (new struct buildsym_compunit
10837 (COMPUNIT_OBJFILE (cust
), "",
10838 COMPUNIT_DIRNAME (cust
),
10839 compunit_language (cust
),
10842 auto &file_names
= line_header
->file_names ();
10843 for (i
= 0; i
< file_names
.size (); ++i
)
10845 file_entry
&fe
= file_names
[i
];
10846 fe
.symtab
= tu_group
->symtabs
[i
];
10850 /* The main symtab is allocated last. Type units don't have DW_AT_name
10851 so they don't have a "real" (so to speak) symtab anyway.
10852 There is later code that will assign the main symtab to all symbols
10853 that don't have one. We need to handle the case of a symbol with a
10854 missing symtab (DW_AT_decl_file) anyway. */
10857 /* Process DW_TAG_type_unit.
10858 For TUs we want to skip the first top level sibling if it's not the
10859 actual type being defined by this TU. In this case the first top
10860 level sibling is there to provide context only. */
10863 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10865 struct die_info
*child_die
;
10867 prepare_one_comp_unit (cu
, die
, language_minimal
);
10869 /* Initialize (or reinitialize) the machinery for building symtabs.
10870 We do this before processing child DIEs, so that the line header table
10871 is available for DW_AT_decl_file. */
10872 cu
->setup_type_unit_groups (die
);
10874 if (die
->child
!= NULL
)
10876 child_die
= die
->child
;
10877 while (child_die
&& child_die
->tag
)
10879 process_die (child_die
, cu
);
10880 child_die
= child_die
->sibling
;
10887 http://gcc.gnu.org/wiki/DebugFission
10888 http://gcc.gnu.org/wiki/DebugFissionDWP
10890 To simplify handling of both DWO files ("object" files with the DWARF info)
10891 and DWP files (a file with the DWOs packaged up into one file), we treat
10892 DWP files as having a collection of virtual DWO files. */
10895 hash_dwo_file (const void *item
)
10897 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10900 hash
= htab_hash_string (dwo_file
->dwo_name
);
10901 if (dwo_file
->comp_dir
!= NULL
)
10902 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10907 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10909 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10910 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10912 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10914 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10915 return lhs
->comp_dir
== rhs
->comp_dir
;
10916 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10919 /* Allocate a hash table for DWO files. */
10922 allocate_dwo_file_hash_table ()
10924 auto delete_dwo_file
= [] (void *item
)
10926 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10931 return htab_up (htab_create_alloc (41,
10938 /* Lookup DWO file DWO_NAME. */
10941 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
10942 const char *dwo_name
,
10943 const char *comp_dir
)
10945 struct dwo_file find_entry
;
10948 if (dwarf2_per_objfile
->dwo_files
== NULL
)
10949 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
10951 find_entry
.dwo_name
= dwo_name
;
10952 find_entry
.comp_dir
= comp_dir
;
10953 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
10960 hash_dwo_unit (const void *item
)
10962 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10964 /* This drops the top 32 bits of the id, but is ok for a hash. */
10965 return dwo_unit
->signature
;
10969 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10971 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10972 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10974 /* The signature is assumed to be unique within the DWO file.
10975 So while object file CU dwo_id's always have the value zero,
10976 that's OK, assuming each object file DWO file has only one CU,
10977 and that's the rule for now. */
10978 return lhs
->signature
== rhs
->signature
;
10981 /* Allocate a hash table for DWO CUs,TUs.
10982 There is one of these tables for each of CUs,TUs for each DWO file. */
10985 allocate_dwo_unit_table ()
10987 /* Start out with a pretty small number.
10988 Generally DWO files contain only one CU and maybe some TUs. */
10989 return htab_up (htab_create_alloc (3,
10992 NULL
, xcalloc
, xfree
));
10995 /* die_reader_func for create_dwo_cu. */
10998 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10999 const gdb_byte
*info_ptr
,
11000 struct die_info
*comp_unit_die
,
11001 struct dwo_file
*dwo_file
,
11002 struct dwo_unit
*dwo_unit
)
11004 struct dwarf2_cu
*cu
= reader
->cu
;
11005 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11006 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11008 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11009 if (!signature
.has_value ())
11011 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11012 " its dwo_id [in module %s]"),
11013 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11017 dwo_unit
->dwo_file
= dwo_file
;
11018 dwo_unit
->signature
= *signature
;
11019 dwo_unit
->section
= section
;
11020 dwo_unit
->sect_off
= sect_off
;
11021 dwo_unit
->length
= cu
->per_cu
->length
;
11023 if (dwarf_read_debug
)
11024 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11025 sect_offset_str (sect_off
),
11026 hex_string (dwo_unit
->signature
));
11029 /* Create the dwo_units for the CUs in a DWO_FILE.
11030 Note: This function processes DWO files only, not DWP files. */
11033 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11034 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11035 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11037 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11038 const gdb_byte
*info_ptr
, *end_ptr
;
11040 section
.read (objfile
);
11041 info_ptr
= section
.buffer
;
11043 if (info_ptr
== NULL
)
11046 if (dwarf_read_debug
)
11048 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11049 section
.get_name (),
11050 section
.get_file_name ());
11053 end_ptr
= info_ptr
+ section
.size
;
11054 while (info_ptr
< end_ptr
)
11056 struct dwarf2_per_cu_data per_cu
;
11057 struct dwo_unit read_unit
{};
11058 struct dwo_unit
*dwo_unit
;
11060 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11062 memset (&per_cu
, 0, sizeof (per_cu
));
11063 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11064 per_cu
.is_debug_types
= 0;
11065 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11066 per_cu
.section
= §ion
;
11068 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11069 if (!reader
.dummy_p
)
11070 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11071 &dwo_file
, &read_unit
);
11072 info_ptr
+= per_cu
.length
;
11074 // If the unit could not be parsed, skip it.
11075 if (read_unit
.dwo_file
== NULL
)
11078 if (cus_htab
== NULL
)
11079 cus_htab
= allocate_dwo_unit_table ();
11081 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11082 *dwo_unit
= read_unit
;
11083 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11084 gdb_assert (slot
!= NULL
);
11087 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11088 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11090 complaint (_("debug cu entry at offset %s is duplicate to"
11091 " the entry at offset %s, signature %s"),
11092 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11093 hex_string (dwo_unit
->signature
));
11095 *slot
= (void *)dwo_unit
;
11099 /* DWP file .debug_{cu,tu}_index section format:
11100 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11104 Both index sections have the same format, and serve to map a 64-bit
11105 signature to a set of section numbers. Each section begins with a header,
11106 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11107 indexes, and a pool of 32-bit section numbers. The index sections will be
11108 aligned at 8-byte boundaries in the file.
11110 The index section header consists of:
11112 V, 32 bit version number
11114 N, 32 bit number of compilation units or type units in the index
11115 M, 32 bit number of slots in the hash table
11117 Numbers are recorded using the byte order of the application binary.
11119 The hash table begins at offset 16 in the section, and consists of an array
11120 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11121 order of the application binary). Unused slots in the hash table are 0.
11122 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11124 The parallel table begins immediately after the hash table
11125 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11126 array of 32-bit indexes (using the byte order of the application binary),
11127 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11128 table contains a 32-bit index into the pool of section numbers. For unused
11129 hash table slots, the corresponding entry in the parallel table will be 0.
11131 The pool of section numbers begins immediately following the hash table
11132 (at offset 16 + 12 * M from the beginning of the section). The pool of
11133 section numbers consists of an array of 32-bit words (using the byte order
11134 of the application binary). Each item in the array is indexed starting
11135 from 0. The hash table entry provides the index of the first section
11136 number in the set. Additional section numbers in the set follow, and the
11137 set is terminated by a 0 entry (section number 0 is not used in ELF).
11139 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11140 section must be the first entry in the set, and the .debug_abbrev.dwo must
11141 be the second entry. Other members of the set may follow in any order.
11147 DWP Version 2 combines all the .debug_info, etc. sections into one,
11148 and the entries in the index tables are now offsets into these sections.
11149 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11152 Index Section Contents:
11154 Hash Table of Signatures dwp_hash_table.hash_table
11155 Parallel Table of Indices dwp_hash_table.unit_table
11156 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11157 Table of Section Sizes dwp_hash_table.v2.sizes
11159 The index section header consists of:
11161 V, 32 bit version number
11162 L, 32 bit number of columns in the table of section offsets
11163 N, 32 bit number of compilation units or type units in the index
11164 M, 32 bit number of slots in the hash table
11166 Numbers are recorded using the byte order of the application binary.
11168 The hash table has the same format as version 1.
11169 The parallel table of indices has the same format as version 1,
11170 except that the entries are origin-1 indices into the table of sections
11171 offsets and the table of section sizes.
11173 The table of offsets begins immediately following the parallel table
11174 (at offset 16 + 12 * M from the beginning of the section). The table is
11175 a two-dimensional array of 32-bit words (using the byte order of the
11176 application binary), with L columns and N+1 rows, in row-major order.
11177 Each row in the array is indexed starting from 0. The first row provides
11178 a key to the remaining rows: each column in this row provides an identifier
11179 for a debug section, and the offsets in the same column of subsequent rows
11180 refer to that section. The section identifiers are:
11182 DW_SECT_INFO 1 .debug_info.dwo
11183 DW_SECT_TYPES 2 .debug_types.dwo
11184 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11185 DW_SECT_LINE 4 .debug_line.dwo
11186 DW_SECT_LOC 5 .debug_loc.dwo
11187 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11188 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11189 DW_SECT_MACRO 8 .debug_macro.dwo
11191 The offsets provided by the CU and TU index sections are the base offsets
11192 for the contributions made by each CU or TU to the corresponding section
11193 in the package file. Each CU and TU header contains an abbrev_offset
11194 field, used to find the abbreviations table for that CU or TU within the
11195 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11196 be interpreted as relative to the base offset given in the index section.
11197 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11198 should be interpreted as relative to the base offset for .debug_line.dwo,
11199 and offsets into other debug sections obtained from DWARF attributes should
11200 also be interpreted as relative to the corresponding base offset.
11202 The table of sizes begins immediately following the table of offsets.
11203 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11204 with L columns and N rows, in row-major order. Each row in the array is
11205 indexed starting from 1 (row 0 is shared by the two tables).
11209 Hash table lookup is handled the same in version 1 and 2:
11211 We assume that N and M will not exceed 2^32 - 1.
11212 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11214 Given a 64-bit compilation unit signature or a type signature S, an entry
11215 in the hash table is located as follows:
11217 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11218 the low-order k bits all set to 1.
11220 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11222 3) If the hash table entry at index H matches the signature, use that
11223 entry. If the hash table entry at index H is unused (all zeroes),
11224 terminate the search: the signature is not present in the table.
11226 4) Let H = (H + H') modulo M. Repeat at Step 3.
11228 Because M > N and H' and M are relatively prime, the search is guaranteed
11229 to stop at an unused slot or find the match. */
11231 /* Create a hash table to map DWO IDs to their CU/TU entry in
11232 .debug_{info,types}.dwo in DWP_FILE.
11233 Returns NULL if there isn't one.
11234 Note: This function processes DWP files only, not DWO files. */
11236 static struct dwp_hash_table
*
11237 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11238 struct dwp_file
*dwp_file
, int is_debug_types
)
11240 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11241 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11242 const gdb_byte
*index_ptr
, *index_end
;
11243 struct dwarf2_section_info
*index
;
11244 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11245 struct dwp_hash_table
*htab
;
11247 if (is_debug_types
)
11248 index
= &dwp_file
->sections
.tu_index
;
11250 index
= &dwp_file
->sections
.cu_index
;
11252 if (index
->empty ())
11254 index
->read (objfile
);
11256 index_ptr
= index
->buffer
;
11257 index_end
= index_ptr
+ index
->size
;
11259 version
= read_4_bytes (dbfd
, index_ptr
);
11262 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11266 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11268 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11271 if (version
!= 1 && version
!= 2)
11273 error (_("Dwarf Error: unsupported DWP file version (%s)"
11274 " [in module %s]"),
11275 pulongest (version
), dwp_file
->name
);
11277 if (nr_slots
!= (nr_slots
& -nr_slots
))
11279 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11280 " is not power of 2 [in module %s]"),
11281 pulongest (nr_slots
), dwp_file
->name
);
11284 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11285 htab
->version
= version
;
11286 htab
->nr_columns
= nr_columns
;
11287 htab
->nr_units
= nr_units
;
11288 htab
->nr_slots
= nr_slots
;
11289 htab
->hash_table
= index_ptr
;
11290 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11292 /* Exit early if the table is empty. */
11293 if (nr_slots
== 0 || nr_units
== 0
11294 || (version
== 2 && nr_columns
== 0))
11296 /* All must be zero. */
11297 if (nr_slots
!= 0 || nr_units
!= 0
11298 || (version
== 2 && nr_columns
!= 0))
11300 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11301 " all zero [in modules %s]"),
11309 htab
->section_pool
.v1
.indices
=
11310 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11311 /* It's harder to decide whether the section is too small in v1.
11312 V1 is deprecated anyway so we punt. */
11316 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11317 int *ids
= htab
->section_pool
.v2
.section_ids
;
11318 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11319 /* Reverse map for error checking. */
11320 int ids_seen
[DW_SECT_MAX
+ 1];
11323 if (nr_columns
< 2)
11325 error (_("Dwarf Error: bad DWP hash table, too few columns"
11326 " in section table [in module %s]"),
11329 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11331 error (_("Dwarf Error: bad DWP hash table, too many columns"
11332 " in section table [in module %s]"),
11335 memset (ids
, 255, sizeof_ids
);
11336 memset (ids_seen
, 255, sizeof (ids_seen
));
11337 for (i
= 0; i
< nr_columns
; ++i
)
11339 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11341 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11343 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11344 " in section table [in module %s]"),
11345 id
, dwp_file
->name
);
11347 if (ids_seen
[id
] != -1)
11349 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11350 " id %d in section table [in module %s]"),
11351 id
, dwp_file
->name
);
11356 /* Must have exactly one info or types section. */
11357 if (((ids_seen
[DW_SECT_INFO
] != -1)
11358 + (ids_seen
[DW_SECT_TYPES
] != -1))
11361 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11362 " DWO info/types section [in module %s]"),
11365 /* Must have an abbrev section. */
11366 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11368 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11369 " section [in module %s]"),
11372 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11373 htab
->section_pool
.v2
.sizes
=
11374 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11375 * nr_units
* nr_columns
);
11376 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11377 * nr_units
* nr_columns
))
11380 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11381 " [in module %s]"),
11389 /* Update SECTIONS with the data from SECTP.
11391 This function is like the other "locate" section routines that are
11392 passed to bfd_map_over_sections, but in this context the sections to
11393 read comes from the DWP V1 hash table, not the full ELF section table.
11395 The result is non-zero for success, or zero if an error was found. */
11398 locate_v1_virtual_dwo_sections (asection
*sectp
,
11399 struct virtual_v1_dwo_sections
*sections
)
11401 const struct dwop_section_names
*names
= &dwop_section_names
;
11403 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11405 /* There can be only one. */
11406 if (sections
->abbrev
.s
.section
!= NULL
)
11408 sections
->abbrev
.s
.section
= sectp
;
11409 sections
->abbrev
.size
= bfd_section_size (sectp
);
11411 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11412 || section_is_p (sectp
->name
, &names
->types_dwo
))
11414 /* There can be only one. */
11415 if (sections
->info_or_types
.s
.section
!= NULL
)
11417 sections
->info_or_types
.s
.section
= sectp
;
11418 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11420 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11422 /* There can be only one. */
11423 if (sections
->line
.s
.section
!= NULL
)
11425 sections
->line
.s
.section
= sectp
;
11426 sections
->line
.size
= bfd_section_size (sectp
);
11428 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11430 /* There can be only one. */
11431 if (sections
->loc
.s
.section
!= NULL
)
11433 sections
->loc
.s
.section
= sectp
;
11434 sections
->loc
.size
= bfd_section_size (sectp
);
11436 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11438 /* There can be only one. */
11439 if (sections
->macinfo
.s
.section
!= NULL
)
11441 sections
->macinfo
.s
.section
= sectp
;
11442 sections
->macinfo
.size
= bfd_section_size (sectp
);
11444 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11446 /* There can be only one. */
11447 if (sections
->macro
.s
.section
!= NULL
)
11449 sections
->macro
.s
.section
= sectp
;
11450 sections
->macro
.size
= bfd_section_size (sectp
);
11452 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11454 /* There can be only one. */
11455 if (sections
->str_offsets
.s
.section
!= NULL
)
11457 sections
->str_offsets
.s
.section
= sectp
;
11458 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11462 /* No other kind of section is valid. */
11469 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11470 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11471 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11472 This is for DWP version 1 files. */
11474 static struct dwo_unit
*
11475 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11476 struct dwp_file
*dwp_file
,
11477 uint32_t unit_index
,
11478 const char *comp_dir
,
11479 ULONGEST signature
, int is_debug_types
)
11481 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11482 const struct dwp_hash_table
*dwp_htab
=
11483 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11484 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11485 const char *kind
= is_debug_types
? "TU" : "CU";
11486 struct dwo_file
*dwo_file
;
11487 struct dwo_unit
*dwo_unit
;
11488 struct virtual_v1_dwo_sections sections
;
11489 void **dwo_file_slot
;
11492 gdb_assert (dwp_file
->version
== 1);
11494 if (dwarf_read_debug
)
11496 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11498 pulongest (unit_index
), hex_string (signature
),
11502 /* Fetch the sections of this DWO unit.
11503 Put a limit on the number of sections we look for so that bad data
11504 doesn't cause us to loop forever. */
11506 #define MAX_NR_V1_DWO_SECTIONS \
11507 (1 /* .debug_info or .debug_types */ \
11508 + 1 /* .debug_abbrev */ \
11509 + 1 /* .debug_line */ \
11510 + 1 /* .debug_loc */ \
11511 + 1 /* .debug_str_offsets */ \
11512 + 1 /* .debug_macro or .debug_macinfo */ \
11513 + 1 /* trailing zero */)
11515 memset (§ions
, 0, sizeof (sections
));
11517 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11520 uint32_t section_nr
=
11521 read_4_bytes (dbfd
,
11522 dwp_htab
->section_pool
.v1
.indices
11523 + (unit_index
+ i
) * sizeof (uint32_t));
11525 if (section_nr
== 0)
11527 if (section_nr
>= dwp_file
->num_sections
)
11529 error (_("Dwarf Error: bad DWP hash table, section number too large"
11530 " [in module %s]"),
11534 sectp
= dwp_file
->elf_sections
[section_nr
];
11535 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11537 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11538 " [in module %s]"),
11544 || sections
.info_or_types
.empty ()
11545 || sections
.abbrev
.empty ())
11547 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11548 " [in module %s]"),
11551 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11553 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11554 " [in module %s]"),
11558 /* It's easier for the rest of the code if we fake a struct dwo_file and
11559 have dwo_unit "live" in that. At least for now.
11561 The DWP file can be made up of a random collection of CUs and TUs.
11562 However, for each CU + set of TUs that came from the same original DWO
11563 file, we can combine them back into a virtual DWO file to save space
11564 (fewer struct dwo_file objects to allocate). Remember that for really
11565 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11567 std::string virtual_dwo_name
=
11568 string_printf ("virtual-dwo/%d-%d-%d-%d",
11569 sections
.abbrev
.get_id (),
11570 sections
.line
.get_id (),
11571 sections
.loc
.get_id (),
11572 sections
.str_offsets
.get_id ());
11573 /* Can we use an existing virtual DWO file? */
11574 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11575 virtual_dwo_name
.c_str (),
11577 /* Create one if necessary. */
11578 if (*dwo_file_slot
== NULL
)
11580 if (dwarf_read_debug
)
11582 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11583 virtual_dwo_name
.c_str ());
11585 dwo_file
= new struct dwo_file
;
11586 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11587 dwo_file
->comp_dir
= comp_dir
;
11588 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11589 dwo_file
->sections
.line
= sections
.line
;
11590 dwo_file
->sections
.loc
= sections
.loc
;
11591 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11592 dwo_file
->sections
.macro
= sections
.macro
;
11593 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11594 /* The "str" section is global to the entire DWP file. */
11595 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11596 /* The info or types section is assigned below to dwo_unit,
11597 there's no need to record it in dwo_file.
11598 Also, we can't simply record type sections in dwo_file because
11599 we record a pointer into the vector in dwo_unit. As we collect more
11600 types we'll grow the vector and eventually have to reallocate space
11601 for it, invalidating all copies of pointers into the previous
11603 *dwo_file_slot
= dwo_file
;
11607 if (dwarf_read_debug
)
11609 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11610 virtual_dwo_name
.c_str ());
11612 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11615 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11616 dwo_unit
->dwo_file
= dwo_file
;
11617 dwo_unit
->signature
= signature
;
11618 dwo_unit
->section
=
11619 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11620 *dwo_unit
->section
= sections
.info_or_types
;
11621 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11626 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11627 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11628 piece within that section used by a TU/CU, return a virtual section
11629 of just that piece. */
11631 static struct dwarf2_section_info
11632 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11633 struct dwarf2_section_info
*section
,
11634 bfd_size_type offset
, bfd_size_type size
)
11636 struct dwarf2_section_info result
;
11639 gdb_assert (section
!= NULL
);
11640 gdb_assert (!section
->is_virtual
);
11642 memset (&result
, 0, sizeof (result
));
11643 result
.s
.containing_section
= section
;
11644 result
.is_virtual
= true;
11649 sectp
= section
->get_bfd_section ();
11651 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11652 bounds of the real section. This is a pretty-rare event, so just
11653 flag an error (easier) instead of a warning and trying to cope. */
11655 || offset
+ size
> bfd_section_size (sectp
))
11657 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11658 " in section %s [in module %s]"),
11659 sectp
? bfd_section_name (sectp
) : "<unknown>",
11660 objfile_name (dwarf2_per_objfile
->objfile
));
11663 result
.virtual_offset
= offset
;
11664 result
.size
= size
;
11668 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11669 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11670 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11671 This is for DWP version 2 files. */
11673 static struct dwo_unit
*
11674 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11675 struct dwp_file
*dwp_file
,
11676 uint32_t unit_index
,
11677 const char *comp_dir
,
11678 ULONGEST signature
, int is_debug_types
)
11680 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11681 const struct dwp_hash_table
*dwp_htab
=
11682 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11683 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11684 const char *kind
= is_debug_types
? "TU" : "CU";
11685 struct dwo_file
*dwo_file
;
11686 struct dwo_unit
*dwo_unit
;
11687 struct virtual_v2_dwo_sections sections
;
11688 void **dwo_file_slot
;
11691 gdb_assert (dwp_file
->version
== 2);
11693 if (dwarf_read_debug
)
11695 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11697 pulongest (unit_index
), hex_string (signature
),
11701 /* Fetch the section offsets of this DWO unit. */
11703 memset (§ions
, 0, sizeof (sections
));
11705 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11707 uint32_t offset
= read_4_bytes (dbfd
,
11708 dwp_htab
->section_pool
.v2
.offsets
11709 + (((unit_index
- 1) * dwp_htab
->nr_columns
11711 * sizeof (uint32_t)));
11712 uint32_t size
= read_4_bytes (dbfd
,
11713 dwp_htab
->section_pool
.v2
.sizes
11714 + (((unit_index
- 1) * dwp_htab
->nr_columns
11716 * sizeof (uint32_t)));
11718 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11721 case DW_SECT_TYPES
:
11722 sections
.info_or_types_offset
= offset
;
11723 sections
.info_or_types_size
= size
;
11725 case DW_SECT_ABBREV
:
11726 sections
.abbrev_offset
= offset
;
11727 sections
.abbrev_size
= size
;
11730 sections
.line_offset
= offset
;
11731 sections
.line_size
= size
;
11734 sections
.loc_offset
= offset
;
11735 sections
.loc_size
= size
;
11737 case DW_SECT_STR_OFFSETS
:
11738 sections
.str_offsets_offset
= offset
;
11739 sections
.str_offsets_size
= size
;
11741 case DW_SECT_MACINFO
:
11742 sections
.macinfo_offset
= offset
;
11743 sections
.macinfo_size
= size
;
11745 case DW_SECT_MACRO
:
11746 sections
.macro_offset
= offset
;
11747 sections
.macro_size
= size
;
11752 /* It's easier for the rest of the code if we fake a struct dwo_file and
11753 have dwo_unit "live" in that. At least for now.
11755 The DWP file can be made up of a random collection of CUs and TUs.
11756 However, for each CU + set of TUs that came from the same original DWO
11757 file, we can combine them back into a virtual DWO file to save space
11758 (fewer struct dwo_file objects to allocate). Remember that for really
11759 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11761 std::string virtual_dwo_name
=
11762 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11763 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11764 (long) (sections
.line_size
? sections
.line_offset
: 0),
11765 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11766 (long) (sections
.str_offsets_size
11767 ? sections
.str_offsets_offset
: 0));
11768 /* Can we use an existing virtual DWO file? */
11769 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11770 virtual_dwo_name
.c_str (),
11772 /* Create one if necessary. */
11773 if (*dwo_file_slot
== NULL
)
11775 if (dwarf_read_debug
)
11777 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11778 virtual_dwo_name
.c_str ());
11780 dwo_file
= new struct dwo_file
;
11781 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11782 dwo_file
->comp_dir
= comp_dir
;
11783 dwo_file
->sections
.abbrev
=
11784 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11785 sections
.abbrev_offset
, sections
.abbrev_size
);
11786 dwo_file
->sections
.line
=
11787 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11788 sections
.line_offset
, sections
.line_size
);
11789 dwo_file
->sections
.loc
=
11790 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11791 sections
.loc_offset
, sections
.loc_size
);
11792 dwo_file
->sections
.macinfo
=
11793 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11794 sections
.macinfo_offset
, sections
.macinfo_size
);
11795 dwo_file
->sections
.macro
=
11796 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11797 sections
.macro_offset
, sections
.macro_size
);
11798 dwo_file
->sections
.str_offsets
=
11799 create_dwp_v2_section (dwarf2_per_objfile
,
11800 &dwp_file
->sections
.str_offsets
,
11801 sections
.str_offsets_offset
,
11802 sections
.str_offsets_size
);
11803 /* The "str" section is global to the entire DWP file. */
11804 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11805 /* The info or types section is assigned below to dwo_unit,
11806 there's no need to record it in dwo_file.
11807 Also, we can't simply record type sections in dwo_file because
11808 we record a pointer into the vector in dwo_unit. As we collect more
11809 types we'll grow the vector and eventually have to reallocate space
11810 for it, invalidating all copies of pointers into the previous
11812 *dwo_file_slot
= dwo_file
;
11816 if (dwarf_read_debug
)
11818 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11819 virtual_dwo_name
.c_str ());
11821 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11824 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11825 dwo_unit
->dwo_file
= dwo_file
;
11826 dwo_unit
->signature
= signature
;
11827 dwo_unit
->section
=
11828 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11829 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11831 ? &dwp_file
->sections
.types
11832 : &dwp_file
->sections
.info
,
11833 sections
.info_or_types_offset
,
11834 sections
.info_or_types_size
);
11835 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11840 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11841 Returns NULL if the signature isn't found. */
11843 static struct dwo_unit
*
11844 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11845 struct dwp_file
*dwp_file
, const char *comp_dir
,
11846 ULONGEST signature
, int is_debug_types
)
11848 const struct dwp_hash_table
*dwp_htab
=
11849 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11850 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11851 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11852 uint32_t hash
= signature
& mask
;
11853 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11856 struct dwo_unit find_dwo_cu
;
11858 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11859 find_dwo_cu
.signature
= signature
;
11860 slot
= htab_find_slot (is_debug_types
11861 ? dwp_file
->loaded_tus
.get ()
11862 : dwp_file
->loaded_cus
.get (),
11863 &find_dwo_cu
, INSERT
);
11866 return (struct dwo_unit
*) *slot
;
11868 /* Use a for loop so that we don't loop forever on bad debug info. */
11869 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11871 ULONGEST signature_in_table
;
11873 signature_in_table
=
11874 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11875 if (signature_in_table
== signature
)
11877 uint32_t unit_index
=
11878 read_4_bytes (dbfd
,
11879 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11881 if (dwp_file
->version
== 1)
11883 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11884 dwp_file
, unit_index
,
11885 comp_dir
, signature
,
11890 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11891 dwp_file
, unit_index
,
11892 comp_dir
, signature
,
11895 return (struct dwo_unit
*) *slot
;
11897 if (signature_in_table
== 0)
11899 hash
= (hash
+ hash2
) & mask
;
11902 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11903 " [in module %s]"),
11907 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11908 Open the file specified by FILE_NAME and hand it off to BFD for
11909 preliminary analysis. Return a newly initialized bfd *, which
11910 includes a canonicalized copy of FILE_NAME.
11911 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11912 SEARCH_CWD is true if the current directory is to be searched.
11913 It will be searched before debug-file-directory.
11914 If successful, the file is added to the bfd include table of the
11915 objfile's bfd (see gdb_bfd_record_inclusion).
11916 If unable to find/open the file, return NULL.
11917 NOTE: This function is derived from symfile_bfd_open. */
11919 static gdb_bfd_ref_ptr
11920 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11921 const char *file_name
, int is_dwp
, int search_cwd
)
11924 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11925 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11926 to debug_file_directory. */
11927 const char *search_path
;
11928 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11930 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11933 if (*debug_file_directory
!= '\0')
11935 search_path_holder
.reset (concat (".", dirname_separator_string
,
11936 debug_file_directory
,
11938 search_path
= search_path_holder
.get ();
11944 search_path
= debug_file_directory
;
11946 openp_flags flags
= OPF_RETURN_REALPATH
;
11948 flags
|= OPF_SEARCH_IN_PATH
;
11950 gdb::unique_xmalloc_ptr
<char> absolute_name
;
11951 desc
= openp (search_path
, flags
, file_name
,
11952 O_RDONLY
| O_BINARY
, &absolute_name
);
11956 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
11958 if (sym_bfd
== NULL
)
11960 bfd_set_cacheable (sym_bfd
.get (), 1);
11962 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
11965 /* Success. Record the bfd as having been included by the objfile's bfd.
11966 This is important because things like demangled_names_hash lives in the
11967 objfile's per_bfd space and may have references to things like symbol
11968 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
11969 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
11974 /* Try to open DWO file FILE_NAME.
11975 COMP_DIR is the DW_AT_comp_dir attribute.
11976 The result is the bfd handle of the file.
11977 If there is a problem finding or opening the file, return NULL.
11978 Upon success, the canonicalized path of the file is stored in the bfd,
11979 same as symfile_bfd_open. */
11981 static gdb_bfd_ref_ptr
11982 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11983 const char *file_name
, const char *comp_dir
)
11985 if (IS_ABSOLUTE_PATH (file_name
))
11986 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
11987 0 /*is_dwp*/, 0 /*search_cwd*/);
11989 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
11991 if (comp_dir
!= NULL
)
11993 gdb::unique_xmalloc_ptr
<char> path_to_try
11994 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
11996 /* NOTE: If comp_dir is a relative path, this will also try the
11997 search path, which seems useful. */
11998 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
11999 path_to_try
.get (),
12001 1 /*search_cwd*/));
12006 /* That didn't work, try debug-file-directory, which, despite its name,
12007 is a list of paths. */
12009 if (*debug_file_directory
== '\0')
12012 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12013 0 /*is_dwp*/, 1 /*search_cwd*/);
12016 /* This function is mapped across the sections and remembers the offset and
12017 size of each of the DWO debugging sections we are interested in. */
12020 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12022 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12023 const struct dwop_section_names
*names
= &dwop_section_names
;
12025 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12027 dwo_sections
->abbrev
.s
.section
= sectp
;
12028 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12030 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12032 dwo_sections
->info
.s
.section
= sectp
;
12033 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12035 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12037 dwo_sections
->line
.s
.section
= sectp
;
12038 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12040 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12042 dwo_sections
->loc
.s
.section
= sectp
;
12043 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12045 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12047 dwo_sections
->macinfo
.s
.section
= sectp
;
12048 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12050 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12052 dwo_sections
->macro
.s
.section
= sectp
;
12053 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12055 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12057 dwo_sections
->str
.s
.section
= sectp
;
12058 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12060 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12062 dwo_sections
->str_offsets
.s
.section
= sectp
;
12063 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12065 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12067 struct dwarf2_section_info type_section
;
12069 memset (&type_section
, 0, sizeof (type_section
));
12070 type_section
.s
.section
= sectp
;
12071 type_section
.size
= bfd_section_size (sectp
);
12072 dwo_sections
->types
.push_back (type_section
);
12076 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12077 by PER_CU. This is for the non-DWP case.
12078 The result is NULL if DWO_NAME can't be found. */
12080 static struct dwo_file
*
12081 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12082 const char *dwo_name
, const char *comp_dir
)
12084 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12086 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12089 if (dwarf_read_debug
)
12090 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12094 dwo_file_up
dwo_file (new struct dwo_file
);
12095 dwo_file
->dwo_name
= dwo_name
;
12096 dwo_file
->comp_dir
= comp_dir
;
12097 dwo_file
->dbfd
= std::move (dbfd
);
12099 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12100 &dwo_file
->sections
);
12102 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12103 dwo_file
->sections
.info
, dwo_file
->cus
);
12105 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12106 dwo_file
->sections
.types
, dwo_file
->tus
);
12108 if (dwarf_read_debug
)
12109 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12111 return dwo_file
.release ();
12114 /* This function is mapped across the sections and remembers the offset and
12115 size of each of the DWP debugging sections common to version 1 and 2 that
12116 we are interested in. */
12119 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12120 void *dwp_file_ptr
)
12122 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12123 const struct dwop_section_names
*names
= &dwop_section_names
;
12124 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12126 /* Record the ELF section number for later lookup: this is what the
12127 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12128 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12129 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12131 /* Look for specific sections that we need. */
12132 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12134 dwp_file
->sections
.str
.s
.section
= sectp
;
12135 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12137 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12139 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12140 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12142 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12144 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12145 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12149 /* This function is mapped across the sections and remembers the offset and
12150 size of each of the DWP version 2 debugging sections that we are interested
12151 in. This is split into a separate function because we don't know if we
12152 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12155 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12157 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12158 const struct dwop_section_names
*names
= &dwop_section_names
;
12159 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12161 /* Record the ELF section number for later lookup: this is what the
12162 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12163 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12164 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12166 /* Look for specific sections that we need. */
12167 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12169 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12170 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12172 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12174 dwp_file
->sections
.info
.s
.section
= sectp
;
12175 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12177 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12179 dwp_file
->sections
.line
.s
.section
= sectp
;
12180 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12182 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12184 dwp_file
->sections
.loc
.s
.section
= sectp
;
12185 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12187 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12189 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12190 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12192 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12194 dwp_file
->sections
.macro
.s
.section
= sectp
;
12195 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12197 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12199 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12200 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12202 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12204 dwp_file
->sections
.types
.s
.section
= sectp
;
12205 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12209 /* Hash function for dwp_file loaded CUs/TUs. */
12212 hash_dwp_loaded_cutus (const void *item
)
12214 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12216 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12217 return dwo_unit
->signature
;
12220 /* Equality function for dwp_file loaded CUs/TUs. */
12223 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12225 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12226 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12228 return dua
->signature
== dub
->signature
;
12231 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12234 allocate_dwp_loaded_cutus_table ()
12236 return htab_up (htab_create_alloc (3,
12237 hash_dwp_loaded_cutus
,
12238 eq_dwp_loaded_cutus
,
12239 NULL
, xcalloc
, xfree
));
12242 /* Try to open DWP file FILE_NAME.
12243 The result is the bfd handle of the file.
12244 If there is a problem finding or opening the file, return NULL.
12245 Upon success, the canonicalized path of the file is stored in the bfd,
12246 same as symfile_bfd_open. */
12248 static gdb_bfd_ref_ptr
12249 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12250 const char *file_name
)
12252 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12254 1 /*search_cwd*/));
12258 /* Work around upstream bug 15652.
12259 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12260 [Whether that's a "bug" is debatable, but it is getting in our way.]
12261 We have no real idea where the dwp file is, because gdb's realpath-ing
12262 of the executable's path may have discarded the needed info.
12263 [IWBN if the dwp file name was recorded in the executable, akin to
12264 .gnu_debuglink, but that doesn't exist yet.]
12265 Strip the directory from FILE_NAME and search again. */
12266 if (*debug_file_directory
!= '\0')
12268 /* Don't implicitly search the current directory here.
12269 If the user wants to search "." to handle this case,
12270 it must be added to debug-file-directory. */
12271 return try_open_dwop_file (dwarf2_per_objfile
,
12272 lbasename (file_name
), 1 /*is_dwp*/,
12279 /* Initialize the use of the DWP file for the current objfile.
12280 By convention the name of the DWP file is ${objfile}.dwp.
12281 The result is NULL if it can't be found. */
12283 static std::unique_ptr
<struct dwp_file
>
12284 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12286 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12288 /* Try to find first .dwp for the binary file before any symbolic links
12291 /* If the objfile is a debug file, find the name of the real binary
12292 file and get the name of dwp file from there. */
12293 std::string dwp_name
;
12294 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12296 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12297 const char *backlink_basename
= lbasename (backlink
->original_name
);
12299 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12302 dwp_name
= objfile
->original_name
;
12304 dwp_name
+= ".dwp";
12306 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12308 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12310 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12311 dwp_name
= objfile_name (objfile
);
12312 dwp_name
+= ".dwp";
12313 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12318 if (dwarf_read_debug
)
12319 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12320 return std::unique_ptr
<dwp_file
> ();
12323 const char *name
= bfd_get_filename (dbfd
.get ());
12324 std::unique_ptr
<struct dwp_file
> dwp_file
12325 (new struct dwp_file (name
, std::move (dbfd
)));
12327 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12328 dwp_file
->elf_sections
=
12329 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12330 dwp_file
->num_sections
, asection
*);
12332 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12333 dwarf2_locate_common_dwp_sections
,
12336 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12339 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12342 /* The DWP file version is stored in the hash table. Oh well. */
12343 if (dwp_file
->cus
&& dwp_file
->tus
12344 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12346 /* Technically speaking, we should try to limp along, but this is
12347 pretty bizarre. We use pulongest here because that's the established
12348 portability solution (e.g, we cannot use %u for uint32_t). */
12349 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12350 " TU version %s [in DWP file %s]"),
12351 pulongest (dwp_file
->cus
->version
),
12352 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12356 dwp_file
->version
= dwp_file
->cus
->version
;
12357 else if (dwp_file
->tus
)
12358 dwp_file
->version
= dwp_file
->tus
->version
;
12360 dwp_file
->version
= 2;
12362 if (dwp_file
->version
== 2)
12363 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12364 dwarf2_locate_v2_dwp_sections
,
12367 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12368 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12370 if (dwarf_read_debug
)
12372 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12373 fprintf_unfiltered (gdb_stdlog
,
12374 " %s CUs, %s TUs\n",
12375 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12376 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12382 /* Wrapper around open_and_init_dwp_file, only open it once. */
12384 static struct dwp_file
*
12385 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12387 if (! dwarf2_per_objfile
->dwp_checked
)
12389 dwarf2_per_objfile
->dwp_file
12390 = open_and_init_dwp_file (dwarf2_per_objfile
);
12391 dwarf2_per_objfile
->dwp_checked
= 1;
12393 return dwarf2_per_objfile
->dwp_file
.get ();
12396 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12397 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12398 or in the DWP file for the objfile, referenced by THIS_UNIT.
12399 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12400 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12402 This is called, for example, when wanting to read a variable with a
12403 complex location. Therefore we don't want to do file i/o for every call.
12404 Therefore we don't want to look for a DWO file on every call.
12405 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12406 then we check if we've already seen DWO_NAME, and only THEN do we check
12409 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12410 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12412 static struct dwo_unit
*
12413 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12414 const char *dwo_name
, const char *comp_dir
,
12415 ULONGEST signature
, int is_debug_types
)
12417 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12418 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12419 const char *kind
= is_debug_types
? "TU" : "CU";
12420 void **dwo_file_slot
;
12421 struct dwo_file
*dwo_file
;
12422 struct dwp_file
*dwp_file
;
12424 /* First see if there's a DWP file.
12425 If we have a DWP file but didn't find the DWO inside it, don't
12426 look for the original DWO file. It makes gdb behave differently
12427 depending on whether one is debugging in the build tree. */
12429 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12430 if (dwp_file
!= NULL
)
12432 const struct dwp_hash_table
*dwp_htab
=
12433 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12435 if (dwp_htab
!= NULL
)
12437 struct dwo_unit
*dwo_cutu
=
12438 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12439 signature
, is_debug_types
);
12441 if (dwo_cutu
!= NULL
)
12443 if (dwarf_read_debug
)
12445 fprintf_unfiltered (gdb_stdlog
,
12446 "Virtual DWO %s %s found: @%s\n",
12447 kind
, hex_string (signature
),
12448 host_address_to_string (dwo_cutu
));
12456 /* No DWP file, look for the DWO file. */
12458 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12459 dwo_name
, comp_dir
);
12460 if (*dwo_file_slot
== NULL
)
12462 /* Read in the file and build a table of the CUs/TUs it contains. */
12463 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12465 /* NOTE: This will be NULL if unable to open the file. */
12466 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12468 if (dwo_file
!= NULL
)
12470 struct dwo_unit
*dwo_cutu
= NULL
;
12472 if (is_debug_types
&& dwo_file
->tus
)
12474 struct dwo_unit find_dwo_cutu
;
12476 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12477 find_dwo_cutu
.signature
= signature
;
12479 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12482 else if (!is_debug_types
&& dwo_file
->cus
)
12484 struct dwo_unit find_dwo_cutu
;
12486 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12487 find_dwo_cutu
.signature
= signature
;
12488 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12492 if (dwo_cutu
!= NULL
)
12494 if (dwarf_read_debug
)
12496 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12497 kind
, dwo_name
, hex_string (signature
),
12498 host_address_to_string (dwo_cutu
));
12505 /* We didn't find it. This could mean a dwo_id mismatch, or
12506 someone deleted the DWO/DWP file, or the search path isn't set up
12507 correctly to find the file. */
12509 if (dwarf_read_debug
)
12511 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12512 kind
, dwo_name
, hex_string (signature
));
12515 /* This is a warning and not a complaint because it can be caused by
12516 pilot error (e.g., user accidentally deleting the DWO). */
12518 /* Print the name of the DWP file if we looked there, helps the user
12519 better diagnose the problem. */
12520 std::string dwp_text
;
12522 if (dwp_file
!= NULL
)
12523 dwp_text
= string_printf (" [in DWP file %s]",
12524 lbasename (dwp_file
->name
));
12526 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12527 " [in module %s]"),
12528 kind
, dwo_name
, hex_string (signature
),
12530 this_unit
->is_debug_types
? "TU" : "CU",
12531 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12536 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12537 See lookup_dwo_cutu_unit for details. */
12539 static struct dwo_unit
*
12540 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12541 const char *dwo_name
, const char *comp_dir
,
12542 ULONGEST signature
)
12544 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12547 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12548 See lookup_dwo_cutu_unit for details. */
12550 static struct dwo_unit
*
12551 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12552 const char *dwo_name
, const char *comp_dir
)
12554 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12557 /* Traversal function for queue_and_load_all_dwo_tus. */
12560 queue_and_load_dwo_tu (void **slot
, void *info
)
12562 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12563 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12564 ULONGEST signature
= dwo_unit
->signature
;
12565 struct signatured_type
*sig_type
=
12566 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12568 if (sig_type
!= NULL
)
12570 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12572 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12573 a real dependency of PER_CU on SIG_TYPE. That is detected later
12574 while processing PER_CU. */
12575 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12576 load_full_type_unit (sig_cu
);
12577 per_cu
->imported_symtabs_push (sig_cu
);
12583 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12584 The DWO may have the only definition of the type, though it may not be
12585 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12586 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12589 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12591 struct dwo_unit
*dwo_unit
;
12592 struct dwo_file
*dwo_file
;
12594 gdb_assert (!per_cu
->is_debug_types
);
12595 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12596 gdb_assert (per_cu
->cu
!= NULL
);
12598 dwo_unit
= per_cu
->cu
->dwo_unit
;
12599 gdb_assert (dwo_unit
!= NULL
);
12601 dwo_file
= dwo_unit
->dwo_file
;
12602 if (dwo_file
->tus
!= NULL
)
12603 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12607 /* Read in various DIEs. */
12609 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12610 Inherit only the children of the DW_AT_abstract_origin DIE not being
12611 already referenced by DW_AT_abstract_origin from the children of the
12615 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12617 struct die_info
*child_die
;
12618 sect_offset
*offsetp
;
12619 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12620 struct die_info
*origin_die
;
12621 /* Iterator of the ORIGIN_DIE children. */
12622 struct die_info
*origin_child_die
;
12623 struct attribute
*attr
;
12624 struct dwarf2_cu
*origin_cu
;
12625 struct pending
**origin_previous_list_in_scope
;
12627 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12631 /* Note that following die references may follow to a die in a
12635 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12637 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12639 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12640 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12642 if (die
->tag
!= origin_die
->tag
12643 && !(die
->tag
== DW_TAG_inlined_subroutine
12644 && origin_die
->tag
== DW_TAG_subprogram
))
12645 complaint (_("DIE %s and its abstract origin %s have different tags"),
12646 sect_offset_str (die
->sect_off
),
12647 sect_offset_str (origin_die
->sect_off
));
12649 std::vector
<sect_offset
> offsets
;
12651 for (child_die
= die
->child
;
12652 child_die
&& child_die
->tag
;
12653 child_die
= child_die
->sibling
)
12655 struct die_info
*child_origin_die
;
12656 struct dwarf2_cu
*child_origin_cu
;
12658 /* We are trying to process concrete instance entries:
12659 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12660 it's not relevant to our analysis here. i.e. detecting DIEs that are
12661 present in the abstract instance but not referenced in the concrete
12663 if (child_die
->tag
== DW_TAG_call_site
12664 || child_die
->tag
== DW_TAG_GNU_call_site
)
12667 /* For each CHILD_DIE, find the corresponding child of
12668 ORIGIN_DIE. If there is more than one layer of
12669 DW_AT_abstract_origin, follow them all; there shouldn't be,
12670 but GCC versions at least through 4.4 generate this (GCC PR
12672 child_origin_die
= child_die
;
12673 child_origin_cu
= cu
;
12676 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12680 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12684 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12685 counterpart may exist. */
12686 if (child_origin_die
!= child_die
)
12688 if (child_die
->tag
!= child_origin_die
->tag
12689 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12690 && child_origin_die
->tag
== DW_TAG_subprogram
))
12691 complaint (_("Child DIE %s and its abstract origin %s have "
12693 sect_offset_str (child_die
->sect_off
),
12694 sect_offset_str (child_origin_die
->sect_off
));
12695 if (child_origin_die
->parent
!= origin_die
)
12696 complaint (_("Child DIE %s and its abstract origin %s have "
12697 "different parents"),
12698 sect_offset_str (child_die
->sect_off
),
12699 sect_offset_str (child_origin_die
->sect_off
));
12701 offsets
.push_back (child_origin_die
->sect_off
);
12704 std::sort (offsets
.begin (), offsets
.end ());
12705 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12706 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12707 if (offsetp
[-1] == *offsetp
)
12708 complaint (_("Multiple children of DIE %s refer "
12709 "to DIE %s as their abstract origin"),
12710 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12712 offsetp
= offsets
.data ();
12713 origin_child_die
= origin_die
->child
;
12714 while (origin_child_die
&& origin_child_die
->tag
)
12716 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12717 while (offsetp
< offsets_end
12718 && *offsetp
< origin_child_die
->sect_off
)
12720 if (offsetp
>= offsets_end
12721 || *offsetp
> origin_child_die
->sect_off
)
12723 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12724 Check whether we're already processing ORIGIN_CHILD_DIE.
12725 This can happen with mutually referenced abstract_origins.
12727 if (!origin_child_die
->in_process
)
12728 process_die (origin_child_die
, origin_cu
);
12730 origin_child_die
= origin_child_die
->sibling
;
12732 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12734 if (cu
!= origin_cu
)
12735 compute_delayed_physnames (origin_cu
);
12739 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12741 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12742 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12743 struct context_stack
*newobj
;
12746 struct die_info
*child_die
;
12747 struct attribute
*attr
, *call_line
, *call_file
;
12749 CORE_ADDR baseaddr
;
12750 struct block
*block
;
12751 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12752 std::vector
<struct symbol
*> template_args
;
12753 struct template_symbol
*templ_func
= NULL
;
12757 /* If we do not have call site information, we can't show the
12758 caller of this inlined function. That's too confusing, so
12759 only use the scope for local variables. */
12760 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12761 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12762 if (call_line
== NULL
|| call_file
== NULL
)
12764 read_lexical_block_scope (die
, cu
);
12769 baseaddr
= objfile
->text_section_offset ();
12771 name
= dwarf2_name (die
, cu
);
12773 /* Ignore functions with missing or empty names. These are actually
12774 illegal according to the DWARF standard. */
12777 complaint (_("missing name for subprogram DIE at %s"),
12778 sect_offset_str (die
->sect_off
));
12782 /* Ignore functions with missing or invalid low and high pc attributes. */
12783 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12784 <= PC_BOUNDS_INVALID
)
12786 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12787 if (!attr
|| !DW_UNSND (attr
))
12788 complaint (_("cannot get low and high bounds "
12789 "for subprogram DIE at %s"),
12790 sect_offset_str (die
->sect_off
));
12794 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12795 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12797 /* If we have any template arguments, then we must allocate a
12798 different sort of symbol. */
12799 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12801 if (child_die
->tag
== DW_TAG_template_type_param
12802 || child_die
->tag
== DW_TAG_template_value_param
)
12804 templ_func
= allocate_template_symbol (objfile
);
12805 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12810 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12811 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12812 (struct symbol
*) templ_func
);
12814 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12815 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12818 /* If there is a location expression for DW_AT_frame_base, record
12820 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12821 if (attr
!= nullptr)
12822 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12824 /* If there is a location for the static link, record it. */
12825 newobj
->static_link
= NULL
;
12826 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12827 if (attr
!= nullptr)
12829 newobj
->static_link
12830 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12831 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12832 cu
->per_cu
->addr_type ());
12835 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12837 if (die
->child
!= NULL
)
12839 child_die
= die
->child
;
12840 while (child_die
&& child_die
->tag
)
12842 if (child_die
->tag
== DW_TAG_template_type_param
12843 || child_die
->tag
== DW_TAG_template_value_param
)
12845 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12848 template_args
.push_back (arg
);
12851 process_die (child_die
, cu
);
12852 child_die
= child_die
->sibling
;
12856 inherit_abstract_dies (die
, cu
);
12858 /* If we have a DW_AT_specification, we might need to import using
12859 directives from the context of the specification DIE. See the
12860 comment in determine_prefix. */
12861 if (cu
->language
== language_cplus
12862 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12864 struct dwarf2_cu
*spec_cu
= cu
;
12865 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12869 child_die
= spec_die
->child
;
12870 while (child_die
&& child_die
->tag
)
12872 if (child_die
->tag
== DW_TAG_imported_module
)
12873 process_die (child_die
, spec_cu
);
12874 child_die
= child_die
->sibling
;
12877 /* In some cases, GCC generates specification DIEs that
12878 themselves contain DW_AT_specification attributes. */
12879 spec_die
= die_specification (spec_die
, &spec_cu
);
12883 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12884 /* Make a block for the local symbols within. */
12885 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12886 cstk
.static_link
, lowpc
, highpc
);
12888 /* For C++, set the block's scope. */
12889 if ((cu
->language
== language_cplus
12890 || cu
->language
== language_fortran
12891 || cu
->language
== language_d
12892 || cu
->language
== language_rust
)
12893 && cu
->processing_has_namespace_info
)
12894 block_set_scope (block
, determine_prefix (die
, cu
),
12895 &objfile
->objfile_obstack
);
12897 /* If we have address ranges, record them. */
12898 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12900 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12902 /* Attach template arguments to function. */
12903 if (!template_args
.empty ())
12905 gdb_assert (templ_func
!= NULL
);
12907 templ_func
->n_template_arguments
= template_args
.size ();
12908 templ_func
->template_arguments
12909 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12910 templ_func
->n_template_arguments
);
12911 memcpy (templ_func
->template_arguments
,
12912 template_args
.data (),
12913 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12915 /* Make sure that the symtab is set on the new symbols. Even
12916 though they don't appear in this symtab directly, other parts
12917 of gdb assume that symbols do, and this is reasonably
12919 for (symbol
*sym
: template_args
)
12920 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12923 /* In C++, we can have functions nested inside functions (e.g., when
12924 a function declares a class that has methods). This means that
12925 when we finish processing a function scope, we may need to go
12926 back to building a containing block's symbol lists. */
12927 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12928 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12930 /* If we've finished processing a top-level function, subsequent
12931 symbols go in the file symbol list. */
12932 if (cu
->get_builder ()->outermost_context_p ())
12933 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12936 /* Process all the DIES contained within a lexical block scope. Start
12937 a new scope, process the dies, and then close the scope. */
12940 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12942 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12943 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12944 CORE_ADDR lowpc
, highpc
;
12945 struct die_info
*child_die
;
12946 CORE_ADDR baseaddr
;
12948 baseaddr
= objfile
->text_section_offset ();
12950 /* Ignore blocks with missing or invalid low and high pc attributes. */
12951 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12952 as multiple lexical blocks? Handling children in a sane way would
12953 be nasty. Might be easier to properly extend generic blocks to
12954 describe ranges. */
12955 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
12957 case PC_BOUNDS_NOT_PRESENT
:
12958 /* DW_TAG_lexical_block has no attributes, process its children as if
12959 there was no wrapping by that DW_TAG_lexical_block.
12960 GCC does no longer produces such DWARF since GCC r224161. */
12961 for (child_die
= die
->child
;
12962 child_die
!= NULL
&& child_die
->tag
;
12963 child_die
= child_die
->sibling
)
12964 process_die (child_die
, cu
);
12966 case PC_BOUNDS_INVALID
:
12969 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12970 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12972 cu
->get_builder ()->push_context (0, lowpc
);
12973 if (die
->child
!= NULL
)
12975 child_die
= die
->child
;
12976 while (child_die
&& child_die
->tag
)
12978 process_die (child_die
, cu
);
12979 child_die
= child_die
->sibling
;
12982 inherit_abstract_dies (die
, cu
);
12983 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12985 if (*cu
->get_builder ()->get_local_symbols () != NULL
12986 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
12988 struct block
*block
12989 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
12990 cstk
.start_addr
, highpc
);
12992 /* Note that recording ranges after traversing children, as we
12993 do here, means that recording a parent's ranges entails
12994 walking across all its children's ranges as they appear in
12995 the address map, which is quadratic behavior.
12997 It would be nicer to record the parent's ranges before
12998 traversing its children, simply overriding whatever you find
12999 there. But since we don't even decide whether to create a
13000 block until after we've traversed its children, that's hard
13002 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13004 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13005 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13008 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13011 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13013 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13014 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13015 CORE_ADDR pc
, baseaddr
;
13016 struct attribute
*attr
;
13017 struct call_site
*call_site
, call_site_local
;
13020 struct die_info
*child_die
;
13022 baseaddr
= objfile
->text_section_offset ();
13024 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13027 /* This was a pre-DWARF-5 GNU extension alias
13028 for DW_AT_call_return_pc. */
13029 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13033 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13034 "DIE %s [in module %s]"),
13035 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13038 pc
= attr
->value_as_address () + baseaddr
;
13039 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13041 if (cu
->call_site_htab
== NULL
)
13042 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13043 NULL
, &objfile
->objfile_obstack
,
13044 hashtab_obstack_allocate
, NULL
);
13045 call_site_local
.pc
= pc
;
13046 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13049 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13050 "DIE %s [in module %s]"),
13051 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13052 objfile_name (objfile
));
13056 /* Count parameters at the caller. */
13059 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13060 child_die
= child_die
->sibling
)
13062 if (child_die
->tag
!= DW_TAG_call_site_parameter
13063 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13065 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13066 "DW_TAG_call_site child DIE %s [in module %s]"),
13067 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13068 objfile_name (objfile
));
13076 = ((struct call_site
*)
13077 obstack_alloc (&objfile
->objfile_obstack
,
13078 sizeof (*call_site
)
13079 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13081 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13082 call_site
->pc
= pc
;
13084 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13085 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13087 struct die_info
*func_die
;
13089 /* Skip also over DW_TAG_inlined_subroutine. */
13090 for (func_die
= die
->parent
;
13091 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13092 && func_die
->tag
!= DW_TAG_subroutine_type
;
13093 func_die
= func_die
->parent
);
13095 /* DW_AT_call_all_calls is a superset
13096 of DW_AT_call_all_tail_calls. */
13098 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13099 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13100 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13101 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13103 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13104 not complete. But keep CALL_SITE for look ups via call_site_htab,
13105 both the initial caller containing the real return address PC and
13106 the final callee containing the current PC of a chain of tail
13107 calls do not need to have the tail call list complete. But any
13108 function candidate for a virtual tail call frame searched via
13109 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13110 determined unambiguously. */
13114 struct type
*func_type
= NULL
;
13117 func_type
= get_die_type (func_die
, cu
);
13118 if (func_type
!= NULL
)
13120 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13122 /* Enlist this call site to the function. */
13123 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13124 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13127 complaint (_("Cannot find function owning DW_TAG_call_site "
13128 "DIE %s [in module %s]"),
13129 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13133 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13135 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13137 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13140 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13141 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13143 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13144 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13145 /* Keep NULL DWARF_BLOCK. */;
13146 else if (attr
->form_is_block ())
13148 struct dwarf2_locexpr_baton
*dlbaton
;
13150 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13151 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13152 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13153 dlbaton
->per_cu
= cu
->per_cu
;
13155 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13157 else if (attr
->form_is_ref ())
13159 struct dwarf2_cu
*target_cu
= cu
;
13160 struct die_info
*target_die
;
13162 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13163 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13164 if (die_is_declaration (target_die
, target_cu
))
13166 const char *target_physname
;
13168 /* Prefer the mangled name; otherwise compute the demangled one. */
13169 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13170 if (target_physname
== NULL
)
13171 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13172 if (target_physname
== NULL
)
13173 complaint (_("DW_AT_call_target target DIE has invalid "
13174 "physname, for referencing DIE %s [in module %s]"),
13175 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13177 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13183 /* DW_AT_entry_pc should be preferred. */
13184 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13185 <= PC_BOUNDS_INVALID
)
13186 complaint (_("DW_AT_call_target target DIE has invalid "
13187 "low pc, for referencing DIE %s [in module %s]"),
13188 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13191 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13192 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13197 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13198 "block nor reference, for DIE %s [in module %s]"),
13199 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13201 call_site
->per_cu
= cu
->per_cu
;
13203 for (child_die
= die
->child
;
13204 child_die
&& child_die
->tag
;
13205 child_die
= child_die
->sibling
)
13207 struct call_site_parameter
*parameter
;
13208 struct attribute
*loc
, *origin
;
13210 if (child_die
->tag
!= DW_TAG_call_site_parameter
13211 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13213 /* Already printed the complaint above. */
13217 gdb_assert (call_site
->parameter_count
< nparams
);
13218 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13220 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13221 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13222 register is contained in DW_AT_call_value. */
13224 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13225 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13226 if (origin
== NULL
)
13228 /* This was a pre-DWARF-5 GNU extension alias
13229 for DW_AT_call_parameter. */
13230 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13232 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13234 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13236 sect_offset sect_off
13237 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13238 if (!cu
->header
.offset_in_cu_p (sect_off
))
13240 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13241 binding can be done only inside one CU. Such referenced DIE
13242 therefore cannot be even moved to DW_TAG_partial_unit. */
13243 complaint (_("DW_AT_call_parameter offset is not in CU for "
13244 "DW_TAG_call_site child DIE %s [in module %s]"),
13245 sect_offset_str (child_die
->sect_off
),
13246 objfile_name (objfile
));
13249 parameter
->u
.param_cu_off
13250 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13252 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13254 complaint (_("No DW_FORM_block* DW_AT_location for "
13255 "DW_TAG_call_site child DIE %s [in module %s]"),
13256 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13261 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13262 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13263 if (parameter
->u
.dwarf_reg
!= -1)
13264 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13265 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13266 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13267 ¶meter
->u
.fb_offset
))
13268 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13271 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13272 "for DW_FORM_block* DW_AT_location is supported for "
13273 "DW_TAG_call_site child DIE %s "
13275 sect_offset_str (child_die
->sect_off
),
13276 objfile_name (objfile
));
13281 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13283 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13284 if (attr
== NULL
|| !attr
->form_is_block ())
13286 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13287 "DW_TAG_call_site child DIE %s [in module %s]"),
13288 sect_offset_str (child_die
->sect_off
),
13289 objfile_name (objfile
));
13292 parameter
->value
= DW_BLOCK (attr
)->data
;
13293 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13295 /* Parameters are not pre-cleared by memset above. */
13296 parameter
->data_value
= NULL
;
13297 parameter
->data_value_size
= 0;
13298 call_site
->parameter_count
++;
13300 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13302 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13303 if (attr
!= nullptr)
13305 if (!attr
->form_is_block ())
13306 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13307 "DW_TAG_call_site child DIE %s [in module %s]"),
13308 sect_offset_str (child_die
->sect_off
),
13309 objfile_name (objfile
));
13312 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13313 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13319 /* Helper function for read_variable. If DIE represents a virtual
13320 table, then return the type of the concrete object that is
13321 associated with the virtual table. Otherwise, return NULL. */
13323 static struct type
*
13324 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13326 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13330 /* Find the type DIE. */
13331 struct die_info
*type_die
= NULL
;
13332 struct dwarf2_cu
*type_cu
= cu
;
13334 if (attr
->form_is_ref ())
13335 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13336 if (type_die
== NULL
)
13339 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13341 return die_containing_type (type_die
, type_cu
);
13344 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13347 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13349 struct rust_vtable_symbol
*storage
= NULL
;
13351 if (cu
->language
== language_rust
)
13353 struct type
*containing_type
= rust_containing_type (die
, cu
);
13355 if (containing_type
!= NULL
)
13357 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13359 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13360 initialize_objfile_symbol (storage
);
13361 storage
->concrete_type
= containing_type
;
13362 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13366 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13367 struct attribute
*abstract_origin
13368 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13369 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13370 if (res
== NULL
&& loc
&& abstract_origin
)
13372 /* We have a variable without a name, but with a location and an abstract
13373 origin. This may be a concrete instance of an abstract variable
13374 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13376 struct dwarf2_cu
*origin_cu
= cu
;
13377 struct die_info
*origin_die
13378 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13379 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13380 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13384 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13385 reading .debug_rnglists.
13386 Callback's type should be:
13387 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13388 Return true if the attributes are present and valid, otherwise,
13391 template <typename Callback
>
13393 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13394 Callback
&&callback
)
13396 struct dwarf2_per_objfile
*dwarf2_per_objfile
13397 = cu
->per_cu
->dwarf2_per_objfile
;
13398 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13399 bfd
*obfd
= objfile
->obfd
;
13400 /* Base address selection entry. */
13401 gdb::optional
<CORE_ADDR
> base
;
13402 const gdb_byte
*buffer
;
13403 CORE_ADDR baseaddr
;
13404 bool overflow
= false;
13406 base
= cu
->base_address
;
13408 dwarf2_per_objfile
->rnglists
.read (objfile
);
13409 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13411 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13415 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13417 baseaddr
= objfile
->text_section_offset ();
13421 /* Initialize it due to a false compiler warning. */
13422 CORE_ADDR range_beginning
= 0, range_end
= 0;
13423 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13424 + dwarf2_per_objfile
->rnglists
.size
);
13425 unsigned int bytes_read
;
13427 if (buffer
== buf_end
)
13432 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13435 case DW_RLE_end_of_list
:
13437 case DW_RLE_base_address
:
13438 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13443 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13444 buffer
+= bytes_read
;
13446 case DW_RLE_start_length
:
13447 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13452 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13454 buffer
+= bytes_read
;
13455 range_end
= (range_beginning
13456 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13457 buffer
+= bytes_read
;
13458 if (buffer
> buf_end
)
13464 case DW_RLE_offset_pair
:
13465 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13466 buffer
+= bytes_read
;
13467 if (buffer
> buf_end
)
13472 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13473 buffer
+= bytes_read
;
13474 if (buffer
> buf_end
)
13480 case DW_RLE_start_end
:
13481 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13486 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13488 buffer
+= bytes_read
;
13489 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13490 buffer
+= bytes_read
;
13493 complaint (_("Invalid .debug_rnglists data (no base address)"));
13496 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13498 if (rlet
== DW_RLE_base_address
)
13501 if (!base
.has_value ())
13503 /* We have no valid base address for the ranges
13505 complaint (_("Invalid .debug_rnglists data (no base address)"));
13509 if (range_beginning
> range_end
)
13511 /* Inverted range entries are invalid. */
13512 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13516 /* Empty range entries have no effect. */
13517 if (range_beginning
== range_end
)
13520 range_beginning
+= *base
;
13521 range_end
+= *base
;
13523 /* A not-uncommon case of bad debug info.
13524 Don't pollute the addrmap with bad data. */
13525 if (range_beginning
+ baseaddr
== 0
13526 && !dwarf2_per_objfile
->has_section_at_zero
)
13528 complaint (_(".debug_rnglists entry has start address of zero"
13529 " [in module %s]"), objfile_name (objfile
));
13533 callback (range_beginning
, range_end
);
13538 complaint (_("Offset %d is not terminated "
13539 "for DW_AT_ranges attribute"),
13547 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13548 Callback's type should be:
13549 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13550 Return 1 if the attributes are present and valid, otherwise, return 0. */
13552 template <typename Callback
>
13554 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13555 Callback
&&callback
)
13557 struct dwarf2_per_objfile
*dwarf2_per_objfile
13558 = cu
->per_cu
->dwarf2_per_objfile
;
13559 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13560 struct comp_unit_head
*cu_header
= &cu
->header
;
13561 bfd
*obfd
= objfile
->obfd
;
13562 unsigned int addr_size
= cu_header
->addr_size
;
13563 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13564 /* Base address selection entry. */
13565 gdb::optional
<CORE_ADDR
> base
;
13566 unsigned int dummy
;
13567 const gdb_byte
*buffer
;
13568 CORE_ADDR baseaddr
;
13570 if (cu_header
->version
>= 5)
13571 return dwarf2_rnglists_process (offset
, cu
, callback
);
13573 base
= cu
->base_address
;
13575 dwarf2_per_objfile
->ranges
.read (objfile
);
13576 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13578 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13582 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13584 baseaddr
= objfile
->text_section_offset ();
13588 CORE_ADDR range_beginning
, range_end
;
13590 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13591 buffer
+= addr_size
;
13592 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13593 buffer
+= addr_size
;
13594 offset
+= 2 * addr_size
;
13596 /* An end of list marker is a pair of zero addresses. */
13597 if (range_beginning
== 0 && range_end
== 0)
13598 /* Found the end of list entry. */
13601 /* Each base address selection entry is a pair of 2 values.
13602 The first is the largest possible address, the second is
13603 the base address. Check for a base address here. */
13604 if ((range_beginning
& mask
) == mask
)
13606 /* If we found the largest possible address, then we already
13607 have the base address in range_end. */
13612 if (!base
.has_value ())
13614 /* We have no valid base address for the ranges
13616 complaint (_("Invalid .debug_ranges data (no base address)"));
13620 if (range_beginning
> range_end
)
13622 /* Inverted range entries are invalid. */
13623 complaint (_("Invalid .debug_ranges data (inverted range)"));
13627 /* Empty range entries have no effect. */
13628 if (range_beginning
== range_end
)
13631 range_beginning
+= *base
;
13632 range_end
+= *base
;
13634 /* A not-uncommon case of bad debug info.
13635 Don't pollute the addrmap with bad data. */
13636 if (range_beginning
+ baseaddr
== 0
13637 && !dwarf2_per_objfile
->has_section_at_zero
)
13639 complaint (_(".debug_ranges entry has start address of zero"
13640 " [in module %s]"), objfile_name (objfile
));
13644 callback (range_beginning
, range_end
);
13650 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13651 Return 1 if the attributes are present and valid, otherwise, return 0.
13652 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13655 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13656 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13657 dwarf2_psymtab
*ranges_pst
)
13659 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13660 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13661 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13664 CORE_ADDR high
= 0;
13667 retval
= dwarf2_ranges_process (offset
, cu
,
13668 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13670 if (ranges_pst
!= NULL
)
13675 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13676 range_beginning
+ baseaddr
)
13678 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13679 range_end
+ baseaddr
)
13681 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13682 lowpc
, highpc
- 1, ranges_pst
);
13685 /* FIXME: This is recording everything as a low-high
13686 segment of consecutive addresses. We should have a
13687 data structure for discontiguous block ranges
13691 low
= range_beginning
;
13697 if (range_beginning
< low
)
13698 low
= range_beginning
;
13699 if (range_end
> high
)
13707 /* If the first entry is an end-of-list marker, the range
13708 describes an empty scope, i.e. no instructions. */
13714 *high_return
= high
;
13718 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13719 definition for the return value. *LOWPC and *HIGHPC are set iff
13720 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13722 static enum pc_bounds_kind
13723 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13724 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13725 dwarf2_psymtab
*pst
)
13727 struct dwarf2_per_objfile
*dwarf2_per_objfile
13728 = cu
->per_cu
->dwarf2_per_objfile
;
13729 struct attribute
*attr
;
13730 struct attribute
*attr_high
;
13732 CORE_ADDR high
= 0;
13733 enum pc_bounds_kind ret
;
13735 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13738 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13739 if (attr
!= nullptr)
13741 low
= attr
->value_as_address ();
13742 high
= attr_high
->value_as_address ();
13743 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13747 /* Found high w/o low attribute. */
13748 return PC_BOUNDS_INVALID
;
13750 /* Found consecutive range of addresses. */
13751 ret
= PC_BOUNDS_HIGH_LOW
;
13755 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13758 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13759 We take advantage of the fact that DW_AT_ranges does not appear
13760 in DW_TAG_compile_unit of DWO files. */
13761 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13762 unsigned int ranges_offset
= (DW_UNSND (attr
)
13763 + (need_ranges_base
13767 /* Value of the DW_AT_ranges attribute is the offset in the
13768 .debug_ranges section. */
13769 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13770 return PC_BOUNDS_INVALID
;
13771 /* Found discontinuous range of addresses. */
13772 ret
= PC_BOUNDS_RANGES
;
13775 return PC_BOUNDS_NOT_PRESENT
;
13778 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13780 return PC_BOUNDS_INVALID
;
13782 /* When using the GNU linker, .gnu.linkonce. sections are used to
13783 eliminate duplicate copies of functions and vtables and such.
13784 The linker will arbitrarily choose one and discard the others.
13785 The AT_*_pc values for such functions refer to local labels in
13786 these sections. If the section from that file was discarded, the
13787 labels are not in the output, so the relocs get a value of 0.
13788 If this is a discarded function, mark the pc bounds as invalid,
13789 so that GDB will ignore it. */
13790 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13791 return PC_BOUNDS_INVALID
;
13799 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13800 its low and high PC addresses. Do nothing if these addresses could not
13801 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13802 and HIGHPC to the high address if greater than HIGHPC. */
13805 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13806 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13807 struct dwarf2_cu
*cu
)
13809 CORE_ADDR low
, high
;
13810 struct die_info
*child
= die
->child
;
13812 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13814 *lowpc
= std::min (*lowpc
, low
);
13815 *highpc
= std::max (*highpc
, high
);
13818 /* If the language does not allow nested subprograms (either inside
13819 subprograms or lexical blocks), we're done. */
13820 if (cu
->language
!= language_ada
)
13823 /* Check all the children of the given DIE. If it contains nested
13824 subprograms, then check their pc bounds. Likewise, we need to
13825 check lexical blocks as well, as they may also contain subprogram
13827 while (child
&& child
->tag
)
13829 if (child
->tag
== DW_TAG_subprogram
13830 || child
->tag
== DW_TAG_lexical_block
)
13831 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13832 child
= child
->sibling
;
13836 /* Get the low and high pc's represented by the scope DIE, and store
13837 them in *LOWPC and *HIGHPC. If the correct values can't be
13838 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13841 get_scope_pc_bounds (struct die_info
*die
,
13842 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13843 struct dwarf2_cu
*cu
)
13845 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13846 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13847 CORE_ADDR current_low
, current_high
;
13849 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13850 >= PC_BOUNDS_RANGES
)
13852 best_low
= current_low
;
13853 best_high
= current_high
;
13857 struct die_info
*child
= die
->child
;
13859 while (child
&& child
->tag
)
13861 switch (child
->tag
) {
13862 case DW_TAG_subprogram
:
13863 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13865 case DW_TAG_namespace
:
13866 case DW_TAG_module
:
13867 /* FIXME: carlton/2004-01-16: Should we do this for
13868 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13869 that current GCC's always emit the DIEs corresponding
13870 to definitions of methods of classes as children of a
13871 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13872 the DIEs giving the declarations, which could be
13873 anywhere). But I don't see any reason why the
13874 standards says that they have to be there. */
13875 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13877 if (current_low
!= ((CORE_ADDR
) -1))
13879 best_low
= std::min (best_low
, current_low
);
13880 best_high
= std::max (best_high
, current_high
);
13888 child
= child
->sibling
;
13893 *highpc
= best_high
;
13896 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13900 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13901 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13903 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13904 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13905 struct attribute
*attr
;
13906 struct attribute
*attr_high
;
13908 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13911 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13912 if (attr
!= nullptr)
13914 CORE_ADDR low
= attr
->value_as_address ();
13915 CORE_ADDR high
= attr_high
->value_as_address ();
13917 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13920 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13921 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13922 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13926 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13927 if (attr
!= nullptr)
13929 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13930 We take advantage of the fact that DW_AT_ranges does not appear
13931 in DW_TAG_compile_unit of DWO files. */
13932 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13934 /* The value of the DW_AT_ranges attribute is the offset of the
13935 address range list in the .debug_ranges section. */
13936 unsigned long offset
= (DW_UNSND (attr
)
13937 + (need_ranges_base
? cu
->ranges_base
: 0));
13939 std::vector
<blockrange
> blockvec
;
13940 dwarf2_ranges_process (offset
, cu
,
13941 [&] (CORE_ADDR start
, CORE_ADDR end
)
13945 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
13946 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
13947 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
13948 blockvec
.emplace_back (start
, end
);
13951 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
13955 /* Check whether the producer field indicates either of GCC < 4.6, or the
13956 Intel C/C++ compiler, and cache the result in CU. */
13959 check_producer (struct dwarf2_cu
*cu
)
13963 if (cu
->producer
== NULL
)
13965 /* For unknown compilers expect their behavior is DWARF version
13968 GCC started to support .debug_types sections by -gdwarf-4 since
13969 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
13970 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
13971 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
13972 interpreted incorrectly by GDB now - GCC PR debug/48229. */
13974 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
13976 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
13977 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
13979 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
13981 cu
->producer_is_icc
= true;
13982 cu
->producer_is_icc_lt_14
= major
< 14;
13984 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
13985 cu
->producer_is_codewarrior
= true;
13988 /* For other non-GCC compilers, expect their behavior is DWARF version
13992 cu
->checked_producer
= true;
13995 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
13996 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
13997 during 4.6.0 experimental. */
14000 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14002 if (!cu
->checked_producer
)
14003 check_producer (cu
);
14005 return cu
->producer_is_gxx_lt_4_6
;
14009 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14010 with incorrect is_stmt attributes. */
14013 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14015 if (!cu
->checked_producer
)
14016 check_producer (cu
);
14018 return cu
->producer_is_codewarrior
;
14021 /* Return the default accessibility type if it is not overridden by
14022 DW_AT_accessibility. */
14024 static enum dwarf_access_attribute
14025 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14027 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14029 /* The default DWARF 2 accessibility for members is public, the default
14030 accessibility for inheritance is private. */
14032 if (die
->tag
!= DW_TAG_inheritance
)
14033 return DW_ACCESS_public
;
14035 return DW_ACCESS_private
;
14039 /* DWARF 3+ defines the default accessibility a different way. The same
14040 rules apply now for DW_TAG_inheritance as for the members and it only
14041 depends on the container kind. */
14043 if (die
->parent
->tag
== DW_TAG_class_type
)
14044 return DW_ACCESS_private
;
14046 return DW_ACCESS_public
;
14050 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14051 offset. If the attribute was not found return 0, otherwise return
14052 1. If it was found but could not properly be handled, set *OFFSET
14056 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14059 struct attribute
*attr
;
14061 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14066 /* Note that we do not check for a section offset first here.
14067 This is because DW_AT_data_member_location is new in DWARF 4,
14068 so if we see it, we can assume that a constant form is really
14069 a constant and not a section offset. */
14070 if (attr
->form_is_constant ())
14071 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14072 else if (attr
->form_is_section_offset ())
14073 dwarf2_complex_location_expr_complaint ();
14074 else if (attr
->form_is_block ())
14075 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14077 dwarf2_complex_location_expr_complaint ();
14085 /* Add an aggregate field to the field list. */
14088 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14089 struct dwarf2_cu
*cu
)
14091 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14092 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14093 struct nextfield
*new_field
;
14094 struct attribute
*attr
;
14096 const char *fieldname
= "";
14098 if (die
->tag
== DW_TAG_inheritance
)
14100 fip
->baseclasses
.emplace_back ();
14101 new_field
= &fip
->baseclasses
.back ();
14105 fip
->fields
.emplace_back ();
14106 new_field
= &fip
->fields
.back ();
14109 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14110 if (attr
!= nullptr)
14111 new_field
->accessibility
= DW_UNSND (attr
);
14113 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14114 if (new_field
->accessibility
!= DW_ACCESS_public
)
14115 fip
->non_public_fields
= 1;
14117 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14118 if (attr
!= nullptr)
14119 new_field
->virtuality
= DW_UNSND (attr
);
14121 new_field
->virtuality
= DW_VIRTUALITY_none
;
14123 fp
= &new_field
->field
;
14125 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14129 /* Data member other than a C++ static data member. */
14131 /* Get type of field. */
14132 fp
->type
= die_type (die
, cu
);
14134 SET_FIELD_BITPOS (*fp
, 0);
14136 /* Get bit size of field (zero if none). */
14137 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14138 if (attr
!= nullptr)
14140 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14144 FIELD_BITSIZE (*fp
) = 0;
14147 /* Get bit offset of field. */
14148 if (handle_data_member_location (die
, cu
, &offset
))
14149 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14150 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14151 if (attr
!= nullptr)
14153 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14155 /* For big endian bits, the DW_AT_bit_offset gives the
14156 additional bit offset from the MSB of the containing
14157 anonymous object to the MSB of the field. We don't
14158 have to do anything special since we don't need to
14159 know the size of the anonymous object. */
14160 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14164 /* For little endian bits, compute the bit offset to the
14165 MSB of the anonymous object, subtract off the number of
14166 bits from the MSB of the field to the MSB of the
14167 object, and then subtract off the number of bits of
14168 the field itself. The result is the bit offset of
14169 the LSB of the field. */
14170 int anonymous_size
;
14171 int bit_offset
= DW_UNSND (attr
);
14173 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14174 if (attr
!= nullptr)
14176 /* The size of the anonymous object containing
14177 the bit field is explicit, so use the
14178 indicated size (in bytes). */
14179 anonymous_size
= DW_UNSND (attr
);
14183 /* The size of the anonymous object containing
14184 the bit field must be inferred from the type
14185 attribute of the data member containing the
14187 anonymous_size
= TYPE_LENGTH (fp
->type
);
14189 SET_FIELD_BITPOS (*fp
,
14190 (FIELD_BITPOS (*fp
)
14191 + anonymous_size
* bits_per_byte
14192 - bit_offset
- FIELD_BITSIZE (*fp
)));
14195 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14197 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14198 + dwarf2_get_attr_constant_value (attr
, 0)));
14200 /* Get name of field. */
14201 fieldname
= dwarf2_name (die
, cu
);
14202 if (fieldname
== NULL
)
14205 /* The name is already allocated along with this objfile, so we don't
14206 need to duplicate it for the type. */
14207 fp
->name
= fieldname
;
14209 /* Change accessibility for artificial fields (e.g. virtual table
14210 pointer or virtual base class pointer) to private. */
14211 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14213 FIELD_ARTIFICIAL (*fp
) = 1;
14214 new_field
->accessibility
= DW_ACCESS_private
;
14215 fip
->non_public_fields
= 1;
14218 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14220 /* C++ static member. */
14222 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14223 is a declaration, but all versions of G++ as of this writing
14224 (so through at least 3.2.1) incorrectly generate
14225 DW_TAG_variable tags. */
14227 const char *physname
;
14229 /* Get name of field. */
14230 fieldname
= dwarf2_name (die
, cu
);
14231 if (fieldname
== NULL
)
14234 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14236 /* Only create a symbol if this is an external value.
14237 new_symbol checks this and puts the value in the global symbol
14238 table, which we want. If it is not external, new_symbol
14239 will try to put the value in cu->list_in_scope which is wrong. */
14240 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14242 /* A static const member, not much different than an enum as far as
14243 we're concerned, except that we can support more types. */
14244 new_symbol (die
, NULL
, cu
);
14247 /* Get physical name. */
14248 physname
= dwarf2_physname (fieldname
, die
, cu
);
14250 /* The name is already allocated along with this objfile, so we don't
14251 need to duplicate it for the type. */
14252 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14253 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14254 FIELD_NAME (*fp
) = fieldname
;
14256 else if (die
->tag
== DW_TAG_inheritance
)
14260 /* C++ base class field. */
14261 if (handle_data_member_location (die
, cu
, &offset
))
14262 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14263 FIELD_BITSIZE (*fp
) = 0;
14264 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14265 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14267 else if (die
->tag
== DW_TAG_variant_part
)
14269 /* process_structure_scope will treat this DIE as a union. */
14270 process_structure_scope (die
, cu
);
14272 /* The variant part is relative to the start of the enclosing
14274 SET_FIELD_BITPOS (*fp
, 0);
14275 fp
->type
= get_die_type (die
, cu
);
14276 fp
->artificial
= 1;
14277 fp
->name
= "<<variant>>";
14279 /* Normally a DW_TAG_variant_part won't have a size, but our
14280 representation requires one, so set it to the maximum of the
14281 child sizes, being sure to account for the offset at which
14282 each child is seen. */
14283 if (TYPE_LENGTH (fp
->type
) == 0)
14286 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14288 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14289 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14293 TYPE_LENGTH (fp
->type
) = max
;
14297 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14300 /* Can the type given by DIE define another type? */
14303 type_can_define_types (const struct die_info
*die
)
14307 case DW_TAG_typedef
:
14308 case DW_TAG_class_type
:
14309 case DW_TAG_structure_type
:
14310 case DW_TAG_union_type
:
14311 case DW_TAG_enumeration_type
:
14319 /* Add a type definition defined in the scope of the FIP's class. */
14322 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14323 struct dwarf2_cu
*cu
)
14325 struct decl_field fp
;
14326 memset (&fp
, 0, sizeof (fp
));
14328 gdb_assert (type_can_define_types (die
));
14330 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14331 fp
.name
= dwarf2_name (die
, cu
);
14332 fp
.type
= read_type_die (die
, cu
);
14334 /* Save accessibility. */
14335 enum dwarf_access_attribute accessibility
;
14336 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14338 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14340 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14341 switch (accessibility
)
14343 case DW_ACCESS_public
:
14344 /* The assumed value if neither private nor protected. */
14346 case DW_ACCESS_private
:
14349 case DW_ACCESS_protected
:
14350 fp
.is_protected
= 1;
14353 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14356 if (die
->tag
== DW_TAG_typedef
)
14357 fip
->typedef_field_list
.push_back (fp
);
14359 fip
->nested_types_list
.push_back (fp
);
14362 /* Create the vector of fields, and attach it to the type. */
14365 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14366 struct dwarf2_cu
*cu
)
14368 int nfields
= fip
->nfields ();
14370 /* Record the field count, allocate space for the array of fields,
14371 and create blank accessibility bitfields if necessary. */
14372 TYPE_NFIELDS (type
) = nfields
;
14373 TYPE_FIELDS (type
) = (struct field
*)
14374 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14376 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14378 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14380 TYPE_FIELD_PRIVATE_BITS (type
) =
14381 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14382 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14384 TYPE_FIELD_PROTECTED_BITS (type
) =
14385 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14386 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14388 TYPE_FIELD_IGNORE_BITS (type
) =
14389 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14390 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14393 /* If the type has baseclasses, allocate and clear a bit vector for
14394 TYPE_FIELD_VIRTUAL_BITS. */
14395 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14397 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14398 unsigned char *pointer
;
14400 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14401 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14402 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14403 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14404 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14407 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14409 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14411 for (int index
= 0; index
< nfields
; ++index
)
14413 struct nextfield
&field
= fip
->fields
[index
];
14415 if (field
.variant
.is_discriminant
)
14416 di
->discriminant_index
= index
;
14417 else if (field
.variant
.default_branch
)
14418 di
->default_index
= index
;
14420 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14424 /* Copy the saved-up fields into the field vector. */
14425 for (int i
= 0; i
< nfields
; ++i
)
14427 struct nextfield
&field
14428 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14429 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14431 TYPE_FIELD (type
, i
) = field
.field
;
14432 switch (field
.accessibility
)
14434 case DW_ACCESS_private
:
14435 if (cu
->language
!= language_ada
)
14436 SET_TYPE_FIELD_PRIVATE (type
, i
);
14439 case DW_ACCESS_protected
:
14440 if (cu
->language
!= language_ada
)
14441 SET_TYPE_FIELD_PROTECTED (type
, i
);
14444 case DW_ACCESS_public
:
14448 /* Unknown accessibility. Complain and treat it as public. */
14450 complaint (_("unsupported accessibility %d"),
14451 field
.accessibility
);
14455 if (i
< fip
->baseclasses
.size ())
14457 switch (field
.virtuality
)
14459 case DW_VIRTUALITY_virtual
:
14460 case DW_VIRTUALITY_pure_virtual
:
14461 if (cu
->language
== language_ada
)
14462 error (_("unexpected virtuality in component of Ada type"));
14463 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14470 /* Return true if this member function is a constructor, false
14474 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14476 const char *fieldname
;
14477 const char *type_name
;
14480 if (die
->parent
== NULL
)
14483 if (die
->parent
->tag
!= DW_TAG_structure_type
14484 && die
->parent
->tag
!= DW_TAG_union_type
14485 && die
->parent
->tag
!= DW_TAG_class_type
)
14488 fieldname
= dwarf2_name (die
, cu
);
14489 type_name
= dwarf2_name (die
->parent
, cu
);
14490 if (fieldname
== NULL
|| type_name
== NULL
)
14493 len
= strlen (fieldname
);
14494 return (strncmp (fieldname
, type_name
, len
) == 0
14495 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14498 /* Check if the given VALUE is a recognized enum
14499 dwarf_defaulted_attribute constant according to DWARF5 spec,
14503 is_valid_DW_AT_defaulted (ULONGEST value
)
14507 case DW_DEFAULTED_no
:
14508 case DW_DEFAULTED_in_class
:
14509 case DW_DEFAULTED_out_of_class
:
14513 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14517 /* Add a member function to the proper fieldlist. */
14520 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14521 struct type
*type
, struct dwarf2_cu
*cu
)
14523 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14524 struct attribute
*attr
;
14526 struct fnfieldlist
*flp
= nullptr;
14527 struct fn_field
*fnp
;
14528 const char *fieldname
;
14529 struct type
*this_type
;
14530 enum dwarf_access_attribute accessibility
;
14532 if (cu
->language
== language_ada
)
14533 error (_("unexpected member function in Ada type"));
14535 /* Get name of member function. */
14536 fieldname
= dwarf2_name (die
, cu
);
14537 if (fieldname
== NULL
)
14540 /* Look up member function name in fieldlist. */
14541 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14543 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14545 flp
= &fip
->fnfieldlists
[i
];
14550 /* Create a new fnfieldlist if necessary. */
14551 if (flp
== nullptr)
14553 fip
->fnfieldlists
.emplace_back ();
14554 flp
= &fip
->fnfieldlists
.back ();
14555 flp
->name
= fieldname
;
14556 i
= fip
->fnfieldlists
.size () - 1;
14559 /* Create a new member function field and add it to the vector of
14561 flp
->fnfields
.emplace_back ();
14562 fnp
= &flp
->fnfields
.back ();
14564 /* Delay processing of the physname until later. */
14565 if (cu
->language
== language_cplus
)
14566 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14570 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14571 fnp
->physname
= physname
? physname
: "";
14574 fnp
->type
= alloc_type (objfile
);
14575 this_type
= read_type_die (die
, cu
);
14576 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14578 int nparams
= TYPE_NFIELDS (this_type
);
14580 /* TYPE is the domain of this method, and THIS_TYPE is the type
14581 of the method itself (TYPE_CODE_METHOD). */
14582 smash_to_method_type (fnp
->type
, type
,
14583 TYPE_TARGET_TYPE (this_type
),
14584 TYPE_FIELDS (this_type
),
14585 TYPE_NFIELDS (this_type
),
14586 TYPE_VARARGS (this_type
));
14588 /* Handle static member functions.
14589 Dwarf2 has no clean way to discern C++ static and non-static
14590 member functions. G++ helps GDB by marking the first
14591 parameter for non-static member functions (which is the this
14592 pointer) as artificial. We obtain this information from
14593 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14594 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14595 fnp
->voffset
= VOFFSET_STATIC
;
14598 complaint (_("member function type missing for '%s'"),
14599 dwarf2_full_name (fieldname
, die
, cu
));
14601 /* Get fcontext from DW_AT_containing_type if present. */
14602 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14603 fnp
->fcontext
= die_containing_type (die
, cu
);
14605 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14606 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14608 /* Get accessibility. */
14609 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14610 if (attr
!= nullptr)
14611 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14613 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14614 switch (accessibility
)
14616 case DW_ACCESS_private
:
14617 fnp
->is_private
= 1;
14619 case DW_ACCESS_protected
:
14620 fnp
->is_protected
= 1;
14624 /* Check for artificial methods. */
14625 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14626 if (attr
&& DW_UNSND (attr
) != 0)
14627 fnp
->is_artificial
= 1;
14629 /* Check for defaulted methods. */
14630 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14631 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14632 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14634 /* Check for deleted methods. */
14635 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14636 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14637 fnp
->is_deleted
= 1;
14639 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14641 /* Get index in virtual function table if it is a virtual member
14642 function. For older versions of GCC, this is an offset in the
14643 appropriate virtual table, as specified by DW_AT_containing_type.
14644 For everyone else, it is an expression to be evaluated relative
14645 to the object address. */
14647 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14648 if (attr
!= nullptr)
14650 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14652 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14654 /* Old-style GCC. */
14655 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14657 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14658 || (DW_BLOCK (attr
)->size
> 1
14659 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14660 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14662 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14663 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14664 dwarf2_complex_location_expr_complaint ();
14666 fnp
->voffset
/= cu
->header
.addr_size
;
14670 dwarf2_complex_location_expr_complaint ();
14672 if (!fnp
->fcontext
)
14674 /* If there is no `this' field and no DW_AT_containing_type,
14675 we cannot actually find a base class context for the
14677 if (TYPE_NFIELDS (this_type
) == 0
14678 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14680 complaint (_("cannot determine context for virtual member "
14681 "function \"%s\" (offset %s)"),
14682 fieldname
, sect_offset_str (die
->sect_off
));
14687 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14691 else if (attr
->form_is_section_offset ())
14693 dwarf2_complex_location_expr_complaint ();
14697 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14703 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14704 if (attr
&& DW_UNSND (attr
))
14706 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14707 complaint (_("Member function \"%s\" (offset %s) is virtual "
14708 "but the vtable offset is not specified"),
14709 fieldname
, sect_offset_str (die
->sect_off
));
14710 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14711 TYPE_CPLUS_DYNAMIC (type
) = 1;
14716 /* Create the vector of member function fields, and attach it to the type. */
14719 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14720 struct dwarf2_cu
*cu
)
14722 if (cu
->language
== language_ada
)
14723 error (_("unexpected member functions in Ada type"));
14725 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14726 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14728 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14730 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14732 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14733 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14735 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14736 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14737 fn_flp
->fn_fields
= (struct fn_field
*)
14738 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14740 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14741 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14744 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14747 /* Returns non-zero if NAME is the name of a vtable member in CU's
14748 language, zero otherwise. */
14750 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14752 static const char vptr
[] = "_vptr";
14754 /* Look for the C++ form of the vtable. */
14755 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14761 /* GCC outputs unnamed structures that are really pointers to member
14762 functions, with the ABI-specified layout. If TYPE describes
14763 such a structure, smash it into a member function type.
14765 GCC shouldn't do this; it should just output pointer to member DIEs.
14766 This is GCC PR debug/28767. */
14769 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14771 struct type
*pfn_type
, *self_type
, *new_type
;
14773 /* Check for a structure with no name and two children. */
14774 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14777 /* Check for __pfn and __delta members. */
14778 if (TYPE_FIELD_NAME (type
, 0) == NULL
14779 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14780 || TYPE_FIELD_NAME (type
, 1) == NULL
14781 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14784 /* Find the type of the method. */
14785 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14786 if (pfn_type
== NULL
14787 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14788 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14791 /* Look for the "this" argument. */
14792 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14793 if (TYPE_NFIELDS (pfn_type
) == 0
14794 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14795 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14798 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14799 new_type
= alloc_type (objfile
);
14800 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14801 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14802 TYPE_VARARGS (pfn_type
));
14803 smash_to_methodptr_type (type
, new_type
);
14806 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14807 appropriate error checking and issuing complaints if there is a
14811 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14813 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14815 if (attr
== nullptr)
14818 if (!attr
->form_is_constant ())
14820 complaint (_("DW_AT_alignment must have constant form"
14821 " - DIE at %s [in module %s]"),
14822 sect_offset_str (die
->sect_off
),
14823 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14828 if (attr
->form
== DW_FORM_sdata
)
14830 LONGEST val
= DW_SND (attr
);
14833 complaint (_("DW_AT_alignment value must not be negative"
14834 " - DIE at %s [in module %s]"),
14835 sect_offset_str (die
->sect_off
),
14836 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14842 align
= DW_UNSND (attr
);
14846 complaint (_("DW_AT_alignment value must not be zero"
14847 " - DIE at %s [in module %s]"),
14848 sect_offset_str (die
->sect_off
),
14849 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14852 if ((align
& (align
- 1)) != 0)
14854 complaint (_("DW_AT_alignment value must be a power of 2"
14855 " - DIE at %s [in module %s]"),
14856 sect_offset_str (die
->sect_off
),
14857 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14864 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14865 the alignment for TYPE. */
14868 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14871 if (!set_type_align (type
, get_alignment (cu
, die
)))
14872 complaint (_("DW_AT_alignment value too large"
14873 " - DIE at %s [in module %s]"),
14874 sect_offset_str (die
->sect_off
),
14875 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14878 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14879 constant for a type, according to DWARF5 spec, Table 5.5. */
14882 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14887 case DW_CC_pass_by_reference
:
14888 case DW_CC_pass_by_value
:
14892 complaint (_("unrecognized DW_AT_calling_convention value "
14893 "(%s) for a type"), pulongest (value
));
14898 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14899 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14900 also according to GNU-specific values (see include/dwarf2.h). */
14903 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14908 case DW_CC_program
:
14912 case DW_CC_GNU_renesas_sh
:
14913 case DW_CC_GNU_borland_fastcall_i386
:
14914 case DW_CC_GDB_IBM_OpenCL
:
14918 complaint (_("unrecognized DW_AT_calling_convention value "
14919 "(%s) for a subroutine"), pulongest (value
));
14924 /* Called when we find the DIE that starts a structure or union scope
14925 (definition) to create a type for the structure or union. Fill in
14926 the type's name and general properties; the members will not be
14927 processed until process_structure_scope. A symbol table entry for
14928 the type will also not be done until process_structure_scope (assuming
14929 the type has a name).
14931 NOTE: we need to call these functions regardless of whether or not the
14932 DIE has a DW_AT_name attribute, since it might be an anonymous
14933 structure or union. This gets the type entered into our set of
14934 user defined types. */
14936 static struct type
*
14937 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14939 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14941 struct attribute
*attr
;
14944 /* If the definition of this type lives in .debug_types, read that type.
14945 Don't follow DW_AT_specification though, that will take us back up
14946 the chain and we want to go down. */
14947 attr
= die
->attr (DW_AT_signature
);
14948 if (attr
!= nullptr)
14950 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14952 /* The type's CU may not be the same as CU.
14953 Ensure TYPE is recorded with CU in die_type_hash. */
14954 return set_die_type (die
, type
, cu
);
14957 type
= alloc_type (objfile
);
14958 INIT_CPLUS_SPECIFIC (type
);
14960 name
= dwarf2_name (die
, cu
);
14963 if (cu
->language
== language_cplus
14964 || cu
->language
== language_d
14965 || cu
->language
== language_rust
)
14967 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
14969 /* dwarf2_full_name might have already finished building the DIE's
14970 type. If so, there is no need to continue. */
14971 if (get_die_type (die
, cu
) != NULL
)
14972 return get_die_type (die
, cu
);
14974 TYPE_NAME (type
) = full_name
;
14978 /* The name is already allocated along with this objfile, so
14979 we don't need to duplicate it for the type. */
14980 TYPE_NAME (type
) = name
;
14984 if (die
->tag
== DW_TAG_structure_type
)
14986 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
14988 else if (die
->tag
== DW_TAG_union_type
)
14990 TYPE_CODE (type
) = TYPE_CODE_UNION
;
14992 else if (die
->tag
== DW_TAG_variant_part
)
14994 TYPE_CODE (type
) = TYPE_CODE_UNION
;
14995 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
14999 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15002 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15003 TYPE_DECLARED_CLASS (type
) = 1;
15005 /* Store the calling convention in the type if it's available in
15006 the die. Otherwise the calling convention remains set to
15007 the default value DW_CC_normal. */
15008 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15009 if (attr
!= nullptr
15010 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15012 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15013 TYPE_CPLUS_CALLING_CONVENTION (type
)
15014 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15017 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15018 if (attr
!= nullptr)
15020 if (attr
->form_is_constant ())
15021 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15024 /* For the moment, dynamic type sizes are not supported
15025 by GDB's struct type. The actual size is determined
15026 on-demand when resolving the type of a given object,
15027 so set the type's length to zero for now. Otherwise,
15028 we record an expression as the length, and that expression
15029 could lead to a very large value, which could eventually
15030 lead to us trying to allocate that much memory when creating
15031 a value of that type. */
15032 TYPE_LENGTH (type
) = 0;
15037 TYPE_LENGTH (type
) = 0;
15040 maybe_set_alignment (cu
, die
, type
);
15042 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15044 /* ICC<14 does not output the required DW_AT_declaration on
15045 incomplete types, but gives them a size of zero. */
15046 TYPE_STUB (type
) = 1;
15049 TYPE_STUB_SUPPORTED (type
) = 1;
15051 if (die_is_declaration (die
, cu
))
15052 TYPE_STUB (type
) = 1;
15053 else if (attr
== NULL
&& die
->child
== NULL
15054 && producer_is_realview (cu
->producer
))
15055 /* RealView does not output the required DW_AT_declaration
15056 on incomplete types. */
15057 TYPE_STUB (type
) = 1;
15059 /* We need to add the type field to the die immediately so we don't
15060 infinitely recurse when dealing with pointers to the structure
15061 type within the structure itself. */
15062 set_die_type (die
, type
, cu
);
15064 /* set_die_type should be already done. */
15065 set_descriptive_type (type
, die
, cu
);
15070 /* A helper for process_structure_scope that handles a single member
15074 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15075 struct field_info
*fi
,
15076 std::vector
<struct symbol
*> *template_args
,
15077 struct dwarf2_cu
*cu
)
15079 if (child_die
->tag
== DW_TAG_member
15080 || child_die
->tag
== DW_TAG_variable
15081 || child_die
->tag
== DW_TAG_variant_part
)
15083 /* NOTE: carlton/2002-11-05: A C++ static data member
15084 should be a DW_TAG_member that is a declaration, but
15085 all versions of G++ as of this writing (so through at
15086 least 3.2.1) incorrectly generate DW_TAG_variable
15087 tags for them instead. */
15088 dwarf2_add_field (fi
, child_die
, cu
);
15090 else if (child_die
->tag
== DW_TAG_subprogram
)
15092 /* Rust doesn't have member functions in the C++ sense.
15093 However, it does emit ordinary functions as children
15094 of a struct DIE. */
15095 if (cu
->language
== language_rust
)
15096 read_func_scope (child_die
, cu
);
15099 /* C++ member function. */
15100 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15103 else if (child_die
->tag
== DW_TAG_inheritance
)
15105 /* C++ base class field. */
15106 dwarf2_add_field (fi
, child_die
, cu
);
15108 else if (type_can_define_types (child_die
))
15109 dwarf2_add_type_defn (fi
, child_die
, cu
);
15110 else if (child_die
->tag
== DW_TAG_template_type_param
15111 || child_die
->tag
== DW_TAG_template_value_param
)
15113 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15116 template_args
->push_back (arg
);
15118 else if (child_die
->tag
== DW_TAG_variant
)
15120 /* In a variant we want to get the discriminant and also add a
15121 field for our sole member child. */
15122 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15124 for (die_info
*variant_child
= child_die
->child
;
15125 variant_child
!= NULL
;
15126 variant_child
= variant_child
->sibling
)
15128 if (variant_child
->tag
== DW_TAG_member
)
15130 handle_struct_member_die (variant_child
, type
, fi
,
15131 template_args
, cu
);
15132 /* Only handle the one. */
15137 /* We don't handle this but we might as well report it if we see
15139 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15140 complaint (_("DW_AT_discr_list is not supported yet"
15141 " - DIE at %s [in module %s]"),
15142 sect_offset_str (child_die
->sect_off
),
15143 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15145 /* The first field was just added, so we can stash the
15146 discriminant there. */
15147 gdb_assert (!fi
->fields
.empty ());
15149 fi
->fields
.back ().variant
.default_branch
= true;
15151 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15155 /* Finish creating a structure or union type, including filling in
15156 its members and creating a symbol for it. */
15159 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15161 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15162 struct die_info
*child_die
;
15165 type
= get_die_type (die
, cu
);
15167 type
= read_structure_type (die
, cu
);
15169 /* When reading a DW_TAG_variant_part, we need to notice when we
15170 read the discriminant member, so we can record it later in the
15171 discriminant_info. */
15172 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15173 sect_offset discr_offset
{};
15174 bool has_template_parameters
= false;
15176 if (is_variant_part
)
15178 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15181 /* Maybe it's a univariant form, an extension we support.
15182 In this case arrange not to check the offset. */
15183 is_variant_part
= false;
15185 else if (discr
->form_is_ref ())
15187 struct dwarf2_cu
*target_cu
= cu
;
15188 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15190 discr_offset
= target_die
->sect_off
;
15194 complaint (_("DW_AT_discr does not have DIE reference form"
15195 " - DIE at %s [in module %s]"),
15196 sect_offset_str (die
->sect_off
),
15197 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15198 is_variant_part
= false;
15202 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15204 struct field_info fi
;
15205 std::vector
<struct symbol
*> template_args
;
15207 child_die
= die
->child
;
15209 while (child_die
&& child_die
->tag
)
15211 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15213 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15214 fi
.fields
.back ().variant
.is_discriminant
= true;
15216 child_die
= child_die
->sibling
;
15219 /* Attach template arguments to type. */
15220 if (!template_args
.empty ())
15222 has_template_parameters
= true;
15223 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15224 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15225 TYPE_TEMPLATE_ARGUMENTS (type
)
15226 = XOBNEWVEC (&objfile
->objfile_obstack
,
15228 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15229 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15230 template_args
.data (),
15231 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15232 * sizeof (struct symbol
*)));
15235 /* Attach fields and member functions to the type. */
15236 if (fi
.nfields () > 0)
15237 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15238 if (!fi
.fnfieldlists
.empty ())
15240 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15242 /* Get the type which refers to the base class (possibly this
15243 class itself) which contains the vtable pointer for the current
15244 class from the DW_AT_containing_type attribute. This use of
15245 DW_AT_containing_type is a GNU extension. */
15247 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15249 struct type
*t
= die_containing_type (die
, cu
);
15251 set_type_vptr_basetype (type
, t
);
15256 /* Our own class provides vtbl ptr. */
15257 for (i
= TYPE_NFIELDS (t
) - 1;
15258 i
>= TYPE_N_BASECLASSES (t
);
15261 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15263 if (is_vtable_name (fieldname
, cu
))
15265 set_type_vptr_fieldno (type
, i
);
15270 /* Complain if virtual function table field not found. */
15271 if (i
< TYPE_N_BASECLASSES (t
))
15272 complaint (_("virtual function table pointer "
15273 "not found when defining class '%s'"),
15274 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15278 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15281 else if (cu
->producer
15282 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15284 /* The IBM XLC compiler does not provide direct indication
15285 of the containing type, but the vtable pointer is
15286 always named __vfp. */
15290 for (i
= TYPE_NFIELDS (type
) - 1;
15291 i
>= TYPE_N_BASECLASSES (type
);
15294 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15296 set_type_vptr_fieldno (type
, i
);
15297 set_type_vptr_basetype (type
, type
);
15304 /* Copy fi.typedef_field_list linked list elements content into the
15305 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15306 if (!fi
.typedef_field_list
.empty ())
15308 int count
= fi
.typedef_field_list
.size ();
15310 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15311 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15312 = ((struct decl_field
*)
15314 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15315 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15317 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15318 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15321 /* Copy fi.nested_types_list linked list elements content into the
15322 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15323 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15325 int count
= fi
.nested_types_list
.size ();
15327 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15328 TYPE_NESTED_TYPES_ARRAY (type
)
15329 = ((struct decl_field
*)
15330 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15331 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15333 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15334 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15338 quirk_gcc_member_function_pointer (type
, objfile
);
15339 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15340 cu
->rust_unions
.push_back (type
);
15342 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15343 snapshots) has been known to create a die giving a declaration
15344 for a class that has, as a child, a die giving a definition for a
15345 nested class. So we have to process our children even if the
15346 current die is a declaration. Normally, of course, a declaration
15347 won't have any children at all. */
15349 child_die
= die
->child
;
15351 while (child_die
!= NULL
&& child_die
->tag
)
15353 if (child_die
->tag
== DW_TAG_member
15354 || child_die
->tag
== DW_TAG_variable
15355 || child_die
->tag
== DW_TAG_inheritance
15356 || child_die
->tag
== DW_TAG_template_value_param
15357 || child_die
->tag
== DW_TAG_template_type_param
)
15362 process_die (child_die
, cu
);
15364 child_die
= child_die
->sibling
;
15367 /* Do not consider external references. According to the DWARF standard,
15368 these DIEs are identified by the fact that they have no byte_size
15369 attribute, and a declaration attribute. */
15370 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15371 || !die_is_declaration (die
, cu
))
15373 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15375 if (has_template_parameters
)
15377 struct symtab
*symtab
;
15378 if (sym
!= nullptr)
15379 symtab
= symbol_symtab (sym
);
15380 else if (cu
->line_header
!= nullptr)
15382 /* Any related symtab will do. */
15384 = cu
->line_header
->file_names ()[0].symtab
;
15389 complaint (_("could not find suitable "
15390 "symtab for template parameter"
15391 " - DIE at %s [in module %s]"),
15392 sect_offset_str (die
->sect_off
),
15393 objfile_name (objfile
));
15396 if (symtab
!= nullptr)
15398 /* Make sure that the symtab is set on the new symbols.
15399 Even though they don't appear in this symtab directly,
15400 other parts of gdb assume that symbols do, and this is
15401 reasonably true. */
15402 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15403 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15409 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15410 update TYPE using some information only available in DIE's children. */
15413 update_enumeration_type_from_children (struct die_info
*die
,
15415 struct dwarf2_cu
*cu
)
15417 struct die_info
*child_die
;
15418 int unsigned_enum
= 1;
15421 auto_obstack obstack
;
15423 for (child_die
= die
->child
;
15424 child_die
!= NULL
&& child_die
->tag
;
15425 child_die
= child_die
->sibling
)
15427 struct attribute
*attr
;
15429 const gdb_byte
*bytes
;
15430 struct dwarf2_locexpr_baton
*baton
;
15433 if (child_die
->tag
!= DW_TAG_enumerator
)
15436 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15440 name
= dwarf2_name (child_die
, cu
);
15442 name
= "<anonymous enumerator>";
15444 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15445 &value
, &bytes
, &baton
);
15453 if (count_one_bits_ll (value
) >= 2)
15457 /* If we already know that the enum type is neither unsigned, nor
15458 a flag type, no need to look at the rest of the enumerates. */
15459 if (!unsigned_enum
&& !flag_enum
)
15464 TYPE_UNSIGNED (type
) = 1;
15466 TYPE_FLAG_ENUM (type
) = 1;
15469 /* Given a DW_AT_enumeration_type die, set its type. We do not
15470 complete the type's fields yet, or create any symbols. */
15472 static struct type
*
15473 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15475 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15477 struct attribute
*attr
;
15480 /* If the definition of this type lives in .debug_types, read that type.
15481 Don't follow DW_AT_specification though, that will take us back up
15482 the chain and we want to go down. */
15483 attr
= die
->attr (DW_AT_signature
);
15484 if (attr
!= nullptr)
15486 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15488 /* The type's CU may not be the same as CU.
15489 Ensure TYPE is recorded with CU in die_type_hash. */
15490 return set_die_type (die
, type
, cu
);
15493 type
= alloc_type (objfile
);
15495 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15496 name
= dwarf2_full_name (NULL
, die
, cu
);
15498 TYPE_NAME (type
) = name
;
15500 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15503 struct type
*underlying_type
= die_type (die
, cu
);
15505 TYPE_TARGET_TYPE (type
) = underlying_type
;
15508 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15509 if (attr
!= nullptr)
15511 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15515 TYPE_LENGTH (type
) = 0;
15518 maybe_set_alignment (cu
, die
, type
);
15520 /* The enumeration DIE can be incomplete. In Ada, any type can be
15521 declared as private in the package spec, and then defined only
15522 inside the package body. Such types are known as Taft Amendment
15523 Types. When another package uses such a type, an incomplete DIE
15524 may be generated by the compiler. */
15525 if (die_is_declaration (die
, cu
))
15526 TYPE_STUB (type
) = 1;
15528 /* Finish the creation of this type by using the enum's children.
15529 We must call this even when the underlying type has been provided
15530 so that we can determine if we're looking at a "flag" enum. */
15531 update_enumeration_type_from_children (die
, type
, cu
);
15533 /* If this type has an underlying type that is not a stub, then we
15534 may use its attributes. We always use the "unsigned" attribute
15535 in this situation, because ordinarily we guess whether the type
15536 is unsigned -- but the guess can be wrong and the underlying type
15537 can tell us the reality. However, we defer to a local size
15538 attribute if one exists, because this lets the compiler override
15539 the underlying type if needed. */
15540 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15542 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15543 if (TYPE_LENGTH (type
) == 0)
15544 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15545 if (TYPE_RAW_ALIGN (type
) == 0
15546 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15547 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15550 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15552 return set_die_type (die
, type
, cu
);
15555 /* Given a pointer to a die which begins an enumeration, process all
15556 the dies that define the members of the enumeration, and create the
15557 symbol for the enumeration type.
15559 NOTE: We reverse the order of the element list. */
15562 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15564 struct type
*this_type
;
15566 this_type
= get_die_type (die
, cu
);
15567 if (this_type
== NULL
)
15568 this_type
= read_enumeration_type (die
, cu
);
15570 if (die
->child
!= NULL
)
15572 struct die_info
*child_die
;
15573 struct symbol
*sym
;
15574 std::vector
<struct field
> fields
;
15577 child_die
= die
->child
;
15578 while (child_die
&& child_die
->tag
)
15580 if (child_die
->tag
!= DW_TAG_enumerator
)
15582 process_die (child_die
, cu
);
15586 name
= dwarf2_name (child_die
, cu
);
15589 sym
= new_symbol (child_die
, this_type
, cu
);
15591 fields
.emplace_back ();
15592 struct field
&field
= fields
.back ();
15594 FIELD_NAME (field
) = sym
->linkage_name ();
15595 FIELD_TYPE (field
) = NULL
;
15596 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15597 FIELD_BITSIZE (field
) = 0;
15601 child_die
= child_die
->sibling
;
15604 if (!fields
.empty ())
15606 TYPE_NFIELDS (this_type
) = fields
.size ();
15607 TYPE_FIELDS (this_type
) = (struct field
*)
15608 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15609 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15610 sizeof (struct field
) * fields
.size ());
15614 /* If we are reading an enum from a .debug_types unit, and the enum
15615 is a declaration, and the enum is not the signatured type in the
15616 unit, then we do not want to add a symbol for it. Adding a
15617 symbol would in some cases obscure the true definition of the
15618 enum, giving users an incomplete type when the definition is
15619 actually available. Note that we do not want to do this for all
15620 enums which are just declarations, because C++0x allows forward
15621 enum declarations. */
15622 if (cu
->per_cu
->is_debug_types
15623 && die_is_declaration (die
, cu
))
15625 struct signatured_type
*sig_type
;
15627 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15628 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15629 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15633 new_symbol (die
, this_type
, cu
);
15636 /* Extract all information from a DW_TAG_array_type DIE and put it in
15637 the DIE's type field. For now, this only handles one dimensional
15640 static struct type
*
15641 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15643 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15644 struct die_info
*child_die
;
15646 struct type
*element_type
, *range_type
, *index_type
;
15647 struct attribute
*attr
;
15649 struct dynamic_prop
*byte_stride_prop
= NULL
;
15650 unsigned int bit_stride
= 0;
15652 element_type
= die_type (die
, cu
);
15654 /* The die_type call above may have already set the type for this DIE. */
15655 type
= get_die_type (die
, cu
);
15659 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15663 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15666 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15667 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15671 complaint (_("unable to read array DW_AT_byte_stride "
15672 " - DIE at %s [in module %s]"),
15673 sect_offset_str (die
->sect_off
),
15674 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15675 /* Ignore this attribute. We will likely not be able to print
15676 arrays of this type correctly, but there is little we can do
15677 to help if we cannot read the attribute's value. */
15678 byte_stride_prop
= NULL
;
15682 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15684 bit_stride
= DW_UNSND (attr
);
15686 /* Irix 6.2 native cc creates array types without children for
15687 arrays with unspecified length. */
15688 if (die
->child
== NULL
)
15690 index_type
= objfile_type (objfile
)->builtin_int
;
15691 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15692 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15693 byte_stride_prop
, bit_stride
);
15694 return set_die_type (die
, type
, cu
);
15697 std::vector
<struct type
*> range_types
;
15698 child_die
= die
->child
;
15699 while (child_die
&& child_die
->tag
)
15701 if (child_die
->tag
== DW_TAG_subrange_type
)
15703 struct type
*child_type
= read_type_die (child_die
, cu
);
15705 if (child_type
!= NULL
)
15707 /* The range type was succesfully read. Save it for the
15708 array type creation. */
15709 range_types
.push_back (child_type
);
15712 child_die
= child_die
->sibling
;
15715 /* Dwarf2 dimensions are output from left to right, create the
15716 necessary array types in backwards order. */
15718 type
= element_type
;
15720 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15724 while (i
< range_types
.size ())
15725 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15726 byte_stride_prop
, bit_stride
);
15730 size_t ndim
= range_types
.size ();
15732 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15733 byte_stride_prop
, bit_stride
);
15736 /* Understand Dwarf2 support for vector types (like they occur on
15737 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15738 array type. This is not part of the Dwarf2/3 standard yet, but a
15739 custom vendor extension. The main difference between a regular
15740 array and the vector variant is that vectors are passed by value
15742 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15743 if (attr
!= nullptr)
15744 make_vector_type (type
);
15746 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15747 implementation may choose to implement triple vectors using this
15749 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15750 if (attr
!= nullptr)
15752 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15753 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15755 complaint (_("DW_AT_byte_size for array type smaller "
15756 "than the total size of elements"));
15759 name
= dwarf2_name (die
, cu
);
15761 TYPE_NAME (type
) = name
;
15763 maybe_set_alignment (cu
, die
, type
);
15765 /* Install the type in the die. */
15766 set_die_type (die
, type
, cu
);
15768 /* set_die_type should be already done. */
15769 set_descriptive_type (type
, die
, cu
);
15774 static enum dwarf_array_dim_ordering
15775 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15777 struct attribute
*attr
;
15779 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15781 if (attr
!= nullptr)
15782 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15784 /* GNU F77 is a special case, as at 08/2004 array type info is the
15785 opposite order to the dwarf2 specification, but data is still
15786 laid out as per normal fortran.
15788 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15789 version checking. */
15791 if (cu
->language
== language_fortran
15792 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15794 return DW_ORD_row_major
;
15797 switch (cu
->language_defn
->la_array_ordering
)
15799 case array_column_major
:
15800 return DW_ORD_col_major
;
15801 case array_row_major
:
15803 return DW_ORD_row_major
;
15807 /* Extract all information from a DW_TAG_set_type DIE and put it in
15808 the DIE's type field. */
15810 static struct type
*
15811 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15813 struct type
*domain_type
, *set_type
;
15814 struct attribute
*attr
;
15816 domain_type
= die_type (die
, cu
);
15818 /* The die_type call above may have already set the type for this DIE. */
15819 set_type
= get_die_type (die
, cu
);
15823 set_type
= create_set_type (NULL
, domain_type
);
15825 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15826 if (attr
!= nullptr)
15827 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15829 maybe_set_alignment (cu
, die
, set_type
);
15831 return set_die_type (die
, set_type
, cu
);
15834 /* A helper for read_common_block that creates a locexpr baton.
15835 SYM is the symbol which we are marking as computed.
15836 COMMON_DIE is the DIE for the common block.
15837 COMMON_LOC is the location expression attribute for the common
15839 MEMBER_LOC is the location expression attribute for the particular
15840 member of the common block that we are processing.
15841 CU is the CU from which the above come. */
15844 mark_common_block_symbol_computed (struct symbol
*sym
,
15845 struct die_info
*common_die
,
15846 struct attribute
*common_loc
,
15847 struct attribute
*member_loc
,
15848 struct dwarf2_cu
*cu
)
15850 struct dwarf2_per_objfile
*dwarf2_per_objfile
15851 = cu
->per_cu
->dwarf2_per_objfile
;
15852 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15853 struct dwarf2_locexpr_baton
*baton
;
15855 unsigned int cu_off
;
15856 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15857 LONGEST offset
= 0;
15859 gdb_assert (common_loc
&& member_loc
);
15860 gdb_assert (common_loc
->form_is_block ());
15861 gdb_assert (member_loc
->form_is_block ()
15862 || member_loc
->form_is_constant ());
15864 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15865 baton
->per_cu
= cu
->per_cu
;
15866 gdb_assert (baton
->per_cu
);
15868 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15870 if (member_loc
->form_is_constant ())
15872 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15873 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15876 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15878 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15881 *ptr
++ = DW_OP_call4
;
15882 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15883 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15886 if (member_loc
->form_is_constant ())
15888 *ptr
++ = DW_OP_addr
;
15889 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15890 ptr
+= cu
->header
.addr_size
;
15894 /* We have to copy the data here, because DW_OP_call4 will only
15895 use a DW_AT_location attribute. */
15896 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15897 ptr
+= DW_BLOCK (member_loc
)->size
;
15900 *ptr
++ = DW_OP_plus
;
15901 gdb_assert (ptr
- baton
->data
== baton
->size
);
15903 SYMBOL_LOCATION_BATON (sym
) = baton
;
15904 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15907 /* Create appropriate locally-scoped variables for all the
15908 DW_TAG_common_block entries. Also create a struct common_block
15909 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15910 is used to separate the common blocks name namespace from regular
15914 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15916 struct attribute
*attr
;
15918 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15919 if (attr
!= nullptr)
15921 /* Support the .debug_loc offsets. */
15922 if (attr
->form_is_block ())
15926 else if (attr
->form_is_section_offset ())
15928 dwarf2_complex_location_expr_complaint ();
15933 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15934 "common block member");
15939 if (die
->child
!= NULL
)
15941 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15942 struct die_info
*child_die
;
15943 size_t n_entries
= 0, size
;
15944 struct common_block
*common_block
;
15945 struct symbol
*sym
;
15947 for (child_die
= die
->child
;
15948 child_die
&& child_die
->tag
;
15949 child_die
= child_die
->sibling
)
15952 size
= (sizeof (struct common_block
)
15953 + (n_entries
- 1) * sizeof (struct symbol
*));
15955 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
15957 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
15958 common_block
->n_entries
= 0;
15960 for (child_die
= die
->child
;
15961 child_die
&& child_die
->tag
;
15962 child_die
= child_die
->sibling
)
15964 /* Create the symbol in the DW_TAG_common_block block in the current
15966 sym
= new_symbol (child_die
, NULL
, cu
);
15969 struct attribute
*member_loc
;
15971 common_block
->contents
[common_block
->n_entries
++] = sym
;
15973 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
15977 /* GDB has handled this for a long time, but it is
15978 not specified by DWARF. It seems to have been
15979 emitted by gfortran at least as recently as:
15980 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
15981 complaint (_("Variable in common block has "
15982 "DW_AT_data_member_location "
15983 "- DIE at %s [in module %s]"),
15984 sect_offset_str (child_die
->sect_off
),
15985 objfile_name (objfile
));
15987 if (member_loc
->form_is_section_offset ())
15988 dwarf2_complex_location_expr_complaint ();
15989 else if (member_loc
->form_is_constant ()
15990 || member_loc
->form_is_block ())
15992 if (attr
!= nullptr)
15993 mark_common_block_symbol_computed (sym
, die
, attr
,
15997 dwarf2_complex_location_expr_complaint ();
16002 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16003 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16007 /* Create a type for a C++ namespace. */
16009 static struct type
*
16010 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16012 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16013 const char *previous_prefix
, *name
;
16017 /* For extensions, reuse the type of the original namespace. */
16018 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16020 struct die_info
*ext_die
;
16021 struct dwarf2_cu
*ext_cu
= cu
;
16023 ext_die
= dwarf2_extension (die
, &ext_cu
);
16024 type
= read_type_die (ext_die
, ext_cu
);
16026 /* EXT_CU may not be the same as CU.
16027 Ensure TYPE is recorded with CU in die_type_hash. */
16028 return set_die_type (die
, type
, cu
);
16031 name
= namespace_name (die
, &is_anonymous
, cu
);
16033 /* Now build the name of the current namespace. */
16035 previous_prefix
= determine_prefix (die
, cu
);
16036 if (previous_prefix
[0] != '\0')
16037 name
= typename_concat (&objfile
->objfile_obstack
,
16038 previous_prefix
, name
, 0, cu
);
16040 /* Create the type. */
16041 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16043 return set_die_type (die
, type
, cu
);
16046 /* Read a namespace scope. */
16049 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16051 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16054 /* Add a symbol associated to this if we haven't seen the namespace
16055 before. Also, add a using directive if it's an anonymous
16058 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16062 type
= read_type_die (die
, cu
);
16063 new_symbol (die
, type
, cu
);
16065 namespace_name (die
, &is_anonymous
, cu
);
16068 const char *previous_prefix
= determine_prefix (die
, cu
);
16070 std::vector
<const char *> excludes
;
16071 add_using_directive (using_directives (cu
),
16072 previous_prefix
, TYPE_NAME (type
), NULL
,
16073 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16077 if (die
->child
!= NULL
)
16079 struct die_info
*child_die
= die
->child
;
16081 while (child_die
&& child_die
->tag
)
16083 process_die (child_die
, cu
);
16084 child_die
= child_die
->sibling
;
16089 /* Read a Fortran module as type. This DIE can be only a declaration used for
16090 imported module. Still we need that type as local Fortran "use ... only"
16091 declaration imports depend on the created type in determine_prefix. */
16093 static struct type
*
16094 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16096 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16097 const char *module_name
;
16100 module_name
= dwarf2_name (die
, cu
);
16101 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16103 return set_die_type (die
, type
, cu
);
16106 /* Read a Fortran module. */
16109 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16111 struct die_info
*child_die
= die
->child
;
16114 type
= read_type_die (die
, cu
);
16115 new_symbol (die
, type
, cu
);
16117 while (child_die
&& child_die
->tag
)
16119 process_die (child_die
, cu
);
16120 child_die
= child_die
->sibling
;
16124 /* Return the name of the namespace represented by DIE. Set
16125 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16128 static const char *
16129 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16131 struct die_info
*current_die
;
16132 const char *name
= NULL
;
16134 /* Loop through the extensions until we find a name. */
16136 for (current_die
= die
;
16137 current_die
!= NULL
;
16138 current_die
= dwarf2_extension (die
, &cu
))
16140 /* We don't use dwarf2_name here so that we can detect the absence
16141 of a name -> anonymous namespace. */
16142 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16148 /* Is it an anonymous namespace? */
16150 *is_anonymous
= (name
== NULL
);
16152 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16157 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16158 the user defined type vector. */
16160 static struct type
*
16161 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16163 struct gdbarch
*gdbarch
16164 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16165 struct comp_unit_head
*cu_header
= &cu
->header
;
16167 struct attribute
*attr_byte_size
;
16168 struct attribute
*attr_address_class
;
16169 int byte_size
, addr_class
;
16170 struct type
*target_type
;
16172 target_type
= die_type (die
, cu
);
16174 /* The die_type call above may have already set the type for this DIE. */
16175 type
= get_die_type (die
, cu
);
16179 type
= lookup_pointer_type (target_type
);
16181 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16182 if (attr_byte_size
)
16183 byte_size
= DW_UNSND (attr_byte_size
);
16185 byte_size
= cu_header
->addr_size
;
16187 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16188 if (attr_address_class
)
16189 addr_class
= DW_UNSND (attr_address_class
);
16191 addr_class
= DW_ADDR_none
;
16193 ULONGEST alignment
= get_alignment (cu
, die
);
16195 /* If the pointer size, alignment, or address class is different
16196 than the default, create a type variant marked as such and set
16197 the length accordingly. */
16198 if (TYPE_LENGTH (type
) != byte_size
16199 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16200 && alignment
!= TYPE_RAW_ALIGN (type
))
16201 || addr_class
!= DW_ADDR_none
)
16203 if (gdbarch_address_class_type_flags_p (gdbarch
))
16207 type_flags
= gdbarch_address_class_type_flags
16208 (gdbarch
, byte_size
, addr_class
);
16209 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16211 type
= make_type_with_address_space (type
, type_flags
);
16213 else if (TYPE_LENGTH (type
) != byte_size
)
16215 complaint (_("invalid pointer size %d"), byte_size
);
16217 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16219 complaint (_("Invalid DW_AT_alignment"
16220 " - DIE at %s [in module %s]"),
16221 sect_offset_str (die
->sect_off
),
16222 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16226 /* Should we also complain about unhandled address classes? */
16230 TYPE_LENGTH (type
) = byte_size
;
16231 set_type_align (type
, alignment
);
16232 return set_die_type (die
, type
, cu
);
16235 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16236 the user defined type vector. */
16238 static struct type
*
16239 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16242 struct type
*to_type
;
16243 struct type
*domain
;
16245 to_type
= die_type (die
, cu
);
16246 domain
= die_containing_type (die
, cu
);
16248 /* The calls above may have already set the type for this DIE. */
16249 type
= get_die_type (die
, cu
);
16253 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16254 type
= lookup_methodptr_type (to_type
);
16255 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16257 struct type
*new_type
16258 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16260 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16261 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16262 TYPE_VARARGS (to_type
));
16263 type
= lookup_methodptr_type (new_type
);
16266 type
= lookup_memberptr_type (to_type
, domain
);
16268 return set_die_type (die
, type
, cu
);
16271 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16272 the user defined type vector. */
16274 static struct type
*
16275 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16276 enum type_code refcode
)
16278 struct comp_unit_head
*cu_header
= &cu
->header
;
16279 struct type
*type
, *target_type
;
16280 struct attribute
*attr
;
16282 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16284 target_type
= die_type (die
, cu
);
16286 /* The die_type call above may have already set the type for this DIE. */
16287 type
= get_die_type (die
, cu
);
16291 type
= lookup_reference_type (target_type
, refcode
);
16292 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16293 if (attr
!= nullptr)
16295 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16299 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16301 maybe_set_alignment (cu
, die
, type
);
16302 return set_die_type (die
, type
, cu
);
16305 /* Add the given cv-qualifiers to the element type of the array. GCC
16306 outputs DWARF type qualifiers that apply to an array, not the
16307 element type. But GDB relies on the array element type to carry
16308 the cv-qualifiers. This mimics section 6.7.3 of the C99
16311 static struct type
*
16312 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16313 struct type
*base_type
, int cnst
, int voltl
)
16315 struct type
*el_type
, *inner_array
;
16317 base_type
= copy_type (base_type
);
16318 inner_array
= base_type
;
16320 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16322 TYPE_TARGET_TYPE (inner_array
) =
16323 copy_type (TYPE_TARGET_TYPE (inner_array
));
16324 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16327 el_type
= TYPE_TARGET_TYPE (inner_array
);
16328 cnst
|= TYPE_CONST (el_type
);
16329 voltl
|= TYPE_VOLATILE (el_type
);
16330 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16332 return set_die_type (die
, base_type
, cu
);
16335 static struct type
*
16336 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16338 struct type
*base_type
, *cv_type
;
16340 base_type
= die_type (die
, cu
);
16342 /* The die_type call above may have already set the type for this DIE. */
16343 cv_type
= get_die_type (die
, cu
);
16347 /* In case the const qualifier is applied to an array type, the element type
16348 is so qualified, not the array type (section 6.7.3 of C99). */
16349 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16350 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16352 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16353 return set_die_type (die
, cv_type
, cu
);
16356 static struct type
*
16357 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16359 struct type
*base_type
, *cv_type
;
16361 base_type
= die_type (die
, cu
);
16363 /* The die_type call above may have already set the type for this DIE. */
16364 cv_type
= get_die_type (die
, cu
);
16368 /* In case the volatile qualifier is applied to an array type, the
16369 element type is so qualified, not the array type (section 6.7.3
16371 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16372 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16374 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16375 return set_die_type (die
, cv_type
, cu
);
16378 /* Handle DW_TAG_restrict_type. */
16380 static struct type
*
16381 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16383 struct type
*base_type
, *cv_type
;
16385 base_type
= die_type (die
, cu
);
16387 /* The die_type call above may have already set the type for this DIE. */
16388 cv_type
= get_die_type (die
, cu
);
16392 cv_type
= make_restrict_type (base_type
);
16393 return set_die_type (die
, cv_type
, cu
);
16396 /* Handle DW_TAG_atomic_type. */
16398 static struct type
*
16399 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16401 struct type
*base_type
, *cv_type
;
16403 base_type
= die_type (die
, cu
);
16405 /* The die_type call above may have already set the type for this DIE. */
16406 cv_type
= get_die_type (die
, cu
);
16410 cv_type
= make_atomic_type (base_type
);
16411 return set_die_type (die
, cv_type
, cu
);
16414 /* Extract all information from a DW_TAG_string_type DIE and add to
16415 the user defined type vector. It isn't really a user defined type,
16416 but it behaves like one, with other DIE's using an AT_user_def_type
16417 attribute to reference it. */
16419 static struct type
*
16420 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16422 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16423 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16424 struct type
*type
, *range_type
, *index_type
, *char_type
;
16425 struct attribute
*attr
;
16426 struct dynamic_prop prop
;
16427 bool length_is_constant
= true;
16430 /* There are a couple of places where bit sizes might be made use of
16431 when parsing a DW_TAG_string_type, however, no producer that we know
16432 of make use of these. Handling bit sizes that are a multiple of the
16433 byte size is easy enough, but what about other bit sizes? Lets deal
16434 with that problem when we have to. Warn about these attributes being
16435 unsupported, then parse the type and ignore them like we always
16437 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16438 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16440 static bool warning_printed
= false;
16441 if (!warning_printed
)
16443 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16444 "currently supported on DW_TAG_string_type."));
16445 warning_printed
= true;
16449 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16450 if (attr
!= nullptr && !attr
->form_is_constant ())
16452 /* The string length describes the location at which the length of
16453 the string can be found. The size of the length field can be
16454 specified with one of the attributes below. */
16455 struct type
*prop_type
;
16456 struct attribute
*len
16457 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16458 if (len
== nullptr)
16459 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16460 if (len
!= nullptr && len
->form_is_constant ())
16462 /* Pass 0 as the default as we know this attribute is constant
16463 and the default value will not be returned. */
16464 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16465 prop_type
= cu
->per_cu
->int_type (sz
, true);
16469 /* If the size is not specified then we assume it is the size of
16470 an address on this target. */
16471 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16474 /* Convert the attribute into a dynamic property. */
16475 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16478 length_is_constant
= false;
16480 else if (attr
!= nullptr)
16482 /* This DW_AT_string_length just contains the length with no
16483 indirection. There's no need to create a dynamic property in this
16484 case. Pass 0 for the default value as we know it will not be
16485 returned in this case. */
16486 length
= dwarf2_get_attr_constant_value (attr
, 0);
16488 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16490 /* We don't currently support non-constant byte sizes for strings. */
16491 length
= dwarf2_get_attr_constant_value (attr
, 1);
16495 /* Use 1 as a fallback length if we have nothing else. */
16499 index_type
= objfile_type (objfile
)->builtin_int
;
16500 if (length_is_constant
)
16501 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16504 struct dynamic_prop low_bound
;
16506 low_bound
.kind
= PROP_CONST
;
16507 low_bound
.data
.const_val
= 1;
16508 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16510 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16511 type
= create_string_type (NULL
, char_type
, range_type
);
16513 return set_die_type (die
, type
, cu
);
16516 /* Assuming that DIE corresponds to a function, returns nonzero
16517 if the function is prototyped. */
16520 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16522 struct attribute
*attr
;
16524 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16525 if (attr
&& (DW_UNSND (attr
) != 0))
16528 /* The DWARF standard implies that the DW_AT_prototyped attribute
16529 is only meaningful for C, but the concept also extends to other
16530 languages that allow unprototyped functions (Eg: Objective C).
16531 For all other languages, assume that functions are always
16533 if (cu
->language
!= language_c
16534 && cu
->language
!= language_objc
16535 && cu
->language
!= language_opencl
)
16538 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16539 prototyped and unprototyped functions; default to prototyped,
16540 since that is more common in modern code (and RealView warns
16541 about unprototyped functions). */
16542 if (producer_is_realview (cu
->producer
))
16548 /* Handle DIES due to C code like:
16552 int (*funcp)(int a, long l);
16556 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16558 static struct type
*
16559 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16561 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16562 struct type
*type
; /* Type that this function returns. */
16563 struct type
*ftype
; /* Function that returns above type. */
16564 struct attribute
*attr
;
16566 type
= die_type (die
, cu
);
16568 /* The die_type call above may have already set the type for this DIE. */
16569 ftype
= get_die_type (die
, cu
);
16573 ftype
= lookup_function_type (type
);
16575 if (prototyped_function_p (die
, cu
))
16576 TYPE_PROTOTYPED (ftype
) = 1;
16578 /* Store the calling convention in the type if it's available in
16579 the subroutine die. Otherwise set the calling convention to
16580 the default value DW_CC_normal. */
16581 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16582 if (attr
!= nullptr
16583 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16584 TYPE_CALLING_CONVENTION (ftype
)
16585 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16586 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16587 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16589 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16591 /* Record whether the function returns normally to its caller or not
16592 if the DWARF producer set that information. */
16593 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16594 if (attr
&& (DW_UNSND (attr
) != 0))
16595 TYPE_NO_RETURN (ftype
) = 1;
16597 /* We need to add the subroutine type to the die immediately so
16598 we don't infinitely recurse when dealing with parameters
16599 declared as the same subroutine type. */
16600 set_die_type (die
, ftype
, cu
);
16602 if (die
->child
!= NULL
)
16604 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16605 struct die_info
*child_die
;
16606 int nparams
, iparams
;
16608 /* Count the number of parameters.
16609 FIXME: GDB currently ignores vararg functions, but knows about
16610 vararg member functions. */
16612 child_die
= die
->child
;
16613 while (child_die
&& child_die
->tag
)
16615 if (child_die
->tag
== DW_TAG_formal_parameter
)
16617 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16618 TYPE_VARARGS (ftype
) = 1;
16619 child_die
= child_die
->sibling
;
16622 /* Allocate storage for parameters and fill them in. */
16623 TYPE_NFIELDS (ftype
) = nparams
;
16624 TYPE_FIELDS (ftype
) = (struct field
*)
16625 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16627 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16628 even if we error out during the parameters reading below. */
16629 for (iparams
= 0; iparams
< nparams
; iparams
++)
16630 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16633 child_die
= die
->child
;
16634 while (child_die
&& child_die
->tag
)
16636 if (child_die
->tag
== DW_TAG_formal_parameter
)
16638 struct type
*arg_type
;
16640 /* DWARF version 2 has no clean way to discern C++
16641 static and non-static member functions. G++ helps
16642 GDB by marking the first parameter for non-static
16643 member functions (which is the this pointer) as
16644 artificial. We pass this information to
16645 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16647 DWARF version 3 added DW_AT_object_pointer, which GCC
16648 4.5 does not yet generate. */
16649 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16650 if (attr
!= nullptr)
16651 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16653 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16654 arg_type
= die_type (child_die
, cu
);
16656 /* RealView does not mark THIS as const, which the testsuite
16657 expects. GCC marks THIS as const in method definitions,
16658 but not in the class specifications (GCC PR 43053). */
16659 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16660 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16663 struct dwarf2_cu
*arg_cu
= cu
;
16664 const char *name
= dwarf2_name (child_die
, cu
);
16666 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16667 if (attr
!= nullptr)
16669 /* If the compiler emits this, use it. */
16670 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16673 else if (name
&& strcmp (name
, "this") == 0)
16674 /* Function definitions will have the argument names. */
16676 else if (name
== NULL
&& iparams
== 0)
16677 /* Declarations may not have the names, so like
16678 elsewhere in GDB, assume an artificial first
16679 argument is "this". */
16683 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16687 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16690 child_die
= child_die
->sibling
;
16697 static struct type
*
16698 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16700 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16701 const char *name
= NULL
;
16702 struct type
*this_type
, *target_type
;
16704 name
= dwarf2_full_name (NULL
, die
, cu
);
16705 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16706 TYPE_TARGET_STUB (this_type
) = 1;
16707 set_die_type (die
, this_type
, cu
);
16708 target_type
= die_type (die
, cu
);
16709 if (target_type
!= this_type
)
16710 TYPE_TARGET_TYPE (this_type
) = target_type
;
16713 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16714 spec and cause infinite loops in GDB. */
16715 complaint (_("Self-referential DW_TAG_typedef "
16716 "- DIE at %s [in module %s]"),
16717 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16718 TYPE_TARGET_TYPE (this_type
) = NULL
;
16722 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16723 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16724 Handle these by just returning the target type, rather than
16725 constructing an anonymous typedef type and trying to handle this
16727 set_die_type (die
, target_type
, cu
);
16728 return target_type
;
16733 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16734 (which may be different from NAME) to the architecture back-end to allow
16735 it to guess the correct format if necessary. */
16737 static struct type
*
16738 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16739 const char *name_hint
, enum bfd_endian byte_order
)
16741 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16742 const struct floatformat
**format
;
16745 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16747 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16749 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16754 /* Allocate an integer type of size BITS and name NAME. */
16756 static struct type
*
16757 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16758 int bits
, int unsigned_p
, const char *name
)
16762 /* Versions of Intel's C Compiler generate an integer type called "void"
16763 instead of using DW_TAG_unspecified_type. This has been seen on
16764 at least versions 14, 17, and 18. */
16765 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16766 && strcmp (name
, "void") == 0)
16767 type
= objfile_type (objfile
)->builtin_void
;
16769 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16774 /* Initialise and return a floating point type of size BITS suitable for
16775 use as a component of a complex number. The NAME_HINT is passed through
16776 when initialising the floating point type and is the name of the complex
16779 As DWARF doesn't currently provide an explicit name for the components
16780 of a complex number, but it can be helpful to have these components
16781 named, we try to select a suitable name based on the size of the
16783 static struct type
*
16784 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16785 struct objfile
*objfile
,
16786 int bits
, const char *name_hint
,
16787 enum bfd_endian byte_order
)
16789 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16790 struct type
*tt
= nullptr;
16792 /* Try to find a suitable floating point builtin type of size BITS.
16793 We're going to use the name of this type as the name for the complex
16794 target type that we are about to create. */
16795 switch (cu
->language
)
16797 case language_fortran
:
16801 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16804 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16806 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16808 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16816 tt
= builtin_type (gdbarch
)->builtin_float
;
16819 tt
= builtin_type (gdbarch
)->builtin_double
;
16821 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16823 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16829 /* If the type we found doesn't match the size we were looking for, then
16830 pretend we didn't find a type at all, the complex target type we
16831 create will then be nameless. */
16832 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16835 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16836 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16839 /* Find a representation of a given base type and install
16840 it in the TYPE field of the die. */
16842 static struct type
*
16843 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16845 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16847 struct attribute
*attr
;
16848 int encoding
= 0, bits
= 0;
16852 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16853 if (attr
!= nullptr)
16854 encoding
= DW_UNSND (attr
);
16855 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16856 if (attr
!= nullptr)
16857 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16858 name
= dwarf2_name (die
, cu
);
16860 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16862 arch
= get_objfile_arch (objfile
);
16863 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16865 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16868 int endianity
= DW_UNSND (attr
);
16873 byte_order
= BFD_ENDIAN_BIG
;
16875 case DW_END_little
:
16876 byte_order
= BFD_ENDIAN_LITTLE
;
16879 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16886 case DW_ATE_address
:
16887 /* Turn DW_ATE_address into a void * pointer. */
16888 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16889 type
= init_pointer_type (objfile
, bits
, name
, type
);
16891 case DW_ATE_boolean
:
16892 type
= init_boolean_type (objfile
, bits
, 1, name
);
16894 case DW_ATE_complex_float
:
16895 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16897 type
= init_complex_type (objfile
, name
, type
);
16899 case DW_ATE_decimal_float
:
16900 type
= init_decfloat_type (objfile
, bits
, name
);
16903 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16905 case DW_ATE_signed
:
16906 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16908 case DW_ATE_unsigned
:
16909 if (cu
->language
== language_fortran
16911 && startswith (name
, "character("))
16912 type
= init_character_type (objfile
, bits
, 1, name
);
16914 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16916 case DW_ATE_signed_char
:
16917 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16918 || cu
->language
== language_pascal
16919 || cu
->language
== language_fortran
)
16920 type
= init_character_type (objfile
, bits
, 0, name
);
16922 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16924 case DW_ATE_unsigned_char
:
16925 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16926 || cu
->language
== language_pascal
16927 || cu
->language
== language_fortran
16928 || cu
->language
== language_rust
)
16929 type
= init_character_type (objfile
, bits
, 1, name
);
16931 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16936 type
= builtin_type (arch
)->builtin_char16
;
16937 else if (bits
== 32)
16938 type
= builtin_type (arch
)->builtin_char32
;
16941 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
16943 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16945 return set_die_type (die
, type
, cu
);
16950 complaint (_("unsupported DW_AT_encoding: '%s'"),
16951 dwarf_type_encoding_name (encoding
));
16952 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16956 if (name
&& strcmp (name
, "char") == 0)
16957 TYPE_NOSIGN (type
) = 1;
16959 maybe_set_alignment (cu
, die
, type
);
16961 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
16963 return set_die_type (die
, type
, cu
);
16966 /* Parse dwarf attribute if it's a block, reference or constant and put the
16967 resulting value of the attribute into struct bound_prop.
16968 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
16971 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
16972 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
16973 struct type
*default_type
)
16975 struct dwarf2_property_baton
*baton
;
16976 struct obstack
*obstack
16977 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
16979 gdb_assert (default_type
!= NULL
);
16981 if (attr
== NULL
|| prop
== NULL
)
16984 if (attr
->form_is_block ())
16986 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
16987 baton
->property_type
= default_type
;
16988 baton
->locexpr
.per_cu
= cu
->per_cu
;
16989 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
16990 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
16991 switch (attr
->name
)
16993 case DW_AT_string_length
:
16994 baton
->locexpr
.is_reference
= true;
16997 baton
->locexpr
.is_reference
= false;
17000 prop
->data
.baton
= baton
;
17001 prop
->kind
= PROP_LOCEXPR
;
17002 gdb_assert (prop
->data
.baton
!= NULL
);
17004 else if (attr
->form_is_ref ())
17006 struct dwarf2_cu
*target_cu
= cu
;
17007 struct die_info
*target_die
;
17008 struct attribute
*target_attr
;
17010 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17011 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17012 if (target_attr
== NULL
)
17013 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17015 if (target_attr
== NULL
)
17018 switch (target_attr
->name
)
17020 case DW_AT_location
:
17021 if (target_attr
->form_is_section_offset ())
17023 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17024 baton
->property_type
= die_type (target_die
, target_cu
);
17025 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17026 prop
->data
.baton
= baton
;
17027 prop
->kind
= PROP_LOCLIST
;
17028 gdb_assert (prop
->data
.baton
!= NULL
);
17030 else if (target_attr
->form_is_block ())
17032 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17033 baton
->property_type
= die_type (target_die
, target_cu
);
17034 baton
->locexpr
.per_cu
= cu
->per_cu
;
17035 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17036 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17037 baton
->locexpr
.is_reference
= true;
17038 prop
->data
.baton
= baton
;
17039 prop
->kind
= PROP_LOCEXPR
;
17040 gdb_assert (prop
->data
.baton
!= NULL
);
17044 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17045 "dynamic property");
17049 case DW_AT_data_member_location
:
17053 if (!handle_data_member_location (target_die
, target_cu
,
17057 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17058 baton
->property_type
= read_type_die (target_die
->parent
,
17060 baton
->offset_info
.offset
= offset
;
17061 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17062 prop
->data
.baton
= baton
;
17063 prop
->kind
= PROP_ADDR_OFFSET
;
17068 else if (attr
->form_is_constant ())
17070 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17071 prop
->kind
= PROP_CONST
;
17075 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17076 dwarf2_name (die
, cu
));
17086 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17088 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17089 struct type
*int_type
;
17091 /* Helper macro to examine the various builtin types. */
17092 #define TRY_TYPE(F) \
17093 int_type = (unsigned_p \
17094 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17095 : objfile_type (objfile)->builtin_ ## F); \
17096 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17103 TRY_TYPE (long_long
);
17107 gdb_assert_not_reached ("unable to find suitable integer type");
17113 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17115 int addr_size
= this->addr_size ();
17116 return int_type (addr_size
, unsigned_p
);
17119 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17120 present (which is valid) then compute the default type based on the
17121 compilation units address size. */
17123 static struct type
*
17124 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17126 struct type
*index_type
= die_type (die
, cu
);
17128 /* Dwarf-2 specifications explicitly allows to create subrange types
17129 without specifying a base type.
17130 In that case, the base type must be set to the type of
17131 the lower bound, upper bound or count, in that order, if any of these
17132 three attributes references an object that has a type.
17133 If no base type is found, the Dwarf-2 specifications say that
17134 a signed integer type of size equal to the size of an address should
17136 For the following C code: `extern char gdb_int [];'
17137 GCC produces an empty range DIE.
17138 FIXME: muller/2010-05-28: Possible references to object for low bound,
17139 high bound or count are not yet handled by this code. */
17140 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17141 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17146 /* Read the given DW_AT_subrange DIE. */
17148 static struct type
*
17149 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17151 struct type
*base_type
, *orig_base_type
;
17152 struct type
*range_type
;
17153 struct attribute
*attr
;
17154 struct dynamic_prop low
, high
;
17155 int low_default_is_valid
;
17156 int high_bound_is_count
= 0;
17158 ULONGEST negative_mask
;
17160 orig_base_type
= read_subrange_index_type (die
, cu
);
17162 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17163 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17164 creating the range type, but we use the result of check_typedef
17165 when examining properties of the type. */
17166 base_type
= check_typedef (orig_base_type
);
17168 /* The die_type call above may have already set the type for this DIE. */
17169 range_type
= get_die_type (die
, cu
);
17173 low
.kind
= PROP_CONST
;
17174 high
.kind
= PROP_CONST
;
17175 high
.data
.const_val
= 0;
17177 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17178 omitting DW_AT_lower_bound. */
17179 switch (cu
->language
)
17182 case language_cplus
:
17183 low
.data
.const_val
= 0;
17184 low_default_is_valid
= 1;
17186 case language_fortran
:
17187 low
.data
.const_val
= 1;
17188 low_default_is_valid
= 1;
17191 case language_objc
:
17192 case language_rust
:
17193 low
.data
.const_val
= 0;
17194 low_default_is_valid
= (cu
->header
.version
>= 4);
17198 case language_pascal
:
17199 low
.data
.const_val
= 1;
17200 low_default_is_valid
= (cu
->header
.version
>= 4);
17203 low
.data
.const_val
= 0;
17204 low_default_is_valid
= 0;
17208 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17209 if (attr
!= nullptr)
17210 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17211 else if (!low_default_is_valid
)
17212 complaint (_("Missing DW_AT_lower_bound "
17213 "- DIE at %s [in module %s]"),
17214 sect_offset_str (die
->sect_off
),
17215 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17217 struct attribute
*attr_ub
, *attr_count
;
17218 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17219 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17221 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17222 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17224 /* If bounds are constant do the final calculation here. */
17225 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17226 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17228 high_bound_is_count
= 1;
17232 if (attr_ub
!= NULL
)
17233 complaint (_("Unresolved DW_AT_upper_bound "
17234 "- DIE at %s [in module %s]"),
17235 sect_offset_str (die
->sect_off
),
17236 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17237 if (attr_count
!= NULL
)
17238 complaint (_("Unresolved DW_AT_count "
17239 "- DIE at %s [in module %s]"),
17240 sect_offset_str (die
->sect_off
),
17241 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17246 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17247 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17248 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17250 /* Normally, the DWARF producers are expected to use a signed
17251 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17252 But this is unfortunately not always the case, as witnessed
17253 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17254 is used instead. To work around that ambiguity, we treat
17255 the bounds as signed, and thus sign-extend their values, when
17256 the base type is signed. */
17258 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17259 if (low
.kind
== PROP_CONST
17260 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17261 low
.data
.const_val
|= negative_mask
;
17262 if (high
.kind
== PROP_CONST
17263 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17264 high
.data
.const_val
|= negative_mask
;
17266 /* Check for bit and byte strides. */
17267 struct dynamic_prop byte_stride_prop
;
17268 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17269 if (attr_byte_stride
!= nullptr)
17271 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17272 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17276 struct dynamic_prop bit_stride_prop
;
17277 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17278 if (attr_bit_stride
!= nullptr)
17280 /* It only makes sense to have either a bit or byte stride. */
17281 if (attr_byte_stride
!= nullptr)
17283 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17284 "- DIE at %s [in module %s]"),
17285 sect_offset_str (die
->sect_off
),
17286 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17287 attr_bit_stride
= nullptr;
17291 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17292 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17297 if (attr_byte_stride
!= nullptr
17298 || attr_bit_stride
!= nullptr)
17300 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17301 struct dynamic_prop
*stride
17302 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17305 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17306 &high
, bias
, stride
, byte_stride_p
);
17309 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17311 if (high_bound_is_count
)
17312 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17314 /* Ada expects an empty array on no boundary attributes. */
17315 if (attr
== NULL
&& cu
->language
!= language_ada
)
17316 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17318 name
= dwarf2_name (die
, cu
);
17320 TYPE_NAME (range_type
) = name
;
17322 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17323 if (attr
!= nullptr)
17324 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17326 maybe_set_alignment (cu
, die
, range_type
);
17328 set_die_type (die
, range_type
, cu
);
17330 /* set_die_type should be already done. */
17331 set_descriptive_type (range_type
, die
, cu
);
17336 static struct type
*
17337 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17341 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17343 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17345 /* In Ada, an unspecified type is typically used when the description
17346 of the type is deferred to a different unit. When encountering
17347 such a type, we treat it as a stub, and try to resolve it later on,
17349 if (cu
->language
== language_ada
)
17350 TYPE_STUB (type
) = 1;
17352 return set_die_type (die
, type
, cu
);
17355 /* Read a single die and all its descendents. Set the die's sibling
17356 field to NULL; set other fields in the die correctly, and set all
17357 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17358 location of the info_ptr after reading all of those dies. PARENT
17359 is the parent of the die in question. */
17361 static struct die_info
*
17362 read_die_and_children (const struct die_reader_specs
*reader
,
17363 const gdb_byte
*info_ptr
,
17364 const gdb_byte
**new_info_ptr
,
17365 struct die_info
*parent
)
17367 struct die_info
*die
;
17368 const gdb_byte
*cur_ptr
;
17370 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17373 *new_info_ptr
= cur_ptr
;
17376 store_in_ref_table (die
, reader
->cu
);
17378 if (die
->has_children
)
17379 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17383 *new_info_ptr
= cur_ptr
;
17386 die
->sibling
= NULL
;
17387 die
->parent
= parent
;
17391 /* Read a die, all of its descendents, and all of its siblings; set
17392 all of the fields of all of the dies correctly. Arguments are as
17393 in read_die_and_children. */
17395 static struct die_info
*
17396 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17397 const gdb_byte
*info_ptr
,
17398 const gdb_byte
**new_info_ptr
,
17399 struct die_info
*parent
)
17401 struct die_info
*first_die
, *last_sibling
;
17402 const gdb_byte
*cur_ptr
;
17404 cur_ptr
= info_ptr
;
17405 first_die
= last_sibling
= NULL
;
17409 struct die_info
*die
17410 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17414 *new_info_ptr
= cur_ptr
;
17421 last_sibling
->sibling
= die
;
17423 last_sibling
= die
;
17427 /* Read a die, all of its descendents, and all of its siblings; set
17428 all of the fields of all of the dies correctly. Arguments are as
17429 in read_die_and_children.
17430 This the main entry point for reading a DIE and all its children. */
17432 static struct die_info
*
17433 read_die_and_siblings (const struct die_reader_specs
*reader
,
17434 const gdb_byte
*info_ptr
,
17435 const gdb_byte
**new_info_ptr
,
17436 struct die_info
*parent
)
17438 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17439 new_info_ptr
, parent
);
17441 if (dwarf_die_debug
)
17443 fprintf_unfiltered (gdb_stdlog
,
17444 "Read die from %s@0x%x of %s:\n",
17445 reader
->die_section
->get_name (),
17446 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17447 bfd_get_filename (reader
->abfd
));
17448 dump_die (die
, dwarf_die_debug
);
17454 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17456 The caller is responsible for filling in the extra attributes
17457 and updating (*DIEP)->num_attrs.
17458 Set DIEP to point to a newly allocated die with its information,
17459 except for its child, sibling, and parent fields. */
17461 static const gdb_byte
*
17462 read_full_die_1 (const struct die_reader_specs
*reader
,
17463 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17464 int num_extra_attrs
)
17466 unsigned int abbrev_number
, bytes_read
, i
;
17467 struct abbrev_info
*abbrev
;
17468 struct die_info
*die
;
17469 struct dwarf2_cu
*cu
= reader
->cu
;
17470 bfd
*abfd
= reader
->abfd
;
17472 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17473 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17474 info_ptr
+= bytes_read
;
17475 if (!abbrev_number
)
17481 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17483 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17485 bfd_get_filename (abfd
));
17487 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17488 die
->sect_off
= sect_off
;
17489 die
->tag
= abbrev
->tag
;
17490 die
->abbrev
= abbrev_number
;
17491 die
->has_children
= abbrev
->has_children
;
17493 /* Make the result usable.
17494 The caller needs to update num_attrs after adding the extra
17496 die
->num_attrs
= abbrev
->num_attrs
;
17498 std::vector
<int> indexes_that_need_reprocess
;
17499 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17501 bool need_reprocess
;
17503 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17504 info_ptr
, &need_reprocess
);
17505 if (need_reprocess
)
17506 indexes_that_need_reprocess
.push_back (i
);
17509 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17510 if (attr
!= nullptr)
17511 cu
->str_offsets_base
= DW_UNSND (attr
);
17513 auto maybe_addr_base
= die
->addr_base ();
17514 if (maybe_addr_base
.has_value ())
17515 cu
->addr_base
= *maybe_addr_base
;
17516 for (int index
: indexes_that_need_reprocess
)
17517 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17522 /* Read a die and all its attributes.
17523 Set DIEP to point to a newly allocated die with its information,
17524 except for its child, sibling, and parent fields. */
17526 static const gdb_byte
*
17527 read_full_die (const struct die_reader_specs
*reader
,
17528 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17530 const gdb_byte
*result
;
17532 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17534 if (dwarf_die_debug
)
17536 fprintf_unfiltered (gdb_stdlog
,
17537 "Read die from %s@0x%x of %s:\n",
17538 reader
->die_section
->get_name (),
17539 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17540 bfd_get_filename (reader
->abfd
));
17541 dump_die (*diep
, dwarf_die_debug
);
17548 /* Returns nonzero if TAG represents a type that we might generate a partial
17552 is_type_tag_for_partial (int tag
)
17557 /* Some types that would be reasonable to generate partial symbols for,
17558 that we don't at present. */
17559 case DW_TAG_array_type
:
17560 case DW_TAG_file_type
:
17561 case DW_TAG_ptr_to_member_type
:
17562 case DW_TAG_set_type
:
17563 case DW_TAG_string_type
:
17564 case DW_TAG_subroutine_type
:
17566 case DW_TAG_base_type
:
17567 case DW_TAG_class_type
:
17568 case DW_TAG_interface_type
:
17569 case DW_TAG_enumeration_type
:
17570 case DW_TAG_structure_type
:
17571 case DW_TAG_subrange_type
:
17572 case DW_TAG_typedef
:
17573 case DW_TAG_union_type
:
17580 /* Load all DIEs that are interesting for partial symbols into memory. */
17582 static struct partial_die_info
*
17583 load_partial_dies (const struct die_reader_specs
*reader
,
17584 const gdb_byte
*info_ptr
, int building_psymtab
)
17586 struct dwarf2_cu
*cu
= reader
->cu
;
17587 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17588 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17589 unsigned int bytes_read
;
17590 unsigned int load_all
= 0;
17591 int nesting_level
= 1;
17596 gdb_assert (cu
->per_cu
!= NULL
);
17597 if (cu
->per_cu
->load_all_dies
)
17601 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17605 &cu
->comp_unit_obstack
,
17606 hashtab_obstack_allocate
,
17607 dummy_obstack_deallocate
);
17611 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17613 /* A NULL abbrev means the end of a series of children. */
17614 if (abbrev
== NULL
)
17616 if (--nesting_level
== 0)
17619 info_ptr
+= bytes_read
;
17620 last_die
= parent_die
;
17621 parent_die
= parent_die
->die_parent
;
17625 /* Check for template arguments. We never save these; if
17626 they're seen, we just mark the parent, and go on our way. */
17627 if (parent_die
!= NULL
17628 && cu
->language
== language_cplus
17629 && (abbrev
->tag
== DW_TAG_template_type_param
17630 || abbrev
->tag
== DW_TAG_template_value_param
))
17632 parent_die
->has_template_arguments
= 1;
17636 /* We don't need a partial DIE for the template argument. */
17637 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17642 /* We only recurse into c++ subprograms looking for template arguments.
17643 Skip their other children. */
17645 && cu
->language
== language_cplus
17646 && parent_die
!= NULL
17647 && parent_die
->tag
== DW_TAG_subprogram
)
17649 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17653 /* Check whether this DIE is interesting enough to save. Normally
17654 we would not be interested in members here, but there may be
17655 later variables referencing them via DW_AT_specification (for
17656 static members). */
17658 && !is_type_tag_for_partial (abbrev
->tag
)
17659 && abbrev
->tag
!= DW_TAG_constant
17660 && abbrev
->tag
!= DW_TAG_enumerator
17661 && abbrev
->tag
!= DW_TAG_subprogram
17662 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17663 && abbrev
->tag
!= DW_TAG_lexical_block
17664 && abbrev
->tag
!= DW_TAG_variable
17665 && abbrev
->tag
!= DW_TAG_namespace
17666 && abbrev
->tag
!= DW_TAG_module
17667 && abbrev
->tag
!= DW_TAG_member
17668 && abbrev
->tag
!= DW_TAG_imported_unit
17669 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17671 /* Otherwise we skip to the next sibling, if any. */
17672 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17676 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17679 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17681 /* This two-pass algorithm for processing partial symbols has a
17682 high cost in cache pressure. Thus, handle some simple cases
17683 here which cover the majority of C partial symbols. DIEs
17684 which neither have specification tags in them, nor could have
17685 specification tags elsewhere pointing at them, can simply be
17686 processed and discarded.
17688 This segment is also optional; scan_partial_symbols and
17689 add_partial_symbol will handle these DIEs if we chain
17690 them in normally. When compilers which do not emit large
17691 quantities of duplicate debug information are more common,
17692 this code can probably be removed. */
17694 /* Any complete simple types at the top level (pretty much all
17695 of them, for a language without namespaces), can be processed
17697 if (parent_die
== NULL
17698 && pdi
.has_specification
== 0
17699 && pdi
.is_declaration
== 0
17700 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17701 || pdi
.tag
== DW_TAG_base_type
17702 || pdi
.tag
== DW_TAG_subrange_type
))
17704 if (building_psymtab
&& pdi
.name
!= NULL
)
17705 add_psymbol_to_list (pdi
.name
, false,
17706 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17707 psymbol_placement::STATIC
,
17708 0, cu
->language
, objfile
);
17709 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17713 /* The exception for DW_TAG_typedef with has_children above is
17714 a workaround of GCC PR debug/47510. In the case of this complaint
17715 type_name_or_error will error on such types later.
17717 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17718 it could not find the child DIEs referenced later, this is checked
17719 above. In correct DWARF DW_TAG_typedef should have no children. */
17721 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17722 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17723 "- DIE at %s [in module %s]"),
17724 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17726 /* If we're at the second level, and we're an enumerator, and
17727 our parent has no specification (meaning possibly lives in a
17728 namespace elsewhere), then we can add the partial symbol now
17729 instead of queueing it. */
17730 if (pdi
.tag
== DW_TAG_enumerator
17731 && parent_die
!= NULL
17732 && parent_die
->die_parent
== NULL
17733 && parent_die
->tag
== DW_TAG_enumeration_type
17734 && parent_die
->has_specification
== 0)
17736 if (pdi
.name
== NULL
)
17737 complaint (_("malformed enumerator DIE ignored"));
17738 else if (building_psymtab
)
17739 add_psymbol_to_list (pdi
.name
, false,
17740 VAR_DOMAIN
, LOC_CONST
, -1,
17741 cu
->language
== language_cplus
17742 ? psymbol_placement::GLOBAL
17743 : psymbol_placement::STATIC
,
17744 0, cu
->language
, objfile
);
17746 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17750 struct partial_die_info
*part_die
17751 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17753 /* We'll save this DIE so link it in. */
17754 part_die
->die_parent
= parent_die
;
17755 part_die
->die_sibling
= NULL
;
17756 part_die
->die_child
= NULL
;
17758 if (last_die
&& last_die
== parent_die
)
17759 last_die
->die_child
= part_die
;
17761 last_die
->die_sibling
= part_die
;
17763 last_die
= part_die
;
17765 if (first_die
== NULL
)
17766 first_die
= part_die
;
17768 /* Maybe add the DIE to the hash table. Not all DIEs that we
17769 find interesting need to be in the hash table, because we
17770 also have the parent/sibling/child chains; only those that we
17771 might refer to by offset later during partial symbol reading.
17773 For now this means things that might have be the target of a
17774 DW_AT_specification, DW_AT_abstract_origin, or
17775 DW_AT_extension. DW_AT_extension will refer only to
17776 namespaces; DW_AT_abstract_origin refers to functions (and
17777 many things under the function DIE, but we do not recurse
17778 into function DIEs during partial symbol reading) and
17779 possibly variables as well; DW_AT_specification refers to
17780 declarations. Declarations ought to have the DW_AT_declaration
17781 flag. It happens that GCC forgets to put it in sometimes, but
17782 only for functions, not for types.
17784 Adding more things than necessary to the hash table is harmless
17785 except for the performance cost. Adding too few will result in
17786 wasted time in find_partial_die, when we reread the compilation
17787 unit with load_all_dies set. */
17790 || abbrev
->tag
== DW_TAG_constant
17791 || abbrev
->tag
== DW_TAG_subprogram
17792 || abbrev
->tag
== DW_TAG_variable
17793 || abbrev
->tag
== DW_TAG_namespace
17794 || part_die
->is_declaration
)
17798 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17799 to_underlying (part_die
->sect_off
),
17804 /* For some DIEs we want to follow their children (if any). For C
17805 we have no reason to follow the children of structures; for other
17806 languages we have to, so that we can get at method physnames
17807 to infer fully qualified class names, for DW_AT_specification,
17808 and for C++ template arguments. For C++, we also look one level
17809 inside functions to find template arguments (if the name of the
17810 function does not already contain the template arguments).
17812 For Ada and Fortran, we need to scan the children of subprograms
17813 and lexical blocks as well because these languages allow the
17814 definition of nested entities that could be interesting for the
17815 debugger, such as nested subprograms for instance. */
17816 if (last_die
->has_children
17818 || last_die
->tag
== DW_TAG_namespace
17819 || last_die
->tag
== DW_TAG_module
17820 || last_die
->tag
== DW_TAG_enumeration_type
17821 || (cu
->language
== language_cplus
17822 && last_die
->tag
== DW_TAG_subprogram
17823 && (last_die
->name
== NULL
17824 || strchr (last_die
->name
, '<') == NULL
))
17825 || (cu
->language
!= language_c
17826 && (last_die
->tag
== DW_TAG_class_type
17827 || last_die
->tag
== DW_TAG_interface_type
17828 || last_die
->tag
== DW_TAG_structure_type
17829 || last_die
->tag
== DW_TAG_union_type
))
17830 || ((cu
->language
== language_ada
17831 || cu
->language
== language_fortran
)
17832 && (last_die
->tag
== DW_TAG_subprogram
17833 || last_die
->tag
== DW_TAG_lexical_block
))))
17836 parent_die
= last_die
;
17840 /* Otherwise we skip to the next sibling, if any. */
17841 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17843 /* Back to the top, do it again. */
17847 partial_die_info::partial_die_info (sect_offset sect_off_
,
17848 struct abbrev_info
*abbrev
)
17849 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17853 /* Read a minimal amount of information into the minimal die structure.
17854 INFO_PTR should point just after the initial uleb128 of a DIE. */
17857 partial_die_info::read (const struct die_reader_specs
*reader
,
17858 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17860 struct dwarf2_cu
*cu
= reader
->cu
;
17861 struct dwarf2_per_objfile
*dwarf2_per_objfile
17862 = cu
->per_cu
->dwarf2_per_objfile
;
17864 int has_low_pc_attr
= 0;
17865 int has_high_pc_attr
= 0;
17866 int high_pc_relative
= 0;
17868 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17869 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17871 bool need_reprocess
;
17872 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17873 info_ptr
, &need_reprocess
);
17874 /* String and address offsets that need to do the reprocessing have
17875 already been read at this point, so there is no need to wait until
17876 the loop terminates to do the reprocessing. */
17877 if (need_reprocess
)
17878 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17879 attribute
&attr
= attr_vec
[i
];
17880 /* Store the data if it is of an attribute we want to keep in a
17881 partial symbol table. */
17887 case DW_TAG_compile_unit
:
17888 case DW_TAG_partial_unit
:
17889 case DW_TAG_type_unit
:
17890 /* Compilation units have a DW_AT_name that is a filename, not
17891 a source language identifier. */
17892 case DW_TAG_enumeration_type
:
17893 case DW_TAG_enumerator
:
17894 /* These tags always have simple identifiers already; no need
17895 to canonicalize them. */
17896 name
= DW_STRING (&attr
);
17900 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17903 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
17908 case DW_AT_linkage_name
:
17909 case DW_AT_MIPS_linkage_name
:
17910 /* Note that both forms of linkage name might appear. We
17911 assume they will be the same, and we only store the last
17913 linkage_name
= DW_STRING (&attr
);
17916 has_low_pc_attr
= 1;
17917 lowpc
= attr
.value_as_address ();
17919 case DW_AT_high_pc
:
17920 has_high_pc_attr
= 1;
17921 highpc
= attr
.value_as_address ();
17922 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17923 high_pc_relative
= 1;
17925 case DW_AT_location
:
17926 /* Support the .debug_loc offsets. */
17927 if (attr
.form_is_block ())
17929 d
.locdesc
= DW_BLOCK (&attr
);
17931 else if (attr
.form_is_section_offset ())
17933 dwarf2_complex_location_expr_complaint ();
17937 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17938 "partial symbol information");
17941 case DW_AT_external
:
17942 is_external
= DW_UNSND (&attr
);
17944 case DW_AT_declaration
:
17945 is_declaration
= DW_UNSND (&attr
);
17950 case DW_AT_abstract_origin
:
17951 case DW_AT_specification
:
17952 case DW_AT_extension
:
17953 has_specification
= 1;
17954 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
17955 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
17956 || cu
->per_cu
->is_dwz
);
17958 case DW_AT_sibling
:
17959 /* Ignore absolute siblings, they might point outside of
17960 the current compile unit. */
17961 if (attr
.form
== DW_FORM_ref_addr
)
17962 complaint (_("ignoring absolute DW_AT_sibling"));
17965 const gdb_byte
*buffer
= reader
->buffer
;
17966 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
17967 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
17969 if (sibling_ptr
< info_ptr
)
17970 complaint (_("DW_AT_sibling points backwards"));
17971 else if (sibling_ptr
> reader
->buffer_end
)
17972 reader
->die_section
->overflow_complaint ();
17974 sibling
= sibling_ptr
;
17977 case DW_AT_byte_size
:
17980 case DW_AT_const_value
:
17981 has_const_value
= 1;
17983 case DW_AT_calling_convention
:
17984 /* DWARF doesn't provide a way to identify a program's source-level
17985 entry point. DW_AT_calling_convention attributes are only meant
17986 to describe functions' calling conventions.
17988 However, because it's a necessary piece of information in
17989 Fortran, and before DWARF 4 DW_CC_program was the only
17990 piece of debugging information whose definition refers to
17991 a 'main program' at all, several compilers marked Fortran
17992 main programs with DW_CC_program --- even when those
17993 functions use the standard calling conventions.
17995 Although DWARF now specifies a way to provide this
17996 information, we support this practice for backward
17998 if (DW_UNSND (&attr
) == DW_CC_program
17999 && cu
->language
== language_fortran
)
18000 main_subprogram
= 1;
18003 if (DW_UNSND (&attr
) == DW_INL_inlined
18004 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18005 may_be_inlined
= 1;
18009 if (tag
== DW_TAG_imported_unit
)
18011 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18012 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18013 || cu
->per_cu
->is_dwz
);
18017 case DW_AT_main_subprogram
:
18018 main_subprogram
= DW_UNSND (&attr
);
18023 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18024 but that requires a full DIE, so instead we just
18026 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18027 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18028 + (need_ranges_base
18032 /* Value of the DW_AT_ranges attribute is the offset in the
18033 .debug_ranges section. */
18034 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18045 /* For Ada, if both the name and the linkage name appear, we prefer
18046 the latter. This lets "catch exception" work better, regardless
18047 of the order in which the name and linkage name were emitted.
18048 Really, though, this is just a workaround for the fact that gdb
18049 doesn't store both the name and the linkage name. */
18050 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18051 name
= linkage_name
;
18053 if (high_pc_relative
)
18056 if (has_low_pc_attr
&& has_high_pc_attr
)
18058 /* When using the GNU linker, .gnu.linkonce. sections are used to
18059 eliminate duplicate copies of functions and vtables and such.
18060 The linker will arbitrarily choose one and discard the others.
18061 The AT_*_pc values for such functions refer to local labels in
18062 these sections. If the section from that file was discarded, the
18063 labels are not in the output, so the relocs get a value of 0.
18064 If this is a discarded function, mark the pc bounds as invalid,
18065 so that GDB will ignore it. */
18066 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18068 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18069 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18071 complaint (_("DW_AT_low_pc %s is zero "
18072 "for DIE at %s [in module %s]"),
18073 paddress (gdbarch
, lowpc
),
18074 sect_offset_str (sect_off
),
18075 objfile_name (objfile
));
18077 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18078 else if (lowpc
>= highpc
)
18080 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18081 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18083 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18084 "for DIE at %s [in module %s]"),
18085 paddress (gdbarch
, lowpc
),
18086 paddress (gdbarch
, highpc
),
18087 sect_offset_str (sect_off
),
18088 objfile_name (objfile
));
18097 /* Find a cached partial DIE at OFFSET in CU. */
18099 struct partial_die_info
*
18100 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18102 struct partial_die_info
*lookup_die
= NULL
;
18103 struct partial_die_info
part_die (sect_off
);
18105 lookup_die
= ((struct partial_die_info
*)
18106 htab_find_with_hash (partial_dies
, &part_die
,
18107 to_underlying (sect_off
)));
18112 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18113 except in the case of .debug_types DIEs which do not reference
18114 outside their CU (they do however referencing other types via
18115 DW_FORM_ref_sig8). */
18117 static const struct cu_partial_die_info
18118 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18120 struct dwarf2_per_objfile
*dwarf2_per_objfile
18121 = cu
->per_cu
->dwarf2_per_objfile
;
18122 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18123 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18124 struct partial_die_info
*pd
= NULL
;
18126 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18127 && cu
->header
.offset_in_cu_p (sect_off
))
18129 pd
= cu
->find_partial_die (sect_off
);
18132 /* We missed recording what we needed.
18133 Load all dies and try again. */
18134 per_cu
= cu
->per_cu
;
18138 /* TUs don't reference other CUs/TUs (except via type signatures). */
18139 if (cu
->per_cu
->is_debug_types
)
18141 error (_("Dwarf Error: Type Unit at offset %s contains"
18142 " external reference to offset %s [in module %s].\n"),
18143 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18144 bfd_get_filename (objfile
->obfd
));
18146 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18147 dwarf2_per_objfile
);
18149 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18150 load_partial_comp_unit (per_cu
);
18152 per_cu
->cu
->last_used
= 0;
18153 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18156 /* If we didn't find it, and not all dies have been loaded,
18157 load them all and try again. */
18159 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18161 per_cu
->load_all_dies
= 1;
18163 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18164 THIS_CU->cu may already be in use. So we can't just free it and
18165 replace its DIEs with the ones we read in. Instead, we leave those
18166 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18167 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18169 load_partial_comp_unit (per_cu
);
18171 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18175 internal_error (__FILE__
, __LINE__
,
18176 _("could not find partial DIE %s "
18177 "in cache [from module %s]\n"),
18178 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18179 return { per_cu
->cu
, pd
};
18182 /* See if we can figure out if the class lives in a namespace. We do
18183 this by looking for a member function; its demangled name will
18184 contain namespace info, if there is any. */
18187 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18188 struct dwarf2_cu
*cu
)
18190 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18191 what template types look like, because the demangler
18192 frequently doesn't give the same name as the debug info. We
18193 could fix this by only using the demangled name to get the
18194 prefix (but see comment in read_structure_type). */
18196 struct partial_die_info
*real_pdi
;
18197 struct partial_die_info
*child_pdi
;
18199 /* If this DIE (this DIE's specification, if any) has a parent, then
18200 we should not do this. We'll prepend the parent's fully qualified
18201 name when we create the partial symbol. */
18203 real_pdi
= struct_pdi
;
18204 while (real_pdi
->has_specification
)
18206 auto res
= find_partial_die (real_pdi
->spec_offset
,
18207 real_pdi
->spec_is_dwz
, cu
);
18208 real_pdi
= res
.pdi
;
18212 if (real_pdi
->die_parent
!= NULL
)
18215 for (child_pdi
= struct_pdi
->die_child
;
18217 child_pdi
= child_pdi
->die_sibling
)
18219 if (child_pdi
->tag
== DW_TAG_subprogram
18220 && child_pdi
->linkage_name
!= NULL
)
18222 gdb::unique_xmalloc_ptr
<char> actual_class_name
18223 (language_class_name_from_physname (cu
->language_defn
,
18224 child_pdi
->linkage_name
));
18225 if (actual_class_name
!= NULL
)
18227 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18228 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18236 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18238 /* Once we've fixed up a die, there's no point in doing so again.
18239 This also avoids a memory leak if we were to call
18240 guess_partial_die_structure_name multiple times. */
18244 /* If we found a reference attribute and the DIE has no name, try
18245 to find a name in the referred to DIE. */
18247 if (name
== NULL
&& has_specification
)
18249 struct partial_die_info
*spec_die
;
18251 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18252 spec_die
= res
.pdi
;
18255 spec_die
->fixup (cu
);
18257 if (spec_die
->name
)
18259 name
= spec_die
->name
;
18261 /* Copy DW_AT_external attribute if it is set. */
18262 if (spec_die
->is_external
)
18263 is_external
= spec_die
->is_external
;
18267 /* Set default names for some unnamed DIEs. */
18269 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18270 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18272 /* If there is no parent die to provide a namespace, and there are
18273 children, see if we can determine the namespace from their linkage
18275 if (cu
->language
== language_cplus
18276 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18277 && die_parent
== NULL
18279 && (tag
== DW_TAG_class_type
18280 || tag
== DW_TAG_structure_type
18281 || tag
== DW_TAG_union_type
))
18282 guess_partial_die_structure_name (this, cu
);
18284 /* GCC might emit a nameless struct or union that has a linkage
18285 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18287 && (tag
== DW_TAG_class_type
18288 || tag
== DW_TAG_interface_type
18289 || tag
== DW_TAG_structure_type
18290 || tag
== DW_TAG_union_type
)
18291 && linkage_name
!= NULL
)
18293 gdb::unique_xmalloc_ptr
<char> demangled
18294 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18295 if (demangled
!= nullptr)
18299 /* Strip any leading namespaces/classes, keep only the base name.
18300 DW_AT_name for named DIEs does not contain the prefixes. */
18301 base
= strrchr (demangled
.get (), ':');
18302 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18305 base
= demangled
.get ();
18307 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18308 name
= objfile
->intern (base
);
18315 /* Process the attributes that had to be skipped in the first round. These
18316 attributes are the ones that need str_offsets_base or addr_base attributes.
18317 They could not have been processed in the first round, because at the time
18318 the values of str_offsets_base or addr_base may not have been known. */
18319 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18320 struct attribute
*attr
)
18322 struct dwarf2_cu
*cu
= reader
->cu
;
18323 switch (attr
->form
)
18325 case DW_FORM_addrx
:
18326 case DW_FORM_GNU_addr_index
:
18327 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18330 case DW_FORM_strx1
:
18331 case DW_FORM_strx2
:
18332 case DW_FORM_strx3
:
18333 case DW_FORM_strx4
:
18334 case DW_FORM_GNU_str_index
:
18336 unsigned int str_index
= DW_UNSND (attr
);
18337 if (reader
->dwo_file
!= NULL
)
18339 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18340 DW_STRING_IS_CANONICAL (attr
) = 0;
18344 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18345 DW_STRING_IS_CANONICAL (attr
) = 0;
18350 gdb_assert_not_reached (_("Unexpected DWARF form."));
18354 /* Read an attribute value described by an attribute form. */
18356 static const gdb_byte
*
18357 read_attribute_value (const struct die_reader_specs
*reader
,
18358 struct attribute
*attr
, unsigned form
,
18359 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18360 bool *need_reprocess
)
18362 struct dwarf2_cu
*cu
= reader
->cu
;
18363 struct dwarf2_per_objfile
*dwarf2_per_objfile
18364 = cu
->per_cu
->dwarf2_per_objfile
;
18365 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18366 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18367 bfd
*abfd
= reader
->abfd
;
18368 struct comp_unit_head
*cu_header
= &cu
->header
;
18369 unsigned int bytes_read
;
18370 struct dwarf_block
*blk
;
18371 *need_reprocess
= false;
18373 attr
->form
= (enum dwarf_form
) form
;
18376 case DW_FORM_ref_addr
:
18377 if (cu
->header
.version
== 2)
18378 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18381 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18383 info_ptr
+= bytes_read
;
18385 case DW_FORM_GNU_ref_alt
:
18386 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18387 info_ptr
+= bytes_read
;
18390 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18391 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18392 info_ptr
+= bytes_read
;
18394 case DW_FORM_block2
:
18395 blk
= dwarf_alloc_block (cu
);
18396 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18398 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18399 info_ptr
+= blk
->size
;
18400 DW_BLOCK (attr
) = blk
;
18402 case DW_FORM_block4
:
18403 blk
= dwarf_alloc_block (cu
);
18404 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18406 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18407 info_ptr
+= blk
->size
;
18408 DW_BLOCK (attr
) = blk
;
18410 case DW_FORM_data2
:
18411 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18414 case DW_FORM_data4
:
18415 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18418 case DW_FORM_data8
:
18419 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18422 case DW_FORM_data16
:
18423 blk
= dwarf_alloc_block (cu
);
18425 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18427 DW_BLOCK (attr
) = blk
;
18429 case DW_FORM_sec_offset
:
18430 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18431 info_ptr
+= bytes_read
;
18433 case DW_FORM_string
:
18434 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18435 DW_STRING_IS_CANONICAL (attr
) = 0;
18436 info_ptr
+= bytes_read
;
18439 if (!cu
->per_cu
->is_dwz
)
18441 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18442 abfd
, info_ptr
, cu_header
,
18444 DW_STRING_IS_CANONICAL (attr
) = 0;
18445 info_ptr
+= bytes_read
;
18449 case DW_FORM_line_strp
:
18450 if (!cu
->per_cu
->is_dwz
)
18453 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18455 DW_STRING_IS_CANONICAL (attr
) = 0;
18456 info_ptr
+= bytes_read
;
18460 case DW_FORM_GNU_strp_alt
:
18462 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18463 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18466 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18467 DW_STRING_IS_CANONICAL (attr
) = 0;
18468 info_ptr
+= bytes_read
;
18471 case DW_FORM_exprloc
:
18472 case DW_FORM_block
:
18473 blk
= dwarf_alloc_block (cu
);
18474 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18475 info_ptr
+= bytes_read
;
18476 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18477 info_ptr
+= blk
->size
;
18478 DW_BLOCK (attr
) = blk
;
18480 case DW_FORM_block1
:
18481 blk
= dwarf_alloc_block (cu
);
18482 blk
->size
= read_1_byte (abfd
, info_ptr
);
18484 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18485 info_ptr
+= blk
->size
;
18486 DW_BLOCK (attr
) = blk
;
18488 case DW_FORM_data1
:
18489 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18493 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18496 case DW_FORM_flag_present
:
18497 DW_UNSND (attr
) = 1;
18499 case DW_FORM_sdata
:
18500 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18501 info_ptr
+= bytes_read
;
18503 case DW_FORM_udata
:
18504 case DW_FORM_rnglistx
:
18505 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18506 info_ptr
+= bytes_read
;
18509 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18510 + read_1_byte (abfd
, info_ptr
));
18514 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18515 + read_2_bytes (abfd
, info_ptr
));
18519 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18520 + read_4_bytes (abfd
, info_ptr
));
18524 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18525 + read_8_bytes (abfd
, info_ptr
));
18528 case DW_FORM_ref_sig8
:
18529 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18532 case DW_FORM_ref_udata
:
18533 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18534 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18535 info_ptr
+= bytes_read
;
18537 case DW_FORM_indirect
:
18538 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18539 info_ptr
+= bytes_read
;
18540 if (form
== DW_FORM_implicit_const
)
18542 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18543 info_ptr
+= bytes_read
;
18545 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18546 info_ptr
, need_reprocess
);
18548 case DW_FORM_implicit_const
:
18549 DW_SND (attr
) = implicit_const
;
18551 case DW_FORM_addrx
:
18552 case DW_FORM_GNU_addr_index
:
18553 *need_reprocess
= true;
18554 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18555 info_ptr
+= bytes_read
;
18558 case DW_FORM_strx1
:
18559 case DW_FORM_strx2
:
18560 case DW_FORM_strx3
:
18561 case DW_FORM_strx4
:
18562 case DW_FORM_GNU_str_index
:
18564 ULONGEST str_index
;
18565 if (form
== DW_FORM_strx1
)
18567 str_index
= read_1_byte (abfd
, info_ptr
);
18570 else if (form
== DW_FORM_strx2
)
18572 str_index
= read_2_bytes (abfd
, info_ptr
);
18575 else if (form
== DW_FORM_strx3
)
18577 str_index
= read_3_bytes (abfd
, info_ptr
);
18580 else if (form
== DW_FORM_strx4
)
18582 str_index
= read_4_bytes (abfd
, info_ptr
);
18587 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18588 info_ptr
+= bytes_read
;
18590 *need_reprocess
= true;
18591 DW_UNSND (attr
) = str_index
;
18595 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18596 dwarf_form_name (form
),
18597 bfd_get_filename (abfd
));
18601 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18602 attr
->form
= DW_FORM_GNU_ref_alt
;
18604 /* We have seen instances where the compiler tried to emit a byte
18605 size attribute of -1 which ended up being encoded as an unsigned
18606 0xffffffff. Although 0xffffffff is technically a valid size value,
18607 an object of this size seems pretty unlikely so we can relatively
18608 safely treat these cases as if the size attribute was invalid and
18609 treat them as zero by default. */
18610 if (attr
->name
== DW_AT_byte_size
18611 && form
== DW_FORM_data4
18612 && DW_UNSND (attr
) >= 0xffffffff)
18615 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18616 hex_string (DW_UNSND (attr
)));
18617 DW_UNSND (attr
) = 0;
18623 /* Read an attribute described by an abbreviated attribute. */
18625 static const gdb_byte
*
18626 read_attribute (const struct die_reader_specs
*reader
,
18627 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18628 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18630 attr
->name
= abbrev
->name
;
18631 return read_attribute_value (reader
, attr
, abbrev
->form
,
18632 abbrev
->implicit_const
, info_ptr
,
18636 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18638 static const char *
18639 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18640 LONGEST str_offset
)
18642 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18643 str_offset
, "DW_FORM_strp");
18646 /* Return pointer to string at .debug_str offset as read from BUF.
18647 BUF is assumed to be in a compilation unit described by CU_HEADER.
18648 Return *BYTES_READ_PTR count of bytes read from BUF. */
18650 static const char *
18651 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18652 const gdb_byte
*buf
,
18653 const struct comp_unit_head
*cu_header
,
18654 unsigned int *bytes_read_ptr
)
18656 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18658 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18664 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18665 const struct comp_unit_head
*cu_header
,
18666 unsigned int *bytes_read_ptr
)
18668 bfd
*abfd
= objfile
->obfd
;
18669 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18671 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18674 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18675 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18676 ADDR_SIZE is the size of addresses from the CU header. */
18679 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18680 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18683 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18684 bfd
*abfd
= objfile
->obfd
;
18685 const gdb_byte
*info_ptr
;
18686 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18688 dwarf2_per_objfile
->addr
.read (objfile
);
18689 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18690 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18691 objfile_name (objfile
));
18692 if (addr_base_or_zero
+ addr_index
* addr_size
18693 >= dwarf2_per_objfile
->addr
.size
)
18694 error (_("DW_FORM_addr_index pointing outside of "
18695 ".debug_addr section [in module %s]"),
18696 objfile_name (objfile
));
18697 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18698 + addr_base_or_zero
+ addr_index
* addr_size
);
18699 if (addr_size
== 4)
18700 return bfd_get_32 (abfd
, info_ptr
);
18702 return bfd_get_64 (abfd
, info_ptr
);
18705 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18708 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18710 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18711 cu
->addr_base
, cu
->header
.addr_size
);
18714 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18717 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18718 unsigned int *bytes_read
)
18720 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18721 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18723 return read_addr_index (cu
, addr_index
);
18729 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18731 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18732 struct dwarf2_cu
*cu
= per_cu
->cu
;
18733 gdb::optional
<ULONGEST
> addr_base
;
18736 /* We need addr_base and addr_size.
18737 If we don't have PER_CU->cu, we have to get it.
18738 Nasty, but the alternative is storing the needed info in PER_CU,
18739 which at this point doesn't seem justified: it's not clear how frequently
18740 it would get used and it would increase the size of every PER_CU.
18741 Entry points like dwarf2_per_cu_addr_size do a similar thing
18742 so we're not in uncharted territory here.
18743 Alas we need to be a bit more complicated as addr_base is contained
18746 We don't need to read the entire CU(/TU).
18747 We just need the header and top level die.
18749 IWBN to use the aging mechanism to let us lazily later discard the CU.
18750 For now we skip this optimization. */
18754 addr_base
= cu
->addr_base
;
18755 addr_size
= cu
->header
.addr_size
;
18759 cutu_reader
reader (per_cu
, NULL
, 0, false);
18760 addr_base
= reader
.cu
->addr_base
;
18761 addr_size
= reader
.cu
->header
.addr_size
;
18764 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18768 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18769 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18772 static const char *
18773 read_str_index (struct dwarf2_cu
*cu
,
18774 struct dwarf2_section_info
*str_section
,
18775 struct dwarf2_section_info
*str_offsets_section
,
18776 ULONGEST str_offsets_base
, ULONGEST str_index
)
18778 struct dwarf2_per_objfile
*dwarf2_per_objfile
18779 = cu
->per_cu
->dwarf2_per_objfile
;
18780 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18781 const char *objf_name
= objfile_name (objfile
);
18782 bfd
*abfd
= objfile
->obfd
;
18783 const gdb_byte
*info_ptr
;
18784 ULONGEST str_offset
;
18785 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18787 str_section
->read (objfile
);
18788 str_offsets_section
->read (objfile
);
18789 if (str_section
->buffer
== NULL
)
18790 error (_("%s used without %s section"
18791 " in CU at offset %s [in module %s]"),
18792 form_name
, str_section
->get_name (),
18793 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18794 if (str_offsets_section
->buffer
== NULL
)
18795 error (_("%s used without %s section"
18796 " in CU at offset %s [in module %s]"),
18797 form_name
, str_section
->get_name (),
18798 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18799 info_ptr
= (str_offsets_section
->buffer
18801 + str_index
* cu
->header
.offset_size
);
18802 if (cu
->header
.offset_size
== 4)
18803 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18805 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18806 if (str_offset
>= str_section
->size
)
18807 error (_("Offset from %s pointing outside of"
18808 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18809 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18810 return (const char *) (str_section
->buffer
+ str_offset
);
18813 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18815 static const char *
18816 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18818 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18819 ? reader
->cu
->header
.addr_size
: 0;
18820 return read_str_index (reader
->cu
,
18821 &reader
->dwo_file
->sections
.str
,
18822 &reader
->dwo_file
->sections
.str_offsets
,
18823 str_offsets_base
, str_index
);
18826 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18828 static const char *
18829 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18831 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18832 const char *objf_name
= objfile_name (objfile
);
18833 static const char form_name
[] = "DW_FORM_GNU_str_index";
18834 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18836 if (!cu
->str_offsets_base
.has_value ())
18837 error (_("%s used in Fission stub without %s"
18838 " in CU at offset 0x%lx [in module %s]"),
18839 form_name
, str_offsets_attr_name
,
18840 (long) cu
->header
.offset_size
, objf_name
);
18842 return read_str_index (cu
,
18843 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18844 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18845 *cu
->str_offsets_base
, str_index
);
18848 /* Return the length of an LEB128 number in BUF. */
18851 leb128_size (const gdb_byte
*buf
)
18853 const gdb_byte
*begin
= buf
;
18859 if ((byte
& 128) == 0)
18860 return buf
- begin
;
18865 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
18874 cu
->language
= language_c
;
18877 case DW_LANG_C_plus_plus
:
18878 case DW_LANG_C_plus_plus_11
:
18879 case DW_LANG_C_plus_plus_14
:
18880 cu
->language
= language_cplus
;
18883 cu
->language
= language_d
;
18885 case DW_LANG_Fortran77
:
18886 case DW_LANG_Fortran90
:
18887 case DW_LANG_Fortran95
:
18888 case DW_LANG_Fortran03
:
18889 case DW_LANG_Fortran08
:
18890 cu
->language
= language_fortran
;
18893 cu
->language
= language_go
;
18895 case DW_LANG_Mips_Assembler
:
18896 cu
->language
= language_asm
;
18898 case DW_LANG_Ada83
:
18899 case DW_LANG_Ada95
:
18900 cu
->language
= language_ada
;
18902 case DW_LANG_Modula2
:
18903 cu
->language
= language_m2
;
18905 case DW_LANG_Pascal83
:
18906 cu
->language
= language_pascal
;
18909 cu
->language
= language_objc
;
18912 case DW_LANG_Rust_old
:
18913 cu
->language
= language_rust
;
18915 case DW_LANG_Cobol74
:
18916 case DW_LANG_Cobol85
:
18918 cu
->language
= language_minimal
;
18921 cu
->language_defn
= language_def (cu
->language
);
18924 /* Return the named attribute or NULL if not there. */
18926 static struct attribute
*
18927 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18932 struct attribute
*spec
= NULL
;
18934 for (i
= 0; i
< die
->num_attrs
; ++i
)
18936 if (die
->attrs
[i
].name
== name
)
18937 return &die
->attrs
[i
];
18938 if (die
->attrs
[i
].name
== DW_AT_specification
18939 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
18940 spec
= &die
->attrs
[i
];
18946 die
= follow_die_ref (die
, spec
, &cu
);
18952 /* Return the string associated with a string-typed attribute, or NULL if it
18953 is either not found or is of an incorrect type. */
18955 static const char *
18956 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18958 struct attribute
*attr
;
18959 const char *str
= NULL
;
18961 attr
= dwarf2_attr (die
, name
, cu
);
18965 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
18966 || attr
->form
== DW_FORM_string
18967 || attr
->form
== DW_FORM_strx
18968 || attr
->form
== DW_FORM_strx1
18969 || attr
->form
== DW_FORM_strx2
18970 || attr
->form
== DW_FORM_strx3
18971 || attr
->form
== DW_FORM_strx4
18972 || attr
->form
== DW_FORM_GNU_str_index
18973 || attr
->form
== DW_FORM_GNU_strp_alt
)
18974 str
= DW_STRING (attr
);
18976 complaint (_("string type expected for attribute %s for "
18977 "DIE at %s in module %s"),
18978 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
18979 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18985 /* Return the dwo name or NULL if not present. If present, it is in either
18986 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
18987 static const char *
18988 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18990 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
18991 if (dwo_name
== nullptr)
18992 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
18996 /* Return non-zero iff the attribute NAME is defined for the given DIE,
18997 and holds a non-zero value. This function should only be used for
18998 DW_FORM_flag or DW_FORM_flag_present attributes. */
19001 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19003 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19005 return (attr
&& DW_UNSND (attr
));
19009 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19011 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19012 which value is non-zero. However, we have to be careful with
19013 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19014 (via dwarf2_flag_true_p) follows this attribute. So we may
19015 end up accidently finding a declaration attribute that belongs
19016 to a different DIE referenced by the specification attribute,
19017 even though the given DIE does not have a declaration attribute. */
19018 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19019 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19022 /* Return the die giving the specification for DIE, if there is
19023 one. *SPEC_CU is the CU containing DIE on input, and the CU
19024 containing the return value on output. If there is no
19025 specification, but there is an abstract origin, that is
19028 static struct die_info
*
19029 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19031 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19034 if (spec_attr
== NULL
)
19035 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19037 if (spec_attr
== NULL
)
19040 return follow_die_ref (die
, spec_attr
, spec_cu
);
19043 /* Stub for free_line_header to match void * callback types. */
19046 free_line_header_voidp (void *arg
)
19048 struct line_header
*lh
= (struct line_header
*) arg
;
19053 /* A convenience function to find the proper .debug_line section for a CU. */
19055 static struct dwarf2_section_info
*
19056 get_debug_line_section (struct dwarf2_cu
*cu
)
19058 struct dwarf2_section_info
*section
;
19059 struct dwarf2_per_objfile
*dwarf2_per_objfile
19060 = cu
->per_cu
->dwarf2_per_objfile
;
19062 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19064 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19065 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19066 else if (cu
->per_cu
->is_dwz
)
19068 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19070 section
= &dwz
->line
;
19073 section
= &dwarf2_per_objfile
->line
;
19078 /* Read the statement program header starting at OFFSET in
19079 .debug_line, or .debug_line.dwo. Return a pointer
19080 to a struct line_header, allocated using xmalloc.
19081 Returns NULL if there is a problem reading the header, e.g., if it
19082 has a version we don't understand.
19084 NOTE: the strings in the include directory and file name tables of
19085 the returned object point into the dwarf line section buffer,
19086 and must not be freed. */
19088 static line_header_up
19089 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19091 struct dwarf2_section_info
*section
;
19092 struct dwarf2_per_objfile
*dwarf2_per_objfile
19093 = cu
->per_cu
->dwarf2_per_objfile
;
19095 section
= get_debug_line_section (cu
);
19096 section
->read (dwarf2_per_objfile
->objfile
);
19097 if (section
->buffer
== NULL
)
19099 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19100 complaint (_("missing .debug_line.dwo section"));
19102 complaint (_("missing .debug_line section"));
19106 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19107 dwarf2_per_objfile
, section
,
19111 /* Subroutine of dwarf_decode_lines to simplify it.
19112 Return the file name of the psymtab for the given file_entry.
19113 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19114 If space for the result is malloc'd, *NAME_HOLDER will be set.
19115 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19117 static const char *
19118 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19119 const dwarf2_psymtab
*pst
,
19120 const char *comp_dir
,
19121 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19123 const char *include_name
= fe
.name
;
19124 const char *include_name_to_compare
= include_name
;
19125 const char *pst_filename
;
19128 const char *dir_name
= fe
.include_dir (lh
);
19130 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19131 if (!IS_ABSOLUTE_PATH (include_name
)
19132 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19134 /* Avoid creating a duplicate psymtab for PST.
19135 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19136 Before we do the comparison, however, we need to account
19137 for DIR_NAME and COMP_DIR.
19138 First prepend dir_name (if non-NULL). If we still don't
19139 have an absolute path prepend comp_dir (if non-NULL).
19140 However, the directory we record in the include-file's
19141 psymtab does not contain COMP_DIR (to match the
19142 corresponding symtab(s)).
19147 bash$ gcc -g ./hello.c
19148 include_name = "hello.c"
19150 DW_AT_comp_dir = comp_dir = "/tmp"
19151 DW_AT_name = "./hello.c"
19155 if (dir_name
!= NULL
)
19157 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19158 include_name
, (char *) NULL
));
19159 include_name
= name_holder
->get ();
19160 include_name_to_compare
= include_name
;
19162 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19164 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19165 include_name
, (char *) NULL
));
19166 include_name_to_compare
= hold_compare
.get ();
19170 pst_filename
= pst
->filename
;
19171 gdb::unique_xmalloc_ptr
<char> copied_name
;
19172 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19174 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19175 pst_filename
, (char *) NULL
));
19176 pst_filename
= copied_name
.get ();
19179 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19183 return include_name
;
19186 /* State machine to track the state of the line number program. */
19188 class lnp_state_machine
19191 /* Initialize a machine state for the start of a line number
19193 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19194 bool record_lines_p
);
19196 file_entry
*current_file ()
19198 /* lh->file_names is 0-based, but the file name numbers in the
19199 statement program are 1-based. */
19200 return m_line_header
->file_name_at (m_file
);
19203 /* Record the line in the state machine. END_SEQUENCE is true if
19204 we're processing the end of a sequence. */
19205 void record_line (bool end_sequence
);
19207 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19208 nop-out rest of the lines in this sequence. */
19209 void check_line_address (struct dwarf2_cu
*cu
,
19210 const gdb_byte
*line_ptr
,
19211 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19213 void handle_set_discriminator (unsigned int discriminator
)
19215 m_discriminator
= discriminator
;
19216 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19219 /* Handle DW_LNE_set_address. */
19220 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19223 address
+= baseaddr
;
19224 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19227 /* Handle DW_LNS_advance_pc. */
19228 void handle_advance_pc (CORE_ADDR adjust
);
19230 /* Handle a special opcode. */
19231 void handle_special_opcode (unsigned char op_code
);
19233 /* Handle DW_LNS_advance_line. */
19234 void handle_advance_line (int line_delta
)
19236 advance_line (line_delta
);
19239 /* Handle DW_LNS_set_file. */
19240 void handle_set_file (file_name_index file
);
19242 /* Handle DW_LNS_negate_stmt. */
19243 void handle_negate_stmt ()
19245 m_is_stmt
= !m_is_stmt
;
19248 /* Handle DW_LNS_const_add_pc. */
19249 void handle_const_add_pc ();
19251 /* Handle DW_LNS_fixed_advance_pc. */
19252 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19254 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19258 /* Handle DW_LNS_copy. */
19259 void handle_copy ()
19261 record_line (false);
19262 m_discriminator
= 0;
19265 /* Handle DW_LNE_end_sequence. */
19266 void handle_end_sequence ()
19268 m_currently_recording_lines
= true;
19272 /* Advance the line by LINE_DELTA. */
19273 void advance_line (int line_delta
)
19275 m_line
+= line_delta
;
19277 if (line_delta
!= 0)
19278 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19281 struct dwarf2_cu
*m_cu
;
19283 gdbarch
*m_gdbarch
;
19285 /* True if we're recording lines.
19286 Otherwise we're building partial symtabs and are just interested in
19287 finding include files mentioned by the line number program. */
19288 bool m_record_lines_p
;
19290 /* The line number header. */
19291 line_header
*m_line_header
;
19293 /* These are part of the standard DWARF line number state machine,
19294 and initialized according to the DWARF spec. */
19296 unsigned char m_op_index
= 0;
19297 /* The line table index of the current file. */
19298 file_name_index m_file
= 1;
19299 unsigned int m_line
= 1;
19301 /* These are initialized in the constructor. */
19303 CORE_ADDR m_address
;
19305 unsigned int m_discriminator
;
19307 /* Additional bits of state we need to track. */
19309 /* The last file that we called dwarf2_start_subfile for.
19310 This is only used for TLLs. */
19311 unsigned int m_last_file
= 0;
19312 /* The last file a line number was recorded for. */
19313 struct subfile
*m_last_subfile
= NULL
;
19315 /* When true, record the lines we decode. */
19316 bool m_currently_recording_lines
= false;
19318 /* The last line number that was recorded, used to coalesce
19319 consecutive entries for the same line. This can happen, for
19320 example, when discriminators are present. PR 17276. */
19321 unsigned int m_last_line
= 0;
19322 bool m_line_has_non_zero_discriminator
= false;
19326 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19328 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19329 / m_line_header
->maximum_ops_per_instruction
)
19330 * m_line_header
->minimum_instruction_length
);
19331 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19332 m_op_index
= ((m_op_index
+ adjust
)
19333 % m_line_header
->maximum_ops_per_instruction
);
19337 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19339 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19340 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19341 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19342 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19343 / m_line_header
->maximum_ops_per_instruction
)
19344 * m_line_header
->minimum_instruction_length
);
19345 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19346 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19347 % m_line_header
->maximum_ops_per_instruction
);
19349 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19350 advance_line (line_delta
);
19351 record_line (false);
19352 m_discriminator
= 0;
19356 lnp_state_machine::handle_set_file (file_name_index file
)
19360 const file_entry
*fe
= current_file ();
19362 dwarf2_debug_line_missing_file_complaint ();
19363 else if (m_record_lines_p
)
19365 const char *dir
= fe
->include_dir (m_line_header
);
19367 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19368 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19369 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19374 lnp_state_machine::handle_const_add_pc ()
19377 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19380 = (((m_op_index
+ adjust
)
19381 / m_line_header
->maximum_ops_per_instruction
)
19382 * m_line_header
->minimum_instruction_length
);
19384 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19385 m_op_index
= ((m_op_index
+ adjust
)
19386 % m_line_header
->maximum_ops_per_instruction
);
19389 /* Return non-zero if we should add LINE to the line number table.
19390 LINE is the line to add, LAST_LINE is the last line that was added,
19391 LAST_SUBFILE is the subfile for LAST_LINE.
19392 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19393 had a non-zero discriminator.
19395 We have to be careful in the presence of discriminators.
19396 E.g., for this line:
19398 for (i = 0; i < 100000; i++);
19400 clang can emit four line number entries for that one line,
19401 each with a different discriminator.
19402 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19404 However, we want gdb to coalesce all four entries into one.
19405 Otherwise the user could stepi into the middle of the line and
19406 gdb would get confused about whether the pc really was in the
19407 middle of the line.
19409 Things are further complicated by the fact that two consecutive
19410 line number entries for the same line is a heuristic used by gcc
19411 to denote the end of the prologue. So we can't just discard duplicate
19412 entries, we have to be selective about it. The heuristic we use is
19413 that we only collapse consecutive entries for the same line if at least
19414 one of those entries has a non-zero discriminator. PR 17276.
19416 Note: Addresses in the line number state machine can never go backwards
19417 within one sequence, thus this coalescing is ok. */
19420 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19421 unsigned int line
, unsigned int last_line
,
19422 int line_has_non_zero_discriminator
,
19423 struct subfile
*last_subfile
)
19425 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19427 if (line
!= last_line
)
19429 /* Same line for the same file that we've seen already.
19430 As a last check, for pr 17276, only record the line if the line
19431 has never had a non-zero discriminator. */
19432 if (!line_has_non_zero_discriminator
)
19437 /* Use the CU's builder to record line number LINE beginning at
19438 address ADDRESS in the line table of subfile SUBFILE. */
19441 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19442 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19443 struct dwarf2_cu
*cu
)
19445 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19447 if (dwarf_line_debug
)
19449 fprintf_unfiltered (gdb_stdlog
,
19450 "Recording line %u, file %s, address %s\n",
19451 line
, lbasename (subfile
->name
),
19452 paddress (gdbarch
, address
));
19456 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19459 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19460 Mark the end of a set of line number records.
19461 The arguments are the same as for dwarf_record_line_1.
19462 If SUBFILE is NULL the request is ignored. */
19465 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19466 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19468 if (subfile
== NULL
)
19471 if (dwarf_line_debug
)
19473 fprintf_unfiltered (gdb_stdlog
,
19474 "Finishing current line, file %s, address %s\n",
19475 lbasename (subfile
->name
),
19476 paddress (gdbarch
, address
));
19479 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19483 lnp_state_machine::record_line (bool end_sequence
)
19485 if (dwarf_line_debug
)
19487 fprintf_unfiltered (gdb_stdlog
,
19488 "Processing actual line %u: file %u,"
19489 " address %s, is_stmt %u, discrim %u%s\n",
19491 paddress (m_gdbarch
, m_address
),
19492 m_is_stmt
, m_discriminator
,
19493 (end_sequence
? "\t(end sequence)" : ""));
19496 file_entry
*fe
= current_file ();
19499 dwarf2_debug_line_missing_file_complaint ();
19500 /* For now we ignore lines not starting on an instruction boundary.
19501 But not when processing end_sequence for compatibility with the
19502 previous version of the code. */
19503 else if (m_op_index
== 0 || end_sequence
)
19505 fe
->included_p
= 1;
19506 if (m_record_lines_p
)
19508 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19511 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19512 m_currently_recording_lines
? m_cu
: nullptr);
19517 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19519 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19520 m_line_has_non_zero_discriminator
,
19523 buildsym_compunit
*builder
= m_cu
->get_builder ();
19524 dwarf_record_line_1 (m_gdbarch
,
19525 builder
->get_current_subfile (),
19526 m_line
, m_address
, is_stmt
,
19527 m_currently_recording_lines
? m_cu
: nullptr);
19529 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19530 m_last_line
= m_line
;
19536 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19537 line_header
*lh
, bool record_lines_p
)
19541 m_record_lines_p
= record_lines_p
;
19542 m_line_header
= lh
;
19544 m_currently_recording_lines
= true;
19546 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19547 was a line entry for it so that the backend has a chance to adjust it
19548 and also record it in case it needs it. This is currently used by MIPS
19549 code, cf. `mips_adjust_dwarf2_line'. */
19550 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19551 m_is_stmt
= lh
->default_is_stmt
;
19552 m_discriminator
= 0;
19556 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19557 const gdb_byte
*line_ptr
,
19558 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19560 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19561 the pc range of the CU. However, we restrict the test to only ADDRESS
19562 values of zero to preserve GDB's previous behaviour which is to handle
19563 the specific case of a function being GC'd by the linker. */
19565 if (address
== 0 && address
< unrelocated_lowpc
)
19567 /* This line table is for a function which has been
19568 GCd by the linker. Ignore it. PR gdb/12528 */
19570 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19571 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19573 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19574 line_offset
, objfile_name (objfile
));
19575 m_currently_recording_lines
= false;
19576 /* Note: m_currently_recording_lines is left as false until we see
19577 DW_LNE_end_sequence. */
19581 /* Subroutine of dwarf_decode_lines to simplify it.
19582 Process the line number information in LH.
19583 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19584 program in order to set included_p for every referenced header. */
19587 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19588 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19590 const gdb_byte
*line_ptr
, *extended_end
;
19591 const gdb_byte
*line_end
;
19592 unsigned int bytes_read
, extended_len
;
19593 unsigned char op_code
, extended_op
;
19594 CORE_ADDR baseaddr
;
19595 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19596 bfd
*abfd
= objfile
->obfd
;
19597 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19598 /* True if we're recording line info (as opposed to building partial
19599 symtabs and just interested in finding include files mentioned by
19600 the line number program). */
19601 bool record_lines_p
= !decode_for_pst_p
;
19603 baseaddr
= objfile
->text_section_offset ();
19605 line_ptr
= lh
->statement_program_start
;
19606 line_end
= lh
->statement_program_end
;
19608 /* Read the statement sequences until there's nothing left. */
19609 while (line_ptr
< line_end
)
19611 /* The DWARF line number program state machine. Reset the state
19612 machine at the start of each sequence. */
19613 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19614 bool end_sequence
= false;
19616 if (record_lines_p
)
19618 /* Start a subfile for the current file of the state
19620 const file_entry
*fe
= state_machine
.current_file ();
19623 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19626 /* Decode the table. */
19627 while (line_ptr
< line_end
&& !end_sequence
)
19629 op_code
= read_1_byte (abfd
, line_ptr
);
19632 if (op_code
>= lh
->opcode_base
)
19634 /* Special opcode. */
19635 state_machine
.handle_special_opcode (op_code
);
19637 else switch (op_code
)
19639 case DW_LNS_extended_op
:
19640 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19642 line_ptr
+= bytes_read
;
19643 extended_end
= line_ptr
+ extended_len
;
19644 extended_op
= read_1_byte (abfd
, line_ptr
);
19646 switch (extended_op
)
19648 case DW_LNE_end_sequence
:
19649 state_machine
.handle_end_sequence ();
19650 end_sequence
= true;
19652 case DW_LNE_set_address
:
19655 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19656 line_ptr
+= bytes_read
;
19658 state_machine
.check_line_address (cu
, line_ptr
,
19659 lowpc
- baseaddr
, address
);
19660 state_machine
.handle_set_address (baseaddr
, address
);
19663 case DW_LNE_define_file
:
19665 const char *cur_file
;
19666 unsigned int mod_time
, length
;
19669 cur_file
= read_direct_string (abfd
, line_ptr
,
19671 line_ptr
+= bytes_read
;
19672 dindex
= (dir_index
)
19673 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19674 line_ptr
+= bytes_read
;
19676 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19677 line_ptr
+= bytes_read
;
19679 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19680 line_ptr
+= bytes_read
;
19681 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19684 case DW_LNE_set_discriminator
:
19686 /* The discriminator is not interesting to the
19687 debugger; just ignore it. We still need to
19688 check its value though:
19689 if there are consecutive entries for the same
19690 (non-prologue) line we want to coalesce them.
19693 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19694 line_ptr
+= bytes_read
;
19696 state_machine
.handle_set_discriminator (discr
);
19700 complaint (_("mangled .debug_line section"));
19703 /* Make sure that we parsed the extended op correctly. If e.g.
19704 we expected a different address size than the producer used,
19705 we may have read the wrong number of bytes. */
19706 if (line_ptr
!= extended_end
)
19708 complaint (_("mangled .debug_line section"));
19713 state_machine
.handle_copy ();
19715 case DW_LNS_advance_pc
:
19718 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19719 line_ptr
+= bytes_read
;
19721 state_machine
.handle_advance_pc (adjust
);
19724 case DW_LNS_advance_line
:
19727 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19728 line_ptr
+= bytes_read
;
19730 state_machine
.handle_advance_line (line_delta
);
19733 case DW_LNS_set_file
:
19735 file_name_index file
19736 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19738 line_ptr
+= bytes_read
;
19740 state_machine
.handle_set_file (file
);
19743 case DW_LNS_set_column
:
19744 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19745 line_ptr
+= bytes_read
;
19747 case DW_LNS_negate_stmt
:
19748 state_machine
.handle_negate_stmt ();
19750 case DW_LNS_set_basic_block
:
19752 /* Add to the address register of the state machine the
19753 address increment value corresponding to special opcode
19754 255. I.e., this value is scaled by the minimum
19755 instruction length since special opcode 255 would have
19756 scaled the increment. */
19757 case DW_LNS_const_add_pc
:
19758 state_machine
.handle_const_add_pc ();
19760 case DW_LNS_fixed_advance_pc
:
19762 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19765 state_machine
.handle_fixed_advance_pc (addr_adj
);
19770 /* Unknown standard opcode, ignore it. */
19773 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19775 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19776 line_ptr
+= bytes_read
;
19783 dwarf2_debug_line_missing_end_sequence_complaint ();
19785 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19786 in which case we still finish recording the last line). */
19787 state_machine
.record_line (true);
19791 /* Decode the Line Number Program (LNP) for the given line_header
19792 structure and CU. The actual information extracted and the type
19793 of structures created from the LNP depends on the value of PST.
19795 1. If PST is NULL, then this procedure uses the data from the program
19796 to create all necessary symbol tables, and their linetables.
19798 2. If PST is not NULL, this procedure reads the program to determine
19799 the list of files included by the unit represented by PST, and
19800 builds all the associated partial symbol tables.
19802 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19803 It is used for relative paths in the line table.
19804 NOTE: When processing partial symtabs (pst != NULL),
19805 comp_dir == pst->dirname.
19807 NOTE: It is important that psymtabs have the same file name (via strcmp)
19808 as the corresponding symtab. Since COMP_DIR is not used in the name of the
19809 symtab we don't use it in the name of the psymtabs we create.
19810 E.g. expand_line_sal requires this when finding psymtabs to expand.
19811 A good testcase for this is mb-inline.exp.
19813 LOWPC is the lowest address in CU (or 0 if not known).
19815 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
19816 for its PC<->lines mapping information. Otherwise only the filename
19817 table is read in. */
19820 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
19821 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
19822 CORE_ADDR lowpc
, int decode_mapping
)
19824 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19825 const int decode_for_pst_p
= (pst
!= NULL
);
19827 if (decode_mapping
)
19828 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
19830 if (decode_for_pst_p
)
19832 /* Now that we're done scanning the Line Header Program, we can
19833 create the psymtab of each included file. */
19834 for (auto &file_entry
: lh
->file_names ())
19835 if (file_entry
.included_p
== 1)
19837 gdb::unique_xmalloc_ptr
<char> name_holder
;
19838 const char *include_name
=
19839 psymtab_include_file_name (lh
, file_entry
, pst
,
19840 comp_dir
, &name_holder
);
19841 if (include_name
!= NULL
)
19842 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
19847 /* Make sure a symtab is created for every file, even files
19848 which contain only variables (i.e. no code with associated
19850 buildsym_compunit
*builder
= cu
->get_builder ();
19851 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
19853 for (auto &fe
: lh
->file_names ())
19855 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
19856 if (builder
->get_current_subfile ()->symtab
== NULL
)
19858 builder
->get_current_subfile ()->symtab
19859 = allocate_symtab (cust
,
19860 builder
->get_current_subfile ()->name
);
19862 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
19867 /* Start a subfile for DWARF. FILENAME is the name of the file and
19868 DIRNAME the name of the source directory which contains FILENAME
19869 or NULL if not known.
19870 This routine tries to keep line numbers from identical absolute and
19871 relative file names in a common subfile.
19873 Using the `list' example from the GDB testsuite, which resides in
19874 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
19875 of /srcdir/list0.c yields the following debugging information for list0.c:
19877 DW_AT_name: /srcdir/list0.c
19878 DW_AT_comp_dir: /compdir
19879 files.files[0].name: list0.h
19880 files.files[0].dir: /srcdir
19881 files.files[1].name: list0.c
19882 files.files[1].dir: /srcdir
19884 The line number information for list0.c has to end up in a single
19885 subfile, so that `break /srcdir/list0.c:1' works as expected.
19886 start_subfile will ensure that this happens provided that we pass the
19887 concatenation of files.files[1].dir and files.files[1].name as the
19891 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
19892 const char *dirname
)
19894 gdb::unique_xmalloc_ptr
<char> copy
;
19896 /* In order not to lose the line information directory,
19897 we concatenate it to the filename when it makes sense.
19898 Note that the Dwarf3 standard says (speaking of filenames in line
19899 information): ``The directory index is ignored for file names
19900 that represent full path names''. Thus ignoring dirname in the
19901 `else' branch below isn't an issue. */
19903 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
19905 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
19906 filename
= copy
.get ();
19909 cu
->get_builder ()->start_subfile (filename
);
19912 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
19913 buildsym_compunit constructor. */
19915 struct compunit_symtab
*
19916 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
19919 gdb_assert (m_builder
== nullptr);
19921 m_builder
.reset (new struct buildsym_compunit
19922 (per_cu
->dwarf2_per_objfile
->objfile
,
19923 name
, comp_dir
, language
, low_pc
));
19925 list_in_scope
= get_builder ()->get_file_symbols ();
19927 get_builder ()->record_debugformat ("DWARF 2");
19928 get_builder ()->record_producer (producer
);
19930 processing_has_namespace_info
= false;
19932 return get_builder ()->get_compunit_symtab ();
19936 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
19937 struct dwarf2_cu
*cu
)
19939 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19940 struct comp_unit_head
*cu_header
= &cu
->header
;
19942 /* NOTE drow/2003-01-30: There used to be a comment and some special
19943 code here to turn a symbol with DW_AT_external and a
19944 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
19945 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
19946 with some versions of binutils) where shared libraries could have
19947 relocations against symbols in their debug information - the
19948 minimal symbol would have the right address, but the debug info
19949 would not. It's no longer necessary, because we will explicitly
19950 apply relocations when we read in the debug information now. */
19952 /* A DW_AT_location attribute with no contents indicates that a
19953 variable has been optimized away. */
19954 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
19956 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
19960 /* Handle one degenerate form of location expression specially, to
19961 preserve GDB's previous behavior when section offsets are
19962 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
19963 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
19965 if (attr
->form_is_block ()
19966 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
19967 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
19968 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
19969 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
19970 && (DW_BLOCK (attr
)->size
19971 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
19973 unsigned int dummy
;
19975 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
19976 SET_SYMBOL_VALUE_ADDRESS
19977 (sym
, cu
->header
.read_address (objfile
->obfd
,
19978 DW_BLOCK (attr
)->data
+ 1,
19981 SET_SYMBOL_VALUE_ADDRESS
19982 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
19984 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
19985 fixup_symbol_section (sym
, objfile
);
19986 SET_SYMBOL_VALUE_ADDRESS
19988 SYMBOL_VALUE_ADDRESS (sym
)
19989 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
19993 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
19994 expression evaluator, and use LOC_COMPUTED only when necessary
19995 (i.e. when the value of a register or memory location is
19996 referenced, or a thread-local block, etc.). Then again, it might
19997 not be worthwhile. I'm assuming that it isn't unless performance
19998 or memory numbers show me otherwise. */
20000 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20002 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20003 cu
->has_loclist
= true;
20006 /* Given a pointer to a DWARF information entry, figure out if we need
20007 to make a symbol table entry for it, and if so, create a new entry
20008 and return a pointer to it.
20009 If TYPE is NULL, determine symbol type from the die, otherwise
20010 used the passed type.
20011 If SPACE is not NULL, use it to hold the new symbol. If it is
20012 NULL, allocate a new symbol on the objfile's obstack. */
20014 static struct symbol
*
20015 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20016 struct symbol
*space
)
20018 struct dwarf2_per_objfile
*dwarf2_per_objfile
20019 = cu
->per_cu
->dwarf2_per_objfile
;
20020 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20021 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20022 struct symbol
*sym
= NULL
;
20024 struct attribute
*attr
= NULL
;
20025 struct attribute
*attr2
= NULL
;
20026 CORE_ADDR baseaddr
;
20027 struct pending
**list_to_add
= NULL
;
20029 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20031 baseaddr
= objfile
->text_section_offset ();
20033 name
= dwarf2_name (die
, cu
);
20036 const char *linkagename
;
20037 int suppress_add
= 0;
20042 sym
= allocate_symbol (objfile
);
20043 OBJSTAT (objfile
, n_syms
++);
20045 /* Cache this symbol's name and the name's demangled form (if any). */
20046 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20047 linkagename
= dwarf2_physname (name
, die
, cu
);
20048 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20050 /* Fortran does not have mangling standard and the mangling does differ
20051 between gfortran, iFort etc. */
20052 if (cu
->language
== language_fortran
20053 && symbol_get_demangled_name (sym
) == NULL
)
20054 symbol_set_demangled_name (sym
,
20055 dwarf2_full_name (name
, die
, cu
),
20058 /* Default assumptions.
20059 Use the passed type or decode it from the die. */
20060 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20061 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20063 SYMBOL_TYPE (sym
) = type
;
20065 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20066 attr
= dwarf2_attr (die
,
20067 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20069 if (attr
!= nullptr)
20071 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20074 attr
= dwarf2_attr (die
,
20075 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20077 if (attr
!= nullptr)
20079 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20080 struct file_entry
*fe
;
20082 if (cu
->line_header
!= NULL
)
20083 fe
= cu
->line_header
->file_name_at (file_index
);
20088 complaint (_("file index out of range"));
20090 symbol_set_symtab (sym
, fe
->symtab
);
20096 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20097 if (attr
!= nullptr)
20101 addr
= attr
->value_as_address ();
20102 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20103 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20105 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20106 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20107 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20108 add_symbol_to_list (sym
, cu
->list_in_scope
);
20110 case DW_TAG_subprogram
:
20111 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20113 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20114 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20115 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20116 || cu
->language
== language_ada
20117 || cu
->language
== language_fortran
)
20119 /* Subprograms marked external are stored as a global symbol.
20120 Ada and Fortran subprograms, whether marked external or
20121 not, are always stored as a global symbol, because we want
20122 to be able to access them globally. For instance, we want
20123 to be able to break on a nested subprogram without having
20124 to specify the context. */
20125 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20129 list_to_add
= cu
->list_in_scope
;
20132 case DW_TAG_inlined_subroutine
:
20133 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20135 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20136 SYMBOL_INLINED (sym
) = 1;
20137 list_to_add
= cu
->list_in_scope
;
20139 case DW_TAG_template_value_param
:
20141 /* Fall through. */
20142 case DW_TAG_constant
:
20143 case DW_TAG_variable
:
20144 case DW_TAG_member
:
20145 /* Compilation with minimal debug info may result in
20146 variables with missing type entries. Change the
20147 misleading `void' type to something sensible. */
20148 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20149 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20151 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20152 /* In the case of DW_TAG_member, we should only be called for
20153 static const members. */
20154 if (die
->tag
== DW_TAG_member
)
20156 /* dwarf2_add_field uses die_is_declaration,
20157 so we do the same. */
20158 gdb_assert (die_is_declaration (die
, cu
));
20161 if (attr
!= nullptr)
20163 dwarf2_const_value (attr
, sym
, cu
);
20164 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20167 if (attr2
&& (DW_UNSND (attr2
) != 0))
20168 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20170 list_to_add
= cu
->list_in_scope
;
20174 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20175 if (attr
!= nullptr)
20177 var_decode_location (attr
, sym
, cu
);
20178 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20180 /* Fortran explicitly imports any global symbols to the local
20181 scope by DW_TAG_common_block. */
20182 if (cu
->language
== language_fortran
&& die
->parent
20183 && die
->parent
->tag
== DW_TAG_common_block
)
20186 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20187 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20188 && !dwarf2_per_objfile
->has_section_at_zero
)
20190 /* When a static variable is eliminated by the linker,
20191 the corresponding debug information is not stripped
20192 out, but the variable address is set to null;
20193 do not add such variables into symbol table. */
20195 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20197 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20198 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20199 && dwarf2_per_objfile
->can_copy
)
20201 /* A global static variable might be subject to
20202 copy relocation. We first check for a local
20203 minsym, though, because maybe the symbol was
20204 marked hidden, in which case this would not
20206 bound_minimal_symbol found
20207 = (lookup_minimal_symbol_linkage
20208 (sym
->linkage_name (), objfile
));
20209 if (found
.minsym
!= nullptr)
20210 sym
->maybe_copied
= 1;
20213 /* A variable with DW_AT_external is never static,
20214 but it may be block-scoped. */
20216 = ((cu
->list_in_scope
20217 == cu
->get_builder ()->get_file_symbols ())
20218 ? cu
->get_builder ()->get_global_symbols ()
20219 : cu
->list_in_scope
);
20222 list_to_add
= cu
->list_in_scope
;
20226 /* We do not know the address of this symbol.
20227 If it is an external symbol and we have type information
20228 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20229 The address of the variable will then be determined from
20230 the minimal symbol table whenever the variable is
20232 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20234 /* Fortran explicitly imports any global symbols to the local
20235 scope by DW_TAG_common_block. */
20236 if (cu
->language
== language_fortran
&& die
->parent
20237 && die
->parent
->tag
== DW_TAG_common_block
)
20239 /* SYMBOL_CLASS doesn't matter here because
20240 read_common_block is going to reset it. */
20242 list_to_add
= cu
->list_in_scope
;
20244 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20245 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20247 /* A variable with DW_AT_external is never static, but it
20248 may be block-scoped. */
20250 = ((cu
->list_in_scope
20251 == cu
->get_builder ()->get_file_symbols ())
20252 ? cu
->get_builder ()->get_global_symbols ()
20253 : cu
->list_in_scope
);
20255 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20257 else if (!die_is_declaration (die
, cu
))
20259 /* Use the default LOC_OPTIMIZED_OUT class. */
20260 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20262 list_to_add
= cu
->list_in_scope
;
20266 case DW_TAG_formal_parameter
:
20268 /* If we are inside a function, mark this as an argument. If
20269 not, we might be looking at an argument to an inlined function
20270 when we do not have enough information to show inlined frames;
20271 pretend it's a local variable in that case so that the user can
20273 struct context_stack
*curr
20274 = cu
->get_builder ()->get_current_context_stack ();
20275 if (curr
!= nullptr && curr
->name
!= nullptr)
20276 SYMBOL_IS_ARGUMENT (sym
) = 1;
20277 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20278 if (attr
!= nullptr)
20280 var_decode_location (attr
, sym
, cu
);
20282 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20283 if (attr
!= nullptr)
20285 dwarf2_const_value (attr
, sym
, cu
);
20288 list_to_add
= cu
->list_in_scope
;
20291 case DW_TAG_unspecified_parameters
:
20292 /* From varargs functions; gdb doesn't seem to have any
20293 interest in this information, so just ignore it for now.
20296 case DW_TAG_template_type_param
:
20298 /* Fall through. */
20299 case DW_TAG_class_type
:
20300 case DW_TAG_interface_type
:
20301 case DW_TAG_structure_type
:
20302 case DW_TAG_union_type
:
20303 case DW_TAG_set_type
:
20304 case DW_TAG_enumeration_type
:
20305 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20306 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20309 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20310 really ever be static objects: otherwise, if you try
20311 to, say, break of a class's method and you're in a file
20312 which doesn't mention that class, it won't work unless
20313 the check for all static symbols in lookup_symbol_aux
20314 saves you. See the OtherFileClass tests in
20315 gdb.c++/namespace.exp. */
20319 buildsym_compunit
*builder
= cu
->get_builder ();
20321 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20322 && cu
->language
== language_cplus
20323 ? builder
->get_global_symbols ()
20324 : cu
->list_in_scope
);
20326 /* The semantics of C++ state that "struct foo {
20327 ... }" also defines a typedef for "foo". */
20328 if (cu
->language
== language_cplus
20329 || cu
->language
== language_ada
20330 || cu
->language
== language_d
20331 || cu
->language
== language_rust
)
20333 /* The symbol's name is already allocated along
20334 with this objfile, so we don't need to
20335 duplicate it for the type. */
20336 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20337 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20342 case DW_TAG_typedef
:
20343 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20344 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20345 list_to_add
= cu
->list_in_scope
;
20347 case DW_TAG_base_type
:
20348 case DW_TAG_subrange_type
:
20349 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20350 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20351 list_to_add
= cu
->list_in_scope
;
20353 case DW_TAG_enumerator
:
20354 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20355 if (attr
!= nullptr)
20357 dwarf2_const_value (attr
, sym
, cu
);
20360 /* NOTE: carlton/2003-11-10: See comment above in the
20361 DW_TAG_class_type, etc. block. */
20364 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20365 && cu
->language
== language_cplus
20366 ? cu
->get_builder ()->get_global_symbols ()
20367 : cu
->list_in_scope
);
20370 case DW_TAG_imported_declaration
:
20371 case DW_TAG_namespace
:
20372 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20373 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20375 case DW_TAG_module
:
20376 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20377 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20378 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20380 case DW_TAG_common_block
:
20381 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20382 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20383 add_symbol_to_list (sym
, cu
->list_in_scope
);
20386 /* Not a tag we recognize. Hopefully we aren't processing
20387 trash data, but since we must specifically ignore things
20388 we don't recognize, there is nothing else we should do at
20390 complaint (_("unsupported tag: '%s'"),
20391 dwarf_tag_name (die
->tag
));
20397 sym
->hash_next
= objfile
->template_symbols
;
20398 objfile
->template_symbols
= sym
;
20399 list_to_add
= NULL
;
20402 if (list_to_add
!= NULL
)
20403 add_symbol_to_list (sym
, list_to_add
);
20405 /* For the benefit of old versions of GCC, check for anonymous
20406 namespaces based on the demangled name. */
20407 if (!cu
->processing_has_namespace_info
20408 && cu
->language
== language_cplus
)
20409 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20414 /* Given an attr with a DW_FORM_dataN value in host byte order,
20415 zero-extend it as appropriate for the symbol's type. The DWARF
20416 standard (v4) is not entirely clear about the meaning of using
20417 DW_FORM_dataN for a constant with a signed type, where the type is
20418 wider than the data. The conclusion of a discussion on the DWARF
20419 list was that this is unspecified. We choose to always zero-extend
20420 because that is the interpretation long in use by GCC. */
20423 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20424 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20426 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20427 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20428 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20429 LONGEST l
= DW_UNSND (attr
);
20431 if (bits
< sizeof (*value
) * 8)
20433 l
&= ((LONGEST
) 1 << bits
) - 1;
20436 else if (bits
== sizeof (*value
) * 8)
20440 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20441 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20448 /* Read a constant value from an attribute. Either set *VALUE, or if
20449 the value does not fit in *VALUE, set *BYTES - either already
20450 allocated on the objfile obstack, or newly allocated on OBSTACK,
20451 or, set *BATON, if we translated the constant to a location
20455 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20456 const char *name
, struct obstack
*obstack
,
20457 struct dwarf2_cu
*cu
,
20458 LONGEST
*value
, const gdb_byte
**bytes
,
20459 struct dwarf2_locexpr_baton
**baton
)
20461 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20462 struct comp_unit_head
*cu_header
= &cu
->header
;
20463 struct dwarf_block
*blk
;
20464 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20465 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20471 switch (attr
->form
)
20474 case DW_FORM_addrx
:
20475 case DW_FORM_GNU_addr_index
:
20479 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20480 dwarf2_const_value_length_mismatch_complaint (name
,
20481 cu_header
->addr_size
,
20482 TYPE_LENGTH (type
));
20483 /* Symbols of this form are reasonably rare, so we just
20484 piggyback on the existing location code rather than writing
20485 a new implementation of symbol_computed_ops. */
20486 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20487 (*baton
)->per_cu
= cu
->per_cu
;
20488 gdb_assert ((*baton
)->per_cu
);
20490 (*baton
)->size
= 2 + cu_header
->addr_size
;
20491 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20492 (*baton
)->data
= data
;
20494 data
[0] = DW_OP_addr
;
20495 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20496 byte_order
, DW_ADDR (attr
));
20497 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20500 case DW_FORM_string
:
20503 case DW_FORM_GNU_str_index
:
20504 case DW_FORM_GNU_strp_alt
:
20505 /* DW_STRING is already allocated on the objfile obstack, point
20507 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20509 case DW_FORM_block1
:
20510 case DW_FORM_block2
:
20511 case DW_FORM_block4
:
20512 case DW_FORM_block
:
20513 case DW_FORM_exprloc
:
20514 case DW_FORM_data16
:
20515 blk
= DW_BLOCK (attr
);
20516 if (TYPE_LENGTH (type
) != blk
->size
)
20517 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20518 TYPE_LENGTH (type
));
20519 *bytes
= blk
->data
;
20522 /* The DW_AT_const_value attributes are supposed to carry the
20523 symbol's value "represented as it would be on the target
20524 architecture." By the time we get here, it's already been
20525 converted to host endianness, so we just need to sign- or
20526 zero-extend it as appropriate. */
20527 case DW_FORM_data1
:
20528 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20530 case DW_FORM_data2
:
20531 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20533 case DW_FORM_data4
:
20534 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20536 case DW_FORM_data8
:
20537 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20540 case DW_FORM_sdata
:
20541 case DW_FORM_implicit_const
:
20542 *value
= DW_SND (attr
);
20545 case DW_FORM_udata
:
20546 *value
= DW_UNSND (attr
);
20550 complaint (_("unsupported const value attribute form: '%s'"),
20551 dwarf_form_name (attr
->form
));
20558 /* Copy constant value from an attribute to a symbol. */
20561 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20562 struct dwarf2_cu
*cu
)
20564 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20566 const gdb_byte
*bytes
;
20567 struct dwarf2_locexpr_baton
*baton
;
20569 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20570 sym
->print_name (),
20571 &objfile
->objfile_obstack
, cu
,
20572 &value
, &bytes
, &baton
);
20576 SYMBOL_LOCATION_BATON (sym
) = baton
;
20577 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20579 else if (bytes
!= NULL
)
20581 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20582 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20586 SYMBOL_VALUE (sym
) = value
;
20587 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20591 /* Return the type of the die in question using its DW_AT_type attribute. */
20593 static struct type
*
20594 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20596 struct attribute
*type_attr
;
20598 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20601 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20602 /* A missing DW_AT_type represents a void type. */
20603 return objfile_type (objfile
)->builtin_void
;
20606 return lookup_die_type (die
, type_attr
, cu
);
20609 /* True iff CU's producer generates GNAT Ada auxiliary information
20610 that allows to find parallel types through that information instead
20611 of having to do expensive parallel lookups by type name. */
20614 need_gnat_info (struct dwarf2_cu
*cu
)
20616 /* Assume that the Ada compiler was GNAT, which always produces
20617 the auxiliary information. */
20618 return (cu
->language
== language_ada
);
20621 /* Return the auxiliary type of the die in question using its
20622 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20623 attribute is not present. */
20625 static struct type
*
20626 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20628 struct attribute
*type_attr
;
20630 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20634 return lookup_die_type (die
, type_attr
, cu
);
20637 /* If DIE has a descriptive_type attribute, then set the TYPE's
20638 descriptive type accordingly. */
20641 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20642 struct dwarf2_cu
*cu
)
20644 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20646 if (descriptive_type
)
20648 ALLOCATE_GNAT_AUX_TYPE (type
);
20649 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20653 /* Return the containing type of the die in question using its
20654 DW_AT_containing_type attribute. */
20656 static struct type
*
20657 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20659 struct attribute
*type_attr
;
20660 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20662 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20664 error (_("Dwarf Error: Problem turning containing type into gdb type "
20665 "[in module %s]"), objfile_name (objfile
));
20667 return lookup_die_type (die
, type_attr
, cu
);
20670 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20672 static struct type
*
20673 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20675 struct dwarf2_per_objfile
*dwarf2_per_objfile
20676 = cu
->per_cu
->dwarf2_per_objfile
;
20677 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20680 std::string message
20681 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20682 objfile_name (objfile
),
20683 sect_offset_str (cu
->header
.sect_off
),
20684 sect_offset_str (die
->sect_off
));
20685 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20687 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20690 /* Look up the type of DIE in CU using its type attribute ATTR.
20691 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20692 DW_AT_containing_type.
20693 If there is no type substitute an error marker. */
20695 static struct type
*
20696 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20697 struct dwarf2_cu
*cu
)
20699 struct dwarf2_per_objfile
*dwarf2_per_objfile
20700 = cu
->per_cu
->dwarf2_per_objfile
;
20701 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20702 struct type
*this_type
;
20704 gdb_assert (attr
->name
== DW_AT_type
20705 || attr
->name
== DW_AT_GNAT_descriptive_type
20706 || attr
->name
== DW_AT_containing_type
);
20708 /* First see if we have it cached. */
20710 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20712 struct dwarf2_per_cu_data
*per_cu
;
20713 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20715 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20716 dwarf2_per_objfile
);
20717 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20719 else if (attr
->form_is_ref ())
20721 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20723 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20725 else if (attr
->form
== DW_FORM_ref_sig8
)
20727 ULONGEST signature
= DW_SIGNATURE (attr
);
20729 return get_signatured_type (die
, signature
, cu
);
20733 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20734 " at %s [in module %s]"),
20735 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20736 objfile_name (objfile
));
20737 return build_error_marker_type (cu
, die
);
20740 /* If not cached we need to read it in. */
20742 if (this_type
== NULL
)
20744 struct die_info
*type_die
= NULL
;
20745 struct dwarf2_cu
*type_cu
= cu
;
20747 if (attr
->form_is_ref ())
20748 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20749 if (type_die
== NULL
)
20750 return build_error_marker_type (cu
, die
);
20751 /* If we find the type now, it's probably because the type came
20752 from an inter-CU reference and the type's CU got expanded before
20754 this_type
= read_type_die (type_die
, type_cu
);
20757 /* If we still don't have a type use an error marker. */
20759 if (this_type
== NULL
)
20760 return build_error_marker_type (cu
, die
);
20765 /* Return the type in DIE, CU.
20766 Returns NULL for invalid types.
20768 This first does a lookup in die_type_hash,
20769 and only reads the die in if necessary.
20771 NOTE: This can be called when reading in partial or full symbols. */
20773 static struct type
*
20774 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20776 struct type
*this_type
;
20778 this_type
= get_die_type (die
, cu
);
20782 return read_type_die_1 (die
, cu
);
20785 /* Read the type in DIE, CU.
20786 Returns NULL for invalid types. */
20788 static struct type
*
20789 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20791 struct type
*this_type
= NULL
;
20795 case DW_TAG_class_type
:
20796 case DW_TAG_interface_type
:
20797 case DW_TAG_structure_type
:
20798 case DW_TAG_union_type
:
20799 this_type
= read_structure_type (die
, cu
);
20801 case DW_TAG_enumeration_type
:
20802 this_type
= read_enumeration_type (die
, cu
);
20804 case DW_TAG_subprogram
:
20805 case DW_TAG_subroutine_type
:
20806 case DW_TAG_inlined_subroutine
:
20807 this_type
= read_subroutine_type (die
, cu
);
20809 case DW_TAG_array_type
:
20810 this_type
= read_array_type (die
, cu
);
20812 case DW_TAG_set_type
:
20813 this_type
= read_set_type (die
, cu
);
20815 case DW_TAG_pointer_type
:
20816 this_type
= read_tag_pointer_type (die
, cu
);
20818 case DW_TAG_ptr_to_member_type
:
20819 this_type
= read_tag_ptr_to_member_type (die
, cu
);
20821 case DW_TAG_reference_type
:
20822 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
20824 case DW_TAG_rvalue_reference_type
:
20825 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
20827 case DW_TAG_const_type
:
20828 this_type
= read_tag_const_type (die
, cu
);
20830 case DW_TAG_volatile_type
:
20831 this_type
= read_tag_volatile_type (die
, cu
);
20833 case DW_TAG_restrict_type
:
20834 this_type
= read_tag_restrict_type (die
, cu
);
20836 case DW_TAG_string_type
:
20837 this_type
= read_tag_string_type (die
, cu
);
20839 case DW_TAG_typedef
:
20840 this_type
= read_typedef (die
, cu
);
20842 case DW_TAG_subrange_type
:
20843 this_type
= read_subrange_type (die
, cu
);
20845 case DW_TAG_base_type
:
20846 this_type
= read_base_type (die
, cu
);
20848 case DW_TAG_unspecified_type
:
20849 this_type
= read_unspecified_type (die
, cu
);
20851 case DW_TAG_namespace
:
20852 this_type
= read_namespace_type (die
, cu
);
20854 case DW_TAG_module
:
20855 this_type
= read_module_type (die
, cu
);
20857 case DW_TAG_atomic_type
:
20858 this_type
= read_tag_atomic_type (die
, cu
);
20861 complaint (_("unexpected tag in read_type_die: '%s'"),
20862 dwarf_tag_name (die
->tag
));
20869 /* See if we can figure out if the class lives in a namespace. We do
20870 this by looking for a member function; its demangled name will
20871 contain namespace info, if there is any.
20872 Return the computed name or NULL.
20873 Space for the result is allocated on the objfile's obstack.
20874 This is the full-die version of guess_partial_die_structure_name.
20875 In this case we know DIE has no useful parent. */
20877 static const char *
20878 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20880 struct die_info
*spec_die
;
20881 struct dwarf2_cu
*spec_cu
;
20882 struct die_info
*child
;
20883 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20886 spec_die
= die_specification (die
, &spec_cu
);
20887 if (spec_die
!= NULL
)
20893 for (child
= die
->child
;
20895 child
= child
->sibling
)
20897 if (child
->tag
== DW_TAG_subprogram
)
20899 const char *linkage_name
= dw2_linkage_name (child
, cu
);
20901 if (linkage_name
!= NULL
)
20903 gdb::unique_xmalloc_ptr
<char> actual_name
20904 (language_class_name_from_physname (cu
->language_defn
,
20906 const char *name
= NULL
;
20908 if (actual_name
!= NULL
)
20910 const char *die_name
= dwarf2_name (die
, cu
);
20912 if (die_name
!= NULL
20913 && strcmp (die_name
, actual_name
.get ()) != 0)
20915 /* Strip off the class name from the full name.
20916 We want the prefix. */
20917 int die_name_len
= strlen (die_name
);
20918 int actual_name_len
= strlen (actual_name
.get ());
20919 const char *ptr
= actual_name
.get ();
20921 /* Test for '::' as a sanity check. */
20922 if (actual_name_len
> die_name_len
+ 2
20923 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
20924 name
= obstack_strndup (
20925 &objfile
->per_bfd
->storage_obstack
,
20926 ptr
, actual_name_len
- die_name_len
- 2);
20937 /* GCC might emit a nameless typedef that has a linkage name. Determine the
20938 prefix part in such case. See
20939 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20941 static const char *
20942 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20944 struct attribute
*attr
;
20947 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
20948 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
20951 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
20954 attr
= dw2_linkage_name_attr (die
, cu
);
20955 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20958 /* dwarf2_name had to be already called. */
20959 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
20961 /* Strip the base name, keep any leading namespaces/classes. */
20962 base
= strrchr (DW_STRING (attr
), ':');
20963 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
20966 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20967 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
20969 &base
[-1] - DW_STRING (attr
));
20972 /* Return the name of the namespace/class that DIE is defined within,
20973 or "" if we can't tell. The caller should not xfree the result.
20975 For example, if we're within the method foo() in the following
20985 then determine_prefix on foo's die will return "N::C". */
20987 static const char *
20988 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20990 struct dwarf2_per_objfile
*dwarf2_per_objfile
20991 = cu
->per_cu
->dwarf2_per_objfile
;
20992 struct die_info
*parent
, *spec_die
;
20993 struct dwarf2_cu
*spec_cu
;
20994 struct type
*parent_type
;
20995 const char *retval
;
20997 if (cu
->language
!= language_cplus
20998 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
20999 && cu
->language
!= language_rust
)
21002 retval
= anonymous_struct_prefix (die
, cu
);
21006 /* We have to be careful in the presence of DW_AT_specification.
21007 For example, with GCC 3.4, given the code
21011 // Definition of N::foo.
21015 then we'll have a tree of DIEs like this:
21017 1: DW_TAG_compile_unit
21018 2: DW_TAG_namespace // N
21019 3: DW_TAG_subprogram // declaration of N::foo
21020 4: DW_TAG_subprogram // definition of N::foo
21021 DW_AT_specification // refers to die #3
21023 Thus, when processing die #4, we have to pretend that we're in
21024 the context of its DW_AT_specification, namely the contex of die
21027 spec_die
= die_specification (die
, &spec_cu
);
21028 if (spec_die
== NULL
)
21029 parent
= die
->parent
;
21032 parent
= spec_die
->parent
;
21036 if (parent
== NULL
)
21038 else if (parent
->building_fullname
)
21041 const char *parent_name
;
21043 /* It has been seen on RealView 2.2 built binaries,
21044 DW_TAG_template_type_param types actually _defined_ as
21045 children of the parent class:
21048 template class <class Enum> Class{};
21049 Class<enum E> class_e;
21051 1: DW_TAG_class_type (Class)
21052 2: DW_TAG_enumeration_type (E)
21053 3: DW_TAG_enumerator (enum1:0)
21054 3: DW_TAG_enumerator (enum2:1)
21056 2: DW_TAG_template_type_param
21057 DW_AT_type DW_FORM_ref_udata (E)
21059 Besides being broken debug info, it can put GDB into an
21060 infinite loop. Consider:
21062 When we're building the full name for Class<E>, we'll start
21063 at Class, and go look over its template type parameters,
21064 finding E. We'll then try to build the full name of E, and
21065 reach here. We're now trying to build the full name of E,
21066 and look over the parent DIE for containing scope. In the
21067 broken case, if we followed the parent DIE of E, we'd again
21068 find Class, and once again go look at its template type
21069 arguments, etc., etc. Simply don't consider such parent die
21070 as source-level parent of this die (it can't be, the language
21071 doesn't allow it), and break the loop here. */
21072 name
= dwarf2_name (die
, cu
);
21073 parent_name
= dwarf2_name (parent
, cu
);
21074 complaint (_("template param type '%s' defined within parent '%s'"),
21075 name
? name
: "<unknown>",
21076 parent_name
? parent_name
: "<unknown>");
21080 switch (parent
->tag
)
21082 case DW_TAG_namespace
:
21083 parent_type
= read_type_die (parent
, cu
);
21084 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21085 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21086 Work around this problem here. */
21087 if (cu
->language
== language_cplus
21088 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21090 /* We give a name to even anonymous namespaces. */
21091 return TYPE_NAME (parent_type
);
21092 case DW_TAG_class_type
:
21093 case DW_TAG_interface_type
:
21094 case DW_TAG_structure_type
:
21095 case DW_TAG_union_type
:
21096 case DW_TAG_module
:
21097 parent_type
= read_type_die (parent
, cu
);
21098 if (TYPE_NAME (parent_type
) != NULL
)
21099 return TYPE_NAME (parent_type
);
21101 /* An anonymous structure is only allowed non-static data
21102 members; no typedefs, no member functions, et cetera.
21103 So it does not need a prefix. */
21105 case DW_TAG_compile_unit
:
21106 case DW_TAG_partial_unit
:
21107 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21108 if (cu
->language
== language_cplus
21109 && !dwarf2_per_objfile
->types
.empty ()
21110 && die
->child
!= NULL
21111 && (die
->tag
== DW_TAG_class_type
21112 || die
->tag
== DW_TAG_structure_type
21113 || die
->tag
== DW_TAG_union_type
))
21115 const char *name
= guess_full_die_structure_name (die
, cu
);
21120 case DW_TAG_subprogram
:
21121 /* Nested subroutines in Fortran get a prefix with the name
21122 of the parent's subroutine. */
21123 if (cu
->language
== language_fortran
)
21125 if ((die
->tag
== DW_TAG_subprogram
)
21126 && (dwarf2_name (parent
, cu
) != NULL
))
21127 return dwarf2_name (parent
, cu
);
21129 return determine_prefix (parent
, cu
);
21130 case DW_TAG_enumeration_type
:
21131 parent_type
= read_type_die (parent
, cu
);
21132 if (TYPE_DECLARED_CLASS (parent_type
))
21134 if (TYPE_NAME (parent_type
) != NULL
)
21135 return TYPE_NAME (parent_type
);
21138 /* Fall through. */
21140 return determine_prefix (parent
, cu
);
21144 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21145 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21146 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21147 an obconcat, otherwise allocate storage for the result. The CU argument is
21148 used to determine the language and hence, the appropriate separator. */
21150 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21153 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21154 int physname
, struct dwarf2_cu
*cu
)
21156 const char *lead
= "";
21159 if (suffix
== NULL
|| suffix
[0] == '\0'
21160 || prefix
== NULL
|| prefix
[0] == '\0')
21162 else if (cu
->language
== language_d
)
21164 /* For D, the 'main' function could be defined in any module, but it
21165 should never be prefixed. */
21166 if (strcmp (suffix
, "D main") == 0)
21174 else if (cu
->language
== language_fortran
&& physname
)
21176 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21177 DW_AT_MIPS_linkage_name is preferred and used instead. */
21185 if (prefix
== NULL
)
21187 if (suffix
== NULL
)
21194 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21196 strcpy (retval
, lead
);
21197 strcat (retval
, prefix
);
21198 strcat (retval
, sep
);
21199 strcat (retval
, suffix
);
21204 /* We have an obstack. */
21205 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21209 /* Get name of a die, return NULL if not found. */
21211 static const char *
21212 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21213 struct objfile
*objfile
)
21215 if (name
&& cu
->language
== language_cplus
)
21217 std::string canon_name
= cp_canonicalize_string (name
);
21219 if (!canon_name
.empty ())
21221 if (canon_name
!= name
)
21222 name
= objfile
->intern (canon_name
);
21229 /* Get name of a die, return NULL if not found.
21230 Anonymous namespaces are converted to their magic string. */
21232 static const char *
21233 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21235 struct attribute
*attr
;
21236 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21238 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21239 if ((!attr
|| !DW_STRING (attr
))
21240 && die
->tag
!= DW_TAG_namespace
21241 && die
->tag
!= DW_TAG_class_type
21242 && die
->tag
!= DW_TAG_interface_type
21243 && die
->tag
!= DW_TAG_structure_type
21244 && die
->tag
!= DW_TAG_union_type
)
21249 case DW_TAG_compile_unit
:
21250 case DW_TAG_partial_unit
:
21251 /* Compilation units have a DW_AT_name that is a filename, not
21252 a source language identifier. */
21253 case DW_TAG_enumeration_type
:
21254 case DW_TAG_enumerator
:
21255 /* These tags always have simple identifiers already; no need
21256 to canonicalize them. */
21257 return DW_STRING (attr
);
21259 case DW_TAG_namespace
:
21260 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21261 return DW_STRING (attr
);
21262 return CP_ANONYMOUS_NAMESPACE_STR
;
21264 case DW_TAG_class_type
:
21265 case DW_TAG_interface_type
:
21266 case DW_TAG_structure_type
:
21267 case DW_TAG_union_type
:
21268 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21269 structures or unions. These were of the form "._%d" in GCC 4.1,
21270 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21271 and GCC 4.4. We work around this problem by ignoring these. */
21272 if (attr
&& DW_STRING (attr
)
21273 && (startswith (DW_STRING (attr
), "._")
21274 || startswith (DW_STRING (attr
), "<anonymous")))
21277 /* GCC might emit a nameless typedef that has a linkage name. See
21278 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21279 if (!attr
|| DW_STRING (attr
) == NULL
)
21281 attr
= dw2_linkage_name_attr (die
, cu
);
21282 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21285 /* Avoid demangling DW_STRING (attr) the second time on a second
21286 call for the same DIE. */
21287 if (!DW_STRING_IS_CANONICAL (attr
))
21289 gdb::unique_xmalloc_ptr
<char> demangled
21290 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21291 if (demangled
== nullptr)
21294 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21295 DW_STRING_IS_CANONICAL (attr
) = 1;
21298 /* Strip any leading namespaces/classes, keep only the base name.
21299 DW_AT_name for named DIEs does not contain the prefixes. */
21300 const char *base
= strrchr (DW_STRING (attr
), ':');
21301 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21304 return DW_STRING (attr
);
21312 if (!DW_STRING_IS_CANONICAL (attr
))
21314 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21316 DW_STRING_IS_CANONICAL (attr
) = 1;
21318 return DW_STRING (attr
);
21321 /* Return the die that this die in an extension of, or NULL if there
21322 is none. *EXT_CU is the CU containing DIE on input, and the CU
21323 containing the return value on output. */
21325 static struct die_info
*
21326 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21328 struct attribute
*attr
;
21330 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21334 return follow_die_ref (die
, attr
, ext_cu
);
21337 /* A convenience function that returns an "unknown" DWARF name,
21338 including the value of V. STR is the name of the entity being
21339 printed, e.g., "TAG". */
21341 static const char *
21342 dwarf_unknown (const char *str
, unsigned v
)
21344 char *cell
= get_print_cell ();
21345 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21349 /* Convert a DIE tag into its string name. */
21351 static const char *
21352 dwarf_tag_name (unsigned tag
)
21354 const char *name
= get_DW_TAG_name (tag
);
21357 return dwarf_unknown ("TAG", tag
);
21362 /* Convert a DWARF attribute code into its string name. */
21364 static const char *
21365 dwarf_attr_name (unsigned attr
)
21369 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21370 if (attr
== DW_AT_MIPS_fde
)
21371 return "DW_AT_MIPS_fde";
21373 if (attr
== DW_AT_HP_block_index
)
21374 return "DW_AT_HP_block_index";
21377 name
= get_DW_AT_name (attr
);
21380 return dwarf_unknown ("AT", attr
);
21385 /* Convert a DWARF value form code into its string name. */
21387 static const char *
21388 dwarf_form_name (unsigned form
)
21390 const char *name
= get_DW_FORM_name (form
);
21393 return dwarf_unknown ("FORM", form
);
21398 static const char *
21399 dwarf_bool_name (unsigned mybool
)
21407 /* Convert a DWARF type code into its string name. */
21409 static const char *
21410 dwarf_type_encoding_name (unsigned enc
)
21412 const char *name
= get_DW_ATE_name (enc
);
21415 return dwarf_unknown ("ATE", enc
);
21421 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21425 print_spaces (indent
, f
);
21426 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21427 dwarf_tag_name (die
->tag
), die
->abbrev
,
21428 sect_offset_str (die
->sect_off
));
21430 if (die
->parent
!= NULL
)
21432 print_spaces (indent
, f
);
21433 fprintf_unfiltered (f
, " parent at offset: %s\n",
21434 sect_offset_str (die
->parent
->sect_off
));
21437 print_spaces (indent
, f
);
21438 fprintf_unfiltered (f
, " has children: %s\n",
21439 dwarf_bool_name (die
->child
!= NULL
));
21441 print_spaces (indent
, f
);
21442 fprintf_unfiltered (f
, " attributes:\n");
21444 for (i
= 0; i
< die
->num_attrs
; ++i
)
21446 print_spaces (indent
, f
);
21447 fprintf_unfiltered (f
, " %s (%s) ",
21448 dwarf_attr_name (die
->attrs
[i
].name
),
21449 dwarf_form_name (die
->attrs
[i
].form
));
21451 switch (die
->attrs
[i
].form
)
21454 case DW_FORM_addrx
:
21455 case DW_FORM_GNU_addr_index
:
21456 fprintf_unfiltered (f
, "address: ");
21457 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21459 case DW_FORM_block2
:
21460 case DW_FORM_block4
:
21461 case DW_FORM_block
:
21462 case DW_FORM_block1
:
21463 fprintf_unfiltered (f
, "block: size %s",
21464 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21466 case DW_FORM_exprloc
:
21467 fprintf_unfiltered (f
, "expression: size %s",
21468 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21470 case DW_FORM_data16
:
21471 fprintf_unfiltered (f
, "constant of 16 bytes");
21473 case DW_FORM_ref_addr
:
21474 fprintf_unfiltered (f
, "ref address: ");
21475 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21477 case DW_FORM_GNU_ref_alt
:
21478 fprintf_unfiltered (f
, "alt ref address: ");
21479 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21485 case DW_FORM_ref_udata
:
21486 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21487 (long) (DW_UNSND (&die
->attrs
[i
])));
21489 case DW_FORM_data1
:
21490 case DW_FORM_data2
:
21491 case DW_FORM_data4
:
21492 case DW_FORM_data8
:
21493 case DW_FORM_udata
:
21494 case DW_FORM_sdata
:
21495 fprintf_unfiltered (f
, "constant: %s",
21496 pulongest (DW_UNSND (&die
->attrs
[i
])));
21498 case DW_FORM_sec_offset
:
21499 fprintf_unfiltered (f
, "section offset: %s",
21500 pulongest (DW_UNSND (&die
->attrs
[i
])));
21502 case DW_FORM_ref_sig8
:
21503 fprintf_unfiltered (f
, "signature: %s",
21504 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21506 case DW_FORM_string
:
21508 case DW_FORM_line_strp
:
21510 case DW_FORM_GNU_str_index
:
21511 case DW_FORM_GNU_strp_alt
:
21512 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21513 DW_STRING (&die
->attrs
[i
])
21514 ? DW_STRING (&die
->attrs
[i
]) : "",
21515 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21518 if (DW_UNSND (&die
->attrs
[i
]))
21519 fprintf_unfiltered (f
, "flag: TRUE");
21521 fprintf_unfiltered (f
, "flag: FALSE");
21523 case DW_FORM_flag_present
:
21524 fprintf_unfiltered (f
, "flag: TRUE");
21526 case DW_FORM_indirect
:
21527 /* The reader will have reduced the indirect form to
21528 the "base form" so this form should not occur. */
21529 fprintf_unfiltered (f
,
21530 "unexpected attribute form: DW_FORM_indirect");
21532 case DW_FORM_implicit_const
:
21533 fprintf_unfiltered (f
, "constant: %s",
21534 plongest (DW_SND (&die
->attrs
[i
])));
21537 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21538 die
->attrs
[i
].form
);
21541 fprintf_unfiltered (f
, "\n");
21546 dump_die_for_error (struct die_info
*die
)
21548 dump_die_shallow (gdb_stderr
, 0, die
);
21552 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21554 int indent
= level
* 4;
21556 gdb_assert (die
!= NULL
);
21558 if (level
>= max_level
)
21561 dump_die_shallow (f
, indent
, die
);
21563 if (die
->child
!= NULL
)
21565 print_spaces (indent
, f
);
21566 fprintf_unfiltered (f
, " Children:");
21567 if (level
+ 1 < max_level
)
21569 fprintf_unfiltered (f
, "\n");
21570 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21574 fprintf_unfiltered (f
,
21575 " [not printed, max nesting level reached]\n");
21579 if (die
->sibling
!= NULL
&& level
> 0)
21581 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21585 /* This is called from the pdie macro in gdbinit.in.
21586 It's not static so gcc will keep a copy callable from gdb. */
21589 dump_die (struct die_info
*die
, int max_level
)
21591 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21595 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21599 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21600 to_underlying (die
->sect_off
),
21606 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
21610 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
21612 if (attr
->form_is_ref ())
21613 return (sect_offset
) DW_UNSND (attr
);
21615 complaint (_("unsupported die ref attribute form: '%s'"),
21616 dwarf_form_name (attr
->form
));
21620 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
21621 * the value held by the attribute is not constant. */
21624 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
21626 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
21627 return DW_SND (attr
);
21628 else if (attr
->form
== DW_FORM_udata
21629 || attr
->form
== DW_FORM_data1
21630 || attr
->form
== DW_FORM_data2
21631 || attr
->form
== DW_FORM_data4
21632 || attr
->form
== DW_FORM_data8
)
21633 return DW_UNSND (attr
);
21636 /* For DW_FORM_data16 see attribute::form_is_constant. */
21637 complaint (_("Attribute value is not a constant (%s)"),
21638 dwarf_form_name (attr
->form
));
21639 return default_value
;
21643 /* Follow reference or signature attribute ATTR of SRC_DIE.
21644 On entry *REF_CU is the CU of SRC_DIE.
21645 On exit *REF_CU is the CU of the result. */
21647 static struct die_info
*
21648 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21649 struct dwarf2_cu
**ref_cu
)
21651 struct die_info
*die
;
21653 if (attr
->form_is_ref ())
21654 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21655 else if (attr
->form
== DW_FORM_ref_sig8
)
21656 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21659 dump_die_for_error (src_die
);
21660 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21661 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21667 /* Follow reference OFFSET.
21668 On entry *REF_CU is the CU of the source die referencing OFFSET.
21669 On exit *REF_CU is the CU of the result.
21670 Returns NULL if OFFSET is invalid. */
21672 static struct die_info
*
21673 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21674 struct dwarf2_cu
**ref_cu
)
21676 struct die_info temp_die
;
21677 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21678 struct dwarf2_per_objfile
*dwarf2_per_objfile
21679 = cu
->per_cu
->dwarf2_per_objfile
;
21681 gdb_assert (cu
->per_cu
!= NULL
);
21685 if (cu
->per_cu
->is_debug_types
)
21687 /* .debug_types CUs cannot reference anything outside their CU.
21688 If they need to, they have to reference a signatured type via
21689 DW_FORM_ref_sig8. */
21690 if (!cu
->header
.offset_in_cu_p (sect_off
))
21693 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21694 || !cu
->header
.offset_in_cu_p (sect_off
))
21696 struct dwarf2_per_cu_data
*per_cu
;
21698 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21699 dwarf2_per_objfile
);
21701 /* If necessary, add it to the queue and load its DIEs. */
21702 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21703 load_full_comp_unit (per_cu
, false, cu
->language
);
21705 target_cu
= per_cu
->cu
;
21707 else if (cu
->dies
== NULL
)
21709 /* We're loading full DIEs during partial symbol reading. */
21710 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21711 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21714 *ref_cu
= target_cu
;
21715 temp_die
.sect_off
= sect_off
;
21717 if (target_cu
!= cu
)
21718 target_cu
->ancestor
= cu
;
21720 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21722 to_underlying (sect_off
));
21725 /* Follow reference attribute ATTR of SRC_DIE.
21726 On entry *REF_CU is the CU of SRC_DIE.
21727 On exit *REF_CU is the CU of the result. */
21729 static struct die_info
*
21730 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21731 struct dwarf2_cu
**ref_cu
)
21733 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21734 struct dwarf2_cu
*cu
= *ref_cu
;
21735 struct die_info
*die
;
21737 die
= follow_die_offset (sect_off
,
21738 (attr
->form
== DW_FORM_GNU_ref_alt
21739 || cu
->per_cu
->is_dwz
),
21742 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21743 "at %s [in module %s]"),
21744 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21745 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21752 struct dwarf2_locexpr_baton
21753 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21754 dwarf2_per_cu_data
*per_cu
,
21755 CORE_ADDR (*get_frame_pc
) (void *baton
),
21756 void *baton
, bool resolve_abstract_p
)
21758 struct dwarf2_cu
*cu
;
21759 struct die_info
*die
;
21760 struct attribute
*attr
;
21761 struct dwarf2_locexpr_baton retval
;
21762 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21763 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21765 if (per_cu
->cu
== NULL
)
21766 load_cu (per_cu
, false);
21770 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21771 Instead just throw an error, not much else we can do. */
21772 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21773 sect_offset_str (sect_off
), objfile_name (objfile
));
21776 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21778 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21779 sect_offset_str (sect_off
), objfile_name (objfile
));
21781 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21782 if (!attr
&& resolve_abstract_p
21783 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21784 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21786 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21787 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21788 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21790 for (const auto &cand_off
21791 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21793 struct dwarf2_cu
*cand_cu
= cu
;
21794 struct die_info
*cand
21795 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21798 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21801 CORE_ADDR pc_low
, pc_high
;
21802 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21803 if (pc_low
== ((CORE_ADDR
) -1))
21805 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21806 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21807 if (!(pc_low
<= pc
&& pc
< pc_high
))
21811 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21818 /* DWARF: "If there is no such attribute, then there is no effect.".
21819 DATA is ignored if SIZE is 0. */
21821 retval
.data
= NULL
;
21824 else if (attr
->form_is_section_offset ())
21826 struct dwarf2_loclist_baton loclist_baton
;
21827 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21830 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21832 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21834 retval
.size
= size
;
21838 if (!attr
->form_is_block ())
21839 error (_("Dwarf Error: DIE at %s referenced in module %s "
21840 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21841 sect_offset_str (sect_off
), objfile_name (objfile
));
21843 retval
.data
= DW_BLOCK (attr
)->data
;
21844 retval
.size
= DW_BLOCK (attr
)->size
;
21846 retval
.per_cu
= cu
->per_cu
;
21848 age_cached_comp_units (dwarf2_per_objfile
);
21855 struct dwarf2_locexpr_baton
21856 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21857 dwarf2_per_cu_data
*per_cu
,
21858 CORE_ADDR (*get_frame_pc
) (void *baton
),
21861 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21863 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21866 /* Write a constant of a given type as target-ordered bytes into
21869 static const gdb_byte
*
21870 write_constant_as_bytes (struct obstack
*obstack
,
21871 enum bfd_endian byte_order
,
21878 *len
= TYPE_LENGTH (type
);
21879 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21880 store_unsigned_integer (result
, *len
, byte_order
, value
);
21888 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21889 dwarf2_per_cu_data
*per_cu
,
21893 struct dwarf2_cu
*cu
;
21894 struct die_info
*die
;
21895 struct attribute
*attr
;
21896 const gdb_byte
*result
= NULL
;
21899 enum bfd_endian byte_order
;
21900 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
21902 if (per_cu
->cu
== NULL
)
21903 load_cu (per_cu
, false);
21907 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21908 Instead just throw an error, not much else we can do. */
21909 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21910 sect_offset_str (sect_off
), objfile_name (objfile
));
21913 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21915 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21916 sect_offset_str (sect_off
), objfile_name (objfile
));
21918 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21922 byte_order
= (bfd_big_endian (objfile
->obfd
)
21923 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21925 switch (attr
->form
)
21928 case DW_FORM_addrx
:
21929 case DW_FORM_GNU_addr_index
:
21933 *len
= cu
->header
.addr_size
;
21934 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21935 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
21939 case DW_FORM_string
:
21942 case DW_FORM_GNU_str_index
:
21943 case DW_FORM_GNU_strp_alt
:
21944 /* DW_STRING is already allocated on the objfile obstack, point
21946 result
= (const gdb_byte
*) DW_STRING (attr
);
21947 *len
= strlen (DW_STRING (attr
));
21949 case DW_FORM_block1
:
21950 case DW_FORM_block2
:
21951 case DW_FORM_block4
:
21952 case DW_FORM_block
:
21953 case DW_FORM_exprloc
:
21954 case DW_FORM_data16
:
21955 result
= DW_BLOCK (attr
)->data
;
21956 *len
= DW_BLOCK (attr
)->size
;
21959 /* The DW_AT_const_value attributes are supposed to carry the
21960 symbol's value "represented as it would be on the target
21961 architecture." By the time we get here, it's already been
21962 converted to host endianness, so we just need to sign- or
21963 zero-extend it as appropriate. */
21964 case DW_FORM_data1
:
21965 type
= die_type (die
, cu
);
21966 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
21967 if (result
== NULL
)
21968 result
= write_constant_as_bytes (obstack
, byte_order
,
21971 case DW_FORM_data2
:
21972 type
= die_type (die
, cu
);
21973 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
21974 if (result
== NULL
)
21975 result
= write_constant_as_bytes (obstack
, byte_order
,
21978 case DW_FORM_data4
:
21979 type
= die_type (die
, cu
);
21980 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
21981 if (result
== NULL
)
21982 result
= write_constant_as_bytes (obstack
, byte_order
,
21985 case DW_FORM_data8
:
21986 type
= die_type (die
, cu
);
21987 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
21988 if (result
== NULL
)
21989 result
= write_constant_as_bytes (obstack
, byte_order
,
21993 case DW_FORM_sdata
:
21994 case DW_FORM_implicit_const
:
21995 type
= die_type (die
, cu
);
21996 result
= write_constant_as_bytes (obstack
, byte_order
,
21997 type
, DW_SND (attr
), len
);
22000 case DW_FORM_udata
:
22001 type
= die_type (die
, cu
);
22002 result
= write_constant_as_bytes (obstack
, byte_order
,
22003 type
, DW_UNSND (attr
), len
);
22007 complaint (_("unsupported const value attribute form: '%s'"),
22008 dwarf_form_name (attr
->form
));
22018 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22019 dwarf2_per_cu_data
*per_cu
)
22021 struct dwarf2_cu
*cu
;
22022 struct die_info
*die
;
22024 if (per_cu
->cu
== NULL
)
22025 load_cu (per_cu
, false);
22030 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22034 return die_type (die
, cu
);
22040 dwarf2_get_die_type (cu_offset die_offset
,
22041 struct dwarf2_per_cu_data
*per_cu
)
22043 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22044 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22047 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22048 On entry *REF_CU is the CU of SRC_DIE.
22049 On exit *REF_CU is the CU of the result.
22050 Returns NULL if the referenced DIE isn't found. */
22052 static struct die_info
*
22053 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22054 struct dwarf2_cu
**ref_cu
)
22056 struct die_info temp_die
;
22057 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22058 struct die_info
*die
;
22060 /* While it might be nice to assert sig_type->type == NULL here,
22061 we can get here for DW_AT_imported_declaration where we need
22062 the DIE not the type. */
22064 /* If necessary, add it to the queue and load its DIEs. */
22066 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22067 read_signatured_type (sig_type
);
22069 sig_cu
= sig_type
->per_cu
.cu
;
22070 gdb_assert (sig_cu
!= NULL
);
22071 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22072 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22073 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22074 to_underlying (temp_die
.sect_off
));
22077 struct dwarf2_per_objfile
*dwarf2_per_objfile
22078 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22080 /* For .gdb_index version 7 keep track of included TUs.
22081 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22082 if (dwarf2_per_objfile
->index_table
!= NULL
22083 && dwarf2_per_objfile
->index_table
->version
<= 7)
22085 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22090 sig_cu
->ancestor
= cu
;
22098 /* Follow signatured type referenced by ATTR in SRC_DIE.
22099 On entry *REF_CU is the CU of SRC_DIE.
22100 On exit *REF_CU is the CU of the result.
22101 The result is the DIE of the type.
22102 If the referenced type cannot be found an error is thrown. */
22104 static struct die_info
*
22105 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22106 struct dwarf2_cu
**ref_cu
)
22108 ULONGEST signature
= DW_SIGNATURE (attr
);
22109 struct signatured_type
*sig_type
;
22110 struct die_info
*die
;
22112 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22114 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22115 /* sig_type will be NULL if the signatured type is missing from
22117 if (sig_type
== NULL
)
22119 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22120 " from DIE at %s [in module %s]"),
22121 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22122 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22125 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22128 dump_die_for_error (src_die
);
22129 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22130 " from DIE at %s [in module %s]"),
22131 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22132 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22138 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22139 reading in and processing the type unit if necessary. */
22141 static struct type
*
22142 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22143 struct dwarf2_cu
*cu
)
22145 struct dwarf2_per_objfile
*dwarf2_per_objfile
22146 = cu
->per_cu
->dwarf2_per_objfile
;
22147 struct signatured_type
*sig_type
;
22148 struct dwarf2_cu
*type_cu
;
22149 struct die_info
*type_die
;
22152 sig_type
= lookup_signatured_type (cu
, signature
);
22153 /* sig_type will be NULL if the signatured type is missing from
22155 if (sig_type
== NULL
)
22157 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22158 " from DIE at %s [in module %s]"),
22159 hex_string (signature
), sect_offset_str (die
->sect_off
),
22160 objfile_name (dwarf2_per_objfile
->objfile
));
22161 return build_error_marker_type (cu
, die
);
22164 /* If we already know the type we're done. */
22165 if (sig_type
->type
!= NULL
)
22166 return sig_type
->type
;
22169 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22170 if (type_die
!= NULL
)
22172 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22173 is created. This is important, for example, because for c++ classes
22174 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22175 type
= read_type_die (type_die
, type_cu
);
22178 complaint (_("Dwarf Error: Cannot build signatured type %s"
22179 " referenced from DIE at %s [in module %s]"),
22180 hex_string (signature
), sect_offset_str (die
->sect_off
),
22181 objfile_name (dwarf2_per_objfile
->objfile
));
22182 type
= build_error_marker_type (cu
, die
);
22187 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22188 " from DIE at %s [in module %s]"),
22189 hex_string (signature
), sect_offset_str (die
->sect_off
),
22190 objfile_name (dwarf2_per_objfile
->objfile
));
22191 type
= build_error_marker_type (cu
, die
);
22193 sig_type
->type
= type
;
22198 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22199 reading in and processing the type unit if necessary. */
22201 static struct type
*
22202 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22203 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22205 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22206 if (attr
->form_is_ref ())
22208 struct dwarf2_cu
*type_cu
= cu
;
22209 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22211 return read_type_die (type_die
, type_cu
);
22213 else if (attr
->form
== DW_FORM_ref_sig8
)
22215 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22219 struct dwarf2_per_objfile
*dwarf2_per_objfile
22220 = cu
->per_cu
->dwarf2_per_objfile
;
22222 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22223 " at %s [in module %s]"),
22224 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22225 objfile_name (dwarf2_per_objfile
->objfile
));
22226 return build_error_marker_type (cu
, die
);
22230 /* Load the DIEs associated with type unit PER_CU into memory. */
22233 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22235 struct signatured_type
*sig_type
;
22237 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22238 gdb_assert (! per_cu
->type_unit_group_p ());
22240 /* We have the per_cu, but we need the signatured_type.
22241 Fortunately this is an easy translation. */
22242 gdb_assert (per_cu
->is_debug_types
);
22243 sig_type
= (struct signatured_type
*) per_cu
;
22245 gdb_assert (per_cu
->cu
== NULL
);
22247 read_signatured_type (sig_type
);
22249 gdb_assert (per_cu
->cu
!= NULL
);
22252 /* Read in a signatured type and build its CU and DIEs.
22253 If the type is a stub for the real type in a DWO file,
22254 read in the real type from the DWO file as well. */
22257 read_signatured_type (struct signatured_type
*sig_type
)
22259 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22261 gdb_assert (per_cu
->is_debug_types
);
22262 gdb_assert (per_cu
->cu
== NULL
);
22264 cutu_reader
reader (per_cu
, NULL
, 0, false);
22266 if (!reader
.dummy_p
)
22268 struct dwarf2_cu
*cu
= reader
.cu
;
22269 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22271 gdb_assert (cu
->die_hash
== NULL
);
22273 htab_create_alloc_ex (cu
->header
.length
/ 12,
22277 &cu
->comp_unit_obstack
,
22278 hashtab_obstack_allocate
,
22279 dummy_obstack_deallocate
);
22281 if (reader
.comp_unit_die
->has_children
)
22282 reader
.comp_unit_die
->child
22283 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22284 reader
.comp_unit_die
);
22285 cu
->dies
= reader
.comp_unit_die
;
22286 /* comp_unit_die is not stored in die_hash, no need. */
22288 /* We try not to read any attributes in this function, because
22289 not all CUs needed for references have been loaded yet, and
22290 symbol table processing isn't initialized. But we have to
22291 set the CU language, or we won't be able to build types
22292 correctly. Similarly, if we do not read the producer, we can
22293 not apply producer-specific interpretation. */
22294 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22299 sig_type
->per_cu
.tu_read
= 1;
22302 /* Decode simple location descriptions.
22303 Given a pointer to a dwarf block that defines a location, compute
22304 the location and return the value.
22306 NOTE drow/2003-11-18: This function is called in two situations
22307 now: for the address of static or global variables (partial symbols
22308 only) and for offsets into structures which are expected to be
22309 (more or less) constant. The partial symbol case should go away,
22310 and only the constant case should remain. That will let this
22311 function complain more accurately. A few special modes are allowed
22312 without complaint for global variables (for instance, global
22313 register values and thread-local values).
22315 A location description containing no operations indicates that the
22316 object is optimized out. The return value is 0 for that case.
22317 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22318 callers will only want a very basic result and this can become a
22321 Note that stack[0] is unused except as a default error return. */
22324 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22326 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22328 size_t size
= blk
->size
;
22329 const gdb_byte
*data
= blk
->data
;
22330 CORE_ADDR stack
[64];
22332 unsigned int bytes_read
, unsnd
;
22338 stack
[++stacki
] = 0;
22377 stack
[++stacki
] = op
- DW_OP_lit0
;
22412 stack
[++stacki
] = op
- DW_OP_reg0
;
22414 dwarf2_complex_location_expr_complaint ();
22418 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22420 stack
[++stacki
] = unsnd
;
22422 dwarf2_complex_location_expr_complaint ();
22426 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22431 case DW_OP_const1u
:
22432 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22436 case DW_OP_const1s
:
22437 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22441 case DW_OP_const2u
:
22442 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22446 case DW_OP_const2s
:
22447 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22451 case DW_OP_const4u
:
22452 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22456 case DW_OP_const4s
:
22457 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22461 case DW_OP_const8u
:
22462 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22467 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22473 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22478 stack
[stacki
+ 1] = stack
[stacki
];
22483 stack
[stacki
- 1] += stack
[stacki
];
22487 case DW_OP_plus_uconst
:
22488 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22494 stack
[stacki
- 1] -= stack
[stacki
];
22499 /* If we're not the last op, then we definitely can't encode
22500 this using GDB's address_class enum. This is valid for partial
22501 global symbols, although the variable's address will be bogus
22504 dwarf2_complex_location_expr_complaint ();
22507 case DW_OP_GNU_push_tls_address
:
22508 case DW_OP_form_tls_address
:
22509 /* The top of the stack has the offset from the beginning
22510 of the thread control block at which the variable is located. */
22511 /* Nothing should follow this operator, so the top of stack would
22513 /* This is valid for partial global symbols, but the variable's
22514 address will be bogus in the psymtab. Make it always at least
22515 non-zero to not look as a variable garbage collected by linker
22516 which have DW_OP_addr 0. */
22518 dwarf2_complex_location_expr_complaint ();
22522 case DW_OP_GNU_uninit
:
22526 case DW_OP_GNU_addr_index
:
22527 case DW_OP_GNU_const_index
:
22528 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22535 const char *name
= get_DW_OP_name (op
);
22538 complaint (_("unsupported stack op: '%s'"),
22541 complaint (_("unsupported stack op: '%02x'"),
22545 return (stack
[stacki
]);
22548 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22549 outside of the allocated space. Also enforce minimum>0. */
22550 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22552 complaint (_("location description stack overflow"));
22558 complaint (_("location description stack underflow"));
22562 return (stack
[stacki
]);
22565 /* memory allocation interface */
22567 static struct dwarf_block
*
22568 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22570 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22573 static struct die_info
*
22574 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22576 struct die_info
*die
;
22577 size_t size
= sizeof (struct die_info
);
22580 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22582 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22583 memset (die
, 0, sizeof (struct die_info
));
22589 /* Macro support. */
22591 /* An overload of dwarf_decode_macros that finds the correct section
22592 and ensures it is read in before calling the other overload. */
22595 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22596 int section_is_gnu
)
22598 struct dwarf2_per_objfile
*dwarf2_per_objfile
22599 = cu
->per_cu
->dwarf2_per_objfile
;
22600 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22601 const struct line_header
*lh
= cu
->line_header
;
22602 unsigned int offset_size
= cu
->header
.offset_size
;
22603 struct dwarf2_section_info
*section
;
22604 const char *section_name
;
22606 if (cu
->dwo_unit
!= nullptr)
22608 if (section_is_gnu
)
22610 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22611 section_name
= ".debug_macro.dwo";
22615 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22616 section_name
= ".debug_macinfo.dwo";
22621 if (section_is_gnu
)
22623 section
= &dwarf2_per_objfile
->macro
;
22624 section_name
= ".debug_macro";
22628 section
= &dwarf2_per_objfile
->macinfo
;
22629 section_name
= ".debug_macinfo";
22633 section
->read (objfile
);
22634 if (section
->buffer
== nullptr)
22636 complaint (_("missing %s section"), section_name
);
22640 buildsym_compunit
*builder
= cu
->get_builder ();
22642 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22643 offset_size
, offset
, section_is_gnu
);
22646 /* Return the .debug_loc section to use for CU.
22647 For DWO files use .debug_loc.dwo. */
22649 static struct dwarf2_section_info
*
22650 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22652 struct dwarf2_per_objfile
*dwarf2_per_objfile
22653 = cu
->per_cu
->dwarf2_per_objfile
;
22657 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22659 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22661 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22662 : &dwarf2_per_objfile
->loc
);
22665 /* A helper function that fills in a dwarf2_loclist_baton. */
22668 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22669 struct dwarf2_loclist_baton
*baton
,
22670 const struct attribute
*attr
)
22672 struct dwarf2_per_objfile
*dwarf2_per_objfile
22673 = cu
->per_cu
->dwarf2_per_objfile
;
22674 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22676 section
->read (dwarf2_per_objfile
->objfile
);
22678 baton
->per_cu
= cu
->per_cu
;
22679 gdb_assert (baton
->per_cu
);
22680 /* We don't know how long the location list is, but make sure we
22681 don't run off the edge of the section. */
22682 baton
->size
= section
->size
- DW_UNSND (attr
);
22683 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22684 if (cu
->base_address
.has_value ())
22685 baton
->base_address
= *cu
->base_address
;
22687 baton
->base_address
= 0;
22688 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22692 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22693 struct dwarf2_cu
*cu
, int is_block
)
22695 struct dwarf2_per_objfile
*dwarf2_per_objfile
22696 = cu
->per_cu
->dwarf2_per_objfile
;
22697 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22698 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22700 if (attr
->form_is_section_offset ()
22701 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22702 the section. If so, fall through to the complaint in the
22704 && DW_UNSND (attr
) < section
->get_size (objfile
))
22706 struct dwarf2_loclist_baton
*baton
;
22708 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22710 fill_in_loclist_baton (cu
, baton
, attr
);
22712 if (!cu
->base_address
.has_value ())
22713 complaint (_("Location list used without "
22714 "specifying the CU base address."));
22716 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22717 ? dwarf2_loclist_block_index
22718 : dwarf2_loclist_index
);
22719 SYMBOL_LOCATION_BATON (sym
) = baton
;
22723 struct dwarf2_locexpr_baton
*baton
;
22725 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22726 baton
->per_cu
= cu
->per_cu
;
22727 gdb_assert (baton
->per_cu
);
22729 if (attr
->form_is_block ())
22731 /* Note that we're just copying the block's data pointer
22732 here, not the actual data. We're still pointing into the
22733 info_buffer for SYM's objfile; right now we never release
22734 that buffer, but when we do clean up properly this may
22736 baton
->size
= DW_BLOCK (attr
)->size
;
22737 baton
->data
= DW_BLOCK (attr
)->data
;
22741 dwarf2_invalid_attrib_class_complaint ("location description",
22742 sym
->natural_name ());
22746 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22747 ? dwarf2_locexpr_block_index
22748 : dwarf2_locexpr_index
);
22749 SYMBOL_LOCATION_BATON (sym
) = baton
;
22756 dwarf2_per_cu_data::objfile () const
22758 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22760 /* Return the master objfile, so that we can report and look up the
22761 correct file containing this variable. */
22762 if (objfile
->separate_debug_objfile_backlink
)
22763 objfile
= objfile
->separate_debug_objfile_backlink
;
22768 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22769 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22770 CU_HEADERP first. */
22772 static const struct comp_unit_head
*
22773 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22774 const struct dwarf2_per_cu_data
*per_cu
)
22776 const gdb_byte
*info_ptr
;
22779 return &per_cu
->cu
->header
;
22781 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22783 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22784 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22785 rcuh_kind::COMPILE
);
22793 dwarf2_per_cu_data::addr_size () const
22795 struct comp_unit_head cu_header_local
;
22796 const struct comp_unit_head
*cu_headerp
;
22798 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22800 return cu_headerp
->addr_size
;
22806 dwarf2_per_cu_data::offset_size () const
22808 struct comp_unit_head cu_header_local
;
22809 const struct comp_unit_head
*cu_headerp
;
22811 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22813 return cu_headerp
->offset_size
;
22819 dwarf2_per_cu_data::ref_addr_size () const
22821 struct comp_unit_head cu_header_local
;
22822 const struct comp_unit_head
*cu_headerp
;
22824 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22826 if (cu_headerp
->version
== 2)
22827 return cu_headerp
->addr_size
;
22829 return cu_headerp
->offset_size
;
22835 dwarf2_per_cu_data::text_offset () const
22837 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22839 return objfile
->text_section_offset ();
22845 dwarf2_per_cu_data::addr_type () const
22847 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22848 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22849 struct type
*addr_type
= lookup_pointer_type (void_type
);
22850 int addr_size
= this->addr_size ();
22852 if (TYPE_LENGTH (addr_type
) == addr_size
)
22855 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22859 /* A helper function for dwarf2_find_containing_comp_unit that returns
22860 the index of the result, and that searches a vector. It will
22861 return a result even if the offset in question does not actually
22862 occur in any CU. This is separate so that it can be unit
22866 dwarf2_find_containing_comp_unit
22867 (sect_offset sect_off
,
22868 unsigned int offset_in_dwz
,
22869 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22874 high
= all_comp_units
.size () - 1;
22877 struct dwarf2_per_cu_data
*mid_cu
;
22878 int mid
= low
+ (high
- low
) / 2;
22880 mid_cu
= all_comp_units
[mid
];
22881 if (mid_cu
->is_dwz
> offset_in_dwz
22882 || (mid_cu
->is_dwz
== offset_in_dwz
22883 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
22888 gdb_assert (low
== high
);
22892 /* Locate the .debug_info compilation unit from CU's objfile which contains
22893 the DIE at OFFSET. Raises an error on failure. */
22895 static struct dwarf2_per_cu_data
*
22896 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22897 unsigned int offset_in_dwz
,
22898 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22901 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22902 dwarf2_per_objfile
->all_comp_units
);
22903 struct dwarf2_per_cu_data
*this_cu
22904 = dwarf2_per_objfile
->all_comp_units
[low
];
22906 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
22908 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22909 error (_("Dwarf Error: could not find partial DIE containing "
22910 "offset %s [in module %s]"),
22911 sect_offset_str (sect_off
),
22912 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
22914 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22916 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22920 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
22921 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
22922 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
22923 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
22930 namespace selftests
{
22931 namespace find_containing_comp_unit
{
22936 struct dwarf2_per_cu_data one
{};
22937 struct dwarf2_per_cu_data two
{};
22938 struct dwarf2_per_cu_data three
{};
22939 struct dwarf2_per_cu_data four
{};
22942 two
.sect_off
= sect_offset (one
.length
);
22947 four
.sect_off
= sect_offset (three
.length
);
22951 std::vector
<dwarf2_per_cu_data
*> units
;
22952 units
.push_back (&one
);
22953 units
.push_back (&two
);
22954 units
.push_back (&three
);
22955 units
.push_back (&four
);
22959 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
22960 SELF_CHECK (units
[result
] == &one
);
22961 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
22962 SELF_CHECK (units
[result
] == &one
);
22963 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
22964 SELF_CHECK (units
[result
] == &two
);
22966 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
22967 SELF_CHECK (units
[result
] == &three
);
22968 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
22969 SELF_CHECK (units
[result
] == &three
);
22970 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
22971 SELF_CHECK (units
[result
] == &four
);
22977 #endif /* GDB_SELF_TEST */
22979 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22981 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
22982 : per_cu (per_cu_
),
22984 has_loclist (false),
22985 checked_producer (false),
22986 producer_is_gxx_lt_4_6 (false),
22987 producer_is_gcc_lt_4_3 (false),
22988 producer_is_icc (false),
22989 producer_is_icc_lt_14 (false),
22990 producer_is_codewarrior (false),
22991 processing_has_namespace_info (false)
22996 /* Destroy a dwarf2_cu. */
22998 dwarf2_cu::~dwarf2_cu ()
23003 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23006 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23007 enum language pretend_language
)
23009 struct attribute
*attr
;
23011 /* Set the language we're debugging. */
23012 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23013 if (attr
!= nullptr)
23014 set_cu_language (DW_UNSND (attr
), cu
);
23017 cu
->language
= pretend_language
;
23018 cu
->language_defn
= language_def (cu
->language
);
23021 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23024 /* Increase the age counter on each cached compilation unit, and free
23025 any that are too old. */
23028 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23030 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23032 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23033 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23034 while (per_cu
!= NULL
)
23036 per_cu
->cu
->last_used
++;
23037 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23038 dwarf2_mark (per_cu
->cu
);
23039 per_cu
= per_cu
->cu
->read_in_chain
;
23042 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23043 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23044 while (per_cu
!= NULL
)
23046 struct dwarf2_per_cu_data
*next_cu
;
23048 next_cu
= per_cu
->cu
->read_in_chain
;
23050 if (!per_cu
->cu
->mark
)
23053 *last_chain
= next_cu
;
23056 last_chain
= &per_cu
->cu
->read_in_chain
;
23062 /* Remove a single compilation unit from the cache. */
23065 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23067 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23068 struct dwarf2_per_objfile
*dwarf2_per_objfile
23069 = target_per_cu
->dwarf2_per_objfile
;
23071 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23072 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23073 while (per_cu
!= NULL
)
23075 struct dwarf2_per_cu_data
*next_cu
;
23077 next_cu
= per_cu
->cu
->read_in_chain
;
23079 if (per_cu
== target_per_cu
)
23083 *last_chain
= next_cu
;
23087 last_chain
= &per_cu
->cu
->read_in_chain
;
23093 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23094 We store these in a hash table separate from the DIEs, and preserve them
23095 when the DIEs are flushed out of cache.
23097 The CU "per_cu" pointer is needed because offset alone is not enough to
23098 uniquely identify the type. A file may have multiple .debug_types sections,
23099 or the type may come from a DWO file. Furthermore, while it's more logical
23100 to use per_cu->section+offset, with Fission the section with the data is in
23101 the DWO file but we don't know that section at the point we need it.
23102 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23103 because we can enter the lookup routine, get_die_type_at_offset, from
23104 outside this file, and thus won't necessarily have PER_CU->cu.
23105 Fortunately, PER_CU is stable for the life of the objfile. */
23107 struct dwarf2_per_cu_offset_and_type
23109 const struct dwarf2_per_cu_data
*per_cu
;
23110 sect_offset sect_off
;
23114 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23117 per_cu_offset_and_type_hash (const void *item
)
23119 const struct dwarf2_per_cu_offset_and_type
*ofs
23120 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23122 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23125 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23128 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23130 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23131 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23132 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23133 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23135 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23136 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23139 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23140 table if necessary. For convenience, return TYPE.
23142 The DIEs reading must have careful ordering to:
23143 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23144 reading current DIE.
23145 * Not trying to dereference contents of still incompletely read in types
23146 while reading in other DIEs.
23147 * Enable referencing still incompletely read in types just by a pointer to
23148 the type without accessing its fields.
23150 Therefore caller should follow these rules:
23151 * Try to fetch any prerequisite types we may need to build this DIE type
23152 before building the type and calling set_die_type.
23153 * After building type call set_die_type for current DIE as soon as
23154 possible before fetching more types to complete the current type.
23155 * Make the type as complete as possible before fetching more types. */
23157 static struct type
*
23158 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23160 struct dwarf2_per_objfile
*dwarf2_per_objfile
23161 = cu
->per_cu
->dwarf2_per_objfile
;
23162 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23163 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23164 struct attribute
*attr
;
23165 struct dynamic_prop prop
;
23167 /* For Ada types, make sure that the gnat-specific data is always
23168 initialized (if not already set). There are a few types where
23169 we should not be doing so, because the type-specific area is
23170 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23171 where the type-specific area is used to store the floatformat).
23172 But this is not a problem, because the gnat-specific information
23173 is actually not needed for these types. */
23174 if (need_gnat_info (cu
)
23175 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23176 && TYPE_CODE (type
) != TYPE_CODE_FLT
23177 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23178 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23179 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23180 && !HAVE_GNAT_AUX_INFO (type
))
23181 INIT_GNAT_SPECIFIC (type
);
23183 /* Read DW_AT_allocated and set in type. */
23184 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23185 if (attr
!= NULL
&& attr
->form_is_block ())
23187 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23188 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23189 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23191 else if (attr
!= NULL
)
23193 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23194 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23195 sect_offset_str (die
->sect_off
));
23198 /* Read DW_AT_associated and set in type. */
23199 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23200 if (attr
!= NULL
&& attr
->form_is_block ())
23202 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23203 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23204 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23206 else if (attr
!= NULL
)
23208 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23209 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23210 sect_offset_str (die
->sect_off
));
23213 /* Read DW_AT_data_location and set in type. */
23214 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23215 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23216 cu
->per_cu
->addr_type ()))
23217 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23219 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23220 dwarf2_per_objfile
->die_type_hash
23221 = htab_up (htab_create_alloc (127,
23222 per_cu_offset_and_type_hash
,
23223 per_cu_offset_and_type_eq
,
23224 NULL
, xcalloc
, xfree
));
23226 ofs
.per_cu
= cu
->per_cu
;
23227 ofs
.sect_off
= die
->sect_off
;
23229 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23230 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23232 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23233 sect_offset_str (die
->sect_off
));
23234 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23235 struct dwarf2_per_cu_offset_and_type
);
23240 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23241 or return NULL if the die does not have a saved type. */
23243 static struct type
*
23244 get_die_type_at_offset (sect_offset sect_off
,
23245 struct dwarf2_per_cu_data
*per_cu
)
23247 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23248 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23250 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23253 ofs
.per_cu
= per_cu
;
23254 ofs
.sect_off
= sect_off
;
23255 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23256 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23263 /* Look up the type for DIE in CU in die_type_hash,
23264 or return NULL if DIE does not have a saved type. */
23266 static struct type
*
23267 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23269 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23272 /* Add a dependence relationship from CU to REF_PER_CU. */
23275 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23276 struct dwarf2_per_cu_data
*ref_per_cu
)
23280 if (cu
->dependencies
== NULL
)
23282 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23283 NULL
, &cu
->comp_unit_obstack
,
23284 hashtab_obstack_allocate
,
23285 dummy_obstack_deallocate
);
23287 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23289 *slot
= ref_per_cu
;
23292 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23293 Set the mark field in every compilation unit in the
23294 cache that we must keep because we are keeping CU. */
23297 dwarf2_mark_helper (void **slot
, void *data
)
23299 struct dwarf2_per_cu_data
*per_cu
;
23301 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23303 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23304 reading of the chain. As such dependencies remain valid it is not much
23305 useful to track and undo them during QUIT cleanups. */
23306 if (per_cu
->cu
== NULL
)
23309 if (per_cu
->cu
->mark
)
23311 per_cu
->cu
->mark
= true;
23313 if (per_cu
->cu
->dependencies
!= NULL
)
23314 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23319 /* Set the mark field in CU and in every other compilation unit in the
23320 cache that we must keep because we are keeping CU. */
23323 dwarf2_mark (struct dwarf2_cu
*cu
)
23328 if (cu
->dependencies
!= NULL
)
23329 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23333 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23337 per_cu
->cu
->mark
= false;
23338 per_cu
= per_cu
->cu
->read_in_chain
;
23342 /* Trivial hash function for partial_die_info: the hash value of a DIE
23343 is its offset in .debug_info for this objfile. */
23346 partial_die_hash (const void *item
)
23348 const struct partial_die_info
*part_die
23349 = (const struct partial_die_info
*) item
;
23351 return to_underlying (part_die
->sect_off
);
23354 /* Trivial comparison function for partial_die_info structures: two DIEs
23355 are equal if they have the same offset. */
23358 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23360 const struct partial_die_info
*part_die_lhs
23361 = (const struct partial_die_info
*) item_lhs
;
23362 const struct partial_die_info
*part_die_rhs
23363 = (const struct partial_die_info
*) item_rhs
;
23365 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23368 struct cmd_list_element
*set_dwarf_cmdlist
;
23369 struct cmd_list_element
*show_dwarf_cmdlist
;
23372 set_dwarf_cmd (const char *args
, int from_tty
)
23374 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23379 show_dwarf_cmd (const char *args
, int from_tty
)
23381 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23385 show_check_physname (struct ui_file
*file
, int from_tty
,
23386 struct cmd_list_element
*c
, const char *value
)
23388 fprintf_filtered (file
,
23389 _("Whether to check \"physname\" is %s.\n"),
23393 void _initialize_dwarf2_read ();
23395 _initialize_dwarf2_read ()
23397 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23398 Set DWARF specific variables.\n\
23399 Configure DWARF variables such as the cache size."),
23400 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23401 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23403 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23404 Show DWARF specific variables.\n\
23405 Show DWARF variables such as the cache size."),
23406 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23407 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23409 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23410 &dwarf_max_cache_age
, _("\
23411 Set the upper bound on the age of cached DWARF compilation units."), _("\
23412 Show the upper bound on the age of cached DWARF compilation units."), _("\
23413 A higher limit means that cached compilation units will be stored\n\
23414 in memory longer, and more total memory will be used. Zero disables\n\
23415 caching, which can slow down startup."),
23417 show_dwarf_max_cache_age
,
23418 &set_dwarf_cmdlist
,
23419 &show_dwarf_cmdlist
);
23421 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23422 Set debugging of the DWARF reader."), _("\
23423 Show debugging of the DWARF reader."), _("\
23424 When enabled (non-zero), debugging messages are printed during DWARF\n\
23425 reading and symtab expansion. A value of 1 (one) provides basic\n\
23426 information. A value greater than 1 provides more verbose information."),
23429 &setdebuglist
, &showdebuglist
);
23431 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23432 Set debugging of the DWARF DIE reader."), _("\
23433 Show debugging of the DWARF DIE reader."), _("\
23434 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23435 The value is the maximum depth to print."),
23438 &setdebuglist
, &showdebuglist
);
23440 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23441 Set debugging of the dwarf line reader."), _("\
23442 Show debugging of the dwarf line reader."), _("\
23443 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23444 A value of 1 (one) provides basic information.\n\
23445 A value greater than 1 provides more verbose information."),
23448 &setdebuglist
, &showdebuglist
);
23450 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23451 Set cross-checking of \"physname\" code against demangler."), _("\
23452 Show cross-checking of \"physname\" code against demangler."), _("\
23453 When enabled, GDB's internal \"physname\" code is checked against\n\
23455 NULL
, show_check_physname
,
23456 &setdebuglist
, &showdebuglist
);
23458 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23459 no_class
, &use_deprecated_index_sections
, _("\
23460 Set whether to use deprecated gdb_index sections."), _("\
23461 Show whether to use deprecated gdb_index sections."), _("\
23462 When enabled, deprecated .gdb_index sections are used anyway.\n\
23463 Normally they are ignored either because of a missing feature or\n\
23464 performance issue.\n\
23465 Warning: This option must be enabled before gdb reads the file."),
23468 &setlist
, &showlist
);
23470 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23471 &dwarf2_locexpr_funcs
);
23472 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23473 &dwarf2_loclist_funcs
);
23475 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23476 &dwarf2_block_frame_base_locexpr_funcs
);
23477 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23478 &dwarf2_block_frame_base_loclist_funcs
);
23481 selftests::register_test ("dw2_expand_symtabs_matching",
23482 selftests::dw2_expand_symtabs_matching::run_test
);
23483 selftests::register_test ("dwarf2_find_containing_comp_unit",
23484 selftests::find_containing_comp_unit::run_test
);