1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
51 #include "gdb-demangle.h"
52 #include "filenames.h" /* for DOSish file names */
54 #include "complaints.h"
55 #include "dwarf2/expr.h"
56 #include "dwarf2/loc.h"
57 #include "cp-support.h"
63 #include "typeprint.h"
68 #include "gdbcore.h" /* for gnutarget */
69 #include "gdb/gdb-index.h"
74 #include "namespace.h"
75 #include "gdbsupport/function-view.h"
76 #include "gdbsupport/gdb_optional.h"
77 #include "gdbsupport/underlying.h"
78 #include "gdbsupport/hash_enum.h"
79 #include "filename-seen-cache.h"
83 #include <unordered_map>
84 #include "gdbsupport/selftest.h"
85 #include "rust-lang.h"
86 #include "gdbsupport/pathstuff.h"
87 #include "count-one-bits.h"
88 #include "debuginfod-support.h"
90 /* When == 1, print basic high level tracing messages.
91 When > 1, be more verbose.
92 This is in contrast to the low level DIE reading of dwarf_die_debug. */
93 static unsigned int dwarf_read_debug
= 0;
95 /* When non-zero, dump DIEs after they are read in. */
96 static unsigned int dwarf_die_debug
= 0;
98 /* When non-zero, dump line number entries as they are read in. */
99 unsigned int dwarf_line_debug
= 0;
101 /* When true, cross-check physname against demangler. */
102 static bool check_physname
= false;
104 /* When true, do not reject deprecated .gdb_index sections. */
105 static bool use_deprecated_index_sections
= false;
107 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
109 /* The "aclass" indices for various kinds of computed DWARF symbols. */
111 static int dwarf2_locexpr_index
;
112 static int dwarf2_loclist_index
;
113 static int dwarf2_locexpr_block_index
;
114 static int dwarf2_loclist_block_index
;
116 /* An index into a (C++) symbol name component in a symbol name as
117 recorded in the mapped_index's symbol table. For each C++ symbol
118 in the symbol table, we record one entry for the start of each
119 component in the symbol in a table of name components, and then
120 sort the table, in order to be able to binary search symbol names,
121 ignoring leading namespaces, both completion and regular look up.
122 For example, for symbol "A::B::C", we'll have an entry that points
123 to "A::B::C", another that points to "B::C", and another for "C".
124 Note that function symbols in GDB index have no parameter
125 information, just the function/method names. You can convert a
126 name_component to a "const char *" using the
127 'mapped_index::symbol_name_at(offset_type)' method. */
129 struct name_component
131 /* Offset in the symbol name where the component starts. Stored as
132 a (32-bit) offset instead of a pointer to save memory and improve
133 locality on 64-bit architectures. */
134 offset_type name_offset
;
136 /* The symbol's index in the symbol and constant pool tables of a
141 /* Base class containing bits shared by both .gdb_index and
142 .debug_name indexes. */
144 struct mapped_index_base
146 mapped_index_base () = default;
147 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
149 /* The name_component table (a sorted vector). See name_component's
150 description above. */
151 std::vector
<name_component
> name_components
;
153 /* How NAME_COMPONENTS is sorted. */
154 enum case_sensitivity name_components_casing
;
156 /* Return the number of names in the symbol table. */
157 virtual size_t symbol_name_count () const = 0;
159 /* Get the name of the symbol at IDX in the symbol table. */
160 virtual const char *symbol_name_at (offset_type idx
) const = 0;
162 /* Return whether the name at IDX in the symbol table should be
164 virtual bool symbol_name_slot_invalid (offset_type idx
) const
169 /* Build the symbol name component sorted vector, if we haven't
171 void build_name_components ();
173 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
174 possible matches for LN_NO_PARAMS in the name component
176 std::pair
<std::vector
<name_component
>::const_iterator
,
177 std::vector
<name_component
>::const_iterator
>
178 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
179 enum language lang
) const;
181 /* Prevent deleting/destroying via a base class pointer. */
183 ~mapped_index_base() = default;
186 /* A description of the mapped index. The file format is described in
187 a comment by the code that writes the index. */
188 struct mapped_index final
: public mapped_index_base
190 /* A slot/bucket in the symbol table hash. */
191 struct symbol_table_slot
193 const offset_type name
;
194 const offset_type vec
;
197 /* Index data format version. */
200 /* The address table data. */
201 gdb::array_view
<const gdb_byte
> address_table
;
203 /* The symbol table, implemented as a hash table. */
204 gdb::array_view
<symbol_table_slot
> symbol_table
;
206 /* A pointer to the constant pool. */
207 const char *constant_pool
= nullptr;
209 bool symbol_name_slot_invalid (offset_type idx
) const override
211 const auto &bucket
= this->symbol_table
[idx
];
212 return bucket
.name
== 0 && bucket
.vec
== 0;
215 /* Convenience method to get at the name of the symbol at IDX in the
217 const char *symbol_name_at (offset_type idx
) const override
218 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
220 size_t symbol_name_count () const override
221 { return this->symbol_table
.size (); }
224 /* A description of the mapped .debug_names.
225 Uninitialized map has CU_COUNT 0. */
226 struct mapped_debug_names final
: public mapped_index_base
228 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
229 : dwarf2_per_objfile (dwarf2_per_objfile_
)
232 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
233 bfd_endian dwarf5_byte_order
;
234 bool dwarf5_is_dwarf64
;
235 bool augmentation_is_gdb
;
237 uint32_t cu_count
= 0;
238 uint32_t tu_count
, bucket_count
, name_count
;
239 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
240 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
241 const gdb_byte
*name_table_string_offs_reordered
;
242 const gdb_byte
*name_table_entry_offs_reordered
;
243 const gdb_byte
*entry_pool
;
250 /* Attribute name DW_IDX_*. */
253 /* Attribute form DW_FORM_*. */
256 /* Value if FORM is DW_FORM_implicit_const. */
257 LONGEST implicit_const
;
259 std::vector
<attr
> attr_vec
;
262 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
264 const char *namei_to_name (uint32_t namei
) const;
266 /* Implementation of the mapped_index_base virtual interface, for
267 the name_components cache. */
269 const char *symbol_name_at (offset_type idx
) const override
270 { return namei_to_name (idx
); }
272 size_t symbol_name_count () const override
273 { return this->name_count
; }
276 /* See dwarf2read.h. */
279 get_dwarf2_per_objfile (struct objfile
*objfile
)
281 return dwarf2_objfile_data_key
.get (objfile
);
284 /* Default names of the debugging sections. */
286 /* Note that if the debugging section has been compressed, it might
287 have a name like .zdebug_info. */
289 static const struct dwarf2_debug_sections dwarf2_elf_names
=
291 { ".debug_info", ".zdebug_info" },
292 { ".debug_abbrev", ".zdebug_abbrev" },
293 { ".debug_line", ".zdebug_line" },
294 { ".debug_loc", ".zdebug_loc" },
295 { ".debug_loclists", ".zdebug_loclists" },
296 { ".debug_macinfo", ".zdebug_macinfo" },
297 { ".debug_macro", ".zdebug_macro" },
298 { ".debug_str", ".zdebug_str" },
299 { ".debug_str_offsets", ".zdebug_str_offsets" },
300 { ".debug_line_str", ".zdebug_line_str" },
301 { ".debug_ranges", ".zdebug_ranges" },
302 { ".debug_rnglists", ".zdebug_rnglists" },
303 { ".debug_types", ".zdebug_types" },
304 { ".debug_addr", ".zdebug_addr" },
305 { ".debug_frame", ".zdebug_frame" },
306 { ".eh_frame", NULL
},
307 { ".gdb_index", ".zgdb_index" },
308 { ".debug_names", ".zdebug_names" },
309 { ".debug_aranges", ".zdebug_aranges" },
313 /* List of DWO/DWP sections. */
315 static const struct dwop_section_names
317 struct dwarf2_section_names abbrev_dwo
;
318 struct dwarf2_section_names info_dwo
;
319 struct dwarf2_section_names line_dwo
;
320 struct dwarf2_section_names loc_dwo
;
321 struct dwarf2_section_names loclists_dwo
;
322 struct dwarf2_section_names macinfo_dwo
;
323 struct dwarf2_section_names macro_dwo
;
324 struct dwarf2_section_names str_dwo
;
325 struct dwarf2_section_names str_offsets_dwo
;
326 struct dwarf2_section_names types_dwo
;
327 struct dwarf2_section_names cu_index
;
328 struct dwarf2_section_names tu_index
;
332 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
333 { ".debug_info.dwo", ".zdebug_info.dwo" },
334 { ".debug_line.dwo", ".zdebug_line.dwo" },
335 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
336 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
337 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
338 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
339 { ".debug_str.dwo", ".zdebug_str.dwo" },
340 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
341 { ".debug_types.dwo", ".zdebug_types.dwo" },
342 { ".debug_cu_index", ".zdebug_cu_index" },
343 { ".debug_tu_index", ".zdebug_tu_index" },
346 /* local data types */
348 /* Type used for delaying computation of method physnames.
349 See comments for compute_delayed_physnames. */
350 struct delayed_method_info
352 /* The type to which the method is attached, i.e., its parent class. */
355 /* The index of the method in the type's function fieldlists. */
358 /* The index of the method in the fieldlist. */
361 /* The name of the DIE. */
364 /* The DIE associated with this method. */
365 struct die_info
*die
;
368 /* Internal state when decoding a particular compilation unit. */
371 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
374 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
376 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
377 Create the set of symtabs used by this TU, or if this TU is sharing
378 symtabs with another TU and the symtabs have already been created
379 then restore those symtabs in the line header.
380 We don't need the pc/line-number mapping for type units. */
381 void setup_type_unit_groups (struct die_info
*die
);
383 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
384 buildsym_compunit constructor. */
385 struct compunit_symtab
*start_symtab (const char *name
,
386 const char *comp_dir
,
389 /* Reset the builder. */
390 void reset_builder () { m_builder
.reset (); }
392 /* The header of the compilation unit. */
393 struct comp_unit_head header
{};
395 /* Base address of this compilation unit. */
396 CORE_ADDR base_address
= 0;
398 /* Non-zero if base_address has been set. */
401 /* The language we are debugging. */
402 enum language language
= language_unknown
;
403 const struct language_defn
*language_defn
= nullptr;
405 const char *producer
= nullptr;
408 /* The symtab builder for this CU. This is only non-NULL when full
409 symbols are being read. */
410 std::unique_ptr
<buildsym_compunit
> m_builder
;
413 /* The generic symbol table building routines have separate lists for
414 file scope symbols and all all other scopes (local scopes). So
415 we need to select the right one to pass to add_symbol_to_list().
416 We do it by keeping a pointer to the correct list in list_in_scope.
418 FIXME: The original dwarf code just treated the file scope as the
419 first local scope, and all other local scopes as nested local
420 scopes, and worked fine. Check to see if we really need to
421 distinguish these in buildsym.c. */
422 struct pending
**list_in_scope
= nullptr;
424 /* Hash table holding all the loaded partial DIEs
425 with partial_die->offset.SECT_OFF as hash. */
426 htab_t partial_dies
= nullptr;
428 /* Storage for things with the same lifetime as this read-in compilation
429 unit, including partial DIEs. */
430 auto_obstack comp_unit_obstack
;
432 /* When multiple dwarf2_cu structures are living in memory, this field
433 chains them all together, so that they can be released efficiently.
434 We will probably also want a generation counter so that most-recently-used
435 compilation units are cached... */
436 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
438 /* Backlink to our per_cu entry. */
439 struct dwarf2_per_cu_data
*per_cu
;
441 /* How many compilation units ago was this CU last referenced? */
444 /* A hash table of DIE cu_offset for following references with
445 die_info->offset.sect_off as hash. */
446 htab_t die_hash
= nullptr;
448 /* Full DIEs if read in. */
449 struct die_info
*dies
= nullptr;
451 /* A set of pointers to dwarf2_per_cu_data objects for compilation
452 units referenced by this one. Only set during full symbol processing;
453 partial symbol tables do not have dependencies. */
454 htab_t dependencies
= nullptr;
456 /* Header data from the line table, during full symbol processing. */
457 struct line_header
*line_header
= nullptr;
458 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
459 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
460 this is the DW_TAG_compile_unit die for this CU. We'll hold on
461 to the line header as long as this DIE is being processed. See
462 process_die_scope. */
463 die_info
*line_header_die_owner
= nullptr;
465 /* A list of methods which need to have physnames computed
466 after all type information has been read. */
467 std::vector
<delayed_method_info
> method_list
;
469 /* To be copied to symtab->call_site_htab. */
470 htab_t call_site_htab
= nullptr;
472 /* Non-NULL if this CU came from a DWO file.
473 There is an invariant here that is important to remember:
474 Except for attributes copied from the top level DIE in the "main"
475 (or "stub") file in preparation for reading the DWO file
476 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
477 Either there isn't a DWO file (in which case this is NULL and the point
478 is moot), or there is and either we're not going to read it (in which
479 case this is NULL) or there is and we are reading it (in which case this
481 struct dwo_unit
*dwo_unit
= nullptr;
483 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
484 Note this value comes from the Fission stub CU/TU's DIE. */
485 gdb::optional
<ULONGEST
> addr_base
;
487 /* The DW_AT_rnglists_base attribute if present.
488 Note this value comes from the Fission stub CU/TU's DIE.
489 Also note that the value is zero in the non-DWO case so this value can
490 be used without needing to know whether DWO files are in use or not.
491 N.B. This does not apply to DW_AT_ranges appearing in
492 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
493 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
494 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
495 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
496 ULONGEST ranges_base
= 0;
498 /* When reading debug info generated by older versions of rustc, we
499 have to rewrite some union types to be struct types with a
500 variant part. This rewriting must be done after the CU is fully
501 read in, because otherwise at the point of rewriting some struct
502 type might not have been fully processed. So, we keep a list of
503 all such types here and process them after expansion. */
504 std::vector
<struct type
*> rust_unions
;
506 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
507 files, the value is implicitly zero. For DWARF 5 version DWO files, the
508 value is often implicit and is the size of the header of
509 .debug_str_offsets section (8 or 4, depending on the address size). */
510 gdb::optional
<ULONGEST
> str_offsets_base
;
512 /* Mark used when releasing cached dies. */
515 /* This CU references .debug_loc. See the symtab->locations_valid field.
516 This test is imperfect as there may exist optimized debug code not using
517 any location list and still facing inlining issues if handled as
518 unoptimized code. For a future better test see GCC PR other/32998. */
519 bool has_loclist
: 1;
521 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
522 if all the producer_is_* fields are valid. This information is cached
523 because profiling CU expansion showed excessive time spent in
524 producer_is_gxx_lt_4_6. */
525 bool checked_producer
: 1;
526 bool producer_is_gxx_lt_4_6
: 1;
527 bool producer_is_gcc_lt_4_3
: 1;
528 bool producer_is_icc
: 1;
529 bool producer_is_icc_lt_14
: 1;
530 bool producer_is_codewarrior
: 1;
532 /* When true, the file that we're processing is known to have
533 debugging info for C++ namespaces. GCC 3.3.x did not produce
534 this information, but later versions do. */
536 bool processing_has_namespace_info
: 1;
538 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
540 /* If this CU was inherited by another CU (via specification,
541 abstract_origin, etc), this is the ancestor CU. */
544 /* Get the buildsym_compunit for this CU. */
545 buildsym_compunit
*get_builder ()
547 /* If this CU has a builder associated with it, use that. */
548 if (m_builder
!= nullptr)
549 return m_builder
.get ();
551 /* Otherwise, search ancestors for a valid builder. */
552 if (ancestor
!= nullptr)
553 return ancestor
->get_builder ();
559 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
560 This includes type_unit_group and quick_file_names. */
562 struct stmt_list_hash
564 /* The DWO unit this table is from or NULL if there is none. */
565 struct dwo_unit
*dwo_unit
;
567 /* Offset in .debug_line or .debug_line.dwo. */
568 sect_offset line_sect_off
;
571 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
572 an object of this type. */
574 struct type_unit_group
576 /* dwarf2read.c's main "handle" on a TU symtab.
577 To simplify things we create an artificial CU that "includes" all the
578 type units using this stmt_list so that the rest of the code still has
579 a "per_cu" handle on the symtab. */
580 struct dwarf2_per_cu_data per_cu
;
582 /* The TUs that share this DW_AT_stmt_list entry.
583 This is added to while parsing type units to build partial symtabs,
584 and is deleted afterwards and not used again. */
585 std::vector
<signatured_type
*> *tus
;
587 /* The compunit symtab.
588 Type units in a group needn't all be defined in the same source file,
589 so we create an essentially anonymous symtab as the compunit symtab. */
590 struct compunit_symtab
*compunit_symtab
;
592 /* The data used to construct the hash key. */
593 struct stmt_list_hash hash
;
595 /* The symbol tables for this TU (obtained from the files listed in
597 WARNING: The order of entries here must match the order of entries
598 in the line header. After the first TU using this type_unit_group, the
599 line header for the subsequent TUs is recreated from this. This is done
600 because we need to use the same symtabs for each TU using the same
601 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
602 there's no guarantee the line header doesn't have duplicate entries. */
603 struct symtab
**symtabs
;
606 /* These sections are what may appear in a (real or virtual) DWO file. */
610 struct dwarf2_section_info abbrev
;
611 struct dwarf2_section_info line
;
612 struct dwarf2_section_info loc
;
613 struct dwarf2_section_info loclists
;
614 struct dwarf2_section_info macinfo
;
615 struct dwarf2_section_info macro
;
616 struct dwarf2_section_info str
;
617 struct dwarf2_section_info str_offsets
;
618 /* In the case of a virtual DWO file, these two are unused. */
619 struct dwarf2_section_info info
;
620 std::vector
<dwarf2_section_info
> types
;
623 /* CUs/TUs in DWP/DWO files. */
627 /* Backlink to the containing struct dwo_file. */
628 struct dwo_file
*dwo_file
;
630 /* The "id" that distinguishes this CU/TU.
631 .debug_info calls this "dwo_id", .debug_types calls this "signature".
632 Since signatures came first, we stick with it for consistency. */
635 /* The section this CU/TU lives in, in the DWO file. */
636 struct dwarf2_section_info
*section
;
638 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
639 sect_offset sect_off
;
642 /* For types, offset in the type's DIE of the type defined by this TU. */
643 cu_offset type_offset_in_tu
;
646 /* include/dwarf2.h defines the DWP section codes.
647 It defines a max value but it doesn't define a min value, which we
648 use for error checking, so provide one. */
650 enum dwp_v2_section_ids
655 /* Data for one DWO file.
657 This includes virtual DWO files (a virtual DWO file is a DWO file as it
658 appears in a DWP file). DWP files don't really have DWO files per se -
659 comdat folding of types "loses" the DWO file they came from, and from
660 a high level view DWP files appear to contain a mass of random types.
661 However, to maintain consistency with the non-DWP case we pretend DWP
662 files contain virtual DWO files, and we assign each TU with one virtual
663 DWO file (generally based on the line and abbrev section offsets -
664 a heuristic that seems to work in practice). */
668 dwo_file () = default;
669 DISABLE_COPY_AND_ASSIGN (dwo_file
);
671 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
672 For virtual DWO files the name is constructed from the section offsets
673 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
674 from related CU+TUs. */
675 const char *dwo_name
= nullptr;
677 /* The DW_AT_comp_dir attribute. */
678 const char *comp_dir
= nullptr;
680 /* The bfd, when the file is open. Otherwise this is NULL.
681 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
682 gdb_bfd_ref_ptr dbfd
;
684 /* The sections that make up this DWO file.
685 Remember that for virtual DWO files in DWP V2, these are virtual
686 sections (for lack of a better name). */
687 struct dwo_sections sections
{};
689 /* The CUs in the file.
690 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
691 an extension to handle LLVM's Link Time Optimization output (where
692 multiple source files may be compiled into a single object/dwo pair). */
695 /* Table of TUs in the file.
696 Each element is a struct dwo_unit. */
700 /* These sections are what may appear in a DWP file. */
704 /* These are used by both DWP version 1 and 2. */
705 struct dwarf2_section_info str
;
706 struct dwarf2_section_info cu_index
;
707 struct dwarf2_section_info tu_index
;
709 /* These are only used by DWP version 2 files.
710 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
711 sections are referenced by section number, and are not recorded here.
712 In DWP version 2 there is at most one copy of all these sections, each
713 section being (effectively) comprised of the concatenation of all of the
714 individual sections that exist in the version 1 format.
715 To keep the code simple we treat each of these concatenated pieces as a
716 section itself (a virtual section?). */
717 struct dwarf2_section_info abbrev
;
718 struct dwarf2_section_info info
;
719 struct dwarf2_section_info line
;
720 struct dwarf2_section_info loc
;
721 struct dwarf2_section_info macinfo
;
722 struct dwarf2_section_info macro
;
723 struct dwarf2_section_info str_offsets
;
724 struct dwarf2_section_info types
;
727 /* These sections are what may appear in a virtual DWO file in DWP version 1.
728 A virtual DWO file is a DWO file as it appears in a DWP file. */
730 struct virtual_v1_dwo_sections
732 struct dwarf2_section_info abbrev
;
733 struct dwarf2_section_info line
;
734 struct dwarf2_section_info loc
;
735 struct dwarf2_section_info macinfo
;
736 struct dwarf2_section_info macro
;
737 struct dwarf2_section_info str_offsets
;
738 /* Each DWP hash table entry records one CU or one TU.
739 That is recorded here, and copied to dwo_unit.section. */
740 struct dwarf2_section_info info_or_types
;
743 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
744 In version 2, the sections of the DWO files are concatenated together
745 and stored in one section of that name. Thus each ELF section contains
746 several "virtual" sections. */
748 struct virtual_v2_dwo_sections
750 bfd_size_type abbrev_offset
;
751 bfd_size_type abbrev_size
;
753 bfd_size_type line_offset
;
754 bfd_size_type line_size
;
756 bfd_size_type loc_offset
;
757 bfd_size_type loc_size
;
759 bfd_size_type macinfo_offset
;
760 bfd_size_type macinfo_size
;
762 bfd_size_type macro_offset
;
763 bfd_size_type macro_size
;
765 bfd_size_type str_offsets_offset
;
766 bfd_size_type str_offsets_size
;
768 /* Each DWP hash table entry records one CU or one TU.
769 That is recorded here, and copied to dwo_unit.section. */
770 bfd_size_type info_or_types_offset
;
771 bfd_size_type info_or_types_size
;
774 /* Contents of DWP hash tables. */
776 struct dwp_hash_table
778 uint32_t version
, nr_columns
;
779 uint32_t nr_units
, nr_slots
;
780 const gdb_byte
*hash_table
, *unit_table
;
785 const gdb_byte
*indices
;
789 /* This is indexed by column number and gives the id of the section
791 #define MAX_NR_V2_DWO_SECTIONS \
792 (1 /* .debug_info or .debug_types */ \
793 + 1 /* .debug_abbrev */ \
794 + 1 /* .debug_line */ \
795 + 1 /* .debug_loc */ \
796 + 1 /* .debug_str_offsets */ \
797 + 1 /* .debug_macro or .debug_macinfo */)
798 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
799 const gdb_byte
*offsets
;
800 const gdb_byte
*sizes
;
805 /* Data for one DWP file. */
809 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
811 dbfd (std::move (abfd
))
815 /* Name of the file. */
818 /* File format version. */
822 gdb_bfd_ref_ptr dbfd
;
824 /* Section info for this file. */
825 struct dwp_sections sections
{};
827 /* Table of CUs in the file. */
828 const struct dwp_hash_table
*cus
= nullptr;
830 /* Table of TUs in the file. */
831 const struct dwp_hash_table
*tus
= nullptr;
833 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
837 /* Table to map ELF section numbers to their sections.
838 This is only needed for the DWP V1 file format. */
839 unsigned int num_sections
= 0;
840 asection
**elf_sections
= nullptr;
843 /* Struct used to pass misc. parameters to read_die_and_children, et
844 al. which are used for both .debug_info and .debug_types dies.
845 All parameters here are unchanging for the life of the call. This
846 struct exists to abstract away the constant parameters of die reading. */
848 struct die_reader_specs
850 /* The bfd of die_section. */
853 /* The CU of the DIE we are parsing. */
854 struct dwarf2_cu
*cu
;
856 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
857 struct dwo_file
*dwo_file
;
859 /* The section the die comes from.
860 This is either .debug_info or .debug_types, or the .dwo variants. */
861 struct dwarf2_section_info
*die_section
;
863 /* die_section->buffer. */
864 const gdb_byte
*buffer
;
866 /* The end of the buffer. */
867 const gdb_byte
*buffer_end
;
869 /* The abbreviation table to use when reading the DIEs. */
870 struct abbrev_table
*abbrev_table
;
873 /* A subclass of die_reader_specs that holds storage and has complex
874 constructor and destructor behavior. */
876 class cutu_reader
: public die_reader_specs
880 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
881 struct abbrev_table
*abbrev_table
,
885 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
886 struct dwarf2_cu
*parent_cu
= nullptr,
887 struct dwo_file
*dwo_file
= nullptr);
889 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
891 const gdb_byte
*info_ptr
= nullptr;
892 struct die_info
*comp_unit_die
= nullptr;
893 bool dummy_p
= false;
895 /* Release the new CU, putting it on the chain. This cannot be done
900 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
901 int use_existing_cu
);
903 struct dwarf2_per_cu_data
*m_this_cu
;
904 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
906 /* The ordinary abbreviation table. */
907 abbrev_table_up m_abbrev_table_holder
;
909 /* The DWO abbreviation table. */
910 abbrev_table_up m_dwo_abbrev_table
;
913 /* When we construct a partial symbol table entry we only
914 need this much information. */
915 struct partial_die_info
: public allocate_on_obstack
917 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
919 /* Disable assign but still keep copy ctor, which is needed
920 load_partial_dies. */
921 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
923 /* Adjust the partial die before generating a symbol for it. This
924 function may set the is_external flag or change the DIE's
926 void fixup (struct dwarf2_cu
*cu
);
928 /* Read a minimal amount of information into the minimal die
930 const gdb_byte
*read (const struct die_reader_specs
*reader
,
931 const struct abbrev_info
&abbrev
,
932 const gdb_byte
*info_ptr
);
934 /* Offset of this DIE. */
935 const sect_offset sect_off
;
937 /* DWARF-2 tag for this DIE. */
938 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
940 /* Assorted flags describing the data found in this DIE. */
941 const unsigned int has_children
: 1;
943 unsigned int is_external
: 1;
944 unsigned int is_declaration
: 1;
945 unsigned int has_type
: 1;
946 unsigned int has_specification
: 1;
947 unsigned int has_pc_info
: 1;
948 unsigned int may_be_inlined
: 1;
950 /* This DIE has been marked DW_AT_main_subprogram. */
951 unsigned int main_subprogram
: 1;
953 /* Flag set if the SCOPE field of this structure has been
955 unsigned int scope_set
: 1;
957 /* Flag set if the DIE has a byte_size attribute. */
958 unsigned int has_byte_size
: 1;
960 /* Flag set if the DIE has a DW_AT_const_value attribute. */
961 unsigned int has_const_value
: 1;
963 /* Flag set if any of the DIE's children are template arguments. */
964 unsigned int has_template_arguments
: 1;
966 /* Flag set if fixup has been called on this die. */
967 unsigned int fixup_called
: 1;
969 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
970 unsigned int is_dwz
: 1;
972 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
973 unsigned int spec_is_dwz
: 1;
975 /* The name of this DIE. Normally the value of DW_AT_name, but
976 sometimes a default name for unnamed DIEs. */
977 const char *name
= nullptr;
979 /* The linkage name, if present. */
980 const char *linkage_name
= nullptr;
982 /* The scope to prepend to our children. This is generally
983 allocated on the comp_unit_obstack, so will disappear
984 when this compilation unit leaves the cache. */
985 const char *scope
= nullptr;
987 /* Some data associated with the partial DIE. The tag determines
988 which field is live. */
991 /* The location description associated with this DIE, if any. */
992 struct dwarf_block
*locdesc
;
993 /* The offset of an import, for DW_TAG_imported_unit. */
994 sect_offset sect_off
;
997 /* If HAS_PC_INFO, the PC range associated with this DIE. */
999 CORE_ADDR highpc
= 0;
1001 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1002 DW_AT_sibling, if any. */
1003 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1004 could return DW_AT_sibling values to its caller load_partial_dies. */
1005 const gdb_byte
*sibling
= nullptr;
1007 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1008 DW_AT_specification (or DW_AT_abstract_origin or
1009 DW_AT_extension). */
1010 sect_offset spec_offset
{};
1012 /* Pointers to this DIE's parent, first child, and next sibling,
1014 struct partial_die_info
*die_parent
= nullptr;
1015 struct partial_die_info
*die_child
= nullptr;
1016 struct partial_die_info
*die_sibling
= nullptr;
1018 friend struct partial_die_info
*
1019 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1022 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1023 partial_die_info (sect_offset sect_off
)
1024 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1028 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1030 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1035 has_specification
= 0;
1038 main_subprogram
= 0;
1041 has_const_value
= 0;
1042 has_template_arguments
= 0;
1049 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1050 but this would require a corresponding change in unpack_field_as_long
1052 static int bits_per_byte
= 8;
1054 /* When reading a variant or variant part, we track a bit more
1055 information about the field, and store it in an object of this
1058 struct variant_field
1060 /* If we see a DW_TAG_variant, then this will be the discriminant
1062 ULONGEST discriminant_value
;
1063 /* If we see a DW_TAG_variant, then this will be set if this is the
1065 bool default_branch
;
1066 /* While reading a DW_TAG_variant_part, this will be set if this
1067 field is the discriminant. */
1068 bool is_discriminant
;
1073 int accessibility
= 0;
1075 /* Extra information to describe a variant or variant part. */
1076 struct variant_field variant
{};
1077 struct field field
{};
1082 const char *name
= nullptr;
1083 std::vector
<struct fn_field
> fnfields
;
1086 /* The routines that read and process dies for a C struct or C++ class
1087 pass lists of data member fields and lists of member function fields
1088 in an instance of a field_info structure, as defined below. */
1091 /* List of data member and baseclasses fields. */
1092 std::vector
<struct nextfield
> fields
;
1093 std::vector
<struct nextfield
> baseclasses
;
1095 /* Set if the accessibility of one of the fields is not public. */
1096 int non_public_fields
= 0;
1098 /* Member function fieldlist array, contains name of possibly overloaded
1099 member function, number of overloaded member functions and a pointer
1100 to the head of the member function field chain. */
1101 std::vector
<struct fnfieldlist
> fnfieldlists
;
1103 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1104 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1105 std::vector
<struct decl_field
> typedef_field_list
;
1107 /* Nested types defined by this class and the number of elements in this
1109 std::vector
<struct decl_field
> nested_types_list
;
1111 /* Return the total number of fields (including baseclasses). */
1112 int nfields () const
1114 return fields
.size () + baseclasses
.size ();
1118 /* Loaded secondary compilation units are kept in memory until they
1119 have not been referenced for the processing of this many
1120 compilation units. Set this to zero to disable caching. Cache
1121 sizes of up to at least twenty will improve startup time for
1122 typical inter-CU-reference binaries, at an obvious memory cost. */
1123 static int dwarf_max_cache_age
= 5;
1125 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1126 struct cmd_list_element
*c
, const char *value
)
1128 fprintf_filtered (file
, _("The upper bound on the age of cached "
1129 "DWARF compilation units is %s.\n"),
1133 /* local function prototypes */
1135 static void dwarf2_find_base_address (struct die_info
*die
,
1136 struct dwarf2_cu
*cu
);
1138 static dwarf2_psymtab
*create_partial_symtab
1139 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1141 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1142 const gdb_byte
*info_ptr
,
1143 struct die_info
*type_unit_die
);
1145 static void dwarf2_build_psymtabs_hard
1146 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1148 static void scan_partial_symbols (struct partial_die_info
*,
1149 CORE_ADDR
*, CORE_ADDR
*,
1150 int, struct dwarf2_cu
*);
1152 static void add_partial_symbol (struct partial_die_info
*,
1153 struct dwarf2_cu
*);
1155 static void add_partial_namespace (struct partial_die_info
*pdi
,
1156 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1157 int set_addrmap
, struct dwarf2_cu
*cu
);
1159 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1160 CORE_ADDR
*highpc
, int set_addrmap
,
1161 struct dwarf2_cu
*cu
);
1163 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1164 struct dwarf2_cu
*cu
);
1166 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1167 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1168 int need_pc
, struct dwarf2_cu
*cu
);
1170 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1172 static struct partial_die_info
*load_partial_dies
1173 (const struct die_reader_specs
*, const gdb_byte
*, int);
1175 /* A pair of partial_die_info and compilation unit. */
1176 struct cu_partial_die_info
1178 /* The compilation unit of the partial_die_info. */
1179 struct dwarf2_cu
*cu
;
1180 /* A partial_die_info. */
1181 struct partial_die_info
*pdi
;
1183 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1189 cu_partial_die_info () = delete;
1192 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1193 struct dwarf2_cu
*);
1195 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1196 struct attribute
*, struct attr_abbrev
*,
1197 const gdb_byte
*, bool *need_reprocess
);
1199 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1200 struct attribute
*attr
);
1202 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1204 static sect_offset read_abbrev_offset
1205 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1206 struct dwarf2_section_info
*, sect_offset
);
1208 static const char *read_indirect_string
1209 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1210 const struct comp_unit_head
*, unsigned int *);
1212 static const char *read_indirect_string_at_offset
1213 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1215 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1219 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1220 ULONGEST str_index
);
1222 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1223 ULONGEST str_index
);
1225 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1227 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1228 struct dwarf2_cu
*);
1230 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1233 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1234 struct dwarf2_cu
*cu
);
1236 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1238 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1239 struct dwarf2_cu
*cu
);
1241 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1243 static struct die_info
*die_specification (struct die_info
*die
,
1244 struct dwarf2_cu
**);
1246 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1247 struct dwarf2_cu
*cu
);
1249 static void dwarf_decode_lines (struct line_header
*, const char *,
1250 struct dwarf2_cu
*, dwarf2_psymtab
*,
1251 CORE_ADDR
, int decode_mapping
);
1253 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1256 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1257 struct dwarf2_cu
*, struct symbol
* = NULL
);
1259 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1260 struct dwarf2_cu
*);
1262 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1265 struct obstack
*obstack
,
1266 struct dwarf2_cu
*cu
, LONGEST
*value
,
1267 const gdb_byte
**bytes
,
1268 struct dwarf2_locexpr_baton
**baton
);
1270 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1272 static int need_gnat_info (struct dwarf2_cu
*);
1274 static struct type
*die_descriptive_type (struct die_info
*,
1275 struct dwarf2_cu
*);
1277 static void set_descriptive_type (struct type
*, struct die_info
*,
1278 struct dwarf2_cu
*);
1280 static struct type
*die_containing_type (struct die_info
*,
1281 struct dwarf2_cu
*);
1283 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1284 struct dwarf2_cu
*);
1286 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1288 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1290 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1292 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1293 const char *suffix
, int physname
,
1294 struct dwarf2_cu
*cu
);
1296 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1298 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1300 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1302 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1304 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1306 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1308 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1309 struct dwarf2_cu
*, dwarf2_psymtab
*);
1311 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1312 values. Keep the items ordered with increasing constraints compliance. */
1315 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1316 PC_BOUNDS_NOT_PRESENT
,
1318 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1319 were present but they do not form a valid range of PC addresses. */
1322 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1325 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1329 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1330 CORE_ADDR
*, CORE_ADDR
*,
1334 static void get_scope_pc_bounds (struct die_info
*,
1335 CORE_ADDR
*, CORE_ADDR
*,
1336 struct dwarf2_cu
*);
1338 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1339 CORE_ADDR
, struct dwarf2_cu
*);
1341 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1342 struct dwarf2_cu
*);
1344 static void dwarf2_attach_fields_to_type (struct field_info
*,
1345 struct type
*, struct dwarf2_cu
*);
1347 static void dwarf2_add_member_fn (struct field_info
*,
1348 struct die_info
*, struct type
*,
1349 struct dwarf2_cu
*);
1351 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1353 struct dwarf2_cu
*);
1355 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1357 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1359 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1361 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1363 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1365 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1367 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1369 static struct type
*read_module_type (struct die_info
*die
,
1370 struct dwarf2_cu
*cu
);
1372 static const char *namespace_name (struct die_info
*die
,
1373 int *is_anonymous
, struct dwarf2_cu
*);
1375 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1377 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1379 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1380 struct dwarf2_cu
*);
1382 static struct die_info
*read_die_and_siblings_1
1383 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1386 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1387 const gdb_byte
*info_ptr
,
1388 const gdb_byte
**new_info_ptr
,
1389 struct die_info
*parent
);
1391 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1392 struct die_info
**, const gdb_byte
*,
1395 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1396 struct die_info
**, const gdb_byte
*);
1398 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1400 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1403 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1405 static const char *dwarf2_full_name (const char *name
,
1406 struct die_info
*die
,
1407 struct dwarf2_cu
*cu
);
1409 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1410 struct dwarf2_cu
*cu
);
1412 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1413 struct dwarf2_cu
**);
1415 static const char *dwarf_tag_name (unsigned int);
1417 static const char *dwarf_attr_name (unsigned int);
1419 static const char *dwarf_form_name (unsigned int);
1421 static const char *dwarf_bool_name (unsigned int);
1423 static const char *dwarf_type_encoding_name (unsigned int);
1425 static struct die_info
*sibling_die (struct die_info
*);
1427 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1429 static void dump_die_for_error (struct die_info
*);
1431 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1434 /*static*/ void dump_die (struct die_info
*, int max_level
);
1436 static void store_in_ref_table (struct die_info
*,
1437 struct dwarf2_cu
*);
1439 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1441 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1443 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1444 const struct attribute
*,
1445 struct dwarf2_cu
**);
1447 static struct die_info
*follow_die_ref (struct die_info
*,
1448 const struct attribute
*,
1449 struct dwarf2_cu
**);
1451 static struct die_info
*follow_die_sig (struct die_info
*,
1452 const struct attribute
*,
1453 struct dwarf2_cu
**);
1455 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1456 struct dwarf2_cu
*);
1458 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1459 const struct attribute
*,
1460 struct dwarf2_cu
*);
1462 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1464 static void read_signatured_type (struct signatured_type
*);
1466 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1467 struct die_info
*die
, struct dwarf2_cu
*cu
,
1468 struct dynamic_prop
*prop
, struct type
*type
);
1470 /* memory allocation interface */
1472 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1474 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1476 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1478 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1479 struct dwarf2_loclist_baton
*baton
,
1480 const struct attribute
*attr
);
1482 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1484 struct dwarf2_cu
*cu
,
1487 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1488 const gdb_byte
*info_ptr
,
1489 struct abbrev_info
*abbrev
);
1491 static hashval_t
partial_die_hash (const void *item
);
1493 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1495 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1496 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1497 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1499 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1500 struct die_info
*comp_unit_die
,
1501 enum language pretend_language
);
1503 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1505 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1507 static struct type
*set_die_type (struct die_info
*, struct type
*,
1508 struct dwarf2_cu
*);
1510 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1512 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1514 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1517 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1520 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1523 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1524 struct dwarf2_per_cu_data
*);
1526 static void dwarf2_mark (struct dwarf2_cu
*);
1528 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1530 static struct type
*get_die_type_at_offset (sect_offset
,
1531 struct dwarf2_per_cu_data
*);
1533 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1535 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1536 enum language pretend_language
);
1538 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1540 /* Class, the destructor of which frees all allocated queue entries. This
1541 will only have work to do if an error was thrown while processing the
1542 dwarf. If no error was thrown then the queue entries should have all
1543 been processed, and freed, as we went along. */
1545 class dwarf2_queue_guard
1548 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1549 : m_per_objfile (per_objfile
)
1553 /* Free any entries remaining on the queue. There should only be
1554 entries left if we hit an error while processing the dwarf. */
1555 ~dwarf2_queue_guard ()
1557 /* Ensure that no memory is allocated by the queue. */
1558 std::queue
<dwarf2_queue_item
> empty
;
1559 std::swap (m_per_objfile
->queue
, empty
);
1562 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1565 dwarf2_per_objfile
*m_per_objfile
;
1568 dwarf2_queue_item::~dwarf2_queue_item ()
1570 /* Anything still marked queued is likely to be in an
1571 inconsistent state, so discard it. */
1574 if (per_cu
->cu
!= NULL
)
1575 free_one_cached_comp_unit (per_cu
);
1580 /* The return type of find_file_and_directory. Note, the enclosed
1581 string pointers are only valid while this object is valid. */
1583 struct file_and_directory
1585 /* The filename. This is never NULL. */
1588 /* The compilation directory. NULL if not known. If we needed to
1589 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1590 points directly to the DW_AT_comp_dir string attribute owned by
1591 the obstack that owns the DIE. */
1592 const char *comp_dir
;
1594 /* If we needed to build a new string for comp_dir, this is what
1595 owns the storage. */
1596 std::string comp_dir_storage
;
1599 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1600 struct dwarf2_cu
*cu
);
1602 static htab_up
allocate_signatured_type_table ();
1604 static htab_up
allocate_dwo_unit_table ();
1606 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1607 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1608 struct dwp_file
*dwp_file
, const char *comp_dir
,
1609 ULONGEST signature
, int is_debug_types
);
1611 static struct dwp_file
*get_dwp_file
1612 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1614 static struct dwo_unit
*lookup_dwo_comp_unit
1615 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1617 static struct dwo_unit
*lookup_dwo_type_unit
1618 (struct signatured_type
*, const char *, const char *);
1620 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1622 /* A unique pointer to a dwo_file. */
1624 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1626 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1628 static void check_producer (struct dwarf2_cu
*cu
);
1630 static void free_line_header_voidp (void *arg
);
1632 /* Various complaints about symbol reading that don't abort the process. */
1635 dwarf2_debug_line_missing_file_complaint (void)
1637 complaint (_(".debug_line section has line data without a file"));
1641 dwarf2_debug_line_missing_end_sequence_complaint (void)
1643 complaint (_(".debug_line section has line "
1644 "program sequence without an end"));
1648 dwarf2_complex_location_expr_complaint (void)
1650 complaint (_("location expression too complex"));
1654 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1657 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1662 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1664 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1668 /* Hash function for line_header_hash. */
1671 line_header_hash (const struct line_header
*ofs
)
1673 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1676 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1679 line_header_hash_voidp (const void *item
)
1681 const struct line_header
*ofs
= (const struct line_header
*) item
;
1683 return line_header_hash (ofs
);
1686 /* Equality function for line_header_hash. */
1689 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1691 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1692 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1694 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1695 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1700 /* See declaration. */
1702 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1703 const dwarf2_debug_sections
*names
,
1705 : objfile (objfile_
),
1706 can_copy (can_copy_
)
1709 names
= &dwarf2_elf_names
;
1711 bfd
*obfd
= objfile
->obfd
;
1713 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1714 locate_sections (obfd
, sec
, *names
);
1717 dwarf2_per_objfile::~dwarf2_per_objfile ()
1719 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1720 free_cached_comp_units ();
1722 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1723 per_cu
->imported_symtabs_free ();
1725 for (signatured_type
*sig_type
: all_type_units
)
1726 sig_type
->per_cu
.imported_symtabs_free ();
1728 /* Everything else should be on the objfile obstack. */
1731 /* See declaration. */
1734 dwarf2_per_objfile::free_cached_comp_units ()
1736 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1737 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1738 while (per_cu
!= NULL
)
1740 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1743 *last_chain
= next_cu
;
1748 /* A helper class that calls free_cached_comp_units on
1751 class free_cached_comp_units
1755 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1756 : m_per_objfile (per_objfile
)
1760 ~free_cached_comp_units ()
1762 m_per_objfile
->free_cached_comp_units ();
1765 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1769 dwarf2_per_objfile
*m_per_objfile
;
1772 /* Try to locate the sections we need for DWARF 2 debugging
1773 information and return true if we have enough to do something.
1774 NAMES points to the dwarf2 section names, or is NULL if the standard
1775 ELF names are used. CAN_COPY is true for formats where symbol
1776 interposition is possible and so symbol values must follow copy
1777 relocation rules. */
1780 dwarf2_has_info (struct objfile
*objfile
,
1781 const struct dwarf2_debug_sections
*names
,
1784 if (objfile
->flags
& OBJF_READNEVER
)
1787 struct dwarf2_per_objfile
*dwarf2_per_objfile
1788 = get_dwarf2_per_objfile (objfile
);
1790 if (dwarf2_per_objfile
== NULL
)
1791 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1795 return (!dwarf2_per_objfile
->info
.is_virtual
1796 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1797 && !dwarf2_per_objfile
->abbrev
.is_virtual
1798 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1801 /* When loading sections, we look either for uncompressed section or for
1802 compressed section names. */
1805 section_is_p (const char *section_name
,
1806 const struct dwarf2_section_names
*names
)
1808 if (names
->normal
!= NULL
1809 && strcmp (section_name
, names
->normal
) == 0)
1811 if (names
->compressed
!= NULL
1812 && strcmp (section_name
, names
->compressed
) == 0)
1817 /* See declaration. */
1820 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1821 const dwarf2_debug_sections
&names
)
1823 flagword aflag
= bfd_section_flags (sectp
);
1825 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1828 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1829 > bfd_get_file_size (abfd
))
1831 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1832 warning (_("Discarding section %s which has a section size (%s"
1833 ") larger than the file size [in module %s]"),
1834 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1835 bfd_get_filename (abfd
));
1837 else if (section_is_p (sectp
->name
, &names
.info
))
1839 this->info
.s
.section
= sectp
;
1840 this->info
.size
= bfd_section_size (sectp
);
1842 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1844 this->abbrev
.s
.section
= sectp
;
1845 this->abbrev
.size
= bfd_section_size (sectp
);
1847 else if (section_is_p (sectp
->name
, &names
.line
))
1849 this->line
.s
.section
= sectp
;
1850 this->line
.size
= bfd_section_size (sectp
);
1852 else if (section_is_p (sectp
->name
, &names
.loc
))
1854 this->loc
.s
.section
= sectp
;
1855 this->loc
.size
= bfd_section_size (sectp
);
1857 else if (section_is_p (sectp
->name
, &names
.loclists
))
1859 this->loclists
.s
.section
= sectp
;
1860 this->loclists
.size
= bfd_section_size (sectp
);
1862 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1864 this->macinfo
.s
.section
= sectp
;
1865 this->macinfo
.size
= bfd_section_size (sectp
);
1867 else if (section_is_p (sectp
->name
, &names
.macro
))
1869 this->macro
.s
.section
= sectp
;
1870 this->macro
.size
= bfd_section_size (sectp
);
1872 else if (section_is_p (sectp
->name
, &names
.str
))
1874 this->str
.s
.section
= sectp
;
1875 this->str
.size
= bfd_section_size (sectp
);
1877 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1879 this->str_offsets
.s
.section
= sectp
;
1880 this->str_offsets
.size
= bfd_section_size (sectp
);
1882 else if (section_is_p (sectp
->name
, &names
.line_str
))
1884 this->line_str
.s
.section
= sectp
;
1885 this->line_str
.size
= bfd_section_size (sectp
);
1887 else if (section_is_p (sectp
->name
, &names
.addr
))
1889 this->addr
.s
.section
= sectp
;
1890 this->addr
.size
= bfd_section_size (sectp
);
1892 else if (section_is_p (sectp
->name
, &names
.frame
))
1894 this->frame
.s
.section
= sectp
;
1895 this->frame
.size
= bfd_section_size (sectp
);
1897 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1899 this->eh_frame
.s
.section
= sectp
;
1900 this->eh_frame
.size
= bfd_section_size (sectp
);
1902 else if (section_is_p (sectp
->name
, &names
.ranges
))
1904 this->ranges
.s
.section
= sectp
;
1905 this->ranges
.size
= bfd_section_size (sectp
);
1907 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1909 this->rnglists
.s
.section
= sectp
;
1910 this->rnglists
.size
= bfd_section_size (sectp
);
1912 else if (section_is_p (sectp
->name
, &names
.types
))
1914 struct dwarf2_section_info type_section
;
1916 memset (&type_section
, 0, sizeof (type_section
));
1917 type_section
.s
.section
= sectp
;
1918 type_section
.size
= bfd_section_size (sectp
);
1920 this->types
.push_back (type_section
);
1922 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1924 this->gdb_index
.s
.section
= sectp
;
1925 this->gdb_index
.size
= bfd_section_size (sectp
);
1927 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1929 this->debug_names
.s
.section
= sectp
;
1930 this->debug_names
.size
= bfd_section_size (sectp
);
1932 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1934 this->debug_aranges
.s
.section
= sectp
;
1935 this->debug_aranges
.size
= bfd_section_size (sectp
);
1938 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1939 && bfd_section_vma (sectp
) == 0)
1940 this->has_section_at_zero
= true;
1943 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1947 dwarf2_get_section_info (struct objfile
*objfile
,
1948 enum dwarf2_section_enum sect
,
1949 asection
**sectp
, const gdb_byte
**bufp
,
1950 bfd_size_type
*sizep
)
1952 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
1953 struct dwarf2_section_info
*info
;
1955 /* We may see an objfile without any DWARF, in which case we just
1966 case DWARF2_DEBUG_FRAME
:
1967 info
= &data
->frame
;
1969 case DWARF2_EH_FRAME
:
1970 info
= &data
->eh_frame
;
1973 gdb_assert_not_reached ("unexpected section");
1976 info
->read (objfile
);
1978 *sectp
= info
->get_bfd_section ();
1979 *bufp
= info
->buffer
;
1980 *sizep
= info
->size
;
1983 /* A helper function to find the sections for a .dwz file. */
1986 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
1988 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
1990 /* Note that we only support the standard ELF names, because .dwz
1991 is ELF-only (at the time of writing). */
1992 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
1994 dwz_file
->abbrev
.s
.section
= sectp
;
1995 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
1997 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
1999 dwz_file
->info
.s
.section
= sectp
;
2000 dwz_file
->info
.size
= bfd_section_size (sectp
);
2002 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2004 dwz_file
->str
.s
.section
= sectp
;
2005 dwz_file
->str
.size
= bfd_section_size (sectp
);
2007 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2009 dwz_file
->line
.s
.section
= sectp
;
2010 dwz_file
->line
.size
= bfd_section_size (sectp
);
2012 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2014 dwz_file
->macro
.s
.section
= sectp
;
2015 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2017 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2019 dwz_file
->gdb_index
.s
.section
= sectp
;
2020 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2022 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2024 dwz_file
->debug_names
.s
.section
= sectp
;
2025 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2029 /* See dwarf2read.h. */
2032 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2034 const char *filename
;
2035 bfd_size_type buildid_len_arg
;
2039 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2040 return dwarf2_per_objfile
->dwz_file
.get ();
2042 bfd_set_error (bfd_error_no_error
);
2043 gdb::unique_xmalloc_ptr
<char> data
2044 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2045 &buildid_len_arg
, &buildid
));
2048 if (bfd_get_error () == bfd_error_no_error
)
2050 error (_("could not read '.gnu_debugaltlink' section: %s"),
2051 bfd_errmsg (bfd_get_error ()));
2054 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2056 buildid_len
= (size_t) buildid_len_arg
;
2058 filename
= data
.get ();
2060 std::string abs_storage
;
2061 if (!IS_ABSOLUTE_PATH (filename
))
2063 gdb::unique_xmalloc_ptr
<char> abs
2064 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2066 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2067 filename
= abs_storage
.c_str ();
2070 /* First try the file name given in the section. If that doesn't
2071 work, try to use the build-id instead. */
2072 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2073 if (dwz_bfd
!= NULL
)
2075 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2076 dwz_bfd
.reset (nullptr);
2079 if (dwz_bfd
== NULL
)
2080 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2082 if (dwz_bfd
== nullptr)
2084 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2085 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2087 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2094 /* File successfully retrieved from server. */
2095 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2097 if (dwz_bfd
== nullptr)
2098 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2099 alt_filename
.get ());
2100 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2101 dwz_bfd
.reset (nullptr);
2105 if (dwz_bfd
== NULL
)
2106 error (_("could not find '.gnu_debugaltlink' file for %s"),
2107 objfile_name (dwarf2_per_objfile
->objfile
));
2109 std::unique_ptr
<struct dwz_file
> result
2110 (new struct dwz_file (std::move (dwz_bfd
)));
2112 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2115 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2116 result
->dwz_bfd
.get ());
2117 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2118 return dwarf2_per_objfile
->dwz_file
.get ();
2121 /* DWARF quick_symbols_functions support. */
2123 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2124 unique line tables, so we maintain a separate table of all .debug_line
2125 derived entries to support the sharing.
2126 All the quick functions need is the list of file names. We discard the
2127 line_header when we're done and don't need to record it here. */
2128 struct quick_file_names
2130 /* The data used to construct the hash key. */
2131 struct stmt_list_hash hash
;
2133 /* The number of entries in file_names, real_names. */
2134 unsigned int num_file_names
;
2136 /* The file names from the line table, after being run through
2138 const char **file_names
;
2140 /* The file names from the line table after being run through
2141 gdb_realpath. These are computed lazily. */
2142 const char **real_names
;
2145 /* When using the index (and thus not using psymtabs), each CU has an
2146 object of this type. This is used to hold information needed by
2147 the various "quick" methods. */
2148 struct dwarf2_per_cu_quick_data
2150 /* The file table. This can be NULL if there was no file table
2151 or it's currently not read in.
2152 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2153 struct quick_file_names
*file_names
;
2155 /* The corresponding symbol table. This is NULL if symbols for this
2156 CU have not yet been read. */
2157 struct compunit_symtab
*compunit_symtab
;
2159 /* A temporary mark bit used when iterating over all CUs in
2160 expand_symtabs_matching. */
2161 unsigned int mark
: 1;
2163 /* True if we've tried to read the file table and found there isn't one.
2164 There will be no point in trying to read it again next time. */
2165 unsigned int no_file_data
: 1;
2168 /* Utility hash function for a stmt_list_hash. */
2171 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2175 if (stmt_list_hash
->dwo_unit
!= NULL
)
2176 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2177 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2181 /* Utility equality function for a stmt_list_hash. */
2184 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2185 const struct stmt_list_hash
*rhs
)
2187 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2189 if (lhs
->dwo_unit
!= NULL
2190 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2193 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2196 /* Hash function for a quick_file_names. */
2199 hash_file_name_entry (const void *e
)
2201 const struct quick_file_names
*file_data
2202 = (const struct quick_file_names
*) e
;
2204 return hash_stmt_list_entry (&file_data
->hash
);
2207 /* Equality function for a quick_file_names. */
2210 eq_file_name_entry (const void *a
, const void *b
)
2212 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2213 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2215 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2218 /* Delete function for a quick_file_names. */
2221 delete_file_name_entry (void *e
)
2223 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2226 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2228 xfree ((void*) file_data
->file_names
[i
]);
2229 if (file_data
->real_names
)
2230 xfree ((void*) file_data
->real_names
[i
]);
2233 /* The space for the struct itself lives on objfile_obstack,
2234 so we don't free it here. */
2237 /* Create a quick_file_names hash table. */
2240 create_quick_file_names_table (unsigned int nr_initial_entries
)
2242 return htab_up (htab_create_alloc (nr_initial_entries
,
2243 hash_file_name_entry
, eq_file_name_entry
,
2244 delete_file_name_entry
, xcalloc
, xfree
));
2247 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2248 have to be created afterwards. You should call age_cached_comp_units after
2249 processing PER_CU->CU. dw2_setup must have been already called. */
2252 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2254 if (per_cu
->is_debug_types
)
2255 load_full_type_unit (per_cu
);
2257 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2259 if (per_cu
->cu
== NULL
)
2260 return; /* Dummy CU. */
2262 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2265 /* Read in the symbols for PER_CU. */
2268 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2270 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2272 /* Skip type_unit_groups, reading the type units they contain
2273 is handled elsewhere. */
2274 if (per_cu
->type_unit_group_p ())
2277 /* The destructor of dwarf2_queue_guard frees any entries left on
2278 the queue. After this point we're guaranteed to leave this function
2279 with the dwarf queue empty. */
2280 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2282 if (dwarf2_per_objfile
->using_index
2283 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2284 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2286 queue_comp_unit (per_cu
, language_minimal
);
2287 load_cu (per_cu
, skip_partial
);
2289 /* If we just loaded a CU from a DWO, and we're working with an index
2290 that may badly handle TUs, load all the TUs in that DWO as well.
2291 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2292 if (!per_cu
->is_debug_types
2293 && per_cu
->cu
!= NULL
2294 && per_cu
->cu
->dwo_unit
!= NULL
2295 && dwarf2_per_objfile
->index_table
!= NULL
2296 && dwarf2_per_objfile
->index_table
->version
<= 7
2297 /* DWP files aren't supported yet. */
2298 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2299 queue_and_load_all_dwo_tus (per_cu
);
2302 process_queue (dwarf2_per_objfile
);
2304 /* Age the cache, releasing compilation units that have not
2305 been used recently. */
2306 age_cached_comp_units (dwarf2_per_objfile
);
2309 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2310 the objfile from which this CU came. Returns the resulting symbol
2313 static struct compunit_symtab
*
2314 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2316 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2318 gdb_assert (dwarf2_per_objfile
->using_index
);
2319 if (!per_cu
->v
.quick
->compunit_symtab
)
2321 free_cached_comp_units
freer (dwarf2_per_objfile
);
2322 scoped_restore decrementer
= increment_reading_symtab ();
2323 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2324 process_cu_includes (dwarf2_per_objfile
);
2327 return per_cu
->v
.quick
->compunit_symtab
;
2330 /* See declaration. */
2332 dwarf2_per_cu_data
*
2333 dwarf2_per_objfile::get_cutu (int index
)
2335 if (index
>= this->all_comp_units
.size ())
2337 index
-= this->all_comp_units
.size ();
2338 gdb_assert (index
< this->all_type_units
.size ());
2339 return &this->all_type_units
[index
]->per_cu
;
2342 return this->all_comp_units
[index
];
2345 /* See declaration. */
2347 dwarf2_per_cu_data
*
2348 dwarf2_per_objfile::get_cu (int index
)
2350 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2352 return this->all_comp_units
[index
];
2355 /* See declaration. */
2358 dwarf2_per_objfile::get_tu (int index
)
2360 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2362 return this->all_type_units
[index
];
2365 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2366 objfile_obstack, and constructed with the specified field
2369 static dwarf2_per_cu_data
*
2370 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2371 struct dwarf2_section_info
*section
,
2373 sect_offset sect_off
, ULONGEST length
)
2375 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2376 dwarf2_per_cu_data
*the_cu
2377 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2378 struct dwarf2_per_cu_data
);
2379 the_cu
->sect_off
= sect_off
;
2380 the_cu
->length
= length
;
2381 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2382 the_cu
->section
= section
;
2383 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2384 struct dwarf2_per_cu_quick_data
);
2385 the_cu
->is_dwz
= is_dwz
;
2389 /* A helper for create_cus_from_index that handles a given list of
2393 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2394 const gdb_byte
*cu_list
, offset_type n_elements
,
2395 struct dwarf2_section_info
*section
,
2398 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2400 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2402 sect_offset sect_off
2403 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2404 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2407 dwarf2_per_cu_data
*per_cu
2408 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2410 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2414 /* Read the CU list from the mapped index, and use it to create all
2415 the CU objects for this objfile. */
2418 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2419 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2420 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2422 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2423 dwarf2_per_objfile
->all_comp_units
.reserve
2424 ((cu_list_elements
+ dwz_elements
) / 2);
2426 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2427 &dwarf2_per_objfile
->info
, 0);
2429 if (dwz_elements
== 0)
2432 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2433 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2437 /* Create the signatured type hash table from the index. */
2440 create_signatured_type_table_from_index
2441 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2442 struct dwarf2_section_info
*section
,
2443 const gdb_byte
*bytes
,
2444 offset_type elements
)
2446 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2448 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2449 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2451 htab_up sig_types_hash
= allocate_signatured_type_table ();
2453 for (offset_type i
= 0; i
< elements
; i
+= 3)
2455 struct signatured_type
*sig_type
;
2458 cu_offset type_offset_in_tu
;
2460 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2461 sect_offset sect_off
2462 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2464 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2466 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2469 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2470 struct signatured_type
);
2471 sig_type
->signature
= signature
;
2472 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2473 sig_type
->per_cu
.is_debug_types
= 1;
2474 sig_type
->per_cu
.section
= section
;
2475 sig_type
->per_cu
.sect_off
= sect_off
;
2476 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2477 sig_type
->per_cu
.v
.quick
2478 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2479 struct dwarf2_per_cu_quick_data
);
2481 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2484 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2487 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2490 /* Create the signatured type hash table from .debug_names. */
2493 create_signatured_type_table_from_debug_names
2494 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2495 const mapped_debug_names
&map
,
2496 struct dwarf2_section_info
*section
,
2497 struct dwarf2_section_info
*abbrev_section
)
2499 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2501 section
->read (objfile
);
2502 abbrev_section
->read (objfile
);
2504 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2505 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2507 htab_up sig_types_hash
= allocate_signatured_type_table ();
2509 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2511 struct signatured_type
*sig_type
;
2514 sect_offset sect_off
2515 = (sect_offset
) (extract_unsigned_integer
2516 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2518 map
.dwarf5_byte_order
));
2520 comp_unit_head cu_header
;
2521 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2523 section
->buffer
+ to_underlying (sect_off
),
2526 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2527 struct signatured_type
);
2528 sig_type
->signature
= cu_header
.signature
;
2529 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2530 sig_type
->per_cu
.is_debug_types
= 1;
2531 sig_type
->per_cu
.section
= section
;
2532 sig_type
->per_cu
.sect_off
= sect_off
;
2533 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2534 sig_type
->per_cu
.v
.quick
2535 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2536 struct dwarf2_per_cu_quick_data
);
2538 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2541 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2544 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2547 /* Read the address map data from the mapped index, and use it to
2548 populate the objfile's psymtabs_addrmap. */
2551 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2552 struct mapped_index
*index
)
2554 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2555 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2556 const gdb_byte
*iter
, *end
;
2557 struct addrmap
*mutable_map
;
2560 auto_obstack temp_obstack
;
2562 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2564 iter
= index
->address_table
.data ();
2565 end
= iter
+ index
->address_table
.size ();
2567 baseaddr
= objfile
->text_section_offset ();
2571 ULONGEST hi
, lo
, cu_index
;
2572 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2574 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2576 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2581 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2582 hex_string (lo
), hex_string (hi
));
2586 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2588 complaint (_(".gdb_index address table has invalid CU number %u"),
2589 (unsigned) cu_index
);
2593 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2594 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2595 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2596 dwarf2_per_objfile
->get_cu (cu_index
));
2599 objfile
->partial_symtabs
->psymtabs_addrmap
2600 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2603 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2604 populate the objfile's psymtabs_addrmap. */
2607 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2608 struct dwarf2_section_info
*section
)
2610 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2611 bfd
*abfd
= objfile
->obfd
;
2612 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2613 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2615 auto_obstack temp_obstack
;
2616 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2618 std::unordered_map
<sect_offset
,
2619 dwarf2_per_cu_data
*,
2620 gdb::hash_enum
<sect_offset
>>
2621 debug_info_offset_to_per_cu
;
2622 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2624 const auto insertpair
2625 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2626 if (!insertpair
.second
)
2628 warning (_("Section .debug_aranges in %s has duplicate "
2629 "debug_info_offset %s, ignoring .debug_aranges."),
2630 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2635 section
->read (objfile
);
2637 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2639 const gdb_byte
*addr
= section
->buffer
;
2641 while (addr
< section
->buffer
+ section
->size
)
2643 const gdb_byte
*const entry_addr
= addr
;
2644 unsigned int bytes_read
;
2646 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2650 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2651 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2652 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2653 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2655 warning (_("Section .debug_aranges in %s entry at offset %s "
2656 "length %s exceeds section length %s, "
2657 "ignoring .debug_aranges."),
2658 objfile_name (objfile
),
2659 plongest (entry_addr
- section
->buffer
),
2660 plongest (bytes_read
+ entry_length
),
2661 pulongest (section
->size
));
2665 /* The version number. */
2666 const uint16_t version
= read_2_bytes (abfd
, addr
);
2670 warning (_("Section .debug_aranges in %s entry at offset %s "
2671 "has unsupported version %d, ignoring .debug_aranges."),
2672 objfile_name (objfile
),
2673 plongest (entry_addr
- section
->buffer
), version
);
2677 const uint64_t debug_info_offset
2678 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2679 addr
+= offset_size
;
2680 const auto per_cu_it
2681 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2682 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2684 warning (_("Section .debug_aranges in %s entry at offset %s "
2685 "debug_info_offset %s does not exists, "
2686 "ignoring .debug_aranges."),
2687 objfile_name (objfile
),
2688 plongest (entry_addr
- section
->buffer
),
2689 pulongest (debug_info_offset
));
2692 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2694 const uint8_t address_size
= *addr
++;
2695 if (address_size
< 1 || address_size
> 8)
2697 warning (_("Section .debug_aranges in %s entry at offset %s "
2698 "address_size %u is invalid, ignoring .debug_aranges."),
2699 objfile_name (objfile
),
2700 plongest (entry_addr
- section
->buffer
), address_size
);
2704 const uint8_t segment_selector_size
= *addr
++;
2705 if (segment_selector_size
!= 0)
2707 warning (_("Section .debug_aranges in %s entry at offset %s "
2708 "segment_selector_size %u is not supported, "
2709 "ignoring .debug_aranges."),
2710 objfile_name (objfile
),
2711 plongest (entry_addr
- section
->buffer
),
2712 segment_selector_size
);
2716 /* Must pad to an alignment boundary that is twice the address
2717 size. It is undocumented by the DWARF standard but GCC does
2719 for (size_t padding
= ((-(addr
- section
->buffer
))
2720 & (2 * address_size
- 1));
2721 padding
> 0; padding
--)
2724 warning (_("Section .debug_aranges in %s entry at offset %s "
2725 "padding is not zero, ignoring .debug_aranges."),
2726 objfile_name (objfile
),
2727 plongest (entry_addr
- section
->buffer
));
2733 if (addr
+ 2 * address_size
> entry_end
)
2735 warning (_("Section .debug_aranges in %s entry at offset %s "
2736 "address list is not properly terminated, "
2737 "ignoring .debug_aranges."),
2738 objfile_name (objfile
),
2739 plongest (entry_addr
- section
->buffer
));
2742 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2744 addr
+= address_size
;
2745 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2747 addr
+= address_size
;
2748 if (start
== 0 && length
== 0)
2750 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2752 /* Symbol was eliminated due to a COMDAT group. */
2755 ULONGEST end
= start
+ length
;
2756 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2758 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2760 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2764 objfile
->partial_symtabs
->psymtabs_addrmap
2765 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2768 /* Find a slot in the mapped index INDEX for the object named NAME.
2769 If NAME is found, set *VEC_OUT to point to the CU vector in the
2770 constant pool and return true. If NAME cannot be found, return
2774 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2775 offset_type
**vec_out
)
2778 offset_type slot
, step
;
2779 int (*cmp
) (const char *, const char *);
2781 gdb::unique_xmalloc_ptr
<char> without_params
;
2782 if (current_language
->la_language
== language_cplus
2783 || current_language
->la_language
== language_fortran
2784 || current_language
->la_language
== language_d
)
2786 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2789 if (strchr (name
, '(') != NULL
)
2791 without_params
= cp_remove_params (name
);
2793 if (without_params
!= NULL
)
2794 name
= without_params
.get ();
2798 /* Index version 4 did not support case insensitive searches. But the
2799 indices for case insensitive languages are built in lowercase, therefore
2800 simulate our NAME being searched is also lowercased. */
2801 hash
= mapped_index_string_hash ((index
->version
== 4
2802 && case_sensitivity
== case_sensitive_off
2803 ? 5 : index
->version
),
2806 slot
= hash
& (index
->symbol_table
.size () - 1);
2807 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2808 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2814 const auto &bucket
= index
->symbol_table
[slot
];
2815 if (bucket
.name
== 0 && bucket
.vec
== 0)
2818 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2819 if (!cmp (name
, str
))
2821 *vec_out
= (offset_type
*) (index
->constant_pool
2822 + MAYBE_SWAP (bucket
.vec
));
2826 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2830 /* A helper function that reads the .gdb_index from BUFFER and fills
2831 in MAP. FILENAME is the name of the file containing the data;
2832 it is used for error reporting. DEPRECATED_OK is true if it is
2833 ok to use deprecated sections.
2835 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2836 out parameters that are filled in with information about the CU and
2837 TU lists in the section.
2839 Returns true if all went well, false otherwise. */
2842 read_gdb_index_from_buffer (struct objfile
*objfile
,
2843 const char *filename
,
2845 gdb::array_view
<const gdb_byte
> buffer
,
2846 struct mapped_index
*map
,
2847 const gdb_byte
**cu_list
,
2848 offset_type
*cu_list_elements
,
2849 const gdb_byte
**types_list
,
2850 offset_type
*types_list_elements
)
2852 const gdb_byte
*addr
= &buffer
[0];
2854 /* Version check. */
2855 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2856 /* Versions earlier than 3 emitted every copy of a psymbol. This
2857 causes the index to behave very poorly for certain requests. Version 3
2858 contained incomplete addrmap. So, it seems better to just ignore such
2862 static int warning_printed
= 0;
2863 if (!warning_printed
)
2865 warning (_("Skipping obsolete .gdb_index section in %s."),
2867 warning_printed
= 1;
2871 /* Index version 4 uses a different hash function than index version
2874 Versions earlier than 6 did not emit psymbols for inlined
2875 functions. Using these files will cause GDB not to be able to
2876 set breakpoints on inlined functions by name, so we ignore these
2877 indices unless the user has done
2878 "set use-deprecated-index-sections on". */
2879 if (version
< 6 && !deprecated_ok
)
2881 static int warning_printed
= 0;
2882 if (!warning_printed
)
2885 Skipping deprecated .gdb_index section in %s.\n\
2886 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2887 to use the section anyway."),
2889 warning_printed
= 1;
2893 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2894 of the TU (for symbols coming from TUs),
2895 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2896 Plus gold-generated indices can have duplicate entries for global symbols,
2897 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2898 These are just performance bugs, and we can't distinguish gdb-generated
2899 indices from gold-generated ones, so issue no warning here. */
2901 /* Indexes with higher version than the one supported by GDB may be no
2902 longer backward compatible. */
2906 map
->version
= version
;
2908 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2911 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2912 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2916 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2917 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2918 - MAYBE_SWAP (metadata
[i
]))
2922 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2923 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2925 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2928 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2929 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2931 = gdb::array_view
<mapped_index::symbol_table_slot
>
2932 ((mapped_index::symbol_table_slot
*) symbol_table
,
2933 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2936 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2941 /* Callback types for dwarf2_read_gdb_index. */
2943 typedef gdb::function_view
2944 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2945 get_gdb_index_contents_ftype
;
2946 typedef gdb::function_view
2947 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2948 get_gdb_index_contents_dwz_ftype
;
2950 /* Read .gdb_index. If everything went ok, initialize the "quick"
2951 elements of all the CUs and return 1. Otherwise, return 0. */
2954 dwarf2_read_gdb_index
2955 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2956 get_gdb_index_contents_ftype get_gdb_index_contents
,
2957 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2959 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2960 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2961 struct dwz_file
*dwz
;
2962 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2964 gdb::array_view
<const gdb_byte
> main_index_contents
2965 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
2967 if (main_index_contents
.empty ())
2970 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2971 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
2972 use_deprecated_index_sections
,
2973 main_index_contents
, map
.get (), &cu_list
,
2974 &cu_list_elements
, &types_list
,
2975 &types_list_elements
))
2978 /* Don't use the index if it's empty. */
2979 if (map
->symbol_table
.empty ())
2982 /* If there is a .dwz file, read it so we can get its CU list as
2984 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2987 struct mapped_index dwz_map
;
2988 const gdb_byte
*dwz_types_ignore
;
2989 offset_type dwz_types_elements_ignore
;
2991 gdb::array_view
<const gdb_byte
> dwz_index_content
2992 = get_gdb_index_contents_dwz (objfile
, dwz
);
2994 if (dwz_index_content
.empty ())
2997 if (!read_gdb_index_from_buffer (objfile
,
2998 bfd_get_filename (dwz
->dwz_bfd
.get ()),
2999 1, dwz_index_content
, &dwz_map
,
3000 &dwz_list
, &dwz_list_elements
,
3002 &dwz_types_elements_ignore
))
3004 warning (_("could not read '.gdb_index' section from %s; skipping"),
3005 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3010 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3011 dwz_list
, dwz_list_elements
);
3013 if (types_list_elements
)
3015 /* We can only handle a single .debug_types when we have an
3017 if (dwarf2_per_objfile
->types
.size () != 1)
3020 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3022 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3023 types_list
, types_list_elements
);
3026 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3028 dwarf2_per_objfile
->index_table
= std::move (map
);
3029 dwarf2_per_objfile
->using_index
= 1;
3030 dwarf2_per_objfile
->quick_file_names_table
=
3031 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3036 /* die_reader_func for dw2_get_file_names. */
3039 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3040 const gdb_byte
*info_ptr
,
3041 struct die_info
*comp_unit_die
)
3043 struct dwarf2_cu
*cu
= reader
->cu
;
3044 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3045 struct dwarf2_per_objfile
*dwarf2_per_objfile
3046 = cu
->per_cu
->dwarf2_per_objfile
;
3047 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3048 struct dwarf2_per_cu_data
*lh_cu
;
3049 struct attribute
*attr
;
3051 struct quick_file_names
*qfn
;
3053 gdb_assert (! this_cu
->is_debug_types
);
3055 /* Our callers never want to match partial units -- instead they
3056 will match the enclosing full CU. */
3057 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3059 this_cu
->v
.quick
->no_file_data
= 1;
3067 sect_offset line_offset
{};
3069 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3070 if (attr
!= nullptr)
3072 struct quick_file_names find_entry
;
3074 line_offset
= (sect_offset
) DW_UNSND (attr
);
3076 /* We may have already read in this line header (TU line header sharing).
3077 If we have we're done. */
3078 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3079 find_entry
.hash
.line_sect_off
= line_offset
;
3080 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3081 &find_entry
, INSERT
);
3084 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3088 lh
= dwarf_decode_line_header (line_offset
, cu
);
3092 lh_cu
->v
.quick
->no_file_data
= 1;
3096 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3097 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3098 qfn
->hash
.line_sect_off
= line_offset
;
3099 gdb_assert (slot
!= NULL
);
3102 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3105 if (strcmp (fnd
.name
, "<unknown>") != 0)
3108 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3110 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3112 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3113 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3114 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3115 fnd
.comp_dir
).release ();
3116 qfn
->real_names
= NULL
;
3118 lh_cu
->v
.quick
->file_names
= qfn
;
3121 /* A helper for the "quick" functions which attempts to read the line
3122 table for THIS_CU. */
3124 static struct quick_file_names
*
3125 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3127 /* This should never be called for TUs. */
3128 gdb_assert (! this_cu
->is_debug_types
);
3129 /* Nor type unit groups. */
3130 gdb_assert (! this_cu
->type_unit_group_p ());
3132 if (this_cu
->v
.quick
->file_names
!= NULL
)
3133 return this_cu
->v
.quick
->file_names
;
3134 /* If we know there is no line data, no point in looking again. */
3135 if (this_cu
->v
.quick
->no_file_data
)
3138 cutu_reader
reader (this_cu
);
3139 if (!reader
.dummy_p
)
3140 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3142 if (this_cu
->v
.quick
->no_file_data
)
3144 return this_cu
->v
.quick
->file_names
;
3147 /* A helper for the "quick" functions which computes and caches the
3148 real path for a given file name from the line table. */
3151 dw2_get_real_path (struct objfile
*objfile
,
3152 struct quick_file_names
*qfn
, int index
)
3154 if (qfn
->real_names
== NULL
)
3155 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3156 qfn
->num_file_names
, const char *);
3158 if (qfn
->real_names
[index
] == NULL
)
3159 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3161 return qfn
->real_names
[index
];
3164 static struct symtab
*
3165 dw2_find_last_source_symtab (struct objfile
*objfile
)
3167 struct dwarf2_per_objfile
*dwarf2_per_objfile
3168 = get_dwarf2_per_objfile (objfile
);
3169 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3170 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3175 return compunit_primary_filetab (cust
);
3178 /* Traversal function for dw2_forget_cached_source_info. */
3181 dw2_free_cached_file_names (void **slot
, void *info
)
3183 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3185 if (file_data
->real_names
)
3189 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3191 xfree ((void*) file_data
->real_names
[i
]);
3192 file_data
->real_names
[i
] = NULL
;
3200 dw2_forget_cached_source_info (struct objfile
*objfile
)
3202 struct dwarf2_per_objfile
*dwarf2_per_objfile
3203 = get_dwarf2_per_objfile (objfile
);
3205 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3206 dw2_free_cached_file_names
, NULL
);
3209 /* Helper function for dw2_map_symtabs_matching_filename that expands
3210 the symtabs and calls the iterator. */
3213 dw2_map_expand_apply (struct objfile
*objfile
,
3214 struct dwarf2_per_cu_data
*per_cu
,
3215 const char *name
, const char *real_path
,
3216 gdb::function_view
<bool (symtab
*)> callback
)
3218 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3220 /* Don't visit already-expanded CUs. */
3221 if (per_cu
->v
.quick
->compunit_symtab
)
3224 /* This may expand more than one symtab, and we want to iterate over
3226 dw2_instantiate_symtab (per_cu
, false);
3228 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3229 last_made
, callback
);
3232 /* Implementation of the map_symtabs_matching_filename method. */
3235 dw2_map_symtabs_matching_filename
3236 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3237 gdb::function_view
<bool (symtab
*)> callback
)
3239 const char *name_basename
= lbasename (name
);
3240 struct dwarf2_per_objfile
*dwarf2_per_objfile
3241 = get_dwarf2_per_objfile (objfile
);
3243 /* The rule is CUs specify all the files, including those used by
3244 any TU, so there's no need to scan TUs here. */
3246 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3248 /* We only need to look at symtabs not already expanded. */
3249 if (per_cu
->v
.quick
->compunit_symtab
)
3252 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3253 if (file_data
== NULL
)
3256 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3258 const char *this_name
= file_data
->file_names
[j
];
3259 const char *this_real_name
;
3261 if (compare_filenames_for_search (this_name
, name
))
3263 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3269 /* Before we invoke realpath, which can get expensive when many
3270 files are involved, do a quick comparison of the basenames. */
3271 if (! basenames_may_differ
3272 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3275 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3276 if (compare_filenames_for_search (this_real_name
, name
))
3278 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3284 if (real_path
!= NULL
)
3286 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3287 gdb_assert (IS_ABSOLUTE_PATH (name
));
3288 if (this_real_name
!= NULL
3289 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3291 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3303 /* Struct used to manage iterating over all CUs looking for a symbol. */
3305 struct dw2_symtab_iterator
3307 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3308 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3309 /* If set, only look for symbols that match that block. Valid values are
3310 GLOBAL_BLOCK and STATIC_BLOCK. */
3311 gdb::optional
<block_enum
> block_index
;
3312 /* The kind of symbol we're looking for. */
3314 /* The list of CUs from the index entry of the symbol,
3315 or NULL if not found. */
3317 /* The next element in VEC to look at. */
3319 /* The number of elements in VEC, or zero if there is no match. */
3321 /* Have we seen a global version of the symbol?
3322 If so we can ignore all further global instances.
3323 This is to work around gold/15646, inefficient gold-generated
3328 /* Initialize the index symtab iterator ITER. */
3331 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3332 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3333 gdb::optional
<block_enum
> block_index
,
3337 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3338 iter
->block_index
= block_index
;
3339 iter
->domain
= domain
;
3341 iter
->global_seen
= 0;
3343 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3345 /* index is NULL if OBJF_READNOW. */
3346 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3347 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3355 /* Return the next matching CU or NULL if there are no more. */
3357 static struct dwarf2_per_cu_data
*
3358 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3360 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3362 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3364 offset_type cu_index_and_attrs
=
3365 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3366 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3367 gdb_index_symbol_kind symbol_kind
=
3368 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3369 /* Only check the symbol attributes if they're present.
3370 Indices prior to version 7 don't record them,
3371 and indices >= 7 may elide them for certain symbols
3372 (gold does this). */
3374 (dwarf2_per_objfile
->index_table
->version
>= 7
3375 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3377 /* Don't crash on bad data. */
3378 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3379 + dwarf2_per_objfile
->all_type_units
.size ()))
3381 complaint (_(".gdb_index entry has bad CU index"
3383 objfile_name (dwarf2_per_objfile
->objfile
));
3387 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3389 /* Skip if already read in. */
3390 if (per_cu
->v
.quick
->compunit_symtab
)
3393 /* Check static vs global. */
3396 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3398 if (iter
->block_index
.has_value ())
3400 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3402 if (is_static
!= want_static
)
3406 /* Work around gold/15646. */
3407 if (!is_static
&& iter
->global_seen
)
3410 iter
->global_seen
= 1;
3413 /* Only check the symbol's kind if it has one. */
3416 switch (iter
->domain
)
3419 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3420 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3421 /* Some types are also in VAR_DOMAIN. */
3422 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3426 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3430 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3434 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3449 static struct compunit_symtab
*
3450 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3451 const char *name
, domain_enum domain
)
3453 struct compunit_symtab
*stab_best
= NULL
;
3454 struct dwarf2_per_objfile
*dwarf2_per_objfile
3455 = get_dwarf2_per_objfile (objfile
);
3457 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3459 struct dw2_symtab_iterator iter
;
3460 struct dwarf2_per_cu_data
*per_cu
;
3462 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3464 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3466 struct symbol
*sym
, *with_opaque
= NULL
;
3467 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3468 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3469 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3471 sym
= block_find_symbol (block
, name
, domain
,
3472 block_find_non_opaque_type_preferred
,
3475 /* Some caution must be observed with overloaded functions
3476 and methods, since the index will not contain any overload
3477 information (but NAME might contain it). */
3480 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3482 if (with_opaque
!= NULL
3483 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3486 /* Keep looking through other CUs. */
3493 dw2_print_stats (struct objfile
*objfile
)
3495 struct dwarf2_per_objfile
*dwarf2_per_objfile
3496 = get_dwarf2_per_objfile (objfile
);
3497 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3498 + dwarf2_per_objfile
->all_type_units
.size ());
3501 for (int i
= 0; i
< total
; ++i
)
3503 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3505 if (!per_cu
->v
.quick
->compunit_symtab
)
3508 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3509 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3512 /* This dumps minimal information about the index.
3513 It is called via "mt print objfiles".
3514 One use is to verify .gdb_index has been loaded by the
3515 gdb.dwarf2/gdb-index.exp testcase. */
3518 dw2_dump (struct objfile
*objfile
)
3520 struct dwarf2_per_objfile
*dwarf2_per_objfile
3521 = get_dwarf2_per_objfile (objfile
);
3523 gdb_assert (dwarf2_per_objfile
->using_index
);
3524 printf_filtered (".gdb_index:");
3525 if (dwarf2_per_objfile
->index_table
!= NULL
)
3527 printf_filtered (" version %d\n",
3528 dwarf2_per_objfile
->index_table
->version
);
3531 printf_filtered (" faked for \"readnow\"\n");
3532 printf_filtered ("\n");
3536 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3537 const char *func_name
)
3539 struct dwarf2_per_objfile
*dwarf2_per_objfile
3540 = get_dwarf2_per_objfile (objfile
);
3542 struct dw2_symtab_iterator iter
;
3543 struct dwarf2_per_cu_data
*per_cu
;
3545 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3547 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3548 dw2_instantiate_symtab (per_cu
, false);
3553 dw2_expand_all_symtabs (struct objfile
*objfile
)
3555 struct dwarf2_per_objfile
*dwarf2_per_objfile
3556 = get_dwarf2_per_objfile (objfile
);
3557 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3558 + dwarf2_per_objfile
->all_type_units
.size ());
3560 for (int i
= 0; i
< total_units
; ++i
)
3562 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3564 /* We don't want to directly expand a partial CU, because if we
3565 read it with the wrong language, then assertion failures can
3566 be triggered later on. See PR symtab/23010. So, tell
3567 dw2_instantiate_symtab to skip partial CUs -- any important
3568 partial CU will be read via DW_TAG_imported_unit anyway. */
3569 dw2_instantiate_symtab (per_cu
, true);
3574 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3575 const char *fullname
)
3577 struct dwarf2_per_objfile
*dwarf2_per_objfile
3578 = get_dwarf2_per_objfile (objfile
);
3580 /* We don't need to consider type units here.
3581 This is only called for examining code, e.g. expand_line_sal.
3582 There can be an order of magnitude (or more) more type units
3583 than comp units, and we avoid them if we can. */
3585 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3587 /* We only need to look at symtabs not already expanded. */
3588 if (per_cu
->v
.quick
->compunit_symtab
)
3591 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3592 if (file_data
== NULL
)
3595 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3597 const char *this_fullname
= file_data
->file_names
[j
];
3599 if (filename_cmp (this_fullname
, fullname
) == 0)
3601 dw2_instantiate_symtab (per_cu
, false);
3609 dw2_map_matching_symbols
3610 (struct objfile
*objfile
,
3611 const lookup_name_info
&name
, domain_enum domain
,
3613 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3614 symbol_compare_ftype
*ordered_compare
)
3616 /* Currently unimplemented; used for Ada. The function can be called if the
3617 current language is Ada for a non-Ada objfile using GNU index. As Ada
3618 does not look for non-Ada symbols this function should just return. */
3621 /* Starting from a search name, return the string that finds the upper
3622 bound of all strings that start with SEARCH_NAME in a sorted name
3623 list. Returns the empty string to indicate that the upper bound is
3624 the end of the list. */
3627 make_sort_after_prefix_name (const char *search_name
)
3629 /* When looking to complete "func", we find the upper bound of all
3630 symbols that start with "func" by looking for where we'd insert
3631 the closest string that would follow "func" in lexicographical
3632 order. Usually, that's "func"-with-last-character-incremented,
3633 i.e. "fund". Mind non-ASCII characters, though. Usually those
3634 will be UTF-8 multi-byte sequences, but we can't be certain.
3635 Especially mind the 0xff character, which is a valid character in
3636 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3637 rule out compilers allowing it in identifiers. Note that
3638 conveniently, strcmp/strcasecmp are specified to compare
3639 characters interpreted as unsigned char. So what we do is treat
3640 the whole string as a base 256 number composed of a sequence of
3641 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3642 to 0, and carries 1 to the following more-significant position.
3643 If the very first character in SEARCH_NAME ends up incremented
3644 and carries/overflows, then the upper bound is the end of the
3645 list. The string after the empty string is also the empty
3648 Some examples of this operation:
3650 SEARCH_NAME => "+1" RESULT
3654 "\xff" "a" "\xff" => "\xff" "b"
3659 Then, with these symbols for example:
3665 completing "func" looks for symbols between "func" and
3666 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3667 which finds "func" and "func1", but not "fund".
3671 funcÿ (Latin1 'ÿ' [0xff])
3675 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3676 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3680 ÿÿ (Latin1 'ÿ' [0xff])
3683 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3684 the end of the list.
3686 std::string after
= search_name
;
3687 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3689 if (!after
.empty ())
3690 after
.back () = (unsigned char) after
.back () + 1;
3694 /* See declaration. */
3696 std::pair
<std::vector
<name_component
>::const_iterator
,
3697 std::vector
<name_component
>::const_iterator
>
3698 mapped_index_base::find_name_components_bounds
3699 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3702 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3704 const char *lang_name
3705 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3707 /* Comparison function object for lower_bound that matches against a
3708 given symbol name. */
3709 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3712 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3713 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3714 return name_cmp (elem_name
, name
) < 0;
3717 /* Comparison function object for upper_bound that matches against a
3718 given symbol name. */
3719 auto lookup_compare_upper
= [&] (const char *name
,
3720 const name_component
&elem
)
3722 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3723 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3724 return name_cmp (name
, elem_name
) < 0;
3727 auto begin
= this->name_components
.begin ();
3728 auto end
= this->name_components
.end ();
3730 /* Find the lower bound. */
3733 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3736 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3739 /* Find the upper bound. */
3742 if (lookup_name_without_params
.completion_mode ())
3744 /* In completion mode, we want UPPER to point past all
3745 symbols names that have the same prefix. I.e., with
3746 these symbols, and completing "func":
3748 function << lower bound
3750 other_function << upper bound
3752 We find the upper bound by looking for the insertion
3753 point of "func"-with-last-character-incremented,
3755 std::string after
= make_sort_after_prefix_name (lang_name
);
3758 return std::lower_bound (lower
, end
, after
.c_str (),
3759 lookup_compare_lower
);
3762 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3765 return {lower
, upper
};
3768 /* See declaration. */
3771 mapped_index_base::build_name_components ()
3773 if (!this->name_components
.empty ())
3776 this->name_components_casing
= case_sensitivity
;
3778 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3780 /* The code below only knows how to break apart components of C++
3781 symbol names (and other languages that use '::' as
3782 namespace/module separator) and Ada symbol names. */
3783 auto count
= this->symbol_name_count ();
3784 for (offset_type idx
= 0; idx
< count
; idx
++)
3786 if (this->symbol_name_slot_invalid (idx
))
3789 const char *name
= this->symbol_name_at (idx
);
3791 /* Add each name component to the name component table. */
3792 unsigned int previous_len
= 0;
3794 if (strstr (name
, "::") != nullptr)
3796 for (unsigned int current_len
= cp_find_first_component (name
);
3797 name
[current_len
] != '\0';
3798 current_len
+= cp_find_first_component (name
+ current_len
))
3800 gdb_assert (name
[current_len
] == ':');
3801 this->name_components
.push_back ({previous_len
, idx
});
3802 /* Skip the '::'. */
3804 previous_len
= current_len
;
3809 /* Handle the Ada encoded (aka mangled) form here. */
3810 for (const char *iter
= strstr (name
, "__");
3812 iter
= strstr (iter
, "__"))
3814 this->name_components
.push_back ({previous_len
, idx
});
3816 previous_len
= iter
- name
;
3820 this->name_components
.push_back ({previous_len
, idx
});
3823 /* Sort name_components elements by name. */
3824 auto name_comp_compare
= [&] (const name_component
&left
,
3825 const name_component
&right
)
3827 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3828 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3830 const char *left_name
= left_qualified
+ left
.name_offset
;
3831 const char *right_name
= right_qualified
+ right
.name_offset
;
3833 return name_cmp (left_name
, right_name
) < 0;
3836 std::sort (this->name_components
.begin (),
3837 this->name_components
.end (),
3841 /* Helper for dw2_expand_symtabs_matching that works with a
3842 mapped_index_base instead of the containing objfile. This is split
3843 to a separate function in order to be able to unit test the
3844 name_components matching using a mock mapped_index_base. For each
3845 symbol name that matches, calls MATCH_CALLBACK, passing it the
3846 symbol's index in the mapped_index_base symbol table. */
3849 dw2_expand_symtabs_matching_symbol
3850 (mapped_index_base
&index
,
3851 const lookup_name_info
&lookup_name_in
,
3852 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3853 enum search_domain kind
,
3854 gdb::function_view
<bool (offset_type
)> match_callback
)
3856 lookup_name_info lookup_name_without_params
3857 = lookup_name_in
.make_ignore_params ();
3859 /* Build the symbol name component sorted vector, if we haven't
3861 index
.build_name_components ();
3863 /* The same symbol may appear more than once in the range though.
3864 E.g., if we're looking for symbols that complete "w", and we have
3865 a symbol named "w1::w2", we'll find the two name components for
3866 that same symbol in the range. To be sure we only call the
3867 callback once per symbol, we first collect the symbol name
3868 indexes that matched in a temporary vector and ignore
3870 std::vector
<offset_type
> matches
;
3872 struct name_and_matcher
3874 symbol_name_matcher_ftype
*matcher
;
3875 const std::string
&name
;
3877 bool operator== (const name_and_matcher
&other
) const
3879 return matcher
== other
.matcher
&& name
== other
.name
;
3883 /* A vector holding all the different symbol name matchers, for all
3885 std::vector
<name_and_matcher
> matchers
;
3887 for (int i
= 0; i
< nr_languages
; i
++)
3889 enum language lang_e
= (enum language
) i
;
3891 const language_defn
*lang
= language_def (lang_e
);
3892 symbol_name_matcher_ftype
*name_matcher
3893 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3895 name_and_matcher key
{
3897 lookup_name_without_params
.language_lookup_name (lang_e
)
3900 /* Don't insert the same comparison routine more than once.
3901 Note that we do this linear walk. This is not a problem in
3902 practice because the number of supported languages is
3904 if (std::find (matchers
.begin (), matchers
.end (), key
)
3907 matchers
.push_back (std::move (key
));
3910 = index
.find_name_components_bounds (lookup_name_without_params
,
3913 /* Now for each symbol name in range, check to see if we have a name
3914 match, and if so, call the MATCH_CALLBACK callback. */
3916 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3918 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3920 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3921 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3924 matches
.push_back (bounds
.first
->idx
);
3928 std::sort (matches
.begin (), matches
.end ());
3930 /* Finally call the callback, once per match. */
3932 for (offset_type idx
: matches
)
3936 if (!match_callback (idx
))
3942 /* Above we use a type wider than idx's for 'prev', since 0 and
3943 (offset_type)-1 are both possible values. */
3944 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3949 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3951 /* A mock .gdb_index/.debug_names-like name index table, enough to
3952 exercise dw2_expand_symtabs_matching_symbol, which works with the
3953 mapped_index_base interface. Builds an index from the symbol list
3954 passed as parameter to the constructor. */
3955 class mock_mapped_index
: public mapped_index_base
3958 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3959 : m_symbol_table (symbols
)
3962 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3964 /* Return the number of names in the symbol table. */
3965 size_t symbol_name_count () const override
3967 return m_symbol_table
.size ();
3970 /* Get the name of the symbol at IDX in the symbol table. */
3971 const char *symbol_name_at (offset_type idx
) const override
3973 return m_symbol_table
[idx
];
3977 gdb::array_view
<const char *> m_symbol_table
;
3980 /* Convenience function that converts a NULL pointer to a "<null>"
3981 string, to pass to print routines. */
3984 string_or_null (const char *str
)
3986 return str
!= NULL
? str
: "<null>";
3989 /* Check if a lookup_name_info built from
3990 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3991 index. EXPECTED_LIST is the list of expected matches, in expected
3992 matching order. If no match expected, then an empty list is
3993 specified. Returns true on success. On failure prints a warning
3994 indicating the file:line that failed, and returns false. */
3997 check_match (const char *file
, int line
,
3998 mock_mapped_index
&mock_index
,
3999 const char *name
, symbol_name_match_type match_type
,
4000 bool completion_mode
,
4001 std::initializer_list
<const char *> expected_list
)
4003 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4005 bool matched
= true;
4007 auto mismatch
= [&] (const char *expected_str
,
4010 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4011 "expected=\"%s\", got=\"%s\"\n"),
4013 (match_type
== symbol_name_match_type::FULL
4015 name
, string_or_null (expected_str
), string_or_null (got
));
4019 auto expected_it
= expected_list
.begin ();
4020 auto expected_end
= expected_list
.end ();
4022 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4024 [&] (offset_type idx
)
4026 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4027 const char *expected_str
4028 = expected_it
== expected_end
? NULL
: *expected_it
++;
4030 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4031 mismatch (expected_str
, matched_name
);
4035 const char *expected_str
4036 = expected_it
== expected_end
? NULL
: *expected_it
++;
4037 if (expected_str
!= NULL
)
4038 mismatch (expected_str
, NULL
);
4043 /* The symbols added to the mock mapped_index for testing (in
4045 static const char *test_symbols
[] = {
4054 "ns2::tmpl<int>::foo2",
4055 "(anonymous namespace)::A::B::C",
4057 /* These are used to check that the increment-last-char in the
4058 matching algorithm for completion doesn't match "t1_fund" when
4059 completing "t1_func". */
4065 /* A UTF-8 name with multi-byte sequences to make sure that
4066 cp-name-parser understands this as a single identifier ("função"
4067 is "function" in PT). */
4070 /* \377 (0xff) is Latin1 'ÿ'. */
4073 /* \377 (0xff) is Latin1 'ÿ'. */
4077 /* A name with all sorts of complications. Starts with "z" to make
4078 it easier for the completion tests below. */
4079 #define Z_SYM_NAME \
4080 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4081 "::tuple<(anonymous namespace)::ui*, " \
4082 "std::default_delete<(anonymous namespace)::ui>, void>"
4087 /* Returns true if the mapped_index_base::find_name_component_bounds
4088 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4089 in completion mode. */
4092 check_find_bounds_finds (mapped_index_base
&index
,
4093 const char *search_name
,
4094 gdb::array_view
<const char *> expected_syms
)
4096 lookup_name_info
lookup_name (search_name
,
4097 symbol_name_match_type::FULL
, true);
4099 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4102 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4103 if (distance
!= expected_syms
.size ())
4106 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4108 auto nc_elem
= bounds
.first
+ exp_elem
;
4109 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4110 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4117 /* Test the lower-level mapped_index::find_name_component_bounds
4121 test_mapped_index_find_name_component_bounds ()
4123 mock_mapped_index
mock_index (test_symbols
);
4125 mock_index
.build_name_components ();
4127 /* Test the lower-level mapped_index::find_name_component_bounds
4128 method in completion mode. */
4130 static const char *expected_syms
[] = {
4135 SELF_CHECK (check_find_bounds_finds (mock_index
,
4136 "t1_func", expected_syms
));
4139 /* Check that the increment-last-char in the name matching algorithm
4140 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4142 static const char *expected_syms1
[] = {
4146 SELF_CHECK (check_find_bounds_finds (mock_index
,
4147 "\377", expected_syms1
));
4149 static const char *expected_syms2
[] = {
4152 SELF_CHECK (check_find_bounds_finds (mock_index
,
4153 "\377\377", expected_syms2
));
4157 /* Test dw2_expand_symtabs_matching_symbol. */
4160 test_dw2_expand_symtabs_matching_symbol ()
4162 mock_mapped_index
mock_index (test_symbols
);
4164 /* We let all tests run until the end even if some fails, for debug
4166 bool any_mismatch
= false;
4168 /* Create the expected symbols list (an initializer_list). Needed
4169 because lists have commas, and we need to pass them to CHECK,
4170 which is a macro. */
4171 #define EXPECT(...) { __VA_ARGS__ }
4173 /* Wrapper for check_match that passes down the current
4174 __FILE__/__LINE__. */
4175 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4176 any_mismatch |= !check_match (__FILE__, __LINE__, \
4178 NAME, MATCH_TYPE, COMPLETION_MODE, \
4181 /* Identity checks. */
4182 for (const char *sym
: test_symbols
)
4184 /* Should be able to match all existing symbols. */
4185 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4188 /* Should be able to match all existing symbols with
4190 std::string with_params
= std::string (sym
) + "(int)";
4191 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4194 /* Should be able to match all existing symbols with
4195 parameters and qualifiers. */
4196 with_params
= std::string (sym
) + " ( int ) const";
4197 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4200 /* This should really find sym, but cp-name-parser.y doesn't
4201 know about lvalue/rvalue qualifiers yet. */
4202 with_params
= std::string (sym
) + " ( int ) &&";
4203 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4207 /* Check that the name matching algorithm for completion doesn't get
4208 confused with Latin1 'ÿ' / 0xff. */
4210 static const char str
[] = "\377";
4211 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4212 EXPECT ("\377", "\377\377123"));
4215 /* Check that the increment-last-char in the matching algorithm for
4216 completion doesn't match "t1_fund" when completing "t1_func". */
4218 static const char str
[] = "t1_func";
4219 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4220 EXPECT ("t1_func", "t1_func1"));
4223 /* Check that completion mode works at each prefix of the expected
4226 static const char str
[] = "function(int)";
4227 size_t len
= strlen (str
);
4230 for (size_t i
= 1; i
< len
; i
++)
4232 lookup
.assign (str
, i
);
4233 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4234 EXPECT ("function"));
4238 /* While "w" is a prefix of both components, the match function
4239 should still only be called once. */
4241 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4243 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4247 /* Same, with a "complicated" symbol. */
4249 static const char str
[] = Z_SYM_NAME
;
4250 size_t len
= strlen (str
);
4253 for (size_t i
= 1; i
< len
; i
++)
4255 lookup
.assign (str
, i
);
4256 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4257 EXPECT (Z_SYM_NAME
));
4261 /* In FULL mode, an incomplete symbol doesn't match. */
4263 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4267 /* A complete symbol with parameters matches any overload, since the
4268 index has no overload info. */
4270 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4271 EXPECT ("std::zfunction", "std::zfunction2"));
4272 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4273 EXPECT ("std::zfunction", "std::zfunction2"));
4274 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4275 EXPECT ("std::zfunction", "std::zfunction2"));
4278 /* Check that whitespace is ignored appropriately. A symbol with a
4279 template argument list. */
4281 static const char expected
[] = "ns::foo<int>";
4282 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4284 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4288 /* Check that whitespace is ignored appropriately. A symbol with a
4289 template argument list that includes a pointer. */
4291 static const char expected
[] = "ns::foo<char*>";
4292 /* Try both completion and non-completion modes. */
4293 static const bool completion_mode
[2] = {false, true};
4294 for (size_t i
= 0; i
< 2; i
++)
4296 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4297 completion_mode
[i
], EXPECT (expected
));
4298 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4299 completion_mode
[i
], EXPECT (expected
));
4301 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4302 completion_mode
[i
], EXPECT (expected
));
4303 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4304 completion_mode
[i
], EXPECT (expected
));
4309 /* Check method qualifiers are ignored. */
4310 static const char expected
[] = "ns::foo<char*>";
4311 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4312 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4313 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4314 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4315 CHECK_MATCH ("foo < char * > ( int ) const",
4316 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4317 CHECK_MATCH ("foo < char * > ( int ) &&",
4318 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4321 /* Test lookup names that don't match anything. */
4323 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4326 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4330 /* Some wild matching tests, exercising "(anonymous namespace)",
4331 which should not be confused with a parameter list. */
4333 static const char *syms
[] = {
4337 "A :: B :: C ( int )",
4342 for (const char *s
: syms
)
4344 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4345 EXPECT ("(anonymous namespace)::A::B::C"));
4350 static const char expected
[] = "ns2::tmpl<int>::foo2";
4351 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4353 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4357 SELF_CHECK (!any_mismatch
);
4366 test_mapped_index_find_name_component_bounds ();
4367 test_dw2_expand_symtabs_matching_symbol ();
4370 }} // namespace selftests::dw2_expand_symtabs_matching
4372 #endif /* GDB_SELF_TEST */
4374 /* If FILE_MATCHER is NULL or if PER_CU has
4375 dwarf2_per_cu_quick_data::MARK set (see
4376 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4377 EXPANSION_NOTIFY on it. */
4380 dw2_expand_symtabs_matching_one
4381 (struct dwarf2_per_cu_data
*per_cu
,
4382 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4383 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4385 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4387 bool symtab_was_null
4388 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4390 dw2_instantiate_symtab (per_cu
, false);
4392 if (expansion_notify
!= NULL
4394 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4395 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4399 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4400 matched, to expand corresponding CUs that were marked. IDX is the
4401 index of the symbol name that matched. */
4404 dw2_expand_marked_cus
4405 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4406 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4407 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4410 offset_type
*vec
, vec_len
, vec_idx
;
4411 bool global_seen
= false;
4412 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4414 vec
= (offset_type
*) (index
.constant_pool
4415 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4416 vec_len
= MAYBE_SWAP (vec
[0]);
4417 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4419 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4420 /* This value is only valid for index versions >= 7. */
4421 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4422 gdb_index_symbol_kind symbol_kind
=
4423 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4424 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4425 /* Only check the symbol attributes if they're present.
4426 Indices prior to version 7 don't record them,
4427 and indices >= 7 may elide them for certain symbols
4428 (gold does this). */
4431 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4433 /* Work around gold/15646. */
4436 if (!is_static
&& global_seen
)
4442 /* Only check the symbol's kind if it has one. */
4447 case VARIABLES_DOMAIN
:
4448 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4451 case FUNCTIONS_DOMAIN
:
4452 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4456 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4459 case MODULES_DOMAIN
:
4460 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4468 /* Don't crash on bad data. */
4469 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4470 + dwarf2_per_objfile
->all_type_units
.size ()))
4472 complaint (_(".gdb_index entry has bad CU index"
4474 objfile_name (dwarf2_per_objfile
->objfile
));
4478 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4479 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4484 /* If FILE_MATCHER is non-NULL, set all the
4485 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4486 that match FILE_MATCHER. */
4489 dw_expand_symtabs_matching_file_matcher
4490 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4491 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4493 if (file_matcher
== NULL
)
4496 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4498 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4500 NULL
, xcalloc
, xfree
));
4501 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4503 NULL
, xcalloc
, xfree
));
4505 /* The rule is CUs specify all the files, including those used by
4506 any TU, so there's no need to scan TUs here. */
4508 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4512 per_cu
->v
.quick
->mark
= 0;
4514 /* We only need to look at symtabs not already expanded. */
4515 if (per_cu
->v
.quick
->compunit_symtab
)
4518 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4519 if (file_data
== NULL
)
4522 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4524 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4526 per_cu
->v
.quick
->mark
= 1;
4530 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4532 const char *this_real_name
;
4534 if (file_matcher (file_data
->file_names
[j
], false))
4536 per_cu
->v
.quick
->mark
= 1;
4540 /* Before we invoke realpath, which can get expensive when many
4541 files are involved, do a quick comparison of the basenames. */
4542 if (!basenames_may_differ
4543 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4547 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4548 if (file_matcher (this_real_name
, false))
4550 per_cu
->v
.quick
->mark
= 1;
4555 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4556 ? visited_found
.get ()
4557 : visited_not_found
.get (),
4564 dw2_expand_symtabs_matching
4565 (struct objfile
*objfile
,
4566 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4567 const lookup_name_info
&lookup_name
,
4568 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4569 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4570 enum search_domain kind
)
4572 struct dwarf2_per_objfile
*dwarf2_per_objfile
4573 = get_dwarf2_per_objfile (objfile
);
4575 /* index_table is NULL if OBJF_READNOW. */
4576 if (!dwarf2_per_objfile
->index_table
)
4579 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4581 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4583 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4585 kind
, [&] (offset_type idx
)
4587 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4588 expansion_notify
, kind
);
4593 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4596 static struct compunit_symtab
*
4597 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4602 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4603 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4606 if (cust
->includes
== NULL
)
4609 for (i
= 0; cust
->includes
[i
]; ++i
)
4611 struct compunit_symtab
*s
= cust
->includes
[i
];
4613 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4621 static struct compunit_symtab
*
4622 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4623 struct bound_minimal_symbol msymbol
,
4625 struct obj_section
*section
,
4628 struct dwarf2_per_cu_data
*data
;
4629 struct compunit_symtab
*result
;
4631 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4634 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4635 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4636 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4640 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4641 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4642 paddress (get_objfile_arch (objfile
), pc
));
4645 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4648 gdb_assert (result
!= NULL
);
4653 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4654 void *data
, int need_fullname
)
4656 struct dwarf2_per_objfile
*dwarf2_per_objfile
4657 = get_dwarf2_per_objfile (objfile
);
4659 if (!dwarf2_per_objfile
->filenames_cache
)
4661 dwarf2_per_objfile
->filenames_cache
.emplace ();
4663 htab_up
visited (htab_create_alloc (10,
4664 htab_hash_pointer
, htab_eq_pointer
,
4665 NULL
, xcalloc
, xfree
));
4667 /* The rule is CUs specify all the files, including those used
4668 by any TU, so there's no need to scan TUs here. We can
4669 ignore file names coming from already-expanded CUs. */
4671 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4673 if (per_cu
->v
.quick
->compunit_symtab
)
4675 void **slot
= htab_find_slot (visited
.get (),
4676 per_cu
->v
.quick
->file_names
,
4679 *slot
= per_cu
->v
.quick
->file_names
;
4683 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4685 /* We only need to look at symtabs not already expanded. */
4686 if (per_cu
->v
.quick
->compunit_symtab
)
4689 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4690 if (file_data
== NULL
)
4693 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4696 /* Already visited. */
4701 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4703 const char *filename
= file_data
->file_names
[j
];
4704 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4709 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4711 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4714 this_real_name
= gdb_realpath (filename
);
4715 (*fun
) (filename
, this_real_name
.get (), data
);
4720 dw2_has_symbols (struct objfile
*objfile
)
4725 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4728 dw2_find_last_source_symtab
,
4729 dw2_forget_cached_source_info
,
4730 dw2_map_symtabs_matching_filename
,
4734 dw2_expand_symtabs_for_function
,
4735 dw2_expand_all_symtabs
,
4736 dw2_expand_symtabs_with_fullname
,
4737 dw2_map_matching_symbols
,
4738 dw2_expand_symtabs_matching
,
4739 dw2_find_pc_sect_compunit_symtab
,
4741 dw2_map_symbol_filenames
4744 /* DWARF-5 debug_names reader. */
4746 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4747 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4749 /* A helper function that reads the .debug_names section in SECTION
4750 and fills in MAP. FILENAME is the name of the file containing the
4751 section; it is used for error reporting.
4753 Returns true if all went well, false otherwise. */
4756 read_debug_names_from_section (struct objfile
*objfile
,
4757 const char *filename
,
4758 struct dwarf2_section_info
*section
,
4759 mapped_debug_names
&map
)
4761 if (section
->empty ())
4764 /* Older elfutils strip versions could keep the section in the main
4765 executable while splitting it for the separate debug info file. */
4766 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4769 section
->read (objfile
);
4771 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4773 const gdb_byte
*addr
= section
->buffer
;
4775 bfd
*const abfd
= section
->get_bfd_owner ();
4777 unsigned int bytes_read
;
4778 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4781 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4782 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4783 if (bytes_read
+ length
!= section
->size
)
4785 /* There may be multiple per-CU indices. */
4786 warning (_("Section .debug_names in %s length %s does not match "
4787 "section length %s, ignoring .debug_names."),
4788 filename
, plongest (bytes_read
+ length
),
4789 pulongest (section
->size
));
4793 /* The version number. */
4794 uint16_t version
= read_2_bytes (abfd
, addr
);
4798 warning (_("Section .debug_names in %s has unsupported version %d, "
4799 "ignoring .debug_names."),
4805 uint16_t padding
= read_2_bytes (abfd
, addr
);
4809 warning (_("Section .debug_names in %s has unsupported padding %d, "
4810 "ignoring .debug_names."),
4815 /* comp_unit_count - The number of CUs in the CU list. */
4816 map
.cu_count
= read_4_bytes (abfd
, addr
);
4819 /* local_type_unit_count - The number of TUs in the local TU
4821 map
.tu_count
= read_4_bytes (abfd
, addr
);
4824 /* foreign_type_unit_count - The number of TUs in the foreign TU
4826 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4828 if (foreign_tu_count
!= 0)
4830 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4831 "ignoring .debug_names."),
4832 filename
, static_cast<unsigned long> (foreign_tu_count
));
4836 /* bucket_count - The number of hash buckets in the hash lookup
4838 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4841 /* name_count - The number of unique names in the index. */
4842 map
.name_count
= read_4_bytes (abfd
, addr
);
4845 /* abbrev_table_size - The size in bytes of the abbreviations
4847 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4850 /* augmentation_string_size - The size in bytes of the augmentation
4851 string. This value is rounded up to a multiple of 4. */
4852 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4854 map
.augmentation_is_gdb
= ((augmentation_string_size
4855 == sizeof (dwarf5_augmentation
))
4856 && memcmp (addr
, dwarf5_augmentation
,
4857 sizeof (dwarf5_augmentation
)) == 0);
4858 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4859 addr
+= augmentation_string_size
;
4862 map
.cu_table_reordered
= addr
;
4863 addr
+= map
.cu_count
* map
.offset_size
;
4865 /* List of Local TUs */
4866 map
.tu_table_reordered
= addr
;
4867 addr
+= map
.tu_count
* map
.offset_size
;
4869 /* Hash Lookup Table */
4870 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4871 addr
+= map
.bucket_count
* 4;
4872 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4873 addr
+= map
.name_count
* 4;
4876 map
.name_table_string_offs_reordered
= addr
;
4877 addr
+= map
.name_count
* map
.offset_size
;
4878 map
.name_table_entry_offs_reordered
= addr
;
4879 addr
+= map
.name_count
* map
.offset_size
;
4881 const gdb_byte
*abbrev_table_start
= addr
;
4884 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4889 const auto insertpair
4890 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4891 if (!insertpair
.second
)
4893 warning (_("Section .debug_names in %s has duplicate index %s, "
4894 "ignoring .debug_names."),
4895 filename
, pulongest (index_num
));
4898 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4899 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4904 mapped_debug_names::index_val::attr attr
;
4905 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4907 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4909 if (attr
.form
== DW_FORM_implicit_const
)
4911 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4915 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4917 indexval
.attr_vec
.push_back (std::move (attr
));
4920 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4922 warning (_("Section .debug_names in %s has abbreviation_table "
4923 "of size %s vs. written as %u, ignoring .debug_names."),
4924 filename
, plongest (addr
- abbrev_table_start
),
4928 map
.entry_pool
= addr
;
4933 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4937 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4938 const mapped_debug_names
&map
,
4939 dwarf2_section_info
§ion
,
4942 sect_offset sect_off_prev
;
4943 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4945 sect_offset sect_off_next
;
4946 if (i
< map
.cu_count
)
4949 = (sect_offset
) (extract_unsigned_integer
4950 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4952 map
.dwarf5_byte_order
));
4955 sect_off_next
= (sect_offset
) section
.size
;
4958 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4959 dwarf2_per_cu_data
*per_cu
4960 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
4961 sect_off_prev
, length
);
4962 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
4964 sect_off_prev
= sect_off_next
;
4968 /* Read the CU list from the mapped index, and use it to create all
4969 the CU objects for this dwarf2_per_objfile. */
4972 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4973 const mapped_debug_names
&map
,
4974 const mapped_debug_names
&dwz_map
)
4976 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
4977 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4979 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
4980 dwarf2_per_objfile
->info
,
4981 false /* is_dwz */);
4983 if (dwz_map
.cu_count
== 0)
4986 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
4987 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
4991 /* Read .debug_names. If everything went ok, initialize the "quick"
4992 elements of all the CUs and return true. Otherwise, return false. */
4995 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
4997 std::unique_ptr
<mapped_debug_names
> map
4998 (new mapped_debug_names (dwarf2_per_objfile
));
4999 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5000 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5002 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5003 &dwarf2_per_objfile
->debug_names
,
5007 /* Don't use the index if it's empty. */
5008 if (map
->name_count
== 0)
5011 /* If there is a .dwz file, read it so we can get its CU list as
5013 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5016 if (!read_debug_names_from_section (objfile
,
5017 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5018 &dwz
->debug_names
, dwz_map
))
5020 warning (_("could not read '.debug_names' section from %s; skipping"),
5021 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5026 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5028 if (map
->tu_count
!= 0)
5030 /* We can only handle a single .debug_types when we have an
5032 if (dwarf2_per_objfile
->types
.size () != 1)
5035 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5037 create_signatured_type_table_from_debug_names
5038 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5041 create_addrmap_from_aranges (dwarf2_per_objfile
,
5042 &dwarf2_per_objfile
->debug_aranges
);
5044 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5045 dwarf2_per_objfile
->using_index
= 1;
5046 dwarf2_per_objfile
->quick_file_names_table
=
5047 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5052 /* Type used to manage iterating over all CUs looking for a symbol for
5055 class dw2_debug_names_iterator
5058 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5059 gdb::optional
<block_enum
> block_index
,
5062 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5063 m_addr (find_vec_in_debug_names (map
, name
))
5066 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5067 search_domain search
, uint32_t namei
)
5070 m_addr (find_vec_in_debug_names (map
, namei
))
5073 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5074 block_enum block_index
, domain_enum domain
,
5076 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5077 m_addr (find_vec_in_debug_names (map
, namei
))
5080 /* Return the next matching CU or NULL if there are no more. */
5081 dwarf2_per_cu_data
*next ();
5084 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5086 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5089 /* The internalized form of .debug_names. */
5090 const mapped_debug_names
&m_map
;
5092 /* If set, only look for symbols that match that block. Valid values are
5093 GLOBAL_BLOCK and STATIC_BLOCK. */
5094 const gdb::optional
<block_enum
> m_block_index
;
5096 /* The kind of symbol we're looking for. */
5097 const domain_enum m_domain
= UNDEF_DOMAIN
;
5098 const search_domain m_search
= ALL_DOMAIN
;
5100 /* The list of CUs from the index entry of the symbol, or NULL if
5102 const gdb_byte
*m_addr
;
5106 mapped_debug_names::namei_to_name (uint32_t namei
) const
5108 const ULONGEST namei_string_offs
5109 = extract_unsigned_integer ((name_table_string_offs_reordered
5110 + namei
* offset_size
),
5113 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5117 /* Find a slot in .debug_names for the object named NAME. If NAME is
5118 found, return pointer to its pool data. If NAME cannot be found,
5122 dw2_debug_names_iterator::find_vec_in_debug_names
5123 (const mapped_debug_names
&map
, const char *name
)
5125 int (*cmp
) (const char *, const char *);
5127 gdb::unique_xmalloc_ptr
<char> without_params
;
5128 if (current_language
->la_language
== language_cplus
5129 || current_language
->la_language
== language_fortran
5130 || current_language
->la_language
== language_d
)
5132 /* NAME is already canonical. Drop any qualifiers as
5133 .debug_names does not contain any. */
5135 if (strchr (name
, '(') != NULL
)
5137 without_params
= cp_remove_params (name
);
5138 if (without_params
!= NULL
)
5139 name
= without_params
.get ();
5143 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5145 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5147 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5148 (map
.bucket_table_reordered
5149 + (full_hash
% map
.bucket_count
)), 4,
5150 map
.dwarf5_byte_order
);
5154 if (namei
>= map
.name_count
)
5156 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5158 namei
, map
.name_count
,
5159 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5165 const uint32_t namei_full_hash
5166 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5167 (map
.hash_table_reordered
+ namei
), 4,
5168 map
.dwarf5_byte_order
);
5169 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5172 if (full_hash
== namei_full_hash
)
5174 const char *const namei_string
= map
.namei_to_name (namei
);
5176 #if 0 /* An expensive sanity check. */
5177 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5179 complaint (_("Wrong .debug_names hash for string at index %u "
5181 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5186 if (cmp (namei_string
, name
) == 0)
5188 const ULONGEST namei_entry_offs
5189 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5190 + namei
* map
.offset_size
),
5191 map
.offset_size
, map
.dwarf5_byte_order
);
5192 return map
.entry_pool
+ namei_entry_offs
;
5197 if (namei
>= map
.name_count
)
5203 dw2_debug_names_iterator::find_vec_in_debug_names
5204 (const mapped_debug_names
&map
, uint32_t namei
)
5206 if (namei
>= map
.name_count
)
5208 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5210 namei
, map
.name_count
,
5211 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5215 const ULONGEST namei_entry_offs
5216 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5217 + namei
* map
.offset_size
),
5218 map
.offset_size
, map
.dwarf5_byte_order
);
5219 return map
.entry_pool
+ namei_entry_offs
;
5222 /* See dw2_debug_names_iterator. */
5224 dwarf2_per_cu_data
*
5225 dw2_debug_names_iterator::next ()
5230 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5231 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5232 bfd
*const abfd
= objfile
->obfd
;
5236 unsigned int bytes_read
;
5237 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5238 m_addr
+= bytes_read
;
5242 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5243 if (indexval_it
== m_map
.abbrev_map
.cend ())
5245 complaint (_("Wrong .debug_names undefined abbrev code %s "
5247 pulongest (abbrev
), objfile_name (objfile
));
5250 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5251 enum class symbol_linkage
{
5255 } symbol_linkage_
= symbol_linkage::unknown
;
5256 dwarf2_per_cu_data
*per_cu
= NULL
;
5257 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5262 case DW_FORM_implicit_const
:
5263 ull
= attr
.implicit_const
;
5265 case DW_FORM_flag_present
:
5269 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5270 m_addr
+= bytes_read
;
5273 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5274 dwarf_form_name (attr
.form
),
5275 objfile_name (objfile
));
5278 switch (attr
.dw_idx
)
5280 case DW_IDX_compile_unit
:
5281 /* Don't crash on bad data. */
5282 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5284 complaint (_(".debug_names entry has bad CU index %s"
5287 objfile_name (dwarf2_per_objfile
->objfile
));
5290 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5292 case DW_IDX_type_unit
:
5293 /* Don't crash on bad data. */
5294 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5296 complaint (_(".debug_names entry has bad TU index %s"
5299 objfile_name (dwarf2_per_objfile
->objfile
));
5302 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5304 case DW_IDX_GNU_internal
:
5305 if (!m_map
.augmentation_is_gdb
)
5307 symbol_linkage_
= symbol_linkage::static_
;
5309 case DW_IDX_GNU_external
:
5310 if (!m_map
.augmentation_is_gdb
)
5312 symbol_linkage_
= symbol_linkage::extern_
;
5317 /* Skip if already read in. */
5318 if (per_cu
->v
.quick
->compunit_symtab
)
5321 /* Check static vs global. */
5322 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5324 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5325 const bool symbol_is_static
=
5326 symbol_linkage_
== symbol_linkage::static_
;
5327 if (want_static
!= symbol_is_static
)
5331 /* Match dw2_symtab_iter_next, symbol_kind
5332 and debug_names::psymbol_tag. */
5336 switch (indexval
.dwarf_tag
)
5338 case DW_TAG_variable
:
5339 case DW_TAG_subprogram
:
5340 /* Some types are also in VAR_DOMAIN. */
5341 case DW_TAG_typedef
:
5342 case DW_TAG_structure_type
:
5349 switch (indexval
.dwarf_tag
)
5351 case DW_TAG_typedef
:
5352 case DW_TAG_structure_type
:
5359 switch (indexval
.dwarf_tag
)
5362 case DW_TAG_variable
:
5369 switch (indexval
.dwarf_tag
)
5381 /* Match dw2_expand_symtabs_matching, symbol_kind and
5382 debug_names::psymbol_tag. */
5385 case VARIABLES_DOMAIN
:
5386 switch (indexval
.dwarf_tag
)
5388 case DW_TAG_variable
:
5394 case FUNCTIONS_DOMAIN
:
5395 switch (indexval
.dwarf_tag
)
5397 case DW_TAG_subprogram
:
5404 switch (indexval
.dwarf_tag
)
5406 case DW_TAG_typedef
:
5407 case DW_TAG_structure_type
:
5413 case MODULES_DOMAIN
:
5414 switch (indexval
.dwarf_tag
)
5428 static struct compunit_symtab
*
5429 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5430 const char *name
, domain_enum domain
)
5432 struct dwarf2_per_objfile
*dwarf2_per_objfile
5433 = get_dwarf2_per_objfile (objfile
);
5435 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5438 /* index is NULL if OBJF_READNOW. */
5441 const auto &map
= *mapp
;
5443 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5445 struct compunit_symtab
*stab_best
= NULL
;
5446 struct dwarf2_per_cu_data
*per_cu
;
5447 while ((per_cu
= iter
.next ()) != NULL
)
5449 struct symbol
*sym
, *with_opaque
= NULL
;
5450 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5451 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5452 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5454 sym
= block_find_symbol (block
, name
, domain
,
5455 block_find_non_opaque_type_preferred
,
5458 /* Some caution must be observed with overloaded functions and
5459 methods, since the index will not contain any overload
5460 information (but NAME might contain it). */
5463 && strcmp_iw (sym
->search_name (), name
) == 0)
5465 if (with_opaque
!= NULL
5466 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5469 /* Keep looking through other CUs. */
5475 /* This dumps minimal information about .debug_names. It is called
5476 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5477 uses this to verify that .debug_names has been loaded. */
5480 dw2_debug_names_dump (struct objfile
*objfile
)
5482 struct dwarf2_per_objfile
*dwarf2_per_objfile
5483 = get_dwarf2_per_objfile (objfile
);
5485 gdb_assert (dwarf2_per_objfile
->using_index
);
5486 printf_filtered (".debug_names:");
5487 if (dwarf2_per_objfile
->debug_names_table
)
5488 printf_filtered (" exists\n");
5490 printf_filtered (" faked for \"readnow\"\n");
5491 printf_filtered ("\n");
5495 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5496 const char *func_name
)
5498 struct dwarf2_per_objfile
*dwarf2_per_objfile
5499 = get_dwarf2_per_objfile (objfile
);
5501 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5502 if (dwarf2_per_objfile
->debug_names_table
)
5504 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5506 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5508 struct dwarf2_per_cu_data
*per_cu
;
5509 while ((per_cu
= iter
.next ()) != NULL
)
5510 dw2_instantiate_symtab (per_cu
, false);
5515 dw2_debug_names_map_matching_symbols
5516 (struct objfile
*objfile
,
5517 const lookup_name_info
&name
, domain_enum domain
,
5519 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5520 symbol_compare_ftype
*ordered_compare
)
5522 struct dwarf2_per_objfile
*dwarf2_per_objfile
5523 = get_dwarf2_per_objfile (objfile
);
5525 /* debug_names_table is NULL if OBJF_READNOW. */
5526 if (!dwarf2_per_objfile
->debug_names_table
)
5529 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5530 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5532 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5533 auto matcher
= [&] (const char *symname
)
5535 if (ordered_compare
== nullptr)
5537 return ordered_compare (symname
, match_name
) == 0;
5540 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5541 [&] (offset_type namei
)
5543 /* The name was matched, now expand corresponding CUs that were
5545 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5547 struct dwarf2_per_cu_data
*per_cu
;
5548 while ((per_cu
= iter
.next ()) != NULL
)
5549 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5553 /* It's a shame we couldn't do this inside the
5554 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5555 that have already been expanded. Instead, this loop matches what
5556 the psymtab code does. */
5557 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5559 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5560 if (cust
!= nullptr)
5562 const struct block
*block
5563 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5564 if (!iterate_over_symbols_terminated (block
, name
,
5572 dw2_debug_names_expand_symtabs_matching
5573 (struct objfile
*objfile
,
5574 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5575 const lookup_name_info
&lookup_name
,
5576 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5577 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5578 enum search_domain kind
)
5580 struct dwarf2_per_objfile
*dwarf2_per_objfile
5581 = get_dwarf2_per_objfile (objfile
);
5583 /* debug_names_table is NULL if OBJF_READNOW. */
5584 if (!dwarf2_per_objfile
->debug_names_table
)
5587 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5589 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5591 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5593 kind
, [&] (offset_type namei
)
5595 /* The name was matched, now expand corresponding CUs that were
5597 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5599 struct dwarf2_per_cu_data
*per_cu
;
5600 while ((per_cu
= iter
.next ()) != NULL
)
5601 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5607 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5610 dw2_find_last_source_symtab
,
5611 dw2_forget_cached_source_info
,
5612 dw2_map_symtabs_matching_filename
,
5613 dw2_debug_names_lookup_symbol
,
5615 dw2_debug_names_dump
,
5616 dw2_debug_names_expand_symtabs_for_function
,
5617 dw2_expand_all_symtabs
,
5618 dw2_expand_symtabs_with_fullname
,
5619 dw2_debug_names_map_matching_symbols
,
5620 dw2_debug_names_expand_symtabs_matching
,
5621 dw2_find_pc_sect_compunit_symtab
,
5623 dw2_map_symbol_filenames
5626 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5627 to either a dwarf2_per_objfile or dwz_file object. */
5629 template <typename T
>
5630 static gdb::array_view
<const gdb_byte
>
5631 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5633 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5635 if (section
->empty ())
5638 /* Older elfutils strip versions could keep the section in the main
5639 executable while splitting it for the separate debug info file. */
5640 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5643 section
->read (obj
);
5645 /* dwarf2_section_info::size is a bfd_size_type, while
5646 gdb::array_view works with size_t. On 32-bit hosts, with
5647 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5648 is 32-bit. So we need an explicit narrowing conversion here.
5649 This is fine, because it's impossible to allocate or mmap an
5650 array/buffer larger than what size_t can represent. */
5651 return gdb::make_array_view (section
->buffer
, section
->size
);
5654 /* Lookup the index cache for the contents of the index associated to
5657 static gdb::array_view
<const gdb_byte
>
5658 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5660 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5661 if (build_id
== nullptr)
5664 return global_index_cache
.lookup_gdb_index (build_id
,
5665 &dwarf2_obj
->index_cache_res
);
5668 /* Same as the above, but for DWZ. */
5670 static gdb::array_view
<const gdb_byte
>
5671 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5673 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5674 if (build_id
== nullptr)
5677 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5680 /* See symfile.h. */
5683 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5685 struct dwarf2_per_objfile
*dwarf2_per_objfile
5686 = get_dwarf2_per_objfile (objfile
);
5688 /* If we're about to read full symbols, don't bother with the
5689 indices. In this case we also don't care if some other debug
5690 format is making psymtabs, because they are all about to be
5692 if ((objfile
->flags
& OBJF_READNOW
))
5694 dwarf2_per_objfile
->using_index
= 1;
5695 create_all_comp_units (dwarf2_per_objfile
);
5696 create_all_type_units (dwarf2_per_objfile
);
5697 dwarf2_per_objfile
->quick_file_names_table
5698 = create_quick_file_names_table
5699 (dwarf2_per_objfile
->all_comp_units
.size ());
5701 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5702 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5704 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5706 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5707 struct dwarf2_per_cu_quick_data
);
5710 /* Return 1 so that gdb sees the "quick" functions. However,
5711 these functions will be no-ops because we will have expanded
5713 *index_kind
= dw_index_kind::GDB_INDEX
;
5717 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5719 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5723 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5724 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5725 get_gdb_index_contents_from_section
<dwz_file
>))
5727 *index_kind
= dw_index_kind::GDB_INDEX
;
5731 /* ... otherwise, try to find the index in the index cache. */
5732 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5733 get_gdb_index_contents_from_cache
,
5734 get_gdb_index_contents_from_cache_dwz
))
5736 global_index_cache
.hit ();
5737 *index_kind
= dw_index_kind::GDB_INDEX
;
5741 global_index_cache
.miss ();
5747 /* Build a partial symbol table. */
5750 dwarf2_build_psymtabs (struct objfile
*objfile
)
5752 struct dwarf2_per_objfile
*dwarf2_per_objfile
5753 = get_dwarf2_per_objfile (objfile
);
5755 init_psymbol_list (objfile
, 1024);
5759 /* This isn't really ideal: all the data we allocate on the
5760 objfile's obstack is still uselessly kept around. However,
5761 freeing it seems unsafe. */
5762 psymtab_discarder
psymtabs (objfile
);
5763 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5766 /* (maybe) store an index in the cache. */
5767 global_index_cache
.store (dwarf2_per_objfile
);
5769 catch (const gdb_exception_error
&except
)
5771 exception_print (gdb_stderr
, except
);
5775 /* Find the base address of the compilation unit for range lists and
5776 location lists. It will normally be specified by DW_AT_low_pc.
5777 In DWARF-3 draft 4, the base address could be overridden by
5778 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5779 compilation units with discontinuous ranges. */
5782 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5784 struct attribute
*attr
;
5787 cu
->base_address
= 0;
5789 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5790 if (attr
!= nullptr)
5792 cu
->base_address
= attr
->value_as_address ();
5797 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5798 if (attr
!= nullptr)
5800 cu
->base_address
= attr
->value_as_address ();
5806 /* Helper function that returns the proper abbrev section for
5809 static struct dwarf2_section_info
*
5810 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5812 struct dwarf2_section_info
*abbrev
;
5813 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5815 if (this_cu
->is_dwz
)
5816 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5818 abbrev
= &dwarf2_per_objfile
->abbrev
;
5823 /* Fetch the abbreviation table offset from a comp or type unit header. */
5826 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5827 struct dwarf2_section_info
*section
,
5828 sect_offset sect_off
)
5830 bfd
*abfd
= section
->get_bfd_owner ();
5831 const gdb_byte
*info_ptr
;
5832 unsigned int initial_length_size
, offset_size
;
5835 section
->read (dwarf2_per_objfile
->objfile
);
5836 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5837 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5838 offset_size
= initial_length_size
== 4 ? 4 : 8;
5839 info_ptr
+= initial_length_size
;
5841 version
= read_2_bytes (abfd
, info_ptr
);
5845 /* Skip unit type and address size. */
5849 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5852 /* A partial symtab that is used only for include files. */
5853 struct dwarf2_include_psymtab
: public partial_symtab
5855 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5856 : partial_symtab (filename
, objfile
)
5860 void read_symtab (struct objfile
*objfile
) override
5862 expand_psymtab (objfile
);
5865 void expand_psymtab (struct objfile
*objfile
) override
5869 /* It's an include file, no symbols to read for it.
5870 Everything is in the parent symtab. */
5871 read_dependencies (objfile
);
5875 bool readin_p () const override
5880 struct compunit_symtab
*get_compunit_symtab () const override
5887 bool m_readin
= false;
5890 /* Allocate a new partial symtab for file named NAME and mark this new
5891 partial symtab as being an include of PST. */
5894 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5895 struct objfile
*objfile
)
5897 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5899 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5901 /* It shares objfile->objfile_obstack. */
5902 subpst
->dirname
= pst
->dirname
;
5905 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5906 subpst
->dependencies
[0] = pst
;
5907 subpst
->number_of_dependencies
= 1;
5910 /* Read the Line Number Program data and extract the list of files
5911 included by the source file represented by PST. Build an include
5912 partial symtab for each of these included files. */
5915 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5916 struct die_info
*die
,
5917 dwarf2_psymtab
*pst
)
5920 struct attribute
*attr
;
5922 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5923 if (attr
!= nullptr)
5924 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5926 return; /* No linetable, so no includes. */
5928 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5929 that we pass in the raw text_low here; that is ok because we're
5930 only decoding the line table to make include partial symtabs, and
5931 so the addresses aren't really used. */
5932 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5933 pst
->raw_text_low (), 1);
5937 hash_signatured_type (const void *item
)
5939 const struct signatured_type
*sig_type
5940 = (const struct signatured_type
*) item
;
5942 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5943 return sig_type
->signature
;
5947 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5949 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5950 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5952 return lhs
->signature
== rhs
->signature
;
5955 /* Allocate a hash table for signatured types. */
5958 allocate_signatured_type_table ()
5960 return htab_up (htab_create_alloc (41,
5961 hash_signatured_type
,
5963 NULL
, xcalloc
, xfree
));
5966 /* A helper function to add a signatured type CU to a table. */
5969 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5971 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5972 std::vector
<signatured_type
*> *all_type_units
5973 = (std::vector
<signatured_type
*> *) datum
;
5975 all_type_units
->push_back (sigt
);
5980 /* A helper for create_debug_types_hash_table. Read types from SECTION
5981 and fill them into TYPES_HTAB. It will process only type units,
5982 therefore DW_UT_type. */
5985 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5986 struct dwo_file
*dwo_file
,
5987 dwarf2_section_info
*section
, htab_up
&types_htab
,
5988 rcuh_kind section_kind
)
5990 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5991 struct dwarf2_section_info
*abbrev_section
;
5993 const gdb_byte
*info_ptr
, *end_ptr
;
5995 abbrev_section
= (dwo_file
!= NULL
5996 ? &dwo_file
->sections
.abbrev
5997 : &dwarf2_per_objfile
->abbrev
);
5999 if (dwarf_read_debug
)
6000 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6001 section
->get_name (),
6002 abbrev_section
->get_file_name ());
6004 section
->read (objfile
);
6005 info_ptr
= section
->buffer
;
6007 if (info_ptr
== NULL
)
6010 /* We can't set abfd until now because the section may be empty or
6011 not present, in which case the bfd is unknown. */
6012 abfd
= section
->get_bfd_owner ();
6014 /* We don't use cutu_reader here because we don't need to read
6015 any dies: the signature is in the header. */
6017 end_ptr
= info_ptr
+ section
->size
;
6018 while (info_ptr
< end_ptr
)
6020 struct signatured_type
*sig_type
;
6021 struct dwo_unit
*dwo_tu
;
6023 const gdb_byte
*ptr
= info_ptr
;
6024 struct comp_unit_head header
;
6025 unsigned int length
;
6027 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6029 /* Initialize it due to a false compiler warning. */
6030 header
.signature
= -1;
6031 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6033 /* We need to read the type's signature in order to build the hash
6034 table, but we don't need anything else just yet. */
6036 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6037 abbrev_section
, ptr
, section_kind
);
6039 length
= header
.get_length ();
6041 /* Skip dummy type units. */
6042 if (ptr
>= info_ptr
+ length
6043 || peek_abbrev_code (abfd
, ptr
) == 0
6044 || header
.unit_type
!= DW_UT_type
)
6050 if (types_htab
== NULL
)
6053 types_htab
= allocate_dwo_unit_table ();
6055 types_htab
= allocate_signatured_type_table ();
6061 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6063 dwo_tu
->dwo_file
= dwo_file
;
6064 dwo_tu
->signature
= header
.signature
;
6065 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6066 dwo_tu
->section
= section
;
6067 dwo_tu
->sect_off
= sect_off
;
6068 dwo_tu
->length
= length
;
6072 /* N.B.: type_offset is not usable if this type uses a DWO file.
6073 The real type_offset is in the DWO file. */
6075 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6076 struct signatured_type
);
6077 sig_type
->signature
= header
.signature
;
6078 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6079 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6080 sig_type
->per_cu
.is_debug_types
= 1;
6081 sig_type
->per_cu
.section
= section
;
6082 sig_type
->per_cu
.sect_off
= sect_off
;
6083 sig_type
->per_cu
.length
= length
;
6086 slot
= htab_find_slot (types_htab
.get (),
6087 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6089 gdb_assert (slot
!= NULL
);
6092 sect_offset dup_sect_off
;
6096 const struct dwo_unit
*dup_tu
6097 = (const struct dwo_unit
*) *slot
;
6099 dup_sect_off
= dup_tu
->sect_off
;
6103 const struct signatured_type
*dup_tu
6104 = (const struct signatured_type
*) *slot
;
6106 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6109 complaint (_("debug type entry at offset %s is duplicate to"
6110 " the entry at offset %s, signature %s"),
6111 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6112 hex_string (header
.signature
));
6114 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6116 if (dwarf_read_debug
> 1)
6117 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6118 sect_offset_str (sect_off
),
6119 hex_string (header
.signature
));
6125 /* Create the hash table of all entries in the .debug_types
6126 (or .debug_types.dwo) section(s).
6127 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6128 otherwise it is NULL.
6130 The result is a pointer to the hash table or NULL if there are no types.
6132 Note: This function processes DWO files only, not DWP files. */
6135 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6136 struct dwo_file
*dwo_file
,
6137 gdb::array_view
<dwarf2_section_info
> type_sections
,
6138 htab_up
&types_htab
)
6140 for (dwarf2_section_info
§ion
: type_sections
)
6141 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6142 types_htab
, rcuh_kind::TYPE
);
6145 /* Create the hash table of all entries in the .debug_types section,
6146 and initialize all_type_units.
6147 The result is zero if there is an error (e.g. missing .debug_types section),
6148 otherwise non-zero. */
6151 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6155 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6156 &dwarf2_per_objfile
->info
, types_htab
,
6157 rcuh_kind::COMPILE
);
6158 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6159 dwarf2_per_objfile
->types
, types_htab
);
6160 if (types_htab
== NULL
)
6162 dwarf2_per_objfile
->signatured_types
= NULL
;
6166 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6168 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6169 dwarf2_per_objfile
->all_type_units
.reserve
6170 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6172 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6173 add_signatured_type_cu_to_table
,
6174 &dwarf2_per_objfile
->all_type_units
);
6179 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6180 If SLOT is non-NULL, it is the entry to use in the hash table.
6181 Otherwise we find one. */
6183 static struct signatured_type
*
6184 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6187 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6189 if (dwarf2_per_objfile
->all_type_units
.size ()
6190 == dwarf2_per_objfile
->all_type_units
.capacity ())
6191 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6193 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6194 struct signatured_type
);
6196 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6197 sig_type
->signature
= sig
;
6198 sig_type
->per_cu
.is_debug_types
= 1;
6199 if (dwarf2_per_objfile
->using_index
)
6201 sig_type
->per_cu
.v
.quick
=
6202 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6203 struct dwarf2_per_cu_quick_data
);
6208 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6211 gdb_assert (*slot
== NULL
);
6213 /* The rest of sig_type must be filled in by the caller. */
6217 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6218 Fill in SIG_ENTRY with DWO_ENTRY. */
6221 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6222 struct signatured_type
*sig_entry
,
6223 struct dwo_unit
*dwo_entry
)
6225 /* Make sure we're not clobbering something we don't expect to. */
6226 gdb_assert (! sig_entry
->per_cu
.queued
);
6227 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6228 if (dwarf2_per_objfile
->using_index
)
6230 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6231 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6234 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6235 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6236 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6237 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6238 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6240 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6241 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6242 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6243 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6244 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6245 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6246 sig_entry
->dwo_unit
= dwo_entry
;
6249 /* Subroutine of lookup_signatured_type.
6250 If we haven't read the TU yet, create the signatured_type data structure
6251 for a TU to be read in directly from a DWO file, bypassing the stub.
6252 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6253 using .gdb_index, then when reading a CU we want to stay in the DWO file
6254 containing that CU. Otherwise we could end up reading several other DWO
6255 files (due to comdat folding) to process the transitive closure of all the
6256 mentioned TUs, and that can be slow. The current DWO file will have every
6257 type signature that it needs.
6258 We only do this for .gdb_index because in the psymtab case we already have
6259 to read all the DWOs to build the type unit groups. */
6261 static struct signatured_type
*
6262 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6264 struct dwarf2_per_objfile
*dwarf2_per_objfile
6265 = cu
->per_cu
->dwarf2_per_objfile
;
6266 struct dwo_file
*dwo_file
;
6267 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6268 struct signatured_type find_sig_entry
, *sig_entry
;
6271 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6273 /* If TU skeletons have been removed then we may not have read in any
6275 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6276 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6278 /* We only ever need to read in one copy of a signatured type.
6279 Use the global signatured_types array to do our own comdat-folding
6280 of types. If this is the first time we're reading this TU, and
6281 the TU has an entry in .gdb_index, replace the recorded data from
6282 .gdb_index with this TU. */
6284 find_sig_entry
.signature
= sig
;
6285 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6286 &find_sig_entry
, INSERT
);
6287 sig_entry
= (struct signatured_type
*) *slot
;
6289 /* We can get here with the TU already read, *or* in the process of being
6290 read. Don't reassign the global entry to point to this DWO if that's
6291 the case. Also note that if the TU is already being read, it may not
6292 have come from a DWO, the program may be a mix of Fission-compiled
6293 code and non-Fission-compiled code. */
6295 /* Have we already tried to read this TU?
6296 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6297 needn't exist in the global table yet). */
6298 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6301 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6302 dwo_unit of the TU itself. */
6303 dwo_file
= cu
->dwo_unit
->dwo_file
;
6305 /* Ok, this is the first time we're reading this TU. */
6306 if (dwo_file
->tus
== NULL
)
6308 find_dwo_entry
.signature
= sig
;
6309 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6311 if (dwo_entry
== NULL
)
6314 /* If the global table doesn't have an entry for this TU, add one. */
6315 if (sig_entry
== NULL
)
6316 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6318 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6319 sig_entry
->per_cu
.tu_read
= 1;
6323 /* Subroutine of lookup_signatured_type.
6324 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6325 then try the DWP file. If the TU stub (skeleton) has been removed then
6326 it won't be in .gdb_index. */
6328 static struct signatured_type
*
6329 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6331 struct dwarf2_per_objfile
*dwarf2_per_objfile
6332 = cu
->per_cu
->dwarf2_per_objfile
;
6333 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6334 struct dwo_unit
*dwo_entry
;
6335 struct signatured_type find_sig_entry
, *sig_entry
;
6338 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6339 gdb_assert (dwp_file
!= NULL
);
6341 /* If TU skeletons have been removed then we may not have read in any
6343 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6344 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6346 find_sig_entry
.signature
= sig
;
6347 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6348 &find_sig_entry
, INSERT
);
6349 sig_entry
= (struct signatured_type
*) *slot
;
6351 /* Have we already tried to read this TU?
6352 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6353 needn't exist in the global table yet). */
6354 if (sig_entry
!= NULL
)
6357 if (dwp_file
->tus
== NULL
)
6359 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6360 sig
, 1 /* is_debug_types */);
6361 if (dwo_entry
== NULL
)
6364 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6365 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6370 /* Lookup a signature based type for DW_FORM_ref_sig8.
6371 Returns NULL if signature SIG is not present in the table.
6372 It is up to the caller to complain about this. */
6374 static struct signatured_type
*
6375 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6377 struct dwarf2_per_objfile
*dwarf2_per_objfile
6378 = cu
->per_cu
->dwarf2_per_objfile
;
6381 && dwarf2_per_objfile
->using_index
)
6383 /* We're in a DWO/DWP file, and we're using .gdb_index.
6384 These cases require special processing. */
6385 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6386 return lookup_dwo_signatured_type (cu
, sig
);
6388 return lookup_dwp_signatured_type (cu
, sig
);
6392 struct signatured_type find_entry
, *entry
;
6394 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6396 find_entry
.signature
= sig
;
6397 entry
= ((struct signatured_type
*)
6398 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6404 /* Return the address base of the compile unit, which, if exists, is stored
6405 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6406 static gdb::optional
<ULONGEST
>
6407 lookup_addr_base (struct die_info
*comp_unit_die
)
6409 struct attribute
*attr
;
6410 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6411 if (attr
== nullptr)
6412 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6413 if (attr
== nullptr)
6414 return gdb::optional
<ULONGEST
> ();
6415 return DW_UNSND (attr
);
6418 /* Return range lists base of the compile unit, which, if exists, is stored
6419 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6421 lookup_ranges_base (struct die_info
*comp_unit_die
)
6423 struct attribute
*attr
;
6424 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6425 if (attr
== nullptr)
6426 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6427 if (attr
== nullptr)
6429 return DW_UNSND (attr
);
6432 /* Low level DIE reading support. */
6434 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6437 init_cu_die_reader (struct die_reader_specs
*reader
,
6438 struct dwarf2_cu
*cu
,
6439 struct dwarf2_section_info
*section
,
6440 struct dwo_file
*dwo_file
,
6441 struct abbrev_table
*abbrev_table
)
6443 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6444 reader
->abfd
= section
->get_bfd_owner ();
6446 reader
->dwo_file
= dwo_file
;
6447 reader
->die_section
= section
;
6448 reader
->buffer
= section
->buffer
;
6449 reader
->buffer_end
= section
->buffer
+ section
->size
;
6450 reader
->abbrev_table
= abbrev_table
;
6453 /* Subroutine of cutu_reader to simplify it.
6454 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6455 There's just a lot of work to do, and cutu_reader is big enough
6458 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6459 from it to the DIE in the DWO. If NULL we are skipping the stub.
6460 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6461 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6462 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6463 STUB_COMP_DIR may be non-NULL.
6464 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6465 are filled in with the info of the DIE from the DWO file.
6466 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6467 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6468 kept around for at least as long as *RESULT_READER.
6470 The result is non-zero if a valid (non-dummy) DIE was found. */
6473 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6474 struct dwo_unit
*dwo_unit
,
6475 struct die_info
*stub_comp_unit_die
,
6476 const char *stub_comp_dir
,
6477 struct die_reader_specs
*result_reader
,
6478 const gdb_byte
**result_info_ptr
,
6479 struct die_info
**result_comp_unit_die
,
6480 abbrev_table_up
*result_dwo_abbrev_table
)
6482 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6483 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6484 struct dwarf2_cu
*cu
= this_cu
->cu
;
6486 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6487 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6488 int i
,num_extra_attrs
;
6489 struct dwarf2_section_info
*dwo_abbrev_section
;
6490 struct die_info
*comp_unit_die
;
6492 /* At most one of these may be provided. */
6493 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6495 /* These attributes aren't processed until later:
6496 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6497 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6498 referenced later. However, these attributes are found in the stub
6499 which we won't have later. In order to not impose this complication
6500 on the rest of the code, we read them here and copy them to the
6509 if (stub_comp_unit_die
!= NULL
)
6511 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6513 if (! this_cu
->is_debug_types
)
6514 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6515 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6516 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6517 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6518 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6520 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6522 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6523 here (if needed). We need the value before we can process
6525 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6527 else if (stub_comp_dir
!= NULL
)
6529 /* Reconstruct the comp_dir attribute to simplify the code below. */
6530 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6531 comp_dir
->name
= DW_AT_comp_dir
;
6532 comp_dir
->form
= DW_FORM_string
;
6533 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6534 DW_STRING (comp_dir
) = stub_comp_dir
;
6537 /* Set up for reading the DWO CU/TU. */
6538 cu
->dwo_unit
= dwo_unit
;
6539 dwarf2_section_info
*section
= dwo_unit
->section
;
6540 section
->read (objfile
);
6541 abfd
= section
->get_bfd_owner ();
6542 begin_info_ptr
= info_ptr
= (section
->buffer
6543 + to_underlying (dwo_unit
->sect_off
));
6544 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6546 if (this_cu
->is_debug_types
)
6548 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6550 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6551 &cu
->header
, section
,
6553 info_ptr
, rcuh_kind::TYPE
);
6554 /* This is not an assert because it can be caused by bad debug info. */
6555 if (sig_type
->signature
!= cu
->header
.signature
)
6557 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6558 " TU at offset %s [in module %s]"),
6559 hex_string (sig_type
->signature
),
6560 hex_string (cu
->header
.signature
),
6561 sect_offset_str (dwo_unit
->sect_off
),
6562 bfd_get_filename (abfd
));
6564 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6565 /* For DWOs coming from DWP files, we don't know the CU length
6566 nor the type's offset in the TU until now. */
6567 dwo_unit
->length
= cu
->header
.get_length ();
6568 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6570 /* Establish the type offset that can be used to lookup the type.
6571 For DWO files, we don't know it until now. */
6572 sig_type
->type_offset_in_section
6573 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6577 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6578 &cu
->header
, section
,
6580 info_ptr
, rcuh_kind::COMPILE
);
6581 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6582 /* For DWOs coming from DWP files, we don't know the CU length
6584 dwo_unit
->length
= cu
->header
.get_length ();
6587 *result_dwo_abbrev_table
6588 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6589 cu
->header
.abbrev_sect_off
);
6590 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6591 result_dwo_abbrev_table
->get ());
6593 /* Read in the die, but leave space to copy over the attributes
6594 from the stub. This has the benefit of simplifying the rest of
6595 the code - all the work to maintain the illusion of a single
6596 DW_TAG_{compile,type}_unit DIE is done here. */
6597 num_extra_attrs
= ((stmt_list
!= NULL
)
6601 + (comp_dir
!= NULL
));
6602 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6605 /* Copy over the attributes from the stub to the DIE we just read in. */
6606 comp_unit_die
= *result_comp_unit_die
;
6607 i
= comp_unit_die
->num_attrs
;
6608 if (stmt_list
!= NULL
)
6609 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6611 comp_unit_die
->attrs
[i
++] = *low_pc
;
6612 if (high_pc
!= NULL
)
6613 comp_unit_die
->attrs
[i
++] = *high_pc
;
6615 comp_unit_die
->attrs
[i
++] = *ranges
;
6616 if (comp_dir
!= NULL
)
6617 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6618 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6620 if (dwarf_die_debug
)
6622 fprintf_unfiltered (gdb_stdlog
,
6623 "Read die from %s@0x%x of %s:\n",
6624 section
->get_name (),
6625 (unsigned) (begin_info_ptr
- section
->buffer
),
6626 bfd_get_filename (abfd
));
6627 dump_die (comp_unit_die
, dwarf_die_debug
);
6630 /* Skip dummy compilation units. */
6631 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6632 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6635 *result_info_ptr
= info_ptr
;
6639 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6640 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6641 signature is part of the header. */
6642 static gdb::optional
<ULONGEST
>
6643 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6645 if (cu
->header
.version
>= 5)
6646 return cu
->header
.signature
;
6647 struct attribute
*attr
;
6648 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6649 if (attr
== nullptr)
6650 return gdb::optional
<ULONGEST
> ();
6651 return DW_UNSND (attr
);
6654 /* Subroutine of cutu_reader to simplify it.
6655 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6656 Returns NULL if the specified DWO unit cannot be found. */
6658 static struct dwo_unit
*
6659 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6660 struct die_info
*comp_unit_die
,
6661 const char *dwo_name
)
6663 struct dwarf2_cu
*cu
= this_cu
->cu
;
6664 struct dwo_unit
*dwo_unit
;
6665 const char *comp_dir
;
6667 gdb_assert (cu
!= NULL
);
6669 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6670 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6671 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6673 if (this_cu
->is_debug_types
)
6675 struct signatured_type
*sig_type
;
6677 /* Since this_cu is the first member of struct signatured_type,
6678 we can go from a pointer to one to a pointer to the other. */
6679 sig_type
= (struct signatured_type
*) this_cu
;
6680 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6684 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6685 if (!signature
.has_value ())
6686 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6688 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6689 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6696 /* Subroutine of cutu_reader to simplify it.
6697 See it for a description of the parameters.
6698 Read a TU directly from a DWO file, bypassing the stub. */
6701 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6702 int use_existing_cu
)
6704 struct signatured_type
*sig_type
;
6706 /* Verify we can do the following downcast, and that we have the
6708 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6709 sig_type
= (struct signatured_type
*) this_cu
;
6710 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6712 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6714 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6715 /* There's no need to do the rereading_dwo_cu handling that
6716 cutu_reader does since we don't read the stub. */
6720 /* If !use_existing_cu, this_cu->cu must be NULL. */
6721 gdb_assert (this_cu
->cu
== NULL
);
6722 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6725 /* A future optimization, if needed, would be to use an existing
6726 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6727 could share abbrev tables. */
6729 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6730 NULL
/* stub_comp_unit_die */,
6731 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6734 &m_dwo_abbrev_table
) == 0)
6741 /* Initialize a CU (or TU) and read its DIEs.
6742 If the CU defers to a DWO file, read the DWO file as well.
6744 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6745 Otherwise the table specified in the comp unit header is read in and used.
6746 This is an optimization for when we already have the abbrev table.
6748 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6749 Otherwise, a new CU is allocated with xmalloc. */
6751 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6752 struct abbrev_table
*abbrev_table
,
6753 int use_existing_cu
,
6755 : die_reader_specs
{},
6758 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6759 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6760 struct dwarf2_section_info
*section
= this_cu
->section
;
6761 bfd
*abfd
= section
->get_bfd_owner ();
6762 struct dwarf2_cu
*cu
;
6763 const gdb_byte
*begin_info_ptr
;
6764 struct signatured_type
*sig_type
= NULL
;
6765 struct dwarf2_section_info
*abbrev_section
;
6766 /* Non-zero if CU currently points to a DWO file and we need to
6767 reread it. When this happens we need to reread the skeleton die
6768 before we can reread the DWO file (this only applies to CUs, not TUs). */
6769 int rereading_dwo_cu
= 0;
6771 if (dwarf_die_debug
)
6772 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6773 this_cu
->is_debug_types
? "type" : "comp",
6774 sect_offset_str (this_cu
->sect_off
));
6776 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6777 file (instead of going through the stub), short-circuit all of this. */
6778 if (this_cu
->reading_dwo_directly
)
6780 /* Narrow down the scope of possibilities to have to understand. */
6781 gdb_assert (this_cu
->is_debug_types
);
6782 gdb_assert (abbrev_table
== NULL
);
6783 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6787 /* This is cheap if the section is already read in. */
6788 section
->read (objfile
);
6790 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6792 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6794 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6797 /* If this CU is from a DWO file we need to start over, we need to
6798 refetch the attributes from the skeleton CU.
6799 This could be optimized by retrieving those attributes from when we
6800 were here the first time: the previous comp_unit_die was stored in
6801 comp_unit_obstack. But there's no data yet that we need this
6803 if (cu
->dwo_unit
!= NULL
)
6804 rereading_dwo_cu
= 1;
6808 /* If !use_existing_cu, this_cu->cu must be NULL. */
6809 gdb_assert (this_cu
->cu
== NULL
);
6810 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6811 cu
= m_new_cu
.get ();
6814 /* Get the header. */
6815 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6817 /* We already have the header, there's no need to read it in again. */
6818 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6822 if (this_cu
->is_debug_types
)
6824 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6825 &cu
->header
, section
,
6826 abbrev_section
, info_ptr
,
6829 /* Since per_cu is the first member of struct signatured_type,
6830 we can go from a pointer to one to a pointer to the other. */
6831 sig_type
= (struct signatured_type
*) this_cu
;
6832 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6833 gdb_assert (sig_type
->type_offset_in_tu
6834 == cu
->header
.type_cu_offset_in_tu
);
6835 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6837 /* LENGTH has not been set yet for type units if we're
6838 using .gdb_index. */
6839 this_cu
->length
= cu
->header
.get_length ();
6841 /* Establish the type offset that can be used to lookup the type. */
6842 sig_type
->type_offset_in_section
=
6843 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6845 this_cu
->dwarf_version
= cu
->header
.version
;
6849 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6850 &cu
->header
, section
,
6853 rcuh_kind::COMPILE
);
6855 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6856 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6857 this_cu
->dwarf_version
= cu
->header
.version
;
6861 /* Skip dummy compilation units. */
6862 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6863 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6869 /* If we don't have them yet, read the abbrevs for this compilation unit.
6870 And if we need to read them now, make sure they're freed when we're
6872 if (abbrev_table
!= NULL
)
6873 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6876 m_abbrev_table_holder
6877 = abbrev_table::read (objfile
, abbrev_section
,
6878 cu
->header
.abbrev_sect_off
);
6879 abbrev_table
= m_abbrev_table_holder
.get ();
6882 /* Read the top level CU/TU die. */
6883 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6884 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6886 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6892 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6893 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6894 table from the DWO file and pass the ownership over to us. It will be
6895 referenced from READER, so we must make sure to free it after we're done
6898 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6899 DWO CU, that this test will fail (the attribute will not be present). */
6900 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6901 if (dwo_name
!= nullptr)
6903 struct dwo_unit
*dwo_unit
;
6904 struct die_info
*dwo_comp_unit_die
;
6906 if (comp_unit_die
->has_children
)
6908 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6909 " has children (offset %s) [in module %s]"),
6910 sect_offset_str (this_cu
->sect_off
),
6911 bfd_get_filename (abfd
));
6913 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6914 if (dwo_unit
!= NULL
)
6916 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6917 comp_unit_die
, NULL
,
6920 &m_dwo_abbrev_table
) == 0)
6926 comp_unit_die
= dwo_comp_unit_die
;
6930 /* Yikes, we couldn't find the rest of the DIE, we only have
6931 the stub. A complaint has already been logged. There's
6932 not much more we can do except pass on the stub DIE to
6933 die_reader_func. We don't want to throw an error on bad
6940 cutu_reader::keep ()
6942 /* Done, clean up. */
6943 gdb_assert (!dummy_p
);
6944 if (m_new_cu
!= NULL
)
6946 struct dwarf2_per_objfile
*dwarf2_per_objfile
6947 = m_this_cu
->dwarf2_per_objfile
;
6948 /* Link this CU into read_in_chain. */
6949 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6950 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6951 /* The chain owns it now. */
6952 m_new_cu
.release ();
6956 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6957 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6958 assumed to have already done the lookup to find the DWO file).
6960 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6961 THIS_CU->is_debug_types, but nothing else.
6963 We fill in THIS_CU->length.
6965 THIS_CU->cu is always freed when done.
6966 This is done in order to not leave THIS_CU->cu in a state where we have
6967 to care whether it refers to the "main" CU or the DWO CU.
6969 When parent_cu is passed, it is used to provide a default value for
6970 str_offsets_base and addr_base from the parent. */
6972 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6973 struct dwarf2_cu
*parent_cu
,
6974 struct dwo_file
*dwo_file
)
6975 : die_reader_specs
{},
6978 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6979 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6980 struct dwarf2_section_info
*section
= this_cu
->section
;
6981 bfd
*abfd
= section
->get_bfd_owner ();
6982 struct dwarf2_section_info
*abbrev_section
;
6983 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6985 if (dwarf_die_debug
)
6986 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6987 this_cu
->is_debug_types
? "type" : "comp",
6988 sect_offset_str (this_cu
->sect_off
));
6990 gdb_assert (this_cu
->cu
== NULL
);
6992 abbrev_section
= (dwo_file
!= NULL
6993 ? &dwo_file
->sections
.abbrev
6994 : get_abbrev_section_for_cu (this_cu
));
6996 /* This is cheap if the section is already read in. */
6997 section
->read (objfile
);
6999 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7001 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7002 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7003 &m_new_cu
->header
, section
,
7004 abbrev_section
, info_ptr
,
7005 (this_cu
->is_debug_types
7007 : rcuh_kind::COMPILE
));
7009 if (parent_cu
!= nullptr)
7011 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7012 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7014 this_cu
->length
= m_new_cu
->header
.get_length ();
7016 /* Skip dummy compilation units. */
7017 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7018 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7024 m_abbrev_table_holder
7025 = abbrev_table::read (objfile
, abbrev_section
,
7026 m_new_cu
->header
.abbrev_sect_off
);
7028 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7029 m_abbrev_table_holder
.get ());
7030 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7034 /* Type Unit Groups.
7036 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7037 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7038 so that all types coming from the same compilation (.o file) are grouped
7039 together. A future step could be to put the types in the same symtab as
7040 the CU the types ultimately came from. */
7043 hash_type_unit_group (const void *item
)
7045 const struct type_unit_group
*tu_group
7046 = (const struct type_unit_group
*) item
;
7048 return hash_stmt_list_entry (&tu_group
->hash
);
7052 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7054 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7055 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7057 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7060 /* Allocate a hash table for type unit groups. */
7063 allocate_type_unit_groups_table ()
7065 return htab_up (htab_create_alloc (3,
7066 hash_type_unit_group
,
7068 NULL
, xcalloc
, xfree
));
7071 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7072 partial symtabs. We combine several TUs per psymtab to not let the size
7073 of any one psymtab grow too big. */
7074 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7075 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7077 /* Helper routine for get_type_unit_group.
7078 Create the type_unit_group object used to hold one or more TUs. */
7080 static struct type_unit_group
*
7081 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7083 struct dwarf2_per_objfile
*dwarf2_per_objfile
7084 = cu
->per_cu
->dwarf2_per_objfile
;
7085 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7086 struct dwarf2_per_cu_data
*per_cu
;
7087 struct type_unit_group
*tu_group
;
7089 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7090 struct type_unit_group
);
7091 per_cu
= &tu_group
->per_cu
;
7092 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7094 if (dwarf2_per_objfile
->using_index
)
7096 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7097 struct dwarf2_per_cu_quick_data
);
7101 unsigned int line_offset
= to_underlying (line_offset_struct
);
7102 dwarf2_psymtab
*pst
;
7105 /* Give the symtab a useful name for debug purposes. */
7106 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7107 name
= string_printf ("<type_units_%d>",
7108 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7110 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7112 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7113 pst
->anonymous
= true;
7116 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7117 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7122 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7123 STMT_LIST is a DW_AT_stmt_list attribute. */
7125 static struct type_unit_group
*
7126 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7128 struct dwarf2_per_objfile
*dwarf2_per_objfile
7129 = cu
->per_cu
->dwarf2_per_objfile
;
7130 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7131 struct type_unit_group
*tu_group
;
7133 unsigned int line_offset
;
7134 struct type_unit_group type_unit_group_for_lookup
;
7136 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7137 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7139 /* Do we need to create a new group, or can we use an existing one? */
7143 line_offset
= DW_UNSND (stmt_list
);
7144 ++tu_stats
->nr_symtab_sharers
;
7148 /* Ugh, no stmt_list. Rare, but we have to handle it.
7149 We can do various things here like create one group per TU or
7150 spread them over multiple groups to split up the expansion work.
7151 To avoid worst case scenarios (too many groups or too large groups)
7152 we, umm, group them in bunches. */
7153 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7154 | (tu_stats
->nr_stmt_less_type_units
7155 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7156 ++tu_stats
->nr_stmt_less_type_units
;
7159 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7160 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7161 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7162 &type_unit_group_for_lookup
, INSERT
);
7165 tu_group
= (struct type_unit_group
*) *slot
;
7166 gdb_assert (tu_group
!= NULL
);
7170 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7171 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7173 ++tu_stats
->nr_symtabs
;
7179 /* Partial symbol tables. */
7181 /* Create a psymtab named NAME and assign it to PER_CU.
7183 The caller must fill in the following details:
7184 dirname, textlow, texthigh. */
7186 static dwarf2_psymtab
*
7187 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7189 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7190 dwarf2_psymtab
*pst
;
7192 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7194 pst
->psymtabs_addrmap_supported
= true;
7196 /* This is the glue that links PST into GDB's symbol API. */
7197 pst
->per_cu_data
= per_cu
;
7198 per_cu
->v
.psymtab
= pst
;
7203 /* DIE reader function for process_psymtab_comp_unit. */
7206 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7207 const gdb_byte
*info_ptr
,
7208 struct die_info
*comp_unit_die
,
7209 enum language pretend_language
)
7211 struct dwarf2_cu
*cu
= reader
->cu
;
7212 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7213 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7214 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7216 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7217 dwarf2_psymtab
*pst
;
7218 enum pc_bounds_kind cu_bounds_kind
;
7219 const char *filename
;
7221 gdb_assert (! per_cu
->is_debug_types
);
7223 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7225 /* Allocate a new partial symbol table structure. */
7226 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7227 static const char artificial
[] = "<artificial>";
7228 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7229 if (filename
== NULL
)
7231 else if (strcmp (filename
, artificial
) == 0)
7233 debug_filename
.reset (concat (artificial
, "@",
7234 sect_offset_str (per_cu
->sect_off
),
7236 filename
= debug_filename
.get ();
7239 pst
= create_partial_symtab (per_cu
, filename
);
7241 /* This must be done before calling dwarf2_build_include_psymtabs. */
7242 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7244 baseaddr
= objfile
->text_section_offset ();
7246 dwarf2_find_base_address (comp_unit_die
, cu
);
7248 /* Possibly set the default values of LOWPC and HIGHPC from
7250 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7251 &best_highpc
, cu
, pst
);
7252 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7255 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7258 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7260 /* Store the contiguous range if it is not empty; it can be
7261 empty for CUs with no code. */
7262 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7266 /* Check if comp unit has_children.
7267 If so, read the rest of the partial symbols from this comp unit.
7268 If not, there's no more debug_info for this comp unit. */
7269 if (comp_unit_die
->has_children
)
7271 struct partial_die_info
*first_die
;
7272 CORE_ADDR lowpc
, highpc
;
7274 lowpc
= ((CORE_ADDR
) -1);
7275 highpc
= ((CORE_ADDR
) 0);
7277 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7279 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7280 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7282 /* If we didn't find a lowpc, set it to highpc to avoid
7283 complaints from `maint check'. */
7284 if (lowpc
== ((CORE_ADDR
) -1))
7287 /* If the compilation unit didn't have an explicit address range,
7288 then use the information extracted from its child dies. */
7289 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7292 best_highpc
= highpc
;
7295 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7296 best_lowpc
+ baseaddr
)
7298 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7299 best_highpc
+ baseaddr
)
7302 end_psymtab_common (objfile
, pst
);
7304 if (!cu
->per_cu
->imported_symtabs_empty ())
7307 int len
= cu
->per_cu
->imported_symtabs_size ();
7309 /* Fill in 'dependencies' here; we fill in 'users' in a
7311 pst
->number_of_dependencies
= len
;
7313 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7314 for (i
= 0; i
< len
; ++i
)
7316 pst
->dependencies
[i
]
7317 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7320 cu
->per_cu
->imported_symtabs_free ();
7323 /* Get the list of files included in the current compilation unit,
7324 and build a psymtab for each of them. */
7325 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7327 if (dwarf_read_debug
)
7328 fprintf_unfiltered (gdb_stdlog
,
7329 "Psymtab for %s unit @%s: %s - %s"
7330 ", %d global, %d static syms\n",
7331 per_cu
->is_debug_types
? "type" : "comp",
7332 sect_offset_str (per_cu
->sect_off
),
7333 paddress (gdbarch
, pst
->text_low (objfile
)),
7334 paddress (gdbarch
, pst
->text_high (objfile
)),
7335 pst
->n_global_syms
, pst
->n_static_syms
);
7338 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7339 Process compilation unit THIS_CU for a psymtab. */
7342 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7343 bool want_partial_unit
,
7344 enum language pretend_language
)
7346 /* If this compilation unit was already read in, free the
7347 cached copy in order to read it in again. This is
7348 necessary because we skipped some symbols when we first
7349 read in the compilation unit (see load_partial_dies).
7350 This problem could be avoided, but the benefit is unclear. */
7351 if (this_cu
->cu
!= NULL
)
7352 free_one_cached_comp_unit (this_cu
);
7354 cutu_reader
reader (this_cu
, NULL
, 0, false);
7356 switch (reader
.comp_unit_die
->tag
)
7358 case DW_TAG_compile_unit
:
7359 this_cu
->unit_type
= DW_UT_compile
;
7361 case DW_TAG_partial_unit
:
7362 this_cu
->unit_type
= DW_UT_partial
;
7372 else if (this_cu
->is_debug_types
)
7373 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7374 reader
.comp_unit_die
);
7375 else if (want_partial_unit
7376 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7377 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7378 reader
.comp_unit_die
,
7381 this_cu
->lang
= this_cu
->cu
->language
;
7383 /* Age out any secondary CUs. */
7384 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7387 /* Reader function for build_type_psymtabs. */
7390 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7391 const gdb_byte
*info_ptr
,
7392 struct die_info
*type_unit_die
)
7394 struct dwarf2_per_objfile
*dwarf2_per_objfile
7395 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7396 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7397 struct dwarf2_cu
*cu
= reader
->cu
;
7398 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7399 struct signatured_type
*sig_type
;
7400 struct type_unit_group
*tu_group
;
7401 struct attribute
*attr
;
7402 struct partial_die_info
*first_die
;
7403 CORE_ADDR lowpc
, highpc
;
7404 dwarf2_psymtab
*pst
;
7406 gdb_assert (per_cu
->is_debug_types
);
7407 sig_type
= (struct signatured_type
*) per_cu
;
7409 if (! type_unit_die
->has_children
)
7412 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7413 tu_group
= get_type_unit_group (cu
, attr
);
7415 if (tu_group
->tus
== nullptr)
7416 tu_group
->tus
= new std::vector
<signatured_type
*>;
7417 tu_group
->tus
->push_back (sig_type
);
7419 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7420 pst
= create_partial_symtab (per_cu
, "");
7421 pst
->anonymous
= true;
7423 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7425 lowpc
= (CORE_ADDR
) -1;
7426 highpc
= (CORE_ADDR
) 0;
7427 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7429 end_psymtab_common (objfile
, pst
);
7432 /* Struct used to sort TUs by their abbreviation table offset. */
7434 struct tu_abbrev_offset
7436 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7437 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7440 signatured_type
*sig_type
;
7441 sect_offset abbrev_offset
;
7444 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7447 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7448 const struct tu_abbrev_offset
&b
)
7450 return a
.abbrev_offset
< b
.abbrev_offset
;
7453 /* Efficiently read all the type units.
7454 This does the bulk of the work for build_type_psymtabs.
7456 The efficiency is because we sort TUs by the abbrev table they use and
7457 only read each abbrev table once. In one program there are 200K TUs
7458 sharing 8K abbrev tables.
7460 The main purpose of this function is to support building the
7461 dwarf2_per_objfile->type_unit_groups table.
7462 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7463 can collapse the search space by grouping them by stmt_list.
7464 The savings can be significant, in the same program from above the 200K TUs
7465 share 8K stmt_list tables.
7467 FUNC is expected to call get_type_unit_group, which will create the
7468 struct type_unit_group if necessary and add it to
7469 dwarf2_per_objfile->type_unit_groups. */
7472 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7474 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7475 abbrev_table_up abbrev_table
;
7476 sect_offset abbrev_offset
;
7478 /* It's up to the caller to not call us multiple times. */
7479 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7481 if (dwarf2_per_objfile
->all_type_units
.empty ())
7484 /* TUs typically share abbrev tables, and there can be way more TUs than
7485 abbrev tables. Sort by abbrev table to reduce the number of times we
7486 read each abbrev table in.
7487 Alternatives are to punt or to maintain a cache of abbrev tables.
7488 This is simpler and efficient enough for now.
7490 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7491 symtab to use). Typically TUs with the same abbrev offset have the same
7492 stmt_list value too so in practice this should work well.
7494 The basic algorithm here is:
7496 sort TUs by abbrev table
7497 for each TU with same abbrev table:
7498 read abbrev table if first user
7499 read TU top level DIE
7500 [IWBN if DWO skeletons had DW_AT_stmt_list]
7503 if (dwarf_read_debug
)
7504 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7506 /* Sort in a separate table to maintain the order of all_type_units
7507 for .gdb_index: TU indices directly index all_type_units. */
7508 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7509 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7511 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7512 sorted_by_abbrev
.emplace_back
7513 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7514 sig_type
->per_cu
.section
,
7515 sig_type
->per_cu
.sect_off
));
7517 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7518 sort_tu_by_abbrev_offset
);
7520 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7522 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7524 /* Switch to the next abbrev table if necessary. */
7525 if (abbrev_table
== NULL
7526 || tu
.abbrev_offset
!= abbrev_offset
)
7528 abbrev_offset
= tu
.abbrev_offset
;
7530 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7531 &dwarf2_per_objfile
->abbrev
,
7533 ++tu_stats
->nr_uniq_abbrev_tables
;
7536 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7538 if (!reader
.dummy_p
)
7539 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7540 reader
.comp_unit_die
);
7544 /* Print collected type unit statistics. */
7547 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7549 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7551 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7552 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7553 dwarf2_per_objfile
->all_type_units
.size ());
7554 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7555 tu_stats
->nr_uniq_abbrev_tables
);
7556 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7557 tu_stats
->nr_symtabs
);
7558 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7559 tu_stats
->nr_symtab_sharers
);
7560 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7561 tu_stats
->nr_stmt_less_type_units
);
7562 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7563 tu_stats
->nr_all_type_units_reallocs
);
7566 /* Traversal function for build_type_psymtabs. */
7569 build_type_psymtab_dependencies (void **slot
, void *info
)
7571 struct dwarf2_per_objfile
*dwarf2_per_objfile
7572 = (struct dwarf2_per_objfile
*) info
;
7573 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7574 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7575 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7576 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7577 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7580 gdb_assert (len
> 0);
7581 gdb_assert (per_cu
->type_unit_group_p ());
7583 pst
->number_of_dependencies
= len
;
7584 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7585 for (i
= 0; i
< len
; ++i
)
7587 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7588 gdb_assert (iter
->per_cu
.is_debug_types
);
7589 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7590 iter
->type_unit_group
= tu_group
;
7593 delete tu_group
->tus
;
7594 tu_group
->tus
= nullptr;
7599 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7600 Build partial symbol tables for the .debug_types comp-units. */
7603 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7605 if (! create_all_type_units (dwarf2_per_objfile
))
7608 build_type_psymtabs_1 (dwarf2_per_objfile
);
7611 /* Traversal function for process_skeletonless_type_unit.
7612 Read a TU in a DWO file and build partial symbols for it. */
7615 process_skeletonless_type_unit (void **slot
, void *info
)
7617 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7618 struct dwarf2_per_objfile
*dwarf2_per_objfile
7619 = (struct dwarf2_per_objfile
*) info
;
7620 struct signatured_type find_entry
, *entry
;
7622 /* If this TU doesn't exist in the global table, add it and read it in. */
7624 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7625 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7627 find_entry
.signature
= dwo_unit
->signature
;
7628 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7629 &find_entry
, INSERT
);
7630 /* If we've already seen this type there's nothing to do. What's happening
7631 is we're doing our own version of comdat-folding here. */
7635 /* This does the job that create_all_type_units would have done for
7637 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7638 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7641 /* This does the job that build_type_psymtabs_1 would have done. */
7642 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7643 if (!reader
.dummy_p
)
7644 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7645 reader
.comp_unit_die
);
7650 /* Traversal function for process_skeletonless_type_units. */
7653 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7655 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7657 if (dwo_file
->tus
!= NULL
)
7658 htab_traverse_noresize (dwo_file
->tus
.get (),
7659 process_skeletonless_type_unit
, info
);
7664 /* Scan all TUs of DWO files, verifying we've processed them.
7665 This is needed in case a TU was emitted without its skeleton.
7666 Note: This can't be done until we know what all the DWO files are. */
7669 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7671 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7672 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7673 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7675 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7676 process_dwo_file_for_skeletonless_type_units
,
7677 dwarf2_per_objfile
);
7681 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7684 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7686 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7688 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7693 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7695 /* Set the 'user' field only if it is not already set. */
7696 if (pst
->dependencies
[j
]->user
== NULL
)
7697 pst
->dependencies
[j
]->user
= pst
;
7702 /* Build the partial symbol table by doing a quick pass through the
7703 .debug_info and .debug_abbrev sections. */
7706 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7708 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7710 if (dwarf_read_debug
)
7712 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7713 objfile_name (objfile
));
7716 scoped_restore restore_reading_psyms
7717 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7720 dwarf2_per_objfile
->info
.read (objfile
);
7722 /* Any cached compilation units will be linked by the per-objfile
7723 read_in_chain. Make sure to free them when we're done. */
7724 free_cached_comp_units
freer (dwarf2_per_objfile
);
7726 build_type_psymtabs (dwarf2_per_objfile
);
7728 create_all_comp_units (dwarf2_per_objfile
);
7730 /* Create a temporary address map on a temporary obstack. We later
7731 copy this to the final obstack. */
7732 auto_obstack temp_obstack
;
7734 scoped_restore save_psymtabs_addrmap
7735 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7736 addrmap_create_mutable (&temp_obstack
));
7738 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7739 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7741 /* This has to wait until we read the CUs, we need the list of DWOs. */
7742 process_skeletonless_type_units (dwarf2_per_objfile
);
7744 /* Now that all TUs have been processed we can fill in the dependencies. */
7745 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7747 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7748 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7751 if (dwarf_read_debug
)
7752 print_tu_stats (dwarf2_per_objfile
);
7754 set_partial_user (dwarf2_per_objfile
);
7756 objfile
->partial_symtabs
->psymtabs_addrmap
7757 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7758 objfile
->partial_symtabs
->obstack ());
7759 /* At this point we want to keep the address map. */
7760 save_psymtabs_addrmap
.release ();
7762 if (dwarf_read_debug
)
7763 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7764 objfile_name (objfile
));
7767 /* Load the partial DIEs for a secondary CU into memory.
7768 This is also used when rereading a primary CU with load_all_dies. */
7771 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7773 cutu_reader
reader (this_cu
, NULL
, 1, false);
7775 if (!reader
.dummy_p
)
7777 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7780 /* Check if comp unit has_children.
7781 If so, read the rest of the partial symbols from this comp unit.
7782 If not, there's no more debug_info for this comp unit. */
7783 if (reader
.comp_unit_die
->has_children
)
7784 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7791 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7792 struct dwarf2_section_info
*section
,
7793 struct dwarf2_section_info
*abbrev_section
,
7794 unsigned int is_dwz
)
7796 const gdb_byte
*info_ptr
;
7797 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7799 if (dwarf_read_debug
)
7800 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7801 section
->get_name (),
7802 section
->get_file_name ());
7804 section
->read (objfile
);
7806 info_ptr
= section
->buffer
;
7808 while (info_ptr
< section
->buffer
+ section
->size
)
7810 struct dwarf2_per_cu_data
*this_cu
;
7812 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7814 comp_unit_head cu_header
;
7815 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7816 abbrev_section
, info_ptr
,
7817 rcuh_kind::COMPILE
);
7819 /* Save the compilation unit for later lookup. */
7820 if (cu_header
.unit_type
!= DW_UT_type
)
7822 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7823 struct dwarf2_per_cu_data
);
7824 memset (this_cu
, 0, sizeof (*this_cu
));
7828 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7829 struct signatured_type
);
7830 memset (sig_type
, 0, sizeof (*sig_type
));
7831 sig_type
->signature
= cu_header
.signature
;
7832 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7833 this_cu
= &sig_type
->per_cu
;
7835 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7836 this_cu
->sect_off
= sect_off
;
7837 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7838 this_cu
->is_dwz
= is_dwz
;
7839 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7840 this_cu
->section
= section
;
7842 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7844 info_ptr
= info_ptr
+ this_cu
->length
;
7848 /* Create a list of all compilation units in OBJFILE.
7849 This is only done for -readnow and building partial symtabs. */
7852 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7854 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7855 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7856 &dwarf2_per_objfile
->abbrev
, 0);
7858 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7860 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7864 /* Process all loaded DIEs for compilation unit CU, starting at
7865 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7866 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7867 DW_AT_ranges). See the comments of add_partial_subprogram on how
7868 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7871 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7872 CORE_ADDR
*highpc
, int set_addrmap
,
7873 struct dwarf2_cu
*cu
)
7875 struct partial_die_info
*pdi
;
7877 /* Now, march along the PDI's, descending into ones which have
7878 interesting children but skipping the children of the other ones,
7879 until we reach the end of the compilation unit. */
7887 /* Anonymous namespaces or modules have no name but have interesting
7888 children, so we need to look at them. Ditto for anonymous
7891 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7892 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7893 || pdi
->tag
== DW_TAG_imported_unit
7894 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7898 case DW_TAG_subprogram
:
7899 case DW_TAG_inlined_subroutine
:
7900 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7902 case DW_TAG_constant
:
7903 case DW_TAG_variable
:
7904 case DW_TAG_typedef
:
7905 case DW_TAG_union_type
:
7906 if (!pdi
->is_declaration
)
7908 add_partial_symbol (pdi
, cu
);
7911 case DW_TAG_class_type
:
7912 case DW_TAG_interface_type
:
7913 case DW_TAG_structure_type
:
7914 if (!pdi
->is_declaration
)
7916 add_partial_symbol (pdi
, cu
);
7918 if ((cu
->language
== language_rust
7919 || cu
->language
== language_cplus
) && pdi
->has_children
)
7920 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7923 case DW_TAG_enumeration_type
:
7924 if (!pdi
->is_declaration
)
7925 add_partial_enumeration (pdi
, cu
);
7927 case DW_TAG_base_type
:
7928 case DW_TAG_subrange_type
:
7929 /* File scope base type definitions are added to the partial
7931 add_partial_symbol (pdi
, cu
);
7933 case DW_TAG_namespace
:
7934 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7937 if (!pdi
->is_declaration
)
7938 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7940 case DW_TAG_imported_unit
:
7942 struct dwarf2_per_cu_data
*per_cu
;
7944 /* For now we don't handle imported units in type units. */
7945 if (cu
->per_cu
->is_debug_types
)
7947 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7948 " supported in type units [in module %s]"),
7949 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7952 per_cu
= dwarf2_find_containing_comp_unit
7953 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7954 cu
->per_cu
->dwarf2_per_objfile
);
7956 /* Go read the partial unit, if needed. */
7957 if (per_cu
->v
.psymtab
== NULL
)
7958 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7960 cu
->per_cu
->imported_symtabs_push (per_cu
);
7963 case DW_TAG_imported_declaration
:
7964 add_partial_symbol (pdi
, cu
);
7971 /* If the die has a sibling, skip to the sibling. */
7973 pdi
= pdi
->die_sibling
;
7977 /* Functions used to compute the fully scoped name of a partial DIE.
7979 Normally, this is simple. For C++, the parent DIE's fully scoped
7980 name is concatenated with "::" and the partial DIE's name.
7981 Enumerators are an exception; they use the scope of their parent
7982 enumeration type, i.e. the name of the enumeration type is not
7983 prepended to the enumerator.
7985 There are two complexities. One is DW_AT_specification; in this
7986 case "parent" means the parent of the target of the specification,
7987 instead of the direct parent of the DIE. The other is compilers
7988 which do not emit DW_TAG_namespace; in this case we try to guess
7989 the fully qualified name of structure types from their members'
7990 linkage names. This must be done using the DIE's children rather
7991 than the children of any DW_AT_specification target. We only need
7992 to do this for structures at the top level, i.e. if the target of
7993 any DW_AT_specification (if any; otherwise the DIE itself) does not
7996 /* Compute the scope prefix associated with PDI's parent, in
7997 compilation unit CU. The result will be allocated on CU's
7998 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7999 field. NULL is returned if no prefix is necessary. */
8001 partial_die_parent_scope (struct partial_die_info
*pdi
,
8002 struct dwarf2_cu
*cu
)
8004 const char *grandparent_scope
;
8005 struct partial_die_info
*parent
, *real_pdi
;
8007 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8008 then this means the parent of the specification DIE. */
8011 while (real_pdi
->has_specification
)
8013 auto res
= find_partial_die (real_pdi
->spec_offset
,
8014 real_pdi
->spec_is_dwz
, cu
);
8019 parent
= real_pdi
->die_parent
;
8023 if (parent
->scope_set
)
8024 return parent
->scope
;
8028 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8030 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8031 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8032 Work around this problem here. */
8033 if (cu
->language
== language_cplus
8034 && parent
->tag
== DW_TAG_namespace
8035 && strcmp (parent
->name
, "::") == 0
8036 && grandparent_scope
== NULL
)
8038 parent
->scope
= NULL
;
8039 parent
->scope_set
= 1;
8043 /* Nested subroutines in Fortran get a prefix. */
8044 if (pdi
->tag
== DW_TAG_enumerator
)
8045 /* Enumerators should not get the name of the enumeration as a prefix. */
8046 parent
->scope
= grandparent_scope
;
8047 else if (parent
->tag
== DW_TAG_namespace
8048 || parent
->tag
== DW_TAG_module
8049 || parent
->tag
== DW_TAG_structure_type
8050 || parent
->tag
== DW_TAG_class_type
8051 || parent
->tag
== DW_TAG_interface_type
8052 || parent
->tag
== DW_TAG_union_type
8053 || parent
->tag
== DW_TAG_enumeration_type
8054 || (cu
->language
== language_fortran
8055 && parent
->tag
== DW_TAG_subprogram
8056 && pdi
->tag
== DW_TAG_subprogram
))
8058 if (grandparent_scope
== NULL
)
8059 parent
->scope
= parent
->name
;
8061 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8063 parent
->name
, 0, cu
);
8067 /* FIXME drow/2004-04-01: What should we be doing with
8068 function-local names? For partial symbols, we should probably be
8070 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8071 dwarf_tag_name (parent
->tag
),
8072 sect_offset_str (pdi
->sect_off
));
8073 parent
->scope
= grandparent_scope
;
8076 parent
->scope_set
= 1;
8077 return parent
->scope
;
8080 /* Return the fully scoped name associated with PDI, from compilation unit
8081 CU. The result will be allocated with malloc. */
8083 static gdb::unique_xmalloc_ptr
<char>
8084 partial_die_full_name (struct partial_die_info
*pdi
,
8085 struct dwarf2_cu
*cu
)
8087 const char *parent_scope
;
8089 /* If this is a template instantiation, we can not work out the
8090 template arguments from partial DIEs. So, unfortunately, we have
8091 to go through the full DIEs. At least any work we do building
8092 types here will be reused if full symbols are loaded later. */
8093 if (pdi
->has_template_arguments
)
8097 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8099 struct die_info
*die
;
8100 struct attribute attr
;
8101 struct dwarf2_cu
*ref_cu
= cu
;
8103 /* DW_FORM_ref_addr is using section offset. */
8104 attr
.name
= (enum dwarf_attribute
) 0;
8105 attr
.form
= DW_FORM_ref_addr
;
8106 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8107 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8109 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8113 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8114 if (parent_scope
== NULL
)
8117 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8122 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8124 struct dwarf2_per_objfile
*dwarf2_per_objfile
8125 = cu
->per_cu
->dwarf2_per_objfile
;
8126 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8127 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8129 const char *actual_name
= NULL
;
8132 baseaddr
= objfile
->text_section_offset ();
8134 gdb::unique_xmalloc_ptr
<char> built_actual_name
8135 = partial_die_full_name (pdi
, cu
);
8136 if (built_actual_name
!= NULL
)
8137 actual_name
= built_actual_name
.get ();
8139 if (actual_name
== NULL
)
8140 actual_name
= pdi
->name
;
8144 case DW_TAG_inlined_subroutine
:
8145 case DW_TAG_subprogram
:
8146 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8148 if (pdi
->is_external
8149 || cu
->language
== language_ada
8150 || (cu
->language
== language_fortran
8151 && pdi
->die_parent
!= NULL
8152 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8154 /* Normally, only "external" DIEs are part of the global scope.
8155 But in Ada and Fortran, we want to be able to access nested
8156 procedures globally. So all Ada and Fortran subprograms are
8157 stored in the global scope. */
8158 add_psymbol_to_list (actual_name
,
8159 built_actual_name
!= NULL
,
8160 VAR_DOMAIN
, LOC_BLOCK
,
8161 SECT_OFF_TEXT (objfile
),
8162 psymbol_placement::GLOBAL
,
8164 cu
->language
, objfile
);
8168 add_psymbol_to_list (actual_name
,
8169 built_actual_name
!= NULL
,
8170 VAR_DOMAIN
, LOC_BLOCK
,
8171 SECT_OFF_TEXT (objfile
),
8172 psymbol_placement::STATIC
,
8173 addr
, cu
->language
, objfile
);
8176 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8177 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8179 case DW_TAG_constant
:
8180 add_psymbol_to_list (actual_name
,
8181 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8182 -1, (pdi
->is_external
8183 ? psymbol_placement::GLOBAL
8184 : psymbol_placement::STATIC
),
8185 0, cu
->language
, objfile
);
8187 case DW_TAG_variable
:
8189 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8193 && !dwarf2_per_objfile
->has_section_at_zero
)
8195 /* A global or static variable may also have been stripped
8196 out by the linker if unused, in which case its address
8197 will be nullified; do not add such variables into partial
8198 symbol table then. */
8200 else if (pdi
->is_external
)
8203 Don't enter into the minimal symbol tables as there is
8204 a minimal symbol table entry from the ELF symbols already.
8205 Enter into partial symbol table if it has a location
8206 descriptor or a type.
8207 If the location descriptor is missing, new_symbol will create
8208 a LOC_UNRESOLVED symbol, the address of the variable will then
8209 be determined from the minimal symbol table whenever the variable
8211 The address for the partial symbol table entry is not
8212 used by GDB, but it comes in handy for debugging partial symbol
8215 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8216 add_psymbol_to_list (actual_name
,
8217 built_actual_name
!= NULL
,
8218 VAR_DOMAIN
, LOC_STATIC
,
8219 SECT_OFF_TEXT (objfile
),
8220 psymbol_placement::GLOBAL
,
8221 addr
, cu
->language
, objfile
);
8225 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8227 /* Static Variable. Skip symbols whose value we cannot know (those
8228 without location descriptors or constant values). */
8229 if (!has_loc
&& !pdi
->has_const_value
)
8232 add_psymbol_to_list (actual_name
,
8233 built_actual_name
!= NULL
,
8234 VAR_DOMAIN
, LOC_STATIC
,
8235 SECT_OFF_TEXT (objfile
),
8236 psymbol_placement::STATIC
,
8238 cu
->language
, objfile
);
8241 case DW_TAG_typedef
:
8242 case DW_TAG_base_type
:
8243 case DW_TAG_subrange_type
:
8244 add_psymbol_to_list (actual_name
,
8245 built_actual_name
!= NULL
,
8246 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8247 psymbol_placement::STATIC
,
8248 0, cu
->language
, objfile
);
8250 case DW_TAG_imported_declaration
:
8251 case DW_TAG_namespace
:
8252 add_psymbol_to_list (actual_name
,
8253 built_actual_name
!= NULL
,
8254 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8255 psymbol_placement::GLOBAL
,
8256 0, cu
->language
, objfile
);
8259 /* With Fortran 77 there might be a "BLOCK DATA" module
8260 available without any name. If so, we skip the module as it
8261 doesn't bring any value. */
8262 if (actual_name
!= nullptr)
8263 add_psymbol_to_list (actual_name
,
8264 built_actual_name
!= NULL
,
8265 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8266 psymbol_placement::GLOBAL
,
8267 0, cu
->language
, objfile
);
8269 case DW_TAG_class_type
:
8270 case DW_TAG_interface_type
:
8271 case DW_TAG_structure_type
:
8272 case DW_TAG_union_type
:
8273 case DW_TAG_enumeration_type
:
8274 /* Skip external references. The DWARF standard says in the section
8275 about "Structure, Union, and Class Type Entries": "An incomplete
8276 structure, union or class type is represented by a structure,
8277 union or class entry that does not have a byte size attribute
8278 and that has a DW_AT_declaration attribute." */
8279 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8282 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8283 static vs. global. */
8284 add_psymbol_to_list (actual_name
,
8285 built_actual_name
!= NULL
,
8286 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8287 cu
->language
== language_cplus
8288 ? psymbol_placement::GLOBAL
8289 : psymbol_placement::STATIC
,
8290 0, cu
->language
, objfile
);
8293 case DW_TAG_enumerator
:
8294 add_psymbol_to_list (actual_name
,
8295 built_actual_name
!= NULL
,
8296 VAR_DOMAIN
, LOC_CONST
, -1,
8297 cu
->language
== language_cplus
8298 ? psymbol_placement::GLOBAL
8299 : psymbol_placement::STATIC
,
8300 0, cu
->language
, objfile
);
8307 /* Read a partial die corresponding to a namespace; also, add a symbol
8308 corresponding to that namespace to the symbol table. NAMESPACE is
8309 the name of the enclosing namespace. */
8312 add_partial_namespace (struct partial_die_info
*pdi
,
8313 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8314 int set_addrmap
, struct dwarf2_cu
*cu
)
8316 /* Add a symbol for the namespace. */
8318 add_partial_symbol (pdi
, cu
);
8320 /* Now scan partial symbols in that namespace. */
8322 if (pdi
->has_children
)
8323 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8326 /* Read a partial die corresponding to a Fortran module. */
8329 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8330 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8332 /* Add a symbol for the namespace. */
8334 add_partial_symbol (pdi
, cu
);
8336 /* Now scan partial symbols in that module. */
8338 if (pdi
->has_children
)
8339 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8342 /* Read a partial die corresponding to a subprogram or an inlined
8343 subprogram and create a partial symbol for that subprogram.
8344 When the CU language allows it, this routine also defines a partial
8345 symbol for each nested subprogram that this subprogram contains.
8346 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8347 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8349 PDI may also be a lexical block, in which case we simply search
8350 recursively for subprograms defined inside that lexical block.
8351 Again, this is only performed when the CU language allows this
8352 type of definitions. */
8355 add_partial_subprogram (struct partial_die_info
*pdi
,
8356 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8357 int set_addrmap
, struct dwarf2_cu
*cu
)
8359 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8361 if (pdi
->has_pc_info
)
8363 if (pdi
->lowpc
< *lowpc
)
8364 *lowpc
= pdi
->lowpc
;
8365 if (pdi
->highpc
> *highpc
)
8366 *highpc
= pdi
->highpc
;
8369 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8370 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8372 CORE_ADDR this_highpc
;
8373 CORE_ADDR this_lowpc
;
8375 baseaddr
= objfile
->text_section_offset ();
8377 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8378 pdi
->lowpc
+ baseaddr
)
8381 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8382 pdi
->highpc
+ baseaddr
)
8384 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8385 this_lowpc
, this_highpc
- 1,
8386 cu
->per_cu
->v
.psymtab
);
8390 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8392 if (!pdi
->is_declaration
)
8393 /* Ignore subprogram DIEs that do not have a name, they are
8394 illegal. Do not emit a complaint at this point, we will
8395 do so when we convert this psymtab into a symtab. */
8397 add_partial_symbol (pdi
, cu
);
8401 if (! pdi
->has_children
)
8404 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8406 pdi
= pdi
->die_child
;
8410 if (pdi
->tag
== DW_TAG_subprogram
8411 || pdi
->tag
== DW_TAG_inlined_subroutine
8412 || pdi
->tag
== DW_TAG_lexical_block
)
8413 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8414 pdi
= pdi
->die_sibling
;
8419 /* Read a partial die corresponding to an enumeration type. */
8422 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8423 struct dwarf2_cu
*cu
)
8425 struct partial_die_info
*pdi
;
8427 if (enum_pdi
->name
!= NULL
)
8428 add_partial_symbol (enum_pdi
, cu
);
8430 pdi
= enum_pdi
->die_child
;
8433 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8434 complaint (_("malformed enumerator DIE ignored"));
8436 add_partial_symbol (pdi
, cu
);
8437 pdi
= pdi
->die_sibling
;
8441 /* Return the initial uleb128 in the die at INFO_PTR. */
8444 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8446 unsigned int bytes_read
;
8448 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8451 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8452 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8454 Return the corresponding abbrev, or NULL if the number is zero (indicating
8455 an empty DIE). In either case *BYTES_READ will be set to the length of
8456 the initial number. */
8458 static struct abbrev_info
*
8459 peek_die_abbrev (const die_reader_specs
&reader
,
8460 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8462 dwarf2_cu
*cu
= reader
.cu
;
8463 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8464 unsigned int abbrev_number
8465 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8467 if (abbrev_number
== 0)
8470 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8473 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8474 " at offset %s [in module %s]"),
8475 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8476 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8482 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8483 Returns a pointer to the end of a series of DIEs, terminated by an empty
8484 DIE. Any children of the skipped DIEs will also be skipped. */
8486 static const gdb_byte
*
8487 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8491 unsigned int bytes_read
;
8492 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8495 return info_ptr
+ bytes_read
;
8497 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8501 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8502 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8503 abbrev corresponding to that skipped uleb128 should be passed in
8504 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8507 static const gdb_byte
*
8508 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8509 struct abbrev_info
*abbrev
)
8511 unsigned int bytes_read
;
8512 struct attribute attr
;
8513 bfd
*abfd
= reader
->abfd
;
8514 struct dwarf2_cu
*cu
= reader
->cu
;
8515 const gdb_byte
*buffer
= reader
->buffer
;
8516 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8517 unsigned int form
, i
;
8519 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8521 /* The only abbrev we care about is DW_AT_sibling. */
8522 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8525 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8527 if (attr
.form
== DW_FORM_ref_addr
)
8528 complaint (_("ignoring absolute DW_AT_sibling"));
8531 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8532 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8534 if (sibling_ptr
< info_ptr
)
8535 complaint (_("DW_AT_sibling points backwards"));
8536 else if (sibling_ptr
> reader
->buffer_end
)
8537 reader
->die_section
->overflow_complaint ();
8543 /* If it isn't DW_AT_sibling, skip this attribute. */
8544 form
= abbrev
->attrs
[i
].form
;
8548 case DW_FORM_ref_addr
:
8549 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8550 and later it is offset sized. */
8551 if (cu
->header
.version
== 2)
8552 info_ptr
+= cu
->header
.addr_size
;
8554 info_ptr
+= cu
->header
.offset_size
;
8556 case DW_FORM_GNU_ref_alt
:
8557 info_ptr
+= cu
->header
.offset_size
;
8560 info_ptr
+= cu
->header
.addr_size
;
8568 case DW_FORM_flag_present
:
8569 case DW_FORM_implicit_const
:
8586 case DW_FORM_ref_sig8
:
8589 case DW_FORM_data16
:
8592 case DW_FORM_string
:
8593 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8594 info_ptr
+= bytes_read
;
8596 case DW_FORM_sec_offset
:
8598 case DW_FORM_GNU_strp_alt
:
8599 info_ptr
+= cu
->header
.offset_size
;
8601 case DW_FORM_exprloc
:
8603 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8604 info_ptr
+= bytes_read
;
8606 case DW_FORM_block1
:
8607 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8609 case DW_FORM_block2
:
8610 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8612 case DW_FORM_block4
:
8613 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8619 case DW_FORM_ref_udata
:
8620 case DW_FORM_GNU_addr_index
:
8621 case DW_FORM_GNU_str_index
:
8622 case DW_FORM_rnglistx
:
8623 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8625 case DW_FORM_indirect
:
8626 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8627 info_ptr
+= bytes_read
;
8628 /* We need to continue parsing from here, so just go back to
8630 goto skip_attribute
;
8633 error (_("Dwarf Error: Cannot handle %s "
8634 "in DWARF reader [in module %s]"),
8635 dwarf_form_name (form
),
8636 bfd_get_filename (abfd
));
8640 if (abbrev
->has_children
)
8641 return skip_children (reader
, info_ptr
);
8646 /* Locate ORIG_PDI's sibling.
8647 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8649 static const gdb_byte
*
8650 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8651 struct partial_die_info
*orig_pdi
,
8652 const gdb_byte
*info_ptr
)
8654 /* Do we know the sibling already? */
8656 if (orig_pdi
->sibling
)
8657 return orig_pdi
->sibling
;
8659 /* Are there any children to deal with? */
8661 if (!orig_pdi
->has_children
)
8664 /* Skip the children the long way. */
8666 return skip_children (reader
, info_ptr
);
8669 /* Expand this partial symbol table into a full symbol table. SELF is
8673 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8675 struct dwarf2_per_objfile
*dwarf2_per_objfile
8676 = get_dwarf2_per_objfile (objfile
);
8678 gdb_assert (!readin
);
8679 /* If this psymtab is constructed from a debug-only objfile, the
8680 has_section_at_zero flag will not necessarily be correct. We
8681 can get the correct value for this flag by looking at the data
8682 associated with the (presumably stripped) associated objfile. */
8683 if (objfile
->separate_debug_objfile_backlink
)
8685 struct dwarf2_per_objfile
*dpo_backlink
8686 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8688 dwarf2_per_objfile
->has_section_at_zero
8689 = dpo_backlink
->has_section_at_zero
;
8692 expand_psymtab (objfile
);
8694 process_cu_includes (dwarf2_per_objfile
);
8697 /* Reading in full CUs. */
8699 /* Add PER_CU to the queue. */
8702 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8703 enum language pretend_language
)
8706 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8709 /* If PER_CU is not yet queued, add it to the queue.
8710 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8712 The result is non-zero if PER_CU was queued, otherwise the result is zero
8713 meaning either PER_CU is already queued or it is already loaded.
8715 N.B. There is an invariant here that if a CU is queued then it is loaded.
8716 The caller is required to load PER_CU if we return non-zero. */
8719 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8720 struct dwarf2_per_cu_data
*per_cu
,
8721 enum language pretend_language
)
8723 /* We may arrive here during partial symbol reading, if we need full
8724 DIEs to process an unusual case (e.g. template arguments). Do
8725 not queue PER_CU, just tell our caller to load its DIEs. */
8726 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8728 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8733 /* Mark the dependence relation so that we don't flush PER_CU
8735 if (dependent_cu
!= NULL
)
8736 dwarf2_add_dependence (dependent_cu
, per_cu
);
8738 /* If it's already on the queue, we have nothing to do. */
8742 /* If the compilation unit is already loaded, just mark it as
8744 if (per_cu
->cu
!= NULL
)
8746 per_cu
->cu
->last_used
= 0;
8750 /* Add it to the queue. */
8751 queue_comp_unit (per_cu
, pretend_language
);
8756 /* Process the queue. */
8759 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8761 if (dwarf_read_debug
)
8763 fprintf_unfiltered (gdb_stdlog
,
8764 "Expanding one or more symtabs of objfile %s ...\n",
8765 objfile_name (dwarf2_per_objfile
->objfile
));
8768 /* The queue starts out with one item, but following a DIE reference
8769 may load a new CU, adding it to the end of the queue. */
8770 while (!dwarf2_per_objfile
->queue
.empty ())
8772 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8774 if ((dwarf2_per_objfile
->using_index
8775 ? !item
.per_cu
->v
.quick
->compunit_symtab
8776 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8777 /* Skip dummy CUs. */
8778 && item
.per_cu
->cu
!= NULL
)
8780 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8781 unsigned int debug_print_threshold
;
8784 if (per_cu
->is_debug_types
)
8786 struct signatured_type
*sig_type
=
8787 (struct signatured_type
*) per_cu
;
8789 sprintf (buf
, "TU %s at offset %s",
8790 hex_string (sig_type
->signature
),
8791 sect_offset_str (per_cu
->sect_off
));
8792 /* There can be 100s of TUs.
8793 Only print them in verbose mode. */
8794 debug_print_threshold
= 2;
8798 sprintf (buf
, "CU at offset %s",
8799 sect_offset_str (per_cu
->sect_off
));
8800 debug_print_threshold
= 1;
8803 if (dwarf_read_debug
>= debug_print_threshold
)
8804 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8806 if (per_cu
->is_debug_types
)
8807 process_full_type_unit (per_cu
, item
.pretend_language
);
8809 process_full_comp_unit (per_cu
, item
.pretend_language
);
8811 if (dwarf_read_debug
>= debug_print_threshold
)
8812 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8815 item
.per_cu
->queued
= 0;
8816 dwarf2_per_objfile
->queue
.pop ();
8819 if (dwarf_read_debug
)
8821 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8822 objfile_name (dwarf2_per_objfile
->objfile
));
8826 /* Read in full symbols for PST, and anything it depends on. */
8829 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8834 read_dependencies (objfile
);
8836 dw2_do_instantiate_symtab (per_cu_data
, false);
8837 gdb_assert (get_compunit_symtab () != nullptr);
8840 /* Trivial hash function for die_info: the hash value of a DIE
8841 is its offset in .debug_info for this objfile. */
8844 die_hash (const void *item
)
8846 const struct die_info
*die
= (const struct die_info
*) item
;
8848 return to_underlying (die
->sect_off
);
8851 /* Trivial comparison function for die_info structures: two DIEs
8852 are equal if they have the same offset. */
8855 die_eq (const void *item_lhs
, const void *item_rhs
)
8857 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8858 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8860 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8863 /* Load the DIEs associated with PER_CU into memory. */
8866 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8868 enum language pretend_language
)
8870 gdb_assert (! this_cu
->is_debug_types
);
8872 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8876 struct dwarf2_cu
*cu
= reader
.cu
;
8877 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8879 gdb_assert (cu
->die_hash
== NULL
);
8881 htab_create_alloc_ex (cu
->header
.length
/ 12,
8885 &cu
->comp_unit_obstack
,
8886 hashtab_obstack_allocate
,
8887 dummy_obstack_deallocate
);
8889 if (reader
.comp_unit_die
->has_children
)
8890 reader
.comp_unit_die
->child
8891 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8892 &info_ptr
, reader
.comp_unit_die
);
8893 cu
->dies
= reader
.comp_unit_die
;
8894 /* comp_unit_die is not stored in die_hash, no need. */
8896 /* We try not to read any attributes in this function, because not
8897 all CUs needed for references have been loaded yet, and symbol
8898 table processing isn't initialized. But we have to set the CU language,
8899 or we won't be able to build types correctly.
8900 Similarly, if we do not read the producer, we can not apply
8901 producer-specific interpretation. */
8902 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8907 /* Add a DIE to the delayed physname list. */
8910 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8911 const char *name
, struct die_info
*die
,
8912 struct dwarf2_cu
*cu
)
8914 struct delayed_method_info mi
;
8916 mi
.fnfield_index
= fnfield_index
;
8920 cu
->method_list
.push_back (mi
);
8923 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8924 "const" / "volatile". If so, decrements LEN by the length of the
8925 modifier and return true. Otherwise return false. */
8929 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8931 size_t mod_len
= sizeof (mod
) - 1;
8932 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8940 /* Compute the physnames of any methods on the CU's method list.
8942 The computation of method physnames is delayed in order to avoid the
8943 (bad) condition that one of the method's formal parameters is of an as yet
8947 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8949 /* Only C++ delays computing physnames. */
8950 if (cu
->method_list
.empty ())
8952 gdb_assert (cu
->language
== language_cplus
);
8954 for (const delayed_method_info
&mi
: cu
->method_list
)
8956 const char *physname
;
8957 struct fn_fieldlist
*fn_flp
8958 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8959 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8960 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8961 = physname
? physname
: "";
8963 /* Since there's no tag to indicate whether a method is a
8964 const/volatile overload, extract that information out of the
8966 if (physname
!= NULL
)
8968 size_t len
= strlen (physname
);
8972 if (physname
[len
] == ')') /* shortcut */
8974 else if (check_modifier (physname
, len
, " const"))
8975 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8976 else if (check_modifier (physname
, len
, " volatile"))
8977 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8984 /* The list is no longer needed. */
8985 cu
->method_list
.clear ();
8988 /* Go objects should be embedded in a DW_TAG_module DIE,
8989 and it's not clear if/how imported objects will appear.
8990 To keep Go support simple until that's worked out,
8991 go back through what we've read and create something usable.
8992 We could do this while processing each DIE, and feels kinda cleaner,
8993 but that way is more invasive.
8994 This is to, for example, allow the user to type "p var" or "b main"
8995 without having to specify the package name, and allow lookups
8996 of module.object to work in contexts that use the expression
9000 fixup_go_packaging (struct dwarf2_cu
*cu
)
9002 gdb::unique_xmalloc_ptr
<char> package_name
;
9003 struct pending
*list
;
9006 for (list
= *cu
->get_builder ()->get_global_symbols ();
9010 for (i
= 0; i
< list
->nsyms
; ++i
)
9012 struct symbol
*sym
= list
->symbol
[i
];
9014 if (sym
->language () == language_go
9015 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9017 gdb::unique_xmalloc_ptr
<char> this_package_name
9018 (go_symbol_package_name (sym
));
9020 if (this_package_name
== NULL
)
9022 if (package_name
== NULL
)
9023 package_name
= std::move (this_package_name
);
9026 struct objfile
*objfile
9027 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9028 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9029 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9030 (symbol_symtab (sym
) != NULL
9031 ? symtab_to_filename_for_display
9032 (symbol_symtab (sym
))
9033 : objfile_name (objfile
)),
9034 this_package_name
.get (), package_name
.get ());
9040 if (package_name
!= NULL
)
9042 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9043 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9044 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9045 saved_package_name
);
9048 sym
= allocate_symbol (objfile
);
9049 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9050 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9051 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9052 e.g., "main" finds the "main" module and not C's main(). */
9053 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9054 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9055 SYMBOL_TYPE (sym
) = type
;
9057 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9061 /* Allocate a fully-qualified name consisting of the two parts on the
9065 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9067 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9070 /* A helper that allocates a struct discriminant_info to attach to a
9073 static struct discriminant_info
*
9074 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9077 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9078 gdb_assert (discriminant_index
== -1
9079 || (discriminant_index
>= 0
9080 && discriminant_index
< TYPE_NFIELDS (type
)));
9081 gdb_assert (default_index
== -1
9082 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9084 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9086 struct discriminant_info
*disc
9087 = ((struct discriminant_info
*)
9089 offsetof (struct discriminant_info
, discriminants
)
9090 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9091 disc
->default_index
= default_index
;
9092 disc
->discriminant_index
= discriminant_index
;
9094 struct dynamic_prop prop
;
9095 prop
.kind
= PROP_UNDEFINED
;
9096 prop
.data
.baton
= disc
;
9098 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9103 /* Some versions of rustc emitted enums in an unusual way.
9105 Ordinary enums were emitted as unions. The first element of each
9106 structure in the union was named "RUST$ENUM$DISR". This element
9107 held the discriminant.
9109 These versions of Rust also implemented the "non-zero"
9110 optimization. When the enum had two values, and one is empty and
9111 the other holds a pointer that cannot be zero, the pointer is used
9112 as the discriminant, with a zero value meaning the empty variant.
9113 Here, the union's first member is of the form
9114 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9115 where the fieldnos are the indices of the fields that should be
9116 traversed in order to find the field (which may be several fields deep)
9117 and the variantname is the name of the variant of the case when the
9120 This function recognizes whether TYPE is of one of these forms,
9121 and, if so, smashes it to be a variant type. */
9124 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9126 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9128 /* We don't need to deal with empty enums. */
9129 if (TYPE_NFIELDS (type
) == 0)
9132 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9133 if (TYPE_NFIELDS (type
) == 1
9134 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9136 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9138 /* Decode the field name to find the offset of the
9140 ULONGEST bit_offset
= 0;
9141 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9142 while (name
[0] >= '0' && name
[0] <= '9')
9145 unsigned long index
= strtoul (name
, &tail
, 10);
9148 || index
>= TYPE_NFIELDS (field_type
)
9149 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9150 != FIELD_LOC_KIND_BITPOS
))
9152 complaint (_("Could not parse Rust enum encoding string \"%s\""
9154 TYPE_FIELD_NAME (type
, 0),
9155 objfile_name (objfile
));
9160 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9161 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9164 /* Make a union to hold the variants. */
9165 struct type
*union_type
= alloc_type (objfile
);
9166 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9167 TYPE_NFIELDS (union_type
) = 3;
9168 TYPE_FIELDS (union_type
)
9169 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9170 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9171 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9173 /* Put the discriminant must at index 0. */
9174 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9175 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9176 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9177 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9179 /* The order of fields doesn't really matter, so put the real
9180 field at index 1 and the data-less field at index 2. */
9181 struct discriminant_info
*disc
9182 = alloc_discriminant_info (union_type
, 0, 1);
9183 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9184 TYPE_FIELD_NAME (union_type
, 1)
9185 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9186 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9187 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9188 TYPE_FIELD_NAME (union_type
, 1));
9190 const char *dataless_name
9191 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9193 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9195 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9196 /* NAME points into the original discriminant name, which
9197 already has the correct lifetime. */
9198 TYPE_FIELD_NAME (union_type
, 2) = name
;
9199 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9200 disc
->discriminants
[2] = 0;
9202 /* Smash this type to be a structure type. We have to do this
9203 because the type has already been recorded. */
9204 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9205 TYPE_NFIELDS (type
) = 1;
9207 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9209 /* Install the variant part. */
9210 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9211 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9212 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9214 /* A union with a single anonymous field is probably an old-style
9216 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9218 /* Smash this type to be a structure type. We have to do this
9219 because the type has already been recorded. */
9220 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9222 /* Make a union to hold the variants. */
9223 struct type
*union_type
= alloc_type (objfile
);
9224 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9225 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9226 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9227 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9228 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9230 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9231 const char *variant_name
9232 = rust_last_path_segment (TYPE_NAME (field_type
));
9233 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9234 TYPE_NAME (field_type
)
9235 = rust_fully_qualify (&objfile
->objfile_obstack
,
9236 TYPE_NAME (type
), variant_name
);
9238 /* Install the union in the outer struct type. */
9239 TYPE_NFIELDS (type
) = 1;
9241 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9242 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9243 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9244 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9246 alloc_discriminant_info (union_type
, -1, 0);
9250 struct type
*disr_type
= nullptr;
9251 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9253 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9255 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9257 /* All fields of a true enum will be structs. */
9260 else if (TYPE_NFIELDS (disr_type
) == 0)
9262 /* Could be data-less variant, so keep going. */
9263 disr_type
= nullptr;
9265 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9266 "RUST$ENUM$DISR") != 0)
9268 /* Not a Rust enum. */
9278 /* If we got here without a discriminant, then it's probably
9280 if (disr_type
== nullptr)
9283 /* Smash this type to be a structure type. We have to do this
9284 because the type has already been recorded. */
9285 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9287 /* Make a union to hold the variants. */
9288 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9289 struct type
*union_type
= alloc_type (objfile
);
9290 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9291 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9292 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9293 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9294 TYPE_FIELDS (union_type
)
9295 = (struct field
*) TYPE_ZALLOC (union_type
,
9296 (TYPE_NFIELDS (union_type
)
9297 * sizeof (struct field
)));
9299 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9300 TYPE_NFIELDS (type
) * sizeof (struct field
));
9302 /* Install the discriminant at index 0 in the union. */
9303 TYPE_FIELD (union_type
, 0) = *disr_field
;
9304 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9305 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9307 /* Install the union in the outer struct type. */
9308 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9309 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9310 TYPE_NFIELDS (type
) = 1;
9312 /* Set the size and offset of the union type. */
9313 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9315 /* We need a way to find the correct discriminant given a
9316 variant name. For convenience we build a map here. */
9317 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9318 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9319 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9321 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9324 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9325 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9329 int n_fields
= TYPE_NFIELDS (union_type
);
9330 struct discriminant_info
*disc
9331 = alloc_discriminant_info (union_type
, 0, -1);
9332 /* Skip the discriminant here. */
9333 for (int i
= 1; i
< n_fields
; ++i
)
9335 /* Find the final word in the name of this variant's type.
9336 That name can be used to look up the correct
9338 const char *variant_name
9339 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9342 auto iter
= discriminant_map
.find (variant_name
);
9343 if (iter
!= discriminant_map
.end ())
9344 disc
->discriminants
[i
] = iter
->second
;
9346 /* Remove the discriminant field, if it exists. */
9347 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9348 if (TYPE_NFIELDS (sub_type
) > 0)
9350 --TYPE_NFIELDS (sub_type
);
9351 ++TYPE_FIELDS (sub_type
);
9353 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9354 TYPE_NAME (sub_type
)
9355 = rust_fully_qualify (&objfile
->objfile_obstack
,
9356 TYPE_NAME (type
), variant_name
);
9361 /* Rewrite some Rust unions to be structures with variants parts. */
9364 rust_union_quirks (struct dwarf2_cu
*cu
)
9366 gdb_assert (cu
->language
== language_rust
);
9367 for (type
*type_
: cu
->rust_unions
)
9368 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9369 /* We don't need this any more. */
9370 cu
->rust_unions
.clear ();
9373 /* Return the symtab for PER_CU. This works properly regardless of
9374 whether we're using the index or psymtabs. */
9376 static struct compunit_symtab
*
9377 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9379 return (per_cu
->dwarf2_per_objfile
->using_index
9380 ? per_cu
->v
.quick
->compunit_symtab
9381 : per_cu
->v
.psymtab
->compunit_symtab
);
9384 /* A helper function for computing the list of all symbol tables
9385 included by PER_CU. */
9388 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9389 htab_t all_children
, htab_t all_type_symtabs
,
9390 struct dwarf2_per_cu_data
*per_cu
,
9391 struct compunit_symtab
*immediate_parent
)
9394 struct compunit_symtab
*cust
;
9396 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9399 /* This inclusion and its children have been processed. */
9404 /* Only add a CU if it has a symbol table. */
9405 cust
= get_compunit_symtab (per_cu
);
9408 /* If this is a type unit only add its symbol table if we haven't
9409 seen it yet (type unit per_cu's can share symtabs). */
9410 if (per_cu
->is_debug_types
)
9412 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9416 result
->push_back (cust
);
9417 if (cust
->user
== NULL
)
9418 cust
->user
= immediate_parent
;
9423 result
->push_back (cust
);
9424 if (cust
->user
== NULL
)
9425 cust
->user
= immediate_parent
;
9429 if (!per_cu
->imported_symtabs_empty ())
9430 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9432 recursively_compute_inclusions (result
, all_children
,
9433 all_type_symtabs
, ptr
, cust
);
9437 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9441 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9443 gdb_assert (! per_cu
->is_debug_types
);
9445 if (!per_cu
->imported_symtabs_empty ())
9448 std::vector
<compunit_symtab
*> result_symtabs
;
9449 htab_t all_children
, all_type_symtabs
;
9450 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9452 /* If we don't have a symtab, we can just skip this case. */
9456 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9457 NULL
, xcalloc
, xfree
);
9458 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9459 NULL
, xcalloc
, xfree
);
9461 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9463 recursively_compute_inclusions (&result_symtabs
, all_children
,
9464 all_type_symtabs
, ptr
, cust
);
9467 /* Now we have a transitive closure of all the included symtabs. */
9468 len
= result_symtabs
.size ();
9470 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9471 struct compunit_symtab
*, len
+ 1);
9472 memcpy (cust
->includes
, result_symtabs
.data (),
9473 len
* sizeof (compunit_symtab
*));
9474 cust
->includes
[len
] = NULL
;
9476 htab_delete (all_children
);
9477 htab_delete (all_type_symtabs
);
9481 /* Compute the 'includes' field for the symtabs of all the CUs we just
9485 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9487 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9489 if (! iter
->is_debug_types
)
9490 compute_compunit_symtab_includes (iter
);
9493 dwarf2_per_objfile
->just_read_cus
.clear ();
9496 /* Generate full symbol information for PER_CU, whose DIEs have
9497 already been loaded into memory. */
9500 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9501 enum language pretend_language
)
9503 struct dwarf2_cu
*cu
= per_cu
->cu
;
9504 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9505 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9506 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9507 CORE_ADDR lowpc
, highpc
;
9508 struct compunit_symtab
*cust
;
9510 struct block
*static_block
;
9513 baseaddr
= objfile
->text_section_offset ();
9515 /* Clear the list here in case something was left over. */
9516 cu
->method_list
.clear ();
9518 cu
->language
= pretend_language
;
9519 cu
->language_defn
= language_def (cu
->language
);
9521 /* Do line number decoding in read_file_scope () */
9522 process_die (cu
->dies
, cu
);
9524 /* For now fudge the Go package. */
9525 if (cu
->language
== language_go
)
9526 fixup_go_packaging (cu
);
9528 /* Now that we have processed all the DIEs in the CU, all the types
9529 should be complete, and it should now be safe to compute all of the
9531 compute_delayed_physnames (cu
);
9533 if (cu
->language
== language_rust
)
9534 rust_union_quirks (cu
);
9536 /* Some compilers don't define a DW_AT_high_pc attribute for the
9537 compilation unit. If the DW_AT_high_pc is missing, synthesize
9538 it, by scanning the DIE's below the compilation unit. */
9539 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9541 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9542 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9544 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9545 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9546 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9547 addrmap to help ensure it has an accurate map of pc values belonging to
9549 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9551 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9552 SECT_OFF_TEXT (objfile
),
9557 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9559 /* Set symtab language to language from DW_AT_language. If the
9560 compilation is from a C file generated by language preprocessors, do
9561 not set the language if it was already deduced by start_subfile. */
9562 if (!(cu
->language
== language_c
9563 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9564 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9566 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9567 produce DW_AT_location with location lists but it can be possibly
9568 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9569 there were bugs in prologue debug info, fixed later in GCC-4.5
9570 by "unwind info for epilogues" patch (which is not directly related).
9572 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9573 needed, it would be wrong due to missing DW_AT_producer there.
9575 Still one can confuse GDB by using non-standard GCC compilation
9576 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9578 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9579 cust
->locations_valid
= 1;
9581 if (gcc_4_minor
>= 5)
9582 cust
->epilogue_unwind_valid
= 1;
9584 cust
->call_site_htab
= cu
->call_site_htab
;
9587 if (dwarf2_per_objfile
->using_index
)
9588 per_cu
->v
.quick
->compunit_symtab
= cust
;
9591 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9592 pst
->compunit_symtab
= cust
;
9596 /* Push it for inclusion processing later. */
9597 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9599 /* Not needed any more. */
9600 cu
->reset_builder ();
9603 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9604 already been loaded into memory. */
9607 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9608 enum language pretend_language
)
9610 struct dwarf2_cu
*cu
= per_cu
->cu
;
9611 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9612 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9613 struct compunit_symtab
*cust
;
9614 struct signatured_type
*sig_type
;
9616 gdb_assert (per_cu
->is_debug_types
);
9617 sig_type
= (struct signatured_type
*) per_cu
;
9619 /* Clear the list here in case something was left over. */
9620 cu
->method_list
.clear ();
9622 cu
->language
= pretend_language
;
9623 cu
->language_defn
= language_def (cu
->language
);
9625 /* The symbol tables are set up in read_type_unit_scope. */
9626 process_die (cu
->dies
, cu
);
9628 /* For now fudge the Go package. */
9629 if (cu
->language
== language_go
)
9630 fixup_go_packaging (cu
);
9632 /* Now that we have processed all the DIEs in the CU, all the types
9633 should be complete, and it should now be safe to compute all of the
9635 compute_delayed_physnames (cu
);
9637 if (cu
->language
== language_rust
)
9638 rust_union_quirks (cu
);
9640 /* TUs share symbol tables.
9641 If this is the first TU to use this symtab, complete the construction
9642 of it with end_expandable_symtab. Otherwise, complete the addition of
9643 this TU's symbols to the existing symtab. */
9644 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9646 buildsym_compunit
*builder
= cu
->get_builder ();
9647 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9648 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9652 /* Set symtab language to language from DW_AT_language. If the
9653 compilation is from a C file generated by language preprocessors,
9654 do not set the language if it was already deduced by
9656 if (!(cu
->language
== language_c
9657 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9658 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9663 cu
->get_builder ()->augment_type_symtab ();
9664 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9667 if (dwarf2_per_objfile
->using_index
)
9668 per_cu
->v
.quick
->compunit_symtab
= cust
;
9671 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9672 pst
->compunit_symtab
= cust
;
9676 /* Not needed any more. */
9677 cu
->reset_builder ();
9680 /* Process an imported unit DIE. */
9683 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9685 struct attribute
*attr
;
9687 /* For now we don't handle imported units in type units. */
9688 if (cu
->per_cu
->is_debug_types
)
9690 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9691 " supported in type units [in module %s]"),
9692 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9695 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9698 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9699 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9700 dwarf2_per_cu_data
*per_cu
9701 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9702 cu
->per_cu
->dwarf2_per_objfile
);
9704 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9705 into another compilation unit, at root level. Regard this as a hint,
9707 if (die
->parent
&& die
->parent
->parent
== NULL
9708 && per_cu
->unit_type
== DW_UT_compile
9709 && per_cu
->lang
== language_cplus
)
9712 /* If necessary, add it to the queue and load its DIEs. */
9713 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9714 load_full_comp_unit (per_cu
, false, cu
->language
);
9716 cu
->per_cu
->imported_symtabs_push (per_cu
);
9720 /* RAII object that represents a process_die scope: i.e.,
9721 starts/finishes processing a DIE. */
9722 class process_die_scope
9725 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9726 : m_die (die
), m_cu (cu
)
9728 /* We should only be processing DIEs not already in process. */
9729 gdb_assert (!m_die
->in_process
);
9730 m_die
->in_process
= true;
9733 ~process_die_scope ()
9735 m_die
->in_process
= false;
9737 /* If we're done processing the DIE for the CU that owns the line
9738 header, we don't need the line header anymore. */
9739 if (m_cu
->line_header_die_owner
== m_die
)
9741 delete m_cu
->line_header
;
9742 m_cu
->line_header
= NULL
;
9743 m_cu
->line_header_die_owner
= NULL
;
9752 /* Process a die and its children. */
9755 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9757 process_die_scope
scope (die
, cu
);
9761 case DW_TAG_padding
:
9763 case DW_TAG_compile_unit
:
9764 case DW_TAG_partial_unit
:
9765 read_file_scope (die
, cu
);
9767 case DW_TAG_type_unit
:
9768 read_type_unit_scope (die
, cu
);
9770 case DW_TAG_subprogram
:
9771 /* Nested subprograms in Fortran get a prefix. */
9772 if (cu
->language
== language_fortran
9773 && die
->parent
!= NULL
9774 && die
->parent
->tag
== DW_TAG_subprogram
)
9775 cu
->processing_has_namespace_info
= true;
9777 case DW_TAG_inlined_subroutine
:
9778 read_func_scope (die
, cu
);
9780 case DW_TAG_lexical_block
:
9781 case DW_TAG_try_block
:
9782 case DW_TAG_catch_block
:
9783 read_lexical_block_scope (die
, cu
);
9785 case DW_TAG_call_site
:
9786 case DW_TAG_GNU_call_site
:
9787 read_call_site_scope (die
, cu
);
9789 case DW_TAG_class_type
:
9790 case DW_TAG_interface_type
:
9791 case DW_TAG_structure_type
:
9792 case DW_TAG_union_type
:
9793 process_structure_scope (die
, cu
);
9795 case DW_TAG_enumeration_type
:
9796 process_enumeration_scope (die
, cu
);
9799 /* These dies have a type, but processing them does not create
9800 a symbol or recurse to process the children. Therefore we can
9801 read them on-demand through read_type_die. */
9802 case DW_TAG_subroutine_type
:
9803 case DW_TAG_set_type
:
9804 case DW_TAG_array_type
:
9805 case DW_TAG_pointer_type
:
9806 case DW_TAG_ptr_to_member_type
:
9807 case DW_TAG_reference_type
:
9808 case DW_TAG_rvalue_reference_type
:
9809 case DW_TAG_string_type
:
9812 case DW_TAG_base_type
:
9813 case DW_TAG_subrange_type
:
9814 case DW_TAG_typedef
:
9815 /* Add a typedef symbol for the type definition, if it has a
9817 new_symbol (die
, read_type_die (die
, cu
), cu
);
9819 case DW_TAG_common_block
:
9820 read_common_block (die
, cu
);
9822 case DW_TAG_common_inclusion
:
9824 case DW_TAG_namespace
:
9825 cu
->processing_has_namespace_info
= true;
9826 read_namespace (die
, cu
);
9829 cu
->processing_has_namespace_info
= true;
9830 read_module (die
, cu
);
9832 case DW_TAG_imported_declaration
:
9833 cu
->processing_has_namespace_info
= true;
9834 if (read_namespace_alias (die
, cu
))
9836 /* The declaration is not a global namespace alias. */
9838 case DW_TAG_imported_module
:
9839 cu
->processing_has_namespace_info
= true;
9840 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9841 || cu
->language
!= language_fortran
))
9842 complaint (_("Tag '%s' has unexpected children"),
9843 dwarf_tag_name (die
->tag
));
9844 read_import_statement (die
, cu
);
9847 case DW_TAG_imported_unit
:
9848 process_imported_unit_die (die
, cu
);
9851 case DW_TAG_variable
:
9852 read_variable (die
, cu
);
9856 new_symbol (die
, NULL
, cu
);
9861 /* DWARF name computation. */
9863 /* A helper function for dwarf2_compute_name which determines whether DIE
9864 needs to have the name of the scope prepended to the name listed in the
9868 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9870 struct attribute
*attr
;
9874 case DW_TAG_namespace
:
9875 case DW_TAG_typedef
:
9876 case DW_TAG_class_type
:
9877 case DW_TAG_interface_type
:
9878 case DW_TAG_structure_type
:
9879 case DW_TAG_union_type
:
9880 case DW_TAG_enumeration_type
:
9881 case DW_TAG_enumerator
:
9882 case DW_TAG_subprogram
:
9883 case DW_TAG_inlined_subroutine
:
9885 case DW_TAG_imported_declaration
:
9888 case DW_TAG_variable
:
9889 case DW_TAG_constant
:
9890 /* We only need to prefix "globally" visible variables. These include
9891 any variable marked with DW_AT_external or any variable that
9892 lives in a namespace. [Variables in anonymous namespaces
9893 require prefixing, but they are not DW_AT_external.] */
9895 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9897 struct dwarf2_cu
*spec_cu
= cu
;
9899 return die_needs_namespace (die_specification (die
, &spec_cu
),
9903 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9904 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9905 && die
->parent
->tag
!= DW_TAG_module
)
9907 /* A variable in a lexical block of some kind does not need a
9908 namespace, even though in C++ such variables may be external
9909 and have a mangled name. */
9910 if (die
->parent
->tag
== DW_TAG_lexical_block
9911 || die
->parent
->tag
== DW_TAG_try_block
9912 || die
->parent
->tag
== DW_TAG_catch_block
9913 || die
->parent
->tag
== DW_TAG_subprogram
)
9922 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9923 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9924 defined for the given DIE. */
9926 static struct attribute
*
9927 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9929 struct attribute
*attr
;
9931 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9933 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9938 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9939 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9940 defined for the given DIE. */
9943 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9945 const char *linkage_name
;
9947 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9948 if (linkage_name
== NULL
)
9949 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9951 return linkage_name
;
9954 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9955 compute the physname for the object, which include a method's:
9956 - formal parameters (C++),
9957 - receiver type (Go),
9959 The term "physname" is a bit confusing.
9960 For C++, for example, it is the demangled name.
9961 For Go, for example, it's the mangled name.
9963 For Ada, return the DIE's linkage name rather than the fully qualified
9964 name. PHYSNAME is ignored..
9966 The result is allocated on the objfile_obstack and canonicalized. */
9969 dwarf2_compute_name (const char *name
,
9970 struct die_info
*die
, struct dwarf2_cu
*cu
,
9973 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9976 name
= dwarf2_name (die
, cu
);
9978 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9979 but otherwise compute it by typename_concat inside GDB.
9980 FIXME: Actually this is not really true, or at least not always true.
9981 It's all very confusing. compute_and_set_names doesn't try to demangle
9982 Fortran names because there is no mangling standard. So new_symbol
9983 will set the demangled name to the result of dwarf2_full_name, and it is
9984 the demangled name that GDB uses if it exists. */
9985 if (cu
->language
== language_ada
9986 || (cu
->language
== language_fortran
&& physname
))
9988 /* For Ada unit, we prefer the linkage name over the name, as
9989 the former contains the exported name, which the user expects
9990 to be able to reference. Ideally, we want the user to be able
9991 to reference this entity using either natural or linkage name,
9992 but we haven't started looking at this enhancement yet. */
9993 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9995 if (linkage_name
!= NULL
)
9996 return linkage_name
;
9999 /* These are the only languages we know how to qualify names in. */
10001 && (cu
->language
== language_cplus
10002 || cu
->language
== language_fortran
|| cu
->language
== language_d
10003 || cu
->language
== language_rust
))
10005 if (die_needs_namespace (die
, cu
))
10007 const char *prefix
;
10008 const char *canonical_name
= NULL
;
10012 prefix
= determine_prefix (die
, cu
);
10013 if (*prefix
!= '\0')
10015 gdb::unique_xmalloc_ptr
<char> prefixed_name
10016 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10018 buf
.puts (prefixed_name
.get ());
10023 /* Template parameters may be specified in the DIE's DW_AT_name, or
10024 as children with DW_TAG_template_type_param or
10025 DW_TAG_value_type_param. If the latter, add them to the name
10026 here. If the name already has template parameters, then
10027 skip this step; some versions of GCC emit both, and
10028 it is more efficient to use the pre-computed name.
10030 Something to keep in mind about this process: it is very
10031 unlikely, or in some cases downright impossible, to produce
10032 something that will match the mangled name of a function.
10033 If the definition of the function has the same debug info,
10034 we should be able to match up with it anyway. But fallbacks
10035 using the minimal symbol, for instance to find a method
10036 implemented in a stripped copy of libstdc++, will not work.
10037 If we do not have debug info for the definition, we will have to
10038 match them up some other way.
10040 When we do name matching there is a related problem with function
10041 templates; two instantiated function templates are allowed to
10042 differ only by their return types, which we do not add here. */
10044 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10046 struct attribute
*attr
;
10047 struct die_info
*child
;
10050 die
->building_fullname
= 1;
10052 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10056 const gdb_byte
*bytes
;
10057 struct dwarf2_locexpr_baton
*baton
;
10060 if (child
->tag
!= DW_TAG_template_type_param
10061 && child
->tag
!= DW_TAG_template_value_param
)
10072 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10075 complaint (_("template parameter missing DW_AT_type"));
10076 buf
.puts ("UNKNOWN_TYPE");
10079 type
= die_type (child
, cu
);
10081 if (child
->tag
== DW_TAG_template_type_param
)
10083 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10084 &type_print_raw_options
);
10088 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10091 complaint (_("template parameter missing "
10092 "DW_AT_const_value"));
10093 buf
.puts ("UNKNOWN_VALUE");
10097 dwarf2_const_value_attr (attr
, type
, name
,
10098 &cu
->comp_unit_obstack
, cu
,
10099 &value
, &bytes
, &baton
);
10101 if (TYPE_NOSIGN (type
))
10102 /* GDB prints characters as NUMBER 'CHAR'. If that's
10103 changed, this can use value_print instead. */
10104 c_printchar (value
, type
, &buf
);
10107 struct value_print_options opts
;
10110 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10114 else if (bytes
!= NULL
)
10116 v
= allocate_value (type
);
10117 memcpy (value_contents_writeable (v
), bytes
,
10118 TYPE_LENGTH (type
));
10121 v
= value_from_longest (type
, value
);
10123 /* Specify decimal so that we do not depend on
10125 get_formatted_print_options (&opts
, 'd');
10127 value_print (v
, &buf
, &opts
);
10132 die
->building_fullname
= 0;
10136 /* Close the argument list, with a space if necessary
10137 (nested templates). */
10138 if (!buf
.empty () && buf
.string ().back () == '>')
10145 /* For C++ methods, append formal parameter type
10146 information, if PHYSNAME. */
10148 if (physname
&& die
->tag
== DW_TAG_subprogram
10149 && cu
->language
== language_cplus
)
10151 struct type
*type
= read_type_die (die
, cu
);
10153 c_type_print_args (type
, &buf
, 1, cu
->language
,
10154 &type_print_raw_options
);
10156 if (cu
->language
== language_cplus
)
10158 /* Assume that an artificial first parameter is
10159 "this", but do not crash if it is not. RealView
10160 marks unnamed (and thus unused) parameters as
10161 artificial; there is no way to differentiate
10163 if (TYPE_NFIELDS (type
) > 0
10164 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10165 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10166 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10168 buf
.puts (" const");
10172 const std::string
&intermediate_name
= buf
.string ();
10174 if (cu
->language
== language_cplus
)
10176 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10179 /* If we only computed INTERMEDIATE_NAME, or if
10180 INTERMEDIATE_NAME is already canonical, then we need to
10182 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10183 name
= objfile
->intern (intermediate_name
);
10185 name
= canonical_name
;
10192 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10193 If scope qualifiers are appropriate they will be added. The result
10194 will be allocated on the storage_obstack, or NULL if the DIE does
10195 not have a name. NAME may either be from a previous call to
10196 dwarf2_name or NULL.
10198 The output string will be canonicalized (if C++). */
10200 static const char *
10201 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10203 return dwarf2_compute_name (name
, die
, cu
, 0);
10206 /* Construct a physname for the given DIE in CU. NAME may either be
10207 from a previous call to dwarf2_name or NULL. The result will be
10208 allocated on the objfile_objstack or NULL if the DIE does not have a
10211 The output string will be canonicalized (if C++). */
10213 static const char *
10214 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10216 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10217 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10220 /* In this case dwarf2_compute_name is just a shortcut not building anything
10222 if (!die_needs_namespace (die
, cu
))
10223 return dwarf2_compute_name (name
, die
, cu
, 1);
10225 mangled
= dw2_linkage_name (die
, cu
);
10227 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10228 See https://github.com/rust-lang/rust/issues/32925. */
10229 if (cu
->language
== language_rust
&& mangled
!= NULL
10230 && strchr (mangled
, '{') != NULL
)
10233 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10235 gdb::unique_xmalloc_ptr
<char> demangled
;
10236 if (mangled
!= NULL
)
10239 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10241 /* Do nothing (do not demangle the symbol name). */
10243 else if (cu
->language
== language_go
)
10245 /* This is a lie, but we already lie to the caller new_symbol.
10246 new_symbol assumes we return the mangled name.
10247 This just undoes that lie until things are cleaned up. */
10251 /* Use DMGL_RET_DROP for C++ template functions to suppress
10252 their return type. It is easier for GDB users to search
10253 for such functions as `name(params)' than `long name(params)'.
10254 In such case the minimal symbol names do not match the full
10255 symbol names but for template functions there is never a need
10256 to look up their definition from their declaration so
10257 the only disadvantage remains the minimal symbol variant
10258 `long name(params)' does not have the proper inferior type. */
10259 demangled
.reset (gdb_demangle (mangled
,
10260 (DMGL_PARAMS
| DMGL_ANSI
10261 | DMGL_RET_DROP
)));
10264 canon
= demangled
.get ();
10272 if (canon
== NULL
|| check_physname
)
10274 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10276 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10278 /* It may not mean a bug in GDB. The compiler could also
10279 compute DW_AT_linkage_name incorrectly. But in such case
10280 GDB would need to be bug-to-bug compatible. */
10282 complaint (_("Computed physname <%s> does not match demangled <%s> "
10283 "(from linkage <%s>) - DIE at %s [in module %s]"),
10284 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10285 objfile_name (objfile
));
10287 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10288 is available here - over computed PHYSNAME. It is safer
10289 against both buggy GDB and buggy compilers. */
10303 retval
= objfile
->intern (retval
);
10308 /* Inspect DIE in CU for a namespace alias. If one exists, record
10309 a new symbol for it.
10311 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10314 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10316 struct attribute
*attr
;
10318 /* If the die does not have a name, this is not a namespace
10320 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10324 struct die_info
*d
= die
;
10325 struct dwarf2_cu
*imported_cu
= cu
;
10327 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10328 keep inspecting DIEs until we hit the underlying import. */
10329 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10330 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10332 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10336 d
= follow_die_ref (d
, attr
, &imported_cu
);
10337 if (d
->tag
!= DW_TAG_imported_declaration
)
10341 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10343 complaint (_("DIE at %s has too many recursively imported "
10344 "declarations"), sect_offset_str (d
->sect_off
));
10351 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10353 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10354 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10356 /* This declaration is a global namespace alias. Add
10357 a symbol for it whose type is the aliased namespace. */
10358 new_symbol (die
, type
, cu
);
10367 /* Return the using directives repository (global or local?) to use in the
10368 current context for CU.
10370 For Ada, imported declarations can materialize renamings, which *may* be
10371 global. However it is impossible (for now?) in DWARF to distinguish
10372 "external" imported declarations and "static" ones. As all imported
10373 declarations seem to be static in all other languages, make them all CU-wide
10374 global only in Ada. */
10376 static struct using_direct
**
10377 using_directives (struct dwarf2_cu
*cu
)
10379 if (cu
->language
== language_ada
10380 && cu
->get_builder ()->outermost_context_p ())
10381 return cu
->get_builder ()->get_global_using_directives ();
10383 return cu
->get_builder ()->get_local_using_directives ();
10386 /* Read the import statement specified by the given die and record it. */
10389 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10391 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10392 struct attribute
*import_attr
;
10393 struct die_info
*imported_die
, *child_die
;
10394 struct dwarf2_cu
*imported_cu
;
10395 const char *imported_name
;
10396 const char *imported_name_prefix
;
10397 const char *canonical_name
;
10398 const char *import_alias
;
10399 const char *imported_declaration
= NULL
;
10400 const char *import_prefix
;
10401 std::vector
<const char *> excludes
;
10403 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10404 if (import_attr
== NULL
)
10406 complaint (_("Tag '%s' has no DW_AT_import"),
10407 dwarf_tag_name (die
->tag
));
10412 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10413 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10414 if (imported_name
== NULL
)
10416 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10418 The import in the following code:
10432 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10433 <52> DW_AT_decl_file : 1
10434 <53> DW_AT_decl_line : 6
10435 <54> DW_AT_import : <0x75>
10436 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10437 <59> DW_AT_name : B
10438 <5b> DW_AT_decl_file : 1
10439 <5c> DW_AT_decl_line : 2
10440 <5d> DW_AT_type : <0x6e>
10442 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10443 <76> DW_AT_byte_size : 4
10444 <77> DW_AT_encoding : 5 (signed)
10446 imports the wrong die ( 0x75 instead of 0x58 ).
10447 This case will be ignored until the gcc bug is fixed. */
10451 /* Figure out the local name after import. */
10452 import_alias
= dwarf2_name (die
, cu
);
10454 /* Figure out where the statement is being imported to. */
10455 import_prefix
= determine_prefix (die
, cu
);
10457 /* Figure out what the scope of the imported die is and prepend it
10458 to the name of the imported die. */
10459 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10461 if (imported_die
->tag
!= DW_TAG_namespace
10462 && imported_die
->tag
!= DW_TAG_module
)
10464 imported_declaration
= imported_name
;
10465 canonical_name
= imported_name_prefix
;
10467 else if (strlen (imported_name_prefix
) > 0)
10468 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10469 imported_name_prefix
,
10470 (cu
->language
== language_d
? "." : "::"),
10471 imported_name
, (char *) NULL
);
10473 canonical_name
= imported_name
;
10475 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10476 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10477 child_die
= sibling_die (child_die
))
10479 /* DWARF-4: A Fortran use statement with a “rename list” may be
10480 represented by an imported module entry with an import attribute
10481 referring to the module and owned entries corresponding to those
10482 entities that are renamed as part of being imported. */
10484 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10486 complaint (_("child DW_TAG_imported_declaration expected "
10487 "- DIE at %s [in module %s]"),
10488 sect_offset_str (child_die
->sect_off
),
10489 objfile_name (objfile
));
10493 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10494 if (import_attr
== NULL
)
10496 complaint (_("Tag '%s' has no DW_AT_import"),
10497 dwarf_tag_name (child_die
->tag
));
10502 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10504 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10505 if (imported_name
== NULL
)
10507 complaint (_("child DW_TAG_imported_declaration has unknown "
10508 "imported name - DIE at %s [in module %s]"),
10509 sect_offset_str (child_die
->sect_off
),
10510 objfile_name (objfile
));
10514 excludes
.push_back (imported_name
);
10516 process_die (child_die
, cu
);
10519 add_using_directive (using_directives (cu
),
10523 imported_declaration
,
10526 &objfile
->objfile_obstack
);
10529 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10530 types, but gives them a size of zero. Starting with version 14,
10531 ICC is compatible with GCC. */
10534 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10536 if (!cu
->checked_producer
)
10537 check_producer (cu
);
10539 return cu
->producer_is_icc_lt_14
;
10542 /* ICC generates a DW_AT_type for C void functions. This was observed on
10543 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10544 which says that void functions should not have a DW_AT_type. */
10547 producer_is_icc (struct dwarf2_cu
*cu
)
10549 if (!cu
->checked_producer
)
10550 check_producer (cu
);
10552 return cu
->producer_is_icc
;
10555 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10556 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10557 this, it was first present in GCC release 4.3.0. */
10560 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10562 if (!cu
->checked_producer
)
10563 check_producer (cu
);
10565 return cu
->producer_is_gcc_lt_4_3
;
10568 static file_and_directory
10569 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10571 file_and_directory res
;
10573 /* Find the filename. Do not use dwarf2_name here, since the filename
10574 is not a source language identifier. */
10575 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10576 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10578 if (res
.comp_dir
== NULL
10579 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10580 && IS_ABSOLUTE_PATH (res
.name
))
10582 res
.comp_dir_storage
= ldirname (res
.name
);
10583 if (!res
.comp_dir_storage
.empty ())
10584 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10586 if (res
.comp_dir
!= NULL
)
10588 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10589 directory, get rid of it. */
10590 const char *cp
= strchr (res
.comp_dir
, ':');
10592 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10593 res
.comp_dir
= cp
+ 1;
10596 if (res
.name
== NULL
)
10597 res
.name
= "<unknown>";
10602 /* Handle DW_AT_stmt_list for a compilation unit.
10603 DIE is the DW_TAG_compile_unit die for CU.
10604 COMP_DIR is the compilation directory. LOWPC is passed to
10605 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10608 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10609 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10611 struct dwarf2_per_objfile
*dwarf2_per_objfile
10612 = cu
->per_cu
->dwarf2_per_objfile
;
10613 struct attribute
*attr
;
10614 struct line_header line_header_local
;
10615 hashval_t line_header_local_hash
;
10617 int decode_mapping
;
10619 gdb_assert (! cu
->per_cu
->is_debug_types
);
10621 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10625 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10627 /* The line header hash table is only created if needed (it exists to
10628 prevent redundant reading of the line table for partial_units).
10629 If we're given a partial_unit, we'll need it. If we're given a
10630 compile_unit, then use the line header hash table if it's already
10631 created, but don't create one just yet. */
10633 if (dwarf2_per_objfile
->line_header_hash
== NULL
10634 && die
->tag
== DW_TAG_partial_unit
)
10636 dwarf2_per_objfile
->line_header_hash
10637 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10638 line_header_eq_voidp
,
10639 free_line_header_voidp
,
10643 line_header_local
.sect_off
= line_offset
;
10644 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10645 line_header_local_hash
= line_header_hash (&line_header_local
);
10646 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10648 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10649 &line_header_local
,
10650 line_header_local_hash
, NO_INSERT
);
10652 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10653 is not present in *SLOT (since if there is something in *SLOT then
10654 it will be for a partial_unit). */
10655 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10657 gdb_assert (*slot
!= NULL
);
10658 cu
->line_header
= (struct line_header
*) *slot
;
10663 /* dwarf_decode_line_header does not yet provide sufficient information.
10664 We always have to call also dwarf_decode_lines for it. */
10665 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10669 cu
->line_header
= lh
.release ();
10670 cu
->line_header_die_owner
= die
;
10672 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10676 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10677 &line_header_local
,
10678 line_header_local_hash
, INSERT
);
10679 gdb_assert (slot
!= NULL
);
10681 if (slot
!= NULL
&& *slot
== NULL
)
10683 /* This newly decoded line number information unit will be owned
10684 by line_header_hash hash table. */
10685 *slot
= cu
->line_header
;
10686 cu
->line_header_die_owner
= NULL
;
10690 /* We cannot free any current entry in (*slot) as that struct line_header
10691 may be already used by multiple CUs. Create only temporary decoded
10692 line_header for this CU - it may happen at most once for each line
10693 number information unit. And if we're not using line_header_hash
10694 then this is what we want as well. */
10695 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10697 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10698 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10703 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10706 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10708 struct dwarf2_per_objfile
*dwarf2_per_objfile
10709 = cu
->per_cu
->dwarf2_per_objfile
;
10710 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10711 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10712 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10713 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10714 struct attribute
*attr
;
10715 struct die_info
*child_die
;
10716 CORE_ADDR baseaddr
;
10718 prepare_one_comp_unit (cu
, die
, cu
->language
);
10719 baseaddr
= objfile
->text_section_offset ();
10721 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10723 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10724 from finish_block. */
10725 if (lowpc
== ((CORE_ADDR
) -1))
10727 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10729 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10731 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10732 standardised yet. As a workaround for the language detection we fall
10733 back to the DW_AT_producer string. */
10734 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10735 cu
->language
= language_opencl
;
10737 /* Similar hack for Go. */
10738 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10739 set_cu_language (DW_LANG_Go
, cu
);
10741 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10743 /* Decode line number information if present. We do this before
10744 processing child DIEs, so that the line header table is available
10745 for DW_AT_decl_file. */
10746 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10748 /* Process all dies in compilation unit. */
10749 if (die
->child
!= NULL
)
10751 child_die
= die
->child
;
10752 while (child_die
&& child_die
->tag
)
10754 process_die (child_die
, cu
);
10755 child_die
= sibling_die (child_die
);
10759 /* Decode macro information, if present. Dwarf 2 macro information
10760 refers to information in the line number info statement program
10761 header, so we can only read it if we've read the header
10763 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10765 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10766 if (attr
&& cu
->line_header
)
10768 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10769 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10771 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10775 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10776 if (attr
&& cu
->line_header
)
10778 unsigned int macro_offset
= DW_UNSND (attr
);
10780 dwarf_decode_macros (cu
, macro_offset
, 0);
10786 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10788 struct type_unit_group
*tu_group
;
10790 struct attribute
*attr
;
10792 struct signatured_type
*sig_type
;
10794 gdb_assert (per_cu
->is_debug_types
);
10795 sig_type
= (struct signatured_type
*) per_cu
;
10797 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10799 /* If we're using .gdb_index (includes -readnow) then
10800 per_cu->type_unit_group may not have been set up yet. */
10801 if (sig_type
->type_unit_group
== NULL
)
10802 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10803 tu_group
= sig_type
->type_unit_group
;
10805 /* If we've already processed this stmt_list there's no real need to
10806 do it again, we could fake it and just recreate the part we need
10807 (file name,index -> symtab mapping). If data shows this optimization
10808 is useful we can do it then. */
10809 first_time
= tu_group
->compunit_symtab
== NULL
;
10811 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10816 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10817 lh
= dwarf_decode_line_header (line_offset
, this);
10822 start_symtab ("", NULL
, 0);
10825 gdb_assert (tu_group
->symtabs
== NULL
);
10826 gdb_assert (m_builder
== nullptr);
10827 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10828 m_builder
.reset (new struct buildsym_compunit
10829 (COMPUNIT_OBJFILE (cust
), "",
10830 COMPUNIT_DIRNAME (cust
),
10831 compunit_language (cust
),
10837 line_header
= lh
.release ();
10838 line_header_die_owner
= die
;
10842 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10844 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10845 still initializing it, and our caller (a few levels up)
10846 process_full_type_unit still needs to know if this is the first
10850 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10851 struct symtab
*, line_header
->file_names_size ());
10853 auto &file_names
= line_header
->file_names ();
10854 for (i
= 0; i
< file_names
.size (); ++i
)
10856 file_entry
&fe
= file_names
[i
];
10857 dwarf2_start_subfile (this, fe
.name
,
10858 fe
.include_dir (line_header
));
10859 buildsym_compunit
*b
= get_builder ();
10860 if (b
->get_current_subfile ()->symtab
== NULL
)
10862 /* NOTE: start_subfile will recognize when it's been
10863 passed a file it has already seen. So we can't
10864 assume there's a simple mapping from
10865 cu->line_header->file_names to subfiles, plus
10866 cu->line_header->file_names may contain dups. */
10867 b
->get_current_subfile ()->symtab
10868 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10871 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10872 tu_group
->symtabs
[i
] = fe
.symtab
;
10877 gdb_assert (m_builder
== nullptr);
10878 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10879 m_builder
.reset (new struct buildsym_compunit
10880 (COMPUNIT_OBJFILE (cust
), "",
10881 COMPUNIT_DIRNAME (cust
),
10882 compunit_language (cust
),
10885 auto &file_names
= line_header
->file_names ();
10886 for (i
= 0; i
< file_names
.size (); ++i
)
10888 file_entry
&fe
= file_names
[i
];
10889 fe
.symtab
= tu_group
->symtabs
[i
];
10893 /* The main symtab is allocated last. Type units don't have DW_AT_name
10894 so they don't have a "real" (so to speak) symtab anyway.
10895 There is later code that will assign the main symtab to all symbols
10896 that don't have one. We need to handle the case of a symbol with a
10897 missing symtab (DW_AT_decl_file) anyway. */
10900 /* Process DW_TAG_type_unit.
10901 For TUs we want to skip the first top level sibling if it's not the
10902 actual type being defined by this TU. In this case the first top
10903 level sibling is there to provide context only. */
10906 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10908 struct die_info
*child_die
;
10910 prepare_one_comp_unit (cu
, die
, language_minimal
);
10912 /* Initialize (or reinitialize) the machinery for building symtabs.
10913 We do this before processing child DIEs, so that the line header table
10914 is available for DW_AT_decl_file. */
10915 cu
->setup_type_unit_groups (die
);
10917 if (die
->child
!= NULL
)
10919 child_die
= die
->child
;
10920 while (child_die
&& child_die
->tag
)
10922 process_die (child_die
, cu
);
10923 child_die
= sibling_die (child_die
);
10930 http://gcc.gnu.org/wiki/DebugFission
10931 http://gcc.gnu.org/wiki/DebugFissionDWP
10933 To simplify handling of both DWO files ("object" files with the DWARF info)
10934 and DWP files (a file with the DWOs packaged up into one file), we treat
10935 DWP files as having a collection of virtual DWO files. */
10938 hash_dwo_file (const void *item
)
10940 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10943 hash
= htab_hash_string (dwo_file
->dwo_name
);
10944 if (dwo_file
->comp_dir
!= NULL
)
10945 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10950 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10952 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10953 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10955 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10957 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10958 return lhs
->comp_dir
== rhs
->comp_dir
;
10959 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10962 /* Allocate a hash table for DWO files. */
10965 allocate_dwo_file_hash_table ()
10967 auto delete_dwo_file
= [] (void *item
)
10969 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10974 return htab_up (htab_create_alloc (41,
10981 /* Lookup DWO file DWO_NAME. */
10984 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
10985 const char *dwo_name
,
10986 const char *comp_dir
)
10988 struct dwo_file find_entry
;
10991 if (dwarf2_per_objfile
->dwo_files
== NULL
)
10992 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
10994 find_entry
.dwo_name
= dwo_name
;
10995 find_entry
.comp_dir
= comp_dir
;
10996 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11003 hash_dwo_unit (const void *item
)
11005 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11007 /* This drops the top 32 bits of the id, but is ok for a hash. */
11008 return dwo_unit
->signature
;
11012 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11014 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11015 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11017 /* The signature is assumed to be unique within the DWO file.
11018 So while object file CU dwo_id's always have the value zero,
11019 that's OK, assuming each object file DWO file has only one CU,
11020 and that's the rule for now. */
11021 return lhs
->signature
== rhs
->signature
;
11024 /* Allocate a hash table for DWO CUs,TUs.
11025 There is one of these tables for each of CUs,TUs for each DWO file. */
11028 allocate_dwo_unit_table ()
11030 /* Start out with a pretty small number.
11031 Generally DWO files contain only one CU and maybe some TUs. */
11032 return htab_up (htab_create_alloc (3,
11035 NULL
, xcalloc
, xfree
));
11038 /* die_reader_func for create_dwo_cu. */
11041 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11042 const gdb_byte
*info_ptr
,
11043 struct die_info
*comp_unit_die
,
11044 struct dwo_file
*dwo_file
,
11045 struct dwo_unit
*dwo_unit
)
11047 struct dwarf2_cu
*cu
= reader
->cu
;
11048 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11049 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11051 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11052 if (!signature
.has_value ())
11054 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11055 " its dwo_id [in module %s]"),
11056 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11060 dwo_unit
->dwo_file
= dwo_file
;
11061 dwo_unit
->signature
= *signature
;
11062 dwo_unit
->section
= section
;
11063 dwo_unit
->sect_off
= sect_off
;
11064 dwo_unit
->length
= cu
->per_cu
->length
;
11066 if (dwarf_read_debug
)
11067 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11068 sect_offset_str (sect_off
),
11069 hex_string (dwo_unit
->signature
));
11072 /* Create the dwo_units for the CUs in a DWO_FILE.
11073 Note: This function processes DWO files only, not DWP files. */
11076 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11077 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11078 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11080 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11081 const gdb_byte
*info_ptr
, *end_ptr
;
11083 section
.read (objfile
);
11084 info_ptr
= section
.buffer
;
11086 if (info_ptr
== NULL
)
11089 if (dwarf_read_debug
)
11091 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11092 section
.get_name (),
11093 section
.get_file_name ());
11096 end_ptr
= info_ptr
+ section
.size
;
11097 while (info_ptr
< end_ptr
)
11099 struct dwarf2_per_cu_data per_cu
;
11100 struct dwo_unit read_unit
{};
11101 struct dwo_unit
*dwo_unit
;
11103 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11105 memset (&per_cu
, 0, sizeof (per_cu
));
11106 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11107 per_cu
.is_debug_types
= 0;
11108 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11109 per_cu
.section
= §ion
;
11111 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11112 if (!reader
.dummy_p
)
11113 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11114 &dwo_file
, &read_unit
);
11115 info_ptr
+= per_cu
.length
;
11117 // If the unit could not be parsed, skip it.
11118 if (read_unit
.dwo_file
== NULL
)
11121 if (cus_htab
== NULL
)
11122 cus_htab
= allocate_dwo_unit_table ();
11124 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11125 *dwo_unit
= read_unit
;
11126 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11127 gdb_assert (slot
!= NULL
);
11130 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11131 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11133 complaint (_("debug cu entry at offset %s is duplicate to"
11134 " the entry at offset %s, signature %s"),
11135 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11136 hex_string (dwo_unit
->signature
));
11138 *slot
= (void *)dwo_unit
;
11142 /* DWP file .debug_{cu,tu}_index section format:
11143 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11147 Both index sections have the same format, and serve to map a 64-bit
11148 signature to a set of section numbers. Each section begins with a header,
11149 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11150 indexes, and a pool of 32-bit section numbers. The index sections will be
11151 aligned at 8-byte boundaries in the file.
11153 The index section header consists of:
11155 V, 32 bit version number
11157 N, 32 bit number of compilation units or type units in the index
11158 M, 32 bit number of slots in the hash table
11160 Numbers are recorded using the byte order of the application binary.
11162 The hash table begins at offset 16 in the section, and consists of an array
11163 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11164 order of the application binary). Unused slots in the hash table are 0.
11165 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11167 The parallel table begins immediately after the hash table
11168 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11169 array of 32-bit indexes (using the byte order of the application binary),
11170 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11171 table contains a 32-bit index into the pool of section numbers. For unused
11172 hash table slots, the corresponding entry in the parallel table will be 0.
11174 The pool of section numbers begins immediately following the hash table
11175 (at offset 16 + 12 * M from the beginning of the section). The pool of
11176 section numbers consists of an array of 32-bit words (using the byte order
11177 of the application binary). Each item in the array is indexed starting
11178 from 0. The hash table entry provides the index of the first section
11179 number in the set. Additional section numbers in the set follow, and the
11180 set is terminated by a 0 entry (section number 0 is not used in ELF).
11182 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11183 section must be the first entry in the set, and the .debug_abbrev.dwo must
11184 be the second entry. Other members of the set may follow in any order.
11190 DWP Version 2 combines all the .debug_info, etc. sections into one,
11191 and the entries in the index tables are now offsets into these sections.
11192 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11195 Index Section Contents:
11197 Hash Table of Signatures dwp_hash_table.hash_table
11198 Parallel Table of Indices dwp_hash_table.unit_table
11199 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11200 Table of Section Sizes dwp_hash_table.v2.sizes
11202 The index section header consists of:
11204 V, 32 bit version number
11205 L, 32 bit number of columns in the table of section offsets
11206 N, 32 bit number of compilation units or type units in the index
11207 M, 32 bit number of slots in the hash table
11209 Numbers are recorded using the byte order of the application binary.
11211 The hash table has the same format as version 1.
11212 The parallel table of indices has the same format as version 1,
11213 except that the entries are origin-1 indices into the table of sections
11214 offsets and the table of section sizes.
11216 The table of offsets begins immediately following the parallel table
11217 (at offset 16 + 12 * M from the beginning of the section). The table is
11218 a two-dimensional array of 32-bit words (using the byte order of the
11219 application binary), with L columns and N+1 rows, in row-major order.
11220 Each row in the array is indexed starting from 0. The first row provides
11221 a key to the remaining rows: each column in this row provides an identifier
11222 for a debug section, and the offsets in the same column of subsequent rows
11223 refer to that section. The section identifiers are:
11225 DW_SECT_INFO 1 .debug_info.dwo
11226 DW_SECT_TYPES 2 .debug_types.dwo
11227 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11228 DW_SECT_LINE 4 .debug_line.dwo
11229 DW_SECT_LOC 5 .debug_loc.dwo
11230 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11231 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11232 DW_SECT_MACRO 8 .debug_macro.dwo
11234 The offsets provided by the CU and TU index sections are the base offsets
11235 for the contributions made by each CU or TU to the corresponding section
11236 in the package file. Each CU and TU header contains an abbrev_offset
11237 field, used to find the abbreviations table for that CU or TU within the
11238 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11239 be interpreted as relative to the base offset given in the index section.
11240 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11241 should be interpreted as relative to the base offset for .debug_line.dwo,
11242 and offsets into other debug sections obtained from DWARF attributes should
11243 also be interpreted as relative to the corresponding base offset.
11245 The table of sizes begins immediately following the table of offsets.
11246 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11247 with L columns and N rows, in row-major order. Each row in the array is
11248 indexed starting from 1 (row 0 is shared by the two tables).
11252 Hash table lookup is handled the same in version 1 and 2:
11254 We assume that N and M will not exceed 2^32 - 1.
11255 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11257 Given a 64-bit compilation unit signature or a type signature S, an entry
11258 in the hash table is located as follows:
11260 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11261 the low-order k bits all set to 1.
11263 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11265 3) If the hash table entry at index H matches the signature, use that
11266 entry. If the hash table entry at index H is unused (all zeroes),
11267 terminate the search: the signature is not present in the table.
11269 4) Let H = (H + H') modulo M. Repeat at Step 3.
11271 Because M > N and H' and M are relatively prime, the search is guaranteed
11272 to stop at an unused slot or find the match. */
11274 /* Create a hash table to map DWO IDs to their CU/TU entry in
11275 .debug_{info,types}.dwo in DWP_FILE.
11276 Returns NULL if there isn't one.
11277 Note: This function processes DWP files only, not DWO files. */
11279 static struct dwp_hash_table
*
11280 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11281 struct dwp_file
*dwp_file
, int is_debug_types
)
11283 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11284 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11285 const gdb_byte
*index_ptr
, *index_end
;
11286 struct dwarf2_section_info
*index
;
11287 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11288 struct dwp_hash_table
*htab
;
11290 if (is_debug_types
)
11291 index
= &dwp_file
->sections
.tu_index
;
11293 index
= &dwp_file
->sections
.cu_index
;
11295 if (index
->empty ())
11297 index
->read (objfile
);
11299 index_ptr
= index
->buffer
;
11300 index_end
= index_ptr
+ index
->size
;
11302 version
= read_4_bytes (dbfd
, index_ptr
);
11305 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11309 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11311 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11314 if (version
!= 1 && version
!= 2)
11316 error (_("Dwarf Error: unsupported DWP file version (%s)"
11317 " [in module %s]"),
11318 pulongest (version
), dwp_file
->name
);
11320 if (nr_slots
!= (nr_slots
& -nr_slots
))
11322 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11323 " is not power of 2 [in module %s]"),
11324 pulongest (nr_slots
), dwp_file
->name
);
11327 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11328 htab
->version
= version
;
11329 htab
->nr_columns
= nr_columns
;
11330 htab
->nr_units
= nr_units
;
11331 htab
->nr_slots
= nr_slots
;
11332 htab
->hash_table
= index_ptr
;
11333 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11335 /* Exit early if the table is empty. */
11336 if (nr_slots
== 0 || nr_units
== 0
11337 || (version
== 2 && nr_columns
== 0))
11339 /* All must be zero. */
11340 if (nr_slots
!= 0 || nr_units
!= 0
11341 || (version
== 2 && nr_columns
!= 0))
11343 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11344 " all zero [in modules %s]"),
11352 htab
->section_pool
.v1
.indices
=
11353 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11354 /* It's harder to decide whether the section is too small in v1.
11355 V1 is deprecated anyway so we punt. */
11359 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11360 int *ids
= htab
->section_pool
.v2
.section_ids
;
11361 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11362 /* Reverse map for error checking. */
11363 int ids_seen
[DW_SECT_MAX
+ 1];
11366 if (nr_columns
< 2)
11368 error (_("Dwarf Error: bad DWP hash table, too few columns"
11369 " in section table [in module %s]"),
11372 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11374 error (_("Dwarf Error: bad DWP hash table, too many columns"
11375 " in section table [in module %s]"),
11378 memset (ids
, 255, sizeof_ids
);
11379 memset (ids_seen
, 255, sizeof (ids_seen
));
11380 for (i
= 0; i
< nr_columns
; ++i
)
11382 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11384 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11386 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11387 " in section table [in module %s]"),
11388 id
, dwp_file
->name
);
11390 if (ids_seen
[id
] != -1)
11392 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11393 " id %d in section table [in module %s]"),
11394 id
, dwp_file
->name
);
11399 /* Must have exactly one info or types section. */
11400 if (((ids_seen
[DW_SECT_INFO
] != -1)
11401 + (ids_seen
[DW_SECT_TYPES
] != -1))
11404 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11405 " DWO info/types section [in module %s]"),
11408 /* Must have an abbrev section. */
11409 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11411 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11412 " section [in module %s]"),
11415 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11416 htab
->section_pool
.v2
.sizes
=
11417 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11418 * nr_units
* nr_columns
);
11419 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11420 * nr_units
* nr_columns
))
11423 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11424 " [in module %s]"),
11432 /* Update SECTIONS with the data from SECTP.
11434 This function is like the other "locate" section routines that are
11435 passed to bfd_map_over_sections, but in this context the sections to
11436 read comes from the DWP V1 hash table, not the full ELF section table.
11438 The result is non-zero for success, or zero if an error was found. */
11441 locate_v1_virtual_dwo_sections (asection
*sectp
,
11442 struct virtual_v1_dwo_sections
*sections
)
11444 const struct dwop_section_names
*names
= &dwop_section_names
;
11446 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11448 /* There can be only one. */
11449 if (sections
->abbrev
.s
.section
!= NULL
)
11451 sections
->abbrev
.s
.section
= sectp
;
11452 sections
->abbrev
.size
= bfd_section_size (sectp
);
11454 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11455 || section_is_p (sectp
->name
, &names
->types_dwo
))
11457 /* There can be only one. */
11458 if (sections
->info_or_types
.s
.section
!= NULL
)
11460 sections
->info_or_types
.s
.section
= sectp
;
11461 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11463 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11465 /* There can be only one. */
11466 if (sections
->line
.s
.section
!= NULL
)
11468 sections
->line
.s
.section
= sectp
;
11469 sections
->line
.size
= bfd_section_size (sectp
);
11471 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11473 /* There can be only one. */
11474 if (sections
->loc
.s
.section
!= NULL
)
11476 sections
->loc
.s
.section
= sectp
;
11477 sections
->loc
.size
= bfd_section_size (sectp
);
11479 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11481 /* There can be only one. */
11482 if (sections
->macinfo
.s
.section
!= NULL
)
11484 sections
->macinfo
.s
.section
= sectp
;
11485 sections
->macinfo
.size
= bfd_section_size (sectp
);
11487 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11489 /* There can be only one. */
11490 if (sections
->macro
.s
.section
!= NULL
)
11492 sections
->macro
.s
.section
= sectp
;
11493 sections
->macro
.size
= bfd_section_size (sectp
);
11495 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11497 /* There can be only one. */
11498 if (sections
->str_offsets
.s
.section
!= NULL
)
11500 sections
->str_offsets
.s
.section
= sectp
;
11501 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11505 /* No other kind of section is valid. */
11512 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11513 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11514 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11515 This is for DWP version 1 files. */
11517 static struct dwo_unit
*
11518 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11519 struct dwp_file
*dwp_file
,
11520 uint32_t unit_index
,
11521 const char *comp_dir
,
11522 ULONGEST signature
, int is_debug_types
)
11524 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11525 const struct dwp_hash_table
*dwp_htab
=
11526 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11527 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11528 const char *kind
= is_debug_types
? "TU" : "CU";
11529 struct dwo_file
*dwo_file
;
11530 struct dwo_unit
*dwo_unit
;
11531 struct virtual_v1_dwo_sections sections
;
11532 void **dwo_file_slot
;
11535 gdb_assert (dwp_file
->version
== 1);
11537 if (dwarf_read_debug
)
11539 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11541 pulongest (unit_index
), hex_string (signature
),
11545 /* Fetch the sections of this DWO unit.
11546 Put a limit on the number of sections we look for so that bad data
11547 doesn't cause us to loop forever. */
11549 #define MAX_NR_V1_DWO_SECTIONS \
11550 (1 /* .debug_info or .debug_types */ \
11551 + 1 /* .debug_abbrev */ \
11552 + 1 /* .debug_line */ \
11553 + 1 /* .debug_loc */ \
11554 + 1 /* .debug_str_offsets */ \
11555 + 1 /* .debug_macro or .debug_macinfo */ \
11556 + 1 /* trailing zero */)
11558 memset (§ions
, 0, sizeof (sections
));
11560 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11563 uint32_t section_nr
=
11564 read_4_bytes (dbfd
,
11565 dwp_htab
->section_pool
.v1
.indices
11566 + (unit_index
+ i
) * sizeof (uint32_t));
11568 if (section_nr
== 0)
11570 if (section_nr
>= dwp_file
->num_sections
)
11572 error (_("Dwarf Error: bad DWP hash table, section number too large"
11573 " [in module %s]"),
11577 sectp
= dwp_file
->elf_sections
[section_nr
];
11578 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11580 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11581 " [in module %s]"),
11587 || sections
.info_or_types
.empty ()
11588 || sections
.abbrev
.empty ())
11590 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11591 " [in module %s]"),
11594 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11596 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11597 " [in module %s]"),
11601 /* It's easier for the rest of the code if we fake a struct dwo_file and
11602 have dwo_unit "live" in that. At least for now.
11604 The DWP file can be made up of a random collection of CUs and TUs.
11605 However, for each CU + set of TUs that came from the same original DWO
11606 file, we can combine them back into a virtual DWO file to save space
11607 (fewer struct dwo_file objects to allocate). Remember that for really
11608 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11610 std::string virtual_dwo_name
=
11611 string_printf ("virtual-dwo/%d-%d-%d-%d",
11612 sections
.abbrev
.get_id (),
11613 sections
.line
.get_id (),
11614 sections
.loc
.get_id (),
11615 sections
.str_offsets
.get_id ());
11616 /* Can we use an existing virtual DWO file? */
11617 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11618 virtual_dwo_name
.c_str (),
11620 /* Create one if necessary. */
11621 if (*dwo_file_slot
== NULL
)
11623 if (dwarf_read_debug
)
11625 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11626 virtual_dwo_name
.c_str ());
11628 dwo_file
= new struct dwo_file
;
11629 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11630 dwo_file
->comp_dir
= comp_dir
;
11631 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11632 dwo_file
->sections
.line
= sections
.line
;
11633 dwo_file
->sections
.loc
= sections
.loc
;
11634 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11635 dwo_file
->sections
.macro
= sections
.macro
;
11636 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11637 /* The "str" section is global to the entire DWP file. */
11638 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11639 /* The info or types section is assigned below to dwo_unit,
11640 there's no need to record it in dwo_file.
11641 Also, we can't simply record type sections in dwo_file because
11642 we record a pointer into the vector in dwo_unit. As we collect more
11643 types we'll grow the vector and eventually have to reallocate space
11644 for it, invalidating all copies of pointers into the previous
11646 *dwo_file_slot
= dwo_file
;
11650 if (dwarf_read_debug
)
11652 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11653 virtual_dwo_name
.c_str ());
11655 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11658 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11659 dwo_unit
->dwo_file
= dwo_file
;
11660 dwo_unit
->signature
= signature
;
11661 dwo_unit
->section
=
11662 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11663 *dwo_unit
->section
= sections
.info_or_types
;
11664 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11669 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11670 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11671 piece within that section used by a TU/CU, return a virtual section
11672 of just that piece. */
11674 static struct dwarf2_section_info
11675 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11676 struct dwarf2_section_info
*section
,
11677 bfd_size_type offset
, bfd_size_type size
)
11679 struct dwarf2_section_info result
;
11682 gdb_assert (section
!= NULL
);
11683 gdb_assert (!section
->is_virtual
);
11685 memset (&result
, 0, sizeof (result
));
11686 result
.s
.containing_section
= section
;
11687 result
.is_virtual
= true;
11692 sectp
= section
->get_bfd_section ();
11694 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11695 bounds of the real section. This is a pretty-rare event, so just
11696 flag an error (easier) instead of a warning and trying to cope. */
11698 || offset
+ size
> bfd_section_size (sectp
))
11700 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11701 " in section %s [in module %s]"),
11702 sectp
? bfd_section_name (sectp
) : "<unknown>",
11703 objfile_name (dwarf2_per_objfile
->objfile
));
11706 result
.virtual_offset
= offset
;
11707 result
.size
= size
;
11711 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11712 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11713 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11714 This is for DWP version 2 files. */
11716 static struct dwo_unit
*
11717 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11718 struct dwp_file
*dwp_file
,
11719 uint32_t unit_index
,
11720 const char *comp_dir
,
11721 ULONGEST signature
, int is_debug_types
)
11723 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11724 const struct dwp_hash_table
*dwp_htab
=
11725 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11726 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11727 const char *kind
= is_debug_types
? "TU" : "CU";
11728 struct dwo_file
*dwo_file
;
11729 struct dwo_unit
*dwo_unit
;
11730 struct virtual_v2_dwo_sections sections
;
11731 void **dwo_file_slot
;
11734 gdb_assert (dwp_file
->version
== 2);
11736 if (dwarf_read_debug
)
11738 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11740 pulongest (unit_index
), hex_string (signature
),
11744 /* Fetch the section offsets of this DWO unit. */
11746 memset (§ions
, 0, sizeof (sections
));
11748 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11750 uint32_t offset
= read_4_bytes (dbfd
,
11751 dwp_htab
->section_pool
.v2
.offsets
11752 + (((unit_index
- 1) * dwp_htab
->nr_columns
11754 * sizeof (uint32_t)));
11755 uint32_t size
= read_4_bytes (dbfd
,
11756 dwp_htab
->section_pool
.v2
.sizes
11757 + (((unit_index
- 1) * dwp_htab
->nr_columns
11759 * sizeof (uint32_t)));
11761 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11764 case DW_SECT_TYPES
:
11765 sections
.info_or_types_offset
= offset
;
11766 sections
.info_or_types_size
= size
;
11768 case DW_SECT_ABBREV
:
11769 sections
.abbrev_offset
= offset
;
11770 sections
.abbrev_size
= size
;
11773 sections
.line_offset
= offset
;
11774 sections
.line_size
= size
;
11777 sections
.loc_offset
= offset
;
11778 sections
.loc_size
= size
;
11780 case DW_SECT_STR_OFFSETS
:
11781 sections
.str_offsets_offset
= offset
;
11782 sections
.str_offsets_size
= size
;
11784 case DW_SECT_MACINFO
:
11785 sections
.macinfo_offset
= offset
;
11786 sections
.macinfo_size
= size
;
11788 case DW_SECT_MACRO
:
11789 sections
.macro_offset
= offset
;
11790 sections
.macro_size
= size
;
11795 /* It's easier for the rest of the code if we fake a struct dwo_file and
11796 have dwo_unit "live" in that. At least for now.
11798 The DWP file can be made up of a random collection of CUs and TUs.
11799 However, for each CU + set of TUs that came from the same original DWO
11800 file, we can combine them back into a virtual DWO file to save space
11801 (fewer struct dwo_file objects to allocate). Remember that for really
11802 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11804 std::string virtual_dwo_name
=
11805 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11806 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11807 (long) (sections
.line_size
? sections
.line_offset
: 0),
11808 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11809 (long) (sections
.str_offsets_size
11810 ? sections
.str_offsets_offset
: 0));
11811 /* Can we use an existing virtual DWO file? */
11812 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11813 virtual_dwo_name
.c_str (),
11815 /* Create one if necessary. */
11816 if (*dwo_file_slot
== NULL
)
11818 if (dwarf_read_debug
)
11820 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11821 virtual_dwo_name
.c_str ());
11823 dwo_file
= new struct dwo_file
;
11824 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11825 dwo_file
->comp_dir
= comp_dir
;
11826 dwo_file
->sections
.abbrev
=
11827 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11828 sections
.abbrev_offset
, sections
.abbrev_size
);
11829 dwo_file
->sections
.line
=
11830 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11831 sections
.line_offset
, sections
.line_size
);
11832 dwo_file
->sections
.loc
=
11833 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11834 sections
.loc_offset
, sections
.loc_size
);
11835 dwo_file
->sections
.macinfo
=
11836 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11837 sections
.macinfo_offset
, sections
.macinfo_size
);
11838 dwo_file
->sections
.macro
=
11839 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11840 sections
.macro_offset
, sections
.macro_size
);
11841 dwo_file
->sections
.str_offsets
=
11842 create_dwp_v2_section (dwarf2_per_objfile
,
11843 &dwp_file
->sections
.str_offsets
,
11844 sections
.str_offsets_offset
,
11845 sections
.str_offsets_size
);
11846 /* The "str" section is global to the entire DWP file. */
11847 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11848 /* The info or types section is assigned below to dwo_unit,
11849 there's no need to record it in dwo_file.
11850 Also, we can't simply record type sections in dwo_file because
11851 we record a pointer into the vector in dwo_unit. As we collect more
11852 types we'll grow the vector and eventually have to reallocate space
11853 for it, invalidating all copies of pointers into the previous
11855 *dwo_file_slot
= dwo_file
;
11859 if (dwarf_read_debug
)
11861 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11862 virtual_dwo_name
.c_str ());
11864 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11867 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11868 dwo_unit
->dwo_file
= dwo_file
;
11869 dwo_unit
->signature
= signature
;
11870 dwo_unit
->section
=
11871 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11872 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11874 ? &dwp_file
->sections
.types
11875 : &dwp_file
->sections
.info
,
11876 sections
.info_or_types_offset
,
11877 sections
.info_or_types_size
);
11878 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11883 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11884 Returns NULL if the signature isn't found. */
11886 static struct dwo_unit
*
11887 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11888 struct dwp_file
*dwp_file
, const char *comp_dir
,
11889 ULONGEST signature
, int is_debug_types
)
11891 const struct dwp_hash_table
*dwp_htab
=
11892 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11893 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11894 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11895 uint32_t hash
= signature
& mask
;
11896 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11899 struct dwo_unit find_dwo_cu
;
11901 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11902 find_dwo_cu
.signature
= signature
;
11903 slot
= htab_find_slot (is_debug_types
11904 ? dwp_file
->loaded_tus
.get ()
11905 : dwp_file
->loaded_cus
.get (),
11906 &find_dwo_cu
, INSERT
);
11909 return (struct dwo_unit
*) *slot
;
11911 /* Use a for loop so that we don't loop forever on bad debug info. */
11912 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11914 ULONGEST signature_in_table
;
11916 signature_in_table
=
11917 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11918 if (signature_in_table
== signature
)
11920 uint32_t unit_index
=
11921 read_4_bytes (dbfd
,
11922 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11924 if (dwp_file
->version
== 1)
11926 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11927 dwp_file
, unit_index
,
11928 comp_dir
, signature
,
11933 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11934 dwp_file
, unit_index
,
11935 comp_dir
, signature
,
11938 return (struct dwo_unit
*) *slot
;
11940 if (signature_in_table
== 0)
11942 hash
= (hash
+ hash2
) & mask
;
11945 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11946 " [in module %s]"),
11950 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11951 Open the file specified by FILE_NAME and hand it off to BFD for
11952 preliminary analysis. Return a newly initialized bfd *, which
11953 includes a canonicalized copy of FILE_NAME.
11954 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11955 SEARCH_CWD is true if the current directory is to be searched.
11956 It will be searched before debug-file-directory.
11957 If successful, the file is added to the bfd include table of the
11958 objfile's bfd (see gdb_bfd_record_inclusion).
11959 If unable to find/open the file, return NULL.
11960 NOTE: This function is derived from symfile_bfd_open. */
11962 static gdb_bfd_ref_ptr
11963 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11964 const char *file_name
, int is_dwp
, int search_cwd
)
11967 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11968 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11969 to debug_file_directory. */
11970 const char *search_path
;
11971 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11973 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11976 if (*debug_file_directory
!= '\0')
11978 search_path_holder
.reset (concat (".", dirname_separator_string
,
11979 debug_file_directory
,
11981 search_path
= search_path_holder
.get ();
11987 search_path
= debug_file_directory
;
11989 openp_flags flags
= OPF_RETURN_REALPATH
;
11991 flags
|= OPF_SEARCH_IN_PATH
;
11993 gdb::unique_xmalloc_ptr
<char> absolute_name
;
11994 desc
= openp (search_path
, flags
, file_name
,
11995 O_RDONLY
| O_BINARY
, &absolute_name
);
11999 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12001 if (sym_bfd
== NULL
)
12003 bfd_set_cacheable (sym_bfd
.get (), 1);
12005 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12008 /* Success. Record the bfd as having been included by the objfile's bfd.
12009 This is important because things like demangled_names_hash lives in the
12010 objfile's per_bfd space and may have references to things like symbol
12011 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12012 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12017 /* Try to open DWO file FILE_NAME.
12018 COMP_DIR is the DW_AT_comp_dir attribute.
12019 The result is the bfd handle of the file.
12020 If there is a problem finding or opening the file, return NULL.
12021 Upon success, the canonicalized path of the file is stored in the bfd,
12022 same as symfile_bfd_open. */
12024 static gdb_bfd_ref_ptr
12025 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12026 const char *file_name
, const char *comp_dir
)
12028 if (IS_ABSOLUTE_PATH (file_name
))
12029 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12030 0 /*is_dwp*/, 0 /*search_cwd*/);
12032 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12034 if (comp_dir
!= NULL
)
12036 gdb::unique_xmalloc_ptr
<char> path_to_try
12037 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12039 /* NOTE: If comp_dir is a relative path, this will also try the
12040 search path, which seems useful. */
12041 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12042 path_to_try
.get (),
12044 1 /*search_cwd*/));
12049 /* That didn't work, try debug-file-directory, which, despite its name,
12050 is a list of paths. */
12052 if (*debug_file_directory
== '\0')
12055 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12056 0 /*is_dwp*/, 1 /*search_cwd*/);
12059 /* This function is mapped across the sections and remembers the offset and
12060 size of each of the DWO debugging sections we are interested in. */
12063 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12065 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12066 const struct dwop_section_names
*names
= &dwop_section_names
;
12068 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12070 dwo_sections
->abbrev
.s
.section
= sectp
;
12071 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12073 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12075 dwo_sections
->info
.s
.section
= sectp
;
12076 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12078 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12080 dwo_sections
->line
.s
.section
= sectp
;
12081 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12083 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12085 dwo_sections
->loc
.s
.section
= sectp
;
12086 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12088 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12090 dwo_sections
->macinfo
.s
.section
= sectp
;
12091 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12093 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12095 dwo_sections
->macro
.s
.section
= sectp
;
12096 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12098 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12100 dwo_sections
->str
.s
.section
= sectp
;
12101 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12103 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12105 dwo_sections
->str_offsets
.s
.section
= sectp
;
12106 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12108 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12110 struct dwarf2_section_info type_section
;
12112 memset (&type_section
, 0, sizeof (type_section
));
12113 type_section
.s
.section
= sectp
;
12114 type_section
.size
= bfd_section_size (sectp
);
12115 dwo_sections
->types
.push_back (type_section
);
12119 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12120 by PER_CU. This is for the non-DWP case.
12121 The result is NULL if DWO_NAME can't be found. */
12123 static struct dwo_file
*
12124 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12125 const char *dwo_name
, const char *comp_dir
)
12127 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12129 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12132 if (dwarf_read_debug
)
12133 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12137 dwo_file_up
dwo_file (new struct dwo_file
);
12138 dwo_file
->dwo_name
= dwo_name
;
12139 dwo_file
->comp_dir
= comp_dir
;
12140 dwo_file
->dbfd
= std::move (dbfd
);
12142 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12143 &dwo_file
->sections
);
12145 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12146 dwo_file
->sections
.info
, dwo_file
->cus
);
12148 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12149 dwo_file
->sections
.types
, dwo_file
->tus
);
12151 if (dwarf_read_debug
)
12152 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12154 return dwo_file
.release ();
12157 /* This function is mapped across the sections and remembers the offset and
12158 size of each of the DWP debugging sections common to version 1 and 2 that
12159 we are interested in. */
12162 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12163 void *dwp_file_ptr
)
12165 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12166 const struct dwop_section_names
*names
= &dwop_section_names
;
12167 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12169 /* Record the ELF section number for later lookup: this is what the
12170 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12171 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12172 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12174 /* Look for specific sections that we need. */
12175 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12177 dwp_file
->sections
.str
.s
.section
= sectp
;
12178 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12180 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12182 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12183 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12185 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12187 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12188 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12192 /* This function is mapped across the sections and remembers the offset and
12193 size of each of the DWP version 2 debugging sections that we are interested
12194 in. This is split into a separate function because we don't know if we
12195 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12198 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12200 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12201 const struct dwop_section_names
*names
= &dwop_section_names
;
12202 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12204 /* Record the ELF section number for later lookup: this is what the
12205 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12206 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12207 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12209 /* Look for specific sections that we need. */
12210 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12212 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12213 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12215 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12217 dwp_file
->sections
.info
.s
.section
= sectp
;
12218 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12220 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12222 dwp_file
->sections
.line
.s
.section
= sectp
;
12223 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12225 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12227 dwp_file
->sections
.loc
.s
.section
= sectp
;
12228 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12230 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12232 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12233 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12235 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12237 dwp_file
->sections
.macro
.s
.section
= sectp
;
12238 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12240 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12242 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12243 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12245 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12247 dwp_file
->sections
.types
.s
.section
= sectp
;
12248 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12252 /* Hash function for dwp_file loaded CUs/TUs. */
12255 hash_dwp_loaded_cutus (const void *item
)
12257 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12259 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12260 return dwo_unit
->signature
;
12263 /* Equality function for dwp_file loaded CUs/TUs. */
12266 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12268 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12269 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12271 return dua
->signature
== dub
->signature
;
12274 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12277 allocate_dwp_loaded_cutus_table ()
12279 return htab_up (htab_create_alloc (3,
12280 hash_dwp_loaded_cutus
,
12281 eq_dwp_loaded_cutus
,
12282 NULL
, xcalloc
, xfree
));
12285 /* Try to open DWP file FILE_NAME.
12286 The result is the bfd handle of the file.
12287 If there is a problem finding or opening the file, return NULL.
12288 Upon success, the canonicalized path of the file is stored in the bfd,
12289 same as symfile_bfd_open. */
12291 static gdb_bfd_ref_ptr
12292 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12293 const char *file_name
)
12295 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12297 1 /*search_cwd*/));
12301 /* Work around upstream bug 15652.
12302 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12303 [Whether that's a "bug" is debatable, but it is getting in our way.]
12304 We have no real idea where the dwp file is, because gdb's realpath-ing
12305 of the executable's path may have discarded the needed info.
12306 [IWBN if the dwp file name was recorded in the executable, akin to
12307 .gnu_debuglink, but that doesn't exist yet.]
12308 Strip the directory from FILE_NAME and search again. */
12309 if (*debug_file_directory
!= '\0')
12311 /* Don't implicitly search the current directory here.
12312 If the user wants to search "." to handle this case,
12313 it must be added to debug-file-directory. */
12314 return try_open_dwop_file (dwarf2_per_objfile
,
12315 lbasename (file_name
), 1 /*is_dwp*/,
12322 /* Initialize the use of the DWP file for the current objfile.
12323 By convention the name of the DWP file is ${objfile}.dwp.
12324 The result is NULL if it can't be found. */
12326 static std::unique_ptr
<struct dwp_file
>
12327 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12329 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12331 /* Try to find first .dwp for the binary file before any symbolic links
12334 /* If the objfile is a debug file, find the name of the real binary
12335 file and get the name of dwp file from there. */
12336 std::string dwp_name
;
12337 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12339 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12340 const char *backlink_basename
= lbasename (backlink
->original_name
);
12342 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12345 dwp_name
= objfile
->original_name
;
12347 dwp_name
+= ".dwp";
12349 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12351 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12353 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12354 dwp_name
= objfile_name (objfile
);
12355 dwp_name
+= ".dwp";
12356 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12361 if (dwarf_read_debug
)
12362 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12363 return std::unique_ptr
<dwp_file
> ();
12366 const char *name
= bfd_get_filename (dbfd
.get ());
12367 std::unique_ptr
<struct dwp_file
> dwp_file
12368 (new struct dwp_file (name
, std::move (dbfd
)));
12370 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12371 dwp_file
->elf_sections
=
12372 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12373 dwp_file
->num_sections
, asection
*);
12375 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12376 dwarf2_locate_common_dwp_sections
,
12379 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12382 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12385 /* The DWP file version is stored in the hash table. Oh well. */
12386 if (dwp_file
->cus
&& dwp_file
->tus
12387 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12389 /* Technically speaking, we should try to limp along, but this is
12390 pretty bizarre. We use pulongest here because that's the established
12391 portability solution (e.g, we cannot use %u for uint32_t). */
12392 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12393 " TU version %s [in DWP file %s]"),
12394 pulongest (dwp_file
->cus
->version
),
12395 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12399 dwp_file
->version
= dwp_file
->cus
->version
;
12400 else if (dwp_file
->tus
)
12401 dwp_file
->version
= dwp_file
->tus
->version
;
12403 dwp_file
->version
= 2;
12405 if (dwp_file
->version
== 2)
12406 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12407 dwarf2_locate_v2_dwp_sections
,
12410 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12411 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12413 if (dwarf_read_debug
)
12415 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12416 fprintf_unfiltered (gdb_stdlog
,
12417 " %s CUs, %s TUs\n",
12418 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12419 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12425 /* Wrapper around open_and_init_dwp_file, only open it once. */
12427 static struct dwp_file
*
12428 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12430 if (! dwarf2_per_objfile
->dwp_checked
)
12432 dwarf2_per_objfile
->dwp_file
12433 = open_and_init_dwp_file (dwarf2_per_objfile
);
12434 dwarf2_per_objfile
->dwp_checked
= 1;
12436 return dwarf2_per_objfile
->dwp_file
.get ();
12439 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12440 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12441 or in the DWP file for the objfile, referenced by THIS_UNIT.
12442 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12443 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12445 This is called, for example, when wanting to read a variable with a
12446 complex location. Therefore we don't want to do file i/o for every call.
12447 Therefore we don't want to look for a DWO file on every call.
12448 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12449 then we check if we've already seen DWO_NAME, and only THEN do we check
12452 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12453 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12455 static struct dwo_unit
*
12456 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12457 const char *dwo_name
, const char *comp_dir
,
12458 ULONGEST signature
, int is_debug_types
)
12460 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12461 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12462 const char *kind
= is_debug_types
? "TU" : "CU";
12463 void **dwo_file_slot
;
12464 struct dwo_file
*dwo_file
;
12465 struct dwp_file
*dwp_file
;
12467 /* First see if there's a DWP file.
12468 If we have a DWP file but didn't find the DWO inside it, don't
12469 look for the original DWO file. It makes gdb behave differently
12470 depending on whether one is debugging in the build tree. */
12472 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12473 if (dwp_file
!= NULL
)
12475 const struct dwp_hash_table
*dwp_htab
=
12476 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12478 if (dwp_htab
!= NULL
)
12480 struct dwo_unit
*dwo_cutu
=
12481 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12482 signature
, is_debug_types
);
12484 if (dwo_cutu
!= NULL
)
12486 if (dwarf_read_debug
)
12488 fprintf_unfiltered (gdb_stdlog
,
12489 "Virtual DWO %s %s found: @%s\n",
12490 kind
, hex_string (signature
),
12491 host_address_to_string (dwo_cutu
));
12499 /* No DWP file, look for the DWO file. */
12501 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12502 dwo_name
, comp_dir
);
12503 if (*dwo_file_slot
== NULL
)
12505 /* Read in the file and build a table of the CUs/TUs it contains. */
12506 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12508 /* NOTE: This will be NULL if unable to open the file. */
12509 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12511 if (dwo_file
!= NULL
)
12513 struct dwo_unit
*dwo_cutu
= NULL
;
12515 if (is_debug_types
&& dwo_file
->tus
)
12517 struct dwo_unit find_dwo_cutu
;
12519 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12520 find_dwo_cutu
.signature
= signature
;
12522 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12525 else if (!is_debug_types
&& dwo_file
->cus
)
12527 struct dwo_unit find_dwo_cutu
;
12529 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12530 find_dwo_cutu
.signature
= signature
;
12531 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12535 if (dwo_cutu
!= NULL
)
12537 if (dwarf_read_debug
)
12539 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12540 kind
, dwo_name
, hex_string (signature
),
12541 host_address_to_string (dwo_cutu
));
12548 /* We didn't find it. This could mean a dwo_id mismatch, or
12549 someone deleted the DWO/DWP file, or the search path isn't set up
12550 correctly to find the file. */
12552 if (dwarf_read_debug
)
12554 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12555 kind
, dwo_name
, hex_string (signature
));
12558 /* This is a warning and not a complaint because it can be caused by
12559 pilot error (e.g., user accidentally deleting the DWO). */
12561 /* Print the name of the DWP file if we looked there, helps the user
12562 better diagnose the problem. */
12563 std::string dwp_text
;
12565 if (dwp_file
!= NULL
)
12566 dwp_text
= string_printf (" [in DWP file %s]",
12567 lbasename (dwp_file
->name
));
12569 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12570 " [in module %s]"),
12571 kind
, dwo_name
, hex_string (signature
),
12573 this_unit
->is_debug_types
? "TU" : "CU",
12574 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12579 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12580 See lookup_dwo_cutu_unit for details. */
12582 static struct dwo_unit
*
12583 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12584 const char *dwo_name
, const char *comp_dir
,
12585 ULONGEST signature
)
12587 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12590 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12591 See lookup_dwo_cutu_unit for details. */
12593 static struct dwo_unit
*
12594 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12595 const char *dwo_name
, const char *comp_dir
)
12597 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12600 /* Traversal function for queue_and_load_all_dwo_tus. */
12603 queue_and_load_dwo_tu (void **slot
, void *info
)
12605 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12606 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12607 ULONGEST signature
= dwo_unit
->signature
;
12608 struct signatured_type
*sig_type
=
12609 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12611 if (sig_type
!= NULL
)
12613 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12615 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12616 a real dependency of PER_CU on SIG_TYPE. That is detected later
12617 while processing PER_CU. */
12618 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12619 load_full_type_unit (sig_cu
);
12620 per_cu
->imported_symtabs_push (sig_cu
);
12626 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12627 The DWO may have the only definition of the type, though it may not be
12628 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12629 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12632 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12634 struct dwo_unit
*dwo_unit
;
12635 struct dwo_file
*dwo_file
;
12637 gdb_assert (!per_cu
->is_debug_types
);
12638 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12639 gdb_assert (per_cu
->cu
!= NULL
);
12641 dwo_unit
= per_cu
->cu
->dwo_unit
;
12642 gdb_assert (dwo_unit
!= NULL
);
12644 dwo_file
= dwo_unit
->dwo_file
;
12645 if (dwo_file
->tus
!= NULL
)
12646 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12650 /* Read in various DIEs. */
12652 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12653 Inherit only the children of the DW_AT_abstract_origin DIE not being
12654 already referenced by DW_AT_abstract_origin from the children of the
12658 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12660 struct die_info
*child_die
;
12661 sect_offset
*offsetp
;
12662 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12663 struct die_info
*origin_die
;
12664 /* Iterator of the ORIGIN_DIE children. */
12665 struct die_info
*origin_child_die
;
12666 struct attribute
*attr
;
12667 struct dwarf2_cu
*origin_cu
;
12668 struct pending
**origin_previous_list_in_scope
;
12670 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12674 /* Note that following die references may follow to a die in a
12678 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12680 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12682 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12683 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12685 if (die
->tag
!= origin_die
->tag
12686 && !(die
->tag
== DW_TAG_inlined_subroutine
12687 && origin_die
->tag
== DW_TAG_subprogram
))
12688 complaint (_("DIE %s and its abstract origin %s have different tags"),
12689 sect_offset_str (die
->sect_off
),
12690 sect_offset_str (origin_die
->sect_off
));
12692 std::vector
<sect_offset
> offsets
;
12694 for (child_die
= die
->child
;
12695 child_die
&& child_die
->tag
;
12696 child_die
= sibling_die (child_die
))
12698 struct die_info
*child_origin_die
;
12699 struct dwarf2_cu
*child_origin_cu
;
12701 /* We are trying to process concrete instance entries:
12702 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12703 it's not relevant to our analysis here. i.e. detecting DIEs that are
12704 present in the abstract instance but not referenced in the concrete
12706 if (child_die
->tag
== DW_TAG_call_site
12707 || child_die
->tag
== DW_TAG_GNU_call_site
)
12710 /* For each CHILD_DIE, find the corresponding child of
12711 ORIGIN_DIE. If there is more than one layer of
12712 DW_AT_abstract_origin, follow them all; there shouldn't be,
12713 but GCC versions at least through 4.4 generate this (GCC PR
12715 child_origin_die
= child_die
;
12716 child_origin_cu
= cu
;
12719 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12723 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12727 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12728 counterpart may exist. */
12729 if (child_origin_die
!= child_die
)
12731 if (child_die
->tag
!= child_origin_die
->tag
12732 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12733 && child_origin_die
->tag
== DW_TAG_subprogram
))
12734 complaint (_("Child DIE %s and its abstract origin %s have "
12736 sect_offset_str (child_die
->sect_off
),
12737 sect_offset_str (child_origin_die
->sect_off
));
12738 if (child_origin_die
->parent
!= origin_die
)
12739 complaint (_("Child DIE %s and its abstract origin %s have "
12740 "different parents"),
12741 sect_offset_str (child_die
->sect_off
),
12742 sect_offset_str (child_origin_die
->sect_off
));
12744 offsets
.push_back (child_origin_die
->sect_off
);
12747 std::sort (offsets
.begin (), offsets
.end ());
12748 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12749 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12750 if (offsetp
[-1] == *offsetp
)
12751 complaint (_("Multiple children of DIE %s refer "
12752 "to DIE %s as their abstract origin"),
12753 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12755 offsetp
= offsets
.data ();
12756 origin_child_die
= origin_die
->child
;
12757 while (origin_child_die
&& origin_child_die
->tag
)
12759 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12760 while (offsetp
< offsets_end
12761 && *offsetp
< origin_child_die
->sect_off
)
12763 if (offsetp
>= offsets_end
12764 || *offsetp
> origin_child_die
->sect_off
)
12766 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12767 Check whether we're already processing ORIGIN_CHILD_DIE.
12768 This can happen with mutually referenced abstract_origins.
12770 if (!origin_child_die
->in_process
)
12771 process_die (origin_child_die
, origin_cu
);
12773 origin_child_die
= sibling_die (origin_child_die
);
12775 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12777 if (cu
!= origin_cu
)
12778 compute_delayed_physnames (origin_cu
);
12782 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12784 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12785 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12786 struct context_stack
*newobj
;
12789 struct die_info
*child_die
;
12790 struct attribute
*attr
, *call_line
, *call_file
;
12792 CORE_ADDR baseaddr
;
12793 struct block
*block
;
12794 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12795 std::vector
<struct symbol
*> template_args
;
12796 struct template_symbol
*templ_func
= NULL
;
12800 /* If we do not have call site information, we can't show the
12801 caller of this inlined function. That's too confusing, so
12802 only use the scope for local variables. */
12803 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12804 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12805 if (call_line
== NULL
|| call_file
== NULL
)
12807 read_lexical_block_scope (die
, cu
);
12812 baseaddr
= objfile
->text_section_offset ();
12814 name
= dwarf2_name (die
, cu
);
12816 /* Ignore functions with missing or empty names. These are actually
12817 illegal according to the DWARF standard. */
12820 complaint (_("missing name for subprogram DIE at %s"),
12821 sect_offset_str (die
->sect_off
));
12825 /* Ignore functions with missing or invalid low and high pc attributes. */
12826 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12827 <= PC_BOUNDS_INVALID
)
12829 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12830 if (!attr
|| !DW_UNSND (attr
))
12831 complaint (_("cannot get low and high bounds "
12832 "for subprogram DIE at %s"),
12833 sect_offset_str (die
->sect_off
));
12837 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12838 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12840 /* If we have any template arguments, then we must allocate a
12841 different sort of symbol. */
12842 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12844 if (child_die
->tag
== DW_TAG_template_type_param
12845 || child_die
->tag
== DW_TAG_template_value_param
)
12847 templ_func
= allocate_template_symbol (objfile
);
12848 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12853 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12854 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12855 (struct symbol
*) templ_func
);
12857 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12858 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12861 /* If there is a location expression for DW_AT_frame_base, record
12863 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12864 if (attr
!= nullptr)
12865 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12867 /* If there is a location for the static link, record it. */
12868 newobj
->static_link
= NULL
;
12869 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12870 if (attr
!= nullptr)
12872 newobj
->static_link
12873 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12874 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12875 cu
->per_cu
->addr_type ());
12878 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12880 if (die
->child
!= NULL
)
12882 child_die
= die
->child
;
12883 while (child_die
&& child_die
->tag
)
12885 if (child_die
->tag
== DW_TAG_template_type_param
12886 || child_die
->tag
== DW_TAG_template_value_param
)
12888 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12891 template_args
.push_back (arg
);
12894 process_die (child_die
, cu
);
12895 child_die
= sibling_die (child_die
);
12899 inherit_abstract_dies (die
, cu
);
12901 /* If we have a DW_AT_specification, we might need to import using
12902 directives from the context of the specification DIE. See the
12903 comment in determine_prefix. */
12904 if (cu
->language
== language_cplus
12905 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12907 struct dwarf2_cu
*spec_cu
= cu
;
12908 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12912 child_die
= spec_die
->child
;
12913 while (child_die
&& child_die
->tag
)
12915 if (child_die
->tag
== DW_TAG_imported_module
)
12916 process_die (child_die
, spec_cu
);
12917 child_die
= sibling_die (child_die
);
12920 /* In some cases, GCC generates specification DIEs that
12921 themselves contain DW_AT_specification attributes. */
12922 spec_die
= die_specification (spec_die
, &spec_cu
);
12926 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12927 /* Make a block for the local symbols within. */
12928 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12929 cstk
.static_link
, lowpc
, highpc
);
12931 /* For C++, set the block's scope. */
12932 if ((cu
->language
== language_cplus
12933 || cu
->language
== language_fortran
12934 || cu
->language
== language_d
12935 || cu
->language
== language_rust
)
12936 && cu
->processing_has_namespace_info
)
12937 block_set_scope (block
, determine_prefix (die
, cu
),
12938 &objfile
->objfile_obstack
);
12940 /* If we have address ranges, record them. */
12941 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12943 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12945 /* Attach template arguments to function. */
12946 if (!template_args
.empty ())
12948 gdb_assert (templ_func
!= NULL
);
12950 templ_func
->n_template_arguments
= template_args
.size ();
12951 templ_func
->template_arguments
12952 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12953 templ_func
->n_template_arguments
);
12954 memcpy (templ_func
->template_arguments
,
12955 template_args
.data (),
12956 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12958 /* Make sure that the symtab is set on the new symbols. Even
12959 though they don't appear in this symtab directly, other parts
12960 of gdb assume that symbols do, and this is reasonably
12962 for (symbol
*sym
: template_args
)
12963 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12966 /* In C++, we can have functions nested inside functions (e.g., when
12967 a function declares a class that has methods). This means that
12968 when we finish processing a function scope, we may need to go
12969 back to building a containing block's symbol lists. */
12970 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12971 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12973 /* If we've finished processing a top-level function, subsequent
12974 symbols go in the file symbol list. */
12975 if (cu
->get_builder ()->outermost_context_p ())
12976 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12979 /* Process all the DIES contained within a lexical block scope. Start
12980 a new scope, process the dies, and then close the scope. */
12983 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12985 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12986 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12987 CORE_ADDR lowpc
, highpc
;
12988 struct die_info
*child_die
;
12989 CORE_ADDR baseaddr
;
12991 baseaddr
= objfile
->text_section_offset ();
12993 /* Ignore blocks with missing or invalid low and high pc attributes. */
12994 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12995 as multiple lexical blocks? Handling children in a sane way would
12996 be nasty. Might be easier to properly extend generic blocks to
12997 describe ranges. */
12998 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13000 case PC_BOUNDS_NOT_PRESENT
:
13001 /* DW_TAG_lexical_block has no attributes, process its children as if
13002 there was no wrapping by that DW_TAG_lexical_block.
13003 GCC does no longer produces such DWARF since GCC r224161. */
13004 for (child_die
= die
->child
;
13005 child_die
!= NULL
&& child_die
->tag
;
13006 child_die
= sibling_die (child_die
))
13007 process_die (child_die
, cu
);
13009 case PC_BOUNDS_INVALID
:
13012 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13013 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13015 cu
->get_builder ()->push_context (0, lowpc
);
13016 if (die
->child
!= NULL
)
13018 child_die
= die
->child
;
13019 while (child_die
&& child_die
->tag
)
13021 process_die (child_die
, cu
);
13022 child_die
= sibling_die (child_die
);
13025 inherit_abstract_dies (die
, cu
);
13026 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13028 if (*cu
->get_builder ()->get_local_symbols () != NULL
13029 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13031 struct block
*block
13032 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13033 cstk
.start_addr
, highpc
);
13035 /* Note that recording ranges after traversing children, as we
13036 do here, means that recording a parent's ranges entails
13037 walking across all its children's ranges as they appear in
13038 the address map, which is quadratic behavior.
13040 It would be nicer to record the parent's ranges before
13041 traversing its children, simply overriding whatever you find
13042 there. But since we don't even decide whether to create a
13043 block until after we've traversed its children, that's hard
13045 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13047 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13048 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13051 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13054 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13056 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13057 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13058 CORE_ADDR pc
, baseaddr
;
13059 struct attribute
*attr
;
13060 struct call_site
*call_site
, call_site_local
;
13063 struct die_info
*child_die
;
13065 baseaddr
= objfile
->text_section_offset ();
13067 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13070 /* This was a pre-DWARF-5 GNU extension alias
13071 for DW_AT_call_return_pc. */
13072 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13076 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13077 "DIE %s [in module %s]"),
13078 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13081 pc
= attr
->value_as_address () + baseaddr
;
13082 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13084 if (cu
->call_site_htab
== NULL
)
13085 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13086 NULL
, &objfile
->objfile_obstack
,
13087 hashtab_obstack_allocate
, NULL
);
13088 call_site_local
.pc
= pc
;
13089 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13092 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13093 "DIE %s [in module %s]"),
13094 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13095 objfile_name (objfile
));
13099 /* Count parameters at the caller. */
13102 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13103 child_die
= sibling_die (child_die
))
13105 if (child_die
->tag
!= DW_TAG_call_site_parameter
13106 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13108 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13109 "DW_TAG_call_site child DIE %s [in module %s]"),
13110 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13111 objfile_name (objfile
));
13119 = ((struct call_site
*)
13120 obstack_alloc (&objfile
->objfile_obstack
,
13121 sizeof (*call_site
)
13122 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13124 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13125 call_site
->pc
= pc
;
13127 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13128 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13130 struct die_info
*func_die
;
13132 /* Skip also over DW_TAG_inlined_subroutine. */
13133 for (func_die
= die
->parent
;
13134 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13135 && func_die
->tag
!= DW_TAG_subroutine_type
;
13136 func_die
= func_die
->parent
);
13138 /* DW_AT_call_all_calls is a superset
13139 of DW_AT_call_all_tail_calls. */
13141 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13142 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13143 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13144 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13146 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13147 not complete. But keep CALL_SITE for look ups via call_site_htab,
13148 both the initial caller containing the real return address PC and
13149 the final callee containing the current PC of a chain of tail
13150 calls do not need to have the tail call list complete. But any
13151 function candidate for a virtual tail call frame searched via
13152 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13153 determined unambiguously. */
13157 struct type
*func_type
= NULL
;
13160 func_type
= get_die_type (func_die
, cu
);
13161 if (func_type
!= NULL
)
13163 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13165 /* Enlist this call site to the function. */
13166 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13167 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13170 complaint (_("Cannot find function owning DW_TAG_call_site "
13171 "DIE %s [in module %s]"),
13172 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13176 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13178 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13180 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13183 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13184 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13186 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13187 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13188 /* Keep NULL DWARF_BLOCK. */;
13189 else if (attr
->form_is_block ())
13191 struct dwarf2_locexpr_baton
*dlbaton
;
13193 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13194 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13195 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13196 dlbaton
->per_cu
= cu
->per_cu
;
13198 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13200 else if (attr
->form_is_ref ())
13202 struct dwarf2_cu
*target_cu
= cu
;
13203 struct die_info
*target_die
;
13205 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13206 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13207 if (die_is_declaration (target_die
, target_cu
))
13209 const char *target_physname
;
13211 /* Prefer the mangled name; otherwise compute the demangled one. */
13212 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13213 if (target_physname
== NULL
)
13214 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13215 if (target_physname
== NULL
)
13216 complaint (_("DW_AT_call_target target DIE has invalid "
13217 "physname, for referencing DIE %s [in module %s]"),
13218 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13220 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13226 /* DW_AT_entry_pc should be preferred. */
13227 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13228 <= PC_BOUNDS_INVALID
)
13229 complaint (_("DW_AT_call_target target DIE has invalid "
13230 "low pc, for referencing DIE %s [in module %s]"),
13231 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13234 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13235 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13240 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13241 "block nor reference, for DIE %s [in module %s]"),
13242 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13244 call_site
->per_cu
= cu
->per_cu
;
13246 for (child_die
= die
->child
;
13247 child_die
&& child_die
->tag
;
13248 child_die
= sibling_die (child_die
))
13250 struct call_site_parameter
*parameter
;
13251 struct attribute
*loc
, *origin
;
13253 if (child_die
->tag
!= DW_TAG_call_site_parameter
13254 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13256 /* Already printed the complaint above. */
13260 gdb_assert (call_site
->parameter_count
< nparams
);
13261 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13263 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13264 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13265 register is contained in DW_AT_call_value. */
13267 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13268 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13269 if (origin
== NULL
)
13271 /* This was a pre-DWARF-5 GNU extension alias
13272 for DW_AT_call_parameter. */
13273 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13275 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13277 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13279 sect_offset sect_off
13280 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13281 if (!cu
->header
.offset_in_cu_p (sect_off
))
13283 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13284 binding can be done only inside one CU. Such referenced DIE
13285 therefore cannot be even moved to DW_TAG_partial_unit. */
13286 complaint (_("DW_AT_call_parameter offset is not in CU for "
13287 "DW_TAG_call_site child DIE %s [in module %s]"),
13288 sect_offset_str (child_die
->sect_off
),
13289 objfile_name (objfile
));
13292 parameter
->u
.param_cu_off
13293 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13295 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13297 complaint (_("No DW_FORM_block* DW_AT_location for "
13298 "DW_TAG_call_site child DIE %s [in module %s]"),
13299 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13304 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13305 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13306 if (parameter
->u
.dwarf_reg
!= -1)
13307 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13308 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13309 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13310 ¶meter
->u
.fb_offset
))
13311 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13314 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13315 "for DW_FORM_block* DW_AT_location is supported for "
13316 "DW_TAG_call_site child DIE %s "
13318 sect_offset_str (child_die
->sect_off
),
13319 objfile_name (objfile
));
13324 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13326 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13327 if (attr
== NULL
|| !attr
->form_is_block ())
13329 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13330 "DW_TAG_call_site child DIE %s [in module %s]"),
13331 sect_offset_str (child_die
->sect_off
),
13332 objfile_name (objfile
));
13335 parameter
->value
= DW_BLOCK (attr
)->data
;
13336 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13338 /* Parameters are not pre-cleared by memset above. */
13339 parameter
->data_value
= NULL
;
13340 parameter
->data_value_size
= 0;
13341 call_site
->parameter_count
++;
13343 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13345 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13346 if (attr
!= nullptr)
13348 if (!attr
->form_is_block ())
13349 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13350 "DW_TAG_call_site child DIE %s [in module %s]"),
13351 sect_offset_str (child_die
->sect_off
),
13352 objfile_name (objfile
));
13355 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13356 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13362 /* Helper function for read_variable. If DIE represents a virtual
13363 table, then return the type of the concrete object that is
13364 associated with the virtual table. Otherwise, return NULL. */
13366 static struct type
*
13367 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13369 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13373 /* Find the type DIE. */
13374 struct die_info
*type_die
= NULL
;
13375 struct dwarf2_cu
*type_cu
= cu
;
13377 if (attr
->form_is_ref ())
13378 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13379 if (type_die
== NULL
)
13382 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13384 return die_containing_type (type_die
, type_cu
);
13387 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13390 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13392 struct rust_vtable_symbol
*storage
= NULL
;
13394 if (cu
->language
== language_rust
)
13396 struct type
*containing_type
= rust_containing_type (die
, cu
);
13398 if (containing_type
!= NULL
)
13400 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13402 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13403 initialize_objfile_symbol (storage
);
13404 storage
->concrete_type
= containing_type
;
13405 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13409 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13410 struct attribute
*abstract_origin
13411 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13412 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13413 if (res
== NULL
&& loc
&& abstract_origin
)
13415 /* We have a variable without a name, but with a location and an abstract
13416 origin. This may be a concrete instance of an abstract variable
13417 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13419 struct dwarf2_cu
*origin_cu
= cu
;
13420 struct die_info
*origin_die
13421 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13422 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13423 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13427 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13428 reading .debug_rnglists.
13429 Callback's type should be:
13430 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13431 Return true if the attributes are present and valid, otherwise,
13434 template <typename Callback
>
13436 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13437 Callback
&&callback
)
13439 struct dwarf2_per_objfile
*dwarf2_per_objfile
13440 = cu
->per_cu
->dwarf2_per_objfile
;
13441 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13442 bfd
*obfd
= objfile
->obfd
;
13443 /* Base address selection entry. */
13446 const gdb_byte
*buffer
;
13447 CORE_ADDR baseaddr
;
13448 bool overflow
= false;
13450 found_base
= cu
->base_known
;
13451 base
= cu
->base_address
;
13453 dwarf2_per_objfile
->rnglists
.read (objfile
);
13454 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13456 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13460 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13462 baseaddr
= objfile
->text_section_offset ();
13466 /* Initialize it due to a false compiler warning. */
13467 CORE_ADDR range_beginning
= 0, range_end
= 0;
13468 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13469 + dwarf2_per_objfile
->rnglists
.size
);
13470 unsigned int bytes_read
;
13472 if (buffer
== buf_end
)
13477 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13480 case DW_RLE_end_of_list
:
13482 case DW_RLE_base_address
:
13483 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13488 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13490 buffer
+= bytes_read
;
13492 case DW_RLE_start_length
:
13493 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13498 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13500 buffer
+= bytes_read
;
13501 range_end
= (range_beginning
13502 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13503 buffer
+= bytes_read
;
13504 if (buffer
> buf_end
)
13510 case DW_RLE_offset_pair
:
13511 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13512 buffer
+= bytes_read
;
13513 if (buffer
> buf_end
)
13518 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13519 buffer
+= bytes_read
;
13520 if (buffer
> buf_end
)
13526 case DW_RLE_start_end
:
13527 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13532 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13534 buffer
+= bytes_read
;
13535 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13536 buffer
+= bytes_read
;
13539 complaint (_("Invalid .debug_rnglists data (no base address)"));
13542 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13544 if (rlet
== DW_RLE_base_address
)
13549 /* We have no valid base address for the ranges
13551 complaint (_("Invalid .debug_rnglists data (no base address)"));
13555 if (range_beginning
> range_end
)
13557 /* Inverted range entries are invalid. */
13558 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13562 /* Empty range entries have no effect. */
13563 if (range_beginning
== range_end
)
13566 range_beginning
+= base
;
13569 /* A not-uncommon case of bad debug info.
13570 Don't pollute the addrmap with bad data. */
13571 if (range_beginning
+ baseaddr
== 0
13572 && !dwarf2_per_objfile
->has_section_at_zero
)
13574 complaint (_(".debug_rnglists entry has start address of zero"
13575 " [in module %s]"), objfile_name (objfile
));
13579 callback (range_beginning
, range_end
);
13584 complaint (_("Offset %d is not terminated "
13585 "for DW_AT_ranges attribute"),
13593 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13594 Callback's type should be:
13595 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13596 Return 1 if the attributes are present and valid, otherwise, return 0. */
13598 template <typename Callback
>
13600 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13601 Callback
&&callback
)
13603 struct dwarf2_per_objfile
*dwarf2_per_objfile
13604 = cu
->per_cu
->dwarf2_per_objfile
;
13605 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13606 struct comp_unit_head
*cu_header
= &cu
->header
;
13607 bfd
*obfd
= objfile
->obfd
;
13608 unsigned int addr_size
= cu_header
->addr_size
;
13609 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13610 /* Base address selection entry. */
13613 unsigned int dummy
;
13614 const gdb_byte
*buffer
;
13615 CORE_ADDR baseaddr
;
13617 if (cu_header
->version
>= 5)
13618 return dwarf2_rnglists_process (offset
, cu
, callback
);
13620 found_base
= cu
->base_known
;
13621 base
= cu
->base_address
;
13623 dwarf2_per_objfile
->ranges
.read (objfile
);
13624 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13626 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13630 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13632 baseaddr
= objfile
->text_section_offset ();
13636 CORE_ADDR range_beginning
, range_end
;
13638 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13639 buffer
+= addr_size
;
13640 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13641 buffer
+= addr_size
;
13642 offset
+= 2 * addr_size
;
13644 /* An end of list marker is a pair of zero addresses. */
13645 if (range_beginning
== 0 && range_end
== 0)
13646 /* Found the end of list entry. */
13649 /* Each base address selection entry is a pair of 2 values.
13650 The first is the largest possible address, the second is
13651 the base address. Check for a base address here. */
13652 if ((range_beginning
& mask
) == mask
)
13654 /* If we found the largest possible address, then we already
13655 have the base address in range_end. */
13663 /* We have no valid base address for the ranges
13665 complaint (_("Invalid .debug_ranges data (no base address)"));
13669 if (range_beginning
> range_end
)
13671 /* Inverted range entries are invalid. */
13672 complaint (_("Invalid .debug_ranges data (inverted range)"));
13676 /* Empty range entries have no effect. */
13677 if (range_beginning
== range_end
)
13680 range_beginning
+= base
;
13683 /* A not-uncommon case of bad debug info.
13684 Don't pollute the addrmap with bad data. */
13685 if (range_beginning
+ baseaddr
== 0
13686 && !dwarf2_per_objfile
->has_section_at_zero
)
13688 complaint (_(".debug_ranges entry has start address of zero"
13689 " [in module %s]"), objfile_name (objfile
));
13693 callback (range_beginning
, range_end
);
13699 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13700 Return 1 if the attributes are present and valid, otherwise, return 0.
13701 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13704 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13705 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13706 dwarf2_psymtab
*ranges_pst
)
13708 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13709 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13710 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13713 CORE_ADDR high
= 0;
13716 retval
= dwarf2_ranges_process (offset
, cu
,
13717 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13719 if (ranges_pst
!= NULL
)
13724 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13725 range_beginning
+ baseaddr
)
13727 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13728 range_end
+ baseaddr
)
13730 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13731 lowpc
, highpc
- 1, ranges_pst
);
13734 /* FIXME: This is recording everything as a low-high
13735 segment of consecutive addresses. We should have a
13736 data structure for discontiguous block ranges
13740 low
= range_beginning
;
13746 if (range_beginning
< low
)
13747 low
= range_beginning
;
13748 if (range_end
> high
)
13756 /* If the first entry is an end-of-list marker, the range
13757 describes an empty scope, i.e. no instructions. */
13763 *high_return
= high
;
13767 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13768 definition for the return value. *LOWPC and *HIGHPC are set iff
13769 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13771 static enum pc_bounds_kind
13772 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13773 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13774 dwarf2_psymtab
*pst
)
13776 struct dwarf2_per_objfile
*dwarf2_per_objfile
13777 = cu
->per_cu
->dwarf2_per_objfile
;
13778 struct attribute
*attr
;
13779 struct attribute
*attr_high
;
13781 CORE_ADDR high
= 0;
13782 enum pc_bounds_kind ret
;
13784 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13787 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13788 if (attr
!= nullptr)
13790 low
= attr
->value_as_address ();
13791 high
= attr_high
->value_as_address ();
13792 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13796 /* Found high w/o low attribute. */
13797 return PC_BOUNDS_INVALID
;
13799 /* Found consecutive range of addresses. */
13800 ret
= PC_BOUNDS_HIGH_LOW
;
13804 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13807 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13808 We take advantage of the fact that DW_AT_ranges does not appear
13809 in DW_TAG_compile_unit of DWO files. */
13810 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13811 unsigned int ranges_offset
= (DW_UNSND (attr
)
13812 + (need_ranges_base
13816 /* Value of the DW_AT_ranges attribute is the offset in the
13817 .debug_ranges section. */
13818 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13819 return PC_BOUNDS_INVALID
;
13820 /* Found discontinuous range of addresses. */
13821 ret
= PC_BOUNDS_RANGES
;
13824 return PC_BOUNDS_NOT_PRESENT
;
13827 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13829 return PC_BOUNDS_INVALID
;
13831 /* When using the GNU linker, .gnu.linkonce. sections are used to
13832 eliminate duplicate copies of functions and vtables and such.
13833 The linker will arbitrarily choose one and discard the others.
13834 The AT_*_pc values for such functions refer to local labels in
13835 these sections. If the section from that file was discarded, the
13836 labels are not in the output, so the relocs get a value of 0.
13837 If this is a discarded function, mark the pc bounds as invalid,
13838 so that GDB will ignore it. */
13839 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13840 return PC_BOUNDS_INVALID
;
13848 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13849 its low and high PC addresses. Do nothing if these addresses could not
13850 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13851 and HIGHPC to the high address if greater than HIGHPC. */
13854 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13855 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13856 struct dwarf2_cu
*cu
)
13858 CORE_ADDR low
, high
;
13859 struct die_info
*child
= die
->child
;
13861 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13863 *lowpc
= std::min (*lowpc
, low
);
13864 *highpc
= std::max (*highpc
, high
);
13867 /* If the language does not allow nested subprograms (either inside
13868 subprograms or lexical blocks), we're done. */
13869 if (cu
->language
!= language_ada
)
13872 /* Check all the children of the given DIE. If it contains nested
13873 subprograms, then check their pc bounds. Likewise, we need to
13874 check lexical blocks as well, as they may also contain subprogram
13876 while (child
&& child
->tag
)
13878 if (child
->tag
== DW_TAG_subprogram
13879 || child
->tag
== DW_TAG_lexical_block
)
13880 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13881 child
= sibling_die (child
);
13885 /* Get the low and high pc's represented by the scope DIE, and store
13886 them in *LOWPC and *HIGHPC. If the correct values can't be
13887 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13890 get_scope_pc_bounds (struct die_info
*die
,
13891 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13892 struct dwarf2_cu
*cu
)
13894 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13895 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13896 CORE_ADDR current_low
, current_high
;
13898 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13899 >= PC_BOUNDS_RANGES
)
13901 best_low
= current_low
;
13902 best_high
= current_high
;
13906 struct die_info
*child
= die
->child
;
13908 while (child
&& child
->tag
)
13910 switch (child
->tag
) {
13911 case DW_TAG_subprogram
:
13912 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13914 case DW_TAG_namespace
:
13915 case DW_TAG_module
:
13916 /* FIXME: carlton/2004-01-16: Should we do this for
13917 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13918 that current GCC's always emit the DIEs corresponding
13919 to definitions of methods of classes as children of a
13920 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13921 the DIEs giving the declarations, which could be
13922 anywhere). But I don't see any reason why the
13923 standards says that they have to be there. */
13924 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13926 if (current_low
!= ((CORE_ADDR
) -1))
13928 best_low
= std::min (best_low
, current_low
);
13929 best_high
= std::max (best_high
, current_high
);
13937 child
= sibling_die (child
);
13942 *highpc
= best_high
;
13945 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13949 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13950 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13952 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13953 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13954 struct attribute
*attr
;
13955 struct attribute
*attr_high
;
13957 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13960 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13961 if (attr
!= nullptr)
13963 CORE_ADDR low
= attr
->value_as_address ();
13964 CORE_ADDR high
= attr_high
->value_as_address ();
13966 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13969 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13970 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13971 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13975 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13976 if (attr
!= nullptr)
13978 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13979 We take advantage of the fact that DW_AT_ranges does not appear
13980 in DW_TAG_compile_unit of DWO files. */
13981 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13983 /* The value of the DW_AT_ranges attribute is the offset of the
13984 address range list in the .debug_ranges section. */
13985 unsigned long offset
= (DW_UNSND (attr
)
13986 + (need_ranges_base
? cu
->ranges_base
: 0));
13988 std::vector
<blockrange
> blockvec
;
13989 dwarf2_ranges_process (offset
, cu
,
13990 [&] (CORE_ADDR start
, CORE_ADDR end
)
13994 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
13995 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
13996 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
13997 blockvec
.emplace_back (start
, end
);
14000 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14004 /* Check whether the producer field indicates either of GCC < 4.6, or the
14005 Intel C/C++ compiler, and cache the result in CU. */
14008 check_producer (struct dwarf2_cu
*cu
)
14012 if (cu
->producer
== NULL
)
14014 /* For unknown compilers expect their behavior is DWARF version
14017 GCC started to support .debug_types sections by -gdwarf-4 since
14018 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14019 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14020 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14021 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14023 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14025 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14026 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14028 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14030 cu
->producer_is_icc
= true;
14031 cu
->producer_is_icc_lt_14
= major
< 14;
14033 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14034 cu
->producer_is_codewarrior
= true;
14037 /* For other non-GCC compilers, expect their behavior is DWARF version
14041 cu
->checked_producer
= true;
14044 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14045 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14046 during 4.6.0 experimental. */
14049 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14051 if (!cu
->checked_producer
)
14052 check_producer (cu
);
14054 return cu
->producer_is_gxx_lt_4_6
;
14058 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14059 with incorrect is_stmt attributes. */
14062 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14064 if (!cu
->checked_producer
)
14065 check_producer (cu
);
14067 return cu
->producer_is_codewarrior
;
14070 /* Return the default accessibility type if it is not overridden by
14071 DW_AT_accessibility. */
14073 static enum dwarf_access_attribute
14074 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14076 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14078 /* The default DWARF 2 accessibility for members is public, the default
14079 accessibility for inheritance is private. */
14081 if (die
->tag
!= DW_TAG_inheritance
)
14082 return DW_ACCESS_public
;
14084 return DW_ACCESS_private
;
14088 /* DWARF 3+ defines the default accessibility a different way. The same
14089 rules apply now for DW_TAG_inheritance as for the members and it only
14090 depends on the container kind. */
14092 if (die
->parent
->tag
== DW_TAG_class_type
)
14093 return DW_ACCESS_private
;
14095 return DW_ACCESS_public
;
14099 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14100 offset. If the attribute was not found return 0, otherwise return
14101 1. If it was found but could not properly be handled, set *OFFSET
14105 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14108 struct attribute
*attr
;
14110 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14115 /* Note that we do not check for a section offset first here.
14116 This is because DW_AT_data_member_location is new in DWARF 4,
14117 so if we see it, we can assume that a constant form is really
14118 a constant and not a section offset. */
14119 if (attr
->form_is_constant ())
14120 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14121 else if (attr
->form_is_section_offset ())
14122 dwarf2_complex_location_expr_complaint ();
14123 else if (attr
->form_is_block ())
14124 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14126 dwarf2_complex_location_expr_complaint ();
14134 /* Add an aggregate field to the field list. */
14137 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14138 struct dwarf2_cu
*cu
)
14140 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14141 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14142 struct nextfield
*new_field
;
14143 struct attribute
*attr
;
14145 const char *fieldname
= "";
14147 if (die
->tag
== DW_TAG_inheritance
)
14149 fip
->baseclasses
.emplace_back ();
14150 new_field
= &fip
->baseclasses
.back ();
14154 fip
->fields
.emplace_back ();
14155 new_field
= &fip
->fields
.back ();
14158 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14159 if (attr
!= nullptr)
14160 new_field
->accessibility
= DW_UNSND (attr
);
14162 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14163 if (new_field
->accessibility
!= DW_ACCESS_public
)
14164 fip
->non_public_fields
= 1;
14166 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14167 if (attr
!= nullptr)
14168 new_field
->virtuality
= DW_UNSND (attr
);
14170 new_field
->virtuality
= DW_VIRTUALITY_none
;
14172 fp
= &new_field
->field
;
14174 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14178 /* Data member other than a C++ static data member. */
14180 /* Get type of field. */
14181 fp
->type
= die_type (die
, cu
);
14183 SET_FIELD_BITPOS (*fp
, 0);
14185 /* Get bit size of field (zero if none). */
14186 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14187 if (attr
!= nullptr)
14189 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14193 FIELD_BITSIZE (*fp
) = 0;
14196 /* Get bit offset of field. */
14197 if (handle_data_member_location (die
, cu
, &offset
))
14198 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14199 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14200 if (attr
!= nullptr)
14202 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14204 /* For big endian bits, the DW_AT_bit_offset gives the
14205 additional bit offset from the MSB of the containing
14206 anonymous object to the MSB of the field. We don't
14207 have to do anything special since we don't need to
14208 know the size of the anonymous object. */
14209 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14213 /* For little endian bits, compute the bit offset to the
14214 MSB of the anonymous object, subtract off the number of
14215 bits from the MSB of the field to the MSB of the
14216 object, and then subtract off the number of bits of
14217 the field itself. The result is the bit offset of
14218 the LSB of the field. */
14219 int anonymous_size
;
14220 int bit_offset
= DW_UNSND (attr
);
14222 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14223 if (attr
!= nullptr)
14225 /* The size of the anonymous object containing
14226 the bit field is explicit, so use the
14227 indicated size (in bytes). */
14228 anonymous_size
= DW_UNSND (attr
);
14232 /* The size of the anonymous object containing
14233 the bit field must be inferred from the type
14234 attribute of the data member containing the
14236 anonymous_size
= TYPE_LENGTH (fp
->type
);
14238 SET_FIELD_BITPOS (*fp
,
14239 (FIELD_BITPOS (*fp
)
14240 + anonymous_size
* bits_per_byte
14241 - bit_offset
- FIELD_BITSIZE (*fp
)));
14244 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14246 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14247 + dwarf2_get_attr_constant_value (attr
, 0)));
14249 /* Get name of field. */
14250 fieldname
= dwarf2_name (die
, cu
);
14251 if (fieldname
== NULL
)
14254 /* The name is already allocated along with this objfile, so we don't
14255 need to duplicate it for the type. */
14256 fp
->name
= fieldname
;
14258 /* Change accessibility for artificial fields (e.g. virtual table
14259 pointer or virtual base class pointer) to private. */
14260 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14262 FIELD_ARTIFICIAL (*fp
) = 1;
14263 new_field
->accessibility
= DW_ACCESS_private
;
14264 fip
->non_public_fields
= 1;
14267 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14269 /* C++ static member. */
14271 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14272 is a declaration, but all versions of G++ as of this writing
14273 (so through at least 3.2.1) incorrectly generate
14274 DW_TAG_variable tags. */
14276 const char *physname
;
14278 /* Get name of field. */
14279 fieldname
= dwarf2_name (die
, cu
);
14280 if (fieldname
== NULL
)
14283 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14285 /* Only create a symbol if this is an external value.
14286 new_symbol checks this and puts the value in the global symbol
14287 table, which we want. If it is not external, new_symbol
14288 will try to put the value in cu->list_in_scope which is wrong. */
14289 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14291 /* A static const member, not much different than an enum as far as
14292 we're concerned, except that we can support more types. */
14293 new_symbol (die
, NULL
, cu
);
14296 /* Get physical name. */
14297 physname
= dwarf2_physname (fieldname
, die
, cu
);
14299 /* The name is already allocated along with this objfile, so we don't
14300 need to duplicate it for the type. */
14301 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14302 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14303 FIELD_NAME (*fp
) = fieldname
;
14305 else if (die
->tag
== DW_TAG_inheritance
)
14309 /* C++ base class field. */
14310 if (handle_data_member_location (die
, cu
, &offset
))
14311 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14312 FIELD_BITSIZE (*fp
) = 0;
14313 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14314 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14316 else if (die
->tag
== DW_TAG_variant_part
)
14318 /* process_structure_scope will treat this DIE as a union. */
14319 process_structure_scope (die
, cu
);
14321 /* The variant part is relative to the start of the enclosing
14323 SET_FIELD_BITPOS (*fp
, 0);
14324 fp
->type
= get_die_type (die
, cu
);
14325 fp
->artificial
= 1;
14326 fp
->name
= "<<variant>>";
14328 /* Normally a DW_TAG_variant_part won't have a size, but our
14329 representation requires one, so set it to the maximum of the
14330 child sizes, being sure to account for the offset at which
14331 each child is seen. */
14332 if (TYPE_LENGTH (fp
->type
) == 0)
14335 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14337 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14338 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14342 TYPE_LENGTH (fp
->type
) = max
;
14346 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14349 /* Can the type given by DIE define another type? */
14352 type_can_define_types (const struct die_info
*die
)
14356 case DW_TAG_typedef
:
14357 case DW_TAG_class_type
:
14358 case DW_TAG_structure_type
:
14359 case DW_TAG_union_type
:
14360 case DW_TAG_enumeration_type
:
14368 /* Add a type definition defined in the scope of the FIP's class. */
14371 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14372 struct dwarf2_cu
*cu
)
14374 struct decl_field fp
;
14375 memset (&fp
, 0, sizeof (fp
));
14377 gdb_assert (type_can_define_types (die
));
14379 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14380 fp
.name
= dwarf2_name (die
, cu
);
14381 fp
.type
= read_type_die (die
, cu
);
14383 /* Save accessibility. */
14384 enum dwarf_access_attribute accessibility
;
14385 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14387 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14389 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14390 switch (accessibility
)
14392 case DW_ACCESS_public
:
14393 /* The assumed value if neither private nor protected. */
14395 case DW_ACCESS_private
:
14398 case DW_ACCESS_protected
:
14399 fp
.is_protected
= 1;
14402 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14405 if (die
->tag
== DW_TAG_typedef
)
14406 fip
->typedef_field_list
.push_back (fp
);
14408 fip
->nested_types_list
.push_back (fp
);
14411 /* Create the vector of fields, and attach it to the type. */
14414 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14415 struct dwarf2_cu
*cu
)
14417 int nfields
= fip
->nfields ();
14419 /* Record the field count, allocate space for the array of fields,
14420 and create blank accessibility bitfields if necessary. */
14421 TYPE_NFIELDS (type
) = nfields
;
14422 TYPE_FIELDS (type
) = (struct field
*)
14423 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14425 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14427 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14429 TYPE_FIELD_PRIVATE_BITS (type
) =
14430 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14431 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14433 TYPE_FIELD_PROTECTED_BITS (type
) =
14434 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14435 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14437 TYPE_FIELD_IGNORE_BITS (type
) =
14438 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14439 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14442 /* If the type has baseclasses, allocate and clear a bit vector for
14443 TYPE_FIELD_VIRTUAL_BITS. */
14444 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14446 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14447 unsigned char *pointer
;
14449 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14450 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14451 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14452 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14453 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14456 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14458 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14460 for (int index
= 0; index
< nfields
; ++index
)
14462 struct nextfield
&field
= fip
->fields
[index
];
14464 if (field
.variant
.is_discriminant
)
14465 di
->discriminant_index
= index
;
14466 else if (field
.variant
.default_branch
)
14467 di
->default_index
= index
;
14469 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14473 /* Copy the saved-up fields into the field vector. */
14474 for (int i
= 0; i
< nfields
; ++i
)
14476 struct nextfield
&field
14477 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14478 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14480 TYPE_FIELD (type
, i
) = field
.field
;
14481 switch (field
.accessibility
)
14483 case DW_ACCESS_private
:
14484 if (cu
->language
!= language_ada
)
14485 SET_TYPE_FIELD_PRIVATE (type
, i
);
14488 case DW_ACCESS_protected
:
14489 if (cu
->language
!= language_ada
)
14490 SET_TYPE_FIELD_PROTECTED (type
, i
);
14493 case DW_ACCESS_public
:
14497 /* Unknown accessibility. Complain and treat it as public. */
14499 complaint (_("unsupported accessibility %d"),
14500 field
.accessibility
);
14504 if (i
< fip
->baseclasses
.size ())
14506 switch (field
.virtuality
)
14508 case DW_VIRTUALITY_virtual
:
14509 case DW_VIRTUALITY_pure_virtual
:
14510 if (cu
->language
== language_ada
)
14511 error (_("unexpected virtuality in component of Ada type"));
14512 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14519 /* Return true if this member function is a constructor, false
14523 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14525 const char *fieldname
;
14526 const char *type_name
;
14529 if (die
->parent
== NULL
)
14532 if (die
->parent
->tag
!= DW_TAG_structure_type
14533 && die
->parent
->tag
!= DW_TAG_union_type
14534 && die
->parent
->tag
!= DW_TAG_class_type
)
14537 fieldname
= dwarf2_name (die
, cu
);
14538 type_name
= dwarf2_name (die
->parent
, cu
);
14539 if (fieldname
== NULL
|| type_name
== NULL
)
14542 len
= strlen (fieldname
);
14543 return (strncmp (fieldname
, type_name
, len
) == 0
14544 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14547 /* Check if the given VALUE is a recognized enum
14548 dwarf_defaulted_attribute constant according to DWARF5 spec,
14552 is_valid_DW_AT_defaulted (ULONGEST value
)
14556 case DW_DEFAULTED_no
:
14557 case DW_DEFAULTED_in_class
:
14558 case DW_DEFAULTED_out_of_class
:
14562 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14566 /* Add a member function to the proper fieldlist. */
14569 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14570 struct type
*type
, struct dwarf2_cu
*cu
)
14572 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14573 struct attribute
*attr
;
14575 struct fnfieldlist
*flp
= nullptr;
14576 struct fn_field
*fnp
;
14577 const char *fieldname
;
14578 struct type
*this_type
;
14579 enum dwarf_access_attribute accessibility
;
14581 if (cu
->language
== language_ada
)
14582 error (_("unexpected member function in Ada type"));
14584 /* Get name of member function. */
14585 fieldname
= dwarf2_name (die
, cu
);
14586 if (fieldname
== NULL
)
14589 /* Look up member function name in fieldlist. */
14590 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14592 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14594 flp
= &fip
->fnfieldlists
[i
];
14599 /* Create a new fnfieldlist if necessary. */
14600 if (flp
== nullptr)
14602 fip
->fnfieldlists
.emplace_back ();
14603 flp
= &fip
->fnfieldlists
.back ();
14604 flp
->name
= fieldname
;
14605 i
= fip
->fnfieldlists
.size () - 1;
14608 /* Create a new member function field and add it to the vector of
14610 flp
->fnfields
.emplace_back ();
14611 fnp
= &flp
->fnfields
.back ();
14613 /* Delay processing of the physname until later. */
14614 if (cu
->language
== language_cplus
)
14615 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14619 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14620 fnp
->physname
= physname
? physname
: "";
14623 fnp
->type
= alloc_type (objfile
);
14624 this_type
= read_type_die (die
, cu
);
14625 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14627 int nparams
= TYPE_NFIELDS (this_type
);
14629 /* TYPE is the domain of this method, and THIS_TYPE is the type
14630 of the method itself (TYPE_CODE_METHOD). */
14631 smash_to_method_type (fnp
->type
, type
,
14632 TYPE_TARGET_TYPE (this_type
),
14633 TYPE_FIELDS (this_type
),
14634 TYPE_NFIELDS (this_type
),
14635 TYPE_VARARGS (this_type
));
14637 /* Handle static member functions.
14638 Dwarf2 has no clean way to discern C++ static and non-static
14639 member functions. G++ helps GDB by marking the first
14640 parameter for non-static member functions (which is the this
14641 pointer) as artificial. We obtain this information from
14642 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14643 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14644 fnp
->voffset
= VOFFSET_STATIC
;
14647 complaint (_("member function type missing for '%s'"),
14648 dwarf2_full_name (fieldname
, die
, cu
));
14650 /* Get fcontext from DW_AT_containing_type if present. */
14651 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14652 fnp
->fcontext
= die_containing_type (die
, cu
);
14654 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14655 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14657 /* Get accessibility. */
14658 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14659 if (attr
!= nullptr)
14660 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14662 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14663 switch (accessibility
)
14665 case DW_ACCESS_private
:
14666 fnp
->is_private
= 1;
14668 case DW_ACCESS_protected
:
14669 fnp
->is_protected
= 1;
14673 /* Check for artificial methods. */
14674 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14675 if (attr
&& DW_UNSND (attr
) != 0)
14676 fnp
->is_artificial
= 1;
14678 /* Check for defaulted methods. */
14679 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14680 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14681 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14683 /* Check for deleted methods. */
14684 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14685 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14686 fnp
->is_deleted
= 1;
14688 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14690 /* Get index in virtual function table if it is a virtual member
14691 function. For older versions of GCC, this is an offset in the
14692 appropriate virtual table, as specified by DW_AT_containing_type.
14693 For everyone else, it is an expression to be evaluated relative
14694 to the object address. */
14696 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14697 if (attr
!= nullptr)
14699 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14701 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14703 /* Old-style GCC. */
14704 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14706 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14707 || (DW_BLOCK (attr
)->size
> 1
14708 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14709 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14711 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14712 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14713 dwarf2_complex_location_expr_complaint ();
14715 fnp
->voffset
/= cu
->header
.addr_size
;
14719 dwarf2_complex_location_expr_complaint ();
14721 if (!fnp
->fcontext
)
14723 /* If there is no `this' field and no DW_AT_containing_type,
14724 we cannot actually find a base class context for the
14726 if (TYPE_NFIELDS (this_type
) == 0
14727 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14729 complaint (_("cannot determine context for virtual member "
14730 "function \"%s\" (offset %s)"),
14731 fieldname
, sect_offset_str (die
->sect_off
));
14736 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14740 else if (attr
->form_is_section_offset ())
14742 dwarf2_complex_location_expr_complaint ();
14746 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14752 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14753 if (attr
&& DW_UNSND (attr
))
14755 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14756 complaint (_("Member function \"%s\" (offset %s) is virtual "
14757 "but the vtable offset is not specified"),
14758 fieldname
, sect_offset_str (die
->sect_off
));
14759 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14760 TYPE_CPLUS_DYNAMIC (type
) = 1;
14765 /* Create the vector of member function fields, and attach it to the type. */
14768 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14769 struct dwarf2_cu
*cu
)
14771 if (cu
->language
== language_ada
)
14772 error (_("unexpected member functions in Ada type"));
14774 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14775 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14777 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14779 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14781 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14782 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14784 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14785 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14786 fn_flp
->fn_fields
= (struct fn_field
*)
14787 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14789 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14790 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14793 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14796 /* Returns non-zero if NAME is the name of a vtable member in CU's
14797 language, zero otherwise. */
14799 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14801 static const char vptr
[] = "_vptr";
14803 /* Look for the C++ form of the vtable. */
14804 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14810 /* GCC outputs unnamed structures that are really pointers to member
14811 functions, with the ABI-specified layout. If TYPE describes
14812 such a structure, smash it into a member function type.
14814 GCC shouldn't do this; it should just output pointer to member DIEs.
14815 This is GCC PR debug/28767. */
14818 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14820 struct type
*pfn_type
, *self_type
, *new_type
;
14822 /* Check for a structure with no name and two children. */
14823 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14826 /* Check for __pfn and __delta members. */
14827 if (TYPE_FIELD_NAME (type
, 0) == NULL
14828 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14829 || TYPE_FIELD_NAME (type
, 1) == NULL
14830 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14833 /* Find the type of the method. */
14834 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14835 if (pfn_type
== NULL
14836 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14837 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14840 /* Look for the "this" argument. */
14841 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14842 if (TYPE_NFIELDS (pfn_type
) == 0
14843 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14844 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14847 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14848 new_type
= alloc_type (objfile
);
14849 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14850 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14851 TYPE_VARARGS (pfn_type
));
14852 smash_to_methodptr_type (type
, new_type
);
14855 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14856 appropriate error checking and issuing complaints if there is a
14860 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14862 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14864 if (attr
== nullptr)
14867 if (!attr
->form_is_constant ())
14869 complaint (_("DW_AT_alignment must have constant form"
14870 " - DIE at %s [in module %s]"),
14871 sect_offset_str (die
->sect_off
),
14872 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14877 if (attr
->form
== DW_FORM_sdata
)
14879 LONGEST val
= DW_SND (attr
);
14882 complaint (_("DW_AT_alignment value must not be negative"
14883 " - DIE at %s [in module %s]"),
14884 sect_offset_str (die
->sect_off
),
14885 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14891 align
= DW_UNSND (attr
);
14895 complaint (_("DW_AT_alignment value must not be zero"
14896 " - DIE at %s [in module %s]"),
14897 sect_offset_str (die
->sect_off
),
14898 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14901 if ((align
& (align
- 1)) != 0)
14903 complaint (_("DW_AT_alignment value must be a power of 2"
14904 " - DIE at %s [in module %s]"),
14905 sect_offset_str (die
->sect_off
),
14906 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14913 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14914 the alignment for TYPE. */
14917 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14920 if (!set_type_align (type
, get_alignment (cu
, die
)))
14921 complaint (_("DW_AT_alignment value too large"
14922 " - DIE at %s [in module %s]"),
14923 sect_offset_str (die
->sect_off
),
14924 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14927 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14928 constant for a type, according to DWARF5 spec, Table 5.5. */
14931 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14936 case DW_CC_pass_by_reference
:
14937 case DW_CC_pass_by_value
:
14941 complaint (_("unrecognized DW_AT_calling_convention value "
14942 "(%s) for a type"), pulongest (value
));
14947 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14948 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14949 also according to GNU-specific values (see include/dwarf2.h). */
14952 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14957 case DW_CC_program
:
14961 case DW_CC_GNU_renesas_sh
:
14962 case DW_CC_GNU_borland_fastcall_i386
:
14963 case DW_CC_GDB_IBM_OpenCL
:
14967 complaint (_("unrecognized DW_AT_calling_convention value "
14968 "(%s) for a subroutine"), pulongest (value
));
14973 /* Called when we find the DIE that starts a structure or union scope
14974 (definition) to create a type for the structure or union. Fill in
14975 the type's name and general properties; the members will not be
14976 processed until process_structure_scope. A symbol table entry for
14977 the type will also not be done until process_structure_scope (assuming
14978 the type has a name).
14980 NOTE: we need to call these functions regardless of whether or not the
14981 DIE has a DW_AT_name attribute, since it might be an anonymous
14982 structure or union. This gets the type entered into our set of
14983 user defined types. */
14985 static struct type
*
14986 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14988 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14990 struct attribute
*attr
;
14993 /* If the definition of this type lives in .debug_types, read that type.
14994 Don't follow DW_AT_specification though, that will take us back up
14995 the chain and we want to go down. */
14996 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
14997 if (attr
!= nullptr)
14999 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15001 /* The type's CU may not be the same as CU.
15002 Ensure TYPE is recorded with CU in die_type_hash. */
15003 return set_die_type (die
, type
, cu
);
15006 type
= alloc_type (objfile
);
15007 INIT_CPLUS_SPECIFIC (type
);
15009 name
= dwarf2_name (die
, cu
);
15012 if (cu
->language
== language_cplus
15013 || cu
->language
== language_d
15014 || cu
->language
== language_rust
)
15016 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15018 /* dwarf2_full_name might have already finished building the DIE's
15019 type. If so, there is no need to continue. */
15020 if (get_die_type (die
, cu
) != NULL
)
15021 return get_die_type (die
, cu
);
15023 TYPE_NAME (type
) = full_name
;
15027 /* The name is already allocated along with this objfile, so
15028 we don't need to duplicate it for the type. */
15029 TYPE_NAME (type
) = name
;
15033 if (die
->tag
== DW_TAG_structure_type
)
15035 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15037 else if (die
->tag
== DW_TAG_union_type
)
15039 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15041 else if (die
->tag
== DW_TAG_variant_part
)
15043 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15044 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15048 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15051 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15052 TYPE_DECLARED_CLASS (type
) = 1;
15054 /* Store the calling convention in the type if it's available in
15055 the die. Otherwise the calling convention remains set to
15056 the default value DW_CC_normal. */
15057 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15058 if (attr
!= nullptr
15059 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15061 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15062 TYPE_CPLUS_CALLING_CONVENTION (type
)
15063 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15066 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15067 if (attr
!= nullptr)
15069 if (attr
->form_is_constant ())
15070 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15073 /* For the moment, dynamic type sizes are not supported
15074 by GDB's struct type. The actual size is determined
15075 on-demand when resolving the type of a given object,
15076 so set the type's length to zero for now. Otherwise,
15077 we record an expression as the length, and that expression
15078 could lead to a very large value, which could eventually
15079 lead to us trying to allocate that much memory when creating
15080 a value of that type. */
15081 TYPE_LENGTH (type
) = 0;
15086 TYPE_LENGTH (type
) = 0;
15089 maybe_set_alignment (cu
, die
, type
);
15091 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15093 /* ICC<14 does not output the required DW_AT_declaration on
15094 incomplete types, but gives them a size of zero. */
15095 TYPE_STUB (type
) = 1;
15098 TYPE_STUB_SUPPORTED (type
) = 1;
15100 if (die_is_declaration (die
, cu
))
15101 TYPE_STUB (type
) = 1;
15102 else if (attr
== NULL
&& die
->child
== NULL
15103 && producer_is_realview (cu
->producer
))
15104 /* RealView does not output the required DW_AT_declaration
15105 on incomplete types. */
15106 TYPE_STUB (type
) = 1;
15108 /* We need to add the type field to the die immediately so we don't
15109 infinitely recurse when dealing with pointers to the structure
15110 type within the structure itself. */
15111 set_die_type (die
, type
, cu
);
15113 /* set_die_type should be already done. */
15114 set_descriptive_type (type
, die
, cu
);
15119 /* A helper for process_structure_scope that handles a single member
15123 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15124 struct field_info
*fi
,
15125 std::vector
<struct symbol
*> *template_args
,
15126 struct dwarf2_cu
*cu
)
15128 if (child_die
->tag
== DW_TAG_member
15129 || child_die
->tag
== DW_TAG_variable
15130 || child_die
->tag
== DW_TAG_variant_part
)
15132 /* NOTE: carlton/2002-11-05: A C++ static data member
15133 should be a DW_TAG_member that is a declaration, but
15134 all versions of G++ as of this writing (so through at
15135 least 3.2.1) incorrectly generate DW_TAG_variable
15136 tags for them instead. */
15137 dwarf2_add_field (fi
, child_die
, cu
);
15139 else if (child_die
->tag
== DW_TAG_subprogram
)
15141 /* Rust doesn't have member functions in the C++ sense.
15142 However, it does emit ordinary functions as children
15143 of a struct DIE. */
15144 if (cu
->language
== language_rust
)
15145 read_func_scope (child_die
, cu
);
15148 /* C++ member function. */
15149 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15152 else if (child_die
->tag
== DW_TAG_inheritance
)
15154 /* C++ base class field. */
15155 dwarf2_add_field (fi
, child_die
, cu
);
15157 else if (type_can_define_types (child_die
))
15158 dwarf2_add_type_defn (fi
, child_die
, cu
);
15159 else if (child_die
->tag
== DW_TAG_template_type_param
15160 || child_die
->tag
== DW_TAG_template_value_param
)
15162 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15165 template_args
->push_back (arg
);
15167 else if (child_die
->tag
== DW_TAG_variant
)
15169 /* In a variant we want to get the discriminant and also add a
15170 field for our sole member child. */
15171 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15173 for (die_info
*variant_child
= child_die
->child
;
15174 variant_child
!= NULL
;
15175 variant_child
= sibling_die (variant_child
))
15177 if (variant_child
->tag
== DW_TAG_member
)
15179 handle_struct_member_die (variant_child
, type
, fi
,
15180 template_args
, cu
);
15181 /* Only handle the one. */
15186 /* We don't handle this but we might as well report it if we see
15188 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15189 complaint (_("DW_AT_discr_list is not supported yet"
15190 " - DIE at %s [in module %s]"),
15191 sect_offset_str (child_die
->sect_off
),
15192 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15194 /* The first field was just added, so we can stash the
15195 discriminant there. */
15196 gdb_assert (!fi
->fields
.empty ());
15198 fi
->fields
.back ().variant
.default_branch
= true;
15200 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15204 /* Finish creating a structure or union type, including filling in
15205 its members and creating a symbol for it. */
15208 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15210 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15211 struct die_info
*child_die
;
15214 type
= get_die_type (die
, cu
);
15216 type
= read_structure_type (die
, cu
);
15218 /* When reading a DW_TAG_variant_part, we need to notice when we
15219 read the discriminant member, so we can record it later in the
15220 discriminant_info. */
15221 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15222 sect_offset discr_offset
{};
15223 bool has_template_parameters
= false;
15225 if (is_variant_part
)
15227 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15230 /* Maybe it's a univariant form, an extension we support.
15231 In this case arrange not to check the offset. */
15232 is_variant_part
= false;
15234 else if (discr
->form_is_ref ())
15236 struct dwarf2_cu
*target_cu
= cu
;
15237 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15239 discr_offset
= target_die
->sect_off
;
15243 complaint (_("DW_AT_discr does not have DIE reference form"
15244 " - DIE at %s [in module %s]"),
15245 sect_offset_str (die
->sect_off
),
15246 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15247 is_variant_part
= false;
15251 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15253 struct field_info fi
;
15254 std::vector
<struct symbol
*> template_args
;
15256 child_die
= die
->child
;
15258 while (child_die
&& child_die
->tag
)
15260 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15262 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15263 fi
.fields
.back ().variant
.is_discriminant
= true;
15265 child_die
= sibling_die (child_die
);
15268 /* Attach template arguments to type. */
15269 if (!template_args
.empty ())
15271 has_template_parameters
= true;
15272 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15273 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15274 TYPE_TEMPLATE_ARGUMENTS (type
)
15275 = XOBNEWVEC (&objfile
->objfile_obstack
,
15277 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15278 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15279 template_args
.data (),
15280 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15281 * sizeof (struct symbol
*)));
15284 /* Attach fields and member functions to the type. */
15285 if (fi
.nfields () > 0)
15286 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15287 if (!fi
.fnfieldlists
.empty ())
15289 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15291 /* Get the type which refers to the base class (possibly this
15292 class itself) which contains the vtable pointer for the current
15293 class from the DW_AT_containing_type attribute. This use of
15294 DW_AT_containing_type is a GNU extension. */
15296 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15298 struct type
*t
= die_containing_type (die
, cu
);
15300 set_type_vptr_basetype (type
, t
);
15305 /* Our own class provides vtbl ptr. */
15306 for (i
= TYPE_NFIELDS (t
) - 1;
15307 i
>= TYPE_N_BASECLASSES (t
);
15310 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15312 if (is_vtable_name (fieldname
, cu
))
15314 set_type_vptr_fieldno (type
, i
);
15319 /* Complain if virtual function table field not found. */
15320 if (i
< TYPE_N_BASECLASSES (t
))
15321 complaint (_("virtual function table pointer "
15322 "not found when defining class '%s'"),
15323 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15327 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15330 else if (cu
->producer
15331 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15333 /* The IBM XLC compiler does not provide direct indication
15334 of the containing type, but the vtable pointer is
15335 always named __vfp. */
15339 for (i
= TYPE_NFIELDS (type
) - 1;
15340 i
>= TYPE_N_BASECLASSES (type
);
15343 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15345 set_type_vptr_fieldno (type
, i
);
15346 set_type_vptr_basetype (type
, type
);
15353 /* Copy fi.typedef_field_list linked list elements content into the
15354 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15355 if (!fi
.typedef_field_list
.empty ())
15357 int count
= fi
.typedef_field_list
.size ();
15359 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15360 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15361 = ((struct decl_field
*)
15363 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15364 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15366 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15367 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15370 /* Copy fi.nested_types_list linked list elements content into the
15371 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15372 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15374 int count
= fi
.nested_types_list
.size ();
15376 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15377 TYPE_NESTED_TYPES_ARRAY (type
)
15378 = ((struct decl_field
*)
15379 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15380 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15382 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15383 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15387 quirk_gcc_member_function_pointer (type
, objfile
);
15388 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15389 cu
->rust_unions
.push_back (type
);
15391 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15392 snapshots) has been known to create a die giving a declaration
15393 for a class that has, as a child, a die giving a definition for a
15394 nested class. So we have to process our children even if the
15395 current die is a declaration. Normally, of course, a declaration
15396 won't have any children at all. */
15398 child_die
= die
->child
;
15400 while (child_die
!= NULL
&& child_die
->tag
)
15402 if (child_die
->tag
== DW_TAG_member
15403 || child_die
->tag
== DW_TAG_variable
15404 || child_die
->tag
== DW_TAG_inheritance
15405 || child_die
->tag
== DW_TAG_template_value_param
15406 || child_die
->tag
== DW_TAG_template_type_param
)
15411 process_die (child_die
, cu
);
15413 child_die
= sibling_die (child_die
);
15416 /* Do not consider external references. According to the DWARF standard,
15417 these DIEs are identified by the fact that they have no byte_size
15418 attribute, and a declaration attribute. */
15419 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15420 || !die_is_declaration (die
, cu
))
15422 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15424 if (has_template_parameters
)
15426 struct symtab
*symtab
;
15427 if (sym
!= nullptr)
15428 symtab
= symbol_symtab (sym
);
15429 else if (cu
->line_header
!= nullptr)
15431 /* Any related symtab will do. */
15433 = cu
->line_header
->file_names ()[0].symtab
;
15438 complaint (_("could not find suitable "
15439 "symtab for template parameter"
15440 " - DIE at %s [in module %s]"),
15441 sect_offset_str (die
->sect_off
),
15442 objfile_name (objfile
));
15445 if (symtab
!= nullptr)
15447 /* Make sure that the symtab is set on the new symbols.
15448 Even though they don't appear in this symtab directly,
15449 other parts of gdb assume that symbols do, and this is
15450 reasonably true. */
15451 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15452 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15458 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15459 update TYPE using some information only available in DIE's children. */
15462 update_enumeration_type_from_children (struct die_info
*die
,
15464 struct dwarf2_cu
*cu
)
15466 struct die_info
*child_die
;
15467 int unsigned_enum
= 1;
15470 auto_obstack obstack
;
15472 for (child_die
= die
->child
;
15473 child_die
!= NULL
&& child_die
->tag
;
15474 child_die
= sibling_die (child_die
))
15476 struct attribute
*attr
;
15478 const gdb_byte
*bytes
;
15479 struct dwarf2_locexpr_baton
*baton
;
15482 if (child_die
->tag
!= DW_TAG_enumerator
)
15485 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15489 name
= dwarf2_name (child_die
, cu
);
15491 name
= "<anonymous enumerator>";
15493 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15494 &value
, &bytes
, &baton
);
15502 if (count_one_bits_ll (value
) >= 2)
15506 /* If we already know that the enum type is neither unsigned, nor
15507 a flag type, no need to look at the rest of the enumerates. */
15508 if (!unsigned_enum
&& !flag_enum
)
15513 TYPE_UNSIGNED (type
) = 1;
15515 TYPE_FLAG_ENUM (type
) = 1;
15518 /* Given a DW_AT_enumeration_type die, set its type. We do not
15519 complete the type's fields yet, or create any symbols. */
15521 static struct type
*
15522 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15524 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15526 struct attribute
*attr
;
15529 /* If the definition of this type lives in .debug_types, read that type.
15530 Don't follow DW_AT_specification though, that will take us back up
15531 the chain and we want to go down. */
15532 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15533 if (attr
!= nullptr)
15535 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15537 /* The type's CU may not be the same as CU.
15538 Ensure TYPE is recorded with CU in die_type_hash. */
15539 return set_die_type (die
, type
, cu
);
15542 type
= alloc_type (objfile
);
15544 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15545 name
= dwarf2_full_name (NULL
, die
, cu
);
15547 TYPE_NAME (type
) = name
;
15549 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15552 struct type
*underlying_type
= die_type (die
, cu
);
15554 TYPE_TARGET_TYPE (type
) = underlying_type
;
15557 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15558 if (attr
!= nullptr)
15560 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15564 TYPE_LENGTH (type
) = 0;
15567 maybe_set_alignment (cu
, die
, type
);
15569 /* The enumeration DIE can be incomplete. In Ada, any type can be
15570 declared as private in the package spec, and then defined only
15571 inside the package body. Such types are known as Taft Amendment
15572 Types. When another package uses such a type, an incomplete DIE
15573 may be generated by the compiler. */
15574 if (die_is_declaration (die
, cu
))
15575 TYPE_STUB (type
) = 1;
15577 /* Finish the creation of this type by using the enum's children.
15578 We must call this even when the underlying type has been provided
15579 so that we can determine if we're looking at a "flag" enum. */
15580 update_enumeration_type_from_children (die
, type
, cu
);
15582 /* If this type has an underlying type that is not a stub, then we
15583 may use its attributes. We always use the "unsigned" attribute
15584 in this situation, because ordinarily we guess whether the type
15585 is unsigned -- but the guess can be wrong and the underlying type
15586 can tell us the reality. However, we defer to a local size
15587 attribute if one exists, because this lets the compiler override
15588 the underlying type if needed. */
15589 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15591 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15592 if (TYPE_LENGTH (type
) == 0)
15593 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15594 if (TYPE_RAW_ALIGN (type
) == 0
15595 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15596 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15599 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15601 return set_die_type (die
, type
, cu
);
15604 /* Given a pointer to a die which begins an enumeration, process all
15605 the dies that define the members of the enumeration, and create the
15606 symbol for the enumeration type.
15608 NOTE: We reverse the order of the element list. */
15611 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15613 struct type
*this_type
;
15615 this_type
= get_die_type (die
, cu
);
15616 if (this_type
== NULL
)
15617 this_type
= read_enumeration_type (die
, cu
);
15619 if (die
->child
!= NULL
)
15621 struct die_info
*child_die
;
15622 struct symbol
*sym
;
15623 std::vector
<struct field
> fields
;
15626 child_die
= die
->child
;
15627 while (child_die
&& child_die
->tag
)
15629 if (child_die
->tag
!= DW_TAG_enumerator
)
15631 process_die (child_die
, cu
);
15635 name
= dwarf2_name (child_die
, cu
);
15638 sym
= new_symbol (child_die
, this_type
, cu
);
15640 fields
.emplace_back ();
15641 struct field
&field
= fields
.back ();
15643 FIELD_NAME (field
) = sym
->linkage_name ();
15644 FIELD_TYPE (field
) = NULL
;
15645 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15646 FIELD_BITSIZE (field
) = 0;
15650 child_die
= sibling_die (child_die
);
15653 if (!fields
.empty ())
15655 TYPE_NFIELDS (this_type
) = fields
.size ();
15656 TYPE_FIELDS (this_type
) = (struct field
*)
15657 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15658 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15659 sizeof (struct field
) * fields
.size ());
15663 /* If we are reading an enum from a .debug_types unit, and the enum
15664 is a declaration, and the enum is not the signatured type in the
15665 unit, then we do not want to add a symbol for it. Adding a
15666 symbol would in some cases obscure the true definition of the
15667 enum, giving users an incomplete type when the definition is
15668 actually available. Note that we do not want to do this for all
15669 enums which are just declarations, because C++0x allows forward
15670 enum declarations. */
15671 if (cu
->per_cu
->is_debug_types
15672 && die_is_declaration (die
, cu
))
15674 struct signatured_type
*sig_type
;
15676 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15677 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15678 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15682 new_symbol (die
, this_type
, cu
);
15685 /* Extract all information from a DW_TAG_array_type DIE and put it in
15686 the DIE's type field. For now, this only handles one dimensional
15689 static struct type
*
15690 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15692 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15693 struct die_info
*child_die
;
15695 struct type
*element_type
, *range_type
, *index_type
;
15696 struct attribute
*attr
;
15698 struct dynamic_prop
*byte_stride_prop
= NULL
;
15699 unsigned int bit_stride
= 0;
15701 element_type
= die_type (die
, cu
);
15703 /* The die_type call above may have already set the type for this DIE. */
15704 type
= get_die_type (die
, cu
);
15708 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15712 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15715 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15716 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15720 complaint (_("unable to read array DW_AT_byte_stride "
15721 " - DIE at %s [in module %s]"),
15722 sect_offset_str (die
->sect_off
),
15723 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15724 /* Ignore this attribute. We will likely not be able to print
15725 arrays of this type correctly, but there is little we can do
15726 to help if we cannot read the attribute's value. */
15727 byte_stride_prop
= NULL
;
15731 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15733 bit_stride
= DW_UNSND (attr
);
15735 /* Irix 6.2 native cc creates array types without children for
15736 arrays with unspecified length. */
15737 if (die
->child
== NULL
)
15739 index_type
= objfile_type (objfile
)->builtin_int
;
15740 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15741 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15742 byte_stride_prop
, bit_stride
);
15743 return set_die_type (die
, type
, cu
);
15746 std::vector
<struct type
*> range_types
;
15747 child_die
= die
->child
;
15748 while (child_die
&& child_die
->tag
)
15750 if (child_die
->tag
== DW_TAG_subrange_type
)
15752 struct type
*child_type
= read_type_die (child_die
, cu
);
15754 if (child_type
!= NULL
)
15756 /* The range type was succesfully read. Save it for the
15757 array type creation. */
15758 range_types
.push_back (child_type
);
15761 child_die
= sibling_die (child_die
);
15764 /* Dwarf2 dimensions are output from left to right, create the
15765 necessary array types in backwards order. */
15767 type
= element_type
;
15769 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15773 while (i
< range_types
.size ())
15774 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15775 byte_stride_prop
, bit_stride
);
15779 size_t ndim
= range_types
.size ();
15781 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15782 byte_stride_prop
, bit_stride
);
15785 /* Understand Dwarf2 support for vector types (like they occur on
15786 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15787 array type. This is not part of the Dwarf2/3 standard yet, but a
15788 custom vendor extension. The main difference between a regular
15789 array and the vector variant is that vectors are passed by value
15791 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15792 if (attr
!= nullptr)
15793 make_vector_type (type
);
15795 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15796 implementation may choose to implement triple vectors using this
15798 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15799 if (attr
!= nullptr)
15801 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15802 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15804 complaint (_("DW_AT_byte_size for array type smaller "
15805 "than the total size of elements"));
15808 name
= dwarf2_name (die
, cu
);
15810 TYPE_NAME (type
) = name
;
15812 maybe_set_alignment (cu
, die
, type
);
15814 /* Install the type in the die. */
15815 set_die_type (die
, type
, cu
);
15817 /* set_die_type should be already done. */
15818 set_descriptive_type (type
, die
, cu
);
15823 static enum dwarf_array_dim_ordering
15824 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15826 struct attribute
*attr
;
15828 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15830 if (attr
!= nullptr)
15831 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15833 /* GNU F77 is a special case, as at 08/2004 array type info is the
15834 opposite order to the dwarf2 specification, but data is still
15835 laid out as per normal fortran.
15837 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15838 version checking. */
15840 if (cu
->language
== language_fortran
15841 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15843 return DW_ORD_row_major
;
15846 switch (cu
->language_defn
->la_array_ordering
)
15848 case array_column_major
:
15849 return DW_ORD_col_major
;
15850 case array_row_major
:
15852 return DW_ORD_row_major
;
15856 /* Extract all information from a DW_TAG_set_type DIE and put it in
15857 the DIE's type field. */
15859 static struct type
*
15860 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15862 struct type
*domain_type
, *set_type
;
15863 struct attribute
*attr
;
15865 domain_type
= die_type (die
, cu
);
15867 /* The die_type call above may have already set the type for this DIE. */
15868 set_type
= get_die_type (die
, cu
);
15872 set_type
= create_set_type (NULL
, domain_type
);
15874 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15875 if (attr
!= nullptr)
15876 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15878 maybe_set_alignment (cu
, die
, set_type
);
15880 return set_die_type (die
, set_type
, cu
);
15883 /* A helper for read_common_block that creates a locexpr baton.
15884 SYM is the symbol which we are marking as computed.
15885 COMMON_DIE is the DIE for the common block.
15886 COMMON_LOC is the location expression attribute for the common
15888 MEMBER_LOC is the location expression attribute for the particular
15889 member of the common block that we are processing.
15890 CU is the CU from which the above come. */
15893 mark_common_block_symbol_computed (struct symbol
*sym
,
15894 struct die_info
*common_die
,
15895 struct attribute
*common_loc
,
15896 struct attribute
*member_loc
,
15897 struct dwarf2_cu
*cu
)
15899 struct dwarf2_per_objfile
*dwarf2_per_objfile
15900 = cu
->per_cu
->dwarf2_per_objfile
;
15901 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15902 struct dwarf2_locexpr_baton
*baton
;
15904 unsigned int cu_off
;
15905 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15906 LONGEST offset
= 0;
15908 gdb_assert (common_loc
&& member_loc
);
15909 gdb_assert (common_loc
->form_is_block ());
15910 gdb_assert (member_loc
->form_is_block ()
15911 || member_loc
->form_is_constant ());
15913 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15914 baton
->per_cu
= cu
->per_cu
;
15915 gdb_assert (baton
->per_cu
);
15917 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15919 if (member_loc
->form_is_constant ())
15921 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15922 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15925 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15927 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15930 *ptr
++ = DW_OP_call4
;
15931 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15932 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15935 if (member_loc
->form_is_constant ())
15937 *ptr
++ = DW_OP_addr
;
15938 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15939 ptr
+= cu
->header
.addr_size
;
15943 /* We have to copy the data here, because DW_OP_call4 will only
15944 use a DW_AT_location attribute. */
15945 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15946 ptr
+= DW_BLOCK (member_loc
)->size
;
15949 *ptr
++ = DW_OP_plus
;
15950 gdb_assert (ptr
- baton
->data
== baton
->size
);
15952 SYMBOL_LOCATION_BATON (sym
) = baton
;
15953 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15956 /* Create appropriate locally-scoped variables for all the
15957 DW_TAG_common_block entries. Also create a struct common_block
15958 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15959 is used to separate the common blocks name namespace from regular
15963 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15965 struct attribute
*attr
;
15967 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15968 if (attr
!= nullptr)
15970 /* Support the .debug_loc offsets. */
15971 if (attr
->form_is_block ())
15975 else if (attr
->form_is_section_offset ())
15977 dwarf2_complex_location_expr_complaint ();
15982 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15983 "common block member");
15988 if (die
->child
!= NULL
)
15990 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15991 struct die_info
*child_die
;
15992 size_t n_entries
= 0, size
;
15993 struct common_block
*common_block
;
15994 struct symbol
*sym
;
15996 for (child_die
= die
->child
;
15997 child_die
&& child_die
->tag
;
15998 child_die
= sibling_die (child_die
))
16001 size
= (sizeof (struct common_block
)
16002 + (n_entries
- 1) * sizeof (struct symbol
*));
16004 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16006 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16007 common_block
->n_entries
= 0;
16009 for (child_die
= die
->child
;
16010 child_die
&& child_die
->tag
;
16011 child_die
= sibling_die (child_die
))
16013 /* Create the symbol in the DW_TAG_common_block block in the current
16015 sym
= new_symbol (child_die
, NULL
, cu
);
16018 struct attribute
*member_loc
;
16020 common_block
->contents
[common_block
->n_entries
++] = sym
;
16022 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16026 /* GDB has handled this for a long time, but it is
16027 not specified by DWARF. It seems to have been
16028 emitted by gfortran at least as recently as:
16029 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16030 complaint (_("Variable in common block has "
16031 "DW_AT_data_member_location "
16032 "- DIE at %s [in module %s]"),
16033 sect_offset_str (child_die
->sect_off
),
16034 objfile_name (objfile
));
16036 if (member_loc
->form_is_section_offset ())
16037 dwarf2_complex_location_expr_complaint ();
16038 else if (member_loc
->form_is_constant ()
16039 || member_loc
->form_is_block ())
16041 if (attr
!= nullptr)
16042 mark_common_block_symbol_computed (sym
, die
, attr
,
16046 dwarf2_complex_location_expr_complaint ();
16051 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16052 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16056 /* Create a type for a C++ namespace. */
16058 static struct type
*
16059 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16061 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16062 const char *previous_prefix
, *name
;
16066 /* For extensions, reuse the type of the original namespace. */
16067 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16069 struct die_info
*ext_die
;
16070 struct dwarf2_cu
*ext_cu
= cu
;
16072 ext_die
= dwarf2_extension (die
, &ext_cu
);
16073 type
= read_type_die (ext_die
, ext_cu
);
16075 /* EXT_CU may not be the same as CU.
16076 Ensure TYPE is recorded with CU in die_type_hash. */
16077 return set_die_type (die
, type
, cu
);
16080 name
= namespace_name (die
, &is_anonymous
, cu
);
16082 /* Now build the name of the current namespace. */
16084 previous_prefix
= determine_prefix (die
, cu
);
16085 if (previous_prefix
[0] != '\0')
16086 name
= typename_concat (&objfile
->objfile_obstack
,
16087 previous_prefix
, name
, 0, cu
);
16089 /* Create the type. */
16090 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16092 return set_die_type (die
, type
, cu
);
16095 /* Read a namespace scope. */
16098 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16100 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16103 /* Add a symbol associated to this if we haven't seen the namespace
16104 before. Also, add a using directive if it's an anonymous
16107 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16111 type
= read_type_die (die
, cu
);
16112 new_symbol (die
, type
, cu
);
16114 namespace_name (die
, &is_anonymous
, cu
);
16117 const char *previous_prefix
= determine_prefix (die
, cu
);
16119 std::vector
<const char *> excludes
;
16120 add_using_directive (using_directives (cu
),
16121 previous_prefix
, TYPE_NAME (type
), NULL
,
16122 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16126 if (die
->child
!= NULL
)
16128 struct die_info
*child_die
= die
->child
;
16130 while (child_die
&& child_die
->tag
)
16132 process_die (child_die
, cu
);
16133 child_die
= sibling_die (child_die
);
16138 /* Read a Fortran module as type. This DIE can be only a declaration used for
16139 imported module. Still we need that type as local Fortran "use ... only"
16140 declaration imports depend on the created type in determine_prefix. */
16142 static struct type
*
16143 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16145 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16146 const char *module_name
;
16149 module_name
= dwarf2_name (die
, cu
);
16150 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16152 return set_die_type (die
, type
, cu
);
16155 /* Read a Fortran module. */
16158 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16160 struct die_info
*child_die
= die
->child
;
16163 type
= read_type_die (die
, cu
);
16164 new_symbol (die
, type
, cu
);
16166 while (child_die
&& child_die
->tag
)
16168 process_die (child_die
, cu
);
16169 child_die
= sibling_die (child_die
);
16173 /* Return the name of the namespace represented by DIE. Set
16174 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16177 static const char *
16178 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16180 struct die_info
*current_die
;
16181 const char *name
= NULL
;
16183 /* Loop through the extensions until we find a name. */
16185 for (current_die
= die
;
16186 current_die
!= NULL
;
16187 current_die
= dwarf2_extension (die
, &cu
))
16189 /* We don't use dwarf2_name here so that we can detect the absence
16190 of a name -> anonymous namespace. */
16191 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16197 /* Is it an anonymous namespace? */
16199 *is_anonymous
= (name
== NULL
);
16201 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16206 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16207 the user defined type vector. */
16209 static struct type
*
16210 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16212 struct gdbarch
*gdbarch
16213 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16214 struct comp_unit_head
*cu_header
= &cu
->header
;
16216 struct attribute
*attr_byte_size
;
16217 struct attribute
*attr_address_class
;
16218 int byte_size
, addr_class
;
16219 struct type
*target_type
;
16221 target_type
= die_type (die
, cu
);
16223 /* The die_type call above may have already set the type for this DIE. */
16224 type
= get_die_type (die
, cu
);
16228 type
= lookup_pointer_type (target_type
);
16230 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16231 if (attr_byte_size
)
16232 byte_size
= DW_UNSND (attr_byte_size
);
16234 byte_size
= cu_header
->addr_size
;
16236 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16237 if (attr_address_class
)
16238 addr_class
= DW_UNSND (attr_address_class
);
16240 addr_class
= DW_ADDR_none
;
16242 ULONGEST alignment
= get_alignment (cu
, die
);
16244 /* If the pointer size, alignment, or address class is different
16245 than the default, create a type variant marked as such and set
16246 the length accordingly. */
16247 if (TYPE_LENGTH (type
) != byte_size
16248 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16249 && alignment
!= TYPE_RAW_ALIGN (type
))
16250 || addr_class
!= DW_ADDR_none
)
16252 if (gdbarch_address_class_type_flags_p (gdbarch
))
16256 type_flags
= gdbarch_address_class_type_flags
16257 (gdbarch
, byte_size
, addr_class
);
16258 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16260 type
= make_type_with_address_space (type
, type_flags
);
16262 else if (TYPE_LENGTH (type
) != byte_size
)
16264 complaint (_("invalid pointer size %d"), byte_size
);
16266 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16268 complaint (_("Invalid DW_AT_alignment"
16269 " - DIE at %s [in module %s]"),
16270 sect_offset_str (die
->sect_off
),
16271 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16275 /* Should we also complain about unhandled address classes? */
16279 TYPE_LENGTH (type
) = byte_size
;
16280 set_type_align (type
, alignment
);
16281 return set_die_type (die
, type
, cu
);
16284 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16285 the user defined type vector. */
16287 static struct type
*
16288 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16291 struct type
*to_type
;
16292 struct type
*domain
;
16294 to_type
= die_type (die
, cu
);
16295 domain
= die_containing_type (die
, cu
);
16297 /* The calls above may have already set the type for this DIE. */
16298 type
= get_die_type (die
, cu
);
16302 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16303 type
= lookup_methodptr_type (to_type
);
16304 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16306 struct type
*new_type
16307 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16309 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16310 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16311 TYPE_VARARGS (to_type
));
16312 type
= lookup_methodptr_type (new_type
);
16315 type
= lookup_memberptr_type (to_type
, domain
);
16317 return set_die_type (die
, type
, cu
);
16320 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16321 the user defined type vector. */
16323 static struct type
*
16324 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16325 enum type_code refcode
)
16327 struct comp_unit_head
*cu_header
= &cu
->header
;
16328 struct type
*type
, *target_type
;
16329 struct attribute
*attr
;
16331 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16333 target_type
= die_type (die
, cu
);
16335 /* The die_type call above may have already set the type for this DIE. */
16336 type
= get_die_type (die
, cu
);
16340 type
= lookup_reference_type (target_type
, refcode
);
16341 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16342 if (attr
!= nullptr)
16344 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16348 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16350 maybe_set_alignment (cu
, die
, type
);
16351 return set_die_type (die
, type
, cu
);
16354 /* Add the given cv-qualifiers to the element type of the array. GCC
16355 outputs DWARF type qualifiers that apply to an array, not the
16356 element type. But GDB relies on the array element type to carry
16357 the cv-qualifiers. This mimics section 6.7.3 of the C99
16360 static struct type
*
16361 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16362 struct type
*base_type
, int cnst
, int voltl
)
16364 struct type
*el_type
, *inner_array
;
16366 base_type
= copy_type (base_type
);
16367 inner_array
= base_type
;
16369 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16371 TYPE_TARGET_TYPE (inner_array
) =
16372 copy_type (TYPE_TARGET_TYPE (inner_array
));
16373 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16376 el_type
= TYPE_TARGET_TYPE (inner_array
);
16377 cnst
|= TYPE_CONST (el_type
);
16378 voltl
|= TYPE_VOLATILE (el_type
);
16379 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16381 return set_die_type (die
, base_type
, cu
);
16384 static struct type
*
16385 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16387 struct type
*base_type
, *cv_type
;
16389 base_type
= die_type (die
, cu
);
16391 /* The die_type call above may have already set the type for this DIE. */
16392 cv_type
= get_die_type (die
, cu
);
16396 /* In case the const qualifier is applied to an array type, the element type
16397 is so qualified, not the array type (section 6.7.3 of C99). */
16398 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16399 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16401 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16402 return set_die_type (die
, cv_type
, cu
);
16405 static struct type
*
16406 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16408 struct type
*base_type
, *cv_type
;
16410 base_type
= die_type (die
, cu
);
16412 /* The die_type call above may have already set the type for this DIE. */
16413 cv_type
= get_die_type (die
, cu
);
16417 /* In case the volatile qualifier is applied to an array type, the
16418 element type is so qualified, not the array type (section 6.7.3
16420 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16421 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16423 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16424 return set_die_type (die
, cv_type
, cu
);
16427 /* Handle DW_TAG_restrict_type. */
16429 static struct type
*
16430 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16432 struct type
*base_type
, *cv_type
;
16434 base_type
= die_type (die
, cu
);
16436 /* The die_type call above may have already set the type for this DIE. */
16437 cv_type
= get_die_type (die
, cu
);
16441 cv_type
= make_restrict_type (base_type
);
16442 return set_die_type (die
, cv_type
, cu
);
16445 /* Handle DW_TAG_atomic_type. */
16447 static struct type
*
16448 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16450 struct type
*base_type
, *cv_type
;
16452 base_type
= die_type (die
, cu
);
16454 /* The die_type call above may have already set the type for this DIE. */
16455 cv_type
= get_die_type (die
, cu
);
16459 cv_type
= make_atomic_type (base_type
);
16460 return set_die_type (die
, cv_type
, cu
);
16463 /* Extract all information from a DW_TAG_string_type DIE and add to
16464 the user defined type vector. It isn't really a user defined type,
16465 but it behaves like one, with other DIE's using an AT_user_def_type
16466 attribute to reference it. */
16468 static struct type
*
16469 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16471 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16472 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16473 struct type
*type
, *range_type
, *index_type
, *char_type
;
16474 struct attribute
*attr
;
16475 struct dynamic_prop prop
;
16476 bool length_is_constant
= true;
16479 /* There are a couple of places where bit sizes might be made use of
16480 when parsing a DW_TAG_string_type, however, no producer that we know
16481 of make use of these. Handling bit sizes that are a multiple of the
16482 byte size is easy enough, but what about other bit sizes? Lets deal
16483 with that problem when we have to. Warn about these attributes being
16484 unsupported, then parse the type and ignore them like we always
16486 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16487 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16489 static bool warning_printed
= false;
16490 if (!warning_printed
)
16492 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16493 "currently supported on DW_TAG_string_type."));
16494 warning_printed
= true;
16498 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16499 if (attr
!= nullptr && !attr
->form_is_constant ())
16501 /* The string length describes the location at which the length of
16502 the string can be found. The size of the length field can be
16503 specified with one of the attributes below. */
16504 struct type
*prop_type
;
16505 struct attribute
*len
16506 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16507 if (len
== nullptr)
16508 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16509 if (len
!= nullptr && len
->form_is_constant ())
16511 /* Pass 0 as the default as we know this attribute is constant
16512 and the default value will not be returned. */
16513 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16514 prop_type
= cu
->per_cu
->int_type (sz
, true);
16518 /* If the size is not specified then we assume it is the size of
16519 an address on this target. */
16520 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16523 /* Convert the attribute into a dynamic property. */
16524 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16527 length_is_constant
= false;
16529 else if (attr
!= nullptr)
16531 /* This DW_AT_string_length just contains the length with no
16532 indirection. There's no need to create a dynamic property in this
16533 case. Pass 0 for the default value as we know it will not be
16534 returned in this case. */
16535 length
= dwarf2_get_attr_constant_value (attr
, 0);
16537 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16539 /* We don't currently support non-constant byte sizes for strings. */
16540 length
= dwarf2_get_attr_constant_value (attr
, 1);
16544 /* Use 1 as a fallback length if we have nothing else. */
16548 index_type
= objfile_type (objfile
)->builtin_int
;
16549 if (length_is_constant
)
16550 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16553 struct dynamic_prop low_bound
;
16555 low_bound
.kind
= PROP_CONST
;
16556 low_bound
.data
.const_val
= 1;
16557 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16559 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16560 type
= create_string_type (NULL
, char_type
, range_type
);
16562 return set_die_type (die
, type
, cu
);
16565 /* Assuming that DIE corresponds to a function, returns nonzero
16566 if the function is prototyped. */
16569 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16571 struct attribute
*attr
;
16573 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16574 if (attr
&& (DW_UNSND (attr
) != 0))
16577 /* The DWARF standard implies that the DW_AT_prototyped attribute
16578 is only meaningful for C, but the concept also extends to other
16579 languages that allow unprototyped functions (Eg: Objective C).
16580 For all other languages, assume that functions are always
16582 if (cu
->language
!= language_c
16583 && cu
->language
!= language_objc
16584 && cu
->language
!= language_opencl
)
16587 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16588 prototyped and unprototyped functions; default to prototyped,
16589 since that is more common in modern code (and RealView warns
16590 about unprototyped functions). */
16591 if (producer_is_realview (cu
->producer
))
16597 /* Handle DIES due to C code like:
16601 int (*funcp)(int a, long l);
16605 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16607 static struct type
*
16608 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16610 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16611 struct type
*type
; /* Type that this function returns. */
16612 struct type
*ftype
; /* Function that returns above type. */
16613 struct attribute
*attr
;
16615 type
= die_type (die
, cu
);
16617 /* The die_type call above may have already set the type for this DIE. */
16618 ftype
= get_die_type (die
, cu
);
16622 ftype
= lookup_function_type (type
);
16624 if (prototyped_function_p (die
, cu
))
16625 TYPE_PROTOTYPED (ftype
) = 1;
16627 /* Store the calling convention in the type if it's available in
16628 the subroutine die. Otherwise set the calling convention to
16629 the default value DW_CC_normal. */
16630 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16631 if (attr
!= nullptr
16632 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16633 TYPE_CALLING_CONVENTION (ftype
)
16634 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16635 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16636 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16638 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16640 /* Record whether the function returns normally to its caller or not
16641 if the DWARF producer set that information. */
16642 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16643 if (attr
&& (DW_UNSND (attr
) != 0))
16644 TYPE_NO_RETURN (ftype
) = 1;
16646 /* We need to add the subroutine type to the die immediately so
16647 we don't infinitely recurse when dealing with parameters
16648 declared as the same subroutine type. */
16649 set_die_type (die
, ftype
, cu
);
16651 if (die
->child
!= NULL
)
16653 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16654 struct die_info
*child_die
;
16655 int nparams
, iparams
;
16657 /* Count the number of parameters.
16658 FIXME: GDB currently ignores vararg functions, but knows about
16659 vararg member functions. */
16661 child_die
= die
->child
;
16662 while (child_die
&& child_die
->tag
)
16664 if (child_die
->tag
== DW_TAG_formal_parameter
)
16666 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16667 TYPE_VARARGS (ftype
) = 1;
16668 child_die
= sibling_die (child_die
);
16671 /* Allocate storage for parameters and fill them in. */
16672 TYPE_NFIELDS (ftype
) = nparams
;
16673 TYPE_FIELDS (ftype
) = (struct field
*)
16674 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16676 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16677 even if we error out during the parameters reading below. */
16678 for (iparams
= 0; iparams
< nparams
; iparams
++)
16679 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16682 child_die
= die
->child
;
16683 while (child_die
&& child_die
->tag
)
16685 if (child_die
->tag
== DW_TAG_formal_parameter
)
16687 struct type
*arg_type
;
16689 /* DWARF version 2 has no clean way to discern C++
16690 static and non-static member functions. G++ helps
16691 GDB by marking the first parameter for non-static
16692 member functions (which is the this pointer) as
16693 artificial. We pass this information to
16694 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16696 DWARF version 3 added DW_AT_object_pointer, which GCC
16697 4.5 does not yet generate. */
16698 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16699 if (attr
!= nullptr)
16700 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16702 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16703 arg_type
= die_type (child_die
, cu
);
16705 /* RealView does not mark THIS as const, which the testsuite
16706 expects. GCC marks THIS as const in method definitions,
16707 but not in the class specifications (GCC PR 43053). */
16708 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16709 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16712 struct dwarf2_cu
*arg_cu
= cu
;
16713 const char *name
= dwarf2_name (child_die
, cu
);
16715 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16716 if (attr
!= nullptr)
16718 /* If the compiler emits this, use it. */
16719 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16722 else if (name
&& strcmp (name
, "this") == 0)
16723 /* Function definitions will have the argument names. */
16725 else if (name
== NULL
&& iparams
== 0)
16726 /* Declarations may not have the names, so like
16727 elsewhere in GDB, assume an artificial first
16728 argument is "this". */
16732 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16736 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16739 child_die
= sibling_die (child_die
);
16746 static struct type
*
16747 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16749 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16750 const char *name
= NULL
;
16751 struct type
*this_type
, *target_type
;
16753 name
= dwarf2_full_name (NULL
, die
, cu
);
16754 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16755 TYPE_TARGET_STUB (this_type
) = 1;
16756 set_die_type (die
, this_type
, cu
);
16757 target_type
= die_type (die
, cu
);
16758 if (target_type
!= this_type
)
16759 TYPE_TARGET_TYPE (this_type
) = target_type
;
16762 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16763 spec and cause infinite loops in GDB. */
16764 complaint (_("Self-referential DW_TAG_typedef "
16765 "- DIE at %s [in module %s]"),
16766 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16767 TYPE_TARGET_TYPE (this_type
) = NULL
;
16771 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16772 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16773 Handle these by just returning the target type, rather than
16774 constructing an anonymous typedef type and trying to handle this
16776 set_die_type (die
, target_type
, cu
);
16777 return target_type
;
16782 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16783 (which may be different from NAME) to the architecture back-end to allow
16784 it to guess the correct format if necessary. */
16786 static struct type
*
16787 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16788 const char *name_hint
, enum bfd_endian byte_order
)
16790 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16791 const struct floatformat
**format
;
16794 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16796 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16798 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16803 /* Allocate an integer type of size BITS and name NAME. */
16805 static struct type
*
16806 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16807 int bits
, int unsigned_p
, const char *name
)
16811 /* Versions of Intel's C Compiler generate an integer type called "void"
16812 instead of using DW_TAG_unspecified_type. This has been seen on
16813 at least versions 14, 17, and 18. */
16814 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16815 && strcmp (name
, "void") == 0)
16816 type
= objfile_type (objfile
)->builtin_void
;
16818 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16823 /* Initialise and return a floating point type of size BITS suitable for
16824 use as a component of a complex number. The NAME_HINT is passed through
16825 when initialising the floating point type and is the name of the complex
16828 As DWARF doesn't currently provide an explicit name for the components
16829 of a complex number, but it can be helpful to have these components
16830 named, we try to select a suitable name based on the size of the
16832 static struct type
*
16833 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16834 struct objfile
*objfile
,
16835 int bits
, const char *name_hint
,
16836 enum bfd_endian byte_order
)
16838 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16839 struct type
*tt
= nullptr;
16841 /* Try to find a suitable floating point builtin type of size BITS.
16842 We're going to use the name of this type as the name for the complex
16843 target type that we are about to create. */
16844 switch (cu
->language
)
16846 case language_fortran
:
16850 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16853 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16855 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16857 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16865 tt
= builtin_type (gdbarch
)->builtin_float
;
16868 tt
= builtin_type (gdbarch
)->builtin_double
;
16870 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16872 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16878 /* If the type we found doesn't match the size we were looking for, then
16879 pretend we didn't find a type at all, the complex target type we
16880 create will then be nameless. */
16881 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16884 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16885 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16888 /* Find a representation of a given base type and install
16889 it in the TYPE field of the die. */
16891 static struct type
*
16892 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16894 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16896 struct attribute
*attr
;
16897 int encoding
= 0, bits
= 0;
16901 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16902 if (attr
!= nullptr)
16903 encoding
= DW_UNSND (attr
);
16904 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16905 if (attr
!= nullptr)
16906 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16907 name
= dwarf2_name (die
, cu
);
16909 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16911 arch
= get_objfile_arch (objfile
);
16912 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16914 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16917 int endianity
= DW_UNSND (attr
);
16922 byte_order
= BFD_ENDIAN_BIG
;
16924 case DW_END_little
:
16925 byte_order
= BFD_ENDIAN_LITTLE
;
16928 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16935 case DW_ATE_address
:
16936 /* Turn DW_ATE_address into a void * pointer. */
16937 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16938 type
= init_pointer_type (objfile
, bits
, name
, type
);
16940 case DW_ATE_boolean
:
16941 type
= init_boolean_type (objfile
, bits
, 1, name
);
16943 case DW_ATE_complex_float
:
16944 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16946 type
= init_complex_type (objfile
, name
, type
);
16948 case DW_ATE_decimal_float
:
16949 type
= init_decfloat_type (objfile
, bits
, name
);
16952 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16954 case DW_ATE_signed
:
16955 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16957 case DW_ATE_unsigned
:
16958 if (cu
->language
== language_fortran
16960 && startswith (name
, "character("))
16961 type
= init_character_type (objfile
, bits
, 1, name
);
16963 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16965 case DW_ATE_signed_char
:
16966 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16967 || cu
->language
== language_pascal
16968 || cu
->language
== language_fortran
)
16969 type
= init_character_type (objfile
, bits
, 0, name
);
16971 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16973 case DW_ATE_unsigned_char
:
16974 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16975 || cu
->language
== language_pascal
16976 || cu
->language
== language_fortran
16977 || cu
->language
== language_rust
)
16978 type
= init_character_type (objfile
, bits
, 1, name
);
16980 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16985 type
= builtin_type (arch
)->builtin_char16
;
16986 else if (bits
== 32)
16987 type
= builtin_type (arch
)->builtin_char32
;
16990 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
16992 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16994 return set_die_type (die
, type
, cu
);
16999 complaint (_("unsupported DW_AT_encoding: '%s'"),
17000 dwarf_type_encoding_name (encoding
));
17001 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17005 if (name
&& strcmp (name
, "char") == 0)
17006 TYPE_NOSIGN (type
) = 1;
17008 maybe_set_alignment (cu
, die
, type
);
17010 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17012 return set_die_type (die
, type
, cu
);
17015 /* Parse dwarf attribute if it's a block, reference or constant and put the
17016 resulting value of the attribute into struct bound_prop.
17017 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17020 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17021 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17022 struct type
*default_type
)
17024 struct dwarf2_property_baton
*baton
;
17025 struct obstack
*obstack
17026 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17028 gdb_assert (default_type
!= NULL
);
17030 if (attr
== NULL
|| prop
== NULL
)
17033 if (attr
->form_is_block ())
17035 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17036 baton
->property_type
= default_type
;
17037 baton
->locexpr
.per_cu
= cu
->per_cu
;
17038 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17039 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17040 switch (attr
->name
)
17042 case DW_AT_string_length
:
17043 baton
->locexpr
.is_reference
= true;
17046 baton
->locexpr
.is_reference
= false;
17049 prop
->data
.baton
= baton
;
17050 prop
->kind
= PROP_LOCEXPR
;
17051 gdb_assert (prop
->data
.baton
!= NULL
);
17053 else if (attr
->form_is_ref ())
17055 struct dwarf2_cu
*target_cu
= cu
;
17056 struct die_info
*target_die
;
17057 struct attribute
*target_attr
;
17059 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17060 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17061 if (target_attr
== NULL
)
17062 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17064 if (target_attr
== NULL
)
17067 switch (target_attr
->name
)
17069 case DW_AT_location
:
17070 if (target_attr
->form_is_section_offset ())
17072 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17073 baton
->property_type
= die_type (target_die
, target_cu
);
17074 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17075 prop
->data
.baton
= baton
;
17076 prop
->kind
= PROP_LOCLIST
;
17077 gdb_assert (prop
->data
.baton
!= NULL
);
17079 else if (target_attr
->form_is_block ())
17081 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17082 baton
->property_type
= die_type (target_die
, target_cu
);
17083 baton
->locexpr
.per_cu
= cu
->per_cu
;
17084 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17085 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17086 baton
->locexpr
.is_reference
= true;
17087 prop
->data
.baton
= baton
;
17088 prop
->kind
= PROP_LOCEXPR
;
17089 gdb_assert (prop
->data
.baton
!= NULL
);
17093 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17094 "dynamic property");
17098 case DW_AT_data_member_location
:
17102 if (!handle_data_member_location (target_die
, target_cu
,
17106 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17107 baton
->property_type
= read_type_die (target_die
->parent
,
17109 baton
->offset_info
.offset
= offset
;
17110 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17111 prop
->data
.baton
= baton
;
17112 prop
->kind
= PROP_ADDR_OFFSET
;
17117 else if (attr
->form_is_constant ())
17119 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17120 prop
->kind
= PROP_CONST
;
17124 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17125 dwarf2_name (die
, cu
));
17135 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17137 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17138 struct type
*int_type
;
17140 /* Helper macro to examine the various builtin types. */
17141 #define TRY_TYPE(F) \
17142 int_type = (unsigned_p \
17143 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17144 : objfile_type (objfile)->builtin_ ## F); \
17145 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17152 TRY_TYPE (long_long
);
17156 gdb_assert_not_reached ("unable to find suitable integer type");
17162 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17164 int addr_size
= this->addr_size ();
17165 return int_type (addr_size
, unsigned_p
);
17168 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17169 present (which is valid) then compute the default type based on the
17170 compilation units address size. */
17172 static struct type
*
17173 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17175 struct type
*index_type
= die_type (die
, cu
);
17177 /* Dwarf-2 specifications explicitly allows to create subrange types
17178 without specifying a base type.
17179 In that case, the base type must be set to the type of
17180 the lower bound, upper bound or count, in that order, if any of these
17181 three attributes references an object that has a type.
17182 If no base type is found, the Dwarf-2 specifications say that
17183 a signed integer type of size equal to the size of an address should
17185 For the following C code: `extern char gdb_int [];'
17186 GCC produces an empty range DIE.
17187 FIXME: muller/2010-05-28: Possible references to object for low bound,
17188 high bound or count are not yet handled by this code. */
17189 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17190 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17195 /* Read the given DW_AT_subrange DIE. */
17197 static struct type
*
17198 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17200 struct type
*base_type
, *orig_base_type
;
17201 struct type
*range_type
;
17202 struct attribute
*attr
;
17203 struct dynamic_prop low
, high
;
17204 int low_default_is_valid
;
17205 int high_bound_is_count
= 0;
17207 ULONGEST negative_mask
;
17209 orig_base_type
= read_subrange_index_type (die
, cu
);
17211 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17212 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17213 creating the range type, but we use the result of check_typedef
17214 when examining properties of the type. */
17215 base_type
= check_typedef (orig_base_type
);
17217 /* The die_type call above may have already set the type for this DIE. */
17218 range_type
= get_die_type (die
, cu
);
17222 low
.kind
= PROP_CONST
;
17223 high
.kind
= PROP_CONST
;
17224 high
.data
.const_val
= 0;
17226 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17227 omitting DW_AT_lower_bound. */
17228 switch (cu
->language
)
17231 case language_cplus
:
17232 low
.data
.const_val
= 0;
17233 low_default_is_valid
= 1;
17235 case language_fortran
:
17236 low
.data
.const_val
= 1;
17237 low_default_is_valid
= 1;
17240 case language_objc
:
17241 case language_rust
:
17242 low
.data
.const_val
= 0;
17243 low_default_is_valid
= (cu
->header
.version
>= 4);
17247 case language_pascal
:
17248 low
.data
.const_val
= 1;
17249 low_default_is_valid
= (cu
->header
.version
>= 4);
17252 low
.data
.const_val
= 0;
17253 low_default_is_valid
= 0;
17257 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17258 if (attr
!= nullptr)
17259 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17260 else if (!low_default_is_valid
)
17261 complaint (_("Missing DW_AT_lower_bound "
17262 "- DIE at %s [in module %s]"),
17263 sect_offset_str (die
->sect_off
),
17264 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17266 struct attribute
*attr_ub
, *attr_count
;
17267 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17268 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17270 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17271 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17273 /* If bounds are constant do the final calculation here. */
17274 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17275 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17277 high_bound_is_count
= 1;
17281 if (attr_ub
!= NULL
)
17282 complaint (_("Unresolved DW_AT_upper_bound "
17283 "- DIE at %s [in module %s]"),
17284 sect_offset_str (die
->sect_off
),
17285 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17286 if (attr_count
!= NULL
)
17287 complaint (_("Unresolved DW_AT_count "
17288 "- DIE at %s [in module %s]"),
17289 sect_offset_str (die
->sect_off
),
17290 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17295 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17296 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17297 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17299 /* Normally, the DWARF producers are expected to use a signed
17300 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17301 But this is unfortunately not always the case, as witnessed
17302 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17303 is used instead. To work around that ambiguity, we treat
17304 the bounds as signed, and thus sign-extend their values, when
17305 the base type is signed. */
17307 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17308 if (low
.kind
== PROP_CONST
17309 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17310 low
.data
.const_val
|= negative_mask
;
17311 if (high
.kind
== PROP_CONST
17312 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17313 high
.data
.const_val
|= negative_mask
;
17315 /* Check for bit and byte strides. */
17316 struct dynamic_prop byte_stride_prop
;
17317 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17318 if (attr_byte_stride
!= nullptr)
17320 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17321 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17325 struct dynamic_prop bit_stride_prop
;
17326 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17327 if (attr_bit_stride
!= nullptr)
17329 /* It only makes sense to have either a bit or byte stride. */
17330 if (attr_byte_stride
!= nullptr)
17332 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17333 "- DIE at %s [in module %s]"),
17334 sect_offset_str (die
->sect_off
),
17335 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17336 attr_bit_stride
= nullptr;
17340 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17341 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17346 if (attr_byte_stride
!= nullptr
17347 || attr_bit_stride
!= nullptr)
17349 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17350 struct dynamic_prop
*stride
17351 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17354 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17355 &high
, bias
, stride
, byte_stride_p
);
17358 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17360 if (high_bound_is_count
)
17361 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17363 /* Ada expects an empty array on no boundary attributes. */
17364 if (attr
== NULL
&& cu
->language
!= language_ada
)
17365 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17367 name
= dwarf2_name (die
, cu
);
17369 TYPE_NAME (range_type
) = name
;
17371 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17372 if (attr
!= nullptr)
17373 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17375 maybe_set_alignment (cu
, die
, range_type
);
17377 set_die_type (die
, range_type
, cu
);
17379 /* set_die_type should be already done. */
17380 set_descriptive_type (range_type
, die
, cu
);
17385 static struct type
*
17386 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17390 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17392 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17394 /* In Ada, an unspecified type is typically used when the description
17395 of the type is deferred to a different unit. When encountering
17396 such a type, we treat it as a stub, and try to resolve it later on,
17398 if (cu
->language
== language_ada
)
17399 TYPE_STUB (type
) = 1;
17401 return set_die_type (die
, type
, cu
);
17404 /* Read a single die and all its descendents. Set the die's sibling
17405 field to NULL; set other fields in the die correctly, and set all
17406 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17407 location of the info_ptr after reading all of those dies. PARENT
17408 is the parent of the die in question. */
17410 static struct die_info
*
17411 read_die_and_children (const struct die_reader_specs
*reader
,
17412 const gdb_byte
*info_ptr
,
17413 const gdb_byte
**new_info_ptr
,
17414 struct die_info
*parent
)
17416 struct die_info
*die
;
17417 const gdb_byte
*cur_ptr
;
17419 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17422 *new_info_ptr
= cur_ptr
;
17425 store_in_ref_table (die
, reader
->cu
);
17427 if (die
->has_children
)
17428 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17432 *new_info_ptr
= cur_ptr
;
17435 die
->sibling
= NULL
;
17436 die
->parent
= parent
;
17440 /* Read a die, all of its descendents, and all of its siblings; set
17441 all of the fields of all of the dies correctly. Arguments are as
17442 in read_die_and_children. */
17444 static struct die_info
*
17445 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17446 const gdb_byte
*info_ptr
,
17447 const gdb_byte
**new_info_ptr
,
17448 struct die_info
*parent
)
17450 struct die_info
*first_die
, *last_sibling
;
17451 const gdb_byte
*cur_ptr
;
17453 cur_ptr
= info_ptr
;
17454 first_die
= last_sibling
= NULL
;
17458 struct die_info
*die
17459 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17463 *new_info_ptr
= cur_ptr
;
17470 last_sibling
->sibling
= die
;
17472 last_sibling
= die
;
17476 /* Read a die, all of its descendents, and all of its siblings; set
17477 all of the fields of all of the dies correctly. Arguments are as
17478 in read_die_and_children.
17479 This the main entry point for reading a DIE and all its children. */
17481 static struct die_info
*
17482 read_die_and_siblings (const struct die_reader_specs
*reader
,
17483 const gdb_byte
*info_ptr
,
17484 const gdb_byte
**new_info_ptr
,
17485 struct die_info
*parent
)
17487 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17488 new_info_ptr
, parent
);
17490 if (dwarf_die_debug
)
17492 fprintf_unfiltered (gdb_stdlog
,
17493 "Read die from %s@0x%x of %s:\n",
17494 reader
->die_section
->get_name (),
17495 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17496 bfd_get_filename (reader
->abfd
));
17497 dump_die (die
, dwarf_die_debug
);
17503 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17505 The caller is responsible for filling in the extra attributes
17506 and updating (*DIEP)->num_attrs.
17507 Set DIEP to point to a newly allocated die with its information,
17508 except for its child, sibling, and parent fields. */
17510 static const gdb_byte
*
17511 read_full_die_1 (const struct die_reader_specs
*reader
,
17512 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17513 int num_extra_attrs
)
17515 unsigned int abbrev_number
, bytes_read
, i
;
17516 struct abbrev_info
*abbrev
;
17517 struct die_info
*die
;
17518 struct dwarf2_cu
*cu
= reader
->cu
;
17519 bfd
*abfd
= reader
->abfd
;
17521 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17522 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17523 info_ptr
+= bytes_read
;
17524 if (!abbrev_number
)
17530 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17532 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17534 bfd_get_filename (abfd
));
17536 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17537 die
->sect_off
= sect_off
;
17538 die
->tag
= abbrev
->tag
;
17539 die
->abbrev
= abbrev_number
;
17540 die
->has_children
= abbrev
->has_children
;
17542 /* Make the result usable.
17543 The caller needs to update num_attrs after adding the extra
17545 die
->num_attrs
= abbrev
->num_attrs
;
17547 std::vector
<int> indexes_that_need_reprocess
;
17548 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17550 bool need_reprocess
;
17552 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17553 info_ptr
, &need_reprocess
);
17554 if (need_reprocess
)
17555 indexes_that_need_reprocess
.push_back (i
);
17558 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17559 if (attr
!= nullptr)
17560 cu
->str_offsets_base
= DW_UNSND (attr
);
17562 auto maybe_addr_base
= lookup_addr_base(die
);
17563 if (maybe_addr_base
.has_value ())
17564 cu
->addr_base
= *maybe_addr_base
;
17565 for (int index
: indexes_that_need_reprocess
)
17566 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17571 /* Read a die and all its attributes.
17572 Set DIEP to point to a newly allocated die with its information,
17573 except for its child, sibling, and parent fields. */
17575 static const gdb_byte
*
17576 read_full_die (const struct die_reader_specs
*reader
,
17577 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17579 const gdb_byte
*result
;
17581 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17583 if (dwarf_die_debug
)
17585 fprintf_unfiltered (gdb_stdlog
,
17586 "Read die from %s@0x%x of %s:\n",
17587 reader
->die_section
->get_name (),
17588 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17589 bfd_get_filename (reader
->abfd
));
17590 dump_die (*diep
, dwarf_die_debug
);
17597 /* Returns nonzero if TAG represents a type that we might generate a partial
17601 is_type_tag_for_partial (int tag
)
17606 /* Some types that would be reasonable to generate partial symbols for,
17607 that we don't at present. */
17608 case DW_TAG_array_type
:
17609 case DW_TAG_file_type
:
17610 case DW_TAG_ptr_to_member_type
:
17611 case DW_TAG_set_type
:
17612 case DW_TAG_string_type
:
17613 case DW_TAG_subroutine_type
:
17615 case DW_TAG_base_type
:
17616 case DW_TAG_class_type
:
17617 case DW_TAG_interface_type
:
17618 case DW_TAG_enumeration_type
:
17619 case DW_TAG_structure_type
:
17620 case DW_TAG_subrange_type
:
17621 case DW_TAG_typedef
:
17622 case DW_TAG_union_type
:
17629 /* Load all DIEs that are interesting for partial symbols into memory. */
17631 static struct partial_die_info
*
17632 load_partial_dies (const struct die_reader_specs
*reader
,
17633 const gdb_byte
*info_ptr
, int building_psymtab
)
17635 struct dwarf2_cu
*cu
= reader
->cu
;
17636 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17637 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17638 unsigned int bytes_read
;
17639 unsigned int load_all
= 0;
17640 int nesting_level
= 1;
17645 gdb_assert (cu
->per_cu
!= NULL
);
17646 if (cu
->per_cu
->load_all_dies
)
17650 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17654 &cu
->comp_unit_obstack
,
17655 hashtab_obstack_allocate
,
17656 dummy_obstack_deallocate
);
17660 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17662 /* A NULL abbrev means the end of a series of children. */
17663 if (abbrev
== NULL
)
17665 if (--nesting_level
== 0)
17668 info_ptr
+= bytes_read
;
17669 last_die
= parent_die
;
17670 parent_die
= parent_die
->die_parent
;
17674 /* Check for template arguments. We never save these; if
17675 they're seen, we just mark the parent, and go on our way. */
17676 if (parent_die
!= NULL
17677 && cu
->language
== language_cplus
17678 && (abbrev
->tag
== DW_TAG_template_type_param
17679 || abbrev
->tag
== DW_TAG_template_value_param
))
17681 parent_die
->has_template_arguments
= 1;
17685 /* We don't need a partial DIE for the template argument. */
17686 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17691 /* We only recurse into c++ subprograms looking for template arguments.
17692 Skip their other children. */
17694 && cu
->language
== language_cplus
17695 && parent_die
!= NULL
17696 && parent_die
->tag
== DW_TAG_subprogram
)
17698 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17702 /* Check whether this DIE is interesting enough to save. Normally
17703 we would not be interested in members here, but there may be
17704 later variables referencing them via DW_AT_specification (for
17705 static members). */
17707 && !is_type_tag_for_partial (abbrev
->tag
)
17708 && abbrev
->tag
!= DW_TAG_constant
17709 && abbrev
->tag
!= DW_TAG_enumerator
17710 && abbrev
->tag
!= DW_TAG_subprogram
17711 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17712 && abbrev
->tag
!= DW_TAG_lexical_block
17713 && abbrev
->tag
!= DW_TAG_variable
17714 && abbrev
->tag
!= DW_TAG_namespace
17715 && abbrev
->tag
!= DW_TAG_module
17716 && abbrev
->tag
!= DW_TAG_member
17717 && abbrev
->tag
!= DW_TAG_imported_unit
17718 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17720 /* Otherwise we skip to the next sibling, if any. */
17721 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17725 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17728 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17730 /* This two-pass algorithm for processing partial symbols has a
17731 high cost in cache pressure. Thus, handle some simple cases
17732 here which cover the majority of C partial symbols. DIEs
17733 which neither have specification tags in them, nor could have
17734 specification tags elsewhere pointing at them, can simply be
17735 processed and discarded.
17737 This segment is also optional; scan_partial_symbols and
17738 add_partial_symbol will handle these DIEs if we chain
17739 them in normally. When compilers which do not emit large
17740 quantities of duplicate debug information are more common,
17741 this code can probably be removed. */
17743 /* Any complete simple types at the top level (pretty much all
17744 of them, for a language without namespaces), can be processed
17746 if (parent_die
== NULL
17747 && pdi
.has_specification
== 0
17748 && pdi
.is_declaration
== 0
17749 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17750 || pdi
.tag
== DW_TAG_base_type
17751 || pdi
.tag
== DW_TAG_subrange_type
))
17753 if (building_psymtab
&& pdi
.name
!= NULL
)
17754 add_psymbol_to_list (pdi
.name
, false,
17755 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17756 psymbol_placement::STATIC
,
17757 0, cu
->language
, objfile
);
17758 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17762 /* The exception for DW_TAG_typedef with has_children above is
17763 a workaround of GCC PR debug/47510. In the case of this complaint
17764 type_name_or_error will error on such types later.
17766 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17767 it could not find the child DIEs referenced later, this is checked
17768 above. In correct DWARF DW_TAG_typedef should have no children. */
17770 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17771 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17772 "- DIE at %s [in module %s]"),
17773 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17775 /* If we're at the second level, and we're an enumerator, and
17776 our parent has no specification (meaning possibly lives in a
17777 namespace elsewhere), then we can add the partial symbol now
17778 instead of queueing it. */
17779 if (pdi
.tag
== DW_TAG_enumerator
17780 && parent_die
!= NULL
17781 && parent_die
->die_parent
== NULL
17782 && parent_die
->tag
== DW_TAG_enumeration_type
17783 && parent_die
->has_specification
== 0)
17785 if (pdi
.name
== NULL
)
17786 complaint (_("malformed enumerator DIE ignored"));
17787 else if (building_psymtab
)
17788 add_psymbol_to_list (pdi
.name
, false,
17789 VAR_DOMAIN
, LOC_CONST
, -1,
17790 cu
->language
== language_cplus
17791 ? psymbol_placement::GLOBAL
17792 : psymbol_placement::STATIC
,
17793 0, cu
->language
, objfile
);
17795 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17799 struct partial_die_info
*part_die
17800 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17802 /* We'll save this DIE so link it in. */
17803 part_die
->die_parent
= parent_die
;
17804 part_die
->die_sibling
= NULL
;
17805 part_die
->die_child
= NULL
;
17807 if (last_die
&& last_die
== parent_die
)
17808 last_die
->die_child
= part_die
;
17810 last_die
->die_sibling
= part_die
;
17812 last_die
= part_die
;
17814 if (first_die
== NULL
)
17815 first_die
= part_die
;
17817 /* Maybe add the DIE to the hash table. Not all DIEs that we
17818 find interesting need to be in the hash table, because we
17819 also have the parent/sibling/child chains; only those that we
17820 might refer to by offset later during partial symbol reading.
17822 For now this means things that might have be the target of a
17823 DW_AT_specification, DW_AT_abstract_origin, or
17824 DW_AT_extension. DW_AT_extension will refer only to
17825 namespaces; DW_AT_abstract_origin refers to functions (and
17826 many things under the function DIE, but we do not recurse
17827 into function DIEs during partial symbol reading) and
17828 possibly variables as well; DW_AT_specification refers to
17829 declarations. Declarations ought to have the DW_AT_declaration
17830 flag. It happens that GCC forgets to put it in sometimes, but
17831 only for functions, not for types.
17833 Adding more things than necessary to the hash table is harmless
17834 except for the performance cost. Adding too few will result in
17835 wasted time in find_partial_die, when we reread the compilation
17836 unit with load_all_dies set. */
17839 || abbrev
->tag
== DW_TAG_constant
17840 || abbrev
->tag
== DW_TAG_subprogram
17841 || abbrev
->tag
== DW_TAG_variable
17842 || abbrev
->tag
== DW_TAG_namespace
17843 || part_die
->is_declaration
)
17847 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17848 to_underlying (part_die
->sect_off
),
17853 /* For some DIEs we want to follow their children (if any). For C
17854 we have no reason to follow the children of structures; for other
17855 languages we have to, so that we can get at method physnames
17856 to infer fully qualified class names, for DW_AT_specification,
17857 and for C++ template arguments. For C++, we also look one level
17858 inside functions to find template arguments (if the name of the
17859 function does not already contain the template arguments).
17861 For Ada and Fortran, we need to scan the children of subprograms
17862 and lexical blocks as well because these languages allow the
17863 definition of nested entities that could be interesting for the
17864 debugger, such as nested subprograms for instance. */
17865 if (last_die
->has_children
17867 || last_die
->tag
== DW_TAG_namespace
17868 || last_die
->tag
== DW_TAG_module
17869 || last_die
->tag
== DW_TAG_enumeration_type
17870 || (cu
->language
== language_cplus
17871 && last_die
->tag
== DW_TAG_subprogram
17872 && (last_die
->name
== NULL
17873 || strchr (last_die
->name
, '<') == NULL
))
17874 || (cu
->language
!= language_c
17875 && (last_die
->tag
== DW_TAG_class_type
17876 || last_die
->tag
== DW_TAG_interface_type
17877 || last_die
->tag
== DW_TAG_structure_type
17878 || last_die
->tag
== DW_TAG_union_type
))
17879 || ((cu
->language
== language_ada
17880 || cu
->language
== language_fortran
)
17881 && (last_die
->tag
== DW_TAG_subprogram
17882 || last_die
->tag
== DW_TAG_lexical_block
))))
17885 parent_die
= last_die
;
17889 /* Otherwise we skip to the next sibling, if any. */
17890 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17892 /* Back to the top, do it again. */
17896 partial_die_info::partial_die_info (sect_offset sect_off_
,
17897 struct abbrev_info
*abbrev
)
17898 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17902 /* Read a minimal amount of information into the minimal die structure.
17903 INFO_PTR should point just after the initial uleb128 of a DIE. */
17906 partial_die_info::read (const struct die_reader_specs
*reader
,
17907 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17909 struct dwarf2_cu
*cu
= reader
->cu
;
17910 struct dwarf2_per_objfile
*dwarf2_per_objfile
17911 = cu
->per_cu
->dwarf2_per_objfile
;
17913 int has_low_pc_attr
= 0;
17914 int has_high_pc_attr
= 0;
17915 int high_pc_relative
= 0;
17917 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17918 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17920 bool need_reprocess
;
17921 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17922 info_ptr
, &need_reprocess
);
17923 /* String and address offsets that need to do the reprocessing have
17924 already been read at this point, so there is no need to wait until
17925 the loop terminates to do the reprocessing. */
17926 if (need_reprocess
)
17927 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17928 attribute
&attr
= attr_vec
[i
];
17929 /* Store the data if it is of an attribute we want to keep in a
17930 partial symbol table. */
17936 case DW_TAG_compile_unit
:
17937 case DW_TAG_partial_unit
:
17938 case DW_TAG_type_unit
:
17939 /* Compilation units have a DW_AT_name that is a filename, not
17940 a source language identifier. */
17941 case DW_TAG_enumeration_type
:
17942 case DW_TAG_enumerator
:
17943 /* These tags always have simple identifiers already; no need
17944 to canonicalize them. */
17945 name
= DW_STRING (&attr
);
17949 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17952 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
17957 case DW_AT_linkage_name
:
17958 case DW_AT_MIPS_linkage_name
:
17959 /* Note that both forms of linkage name might appear. We
17960 assume they will be the same, and we only store the last
17962 linkage_name
= DW_STRING (&attr
);
17965 has_low_pc_attr
= 1;
17966 lowpc
= attr
.value_as_address ();
17968 case DW_AT_high_pc
:
17969 has_high_pc_attr
= 1;
17970 highpc
= attr
.value_as_address ();
17971 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17972 high_pc_relative
= 1;
17974 case DW_AT_location
:
17975 /* Support the .debug_loc offsets. */
17976 if (attr
.form_is_block ())
17978 d
.locdesc
= DW_BLOCK (&attr
);
17980 else if (attr
.form_is_section_offset ())
17982 dwarf2_complex_location_expr_complaint ();
17986 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17987 "partial symbol information");
17990 case DW_AT_external
:
17991 is_external
= DW_UNSND (&attr
);
17993 case DW_AT_declaration
:
17994 is_declaration
= DW_UNSND (&attr
);
17999 case DW_AT_abstract_origin
:
18000 case DW_AT_specification
:
18001 case DW_AT_extension
:
18002 has_specification
= 1;
18003 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18004 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18005 || cu
->per_cu
->is_dwz
);
18007 case DW_AT_sibling
:
18008 /* Ignore absolute siblings, they might point outside of
18009 the current compile unit. */
18010 if (attr
.form
== DW_FORM_ref_addr
)
18011 complaint (_("ignoring absolute DW_AT_sibling"));
18014 const gdb_byte
*buffer
= reader
->buffer
;
18015 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18016 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18018 if (sibling_ptr
< info_ptr
)
18019 complaint (_("DW_AT_sibling points backwards"));
18020 else if (sibling_ptr
> reader
->buffer_end
)
18021 reader
->die_section
->overflow_complaint ();
18023 sibling
= sibling_ptr
;
18026 case DW_AT_byte_size
:
18029 case DW_AT_const_value
:
18030 has_const_value
= 1;
18032 case DW_AT_calling_convention
:
18033 /* DWARF doesn't provide a way to identify a program's source-level
18034 entry point. DW_AT_calling_convention attributes are only meant
18035 to describe functions' calling conventions.
18037 However, because it's a necessary piece of information in
18038 Fortran, and before DWARF 4 DW_CC_program was the only
18039 piece of debugging information whose definition refers to
18040 a 'main program' at all, several compilers marked Fortran
18041 main programs with DW_CC_program --- even when those
18042 functions use the standard calling conventions.
18044 Although DWARF now specifies a way to provide this
18045 information, we support this practice for backward
18047 if (DW_UNSND (&attr
) == DW_CC_program
18048 && cu
->language
== language_fortran
)
18049 main_subprogram
= 1;
18052 if (DW_UNSND (&attr
) == DW_INL_inlined
18053 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18054 may_be_inlined
= 1;
18058 if (tag
== DW_TAG_imported_unit
)
18060 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18061 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18062 || cu
->per_cu
->is_dwz
);
18066 case DW_AT_main_subprogram
:
18067 main_subprogram
= DW_UNSND (&attr
);
18072 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18073 but that requires a full DIE, so instead we just
18075 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18076 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18077 + (need_ranges_base
18081 /* Value of the DW_AT_ranges attribute is the offset in the
18082 .debug_ranges section. */
18083 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18094 /* For Ada, if both the name and the linkage name appear, we prefer
18095 the latter. This lets "catch exception" work better, regardless
18096 of the order in which the name and linkage name were emitted.
18097 Really, though, this is just a workaround for the fact that gdb
18098 doesn't store both the name and the linkage name. */
18099 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18100 name
= linkage_name
;
18102 if (high_pc_relative
)
18105 if (has_low_pc_attr
&& has_high_pc_attr
)
18107 /* When using the GNU linker, .gnu.linkonce. sections are used to
18108 eliminate duplicate copies of functions and vtables and such.
18109 The linker will arbitrarily choose one and discard the others.
18110 The AT_*_pc values for such functions refer to local labels in
18111 these sections. If the section from that file was discarded, the
18112 labels are not in the output, so the relocs get a value of 0.
18113 If this is a discarded function, mark the pc bounds as invalid,
18114 so that GDB will ignore it. */
18115 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18117 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18118 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18120 complaint (_("DW_AT_low_pc %s is zero "
18121 "for DIE at %s [in module %s]"),
18122 paddress (gdbarch
, lowpc
),
18123 sect_offset_str (sect_off
),
18124 objfile_name (objfile
));
18126 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18127 else if (lowpc
>= highpc
)
18129 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18130 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18132 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18133 "for DIE at %s [in module %s]"),
18134 paddress (gdbarch
, lowpc
),
18135 paddress (gdbarch
, highpc
),
18136 sect_offset_str (sect_off
),
18137 objfile_name (objfile
));
18146 /* Find a cached partial DIE at OFFSET in CU. */
18148 struct partial_die_info
*
18149 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18151 struct partial_die_info
*lookup_die
= NULL
;
18152 struct partial_die_info
part_die (sect_off
);
18154 lookup_die
= ((struct partial_die_info
*)
18155 htab_find_with_hash (partial_dies
, &part_die
,
18156 to_underlying (sect_off
)));
18161 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18162 except in the case of .debug_types DIEs which do not reference
18163 outside their CU (they do however referencing other types via
18164 DW_FORM_ref_sig8). */
18166 static const struct cu_partial_die_info
18167 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18169 struct dwarf2_per_objfile
*dwarf2_per_objfile
18170 = cu
->per_cu
->dwarf2_per_objfile
;
18171 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18172 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18173 struct partial_die_info
*pd
= NULL
;
18175 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18176 && cu
->header
.offset_in_cu_p (sect_off
))
18178 pd
= cu
->find_partial_die (sect_off
);
18181 /* We missed recording what we needed.
18182 Load all dies and try again. */
18183 per_cu
= cu
->per_cu
;
18187 /* TUs don't reference other CUs/TUs (except via type signatures). */
18188 if (cu
->per_cu
->is_debug_types
)
18190 error (_("Dwarf Error: Type Unit at offset %s contains"
18191 " external reference to offset %s [in module %s].\n"),
18192 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18193 bfd_get_filename (objfile
->obfd
));
18195 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18196 dwarf2_per_objfile
);
18198 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18199 load_partial_comp_unit (per_cu
);
18201 per_cu
->cu
->last_used
= 0;
18202 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18205 /* If we didn't find it, and not all dies have been loaded,
18206 load them all and try again. */
18208 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18210 per_cu
->load_all_dies
= 1;
18212 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18213 THIS_CU->cu may already be in use. So we can't just free it and
18214 replace its DIEs with the ones we read in. Instead, we leave those
18215 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18216 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18218 load_partial_comp_unit (per_cu
);
18220 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18224 internal_error (__FILE__
, __LINE__
,
18225 _("could not find partial DIE %s "
18226 "in cache [from module %s]\n"),
18227 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18228 return { per_cu
->cu
, pd
};
18231 /* See if we can figure out if the class lives in a namespace. We do
18232 this by looking for a member function; its demangled name will
18233 contain namespace info, if there is any. */
18236 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18237 struct dwarf2_cu
*cu
)
18239 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18240 what template types look like, because the demangler
18241 frequently doesn't give the same name as the debug info. We
18242 could fix this by only using the demangled name to get the
18243 prefix (but see comment in read_structure_type). */
18245 struct partial_die_info
*real_pdi
;
18246 struct partial_die_info
*child_pdi
;
18248 /* If this DIE (this DIE's specification, if any) has a parent, then
18249 we should not do this. We'll prepend the parent's fully qualified
18250 name when we create the partial symbol. */
18252 real_pdi
= struct_pdi
;
18253 while (real_pdi
->has_specification
)
18255 auto res
= find_partial_die (real_pdi
->spec_offset
,
18256 real_pdi
->spec_is_dwz
, cu
);
18257 real_pdi
= res
.pdi
;
18261 if (real_pdi
->die_parent
!= NULL
)
18264 for (child_pdi
= struct_pdi
->die_child
;
18266 child_pdi
= child_pdi
->die_sibling
)
18268 if (child_pdi
->tag
== DW_TAG_subprogram
18269 && child_pdi
->linkage_name
!= NULL
)
18271 gdb::unique_xmalloc_ptr
<char> actual_class_name
18272 (language_class_name_from_physname (cu
->language_defn
,
18273 child_pdi
->linkage_name
));
18274 if (actual_class_name
!= NULL
)
18276 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18277 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18285 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18287 /* Once we've fixed up a die, there's no point in doing so again.
18288 This also avoids a memory leak if we were to call
18289 guess_partial_die_structure_name multiple times. */
18293 /* If we found a reference attribute and the DIE has no name, try
18294 to find a name in the referred to DIE. */
18296 if (name
== NULL
&& has_specification
)
18298 struct partial_die_info
*spec_die
;
18300 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18301 spec_die
= res
.pdi
;
18304 spec_die
->fixup (cu
);
18306 if (spec_die
->name
)
18308 name
= spec_die
->name
;
18310 /* Copy DW_AT_external attribute if it is set. */
18311 if (spec_die
->is_external
)
18312 is_external
= spec_die
->is_external
;
18316 /* Set default names for some unnamed DIEs. */
18318 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18319 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18321 /* If there is no parent die to provide a namespace, and there are
18322 children, see if we can determine the namespace from their linkage
18324 if (cu
->language
== language_cplus
18325 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18326 && die_parent
== NULL
18328 && (tag
== DW_TAG_class_type
18329 || tag
== DW_TAG_structure_type
18330 || tag
== DW_TAG_union_type
))
18331 guess_partial_die_structure_name (this, cu
);
18333 /* GCC might emit a nameless struct or union that has a linkage
18334 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18336 && (tag
== DW_TAG_class_type
18337 || tag
== DW_TAG_interface_type
18338 || tag
== DW_TAG_structure_type
18339 || tag
== DW_TAG_union_type
)
18340 && linkage_name
!= NULL
)
18342 gdb::unique_xmalloc_ptr
<char> demangled
18343 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18344 if (demangled
!= nullptr)
18348 /* Strip any leading namespaces/classes, keep only the base name.
18349 DW_AT_name for named DIEs does not contain the prefixes. */
18350 base
= strrchr (demangled
.get (), ':');
18351 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18354 base
= demangled
.get ();
18356 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18357 name
= objfile
->intern (base
);
18364 /* Process the attributes that had to be skipped in the first round. These
18365 attributes are the ones that need str_offsets_base or addr_base attributes.
18366 They could not have been processed in the first round, because at the time
18367 the values of str_offsets_base or addr_base may not have been known. */
18368 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18369 struct attribute
*attr
)
18371 struct dwarf2_cu
*cu
= reader
->cu
;
18372 switch (attr
->form
)
18374 case DW_FORM_addrx
:
18375 case DW_FORM_GNU_addr_index
:
18376 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18379 case DW_FORM_strx1
:
18380 case DW_FORM_strx2
:
18381 case DW_FORM_strx3
:
18382 case DW_FORM_strx4
:
18383 case DW_FORM_GNU_str_index
:
18385 unsigned int str_index
= DW_UNSND (attr
);
18386 if (reader
->dwo_file
!= NULL
)
18388 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18389 DW_STRING_IS_CANONICAL (attr
) = 0;
18393 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18394 DW_STRING_IS_CANONICAL (attr
) = 0;
18399 gdb_assert_not_reached (_("Unexpected DWARF form."));
18403 /* Read an attribute value described by an attribute form. */
18405 static const gdb_byte
*
18406 read_attribute_value (const struct die_reader_specs
*reader
,
18407 struct attribute
*attr
, unsigned form
,
18408 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18409 bool *need_reprocess
)
18411 struct dwarf2_cu
*cu
= reader
->cu
;
18412 struct dwarf2_per_objfile
*dwarf2_per_objfile
18413 = cu
->per_cu
->dwarf2_per_objfile
;
18414 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18415 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18416 bfd
*abfd
= reader
->abfd
;
18417 struct comp_unit_head
*cu_header
= &cu
->header
;
18418 unsigned int bytes_read
;
18419 struct dwarf_block
*blk
;
18420 *need_reprocess
= false;
18422 attr
->form
= (enum dwarf_form
) form
;
18425 case DW_FORM_ref_addr
:
18426 if (cu
->header
.version
== 2)
18427 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18430 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18432 info_ptr
+= bytes_read
;
18434 case DW_FORM_GNU_ref_alt
:
18435 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18436 info_ptr
+= bytes_read
;
18439 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18440 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18441 info_ptr
+= bytes_read
;
18443 case DW_FORM_block2
:
18444 blk
= dwarf_alloc_block (cu
);
18445 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18447 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18448 info_ptr
+= blk
->size
;
18449 DW_BLOCK (attr
) = blk
;
18451 case DW_FORM_block4
:
18452 blk
= dwarf_alloc_block (cu
);
18453 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18455 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18456 info_ptr
+= blk
->size
;
18457 DW_BLOCK (attr
) = blk
;
18459 case DW_FORM_data2
:
18460 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18463 case DW_FORM_data4
:
18464 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18467 case DW_FORM_data8
:
18468 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18471 case DW_FORM_data16
:
18472 blk
= dwarf_alloc_block (cu
);
18474 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18476 DW_BLOCK (attr
) = blk
;
18478 case DW_FORM_sec_offset
:
18479 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18480 info_ptr
+= bytes_read
;
18482 case DW_FORM_string
:
18483 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18484 DW_STRING_IS_CANONICAL (attr
) = 0;
18485 info_ptr
+= bytes_read
;
18488 if (!cu
->per_cu
->is_dwz
)
18490 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18491 abfd
, info_ptr
, cu_header
,
18493 DW_STRING_IS_CANONICAL (attr
) = 0;
18494 info_ptr
+= bytes_read
;
18498 case DW_FORM_line_strp
:
18499 if (!cu
->per_cu
->is_dwz
)
18502 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18504 DW_STRING_IS_CANONICAL (attr
) = 0;
18505 info_ptr
+= bytes_read
;
18509 case DW_FORM_GNU_strp_alt
:
18511 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18512 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18515 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18516 DW_STRING_IS_CANONICAL (attr
) = 0;
18517 info_ptr
+= bytes_read
;
18520 case DW_FORM_exprloc
:
18521 case DW_FORM_block
:
18522 blk
= dwarf_alloc_block (cu
);
18523 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18524 info_ptr
+= bytes_read
;
18525 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18526 info_ptr
+= blk
->size
;
18527 DW_BLOCK (attr
) = blk
;
18529 case DW_FORM_block1
:
18530 blk
= dwarf_alloc_block (cu
);
18531 blk
->size
= read_1_byte (abfd
, info_ptr
);
18533 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18534 info_ptr
+= blk
->size
;
18535 DW_BLOCK (attr
) = blk
;
18537 case DW_FORM_data1
:
18538 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18542 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18545 case DW_FORM_flag_present
:
18546 DW_UNSND (attr
) = 1;
18548 case DW_FORM_sdata
:
18549 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18550 info_ptr
+= bytes_read
;
18552 case DW_FORM_udata
:
18553 case DW_FORM_rnglistx
:
18554 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18555 info_ptr
+= bytes_read
;
18558 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18559 + read_1_byte (abfd
, info_ptr
));
18563 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18564 + read_2_bytes (abfd
, info_ptr
));
18568 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18569 + read_4_bytes (abfd
, info_ptr
));
18573 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18574 + read_8_bytes (abfd
, info_ptr
));
18577 case DW_FORM_ref_sig8
:
18578 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18581 case DW_FORM_ref_udata
:
18582 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18583 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18584 info_ptr
+= bytes_read
;
18586 case DW_FORM_indirect
:
18587 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18588 info_ptr
+= bytes_read
;
18589 if (form
== DW_FORM_implicit_const
)
18591 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18592 info_ptr
+= bytes_read
;
18594 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18595 info_ptr
, need_reprocess
);
18597 case DW_FORM_implicit_const
:
18598 DW_SND (attr
) = implicit_const
;
18600 case DW_FORM_addrx
:
18601 case DW_FORM_GNU_addr_index
:
18602 *need_reprocess
= true;
18603 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18604 info_ptr
+= bytes_read
;
18607 case DW_FORM_strx1
:
18608 case DW_FORM_strx2
:
18609 case DW_FORM_strx3
:
18610 case DW_FORM_strx4
:
18611 case DW_FORM_GNU_str_index
:
18613 ULONGEST str_index
;
18614 if (form
== DW_FORM_strx1
)
18616 str_index
= read_1_byte (abfd
, info_ptr
);
18619 else if (form
== DW_FORM_strx2
)
18621 str_index
= read_2_bytes (abfd
, info_ptr
);
18624 else if (form
== DW_FORM_strx3
)
18626 str_index
= read_3_bytes (abfd
, info_ptr
);
18629 else if (form
== DW_FORM_strx4
)
18631 str_index
= read_4_bytes (abfd
, info_ptr
);
18636 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18637 info_ptr
+= bytes_read
;
18639 *need_reprocess
= true;
18640 DW_UNSND (attr
) = str_index
;
18644 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18645 dwarf_form_name (form
),
18646 bfd_get_filename (abfd
));
18650 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18651 attr
->form
= DW_FORM_GNU_ref_alt
;
18653 /* We have seen instances where the compiler tried to emit a byte
18654 size attribute of -1 which ended up being encoded as an unsigned
18655 0xffffffff. Although 0xffffffff is technically a valid size value,
18656 an object of this size seems pretty unlikely so we can relatively
18657 safely treat these cases as if the size attribute was invalid and
18658 treat them as zero by default. */
18659 if (attr
->name
== DW_AT_byte_size
18660 && form
== DW_FORM_data4
18661 && DW_UNSND (attr
) >= 0xffffffff)
18664 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18665 hex_string (DW_UNSND (attr
)));
18666 DW_UNSND (attr
) = 0;
18672 /* Read an attribute described by an abbreviated attribute. */
18674 static const gdb_byte
*
18675 read_attribute (const struct die_reader_specs
*reader
,
18676 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18677 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18679 attr
->name
= abbrev
->name
;
18680 return read_attribute_value (reader
, attr
, abbrev
->form
,
18681 abbrev
->implicit_const
, info_ptr
,
18685 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18687 static const char *
18688 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18689 LONGEST str_offset
)
18691 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18692 str_offset
, "DW_FORM_strp");
18695 /* Return pointer to string at .debug_str offset as read from BUF.
18696 BUF is assumed to be in a compilation unit described by CU_HEADER.
18697 Return *BYTES_READ_PTR count of bytes read from BUF. */
18699 static const char *
18700 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18701 const gdb_byte
*buf
,
18702 const struct comp_unit_head
*cu_header
,
18703 unsigned int *bytes_read_ptr
)
18705 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18707 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18713 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18714 const struct comp_unit_head
*cu_header
,
18715 unsigned int *bytes_read_ptr
)
18717 bfd
*abfd
= objfile
->obfd
;
18718 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18720 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18723 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18724 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18725 ADDR_SIZE is the size of addresses from the CU header. */
18728 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18729 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18732 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18733 bfd
*abfd
= objfile
->obfd
;
18734 const gdb_byte
*info_ptr
;
18735 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18737 dwarf2_per_objfile
->addr
.read (objfile
);
18738 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18739 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18740 objfile_name (objfile
));
18741 if (addr_base_or_zero
+ addr_index
* addr_size
18742 >= dwarf2_per_objfile
->addr
.size
)
18743 error (_("DW_FORM_addr_index pointing outside of "
18744 ".debug_addr section [in module %s]"),
18745 objfile_name (objfile
));
18746 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18747 + addr_base_or_zero
+ addr_index
* addr_size
);
18748 if (addr_size
== 4)
18749 return bfd_get_32 (abfd
, info_ptr
);
18751 return bfd_get_64 (abfd
, info_ptr
);
18754 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18757 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18759 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18760 cu
->addr_base
, cu
->header
.addr_size
);
18763 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18766 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18767 unsigned int *bytes_read
)
18769 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18770 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18772 return read_addr_index (cu
, addr_index
);
18778 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18780 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18781 struct dwarf2_cu
*cu
= per_cu
->cu
;
18782 gdb::optional
<ULONGEST
> addr_base
;
18785 /* We need addr_base and addr_size.
18786 If we don't have PER_CU->cu, we have to get it.
18787 Nasty, but the alternative is storing the needed info in PER_CU,
18788 which at this point doesn't seem justified: it's not clear how frequently
18789 it would get used and it would increase the size of every PER_CU.
18790 Entry points like dwarf2_per_cu_addr_size do a similar thing
18791 so we're not in uncharted territory here.
18792 Alas we need to be a bit more complicated as addr_base is contained
18795 We don't need to read the entire CU(/TU).
18796 We just need the header and top level die.
18798 IWBN to use the aging mechanism to let us lazily later discard the CU.
18799 For now we skip this optimization. */
18803 addr_base
= cu
->addr_base
;
18804 addr_size
= cu
->header
.addr_size
;
18808 cutu_reader
reader (per_cu
, NULL
, 0, false);
18809 addr_base
= reader
.cu
->addr_base
;
18810 addr_size
= reader
.cu
->header
.addr_size
;
18813 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18817 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18818 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18821 static const char *
18822 read_str_index (struct dwarf2_cu
*cu
,
18823 struct dwarf2_section_info
*str_section
,
18824 struct dwarf2_section_info
*str_offsets_section
,
18825 ULONGEST str_offsets_base
, ULONGEST str_index
)
18827 struct dwarf2_per_objfile
*dwarf2_per_objfile
18828 = cu
->per_cu
->dwarf2_per_objfile
;
18829 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18830 const char *objf_name
= objfile_name (objfile
);
18831 bfd
*abfd
= objfile
->obfd
;
18832 const gdb_byte
*info_ptr
;
18833 ULONGEST str_offset
;
18834 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18836 str_section
->read (objfile
);
18837 str_offsets_section
->read (objfile
);
18838 if (str_section
->buffer
== NULL
)
18839 error (_("%s used without %s section"
18840 " in CU at offset %s [in module %s]"),
18841 form_name
, str_section
->get_name (),
18842 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18843 if (str_offsets_section
->buffer
== NULL
)
18844 error (_("%s used without %s section"
18845 " in CU at offset %s [in module %s]"),
18846 form_name
, str_section
->get_name (),
18847 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18848 info_ptr
= (str_offsets_section
->buffer
18850 + str_index
* cu
->header
.offset_size
);
18851 if (cu
->header
.offset_size
== 4)
18852 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18854 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18855 if (str_offset
>= str_section
->size
)
18856 error (_("Offset from %s pointing outside of"
18857 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18858 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18859 return (const char *) (str_section
->buffer
+ str_offset
);
18862 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18864 static const char *
18865 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18867 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18868 ? reader
->cu
->header
.addr_size
: 0;
18869 return read_str_index (reader
->cu
,
18870 &reader
->dwo_file
->sections
.str
,
18871 &reader
->dwo_file
->sections
.str_offsets
,
18872 str_offsets_base
, str_index
);
18875 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18877 static const char *
18878 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18880 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18881 const char *objf_name
= objfile_name (objfile
);
18882 static const char form_name
[] = "DW_FORM_GNU_str_index";
18883 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18885 if (!cu
->str_offsets_base
.has_value ())
18886 error (_("%s used in Fission stub without %s"
18887 " in CU at offset 0x%lx [in module %s]"),
18888 form_name
, str_offsets_attr_name
,
18889 (long) cu
->header
.offset_size
, objf_name
);
18891 return read_str_index (cu
,
18892 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18893 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18894 *cu
->str_offsets_base
, str_index
);
18897 /* Return the length of an LEB128 number in BUF. */
18900 leb128_size (const gdb_byte
*buf
)
18902 const gdb_byte
*begin
= buf
;
18908 if ((byte
& 128) == 0)
18909 return buf
- begin
;
18914 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
18923 cu
->language
= language_c
;
18926 case DW_LANG_C_plus_plus
:
18927 case DW_LANG_C_plus_plus_11
:
18928 case DW_LANG_C_plus_plus_14
:
18929 cu
->language
= language_cplus
;
18932 cu
->language
= language_d
;
18934 case DW_LANG_Fortran77
:
18935 case DW_LANG_Fortran90
:
18936 case DW_LANG_Fortran95
:
18937 case DW_LANG_Fortran03
:
18938 case DW_LANG_Fortran08
:
18939 cu
->language
= language_fortran
;
18942 cu
->language
= language_go
;
18944 case DW_LANG_Mips_Assembler
:
18945 cu
->language
= language_asm
;
18947 case DW_LANG_Ada83
:
18948 case DW_LANG_Ada95
:
18949 cu
->language
= language_ada
;
18951 case DW_LANG_Modula2
:
18952 cu
->language
= language_m2
;
18954 case DW_LANG_Pascal83
:
18955 cu
->language
= language_pascal
;
18958 cu
->language
= language_objc
;
18961 case DW_LANG_Rust_old
:
18962 cu
->language
= language_rust
;
18964 case DW_LANG_Cobol74
:
18965 case DW_LANG_Cobol85
:
18967 cu
->language
= language_minimal
;
18970 cu
->language_defn
= language_def (cu
->language
);
18973 /* Return the named attribute or NULL if not there. */
18975 static struct attribute
*
18976 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18981 struct attribute
*spec
= NULL
;
18983 for (i
= 0; i
< die
->num_attrs
; ++i
)
18985 if (die
->attrs
[i
].name
== name
)
18986 return &die
->attrs
[i
];
18987 if (die
->attrs
[i
].name
== DW_AT_specification
18988 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
18989 spec
= &die
->attrs
[i
];
18995 die
= follow_die_ref (die
, spec
, &cu
);
19001 /* Return the named attribute or NULL if not there,
19002 but do not follow DW_AT_specification, etc.
19003 This is for use in contexts where we're reading .debug_types dies.
19004 Following DW_AT_specification, DW_AT_abstract_origin will take us
19005 back up the chain, and we want to go down. */
19007 static struct attribute
*
19008 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19012 for (i
= 0; i
< die
->num_attrs
; ++i
)
19013 if (die
->attrs
[i
].name
== name
)
19014 return &die
->attrs
[i
];
19019 /* Return the string associated with a string-typed attribute, or NULL if it
19020 is either not found or is of an incorrect type. */
19022 static const char *
19023 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19025 struct attribute
*attr
;
19026 const char *str
= NULL
;
19028 attr
= dwarf2_attr (die
, name
, cu
);
19032 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19033 || attr
->form
== DW_FORM_string
19034 || attr
->form
== DW_FORM_strx
19035 || attr
->form
== DW_FORM_strx1
19036 || attr
->form
== DW_FORM_strx2
19037 || attr
->form
== DW_FORM_strx3
19038 || attr
->form
== DW_FORM_strx4
19039 || attr
->form
== DW_FORM_GNU_str_index
19040 || attr
->form
== DW_FORM_GNU_strp_alt
)
19041 str
= DW_STRING (attr
);
19043 complaint (_("string type expected for attribute %s for "
19044 "DIE at %s in module %s"),
19045 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19046 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19052 /* Return the dwo name or NULL if not present. If present, it is in either
19053 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19054 static const char *
19055 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19057 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19058 if (dwo_name
== nullptr)
19059 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19063 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19064 and holds a non-zero value. This function should only be used for
19065 DW_FORM_flag or DW_FORM_flag_present attributes. */
19068 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19070 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19072 return (attr
&& DW_UNSND (attr
));
19076 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19078 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19079 which value is non-zero. However, we have to be careful with
19080 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19081 (via dwarf2_flag_true_p) follows this attribute. So we may
19082 end up accidently finding a declaration attribute that belongs
19083 to a different DIE referenced by the specification attribute,
19084 even though the given DIE does not have a declaration attribute. */
19085 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19086 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19089 /* Return the die giving the specification for DIE, if there is
19090 one. *SPEC_CU is the CU containing DIE on input, and the CU
19091 containing the return value on output. If there is no
19092 specification, but there is an abstract origin, that is
19095 static struct die_info
*
19096 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19098 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19101 if (spec_attr
== NULL
)
19102 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19104 if (spec_attr
== NULL
)
19107 return follow_die_ref (die
, spec_attr
, spec_cu
);
19110 /* Stub for free_line_header to match void * callback types. */
19113 free_line_header_voidp (void *arg
)
19115 struct line_header
*lh
= (struct line_header
*) arg
;
19120 /* A convenience function to find the proper .debug_line section for a CU. */
19122 static struct dwarf2_section_info
*
19123 get_debug_line_section (struct dwarf2_cu
*cu
)
19125 struct dwarf2_section_info
*section
;
19126 struct dwarf2_per_objfile
*dwarf2_per_objfile
19127 = cu
->per_cu
->dwarf2_per_objfile
;
19129 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19131 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19132 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19133 else if (cu
->per_cu
->is_dwz
)
19135 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19137 section
= &dwz
->line
;
19140 section
= &dwarf2_per_objfile
->line
;
19145 /* Read the statement program header starting at OFFSET in
19146 .debug_line, or .debug_line.dwo. Return a pointer
19147 to a struct line_header, allocated using xmalloc.
19148 Returns NULL if there is a problem reading the header, e.g., if it
19149 has a version we don't understand.
19151 NOTE: the strings in the include directory and file name tables of
19152 the returned object point into the dwarf line section buffer,
19153 and must not be freed. */
19155 static line_header_up
19156 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19158 struct dwarf2_section_info
*section
;
19159 struct dwarf2_per_objfile
*dwarf2_per_objfile
19160 = cu
->per_cu
->dwarf2_per_objfile
;
19162 section
= get_debug_line_section (cu
);
19163 section
->read (dwarf2_per_objfile
->objfile
);
19164 if (section
->buffer
== NULL
)
19166 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19167 complaint (_("missing .debug_line.dwo section"));
19169 complaint (_("missing .debug_line section"));
19173 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19174 dwarf2_per_objfile
, section
,
19178 /* Subroutine of dwarf_decode_lines to simplify it.
19179 Return the file name of the psymtab for the given file_entry.
19180 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19181 If space for the result is malloc'd, *NAME_HOLDER will be set.
19182 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19184 static const char *
19185 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19186 const dwarf2_psymtab
*pst
,
19187 const char *comp_dir
,
19188 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19190 const char *include_name
= fe
.name
;
19191 const char *include_name_to_compare
= include_name
;
19192 const char *pst_filename
;
19195 const char *dir_name
= fe
.include_dir (lh
);
19197 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19198 if (!IS_ABSOLUTE_PATH (include_name
)
19199 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19201 /* Avoid creating a duplicate psymtab for PST.
19202 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19203 Before we do the comparison, however, we need to account
19204 for DIR_NAME and COMP_DIR.
19205 First prepend dir_name (if non-NULL). If we still don't
19206 have an absolute path prepend comp_dir (if non-NULL).
19207 However, the directory we record in the include-file's
19208 psymtab does not contain COMP_DIR (to match the
19209 corresponding symtab(s)).
19214 bash$ gcc -g ./hello.c
19215 include_name = "hello.c"
19217 DW_AT_comp_dir = comp_dir = "/tmp"
19218 DW_AT_name = "./hello.c"
19222 if (dir_name
!= NULL
)
19224 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19225 include_name
, (char *) NULL
));
19226 include_name
= name_holder
->get ();
19227 include_name_to_compare
= include_name
;
19229 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19231 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19232 include_name
, (char *) NULL
));
19233 include_name_to_compare
= hold_compare
.get ();
19237 pst_filename
= pst
->filename
;
19238 gdb::unique_xmalloc_ptr
<char> copied_name
;
19239 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19241 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19242 pst_filename
, (char *) NULL
));
19243 pst_filename
= copied_name
.get ();
19246 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19250 return include_name
;
19253 /* State machine to track the state of the line number program. */
19255 class lnp_state_machine
19258 /* Initialize a machine state for the start of a line number
19260 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19261 bool record_lines_p
);
19263 file_entry
*current_file ()
19265 /* lh->file_names is 0-based, but the file name numbers in the
19266 statement program are 1-based. */
19267 return m_line_header
->file_name_at (m_file
);
19270 /* Record the line in the state machine. END_SEQUENCE is true if
19271 we're processing the end of a sequence. */
19272 void record_line (bool end_sequence
);
19274 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19275 nop-out rest of the lines in this sequence. */
19276 void check_line_address (struct dwarf2_cu
*cu
,
19277 const gdb_byte
*line_ptr
,
19278 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19280 void handle_set_discriminator (unsigned int discriminator
)
19282 m_discriminator
= discriminator
;
19283 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19286 /* Handle DW_LNE_set_address. */
19287 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19290 address
+= baseaddr
;
19291 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19294 /* Handle DW_LNS_advance_pc. */
19295 void handle_advance_pc (CORE_ADDR adjust
);
19297 /* Handle a special opcode. */
19298 void handle_special_opcode (unsigned char op_code
);
19300 /* Handle DW_LNS_advance_line. */
19301 void handle_advance_line (int line_delta
)
19303 advance_line (line_delta
);
19306 /* Handle DW_LNS_set_file. */
19307 void handle_set_file (file_name_index file
);
19309 /* Handle DW_LNS_negate_stmt. */
19310 void handle_negate_stmt ()
19312 m_is_stmt
= !m_is_stmt
;
19315 /* Handle DW_LNS_const_add_pc. */
19316 void handle_const_add_pc ();
19318 /* Handle DW_LNS_fixed_advance_pc. */
19319 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19321 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19325 /* Handle DW_LNS_copy. */
19326 void handle_copy ()
19328 record_line (false);
19329 m_discriminator
= 0;
19332 /* Handle DW_LNE_end_sequence. */
19333 void handle_end_sequence ()
19335 m_currently_recording_lines
= true;
19339 /* Advance the line by LINE_DELTA. */
19340 void advance_line (int line_delta
)
19342 m_line
+= line_delta
;
19344 if (line_delta
!= 0)
19345 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19348 struct dwarf2_cu
*m_cu
;
19350 gdbarch
*m_gdbarch
;
19352 /* True if we're recording lines.
19353 Otherwise we're building partial symtabs and are just interested in
19354 finding include files mentioned by the line number program. */
19355 bool m_record_lines_p
;
19357 /* The line number header. */
19358 line_header
*m_line_header
;
19360 /* These are part of the standard DWARF line number state machine,
19361 and initialized according to the DWARF spec. */
19363 unsigned char m_op_index
= 0;
19364 /* The line table index of the current file. */
19365 file_name_index m_file
= 1;
19366 unsigned int m_line
= 1;
19368 /* These are initialized in the constructor. */
19370 CORE_ADDR m_address
;
19372 unsigned int m_discriminator
;
19374 /* Additional bits of state we need to track. */
19376 /* The last file that we called dwarf2_start_subfile for.
19377 This is only used for TLLs. */
19378 unsigned int m_last_file
= 0;
19379 /* The last file a line number was recorded for. */
19380 struct subfile
*m_last_subfile
= NULL
;
19382 /* When true, record the lines we decode. */
19383 bool m_currently_recording_lines
= false;
19385 /* The last line number that was recorded, used to coalesce
19386 consecutive entries for the same line. This can happen, for
19387 example, when discriminators are present. PR 17276. */
19388 unsigned int m_last_line
= 0;
19389 bool m_line_has_non_zero_discriminator
= false;
19393 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19395 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19396 / m_line_header
->maximum_ops_per_instruction
)
19397 * m_line_header
->minimum_instruction_length
);
19398 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19399 m_op_index
= ((m_op_index
+ adjust
)
19400 % m_line_header
->maximum_ops_per_instruction
);
19404 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19406 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19407 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19408 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19409 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19410 / m_line_header
->maximum_ops_per_instruction
)
19411 * m_line_header
->minimum_instruction_length
);
19412 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19413 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19414 % m_line_header
->maximum_ops_per_instruction
);
19416 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19417 advance_line (line_delta
);
19418 record_line (false);
19419 m_discriminator
= 0;
19423 lnp_state_machine::handle_set_file (file_name_index file
)
19427 const file_entry
*fe
= current_file ();
19429 dwarf2_debug_line_missing_file_complaint ();
19430 else if (m_record_lines_p
)
19432 const char *dir
= fe
->include_dir (m_line_header
);
19434 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19435 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19436 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19441 lnp_state_machine::handle_const_add_pc ()
19444 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19447 = (((m_op_index
+ adjust
)
19448 / m_line_header
->maximum_ops_per_instruction
)
19449 * m_line_header
->minimum_instruction_length
);
19451 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19452 m_op_index
= ((m_op_index
+ adjust
)
19453 % m_line_header
->maximum_ops_per_instruction
);
19456 /* Return non-zero if we should add LINE to the line number table.
19457 LINE is the line to add, LAST_LINE is the last line that was added,
19458 LAST_SUBFILE is the subfile for LAST_LINE.
19459 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19460 had a non-zero discriminator.
19462 We have to be careful in the presence of discriminators.
19463 E.g., for this line:
19465 for (i = 0; i < 100000; i++);
19467 clang can emit four line number entries for that one line,
19468 each with a different discriminator.
19469 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19471 However, we want gdb to coalesce all four entries into one.
19472 Otherwise the user could stepi into the middle of the line and
19473 gdb would get confused about whether the pc really was in the
19474 middle of the line.
19476 Things are further complicated by the fact that two consecutive
19477 line number entries for the same line is a heuristic used by gcc
19478 to denote the end of the prologue. So we can't just discard duplicate
19479 entries, we have to be selective about it. The heuristic we use is
19480 that we only collapse consecutive entries for the same line if at least
19481 one of those entries has a non-zero discriminator. PR 17276.
19483 Note: Addresses in the line number state machine can never go backwards
19484 within one sequence, thus this coalescing is ok. */
19487 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19488 unsigned int line
, unsigned int last_line
,
19489 int line_has_non_zero_discriminator
,
19490 struct subfile
*last_subfile
)
19492 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19494 if (line
!= last_line
)
19496 /* Same line for the same file that we've seen already.
19497 As a last check, for pr 17276, only record the line if the line
19498 has never had a non-zero discriminator. */
19499 if (!line_has_non_zero_discriminator
)
19504 /* Use the CU's builder to record line number LINE beginning at
19505 address ADDRESS in the line table of subfile SUBFILE. */
19508 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19509 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19510 struct dwarf2_cu
*cu
)
19512 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19514 if (dwarf_line_debug
)
19516 fprintf_unfiltered (gdb_stdlog
,
19517 "Recording line %u, file %s, address %s\n",
19518 line
, lbasename (subfile
->name
),
19519 paddress (gdbarch
, address
));
19523 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19526 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19527 Mark the end of a set of line number records.
19528 The arguments are the same as for dwarf_record_line_1.
19529 If SUBFILE is NULL the request is ignored. */
19532 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19533 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19535 if (subfile
== NULL
)
19538 if (dwarf_line_debug
)
19540 fprintf_unfiltered (gdb_stdlog
,
19541 "Finishing current line, file %s, address %s\n",
19542 lbasename (subfile
->name
),
19543 paddress (gdbarch
, address
));
19546 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19550 lnp_state_machine::record_line (bool end_sequence
)
19552 if (dwarf_line_debug
)
19554 fprintf_unfiltered (gdb_stdlog
,
19555 "Processing actual line %u: file %u,"
19556 " address %s, is_stmt %u, discrim %u%s\n",
19558 paddress (m_gdbarch
, m_address
),
19559 m_is_stmt
, m_discriminator
,
19560 (end_sequence
? "\t(end sequence)" : ""));
19563 file_entry
*fe
= current_file ();
19566 dwarf2_debug_line_missing_file_complaint ();
19567 /* For now we ignore lines not starting on an instruction boundary.
19568 But not when processing end_sequence for compatibility with the
19569 previous version of the code. */
19570 else if (m_op_index
== 0 || end_sequence
)
19572 fe
->included_p
= 1;
19573 if (m_record_lines_p
)
19575 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19578 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19579 m_currently_recording_lines
? m_cu
: nullptr);
19584 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19586 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19587 m_line_has_non_zero_discriminator
,
19590 buildsym_compunit
*builder
= m_cu
->get_builder ();
19591 dwarf_record_line_1 (m_gdbarch
,
19592 builder
->get_current_subfile (),
19593 m_line
, m_address
, is_stmt
,
19594 m_currently_recording_lines
? m_cu
: nullptr);
19596 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19597 m_last_line
= m_line
;
19603 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19604 line_header
*lh
, bool record_lines_p
)
19608 m_record_lines_p
= record_lines_p
;
19609 m_line_header
= lh
;
19611 m_currently_recording_lines
= true;
19613 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19614 was a line entry for it so that the backend has a chance to adjust it
19615 and also record it in case it needs it. This is currently used by MIPS
19616 code, cf. `mips_adjust_dwarf2_line'. */
19617 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19618 m_is_stmt
= lh
->default_is_stmt
;
19619 m_discriminator
= 0;
19623 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19624 const gdb_byte
*line_ptr
,
19625 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19627 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19628 the pc range of the CU. However, we restrict the test to only ADDRESS
19629 values of zero to preserve GDB's previous behaviour which is to handle
19630 the specific case of a function being GC'd by the linker. */
19632 if (address
== 0 && address
< unrelocated_lowpc
)
19634 /* This line table is for a function which has been
19635 GCd by the linker. Ignore it. PR gdb/12528 */
19637 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19638 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19640 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19641 line_offset
, objfile_name (objfile
));
19642 m_currently_recording_lines
= false;
19643 /* Note: m_currently_recording_lines is left as false until we see
19644 DW_LNE_end_sequence. */
19648 /* Subroutine of dwarf_decode_lines to simplify it.
19649 Process the line number information in LH.
19650 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19651 program in order to set included_p for every referenced header. */
19654 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19655 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19657 const gdb_byte
*line_ptr
, *extended_end
;
19658 const gdb_byte
*line_end
;
19659 unsigned int bytes_read
, extended_len
;
19660 unsigned char op_code
, extended_op
;
19661 CORE_ADDR baseaddr
;
19662 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19663 bfd
*abfd
= objfile
->obfd
;
19664 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19665 /* True if we're recording line info (as opposed to building partial
19666 symtabs and just interested in finding include files mentioned by
19667 the line number program). */
19668 bool record_lines_p
= !decode_for_pst_p
;
19670 baseaddr
= objfile
->text_section_offset ();
19672 line_ptr
= lh
->statement_program_start
;
19673 line_end
= lh
->statement_program_end
;
19675 /* Read the statement sequences until there's nothing left. */
19676 while (line_ptr
< line_end
)
19678 /* The DWARF line number program state machine. Reset the state
19679 machine at the start of each sequence. */
19680 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19681 bool end_sequence
= false;
19683 if (record_lines_p
)
19685 /* Start a subfile for the current file of the state
19687 const file_entry
*fe
= state_machine
.current_file ();
19690 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19693 /* Decode the table. */
19694 while (line_ptr
< line_end
&& !end_sequence
)
19696 op_code
= read_1_byte (abfd
, line_ptr
);
19699 if (op_code
>= lh
->opcode_base
)
19701 /* Special opcode. */
19702 state_machine
.handle_special_opcode (op_code
);
19704 else switch (op_code
)
19706 case DW_LNS_extended_op
:
19707 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19709 line_ptr
+= bytes_read
;
19710 extended_end
= line_ptr
+ extended_len
;
19711 extended_op
= read_1_byte (abfd
, line_ptr
);
19713 switch (extended_op
)
19715 case DW_LNE_end_sequence
:
19716 state_machine
.handle_end_sequence ();
19717 end_sequence
= true;
19719 case DW_LNE_set_address
:
19722 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19723 line_ptr
+= bytes_read
;
19725 state_machine
.check_line_address (cu
, line_ptr
,
19726 lowpc
- baseaddr
, address
);
19727 state_machine
.handle_set_address (baseaddr
, address
);
19730 case DW_LNE_define_file
:
19732 const char *cur_file
;
19733 unsigned int mod_time
, length
;
19736 cur_file
= read_direct_string (abfd
, line_ptr
,
19738 line_ptr
+= bytes_read
;
19739 dindex
= (dir_index
)
19740 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19741 line_ptr
+= bytes_read
;
19743 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19744 line_ptr
+= bytes_read
;
19746 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19747 line_ptr
+= bytes_read
;
19748 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19751 case DW_LNE_set_discriminator
:
19753 /* The discriminator is not interesting to the
19754 debugger; just ignore it. We still need to
19755 check its value though:
19756 if there are consecutive entries for the same
19757 (non-prologue) line we want to coalesce them.
19760 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19761 line_ptr
+= bytes_read
;
19763 state_machine
.handle_set_discriminator (discr
);
19767 complaint (_("mangled .debug_line section"));
19770 /* Make sure that we parsed the extended op correctly. If e.g.
19771 we expected a different address size than the producer used,
19772 we may have read the wrong number of bytes. */
19773 if (line_ptr
!= extended_end
)
19775 complaint (_("mangled .debug_line section"));
19780 state_machine
.handle_copy ();
19782 case DW_LNS_advance_pc
:
19785 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19786 line_ptr
+= bytes_read
;
19788 state_machine
.handle_advance_pc (adjust
);
19791 case DW_LNS_advance_line
:
19794 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19795 line_ptr
+= bytes_read
;
19797 state_machine
.handle_advance_line (line_delta
);
19800 case DW_LNS_set_file
:
19802 file_name_index file
19803 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19805 line_ptr
+= bytes_read
;
19807 state_machine
.handle_set_file (file
);
19810 case DW_LNS_set_column
:
19811 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19812 line_ptr
+= bytes_read
;
19814 case DW_LNS_negate_stmt
:
19815 state_machine
.handle_negate_stmt ();
19817 case DW_LNS_set_basic_block
:
19819 /* Add to the address register of the state machine the
19820 address increment value corresponding to special opcode
19821 255. I.e., this value is scaled by the minimum
19822 instruction length since special opcode 255 would have
19823 scaled the increment. */
19824 case DW_LNS_const_add_pc
:
19825 state_machine
.handle_const_add_pc ();
19827 case DW_LNS_fixed_advance_pc
:
19829 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19832 state_machine
.handle_fixed_advance_pc (addr_adj
);
19837 /* Unknown standard opcode, ignore it. */
19840 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19842 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19843 line_ptr
+= bytes_read
;
19850 dwarf2_debug_line_missing_end_sequence_complaint ();
19852 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19853 in which case we still finish recording the last line). */
19854 state_machine
.record_line (true);
19858 /* Decode the Line Number Program (LNP) for the given line_header
19859 structure and CU. The actual information extracted and the type
19860 of structures created from the LNP depends on the value of PST.
19862 1. If PST is NULL, then this procedure uses the data from the program
19863 to create all necessary symbol tables, and their linetables.
19865 2. If PST is not NULL, this procedure reads the program to determine
19866 the list of files included by the unit represented by PST, and
19867 builds all the associated partial symbol tables.
19869 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19870 It is used for relative paths in the line table.
19871 NOTE: When processing partial symtabs (pst != NULL),
19872 comp_dir == pst->dirname.
19874 NOTE: It is important that psymtabs have the same file name (via strcmp)
19875 as the corresponding symtab. Since COMP_DIR is not used in the name of the
19876 symtab we don't use it in the name of the psymtabs we create.
19877 E.g. expand_line_sal requires this when finding psymtabs to expand.
19878 A good testcase for this is mb-inline.exp.
19880 LOWPC is the lowest address in CU (or 0 if not known).
19882 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
19883 for its PC<->lines mapping information. Otherwise only the filename
19884 table is read in. */
19887 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
19888 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
19889 CORE_ADDR lowpc
, int decode_mapping
)
19891 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19892 const int decode_for_pst_p
= (pst
!= NULL
);
19894 if (decode_mapping
)
19895 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
19897 if (decode_for_pst_p
)
19899 /* Now that we're done scanning the Line Header Program, we can
19900 create the psymtab of each included file. */
19901 for (auto &file_entry
: lh
->file_names ())
19902 if (file_entry
.included_p
== 1)
19904 gdb::unique_xmalloc_ptr
<char> name_holder
;
19905 const char *include_name
=
19906 psymtab_include_file_name (lh
, file_entry
, pst
,
19907 comp_dir
, &name_holder
);
19908 if (include_name
!= NULL
)
19909 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
19914 /* Make sure a symtab is created for every file, even files
19915 which contain only variables (i.e. no code with associated
19917 buildsym_compunit
*builder
= cu
->get_builder ();
19918 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
19920 for (auto &fe
: lh
->file_names ())
19922 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
19923 if (builder
->get_current_subfile ()->symtab
== NULL
)
19925 builder
->get_current_subfile ()->symtab
19926 = allocate_symtab (cust
,
19927 builder
->get_current_subfile ()->name
);
19929 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
19934 /* Start a subfile for DWARF. FILENAME is the name of the file and
19935 DIRNAME the name of the source directory which contains FILENAME
19936 or NULL if not known.
19937 This routine tries to keep line numbers from identical absolute and
19938 relative file names in a common subfile.
19940 Using the `list' example from the GDB testsuite, which resides in
19941 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
19942 of /srcdir/list0.c yields the following debugging information for list0.c:
19944 DW_AT_name: /srcdir/list0.c
19945 DW_AT_comp_dir: /compdir
19946 files.files[0].name: list0.h
19947 files.files[0].dir: /srcdir
19948 files.files[1].name: list0.c
19949 files.files[1].dir: /srcdir
19951 The line number information for list0.c has to end up in a single
19952 subfile, so that `break /srcdir/list0.c:1' works as expected.
19953 start_subfile will ensure that this happens provided that we pass the
19954 concatenation of files.files[1].dir and files.files[1].name as the
19958 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
19959 const char *dirname
)
19961 gdb::unique_xmalloc_ptr
<char> copy
;
19963 /* In order not to lose the line information directory,
19964 we concatenate it to the filename when it makes sense.
19965 Note that the Dwarf3 standard says (speaking of filenames in line
19966 information): ``The directory index is ignored for file names
19967 that represent full path names''. Thus ignoring dirname in the
19968 `else' branch below isn't an issue. */
19970 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
19972 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
19973 filename
= copy
.get ();
19976 cu
->get_builder ()->start_subfile (filename
);
19979 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
19980 buildsym_compunit constructor. */
19982 struct compunit_symtab
*
19983 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
19986 gdb_assert (m_builder
== nullptr);
19988 m_builder
.reset (new struct buildsym_compunit
19989 (per_cu
->dwarf2_per_objfile
->objfile
,
19990 name
, comp_dir
, language
, low_pc
));
19992 list_in_scope
= get_builder ()->get_file_symbols ();
19994 get_builder ()->record_debugformat ("DWARF 2");
19995 get_builder ()->record_producer (producer
);
19997 processing_has_namespace_info
= false;
19999 return get_builder ()->get_compunit_symtab ();
20003 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20004 struct dwarf2_cu
*cu
)
20006 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20007 struct comp_unit_head
*cu_header
= &cu
->header
;
20009 /* NOTE drow/2003-01-30: There used to be a comment and some special
20010 code here to turn a symbol with DW_AT_external and a
20011 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20012 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20013 with some versions of binutils) where shared libraries could have
20014 relocations against symbols in their debug information - the
20015 minimal symbol would have the right address, but the debug info
20016 would not. It's no longer necessary, because we will explicitly
20017 apply relocations when we read in the debug information now. */
20019 /* A DW_AT_location attribute with no contents indicates that a
20020 variable has been optimized away. */
20021 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20023 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20027 /* Handle one degenerate form of location expression specially, to
20028 preserve GDB's previous behavior when section offsets are
20029 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20030 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20032 if (attr
->form_is_block ()
20033 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20034 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20035 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20036 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20037 && (DW_BLOCK (attr
)->size
20038 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20040 unsigned int dummy
;
20042 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20043 SET_SYMBOL_VALUE_ADDRESS
20044 (sym
, cu
->header
.read_address (objfile
->obfd
,
20045 DW_BLOCK (attr
)->data
+ 1,
20048 SET_SYMBOL_VALUE_ADDRESS
20049 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20051 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20052 fixup_symbol_section (sym
, objfile
);
20053 SET_SYMBOL_VALUE_ADDRESS
20055 SYMBOL_VALUE_ADDRESS (sym
)
20056 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20060 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20061 expression evaluator, and use LOC_COMPUTED only when necessary
20062 (i.e. when the value of a register or memory location is
20063 referenced, or a thread-local block, etc.). Then again, it might
20064 not be worthwhile. I'm assuming that it isn't unless performance
20065 or memory numbers show me otherwise. */
20067 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20069 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20070 cu
->has_loclist
= true;
20073 /* Given a pointer to a DWARF information entry, figure out if we need
20074 to make a symbol table entry for it, and if so, create a new entry
20075 and return a pointer to it.
20076 If TYPE is NULL, determine symbol type from the die, otherwise
20077 used the passed type.
20078 If SPACE is not NULL, use it to hold the new symbol. If it is
20079 NULL, allocate a new symbol on the objfile's obstack. */
20081 static struct symbol
*
20082 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20083 struct symbol
*space
)
20085 struct dwarf2_per_objfile
*dwarf2_per_objfile
20086 = cu
->per_cu
->dwarf2_per_objfile
;
20087 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20088 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20089 struct symbol
*sym
= NULL
;
20091 struct attribute
*attr
= NULL
;
20092 struct attribute
*attr2
= NULL
;
20093 CORE_ADDR baseaddr
;
20094 struct pending
**list_to_add
= NULL
;
20096 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20098 baseaddr
= objfile
->text_section_offset ();
20100 name
= dwarf2_name (die
, cu
);
20103 const char *linkagename
;
20104 int suppress_add
= 0;
20109 sym
= allocate_symbol (objfile
);
20110 OBJSTAT (objfile
, n_syms
++);
20112 /* Cache this symbol's name and the name's demangled form (if any). */
20113 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20114 linkagename
= dwarf2_physname (name
, die
, cu
);
20115 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20117 /* Fortran does not have mangling standard and the mangling does differ
20118 between gfortran, iFort etc. */
20119 if (cu
->language
== language_fortran
20120 && symbol_get_demangled_name (sym
) == NULL
)
20121 symbol_set_demangled_name (sym
,
20122 dwarf2_full_name (name
, die
, cu
),
20125 /* Default assumptions.
20126 Use the passed type or decode it from the die. */
20127 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20128 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20130 SYMBOL_TYPE (sym
) = type
;
20132 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20133 attr
= dwarf2_attr (die
,
20134 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20136 if (attr
!= nullptr)
20138 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20141 attr
= dwarf2_attr (die
,
20142 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20144 if (attr
!= nullptr)
20146 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20147 struct file_entry
*fe
;
20149 if (cu
->line_header
!= NULL
)
20150 fe
= cu
->line_header
->file_name_at (file_index
);
20155 complaint (_("file index out of range"));
20157 symbol_set_symtab (sym
, fe
->symtab
);
20163 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20164 if (attr
!= nullptr)
20168 addr
= attr
->value_as_address ();
20169 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20170 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20172 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20173 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20174 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20175 add_symbol_to_list (sym
, cu
->list_in_scope
);
20177 case DW_TAG_subprogram
:
20178 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20180 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20181 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20182 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20183 || cu
->language
== language_ada
20184 || cu
->language
== language_fortran
)
20186 /* Subprograms marked external are stored as a global symbol.
20187 Ada and Fortran subprograms, whether marked external or
20188 not, are always stored as a global symbol, because we want
20189 to be able to access them globally. For instance, we want
20190 to be able to break on a nested subprogram without having
20191 to specify the context. */
20192 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20196 list_to_add
= cu
->list_in_scope
;
20199 case DW_TAG_inlined_subroutine
:
20200 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20202 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20203 SYMBOL_INLINED (sym
) = 1;
20204 list_to_add
= cu
->list_in_scope
;
20206 case DW_TAG_template_value_param
:
20208 /* Fall through. */
20209 case DW_TAG_constant
:
20210 case DW_TAG_variable
:
20211 case DW_TAG_member
:
20212 /* Compilation with minimal debug info may result in
20213 variables with missing type entries. Change the
20214 misleading `void' type to something sensible. */
20215 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20216 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20218 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20219 /* In the case of DW_TAG_member, we should only be called for
20220 static const members. */
20221 if (die
->tag
== DW_TAG_member
)
20223 /* dwarf2_add_field uses die_is_declaration,
20224 so we do the same. */
20225 gdb_assert (die_is_declaration (die
, cu
));
20228 if (attr
!= nullptr)
20230 dwarf2_const_value (attr
, sym
, cu
);
20231 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20234 if (attr2
&& (DW_UNSND (attr2
) != 0))
20235 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20237 list_to_add
= cu
->list_in_scope
;
20241 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20242 if (attr
!= nullptr)
20244 var_decode_location (attr
, sym
, cu
);
20245 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20247 /* Fortran explicitly imports any global symbols to the local
20248 scope by DW_TAG_common_block. */
20249 if (cu
->language
== language_fortran
&& die
->parent
20250 && die
->parent
->tag
== DW_TAG_common_block
)
20253 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20254 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20255 && !dwarf2_per_objfile
->has_section_at_zero
)
20257 /* When a static variable is eliminated by the linker,
20258 the corresponding debug information is not stripped
20259 out, but the variable address is set to null;
20260 do not add such variables into symbol table. */
20262 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20264 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20265 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20266 && dwarf2_per_objfile
->can_copy
)
20268 /* A global static variable might be subject to
20269 copy relocation. We first check for a local
20270 minsym, though, because maybe the symbol was
20271 marked hidden, in which case this would not
20273 bound_minimal_symbol found
20274 = (lookup_minimal_symbol_linkage
20275 (sym
->linkage_name (), objfile
));
20276 if (found
.minsym
!= nullptr)
20277 sym
->maybe_copied
= 1;
20280 /* A variable with DW_AT_external is never static,
20281 but it may be block-scoped. */
20283 = ((cu
->list_in_scope
20284 == cu
->get_builder ()->get_file_symbols ())
20285 ? cu
->get_builder ()->get_global_symbols ()
20286 : cu
->list_in_scope
);
20289 list_to_add
= cu
->list_in_scope
;
20293 /* We do not know the address of this symbol.
20294 If it is an external symbol and we have type information
20295 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20296 The address of the variable will then be determined from
20297 the minimal symbol table whenever the variable is
20299 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20301 /* Fortran explicitly imports any global symbols to the local
20302 scope by DW_TAG_common_block. */
20303 if (cu
->language
== language_fortran
&& die
->parent
20304 && die
->parent
->tag
== DW_TAG_common_block
)
20306 /* SYMBOL_CLASS doesn't matter here because
20307 read_common_block is going to reset it. */
20309 list_to_add
= cu
->list_in_scope
;
20311 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20312 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20314 /* A variable with DW_AT_external is never static, but it
20315 may be block-scoped. */
20317 = ((cu
->list_in_scope
20318 == cu
->get_builder ()->get_file_symbols ())
20319 ? cu
->get_builder ()->get_global_symbols ()
20320 : cu
->list_in_scope
);
20322 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20324 else if (!die_is_declaration (die
, cu
))
20326 /* Use the default LOC_OPTIMIZED_OUT class. */
20327 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20329 list_to_add
= cu
->list_in_scope
;
20333 case DW_TAG_formal_parameter
:
20335 /* If we are inside a function, mark this as an argument. If
20336 not, we might be looking at an argument to an inlined function
20337 when we do not have enough information to show inlined frames;
20338 pretend it's a local variable in that case so that the user can
20340 struct context_stack
*curr
20341 = cu
->get_builder ()->get_current_context_stack ();
20342 if (curr
!= nullptr && curr
->name
!= nullptr)
20343 SYMBOL_IS_ARGUMENT (sym
) = 1;
20344 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20345 if (attr
!= nullptr)
20347 var_decode_location (attr
, sym
, cu
);
20349 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20350 if (attr
!= nullptr)
20352 dwarf2_const_value (attr
, sym
, cu
);
20355 list_to_add
= cu
->list_in_scope
;
20358 case DW_TAG_unspecified_parameters
:
20359 /* From varargs functions; gdb doesn't seem to have any
20360 interest in this information, so just ignore it for now.
20363 case DW_TAG_template_type_param
:
20365 /* Fall through. */
20366 case DW_TAG_class_type
:
20367 case DW_TAG_interface_type
:
20368 case DW_TAG_structure_type
:
20369 case DW_TAG_union_type
:
20370 case DW_TAG_set_type
:
20371 case DW_TAG_enumeration_type
:
20372 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20373 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20376 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20377 really ever be static objects: otherwise, if you try
20378 to, say, break of a class's method and you're in a file
20379 which doesn't mention that class, it won't work unless
20380 the check for all static symbols in lookup_symbol_aux
20381 saves you. See the OtherFileClass tests in
20382 gdb.c++/namespace.exp. */
20386 buildsym_compunit
*builder
= cu
->get_builder ();
20388 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20389 && cu
->language
== language_cplus
20390 ? builder
->get_global_symbols ()
20391 : cu
->list_in_scope
);
20393 /* The semantics of C++ state that "struct foo {
20394 ... }" also defines a typedef for "foo". */
20395 if (cu
->language
== language_cplus
20396 || cu
->language
== language_ada
20397 || cu
->language
== language_d
20398 || cu
->language
== language_rust
)
20400 /* The symbol's name is already allocated along
20401 with this objfile, so we don't need to
20402 duplicate it for the type. */
20403 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20404 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20409 case DW_TAG_typedef
:
20410 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20411 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20412 list_to_add
= cu
->list_in_scope
;
20414 case DW_TAG_base_type
:
20415 case DW_TAG_subrange_type
:
20416 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20417 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20418 list_to_add
= cu
->list_in_scope
;
20420 case DW_TAG_enumerator
:
20421 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20422 if (attr
!= nullptr)
20424 dwarf2_const_value (attr
, sym
, cu
);
20427 /* NOTE: carlton/2003-11-10: See comment above in the
20428 DW_TAG_class_type, etc. block. */
20431 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20432 && cu
->language
== language_cplus
20433 ? cu
->get_builder ()->get_global_symbols ()
20434 : cu
->list_in_scope
);
20437 case DW_TAG_imported_declaration
:
20438 case DW_TAG_namespace
:
20439 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20440 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20442 case DW_TAG_module
:
20443 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20444 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20445 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20447 case DW_TAG_common_block
:
20448 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20449 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20450 add_symbol_to_list (sym
, cu
->list_in_scope
);
20453 /* Not a tag we recognize. Hopefully we aren't processing
20454 trash data, but since we must specifically ignore things
20455 we don't recognize, there is nothing else we should do at
20457 complaint (_("unsupported tag: '%s'"),
20458 dwarf_tag_name (die
->tag
));
20464 sym
->hash_next
= objfile
->template_symbols
;
20465 objfile
->template_symbols
= sym
;
20466 list_to_add
= NULL
;
20469 if (list_to_add
!= NULL
)
20470 add_symbol_to_list (sym
, list_to_add
);
20472 /* For the benefit of old versions of GCC, check for anonymous
20473 namespaces based on the demangled name. */
20474 if (!cu
->processing_has_namespace_info
20475 && cu
->language
== language_cplus
)
20476 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20481 /* Given an attr with a DW_FORM_dataN value in host byte order,
20482 zero-extend it as appropriate for the symbol's type. The DWARF
20483 standard (v4) is not entirely clear about the meaning of using
20484 DW_FORM_dataN for a constant with a signed type, where the type is
20485 wider than the data. The conclusion of a discussion on the DWARF
20486 list was that this is unspecified. We choose to always zero-extend
20487 because that is the interpretation long in use by GCC. */
20490 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20491 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20493 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20494 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20495 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20496 LONGEST l
= DW_UNSND (attr
);
20498 if (bits
< sizeof (*value
) * 8)
20500 l
&= ((LONGEST
) 1 << bits
) - 1;
20503 else if (bits
== sizeof (*value
) * 8)
20507 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20508 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20515 /* Read a constant value from an attribute. Either set *VALUE, or if
20516 the value does not fit in *VALUE, set *BYTES - either already
20517 allocated on the objfile obstack, or newly allocated on OBSTACK,
20518 or, set *BATON, if we translated the constant to a location
20522 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20523 const char *name
, struct obstack
*obstack
,
20524 struct dwarf2_cu
*cu
,
20525 LONGEST
*value
, const gdb_byte
**bytes
,
20526 struct dwarf2_locexpr_baton
**baton
)
20528 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20529 struct comp_unit_head
*cu_header
= &cu
->header
;
20530 struct dwarf_block
*blk
;
20531 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20532 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20538 switch (attr
->form
)
20541 case DW_FORM_addrx
:
20542 case DW_FORM_GNU_addr_index
:
20546 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20547 dwarf2_const_value_length_mismatch_complaint (name
,
20548 cu_header
->addr_size
,
20549 TYPE_LENGTH (type
));
20550 /* Symbols of this form are reasonably rare, so we just
20551 piggyback on the existing location code rather than writing
20552 a new implementation of symbol_computed_ops. */
20553 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20554 (*baton
)->per_cu
= cu
->per_cu
;
20555 gdb_assert ((*baton
)->per_cu
);
20557 (*baton
)->size
= 2 + cu_header
->addr_size
;
20558 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20559 (*baton
)->data
= data
;
20561 data
[0] = DW_OP_addr
;
20562 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20563 byte_order
, DW_ADDR (attr
));
20564 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20567 case DW_FORM_string
:
20570 case DW_FORM_GNU_str_index
:
20571 case DW_FORM_GNU_strp_alt
:
20572 /* DW_STRING is already allocated on the objfile obstack, point
20574 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20576 case DW_FORM_block1
:
20577 case DW_FORM_block2
:
20578 case DW_FORM_block4
:
20579 case DW_FORM_block
:
20580 case DW_FORM_exprloc
:
20581 case DW_FORM_data16
:
20582 blk
= DW_BLOCK (attr
);
20583 if (TYPE_LENGTH (type
) != blk
->size
)
20584 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20585 TYPE_LENGTH (type
));
20586 *bytes
= blk
->data
;
20589 /* The DW_AT_const_value attributes are supposed to carry the
20590 symbol's value "represented as it would be on the target
20591 architecture." By the time we get here, it's already been
20592 converted to host endianness, so we just need to sign- or
20593 zero-extend it as appropriate. */
20594 case DW_FORM_data1
:
20595 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20597 case DW_FORM_data2
:
20598 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20600 case DW_FORM_data4
:
20601 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20603 case DW_FORM_data8
:
20604 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20607 case DW_FORM_sdata
:
20608 case DW_FORM_implicit_const
:
20609 *value
= DW_SND (attr
);
20612 case DW_FORM_udata
:
20613 *value
= DW_UNSND (attr
);
20617 complaint (_("unsupported const value attribute form: '%s'"),
20618 dwarf_form_name (attr
->form
));
20625 /* Copy constant value from an attribute to a symbol. */
20628 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20629 struct dwarf2_cu
*cu
)
20631 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20633 const gdb_byte
*bytes
;
20634 struct dwarf2_locexpr_baton
*baton
;
20636 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20637 sym
->print_name (),
20638 &objfile
->objfile_obstack
, cu
,
20639 &value
, &bytes
, &baton
);
20643 SYMBOL_LOCATION_BATON (sym
) = baton
;
20644 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20646 else if (bytes
!= NULL
)
20648 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20649 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20653 SYMBOL_VALUE (sym
) = value
;
20654 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20658 /* Return the type of the die in question using its DW_AT_type attribute. */
20660 static struct type
*
20661 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20663 struct attribute
*type_attr
;
20665 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20668 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20669 /* A missing DW_AT_type represents a void type. */
20670 return objfile_type (objfile
)->builtin_void
;
20673 return lookup_die_type (die
, type_attr
, cu
);
20676 /* True iff CU's producer generates GNAT Ada auxiliary information
20677 that allows to find parallel types through that information instead
20678 of having to do expensive parallel lookups by type name. */
20681 need_gnat_info (struct dwarf2_cu
*cu
)
20683 /* Assume that the Ada compiler was GNAT, which always produces
20684 the auxiliary information. */
20685 return (cu
->language
== language_ada
);
20688 /* Return the auxiliary type of the die in question using its
20689 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20690 attribute is not present. */
20692 static struct type
*
20693 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20695 struct attribute
*type_attr
;
20697 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20701 return lookup_die_type (die
, type_attr
, cu
);
20704 /* If DIE has a descriptive_type attribute, then set the TYPE's
20705 descriptive type accordingly. */
20708 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20709 struct dwarf2_cu
*cu
)
20711 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20713 if (descriptive_type
)
20715 ALLOCATE_GNAT_AUX_TYPE (type
);
20716 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20720 /* Return the containing type of the die in question using its
20721 DW_AT_containing_type attribute. */
20723 static struct type
*
20724 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20726 struct attribute
*type_attr
;
20727 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20729 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20731 error (_("Dwarf Error: Problem turning containing type into gdb type "
20732 "[in module %s]"), objfile_name (objfile
));
20734 return lookup_die_type (die
, type_attr
, cu
);
20737 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20739 static struct type
*
20740 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20742 struct dwarf2_per_objfile
*dwarf2_per_objfile
20743 = cu
->per_cu
->dwarf2_per_objfile
;
20744 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20747 std::string message
20748 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20749 objfile_name (objfile
),
20750 sect_offset_str (cu
->header
.sect_off
),
20751 sect_offset_str (die
->sect_off
));
20752 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20754 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20757 /* Look up the type of DIE in CU using its type attribute ATTR.
20758 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20759 DW_AT_containing_type.
20760 If there is no type substitute an error marker. */
20762 static struct type
*
20763 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20764 struct dwarf2_cu
*cu
)
20766 struct dwarf2_per_objfile
*dwarf2_per_objfile
20767 = cu
->per_cu
->dwarf2_per_objfile
;
20768 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20769 struct type
*this_type
;
20771 gdb_assert (attr
->name
== DW_AT_type
20772 || attr
->name
== DW_AT_GNAT_descriptive_type
20773 || attr
->name
== DW_AT_containing_type
);
20775 /* First see if we have it cached. */
20777 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20779 struct dwarf2_per_cu_data
*per_cu
;
20780 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20782 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20783 dwarf2_per_objfile
);
20784 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20786 else if (attr
->form_is_ref ())
20788 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
20790 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20792 else if (attr
->form
== DW_FORM_ref_sig8
)
20794 ULONGEST signature
= DW_SIGNATURE (attr
);
20796 return get_signatured_type (die
, signature
, cu
);
20800 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20801 " at %s [in module %s]"),
20802 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20803 objfile_name (objfile
));
20804 return build_error_marker_type (cu
, die
);
20807 /* If not cached we need to read it in. */
20809 if (this_type
== NULL
)
20811 struct die_info
*type_die
= NULL
;
20812 struct dwarf2_cu
*type_cu
= cu
;
20814 if (attr
->form_is_ref ())
20815 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20816 if (type_die
== NULL
)
20817 return build_error_marker_type (cu
, die
);
20818 /* If we find the type now, it's probably because the type came
20819 from an inter-CU reference and the type's CU got expanded before
20821 this_type
= read_type_die (type_die
, type_cu
);
20824 /* If we still don't have a type use an error marker. */
20826 if (this_type
== NULL
)
20827 return build_error_marker_type (cu
, die
);
20832 /* Return the type in DIE, CU.
20833 Returns NULL for invalid types.
20835 This first does a lookup in die_type_hash,
20836 and only reads the die in if necessary.
20838 NOTE: This can be called when reading in partial or full symbols. */
20840 static struct type
*
20841 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20843 struct type
*this_type
;
20845 this_type
= get_die_type (die
, cu
);
20849 return read_type_die_1 (die
, cu
);
20852 /* Read the type in DIE, CU.
20853 Returns NULL for invalid types. */
20855 static struct type
*
20856 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20858 struct type
*this_type
= NULL
;
20862 case DW_TAG_class_type
:
20863 case DW_TAG_interface_type
:
20864 case DW_TAG_structure_type
:
20865 case DW_TAG_union_type
:
20866 this_type
= read_structure_type (die
, cu
);
20868 case DW_TAG_enumeration_type
:
20869 this_type
= read_enumeration_type (die
, cu
);
20871 case DW_TAG_subprogram
:
20872 case DW_TAG_subroutine_type
:
20873 case DW_TAG_inlined_subroutine
:
20874 this_type
= read_subroutine_type (die
, cu
);
20876 case DW_TAG_array_type
:
20877 this_type
= read_array_type (die
, cu
);
20879 case DW_TAG_set_type
:
20880 this_type
= read_set_type (die
, cu
);
20882 case DW_TAG_pointer_type
:
20883 this_type
= read_tag_pointer_type (die
, cu
);
20885 case DW_TAG_ptr_to_member_type
:
20886 this_type
= read_tag_ptr_to_member_type (die
, cu
);
20888 case DW_TAG_reference_type
:
20889 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
20891 case DW_TAG_rvalue_reference_type
:
20892 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
20894 case DW_TAG_const_type
:
20895 this_type
= read_tag_const_type (die
, cu
);
20897 case DW_TAG_volatile_type
:
20898 this_type
= read_tag_volatile_type (die
, cu
);
20900 case DW_TAG_restrict_type
:
20901 this_type
= read_tag_restrict_type (die
, cu
);
20903 case DW_TAG_string_type
:
20904 this_type
= read_tag_string_type (die
, cu
);
20906 case DW_TAG_typedef
:
20907 this_type
= read_typedef (die
, cu
);
20909 case DW_TAG_subrange_type
:
20910 this_type
= read_subrange_type (die
, cu
);
20912 case DW_TAG_base_type
:
20913 this_type
= read_base_type (die
, cu
);
20915 case DW_TAG_unspecified_type
:
20916 this_type
= read_unspecified_type (die
, cu
);
20918 case DW_TAG_namespace
:
20919 this_type
= read_namespace_type (die
, cu
);
20921 case DW_TAG_module
:
20922 this_type
= read_module_type (die
, cu
);
20924 case DW_TAG_atomic_type
:
20925 this_type
= read_tag_atomic_type (die
, cu
);
20928 complaint (_("unexpected tag in read_type_die: '%s'"),
20929 dwarf_tag_name (die
->tag
));
20936 /* See if we can figure out if the class lives in a namespace. We do
20937 this by looking for a member function; its demangled name will
20938 contain namespace info, if there is any.
20939 Return the computed name or NULL.
20940 Space for the result is allocated on the objfile's obstack.
20941 This is the full-die version of guess_partial_die_structure_name.
20942 In this case we know DIE has no useful parent. */
20944 static const char *
20945 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20947 struct die_info
*spec_die
;
20948 struct dwarf2_cu
*spec_cu
;
20949 struct die_info
*child
;
20950 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20953 spec_die
= die_specification (die
, &spec_cu
);
20954 if (spec_die
!= NULL
)
20960 for (child
= die
->child
;
20962 child
= child
->sibling
)
20964 if (child
->tag
== DW_TAG_subprogram
)
20966 const char *linkage_name
= dw2_linkage_name (child
, cu
);
20968 if (linkage_name
!= NULL
)
20970 gdb::unique_xmalloc_ptr
<char> actual_name
20971 (language_class_name_from_physname (cu
->language_defn
,
20973 const char *name
= NULL
;
20975 if (actual_name
!= NULL
)
20977 const char *die_name
= dwarf2_name (die
, cu
);
20979 if (die_name
!= NULL
20980 && strcmp (die_name
, actual_name
.get ()) != 0)
20982 /* Strip off the class name from the full name.
20983 We want the prefix. */
20984 int die_name_len
= strlen (die_name
);
20985 int actual_name_len
= strlen (actual_name
.get ());
20986 const char *ptr
= actual_name
.get ();
20988 /* Test for '::' as a sanity check. */
20989 if (actual_name_len
> die_name_len
+ 2
20990 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
20991 name
= obstack_strndup (
20992 &objfile
->per_bfd
->storage_obstack
,
20993 ptr
, actual_name_len
- die_name_len
- 2);
21004 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21005 prefix part in such case. See
21006 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21008 static const char *
21009 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21011 struct attribute
*attr
;
21014 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21015 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21018 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21021 attr
= dw2_linkage_name_attr (die
, cu
);
21022 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21025 /* dwarf2_name had to be already called. */
21026 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21028 /* Strip the base name, keep any leading namespaces/classes. */
21029 base
= strrchr (DW_STRING (attr
), ':');
21030 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21033 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21034 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21036 &base
[-1] - DW_STRING (attr
));
21039 /* Return the name of the namespace/class that DIE is defined within,
21040 or "" if we can't tell. The caller should not xfree the result.
21042 For example, if we're within the method foo() in the following
21052 then determine_prefix on foo's die will return "N::C". */
21054 static const char *
21055 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21057 struct dwarf2_per_objfile
*dwarf2_per_objfile
21058 = cu
->per_cu
->dwarf2_per_objfile
;
21059 struct die_info
*parent
, *spec_die
;
21060 struct dwarf2_cu
*spec_cu
;
21061 struct type
*parent_type
;
21062 const char *retval
;
21064 if (cu
->language
!= language_cplus
21065 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21066 && cu
->language
!= language_rust
)
21069 retval
= anonymous_struct_prefix (die
, cu
);
21073 /* We have to be careful in the presence of DW_AT_specification.
21074 For example, with GCC 3.4, given the code
21078 // Definition of N::foo.
21082 then we'll have a tree of DIEs like this:
21084 1: DW_TAG_compile_unit
21085 2: DW_TAG_namespace // N
21086 3: DW_TAG_subprogram // declaration of N::foo
21087 4: DW_TAG_subprogram // definition of N::foo
21088 DW_AT_specification // refers to die #3
21090 Thus, when processing die #4, we have to pretend that we're in
21091 the context of its DW_AT_specification, namely the contex of die
21094 spec_die
= die_specification (die
, &spec_cu
);
21095 if (spec_die
== NULL
)
21096 parent
= die
->parent
;
21099 parent
= spec_die
->parent
;
21103 if (parent
== NULL
)
21105 else if (parent
->building_fullname
)
21108 const char *parent_name
;
21110 /* It has been seen on RealView 2.2 built binaries,
21111 DW_TAG_template_type_param types actually _defined_ as
21112 children of the parent class:
21115 template class <class Enum> Class{};
21116 Class<enum E> class_e;
21118 1: DW_TAG_class_type (Class)
21119 2: DW_TAG_enumeration_type (E)
21120 3: DW_TAG_enumerator (enum1:0)
21121 3: DW_TAG_enumerator (enum2:1)
21123 2: DW_TAG_template_type_param
21124 DW_AT_type DW_FORM_ref_udata (E)
21126 Besides being broken debug info, it can put GDB into an
21127 infinite loop. Consider:
21129 When we're building the full name for Class<E>, we'll start
21130 at Class, and go look over its template type parameters,
21131 finding E. We'll then try to build the full name of E, and
21132 reach here. We're now trying to build the full name of E,
21133 and look over the parent DIE for containing scope. In the
21134 broken case, if we followed the parent DIE of E, we'd again
21135 find Class, and once again go look at its template type
21136 arguments, etc., etc. Simply don't consider such parent die
21137 as source-level parent of this die (it can't be, the language
21138 doesn't allow it), and break the loop here. */
21139 name
= dwarf2_name (die
, cu
);
21140 parent_name
= dwarf2_name (parent
, cu
);
21141 complaint (_("template param type '%s' defined within parent '%s'"),
21142 name
? name
: "<unknown>",
21143 parent_name
? parent_name
: "<unknown>");
21147 switch (parent
->tag
)
21149 case DW_TAG_namespace
:
21150 parent_type
= read_type_die (parent
, cu
);
21151 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21152 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21153 Work around this problem here. */
21154 if (cu
->language
== language_cplus
21155 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21157 /* We give a name to even anonymous namespaces. */
21158 return TYPE_NAME (parent_type
);
21159 case DW_TAG_class_type
:
21160 case DW_TAG_interface_type
:
21161 case DW_TAG_structure_type
:
21162 case DW_TAG_union_type
:
21163 case DW_TAG_module
:
21164 parent_type
= read_type_die (parent
, cu
);
21165 if (TYPE_NAME (parent_type
) != NULL
)
21166 return TYPE_NAME (parent_type
);
21168 /* An anonymous structure is only allowed non-static data
21169 members; no typedefs, no member functions, et cetera.
21170 So it does not need a prefix. */
21172 case DW_TAG_compile_unit
:
21173 case DW_TAG_partial_unit
:
21174 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21175 if (cu
->language
== language_cplus
21176 && !dwarf2_per_objfile
->types
.empty ()
21177 && die
->child
!= NULL
21178 && (die
->tag
== DW_TAG_class_type
21179 || die
->tag
== DW_TAG_structure_type
21180 || die
->tag
== DW_TAG_union_type
))
21182 const char *name
= guess_full_die_structure_name (die
, cu
);
21187 case DW_TAG_subprogram
:
21188 /* Nested subroutines in Fortran get a prefix with the name
21189 of the parent's subroutine. */
21190 if (cu
->language
== language_fortran
)
21192 if ((die
->tag
== DW_TAG_subprogram
)
21193 && (dwarf2_name (parent
, cu
) != NULL
))
21194 return dwarf2_name (parent
, cu
);
21196 return determine_prefix (parent
, cu
);
21197 case DW_TAG_enumeration_type
:
21198 parent_type
= read_type_die (parent
, cu
);
21199 if (TYPE_DECLARED_CLASS (parent_type
))
21201 if (TYPE_NAME (parent_type
) != NULL
)
21202 return TYPE_NAME (parent_type
);
21205 /* Fall through. */
21207 return determine_prefix (parent
, cu
);
21211 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21212 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21213 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21214 an obconcat, otherwise allocate storage for the result. The CU argument is
21215 used to determine the language and hence, the appropriate separator. */
21217 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21220 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21221 int physname
, struct dwarf2_cu
*cu
)
21223 const char *lead
= "";
21226 if (suffix
== NULL
|| suffix
[0] == '\0'
21227 || prefix
== NULL
|| prefix
[0] == '\0')
21229 else if (cu
->language
== language_d
)
21231 /* For D, the 'main' function could be defined in any module, but it
21232 should never be prefixed. */
21233 if (strcmp (suffix
, "D main") == 0)
21241 else if (cu
->language
== language_fortran
&& physname
)
21243 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21244 DW_AT_MIPS_linkage_name is preferred and used instead. */
21252 if (prefix
== NULL
)
21254 if (suffix
== NULL
)
21261 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21263 strcpy (retval
, lead
);
21264 strcat (retval
, prefix
);
21265 strcat (retval
, sep
);
21266 strcat (retval
, suffix
);
21271 /* We have an obstack. */
21272 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21276 /* Return sibling of die, NULL if no sibling. */
21278 static struct die_info
*
21279 sibling_die (struct die_info
*die
)
21281 return die
->sibling
;
21284 /* Get name of a die, return NULL if not found. */
21286 static const char *
21287 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21288 struct objfile
*objfile
)
21290 if (name
&& cu
->language
== language_cplus
)
21292 std::string canon_name
= cp_canonicalize_string (name
);
21294 if (!canon_name
.empty ())
21296 if (canon_name
!= name
)
21297 name
= objfile
->intern (canon_name
);
21304 /* Get name of a die, return NULL if not found.
21305 Anonymous namespaces are converted to their magic string. */
21307 static const char *
21308 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21310 struct attribute
*attr
;
21311 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21313 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21314 if ((!attr
|| !DW_STRING (attr
))
21315 && die
->tag
!= DW_TAG_namespace
21316 && die
->tag
!= DW_TAG_class_type
21317 && die
->tag
!= DW_TAG_interface_type
21318 && die
->tag
!= DW_TAG_structure_type
21319 && die
->tag
!= DW_TAG_union_type
)
21324 case DW_TAG_compile_unit
:
21325 case DW_TAG_partial_unit
:
21326 /* Compilation units have a DW_AT_name that is a filename, not
21327 a source language identifier. */
21328 case DW_TAG_enumeration_type
:
21329 case DW_TAG_enumerator
:
21330 /* These tags always have simple identifiers already; no need
21331 to canonicalize them. */
21332 return DW_STRING (attr
);
21334 case DW_TAG_namespace
:
21335 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21336 return DW_STRING (attr
);
21337 return CP_ANONYMOUS_NAMESPACE_STR
;
21339 case DW_TAG_class_type
:
21340 case DW_TAG_interface_type
:
21341 case DW_TAG_structure_type
:
21342 case DW_TAG_union_type
:
21343 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21344 structures or unions. These were of the form "._%d" in GCC 4.1,
21345 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21346 and GCC 4.4. We work around this problem by ignoring these. */
21347 if (attr
&& DW_STRING (attr
)
21348 && (startswith (DW_STRING (attr
), "._")
21349 || startswith (DW_STRING (attr
), "<anonymous")))
21352 /* GCC might emit a nameless typedef that has a linkage name. See
21353 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21354 if (!attr
|| DW_STRING (attr
) == NULL
)
21356 attr
= dw2_linkage_name_attr (die
, cu
);
21357 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21360 /* Avoid demangling DW_STRING (attr) the second time on a second
21361 call for the same DIE. */
21362 if (!DW_STRING_IS_CANONICAL (attr
))
21364 gdb::unique_xmalloc_ptr
<char> demangled
21365 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21366 if (demangled
== nullptr)
21369 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21370 DW_STRING_IS_CANONICAL (attr
) = 1;
21373 /* Strip any leading namespaces/classes, keep only the base name.
21374 DW_AT_name for named DIEs does not contain the prefixes. */
21375 const char *base
= strrchr (DW_STRING (attr
), ':');
21376 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21379 return DW_STRING (attr
);
21387 if (!DW_STRING_IS_CANONICAL (attr
))
21389 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21391 DW_STRING_IS_CANONICAL (attr
) = 1;
21393 return DW_STRING (attr
);
21396 /* Return the die that this die in an extension of, or NULL if there
21397 is none. *EXT_CU is the CU containing DIE on input, and the CU
21398 containing the return value on output. */
21400 static struct die_info
*
21401 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21403 struct attribute
*attr
;
21405 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21409 return follow_die_ref (die
, attr
, ext_cu
);
21412 /* A convenience function that returns an "unknown" DWARF name,
21413 including the value of V. STR is the name of the entity being
21414 printed, e.g., "TAG". */
21416 static const char *
21417 dwarf_unknown (const char *str
, unsigned v
)
21419 char *cell
= get_print_cell ();
21420 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21424 /* Convert a DIE tag into its string name. */
21426 static const char *
21427 dwarf_tag_name (unsigned tag
)
21429 const char *name
= get_DW_TAG_name (tag
);
21432 return dwarf_unknown ("TAG", tag
);
21437 /* Convert a DWARF attribute code into its string name. */
21439 static const char *
21440 dwarf_attr_name (unsigned attr
)
21444 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21445 if (attr
== DW_AT_MIPS_fde
)
21446 return "DW_AT_MIPS_fde";
21448 if (attr
== DW_AT_HP_block_index
)
21449 return "DW_AT_HP_block_index";
21452 name
= get_DW_AT_name (attr
);
21455 return dwarf_unknown ("AT", attr
);
21460 /* Convert a DWARF value form code into its string name. */
21462 static const char *
21463 dwarf_form_name (unsigned form
)
21465 const char *name
= get_DW_FORM_name (form
);
21468 return dwarf_unknown ("FORM", form
);
21473 static const char *
21474 dwarf_bool_name (unsigned mybool
)
21482 /* Convert a DWARF type code into its string name. */
21484 static const char *
21485 dwarf_type_encoding_name (unsigned enc
)
21487 const char *name
= get_DW_ATE_name (enc
);
21490 return dwarf_unknown ("ATE", enc
);
21496 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21500 print_spaces (indent
, f
);
21501 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21502 dwarf_tag_name (die
->tag
), die
->abbrev
,
21503 sect_offset_str (die
->sect_off
));
21505 if (die
->parent
!= NULL
)
21507 print_spaces (indent
, f
);
21508 fprintf_unfiltered (f
, " parent at offset: %s\n",
21509 sect_offset_str (die
->parent
->sect_off
));
21512 print_spaces (indent
, f
);
21513 fprintf_unfiltered (f
, " has children: %s\n",
21514 dwarf_bool_name (die
->child
!= NULL
));
21516 print_spaces (indent
, f
);
21517 fprintf_unfiltered (f
, " attributes:\n");
21519 for (i
= 0; i
< die
->num_attrs
; ++i
)
21521 print_spaces (indent
, f
);
21522 fprintf_unfiltered (f
, " %s (%s) ",
21523 dwarf_attr_name (die
->attrs
[i
].name
),
21524 dwarf_form_name (die
->attrs
[i
].form
));
21526 switch (die
->attrs
[i
].form
)
21529 case DW_FORM_addrx
:
21530 case DW_FORM_GNU_addr_index
:
21531 fprintf_unfiltered (f
, "address: ");
21532 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21534 case DW_FORM_block2
:
21535 case DW_FORM_block4
:
21536 case DW_FORM_block
:
21537 case DW_FORM_block1
:
21538 fprintf_unfiltered (f
, "block: size %s",
21539 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21541 case DW_FORM_exprloc
:
21542 fprintf_unfiltered (f
, "expression: size %s",
21543 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21545 case DW_FORM_data16
:
21546 fprintf_unfiltered (f
, "constant of 16 bytes");
21548 case DW_FORM_ref_addr
:
21549 fprintf_unfiltered (f
, "ref address: ");
21550 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21552 case DW_FORM_GNU_ref_alt
:
21553 fprintf_unfiltered (f
, "alt ref address: ");
21554 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21560 case DW_FORM_ref_udata
:
21561 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21562 (long) (DW_UNSND (&die
->attrs
[i
])));
21564 case DW_FORM_data1
:
21565 case DW_FORM_data2
:
21566 case DW_FORM_data4
:
21567 case DW_FORM_data8
:
21568 case DW_FORM_udata
:
21569 case DW_FORM_sdata
:
21570 fprintf_unfiltered (f
, "constant: %s",
21571 pulongest (DW_UNSND (&die
->attrs
[i
])));
21573 case DW_FORM_sec_offset
:
21574 fprintf_unfiltered (f
, "section offset: %s",
21575 pulongest (DW_UNSND (&die
->attrs
[i
])));
21577 case DW_FORM_ref_sig8
:
21578 fprintf_unfiltered (f
, "signature: %s",
21579 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21581 case DW_FORM_string
:
21583 case DW_FORM_line_strp
:
21585 case DW_FORM_GNU_str_index
:
21586 case DW_FORM_GNU_strp_alt
:
21587 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21588 DW_STRING (&die
->attrs
[i
])
21589 ? DW_STRING (&die
->attrs
[i
]) : "",
21590 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21593 if (DW_UNSND (&die
->attrs
[i
]))
21594 fprintf_unfiltered (f
, "flag: TRUE");
21596 fprintf_unfiltered (f
, "flag: FALSE");
21598 case DW_FORM_flag_present
:
21599 fprintf_unfiltered (f
, "flag: TRUE");
21601 case DW_FORM_indirect
:
21602 /* The reader will have reduced the indirect form to
21603 the "base form" so this form should not occur. */
21604 fprintf_unfiltered (f
,
21605 "unexpected attribute form: DW_FORM_indirect");
21607 case DW_FORM_implicit_const
:
21608 fprintf_unfiltered (f
, "constant: %s",
21609 plongest (DW_SND (&die
->attrs
[i
])));
21612 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21613 die
->attrs
[i
].form
);
21616 fprintf_unfiltered (f
, "\n");
21621 dump_die_for_error (struct die_info
*die
)
21623 dump_die_shallow (gdb_stderr
, 0, die
);
21627 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21629 int indent
= level
* 4;
21631 gdb_assert (die
!= NULL
);
21633 if (level
>= max_level
)
21636 dump_die_shallow (f
, indent
, die
);
21638 if (die
->child
!= NULL
)
21640 print_spaces (indent
, f
);
21641 fprintf_unfiltered (f
, " Children:");
21642 if (level
+ 1 < max_level
)
21644 fprintf_unfiltered (f
, "\n");
21645 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21649 fprintf_unfiltered (f
,
21650 " [not printed, max nesting level reached]\n");
21654 if (die
->sibling
!= NULL
&& level
> 0)
21656 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21660 /* This is called from the pdie macro in gdbinit.in.
21661 It's not static so gcc will keep a copy callable from gdb. */
21664 dump_die (struct die_info
*die
, int max_level
)
21666 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21670 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21674 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21675 to_underlying (die
->sect_off
),
21681 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
21685 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
21687 if (attr
->form_is_ref ())
21688 return (sect_offset
) DW_UNSND (attr
);
21690 complaint (_("unsupported die ref attribute form: '%s'"),
21691 dwarf_form_name (attr
->form
));
21695 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
21696 * the value held by the attribute is not constant. */
21699 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
21701 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
21702 return DW_SND (attr
);
21703 else if (attr
->form
== DW_FORM_udata
21704 || attr
->form
== DW_FORM_data1
21705 || attr
->form
== DW_FORM_data2
21706 || attr
->form
== DW_FORM_data4
21707 || attr
->form
== DW_FORM_data8
)
21708 return DW_UNSND (attr
);
21711 /* For DW_FORM_data16 see attribute::form_is_constant. */
21712 complaint (_("Attribute value is not a constant (%s)"),
21713 dwarf_form_name (attr
->form
));
21714 return default_value
;
21718 /* Follow reference or signature attribute ATTR of SRC_DIE.
21719 On entry *REF_CU is the CU of SRC_DIE.
21720 On exit *REF_CU is the CU of the result. */
21722 static struct die_info
*
21723 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21724 struct dwarf2_cu
**ref_cu
)
21726 struct die_info
*die
;
21728 if (attr
->form_is_ref ())
21729 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21730 else if (attr
->form
== DW_FORM_ref_sig8
)
21731 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21734 dump_die_for_error (src_die
);
21735 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21736 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21742 /* Follow reference OFFSET.
21743 On entry *REF_CU is the CU of the source die referencing OFFSET.
21744 On exit *REF_CU is the CU of the result.
21745 Returns NULL if OFFSET is invalid. */
21747 static struct die_info
*
21748 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21749 struct dwarf2_cu
**ref_cu
)
21751 struct die_info temp_die
;
21752 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21753 struct dwarf2_per_objfile
*dwarf2_per_objfile
21754 = cu
->per_cu
->dwarf2_per_objfile
;
21756 gdb_assert (cu
->per_cu
!= NULL
);
21760 if (cu
->per_cu
->is_debug_types
)
21762 /* .debug_types CUs cannot reference anything outside their CU.
21763 If they need to, they have to reference a signatured type via
21764 DW_FORM_ref_sig8. */
21765 if (!cu
->header
.offset_in_cu_p (sect_off
))
21768 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21769 || !cu
->header
.offset_in_cu_p (sect_off
))
21771 struct dwarf2_per_cu_data
*per_cu
;
21773 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21774 dwarf2_per_objfile
);
21776 /* If necessary, add it to the queue and load its DIEs. */
21777 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21778 load_full_comp_unit (per_cu
, false, cu
->language
);
21780 target_cu
= per_cu
->cu
;
21782 else if (cu
->dies
== NULL
)
21784 /* We're loading full DIEs during partial symbol reading. */
21785 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21786 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21789 *ref_cu
= target_cu
;
21790 temp_die
.sect_off
= sect_off
;
21792 if (target_cu
!= cu
)
21793 target_cu
->ancestor
= cu
;
21795 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21797 to_underlying (sect_off
));
21800 /* Follow reference attribute ATTR of SRC_DIE.
21801 On entry *REF_CU is the CU of SRC_DIE.
21802 On exit *REF_CU is the CU of the result. */
21804 static struct die_info
*
21805 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21806 struct dwarf2_cu
**ref_cu
)
21808 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21809 struct dwarf2_cu
*cu
= *ref_cu
;
21810 struct die_info
*die
;
21812 die
= follow_die_offset (sect_off
,
21813 (attr
->form
== DW_FORM_GNU_ref_alt
21814 || cu
->per_cu
->is_dwz
),
21817 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21818 "at %s [in module %s]"),
21819 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21820 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21827 struct dwarf2_locexpr_baton
21828 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21829 dwarf2_per_cu_data
*per_cu
,
21830 CORE_ADDR (*get_frame_pc
) (void *baton
),
21831 void *baton
, bool resolve_abstract_p
)
21833 struct dwarf2_cu
*cu
;
21834 struct die_info
*die
;
21835 struct attribute
*attr
;
21836 struct dwarf2_locexpr_baton retval
;
21837 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21838 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21840 if (per_cu
->cu
== NULL
)
21841 load_cu (per_cu
, false);
21845 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21846 Instead just throw an error, not much else we can do. */
21847 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21848 sect_offset_str (sect_off
), objfile_name (objfile
));
21851 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21853 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21854 sect_offset_str (sect_off
), objfile_name (objfile
));
21856 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21857 if (!attr
&& resolve_abstract_p
21858 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21859 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21861 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21862 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21863 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21865 for (const auto &cand_off
21866 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21868 struct dwarf2_cu
*cand_cu
= cu
;
21869 struct die_info
*cand
21870 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21873 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21876 CORE_ADDR pc_low
, pc_high
;
21877 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21878 if (pc_low
== ((CORE_ADDR
) -1))
21880 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21881 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21882 if (!(pc_low
<= pc
&& pc
< pc_high
))
21886 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21893 /* DWARF: "If there is no such attribute, then there is no effect.".
21894 DATA is ignored if SIZE is 0. */
21896 retval
.data
= NULL
;
21899 else if (attr
->form_is_section_offset ())
21901 struct dwarf2_loclist_baton loclist_baton
;
21902 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21905 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21907 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21909 retval
.size
= size
;
21913 if (!attr
->form_is_block ())
21914 error (_("Dwarf Error: DIE at %s referenced in module %s "
21915 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21916 sect_offset_str (sect_off
), objfile_name (objfile
));
21918 retval
.data
= DW_BLOCK (attr
)->data
;
21919 retval
.size
= DW_BLOCK (attr
)->size
;
21921 retval
.per_cu
= cu
->per_cu
;
21923 age_cached_comp_units (dwarf2_per_objfile
);
21930 struct dwarf2_locexpr_baton
21931 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21932 dwarf2_per_cu_data
*per_cu
,
21933 CORE_ADDR (*get_frame_pc
) (void *baton
),
21936 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21938 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21941 /* Write a constant of a given type as target-ordered bytes into
21944 static const gdb_byte
*
21945 write_constant_as_bytes (struct obstack
*obstack
,
21946 enum bfd_endian byte_order
,
21953 *len
= TYPE_LENGTH (type
);
21954 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21955 store_unsigned_integer (result
, *len
, byte_order
, value
);
21963 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21964 dwarf2_per_cu_data
*per_cu
,
21968 struct dwarf2_cu
*cu
;
21969 struct die_info
*die
;
21970 struct attribute
*attr
;
21971 const gdb_byte
*result
= NULL
;
21974 enum bfd_endian byte_order
;
21975 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
21977 if (per_cu
->cu
== NULL
)
21978 load_cu (per_cu
, false);
21982 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21983 Instead just throw an error, not much else we can do. */
21984 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21985 sect_offset_str (sect_off
), objfile_name (objfile
));
21988 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21990 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21991 sect_offset_str (sect_off
), objfile_name (objfile
));
21993 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21997 byte_order
= (bfd_big_endian (objfile
->obfd
)
21998 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22000 switch (attr
->form
)
22003 case DW_FORM_addrx
:
22004 case DW_FORM_GNU_addr_index
:
22008 *len
= cu
->header
.addr_size
;
22009 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22010 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22014 case DW_FORM_string
:
22017 case DW_FORM_GNU_str_index
:
22018 case DW_FORM_GNU_strp_alt
:
22019 /* DW_STRING is already allocated on the objfile obstack, point
22021 result
= (const gdb_byte
*) DW_STRING (attr
);
22022 *len
= strlen (DW_STRING (attr
));
22024 case DW_FORM_block1
:
22025 case DW_FORM_block2
:
22026 case DW_FORM_block4
:
22027 case DW_FORM_block
:
22028 case DW_FORM_exprloc
:
22029 case DW_FORM_data16
:
22030 result
= DW_BLOCK (attr
)->data
;
22031 *len
= DW_BLOCK (attr
)->size
;
22034 /* The DW_AT_const_value attributes are supposed to carry the
22035 symbol's value "represented as it would be on the target
22036 architecture." By the time we get here, it's already been
22037 converted to host endianness, so we just need to sign- or
22038 zero-extend it as appropriate. */
22039 case DW_FORM_data1
:
22040 type
= die_type (die
, cu
);
22041 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22042 if (result
== NULL
)
22043 result
= write_constant_as_bytes (obstack
, byte_order
,
22046 case DW_FORM_data2
:
22047 type
= die_type (die
, cu
);
22048 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22049 if (result
== NULL
)
22050 result
= write_constant_as_bytes (obstack
, byte_order
,
22053 case DW_FORM_data4
:
22054 type
= die_type (die
, cu
);
22055 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22056 if (result
== NULL
)
22057 result
= write_constant_as_bytes (obstack
, byte_order
,
22060 case DW_FORM_data8
:
22061 type
= die_type (die
, cu
);
22062 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22063 if (result
== NULL
)
22064 result
= write_constant_as_bytes (obstack
, byte_order
,
22068 case DW_FORM_sdata
:
22069 case DW_FORM_implicit_const
:
22070 type
= die_type (die
, cu
);
22071 result
= write_constant_as_bytes (obstack
, byte_order
,
22072 type
, DW_SND (attr
), len
);
22075 case DW_FORM_udata
:
22076 type
= die_type (die
, cu
);
22077 result
= write_constant_as_bytes (obstack
, byte_order
,
22078 type
, DW_UNSND (attr
), len
);
22082 complaint (_("unsupported const value attribute form: '%s'"),
22083 dwarf_form_name (attr
->form
));
22093 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22094 dwarf2_per_cu_data
*per_cu
)
22096 struct dwarf2_cu
*cu
;
22097 struct die_info
*die
;
22099 if (per_cu
->cu
== NULL
)
22100 load_cu (per_cu
, false);
22105 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22109 return die_type (die
, cu
);
22115 dwarf2_get_die_type (cu_offset die_offset
,
22116 struct dwarf2_per_cu_data
*per_cu
)
22118 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22119 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22122 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22123 On entry *REF_CU is the CU of SRC_DIE.
22124 On exit *REF_CU is the CU of the result.
22125 Returns NULL if the referenced DIE isn't found. */
22127 static struct die_info
*
22128 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22129 struct dwarf2_cu
**ref_cu
)
22131 struct die_info temp_die
;
22132 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22133 struct die_info
*die
;
22135 /* While it might be nice to assert sig_type->type == NULL here,
22136 we can get here for DW_AT_imported_declaration where we need
22137 the DIE not the type. */
22139 /* If necessary, add it to the queue and load its DIEs. */
22141 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22142 read_signatured_type (sig_type
);
22144 sig_cu
= sig_type
->per_cu
.cu
;
22145 gdb_assert (sig_cu
!= NULL
);
22146 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22147 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22148 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22149 to_underlying (temp_die
.sect_off
));
22152 struct dwarf2_per_objfile
*dwarf2_per_objfile
22153 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22155 /* For .gdb_index version 7 keep track of included TUs.
22156 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22157 if (dwarf2_per_objfile
->index_table
!= NULL
22158 && dwarf2_per_objfile
->index_table
->version
<= 7)
22160 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22165 sig_cu
->ancestor
= cu
;
22173 /* Follow signatured type referenced by ATTR in SRC_DIE.
22174 On entry *REF_CU is the CU of SRC_DIE.
22175 On exit *REF_CU is the CU of the result.
22176 The result is the DIE of the type.
22177 If the referenced type cannot be found an error is thrown. */
22179 static struct die_info
*
22180 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22181 struct dwarf2_cu
**ref_cu
)
22183 ULONGEST signature
= DW_SIGNATURE (attr
);
22184 struct signatured_type
*sig_type
;
22185 struct die_info
*die
;
22187 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22189 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22190 /* sig_type will be NULL if the signatured type is missing from
22192 if (sig_type
== NULL
)
22194 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22195 " from DIE at %s [in module %s]"),
22196 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22197 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22200 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22203 dump_die_for_error (src_die
);
22204 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22205 " from DIE at %s [in module %s]"),
22206 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22207 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22213 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22214 reading in and processing the type unit if necessary. */
22216 static struct type
*
22217 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22218 struct dwarf2_cu
*cu
)
22220 struct dwarf2_per_objfile
*dwarf2_per_objfile
22221 = cu
->per_cu
->dwarf2_per_objfile
;
22222 struct signatured_type
*sig_type
;
22223 struct dwarf2_cu
*type_cu
;
22224 struct die_info
*type_die
;
22227 sig_type
= lookup_signatured_type (cu
, signature
);
22228 /* sig_type will be NULL if the signatured type is missing from
22230 if (sig_type
== NULL
)
22232 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22233 " from DIE at %s [in module %s]"),
22234 hex_string (signature
), sect_offset_str (die
->sect_off
),
22235 objfile_name (dwarf2_per_objfile
->objfile
));
22236 return build_error_marker_type (cu
, die
);
22239 /* If we already know the type we're done. */
22240 if (sig_type
->type
!= NULL
)
22241 return sig_type
->type
;
22244 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22245 if (type_die
!= NULL
)
22247 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22248 is created. This is important, for example, because for c++ classes
22249 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22250 type
= read_type_die (type_die
, type_cu
);
22253 complaint (_("Dwarf Error: Cannot build signatured type %s"
22254 " referenced from DIE at %s [in module %s]"),
22255 hex_string (signature
), sect_offset_str (die
->sect_off
),
22256 objfile_name (dwarf2_per_objfile
->objfile
));
22257 type
= build_error_marker_type (cu
, die
);
22262 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22263 " from DIE at %s [in module %s]"),
22264 hex_string (signature
), sect_offset_str (die
->sect_off
),
22265 objfile_name (dwarf2_per_objfile
->objfile
));
22266 type
= build_error_marker_type (cu
, die
);
22268 sig_type
->type
= type
;
22273 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22274 reading in and processing the type unit if necessary. */
22276 static struct type
*
22277 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22278 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22280 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22281 if (attr
->form_is_ref ())
22283 struct dwarf2_cu
*type_cu
= cu
;
22284 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22286 return read_type_die (type_die
, type_cu
);
22288 else if (attr
->form
== DW_FORM_ref_sig8
)
22290 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22294 struct dwarf2_per_objfile
*dwarf2_per_objfile
22295 = cu
->per_cu
->dwarf2_per_objfile
;
22297 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22298 " at %s [in module %s]"),
22299 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22300 objfile_name (dwarf2_per_objfile
->objfile
));
22301 return build_error_marker_type (cu
, die
);
22305 /* Load the DIEs associated with type unit PER_CU into memory. */
22308 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22310 struct signatured_type
*sig_type
;
22312 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22313 gdb_assert (! per_cu
->type_unit_group_p ());
22315 /* We have the per_cu, but we need the signatured_type.
22316 Fortunately this is an easy translation. */
22317 gdb_assert (per_cu
->is_debug_types
);
22318 sig_type
= (struct signatured_type
*) per_cu
;
22320 gdb_assert (per_cu
->cu
== NULL
);
22322 read_signatured_type (sig_type
);
22324 gdb_assert (per_cu
->cu
!= NULL
);
22327 /* Read in a signatured type and build its CU and DIEs.
22328 If the type is a stub for the real type in a DWO file,
22329 read in the real type from the DWO file as well. */
22332 read_signatured_type (struct signatured_type
*sig_type
)
22334 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22336 gdb_assert (per_cu
->is_debug_types
);
22337 gdb_assert (per_cu
->cu
== NULL
);
22339 cutu_reader
reader (per_cu
, NULL
, 0, false);
22341 if (!reader
.dummy_p
)
22343 struct dwarf2_cu
*cu
= reader
.cu
;
22344 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22346 gdb_assert (cu
->die_hash
== NULL
);
22348 htab_create_alloc_ex (cu
->header
.length
/ 12,
22352 &cu
->comp_unit_obstack
,
22353 hashtab_obstack_allocate
,
22354 dummy_obstack_deallocate
);
22356 if (reader
.comp_unit_die
->has_children
)
22357 reader
.comp_unit_die
->child
22358 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22359 reader
.comp_unit_die
);
22360 cu
->dies
= reader
.comp_unit_die
;
22361 /* comp_unit_die is not stored in die_hash, no need. */
22363 /* We try not to read any attributes in this function, because
22364 not all CUs needed for references have been loaded yet, and
22365 symbol table processing isn't initialized. But we have to
22366 set the CU language, or we won't be able to build types
22367 correctly. Similarly, if we do not read the producer, we can
22368 not apply producer-specific interpretation. */
22369 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22374 sig_type
->per_cu
.tu_read
= 1;
22377 /* Decode simple location descriptions.
22378 Given a pointer to a dwarf block that defines a location, compute
22379 the location and return the value.
22381 NOTE drow/2003-11-18: This function is called in two situations
22382 now: for the address of static or global variables (partial symbols
22383 only) and for offsets into structures which are expected to be
22384 (more or less) constant. The partial symbol case should go away,
22385 and only the constant case should remain. That will let this
22386 function complain more accurately. A few special modes are allowed
22387 without complaint for global variables (for instance, global
22388 register values and thread-local values).
22390 A location description containing no operations indicates that the
22391 object is optimized out. The return value is 0 for that case.
22392 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22393 callers will only want a very basic result and this can become a
22396 Note that stack[0] is unused except as a default error return. */
22399 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22401 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22403 size_t size
= blk
->size
;
22404 const gdb_byte
*data
= blk
->data
;
22405 CORE_ADDR stack
[64];
22407 unsigned int bytes_read
, unsnd
;
22413 stack
[++stacki
] = 0;
22452 stack
[++stacki
] = op
- DW_OP_lit0
;
22487 stack
[++stacki
] = op
- DW_OP_reg0
;
22489 dwarf2_complex_location_expr_complaint ();
22493 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22495 stack
[++stacki
] = unsnd
;
22497 dwarf2_complex_location_expr_complaint ();
22501 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22506 case DW_OP_const1u
:
22507 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22511 case DW_OP_const1s
:
22512 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22516 case DW_OP_const2u
:
22517 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22521 case DW_OP_const2s
:
22522 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22526 case DW_OP_const4u
:
22527 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22531 case DW_OP_const4s
:
22532 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22536 case DW_OP_const8u
:
22537 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22542 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22548 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22553 stack
[stacki
+ 1] = stack
[stacki
];
22558 stack
[stacki
- 1] += stack
[stacki
];
22562 case DW_OP_plus_uconst
:
22563 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22569 stack
[stacki
- 1] -= stack
[stacki
];
22574 /* If we're not the last op, then we definitely can't encode
22575 this using GDB's address_class enum. This is valid for partial
22576 global symbols, although the variable's address will be bogus
22579 dwarf2_complex_location_expr_complaint ();
22582 case DW_OP_GNU_push_tls_address
:
22583 case DW_OP_form_tls_address
:
22584 /* The top of the stack has the offset from the beginning
22585 of the thread control block at which the variable is located. */
22586 /* Nothing should follow this operator, so the top of stack would
22588 /* This is valid for partial global symbols, but the variable's
22589 address will be bogus in the psymtab. Make it always at least
22590 non-zero to not look as a variable garbage collected by linker
22591 which have DW_OP_addr 0. */
22593 dwarf2_complex_location_expr_complaint ();
22597 case DW_OP_GNU_uninit
:
22601 case DW_OP_GNU_addr_index
:
22602 case DW_OP_GNU_const_index
:
22603 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22610 const char *name
= get_DW_OP_name (op
);
22613 complaint (_("unsupported stack op: '%s'"),
22616 complaint (_("unsupported stack op: '%02x'"),
22620 return (stack
[stacki
]);
22623 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22624 outside of the allocated space. Also enforce minimum>0. */
22625 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22627 complaint (_("location description stack overflow"));
22633 complaint (_("location description stack underflow"));
22637 return (stack
[stacki
]);
22640 /* memory allocation interface */
22642 static struct dwarf_block
*
22643 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22645 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22648 static struct die_info
*
22649 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22651 struct die_info
*die
;
22652 size_t size
= sizeof (struct die_info
);
22655 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22657 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22658 memset (die
, 0, sizeof (struct die_info
));
22664 /* Macro support. */
22666 /* An overload of dwarf_decode_macros that finds the correct section
22667 and ensures it is read in before calling the other overload. */
22670 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22671 int section_is_gnu
)
22673 struct dwarf2_per_objfile
*dwarf2_per_objfile
22674 = cu
->per_cu
->dwarf2_per_objfile
;
22675 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22676 const struct line_header
*lh
= cu
->line_header
;
22677 unsigned int offset_size
= cu
->header
.offset_size
;
22678 struct dwarf2_section_info
*section
;
22679 const char *section_name
;
22681 if (cu
->dwo_unit
!= nullptr)
22683 if (section_is_gnu
)
22685 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22686 section_name
= ".debug_macro.dwo";
22690 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22691 section_name
= ".debug_macinfo.dwo";
22696 if (section_is_gnu
)
22698 section
= &dwarf2_per_objfile
->macro
;
22699 section_name
= ".debug_macro";
22703 section
= &dwarf2_per_objfile
->macinfo
;
22704 section_name
= ".debug_macinfo";
22708 section
->read (objfile
);
22709 if (section
->buffer
== nullptr)
22711 complaint (_("missing %s section"), section_name
);
22715 buildsym_compunit
*builder
= cu
->get_builder ();
22717 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22718 offset_size
, offset
, section_is_gnu
);
22721 /* Return the .debug_loc section to use for CU.
22722 For DWO files use .debug_loc.dwo. */
22724 static struct dwarf2_section_info
*
22725 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22727 struct dwarf2_per_objfile
*dwarf2_per_objfile
22728 = cu
->per_cu
->dwarf2_per_objfile
;
22732 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22734 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22736 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22737 : &dwarf2_per_objfile
->loc
);
22740 /* A helper function that fills in a dwarf2_loclist_baton. */
22743 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22744 struct dwarf2_loclist_baton
*baton
,
22745 const struct attribute
*attr
)
22747 struct dwarf2_per_objfile
*dwarf2_per_objfile
22748 = cu
->per_cu
->dwarf2_per_objfile
;
22749 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22751 section
->read (dwarf2_per_objfile
->objfile
);
22753 baton
->per_cu
= cu
->per_cu
;
22754 gdb_assert (baton
->per_cu
);
22755 /* We don't know how long the location list is, but make sure we
22756 don't run off the edge of the section. */
22757 baton
->size
= section
->size
- DW_UNSND (attr
);
22758 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22759 baton
->base_address
= cu
->base_address
;
22760 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22764 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22765 struct dwarf2_cu
*cu
, int is_block
)
22767 struct dwarf2_per_objfile
*dwarf2_per_objfile
22768 = cu
->per_cu
->dwarf2_per_objfile
;
22769 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22770 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22772 if (attr
->form_is_section_offset ()
22773 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22774 the section. If so, fall through to the complaint in the
22776 && DW_UNSND (attr
) < section
->get_size (objfile
))
22778 struct dwarf2_loclist_baton
*baton
;
22780 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22782 fill_in_loclist_baton (cu
, baton
, attr
);
22784 if (cu
->base_known
== 0)
22785 complaint (_("Location list used without "
22786 "specifying the CU base address."));
22788 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22789 ? dwarf2_loclist_block_index
22790 : dwarf2_loclist_index
);
22791 SYMBOL_LOCATION_BATON (sym
) = baton
;
22795 struct dwarf2_locexpr_baton
*baton
;
22797 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22798 baton
->per_cu
= cu
->per_cu
;
22799 gdb_assert (baton
->per_cu
);
22801 if (attr
->form_is_block ())
22803 /* Note that we're just copying the block's data pointer
22804 here, not the actual data. We're still pointing into the
22805 info_buffer for SYM's objfile; right now we never release
22806 that buffer, but when we do clean up properly this may
22808 baton
->size
= DW_BLOCK (attr
)->size
;
22809 baton
->data
= DW_BLOCK (attr
)->data
;
22813 dwarf2_invalid_attrib_class_complaint ("location description",
22814 sym
->natural_name ());
22818 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22819 ? dwarf2_locexpr_block_index
22820 : dwarf2_locexpr_index
);
22821 SYMBOL_LOCATION_BATON (sym
) = baton
;
22828 dwarf2_per_cu_data::objfile () const
22830 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22832 /* Return the master objfile, so that we can report and look up the
22833 correct file containing this variable. */
22834 if (objfile
->separate_debug_objfile_backlink
)
22835 objfile
= objfile
->separate_debug_objfile_backlink
;
22840 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22841 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22842 CU_HEADERP first. */
22844 static const struct comp_unit_head
*
22845 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22846 const struct dwarf2_per_cu_data
*per_cu
)
22848 const gdb_byte
*info_ptr
;
22851 return &per_cu
->cu
->header
;
22853 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22855 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22856 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22857 rcuh_kind::COMPILE
);
22865 dwarf2_per_cu_data::addr_size () const
22867 struct comp_unit_head cu_header_local
;
22868 const struct comp_unit_head
*cu_headerp
;
22870 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22872 return cu_headerp
->addr_size
;
22878 dwarf2_per_cu_data::offset_size () const
22880 struct comp_unit_head cu_header_local
;
22881 const struct comp_unit_head
*cu_headerp
;
22883 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22885 return cu_headerp
->offset_size
;
22891 dwarf2_per_cu_data::ref_addr_size () const
22893 struct comp_unit_head cu_header_local
;
22894 const struct comp_unit_head
*cu_headerp
;
22896 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22898 if (cu_headerp
->version
== 2)
22899 return cu_headerp
->addr_size
;
22901 return cu_headerp
->offset_size
;
22907 dwarf2_per_cu_data::text_offset () const
22909 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22911 return objfile
->text_section_offset ();
22917 dwarf2_per_cu_data::addr_type () const
22919 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22920 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22921 struct type
*addr_type
= lookup_pointer_type (void_type
);
22922 int addr_size
= this->addr_size ();
22924 if (TYPE_LENGTH (addr_type
) == addr_size
)
22927 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22931 /* A helper function for dwarf2_find_containing_comp_unit that returns
22932 the index of the result, and that searches a vector. It will
22933 return a result even if the offset in question does not actually
22934 occur in any CU. This is separate so that it can be unit
22938 dwarf2_find_containing_comp_unit
22939 (sect_offset sect_off
,
22940 unsigned int offset_in_dwz
,
22941 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22946 high
= all_comp_units
.size () - 1;
22949 struct dwarf2_per_cu_data
*mid_cu
;
22950 int mid
= low
+ (high
- low
) / 2;
22952 mid_cu
= all_comp_units
[mid
];
22953 if (mid_cu
->is_dwz
> offset_in_dwz
22954 || (mid_cu
->is_dwz
== offset_in_dwz
22955 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
22960 gdb_assert (low
== high
);
22964 /* Locate the .debug_info compilation unit from CU's objfile which contains
22965 the DIE at OFFSET. Raises an error on failure. */
22967 static struct dwarf2_per_cu_data
*
22968 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22969 unsigned int offset_in_dwz
,
22970 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22973 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22974 dwarf2_per_objfile
->all_comp_units
);
22975 struct dwarf2_per_cu_data
*this_cu
22976 = dwarf2_per_objfile
->all_comp_units
[low
];
22978 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
22980 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22981 error (_("Dwarf Error: could not find partial DIE containing "
22982 "offset %s [in module %s]"),
22983 sect_offset_str (sect_off
),
22984 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
22986 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22988 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22992 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
22993 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
22994 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
22995 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23002 namespace selftests
{
23003 namespace find_containing_comp_unit
{
23008 struct dwarf2_per_cu_data one
{};
23009 struct dwarf2_per_cu_data two
{};
23010 struct dwarf2_per_cu_data three
{};
23011 struct dwarf2_per_cu_data four
{};
23014 two
.sect_off
= sect_offset (one
.length
);
23019 four
.sect_off
= sect_offset (three
.length
);
23023 std::vector
<dwarf2_per_cu_data
*> units
;
23024 units
.push_back (&one
);
23025 units
.push_back (&two
);
23026 units
.push_back (&three
);
23027 units
.push_back (&four
);
23031 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23032 SELF_CHECK (units
[result
] == &one
);
23033 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23034 SELF_CHECK (units
[result
] == &one
);
23035 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23036 SELF_CHECK (units
[result
] == &two
);
23038 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23039 SELF_CHECK (units
[result
] == &three
);
23040 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23041 SELF_CHECK (units
[result
] == &three
);
23042 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23043 SELF_CHECK (units
[result
] == &four
);
23049 #endif /* GDB_SELF_TEST */
23051 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23053 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23054 : per_cu (per_cu_
),
23056 has_loclist (false),
23057 checked_producer (false),
23058 producer_is_gxx_lt_4_6 (false),
23059 producer_is_gcc_lt_4_3 (false),
23060 producer_is_icc (false),
23061 producer_is_icc_lt_14 (false),
23062 producer_is_codewarrior (false),
23063 processing_has_namespace_info (false)
23068 /* Destroy a dwarf2_cu. */
23070 dwarf2_cu::~dwarf2_cu ()
23075 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23078 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23079 enum language pretend_language
)
23081 struct attribute
*attr
;
23083 /* Set the language we're debugging. */
23084 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23085 if (attr
!= nullptr)
23086 set_cu_language (DW_UNSND (attr
), cu
);
23089 cu
->language
= pretend_language
;
23090 cu
->language_defn
= language_def (cu
->language
);
23093 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23096 /* Increase the age counter on each cached compilation unit, and free
23097 any that are too old. */
23100 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23102 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23104 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23105 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23106 while (per_cu
!= NULL
)
23108 per_cu
->cu
->last_used
++;
23109 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23110 dwarf2_mark (per_cu
->cu
);
23111 per_cu
= per_cu
->cu
->read_in_chain
;
23114 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23115 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23116 while (per_cu
!= NULL
)
23118 struct dwarf2_per_cu_data
*next_cu
;
23120 next_cu
= per_cu
->cu
->read_in_chain
;
23122 if (!per_cu
->cu
->mark
)
23125 *last_chain
= next_cu
;
23128 last_chain
= &per_cu
->cu
->read_in_chain
;
23134 /* Remove a single compilation unit from the cache. */
23137 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23139 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23140 struct dwarf2_per_objfile
*dwarf2_per_objfile
23141 = target_per_cu
->dwarf2_per_objfile
;
23143 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23144 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23145 while (per_cu
!= NULL
)
23147 struct dwarf2_per_cu_data
*next_cu
;
23149 next_cu
= per_cu
->cu
->read_in_chain
;
23151 if (per_cu
== target_per_cu
)
23155 *last_chain
= next_cu
;
23159 last_chain
= &per_cu
->cu
->read_in_chain
;
23165 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23166 We store these in a hash table separate from the DIEs, and preserve them
23167 when the DIEs are flushed out of cache.
23169 The CU "per_cu" pointer is needed because offset alone is not enough to
23170 uniquely identify the type. A file may have multiple .debug_types sections,
23171 or the type may come from a DWO file. Furthermore, while it's more logical
23172 to use per_cu->section+offset, with Fission the section with the data is in
23173 the DWO file but we don't know that section at the point we need it.
23174 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23175 because we can enter the lookup routine, get_die_type_at_offset, from
23176 outside this file, and thus won't necessarily have PER_CU->cu.
23177 Fortunately, PER_CU is stable for the life of the objfile. */
23179 struct dwarf2_per_cu_offset_and_type
23181 const struct dwarf2_per_cu_data
*per_cu
;
23182 sect_offset sect_off
;
23186 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23189 per_cu_offset_and_type_hash (const void *item
)
23191 const struct dwarf2_per_cu_offset_and_type
*ofs
23192 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23194 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23197 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23200 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23202 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23203 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23204 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23205 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23207 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23208 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23211 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23212 table if necessary. For convenience, return TYPE.
23214 The DIEs reading must have careful ordering to:
23215 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23216 reading current DIE.
23217 * Not trying to dereference contents of still incompletely read in types
23218 while reading in other DIEs.
23219 * Enable referencing still incompletely read in types just by a pointer to
23220 the type without accessing its fields.
23222 Therefore caller should follow these rules:
23223 * Try to fetch any prerequisite types we may need to build this DIE type
23224 before building the type and calling set_die_type.
23225 * After building type call set_die_type for current DIE as soon as
23226 possible before fetching more types to complete the current type.
23227 * Make the type as complete as possible before fetching more types. */
23229 static struct type
*
23230 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23232 struct dwarf2_per_objfile
*dwarf2_per_objfile
23233 = cu
->per_cu
->dwarf2_per_objfile
;
23234 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23235 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23236 struct attribute
*attr
;
23237 struct dynamic_prop prop
;
23239 /* For Ada types, make sure that the gnat-specific data is always
23240 initialized (if not already set). There are a few types where
23241 we should not be doing so, because the type-specific area is
23242 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23243 where the type-specific area is used to store the floatformat).
23244 But this is not a problem, because the gnat-specific information
23245 is actually not needed for these types. */
23246 if (need_gnat_info (cu
)
23247 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23248 && TYPE_CODE (type
) != TYPE_CODE_FLT
23249 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23250 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23251 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23252 && !HAVE_GNAT_AUX_INFO (type
))
23253 INIT_GNAT_SPECIFIC (type
);
23255 /* Read DW_AT_allocated and set in type. */
23256 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23257 if (attr
!= NULL
&& attr
->form_is_block ())
23259 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23260 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23261 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23263 else if (attr
!= NULL
)
23265 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23266 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23267 sect_offset_str (die
->sect_off
));
23270 /* Read DW_AT_associated and set in type. */
23271 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23272 if (attr
!= NULL
&& attr
->form_is_block ())
23274 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23275 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23276 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23278 else if (attr
!= NULL
)
23280 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23281 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23282 sect_offset_str (die
->sect_off
));
23285 /* Read DW_AT_data_location and set in type. */
23286 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23287 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23288 cu
->per_cu
->addr_type ()))
23289 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23291 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23292 dwarf2_per_objfile
->die_type_hash
23293 = htab_up (htab_create_alloc (127,
23294 per_cu_offset_and_type_hash
,
23295 per_cu_offset_and_type_eq
,
23296 NULL
, xcalloc
, xfree
));
23298 ofs
.per_cu
= cu
->per_cu
;
23299 ofs
.sect_off
= die
->sect_off
;
23301 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23302 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23304 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23305 sect_offset_str (die
->sect_off
));
23306 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23307 struct dwarf2_per_cu_offset_and_type
);
23312 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23313 or return NULL if the die does not have a saved type. */
23315 static struct type
*
23316 get_die_type_at_offset (sect_offset sect_off
,
23317 struct dwarf2_per_cu_data
*per_cu
)
23319 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23320 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23322 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23325 ofs
.per_cu
= per_cu
;
23326 ofs
.sect_off
= sect_off
;
23327 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23328 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23335 /* Look up the type for DIE in CU in die_type_hash,
23336 or return NULL if DIE does not have a saved type. */
23338 static struct type
*
23339 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23341 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23344 /* Add a dependence relationship from CU to REF_PER_CU. */
23347 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23348 struct dwarf2_per_cu_data
*ref_per_cu
)
23352 if (cu
->dependencies
== NULL
)
23354 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23355 NULL
, &cu
->comp_unit_obstack
,
23356 hashtab_obstack_allocate
,
23357 dummy_obstack_deallocate
);
23359 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23361 *slot
= ref_per_cu
;
23364 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23365 Set the mark field in every compilation unit in the
23366 cache that we must keep because we are keeping CU. */
23369 dwarf2_mark_helper (void **slot
, void *data
)
23371 struct dwarf2_per_cu_data
*per_cu
;
23373 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23375 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23376 reading of the chain. As such dependencies remain valid it is not much
23377 useful to track and undo them during QUIT cleanups. */
23378 if (per_cu
->cu
== NULL
)
23381 if (per_cu
->cu
->mark
)
23383 per_cu
->cu
->mark
= true;
23385 if (per_cu
->cu
->dependencies
!= NULL
)
23386 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23391 /* Set the mark field in CU and in every other compilation unit in the
23392 cache that we must keep because we are keeping CU. */
23395 dwarf2_mark (struct dwarf2_cu
*cu
)
23400 if (cu
->dependencies
!= NULL
)
23401 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23405 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23409 per_cu
->cu
->mark
= false;
23410 per_cu
= per_cu
->cu
->read_in_chain
;
23414 /* Trivial hash function for partial_die_info: the hash value of a DIE
23415 is its offset in .debug_info for this objfile. */
23418 partial_die_hash (const void *item
)
23420 const struct partial_die_info
*part_die
23421 = (const struct partial_die_info
*) item
;
23423 return to_underlying (part_die
->sect_off
);
23426 /* Trivial comparison function for partial_die_info structures: two DIEs
23427 are equal if they have the same offset. */
23430 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23432 const struct partial_die_info
*part_die_lhs
23433 = (const struct partial_die_info
*) item_lhs
;
23434 const struct partial_die_info
*part_die_rhs
23435 = (const struct partial_die_info
*) item_rhs
;
23437 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23440 struct cmd_list_element
*set_dwarf_cmdlist
;
23441 struct cmd_list_element
*show_dwarf_cmdlist
;
23444 set_dwarf_cmd (const char *args
, int from_tty
)
23446 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23451 show_dwarf_cmd (const char *args
, int from_tty
)
23453 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23457 show_check_physname (struct ui_file
*file
, int from_tty
,
23458 struct cmd_list_element
*c
, const char *value
)
23460 fprintf_filtered (file
,
23461 _("Whether to check \"physname\" is %s.\n"),
23465 void _initialize_dwarf2_read ();
23467 _initialize_dwarf2_read ()
23469 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23470 Set DWARF specific variables.\n\
23471 Configure DWARF variables such as the cache size."),
23472 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23473 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23475 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23476 Show DWARF specific variables.\n\
23477 Show DWARF variables such as the cache size."),
23478 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23479 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23481 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23482 &dwarf_max_cache_age
, _("\
23483 Set the upper bound on the age of cached DWARF compilation units."), _("\
23484 Show the upper bound on the age of cached DWARF compilation units."), _("\
23485 A higher limit means that cached compilation units will be stored\n\
23486 in memory longer, and more total memory will be used. Zero disables\n\
23487 caching, which can slow down startup."),
23489 show_dwarf_max_cache_age
,
23490 &set_dwarf_cmdlist
,
23491 &show_dwarf_cmdlist
);
23493 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23494 Set debugging of the DWARF reader."), _("\
23495 Show debugging of the DWARF reader."), _("\
23496 When enabled (non-zero), debugging messages are printed during DWARF\n\
23497 reading and symtab expansion. A value of 1 (one) provides basic\n\
23498 information. A value greater than 1 provides more verbose information."),
23501 &setdebuglist
, &showdebuglist
);
23503 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23504 Set debugging of the DWARF DIE reader."), _("\
23505 Show debugging of the DWARF DIE reader."), _("\
23506 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23507 The value is the maximum depth to print."),
23510 &setdebuglist
, &showdebuglist
);
23512 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23513 Set debugging of the dwarf line reader."), _("\
23514 Show debugging of the dwarf line reader."), _("\
23515 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23516 A value of 1 (one) provides basic information.\n\
23517 A value greater than 1 provides more verbose information."),
23520 &setdebuglist
, &showdebuglist
);
23522 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23523 Set cross-checking of \"physname\" code against demangler."), _("\
23524 Show cross-checking of \"physname\" code against demangler."), _("\
23525 When enabled, GDB's internal \"physname\" code is checked against\n\
23527 NULL
, show_check_physname
,
23528 &setdebuglist
, &showdebuglist
);
23530 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23531 no_class
, &use_deprecated_index_sections
, _("\
23532 Set whether to use deprecated gdb_index sections."), _("\
23533 Show whether to use deprecated gdb_index sections."), _("\
23534 When enabled, deprecated .gdb_index sections are used anyway.\n\
23535 Normally they are ignored either because of a missing feature or\n\
23536 performance issue.\n\
23537 Warning: This option must be enabled before gdb reads the file."),
23540 &setlist
, &showlist
);
23542 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23543 &dwarf2_locexpr_funcs
);
23544 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23545 &dwarf2_loclist_funcs
);
23547 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23548 &dwarf2_block_frame_base_locexpr_funcs
);
23549 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23550 &dwarf2_block_frame_base_loclist_funcs
);
23553 selftests::register_test ("dw2_expand_symtabs_matching",
23554 selftests::dw2_expand_symtabs_matching::run_test
);
23555 selftests::register_test ("dwarf2_find_containing_comp_unit",
23556 selftests::find_containing_comp_unit::run_test
);