1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
48 #include "gdb-demangle.h"
49 #include "filenames.h" /* for DOSish file names */
52 #include "complaints.h"
53 #include "dwarf2/expr.h"
54 #include "dwarf2/loc.h"
55 #include "cp-support.h"
61 #include "typeprint.h"
66 #include "gdbcore.h" /* for gnutarget */
67 #include "gdb/gdb-index.h"
72 #include "namespace.h"
73 #include "gdbsupport/function-view.h"
74 #include "gdbsupport/gdb_optional.h"
75 #include "gdbsupport/underlying.h"
76 #include "gdbsupport/hash_enum.h"
77 #include "filename-seen-cache.h"
81 #include <unordered_map>
82 #include "gdbsupport/selftest.h"
83 #include "rust-lang.h"
84 #include "gdbsupport/pathstuff.h"
85 #include "count-one-bits.h"
87 /* When == 1, print basic high level tracing messages.
88 When > 1, be more verbose.
89 This is in contrast to the low level DIE reading of dwarf_die_debug. */
90 static unsigned int dwarf_read_debug
= 0;
92 /* When non-zero, dump DIEs after they are read in. */
93 static unsigned int dwarf_die_debug
= 0;
95 /* When non-zero, dump line number entries as they are read in. */
96 unsigned int dwarf_line_debug
= 0;
98 /* When true, cross-check physname against demangler. */
99 static bool check_physname
= false;
101 /* When true, do not reject deprecated .gdb_index sections. */
102 static bool use_deprecated_index_sections
= false;
104 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
106 /* The "aclass" indices for various kinds of computed DWARF symbols. */
108 static int dwarf2_locexpr_index
;
109 static int dwarf2_loclist_index
;
110 static int dwarf2_locexpr_block_index
;
111 static int dwarf2_loclist_block_index
;
113 /* An index into a (C++) symbol name component in a symbol name as
114 recorded in the mapped_index's symbol table. For each C++ symbol
115 in the symbol table, we record one entry for the start of each
116 component in the symbol in a table of name components, and then
117 sort the table, in order to be able to binary search symbol names,
118 ignoring leading namespaces, both completion and regular look up.
119 For example, for symbol "A::B::C", we'll have an entry that points
120 to "A::B::C", another that points to "B::C", and another for "C".
121 Note that function symbols in GDB index have no parameter
122 information, just the function/method names. You can convert a
123 name_component to a "const char *" using the
124 'mapped_index::symbol_name_at(offset_type)' method. */
126 struct name_component
128 /* Offset in the symbol name where the component starts. Stored as
129 a (32-bit) offset instead of a pointer to save memory and improve
130 locality on 64-bit architectures. */
131 offset_type name_offset
;
133 /* The symbol's index in the symbol and constant pool tables of a
138 /* Base class containing bits shared by both .gdb_index and
139 .debug_name indexes. */
141 struct mapped_index_base
143 mapped_index_base () = default;
144 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
146 /* The name_component table (a sorted vector). See name_component's
147 description above. */
148 std::vector
<name_component
> name_components
;
150 /* How NAME_COMPONENTS is sorted. */
151 enum case_sensitivity name_components_casing
;
153 /* Return the number of names in the symbol table. */
154 virtual size_t symbol_name_count () const = 0;
156 /* Get the name of the symbol at IDX in the symbol table. */
157 virtual const char *symbol_name_at (offset_type idx
) const = 0;
159 /* Return whether the name at IDX in the symbol table should be
161 virtual bool symbol_name_slot_invalid (offset_type idx
) const
166 /* Build the symbol name component sorted vector, if we haven't
168 void build_name_components ();
170 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
171 possible matches for LN_NO_PARAMS in the name component
173 std::pair
<std::vector
<name_component
>::const_iterator
,
174 std::vector
<name_component
>::const_iterator
>
175 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
176 enum language lang
) const;
178 /* Prevent deleting/destroying via a base class pointer. */
180 ~mapped_index_base() = default;
183 /* A description of the mapped index. The file format is described in
184 a comment by the code that writes the index. */
185 struct mapped_index final
: public mapped_index_base
187 /* A slot/bucket in the symbol table hash. */
188 struct symbol_table_slot
190 const offset_type name
;
191 const offset_type vec
;
194 /* Index data format version. */
197 /* The address table data. */
198 gdb::array_view
<const gdb_byte
> address_table
;
200 /* The symbol table, implemented as a hash table. */
201 gdb::array_view
<symbol_table_slot
> symbol_table
;
203 /* A pointer to the constant pool. */
204 const char *constant_pool
= nullptr;
206 bool symbol_name_slot_invalid (offset_type idx
) const override
208 const auto &bucket
= this->symbol_table
[idx
];
209 return bucket
.name
== 0 && bucket
.vec
== 0;
212 /* Convenience method to get at the name of the symbol at IDX in the
214 const char *symbol_name_at (offset_type idx
) const override
215 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
217 size_t symbol_name_count () const override
218 { return this->symbol_table
.size (); }
221 /* A description of the mapped .debug_names.
222 Uninitialized map has CU_COUNT 0. */
223 struct mapped_debug_names final
: public mapped_index_base
225 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
226 : dwarf2_per_objfile (dwarf2_per_objfile_
)
229 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
230 bfd_endian dwarf5_byte_order
;
231 bool dwarf5_is_dwarf64
;
232 bool augmentation_is_gdb
;
234 uint32_t cu_count
= 0;
235 uint32_t tu_count
, bucket_count
, name_count
;
236 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
237 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
238 const gdb_byte
*name_table_string_offs_reordered
;
239 const gdb_byte
*name_table_entry_offs_reordered
;
240 const gdb_byte
*entry_pool
;
247 /* Attribute name DW_IDX_*. */
250 /* Attribute form DW_FORM_*. */
253 /* Value if FORM is DW_FORM_implicit_const. */
254 LONGEST implicit_const
;
256 std::vector
<attr
> attr_vec
;
259 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
261 const char *namei_to_name (uint32_t namei
) const;
263 /* Implementation of the mapped_index_base virtual interface, for
264 the name_components cache. */
266 const char *symbol_name_at (offset_type idx
) const override
267 { return namei_to_name (idx
); }
269 size_t symbol_name_count () const override
270 { return this->name_count
; }
273 /* See dwarf2read.h. */
276 get_dwarf2_per_objfile (struct objfile
*objfile
)
278 return dwarf2_objfile_data_key
.get (objfile
);
281 /* Default names of the debugging sections. */
283 /* Note that if the debugging section has been compressed, it might
284 have a name like .zdebug_info. */
286 static const struct dwarf2_debug_sections dwarf2_elf_names
=
288 { ".debug_info", ".zdebug_info" },
289 { ".debug_abbrev", ".zdebug_abbrev" },
290 { ".debug_line", ".zdebug_line" },
291 { ".debug_loc", ".zdebug_loc" },
292 { ".debug_loclists", ".zdebug_loclists" },
293 { ".debug_macinfo", ".zdebug_macinfo" },
294 { ".debug_macro", ".zdebug_macro" },
295 { ".debug_str", ".zdebug_str" },
296 { ".debug_str_offsets", ".zdebug_str_offsets" },
297 { ".debug_line_str", ".zdebug_line_str" },
298 { ".debug_ranges", ".zdebug_ranges" },
299 { ".debug_rnglists", ".zdebug_rnglists" },
300 { ".debug_types", ".zdebug_types" },
301 { ".debug_addr", ".zdebug_addr" },
302 { ".debug_frame", ".zdebug_frame" },
303 { ".eh_frame", NULL
},
304 { ".gdb_index", ".zgdb_index" },
305 { ".debug_names", ".zdebug_names" },
306 { ".debug_aranges", ".zdebug_aranges" },
310 /* List of DWO/DWP sections. */
312 static const struct dwop_section_names
314 struct dwarf2_section_names abbrev_dwo
;
315 struct dwarf2_section_names info_dwo
;
316 struct dwarf2_section_names line_dwo
;
317 struct dwarf2_section_names loc_dwo
;
318 struct dwarf2_section_names loclists_dwo
;
319 struct dwarf2_section_names macinfo_dwo
;
320 struct dwarf2_section_names macro_dwo
;
321 struct dwarf2_section_names str_dwo
;
322 struct dwarf2_section_names str_offsets_dwo
;
323 struct dwarf2_section_names types_dwo
;
324 struct dwarf2_section_names cu_index
;
325 struct dwarf2_section_names tu_index
;
329 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
330 { ".debug_info.dwo", ".zdebug_info.dwo" },
331 { ".debug_line.dwo", ".zdebug_line.dwo" },
332 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
333 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
334 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
335 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
336 { ".debug_str.dwo", ".zdebug_str.dwo" },
337 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
338 { ".debug_types.dwo", ".zdebug_types.dwo" },
339 { ".debug_cu_index", ".zdebug_cu_index" },
340 { ".debug_tu_index", ".zdebug_tu_index" },
343 /* local data types */
345 /* Type used for delaying computation of method physnames.
346 See comments for compute_delayed_physnames. */
347 struct delayed_method_info
349 /* The type to which the method is attached, i.e., its parent class. */
352 /* The index of the method in the type's function fieldlists. */
355 /* The index of the method in the fieldlist. */
358 /* The name of the DIE. */
361 /* The DIE associated with this method. */
362 struct die_info
*die
;
365 /* Internal state when decoding a particular compilation unit. */
368 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
371 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
373 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
374 Create the set of symtabs used by this TU, or if this TU is sharing
375 symtabs with another TU and the symtabs have already been created
376 then restore those symtabs in the line header.
377 We don't need the pc/line-number mapping for type units. */
378 void setup_type_unit_groups (struct die_info
*die
);
380 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
381 buildsym_compunit constructor. */
382 struct compunit_symtab
*start_symtab (const char *name
,
383 const char *comp_dir
,
386 /* Reset the builder. */
387 void reset_builder () { m_builder
.reset (); }
389 /* The header of the compilation unit. */
390 struct comp_unit_head header
{};
392 /* Base address of this compilation unit. */
393 CORE_ADDR base_address
= 0;
395 /* Non-zero if base_address has been set. */
398 /* The language we are debugging. */
399 enum language language
= language_unknown
;
400 const struct language_defn
*language_defn
= nullptr;
402 const char *producer
= nullptr;
405 /* The symtab builder for this CU. This is only non-NULL when full
406 symbols are being read. */
407 std::unique_ptr
<buildsym_compunit
> m_builder
;
410 /* The generic symbol table building routines have separate lists for
411 file scope symbols and all all other scopes (local scopes). So
412 we need to select the right one to pass to add_symbol_to_list().
413 We do it by keeping a pointer to the correct list in list_in_scope.
415 FIXME: The original dwarf code just treated the file scope as the
416 first local scope, and all other local scopes as nested local
417 scopes, and worked fine. Check to see if we really need to
418 distinguish these in buildsym.c. */
419 struct pending
**list_in_scope
= nullptr;
421 /* Hash table holding all the loaded partial DIEs
422 with partial_die->offset.SECT_OFF as hash. */
423 htab_t partial_dies
= nullptr;
425 /* Storage for things with the same lifetime as this read-in compilation
426 unit, including partial DIEs. */
427 auto_obstack comp_unit_obstack
;
429 /* When multiple dwarf2_cu structures are living in memory, this field
430 chains them all together, so that they can be released efficiently.
431 We will probably also want a generation counter so that most-recently-used
432 compilation units are cached... */
433 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
435 /* Backlink to our per_cu entry. */
436 struct dwarf2_per_cu_data
*per_cu
;
438 /* How many compilation units ago was this CU last referenced? */
441 /* A hash table of DIE cu_offset for following references with
442 die_info->offset.sect_off as hash. */
443 htab_t die_hash
= nullptr;
445 /* Full DIEs if read in. */
446 struct die_info
*dies
= nullptr;
448 /* A set of pointers to dwarf2_per_cu_data objects for compilation
449 units referenced by this one. Only set during full symbol processing;
450 partial symbol tables do not have dependencies. */
451 htab_t dependencies
= nullptr;
453 /* Header data from the line table, during full symbol processing. */
454 struct line_header
*line_header
= nullptr;
455 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
456 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
457 this is the DW_TAG_compile_unit die for this CU. We'll hold on
458 to the line header as long as this DIE is being processed. See
459 process_die_scope. */
460 die_info
*line_header_die_owner
= nullptr;
462 /* A list of methods which need to have physnames computed
463 after all type information has been read. */
464 std::vector
<delayed_method_info
> method_list
;
466 /* To be copied to symtab->call_site_htab. */
467 htab_t call_site_htab
= nullptr;
469 /* Non-NULL if this CU came from a DWO file.
470 There is an invariant here that is important to remember:
471 Except for attributes copied from the top level DIE in the "main"
472 (or "stub") file in preparation for reading the DWO file
473 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
474 Either there isn't a DWO file (in which case this is NULL and the point
475 is moot), or there is and either we're not going to read it (in which
476 case this is NULL) or there is and we are reading it (in which case this
478 struct dwo_unit
*dwo_unit
= nullptr;
480 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
481 Note this value comes from the Fission stub CU/TU's DIE. */
482 gdb::optional
<ULONGEST
> addr_base
;
484 /* The DW_AT_rnglists_base attribute if present.
485 Note this value comes from the Fission stub CU/TU's DIE.
486 Also note that the value is zero in the non-DWO case so this value can
487 be used without needing to know whether DWO files are in use or not.
488 N.B. This does not apply to DW_AT_ranges appearing in
489 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
490 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
491 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
492 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
493 ULONGEST ranges_base
= 0;
495 /* When reading debug info generated by older versions of rustc, we
496 have to rewrite some union types to be struct types with a
497 variant part. This rewriting must be done after the CU is fully
498 read in, because otherwise at the point of rewriting some struct
499 type might not have been fully processed. So, we keep a list of
500 all such types here and process them after expansion. */
501 std::vector
<struct type
*> rust_unions
;
503 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
504 files, the value is implicitly zero. For DWARF 5 version DWO files, the
505 value is often implicit and is the size of the header of
506 .debug_str_offsets section (8 or 4, depending on the address size). */
507 gdb::optional
<ULONGEST
> str_offsets_base
;
509 /* Mark used when releasing cached dies. */
512 /* This CU references .debug_loc. See the symtab->locations_valid field.
513 This test is imperfect as there may exist optimized debug code not using
514 any location list and still facing inlining issues if handled as
515 unoptimized code. For a future better test see GCC PR other/32998. */
516 bool has_loclist
: 1;
518 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
519 if all the producer_is_* fields are valid. This information is cached
520 because profiling CU expansion showed excessive time spent in
521 producer_is_gxx_lt_4_6. */
522 bool checked_producer
: 1;
523 bool producer_is_gxx_lt_4_6
: 1;
524 bool producer_is_gcc_lt_4_3
: 1;
525 bool producer_is_icc
: 1;
526 bool producer_is_icc_lt_14
: 1;
527 bool producer_is_codewarrior
: 1;
529 /* When true, the file that we're processing is known to have
530 debugging info for C++ namespaces. GCC 3.3.x did not produce
531 this information, but later versions do. */
533 bool processing_has_namespace_info
: 1;
535 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
537 /* If this CU was inherited by another CU (via specification,
538 abstract_origin, etc), this is the ancestor CU. */
541 /* Get the buildsym_compunit for this CU. */
542 buildsym_compunit
*get_builder ()
544 /* If this CU has a builder associated with it, use that. */
545 if (m_builder
!= nullptr)
546 return m_builder
.get ();
548 /* Otherwise, search ancestors for a valid builder. */
549 if (ancestor
!= nullptr)
550 return ancestor
->get_builder ();
556 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
557 This includes type_unit_group and quick_file_names. */
559 struct stmt_list_hash
561 /* The DWO unit this table is from or NULL if there is none. */
562 struct dwo_unit
*dwo_unit
;
564 /* Offset in .debug_line or .debug_line.dwo. */
565 sect_offset line_sect_off
;
568 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
569 an object of this type. */
571 struct type_unit_group
573 /* dwarf2read.c's main "handle" on a TU symtab.
574 To simplify things we create an artificial CU that "includes" all the
575 type units using this stmt_list so that the rest of the code still has
576 a "per_cu" handle on the symtab. */
577 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 /* This data structure holds a complete die structure. */
1049 /* DWARF-2 tag for this DIE. */
1050 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1052 /* Number of attributes */
1053 unsigned char num_attrs
;
1055 /* True if we're presently building the full type name for the
1056 type derived from this DIE. */
1057 unsigned char building_fullname
: 1;
1059 /* True if this die is in process. PR 16581. */
1060 unsigned char in_process
: 1;
1062 /* True if this DIE has children. */
1063 unsigned char has_children
: 1;
1066 unsigned int abbrev
;
1068 /* Offset in .debug_info or .debug_types section. */
1069 sect_offset sect_off
;
1071 /* The dies in a compilation unit form an n-ary tree. PARENT
1072 points to this die's parent; CHILD points to the first child of
1073 this node; and all the children of a given node are chained
1074 together via their SIBLING fields. */
1075 struct die_info
*child
; /* Its first child, if any. */
1076 struct die_info
*sibling
; /* Its next sibling, if any. */
1077 struct die_info
*parent
; /* Its parent, if any. */
1079 /* An array of attributes, with NUM_ATTRS elements. There may be
1080 zero, but it's not common and zero-sized arrays are not
1081 sufficiently portable C. */
1082 struct attribute attrs
[1];
1085 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1086 but this would require a corresponding change in unpack_field_as_long
1088 static int bits_per_byte
= 8;
1090 /* When reading a variant or variant part, we track a bit more
1091 information about the field, and store it in an object of this
1094 struct variant_field
1096 /* If we see a DW_TAG_variant, then this will be the discriminant
1098 ULONGEST discriminant_value
;
1099 /* If we see a DW_TAG_variant, then this will be set if this is the
1101 bool default_branch
;
1102 /* While reading a DW_TAG_variant_part, this will be set if this
1103 field is the discriminant. */
1104 bool is_discriminant
;
1109 int accessibility
= 0;
1111 /* Extra information to describe a variant or variant part. */
1112 struct variant_field variant
{};
1113 struct field field
{};
1118 const char *name
= nullptr;
1119 std::vector
<struct fn_field
> fnfields
;
1122 /* The routines that read and process dies for a C struct or C++ class
1123 pass lists of data member fields and lists of member function fields
1124 in an instance of a field_info structure, as defined below. */
1127 /* List of data member and baseclasses fields. */
1128 std::vector
<struct nextfield
> fields
;
1129 std::vector
<struct nextfield
> baseclasses
;
1131 /* Number of fields (including baseclasses). */
1134 /* Set if the accessibility of one of the fields is not public. */
1135 int non_public_fields
= 0;
1137 /* Member function fieldlist array, contains name of possibly overloaded
1138 member function, number of overloaded member functions and a pointer
1139 to the head of the member function field chain. */
1140 std::vector
<struct fnfieldlist
> fnfieldlists
;
1142 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1143 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1144 std::vector
<struct decl_field
> typedef_field_list
;
1146 /* Nested types defined by this class and the number of elements in this
1148 std::vector
<struct decl_field
> nested_types_list
;
1151 /* Loaded secondary compilation units are kept in memory until they
1152 have not been referenced for the processing of this many
1153 compilation units. Set this to zero to disable caching. Cache
1154 sizes of up to at least twenty will improve startup time for
1155 typical inter-CU-reference binaries, at an obvious memory cost. */
1156 static int dwarf_max_cache_age
= 5;
1158 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1159 struct cmd_list_element
*c
, const char *value
)
1161 fprintf_filtered (file
, _("The upper bound on the age of cached "
1162 "DWARF compilation units is %s.\n"),
1166 /* local function prototypes */
1168 static void dwarf2_find_base_address (struct die_info
*die
,
1169 struct dwarf2_cu
*cu
);
1171 static dwarf2_psymtab
*create_partial_symtab
1172 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1174 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1175 const gdb_byte
*info_ptr
,
1176 struct die_info
*type_unit_die
);
1178 static void dwarf2_build_psymtabs_hard
1179 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1181 static void scan_partial_symbols (struct partial_die_info
*,
1182 CORE_ADDR
*, CORE_ADDR
*,
1183 int, struct dwarf2_cu
*);
1185 static void add_partial_symbol (struct partial_die_info
*,
1186 struct dwarf2_cu
*);
1188 static void add_partial_namespace (struct partial_die_info
*pdi
,
1189 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1190 int set_addrmap
, struct dwarf2_cu
*cu
);
1192 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1193 CORE_ADDR
*highpc
, int set_addrmap
,
1194 struct dwarf2_cu
*cu
);
1196 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1197 struct dwarf2_cu
*cu
);
1199 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1200 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1201 int need_pc
, struct dwarf2_cu
*cu
);
1203 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1205 static struct partial_die_info
*load_partial_dies
1206 (const struct die_reader_specs
*, const gdb_byte
*, int);
1208 /* A pair of partial_die_info and compilation unit. */
1209 struct cu_partial_die_info
1211 /* The compilation unit of the partial_die_info. */
1212 struct dwarf2_cu
*cu
;
1213 /* A partial_die_info. */
1214 struct partial_die_info
*pdi
;
1216 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1222 cu_partial_die_info () = delete;
1225 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1226 struct dwarf2_cu
*);
1228 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1229 struct attribute
*, struct attr_abbrev
*,
1230 const gdb_byte
*, bool *need_reprocess
);
1232 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1233 struct attribute
*attr
);
1235 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1237 static LONGEST read_checked_initial_length_and_offset
1238 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1239 unsigned int *, unsigned int *);
1241 static sect_offset read_abbrev_offset
1242 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1243 struct dwarf2_section_info
*, sect_offset
);
1245 static const char *read_indirect_string
1246 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1247 const struct comp_unit_head
*, unsigned int *);
1249 static const char *read_indirect_line_string
1250 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1251 const struct comp_unit_head
*, unsigned int *);
1253 static const char *read_indirect_string_at_offset
1254 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1255 LONGEST str_offset
);
1257 static const char *read_indirect_string_from_dwz
1258 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1260 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1264 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1265 ULONGEST str_index
);
1267 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1268 ULONGEST str_index
);
1270 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1272 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1273 struct dwarf2_cu
*);
1275 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1278 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1279 struct dwarf2_cu
*cu
);
1281 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1283 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1284 struct dwarf2_cu
*cu
);
1286 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1288 static struct die_info
*die_specification (struct die_info
*die
,
1289 struct dwarf2_cu
**);
1291 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1292 struct dwarf2_cu
*cu
);
1294 static void dwarf_decode_lines (struct line_header
*, const char *,
1295 struct dwarf2_cu
*, dwarf2_psymtab
*,
1296 CORE_ADDR
, int decode_mapping
);
1298 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1301 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1302 struct dwarf2_cu
*, struct symbol
* = NULL
);
1304 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1305 struct dwarf2_cu
*);
1307 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1310 struct obstack
*obstack
,
1311 struct dwarf2_cu
*cu
, LONGEST
*value
,
1312 const gdb_byte
**bytes
,
1313 struct dwarf2_locexpr_baton
**baton
);
1315 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1317 static int need_gnat_info (struct dwarf2_cu
*);
1319 static struct type
*die_descriptive_type (struct die_info
*,
1320 struct dwarf2_cu
*);
1322 static void set_descriptive_type (struct type
*, struct die_info
*,
1323 struct dwarf2_cu
*);
1325 static struct type
*die_containing_type (struct die_info
*,
1326 struct dwarf2_cu
*);
1328 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1329 struct dwarf2_cu
*);
1331 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1333 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1335 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1337 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1338 const char *suffix
, int physname
,
1339 struct dwarf2_cu
*cu
);
1341 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1343 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1345 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1347 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1349 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1351 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1353 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1354 struct dwarf2_cu
*, dwarf2_psymtab
*);
1356 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1357 values. Keep the items ordered with increasing constraints compliance. */
1360 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1361 PC_BOUNDS_NOT_PRESENT
,
1363 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1364 were present but they do not form a valid range of PC addresses. */
1367 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1370 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1374 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1375 CORE_ADDR
*, CORE_ADDR
*,
1379 static void get_scope_pc_bounds (struct die_info
*,
1380 CORE_ADDR
*, CORE_ADDR
*,
1381 struct dwarf2_cu
*);
1383 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1384 CORE_ADDR
, struct dwarf2_cu
*);
1386 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1387 struct dwarf2_cu
*);
1389 static void dwarf2_attach_fields_to_type (struct field_info
*,
1390 struct type
*, struct dwarf2_cu
*);
1392 static void dwarf2_add_member_fn (struct field_info
*,
1393 struct die_info
*, struct type
*,
1394 struct dwarf2_cu
*);
1396 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1398 struct dwarf2_cu
*);
1400 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1402 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1404 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1406 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1408 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1410 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1412 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1414 static struct type
*read_module_type (struct die_info
*die
,
1415 struct dwarf2_cu
*cu
);
1417 static const char *namespace_name (struct die_info
*die
,
1418 int *is_anonymous
, struct dwarf2_cu
*);
1420 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1422 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1424 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1425 struct dwarf2_cu
*);
1427 static struct die_info
*read_die_and_siblings_1
1428 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1431 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1432 const gdb_byte
*info_ptr
,
1433 const gdb_byte
**new_info_ptr
,
1434 struct die_info
*parent
);
1436 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1437 struct die_info
**, const gdb_byte
*,
1440 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1441 struct die_info
**, const gdb_byte
*);
1443 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1445 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1448 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1450 static const char *dwarf2_full_name (const char *name
,
1451 struct die_info
*die
,
1452 struct dwarf2_cu
*cu
);
1454 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1455 struct dwarf2_cu
*cu
);
1457 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1458 struct dwarf2_cu
**);
1460 static const char *dwarf_tag_name (unsigned int);
1462 static const char *dwarf_attr_name (unsigned int);
1464 static const char *dwarf_form_name (unsigned int);
1466 static const char *dwarf_bool_name (unsigned int);
1468 static const char *dwarf_type_encoding_name (unsigned int);
1470 static struct die_info
*sibling_die (struct die_info
*);
1472 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1474 static void dump_die_for_error (struct die_info
*);
1476 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1479 /*static*/ void dump_die (struct die_info
*, int max_level
);
1481 static void store_in_ref_table (struct die_info
*,
1482 struct dwarf2_cu
*);
1484 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1486 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1488 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1489 const struct attribute
*,
1490 struct dwarf2_cu
**);
1492 static struct die_info
*follow_die_ref (struct die_info
*,
1493 const struct attribute
*,
1494 struct dwarf2_cu
**);
1496 static struct die_info
*follow_die_sig (struct die_info
*,
1497 const struct attribute
*,
1498 struct dwarf2_cu
**);
1500 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1501 struct dwarf2_cu
*);
1503 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1504 const struct attribute
*,
1505 struct dwarf2_cu
*);
1507 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1509 static void read_signatured_type (struct signatured_type
*);
1511 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1512 struct die_info
*die
, struct dwarf2_cu
*cu
,
1513 struct dynamic_prop
*prop
, struct type
*type
);
1515 /* memory allocation interface */
1517 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1519 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1521 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1523 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1524 struct dwarf2_loclist_baton
*baton
,
1525 const struct attribute
*attr
);
1527 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1529 struct dwarf2_cu
*cu
,
1532 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1533 const gdb_byte
*info_ptr
,
1534 struct abbrev_info
*abbrev
);
1536 static hashval_t
partial_die_hash (const void *item
);
1538 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1540 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1541 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1542 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1544 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1545 struct die_info
*comp_unit_die
,
1546 enum language pretend_language
);
1548 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1550 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1552 static struct type
*set_die_type (struct die_info
*, struct type
*,
1553 struct dwarf2_cu
*);
1555 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1557 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1559 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1562 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1565 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1568 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1569 struct dwarf2_per_cu_data
*);
1571 static void dwarf2_mark (struct dwarf2_cu
*);
1573 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1575 static struct type
*get_die_type_at_offset (sect_offset
,
1576 struct dwarf2_per_cu_data
*);
1578 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1580 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1581 enum language pretend_language
);
1583 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1585 /* Class, the destructor of which frees all allocated queue entries. This
1586 will only have work to do if an error was thrown while processing the
1587 dwarf. If no error was thrown then the queue entries should have all
1588 been processed, and freed, as we went along. */
1590 class dwarf2_queue_guard
1593 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1594 : m_per_objfile (per_objfile
)
1598 /* Free any entries remaining on the queue. There should only be
1599 entries left if we hit an error while processing the dwarf. */
1600 ~dwarf2_queue_guard ()
1602 /* Ensure that no memory is allocated by the queue. */
1603 std::queue
<dwarf2_queue_item
> empty
;
1604 std::swap (m_per_objfile
->queue
, empty
);
1607 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1610 dwarf2_per_objfile
*m_per_objfile
;
1613 dwarf2_queue_item::~dwarf2_queue_item ()
1615 /* Anything still marked queued is likely to be in an
1616 inconsistent state, so discard it. */
1619 if (per_cu
->cu
!= NULL
)
1620 free_one_cached_comp_unit (per_cu
);
1625 /* The return type of find_file_and_directory. Note, the enclosed
1626 string pointers are only valid while this object is valid. */
1628 struct file_and_directory
1630 /* The filename. This is never NULL. */
1633 /* The compilation directory. NULL if not known. If we needed to
1634 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1635 points directly to the DW_AT_comp_dir string attribute owned by
1636 the obstack that owns the DIE. */
1637 const char *comp_dir
;
1639 /* If we needed to build a new string for comp_dir, this is what
1640 owns the storage. */
1641 std::string comp_dir_storage
;
1644 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1645 struct dwarf2_cu
*cu
);
1647 static htab_up
allocate_signatured_type_table ();
1649 static htab_up
allocate_dwo_unit_table ();
1651 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1652 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1653 struct dwp_file
*dwp_file
, const char *comp_dir
,
1654 ULONGEST signature
, int is_debug_types
);
1656 static struct dwp_file
*get_dwp_file
1657 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1659 static struct dwo_unit
*lookup_dwo_comp_unit
1660 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1662 static struct dwo_unit
*lookup_dwo_type_unit
1663 (struct signatured_type
*, const char *, const char *);
1665 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1667 /* A unique pointer to a dwo_file. */
1669 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1671 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1673 static void check_producer (struct dwarf2_cu
*cu
);
1675 static void free_line_header_voidp (void *arg
);
1677 /* Various complaints about symbol reading that don't abort the process. */
1680 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1682 complaint (_("statement list doesn't fit in .debug_line section"));
1686 dwarf2_debug_line_missing_file_complaint (void)
1688 complaint (_(".debug_line section has line data without a file"));
1692 dwarf2_debug_line_missing_end_sequence_complaint (void)
1694 complaint (_(".debug_line section has line "
1695 "program sequence without an end"));
1699 dwarf2_complex_location_expr_complaint (void)
1701 complaint (_("location expression too complex"));
1705 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1708 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1713 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1715 complaint (_("debug info runs off end of %s section"
1717 section
->get_name (),
1718 section
->get_file_name ());
1722 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1724 complaint (_("macro debug info contains a "
1725 "malformed macro definition:\n`%s'"),
1730 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1732 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1736 /* Hash function for line_header_hash. */
1739 line_header_hash (const struct line_header
*ofs
)
1741 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1744 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1747 line_header_hash_voidp (const void *item
)
1749 const struct line_header
*ofs
= (const struct line_header
*) item
;
1751 return line_header_hash (ofs
);
1754 /* Equality function for line_header_hash. */
1757 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1759 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1760 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1762 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1763 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1768 /* See declaration. */
1770 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1771 const dwarf2_debug_sections
*names
,
1773 : objfile (objfile_
),
1774 can_copy (can_copy_
)
1777 names
= &dwarf2_elf_names
;
1779 bfd
*obfd
= objfile
->obfd
;
1781 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1782 locate_sections (obfd
, sec
, *names
);
1785 dwarf2_per_objfile::~dwarf2_per_objfile ()
1787 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1788 free_cached_comp_units ();
1790 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1791 per_cu
->imported_symtabs_free ();
1793 for (signatured_type
*sig_type
: all_type_units
)
1794 sig_type
->per_cu
.imported_symtabs_free ();
1796 /* Everything else should be on the objfile obstack. */
1799 /* See declaration. */
1802 dwarf2_per_objfile::free_cached_comp_units ()
1804 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1805 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1806 while (per_cu
!= NULL
)
1808 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1811 *last_chain
= next_cu
;
1816 /* A helper class that calls free_cached_comp_units on
1819 class free_cached_comp_units
1823 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1824 : m_per_objfile (per_objfile
)
1828 ~free_cached_comp_units ()
1830 m_per_objfile
->free_cached_comp_units ();
1833 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1837 dwarf2_per_objfile
*m_per_objfile
;
1840 /* Try to locate the sections we need for DWARF 2 debugging
1841 information and return true if we have enough to do something.
1842 NAMES points to the dwarf2 section names, or is NULL if the standard
1843 ELF names are used. CAN_COPY is true for formats where symbol
1844 interposition is possible and so symbol values must follow copy
1845 relocation rules. */
1848 dwarf2_has_info (struct objfile
*objfile
,
1849 const struct dwarf2_debug_sections
*names
,
1852 if (objfile
->flags
& OBJF_READNEVER
)
1855 struct dwarf2_per_objfile
*dwarf2_per_objfile
1856 = get_dwarf2_per_objfile (objfile
);
1858 if (dwarf2_per_objfile
== NULL
)
1859 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1863 return (!dwarf2_per_objfile
->info
.is_virtual
1864 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1865 && !dwarf2_per_objfile
->abbrev
.is_virtual
1866 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1869 /* When loading sections, we look either for uncompressed section or for
1870 compressed section names. */
1873 section_is_p (const char *section_name
,
1874 const struct dwarf2_section_names
*names
)
1876 if (names
->normal
!= NULL
1877 && strcmp (section_name
, names
->normal
) == 0)
1879 if (names
->compressed
!= NULL
1880 && strcmp (section_name
, names
->compressed
) == 0)
1885 /* See declaration. */
1888 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1889 const dwarf2_debug_sections
&names
)
1891 flagword aflag
= bfd_section_flags (sectp
);
1893 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1896 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1897 > bfd_get_file_size (abfd
))
1899 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1900 warning (_("Discarding section %s which has a section size (%s"
1901 ") larger than the file size [in module %s]"),
1902 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1903 bfd_get_filename (abfd
));
1905 else if (section_is_p (sectp
->name
, &names
.info
))
1907 this->info
.s
.section
= sectp
;
1908 this->info
.size
= bfd_section_size (sectp
);
1910 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1912 this->abbrev
.s
.section
= sectp
;
1913 this->abbrev
.size
= bfd_section_size (sectp
);
1915 else if (section_is_p (sectp
->name
, &names
.line
))
1917 this->line
.s
.section
= sectp
;
1918 this->line
.size
= bfd_section_size (sectp
);
1920 else if (section_is_p (sectp
->name
, &names
.loc
))
1922 this->loc
.s
.section
= sectp
;
1923 this->loc
.size
= bfd_section_size (sectp
);
1925 else if (section_is_p (sectp
->name
, &names
.loclists
))
1927 this->loclists
.s
.section
= sectp
;
1928 this->loclists
.size
= bfd_section_size (sectp
);
1930 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1932 this->macinfo
.s
.section
= sectp
;
1933 this->macinfo
.size
= bfd_section_size (sectp
);
1935 else if (section_is_p (sectp
->name
, &names
.macro
))
1937 this->macro
.s
.section
= sectp
;
1938 this->macro
.size
= bfd_section_size (sectp
);
1940 else if (section_is_p (sectp
->name
, &names
.str
))
1942 this->str
.s
.section
= sectp
;
1943 this->str
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1947 this->str_offsets
.s
.section
= sectp
;
1948 this->str_offsets
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.line_str
))
1952 this->line_str
.s
.section
= sectp
;
1953 this->line_str
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.addr
))
1957 this->addr
.s
.section
= sectp
;
1958 this->addr
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.frame
))
1962 this->frame
.s
.section
= sectp
;
1963 this->frame
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1967 this->eh_frame
.s
.section
= sectp
;
1968 this->eh_frame
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.ranges
))
1972 this->ranges
.s
.section
= sectp
;
1973 this->ranges
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1977 this->rnglists
.s
.section
= sectp
;
1978 this->rnglists
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.types
))
1982 struct dwarf2_section_info type_section
;
1984 memset (&type_section
, 0, sizeof (type_section
));
1985 type_section
.s
.section
= sectp
;
1986 type_section
.size
= bfd_section_size (sectp
);
1988 this->types
.push_back (type_section
);
1990 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1992 this->gdb_index
.s
.section
= sectp
;
1993 this->gdb_index
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1997 this->debug_names
.s
.section
= sectp
;
1998 this->debug_names
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2002 this->debug_aranges
.s
.section
= sectp
;
2003 this->debug_aranges
.size
= bfd_section_size (sectp
);
2006 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2007 && bfd_section_vma (sectp
) == 0)
2008 this->has_section_at_zero
= true;
2011 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2015 dwarf2_get_section_info (struct objfile
*objfile
,
2016 enum dwarf2_section_enum sect
,
2017 asection
**sectp
, const gdb_byte
**bufp
,
2018 bfd_size_type
*sizep
)
2020 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2021 struct dwarf2_section_info
*info
;
2023 /* We may see an objfile without any DWARF, in which case we just
2034 case DWARF2_DEBUG_FRAME
:
2035 info
= &data
->frame
;
2037 case DWARF2_EH_FRAME
:
2038 info
= &data
->eh_frame
;
2041 gdb_assert_not_reached ("unexpected section");
2044 info
->read (objfile
);
2046 *sectp
= info
->get_bfd_section ();
2047 *bufp
= info
->buffer
;
2048 *sizep
= info
->size
;
2051 /* A helper function to find the sections for a .dwz file. */
2054 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2056 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2058 /* Note that we only support the standard ELF names, because .dwz
2059 is ELF-only (at the time of writing). */
2060 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2062 dwz_file
->abbrev
.s
.section
= sectp
;
2063 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2065 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2067 dwz_file
->info
.s
.section
= sectp
;
2068 dwz_file
->info
.size
= bfd_section_size (sectp
);
2070 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2072 dwz_file
->str
.s
.section
= sectp
;
2073 dwz_file
->str
.size
= bfd_section_size (sectp
);
2075 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2077 dwz_file
->line
.s
.section
= sectp
;
2078 dwz_file
->line
.size
= bfd_section_size (sectp
);
2080 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2082 dwz_file
->macro
.s
.section
= sectp
;
2083 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2085 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2087 dwz_file
->gdb_index
.s
.section
= sectp
;
2088 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2090 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2092 dwz_file
->debug_names
.s
.section
= sectp
;
2093 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2097 /* See dwarf2read.h. */
2100 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2102 const char *filename
;
2103 bfd_size_type buildid_len_arg
;
2107 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2108 return dwarf2_per_objfile
->dwz_file
.get ();
2110 bfd_set_error (bfd_error_no_error
);
2111 gdb::unique_xmalloc_ptr
<char> data
2112 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2113 &buildid_len_arg
, &buildid
));
2116 if (bfd_get_error () == bfd_error_no_error
)
2118 error (_("could not read '.gnu_debugaltlink' section: %s"),
2119 bfd_errmsg (bfd_get_error ()));
2122 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2124 buildid_len
= (size_t) buildid_len_arg
;
2126 filename
= data
.get ();
2128 std::string abs_storage
;
2129 if (!IS_ABSOLUTE_PATH (filename
))
2131 gdb::unique_xmalloc_ptr
<char> abs
2132 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2134 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2135 filename
= abs_storage
.c_str ();
2138 /* First try the file name given in the section. If that doesn't
2139 work, try to use the build-id instead. */
2140 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2141 if (dwz_bfd
!= NULL
)
2143 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2144 dwz_bfd
.reset (nullptr);
2147 if (dwz_bfd
== NULL
)
2148 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2150 if (dwz_bfd
== NULL
)
2151 error (_("could not find '.gnu_debugaltlink' file for %s"),
2152 objfile_name (dwarf2_per_objfile
->objfile
));
2154 std::unique_ptr
<struct dwz_file
> result
2155 (new struct dwz_file (std::move (dwz_bfd
)));
2157 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2160 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2161 result
->dwz_bfd
.get ());
2162 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2163 return dwarf2_per_objfile
->dwz_file
.get ();
2166 /* DWARF quick_symbols_functions support. */
2168 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2169 unique line tables, so we maintain a separate table of all .debug_line
2170 derived entries to support the sharing.
2171 All the quick functions need is the list of file names. We discard the
2172 line_header when we're done and don't need to record it here. */
2173 struct quick_file_names
2175 /* The data used to construct the hash key. */
2176 struct stmt_list_hash hash
;
2178 /* The number of entries in file_names, real_names. */
2179 unsigned int num_file_names
;
2181 /* The file names from the line table, after being run through
2183 const char **file_names
;
2185 /* The file names from the line table after being run through
2186 gdb_realpath. These are computed lazily. */
2187 const char **real_names
;
2190 /* When using the index (and thus not using psymtabs), each CU has an
2191 object of this type. This is used to hold information needed by
2192 the various "quick" methods. */
2193 struct dwarf2_per_cu_quick_data
2195 /* The file table. This can be NULL if there was no file table
2196 or it's currently not read in.
2197 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2198 struct quick_file_names
*file_names
;
2200 /* The corresponding symbol table. This is NULL if symbols for this
2201 CU have not yet been read. */
2202 struct compunit_symtab
*compunit_symtab
;
2204 /* A temporary mark bit used when iterating over all CUs in
2205 expand_symtabs_matching. */
2206 unsigned int mark
: 1;
2208 /* True if we've tried to read the file table and found there isn't one.
2209 There will be no point in trying to read it again next time. */
2210 unsigned int no_file_data
: 1;
2213 /* Utility hash function for a stmt_list_hash. */
2216 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2220 if (stmt_list_hash
->dwo_unit
!= NULL
)
2221 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2222 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2226 /* Utility equality function for a stmt_list_hash. */
2229 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2230 const struct stmt_list_hash
*rhs
)
2232 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2234 if (lhs
->dwo_unit
!= NULL
2235 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2238 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2241 /* Hash function for a quick_file_names. */
2244 hash_file_name_entry (const void *e
)
2246 const struct quick_file_names
*file_data
2247 = (const struct quick_file_names
*) e
;
2249 return hash_stmt_list_entry (&file_data
->hash
);
2252 /* Equality function for a quick_file_names. */
2255 eq_file_name_entry (const void *a
, const void *b
)
2257 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2258 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2260 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2263 /* Delete function for a quick_file_names. */
2266 delete_file_name_entry (void *e
)
2268 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2271 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2273 xfree ((void*) file_data
->file_names
[i
]);
2274 if (file_data
->real_names
)
2275 xfree ((void*) file_data
->real_names
[i
]);
2278 /* The space for the struct itself lives on objfile_obstack,
2279 so we don't free it here. */
2282 /* Create a quick_file_names hash table. */
2285 create_quick_file_names_table (unsigned int nr_initial_entries
)
2287 return htab_up (htab_create_alloc (nr_initial_entries
,
2288 hash_file_name_entry
, eq_file_name_entry
,
2289 delete_file_name_entry
, xcalloc
, xfree
));
2292 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2293 have to be created afterwards. You should call age_cached_comp_units after
2294 processing PER_CU->CU. dw2_setup must have been already called. */
2297 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2299 if (per_cu
->is_debug_types
)
2300 load_full_type_unit (per_cu
);
2302 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2304 if (per_cu
->cu
== NULL
)
2305 return; /* Dummy CU. */
2307 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2310 /* Read in the symbols for PER_CU. */
2313 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2315 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2317 /* Skip type_unit_groups, reading the type units they contain
2318 is handled elsewhere. */
2319 if (per_cu
->type_unit_group_p ())
2322 /* The destructor of dwarf2_queue_guard frees any entries left on
2323 the queue. After this point we're guaranteed to leave this function
2324 with the dwarf queue empty. */
2325 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2327 if (dwarf2_per_objfile
->using_index
2328 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2329 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2331 queue_comp_unit (per_cu
, language_minimal
);
2332 load_cu (per_cu
, skip_partial
);
2334 /* If we just loaded a CU from a DWO, and we're working with an index
2335 that may badly handle TUs, load all the TUs in that DWO as well.
2336 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2337 if (!per_cu
->is_debug_types
2338 && per_cu
->cu
!= NULL
2339 && per_cu
->cu
->dwo_unit
!= NULL
2340 && dwarf2_per_objfile
->index_table
!= NULL
2341 && dwarf2_per_objfile
->index_table
->version
<= 7
2342 /* DWP files aren't supported yet. */
2343 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2344 queue_and_load_all_dwo_tus (per_cu
);
2347 process_queue (dwarf2_per_objfile
);
2349 /* Age the cache, releasing compilation units that have not
2350 been used recently. */
2351 age_cached_comp_units (dwarf2_per_objfile
);
2354 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2355 the objfile from which this CU came. Returns the resulting symbol
2358 static struct compunit_symtab
*
2359 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2361 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2363 gdb_assert (dwarf2_per_objfile
->using_index
);
2364 if (!per_cu
->v
.quick
->compunit_symtab
)
2366 free_cached_comp_units
freer (dwarf2_per_objfile
);
2367 scoped_restore decrementer
= increment_reading_symtab ();
2368 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2369 process_cu_includes (dwarf2_per_objfile
);
2372 return per_cu
->v
.quick
->compunit_symtab
;
2375 /* See declaration. */
2377 dwarf2_per_cu_data
*
2378 dwarf2_per_objfile::get_cutu (int index
)
2380 if (index
>= this->all_comp_units
.size ())
2382 index
-= this->all_comp_units
.size ();
2383 gdb_assert (index
< this->all_type_units
.size ());
2384 return &this->all_type_units
[index
]->per_cu
;
2387 return this->all_comp_units
[index
];
2390 /* See declaration. */
2392 dwarf2_per_cu_data
*
2393 dwarf2_per_objfile::get_cu (int index
)
2395 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2397 return this->all_comp_units
[index
];
2400 /* See declaration. */
2403 dwarf2_per_objfile::get_tu (int index
)
2405 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2407 return this->all_type_units
[index
];
2410 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2411 objfile_obstack, and constructed with the specified field
2414 static dwarf2_per_cu_data
*
2415 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2416 struct dwarf2_section_info
*section
,
2418 sect_offset sect_off
, ULONGEST length
)
2420 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2421 dwarf2_per_cu_data
*the_cu
2422 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2423 struct dwarf2_per_cu_data
);
2424 the_cu
->sect_off
= sect_off
;
2425 the_cu
->length
= length
;
2426 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2427 the_cu
->section
= section
;
2428 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2429 struct dwarf2_per_cu_quick_data
);
2430 the_cu
->is_dwz
= is_dwz
;
2434 /* A helper for create_cus_from_index that handles a given list of
2438 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2439 const gdb_byte
*cu_list
, offset_type n_elements
,
2440 struct dwarf2_section_info
*section
,
2443 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2445 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2447 sect_offset sect_off
2448 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2449 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2452 dwarf2_per_cu_data
*per_cu
2453 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2455 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2459 /* Read the CU list from the mapped index, and use it to create all
2460 the CU objects for this objfile. */
2463 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2464 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2465 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2467 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2468 dwarf2_per_objfile
->all_comp_units
.reserve
2469 ((cu_list_elements
+ dwz_elements
) / 2);
2471 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2472 &dwarf2_per_objfile
->info
, 0);
2474 if (dwz_elements
== 0)
2477 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2478 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2482 /* Create the signatured type hash table from the index. */
2485 create_signatured_type_table_from_index
2486 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2487 struct dwarf2_section_info
*section
,
2488 const gdb_byte
*bytes
,
2489 offset_type elements
)
2491 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2493 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2494 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2496 htab_up sig_types_hash
= allocate_signatured_type_table ();
2498 for (offset_type i
= 0; i
< elements
; i
+= 3)
2500 struct signatured_type
*sig_type
;
2503 cu_offset type_offset_in_tu
;
2505 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2506 sect_offset sect_off
2507 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2509 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2511 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2514 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2515 struct signatured_type
);
2516 sig_type
->signature
= signature
;
2517 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2518 sig_type
->per_cu
.is_debug_types
= 1;
2519 sig_type
->per_cu
.section
= section
;
2520 sig_type
->per_cu
.sect_off
= sect_off
;
2521 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2522 sig_type
->per_cu
.v
.quick
2523 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2524 struct dwarf2_per_cu_quick_data
);
2526 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2529 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2532 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2535 /* Create the signatured type hash table from .debug_names. */
2538 create_signatured_type_table_from_debug_names
2539 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2540 const mapped_debug_names
&map
,
2541 struct dwarf2_section_info
*section
,
2542 struct dwarf2_section_info
*abbrev_section
)
2544 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2546 section
->read (objfile
);
2547 abbrev_section
->read (objfile
);
2549 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2550 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2552 htab_up sig_types_hash
= allocate_signatured_type_table ();
2554 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2556 struct signatured_type
*sig_type
;
2559 sect_offset sect_off
2560 = (sect_offset
) (extract_unsigned_integer
2561 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2563 map
.dwarf5_byte_order
));
2565 comp_unit_head cu_header
;
2566 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2568 section
->buffer
+ to_underlying (sect_off
),
2571 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2572 struct signatured_type
);
2573 sig_type
->signature
= cu_header
.signature
;
2574 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2575 sig_type
->per_cu
.is_debug_types
= 1;
2576 sig_type
->per_cu
.section
= section
;
2577 sig_type
->per_cu
.sect_off
= sect_off
;
2578 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2579 sig_type
->per_cu
.v
.quick
2580 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2581 struct dwarf2_per_cu_quick_data
);
2583 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2586 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2589 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2592 /* Read the address map data from the mapped index, and use it to
2593 populate the objfile's psymtabs_addrmap. */
2596 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2597 struct mapped_index
*index
)
2599 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2600 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2601 const gdb_byte
*iter
, *end
;
2602 struct addrmap
*mutable_map
;
2605 auto_obstack temp_obstack
;
2607 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2609 iter
= index
->address_table
.data ();
2610 end
= iter
+ index
->address_table
.size ();
2612 baseaddr
= objfile
->text_section_offset ();
2616 ULONGEST hi
, lo
, cu_index
;
2617 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2619 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2621 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2626 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2627 hex_string (lo
), hex_string (hi
));
2631 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2633 complaint (_(".gdb_index address table has invalid CU number %u"),
2634 (unsigned) cu_index
);
2638 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2639 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2640 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2641 dwarf2_per_objfile
->get_cu (cu_index
));
2644 objfile
->partial_symtabs
->psymtabs_addrmap
2645 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2648 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2649 populate the objfile's psymtabs_addrmap. */
2652 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2653 struct dwarf2_section_info
*section
)
2655 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2656 bfd
*abfd
= objfile
->obfd
;
2657 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2658 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2660 auto_obstack temp_obstack
;
2661 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2663 std::unordered_map
<sect_offset
,
2664 dwarf2_per_cu_data
*,
2665 gdb::hash_enum
<sect_offset
>>
2666 debug_info_offset_to_per_cu
;
2667 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2669 const auto insertpair
2670 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2671 if (!insertpair
.second
)
2673 warning (_("Section .debug_aranges in %s has duplicate "
2674 "debug_info_offset %s, ignoring .debug_aranges."),
2675 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2680 section
->read (objfile
);
2682 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2684 const gdb_byte
*addr
= section
->buffer
;
2686 while (addr
< section
->buffer
+ section
->size
)
2688 const gdb_byte
*const entry_addr
= addr
;
2689 unsigned int bytes_read
;
2691 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2695 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2696 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2697 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2698 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2700 warning (_("Section .debug_aranges in %s entry at offset %s "
2701 "length %s exceeds section length %s, "
2702 "ignoring .debug_aranges."),
2703 objfile_name (objfile
),
2704 plongest (entry_addr
- section
->buffer
),
2705 plongest (bytes_read
+ entry_length
),
2706 pulongest (section
->size
));
2710 /* The version number. */
2711 const uint16_t version
= read_2_bytes (abfd
, addr
);
2715 warning (_("Section .debug_aranges in %s entry at offset %s "
2716 "has unsupported version %d, ignoring .debug_aranges."),
2717 objfile_name (objfile
),
2718 plongest (entry_addr
- section
->buffer
), version
);
2722 const uint64_t debug_info_offset
2723 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2724 addr
+= offset_size
;
2725 const auto per_cu_it
2726 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2727 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2729 warning (_("Section .debug_aranges in %s entry at offset %s "
2730 "debug_info_offset %s does not exists, "
2731 "ignoring .debug_aranges."),
2732 objfile_name (objfile
),
2733 plongest (entry_addr
- section
->buffer
),
2734 pulongest (debug_info_offset
));
2737 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2739 const uint8_t address_size
= *addr
++;
2740 if (address_size
< 1 || address_size
> 8)
2742 warning (_("Section .debug_aranges in %s entry at offset %s "
2743 "address_size %u is invalid, ignoring .debug_aranges."),
2744 objfile_name (objfile
),
2745 plongest (entry_addr
- section
->buffer
), address_size
);
2749 const uint8_t segment_selector_size
= *addr
++;
2750 if (segment_selector_size
!= 0)
2752 warning (_("Section .debug_aranges in %s entry at offset %s "
2753 "segment_selector_size %u is not supported, "
2754 "ignoring .debug_aranges."),
2755 objfile_name (objfile
),
2756 plongest (entry_addr
- section
->buffer
),
2757 segment_selector_size
);
2761 /* Must pad to an alignment boundary that is twice the address
2762 size. It is undocumented by the DWARF standard but GCC does
2764 for (size_t padding
= ((-(addr
- section
->buffer
))
2765 & (2 * address_size
- 1));
2766 padding
> 0; padding
--)
2769 warning (_("Section .debug_aranges in %s entry at offset %s "
2770 "padding is not zero, ignoring .debug_aranges."),
2771 objfile_name (objfile
),
2772 plongest (entry_addr
- section
->buffer
));
2778 if (addr
+ 2 * address_size
> entry_end
)
2780 warning (_("Section .debug_aranges in %s entry at offset %s "
2781 "address list is not properly terminated, "
2782 "ignoring .debug_aranges."),
2783 objfile_name (objfile
),
2784 plongest (entry_addr
- section
->buffer
));
2787 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2789 addr
+= address_size
;
2790 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2792 addr
+= address_size
;
2793 if (start
== 0 && length
== 0)
2795 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2797 /* Symbol was eliminated due to a COMDAT group. */
2800 ULONGEST end
= start
+ length
;
2801 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2803 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2805 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2809 objfile
->partial_symtabs
->psymtabs_addrmap
2810 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2813 /* Find a slot in the mapped index INDEX for the object named NAME.
2814 If NAME is found, set *VEC_OUT to point to the CU vector in the
2815 constant pool and return true. If NAME cannot be found, return
2819 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2820 offset_type
**vec_out
)
2823 offset_type slot
, step
;
2824 int (*cmp
) (const char *, const char *);
2826 gdb::unique_xmalloc_ptr
<char> without_params
;
2827 if (current_language
->la_language
== language_cplus
2828 || current_language
->la_language
== language_fortran
2829 || current_language
->la_language
== language_d
)
2831 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2834 if (strchr (name
, '(') != NULL
)
2836 without_params
= cp_remove_params (name
);
2838 if (without_params
!= NULL
)
2839 name
= without_params
.get ();
2843 /* Index version 4 did not support case insensitive searches. But the
2844 indices for case insensitive languages are built in lowercase, therefore
2845 simulate our NAME being searched is also lowercased. */
2846 hash
= mapped_index_string_hash ((index
->version
== 4
2847 && case_sensitivity
== case_sensitive_off
2848 ? 5 : index
->version
),
2851 slot
= hash
& (index
->symbol_table
.size () - 1);
2852 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2853 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2859 const auto &bucket
= index
->symbol_table
[slot
];
2860 if (bucket
.name
== 0 && bucket
.vec
== 0)
2863 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2864 if (!cmp (name
, str
))
2866 *vec_out
= (offset_type
*) (index
->constant_pool
2867 + MAYBE_SWAP (bucket
.vec
));
2871 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2875 /* A helper function that reads the .gdb_index from BUFFER and fills
2876 in MAP. FILENAME is the name of the file containing the data;
2877 it is used for error reporting. DEPRECATED_OK is true if it is
2878 ok to use deprecated sections.
2880 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2881 out parameters that are filled in with information about the CU and
2882 TU lists in the section.
2884 Returns true if all went well, false otherwise. */
2887 read_gdb_index_from_buffer (struct objfile
*objfile
,
2888 const char *filename
,
2890 gdb::array_view
<const gdb_byte
> buffer
,
2891 struct mapped_index
*map
,
2892 const gdb_byte
**cu_list
,
2893 offset_type
*cu_list_elements
,
2894 const gdb_byte
**types_list
,
2895 offset_type
*types_list_elements
)
2897 const gdb_byte
*addr
= &buffer
[0];
2899 /* Version check. */
2900 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2901 /* Versions earlier than 3 emitted every copy of a psymbol. This
2902 causes the index to behave very poorly for certain requests. Version 3
2903 contained incomplete addrmap. So, it seems better to just ignore such
2907 static int warning_printed
= 0;
2908 if (!warning_printed
)
2910 warning (_("Skipping obsolete .gdb_index section in %s."),
2912 warning_printed
= 1;
2916 /* Index version 4 uses a different hash function than index version
2919 Versions earlier than 6 did not emit psymbols for inlined
2920 functions. Using these files will cause GDB not to be able to
2921 set breakpoints on inlined functions by name, so we ignore these
2922 indices unless the user has done
2923 "set use-deprecated-index-sections on". */
2924 if (version
< 6 && !deprecated_ok
)
2926 static int warning_printed
= 0;
2927 if (!warning_printed
)
2930 Skipping deprecated .gdb_index section in %s.\n\
2931 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2932 to use the section anyway."),
2934 warning_printed
= 1;
2938 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2939 of the TU (for symbols coming from TUs),
2940 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2941 Plus gold-generated indices can have duplicate entries for global symbols,
2942 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2943 These are just performance bugs, and we can't distinguish gdb-generated
2944 indices from gold-generated ones, so issue no warning here. */
2946 /* Indexes with higher version than the one supported by GDB may be no
2947 longer backward compatible. */
2951 map
->version
= version
;
2953 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2956 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2957 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2961 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2962 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2963 - MAYBE_SWAP (metadata
[i
]))
2967 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2968 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2970 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2973 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2974 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2976 = gdb::array_view
<mapped_index::symbol_table_slot
>
2977 ((mapped_index::symbol_table_slot
*) symbol_table
,
2978 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2981 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2986 /* Callback types for dwarf2_read_gdb_index. */
2988 typedef gdb::function_view
2989 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2990 get_gdb_index_contents_ftype
;
2991 typedef gdb::function_view
2992 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2993 get_gdb_index_contents_dwz_ftype
;
2995 /* Read .gdb_index. If everything went ok, initialize the "quick"
2996 elements of all the CUs and return 1. Otherwise, return 0. */
2999 dwarf2_read_gdb_index
3000 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3001 get_gdb_index_contents_ftype get_gdb_index_contents
,
3002 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3004 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3005 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3006 struct dwz_file
*dwz
;
3007 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3009 gdb::array_view
<const gdb_byte
> main_index_contents
3010 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3012 if (main_index_contents
.empty ())
3015 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3016 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3017 use_deprecated_index_sections
,
3018 main_index_contents
, map
.get (), &cu_list
,
3019 &cu_list_elements
, &types_list
,
3020 &types_list_elements
))
3023 /* Don't use the index if it's empty. */
3024 if (map
->symbol_table
.empty ())
3027 /* If there is a .dwz file, read it so we can get its CU list as
3029 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3032 struct mapped_index dwz_map
;
3033 const gdb_byte
*dwz_types_ignore
;
3034 offset_type dwz_types_elements_ignore
;
3036 gdb::array_view
<const gdb_byte
> dwz_index_content
3037 = get_gdb_index_contents_dwz (objfile
, dwz
);
3039 if (dwz_index_content
.empty ())
3042 if (!read_gdb_index_from_buffer (objfile
,
3043 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3044 1, dwz_index_content
, &dwz_map
,
3045 &dwz_list
, &dwz_list_elements
,
3047 &dwz_types_elements_ignore
))
3049 warning (_("could not read '.gdb_index' section from %s; skipping"),
3050 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3055 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3056 dwz_list
, dwz_list_elements
);
3058 if (types_list_elements
)
3060 /* We can only handle a single .debug_types when we have an
3062 if (dwarf2_per_objfile
->types
.size () != 1)
3065 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3067 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3068 types_list
, types_list_elements
);
3071 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3073 dwarf2_per_objfile
->index_table
= std::move (map
);
3074 dwarf2_per_objfile
->using_index
= 1;
3075 dwarf2_per_objfile
->quick_file_names_table
=
3076 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3081 /* die_reader_func for dw2_get_file_names. */
3084 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3085 const gdb_byte
*info_ptr
,
3086 struct die_info
*comp_unit_die
)
3088 struct dwarf2_cu
*cu
= reader
->cu
;
3089 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3090 struct dwarf2_per_objfile
*dwarf2_per_objfile
3091 = cu
->per_cu
->dwarf2_per_objfile
;
3092 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3093 struct dwarf2_per_cu_data
*lh_cu
;
3094 struct attribute
*attr
;
3096 struct quick_file_names
*qfn
;
3098 gdb_assert (! this_cu
->is_debug_types
);
3100 /* Our callers never want to match partial units -- instead they
3101 will match the enclosing full CU. */
3102 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3104 this_cu
->v
.quick
->no_file_data
= 1;
3112 sect_offset line_offset
{};
3114 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3115 if (attr
!= nullptr)
3117 struct quick_file_names find_entry
;
3119 line_offset
= (sect_offset
) DW_UNSND (attr
);
3121 /* We may have already read in this line header (TU line header sharing).
3122 If we have we're done. */
3123 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3124 find_entry
.hash
.line_sect_off
= line_offset
;
3125 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3126 &find_entry
, INSERT
);
3129 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3133 lh
= dwarf_decode_line_header (line_offset
, cu
);
3137 lh_cu
->v
.quick
->no_file_data
= 1;
3141 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3142 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3143 qfn
->hash
.line_sect_off
= line_offset
;
3144 gdb_assert (slot
!= NULL
);
3147 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3150 if (strcmp (fnd
.name
, "<unknown>") != 0)
3153 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3155 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3157 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3158 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3159 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3160 fnd
.comp_dir
).release ();
3161 qfn
->real_names
= NULL
;
3163 lh_cu
->v
.quick
->file_names
= qfn
;
3166 /* A helper for the "quick" functions which attempts to read the line
3167 table for THIS_CU. */
3169 static struct quick_file_names
*
3170 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3172 /* This should never be called for TUs. */
3173 gdb_assert (! this_cu
->is_debug_types
);
3174 /* Nor type unit groups. */
3175 gdb_assert (! this_cu
->type_unit_group_p ());
3177 if (this_cu
->v
.quick
->file_names
!= NULL
)
3178 return this_cu
->v
.quick
->file_names
;
3179 /* If we know there is no line data, no point in looking again. */
3180 if (this_cu
->v
.quick
->no_file_data
)
3183 cutu_reader
reader (this_cu
);
3184 if (!reader
.dummy_p
)
3185 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3187 if (this_cu
->v
.quick
->no_file_data
)
3189 return this_cu
->v
.quick
->file_names
;
3192 /* A helper for the "quick" functions which computes and caches the
3193 real path for a given file name from the line table. */
3196 dw2_get_real_path (struct objfile
*objfile
,
3197 struct quick_file_names
*qfn
, int index
)
3199 if (qfn
->real_names
== NULL
)
3200 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3201 qfn
->num_file_names
, const char *);
3203 if (qfn
->real_names
[index
] == NULL
)
3204 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3206 return qfn
->real_names
[index
];
3209 static struct symtab
*
3210 dw2_find_last_source_symtab (struct objfile
*objfile
)
3212 struct dwarf2_per_objfile
*dwarf2_per_objfile
3213 = get_dwarf2_per_objfile (objfile
);
3214 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3215 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3220 return compunit_primary_filetab (cust
);
3223 /* Traversal function for dw2_forget_cached_source_info. */
3226 dw2_free_cached_file_names (void **slot
, void *info
)
3228 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3230 if (file_data
->real_names
)
3234 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3236 xfree ((void*) file_data
->real_names
[i
]);
3237 file_data
->real_names
[i
] = NULL
;
3245 dw2_forget_cached_source_info (struct objfile
*objfile
)
3247 struct dwarf2_per_objfile
*dwarf2_per_objfile
3248 = get_dwarf2_per_objfile (objfile
);
3250 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3251 dw2_free_cached_file_names
, NULL
);
3254 /* Helper function for dw2_map_symtabs_matching_filename that expands
3255 the symtabs and calls the iterator. */
3258 dw2_map_expand_apply (struct objfile
*objfile
,
3259 struct dwarf2_per_cu_data
*per_cu
,
3260 const char *name
, const char *real_path
,
3261 gdb::function_view
<bool (symtab
*)> callback
)
3263 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3265 /* Don't visit already-expanded CUs. */
3266 if (per_cu
->v
.quick
->compunit_symtab
)
3269 /* This may expand more than one symtab, and we want to iterate over
3271 dw2_instantiate_symtab (per_cu
, false);
3273 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3274 last_made
, callback
);
3277 /* Implementation of the map_symtabs_matching_filename method. */
3280 dw2_map_symtabs_matching_filename
3281 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3282 gdb::function_view
<bool (symtab
*)> callback
)
3284 const char *name_basename
= lbasename (name
);
3285 struct dwarf2_per_objfile
*dwarf2_per_objfile
3286 = get_dwarf2_per_objfile (objfile
);
3288 /* The rule is CUs specify all the files, including those used by
3289 any TU, so there's no need to scan TUs here. */
3291 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3293 /* We only need to look at symtabs not already expanded. */
3294 if (per_cu
->v
.quick
->compunit_symtab
)
3297 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3298 if (file_data
== NULL
)
3301 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3303 const char *this_name
= file_data
->file_names
[j
];
3304 const char *this_real_name
;
3306 if (compare_filenames_for_search (this_name
, name
))
3308 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3314 /* Before we invoke realpath, which can get expensive when many
3315 files are involved, do a quick comparison of the basenames. */
3316 if (! basenames_may_differ
3317 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3320 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3321 if (compare_filenames_for_search (this_real_name
, name
))
3323 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3329 if (real_path
!= NULL
)
3331 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3332 gdb_assert (IS_ABSOLUTE_PATH (name
));
3333 if (this_real_name
!= NULL
3334 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3336 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3348 /* Struct used to manage iterating over all CUs looking for a symbol. */
3350 struct dw2_symtab_iterator
3352 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3353 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3354 /* If set, only look for symbols that match that block. Valid values are
3355 GLOBAL_BLOCK and STATIC_BLOCK. */
3356 gdb::optional
<block_enum
> block_index
;
3357 /* The kind of symbol we're looking for. */
3359 /* The list of CUs from the index entry of the symbol,
3360 or NULL if not found. */
3362 /* The next element in VEC to look at. */
3364 /* The number of elements in VEC, or zero if there is no match. */
3366 /* Have we seen a global version of the symbol?
3367 If so we can ignore all further global instances.
3368 This is to work around gold/15646, inefficient gold-generated
3373 /* Initialize the index symtab iterator ITER. */
3376 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3377 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3378 gdb::optional
<block_enum
> block_index
,
3382 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3383 iter
->block_index
= block_index
;
3384 iter
->domain
= domain
;
3386 iter
->global_seen
= 0;
3388 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3390 /* index is NULL if OBJF_READNOW. */
3391 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3392 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3400 /* Return the next matching CU or NULL if there are no more. */
3402 static struct dwarf2_per_cu_data
*
3403 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3405 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3407 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3409 offset_type cu_index_and_attrs
=
3410 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3411 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3412 gdb_index_symbol_kind symbol_kind
=
3413 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3414 /* Only check the symbol attributes if they're present.
3415 Indices prior to version 7 don't record them,
3416 and indices >= 7 may elide them for certain symbols
3417 (gold does this). */
3419 (dwarf2_per_objfile
->index_table
->version
>= 7
3420 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3422 /* Don't crash on bad data. */
3423 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3424 + dwarf2_per_objfile
->all_type_units
.size ()))
3426 complaint (_(".gdb_index entry has bad CU index"
3428 objfile_name (dwarf2_per_objfile
->objfile
));
3432 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3434 /* Skip if already read in. */
3435 if (per_cu
->v
.quick
->compunit_symtab
)
3438 /* Check static vs global. */
3441 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3443 if (iter
->block_index
.has_value ())
3445 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3447 if (is_static
!= want_static
)
3451 /* Work around gold/15646. */
3452 if (!is_static
&& iter
->global_seen
)
3455 iter
->global_seen
= 1;
3458 /* Only check the symbol's kind if it has one. */
3461 switch (iter
->domain
)
3464 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3465 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3466 /* Some types are also in VAR_DOMAIN. */
3467 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3471 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3475 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3479 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3494 static struct compunit_symtab
*
3495 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3496 const char *name
, domain_enum domain
)
3498 struct compunit_symtab
*stab_best
= NULL
;
3499 struct dwarf2_per_objfile
*dwarf2_per_objfile
3500 = get_dwarf2_per_objfile (objfile
);
3502 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3504 struct dw2_symtab_iterator iter
;
3505 struct dwarf2_per_cu_data
*per_cu
;
3507 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3509 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3511 struct symbol
*sym
, *with_opaque
= NULL
;
3512 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3513 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3514 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3516 sym
= block_find_symbol (block
, name
, domain
,
3517 block_find_non_opaque_type_preferred
,
3520 /* Some caution must be observed with overloaded functions
3521 and methods, since the index will not contain any overload
3522 information (but NAME might contain it). */
3525 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3527 if (with_opaque
!= NULL
3528 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3531 /* Keep looking through other CUs. */
3538 dw2_print_stats (struct objfile
*objfile
)
3540 struct dwarf2_per_objfile
*dwarf2_per_objfile
3541 = get_dwarf2_per_objfile (objfile
);
3542 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3543 + dwarf2_per_objfile
->all_type_units
.size ());
3546 for (int i
= 0; i
< total
; ++i
)
3548 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3550 if (!per_cu
->v
.quick
->compunit_symtab
)
3553 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3554 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3557 /* This dumps minimal information about the index.
3558 It is called via "mt print objfiles".
3559 One use is to verify .gdb_index has been loaded by the
3560 gdb.dwarf2/gdb-index.exp testcase. */
3563 dw2_dump (struct objfile
*objfile
)
3565 struct dwarf2_per_objfile
*dwarf2_per_objfile
3566 = get_dwarf2_per_objfile (objfile
);
3568 gdb_assert (dwarf2_per_objfile
->using_index
);
3569 printf_filtered (".gdb_index:");
3570 if (dwarf2_per_objfile
->index_table
!= NULL
)
3572 printf_filtered (" version %d\n",
3573 dwarf2_per_objfile
->index_table
->version
);
3576 printf_filtered (" faked for \"readnow\"\n");
3577 printf_filtered ("\n");
3581 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3582 const char *func_name
)
3584 struct dwarf2_per_objfile
*dwarf2_per_objfile
3585 = get_dwarf2_per_objfile (objfile
);
3587 struct dw2_symtab_iterator iter
;
3588 struct dwarf2_per_cu_data
*per_cu
;
3590 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3592 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3593 dw2_instantiate_symtab (per_cu
, false);
3598 dw2_expand_all_symtabs (struct objfile
*objfile
)
3600 struct dwarf2_per_objfile
*dwarf2_per_objfile
3601 = get_dwarf2_per_objfile (objfile
);
3602 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3603 + dwarf2_per_objfile
->all_type_units
.size ());
3605 for (int i
= 0; i
< total_units
; ++i
)
3607 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3609 /* We don't want to directly expand a partial CU, because if we
3610 read it with the wrong language, then assertion failures can
3611 be triggered later on. See PR symtab/23010. So, tell
3612 dw2_instantiate_symtab to skip partial CUs -- any important
3613 partial CU will be read via DW_TAG_imported_unit anyway. */
3614 dw2_instantiate_symtab (per_cu
, true);
3619 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3620 const char *fullname
)
3622 struct dwarf2_per_objfile
*dwarf2_per_objfile
3623 = get_dwarf2_per_objfile (objfile
);
3625 /* We don't need to consider type units here.
3626 This is only called for examining code, e.g. expand_line_sal.
3627 There can be an order of magnitude (or more) more type units
3628 than comp units, and we avoid them if we can. */
3630 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3632 /* We only need to look at symtabs not already expanded. */
3633 if (per_cu
->v
.quick
->compunit_symtab
)
3636 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3637 if (file_data
== NULL
)
3640 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3642 const char *this_fullname
= file_data
->file_names
[j
];
3644 if (filename_cmp (this_fullname
, fullname
) == 0)
3646 dw2_instantiate_symtab (per_cu
, false);
3654 dw2_map_matching_symbols
3655 (struct objfile
*objfile
,
3656 const lookup_name_info
&name
, domain_enum domain
,
3658 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3659 symbol_compare_ftype
*ordered_compare
)
3661 /* Currently unimplemented; used for Ada. The function can be called if the
3662 current language is Ada for a non-Ada objfile using GNU index. As Ada
3663 does not look for non-Ada symbols this function should just return. */
3666 /* Starting from a search name, return the string that finds the upper
3667 bound of all strings that start with SEARCH_NAME in a sorted name
3668 list. Returns the empty string to indicate that the upper bound is
3669 the end of the list. */
3672 make_sort_after_prefix_name (const char *search_name
)
3674 /* When looking to complete "func", we find the upper bound of all
3675 symbols that start with "func" by looking for where we'd insert
3676 the closest string that would follow "func" in lexicographical
3677 order. Usually, that's "func"-with-last-character-incremented,
3678 i.e. "fund". Mind non-ASCII characters, though. Usually those
3679 will be UTF-8 multi-byte sequences, but we can't be certain.
3680 Especially mind the 0xff character, which is a valid character in
3681 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3682 rule out compilers allowing it in identifiers. Note that
3683 conveniently, strcmp/strcasecmp are specified to compare
3684 characters interpreted as unsigned char. So what we do is treat
3685 the whole string as a base 256 number composed of a sequence of
3686 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3687 to 0, and carries 1 to the following more-significant position.
3688 If the very first character in SEARCH_NAME ends up incremented
3689 and carries/overflows, then the upper bound is the end of the
3690 list. The string after the empty string is also the empty
3693 Some examples of this operation:
3695 SEARCH_NAME => "+1" RESULT
3699 "\xff" "a" "\xff" => "\xff" "b"
3704 Then, with these symbols for example:
3710 completing "func" looks for symbols between "func" and
3711 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3712 which finds "func" and "func1", but not "fund".
3716 funcÿ (Latin1 'ÿ' [0xff])
3720 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3721 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3725 ÿÿ (Latin1 'ÿ' [0xff])
3728 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3729 the end of the list.
3731 std::string after
= search_name
;
3732 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3734 if (!after
.empty ())
3735 after
.back () = (unsigned char) after
.back () + 1;
3739 /* See declaration. */
3741 std::pair
<std::vector
<name_component
>::const_iterator
,
3742 std::vector
<name_component
>::const_iterator
>
3743 mapped_index_base::find_name_components_bounds
3744 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3747 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3749 const char *lang_name
3750 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3752 /* Comparison function object for lower_bound that matches against a
3753 given symbol name. */
3754 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3757 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3758 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3759 return name_cmp (elem_name
, name
) < 0;
3762 /* Comparison function object for upper_bound that matches against a
3763 given symbol name. */
3764 auto lookup_compare_upper
= [&] (const char *name
,
3765 const name_component
&elem
)
3767 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3768 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3769 return name_cmp (name
, elem_name
) < 0;
3772 auto begin
= this->name_components
.begin ();
3773 auto end
= this->name_components
.end ();
3775 /* Find the lower bound. */
3778 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3781 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3784 /* Find the upper bound. */
3787 if (lookup_name_without_params
.completion_mode ())
3789 /* In completion mode, we want UPPER to point past all
3790 symbols names that have the same prefix. I.e., with
3791 these symbols, and completing "func":
3793 function << lower bound
3795 other_function << upper bound
3797 We find the upper bound by looking for the insertion
3798 point of "func"-with-last-character-incremented,
3800 std::string after
= make_sort_after_prefix_name (lang_name
);
3803 return std::lower_bound (lower
, end
, after
.c_str (),
3804 lookup_compare_lower
);
3807 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3810 return {lower
, upper
};
3813 /* See declaration. */
3816 mapped_index_base::build_name_components ()
3818 if (!this->name_components
.empty ())
3821 this->name_components_casing
= case_sensitivity
;
3823 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3825 /* The code below only knows how to break apart components of C++
3826 symbol names (and other languages that use '::' as
3827 namespace/module separator) and Ada symbol names. */
3828 auto count
= this->symbol_name_count ();
3829 for (offset_type idx
= 0; idx
< count
; idx
++)
3831 if (this->symbol_name_slot_invalid (idx
))
3834 const char *name
= this->symbol_name_at (idx
);
3836 /* Add each name component to the name component table. */
3837 unsigned int previous_len
= 0;
3839 if (strstr (name
, "::") != nullptr)
3841 for (unsigned int current_len
= cp_find_first_component (name
);
3842 name
[current_len
] != '\0';
3843 current_len
+= cp_find_first_component (name
+ current_len
))
3845 gdb_assert (name
[current_len
] == ':');
3846 this->name_components
.push_back ({previous_len
, idx
});
3847 /* Skip the '::'. */
3849 previous_len
= current_len
;
3854 /* Handle the Ada encoded (aka mangled) form here. */
3855 for (const char *iter
= strstr (name
, "__");
3857 iter
= strstr (iter
, "__"))
3859 this->name_components
.push_back ({previous_len
, idx
});
3861 previous_len
= iter
- name
;
3865 this->name_components
.push_back ({previous_len
, idx
});
3868 /* Sort name_components elements by name. */
3869 auto name_comp_compare
= [&] (const name_component
&left
,
3870 const name_component
&right
)
3872 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3873 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3875 const char *left_name
= left_qualified
+ left
.name_offset
;
3876 const char *right_name
= right_qualified
+ right
.name_offset
;
3878 return name_cmp (left_name
, right_name
) < 0;
3881 std::sort (this->name_components
.begin (),
3882 this->name_components
.end (),
3886 /* Helper for dw2_expand_symtabs_matching that works with a
3887 mapped_index_base instead of the containing objfile. This is split
3888 to a separate function in order to be able to unit test the
3889 name_components matching using a mock mapped_index_base. For each
3890 symbol name that matches, calls MATCH_CALLBACK, passing it the
3891 symbol's index in the mapped_index_base symbol table. */
3894 dw2_expand_symtabs_matching_symbol
3895 (mapped_index_base
&index
,
3896 const lookup_name_info
&lookup_name_in
,
3897 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3898 enum search_domain kind
,
3899 gdb::function_view
<bool (offset_type
)> match_callback
)
3901 lookup_name_info lookup_name_without_params
3902 = lookup_name_in
.make_ignore_params ();
3904 /* Build the symbol name component sorted vector, if we haven't
3906 index
.build_name_components ();
3908 /* The same symbol may appear more than once in the range though.
3909 E.g., if we're looking for symbols that complete "w", and we have
3910 a symbol named "w1::w2", we'll find the two name components for
3911 that same symbol in the range. To be sure we only call the
3912 callback once per symbol, we first collect the symbol name
3913 indexes that matched in a temporary vector and ignore
3915 std::vector
<offset_type
> matches
;
3917 struct name_and_matcher
3919 symbol_name_matcher_ftype
*matcher
;
3920 const std::string
&name
;
3922 bool operator== (const name_and_matcher
&other
) const
3924 return matcher
== other
.matcher
&& name
== other
.name
;
3928 /* A vector holding all the different symbol name matchers, for all
3930 std::vector
<name_and_matcher
> matchers
;
3932 for (int i
= 0; i
< nr_languages
; i
++)
3934 enum language lang_e
= (enum language
) i
;
3936 const language_defn
*lang
= language_def (lang_e
);
3937 symbol_name_matcher_ftype
*name_matcher
3938 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3940 name_and_matcher key
{
3942 lookup_name_without_params
.language_lookup_name (lang_e
)
3945 /* Don't insert the same comparison routine more than once.
3946 Note that we do this linear walk. This is not a problem in
3947 practice because the number of supported languages is
3949 if (std::find (matchers
.begin (), matchers
.end (), key
)
3952 matchers
.push_back (std::move (key
));
3955 = index
.find_name_components_bounds (lookup_name_without_params
,
3958 /* Now for each symbol name in range, check to see if we have a name
3959 match, and if so, call the MATCH_CALLBACK callback. */
3961 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3963 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3965 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3966 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3969 matches
.push_back (bounds
.first
->idx
);
3973 std::sort (matches
.begin (), matches
.end ());
3975 /* Finally call the callback, once per match. */
3977 for (offset_type idx
: matches
)
3981 if (!match_callback (idx
))
3987 /* Above we use a type wider than idx's for 'prev', since 0 and
3988 (offset_type)-1 are both possible values. */
3989 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3994 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3996 /* A mock .gdb_index/.debug_names-like name index table, enough to
3997 exercise dw2_expand_symtabs_matching_symbol, which works with the
3998 mapped_index_base interface. Builds an index from the symbol list
3999 passed as parameter to the constructor. */
4000 class mock_mapped_index
: public mapped_index_base
4003 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4004 : m_symbol_table (symbols
)
4007 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4009 /* Return the number of names in the symbol table. */
4010 size_t symbol_name_count () const override
4012 return m_symbol_table
.size ();
4015 /* Get the name of the symbol at IDX in the symbol table. */
4016 const char *symbol_name_at (offset_type idx
) const override
4018 return m_symbol_table
[idx
];
4022 gdb::array_view
<const char *> m_symbol_table
;
4025 /* Convenience function that converts a NULL pointer to a "<null>"
4026 string, to pass to print routines. */
4029 string_or_null (const char *str
)
4031 return str
!= NULL
? str
: "<null>";
4034 /* Check if a lookup_name_info built from
4035 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4036 index. EXPECTED_LIST is the list of expected matches, in expected
4037 matching order. If no match expected, then an empty list is
4038 specified. Returns true on success. On failure prints a warning
4039 indicating the file:line that failed, and returns false. */
4042 check_match (const char *file
, int line
,
4043 mock_mapped_index
&mock_index
,
4044 const char *name
, symbol_name_match_type match_type
,
4045 bool completion_mode
,
4046 std::initializer_list
<const char *> expected_list
)
4048 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4050 bool matched
= true;
4052 auto mismatch
= [&] (const char *expected_str
,
4055 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4056 "expected=\"%s\", got=\"%s\"\n"),
4058 (match_type
== symbol_name_match_type::FULL
4060 name
, string_or_null (expected_str
), string_or_null (got
));
4064 auto expected_it
= expected_list
.begin ();
4065 auto expected_end
= expected_list
.end ();
4067 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4069 [&] (offset_type idx
)
4071 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4072 const char *expected_str
4073 = expected_it
== expected_end
? NULL
: *expected_it
++;
4075 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4076 mismatch (expected_str
, matched_name
);
4080 const char *expected_str
4081 = expected_it
== expected_end
? NULL
: *expected_it
++;
4082 if (expected_str
!= NULL
)
4083 mismatch (expected_str
, NULL
);
4088 /* The symbols added to the mock mapped_index for testing (in
4090 static const char *test_symbols
[] = {
4099 "ns2::tmpl<int>::foo2",
4100 "(anonymous namespace)::A::B::C",
4102 /* These are used to check that the increment-last-char in the
4103 matching algorithm for completion doesn't match "t1_fund" when
4104 completing "t1_func". */
4110 /* A UTF-8 name with multi-byte sequences to make sure that
4111 cp-name-parser understands this as a single identifier ("função"
4112 is "function" in PT). */
4115 /* \377 (0xff) is Latin1 'ÿ'. */
4118 /* \377 (0xff) is Latin1 'ÿ'. */
4122 /* A name with all sorts of complications. Starts with "z" to make
4123 it easier for the completion tests below. */
4124 #define Z_SYM_NAME \
4125 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4126 "::tuple<(anonymous namespace)::ui*, " \
4127 "std::default_delete<(anonymous namespace)::ui>, void>"
4132 /* Returns true if the mapped_index_base::find_name_component_bounds
4133 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4134 in completion mode. */
4137 check_find_bounds_finds (mapped_index_base
&index
,
4138 const char *search_name
,
4139 gdb::array_view
<const char *> expected_syms
)
4141 lookup_name_info
lookup_name (search_name
,
4142 symbol_name_match_type::FULL
, true);
4144 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4147 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4148 if (distance
!= expected_syms
.size ())
4151 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4153 auto nc_elem
= bounds
.first
+ exp_elem
;
4154 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4155 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4162 /* Test the lower-level mapped_index::find_name_component_bounds
4166 test_mapped_index_find_name_component_bounds ()
4168 mock_mapped_index
mock_index (test_symbols
);
4170 mock_index
.build_name_components ();
4172 /* Test the lower-level mapped_index::find_name_component_bounds
4173 method in completion mode. */
4175 static const char *expected_syms
[] = {
4180 SELF_CHECK (check_find_bounds_finds (mock_index
,
4181 "t1_func", expected_syms
));
4184 /* Check that the increment-last-char in the name matching algorithm
4185 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4187 static const char *expected_syms1
[] = {
4191 SELF_CHECK (check_find_bounds_finds (mock_index
,
4192 "\377", expected_syms1
));
4194 static const char *expected_syms2
[] = {
4197 SELF_CHECK (check_find_bounds_finds (mock_index
,
4198 "\377\377", expected_syms2
));
4202 /* Test dw2_expand_symtabs_matching_symbol. */
4205 test_dw2_expand_symtabs_matching_symbol ()
4207 mock_mapped_index
mock_index (test_symbols
);
4209 /* We let all tests run until the end even if some fails, for debug
4211 bool any_mismatch
= false;
4213 /* Create the expected symbols list (an initializer_list). Needed
4214 because lists have commas, and we need to pass them to CHECK,
4215 which is a macro. */
4216 #define EXPECT(...) { __VA_ARGS__ }
4218 /* Wrapper for check_match that passes down the current
4219 __FILE__/__LINE__. */
4220 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4221 any_mismatch |= !check_match (__FILE__, __LINE__, \
4223 NAME, MATCH_TYPE, COMPLETION_MODE, \
4226 /* Identity checks. */
4227 for (const char *sym
: test_symbols
)
4229 /* Should be able to match all existing symbols. */
4230 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4233 /* Should be able to match all existing symbols with
4235 std::string with_params
= std::string (sym
) + "(int)";
4236 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4239 /* Should be able to match all existing symbols with
4240 parameters and qualifiers. */
4241 with_params
= std::string (sym
) + " ( int ) const";
4242 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4245 /* This should really find sym, but cp-name-parser.y doesn't
4246 know about lvalue/rvalue qualifiers yet. */
4247 with_params
= std::string (sym
) + " ( int ) &&";
4248 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4252 /* Check that the name matching algorithm for completion doesn't get
4253 confused with Latin1 'ÿ' / 0xff. */
4255 static const char str
[] = "\377";
4256 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4257 EXPECT ("\377", "\377\377123"));
4260 /* Check that the increment-last-char in the matching algorithm for
4261 completion doesn't match "t1_fund" when completing "t1_func". */
4263 static const char str
[] = "t1_func";
4264 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4265 EXPECT ("t1_func", "t1_func1"));
4268 /* Check that completion mode works at each prefix of the expected
4271 static const char str
[] = "function(int)";
4272 size_t len
= strlen (str
);
4275 for (size_t i
= 1; i
< len
; i
++)
4277 lookup
.assign (str
, i
);
4278 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4279 EXPECT ("function"));
4283 /* While "w" is a prefix of both components, the match function
4284 should still only be called once. */
4286 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4288 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4292 /* Same, with a "complicated" symbol. */
4294 static const char str
[] = Z_SYM_NAME
;
4295 size_t len
= strlen (str
);
4298 for (size_t i
= 1; i
< len
; i
++)
4300 lookup
.assign (str
, i
);
4301 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4302 EXPECT (Z_SYM_NAME
));
4306 /* In FULL mode, an incomplete symbol doesn't match. */
4308 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4312 /* A complete symbol with parameters matches any overload, since the
4313 index has no overload info. */
4315 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4316 EXPECT ("std::zfunction", "std::zfunction2"));
4317 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4318 EXPECT ("std::zfunction", "std::zfunction2"));
4319 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4320 EXPECT ("std::zfunction", "std::zfunction2"));
4323 /* Check that whitespace is ignored appropriately. A symbol with a
4324 template argument list. */
4326 static const char expected
[] = "ns::foo<int>";
4327 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4329 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4333 /* Check that whitespace is ignored appropriately. A symbol with a
4334 template argument list that includes a pointer. */
4336 static const char expected
[] = "ns::foo<char*>";
4337 /* Try both completion and non-completion modes. */
4338 static const bool completion_mode
[2] = {false, true};
4339 for (size_t i
= 0; i
< 2; i
++)
4341 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4342 completion_mode
[i
], EXPECT (expected
));
4343 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4344 completion_mode
[i
], EXPECT (expected
));
4346 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4347 completion_mode
[i
], EXPECT (expected
));
4348 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4349 completion_mode
[i
], EXPECT (expected
));
4354 /* Check method qualifiers are ignored. */
4355 static const char expected
[] = "ns::foo<char*>";
4356 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4357 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4358 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4359 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4360 CHECK_MATCH ("foo < char * > ( int ) const",
4361 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4362 CHECK_MATCH ("foo < char * > ( int ) &&",
4363 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4366 /* Test lookup names that don't match anything. */
4368 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4371 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4375 /* Some wild matching tests, exercising "(anonymous namespace)",
4376 which should not be confused with a parameter list. */
4378 static const char *syms
[] = {
4382 "A :: B :: C ( int )",
4387 for (const char *s
: syms
)
4389 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4390 EXPECT ("(anonymous namespace)::A::B::C"));
4395 static const char expected
[] = "ns2::tmpl<int>::foo2";
4396 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4398 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4402 SELF_CHECK (!any_mismatch
);
4411 test_mapped_index_find_name_component_bounds ();
4412 test_dw2_expand_symtabs_matching_symbol ();
4415 }} // namespace selftests::dw2_expand_symtabs_matching
4417 #endif /* GDB_SELF_TEST */
4419 /* If FILE_MATCHER is NULL or if PER_CU has
4420 dwarf2_per_cu_quick_data::MARK set (see
4421 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4422 EXPANSION_NOTIFY on it. */
4425 dw2_expand_symtabs_matching_one
4426 (struct dwarf2_per_cu_data
*per_cu
,
4427 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4428 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4430 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4432 bool symtab_was_null
4433 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4435 dw2_instantiate_symtab (per_cu
, false);
4437 if (expansion_notify
!= NULL
4439 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4440 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4444 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4445 matched, to expand corresponding CUs that were marked. IDX is the
4446 index of the symbol name that matched. */
4449 dw2_expand_marked_cus
4450 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4451 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4452 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4455 offset_type
*vec
, vec_len
, vec_idx
;
4456 bool global_seen
= false;
4457 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4459 vec
= (offset_type
*) (index
.constant_pool
4460 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4461 vec_len
= MAYBE_SWAP (vec
[0]);
4462 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4464 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4465 /* This value is only valid for index versions >= 7. */
4466 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4467 gdb_index_symbol_kind symbol_kind
=
4468 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4469 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4470 /* Only check the symbol attributes if they're present.
4471 Indices prior to version 7 don't record them,
4472 and indices >= 7 may elide them for certain symbols
4473 (gold does this). */
4476 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4478 /* Work around gold/15646. */
4481 if (!is_static
&& global_seen
)
4487 /* Only check the symbol's kind if it has one. */
4492 case VARIABLES_DOMAIN
:
4493 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4496 case FUNCTIONS_DOMAIN
:
4497 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4501 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4504 case MODULES_DOMAIN
:
4505 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4513 /* Don't crash on bad data. */
4514 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4515 + dwarf2_per_objfile
->all_type_units
.size ()))
4517 complaint (_(".gdb_index entry has bad CU index"
4519 objfile_name (dwarf2_per_objfile
->objfile
));
4523 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4524 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4529 /* If FILE_MATCHER is non-NULL, set all the
4530 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4531 that match FILE_MATCHER. */
4534 dw_expand_symtabs_matching_file_matcher
4535 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4536 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4538 if (file_matcher
== NULL
)
4541 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4543 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4545 NULL
, xcalloc
, xfree
));
4546 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4548 NULL
, xcalloc
, xfree
));
4550 /* The rule is CUs specify all the files, including those used by
4551 any TU, so there's no need to scan TUs here. */
4553 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4557 per_cu
->v
.quick
->mark
= 0;
4559 /* We only need to look at symtabs not already expanded. */
4560 if (per_cu
->v
.quick
->compunit_symtab
)
4563 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4564 if (file_data
== NULL
)
4567 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4569 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4571 per_cu
->v
.quick
->mark
= 1;
4575 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4577 const char *this_real_name
;
4579 if (file_matcher (file_data
->file_names
[j
], false))
4581 per_cu
->v
.quick
->mark
= 1;
4585 /* Before we invoke realpath, which can get expensive when many
4586 files are involved, do a quick comparison of the basenames. */
4587 if (!basenames_may_differ
4588 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4592 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4593 if (file_matcher (this_real_name
, false))
4595 per_cu
->v
.quick
->mark
= 1;
4600 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4601 ? visited_found
.get ()
4602 : visited_not_found
.get (),
4609 dw2_expand_symtabs_matching
4610 (struct objfile
*objfile
,
4611 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4612 const lookup_name_info
&lookup_name
,
4613 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4614 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4615 enum search_domain kind
)
4617 struct dwarf2_per_objfile
*dwarf2_per_objfile
4618 = get_dwarf2_per_objfile (objfile
);
4620 /* index_table is NULL if OBJF_READNOW. */
4621 if (!dwarf2_per_objfile
->index_table
)
4624 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4626 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4628 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4630 kind
, [&] (offset_type idx
)
4632 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4633 expansion_notify
, kind
);
4638 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4641 static struct compunit_symtab
*
4642 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4647 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4648 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4651 if (cust
->includes
== NULL
)
4654 for (i
= 0; cust
->includes
[i
]; ++i
)
4656 struct compunit_symtab
*s
= cust
->includes
[i
];
4658 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4666 static struct compunit_symtab
*
4667 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4668 struct bound_minimal_symbol msymbol
,
4670 struct obj_section
*section
,
4673 struct dwarf2_per_cu_data
*data
;
4674 struct compunit_symtab
*result
;
4676 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4679 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4680 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4681 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4685 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4686 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4687 paddress (get_objfile_arch (objfile
), pc
));
4690 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4693 gdb_assert (result
!= NULL
);
4698 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4699 void *data
, int need_fullname
)
4701 struct dwarf2_per_objfile
*dwarf2_per_objfile
4702 = get_dwarf2_per_objfile (objfile
);
4704 if (!dwarf2_per_objfile
->filenames_cache
)
4706 dwarf2_per_objfile
->filenames_cache
.emplace ();
4708 htab_up
visited (htab_create_alloc (10,
4709 htab_hash_pointer
, htab_eq_pointer
,
4710 NULL
, xcalloc
, xfree
));
4712 /* The rule is CUs specify all the files, including those used
4713 by any TU, so there's no need to scan TUs here. We can
4714 ignore file names coming from already-expanded CUs. */
4716 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4718 if (per_cu
->v
.quick
->compunit_symtab
)
4720 void **slot
= htab_find_slot (visited
.get (),
4721 per_cu
->v
.quick
->file_names
,
4724 *slot
= per_cu
->v
.quick
->file_names
;
4728 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4730 /* We only need to look at symtabs not already expanded. */
4731 if (per_cu
->v
.quick
->compunit_symtab
)
4734 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4735 if (file_data
== NULL
)
4738 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4741 /* Already visited. */
4746 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4748 const char *filename
= file_data
->file_names
[j
];
4749 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4754 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4756 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4759 this_real_name
= gdb_realpath (filename
);
4760 (*fun
) (filename
, this_real_name
.get (), data
);
4765 dw2_has_symbols (struct objfile
*objfile
)
4770 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4773 dw2_find_last_source_symtab
,
4774 dw2_forget_cached_source_info
,
4775 dw2_map_symtabs_matching_filename
,
4779 dw2_expand_symtabs_for_function
,
4780 dw2_expand_all_symtabs
,
4781 dw2_expand_symtabs_with_fullname
,
4782 dw2_map_matching_symbols
,
4783 dw2_expand_symtabs_matching
,
4784 dw2_find_pc_sect_compunit_symtab
,
4786 dw2_map_symbol_filenames
4789 /* DWARF-5 debug_names reader. */
4791 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4792 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4794 /* A helper function that reads the .debug_names section in SECTION
4795 and fills in MAP. FILENAME is the name of the file containing the
4796 section; it is used for error reporting.
4798 Returns true if all went well, false otherwise. */
4801 read_debug_names_from_section (struct objfile
*objfile
,
4802 const char *filename
,
4803 struct dwarf2_section_info
*section
,
4804 mapped_debug_names
&map
)
4806 if (section
->empty ())
4809 /* Older elfutils strip versions could keep the section in the main
4810 executable while splitting it for the separate debug info file. */
4811 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4814 section
->read (objfile
);
4816 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4818 const gdb_byte
*addr
= section
->buffer
;
4820 bfd
*const abfd
= section
->get_bfd_owner ();
4822 unsigned int bytes_read
;
4823 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4826 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4827 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4828 if (bytes_read
+ length
!= section
->size
)
4830 /* There may be multiple per-CU indices. */
4831 warning (_("Section .debug_names in %s length %s does not match "
4832 "section length %s, ignoring .debug_names."),
4833 filename
, plongest (bytes_read
+ length
),
4834 pulongest (section
->size
));
4838 /* The version number. */
4839 uint16_t version
= read_2_bytes (abfd
, addr
);
4843 warning (_("Section .debug_names in %s has unsupported version %d, "
4844 "ignoring .debug_names."),
4850 uint16_t padding
= read_2_bytes (abfd
, addr
);
4854 warning (_("Section .debug_names in %s has unsupported padding %d, "
4855 "ignoring .debug_names."),
4860 /* comp_unit_count - The number of CUs in the CU list. */
4861 map
.cu_count
= read_4_bytes (abfd
, addr
);
4864 /* local_type_unit_count - The number of TUs in the local TU
4866 map
.tu_count
= read_4_bytes (abfd
, addr
);
4869 /* foreign_type_unit_count - The number of TUs in the foreign TU
4871 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4873 if (foreign_tu_count
!= 0)
4875 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4876 "ignoring .debug_names."),
4877 filename
, static_cast<unsigned long> (foreign_tu_count
));
4881 /* bucket_count - The number of hash buckets in the hash lookup
4883 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4886 /* name_count - The number of unique names in the index. */
4887 map
.name_count
= read_4_bytes (abfd
, addr
);
4890 /* abbrev_table_size - The size in bytes of the abbreviations
4892 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4895 /* augmentation_string_size - The size in bytes of the augmentation
4896 string. This value is rounded up to a multiple of 4. */
4897 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4899 map
.augmentation_is_gdb
= ((augmentation_string_size
4900 == sizeof (dwarf5_augmentation
))
4901 && memcmp (addr
, dwarf5_augmentation
,
4902 sizeof (dwarf5_augmentation
)) == 0);
4903 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4904 addr
+= augmentation_string_size
;
4907 map
.cu_table_reordered
= addr
;
4908 addr
+= map
.cu_count
* map
.offset_size
;
4910 /* List of Local TUs */
4911 map
.tu_table_reordered
= addr
;
4912 addr
+= map
.tu_count
* map
.offset_size
;
4914 /* Hash Lookup Table */
4915 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4916 addr
+= map
.bucket_count
* 4;
4917 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4918 addr
+= map
.name_count
* 4;
4921 map
.name_table_string_offs_reordered
= addr
;
4922 addr
+= map
.name_count
* map
.offset_size
;
4923 map
.name_table_entry_offs_reordered
= addr
;
4924 addr
+= map
.name_count
* map
.offset_size
;
4926 const gdb_byte
*abbrev_table_start
= addr
;
4929 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4934 const auto insertpair
4935 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4936 if (!insertpair
.second
)
4938 warning (_("Section .debug_names in %s has duplicate index %s, "
4939 "ignoring .debug_names."),
4940 filename
, pulongest (index_num
));
4943 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4944 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4949 mapped_debug_names::index_val::attr attr
;
4950 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4952 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4954 if (attr
.form
== DW_FORM_implicit_const
)
4956 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4960 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4962 indexval
.attr_vec
.push_back (std::move (attr
));
4965 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4967 warning (_("Section .debug_names in %s has abbreviation_table "
4968 "of size %s vs. written as %u, ignoring .debug_names."),
4969 filename
, plongest (addr
- abbrev_table_start
),
4973 map
.entry_pool
= addr
;
4978 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4982 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4983 const mapped_debug_names
&map
,
4984 dwarf2_section_info
§ion
,
4987 sect_offset sect_off_prev
;
4988 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4990 sect_offset sect_off_next
;
4991 if (i
< map
.cu_count
)
4994 = (sect_offset
) (extract_unsigned_integer
4995 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4997 map
.dwarf5_byte_order
));
5000 sect_off_next
= (sect_offset
) section
.size
;
5003 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5004 dwarf2_per_cu_data
*per_cu
5005 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5006 sect_off_prev
, length
);
5007 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5009 sect_off_prev
= sect_off_next
;
5013 /* Read the CU list from the mapped index, and use it to create all
5014 the CU objects for this dwarf2_per_objfile. */
5017 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5018 const mapped_debug_names
&map
,
5019 const mapped_debug_names
&dwz_map
)
5021 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5022 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5024 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5025 dwarf2_per_objfile
->info
,
5026 false /* is_dwz */);
5028 if (dwz_map
.cu_count
== 0)
5031 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5032 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5036 /* Read .debug_names. If everything went ok, initialize the "quick"
5037 elements of all the CUs and return true. Otherwise, return false. */
5040 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5042 std::unique_ptr
<mapped_debug_names
> map
5043 (new mapped_debug_names (dwarf2_per_objfile
));
5044 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5045 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5047 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5048 &dwarf2_per_objfile
->debug_names
,
5052 /* Don't use the index if it's empty. */
5053 if (map
->name_count
== 0)
5056 /* If there is a .dwz file, read it so we can get its CU list as
5058 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5061 if (!read_debug_names_from_section (objfile
,
5062 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5063 &dwz
->debug_names
, dwz_map
))
5065 warning (_("could not read '.debug_names' section from %s; skipping"),
5066 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5071 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5073 if (map
->tu_count
!= 0)
5075 /* We can only handle a single .debug_types when we have an
5077 if (dwarf2_per_objfile
->types
.size () != 1)
5080 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5082 create_signatured_type_table_from_debug_names
5083 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5086 create_addrmap_from_aranges (dwarf2_per_objfile
,
5087 &dwarf2_per_objfile
->debug_aranges
);
5089 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5090 dwarf2_per_objfile
->using_index
= 1;
5091 dwarf2_per_objfile
->quick_file_names_table
=
5092 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5097 /* Type used to manage iterating over all CUs looking for a symbol for
5100 class dw2_debug_names_iterator
5103 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5104 gdb::optional
<block_enum
> block_index
,
5107 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5108 m_addr (find_vec_in_debug_names (map
, name
))
5111 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5112 search_domain search
, uint32_t namei
)
5115 m_addr (find_vec_in_debug_names (map
, namei
))
5118 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5119 block_enum block_index
, domain_enum domain
,
5121 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5122 m_addr (find_vec_in_debug_names (map
, namei
))
5125 /* Return the next matching CU or NULL if there are no more. */
5126 dwarf2_per_cu_data
*next ();
5129 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5131 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5134 /* The internalized form of .debug_names. */
5135 const mapped_debug_names
&m_map
;
5137 /* If set, only look for symbols that match that block. Valid values are
5138 GLOBAL_BLOCK and STATIC_BLOCK. */
5139 const gdb::optional
<block_enum
> m_block_index
;
5141 /* The kind of symbol we're looking for. */
5142 const domain_enum m_domain
= UNDEF_DOMAIN
;
5143 const search_domain m_search
= ALL_DOMAIN
;
5145 /* The list of CUs from the index entry of the symbol, or NULL if
5147 const gdb_byte
*m_addr
;
5151 mapped_debug_names::namei_to_name (uint32_t namei
) const
5153 const ULONGEST namei_string_offs
5154 = extract_unsigned_integer ((name_table_string_offs_reordered
5155 + namei
* offset_size
),
5158 return read_indirect_string_at_offset
5159 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5162 /* Find a slot in .debug_names for the object named NAME. If NAME is
5163 found, return pointer to its pool data. If NAME cannot be found,
5167 dw2_debug_names_iterator::find_vec_in_debug_names
5168 (const mapped_debug_names
&map
, const char *name
)
5170 int (*cmp
) (const char *, const char *);
5172 gdb::unique_xmalloc_ptr
<char> without_params
;
5173 if (current_language
->la_language
== language_cplus
5174 || current_language
->la_language
== language_fortran
5175 || current_language
->la_language
== language_d
)
5177 /* NAME is already canonical. Drop any qualifiers as
5178 .debug_names does not contain any. */
5180 if (strchr (name
, '(') != NULL
)
5182 without_params
= cp_remove_params (name
);
5183 if (without_params
!= NULL
)
5184 name
= without_params
.get ();
5188 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5190 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5192 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5193 (map
.bucket_table_reordered
5194 + (full_hash
% map
.bucket_count
)), 4,
5195 map
.dwarf5_byte_order
);
5199 if (namei
>= map
.name_count
)
5201 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5203 namei
, map
.name_count
,
5204 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5210 const uint32_t namei_full_hash
5211 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5212 (map
.hash_table_reordered
+ namei
), 4,
5213 map
.dwarf5_byte_order
);
5214 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5217 if (full_hash
== namei_full_hash
)
5219 const char *const namei_string
= map
.namei_to_name (namei
);
5221 #if 0 /* An expensive sanity check. */
5222 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5224 complaint (_("Wrong .debug_names hash for string at index %u "
5226 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5231 if (cmp (namei_string
, name
) == 0)
5233 const ULONGEST namei_entry_offs
5234 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5235 + namei
* map
.offset_size
),
5236 map
.offset_size
, map
.dwarf5_byte_order
);
5237 return map
.entry_pool
+ namei_entry_offs
;
5242 if (namei
>= map
.name_count
)
5248 dw2_debug_names_iterator::find_vec_in_debug_names
5249 (const mapped_debug_names
&map
, uint32_t namei
)
5251 if (namei
>= map
.name_count
)
5253 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5255 namei
, map
.name_count
,
5256 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5260 const ULONGEST namei_entry_offs
5261 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5262 + namei
* map
.offset_size
),
5263 map
.offset_size
, map
.dwarf5_byte_order
);
5264 return map
.entry_pool
+ namei_entry_offs
;
5267 /* See dw2_debug_names_iterator. */
5269 dwarf2_per_cu_data
*
5270 dw2_debug_names_iterator::next ()
5275 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5276 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5277 bfd
*const abfd
= objfile
->obfd
;
5281 unsigned int bytes_read
;
5282 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5283 m_addr
+= bytes_read
;
5287 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5288 if (indexval_it
== m_map
.abbrev_map
.cend ())
5290 complaint (_("Wrong .debug_names undefined abbrev code %s "
5292 pulongest (abbrev
), objfile_name (objfile
));
5295 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5296 enum class symbol_linkage
{
5300 } symbol_linkage_
= symbol_linkage::unknown
;
5301 dwarf2_per_cu_data
*per_cu
= NULL
;
5302 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5307 case DW_FORM_implicit_const
:
5308 ull
= attr
.implicit_const
;
5310 case DW_FORM_flag_present
:
5314 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5315 m_addr
+= bytes_read
;
5318 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5319 dwarf_form_name (attr
.form
),
5320 objfile_name (objfile
));
5323 switch (attr
.dw_idx
)
5325 case DW_IDX_compile_unit
:
5326 /* Don't crash on bad data. */
5327 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5329 complaint (_(".debug_names entry has bad CU index %s"
5332 objfile_name (dwarf2_per_objfile
->objfile
));
5335 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5337 case DW_IDX_type_unit
:
5338 /* Don't crash on bad data. */
5339 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5341 complaint (_(".debug_names entry has bad TU index %s"
5344 objfile_name (dwarf2_per_objfile
->objfile
));
5347 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5349 case DW_IDX_GNU_internal
:
5350 if (!m_map
.augmentation_is_gdb
)
5352 symbol_linkage_
= symbol_linkage::static_
;
5354 case DW_IDX_GNU_external
:
5355 if (!m_map
.augmentation_is_gdb
)
5357 symbol_linkage_
= symbol_linkage::extern_
;
5362 /* Skip if already read in. */
5363 if (per_cu
->v
.quick
->compunit_symtab
)
5366 /* Check static vs global. */
5367 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5369 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5370 const bool symbol_is_static
=
5371 symbol_linkage_
== symbol_linkage::static_
;
5372 if (want_static
!= symbol_is_static
)
5376 /* Match dw2_symtab_iter_next, symbol_kind
5377 and debug_names::psymbol_tag. */
5381 switch (indexval
.dwarf_tag
)
5383 case DW_TAG_variable
:
5384 case DW_TAG_subprogram
:
5385 /* Some types are also in VAR_DOMAIN. */
5386 case DW_TAG_typedef
:
5387 case DW_TAG_structure_type
:
5394 switch (indexval
.dwarf_tag
)
5396 case DW_TAG_typedef
:
5397 case DW_TAG_structure_type
:
5404 switch (indexval
.dwarf_tag
)
5407 case DW_TAG_variable
:
5414 switch (indexval
.dwarf_tag
)
5426 /* Match dw2_expand_symtabs_matching, symbol_kind and
5427 debug_names::psymbol_tag. */
5430 case VARIABLES_DOMAIN
:
5431 switch (indexval
.dwarf_tag
)
5433 case DW_TAG_variable
:
5439 case FUNCTIONS_DOMAIN
:
5440 switch (indexval
.dwarf_tag
)
5442 case DW_TAG_subprogram
:
5449 switch (indexval
.dwarf_tag
)
5451 case DW_TAG_typedef
:
5452 case DW_TAG_structure_type
:
5458 case MODULES_DOMAIN
:
5459 switch (indexval
.dwarf_tag
)
5473 static struct compunit_symtab
*
5474 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5475 const char *name
, domain_enum domain
)
5477 struct dwarf2_per_objfile
*dwarf2_per_objfile
5478 = get_dwarf2_per_objfile (objfile
);
5480 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5483 /* index is NULL if OBJF_READNOW. */
5486 const auto &map
= *mapp
;
5488 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5490 struct compunit_symtab
*stab_best
= NULL
;
5491 struct dwarf2_per_cu_data
*per_cu
;
5492 while ((per_cu
= iter
.next ()) != NULL
)
5494 struct symbol
*sym
, *with_opaque
= NULL
;
5495 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5496 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5497 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5499 sym
= block_find_symbol (block
, name
, domain
,
5500 block_find_non_opaque_type_preferred
,
5503 /* Some caution must be observed with overloaded functions and
5504 methods, since the index will not contain any overload
5505 information (but NAME might contain it). */
5508 && strcmp_iw (sym
->search_name (), name
) == 0)
5510 if (with_opaque
!= NULL
5511 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5514 /* Keep looking through other CUs. */
5520 /* This dumps minimal information about .debug_names. It is called
5521 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5522 uses this to verify that .debug_names has been loaded. */
5525 dw2_debug_names_dump (struct objfile
*objfile
)
5527 struct dwarf2_per_objfile
*dwarf2_per_objfile
5528 = get_dwarf2_per_objfile (objfile
);
5530 gdb_assert (dwarf2_per_objfile
->using_index
);
5531 printf_filtered (".debug_names:");
5532 if (dwarf2_per_objfile
->debug_names_table
)
5533 printf_filtered (" exists\n");
5535 printf_filtered (" faked for \"readnow\"\n");
5536 printf_filtered ("\n");
5540 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5541 const char *func_name
)
5543 struct dwarf2_per_objfile
*dwarf2_per_objfile
5544 = get_dwarf2_per_objfile (objfile
);
5546 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5547 if (dwarf2_per_objfile
->debug_names_table
)
5549 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5551 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5553 struct dwarf2_per_cu_data
*per_cu
;
5554 while ((per_cu
= iter
.next ()) != NULL
)
5555 dw2_instantiate_symtab (per_cu
, false);
5560 dw2_debug_names_map_matching_symbols
5561 (struct objfile
*objfile
,
5562 const lookup_name_info
&name
, domain_enum domain
,
5564 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5565 symbol_compare_ftype
*ordered_compare
)
5567 struct dwarf2_per_objfile
*dwarf2_per_objfile
5568 = get_dwarf2_per_objfile (objfile
);
5570 /* debug_names_table is NULL if OBJF_READNOW. */
5571 if (!dwarf2_per_objfile
->debug_names_table
)
5574 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5575 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5577 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5578 auto matcher
= [&] (const char *symname
)
5580 if (ordered_compare
== nullptr)
5582 return ordered_compare (symname
, match_name
) == 0;
5585 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5586 [&] (offset_type namei
)
5588 /* The name was matched, now expand corresponding CUs that were
5590 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5592 struct dwarf2_per_cu_data
*per_cu
;
5593 while ((per_cu
= iter
.next ()) != NULL
)
5594 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5598 /* It's a shame we couldn't do this inside the
5599 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5600 that have already been expanded. Instead, this loop matches what
5601 the psymtab code does. */
5602 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5604 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5605 if (cust
!= nullptr)
5607 const struct block
*block
5608 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5609 if (!iterate_over_symbols_terminated (block
, name
,
5617 dw2_debug_names_expand_symtabs_matching
5618 (struct objfile
*objfile
,
5619 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5620 const lookup_name_info
&lookup_name
,
5621 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5622 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5623 enum search_domain kind
)
5625 struct dwarf2_per_objfile
*dwarf2_per_objfile
5626 = get_dwarf2_per_objfile (objfile
);
5628 /* debug_names_table is NULL if OBJF_READNOW. */
5629 if (!dwarf2_per_objfile
->debug_names_table
)
5632 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5634 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5636 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5638 kind
, [&] (offset_type namei
)
5640 /* The name was matched, now expand corresponding CUs that were
5642 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5644 struct dwarf2_per_cu_data
*per_cu
;
5645 while ((per_cu
= iter
.next ()) != NULL
)
5646 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5652 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5655 dw2_find_last_source_symtab
,
5656 dw2_forget_cached_source_info
,
5657 dw2_map_symtabs_matching_filename
,
5658 dw2_debug_names_lookup_symbol
,
5660 dw2_debug_names_dump
,
5661 dw2_debug_names_expand_symtabs_for_function
,
5662 dw2_expand_all_symtabs
,
5663 dw2_expand_symtabs_with_fullname
,
5664 dw2_debug_names_map_matching_symbols
,
5665 dw2_debug_names_expand_symtabs_matching
,
5666 dw2_find_pc_sect_compunit_symtab
,
5668 dw2_map_symbol_filenames
5671 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5672 to either a dwarf2_per_objfile or dwz_file object. */
5674 template <typename T
>
5675 static gdb::array_view
<const gdb_byte
>
5676 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5678 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5680 if (section
->empty ())
5683 /* Older elfutils strip versions could keep the section in the main
5684 executable while splitting it for the separate debug info file. */
5685 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5688 section
->read (obj
);
5690 /* dwarf2_section_info::size is a bfd_size_type, while
5691 gdb::array_view works with size_t. On 32-bit hosts, with
5692 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5693 is 32-bit. So we need an explicit narrowing conversion here.
5694 This is fine, because it's impossible to allocate or mmap an
5695 array/buffer larger than what size_t can represent. */
5696 return gdb::make_array_view (section
->buffer
, section
->size
);
5699 /* Lookup the index cache for the contents of the index associated to
5702 static gdb::array_view
<const gdb_byte
>
5703 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5705 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5706 if (build_id
== nullptr)
5709 return global_index_cache
.lookup_gdb_index (build_id
,
5710 &dwarf2_obj
->index_cache_res
);
5713 /* Same as the above, but for DWZ. */
5715 static gdb::array_view
<const gdb_byte
>
5716 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5718 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5719 if (build_id
== nullptr)
5722 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5725 /* See symfile.h. */
5728 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5730 struct dwarf2_per_objfile
*dwarf2_per_objfile
5731 = get_dwarf2_per_objfile (objfile
);
5733 /* If we're about to read full symbols, don't bother with the
5734 indices. In this case we also don't care if some other debug
5735 format is making psymtabs, because they are all about to be
5737 if ((objfile
->flags
& OBJF_READNOW
))
5739 dwarf2_per_objfile
->using_index
= 1;
5740 create_all_comp_units (dwarf2_per_objfile
);
5741 create_all_type_units (dwarf2_per_objfile
);
5742 dwarf2_per_objfile
->quick_file_names_table
5743 = create_quick_file_names_table
5744 (dwarf2_per_objfile
->all_comp_units
.size ());
5746 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5747 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5749 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5751 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5752 struct dwarf2_per_cu_quick_data
);
5755 /* Return 1 so that gdb sees the "quick" functions. However,
5756 these functions will be no-ops because we will have expanded
5758 *index_kind
= dw_index_kind::GDB_INDEX
;
5762 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5764 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5768 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5769 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5770 get_gdb_index_contents_from_section
<dwz_file
>))
5772 *index_kind
= dw_index_kind::GDB_INDEX
;
5776 /* ... otherwise, try to find the index in the index cache. */
5777 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5778 get_gdb_index_contents_from_cache
,
5779 get_gdb_index_contents_from_cache_dwz
))
5781 global_index_cache
.hit ();
5782 *index_kind
= dw_index_kind::GDB_INDEX
;
5786 global_index_cache
.miss ();
5792 /* Build a partial symbol table. */
5795 dwarf2_build_psymtabs (struct objfile
*objfile
)
5797 struct dwarf2_per_objfile
*dwarf2_per_objfile
5798 = get_dwarf2_per_objfile (objfile
);
5800 init_psymbol_list (objfile
, 1024);
5804 /* This isn't really ideal: all the data we allocate on the
5805 objfile's obstack is still uselessly kept around. However,
5806 freeing it seems unsafe. */
5807 psymtab_discarder
psymtabs (objfile
);
5808 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5811 /* (maybe) store an index in the cache. */
5812 global_index_cache
.store (dwarf2_per_objfile
);
5814 catch (const gdb_exception_error
&except
)
5816 exception_print (gdb_stderr
, except
);
5820 /* Find the base address of the compilation unit for range lists and
5821 location lists. It will normally be specified by DW_AT_low_pc.
5822 In DWARF-3 draft 4, the base address could be overridden by
5823 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5824 compilation units with discontinuous ranges. */
5827 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5829 struct attribute
*attr
;
5832 cu
->base_address
= 0;
5834 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5835 if (attr
!= nullptr)
5837 cu
->base_address
= attr
->value_as_address ();
5842 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5843 if (attr
!= nullptr)
5845 cu
->base_address
= attr
->value_as_address ();
5851 /* Helper function that returns the proper abbrev section for
5854 static struct dwarf2_section_info
*
5855 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5857 struct dwarf2_section_info
*abbrev
;
5858 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5860 if (this_cu
->is_dwz
)
5861 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5863 abbrev
= &dwarf2_per_objfile
->abbrev
;
5868 /* Fetch the abbreviation table offset from a comp or type unit header. */
5871 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5872 struct dwarf2_section_info
*section
,
5873 sect_offset sect_off
)
5875 bfd
*abfd
= section
->get_bfd_owner ();
5876 const gdb_byte
*info_ptr
;
5877 unsigned int initial_length_size
, offset_size
;
5880 section
->read (dwarf2_per_objfile
->objfile
);
5881 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5882 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5883 offset_size
= initial_length_size
== 4 ? 4 : 8;
5884 info_ptr
+= initial_length_size
;
5886 version
= read_2_bytes (abfd
, info_ptr
);
5890 /* Skip unit type and address size. */
5894 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5897 /* Allocate a new partial symtab for file named NAME and mark this new
5898 partial symtab as being an include of PST. */
5901 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5902 struct objfile
*objfile
)
5904 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
5906 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5908 /* It shares objfile->objfile_obstack. */
5909 subpst
->dirname
= pst
->dirname
;
5912 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5913 subpst
->dependencies
[0] = pst
;
5914 subpst
->number_of_dependencies
= 1;
5916 /* No private part is necessary for include psymtabs. This property
5917 can be used to differentiate between such include psymtabs and
5918 the regular ones. */
5919 subpst
->per_cu_data
= nullptr;
5922 /* Read the Line Number Program data and extract the list of files
5923 included by the source file represented by PST. Build an include
5924 partial symtab for each of these included files. */
5927 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5928 struct die_info
*die
,
5929 dwarf2_psymtab
*pst
)
5932 struct attribute
*attr
;
5934 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5935 if (attr
!= nullptr)
5936 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5938 return; /* No linetable, so no includes. */
5940 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5941 that we pass in the raw text_low here; that is ok because we're
5942 only decoding the line table to make include partial symtabs, and
5943 so the addresses aren't really used. */
5944 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5945 pst
->raw_text_low (), 1);
5949 hash_signatured_type (const void *item
)
5951 const struct signatured_type
*sig_type
5952 = (const struct signatured_type
*) item
;
5954 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5955 return sig_type
->signature
;
5959 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5961 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5962 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5964 return lhs
->signature
== rhs
->signature
;
5967 /* Allocate a hash table for signatured types. */
5970 allocate_signatured_type_table ()
5972 return htab_up (htab_create_alloc (41,
5973 hash_signatured_type
,
5975 NULL
, xcalloc
, xfree
));
5978 /* A helper function to add a signatured type CU to a table. */
5981 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5983 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5984 std::vector
<signatured_type
*> *all_type_units
5985 = (std::vector
<signatured_type
*> *) datum
;
5987 all_type_units
->push_back (sigt
);
5992 /* A helper for create_debug_types_hash_table. Read types from SECTION
5993 and fill them into TYPES_HTAB. It will process only type units,
5994 therefore DW_UT_type. */
5997 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5998 struct dwo_file
*dwo_file
,
5999 dwarf2_section_info
*section
, htab_up
&types_htab
,
6000 rcuh_kind section_kind
)
6002 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6003 struct dwarf2_section_info
*abbrev_section
;
6005 const gdb_byte
*info_ptr
, *end_ptr
;
6007 abbrev_section
= (dwo_file
!= NULL
6008 ? &dwo_file
->sections
.abbrev
6009 : &dwarf2_per_objfile
->abbrev
);
6011 if (dwarf_read_debug
)
6012 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6013 section
->get_name (),
6014 abbrev_section
->get_file_name ());
6016 section
->read (objfile
);
6017 info_ptr
= section
->buffer
;
6019 if (info_ptr
== NULL
)
6022 /* We can't set abfd until now because the section may be empty or
6023 not present, in which case the bfd is unknown. */
6024 abfd
= section
->get_bfd_owner ();
6026 /* We don't use cutu_reader here because we don't need to read
6027 any dies: the signature is in the header. */
6029 end_ptr
= info_ptr
+ section
->size
;
6030 while (info_ptr
< end_ptr
)
6032 struct signatured_type
*sig_type
;
6033 struct dwo_unit
*dwo_tu
;
6035 const gdb_byte
*ptr
= info_ptr
;
6036 struct comp_unit_head header
;
6037 unsigned int length
;
6039 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6041 /* Initialize it due to a false compiler warning. */
6042 header
.signature
= -1;
6043 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6045 /* We need to read the type's signature in order to build the hash
6046 table, but we don't need anything else just yet. */
6048 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6049 abbrev_section
, ptr
, section_kind
);
6051 length
= header
.get_length ();
6053 /* Skip dummy type units. */
6054 if (ptr
>= info_ptr
+ length
6055 || peek_abbrev_code (abfd
, ptr
) == 0
6056 || header
.unit_type
!= DW_UT_type
)
6062 if (types_htab
== NULL
)
6065 types_htab
= allocate_dwo_unit_table ();
6067 types_htab
= allocate_signatured_type_table ();
6073 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6075 dwo_tu
->dwo_file
= dwo_file
;
6076 dwo_tu
->signature
= header
.signature
;
6077 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6078 dwo_tu
->section
= section
;
6079 dwo_tu
->sect_off
= sect_off
;
6080 dwo_tu
->length
= length
;
6084 /* N.B.: type_offset is not usable if this type uses a DWO file.
6085 The real type_offset is in the DWO file. */
6087 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6088 struct signatured_type
);
6089 sig_type
->signature
= header
.signature
;
6090 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6091 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6092 sig_type
->per_cu
.is_debug_types
= 1;
6093 sig_type
->per_cu
.section
= section
;
6094 sig_type
->per_cu
.sect_off
= sect_off
;
6095 sig_type
->per_cu
.length
= length
;
6098 slot
= htab_find_slot (types_htab
.get (),
6099 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6101 gdb_assert (slot
!= NULL
);
6104 sect_offset dup_sect_off
;
6108 const struct dwo_unit
*dup_tu
6109 = (const struct dwo_unit
*) *slot
;
6111 dup_sect_off
= dup_tu
->sect_off
;
6115 const struct signatured_type
*dup_tu
6116 = (const struct signatured_type
*) *slot
;
6118 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6121 complaint (_("debug type entry at offset %s is duplicate to"
6122 " the entry at offset %s, signature %s"),
6123 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6124 hex_string (header
.signature
));
6126 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6128 if (dwarf_read_debug
> 1)
6129 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6130 sect_offset_str (sect_off
),
6131 hex_string (header
.signature
));
6137 /* Create the hash table of all entries in the .debug_types
6138 (or .debug_types.dwo) section(s).
6139 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6140 otherwise it is NULL.
6142 The result is a pointer to the hash table or NULL if there are no types.
6144 Note: This function processes DWO files only, not DWP files. */
6147 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6148 struct dwo_file
*dwo_file
,
6149 gdb::array_view
<dwarf2_section_info
> type_sections
,
6150 htab_up
&types_htab
)
6152 for (dwarf2_section_info
§ion
: type_sections
)
6153 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6154 types_htab
, rcuh_kind::TYPE
);
6157 /* Create the hash table of all entries in the .debug_types section,
6158 and initialize all_type_units.
6159 The result is zero if there is an error (e.g. missing .debug_types section),
6160 otherwise non-zero. */
6163 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6167 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6168 &dwarf2_per_objfile
->info
, types_htab
,
6169 rcuh_kind::COMPILE
);
6170 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6171 dwarf2_per_objfile
->types
, types_htab
);
6172 if (types_htab
== NULL
)
6174 dwarf2_per_objfile
->signatured_types
= NULL
;
6178 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6180 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6181 dwarf2_per_objfile
->all_type_units
.reserve
6182 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6184 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6185 add_signatured_type_cu_to_table
,
6186 &dwarf2_per_objfile
->all_type_units
);
6191 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6192 If SLOT is non-NULL, it is the entry to use in the hash table.
6193 Otherwise we find one. */
6195 static struct signatured_type
*
6196 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6199 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6201 if (dwarf2_per_objfile
->all_type_units
.size ()
6202 == dwarf2_per_objfile
->all_type_units
.capacity ())
6203 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6205 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6206 struct signatured_type
);
6208 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6209 sig_type
->signature
= sig
;
6210 sig_type
->per_cu
.is_debug_types
= 1;
6211 if (dwarf2_per_objfile
->using_index
)
6213 sig_type
->per_cu
.v
.quick
=
6214 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6215 struct dwarf2_per_cu_quick_data
);
6220 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6223 gdb_assert (*slot
== NULL
);
6225 /* The rest of sig_type must be filled in by the caller. */
6229 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6230 Fill in SIG_ENTRY with DWO_ENTRY. */
6233 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6234 struct signatured_type
*sig_entry
,
6235 struct dwo_unit
*dwo_entry
)
6237 /* Make sure we're not clobbering something we don't expect to. */
6238 gdb_assert (! sig_entry
->per_cu
.queued
);
6239 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6240 if (dwarf2_per_objfile
->using_index
)
6242 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6243 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6246 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6247 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6248 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6249 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6250 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6252 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6253 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6254 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6255 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6256 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6257 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6258 sig_entry
->dwo_unit
= dwo_entry
;
6261 /* Subroutine of lookup_signatured_type.
6262 If we haven't read the TU yet, create the signatured_type data structure
6263 for a TU to be read in directly from a DWO file, bypassing the stub.
6264 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6265 using .gdb_index, then when reading a CU we want to stay in the DWO file
6266 containing that CU. Otherwise we could end up reading several other DWO
6267 files (due to comdat folding) to process the transitive closure of all the
6268 mentioned TUs, and that can be slow. The current DWO file will have every
6269 type signature that it needs.
6270 We only do this for .gdb_index because in the psymtab case we already have
6271 to read all the DWOs to build the type unit groups. */
6273 static struct signatured_type
*
6274 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6276 struct dwarf2_per_objfile
*dwarf2_per_objfile
6277 = cu
->per_cu
->dwarf2_per_objfile
;
6278 struct dwo_file
*dwo_file
;
6279 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6280 struct signatured_type find_sig_entry
, *sig_entry
;
6283 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6285 /* If TU skeletons have been removed then we may not have read in any
6287 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6288 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6290 /* We only ever need to read in one copy of a signatured type.
6291 Use the global signatured_types array to do our own comdat-folding
6292 of types. If this is the first time we're reading this TU, and
6293 the TU has an entry in .gdb_index, replace the recorded data from
6294 .gdb_index with this TU. */
6296 find_sig_entry
.signature
= sig
;
6297 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6298 &find_sig_entry
, INSERT
);
6299 sig_entry
= (struct signatured_type
*) *slot
;
6301 /* We can get here with the TU already read, *or* in the process of being
6302 read. Don't reassign the global entry to point to this DWO if that's
6303 the case. Also note that if the TU is already being read, it may not
6304 have come from a DWO, the program may be a mix of Fission-compiled
6305 code and non-Fission-compiled code. */
6307 /* Have we already tried to read this TU?
6308 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6309 needn't exist in the global table yet). */
6310 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6313 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6314 dwo_unit of the TU itself. */
6315 dwo_file
= cu
->dwo_unit
->dwo_file
;
6317 /* Ok, this is the first time we're reading this TU. */
6318 if (dwo_file
->tus
== NULL
)
6320 find_dwo_entry
.signature
= sig
;
6321 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6323 if (dwo_entry
== NULL
)
6326 /* If the global table doesn't have an entry for this TU, add one. */
6327 if (sig_entry
== NULL
)
6328 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6330 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6331 sig_entry
->per_cu
.tu_read
= 1;
6335 /* Subroutine of lookup_signatured_type.
6336 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6337 then try the DWP file. If the TU stub (skeleton) has been removed then
6338 it won't be in .gdb_index. */
6340 static struct signatured_type
*
6341 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6343 struct dwarf2_per_objfile
*dwarf2_per_objfile
6344 = cu
->per_cu
->dwarf2_per_objfile
;
6345 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6346 struct dwo_unit
*dwo_entry
;
6347 struct signatured_type find_sig_entry
, *sig_entry
;
6350 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6351 gdb_assert (dwp_file
!= NULL
);
6353 /* If TU skeletons have been removed then we may not have read in any
6355 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6356 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6358 find_sig_entry
.signature
= sig
;
6359 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6360 &find_sig_entry
, INSERT
);
6361 sig_entry
= (struct signatured_type
*) *slot
;
6363 /* Have we already tried to read this TU?
6364 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6365 needn't exist in the global table yet). */
6366 if (sig_entry
!= NULL
)
6369 if (dwp_file
->tus
== NULL
)
6371 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6372 sig
, 1 /* is_debug_types */);
6373 if (dwo_entry
== NULL
)
6376 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6377 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6382 /* Lookup a signature based type for DW_FORM_ref_sig8.
6383 Returns NULL if signature SIG is not present in the table.
6384 It is up to the caller to complain about this. */
6386 static struct signatured_type
*
6387 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6389 struct dwarf2_per_objfile
*dwarf2_per_objfile
6390 = cu
->per_cu
->dwarf2_per_objfile
;
6393 && dwarf2_per_objfile
->using_index
)
6395 /* We're in a DWO/DWP file, and we're using .gdb_index.
6396 These cases require special processing. */
6397 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6398 return lookup_dwo_signatured_type (cu
, sig
);
6400 return lookup_dwp_signatured_type (cu
, sig
);
6404 struct signatured_type find_entry
, *entry
;
6406 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6408 find_entry
.signature
= sig
;
6409 entry
= ((struct signatured_type
*)
6410 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6416 /* Return the address base of the compile unit, which, if exists, is stored
6417 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6418 static gdb::optional
<ULONGEST
>
6419 lookup_addr_base (struct die_info
*comp_unit_die
)
6421 struct attribute
*attr
;
6422 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6423 if (attr
== nullptr)
6424 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6425 if (attr
== nullptr)
6426 return gdb::optional
<ULONGEST
> ();
6427 return DW_UNSND (attr
);
6430 /* Return range lists base of the compile unit, which, if exists, is stored
6431 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6433 lookup_ranges_base (struct die_info
*comp_unit_die
)
6435 struct attribute
*attr
;
6436 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6437 if (attr
== nullptr)
6438 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6439 if (attr
== nullptr)
6441 return DW_UNSND (attr
);
6444 /* Low level DIE reading support. */
6446 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6449 init_cu_die_reader (struct die_reader_specs
*reader
,
6450 struct dwarf2_cu
*cu
,
6451 struct dwarf2_section_info
*section
,
6452 struct dwo_file
*dwo_file
,
6453 struct abbrev_table
*abbrev_table
)
6455 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6456 reader
->abfd
= section
->get_bfd_owner ();
6458 reader
->dwo_file
= dwo_file
;
6459 reader
->die_section
= section
;
6460 reader
->buffer
= section
->buffer
;
6461 reader
->buffer_end
= section
->buffer
+ section
->size
;
6462 reader
->abbrev_table
= abbrev_table
;
6465 /* Subroutine of cutu_reader to simplify it.
6466 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6467 There's just a lot of work to do, and cutu_reader is big enough
6470 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6471 from it to the DIE in the DWO. If NULL we are skipping the stub.
6472 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6473 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6474 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6475 STUB_COMP_DIR may be non-NULL.
6476 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6477 are filled in with the info of the DIE from the DWO file.
6478 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6479 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6480 kept around for at least as long as *RESULT_READER.
6482 The result is non-zero if a valid (non-dummy) DIE was found. */
6485 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6486 struct dwo_unit
*dwo_unit
,
6487 struct die_info
*stub_comp_unit_die
,
6488 const char *stub_comp_dir
,
6489 struct die_reader_specs
*result_reader
,
6490 const gdb_byte
**result_info_ptr
,
6491 struct die_info
**result_comp_unit_die
,
6492 abbrev_table_up
*result_dwo_abbrev_table
)
6494 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6495 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6496 struct dwarf2_cu
*cu
= this_cu
->cu
;
6498 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6499 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6500 int i
,num_extra_attrs
;
6501 struct dwarf2_section_info
*dwo_abbrev_section
;
6502 struct die_info
*comp_unit_die
;
6504 /* At most one of these may be provided. */
6505 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6507 /* These attributes aren't processed until later:
6508 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6509 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6510 referenced later. However, these attributes are found in the stub
6511 which we won't have later. In order to not impose this complication
6512 on the rest of the code, we read them here and copy them to the
6521 if (stub_comp_unit_die
!= NULL
)
6523 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6525 if (! this_cu
->is_debug_types
)
6526 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6527 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6528 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6529 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6530 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6532 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6534 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6535 here (if needed). We need the value before we can process
6537 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6539 else if (stub_comp_dir
!= NULL
)
6541 /* Reconstruct the comp_dir attribute to simplify the code below. */
6542 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6543 comp_dir
->name
= DW_AT_comp_dir
;
6544 comp_dir
->form
= DW_FORM_string
;
6545 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6546 DW_STRING (comp_dir
) = stub_comp_dir
;
6549 /* Set up for reading the DWO CU/TU. */
6550 cu
->dwo_unit
= dwo_unit
;
6551 dwarf2_section_info
*section
= dwo_unit
->section
;
6552 section
->read (objfile
);
6553 abfd
= section
->get_bfd_owner ();
6554 begin_info_ptr
= info_ptr
= (section
->buffer
6555 + to_underlying (dwo_unit
->sect_off
));
6556 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6558 if (this_cu
->is_debug_types
)
6560 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6562 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6563 &cu
->header
, section
,
6565 info_ptr
, rcuh_kind::TYPE
);
6566 /* This is not an assert because it can be caused by bad debug info. */
6567 if (sig_type
->signature
!= cu
->header
.signature
)
6569 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6570 " TU at offset %s [in module %s]"),
6571 hex_string (sig_type
->signature
),
6572 hex_string (cu
->header
.signature
),
6573 sect_offset_str (dwo_unit
->sect_off
),
6574 bfd_get_filename (abfd
));
6576 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6577 /* For DWOs coming from DWP files, we don't know the CU length
6578 nor the type's offset in the TU until now. */
6579 dwo_unit
->length
= cu
->header
.get_length ();
6580 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6582 /* Establish the type offset that can be used to lookup the type.
6583 For DWO files, we don't know it until now. */
6584 sig_type
->type_offset_in_section
6585 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6589 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6590 &cu
->header
, section
,
6592 info_ptr
, rcuh_kind::COMPILE
);
6593 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6594 /* For DWOs coming from DWP files, we don't know the CU length
6596 dwo_unit
->length
= cu
->header
.get_length ();
6599 *result_dwo_abbrev_table
6600 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6601 cu
->header
.abbrev_sect_off
);
6602 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6603 result_dwo_abbrev_table
->get ());
6605 /* Read in the die, but leave space to copy over the attributes
6606 from the stub. This has the benefit of simplifying the rest of
6607 the code - all the work to maintain the illusion of a single
6608 DW_TAG_{compile,type}_unit DIE is done here. */
6609 num_extra_attrs
= ((stmt_list
!= NULL
)
6613 + (comp_dir
!= NULL
));
6614 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6617 /* Copy over the attributes from the stub to the DIE we just read in. */
6618 comp_unit_die
= *result_comp_unit_die
;
6619 i
= comp_unit_die
->num_attrs
;
6620 if (stmt_list
!= NULL
)
6621 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6623 comp_unit_die
->attrs
[i
++] = *low_pc
;
6624 if (high_pc
!= NULL
)
6625 comp_unit_die
->attrs
[i
++] = *high_pc
;
6627 comp_unit_die
->attrs
[i
++] = *ranges
;
6628 if (comp_dir
!= NULL
)
6629 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6630 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6632 if (dwarf_die_debug
)
6634 fprintf_unfiltered (gdb_stdlog
,
6635 "Read die from %s@0x%x of %s:\n",
6636 section
->get_name (),
6637 (unsigned) (begin_info_ptr
- section
->buffer
),
6638 bfd_get_filename (abfd
));
6639 dump_die (comp_unit_die
, dwarf_die_debug
);
6642 /* Skip dummy compilation units. */
6643 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6644 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6647 *result_info_ptr
= info_ptr
;
6651 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6652 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6653 signature is part of the header. */
6654 static gdb::optional
<ULONGEST
>
6655 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6657 if (cu
->header
.version
>= 5)
6658 return cu
->header
.signature
;
6659 struct attribute
*attr
;
6660 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6661 if (attr
== nullptr)
6662 return gdb::optional
<ULONGEST
> ();
6663 return DW_UNSND (attr
);
6666 /* Subroutine of cutu_reader to simplify it.
6667 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6668 Returns NULL if the specified DWO unit cannot be found. */
6670 static struct dwo_unit
*
6671 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6672 struct die_info
*comp_unit_die
,
6673 const char *dwo_name
)
6675 struct dwarf2_cu
*cu
= this_cu
->cu
;
6676 struct dwo_unit
*dwo_unit
;
6677 const char *comp_dir
;
6679 gdb_assert (cu
!= NULL
);
6681 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6682 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6683 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6685 if (this_cu
->is_debug_types
)
6687 struct signatured_type
*sig_type
;
6689 /* Since this_cu is the first member of struct signatured_type,
6690 we can go from a pointer to one to a pointer to the other. */
6691 sig_type
= (struct signatured_type
*) this_cu
;
6692 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6696 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6697 if (!signature
.has_value ())
6698 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6700 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6701 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6708 /* Subroutine of cutu_reader to simplify it.
6709 See it for a description of the parameters.
6710 Read a TU directly from a DWO file, bypassing the stub. */
6713 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6714 int use_existing_cu
)
6716 struct signatured_type
*sig_type
;
6717 struct die_reader_specs reader
;
6719 /* Verify we can do the following downcast, and that we have the
6721 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6722 sig_type
= (struct signatured_type
*) this_cu
;
6723 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6725 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6727 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6728 /* There's no need to do the rereading_dwo_cu handling that
6729 cutu_reader does since we don't read the stub. */
6733 /* If !use_existing_cu, this_cu->cu must be NULL. */
6734 gdb_assert (this_cu
->cu
== NULL
);
6735 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6738 /* A future optimization, if needed, would be to use an existing
6739 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6740 could share abbrev tables. */
6742 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6743 NULL
/* stub_comp_unit_die */,
6744 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6747 &m_dwo_abbrev_table
) == 0)
6754 /* Initialize a CU (or TU) and read its DIEs.
6755 If the CU defers to a DWO file, read the DWO file as well.
6757 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6758 Otherwise the table specified in the comp unit header is read in and used.
6759 This is an optimization for when we already have the abbrev table.
6761 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6762 Otherwise, a new CU is allocated with xmalloc. */
6764 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6765 struct abbrev_table
*abbrev_table
,
6766 int use_existing_cu
,
6768 : die_reader_specs
{},
6771 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6772 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6773 struct dwarf2_section_info
*section
= this_cu
->section
;
6774 bfd
*abfd
= section
->get_bfd_owner ();
6775 struct dwarf2_cu
*cu
;
6776 const gdb_byte
*begin_info_ptr
;
6777 struct signatured_type
*sig_type
= NULL
;
6778 struct dwarf2_section_info
*abbrev_section
;
6779 /* Non-zero if CU currently points to a DWO file and we need to
6780 reread it. When this happens we need to reread the skeleton die
6781 before we can reread the DWO file (this only applies to CUs, not TUs). */
6782 int rereading_dwo_cu
= 0;
6784 if (dwarf_die_debug
)
6785 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6786 this_cu
->is_debug_types
? "type" : "comp",
6787 sect_offset_str (this_cu
->sect_off
));
6789 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6790 file (instead of going through the stub), short-circuit all of this. */
6791 if (this_cu
->reading_dwo_directly
)
6793 /* Narrow down the scope of possibilities to have to understand. */
6794 gdb_assert (this_cu
->is_debug_types
);
6795 gdb_assert (abbrev_table
== NULL
);
6796 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6800 /* This is cheap if the section is already read in. */
6801 section
->read (objfile
);
6803 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6805 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6807 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6810 /* If this CU is from a DWO file we need to start over, we need to
6811 refetch the attributes from the skeleton CU.
6812 This could be optimized by retrieving those attributes from when we
6813 were here the first time: the previous comp_unit_die was stored in
6814 comp_unit_obstack. But there's no data yet that we need this
6816 if (cu
->dwo_unit
!= NULL
)
6817 rereading_dwo_cu
= 1;
6821 /* If !use_existing_cu, this_cu->cu must be NULL. */
6822 gdb_assert (this_cu
->cu
== NULL
);
6823 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6824 cu
= m_new_cu
.get ();
6827 /* Get the header. */
6828 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6830 /* We already have the header, there's no need to read it in again. */
6831 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6835 if (this_cu
->is_debug_types
)
6837 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6838 &cu
->header
, section
,
6839 abbrev_section
, info_ptr
,
6842 /* Since per_cu is the first member of struct signatured_type,
6843 we can go from a pointer to one to a pointer to the other. */
6844 sig_type
= (struct signatured_type
*) this_cu
;
6845 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6846 gdb_assert (sig_type
->type_offset_in_tu
6847 == cu
->header
.type_cu_offset_in_tu
);
6848 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6850 /* LENGTH has not been set yet for type units if we're
6851 using .gdb_index. */
6852 this_cu
->length
= cu
->header
.get_length ();
6854 /* Establish the type offset that can be used to lookup the type. */
6855 sig_type
->type_offset_in_section
=
6856 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6858 this_cu
->dwarf_version
= cu
->header
.version
;
6862 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6863 &cu
->header
, section
,
6866 rcuh_kind::COMPILE
);
6868 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6869 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6870 this_cu
->dwarf_version
= cu
->header
.version
;
6874 /* Skip dummy compilation units. */
6875 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6876 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6882 /* If we don't have them yet, read the abbrevs for this compilation unit.
6883 And if we need to read them now, make sure they're freed when we're
6885 if (abbrev_table
!= NULL
)
6886 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6889 m_abbrev_table_holder
6890 = abbrev_table::read (objfile
, abbrev_section
,
6891 cu
->header
.abbrev_sect_off
);
6892 abbrev_table
= m_abbrev_table_holder
.get ();
6895 /* Read the top level CU/TU die. */
6896 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6897 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6899 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6905 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6906 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6907 table from the DWO file and pass the ownership over to us. It will be
6908 referenced from READER, so we must make sure to free it after we're done
6911 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6912 DWO CU, that this test will fail (the attribute will not be present). */
6913 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6914 if (dwo_name
!= nullptr)
6916 struct dwo_unit
*dwo_unit
;
6917 struct die_info
*dwo_comp_unit_die
;
6919 if (comp_unit_die
->has_children
)
6921 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6922 " has children (offset %s) [in module %s]"),
6923 sect_offset_str (this_cu
->sect_off
),
6924 bfd_get_filename (abfd
));
6926 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6927 if (dwo_unit
!= NULL
)
6929 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6930 comp_unit_die
, NULL
,
6933 &m_dwo_abbrev_table
) == 0)
6939 comp_unit_die
= dwo_comp_unit_die
;
6943 /* Yikes, we couldn't find the rest of the DIE, we only have
6944 the stub. A complaint has already been logged. There's
6945 not much more we can do except pass on the stub DIE to
6946 die_reader_func. We don't want to throw an error on bad
6953 cutu_reader::keep ()
6955 /* Done, clean up. */
6956 gdb_assert (!dummy_p
);
6957 if (m_new_cu
!= NULL
)
6959 struct dwarf2_per_objfile
*dwarf2_per_objfile
6960 = m_this_cu
->dwarf2_per_objfile
;
6961 /* Link this CU into read_in_chain. */
6962 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6963 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6964 /* The chain owns it now. */
6965 m_new_cu
.release ();
6969 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6970 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6971 assumed to have already done the lookup to find the DWO file).
6973 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6974 THIS_CU->is_debug_types, but nothing else.
6976 We fill in THIS_CU->length.
6978 THIS_CU->cu is always freed when done.
6979 This is done in order to not leave THIS_CU->cu in a state where we have
6980 to care whether it refers to the "main" CU or the DWO CU.
6982 When parent_cu is passed, it is used to provide a default value for
6983 str_offsets_base and addr_base from the parent. */
6985 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6986 struct dwarf2_cu
*parent_cu
,
6987 struct dwo_file
*dwo_file
)
6988 : die_reader_specs
{},
6991 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6992 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6993 struct dwarf2_section_info
*section
= this_cu
->section
;
6994 bfd
*abfd
= section
->get_bfd_owner ();
6995 struct dwarf2_section_info
*abbrev_section
;
6996 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6998 if (dwarf_die_debug
)
6999 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7000 this_cu
->is_debug_types
? "type" : "comp",
7001 sect_offset_str (this_cu
->sect_off
));
7003 gdb_assert (this_cu
->cu
== NULL
);
7005 abbrev_section
= (dwo_file
!= NULL
7006 ? &dwo_file
->sections
.abbrev
7007 : get_abbrev_section_for_cu (this_cu
));
7009 /* This is cheap if the section is already read in. */
7010 section
->read (objfile
);
7012 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7014 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7015 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7016 &m_new_cu
->header
, section
,
7017 abbrev_section
, info_ptr
,
7018 (this_cu
->is_debug_types
7020 : rcuh_kind::COMPILE
));
7022 if (parent_cu
!= nullptr)
7024 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7025 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7027 this_cu
->length
= m_new_cu
->header
.get_length ();
7029 /* Skip dummy compilation units. */
7030 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7031 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7037 m_abbrev_table_holder
7038 = abbrev_table::read (objfile
, abbrev_section
,
7039 m_new_cu
->header
.abbrev_sect_off
);
7041 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7042 m_abbrev_table_holder
.get ());
7043 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7047 /* Type Unit Groups.
7049 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7050 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7051 so that all types coming from the same compilation (.o file) are grouped
7052 together. A future step could be to put the types in the same symtab as
7053 the CU the types ultimately came from. */
7056 hash_type_unit_group (const void *item
)
7058 const struct type_unit_group
*tu_group
7059 = (const struct type_unit_group
*) item
;
7061 return hash_stmt_list_entry (&tu_group
->hash
);
7065 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7067 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7068 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7070 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7073 /* Allocate a hash table for type unit groups. */
7076 allocate_type_unit_groups_table ()
7078 return htab_up (htab_create_alloc (3,
7079 hash_type_unit_group
,
7081 NULL
, xcalloc
, xfree
));
7084 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7085 partial symtabs. We combine several TUs per psymtab to not let the size
7086 of any one psymtab grow too big. */
7087 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7088 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7090 /* Helper routine for get_type_unit_group.
7091 Create the type_unit_group object used to hold one or more TUs. */
7093 static struct type_unit_group
*
7094 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7096 struct dwarf2_per_objfile
*dwarf2_per_objfile
7097 = cu
->per_cu
->dwarf2_per_objfile
;
7098 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7099 struct dwarf2_per_cu_data
*per_cu
;
7100 struct type_unit_group
*tu_group
;
7102 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7103 struct type_unit_group
);
7104 per_cu
= &tu_group
->per_cu
;
7105 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7107 if (dwarf2_per_objfile
->using_index
)
7109 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7110 struct dwarf2_per_cu_quick_data
);
7114 unsigned int line_offset
= to_underlying (line_offset_struct
);
7115 dwarf2_psymtab
*pst
;
7118 /* Give the symtab a useful name for debug purposes. */
7119 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7120 name
= string_printf ("<type_units_%d>",
7121 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7123 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7125 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7126 pst
->anonymous
= true;
7129 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7130 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7135 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7136 STMT_LIST is a DW_AT_stmt_list attribute. */
7138 static struct type_unit_group
*
7139 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7141 struct dwarf2_per_objfile
*dwarf2_per_objfile
7142 = cu
->per_cu
->dwarf2_per_objfile
;
7143 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7144 struct type_unit_group
*tu_group
;
7146 unsigned int line_offset
;
7147 struct type_unit_group type_unit_group_for_lookup
;
7149 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7150 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7152 /* Do we need to create a new group, or can we use an existing one? */
7156 line_offset
= DW_UNSND (stmt_list
);
7157 ++tu_stats
->nr_symtab_sharers
;
7161 /* Ugh, no stmt_list. Rare, but we have to handle it.
7162 We can do various things here like create one group per TU or
7163 spread them over multiple groups to split up the expansion work.
7164 To avoid worst case scenarios (too many groups or too large groups)
7165 we, umm, group them in bunches. */
7166 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7167 | (tu_stats
->nr_stmt_less_type_units
7168 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7169 ++tu_stats
->nr_stmt_less_type_units
;
7172 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7173 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7174 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7175 &type_unit_group_for_lookup
, INSERT
);
7178 tu_group
= (struct type_unit_group
*) *slot
;
7179 gdb_assert (tu_group
!= NULL
);
7183 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7184 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7186 ++tu_stats
->nr_symtabs
;
7192 /* Partial symbol tables. */
7194 /* Create a psymtab named NAME and assign it to PER_CU.
7196 The caller must fill in the following details:
7197 dirname, textlow, texthigh. */
7199 static dwarf2_psymtab
*
7200 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7202 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7203 dwarf2_psymtab
*pst
;
7205 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7207 pst
->psymtabs_addrmap_supported
= true;
7209 /* This is the glue that links PST into GDB's symbol API. */
7210 pst
->per_cu_data
= per_cu
;
7211 per_cu
->v
.psymtab
= pst
;
7216 /* DIE reader function for process_psymtab_comp_unit. */
7219 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7220 const gdb_byte
*info_ptr
,
7221 struct die_info
*comp_unit_die
,
7222 enum language pretend_language
)
7224 struct dwarf2_cu
*cu
= reader
->cu
;
7225 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7226 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7227 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7229 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7230 dwarf2_psymtab
*pst
;
7231 enum pc_bounds_kind cu_bounds_kind
;
7232 const char *filename
;
7234 gdb_assert (! per_cu
->is_debug_types
);
7236 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7238 /* Allocate a new partial symbol table structure. */
7239 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7240 static const char artificial
[] = "<artificial>";
7241 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7242 if (filename
== NULL
)
7244 else if (strcmp (filename
, artificial
) == 0)
7246 debug_filename
.reset (concat (artificial
, "@",
7247 sect_offset_str (per_cu
->sect_off
),
7249 filename
= debug_filename
.get ();
7252 pst
= create_partial_symtab (per_cu
, filename
);
7254 /* This must be done before calling dwarf2_build_include_psymtabs. */
7255 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7257 baseaddr
= objfile
->text_section_offset ();
7259 dwarf2_find_base_address (comp_unit_die
, cu
);
7261 /* Possibly set the default values of LOWPC and HIGHPC from
7263 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7264 &best_highpc
, cu
, pst
);
7265 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7268 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7271 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7273 /* Store the contiguous range if it is not empty; it can be
7274 empty for CUs with no code. */
7275 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7279 /* Check if comp unit has_children.
7280 If so, read the rest of the partial symbols from this comp unit.
7281 If not, there's no more debug_info for this comp unit. */
7282 if (comp_unit_die
->has_children
)
7284 struct partial_die_info
*first_die
;
7285 CORE_ADDR lowpc
, highpc
;
7287 lowpc
= ((CORE_ADDR
) -1);
7288 highpc
= ((CORE_ADDR
) 0);
7290 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7292 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7293 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7295 /* If we didn't find a lowpc, set it to highpc to avoid
7296 complaints from `maint check'. */
7297 if (lowpc
== ((CORE_ADDR
) -1))
7300 /* If the compilation unit didn't have an explicit address range,
7301 then use the information extracted from its child dies. */
7302 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7305 best_highpc
= highpc
;
7308 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7309 best_lowpc
+ baseaddr
)
7311 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7312 best_highpc
+ baseaddr
)
7315 end_psymtab_common (objfile
, pst
);
7317 if (!cu
->per_cu
->imported_symtabs_empty ())
7320 int len
= cu
->per_cu
->imported_symtabs_size ();
7322 /* Fill in 'dependencies' here; we fill in 'users' in a
7324 pst
->number_of_dependencies
= len
;
7326 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7327 for (i
= 0; i
< len
; ++i
)
7329 pst
->dependencies
[i
]
7330 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7333 cu
->per_cu
->imported_symtabs_free ();
7336 /* Get the list of files included in the current compilation unit,
7337 and build a psymtab for each of them. */
7338 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7340 if (dwarf_read_debug
)
7341 fprintf_unfiltered (gdb_stdlog
,
7342 "Psymtab for %s unit @%s: %s - %s"
7343 ", %d global, %d static syms\n",
7344 per_cu
->is_debug_types
? "type" : "comp",
7345 sect_offset_str (per_cu
->sect_off
),
7346 paddress (gdbarch
, pst
->text_low (objfile
)),
7347 paddress (gdbarch
, pst
->text_high (objfile
)),
7348 pst
->n_global_syms
, pst
->n_static_syms
);
7351 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7352 Process compilation unit THIS_CU for a psymtab. */
7355 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7356 bool want_partial_unit
,
7357 enum language pretend_language
)
7359 /* If this compilation unit was already read in, free the
7360 cached copy in order to read it in again. This is
7361 necessary because we skipped some symbols when we first
7362 read in the compilation unit (see load_partial_dies).
7363 This problem could be avoided, but the benefit is unclear. */
7364 if (this_cu
->cu
!= NULL
)
7365 free_one_cached_comp_unit (this_cu
);
7367 cutu_reader
reader (this_cu
, NULL
, 0, false);
7373 else if (this_cu
->is_debug_types
)
7374 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7375 reader
.comp_unit_die
);
7376 else if (want_partial_unit
7377 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7378 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7379 reader
.comp_unit_die
,
7382 /* Age out any secondary CUs. */
7383 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7386 /* Reader function for build_type_psymtabs. */
7389 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7390 const gdb_byte
*info_ptr
,
7391 struct die_info
*type_unit_die
)
7393 struct dwarf2_per_objfile
*dwarf2_per_objfile
7394 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7395 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7396 struct dwarf2_cu
*cu
= reader
->cu
;
7397 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7398 struct signatured_type
*sig_type
;
7399 struct type_unit_group
*tu_group
;
7400 struct attribute
*attr
;
7401 struct partial_die_info
*first_die
;
7402 CORE_ADDR lowpc
, highpc
;
7403 dwarf2_psymtab
*pst
;
7405 gdb_assert (per_cu
->is_debug_types
);
7406 sig_type
= (struct signatured_type
*) per_cu
;
7408 if (! type_unit_die
->has_children
)
7411 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7412 tu_group
= get_type_unit_group (cu
, attr
);
7414 if (tu_group
->tus
== nullptr)
7415 tu_group
->tus
= new std::vector
<signatured_type
*>;
7416 tu_group
->tus
->push_back (sig_type
);
7418 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7419 pst
= create_partial_symtab (per_cu
, "");
7420 pst
->anonymous
= true;
7422 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7424 lowpc
= (CORE_ADDR
) -1;
7425 highpc
= (CORE_ADDR
) 0;
7426 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7428 end_psymtab_common (objfile
, pst
);
7431 /* Struct used to sort TUs by their abbreviation table offset. */
7433 struct tu_abbrev_offset
7435 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7436 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7439 signatured_type
*sig_type
;
7440 sect_offset abbrev_offset
;
7443 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7446 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7447 const struct tu_abbrev_offset
&b
)
7449 return a
.abbrev_offset
< b
.abbrev_offset
;
7452 /* Efficiently read all the type units.
7453 This does the bulk of the work for build_type_psymtabs.
7455 The efficiency is because we sort TUs by the abbrev table they use and
7456 only read each abbrev table once. In one program there are 200K TUs
7457 sharing 8K abbrev tables.
7459 The main purpose of this function is to support building the
7460 dwarf2_per_objfile->type_unit_groups table.
7461 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7462 can collapse the search space by grouping them by stmt_list.
7463 The savings can be significant, in the same program from above the 200K TUs
7464 share 8K stmt_list tables.
7466 FUNC is expected to call get_type_unit_group, which will create the
7467 struct type_unit_group if necessary and add it to
7468 dwarf2_per_objfile->type_unit_groups. */
7471 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7473 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7474 abbrev_table_up abbrev_table
;
7475 sect_offset abbrev_offset
;
7477 /* It's up to the caller to not call us multiple times. */
7478 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7480 if (dwarf2_per_objfile
->all_type_units
.empty ())
7483 /* TUs typically share abbrev tables, and there can be way more TUs than
7484 abbrev tables. Sort by abbrev table to reduce the number of times we
7485 read each abbrev table in.
7486 Alternatives are to punt or to maintain a cache of abbrev tables.
7487 This is simpler and efficient enough for now.
7489 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7490 symtab to use). Typically TUs with the same abbrev offset have the same
7491 stmt_list value too so in practice this should work well.
7493 The basic algorithm here is:
7495 sort TUs by abbrev table
7496 for each TU with same abbrev table:
7497 read abbrev table if first user
7498 read TU top level DIE
7499 [IWBN if DWO skeletons had DW_AT_stmt_list]
7502 if (dwarf_read_debug
)
7503 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7505 /* Sort in a separate table to maintain the order of all_type_units
7506 for .gdb_index: TU indices directly index all_type_units. */
7507 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7508 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7510 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7511 sorted_by_abbrev
.emplace_back
7512 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7513 sig_type
->per_cu
.section
,
7514 sig_type
->per_cu
.sect_off
));
7516 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7517 sort_tu_by_abbrev_offset
);
7519 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7521 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7523 /* Switch to the next abbrev table if necessary. */
7524 if (abbrev_table
== NULL
7525 || tu
.abbrev_offset
!= abbrev_offset
)
7527 abbrev_offset
= tu
.abbrev_offset
;
7529 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7530 &dwarf2_per_objfile
->abbrev
,
7532 ++tu_stats
->nr_uniq_abbrev_tables
;
7535 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7537 if (!reader
.dummy_p
)
7538 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7539 reader
.comp_unit_die
);
7543 /* Print collected type unit statistics. */
7546 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7548 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7550 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7551 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7552 dwarf2_per_objfile
->all_type_units
.size ());
7553 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7554 tu_stats
->nr_uniq_abbrev_tables
);
7555 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7556 tu_stats
->nr_symtabs
);
7557 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7558 tu_stats
->nr_symtab_sharers
);
7559 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7560 tu_stats
->nr_stmt_less_type_units
);
7561 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7562 tu_stats
->nr_all_type_units_reallocs
);
7565 /* Traversal function for build_type_psymtabs. */
7568 build_type_psymtab_dependencies (void **slot
, void *info
)
7570 struct dwarf2_per_objfile
*dwarf2_per_objfile
7571 = (struct dwarf2_per_objfile
*) info
;
7572 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7573 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7574 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7575 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7576 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7579 gdb_assert (len
> 0);
7580 gdb_assert (per_cu
->type_unit_group_p ());
7582 pst
->number_of_dependencies
= len
;
7583 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7584 for (i
= 0; i
< len
; ++i
)
7586 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7587 gdb_assert (iter
->per_cu
.is_debug_types
);
7588 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7589 iter
->type_unit_group
= tu_group
;
7592 delete tu_group
->tus
;
7593 tu_group
->tus
= nullptr;
7598 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7599 Build partial symbol tables for the .debug_types comp-units. */
7602 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7604 if (! create_all_type_units (dwarf2_per_objfile
))
7607 build_type_psymtabs_1 (dwarf2_per_objfile
);
7610 /* Traversal function for process_skeletonless_type_unit.
7611 Read a TU in a DWO file and build partial symbols for it. */
7614 process_skeletonless_type_unit (void **slot
, void *info
)
7616 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7617 struct dwarf2_per_objfile
*dwarf2_per_objfile
7618 = (struct dwarf2_per_objfile
*) info
;
7619 struct signatured_type find_entry
, *entry
;
7621 /* If this TU doesn't exist in the global table, add it and read it in. */
7623 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7624 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7626 find_entry
.signature
= dwo_unit
->signature
;
7627 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7628 &find_entry
, INSERT
);
7629 /* If we've already seen this type there's nothing to do. What's happening
7630 is we're doing our own version of comdat-folding here. */
7634 /* This does the job that create_all_type_units would have done for
7636 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7637 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7640 /* This does the job that build_type_psymtabs_1 would have done. */
7641 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7642 if (!reader
.dummy_p
)
7643 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7644 reader
.comp_unit_die
);
7649 /* Traversal function for process_skeletonless_type_units. */
7652 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7654 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7656 if (dwo_file
->tus
!= NULL
)
7657 htab_traverse_noresize (dwo_file
->tus
.get (),
7658 process_skeletonless_type_unit
, info
);
7663 /* Scan all TUs of DWO files, verifying we've processed them.
7664 This is needed in case a TU was emitted without its skeleton.
7665 Note: This can't be done until we know what all the DWO files are. */
7668 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7670 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7671 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7672 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7674 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7675 process_dwo_file_for_skeletonless_type_units
,
7676 dwarf2_per_objfile
);
7680 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7683 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7685 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7687 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7692 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7694 /* Set the 'user' field only if it is not already set. */
7695 if (pst
->dependencies
[j
]->user
== NULL
)
7696 pst
->dependencies
[j
]->user
= pst
;
7701 /* Build the partial symbol table by doing a quick pass through the
7702 .debug_info and .debug_abbrev sections. */
7705 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7707 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7709 if (dwarf_read_debug
)
7711 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7712 objfile_name (objfile
));
7715 scoped_restore restore_reading_psyms
7716 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7719 dwarf2_per_objfile
->info
.read (objfile
);
7721 /* Any cached compilation units will be linked by the per-objfile
7722 read_in_chain. Make sure to free them when we're done. */
7723 free_cached_comp_units
freer (dwarf2_per_objfile
);
7725 build_type_psymtabs (dwarf2_per_objfile
);
7727 create_all_comp_units (dwarf2_per_objfile
);
7729 /* Create a temporary address map on a temporary obstack. We later
7730 copy this to the final obstack. */
7731 auto_obstack temp_obstack
;
7733 scoped_restore save_psymtabs_addrmap
7734 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7735 addrmap_create_mutable (&temp_obstack
));
7737 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7738 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7740 /* This has to wait until we read the CUs, we need the list of DWOs. */
7741 process_skeletonless_type_units (dwarf2_per_objfile
);
7743 /* Now that all TUs have been processed we can fill in the dependencies. */
7744 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7746 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7747 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7750 if (dwarf_read_debug
)
7751 print_tu_stats (dwarf2_per_objfile
);
7753 set_partial_user (dwarf2_per_objfile
);
7755 objfile
->partial_symtabs
->psymtabs_addrmap
7756 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7757 objfile
->partial_symtabs
->obstack ());
7758 /* At this point we want to keep the address map. */
7759 save_psymtabs_addrmap
.release ();
7761 if (dwarf_read_debug
)
7762 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7763 objfile_name (objfile
));
7766 /* Load the partial DIEs for a secondary CU into memory.
7767 This is also used when rereading a primary CU with load_all_dies. */
7770 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7772 cutu_reader
reader (this_cu
, NULL
, 1, false);
7774 if (!reader
.dummy_p
)
7776 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7779 /* Check if comp unit has_children.
7780 If so, read the rest of the partial symbols from this comp unit.
7781 If not, there's no more debug_info for this comp unit. */
7782 if (reader
.comp_unit_die
->has_children
)
7783 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7790 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7791 struct dwarf2_section_info
*section
,
7792 struct dwarf2_section_info
*abbrev_section
,
7793 unsigned int is_dwz
)
7795 const gdb_byte
*info_ptr
;
7796 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7798 if (dwarf_read_debug
)
7799 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7800 section
->get_name (),
7801 section
->get_file_name ());
7803 section
->read (objfile
);
7805 info_ptr
= section
->buffer
;
7807 while (info_ptr
< section
->buffer
+ section
->size
)
7809 struct dwarf2_per_cu_data
*this_cu
;
7811 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7813 comp_unit_head cu_header
;
7814 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7815 abbrev_section
, info_ptr
,
7816 rcuh_kind::COMPILE
);
7818 /* Save the compilation unit for later lookup. */
7819 if (cu_header
.unit_type
!= DW_UT_type
)
7821 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7822 struct dwarf2_per_cu_data
);
7823 memset (this_cu
, 0, sizeof (*this_cu
));
7827 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7828 struct signatured_type
);
7829 memset (sig_type
, 0, sizeof (*sig_type
));
7830 sig_type
->signature
= cu_header
.signature
;
7831 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7832 this_cu
= &sig_type
->per_cu
;
7834 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7835 this_cu
->sect_off
= sect_off
;
7836 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7837 this_cu
->is_dwz
= is_dwz
;
7838 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7839 this_cu
->section
= section
;
7841 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7843 info_ptr
= info_ptr
+ this_cu
->length
;
7847 /* Create a list of all compilation units in OBJFILE.
7848 This is only done for -readnow and building partial symtabs. */
7851 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7853 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7854 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7855 &dwarf2_per_objfile
->abbrev
, 0);
7857 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7859 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7863 /* Process all loaded DIEs for compilation unit CU, starting at
7864 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7865 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7866 DW_AT_ranges). See the comments of add_partial_subprogram on how
7867 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7870 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7871 CORE_ADDR
*highpc
, int set_addrmap
,
7872 struct dwarf2_cu
*cu
)
7874 struct partial_die_info
*pdi
;
7876 /* Now, march along the PDI's, descending into ones which have
7877 interesting children but skipping the children of the other ones,
7878 until we reach the end of the compilation unit. */
7886 /* Anonymous namespaces or modules have no name but have interesting
7887 children, so we need to look at them. Ditto for anonymous
7890 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7891 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7892 || pdi
->tag
== DW_TAG_imported_unit
7893 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7897 case DW_TAG_subprogram
:
7898 case DW_TAG_inlined_subroutine
:
7899 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7901 case DW_TAG_constant
:
7902 case DW_TAG_variable
:
7903 case DW_TAG_typedef
:
7904 case DW_TAG_union_type
:
7905 if (!pdi
->is_declaration
)
7907 add_partial_symbol (pdi
, cu
);
7910 case DW_TAG_class_type
:
7911 case DW_TAG_interface_type
:
7912 case DW_TAG_structure_type
:
7913 if (!pdi
->is_declaration
)
7915 add_partial_symbol (pdi
, cu
);
7917 if ((cu
->language
== language_rust
7918 || cu
->language
== language_cplus
) && pdi
->has_children
)
7919 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7922 case DW_TAG_enumeration_type
:
7923 if (!pdi
->is_declaration
)
7924 add_partial_enumeration (pdi
, cu
);
7926 case DW_TAG_base_type
:
7927 case DW_TAG_subrange_type
:
7928 /* File scope base type definitions are added to the partial
7930 add_partial_symbol (pdi
, cu
);
7932 case DW_TAG_namespace
:
7933 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7936 if (!pdi
->is_declaration
)
7937 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7939 case DW_TAG_imported_unit
:
7941 struct dwarf2_per_cu_data
*per_cu
;
7943 /* For now we don't handle imported units in type units. */
7944 if (cu
->per_cu
->is_debug_types
)
7946 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7947 " supported in type units [in module %s]"),
7948 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7951 per_cu
= dwarf2_find_containing_comp_unit
7952 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7953 cu
->per_cu
->dwarf2_per_objfile
);
7955 /* Go read the partial unit, if needed. */
7956 if (per_cu
->v
.psymtab
== NULL
)
7957 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7959 cu
->per_cu
->imported_symtabs_push (per_cu
);
7962 case DW_TAG_imported_declaration
:
7963 add_partial_symbol (pdi
, cu
);
7970 /* If the die has a sibling, skip to the sibling. */
7972 pdi
= pdi
->die_sibling
;
7976 /* Functions used to compute the fully scoped name of a partial DIE.
7978 Normally, this is simple. For C++, the parent DIE's fully scoped
7979 name is concatenated with "::" and the partial DIE's name.
7980 Enumerators are an exception; they use the scope of their parent
7981 enumeration type, i.e. the name of the enumeration type is not
7982 prepended to the enumerator.
7984 There are two complexities. One is DW_AT_specification; in this
7985 case "parent" means the parent of the target of the specification,
7986 instead of the direct parent of the DIE. The other is compilers
7987 which do not emit DW_TAG_namespace; in this case we try to guess
7988 the fully qualified name of structure types from their members'
7989 linkage names. This must be done using the DIE's children rather
7990 than the children of any DW_AT_specification target. We only need
7991 to do this for structures at the top level, i.e. if the target of
7992 any DW_AT_specification (if any; otherwise the DIE itself) does not
7995 /* Compute the scope prefix associated with PDI's parent, in
7996 compilation unit CU. The result will be allocated on CU's
7997 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7998 field. NULL is returned if no prefix is necessary. */
8000 partial_die_parent_scope (struct partial_die_info
*pdi
,
8001 struct dwarf2_cu
*cu
)
8003 const char *grandparent_scope
;
8004 struct partial_die_info
*parent
, *real_pdi
;
8006 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8007 then this means the parent of the specification DIE. */
8010 while (real_pdi
->has_specification
)
8012 auto res
= find_partial_die (real_pdi
->spec_offset
,
8013 real_pdi
->spec_is_dwz
, cu
);
8018 parent
= real_pdi
->die_parent
;
8022 if (parent
->scope_set
)
8023 return parent
->scope
;
8027 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8029 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8030 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8031 Work around this problem here. */
8032 if (cu
->language
== language_cplus
8033 && parent
->tag
== DW_TAG_namespace
8034 && strcmp (parent
->name
, "::") == 0
8035 && grandparent_scope
== NULL
)
8037 parent
->scope
= NULL
;
8038 parent
->scope_set
= 1;
8042 /* Nested subroutines in Fortran get a prefix. */
8043 if (pdi
->tag
== DW_TAG_enumerator
)
8044 /* Enumerators should not get the name of the enumeration as a prefix. */
8045 parent
->scope
= grandparent_scope
;
8046 else if (parent
->tag
== DW_TAG_namespace
8047 || parent
->tag
== DW_TAG_module
8048 || parent
->tag
== DW_TAG_structure_type
8049 || parent
->tag
== DW_TAG_class_type
8050 || parent
->tag
== DW_TAG_interface_type
8051 || parent
->tag
== DW_TAG_union_type
8052 || parent
->tag
== DW_TAG_enumeration_type
8053 || (cu
->language
== language_fortran
8054 && parent
->tag
== DW_TAG_subprogram
8055 && pdi
->tag
== DW_TAG_subprogram
))
8057 if (grandparent_scope
== NULL
)
8058 parent
->scope
= parent
->name
;
8060 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8062 parent
->name
, 0, cu
);
8066 /* FIXME drow/2004-04-01: What should we be doing with
8067 function-local names? For partial symbols, we should probably be
8069 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8070 dwarf_tag_name (parent
->tag
),
8071 sect_offset_str (pdi
->sect_off
));
8072 parent
->scope
= grandparent_scope
;
8075 parent
->scope_set
= 1;
8076 return parent
->scope
;
8079 /* Return the fully scoped name associated with PDI, from compilation unit
8080 CU. The result will be allocated with malloc. */
8082 static gdb::unique_xmalloc_ptr
<char>
8083 partial_die_full_name (struct partial_die_info
*pdi
,
8084 struct dwarf2_cu
*cu
)
8086 const char *parent_scope
;
8088 /* If this is a template instantiation, we can not work out the
8089 template arguments from partial DIEs. So, unfortunately, we have
8090 to go through the full DIEs. At least any work we do building
8091 types here will be reused if full symbols are loaded later. */
8092 if (pdi
->has_template_arguments
)
8096 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8098 struct die_info
*die
;
8099 struct attribute attr
;
8100 struct dwarf2_cu
*ref_cu
= cu
;
8102 /* DW_FORM_ref_addr is using section offset. */
8103 attr
.name
= (enum dwarf_attribute
) 0;
8104 attr
.form
= DW_FORM_ref_addr
;
8105 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8106 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8108 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8112 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8113 if (parent_scope
== NULL
)
8116 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8121 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8123 struct dwarf2_per_objfile
*dwarf2_per_objfile
8124 = cu
->per_cu
->dwarf2_per_objfile
;
8125 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8126 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8128 const char *actual_name
= NULL
;
8131 baseaddr
= objfile
->text_section_offset ();
8133 gdb::unique_xmalloc_ptr
<char> built_actual_name
8134 = partial_die_full_name (pdi
, cu
);
8135 if (built_actual_name
!= NULL
)
8136 actual_name
= built_actual_name
.get ();
8138 if (actual_name
== NULL
)
8139 actual_name
= pdi
->name
;
8143 case DW_TAG_inlined_subroutine
:
8144 case DW_TAG_subprogram
:
8145 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8147 if (pdi
->is_external
8148 || cu
->language
== language_ada
8149 || (cu
->language
== language_fortran
8150 && pdi
->die_parent
!= NULL
8151 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8153 /* Normally, only "external" DIEs are part of the global scope.
8154 But in Ada and Fortran, we want to be able to access nested
8155 procedures globally. So all Ada and Fortran subprograms are
8156 stored in the global scope. */
8157 add_psymbol_to_list (actual_name
,
8158 built_actual_name
!= NULL
,
8159 VAR_DOMAIN
, LOC_BLOCK
,
8160 SECT_OFF_TEXT (objfile
),
8161 psymbol_placement::GLOBAL
,
8163 cu
->language
, objfile
);
8167 add_psymbol_to_list (actual_name
,
8168 built_actual_name
!= NULL
,
8169 VAR_DOMAIN
, LOC_BLOCK
,
8170 SECT_OFF_TEXT (objfile
),
8171 psymbol_placement::STATIC
,
8172 addr
, cu
->language
, objfile
);
8175 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8176 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8178 case DW_TAG_constant
:
8179 add_psymbol_to_list (actual_name
,
8180 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8181 -1, (pdi
->is_external
8182 ? psymbol_placement::GLOBAL
8183 : psymbol_placement::STATIC
),
8184 0, cu
->language
, objfile
);
8186 case DW_TAG_variable
:
8188 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8192 && !dwarf2_per_objfile
->has_section_at_zero
)
8194 /* A global or static variable may also have been stripped
8195 out by the linker if unused, in which case its address
8196 will be nullified; do not add such variables into partial
8197 symbol table then. */
8199 else if (pdi
->is_external
)
8202 Don't enter into the minimal symbol tables as there is
8203 a minimal symbol table entry from the ELF symbols already.
8204 Enter into partial symbol table if it has a location
8205 descriptor or a type.
8206 If the location descriptor is missing, new_symbol will create
8207 a LOC_UNRESOLVED symbol, the address of the variable will then
8208 be determined from the minimal symbol table whenever the variable
8210 The address for the partial symbol table entry is not
8211 used by GDB, but it comes in handy for debugging partial symbol
8214 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8215 add_psymbol_to_list (actual_name
,
8216 built_actual_name
!= NULL
,
8217 VAR_DOMAIN
, LOC_STATIC
,
8218 SECT_OFF_TEXT (objfile
),
8219 psymbol_placement::GLOBAL
,
8220 addr
, cu
->language
, objfile
);
8224 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8226 /* Static Variable. Skip symbols whose value we cannot know (those
8227 without location descriptors or constant values). */
8228 if (!has_loc
&& !pdi
->has_const_value
)
8231 add_psymbol_to_list (actual_name
,
8232 built_actual_name
!= NULL
,
8233 VAR_DOMAIN
, LOC_STATIC
,
8234 SECT_OFF_TEXT (objfile
),
8235 psymbol_placement::STATIC
,
8237 cu
->language
, objfile
);
8240 case DW_TAG_typedef
:
8241 case DW_TAG_base_type
:
8242 case DW_TAG_subrange_type
:
8243 add_psymbol_to_list (actual_name
,
8244 built_actual_name
!= NULL
,
8245 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8246 psymbol_placement::STATIC
,
8247 0, cu
->language
, objfile
);
8249 case DW_TAG_imported_declaration
:
8250 case DW_TAG_namespace
:
8251 add_psymbol_to_list (actual_name
,
8252 built_actual_name
!= NULL
,
8253 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8254 psymbol_placement::GLOBAL
,
8255 0, cu
->language
, objfile
);
8258 /* With Fortran 77 there might be a "BLOCK DATA" module
8259 available without any name. If so, we skip the module as it
8260 doesn't bring any value. */
8261 if (actual_name
!= nullptr)
8262 add_psymbol_to_list (actual_name
,
8263 built_actual_name
!= NULL
,
8264 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8265 psymbol_placement::GLOBAL
,
8266 0, cu
->language
, objfile
);
8268 case DW_TAG_class_type
:
8269 case DW_TAG_interface_type
:
8270 case DW_TAG_structure_type
:
8271 case DW_TAG_union_type
:
8272 case DW_TAG_enumeration_type
:
8273 /* Skip external references. The DWARF standard says in the section
8274 about "Structure, Union, and Class Type Entries": "An incomplete
8275 structure, union or class type is represented by a structure,
8276 union or class entry that does not have a byte size attribute
8277 and that has a DW_AT_declaration attribute." */
8278 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8281 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8282 static vs. global. */
8283 add_psymbol_to_list (actual_name
,
8284 built_actual_name
!= NULL
,
8285 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8286 cu
->language
== language_cplus
8287 ? psymbol_placement::GLOBAL
8288 : psymbol_placement::STATIC
,
8289 0, cu
->language
, objfile
);
8292 case DW_TAG_enumerator
:
8293 add_psymbol_to_list (actual_name
,
8294 built_actual_name
!= NULL
,
8295 VAR_DOMAIN
, LOC_CONST
, -1,
8296 cu
->language
== language_cplus
8297 ? psymbol_placement::GLOBAL
8298 : psymbol_placement::STATIC
,
8299 0, cu
->language
, objfile
);
8306 /* Read a partial die corresponding to a namespace; also, add a symbol
8307 corresponding to that namespace to the symbol table. NAMESPACE is
8308 the name of the enclosing namespace. */
8311 add_partial_namespace (struct partial_die_info
*pdi
,
8312 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8313 int set_addrmap
, struct dwarf2_cu
*cu
)
8315 /* Add a symbol for the namespace. */
8317 add_partial_symbol (pdi
, cu
);
8319 /* Now scan partial symbols in that namespace. */
8321 if (pdi
->has_children
)
8322 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8325 /* Read a partial die corresponding to a Fortran module. */
8328 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8329 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8331 /* Add a symbol for the namespace. */
8333 add_partial_symbol (pdi
, cu
);
8335 /* Now scan partial symbols in that module. */
8337 if (pdi
->has_children
)
8338 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8341 /* Read a partial die corresponding to a subprogram or an inlined
8342 subprogram and create a partial symbol for that subprogram.
8343 When the CU language allows it, this routine also defines a partial
8344 symbol for each nested subprogram that this subprogram contains.
8345 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8346 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8348 PDI may also be a lexical block, in which case we simply search
8349 recursively for subprograms defined inside that lexical block.
8350 Again, this is only performed when the CU language allows this
8351 type of definitions. */
8354 add_partial_subprogram (struct partial_die_info
*pdi
,
8355 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8356 int set_addrmap
, struct dwarf2_cu
*cu
)
8358 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8360 if (pdi
->has_pc_info
)
8362 if (pdi
->lowpc
< *lowpc
)
8363 *lowpc
= pdi
->lowpc
;
8364 if (pdi
->highpc
> *highpc
)
8365 *highpc
= pdi
->highpc
;
8368 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8369 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8371 CORE_ADDR this_highpc
;
8372 CORE_ADDR this_lowpc
;
8374 baseaddr
= objfile
->text_section_offset ();
8376 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8377 pdi
->lowpc
+ baseaddr
)
8380 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8381 pdi
->highpc
+ baseaddr
)
8383 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8384 this_lowpc
, this_highpc
- 1,
8385 cu
->per_cu
->v
.psymtab
);
8389 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8391 if (!pdi
->is_declaration
)
8392 /* Ignore subprogram DIEs that do not have a name, they are
8393 illegal. Do not emit a complaint at this point, we will
8394 do so when we convert this psymtab into a symtab. */
8396 add_partial_symbol (pdi
, cu
);
8400 if (! pdi
->has_children
)
8403 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8405 pdi
= pdi
->die_child
;
8409 if (pdi
->tag
== DW_TAG_subprogram
8410 || pdi
->tag
== DW_TAG_inlined_subroutine
8411 || pdi
->tag
== DW_TAG_lexical_block
)
8412 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8413 pdi
= pdi
->die_sibling
;
8418 /* Read a partial die corresponding to an enumeration type. */
8421 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8422 struct dwarf2_cu
*cu
)
8424 struct partial_die_info
*pdi
;
8426 if (enum_pdi
->name
!= NULL
)
8427 add_partial_symbol (enum_pdi
, cu
);
8429 pdi
= enum_pdi
->die_child
;
8432 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8433 complaint (_("malformed enumerator DIE ignored"));
8435 add_partial_symbol (pdi
, cu
);
8436 pdi
= pdi
->die_sibling
;
8440 /* Return the initial uleb128 in the die at INFO_PTR. */
8443 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8445 unsigned int bytes_read
;
8447 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8450 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8451 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8453 Return the corresponding abbrev, or NULL if the number is zero (indicating
8454 an empty DIE). In either case *BYTES_READ will be set to the length of
8455 the initial number. */
8457 static struct abbrev_info
*
8458 peek_die_abbrev (const die_reader_specs
&reader
,
8459 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8461 dwarf2_cu
*cu
= reader
.cu
;
8462 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8463 unsigned int abbrev_number
8464 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8466 if (abbrev_number
== 0)
8469 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8472 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8473 " at offset %s [in module %s]"),
8474 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8475 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8481 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8482 Returns a pointer to the end of a series of DIEs, terminated by an empty
8483 DIE. Any children of the skipped DIEs will also be skipped. */
8485 static const gdb_byte
*
8486 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8490 unsigned int bytes_read
;
8491 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8494 return info_ptr
+ bytes_read
;
8496 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8500 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8501 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8502 abbrev corresponding to that skipped uleb128 should be passed in
8503 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8506 static const gdb_byte
*
8507 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8508 struct abbrev_info
*abbrev
)
8510 unsigned int bytes_read
;
8511 struct attribute attr
;
8512 bfd
*abfd
= reader
->abfd
;
8513 struct dwarf2_cu
*cu
= reader
->cu
;
8514 const gdb_byte
*buffer
= reader
->buffer
;
8515 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8516 unsigned int form
, i
;
8518 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8520 /* The only abbrev we care about is DW_AT_sibling. */
8521 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8524 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8526 if (attr
.form
== DW_FORM_ref_addr
)
8527 complaint (_("ignoring absolute DW_AT_sibling"));
8530 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8531 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8533 if (sibling_ptr
< info_ptr
)
8534 complaint (_("DW_AT_sibling points backwards"));
8535 else if (sibling_ptr
> reader
->buffer_end
)
8536 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8542 /* If it isn't DW_AT_sibling, skip this attribute. */
8543 form
= abbrev
->attrs
[i
].form
;
8547 case DW_FORM_ref_addr
:
8548 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8549 and later it is offset sized. */
8550 if (cu
->header
.version
== 2)
8551 info_ptr
+= cu
->header
.addr_size
;
8553 info_ptr
+= cu
->header
.offset_size
;
8555 case DW_FORM_GNU_ref_alt
:
8556 info_ptr
+= cu
->header
.offset_size
;
8559 info_ptr
+= cu
->header
.addr_size
;
8567 case DW_FORM_flag_present
:
8568 case DW_FORM_implicit_const
:
8585 case DW_FORM_ref_sig8
:
8588 case DW_FORM_data16
:
8591 case DW_FORM_string
:
8592 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8593 info_ptr
+= bytes_read
;
8595 case DW_FORM_sec_offset
:
8597 case DW_FORM_GNU_strp_alt
:
8598 info_ptr
+= cu
->header
.offset_size
;
8600 case DW_FORM_exprloc
:
8602 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8603 info_ptr
+= bytes_read
;
8605 case DW_FORM_block1
:
8606 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8608 case DW_FORM_block2
:
8609 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8611 case DW_FORM_block4
:
8612 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8618 case DW_FORM_ref_udata
:
8619 case DW_FORM_GNU_addr_index
:
8620 case DW_FORM_GNU_str_index
:
8621 case DW_FORM_rnglistx
:
8622 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8624 case DW_FORM_indirect
:
8625 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8626 info_ptr
+= bytes_read
;
8627 /* We need to continue parsing from here, so just go back to
8629 goto skip_attribute
;
8632 error (_("Dwarf Error: Cannot handle %s "
8633 "in DWARF reader [in module %s]"),
8634 dwarf_form_name (form
),
8635 bfd_get_filename (abfd
));
8639 if (abbrev
->has_children
)
8640 return skip_children (reader
, info_ptr
);
8645 /* Locate ORIG_PDI's sibling.
8646 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8648 static const gdb_byte
*
8649 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8650 struct partial_die_info
*orig_pdi
,
8651 const gdb_byte
*info_ptr
)
8653 /* Do we know the sibling already? */
8655 if (orig_pdi
->sibling
)
8656 return orig_pdi
->sibling
;
8658 /* Are there any children to deal with? */
8660 if (!orig_pdi
->has_children
)
8663 /* Skip the children the long way. */
8665 return skip_children (reader
, info_ptr
);
8668 /* Expand this partial symbol table into a full symbol table. SELF is
8672 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8674 struct dwarf2_per_objfile
*dwarf2_per_objfile
8675 = get_dwarf2_per_objfile (objfile
);
8677 gdb_assert (!readin
);
8678 /* If this psymtab is constructed from a debug-only objfile, the
8679 has_section_at_zero flag will not necessarily be correct. We
8680 can get the correct value for this flag by looking at the data
8681 associated with the (presumably stripped) associated objfile. */
8682 if (objfile
->separate_debug_objfile_backlink
)
8684 struct dwarf2_per_objfile
*dpo_backlink
8685 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8687 dwarf2_per_objfile
->has_section_at_zero
8688 = dpo_backlink
->has_section_at_zero
;
8691 expand_psymtab (objfile
);
8693 process_cu_includes (dwarf2_per_objfile
);
8696 /* Reading in full CUs. */
8698 /* Add PER_CU to the queue. */
8701 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8702 enum language pretend_language
)
8705 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8708 /* If PER_CU is not yet queued, add it to the queue.
8709 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8711 The result is non-zero if PER_CU was queued, otherwise the result is zero
8712 meaning either PER_CU is already queued or it is already loaded.
8714 N.B. There is an invariant here that if a CU is queued then it is loaded.
8715 The caller is required to load PER_CU if we return non-zero. */
8718 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8719 struct dwarf2_per_cu_data
*per_cu
,
8720 enum language pretend_language
)
8722 /* We may arrive here during partial symbol reading, if we need full
8723 DIEs to process an unusual case (e.g. template arguments). Do
8724 not queue PER_CU, just tell our caller to load its DIEs. */
8725 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8727 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8732 /* Mark the dependence relation so that we don't flush PER_CU
8734 if (dependent_cu
!= NULL
)
8735 dwarf2_add_dependence (dependent_cu
, per_cu
);
8737 /* If it's already on the queue, we have nothing to do. */
8741 /* If the compilation unit is already loaded, just mark it as
8743 if (per_cu
->cu
!= NULL
)
8745 per_cu
->cu
->last_used
= 0;
8749 /* Add it to the queue. */
8750 queue_comp_unit (per_cu
, pretend_language
);
8755 /* Process the queue. */
8758 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8760 if (dwarf_read_debug
)
8762 fprintf_unfiltered (gdb_stdlog
,
8763 "Expanding one or more symtabs of objfile %s ...\n",
8764 objfile_name (dwarf2_per_objfile
->objfile
));
8767 /* The queue starts out with one item, but following a DIE reference
8768 may load a new CU, adding it to the end of the queue. */
8769 while (!dwarf2_per_objfile
->queue
.empty ())
8771 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8773 if ((dwarf2_per_objfile
->using_index
8774 ? !item
.per_cu
->v
.quick
->compunit_symtab
8775 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8776 /* Skip dummy CUs. */
8777 && item
.per_cu
->cu
!= NULL
)
8779 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8780 unsigned int debug_print_threshold
;
8783 if (per_cu
->is_debug_types
)
8785 struct signatured_type
*sig_type
=
8786 (struct signatured_type
*) per_cu
;
8788 sprintf (buf
, "TU %s at offset %s",
8789 hex_string (sig_type
->signature
),
8790 sect_offset_str (per_cu
->sect_off
));
8791 /* There can be 100s of TUs.
8792 Only print them in verbose mode. */
8793 debug_print_threshold
= 2;
8797 sprintf (buf
, "CU at offset %s",
8798 sect_offset_str (per_cu
->sect_off
));
8799 debug_print_threshold
= 1;
8802 if (dwarf_read_debug
>= debug_print_threshold
)
8803 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8805 if (per_cu
->is_debug_types
)
8806 process_full_type_unit (per_cu
, item
.pretend_language
);
8808 process_full_comp_unit (per_cu
, item
.pretend_language
);
8810 if (dwarf_read_debug
>= debug_print_threshold
)
8811 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8814 item
.per_cu
->queued
= 0;
8815 dwarf2_per_objfile
->queue
.pop ();
8818 if (dwarf_read_debug
)
8820 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8821 objfile_name (dwarf2_per_objfile
->objfile
));
8825 /* Read in full symbols for PST, and anything it depends on. */
8828 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8830 struct dwarf2_per_cu_data
*per_cu
;
8835 read_dependencies (objfile
);
8837 per_cu
= per_cu_data
;
8841 /* It's an include file, no symbols to read for it.
8842 Everything is in the parent symtab. */
8847 dw2_do_instantiate_symtab (per_cu
, false);
8850 /* Trivial hash function for die_info: the hash value of a DIE
8851 is its offset in .debug_info for this objfile. */
8854 die_hash (const void *item
)
8856 const struct die_info
*die
= (const struct die_info
*) item
;
8858 return to_underlying (die
->sect_off
);
8861 /* Trivial comparison function for die_info structures: two DIEs
8862 are equal if they have the same offset. */
8865 die_eq (const void *item_lhs
, const void *item_rhs
)
8867 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8868 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8870 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8873 /* Load the DIEs associated with PER_CU into memory. */
8876 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8878 enum language pretend_language
)
8880 gdb_assert (! this_cu
->is_debug_types
);
8882 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8886 struct dwarf2_cu
*cu
= reader
.cu
;
8887 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8889 gdb_assert (cu
->die_hash
== NULL
);
8891 htab_create_alloc_ex (cu
->header
.length
/ 12,
8895 &cu
->comp_unit_obstack
,
8896 hashtab_obstack_allocate
,
8897 dummy_obstack_deallocate
);
8899 if (reader
.comp_unit_die
->has_children
)
8900 reader
.comp_unit_die
->child
8901 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8902 &info_ptr
, reader
.comp_unit_die
);
8903 cu
->dies
= reader
.comp_unit_die
;
8904 /* comp_unit_die is not stored in die_hash, no need. */
8906 /* We try not to read any attributes in this function, because not
8907 all CUs needed for references have been loaded yet, and symbol
8908 table processing isn't initialized. But we have to set the CU language,
8909 or we won't be able to build types correctly.
8910 Similarly, if we do not read the producer, we can not apply
8911 producer-specific interpretation. */
8912 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8917 /* Add a DIE to the delayed physname list. */
8920 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8921 const char *name
, struct die_info
*die
,
8922 struct dwarf2_cu
*cu
)
8924 struct delayed_method_info mi
;
8926 mi
.fnfield_index
= fnfield_index
;
8930 cu
->method_list
.push_back (mi
);
8933 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8934 "const" / "volatile". If so, decrements LEN by the length of the
8935 modifier and return true. Otherwise return false. */
8939 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8941 size_t mod_len
= sizeof (mod
) - 1;
8942 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8950 /* Compute the physnames of any methods on the CU's method list.
8952 The computation of method physnames is delayed in order to avoid the
8953 (bad) condition that one of the method's formal parameters is of an as yet
8957 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8959 /* Only C++ delays computing physnames. */
8960 if (cu
->method_list
.empty ())
8962 gdb_assert (cu
->language
== language_cplus
);
8964 for (const delayed_method_info
&mi
: cu
->method_list
)
8966 const char *physname
;
8967 struct fn_fieldlist
*fn_flp
8968 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8969 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8970 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8971 = physname
? physname
: "";
8973 /* Since there's no tag to indicate whether a method is a
8974 const/volatile overload, extract that information out of the
8976 if (physname
!= NULL
)
8978 size_t len
= strlen (physname
);
8982 if (physname
[len
] == ')') /* shortcut */
8984 else if (check_modifier (physname
, len
, " const"))
8985 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8986 else if (check_modifier (physname
, len
, " volatile"))
8987 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8994 /* The list is no longer needed. */
8995 cu
->method_list
.clear ();
8998 /* Go objects should be embedded in a DW_TAG_module DIE,
8999 and it's not clear if/how imported objects will appear.
9000 To keep Go support simple until that's worked out,
9001 go back through what we've read and create something usable.
9002 We could do this while processing each DIE, and feels kinda cleaner,
9003 but that way is more invasive.
9004 This is to, for example, allow the user to type "p var" or "b main"
9005 without having to specify the package name, and allow lookups
9006 of module.object to work in contexts that use the expression
9010 fixup_go_packaging (struct dwarf2_cu
*cu
)
9012 gdb::unique_xmalloc_ptr
<char> package_name
;
9013 struct pending
*list
;
9016 for (list
= *cu
->get_builder ()->get_global_symbols ();
9020 for (i
= 0; i
< list
->nsyms
; ++i
)
9022 struct symbol
*sym
= list
->symbol
[i
];
9024 if (sym
->language () == language_go
9025 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9027 gdb::unique_xmalloc_ptr
<char> this_package_name
9028 (go_symbol_package_name (sym
));
9030 if (this_package_name
== NULL
)
9032 if (package_name
== NULL
)
9033 package_name
= std::move (this_package_name
);
9036 struct objfile
*objfile
9037 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9038 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9039 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9040 (symbol_symtab (sym
) != NULL
9041 ? symtab_to_filename_for_display
9042 (symbol_symtab (sym
))
9043 : objfile_name (objfile
)),
9044 this_package_name
.get (), package_name
.get ());
9050 if (package_name
!= NULL
)
9052 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9053 const char *saved_package_name
9054 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9055 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9056 saved_package_name
);
9059 sym
= allocate_symbol (objfile
);
9060 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9061 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9062 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9063 e.g., "main" finds the "main" module and not C's main(). */
9064 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9065 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9066 SYMBOL_TYPE (sym
) = type
;
9068 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9072 /* Allocate a fully-qualified name consisting of the two parts on the
9076 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9078 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9081 /* A helper that allocates a struct discriminant_info to attach to a
9084 static struct discriminant_info
*
9085 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9088 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9089 gdb_assert (discriminant_index
== -1
9090 || (discriminant_index
>= 0
9091 && discriminant_index
< TYPE_NFIELDS (type
)));
9092 gdb_assert (default_index
== -1
9093 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9095 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9097 struct discriminant_info
*disc
9098 = ((struct discriminant_info
*)
9100 offsetof (struct discriminant_info
, discriminants
)
9101 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9102 disc
->default_index
= default_index
;
9103 disc
->discriminant_index
= discriminant_index
;
9105 struct dynamic_prop prop
;
9106 prop
.kind
= PROP_UNDEFINED
;
9107 prop
.data
.baton
= disc
;
9109 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9114 /* Some versions of rustc emitted enums in an unusual way.
9116 Ordinary enums were emitted as unions. The first element of each
9117 structure in the union was named "RUST$ENUM$DISR". This element
9118 held the discriminant.
9120 These versions of Rust also implemented the "non-zero"
9121 optimization. When the enum had two values, and one is empty and
9122 the other holds a pointer that cannot be zero, the pointer is used
9123 as the discriminant, with a zero value meaning the empty variant.
9124 Here, the union's first member is of the form
9125 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9126 where the fieldnos are the indices of the fields that should be
9127 traversed in order to find the field (which may be several fields deep)
9128 and the variantname is the name of the variant of the case when the
9131 This function recognizes whether TYPE is of one of these forms,
9132 and, if so, smashes it to be a variant type. */
9135 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9137 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9139 /* We don't need to deal with empty enums. */
9140 if (TYPE_NFIELDS (type
) == 0)
9143 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9144 if (TYPE_NFIELDS (type
) == 1
9145 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9147 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9149 /* Decode the field name to find the offset of the
9151 ULONGEST bit_offset
= 0;
9152 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9153 while (name
[0] >= '0' && name
[0] <= '9')
9156 unsigned long index
= strtoul (name
, &tail
, 10);
9159 || index
>= TYPE_NFIELDS (field_type
)
9160 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9161 != FIELD_LOC_KIND_BITPOS
))
9163 complaint (_("Could not parse Rust enum encoding string \"%s\""
9165 TYPE_FIELD_NAME (type
, 0),
9166 objfile_name (objfile
));
9171 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9172 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9175 /* Make a union to hold the variants. */
9176 struct type
*union_type
= alloc_type (objfile
);
9177 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9178 TYPE_NFIELDS (union_type
) = 3;
9179 TYPE_FIELDS (union_type
)
9180 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9181 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9182 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9184 /* Put the discriminant must at index 0. */
9185 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9186 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9187 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9188 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9190 /* The order of fields doesn't really matter, so put the real
9191 field at index 1 and the data-less field at index 2. */
9192 struct discriminant_info
*disc
9193 = alloc_discriminant_info (union_type
, 0, 1);
9194 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9195 TYPE_FIELD_NAME (union_type
, 1)
9196 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9197 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9198 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9199 TYPE_FIELD_NAME (union_type
, 1));
9201 const char *dataless_name
9202 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9204 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9206 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9207 /* NAME points into the original discriminant name, which
9208 already has the correct lifetime. */
9209 TYPE_FIELD_NAME (union_type
, 2) = name
;
9210 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9211 disc
->discriminants
[2] = 0;
9213 /* Smash this type to be a structure type. We have to do this
9214 because the type has already been recorded. */
9215 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9216 TYPE_NFIELDS (type
) = 1;
9218 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9220 /* Install the variant part. */
9221 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9222 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9223 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9225 /* A union with a single anonymous field is probably an old-style
9227 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9229 /* Smash this type to be a structure type. We have to do this
9230 because the type has already been recorded. */
9231 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9233 /* Make a union to hold the variants. */
9234 struct type
*union_type
= alloc_type (objfile
);
9235 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9236 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9237 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9238 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9239 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9241 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9242 const char *variant_name
9243 = rust_last_path_segment (TYPE_NAME (field_type
));
9244 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9245 TYPE_NAME (field_type
)
9246 = rust_fully_qualify (&objfile
->objfile_obstack
,
9247 TYPE_NAME (type
), variant_name
);
9249 /* Install the union in the outer struct type. */
9250 TYPE_NFIELDS (type
) = 1;
9252 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9253 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9254 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9255 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9257 alloc_discriminant_info (union_type
, -1, 0);
9261 struct type
*disr_type
= nullptr;
9262 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9264 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9266 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9268 /* All fields of a true enum will be structs. */
9271 else if (TYPE_NFIELDS (disr_type
) == 0)
9273 /* Could be data-less variant, so keep going. */
9274 disr_type
= nullptr;
9276 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9277 "RUST$ENUM$DISR") != 0)
9279 /* Not a Rust enum. */
9289 /* If we got here without a discriminant, then it's probably
9291 if (disr_type
== nullptr)
9294 /* Smash this type to be a structure type. We have to do this
9295 because the type has already been recorded. */
9296 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9298 /* Make a union to hold the variants. */
9299 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9300 struct type
*union_type
= alloc_type (objfile
);
9301 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9302 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9303 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9304 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9305 TYPE_FIELDS (union_type
)
9306 = (struct field
*) TYPE_ZALLOC (union_type
,
9307 (TYPE_NFIELDS (union_type
)
9308 * sizeof (struct field
)));
9310 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9311 TYPE_NFIELDS (type
) * sizeof (struct field
));
9313 /* Install the discriminant at index 0 in the union. */
9314 TYPE_FIELD (union_type
, 0) = *disr_field
;
9315 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9316 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9318 /* Install the union in the outer struct type. */
9319 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9320 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9321 TYPE_NFIELDS (type
) = 1;
9323 /* Set the size and offset of the union type. */
9324 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9326 /* We need a way to find the correct discriminant given a
9327 variant name. For convenience we build a map here. */
9328 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9329 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9330 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9332 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9335 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9336 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9340 int n_fields
= TYPE_NFIELDS (union_type
);
9341 struct discriminant_info
*disc
9342 = alloc_discriminant_info (union_type
, 0, -1);
9343 /* Skip the discriminant here. */
9344 for (int i
= 1; i
< n_fields
; ++i
)
9346 /* Find the final word in the name of this variant's type.
9347 That name can be used to look up the correct
9349 const char *variant_name
9350 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9353 auto iter
= discriminant_map
.find (variant_name
);
9354 if (iter
!= discriminant_map
.end ())
9355 disc
->discriminants
[i
] = iter
->second
;
9357 /* Remove the discriminant field, if it exists. */
9358 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9359 if (TYPE_NFIELDS (sub_type
) > 0)
9361 --TYPE_NFIELDS (sub_type
);
9362 ++TYPE_FIELDS (sub_type
);
9364 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9365 TYPE_NAME (sub_type
)
9366 = rust_fully_qualify (&objfile
->objfile_obstack
,
9367 TYPE_NAME (type
), variant_name
);
9372 /* Rewrite some Rust unions to be structures with variants parts. */
9375 rust_union_quirks (struct dwarf2_cu
*cu
)
9377 gdb_assert (cu
->language
== language_rust
);
9378 for (type
*type_
: cu
->rust_unions
)
9379 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9380 /* We don't need this any more. */
9381 cu
->rust_unions
.clear ();
9384 /* Return the symtab for PER_CU. This works properly regardless of
9385 whether we're using the index or psymtabs. */
9387 static struct compunit_symtab
*
9388 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9390 return (per_cu
->dwarf2_per_objfile
->using_index
9391 ? per_cu
->v
.quick
->compunit_symtab
9392 : per_cu
->v
.psymtab
->compunit_symtab
);
9395 /* A helper function for computing the list of all symbol tables
9396 included by PER_CU. */
9399 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9400 htab_t all_children
, htab_t all_type_symtabs
,
9401 struct dwarf2_per_cu_data
*per_cu
,
9402 struct compunit_symtab
*immediate_parent
)
9405 struct compunit_symtab
*cust
;
9407 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9410 /* This inclusion and its children have been processed. */
9415 /* Only add a CU if it has a symbol table. */
9416 cust
= get_compunit_symtab (per_cu
);
9419 /* If this is a type unit only add its symbol table if we haven't
9420 seen it yet (type unit per_cu's can share symtabs). */
9421 if (per_cu
->is_debug_types
)
9423 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9427 result
->push_back (cust
);
9428 if (cust
->user
== NULL
)
9429 cust
->user
= immediate_parent
;
9434 result
->push_back (cust
);
9435 if (cust
->user
== NULL
)
9436 cust
->user
= immediate_parent
;
9440 if (!per_cu
->imported_symtabs_empty ())
9441 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9443 recursively_compute_inclusions (result
, all_children
,
9444 all_type_symtabs
, ptr
, cust
);
9448 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9452 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9454 gdb_assert (! per_cu
->is_debug_types
);
9456 if (!per_cu
->imported_symtabs_empty ())
9459 std::vector
<compunit_symtab
*> result_symtabs
;
9460 htab_t all_children
, all_type_symtabs
;
9461 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9463 /* If we don't have a symtab, we can just skip this case. */
9467 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9468 NULL
, xcalloc
, xfree
);
9469 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9470 NULL
, xcalloc
, xfree
);
9472 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9474 recursively_compute_inclusions (&result_symtabs
, all_children
,
9475 all_type_symtabs
, ptr
, cust
);
9478 /* Now we have a transitive closure of all the included symtabs. */
9479 len
= result_symtabs
.size ();
9481 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9482 struct compunit_symtab
*, len
+ 1);
9483 memcpy (cust
->includes
, result_symtabs
.data (),
9484 len
* sizeof (compunit_symtab
*));
9485 cust
->includes
[len
] = NULL
;
9487 htab_delete (all_children
);
9488 htab_delete (all_type_symtabs
);
9492 /* Compute the 'includes' field for the symtabs of all the CUs we just
9496 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9498 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9500 if (! iter
->is_debug_types
)
9501 compute_compunit_symtab_includes (iter
);
9504 dwarf2_per_objfile
->just_read_cus
.clear ();
9507 /* Generate full symbol information for PER_CU, whose DIEs have
9508 already been loaded into memory. */
9511 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9512 enum language pretend_language
)
9514 struct dwarf2_cu
*cu
= per_cu
->cu
;
9515 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9516 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9517 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9518 CORE_ADDR lowpc
, highpc
;
9519 struct compunit_symtab
*cust
;
9521 struct block
*static_block
;
9524 baseaddr
= objfile
->text_section_offset ();
9526 /* Clear the list here in case something was left over. */
9527 cu
->method_list
.clear ();
9529 cu
->language
= pretend_language
;
9530 cu
->language_defn
= language_def (cu
->language
);
9532 /* Do line number decoding in read_file_scope () */
9533 process_die (cu
->dies
, cu
);
9535 /* For now fudge the Go package. */
9536 if (cu
->language
== language_go
)
9537 fixup_go_packaging (cu
);
9539 /* Now that we have processed all the DIEs in the CU, all the types
9540 should be complete, and it should now be safe to compute all of the
9542 compute_delayed_physnames (cu
);
9544 if (cu
->language
== language_rust
)
9545 rust_union_quirks (cu
);
9547 /* Some compilers don't define a DW_AT_high_pc attribute for the
9548 compilation unit. If the DW_AT_high_pc is missing, synthesize
9549 it, by scanning the DIE's below the compilation unit. */
9550 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9552 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9553 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9555 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9556 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9557 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9558 addrmap to help ensure it has an accurate map of pc values belonging to
9560 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9562 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9563 SECT_OFF_TEXT (objfile
),
9568 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9570 /* Set symtab language to language from DW_AT_language. If the
9571 compilation is from a C file generated by language preprocessors, do
9572 not set the language if it was already deduced by start_subfile. */
9573 if (!(cu
->language
== language_c
9574 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9575 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9577 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9578 produce DW_AT_location with location lists but it can be possibly
9579 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9580 there were bugs in prologue debug info, fixed later in GCC-4.5
9581 by "unwind info for epilogues" patch (which is not directly related).
9583 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9584 needed, it would be wrong due to missing DW_AT_producer there.
9586 Still one can confuse GDB by using non-standard GCC compilation
9587 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9589 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9590 cust
->locations_valid
= 1;
9592 if (gcc_4_minor
>= 5)
9593 cust
->epilogue_unwind_valid
= 1;
9595 cust
->call_site_htab
= cu
->call_site_htab
;
9598 if (dwarf2_per_objfile
->using_index
)
9599 per_cu
->v
.quick
->compunit_symtab
= cust
;
9602 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9603 pst
->compunit_symtab
= cust
;
9607 /* Push it for inclusion processing later. */
9608 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9610 /* Not needed any more. */
9611 cu
->reset_builder ();
9614 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9615 already been loaded into memory. */
9618 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9619 enum language pretend_language
)
9621 struct dwarf2_cu
*cu
= per_cu
->cu
;
9622 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9623 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9624 struct compunit_symtab
*cust
;
9625 struct signatured_type
*sig_type
;
9627 gdb_assert (per_cu
->is_debug_types
);
9628 sig_type
= (struct signatured_type
*) per_cu
;
9630 /* Clear the list here in case something was left over. */
9631 cu
->method_list
.clear ();
9633 cu
->language
= pretend_language
;
9634 cu
->language_defn
= language_def (cu
->language
);
9636 /* The symbol tables are set up in read_type_unit_scope. */
9637 process_die (cu
->dies
, cu
);
9639 /* For now fudge the Go package. */
9640 if (cu
->language
== language_go
)
9641 fixup_go_packaging (cu
);
9643 /* Now that we have processed all the DIEs in the CU, all the types
9644 should be complete, and it should now be safe to compute all of the
9646 compute_delayed_physnames (cu
);
9648 if (cu
->language
== language_rust
)
9649 rust_union_quirks (cu
);
9651 /* TUs share symbol tables.
9652 If this is the first TU to use this symtab, complete the construction
9653 of it with end_expandable_symtab. Otherwise, complete the addition of
9654 this TU's symbols to the existing symtab. */
9655 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9657 buildsym_compunit
*builder
= cu
->get_builder ();
9658 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9659 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9663 /* Set symtab language to language from DW_AT_language. If the
9664 compilation is from a C file generated by language preprocessors,
9665 do not set the language if it was already deduced by
9667 if (!(cu
->language
== language_c
9668 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9669 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9674 cu
->get_builder ()->augment_type_symtab ();
9675 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9678 if (dwarf2_per_objfile
->using_index
)
9679 per_cu
->v
.quick
->compunit_symtab
= cust
;
9682 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9683 pst
->compunit_symtab
= cust
;
9687 /* Not needed any more. */
9688 cu
->reset_builder ();
9691 /* Process an imported unit DIE. */
9694 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9696 struct attribute
*attr
;
9698 /* For now we don't handle imported units in type units. */
9699 if (cu
->per_cu
->is_debug_types
)
9701 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9702 " supported in type units [in module %s]"),
9703 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9706 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9709 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9710 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9711 dwarf2_per_cu_data
*per_cu
9712 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9713 cu
->per_cu
->dwarf2_per_objfile
);
9715 /* If necessary, add it to the queue and load its DIEs. */
9716 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9717 load_full_comp_unit (per_cu
, false, cu
->language
);
9719 cu
->per_cu
->imported_symtabs_push (per_cu
);
9723 /* RAII object that represents a process_die scope: i.e.,
9724 starts/finishes processing a DIE. */
9725 class process_die_scope
9728 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9729 : m_die (die
), m_cu (cu
)
9731 /* We should only be processing DIEs not already in process. */
9732 gdb_assert (!m_die
->in_process
);
9733 m_die
->in_process
= true;
9736 ~process_die_scope ()
9738 m_die
->in_process
= false;
9740 /* If we're done processing the DIE for the CU that owns the line
9741 header, we don't need the line header anymore. */
9742 if (m_cu
->line_header_die_owner
== m_die
)
9744 delete m_cu
->line_header
;
9745 m_cu
->line_header
= NULL
;
9746 m_cu
->line_header_die_owner
= NULL
;
9755 /* Process a die and its children. */
9758 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9760 process_die_scope
scope (die
, cu
);
9764 case DW_TAG_padding
:
9766 case DW_TAG_compile_unit
:
9767 case DW_TAG_partial_unit
:
9768 read_file_scope (die
, cu
);
9770 case DW_TAG_type_unit
:
9771 read_type_unit_scope (die
, cu
);
9773 case DW_TAG_subprogram
:
9774 /* Nested subprograms in Fortran get a prefix. */
9775 if (cu
->language
== language_fortran
9776 && die
->parent
!= NULL
9777 && die
->parent
->tag
== DW_TAG_subprogram
)
9778 cu
->processing_has_namespace_info
= true;
9780 case DW_TAG_inlined_subroutine
:
9781 read_func_scope (die
, cu
);
9783 case DW_TAG_lexical_block
:
9784 case DW_TAG_try_block
:
9785 case DW_TAG_catch_block
:
9786 read_lexical_block_scope (die
, cu
);
9788 case DW_TAG_call_site
:
9789 case DW_TAG_GNU_call_site
:
9790 read_call_site_scope (die
, cu
);
9792 case DW_TAG_class_type
:
9793 case DW_TAG_interface_type
:
9794 case DW_TAG_structure_type
:
9795 case DW_TAG_union_type
:
9796 process_structure_scope (die
, cu
);
9798 case DW_TAG_enumeration_type
:
9799 process_enumeration_scope (die
, cu
);
9802 /* These dies have a type, but processing them does not create
9803 a symbol or recurse to process the children. Therefore we can
9804 read them on-demand through read_type_die. */
9805 case DW_TAG_subroutine_type
:
9806 case DW_TAG_set_type
:
9807 case DW_TAG_array_type
:
9808 case DW_TAG_pointer_type
:
9809 case DW_TAG_ptr_to_member_type
:
9810 case DW_TAG_reference_type
:
9811 case DW_TAG_rvalue_reference_type
:
9812 case DW_TAG_string_type
:
9815 case DW_TAG_base_type
:
9816 case DW_TAG_subrange_type
:
9817 case DW_TAG_typedef
:
9818 /* Add a typedef symbol for the type definition, if it has a
9820 new_symbol (die
, read_type_die (die
, cu
), cu
);
9822 case DW_TAG_common_block
:
9823 read_common_block (die
, cu
);
9825 case DW_TAG_common_inclusion
:
9827 case DW_TAG_namespace
:
9828 cu
->processing_has_namespace_info
= true;
9829 read_namespace (die
, cu
);
9832 cu
->processing_has_namespace_info
= true;
9833 read_module (die
, cu
);
9835 case DW_TAG_imported_declaration
:
9836 cu
->processing_has_namespace_info
= true;
9837 if (read_namespace_alias (die
, cu
))
9839 /* The declaration is not a global namespace alias. */
9841 case DW_TAG_imported_module
:
9842 cu
->processing_has_namespace_info
= true;
9843 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9844 || cu
->language
!= language_fortran
))
9845 complaint (_("Tag '%s' has unexpected children"),
9846 dwarf_tag_name (die
->tag
));
9847 read_import_statement (die
, cu
);
9850 case DW_TAG_imported_unit
:
9851 process_imported_unit_die (die
, cu
);
9854 case DW_TAG_variable
:
9855 read_variable (die
, cu
);
9859 new_symbol (die
, NULL
, cu
);
9864 /* DWARF name computation. */
9866 /* A helper function for dwarf2_compute_name which determines whether DIE
9867 needs to have the name of the scope prepended to the name listed in the
9871 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9873 struct attribute
*attr
;
9877 case DW_TAG_namespace
:
9878 case DW_TAG_typedef
:
9879 case DW_TAG_class_type
:
9880 case DW_TAG_interface_type
:
9881 case DW_TAG_structure_type
:
9882 case DW_TAG_union_type
:
9883 case DW_TAG_enumeration_type
:
9884 case DW_TAG_enumerator
:
9885 case DW_TAG_subprogram
:
9886 case DW_TAG_inlined_subroutine
:
9888 case DW_TAG_imported_declaration
:
9891 case DW_TAG_variable
:
9892 case DW_TAG_constant
:
9893 /* We only need to prefix "globally" visible variables. These include
9894 any variable marked with DW_AT_external or any variable that
9895 lives in a namespace. [Variables in anonymous namespaces
9896 require prefixing, but they are not DW_AT_external.] */
9898 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9900 struct dwarf2_cu
*spec_cu
= cu
;
9902 return die_needs_namespace (die_specification (die
, &spec_cu
),
9906 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9907 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9908 && die
->parent
->tag
!= DW_TAG_module
)
9910 /* A variable in a lexical block of some kind does not need a
9911 namespace, even though in C++ such variables may be external
9912 and have a mangled name. */
9913 if (die
->parent
->tag
== DW_TAG_lexical_block
9914 || die
->parent
->tag
== DW_TAG_try_block
9915 || die
->parent
->tag
== DW_TAG_catch_block
9916 || die
->parent
->tag
== DW_TAG_subprogram
)
9925 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9926 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9927 defined for the given DIE. */
9929 static struct attribute
*
9930 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9932 struct attribute
*attr
;
9934 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9936 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9941 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9942 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9943 defined for the given DIE. */
9946 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9948 const char *linkage_name
;
9950 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9951 if (linkage_name
== NULL
)
9952 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9954 return linkage_name
;
9957 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9958 compute the physname for the object, which include a method's:
9959 - formal parameters (C++),
9960 - receiver type (Go),
9962 The term "physname" is a bit confusing.
9963 For C++, for example, it is the demangled name.
9964 For Go, for example, it's the mangled name.
9966 For Ada, return the DIE's linkage name rather than the fully qualified
9967 name. PHYSNAME is ignored..
9969 The result is allocated on the objfile_obstack and canonicalized. */
9972 dwarf2_compute_name (const char *name
,
9973 struct die_info
*die
, struct dwarf2_cu
*cu
,
9976 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9979 name
= dwarf2_name (die
, cu
);
9981 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9982 but otherwise compute it by typename_concat inside GDB.
9983 FIXME: Actually this is not really true, or at least not always true.
9984 It's all very confusing. compute_and_set_names doesn't try to demangle
9985 Fortran names because there is no mangling standard. So new_symbol
9986 will set the demangled name to the result of dwarf2_full_name, and it is
9987 the demangled name that GDB uses if it exists. */
9988 if (cu
->language
== language_ada
9989 || (cu
->language
== language_fortran
&& physname
))
9991 /* For Ada unit, we prefer the linkage name over the name, as
9992 the former contains the exported name, which the user expects
9993 to be able to reference. Ideally, we want the user to be able
9994 to reference this entity using either natural or linkage name,
9995 but we haven't started looking at this enhancement yet. */
9996 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9998 if (linkage_name
!= NULL
)
9999 return linkage_name
;
10002 /* These are the only languages we know how to qualify names in. */
10004 && (cu
->language
== language_cplus
10005 || cu
->language
== language_fortran
|| cu
->language
== language_d
10006 || cu
->language
== language_rust
))
10008 if (die_needs_namespace (die
, cu
))
10010 const char *prefix
;
10011 const char *canonical_name
= NULL
;
10015 prefix
= determine_prefix (die
, cu
);
10016 if (*prefix
!= '\0')
10018 gdb::unique_xmalloc_ptr
<char> prefixed_name
10019 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10021 buf
.puts (prefixed_name
.get ());
10026 /* Template parameters may be specified in the DIE's DW_AT_name, or
10027 as children with DW_TAG_template_type_param or
10028 DW_TAG_value_type_param. If the latter, add them to the name
10029 here. If the name already has template parameters, then
10030 skip this step; some versions of GCC emit both, and
10031 it is more efficient to use the pre-computed name.
10033 Something to keep in mind about this process: it is very
10034 unlikely, or in some cases downright impossible, to produce
10035 something that will match the mangled name of a function.
10036 If the definition of the function has the same debug info,
10037 we should be able to match up with it anyway. But fallbacks
10038 using the minimal symbol, for instance to find a method
10039 implemented in a stripped copy of libstdc++, will not work.
10040 If we do not have debug info for the definition, we will have to
10041 match them up some other way.
10043 When we do name matching there is a related problem with function
10044 templates; two instantiated function templates are allowed to
10045 differ only by their return types, which we do not add here. */
10047 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10049 struct attribute
*attr
;
10050 struct die_info
*child
;
10053 die
->building_fullname
= 1;
10055 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10059 const gdb_byte
*bytes
;
10060 struct dwarf2_locexpr_baton
*baton
;
10063 if (child
->tag
!= DW_TAG_template_type_param
10064 && child
->tag
!= DW_TAG_template_value_param
)
10075 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10078 complaint (_("template parameter missing DW_AT_type"));
10079 buf
.puts ("UNKNOWN_TYPE");
10082 type
= die_type (child
, cu
);
10084 if (child
->tag
== DW_TAG_template_type_param
)
10086 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10087 &type_print_raw_options
);
10091 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10094 complaint (_("template parameter missing "
10095 "DW_AT_const_value"));
10096 buf
.puts ("UNKNOWN_VALUE");
10100 dwarf2_const_value_attr (attr
, type
, name
,
10101 &cu
->comp_unit_obstack
, cu
,
10102 &value
, &bytes
, &baton
);
10104 if (TYPE_NOSIGN (type
))
10105 /* GDB prints characters as NUMBER 'CHAR'. If that's
10106 changed, this can use value_print instead. */
10107 c_printchar (value
, type
, &buf
);
10110 struct value_print_options opts
;
10113 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10117 else if (bytes
!= NULL
)
10119 v
= allocate_value (type
);
10120 memcpy (value_contents_writeable (v
), bytes
,
10121 TYPE_LENGTH (type
));
10124 v
= value_from_longest (type
, value
);
10126 /* Specify decimal so that we do not depend on
10128 get_formatted_print_options (&opts
, 'd');
10130 value_print (v
, &buf
, &opts
);
10135 die
->building_fullname
= 0;
10139 /* Close the argument list, with a space if necessary
10140 (nested templates). */
10141 if (!buf
.empty () && buf
.string ().back () == '>')
10148 /* For C++ methods, append formal parameter type
10149 information, if PHYSNAME. */
10151 if (physname
&& die
->tag
== DW_TAG_subprogram
10152 && cu
->language
== language_cplus
)
10154 struct type
*type
= read_type_die (die
, cu
);
10156 c_type_print_args (type
, &buf
, 1, cu
->language
,
10157 &type_print_raw_options
);
10159 if (cu
->language
== language_cplus
)
10161 /* Assume that an artificial first parameter is
10162 "this", but do not crash if it is not. RealView
10163 marks unnamed (and thus unused) parameters as
10164 artificial; there is no way to differentiate
10166 if (TYPE_NFIELDS (type
) > 0
10167 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10168 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10169 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10171 buf
.puts (" const");
10175 const std::string
&intermediate_name
= buf
.string ();
10177 if (cu
->language
== language_cplus
)
10179 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10180 &objfile
->per_bfd
->storage_obstack
);
10182 /* If we only computed INTERMEDIATE_NAME, or if
10183 INTERMEDIATE_NAME is already canonical, then we need to
10184 copy it to the appropriate obstack. */
10185 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10186 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10187 intermediate_name
);
10189 name
= canonical_name
;
10196 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10197 If scope qualifiers are appropriate they will be added. The result
10198 will be allocated on the storage_obstack, or NULL if the DIE does
10199 not have a name. NAME may either be from a previous call to
10200 dwarf2_name or NULL.
10202 The output string will be canonicalized (if C++). */
10204 static const char *
10205 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10207 return dwarf2_compute_name (name
, die
, cu
, 0);
10210 /* Construct a physname for the given DIE in CU. NAME may either be
10211 from a previous call to dwarf2_name or NULL. The result will be
10212 allocated on the objfile_objstack or NULL if the DIE does not have a
10215 The output string will be canonicalized (if C++). */
10217 static const char *
10218 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10220 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10221 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10224 /* In this case dwarf2_compute_name is just a shortcut not building anything
10226 if (!die_needs_namespace (die
, cu
))
10227 return dwarf2_compute_name (name
, die
, cu
, 1);
10229 mangled
= dw2_linkage_name (die
, cu
);
10231 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10232 See https://github.com/rust-lang/rust/issues/32925. */
10233 if (cu
->language
== language_rust
&& mangled
!= NULL
10234 && strchr (mangled
, '{') != NULL
)
10237 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10239 gdb::unique_xmalloc_ptr
<char> demangled
;
10240 if (mangled
!= NULL
)
10243 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10245 /* Do nothing (do not demangle the symbol name). */
10247 else if (cu
->language
== language_go
)
10249 /* This is a lie, but we already lie to the caller new_symbol.
10250 new_symbol assumes we return the mangled name.
10251 This just undoes that lie until things are cleaned up. */
10255 /* Use DMGL_RET_DROP for C++ template functions to suppress
10256 their return type. It is easier for GDB users to search
10257 for such functions as `name(params)' than `long name(params)'.
10258 In such case the minimal symbol names do not match the full
10259 symbol names but for template functions there is never a need
10260 to look up their definition from their declaration so
10261 the only disadvantage remains the minimal symbol variant
10262 `long name(params)' does not have the proper inferior type. */
10263 demangled
.reset (gdb_demangle (mangled
,
10264 (DMGL_PARAMS
| DMGL_ANSI
10265 | DMGL_RET_DROP
)));
10268 canon
= demangled
.get ();
10276 if (canon
== NULL
|| check_physname
)
10278 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10280 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10282 /* It may not mean a bug in GDB. The compiler could also
10283 compute DW_AT_linkage_name incorrectly. But in such case
10284 GDB would need to be bug-to-bug compatible. */
10286 complaint (_("Computed physname <%s> does not match demangled <%s> "
10287 "(from linkage <%s>) - DIE at %s [in module %s]"),
10288 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10289 objfile_name (objfile
));
10291 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10292 is available here - over computed PHYSNAME. It is safer
10293 against both buggy GDB and buggy compilers. */
10307 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
10312 /* Inspect DIE in CU for a namespace alias. If one exists, record
10313 a new symbol for it.
10315 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10318 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10320 struct attribute
*attr
;
10322 /* If the die does not have a name, this is not a namespace
10324 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10328 struct die_info
*d
= die
;
10329 struct dwarf2_cu
*imported_cu
= cu
;
10331 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10332 keep inspecting DIEs until we hit the underlying import. */
10333 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10334 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10336 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10340 d
= follow_die_ref (d
, attr
, &imported_cu
);
10341 if (d
->tag
!= DW_TAG_imported_declaration
)
10345 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10347 complaint (_("DIE at %s has too many recursively imported "
10348 "declarations"), sect_offset_str (d
->sect_off
));
10355 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10357 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10358 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10360 /* This declaration is a global namespace alias. Add
10361 a symbol for it whose type is the aliased namespace. */
10362 new_symbol (die
, type
, cu
);
10371 /* Return the using directives repository (global or local?) to use in the
10372 current context for CU.
10374 For Ada, imported declarations can materialize renamings, which *may* be
10375 global. However it is impossible (for now?) in DWARF to distinguish
10376 "external" imported declarations and "static" ones. As all imported
10377 declarations seem to be static in all other languages, make them all CU-wide
10378 global only in Ada. */
10380 static struct using_direct
**
10381 using_directives (struct dwarf2_cu
*cu
)
10383 if (cu
->language
== language_ada
10384 && cu
->get_builder ()->outermost_context_p ())
10385 return cu
->get_builder ()->get_global_using_directives ();
10387 return cu
->get_builder ()->get_local_using_directives ();
10390 /* Read the import statement specified by the given die and record it. */
10393 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10395 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10396 struct attribute
*import_attr
;
10397 struct die_info
*imported_die
, *child_die
;
10398 struct dwarf2_cu
*imported_cu
;
10399 const char *imported_name
;
10400 const char *imported_name_prefix
;
10401 const char *canonical_name
;
10402 const char *import_alias
;
10403 const char *imported_declaration
= NULL
;
10404 const char *import_prefix
;
10405 std::vector
<const char *> excludes
;
10407 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10408 if (import_attr
== NULL
)
10410 complaint (_("Tag '%s' has no DW_AT_import"),
10411 dwarf_tag_name (die
->tag
));
10416 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10417 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10418 if (imported_name
== NULL
)
10420 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10422 The import in the following code:
10436 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10437 <52> DW_AT_decl_file : 1
10438 <53> DW_AT_decl_line : 6
10439 <54> DW_AT_import : <0x75>
10440 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10441 <59> DW_AT_name : B
10442 <5b> DW_AT_decl_file : 1
10443 <5c> DW_AT_decl_line : 2
10444 <5d> DW_AT_type : <0x6e>
10446 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10447 <76> DW_AT_byte_size : 4
10448 <77> DW_AT_encoding : 5 (signed)
10450 imports the wrong die ( 0x75 instead of 0x58 ).
10451 This case will be ignored until the gcc bug is fixed. */
10455 /* Figure out the local name after import. */
10456 import_alias
= dwarf2_name (die
, cu
);
10458 /* Figure out where the statement is being imported to. */
10459 import_prefix
= determine_prefix (die
, cu
);
10461 /* Figure out what the scope of the imported die is and prepend it
10462 to the name of the imported die. */
10463 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10465 if (imported_die
->tag
!= DW_TAG_namespace
10466 && imported_die
->tag
!= DW_TAG_module
)
10468 imported_declaration
= imported_name
;
10469 canonical_name
= imported_name_prefix
;
10471 else if (strlen (imported_name_prefix
) > 0)
10472 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10473 imported_name_prefix
,
10474 (cu
->language
== language_d
? "." : "::"),
10475 imported_name
, (char *) NULL
);
10477 canonical_name
= imported_name
;
10479 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10480 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10481 child_die
= sibling_die (child_die
))
10483 /* DWARF-4: A Fortran use statement with a “rename list” may be
10484 represented by an imported module entry with an import attribute
10485 referring to the module and owned entries corresponding to those
10486 entities that are renamed as part of being imported. */
10488 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10490 complaint (_("child DW_TAG_imported_declaration expected "
10491 "- DIE at %s [in module %s]"),
10492 sect_offset_str (child_die
->sect_off
),
10493 objfile_name (objfile
));
10497 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10498 if (import_attr
== NULL
)
10500 complaint (_("Tag '%s' has no DW_AT_import"),
10501 dwarf_tag_name (child_die
->tag
));
10506 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10508 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10509 if (imported_name
== NULL
)
10511 complaint (_("child DW_TAG_imported_declaration has unknown "
10512 "imported name - DIE at %s [in module %s]"),
10513 sect_offset_str (child_die
->sect_off
),
10514 objfile_name (objfile
));
10518 excludes
.push_back (imported_name
);
10520 process_die (child_die
, cu
);
10523 add_using_directive (using_directives (cu
),
10527 imported_declaration
,
10530 &objfile
->objfile_obstack
);
10533 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10534 types, but gives them a size of zero. Starting with version 14,
10535 ICC is compatible with GCC. */
10538 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10540 if (!cu
->checked_producer
)
10541 check_producer (cu
);
10543 return cu
->producer_is_icc_lt_14
;
10546 /* ICC generates a DW_AT_type for C void functions. This was observed on
10547 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10548 which says that void functions should not have a DW_AT_type. */
10551 producer_is_icc (struct dwarf2_cu
*cu
)
10553 if (!cu
->checked_producer
)
10554 check_producer (cu
);
10556 return cu
->producer_is_icc
;
10559 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10560 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10561 this, it was first present in GCC release 4.3.0. */
10564 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10566 if (!cu
->checked_producer
)
10567 check_producer (cu
);
10569 return cu
->producer_is_gcc_lt_4_3
;
10572 static file_and_directory
10573 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10575 file_and_directory res
;
10577 /* Find the filename. Do not use dwarf2_name here, since the filename
10578 is not a source language identifier. */
10579 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10580 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10582 if (res
.comp_dir
== NULL
10583 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10584 && IS_ABSOLUTE_PATH (res
.name
))
10586 res
.comp_dir_storage
= ldirname (res
.name
);
10587 if (!res
.comp_dir_storage
.empty ())
10588 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10590 if (res
.comp_dir
!= NULL
)
10592 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10593 directory, get rid of it. */
10594 const char *cp
= strchr (res
.comp_dir
, ':');
10596 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10597 res
.comp_dir
= cp
+ 1;
10600 if (res
.name
== NULL
)
10601 res
.name
= "<unknown>";
10606 /* Handle DW_AT_stmt_list for a compilation unit.
10607 DIE is the DW_TAG_compile_unit die for CU.
10608 COMP_DIR is the compilation directory. LOWPC is passed to
10609 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10612 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10613 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10615 struct dwarf2_per_objfile
*dwarf2_per_objfile
10616 = cu
->per_cu
->dwarf2_per_objfile
;
10617 struct attribute
*attr
;
10618 struct line_header line_header_local
;
10619 hashval_t line_header_local_hash
;
10621 int decode_mapping
;
10623 gdb_assert (! cu
->per_cu
->is_debug_types
);
10625 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10629 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10631 /* The line header hash table is only created if needed (it exists to
10632 prevent redundant reading of the line table for partial_units).
10633 If we're given a partial_unit, we'll need it. If we're given a
10634 compile_unit, then use the line header hash table if it's already
10635 created, but don't create one just yet. */
10637 if (dwarf2_per_objfile
->line_header_hash
== NULL
10638 && die
->tag
== DW_TAG_partial_unit
)
10640 dwarf2_per_objfile
->line_header_hash
10641 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10642 line_header_eq_voidp
,
10643 free_line_header_voidp
,
10647 line_header_local
.sect_off
= line_offset
;
10648 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10649 line_header_local_hash
= line_header_hash (&line_header_local
);
10650 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10652 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10653 &line_header_local
,
10654 line_header_local_hash
, NO_INSERT
);
10656 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10657 is not present in *SLOT (since if there is something in *SLOT then
10658 it will be for a partial_unit). */
10659 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10661 gdb_assert (*slot
!= NULL
);
10662 cu
->line_header
= (struct line_header
*) *slot
;
10667 /* dwarf_decode_line_header does not yet provide sufficient information.
10668 We always have to call also dwarf_decode_lines for it. */
10669 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10673 cu
->line_header
= lh
.release ();
10674 cu
->line_header_die_owner
= die
;
10676 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10680 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10681 &line_header_local
,
10682 line_header_local_hash
, INSERT
);
10683 gdb_assert (slot
!= NULL
);
10685 if (slot
!= NULL
&& *slot
== NULL
)
10687 /* This newly decoded line number information unit will be owned
10688 by line_header_hash hash table. */
10689 *slot
= cu
->line_header
;
10690 cu
->line_header_die_owner
= NULL
;
10694 /* We cannot free any current entry in (*slot) as that struct line_header
10695 may be already used by multiple CUs. Create only temporary decoded
10696 line_header for this CU - it may happen at most once for each line
10697 number information unit. And if we're not using line_header_hash
10698 then this is what we want as well. */
10699 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10701 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10702 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10707 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10710 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10712 struct dwarf2_per_objfile
*dwarf2_per_objfile
10713 = cu
->per_cu
->dwarf2_per_objfile
;
10714 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10715 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10716 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10717 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10718 struct attribute
*attr
;
10719 struct die_info
*child_die
;
10720 CORE_ADDR baseaddr
;
10722 prepare_one_comp_unit (cu
, die
, cu
->language
);
10723 baseaddr
= objfile
->text_section_offset ();
10725 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10727 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10728 from finish_block. */
10729 if (lowpc
== ((CORE_ADDR
) -1))
10731 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10733 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10735 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10736 standardised yet. As a workaround for the language detection we fall
10737 back to the DW_AT_producer string. */
10738 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10739 cu
->language
= language_opencl
;
10741 /* Similar hack for Go. */
10742 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10743 set_cu_language (DW_LANG_Go
, cu
);
10745 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10747 /* Decode line number information if present. We do this before
10748 processing child DIEs, so that the line header table is available
10749 for DW_AT_decl_file. */
10750 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10752 /* Process all dies in compilation unit. */
10753 if (die
->child
!= NULL
)
10755 child_die
= die
->child
;
10756 while (child_die
&& child_die
->tag
)
10758 process_die (child_die
, cu
);
10759 child_die
= sibling_die (child_die
);
10763 /* Decode macro information, if present. Dwarf 2 macro information
10764 refers to information in the line number info statement program
10765 header, so we can only read it if we've read the header
10767 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10769 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10770 if (attr
&& cu
->line_header
)
10772 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10773 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10775 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10779 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10780 if (attr
&& cu
->line_header
)
10782 unsigned int macro_offset
= DW_UNSND (attr
);
10784 dwarf_decode_macros (cu
, macro_offset
, 0);
10790 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10792 struct type_unit_group
*tu_group
;
10794 struct attribute
*attr
;
10796 struct signatured_type
*sig_type
;
10798 gdb_assert (per_cu
->is_debug_types
);
10799 sig_type
= (struct signatured_type
*) per_cu
;
10801 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10803 /* If we're using .gdb_index (includes -readnow) then
10804 per_cu->type_unit_group may not have been set up yet. */
10805 if (sig_type
->type_unit_group
== NULL
)
10806 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10807 tu_group
= sig_type
->type_unit_group
;
10809 /* If we've already processed this stmt_list there's no real need to
10810 do it again, we could fake it and just recreate the part we need
10811 (file name,index -> symtab mapping). If data shows this optimization
10812 is useful we can do it then. */
10813 first_time
= tu_group
->compunit_symtab
== NULL
;
10815 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10820 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10821 lh
= dwarf_decode_line_header (line_offset
, this);
10826 start_symtab ("", NULL
, 0);
10829 gdb_assert (tu_group
->symtabs
== NULL
);
10830 gdb_assert (m_builder
== nullptr);
10831 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10832 m_builder
.reset (new struct buildsym_compunit
10833 (COMPUNIT_OBJFILE (cust
), "",
10834 COMPUNIT_DIRNAME (cust
),
10835 compunit_language (cust
),
10841 line_header
= lh
.release ();
10842 line_header_die_owner
= die
;
10846 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10848 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10849 still initializing it, and our caller (a few levels up)
10850 process_full_type_unit still needs to know if this is the first
10854 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10855 struct symtab
*, line_header
->file_names_size ());
10857 auto &file_names
= line_header
->file_names ();
10858 for (i
= 0; i
< file_names
.size (); ++i
)
10860 file_entry
&fe
= file_names
[i
];
10861 dwarf2_start_subfile (this, fe
.name
,
10862 fe
.include_dir (line_header
));
10863 buildsym_compunit
*b
= get_builder ();
10864 if (b
->get_current_subfile ()->symtab
== NULL
)
10866 /* NOTE: start_subfile will recognize when it's been
10867 passed a file it has already seen. So we can't
10868 assume there's a simple mapping from
10869 cu->line_header->file_names to subfiles, plus
10870 cu->line_header->file_names may contain dups. */
10871 b
->get_current_subfile ()->symtab
10872 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10875 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10876 tu_group
->symtabs
[i
] = fe
.symtab
;
10881 gdb_assert (m_builder
== nullptr);
10882 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10883 m_builder
.reset (new struct buildsym_compunit
10884 (COMPUNIT_OBJFILE (cust
), "",
10885 COMPUNIT_DIRNAME (cust
),
10886 compunit_language (cust
),
10889 auto &file_names
= line_header
->file_names ();
10890 for (i
= 0; i
< file_names
.size (); ++i
)
10892 file_entry
&fe
= file_names
[i
];
10893 fe
.symtab
= tu_group
->symtabs
[i
];
10897 /* The main symtab is allocated last. Type units don't have DW_AT_name
10898 so they don't have a "real" (so to speak) symtab anyway.
10899 There is later code that will assign the main symtab to all symbols
10900 that don't have one. We need to handle the case of a symbol with a
10901 missing symtab (DW_AT_decl_file) anyway. */
10904 /* Process DW_TAG_type_unit.
10905 For TUs we want to skip the first top level sibling if it's not the
10906 actual type being defined by this TU. In this case the first top
10907 level sibling is there to provide context only. */
10910 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10912 struct die_info
*child_die
;
10914 prepare_one_comp_unit (cu
, die
, language_minimal
);
10916 /* Initialize (or reinitialize) the machinery for building symtabs.
10917 We do this before processing child DIEs, so that the line header table
10918 is available for DW_AT_decl_file. */
10919 cu
->setup_type_unit_groups (die
);
10921 if (die
->child
!= NULL
)
10923 child_die
= die
->child
;
10924 while (child_die
&& child_die
->tag
)
10926 process_die (child_die
, cu
);
10927 child_die
= sibling_die (child_die
);
10934 http://gcc.gnu.org/wiki/DebugFission
10935 http://gcc.gnu.org/wiki/DebugFissionDWP
10937 To simplify handling of both DWO files ("object" files with the DWARF info)
10938 and DWP files (a file with the DWOs packaged up into one file), we treat
10939 DWP files as having a collection of virtual DWO files. */
10942 hash_dwo_file (const void *item
)
10944 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10947 hash
= htab_hash_string (dwo_file
->dwo_name
);
10948 if (dwo_file
->comp_dir
!= NULL
)
10949 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10954 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10956 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10957 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10959 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10961 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10962 return lhs
->comp_dir
== rhs
->comp_dir
;
10963 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10966 /* Allocate a hash table for DWO files. */
10969 allocate_dwo_file_hash_table ()
10971 auto delete_dwo_file
= [] (void *item
)
10973 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10978 return htab_up (htab_create_alloc (41,
10985 /* Lookup DWO file DWO_NAME. */
10988 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
10989 const char *dwo_name
,
10990 const char *comp_dir
)
10992 struct dwo_file find_entry
;
10995 if (dwarf2_per_objfile
->dwo_files
== NULL
)
10996 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
10998 find_entry
.dwo_name
= dwo_name
;
10999 find_entry
.comp_dir
= comp_dir
;
11000 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11007 hash_dwo_unit (const void *item
)
11009 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11011 /* This drops the top 32 bits of the id, but is ok for a hash. */
11012 return dwo_unit
->signature
;
11016 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11018 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11019 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11021 /* The signature is assumed to be unique within the DWO file.
11022 So while object file CU dwo_id's always have the value zero,
11023 that's OK, assuming each object file DWO file has only one CU,
11024 and that's the rule for now. */
11025 return lhs
->signature
== rhs
->signature
;
11028 /* Allocate a hash table for DWO CUs,TUs.
11029 There is one of these tables for each of CUs,TUs for each DWO file. */
11032 allocate_dwo_unit_table ()
11034 /* Start out with a pretty small number.
11035 Generally DWO files contain only one CU and maybe some TUs. */
11036 return htab_up (htab_create_alloc (3,
11039 NULL
, xcalloc
, xfree
));
11042 /* die_reader_func for create_dwo_cu. */
11045 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11046 const gdb_byte
*info_ptr
,
11047 struct die_info
*comp_unit_die
,
11048 struct dwo_file
*dwo_file
,
11049 struct dwo_unit
*dwo_unit
)
11051 struct dwarf2_cu
*cu
= reader
->cu
;
11052 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11053 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11055 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11056 if (!signature
.has_value ())
11058 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11059 " its dwo_id [in module %s]"),
11060 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11064 dwo_unit
->dwo_file
= dwo_file
;
11065 dwo_unit
->signature
= *signature
;
11066 dwo_unit
->section
= section
;
11067 dwo_unit
->sect_off
= sect_off
;
11068 dwo_unit
->length
= cu
->per_cu
->length
;
11070 if (dwarf_read_debug
)
11071 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11072 sect_offset_str (sect_off
),
11073 hex_string (dwo_unit
->signature
));
11076 /* Create the dwo_units for the CUs in a DWO_FILE.
11077 Note: This function processes DWO files only, not DWP files. */
11080 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11081 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11082 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11084 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11085 const gdb_byte
*info_ptr
, *end_ptr
;
11087 section
.read (objfile
);
11088 info_ptr
= section
.buffer
;
11090 if (info_ptr
== NULL
)
11093 if (dwarf_read_debug
)
11095 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11096 section
.get_name (),
11097 section
.get_file_name ());
11100 end_ptr
= info_ptr
+ section
.size
;
11101 while (info_ptr
< end_ptr
)
11103 struct dwarf2_per_cu_data per_cu
;
11104 struct dwo_unit read_unit
{};
11105 struct dwo_unit
*dwo_unit
;
11107 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11109 memset (&per_cu
, 0, sizeof (per_cu
));
11110 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11111 per_cu
.is_debug_types
= 0;
11112 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11113 per_cu
.section
= §ion
;
11115 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11116 if (!reader
.dummy_p
)
11117 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11118 &dwo_file
, &read_unit
);
11119 info_ptr
+= per_cu
.length
;
11121 // If the unit could not be parsed, skip it.
11122 if (read_unit
.dwo_file
== NULL
)
11125 if (cus_htab
== NULL
)
11126 cus_htab
= allocate_dwo_unit_table ();
11128 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11129 *dwo_unit
= read_unit
;
11130 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11131 gdb_assert (slot
!= NULL
);
11134 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11135 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11137 complaint (_("debug cu entry at offset %s is duplicate to"
11138 " the entry at offset %s, signature %s"),
11139 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11140 hex_string (dwo_unit
->signature
));
11142 *slot
= (void *)dwo_unit
;
11146 /* DWP file .debug_{cu,tu}_index section format:
11147 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11151 Both index sections have the same format, and serve to map a 64-bit
11152 signature to a set of section numbers. Each section begins with a header,
11153 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11154 indexes, and a pool of 32-bit section numbers. The index sections will be
11155 aligned at 8-byte boundaries in the file.
11157 The index section header consists of:
11159 V, 32 bit version number
11161 N, 32 bit number of compilation units or type units in the index
11162 M, 32 bit number of slots in the hash table
11164 Numbers are recorded using the byte order of the application binary.
11166 The hash table begins at offset 16 in the section, and consists of an array
11167 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11168 order of the application binary). Unused slots in the hash table are 0.
11169 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11171 The parallel table begins immediately after the hash table
11172 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11173 array of 32-bit indexes (using the byte order of the application binary),
11174 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11175 table contains a 32-bit index into the pool of section numbers. For unused
11176 hash table slots, the corresponding entry in the parallel table will be 0.
11178 The pool of section numbers begins immediately following the hash table
11179 (at offset 16 + 12 * M from the beginning of the section). The pool of
11180 section numbers consists of an array of 32-bit words (using the byte order
11181 of the application binary). Each item in the array is indexed starting
11182 from 0. The hash table entry provides the index of the first section
11183 number in the set. Additional section numbers in the set follow, and the
11184 set is terminated by a 0 entry (section number 0 is not used in ELF).
11186 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11187 section must be the first entry in the set, and the .debug_abbrev.dwo must
11188 be the second entry. Other members of the set may follow in any order.
11194 DWP Version 2 combines all the .debug_info, etc. sections into one,
11195 and the entries in the index tables are now offsets into these sections.
11196 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11199 Index Section Contents:
11201 Hash Table of Signatures dwp_hash_table.hash_table
11202 Parallel Table of Indices dwp_hash_table.unit_table
11203 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11204 Table of Section Sizes dwp_hash_table.v2.sizes
11206 The index section header consists of:
11208 V, 32 bit version number
11209 L, 32 bit number of columns in the table of section offsets
11210 N, 32 bit number of compilation units or type units in the index
11211 M, 32 bit number of slots in the hash table
11213 Numbers are recorded using the byte order of the application binary.
11215 The hash table has the same format as version 1.
11216 The parallel table of indices has the same format as version 1,
11217 except that the entries are origin-1 indices into the table of sections
11218 offsets and the table of section sizes.
11220 The table of offsets begins immediately following the parallel table
11221 (at offset 16 + 12 * M from the beginning of the section). The table is
11222 a two-dimensional array of 32-bit words (using the byte order of the
11223 application binary), with L columns and N+1 rows, in row-major order.
11224 Each row in the array is indexed starting from 0. The first row provides
11225 a key to the remaining rows: each column in this row provides an identifier
11226 for a debug section, and the offsets in the same column of subsequent rows
11227 refer to that section. The section identifiers are:
11229 DW_SECT_INFO 1 .debug_info.dwo
11230 DW_SECT_TYPES 2 .debug_types.dwo
11231 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11232 DW_SECT_LINE 4 .debug_line.dwo
11233 DW_SECT_LOC 5 .debug_loc.dwo
11234 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11235 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11236 DW_SECT_MACRO 8 .debug_macro.dwo
11238 The offsets provided by the CU and TU index sections are the base offsets
11239 for the contributions made by each CU or TU to the corresponding section
11240 in the package file. Each CU and TU header contains an abbrev_offset
11241 field, used to find the abbreviations table for that CU or TU within the
11242 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11243 be interpreted as relative to the base offset given in the index section.
11244 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11245 should be interpreted as relative to the base offset for .debug_line.dwo,
11246 and offsets into other debug sections obtained from DWARF attributes should
11247 also be interpreted as relative to the corresponding base offset.
11249 The table of sizes begins immediately following the table of offsets.
11250 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11251 with L columns and N rows, in row-major order. Each row in the array is
11252 indexed starting from 1 (row 0 is shared by the two tables).
11256 Hash table lookup is handled the same in version 1 and 2:
11258 We assume that N and M will not exceed 2^32 - 1.
11259 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11261 Given a 64-bit compilation unit signature or a type signature S, an entry
11262 in the hash table is located as follows:
11264 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11265 the low-order k bits all set to 1.
11267 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11269 3) If the hash table entry at index H matches the signature, use that
11270 entry. If the hash table entry at index H is unused (all zeroes),
11271 terminate the search: the signature is not present in the table.
11273 4) Let H = (H + H') modulo M. Repeat at Step 3.
11275 Because M > N and H' and M are relatively prime, the search is guaranteed
11276 to stop at an unused slot or find the match. */
11278 /* Create a hash table to map DWO IDs to their CU/TU entry in
11279 .debug_{info,types}.dwo in DWP_FILE.
11280 Returns NULL if there isn't one.
11281 Note: This function processes DWP files only, not DWO files. */
11283 static struct dwp_hash_table
*
11284 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11285 struct dwp_file
*dwp_file
, int is_debug_types
)
11287 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11288 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11289 const gdb_byte
*index_ptr
, *index_end
;
11290 struct dwarf2_section_info
*index
;
11291 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11292 struct dwp_hash_table
*htab
;
11294 if (is_debug_types
)
11295 index
= &dwp_file
->sections
.tu_index
;
11297 index
= &dwp_file
->sections
.cu_index
;
11299 if (index
->empty ())
11301 index
->read (objfile
);
11303 index_ptr
= index
->buffer
;
11304 index_end
= index_ptr
+ index
->size
;
11306 version
= read_4_bytes (dbfd
, index_ptr
);
11309 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11313 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11315 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11318 if (version
!= 1 && version
!= 2)
11320 error (_("Dwarf Error: unsupported DWP file version (%s)"
11321 " [in module %s]"),
11322 pulongest (version
), dwp_file
->name
);
11324 if (nr_slots
!= (nr_slots
& -nr_slots
))
11326 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11327 " is not power of 2 [in module %s]"),
11328 pulongest (nr_slots
), dwp_file
->name
);
11331 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11332 htab
->version
= version
;
11333 htab
->nr_columns
= nr_columns
;
11334 htab
->nr_units
= nr_units
;
11335 htab
->nr_slots
= nr_slots
;
11336 htab
->hash_table
= index_ptr
;
11337 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11339 /* Exit early if the table is empty. */
11340 if (nr_slots
== 0 || nr_units
== 0
11341 || (version
== 2 && nr_columns
== 0))
11343 /* All must be zero. */
11344 if (nr_slots
!= 0 || nr_units
!= 0
11345 || (version
== 2 && nr_columns
!= 0))
11347 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11348 " all zero [in modules %s]"),
11356 htab
->section_pool
.v1
.indices
=
11357 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11358 /* It's harder to decide whether the section is too small in v1.
11359 V1 is deprecated anyway so we punt. */
11363 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11364 int *ids
= htab
->section_pool
.v2
.section_ids
;
11365 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11366 /* Reverse map for error checking. */
11367 int ids_seen
[DW_SECT_MAX
+ 1];
11370 if (nr_columns
< 2)
11372 error (_("Dwarf Error: bad DWP hash table, too few columns"
11373 " in section table [in module %s]"),
11376 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11378 error (_("Dwarf Error: bad DWP hash table, too many columns"
11379 " in section table [in module %s]"),
11382 memset (ids
, 255, sizeof_ids
);
11383 memset (ids_seen
, 255, sizeof (ids_seen
));
11384 for (i
= 0; i
< nr_columns
; ++i
)
11386 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11388 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11390 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11391 " in section table [in module %s]"),
11392 id
, dwp_file
->name
);
11394 if (ids_seen
[id
] != -1)
11396 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11397 " id %d in section table [in module %s]"),
11398 id
, dwp_file
->name
);
11403 /* Must have exactly one info or types section. */
11404 if (((ids_seen
[DW_SECT_INFO
] != -1)
11405 + (ids_seen
[DW_SECT_TYPES
] != -1))
11408 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11409 " DWO info/types section [in module %s]"),
11412 /* Must have an abbrev section. */
11413 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11415 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11416 " section [in module %s]"),
11419 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11420 htab
->section_pool
.v2
.sizes
=
11421 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11422 * nr_units
* nr_columns
);
11423 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11424 * nr_units
* nr_columns
))
11427 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11428 " [in module %s]"),
11436 /* Update SECTIONS with the data from SECTP.
11438 This function is like the other "locate" section routines that are
11439 passed to bfd_map_over_sections, but in this context the sections to
11440 read comes from the DWP V1 hash table, not the full ELF section table.
11442 The result is non-zero for success, or zero if an error was found. */
11445 locate_v1_virtual_dwo_sections (asection
*sectp
,
11446 struct virtual_v1_dwo_sections
*sections
)
11448 const struct dwop_section_names
*names
= &dwop_section_names
;
11450 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11452 /* There can be only one. */
11453 if (sections
->abbrev
.s
.section
!= NULL
)
11455 sections
->abbrev
.s
.section
= sectp
;
11456 sections
->abbrev
.size
= bfd_section_size (sectp
);
11458 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11459 || section_is_p (sectp
->name
, &names
->types_dwo
))
11461 /* There can be only one. */
11462 if (sections
->info_or_types
.s
.section
!= NULL
)
11464 sections
->info_or_types
.s
.section
= sectp
;
11465 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11467 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11469 /* There can be only one. */
11470 if (sections
->line
.s
.section
!= NULL
)
11472 sections
->line
.s
.section
= sectp
;
11473 sections
->line
.size
= bfd_section_size (sectp
);
11475 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11477 /* There can be only one. */
11478 if (sections
->loc
.s
.section
!= NULL
)
11480 sections
->loc
.s
.section
= sectp
;
11481 sections
->loc
.size
= bfd_section_size (sectp
);
11483 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11485 /* There can be only one. */
11486 if (sections
->macinfo
.s
.section
!= NULL
)
11488 sections
->macinfo
.s
.section
= sectp
;
11489 sections
->macinfo
.size
= bfd_section_size (sectp
);
11491 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11493 /* There can be only one. */
11494 if (sections
->macro
.s
.section
!= NULL
)
11496 sections
->macro
.s
.section
= sectp
;
11497 sections
->macro
.size
= bfd_section_size (sectp
);
11499 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11501 /* There can be only one. */
11502 if (sections
->str_offsets
.s
.section
!= NULL
)
11504 sections
->str_offsets
.s
.section
= sectp
;
11505 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11509 /* No other kind of section is valid. */
11516 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11517 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11518 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11519 This is for DWP version 1 files. */
11521 static struct dwo_unit
*
11522 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11523 struct dwp_file
*dwp_file
,
11524 uint32_t unit_index
,
11525 const char *comp_dir
,
11526 ULONGEST signature
, int is_debug_types
)
11528 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11529 const struct dwp_hash_table
*dwp_htab
=
11530 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11531 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11532 const char *kind
= is_debug_types
? "TU" : "CU";
11533 struct dwo_file
*dwo_file
;
11534 struct dwo_unit
*dwo_unit
;
11535 struct virtual_v1_dwo_sections sections
;
11536 void **dwo_file_slot
;
11539 gdb_assert (dwp_file
->version
== 1);
11541 if (dwarf_read_debug
)
11543 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11545 pulongest (unit_index
), hex_string (signature
),
11549 /* Fetch the sections of this DWO unit.
11550 Put a limit on the number of sections we look for so that bad data
11551 doesn't cause us to loop forever. */
11553 #define MAX_NR_V1_DWO_SECTIONS \
11554 (1 /* .debug_info or .debug_types */ \
11555 + 1 /* .debug_abbrev */ \
11556 + 1 /* .debug_line */ \
11557 + 1 /* .debug_loc */ \
11558 + 1 /* .debug_str_offsets */ \
11559 + 1 /* .debug_macro or .debug_macinfo */ \
11560 + 1 /* trailing zero */)
11562 memset (§ions
, 0, sizeof (sections
));
11564 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11567 uint32_t section_nr
=
11568 read_4_bytes (dbfd
,
11569 dwp_htab
->section_pool
.v1
.indices
11570 + (unit_index
+ i
) * sizeof (uint32_t));
11572 if (section_nr
== 0)
11574 if (section_nr
>= dwp_file
->num_sections
)
11576 error (_("Dwarf Error: bad DWP hash table, section number too large"
11577 " [in module %s]"),
11581 sectp
= dwp_file
->elf_sections
[section_nr
];
11582 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11584 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11585 " [in module %s]"),
11591 || sections
.info_or_types
.empty ()
11592 || sections
.abbrev
.empty ())
11594 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11595 " [in module %s]"),
11598 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11600 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11601 " [in module %s]"),
11605 /* It's easier for the rest of the code if we fake a struct dwo_file and
11606 have dwo_unit "live" in that. At least for now.
11608 The DWP file can be made up of a random collection of CUs and TUs.
11609 However, for each CU + set of TUs that came from the same original DWO
11610 file, we can combine them back into a virtual DWO file to save space
11611 (fewer struct dwo_file objects to allocate). Remember that for really
11612 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11614 std::string virtual_dwo_name
=
11615 string_printf ("virtual-dwo/%d-%d-%d-%d",
11616 sections
.abbrev
.get_id (),
11617 sections
.line
.get_id (),
11618 sections
.loc
.get_id (),
11619 sections
.str_offsets
.get_id ());
11620 /* Can we use an existing virtual DWO file? */
11621 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11622 virtual_dwo_name
.c_str (),
11624 /* Create one if necessary. */
11625 if (*dwo_file_slot
== NULL
)
11627 if (dwarf_read_debug
)
11629 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11630 virtual_dwo_name
.c_str ());
11632 dwo_file
= new struct dwo_file
;
11633 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11635 dwo_file
->comp_dir
= comp_dir
;
11636 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11637 dwo_file
->sections
.line
= sections
.line
;
11638 dwo_file
->sections
.loc
= sections
.loc
;
11639 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11640 dwo_file
->sections
.macro
= sections
.macro
;
11641 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11642 /* The "str" section is global to the entire DWP file. */
11643 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11644 /* The info or types section is assigned below to dwo_unit,
11645 there's no need to record it in dwo_file.
11646 Also, we can't simply record type sections in dwo_file because
11647 we record a pointer into the vector in dwo_unit. As we collect more
11648 types we'll grow the vector and eventually have to reallocate space
11649 for it, invalidating all copies of pointers into the previous
11651 *dwo_file_slot
= dwo_file
;
11655 if (dwarf_read_debug
)
11657 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11658 virtual_dwo_name
.c_str ());
11660 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11663 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11664 dwo_unit
->dwo_file
= dwo_file
;
11665 dwo_unit
->signature
= signature
;
11666 dwo_unit
->section
=
11667 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11668 *dwo_unit
->section
= sections
.info_or_types
;
11669 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11674 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11675 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11676 piece within that section used by a TU/CU, return a virtual section
11677 of just that piece. */
11679 static struct dwarf2_section_info
11680 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11681 struct dwarf2_section_info
*section
,
11682 bfd_size_type offset
, bfd_size_type size
)
11684 struct dwarf2_section_info result
;
11687 gdb_assert (section
!= NULL
);
11688 gdb_assert (!section
->is_virtual
);
11690 memset (&result
, 0, sizeof (result
));
11691 result
.s
.containing_section
= section
;
11692 result
.is_virtual
= true;
11697 sectp
= section
->get_bfd_section ();
11699 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11700 bounds of the real section. This is a pretty-rare event, so just
11701 flag an error (easier) instead of a warning and trying to cope. */
11703 || offset
+ size
> bfd_section_size (sectp
))
11705 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11706 " in section %s [in module %s]"),
11707 sectp
? bfd_section_name (sectp
) : "<unknown>",
11708 objfile_name (dwarf2_per_objfile
->objfile
));
11711 result
.virtual_offset
= offset
;
11712 result
.size
= size
;
11716 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11717 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11718 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11719 This is for DWP version 2 files. */
11721 static struct dwo_unit
*
11722 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11723 struct dwp_file
*dwp_file
,
11724 uint32_t unit_index
,
11725 const char *comp_dir
,
11726 ULONGEST signature
, int is_debug_types
)
11728 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11729 const struct dwp_hash_table
*dwp_htab
=
11730 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11731 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11732 const char *kind
= is_debug_types
? "TU" : "CU";
11733 struct dwo_file
*dwo_file
;
11734 struct dwo_unit
*dwo_unit
;
11735 struct virtual_v2_dwo_sections sections
;
11736 void **dwo_file_slot
;
11739 gdb_assert (dwp_file
->version
== 2);
11741 if (dwarf_read_debug
)
11743 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11745 pulongest (unit_index
), hex_string (signature
),
11749 /* Fetch the section offsets of this DWO unit. */
11751 memset (§ions
, 0, sizeof (sections
));
11753 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11755 uint32_t offset
= read_4_bytes (dbfd
,
11756 dwp_htab
->section_pool
.v2
.offsets
11757 + (((unit_index
- 1) * dwp_htab
->nr_columns
11759 * sizeof (uint32_t)));
11760 uint32_t size
= read_4_bytes (dbfd
,
11761 dwp_htab
->section_pool
.v2
.sizes
11762 + (((unit_index
- 1) * dwp_htab
->nr_columns
11764 * sizeof (uint32_t)));
11766 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11769 case DW_SECT_TYPES
:
11770 sections
.info_or_types_offset
= offset
;
11771 sections
.info_or_types_size
= size
;
11773 case DW_SECT_ABBREV
:
11774 sections
.abbrev_offset
= offset
;
11775 sections
.abbrev_size
= size
;
11778 sections
.line_offset
= offset
;
11779 sections
.line_size
= size
;
11782 sections
.loc_offset
= offset
;
11783 sections
.loc_size
= size
;
11785 case DW_SECT_STR_OFFSETS
:
11786 sections
.str_offsets_offset
= offset
;
11787 sections
.str_offsets_size
= size
;
11789 case DW_SECT_MACINFO
:
11790 sections
.macinfo_offset
= offset
;
11791 sections
.macinfo_size
= size
;
11793 case DW_SECT_MACRO
:
11794 sections
.macro_offset
= offset
;
11795 sections
.macro_size
= size
;
11800 /* It's easier for the rest of the code if we fake a struct dwo_file and
11801 have dwo_unit "live" in that. At least for now.
11803 The DWP file can be made up of a random collection of CUs and TUs.
11804 However, for each CU + set of TUs that came from the same original DWO
11805 file, we can combine them back into a virtual DWO file to save space
11806 (fewer struct dwo_file objects to allocate). Remember that for really
11807 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11809 std::string virtual_dwo_name
=
11810 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11811 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11812 (long) (sections
.line_size
? sections
.line_offset
: 0),
11813 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11814 (long) (sections
.str_offsets_size
11815 ? sections
.str_offsets_offset
: 0));
11816 /* Can we use an existing virtual DWO file? */
11817 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11818 virtual_dwo_name
.c_str (),
11820 /* Create one if necessary. */
11821 if (*dwo_file_slot
== NULL
)
11823 if (dwarf_read_debug
)
11825 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11826 virtual_dwo_name
.c_str ());
11828 dwo_file
= new struct dwo_file
;
11829 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11831 dwo_file
->comp_dir
= comp_dir
;
11832 dwo_file
->sections
.abbrev
=
11833 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11834 sections
.abbrev_offset
, sections
.abbrev_size
);
11835 dwo_file
->sections
.line
=
11836 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11837 sections
.line_offset
, sections
.line_size
);
11838 dwo_file
->sections
.loc
=
11839 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11840 sections
.loc_offset
, sections
.loc_size
);
11841 dwo_file
->sections
.macinfo
=
11842 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11843 sections
.macinfo_offset
, sections
.macinfo_size
);
11844 dwo_file
->sections
.macro
=
11845 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11846 sections
.macro_offset
, sections
.macro_size
);
11847 dwo_file
->sections
.str_offsets
=
11848 create_dwp_v2_section (dwarf2_per_objfile
,
11849 &dwp_file
->sections
.str_offsets
,
11850 sections
.str_offsets_offset
,
11851 sections
.str_offsets_size
);
11852 /* The "str" section is global to the entire DWP file. */
11853 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11854 /* The info or types section is assigned below to dwo_unit,
11855 there's no need to record it in dwo_file.
11856 Also, we can't simply record type sections in dwo_file because
11857 we record a pointer into the vector in dwo_unit. As we collect more
11858 types we'll grow the vector and eventually have to reallocate space
11859 for it, invalidating all copies of pointers into the previous
11861 *dwo_file_slot
= dwo_file
;
11865 if (dwarf_read_debug
)
11867 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11868 virtual_dwo_name
.c_str ());
11870 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11873 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11874 dwo_unit
->dwo_file
= dwo_file
;
11875 dwo_unit
->signature
= signature
;
11876 dwo_unit
->section
=
11877 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11878 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11880 ? &dwp_file
->sections
.types
11881 : &dwp_file
->sections
.info
,
11882 sections
.info_or_types_offset
,
11883 sections
.info_or_types_size
);
11884 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11889 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11890 Returns NULL if the signature isn't found. */
11892 static struct dwo_unit
*
11893 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11894 struct dwp_file
*dwp_file
, const char *comp_dir
,
11895 ULONGEST signature
, int is_debug_types
)
11897 const struct dwp_hash_table
*dwp_htab
=
11898 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11899 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11900 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11901 uint32_t hash
= signature
& mask
;
11902 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11905 struct dwo_unit find_dwo_cu
;
11907 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11908 find_dwo_cu
.signature
= signature
;
11909 slot
= htab_find_slot (is_debug_types
11910 ? dwp_file
->loaded_tus
.get ()
11911 : dwp_file
->loaded_cus
.get (),
11912 &find_dwo_cu
, INSERT
);
11915 return (struct dwo_unit
*) *slot
;
11917 /* Use a for loop so that we don't loop forever on bad debug info. */
11918 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11920 ULONGEST signature_in_table
;
11922 signature_in_table
=
11923 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11924 if (signature_in_table
== signature
)
11926 uint32_t unit_index
=
11927 read_4_bytes (dbfd
,
11928 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11930 if (dwp_file
->version
== 1)
11932 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11933 dwp_file
, unit_index
,
11934 comp_dir
, signature
,
11939 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11940 dwp_file
, unit_index
,
11941 comp_dir
, signature
,
11944 return (struct dwo_unit
*) *slot
;
11946 if (signature_in_table
== 0)
11948 hash
= (hash
+ hash2
) & mask
;
11951 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11952 " [in module %s]"),
11956 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11957 Open the file specified by FILE_NAME and hand it off to BFD for
11958 preliminary analysis. Return a newly initialized bfd *, which
11959 includes a canonicalized copy of FILE_NAME.
11960 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11961 SEARCH_CWD is true if the current directory is to be searched.
11962 It will be searched before debug-file-directory.
11963 If successful, the file is added to the bfd include table of the
11964 objfile's bfd (see gdb_bfd_record_inclusion).
11965 If unable to find/open the file, return NULL.
11966 NOTE: This function is derived from symfile_bfd_open. */
11968 static gdb_bfd_ref_ptr
11969 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11970 const char *file_name
, int is_dwp
, int search_cwd
)
11973 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11974 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11975 to debug_file_directory. */
11976 const char *search_path
;
11977 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11979 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11982 if (*debug_file_directory
!= '\0')
11984 search_path_holder
.reset (concat (".", dirname_separator_string
,
11985 debug_file_directory
,
11987 search_path
= search_path_holder
.get ();
11993 search_path
= debug_file_directory
;
11995 openp_flags flags
= OPF_RETURN_REALPATH
;
11997 flags
|= OPF_SEARCH_IN_PATH
;
11999 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12000 desc
= openp (search_path
, flags
, file_name
,
12001 O_RDONLY
| O_BINARY
, &absolute_name
);
12005 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12007 if (sym_bfd
== NULL
)
12009 bfd_set_cacheable (sym_bfd
.get (), 1);
12011 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12014 /* Success. Record the bfd as having been included by the objfile's bfd.
12015 This is important because things like demangled_names_hash lives in the
12016 objfile's per_bfd space and may have references to things like symbol
12017 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12018 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12023 /* Try to open DWO file FILE_NAME.
12024 COMP_DIR is the DW_AT_comp_dir attribute.
12025 The result is the bfd handle of the file.
12026 If there is a problem finding or opening the file, return NULL.
12027 Upon success, the canonicalized path of the file is stored in the bfd,
12028 same as symfile_bfd_open. */
12030 static gdb_bfd_ref_ptr
12031 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12032 const char *file_name
, const char *comp_dir
)
12034 if (IS_ABSOLUTE_PATH (file_name
))
12035 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12036 0 /*is_dwp*/, 0 /*search_cwd*/);
12038 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12040 if (comp_dir
!= NULL
)
12042 gdb::unique_xmalloc_ptr
<char> path_to_try
12043 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12045 /* NOTE: If comp_dir is a relative path, this will also try the
12046 search path, which seems useful. */
12047 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12048 path_to_try
.get (),
12050 1 /*search_cwd*/));
12055 /* That didn't work, try debug-file-directory, which, despite its name,
12056 is a list of paths. */
12058 if (*debug_file_directory
== '\0')
12061 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12062 0 /*is_dwp*/, 1 /*search_cwd*/);
12065 /* This function is mapped across the sections and remembers the offset and
12066 size of each of the DWO debugging sections we are interested in. */
12069 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12071 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12072 const struct dwop_section_names
*names
= &dwop_section_names
;
12074 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12076 dwo_sections
->abbrev
.s
.section
= sectp
;
12077 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12079 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12081 dwo_sections
->info
.s
.section
= sectp
;
12082 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12084 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12086 dwo_sections
->line
.s
.section
= sectp
;
12087 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12089 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12091 dwo_sections
->loc
.s
.section
= sectp
;
12092 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12094 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12096 dwo_sections
->macinfo
.s
.section
= sectp
;
12097 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12099 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12101 dwo_sections
->macro
.s
.section
= sectp
;
12102 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12104 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12106 dwo_sections
->str
.s
.section
= sectp
;
12107 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12109 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12111 dwo_sections
->str_offsets
.s
.section
= sectp
;
12112 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12114 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12116 struct dwarf2_section_info type_section
;
12118 memset (&type_section
, 0, sizeof (type_section
));
12119 type_section
.s
.section
= sectp
;
12120 type_section
.size
= bfd_section_size (sectp
);
12121 dwo_sections
->types
.push_back (type_section
);
12125 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12126 by PER_CU. This is for the non-DWP case.
12127 The result is NULL if DWO_NAME can't be found. */
12129 static struct dwo_file
*
12130 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12131 const char *dwo_name
, const char *comp_dir
)
12133 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12135 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12138 if (dwarf_read_debug
)
12139 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12143 dwo_file_up
dwo_file (new struct dwo_file
);
12144 dwo_file
->dwo_name
= dwo_name
;
12145 dwo_file
->comp_dir
= comp_dir
;
12146 dwo_file
->dbfd
= std::move (dbfd
);
12148 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12149 &dwo_file
->sections
);
12151 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12152 dwo_file
->sections
.info
, dwo_file
->cus
);
12154 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12155 dwo_file
->sections
.types
, dwo_file
->tus
);
12157 if (dwarf_read_debug
)
12158 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12160 return dwo_file
.release ();
12163 /* This function is mapped across the sections and remembers the offset and
12164 size of each of the DWP debugging sections common to version 1 and 2 that
12165 we are interested in. */
12168 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12169 void *dwp_file_ptr
)
12171 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12172 const struct dwop_section_names
*names
= &dwop_section_names
;
12173 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12175 /* Record the ELF section number for later lookup: this is what the
12176 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12177 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12178 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12180 /* Look for specific sections that we need. */
12181 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12183 dwp_file
->sections
.str
.s
.section
= sectp
;
12184 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12186 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12188 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12189 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12191 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12193 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12194 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12198 /* This function is mapped across the sections and remembers the offset and
12199 size of each of the DWP version 2 debugging sections that we are interested
12200 in. This is split into a separate function because we don't know if we
12201 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12204 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12206 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12207 const struct dwop_section_names
*names
= &dwop_section_names
;
12208 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12210 /* Record the ELF section number for later lookup: this is what the
12211 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12212 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12213 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12215 /* Look for specific sections that we need. */
12216 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12218 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12219 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12221 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12223 dwp_file
->sections
.info
.s
.section
= sectp
;
12224 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12226 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12228 dwp_file
->sections
.line
.s
.section
= sectp
;
12229 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12231 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12233 dwp_file
->sections
.loc
.s
.section
= sectp
;
12234 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12236 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12238 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12239 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12241 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12243 dwp_file
->sections
.macro
.s
.section
= sectp
;
12244 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12246 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12248 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12249 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12251 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12253 dwp_file
->sections
.types
.s
.section
= sectp
;
12254 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12258 /* Hash function for dwp_file loaded CUs/TUs. */
12261 hash_dwp_loaded_cutus (const void *item
)
12263 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12265 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12266 return dwo_unit
->signature
;
12269 /* Equality function for dwp_file loaded CUs/TUs. */
12272 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12274 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12275 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12277 return dua
->signature
== dub
->signature
;
12280 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12283 allocate_dwp_loaded_cutus_table ()
12285 return htab_up (htab_create_alloc (3,
12286 hash_dwp_loaded_cutus
,
12287 eq_dwp_loaded_cutus
,
12288 NULL
, xcalloc
, xfree
));
12291 /* Try to open DWP file FILE_NAME.
12292 The result is the bfd handle of the file.
12293 If there is a problem finding or opening the file, return NULL.
12294 Upon success, the canonicalized path of the file is stored in the bfd,
12295 same as symfile_bfd_open. */
12297 static gdb_bfd_ref_ptr
12298 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12299 const char *file_name
)
12301 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12303 1 /*search_cwd*/));
12307 /* Work around upstream bug 15652.
12308 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12309 [Whether that's a "bug" is debatable, but it is getting in our way.]
12310 We have no real idea where the dwp file is, because gdb's realpath-ing
12311 of the executable's path may have discarded the needed info.
12312 [IWBN if the dwp file name was recorded in the executable, akin to
12313 .gnu_debuglink, but that doesn't exist yet.]
12314 Strip the directory from FILE_NAME and search again. */
12315 if (*debug_file_directory
!= '\0')
12317 /* Don't implicitly search the current directory here.
12318 If the user wants to search "." to handle this case,
12319 it must be added to debug-file-directory. */
12320 return try_open_dwop_file (dwarf2_per_objfile
,
12321 lbasename (file_name
), 1 /*is_dwp*/,
12328 /* Initialize the use of the DWP file for the current objfile.
12329 By convention the name of the DWP file is ${objfile}.dwp.
12330 The result is NULL if it can't be found. */
12332 static std::unique_ptr
<struct dwp_file
>
12333 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12335 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12337 /* Try to find first .dwp for the binary file before any symbolic links
12340 /* If the objfile is a debug file, find the name of the real binary
12341 file and get the name of dwp file from there. */
12342 std::string dwp_name
;
12343 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12345 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12346 const char *backlink_basename
= lbasename (backlink
->original_name
);
12348 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12351 dwp_name
= objfile
->original_name
;
12353 dwp_name
+= ".dwp";
12355 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12357 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12359 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12360 dwp_name
= objfile_name (objfile
);
12361 dwp_name
+= ".dwp";
12362 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12367 if (dwarf_read_debug
)
12368 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12369 return std::unique_ptr
<dwp_file
> ();
12372 const char *name
= bfd_get_filename (dbfd
.get ());
12373 std::unique_ptr
<struct dwp_file
> dwp_file
12374 (new struct dwp_file (name
, std::move (dbfd
)));
12376 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12377 dwp_file
->elf_sections
=
12378 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12379 dwp_file
->num_sections
, asection
*);
12381 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12382 dwarf2_locate_common_dwp_sections
,
12385 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12388 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12391 /* The DWP file version is stored in the hash table. Oh well. */
12392 if (dwp_file
->cus
&& dwp_file
->tus
12393 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12395 /* Technically speaking, we should try to limp along, but this is
12396 pretty bizarre. We use pulongest here because that's the established
12397 portability solution (e.g, we cannot use %u for uint32_t). */
12398 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12399 " TU version %s [in DWP file %s]"),
12400 pulongest (dwp_file
->cus
->version
),
12401 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12405 dwp_file
->version
= dwp_file
->cus
->version
;
12406 else if (dwp_file
->tus
)
12407 dwp_file
->version
= dwp_file
->tus
->version
;
12409 dwp_file
->version
= 2;
12411 if (dwp_file
->version
== 2)
12412 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12413 dwarf2_locate_v2_dwp_sections
,
12416 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12417 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12419 if (dwarf_read_debug
)
12421 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12422 fprintf_unfiltered (gdb_stdlog
,
12423 " %s CUs, %s TUs\n",
12424 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12425 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12431 /* Wrapper around open_and_init_dwp_file, only open it once. */
12433 static struct dwp_file
*
12434 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12436 if (! dwarf2_per_objfile
->dwp_checked
)
12438 dwarf2_per_objfile
->dwp_file
12439 = open_and_init_dwp_file (dwarf2_per_objfile
);
12440 dwarf2_per_objfile
->dwp_checked
= 1;
12442 return dwarf2_per_objfile
->dwp_file
.get ();
12445 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12446 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12447 or in the DWP file for the objfile, referenced by THIS_UNIT.
12448 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12449 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12451 This is called, for example, when wanting to read a variable with a
12452 complex location. Therefore we don't want to do file i/o for every call.
12453 Therefore we don't want to look for a DWO file on every call.
12454 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12455 then we check if we've already seen DWO_NAME, and only THEN do we check
12458 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12459 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12461 static struct dwo_unit
*
12462 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12463 const char *dwo_name
, const char *comp_dir
,
12464 ULONGEST signature
, int is_debug_types
)
12466 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12467 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12468 const char *kind
= is_debug_types
? "TU" : "CU";
12469 void **dwo_file_slot
;
12470 struct dwo_file
*dwo_file
;
12471 struct dwp_file
*dwp_file
;
12473 /* First see if there's a DWP file.
12474 If we have a DWP file but didn't find the DWO inside it, don't
12475 look for the original DWO file. It makes gdb behave differently
12476 depending on whether one is debugging in the build tree. */
12478 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12479 if (dwp_file
!= NULL
)
12481 const struct dwp_hash_table
*dwp_htab
=
12482 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12484 if (dwp_htab
!= NULL
)
12486 struct dwo_unit
*dwo_cutu
=
12487 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12488 signature
, is_debug_types
);
12490 if (dwo_cutu
!= NULL
)
12492 if (dwarf_read_debug
)
12494 fprintf_unfiltered (gdb_stdlog
,
12495 "Virtual DWO %s %s found: @%s\n",
12496 kind
, hex_string (signature
),
12497 host_address_to_string (dwo_cutu
));
12505 /* No DWP file, look for the DWO file. */
12507 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12508 dwo_name
, comp_dir
);
12509 if (*dwo_file_slot
== NULL
)
12511 /* Read in the file and build a table of the CUs/TUs it contains. */
12512 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12514 /* NOTE: This will be NULL if unable to open the file. */
12515 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12517 if (dwo_file
!= NULL
)
12519 struct dwo_unit
*dwo_cutu
= NULL
;
12521 if (is_debug_types
&& dwo_file
->tus
)
12523 struct dwo_unit find_dwo_cutu
;
12525 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12526 find_dwo_cutu
.signature
= signature
;
12528 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12531 else if (!is_debug_types
&& dwo_file
->cus
)
12533 struct dwo_unit find_dwo_cutu
;
12535 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12536 find_dwo_cutu
.signature
= signature
;
12537 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12541 if (dwo_cutu
!= NULL
)
12543 if (dwarf_read_debug
)
12545 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12546 kind
, dwo_name
, hex_string (signature
),
12547 host_address_to_string (dwo_cutu
));
12554 /* We didn't find it. This could mean a dwo_id mismatch, or
12555 someone deleted the DWO/DWP file, or the search path isn't set up
12556 correctly to find the file. */
12558 if (dwarf_read_debug
)
12560 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12561 kind
, dwo_name
, hex_string (signature
));
12564 /* This is a warning and not a complaint because it can be caused by
12565 pilot error (e.g., user accidentally deleting the DWO). */
12567 /* Print the name of the DWP file if we looked there, helps the user
12568 better diagnose the problem. */
12569 std::string dwp_text
;
12571 if (dwp_file
!= NULL
)
12572 dwp_text
= string_printf (" [in DWP file %s]",
12573 lbasename (dwp_file
->name
));
12575 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12576 " [in module %s]"),
12577 kind
, dwo_name
, hex_string (signature
),
12579 this_unit
->is_debug_types
? "TU" : "CU",
12580 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12585 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12586 See lookup_dwo_cutu_unit for details. */
12588 static struct dwo_unit
*
12589 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12590 const char *dwo_name
, const char *comp_dir
,
12591 ULONGEST signature
)
12593 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12596 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12597 See lookup_dwo_cutu_unit for details. */
12599 static struct dwo_unit
*
12600 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12601 const char *dwo_name
, const char *comp_dir
)
12603 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12606 /* Traversal function for queue_and_load_all_dwo_tus. */
12609 queue_and_load_dwo_tu (void **slot
, void *info
)
12611 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12612 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12613 ULONGEST signature
= dwo_unit
->signature
;
12614 struct signatured_type
*sig_type
=
12615 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12617 if (sig_type
!= NULL
)
12619 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12621 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12622 a real dependency of PER_CU on SIG_TYPE. That is detected later
12623 while processing PER_CU. */
12624 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12625 load_full_type_unit (sig_cu
);
12626 per_cu
->imported_symtabs_push (sig_cu
);
12632 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12633 The DWO may have the only definition of the type, though it may not be
12634 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12635 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12638 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12640 struct dwo_unit
*dwo_unit
;
12641 struct dwo_file
*dwo_file
;
12643 gdb_assert (!per_cu
->is_debug_types
);
12644 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12645 gdb_assert (per_cu
->cu
!= NULL
);
12647 dwo_unit
= per_cu
->cu
->dwo_unit
;
12648 gdb_assert (dwo_unit
!= NULL
);
12650 dwo_file
= dwo_unit
->dwo_file
;
12651 if (dwo_file
->tus
!= NULL
)
12652 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12656 /* Read in various DIEs. */
12658 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12659 Inherit only the children of the DW_AT_abstract_origin DIE not being
12660 already referenced by DW_AT_abstract_origin from the children of the
12664 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12666 struct die_info
*child_die
;
12667 sect_offset
*offsetp
;
12668 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12669 struct die_info
*origin_die
;
12670 /* Iterator of the ORIGIN_DIE children. */
12671 struct die_info
*origin_child_die
;
12672 struct attribute
*attr
;
12673 struct dwarf2_cu
*origin_cu
;
12674 struct pending
**origin_previous_list_in_scope
;
12676 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12680 /* Note that following die references may follow to a die in a
12684 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12686 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12688 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12689 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12691 if (die
->tag
!= origin_die
->tag
12692 && !(die
->tag
== DW_TAG_inlined_subroutine
12693 && origin_die
->tag
== DW_TAG_subprogram
))
12694 complaint (_("DIE %s and its abstract origin %s have different tags"),
12695 sect_offset_str (die
->sect_off
),
12696 sect_offset_str (origin_die
->sect_off
));
12698 std::vector
<sect_offset
> offsets
;
12700 for (child_die
= die
->child
;
12701 child_die
&& child_die
->tag
;
12702 child_die
= sibling_die (child_die
))
12704 struct die_info
*child_origin_die
;
12705 struct dwarf2_cu
*child_origin_cu
;
12707 /* We are trying to process concrete instance entries:
12708 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12709 it's not relevant to our analysis here. i.e. detecting DIEs that are
12710 present in the abstract instance but not referenced in the concrete
12712 if (child_die
->tag
== DW_TAG_call_site
12713 || child_die
->tag
== DW_TAG_GNU_call_site
)
12716 /* For each CHILD_DIE, find the corresponding child of
12717 ORIGIN_DIE. If there is more than one layer of
12718 DW_AT_abstract_origin, follow them all; there shouldn't be,
12719 but GCC versions at least through 4.4 generate this (GCC PR
12721 child_origin_die
= child_die
;
12722 child_origin_cu
= cu
;
12725 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12729 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12733 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12734 counterpart may exist. */
12735 if (child_origin_die
!= child_die
)
12737 if (child_die
->tag
!= child_origin_die
->tag
12738 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12739 && child_origin_die
->tag
== DW_TAG_subprogram
))
12740 complaint (_("Child DIE %s and its abstract origin %s have "
12742 sect_offset_str (child_die
->sect_off
),
12743 sect_offset_str (child_origin_die
->sect_off
));
12744 if (child_origin_die
->parent
!= origin_die
)
12745 complaint (_("Child DIE %s and its abstract origin %s have "
12746 "different parents"),
12747 sect_offset_str (child_die
->sect_off
),
12748 sect_offset_str (child_origin_die
->sect_off
));
12750 offsets
.push_back (child_origin_die
->sect_off
);
12753 std::sort (offsets
.begin (), offsets
.end ());
12754 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12755 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12756 if (offsetp
[-1] == *offsetp
)
12757 complaint (_("Multiple children of DIE %s refer "
12758 "to DIE %s as their abstract origin"),
12759 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12761 offsetp
= offsets
.data ();
12762 origin_child_die
= origin_die
->child
;
12763 while (origin_child_die
&& origin_child_die
->tag
)
12765 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12766 while (offsetp
< offsets_end
12767 && *offsetp
< origin_child_die
->sect_off
)
12769 if (offsetp
>= offsets_end
12770 || *offsetp
> origin_child_die
->sect_off
)
12772 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12773 Check whether we're already processing ORIGIN_CHILD_DIE.
12774 This can happen with mutually referenced abstract_origins.
12776 if (!origin_child_die
->in_process
)
12777 process_die (origin_child_die
, origin_cu
);
12779 origin_child_die
= sibling_die (origin_child_die
);
12781 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12783 if (cu
!= origin_cu
)
12784 compute_delayed_physnames (origin_cu
);
12788 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12790 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12791 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12792 struct context_stack
*newobj
;
12795 struct die_info
*child_die
;
12796 struct attribute
*attr
, *call_line
, *call_file
;
12798 CORE_ADDR baseaddr
;
12799 struct block
*block
;
12800 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12801 std::vector
<struct symbol
*> template_args
;
12802 struct template_symbol
*templ_func
= NULL
;
12806 /* If we do not have call site information, we can't show the
12807 caller of this inlined function. That's too confusing, so
12808 only use the scope for local variables. */
12809 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12810 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12811 if (call_line
== NULL
|| call_file
== NULL
)
12813 read_lexical_block_scope (die
, cu
);
12818 baseaddr
= objfile
->text_section_offset ();
12820 name
= dwarf2_name (die
, cu
);
12822 /* Ignore functions with missing or empty names. These are actually
12823 illegal according to the DWARF standard. */
12826 complaint (_("missing name for subprogram DIE at %s"),
12827 sect_offset_str (die
->sect_off
));
12831 /* Ignore functions with missing or invalid low and high pc attributes. */
12832 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12833 <= PC_BOUNDS_INVALID
)
12835 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12836 if (!attr
|| !DW_UNSND (attr
))
12837 complaint (_("cannot get low and high bounds "
12838 "for subprogram DIE at %s"),
12839 sect_offset_str (die
->sect_off
));
12843 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12844 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12846 /* If we have any template arguments, then we must allocate a
12847 different sort of symbol. */
12848 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12850 if (child_die
->tag
== DW_TAG_template_type_param
12851 || child_die
->tag
== DW_TAG_template_value_param
)
12853 templ_func
= allocate_template_symbol (objfile
);
12854 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12859 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12860 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12861 (struct symbol
*) templ_func
);
12863 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12864 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12867 /* If there is a location expression for DW_AT_frame_base, record
12869 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12870 if (attr
!= nullptr)
12871 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12873 /* If there is a location for the static link, record it. */
12874 newobj
->static_link
= NULL
;
12875 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12876 if (attr
!= nullptr)
12878 newobj
->static_link
12879 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12880 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12881 cu
->per_cu
->addr_type ());
12884 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12886 if (die
->child
!= NULL
)
12888 child_die
= die
->child
;
12889 while (child_die
&& child_die
->tag
)
12891 if (child_die
->tag
== DW_TAG_template_type_param
12892 || child_die
->tag
== DW_TAG_template_value_param
)
12894 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12897 template_args
.push_back (arg
);
12900 process_die (child_die
, cu
);
12901 child_die
= sibling_die (child_die
);
12905 inherit_abstract_dies (die
, cu
);
12907 /* If we have a DW_AT_specification, we might need to import using
12908 directives from the context of the specification DIE. See the
12909 comment in determine_prefix. */
12910 if (cu
->language
== language_cplus
12911 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12913 struct dwarf2_cu
*spec_cu
= cu
;
12914 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12918 child_die
= spec_die
->child
;
12919 while (child_die
&& child_die
->tag
)
12921 if (child_die
->tag
== DW_TAG_imported_module
)
12922 process_die (child_die
, spec_cu
);
12923 child_die
= sibling_die (child_die
);
12926 /* In some cases, GCC generates specification DIEs that
12927 themselves contain DW_AT_specification attributes. */
12928 spec_die
= die_specification (spec_die
, &spec_cu
);
12932 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12933 /* Make a block for the local symbols within. */
12934 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12935 cstk
.static_link
, lowpc
, highpc
);
12937 /* For C++, set the block's scope. */
12938 if ((cu
->language
== language_cplus
12939 || cu
->language
== language_fortran
12940 || cu
->language
== language_d
12941 || cu
->language
== language_rust
)
12942 && cu
->processing_has_namespace_info
)
12943 block_set_scope (block
, determine_prefix (die
, cu
),
12944 &objfile
->objfile_obstack
);
12946 /* If we have address ranges, record them. */
12947 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12949 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12951 /* Attach template arguments to function. */
12952 if (!template_args
.empty ())
12954 gdb_assert (templ_func
!= NULL
);
12956 templ_func
->n_template_arguments
= template_args
.size ();
12957 templ_func
->template_arguments
12958 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12959 templ_func
->n_template_arguments
);
12960 memcpy (templ_func
->template_arguments
,
12961 template_args
.data (),
12962 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12964 /* Make sure that the symtab is set on the new symbols. Even
12965 though they don't appear in this symtab directly, other parts
12966 of gdb assume that symbols do, and this is reasonably
12968 for (symbol
*sym
: template_args
)
12969 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12972 /* In C++, we can have functions nested inside functions (e.g., when
12973 a function declares a class that has methods). This means that
12974 when we finish processing a function scope, we may need to go
12975 back to building a containing block's symbol lists. */
12976 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12977 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12979 /* If we've finished processing a top-level function, subsequent
12980 symbols go in the file symbol list. */
12981 if (cu
->get_builder ()->outermost_context_p ())
12982 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12985 /* Process all the DIES contained within a lexical block scope. Start
12986 a new scope, process the dies, and then close the scope. */
12989 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12991 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12992 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12993 CORE_ADDR lowpc
, highpc
;
12994 struct die_info
*child_die
;
12995 CORE_ADDR baseaddr
;
12997 baseaddr
= objfile
->text_section_offset ();
12999 /* Ignore blocks with missing or invalid low and high pc attributes. */
13000 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13001 as multiple lexical blocks? Handling children in a sane way would
13002 be nasty. Might be easier to properly extend generic blocks to
13003 describe ranges. */
13004 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13006 case PC_BOUNDS_NOT_PRESENT
:
13007 /* DW_TAG_lexical_block has no attributes, process its children as if
13008 there was no wrapping by that DW_TAG_lexical_block.
13009 GCC does no longer produces such DWARF since GCC r224161. */
13010 for (child_die
= die
->child
;
13011 child_die
!= NULL
&& child_die
->tag
;
13012 child_die
= sibling_die (child_die
))
13013 process_die (child_die
, cu
);
13015 case PC_BOUNDS_INVALID
:
13018 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13019 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13021 cu
->get_builder ()->push_context (0, lowpc
);
13022 if (die
->child
!= NULL
)
13024 child_die
= die
->child
;
13025 while (child_die
&& child_die
->tag
)
13027 process_die (child_die
, cu
);
13028 child_die
= sibling_die (child_die
);
13031 inherit_abstract_dies (die
, cu
);
13032 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13034 if (*cu
->get_builder ()->get_local_symbols () != NULL
13035 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13037 struct block
*block
13038 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13039 cstk
.start_addr
, highpc
);
13041 /* Note that recording ranges after traversing children, as we
13042 do here, means that recording a parent's ranges entails
13043 walking across all its children's ranges as they appear in
13044 the address map, which is quadratic behavior.
13046 It would be nicer to record the parent's ranges before
13047 traversing its children, simply overriding whatever you find
13048 there. But since we don't even decide whether to create a
13049 block until after we've traversed its children, that's hard
13051 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13053 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13054 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13057 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13060 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13062 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13063 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13064 CORE_ADDR pc
, baseaddr
;
13065 struct attribute
*attr
;
13066 struct call_site
*call_site
, call_site_local
;
13069 struct die_info
*child_die
;
13071 baseaddr
= objfile
->text_section_offset ();
13073 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13076 /* This was a pre-DWARF-5 GNU extension alias
13077 for DW_AT_call_return_pc. */
13078 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13082 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13083 "DIE %s [in module %s]"),
13084 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13087 pc
= attr
->value_as_address () + baseaddr
;
13088 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13090 if (cu
->call_site_htab
== NULL
)
13091 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13092 NULL
, &objfile
->objfile_obstack
,
13093 hashtab_obstack_allocate
, NULL
);
13094 call_site_local
.pc
= pc
;
13095 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13098 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13099 "DIE %s [in module %s]"),
13100 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13101 objfile_name (objfile
));
13105 /* Count parameters at the caller. */
13108 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13109 child_die
= sibling_die (child_die
))
13111 if (child_die
->tag
!= DW_TAG_call_site_parameter
13112 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13114 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13115 "DW_TAG_call_site child DIE %s [in module %s]"),
13116 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13117 objfile_name (objfile
));
13125 = ((struct call_site
*)
13126 obstack_alloc (&objfile
->objfile_obstack
,
13127 sizeof (*call_site
)
13128 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13130 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13131 call_site
->pc
= pc
;
13133 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13134 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13136 struct die_info
*func_die
;
13138 /* Skip also over DW_TAG_inlined_subroutine. */
13139 for (func_die
= die
->parent
;
13140 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13141 && func_die
->tag
!= DW_TAG_subroutine_type
;
13142 func_die
= func_die
->parent
);
13144 /* DW_AT_call_all_calls is a superset
13145 of DW_AT_call_all_tail_calls. */
13147 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13148 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13149 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13150 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13152 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13153 not complete. But keep CALL_SITE for look ups via call_site_htab,
13154 both the initial caller containing the real return address PC and
13155 the final callee containing the current PC of a chain of tail
13156 calls do not need to have the tail call list complete. But any
13157 function candidate for a virtual tail call frame searched via
13158 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13159 determined unambiguously. */
13163 struct type
*func_type
= NULL
;
13166 func_type
= get_die_type (func_die
, cu
);
13167 if (func_type
!= NULL
)
13169 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13171 /* Enlist this call site to the function. */
13172 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13173 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13176 complaint (_("Cannot find function owning DW_TAG_call_site "
13177 "DIE %s [in module %s]"),
13178 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13182 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13184 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13186 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13189 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13190 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13192 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13193 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13194 /* Keep NULL DWARF_BLOCK. */;
13195 else if (attr
->form_is_block ())
13197 struct dwarf2_locexpr_baton
*dlbaton
;
13199 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13200 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13201 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13202 dlbaton
->per_cu
= cu
->per_cu
;
13204 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13206 else if (attr
->form_is_ref ())
13208 struct dwarf2_cu
*target_cu
= cu
;
13209 struct die_info
*target_die
;
13211 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13212 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13213 if (die_is_declaration (target_die
, target_cu
))
13215 const char *target_physname
;
13217 /* Prefer the mangled name; otherwise compute the demangled one. */
13218 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13219 if (target_physname
== NULL
)
13220 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13221 if (target_physname
== NULL
)
13222 complaint (_("DW_AT_call_target target DIE has invalid "
13223 "physname, for referencing DIE %s [in module %s]"),
13224 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13226 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13232 /* DW_AT_entry_pc should be preferred. */
13233 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13234 <= PC_BOUNDS_INVALID
)
13235 complaint (_("DW_AT_call_target target DIE has invalid "
13236 "low pc, for referencing DIE %s [in module %s]"),
13237 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13240 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13241 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13246 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13247 "block nor reference, for DIE %s [in module %s]"),
13248 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13250 call_site
->per_cu
= cu
->per_cu
;
13252 for (child_die
= die
->child
;
13253 child_die
&& child_die
->tag
;
13254 child_die
= sibling_die (child_die
))
13256 struct call_site_parameter
*parameter
;
13257 struct attribute
*loc
, *origin
;
13259 if (child_die
->tag
!= DW_TAG_call_site_parameter
13260 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13262 /* Already printed the complaint above. */
13266 gdb_assert (call_site
->parameter_count
< nparams
);
13267 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13269 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13270 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13271 register is contained in DW_AT_call_value. */
13273 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13274 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13275 if (origin
== NULL
)
13277 /* This was a pre-DWARF-5 GNU extension alias
13278 for DW_AT_call_parameter. */
13279 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13281 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13283 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13285 sect_offset sect_off
13286 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13287 if (!cu
->header
.offset_in_cu_p (sect_off
))
13289 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13290 binding can be done only inside one CU. Such referenced DIE
13291 therefore cannot be even moved to DW_TAG_partial_unit. */
13292 complaint (_("DW_AT_call_parameter offset is not in CU for "
13293 "DW_TAG_call_site child DIE %s [in module %s]"),
13294 sect_offset_str (child_die
->sect_off
),
13295 objfile_name (objfile
));
13298 parameter
->u
.param_cu_off
13299 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13301 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13303 complaint (_("No DW_FORM_block* DW_AT_location for "
13304 "DW_TAG_call_site child DIE %s [in module %s]"),
13305 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13310 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13311 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13312 if (parameter
->u
.dwarf_reg
!= -1)
13313 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13314 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13315 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13316 ¶meter
->u
.fb_offset
))
13317 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13320 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13321 "for DW_FORM_block* DW_AT_location is supported for "
13322 "DW_TAG_call_site child DIE %s "
13324 sect_offset_str (child_die
->sect_off
),
13325 objfile_name (objfile
));
13330 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13332 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13333 if (attr
== NULL
|| !attr
->form_is_block ())
13335 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13336 "DW_TAG_call_site child DIE %s [in module %s]"),
13337 sect_offset_str (child_die
->sect_off
),
13338 objfile_name (objfile
));
13341 parameter
->value
= DW_BLOCK (attr
)->data
;
13342 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13344 /* Parameters are not pre-cleared by memset above. */
13345 parameter
->data_value
= NULL
;
13346 parameter
->data_value_size
= 0;
13347 call_site
->parameter_count
++;
13349 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13351 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13352 if (attr
!= nullptr)
13354 if (!attr
->form_is_block ())
13355 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13356 "DW_TAG_call_site child DIE %s [in module %s]"),
13357 sect_offset_str (child_die
->sect_off
),
13358 objfile_name (objfile
));
13361 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13362 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13368 /* Helper function for read_variable. If DIE represents a virtual
13369 table, then return the type of the concrete object that is
13370 associated with the virtual table. Otherwise, return NULL. */
13372 static struct type
*
13373 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13375 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13379 /* Find the type DIE. */
13380 struct die_info
*type_die
= NULL
;
13381 struct dwarf2_cu
*type_cu
= cu
;
13383 if (attr
->form_is_ref ())
13384 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13385 if (type_die
== NULL
)
13388 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13390 return die_containing_type (type_die
, type_cu
);
13393 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13396 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13398 struct rust_vtable_symbol
*storage
= NULL
;
13400 if (cu
->language
== language_rust
)
13402 struct type
*containing_type
= rust_containing_type (die
, cu
);
13404 if (containing_type
!= NULL
)
13406 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13408 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13409 initialize_objfile_symbol (storage
);
13410 storage
->concrete_type
= containing_type
;
13411 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13415 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13416 struct attribute
*abstract_origin
13417 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13418 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13419 if (res
== NULL
&& loc
&& abstract_origin
)
13421 /* We have a variable without a name, but with a location and an abstract
13422 origin. This may be a concrete instance of an abstract variable
13423 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13425 struct dwarf2_cu
*origin_cu
= cu
;
13426 struct die_info
*origin_die
13427 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13428 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13429 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13433 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13434 reading .debug_rnglists.
13435 Callback's type should be:
13436 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13437 Return true if the attributes are present and valid, otherwise,
13440 template <typename Callback
>
13442 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13443 Callback
&&callback
)
13445 struct dwarf2_per_objfile
*dwarf2_per_objfile
13446 = cu
->per_cu
->dwarf2_per_objfile
;
13447 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13448 bfd
*obfd
= objfile
->obfd
;
13449 /* Base address selection entry. */
13452 const gdb_byte
*buffer
;
13453 CORE_ADDR baseaddr
;
13454 bool overflow
= false;
13456 found_base
= cu
->base_known
;
13457 base
= cu
->base_address
;
13459 dwarf2_per_objfile
->rnglists
.read (objfile
);
13460 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13462 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13466 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13468 baseaddr
= objfile
->text_section_offset ();
13472 /* Initialize it due to a false compiler warning. */
13473 CORE_ADDR range_beginning
= 0, range_end
= 0;
13474 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13475 + dwarf2_per_objfile
->rnglists
.size
);
13476 unsigned int bytes_read
;
13478 if (buffer
== buf_end
)
13483 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13486 case DW_RLE_end_of_list
:
13488 case DW_RLE_base_address
:
13489 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13494 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13496 buffer
+= bytes_read
;
13498 case DW_RLE_start_length
:
13499 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13504 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13506 buffer
+= bytes_read
;
13507 range_end
= (range_beginning
13508 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13509 buffer
+= bytes_read
;
13510 if (buffer
> buf_end
)
13516 case DW_RLE_offset_pair
:
13517 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13518 buffer
+= bytes_read
;
13519 if (buffer
> buf_end
)
13524 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13525 buffer
+= bytes_read
;
13526 if (buffer
> buf_end
)
13532 case DW_RLE_start_end
:
13533 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13538 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13540 buffer
+= bytes_read
;
13541 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13542 buffer
+= bytes_read
;
13545 complaint (_("Invalid .debug_rnglists data (no base address)"));
13548 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13550 if (rlet
== DW_RLE_base_address
)
13555 /* We have no valid base address for the ranges
13557 complaint (_("Invalid .debug_rnglists data (no base address)"));
13561 if (range_beginning
> range_end
)
13563 /* Inverted range entries are invalid. */
13564 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13568 /* Empty range entries have no effect. */
13569 if (range_beginning
== range_end
)
13572 range_beginning
+= base
;
13575 /* A not-uncommon case of bad debug info.
13576 Don't pollute the addrmap with bad data. */
13577 if (range_beginning
+ baseaddr
== 0
13578 && !dwarf2_per_objfile
->has_section_at_zero
)
13580 complaint (_(".debug_rnglists entry has start address of zero"
13581 " [in module %s]"), objfile_name (objfile
));
13585 callback (range_beginning
, range_end
);
13590 complaint (_("Offset %d is not terminated "
13591 "for DW_AT_ranges attribute"),
13599 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13600 Callback's type should be:
13601 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13602 Return 1 if the attributes are present and valid, otherwise, return 0. */
13604 template <typename Callback
>
13606 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13607 Callback
&&callback
)
13609 struct dwarf2_per_objfile
*dwarf2_per_objfile
13610 = cu
->per_cu
->dwarf2_per_objfile
;
13611 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13612 struct comp_unit_head
*cu_header
= &cu
->header
;
13613 bfd
*obfd
= objfile
->obfd
;
13614 unsigned int addr_size
= cu_header
->addr_size
;
13615 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13616 /* Base address selection entry. */
13619 unsigned int dummy
;
13620 const gdb_byte
*buffer
;
13621 CORE_ADDR baseaddr
;
13623 if (cu_header
->version
>= 5)
13624 return dwarf2_rnglists_process (offset
, cu
, callback
);
13626 found_base
= cu
->base_known
;
13627 base
= cu
->base_address
;
13629 dwarf2_per_objfile
->ranges
.read (objfile
);
13630 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13632 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13636 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13638 baseaddr
= objfile
->text_section_offset ();
13642 CORE_ADDR range_beginning
, range_end
;
13644 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13645 buffer
+= addr_size
;
13646 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13647 buffer
+= addr_size
;
13648 offset
+= 2 * addr_size
;
13650 /* An end of list marker is a pair of zero addresses. */
13651 if (range_beginning
== 0 && range_end
== 0)
13652 /* Found the end of list entry. */
13655 /* Each base address selection entry is a pair of 2 values.
13656 The first is the largest possible address, the second is
13657 the base address. Check for a base address here. */
13658 if ((range_beginning
& mask
) == mask
)
13660 /* If we found the largest possible address, then we already
13661 have the base address in range_end. */
13669 /* We have no valid base address for the ranges
13671 complaint (_("Invalid .debug_ranges data (no base address)"));
13675 if (range_beginning
> range_end
)
13677 /* Inverted range entries are invalid. */
13678 complaint (_("Invalid .debug_ranges data (inverted range)"));
13682 /* Empty range entries have no effect. */
13683 if (range_beginning
== range_end
)
13686 range_beginning
+= base
;
13689 /* A not-uncommon case of bad debug info.
13690 Don't pollute the addrmap with bad data. */
13691 if (range_beginning
+ baseaddr
== 0
13692 && !dwarf2_per_objfile
->has_section_at_zero
)
13694 complaint (_(".debug_ranges entry has start address of zero"
13695 " [in module %s]"), objfile_name (objfile
));
13699 callback (range_beginning
, range_end
);
13705 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13706 Return 1 if the attributes are present and valid, otherwise, return 0.
13707 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13710 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13711 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13712 dwarf2_psymtab
*ranges_pst
)
13714 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13715 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13716 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13719 CORE_ADDR high
= 0;
13722 retval
= dwarf2_ranges_process (offset
, cu
,
13723 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13725 if (ranges_pst
!= NULL
)
13730 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13731 range_beginning
+ baseaddr
)
13733 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13734 range_end
+ baseaddr
)
13736 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13737 lowpc
, highpc
- 1, ranges_pst
);
13740 /* FIXME: This is recording everything as a low-high
13741 segment of consecutive addresses. We should have a
13742 data structure for discontiguous block ranges
13746 low
= range_beginning
;
13752 if (range_beginning
< low
)
13753 low
= range_beginning
;
13754 if (range_end
> high
)
13762 /* If the first entry is an end-of-list marker, the range
13763 describes an empty scope, i.e. no instructions. */
13769 *high_return
= high
;
13773 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13774 definition for the return value. *LOWPC and *HIGHPC are set iff
13775 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13777 static enum pc_bounds_kind
13778 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13779 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13780 dwarf2_psymtab
*pst
)
13782 struct dwarf2_per_objfile
*dwarf2_per_objfile
13783 = cu
->per_cu
->dwarf2_per_objfile
;
13784 struct attribute
*attr
;
13785 struct attribute
*attr_high
;
13787 CORE_ADDR high
= 0;
13788 enum pc_bounds_kind ret
;
13790 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13793 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13794 if (attr
!= nullptr)
13796 low
= attr
->value_as_address ();
13797 high
= attr_high
->value_as_address ();
13798 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13802 /* Found high w/o low attribute. */
13803 return PC_BOUNDS_INVALID
;
13805 /* Found consecutive range of addresses. */
13806 ret
= PC_BOUNDS_HIGH_LOW
;
13810 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13813 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13814 We take advantage of the fact that DW_AT_ranges does not appear
13815 in DW_TAG_compile_unit of DWO files. */
13816 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13817 unsigned int ranges_offset
= (DW_UNSND (attr
)
13818 + (need_ranges_base
13822 /* Value of the DW_AT_ranges attribute is the offset in the
13823 .debug_ranges section. */
13824 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13825 return PC_BOUNDS_INVALID
;
13826 /* Found discontinuous range of addresses. */
13827 ret
= PC_BOUNDS_RANGES
;
13830 return PC_BOUNDS_NOT_PRESENT
;
13833 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13835 return PC_BOUNDS_INVALID
;
13837 /* When using the GNU linker, .gnu.linkonce. sections are used to
13838 eliminate duplicate copies of functions and vtables and such.
13839 The linker will arbitrarily choose one and discard the others.
13840 The AT_*_pc values for such functions refer to local labels in
13841 these sections. If the section from that file was discarded, the
13842 labels are not in the output, so the relocs get a value of 0.
13843 If this is a discarded function, mark the pc bounds as invalid,
13844 so that GDB will ignore it. */
13845 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13846 return PC_BOUNDS_INVALID
;
13854 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13855 its low and high PC addresses. Do nothing if these addresses could not
13856 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13857 and HIGHPC to the high address if greater than HIGHPC. */
13860 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13861 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13862 struct dwarf2_cu
*cu
)
13864 CORE_ADDR low
, high
;
13865 struct die_info
*child
= die
->child
;
13867 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13869 *lowpc
= std::min (*lowpc
, low
);
13870 *highpc
= std::max (*highpc
, high
);
13873 /* If the language does not allow nested subprograms (either inside
13874 subprograms or lexical blocks), we're done. */
13875 if (cu
->language
!= language_ada
)
13878 /* Check all the children of the given DIE. If it contains nested
13879 subprograms, then check their pc bounds. Likewise, we need to
13880 check lexical blocks as well, as they may also contain subprogram
13882 while (child
&& child
->tag
)
13884 if (child
->tag
== DW_TAG_subprogram
13885 || child
->tag
== DW_TAG_lexical_block
)
13886 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13887 child
= sibling_die (child
);
13891 /* Get the low and high pc's represented by the scope DIE, and store
13892 them in *LOWPC and *HIGHPC. If the correct values can't be
13893 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13896 get_scope_pc_bounds (struct die_info
*die
,
13897 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13898 struct dwarf2_cu
*cu
)
13900 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13901 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13902 CORE_ADDR current_low
, current_high
;
13904 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13905 >= PC_BOUNDS_RANGES
)
13907 best_low
= current_low
;
13908 best_high
= current_high
;
13912 struct die_info
*child
= die
->child
;
13914 while (child
&& child
->tag
)
13916 switch (child
->tag
) {
13917 case DW_TAG_subprogram
:
13918 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13920 case DW_TAG_namespace
:
13921 case DW_TAG_module
:
13922 /* FIXME: carlton/2004-01-16: Should we do this for
13923 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13924 that current GCC's always emit the DIEs corresponding
13925 to definitions of methods of classes as children of a
13926 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13927 the DIEs giving the declarations, which could be
13928 anywhere). But I don't see any reason why the
13929 standards says that they have to be there. */
13930 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13932 if (current_low
!= ((CORE_ADDR
) -1))
13934 best_low
= std::min (best_low
, current_low
);
13935 best_high
= std::max (best_high
, current_high
);
13943 child
= sibling_die (child
);
13948 *highpc
= best_high
;
13951 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13955 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13956 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13958 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13959 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13960 struct attribute
*attr
;
13961 struct attribute
*attr_high
;
13963 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13966 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13967 if (attr
!= nullptr)
13969 CORE_ADDR low
= attr
->value_as_address ();
13970 CORE_ADDR high
= attr_high
->value_as_address ();
13972 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13975 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13976 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13977 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13981 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13982 if (attr
!= nullptr)
13984 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13985 We take advantage of the fact that DW_AT_ranges does not appear
13986 in DW_TAG_compile_unit of DWO files. */
13987 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13989 /* The value of the DW_AT_ranges attribute is the offset of the
13990 address range list in the .debug_ranges section. */
13991 unsigned long offset
= (DW_UNSND (attr
)
13992 + (need_ranges_base
? cu
->ranges_base
: 0));
13994 std::vector
<blockrange
> blockvec
;
13995 dwarf2_ranges_process (offset
, cu
,
13996 [&] (CORE_ADDR start
, CORE_ADDR end
)
14000 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14001 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14002 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14003 blockvec
.emplace_back (start
, end
);
14006 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14010 /* Check whether the producer field indicates either of GCC < 4.6, or the
14011 Intel C/C++ compiler, and cache the result in CU. */
14014 check_producer (struct dwarf2_cu
*cu
)
14018 if (cu
->producer
== NULL
)
14020 /* For unknown compilers expect their behavior is DWARF version
14023 GCC started to support .debug_types sections by -gdwarf-4 since
14024 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14025 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14026 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14027 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14029 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14031 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14032 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14034 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14036 cu
->producer_is_icc
= true;
14037 cu
->producer_is_icc_lt_14
= major
< 14;
14039 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14040 cu
->producer_is_codewarrior
= true;
14043 /* For other non-GCC compilers, expect their behavior is DWARF version
14047 cu
->checked_producer
= true;
14050 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14051 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14052 during 4.6.0 experimental. */
14055 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14057 if (!cu
->checked_producer
)
14058 check_producer (cu
);
14060 return cu
->producer_is_gxx_lt_4_6
;
14064 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14065 with incorrect is_stmt attributes. */
14068 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14070 if (!cu
->checked_producer
)
14071 check_producer (cu
);
14073 return cu
->producer_is_codewarrior
;
14076 /* Return the default accessibility type if it is not overridden by
14077 DW_AT_accessibility. */
14079 static enum dwarf_access_attribute
14080 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14082 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14084 /* The default DWARF 2 accessibility for members is public, the default
14085 accessibility for inheritance is private. */
14087 if (die
->tag
!= DW_TAG_inheritance
)
14088 return DW_ACCESS_public
;
14090 return DW_ACCESS_private
;
14094 /* DWARF 3+ defines the default accessibility a different way. The same
14095 rules apply now for DW_TAG_inheritance as for the members and it only
14096 depends on the container kind. */
14098 if (die
->parent
->tag
== DW_TAG_class_type
)
14099 return DW_ACCESS_private
;
14101 return DW_ACCESS_public
;
14105 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14106 offset. If the attribute was not found return 0, otherwise return
14107 1. If it was found but could not properly be handled, set *OFFSET
14111 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14114 struct attribute
*attr
;
14116 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14121 /* Note that we do not check for a section offset first here.
14122 This is because DW_AT_data_member_location is new in DWARF 4,
14123 so if we see it, we can assume that a constant form is really
14124 a constant and not a section offset. */
14125 if (attr
->form_is_constant ())
14126 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14127 else if (attr
->form_is_section_offset ())
14128 dwarf2_complex_location_expr_complaint ();
14129 else if (attr
->form_is_block ())
14130 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14132 dwarf2_complex_location_expr_complaint ();
14140 /* Add an aggregate field to the field list. */
14143 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14144 struct dwarf2_cu
*cu
)
14146 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14147 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14148 struct nextfield
*new_field
;
14149 struct attribute
*attr
;
14151 const char *fieldname
= "";
14153 if (die
->tag
== DW_TAG_inheritance
)
14155 fip
->baseclasses
.emplace_back ();
14156 new_field
= &fip
->baseclasses
.back ();
14160 fip
->fields
.emplace_back ();
14161 new_field
= &fip
->fields
.back ();
14166 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14167 if (attr
!= nullptr)
14168 new_field
->accessibility
= DW_UNSND (attr
);
14170 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14171 if (new_field
->accessibility
!= DW_ACCESS_public
)
14172 fip
->non_public_fields
= 1;
14174 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14175 if (attr
!= nullptr)
14176 new_field
->virtuality
= DW_UNSND (attr
);
14178 new_field
->virtuality
= DW_VIRTUALITY_none
;
14180 fp
= &new_field
->field
;
14182 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14186 /* Data member other than a C++ static data member. */
14188 /* Get type of field. */
14189 fp
->type
= die_type (die
, cu
);
14191 SET_FIELD_BITPOS (*fp
, 0);
14193 /* Get bit size of field (zero if none). */
14194 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14195 if (attr
!= nullptr)
14197 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14201 FIELD_BITSIZE (*fp
) = 0;
14204 /* Get bit offset of field. */
14205 if (handle_data_member_location (die
, cu
, &offset
))
14206 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14207 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14208 if (attr
!= nullptr)
14210 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14212 /* For big endian bits, the DW_AT_bit_offset gives the
14213 additional bit offset from the MSB of the containing
14214 anonymous object to the MSB of the field. We don't
14215 have to do anything special since we don't need to
14216 know the size of the anonymous object. */
14217 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14221 /* For little endian bits, compute the bit offset to the
14222 MSB of the anonymous object, subtract off the number of
14223 bits from the MSB of the field to the MSB of the
14224 object, and then subtract off the number of bits of
14225 the field itself. The result is the bit offset of
14226 the LSB of the field. */
14227 int anonymous_size
;
14228 int bit_offset
= DW_UNSND (attr
);
14230 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14231 if (attr
!= nullptr)
14233 /* The size of the anonymous object containing
14234 the bit field is explicit, so use the
14235 indicated size (in bytes). */
14236 anonymous_size
= DW_UNSND (attr
);
14240 /* The size of the anonymous object containing
14241 the bit field must be inferred from the type
14242 attribute of the data member containing the
14244 anonymous_size
= TYPE_LENGTH (fp
->type
);
14246 SET_FIELD_BITPOS (*fp
,
14247 (FIELD_BITPOS (*fp
)
14248 + anonymous_size
* bits_per_byte
14249 - bit_offset
- FIELD_BITSIZE (*fp
)));
14252 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14254 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14255 + dwarf2_get_attr_constant_value (attr
, 0)));
14257 /* Get name of field. */
14258 fieldname
= dwarf2_name (die
, cu
);
14259 if (fieldname
== NULL
)
14262 /* The name is already allocated along with this objfile, so we don't
14263 need to duplicate it for the type. */
14264 fp
->name
= fieldname
;
14266 /* Change accessibility for artificial fields (e.g. virtual table
14267 pointer or virtual base class pointer) to private. */
14268 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14270 FIELD_ARTIFICIAL (*fp
) = 1;
14271 new_field
->accessibility
= DW_ACCESS_private
;
14272 fip
->non_public_fields
= 1;
14275 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14277 /* C++ static member. */
14279 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14280 is a declaration, but all versions of G++ as of this writing
14281 (so through at least 3.2.1) incorrectly generate
14282 DW_TAG_variable tags. */
14284 const char *physname
;
14286 /* Get name of field. */
14287 fieldname
= dwarf2_name (die
, cu
);
14288 if (fieldname
== NULL
)
14291 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14293 /* Only create a symbol if this is an external value.
14294 new_symbol checks this and puts the value in the global symbol
14295 table, which we want. If it is not external, new_symbol
14296 will try to put the value in cu->list_in_scope which is wrong. */
14297 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14299 /* A static const member, not much different than an enum as far as
14300 we're concerned, except that we can support more types. */
14301 new_symbol (die
, NULL
, cu
);
14304 /* Get physical name. */
14305 physname
= dwarf2_physname (fieldname
, die
, cu
);
14307 /* The name is already allocated along with this objfile, so we don't
14308 need to duplicate it for the type. */
14309 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14310 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14311 FIELD_NAME (*fp
) = fieldname
;
14313 else if (die
->tag
== DW_TAG_inheritance
)
14317 /* C++ base class field. */
14318 if (handle_data_member_location (die
, cu
, &offset
))
14319 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14320 FIELD_BITSIZE (*fp
) = 0;
14321 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14322 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14324 else if (die
->tag
== DW_TAG_variant_part
)
14326 /* process_structure_scope will treat this DIE as a union. */
14327 process_structure_scope (die
, cu
);
14329 /* The variant part is relative to the start of the enclosing
14331 SET_FIELD_BITPOS (*fp
, 0);
14332 fp
->type
= get_die_type (die
, cu
);
14333 fp
->artificial
= 1;
14334 fp
->name
= "<<variant>>";
14336 /* Normally a DW_TAG_variant_part won't have a size, but our
14337 representation requires one, so set it to the maximum of the
14338 child sizes, being sure to account for the offset at which
14339 each child is seen. */
14340 if (TYPE_LENGTH (fp
->type
) == 0)
14343 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14345 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14346 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14350 TYPE_LENGTH (fp
->type
) = max
;
14354 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14357 /* Can the type given by DIE define another type? */
14360 type_can_define_types (const struct die_info
*die
)
14364 case DW_TAG_typedef
:
14365 case DW_TAG_class_type
:
14366 case DW_TAG_structure_type
:
14367 case DW_TAG_union_type
:
14368 case DW_TAG_enumeration_type
:
14376 /* Add a type definition defined in the scope of the FIP's class. */
14379 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14380 struct dwarf2_cu
*cu
)
14382 struct decl_field fp
;
14383 memset (&fp
, 0, sizeof (fp
));
14385 gdb_assert (type_can_define_types (die
));
14387 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14388 fp
.name
= dwarf2_name (die
, cu
);
14389 fp
.type
= read_type_die (die
, cu
);
14391 /* Save accessibility. */
14392 enum dwarf_access_attribute accessibility
;
14393 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14395 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14397 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14398 switch (accessibility
)
14400 case DW_ACCESS_public
:
14401 /* The assumed value if neither private nor protected. */
14403 case DW_ACCESS_private
:
14406 case DW_ACCESS_protected
:
14407 fp
.is_protected
= 1;
14410 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14413 if (die
->tag
== DW_TAG_typedef
)
14414 fip
->typedef_field_list
.push_back (fp
);
14416 fip
->nested_types_list
.push_back (fp
);
14419 /* Create the vector of fields, and attach it to the type. */
14422 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14423 struct dwarf2_cu
*cu
)
14425 int nfields
= fip
->nfields
;
14427 /* Record the field count, allocate space for the array of fields,
14428 and create blank accessibility bitfields if necessary. */
14429 TYPE_NFIELDS (type
) = nfields
;
14430 TYPE_FIELDS (type
) = (struct field
*)
14431 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14433 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14435 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14437 TYPE_FIELD_PRIVATE_BITS (type
) =
14438 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14439 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14441 TYPE_FIELD_PROTECTED_BITS (type
) =
14442 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14443 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14445 TYPE_FIELD_IGNORE_BITS (type
) =
14446 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14447 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14450 /* If the type has baseclasses, allocate and clear a bit vector for
14451 TYPE_FIELD_VIRTUAL_BITS. */
14452 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14454 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14455 unsigned char *pointer
;
14457 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14458 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14459 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14460 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14461 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14464 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14466 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14468 for (int index
= 0; index
< nfields
; ++index
)
14470 struct nextfield
&field
= fip
->fields
[index
];
14472 if (field
.variant
.is_discriminant
)
14473 di
->discriminant_index
= index
;
14474 else if (field
.variant
.default_branch
)
14475 di
->default_index
= index
;
14477 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14481 /* Copy the saved-up fields into the field vector. */
14482 for (int i
= 0; i
< nfields
; ++i
)
14484 struct nextfield
&field
14485 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14486 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14488 TYPE_FIELD (type
, i
) = field
.field
;
14489 switch (field
.accessibility
)
14491 case DW_ACCESS_private
:
14492 if (cu
->language
!= language_ada
)
14493 SET_TYPE_FIELD_PRIVATE (type
, i
);
14496 case DW_ACCESS_protected
:
14497 if (cu
->language
!= language_ada
)
14498 SET_TYPE_FIELD_PROTECTED (type
, i
);
14501 case DW_ACCESS_public
:
14505 /* Unknown accessibility. Complain and treat it as public. */
14507 complaint (_("unsupported accessibility %d"),
14508 field
.accessibility
);
14512 if (i
< fip
->baseclasses
.size ())
14514 switch (field
.virtuality
)
14516 case DW_VIRTUALITY_virtual
:
14517 case DW_VIRTUALITY_pure_virtual
:
14518 if (cu
->language
== language_ada
)
14519 error (_("unexpected virtuality in component of Ada type"));
14520 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14527 /* Return true if this member function is a constructor, false
14531 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14533 const char *fieldname
;
14534 const char *type_name
;
14537 if (die
->parent
== NULL
)
14540 if (die
->parent
->tag
!= DW_TAG_structure_type
14541 && die
->parent
->tag
!= DW_TAG_union_type
14542 && die
->parent
->tag
!= DW_TAG_class_type
)
14545 fieldname
= dwarf2_name (die
, cu
);
14546 type_name
= dwarf2_name (die
->parent
, cu
);
14547 if (fieldname
== NULL
|| type_name
== NULL
)
14550 len
= strlen (fieldname
);
14551 return (strncmp (fieldname
, type_name
, len
) == 0
14552 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14555 /* Check if the given VALUE is a recognized enum
14556 dwarf_defaulted_attribute constant according to DWARF5 spec,
14560 is_valid_DW_AT_defaulted (ULONGEST value
)
14564 case DW_DEFAULTED_no
:
14565 case DW_DEFAULTED_in_class
:
14566 case DW_DEFAULTED_out_of_class
:
14570 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14574 /* Add a member function to the proper fieldlist. */
14577 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14578 struct type
*type
, struct dwarf2_cu
*cu
)
14580 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14581 struct attribute
*attr
;
14583 struct fnfieldlist
*flp
= nullptr;
14584 struct fn_field
*fnp
;
14585 const char *fieldname
;
14586 struct type
*this_type
;
14587 enum dwarf_access_attribute accessibility
;
14589 if (cu
->language
== language_ada
)
14590 error (_("unexpected member function in Ada type"));
14592 /* Get name of member function. */
14593 fieldname
= dwarf2_name (die
, cu
);
14594 if (fieldname
== NULL
)
14597 /* Look up member function name in fieldlist. */
14598 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14600 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14602 flp
= &fip
->fnfieldlists
[i
];
14607 /* Create a new fnfieldlist if necessary. */
14608 if (flp
== nullptr)
14610 fip
->fnfieldlists
.emplace_back ();
14611 flp
= &fip
->fnfieldlists
.back ();
14612 flp
->name
= fieldname
;
14613 i
= fip
->fnfieldlists
.size () - 1;
14616 /* Create a new member function field and add it to the vector of
14618 flp
->fnfields
.emplace_back ();
14619 fnp
= &flp
->fnfields
.back ();
14621 /* Delay processing of the physname until later. */
14622 if (cu
->language
== language_cplus
)
14623 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14627 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14628 fnp
->physname
= physname
? physname
: "";
14631 fnp
->type
= alloc_type (objfile
);
14632 this_type
= read_type_die (die
, cu
);
14633 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14635 int nparams
= TYPE_NFIELDS (this_type
);
14637 /* TYPE is the domain of this method, and THIS_TYPE is the type
14638 of the method itself (TYPE_CODE_METHOD). */
14639 smash_to_method_type (fnp
->type
, type
,
14640 TYPE_TARGET_TYPE (this_type
),
14641 TYPE_FIELDS (this_type
),
14642 TYPE_NFIELDS (this_type
),
14643 TYPE_VARARGS (this_type
));
14645 /* Handle static member functions.
14646 Dwarf2 has no clean way to discern C++ static and non-static
14647 member functions. G++ helps GDB by marking the first
14648 parameter for non-static member functions (which is the this
14649 pointer) as artificial. We obtain this information from
14650 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14651 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14652 fnp
->voffset
= VOFFSET_STATIC
;
14655 complaint (_("member function type missing for '%s'"),
14656 dwarf2_full_name (fieldname
, die
, cu
));
14658 /* Get fcontext from DW_AT_containing_type if present. */
14659 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14660 fnp
->fcontext
= die_containing_type (die
, cu
);
14662 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14663 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14665 /* Get accessibility. */
14666 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14667 if (attr
!= nullptr)
14668 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14670 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14671 switch (accessibility
)
14673 case DW_ACCESS_private
:
14674 fnp
->is_private
= 1;
14676 case DW_ACCESS_protected
:
14677 fnp
->is_protected
= 1;
14681 /* Check for artificial methods. */
14682 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14683 if (attr
&& DW_UNSND (attr
) != 0)
14684 fnp
->is_artificial
= 1;
14686 /* Check for defaulted methods. */
14687 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14688 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14689 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14691 /* Check for deleted methods. */
14692 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14693 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14694 fnp
->is_deleted
= 1;
14696 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14698 /* Get index in virtual function table if it is a virtual member
14699 function. For older versions of GCC, this is an offset in the
14700 appropriate virtual table, as specified by DW_AT_containing_type.
14701 For everyone else, it is an expression to be evaluated relative
14702 to the object address. */
14704 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14705 if (attr
!= nullptr)
14707 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14709 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14711 /* Old-style GCC. */
14712 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14714 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14715 || (DW_BLOCK (attr
)->size
> 1
14716 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14717 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14719 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14720 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14721 dwarf2_complex_location_expr_complaint ();
14723 fnp
->voffset
/= cu
->header
.addr_size
;
14727 dwarf2_complex_location_expr_complaint ();
14729 if (!fnp
->fcontext
)
14731 /* If there is no `this' field and no DW_AT_containing_type,
14732 we cannot actually find a base class context for the
14734 if (TYPE_NFIELDS (this_type
) == 0
14735 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14737 complaint (_("cannot determine context for virtual member "
14738 "function \"%s\" (offset %s)"),
14739 fieldname
, sect_offset_str (die
->sect_off
));
14744 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14748 else if (attr
->form_is_section_offset ())
14750 dwarf2_complex_location_expr_complaint ();
14754 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14760 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14761 if (attr
&& DW_UNSND (attr
))
14763 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14764 complaint (_("Member function \"%s\" (offset %s) is virtual "
14765 "but the vtable offset is not specified"),
14766 fieldname
, sect_offset_str (die
->sect_off
));
14767 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14768 TYPE_CPLUS_DYNAMIC (type
) = 1;
14773 /* Create the vector of member function fields, and attach it to the type. */
14776 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14777 struct dwarf2_cu
*cu
)
14779 if (cu
->language
== language_ada
)
14780 error (_("unexpected member functions in Ada type"));
14782 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14783 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14785 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14787 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14789 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14790 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14792 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14793 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14794 fn_flp
->fn_fields
= (struct fn_field
*)
14795 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14797 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14798 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14801 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14804 /* Returns non-zero if NAME is the name of a vtable member in CU's
14805 language, zero otherwise. */
14807 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14809 static const char vptr
[] = "_vptr";
14811 /* Look for the C++ form of the vtable. */
14812 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14818 /* GCC outputs unnamed structures that are really pointers to member
14819 functions, with the ABI-specified layout. If TYPE describes
14820 such a structure, smash it into a member function type.
14822 GCC shouldn't do this; it should just output pointer to member DIEs.
14823 This is GCC PR debug/28767. */
14826 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14828 struct type
*pfn_type
, *self_type
, *new_type
;
14830 /* Check for a structure with no name and two children. */
14831 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14834 /* Check for __pfn and __delta members. */
14835 if (TYPE_FIELD_NAME (type
, 0) == NULL
14836 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14837 || TYPE_FIELD_NAME (type
, 1) == NULL
14838 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14841 /* Find the type of the method. */
14842 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14843 if (pfn_type
== NULL
14844 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14845 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14848 /* Look for the "this" argument. */
14849 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14850 if (TYPE_NFIELDS (pfn_type
) == 0
14851 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14852 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14855 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14856 new_type
= alloc_type (objfile
);
14857 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14858 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14859 TYPE_VARARGS (pfn_type
));
14860 smash_to_methodptr_type (type
, new_type
);
14863 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14864 appropriate error checking and issuing complaints if there is a
14868 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14870 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14872 if (attr
== nullptr)
14875 if (!attr
->form_is_constant ())
14877 complaint (_("DW_AT_alignment must have constant form"
14878 " - DIE at %s [in module %s]"),
14879 sect_offset_str (die
->sect_off
),
14880 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14885 if (attr
->form
== DW_FORM_sdata
)
14887 LONGEST val
= DW_SND (attr
);
14890 complaint (_("DW_AT_alignment value must not be negative"
14891 " - DIE at %s [in module %s]"),
14892 sect_offset_str (die
->sect_off
),
14893 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14899 align
= DW_UNSND (attr
);
14903 complaint (_("DW_AT_alignment value must not be zero"
14904 " - DIE at %s [in module %s]"),
14905 sect_offset_str (die
->sect_off
),
14906 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14909 if ((align
& (align
- 1)) != 0)
14911 complaint (_("DW_AT_alignment value must be a power of 2"
14912 " - DIE at %s [in module %s]"),
14913 sect_offset_str (die
->sect_off
),
14914 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14921 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14922 the alignment for TYPE. */
14925 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14928 if (!set_type_align (type
, get_alignment (cu
, die
)))
14929 complaint (_("DW_AT_alignment value too large"
14930 " - DIE at %s [in module %s]"),
14931 sect_offset_str (die
->sect_off
),
14932 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14935 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14936 constant for a type, according to DWARF5 spec, Table 5.5. */
14939 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14944 case DW_CC_pass_by_reference
:
14945 case DW_CC_pass_by_value
:
14949 complaint (_("unrecognized DW_AT_calling_convention value "
14950 "(%s) for a type"), pulongest (value
));
14955 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14956 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14957 also according to GNU-specific values (see include/dwarf2.h). */
14960 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14965 case DW_CC_program
:
14969 case DW_CC_GNU_renesas_sh
:
14970 case DW_CC_GNU_borland_fastcall_i386
:
14971 case DW_CC_GDB_IBM_OpenCL
:
14975 complaint (_("unrecognized DW_AT_calling_convention value "
14976 "(%s) for a subroutine"), pulongest (value
));
14981 /* Called when we find the DIE that starts a structure or union scope
14982 (definition) to create a type for the structure or union. Fill in
14983 the type's name and general properties; the members will not be
14984 processed until process_structure_scope. A symbol table entry for
14985 the type will also not be done until process_structure_scope (assuming
14986 the type has a name).
14988 NOTE: we need to call these functions regardless of whether or not the
14989 DIE has a DW_AT_name attribute, since it might be an anonymous
14990 structure or union. This gets the type entered into our set of
14991 user defined types. */
14993 static struct type
*
14994 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14996 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14998 struct attribute
*attr
;
15001 /* If the definition of this type lives in .debug_types, read that type.
15002 Don't follow DW_AT_specification though, that will take us back up
15003 the chain and we want to go down. */
15004 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15005 if (attr
!= nullptr)
15007 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15009 /* The type's CU may not be the same as CU.
15010 Ensure TYPE is recorded with CU in die_type_hash. */
15011 return set_die_type (die
, type
, cu
);
15014 type
= alloc_type (objfile
);
15015 INIT_CPLUS_SPECIFIC (type
);
15017 name
= dwarf2_name (die
, cu
);
15020 if (cu
->language
== language_cplus
15021 || cu
->language
== language_d
15022 || cu
->language
== language_rust
)
15024 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15026 /* dwarf2_full_name might have already finished building the DIE's
15027 type. If so, there is no need to continue. */
15028 if (get_die_type (die
, cu
) != NULL
)
15029 return get_die_type (die
, cu
);
15031 TYPE_NAME (type
) = full_name
;
15035 /* The name is already allocated along with this objfile, so
15036 we don't need to duplicate it for the type. */
15037 TYPE_NAME (type
) = name
;
15041 if (die
->tag
== DW_TAG_structure_type
)
15043 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15045 else if (die
->tag
== DW_TAG_union_type
)
15047 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15049 else if (die
->tag
== DW_TAG_variant_part
)
15051 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15052 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15056 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15059 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15060 TYPE_DECLARED_CLASS (type
) = 1;
15062 /* Store the calling convention in the type if it's available in
15063 the die. Otherwise the calling convention remains set to
15064 the default value DW_CC_normal. */
15065 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15066 if (attr
!= nullptr
15067 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15069 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15070 TYPE_CPLUS_CALLING_CONVENTION (type
)
15071 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15074 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15075 if (attr
!= nullptr)
15077 if (attr
->form_is_constant ())
15078 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15081 /* For the moment, dynamic type sizes are not supported
15082 by GDB's struct type. The actual size is determined
15083 on-demand when resolving the type of a given object,
15084 so set the type's length to zero for now. Otherwise,
15085 we record an expression as the length, and that expression
15086 could lead to a very large value, which could eventually
15087 lead to us trying to allocate that much memory when creating
15088 a value of that type. */
15089 TYPE_LENGTH (type
) = 0;
15094 TYPE_LENGTH (type
) = 0;
15097 maybe_set_alignment (cu
, die
, type
);
15099 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15101 /* ICC<14 does not output the required DW_AT_declaration on
15102 incomplete types, but gives them a size of zero. */
15103 TYPE_STUB (type
) = 1;
15106 TYPE_STUB_SUPPORTED (type
) = 1;
15108 if (die_is_declaration (die
, cu
))
15109 TYPE_STUB (type
) = 1;
15110 else if (attr
== NULL
&& die
->child
== NULL
15111 && producer_is_realview (cu
->producer
))
15112 /* RealView does not output the required DW_AT_declaration
15113 on incomplete types. */
15114 TYPE_STUB (type
) = 1;
15116 /* We need to add the type field to the die immediately so we don't
15117 infinitely recurse when dealing with pointers to the structure
15118 type within the structure itself. */
15119 set_die_type (die
, type
, cu
);
15121 /* set_die_type should be already done. */
15122 set_descriptive_type (type
, die
, cu
);
15127 /* A helper for process_structure_scope that handles a single member
15131 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15132 struct field_info
*fi
,
15133 std::vector
<struct symbol
*> *template_args
,
15134 struct dwarf2_cu
*cu
)
15136 if (child_die
->tag
== DW_TAG_member
15137 || child_die
->tag
== DW_TAG_variable
15138 || child_die
->tag
== DW_TAG_variant_part
)
15140 /* NOTE: carlton/2002-11-05: A C++ static data member
15141 should be a DW_TAG_member that is a declaration, but
15142 all versions of G++ as of this writing (so through at
15143 least 3.2.1) incorrectly generate DW_TAG_variable
15144 tags for them instead. */
15145 dwarf2_add_field (fi
, child_die
, cu
);
15147 else if (child_die
->tag
== DW_TAG_subprogram
)
15149 /* Rust doesn't have member functions in the C++ sense.
15150 However, it does emit ordinary functions as children
15151 of a struct DIE. */
15152 if (cu
->language
== language_rust
)
15153 read_func_scope (child_die
, cu
);
15156 /* C++ member function. */
15157 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15160 else if (child_die
->tag
== DW_TAG_inheritance
)
15162 /* C++ base class field. */
15163 dwarf2_add_field (fi
, child_die
, cu
);
15165 else if (type_can_define_types (child_die
))
15166 dwarf2_add_type_defn (fi
, child_die
, cu
);
15167 else if (child_die
->tag
== DW_TAG_template_type_param
15168 || child_die
->tag
== DW_TAG_template_value_param
)
15170 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15173 template_args
->push_back (arg
);
15175 else if (child_die
->tag
== DW_TAG_variant
)
15177 /* In a variant we want to get the discriminant and also add a
15178 field for our sole member child. */
15179 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15181 for (die_info
*variant_child
= child_die
->child
;
15182 variant_child
!= NULL
;
15183 variant_child
= sibling_die (variant_child
))
15185 if (variant_child
->tag
== DW_TAG_member
)
15187 handle_struct_member_die (variant_child
, type
, fi
,
15188 template_args
, cu
);
15189 /* Only handle the one. */
15194 /* We don't handle this but we might as well report it if we see
15196 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15197 complaint (_("DW_AT_discr_list is not supported yet"
15198 " - DIE at %s [in module %s]"),
15199 sect_offset_str (child_die
->sect_off
),
15200 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15202 /* The first field was just added, so we can stash the
15203 discriminant there. */
15204 gdb_assert (!fi
->fields
.empty ());
15206 fi
->fields
.back ().variant
.default_branch
= true;
15208 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15212 /* Finish creating a structure or union type, including filling in
15213 its members and creating a symbol for it. */
15216 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15218 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15219 struct die_info
*child_die
;
15222 type
= get_die_type (die
, cu
);
15224 type
= read_structure_type (die
, cu
);
15226 /* When reading a DW_TAG_variant_part, we need to notice when we
15227 read the discriminant member, so we can record it later in the
15228 discriminant_info. */
15229 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15230 sect_offset discr_offset
{};
15231 bool has_template_parameters
= false;
15233 if (is_variant_part
)
15235 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15238 /* Maybe it's a univariant form, an extension we support.
15239 In this case arrange not to check the offset. */
15240 is_variant_part
= false;
15242 else if (discr
->form_is_ref ())
15244 struct dwarf2_cu
*target_cu
= cu
;
15245 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15247 discr_offset
= target_die
->sect_off
;
15251 complaint (_("DW_AT_discr does not have DIE reference form"
15252 " - DIE at %s [in module %s]"),
15253 sect_offset_str (die
->sect_off
),
15254 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15255 is_variant_part
= false;
15259 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15261 struct field_info fi
;
15262 std::vector
<struct symbol
*> template_args
;
15264 child_die
= die
->child
;
15266 while (child_die
&& child_die
->tag
)
15268 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15270 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15271 fi
.fields
.back ().variant
.is_discriminant
= true;
15273 child_die
= sibling_die (child_die
);
15276 /* Attach template arguments to type. */
15277 if (!template_args
.empty ())
15279 has_template_parameters
= true;
15280 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15281 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15282 TYPE_TEMPLATE_ARGUMENTS (type
)
15283 = XOBNEWVEC (&objfile
->objfile_obstack
,
15285 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15286 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15287 template_args
.data (),
15288 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15289 * sizeof (struct symbol
*)));
15292 /* Attach fields and member functions to the type. */
15294 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15295 if (!fi
.fnfieldlists
.empty ())
15297 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15299 /* Get the type which refers to the base class (possibly this
15300 class itself) which contains the vtable pointer for the current
15301 class from the DW_AT_containing_type attribute. This use of
15302 DW_AT_containing_type is a GNU extension. */
15304 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15306 struct type
*t
= die_containing_type (die
, cu
);
15308 set_type_vptr_basetype (type
, t
);
15313 /* Our own class provides vtbl ptr. */
15314 for (i
= TYPE_NFIELDS (t
) - 1;
15315 i
>= TYPE_N_BASECLASSES (t
);
15318 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15320 if (is_vtable_name (fieldname
, cu
))
15322 set_type_vptr_fieldno (type
, i
);
15327 /* Complain if virtual function table field not found. */
15328 if (i
< TYPE_N_BASECLASSES (t
))
15329 complaint (_("virtual function table pointer "
15330 "not found when defining class '%s'"),
15331 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15335 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15338 else if (cu
->producer
15339 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15341 /* The IBM XLC compiler does not provide direct indication
15342 of the containing type, but the vtable pointer is
15343 always named __vfp. */
15347 for (i
= TYPE_NFIELDS (type
) - 1;
15348 i
>= TYPE_N_BASECLASSES (type
);
15351 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15353 set_type_vptr_fieldno (type
, i
);
15354 set_type_vptr_basetype (type
, type
);
15361 /* Copy fi.typedef_field_list linked list elements content into the
15362 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15363 if (!fi
.typedef_field_list
.empty ())
15365 int count
= fi
.typedef_field_list
.size ();
15367 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15368 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15369 = ((struct decl_field
*)
15371 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15372 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15374 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15375 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15378 /* Copy fi.nested_types_list linked list elements content into the
15379 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15380 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15382 int count
= fi
.nested_types_list
.size ();
15384 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15385 TYPE_NESTED_TYPES_ARRAY (type
)
15386 = ((struct decl_field
*)
15387 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15388 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15390 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15391 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15395 quirk_gcc_member_function_pointer (type
, objfile
);
15396 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15397 cu
->rust_unions
.push_back (type
);
15399 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15400 snapshots) has been known to create a die giving a declaration
15401 for a class that has, as a child, a die giving a definition for a
15402 nested class. So we have to process our children even if the
15403 current die is a declaration. Normally, of course, a declaration
15404 won't have any children at all. */
15406 child_die
= die
->child
;
15408 while (child_die
!= NULL
&& child_die
->tag
)
15410 if (child_die
->tag
== DW_TAG_member
15411 || child_die
->tag
== DW_TAG_variable
15412 || child_die
->tag
== DW_TAG_inheritance
15413 || child_die
->tag
== DW_TAG_template_value_param
15414 || child_die
->tag
== DW_TAG_template_type_param
)
15419 process_die (child_die
, cu
);
15421 child_die
= sibling_die (child_die
);
15424 /* Do not consider external references. According to the DWARF standard,
15425 these DIEs are identified by the fact that they have no byte_size
15426 attribute, and a declaration attribute. */
15427 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15428 || !die_is_declaration (die
, cu
))
15430 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15432 if (has_template_parameters
)
15434 struct symtab
*symtab
;
15435 if (sym
!= nullptr)
15436 symtab
= symbol_symtab (sym
);
15437 else if (cu
->line_header
!= nullptr)
15439 /* Any related symtab will do. */
15441 = cu
->line_header
->file_names ()[0].symtab
;
15446 complaint (_("could not find suitable "
15447 "symtab for template parameter"
15448 " - DIE at %s [in module %s]"),
15449 sect_offset_str (die
->sect_off
),
15450 objfile_name (objfile
));
15453 if (symtab
!= nullptr)
15455 /* Make sure that the symtab is set on the new symbols.
15456 Even though they don't appear in this symtab directly,
15457 other parts of gdb assume that symbols do, and this is
15458 reasonably true. */
15459 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15460 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15466 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15467 update TYPE using some information only available in DIE's children. */
15470 update_enumeration_type_from_children (struct die_info
*die
,
15472 struct dwarf2_cu
*cu
)
15474 struct die_info
*child_die
;
15475 int unsigned_enum
= 1;
15478 auto_obstack obstack
;
15480 for (child_die
= die
->child
;
15481 child_die
!= NULL
&& child_die
->tag
;
15482 child_die
= sibling_die (child_die
))
15484 struct attribute
*attr
;
15486 const gdb_byte
*bytes
;
15487 struct dwarf2_locexpr_baton
*baton
;
15490 if (child_die
->tag
!= DW_TAG_enumerator
)
15493 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15497 name
= dwarf2_name (child_die
, cu
);
15499 name
= "<anonymous enumerator>";
15501 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15502 &value
, &bytes
, &baton
);
15510 if (count_one_bits_ll (value
) >= 2)
15514 /* If we already know that the enum type is neither unsigned, nor
15515 a flag type, no need to look at the rest of the enumerates. */
15516 if (!unsigned_enum
&& !flag_enum
)
15521 TYPE_UNSIGNED (type
) = 1;
15523 TYPE_FLAG_ENUM (type
) = 1;
15526 /* Given a DW_AT_enumeration_type die, set its type. We do not
15527 complete the type's fields yet, or create any symbols. */
15529 static struct type
*
15530 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15532 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15534 struct attribute
*attr
;
15537 /* If the definition of this type lives in .debug_types, read that type.
15538 Don't follow DW_AT_specification though, that will take us back up
15539 the chain and we want to go down. */
15540 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15541 if (attr
!= nullptr)
15543 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15545 /* The type's CU may not be the same as CU.
15546 Ensure TYPE is recorded with CU in die_type_hash. */
15547 return set_die_type (die
, type
, cu
);
15550 type
= alloc_type (objfile
);
15552 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15553 name
= dwarf2_full_name (NULL
, die
, cu
);
15555 TYPE_NAME (type
) = name
;
15557 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15560 struct type
*underlying_type
= die_type (die
, cu
);
15562 TYPE_TARGET_TYPE (type
) = underlying_type
;
15565 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15566 if (attr
!= nullptr)
15568 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15572 TYPE_LENGTH (type
) = 0;
15575 maybe_set_alignment (cu
, die
, type
);
15577 /* The enumeration DIE can be incomplete. In Ada, any type can be
15578 declared as private in the package spec, and then defined only
15579 inside the package body. Such types are known as Taft Amendment
15580 Types. When another package uses such a type, an incomplete DIE
15581 may be generated by the compiler. */
15582 if (die_is_declaration (die
, cu
))
15583 TYPE_STUB (type
) = 1;
15585 /* Finish the creation of this type by using the enum's children.
15586 We must call this even when the underlying type has been provided
15587 so that we can determine if we're looking at a "flag" enum. */
15588 update_enumeration_type_from_children (die
, type
, cu
);
15590 /* If this type has an underlying type that is not a stub, then we
15591 may use its attributes. We always use the "unsigned" attribute
15592 in this situation, because ordinarily we guess whether the type
15593 is unsigned -- but the guess can be wrong and the underlying type
15594 can tell us the reality. However, we defer to a local size
15595 attribute if one exists, because this lets the compiler override
15596 the underlying type if needed. */
15597 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15599 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15600 if (TYPE_LENGTH (type
) == 0)
15601 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15602 if (TYPE_RAW_ALIGN (type
) == 0
15603 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15604 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15607 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15609 return set_die_type (die
, type
, cu
);
15612 /* Given a pointer to a die which begins an enumeration, process all
15613 the dies that define the members of the enumeration, and create the
15614 symbol for the enumeration type.
15616 NOTE: We reverse the order of the element list. */
15619 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15621 struct type
*this_type
;
15623 this_type
= get_die_type (die
, cu
);
15624 if (this_type
== NULL
)
15625 this_type
= read_enumeration_type (die
, cu
);
15627 if (die
->child
!= NULL
)
15629 struct die_info
*child_die
;
15630 struct symbol
*sym
;
15631 std::vector
<struct field
> fields
;
15634 child_die
= die
->child
;
15635 while (child_die
&& child_die
->tag
)
15637 if (child_die
->tag
!= DW_TAG_enumerator
)
15639 process_die (child_die
, cu
);
15643 name
= dwarf2_name (child_die
, cu
);
15646 sym
= new_symbol (child_die
, this_type
, cu
);
15648 fields
.emplace_back ();
15649 struct field
&field
= fields
.back ();
15651 FIELD_NAME (field
) = sym
->linkage_name ();
15652 FIELD_TYPE (field
) = NULL
;
15653 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15654 FIELD_BITSIZE (field
) = 0;
15658 child_die
= sibling_die (child_die
);
15661 if (!fields
.empty ())
15663 TYPE_NFIELDS (this_type
) = fields
.size ();
15664 TYPE_FIELDS (this_type
) = (struct field
*)
15665 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15666 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15667 sizeof (struct field
) * fields
.size ());
15671 /* If we are reading an enum from a .debug_types unit, and the enum
15672 is a declaration, and the enum is not the signatured type in the
15673 unit, then we do not want to add a symbol for it. Adding a
15674 symbol would in some cases obscure the true definition of the
15675 enum, giving users an incomplete type when the definition is
15676 actually available. Note that we do not want to do this for all
15677 enums which are just declarations, because C++0x allows forward
15678 enum declarations. */
15679 if (cu
->per_cu
->is_debug_types
15680 && die_is_declaration (die
, cu
))
15682 struct signatured_type
*sig_type
;
15684 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15685 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15686 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15690 new_symbol (die
, this_type
, cu
);
15693 /* Extract all information from a DW_TAG_array_type DIE and put it in
15694 the DIE's type field. For now, this only handles one dimensional
15697 static struct type
*
15698 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15700 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15701 struct die_info
*child_die
;
15703 struct type
*element_type
, *range_type
, *index_type
;
15704 struct attribute
*attr
;
15706 struct dynamic_prop
*byte_stride_prop
= NULL
;
15707 unsigned int bit_stride
= 0;
15709 element_type
= die_type (die
, cu
);
15711 /* The die_type call above may have already set the type for this DIE. */
15712 type
= get_die_type (die
, cu
);
15716 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15720 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15723 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15724 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15728 complaint (_("unable to read array DW_AT_byte_stride "
15729 " - DIE at %s [in module %s]"),
15730 sect_offset_str (die
->sect_off
),
15731 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15732 /* Ignore this attribute. We will likely not be able to print
15733 arrays of this type correctly, but there is little we can do
15734 to help if we cannot read the attribute's value. */
15735 byte_stride_prop
= NULL
;
15739 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15741 bit_stride
= DW_UNSND (attr
);
15743 /* Irix 6.2 native cc creates array types without children for
15744 arrays with unspecified length. */
15745 if (die
->child
== NULL
)
15747 index_type
= objfile_type (objfile
)->builtin_int
;
15748 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15749 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15750 byte_stride_prop
, bit_stride
);
15751 return set_die_type (die
, type
, cu
);
15754 std::vector
<struct type
*> range_types
;
15755 child_die
= die
->child
;
15756 while (child_die
&& child_die
->tag
)
15758 if (child_die
->tag
== DW_TAG_subrange_type
)
15760 struct type
*child_type
= read_type_die (child_die
, cu
);
15762 if (child_type
!= NULL
)
15764 /* The range type was succesfully read. Save it for the
15765 array type creation. */
15766 range_types
.push_back (child_type
);
15769 child_die
= sibling_die (child_die
);
15772 /* Dwarf2 dimensions are output from left to right, create the
15773 necessary array types in backwards order. */
15775 type
= element_type
;
15777 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15781 while (i
< range_types
.size ())
15782 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15783 byte_stride_prop
, bit_stride
);
15787 size_t ndim
= range_types
.size ();
15789 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15790 byte_stride_prop
, bit_stride
);
15793 /* Understand Dwarf2 support for vector types (like they occur on
15794 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15795 array type. This is not part of the Dwarf2/3 standard yet, but a
15796 custom vendor extension. The main difference between a regular
15797 array and the vector variant is that vectors are passed by value
15799 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15800 if (attr
!= nullptr)
15801 make_vector_type (type
);
15803 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15804 implementation may choose to implement triple vectors using this
15806 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15807 if (attr
!= nullptr)
15809 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15810 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15812 complaint (_("DW_AT_byte_size for array type smaller "
15813 "than the total size of elements"));
15816 name
= dwarf2_name (die
, cu
);
15818 TYPE_NAME (type
) = name
;
15820 maybe_set_alignment (cu
, die
, type
);
15822 /* Install the type in the die. */
15823 set_die_type (die
, type
, cu
);
15825 /* set_die_type should be already done. */
15826 set_descriptive_type (type
, die
, cu
);
15831 static enum dwarf_array_dim_ordering
15832 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15834 struct attribute
*attr
;
15836 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15838 if (attr
!= nullptr)
15839 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15841 /* GNU F77 is a special case, as at 08/2004 array type info is the
15842 opposite order to the dwarf2 specification, but data is still
15843 laid out as per normal fortran.
15845 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15846 version checking. */
15848 if (cu
->language
== language_fortran
15849 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15851 return DW_ORD_row_major
;
15854 switch (cu
->language_defn
->la_array_ordering
)
15856 case array_column_major
:
15857 return DW_ORD_col_major
;
15858 case array_row_major
:
15860 return DW_ORD_row_major
;
15864 /* Extract all information from a DW_TAG_set_type DIE and put it in
15865 the DIE's type field. */
15867 static struct type
*
15868 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15870 struct type
*domain_type
, *set_type
;
15871 struct attribute
*attr
;
15873 domain_type
= die_type (die
, cu
);
15875 /* The die_type call above may have already set the type for this DIE. */
15876 set_type
= get_die_type (die
, cu
);
15880 set_type
= create_set_type (NULL
, domain_type
);
15882 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15883 if (attr
!= nullptr)
15884 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15886 maybe_set_alignment (cu
, die
, set_type
);
15888 return set_die_type (die
, set_type
, cu
);
15891 /* A helper for read_common_block that creates a locexpr baton.
15892 SYM is the symbol which we are marking as computed.
15893 COMMON_DIE is the DIE for the common block.
15894 COMMON_LOC is the location expression attribute for the common
15896 MEMBER_LOC is the location expression attribute for the particular
15897 member of the common block that we are processing.
15898 CU is the CU from which the above come. */
15901 mark_common_block_symbol_computed (struct symbol
*sym
,
15902 struct die_info
*common_die
,
15903 struct attribute
*common_loc
,
15904 struct attribute
*member_loc
,
15905 struct dwarf2_cu
*cu
)
15907 struct dwarf2_per_objfile
*dwarf2_per_objfile
15908 = cu
->per_cu
->dwarf2_per_objfile
;
15909 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15910 struct dwarf2_locexpr_baton
*baton
;
15912 unsigned int cu_off
;
15913 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15914 LONGEST offset
= 0;
15916 gdb_assert (common_loc
&& member_loc
);
15917 gdb_assert (common_loc
->form_is_block ());
15918 gdb_assert (member_loc
->form_is_block ()
15919 || member_loc
->form_is_constant ());
15921 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15922 baton
->per_cu
= cu
->per_cu
;
15923 gdb_assert (baton
->per_cu
);
15925 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15927 if (member_loc
->form_is_constant ())
15929 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15930 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15933 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15935 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15938 *ptr
++ = DW_OP_call4
;
15939 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15940 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15943 if (member_loc
->form_is_constant ())
15945 *ptr
++ = DW_OP_addr
;
15946 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15947 ptr
+= cu
->header
.addr_size
;
15951 /* We have to copy the data here, because DW_OP_call4 will only
15952 use a DW_AT_location attribute. */
15953 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15954 ptr
+= DW_BLOCK (member_loc
)->size
;
15957 *ptr
++ = DW_OP_plus
;
15958 gdb_assert (ptr
- baton
->data
== baton
->size
);
15960 SYMBOL_LOCATION_BATON (sym
) = baton
;
15961 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15964 /* Create appropriate locally-scoped variables for all the
15965 DW_TAG_common_block entries. Also create a struct common_block
15966 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15967 is used to separate the common blocks name namespace from regular
15971 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15973 struct attribute
*attr
;
15975 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15976 if (attr
!= nullptr)
15978 /* Support the .debug_loc offsets. */
15979 if (attr
->form_is_block ())
15983 else if (attr
->form_is_section_offset ())
15985 dwarf2_complex_location_expr_complaint ();
15990 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15991 "common block member");
15996 if (die
->child
!= NULL
)
15998 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15999 struct die_info
*child_die
;
16000 size_t n_entries
= 0, size
;
16001 struct common_block
*common_block
;
16002 struct symbol
*sym
;
16004 for (child_die
= die
->child
;
16005 child_die
&& child_die
->tag
;
16006 child_die
= sibling_die (child_die
))
16009 size
= (sizeof (struct common_block
)
16010 + (n_entries
- 1) * sizeof (struct symbol
*));
16012 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16014 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16015 common_block
->n_entries
= 0;
16017 for (child_die
= die
->child
;
16018 child_die
&& child_die
->tag
;
16019 child_die
= sibling_die (child_die
))
16021 /* Create the symbol in the DW_TAG_common_block block in the current
16023 sym
= new_symbol (child_die
, NULL
, cu
);
16026 struct attribute
*member_loc
;
16028 common_block
->contents
[common_block
->n_entries
++] = sym
;
16030 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16034 /* GDB has handled this for a long time, but it is
16035 not specified by DWARF. It seems to have been
16036 emitted by gfortran at least as recently as:
16037 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16038 complaint (_("Variable in common block has "
16039 "DW_AT_data_member_location "
16040 "- DIE at %s [in module %s]"),
16041 sect_offset_str (child_die
->sect_off
),
16042 objfile_name (objfile
));
16044 if (member_loc
->form_is_section_offset ())
16045 dwarf2_complex_location_expr_complaint ();
16046 else if (member_loc
->form_is_constant ()
16047 || member_loc
->form_is_block ())
16049 if (attr
!= nullptr)
16050 mark_common_block_symbol_computed (sym
, die
, attr
,
16054 dwarf2_complex_location_expr_complaint ();
16059 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16060 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16064 /* Create a type for a C++ namespace. */
16066 static struct type
*
16067 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16069 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16070 const char *previous_prefix
, *name
;
16074 /* For extensions, reuse the type of the original namespace. */
16075 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16077 struct die_info
*ext_die
;
16078 struct dwarf2_cu
*ext_cu
= cu
;
16080 ext_die
= dwarf2_extension (die
, &ext_cu
);
16081 type
= read_type_die (ext_die
, ext_cu
);
16083 /* EXT_CU may not be the same as CU.
16084 Ensure TYPE is recorded with CU in die_type_hash. */
16085 return set_die_type (die
, type
, cu
);
16088 name
= namespace_name (die
, &is_anonymous
, cu
);
16090 /* Now build the name of the current namespace. */
16092 previous_prefix
= determine_prefix (die
, cu
);
16093 if (previous_prefix
[0] != '\0')
16094 name
= typename_concat (&objfile
->objfile_obstack
,
16095 previous_prefix
, name
, 0, cu
);
16097 /* Create the type. */
16098 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16100 return set_die_type (die
, type
, cu
);
16103 /* Read a namespace scope. */
16106 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16108 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16111 /* Add a symbol associated to this if we haven't seen the namespace
16112 before. Also, add a using directive if it's an anonymous
16115 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16119 type
= read_type_die (die
, cu
);
16120 new_symbol (die
, type
, cu
);
16122 namespace_name (die
, &is_anonymous
, cu
);
16125 const char *previous_prefix
= determine_prefix (die
, cu
);
16127 std::vector
<const char *> excludes
;
16128 add_using_directive (using_directives (cu
),
16129 previous_prefix
, TYPE_NAME (type
), NULL
,
16130 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16134 if (die
->child
!= NULL
)
16136 struct die_info
*child_die
= die
->child
;
16138 while (child_die
&& child_die
->tag
)
16140 process_die (child_die
, cu
);
16141 child_die
= sibling_die (child_die
);
16146 /* Read a Fortran module as type. This DIE can be only a declaration used for
16147 imported module. Still we need that type as local Fortran "use ... only"
16148 declaration imports depend on the created type in determine_prefix. */
16150 static struct type
*
16151 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16153 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16154 const char *module_name
;
16157 module_name
= dwarf2_name (die
, cu
);
16158 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16160 return set_die_type (die
, type
, cu
);
16163 /* Read a Fortran module. */
16166 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16168 struct die_info
*child_die
= die
->child
;
16171 type
= read_type_die (die
, cu
);
16172 new_symbol (die
, type
, cu
);
16174 while (child_die
&& child_die
->tag
)
16176 process_die (child_die
, cu
);
16177 child_die
= sibling_die (child_die
);
16181 /* Return the name of the namespace represented by DIE. Set
16182 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16185 static const char *
16186 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16188 struct die_info
*current_die
;
16189 const char *name
= NULL
;
16191 /* Loop through the extensions until we find a name. */
16193 for (current_die
= die
;
16194 current_die
!= NULL
;
16195 current_die
= dwarf2_extension (die
, &cu
))
16197 /* We don't use dwarf2_name here so that we can detect the absence
16198 of a name -> anonymous namespace. */
16199 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16205 /* Is it an anonymous namespace? */
16207 *is_anonymous
= (name
== NULL
);
16209 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16214 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16215 the user defined type vector. */
16217 static struct type
*
16218 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16220 struct gdbarch
*gdbarch
16221 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16222 struct comp_unit_head
*cu_header
= &cu
->header
;
16224 struct attribute
*attr_byte_size
;
16225 struct attribute
*attr_address_class
;
16226 int byte_size
, addr_class
;
16227 struct type
*target_type
;
16229 target_type
= die_type (die
, cu
);
16231 /* The die_type call above may have already set the type for this DIE. */
16232 type
= get_die_type (die
, cu
);
16236 type
= lookup_pointer_type (target_type
);
16238 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16239 if (attr_byte_size
)
16240 byte_size
= DW_UNSND (attr_byte_size
);
16242 byte_size
= cu_header
->addr_size
;
16244 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16245 if (attr_address_class
)
16246 addr_class
= DW_UNSND (attr_address_class
);
16248 addr_class
= DW_ADDR_none
;
16250 ULONGEST alignment
= get_alignment (cu
, die
);
16252 /* If the pointer size, alignment, or address class is different
16253 than the default, create a type variant marked as such and set
16254 the length accordingly. */
16255 if (TYPE_LENGTH (type
) != byte_size
16256 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16257 && alignment
!= TYPE_RAW_ALIGN (type
))
16258 || addr_class
!= DW_ADDR_none
)
16260 if (gdbarch_address_class_type_flags_p (gdbarch
))
16264 type_flags
= gdbarch_address_class_type_flags
16265 (gdbarch
, byte_size
, addr_class
);
16266 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16268 type
= make_type_with_address_space (type
, type_flags
);
16270 else if (TYPE_LENGTH (type
) != byte_size
)
16272 complaint (_("invalid pointer size %d"), byte_size
);
16274 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16276 complaint (_("Invalid DW_AT_alignment"
16277 " - DIE at %s [in module %s]"),
16278 sect_offset_str (die
->sect_off
),
16279 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16283 /* Should we also complain about unhandled address classes? */
16287 TYPE_LENGTH (type
) = byte_size
;
16288 set_type_align (type
, alignment
);
16289 return set_die_type (die
, type
, cu
);
16292 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16293 the user defined type vector. */
16295 static struct type
*
16296 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16299 struct type
*to_type
;
16300 struct type
*domain
;
16302 to_type
= die_type (die
, cu
);
16303 domain
= die_containing_type (die
, cu
);
16305 /* The calls above may have already set the type for this DIE. */
16306 type
= get_die_type (die
, cu
);
16310 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16311 type
= lookup_methodptr_type (to_type
);
16312 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16314 struct type
*new_type
16315 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16317 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16318 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16319 TYPE_VARARGS (to_type
));
16320 type
= lookup_methodptr_type (new_type
);
16323 type
= lookup_memberptr_type (to_type
, domain
);
16325 return set_die_type (die
, type
, cu
);
16328 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16329 the user defined type vector. */
16331 static struct type
*
16332 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16333 enum type_code refcode
)
16335 struct comp_unit_head
*cu_header
= &cu
->header
;
16336 struct type
*type
, *target_type
;
16337 struct attribute
*attr
;
16339 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16341 target_type
= die_type (die
, cu
);
16343 /* The die_type call above may have already set the type for this DIE. */
16344 type
= get_die_type (die
, cu
);
16348 type
= lookup_reference_type (target_type
, refcode
);
16349 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16350 if (attr
!= nullptr)
16352 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16356 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16358 maybe_set_alignment (cu
, die
, type
);
16359 return set_die_type (die
, type
, cu
);
16362 /* Add the given cv-qualifiers to the element type of the array. GCC
16363 outputs DWARF type qualifiers that apply to an array, not the
16364 element type. But GDB relies on the array element type to carry
16365 the cv-qualifiers. This mimics section 6.7.3 of the C99
16368 static struct type
*
16369 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16370 struct type
*base_type
, int cnst
, int voltl
)
16372 struct type
*el_type
, *inner_array
;
16374 base_type
= copy_type (base_type
);
16375 inner_array
= base_type
;
16377 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16379 TYPE_TARGET_TYPE (inner_array
) =
16380 copy_type (TYPE_TARGET_TYPE (inner_array
));
16381 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16384 el_type
= TYPE_TARGET_TYPE (inner_array
);
16385 cnst
|= TYPE_CONST (el_type
);
16386 voltl
|= TYPE_VOLATILE (el_type
);
16387 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16389 return set_die_type (die
, base_type
, cu
);
16392 static struct type
*
16393 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16395 struct type
*base_type
, *cv_type
;
16397 base_type
= die_type (die
, cu
);
16399 /* The die_type call above may have already set the type for this DIE. */
16400 cv_type
= get_die_type (die
, cu
);
16404 /* In case the const qualifier is applied to an array type, the element type
16405 is so qualified, not the array type (section 6.7.3 of C99). */
16406 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16407 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16409 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16410 return set_die_type (die
, cv_type
, cu
);
16413 static struct type
*
16414 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16416 struct type
*base_type
, *cv_type
;
16418 base_type
= die_type (die
, cu
);
16420 /* The die_type call above may have already set the type for this DIE. */
16421 cv_type
= get_die_type (die
, cu
);
16425 /* In case the volatile qualifier is applied to an array type, the
16426 element type is so qualified, not the array type (section 6.7.3
16428 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16429 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16431 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16432 return set_die_type (die
, cv_type
, cu
);
16435 /* Handle DW_TAG_restrict_type. */
16437 static struct type
*
16438 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16440 struct type
*base_type
, *cv_type
;
16442 base_type
= die_type (die
, cu
);
16444 /* The die_type call above may have already set the type for this DIE. */
16445 cv_type
= get_die_type (die
, cu
);
16449 cv_type
= make_restrict_type (base_type
);
16450 return set_die_type (die
, cv_type
, cu
);
16453 /* Handle DW_TAG_atomic_type. */
16455 static struct type
*
16456 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16458 struct type
*base_type
, *cv_type
;
16460 base_type
= die_type (die
, cu
);
16462 /* The die_type call above may have already set the type for this DIE. */
16463 cv_type
= get_die_type (die
, cu
);
16467 cv_type
= make_atomic_type (base_type
);
16468 return set_die_type (die
, cv_type
, cu
);
16471 /* Extract all information from a DW_TAG_string_type DIE and add to
16472 the user defined type vector. It isn't really a user defined type,
16473 but it behaves like one, with other DIE's using an AT_user_def_type
16474 attribute to reference it. */
16476 static struct type
*
16477 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16479 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16480 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16481 struct type
*type
, *range_type
, *index_type
, *char_type
;
16482 struct attribute
*attr
;
16483 struct dynamic_prop prop
;
16484 bool length_is_constant
= true;
16487 /* There are a couple of places where bit sizes might be made use of
16488 when parsing a DW_TAG_string_type, however, no producer that we know
16489 of make use of these. Handling bit sizes that are a multiple of the
16490 byte size is easy enough, but what about other bit sizes? Lets deal
16491 with that problem when we have to. Warn about these attributes being
16492 unsupported, then parse the type and ignore them like we always
16494 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16495 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16497 static bool warning_printed
= false;
16498 if (!warning_printed
)
16500 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16501 "currently supported on DW_TAG_string_type."));
16502 warning_printed
= true;
16506 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16507 if (attr
!= nullptr && !attr
->form_is_constant ())
16509 /* The string length describes the location at which the length of
16510 the string can be found. The size of the length field can be
16511 specified with one of the attributes below. */
16512 struct type
*prop_type
;
16513 struct attribute
*len
16514 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16515 if (len
== nullptr)
16516 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16517 if (len
!= nullptr && len
->form_is_constant ())
16519 /* Pass 0 as the default as we know this attribute is constant
16520 and the default value will not be returned. */
16521 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16522 prop_type
= cu
->per_cu
->int_type (sz
, true);
16526 /* If the size is not specified then we assume it is the size of
16527 an address on this target. */
16528 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16531 /* Convert the attribute into a dynamic property. */
16532 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16535 length_is_constant
= false;
16537 else if (attr
!= nullptr)
16539 /* This DW_AT_string_length just contains the length with no
16540 indirection. There's no need to create a dynamic property in this
16541 case. Pass 0 for the default value as we know it will not be
16542 returned in this case. */
16543 length
= dwarf2_get_attr_constant_value (attr
, 0);
16545 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16547 /* We don't currently support non-constant byte sizes for strings. */
16548 length
= dwarf2_get_attr_constant_value (attr
, 1);
16552 /* Use 1 as a fallback length if we have nothing else. */
16556 index_type
= objfile_type (objfile
)->builtin_int
;
16557 if (length_is_constant
)
16558 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16561 struct dynamic_prop low_bound
;
16563 low_bound
.kind
= PROP_CONST
;
16564 low_bound
.data
.const_val
= 1;
16565 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16567 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16568 type
= create_string_type (NULL
, char_type
, range_type
);
16570 return set_die_type (die
, type
, cu
);
16573 /* Assuming that DIE corresponds to a function, returns nonzero
16574 if the function is prototyped. */
16577 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16579 struct attribute
*attr
;
16581 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16582 if (attr
&& (DW_UNSND (attr
) != 0))
16585 /* The DWARF standard implies that the DW_AT_prototyped attribute
16586 is only meaningful for C, but the concept also extends to other
16587 languages that allow unprototyped functions (Eg: Objective C).
16588 For all other languages, assume that functions are always
16590 if (cu
->language
!= language_c
16591 && cu
->language
!= language_objc
16592 && cu
->language
!= language_opencl
)
16595 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16596 prototyped and unprototyped functions; default to prototyped,
16597 since that is more common in modern code (and RealView warns
16598 about unprototyped functions). */
16599 if (producer_is_realview (cu
->producer
))
16605 /* Handle DIES due to C code like:
16609 int (*funcp)(int a, long l);
16613 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16615 static struct type
*
16616 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16618 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16619 struct type
*type
; /* Type that this function returns. */
16620 struct type
*ftype
; /* Function that returns above type. */
16621 struct attribute
*attr
;
16623 type
= die_type (die
, cu
);
16625 /* The die_type call above may have already set the type for this DIE. */
16626 ftype
= get_die_type (die
, cu
);
16630 ftype
= lookup_function_type (type
);
16632 if (prototyped_function_p (die
, cu
))
16633 TYPE_PROTOTYPED (ftype
) = 1;
16635 /* Store the calling convention in the type if it's available in
16636 the subroutine die. Otherwise set the calling convention to
16637 the default value DW_CC_normal. */
16638 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16639 if (attr
!= nullptr
16640 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16641 TYPE_CALLING_CONVENTION (ftype
)
16642 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16643 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16644 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16646 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16648 /* Record whether the function returns normally to its caller or not
16649 if the DWARF producer set that information. */
16650 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16651 if (attr
&& (DW_UNSND (attr
) != 0))
16652 TYPE_NO_RETURN (ftype
) = 1;
16654 /* We need to add the subroutine type to the die immediately so
16655 we don't infinitely recurse when dealing with parameters
16656 declared as the same subroutine type. */
16657 set_die_type (die
, ftype
, cu
);
16659 if (die
->child
!= NULL
)
16661 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16662 struct die_info
*child_die
;
16663 int nparams
, iparams
;
16665 /* Count the number of parameters.
16666 FIXME: GDB currently ignores vararg functions, but knows about
16667 vararg member functions. */
16669 child_die
= die
->child
;
16670 while (child_die
&& child_die
->tag
)
16672 if (child_die
->tag
== DW_TAG_formal_parameter
)
16674 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16675 TYPE_VARARGS (ftype
) = 1;
16676 child_die
= sibling_die (child_die
);
16679 /* Allocate storage for parameters and fill them in. */
16680 TYPE_NFIELDS (ftype
) = nparams
;
16681 TYPE_FIELDS (ftype
) = (struct field
*)
16682 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16684 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16685 even if we error out during the parameters reading below. */
16686 for (iparams
= 0; iparams
< nparams
; iparams
++)
16687 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16690 child_die
= die
->child
;
16691 while (child_die
&& child_die
->tag
)
16693 if (child_die
->tag
== DW_TAG_formal_parameter
)
16695 struct type
*arg_type
;
16697 /* DWARF version 2 has no clean way to discern C++
16698 static and non-static member functions. G++ helps
16699 GDB by marking the first parameter for non-static
16700 member functions (which is the this pointer) as
16701 artificial. We pass this information to
16702 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16704 DWARF version 3 added DW_AT_object_pointer, which GCC
16705 4.5 does not yet generate. */
16706 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16707 if (attr
!= nullptr)
16708 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16710 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16711 arg_type
= die_type (child_die
, cu
);
16713 /* RealView does not mark THIS as const, which the testsuite
16714 expects. GCC marks THIS as const in method definitions,
16715 but not in the class specifications (GCC PR 43053). */
16716 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16717 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16720 struct dwarf2_cu
*arg_cu
= cu
;
16721 const char *name
= dwarf2_name (child_die
, cu
);
16723 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16724 if (attr
!= nullptr)
16726 /* If the compiler emits this, use it. */
16727 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16730 else if (name
&& strcmp (name
, "this") == 0)
16731 /* Function definitions will have the argument names. */
16733 else if (name
== NULL
&& iparams
== 0)
16734 /* Declarations may not have the names, so like
16735 elsewhere in GDB, assume an artificial first
16736 argument is "this". */
16740 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16744 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16747 child_die
= sibling_die (child_die
);
16754 static struct type
*
16755 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16757 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16758 const char *name
= NULL
;
16759 struct type
*this_type
, *target_type
;
16761 name
= dwarf2_full_name (NULL
, die
, cu
);
16762 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16763 TYPE_TARGET_STUB (this_type
) = 1;
16764 set_die_type (die
, this_type
, cu
);
16765 target_type
= die_type (die
, cu
);
16766 if (target_type
!= this_type
)
16767 TYPE_TARGET_TYPE (this_type
) = target_type
;
16770 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16771 spec and cause infinite loops in GDB. */
16772 complaint (_("Self-referential DW_TAG_typedef "
16773 "- DIE at %s [in module %s]"),
16774 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16775 TYPE_TARGET_TYPE (this_type
) = NULL
;
16780 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16781 (which may be different from NAME) to the architecture back-end to allow
16782 it to guess the correct format if necessary. */
16784 static struct type
*
16785 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16786 const char *name_hint
, enum bfd_endian byte_order
)
16788 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16789 const struct floatformat
**format
;
16792 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16794 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16796 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16801 /* Allocate an integer type of size BITS and name NAME. */
16803 static struct type
*
16804 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16805 int bits
, int unsigned_p
, const char *name
)
16809 /* Versions of Intel's C Compiler generate an integer type called "void"
16810 instead of using DW_TAG_unspecified_type. This has been seen on
16811 at least versions 14, 17, and 18. */
16812 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16813 && strcmp (name
, "void") == 0)
16814 type
= objfile_type (objfile
)->builtin_void
;
16816 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16821 /* Initialise and return a floating point type of size BITS suitable for
16822 use as a component of a complex number. The NAME_HINT is passed through
16823 when initialising the floating point type and is the name of the complex
16826 As DWARF doesn't currently provide an explicit name for the components
16827 of a complex number, but it can be helpful to have these components
16828 named, we try to select a suitable name based on the size of the
16830 static struct type
*
16831 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16832 struct objfile
*objfile
,
16833 int bits
, const char *name_hint
,
16834 enum bfd_endian byte_order
)
16836 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16837 struct type
*tt
= nullptr;
16839 /* Try to find a suitable floating point builtin type of size BITS.
16840 We're going to use the name of this type as the name for the complex
16841 target type that we are about to create. */
16842 switch (cu
->language
)
16844 case language_fortran
:
16848 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16851 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16853 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16855 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16863 tt
= builtin_type (gdbarch
)->builtin_float
;
16866 tt
= builtin_type (gdbarch
)->builtin_double
;
16868 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16870 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16876 /* If the type we found doesn't match the size we were looking for, then
16877 pretend we didn't find a type at all, the complex target type we
16878 create will then be nameless. */
16879 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16882 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16883 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16886 /* Find a representation of a given base type and install
16887 it in the TYPE field of the die. */
16889 static struct type
*
16890 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16892 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16894 struct attribute
*attr
;
16895 int encoding
= 0, bits
= 0;
16899 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16900 if (attr
!= nullptr)
16901 encoding
= DW_UNSND (attr
);
16902 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16903 if (attr
!= nullptr)
16904 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16905 name
= dwarf2_name (die
, cu
);
16907 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16909 arch
= get_objfile_arch (objfile
);
16910 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16912 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16915 int endianity
= DW_UNSND (attr
);
16920 byte_order
= BFD_ENDIAN_BIG
;
16922 case DW_END_little
:
16923 byte_order
= BFD_ENDIAN_LITTLE
;
16926 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16933 case DW_ATE_address
:
16934 /* Turn DW_ATE_address into a void * pointer. */
16935 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16936 type
= init_pointer_type (objfile
, bits
, name
, type
);
16938 case DW_ATE_boolean
:
16939 type
= init_boolean_type (objfile
, bits
, 1, name
);
16941 case DW_ATE_complex_float
:
16942 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16944 type
= init_complex_type (objfile
, name
, type
);
16946 case DW_ATE_decimal_float
:
16947 type
= init_decfloat_type (objfile
, bits
, name
);
16950 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16952 case DW_ATE_signed
:
16953 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16955 case DW_ATE_unsigned
:
16956 if (cu
->language
== language_fortran
16958 && startswith (name
, "character("))
16959 type
= init_character_type (objfile
, bits
, 1, name
);
16961 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16963 case DW_ATE_signed_char
:
16964 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16965 || cu
->language
== language_pascal
16966 || cu
->language
== language_fortran
)
16967 type
= init_character_type (objfile
, bits
, 0, name
);
16969 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16971 case DW_ATE_unsigned_char
:
16972 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16973 || cu
->language
== language_pascal
16974 || cu
->language
== language_fortran
16975 || cu
->language
== language_rust
)
16976 type
= init_character_type (objfile
, bits
, 1, name
);
16978 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16983 type
= builtin_type (arch
)->builtin_char16
;
16984 else if (bits
== 32)
16985 type
= builtin_type (arch
)->builtin_char32
;
16988 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
16990 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16992 return set_die_type (die
, type
, cu
);
16997 complaint (_("unsupported DW_AT_encoding: '%s'"),
16998 dwarf_type_encoding_name (encoding
));
16999 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17003 if (name
&& strcmp (name
, "char") == 0)
17004 TYPE_NOSIGN (type
) = 1;
17006 maybe_set_alignment (cu
, die
, type
);
17008 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17010 return set_die_type (die
, type
, cu
);
17013 /* Parse dwarf attribute if it's a block, reference or constant and put the
17014 resulting value of the attribute into struct bound_prop.
17015 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17018 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17019 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17020 struct type
*default_type
)
17022 struct dwarf2_property_baton
*baton
;
17023 struct obstack
*obstack
17024 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17026 gdb_assert (default_type
!= NULL
);
17028 if (attr
== NULL
|| prop
== NULL
)
17031 if (attr
->form_is_block ())
17033 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17034 baton
->property_type
= default_type
;
17035 baton
->locexpr
.per_cu
= cu
->per_cu
;
17036 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17037 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17038 switch (attr
->name
)
17040 case DW_AT_string_length
:
17041 baton
->locexpr
.is_reference
= true;
17044 baton
->locexpr
.is_reference
= false;
17047 prop
->data
.baton
= baton
;
17048 prop
->kind
= PROP_LOCEXPR
;
17049 gdb_assert (prop
->data
.baton
!= NULL
);
17051 else if (attr
->form_is_ref ())
17053 struct dwarf2_cu
*target_cu
= cu
;
17054 struct die_info
*target_die
;
17055 struct attribute
*target_attr
;
17057 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17058 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17059 if (target_attr
== NULL
)
17060 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17062 if (target_attr
== NULL
)
17065 switch (target_attr
->name
)
17067 case DW_AT_location
:
17068 if (target_attr
->form_is_section_offset ())
17070 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17071 baton
->property_type
= die_type (target_die
, target_cu
);
17072 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17073 prop
->data
.baton
= baton
;
17074 prop
->kind
= PROP_LOCLIST
;
17075 gdb_assert (prop
->data
.baton
!= NULL
);
17077 else if (target_attr
->form_is_block ())
17079 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17080 baton
->property_type
= die_type (target_die
, target_cu
);
17081 baton
->locexpr
.per_cu
= cu
->per_cu
;
17082 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17083 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17084 baton
->locexpr
.is_reference
= true;
17085 prop
->data
.baton
= baton
;
17086 prop
->kind
= PROP_LOCEXPR
;
17087 gdb_assert (prop
->data
.baton
!= NULL
);
17091 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17092 "dynamic property");
17096 case DW_AT_data_member_location
:
17100 if (!handle_data_member_location (target_die
, target_cu
,
17104 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17105 baton
->property_type
= read_type_die (target_die
->parent
,
17107 baton
->offset_info
.offset
= offset
;
17108 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17109 prop
->data
.baton
= baton
;
17110 prop
->kind
= PROP_ADDR_OFFSET
;
17115 else if (attr
->form_is_constant ())
17117 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17118 prop
->kind
= PROP_CONST
;
17122 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17123 dwarf2_name (die
, cu
));
17133 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17135 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17136 struct type
*int_type
;
17138 /* Helper macro to examine the various builtin types. */
17139 #define TRY_TYPE(F) \
17140 int_type = (unsigned_p \
17141 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17142 : objfile_type (objfile)->builtin_ ## F); \
17143 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17150 TRY_TYPE (long_long
);
17154 gdb_assert_not_reached ("unable to find suitable integer type");
17160 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17162 int addr_size
= this->addr_size ();
17163 return int_type (addr_size
, unsigned_p
);
17166 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17167 present (which is valid) then compute the default type based on the
17168 compilation units address size. */
17170 static struct type
*
17171 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17173 struct type
*index_type
= die_type (die
, cu
);
17175 /* Dwarf-2 specifications explicitly allows to create subrange types
17176 without specifying a base type.
17177 In that case, the base type must be set to the type of
17178 the lower bound, upper bound or count, in that order, if any of these
17179 three attributes references an object that has a type.
17180 If no base type is found, the Dwarf-2 specifications say that
17181 a signed integer type of size equal to the size of an address should
17183 For the following C code: `extern char gdb_int [];'
17184 GCC produces an empty range DIE.
17185 FIXME: muller/2010-05-28: Possible references to object for low bound,
17186 high bound or count are not yet handled by this code. */
17187 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17188 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17193 /* Read the given DW_AT_subrange DIE. */
17195 static struct type
*
17196 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17198 struct type
*base_type
, *orig_base_type
;
17199 struct type
*range_type
;
17200 struct attribute
*attr
;
17201 struct dynamic_prop low
, high
;
17202 int low_default_is_valid
;
17203 int high_bound_is_count
= 0;
17205 ULONGEST negative_mask
;
17207 orig_base_type
= read_subrange_index_type (die
, cu
);
17209 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17210 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17211 creating the range type, but we use the result of check_typedef
17212 when examining properties of the type. */
17213 base_type
= check_typedef (orig_base_type
);
17215 /* The die_type call above may have already set the type for this DIE. */
17216 range_type
= get_die_type (die
, cu
);
17220 low
.kind
= PROP_CONST
;
17221 high
.kind
= PROP_CONST
;
17222 high
.data
.const_val
= 0;
17224 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17225 omitting DW_AT_lower_bound. */
17226 switch (cu
->language
)
17229 case language_cplus
:
17230 low
.data
.const_val
= 0;
17231 low_default_is_valid
= 1;
17233 case language_fortran
:
17234 low
.data
.const_val
= 1;
17235 low_default_is_valid
= 1;
17238 case language_objc
:
17239 case language_rust
:
17240 low
.data
.const_val
= 0;
17241 low_default_is_valid
= (cu
->header
.version
>= 4);
17245 case language_pascal
:
17246 low
.data
.const_val
= 1;
17247 low_default_is_valid
= (cu
->header
.version
>= 4);
17250 low
.data
.const_val
= 0;
17251 low_default_is_valid
= 0;
17255 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17256 if (attr
!= nullptr)
17257 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17258 else if (!low_default_is_valid
)
17259 complaint (_("Missing DW_AT_lower_bound "
17260 "- DIE at %s [in module %s]"),
17261 sect_offset_str (die
->sect_off
),
17262 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17264 struct attribute
*attr_ub
, *attr_count
;
17265 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17266 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17268 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17269 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17271 /* If bounds are constant do the final calculation here. */
17272 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17273 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17275 high_bound_is_count
= 1;
17279 if (attr_ub
!= NULL
)
17280 complaint (_("Unresolved DW_AT_upper_bound "
17281 "- DIE at %s [in module %s]"),
17282 sect_offset_str (die
->sect_off
),
17283 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17284 if (attr_count
!= NULL
)
17285 complaint (_("Unresolved DW_AT_count "
17286 "- DIE at %s [in module %s]"),
17287 sect_offset_str (die
->sect_off
),
17288 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17293 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17294 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17295 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17297 /* Normally, the DWARF producers are expected to use a signed
17298 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17299 But this is unfortunately not always the case, as witnessed
17300 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17301 is used instead. To work around that ambiguity, we treat
17302 the bounds as signed, and thus sign-extend their values, when
17303 the base type is signed. */
17305 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17306 if (low
.kind
== PROP_CONST
17307 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17308 low
.data
.const_val
|= negative_mask
;
17309 if (high
.kind
== PROP_CONST
17310 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17311 high
.data
.const_val
|= negative_mask
;
17313 /* Check for bit and byte strides. */
17314 struct dynamic_prop byte_stride_prop
;
17315 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17316 if (attr_byte_stride
!= nullptr)
17318 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17319 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17323 struct dynamic_prop bit_stride_prop
;
17324 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17325 if (attr_bit_stride
!= nullptr)
17327 /* It only makes sense to have either a bit or byte stride. */
17328 if (attr_byte_stride
!= nullptr)
17330 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17331 "- DIE at %s [in module %s]"),
17332 sect_offset_str (die
->sect_off
),
17333 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17334 attr_bit_stride
= nullptr;
17338 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17339 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17344 if (attr_byte_stride
!= nullptr
17345 || attr_bit_stride
!= nullptr)
17347 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17348 struct dynamic_prop
*stride
17349 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17352 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17353 &high
, bias
, stride
, byte_stride_p
);
17356 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17358 if (high_bound_is_count
)
17359 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17361 /* Ada expects an empty array on no boundary attributes. */
17362 if (attr
== NULL
&& cu
->language
!= language_ada
)
17363 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17365 name
= dwarf2_name (die
, cu
);
17367 TYPE_NAME (range_type
) = name
;
17369 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17370 if (attr
!= nullptr)
17371 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17373 maybe_set_alignment (cu
, die
, range_type
);
17375 set_die_type (die
, range_type
, cu
);
17377 /* set_die_type should be already done. */
17378 set_descriptive_type (range_type
, die
, cu
);
17383 static struct type
*
17384 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17388 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17390 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17392 /* In Ada, an unspecified type is typically used when the description
17393 of the type is deferred to a different unit. When encountering
17394 such a type, we treat it as a stub, and try to resolve it later on,
17396 if (cu
->language
== language_ada
)
17397 TYPE_STUB (type
) = 1;
17399 return set_die_type (die
, type
, cu
);
17402 /* Read a single die and all its descendents. Set the die's sibling
17403 field to NULL; set other fields in the die correctly, and set all
17404 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17405 location of the info_ptr after reading all of those dies. PARENT
17406 is the parent of the die in question. */
17408 static struct die_info
*
17409 read_die_and_children (const struct die_reader_specs
*reader
,
17410 const gdb_byte
*info_ptr
,
17411 const gdb_byte
**new_info_ptr
,
17412 struct die_info
*parent
)
17414 struct die_info
*die
;
17415 const gdb_byte
*cur_ptr
;
17417 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17420 *new_info_ptr
= cur_ptr
;
17423 store_in_ref_table (die
, reader
->cu
);
17425 if (die
->has_children
)
17426 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17430 *new_info_ptr
= cur_ptr
;
17433 die
->sibling
= NULL
;
17434 die
->parent
= parent
;
17438 /* Read a die, all of its descendents, and all of its siblings; set
17439 all of the fields of all of the dies correctly. Arguments are as
17440 in read_die_and_children. */
17442 static struct die_info
*
17443 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17444 const gdb_byte
*info_ptr
,
17445 const gdb_byte
**new_info_ptr
,
17446 struct die_info
*parent
)
17448 struct die_info
*first_die
, *last_sibling
;
17449 const gdb_byte
*cur_ptr
;
17451 cur_ptr
= info_ptr
;
17452 first_die
= last_sibling
= NULL
;
17456 struct die_info
*die
17457 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17461 *new_info_ptr
= cur_ptr
;
17468 last_sibling
->sibling
= die
;
17470 last_sibling
= die
;
17474 /* Read a die, all of its descendents, and all of its siblings; set
17475 all of the fields of all of the dies correctly. Arguments are as
17476 in read_die_and_children.
17477 This the main entry point for reading a DIE and all its children. */
17479 static struct die_info
*
17480 read_die_and_siblings (const struct die_reader_specs
*reader
,
17481 const gdb_byte
*info_ptr
,
17482 const gdb_byte
**new_info_ptr
,
17483 struct die_info
*parent
)
17485 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17486 new_info_ptr
, parent
);
17488 if (dwarf_die_debug
)
17490 fprintf_unfiltered (gdb_stdlog
,
17491 "Read die from %s@0x%x of %s:\n",
17492 reader
->die_section
->get_name (),
17493 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17494 bfd_get_filename (reader
->abfd
));
17495 dump_die (die
, dwarf_die_debug
);
17501 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17503 The caller is responsible for filling in the extra attributes
17504 and updating (*DIEP)->num_attrs.
17505 Set DIEP to point to a newly allocated die with its information,
17506 except for its child, sibling, and parent fields. */
17508 static const gdb_byte
*
17509 read_full_die_1 (const struct die_reader_specs
*reader
,
17510 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17511 int num_extra_attrs
)
17513 unsigned int abbrev_number
, bytes_read
, i
;
17514 struct abbrev_info
*abbrev
;
17515 struct die_info
*die
;
17516 struct dwarf2_cu
*cu
= reader
->cu
;
17517 bfd
*abfd
= reader
->abfd
;
17519 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17520 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17521 info_ptr
+= bytes_read
;
17522 if (!abbrev_number
)
17528 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17530 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17532 bfd_get_filename (abfd
));
17534 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17535 die
->sect_off
= sect_off
;
17536 die
->tag
= abbrev
->tag
;
17537 die
->abbrev
= abbrev_number
;
17538 die
->has_children
= abbrev
->has_children
;
17540 /* Make the result usable.
17541 The caller needs to update num_attrs after adding the extra
17543 die
->num_attrs
= abbrev
->num_attrs
;
17545 std::vector
<int> indexes_that_need_reprocess
;
17546 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17548 bool need_reprocess
;
17550 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17551 info_ptr
, &need_reprocess
);
17552 if (need_reprocess
)
17553 indexes_that_need_reprocess
.push_back (i
);
17556 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17557 if (attr
!= nullptr)
17558 cu
->str_offsets_base
= DW_UNSND (attr
);
17560 auto maybe_addr_base
= lookup_addr_base(die
);
17561 if (maybe_addr_base
.has_value ())
17562 cu
->addr_base
= *maybe_addr_base
;
17563 for (int index
: indexes_that_need_reprocess
)
17564 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17569 /* Read a die and all its attributes.
17570 Set DIEP to point to a newly allocated die with its information,
17571 except for its child, sibling, and parent fields. */
17573 static const gdb_byte
*
17574 read_full_die (const struct die_reader_specs
*reader
,
17575 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17577 const gdb_byte
*result
;
17579 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17581 if (dwarf_die_debug
)
17583 fprintf_unfiltered (gdb_stdlog
,
17584 "Read die from %s@0x%x of %s:\n",
17585 reader
->die_section
->get_name (),
17586 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17587 bfd_get_filename (reader
->abfd
));
17588 dump_die (*diep
, dwarf_die_debug
);
17595 /* Returns nonzero if TAG represents a type that we might generate a partial
17599 is_type_tag_for_partial (int tag
)
17604 /* Some types that would be reasonable to generate partial symbols for,
17605 that we don't at present. */
17606 case DW_TAG_array_type
:
17607 case DW_TAG_file_type
:
17608 case DW_TAG_ptr_to_member_type
:
17609 case DW_TAG_set_type
:
17610 case DW_TAG_string_type
:
17611 case DW_TAG_subroutine_type
:
17613 case DW_TAG_base_type
:
17614 case DW_TAG_class_type
:
17615 case DW_TAG_interface_type
:
17616 case DW_TAG_enumeration_type
:
17617 case DW_TAG_structure_type
:
17618 case DW_TAG_subrange_type
:
17619 case DW_TAG_typedef
:
17620 case DW_TAG_union_type
:
17627 /* Load all DIEs that are interesting for partial symbols into memory. */
17629 static struct partial_die_info
*
17630 load_partial_dies (const struct die_reader_specs
*reader
,
17631 const gdb_byte
*info_ptr
, int building_psymtab
)
17633 struct dwarf2_cu
*cu
= reader
->cu
;
17634 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17635 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17636 unsigned int bytes_read
;
17637 unsigned int load_all
= 0;
17638 int nesting_level
= 1;
17643 gdb_assert (cu
->per_cu
!= NULL
);
17644 if (cu
->per_cu
->load_all_dies
)
17648 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17652 &cu
->comp_unit_obstack
,
17653 hashtab_obstack_allocate
,
17654 dummy_obstack_deallocate
);
17658 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17660 /* A NULL abbrev means the end of a series of children. */
17661 if (abbrev
== NULL
)
17663 if (--nesting_level
== 0)
17666 info_ptr
+= bytes_read
;
17667 last_die
= parent_die
;
17668 parent_die
= parent_die
->die_parent
;
17672 /* Check for template arguments. We never save these; if
17673 they're seen, we just mark the parent, and go on our way. */
17674 if (parent_die
!= NULL
17675 && cu
->language
== language_cplus
17676 && (abbrev
->tag
== DW_TAG_template_type_param
17677 || abbrev
->tag
== DW_TAG_template_value_param
))
17679 parent_die
->has_template_arguments
= 1;
17683 /* We don't need a partial DIE for the template argument. */
17684 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17689 /* We only recurse into c++ subprograms looking for template arguments.
17690 Skip their other children. */
17692 && cu
->language
== language_cplus
17693 && parent_die
!= NULL
17694 && parent_die
->tag
== DW_TAG_subprogram
)
17696 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17700 /* Check whether this DIE is interesting enough to save. Normally
17701 we would not be interested in members here, but there may be
17702 later variables referencing them via DW_AT_specification (for
17703 static members). */
17705 && !is_type_tag_for_partial (abbrev
->tag
)
17706 && abbrev
->tag
!= DW_TAG_constant
17707 && abbrev
->tag
!= DW_TAG_enumerator
17708 && abbrev
->tag
!= DW_TAG_subprogram
17709 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17710 && abbrev
->tag
!= DW_TAG_lexical_block
17711 && abbrev
->tag
!= DW_TAG_variable
17712 && abbrev
->tag
!= DW_TAG_namespace
17713 && abbrev
->tag
!= DW_TAG_module
17714 && abbrev
->tag
!= DW_TAG_member
17715 && abbrev
->tag
!= DW_TAG_imported_unit
17716 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17718 /* Otherwise we skip to the next sibling, if any. */
17719 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17723 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17726 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17728 /* This two-pass algorithm for processing partial symbols has a
17729 high cost in cache pressure. Thus, handle some simple cases
17730 here which cover the majority of C partial symbols. DIEs
17731 which neither have specification tags in them, nor could have
17732 specification tags elsewhere pointing at them, can simply be
17733 processed and discarded.
17735 This segment is also optional; scan_partial_symbols and
17736 add_partial_symbol will handle these DIEs if we chain
17737 them in normally. When compilers which do not emit large
17738 quantities of duplicate debug information are more common,
17739 this code can probably be removed. */
17741 /* Any complete simple types at the top level (pretty much all
17742 of them, for a language without namespaces), can be processed
17744 if (parent_die
== NULL
17745 && pdi
.has_specification
== 0
17746 && pdi
.is_declaration
== 0
17747 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17748 || pdi
.tag
== DW_TAG_base_type
17749 || pdi
.tag
== DW_TAG_subrange_type
))
17751 if (building_psymtab
&& pdi
.name
!= NULL
)
17752 add_psymbol_to_list (pdi
.name
, false,
17753 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17754 psymbol_placement::STATIC
,
17755 0, cu
->language
, objfile
);
17756 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17760 /* The exception for DW_TAG_typedef with has_children above is
17761 a workaround of GCC PR debug/47510. In the case of this complaint
17762 type_name_or_error will error on such types later.
17764 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17765 it could not find the child DIEs referenced later, this is checked
17766 above. In correct DWARF DW_TAG_typedef should have no children. */
17768 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17769 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17770 "- DIE at %s [in module %s]"),
17771 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17773 /* If we're at the second level, and we're an enumerator, and
17774 our parent has no specification (meaning possibly lives in a
17775 namespace elsewhere), then we can add the partial symbol now
17776 instead of queueing it. */
17777 if (pdi
.tag
== DW_TAG_enumerator
17778 && parent_die
!= NULL
17779 && parent_die
->die_parent
== NULL
17780 && parent_die
->tag
== DW_TAG_enumeration_type
17781 && parent_die
->has_specification
== 0)
17783 if (pdi
.name
== NULL
)
17784 complaint (_("malformed enumerator DIE ignored"));
17785 else if (building_psymtab
)
17786 add_psymbol_to_list (pdi
.name
, false,
17787 VAR_DOMAIN
, LOC_CONST
, -1,
17788 cu
->language
== language_cplus
17789 ? psymbol_placement::GLOBAL
17790 : psymbol_placement::STATIC
,
17791 0, cu
->language
, objfile
);
17793 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17797 struct partial_die_info
*part_die
17798 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17800 /* We'll save this DIE so link it in. */
17801 part_die
->die_parent
= parent_die
;
17802 part_die
->die_sibling
= NULL
;
17803 part_die
->die_child
= NULL
;
17805 if (last_die
&& last_die
== parent_die
)
17806 last_die
->die_child
= part_die
;
17808 last_die
->die_sibling
= part_die
;
17810 last_die
= part_die
;
17812 if (first_die
== NULL
)
17813 first_die
= part_die
;
17815 /* Maybe add the DIE to the hash table. Not all DIEs that we
17816 find interesting need to be in the hash table, because we
17817 also have the parent/sibling/child chains; only those that we
17818 might refer to by offset later during partial symbol reading.
17820 For now this means things that might have be the target of a
17821 DW_AT_specification, DW_AT_abstract_origin, or
17822 DW_AT_extension. DW_AT_extension will refer only to
17823 namespaces; DW_AT_abstract_origin refers to functions (and
17824 many things under the function DIE, but we do not recurse
17825 into function DIEs during partial symbol reading) and
17826 possibly variables as well; DW_AT_specification refers to
17827 declarations. Declarations ought to have the DW_AT_declaration
17828 flag. It happens that GCC forgets to put it in sometimes, but
17829 only for functions, not for types.
17831 Adding more things than necessary to the hash table is harmless
17832 except for the performance cost. Adding too few will result in
17833 wasted time in find_partial_die, when we reread the compilation
17834 unit with load_all_dies set. */
17837 || abbrev
->tag
== DW_TAG_constant
17838 || abbrev
->tag
== DW_TAG_subprogram
17839 || abbrev
->tag
== DW_TAG_variable
17840 || abbrev
->tag
== DW_TAG_namespace
17841 || part_die
->is_declaration
)
17845 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17846 to_underlying (part_die
->sect_off
),
17851 /* For some DIEs we want to follow their children (if any). For C
17852 we have no reason to follow the children of structures; for other
17853 languages we have to, so that we can get at method physnames
17854 to infer fully qualified class names, for DW_AT_specification,
17855 and for C++ template arguments. For C++, we also look one level
17856 inside functions to find template arguments (if the name of the
17857 function does not already contain the template arguments).
17859 For Ada and Fortran, we need to scan the children of subprograms
17860 and lexical blocks as well because these languages allow the
17861 definition of nested entities that could be interesting for the
17862 debugger, such as nested subprograms for instance. */
17863 if (last_die
->has_children
17865 || last_die
->tag
== DW_TAG_namespace
17866 || last_die
->tag
== DW_TAG_module
17867 || last_die
->tag
== DW_TAG_enumeration_type
17868 || (cu
->language
== language_cplus
17869 && last_die
->tag
== DW_TAG_subprogram
17870 && (last_die
->name
== NULL
17871 || strchr (last_die
->name
, '<') == NULL
))
17872 || (cu
->language
!= language_c
17873 && (last_die
->tag
== DW_TAG_class_type
17874 || last_die
->tag
== DW_TAG_interface_type
17875 || last_die
->tag
== DW_TAG_structure_type
17876 || last_die
->tag
== DW_TAG_union_type
))
17877 || ((cu
->language
== language_ada
17878 || cu
->language
== language_fortran
)
17879 && (last_die
->tag
== DW_TAG_subprogram
17880 || last_die
->tag
== DW_TAG_lexical_block
))))
17883 parent_die
= last_die
;
17887 /* Otherwise we skip to the next sibling, if any. */
17888 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17890 /* Back to the top, do it again. */
17894 partial_die_info::partial_die_info (sect_offset sect_off_
,
17895 struct abbrev_info
*abbrev
)
17896 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17900 /* Read a minimal amount of information into the minimal die structure.
17901 INFO_PTR should point just after the initial uleb128 of a DIE. */
17904 partial_die_info::read (const struct die_reader_specs
*reader
,
17905 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17907 struct dwarf2_cu
*cu
= reader
->cu
;
17908 struct dwarf2_per_objfile
*dwarf2_per_objfile
17909 = cu
->per_cu
->dwarf2_per_objfile
;
17911 int has_low_pc_attr
= 0;
17912 int has_high_pc_attr
= 0;
17913 int high_pc_relative
= 0;
17915 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17916 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17918 bool need_reprocess
;
17919 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17920 info_ptr
, &need_reprocess
);
17921 /* String and address offsets that need to do the reprocessing have
17922 already been read at this point, so there is no need to wait until
17923 the loop terminates to do the reprocessing. */
17924 if (need_reprocess
)
17925 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17926 attribute
&attr
= attr_vec
[i
];
17927 /* Store the data if it is of an attribute we want to keep in a
17928 partial symbol table. */
17934 case DW_TAG_compile_unit
:
17935 case DW_TAG_partial_unit
:
17936 case DW_TAG_type_unit
:
17937 /* Compilation units have a DW_AT_name that is a filename, not
17938 a source language identifier. */
17939 case DW_TAG_enumeration_type
:
17940 case DW_TAG_enumerator
:
17941 /* These tags always have simple identifiers already; no need
17942 to canonicalize them. */
17943 name
= DW_STRING (&attr
);
17947 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17950 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
17951 &objfile
->per_bfd
->storage_obstack
);
17956 case DW_AT_linkage_name
:
17957 case DW_AT_MIPS_linkage_name
:
17958 /* Note that both forms of linkage name might appear. We
17959 assume they will be the same, and we only store the last
17961 linkage_name
= DW_STRING (&attr
);
17964 has_low_pc_attr
= 1;
17965 lowpc
= attr
.value_as_address ();
17967 case DW_AT_high_pc
:
17968 has_high_pc_attr
= 1;
17969 highpc
= attr
.value_as_address ();
17970 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17971 high_pc_relative
= 1;
17973 case DW_AT_location
:
17974 /* Support the .debug_loc offsets. */
17975 if (attr
.form_is_block ())
17977 d
.locdesc
= DW_BLOCK (&attr
);
17979 else if (attr
.form_is_section_offset ())
17981 dwarf2_complex_location_expr_complaint ();
17985 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17986 "partial symbol information");
17989 case DW_AT_external
:
17990 is_external
= DW_UNSND (&attr
);
17992 case DW_AT_declaration
:
17993 is_declaration
= DW_UNSND (&attr
);
17998 case DW_AT_abstract_origin
:
17999 case DW_AT_specification
:
18000 case DW_AT_extension
:
18001 has_specification
= 1;
18002 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18003 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18004 || cu
->per_cu
->is_dwz
);
18006 case DW_AT_sibling
:
18007 /* Ignore absolute siblings, they might point outside of
18008 the current compile unit. */
18009 if (attr
.form
== DW_FORM_ref_addr
)
18010 complaint (_("ignoring absolute DW_AT_sibling"));
18013 const gdb_byte
*buffer
= reader
->buffer
;
18014 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18015 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18017 if (sibling_ptr
< info_ptr
)
18018 complaint (_("DW_AT_sibling points backwards"));
18019 else if (sibling_ptr
> reader
->buffer_end
)
18020 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18022 sibling
= sibling_ptr
;
18025 case DW_AT_byte_size
:
18028 case DW_AT_const_value
:
18029 has_const_value
= 1;
18031 case DW_AT_calling_convention
:
18032 /* DWARF doesn't provide a way to identify a program's source-level
18033 entry point. DW_AT_calling_convention attributes are only meant
18034 to describe functions' calling conventions.
18036 However, because it's a necessary piece of information in
18037 Fortran, and before DWARF 4 DW_CC_program was the only
18038 piece of debugging information whose definition refers to
18039 a 'main program' at all, several compilers marked Fortran
18040 main programs with DW_CC_program --- even when those
18041 functions use the standard calling conventions.
18043 Although DWARF now specifies a way to provide this
18044 information, we support this practice for backward
18046 if (DW_UNSND (&attr
) == DW_CC_program
18047 && cu
->language
== language_fortran
)
18048 main_subprogram
= 1;
18051 if (DW_UNSND (&attr
) == DW_INL_inlined
18052 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18053 may_be_inlined
= 1;
18057 if (tag
== DW_TAG_imported_unit
)
18059 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18060 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18061 || cu
->per_cu
->is_dwz
);
18065 case DW_AT_main_subprogram
:
18066 main_subprogram
= DW_UNSND (&attr
);
18071 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18072 but that requires a full DIE, so instead we just
18074 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18075 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18076 + (need_ranges_base
18080 /* Value of the DW_AT_ranges attribute is the offset in the
18081 .debug_ranges section. */
18082 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18093 /* For Ada, if both the name and the linkage name appear, we prefer
18094 the latter. This lets "catch exception" work better, regardless
18095 of the order in which the name and linkage name were emitted.
18096 Really, though, this is just a workaround for the fact that gdb
18097 doesn't store both the name and the linkage name. */
18098 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18099 name
= linkage_name
;
18101 if (high_pc_relative
)
18104 if (has_low_pc_attr
&& has_high_pc_attr
)
18106 /* When using the GNU linker, .gnu.linkonce. sections are used to
18107 eliminate duplicate copies of functions and vtables and such.
18108 The linker will arbitrarily choose one and discard the others.
18109 The AT_*_pc values for such functions refer to local labels in
18110 these sections. If the section from that file was discarded, the
18111 labels are not in the output, so the relocs get a value of 0.
18112 If this is a discarded function, mark the pc bounds as invalid,
18113 so that GDB will ignore it. */
18114 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18116 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18117 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18119 complaint (_("DW_AT_low_pc %s is zero "
18120 "for DIE at %s [in module %s]"),
18121 paddress (gdbarch
, lowpc
),
18122 sect_offset_str (sect_off
),
18123 objfile_name (objfile
));
18125 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18126 else if (lowpc
>= highpc
)
18128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18129 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18131 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18132 "for DIE at %s [in module %s]"),
18133 paddress (gdbarch
, lowpc
),
18134 paddress (gdbarch
, highpc
),
18135 sect_offset_str (sect_off
),
18136 objfile_name (objfile
));
18145 /* Find a cached partial DIE at OFFSET in CU. */
18147 struct partial_die_info
*
18148 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18150 struct partial_die_info
*lookup_die
= NULL
;
18151 struct partial_die_info
part_die (sect_off
);
18153 lookup_die
= ((struct partial_die_info
*)
18154 htab_find_with_hash (partial_dies
, &part_die
,
18155 to_underlying (sect_off
)));
18160 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18161 except in the case of .debug_types DIEs which do not reference
18162 outside their CU (they do however referencing other types via
18163 DW_FORM_ref_sig8). */
18165 static const struct cu_partial_die_info
18166 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18168 struct dwarf2_per_objfile
*dwarf2_per_objfile
18169 = cu
->per_cu
->dwarf2_per_objfile
;
18170 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18171 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18172 struct partial_die_info
*pd
= NULL
;
18174 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18175 && cu
->header
.offset_in_cu_p (sect_off
))
18177 pd
= cu
->find_partial_die (sect_off
);
18180 /* We missed recording what we needed.
18181 Load all dies and try again. */
18182 per_cu
= cu
->per_cu
;
18186 /* TUs don't reference other CUs/TUs (except via type signatures). */
18187 if (cu
->per_cu
->is_debug_types
)
18189 error (_("Dwarf Error: Type Unit at offset %s contains"
18190 " external reference to offset %s [in module %s].\n"),
18191 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18192 bfd_get_filename (objfile
->obfd
));
18194 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18195 dwarf2_per_objfile
);
18197 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18198 load_partial_comp_unit (per_cu
);
18200 per_cu
->cu
->last_used
= 0;
18201 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18204 /* If we didn't find it, and not all dies have been loaded,
18205 load them all and try again. */
18207 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18209 per_cu
->load_all_dies
= 1;
18211 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18212 THIS_CU->cu may already be in use. So we can't just free it and
18213 replace its DIEs with the ones we read in. Instead, we leave those
18214 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18215 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18217 load_partial_comp_unit (per_cu
);
18219 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18223 internal_error (__FILE__
, __LINE__
,
18224 _("could not find partial DIE %s "
18225 "in cache [from module %s]\n"),
18226 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18227 return { per_cu
->cu
, pd
};
18230 /* See if we can figure out if the class lives in a namespace. We do
18231 this by looking for a member function; its demangled name will
18232 contain namespace info, if there is any. */
18235 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18236 struct dwarf2_cu
*cu
)
18238 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18239 what template types look like, because the demangler
18240 frequently doesn't give the same name as the debug info. We
18241 could fix this by only using the demangled name to get the
18242 prefix (but see comment in read_structure_type). */
18244 struct partial_die_info
*real_pdi
;
18245 struct partial_die_info
*child_pdi
;
18247 /* If this DIE (this DIE's specification, if any) has a parent, then
18248 we should not do this. We'll prepend the parent's fully qualified
18249 name when we create the partial symbol. */
18251 real_pdi
= struct_pdi
;
18252 while (real_pdi
->has_specification
)
18254 auto res
= find_partial_die (real_pdi
->spec_offset
,
18255 real_pdi
->spec_is_dwz
, cu
);
18256 real_pdi
= res
.pdi
;
18260 if (real_pdi
->die_parent
!= NULL
)
18263 for (child_pdi
= struct_pdi
->die_child
;
18265 child_pdi
= child_pdi
->die_sibling
)
18267 if (child_pdi
->tag
== DW_TAG_subprogram
18268 && child_pdi
->linkage_name
!= NULL
)
18270 gdb::unique_xmalloc_ptr
<char> actual_class_name
18271 (language_class_name_from_physname (cu
->language_defn
,
18272 child_pdi
->linkage_name
));
18273 if (actual_class_name
!= NULL
)
18275 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18277 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
18278 actual_class_name
.get ());
18286 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18288 /* Once we've fixed up a die, there's no point in doing so again.
18289 This also avoids a memory leak if we were to call
18290 guess_partial_die_structure_name multiple times. */
18294 /* If we found a reference attribute and the DIE has no name, try
18295 to find a name in the referred to DIE. */
18297 if (name
== NULL
&& has_specification
)
18299 struct partial_die_info
*spec_die
;
18301 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18302 spec_die
= res
.pdi
;
18305 spec_die
->fixup (cu
);
18307 if (spec_die
->name
)
18309 name
= spec_die
->name
;
18311 /* Copy DW_AT_external attribute if it is set. */
18312 if (spec_die
->is_external
)
18313 is_external
= spec_die
->is_external
;
18317 /* Set default names for some unnamed DIEs. */
18319 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18320 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18322 /* If there is no parent die to provide a namespace, and there are
18323 children, see if we can determine the namespace from their linkage
18325 if (cu
->language
== language_cplus
18326 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18327 && die_parent
== NULL
18329 && (tag
== DW_TAG_class_type
18330 || tag
== DW_TAG_structure_type
18331 || tag
== DW_TAG_union_type
))
18332 guess_partial_die_structure_name (this, cu
);
18334 /* GCC might emit a nameless struct or union that has a linkage
18335 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18337 && (tag
== DW_TAG_class_type
18338 || tag
== DW_TAG_interface_type
18339 || tag
== DW_TAG_structure_type
18340 || tag
== DW_TAG_union_type
)
18341 && linkage_name
!= NULL
)
18343 gdb::unique_xmalloc_ptr
<char> demangled
18344 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18345 if (demangled
!= nullptr)
18349 /* Strip any leading namespaces/classes, keep only the base name.
18350 DW_AT_name for named DIEs does not contain the prefixes. */
18351 base
= strrchr (demangled
.get (), ':');
18352 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18355 base
= demangled
.get ();
18357 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18358 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
18365 /* Process the attributes that had to be skipped in the first round. These
18366 attributes are the ones that need str_offsets_base or addr_base attributes.
18367 They could not have been processed in the first round, because at the time
18368 the values of str_offsets_base or addr_base may not have been known. */
18369 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18370 struct attribute
*attr
)
18372 struct dwarf2_cu
*cu
= reader
->cu
;
18373 switch (attr
->form
)
18375 case DW_FORM_addrx
:
18376 case DW_FORM_GNU_addr_index
:
18377 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18380 case DW_FORM_strx1
:
18381 case DW_FORM_strx2
:
18382 case DW_FORM_strx3
:
18383 case DW_FORM_strx4
:
18384 case DW_FORM_GNU_str_index
:
18386 unsigned int str_index
= DW_UNSND (attr
);
18387 if (reader
->dwo_file
!= NULL
)
18389 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18390 DW_STRING_IS_CANONICAL (attr
) = 0;
18394 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18395 DW_STRING_IS_CANONICAL (attr
) = 0;
18400 gdb_assert_not_reached (_("Unexpected DWARF form."));
18404 /* Read an attribute value described by an attribute form. */
18406 static const gdb_byte
*
18407 read_attribute_value (const struct die_reader_specs
*reader
,
18408 struct attribute
*attr
, unsigned form
,
18409 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18410 bool *need_reprocess
)
18412 struct dwarf2_cu
*cu
= reader
->cu
;
18413 struct dwarf2_per_objfile
*dwarf2_per_objfile
18414 = cu
->per_cu
->dwarf2_per_objfile
;
18415 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18416 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18417 bfd
*abfd
= reader
->abfd
;
18418 struct comp_unit_head
*cu_header
= &cu
->header
;
18419 unsigned int bytes_read
;
18420 struct dwarf_block
*blk
;
18421 *need_reprocess
= false;
18423 attr
->form
= (enum dwarf_form
) form
;
18426 case DW_FORM_ref_addr
:
18427 if (cu
->header
.version
== 2)
18428 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18431 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18433 info_ptr
+= bytes_read
;
18435 case DW_FORM_GNU_ref_alt
:
18436 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18437 info_ptr
+= bytes_read
;
18440 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18441 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18442 info_ptr
+= bytes_read
;
18444 case DW_FORM_block2
:
18445 blk
= dwarf_alloc_block (cu
);
18446 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18448 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18449 info_ptr
+= blk
->size
;
18450 DW_BLOCK (attr
) = blk
;
18452 case DW_FORM_block4
:
18453 blk
= dwarf_alloc_block (cu
);
18454 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18456 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18457 info_ptr
+= blk
->size
;
18458 DW_BLOCK (attr
) = blk
;
18460 case DW_FORM_data2
:
18461 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18464 case DW_FORM_data4
:
18465 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18468 case DW_FORM_data8
:
18469 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18472 case DW_FORM_data16
:
18473 blk
= dwarf_alloc_block (cu
);
18475 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18477 DW_BLOCK (attr
) = blk
;
18479 case DW_FORM_sec_offset
:
18480 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18481 info_ptr
+= bytes_read
;
18483 case DW_FORM_string
:
18484 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18485 DW_STRING_IS_CANONICAL (attr
) = 0;
18486 info_ptr
+= bytes_read
;
18489 if (!cu
->per_cu
->is_dwz
)
18491 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18492 abfd
, info_ptr
, cu_header
,
18494 DW_STRING_IS_CANONICAL (attr
) = 0;
18495 info_ptr
+= bytes_read
;
18499 case DW_FORM_line_strp
:
18500 if (!cu
->per_cu
->is_dwz
)
18502 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18504 cu_header
, &bytes_read
);
18505 DW_STRING_IS_CANONICAL (attr
) = 0;
18506 info_ptr
+= bytes_read
;
18510 case DW_FORM_GNU_strp_alt
:
18512 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18513 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18516 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
18518 DW_STRING_IS_CANONICAL (attr
) = 0;
18519 info_ptr
+= bytes_read
;
18522 case DW_FORM_exprloc
:
18523 case DW_FORM_block
:
18524 blk
= dwarf_alloc_block (cu
);
18525 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18526 info_ptr
+= bytes_read
;
18527 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18528 info_ptr
+= blk
->size
;
18529 DW_BLOCK (attr
) = blk
;
18531 case DW_FORM_block1
:
18532 blk
= dwarf_alloc_block (cu
);
18533 blk
->size
= read_1_byte (abfd
, info_ptr
);
18535 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18536 info_ptr
+= blk
->size
;
18537 DW_BLOCK (attr
) = blk
;
18539 case DW_FORM_data1
:
18540 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18544 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18547 case DW_FORM_flag_present
:
18548 DW_UNSND (attr
) = 1;
18550 case DW_FORM_sdata
:
18551 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18552 info_ptr
+= bytes_read
;
18554 case DW_FORM_udata
:
18555 case DW_FORM_rnglistx
:
18556 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18557 info_ptr
+= bytes_read
;
18560 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18561 + read_1_byte (abfd
, info_ptr
));
18565 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18566 + read_2_bytes (abfd
, info_ptr
));
18570 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18571 + read_4_bytes (abfd
, info_ptr
));
18575 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18576 + read_8_bytes (abfd
, info_ptr
));
18579 case DW_FORM_ref_sig8
:
18580 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18583 case DW_FORM_ref_udata
:
18584 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18585 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18586 info_ptr
+= bytes_read
;
18588 case DW_FORM_indirect
:
18589 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18590 info_ptr
+= bytes_read
;
18591 if (form
== DW_FORM_implicit_const
)
18593 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18594 info_ptr
+= bytes_read
;
18596 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18597 info_ptr
, need_reprocess
);
18599 case DW_FORM_implicit_const
:
18600 DW_SND (attr
) = implicit_const
;
18602 case DW_FORM_addrx
:
18603 case DW_FORM_GNU_addr_index
:
18604 *need_reprocess
= true;
18605 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18606 info_ptr
+= bytes_read
;
18609 case DW_FORM_strx1
:
18610 case DW_FORM_strx2
:
18611 case DW_FORM_strx3
:
18612 case DW_FORM_strx4
:
18613 case DW_FORM_GNU_str_index
:
18615 ULONGEST str_index
;
18616 if (form
== DW_FORM_strx1
)
18618 str_index
= read_1_byte (abfd
, info_ptr
);
18621 else if (form
== DW_FORM_strx2
)
18623 str_index
= read_2_bytes (abfd
, info_ptr
);
18626 else if (form
== DW_FORM_strx3
)
18628 str_index
= read_3_bytes (abfd
, info_ptr
);
18631 else if (form
== DW_FORM_strx4
)
18633 str_index
= read_4_bytes (abfd
, info_ptr
);
18638 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18639 info_ptr
+= bytes_read
;
18641 *need_reprocess
= true;
18642 DW_UNSND (attr
) = str_index
;
18646 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18647 dwarf_form_name (form
),
18648 bfd_get_filename (abfd
));
18652 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18653 attr
->form
= DW_FORM_GNU_ref_alt
;
18655 /* We have seen instances where the compiler tried to emit a byte
18656 size attribute of -1 which ended up being encoded as an unsigned
18657 0xffffffff. Although 0xffffffff is technically a valid size value,
18658 an object of this size seems pretty unlikely so we can relatively
18659 safely treat these cases as if the size attribute was invalid and
18660 treat them as zero by default. */
18661 if (attr
->name
== DW_AT_byte_size
18662 && form
== DW_FORM_data4
18663 && DW_UNSND (attr
) >= 0xffffffff)
18666 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18667 hex_string (DW_UNSND (attr
)));
18668 DW_UNSND (attr
) = 0;
18674 /* Read an attribute described by an abbreviated attribute. */
18676 static const gdb_byte
*
18677 read_attribute (const struct die_reader_specs
*reader
,
18678 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18679 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18681 attr
->name
= abbrev
->name
;
18682 return read_attribute_value (reader
, attr
, abbrev
->form
,
18683 abbrev
->implicit_const
, info_ptr
,
18687 /* Cover function for read_initial_length.
18688 Returns the length of the object at BUF, and stores the size of the
18689 initial length in *BYTES_READ and stores the size that offsets will be in
18691 If the initial length size is not equivalent to that specified in
18692 CU_HEADER then issue a complaint.
18693 This is useful when reading non-comp-unit headers. */
18696 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18697 const struct comp_unit_head
*cu_header
,
18698 unsigned int *bytes_read
,
18699 unsigned int *offset_size
)
18701 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18703 gdb_assert (cu_header
->initial_length_size
== 4
18704 || cu_header
->initial_length_size
== 8
18705 || cu_header
->initial_length_size
== 12);
18707 if (cu_header
->initial_length_size
!= *bytes_read
)
18708 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18710 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18714 /* Return pointer to string at section SECT offset STR_OFFSET with error
18715 reporting strings FORM_NAME and SECT_NAME. */
18717 static const char *
18718 read_indirect_string_at_offset_from (struct objfile
*objfile
,
18719 bfd
*abfd
, LONGEST str_offset
,
18720 struct dwarf2_section_info
*sect
,
18721 const char *form_name
,
18722 const char *sect_name
)
18724 sect
->read (objfile
);
18725 if (sect
->buffer
== NULL
)
18726 error (_("%s used without %s section [in module %s]"),
18727 form_name
, sect_name
, bfd_get_filename (abfd
));
18728 if (str_offset
>= sect
->size
)
18729 error (_("%s pointing outside of %s section [in module %s]"),
18730 form_name
, sect_name
, bfd_get_filename (abfd
));
18731 gdb_assert (HOST_CHAR_BIT
== 8);
18732 if (sect
->buffer
[str_offset
] == '\0')
18734 return (const char *) (sect
->buffer
+ str_offset
);
18737 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18739 static const char *
18740 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18741 bfd
*abfd
, LONGEST str_offset
)
18743 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18745 &dwarf2_per_objfile
->str
,
18746 "DW_FORM_strp", ".debug_str");
18749 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
18751 static const char *
18752 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18753 bfd
*abfd
, LONGEST str_offset
)
18755 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18757 &dwarf2_per_objfile
->line_str
,
18758 "DW_FORM_line_strp",
18759 ".debug_line_str");
18762 /* Read a string at offset STR_OFFSET in the .debug_str section from
18763 the .dwz file DWZ. Throw an error if the offset is too large. If
18764 the string consists of a single NUL byte, return NULL; otherwise
18765 return a pointer to the string. */
18767 static const char *
18768 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
18769 LONGEST str_offset
)
18771 dwz
->str
.read (objfile
);
18773 if (dwz
->str
.buffer
== NULL
)
18774 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
18775 "section [in module %s]"),
18776 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18777 if (str_offset
>= dwz
->str
.size
)
18778 error (_("DW_FORM_GNU_strp_alt pointing outside of "
18779 ".debug_str section [in module %s]"),
18780 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18781 gdb_assert (HOST_CHAR_BIT
== 8);
18782 if (dwz
->str
.buffer
[str_offset
] == '\0')
18784 return (const char *) (dwz
->str
.buffer
+ str_offset
);
18787 /* Return pointer to string at .debug_str offset as read from BUF.
18788 BUF is assumed to be in a compilation unit described by CU_HEADER.
18789 Return *BYTES_READ_PTR count of bytes read from BUF. */
18791 static const char *
18792 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18793 const gdb_byte
*buf
,
18794 const struct comp_unit_head
*cu_header
,
18795 unsigned int *bytes_read_ptr
)
18797 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18799 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
18802 /* Return pointer to string at .debug_line_str offset as read from BUF.
18803 BUF is assumed to be in a compilation unit described by CU_HEADER.
18804 Return *BYTES_READ_PTR count of bytes read from BUF. */
18806 static const char *
18807 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18808 bfd
*abfd
, const gdb_byte
*buf
,
18809 const struct comp_unit_head
*cu_header
,
18810 unsigned int *bytes_read_ptr
)
18812 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18814 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
18818 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18819 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18820 ADDR_SIZE is the size of addresses from the CU header. */
18823 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18824 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18827 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18828 bfd
*abfd
= objfile
->obfd
;
18829 const gdb_byte
*info_ptr
;
18830 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18832 dwarf2_per_objfile
->addr
.read (objfile
);
18833 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18834 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18835 objfile_name (objfile
));
18836 if (addr_base_or_zero
+ addr_index
* addr_size
18837 >= dwarf2_per_objfile
->addr
.size
)
18838 error (_("DW_FORM_addr_index pointing outside of "
18839 ".debug_addr section [in module %s]"),
18840 objfile_name (objfile
));
18841 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18842 + addr_base_or_zero
+ addr_index
* addr_size
);
18843 if (addr_size
== 4)
18844 return bfd_get_32 (abfd
, info_ptr
);
18846 return bfd_get_64 (abfd
, info_ptr
);
18849 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18852 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18854 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18855 cu
->addr_base
, cu
->header
.addr_size
);
18858 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18861 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18862 unsigned int *bytes_read
)
18864 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18865 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18867 return read_addr_index (cu
, addr_index
);
18870 /* Given an index in .debug_addr, fetch the value.
18871 NOTE: This can be called during dwarf expression evaluation,
18872 long after the debug information has been read, and thus per_cu->cu
18873 may no longer exist. */
18876 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
18877 unsigned int addr_index
)
18879 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18880 struct dwarf2_cu
*cu
= per_cu
->cu
;
18881 gdb::optional
<ULONGEST
> addr_base
;
18884 /* We need addr_base and addr_size.
18885 If we don't have PER_CU->cu, we have to get it.
18886 Nasty, but the alternative is storing the needed info in PER_CU,
18887 which at this point doesn't seem justified: it's not clear how frequently
18888 it would get used and it would increase the size of every PER_CU.
18889 Entry points like dwarf2_per_cu_addr_size do a similar thing
18890 so we're not in uncharted territory here.
18891 Alas we need to be a bit more complicated as addr_base is contained
18894 We don't need to read the entire CU(/TU).
18895 We just need the header and top level die.
18897 IWBN to use the aging mechanism to let us lazily later discard the CU.
18898 For now we skip this optimization. */
18902 addr_base
= cu
->addr_base
;
18903 addr_size
= cu
->header
.addr_size
;
18907 cutu_reader
reader (per_cu
, NULL
, 0, false);
18908 addr_base
= reader
.cu
->addr_base
;
18909 addr_size
= reader
.cu
->header
.addr_size
;
18912 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18916 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18917 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18920 static const char *
18921 read_str_index (struct dwarf2_cu
*cu
,
18922 struct dwarf2_section_info
*str_section
,
18923 struct dwarf2_section_info
*str_offsets_section
,
18924 ULONGEST str_offsets_base
, ULONGEST str_index
)
18926 struct dwarf2_per_objfile
*dwarf2_per_objfile
18927 = cu
->per_cu
->dwarf2_per_objfile
;
18928 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18929 const char *objf_name
= objfile_name (objfile
);
18930 bfd
*abfd
= objfile
->obfd
;
18931 const gdb_byte
*info_ptr
;
18932 ULONGEST str_offset
;
18933 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18935 str_section
->read (objfile
);
18936 str_offsets_section
->read (objfile
);
18937 if (str_section
->buffer
== NULL
)
18938 error (_("%s used without %s section"
18939 " in CU at offset %s [in module %s]"),
18940 form_name
, str_section
->get_name (),
18941 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18942 if (str_offsets_section
->buffer
== NULL
)
18943 error (_("%s used without %s section"
18944 " in CU at offset %s [in module %s]"),
18945 form_name
, str_section
->get_name (),
18946 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18947 info_ptr
= (str_offsets_section
->buffer
18949 + str_index
* cu
->header
.offset_size
);
18950 if (cu
->header
.offset_size
== 4)
18951 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18953 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18954 if (str_offset
>= str_section
->size
)
18955 error (_("Offset from %s pointing outside of"
18956 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18957 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18958 return (const char *) (str_section
->buffer
+ str_offset
);
18961 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18963 static const char *
18964 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18966 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18967 ? reader
->cu
->header
.addr_size
: 0;
18968 return read_str_index (reader
->cu
,
18969 &reader
->dwo_file
->sections
.str
,
18970 &reader
->dwo_file
->sections
.str_offsets
,
18971 str_offsets_base
, str_index
);
18974 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18976 static const char *
18977 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18979 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18980 const char *objf_name
= objfile_name (objfile
);
18981 static const char form_name
[] = "DW_FORM_GNU_str_index";
18982 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18984 if (!cu
->str_offsets_base
.has_value ())
18985 error (_("%s used in Fission stub without %s"
18986 " in CU at offset 0x%lx [in module %s]"),
18987 form_name
, str_offsets_attr_name
,
18988 (long) cu
->header
.offset_size
, objf_name
);
18990 return read_str_index (cu
,
18991 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18992 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18993 *cu
->str_offsets_base
, str_index
);
18996 /* Return the length of an LEB128 number in BUF. */
18999 leb128_size (const gdb_byte
*buf
)
19001 const gdb_byte
*begin
= buf
;
19007 if ((byte
& 128) == 0)
19008 return buf
- begin
;
19013 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19022 cu
->language
= language_c
;
19025 case DW_LANG_C_plus_plus
:
19026 case DW_LANG_C_plus_plus_11
:
19027 case DW_LANG_C_plus_plus_14
:
19028 cu
->language
= language_cplus
;
19031 cu
->language
= language_d
;
19033 case DW_LANG_Fortran77
:
19034 case DW_LANG_Fortran90
:
19035 case DW_LANG_Fortran95
:
19036 case DW_LANG_Fortran03
:
19037 case DW_LANG_Fortran08
:
19038 cu
->language
= language_fortran
;
19041 cu
->language
= language_go
;
19043 case DW_LANG_Mips_Assembler
:
19044 cu
->language
= language_asm
;
19046 case DW_LANG_Ada83
:
19047 case DW_LANG_Ada95
:
19048 cu
->language
= language_ada
;
19050 case DW_LANG_Modula2
:
19051 cu
->language
= language_m2
;
19053 case DW_LANG_Pascal83
:
19054 cu
->language
= language_pascal
;
19057 cu
->language
= language_objc
;
19060 case DW_LANG_Rust_old
:
19061 cu
->language
= language_rust
;
19063 case DW_LANG_Cobol74
:
19064 case DW_LANG_Cobol85
:
19066 cu
->language
= language_minimal
;
19069 cu
->language_defn
= language_def (cu
->language
);
19072 /* Return the named attribute or NULL if not there. */
19074 static struct attribute
*
19075 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19080 struct attribute
*spec
= NULL
;
19082 for (i
= 0; i
< die
->num_attrs
; ++i
)
19084 if (die
->attrs
[i
].name
== name
)
19085 return &die
->attrs
[i
];
19086 if (die
->attrs
[i
].name
== DW_AT_specification
19087 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19088 spec
= &die
->attrs
[i
];
19094 die
= follow_die_ref (die
, spec
, &cu
);
19100 /* Return the named attribute or NULL if not there,
19101 but do not follow DW_AT_specification, etc.
19102 This is for use in contexts where we're reading .debug_types dies.
19103 Following DW_AT_specification, DW_AT_abstract_origin will take us
19104 back up the chain, and we want to go down. */
19106 static struct attribute
*
19107 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19111 for (i
= 0; i
< die
->num_attrs
; ++i
)
19112 if (die
->attrs
[i
].name
== name
)
19113 return &die
->attrs
[i
];
19118 /* Return the string associated with a string-typed attribute, or NULL if it
19119 is either not found or is of an incorrect type. */
19121 static const char *
19122 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19124 struct attribute
*attr
;
19125 const char *str
= NULL
;
19127 attr
= dwarf2_attr (die
, name
, cu
);
19131 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19132 || attr
->form
== DW_FORM_string
19133 || attr
->form
== DW_FORM_strx
19134 || attr
->form
== DW_FORM_strx1
19135 || attr
->form
== DW_FORM_strx2
19136 || attr
->form
== DW_FORM_strx3
19137 || attr
->form
== DW_FORM_strx4
19138 || attr
->form
== DW_FORM_GNU_str_index
19139 || attr
->form
== DW_FORM_GNU_strp_alt
)
19140 str
= DW_STRING (attr
);
19142 complaint (_("string type expected for attribute %s for "
19143 "DIE at %s in module %s"),
19144 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19145 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19151 /* Return the dwo name or NULL if not present. If present, it is in either
19152 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19153 static const char *
19154 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19156 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19157 if (dwo_name
== nullptr)
19158 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19162 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19163 and holds a non-zero value. This function should only be used for
19164 DW_FORM_flag or DW_FORM_flag_present attributes. */
19167 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19169 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19171 return (attr
&& DW_UNSND (attr
));
19175 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19177 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19178 which value is non-zero. However, we have to be careful with
19179 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19180 (via dwarf2_flag_true_p) follows this attribute. So we may
19181 end up accidently finding a declaration attribute that belongs
19182 to a different DIE referenced by the specification attribute,
19183 even though the given DIE does not have a declaration attribute. */
19184 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19185 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19188 /* Return the die giving the specification for DIE, if there is
19189 one. *SPEC_CU is the CU containing DIE on input, and the CU
19190 containing the return value on output. If there is no
19191 specification, but there is an abstract origin, that is
19194 static struct die_info
*
19195 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19197 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19200 if (spec_attr
== NULL
)
19201 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19203 if (spec_attr
== NULL
)
19206 return follow_die_ref (die
, spec_attr
, spec_cu
);
19209 /* Stub for free_line_header to match void * callback types. */
19212 free_line_header_voidp (void *arg
)
19214 struct line_header
*lh
= (struct line_header
*) arg
;
19219 /* A convenience function to find the proper .debug_line section for a CU. */
19221 static struct dwarf2_section_info
*
19222 get_debug_line_section (struct dwarf2_cu
*cu
)
19224 struct dwarf2_section_info
*section
;
19225 struct dwarf2_per_objfile
*dwarf2_per_objfile
19226 = cu
->per_cu
->dwarf2_per_objfile
;
19228 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19230 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19231 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19232 else if (cu
->per_cu
->is_dwz
)
19234 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19236 section
= &dwz
->line
;
19239 section
= &dwarf2_per_objfile
->line
;
19244 /* Read directory or file name entry format, starting with byte of
19245 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19246 entries count and the entries themselves in the described entry
19250 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19251 bfd
*abfd
, const gdb_byte
**bufp
,
19252 struct line_header
*lh
,
19253 const struct comp_unit_head
*cu_header
,
19254 void (*callback
) (struct line_header
*lh
,
19257 unsigned int mod_time
,
19258 unsigned int length
))
19260 gdb_byte format_count
, formati
;
19261 ULONGEST data_count
, datai
;
19262 const gdb_byte
*buf
= *bufp
;
19263 const gdb_byte
*format_header_data
;
19264 unsigned int bytes_read
;
19266 format_count
= read_1_byte (abfd
, buf
);
19268 format_header_data
= buf
;
19269 for (formati
= 0; formati
< format_count
; formati
++)
19271 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19273 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19277 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19279 for (datai
= 0; datai
< data_count
; datai
++)
19281 const gdb_byte
*format
= format_header_data
;
19282 struct file_entry fe
;
19284 for (formati
= 0; formati
< format_count
; formati
++)
19286 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19287 format
+= bytes_read
;
19289 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19290 format
+= bytes_read
;
19292 gdb::optional
<const char *> string
;
19293 gdb::optional
<unsigned int> uint
;
19297 case DW_FORM_string
:
19298 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19302 case DW_FORM_line_strp
:
19303 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19310 case DW_FORM_data1
:
19311 uint
.emplace (read_1_byte (abfd
, buf
));
19315 case DW_FORM_data2
:
19316 uint
.emplace (read_2_bytes (abfd
, buf
));
19320 case DW_FORM_data4
:
19321 uint
.emplace (read_4_bytes (abfd
, buf
));
19325 case DW_FORM_data8
:
19326 uint
.emplace (read_8_bytes (abfd
, buf
));
19330 case DW_FORM_data16
:
19331 /* This is used for MD5, but file_entry does not record MD5s. */
19335 case DW_FORM_udata
:
19336 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19340 case DW_FORM_block
:
19341 /* It is valid only for DW_LNCT_timestamp which is ignored by
19346 switch (content_type
)
19349 if (string
.has_value ())
19352 case DW_LNCT_directory_index
:
19353 if (uint
.has_value ())
19354 fe
.d_index
= (dir_index
) *uint
;
19356 case DW_LNCT_timestamp
:
19357 if (uint
.has_value ())
19358 fe
.mod_time
= *uint
;
19361 if (uint
.has_value ())
19367 complaint (_("Unknown format content type %s"),
19368 pulongest (content_type
));
19372 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19378 /* Read the statement program header starting at OFFSET in
19379 .debug_line, or .debug_line.dwo. Return a pointer
19380 to a struct line_header, allocated using xmalloc.
19381 Returns NULL if there is a problem reading the header, e.g., if it
19382 has a version we don't understand.
19384 NOTE: the strings in the include directory and file name tables of
19385 the returned object point into the dwarf line section buffer,
19386 and must not be freed. */
19388 static line_header_up
19389 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19391 const gdb_byte
*line_ptr
;
19392 unsigned int bytes_read
, offset_size
;
19394 const char *cur_dir
, *cur_file
;
19395 struct dwarf2_section_info
*section
;
19397 struct dwarf2_per_objfile
*dwarf2_per_objfile
19398 = cu
->per_cu
->dwarf2_per_objfile
;
19400 section
= get_debug_line_section (cu
);
19401 section
->read (dwarf2_per_objfile
->objfile
);
19402 if (section
->buffer
== NULL
)
19404 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19405 complaint (_("missing .debug_line.dwo section"));
19407 complaint (_("missing .debug_line section"));
19411 /* We can't do this until we know the section is non-empty.
19412 Only then do we know we have such a section. */
19413 abfd
= section
->get_bfd_owner ();
19415 /* Make sure that at least there's room for the total_length field.
19416 That could be 12 bytes long, but we're just going to fudge that. */
19417 if (to_underlying (sect_off
) + 4 >= section
->size
)
19419 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19423 line_header_up
lh (new line_header ());
19425 lh
->sect_off
= sect_off
;
19426 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19428 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19430 /* Read in the header. */
19432 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19433 &bytes_read
, &offset_size
);
19434 line_ptr
+= bytes_read
;
19436 const gdb_byte
*start_here
= line_ptr
;
19438 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19440 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19443 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19444 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19446 if (lh
->version
> 5)
19448 /* This is a version we don't understand. The format could have
19449 changed in ways we don't handle properly so just punt. */
19450 complaint (_("unsupported version in .debug_line section"));
19453 if (lh
->version
>= 5)
19455 gdb_byte segment_selector_size
;
19457 /* Skip address size. */
19458 read_1_byte (abfd
, line_ptr
);
19461 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19463 if (segment_selector_size
!= 0)
19465 complaint (_("unsupported segment selector size %u "
19466 "in .debug_line section"),
19467 segment_selector_size
);
19471 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19472 line_ptr
+= offset_size
;
19473 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19474 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19476 if (lh
->version
>= 4)
19478 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19482 lh
->maximum_ops_per_instruction
= 1;
19484 if (lh
->maximum_ops_per_instruction
== 0)
19486 lh
->maximum_ops_per_instruction
= 1;
19487 complaint (_("invalid maximum_ops_per_instruction "
19488 "in `.debug_line' section"));
19491 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19493 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19495 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19497 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19499 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19501 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19502 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19504 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19508 if (lh
->version
>= 5)
19510 /* Read directory table. */
19511 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19513 [] (struct line_header
*header
, const char *name
,
19514 dir_index d_index
, unsigned int mod_time
,
19515 unsigned int length
)
19517 header
->add_include_dir (name
);
19520 /* Read file name table. */
19521 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19523 [] (struct line_header
*header
, const char *name
,
19524 dir_index d_index
, unsigned int mod_time
,
19525 unsigned int length
)
19527 header
->add_file_name (name
, d_index
, mod_time
, length
);
19532 /* Read directory table. */
19533 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19535 line_ptr
+= bytes_read
;
19536 lh
->add_include_dir (cur_dir
);
19538 line_ptr
+= bytes_read
;
19540 /* Read file name table. */
19541 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19543 unsigned int mod_time
, length
;
19546 line_ptr
+= bytes_read
;
19547 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19548 line_ptr
+= bytes_read
;
19549 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19550 line_ptr
+= bytes_read
;
19551 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19552 line_ptr
+= bytes_read
;
19554 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19556 line_ptr
+= bytes_read
;
19559 if (line_ptr
> (section
->buffer
+ section
->size
))
19560 complaint (_("line number info header doesn't "
19561 "fit in `.debug_line' section"));
19566 /* Subroutine of dwarf_decode_lines to simplify it.
19567 Return the file name of the psymtab for the given file_entry.
19568 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19569 If space for the result is malloc'd, *NAME_HOLDER will be set.
19570 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19572 static const char *
19573 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19574 const dwarf2_psymtab
*pst
,
19575 const char *comp_dir
,
19576 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19578 const char *include_name
= fe
.name
;
19579 const char *include_name_to_compare
= include_name
;
19580 const char *pst_filename
;
19583 const char *dir_name
= fe
.include_dir (lh
);
19585 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19586 if (!IS_ABSOLUTE_PATH (include_name
)
19587 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19589 /* Avoid creating a duplicate psymtab for PST.
19590 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19591 Before we do the comparison, however, we need to account
19592 for DIR_NAME and COMP_DIR.
19593 First prepend dir_name (if non-NULL). If we still don't
19594 have an absolute path prepend comp_dir (if non-NULL).
19595 However, the directory we record in the include-file's
19596 psymtab does not contain COMP_DIR (to match the
19597 corresponding symtab(s)).
19602 bash$ gcc -g ./hello.c
19603 include_name = "hello.c"
19605 DW_AT_comp_dir = comp_dir = "/tmp"
19606 DW_AT_name = "./hello.c"
19610 if (dir_name
!= NULL
)
19612 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19613 include_name
, (char *) NULL
));
19614 include_name
= name_holder
->get ();
19615 include_name_to_compare
= include_name
;
19617 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19619 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19620 include_name
, (char *) NULL
));
19621 include_name_to_compare
= hold_compare
.get ();
19625 pst_filename
= pst
->filename
;
19626 gdb::unique_xmalloc_ptr
<char> copied_name
;
19627 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19629 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19630 pst_filename
, (char *) NULL
));
19631 pst_filename
= copied_name
.get ();
19634 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19638 return include_name
;
19641 /* State machine to track the state of the line number program. */
19643 class lnp_state_machine
19646 /* Initialize a machine state for the start of a line number
19648 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19649 bool record_lines_p
);
19651 file_entry
*current_file ()
19653 /* lh->file_names is 0-based, but the file name numbers in the
19654 statement program are 1-based. */
19655 return m_line_header
->file_name_at (m_file
);
19658 /* Record the line in the state machine. END_SEQUENCE is true if
19659 we're processing the end of a sequence. */
19660 void record_line (bool end_sequence
);
19662 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19663 nop-out rest of the lines in this sequence. */
19664 void check_line_address (struct dwarf2_cu
*cu
,
19665 const gdb_byte
*line_ptr
,
19666 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19668 void handle_set_discriminator (unsigned int discriminator
)
19670 m_discriminator
= discriminator
;
19671 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19674 /* Handle DW_LNE_set_address. */
19675 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19678 address
+= baseaddr
;
19679 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19682 /* Handle DW_LNS_advance_pc. */
19683 void handle_advance_pc (CORE_ADDR adjust
);
19685 /* Handle a special opcode. */
19686 void handle_special_opcode (unsigned char op_code
);
19688 /* Handle DW_LNS_advance_line. */
19689 void handle_advance_line (int line_delta
)
19691 advance_line (line_delta
);
19694 /* Handle DW_LNS_set_file. */
19695 void handle_set_file (file_name_index file
);
19697 /* Handle DW_LNS_negate_stmt. */
19698 void handle_negate_stmt ()
19700 m_is_stmt
= !m_is_stmt
;
19703 /* Handle DW_LNS_const_add_pc. */
19704 void handle_const_add_pc ();
19706 /* Handle DW_LNS_fixed_advance_pc. */
19707 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19709 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19713 /* Handle DW_LNS_copy. */
19714 void handle_copy ()
19716 record_line (false);
19717 m_discriminator
= 0;
19720 /* Handle DW_LNE_end_sequence. */
19721 void handle_end_sequence ()
19723 m_currently_recording_lines
= true;
19727 /* Advance the line by LINE_DELTA. */
19728 void advance_line (int line_delta
)
19730 m_line
+= line_delta
;
19732 if (line_delta
!= 0)
19733 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19736 struct dwarf2_cu
*m_cu
;
19738 gdbarch
*m_gdbarch
;
19740 /* True if we're recording lines.
19741 Otherwise we're building partial symtabs and are just interested in
19742 finding include files mentioned by the line number program. */
19743 bool m_record_lines_p
;
19745 /* The line number header. */
19746 line_header
*m_line_header
;
19748 /* These are part of the standard DWARF line number state machine,
19749 and initialized according to the DWARF spec. */
19751 unsigned char m_op_index
= 0;
19752 /* The line table index of the current file. */
19753 file_name_index m_file
= 1;
19754 unsigned int m_line
= 1;
19756 /* These are initialized in the constructor. */
19758 CORE_ADDR m_address
;
19760 unsigned int m_discriminator
;
19762 /* Additional bits of state we need to track. */
19764 /* The last file that we called dwarf2_start_subfile for.
19765 This is only used for TLLs. */
19766 unsigned int m_last_file
= 0;
19767 /* The last file a line number was recorded for. */
19768 struct subfile
*m_last_subfile
= NULL
;
19770 /* When true, record the lines we decode. */
19771 bool m_currently_recording_lines
= false;
19773 /* The last line number that was recorded, used to coalesce
19774 consecutive entries for the same line. This can happen, for
19775 example, when discriminators are present. PR 17276. */
19776 unsigned int m_last_line
= 0;
19777 bool m_line_has_non_zero_discriminator
= false;
19781 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19783 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19784 / m_line_header
->maximum_ops_per_instruction
)
19785 * m_line_header
->minimum_instruction_length
);
19786 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19787 m_op_index
= ((m_op_index
+ adjust
)
19788 % m_line_header
->maximum_ops_per_instruction
);
19792 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19794 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19795 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19796 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19797 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19798 / m_line_header
->maximum_ops_per_instruction
)
19799 * m_line_header
->minimum_instruction_length
);
19800 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19801 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19802 % m_line_header
->maximum_ops_per_instruction
);
19804 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19805 advance_line (line_delta
);
19806 record_line (false);
19807 m_discriminator
= 0;
19811 lnp_state_machine::handle_set_file (file_name_index file
)
19815 const file_entry
*fe
= current_file ();
19817 dwarf2_debug_line_missing_file_complaint ();
19818 else if (m_record_lines_p
)
19820 const char *dir
= fe
->include_dir (m_line_header
);
19822 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19823 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19824 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19829 lnp_state_machine::handle_const_add_pc ()
19832 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19835 = (((m_op_index
+ adjust
)
19836 / m_line_header
->maximum_ops_per_instruction
)
19837 * m_line_header
->minimum_instruction_length
);
19839 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19840 m_op_index
= ((m_op_index
+ adjust
)
19841 % m_line_header
->maximum_ops_per_instruction
);
19844 /* Return non-zero if we should add LINE to the line number table.
19845 LINE is the line to add, LAST_LINE is the last line that was added,
19846 LAST_SUBFILE is the subfile for LAST_LINE.
19847 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19848 had a non-zero discriminator.
19850 We have to be careful in the presence of discriminators.
19851 E.g., for this line:
19853 for (i = 0; i < 100000; i++);
19855 clang can emit four line number entries for that one line,
19856 each with a different discriminator.
19857 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19859 However, we want gdb to coalesce all four entries into one.
19860 Otherwise the user could stepi into the middle of the line and
19861 gdb would get confused about whether the pc really was in the
19862 middle of the line.
19864 Things are further complicated by the fact that two consecutive
19865 line number entries for the same line is a heuristic used by gcc
19866 to denote the end of the prologue. So we can't just discard duplicate
19867 entries, we have to be selective about it. The heuristic we use is
19868 that we only collapse consecutive entries for the same line if at least
19869 one of those entries has a non-zero discriminator. PR 17276.
19871 Note: Addresses in the line number state machine can never go backwards
19872 within one sequence, thus this coalescing is ok. */
19875 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19876 unsigned int line
, unsigned int last_line
,
19877 int line_has_non_zero_discriminator
,
19878 struct subfile
*last_subfile
)
19880 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19882 if (line
!= last_line
)
19884 /* Same line for the same file that we've seen already.
19885 As a last check, for pr 17276, only record the line if the line
19886 has never had a non-zero discriminator. */
19887 if (!line_has_non_zero_discriminator
)
19892 /* Use the CU's builder to record line number LINE beginning at
19893 address ADDRESS in the line table of subfile SUBFILE. */
19896 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19897 unsigned int line
, CORE_ADDR address
,
19898 struct dwarf2_cu
*cu
)
19900 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19902 if (dwarf_line_debug
)
19904 fprintf_unfiltered (gdb_stdlog
,
19905 "Recording line %u, file %s, address %s\n",
19906 line
, lbasename (subfile
->name
),
19907 paddress (gdbarch
, address
));
19911 cu
->get_builder ()->record_line (subfile
, line
, addr
);
19914 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19915 Mark the end of a set of line number records.
19916 The arguments are the same as for dwarf_record_line_1.
19917 If SUBFILE is NULL the request is ignored. */
19920 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19921 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19923 if (subfile
== NULL
)
19926 if (dwarf_line_debug
)
19928 fprintf_unfiltered (gdb_stdlog
,
19929 "Finishing current line, file %s, address %s\n",
19930 lbasename (subfile
->name
),
19931 paddress (gdbarch
, address
));
19934 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
19938 lnp_state_machine::record_line (bool end_sequence
)
19940 if (dwarf_line_debug
)
19942 fprintf_unfiltered (gdb_stdlog
,
19943 "Processing actual line %u: file %u,"
19944 " address %s, is_stmt %u, discrim %u%s\n",
19946 paddress (m_gdbarch
, m_address
),
19947 m_is_stmt
, m_discriminator
,
19948 (end_sequence
? "\t(end sequence)" : ""));
19951 file_entry
*fe
= current_file ();
19954 dwarf2_debug_line_missing_file_complaint ();
19955 /* For now we ignore lines not starting on an instruction boundary.
19956 But not when processing end_sequence for compatibility with the
19957 previous version of the code. */
19958 else if (m_op_index
== 0 || end_sequence
)
19960 fe
->included_p
= 1;
19961 if (m_record_lines_p
19962 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
19964 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19967 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19968 m_currently_recording_lines
? m_cu
: nullptr);
19973 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19974 m_line_has_non_zero_discriminator
,
19977 buildsym_compunit
*builder
= m_cu
->get_builder ();
19978 dwarf_record_line_1 (m_gdbarch
,
19979 builder
->get_current_subfile (),
19981 m_currently_recording_lines
? m_cu
: nullptr);
19983 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19984 m_last_line
= m_line
;
19990 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19991 line_header
*lh
, bool record_lines_p
)
19995 m_record_lines_p
= record_lines_p
;
19996 m_line_header
= lh
;
19998 m_currently_recording_lines
= true;
20000 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20001 was a line entry for it so that the backend has a chance to adjust it
20002 and also record it in case it needs it. This is currently used by MIPS
20003 code, cf. `mips_adjust_dwarf2_line'. */
20004 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20005 m_is_stmt
= lh
->default_is_stmt
;
20006 m_discriminator
= 0;
20010 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20011 const gdb_byte
*line_ptr
,
20012 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20014 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20015 the pc range of the CU. However, we restrict the test to only ADDRESS
20016 values of zero to preserve GDB's previous behaviour which is to handle
20017 the specific case of a function being GC'd by the linker. */
20019 if (address
== 0 && address
< unrelocated_lowpc
)
20021 /* This line table is for a function which has been
20022 GCd by the linker. Ignore it. PR gdb/12528 */
20024 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20025 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20027 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20028 line_offset
, objfile_name (objfile
));
20029 m_currently_recording_lines
= false;
20030 /* Note: m_currently_recording_lines is left as false until we see
20031 DW_LNE_end_sequence. */
20035 /* Subroutine of dwarf_decode_lines to simplify it.
20036 Process the line number information in LH.
20037 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20038 program in order to set included_p for every referenced header. */
20041 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20042 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20044 const gdb_byte
*line_ptr
, *extended_end
;
20045 const gdb_byte
*line_end
;
20046 unsigned int bytes_read
, extended_len
;
20047 unsigned char op_code
, extended_op
;
20048 CORE_ADDR baseaddr
;
20049 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20050 bfd
*abfd
= objfile
->obfd
;
20051 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20052 /* True if we're recording line info (as opposed to building partial
20053 symtabs and just interested in finding include files mentioned by
20054 the line number program). */
20055 bool record_lines_p
= !decode_for_pst_p
;
20057 baseaddr
= objfile
->text_section_offset ();
20059 line_ptr
= lh
->statement_program_start
;
20060 line_end
= lh
->statement_program_end
;
20062 /* Read the statement sequences until there's nothing left. */
20063 while (line_ptr
< line_end
)
20065 /* The DWARF line number program state machine. Reset the state
20066 machine at the start of each sequence. */
20067 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20068 bool end_sequence
= false;
20070 if (record_lines_p
)
20072 /* Start a subfile for the current file of the state
20074 const file_entry
*fe
= state_machine
.current_file ();
20077 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20080 /* Decode the table. */
20081 while (line_ptr
< line_end
&& !end_sequence
)
20083 op_code
= read_1_byte (abfd
, line_ptr
);
20086 if (op_code
>= lh
->opcode_base
)
20088 /* Special opcode. */
20089 state_machine
.handle_special_opcode (op_code
);
20091 else switch (op_code
)
20093 case DW_LNS_extended_op
:
20094 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20096 line_ptr
+= bytes_read
;
20097 extended_end
= line_ptr
+ extended_len
;
20098 extended_op
= read_1_byte (abfd
, line_ptr
);
20100 switch (extended_op
)
20102 case DW_LNE_end_sequence
:
20103 state_machine
.handle_end_sequence ();
20104 end_sequence
= true;
20106 case DW_LNE_set_address
:
20109 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20110 line_ptr
+= bytes_read
;
20112 state_machine
.check_line_address (cu
, line_ptr
,
20113 lowpc
- baseaddr
, address
);
20114 state_machine
.handle_set_address (baseaddr
, address
);
20117 case DW_LNE_define_file
:
20119 const char *cur_file
;
20120 unsigned int mod_time
, length
;
20123 cur_file
= read_direct_string (abfd
, line_ptr
,
20125 line_ptr
+= bytes_read
;
20126 dindex
= (dir_index
)
20127 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20128 line_ptr
+= bytes_read
;
20130 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20131 line_ptr
+= bytes_read
;
20133 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20134 line_ptr
+= bytes_read
;
20135 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20138 case DW_LNE_set_discriminator
:
20140 /* The discriminator is not interesting to the
20141 debugger; just ignore it. We still need to
20142 check its value though:
20143 if there are consecutive entries for the same
20144 (non-prologue) line we want to coalesce them.
20147 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20148 line_ptr
+= bytes_read
;
20150 state_machine
.handle_set_discriminator (discr
);
20154 complaint (_("mangled .debug_line section"));
20157 /* Make sure that we parsed the extended op correctly. If e.g.
20158 we expected a different address size than the producer used,
20159 we may have read the wrong number of bytes. */
20160 if (line_ptr
!= extended_end
)
20162 complaint (_("mangled .debug_line section"));
20167 state_machine
.handle_copy ();
20169 case DW_LNS_advance_pc
:
20172 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20173 line_ptr
+= bytes_read
;
20175 state_machine
.handle_advance_pc (adjust
);
20178 case DW_LNS_advance_line
:
20181 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20182 line_ptr
+= bytes_read
;
20184 state_machine
.handle_advance_line (line_delta
);
20187 case DW_LNS_set_file
:
20189 file_name_index file
20190 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20192 line_ptr
+= bytes_read
;
20194 state_machine
.handle_set_file (file
);
20197 case DW_LNS_set_column
:
20198 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20199 line_ptr
+= bytes_read
;
20201 case DW_LNS_negate_stmt
:
20202 state_machine
.handle_negate_stmt ();
20204 case DW_LNS_set_basic_block
:
20206 /* Add to the address register of the state machine the
20207 address increment value corresponding to special opcode
20208 255. I.e., this value is scaled by the minimum
20209 instruction length since special opcode 255 would have
20210 scaled the increment. */
20211 case DW_LNS_const_add_pc
:
20212 state_machine
.handle_const_add_pc ();
20214 case DW_LNS_fixed_advance_pc
:
20216 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20219 state_machine
.handle_fixed_advance_pc (addr_adj
);
20224 /* Unknown standard opcode, ignore it. */
20227 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20229 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20230 line_ptr
+= bytes_read
;
20237 dwarf2_debug_line_missing_end_sequence_complaint ();
20239 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20240 in which case we still finish recording the last line). */
20241 state_machine
.record_line (true);
20245 /* Decode the Line Number Program (LNP) for the given line_header
20246 structure and CU. The actual information extracted and the type
20247 of structures created from the LNP depends on the value of PST.
20249 1. If PST is NULL, then this procedure uses the data from the program
20250 to create all necessary symbol tables, and their linetables.
20252 2. If PST is not NULL, this procedure reads the program to determine
20253 the list of files included by the unit represented by PST, and
20254 builds all the associated partial symbol tables.
20256 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20257 It is used for relative paths in the line table.
20258 NOTE: When processing partial symtabs (pst != NULL),
20259 comp_dir == pst->dirname.
20261 NOTE: It is important that psymtabs have the same file name (via strcmp)
20262 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20263 symtab we don't use it in the name of the psymtabs we create.
20264 E.g. expand_line_sal requires this when finding psymtabs to expand.
20265 A good testcase for this is mb-inline.exp.
20267 LOWPC is the lowest address in CU (or 0 if not known).
20269 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20270 for its PC<->lines mapping information. Otherwise only the filename
20271 table is read in. */
20274 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20275 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20276 CORE_ADDR lowpc
, int decode_mapping
)
20278 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20279 const int decode_for_pst_p
= (pst
!= NULL
);
20281 if (decode_mapping
)
20282 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20284 if (decode_for_pst_p
)
20286 /* Now that we're done scanning the Line Header Program, we can
20287 create the psymtab of each included file. */
20288 for (auto &file_entry
: lh
->file_names ())
20289 if (file_entry
.included_p
== 1)
20291 gdb::unique_xmalloc_ptr
<char> name_holder
;
20292 const char *include_name
=
20293 psymtab_include_file_name (lh
, file_entry
, pst
,
20294 comp_dir
, &name_holder
);
20295 if (include_name
!= NULL
)
20296 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20301 /* Make sure a symtab is created for every file, even files
20302 which contain only variables (i.e. no code with associated
20304 buildsym_compunit
*builder
= cu
->get_builder ();
20305 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20307 for (auto &fe
: lh
->file_names ())
20309 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20310 if (builder
->get_current_subfile ()->symtab
== NULL
)
20312 builder
->get_current_subfile ()->symtab
20313 = allocate_symtab (cust
,
20314 builder
->get_current_subfile ()->name
);
20316 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20321 /* Start a subfile for DWARF. FILENAME is the name of the file and
20322 DIRNAME the name of the source directory which contains FILENAME
20323 or NULL if not known.
20324 This routine tries to keep line numbers from identical absolute and
20325 relative file names in a common subfile.
20327 Using the `list' example from the GDB testsuite, which resides in
20328 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20329 of /srcdir/list0.c yields the following debugging information for list0.c:
20331 DW_AT_name: /srcdir/list0.c
20332 DW_AT_comp_dir: /compdir
20333 files.files[0].name: list0.h
20334 files.files[0].dir: /srcdir
20335 files.files[1].name: list0.c
20336 files.files[1].dir: /srcdir
20338 The line number information for list0.c has to end up in a single
20339 subfile, so that `break /srcdir/list0.c:1' works as expected.
20340 start_subfile will ensure that this happens provided that we pass the
20341 concatenation of files.files[1].dir and files.files[1].name as the
20345 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20346 const char *dirname
)
20348 gdb::unique_xmalloc_ptr
<char> copy
;
20350 /* In order not to lose the line information directory,
20351 we concatenate it to the filename when it makes sense.
20352 Note that the Dwarf3 standard says (speaking of filenames in line
20353 information): ``The directory index is ignored for file names
20354 that represent full path names''. Thus ignoring dirname in the
20355 `else' branch below isn't an issue. */
20357 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20359 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20360 filename
= copy
.get ();
20363 cu
->get_builder ()->start_subfile (filename
);
20366 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20367 buildsym_compunit constructor. */
20369 struct compunit_symtab
*
20370 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20373 gdb_assert (m_builder
== nullptr);
20375 m_builder
.reset (new struct buildsym_compunit
20376 (per_cu
->dwarf2_per_objfile
->objfile
,
20377 name
, comp_dir
, language
, low_pc
));
20379 list_in_scope
= get_builder ()->get_file_symbols ();
20381 get_builder ()->record_debugformat ("DWARF 2");
20382 get_builder ()->record_producer (producer
);
20384 processing_has_namespace_info
= false;
20386 return get_builder ()->get_compunit_symtab ();
20390 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20391 struct dwarf2_cu
*cu
)
20393 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20394 struct comp_unit_head
*cu_header
= &cu
->header
;
20396 /* NOTE drow/2003-01-30: There used to be a comment and some special
20397 code here to turn a symbol with DW_AT_external and a
20398 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20399 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20400 with some versions of binutils) where shared libraries could have
20401 relocations against symbols in their debug information - the
20402 minimal symbol would have the right address, but the debug info
20403 would not. It's no longer necessary, because we will explicitly
20404 apply relocations when we read in the debug information now. */
20406 /* A DW_AT_location attribute with no contents indicates that a
20407 variable has been optimized away. */
20408 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20410 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20414 /* Handle one degenerate form of location expression specially, to
20415 preserve GDB's previous behavior when section offsets are
20416 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20417 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20419 if (attr
->form_is_block ()
20420 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20421 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20422 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20423 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20424 && (DW_BLOCK (attr
)->size
20425 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20427 unsigned int dummy
;
20429 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20430 SET_SYMBOL_VALUE_ADDRESS
20431 (sym
, cu
->header
.read_address (objfile
->obfd
,
20432 DW_BLOCK (attr
)->data
+ 1,
20435 SET_SYMBOL_VALUE_ADDRESS
20436 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20438 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20439 fixup_symbol_section (sym
, objfile
);
20440 SET_SYMBOL_VALUE_ADDRESS
20442 SYMBOL_VALUE_ADDRESS (sym
)
20443 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20447 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20448 expression evaluator, and use LOC_COMPUTED only when necessary
20449 (i.e. when the value of a register or memory location is
20450 referenced, or a thread-local block, etc.). Then again, it might
20451 not be worthwhile. I'm assuming that it isn't unless performance
20452 or memory numbers show me otherwise. */
20454 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20456 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20457 cu
->has_loclist
= true;
20460 /* Given a pointer to a DWARF information entry, figure out if we need
20461 to make a symbol table entry for it, and if so, create a new entry
20462 and return a pointer to it.
20463 If TYPE is NULL, determine symbol type from the die, otherwise
20464 used the passed type.
20465 If SPACE is not NULL, use it to hold the new symbol. If it is
20466 NULL, allocate a new symbol on the objfile's obstack. */
20468 static struct symbol
*
20469 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20470 struct symbol
*space
)
20472 struct dwarf2_per_objfile
*dwarf2_per_objfile
20473 = cu
->per_cu
->dwarf2_per_objfile
;
20474 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20475 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20476 struct symbol
*sym
= NULL
;
20478 struct attribute
*attr
= NULL
;
20479 struct attribute
*attr2
= NULL
;
20480 CORE_ADDR baseaddr
;
20481 struct pending
**list_to_add
= NULL
;
20483 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20485 baseaddr
= objfile
->text_section_offset ();
20487 name
= dwarf2_name (die
, cu
);
20490 const char *linkagename
;
20491 int suppress_add
= 0;
20496 sym
= allocate_symbol (objfile
);
20497 OBJSTAT (objfile
, n_syms
++);
20499 /* Cache this symbol's name and the name's demangled form (if any). */
20500 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20501 linkagename
= dwarf2_physname (name
, die
, cu
);
20502 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20504 /* Fortran does not have mangling standard and the mangling does differ
20505 between gfortran, iFort etc. */
20506 if (cu
->language
== language_fortran
20507 && symbol_get_demangled_name (sym
) == NULL
)
20508 symbol_set_demangled_name (sym
,
20509 dwarf2_full_name (name
, die
, cu
),
20512 /* Default assumptions.
20513 Use the passed type or decode it from the die. */
20514 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20515 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20517 SYMBOL_TYPE (sym
) = type
;
20519 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20520 attr
= dwarf2_attr (die
,
20521 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20523 if (attr
!= nullptr)
20525 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20528 attr
= dwarf2_attr (die
,
20529 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20531 if (attr
!= nullptr)
20533 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20534 struct file_entry
*fe
;
20536 if (cu
->line_header
!= NULL
)
20537 fe
= cu
->line_header
->file_name_at (file_index
);
20542 complaint (_("file index out of range"));
20544 symbol_set_symtab (sym
, fe
->symtab
);
20550 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20551 if (attr
!= nullptr)
20555 addr
= attr
->value_as_address ();
20556 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20557 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20559 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20560 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20561 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20562 add_symbol_to_list (sym
, cu
->list_in_scope
);
20564 case DW_TAG_subprogram
:
20565 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20567 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20568 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20569 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20570 || cu
->language
== language_ada
20571 || cu
->language
== language_fortran
)
20573 /* Subprograms marked external are stored as a global symbol.
20574 Ada and Fortran subprograms, whether marked external or
20575 not, are always stored as a global symbol, because we want
20576 to be able to access them globally. For instance, we want
20577 to be able to break on a nested subprogram without having
20578 to specify the context. */
20579 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20583 list_to_add
= cu
->list_in_scope
;
20586 case DW_TAG_inlined_subroutine
:
20587 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20589 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20590 SYMBOL_INLINED (sym
) = 1;
20591 list_to_add
= cu
->list_in_scope
;
20593 case DW_TAG_template_value_param
:
20595 /* Fall through. */
20596 case DW_TAG_constant
:
20597 case DW_TAG_variable
:
20598 case DW_TAG_member
:
20599 /* Compilation with minimal debug info may result in
20600 variables with missing type entries. Change the
20601 misleading `void' type to something sensible. */
20602 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20603 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20605 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20606 /* In the case of DW_TAG_member, we should only be called for
20607 static const members. */
20608 if (die
->tag
== DW_TAG_member
)
20610 /* dwarf2_add_field uses die_is_declaration,
20611 so we do the same. */
20612 gdb_assert (die_is_declaration (die
, cu
));
20615 if (attr
!= nullptr)
20617 dwarf2_const_value (attr
, sym
, cu
);
20618 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20621 if (attr2
&& (DW_UNSND (attr2
) != 0))
20622 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20624 list_to_add
= cu
->list_in_scope
;
20628 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20629 if (attr
!= nullptr)
20631 var_decode_location (attr
, sym
, cu
);
20632 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20634 /* Fortran explicitly imports any global symbols to the local
20635 scope by DW_TAG_common_block. */
20636 if (cu
->language
== language_fortran
&& die
->parent
20637 && die
->parent
->tag
== DW_TAG_common_block
)
20640 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20641 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20642 && !dwarf2_per_objfile
->has_section_at_zero
)
20644 /* When a static variable is eliminated by the linker,
20645 the corresponding debug information is not stripped
20646 out, but the variable address is set to null;
20647 do not add such variables into symbol table. */
20649 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20651 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20652 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20653 && dwarf2_per_objfile
->can_copy
)
20655 /* A global static variable might be subject to
20656 copy relocation. We first check for a local
20657 minsym, though, because maybe the symbol was
20658 marked hidden, in which case this would not
20660 bound_minimal_symbol found
20661 = (lookup_minimal_symbol_linkage
20662 (sym
->linkage_name (), objfile
));
20663 if (found
.minsym
!= nullptr)
20664 sym
->maybe_copied
= 1;
20667 /* A variable with DW_AT_external is never static,
20668 but it may be block-scoped. */
20670 = ((cu
->list_in_scope
20671 == cu
->get_builder ()->get_file_symbols ())
20672 ? cu
->get_builder ()->get_global_symbols ()
20673 : cu
->list_in_scope
);
20676 list_to_add
= cu
->list_in_scope
;
20680 /* We do not know the address of this symbol.
20681 If it is an external symbol and we have type information
20682 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20683 The address of the variable will then be determined from
20684 the minimal symbol table whenever the variable is
20686 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20688 /* Fortran explicitly imports any global symbols to the local
20689 scope by DW_TAG_common_block. */
20690 if (cu
->language
== language_fortran
&& die
->parent
20691 && die
->parent
->tag
== DW_TAG_common_block
)
20693 /* SYMBOL_CLASS doesn't matter here because
20694 read_common_block is going to reset it. */
20696 list_to_add
= cu
->list_in_scope
;
20698 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20699 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20701 /* A variable with DW_AT_external is never static, but it
20702 may be block-scoped. */
20704 = ((cu
->list_in_scope
20705 == cu
->get_builder ()->get_file_symbols ())
20706 ? cu
->get_builder ()->get_global_symbols ()
20707 : cu
->list_in_scope
);
20709 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20711 else if (!die_is_declaration (die
, cu
))
20713 /* Use the default LOC_OPTIMIZED_OUT class. */
20714 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20716 list_to_add
= cu
->list_in_scope
;
20720 case DW_TAG_formal_parameter
:
20722 /* If we are inside a function, mark this as an argument. If
20723 not, we might be looking at an argument to an inlined function
20724 when we do not have enough information to show inlined frames;
20725 pretend it's a local variable in that case so that the user can
20727 struct context_stack
*curr
20728 = cu
->get_builder ()->get_current_context_stack ();
20729 if (curr
!= nullptr && curr
->name
!= nullptr)
20730 SYMBOL_IS_ARGUMENT (sym
) = 1;
20731 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20732 if (attr
!= nullptr)
20734 var_decode_location (attr
, sym
, cu
);
20736 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20737 if (attr
!= nullptr)
20739 dwarf2_const_value (attr
, sym
, cu
);
20742 list_to_add
= cu
->list_in_scope
;
20745 case DW_TAG_unspecified_parameters
:
20746 /* From varargs functions; gdb doesn't seem to have any
20747 interest in this information, so just ignore it for now.
20750 case DW_TAG_template_type_param
:
20752 /* Fall through. */
20753 case DW_TAG_class_type
:
20754 case DW_TAG_interface_type
:
20755 case DW_TAG_structure_type
:
20756 case DW_TAG_union_type
:
20757 case DW_TAG_set_type
:
20758 case DW_TAG_enumeration_type
:
20759 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20760 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20763 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20764 really ever be static objects: otherwise, if you try
20765 to, say, break of a class's method and you're in a file
20766 which doesn't mention that class, it won't work unless
20767 the check for all static symbols in lookup_symbol_aux
20768 saves you. See the OtherFileClass tests in
20769 gdb.c++/namespace.exp. */
20773 buildsym_compunit
*builder
= cu
->get_builder ();
20775 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20776 && cu
->language
== language_cplus
20777 ? builder
->get_global_symbols ()
20778 : cu
->list_in_scope
);
20780 /* The semantics of C++ state that "struct foo {
20781 ... }" also defines a typedef for "foo". */
20782 if (cu
->language
== language_cplus
20783 || cu
->language
== language_ada
20784 || cu
->language
== language_d
20785 || cu
->language
== language_rust
)
20787 /* The symbol's name is already allocated along
20788 with this objfile, so we don't need to
20789 duplicate it for the type. */
20790 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20791 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20796 case DW_TAG_typedef
:
20797 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20798 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20799 list_to_add
= cu
->list_in_scope
;
20801 case DW_TAG_base_type
:
20802 case DW_TAG_subrange_type
:
20803 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20804 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20805 list_to_add
= cu
->list_in_scope
;
20807 case DW_TAG_enumerator
:
20808 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20809 if (attr
!= nullptr)
20811 dwarf2_const_value (attr
, sym
, cu
);
20814 /* NOTE: carlton/2003-11-10: See comment above in the
20815 DW_TAG_class_type, etc. block. */
20818 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20819 && cu
->language
== language_cplus
20820 ? cu
->get_builder ()->get_global_symbols ()
20821 : cu
->list_in_scope
);
20824 case DW_TAG_imported_declaration
:
20825 case DW_TAG_namespace
:
20826 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20827 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20829 case DW_TAG_module
:
20830 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20831 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20832 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20834 case DW_TAG_common_block
:
20835 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20836 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20837 add_symbol_to_list (sym
, cu
->list_in_scope
);
20840 /* Not a tag we recognize. Hopefully we aren't processing
20841 trash data, but since we must specifically ignore things
20842 we don't recognize, there is nothing else we should do at
20844 complaint (_("unsupported tag: '%s'"),
20845 dwarf_tag_name (die
->tag
));
20851 sym
->hash_next
= objfile
->template_symbols
;
20852 objfile
->template_symbols
= sym
;
20853 list_to_add
= NULL
;
20856 if (list_to_add
!= NULL
)
20857 add_symbol_to_list (sym
, list_to_add
);
20859 /* For the benefit of old versions of GCC, check for anonymous
20860 namespaces based on the demangled name. */
20861 if (!cu
->processing_has_namespace_info
20862 && cu
->language
== language_cplus
)
20863 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20868 /* Given an attr with a DW_FORM_dataN value in host byte order,
20869 zero-extend it as appropriate for the symbol's type. The DWARF
20870 standard (v4) is not entirely clear about the meaning of using
20871 DW_FORM_dataN for a constant with a signed type, where the type is
20872 wider than the data. The conclusion of a discussion on the DWARF
20873 list was that this is unspecified. We choose to always zero-extend
20874 because that is the interpretation long in use by GCC. */
20877 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20878 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20880 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20881 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20882 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20883 LONGEST l
= DW_UNSND (attr
);
20885 if (bits
< sizeof (*value
) * 8)
20887 l
&= ((LONGEST
) 1 << bits
) - 1;
20890 else if (bits
== sizeof (*value
) * 8)
20894 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20895 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20902 /* Read a constant value from an attribute. Either set *VALUE, or if
20903 the value does not fit in *VALUE, set *BYTES - either already
20904 allocated on the objfile obstack, or newly allocated on OBSTACK,
20905 or, set *BATON, if we translated the constant to a location
20909 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20910 const char *name
, struct obstack
*obstack
,
20911 struct dwarf2_cu
*cu
,
20912 LONGEST
*value
, const gdb_byte
**bytes
,
20913 struct dwarf2_locexpr_baton
**baton
)
20915 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20916 struct comp_unit_head
*cu_header
= &cu
->header
;
20917 struct dwarf_block
*blk
;
20918 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20919 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20925 switch (attr
->form
)
20928 case DW_FORM_addrx
:
20929 case DW_FORM_GNU_addr_index
:
20933 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20934 dwarf2_const_value_length_mismatch_complaint (name
,
20935 cu_header
->addr_size
,
20936 TYPE_LENGTH (type
));
20937 /* Symbols of this form are reasonably rare, so we just
20938 piggyback on the existing location code rather than writing
20939 a new implementation of symbol_computed_ops. */
20940 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20941 (*baton
)->per_cu
= cu
->per_cu
;
20942 gdb_assert ((*baton
)->per_cu
);
20944 (*baton
)->size
= 2 + cu_header
->addr_size
;
20945 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20946 (*baton
)->data
= data
;
20948 data
[0] = DW_OP_addr
;
20949 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20950 byte_order
, DW_ADDR (attr
));
20951 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20954 case DW_FORM_string
:
20957 case DW_FORM_GNU_str_index
:
20958 case DW_FORM_GNU_strp_alt
:
20959 /* DW_STRING is already allocated on the objfile obstack, point
20961 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20963 case DW_FORM_block1
:
20964 case DW_FORM_block2
:
20965 case DW_FORM_block4
:
20966 case DW_FORM_block
:
20967 case DW_FORM_exprloc
:
20968 case DW_FORM_data16
:
20969 blk
= DW_BLOCK (attr
);
20970 if (TYPE_LENGTH (type
) != blk
->size
)
20971 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20972 TYPE_LENGTH (type
));
20973 *bytes
= blk
->data
;
20976 /* The DW_AT_const_value attributes are supposed to carry the
20977 symbol's value "represented as it would be on the target
20978 architecture." By the time we get here, it's already been
20979 converted to host endianness, so we just need to sign- or
20980 zero-extend it as appropriate. */
20981 case DW_FORM_data1
:
20982 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20984 case DW_FORM_data2
:
20985 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20987 case DW_FORM_data4
:
20988 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20990 case DW_FORM_data8
:
20991 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20994 case DW_FORM_sdata
:
20995 case DW_FORM_implicit_const
:
20996 *value
= DW_SND (attr
);
20999 case DW_FORM_udata
:
21000 *value
= DW_UNSND (attr
);
21004 complaint (_("unsupported const value attribute form: '%s'"),
21005 dwarf_form_name (attr
->form
));
21012 /* Copy constant value from an attribute to a symbol. */
21015 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21016 struct dwarf2_cu
*cu
)
21018 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21020 const gdb_byte
*bytes
;
21021 struct dwarf2_locexpr_baton
*baton
;
21023 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21024 sym
->print_name (),
21025 &objfile
->objfile_obstack
, cu
,
21026 &value
, &bytes
, &baton
);
21030 SYMBOL_LOCATION_BATON (sym
) = baton
;
21031 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21033 else if (bytes
!= NULL
)
21035 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21036 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21040 SYMBOL_VALUE (sym
) = value
;
21041 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21045 /* Return the type of the die in question using its DW_AT_type attribute. */
21047 static struct type
*
21048 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21050 struct attribute
*type_attr
;
21052 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21055 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21056 /* A missing DW_AT_type represents a void type. */
21057 return objfile_type (objfile
)->builtin_void
;
21060 return lookup_die_type (die
, type_attr
, cu
);
21063 /* True iff CU's producer generates GNAT Ada auxiliary information
21064 that allows to find parallel types through that information instead
21065 of having to do expensive parallel lookups by type name. */
21068 need_gnat_info (struct dwarf2_cu
*cu
)
21070 /* Assume that the Ada compiler was GNAT, which always produces
21071 the auxiliary information. */
21072 return (cu
->language
== language_ada
);
21075 /* Return the auxiliary type of the die in question using its
21076 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21077 attribute is not present. */
21079 static struct type
*
21080 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21082 struct attribute
*type_attr
;
21084 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21088 return lookup_die_type (die
, type_attr
, cu
);
21091 /* If DIE has a descriptive_type attribute, then set the TYPE's
21092 descriptive type accordingly. */
21095 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21096 struct dwarf2_cu
*cu
)
21098 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21100 if (descriptive_type
)
21102 ALLOCATE_GNAT_AUX_TYPE (type
);
21103 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21107 /* Return the containing type of the die in question using its
21108 DW_AT_containing_type attribute. */
21110 static struct type
*
21111 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21113 struct attribute
*type_attr
;
21114 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21116 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21118 error (_("Dwarf Error: Problem turning containing type into gdb type "
21119 "[in module %s]"), objfile_name (objfile
));
21121 return lookup_die_type (die
, type_attr
, cu
);
21124 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21126 static struct type
*
21127 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21129 struct dwarf2_per_objfile
*dwarf2_per_objfile
21130 = cu
->per_cu
->dwarf2_per_objfile
;
21131 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21134 std::string message
21135 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21136 objfile_name (objfile
),
21137 sect_offset_str (cu
->header
.sect_off
),
21138 sect_offset_str (die
->sect_off
));
21139 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21141 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21144 /* Look up the type of DIE in CU using its type attribute ATTR.
21145 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21146 DW_AT_containing_type.
21147 If there is no type substitute an error marker. */
21149 static struct type
*
21150 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21151 struct dwarf2_cu
*cu
)
21153 struct dwarf2_per_objfile
*dwarf2_per_objfile
21154 = cu
->per_cu
->dwarf2_per_objfile
;
21155 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21156 struct type
*this_type
;
21158 gdb_assert (attr
->name
== DW_AT_type
21159 || attr
->name
== DW_AT_GNAT_descriptive_type
21160 || attr
->name
== DW_AT_containing_type
);
21162 /* First see if we have it cached. */
21164 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21166 struct dwarf2_per_cu_data
*per_cu
;
21167 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21169 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21170 dwarf2_per_objfile
);
21171 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21173 else if (attr
->form_is_ref ())
21175 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21177 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21179 else if (attr
->form
== DW_FORM_ref_sig8
)
21181 ULONGEST signature
= DW_SIGNATURE (attr
);
21183 return get_signatured_type (die
, signature
, cu
);
21187 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21188 " at %s [in module %s]"),
21189 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21190 objfile_name (objfile
));
21191 return build_error_marker_type (cu
, die
);
21194 /* If not cached we need to read it in. */
21196 if (this_type
== NULL
)
21198 struct die_info
*type_die
= NULL
;
21199 struct dwarf2_cu
*type_cu
= cu
;
21201 if (attr
->form_is_ref ())
21202 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21203 if (type_die
== NULL
)
21204 return build_error_marker_type (cu
, die
);
21205 /* If we find the type now, it's probably because the type came
21206 from an inter-CU reference and the type's CU got expanded before
21208 this_type
= read_type_die (type_die
, type_cu
);
21211 /* If we still don't have a type use an error marker. */
21213 if (this_type
== NULL
)
21214 return build_error_marker_type (cu
, die
);
21219 /* Return the type in DIE, CU.
21220 Returns NULL for invalid types.
21222 This first does a lookup in die_type_hash,
21223 and only reads the die in if necessary.
21225 NOTE: This can be called when reading in partial or full symbols. */
21227 static struct type
*
21228 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21230 struct type
*this_type
;
21232 this_type
= get_die_type (die
, cu
);
21236 return read_type_die_1 (die
, cu
);
21239 /* Read the type in DIE, CU.
21240 Returns NULL for invalid types. */
21242 static struct type
*
21243 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21245 struct type
*this_type
= NULL
;
21249 case DW_TAG_class_type
:
21250 case DW_TAG_interface_type
:
21251 case DW_TAG_structure_type
:
21252 case DW_TAG_union_type
:
21253 this_type
= read_structure_type (die
, cu
);
21255 case DW_TAG_enumeration_type
:
21256 this_type
= read_enumeration_type (die
, cu
);
21258 case DW_TAG_subprogram
:
21259 case DW_TAG_subroutine_type
:
21260 case DW_TAG_inlined_subroutine
:
21261 this_type
= read_subroutine_type (die
, cu
);
21263 case DW_TAG_array_type
:
21264 this_type
= read_array_type (die
, cu
);
21266 case DW_TAG_set_type
:
21267 this_type
= read_set_type (die
, cu
);
21269 case DW_TAG_pointer_type
:
21270 this_type
= read_tag_pointer_type (die
, cu
);
21272 case DW_TAG_ptr_to_member_type
:
21273 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21275 case DW_TAG_reference_type
:
21276 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21278 case DW_TAG_rvalue_reference_type
:
21279 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21281 case DW_TAG_const_type
:
21282 this_type
= read_tag_const_type (die
, cu
);
21284 case DW_TAG_volatile_type
:
21285 this_type
= read_tag_volatile_type (die
, cu
);
21287 case DW_TAG_restrict_type
:
21288 this_type
= read_tag_restrict_type (die
, cu
);
21290 case DW_TAG_string_type
:
21291 this_type
= read_tag_string_type (die
, cu
);
21293 case DW_TAG_typedef
:
21294 this_type
= read_typedef (die
, cu
);
21296 case DW_TAG_subrange_type
:
21297 this_type
= read_subrange_type (die
, cu
);
21299 case DW_TAG_base_type
:
21300 this_type
= read_base_type (die
, cu
);
21302 case DW_TAG_unspecified_type
:
21303 this_type
= read_unspecified_type (die
, cu
);
21305 case DW_TAG_namespace
:
21306 this_type
= read_namespace_type (die
, cu
);
21308 case DW_TAG_module
:
21309 this_type
= read_module_type (die
, cu
);
21311 case DW_TAG_atomic_type
:
21312 this_type
= read_tag_atomic_type (die
, cu
);
21315 complaint (_("unexpected tag in read_type_die: '%s'"),
21316 dwarf_tag_name (die
->tag
));
21323 /* See if we can figure out if the class lives in a namespace. We do
21324 this by looking for a member function; its demangled name will
21325 contain namespace info, if there is any.
21326 Return the computed name or NULL.
21327 Space for the result is allocated on the objfile's obstack.
21328 This is the full-die version of guess_partial_die_structure_name.
21329 In this case we know DIE has no useful parent. */
21331 static const char *
21332 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21334 struct die_info
*spec_die
;
21335 struct dwarf2_cu
*spec_cu
;
21336 struct die_info
*child
;
21337 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21340 spec_die
= die_specification (die
, &spec_cu
);
21341 if (spec_die
!= NULL
)
21347 for (child
= die
->child
;
21349 child
= child
->sibling
)
21351 if (child
->tag
== DW_TAG_subprogram
)
21353 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21355 if (linkage_name
!= NULL
)
21357 gdb::unique_xmalloc_ptr
<char> actual_name
21358 (language_class_name_from_physname (cu
->language_defn
,
21360 const char *name
= NULL
;
21362 if (actual_name
!= NULL
)
21364 const char *die_name
= dwarf2_name (die
, cu
);
21366 if (die_name
!= NULL
21367 && strcmp (die_name
, actual_name
.get ()) != 0)
21369 /* Strip off the class name from the full name.
21370 We want the prefix. */
21371 int die_name_len
= strlen (die_name
);
21372 int actual_name_len
= strlen (actual_name
.get ());
21373 const char *ptr
= actual_name
.get ();
21375 /* Test for '::' as a sanity check. */
21376 if (actual_name_len
> die_name_len
+ 2
21377 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21378 name
= obstack_strndup (
21379 &objfile
->per_bfd
->storage_obstack
,
21380 ptr
, actual_name_len
- die_name_len
- 2);
21391 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21392 prefix part in such case. See
21393 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21395 static const char *
21396 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21398 struct attribute
*attr
;
21401 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21402 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21405 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21408 attr
= dw2_linkage_name_attr (die
, cu
);
21409 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21412 /* dwarf2_name had to be already called. */
21413 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21415 /* Strip the base name, keep any leading namespaces/classes. */
21416 base
= strrchr (DW_STRING (attr
), ':');
21417 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21420 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21421 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21423 &base
[-1] - DW_STRING (attr
));
21426 /* Return the name of the namespace/class that DIE is defined within,
21427 or "" if we can't tell. The caller should not xfree the result.
21429 For example, if we're within the method foo() in the following
21439 then determine_prefix on foo's die will return "N::C". */
21441 static const char *
21442 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21444 struct dwarf2_per_objfile
*dwarf2_per_objfile
21445 = cu
->per_cu
->dwarf2_per_objfile
;
21446 struct die_info
*parent
, *spec_die
;
21447 struct dwarf2_cu
*spec_cu
;
21448 struct type
*parent_type
;
21449 const char *retval
;
21451 if (cu
->language
!= language_cplus
21452 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21453 && cu
->language
!= language_rust
)
21456 retval
= anonymous_struct_prefix (die
, cu
);
21460 /* We have to be careful in the presence of DW_AT_specification.
21461 For example, with GCC 3.4, given the code
21465 // Definition of N::foo.
21469 then we'll have a tree of DIEs like this:
21471 1: DW_TAG_compile_unit
21472 2: DW_TAG_namespace // N
21473 3: DW_TAG_subprogram // declaration of N::foo
21474 4: DW_TAG_subprogram // definition of N::foo
21475 DW_AT_specification // refers to die #3
21477 Thus, when processing die #4, we have to pretend that we're in
21478 the context of its DW_AT_specification, namely the contex of die
21481 spec_die
= die_specification (die
, &spec_cu
);
21482 if (spec_die
== NULL
)
21483 parent
= die
->parent
;
21486 parent
= spec_die
->parent
;
21490 if (parent
== NULL
)
21492 else if (parent
->building_fullname
)
21495 const char *parent_name
;
21497 /* It has been seen on RealView 2.2 built binaries,
21498 DW_TAG_template_type_param types actually _defined_ as
21499 children of the parent class:
21502 template class <class Enum> Class{};
21503 Class<enum E> class_e;
21505 1: DW_TAG_class_type (Class)
21506 2: DW_TAG_enumeration_type (E)
21507 3: DW_TAG_enumerator (enum1:0)
21508 3: DW_TAG_enumerator (enum2:1)
21510 2: DW_TAG_template_type_param
21511 DW_AT_type DW_FORM_ref_udata (E)
21513 Besides being broken debug info, it can put GDB into an
21514 infinite loop. Consider:
21516 When we're building the full name for Class<E>, we'll start
21517 at Class, and go look over its template type parameters,
21518 finding E. We'll then try to build the full name of E, and
21519 reach here. We're now trying to build the full name of E,
21520 and look over the parent DIE for containing scope. In the
21521 broken case, if we followed the parent DIE of E, we'd again
21522 find Class, and once again go look at its template type
21523 arguments, etc., etc. Simply don't consider such parent die
21524 as source-level parent of this die (it can't be, the language
21525 doesn't allow it), and break the loop here. */
21526 name
= dwarf2_name (die
, cu
);
21527 parent_name
= dwarf2_name (parent
, cu
);
21528 complaint (_("template param type '%s' defined within parent '%s'"),
21529 name
? name
: "<unknown>",
21530 parent_name
? parent_name
: "<unknown>");
21534 switch (parent
->tag
)
21536 case DW_TAG_namespace
:
21537 parent_type
= read_type_die (parent
, cu
);
21538 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21539 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21540 Work around this problem here. */
21541 if (cu
->language
== language_cplus
21542 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21544 /* We give a name to even anonymous namespaces. */
21545 return TYPE_NAME (parent_type
);
21546 case DW_TAG_class_type
:
21547 case DW_TAG_interface_type
:
21548 case DW_TAG_structure_type
:
21549 case DW_TAG_union_type
:
21550 case DW_TAG_module
:
21551 parent_type
= read_type_die (parent
, cu
);
21552 if (TYPE_NAME (parent_type
) != NULL
)
21553 return TYPE_NAME (parent_type
);
21555 /* An anonymous structure is only allowed non-static data
21556 members; no typedefs, no member functions, et cetera.
21557 So it does not need a prefix. */
21559 case DW_TAG_compile_unit
:
21560 case DW_TAG_partial_unit
:
21561 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21562 if (cu
->language
== language_cplus
21563 && !dwarf2_per_objfile
->types
.empty ()
21564 && die
->child
!= NULL
21565 && (die
->tag
== DW_TAG_class_type
21566 || die
->tag
== DW_TAG_structure_type
21567 || die
->tag
== DW_TAG_union_type
))
21569 const char *name
= guess_full_die_structure_name (die
, cu
);
21574 case DW_TAG_subprogram
:
21575 /* Nested subroutines in Fortran get a prefix with the name
21576 of the parent's subroutine. */
21577 if (cu
->language
== language_fortran
)
21579 if ((die
->tag
== DW_TAG_subprogram
)
21580 && (dwarf2_name (parent
, cu
) != NULL
))
21581 return dwarf2_name (parent
, cu
);
21583 return determine_prefix (parent
, cu
);
21584 case DW_TAG_enumeration_type
:
21585 parent_type
= read_type_die (parent
, cu
);
21586 if (TYPE_DECLARED_CLASS (parent_type
))
21588 if (TYPE_NAME (parent_type
) != NULL
)
21589 return TYPE_NAME (parent_type
);
21592 /* Fall through. */
21594 return determine_prefix (parent
, cu
);
21598 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21599 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21600 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21601 an obconcat, otherwise allocate storage for the result. The CU argument is
21602 used to determine the language and hence, the appropriate separator. */
21604 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21607 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21608 int physname
, struct dwarf2_cu
*cu
)
21610 const char *lead
= "";
21613 if (suffix
== NULL
|| suffix
[0] == '\0'
21614 || prefix
== NULL
|| prefix
[0] == '\0')
21616 else if (cu
->language
== language_d
)
21618 /* For D, the 'main' function could be defined in any module, but it
21619 should never be prefixed. */
21620 if (strcmp (suffix
, "D main") == 0)
21628 else if (cu
->language
== language_fortran
&& physname
)
21630 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21631 DW_AT_MIPS_linkage_name is preferred and used instead. */
21639 if (prefix
== NULL
)
21641 if (suffix
== NULL
)
21648 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21650 strcpy (retval
, lead
);
21651 strcat (retval
, prefix
);
21652 strcat (retval
, sep
);
21653 strcat (retval
, suffix
);
21658 /* We have an obstack. */
21659 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21663 /* Return sibling of die, NULL if no sibling. */
21665 static struct die_info
*
21666 sibling_die (struct die_info
*die
)
21668 return die
->sibling
;
21671 /* Get name of a die, return NULL if not found. */
21673 static const char *
21674 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21675 struct obstack
*obstack
)
21677 if (name
&& cu
->language
== language_cplus
)
21679 std::string canon_name
= cp_canonicalize_string (name
);
21681 if (!canon_name
.empty ())
21683 if (canon_name
!= name
)
21684 name
= obstack_strdup (obstack
, canon_name
);
21691 /* Get name of a die, return NULL if not found.
21692 Anonymous namespaces are converted to their magic string. */
21694 static const char *
21695 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21697 struct attribute
*attr
;
21698 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21700 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21701 if ((!attr
|| !DW_STRING (attr
))
21702 && die
->tag
!= DW_TAG_namespace
21703 && die
->tag
!= DW_TAG_class_type
21704 && die
->tag
!= DW_TAG_interface_type
21705 && die
->tag
!= DW_TAG_structure_type
21706 && die
->tag
!= DW_TAG_union_type
)
21711 case DW_TAG_compile_unit
:
21712 case DW_TAG_partial_unit
:
21713 /* Compilation units have a DW_AT_name that is a filename, not
21714 a source language identifier. */
21715 case DW_TAG_enumeration_type
:
21716 case DW_TAG_enumerator
:
21717 /* These tags always have simple identifiers already; no need
21718 to canonicalize them. */
21719 return DW_STRING (attr
);
21721 case DW_TAG_namespace
:
21722 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21723 return DW_STRING (attr
);
21724 return CP_ANONYMOUS_NAMESPACE_STR
;
21726 case DW_TAG_class_type
:
21727 case DW_TAG_interface_type
:
21728 case DW_TAG_structure_type
:
21729 case DW_TAG_union_type
:
21730 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21731 structures or unions. These were of the form "._%d" in GCC 4.1,
21732 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21733 and GCC 4.4. We work around this problem by ignoring these. */
21734 if (attr
&& DW_STRING (attr
)
21735 && (startswith (DW_STRING (attr
), "._")
21736 || startswith (DW_STRING (attr
), "<anonymous")))
21739 /* GCC might emit a nameless typedef that has a linkage name. See
21740 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21741 if (!attr
|| DW_STRING (attr
) == NULL
)
21743 attr
= dw2_linkage_name_attr (die
, cu
);
21744 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21747 /* Avoid demangling DW_STRING (attr) the second time on a second
21748 call for the same DIE. */
21749 if (!DW_STRING_IS_CANONICAL (attr
))
21751 gdb::unique_xmalloc_ptr
<char> demangled
21752 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21753 if (demangled
== nullptr)
21758 /* FIXME: we already did this for the partial symbol... */
21760 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
21762 DW_STRING_IS_CANONICAL (attr
) = 1;
21764 /* Strip any leading namespaces/classes, keep only the base name.
21765 DW_AT_name for named DIEs does not contain the prefixes. */
21766 base
= strrchr (DW_STRING (attr
), ':');
21767 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21770 return DW_STRING (attr
);
21779 if (!DW_STRING_IS_CANONICAL (attr
))
21782 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21783 &objfile
->per_bfd
->storage_obstack
);
21784 DW_STRING_IS_CANONICAL (attr
) = 1;
21786 return DW_STRING (attr
);
21789 /* Return the die that this die in an extension of, or NULL if there
21790 is none. *EXT_CU is the CU containing DIE on input, and the CU
21791 containing the return value on output. */
21793 static struct die_info
*
21794 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21796 struct attribute
*attr
;
21798 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21802 return follow_die_ref (die
, attr
, ext_cu
);
21805 /* A convenience function that returns an "unknown" DWARF name,
21806 including the value of V. STR is the name of the entity being
21807 printed, e.g., "TAG". */
21809 static const char *
21810 dwarf_unknown (const char *str
, unsigned v
)
21812 char *cell
= get_print_cell ();
21813 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21817 /* Convert a DIE tag into its string name. */
21819 static const char *
21820 dwarf_tag_name (unsigned tag
)
21822 const char *name
= get_DW_TAG_name (tag
);
21825 return dwarf_unknown ("TAG", tag
);
21830 /* Convert a DWARF attribute code into its string name. */
21832 static const char *
21833 dwarf_attr_name (unsigned attr
)
21837 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21838 if (attr
== DW_AT_MIPS_fde
)
21839 return "DW_AT_MIPS_fde";
21841 if (attr
== DW_AT_HP_block_index
)
21842 return "DW_AT_HP_block_index";
21845 name
= get_DW_AT_name (attr
);
21848 return dwarf_unknown ("AT", attr
);
21853 /* Convert a DWARF value form code into its string name. */
21855 static const char *
21856 dwarf_form_name (unsigned form
)
21858 const char *name
= get_DW_FORM_name (form
);
21861 return dwarf_unknown ("FORM", form
);
21866 static const char *
21867 dwarf_bool_name (unsigned mybool
)
21875 /* Convert a DWARF type code into its string name. */
21877 static const char *
21878 dwarf_type_encoding_name (unsigned enc
)
21880 const char *name
= get_DW_ATE_name (enc
);
21883 return dwarf_unknown ("ATE", enc
);
21889 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21893 print_spaces (indent
, f
);
21894 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21895 dwarf_tag_name (die
->tag
), die
->abbrev
,
21896 sect_offset_str (die
->sect_off
));
21898 if (die
->parent
!= NULL
)
21900 print_spaces (indent
, f
);
21901 fprintf_unfiltered (f
, " parent at offset: %s\n",
21902 sect_offset_str (die
->parent
->sect_off
));
21905 print_spaces (indent
, f
);
21906 fprintf_unfiltered (f
, " has children: %s\n",
21907 dwarf_bool_name (die
->child
!= NULL
));
21909 print_spaces (indent
, f
);
21910 fprintf_unfiltered (f
, " attributes:\n");
21912 for (i
= 0; i
< die
->num_attrs
; ++i
)
21914 print_spaces (indent
, f
);
21915 fprintf_unfiltered (f
, " %s (%s) ",
21916 dwarf_attr_name (die
->attrs
[i
].name
),
21917 dwarf_form_name (die
->attrs
[i
].form
));
21919 switch (die
->attrs
[i
].form
)
21922 case DW_FORM_addrx
:
21923 case DW_FORM_GNU_addr_index
:
21924 fprintf_unfiltered (f
, "address: ");
21925 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21927 case DW_FORM_block2
:
21928 case DW_FORM_block4
:
21929 case DW_FORM_block
:
21930 case DW_FORM_block1
:
21931 fprintf_unfiltered (f
, "block: size %s",
21932 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21934 case DW_FORM_exprloc
:
21935 fprintf_unfiltered (f
, "expression: size %s",
21936 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21938 case DW_FORM_data16
:
21939 fprintf_unfiltered (f
, "constant of 16 bytes");
21941 case DW_FORM_ref_addr
:
21942 fprintf_unfiltered (f
, "ref address: ");
21943 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21945 case DW_FORM_GNU_ref_alt
:
21946 fprintf_unfiltered (f
, "alt ref address: ");
21947 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21953 case DW_FORM_ref_udata
:
21954 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21955 (long) (DW_UNSND (&die
->attrs
[i
])));
21957 case DW_FORM_data1
:
21958 case DW_FORM_data2
:
21959 case DW_FORM_data4
:
21960 case DW_FORM_data8
:
21961 case DW_FORM_udata
:
21962 case DW_FORM_sdata
:
21963 fprintf_unfiltered (f
, "constant: %s",
21964 pulongest (DW_UNSND (&die
->attrs
[i
])));
21966 case DW_FORM_sec_offset
:
21967 fprintf_unfiltered (f
, "section offset: %s",
21968 pulongest (DW_UNSND (&die
->attrs
[i
])));
21970 case DW_FORM_ref_sig8
:
21971 fprintf_unfiltered (f
, "signature: %s",
21972 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21974 case DW_FORM_string
:
21976 case DW_FORM_line_strp
:
21978 case DW_FORM_GNU_str_index
:
21979 case DW_FORM_GNU_strp_alt
:
21980 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21981 DW_STRING (&die
->attrs
[i
])
21982 ? DW_STRING (&die
->attrs
[i
]) : "",
21983 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21986 if (DW_UNSND (&die
->attrs
[i
]))
21987 fprintf_unfiltered (f
, "flag: TRUE");
21989 fprintf_unfiltered (f
, "flag: FALSE");
21991 case DW_FORM_flag_present
:
21992 fprintf_unfiltered (f
, "flag: TRUE");
21994 case DW_FORM_indirect
:
21995 /* The reader will have reduced the indirect form to
21996 the "base form" so this form should not occur. */
21997 fprintf_unfiltered (f
,
21998 "unexpected attribute form: DW_FORM_indirect");
22000 case DW_FORM_implicit_const
:
22001 fprintf_unfiltered (f
, "constant: %s",
22002 plongest (DW_SND (&die
->attrs
[i
])));
22005 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22006 die
->attrs
[i
].form
);
22009 fprintf_unfiltered (f
, "\n");
22014 dump_die_for_error (struct die_info
*die
)
22016 dump_die_shallow (gdb_stderr
, 0, die
);
22020 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22022 int indent
= level
* 4;
22024 gdb_assert (die
!= NULL
);
22026 if (level
>= max_level
)
22029 dump_die_shallow (f
, indent
, die
);
22031 if (die
->child
!= NULL
)
22033 print_spaces (indent
, f
);
22034 fprintf_unfiltered (f
, " Children:");
22035 if (level
+ 1 < max_level
)
22037 fprintf_unfiltered (f
, "\n");
22038 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22042 fprintf_unfiltered (f
,
22043 " [not printed, max nesting level reached]\n");
22047 if (die
->sibling
!= NULL
&& level
> 0)
22049 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22053 /* This is called from the pdie macro in gdbinit.in.
22054 It's not static so gcc will keep a copy callable from gdb. */
22057 dump_die (struct die_info
*die
, int max_level
)
22059 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22063 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22067 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22068 to_underlying (die
->sect_off
),
22074 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22078 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22080 if (attr
->form_is_ref ())
22081 return (sect_offset
) DW_UNSND (attr
);
22083 complaint (_("unsupported die ref attribute form: '%s'"),
22084 dwarf_form_name (attr
->form
));
22088 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22089 * the value held by the attribute is not constant. */
22092 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22094 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22095 return DW_SND (attr
);
22096 else if (attr
->form
== DW_FORM_udata
22097 || attr
->form
== DW_FORM_data1
22098 || attr
->form
== DW_FORM_data2
22099 || attr
->form
== DW_FORM_data4
22100 || attr
->form
== DW_FORM_data8
)
22101 return DW_UNSND (attr
);
22104 /* For DW_FORM_data16 see attribute::form_is_constant. */
22105 complaint (_("Attribute value is not a constant (%s)"),
22106 dwarf_form_name (attr
->form
));
22107 return default_value
;
22111 /* Follow reference or signature attribute ATTR of SRC_DIE.
22112 On entry *REF_CU is the CU of SRC_DIE.
22113 On exit *REF_CU is the CU of the result. */
22115 static struct die_info
*
22116 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22117 struct dwarf2_cu
**ref_cu
)
22119 struct die_info
*die
;
22121 if (attr
->form_is_ref ())
22122 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22123 else if (attr
->form
== DW_FORM_ref_sig8
)
22124 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22127 dump_die_for_error (src_die
);
22128 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22129 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22135 /* Follow reference OFFSET.
22136 On entry *REF_CU is the CU of the source die referencing OFFSET.
22137 On exit *REF_CU is the CU of the result.
22138 Returns NULL if OFFSET is invalid. */
22140 static struct die_info
*
22141 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22142 struct dwarf2_cu
**ref_cu
)
22144 struct die_info temp_die
;
22145 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22146 struct dwarf2_per_objfile
*dwarf2_per_objfile
22147 = cu
->per_cu
->dwarf2_per_objfile
;
22149 gdb_assert (cu
->per_cu
!= NULL
);
22153 if (cu
->per_cu
->is_debug_types
)
22155 /* .debug_types CUs cannot reference anything outside their CU.
22156 If they need to, they have to reference a signatured type via
22157 DW_FORM_ref_sig8. */
22158 if (!cu
->header
.offset_in_cu_p (sect_off
))
22161 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22162 || !cu
->header
.offset_in_cu_p (sect_off
))
22164 struct dwarf2_per_cu_data
*per_cu
;
22166 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22167 dwarf2_per_objfile
);
22169 /* If necessary, add it to the queue and load its DIEs. */
22170 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22171 load_full_comp_unit (per_cu
, false, cu
->language
);
22173 target_cu
= per_cu
->cu
;
22175 else if (cu
->dies
== NULL
)
22177 /* We're loading full DIEs during partial symbol reading. */
22178 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22179 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22182 *ref_cu
= target_cu
;
22183 temp_die
.sect_off
= sect_off
;
22185 if (target_cu
!= cu
)
22186 target_cu
->ancestor
= cu
;
22188 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22190 to_underlying (sect_off
));
22193 /* Follow reference attribute ATTR of SRC_DIE.
22194 On entry *REF_CU is the CU of SRC_DIE.
22195 On exit *REF_CU is the CU of the result. */
22197 static struct die_info
*
22198 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22199 struct dwarf2_cu
**ref_cu
)
22201 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22202 struct dwarf2_cu
*cu
= *ref_cu
;
22203 struct die_info
*die
;
22205 die
= follow_die_offset (sect_off
,
22206 (attr
->form
== DW_FORM_GNU_ref_alt
22207 || cu
->per_cu
->is_dwz
),
22210 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22211 "at %s [in module %s]"),
22212 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22213 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22218 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22219 Returned value is intended for DW_OP_call*. Returned
22220 dwarf2_locexpr_baton->data has lifetime of
22221 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22223 struct dwarf2_locexpr_baton
22224 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22225 struct dwarf2_per_cu_data
*per_cu
,
22226 CORE_ADDR (*get_frame_pc
) (void *baton
),
22227 void *baton
, bool resolve_abstract_p
)
22229 struct dwarf2_cu
*cu
;
22230 struct die_info
*die
;
22231 struct attribute
*attr
;
22232 struct dwarf2_locexpr_baton retval
;
22233 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22234 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22236 if (per_cu
->cu
== NULL
)
22237 load_cu (per_cu
, false);
22241 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22242 Instead just throw an error, not much else we can do. */
22243 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22244 sect_offset_str (sect_off
), objfile_name (objfile
));
22247 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22249 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22250 sect_offset_str (sect_off
), objfile_name (objfile
));
22252 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22253 if (!attr
&& resolve_abstract_p
22254 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22255 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22257 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22258 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22259 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22261 for (const auto &cand_off
22262 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22264 struct dwarf2_cu
*cand_cu
= cu
;
22265 struct die_info
*cand
22266 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22269 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22272 CORE_ADDR pc_low
, pc_high
;
22273 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22274 if (pc_low
== ((CORE_ADDR
) -1))
22276 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22277 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22278 if (!(pc_low
<= pc
&& pc
< pc_high
))
22282 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22289 /* DWARF: "If there is no such attribute, then there is no effect.".
22290 DATA is ignored if SIZE is 0. */
22292 retval
.data
= NULL
;
22295 else if (attr
->form_is_section_offset ())
22297 struct dwarf2_loclist_baton loclist_baton
;
22298 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22301 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22303 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22305 retval
.size
= size
;
22309 if (!attr
->form_is_block ())
22310 error (_("Dwarf Error: DIE at %s referenced in module %s "
22311 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22312 sect_offset_str (sect_off
), objfile_name (objfile
));
22314 retval
.data
= DW_BLOCK (attr
)->data
;
22315 retval
.size
= DW_BLOCK (attr
)->size
;
22317 retval
.per_cu
= cu
->per_cu
;
22319 age_cached_comp_units (dwarf2_per_objfile
);
22324 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
22327 struct dwarf2_locexpr_baton
22328 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22329 struct dwarf2_per_cu_data
*per_cu
,
22330 CORE_ADDR (*get_frame_pc
) (void *baton
),
22333 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22335 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22338 /* Write a constant of a given type as target-ordered bytes into
22341 static const gdb_byte
*
22342 write_constant_as_bytes (struct obstack
*obstack
,
22343 enum bfd_endian byte_order
,
22350 *len
= TYPE_LENGTH (type
);
22351 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22352 store_unsigned_integer (result
, *len
, byte_order
, value
);
22357 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
22358 pointer to the constant bytes and set LEN to the length of the
22359 data. If memory is needed, allocate it on OBSTACK. If the DIE
22360 does not have a DW_AT_const_value, return NULL. */
22363 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22364 struct dwarf2_per_cu_data
*per_cu
,
22365 struct obstack
*obstack
,
22368 struct dwarf2_cu
*cu
;
22369 struct die_info
*die
;
22370 struct attribute
*attr
;
22371 const gdb_byte
*result
= NULL
;
22374 enum bfd_endian byte_order
;
22375 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22377 if (per_cu
->cu
== NULL
)
22378 load_cu (per_cu
, false);
22382 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22383 Instead just throw an error, not much else we can do. */
22384 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22385 sect_offset_str (sect_off
), objfile_name (objfile
));
22388 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22390 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22391 sect_offset_str (sect_off
), objfile_name (objfile
));
22393 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22397 byte_order
= (bfd_big_endian (objfile
->obfd
)
22398 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22400 switch (attr
->form
)
22403 case DW_FORM_addrx
:
22404 case DW_FORM_GNU_addr_index
:
22408 *len
= cu
->header
.addr_size
;
22409 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22410 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22414 case DW_FORM_string
:
22417 case DW_FORM_GNU_str_index
:
22418 case DW_FORM_GNU_strp_alt
:
22419 /* DW_STRING is already allocated on the objfile obstack, point
22421 result
= (const gdb_byte
*) DW_STRING (attr
);
22422 *len
= strlen (DW_STRING (attr
));
22424 case DW_FORM_block1
:
22425 case DW_FORM_block2
:
22426 case DW_FORM_block4
:
22427 case DW_FORM_block
:
22428 case DW_FORM_exprloc
:
22429 case DW_FORM_data16
:
22430 result
= DW_BLOCK (attr
)->data
;
22431 *len
= DW_BLOCK (attr
)->size
;
22434 /* The DW_AT_const_value attributes are supposed to carry the
22435 symbol's value "represented as it would be on the target
22436 architecture." By the time we get here, it's already been
22437 converted to host endianness, so we just need to sign- or
22438 zero-extend it as appropriate. */
22439 case DW_FORM_data1
:
22440 type
= die_type (die
, cu
);
22441 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22442 if (result
== NULL
)
22443 result
= write_constant_as_bytes (obstack
, byte_order
,
22446 case DW_FORM_data2
:
22447 type
= die_type (die
, cu
);
22448 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22449 if (result
== NULL
)
22450 result
= write_constant_as_bytes (obstack
, byte_order
,
22453 case DW_FORM_data4
:
22454 type
= die_type (die
, cu
);
22455 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22456 if (result
== NULL
)
22457 result
= write_constant_as_bytes (obstack
, byte_order
,
22460 case DW_FORM_data8
:
22461 type
= die_type (die
, cu
);
22462 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22463 if (result
== NULL
)
22464 result
= write_constant_as_bytes (obstack
, byte_order
,
22468 case DW_FORM_sdata
:
22469 case DW_FORM_implicit_const
:
22470 type
= die_type (die
, cu
);
22471 result
= write_constant_as_bytes (obstack
, byte_order
,
22472 type
, DW_SND (attr
), len
);
22475 case DW_FORM_udata
:
22476 type
= die_type (die
, cu
);
22477 result
= write_constant_as_bytes (obstack
, byte_order
,
22478 type
, DW_UNSND (attr
), len
);
22482 complaint (_("unsupported const value attribute form: '%s'"),
22483 dwarf_form_name (attr
->form
));
22490 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
22491 valid type for this die is found. */
22494 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22495 struct dwarf2_per_cu_data
*per_cu
)
22497 struct dwarf2_cu
*cu
;
22498 struct die_info
*die
;
22500 if (per_cu
->cu
== NULL
)
22501 load_cu (per_cu
, false);
22506 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22510 return die_type (die
, cu
);
22513 /* Return the type of the DIE at DIE_OFFSET in the CU named by
22517 dwarf2_get_die_type (cu_offset die_offset
,
22518 struct dwarf2_per_cu_data
*per_cu
)
22520 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22521 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22524 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22525 On entry *REF_CU is the CU of SRC_DIE.
22526 On exit *REF_CU is the CU of the result.
22527 Returns NULL if the referenced DIE isn't found. */
22529 static struct die_info
*
22530 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22531 struct dwarf2_cu
**ref_cu
)
22533 struct die_info temp_die
;
22534 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22535 struct die_info
*die
;
22537 /* While it might be nice to assert sig_type->type == NULL here,
22538 we can get here for DW_AT_imported_declaration where we need
22539 the DIE not the type. */
22541 /* If necessary, add it to the queue and load its DIEs. */
22543 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22544 read_signatured_type (sig_type
);
22546 sig_cu
= sig_type
->per_cu
.cu
;
22547 gdb_assert (sig_cu
!= NULL
);
22548 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22549 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22550 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22551 to_underlying (temp_die
.sect_off
));
22554 struct dwarf2_per_objfile
*dwarf2_per_objfile
22555 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22557 /* For .gdb_index version 7 keep track of included TUs.
22558 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22559 if (dwarf2_per_objfile
->index_table
!= NULL
22560 && dwarf2_per_objfile
->index_table
->version
<= 7)
22562 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22567 sig_cu
->ancestor
= cu
;
22575 /* Follow signatured type referenced by ATTR in SRC_DIE.
22576 On entry *REF_CU is the CU of SRC_DIE.
22577 On exit *REF_CU is the CU of the result.
22578 The result is the DIE of the type.
22579 If the referenced type cannot be found an error is thrown. */
22581 static struct die_info
*
22582 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22583 struct dwarf2_cu
**ref_cu
)
22585 ULONGEST signature
= DW_SIGNATURE (attr
);
22586 struct signatured_type
*sig_type
;
22587 struct die_info
*die
;
22589 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22591 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22592 /* sig_type will be NULL if the signatured type is missing from
22594 if (sig_type
== NULL
)
22596 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22597 " from DIE at %s [in module %s]"),
22598 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22599 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22602 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22605 dump_die_for_error (src_die
);
22606 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22607 " from DIE at %s [in module %s]"),
22608 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22609 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22615 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22616 reading in and processing the type unit if necessary. */
22618 static struct type
*
22619 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22620 struct dwarf2_cu
*cu
)
22622 struct dwarf2_per_objfile
*dwarf2_per_objfile
22623 = cu
->per_cu
->dwarf2_per_objfile
;
22624 struct signatured_type
*sig_type
;
22625 struct dwarf2_cu
*type_cu
;
22626 struct die_info
*type_die
;
22629 sig_type
= lookup_signatured_type (cu
, signature
);
22630 /* sig_type will be NULL if the signatured type is missing from
22632 if (sig_type
== NULL
)
22634 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22635 " from DIE at %s [in module %s]"),
22636 hex_string (signature
), sect_offset_str (die
->sect_off
),
22637 objfile_name (dwarf2_per_objfile
->objfile
));
22638 return build_error_marker_type (cu
, die
);
22641 /* If we already know the type we're done. */
22642 if (sig_type
->type
!= NULL
)
22643 return sig_type
->type
;
22646 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22647 if (type_die
!= NULL
)
22649 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22650 is created. This is important, for example, because for c++ classes
22651 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22652 type
= read_type_die (type_die
, type_cu
);
22655 complaint (_("Dwarf Error: Cannot build signatured type %s"
22656 " referenced from DIE at %s [in module %s]"),
22657 hex_string (signature
), sect_offset_str (die
->sect_off
),
22658 objfile_name (dwarf2_per_objfile
->objfile
));
22659 type
= build_error_marker_type (cu
, die
);
22664 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22665 " from DIE at %s [in module %s]"),
22666 hex_string (signature
), sect_offset_str (die
->sect_off
),
22667 objfile_name (dwarf2_per_objfile
->objfile
));
22668 type
= build_error_marker_type (cu
, die
);
22670 sig_type
->type
= type
;
22675 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22676 reading in and processing the type unit if necessary. */
22678 static struct type
*
22679 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22680 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22682 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22683 if (attr
->form_is_ref ())
22685 struct dwarf2_cu
*type_cu
= cu
;
22686 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22688 return read_type_die (type_die
, type_cu
);
22690 else if (attr
->form
== DW_FORM_ref_sig8
)
22692 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22696 struct dwarf2_per_objfile
*dwarf2_per_objfile
22697 = cu
->per_cu
->dwarf2_per_objfile
;
22699 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22700 " at %s [in module %s]"),
22701 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22702 objfile_name (dwarf2_per_objfile
->objfile
));
22703 return build_error_marker_type (cu
, die
);
22707 /* Load the DIEs associated with type unit PER_CU into memory. */
22710 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22712 struct signatured_type
*sig_type
;
22714 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22715 gdb_assert (! per_cu
->type_unit_group_p ());
22717 /* We have the per_cu, but we need the signatured_type.
22718 Fortunately this is an easy translation. */
22719 gdb_assert (per_cu
->is_debug_types
);
22720 sig_type
= (struct signatured_type
*) per_cu
;
22722 gdb_assert (per_cu
->cu
== NULL
);
22724 read_signatured_type (sig_type
);
22726 gdb_assert (per_cu
->cu
!= NULL
);
22729 /* Read in a signatured type and build its CU and DIEs.
22730 If the type is a stub for the real type in a DWO file,
22731 read in the real type from the DWO file as well. */
22734 read_signatured_type (struct signatured_type
*sig_type
)
22736 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22738 gdb_assert (per_cu
->is_debug_types
);
22739 gdb_assert (per_cu
->cu
== NULL
);
22741 cutu_reader
reader (per_cu
, NULL
, 0, false);
22743 if (!reader
.dummy_p
)
22745 struct dwarf2_cu
*cu
= reader
.cu
;
22746 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22748 gdb_assert (cu
->die_hash
== NULL
);
22750 htab_create_alloc_ex (cu
->header
.length
/ 12,
22754 &cu
->comp_unit_obstack
,
22755 hashtab_obstack_allocate
,
22756 dummy_obstack_deallocate
);
22758 if (reader
.comp_unit_die
->has_children
)
22759 reader
.comp_unit_die
->child
22760 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22761 reader
.comp_unit_die
);
22762 cu
->dies
= reader
.comp_unit_die
;
22763 /* comp_unit_die is not stored in die_hash, no need. */
22765 /* We try not to read any attributes in this function, because
22766 not all CUs needed for references have been loaded yet, and
22767 symbol table processing isn't initialized. But we have to
22768 set the CU language, or we won't be able to build types
22769 correctly. Similarly, if we do not read the producer, we can
22770 not apply producer-specific interpretation. */
22771 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22776 sig_type
->per_cu
.tu_read
= 1;
22779 /* Decode simple location descriptions.
22780 Given a pointer to a dwarf block that defines a location, compute
22781 the location and return the value.
22783 NOTE drow/2003-11-18: This function is called in two situations
22784 now: for the address of static or global variables (partial symbols
22785 only) and for offsets into structures which are expected to be
22786 (more or less) constant. The partial symbol case should go away,
22787 and only the constant case should remain. That will let this
22788 function complain more accurately. A few special modes are allowed
22789 without complaint for global variables (for instance, global
22790 register values and thread-local values).
22792 A location description containing no operations indicates that the
22793 object is optimized out. The return value is 0 for that case.
22794 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22795 callers will only want a very basic result and this can become a
22798 Note that stack[0] is unused except as a default error return. */
22801 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22803 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22805 size_t size
= blk
->size
;
22806 const gdb_byte
*data
= blk
->data
;
22807 CORE_ADDR stack
[64];
22809 unsigned int bytes_read
, unsnd
;
22815 stack
[++stacki
] = 0;
22854 stack
[++stacki
] = op
- DW_OP_lit0
;
22889 stack
[++stacki
] = op
- DW_OP_reg0
;
22891 dwarf2_complex_location_expr_complaint ();
22895 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22897 stack
[++stacki
] = unsnd
;
22899 dwarf2_complex_location_expr_complaint ();
22903 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22908 case DW_OP_const1u
:
22909 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22913 case DW_OP_const1s
:
22914 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22918 case DW_OP_const2u
:
22919 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22923 case DW_OP_const2s
:
22924 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22928 case DW_OP_const4u
:
22929 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22933 case DW_OP_const4s
:
22934 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22938 case DW_OP_const8u
:
22939 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22944 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22950 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22955 stack
[stacki
+ 1] = stack
[stacki
];
22960 stack
[stacki
- 1] += stack
[stacki
];
22964 case DW_OP_plus_uconst
:
22965 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22971 stack
[stacki
- 1] -= stack
[stacki
];
22976 /* If we're not the last op, then we definitely can't encode
22977 this using GDB's address_class enum. This is valid for partial
22978 global symbols, although the variable's address will be bogus
22981 dwarf2_complex_location_expr_complaint ();
22984 case DW_OP_GNU_push_tls_address
:
22985 case DW_OP_form_tls_address
:
22986 /* The top of the stack has the offset from the beginning
22987 of the thread control block at which the variable is located. */
22988 /* Nothing should follow this operator, so the top of stack would
22990 /* This is valid for partial global symbols, but the variable's
22991 address will be bogus in the psymtab. Make it always at least
22992 non-zero to not look as a variable garbage collected by linker
22993 which have DW_OP_addr 0. */
22995 dwarf2_complex_location_expr_complaint ();
22999 case DW_OP_GNU_uninit
:
23003 case DW_OP_GNU_addr_index
:
23004 case DW_OP_GNU_const_index
:
23005 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23012 const char *name
= get_DW_OP_name (op
);
23015 complaint (_("unsupported stack op: '%s'"),
23018 complaint (_("unsupported stack op: '%02x'"),
23022 return (stack
[stacki
]);
23025 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23026 outside of the allocated space. Also enforce minimum>0. */
23027 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23029 complaint (_("location description stack overflow"));
23035 complaint (_("location description stack underflow"));
23039 return (stack
[stacki
]);
23042 /* memory allocation interface */
23044 static struct dwarf_block
*
23045 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23047 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23050 static struct die_info
*
23051 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23053 struct die_info
*die
;
23054 size_t size
= sizeof (struct die_info
);
23057 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23059 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23060 memset (die
, 0, sizeof (struct die_info
));
23065 /* Macro support. */
23067 static struct macro_source_file
*
23068 macro_start_file (struct dwarf2_cu
*cu
,
23069 int file
, int line
,
23070 struct macro_source_file
*current_file
,
23071 struct line_header
*lh
)
23073 /* File name relative to the compilation directory of this source file. */
23074 gdb::unique_xmalloc_ptr
<char> file_name
= lh
->file_file_name (file
);
23076 if (! current_file
)
23078 /* Note: We don't create a macro table for this compilation unit
23079 at all until we actually get a filename. */
23080 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23082 /* If we have no current file, then this must be the start_file
23083 directive for the compilation unit's main source file. */
23084 current_file
= macro_set_main (macro_table
, file_name
.get ());
23085 macro_define_special (macro_table
);
23088 current_file
= macro_include (current_file
, line
, file_name
.get ());
23090 return current_file
;
23093 static const char *
23094 consume_improper_spaces (const char *p
, const char *body
)
23098 complaint (_("macro definition contains spaces "
23099 "in formal argument list:\n`%s'"),
23111 parse_macro_definition (struct macro_source_file
*file
, int line
,
23116 /* The body string takes one of two forms. For object-like macro
23117 definitions, it should be:
23119 <macro name> " " <definition>
23121 For function-like macro definitions, it should be:
23123 <macro name> "() " <definition>
23125 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23127 Spaces may appear only where explicitly indicated, and in the
23130 The Dwarf 2 spec says that an object-like macro's name is always
23131 followed by a space, but versions of GCC around March 2002 omit
23132 the space when the macro's definition is the empty string.
23134 The Dwarf 2 spec says that there should be no spaces between the
23135 formal arguments in a function-like macro's formal argument list,
23136 but versions of GCC around March 2002 include spaces after the
23140 /* Find the extent of the macro name. The macro name is terminated
23141 by either a space or null character (for an object-like macro) or
23142 an opening paren (for a function-like macro). */
23143 for (p
= body
; *p
; p
++)
23144 if (*p
== ' ' || *p
== '(')
23147 if (*p
== ' ' || *p
== '\0')
23149 /* It's an object-like macro. */
23150 int name_len
= p
- body
;
23151 std::string
name (body
, name_len
);
23152 const char *replacement
;
23155 replacement
= body
+ name_len
+ 1;
23158 dwarf2_macro_malformed_definition_complaint (body
);
23159 replacement
= body
+ name_len
;
23162 macro_define_object (file
, line
, name
.c_str (), replacement
);
23164 else if (*p
== '(')
23166 /* It's a function-like macro. */
23167 std::string
name (body
, p
- body
);
23170 char **argv
= XNEWVEC (char *, argv_size
);
23174 p
= consume_improper_spaces (p
, body
);
23176 /* Parse the formal argument list. */
23177 while (*p
&& *p
!= ')')
23179 /* Find the extent of the current argument name. */
23180 const char *arg_start
= p
;
23182 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23185 if (! *p
|| p
== arg_start
)
23186 dwarf2_macro_malformed_definition_complaint (body
);
23189 /* Make sure argv has room for the new argument. */
23190 if (argc
>= argv_size
)
23193 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23196 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23199 p
= consume_improper_spaces (p
, body
);
23201 /* Consume the comma, if present. */
23206 p
= consume_improper_spaces (p
, body
);
23215 /* Perfectly formed definition, no complaints. */
23216 macro_define_function (file
, line
, name
.c_str (),
23217 argc
, (const char **) argv
,
23219 else if (*p
== '\0')
23221 /* Complain, but do define it. */
23222 dwarf2_macro_malformed_definition_complaint (body
);
23223 macro_define_function (file
, line
, name
.c_str (),
23224 argc
, (const char **) argv
,
23228 /* Just complain. */
23229 dwarf2_macro_malformed_definition_complaint (body
);
23232 /* Just complain. */
23233 dwarf2_macro_malformed_definition_complaint (body
);
23238 for (i
= 0; i
< argc
; i
++)
23244 dwarf2_macro_malformed_definition_complaint (body
);
23247 /* Skip some bytes from BYTES according to the form given in FORM.
23248 Returns the new pointer. */
23250 static const gdb_byte
*
23251 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23252 enum dwarf_form form
,
23253 unsigned int offset_size
,
23254 struct dwarf2_section_info
*section
)
23256 unsigned int bytes_read
;
23260 case DW_FORM_data1
:
23265 case DW_FORM_data2
:
23269 case DW_FORM_data4
:
23273 case DW_FORM_data8
:
23277 case DW_FORM_data16
:
23281 case DW_FORM_string
:
23282 read_direct_string (abfd
, bytes
, &bytes_read
);
23283 bytes
+= bytes_read
;
23286 case DW_FORM_sec_offset
:
23288 case DW_FORM_GNU_strp_alt
:
23289 bytes
+= offset_size
;
23292 case DW_FORM_block
:
23293 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23294 bytes
+= bytes_read
;
23297 case DW_FORM_block1
:
23298 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23300 case DW_FORM_block2
:
23301 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23303 case DW_FORM_block4
:
23304 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23307 case DW_FORM_addrx
:
23308 case DW_FORM_sdata
:
23310 case DW_FORM_udata
:
23311 case DW_FORM_GNU_addr_index
:
23312 case DW_FORM_GNU_str_index
:
23313 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23316 dwarf2_section_buffer_overflow_complaint (section
);
23321 case DW_FORM_implicit_const
:
23326 complaint (_("invalid form 0x%x in `%s'"),
23327 form
, section
->get_name ());
23335 /* A helper for dwarf_decode_macros that handles skipping an unknown
23336 opcode. Returns an updated pointer to the macro data buffer; or,
23337 on error, issues a complaint and returns NULL. */
23339 static const gdb_byte
*
23340 skip_unknown_opcode (unsigned int opcode
,
23341 const gdb_byte
**opcode_definitions
,
23342 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23344 unsigned int offset_size
,
23345 struct dwarf2_section_info
*section
)
23347 unsigned int bytes_read
, i
;
23349 const gdb_byte
*defn
;
23351 if (opcode_definitions
[opcode
] == NULL
)
23353 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
23358 defn
= opcode_definitions
[opcode
];
23359 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
23360 defn
+= bytes_read
;
23362 for (i
= 0; i
< arg
; ++i
)
23364 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
23365 (enum dwarf_form
) defn
[i
], offset_size
,
23367 if (mac_ptr
== NULL
)
23369 /* skip_form_bytes already issued the complaint. */
23377 /* A helper function which parses the header of a macro section.
23378 If the macro section is the extended (for now called "GNU") type,
23379 then this updates *OFFSET_SIZE. Returns a pointer to just after
23380 the header, or issues a complaint and returns NULL on error. */
23382 static const gdb_byte
*
23383 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
23385 const gdb_byte
*mac_ptr
,
23386 unsigned int *offset_size
,
23387 int section_is_gnu
)
23389 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
23391 if (section_is_gnu
)
23393 unsigned int version
, flags
;
23395 version
= read_2_bytes (abfd
, mac_ptr
);
23396 if (version
!= 4 && version
!= 5)
23398 complaint (_("unrecognized version `%d' in .debug_macro section"),
23404 flags
= read_1_byte (abfd
, mac_ptr
);
23406 *offset_size
= (flags
& 1) ? 8 : 4;
23408 if ((flags
& 2) != 0)
23409 /* We don't need the line table offset. */
23410 mac_ptr
+= *offset_size
;
23412 /* Vendor opcode descriptions. */
23413 if ((flags
& 4) != 0)
23415 unsigned int i
, count
;
23417 count
= read_1_byte (abfd
, mac_ptr
);
23419 for (i
= 0; i
< count
; ++i
)
23421 unsigned int opcode
, bytes_read
;
23424 opcode
= read_1_byte (abfd
, mac_ptr
);
23426 opcode_definitions
[opcode
] = mac_ptr
;
23427 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23428 mac_ptr
+= bytes_read
;
23437 /* A helper for dwarf_decode_macros that handles the GNU extensions,
23438 including DW_MACRO_import. */
23441 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
23443 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23444 struct macro_source_file
*current_file
,
23445 struct line_header
*lh
,
23446 struct dwarf2_section_info
*section
,
23447 int section_is_gnu
, int section_is_dwz
,
23448 unsigned int offset_size
,
23449 htab_t include_hash
)
23451 struct dwarf2_per_objfile
*dwarf2_per_objfile
23452 = cu
->per_cu
->dwarf2_per_objfile
;
23453 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23454 enum dwarf_macro_record_type macinfo_type
;
23455 int at_commandline
;
23456 const gdb_byte
*opcode_definitions
[256];
23458 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23459 &offset_size
, section_is_gnu
);
23460 if (mac_ptr
== NULL
)
23462 /* We already issued a complaint. */
23466 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
23467 GDB is still reading the definitions from command line. First
23468 DW_MACINFO_start_file will need to be ignored as it was already executed
23469 to create CURRENT_FILE for the main source holding also the command line
23470 definitions. On first met DW_MACINFO_start_file this flag is reset to
23471 normally execute all the remaining DW_MACINFO_start_file macinfos. */
23473 at_commandline
= 1;
23477 /* Do we at least have room for a macinfo type byte? */
23478 if (mac_ptr
>= mac_end
)
23480 dwarf2_section_buffer_overflow_complaint (section
);
23484 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23487 /* Note that we rely on the fact that the corresponding GNU and
23488 DWARF constants are the same. */
23490 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23491 switch (macinfo_type
)
23493 /* A zero macinfo type indicates the end of the macro
23498 case DW_MACRO_define
:
23499 case DW_MACRO_undef
:
23500 case DW_MACRO_define_strp
:
23501 case DW_MACRO_undef_strp
:
23502 case DW_MACRO_define_sup
:
23503 case DW_MACRO_undef_sup
:
23505 unsigned int bytes_read
;
23510 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23511 mac_ptr
+= bytes_read
;
23513 if (macinfo_type
== DW_MACRO_define
23514 || macinfo_type
== DW_MACRO_undef
)
23516 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23517 mac_ptr
+= bytes_read
;
23521 LONGEST str_offset
;
23523 str_offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23524 mac_ptr
+= offset_size
;
23526 if (macinfo_type
== DW_MACRO_define_sup
23527 || macinfo_type
== DW_MACRO_undef_sup
23530 struct dwz_file
*dwz
23531 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
23533 body
= read_indirect_string_from_dwz (objfile
,
23537 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
23541 is_define
= (macinfo_type
== DW_MACRO_define
23542 || macinfo_type
== DW_MACRO_define_strp
23543 || macinfo_type
== DW_MACRO_define_sup
);
23544 if (! current_file
)
23546 /* DWARF violation as no main source is present. */
23547 complaint (_("debug info with no main source gives macro %s "
23549 is_define
? _("definition") : _("undefinition"),
23553 if ((line
== 0 && !at_commandline
)
23554 || (line
!= 0 && at_commandline
))
23555 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
23556 at_commandline
? _("command-line") : _("in-file"),
23557 is_define
? _("definition") : _("undefinition"),
23558 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
23562 /* Fedora's rpm-build's "debugedit" binary
23563 corrupted .debug_macro sections.
23566 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
23567 complaint (_("debug info gives %s invalid macro %s "
23568 "without body (corrupted?) at line %d "
23570 at_commandline
? _("command-line") : _("in-file"),
23571 is_define
? _("definition") : _("undefinition"),
23572 line
, current_file
->filename
);
23574 else if (is_define
)
23575 parse_macro_definition (current_file
, line
, body
);
23578 gdb_assert (macinfo_type
== DW_MACRO_undef
23579 || macinfo_type
== DW_MACRO_undef_strp
23580 || macinfo_type
== DW_MACRO_undef_sup
);
23581 macro_undef (current_file
, line
, body
);
23586 case DW_MACRO_start_file
:
23588 unsigned int bytes_read
;
23591 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23592 mac_ptr
+= bytes_read
;
23593 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23594 mac_ptr
+= bytes_read
;
23596 if ((line
== 0 && !at_commandline
)
23597 || (line
!= 0 && at_commandline
))
23598 complaint (_("debug info gives source %d included "
23599 "from %s at %s line %d"),
23600 file
, at_commandline
? _("command-line") : _("file"),
23601 line
== 0 ? _("zero") : _("non-zero"), line
);
23603 if (at_commandline
)
23605 /* This DW_MACRO_start_file was executed in the
23607 at_commandline
= 0;
23610 current_file
= macro_start_file (cu
, file
, line
, current_file
,
23615 case DW_MACRO_end_file
:
23616 if (! current_file
)
23617 complaint (_("macro debug info has an unmatched "
23618 "`close_file' directive"));
23621 current_file
= current_file
->included_by
;
23622 if (! current_file
)
23624 enum dwarf_macro_record_type next_type
;
23626 /* GCC circa March 2002 doesn't produce the zero
23627 type byte marking the end of the compilation
23628 unit. Complain if it's not there, but exit no
23631 /* Do we at least have room for a macinfo type byte? */
23632 if (mac_ptr
>= mac_end
)
23634 dwarf2_section_buffer_overflow_complaint (section
);
23638 /* We don't increment mac_ptr here, so this is just
23641 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
23643 if (next_type
!= 0)
23644 complaint (_("no terminating 0-type entry for "
23645 "macros in `.debug_macinfo' section"));
23652 case DW_MACRO_import
:
23653 case DW_MACRO_import_sup
:
23657 bfd
*include_bfd
= abfd
;
23658 struct dwarf2_section_info
*include_section
= section
;
23659 const gdb_byte
*include_mac_end
= mac_end
;
23660 int is_dwz
= section_is_dwz
;
23661 const gdb_byte
*new_mac_ptr
;
23663 offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23664 mac_ptr
+= offset_size
;
23666 if (macinfo_type
== DW_MACRO_import_sup
)
23668 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
23670 dwz
->macro
.read (objfile
);
23672 include_section
= &dwz
->macro
;
23673 include_bfd
= include_section
->get_bfd_owner ();
23674 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
23678 new_mac_ptr
= include_section
->buffer
+ offset
;
23679 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
23683 /* This has actually happened; see
23684 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
23685 complaint (_("recursive DW_MACRO_import in "
23686 ".debug_macro section"));
23690 *slot
= (void *) new_mac_ptr
;
23692 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
23693 include_mac_end
, current_file
, lh
,
23694 section
, section_is_gnu
, is_dwz
,
23695 offset_size
, include_hash
);
23697 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
23702 case DW_MACINFO_vendor_ext
:
23703 if (!section_is_gnu
)
23705 unsigned int bytes_read
;
23707 /* This reads the constant, but since we don't recognize
23708 any vendor extensions, we ignore it. */
23709 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23710 mac_ptr
+= bytes_read
;
23711 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23712 mac_ptr
+= bytes_read
;
23714 /* We don't recognize any vendor extensions. */
23720 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23721 mac_ptr
, mac_end
, abfd
, offset_size
,
23723 if (mac_ptr
== NULL
)
23728 } while (macinfo_type
!= 0);
23732 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23733 int section_is_gnu
)
23735 struct dwarf2_per_objfile
*dwarf2_per_objfile
23736 = cu
->per_cu
->dwarf2_per_objfile
;
23737 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23738 struct line_header
*lh
= cu
->line_header
;
23740 const gdb_byte
*mac_ptr
, *mac_end
;
23741 struct macro_source_file
*current_file
= 0;
23742 enum dwarf_macro_record_type macinfo_type
;
23743 unsigned int offset_size
= cu
->header
.offset_size
;
23744 const gdb_byte
*opcode_definitions
[256];
23746 struct dwarf2_section_info
*section
;
23747 const char *section_name
;
23749 if (cu
->dwo_unit
!= NULL
)
23751 if (section_is_gnu
)
23753 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23754 section_name
= ".debug_macro.dwo";
23758 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23759 section_name
= ".debug_macinfo.dwo";
23764 if (section_is_gnu
)
23766 section
= &dwarf2_per_objfile
->macro
;
23767 section_name
= ".debug_macro";
23771 section
= &dwarf2_per_objfile
->macinfo
;
23772 section_name
= ".debug_macinfo";
23776 section
->read (objfile
);
23777 if (section
->buffer
== NULL
)
23779 complaint (_("missing %s section"), section_name
);
23782 abfd
= section
->get_bfd_owner ();
23784 /* First pass: Find the name of the base filename.
23785 This filename is needed in order to process all macros whose definition
23786 (or undefinition) comes from the command line. These macros are defined
23787 before the first DW_MACINFO_start_file entry, and yet still need to be
23788 associated to the base file.
23790 To determine the base file name, we scan the macro definitions until we
23791 reach the first DW_MACINFO_start_file entry. We then initialize
23792 CURRENT_FILE accordingly so that any macro definition found before the
23793 first DW_MACINFO_start_file can still be associated to the base file. */
23795 mac_ptr
= section
->buffer
+ offset
;
23796 mac_end
= section
->buffer
+ section
->size
;
23798 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23799 &offset_size
, section_is_gnu
);
23800 if (mac_ptr
== NULL
)
23802 /* We already issued a complaint. */
23808 /* Do we at least have room for a macinfo type byte? */
23809 if (mac_ptr
>= mac_end
)
23811 /* Complaint is printed during the second pass as GDB will probably
23812 stop the first pass earlier upon finding
23813 DW_MACINFO_start_file. */
23817 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23820 /* Note that we rely on the fact that the corresponding GNU and
23821 DWARF constants are the same. */
23823 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23824 switch (macinfo_type
)
23826 /* A zero macinfo type indicates the end of the macro
23831 case DW_MACRO_define
:
23832 case DW_MACRO_undef
:
23833 /* Only skip the data by MAC_PTR. */
23835 unsigned int bytes_read
;
23837 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23838 mac_ptr
+= bytes_read
;
23839 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23840 mac_ptr
+= bytes_read
;
23844 case DW_MACRO_start_file
:
23846 unsigned int bytes_read
;
23849 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23850 mac_ptr
+= bytes_read
;
23851 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23852 mac_ptr
+= bytes_read
;
23854 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
23858 case DW_MACRO_end_file
:
23859 /* No data to skip by MAC_PTR. */
23862 case DW_MACRO_define_strp
:
23863 case DW_MACRO_undef_strp
:
23864 case DW_MACRO_define_sup
:
23865 case DW_MACRO_undef_sup
:
23867 unsigned int bytes_read
;
23869 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23870 mac_ptr
+= bytes_read
;
23871 mac_ptr
+= offset_size
;
23875 case DW_MACRO_import
:
23876 case DW_MACRO_import_sup
:
23877 /* Note that, according to the spec, a transparent include
23878 chain cannot call DW_MACRO_start_file. So, we can just
23879 skip this opcode. */
23880 mac_ptr
+= offset_size
;
23883 case DW_MACINFO_vendor_ext
:
23884 /* Only skip the data by MAC_PTR. */
23885 if (!section_is_gnu
)
23887 unsigned int bytes_read
;
23889 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23890 mac_ptr
+= bytes_read
;
23891 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23892 mac_ptr
+= bytes_read
;
23897 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23898 mac_ptr
, mac_end
, abfd
, offset_size
,
23900 if (mac_ptr
== NULL
)
23905 } while (macinfo_type
!= 0 && current_file
== NULL
);
23907 /* Second pass: Process all entries.
23909 Use the AT_COMMAND_LINE flag to determine whether we are still processing
23910 command-line macro definitions/undefinitions. This flag is unset when we
23911 reach the first DW_MACINFO_start_file entry. */
23913 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
23915 NULL
, xcalloc
, xfree
));
23916 mac_ptr
= section
->buffer
+ offset
;
23917 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
23918 *slot
= (void *) mac_ptr
;
23919 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
23920 current_file
, lh
, section
,
23921 section_is_gnu
, 0, offset_size
,
23922 include_hash
.get ());
23925 /* Return the .debug_loc section to use for CU.
23926 For DWO files use .debug_loc.dwo. */
23928 static struct dwarf2_section_info
*
23929 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23931 struct dwarf2_per_objfile
*dwarf2_per_objfile
23932 = cu
->per_cu
->dwarf2_per_objfile
;
23936 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23938 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23940 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23941 : &dwarf2_per_objfile
->loc
);
23944 /* A helper function that fills in a dwarf2_loclist_baton. */
23947 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23948 struct dwarf2_loclist_baton
*baton
,
23949 const struct attribute
*attr
)
23951 struct dwarf2_per_objfile
*dwarf2_per_objfile
23952 = cu
->per_cu
->dwarf2_per_objfile
;
23953 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23955 section
->read (dwarf2_per_objfile
->objfile
);
23957 baton
->per_cu
= cu
->per_cu
;
23958 gdb_assert (baton
->per_cu
);
23959 /* We don't know how long the location list is, but make sure we
23960 don't run off the edge of the section. */
23961 baton
->size
= section
->size
- DW_UNSND (attr
);
23962 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23963 baton
->base_address
= cu
->base_address
;
23964 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23968 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23969 struct dwarf2_cu
*cu
, int is_block
)
23971 struct dwarf2_per_objfile
*dwarf2_per_objfile
23972 = cu
->per_cu
->dwarf2_per_objfile
;
23973 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23974 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23976 if (attr
->form_is_section_offset ()
23977 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23978 the section. If so, fall through to the complaint in the
23980 && DW_UNSND (attr
) < section
->get_size (objfile
))
23982 struct dwarf2_loclist_baton
*baton
;
23984 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23986 fill_in_loclist_baton (cu
, baton
, attr
);
23988 if (cu
->base_known
== 0)
23989 complaint (_("Location list used without "
23990 "specifying the CU base address."));
23992 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23993 ? dwarf2_loclist_block_index
23994 : dwarf2_loclist_index
);
23995 SYMBOL_LOCATION_BATON (sym
) = baton
;
23999 struct dwarf2_locexpr_baton
*baton
;
24001 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24002 baton
->per_cu
= cu
->per_cu
;
24003 gdb_assert (baton
->per_cu
);
24005 if (attr
->form_is_block ())
24007 /* Note that we're just copying the block's data pointer
24008 here, not the actual data. We're still pointing into the
24009 info_buffer for SYM's objfile; right now we never release
24010 that buffer, but when we do clean up properly this may
24012 baton
->size
= DW_BLOCK (attr
)->size
;
24013 baton
->data
= DW_BLOCK (attr
)->data
;
24017 dwarf2_invalid_attrib_class_complaint ("location description",
24018 sym
->natural_name ());
24022 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24023 ? dwarf2_locexpr_block_index
24024 : dwarf2_locexpr_index
);
24025 SYMBOL_LOCATION_BATON (sym
) = baton
;
24032 dwarf2_per_cu_data::objfile () const
24034 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24036 /* Return the master objfile, so that we can report and look up the
24037 correct file containing this variable. */
24038 if (objfile
->separate_debug_objfile_backlink
)
24039 objfile
= objfile
->separate_debug_objfile_backlink
;
24044 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24045 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24046 CU_HEADERP first. */
24048 static const struct comp_unit_head
*
24049 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24050 const struct dwarf2_per_cu_data
*per_cu
)
24052 const gdb_byte
*info_ptr
;
24055 return &per_cu
->cu
->header
;
24057 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24059 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24060 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24061 rcuh_kind::COMPILE
);
24069 dwarf2_per_cu_data::addr_size () const
24071 struct comp_unit_head cu_header_local
;
24072 const struct comp_unit_head
*cu_headerp
;
24074 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24076 return cu_headerp
->addr_size
;
24082 dwarf2_per_cu_data::offset_size () const
24084 struct comp_unit_head cu_header_local
;
24085 const struct comp_unit_head
*cu_headerp
;
24087 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24089 return cu_headerp
->offset_size
;
24095 dwarf2_per_cu_data::ref_addr_size () const
24097 struct comp_unit_head cu_header_local
;
24098 const struct comp_unit_head
*cu_headerp
;
24100 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24102 if (cu_headerp
->version
== 2)
24103 return cu_headerp
->addr_size
;
24105 return cu_headerp
->offset_size
;
24111 dwarf2_per_cu_data::text_offset () const
24113 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24115 return objfile
->text_section_offset ();
24121 dwarf2_per_cu_data::addr_type () const
24123 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24124 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24125 struct type
*addr_type
= lookup_pointer_type (void_type
);
24126 int addr_size
= this->addr_size ();
24128 if (TYPE_LENGTH (addr_type
) == addr_size
)
24131 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
24135 /* A helper function for dwarf2_find_containing_comp_unit that returns
24136 the index of the result, and that searches a vector. It will
24137 return a result even if the offset in question does not actually
24138 occur in any CU. This is separate so that it can be unit
24142 dwarf2_find_containing_comp_unit
24143 (sect_offset sect_off
,
24144 unsigned int offset_in_dwz
,
24145 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24150 high
= all_comp_units
.size () - 1;
24153 struct dwarf2_per_cu_data
*mid_cu
;
24154 int mid
= low
+ (high
- low
) / 2;
24156 mid_cu
= all_comp_units
[mid
];
24157 if (mid_cu
->is_dwz
> offset_in_dwz
24158 || (mid_cu
->is_dwz
== offset_in_dwz
24159 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24164 gdb_assert (low
== high
);
24168 /* Locate the .debug_info compilation unit from CU's objfile which contains
24169 the DIE at OFFSET. Raises an error on failure. */
24171 static struct dwarf2_per_cu_data
*
24172 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24173 unsigned int offset_in_dwz
,
24174 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24177 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
24178 dwarf2_per_objfile
->all_comp_units
);
24179 struct dwarf2_per_cu_data
*this_cu
24180 = dwarf2_per_objfile
->all_comp_units
[low
];
24182 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24184 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24185 error (_("Dwarf Error: could not find partial DIE containing "
24186 "offset %s [in module %s]"),
24187 sect_offset_str (sect_off
),
24188 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24190 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24192 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24196 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24197 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24198 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24199 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24206 namespace selftests
{
24207 namespace find_containing_comp_unit
{
24212 struct dwarf2_per_cu_data one
{};
24213 struct dwarf2_per_cu_data two
{};
24214 struct dwarf2_per_cu_data three
{};
24215 struct dwarf2_per_cu_data four
{};
24218 two
.sect_off
= sect_offset (one
.length
);
24223 four
.sect_off
= sect_offset (three
.length
);
24227 std::vector
<dwarf2_per_cu_data
*> units
;
24228 units
.push_back (&one
);
24229 units
.push_back (&two
);
24230 units
.push_back (&three
);
24231 units
.push_back (&four
);
24235 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24236 SELF_CHECK (units
[result
] == &one
);
24237 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24238 SELF_CHECK (units
[result
] == &one
);
24239 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24240 SELF_CHECK (units
[result
] == &two
);
24242 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24243 SELF_CHECK (units
[result
] == &three
);
24244 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24245 SELF_CHECK (units
[result
] == &three
);
24246 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24247 SELF_CHECK (units
[result
] == &four
);
24253 #endif /* GDB_SELF_TEST */
24255 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24257 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24258 : per_cu (per_cu_
),
24260 has_loclist (false),
24261 checked_producer (false),
24262 producer_is_gxx_lt_4_6 (false),
24263 producer_is_gcc_lt_4_3 (false),
24264 producer_is_icc (false),
24265 producer_is_icc_lt_14 (false),
24266 producer_is_codewarrior (false),
24267 processing_has_namespace_info (false)
24272 /* Destroy a dwarf2_cu. */
24274 dwarf2_cu::~dwarf2_cu ()
24279 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24282 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24283 enum language pretend_language
)
24285 struct attribute
*attr
;
24287 /* Set the language we're debugging. */
24288 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24289 if (attr
!= nullptr)
24290 set_cu_language (DW_UNSND (attr
), cu
);
24293 cu
->language
= pretend_language
;
24294 cu
->language_defn
= language_def (cu
->language
);
24297 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24300 /* Increase the age counter on each cached compilation unit, and free
24301 any that are too old. */
24304 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24306 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24308 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24309 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24310 while (per_cu
!= NULL
)
24312 per_cu
->cu
->last_used
++;
24313 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24314 dwarf2_mark (per_cu
->cu
);
24315 per_cu
= per_cu
->cu
->read_in_chain
;
24318 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24319 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24320 while (per_cu
!= NULL
)
24322 struct dwarf2_per_cu_data
*next_cu
;
24324 next_cu
= per_cu
->cu
->read_in_chain
;
24326 if (!per_cu
->cu
->mark
)
24329 *last_chain
= next_cu
;
24332 last_chain
= &per_cu
->cu
->read_in_chain
;
24338 /* Remove a single compilation unit from the cache. */
24341 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
24343 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24344 struct dwarf2_per_objfile
*dwarf2_per_objfile
24345 = target_per_cu
->dwarf2_per_objfile
;
24347 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24348 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24349 while (per_cu
!= NULL
)
24351 struct dwarf2_per_cu_data
*next_cu
;
24353 next_cu
= per_cu
->cu
->read_in_chain
;
24355 if (per_cu
== target_per_cu
)
24359 *last_chain
= next_cu
;
24363 last_chain
= &per_cu
->cu
->read_in_chain
;
24369 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24370 We store these in a hash table separate from the DIEs, and preserve them
24371 when the DIEs are flushed out of cache.
24373 The CU "per_cu" pointer is needed because offset alone is not enough to
24374 uniquely identify the type. A file may have multiple .debug_types sections,
24375 or the type may come from a DWO file. Furthermore, while it's more logical
24376 to use per_cu->section+offset, with Fission the section with the data is in
24377 the DWO file but we don't know that section at the point we need it.
24378 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24379 because we can enter the lookup routine, get_die_type_at_offset, from
24380 outside this file, and thus won't necessarily have PER_CU->cu.
24381 Fortunately, PER_CU is stable for the life of the objfile. */
24383 struct dwarf2_per_cu_offset_and_type
24385 const struct dwarf2_per_cu_data
*per_cu
;
24386 sect_offset sect_off
;
24390 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24393 per_cu_offset_and_type_hash (const void *item
)
24395 const struct dwarf2_per_cu_offset_and_type
*ofs
24396 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24398 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24401 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24404 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24406 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24407 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24408 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24409 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24411 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24412 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24415 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24416 table if necessary. For convenience, return TYPE.
24418 The DIEs reading must have careful ordering to:
24419 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24420 reading current DIE.
24421 * Not trying to dereference contents of still incompletely read in types
24422 while reading in other DIEs.
24423 * Enable referencing still incompletely read in types just by a pointer to
24424 the type without accessing its fields.
24426 Therefore caller should follow these rules:
24427 * Try to fetch any prerequisite types we may need to build this DIE type
24428 before building the type and calling set_die_type.
24429 * After building type call set_die_type for current DIE as soon as
24430 possible before fetching more types to complete the current type.
24431 * Make the type as complete as possible before fetching more types. */
24433 static struct type
*
24434 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24436 struct dwarf2_per_objfile
*dwarf2_per_objfile
24437 = cu
->per_cu
->dwarf2_per_objfile
;
24438 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24439 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24440 struct attribute
*attr
;
24441 struct dynamic_prop prop
;
24443 /* For Ada types, make sure that the gnat-specific data is always
24444 initialized (if not already set). There are a few types where
24445 we should not be doing so, because the type-specific area is
24446 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24447 where the type-specific area is used to store the floatformat).
24448 But this is not a problem, because the gnat-specific information
24449 is actually not needed for these types. */
24450 if (need_gnat_info (cu
)
24451 && TYPE_CODE (type
) != TYPE_CODE_FUNC
24452 && TYPE_CODE (type
) != TYPE_CODE_FLT
24453 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
24454 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
24455 && TYPE_CODE (type
) != TYPE_CODE_METHOD
24456 && !HAVE_GNAT_AUX_INFO (type
))
24457 INIT_GNAT_SPECIFIC (type
);
24459 /* Read DW_AT_allocated and set in type. */
24460 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24461 if (attr
!= NULL
&& attr
->form_is_block ())
24463 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24464 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24465 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
24467 else if (attr
!= NULL
)
24469 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
24470 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24471 sect_offset_str (die
->sect_off
));
24474 /* Read DW_AT_associated and set in type. */
24475 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24476 if (attr
!= NULL
&& attr
->form_is_block ())
24478 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24479 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24480 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
24482 else if (attr
!= NULL
)
24484 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
24485 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24486 sect_offset_str (die
->sect_off
));
24489 /* Read DW_AT_data_location and set in type. */
24490 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24491 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
24492 cu
->per_cu
->addr_type ()))
24493 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
24495 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24496 dwarf2_per_objfile
->die_type_hash
24497 = htab_up (htab_create_alloc (127,
24498 per_cu_offset_and_type_hash
,
24499 per_cu_offset_and_type_eq
,
24500 NULL
, xcalloc
, xfree
));
24502 ofs
.per_cu
= cu
->per_cu
;
24503 ofs
.sect_off
= die
->sect_off
;
24505 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24506 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24508 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24509 sect_offset_str (die
->sect_off
));
24510 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24511 struct dwarf2_per_cu_offset_and_type
);
24516 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24517 or return NULL if the die does not have a saved type. */
24519 static struct type
*
24520 get_die_type_at_offset (sect_offset sect_off
,
24521 struct dwarf2_per_cu_data
*per_cu
)
24523 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24524 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
24526 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24529 ofs
.per_cu
= per_cu
;
24530 ofs
.sect_off
= sect_off
;
24531 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24532 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
24539 /* Look up the type for DIE in CU in die_type_hash,
24540 or return NULL if DIE does not have a saved type. */
24542 static struct type
*
24543 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24545 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
24548 /* Add a dependence relationship from CU to REF_PER_CU. */
24551 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24552 struct dwarf2_per_cu_data
*ref_per_cu
)
24556 if (cu
->dependencies
== NULL
)
24558 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24559 NULL
, &cu
->comp_unit_obstack
,
24560 hashtab_obstack_allocate
,
24561 dummy_obstack_deallocate
);
24563 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24565 *slot
= ref_per_cu
;
24568 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24569 Set the mark field in every compilation unit in the
24570 cache that we must keep because we are keeping CU. */
24573 dwarf2_mark_helper (void **slot
, void *data
)
24575 struct dwarf2_per_cu_data
*per_cu
;
24577 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
24579 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24580 reading of the chain. As such dependencies remain valid it is not much
24581 useful to track and undo them during QUIT cleanups. */
24582 if (per_cu
->cu
== NULL
)
24585 if (per_cu
->cu
->mark
)
24587 per_cu
->cu
->mark
= true;
24589 if (per_cu
->cu
->dependencies
!= NULL
)
24590 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24595 /* Set the mark field in CU and in every other compilation unit in the
24596 cache that we must keep because we are keeping CU. */
24599 dwarf2_mark (struct dwarf2_cu
*cu
)
24604 if (cu
->dependencies
!= NULL
)
24605 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24609 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
24613 per_cu
->cu
->mark
= false;
24614 per_cu
= per_cu
->cu
->read_in_chain
;
24618 /* Trivial hash function for partial_die_info: the hash value of a DIE
24619 is its offset in .debug_info for this objfile. */
24622 partial_die_hash (const void *item
)
24624 const struct partial_die_info
*part_die
24625 = (const struct partial_die_info
*) item
;
24627 return to_underlying (part_die
->sect_off
);
24630 /* Trivial comparison function for partial_die_info structures: two DIEs
24631 are equal if they have the same offset. */
24634 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24636 const struct partial_die_info
*part_die_lhs
24637 = (const struct partial_die_info
*) item_lhs
;
24638 const struct partial_die_info
*part_die_rhs
24639 = (const struct partial_die_info
*) item_rhs
;
24641 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24644 struct cmd_list_element
*set_dwarf_cmdlist
;
24645 struct cmd_list_element
*show_dwarf_cmdlist
;
24648 set_dwarf_cmd (const char *args
, int from_tty
)
24650 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
24655 show_dwarf_cmd (const char *args
, int from_tty
)
24657 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
24661 show_check_physname (struct ui_file
*file
, int from_tty
,
24662 struct cmd_list_element
*c
, const char *value
)
24664 fprintf_filtered (file
,
24665 _("Whether to check \"physname\" is %s.\n"),
24669 void _initialize_dwarf2_read ();
24671 _initialize_dwarf2_read ()
24673 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24674 Set DWARF specific variables.\n\
24675 Configure DWARF variables such as the cache size."),
24676 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24677 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24679 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24680 Show DWARF specific variables.\n\
24681 Show DWARF variables such as the cache size."),
24682 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24683 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24685 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24686 &dwarf_max_cache_age
, _("\
24687 Set the upper bound on the age of cached DWARF compilation units."), _("\
24688 Show the upper bound on the age of cached DWARF compilation units."), _("\
24689 A higher limit means that cached compilation units will be stored\n\
24690 in memory longer, and more total memory will be used. Zero disables\n\
24691 caching, which can slow down startup."),
24693 show_dwarf_max_cache_age
,
24694 &set_dwarf_cmdlist
,
24695 &show_dwarf_cmdlist
);
24697 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24698 Set debugging of the DWARF reader."), _("\
24699 Show debugging of the DWARF reader."), _("\
24700 When enabled (non-zero), debugging messages are printed during DWARF\n\
24701 reading and symtab expansion. A value of 1 (one) provides basic\n\
24702 information. A value greater than 1 provides more verbose information."),
24705 &setdebuglist
, &showdebuglist
);
24707 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24708 Set debugging of the DWARF DIE reader."), _("\
24709 Show debugging of the DWARF DIE reader."), _("\
24710 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24711 The value is the maximum depth to print."),
24714 &setdebuglist
, &showdebuglist
);
24716 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24717 Set debugging of the dwarf line reader."), _("\
24718 Show debugging of the dwarf line reader."), _("\
24719 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24720 A value of 1 (one) provides basic information.\n\
24721 A value greater than 1 provides more verbose information."),
24724 &setdebuglist
, &showdebuglist
);
24726 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24727 Set cross-checking of \"physname\" code against demangler."), _("\
24728 Show cross-checking of \"physname\" code against demangler."), _("\
24729 When enabled, GDB's internal \"physname\" code is checked against\n\
24731 NULL
, show_check_physname
,
24732 &setdebuglist
, &showdebuglist
);
24734 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24735 no_class
, &use_deprecated_index_sections
, _("\
24736 Set whether to use deprecated gdb_index sections."), _("\
24737 Show whether to use deprecated gdb_index sections."), _("\
24738 When enabled, deprecated .gdb_index sections are used anyway.\n\
24739 Normally they are ignored either because of a missing feature or\n\
24740 performance issue.\n\
24741 Warning: This option must be enabled before gdb reads the file."),
24744 &setlist
, &showlist
);
24746 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24747 &dwarf2_locexpr_funcs
);
24748 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24749 &dwarf2_loclist_funcs
);
24751 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24752 &dwarf2_block_frame_base_locexpr_funcs
);
24753 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24754 &dwarf2_block_frame_base_loclist_funcs
);
24757 selftests::register_test ("dw2_expand_symtabs_matching",
24758 selftests::dw2_expand_symtabs_matching::run_test
);
24759 selftests::register_test ("dwarf2_find_containing_comp_unit",
24760 selftests::find_containing_comp_unit::run_test
);