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"
43 #include "dwarf2/stringify.h"
52 #include "gdb-demangle.h"
53 #include "filenames.h" /* for DOSish file names */
55 #include "complaints.h"
56 #include "dwarf2/expr.h"
57 #include "dwarf2/loc.h"
58 #include "cp-support.h"
64 #include "typeprint.h"
69 #include "gdbcore.h" /* for gnutarget */
70 #include "gdb/gdb-index.h"
75 #include "namespace.h"
76 #include "gdbsupport/function-view.h"
77 #include "gdbsupport/gdb_optional.h"
78 #include "gdbsupport/underlying.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
84 #include <unordered_map>
85 #include "gdbsupport/selftest.h"
86 #include "rust-lang.h"
87 #include "gdbsupport/pathstuff.h"
88 #include "count-one-bits.h"
89 #include "debuginfod-support.h"
91 /* When == 1, print basic high level tracing messages.
92 When > 1, be more verbose.
93 This is in contrast to the low level DIE reading of dwarf_die_debug. */
94 static unsigned int dwarf_read_debug
= 0;
96 /* When non-zero, dump DIEs after they are read in. */
97 static unsigned int dwarf_die_debug
= 0;
99 /* When non-zero, dump line number entries as they are read in. */
100 unsigned int dwarf_line_debug
= 0;
102 /* When true, cross-check physname against demangler. */
103 static bool check_physname
= false;
105 /* When true, do not reject deprecated .gdb_index sections. */
106 static bool use_deprecated_index_sections
= false;
108 /* This is used to store the data that is always per objfile. */
109 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
111 /* These are used to store the dwarf2_per_bfd objects.
113 objfiles having the same BFD, which doesn't require relocations, are going to
114 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
116 Other objfiles are not going to share a dwarf2_per_bfd with any other
117 objfiles, so they'll have their own version kept in the _objfile_data_key
119 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
120 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
122 /* The "aclass" indices for various kinds of computed DWARF symbols. */
124 static int dwarf2_locexpr_index
;
125 static int dwarf2_loclist_index
;
126 static int dwarf2_locexpr_block_index
;
127 static int dwarf2_loclist_block_index
;
129 /* Size of .debug_loclists section header for 32-bit DWARF format. */
130 #define LOCLIST_HEADER_SIZE32 12
132 /* Size of .debug_loclists section header for 64-bit DWARF format. */
133 #define LOCLIST_HEADER_SIZE64 20
135 /* An index into a (C++) symbol name component in a symbol name as
136 recorded in the mapped_index's symbol table. For each C++ symbol
137 in the symbol table, we record one entry for the start of each
138 component in the symbol in a table of name components, and then
139 sort the table, in order to be able to binary search symbol names,
140 ignoring leading namespaces, both completion and regular look up.
141 For example, for symbol "A::B::C", we'll have an entry that points
142 to "A::B::C", another that points to "B::C", and another for "C".
143 Note that function symbols in GDB index have no parameter
144 information, just the function/method names. You can convert a
145 name_component to a "const char *" using the
146 'mapped_index::symbol_name_at(offset_type)' method. */
148 struct name_component
150 /* Offset in the symbol name where the component starts. Stored as
151 a (32-bit) offset instead of a pointer to save memory and improve
152 locality on 64-bit architectures. */
153 offset_type name_offset
;
155 /* The symbol's index in the symbol and constant pool tables of a
160 /* Base class containing bits shared by both .gdb_index and
161 .debug_name indexes. */
163 struct mapped_index_base
165 mapped_index_base () = default;
166 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
168 /* The name_component table (a sorted vector). See name_component's
169 description above. */
170 std::vector
<name_component
> name_components
;
172 /* How NAME_COMPONENTS is sorted. */
173 enum case_sensitivity name_components_casing
;
175 /* Return the number of names in the symbol table. */
176 virtual size_t symbol_name_count () const = 0;
178 /* Get the name of the symbol at IDX in the symbol table. */
179 virtual const char *symbol_name_at
180 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
182 /* Return whether the name at IDX in the symbol table should be
184 virtual bool symbol_name_slot_invalid (offset_type idx
) const
189 /* Build the symbol name component sorted vector, if we haven't
191 void build_name_components (dwarf2_per_objfile
*per_objfile
);
193 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
194 possible matches for LN_NO_PARAMS in the name component
196 std::pair
<std::vector
<name_component
>::const_iterator
,
197 std::vector
<name_component
>::const_iterator
>
198 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
200 dwarf2_per_objfile
*per_objfile
) const;
202 /* Prevent deleting/destroying via a base class pointer. */
204 ~mapped_index_base() = default;
207 /* A description of the mapped index. The file format is described in
208 a comment by the code that writes the index. */
209 struct mapped_index final
: public mapped_index_base
211 /* A slot/bucket in the symbol table hash. */
212 struct symbol_table_slot
214 const offset_type name
;
215 const offset_type vec
;
218 /* Index data format version. */
221 /* The address table data. */
222 gdb::array_view
<const gdb_byte
> address_table
;
224 /* The symbol table, implemented as a hash table. */
225 gdb::array_view
<symbol_table_slot
> symbol_table
;
227 /* A pointer to the constant pool. */
228 const char *constant_pool
= nullptr;
230 bool symbol_name_slot_invalid (offset_type idx
) const override
232 const auto &bucket
= this->symbol_table
[idx
];
233 return bucket
.name
== 0 && bucket
.vec
== 0;
236 /* Convenience method to get at the name of the symbol at IDX in the
238 const char *symbol_name_at
239 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
240 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
242 size_t symbol_name_count () const override
243 { return this->symbol_table
.size (); }
246 /* A description of the mapped .debug_names.
247 Uninitialized map has CU_COUNT 0. */
248 struct mapped_debug_names final
: public mapped_index_base
250 bfd_endian dwarf5_byte_order
;
251 bool dwarf5_is_dwarf64
;
252 bool augmentation_is_gdb
;
254 uint32_t cu_count
= 0;
255 uint32_t tu_count
, bucket_count
, name_count
;
256 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
257 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
258 const gdb_byte
*name_table_string_offs_reordered
;
259 const gdb_byte
*name_table_entry_offs_reordered
;
260 const gdb_byte
*entry_pool
;
267 /* Attribute name DW_IDX_*. */
270 /* Attribute form DW_FORM_*. */
273 /* Value if FORM is DW_FORM_implicit_const. */
274 LONGEST implicit_const
;
276 std::vector
<attr
> attr_vec
;
279 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
281 const char *namei_to_name
282 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
284 /* Implementation of the mapped_index_base virtual interface, for
285 the name_components cache. */
287 const char *symbol_name_at
288 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
289 { return namei_to_name (idx
, per_objfile
); }
291 size_t symbol_name_count () const override
292 { return this->name_count
; }
295 /* See dwarf2read.h. */
298 get_dwarf2_per_objfile (struct objfile
*objfile
)
300 return dwarf2_objfile_data_key
.get (objfile
);
303 /* Default names of the debugging sections. */
305 /* Note that if the debugging section has been compressed, it might
306 have a name like .zdebug_info. */
308 static const struct dwarf2_debug_sections dwarf2_elf_names
=
310 { ".debug_info", ".zdebug_info" },
311 { ".debug_abbrev", ".zdebug_abbrev" },
312 { ".debug_line", ".zdebug_line" },
313 { ".debug_loc", ".zdebug_loc" },
314 { ".debug_loclists", ".zdebug_loclists" },
315 { ".debug_macinfo", ".zdebug_macinfo" },
316 { ".debug_macro", ".zdebug_macro" },
317 { ".debug_str", ".zdebug_str" },
318 { ".debug_str_offsets", ".zdebug_str_offsets" },
319 { ".debug_line_str", ".zdebug_line_str" },
320 { ".debug_ranges", ".zdebug_ranges" },
321 { ".debug_rnglists", ".zdebug_rnglists" },
322 { ".debug_types", ".zdebug_types" },
323 { ".debug_addr", ".zdebug_addr" },
324 { ".debug_frame", ".zdebug_frame" },
325 { ".eh_frame", NULL
},
326 { ".gdb_index", ".zgdb_index" },
327 { ".debug_names", ".zdebug_names" },
328 { ".debug_aranges", ".zdebug_aranges" },
332 /* List of DWO/DWP sections. */
334 static const struct dwop_section_names
336 struct dwarf2_section_names abbrev_dwo
;
337 struct dwarf2_section_names info_dwo
;
338 struct dwarf2_section_names line_dwo
;
339 struct dwarf2_section_names loc_dwo
;
340 struct dwarf2_section_names loclists_dwo
;
341 struct dwarf2_section_names macinfo_dwo
;
342 struct dwarf2_section_names macro_dwo
;
343 struct dwarf2_section_names str_dwo
;
344 struct dwarf2_section_names str_offsets_dwo
;
345 struct dwarf2_section_names types_dwo
;
346 struct dwarf2_section_names cu_index
;
347 struct dwarf2_section_names tu_index
;
351 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
352 { ".debug_info.dwo", ".zdebug_info.dwo" },
353 { ".debug_line.dwo", ".zdebug_line.dwo" },
354 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
355 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
356 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
357 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
358 { ".debug_str.dwo", ".zdebug_str.dwo" },
359 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
360 { ".debug_types.dwo", ".zdebug_types.dwo" },
361 { ".debug_cu_index", ".zdebug_cu_index" },
362 { ".debug_tu_index", ".zdebug_tu_index" },
365 /* local data types */
367 /* The location list section (.debug_loclists) begins with a header,
368 which contains the following information. */
369 struct loclist_header
371 /* A 4-byte or 12-byte length containing the length of the
372 set of entries for this compilation unit, not including the
373 length field itself. */
376 /* A 2-byte version identifier. */
379 /* A 1-byte unsigned integer containing the size in bytes of an address on
380 the target system. */
381 unsigned char addr_size
;
383 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
384 on the target system. */
385 unsigned char segment_collector_size
;
387 /* A 4-byte count of the number of offsets that follow the header. */
388 unsigned int offset_entry_count
;
391 /* Type used for delaying computation of method physnames.
392 See comments for compute_delayed_physnames. */
393 struct delayed_method_info
395 /* The type to which the method is attached, i.e., its parent class. */
398 /* The index of the method in the type's function fieldlists. */
401 /* The index of the method in the fieldlist. */
404 /* The name of the DIE. */
407 /* The DIE associated with this method. */
408 struct die_info
*die
;
411 /* Internal state when decoding a particular compilation unit. */
414 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
415 dwarf2_per_objfile
*per_objfile
);
417 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
419 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
420 Create the set of symtabs used by this TU, or if this TU is sharing
421 symtabs with another TU and the symtabs have already been created
422 then restore those symtabs in the line header.
423 We don't need the pc/line-number mapping for type units. */
424 void setup_type_unit_groups (struct die_info
*die
);
426 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
427 buildsym_compunit constructor. */
428 struct compunit_symtab
*start_symtab (const char *name
,
429 const char *comp_dir
,
432 /* Reset the builder. */
433 void reset_builder () { m_builder
.reset (); }
435 /* Return a type that is a generic pointer type, the size of which
436 matches the address size given in the compilation unit header for
438 struct type
*addr_type () const;
440 /* Find an integer type the same size as the address size given in
441 the compilation unit header for this CU. UNSIGNED_P controls if
442 the integer is unsigned or not. */
443 struct type
*addr_sized_int_type (bool unsigned_p
) const;
445 /* The header of the compilation unit. */
446 struct comp_unit_head header
{};
448 /* Base address of this compilation unit. */
449 gdb::optional
<CORE_ADDR
> base_address
;
451 /* The language we are debugging. */
452 enum language language
= language_unknown
;
453 const struct language_defn
*language_defn
= nullptr;
455 const char *producer
= nullptr;
458 /* The symtab builder for this CU. This is only non-NULL when full
459 symbols are being read. */
460 std::unique_ptr
<buildsym_compunit
> m_builder
;
463 /* The generic symbol table building routines have separate lists for
464 file scope symbols and all all other scopes (local scopes). So
465 we need to select the right one to pass to add_symbol_to_list().
466 We do it by keeping a pointer to the correct list in list_in_scope.
468 FIXME: The original dwarf code just treated the file scope as the
469 first local scope, and all other local scopes as nested local
470 scopes, and worked fine. Check to see if we really need to
471 distinguish these in buildsym.c. */
472 struct pending
**list_in_scope
= nullptr;
474 /* Hash table holding all the loaded partial DIEs
475 with partial_die->offset.SECT_OFF as hash. */
476 htab_t partial_dies
= nullptr;
478 /* Storage for things with the same lifetime as this read-in compilation
479 unit, including partial DIEs. */
480 auto_obstack comp_unit_obstack
;
482 /* Backlink to our per_cu entry. */
483 struct dwarf2_per_cu_data
*per_cu
;
485 /* The dwarf2_per_objfile that owns this. */
486 dwarf2_per_objfile
*per_objfile
;
488 /* How many compilation units ago was this CU last referenced? */
491 /* A hash table of DIE cu_offset for following references with
492 die_info->offset.sect_off as hash. */
493 htab_t die_hash
= nullptr;
495 /* Full DIEs if read in. */
496 struct die_info
*dies
= nullptr;
498 /* A set of pointers to dwarf2_per_cu_data objects for compilation
499 units referenced by this one. Only set during full symbol processing;
500 partial symbol tables do not have dependencies. */
501 htab_t dependencies
= nullptr;
503 /* Header data from the line table, during full symbol processing. */
504 struct line_header
*line_header
= nullptr;
505 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
506 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
507 this is the DW_TAG_compile_unit die for this CU. We'll hold on
508 to the line header as long as this DIE is being processed. See
509 process_die_scope. */
510 die_info
*line_header_die_owner
= nullptr;
512 /* A list of methods which need to have physnames computed
513 after all type information has been read. */
514 std::vector
<delayed_method_info
> method_list
;
516 /* To be copied to symtab->call_site_htab. */
517 htab_t call_site_htab
= nullptr;
519 /* Non-NULL if this CU came from a DWO file.
520 There is an invariant here that is important to remember:
521 Except for attributes copied from the top level DIE in the "main"
522 (or "stub") file in preparation for reading the DWO file
523 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
524 Either there isn't a DWO file (in which case this is NULL and the point
525 is moot), or there is and either we're not going to read it (in which
526 case this is NULL) or there is and we are reading it (in which case this
528 struct dwo_unit
*dwo_unit
= nullptr;
530 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
531 Note this value comes from the Fission stub CU/TU's DIE. */
532 gdb::optional
<ULONGEST
> addr_base
;
534 /* The DW_AT_rnglists_base attribute if present.
535 Note this value comes from the Fission stub CU/TU's DIE.
536 Also note that the value is zero in the non-DWO case so this value can
537 be used without needing to know whether DWO files are in use or not.
538 N.B. This does not apply to DW_AT_ranges appearing in
539 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
540 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
541 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
542 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
543 ULONGEST ranges_base
= 0;
545 /* The DW_AT_loclists_base attribute if present. */
546 ULONGEST loclist_base
= 0;
548 /* When reading debug info generated by older versions of rustc, we
549 have to rewrite some union types to be struct types with a
550 variant part. This rewriting must be done after the CU is fully
551 read in, because otherwise at the point of rewriting some struct
552 type might not have been fully processed. So, we keep a list of
553 all such types here and process them after expansion. */
554 std::vector
<struct type
*> rust_unions
;
556 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
557 files, the value is implicitly zero. For DWARF 5 version DWO files, the
558 value is often implicit and is the size of the header of
559 .debug_str_offsets section (8 or 4, depending on the address size). */
560 gdb::optional
<ULONGEST
> str_offsets_base
;
562 /* Mark used when releasing cached dies. */
565 /* This CU references .debug_loc. See the symtab->locations_valid field.
566 This test is imperfect as there may exist optimized debug code not using
567 any location list and still facing inlining issues if handled as
568 unoptimized code. For a future better test see GCC PR other/32998. */
569 bool has_loclist
: 1;
571 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
572 if all the producer_is_* fields are valid. This information is cached
573 because profiling CU expansion showed excessive time spent in
574 producer_is_gxx_lt_4_6. */
575 bool checked_producer
: 1;
576 bool producer_is_gxx_lt_4_6
: 1;
577 bool producer_is_gcc_lt_4_3
: 1;
578 bool producer_is_icc
: 1;
579 bool producer_is_icc_lt_14
: 1;
580 bool producer_is_codewarrior
: 1;
582 /* When true, the file that we're processing is known to have
583 debugging info for C++ namespaces. GCC 3.3.x did not produce
584 this information, but later versions do. */
586 bool processing_has_namespace_info
: 1;
588 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
590 /* If this CU was inherited by another CU (via specification,
591 abstract_origin, etc), this is the ancestor CU. */
594 /* Get the buildsym_compunit for this CU. */
595 buildsym_compunit
*get_builder ()
597 /* If this CU has a builder associated with it, use that. */
598 if (m_builder
!= nullptr)
599 return m_builder
.get ();
601 /* Otherwise, search ancestors for a valid builder. */
602 if (ancestor
!= nullptr)
603 return ancestor
->get_builder ();
609 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
610 This includes type_unit_group and quick_file_names. */
612 struct stmt_list_hash
614 /* The DWO unit this table is from or NULL if there is none. */
615 struct dwo_unit
*dwo_unit
;
617 /* Offset in .debug_line or .debug_line.dwo. */
618 sect_offset line_sect_off
;
621 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
622 an object of this type. This contains elements of type unit groups
623 that can be shared across objfiles. The non-shareable parts are in
624 type_unit_group_unshareable. */
626 struct type_unit_group
628 /* dwarf2read.c's main "handle" on a TU symtab.
629 To simplify things we create an artificial CU that "includes" all the
630 type units using this stmt_list so that the rest of the code still has
631 a "per_cu" handle on the symtab. */
632 struct dwarf2_per_cu_data per_cu
;
634 /* The TUs that share this DW_AT_stmt_list entry.
635 This is added to while parsing type units to build partial symtabs,
636 and is deleted afterwards and not used again. */
637 std::vector
<signatured_type
*> *tus
;
639 /* The data used to construct the hash key. */
640 struct stmt_list_hash hash
;
643 /* These sections are what may appear in a (real or virtual) DWO file. */
647 struct dwarf2_section_info abbrev
;
648 struct dwarf2_section_info line
;
649 struct dwarf2_section_info loc
;
650 struct dwarf2_section_info loclists
;
651 struct dwarf2_section_info macinfo
;
652 struct dwarf2_section_info macro
;
653 struct dwarf2_section_info str
;
654 struct dwarf2_section_info str_offsets
;
655 /* In the case of a virtual DWO file, these two are unused. */
656 struct dwarf2_section_info info
;
657 std::vector
<dwarf2_section_info
> types
;
660 /* CUs/TUs in DWP/DWO files. */
664 /* Backlink to the containing struct dwo_file. */
665 struct dwo_file
*dwo_file
;
667 /* The "id" that distinguishes this CU/TU.
668 .debug_info calls this "dwo_id", .debug_types calls this "signature".
669 Since signatures came first, we stick with it for consistency. */
672 /* The section this CU/TU lives in, in the DWO file. */
673 struct dwarf2_section_info
*section
;
675 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
676 sect_offset sect_off
;
679 /* For types, offset in the type's DIE of the type defined by this TU. */
680 cu_offset type_offset_in_tu
;
683 /* include/dwarf2.h defines the DWP section codes.
684 It defines a max value but it doesn't define a min value, which we
685 use for error checking, so provide one. */
687 enum dwp_v2_section_ids
692 /* Data for one DWO file.
694 This includes virtual DWO files (a virtual DWO file is a DWO file as it
695 appears in a DWP file). DWP files don't really have DWO files per se -
696 comdat folding of types "loses" the DWO file they came from, and from
697 a high level view DWP files appear to contain a mass of random types.
698 However, to maintain consistency with the non-DWP case we pretend DWP
699 files contain virtual DWO files, and we assign each TU with one virtual
700 DWO file (generally based on the line and abbrev section offsets -
701 a heuristic that seems to work in practice). */
705 dwo_file () = default;
706 DISABLE_COPY_AND_ASSIGN (dwo_file
);
708 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
709 For virtual DWO files the name is constructed from the section offsets
710 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
711 from related CU+TUs. */
712 const char *dwo_name
= nullptr;
714 /* The DW_AT_comp_dir attribute. */
715 const char *comp_dir
= nullptr;
717 /* The bfd, when the file is open. Otherwise this is NULL.
718 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
719 gdb_bfd_ref_ptr dbfd
;
721 /* The sections that make up this DWO file.
722 Remember that for virtual DWO files in DWP V2, these are virtual
723 sections (for lack of a better name). */
724 struct dwo_sections sections
{};
726 /* The CUs in the file.
727 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
728 an extension to handle LLVM's Link Time Optimization output (where
729 multiple source files may be compiled into a single object/dwo pair). */
732 /* Table of TUs in the file.
733 Each element is a struct dwo_unit. */
737 /* These sections are what may appear in a DWP file. */
741 /* These are used by both DWP version 1 and 2. */
742 struct dwarf2_section_info str
;
743 struct dwarf2_section_info cu_index
;
744 struct dwarf2_section_info tu_index
;
746 /* These are only used by DWP version 2 files.
747 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
748 sections are referenced by section number, and are not recorded here.
749 In DWP version 2 there is at most one copy of all these sections, each
750 section being (effectively) comprised of the concatenation of all of the
751 individual sections that exist in the version 1 format.
752 To keep the code simple we treat each of these concatenated pieces as a
753 section itself (a virtual section?). */
754 struct dwarf2_section_info abbrev
;
755 struct dwarf2_section_info info
;
756 struct dwarf2_section_info line
;
757 struct dwarf2_section_info loc
;
758 struct dwarf2_section_info macinfo
;
759 struct dwarf2_section_info macro
;
760 struct dwarf2_section_info str_offsets
;
761 struct dwarf2_section_info types
;
764 /* These sections are what may appear in a virtual DWO file in DWP version 1.
765 A virtual DWO file is a DWO file as it appears in a DWP file. */
767 struct virtual_v1_dwo_sections
769 struct dwarf2_section_info abbrev
;
770 struct dwarf2_section_info line
;
771 struct dwarf2_section_info loc
;
772 struct dwarf2_section_info macinfo
;
773 struct dwarf2_section_info macro
;
774 struct dwarf2_section_info str_offsets
;
775 /* Each DWP hash table entry records one CU or one TU.
776 That is recorded here, and copied to dwo_unit.section. */
777 struct dwarf2_section_info info_or_types
;
780 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
781 In version 2, the sections of the DWO files are concatenated together
782 and stored in one section of that name. Thus each ELF section contains
783 several "virtual" sections. */
785 struct virtual_v2_dwo_sections
787 bfd_size_type abbrev_offset
;
788 bfd_size_type abbrev_size
;
790 bfd_size_type line_offset
;
791 bfd_size_type line_size
;
793 bfd_size_type loc_offset
;
794 bfd_size_type loc_size
;
796 bfd_size_type macinfo_offset
;
797 bfd_size_type macinfo_size
;
799 bfd_size_type macro_offset
;
800 bfd_size_type macro_size
;
802 bfd_size_type str_offsets_offset
;
803 bfd_size_type str_offsets_size
;
805 /* Each DWP hash table entry records one CU or one TU.
806 That is recorded here, and copied to dwo_unit.section. */
807 bfd_size_type info_or_types_offset
;
808 bfd_size_type info_or_types_size
;
811 /* Contents of DWP hash tables. */
813 struct dwp_hash_table
815 uint32_t version
, nr_columns
;
816 uint32_t nr_units
, nr_slots
;
817 const gdb_byte
*hash_table
, *unit_table
;
822 const gdb_byte
*indices
;
826 /* This is indexed by column number and gives the id of the section
828 #define MAX_NR_V2_DWO_SECTIONS \
829 (1 /* .debug_info or .debug_types */ \
830 + 1 /* .debug_abbrev */ \
831 + 1 /* .debug_line */ \
832 + 1 /* .debug_loc */ \
833 + 1 /* .debug_str_offsets */ \
834 + 1 /* .debug_macro or .debug_macinfo */)
835 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
836 const gdb_byte
*offsets
;
837 const gdb_byte
*sizes
;
842 /* Data for one DWP file. */
846 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
848 dbfd (std::move (abfd
))
852 /* Name of the file. */
855 /* File format version. */
859 gdb_bfd_ref_ptr dbfd
;
861 /* Section info for this file. */
862 struct dwp_sections sections
{};
864 /* Table of CUs in the file. */
865 const struct dwp_hash_table
*cus
= nullptr;
867 /* Table of TUs in the file. */
868 const struct dwp_hash_table
*tus
= nullptr;
870 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
874 /* Table to map ELF section numbers to their sections.
875 This is only needed for the DWP V1 file format. */
876 unsigned int num_sections
= 0;
877 asection
**elf_sections
= nullptr;
880 /* Struct used to pass misc. parameters to read_die_and_children, et
881 al. which are used for both .debug_info and .debug_types dies.
882 All parameters here are unchanging for the life of the call. This
883 struct exists to abstract away the constant parameters of die reading. */
885 struct die_reader_specs
887 /* The bfd of die_section. */
890 /* The CU of the DIE we are parsing. */
891 struct dwarf2_cu
*cu
;
893 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
894 struct dwo_file
*dwo_file
;
896 /* The section the die comes from.
897 This is either .debug_info or .debug_types, or the .dwo variants. */
898 struct dwarf2_section_info
*die_section
;
900 /* die_section->buffer. */
901 const gdb_byte
*buffer
;
903 /* The end of the buffer. */
904 const gdb_byte
*buffer_end
;
906 /* The abbreviation table to use when reading the DIEs. */
907 struct abbrev_table
*abbrev_table
;
910 /* A subclass of die_reader_specs that holds storage and has complex
911 constructor and destructor behavior. */
913 class cutu_reader
: public die_reader_specs
917 cutu_reader (dwarf2_per_cu_data
*this_cu
,
918 dwarf2_per_objfile
*per_objfile
,
919 struct abbrev_table
*abbrev_table
,
920 dwarf2_cu
*existing_cu
,
923 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
924 dwarf2_per_objfile
*per_objfile
,
925 struct dwarf2_cu
*parent_cu
= nullptr,
926 struct dwo_file
*dwo_file
= nullptr);
928 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
930 const gdb_byte
*info_ptr
= nullptr;
931 struct die_info
*comp_unit_die
= nullptr;
932 bool dummy_p
= false;
934 /* Release the new CU, putting it on the chain. This cannot be done
939 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
940 dwarf2_per_objfile
*per_objfile
,
941 dwarf2_cu
*existing_cu
);
943 struct dwarf2_per_cu_data
*m_this_cu
;
944 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
946 /* The ordinary abbreviation table. */
947 abbrev_table_up m_abbrev_table_holder
;
949 /* The DWO abbreviation table. */
950 abbrev_table_up m_dwo_abbrev_table
;
953 /* When we construct a partial symbol table entry we only
954 need this much information. */
955 struct partial_die_info
: public allocate_on_obstack
957 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
959 /* Disable assign but still keep copy ctor, which is needed
960 load_partial_dies. */
961 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
963 /* Adjust the partial die before generating a symbol for it. This
964 function may set the is_external flag or change the DIE's
966 void fixup (struct dwarf2_cu
*cu
);
968 /* Read a minimal amount of information into the minimal die
970 const gdb_byte
*read (const struct die_reader_specs
*reader
,
971 const struct abbrev_info
&abbrev
,
972 const gdb_byte
*info_ptr
);
974 /* Compute the name of this partial DIE. This memoizes the
975 result, so it is safe to call multiple times. */
976 const char *name (dwarf2_cu
*cu
);
978 /* Offset of this DIE. */
979 const sect_offset sect_off
;
981 /* DWARF-2 tag for this DIE. */
982 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
984 /* Assorted flags describing the data found in this DIE. */
985 const unsigned int has_children
: 1;
987 unsigned int is_external
: 1;
988 unsigned int is_declaration
: 1;
989 unsigned int has_type
: 1;
990 unsigned int has_specification
: 1;
991 unsigned int has_pc_info
: 1;
992 unsigned int may_be_inlined
: 1;
994 /* This DIE has been marked DW_AT_main_subprogram. */
995 unsigned int main_subprogram
: 1;
997 /* Flag set if the SCOPE field of this structure has been
999 unsigned int scope_set
: 1;
1001 /* Flag set if the DIE has a byte_size attribute. */
1002 unsigned int has_byte_size
: 1;
1004 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1005 unsigned int has_const_value
: 1;
1007 /* Flag set if any of the DIE's children are template arguments. */
1008 unsigned int has_template_arguments
: 1;
1010 /* Flag set if fixup has been called on this die. */
1011 unsigned int fixup_called
: 1;
1013 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1014 unsigned int is_dwz
: 1;
1016 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1017 unsigned int spec_is_dwz
: 1;
1019 unsigned int canonical_name
: 1;
1021 /* The name of this DIE. Normally the value of DW_AT_name, but
1022 sometimes a default name for unnamed DIEs. */
1023 const char *raw_name
= nullptr;
1025 /* The linkage name, if present. */
1026 const char *linkage_name
= nullptr;
1028 /* The scope to prepend to our children. This is generally
1029 allocated on the comp_unit_obstack, so will disappear
1030 when this compilation unit leaves the cache. */
1031 const char *scope
= nullptr;
1033 /* Some data associated with the partial DIE. The tag determines
1034 which field is live. */
1037 /* The location description associated with this DIE, if any. */
1038 struct dwarf_block
*locdesc
;
1039 /* The offset of an import, for DW_TAG_imported_unit. */
1040 sect_offset sect_off
;
1043 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1044 CORE_ADDR lowpc
= 0;
1045 CORE_ADDR highpc
= 0;
1047 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1048 DW_AT_sibling, if any. */
1049 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1050 could return DW_AT_sibling values to its caller load_partial_dies. */
1051 const gdb_byte
*sibling
= nullptr;
1053 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1054 DW_AT_specification (or DW_AT_abstract_origin or
1055 DW_AT_extension). */
1056 sect_offset spec_offset
{};
1058 /* Pointers to this DIE's parent, first child, and next sibling,
1060 struct partial_die_info
*die_parent
= nullptr;
1061 struct partial_die_info
*die_child
= nullptr;
1062 struct partial_die_info
*die_sibling
= nullptr;
1064 friend struct partial_die_info
*
1065 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1068 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1069 partial_die_info (sect_offset sect_off
)
1070 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1074 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1076 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1081 has_specification
= 0;
1084 main_subprogram
= 0;
1087 has_const_value
= 0;
1088 has_template_arguments
= 0;
1096 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1097 but this would require a corresponding change in unpack_field_as_long
1099 static int bits_per_byte
= 8;
1101 struct variant_part_builder
;
1103 /* When reading a variant, we track a bit more information about the
1104 field, and store it in an object of this type. */
1106 struct variant_field
1108 int first_field
= -1;
1109 int last_field
= -1;
1111 /* A variant can contain other variant parts. */
1112 std::vector
<variant_part_builder
> variant_parts
;
1114 /* If we see a DW_TAG_variant, then this will be set if this is the
1116 bool default_branch
= false;
1117 /* If we see a DW_AT_discr_value, then this will be the discriminant
1119 ULONGEST discriminant_value
= 0;
1120 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1122 struct dwarf_block
*discr_list_data
= nullptr;
1125 /* This represents a DW_TAG_variant_part. */
1127 struct variant_part_builder
1129 /* The offset of the discriminant field. */
1130 sect_offset discriminant_offset
{};
1132 /* Variants that are direct children of this variant part. */
1133 std::vector
<variant_field
> variants
;
1135 /* True if we're currently reading a variant. */
1136 bool processing_variant
= false;
1141 int accessibility
= 0;
1143 /* Variant parts need to find the discriminant, which is a DIE
1144 reference. We track the section offset of each field to make
1147 struct field field
{};
1152 const char *name
= nullptr;
1153 std::vector
<struct fn_field
> fnfields
;
1156 /* The routines that read and process dies for a C struct or C++ class
1157 pass lists of data member fields and lists of member function fields
1158 in an instance of a field_info structure, as defined below. */
1161 /* List of data member and baseclasses fields. */
1162 std::vector
<struct nextfield
> fields
;
1163 std::vector
<struct nextfield
> baseclasses
;
1165 /* Set if the accessibility of one of the fields is not public. */
1166 int non_public_fields
= 0;
1168 /* Member function fieldlist array, contains name of possibly overloaded
1169 member function, number of overloaded member functions and a pointer
1170 to the head of the member function field chain. */
1171 std::vector
<struct fnfieldlist
> fnfieldlists
;
1173 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1174 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1175 std::vector
<struct decl_field
> typedef_field_list
;
1177 /* Nested types defined by this class and the number of elements in this
1179 std::vector
<struct decl_field
> nested_types_list
;
1181 /* If non-null, this is the variant part we are currently
1183 variant_part_builder
*current_variant_part
= nullptr;
1184 /* This holds all the top-level variant parts attached to the type
1186 std::vector
<variant_part_builder
> variant_parts
;
1188 /* Return the total number of fields (including baseclasses). */
1189 int nfields () const
1191 return fields
.size () + baseclasses
.size ();
1195 /* Loaded secondary compilation units are kept in memory until they
1196 have not been referenced for the processing of this many
1197 compilation units. Set this to zero to disable caching. Cache
1198 sizes of up to at least twenty will improve startup time for
1199 typical inter-CU-reference binaries, at an obvious memory cost. */
1200 static int dwarf_max_cache_age
= 5;
1202 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1203 struct cmd_list_element
*c
, const char *value
)
1205 fprintf_filtered (file
, _("The upper bound on the age of cached "
1206 "DWARF compilation units is %s.\n"),
1210 /* local function prototypes */
1212 static void dwarf2_find_base_address (struct die_info
*die
,
1213 struct dwarf2_cu
*cu
);
1215 static dwarf2_psymtab
*create_partial_symtab
1216 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1219 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1220 const gdb_byte
*info_ptr
,
1221 struct die_info
*type_unit_die
);
1223 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1225 static void scan_partial_symbols (struct partial_die_info
*,
1226 CORE_ADDR
*, CORE_ADDR
*,
1227 int, struct dwarf2_cu
*);
1229 static void add_partial_symbol (struct partial_die_info
*,
1230 struct dwarf2_cu
*);
1232 static void add_partial_namespace (struct partial_die_info
*pdi
,
1233 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1234 int set_addrmap
, struct dwarf2_cu
*cu
);
1236 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1237 CORE_ADDR
*highpc
, int set_addrmap
,
1238 struct dwarf2_cu
*cu
);
1240 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1241 struct dwarf2_cu
*cu
);
1243 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1244 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1245 int need_pc
, struct dwarf2_cu
*cu
);
1247 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1249 static struct partial_die_info
*load_partial_dies
1250 (const struct die_reader_specs
*, const gdb_byte
*, int);
1252 /* A pair of partial_die_info and compilation unit. */
1253 struct cu_partial_die_info
1255 /* The compilation unit of the partial_die_info. */
1256 struct dwarf2_cu
*cu
;
1257 /* A partial_die_info. */
1258 struct partial_die_info
*pdi
;
1260 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1266 cu_partial_die_info () = delete;
1269 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1270 struct dwarf2_cu
*);
1272 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1273 struct attribute
*, struct attr_abbrev
*,
1274 const gdb_byte
*, bool *need_reprocess
);
1276 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1277 struct attribute
*attr
);
1279 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1281 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1282 dwarf2_section_info
*, sect_offset
);
1284 static const char *read_indirect_string
1285 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1286 const struct comp_unit_head
*, unsigned int *);
1288 static const char *read_indirect_string_at_offset
1289 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1291 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1295 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1296 ULONGEST str_index
);
1298 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1299 ULONGEST str_index
);
1301 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1303 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1304 struct dwarf2_cu
*);
1306 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1307 struct dwarf2_cu
*cu
);
1309 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1311 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1312 struct dwarf2_cu
*cu
);
1314 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1316 static struct die_info
*die_specification (struct die_info
*die
,
1317 struct dwarf2_cu
**);
1319 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1320 struct dwarf2_cu
*cu
);
1322 static void dwarf_decode_lines (struct line_header
*, const char *,
1323 struct dwarf2_cu
*, dwarf2_psymtab
*,
1324 CORE_ADDR
, int decode_mapping
);
1326 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1329 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1330 struct dwarf2_cu
*, struct symbol
* = NULL
);
1332 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1333 struct dwarf2_cu
*);
1335 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1338 struct obstack
*obstack
,
1339 struct dwarf2_cu
*cu
, LONGEST
*value
,
1340 const gdb_byte
**bytes
,
1341 struct dwarf2_locexpr_baton
**baton
);
1343 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1345 static int need_gnat_info (struct dwarf2_cu
*);
1347 static struct type
*die_descriptive_type (struct die_info
*,
1348 struct dwarf2_cu
*);
1350 static void set_descriptive_type (struct type
*, struct die_info
*,
1351 struct dwarf2_cu
*);
1353 static struct type
*die_containing_type (struct die_info
*,
1354 struct dwarf2_cu
*);
1356 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1357 struct dwarf2_cu
*);
1359 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1361 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1363 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1365 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1366 const char *suffix
, int physname
,
1367 struct dwarf2_cu
*cu
);
1369 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1371 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1373 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1375 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1377 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1379 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1381 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1382 struct dwarf2_cu
*, dwarf2_psymtab
*);
1384 /* Return the .debug_loclists section to use for cu. */
1385 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1387 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1388 values. Keep the items ordered with increasing constraints compliance. */
1391 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1392 PC_BOUNDS_NOT_PRESENT
,
1394 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1395 were present but they do not form a valid range of PC addresses. */
1398 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1401 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1405 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1406 CORE_ADDR
*, CORE_ADDR
*,
1410 static void get_scope_pc_bounds (struct die_info
*,
1411 CORE_ADDR
*, CORE_ADDR
*,
1412 struct dwarf2_cu
*);
1414 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1415 CORE_ADDR
, struct dwarf2_cu
*);
1417 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1418 struct dwarf2_cu
*);
1420 static void dwarf2_attach_fields_to_type (struct field_info
*,
1421 struct type
*, struct dwarf2_cu
*);
1423 static void dwarf2_add_member_fn (struct field_info
*,
1424 struct die_info
*, struct type
*,
1425 struct dwarf2_cu
*);
1427 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1429 struct dwarf2_cu
*);
1431 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1433 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1435 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1437 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1439 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1441 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1443 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1445 static struct type
*read_module_type (struct die_info
*die
,
1446 struct dwarf2_cu
*cu
);
1448 static const char *namespace_name (struct die_info
*die
,
1449 int *is_anonymous
, struct dwarf2_cu
*);
1451 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1453 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1456 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1457 struct dwarf2_cu
*);
1459 static struct die_info
*read_die_and_siblings_1
1460 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1463 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1464 const gdb_byte
*info_ptr
,
1465 const gdb_byte
**new_info_ptr
,
1466 struct die_info
*parent
);
1468 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1469 struct die_info
**, const gdb_byte
*,
1472 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1473 struct die_info
**, const gdb_byte
*);
1475 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1477 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1480 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1482 static const char *dwarf2_full_name (const char *name
,
1483 struct die_info
*die
,
1484 struct dwarf2_cu
*cu
);
1486 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1487 struct dwarf2_cu
*cu
);
1489 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1490 struct dwarf2_cu
**);
1492 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1494 static void dump_die_for_error (struct die_info
*);
1496 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1499 /*static*/ void dump_die (struct die_info
*, int max_level
);
1501 static void store_in_ref_table (struct die_info
*,
1502 struct dwarf2_cu
*);
1504 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1505 const struct attribute
*,
1506 struct dwarf2_cu
**);
1508 static struct die_info
*follow_die_ref (struct die_info
*,
1509 const struct attribute
*,
1510 struct dwarf2_cu
**);
1512 static struct die_info
*follow_die_sig (struct die_info
*,
1513 const struct attribute
*,
1514 struct dwarf2_cu
**);
1516 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1517 struct dwarf2_cu
*);
1519 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1520 const struct attribute
*,
1521 struct dwarf2_cu
*);
1523 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1524 dwarf2_per_objfile
*per_objfile
);
1526 static void read_signatured_type (signatured_type
*sig_type
,
1527 dwarf2_per_objfile
*per_objfile
);
1529 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1530 struct die_info
*die
, struct dwarf2_cu
*cu
,
1531 struct dynamic_prop
*prop
, struct type
*type
);
1533 /* memory allocation interface */
1535 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1537 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1539 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1541 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1542 struct dwarf2_loclist_baton
*baton
,
1543 const struct attribute
*attr
);
1545 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1547 struct dwarf2_cu
*cu
,
1550 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1551 const gdb_byte
*info_ptr
,
1552 struct abbrev_info
*abbrev
);
1554 static hashval_t
partial_die_hash (const void *item
);
1556 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1558 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1559 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1560 dwarf2_per_objfile
*per_objfile
);
1562 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1563 struct die_info
*comp_unit_die
,
1564 enum language pretend_language
);
1566 static struct type
*set_die_type (struct die_info
*, struct type
*,
1567 struct dwarf2_cu
*);
1569 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1571 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1573 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1574 dwarf2_per_objfile
*per_objfile
,
1576 enum language pretend_language
);
1578 static void process_full_comp_unit (dwarf2_cu
*cu
,
1579 enum language pretend_language
);
1581 static void process_full_type_unit (dwarf2_cu
*cu
,
1582 enum language pretend_language
);
1584 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1585 struct dwarf2_per_cu_data
*);
1587 static void dwarf2_mark (struct dwarf2_cu
*);
1589 static struct type
*get_die_type_at_offset (sect_offset
,
1590 dwarf2_per_cu_data
*per_cu
,
1591 dwarf2_per_objfile
*per_objfile
);
1593 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1595 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1596 dwarf2_per_objfile
*per_objfile
,
1597 enum language pretend_language
);
1599 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1601 /* Class, the destructor of which frees all allocated queue entries. This
1602 will only have work to do if an error was thrown while processing the
1603 dwarf. If no error was thrown then the queue entries should have all
1604 been processed, and freed, as we went along. */
1606 class dwarf2_queue_guard
1609 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1610 : m_per_objfile (per_objfile
)
1614 /* Free any entries remaining on the queue. There should only be
1615 entries left if we hit an error while processing the dwarf. */
1616 ~dwarf2_queue_guard ()
1618 /* Ensure that no memory is allocated by the queue. */
1619 std::queue
<dwarf2_queue_item
> empty
;
1620 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1623 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1626 dwarf2_per_objfile
*m_per_objfile
;
1629 dwarf2_queue_item::~dwarf2_queue_item ()
1631 /* Anything still marked queued is likely to be in an
1632 inconsistent state, so discard it. */
1635 per_objfile
->remove_cu (per_cu
);
1640 /* The return type of find_file_and_directory. Note, the enclosed
1641 string pointers are only valid while this object is valid. */
1643 struct file_and_directory
1645 /* The filename. This is never NULL. */
1648 /* The compilation directory. NULL if not known. If we needed to
1649 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1650 points directly to the DW_AT_comp_dir string attribute owned by
1651 the obstack that owns the DIE. */
1652 const char *comp_dir
;
1654 /* If we needed to build a new string for comp_dir, this is what
1655 owns the storage. */
1656 std::string comp_dir_storage
;
1659 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1660 struct dwarf2_cu
*cu
);
1662 static htab_up
allocate_signatured_type_table ();
1664 static htab_up
allocate_dwo_unit_table ();
1666 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1667 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1668 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1670 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1672 static struct dwo_unit
*lookup_dwo_comp_unit
1673 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1674 ULONGEST signature
);
1676 static struct dwo_unit
*lookup_dwo_type_unit
1677 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1679 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1681 /* A unique pointer to a dwo_file. */
1683 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1685 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1687 static void check_producer (struct dwarf2_cu
*cu
);
1689 static void free_line_header_voidp (void *arg
);
1691 /* Various complaints about symbol reading that don't abort the process. */
1694 dwarf2_debug_line_missing_file_complaint (void)
1696 complaint (_(".debug_line section has line data without a file"));
1700 dwarf2_debug_line_missing_end_sequence_complaint (void)
1702 complaint (_(".debug_line section has line "
1703 "program sequence without an end"));
1707 dwarf2_complex_location_expr_complaint (void)
1709 complaint (_("location expression too complex"));
1713 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1716 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1721 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1723 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1727 /* Hash function for line_header_hash. */
1730 line_header_hash (const struct line_header
*ofs
)
1732 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1735 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1738 line_header_hash_voidp (const void *item
)
1740 const struct line_header
*ofs
= (const struct line_header
*) item
;
1742 return line_header_hash (ofs
);
1745 /* Equality function for line_header_hash. */
1748 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1750 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1751 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1753 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1754 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1759 /* See declaration. */
1761 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1764 can_copy (can_copy_
)
1767 names
= &dwarf2_elf_names
;
1769 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1770 locate_sections (obfd
, sec
, *names
);
1773 dwarf2_per_bfd::~dwarf2_per_bfd ()
1775 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1776 per_cu
->imported_symtabs_free ();
1778 for (signatured_type
*sig_type
: all_type_units
)
1779 sig_type
->per_cu
.imported_symtabs_free ();
1781 /* Everything else should be on this->obstack. */
1787 dwarf2_per_objfile::remove_all_cus ()
1789 for (auto pair
: m_dwarf2_cus
)
1792 m_dwarf2_cus
.clear ();
1795 /* A helper class that calls free_cached_comp_units on
1798 class free_cached_comp_units
1802 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1803 : m_per_objfile (per_objfile
)
1807 ~free_cached_comp_units ()
1809 m_per_objfile
->remove_all_cus ();
1812 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1816 dwarf2_per_objfile
*m_per_objfile
;
1822 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1824 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1826 return this->m_symtabs
[per_cu
->index
] != nullptr;
1832 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1834 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1836 return this->m_symtabs
[per_cu
->index
];
1842 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1843 compunit_symtab
*symtab
)
1845 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1846 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1848 this->m_symtabs
[per_cu
->index
] = symtab
;
1851 /* Try to locate the sections we need for DWARF 2 debugging
1852 information and return true if we have enough to do something.
1853 NAMES points to the dwarf2 section names, or is NULL if the standard
1854 ELF names are used. CAN_COPY is true for formats where symbol
1855 interposition is possible and so symbol values must follow copy
1856 relocation rules. */
1859 dwarf2_has_info (struct objfile
*objfile
,
1860 const struct dwarf2_debug_sections
*names
,
1863 if (objfile
->flags
& OBJF_READNEVER
)
1866 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1868 if (per_objfile
== NULL
)
1870 dwarf2_per_bfd
*per_bfd
;
1872 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1873 doesn't require relocations and if there aren't partial symbols
1874 from some other reader. */
1875 if (!objfile_has_partial_symbols (objfile
)
1876 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1878 /* See if one has been created for this BFD yet. */
1879 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1881 if (per_bfd
== nullptr)
1883 /* No, create it now. */
1884 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1885 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1890 /* No sharing possible, create one specifically for this objfile. */
1891 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1892 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1895 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1898 return (!per_objfile
->per_bfd
->info
.is_virtual
1899 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1900 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1901 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1904 /* When loading sections, we look either for uncompressed section or for
1905 compressed section names. */
1908 section_is_p (const char *section_name
,
1909 const struct dwarf2_section_names
*names
)
1911 if (names
->normal
!= NULL
1912 && strcmp (section_name
, names
->normal
) == 0)
1914 if (names
->compressed
!= NULL
1915 && strcmp (section_name
, names
->compressed
) == 0)
1920 /* See declaration. */
1923 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1924 const dwarf2_debug_sections
&names
)
1926 flagword aflag
= bfd_section_flags (sectp
);
1928 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1931 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1932 > bfd_get_file_size (abfd
))
1934 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1935 warning (_("Discarding section %s which has a section size (%s"
1936 ") larger than the file size [in module %s]"),
1937 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1938 bfd_get_filename (abfd
));
1940 else if (section_is_p (sectp
->name
, &names
.info
))
1942 this->info
.s
.section
= sectp
;
1943 this->info
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1947 this->abbrev
.s
.section
= sectp
;
1948 this->abbrev
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.line
))
1952 this->line
.s
.section
= sectp
;
1953 this->line
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.loc
))
1957 this->loc
.s
.section
= sectp
;
1958 this->loc
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.loclists
))
1962 this->loclists
.s
.section
= sectp
;
1963 this->loclists
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1967 this->macinfo
.s
.section
= sectp
;
1968 this->macinfo
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.macro
))
1972 this->macro
.s
.section
= sectp
;
1973 this->macro
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.str
))
1977 this->str
.s
.section
= sectp
;
1978 this->str
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1982 this->str_offsets
.s
.section
= sectp
;
1983 this->str_offsets
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.line_str
))
1987 this->line_str
.s
.section
= sectp
;
1988 this->line_str
.size
= bfd_section_size (sectp
);
1990 else if (section_is_p (sectp
->name
, &names
.addr
))
1992 this->addr
.s
.section
= sectp
;
1993 this->addr
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.frame
))
1997 this->frame
.s
.section
= sectp
;
1998 this->frame
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2002 this->eh_frame
.s
.section
= sectp
;
2003 this->eh_frame
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.ranges
))
2007 this->ranges
.s
.section
= sectp
;
2008 this->ranges
.size
= bfd_section_size (sectp
);
2010 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2012 this->rnglists
.s
.section
= sectp
;
2013 this->rnglists
.size
= bfd_section_size (sectp
);
2015 else if (section_is_p (sectp
->name
, &names
.types
))
2017 struct dwarf2_section_info type_section
;
2019 memset (&type_section
, 0, sizeof (type_section
));
2020 type_section
.s
.section
= sectp
;
2021 type_section
.size
= bfd_section_size (sectp
);
2023 this->types
.push_back (type_section
);
2025 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2027 this->gdb_index
.s
.section
= sectp
;
2028 this->gdb_index
.size
= bfd_section_size (sectp
);
2030 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2032 this->debug_names
.s
.section
= sectp
;
2033 this->debug_names
.size
= bfd_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2037 this->debug_aranges
.s
.section
= sectp
;
2038 this->debug_aranges
.size
= bfd_section_size (sectp
);
2041 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2042 && bfd_section_vma (sectp
) == 0)
2043 this->has_section_at_zero
= true;
2046 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2050 dwarf2_get_section_info (struct objfile
*objfile
,
2051 enum dwarf2_section_enum sect
,
2052 asection
**sectp
, const gdb_byte
**bufp
,
2053 bfd_size_type
*sizep
)
2055 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2056 struct dwarf2_section_info
*info
;
2058 /* We may see an objfile without any DWARF, in which case we just
2060 if (per_objfile
== NULL
)
2069 case DWARF2_DEBUG_FRAME
:
2070 info
= &per_objfile
->per_bfd
->frame
;
2072 case DWARF2_EH_FRAME
:
2073 info
= &per_objfile
->per_bfd
->eh_frame
;
2076 gdb_assert_not_reached ("unexpected section");
2079 info
->read (objfile
);
2081 *sectp
= info
->get_bfd_section ();
2082 *bufp
= info
->buffer
;
2083 *sizep
= info
->size
;
2086 /* A helper function to find the sections for a .dwz file. */
2089 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2091 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2093 /* Note that we only support the standard ELF names, because .dwz
2094 is ELF-only (at the time of writing). */
2095 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2097 dwz_file
->abbrev
.s
.section
= sectp
;
2098 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2100 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2102 dwz_file
->info
.s
.section
= sectp
;
2103 dwz_file
->info
.size
= bfd_section_size (sectp
);
2105 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2107 dwz_file
->str
.s
.section
= sectp
;
2108 dwz_file
->str
.size
= bfd_section_size (sectp
);
2110 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2112 dwz_file
->line
.s
.section
= sectp
;
2113 dwz_file
->line
.size
= bfd_section_size (sectp
);
2115 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2117 dwz_file
->macro
.s
.section
= sectp
;
2118 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2120 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2122 dwz_file
->gdb_index
.s
.section
= sectp
;
2123 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2125 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2127 dwz_file
->debug_names
.s
.section
= sectp
;
2128 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2132 /* See dwarf2read.h. */
2135 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2137 const char *filename
;
2138 bfd_size_type buildid_len_arg
;
2142 if (per_bfd
->dwz_file
!= NULL
)
2143 return per_bfd
->dwz_file
.get ();
2145 bfd_set_error (bfd_error_no_error
);
2146 gdb::unique_xmalloc_ptr
<char> data
2147 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2148 &buildid_len_arg
, &buildid
));
2151 if (bfd_get_error () == bfd_error_no_error
)
2153 error (_("could not read '.gnu_debugaltlink' section: %s"),
2154 bfd_errmsg (bfd_get_error ()));
2157 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2159 buildid_len
= (size_t) buildid_len_arg
;
2161 filename
= data
.get ();
2163 std::string abs_storage
;
2164 if (!IS_ABSOLUTE_PATH (filename
))
2166 gdb::unique_xmalloc_ptr
<char> abs
2167 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2169 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2170 filename
= abs_storage
.c_str ();
2173 /* First try the file name given in the section. If that doesn't
2174 work, try to use the build-id instead. */
2175 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2176 if (dwz_bfd
!= NULL
)
2178 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2179 dwz_bfd
.reset (nullptr);
2182 if (dwz_bfd
== NULL
)
2183 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2185 if (dwz_bfd
== nullptr)
2187 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2188 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2190 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2197 /* File successfully retrieved from server. */
2198 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2200 if (dwz_bfd
== nullptr)
2201 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2202 alt_filename
.get ());
2203 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2204 dwz_bfd
.reset (nullptr);
2208 if (dwz_bfd
== NULL
)
2209 error (_("could not find '.gnu_debugaltlink' file for %s"),
2210 bfd_get_filename (per_bfd
->obfd
));
2212 std::unique_ptr
<struct dwz_file
> result
2213 (new struct dwz_file (std::move (dwz_bfd
)));
2215 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2218 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2219 per_bfd
->dwz_file
= std::move (result
);
2220 return per_bfd
->dwz_file
.get ();
2223 /* DWARF quick_symbols_functions support. */
2225 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2226 unique line tables, so we maintain a separate table of all .debug_line
2227 derived entries to support the sharing.
2228 All the quick functions need is the list of file names. We discard the
2229 line_header when we're done and don't need to record it here. */
2230 struct quick_file_names
2232 /* The data used to construct the hash key. */
2233 struct stmt_list_hash hash
;
2235 /* The number of entries in file_names, real_names. */
2236 unsigned int num_file_names
;
2238 /* The file names from the line table, after being run through
2240 const char **file_names
;
2242 /* The file names from the line table after being run through
2243 gdb_realpath. These are computed lazily. */
2244 const char **real_names
;
2247 /* When using the index (and thus not using psymtabs), each CU has an
2248 object of this type. This is used to hold information needed by
2249 the various "quick" methods. */
2250 struct dwarf2_per_cu_quick_data
2252 /* The file table. This can be NULL if there was no file table
2253 or it's currently not read in.
2254 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2255 struct quick_file_names
*file_names
;
2257 /* A temporary mark bit used when iterating over all CUs in
2258 expand_symtabs_matching. */
2259 unsigned int mark
: 1;
2261 /* True if we've tried to read the file table and found there isn't one.
2262 There will be no point in trying to read it again next time. */
2263 unsigned int no_file_data
: 1;
2266 /* Utility hash function for a stmt_list_hash. */
2269 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2273 if (stmt_list_hash
->dwo_unit
!= NULL
)
2274 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2275 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2279 /* Utility equality function for a stmt_list_hash. */
2282 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2283 const struct stmt_list_hash
*rhs
)
2285 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2287 if (lhs
->dwo_unit
!= NULL
2288 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2291 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2294 /* Hash function for a quick_file_names. */
2297 hash_file_name_entry (const void *e
)
2299 const struct quick_file_names
*file_data
2300 = (const struct quick_file_names
*) e
;
2302 return hash_stmt_list_entry (&file_data
->hash
);
2305 /* Equality function for a quick_file_names. */
2308 eq_file_name_entry (const void *a
, const void *b
)
2310 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2311 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2313 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2316 /* Delete function for a quick_file_names. */
2319 delete_file_name_entry (void *e
)
2321 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2324 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2326 xfree ((void*) file_data
->file_names
[i
]);
2327 if (file_data
->real_names
)
2328 xfree ((void*) file_data
->real_names
[i
]);
2331 /* The space for the struct itself lives on the obstack, so we don't
2335 /* Create a quick_file_names hash table. */
2338 create_quick_file_names_table (unsigned int nr_initial_entries
)
2340 return htab_up (htab_create_alloc (nr_initial_entries
,
2341 hash_file_name_entry
, eq_file_name_entry
,
2342 delete_file_name_entry
, xcalloc
, xfree
));
2345 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2346 function is unrelated to symtabs, symtab would have to be created afterwards.
2347 You should call age_cached_comp_units after processing the CU. */
2350 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2353 if (per_cu
->is_debug_types
)
2354 load_full_type_unit (per_cu
, per_objfile
);
2356 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2358 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2360 return nullptr; /* Dummy CU. */
2362 dwarf2_find_base_address (cu
->dies
, cu
);
2367 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2370 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2371 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2373 /* Skip type_unit_groups, reading the type units they contain
2374 is handled elsewhere. */
2375 if (per_cu
->type_unit_group_p ())
2378 /* The destructor of dwarf2_queue_guard frees any entries left on
2379 the queue. After this point we're guaranteed to leave this function
2380 with the dwarf queue empty. */
2381 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2383 if (!per_objfile
->symtab_set_p (per_cu
))
2385 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2386 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2388 /* If we just loaded a CU from a DWO, and we're working with an index
2389 that may badly handle TUs, load all the TUs in that DWO as well.
2390 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2391 if (!per_cu
->is_debug_types
2393 && cu
->dwo_unit
!= NULL
2394 && per_objfile
->per_bfd
->index_table
!= NULL
2395 && per_objfile
->per_bfd
->index_table
->version
<= 7
2396 /* DWP files aren't supported yet. */
2397 && get_dwp_file (per_objfile
) == NULL
)
2398 queue_and_load_all_dwo_tus (cu
);
2401 process_queue (per_objfile
);
2403 /* Age the cache, releasing compilation units that have not
2404 been used recently. */
2405 per_objfile
->age_comp_units ();
2408 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2409 the per-objfile for which this symtab is instantiated.
2411 Returns the resulting symbol table. */
2413 static struct compunit_symtab
*
2414 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2415 dwarf2_per_objfile
*per_objfile
,
2418 gdb_assert (per_objfile
->per_bfd
->using_index
);
2420 if (!per_objfile
->symtab_set_p (per_cu
))
2422 free_cached_comp_units
freer (per_objfile
);
2423 scoped_restore decrementer
= increment_reading_symtab ();
2424 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2425 process_cu_includes (per_objfile
);
2428 return per_objfile
->get_symtab (per_cu
);
2431 /* See declaration. */
2433 dwarf2_per_cu_data
*
2434 dwarf2_per_bfd::get_cutu (int index
)
2436 if (index
>= this->all_comp_units
.size ())
2438 index
-= this->all_comp_units
.size ();
2439 gdb_assert (index
< this->all_type_units
.size ());
2440 return &this->all_type_units
[index
]->per_cu
;
2443 return this->all_comp_units
[index
];
2446 /* See declaration. */
2448 dwarf2_per_cu_data
*
2449 dwarf2_per_bfd::get_cu (int index
)
2451 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2453 return this->all_comp_units
[index
];
2456 /* See declaration. */
2459 dwarf2_per_bfd::get_tu (int index
)
2461 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2463 return this->all_type_units
[index
];
2468 dwarf2_per_cu_data
*
2469 dwarf2_per_bfd::allocate_per_cu ()
2471 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2472 result
->per_bfd
= this;
2473 result
->index
= m_num_psymtabs
++;
2480 dwarf2_per_bfd::allocate_signatured_type ()
2482 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2483 result
->per_cu
.per_bfd
= this;
2484 result
->per_cu
.index
= m_num_psymtabs
++;
2488 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2489 obstack, and constructed with the specified field values. */
2491 static dwarf2_per_cu_data
*
2492 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2493 struct dwarf2_section_info
*section
,
2495 sect_offset sect_off
, ULONGEST length
)
2497 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2498 the_cu
->sect_off
= sect_off
;
2499 the_cu
->length
= length
;
2500 the_cu
->section
= section
;
2501 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2502 struct dwarf2_per_cu_quick_data
);
2503 the_cu
->is_dwz
= is_dwz
;
2507 /* A helper for create_cus_from_index that handles a given list of
2511 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2512 const gdb_byte
*cu_list
, offset_type n_elements
,
2513 struct dwarf2_section_info
*section
,
2516 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2518 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2520 sect_offset sect_off
2521 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2522 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2525 dwarf2_per_cu_data
*per_cu
2526 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2528 per_bfd
->all_comp_units
.push_back (per_cu
);
2532 /* Read the CU list from the mapped index, and use it to create all
2533 the CU objects for PER_BFD. */
2536 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2537 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2538 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2540 gdb_assert (per_bfd
->all_comp_units
.empty ());
2541 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2543 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2546 if (dwz_elements
== 0)
2549 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2550 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2554 /* Create the signatured type hash table from the index. */
2557 create_signatured_type_table_from_index
2558 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2559 const gdb_byte
*bytes
, offset_type elements
)
2561 gdb_assert (per_bfd
->all_type_units
.empty ());
2562 per_bfd
->all_type_units
.reserve (elements
/ 3);
2564 htab_up sig_types_hash
= allocate_signatured_type_table ();
2566 for (offset_type i
= 0; i
< elements
; i
+= 3)
2568 struct signatured_type
*sig_type
;
2571 cu_offset type_offset_in_tu
;
2573 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2574 sect_offset sect_off
2575 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2577 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2579 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2582 sig_type
= per_bfd
->allocate_signatured_type ();
2583 sig_type
->signature
= signature
;
2584 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2585 sig_type
->per_cu
.is_debug_types
= 1;
2586 sig_type
->per_cu
.section
= section
;
2587 sig_type
->per_cu
.sect_off
= sect_off
;
2588 sig_type
->per_cu
.v
.quick
2589 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2590 struct dwarf2_per_cu_quick_data
);
2592 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2595 per_bfd
->all_type_units
.push_back (sig_type
);
2598 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2601 /* Create the signatured type hash table from .debug_names. */
2604 create_signatured_type_table_from_debug_names
2605 (dwarf2_per_objfile
*per_objfile
,
2606 const mapped_debug_names
&map
,
2607 struct dwarf2_section_info
*section
,
2608 struct dwarf2_section_info
*abbrev_section
)
2610 struct objfile
*objfile
= per_objfile
->objfile
;
2612 section
->read (objfile
);
2613 abbrev_section
->read (objfile
);
2615 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2616 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2618 htab_up sig_types_hash
= allocate_signatured_type_table ();
2620 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2622 struct signatured_type
*sig_type
;
2625 sect_offset sect_off
2626 = (sect_offset
) (extract_unsigned_integer
2627 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2629 map
.dwarf5_byte_order
));
2631 comp_unit_head cu_header
;
2632 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2634 section
->buffer
+ to_underlying (sect_off
),
2637 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2638 sig_type
->signature
= cu_header
.signature
;
2639 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2640 sig_type
->per_cu
.is_debug_types
= 1;
2641 sig_type
->per_cu
.section
= section
;
2642 sig_type
->per_cu
.sect_off
= sect_off
;
2643 sig_type
->per_cu
.v
.quick
2644 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2645 struct dwarf2_per_cu_quick_data
);
2647 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2650 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2653 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2656 /* Read the address map data from the mapped index, and use it to
2657 populate the objfile's psymtabs_addrmap. */
2660 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2661 struct mapped_index
*index
)
2663 struct objfile
*objfile
= per_objfile
->objfile
;
2664 struct gdbarch
*gdbarch
= objfile
->arch ();
2665 const gdb_byte
*iter
, *end
;
2666 struct addrmap
*mutable_map
;
2669 auto_obstack temp_obstack
;
2671 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2673 iter
= index
->address_table
.data ();
2674 end
= iter
+ index
->address_table
.size ();
2676 baseaddr
= objfile
->text_section_offset ();
2680 ULONGEST hi
, lo
, cu_index
;
2681 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2683 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2685 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2690 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2691 hex_string (lo
), hex_string (hi
));
2695 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2697 complaint (_(".gdb_index address table has invalid CU number %u"),
2698 (unsigned) cu_index
);
2702 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2703 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2704 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2705 per_objfile
->per_bfd
->get_cu (cu_index
));
2708 objfile
->partial_symtabs
->psymtabs_addrmap
2709 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2712 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2713 populate the objfile's psymtabs_addrmap. */
2716 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2717 struct dwarf2_section_info
*section
)
2719 struct objfile
*objfile
= per_objfile
->objfile
;
2720 bfd
*abfd
= objfile
->obfd
;
2721 struct gdbarch
*gdbarch
= objfile
->arch ();
2722 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2724 auto_obstack temp_obstack
;
2725 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2727 std::unordered_map
<sect_offset
,
2728 dwarf2_per_cu_data
*,
2729 gdb::hash_enum
<sect_offset
>>
2730 debug_info_offset_to_per_cu
;
2731 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2733 const auto insertpair
2734 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2735 if (!insertpair
.second
)
2737 warning (_("Section .debug_aranges in %s has duplicate "
2738 "debug_info_offset %s, ignoring .debug_aranges."),
2739 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2744 section
->read (objfile
);
2746 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2748 const gdb_byte
*addr
= section
->buffer
;
2750 while (addr
< section
->buffer
+ section
->size
)
2752 const gdb_byte
*const entry_addr
= addr
;
2753 unsigned int bytes_read
;
2755 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2759 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2760 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2761 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2762 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2764 warning (_("Section .debug_aranges in %s entry at offset %s "
2765 "length %s exceeds section length %s, "
2766 "ignoring .debug_aranges."),
2767 objfile_name (objfile
),
2768 plongest (entry_addr
- section
->buffer
),
2769 plongest (bytes_read
+ entry_length
),
2770 pulongest (section
->size
));
2774 /* The version number. */
2775 const uint16_t version
= read_2_bytes (abfd
, addr
);
2779 warning (_("Section .debug_aranges in %s entry at offset %s "
2780 "has unsupported version %d, ignoring .debug_aranges."),
2781 objfile_name (objfile
),
2782 plongest (entry_addr
- section
->buffer
), version
);
2786 const uint64_t debug_info_offset
2787 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2788 addr
+= offset_size
;
2789 const auto per_cu_it
2790 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2791 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2793 warning (_("Section .debug_aranges in %s entry at offset %s "
2794 "debug_info_offset %s does not exists, "
2795 "ignoring .debug_aranges."),
2796 objfile_name (objfile
),
2797 plongest (entry_addr
- section
->buffer
),
2798 pulongest (debug_info_offset
));
2801 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2803 const uint8_t address_size
= *addr
++;
2804 if (address_size
< 1 || address_size
> 8)
2806 warning (_("Section .debug_aranges in %s entry at offset %s "
2807 "address_size %u is invalid, ignoring .debug_aranges."),
2808 objfile_name (objfile
),
2809 plongest (entry_addr
- section
->buffer
), address_size
);
2813 const uint8_t segment_selector_size
= *addr
++;
2814 if (segment_selector_size
!= 0)
2816 warning (_("Section .debug_aranges in %s entry at offset %s "
2817 "segment_selector_size %u is not supported, "
2818 "ignoring .debug_aranges."),
2819 objfile_name (objfile
),
2820 plongest (entry_addr
- section
->buffer
),
2821 segment_selector_size
);
2825 /* Must pad to an alignment boundary that is twice the address
2826 size. It is undocumented by the DWARF standard but GCC does
2828 for (size_t padding
= ((-(addr
- section
->buffer
))
2829 & (2 * address_size
- 1));
2830 padding
> 0; padding
--)
2833 warning (_("Section .debug_aranges in %s entry at offset %s "
2834 "padding is not zero, ignoring .debug_aranges."),
2835 objfile_name (objfile
),
2836 plongest (entry_addr
- section
->buffer
));
2842 if (addr
+ 2 * address_size
> entry_end
)
2844 warning (_("Section .debug_aranges in %s entry at offset %s "
2845 "address list is not properly terminated, "
2846 "ignoring .debug_aranges."),
2847 objfile_name (objfile
),
2848 plongest (entry_addr
- section
->buffer
));
2851 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2853 addr
+= address_size
;
2854 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2856 addr
+= address_size
;
2857 if (start
== 0 && length
== 0)
2859 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
2861 /* Symbol was eliminated due to a COMDAT group. */
2864 ULONGEST end
= start
+ length
;
2865 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2867 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2869 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2873 objfile
->partial_symtabs
->psymtabs_addrmap
2874 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2877 /* Find a slot in the mapped index INDEX for the object named NAME.
2878 If NAME is found, set *VEC_OUT to point to the CU vector in the
2879 constant pool and return true. If NAME cannot be found, return
2883 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2884 offset_type
**vec_out
)
2887 offset_type slot
, step
;
2888 int (*cmp
) (const char *, const char *);
2890 gdb::unique_xmalloc_ptr
<char> without_params
;
2891 if (current_language
->la_language
== language_cplus
2892 || current_language
->la_language
== language_fortran
2893 || current_language
->la_language
== language_d
)
2895 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2898 if (strchr (name
, '(') != NULL
)
2900 without_params
= cp_remove_params (name
);
2902 if (without_params
!= NULL
)
2903 name
= without_params
.get ();
2907 /* Index version 4 did not support case insensitive searches. But the
2908 indices for case insensitive languages are built in lowercase, therefore
2909 simulate our NAME being searched is also lowercased. */
2910 hash
= mapped_index_string_hash ((index
->version
== 4
2911 && case_sensitivity
== case_sensitive_off
2912 ? 5 : index
->version
),
2915 slot
= hash
& (index
->symbol_table
.size () - 1);
2916 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2917 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2923 const auto &bucket
= index
->symbol_table
[slot
];
2924 if (bucket
.name
== 0 && bucket
.vec
== 0)
2927 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2928 if (!cmp (name
, str
))
2930 *vec_out
= (offset_type
*) (index
->constant_pool
2931 + MAYBE_SWAP (bucket
.vec
));
2935 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2939 /* A helper function that reads the .gdb_index from BUFFER and fills
2940 in MAP. FILENAME is the name of the file containing the data;
2941 it is used for error reporting. DEPRECATED_OK is true if it is
2942 ok to use deprecated sections.
2944 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2945 out parameters that are filled in with information about the CU and
2946 TU lists in the section.
2948 Returns true if all went well, false otherwise. */
2951 read_gdb_index_from_buffer (const char *filename
,
2953 gdb::array_view
<const gdb_byte
> buffer
,
2954 struct mapped_index
*map
,
2955 const gdb_byte
**cu_list
,
2956 offset_type
*cu_list_elements
,
2957 const gdb_byte
**types_list
,
2958 offset_type
*types_list_elements
)
2960 const gdb_byte
*addr
= &buffer
[0];
2962 /* Version check. */
2963 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2964 /* Versions earlier than 3 emitted every copy of a psymbol. This
2965 causes the index to behave very poorly for certain requests. Version 3
2966 contained incomplete addrmap. So, it seems better to just ignore such
2970 static int warning_printed
= 0;
2971 if (!warning_printed
)
2973 warning (_("Skipping obsolete .gdb_index section in %s."),
2975 warning_printed
= 1;
2979 /* Index version 4 uses a different hash function than index version
2982 Versions earlier than 6 did not emit psymbols for inlined
2983 functions. Using these files will cause GDB not to be able to
2984 set breakpoints on inlined functions by name, so we ignore these
2985 indices unless the user has done
2986 "set use-deprecated-index-sections on". */
2987 if (version
< 6 && !deprecated_ok
)
2989 static int warning_printed
= 0;
2990 if (!warning_printed
)
2993 Skipping deprecated .gdb_index section in %s.\n\
2994 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2995 to use the section anyway."),
2997 warning_printed
= 1;
3001 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3002 of the TU (for symbols coming from TUs),
3003 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3004 Plus gold-generated indices can have duplicate entries for global symbols,
3005 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3006 These are just performance bugs, and we can't distinguish gdb-generated
3007 indices from gold-generated ones, so issue no warning here. */
3009 /* Indexes with higher version than the one supported by GDB may be no
3010 longer backward compatible. */
3014 map
->version
= version
;
3016 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3019 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3020 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3024 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3025 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3026 - MAYBE_SWAP (metadata
[i
]))
3030 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3031 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3033 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3036 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3037 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3039 = gdb::array_view
<mapped_index::symbol_table_slot
>
3040 ((mapped_index::symbol_table_slot
*) symbol_table
,
3041 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3044 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3049 /* Callback types for dwarf2_read_gdb_index. */
3051 typedef gdb::function_view
3052 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3053 get_gdb_index_contents_ftype
;
3054 typedef gdb::function_view
3055 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3056 get_gdb_index_contents_dwz_ftype
;
3058 /* Read .gdb_index. If everything went ok, initialize the "quick"
3059 elements of all the CUs and return 1. Otherwise, return 0. */
3062 dwarf2_read_gdb_index
3063 (dwarf2_per_objfile
*per_objfile
,
3064 get_gdb_index_contents_ftype get_gdb_index_contents
,
3065 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3067 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3068 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3069 struct dwz_file
*dwz
;
3070 struct objfile
*objfile
= per_objfile
->objfile
;
3072 gdb::array_view
<const gdb_byte
> main_index_contents
3073 = get_gdb_index_contents (objfile
, per_objfile
->per_bfd
);
3075 if (main_index_contents
.empty ())
3078 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3079 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3080 use_deprecated_index_sections
,
3081 main_index_contents
, map
.get (), &cu_list
,
3082 &cu_list_elements
, &types_list
,
3083 &types_list_elements
))
3086 /* Don't use the index if it's empty. */
3087 if (map
->symbol_table
.empty ())
3090 /* If there is a .dwz file, read it so we can get its CU list as
3092 dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
3095 struct mapped_index dwz_map
;
3096 const gdb_byte
*dwz_types_ignore
;
3097 offset_type dwz_types_elements_ignore
;
3099 gdb::array_view
<const gdb_byte
> dwz_index_content
3100 = get_gdb_index_contents_dwz (objfile
, dwz
);
3102 if (dwz_index_content
.empty ())
3105 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3106 1, dwz_index_content
, &dwz_map
,
3107 &dwz_list
, &dwz_list_elements
,
3109 &dwz_types_elements_ignore
))
3111 warning (_("could not read '.gdb_index' section from %s; skipping"),
3112 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3117 create_cus_from_index (per_objfile
->per_bfd
, cu_list
, cu_list_elements
,
3118 dwz_list
, dwz_list_elements
);
3120 if (types_list_elements
)
3122 /* We can only handle a single .debug_types when we have an
3124 if (per_objfile
->per_bfd
->types
.size () != 1)
3127 dwarf2_section_info
*section
= &per_objfile
->per_bfd
->types
[0];
3129 create_signatured_type_table_from_index (per_objfile
->per_bfd
,
3130 section
, types_list
,
3131 types_list_elements
);
3134 create_addrmap_from_index (per_objfile
, map
.get ());
3136 per_objfile
->per_bfd
->index_table
= std::move (map
);
3137 per_objfile
->per_bfd
->using_index
= 1;
3138 per_objfile
->per_bfd
->quick_file_names_table
=
3139 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
3144 /* die_reader_func for dw2_get_file_names. */
3147 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3148 const gdb_byte
*info_ptr
,
3149 struct die_info
*comp_unit_die
)
3151 struct dwarf2_cu
*cu
= reader
->cu
;
3152 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3153 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3154 struct dwarf2_per_cu_data
*lh_cu
;
3155 struct attribute
*attr
;
3157 struct quick_file_names
*qfn
;
3159 gdb_assert (! this_cu
->is_debug_types
);
3161 /* Our callers never want to match partial units -- instead they
3162 will match the enclosing full CU. */
3163 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3165 this_cu
->v
.quick
->no_file_data
= 1;
3173 sect_offset line_offset
{};
3175 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3176 if (attr
!= nullptr)
3178 struct quick_file_names find_entry
;
3180 line_offset
= (sect_offset
) DW_UNSND (attr
);
3182 /* We may have already read in this line header (TU line header sharing).
3183 If we have we're done. */
3184 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3185 find_entry
.hash
.line_sect_off
= line_offset
;
3186 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3187 &find_entry
, INSERT
);
3190 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3194 lh
= dwarf_decode_line_header (line_offset
, cu
);
3198 lh_cu
->v
.quick
->no_file_data
= 1;
3202 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3203 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3204 qfn
->hash
.line_sect_off
= line_offset
;
3205 gdb_assert (slot
!= NULL
);
3208 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3211 if (strcmp (fnd
.name
, "<unknown>") != 0)
3214 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3216 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3217 qfn
->num_file_names
);
3219 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3220 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3221 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3222 fnd
.comp_dir
).release ();
3223 qfn
->real_names
= NULL
;
3225 lh_cu
->v
.quick
->file_names
= qfn
;
3228 /* A helper for the "quick" functions which attempts to read the line
3229 table for THIS_CU. */
3231 static struct quick_file_names
*
3232 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3233 dwarf2_per_objfile
*per_objfile
)
3235 /* This should never be called for TUs. */
3236 gdb_assert (! this_cu
->is_debug_types
);
3237 /* Nor type unit groups. */
3238 gdb_assert (! this_cu
->type_unit_group_p ());
3240 if (this_cu
->v
.quick
->file_names
!= NULL
)
3241 return this_cu
->v
.quick
->file_names
;
3242 /* If we know there is no line data, no point in looking again. */
3243 if (this_cu
->v
.quick
->no_file_data
)
3246 cutu_reader
reader (this_cu
, per_objfile
);
3247 if (!reader
.dummy_p
)
3248 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3250 if (this_cu
->v
.quick
->no_file_data
)
3252 return this_cu
->v
.quick
->file_names
;
3255 /* A helper for the "quick" functions which computes and caches the
3256 real path for a given file name from the line table. */
3259 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3260 struct quick_file_names
*qfn
, int index
)
3262 if (qfn
->real_names
== NULL
)
3263 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3264 qfn
->num_file_names
, const char *);
3266 if (qfn
->real_names
[index
] == NULL
)
3267 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3269 return qfn
->real_names
[index
];
3272 static struct symtab
*
3273 dw2_find_last_source_symtab (struct objfile
*objfile
)
3275 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3276 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3277 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3282 return compunit_primary_filetab (cust
);
3285 /* Traversal function for dw2_forget_cached_source_info. */
3288 dw2_free_cached_file_names (void **slot
, void *info
)
3290 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3292 if (file_data
->real_names
)
3296 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3298 xfree ((void*) file_data
->real_names
[i
]);
3299 file_data
->real_names
[i
] = NULL
;
3307 dw2_forget_cached_source_info (struct objfile
*objfile
)
3309 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3311 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3312 dw2_free_cached_file_names
, NULL
);
3315 /* Helper function for dw2_map_symtabs_matching_filename that expands
3316 the symtabs and calls the iterator. */
3319 dw2_map_expand_apply (struct objfile
*objfile
,
3320 struct dwarf2_per_cu_data
*per_cu
,
3321 const char *name
, const char *real_path
,
3322 gdb::function_view
<bool (symtab
*)> callback
)
3324 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3326 /* Don't visit already-expanded CUs. */
3327 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3328 if (per_objfile
->symtab_set_p (per_cu
))
3331 /* This may expand more than one symtab, and we want to iterate over
3333 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3335 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3336 last_made
, callback
);
3339 /* Implementation of the map_symtabs_matching_filename method. */
3342 dw2_map_symtabs_matching_filename
3343 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3344 gdb::function_view
<bool (symtab
*)> callback
)
3346 const char *name_basename
= lbasename (name
);
3347 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3349 /* The rule is CUs specify all the files, including those used by
3350 any TU, so there's no need to scan TUs here. */
3352 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3354 /* We only need to look at symtabs not already expanded. */
3355 if (per_objfile
->symtab_set_p (per_cu
))
3358 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3359 if (file_data
== NULL
)
3362 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3364 const char *this_name
= file_data
->file_names
[j
];
3365 const char *this_real_name
;
3367 if (compare_filenames_for_search (this_name
, name
))
3369 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3375 /* Before we invoke realpath, which can get expensive when many
3376 files are involved, do a quick comparison of the basenames. */
3377 if (! basenames_may_differ
3378 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3381 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3382 if (compare_filenames_for_search (this_real_name
, name
))
3384 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3390 if (real_path
!= NULL
)
3392 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3393 gdb_assert (IS_ABSOLUTE_PATH (name
));
3394 if (this_real_name
!= NULL
3395 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3397 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3409 /* Struct used to manage iterating over all CUs looking for a symbol. */
3411 struct dw2_symtab_iterator
3413 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3414 dwarf2_per_objfile
*per_objfile
;
3415 /* If set, only look for symbols that match that block. Valid values are
3416 GLOBAL_BLOCK and STATIC_BLOCK. */
3417 gdb::optional
<block_enum
> block_index
;
3418 /* The kind of symbol we're looking for. */
3420 /* The list of CUs from the index entry of the symbol,
3421 or NULL if not found. */
3423 /* The next element in VEC to look at. */
3425 /* The number of elements in VEC, or zero if there is no match. */
3427 /* Have we seen a global version of the symbol?
3428 If so we can ignore all further global instances.
3429 This is to work around gold/15646, inefficient gold-generated
3434 /* Initialize the index symtab iterator ITER. */
3437 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3438 dwarf2_per_objfile
*per_objfile
,
3439 gdb::optional
<block_enum
> block_index
,
3443 iter
->per_objfile
= per_objfile
;
3444 iter
->block_index
= block_index
;
3445 iter
->domain
= domain
;
3447 iter
->global_seen
= 0;
3449 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3451 /* index is NULL if OBJF_READNOW. */
3452 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3453 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3461 /* Return the next matching CU or NULL if there are no more. */
3463 static struct dwarf2_per_cu_data
*
3464 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3466 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3468 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3470 offset_type cu_index_and_attrs
=
3471 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3472 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3473 gdb_index_symbol_kind symbol_kind
=
3474 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3475 /* Only check the symbol attributes if they're present.
3476 Indices prior to version 7 don't record them,
3477 and indices >= 7 may elide them for certain symbols
3478 (gold does this). */
3480 (per_objfile
->per_bfd
->index_table
->version
>= 7
3481 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3483 /* Don't crash on bad data. */
3484 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3485 + per_objfile
->per_bfd
->all_type_units
.size ()))
3487 complaint (_(".gdb_index entry has bad CU index"
3488 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3492 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3494 /* Skip if already read in. */
3495 if (per_objfile
->symtab_set_p (per_cu
))
3498 /* Check static vs global. */
3501 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3503 if (iter
->block_index
.has_value ())
3505 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3507 if (is_static
!= want_static
)
3511 /* Work around gold/15646. */
3513 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3515 if (iter
->global_seen
)
3518 iter
->global_seen
= 1;
3522 /* Only check the symbol's kind if it has one. */
3525 switch (iter
->domain
)
3528 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3529 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3530 /* Some types are also in VAR_DOMAIN. */
3531 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3535 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3539 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3543 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3558 static struct compunit_symtab
*
3559 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3560 const char *name
, domain_enum domain
)
3562 struct compunit_symtab
*stab_best
= NULL
;
3563 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3565 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3567 struct dw2_symtab_iterator iter
;
3568 struct dwarf2_per_cu_data
*per_cu
;
3570 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3572 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3574 struct symbol
*sym
, *with_opaque
= NULL
;
3575 struct compunit_symtab
*stab
3576 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3577 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3578 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3580 sym
= block_find_symbol (block
, name
, domain
,
3581 block_find_non_opaque_type_preferred
,
3584 /* Some caution must be observed with overloaded functions
3585 and methods, since the index will not contain any overload
3586 information (but NAME might contain it). */
3589 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3591 if (with_opaque
!= NULL
3592 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3595 /* Keep looking through other CUs. */
3602 dw2_print_stats (struct objfile
*objfile
)
3604 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3605 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3606 + per_objfile
->per_bfd
->all_type_units
.size ());
3609 for (int i
= 0; i
< total
; ++i
)
3611 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3613 if (!per_objfile
->symtab_set_p (per_cu
))
3616 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3617 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3620 /* This dumps minimal information about the index.
3621 It is called via "mt print objfiles".
3622 One use is to verify .gdb_index has been loaded by the
3623 gdb.dwarf2/gdb-index.exp testcase. */
3626 dw2_dump (struct objfile
*objfile
)
3628 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3630 gdb_assert (per_objfile
->per_bfd
->using_index
);
3631 printf_filtered (".gdb_index:");
3632 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3634 printf_filtered (" version %d\n",
3635 per_objfile
->per_bfd
->index_table
->version
);
3638 printf_filtered (" faked for \"readnow\"\n");
3639 printf_filtered ("\n");
3643 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3644 const char *func_name
)
3646 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3648 struct dw2_symtab_iterator iter
;
3649 struct dwarf2_per_cu_data
*per_cu
;
3651 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3653 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3654 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3659 dw2_expand_all_symtabs (struct objfile
*objfile
)
3661 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3662 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3663 + per_objfile
->per_bfd
->all_type_units
.size ());
3665 for (int i
= 0; i
< total_units
; ++i
)
3667 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3669 /* We don't want to directly expand a partial CU, because if we
3670 read it with the wrong language, then assertion failures can
3671 be triggered later on. See PR symtab/23010. So, tell
3672 dw2_instantiate_symtab to skip partial CUs -- any important
3673 partial CU will be read via DW_TAG_imported_unit anyway. */
3674 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3679 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3680 const char *fullname
)
3682 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3684 /* We don't need to consider type units here.
3685 This is only called for examining code, e.g. expand_line_sal.
3686 There can be an order of magnitude (or more) more type units
3687 than comp units, and we avoid them if we can. */
3689 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3691 /* We only need to look at symtabs not already expanded. */
3692 if (per_objfile
->symtab_set_p (per_cu
))
3695 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3696 if (file_data
== NULL
)
3699 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3701 const char *this_fullname
= file_data
->file_names
[j
];
3703 if (filename_cmp (this_fullname
, fullname
) == 0)
3705 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3713 dw2_expand_symtabs_matching_symbol
3714 (mapped_index_base
&index
,
3715 const lookup_name_info
&lookup_name_in
,
3716 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3717 enum search_domain kind
,
3718 gdb::function_view
<bool (offset_type
)> match_callback
,
3719 dwarf2_per_objfile
*per_objfile
);
3722 dw2_expand_symtabs_matching_one
3723 (dwarf2_per_cu_data
*per_cu
,
3724 dwarf2_per_objfile
*per_objfile
,
3725 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3726 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3729 dw2_map_matching_symbols
3730 (struct objfile
*objfile
,
3731 const lookup_name_info
&name
, domain_enum domain
,
3733 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3734 symbol_compare_ftype
*ordered_compare
)
3737 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3739 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3741 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3743 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3744 here though if the current language is Ada for a non-Ada objfile
3746 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3748 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3749 auto matcher
= [&] (const char *symname
)
3751 if (ordered_compare
== nullptr)
3753 return ordered_compare (symname
, match_name
) == 0;
3756 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3757 [&] (offset_type namei
)
3759 struct dw2_symtab_iterator iter
;
3760 struct dwarf2_per_cu_data
*per_cu
;
3762 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3764 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3765 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3772 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3773 proceed assuming all symtabs have been read in. */
3776 for (compunit_symtab
*cust
: objfile
->compunits ())
3778 const struct block
*block
;
3782 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3783 if (!iterate_over_symbols_terminated (block
, name
,
3789 /* Starting from a search name, return the string that finds the upper
3790 bound of all strings that start with SEARCH_NAME in a sorted name
3791 list. Returns the empty string to indicate that the upper bound is
3792 the end of the list. */
3795 make_sort_after_prefix_name (const char *search_name
)
3797 /* When looking to complete "func", we find the upper bound of all
3798 symbols that start with "func" by looking for where we'd insert
3799 the closest string that would follow "func" in lexicographical
3800 order. Usually, that's "func"-with-last-character-incremented,
3801 i.e. "fund". Mind non-ASCII characters, though. Usually those
3802 will be UTF-8 multi-byte sequences, but we can't be certain.
3803 Especially mind the 0xff character, which is a valid character in
3804 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3805 rule out compilers allowing it in identifiers. Note that
3806 conveniently, strcmp/strcasecmp are specified to compare
3807 characters interpreted as unsigned char. So what we do is treat
3808 the whole string as a base 256 number composed of a sequence of
3809 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3810 to 0, and carries 1 to the following more-significant position.
3811 If the very first character in SEARCH_NAME ends up incremented
3812 and carries/overflows, then the upper bound is the end of the
3813 list. The string after the empty string is also the empty
3816 Some examples of this operation:
3818 SEARCH_NAME => "+1" RESULT
3822 "\xff" "a" "\xff" => "\xff" "b"
3827 Then, with these symbols for example:
3833 completing "func" looks for symbols between "func" and
3834 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3835 which finds "func" and "func1", but not "fund".
3839 funcÿ (Latin1 'ÿ' [0xff])
3843 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3844 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3848 ÿÿ (Latin1 'ÿ' [0xff])
3851 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3852 the end of the list.
3854 std::string after
= search_name
;
3855 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3857 if (!after
.empty ())
3858 after
.back () = (unsigned char) after
.back () + 1;
3862 /* See declaration. */
3864 std::pair
<std::vector
<name_component
>::const_iterator
,
3865 std::vector
<name_component
>::const_iterator
>
3866 mapped_index_base::find_name_components_bounds
3867 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3868 dwarf2_per_objfile
*per_objfile
) const
3871 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3873 const char *lang_name
3874 = lookup_name_without_params
.language_lookup_name (lang
);
3876 /* Comparison function object for lower_bound that matches against a
3877 given symbol name. */
3878 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3881 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3882 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3883 return name_cmp (elem_name
, name
) < 0;
3886 /* Comparison function object for upper_bound that matches against a
3887 given symbol name. */
3888 auto lookup_compare_upper
= [&] (const char *name
,
3889 const name_component
&elem
)
3891 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3892 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3893 return name_cmp (name
, elem_name
) < 0;
3896 auto begin
= this->name_components
.begin ();
3897 auto end
= this->name_components
.end ();
3899 /* Find the lower bound. */
3902 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3905 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3908 /* Find the upper bound. */
3911 if (lookup_name_without_params
.completion_mode ())
3913 /* In completion mode, we want UPPER to point past all
3914 symbols names that have the same prefix. I.e., with
3915 these symbols, and completing "func":
3917 function << lower bound
3919 other_function << upper bound
3921 We find the upper bound by looking for the insertion
3922 point of "func"-with-last-character-incremented,
3924 std::string after
= make_sort_after_prefix_name (lang_name
);
3927 return std::lower_bound (lower
, end
, after
.c_str (),
3928 lookup_compare_lower
);
3931 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3934 return {lower
, upper
};
3937 /* See declaration. */
3940 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3942 if (!this->name_components
.empty ())
3945 this->name_components_casing
= case_sensitivity
;
3947 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3949 /* The code below only knows how to break apart components of C++
3950 symbol names (and other languages that use '::' as
3951 namespace/module separator) and Ada symbol names. */
3952 auto count
= this->symbol_name_count ();
3953 for (offset_type idx
= 0; idx
< count
; idx
++)
3955 if (this->symbol_name_slot_invalid (idx
))
3958 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3960 /* Add each name component to the name component table. */
3961 unsigned int previous_len
= 0;
3963 if (strstr (name
, "::") != nullptr)
3965 for (unsigned int current_len
= cp_find_first_component (name
);
3966 name
[current_len
] != '\0';
3967 current_len
+= cp_find_first_component (name
+ current_len
))
3969 gdb_assert (name
[current_len
] == ':');
3970 this->name_components
.push_back ({previous_len
, idx
});
3971 /* Skip the '::'. */
3973 previous_len
= current_len
;
3978 /* Handle the Ada encoded (aka mangled) form here. */
3979 for (const char *iter
= strstr (name
, "__");
3981 iter
= strstr (iter
, "__"))
3983 this->name_components
.push_back ({previous_len
, idx
});
3985 previous_len
= iter
- name
;
3989 this->name_components
.push_back ({previous_len
, idx
});
3992 /* Sort name_components elements by name. */
3993 auto name_comp_compare
= [&] (const name_component
&left
,
3994 const name_component
&right
)
3996 const char *left_qualified
3997 = this->symbol_name_at (left
.idx
, per_objfile
);
3998 const char *right_qualified
3999 = this->symbol_name_at (right
.idx
, per_objfile
);
4001 const char *left_name
= left_qualified
+ left
.name_offset
;
4002 const char *right_name
= right_qualified
+ right
.name_offset
;
4004 return name_cmp (left_name
, right_name
) < 0;
4007 std::sort (this->name_components
.begin (),
4008 this->name_components
.end (),
4012 /* Helper for dw2_expand_symtabs_matching that works with a
4013 mapped_index_base instead of the containing objfile. This is split
4014 to a separate function in order to be able to unit test the
4015 name_components matching using a mock mapped_index_base. For each
4016 symbol name that matches, calls MATCH_CALLBACK, passing it the
4017 symbol's index in the mapped_index_base symbol table. */
4020 dw2_expand_symtabs_matching_symbol
4021 (mapped_index_base
&index
,
4022 const lookup_name_info
&lookup_name_in
,
4023 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4024 enum search_domain kind
,
4025 gdb::function_view
<bool (offset_type
)> match_callback
,
4026 dwarf2_per_objfile
*per_objfile
)
4028 lookup_name_info lookup_name_without_params
4029 = lookup_name_in
.make_ignore_params ();
4031 /* Build the symbol name component sorted vector, if we haven't
4033 index
.build_name_components (per_objfile
);
4035 /* The same symbol may appear more than once in the range though.
4036 E.g., if we're looking for symbols that complete "w", and we have
4037 a symbol named "w1::w2", we'll find the two name components for
4038 that same symbol in the range. To be sure we only call the
4039 callback once per symbol, we first collect the symbol name
4040 indexes that matched in a temporary vector and ignore
4042 std::vector
<offset_type
> matches
;
4044 struct name_and_matcher
4046 symbol_name_matcher_ftype
*matcher
;
4049 bool operator== (const name_and_matcher
&other
) const
4051 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4055 /* A vector holding all the different symbol name matchers, for all
4057 std::vector
<name_and_matcher
> matchers
;
4059 for (int i
= 0; i
< nr_languages
; i
++)
4061 enum language lang_e
= (enum language
) i
;
4063 const language_defn
*lang
= language_def (lang_e
);
4064 symbol_name_matcher_ftype
*name_matcher
4065 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4067 name_and_matcher key
{
4069 lookup_name_without_params
.language_lookup_name (lang_e
)
4072 /* Don't insert the same comparison routine more than once.
4073 Note that we do this linear walk. This is not a problem in
4074 practice because the number of supported languages is
4076 if (std::find (matchers
.begin (), matchers
.end (), key
)
4079 matchers
.push_back (std::move (key
));
4082 = index
.find_name_components_bounds (lookup_name_without_params
,
4083 lang_e
, per_objfile
);
4085 /* Now for each symbol name in range, check to see if we have a name
4086 match, and if so, call the MATCH_CALLBACK callback. */
4088 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4090 const char *qualified
4091 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4093 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4094 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4097 matches
.push_back (bounds
.first
->idx
);
4101 std::sort (matches
.begin (), matches
.end ());
4103 /* Finally call the callback, once per match. */
4105 for (offset_type idx
: matches
)
4109 if (!match_callback (idx
))
4115 /* Above we use a type wider than idx's for 'prev', since 0 and
4116 (offset_type)-1 are both possible values. */
4117 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4122 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4124 /* A mock .gdb_index/.debug_names-like name index table, enough to
4125 exercise dw2_expand_symtabs_matching_symbol, which works with the
4126 mapped_index_base interface. Builds an index from the symbol list
4127 passed as parameter to the constructor. */
4128 class mock_mapped_index
: public mapped_index_base
4131 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4132 : m_symbol_table (symbols
)
4135 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4137 /* Return the number of names in the symbol table. */
4138 size_t symbol_name_count () const override
4140 return m_symbol_table
.size ();
4143 /* Get the name of the symbol at IDX in the symbol table. */
4144 const char *symbol_name_at
4145 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4147 return m_symbol_table
[idx
];
4151 gdb::array_view
<const char *> m_symbol_table
;
4154 /* Convenience function that converts a NULL pointer to a "<null>"
4155 string, to pass to print routines. */
4158 string_or_null (const char *str
)
4160 return str
!= NULL
? str
: "<null>";
4163 /* Check if a lookup_name_info built from
4164 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4165 index. EXPECTED_LIST is the list of expected matches, in expected
4166 matching order. If no match expected, then an empty list is
4167 specified. Returns true on success. On failure prints a warning
4168 indicating the file:line that failed, and returns false. */
4171 check_match (const char *file
, int line
,
4172 mock_mapped_index
&mock_index
,
4173 const char *name
, symbol_name_match_type match_type
,
4174 bool completion_mode
,
4175 std::initializer_list
<const char *> expected_list
,
4176 dwarf2_per_objfile
*per_objfile
)
4178 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4180 bool matched
= true;
4182 auto mismatch
= [&] (const char *expected_str
,
4185 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4186 "expected=\"%s\", got=\"%s\"\n"),
4188 (match_type
== symbol_name_match_type::FULL
4190 name
, string_or_null (expected_str
), string_or_null (got
));
4194 auto expected_it
= expected_list
.begin ();
4195 auto expected_end
= expected_list
.end ();
4197 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4199 [&] (offset_type idx
)
4201 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4202 const char *expected_str
4203 = expected_it
== expected_end
? NULL
: *expected_it
++;
4205 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4206 mismatch (expected_str
, matched_name
);
4210 const char *expected_str
4211 = expected_it
== expected_end
? NULL
: *expected_it
++;
4212 if (expected_str
!= NULL
)
4213 mismatch (expected_str
, NULL
);
4218 /* The symbols added to the mock mapped_index for testing (in
4220 static const char *test_symbols
[] = {
4229 "ns2::tmpl<int>::foo2",
4230 "(anonymous namespace)::A::B::C",
4232 /* These are used to check that the increment-last-char in the
4233 matching algorithm for completion doesn't match "t1_fund" when
4234 completing "t1_func". */
4240 /* A UTF-8 name with multi-byte sequences to make sure that
4241 cp-name-parser understands this as a single identifier ("função"
4242 is "function" in PT). */
4245 /* \377 (0xff) is Latin1 'ÿ'. */
4248 /* \377 (0xff) is Latin1 'ÿ'. */
4252 /* A name with all sorts of complications. Starts with "z" to make
4253 it easier for the completion tests below. */
4254 #define Z_SYM_NAME \
4255 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4256 "::tuple<(anonymous namespace)::ui*, " \
4257 "std::default_delete<(anonymous namespace)::ui>, void>"
4262 /* Returns true if the mapped_index_base::find_name_component_bounds
4263 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4264 in completion mode. */
4267 check_find_bounds_finds (mapped_index_base
&index
,
4268 const char *search_name
,
4269 gdb::array_view
<const char *> expected_syms
,
4270 dwarf2_per_objfile
*per_objfile
)
4272 lookup_name_info
lookup_name (search_name
,
4273 symbol_name_match_type::FULL
, true);
4275 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4279 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4280 if (distance
!= expected_syms
.size ())
4283 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4285 auto nc_elem
= bounds
.first
+ exp_elem
;
4286 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4287 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4294 /* Test the lower-level mapped_index::find_name_component_bounds
4298 test_mapped_index_find_name_component_bounds ()
4300 mock_mapped_index
mock_index (test_symbols
);
4302 mock_index
.build_name_components (NULL
/* per_objfile */);
4304 /* Test the lower-level mapped_index::find_name_component_bounds
4305 method in completion mode. */
4307 static const char *expected_syms
[] = {
4312 SELF_CHECK (check_find_bounds_finds
4313 (mock_index
, "t1_func", expected_syms
,
4314 NULL
/* per_objfile */));
4317 /* Check that the increment-last-char in the name matching algorithm
4318 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4320 static const char *expected_syms1
[] = {
4324 SELF_CHECK (check_find_bounds_finds
4325 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4327 static const char *expected_syms2
[] = {
4330 SELF_CHECK (check_find_bounds_finds
4331 (mock_index
, "\377\377", expected_syms2
,
4332 NULL
/* per_objfile */));
4336 /* Test dw2_expand_symtabs_matching_symbol. */
4339 test_dw2_expand_symtabs_matching_symbol ()
4341 mock_mapped_index
mock_index (test_symbols
);
4343 /* We let all tests run until the end even if some fails, for debug
4345 bool any_mismatch
= false;
4347 /* Create the expected symbols list (an initializer_list). Needed
4348 because lists have commas, and we need to pass them to CHECK,
4349 which is a macro. */
4350 #define EXPECT(...) { __VA_ARGS__ }
4352 /* Wrapper for check_match that passes down the current
4353 __FILE__/__LINE__. */
4354 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4355 any_mismatch |= !check_match (__FILE__, __LINE__, \
4357 NAME, MATCH_TYPE, COMPLETION_MODE, \
4358 EXPECTED_LIST, NULL)
4360 /* Identity checks. */
4361 for (const char *sym
: test_symbols
)
4363 /* Should be able to match all existing symbols. */
4364 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4367 /* Should be able to match all existing symbols with
4369 std::string with_params
= std::string (sym
) + "(int)";
4370 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4373 /* Should be able to match all existing symbols with
4374 parameters and qualifiers. */
4375 with_params
= std::string (sym
) + " ( int ) const";
4376 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4379 /* This should really find sym, but cp-name-parser.y doesn't
4380 know about lvalue/rvalue qualifiers yet. */
4381 with_params
= std::string (sym
) + " ( int ) &&";
4382 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4386 /* Check that the name matching algorithm for completion doesn't get
4387 confused with Latin1 'ÿ' / 0xff. */
4389 static const char str
[] = "\377";
4390 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4391 EXPECT ("\377", "\377\377123"));
4394 /* Check that the increment-last-char in the matching algorithm for
4395 completion doesn't match "t1_fund" when completing "t1_func". */
4397 static const char str
[] = "t1_func";
4398 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4399 EXPECT ("t1_func", "t1_func1"));
4402 /* Check that completion mode works at each prefix of the expected
4405 static const char str
[] = "function(int)";
4406 size_t len
= strlen (str
);
4409 for (size_t i
= 1; i
< len
; i
++)
4411 lookup
.assign (str
, i
);
4412 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4413 EXPECT ("function"));
4417 /* While "w" is a prefix of both components, the match function
4418 should still only be called once. */
4420 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4422 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4426 /* Same, with a "complicated" symbol. */
4428 static const char str
[] = Z_SYM_NAME
;
4429 size_t len
= strlen (str
);
4432 for (size_t i
= 1; i
< len
; i
++)
4434 lookup
.assign (str
, i
);
4435 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4436 EXPECT (Z_SYM_NAME
));
4440 /* In FULL mode, an incomplete symbol doesn't match. */
4442 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4446 /* A complete symbol with parameters matches any overload, since the
4447 index has no overload info. */
4449 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4450 EXPECT ("std::zfunction", "std::zfunction2"));
4451 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4452 EXPECT ("std::zfunction", "std::zfunction2"));
4453 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4454 EXPECT ("std::zfunction", "std::zfunction2"));
4457 /* Check that whitespace is ignored appropriately. A symbol with a
4458 template argument list. */
4460 static const char expected
[] = "ns::foo<int>";
4461 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4463 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4467 /* Check that whitespace is ignored appropriately. A symbol with a
4468 template argument list that includes a pointer. */
4470 static const char expected
[] = "ns::foo<char*>";
4471 /* Try both completion and non-completion modes. */
4472 static const bool completion_mode
[2] = {false, true};
4473 for (size_t i
= 0; i
< 2; i
++)
4475 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4476 completion_mode
[i
], EXPECT (expected
));
4477 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4478 completion_mode
[i
], EXPECT (expected
));
4480 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4481 completion_mode
[i
], EXPECT (expected
));
4482 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4483 completion_mode
[i
], EXPECT (expected
));
4488 /* Check method qualifiers are ignored. */
4489 static const char expected
[] = "ns::foo<char*>";
4490 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4491 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4492 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4493 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4494 CHECK_MATCH ("foo < char * > ( int ) const",
4495 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4496 CHECK_MATCH ("foo < char * > ( int ) &&",
4497 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4500 /* Test lookup names that don't match anything. */
4502 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4505 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4509 /* Some wild matching tests, exercising "(anonymous namespace)",
4510 which should not be confused with a parameter list. */
4512 static const char *syms
[] = {
4516 "A :: B :: C ( int )",
4521 for (const char *s
: syms
)
4523 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4524 EXPECT ("(anonymous namespace)::A::B::C"));
4529 static const char expected
[] = "ns2::tmpl<int>::foo2";
4530 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4532 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4536 SELF_CHECK (!any_mismatch
);
4545 test_mapped_index_find_name_component_bounds ();
4546 test_dw2_expand_symtabs_matching_symbol ();
4549 }} // namespace selftests::dw2_expand_symtabs_matching
4551 #endif /* GDB_SELF_TEST */
4553 /* If FILE_MATCHER is NULL or if PER_CU has
4554 dwarf2_per_cu_quick_data::MARK set (see
4555 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4556 EXPANSION_NOTIFY on it. */
4559 dw2_expand_symtabs_matching_one
4560 (dwarf2_per_cu_data
*per_cu
,
4561 dwarf2_per_objfile
*per_objfile
,
4562 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4563 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4565 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4567 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4569 compunit_symtab
*symtab
4570 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4571 gdb_assert (symtab
!= nullptr);
4573 if (expansion_notify
!= NULL
&& symtab_was_null
)
4574 expansion_notify (symtab
);
4578 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4579 matched, to expand corresponding CUs that were marked. IDX is the
4580 index of the symbol name that matched. */
4583 dw2_expand_marked_cus
4584 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4585 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4586 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4589 offset_type
*vec
, vec_len
, vec_idx
;
4590 bool global_seen
= false;
4591 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4593 vec
= (offset_type
*) (index
.constant_pool
4594 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4595 vec_len
= MAYBE_SWAP (vec
[0]);
4596 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4598 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4599 /* This value is only valid for index versions >= 7. */
4600 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4601 gdb_index_symbol_kind symbol_kind
=
4602 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4603 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4604 /* Only check the symbol attributes if they're present.
4605 Indices prior to version 7 don't record them,
4606 and indices >= 7 may elide them for certain symbols
4607 (gold does this). */
4610 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4612 /* Work around gold/15646. */
4615 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4623 /* Only check the symbol's kind if it has one. */
4628 case VARIABLES_DOMAIN
:
4629 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4632 case FUNCTIONS_DOMAIN
:
4633 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4637 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4640 case MODULES_DOMAIN
:
4641 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4649 /* Don't crash on bad data. */
4650 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4651 + per_objfile
->per_bfd
->all_type_units
.size ()))
4653 complaint (_(".gdb_index entry has bad CU index"
4654 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4658 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4659 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4664 /* If FILE_MATCHER is non-NULL, set all the
4665 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4666 that match FILE_MATCHER. */
4669 dw_expand_symtabs_matching_file_matcher
4670 (dwarf2_per_objfile
*per_objfile
,
4671 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4673 if (file_matcher
== NULL
)
4676 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4678 NULL
, xcalloc
, xfree
));
4679 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4681 NULL
, xcalloc
, xfree
));
4683 /* The rule is CUs specify all the files, including those used by
4684 any TU, so there's no need to scan TUs here. */
4686 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4690 per_cu
->v
.quick
->mark
= 0;
4692 /* We only need to look at symtabs not already expanded. */
4693 if (per_objfile
->symtab_set_p (per_cu
))
4696 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4697 if (file_data
== NULL
)
4700 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4702 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4704 per_cu
->v
.quick
->mark
= 1;
4708 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4710 const char *this_real_name
;
4712 if (file_matcher (file_data
->file_names
[j
], false))
4714 per_cu
->v
.quick
->mark
= 1;
4718 /* Before we invoke realpath, which can get expensive when many
4719 files are involved, do a quick comparison of the basenames. */
4720 if (!basenames_may_differ
4721 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4725 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4726 if (file_matcher (this_real_name
, false))
4728 per_cu
->v
.quick
->mark
= 1;
4733 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4734 ? visited_found
.get ()
4735 : visited_not_found
.get (),
4742 dw2_expand_symtabs_matching
4743 (struct objfile
*objfile
,
4744 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4745 const lookup_name_info
*lookup_name
,
4746 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4747 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4748 enum search_domain kind
)
4750 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4752 /* index_table is NULL if OBJF_READNOW. */
4753 if (!per_objfile
->per_bfd
->index_table
)
4756 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4758 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4760 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4764 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4765 file_matcher
, expansion_notify
);
4770 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4772 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4774 kind
, [&] (offset_type idx
)
4776 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4782 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4785 static struct compunit_symtab
*
4786 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4791 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4792 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4795 if (cust
->includes
== NULL
)
4798 for (i
= 0; cust
->includes
[i
]; ++i
)
4800 struct compunit_symtab
*s
= cust
->includes
[i
];
4802 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4810 static struct compunit_symtab
*
4811 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4812 struct bound_minimal_symbol msymbol
,
4814 struct obj_section
*section
,
4817 struct dwarf2_per_cu_data
*data
;
4818 struct compunit_symtab
*result
;
4820 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4823 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4824 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4825 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4829 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4830 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4831 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4832 paddress (objfile
->arch (), pc
));
4834 result
= recursively_find_pc_sect_compunit_symtab
4835 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4837 gdb_assert (result
!= NULL
);
4842 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4843 void *data
, int need_fullname
)
4845 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4847 if (!per_objfile
->per_bfd
->filenames_cache
)
4849 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4851 htab_up
visited (htab_create_alloc (10,
4852 htab_hash_pointer
, htab_eq_pointer
,
4853 NULL
, xcalloc
, xfree
));
4855 /* The rule is CUs specify all the files, including those used
4856 by any TU, so there's no need to scan TUs here. We can
4857 ignore file names coming from already-expanded CUs. */
4859 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4861 if (per_objfile
->symtab_set_p (per_cu
))
4863 void **slot
= htab_find_slot (visited
.get (),
4864 per_cu
->v
.quick
->file_names
,
4867 *slot
= per_cu
->v
.quick
->file_names
;
4871 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4873 /* We only need to look at symtabs not already expanded. */
4874 if (per_objfile
->symtab_set_p (per_cu
))
4877 quick_file_names
*file_data
4878 = dw2_get_file_names (per_cu
, per_objfile
);
4879 if (file_data
== NULL
)
4882 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4885 /* Already visited. */
4890 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4892 const char *filename
= file_data
->file_names
[j
];
4893 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4898 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4900 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4903 this_real_name
= gdb_realpath (filename
);
4904 (*fun
) (filename
, this_real_name
.get (), data
);
4909 dw2_has_symbols (struct objfile
*objfile
)
4914 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4917 dw2_find_last_source_symtab
,
4918 dw2_forget_cached_source_info
,
4919 dw2_map_symtabs_matching_filename
,
4924 dw2_expand_symtabs_for_function
,
4925 dw2_expand_all_symtabs
,
4926 dw2_expand_symtabs_with_fullname
,
4927 dw2_map_matching_symbols
,
4928 dw2_expand_symtabs_matching
,
4929 dw2_find_pc_sect_compunit_symtab
,
4931 dw2_map_symbol_filenames
4934 /* DWARF-5 debug_names reader. */
4936 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4937 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4939 /* A helper function that reads the .debug_names section in SECTION
4940 and fills in MAP. FILENAME is the name of the file containing the
4941 section; it is used for error reporting.
4943 Returns true if all went well, false otherwise. */
4946 read_debug_names_from_section (struct objfile
*objfile
,
4947 const char *filename
,
4948 struct dwarf2_section_info
*section
,
4949 mapped_debug_names
&map
)
4951 if (section
->empty ())
4954 /* Older elfutils strip versions could keep the section in the main
4955 executable while splitting it for the separate debug info file. */
4956 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4959 section
->read (objfile
);
4961 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4963 const gdb_byte
*addr
= section
->buffer
;
4965 bfd
*const abfd
= section
->get_bfd_owner ();
4967 unsigned int bytes_read
;
4968 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4971 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4972 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4973 if (bytes_read
+ length
!= section
->size
)
4975 /* There may be multiple per-CU indices. */
4976 warning (_("Section .debug_names in %s length %s does not match "
4977 "section length %s, ignoring .debug_names."),
4978 filename
, plongest (bytes_read
+ length
),
4979 pulongest (section
->size
));
4983 /* The version number. */
4984 uint16_t version
= read_2_bytes (abfd
, addr
);
4988 warning (_("Section .debug_names in %s has unsupported version %d, "
4989 "ignoring .debug_names."),
4995 uint16_t padding
= read_2_bytes (abfd
, addr
);
4999 warning (_("Section .debug_names in %s has unsupported padding %d, "
5000 "ignoring .debug_names."),
5005 /* comp_unit_count - The number of CUs in the CU list. */
5006 map
.cu_count
= read_4_bytes (abfd
, addr
);
5009 /* local_type_unit_count - The number of TUs in the local TU
5011 map
.tu_count
= read_4_bytes (abfd
, addr
);
5014 /* foreign_type_unit_count - The number of TUs in the foreign TU
5016 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5018 if (foreign_tu_count
!= 0)
5020 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5021 "ignoring .debug_names."),
5022 filename
, static_cast<unsigned long> (foreign_tu_count
));
5026 /* bucket_count - The number of hash buckets in the hash lookup
5028 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5031 /* name_count - The number of unique names in the index. */
5032 map
.name_count
= read_4_bytes (abfd
, addr
);
5035 /* abbrev_table_size - The size in bytes of the abbreviations
5037 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5040 /* augmentation_string_size - The size in bytes of the augmentation
5041 string. This value is rounded up to a multiple of 4. */
5042 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5044 map
.augmentation_is_gdb
= ((augmentation_string_size
5045 == sizeof (dwarf5_augmentation
))
5046 && memcmp (addr
, dwarf5_augmentation
,
5047 sizeof (dwarf5_augmentation
)) == 0);
5048 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5049 addr
+= augmentation_string_size
;
5052 map
.cu_table_reordered
= addr
;
5053 addr
+= map
.cu_count
* map
.offset_size
;
5055 /* List of Local TUs */
5056 map
.tu_table_reordered
= addr
;
5057 addr
+= map
.tu_count
* map
.offset_size
;
5059 /* Hash Lookup Table */
5060 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5061 addr
+= map
.bucket_count
* 4;
5062 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5063 addr
+= map
.name_count
* 4;
5066 map
.name_table_string_offs_reordered
= addr
;
5067 addr
+= map
.name_count
* map
.offset_size
;
5068 map
.name_table_entry_offs_reordered
= addr
;
5069 addr
+= map
.name_count
* map
.offset_size
;
5071 const gdb_byte
*abbrev_table_start
= addr
;
5074 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5079 const auto insertpair
5080 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5081 if (!insertpair
.second
)
5083 warning (_("Section .debug_names in %s has duplicate index %s, "
5084 "ignoring .debug_names."),
5085 filename
, pulongest (index_num
));
5088 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5089 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5094 mapped_debug_names::index_val::attr attr
;
5095 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5097 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5099 if (attr
.form
== DW_FORM_implicit_const
)
5101 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5105 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5107 indexval
.attr_vec
.push_back (std::move (attr
));
5110 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5112 warning (_("Section .debug_names in %s has abbreviation_table "
5113 "of size %s vs. written as %u, ignoring .debug_names."),
5114 filename
, plongest (addr
- abbrev_table_start
),
5118 map
.entry_pool
= addr
;
5123 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5127 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5128 const mapped_debug_names
&map
,
5129 dwarf2_section_info
§ion
,
5132 if (!map
.augmentation_is_gdb
)
5134 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5136 sect_offset sect_off
5137 = (sect_offset
) (extract_unsigned_integer
5138 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5140 map
.dwarf5_byte_order
));
5141 /* We don't know the length of the CU, because the CU list in a
5142 .debug_names index can be incomplete, so we can't use the start of
5143 the next CU as end of this CU. We create the CUs here with length 0,
5144 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5145 dwarf2_per_cu_data
*per_cu
5146 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5147 per_bfd
->all_comp_units
.push_back (per_cu
);
5151 sect_offset sect_off_prev
;
5152 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5154 sect_offset sect_off_next
;
5155 if (i
< map
.cu_count
)
5158 = (sect_offset
) (extract_unsigned_integer
5159 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5161 map
.dwarf5_byte_order
));
5164 sect_off_next
= (sect_offset
) section
.size
;
5167 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5168 dwarf2_per_cu_data
*per_cu
5169 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5170 sect_off_prev
, length
);
5171 per_bfd
->all_comp_units
.push_back (per_cu
);
5173 sect_off_prev
= sect_off_next
;
5177 /* Read the CU list from the mapped index, and use it to create all
5178 the CU objects for this dwarf2_per_objfile. */
5181 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5182 const mapped_debug_names
&map
,
5183 const mapped_debug_names
&dwz_map
)
5185 gdb_assert (per_bfd
->all_comp_units
.empty ());
5186 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5188 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5189 false /* is_dwz */);
5191 if (dwz_map
.cu_count
== 0)
5194 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5195 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5199 /* Read .debug_names. If everything went ok, initialize the "quick"
5200 elements of all the CUs and return true. Otherwise, return false. */
5203 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5205 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5206 mapped_debug_names dwz_map
;
5207 struct objfile
*objfile
= per_objfile
->objfile
;
5209 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5210 &per_objfile
->per_bfd
->debug_names
, *map
))
5213 /* Don't use the index if it's empty. */
5214 if (map
->name_count
== 0)
5217 /* If there is a .dwz file, read it so we can get its CU list as
5219 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
5222 if (!read_debug_names_from_section (objfile
,
5223 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5224 &dwz
->debug_names
, dwz_map
))
5226 warning (_("could not read '.debug_names' section from %s; skipping"),
5227 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5232 create_cus_from_debug_names (per_objfile
->per_bfd
, *map
, dwz_map
);
5234 if (map
->tu_count
!= 0)
5236 /* We can only handle a single .debug_types when we have an
5238 if (per_objfile
->per_bfd
->types
.size () != 1)
5241 dwarf2_section_info
*section
= &per_objfile
->per_bfd
->types
[0];
5243 create_signatured_type_table_from_debug_names
5244 (per_objfile
, *map
, section
, &per_objfile
->per_bfd
->abbrev
);
5247 create_addrmap_from_aranges (per_objfile
,
5248 &per_objfile
->per_bfd
->debug_aranges
);
5250 per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5251 per_objfile
->per_bfd
->using_index
= 1;
5252 per_objfile
->per_bfd
->quick_file_names_table
=
5253 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5258 /* Type used to manage iterating over all CUs looking for a symbol for
5261 class dw2_debug_names_iterator
5264 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5265 gdb::optional
<block_enum
> block_index
,
5267 const char *name
, dwarf2_per_objfile
*per_objfile
)
5268 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5269 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5270 m_per_objfile (per_objfile
)
5273 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5274 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5277 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5278 m_per_objfile (per_objfile
)
5281 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5282 block_enum block_index
, domain_enum domain
,
5283 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5284 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5285 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5286 m_per_objfile (per_objfile
)
5289 /* Return the next matching CU or NULL if there are no more. */
5290 dwarf2_per_cu_data
*next ();
5293 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5295 dwarf2_per_objfile
*per_objfile
);
5296 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5298 dwarf2_per_objfile
*per_objfile
);
5300 /* The internalized form of .debug_names. */
5301 const mapped_debug_names
&m_map
;
5303 /* If set, only look for symbols that match that block. Valid values are
5304 GLOBAL_BLOCK and STATIC_BLOCK. */
5305 const gdb::optional
<block_enum
> m_block_index
;
5307 /* The kind of symbol we're looking for. */
5308 const domain_enum m_domain
= UNDEF_DOMAIN
;
5309 const search_domain m_search
= ALL_DOMAIN
;
5311 /* The list of CUs from the index entry of the symbol, or NULL if
5313 const gdb_byte
*m_addr
;
5315 dwarf2_per_objfile
*m_per_objfile
;
5319 mapped_debug_names::namei_to_name
5320 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5322 const ULONGEST namei_string_offs
5323 = extract_unsigned_integer ((name_table_string_offs_reordered
5324 + namei
* offset_size
),
5327 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5330 /* Find a slot in .debug_names for the object named NAME. If NAME is
5331 found, return pointer to its pool data. If NAME cannot be found,
5335 dw2_debug_names_iterator::find_vec_in_debug_names
5336 (const mapped_debug_names
&map
, const char *name
,
5337 dwarf2_per_objfile
*per_objfile
)
5339 int (*cmp
) (const char *, const char *);
5341 gdb::unique_xmalloc_ptr
<char> without_params
;
5342 if (current_language
->la_language
== language_cplus
5343 || current_language
->la_language
== language_fortran
5344 || current_language
->la_language
== language_d
)
5346 /* NAME is already canonical. Drop any qualifiers as
5347 .debug_names does not contain any. */
5349 if (strchr (name
, '(') != NULL
)
5351 without_params
= cp_remove_params (name
);
5352 if (without_params
!= NULL
)
5353 name
= without_params
.get ();
5357 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5359 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5361 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5362 (map
.bucket_table_reordered
5363 + (full_hash
% map
.bucket_count
)), 4,
5364 map
.dwarf5_byte_order
);
5368 if (namei
>= map
.name_count
)
5370 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5372 namei
, map
.name_count
,
5373 objfile_name (per_objfile
->objfile
));
5379 const uint32_t namei_full_hash
5380 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5381 (map
.hash_table_reordered
+ namei
), 4,
5382 map
.dwarf5_byte_order
);
5383 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5386 if (full_hash
== namei_full_hash
)
5388 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5390 #if 0 /* An expensive sanity check. */
5391 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5393 complaint (_("Wrong .debug_names hash for string at index %u "
5395 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5400 if (cmp (namei_string
, name
) == 0)
5402 const ULONGEST namei_entry_offs
5403 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5404 + namei
* map
.offset_size
),
5405 map
.offset_size
, map
.dwarf5_byte_order
);
5406 return map
.entry_pool
+ namei_entry_offs
;
5411 if (namei
>= map
.name_count
)
5417 dw2_debug_names_iterator::find_vec_in_debug_names
5418 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5420 if (namei
>= map
.name_count
)
5422 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5424 namei
, map
.name_count
,
5425 objfile_name (per_objfile
->objfile
));
5429 const ULONGEST namei_entry_offs
5430 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5431 + namei
* map
.offset_size
),
5432 map
.offset_size
, map
.dwarf5_byte_order
);
5433 return map
.entry_pool
+ namei_entry_offs
;
5436 /* See dw2_debug_names_iterator. */
5438 dwarf2_per_cu_data
*
5439 dw2_debug_names_iterator::next ()
5444 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5445 struct objfile
*objfile
= m_per_objfile
->objfile
;
5446 bfd
*const abfd
= objfile
->obfd
;
5450 unsigned int bytes_read
;
5451 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5452 m_addr
+= bytes_read
;
5456 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5457 if (indexval_it
== m_map
.abbrev_map
.cend ())
5459 complaint (_("Wrong .debug_names undefined abbrev code %s "
5461 pulongest (abbrev
), objfile_name (objfile
));
5464 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5465 enum class symbol_linkage
{
5469 } symbol_linkage_
= symbol_linkage::unknown
;
5470 dwarf2_per_cu_data
*per_cu
= NULL
;
5471 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5476 case DW_FORM_implicit_const
:
5477 ull
= attr
.implicit_const
;
5479 case DW_FORM_flag_present
:
5483 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5484 m_addr
+= bytes_read
;
5487 ull
= read_4_bytes (abfd
, m_addr
);
5491 ull
= read_8_bytes (abfd
, m_addr
);
5494 case DW_FORM_ref_sig8
:
5495 ull
= read_8_bytes (abfd
, m_addr
);
5499 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5500 dwarf_form_name (attr
.form
),
5501 objfile_name (objfile
));
5504 switch (attr
.dw_idx
)
5506 case DW_IDX_compile_unit
:
5507 /* Don't crash on bad data. */
5508 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5510 complaint (_(".debug_names entry has bad CU index %s"
5513 objfile_name (objfile
));
5516 per_cu
= per_bfd
->get_cutu (ull
);
5518 case DW_IDX_type_unit
:
5519 /* Don't crash on bad data. */
5520 if (ull
>= per_bfd
->all_type_units
.size ())
5522 complaint (_(".debug_names entry has bad TU index %s"
5525 objfile_name (objfile
));
5528 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5530 case DW_IDX_die_offset
:
5531 /* In a per-CU index (as opposed to a per-module index), index
5532 entries without CU attribute implicitly refer to the single CU. */
5534 per_cu
= per_bfd
->get_cu (0);
5536 case DW_IDX_GNU_internal
:
5537 if (!m_map
.augmentation_is_gdb
)
5539 symbol_linkage_
= symbol_linkage::static_
;
5541 case DW_IDX_GNU_external
:
5542 if (!m_map
.augmentation_is_gdb
)
5544 symbol_linkage_
= symbol_linkage::extern_
;
5549 /* Skip if already read in. */
5550 if (m_per_objfile
->symtab_set_p (per_cu
))
5553 /* Check static vs global. */
5554 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5556 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5557 const bool symbol_is_static
=
5558 symbol_linkage_
== symbol_linkage::static_
;
5559 if (want_static
!= symbol_is_static
)
5563 /* Match dw2_symtab_iter_next, symbol_kind
5564 and debug_names::psymbol_tag. */
5568 switch (indexval
.dwarf_tag
)
5570 case DW_TAG_variable
:
5571 case DW_TAG_subprogram
:
5572 /* Some types are also in VAR_DOMAIN. */
5573 case DW_TAG_typedef
:
5574 case DW_TAG_structure_type
:
5581 switch (indexval
.dwarf_tag
)
5583 case DW_TAG_typedef
:
5584 case DW_TAG_structure_type
:
5591 switch (indexval
.dwarf_tag
)
5594 case DW_TAG_variable
:
5601 switch (indexval
.dwarf_tag
)
5613 /* Match dw2_expand_symtabs_matching, symbol_kind and
5614 debug_names::psymbol_tag. */
5617 case VARIABLES_DOMAIN
:
5618 switch (indexval
.dwarf_tag
)
5620 case DW_TAG_variable
:
5626 case FUNCTIONS_DOMAIN
:
5627 switch (indexval
.dwarf_tag
)
5629 case DW_TAG_subprogram
:
5636 switch (indexval
.dwarf_tag
)
5638 case DW_TAG_typedef
:
5639 case DW_TAG_structure_type
:
5645 case MODULES_DOMAIN
:
5646 switch (indexval
.dwarf_tag
)
5660 static struct compunit_symtab
*
5661 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5662 const char *name
, domain_enum domain
)
5664 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5666 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5669 /* index is NULL if OBJF_READNOW. */
5672 const auto &map
= *mapp
;
5674 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5676 struct compunit_symtab
*stab_best
= NULL
;
5677 struct dwarf2_per_cu_data
*per_cu
;
5678 while ((per_cu
= iter
.next ()) != NULL
)
5680 struct symbol
*sym
, *with_opaque
= NULL
;
5681 compunit_symtab
*stab
5682 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5683 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5684 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5686 sym
= block_find_symbol (block
, name
, domain
,
5687 block_find_non_opaque_type_preferred
,
5690 /* Some caution must be observed with overloaded functions and
5691 methods, since the index will not contain any overload
5692 information (but NAME might contain it). */
5695 && strcmp_iw (sym
->search_name (), name
) == 0)
5697 if (with_opaque
!= NULL
5698 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5701 /* Keep looking through other CUs. */
5707 /* This dumps minimal information about .debug_names. It is called
5708 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5709 uses this to verify that .debug_names has been loaded. */
5712 dw2_debug_names_dump (struct objfile
*objfile
)
5714 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5716 gdb_assert (per_objfile
->per_bfd
->using_index
);
5717 printf_filtered (".debug_names:");
5718 if (per_objfile
->per_bfd
->debug_names_table
)
5719 printf_filtered (" exists\n");
5721 printf_filtered (" faked for \"readnow\"\n");
5722 printf_filtered ("\n");
5726 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5727 const char *func_name
)
5729 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5731 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5732 if (per_objfile
->per_bfd
->debug_names_table
)
5734 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5736 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5739 struct dwarf2_per_cu_data
*per_cu
;
5740 while ((per_cu
= iter
.next ()) != NULL
)
5741 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5746 dw2_debug_names_map_matching_symbols
5747 (struct objfile
*objfile
,
5748 const lookup_name_info
&name
, domain_enum domain
,
5750 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5751 symbol_compare_ftype
*ordered_compare
)
5753 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5755 /* debug_names_table is NULL if OBJF_READNOW. */
5756 if (!per_objfile
->per_bfd
->debug_names_table
)
5759 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5760 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5762 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5763 auto matcher
= [&] (const char *symname
)
5765 if (ordered_compare
== nullptr)
5767 return ordered_compare (symname
, match_name
) == 0;
5770 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5771 [&] (offset_type namei
)
5773 /* The name was matched, now expand corresponding CUs that were
5775 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5778 struct dwarf2_per_cu_data
*per_cu
;
5779 while ((per_cu
= iter
.next ()) != NULL
)
5780 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5785 /* It's a shame we couldn't do this inside the
5786 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5787 that have already been expanded. Instead, this loop matches what
5788 the psymtab code does. */
5789 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5791 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5792 if (symtab
!= nullptr)
5794 const struct block
*block
5795 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5796 if (!iterate_over_symbols_terminated (block
, name
,
5804 dw2_debug_names_expand_symtabs_matching
5805 (struct objfile
*objfile
,
5806 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5807 const lookup_name_info
*lookup_name
,
5808 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5809 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5810 enum search_domain kind
)
5812 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5814 /* debug_names_table is NULL if OBJF_READNOW. */
5815 if (!per_objfile
->per_bfd
->debug_names_table
)
5818 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5820 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5822 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5826 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5832 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5834 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5836 kind
, [&] (offset_type namei
)
5838 /* The name was matched, now expand corresponding CUs that were
5840 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5842 struct dwarf2_per_cu_data
*per_cu
;
5843 while ((per_cu
= iter
.next ()) != NULL
)
5844 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5850 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5853 dw2_find_last_source_symtab
,
5854 dw2_forget_cached_source_info
,
5855 dw2_map_symtabs_matching_filename
,
5856 dw2_debug_names_lookup_symbol
,
5859 dw2_debug_names_dump
,
5860 dw2_debug_names_expand_symtabs_for_function
,
5861 dw2_expand_all_symtabs
,
5862 dw2_expand_symtabs_with_fullname
,
5863 dw2_debug_names_map_matching_symbols
,
5864 dw2_debug_names_expand_symtabs_matching
,
5865 dw2_find_pc_sect_compunit_symtab
,
5867 dw2_map_symbol_filenames
5870 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5871 to either a dwarf2_per_bfd or dwz_file object. */
5873 template <typename T
>
5874 static gdb::array_view
<const gdb_byte
>
5875 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5877 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5879 if (section
->empty ())
5882 /* Older elfutils strip versions could keep the section in the main
5883 executable while splitting it for the separate debug info file. */
5884 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5887 section
->read (obj
);
5889 /* dwarf2_section_info::size is a bfd_size_type, while
5890 gdb::array_view works with size_t. On 32-bit hosts, with
5891 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5892 is 32-bit. So we need an explicit narrowing conversion here.
5893 This is fine, because it's impossible to allocate or mmap an
5894 array/buffer larger than what size_t can represent. */
5895 return gdb::make_array_view (section
->buffer
, section
->size
);
5898 /* Lookup the index cache for the contents of the index associated to
5901 static gdb::array_view
<const gdb_byte
>
5902 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5904 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5905 if (build_id
== nullptr)
5908 return global_index_cache
.lookup_gdb_index (build_id
,
5909 &dwarf2_per_bfd
->index_cache_res
);
5912 /* Same as the above, but for DWZ. */
5914 static gdb::array_view
<const gdb_byte
>
5915 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5917 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5918 if (build_id
== nullptr)
5921 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5924 /* See symfile.h. */
5927 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5929 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5930 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5932 /* If we're about to read full symbols, don't bother with the
5933 indices. In this case we also don't care if some other debug
5934 format is making psymtabs, because they are all about to be
5936 if ((objfile
->flags
& OBJF_READNOW
))
5938 /* When using READNOW, the using_index flag (set below) indicates that
5939 PER_BFD was already initialized, when we loaded some other objfile. */
5940 if (per_bfd
->using_index
)
5942 *index_kind
= dw_index_kind::GDB_INDEX
;
5943 per_objfile
->resize_symtabs ();
5947 per_bfd
->using_index
= 1;
5948 create_all_comp_units (per_objfile
);
5949 create_all_type_units (per_objfile
);
5950 per_bfd
->quick_file_names_table
5951 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5952 per_objfile
->resize_symtabs ();
5954 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
5955 + per_bfd
->all_type_units
.size ()); ++i
)
5957 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
5959 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5960 struct dwarf2_per_cu_quick_data
);
5963 /* Return 1 so that gdb sees the "quick" functions. However,
5964 these functions will be no-ops because we will have expanded
5966 *index_kind
= dw_index_kind::GDB_INDEX
;
5970 /* Was a debug names index already read when we processed an objfile sharing
5972 if (per_bfd
->debug_names_table
!= nullptr)
5974 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5975 per_objfile
->resize_symtabs ();
5979 /* Was a GDB index already read when we processed an objfile sharing
5981 if (per_bfd
->index_table
!= nullptr)
5983 *index_kind
= dw_index_kind::GDB_INDEX
;
5984 per_objfile
->resize_symtabs ();
5988 if (dwarf2_read_debug_names (per_objfile
))
5990 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5991 per_objfile
->resize_symtabs ();
5995 if (dwarf2_read_gdb_index (per_objfile
,
5996 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5997 get_gdb_index_contents_from_section
<dwz_file
>))
5999 *index_kind
= dw_index_kind::GDB_INDEX
;
6000 per_objfile
->resize_symtabs ();
6004 /* ... otherwise, try to find the index in the index cache. */
6005 if (dwarf2_read_gdb_index (per_objfile
,
6006 get_gdb_index_contents_from_cache
,
6007 get_gdb_index_contents_from_cache_dwz
))
6009 global_index_cache
.hit ();
6010 *index_kind
= dw_index_kind::GDB_INDEX
;
6011 per_objfile
->resize_symtabs ();
6015 global_index_cache
.miss ();
6021 /* Build a partial symbol table. */
6024 dwarf2_build_psymtabs (struct objfile
*objfile
)
6026 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6027 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6029 if (per_bfd
->partial_symtabs
!= nullptr)
6031 /* Partial symbols were already read, so now we can simply
6033 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6034 per_objfile
->resize_symtabs ();
6038 init_psymbol_list (objfile
, 1024);
6042 /* This isn't really ideal: all the data we allocate on the
6043 objfile's obstack is still uselessly kept around. However,
6044 freeing it seems unsafe. */
6045 psymtab_discarder
psymtabs (objfile
);
6046 dwarf2_build_psymtabs_hard (per_objfile
);
6049 per_objfile
->resize_symtabs ();
6051 /* (maybe) store an index in the cache. */
6052 global_index_cache
.store (per_objfile
);
6054 catch (const gdb_exception_error
&except
)
6056 exception_print (gdb_stderr
, except
);
6059 /* Finish by setting the local reference to partial symtabs, so that
6060 we don't try to read them again if reading another objfile with the same
6061 BFD. If we can't in fact share, this won't make a difference anyway as
6062 the dwarf2_per_bfd object won't be shared. */
6063 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6066 /* Find the base address of the compilation unit for range lists and
6067 location lists. It will normally be specified by DW_AT_low_pc.
6068 In DWARF-3 draft 4, the base address could be overridden by
6069 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6070 compilation units with discontinuous ranges. */
6073 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6075 struct attribute
*attr
;
6077 cu
->base_address
.reset ();
6079 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6080 if (attr
!= nullptr)
6081 cu
->base_address
= attr
->value_as_address ();
6084 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6085 if (attr
!= nullptr)
6086 cu
->base_address
= attr
->value_as_address ();
6090 /* Helper function that returns the proper abbrev section for
6093 static struct dwarf2_section_info
*
6094 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6096 struct dwarf2_section_info
*abbrev
;
6097 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6099 if (this_cu
->is_dwz
)
6100 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6102 abbrev
= &per_bfd
->abbrev
;
6107 /* Fetch the abbreviation table offset from a comp or type unit header. */
6110 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6111 struct dwarf2_section_info
*section
,
6112 sect_offset sect_off
)
6114 bfd
*abfd
= section
->get_bfd_owner ();
6115 const gdb_byte
*info_ptr
;
6116 unsigned int initial_length_size
, offset_size
;
6119 section
->read (per_objfile
->objfile
);
6120 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6121 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6122 offset_size
= initial_length_size
== 4 ? 4 : 8;
6123 info_ptr
+= initial_length_size
;
6125 version
= read_2_bytes (abfd
, info_ptr
);
6129 /* Skip unit type and address size. */
6133 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6136 /* A partial symtab that is used only for include files. */
6137 struct dwarf2_include_psymtab
: public partial_symtab
6139 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6140 : partial_symtab (filename
, objfile
)
6144 void read_symtab (struct objfile
*objfile
) override
6146 /* It's an include file, no symbols to read for it.
6147 Everything is in the includer symtab. */
6149 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6150 expansion of the includer psymtab. We use the dependencies[0] field to
6151 model the includer. But if we go the regular route of calling
6152 expand_psymtab here, and having expand_psymtab call expand_dependencies
6153 to expand the includer, we'll only use expand_psymtab on the includer
6154 (making it a non-toplevel psymtab), while if we expand the includer via
6155 another path, we'll use read_symtab (making it a toplevel psymtab).
6156 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6157 psymtab, and trigger read_symtab on the includer here directly. */
6158 includer ()->read_symtab (objfile
);
6161 void expand_psymtab (struct objfile
*objfile
) override
6163 /* This is not called by read_symtab, and should not be called by any
6164 expand_dependencies. */
6168 bool readin_p (struct objfile
*objfile
) const override
6170 return includer ()->readin_p (objfile
);
6173 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6179 partial_symtab
*includer () const
6181 /* An include psymtab has exactly one dependency: the psymtab that
6183 gdb_assert (this->number_of_dependencies
== 1);
6184 return this->dependencies
[0];
6188 /* Allocate a new partial symtab for file named NAME and mark this new
6189 partial symtab as being an include of PST. */
6192 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6193 struct objfile
*objfile
)
6195 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6197 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6198 subpst
->dirname
= pst
->dirname
;
6200 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6201 subpst
->dependencies
[0] = pst
;
6202 subpst
->number_of_dependencies
= 1;
6205 /* Read the Line Number Program data and extract the list of files
6206 included by the source file represented by PST. Build an include
6207 partial symtab for each of these included files. */
6210 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6211 struct die_info
*die
,
6212 dwarf2_psymtab
*pst
)
6215 struct attribute
*attr
;
6217 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6218 if (attr
!= nullptr)
6219 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6221 return; /* No linetable, so no includes. */
6223 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6224 that we pass in the raw text_low here; that is ok because we're
6225 only decoding the line table to make include partial symtabs, and
6226 so the addresses aren't really used. */
6227 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6228 pst
->raw_text_low (), 1);
6232 hash_signatured_type (const void *item
)
6234 const struct signatured_type
*sig_type
6235 = (const struct signatured_type
*) item
;
6237 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6238 return sig_type
->signature
;
6242 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6244 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6245 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6247 return lhs
->signature
== rhs
->signature
;
6250 /* Allocate a hash table for signatured types. */
6253 allocate_signatured_type_table ()
6255 return htab_up (htab_create_alloc (41,
6256 hash_signatured_type
,
6258 NULL
, xcalloc
, xfree
));
6261 /* A helper function to add a signatured type CU to a table. */
6264 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6266 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6267 std::vector
<signatured_type
*> *all_type_units
6268 = (std::vector
<signatured_type
*> *) datum
;
6270 all_type_units
->push_back (sigt
);
6275 /* A helper for create_debug_types_hash_table. Read types from SECTION
6276 and fill them into TYPES_HTAB. It will process only type units,
6277 therefore DW_UT_type. */
6280 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6281 struct dwo_file
*dwo_file
,
6282 dwarf2_section_info
*section
, htab_up
&types_htab
,
6283 rcuh_kind section_kind
)
6285 struct objfile
*objfile
= per_objfile
->objfile
;
6286 struct dwarf2_section_info
*abbrev_section
;
6288 const gdb_byte
*info_ptr
, *end_ptr
;
6290 abbrev_section
= (dwo_file
!= NULL
6291 ? &dwo_file
->sections
.abbrev
6292 : &per_objfile
->per_bfd
->abbrev
);
6294 if (dwarf_read_debug
)
6295 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6296 section
->get_name (),
6297 abbrev_section
->get_file_name ());
6299 section
->read (objfile
);
6300 info_ptr
= section
->buffer
;
6302 if (info_ptr
== NULL
)
6305 /* We can't set abfd until now because the section may be empty or
6306 not present, in which case the bfd is unknown. */
6307 abfd
= section
->get_bfd_owner ();
6309 /* We don't use cutu_reader here because we don't need to read
6310 any dies: the signature is in the header. */
6312 end_ptr
= info_ptr
+ section
->size
;
6313 while (info_ptr
< end_ptr
)
6315 struct signatured_type
*sig_type
;
6316 struct dwo_unit
*dwo_tu
;
6318 const gdb_byte
*ptr
= info_ptr
;
6319 struct comp_unit_head header
;
6320 unsigned int length
;
6322 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6324 /* Initialize it due to a false compiler warning. */
6325 header
.signature
= -1;
6326 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6328 /* We need to read the type's signature in order to build the hash
6329 table, but we don't need anything else just yet. */
6331 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6332 abbrev_section
, ptr
, section_kind
);
6334 length
= header
.get_length ();
6336 /* Skip dummy type units. */
6337 if (ptr
>= info_ptr
+ length
6338 || peek_abbrev_code (abfd
, ptr
) == 0
6339 || header
.unit_type
!= DW_UT_type
)
6345 if (types_htab
== NULL
)
6348 types_htab
= allocate_dwo_unit_table ();
6350 types_htab
= allocate_signatured_type_table ();
6356 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6357 dwo_tu
->dwo_file
= dwo_file
;
6358 dwo_tu
->signature
= header
.signature
;
6359 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6360 dwo_tu
->section
= section
;
6361 dwo_tu
->sect_off
= sect_off
;
6362 dwo_tu
->length
= length
;
6366 /* N.B.: type_offset is not usable if this type uses a DWO file.
6367 The real type_offset is in the DWO file. */
6369 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6370 sig_type
->signature
= header
.signature
;
6371 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6372 sig_type
->per_cu
.is_debug_types
= 1;
6373 sig_type
->per_cu
.section
= section
;
6374 sig_type
->per_cu
.sect_off
= sect_off
;
6375 sig_type
->per_cu
.length
= length
;
6378 slot
= htab_find_slot (types_htab
.get (),
6379 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6381 gdb_assert (slot
!= NULL
);
6384 sect_offset dup_sect_off
;
6388 const struct dwo_unit
*dup_tu
6389 = (const struct dwo_unit
*) *slot
;
6391 dup_sect_off
= dup_tu
->sect_off
;
6395 const struct signatured_type
*dup_tu
6396 = (const struct signatured_type
*) *slot
;
6398 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6401 complaint (_("debug type entry at offset %s is duplicate to"
6402 " the entry at offset %s, signature %s"),
6403 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6404 hex_string (header
.signature
));
6406 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6408 if (dwarf_read_debug
> 1)
6409 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6410 sect_offset_str (sect_off
),
6411 hex_string (header
.signature
));
6417 /* Create the hash table of all entries in the .debug_types
6418 (or .debug_types.dwo) section(s).
6419 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6420 otherwise it is NULL.
6422 The result is a pointer to the hash table or NULL if there are no types.
6424 Note: This function processes DWO files only, not DWP files. */
6427 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6428 struct dwo_file
*dwo_file
,
6429 gdb::array_view
<dwarf2_section_info
> type_sections
,
6430 htab_up
&types_htab
)
6432 for (dwarf2_section_info
§ion
: type_sections
)
6433 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6437 /* Create the hash table of all entries in the .debug_types section,
6438 and initialize all_type_units.
6439 The result is zero if there is an error (e.g. missing .debug_types section),
6440 otherwise non-zero. */
6443 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6447 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6448 types_htab
, rcuh_kind::COMPILE
);
6449 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6451 if (types_htab
== NULL
)
6453 per_objfile
->per_bfd
->signatured_types
= NULL
;
6457 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6459 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6460 per_objfile
->per_bfd
->all_type_units
.reserve
6461 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6463 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6464 add_signatured_type_cu_to_table
,
6465 &per_objfile
->per_bfd
->all_type_units
);
6470 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6471 If SLOT is non-NULL, it is the entry to use in the hash table.
6472 Otherwise we find one. */
6474 static struct signatured_type
*
6475 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6477 if (per_objfile
->per_bfd
->all_type_units
.size ()
6478 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6479 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6481 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6483 per_objfile
->resize_symtabs ();
6485 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6486 sig_type
->signature
= sig
;
6487 sig_type
->per_cu
.is_debug_types
= 1;
6488 if (per_objfile
->per_bfd
->using_index
)
6490 sig_type
->per_cu
.v
.quick
=
6491 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6492 struct dwarf2_per_cu_quick_data
);
6497 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6500 gdb_assert (*slot
== NULL
);
6502 /* The rest of sig_type must be filled in by the caller. */
6506 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6507 Fill in SIG_ENTRY with DWO_ENTRY. */
6510 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6511 struct signatured_type
*sig_entry
,
6512 struct dwo_unit
*dwo_entry
)
6514 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6516 /* Make sure we're not clobbering something we don't expect to. */
6517 gdb_assert (! sig_entry
->per_cu
.queued
);
6518 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6519 if (per_bfd
->using_index
)
6521 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6522 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6525 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6526 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6527 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6528 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6529 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6531 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6532 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6533 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6534 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6535 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6536 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6537 sig_entry
->dwo_unit
= dwo_entry
;
6540 /* Subroutine of lookup_signatured_type.
6541 If we haven't read the TU yet, create the signatured_type data structure
6542 for a TU to be read in directly from a DWO file, bypassing the stub.
6543 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6544 using .gdb_index, then when reading a CU we want to stay in the DWO file
6545 containing that CU. Otherwise we could end up reading several other DWO
6546 files (due to comdat folding) to process the transitive closure of all the
6547 mentioned TUs, and that can be slow. The current DWO file will have every
6548 type signature that it needs.
6549 We only do this for .gdb_index because in the psymtab case we already have
6550 to read all the DWOs to build the type unit groups. */
6552 static struct signatured_type
*
6553 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6555 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6556 struct dwo_file
*dwo_file
;
6557 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6558 struct signatured_type find_sig_entry
, *sig_entry
;
6561 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6563 /* If TU skeletons have been removed then we may not have read in any
6565 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6566 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6568 /* We only ever need to read in one copy of a signatured type.
6569 Use the global signatured_types array to do our own comdat-folding
6570 of types. If this is the first time we're reading this TU, and
6571 the TU has an entry in .gdb_index, replace the recorded data from
6572 .gdb_index with this TU. */
6574 find_sig_entry
.signature
= sig
;
6575 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6576 &find_sig_entry
, INSERT
);
6577 sig_entry
= (struct signatured_type
*) *slot
;
6579 /* We can get here with the TU already read, *or* in the process of being
6580 read. Don't reassign the global entry to point to this DWO if that's
6581 the case. Also note that if the TU is already being read, it may not
6582 have come from a DWO, the program may be a mix of Fission-compiled
6583 code and non-Fission-compiled code. */
6585 /* Have we already tried to read this TU?
6586 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6587 needn't exist in the global table yet). */
6588 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6591 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6592 dwo_unit of the TU itself. */
6593 dwo_file
= cu
->dwo_unit
->dwo_file
;
6595 /* Ok, this is the first time we're reading this TU. */
6596 if (dwo_file
->tus
== NULL
)
6598 find_dwo_entry
.signature
= sig
;
6599 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6601 if (dwo_entry
== NULL
)
6604 /* If the global table doesn't have an entry for this TU, add one. */
6605 if (sig_entry
== NULL
)
6606 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6608 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6609 sig_entry
->per_cu
.tu_read
= 1;
6613 /* Subroutine of lookup_signatured_type.
6614 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6615 then try the DWP file. If the TU stub (skeleton) has been removed then
6616 it won't be in .gdb_index. */
6618 static struct signatured_type
*
6619 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6621 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6622 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6623 struct dwo_unit
*dwo_entry
;
6624 struct signatured_type find_sig_entry
, *sig_entry
;
6627 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6628 gdb_assert (dwp_file
!= NULL
);
6630 /* If TU skeletons have been removed then we may not have read in any
6632 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6633 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6635 find_sig_entry
.signature
= sig
;
6636 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6637 &find_sig_entry
, INSERT
);
6638 sig_entry
= (struct signatured_type
*) *slot
;
6640 /* Have we already tried to read this TU?
6641 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6642 needn't exist in the global table yet). */
6643 if (sig_entry
!= NULL
)
6646 if (dwp_file
->tus
== NULL
)
6648 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6649 1 /* is_debug_types */);
6650 if (dwo_entry
== NULL
)
6653 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6654 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6659 /* Lookup a signature based type for DW_FORM_ref_sig8.
6660 Returns NULL if signature SIG is not present in the table.
6661 It is up to the caller to complain about this. */
6663 static struct signatured_type
*
6664 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6666 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6668 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6670 /* We're in a DWO/DWP file, and we're using .gdb_index.
6671 These cases require special processing. */
6672 if (get_dwp_file (per_objfile
) == NULL
)
6673 return lookup_dwo_signatured_type (cu
, sig
);
6675 return lookup_dwp_signatured_type (cu
, sig
);
6679 struct signatured_type find_entry
, *entry
;
6681 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6683 find_entry
.signature
= sig
;
6684 entry
= ((struct signatured_type
*)
6685 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6691 /* Low level DIE reading support. */
6693 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6696 init_cu_die_reader (struct die_reader_specs
*reader
,
6697 struct dwarf2_cu
*cu
,
6698 struct dwarf2_section_info
*section
,
6699 struct dwo_file
*dwo_file
,
6700 struct abbrev_table
*abbrev_table
)
6702 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6703 reader
->abfd
= section
->get_bfd_owner ();
6705 reader
->dwo_file
= dwo_file
;
6706 reader
->die_section
= section
;
6707 reader
->buffer
= section
->buffer
;
6708 reader
->buffer_end
= section
->buffer
+ section
->size
;
6709 reader
->abbrev_table
= abbrev_table
;
6712 /* Subroutine of cutu_reader to simplify it.
6713 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6714 There's just a lot of work to do, and cutu_reader is big enough
6717 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6718 from it to the DIE in the DWO. If NULL we are skipping the stub.
6719 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6720 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6721 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6722 STUB_COMP_DIR may be non-NULL.
6723 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6724 are filled in with the info of the DIE from the DWO file.
6725 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6726 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6727 kept around for at least as long as *RESULT_READER.
6729 The result is non-zero if a valid (non-dummy) DIE was found. */
6732 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6733 struct dwo_unit
*dwo_unit
,
6734 struct die_info
*stub_comp_unit_die
,
6735 const char *stub_comp_dir
,
6736 struct die_reader_specs
*result_reader
,
6737 const gdb_byte
**result_info_ptr
,
6738 struct die_info
**result_comp_unit_die
,
6739 abbrev_table_up
*result_dwo_abbrev_table
)
6741 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6742 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6743 struct objfile
*objfile
= per_objfile
->objfile
;
6745 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6746 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6747 int i
,num_extra_attrs
;
6748 struct dwarf2_section_info
*dwo_abbrev_section
;
6749 struct die_info
*comp_unit_die
;
6751 /* At most one of these may be provided. */
6752 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6754 /* These attributes aren't processed until later:
6755 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6756 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6757 referenced later. However, these attributes are found in the stub
6758 which we won't have later. In order to not impose this complication
6759 on the rest of the code, we read them here and copy them to the
6768 if (stub_comp_unit_die
!= NULL
)
6770 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6772 if (!per_cu
->is_debug_types
)
6773 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6774 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6775 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6776 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6777 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6779 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6781 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6782 here (if needed). We need the value before we can process
6784 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6786 else if (stub_comp_dir
!= NULL
)
6788 /* Reconstruct the comp_dir attribute to simplify the code below. */
6789 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6790 comp_dir
->name
= DW_AT_comp_dir
;
6791 comp_dir
->form
= DW_FORM_string
;
6792 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6793 DW_STRING (comp_dir
) = stub_comp_dir
;
6796 /* Set up for reading the DWO CU/TU. */
6797 cu
->dwo_unit
= dwo_unit
;
6798 dwarf2_section_info
*section
= dwo_unit
->section
;
6799 section
->read (objfile
);
6800 abfd
= section
->get_bfd_owner ();
6801 begin_info_ptr
= info_ptr
= (section
->buffer
6802 + to_underlying (dwo_unit
->sect_off
));
6803 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6805 if (per_cu
->is_debug_types
)
6807 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6809 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6810 section
, dwo_abbrev_section
,
6811 info_ptr
, rcuh_kind::TYPE
);
6812 /* This is not an assert because it can be caused by bad debug info. */
6813 if (sig_type
->signature
!= cu
->header
.signature
)
6815 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6816 " TU at offset %s [in module %s]"),
6817 hex_string (sig_type
->signature
),
6818 hex_string (cu
->header
.signature
),
6819 sect_offset_str (dwo_unit
->sect_off
),
6820 bfd_get_filename (abfd
));
6822 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6823 /* For DWOs coming from DWP files, we don't know the CU length
6824 nor the type's offset in the TU until now. */
6825 dwo_unit
->length
= cu
->header
.get_length ();
6826 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6828 /* Establish the type offset that can be used to lookup the type.
6829 For DWO files, we don't know it until now. */
6830 sig_type
->type_offset_in_section
6831 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6835 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6836 section
, dwo_abbrev_section
,
6837 info_ptr
, rcuh_kind::COMPILE
);
6838 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6839 /* For DWOs coming from DWP files, we don't know the CU length
6841 dwo_unit
->length
= cu
->header
.get_length ();
6844 *result_dwo_abbrev_table
6845 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6846 cu
->header
.abbrev_sect_off
);
6847 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6848 result_dwo_abbrev_table
->get ());
6850 /* Read in the die, but leave space to copy over the attributes
6851 from the stub. This has the benefit of simplifying the rest of
6852 the code - all the work to maintain the illusion of a single
6853 DW_TAG_{compile,type}_unit DIE is done here. */
6854 num_extra_attrs
= ((stmt_list
!= NULL
)
6858 + (comp_dir
!= NULL
));
6859 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6862 /* Copy over the attributes from the stub to the DIE we just read in. */
6863 comp_unit_die
= *result_comp_unit_die
;
6864 i
= comp_unit_die
->num_attrs
;
6865 if (stmt_list
!= NULL
)
6866 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6868 comp_unit_die
->attrs
[i
++] = *low_pc
;
6869 if (high_pc
!= NULL
)
6870 comp_unit_die
->attrs
[i
++] = *high_pc
;
6872 comp_unit_die
->attrs
[i
++] = *ranges
;
6873 if (comp_dir
!= NULL
)
6874 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6875 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6877 if (dwarf_die_debug
)
6879 fprintf_unfiltered (gdb_stdlog
,
6880 "Read die from %s@0x%x of %s:\n",
6881 section
->get_name (),
6882 (unsigned) (begin_info_ptr
- section
->buffer
),
6883 bfd_get_filename (abfd
));
6884 dump_die (comp_unit_die
, dwarf_die_debug
);
6887 /* Skip dummy compilation units. */
6888 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6889 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6892 *result_info_ptr
= info_ptr
;
6896 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6897 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6898 signature is part of the header. */
6899 static gdb::optional
<ULONGEST
>
6900 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6902 if (cu
->header
.version
>= 5)
6903 return cu
->header
.signature
;
6904 struct attribute
*attr
;
6905 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6906 if (attr
== nullptr)
6907 return gdb::optional
<ULONGEST
> ();
6908 return DW_UNSND (attr
);
6911 /* Subroutine of cutu_reader to simplify it.
6912 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6913 Returns NULL if the specified DWO unit cannot be found. */
6915 static struct dwo_unit
*
6916 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6918 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6919 struct dwo_unit
*dwo_unit
;
6920 const char *comp_dir
;
6922 gdb_assert (cu
!= NULL
);
6924 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6925 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6926 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6928 if (per_cu
->is_debug_types
)
6929 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6932 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6934 if (!signature
.has_value ())
6935 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6937 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6939 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6945 /* Subroutine of cutu_reader to simplify it.
6946 See it for a description of the parameters.
6947 Read a TU directly from a DWO file, bypassing the stub. */
6950 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6951 dwarf2_per_objfile
*per_objfile
,
6952 dwarf2_cu
*existing_cu
)
6954 struct signatured_type
*sig_type
;
6956 /* Verify we can do the following downcast, and that we have the
6958 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6959 sig_type
= (struct signatured_type
*) this_cu
;
6960 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6964 if (existing_cu
!= nullptr)
6967 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6968 /* There's no need to do the rereading_dwo_cu handling that
6969 cutu_reader does since we don't read the stub. */
6973 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6974 in per_objfile yet. */
6975 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6976 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6977 cu
= m_new_cu
.get ();
6980 /* A future optimization, if needed, would be to use an existing
6981 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6982 could share abbrev tables. */
6984 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6985 NULL
/* stub_comp_unit_die */,
6986 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6989 &m_dwo_abbrev_table
) == 0)
6996 /* Initialize a CU (or TU) and read its DIEs.
6997 If the CU defers to a DWO file, read the DWO file as well.
6999 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7000 Otherwise the table specified in the comp unit header is read in and used.
7001 This is an optimization for when we already have the abbrev table.
7003 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7006 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7007 dwarf2_per_objfile
*per_objfile
,
7008 struct abbrev_table
*abbrev_table
,
7009 dwarf2_cu
*existing_cu
,
7011 : die_reader_specs
{},
7014 struct objfile
*objfile
= per_objfile
->objfile
;
7015 struct dwarf2_section_info
*section
= this_cu
->section
;
7016 bfd
*abfd
= section
->get_bfd_owner ();
7017 const gdb_byte
*begin_info_ptr
;
7018 struct signatured_type
*sig_type
= NULL
;
7019 struct dwarf2_section_info
*abbrev_section
;
7020 /* Non-zero if CU currently points to a DWO file and we need to
7021 reread it. When this happens we need to reread the skeleton die
7022 before we can reread the DWO file (this only applies to CUs, not TUs). */
7023 int rereading_dwo_cu
= 0;
7025 if (dwarf_die_debug
)
7026 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7027 this_cu
->is_debug_types
? "type" : "comp",
7028 sect_offset_str (this_cu
->sect_off
));
7030 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7031 file (instead of going through the stub), short-circuit all of this. */
7032 if (this_cu
->reading_dwo_directly
)
7034 /* Narrow down the scope of possibilities to have to understand. */
7035 gdb_assert (this_cu
->is_debug_types
);
7036 gdb_assert (abbrev_table
== NULL
);
7037 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7041 /* This is cheap if the section is already read in. */
7042 section
->read (objfile
);
7044 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7046 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7050 if (existing_cu
!= nullptr)
7053 /* If this CU is from a DWO file we need to start over, we need to
7054 refetch the attributes from the skeleton CU.
7055 This could be optimized by retrieving those attributes from when we
7056 were here the first time: the previous comp_unit_die was stored in
7057 comp_unit_obstack. But there's no data yet that we need this
7059 if (cu
->dwo_unit
!= NULL
)
7060 rereading_dwo_cu
= 1;
7064 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7065 in per_objfile yet. */
7066 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7067 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7068 cu
= m_new_cu
.get ();
7071 /* Get the header. */
7072 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7074 /* We already have the header, there's no need to read it in again. */
7075 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7079 if (this_cu
->is_debug_types
)
7081 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7082 section
, abbrev_section
,
7083 info_ptr
, rcuh_kind::TYPE
);
7085 /* Since per_cu is the first member of struct signatured_type,
7086 we can go from a pointer to one to a pointer to the other. */
7087 sig_type
= (struct signatured_type
*) this_cu
;
7088 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7089 gdb_assert (sig_type
->type_offset_in_tu
7090 == cu
->header
.type_cu_offset_in_tu
);
7091 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7093 /* LENGTH has not been set yet for type units if we're
7094 using .gdb_index. */
7095 this_cu
->length
= cu
->header
.get_length ();
7097 /* Establish the type offset that can be used to lookup the type. */
7098 sig_type
->type_offset_in_section
=
7099 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7101 this_cu
->dwarf_version
= cu
->header
.version
;
7105 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7106 section
, abbrev_section
,
7108 rcuh_kind::COMPILE
);
7110 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7111 if (this_cu
->length
== 0)
7112 this_cu
->length
= cu
->header
.get_length ();
7114 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7115 this_cu
->dwarf_version
= cu
->header
.version
;
7119 /* Skip dummy compilation units. */
7120 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7121 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7127 /* If we don't have them yet, read the abbrevs for this compilation unit.
7128 And if we need to read them now, make sure they're freed when we're
7130 if (abbrev_table
!= NULL
)
7131 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7134 m_abbrev_table_holder
7135 = abbrev_table::read (objfile
, abbrev_section
,
7136 cu
->header
.abbrev_sect_off
);
7137 abbrev_table
= m_abbrev_table_holder
.get ();
7140 /* Read the top level CU/TU die. */
7141 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7142 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7144 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7150 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7151 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7152 table from the DWO file and pass the ownership over to us. It will be
7153 referenced from READER, so we must make sure to free it after we're done
7156 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7157 DWO CU, that this test will fail (the attribute will not be present). */
7158 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7159 if (dwo_name
!= nullptr)
7161 struct dwo_unit
*dwo_unit
;
7162 struct die_info
*dwo_comp_unit_die
;
7164 if (comp_unit_die
->has_children
)
7166 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7167 " has children (offset %s) [in module %s]"),
7168 sect_offset_str (this_cu
->sect_off
),
7169 bfd_get_filename (abfd
));
7171 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7172 if (dwo_unit
!= NULL
)
7174 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7175 comp_unit_die
, NULL
,
7178 &m_dwo_abbrev_table
) == 0)
7184 comp_unit_die
= dwo_comp_unit_die
;
7188 /* Yikes, we couldn't find the rest of the DIE, we only have
7189 the stub. A complaint has already been logged. There's
7190 not much more we can do except pass on the stub DIE to
7191 die_reader_func. We don't want to throw an error on bad
7198 cutu_reader::keep ()
7200 /* Done, clean up. */
7201 gdb_assert (!dummy_p
);
7202 if (m_new_cu
!= NULL
)
7204 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7206 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7207 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7211 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7212 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7213 assumed to have already done the lookup to find the DWO file).
7215 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7216 THIS_CU->is_debug_types, but nothing else.
7218 We fill in THIS_CU->length.
7220 THIS_CU->cu is always freed when done.
7221 This is done in order to not leave THIS_CU->cu in a state where we have
7222 to care whether it refers to the "main" CU or the DWO CU.
7224 When parent_cu is passed, it is used to provide a default value for
7225 str_offsets_base and addr_base from the parent. */
7227 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7228 dwarf2_per_objfile
*per_objfile
,
7229 struct dwarf2_cu
*parent_cu
,
7230 struct dwo_file
*dwo_file
)
7231 : die_reader_specs
{},
7234 struct objfile
*objfile
= per_objfile
->objfile
;
7235 struct dwarf2_section_info
*section
= this_cu
->section
;
7236 bfd
*abfd
= section
->get_bfd_owner ();
7237 struct dwarf2_section_info
*abbrev_section
;
7238 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7240 if (dwarf_die_debug
)
7241 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7242 this_cu
->is_debug_types
? "type" : "comp",
7243 sect_offset_str (this_cu
->sect_off
));
7245 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7247 abbrev_section
= (dwo_file
!= NULL
7248 ? &dwo_file
->sections
.abbrev
7249 : get_abbrev_section_for_cu (this_cu
));
7251 /* This is cheap if the section is already read in. */
7252 section
->read (objfile
);
7254 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7256 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7257 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7258 section
, abbrev_section
, info_ptr
,
7259 (this_cu
->is_debug_types
7261 : rcuh_kind::COMPILE
));
7263 if (parent_cu
!= nullptr)
7265 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7266 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7268 this_cu
->length
= m_new_cu
->header
.get_length ();
7270 /* Skip dummy compilation units. */
7271 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7272 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7278 m_abbrev_table_holder
7279 = abbrev_table::read (objfile
, abbrev_section
,
7280 m_new_cu
->header
.abbrev_sect_off
);
7282 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7283 m_abbrev_table_holder
.get ());
7284 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7288 /* Type Unit Groups.
7290 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7291 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7292 so that all types coming from the same compilation (.o file) are grouped
7293 together. A future step could be to put the types in the same symtab as
7294 the CU the types ultimately came from. */
7297 hash_type_unit_group (const void *item
)
7299 const struct type_unit_group
*tu_group
7300 = (const struct type_unit_group
*) item
;
7302 return hash_stmt_list_entry (&tu_group
->hash
);
7306 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7308 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7309 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7311 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7314 /* Allocate a hash table for type unit groups. */
7317 allocate_type_unit_groups_table ()
7319 return htab_up (htab_create_alloc (3,
7320 hash_type_unit_group
,
7322 NULL
, xcalloc
, xfree
));
7325 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7326 partial symtabs. We combine several TUs per psymtab to not let the size
7327 of any one psymtab grow too big. */
7328 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7329 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7331 /* Helper routine for get_type_unit_group.
7332 Create the type_unit_group object used to hold one or more TUs. */
7334 static struct type_unit_group
*
7335 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7337 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7338 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7339 struct dwarf2_per_cu_data
*per_cu
;
7340 struct type_unit_group
*tu_group
;
7342 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7343 per_cu
= &tu_group
->per_cu
;
7344 per_cu
->per_bfd
= per_bfd
;
7346 if (per_bfd
->using_index
)
7348 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7349 struct dwarf2_per_cu_quick_data
);
7353 unsigned int line_offset
= to_underlying (line_offset_struct
);
7354 dwarf2_psymtab
*pst
;
7357 /* Give the symtab a useful name for debug purposes. */
7358 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7359 name
= string_printf ("<type_units_%d>",
7360 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7362 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7364 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7365 pst
->anonymous
= true;
7368 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7369 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7374 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7375 STMT_LIST is a DW_AT_stmt_list attribute. */
7377 static struct type_unit_group
*
7378 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7380 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7381 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7382 struct type_unit_group
*tu_group
;
7384 unsigned int line_offset
;
7385 struct type_unit_group type_unit_group_for_lookup
;
7387 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7388 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7390 /* Do we need to create a new group, or can we use an existing one? */
7394 line_offset
= DW_UNSND (stmt_list
);
7395 ++tu_stats
->nr_symtab_sharers
;
7399 /* Ugh, no stmt_list. Rare, but we have to handle it.
7400 We can do various things here like create one group per TU or
7401 spread them over multiple groups to split up the expansion work.
7402 To avoid worst case scenarios (too many groups or too large groups)
7403 we, umm, group them in bunches. */
7404 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7405 | (tu_stats
->nr_stmt_less_type_units
7406 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7407 ++tu_stats
->nr_stmt_less_type_units
;
7410 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7411 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7412 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7413 &type_unit_group_for_lookup
, INSERT
);
7416 tu_group
= (struct type_unit_group
*) *slot
;
7417 gdb_assert (tu_group
!= NULL
);
7421 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7422 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7424 ++tu_stats
->nr_symtabs
;
7430 /* Partial symbol tables. */
7432 /* Create a psymtab named NAME and assign it to PER_CU.
7434 The caller must fill in the following details:
7435 dirname, textlow, texthigh. */
7437 static dwarf2_psymtab
*
7438 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7439 dwarf2_per_objfile
*per_objfile
,
7442 struct objfile
*objfile
= per_objfile
->objfile
;
7443 dwarf2_psymtab
*pst
;
7445 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7447 pst
->psymtabs_addrmap_supported
= true;
7449 /* This is the glue that links PST into GDB's symbol API. */
7450 per_cu
->v
.psymtab
= pst
;
7455 /* DIE reader function for process_psymtab_comp_unit. */
7458 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7459 const gdb_byte
*info_ptr
,
7460 struct die_info
*comp_unit_die
,
7461 enum language pretend_language
)
7463 struct dwarf2_cu
*cu
= reader
->cu
;
7464 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7465 struct objfile
*objfile
= per_objfile
->objfile
;
7466 struct gdbarch
*gdbarch
= objfile
->arch ();
7467 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7469 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7470 dwarf2_psymtab
*pst
;
7471 enum pc_bounds_kind cu_bounds_kind
;
7472 const char *filename
;
7474 gdb_assert (! per_cu
->is_debug_types
);
7476 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7478 /* Allocate a new partial symbol table structure. */
7479 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7480 static const char artificial
[] = "<artificial>";
7481 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7482 if (filename
== NULL
)
7484 else if (strcmp (filename
, artificial
) == 0)
7486 debug_filename
.reset (concat (artificial
, "@",
7487 sect_offset_str (per_cu
->sect_off
),
7489 filename
= debug_filename
.get ();
7492 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7494 /* This must be done before calling dwarf2_build_include_psymtabs. */
7495 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7497 baseaddr
= objfile
->text_section_offset ();
7499 dwarf2_find_base_address (comp_unit_die
, cu
);
7501 /* Possibly set the default values of LOWPC and HIGHPC from
7503 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7504 &best_highpc
, cu
, pst
);
7505 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7508 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7511 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7513 /* Store the contiguous range if it is not empty; it can be
7514 empty for CUs with no code. */
7515 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7519 /* Check if comp unit has_children.
7520 If so, read the rest of the partial symbols from this comp unit.
7521 If not, there's no more debug_info for this comp unit. */
7522 if (comp_unit_die
->has_children
)
7524 struct partial_die_info
*first_die
;
7525 CORE_ADDR lowpc
, highpc
;
7527 lowpc
= ((CORE_ADDR
) -1);
7528 highpc
= ((CORE_ADDR
) 0);
7530 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7532 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7533 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7535 /* If we didn't find a lowpc, set it to highpc to avoid
7536 complaints from `maint check'. */
7537 if (lowpc
== ((CORE_ADDR
) -1))
7540 /* If the compilation unit didn't have an explicit address range,
7541 then use the information extracted from its child dies. */
7542 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7545 best_highpc
= highpc
;
7548 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7549 best_lowpc
+ baseaddr
)
7551 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7552 best_highpc
+ baseaddr
)
7555 end_psymtab_common (objfile
, pst
);
7557 if (!cu
->per_cu
->imported_symtabs_empty ())
7560 int len
= cu
->per_cu
->imported_symtabs_size ();
7562 /* Fill in 'dependencies' here; we fill in 'users' in a
7564 pst
->number_of_dependencies
= len
;
7566 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7567 for (i
= 0; i
< len
; ++i
)
7569 pst
->dependencies
[i
]
7570 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7573 cu
->per_cu
->imported_symtabs_free ();
7576 /* Get the list of files included in the current compilation unit,
7577 and build a psymtab for each of them. */
7578 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7580 if (dwarf_read_debug
)
7581 fprintf_unfiltered (gdb_stdlog
,
7582 "Psymtab for %s unit @%s: %s - %s"
7583 ", %d global, %d static syms\n",
7584 per_cu
->is_debug_types
? "type" : "comp",
7585 sect_offset_str (per_cu
->sect_off
),
7586 paddress (gdbarch
, pst
->text_low (objfile
)),
7587 paddress (gdbarch
, pst
->text_high (objfile
)),
7588 pst
->n_global_syms
, pst
->n_static_syms
);
7591 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7592 Process compilation unit THIS_CU for a psymtab. */
7595 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7596 dwarf2_per_objfile
*per_objfile
,
7597 bool want_partial_unit
,
7598 enum language pretend_language
)
7600 /* If this compilation unit was already read in, free the
7601 cached copy in order to read it in again. This is
7602 necessary because we skipped some symbols when we first
7603 read in the compilation unit (see load_partial_dies).
7604 This problem could be avoided, but the benefit is unclear. */
7605 per_objfile
->remove_cu (this_cu
);
7607 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7609 switch (reader
.comp_unit_die
->tag
)
7611 case DW_TAG_compile_unit
:
7612 this_cu
->unit_type
= DW_UT_compile
;
7614 case DW_TAG_partial_unit
:
7615 this_cu
->unit_type
= DW_UT_partial
;
7625 else if (this_cu
->is_debug_types
)
7626 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7627 reader
.comp_unit_die
);
7628 else if (want_partial_unit
7629 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7630 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7631 reader
.comp_unit_die
,
7634 this_cu
->lang
= reader
.cu
->language
;
7636 /* Age out any secondary CUs. */
7637 per_objfile
->age_comp_units ();
7640 /* Reader function for build_type_psymtabs. */
7643 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7644 const gdb_byte
*info_ptr
,
7645 struct die_info
*type_unit_die
)
7647 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7648 struct objfile
*objfile
= per_objfile
->objfile
;
7649 struct dwarf2_cu
*cu
= reader
->cu
;
7650 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7651 struct signatured_type
*sig_type
;
7652 struct type_unit_group
*tu_group
;
7653 struct attribute
*attr
;
7654 struct partial_die_info
*first_die
;
7655 CORE_ADDR lowpc
, highpc
;
7656 dwarf2_psymtab
*pst
;
7658 gdb_assert (per_cu
->is_debug_types
);
7659 sig_type
= (struct signatured_type
*) per_cu
;
7661 if (! type_unit_die
->has_children
)
7664 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7665 tu_group
= get_type_unit_group (cu
, attr
);
7667 if (tu_group
->tus
== nullptr)
7668 tu_group
->tus
= new std::vector
<signatured_type
*>;
7669 tu_group
->tus
->push_back (sig_type
);
7671 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7672 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7673 pst
->anonymous
= true;
7675 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7677 lowpc
= (CORE_ADDR
) -1;
7678 highpc
= (CORE_ADDR
) 0;
7679 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7681 end_psymtab_common (objfile
, pst
);
7684 /* Struct used to sort TUs by their abbreviation table offset. */
7686 struct tu_abbrev_offset
7688 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7689 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7692 signatured_type
*sig_type
;
7693 sect_offset abbrev_offset
;
7696 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7699 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7700 const struct tu_abbrev_offset
&b
)
7702 return a
.abbrev_offset
< b
.abbrev_offset
;
7705 /* Efficiently read all the type units.
7706 This does the bulk of the work for build_type_psymtabs.
7708 The efficiency is because we sort TUs by the abbrev table they use and
7709 only read each abbrev table once. In one program there are 200K TUs
7710 sharing 8K abbrev tables.
7712 The main purpose of this function is to support building the
7713 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7714 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7715 can collapse the search space by grouping them by stmt_list.
7716 The savings can be significant, in the same program from above the 200K TUs
7717 share 8K stmt_list tables.
7719 FUNC is expected to call get_type_unit_group, which will create the
7720 struct type_unit_group if necessary and add it to
7721 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7724 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7726 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7727 abbrev_table_up abbrev_table
;
7728 sect_offset abbrev_offset
;
7730 /* It's up to the caller to not call us multiple times. */
7731 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7733 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7736 /* TUs typically share abbrev tables, and there can be way more TUs than
7737 abbrev tables. Sort by abbrev table to reduce the number of times we
7738 read each abbrev table in.
7739 Alternatives are to punt or to maintain a cache of abbrev tables.
7740 This is simpler and efficient enough for now.
7742 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7743 symtab to use). Typically TUs with the same abbrev offset have the same
7744 stmt_list value too so in practice this should work well.
7746 The basic algorithm here is:
7748 sort TUs by abbrev table
7749 for each TU with same abbrev table:
7750 read abbrev table if first user
7751 read TU top level DIE
7752 [IWBN if DWO skeletons had DW_AT_stmt_list]
7755 if (dwarf_read_debug
)
7756 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7758 /* Sort in a separate table to maintain the order of all_type_units
7759 for .gdb_index: TU indices directly index all_type_units. */
7760 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7761 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7763 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7764 sorted_by_abbrev
.emplace_back
7765 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7766 sig_type
->per_cu
.sect_off
));
7768 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7769 sort_tu_by_abbrev_offset
);
7771 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7773 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7775 /* Switch to the next abbrev table if necessary. */
7776 if (abbrev_table
== NULL
7777 || tu
.abbrev_offset
!= abbrev_offset
)
7779 abbrev_offset
= tu
.abbrev_offset
;
7781 abbrev_table::read (per_objfile
->objfile
,
7782 &per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7783 ++tu_stats
->nr_uniq_abbrev_tables
;
7786 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7787 abbrev_table
.get (), nullptr, false);
7788 if (!reader
.dummy_p
)
7789 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7790 reader
.comp_unit_die
);
7794 /* Print collected type unit statistics. */
7797 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7799 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7801 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7802 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7803 per_objfile
->per_bfd
->all_type_units
.size ());
7804 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7805 tu_stats
->nr_uniq_abbrev_tables
);
7806 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7807 tu_stats
->nr_symtabs
);
7808 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7809 tu_stats
->nr_symtab_sharers
);
7810 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7811 tu_stats
->nr_stmt_less_type_units
);
7812 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7813 tu_stats
->nr_all_type_units_reallocs
);
7816 /* Traversal function for build_type_psymtabs. */
7819 build_type_psymtab_dependencies (void **slot
, void *info
)
7821 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7822 struct objfile
*objfile
= per_objfile
->objfile
;
7823 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7824 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7825 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7826 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7829 gdb_assert (len
> 0);
7830 gdb_assert (per_cu
->type_unit_group_p ());
7832 pst
->number_of_dependencies
= len
;
7833 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7834 for (i
= 0; i
< len
; ++i
)
7836 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7837 gdb_assert (iter
->per_cu
.is_debug_types
);
7838 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7839 iter
->type_unit_group
= tu_group
;
7842 delete tu_group
->tus
;
7843 tu_group
->tus
= nullptr;
7848 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7849 Build partial symbol tables for the .debug_types comp-units. */
7852 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7854 if (! create_all_type_units (per_objfile
))
7857 build_type_psymtabs_1 (per_objfile
);
7860 /* Traversal function for process_skeletonless_type_unit.
7861 Read a TU in a DWO file and build partial symbols for it. */
7864 process_skeletonless_type_unit (void **slot
, void *info
)
7866 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7867 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7868 struct signatured_type find_entry
, *entry
;
7870 /* If this TU doesn't exist in the global table, add it and read it in. */
7872 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7873 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7875 find_entry
.signature
= dwo_unit
->signature
;
7876 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7877 &find_entry
, INSERT
);
7878 /* If we've already seen this type there's nothing to do. What's happening
7879 is we're doing our own version of comdat-folding here. */
7883 /* This does the job that create_all_type_units would have done for
7885 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7886 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7889 /* This does the job that build_type_psymtabs_1 would have done. */
7890 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7891 if (!reader
.dummy_p
)
7892 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7893 reader
.comp_unit_die
);
7898 /* Traversal function for process_skeletonless_type_units. */
7901 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7903 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7905 if (dwo_file
->tus
!= NULL
)
7906 htab_traverse_noresize (dwo_file
->tus
.get (),
7907 process_skeletonless_type_unit
, info
);
7912 /* Scan all TUs of DWO files, verifying we've processed them.
7913 This is needed in case a TU was emitted without its skeleton.
7914 Note: This can't be done until we know what all the DWO files are. */
7917 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7919 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7920 if (get_dwp_file (per_objfile
) == NULL
7921 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7923 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7924 process_dwo_file_for_skeletonless_type_units
,
7929 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7932 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7934 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7936 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7941 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7943 /* Set the 'user' field only if it is not already set. */
7944 if (pst
->dependencies
[j
]->user
== NULL
)
7945 pst
->dependencies
[j
]->user
= pst
;
7950 /* Build the partial symbol table by doing a quick pass through the
7951 .debug_info and .debug_abbrev sections. */
7954 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7956 struct objfile
*objfile
= per_objfile
->objfile
;
7958 if (dwarf_read_debug
)
7960 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7961 objfile_name (objfile
));
7964 scoped_restore restore_reading_psyms
7965 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
7968 per_objfile
->per_bfd
->info
.read (objfile
);
7970 /* Any cached compilation units will be linked by the per-objfile
7971 read_in_chain. Make sure to free them when we're done. */
7972 free_cached_comp_units
freer (per_objfile
);
7974 build_type_psymtabs (per_objfile
);
7976 create_all_comp_units (per_objfile
);
7978 /* Create a temporary address map on a temporary obstack. We later
7979 copy this to the final obstack. */
7980 auto_obstack temp_obstack
;
7982 scoped_restore save_psymtabs_addrmap
7983 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7984 addrmap_create_mutable (&temp_obstack
));
7986 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7988 if (per_cu
->v
.psymtab
!= NULL
)
7989 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7991 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
7995 /* This has to wait until we read the CUs, we need the list of DWOs. */
7996 process_skeletonless_type_units (per_objfile
);
7998 /* Now that all TUs have been processed we can fill in the dependencies. */
7999 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8001 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8002 build_type_psymtab_dependencies
, per_objfile
);
8005 if (dwarf_read_debug
)
8006 print_tu_stats (per_objfile
);
8008 set_partial_user (per_objfile
);
8010 objfile
->partial_symtabs
->psymtabs_addrmap
8011 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8012 objfile
->partial_symtabs
->obstack ());
8013 /* At this point we want to keep the address map. */
8014 save_psymtabs_addrmap
.release ();
8016 if (dwarf_read_debug
)
8017 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8018 objfile_name (objfile
));
8021 /* Load the partial DIEs for a secondary CU into memory.
8022 This is also used when rereading a primary CU with load_all_dies. */
8025 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8026 dwarf2_per_objfile
*per_objfile
,
8027 dwarf2_cu
*existing_cu
)
8029 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8031 if (!reader
.dummy_p
)
8033 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8036 /* Check if comp unit has_children.
8037 If so, read the rest of the partial symbols from this comp unit.
8038 If not, there's no more debug_info for this comp unit. */
8039 if (reader
.comp_unit_die
->has_children
)
8040 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8047 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8048 struct dwarf2_section_info
*section
,
8049 struct dwarf2_section_info
*abbrev_section
,
8050 unsigned int is_dwz
)
8052 const gdb_byte
*info_ptr
;
8053 struct objfile
*objfile
= per_objfile
->objfile
;
8055 if (dwarf_read_debug
)
8056 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8057 section
->get_name (),
8058 section
->get_file_name ());
8060 section
->read (objfile
);
8062 info_ptr
= section
->buffer
;
8064 while (info_ptr
< section
->buffer
+ section
->size
)
8066 struct dwarf2_per_cu_data
*this_cu
;
8068 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8070 comp_unit_head cu_header
;
8071 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8072 abbrev_section
, info_ptr
,
8073 rcuh_kind::COMPILE
);
8075 /* Save the compilation unit for later lookup. */
8076 if (cu_header
.unit_type
!= DW_UT_type
)
8077 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8080 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8081 sig_type
->signature
= cu_header
.signature
;
8082 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8083 this_cu
= &sig_type
->per_cu
;
8085 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8086 this_cu
->sect_off
= sect_off
;
8087 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8088 this_cu
->is_dwz
= is_dwz
;
8089 this_cu
->section
= section
;
8091 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8093 info_ptr
= info_ptr
+ this_cu
->length
;
8097 /* Create a list of all compilation units in OBJFILE.
8098 This is only done for -readnow and building partial symtabs. */
8101 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8103 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8104 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8105 &per_objfile
->per_bfd
->abbrev
, 0);
8107 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8109 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8112 /* Process all loaded DIEs for compilation unit CU, starting at
8113 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8114 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8115 DW_AT_ranges). See the comments of add_partial_subprogram on how
8116 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8119 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8120 CORE_ADDR
*highpc
, int set_addrmap
,
8121 struct dwarf2_cu
*cu
)
8123 struct partial_die_info
*pdi
;
8125 /* Now, march along the PDI's, descending into ones which have
8126 interesting children but skipping the children of the other ones,
8127 until we reach the end of the compilation unit. */
8135 /* Anonymous namespaces or modules have no name but have interesting
8136 children, so we need to look at them. Ditto for anonymous
8139 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8140 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8141 || pdi
->tag
== DW_TAG_imported_unit
8142 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8146 case DW_TAG_subprogram
:
8147 case DW_TAG_inlined_subroutine
:
8148 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8150 case DW_TAG_constant
:
8151 case DW_TAG_variable
:
8152 case DW_TAG_typedef
:
8153 case DW_TAG_union_type
:
8154 if (!pdi
->is_declaration
8155 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8157 add_partial_symbol (pdi
, cu
);
8160 case DW_TAG_class_type
:
8161 case DW_TAG_interface_type
:
8162 case DW_TAG_structure_type
:
8163 if (!pdi
->is_declaration
)
8165 add_partial_symbol (pdi
, cu
);
8167 if ((cu
->language
== language_rust
8168 || cu
->language
== language_cplus
) && pdi
->has_children
)
8169 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8172 case DW_TAG_enumeration_type
:
8173 if (!pdi
->is_declaration
)
8174 add_partial_enumeration (pdi
, cu
);
8176 case DW_TAG_base_type
:
8177 case DW_TAG_subrange_type
:
8178 /* File scope base type definitions are added to the partial
8180 add_partial_symbol (pdi
, cu
);
8182 case DW_TAG_namespace
:
8183 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8186 if (!pdi
->is_declaration
)
8187 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8189 case DW_TAG_imported_unit
:
8191 struct dwarf2_per_cu_data
*per_cu
;
8193 /* For now we don't handle imported units in type units. */
8194 if (cu
->per_cu
->is_debug_types
)
8196 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8197 " supported in type units [in module %s]"),
8198 objfile_name (cu
->per_objfile
->objfile
));
8201 per_cu
= dwarf2_find_containing_comp_unit
8202 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8204 /* Go read the partial unit, if needed. */
8205 if (per_cu
->v
.psymtab
== NULL
)
8206 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8209 cu
->per_cu
->imported_symtabs_push (per_cu
);
8212 case DW_TAG_imported_declaration
:
8213 add_partial_symbol (pdi
, cu
);
8220 /* If the die has a sibling, skip to the sibling. */
8222 pdi
= pdi
->die_sibling
;
8226 /* Functions used to compute the fully scoped name of a partial DIE.
8228 Normally, this is simple. For C++, the parent DIE's fully scoped
8229 name is concatenated with "::" and the partial DIE's name.
8230 Enumerators are an exception; they use the scope of their parent
8231 enumeration type, i.e. the name of the enumeration type is not
8232 prepended to the enumerator.
8234 There are two complexities. One is DW_AT_specification; in this
8235 case "parent" means the parent of the target of the specification,
8236 instead of the direct parent of the DIE. The other is compilers
8237 which do not emit DW_TAG_namespace; in this case we try to guess
8238 the fully qualified name of structure types from their members'
8239 linkage names. This must be done using the DIE's children rather
8240 than the children of any DW_AT_specification target. We only need
8241 to do this for structures at the top level, i.e. if the target of
8242 any DW_AT_specification (if any; otherwise the DIE itself) does not
8245 /* Compute the scope prefix associated with PDI's parent, in
8246 compilation unit CU. The result will be allocated on CU's
8247 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8248 field. NULL is returned if no prefix is necessary. */
8250 partial_die_parent_scope (struct partial_die_info
*pdi
,
8251 struct dwarf2_cu
*cu
)
8253 const char *grandparent_scope
;
8254 struct partial_die_info
*parent
, *real_pdi
;
8256 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8257 then this means the parent of the specification DIE. */
8260 while (real_pdi
->has_specification
)
8262 auto res
= find_partial_die (real_pdi
->spec_offset
,
8263 real_pdi
->spec_is_dwz
, cu
);
8268 parent
= real_pdi
->die_parent
;
8272 if (parent
->scope_set
)
8273 return parent
->scope
;
8277 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8279 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8280 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8281 Work around this problem here. */
8282 if (cu
->language
== language_cplus
8283 && parent
->tag
== DW_TAG_namespace
8284 && strcmp (parent
->name (cu
), "::") == 0
8285 && grandparent_scope
== NULL
)
8287 parent
->scope
= NULL
;
8288 parent
->scope_set
= 1;
8292 /* Nested subroutines in Fortran get a prefix. */
8293 if (pdi
->tag
== DW_TAG_enumerator
)
8294 /* Enumerators should not get the name of the enumeration as a prefix. */
8295 parent
->scope
= grandparent_scope
;
8296 else if (parent
->tag
== DW_TAG_namespace
8297 || parent
->tag
== DW_TAG_module
8298 || parent
->tag
== DW_TAG_structure_type
8299 || parent
->tag
== DW_TAG_class_type
8300 || parent
->tag
== DW_TAG_interface_type
8301 || parent
->tag
== DW_TAG_union_type
8302 || parent
->tag
== DW_TAG_enumeration_type
8303 || (cu
->language
== language_fortran
8304 && parent
->tag
== DW_TAG_subprogram
8305 && pdi
->tag
== DW_TAG_subprogram
))
8307 if (grandparent_scope
== NULL
)
8308 parent
->scope
= parent
->name (cu
);
8310 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8312 parent
->name (cu
), 0, cu
);
8316 /* FIXME drow/2004-04-01: What should we be doing with
8317 function-local names? For partial symbols, we should probably be
8319 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8320 dwarf_tag_name (parent
->tag
),
8321 sect_offset_str (pdi
->sect_off
));
8322 parent
->scope
= grandparent_scope
;
8325 parent
->scope_set
= 1;
8326 return parent
->scope
;
8329 /* Return the fully scoped name associated with PDI, from compilation unit
8330 CU. The result will be allocated with malloc. */
8332 static gdb::unique_xmalloc_ptr
<char>
8333 partial_die_full_name (struct partial_die_info
*pdi
,
8334 struct dwarf2_cu
*cu
)
8336 const char *parent_scope
;
8338 /* If this is a template instantiation, we can not work out the
8339 template arguments from partial DIEs. So, unfortunately, we have
8340 to go through the full DIEs. At least any work we do building
8341 types here will be reused if full symbols are loaded later. */
8342 if (pdi
->has_template_arguments
)
8346 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8348 struct die_info
*die
;
8349 struct attribute attr
;
8350 struct dwarf2_cu
*ref_cu
= cu
;
8352 /* DW_FORM_ref_addr is using section offset. */
8353 attr
.name
= (enum dwarf_attribute
) 0;
8354 attr
.form
= DW_FORM_ref_addr
;
8355 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8356 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8358 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8362 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8363 if (parent_scope
== NULL
)
8366 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8372 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8374 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8375 struct objfile
*objfile
= per_objfile
->objfile
;
8376 struct gdbarch
*gdbarch
= objfile
->arch ();
8378 const char *actual_name
= NULL
;
8381 baseaddr
= objfile
->text_section_offset ();
8383 gdb::unique_xmalloc_ptr
<char> built_actual_name
8384 = partial_die_full_name (pdi
, cu
);
8385 if (built_actual_name
!= NULL
)
8386 actual_name
= built_actual_name
.get ();
8388 if (actual_name
== NULL
)
8389 actual_name
= pdi
->name (cu
);
8391 partial_symbol psymbol
;
8392 memset (&psymbol
, 0, sizeof (psymbol
));
8393 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8394 psymbol
.ginfo
.section
= -1;
8396 /* The code below indicates that the psymbol should be installed by
8398 gdb::optional
<psymbol_placement
> where
;
8402 case DW_TAG_inlined_subroutine
:
8403 case DW_TAG_subprogram
:
8404 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8406 if (pdi
->is_external
8407 || cu
->language
== language_ada
8408 || (cu
->language
== language_fortran
8409 && pdi
->die_parent
!= NULL
8410 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8412 /* Normally, only "external" DIEs are part of the global scope.
8413 But in Ada and Fortran, we want to be able to access nested
8414 procedures globally. So all Ada and Fortran subprograms are
8415 stored in the global scope. */
8416 where
= psymbol_placement::GLOBAL
;
8419 where
= psymbol_placement::STATIC
;
8421 psymbol
.domain
= VAR_DOMAIN
;
8422 psymbol
.aclass
= LOC_BLOCK
;
8423 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8424 psymbol
.ginfo
.value
.address
= addr
;
8426 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8427 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8429 case DW_TAG_constant
:
8430 psymbol
.domain
= VAR_DOMAIN
;
8431 psymbol
.aclass
= LOC_STATIC
;
8432 where
= (pdi
->is_external
8433 ? psymbol_placement::GLOBAL
8434 : psymbol_placement::STATIC
);
8436 case DW_TAG_variable
:
8438 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8442 && !per_objfile
->per_bfd
->has_section_at_zero
)
8444 /* A global or static variable may also have been stripped
8445 out by the linker if unused, in which case its address
8446 will be nullified; do not add such variables into partial
8447 symbol table then. */
8449 else if (pdi
->is_external
)
8452 Don't enter into the minimal symbol tables as there is
8453 a minimal symbol table entry from the ELF symbols already.
8454 Enter into partial symbol table if it has a location
8455 descriptor or a type.
8456 If the location descriptor is missing, new_symbol will create
8457 a LOC_UNRESOLVED symbol, the address of the variable will then
8458 be determined from the minimal symbol table whenever the variable
8460 The address for the partial symbol table entry is not
8461 used by GDB, but it comes in handy for debugging partial symbol
8464 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8466 psymbol
.domain
= VAR_DOMAIN
;
8467 psymbol
.aclass
= LOC_STATIC
;
8468 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8469 psymbol
.ginfo
.value
.address
= addr
;
8470 where
= psymbol_placement::GLOBAL
;
8475 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8477 /* Static Variable. Skip symbols whose value we cannot know (those
8478 without location descriptors or constant values). */
8479 if (!has_loc
&& !pdi
->has_const_value
)
8482 psymbol
.domain
= VAR_DOMAIN
;
8483 psymbol
.aclass
= LOC_STATIC
;
8484 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8486 psymbol
.ginfo
.value
.address
= addr
;
8487 where
= psymbol_placement::STATIC
;
8490 case DW_TAG_typedef
:
8491 case DW_TAG_base_type
:
8492 case DW_TAG_subrange_type
:
8493 psymbol
.domain
= VAR_DOMAIN
;
8494 psymbol
.aclass
= LOC_TYPEDEF
;
8495 where
= psymbol_placement::STATIC
;
8497 case DW_TAG_imported_declaration
:
8498 case DW_TAG_namespace
:
8499 psymbol
.domain
= VAR_DOMAIN
;
8500 psymbol
.aclass
= LOC_TYPEDEF
;
8501 where
= psymbol_placement::GLOBAL
;
8504 /* With Fortran 77 there might be a "BLOCK DATA" module
8505 available without any name. If so, we skip the module as it
8506 doesn't bring any value. */
8507 if (actual_name
!= nullptr)
8509 psymbol
.domain
= MODULE_DOMAIN
;
8510 psymbol
.aclass
= LOC_TYPEDEF
;
8511 where
= psymbol_placement::GLOBAL
;
8514 case DW_TAG_class_type
:
8515 case DW_TAG_interface_type
:
8516 case DW_TAG_structure_type
:
8517 case DW_TAG_union_type
:
8518 case DW_TAG_enumeration_type
:
8519 /* Skip external references. The DWARF standard says in the section
8520 about "Structure, Union, and Class Type Entries": "An incomplete
8521 structure, union or class type is represented by a structure,
8522 union or class entry that does not have a byte size attribute
8523 and that has a DW_AT_declaration attribute." */
8524 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8527 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8528 static vs. global. */
8529 psymbol
.domain
= STRUCT_DOMAIN
;
8530 psymbol
.aclass
= LOC_TYPEDEF
;
8531 where
= (cu
->language
== language_cplus
8532 ? psymbol_placement::GLOBAL
8533 : psymbol_placement::STATIC
);
8535 case DW_TAG_enumerator
:
8536 psymbol
.domain
= VAR_DOMAIN
;
8537 psymbol
.aclass
= LOC_CONST
;
8538 where
= (cu
->language
== language_cplus
8539 ? psymbol_placement::GLOBAL
8540 : psymbol_placement::STATIC
);
8546 if (where
.has_value ())
8548 if (built_actual_name
!= nullptr)
8549 actual_name
= objfile
->intern (actual_name
);
8550 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8551 psymbol
.ginfo
.set_linkage_name (actual_name
);
8554 psymbol
.ginfo
.set_demangled_name (actual_name
,
8555 &objfile
->objfile_obstack
);
8556 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8558 add_psymbol_to_list (psymbol
, *where
, objfile
);
8562 /* Read a partial die corresponding to a namespace; also, add a symbol
8563 corresponding to that namespace to the symbol table. NAMESPACE is
8564 the name of the enclosing namespace. */
8567 add_partial_namespace (struct partial_die_info
*pdi
,
8568 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8569 int set_addrmap
, struct dwarf2_cu
*cu
)
8571 /* Add a symbol for the namespace. */
8573 add_partial_symbol (pdi
, cu
);
8575 /* Now scan partial symbols in that namespace. */
8577 if (pdi
->has_children
)
8578 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8581 /* Read a partial die corresponding to a Fortran module. */
8584 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8585 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8587 /* Add a symbol for the namespace. */
8589 add_partial_symbol (pdi
, cu
);
8591 /* Now scan partial symbols in that module. */
8593 if (pdi
->has_children
)
8594 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8597 /* Read a partial die corresponding to a subprogram or an inlined
8598 subprogram and create a partial symbol for that subprogram.
8599 When the CU language allows it, this routine also defines a partial
8600 symbol for each nested subprogram that this subprogram contains.
8601 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8602 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8604 PDI may also be a lexical block, in which case we simply search
8605 recursively for subprograms defined inside that lexical block.
8606 Again, this is only performed when the CU language allows this
8607 type of definitions. */
8610 add_partial_subprogram (struct partial_die_info
*pdi
,
8611 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8612 int set_addrmap
, struct dwarf2_cu
*cu
)
8614 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8616 if (pdi
->has_pc_info
)
8618 if (pdi
->lowpc
< *lowpc
)
8619 *lowpc
= pdi
->lowpc
;
8620 if (pdi
->highpc
> *highpc
)
8621 *highpc
= pdi
->highpc
;
8624 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8625 struct gdbarch
*gdbarch
= objfile
->arch ();
8627 CORE_ADDR this_highpc
;
8628 CORE_ADDR this_lowpc
;
8630 baseaddr
= objfile
->text_section_offset ();
8632 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8633 pdi
->lowpc
+ baseaddr
)
8636 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8637 pdi
->highpc
+ baseaddr
)
8639 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8640 this_lowpc
, this_highpc
- 1,
8641 cu
->per_cu
->v
.psymtab
);
8645 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8647 if (!pdi
->is_declaration
)
8648 /* Ignore subprogram DIEs that do not have a name, they are
8649 illegal. Do not emit a complaint at this point, we will
8650 do so when we convert this psymtab into a symtab. */
8652 add_partial_symbol (pdi
, cu
);
8656 if (! pdi
->has_children
)
8659 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8661 pdi
= pdi
->die_child
;
8665 if (pdi
->tag
== DW_TAG_subprogram
8666 || pdi
->tag
== DW_TAG_inlined_subroutine
8667 || pdi
->tag
== DW_TAG_lexical_block
)
8668 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8669 pdi
= pdi
->die_sibling
;
8674 /* Read a partial die corresponding to an enumeration type. */
8677 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8678 struct dwarf2_cu
*cu
)
8680 struct partial_die_info
*pdi
;
8682 if (enum_pdi
->name (cu
) != NULL
)
8683 add_partial_symbol (enum_pdi
, cu
);
8685 pdi
= enum_pdi
->die_child
;
8688 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8689 complaint (_("malformed enumerator DIE ignored"));
8691 add_partial_symbol (pdi
, cu
);
8692 pdi
= pdi
->die_sibling
;
8696 /* Return the initial uleb128 in the die at INFO_PTR. */
8699 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8701 unsigned int bytes_read
;
8703 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8706 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8707 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8709 Return the corresponding abbrev, or NULL if the number is zero (indicating
8710 an empty DIE). In either case *BYTES_READ will be set to the length of
8711 the initial number. */
8713 static struct abbrev_info
*
8714 peek_die_abbrev (const die_reader_specs
&reader
,
8715 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8717 dwarf2_cu
*cu
= reader
.cu
;
8718 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8719 unsigned int abbrev_number
8720 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8722 if (abbrev_number
== 0)
8725 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8728 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8729 " at offset %s [in module %s]"),
8730 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8731 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8737 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8738 Returns a pointer to the end of a series of DIEs, terminated by an empty
8739 DIE. Any children of the skipped DIEs will also be skipped. */
8741 static const gdb_byte
*
8742 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8746 unsigned int bytes_read
;
8747 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8750 return info_ptr
+ bytes_read
;
8752 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8756 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8757 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8758 abbrev corresponding to that skipped uleb128 should be passed in
8759 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8762 static const gdb_byte
*
8763 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8764 struct abbrev_info
*abbrev
)
8766 unsigned int bytes_read
;
8767 struct attribute attr
;
8768 bfd
*abfd
= reader
->abfd
;
8769 struct dwarf2_cu
*cu
= reader
->cu
;
8770 const gdb_byte
*buffer
= reader
->buffer
;
8771 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8772 unsigned int form
, i
;
8774 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8776 /* The only abbrev we care about is DW_AT_sibling. */
8777 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8780 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8782 if (attr
.form
== DW_FORM_ref_addr
)
8783 complaint (_("ignoring absolute DW_AT_sibling"));
8786 sect_offset off
= attr
.get_ref_die_offset ();
8787 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8789 if (sibling_ptr
< info_ptr
)
8790 complaint (_("DW_AT_sibling points backwards"));
8791 else if (sibling_ptr
> reader
->buffer_end
)
8792 reader
->die_section
->overflow_complaint ();
8798 /* If it isn't DW_AT_sibling, skip this attribute. */
8799 form
= abbrev
->attrs
[i
].form
;
8803 case DW_FORM_ref_addr
:
8804 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8805 and later it is offset sized. */
8806 if (cu
->header
.version
== 2)
8807 info_ptr
+= cu
->header
.addr_size
;
8809 info_ptr
+= cu
->header
.offset_size
;
8811 case DW_FORM_GNU_ref_alt
:
8812 info_ptr
+= cu
->header
.offset_size
;
8815 info_ptr
+= cu
->header
.addr_size
;
8823 case DW_FORM_flag_present
:
8824 case DW_FORM_implicit_const
:
8841 case DW_FORM_ref_sig8
:
8844 case DW_FORM_data16
:
8847 case DW_FORM_string
:
8848 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8849 info_ptr
+= bytes_read
;
8851 case DW_FORM_sec_offset
:
8853 case DW_FORM_GNU_strp_alt
:
8854 info_ptr
+= cu
->header
.offset_size
;
8856 case DW_FORM_exprloc
:
8858 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8859 info_ptr
+= bytes_read
;
8861 case DW_FORM_block1
:
8862 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8864 case DW_FORM_block2
:
8865 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8867 case DW_FORM_block4
:
8868 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8874 case DW_FORM_ref_udata
:
8875 case DW_FORM_GNU_addr_index
:
8876 case DW_FORM_GNU_str_index
:
8877 case DW_FORM_rnglistx
:
8878 case DW_FORM_loclistx
:
8879 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8881 case DW_FORM_indirect
:
8882 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8883 info_ptr
+= bytes_read
;
8884 /* We need to continue parsing from here, so just go back to
8886 goto skip_attribute
;
8889 error (_("Dwarf Error: Cannot handle %s "
8890 "in DWARF reader [in module %s]"),
8891 dwarf_form_name (form
),
8892 bfd_get_filename (abfd
));
8896 if (abbrev
->has_children
)
8897 return skip_children (reader
, info_ptr
);
8902 /* Locate ORIG_PDI's sibling.
8903 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8905 static const gdb_byte
*
8906 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8907 struct partial_die_info
*orig_pdi
,
8908 const gdb_byte
*info_ptr
)
8910 /* Do we know the sibling already? */
8912 if (orig_pdi
->sibling
)
8913 return orig_pdi
->sibling
;
8915 /* Are there any children to deal with? */
8917 if (!orig_pdi
->has_children
)
8920 /* Skip the children the long way. */
8922 return skip_children (reader
, info_ptr
);
8925 /* Expand this partial symbol table into a full symbol table. SELF is
8929 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8931 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8933 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8935 /* If this psymtab is constructed from a debug-only objfile, the
8936 has_section_at_zero flag will not necessarily be correct. We
8937 can get the correct value for this flag by looking at the data
8938 associated with the (presumably stripped) associated objfile. */
8939 if (objfile
->separate_debug_objfile_backlink
)
8941 dwarf2_per_objfile
*per_objfile_backlink
8942 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8944 per_objfile
->per_bfd
->has_section_at_zero
8945 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8948 expand_psymtab (objfile
);
8950 process_cu_includes (per_objfile
);
8953 /* Reading in full CUs. */
8955 /* Add PER_CU to the queue. */
8958 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8959 dwarf2_per_objfile
*per_objfile
,
8960 enum language pretend_language
)
8963 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
8966 /* If PER_CU is not yet queued, add it to the queue.
8967 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8969 The result is non-zero if PER_CU was queued, otherwise the result is zero
8970 meaning either PER_CU is already queued or it is already loaded.
8972 N.B. There is an invariant here that if a CU is queued then it is loaded.
8973 The caller is required to load PER_CU if we return non-zero. */
8976 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8977 dwarf2_per_cu_data
*per_cu
,
8978 dwarf2_per_objfile
*per_objfile
,
8979 enum language pretend_language
)
8981 /* We may arrive here during partial symbol reading, if we need full
8982 DIEs to process an unusual case (e.g. template arguments). Do
8983 not queue PER_CU, just tell our caller to load its DIEs. */
8984 if (per_cu
->per_bfd
->reading_partial_symbols
)
8986 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8988 if (cu
== NULL
|| cu
->dies
== NULL
)
8993 /* Mark the dependence relation so that we don't flush PER_CU
8995 if (dependent_cu
!= NULL
)
8996 dwarf2_add_dependence (dependent_cu
, per_cu
);
8998 /* If it's already on the queue, we have nothing to do. */
9002 /* If the compilation unit is already loaded, just mark it as
9004 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9011 /* Add it to the queue. */
9012 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9017 /* Process the queue. */
9020 process_queue (dwarf2_per_objfile
*per_objfile
)
9022 if (dwarf_read_debug
)
9024 fprintf_unfiltered (gdb_stdlog
,
9025 "Expanding one or more symtabs of objfile %s ...\n",
9026 objfile_name (per_objfile
->objfile
));
9029 /* The queue starts out with one item, but following a DIE reference
9030 may load a new CU, adding it to the end of the queue. */
9031 while (!per_objfile
->per_bfd
->queue
.empty ())
9033 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9034 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9036 if (!per_objfile
->symtab_set_p (per_cu
))
9038 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9040 /* Skip dummy CUs. */
9043 unsigned int debug_print_threshold
;
9046 if (per_cu
->is_debug_types
)
9048 struct signatured_type
*sig_type
=
9049 (struct signatured_type
*) per_cu
;
9051 sprintf (buf
, "TU %s at offset %s",
9052 hex_string (sig_type
->signature
),
9053 sect_offset_str (per_cu
->sect_off
));
9054 /* There can be 100s of TUs.
9055 Only print them in verbose mode. */
9056 debug_print_threshold
= 2;
9060 sprintf (buf
, "CU at offset %s",
9061 sect_offset_str (per_cu
->sect_off
));
9062 debug_print_threshold
= 1;
9065 if (dwarf_read_debug
>= debug_print_threshold
)
9066 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9068 if (per_cu
->is_debug_types
)
9069 process_full_type_unit (cu
, item
.pretend_language
);
9071 process_full_comp_unit (cu
, item
.pretend_language
);
9073 if (dwarf_read_debug
>= debug_print_threshold
)
9074 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9079 per_objfile
->per_bfd
->queue
.pop ();
9082 if (dwarf_read_debug
)
9084 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9085 objfile_name (per_objfile
->objfile
));
9089 /* Read in full symbols for PST, and anything it depends on. */
9092 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9094 gdb_assert (!readin_p (objfile
));
9096 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9097 free_cached_comp_units
freer (per_objfile
);
9098 expand_dependencies (objfile
);
9100 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9101 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9104 /* See psympriv.h. */
9107 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9109 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9110 return per_objfile
->symtab_set_p (per_cu_data
);
9113 /* See psympriv.h. */
9116 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9118 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9119 return per_objfile
->get_symtab (per_cu_data
);
9122 /* Trivial hash function for die_info: the hash value of a DIE
9123 is its offset in .debug_info for this objfile. */
9126 die_hash (const void *item
)
9128 const struct die_info
*die
= (const struct die_info
*) item
;
9130 return to_underlying (die
->sect_off
);
9133 /* Trivial comparison function for die_info structures: two DIEs
9134 are equal if they have the same offset. */
9137 die_eq (const void *item_lhs
, const void *item_rhs
)
9139 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9140 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9142 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9145 /* Load the DIEs associated with PER_CU into memory. */
9148 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9149 dwarf2_per_objfile
*per_objfile
,
9151 enum language pretend_language
)
9153 gdb_assert (! this_cu
->is_debug_types
);
9155 dwarf2_cu
*existing_cu
= per_objfile
->get_cu (this_cu
);
9156 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9160 struct dwarf2_cu
*cu
= reader
.cu
;
9161 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9163 gdb_assert (cu
->die_hash
== NULL
);
9165 htab_create_alloc_ex (cu
->header
.length
/ 12,
9169 &cu
->comp_unit_obstack
,
9170 hashtab_obstack_allocate
,
9171 dummy_obstack_deallocate
);
9173 if (reader
.comp_unit_die
->has_children
)
9174 reader
.comp_unit_die
->child
9175 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9176 &info_ptr
, reader
.comp_unit_die
);
9177 cu
->dies
= reader
.comp_unit_die
;
9178 /* comp_unit_die is not stored in die_hash, no need. */
9180 /* We try not to read any attributes in this function, because not
9181 all CUs needed for references have been loaded yet, and symbol
9182 table processing isn't initialized. But we have to set the CU language,
9183 or we won't be able to build types correctly.
9184 Similarly, if we do not read the producer, we can not apply
9185 producer-specific interpretation. */
9186 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9191 /* Add a DIE to the delayed physname list. */
9194 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9195 const char *name
, struct die_info
*die
,
9196 struct dwarf2_cu
*cu
)
9198 struct delayed_method_info mi
;
9200 mi
.fnfield_index
= fnfield_index
;
9204 cu
->method_list
.push_back (mi
);
9207 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9208 "const" / "volatile". If so, decrements LEN by the length of the
9209 modifier and return true. Otherwise return false. */
9213 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9215 size_t mod_len
= sizeof (mod
) - 1;
9216 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9224 /* Compute the physnames of any methods on the CU's method list.
9226 The computation of method physnames is delayed in order to avoid the
9227 (bad) condition that one of the method's formal parameters is of an as yet
9231 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9233 /* Only C++ delays computing physnames. */
9234 if (cu
->method_list
.empty ())
9236 gdb_assert (cu
->language
== language_cplus
);
9238 for (const delayed_method_info
&mi
: cu
->method_list
)
9240 const char *physname
;
9241 struct fn_fieldlist
*fn_flp
9242 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9243 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9244 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9245 = physname
? physname
: "";
9247 /* Since there's no tag to indicate whether a method is a
9248 const/volatile overload, extract that information out of the
9250 if (physname
!= NULL
)
9252 size_t len
= strlen (physname
);
9256 if (physname
[len
] == ')') /* shortcut */
9258 else if (check_modifier (physname
, len
, " const"))
9259 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9260 else if (check_modifier (physname
, len
, " volatile"))
9261 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9268 /* The list is no longer needed. */
9269 cu
->method_list
.clear ();
9272 /* Go objects should be embedded in a DW_TAG_module DIE,
9273 and it's not clear if/how imported objects will appear.
9274 To keep Go support simple until that's worked out,
9275 go back through what we've read and create something usable.
9276 We could do this while processing each DIE, and feels kinda cleaner,
9277 but that way is more invasive.
9278 This is to, for example, allow the user to type "p var" or "b main"
9279 without having to specify the package name, and allow lookups
9280 of module.object to work in contexts that use the expression
9284 fixup_go_packaging (struct dwarf2_cu
*cu
)
9286 gdb::unique_xmalloc_ptr
<char> package_name
;
9287 struct pending
*list
;
9290 for (list
= *cu
->get_builder ()->get_global_symbols ();
9294 for (i
= 0; i
< list
->nsyms
; ++i
)
9296 struct symbol
*sym
= list
->symbol
[i
];
9298 if (sym
->language () == language_go
9299 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9301 gdb::unique_xmalloc_ptr
<char> this_package_name
9302 (go_symbol_package_name (sym
));
9304 if (this_package_name
== NULL
)
9306 if (package_name
== NULL
)
9307 package_name
= std::move (this_package_name
);
9310 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9311 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9312 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9313 (symbol_symtab (sym
) != NULL
9314 ? symtab_to_filename_for_display
9315 (symbol_symtab (sym
))
9316 : objfile_name (objfile
)),
9317 this_package_name
.get (), package_name
.get ());
9323 if (package_name
!= NULL
)
9325 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9326 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9327 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9328 saved_package_name
);
9331 sym
= new (&objfile
->objfile_obstack
) symbol
;
9332 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9333 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9334 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9335 e.g., "main" finds the "main" module and not C's main(). */
9336 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9337 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9338 SYMBOL_TYPE (sym
) = type
;
9340 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9344 /* Allocate a fully-qualified name consisting of the two parts on the
9348 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9350 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9353 /* A helper that allocates a variant part to attach to a Rust enum
9354 type. OBSTACK is where the results should be allocated. TYPE is
9355 the type we're processing. DISCRIMINANT_INDEX is the index of the
9356 discriminant. It must be the index of one of the fields of TYPE.
9357 DEFAULT_INDEX is the index of the default field; or -1 if there is
9358 no default. RANGES is indexed by "effective" field number (the
9359 field index, but omitting the discriminant and default fields) and
9360 must hold the discriminant values used by the variants. Note that
9361 RANGES must have a lifetime at least as long as OBSTACK -- either
9362 already allocated on it, or static. */
9365 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9366 int discriminant_index
, int default_index
,
9367 gdb::array_view
<discriminant_range
> ranges
)
9369 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9370 must be handled by the caller. */
9371 gdb_assert (discriminant_index
>= 0
9372 && discriminant_index
< type
->num_fields ());
9373 gdb_assert (default_index
== -1
9374 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9376 /* We have one variant for each non-discriminant field. */
9377 int n_variants
= type
->num_fields () - 1;
9379 variant
*variants
= new (obstack
) variant
[n_variants
];
9382 for (int i
= 0; i
< type
->num_fields (); ++i
)
9384 if (i
== discriminant_index
)
9387 variants
[var_idx
].first_field
= i
;
9388 variants
[var_idx
].last_field
= i
+ 1;
9390 /* The default field does not need a range, but other fields do.
9391 We skipped the discriminant above. */
9392 if (i
!= default_index
)
9394 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9401 gdb_assert (range_idx
== ranges
.size ());
9402 gdb_assert (var_idx
== n_variants
);
9404 variant_part
*part
= new (obstack
) variant_part
;
9405 part
->discriminant_index
= discriminant_index
;
9406 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9407 discriminant_index
));
9408 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9410 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9411 gdb::array_view
<variant_part
> *prop_value
9412 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9414 struct dynamic_prop prop
;
9415 prop
.kind
= PROP_VARIANT_PARTS
;
9416 prop
.data
.variant_parts
= prop_value
;
9418 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9421 /* Some versions of rustc emitted enums in an unusual way.
9423 Ordinary enums were emitted as unions. The first element of each
9424 structure in the union was named "RUST$ENUM$DISR". This element
9425 held the discriminant.
9427 These versions of Rust also implemented the "non-zero"
9428 optimization. When the enum had two values, and one is empty and
9429 the other holds a pointer that cannot be zero, the pointer is used
9430 as the discriminant, with a zero value meaning the empty variant.
9431 Here, the union's first member is of the form
9432 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9433 where the fieldnos are the indices of the fields that should be
9434 traversed in order to find the field (which may be several fields deep)
9435 and the variantname is the name of the variant of the case when the
9438 This function recognizes whether TYPE is of one of these forms,
9439 and, if so, smashes it to be a variant type. */
9442 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9444 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9446 /* We don't need to deal with empty enums. */
9447 if (type
->num_fields () == 0)
9450 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9451 if (type
->num_fields () == 1
9452 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9454 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9456 /* Decode the field name to find the offset of the
9458 ULONGEST bit_offset
= 0;
9459 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9460 while (name
[0] >= '0' && name
[0] <= '9')
9463 unsigned long index
= strtoul (name
, &tail
, 10);
9466 || index
>= field_type
->num_fields ()
9467 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9468 != FIELD_LOC_KIND_BITPOS
))
9470 complaint (_("Could not parse Rust enum encoding string \"%s\""
9472 TYPE_FIELD_NAME (type
, 0),
9473 objfile_name (objfile
));
9478 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9479 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9482 /* Smash this type to be a structure type. We have to do this
9483 because the type has already been recorded. */
9484 type
->set_code (TYPE_CODE_STRUCT
);
9485 type
->set_num_fields (3);
9486 /* Save the field we care about. */
9487 struct field saved_field
= type
->field (0);
9489 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9491 /* Put the discriminant at index 0. */
9492 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9493 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9494 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9495 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9497 /* The order of fields doesn't really matter, so put the real
9498 field at index 1 and the data-less field at index 2. */
9499 type
->field (1) = saved_field
;
9500 TYPE_FIELD_NAME (type
, 1)
9501 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9502 TYPE_FIELD_TYPE (type
, 1)->set_name
9503 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9504 TYPE_FIELD_NAME (type
, 1)));
9506 const char *dataless_name
9507 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9509 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9511 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9512 /* NAME points into the original discriminant name, which
9513 already has the correct lifetime. */
9514 TYPE_FIELD_NAME (type
, 2) = name
;
9515 SET_FIELD_BITPOS (type
->field (2), 0);
9517 /* Indicate that this is a variant type. */
9518 static discriminant_range ranges
[1] = { { 0, 0 } };
9519 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9521 /* A union with a single anonymous field is probably an old-style
9523 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9525 /* Smash this type to be a structure type. We have to do this
9526 because the type has already been recorded. */
9527 type
->set_code (TYPE_CODE_STRUCT
);
9529 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9530 const char *variant_name
9531 = rust_last_path_segment (field_type
->name ());
9532 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9533 field_type
->set_name
9534 (rust_fully_qualify (&objfile
->objfile_obstack
,
9535 type
->name (), variant_name
));
9539 struct type
*disr_type
= nullptr;
9540 for (int i
= 0; i
< type
->num_fields (); ++i
)
9542 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9544 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9546 /* All fields of a true enum will be structs. */
9549 else if (disr_type
->num_fields () == 0)
9551 /* Could be data-less variant, so keep going. */
9552 disr_type
= nullptr;
9554 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9555 "RUST$ENUM$DISR") != 0)
9557 /* Not a Rust enum. */
9567 /* If we got here without a discriminant, then it's probably
9569 if (disr_type
== nullptr)
9572 /* Smash this type to be a structure type. We have to do this
9573 because the type has already been recorded. */
9574 type
->set_code (TYPE_CODE_STRUCT
);
9576 /* Make space for the discriminant field. */
9577 struct field
*disr_field
= &disr_type
->field (0);
9579 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9580 * sizeof (struct field
)));
9581 memcpy (new_fields
+ 1, type
->fields (),
9582 type
->num_fields () * sizeof (struct field
));
9583 type
->set_fields (new_fields
);
9584 type
->set_num_fields (type
->num_fields () + 1);
9586 /* Install the discriminant at index 0 in the union. */
9587 type
->field (0) = *disr_field
;
9588 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9589 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9591 /* We need a way to find the correct discriminant given a
9592 variant name. For convenience we build a map here. */
9593 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9594 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9595 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9597 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9600 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9601 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9605 int n_fields
= type
->num_fields ();
9606 /* We don't need a range entry for the discriminant, but we do
9607 need one for every other field, as there is no default
9609 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9612 /* Skip the discriminant here. */
9613 for (int i
= 1; i
< n_fields
; ++i
)
9615 /* Find the final word in the name of this variant's type.
9616 That name can be used to look up the correct
9618 const char *variant_name
9619 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9621 auto iter
= discriminant_map
.find (variant_name
);
9622 if (iter
!= discriminant_map
.end ())
9624 ranges
[i
].low
= iter
->second
;
9625 ranges
[i
].high
= iter
->second
;
9628 /* Remove the discriminant field, if it exists. */
9629 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9630 if (sub_type
->num_fields () > 0)
9632 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9633 sub_type
->set_fields (sub_type
->fields () + 1);
9635 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9637 (rust_fully_qualify (&objfile
->objfile_obstack
,
9638 type
->name (), variant_name
));
9641 /* Indicate that this is a variant type. */
9642 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9643 gdb::array_view
<discriminant_range
> (ranges
,
9648 /* Rewrite some Rust unions to be structures with variants parts. */
9651 rust_union_quirks (struct dwarf2_cu
*cu
)
9653 gdb_assert (cu
->language
== language_rust
);
9654 for (type
*type_
: cu
->rust_unions
)
9655 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9656 /* We don't need this any more. */
9657 cu
->rust_unions
.clear ();
9662 type_unit_group_unshareable
*
9663 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9665 auto iter
= this->m_type_units
.find (tu_group
);
9666 if (iter
!= this->m_type_units
.end ())
9667 return iter
->second
.get ();
9669 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9670 type_unit_group_unshareable
*result
= uniq
.get ();
9671 this->m_type_units
[tu_group
] = std::move (uniq
);
9676 dwarf2_per_objfile::get_type_for_signatured_type
9677 (signatured_type
*sig_type
) const
9679 auto iter
= this->m_type_map
.find (sig_type
);
9680 if (iter
== this->m_type_map
.end ())
9683 return iter
->second
;
9686 void dwarf2_per_objfile::set_type_for_signatured_type
9687 (signatured_type
*sig_type
, struct type
*type
)
9689 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9691 this->m_type_map
[sig_type
] = type
;
9694 /* A helper function for computing the list of all symbol tables
9695 included by PER_CU. */
9698 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9699 htab_t all_children
, htab_t all_type_symtabs
,
9700 dwarf2_per_cu_data
*per_cu
,
9701 dwarf2_per_objfile
*per_objfile
,
9702 struct compunit_symtab
*immediate_parent
)
9704 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9707 /* This inclusion and its children have been processed. */
9713 /* Only add a CU if it has a symbol table. */
9714 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9717 /* If this is a type unit only add its symbol table if we haven't
9718 seen it yet (type unit per_cu's can share symtabs). */
9719 if (per_cu
->is_debug_types
)
9721 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9725 result
->push_back (cust
);
9726 if (cust
->user
== NULL
)
9727 cust
->user
= immediate_parent
;
9732 result
->push_back (cust
);
9733 if (cust
->user
== NULL
)
9734 cust
->user
= immediate_parent
;
9738 if (!per_cu
->imported_symtabs_empty ())
9739 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9741 recursively_compute_inclusions (result
, all_children
,
9742 all_type_symtabs
, ptr
, per_objfile
,
9747 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9751 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9752 dwarf2_per_objfile
*per_objfile
)
9754 gdb_assert (! per_cu
->is_debug_types
);
9756 if (!per_cu
->imported_symtabs_empty ())
9759 std::vector
<compunit_symtab
*> result_symtabs
;
9760 htab_t all_children
, all_type_symtabs
;
9761 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9763 /* If we don't have a symtab, we can just skip this case. */
9767 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9768 NULL
, xcalloc
, xfree
);
9769 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9770 NULL
, xcalloc
, xfree
);
9772 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9774 recursively_compute_inclusions (&result_symtabs
, all_children
,
9775 all_type_symtabs
, ptr
, per_objfile
,
9779 /* Now we have a transitive closure of all the included symtabs. */
9780 len
= result_symtabs
.size ();
9782 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9783 struct compunit_symtab
*, len
+ 1);
9784 memcpy (cust
->includes
, result_symtabs
.data (),
9785 len
* sizeof (compunit_symtab
*));
9786 cust
->includes
[len
] = NULL
;
9788 htab_delete (all_children
);
9789 htab_delete (all_type_symtabs
);
9793 /* Compute the 'includes' field for the symtabs of all the CUs we just
9797 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9799 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9801 if (! iter
->is_debug_types
)
9802 compute_compunit_symtab_includes (iter
, per_objfile
);
9805 per_objfile
->per_bfd
->just_read_cus
.clear ();
9808 /* Generate full symbol information for CU, whose DIEs have
9809 already been loaded into memory. */
9812 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9814 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9815 struct objfile
*objfile
= per_objfile
->objfile
;
9816 struct gdbarch
*gdbarch
= objfile
->arch ();
9817 CORE_ADDR lowpc
, highpc
;
9818 struct compunit_symtab
*cust
;
9820 struct block
*static_block
;
9823 baseaddr
= objfile
->text_section_offset ();
9825 /* Clear the list here in case something was left over. */
9826 cu
->method_list
.clear ();
9828 cu
->language
= pretend_language
;
9829 cu
->language_defn
= language_def (cu
->language
);
9831 /* Do line number decoding in read_file_scope () */
9832 process_die (cu
->dies
, cu
);
9834 /* For now fudge the Go package. */
9835 if (cu
->language
== language_go
)
9836 fixup_go_packaging (cu
);
9838 /* Now that we have processed all the DIEs in the CU, all the types
9839 should be complete, and it should now be safe to compute all of the
9841 compute_delayed_physnames (cu
);
9843 if (cu
->language
== language_rust
)
9844 rust_union_quirks (cu
);
9846 /* Some compilers don't define a DW_AT_high_pc attribute for the
9847 compilation unit. If the DW_AT_high_pc is missing, synthesize
9848 it, by scanning the DIE's below the compilation unit. */
9849 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9851 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9852 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9854 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9855 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9856 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9857 addrmap to help ensure it has an accurate map of pc values belonging to
9859 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9861 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9862 SECT_OFF_TEXT (objfile
),
9867 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9869 /* Set symtab language to language from DW_AT_language. If the
9870 compilation is from a C file generated by language preprocessors, do
9871 not set the language if it was already deduced by start_subfile. */
9872 if (!(cu
->language
== language_c
9873 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9874 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9876 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9877 produce DW_AT_location with location lists but it can be possibly
9878 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9879 there were bugs in prologue debug info, fixed later in GCC-4.5
9880 by "unwind info for epilogues" patch (which is not directly related).
9882 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9883 needed, it would be wrong due to missing DW_AT_producer there.
9885 Still one can confuse GDB by using non-standard GCC compilation
9886 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9888 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9889 cust
->locations_valid
= 1;
9891 if (gcc_4_minor
>= 5)
9892 cust
->epilogue_unwind_valid
= 1;
9894 cust
->call_site_htab
= cu
->call_site_htab
;
9897 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9899 /* Push it for inclusion processing later. */
9900 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9902 /* Not needed any more. */
9903 cu
->reset_builder ();
9906 /* Generate full symbol information for type unit CU, whose DIEs have
9907 already been loaded into memory. */
9910 process_full_type_unit (dwarf2_cu
*cu
,
9911 enum language pretend_language
)
9913 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9914 struct objfile
*objfile
= per_objfile
->objfile
;
9915 struct compunit_symtab
*cust
;
9916 struct signatured_type
*sig_type
;
9918 gdb_assert (cu
->per_cu
->is_debug_types
);
9919 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9921 /* Clear the list here in case something was left over. */
9922 cu
->method_list
.clear ();
9924 cu
->language
= pretend_language
;
9925 cu
->language_defn
= language_def (cu
->language
);
9927 /* The symbol tables are set up in read_type_unit_scope. */
9928 process_die (cu
->dies
, cu
);
9930 /* For now fudge the Go package. */
9931 if (cu
->language
== language_go
)
9932 fixup_go_packaging (cu
);
9934 /* Now that we have processed all the DIEs in the CU, all the types
9935 should be complete, and it should now be safe to compute all of the
9937 compute_delayed_physnames (cu
);
9939 if (cu
->language
== language_rust
)
9940 rust_union_quirks (cu
);
9942 /* TUs share symbol tables.
9943 If this is the first TU to use this symtab, complete the construction
9944 of it with end_expandable_symtab. Otherwise, complete the addition of
9945 this TU's symbols to the existing symtab. */
9946 type_unit_group_unshareable
*tug_unshare
=
9947 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9948 if (tug_unshare
->compunit_symtab
== NULL
)
9950 buildsym_compunit
*builder
= cu
->get_builder ();
9951 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9952 tug_unshare
->compunit_symtab
= cust
;
9956 /* Set symtab language to language from DW_AT_language. If the
9957 compilation is from a C file generated by language preprocessors,
9958 do not set the language if it was already deduced by
9960 if (!(cu
->language
== language_c
9961 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9962 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9967 cu
->get_builder ()->augment_type_symtab ();
9968 cust
= tug_unshare
->compunit_symtab
;
9971 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9973 /* Not needed any more. */
9974 cu
->reset_builder ();
9977 /* Process an imported unit DIE. */
9980 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9982 struct attribute
*attr
;
9984 /* For now we don't handle imported units in type units. */
9985 if (cu
->per_cu
->is_debug_types
)
9987 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9988 " supported in type units [in module %s]"),
9989 objfile_name (cu
->per_objfile
->objfile
));
9992 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9995 sect_offset sect_off
= attr
->get_ref_die_offset ();
9996 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9997 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9998 dwarf2_per_cu_data
*per_cu
9999 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10001 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10002 into another compilation unit, at root level. Regard this as a hint,
10004 if (die
->parent
&& die
->parent
->parent
== NULL
10005 && per_cu
->unit_type
== DW_UT_compile
10006 && per_cu
->lang
== language_cplus
)
10009 /* If necessary, add it to the queue and load its DIEs. */
10010 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10011 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
10013 cu
->per_cu
->imported_symtabs_push (per_cu
);
10017 /* RAII object that represents a process_die scope: i.e.,
10018 starts/finishes processing a DIE. */
10019 class process_die_scope
10022 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10023 : m_die (die
), m_cu (cu
)
10025 /* We should only be processing DIEs not already in process. */
10026 gdb_assert (!m_die
->in_process
);
10027 m_die
->in_process
= true;
10030 ~process_die_scope ()
10032 m_die
->in_process
= false;
10034 /* If we're done processing the DIE for the CU that owns the line
10035 header, we don't need the line header anymore. */
10036 if (m_cu
->line_header_die_owner
== m_die
)
10038 delete m_cu
->line_header
;
10039 m_cu
->line_header
= NULL
;
10040 m_cu
->line_header_die_owner
= NULL
;
10049 /* Process a die and its children. */
10052 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10054 process_die_scope
scope (die
, cu
);
10058 case DW_TAG_padding
:
10060 case DW_TAG_compile_unit
:
10061 case DW_TAG_partial_unit
:
10062 read_file_scope (die
, cu
);
10064 case DW_TAG_type_unit
:
10065 read_type_unit_scope (die
, cu
);
10067 case DW_TAG_subprogram
:
10068 /* Nested subprograms in Fortran get a prefix. */
10069 if (cu
->language
== language_fortran
10070 && die
->parent
!= NULL
10071 && die
->parent
->tag
== DW_TAG_subprogram
)
10072 cu
->processing_has_namespace_info
= true;
10073 /* Fall through. */
10074 case DW_TAG_inlined_subroutine
:
10075 read_func_scope (die
, cu
);
10077 case DW_TAG_lexical_block
:
10078 case DW_TAG_try_block
:
10079 case DW_TAG_catch_block
:
10080 read_lexical_block_scope (die
, cu
);
10082 case DW_TAG_call_site
:
10083 case DW_TAG_GNU_call_site
:
10084 read_call_site_scope (die
, cu
);
10086 case DW_TAG_class_type
:
10087 case DW_TAG_interface_type
:
10088 case DW_TAG_structure_type
:
10089 case DW_TAG_union_type
:
10090 process_structure_scope (die
, cu
);
10092 case DW_TAG_enumeration_type
:
10093 process_enumeration_scope (die
, cu
);
10096 /* These dies have a type, but processing them does not create
10097 a symbol or recurse to process the children. Therefore we can
10098 read them on-demand through read_type_die. */
10099 case DW_TAG_subroutine_type
:
10100 case DW_TAG_set_type
:
10101 case DW_TAG_array_type
:
10102 case DW_TAG_pointer_type
:
10103 case DW_TAG_ptr_to_member_type
:
10104 case DW_TAG_reference_type
:
10105 case DW_TAG_rvalue_reference_type
:
10106 case DW_TAG_string_type
:
10109 case DW_TAG_base_type
:
10110 case DW_TAG_subrange_type
:
10111 case DW_TAG_typedef
:
10112 /* Add a typedef symbol for the type definition, if it has a
10114 new_symbol (die
, read_type_die (die
, cu
), cu
);
10116 case DW_TAG_common_block
:
10117 read_common_block (die
, cu
);
10119 case DW_TAG_common_inclusion
:
10121 case DW_TAG_namespace
:
10122 cu
->processing_has_namespace_info
= true;
10123 read_namespace (die
, cu
);
10125 case DW_TAG_module
:
10126 cu
->processing_has_namespace_info
= true;
10127 read_module (die
, cu
);
10129 case DW_TAG_imported_declaration
:
10130 cu
->processing_has_namespace_info
= true;
10131 if (read_namespace_alias (die
, cu
))
10133 /* The declaration is not a global namespace alias. */
10134 /* Fall through. */
10135 case DW_TAG_imported_module
:
10136 cu
->processing_has_namespace_info
= true;
10137 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10138 || cu
->language
!= language_fortran
))
10139 complaint (_("Tag '%s' has unexpected children"),
10140 dwarf_tag_name (die
->tag
));
10141 read_import_statement (die
, cu
);
10144 case DW_TAG_imported_unit
:
10145 process_imported_unit_die (die
, cu
);
10148 case DW_TAG_variable
:
10149 read_variable (die
, cu
);
10153 new_symbol (die
, NULL
, cu
);
10158 /* DWARF name computation. */
10160 /* A helper function for dwarf2_compute_name which determines whether DIE
10161 needs to have the name of the scope prepended to the name listed in the
10165 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10167 struct attribute
*attr
;
10171 case DW_TAG_namespace
:
10172 case DW_TAG_typedef
:
10173 case DW_TAG_class_type
:
10174 case DW_TAG_interface_type
:
10175 case DW_TAG_structure_type
:
10176 case DW_TAG_union_type
:
10177 case DW_TAG_enumeration_type
:
10178 case DW_TAG_enumerator
:
10179 case DW_TAG_subprogram
:
10180 case DW_TAG_inlined_subroutine
:
10181 case DW_TAG_member
:
10182 case DW_TAG_imported_declaration
:
10185 case DW_TAG_variable
:
10186 case DW_TAG_constant
:
10187 /* We only need to prefix "globally" visible variables. These include
10188 any variable marked with DW_AT_external or any variable that
10189 lives in a namespace. [Variables in anonymous namespaces
10190 require prefixing, but they are not DW_AT_external.] */
10192 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10194 struct dwarf2_cu
*spec_cu
= cu
;
10196 return die_needs_namespace (die_specification (die
, &spec_cu
),
10200 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10201 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10202 && die
->parent
->tag
!= DW_TAG_module
)
10204 /* A variable in a lexical block of some kind does not need a
10205 namespace, even though in C++ such variables may be external
10206 and have a mangled name. */
10207 if (die
->parent
->tag
== DW_TAG_lexical_block
10208 || die
->parent
->tag
== DW_TAG_try_block
10209 || die
->parent
->tag
== DW_TAG_catch_block
10210 || die
->parent
->tag
== DW_TAG_subprogram
)
10219 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10220 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10221 defined for the given DIE. */
10223 static struct attribute
*
10224 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10226 struct attribute
*attr
;
10228 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10230 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10235 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10236 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10237 defined for the given DIE. */
10239 static const char *
10240 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10242 const char *linkage_name
;
10244 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10245 if (linkage_name
== NULL
)
10246 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10248 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10249 See https://github.com/rust-lang/rust/issues/32925. */
10250 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10251 && strchr (linkage_name
, '{') != NULL
)
10252 linkage_name
= NULL
;
10254 return linkage_name
;
10257 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10258 compute the physname for the object, which include a method's:
10259 - formal parameters (C++),
10260 - receiver type (Go),
10262 The term "physname" is a bit confusing.
10263 For C++, for example, it is the demangled name.
10264 For Go, for example, it's the mangled name.
10266 For Ada, return the DIE's linkage name rather than the fully qualified
10267 name. PHYSNAME is ignored..
10269 The result is allocated on the objfile->per_bfd's obstack and
10272 static const char *
10273 dwarf2_compute_name (const char *name
,
10274 struct die_info
*die
, struct dwarf2_cu
*cu
,
10277 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10280 name
= dwarf2_name (die
, cu
);
10282 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10283 but otherwise compute it by typename_concat inside GDB.
10284 FIXME: Actually this is not really true, or at least not always true.
10285 It's all very confusing. compute_and_set_names doesn't try to demangle
10286 Fortran names because there is no mangling standard. So new_symbol
10287 will set the demangled name to the result of dwarf2_full_name, and it is
10288 the demangled name that GDB uses if it exists. */
10289 if (cu
->language
== language_ada
10290 || (cu
->language
== language_fortran
&& physname
))
10292 /* For Ada unit, we prefer the linkage name over the name, as
10293 the former contains the exported name, which the user expects
10294 to be able to reference. Ideally, we want the user to be able
10295 to reference this entity using either natural or linkage name,
10296 but we haven't started looking at this enhancement yet. */
10297 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10299 if (linkage_name
!= NULL
)
10300 return linkage_name
;
10303 /* These are the only languages we know how to qualify names in. */
10305 && (cu
->language
== language_cplus
10306 || cu
->language
== language_fortran
|| cu
->language
== language_d
10307 || cu
->language
== language_rust
))
10309 if (die_needs_namespace (die
, cu
))
10311 const char *prefix
;
10312 const char *canonical_name
= NULL
;
10316 prefix
= determine_prefix (die
, cu
);
10317 if (*prefix
!= '\0')
10319 gdb::unique_xmalloc_ptr
<char> prefixed_name
10320 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10322 buf
.puts (prefixed_name
.get ());
10327 /* Template parameters may be specified in the DIE's DW_AT_name, or
10328 as children with DW_TAG_template_type_param or
10329 DW_TAG_value_type_param. If the latter, add them to the name
10330 here. If the name already has template parameters, then
10331 skip this step; some versions of GCC emit both, and
10332 it is more efficient to use the pre-computed name.
10334 Something to keep in mind about this process: it is very
10335 unlikely, or in some cases downright impossible, to produce
10336 something that will match the mangled name of a function.
10337 If the definition of the function has the same debug info,
10338 we should be able to match up with it anyway. But fallbacks
10339 using the minimal symbol, for instance to find a method
10340 implemented in a stripped copy of libstdc++, will not work.
10341 If we do not have debug info for the definition, we will have to
10342 match them up some other way.
10344 When we do name matching there is a related problem with function
10345 templates; two instantiated function templates are allowed to
10346 differ only by their return types, which we do not add here. */
10348 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10350 struct attribute
*attr
;
10351 struct die_info
*child
;
10354 die
->building_fullname
= 1;
10356 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10360 const gdb_byte
*bytes
;
10361 struct dwarf2_locexpr_baton
*baton
;
10364 if (child
->tag
!= DW_TAG_template_type_param
10365 && child
->tag
!= DW_TAG_template_value_param
)
10376 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10379 complaint (_("template parameter missing DW_AT_type"));
10380 buf
.puts ("UNKNOWN_TYPE");
10383 type
= die_type (child
, cu
);
10385 if (child
->tag
== DW_TAG_template_type_param
)
10387 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10388 &type_print_raw_options
);
10392 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10395 complaint (_("template parameter missing "
10396 "DW_AT_const_value"));
10397 buf
.puts ("UNKNOWN_VALUE");
10401 dwarf2_const_value_attr (attr
, type
, name
,
10402 &cu
->comp_unit_obstack
, cu
,
10403 &value
, &bytes
, &baton
);
10405 if (TYPE_NOSIGN (type
))
10406 /* GDB prints characters as NUMBER 'CHAR'. If that's
10407 changed, this can use value_print instead. */
10408 c_printchar (value
, type
, &buf
);
10411 struct value_print_options opts
;
10414 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10418 baton
->per_objfile
);
10419 else if (bytes
!= NULL
)
10421 v
= allocate_value (type
);
10422 memcpy (value_contents_writeable (v
), bytes
,
10423 TYPE_LENGTH (type
));
10426 v
= value_from_longest (type
, value
);
10428 /* Specify decimal so that we do not depend on
10430 get_formatted_print_options (&opts
, 'd');
10432 value_print (v
, &buf
, &opts
);
10437 die
->building_fullname
= 0;
10441 /* Close the argument list, with a space if necessary
10442 (nested templates). */
10443 if (!buf
.empty () && buf
.string ().back () == '>')
10450 /* For C++ methods, append formal parameter type
10451 information, if PHYSNAME. */
10453 if (physname
&& die
->tag
== DW_TAG_subprogram
10454 && cu
->language
== language_cplus
)
10456 struct type
*type
= read_type_die (die
, cu
);
10458 c_type_print_args (type
, &buf
, 1, cu
->language
,
10459 &type_print_raw_options
);
10461 if (cu
->language
== language_cplus
)
10463 /* Assume that an artificial first parameter is
10464 "this", but do not crash if it is not. RealView
10465 marks unnamed (and thus unused) parameters as
10466 artificial; there is no way to differentiate
10468 if (type
->num_fields () > 0
10469 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10470 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10471 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10473 buf
.puts (" const");
10477 const std::string
&intermediate_name
= buf
.string ();
10479 if (cu
->language
== language_cplus
)
10481 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10484 /* If we only computed INTERMEDIATE_NAME, or if
10485 INTERMEDIATE_NAME is already canonical, then we need to
10487 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10488 name
= objfile
->intern (intermediate_name
);
10490 name
= canonical_name
;
10497 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10498 If scope qualifiers are appropriate they will be added. The result
10499 will be allocated on the storage_obstack, or NULL if the DIE does
10500 not have a name. NAME may either be from a previous call to
10501 dwarf2_name or NULL.
10503 The output string will be canonicalized (if C++). */
10505 static const char *
10506 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10508 return dwarf2_compute_name (name
, die
, cu
, 0);
10511 /* Construct a physname for the given DIE in CU. NAME may either be
10512 from a previous call to dwarf2_name or NULL. The result will be
10513 allocated on the objfile_objstack or NULL if the DIE does not have a
10516 The output string will be canonicalized (if C++). */
10518 static const char *
10519 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10521 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10522 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10525 /* In this case dwarf2_compute_name is just a shortcut not building anything
10527 if (!die_needs_namespace (die
, cu
))
10528 return dwarf2_compute_name (name
, die
, cu
, 1);
10530 if (cu
->language
!= language_rust
)
10531 mangled
= dw2_linkage_name (die
, cu
);
10533 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10535 gdb::unique_xmalloc_ptr
<char> demangled
;
10536 if (mangled
!= NULL
)
10539 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10541 /* Do nothing (do not demangle the symbol name). */
10543 else if (cu
->language
== language_go
)
10545 /* This is a lie, but we already lie to the caller new_symbol.
10546 new_symbol assumes we return the mangled name.
10547 This just undoes that lie until things are cleaned up. */
10551 /* Use DMGL_RET_DROP for C++ template functions to suppress
10552 their return type. It is easier for GDB users to search
10553 for such functions as `name(params)' than `long name(params)'.
10554 In such case the minimal symbol names do not match the full
10555 symbol names but for template functions there is never a need
10556 to look up their definition from their declaration so
10557 the only disadvantage remains the minimal symbol variant
10558 `long name(params)' does not have the proper inferior type. */
10559 demangled
.reset (gdb_demangle (mangled
,
10560 (DMGL_PARAMS
| DMGL_ANSI
10561 | DMGL_RET_DROP
)));
10564 canon
= demangled
.get ();
10572 if (canon
== NULL
|| check_physname
)
10574 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10576 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10578 /* It may not mean a bug in GDB. The compiler could also
10579 compute DW_AT_linkage_name incorrectly. But in such case
10580 GDB would need to be bug-to-bug compatible. */
10582 complaint (_("Computed physname <%s> does not match demangled <%s> "
10583 "(from linkage <%s>) - DIE at %s [in module %s]"),
10584 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10585 objfile_name (objfile
));
10587 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10588 is available here - over computed PHYSNAME. It is safer
10589 against both buggy GDB and buggy compilers. */
10603 retval
= objfile
->intern (retval
);
10608 /* Inspect DIE in CU for a namespace alias. If one exists, record
10609 a new symbol for it.
10611 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10614 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10616 struct attribute
*attr
;
10618 /* If the die does not have a name, this is not a namespace
10620 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10624 struct die_info
*d
= die
;
10625 struct dwarf2_cu
*imported_cu
= cu
;
10627 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10628 keep inspecting DIEs until we hit the underlying import. */
10629 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10630 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10632 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10636 d
= follow_die_ref (d
, attr
, &imported_cu
);
10637 if (d
->tag
!= DW_TAG_imported_declaration
)
10641 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10643 complaint (_("DIE at %s has too many recursively imported "
10644 "declarations"), sect_offset_str (d
->sect_off
));
10651 sect_offset sect_off
= attr
->get_ref_die_offset ();
10653 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10654 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10656 /* This declaration is a global namespace alias. Add
10657 a symbol for it whose type is the aliased namespace. */
10658 new_symbol (die
, type
, cu
);
10667 /* Return the using directives repository (global or local?) to use in the
10668 current context for CU.
10670 For Ada, imported declarations can materialize renamings, which *may* be
10671 global. However it is impossible (for now?) in DWARF to distinguish
10672 "external" imported declarations and "static" ones. As all imported
10673 declarations seem to be static in all other languages, make them all CU-wide
10674 global only in Ada. */
10676 static struct using_direct
**
10677 using_directives (struct dwarf2_cu
*cu
)
10679 if (cu
->language
== language_ada
10680 && cu
->get_builder ()->outermost_context_p ())
10681 return cu
->get_builder ()->get_global_using_directives ();
10683 return cu
->get_builder ()->get_local_using_directives ();
10686 /* Read the import statement specified by the given die and record it. */
10689 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10691 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10692 struct attribute
*import_attr
;
10693 struct die_info
*imported_die
, *child_die
;
10694 struct dwarf2_cu
*imported_cu
;
10695 const char *imported_name
;
10696 const char *imported_name_prefix
;
10697 const char *canonical_name
;
10698 const char *import_alias
;
10699 const char *imported_declaration
= NULL
;
10700 const char *import_prefix
;
10701 std::vector
<const char *> excludes
;
10703 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10704 if (import_attr
== NULL
)
10706 complaint (_("Tag '%s' has no DW_AT_import"),
10707 dwarf_tag_name (die
->tag
));
10712 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10713 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10714 if (imported_name
== NULL
)
10716 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10718 The import in the following code:
10732 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10733 <52> DW_AT_decl_file : 1
10734 <53> DW_AT_decl_line : 6
10735 <54> DW_AT_import : <0x75>
10736 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10737 <59> DW_AT_name : B
10738 <5b> DW_AT_decl_file : 1
10739 <5c> DW_AT_decl_line : 2
10740 <5d> DW_AT_type : <0x6e>
10742 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10743 <76> DW_AT_byte_size : 4
10744 <77> DW_AT_encoding : 5 (signed)
10746 imports the wrong die ( 0x75 instead of 0x58 ).
10747 This case will be ignored until the gcc bug is fixed. */
10751 /* Figure out the local name after import. */
10752 import_alias
= dwarf2_name (die
, cu
);
10754 /* Figure out where the statement is being imported to. */
10755 import_prefix
= determine_prefix (die
, cu
);
10757 /* Figure out what the scope of the imported die is and prepend it
10758 to the name of the imported die. */
10759 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10761 if (imported_die
->tag
!= DW_TAG_namespace
10762 && imported_die
->tag
!= DW_TAG_module
)
10764 imported_declaration
= imported_name
;
10765 canonical_name
= imported_name_prefix
;
10767 else if (strlen (imported_name_prefix
) > 0)
10768 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10769 imported_name_prefix
,
10770 (cu
->language
== language_d
? "." : "::"),
10771 imported_name
, (char *) NULL
);
10773 canonical_name
= imported_name
;
10775 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10776 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10777 child_die
= child_die
->sibling
)
10779 /* DWARF-4: A Fortran use statement with a “rename list” may be
10780 represented by an imported module entry with an import attribute
10781 referring to the module and owned entries corresponding to those
10782 entities that are renamed as part of being imported. */
10784 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10786 complaint (_("child DW_TAG_imported_declaration expected "
10787 "- DIE at %s [in module %s]"),
10788 sect_offset_str (child_die
->sect_off
),
10789 objfile_name (objfile
));
10793 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10794 if (import_attr
== NULL
)
10796 complaint (_("Tag '%s' has no DW_AT_import"),
10797 dwarf_tag_name (child_die
->tag
));
10802 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10804 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10805 if (imported_name
== NULL
)
10807 complaint (_("child DW_TAG_imported_declaration has unknown "
10808 "imported name - DIE at %s [in module %s]"),
10809 sect_offset_str (child_die
->sect_off
),
10810 objfile_name (objfile
));
10814 excludes
.push_back (imported_name
);
10816 process_die (child_die
, cu
);
10819 add_using_directive (using_directives (cu
),
10823 imported_declaration
,
10826 &objfile
->objfile_obstack
);
10829 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10830 types, but gives them a size of zero. Starting with version 14,
10831 ICC is compatible with GCC. */
10834 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10836 if (!cu
->checked_producer
)
10837 check_producer (cu
);
10839 return cu
->producer_is_icc_lt_14
;
10842 /* ICC generates a DW_AT_type for C void functions. This was observed on
10843 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10844 which says that void functions should not have a DW_AT_type. */
10847 producer_is_icc (struct dwarf2_cu
*cu
)
10849 if (!cu
->checked_producer
)
10850 check_producer (cu
);
10852 return cu
->producer_is_icc
;
10855 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10856 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10857 this, it was first present in GCC release 4.3.0. */
10860 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10862 if (!cu
->checked_producer
)
10863 check_producer (cu
);
10865 return cu
->producer_is_gcc_lt_4_3
;
10868 static file_and_directory
10869 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10871 file_and_directory res
;
10873 /* Find the filename. Do not use dwarf2_name here, since the filename
10874 is not a source language identifier. */
10875 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10876 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10878 if (res
.comp_dir
== NULL
10879 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10880 && IS_ABSOLUTE_PATH (res
.name
))
10882 res
.comp_dir_storage
= ldirname (res
.name
);
10883 if (!res
.comp_dir_storage
.empty ())
10884 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10886 if (res
.comp_dir
!= NULL
)
10888 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10889 directory, get rid of it. */
10890 const char *cp
= strchr (res
.comp_dir
, ':');
10892 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10893 res
.comp_dir
= cp
+ 1;
10896 if (res
.name
== NULL
)
10897 res
.name
= "<unknown>";
10902 /* Handle DW_AT_stmt_list for a compilation unit.
10903 DIE is the DW_TAG_compile_unit die for CU.
10904 COMP_DIR is the compilation directory. LOWPC is passed to
10905 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10908 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10909 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10911 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10912 struct attribute
*attr
;
10913 struct line_header line_header_local
;
10914 hashval_t line_header_local_hash
;
10916 int decode_mapping
;
10918 gdb_assert (! cu
->per_cu
->is_debug_types
);
10920 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10924 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10926 /* The line header hash table is only created if needed (it exists to
10927 prevent redundant reading of the line table for partial_units).
10928 If we're given a partial_unit, we'll need it. If we're given a
10929 compile_unit, then use the line header hash table if it's already
10930 created, but don't create one just yet. */
10932 if (per_objfile
->line_header_hash
== NULL
10933 && die
->tag
== DW_TAG_partial_unit
)
10935 per_objfile
->line_header_hash
10936 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10937 line_header_eq_voidp
,
10938 free_line_header_voidp
,
10942 line_header_local
.sect_off
= line_offset
;
10943 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10944 line_header_local_hash
= line_header_hash (&line_header_local
);
10945 if (per_objfile
->line_header_hash
!= NULL
)
10947 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10948 &line_header_local
,
10949 line_header_local_hash
, NO_INSERT
);
10951 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10952 is not present in *SLOT (since if there is something in *SLOT then
10953 it will be for a partial_unit). */
10954 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10956 gdb_assert (*slot
!= NULL
);
10957 cu
->line_header
= (struct line_header
*) *slot
;
10962 /* dwarf_decode_line_header does not yet provide sufficient information.
10963 We always have to call also dwarf_decode_lines for it. */
10964 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10968 cu
->line_header
= lh
.release ();
10969 cu
->line_header_die_owner
= die
;
10971 if (per_objfile
->line_header_hash
== NULL
)
10975 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10976 &line_header_local
,
10977 line_header_local_hash
, INSERT
);
10978 gdb_assert (slot
!= NULL
);
10980 if (slot
!= NULL
&& *slot
== NULL
)
10982 /* This newly decoded line number information unit will be owned
10983 by line_header_hash hash table. */
10984 *slot
= cu
->line_header
;
10985 cu
->line_header_die_owner
= NULL
;
10989 /* We cannot free any current entry in (*slot) as that struct line_header
10990 may be already used by multiple CUs. Create only temporary decoded
10991 line_header for this CU - it may happen at most once for each line
10992 number information unit. And if we're not using line_header_hash
10993 then this is what we want as well. */
10994 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10996 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10997 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11002 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11005 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11007 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11008 struct objfile
*objfile
= per_objfile
->objfile
;
11009 struct gdbarch
*gdbarch
= objfile
->arch ();
11010 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11011 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11012 struct attribute
*attr
;
11013 struct die_info
*child_die
;
11014 CORE_ADDR baseaddr
;
11016 prepare_one_comp_unit (cu
, die
, cu
->language
);
11017 baseaddr
= objfile
->text_section_offset ();
11019 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11021 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11022 from finish_block. */
11023 if (lowpc
== ((CORE_ADDR
) -1))
11025 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11027 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11029 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11030 standardised yet. As a workaround for the language detection we fall
11031 back to the DW_AT_producer string. */
11032 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11033 cu
->language
= language_opencl
;
11035 /* Similar hack for Go. */
11036 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11037 set_cu_language (DW_LANG_Go
, cu
);
11039 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11041 /* Decode line number information if present. We do this before
11042 processing child DIEs, so that the line header table is available
11043 for DW_AT_decl_file. */
11044 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11046 /* Process all dies in compilation unit. */
11047 if (die
->child
!= NULL
)
11049 child_die
= die
->child
;
11050 while (child_die
&& child_die
->tag
)
11052 process_die (child_die
, cu
);
11053 child_die
= child_die
->sibling
;
11057 /* Decode macro information, if present. Dwarf 2 macro information
11058 refers to information in the line number info statement program
11059 header, so we can only read it if we've read the header
11061 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11063 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11064 if (attr
&& cu
->line_header
)
11066 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11067 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11069 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11073 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11074 if (attr
&& cu
->line_header
)
11076 unsigned int macro_offset
= DW_UNSND (attr
);
11078 dwarf_decode_macros (cu
, macro_offset
, 0);
11084 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11086 struct type_unit_group
*tu_group
;
11088 struct attribute
*attr
;
11090 struct signatured_type
*sig_type
;
11092 gdb_assert (per_cu
->is_debug_types
);
11093 sig_type
= (struct signatured_type
*) per_cu
;
11095 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11097 /* If we're using .gdb_index (includes -readnow) then
11098 per_cu->type_unit_group may not have been set up yet. */
11099 if (sig_type
->type_unit_group
== NULL
)
11100 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11101 tu_group
= sig_type
->type_unit_group
;
11103 /* If we've already processed this stmt_list there's no real need to
11104 do it again, we could fake it and just recreate the part we need
11105 (file name,index -> symtab mapping). If data shows this optimization
11106 is useful we can do it then. */
11107 type_unit_group_unshareable
*tug_unshare
11108 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11109 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11111 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11116 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11117 lh
= dwarf_decode_line_header (line_offset
, this);
11122 start_symtab ("", NULL
, 0);
11125 gdb_assert (tug_unshare
->symtabs
== NULL
);
11126 gdb_assert (m_builder
== nullptr);
11127 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11128 m_builder
.reset (new struct buildsym_compunit
11129 (COMPUNIT_OBJFILE (cust
), "",
11130 COMPUNIT_DIRNAME (cust
),
11131 compunit_language (cust
),
11133 list_in_scope
= get_builder ()->get_file_symbols ();
11138 line_header
= lh
.release ();
11139 line_header_die_owner
= die
;
11143 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11145 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11146 still initializing it, and our caller (a few levels up)
11147 process_full_type_unit still needs to know if this is the first
11150 tug_unshare
->symtabs
11151 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11152 struct symtab
*, line_header
->file_names_size ());
11154 auto &file_names
= line_header
->file_names ();
11155 for (i
= 0; i
< file_names
.size (); ++i
)
11157 file_entry
&fe
= file_names
[i
];
11158 dwarf2_start_subfile (this, fe
.name
,
11159 fe
.include_dir (line_header
));
11160 buildsym_compunit
*b
= get_builder ();
11161 if (b
->get_current_subfile ()->symtab
== NULL
)
11163 /* NOTE: start_subfile will recognize when it's been
11164 passed a file it has already seen. So we can't
11165 assume there's a simple mapping from
11166 cu->line_header->file_names to subfiles, plus
11167 cu->line_header->file_names may contain dups. */
11168 b
->get_current_subfile ()->symtab
11169 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11172 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11173 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11178 gdb_assert (m_builder
== nullptr);
11179 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11180 m_builder
.reset (new struct buildsym_compunit
11181 (COMPUNIT_OBJFILE (cust
), "",
11182 COMPUNIT_DIRNAME (cust
),
11183 compunit_language (cust
),
11185 list_in_scope
= get_builder ()->get_file_symbols ();
11187 auto &file_names
= line_header
->file_names ();
11188 for (i
= 0; i
< file_names
.size (); ++i
)
11190 file_entry
&fe
= file_names
[i
];
11191 fe
.symtab
= tug_unshare
->symtabs
[i
];
11195 /* The main symtab is allocated last. Type units don't have DW_AT_name
11196 so they don't have a "real" (so to speak) symtab anyway.
11197 There is later code that will assign the main symtab to all symbols
11198 that don't have one. We need to handle the case of a symbol with a
11199 missing symtab (DW_AT_decl_file) anyway. */
11202 /* Process DW_TAG_type_unit.
11203 For TUs we want to skip the first top level sibling if it's not the
11204 actual type being defined by this TU. In this case the first top
11205 level sibling is there to provide context only. */
11208 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11210 struct die_info
*child_die
;
11212 prepare_one_comp_unit (cu
, die
, language_minimal
);
11214 /* Initialize (or reinitialize) the machinery for building symtabs.
11215 We do this before processing child DIEs, so that the line header table
11216 is available for DW_AT_decl_file. */
11217 cu
->setup_type_unit_groups (die
);
11219 if (die
->child
!= NULL
)
11221 child_die
= die
->child
;
11222 while (child_die
&& child_die
->tag
)
11224 process_die (child_die
, cu
);
11225 child_die
= child_die
->sibling
;
11232 http://gcc.gnu.org/wiki/DebugFission
11233 http://gcc.gnu.org/wiki/DebugFissionDWP
11235 To simplify handling of both DWO files ("object" files with the DWARF info)
11236 and DWP files (a file with the DWOs packaged up into one file), we treat
11237 DWP files as having a collection of virtual DWO files. */
11240 hash_dwo_file (const void *item
)
11242 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11245 hash
= htab_hash_string (dwo_file
->dwo_name
);
11246 if (dwo_file
->comp_dir
!= NULL
)
11247 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11252 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11254 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11255 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11257 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11259 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11260 return lhs
->comp_dir
== rhs
->comp_dir
;
11261 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11264 /* Allocate a hash table for DWO files. */
11267 allocate_dwo_file_hash_table ()
11269 auto delete_dwo_file
= [] (void *item
)
11271 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11276 return htab_up (htab_create_alloc (41,
11283 /* Lookup DWO file DWO_NAME. */
11286 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11287 const char *dwo_name
,
11288 const char *comp_dir
)
11290 struct dwo_file find_entry
;
11293 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11294 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11296 find_entry
.dwo_name
= dwo_name
;
11297 find_entry
.comp_dir
= comp_dir
;
11298 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11305 hash_dwo_unit (const void *item
)
11307 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11309 /* This drops the top 32 bits of the id, but is ok for a hash. */
11310 return dwo_unit
->signature
;
11314 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11316 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11317 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11319 /* The signature is assumed to be unique within the DWO file.
11320 So while object file CU dwo_id's always have the value zero,
11321 that's OK, assuming each object file DWO file has only one CU,
11322 and that's the rule for now. */
11323 return lhs
->signature
== rhs
->signature
;
11326 /* Allocate a hash table for DWO CUs,TUs.
11327 There is one of these tables for each of CUs,TUs for each DWO file. */
11330 allocate_dwo_unit_table ()
11332 /* Start out with a pretty small number.
11333 Generally DWO files contain only one CU and maybe some TUs. */
11334 return htab_up (htab_create_alloc (3,
11337 NULL
, xcalloc
, xfree
));
11340 /* die_reader_func for create_dwo_cu. */
11343 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11344 const gdb_byte
*info_ptr
,
11345 struct die_info
*comp_unit_die
,
11346 struct dwo_file
*dwo_file
,
11347 struct dwo_unit
*dwo_unit
)
11349 struct dwarf2_cu
*cu
= reader
->cu
;
11350 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11351 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11353 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11354 if (!signature
.has_value ())
11356 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11357 " its dwo_id [in module %s]"),
11358 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11362 dwo_unit
->dwo_file
= dwo_file
;
11363 dwo_unit
->signature
= *signature
;
11364 dwo_unit
->section
= section
;
11365 dwo_unit
->sect_off
= sect_off
;
11366 dwo_unit
->length
= cu
->per_cu
->length
;
11368 if (dwarf_read_debug
)
11369 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11370 sect_offset_str (sect_off
),
11371 hex_string (dwo_unit
->signature
));
11374 /* Create the dwo_units for the CUs in a DWO_FILE.
11375 Note: This function processes DWO files only, not DWP files. */
11378 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11379 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11380 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11382 struct objfile
*objfile
= per_objfile
->objfile
;
11383 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11384 const gdb_byte
*info_ptr
, *end_ptr
;
11386 section
.read (objfile
);
11387 info_ptr
= section
.buffer
;
11389 if (info_ptr
== NULL
)
11392 if (dwarf_read_debug
)
11394 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11395 section
.get_name (),
11396 section
.get_file_name ());
11399 end_ptr
= info_ptr
+ section
.size
;
11400 while (info_ptr
< end_ptr
)
11402 struct dwarf2_per_cu_data per_cu
;
11403 struct dwo_unit read_unit
{};
11404 struct dwo_unit
*dwo_unit
;
11406 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11408 memset (&per_cu
, 0, sizeof (per_cu
));
11409 per_cu
.per_bfd
= per_bfd
;
11410 per_cu
.is_debug_types
= 0;
11411 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11412 per_cu
.section
= §ion
;
11414 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11415 if (!reader
.dummy_p
)
11416 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11417 &dwo_file
, &read_unit
);
11418 info_ptr
+= per_cu
.length
;
11420 // If the unit could not be parsed, skip it.
11421 if (read_unit
.dwo_file
== NULL
)
11424 if (cus_htab
== NULL
)
11425 cus_htab
= allocate_dwo_unit_table ();
11427 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11429 *dwo_unit
= read_unit
;
11430 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11431 gdb_assert (slot
!= NULL
);
11434 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11435 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11437 complaint (_("debug cu entry at offset %s is duplicate to"
11438 " the entry at offset %s, signature %s"),
11439 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11440 hex_string (dwo_unit
->signature
));
11442 *slot
= (void *)dwo_unit
;
11446 /* DWP file .debug_{cu,tu}_index section format:
11447 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11451 Both index sections have the same format, and serve to map a 64-bit
11452 signature to a set of section numbers. Each section begins with a header,
11453 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11454 indexes, and a pool of 32-bit section numbers. The index sections will be
11455 aligned at 8-byte boundaries in the file.
11457 The index section header consists of:
11459 V, 32 bit version number
11461 N, 32 bit number of compilation units or type units in the index
11462 M, 32 bit number of slots in the hash table
11464 Numbers are recorded using the byte order of the application binary.
11466 The hash table begins at offset 16 in the section, and consists of an array
11467 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11468 order of the application binary). Unused slots in the hash table are 0.
11469 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11471 The parallel table begins immediately after the hash table
11472 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11473 array of 32-bit indexes (using the byte order of the application binary),
11474 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11475 table contains a 32-bit index into the pool of section numbers. For unused
11476 hash table slots, the corresponding entry in the parallel table will be 0.
11478 The pool of section numbers begins immediately following the hash table
11479 (at offset 16 + 12 * M from the beginning of the section). The pool of
11480 section numbers consists of an array of 32-bit words (using the byte order
11481 of the application binary). Each item in the array is indexed starting
11482 from 0. The hash table entry provides the index of the first section
11483 number in the set. Additional section numbers in the set follow, and the
11484 set is terminated by a 0 entry (section number 0 is not used in ELF).
11486 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11487 section must be the first entry in the set, and the .debug_abbrev.dwo must
11488 be the second entry. Other members of the set may follow in any order.
11494 DWP Version 2 combines all the .debug_info, etc. sections into one,
11495 and the entries in the index tables are now offsets into these sections.
11496 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11499 Index Section Contents:
11501 Hash Table of Signatures dwp_hash_table.hash_table
11502 Parallel Table of Indices dwp_hash_table.unit_table
11503 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11504 Table of Section Sizes dwp_hash_table.v2.sizes
11506 The index section header consists of:
11508 V, 32 bit version number
11509 L, 32 bit number of columns in the table of section offsets
11510 N, 32 bit number of compilation units or type units in the index
11511 M, 32 bit number of slots in the hash table
11513 Numbers are recorded using the byte order of the application binary.
11515 The hash table has the same format as version 1.
11516 The parallel table of indices has the same format as version 1,
11517 except that the entries are origin-1 indices into the table of sections
11518 offsets and the table of section sizes.
11520 The table of offsets begins immediately following the parallel table
11521 (at offset 16 + 12 * M from the beginning of the section). The table is
11522 a two-dimensional array of 32-bit words (using the byte order of the
11523 application binary), with L columns and N+1 rows, in row-major order.
11524 Each row in the array is indexed starting from 0. The first row provides
11525 a key to the remaining rows: each column in this row provides an identifier
11526 for a debug section, and the offsets in the same column of subsequent rows
11527 refer to that section. The section identifiers are:
11529 DW_SECT_INFO 1 .debug_info.dwo
11530 DW_SECT_TYPES 2 .debug_types.dwo
11531 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11532 DW_SECT_LINE 4 .debug_line.dwo
11533 DW_SECT_LOC 5 .debug_loc.dwo
11534 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11535 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11536 DW_SECT_MACRO 8 .debug_macro.dwo
11538 The offsets provided by the CU and TU index sections are the base offsets
11539 for the contributions made by each CU or TU to the corresponding section
11540 in the package file. Each CU and TU header contains an abbrev_offset
11541 field, used to find the abbreviations table for that CU or TU within the
11542 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11543 be interpreted as relative to the base offset given in the index section.
11544 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11545 should be interpreted as relative to the base offset for .debug_line.dwo,
11546 and offsets into other debug sections obtained from DWARF attributes should
11547 also be interpreted as relative to the corresponding base offset.
11549 The table of sizes begins immediately following the table of offsets.
11550 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11551 with L columns and N rows, in row-major order. Each row in the array is
11552 indexed starting from 1 (row 0 is shared by the two tables).
11556 Hash table lookup is handled the same in version 1 and 2:
11558 We assume that N and M will not exceed 2^32 - 1.
11559 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11561 Given a 64-bit compilation unit signature or a type signature S, an entry
11562 in the hash table is located as follows:
11564 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11565 the low-order k bits all set to 1.
11567 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11569 3) If the hash table entry at index H matches the signature, use that
11570 entry. If the hash table entry at index H is unused (all zeroes),
11571 terminate the search: the signature is not present in the table.
11573 4) Let H = (H + H') modulo M. Repeat at Step 3.
11575 Because M > N and H' and M are relatively prime, the search is guaranteed
11576 to stop at an unused slot or find the match. */
11578 /* Create a hash table to map DWO IDs to their CU/TU entry in
11579 .debug_{info,types}.dwo in DWP_FILE.
11580 Returns NULL if there isn't one.
11581 Note: This function processes DWP files only, not DWO files. */
11583 static struct dwp_hash_table
*
11584 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11585 struct dwp_file
*dwp_file
, int is_debug_types
)
11587 struct objfile
*objfile
= per_objfile
->objfile
;
11588 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11589 const gdb_byte
*index_ptr
, *index_end
;
11590 struct dwarf2_section_info
*index
;
11591 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11592 struct dwp_hash_table
*htab
;
11594 if (is_debug_types
)
11595 index
= &dwp_file
->sections
.tu_index
;
11597 index
= &dwp_file
->sections
.cu_index
;
11599 if (index
->empty ())
11601 index
->read (objfile
);
11603 index_ptr
= index
->buffer
;
11604 index_end
= index_ptr
+ index
->size
;
11606 version
= read_4_bytes (dbfd
, index_ptr
);
11609 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11613 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11615 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11618 if (version
!= 1 && version
!= 2)
11620 error (_("Dwarf Error: unsupported DWP file version (%s)"
11621 " [in module %s]"),
11622 pulongest (version
), dwp_file
->name
);
11624 if (nr_slots
!= (nr_slots
& -nr_slots
))
11626 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11627 " is not power of 2 [in module %s]"),
11628 pulongest (nr_slots
), dwp_file
->name
);
11631 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11632 htab
->version
= version
;
11633 htab
->nr_columns
= nr_columns
;
11634 htab
->nr_units
= nr_units
;
11635 htab
->nr_slots
= nr_slots
;
11636 htab
->hash_table
= index_ptr
;
11637 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11639 /* Exit early if the table is empty. */
11640 if (nr_slots
== 0 || nr_units
== 0
11641 || (version
== 2 && nr_columns
== 0))
11643 /* All must be zero. */
11644 if (nr_slots
!= 0 || nr_units
!= 0
11645 || (version
== 2 && nr_columns
!= 0))
11647 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11648 " all zero [in modules %s]"),
11656 htab
->section_pool
.v1
.indices
=
11657 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11658 /* It's harder to decide whether the section is too small in v1.
11659 V1 is deprecated anyway so we punt. */
11663 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11664 int *ids
= htab
->section_pool
.v2
.section_ids
;
11665 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11666 /* Reverse map for error checking. */
11667 int ids_seen
[DW_SECT_MAX
+ 1];
11670 if (nr_columns
< 2)
11672 error (_("Dwarf Error: bad DWP hash table, too few columns"
11673 " in section table [in module %s]"),
11676 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11678 error (_("Dwarf Error: bad DWP hash table, too many columns"
11679 " in section table [in module %s]"),
11682 memset (ids
, 255, sizeof_ids
);
11683 memset (ids_seen
, 255, sizeof (ids_seen
));
11684 for (i
= 0; i
< nr_columns
; ++i
)
11686 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11688 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11690 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11691 " in section table [in module %s]"),
11692 id
, dwp_file
->name
);
11694 if (ids_seen
[id
] != -1)
11696 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11697 " id %d in section table [in module %s]"),
11698 id
, dwp_file
->name
);
11703 /* Must have exactly one info or types section. */
11704 if (((ids_seen
[DW_SECT_INFO
] != -1)
11705 + (ids_seen
[DW_SECT_TYPES
] != -1))
11708 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11709 " DWO info/types section [in module %s]"),
11712 /* Must have an abbrev section. */
11713 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11715 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11716 " section [in module %s]"),
11719 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11720 htab
->section_pool
.v2
.sizes
=
11721 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11722 * nr_units
* nr_columns
);
11723 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11724 * nr_units
* nr_columns
))
11727 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11728 " [in module %s]"),
11736 /* Update SECTIONS with the data from SECTP.
11738 This function is like the other "locate" section routines that are
11739 passed to bfd_map_over_sections, but in this context the sections to
11740 read comes from the DWP V1 hash table, not the full ELF section table.
11742 The result is non-zero for success, or zero if an error was found. */
11745 locate_v1_virtual_dwo_sections (asection
*sectp
,
11746 struct virtual_v1_dwo_sections
*sections
)
11748 const struct dwop_section_names
*names
= &dwop_section_names
;
11750 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11752 /* There can be only one. */
11753 if (sections
->abbrev
.s
.section
!= NULL
)
11755 sections
->abbrev
.s
.section
= sectp
;
11756 sections
->abbrev
.size
= bfd_section_size (sectp
);
11758 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11759 || section_is_p (sectp
->name
, &names
->types_dwo
))
11761 /* There can be only one. */
11762 if (sections
->info_or_types
.s
.section
!= NULL
)
11764 sections
->info_or_types
.s
.section
= sectp
;
11765 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11767 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11769 /* There can be only one. */
11770 if (sections
->line
.s
.section
!= NULL
)
11772 sections
->line
.s
.section
= sectp
;
11773 sections
->line
.size
= bfd_section_size (sectp
);
11775 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11777 /* There can be only one. */
11778 if (sections
->loc
.s
.section
!= NULL
)
11780 sections
->loc
.s
.section
= sectp
;
11781 sections
->loc
.size
= bfd_section_size (sectp
);
11783 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11785 /* There can be only one. */
11786 if (sections
->macinfo
.s
.section
!= NULL
)
11788 sections
->macinfo
.s
.section
= sectp
;
11789 sections
->macinfo
.size
= bfd_section_size (sectp
);
11791 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11793 /* There can be only one. */
11794 if (sections
->macro
.s
.section
!= NULL
)
11796 sections
->macro
.s
.section
= sectp
;
11797 sections
->macro
.size
= bfd_section_size (sectp
);
11799 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11801 /* There can be only one. */
11802 if (sections
->str_offsets
.s
.section
!= NULL
)
11804 sections
->str_offsets
.s
.section
= sectp
;
11805 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11809 /* No other kind of section is valid. */
11816 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11817 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11818 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11819 This is for DWP version 1 files. */
11821 static struct dwo_unit
*
11822 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11823 struct dwp_file
*dwp_file
,
11824 uint32_t unit_index
,
11825 const char *comp_dir
,
11826 ULONGEST signature
, int is_debug_types
)
11828 const struct dwp_hash_table
*dwp_htab
=
11829 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11830 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11831 const char *kind
= is_debug_types
? "TU" : "CU";
11832 struct dwo_file
*dwo_file
;
11833 struct dwo_unit
*dwo_unit
;
11834 struct virtual_v1_dwo_sections sections
;
11835 void **dwo_file_slot
;
11838 gdb_assert (dwp_file
->version
== 1);
11840 if (dwarf_read_debug
)
11842 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11844 pulongest (unit_index
), hex_string (signature
),
11848 /* Fetch the sections of this DWO unit.
11849 Put a limit on the number of sections we look for so that bad data
11850 doesn't cause us to loop forever. */
11852 #define MAX_NR_V1_DWO_SECTIONS \
11853 (1 /* .debug_info or .debug_types */ \
11854 + 1 /* .debug_abbrev */ \
11855 + 1 /* .debug_line */ \
11856 + 1 /* .debug_loc */ \
11857 + 1 /* .debug_str_offsets */ \
11858 + 1 /* .debug_macro or .debug_macinfo */ \
11859 + 1 /* trailing zero */)
11861 memset (§ions
, 0, sizeof (sections
));
11863 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11866 uint32_t section_nr
=
11867 read_4_bytes (dbfd
,
11868 dwp_htab
->section_pool
.v1
.indices
11869 + (unit_index
+ i
) * sizeof (uint32_t));
11871 if (section_nr
== 0)
11873 if (section_nr
>= dwp_file
->num_sections
)
11875 error (_("Dwarf Error: bad DWP hash table, section number too large"
11876 " [in module %s]"),
11880 sectp
= dwp_file
->elf_sections
[section_nr
];
11881 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11883 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11884 " [in module %s]"),
11890 || sections
.info_or_types
.empty ()
11891 || sections
.abbrev
.empty ())
11893 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11894 " [in module %s]"),
11897 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11899 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11900 " [in module %s]"),
11904 /* It's easier for the rest of the code if we fake a struct dwo_file and
11905 have dwo_unit "live" in that. At least for now.
11907 The DWP file can be made up of a random collection of CUs and TUs.
11908 However, for each CU + set of TUs that came from the same original DWO
11909 file, we can combine them back into a virtual DWO file to save space
11910 (fewer struct dwo_file objects to allocate). Remember that for really
11911 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11913 std::string virtual_dwo_name
=
11914 string_printf ("virtual-dwo/%d-%d-%d-%d",
11915 sections
.abbrev
.get_id (),
11916 sections
.line
.get_id (),
11917 sections
.loc
.get_id (),
11918 sections
.str_offsets
.get_id ());
11919 /* Can we use an existing virtual DWO file? */
11920 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11922 /* Create one if necessary. */
11923 if (*dwo_file_slot
== NULL
)
11925 if (dwarf_read_debug
)
11927 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11928 virtual_dwo_name
.c_str ());
11930 dwo_file
= new struct dwo_file
;
11931 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11932 dwo_file
->comp_dir
= comp_dir
;
11933 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11934 dwo_file
->sections
.line
= sections
.line
;
11935 dwo_file
->sections
.loc
= sections
.loc
;
11936 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11937 dwo_file
->sections
.macro
= sections
.macro
;
11938 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11939 /* The "str" section is global to the entire DWP file. */
11940 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11941 /* The info or types section is assigned below to dwo_unit,
11942 there's no need to record it in dwo_file.
11943 Also, we can't simply record type sections in dwo_file because
11944 we record a pointer into the vector in dwo_unit. As we collect more
11945 types we'll grow the vector and eventually have to reallocate space
11946 for it, invalidating all copies of pointers into the previous
11948 *dwo_file_slot
= dwo_file
;
11952 if (dwarf_read_debug
)
11954 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11955 virtual_dwo_name
.c_str ());
11957 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11960 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11961 dwo_unit
->dwo_file
= dwo_file
;
11962 dwo_unit
->signature
= signature
;
11963 dwo_unit
->section
=
11964 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11965 *dwo_unit
->section
= sections
.info_or_types
;
11966 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11971 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11972 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11973 piece within that section used by a TU/CU, return a virtual section
11974 of just that piece. */
11976 static struct dwarf2_section_info
11977 create_dwp_v2_section (dwarf2_per_objfile
*per_objfile
,
11978 struct dwarf2_section_info
*section
,
11979 bfd_size_type offset
, bfd_size_type size
)
11981 struct dwarf2_section_info result
;
11984 gdb_assert (section
!= NULL
);
11985 gdb_assert (!section
->is_virtual
);
11987 memset (&result
, 0, sizeof (result
));
11988 result
.s
.containing_section
= section
;
11989 result
.is_virtual
= true;
11994 sectp
= section
->get_bfd_section ();
11996 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11997 bounds of the real section. This is a pretty-rare event, so just
11998 flag an error (easier) instead of a warning and trying to cope. */
12000 || offset
+ size
> bfd_section_size (sectp
))
12002 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12003 " in section %s [in module %s]"),
12004 sectp
? bfd_section_name (sectp
) : "<unknown>",
12005 objfile_name (per_objfile
->objfile
));
12008 result
.virtual_offset
= offset
;
12009 result
.size
= size
;
12013 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12014 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12015 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12016 This is for DWP version 2 files. */
12018 static struct dwo_unit
*
12019 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12020 struct dwp_file
*dwp_file
,
12021 uint32_t unit_index
,
12022 const char *comp_dir
,
12023 ULONGEST signature
, int is_debug_types
)
12025 const struct dwp_hash_table
*dwp_htab
=
12026 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12027 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12028 const char *kind
= is_debug_types
? "TU" : "CU";
12029 struct dwo_file
*dwo_file
;
12030 struct dwo_unit
*dwo_unit
;
12031 struct virtual_v2_dwo_sections sections
;
12032 void **dwo_file_slot
;
12035 gdb_assert (dwp_file
->version
== 2);
12037 if (dwarf_read_debug
)
12039 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12041 pulongest (unit_index
), hex_string (signature
),
12045 /* Fetch the section offsets of this DWO unit. */
12047 memset (§ions
, 0, sizeof (sections
));
12049 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12051 uint32_t offset
= read_4_bytes (dbfd
,
12052 dwp_htab
->section_pool
.v2
.offsets
12053 + (((unit_index
- 1) * dwp_htab
->nr_columns
12055 * sizeof (uint32_t)));
12056 uint32_t size
= read_4_bytes (dbfd
,
12057 dwp_htab
->section_pool
.v2
.sizes
12058 + (((unit_index
- 1) * dwp_htab
->nr_columns
12060 * sizeof (uint32_t)));
12062 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12065 case DW_SECT_TYPES
:
12066 sections
.info_or_types_offset
= offset
;
12067 sections
.info_or_types_size
= size
;
12069 case DW_SECT_ABBREV
:
12070 sections
.abbrev_offset
= offset
;
12071 sections
.abbrev_size
= size
;
12074 sections
.line_offset
= offset
;
12075 sections
.line_size
= size
;
12078 sections
.loc_offset
= offset
;
12079 sections
.loc_size
= size
;
12081 case DW_SECT_STR_OFFSETS
:
12082 sections
.str_offsets_offset
= offset
;
12083 sections
.str_offsets_size
= size
;
12085 case DW_SECT_MACINFO
:
12086 sections
.macinfo_offset
= offset
;
12087 sections
.macinfo_size
= size
;
12089 case DW_SECT_MACRO
:
12090 sections
.macro_offset
= offset
;
12091 sections
.macro_size
= size
;
12096 /* It's easier for the rest of the code if we fake a struct dwo_file and
12097 have dwo_unit "live" in that. At least for now.
12099 The DWP file can be made up of a random collection of CUs and TUs.
12100 However, for each CU + set of TUs that came from the same original DWO
12101 file, we can combine them back into a virtual DWO file to save space
12102 (fewer struct dwo_file objects to allocate). Remember that for really
12103 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12105 std::string virtual_dwo_name
=
12106 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12107 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12108 (long) (sections
.line_size
? sections
.line_offset
: 0),
12109 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12110 (long) (sections
.str_offsets_size
12111 ? sections
.str_offsets_offset
: 0));
12112 /* Can we use an existing virtual DWO file? */
12113 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12115 /* Create one if necessary. */
12116 if (*dwo_file_slot
== NULL
)
12118 if (dwarf_read_debug
)
12120 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12121 virtual_dwo_name
.c_str ());
12123 dwo_file
= new struct dwo_file
;
12124 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12125 dwo_file
->comp_dir
= comp_dir
;
12126 dwo_file
->sections
.abbrev
=
12127 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12128 sections
.abbrev_offset
, sections
.abbrev_size
);
12129 dwo_file
->sections
.line
=
12130 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.line
,
12131 sections
.line_offset
, sections
.line_size
);
12132 dwo_file
->sections
.loc
=
12133 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.loc
,
12134 sections
.loc_offset
, sections
.loc_size
);
12135 dwo_file
->sections
.macinfo
=
12136 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12137 sections
.macinfo_offset
, sections
.macinfo_size
);
12138 dwo_file
->sections
.macro
=
12139 create_dwp_v2_section (per_objfile
, &dwp_file
->sections
.macro
,
12140 sections
.macro_offset
, sections
.macro_size
);
12141 dwo_file
->sections
.str_offsets
=
12142 create_dwp_v2_section (per_objfile
,
12143 &dwp_file
->sections
.str_offsets
,
12144 sections
.str_offsets_offset
,
12145 sections
.str_offsets_size
);
12146 /* The "str" section is global to the entire DWP file. */
12147 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12148 /* The info or types section is assigned below to dwo_unit,
12149 there's no need to record it in dwo_file.
12150 Also, we can't simply record type sections in dwo_file because
12151 we record a pointer into the vector in dwo_unit. As we collect more
12152 types we'll grow the vector and eventually have to reallocate space
12153 for it, invalidating all copies of pointers into the previous
12155 *dwo_file_slot
= dwo_file
;
12159 if (dwarf_read_debug
)
12161 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12162 virtual_dwo_name
.c_str ());
12164 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12167 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12168 dwo_unit
->dwo_file
= dwo_file
;
12169 dwo_unit
->signature
= signature
;
12170 dwo_unit
->section
=
12171 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12172 *dwo_unit
->section
= create_dwp_v2_section (per_objfile
,
12174 ? &dwp_file
->sections
.types
12175 : &dwp_file
->sections
.info
,
12176 sections
.info_or_types_offset
,
12177 sections
.info_or_types_size
);
12178 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12183 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12184 Returns NULL if the signature isn't found. */
12186 static struct dwo_unit
*
12187 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12188 struct dwp_file
*dwp_file
, const char *comp_dir
,
12189 ULONGEST signature
, int is_debug_types
)
12191 const struct dwp_hash_table
*dwp_htab
=
12192 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12193 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12194 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12195 uint32_t hash
= signature
& mask
;
12196 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12199 struct dwo_unit find_dwo_cu
;
12201 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12202 find_dwo_cu
.signature
= signature
;
12203 slot
= htab_find_slot (is_debug_types
12204 ? dwp_file
->loaded_tus
.get ()
12205 : dwp_file
->loaded_cus
.get (),
12206 &find_dwo_cu
, INSERT
);
12209 return (struct dwo_unit
*) *slot
;
12211 /* Use a for loop so that we don't loop forever on bad debug info. */
12212 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12214 ULONGEST signature_in_table
;
12216 signature_in_table
=
12217 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12218 if (signature_in_table
== signature
)
12220 uint32_t unit_index
=
12221 read_4_bytes (dbfd
,
12222 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12224 if (dwp_file
->version
== 1)
12226 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12227 unit_index
, comp_dir
,
12228 signature
, is_debug_types
);
12232 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12233 unit_index
, comp_dir
,
12234 signature
, is_debug_types
);
12236 return (struct dwo_unit
*) *slot
;
12238 if (signature_in_table
== 0)
12240 hash
= (hash
+ hash2
) & mask
;
12243 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12244 " [in module %s]"),
12248 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12249 Open the file specified by FILE_NAME and hand it off to BFD for
12250 preliminary analysis. Return a newly initialized bfd *, which
12251 includes a canonicalized copy of FILE_NAME.
12252 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12253 SEARCH_CWD is true if the current directory is to be searched.
12254 It will be searched before debug-file-directory.
12255 If successful, the file is added to the bfd include table of the
12256 objfile's bfd (see gdb_bfd_record_inclusion).
12257 If unable to find/open the file, return NULL.
12258 NOTE: This function is derived from symfile_bfd_open. */
12260 static gdb_bfd_ref_ptr
12261 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12262 const char *file_name
, int is_dwp
, int search_cwd
)
12265 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12266 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12267 to debug_file_directory. */
12268 const char *search_path
;
12269 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12271 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12274 if (*debug_file_directory
!= '\0')
12276 search_path_holder
.reset (concat (".", dirname_separator_string
,
12277 debug_file_directory
,
12279 search_path
= search_path_holder
.get ();
12285 search_path
= debug_file_directory
;
12287 openp_flags flags
= OPF_RETURN_REALPATH
;
12289 flags
|= OPF_SEARCH_IN_PATH
;
12291 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12292 desc
= openp (search_path
, flags
, file_name
,
12293 O_RDONLY
| O_BINARY
, &absolute_name
);
12297 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12299 if (sym_bfd
== NULL
)
12301 bfd_set_cacheable (sym_bfd
.get (), 1);
12303 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12306 /* Success. Record the bfd as having been included by the objfile's bfd.
12307 This is important because things like demangled_names_hash lives in the
12308 objfile's per_bfd space and may have references to things like symbol
12309 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12310 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12315 /* Try to open DWO file FILE_NAME.
12316 COMP_DIR is the DW_AT_comp_dir attribute.
12317 The result is the bfd handle of the file.
12318 If there is a problem finding or opening the file, return NULL.
12319 Upon success, the canonicalized path of the file is stored in the bfd,
12320 same as symfile_bfd_open. */
12322 static gdb_bfd_ref_ptr
12323 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12324 const char *file_name
, const char *comp_dir
)
12326 if (IS_ABSOLUTE_PATH (file_name
))
12327 return try_open_dwop_file (per_objfile
, file_name
,
12328 0 /*is_dwp*/, 0 /*search_cwd*/);
12330 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12332 if (comp_dir
!= NULL
)
12334 gdb::unique_xmalloc_ptr
<char> path_to_try
12335 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12337 /* NOTE: If comp_dir is a relative path, this will also try the
12338 search path, which seems useful. */
12339 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12341 1 /*search_cwd*/));
12346 /* That didn't work, try debug-file-directory, which, despite its name,
12347 is a list of paths. */
12349 if (*debug_file_directory
== '\0')
12352 return try_open_dwop_file (per_objfile
, file_name
,
12353 0 /*is_dwp*/, 1 /*search_cwd*/);
12356 /* This function is mapped across the sections and remembers the offset and
12357 size of each of the DWO debugging sections we are interested in. */
12360 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12362 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12363 const struct dwop_section_names
*names
= &dwop_section_names
;
12365 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12367 dwo_sections
->abbrev
.s
.section
= sectp
;
12368 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12370 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12372 dwo_sections
->info
.s
.section
= sectp
;
12373 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12375 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12377 dwo_sections
->line
.s
.section
= sectp
;
12378 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12380 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12382 dwo_sections
->loc
.s
.section
= sectp
;
12383 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12385 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12387 dwo_sections
->loclists
.s
.section
= sectp
;
12388 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12390 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12392 dwo_sections
->macinfo
.s
.section
= sectp
;
12393 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12395 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12397 dwo_sections
->macro
.s
.section
= sectp
;
12398 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12400 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12402 dwo_sections
->str
.s
.section
= sectp
;
12403 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12405 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12407 dwo_sections
->str_offsets
.s
.section
= sectp
;
12408 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12410 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12412 struct dwarf2_section_info type_section
;
12414 memset (&type_section
, 0, sizeof (type_section
));
12415 type_section
.s
.section
= sectp
;
12416 type_section
.size
= bfd_section_size (sectp
);
12417 dwo_sections
->types
.push_back (type_section
);
12421 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12422 by PER_CU. This is for the non-DWP case.
12423 The result is NULL if DWO_NAME can't be found. */
12425 static struct dwo_file
*
12426 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12427 const char *comp_dir
)
12429 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12431 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12434 if (dwarf_read_debug
)
12435 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12439 dwo_file_up
dwo_file (new struct dwo_file
);
12440 dwo_file
->dwo_name
= dwo_name
;
12441 dwo_file
->comp_dir
= comp_dir
;
12442 dwo_file
->dbfd
= std::move (dbfd
);
12444 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12445 &dwo_file
->sections
);
12447 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12450 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12451 dwo_file
->sections
.types
, dwo_file
->tus
);
12453 if (dwarf_read_debug
)
12454 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12456 return dwo_file
.release ();
12459 /* This function is mapped across the sections and remembers the offset and
12460 size of each of the DWP debugging sections common to version 1 and 2 that
12461 we are interested in. */
12464 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12465 void *dwp_file_ptr
)
12467 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12468 const struct dwop_section_names
*names
= &dwop_section_names
;
12469 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12471 /* Record the ELF section number for later lookup: this is what the
12472 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12473 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12474 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12476 /* Look for specific sections that we need. */
12477 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12479 dwp_file
->sections
.str
.s
.section
= sectp
;
12480 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12482 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12484 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12485 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12487 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12489 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12490 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12494 /* This function is mapped across the sections and remembers the offset and
12495 size of each of the DWP version 2 debugging sections that we are interested
12496 in. This is split into a separate function because we don't know if we
12497 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12500 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12502 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12503 const struct dwop_section_names
*names
= &dwop_section_names
;
12504 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12506 /* Record the ELF section number for later lookup: this is what the
12507 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12508 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12509 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12511 /* Look for specific sections that we need. */
12512 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12514 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12515 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12517 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12519 dwp_file
->sections
.info
.s
.section
= sectp
;
12520 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12522 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12524 dwp_file
->sections
.line
.s
.section
= sectp
;
12525 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12527 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12529 dwp_file
->sections
.loc
.s
.section
= sectp
;
12530 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12532 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12534 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12535 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12537 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12539 dwp_file
->sections
.macro
.s
.section
= sectp
;
12540 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12542 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12544 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12545 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12547 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12549 dwp_file
->sections
.types
.s
.section
= sectp
;
12550 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12554 /* Hash function for dwp_file loaded CUs/TUs. */
12557 hash_dwp_loaded_cutus (const void *item
)
12559 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12561 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12562 return dwo_unit
->signature
;
12565 /* Equality function for dwp_file loaded CUs/TUs. */
12568 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12570 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12571 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12573 return dua
->signature
== dub
->signature
;
12576 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12579 allocate_dwp_loaded_cutus_table ()
12581 return htab_up (htab_create_alloc (3,
12582 hash_dwp_loaded_cutus
,
12583 eq_dwp_loaded_cutus
,
12584 NULL
, xcalloc
, xfree
));
12587 /* Try to open DWP file FILE_NAME.
12588 The result is the bfd handle of the file.
12589 If there is a problem finding or opening the file, return NULL.
12590 Upon success, the canonicalized path of the file is stored in the bfd,
12591 same as symfile_bfd_open. */
12593 static gdb_bfd_ref_ptr
12594 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12596 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12598 1 /*search_cwd*/));
12602 /* Work around upstream bug 15652.
12603 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12604 [Whether that's a "bug" is debatable, but it is getting in our way.]
12605 We have no real idea where the dwp file is, because gdb's realpath-ing
12606 of the executable's path may have discarded the needed info.
12607 [IWBN if the dwp file name was recorded in the executable, akin to
12608 .gnu_debuglink, but that doesn't exist yet.]
12609 Strip the directory from FILE_NAME and search again. */
12610 if (*debug_file_directory
!= '\0')
12612 /* Don't implicitly search the current directory here.
12613 If the user wants to search "." to handle this case,
12614 it must be added to debug-file-directory. */
12615 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12623 /* Initialize the use of the DWP file for the current objfile.
12624 By convention the name of the DWP file is ${objfile}.dwp.
12625 The result is NULL if it can't be found. */
12627 static std::unique_ptr
<struct dwp_file
>
12628 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12630 struct objfile
*objfile
= per_objfile
->objfile
;
12632 /* Try to find first .dwp for the binary file before any symbolic links
12635 /* If the objfile is a debug file, find the name of the real binary
12636 file and get the name of dwp file from there. */
12637 std::string dwp_name
;
12638 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12640 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12641 const char *backlink_basename
= lbasename (backlink
->original_name
);
12643 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12646 dwp_name
= objfile
->original_name
;
12648 dwp_name
+= ".dwp";
12650 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12652 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12654 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12655 dwp_name
= objfile_name (objfile
);
12656 dwp_name
+= ".dwp";
12657 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12662 if (dwarf_read_debug
)
12663 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12664 return std::unique_ptr
<dwp_file
> ();
12667 const char *name
= bfd_get_filename (dbfd
.get ());
12668 std::unique_ptr
<struct dwp_file
> dwp_file
12669 (new struct dwp_file (name
, std::move (dbfd
)));
12671 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12672 dwp_file
->elf_sections
=
12673 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12674 dwp_file
->num_sections
, asection
*);
12676 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12677 dwarf2_locate_common_dwp_sections
,
12680 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12682 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12684 /* The DWP file version is stored in the hash table. Oh well. */
12685 if (dwp_file
->cus
&& dwp_file
->tus
12686 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12688 /* Technically speaking, we should try to limp along, but this is
12689 pretty bizarre. We use pulongest here because that's the established
12690 portability solution (e.g, we cannot use %u for uint32_t). */
12691 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12692 " TU version %s [in DWP file %s]"),
12693 pulongest (dwp_file
->cus
->version
),
12694 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12698 dwp_file
->version
= dwp_file
->cus
->version
;
12699 else if (dwp_file
->tus
)
12700 dwp_file
->version
= dwp_file
->tus
->version
;
12702 dwp_file
->version
= 2;
12704 if (dwp_file
->version
== 2)
12705 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12706 dwarf2_locate_v2_dwp_sections
,
12709 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12710 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12712 if (dwarf_read_debug
)
12714 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12715 fprintf_unfiltered (gdb_stdlog
,
12716 " %s CUs, %s TUs\n",
12717 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12718 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12724 /* Wrapper around open_and_init_dwp_file, only open it once. */
12726 static struct dwp_file
*
12727 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12729 if (!per_objfile
->per_bfd
->dwp_checked
)
12731 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12732 per_objfile
->per_bfd
->dwp_checked
= 1;
12734 return per_objfile
->per_bfd
->dwp_file
.get ();
12737 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12738 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12739 or in the DWP file for the objfile, referenced by THIS_UNIT.
12740 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12741 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12743 This is called, for example, when wanting to read a variable with a
12744 complex location. Therefore we don't want to do file i/o for every call.
12745 Therefore we don't want to look for a DWO file on every call.
12746 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12747 then we check if we've already seen DWO_NAME, and only THEN do we check
12750 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12751 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12753 static struct dwo_unit
*
12754 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12755 ULONGEST signature
, int is_debug_types
)
12757 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12758 struct objfile
*objfile
= per_objfile
->objfile
;
12759 const char *kind
= is_debug_types
? "TU" : "CU";
12760 void **dwo_file_slot
;
12761 struct dwo_file
*dwo_file
;
12762 struct dwp_file
*dwp_file
;
12764 /* First see if there's a DWP file.
12765 If we have a DWP file but didn't find the DWO inside it, don't
12766 look for the original DWO file. It makes gdb behave differently
12767 depending on whether one is debugging in the build tree. */
12769 dwp_file
= get_dwp_file (per_objfile
);
12770 if (dwp_file
!= NULL
)
12772 const struct dwp_hash_table
*dwp_htab
=
12773 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12775 if (dwp_htab
!= NULL
)
12777 struct dwo_unit
*dwo_cutu
=
12778 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12781 if (dwo_cutu
!= NULL
)
12783 if (dwarf_read_debug
)
12785 fprintf_unfiltered (gdb_stdlog
,
12786 "Virtual DWO %s %s found: @%s\n",
12787 kind
, hex_string (signature
),
12788 host_address_to_string (dwo_cutu
));
12796 /* No DWP file, look for the DWO file. */
12798 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12799 if (*dwo_file_slot
== NULL
)
12801 /* Read in the file and build a table of the CUs/TUs it contains. */
12802 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12804 /* NOTE: This will be NULL if unable to open the file. */
12805 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12807 if (dwo_file
!= NULL
)
12809 struct dwo_unit
*dwo_cutu
= NULL
;
12811 if (is_debug_types
&& dwo_file
->tus
)
12813 struct dwo_unit find_dwo_cutu
;
12815 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12816 find_dwo_cutu
.signature
= signature
;
12818 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12821 else if (!is_debug_types
&& dwo_file
->cus
)
12823 struct dwo_unit find_dwo_cutu
;
12825 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12826 find_dwo_cutu
.signature
= signature
;
12827 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12831 if (dwo_cutu
!= NULL
)
12833 if (dwarf_read_debug
)
12835 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12836 kind
, dwo_name
, hex_string (signature
),
12837 host_address_to_string (dwo_cutu
));
12844 /* We didn't find it. This could mean a dwo_id mismatch, or
12845 someone deleted the DWO/DWP file, or the search path isn't set up
12846 correctly to find the file. */
12848 if (dwarf_read_debug
)
12850 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12851 kind
, dwo_name
, hex_string (signature
));
12854 /* This is a warning and not a complaint because it can be caused by
12855 pilot error (e.g., user accidentally deleting the DWO). */
12857 /* Print the name of the DWP file if we looked there, helps the user
12858 better diagnose the problem. */
12859 std::string dwp_text
;
12861 if (dwp_file
!= NULL
)
12862 dwp_text
= string_printf (" [in DWP file %s]",
12863 lbasename (dwp_file
->name
));
12865 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12866 " [in module %s]"),
12867 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12868 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12873 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12874 See lookup_dwo_cutu_unit for details. */
12876 static struct dwo_unit
*
12877 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12878 ULONGEST signature
)
12880 gdb_assert (!cu
->per_cu
->is_debug_types
);
12882 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12885 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12886 See lookup_dwo_cutu_unit for details. */
12888 static struct dwo_unit
*
12889 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12891 gdb_assert (cu
->per_cu
->is_debug_types
);
12893 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12895 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12898 /* Traversal function for queue_and_load_all_dwo_tus. */
12901 queue_and_load_dwo_tu (void **slot
, void *info
)
12903 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12904 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12905 ULONGEST signature
= dwo_unit
->signature
;
12906 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12908 if (sig_type
!= NULL
)
12910 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12912 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12913 a real dependency of PER_CU on SIG_TYPE. That is detected later
12914 while processing PER_CU. */
12915 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12916 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12917 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12923 /* Queue all TUs contained in the DWO of CU to be read in.
12924 The DWO may have the only definition of the type, though it may not be
12925 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12926 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12929 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12931 struct dwo_unit
*dwo_unit
;
12932 struct dwo_file
*dwo_file
;
12934 gdb_assert (cu
!= nullptr);
12935 gdb_assert (!cu
->per_cu
->is_debug_types
);
12936 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12938 dwo_unit
= cu
->dwo_unit
;
12939 gdb_assert (dwo_unit
!= NULL
);
12941 dwo_file
= dwo_unit
->dwo_file
;
12942 if (dwo_file
->tus
!= NULL
)
12943 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12946 /* Read in various DIEs. */
12948 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12949 Inherit only the children of the DW_AT_abstract_origin DIE not being
12950 already referenced by DW_AT_abstract_origin from the children of the
12954 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12956 struct die_info
*child_die
;
12957 sect_offset
*offsetp
;
12958 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12959 struct die_info
*origin_die
;
12960 /* Iterator of the ORIGIN_DIE children. */
12961 struct die_info
*origin_child_die
;
12962 struct attribute
*attr
;
12963 struct dwarf2_cu
*origin_cu
;
12964 struct pending
**origin_previous_list_in_scope
;
12966 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12970 /* Note that following die references may follow to a die in a
12974 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12976 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12978 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12979 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12981 if (die
->tag
!= origin_die
->tag
12982 && !(die
->tag
== DW_TAG_inlined_subroutine
12983 && origin_die
->tag
== DW_TAG_subprogram
))
12984 complaint (_("DIE %s and its abstract origin %s have different tags"),
12985 sect_offset_str (die
->sect_off
),
12986 sect_offset_str (origin_die
->sect_off
));
12988 std::vector
<sect_offset
> offsets
;
12990 for (child_die
= die
->child
;
12991 child_die
&& child_die
->tag
;
12992 child_die
= child_die
->sibling
)
12994 struct die_info
*child_origin_die
;
12995 struct dwarf2_cu
*child_origin_cu
;
12997 /* We are trying to process concrete instance entries:
12998 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12999 it's not relevant to our analysis here. i.e. detecting DIEs that are
13000 present in the abstract instance but not referenced in the concrete
13002 if (child_die
->tag
== DW_TAG_call_site
13003 || child_die
->tag
== DW_TAG_GNU_call_site
)
13006 /* For each CHILD_DIE, find the corresponding child of
13007 ORIGIN_DIE. If there is more than one layer of
13008 DW_AT_abstract_origin, follow them all; there shouldn't be,
13009 but GCC versions at least through 4.4 generate this (GCC PR
13011 child_origin_die
= child_die
;
13012 child_origin_cu
= cu
;
13015 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13019 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13023 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13024 counterpart may exist. */
13025 if (child_origin_die
!= child_die
)
13027 if (child_die
->tag
!= child_origin_die
->tag
13028 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13029 && child_origin_die
->tag
== DW_TAG_subprogram
))
13030 complaint (_("Child DIE %s and its abstract origin %s have "
13032 sect_offset_str (child_die
->sect_off
),
13033 sect_offset_str (child_origin_die
->sect_off
));
13034 if (child_origin_die
->parent
!= origin_die
)
13035 complaint (_("Child DIE %s and its abstract origin %s have "
13036 "different parents"),
13037 sect_offset_str (child_die
->sect_off
),
13038 sect_offset_str (child_origin_die
->sect_off
));
13040 offsets
.push_back (child_origin_die
->sect_off
);
13043 std::sort (offsets
.begin (), offsets
.end ());
13044 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13045 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13046 if (offsetp
[-1] == *offsetp
)
13047 complaint (_("Multiple children of DIE %s refer "
13048 "to DIE %s as their abstract origin"),
13049 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13051 offsetp
= offsets
.data ();
13052 origin_child_die
= origin_die
->child
;
13053 while (origin_child_die
&& origin_child_die
->tag
)
13055 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13056 while (offsetp
< offsets_end
13057 && *offsetp
< origin_child_die
->sect_off
)
13059 if (offsetp
>= offsets_end
13060 || *offsetp
> origin_child_die
->sect_off
)
13062 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13063 Check whether we're already processing ORIGIN_CHILD_DIE.
13064 This can happen with mutually referenced abstract_origins.
13066 if (!origin_child_die
->in_process
)
13067 process_die (origin_child_die
, origin_cu
);
13069 origin_child_die
= origin_child_die
->sibling
;
13071 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13073 if (cu
!= origin_cu
)
13074 compute_delayed_physnames (origin_cu
);
13078 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13080 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13081 struct gdbarch
*gdbarch
= objfile
->arch ();
13082 struct context_stack
*newobj
;
13085 struct die_info
*child_die
;
13086 struct attribute
*attr
, *call_line
, *call_file
;
13088 CORE_ADDR baseaddr
;
13089 struct block
*block
;
13090 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13091 std::vector
<struct symbol
*> template_args
;
13092 struct template_symbol
*templ_func
= NULL
;
13096 /* If we do not have call site information, we can't show the
13097 caller of this inlined function. That's too confusing, so
13098 only use the scope for local variables. */
13099 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13100 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13101 if (call_line
== NULL
|| call_file
== NULL
)
13103 read_lexical_block_scope (die
, cu
);
13108 baseaddr
= objfile
->text_section_offset ();
13110 name
= dwarf2_name (die
, cu
);
13112 /* Ignore functions with missing or empty names. These are actually
13113 illegal according to the DWARF standard. */
13116 complaint (_("missing name for subprogram DIE at %s"),
13117 sect_offset_str (die
->sect_off
));
13121 /* Ignore functions with missing or invalid low and high pc attributes. */
13122 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13123 <= PC_BOUNDS_INVALID
)
13125 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13126 if (!attr
|| !DW_UNSND (attr
))
13127 complaint (_("cannot get low and high bounds "
13128 "for subprogram DIE at %s"),
13129 sect_offset_str (die
->sect_off
));
13133 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13134 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13136 /* If we have any template arguments, then we must allocate a
13137 different sort of symbol. */
13138 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13140 if (child_die
->tag
== DW_TAG_template_type_param
13141 || child_die
->tag
== DW_TAG_template_value_param
)
13143 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13144 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13149 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13150 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13151 (struct symbol
*) templ_func
);
13153 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13154 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13157 /* If there is a location expression for DW_AT_frame_base, record
13159 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13160 if (attr
!= nullptr)
13161 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13163 /* If there is a location for the static link, record it. */
13164 newobj
->static_link
= NULL
;
13165 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13166 if (attr
!= nullptr)
13168 newobj
->static_link
13169 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13170 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13174 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13176 if (die
->child
!= NULL
)
13178 child_die
= die
->child
;
13179 while (child_die
&& child_die
->tag
)
13181 if (child_die
->tag
== DW_TAG_template_type_param
13182 || child_die
->tag
== DW_TAG_template_value_param
)
13184 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13187 template_args
.push_back (arg
);
13190 process_die (child_die
, cu
);
13191 child_die
= child_die
->sibling
;
13195 inherit_abstract_dies (die
, cu
);
13197 /* If we have a DW_AT_specification, we might need to import using
13198 directives from the context of the specification DIE. See the
13199 comment in determine_prefix. */
13200 if (cu
->language
== language_cplus
13201 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13203 struct dwarf2_cu
*spec_cu
= cu
;
13204 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13208 child_die
= spec_die
->child
;
13209 while (child_die
&& child_die
->tag
)
13211 if (child_die
->tag
== DW_TAG_imported_module
)
13212 process_die (child_die
, spec_cu
);
13213 child_die
= child_die
->sibling
;
13216 /* In some cases, GCC generates specification DIEs that
13217 themselves contain DW_AT_specification attributes. */
13218 spec_die
= die_specification (spec_die
, &spec_cu
);
13222 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13223 /* Make a block for the local symbols within. */
13224 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13225 cstk
.static_link
, lowpc
, highpc
);
13227 /* For C++, set the block's scope. */
13228 if ((cu
->language
== language_cplus
13229 || cu
->language
== language_fortran
13230 || cu
->language
== language_d
13231 || cu
->language
== language_rust
)
13232 && cu
->processing_has_namespace_info
)
13233 block_set_scope (block
, determine_prefix (die
, cu
),
13234 &objfile
->objfile_obstack
);
13236 /* If we have address ranges, record them. */
13237 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13239 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13241 /* Attach template arguments to function. */
13242 if (!template_args
.empty ())
13244 gdb_assert (templ_func
!= NULL
);
13246 templ_func
->n_template_arguments
= template_args
.size ();
13247 templ_func
->template_arguments
13248 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13249 templ_func
->n_template_arguments
);
13250 memcpy (templ_func
->template_arguments
,
13251 template_args
.data (),
13252 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13254 /* Make sure that the symtab is set on the new symbols. Even
13255 though they don't appear in this symtab directly, other parts
13256 of gdb assume that symbols do, and this is reasonably
13258 for (symbol
*sym
: template_args
)
13259 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13262 /* In C++, we can have functions nested inside functions (e.g., when
13263 a function declares a class that has methods). This means that
13264 when we finish processing a function scope, we may need to go
13265 back to building a containing block's symbol lists. */
13266 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13267 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13269 /* If we've finished processing a top-level function, subsequent
13270 symbols go in the file symbol list. */
13271 if (cu
->get_builder ()->outermost_context_p ())
13272 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13275 /* Process all the DIES contained within a lexical block scope. Start
13276 a new scope, process the dies, and then close the scope. */
13279 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13281 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13282 struct gdbarch
*gdbarch
= objfile
->arch ();
13283 CORE_ADDR lowpc
, highpc
;
13284 struct die_info
*child_die
;
13285 CORE_ADDR baseaddr
;
13287 baseaddr
= objfile
->text_section_offset ();
13289 /* Ignore blocks with missing or invalid low and high pc attributes. */
13290 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13291 as multiple lexical blocks? Handling children in a sane way would
13292 be nasty. Might be easier to properly extend generic blocks to
13293 describe ranges. */
13294 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13296 case PC_BOUNDS_NOT_PRESENT
:
13297 /* DW_TAG_lexical_block has no attributes, process its children as if
13298 there was no wrapping by that DW_TAG_lexical_block.
13299 GCC does no longer produces such DWARF since GCC r224161. */
13300 for (child_die
= die
->child
;
13301 child_die
!= NULL
&& child_die
->tag
;
13302 child_die
= child_die
->sibling
)
13304 /* We might already be processing this DIE. This can happen
13305 in an unusual circumstance -- where a subroutine A
13306 appears lexically in another subroutine B, but A actually
13307 inlines B. The recursion is broken here, rather than in
13308 inherit_abstract_dies, because it seems better to simply
13309 drop concrete children here. */
13310 if (!child_die
->in_process
)
13311 process_die (child_die
, cu
);
13314 case PC_BOUNDS_INVALID
:
13317 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13318 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13320 cu
->get_builder ()->push_context (0, lowpc
);
13321 if (die
->child
!= NULL
)
13323 child_die
= die
->child
;
13324 while (child_die
&& child_die
->tag
)
13326 process_die (child_die
, cu
);
13327 child_die
= child_die
->sibling
;
13330 inherit_abstract_dies (die
, cu
);
13331 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13333 if (*cu
->get_builder ()->get_local_symbols () != NULL
13334 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13336 struct block
*block
13337 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13338 cstk
.start_addr
, highpc
);
13340 /* Note that recording ranges after traversing children, as we
13341 do here, means that recording a parent's ranges entails
13342 walking across all its children's ranges as they appear in
13343 the address map, which is quadratic behavior.
13345 It would be nicer to record the parent's ranges before
13346 traversing its children, simply overriding whatever you find
13347 there. But since we don't even decide whether to create a
13348 block until after we've traversed its children, that's hard
13350 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13352 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13353 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13356 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13359 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13361 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13362 struct objfile
*objfile
= per_objfile
->objfile
;
13363 struct gdbarch
*gdbarch
= objfile
->arch ();
13364 CORE_ADDR pc
, baseaddr
;
13365 struct attribute
*attr
;
13366 struct call_site
*call_site
, call_site_local
;
13369 struct die_info
*child_die
;
13371 baseaddr
= objfile
->text_section_offset ();
13373 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13376 /* This was a pre-DWARF-5 GNU extension alias
13377 for DW_AT_call_return_pc. */
13378 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13382 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13383 "DIE %s [in module %s]"),
13384 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13387 pc
= attr
->value_as_address () + baseaddr
;
13388 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13390 if (cu
->call_site_htab
== NULL
)
13391 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13392 NULL
, &objfile
->objfile_obstack
,
13393 hashtab_obstack_allocate
, NULL
);
13394 call_site_local
.pc
= pc
;
13395 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13398 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13399 "DIE %s [in module %s]"),
13400 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13401 objfile_name (objfile
));
13405 /* Count parameters at the caller. */
13408 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13409 child_die
= child_die
->sibling
)
13411 if (child_die
->tag
!= DW_TAG_call_site_parameter
13412 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13414 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13415 "DW_TAG_call_site child DIE %s [in module %s]"),
13416 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13417 objfile_name (objfile
));
13425 = ((struct call_site
*)
13426 obstack_alloc (&objfile
->objfile_obstack
,
13427 sizeof (*call_site
)
13428 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13430 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13431 call_site
->pc
= pc
;
13433 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13434 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13436 struct die_info
*func_die
;
13438 /* Skip also over DW_TAG_inlined_subroutine. */
13439 for (func_die
= die
->parent
;
13440 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13441 && func_die
->tag
!= DW_TAG_subroutine_type
;
13442 func_die
= func_die
->parent
);
13444 /* DW_AT_call_all_calls is a superset
13445 of DW_AT_call_all_tail_calls. */
13447 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13448 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13449 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13450 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13452 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13453 not complete. But keep CALL_SITE for look ups via call_site_htab,
13454 both the initial caller containing the real return address PC and
13455 the final callee containing the current PC of a chain of tail
13456 calls do not need to have the tail call list complete. But any
13457 function candidate for a virtual tail call frame searched via
13458 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13459 determined unambiguously. */
13463 struct type
*func_type
= NULL
;
13466 func_type
= get_die_type (func_die
, cu
);
13467 if (func_type
!= NULL
)
13469 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13471 /* Enlist this call site to the function. */
13472 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13473 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13476 complaint (_("Cannot find function owning DW_TAG_call_site "
13477 "DIE %s [in module %s]"),
13478 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13482 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13484 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13486 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13489 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13490 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13492 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13493 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13494 /* Keep NULL DWARF_BLOCK. */;
13495 else if (attr
->form_is_block ())
13497 struct dwarf2_locexpr_baton
*dlbaton
;
13499 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13500 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13501 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13502 dlbaton
->per_objfile
= per_objfile
;
13503 dlbaton
->per_cu
= cu
->per_cu
;
13505 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13507 else if (attr
->form_is_ref ())
13509 struct dwarf2_cu
*target_cu
= cu
;
13510 struct die_info
*target_die
;
13512 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13513 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13514 if (die_is_declaration (target_die
, target_cu
))
13516 const char *target_physname
;
13518 /* Prefer the mangled name; otherwise compute the demangled one. */
13519 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13520 if (target_physname
== NULL
)
13521 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13522 if (target_physname
== NULL
)
13523 complaint (_("DW_AT_call_target target DIE has invalid "
13524 "physname, for referencing DIE %s [in module %s]"),
13525 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13527 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13533 /* DW_AT_entry_pc should be preferred. */
13534 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13535 <= PC_BOUNDS_INVALID
)
13536 complaint (_("DW_AT_call_target target DIE has invalid "
13537 "low pc, for referencing DIE %s [in module %s]"),
13538 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13541 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13542 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13547 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13548 "block nor reference, for DIE %s [in module %s]"),
13549 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13551 call_site
->per_cu
= cu
->per_cu
;
13552 call_site
->per_objfile
= per_objfile
;
13554 for (child_die
= die
->child
;
13555 child_die
&& child_die
->tag
;
13556 child_die
= child_die
->sibling
)
13558 struct call_site_parameter
*parameter
;
13559 struct attribute
*loc
, *origin
;
13561 if (child_die
->tag
!= DW_TAG_call_site_parameter
13562 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13564 /* Already printed the complaint above. */
13568 gdb_assert (call_site
->parameter_count
< nparams
);
13569 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13571 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13572 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13573 register is contained in DW_AT_call_value. */
13575 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13576 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13577 if (origin
== NULL
)
13579 /* This was a pre-DWARF-5 GNU extension alias
13580 for DW_AT_call_parameter. */
13581 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13583 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13585 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13587 sect_offset sect_off
= origin
->get_ref_die_offset ();
13588 if (!cu
->header
.offset_in_cu_p (sect_off
))
13590 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13591 binding can be done only inside one CU. Such referenced DIE
13592 therefore cannot be even moved to DW_TAG_partial_unit. */
13593 complaint (_("DW_AT_call_parameter offset is not in CU for "
13594 "DW_TAG_call_site child DIE %s [in module %s]"),
13595 sect_offset_str (child_die
->sect_off
),
13596 objfile_name (objfile
));
13599 parameter
->u
.param_cu_off
13600 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13602 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13604 complaint (_("No DW_FORM_block* DW_AT_location for "
13605 "DW_TAG_call_site child DIE %s [in module %s]"),
13606 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13611 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13612 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13613 if (parameter
->u
.dwarf_reg
!= -1)
13614 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13615 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13616 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13617 ¶meter
->u
.fb_offset
))
13618 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13621 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13622 "for DW_FORM_block* DW_AT_location is supported for "
13623 "DW_TAG_call_site child DIE %s "
13625 sect_offset_str (child_die
->sect_off
),
13626 objfile_name (objfile
));
13631 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13633 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13634 if (attr
== NULL
|| !attr
->form_is_block ())
13636 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13637 "DW_TAG_call_site child DIE %s [in module %s]"),
13638 sect_offset_str (child_die
->sect_off
),
13639 objfile_name (objfile
));
13642 parameter
->value
= DW_BLOCK (attr
)->data
;
13643 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13645 /* Parameters are not pre-cleared by memset above. */
13646 parameter
->data_value
= NULL
;
13647 parameter
->data_value_size
= 0;
13648 call_site
->parameter_count
++;
13650 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13652 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13653 if (attr
!= nullptr)
13655 if (!attr
->form_is_block ())
13656 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13657 "DW_TAG_call_site child DIE %s [in module %s]"),
13658 sect_offset_str (child_die
->sect_off
),
13659 objfile_name (objfile
));
13662 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13663 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13669 /* Helper function for read_variable. If DIE represents a virtual
13670 table, then return the type of the concrete object that is
13671 associated with the virtual table. Otherwise, return NULL. */
13673 static struct type
*
13674 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13676 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13680 /* Find the type DIE. */
13681 struct die_info
*type_die
= NULL
;
13682 struct dwarf2_cu
*type_cu
= cu
;
13684 if (attr
->form_is_ref ())
13685 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13686 if (type_die
== NULL
)
13689 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13691 return die_containing_type (type_die
, type_cu
);
13694 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13697 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13699 struct rust_vtable_symbol
*storage
= NULL
;
13701 if (cu
->language
== language_rust
)
13703 struct type
*containing_type
= rust_containing_type (die
, cu
);
13705 if (containing_type
!= NULL
)
13707 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13709 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13710 storage
->concrete_type
= containing_type
;
13711 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13715 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13716 struct attribute
*abstract_origin
13717 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13718 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13719 if (res
== NULL
&& loc
&& abstract_origin
)
13721 /* We have a variable without a name, but with a location and an abstract
13722 origin. This may be a concrete instance of an abstract variable
13723 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13725 struct dwarf2_cu
*origin_cu
= cu
;
13726 struct die_info
*origin_die
13727 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13728 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13729 per_objfile
->per_bfd
->abstract_to_concrete
13730 [origin_die
->sect_off
].push_back (die
->sect_off
);
13734 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13735 reading .debug_rnglists.
13736 Callback's type should be:
13737 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13738 Return true if the attributes are present and valid, otherwise,
13741 template <typename Callback
>
13743 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13744 Callback
&&callback
)
13746 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13747 struct objfile
*objfile
= per_objfile
->objfile
;
13748 bfd
*obfd
= objfile
->obfd
;
13749 /* Base address selection entry. */
13750 gdb::optional
<CORE_ADDR
> base
;
13751 const gdb_byte
*buffer
;
13752 CORE_ADDR baseaddr
;
13753 bool overflow
= false;
13755 base
= cu
->base_address
;
13757 per_objfile
->per_bfd
->rnglists
.read (objfile
);
13758 if (offset
>= per_objfile
->per_bfd
->rnglists
.size
)
13760 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13764 buffer
= per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13766 baseaddr
= objfile
->text_section_offset ();
13770 /* Initialize it due to a false compiler warning. */
13771 CORE_ADDR range_beginning
= 0, range_end
= 0;
13772 const gdb_byte
*buf_end
= (per_objfile
->per_bfd
->rnglists
.buffer
13773 + per_objfile
->per_bfd
->rnglists
.size
);
13774 unsigned int bytes_read
;
13776 if (buffer
== buf_end
)
13781 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13784 case DW_RLE_end_of_list
:
13786 case DW_RLE_base_address
:
13787 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13792 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13793 buffer
+= bytes_read
;
13795 case DW_RLE_start_length
:
13796 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13801 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13803 buffer
+= bytes_read
;
13804 range_end
= (range_beginning
13805 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13806 buffer
+= bytes_read
;
13807 if (buffer
> buf_end
)
13813 case DW_RLE_offset_pair
:
13814 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13815 buffer
+= bytes_read
;
13816 if (buffer
> buf_end
)
13821 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13822 buffer
+= bytes_read
;
13823 if (buffer
> buf_end
)
13829 case DW_RLE_start_end
:
13830 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13835 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13837 buffer
+= bytes_read
;
13838 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13839 buffer
+= bytes_read
;
13842 complaint (_("Invalid .debug_rnglists data (no base address)"));
13845 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13847 if (rlet
== DW_RLE_base_address
)
13850 if (!base
.has_value ())
13852 /* We have no valid base address for the ranges
13854 complaint (_("Invalid .debug_rnglists data (no base address)"));
13858 if (range_beginning
> range_end
)
13860 /* Inverted range entries are invalid. */
13861 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13865 /* Empty range entries have no effect. */
13866 if (range_beginning
== range_end
)
13869 range_beginning
+= *base
;
13870 range_end
+= *base
;
13872 /* A not-uncommon case of bad debug info.
13873 Don't pollute the addrmap with bad data. */
13874 if (range_beginning
+ baseaddr
== 0
13875 && !per_objfile
->per_bfd
->has_section_at_zero
)
13877 complaint (_(".debug_rnglists entry has start address of zero"
13878 " [in module %s]"), objfile_name (objfile
));
13882 callback (range_beginning
, range_end
);
13887 complaint (_("Offset %d is not terminated "
13888 "for DW_AT_ranges attribute"),
13896 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13897 Callback's type should be:
13898 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13899 Return 1 if the attributes are present and valid, otherwise, return 0. */
13901 template <typename Callback
>
13903 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13904 Callback
&&callback
)
13906 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13907 struct objfile
*objfile
= per_objfile
->objfile
;
13908 struct comp_unit_head
*cu_header
= &cu
->header
;
13909 bfd
*obfd
= objfile
->obfd
;
13910 unsigned int addr_size
= cu_header
->addr_size
;
13911 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13912 /* Base address selection entry. */
13913 gdb::optional
<CORE_ADDR
> base
;
13914 unsigned int dummy
;
13915 const gdb_byte
*buffer
;
13916 CORE_ADDR baseaddr
;
13918 if (cu_header
->version
>= 5)
13919 return dwarf2_rnglists_process (offset
, cu
, callback
);
13921 base
= cu
->base_address
;
13923 per_objfile
->per_bfd
->ranges
.read (objfile
);
13924 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13926 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13930 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13932 baseaddr
= objfile
->text_section_offset ();
13936 CORE_ADDR range_beginning
, range_end
;
13938 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13939 buffer
+= addr_size
;
13940 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13941 buffer
+= addr_size
;
13942 offset
+= 2 * addr_size
;
13944 /* An end of list marker is a pair of zero addresses. */
13945 if (range_beginning
== 0 && range_end
== 0)
13946 /* Found the end of list entry. */
13949 /* Each base address selection entry is a pair of 2 values.
13950 The first is the largest possible address, the second is
13951 the base address. Check for a base address here. */
13952 if ((range_beginning
& mask
) == mask
)
13954 /* If we found the largest possible address, then we already
13955 have the base address in range_end. */
13960 if (!base
.has_value ())
13962 /* We have no valid base address for the ranges
13964 complaint (_("Invalid .debug_ranges data (no base address)"));
13968 if (range_beginning
> range_end
)
13970 /* Inverted range entries are invalid. */
13971 complaint (_("Invalid .debug_ranges data (inverted range)"));
13975 /* Empty range entries have no effect. */
13976 if (range_beginning
== range_end
)
13979 range_beginning
+= *base
;
13980 range_end
+= *base
;
13982 /* A not-uncommon case of bad debug info.
13983 Don't pollute the addrmap with bad data. */
13984 if (range_beginning
+ baseaddr
== 0
13985 && !per_objfile
->per_bfd
->has_section_at_zero
)
13987 complaint (_(".debug_ranges entry has start address of zero"
13988 " [in module %s]"), objfile_name (objfile
));
13992 callback (range_beginning
, range_end
);
13998 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13999 Return 1 if the attributes are present and valid, otherwise, return 0.
14000 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14003 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14004 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14005 dwarf2_psymtab
*ranges_pst
)
14007 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14008 struct gdbarch
*gdbarch
= objfile
->arch ();
14009 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14012 CORE_ADDR high
= 0;
14015 retval
= dwarf2_ranges_process (offset
, cu
,
14016 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14018 if (ranges_pst
!= NULL
)
14023 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14024 range_beginning
+ baseaddr
)
14026 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14027 range_end
+ baseaddr
)
14029 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14030 lowpc
, highpc
- 1, ranges_pst
);
14033 /* FIXME: This is recording everything as a low-high
14034 segment of consecutive addresses. We should have a
14035 data structure for discontiguous block ranges
14039 low
= range_beginning
;
14045 if (range_beginning
< low
)
14046 low
= range_beginning
;
14047 if (range_end
> high
)
14055 /* If the first entry is an end-of-list marker, the range
14056 describes an empty scope, i.e. no instructions. */
14062 *high_return
= high
;
14066 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14067 definition for the return value. *LOWPC and *HIGHPC are set iff
14068 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14070 static enum pc_bounds_kind
14071 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14072 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14073 dwarf2_psymtab
*pst
)
14075 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14076 struct attribute
*attr
;
14077 struct attribute
*attr_high
;
14079 CORE_ADDR high
= 0;
14080 enum pc_bounds_kind ret
;
14082 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14085 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14086 if (attr
!= nullptr)
14088 low
= attr
->value_as_address ();
14089 high
= attr_high
->value_as_address ();
14090 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14094 /* Found high w/o low attribute. */
14095 return PC_BOUNDS_INVALID
;
14097 /* Found consecutive range of addresses. */
14098 ret
= PC_BOUNDS_HIGH_LOW
;
14102 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14105 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14106 We take advantage of the fact that DW_AT_ranges does not appear
14107 in DW_TAG_compile_unit of DWO files. */
14108 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14109 unsigned int ranges_offset
= (DW_UNSND (attr
)
14110 + (need_ranges_base
14114 /* Value of the DW_AT_ranges attribute is the offset in the
14115 .debug_ranges section. */
14116 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14117 return PC_BOUNDS_INVALID
;
14118 /* Found discontinuous range of addresses. */
14119 ret
= PC_BOUNDS_RANGES
;
14122 return PC_BOUNDS_NOT_PRESENT
;
14125 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14127 return PC_BOUNDS_INVALID
;
14129 /* When using the GNU linker, .gnu.linkonce. sections are used to
14130 eliminate duplicate copies of functions and vtables and such.
14131 The linker will arbitrarily choose one and discard the others.
14132 The AT_*_pc values for such functions refer to local labels in
14133 these sections. If the section from that file was discarded, the
14134 labels are not in the output, so the relocs get a value of 0.
14135 If this is a discarded function, mark the pc bounds as invalid,
14136 so that GDB will ignore it. */
14137 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14138 return PC_BOUNDS_INVALID
;
14146 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14147 its low and high PC addresses. Do nothing if these addresses could not
14148 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14149 and HIGHPC to the high address if greater than HIGHPC. */
14152 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14153 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14154 struct dwarf2_cu
*cu
)
14156 CORE_ADDR low
, high
;
14157 struct die_info
*child
= die
->child
;
14159 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14161 *lowpc
= std::min (*lowpc
, low
);
14162 *highpc
= std::max (*highpc
, high
);
14165 /* If the language does not allow nested subprograms (either inside
14166 subprograms or lexical blocks), we're done. */
14167 if (cu
->language
!= language_ada
)
14170 /* Check all the children of the given DIE. If it contains nested
14171 subprograms, then check their pc bounds. Likewise, we need to
14172 check lexical blocks as well, as they may also contain subprogram
14174 while (child
&& child
->tag
)
14176 if (child
->tag
== DW_TAG_subprogram
14177 || child
->tag
== DW_TAG_lexical_block
)
14178 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14179 child
= child
->sibling
;
14183 /* Get the low and high pc's represented by the scope DIE, and store
14184 them in *LOWPC and *HIGHPC. If the correct values can't be
14185 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14188 get_scope_pc_bounds (struct die_info
*die
,
14189 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14190 struct dwarf2_cu
*cu
)
14192 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14193 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14194 CORE_ADDR current_low
, current_high
;
14196 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14197 >= PC_BOUNDS_RANGES
)
14199 best_low
= current_low
;
14200 best_high
= current_high
;
14204 struct die_info
*child
= die
->child
;
14206 while (child
&& child
->tag
)
14208 switch (child
->tag
) {
14209 case DW_TAG_subprogram
:
14210 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14212 case DW_TAG_namespace
:
14213 case DW_TAG_module
:
14214 /* FIXME: carlton/2004-01-16: Should we do this for
14215 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14216 that current GCC's always emit the DIEs corresponding
14217 to definitions of methods of classes as children of a
14218 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14219 the DIEs giving the declarations, which could be
14220 anywhere). But I don't see any reason why the
14221 standards says that they have to be there. */
14222 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14224 if (current_low
!= ((CORE_ADDR
) -1))
14226 best_low
= std::min (best_low
, current_low
);
14227 best_high
= std::max (best_high
, current_high
);
14235 child
= child
->sibling
;
14240 *highpc
= best_high
;
14243 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14247 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14248 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14250 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14251 struct gdbarch
*gdbarch
= objfile
->arch ();
14252 struct attribute
*attr
;
14253 struct attribute
*attr_high
;
14255 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14258 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14259 if (attr
!= nullptr)
14261 CORE_ADDR low
= attr
->value_as_address ();
14262 CORE_ADDR high
= attr_high
->value_as_address ();
14264 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14267 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14268 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14269 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14273 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14274 if (attr
!= nullptr)
14276 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14277 We take advantage of the fact that DW_AT_ranges does not appear
14278 in DW_TAG_compile_unit of DWO files. */
14279 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14281 /* The value of the DW_AT_ranges attribute is the offset of the
14282 address range list in the .debug_ranges section. */
14283 unsigned long offset
= (DW_UNSND (attr
)
14284 + (need_ranges_base
? cu
->ranges_base
: 0));
14286 std::vector
<blockrange
> blockvec
;
14287 dwarf2_ranges_process (offset
, cu
,
14288 [&] (CORE_ADDR start
, CORE_ADDR end
)
14292 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14293 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14294 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14295 blockvec
.emplace_back (start
, end
);
14298 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14302 /* Check whether the producer field indicates either of GCC < 4.6, or the
14303 Intel C/C++ compiler, and cache the result in CU. */
14306 check_producer (struct dwarf2_cu
*cu
)
14310 if (cu
->producer
== NULL
)
14312 /* For unknown compilers expect their behavior is DWARF version
14315 GCC started to support .debug_types sections by -gdwarf-4 since
14316 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14317 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14318 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14319 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14321 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14323 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14324 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14326 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14328 cu
->producer_is_icc
= true;
14329 cu
->producer_is_icc_lt_14
= major
< 14;
14331 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14332 cu
->producer_is_codewarrior
= true;
14335 /* For other non-GCC compilers, expect their behavior is DWARF version
14339 cu
->checked_producer
= true;
14342 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14343 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14344 during 4.6.0 experimental. */
14347 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14349 if (!cu
->checked_producer
)
14350 check_producer (cu
);
14352 return cu
->producer_is_gxx_lt_4_6
;
14356 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14357 with incorrect is_stmt attributes. */
14360 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14362 if (!cu
->checked_producer
)
14363 check_producer (cu
);
14365 return cu
->producer_is_codewarrior
;
14368 /* Return the default accessibility type if it is not overridden by
14369 DW_AT_accessibility. */
14371 static enum dwarf_access_attribute
14372 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14374 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14376 /* The default DWARF 2 accessibility for members is public, the default
14377 accessibility for inheritance is private. */
14379 if (die
->tag
!= DW_TAG_inheritance
)
14380 return DW_ACCESS_public
;
14382 return DW_ACCESS_private
;
14386 /* DWARF 3+ defines the default accessibility a different way. The same
14387 rules apply now for DW_TAG_inheritance as for the members and it only
14388 depends on the container kind. */
14390 if (die
->parent
->tag
== DW_TAG_class_type
)
14391 return DW_ACCESS_private
;
14393 return DW_ACCESS_public
;
14397 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14398 offset. If the attribute was not found return 0, otherwise return
14399 1. If it was found but could not properly be handled, set *OFFSET
14403 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14406 struct attribute
*attr
;
14408 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14413 /* Note that we do not check for a section offset first here.
14414 This is because DW_AT_data_member_location is new in DWARF 4,
14415 so if we see it, we can assume that a constant form is really
14416 a constant and not a section offset. */
14417 if (attr
->form_is_constant ())
14418 *offset
= attr
->constant_value (0);
14419 else if (attr
->form_is_section_offset ())
14420 dwarf2_complex_location_expr_complaint ();
14421 else if (attr
->form_is_block ())
14422 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14424 dwarf2_complex_location_expr_complaint ();
14432 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14435 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14436 struct field
*field
)
14438 struct attribute
*attr
;
14440 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14443 if (attr
->form_is_constant ())
14445 LONGEST offset
= attr
->constant_value (0);
14446 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14448 else if (attr
->form_is_section_offset ())
14449 dwarf2_complex_location_expr_complaint ();
14450 else if (attr
->form_is_block ())
14453 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14455 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14458 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14459 struct objfile
*objfile
= per_objfile
->objfile
;
14460 struct dwarf2_locexpr_baton
*dlbaton
14461 = XOBNEW (&objfile
->objfile_obstack
,
14462 struct dwarf2_locexpr_baton
);
14463 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14464 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14465 /* When using this baton, we want to compute the address
14466 of the field, not the value. This is why
14467 is_reference is set to false here. */
14468 dlbaton
->is_reference
= false;
14469 dlbaton
->per_objfile
= per_objfile
;
14470 dlbaton
->per_cu
= cu
->per_cu
;
14472 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14476 dwarf2_complex_location_expr_complaint ();
14480 /* Add an aggregate field to the field list. */
14483 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14484 struct dwarf2_cu
*cu
)
14486 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14487 struct gdbarch
*gdbarch
= objfile
->arch ();
14488 struct nextfield
*new_field
;
14489 struct attribute
*attr
;
14491 const char *fieldname
= "";
14493 if (die
->tag
== DW_TAG_inheritance
)
14495 fip
->baseclasses
.emplace_back ();
14496 new_field
= &fip
->baseclasses
.back ();
14500 fip
->fields
.emplace_back ();
14501 new_field
= &fip
->fields
.back ();
14504 new_field
->offset
= die
->sect_off
;
14506 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14507 if (attr
!= nullptr)
14508 new_field
->accessibility
= DW_UNSND (attr
);
14510 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14511 if (new_field
->accessibility
!= DW_ACCESS_public
)
14512 fip
->non_public_fields
= 1;
14514 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14515 if (attr
!= nullptr)
14516 new_field
->virtuality
= DW_UNSND (attr
);
14518 new_field
->virtuality
= DW_VIRTUALITY_none
;
14520 fp
= &new_field
->field
;
14522 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14524 /* Data member other than a C++ static data member. */
14526 /* Get type of field. */
14527 fp
->type
= die_type (die
, cu
);
14529 SET_FIELD_BITPOS (*fp
, 0);
14531 /* Get bit size of field (zero if none). */
14532 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14533 if (attr
!= nullptr)
14535 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14539 FIELD_BITSIZE (*fp
) = 0;
14542 /* Get bit offset of field. */
14543 handle_data_member_location (die
, cu
, fp
);
14544 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14545 if (attr
!= nullptr)
14547 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14549 /* For big endian bits, the DW_AT_bit_offset gives the
14550 additional bit offset from the MSB of the containing
14551 anonymous object to the MSB of the field. We don't
14552 have to do anything special since we don't need to
14553 know the size of the anonymous object. */
14554 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14558 /* For little endian bits, compute the bit offset to the
14559 MSB of the anonymous object, subtract off the number of
14560 bits from the MSB of the field to the MSB of the
14561 object, and then subtract off the number of bits of
14562 the field itself. The result is the bit offset of
14563 the LSB of the field. */
14564 int anonymous_size
;
14565 int bit_offset
= DW_UNSND (attr
);
14567 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14568 if (attr
!= nullptr)
14570 /* The size of the anonymous object containing
14571 the bit field is explicit, so use the
14572 indicated size (in bytes). */
14573 anonymous_size
= DW_UNSND (attr
);
14577 /* The size of the anonymous object containing
14578 the bit field must be inferred from the type
14579 attribute of the data member containing the
14581 anonymous_size
= TYPE_LENGTH (fp
->type
);
14583 SET_FIELD_BITPOS (*fp
,
14584 (FIELD_BITPOS (*fp
)
14585 + anonymous_size
* bits_per_byte
14586 - bit_offset
- FIELD_BITSIZE (*fp
)));
14589 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14591 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14592 + attr
->constant_value (0)));
14594 /* Get name of field. */
14595 fieldname
= dwarf2_name (die
, cu
);
14596 if (fieldname
== NULL
)
14599 /* The name is already allocated along with this objfile, so we don't
14600 need to duplicate it for the type. */
14601 fp
->name
= fieldname
;
14603 /* Change accessibility for artificial fields (e.g. virtual table
14604 pointer or virtual base class pointer) to private. */
14605 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14607 FIELD_ARTIFICIAL (*fp
) = 1;
14608 new_field
->accessibility
= DW_ACCESS_private
;
14609 fip
->non_public_fields
= 1;
14612 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14614 /* C++ static member. */
14616 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14617 is a declaration, but all versions of G++ as of this writing
14618 (so through at least 3.2.1) incorrectly generate
14619 DW_TAG_variable tags. */
14621 const char *physname
;
14623 /* Get name of field. */
14624 fieldname
= dwarf2_name (die
, cu
);
14625 if (fieldname
== NULL
)
14628 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14630 /* Only create a symbol if this is an external value.
14631 new_symbol checks this and puts the value in the global symbol
14632 table, which we want. If it is not external, new_symbol
14633 will try to put the value in cu->list_in_scope which is wrong. */
14634 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14636 /* A static const member, not much different than an enum as far as
14637 we're concerned, except that we can support more types. */
14638 new_symbol (die
, NULL
, cu
);
14641 /* Get physical name. */
14642 physname
= dwarf2_physname (fieldname
, die
, cu
);
14644 /* The name is already allocated along with this objfile, so we don't
14645 need to duplicate it for the type. */
14646 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14647 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14648 FIELD_NAME (*fp
) = fieldname
;
14650 else if (die
->tag
== DW_TAG_inheritance
)
14652 /* C++ base class field. */
14653 handle_data_member_location (die
, cu
, fp
);
14654 FIELD_BITSIZE (*fp
) = 0;
14655 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14656 FIELD_NAME (*fp
) = fp
->type
->name ();
14659 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14662 /* Can the type given by DIE define another type? */
14665 type_can_define_types (const struct die_info
*die
)
14669 case DW_TAG_typedef
:
14670 case DW_TAG_class_type
:
14671 case DW_TAG_structure_type
:
14672 case DW_TAG_union_type
:
14673 case DW_TAG_enumeration_type
:
14681 /* Add a type definition defined in the scope of the FIP's class. */
14684 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14685 struct dwarf2_cu
*cu
)
14687 struct decl_field fp
;
14688 memset (&fp
, 0, sizeof (fp
));
14690 gdb_assert (type_can_define_types (die
));
14692 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14693 fp
.name
= dwarf2_name (die
, cu
);
14694 fp
.type
= read_type_die (die
, cu
);
14696 /* Save accessibility. */
14697 enum dwarf_access_attribute accessibility
;
14698 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14700 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14702 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14703 switch (accessibility
)
14705 case DW_ACCESS_public
:
14706 /* The assumed value if neither private nor protected. */
14708 case DW_ACCESS_private
:
14711 case DW_ACCESS_protected
:
14712 fp
.is_protected
= 1;
14715 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14718 if (die
->tag
== DW_TAG_typedef
)
14719 fip
->typedef_field_list
.push_back (fp
);
14721 fip
->nested_types_list
.push_back (fp
);
14724 /* A convenience typedef that's used when finding the discriminant
14725 field for a variant part. */
14726 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14729 /* Compute the discriminant range for a given variant. OBSTACK is
14730 where the results will be stored. VARIANT is the variant to
14731 process. IS_UNSIGNED indicates whether the discriminant is signed
14734 static const gdb::array_view
<discriminant_range
>
14735 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14738 std::vector
<discriminant_range
> ranges
;
14740 if (variant
.default_branch
)
14743 if (variant
.discr_list_data
== nullptr)
14745 discriminant_range r
14746 = {variant
.discriminant_value
, variant
.discriminant_value
};
14747 ranges
.push_back (r
);
14751 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14752 variant
.discr_list_data
->size
);
14753 while (!data
.empty ())
14755 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14757 complaint (_("invalid discriminant marker: %d"), data
[0]);
14760 bool is_range
= data
[0] == DW_DSC_range
;
14761 data
= data
.slice (1);
14763 ULONGEST low
, high
;
14764 unsigned int bytes_read
;
14768 complaint (_("DW_AT_discr_list missing low value"));
14772 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14774 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14776 data
= data
.slice (bytes_read
);
14782 complaint (_("DW_AT_discr_list missing high value"));
14786 high
= read_unsigned_leb128 (nullptr, data
.data (),
14789 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14791 data
= data
.slice (bytes_read
);
14796 ranges
.push_back ({ low
, high
});
14800 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14802 std::copy (ranges
.begin (), ranges
.end (), result
);
14803 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14806 static const gdb::array_view
<variant_part
> create_variant_parts
14807 (struct obstack
*obstack
,
14808 const offset_map_type
&offset_map
,
14809 struct field_info
*fi
,
14810 const std::vector
<variant_part_builder
> &variant_parts
);
14812 /* Fill in a "struct variant" for a given variant field. RESULT is
14813 the variant to fill in. OBSTACK is where any needed allocations
14814 will be done. OFFSET_MAP holds the mapping from section offsets to
14815 fields for the type. FI describes the fields of the type we're
14816 processing. FIELD is the variant field we're converting. */
14819 create_one_variant (variant
&result
, struct obstack
*obstack
,
14820 const offset_map_type
&offset_map
,
14821 struct field_info
*fi
, const variant_field
&field
)
14823 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14824 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14825 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14826 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14827 field
.variant_parts
);
14830 /* Fill in a "struct variant_part" for a given variant part. RESULT
14831 is the variant part to fill in. OBSTACK is where any needed
14832 allocations will be done. OFFSET_MAP holds the mapping from
14833 section offsets to fields for the type. FI describes the fields of
14834 the type we're processing. BUILDER is the variant part to be
14838 create_one_variant_part (variant_part
&result
,
14839 struct obstack
*obstack
,
14840 const offset_map_type
&offset_map
,
14841 struct field_info
*fi
,
14842 const variant_part_builder
&builder
)
14844 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14845 if (iter
== offset_map
.end ())
14847 result
.discriminant_index
= -1;
14848 /* Doesn't matter. */
14849 result
.is_unsigned
= false;
14853 result
.discriminant_index
= iter
->second
;
14855 = TYPE_UNSIGNED (FIELD_TYPE
14856 (fi
->fields
[result
.discriminant_index
].field
));
14859 size_t n
= builder
.variants
.size ();
14860 variant
*output
= new (obstack
) variant
[n
];
14861 for (size_t i
= 0; i
< n
; ++i
)
14862 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14863 builder
.variants
[i
]);
14865 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14868 /* Create a vector of variant parts that can be attached to a type.
14869 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14870 holds the mapping from section offsets to fields for the type. FI
14871 describes the fields of the type we're processing. VARIANT_PARTS
14872 is the vector to convert. */
14874 static const gdb::array_view
<variant_part
>
14875 create_variant_parts (struct obstack
*obstack
,
14876 const offset_map_type
&offset_map
,
14877 struct field_info
*fi
,
14878 const std::vector
<variant_part_builder
> &variant_parts
)
14880 if (variant_parts
.empty ())
14883 size_t n
= variant_parts
.size ();
14884 variant_part
*result
= new (obstack
) variant_part
[n
];
14885 for (size_t i
= 0; i
< n
; ++i
)
14886 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14889 return gdb::array_view
<variant_part
> (result
, n
);
14892 /* Compute the variant part vector for FIP, attaching it to TYPE when
14896 add_variant_property (struct field_info
*fip
, struct type
*type
,
14897 struct dwarf2_cu
*cu
)
14899 /* Map section offsets of fields to their field index. Note the
14900 field index here does not take the number of baseclasses into
14902 offset_map_type offset_map
;
14903 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14904 offset_map
[fip
->fields
[i
].offset
] = i
;
14906 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14907 gdb::array_view
<variant_part
> parts
14908 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14909 fip
->variant_parts
);
14911 struct dynamic_prop prop
;
14912 prop
.kind
= PROP_VARIANT_PARTS
;
14913 prop
.data
.variant_parts
14914 = ((gdb::array_view
<variant_part
> *)
14915 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14917 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14920 /* Create the vector of fields, and attach it to the type. */
14923 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14924 struct dwarf2_cu
*cu
)
14926 int nfields
= fip
->nfields ();
14928 /* Record the field count, allocate space for the array of fields,
14929 and create blank accessibility bitfields if necessary. */
14930 type
->set_num_fields (nfields
);
14932 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14934 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14936 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14938 TYPE_FIELD_PRIVATE_BITS (type
) =
14939 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14940 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14942 TYPE_FIELD_PROTECTED_BITS (type
) =
14943 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14944 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14946 TYPE_FIELD_IGNORE_BITS (type
) =
14947 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14948 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14951 /* If the type has baseclasses, allocate and clear a bit vector for
14952 TYPE_FIELD_VIRTUAL_BITS. */
14953 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14955 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14956 unsigned char *pointer
;
14958 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14959 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14960 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14961 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14962 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14965 if (!fip
->variant_parts
.empty ())
14966 add_variant_property (fip
, type
, cu
);
14968 /* Copy the saved-up fields into the field vector. */
14969 for (int i
= 0; i
< nfields
; ++i
)
14971 struct nextfield
&field
14972 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14973 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14975 type
->field (i
) = field
.field
;
14976 switch (field
.accessibility
)
14978 case DW_ACCESS_private
:
14979 if (cu
->language
!= language_ada
)
14980 SET_TYPE_FIELD_PRIVATE (type
, i
);
14983 case DW_ACCESS_protected
:
14984 if (cu
->language
!= language_ada
)
14985 SET_TYPE_FIELD_PROTECTED (type
, i
);
14988 case DW_ACCESS_public
:
14992 /* Unknown accessibility. Complain and treat it as public. */
14994 complaint (_("unsupported accessibility %d"),
14995 field
.accessibility
);
14999 if (i
< fip
->baseclasses
.size ())
15001 switch (field
.virtuality
)
15003 case DW_VIRTUALITY_virtual
:
15004 case DW_VIRTUALITY_pure_virtual
:
15005 if (cu
->language
== language_ada
)
15006 error (_("unexpected virtuality in component of Ada type"));
15007 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15014 /* Return true if this member function is a constructor, false
15018 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15020 const char *fieldname
;
15021 const char *type_name
;
15024 if (die
->parent
== NULL
)
15027 if (die
->parent
->tag
!= DW_TAG_structure_type
15028 && die
->parent
->tag
!= DW_TAG_union_type
15029 && die
->parent
->tag
!= DW_TAG_class_type
)
15032 fieldname
= dwarf2_name (die
, cu
);
15033 type_name
= dwarf2_name (die
->parent
, cu
);
15034 if (fieldname
== NULL
|| type_name
== NULL
)
15037 len
= strlen (fieldname
);
15038 return (strncmp (fieldname
, type_name
, len
) == 0
15039 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15042 /* Check if the given VALUE is a recognized enum
15043 dwarf_defaulted_attribute constant according to DWARF5 spec,
15047 is_valid_DW_AT_defaulted (ULONGEST value
)
15051 case DW_DEFAULTED_no
:
15052 case DW_DEFAULTED_in_class
:
15053 case DW_DEFAULTED_out_of_class
:
15057 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15061 /* Add a member function to the proper fieldlist. */
15064 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15065 struct type
*type
, struct dwarf2_cu
*cu
)
15067 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15068 struct attribute
*attr
;
15070 struct fnfieldlist
*flp
= nullptr;
15071 struct fn_field
*fnp
;
15072 const char *fieldname
;
15073 struct type
*this_type
;
15074 enum dwarf_access_attribute accessibility
;
15076 if (cu
->language
== language_ada
)
15077 error (_("unexpected member function in Ada type"));
15079 /* Get name of member function. */
15080 fieldname
= dwarf2_name (die
, cu
);
15081 if (fieldname
== NULL
)
15084 /* Look up member function name in fieldlist. */
15085 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15087 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15089 flp
= &fip
->fnfieldlists
[i
];
15094 /* Create a new fnfieldlist if necessary. */
15095 if (flp
== nullptr)
15097 fip
->fnfieldlists
.emplace_back ();
15098 flp
= &fip
->fnfieldlists
.back ();
15099 flp
->name
= fieldname
;
15100 i
= fip
->fnfieldlists
.size () - 1;
15103 /* Create a new member function field and add it to the vector of
15105 flp
->fnfields
.emplace_back ();
15106 fnp
= &flp
->fnfields
.back ();
15108 /* Delay processing of the physname until later. */
15109 if (cu
->language
== language_cplus
)
15110 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15114 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15115 fnp
->physname
= physname
? physname
: "";
15118 fnp
->type
= alloc_type (objfile
);
15119 this_type
= read_type_die (die
, cu
);
15120 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15122 int nparams
= this_type
->num_fields ();
15124 /* TYPE is the domain of this method, and THIS_TYPE is the type
15125 of the method itself (TYPE_CODE_METHOD). */
15126 smash_to_method_type (fnp
->type
, type
,
15127 TYPE_TARGET_TYPE (this_type
),
15128 this_type
->fields (),
15129 this_type
->num_fields (),
15130 TYPE_VARARGS (this_type
));
15132 /* Handle static member functions.
15133 Dwarf2 has no clean way to discern C++ static and non-static
15134 member functions. G++ helps GDB by marking the first
15135 parameter for non-static member functions (which is the this
15136 pointer) as artificial. We obtain this information from
15137 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15138 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15139 fnp
->voffset
= VOFFSET_STATIC
;
15142 complaint (_("member function type missing for '%s'"),
15143 dwarf2_full_name (fieldname
, die
, cu
));
15145 /* Get fcontext from DW_AT_containing_type if present. */
15146 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15147 fnp
->fcontext
= die_containing_type (die
, cu
);
15149 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15150 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15152 /* Get accessibility. */
15153 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15154 if (attr
!= nullptr)
15155 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15157 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15158 switch (accessibility
)
15160 case DW_ACCESS_private
:
15161 fnp
->is_private
= 1;
15163 case DW_ACCESS_protected
:
15164 fnp
->is_protected
= 1;
15168 /* Check for artificial methods. */
15169 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15170 if (attr
&& DW_UNSND (attr
) != 0)
15171 fnp
->is_artificial
= 1;
15173 /* Check for defaulted methods. */
15174 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15175 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15176 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15178 /* Check for deleted methods. */
15179 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15180 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15181 fnp
->is_deleted
= 1;
15183 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15185 /* Get index in virtual function table if it is a virtual member
15186 function. For older versions of GCC, this is an offset in the
15187 appropriate virtual table, as specified by DW_AT_containing_type.
15188 For everyone else, it is an expression to be evaluated relative
15189 to the object address. */
15191 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15192 if (attr
!= nullptr)
15194 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15196 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15198 /* Old-style GCC. */
15199 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15201 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15202 || (DW_BLOCK (attr
)->size
> 1
15203 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15204 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15206 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15207 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15208 dwarf2_complex_location_expr_complaint ();
15210 fnp
->voffset
/= cu
->header
.addr_size
;
15214 dwarf2_complex_location_expr_complaint ();
15216 if (!fnp
->fcontext
)
15218 /* If there is no `this' field and no DW_AT_containing_type,
15219 we cannot actually find a base class context for the
15221 if (this_type
->num_fields () == 0
15222 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15224 complaint (_("cannot determine context for virtual member "
15225 "function \"%s\" (offset %s)"),
15226 fieldname
, sect_offset_str (die
->sect_off
));
15231 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15235 else if (attr
->form_is_section_offset ())
15237 dwarf2_complex_location_expr_complaint ();
15241 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15247 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15248 if (attr
&& DW_UNSND (attr
))
15250 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15251 complaint (_("Member function \"%s\" (offset %s) is virtual "
15252 "but the vtable offset is not specified"),
15253 fieldname
, sect_offset_str (die
->sect_off
));
15254 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15255 TYPE_CPLUS_DYNAMIC (type
) = 1;
15260 /* Create the vector of member function fields, and attach it to the type. */
15263 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15264 struct dwarf2_cu
*cu
)
15266 if (cu
->language
== language_ada
)
15267 error (_("unexpected member functions in Ada type"));
15269 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15270 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15272 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15274 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15276 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15277 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15279 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15280 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15281 fn_flp
->fn_fields
= (struct fn_field
*)
15282 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15284 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15285 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15288 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15291 /* Returns non-zero if NAME is the name of a vtable member in CU's
15292 language, zero otherwise. */
15294 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15296 static const char vptr
[] = "_vptr";
15298 /* Look for the C++ form of the vtable. */
15299 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15305 /* GCC outputs unnamed structures that are really pointers to member
15306 functions, with the ABI-specified layout. If TYPE describes
15307 such a structure, smash it into a member function type.
15309 GCC shouldn't do this; it should just output pointer to member DIEs.
15310 This is GCC PR debug/28767. */
15313 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15315 struct type
*pfn_type
, *self_type
, *new_type
;
15317 /* Check for a structure with no name and two children. */
15318 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15321 /* Check for __pfn and __delta members. */
15322 if (TYPE_FIELD_NAME (type
, 0) == NULL
15323 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15324 || TYPE_FIELD_NAME (type
, 1) == NULL
15325 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15328 /* Find the type of the method. */
15329 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15330 if (pfn_type
== NULL
15331 || pfn_type
->code () != TYPE_CODE_PTR
15332 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15335 /* Look for the "this" argument. */
15336 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15337 if (pfn_type
->num_fields () == 0
15338 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15339 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15342 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15343 new_type
= alloc_type (objfile
);
15344 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15345 pfn_type
->fields (), pfn_type
->num_fields (),
15346 TYPE_VARARGS (pfn_type
));
15347 smash_to_methodptr_type (type
, new_type
);
15350 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15351 appropriate error checking and issuing complaints if there is a
15355 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15357 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15359 if (attr
== nullptr)
15362 if (!attr
->form_is_constant ())
15364 complaint (_("DW_AT_alignment must have constant form"
15365 " - DIE at %s [in module %s]"),
15366 sect_offset_str (die
->sect_off
),
15367 objfile_name (cu
->per_objfile
->objfile
));
15372 if (attr
->form
== DW_FORM_sdata
)
15374 LONGEST val
= DW_SND (attr
);
15377 complaint (_("DW_AT_alignment value must not be negative"
15378 " - DIE at %s [in module %s]"),
15379 sect_offset_str (die
->sect_off
),
15380 objfile_name (cu
->per_objfile
->objfile
));
15386 align
= DW_UNSND (attr
);
15390 complaint (_("DW_AT_alignment value must not be zero"
15391 " - DIE at %s [in module %s]"),
15392 sect_offset_str (die
->sect_off
),
15393 objfile_name (cu
->per_objfile
->objfile
));
15396 if ((align
& (align
- 1)) != 0)
15398 complaint (_("DW_AT_alignment value must be a power of 2"
15399 " - DIE at %s [in module %s]"),
15400 sect_offset_str (die
->sect_off
),
15401 objfile_name (cu
->per_objfile
->objfile
));
15408 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15409 the alignment for TYPE. */
15412 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15415 if (!set_type_align (type
, get_alignment (cu
, die
)))
15416 complaint (_("DW_AT_alignment value too large"
15417 " - DIE at %s [in module %s]"),
15418 sect_offset_str (die
->sect_off
),
15419 objfile_name (cu
->per_objfile
->objfile
));
15422 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15423 constant for a type, according to DWARF5 spec, Table 5.5. */
15426 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15431 case DW_CC_pass_by_reference
:
15432 case DW_CC_pass_by_value
:
15436 complaint (_("unrecognized DW_AT_calling_convention value "
15437 "(%s) for a type"), pulongest (value
));
15442 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15443 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15444 also according to GNU-specific values (see include/dwarf2.h). */
15447 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15452 case DW_CC_program
:
15456 case DW_CC_GNU_renesas_sh
:
15457 case DW_CC_GNU_borland_fastcall_i386
:
15458 case DW_CC_GDB_IBM_OpenCL
:
15462 complaint (_("unrecognized DW_AT_calling_convention value "
15463 "(%s) for a subroutine"), pulongest (value
));
15468 /* Called when we find the DIE that starts a structure or union scope
15469 (definition) to create a type for the structure or union. Fill in
15470 the type's name and general properties; the members will not be
15471 processed until process_structure_scope. A symbol table entry for
15472 the type will also not be done until process_structure_scope (assuming
15473 the type has a name).
15475 NOTE: we need to call these functions regardless of whether or not the
15476 DIE has a DW_AT_name attribute, since it might be an anonymous
15477 structure or union. This gets the type entered into our set of
15478 user defined types. */
15480 static struct type
*
15481 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15483 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15485 struct attribute
*attr
;
15488 /* If the definition of this type lives in .debug_types, read that type.
15489 Don't follow DW_AT_specification though, that will take us back up
15490 the chain and we want to go down. */
15491 attr
= die
->attr (DW_AT_signature
);
15492 if (attr
!= nullptr)
15494 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15496 /* The type's CU may not be the same as CU.
15497 Ensure TYPE is recorded with CU in die_type_hash. */
15498 return set_die_type (die
, type
, cu
);
15501 type
= alloc_type (objfile
);
15502 INIT_CPLUS_SPECIFIC (type
);
15504 name
= dwarf2_name (die
, cu
);
15507 if (cu
->language
== language_cplus
15508 || cu
->language
== language_d
15509 || cu
->language
== language_rust
)
15511 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15513 /* dwarf2_full_name might have already finished building the DIE's
15514 type. If so, there is no need to continue. */
15515 if (get_die_type (die
, cu
) != NULL
)
15516 return get_die_type (die
, cu
);
15518 type
->set_name (full_name
);
15522 /* The name is already allocated along with this objfile, so
15523 we don't need to duplicate it for the type. */
15524 type
->set_name (name
);
15528 if (die
->tag
== DW_TAG_structure_type
)
15530 type
->set_code (TYPE_CODE_STRUCT
);
15532 else if (die
->tag
== DW_TAG_union_type
)
15534 type
->set_code (TYPE_CODE_UNION
);
15538 type
->set_code (TYPE_CODE_STRUCT
);
15541 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15542 TYPE_DECLARED_CLASS (type
) = 1;
15544 /* Store the calling convention in the type if it's available in
15545 the die. Otherwise the calling convention remains set to
15546 the default value DW_CC_normal. */
15547 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15548 if (attr
!= nullptr
15549 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15551 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15552 TYPE_CPLUS_CALLING_CONVENTION (type
)
15553 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15556 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15557 if (attr
!= nullptr)
15559 if (attr
->form_is_constant ())
15560 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15563 struct dynamic_prop prop
;
15564 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15565 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15566 TYPE_LENGTH (type
) = 0;
15571 TYPE_LENGTH (type
) = 0;
15574 maybe_set_alignment (cu
, die
, type
);
15576 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15578 /* ICC<14 does not output the required DW_AT_declaration on
15579 incomplete types, but gives them a size of zero. */
15580 TYPE_STUB (type
) = 1;
15583 TYPE_STUB_SUPPORTED (type
) = 1;
15585 if (die_is_declaration (die
, cu
))
15586 TYPE_STUB (type
) = 1;
15587 else if (attr
== NULL
&& die
->child
== NULL
15588 && producer_is_realview (cu
->producer
))
15589 /* RealView does not output the required DW_AT_declaration
15590 on incomplete types. */
15591 TYPE_STUB (type
) = 1;
15593 /* We need to add the type field to the die immediately so we don't
15594 infinitely recurse when dealing with pointers to the structure
15595 type within the structure itself. */
15596 set_die_type (die
, type
, cu
);
15598 /* set_die_type should be already done. */
15599 set_descriptive_type (type
, die
, cu
);
15604 static void handle_struct_member_die
15605 (struct die_info
*child_die
,
15607 struct field_info
*fi
,
15608 std::vector
<struct symbol
*> *template_args
,
15609 struct dwarf2_cu
*cu
);
15611 /* A helper for handle_struct_member_die that handles
15612 DW_TAG_variant_part. */
15615 handle_variant_part (struct die_info
*die
, struct type
*type
,
15616 struct field_info
*fi
,
15617 std::vector
<struct symbol
*> *template_args
,
15618 struct dwarf2_cu
*cu
)
15620 variant_part_builder
*new_part
;
15621 if (fi
->current_variant_part
== nullptr)
15623 fi
->variant_parts
.emplace_back ();
15624 new_part
= &fi
->variant_parts
.back ();
15626 else if (!fi
->current_variant_part
->processing_variant
)
15628 complaint (_("nested DW_TAG_variant_part seen "
15629 "- DIE at %s [in module %s]"),
15630 sect_offset_str (die
->sect_off
),
15631 objfile_name (cu
->per_objfile
->objfile
));
15636 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15637 current
.variant_parts
.emplace_back ();
15638 new_part
= ¤t
.variant_parts
.back ();
15641 /* When we recurse, we want callees to add to this new variant
15643 scoped_restore save_current_variant_part
15644 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15646 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15649 /* It's a univariant form, an extension we support. */
15651 else if (discr
->form_is_ref ())
15653 struct dwarf2_cu
*target_cu
= cu
;
15654 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15656 new_part
->discriminant_offset
= target_die
->sect_off
;
15660 complaint (_("DW_AT_discr does not have DIE reference form"
15661 " - DIE at %s [in module %s]"),
15662 sect_offset_str (die
->sect_off
),
15663 objfile_name (cu
->per_objfile
->objfile
));
15666 for (die_info
*child_die
= die
->child
;
15668 child_die
= child_die
->sibling
)
15669 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15672 /* A helper for handle_struct_member_die that handles
15676 handle_variant (struct die_info
*die
, struct type
*type
,
15677 struct field_info
*fi
,
15678 std::vector
<struct symbol
*> *template_args
,
15679 struct dwarf2_cu
*cu
)
15681 if (fi
->current_variant_part
== nullptr)
15683 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15684 "- DIE at %s [in module %s]"),
15685 sect_offset_str (die
->sect_off
),
15686 objfile_name (cu
->per_objfile
->objfile
));
15689 if (fi
->current_variant_part
->processing_variant
)
15691 complaint (_("nested DW_TAG_variant seen "
15692 "- DIE at %s [in module %s]"),
15693 sect_offset_str (die
->sect_off
),
15694 objfile_name (cu
->per_objfile
->objfile
));
15698 scoped_restore save_processing_variant
15699 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15702 fi
->current_variant_part
->variants
.emplace_back ();
15703 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15704 variant
.first_field
= fi
->fields
.size ();
15706 /* In a variant we want to get the discriminant and also add a
15707 field for our sole member child. */
15708 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15709 if (discr
== nullptr)
15711 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15712 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15713 variant
.default_branch
= true;
15715 variant
.discr_list_data
= DW_BLOCK (discr
);
15718 variant
.discriminant_value
= DW_UNSND (discr
);
15720 for (die_info
*variant_child
= die
->child
;
15721 variant_child
!= NULL
;
15722 variant_child
= variant_child
->sibling
)
15723 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15725 variant
.last_field
= fi
->fields
.size ();
15728 /* A helper for process_structure_scope that handles a single member
15732 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15733 struct field_info
*fi
,
15734 std::vector
<struct symbol
*> *template_args
,
15735 struct dwarf2_cu
*cu
)
15737 if (child_die
->tag
== DW_TAG_member
15738 || child_die
->tag
== DW_TAG_variable
)
15740 /* NOTE: carlton/2002-11-05: A C++ static data member
15741 should be a DW_TAG_member that is a declaration, but
15742 all versions of G++ as of this writing (so through at
15743 least 3.2.1) incorrectly generate DW_TAG_variable
15744 tags for them instead. */
15745 dwarf2_add_field (fi
, child_die
, cu
);
15747 else if (child_die
->tag
== DW_TAG_subprogram
)
15749 /* Rust doesn't have member functions in the C++ sense.
15750 However, it does emit ordinary functions as children
15751 of a struct DIE. */
15752 if (cu
->language
== language_rust
)
15753 read_func_scope (child_die
, cu
);
15756 /* C++ member function. */
15757 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15760 else if (child_die
->tag
== DW_TAG_inheritance
)
15762 /* C++ base class field. */
15763 dwarf2_add_field (fi
, child_die
, cu
);
15765 else if (type_can_define_types (child_die
))
15766 dwarf2_add_type_defn (fi
, child_die
, cu
);
15767 else if (child_die
->tag
== DW_TAG_template_type_param
15768 || child_die
->tag
== DW_TAG_template_value_param
)
15770 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15773 template_args
->push_back (arg
);
15775 else if (child_die
->tag
== DW_TAG_variant_part
)
15776 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15777 else if (child_die
->tag
== DW_TAG_variant
)
15778 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15781 /* Finish creating a structure or union type, including filling in
15782 its members and creating a symbol for it. */
15785 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15787 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15788 struct die_info
*child_die
;
15791 type
= get_die_type (die
, cu
);
15793 type
= read_structure_type (die
, cu
);
15795 bool has_template_parameters
= false;
15796 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15798 struct field_info fi
;
15799 std::vector
<struct symbol
*> template_args
;
15801 child_die
= die
->child
;
15803 while (child_die
&& child_die
->tag
)
15805 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15806 child_die
= child_die
->sibling
;
15809 /* Attach template arguments to type. */
15810 if (!template_args
.empty ())
15812 has_template_parameters
= true;
15813 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15814 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15815 TYPE_TEMPLATE_ARGUMENTS (type
)
15816 = XOBNEWVEC (&objfile
->objfile_obstack
,
15818 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15819 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15820 template_args
.data (),
15821 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15822 * sizeof (struct symbol
*)));
15825 /* Attach fields and member functions to the type. */
15826 if (fi
.nfields () > 0)
15827 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15828 if (!fi
.fnfieldlists
.empty ())
15830 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15832 /* Get the type which refers to the base class (possibly this
15833 class itself) which contains the vtable pointer for the current
15834 class from the DW_AT_containing_type attribute. This use of
15835 DW_AT_containing_type is a GNU extension. */
15837 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15839 struct type
*t
= die_containing_type (die
, cu
);
15841 set_type_vptr_basetype (type
, t
);
15846 /* Our own class provides vtbl ptr. */
15847 for (i
= t
->num_fields () - 1;
15848 i
>= TYPE_N_BASECLASSES (t
);
15851 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15853 if (is_vtable_name (fieldname
, cu
))
15855 set_type_vptr_fieldno (type
, i
);
15860 /* Complain if virtual function table field not found. */
15861 if (i
< TYPE_N_BASECLASSES (t
))
15862 complaint (_("virtual function table pointer "
15863 "not found when defining class '%s'"),
15864 type
->name () ? type
->name () : "");
15868 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15871 else if (cu
->producer
15872 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15874 /* The IBM XLC compiler does not provide direct indication
15875 of the containing type, but the vtable pointer is
15876 always named __vfp. */
15880 for (i
= type
->num_fields () - 1;
15881 i
>= TYPE_N_BASECLASSES (type
);
15884 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15886 set_type_vptr_fieldno (type
, i
);
15887 set_type_vptr_basetype (type
, type
);
15894 /* Copy fi.typedef_field_list linked list elements content into the
15895 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15896 if (!fi
.typedef_field_list
.empty ())
15898 int count
= fi
.typedef_field_list
.size ();
15900 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15901 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15902 = ((struct decl_field
*)
15904 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15905 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15907 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15908 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15911 /* Copy fi.nested_types_list linked list elements content into the
15912 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15913 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15915 int count
= fi
.nested_types_list
.size ();
15917 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15918 TYPE_NESTED_TYPES_ARRAY (type
)
15919 = ((struct decl_field
*)
15920 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15921 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15923 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15924 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15928 quirk_gcc_member_function_pointer (type
, objfile
);
15929 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15930 cu
->rust_unions
.push_back (type
);
15932 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15933 snapshots) has been known to create a die giving a declaration
15934 for a class that has, as a child, a die giving a definition for a
15935 nested class. So we have to process our children even if the
15936 current die is a declaration. Normally, of course, a declaration
15937 won't have any children at all. */
15939 child_die
= die
->child
;
15941 while (child_die
!= NULL
&& child_die
->tag
)
15943 if (child_die
->tag
== DW_TAG_member
15944 || child_die
->tag
== DW_TAG_variable
15945 || child_die
->tag
== DW_TAG_inheritance
15946 || child_die
->tag
== DW_TAG_template_value_param
15947 || child_die
->tag
== DW_TAG_template_type_param
)
15952 process_die (child_die
, cu
);
15954 child_die
= child_die
->sibling
;
15957 /* Do not consider external references. According to the DWARF standard,
15958 these DIEs are identified by the fact that they have no byte_size
15959 attribute, and a declaration attribute. */
15960 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15961 || !die_is_declaration (die
, cu
)
15962 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15964 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15966 if (has_template_parameters
)
15968 struct symtab
*symtab
;
15969 if (sym
!= nullptr)
15970 symtab
= symbol_symtab (sym
);
15971 else if (cu
->line_header
!= nullptr)
15973 /* Any related symtab will do. */
15975 = cu
->line_header
->file_names ()[0].symtab
;
15980 complaint (_("could not find suitable "
15981 "symtab for template parameter"
15982 " - DIE at %s [in module %s]"),
15983 sect_offset_str (die
->sect_off
),
15984 objfile_name (objfile
));
15987 if (symtab
!= nullptr)
15989 /* Make sure that the symtab is set on the new symbols.
15990 Even though they don't appear in this symtab directly,
15991 other parts of gdb assume that symbols do, and this is
15992 reasonably true. */
15993 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15994 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16000 /* Assuming DIE is an enumeration type, and TYPE is its associated
16001 type, update TYPE using some information only available in DIE's
16002 children. In particular, the fields are computed. */
16005 update_enumeration_type_from_children (struct die_info
*die
,
16007 struct dwarf2_cu
*cu
)
16009 struct die_info
*child_die
;
16010 int unsigned_enum
= 1;
16013 auto_obstack obstack
;
16014 std::vector
<struct field
> fields
;
16016 for (child_die
= die
->child
;
16017 child_die
!= NULL
&& child_die
->tag
;
16018 child_die
= child_die
->sibling
)
16020 struct attribute
*attr
;
16022 const gdb_byte
*bytes
;
16023 struct dwarf2_locexpr_baton
*baton
;
16026 if (child_die
->tag
!= DW_TAG_enumerator
)
16029 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16033 name
= dwarf2_name (child_die
, cu
);
16035 name
= "<anonymous enumerator>";
16037 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16038 &value
, &bytes
, &baton
);
16046 if (count_one_bits_ll (value
) >= 2)
16050 fields
.emplace_back ();
16051 struct field
&field
= fields
.back ();
16052 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16053 SET_FIELD_ENUMVAL (field
, value
);
16056 if (!fields
.empty ())
16058 type
->set_num_fields (fields
.size ());
16061 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16062 memcpy (type
->fields (), fields
.data (),
16063 sizeof (struct field
) * fields
.size ());
16067 TYPE_UNSIGNED (type
) = 1;
16069 TYPE_FLAG_ENUM (type
) = 1;
16072 /* Given a DW_AT_enumeration_type die, set its type. We do not
16073 complete the type's fields yet, or create any symbols. */
16075 static struct type
*
16076 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16078 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16080 struct attribute
*attr
;
16083 /* If the definition of this type lives in .debug_types, read that type.
16084 Don't follow DW_AT_specification though, that will take us back up
16085 the chain and we want to go down. */
16086 attr
= die
->attr (DW_AT_signature
);
16087 if (attr
!= nullptr)
16089 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16091 /* The type's CU may not be the same as CU.
16092 Ensure TYPE is recorded with CU in die_type_hash. */
16093 return set_die_type (die
, type
, cu
);
16096 type
= alloc_type (objfile
);
16098 type
->set_code (TYPE_CODE_ENUM
);
16099 name
= dwarf2_full_name (NULL
, die
, cu
);
16101 type
->set_name (name
);
16103 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16106 struct type
*underlying_type
= die_type (die
, cu
);
16108 TYPE_TARGET_TYPE (type
) = underlying_type
;
16111 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16112 if (attr
!= nullptr)
16114 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16118 TYPE_LENGTH (type
) = 0;
16121 maybe_set_alignment (cu
, die
, type
);
16123 /* The enumeration DIE can be incomplete. In Ada, any type can be
16124 declared as private in the package spec, and then defined only
16125 inside the package body. Such types are known as Taft Amendment
16126 Types. When another package uses such a type, an incomplete DIE
16127 may be generated by the compiler. */
16128 if (die_is_declaration (die
, cu
))
16129 TYPE_STUB (type
) = 1;
16131 /* If this type has an underlying type that is not a stub, then we
16132 may use its attributes. We always use the "unsigned" attribute
16133 in this situation, because ordinarily we guess whether the type
16134 is unsigned -- but the guess can be wrong and the underlying type
16135 can tell us the reality. However, we defer to a local size
16136 attribute if one exists, because this lets the compiler override
16137 the underlying type if needed. */
16138 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16140 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16141 underlying_type
= check_typedef (underlying_type
);
16142 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16143 if (TYPE_LENGTH (type
) == 0)
16144 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16145 if (TYPE_RAW_ALIGN (type
) == 0
16146 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16147 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16150 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16152 set_die_type (die
, type
, cu
);
16154 /* Finish the creation of this type by using the enum's children.
16155 Note that, as usual, this must come after set_die_type to avoid
16156 infinite recursion when trying to compute the names of the
16158 update_enumeration_type_from_children (die
, type
, cu
);
16163 /* Given a pointer to a die which begins an enumeration, process all
16164 the dies that define the members of the enumeration, and create the
16165 symbol for the enumeration type.
16167 NOTE: We reverse the order of the element list. */
16170 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16172 struct type
*this_type
;
16174 this_type
= get_die_type (die
, cu
);
16175 if (this_type
== NULL
)
16176 this_type
= read_enumeration_type (die
, cu
);
16178 if (die
->child
!= NULL
)
16180 struct die_info
*child_die
;
16183 child_die
= die
->child
;
16184 while (child_die
&& child_die
->tag
)
16186 if (child_die
->tag
!= DW_TAG_enumerator
)
16188 process_die (child_die
, cu
);
16192 name
= dwarf2_name (child_die
, cu
);
16194 new_symbol (child_die
, this_type
, cu
);
16197 child_die
= child_die
->sibling
;
16201 /* If we are reading an enum from a .debug_types unit, and the enum
16202 is a declaration, and the enum is not the signatured type in the
16203 unit, then we do not want to add a symbol for it. Adding a
16204 symbol would in some cases obscure the true definition of the
16205 enum, giving users an incomplete type when the definition is
16206 actually available. Note that we do not want to do this for all
16207 enums which are just declarations, because C++0x allows forward
16208 enum declarations. */
16209 if (cu
->per_cu
->is_debug_types
16210 && die_is_declaration (die
, cu
))
16212 struct signatured_type
*sig_type
;
16214 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16215 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16216 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16220 new_symbol (die
, this_type
, cu
);
16223 /* Extract all information from a DW_TAG_array_type DIE and put it in
16224 the DIE's type field. For now, this only handles one dimensional
16227 static struct type
*
16228 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16230 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16231 struct die_info
*child_die
;
16233 struct type
*element_type
, *range_type
, *index_type
;
16234 struct attribute
*attr
;
16236 struct dynamic_prop
*byte_stride_prop
= NULL
;
16237 unsigned int bit_stride
= 0;
16239 element_type
= die_type (die
, cu
);
16241 /* The die_type call above may have already set the type for this DIE. */
16242 type
= get_die_type (die
, cu
);
16246 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16250 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16253 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16254 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16258 complaint (_("unable to read array DW_AT_byte_stride "
16259 " - DIE at %s [in module %s]"),
16260 sect_offset_str (die
->sect_off
),
16261 objfile_name (cu
->per_objfile
->objfile
));
16262 /* Ignore this attribute. We will likely not be able to print
16263 arrays of this type correctly, but there is little we can do
16264 to help if we cannot read the attribute's value. */
16265 byte_stride_prop
= NULL
;
16269 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16271 bit_stride
= DW_UNSND (attr
);
16273 /* Irix 6.2 native cc creates array types without children for
16274 arrays with unspecified length. */
16275 if (die
->child
== NULL
)
16277 index_type
= objfile_type (objfile
)->builtin_int
;
16278 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16279 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16280 byte_stride_prop
, bit_stride
);
16281 return set_die_type (die
, type
, cu
);
16284 std::vector
<struct type
*> range_types
;
16285 child_die
= die
->child
;
16286 while (child_die
&& child_die
->tag
)
16288 if (child_die
->tag
== DW_TAG_subrange_type
)
16290 struct type
*child_type
= read_type_die (child_die
, cu
);
16292 if (child_type
!= NULL
)
16294 /* The range type was succesfully read. Save it for the
16295 array type creation. */
16296 range_types
.push_back (child_type
);
16299 child_die
= child_die
->sibling
;
16302 /* Dwarf2 dimensions are output from left to right, create the
16303 necessary array types in backwards order. */
16305 type
= element_type
;
16307 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16311 while (i
< range_types
.size ())
16312 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16313 byte_stride_prop
, bit_stride
);
16317 size_t ndim
= range_types
.size ();
16319 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16320 byte_stride_prop
, bit_stride
);
16323 /* Understand Dwarf2 support for vector types (like they occur on
16324 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16325 array type. This is not part of the Dwarf2/3 standard yet, but a
16326 custom vendor extension. The main difference between a regular
16327 array and the vector variant is that vectors are passed by value
16329 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16330 if (attr
!= nullptr)
16331 make_vector_type (type
);
16333 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16334 implementation may choose to implement triple vectors using this
16336 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16337 if (attr
!= nullptr)
16339 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16340 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16342 complaint (_("DW_AT_byte_size for array type smaller "
16343 "than the total size of elements"));
16346 name
= dwarf2_name (die
, cu
);
16348 type
->set_name (name
);
16350 maybe_set_alignment (cu
, die
, type
);
16352 /* Install the type in the die. */
16353 set_die_type (die
, type
, cu
);
16355 /* set_die_type should be already done. */
16356 set_descriptive_type (type
, die
, cu
);
16361 static enum dwarf_array_dim_ordering
16362 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16364 struct attribute
*attr
;
16366 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16368 if (attr
!= nullptr)
16369 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16371 /* GNU F77 is a special case, as at 08/2004 array type info is the
16372 opposite order to the dwarf2 specification, but data is still
16373 laid out as per normal fortran.
16375 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16376 version checking. */
16378 if (cu
->language
== language_fortran
16379 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16381 return DW_ORD_row_major
;
16384 switch (cu
->language_defn
->la_array_ordering
)
16386 case array_column_major
:
16387 return DW_ORD_col_major
;
16388 case array_row_major
:
16390 return DW_ORD_row_major
;
16394 /* Extract all information from a DW_TAG_set_type DIE and put it in
16395 the DIE's type field. */
16397 static struct type
*
16398 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16400 struct type
*domain_type
, *set_type
;
16401 struct attribute
*attr
;
16403 domain_type
= die_type (die
, cu
);
16405 /* The die_type call above may have already set the type for this DIE. */
16406 set_type
= get_die_type (die
, cu
);
16410 set_type
= create_set_type (NULL
, domain_type
);
16412 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16413 if (attr
!= nullptr)
16414 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16416 maybe_set_alignment (cu
, die
, set_type
);
16418 return set_die_type (die
, set_type
, cu
);
16421 /* A helper for read_common_block that creates a locexpr baton.
16422 SYM is the symbol which we are marking as computed.
16423 COMMON_DIE is the DIE for the common block.
16424 COMMON_LOC is the location expression attribute for the common
16426 MEMBER_LOC is the location expression attribute for the particular
16427 member of the common block that we are processing.
16428 CU is the CU from which the above come. */
16431 mark_common_block_symbol_computed (struct symbol
*sym
,
16432 struct die_info
*common_die
,
16433 struct attribute
*common_loc
,
16434 struct attribute
*member_loc
,
16435 struct dwarf2_cu
*cu
)
16437 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16438 struct objfile
*objfile
= per_objfile
->objfile
;
16439 struct dwarf2_locexpr_baton
*baton
;
16441 unsigned int cu_off
;
16442 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16443 LONGEST offset
= 0;
16445 gdb_assert (common_loc
&& member_loc
);
16446 gdb_assert (common_loc
->form_is_block ());
16447 gdb_assert (member_loc
->form_is_block ()
16448 || member_loc
->form_is_constant ());
16450 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16451 baton
->per_objfile
= per_objfile
;
16452 baton
->per_cu
= cu
->per_cu
;
16453 gdb_assert (baton
->per_cu
);
16455 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16457 if (member_loc
->form_is_constant ())
16459 offset
= member_loc
->constant_value (0);
16460 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16463 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16465 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16468 *ptr
++ = DW_OP_call4
;
16469 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16470 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16473 if (member_loc
->form_is_constant ())
16475 *ptr
++ = DW_OP_addr
;
16476 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16477 ptr
+= cu
->header
.addr_size
;
16481 /* We have to copy the data here, because DW_OP_call4 will only
16482 use a DW_AT_location attribute. */
16483 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16484 ptr
+= DW_BLOCK (member_loc
)->size
;
16487 *ptr
++ = DW_OP_plus
;
16488 gdb_assert (ptr
- baton
->data
== baton
->size
);
16490 SYMBOL_LOCATION_BATON (sym
) = baton
;
16491 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16494 /* Create appropriate locally-scoped variables for all the
16495 DW_TAG_common_block entries. Also create a struct common_block
16496 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16497 is used to separate the common blocks name namespace from regular
16501 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16503 struct attribute
*attr
;
16505 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16506 if (attr
!= nullptr)
16508 /* Support the .debug_loc offsets. */
16509 if (attr
->form_is_block ())
16513 else if (attr
->form_is_section_offset ())
16515 dwarf2_complex_location_expr_complaint ();
16520 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16521 "common block member");
16526 if (die
->child
!= NULL
)
16528 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16529 struct die_info
*child_die
;
16530 size_t n_entries
= 0, size
;
16531 struct common_block
*common_block
;
16532 struct symbol
*sym
;
16534 for (child_die
= die
->child
;
16535 child_die
&& child_die
->tag
;
16536 child_die
= child_die
->sibling
)
16539 size
= (sizeof (struct common_block
)
16540 + (n_entries
- 1) * sizeof (struct symbol
*));
16542 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16544 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16545 common_block
->n_entries
= 0;
16547 for (child_die
= die
->child
;
16548 child_die
&& child_die
->tag
;
16549 child_die
= child_die
->sibling
)
16551 /* Create the symbol in the DW_TAG_common_block block in the current
16553 sym
= new_symbol (child_die
, NULL
, cu
);
16556 struct attribute
*member_loc
;
16558 common_block
->contents
[common_block
->n_entries
++] = sym
;
16560 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16564 /* GDB has handled this for a long time, but it is
16565 not specified by DWARF. It seems to have been
16566 emitted by gfortran at least as recently as:
16567 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16568 complaint (_("Variable in common block has "
16569 "DW_AT_data_member_location "
16570 "- DIE at %s [in module %s]"),
16571 sect_offset_str (child_die
->sect_off
),
16572 objfile_name (objfile
));
16574 if (member_loc
->form_is_section_offset ())
16575 dwarf2_complex_location_expr_complaint ();
16576 else if (member_loc
->form_is_constant ()
16577 || member_loc
->form_is_block ())
16579 if (attr
!= nullptr)
16580 mark_common_block_symbol_computed (sym
, die
, attr
,
16584 dwarf2_complex_location_expr_complaint ();
16589 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16590 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16594 /* Create a type for a C++ namespace. */
16596 static struct type
*
16597 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16599 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16600 const char *previous_prefix
, *name
;
16604 /* For extensions, reuse the type of the original namespace. */
16605 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16607 struct die_info
*ext_die
;
16608 struct dwarf2_cu
*ext_cu
= cu
;
16610 ext_die
= dwarf2_extension (die
, &ext_cu
);
16611 type
= read_type_die (ext_die
, ext_cu
);
16613 /* EXT_CU may not be the same as CU.
16614 Ensure TYPE is recorded with CU in die_type_hash. */
16615 return set_die_type (die
, type
, cu
);
16618 name
= namespace_name (die
, &is_anonymous
, cu
);
16620 /* Now build the name of the current namespace. */
16622 previous_prefix
= determine_prefix (die
, cu
);
16623 if (previous_prefix
[0] != '\0')
16624 name
= typename_concat (&objfile
->objfile_obstack
,
16625 previous_prefix
, name
, 0, cu
);
16627 /* Create the type. */
16628 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16630 return set_die_type (die
, type
, cu
);
16633 /* Read a namespace scope. */
16636 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16638 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16641 /* Add a symbol associated to this if we haven't seen the namespace
16642 before. Also, add a using directive if it's an anonymous
16645 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16649 type
= read_type_die (die
, cu
);
16650 new_symbol (die
, type
, cu
);
16652 namespace_name (die
, &is_anonymous
, cu
);
16655 const char *previous_prefix
= determine_prefix (die
, cu
);
16657 std::vector
<const char *> excludes
;
16658 add_using_directive (using_directives (cu
),
16659 previous_prefix
, type
->name (), NULL
,
16660 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16664 if (die
->child
!= NULL
)
16666 struct die_info
*child_die
= die
->child
;
16668 while (child_die
&& child_die
->tag
)
16670 process_die (child_die
, cu
);
16671 child_die
= child_die
->sibling
;
16676 /* Read a Fortran module as type. This DIE can be only a declaration used for
16677 imported module. Still we need that type as local Fortran "use ... only"
16678 declaration imports depend on the created type in determine_prefix. */
16680 static struct type
*
16681 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16683 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16684 const char *module_name
;
16687 module_name
= dwarf2_name (die
, cu
);
16688 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16690 return set_die_type (die
, type
, cu
);
16693 /* Read a Fortran module. */
16696 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16698 struct die_info
*child_die
= die
->child
;
16701 type
= read_type_die (die
, cu
);
16702 new_symbol (die
, type
, cu
);
16704 while (child_die
&& child_die
->tag
)
16706 process_die (child_die
, cu
);
16707 child_die
= child_die
->sibling
;
16711 /* Return the name of the namespace represented by DIE. Set
16712 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16715 static const char *
16716 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16718 struct die_info
*current_die
;
16719 const char *name
= NULL
;
16721 /* Loop through the extensions until we find a name. */
16723 for (current_die
= die
;
16724 current_die
!= NULL
;
16725 current_die
= dwarf2_extension (die
, &cu
))
16727 /* We don't use dwarf2_name here so that we can detect the absence
16728 of a name -> anonymous namespace. */
16729 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16735 /* Is it an anonymous namespace? */
16737 *is_anonymous
= (name
== NULL
);
16739 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16744 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16745 the user defined type vector. */
16747 static struct type
*
16748 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16750 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16751 struct comp_unit_head
*cu_header
= &cu
->header
;
16753 struct attribute
*attr_byte_size
;
16754 struct attribute
*attr_address_class
;
16755 int byte_size
, addr_class
;
16756 struct type
*target_type
;
16758 target_type
= die_type (die
, cu
);
16760 /* The die_type call above may have already set the type for this DIE. */
16761 type
= get_die_type (die
, cu
);
16765 type
= lookup_pointer_type (target_type
);
16767 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16768 if (attr_byte_size
)
16769 byte_size
= DW_UNSND (attr_byte_size
);
16771 byte_size
= cu_header
->addr_size
;
16773 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16774 if (attr_address_class
)
16775 addr_class
= DW_UNSND (attr_address_class
);
16777 addr_class
= DW_ADDR_none
;
16779 ULONGEST alignment
= get_alignment (cu
, die
);
16781 /* If the pointer size, alignment, or address class is different
16782 than the default, create a type variant marked as such and set
16783 the length accordingly. */
16784 if (TYPE_LENGTH (type
) != byte_size
16785 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16786 && alignment
!= TYPE_RAW_ALIGN (type
))
16787 || addr_class
!= DW_ADDR_none
)
16789 if (gdbarch_address_class_type_flags_p (gdbarch
))
16793 type_flags
= gdbarch_address_class_type_flags
16794 (gdbarch
, byte_size
, addr_class
);
16795 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16797 type
= make_type_with_address_space (type
, type_flags
);
16799 else if (TYPE_LENGTH (type
) != byte_size
)
16801 complaint (_("invalid pointer size %d"), byte_size
);
16803 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16805 complaint (_("Invalid DW_AT_alignment"
16806 " - DIE at %s [in module %s]"),
16807 sect_offset_str (die
->sect_off
),
16808 objfile_name (cu
->per_objfile
->objfile
));
16812 /* Should we also complain about unhandled address classes? */
16816 TYPE_LENGTH (type
) = byte_size
;
16817 set_type_align (type
, alignment
);
16818 return set_die_type (die
, type
, cu
);
16821 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16822 the user defined type vector. */
16824 static struct type
*
16825 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16828 struct type
*to_type
;
16829 struct type
*domain
;
16831 to_type
= die_type (die
, cu
);
16832 domain
= die_containing_type (die
, cu
);
16834 /* The calls above may have already set the type for this DIE. */
16835 type
= get_die_type (die
, cu
);
16839 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16840 type
= lookup_methodptr_type (to_type
);
16841 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16843 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16845 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16846 to_type
->fields (), to_type
->num_fields (),
16847 TYPE_VARARGS (to_type
));
16848 type
= lookup_methodptr_type (new_type
);
16851 type
= lookup_memberptr_type (to_type
, domain
);
16853 return set_die_type (die
, type
, cu
);
16856 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16857 the user defined type vector. */
16859 static struct type
*
16860 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16861 enum type_code refcode
)
16863 struct comp_unit_head
*cu_header
= &cu
->header
;
16864 struct type
*type
, *target_type
;
16865 struct attribute
*attr
;
16867 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16869 target_type
= die_type (die
, cu
);
16871 /* The die_type call above may have already set the type for this DIE. */
16872 type
= get_die_type (die
, cu
);
16876 type
= lookup_reference_type (target_type
, refcode
);
16877 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16878 if (attr
!= nullptr)
16880 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16884 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16886 maybe_set_alignment (cu
, die
, type
);
16887 return set_die_type (die
, type
, cu
);
16890 /* Add the given cv-qualifiers to the element type of the array. GCC
16891 outputs DWARF type qualifiers that apply to an array, not the
16892 element type. But GDB relies on the array element type to carry
16893 the cv-qualifiers. This mimics section 6.7.3 of the C99
16896 static struct type
*
16897 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16898 struct type
*base_type
, int cnst
, int voltl
)
16900 struct type
*el_type
, *inner_array
;
16902 base_type
= copy_type (base_type
);
16903 inner_array
= base_type
;
16905 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16907 TYPE_TARGET_TYPE (inner_array
) =
16908 copy_type (TYPE_TARGET_TYPE (inner_array
));
16909 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16912 el_type
= TYPE_TARGET_TYPE (inner_array
);
16913 cnst
|= TYPE_CONST (el_type
);
16914 voltl
|= TYPE_VOLATILE (el_type
);
16915 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16917 return set_die_type (die
, base_type
, cu
);
16920 static struct type
*
16921 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16923 struct type
*base_type
, *cv_type
;
16925 base_type
= die_type (die
, cu
);
16927 /* The die_type call above may have already set the type for this DIE. */
16928 cv_type
= get_die_type (die
, cu
);
16932 /* In case the const qualifier is applied to an array type, the element type
16933 is so qualified, not the array type (section 6.7.3 of C99). */
16934 if (base_type
->code () == TYPE_CODE_ARRAY
)
16935 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16937 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16938 return set_die_type (die
, cv_type
, cu
);
16941 static struct type
*
16942 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16944 struct type
*base_type
, *cv_type
;
16946 base_type
= die_type (die
, cu
);
16948 /* The die_type call above may have already set the type for this DIE. */
16949 cv_type
= get_die_type (die
, cu
);
16953 /* In case the volatile qualifier is applied to an array type, the
16954 element type is so qualified, not the array type (section 6.7.3
16956 if (base_type
->code () == TYPE_CODE_ARRAY
)
16957 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16959 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16960 return set_die_type (die
, cv_type
, cu
);
16963 /* Handle DW_TAG_restrict_type. */
16965 static struct type
*
16966 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16968 struct type
*base_type
, *cv_type
;
16970 base_type
= die_type (die
, cu
);
16972 /* The die_type call above may have already set the type for this DIE. */
16973 cv_type
= get_die_type (die
, cu
);
16977 cv_type
= make_restrict_type (base_type
);
16978 return set_die_type (die
, cv_type
, cu
);
16981 /* Handle DW_TAG_atomic_type. */
16983 static struct type
*
16984 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16986 struct type
*base_type
, *cv_type
;
16988 base_type
= die_type (die
, cu
);
16990 /* The die_type call above may have already set the type for this DIE. */
16991 cv_type
= get_die_type (die
, cu
);
16995 cv_type
= make_atomic_type (base_type
);
16996 return set_die_type (die
, cv_type
, cu
);
16999 /* Extract all information from a DW_TAG_string_type DIE and add to
17000 the user defined type vector. It isn't really a user defined type,
17001 but it behaves like one, with other DIE's using an AT_user_def_type
17002 attribute to reference it. */
17004 static struct type
*
17005 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17007 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17008 struct gdbarch
*gdbarch
= objfile
->arch ();
17009 struct type
*type
, *range_type
, *index_type
, *char_type
;
17010 struct attribute
*attr
;
17011 struct dynamic_prop prop
;
17012 bool length_is_constant
= true;
17015 /* There are a couple of places where bit sizes might be made use of
17016 when parsing a DW_TAG_string_type, however, no producer that we know
17017 of make use of these. Handling bit sizes that are a multiple of the
17018 byte size is easy enough, but what about other bit sizes? Lets deal
17019 with that problem when we have to. Warn about these attributes being
17020 unsupported, then parse the type and ignore them like we always
17022 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17023 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17025 static bool warning_printed
= false;
17026 if (!warning_printed
)
17028 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17029 "currently supported on DW_TAG_string_type."));
17030 warning_printed
= true;
17034 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17035 if (attr
!= nullptr && !attr
->form_is_constant ())
17037 /* The string length describes the location at which the length of
17038 the string can be found. The size of the length field can be
17039 specified with one of the attributes below. */
17040 struct type
*prop_type
;
17041 struct attribute
*len
17042 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17043 if (len
== nullptr)
17044 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17045 if (len
!= nullptr && len
->form_is_constant ())
17047 /* Pass 0 as the default as we know this attribute is constant
17048 and the default value will not be returned. */
17049 LONGEST sz
= len
->constant_value (0);
17050 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17054 /* If the size is not specified then we assume it is the size of
17055 an address on this target. */
17056 prop_type
= cu
->addr_sized_int_type (true);
17059 /* Convert the attribute into a dynamic property. */
17060 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17063 length_is_constant
= false;
17065 else if (attr
!= nullptr)
17067 /* This DW_AT_string_length just contains the length with no
17068 indirection. There's no need to create a dynamic property in this
17069 case. Pass 0 for the default value as we know it will not be
17070 returned in this case. */
17071 length
= attr
->constant_value (0);
17073 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17075 /* We don't currently support non-constant byte sizes for strings. */
17076 length
= attr
->constant_value (1);
17080 /* Use 1 as a fallback length if we have nothing else. */
17084 index_type
= objfile_type (objfile
)->builtin_int
;
17085 if (length_is_constant
)
17086 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17089 struct dynamic_prop low_bound
;
17091 low_bound
.kind
= PROP_CONST
;
17092 low_bound
.data
.const_val
= 1;
17093 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17095 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17096 type
= create_string_type (NULL
, char_type
, range_type
);
17098 return set_die_type (die
, type
, cu
);
17101 /* Assuming that DIE corresponds to a function, returns nonzero
17102 if the function is prototyped. */
17105 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17107 struct attribute
*attr
;
17109 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17110 if (attr
&& (DW_UNSND (attr
) != 0))
17113 /* The DWARF standard implies that the DW_AT_prototyped attribute
17114 is only meaningful for C, but the concept also extends to other
17115 languages that allow unprototyped functions (Eg: Objective C).
17116 For all other languages, assume that functions are always
17118 if (cu
->language
!= language_c
17119 && cu
->language
!= language_objc
17120 && cu
->language
!= language_opencl
)
17123 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17124 prototyped and unprototyped functions; default to prototyped,
17125 since that is more common in modern code (and RealView warns
17126 about unprototyped functions). */
17127 if (producer_is_realview (cu
->producer
))
17133 /* Handle DIES due to C code like:
17137 int (*funcp)(int a, long l);
17141 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17143 static struct type
*
17144 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17146 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17147 struct type
*type
; /* Type that this function returns. */
17148 struct type
*ftype
; /* Function that returns above type. */
17149 struct attribute
*attr
;
17151 type
= die_type (die
, cu
);
17153 /* The die_type call above may have already set the type for this DIE. */
17154 ftype
= get_die_type (die
, cu
);
17158 ftype
= lookup_function_type (type
);
17160 if (prototyped_function_p (die
, cu
))
17161 TYPE_PROTOTYPED (ftype
) = 1;
17163 /* Store the calling convention in the type if it's available in
17164 the subroutine die. Otherwise set the calling convention to
17165 the default value DW_CC_normal. */
17166 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17167 if (attr
!= nullptr
17168 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17169 TYPE_CALLING_CONVENTION (ftype
)
17170 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17171 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17172 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17174 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17176 /* Record whether the function returns normally to its caller or not
17177 if the DWARF producer set that information. */
17178 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17179 if (attr
&& (DW_UNSND (attr
) != 0))
17180 TYPE_NO_RETURN (ftype
) = 1;
17182 /* We need to add the subroutine type to the die immediately so
17183 we don't infinitely recurse when dealing with parameters
17184 declared as the same subroutine type. */
17185 set_die_type (die
, ftype
, cu
);
17187 if (die
->child
!= NULL
)
17189 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17190 struct die_info
*child_die
;
17191 int nparams
, iparams
;
17193 /* Count the number of parameters.
17194 FIXME: GDB currently ignores vararg functions, but knows about
17195 vararg member functions. */
17197 child_die
= die
->child
;
17198 while (child_die
&& child_die
->tag
)
17200 if (child_die
->tag
== DW_TAG_formal_parameter
)
17202 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17203 TYPE_VARARGS (ftype
) = 1;
17204 child_die
= child_die
->sibling
;
17207 /* Allocate storage for parameters and fill them in. */
17208 ftype
->set_num_fields (nparams
);
17210 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17212 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17213 even if we error out during the parameters reading below. */
17214 for (iparams
= 0; iparams
< nparams
; iparams
++)
17215 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17218 child_die
= die
->child
;
17219 while (child_die
&& child_die
->tag
)
17221 if (child_die
->tag
== DW_TAG_formal_parameter
)
17223 struct type
*arg_type
;
17225 /* DWARF version 2 has no clean way to discern C++
17226 static and non-static member functions. G++ helps
17227 GDB by marking the first parameter for non-static
17228 member functions (which is the this pointer) as
17229 artificial. We pass this information to
17230 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17232 DWARF version 3 added DW_AT_object_pointer, which GCC
17233 4.5 does not yet generate. */
17234 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17235 if (attr
!= nullptr)
17236 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17238 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17239 arg_type
= die_type (child_die
, cu
);
17241 /* RealView does not mark THIS as const, which the testsuite
17242 expects. GCC marks THIS as const in method definitions,
17243 but not in the class specifications (GCC PR 43053). */
17244 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17245 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17248 struct dwarf2_cu
*arg_cu
= cu
;
17249 const char *name
= dwarf2_name (child_die
, cu
);
17251 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17252 if (attr
!= nullptr)
17254 /* If the compiler emits this, use it. */
17255 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17258 else if (name
&& strcmp (name
, "this") == 0)
17259 /* Function definitions will have the argument names. */
17261 else if (name
== NULL
&& iparams
== 0)
17262 /* Declarations may not have the names, so like
17263 elsewhere in GDB, assume an artificial first
17264 argument is "this". */
17268 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17272 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17275 child_die
= child_die
->sibling
;
17282 static struct type
*
17283 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17285 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17286 const char *name
= NULL
;
17287 struct type
*this_type
, *target_type
;
17289 name
= dwarf2_full_name (NULL
, die
, cu
);
17290 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17291 TYPE_TARGET_STUB (this_type
) = 1;
17292 set_die_type (die
, this_type
, cu
);
17293 target_type
= die_type (die
, cu
);
17294 if (target_type
!= this_type
)
17295 TYPE_TARGET_TYPE (this_type
) = target_type
;
17298 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17299 spec and cause infinite loops in GDB. */
17300 complaint (_("Self-referential DW_TAG_typedef "
17301 "- DIE at %s [in module %s]"),
17302 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17303 TYPE_TARGET_TYPE (this_type
) = NULL
;
17307 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17308 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17309 Handle these by just returning the target type, rather than
17310 constructing an anonymous typedef type and trying to handle this
17312 set_die_type (die
, target_type
, cu
);
17313 return target_type
;
17318 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17319 (which may be different from NAME) to the architecture back-end to allow
17320 it to guess the correct format if necessary. */
17322 static struct type
*
17323 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17324 const char *name_hint
, enum bfd_endian byte_order
)
17326 struct gdbarch
*gdbarch
= objfile
->arch ();
17327 const struct floatformat
**format
;
17330 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17332 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17334 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17339 /* Allocate an integer type of size BITS and name NAME. */
17341 static struct type
*
17342 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17343 int bits
, int unsigned_p
, const char *name
)
17347 /* Versions of Intel's C Compiler generate an integer type called "void"
17348 instead of using DW_TAG_unspecified_type. This has been seen on
17349 at least versions 14, 17, and 18. */
17350 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17351 && strcmp (name
, "void") == 0)
17352 type
= objfile_type (objfile
)->builtin_void
;
17354 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17359 /* Initialise and return a floating point type of size BITS suitable for
17360 use as a component of a complex number. The NAME_HINT is passed through
17361 when initialising the floating point type and is the name of the complex
17364 As DWARF doesn't currently provide an explicit name for the components
17365 of a complex number, but it can be helpful to have these components
17366 named, we try to select a suitable name based on the size of the
17368 static struct type
*
17369 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17370 struct objfile
*objfile
,
17371 int bits
, const char *name_hint
,
17372 enum bfd_endian byte_order
)
17374 gdbarch
*gdbarch
= objfile
->arch ();
17375 struct type
*tt
= nullptr;
17377 /* Try to find a suitable floating point builtin type of size BITS.
17378 We're going to use the name of this type as the name for the complex
17379 target type that we are about to create. */
17380 switch (cu
->language
)
17382 case language_fortran
:
17386 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17389 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17391 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17393 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17401 tt
= builtin_type (gdbarch
)->builtin_float
;
17404 tt
= builtin_type (gdbarch
)->builtin_double
;
17406 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17408 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17414 /* If the type we found doesn't match the size we were looking for, then
17415 pretend we didn't find a type at all, the complex target type we
17416 create will then be nameless. */
17417 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17420 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17421 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17424 /* Find a representation of a given base type and install
17425 it in the TYPE field of the die. */
17427 static struct type
*
17428 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17430 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17432 struct attribute
*attr
;
17433 int encoding
= 0, bits
= 0;
17437 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17438 if (attr
!= nullptr)
17439 encoding
= DW_UNSND (attr
);
17440 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17441 if (attr
!= nullptr)
17442 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17443 name
= dwarf2_name (die
, cu
);
17445 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17447 arch
= objfile
->arch ();
17448 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17450 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17453 int endianity
= DW_UNSND (attr
);
17458 byte_order
= BFD_ENDIAN_BIG
;
17460 case DW_END_little
:
17461 byte_order
= BFD_ENDIAN_LITTLE
;
17464 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17471 case DW_ATE_address
:
17472 /* Turn DW_ATE_address into a void * pointer. */
17473 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17474 type
= init_pointer_type (objfile
, bits
, name
, type
);
17476 case DW_ATE_boolean
:
17477 type
= init_boolean_type (objfile
, bits
, 1, name
);
17479 case DW_ATE_complex_float
:
17480 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17482 if (type
->code () == TYPE_CODE_ERROR
)
17484 if (name
== nullptr)
17486 struct obstack
*obstack
17487 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17488 name
= obconcat (obstack
, "_Complex ", type
->name (),
17491 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17494 type
= init_complex_type (name
, type
);
17496 case DW_ATE_decimal_float
:
17497 type
= init_decfloat_type (objfile
, bits
, name
);
17500 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17502 case DW_ATE_signed
:
17503 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17505 case DW_ATE_unsigned
:
17506 if (cu
->language
== language_fortran
17508 && startswith (name
, "character("))
17509 type
= init_character_type (objfile
, bits
, 1, name
);
17511 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17513 case DW_ATE_signed_char
:
17514 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17515 || cu
->language
== language_pascal
17516 || cu
->language
== language_fortran
)
17517 type
= init_character_type (objfile
, bits
, 0, name
);
17519 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17521 case DW_ATE_unsigned_char
:
17522 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17523 || cu
->language
== language_pascal
17524 || cu
->language
== language_fortran
17525 || cu
->language
== language_rust
)
17526 type
= init_character_type (objfile
, bits
, 1, name
);
17528 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17533 type
= builtin_type (arch
)->builtin_char16
;
17534 else if (bits
== 32)
17535 type
= builtin_type (arch
)->builtin_char32
;
17538 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17540 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17542 return set_die_type (die
, type
, cu
);
17547 complaint (_("unsupported DW_AT_encoding: '%s'"),
17548 dwarf_type_encoding_name (encoding
));
17549 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17553 if (name
&& strcmp (name
, "char") == 0)
17554 TYPE_NOSIGN (type
) = 1;
17556 maybe_set_alignment (cu
, die
, type
);
17558 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17560 return set_die_type (die
, type
, cu
);
17563 /* Parse dwarf attribute if it's a block, reference or constant and put the
17564 resulting value of the attribute into struct bound_prop.
17565 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17568 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17569 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17570 struct type
*default_type
)
17572 struct dwarf2_property_baton
*baton
;
17573 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17574 struct objfile
*objfile
= per_objfile
->objfile
;
17575 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17577 gdb_assert (default_type
!= NULL
);
17579 if (attr
== NULL
|| prop
== NULL
)
17582 if (attr
->form_is_block ())
17584 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17585 baton
->property_type
= default_type
;
17586 baton
->locexpr
.per_cu
= cu
->per_cu
;
17587 baton
->locexpr
.per_objfile
= per_objfile
;
17588 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17589 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17590 switch (attr
->name
)
17592 case DW_AT_string_length
:
17593 baton
->locexpr
.is_reference
= true;
17596 baton
->locexpr
.is_reference
= false;
17599 prop
->data
.baton
= baton
;
17600 prop
->kind
= PROP_LOCEXPR
;
17601 gdb_assert (prop
->data
.baton
!= NULL
);
17603 else if (attr
->form_is_ref ())
17605 struct dwarf2_cu
*target_cu
= cu
;
17606 struct die_info
*target_die
;
17607 struct attribute
*target_attr
;
17609 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17610 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17611 if (target_attr
== NULL
)
17612 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17614 if (target_attr
== NULL
)
17617 switch (target_attr
->name
)
17619 case DW_AT_location
:
17620 if (target_attr
->form_is_section_offset ())
17622 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17623 baton
->property_type
= die_type (target_die
, target_cu
);
17624 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17625 prop
->data
.baton
= baton
;
17626 prop
->kind
= PROP_LOCLIST
;
17627 gdb_assert (prop
->data
.baton
!= NULL
);
17629 else if (target_attr
->form_is_block ())
17631 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17632 baton
->property_type
= die_type (target_die
, target_cu
);
17633 baton
->locexpr
.per_cu
= cu
->per_cu
;
17634 baton
->locexpr
.per_objfile
= per_objfile
;
17635 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17636 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17637 baton
->locexpr
.is_reference
= true;
17638 prop
->data
.baton
= baton
;
17639 prop
->kind
= PROP_LOCEXPR
;
17640 gdb_assert (prop
->data
.baton
!= NULL
);
17644 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17645 "dynamic property");
17649 case DW_AT_data_member_location
:
17653 if (!handle_data_member_location (target_die
, target_cu
,
17657 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17658 baton
->property_type
= read_type_die (target_die
->parent
,
17660 baton
->offset_info
.offset
= offset
;
17661 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17662 prop
->data
.baton
= baton
;
17663 prop
->kind
= PROP_ADDR_OFFSET
;
17668 else if (attr
->form_is_constant ())
17670 prop
->data
.const_val
= attr
->constant_value (0);
17671 prop
->kind
= PROP_CONST
;
17675 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17676 dwarf2_name (die
, cu
));
17686 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17688 struct type
*int_type
;
17690 /* Helper macro to examine the various builtin types. */
17691 #define TRY_TYPE(F) \
17692 int_type = (unsigned_p \
17693 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17694 : objfile_type (objfile)->builtin_ ## F); \
17695 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17702 TRY_TYPE (long_long
);
17706 gdb_assert_not_reached ("unable to find suitable integer type");
17712 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17714 int addr_size
= this->per_cu
->addr_size ();
17715 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17718 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17719 present (which is valid) then compute the default type based on the
17720 compilation units address size. */
17722 static struct type
*
17723 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17725 struct type
*index_type
= die_type (die
, cu
);
17727 /* Dwarf-2 specifications explicitly allows to create subrange types
17728 without specifying a base type.
17729 In that case, the base type must be set to the type of
17730 the lower bound, upper bound or count, in that order, if any of these
17731 three attributes references an object that has a type.
17732 If no base type is found, the Dwarf-2 specifications say that
17733 a signed integer type of size equal to the size of an address should
17735 For the following C code: `extern char gdb_int [];'
17736 GCC produces an empty range DIE.
17737 FIXME: muller/2010-05-28: Possible references to object for low bound,
17738 high bound or count are not yet handled by this code. */
17739 if (index_type
->code () == TYPE_CODE_VOID
)
17740 index_type
= cu
->addr_sized_int_type (false);
17745 /* Read the given DW_AT_subrange DIE. */
17747 static struct type
*
17748 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17750 struct type
*base_type
, *orig_base_type
;
17751 struct type
*range_type
;
17752 struct attribute
*attr
;
17753 struct dynamic_prop low
, high
;
17754 int low_default_is_valid
;
17755 int high_bound_is_count
= 0;
17757 ULONGEST negative_mask
;
17759 orig_base_type
= read_subrange_index_type (die
, cu
);
17761 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17762 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17763 creating the range type, but we use the result of check_typedef
17764 when examining properties of the type. */
17765 base_type
= check_typedef (orig_base_type
);
17767 /* The die_type call above may have already set the type for this DIE. */
17768 range_type
= get_die_type (die
, cu
);
17772 low
.kind
= PROP_CONST
;
17773 high
.kind
= PROP_CONST
;
17774 high
.data
.const_val
= 0;
17776 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17777 omitting DW_AT_lower_bound. */
17778 switch (cu
->language
)
17781 case language_cplus
:
17782 low
.data
.const_val
= 0;
17783 low_default_is_valid
= 1;
17785 case language_fortran
:
17786 low
.data
.const_val
= 1;
17787 low_default_is_valid
= 1;
17790 case language_objc
:
17791 case language_rust
:
17792 low
.data
.const_val
= 0;
17793 low_default_is_valid
= (cu
->header
.version
>= 4);
17797 case language_pascal
:
17798 low
.data
.const_val
= 1;
17799 low_default_is_valid
= (cu
->header
.version
>= 4);
17802 low
.data
.const_val
= 0;
17803 low_default_is_valid
= 0;
17807 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17808 if (attr
!= nullptr)
17809 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17810 else if (!low_default_is_valid
)
17811 complaint (_("Missing DW_AT_lower_bound "
17812 "- DIE at %s [in module %s]"),
17813 sect_offset_str (die
->sect_off
),
17814 objfile_name (cu
->per_objfile
->objfile
));
17816 struct attribute
*attr_ub
, *attr_count
;
17817 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17818 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17820 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17821 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17823 /* If bounds are constant do the final calculation here. */
17824 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17825 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17827 high_bound_is_count
= 1;
17831 if (attr_ub
!= NULL
)
17832 complaint (_("Unresolved DW_AT_upper_bound "
17833 "- DIE at %s [in module %s]"),
17834 sect_offset_str (die
->sect_off
),
17835 objfile_name (cu
->per_objfile
->objfile
));
17836 if (attr_count
!= NULL
)
17837 complaint (_("Unresolved DW_AT_count "
17838 "- DIE at %s [in module %s]"),
17839 sect_offset_str (die
->sect_off
),
17840 objfile_name (cu
->per_objfile
->objfile
));
17845 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17846 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17847 bias
= bias_attr
->constant_value (0);
17849 /* Normally, the DWARF producers are expected to use a signed
17850 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17851 But this is unfortunately not always the case, as witnessed
17852 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17853 is used instead. To work around that ambiguity, we treat
17854 the bounds as signed, and thus sign-extend their values, when
17855 the base type is signed. */
17857 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17858 if (low
.kind
== PROP_CONST
17859 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17860 low
.data
.const_val
|= negative_mask
;
17861 if (high
.kind
== PROP_CONST
17862 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17863 high
.data
.const_val
|= negative_mask
;
17865 /* Check for bit and byte strides. */
17866 struct dynamic_prop byte_stride_prop
;
17867 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17868 if (attr_byte_stride
!= nullptr)
17870 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17871 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17875 struct dynamic_prop bit_stride_prop
;
17876 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17877 if (attr_bit_stride
!= nullptr)
17879 /* It only makes sense to have either a bit or byte stride. */
17880 if (attr_byte_stride
!= nullptr)
17882 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17883 "- DIE at %s [in module %s]"),
17884 sect_offset_str (die
->sect_off
),
17885 objfile_name (cu
->per_objfile
->objfile
));
17886 attr_bit_stride
= nullptr;
17890 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17891 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17896 if (attr_byte_stride
!= nullptr
17897 || attr_bit_stride
!= nullptr)
17899 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17900 struct dynamic_prop
*stride
17901 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17904 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17905 &high
, bias
, stride
, byte_stride_p
);
17908 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17910 if (high_bound_is_count
)
17911 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17913 /* Ada expects an empty array on no boundary attributes. */
17914 if (attr
== NULL
&& cu
->language
!= language_ada
)
17915 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17917 name
= dwarf2_name (die
, cu
);
17919 range_type
->set_name (name
);
17921 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17922 if (attr
!= nullptr)
17923 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17925 maybe_set_alignment (cu
, die
, range_type
);
17927 set_die_type (die
, range_type
, cu
);
17929 /* set_die_type should be already done. */
17930 set_descriptive_type (range_type
, die
, cu
);
17935 static struct type
*
17936 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17940 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17941 type
->set_name (dwarf2_name (die
, cu
));
17943 /* In Ada, an unspecified type is typically used when the description
17944 of the type is deferred to a different unit. When encountering
17945 such a type, we treat it as a stub, and try to resolve it later on,
17947 if (cu
->language
== language_ada
)
17948 TYPE_STUB (type
) = 1;
17950 return set_die_type (die
, type
, cu
);
17953 /* Read a single die and all its descendents. Set the die's sibling
17954 field to NULL; set other fields in the die correctly, and set all
17955 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17956 location of the info_ptr after reading all of those dies. PARENT
17957 is the parent of the die in question. */
17959 static struct die_info
*
17960 read_die_and_children (const struct die_reader_specs
*reader
,
17961 const gdb_byte
*info_ptr
,
17962 const gdb_byte
**new_info_ptr
,
17963 struct die_info
*parent
)
17965 struct die_info
*die
;
17966 const gdb_byte
*cur_ptr
;
17968 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17971 *new_info_ptr
= cur_ptr
;
17974 store_in_ref_table (die
, reader
->cu
);
17976 if (die
->has_children
)
17977 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17981 *new_info_ptr
= cur_ptr
;
17984 die
->sibling
= NULL
;
17985 die
->parent
= parent
;
17989 /* Read a die, all of its descendents, and all of its siblings; set
17990 all of the fields of all of the dies correctly. Arguments are as
17991 in read_die_and_children. */
17993 static struct die_info
*
17994 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17995 const gdb_byte
*info_ptr
,
17996 const gdb_byte
**new_info_ptr
,
17997 struct die_info
*parent
)
17999 struct die_info
*first_die
, *last_sibling
;
18000 const gdb_byte
*cur_ptr
;
18002 cur_ptr
= info_ptr
;
18003 first_die
= last_sibling
= NULL
;
18007 struct die_info
*die
18008 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18012 *new_info_ptr
= cur_ptr
;
18019 last_sibling
->sibling
= die
;
18021 last_sibling
= die
;
18025 /* Read a die, all of its descendents, and all of its siblings; set
18026 all of the fields of all of the dies correctly. Arguments are as
18027 in read_die_and_children.
18028 This the main entry point for reading a DIE and all its children. */
18030 static struct die_info
*
18031 read_die_and_siblings (const struct die_reader_specs
*reader
,
18032 const gdb_byte
*info_ptr
,
18033 const gdb_byte
**new_info_ptr
,
18034 struct die_info
*parent
)
18036 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18037 new_info_ptr
, parent
);
18039 if (dwarf_die_debug
)
18041 fprintf_unfiltered (gdb_stdlog
,
18042 "Read die from %s@0x%x of %s:\n",
18043 reader
->die_section
->get_name (),
18044 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18045 bfd_get_filename (reader
->abfd
));
18046 dump_die (die
, dwarf_die_debug
);
18052 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18054 The caller is responsible for filling in the extra attributes
18055 and updating (*DIEP)->num_attrs.
18056 Set DIEP to point to a newly allocated die with its information,
18057 except for its child, sibling, and parent fields. */
18059 static const gdb_byte
*
18060 read_full_die_1 (const struct die_reader_specs
*reader
,
18061 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18062 int num_extra_attrs
)
18064 unsigned int abbrev_number
, bytes_read
, i
;
18065 struct abbrev_info
*abbrev
;
18066 struct die_info
*die
;
18067 struct dwarf2_cu
*cu
= reader
->cu
;
18068 bfd
*abfd
= reader
->abfd
;
18070 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18071 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18072 info_ptr
+= bytes_read
;
18073 if (!abbrev_number
)
18079 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18081 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18083 bfd_get_filename (abfd
));
18085 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18086 die
->sect_off
= sect_off
;
18087 die
->tag
= abbrev
->tag
;
18088 die
->abbrev
= abbrev_number
;
18089 die
->has_children
= abbrev
->has_children
;
18091 /* Make the result usable.
18092 The caller needs to update num_attrs after adding the extra
18094 die
->num_attrs
= abbrev
->num_attrs
;
18096 std::vector
<int> indexes_that_need_reprocess
;
18097 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18099 bool need_reprocess
;
18101 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18102 info_ptr
, &need_reprocess
);
18103 if (need_reprocess
)
18104 indexes_that_need_reprocess
.push_back (i
);
18107 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18108 if (attr
!= nullptr)
18109 cu
->str_offsets_base
= DW_UNSND (attr
);
18111 attr
= die
->attr (DW_AT_loclists_base
);
18112 if (attr
!= nullptr)
18113 cu
->loclist_base
= DW_UNSND (attr
);
18115 auto maybe_addr_base
= die
->addr_base ();
18116 if (maybe_addr_base
.has_value ())
18117 cu
->addr_base
= *maybe_addr_base
;
18118 for (int index
: indexes_that_need_reprocess
)
18119 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18124 /* Read a die and all its attributes.
18125 Set DIEP to point to a newly allocated die with its information,
18126 except for its child, sibling, and parent fields. */
18128 static const gdb_byte
*
18129 read_full_die (const struct die_reader_specs
*reader
,
18130 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18132 const gdb_byte
*result
;
18134 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18136 if (dwarf_die_debug
)
18138 fprintf_unfiltered (gdb_stdlog
,
18139 "Read die from %s@0x%x of %s:\n",
18140 reader
->die_section
->get_name (),
18141 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18142 bfd_get_filename (reader
->abfd
));
18143 dump_die (*diep
, dwarf_die_debug
);
18150 /* Returns nonzero if TAG represents a type that we might generate a partial
18154 is_type_tag_for_partial (int tag
)
18159 /* Some types that would be reasonable to generate partial symbols for,
18160 that we don't at present. */
18161 case DW_TAG_array_type
:
18162 case DW_TAG_file_type
:
18163 case DW_TAG_ptr_to_member_type
:
18164 case DW_TAG_set_type
:
18165 case DW_TAG_string_type
:
18166 case DW_TAG_subroutine_type
:
18168 case DW_TAG_base_type
:
18169 case DW_TAG_class_type
:
18170 case DW_TAG_interface_type
:
18171 case DW_TAG_enumeration_type
:
18172 case DW_TAG_structure_type
:
18173 case DW_TAG_subrange_type
:
18174 case DW_TAG_typedef
:
18175 case DW_TAG_union_type
:
18182 /* Load all DIEs that are interesting for partial symbols into memory. */
18184 static struct partial_die_info
*
18185 load_partial_dies (const struct die_reader_specs
*reader
,
18186 const gdb_byte
*info_ptr
, int building_psymtab
)
18188 struct dwarf2_cu
*cu
= reader
->cu
;
18189 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18190 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18191 unsigned int bytes_read
;
18192 unsigned int load_all
= 0;
18193 int nesting_level
= 1;
18198 gdb_assert (cu
->per_cu
!= NULL
);
18199 if (cu
->per_cu
->load_all_dies
)
18203 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18207 &cu
->comp_unit_obstack
,
18208 hashtab_obstack_allocate
,
18209 dummy_obstack_deallocate
);
18213 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18215 /* A NULL abbrev means the end of a series of children. */
18216 if (abbrev
== NULL
)
18218 if (--nesting_level
== 0)
18221 info_ptr
+= bytes_read
;
18222 last_die
= parent_die
;
18223 parent_die
= parent_die
->die_parent
;
18227 /* Check for template arguments. We never save these; if
18228 they're seen, we just mark the parent, and go on our way. */
18229 if (parent_die
!= NULL
18230 && cu
->language
== language_cplus
18231 && (abbrev
->tag
== DW_TAG_template_type_param
18232 || abbrev
->tag
== DW_TAG_template_value_param
))
18234 parent_die
->has_template_arguments
= 1;
18238 /* We don't need a partial DIE for the template argument. */
18239 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18244 /* We only recurse into c++ subprograms looking for template arguments.
18245 Skip their other children. */
18247 && cu
->language
== language_cplus
18248 && parent_die
!= NULL
18249 && parent_die
->tag
== DW_TAG_subprogram
)
18251 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18255 /* Check whether this DIE is interesting enough to save. Normally
18256 we would not be interested in members here, but there may be
18257 later variables referencing them via DW_AT_specification (for
18258 static members). */
18260 && !is_type_tag_for_partial (abbrev
->tag
)
18261 && abbrev
->tag
!= DW_TAG_constant
18262 && abbrev
->tag
!= DW_TAG_enumerator
18263 && abbrev
->tag
!= DW_TAG_subprogram
18264 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18265 && abbrev
->tag
!= DW_TAG_lexical_block
18266 && abbrev
->tag
!= DW_TAG_variable
18267 && abbrev
->tag
!= DW_TAG_namespace
18268 && abbrev
->tag
!= DW_TAG_module
18269 && abbrev
->tag
!= DW_TAG_member
18270 && abbrev
->tag
!= DW_TAG_imported_unit
18271 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18273 /* Otherwise we skip to the next sibling, if any. */
18274 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18278 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18281 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18283 /* This two-pass algorithm for processing partial symbols has a
18284 high cost in cache pressure. Thus, handle some simple cases
18285 here which cover the majority of C partial symbols. DIEs
18286 which neither have specification tags in them, nor could have
18287 specification tags elsewhere pointing at them, can simply be
18288 processed and discarded.
18290 This segment is also optional; scan_partial_symbols and
18291 add_partial_symbol will handle these DIEs if we chain
18292 them in normally. When compilers which do not emit large
18293 quantities of duplicate debug information are more common,
18294 this code can probably be removed. */
18296 /* Any complete simple types at the top level (pretty much all
18297 of them, for a language without namespaces), can be processed
18299 if (parent_die
== NULL
18300 && pdi
.has_specification
== 0
18301 && pdi
.is_declaration
== 0
18302 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18303 || pdi
.tag
== DW_TAG_base_type
18304 || pdi
.tag
== DW_TAG_subrange_type
))
18306 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18307 add_partial_symbol (&pdi
, cu
);
18309 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18313 /* The exception for DW_TAG_typedef with has_children above is
18314 a workaround of GCC PR debug/47510. In the case of this complaint
18315 type_name_or_error will error on such types later.
18317 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18318 it could not find the child DIEs referenced later, this is checked
18319 above. In correct DWARF DW_TAG_typedef should have no children. */
18321 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18322 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18323 "- DIE at %s [in module %s]"),
18324 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18326 /* If we're at the second level, and we're an enumerator, and
18327 our parent has no specification (meaning possibly lives in a
18328 namespace elsewhere), then we can add the partial symbol now
18329 instead of queueing it. */
18330 if (pdi
.tag
== DW_TAG_enumerator
18331 && parent_die
!= NULL
18332 && parent_die
->die_parent
== NULL
18333 && parent_die
->tag
== DW_TAG_enumeration_type
18334 && parent_die
->has_specification
== 0)
18336 if (pdi
.raw_name
== NULL
)
18337 complaint (_("malformed enumerator DIE ignored"));
18338 else if (building_psymtab
)
18339 add_partial_symbol (&pdi
, cu
);
18341 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18345 struct partial_die_info
*part_die
18346 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18348 /* We'll save this DIE so link it in. */
18349 part_die
->die_parent
= parent_die
;
18350 part_die
->die_sibling
= NULL
;
18351 part_die
->die_child
= NULL
;
18353 if (last_die
&& last_die
== parent_die
)
18354 last_die
->die_child
= part_die
;
18356 last_die
->die_sibling
= part_die
;
18358 last_die
= part_die
;
18360 if (first_die
== NULL
)
18361 first_die
= part_die
;
18363 /* Maybe add the DIE to the hash table. Not all DIEs that we
18364 find interesting need to be in the hash table, because we
18365 also have the parent/sibling/child chains; only those that we
18366 might refer to by offset later during partial symbol reading.
18368 For now this means things that might have be the target of a
18369 DW_AT_specification, DW_AT_abstract_origin, or
18370 DW_AT_extension. DW_AT_extension will refer only to
18371 namespaces; DW_AT_abstract_origin refers to functions (and
18372 many things under the function DIE, but we do not recurse
18373 into function DIEs during partial symbol reading) and
18374 possibly variables as well; DW_AT_specification refers to
18375 declarations. Declarations ought to have the DW_AT_declaration
18376 flag. It happens that GCC forgets to put it in sometimes, but
18377 only for functions, not for types.
18379 Adding more things than necessary to the hash table is harmless
18380 except for the performance cost. Adding too few will result in
18381 wasted time in find_partial_die, when we reread the compilation
18382 unit with load_all_dies set. */
18385 || abbrev
->tag
== DW_TAG_constant
18386 || abbrev
->tag
== DW_TAG_subprogram
18387 || abbrev
->tag
== DW_TAG_variable
18388 || abbrev
->tag
== DW_TAG_namespace
18389 || part_die
->is_declaration
)
18393 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18394 to_underlying (part_die
->sect_off
),
18399 /* For some DIEs we want to follow their children (if any). For C
18400 we have no reason to follow the children of structures; for other
18401 languages we have to, so that we can get at method physnames
18402 to infer fully qualified class names, for DW_AT_specification,
18403 and for C++ template arguments. For C++, we also look one level
18404 inside functions to find template arguments (if the name of the
18405 function does not already contain the template arguments).
18407 For Ada and Fortran, we need to scan the children of subprograms
18408 and lexical blocks as well because these languages allow the
18409 definition of nested entities that could be interesting for the
18410 debugger, such as nested subprograms for instance. */
18411 if (last_die
->has_children
18413 || last_die
->tag
== DW_TAG_namespace
18414 || last_die
->tag
== DW_TAG_module
18415 || last_die
->tag
== DW_TAG_enumeration_type
18416 || (cu
->language
== language_cplus
18417 && last_die
->tag
== DW_TAG_subprogram
18418 && (last_die
->raw_name
== NULL
18419 || strchr (last_die
->raw_name
, '<') == NULL
))
18420 || (cu
->language
!= language_c
18421 && (last_die
->tag
== DW_TAG_class_type
18422 || last_die
->tag
== DW_TAG_interface_type
18423 || last_die
->tag
== DW_TAG_structure_type
18424 || last_die
->tag
== DW_TAG_union_type
))
18425 || ((cu
->language
== language_ada
18426 || cu
->language
== language_fortran
)
18427 && (last_die
->tag
== DW_TAG_subprogram
18428 || last_die
->tag
== DW_TAG_lexical_block
))))
18431 parent_die
= last_die
;
18435 /* Otherwise we skip to the next sibling, if any. */
18436 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18438 /* Back to the top, do it again. */
18442 partial_die_info::partial_die_info (sect_offset sect_off_
,
18443 struct abbrev_info
*abbrev
)
18444 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18448 /* See class definition. */
18451 partial_die_info::name (dwarf2_cu
*cu
)
18453 if (!canonical_name
&& raw_name
!= nullptr)
18455 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18456 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
18457 canonical_name
= 1;
18463 /* Read a minimal amount of information into the minimal die structure.
18464 INFO_PTR should point just after the initial uleb128 of a DIE. */
18467 partial_die_info::read (const struct die_reader_specs
*reader
,
18468 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18470 struct dwarf2_cu
*cu
= reader
->cu
;
18471 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18473 int has_low_pc_attr
= 0;
18474 int has_high_pc_attr
= 0;
18475 int high_pc_relative
= 0;
18477 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18480 bool need_reprocess
;
18481 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18482 info_ptr
, &need_reprocess
);
18483 /* String and address offsets that need to do the reprocessing have
18484 already been read at this point, so there is no need to wait until
18485 the loop terminates to do the reprocessing. */
18486 if (need_reprocess
)
18487 read_attribute_reprocess (reader
, &attr
);
18488 /* Store the data if it is of an attribute we want to keep in a
18489 partial symbol table. */
18495 case DW_TAG_compile_unit
:
18496 case DW_TAG_partial_unit
:
18497 case DW_TAG_type_unit
:
18498 /* Compilation units have a DW_AT_name that is a filename, not
18499 a source language identifier. */
18500 case DW_TAG_enumeration_type
:
18501 case DW_TAG_enumerator
:
18502 /* These tags always have simple identifiers already; no need
18503 to canonicalize them. */
18504 canonical_name
= 1;
18505 raw_name
= DW_STRING (&attr
);
18508 canonical_name
= 0;
18509 raw_name
= DW_STRING (&attr
);
18513 case DW_AT_linkage_name
:
18514 case DW_AT_MIPS_linkage_name
:
18515 /* Note that both forms of linkage name might appear. We
18516 assume they will be the same, and we only store the last
18518 linkage_name
= attr
.value_as_string ();
18519 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18520 See https://github.com/rust-lang/rust/issues/32925. */
18521 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18522 && strchr (linkage_name
, '{') != NULL
)
18523 linkage_name
= NULL
;
18526 has_low_pc_attr
= 1;
18527 lowpc
= attr
.value_as_address ();
18529 case DW_AT_high_pc
:
18530 has_high_pc_attr
= 1;
18531 highpc
= attr
.value_as_address ();
18532 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18533 high_pc_relative
= 1;
18535 case DW_AT_location
:
18536 /* Support the .debug_loc offsets. */
18537 if (attr
.form_is_block ())
18539 d
.locdesc
= DW_BLOCK (&attr
);
18541 else if (attr
.form_is_section_offset ())
18543 dwarf2_complex_location_expr_complaint ();
18547 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18548 "partial symbol information");
18551 case DW_AT_external
:
18552 is_external
= DW_UNSND (&attr
);
18554 case DW_AT_declaration
:
18555 is_declaration
= DW_UNSND (&attr
);
18560 case DW_AT_abstract_origin
:
18561 case DW_AT_specification
:
18562 case DW_AT_extension
:
18563 has_specification
= 1;
18564 spec_offset
= attr
.get_ref_die_offset ();
18565 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18566 || cu
->per_cu
->is_dwz
);
18568 case DW_AT_sibling
:
18569 /* Ignore absolute siblings, they might point outside of
18570 the current compile unit. */
18571 if (attr
.form
== DW_FORM_ref_addr
)
18572 complaint (_("ignoring absolute DW_AT_sibling"));
18575 const gdb_byte
*buffer
= reader
->buffer
;
18576 sect_offset off
= attr
.get_ref_die_offset ();
18577 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18579 if (sibling_ptr
< info_ptr
)
18580 complaint (_("DW_AT_sibling points backwards"));
18581 else if (sibling_ptr
> reader
->buffer_end
)
18582 reader
->die_section
->overflow_complaint ();
18584 sibling
= sibling_ptr
;
18587 case DW_AT_byte_size
:
18590 case DW_AT_const_value
:
18591 has_const_value
= 1;
18593 case DW_AT_calling_convention
:
18594 /* DWARF doesn't provide a way to identify a program's source-level
18595 entry point. DW_AT_calling_convention attributes are only meant
18596 to describe functions' calling conventions.
18598 However, because it's a necessary piece of information in
18599 Fortran, and before DWARF 4 DW_CC_program was the only
18600 piece of debugging information whose definition refers to
18601 a 'main program' at all, several compilers marked Fortran
18602 main programs with DW_CC_program --- even when those
18603 functions use the standard calling conventions.
18605 Although DWARF now specifies a way to provide this
18606 information, we support this practice for backward
18608 if (DW_UNSND (&attr
) == DW_CC_program
18609 && cu
->language
== language_fortran
)
18610 main_subprogram
= 1;
18613 if (DW_UNSND (&attr
) == DW_INL_inlined
18614 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18615 may_be_inlined
= 1;
18619 if (tag
== DW_TAG_imported_unit
)
18621 d
.sect_off
= attr
.get_ref_die_offset ();
18622 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18623 || cu
->per_cu
->is_dwz
);
18627 case DW_AT_main_subprogram
:
18628 main_subprogram
= DW_UNSND (&attr
);
18633 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18634 but that requires a full DIE, so instead we just
18636 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18637 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18638 + (need_ranges_base
18642 /* Value of the DW_AT_ranges attribute is the offset in the
18643 .debug_ranges section. */
18644 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18655 /* For Ada, if both the name and the linkage name appear, we prefer
18656 the latter. This lets "catch exception" work better, regardless
18657 of the order in which the name and linkage name were emitted.
18658 Really, though, this is just a workaround for the fact that gdb
18659 doesn't store both the name and the linkage name. */
18660 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18661 raw_name
= linkage_name
;
18663 if (high_pc_relative
)
18666 if (has_low_pc_attr
&& has_high_pc_attr
)
18668 /* When using the GNU linker, .gnu.linkonce. sections are used to
18669 eliminate duplicate copies of functions and vtables and such.
18670 The linker will arbitrarily choose one and discard the others.
18671 The AT_*_pc values for such functions refer to local labels in
18672 these sections. If the section from that file was discarded, the
18673 labels are not in the output, so the relocs get a value of 0.
18674 If this is a discarded function, mark the pc bounds as invalid,
18675 so that GDB will ignore it. */
18676 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
18678 struct objfile
*objfile
= per_objfile
->objfile
;
18679 struct gdbarch
*gdbarch
= objfile
->arch ();
18681 complaint (_("DW_AT_low_pc %s is zero "
18682 "for DIE at %s [in module %s]"),
18683 paddress (gdbarch
, lowpc
),
18684 sect_offset_str (sect_off
),
18685 objfile_name (objfile
));
18687 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18688 else if (lowpc
>= highpc
)
18690 struct objfile
*objfile
= per_objfile
->objfile
;
18691 struct gdbarch
*gdbarch
= objfile
->arch ();
18693 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18694 "for DIE at %s [in module %s]"),
18695 paddress (gdbarch
, lowpc
),
18696 paddress (gdbarch
, highpc
),
18697 sect_offset_str (sect_off
),
18698 objfile_name (objfile
));
18707 /* Find a cached partial DIE at OFFSET in CU. */
18709 struct partial_die_info
*
18710 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18712 struct partial_die_info
*lookup_die
= NULL
;
18713 struct partial_die_info
part_die (sect_off
);
18715 lookup_die
= ((struct partial_die_info
*)
18716 htab_find_with_hash (partial_dies
, &part_die
,
18717 to_underlying (sect_off
)));
18722 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18723 except in the case of .debug_types DIEs which do not reference
18724 outside their CU (they do however referencing other types via
18725 DW_FORM_ref_sig8). */
18727 static const struct cu_partial_die_info
18728 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18730 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18731 struct objfile
*objfile
= per_objfile
->objfile
;
18732 struct partial_die_info
*pd
= NULL
;
18734 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18735 && cu
->header
.offset_in_cu_p (sect_off
))
18737 pd
= cu
->find_partial_die (sect_off
);
18740 /* We missed recording what we needed.
18741 Load all dies and try again. */
18745 /* TUs don't reference other CUs/TUs (except via type signatures). */
18746 if (cu
->per_cu
->is_debug_types
)
18748 error (_("Dwarf Error: Type Unit at offset %s contains"
18749 " external reference to offset %s [in module %s].\n"),
18750 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18751 bfd_get_filename (objfile
->obfd
));
18753 dwarf2_per_cu_data
*per_cu
18754 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18757 cu
= per_objfile
->get_cu (per_cu
);
18758 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
18759 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
18761 cu
= per_objfile
->get_cu (per_cu
);
18764 pd
= cu
->find_partial_die (sect_off
);
18767 /* If we didn't find it, and not all dies have been loaded,
18768 load them all and try again. */
18770 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
18772 cu
->per_cu
->load_all_dies
= 1;
18774 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18775 THIS_CU->cu may already be in use. So we can't just free it and
18776 replace its DIEs with the ones we read in. Instead, we leave those
18777 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18778 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18780 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
18782 pd
= cu
->find_partial_die (sect_off
);
18786 internal_error (__FILE__
, __LINE__
,
18787 _("could not find partial DIE %s "
18788 "in cache [from module %s]\n"),
18789 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18793 /* See if we can figure out if the class lives in a namespace. We do
18794 this by looking for a member function; its demangled name will
18795 contain namespace info, if there is any. */
18798 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18799 struct dwarf2_cu
*cu
)
18801 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18802 what template types look like, because the demangler
18803 frequently doesn't give the same name as the debug info. We
18804 could fix this by only using the demangled name to get the
18805 prefix (but see comment in read_structure_type). */
18807 struct partial_die_info
*real_pdi
;
18808 struct partial_die_info
*child_pdi
;
18810 /* If this DIE (this DIE's specification, if any) has a parent, then
18811 we should not do this. We'll prepend the parent's fully qualified
18812 name when we create the partial symbol. */
18814 real_pdi
= struct_pdi
;
18815 while (real_pdi
->has_specification
)
18817 auto res
= find_partial_die (real_pdi
->spec_offset
,
18818 real_pdi
->spec_is_dwz
, cu
);
18819 real_pdi
= res
.pdi
;
18823 if (real_pdi
->die_parent
!= NULL
)
18826 for (child_pdi
= struct_pdi
->die_child
;
18828 child_pdi
= child_pdi
->die_sibling
)
18830 if (child_pdi
->tag
== DW_TAG_subprogram
18831 && child_pdi
->linkage_name
!= NULL
)
18833 gdb::unique_xmalloc_ptr
<char> actual_class_name
18834 (language_class_name_from_physname (cu
->language_defn
,
18835 child_pdi
->linkage_name
));
18836 if (actual_class_name
!= NULL
)
18838 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18839 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
18840 struct_pdi
->canonical_name
= 1;
18847 /* Return true if a DIE with TAG may have the DW_AT_const_value
18851 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18855 case DW_TAG_constant
:
18856 case DW_TAG_enumerator
:
18857 case DW_TAG_formal_parameter
:
18858 case DW_TAG_template_value_param
:
18859 case DW_TAG_variable
:
18867 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18869 /* Once we've fixed up a die, there's no point in doing so again.
18870 This also avoids a memory leak if we were to call
18871 guess_partial_die_structure_name multiple times. */
18875 /* If we found a reference attribute and the DIE has no name, try
18876 to find a name in the referred to DIE. */
18878 if (raw_name
== NULL
&& has_specification
)
18880 struct partial_die_info
*spec_die
;
18882 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18883 spec_die
= res
.pdi
;
18886 spec_die
->fixup (cu
);
18888 if (spec_die
->raw_name
)
18890 raw_name
= spec_die
->raw_name
;
18891 canonical_name
= spec_die
->canonical_name
;
18893 /* Copy DW_AT_external attribute if it is set. */
18894 if (spec_die
->is_external
)
18895 is_external
= spec_die
->is_external
;
18899 if (!has_const_value
&& has_specification
18900 && can_have_DW_AT_const_value_p (tag
))
18902 struct partial_die_info
*spec_die
;
18904 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18905 spec_die
= res
.pdi
;
18908 spec_die
->fixup (cu
);
18910 if (spec_die
->has_const_value
)
18912 /* Copy DW_AT_const_value attribute if it is set. */
18913 has_const_value
= spec_die
->has_const_value
;
18917 /* Set default names for some unnamed DIEs. */
18919 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
18921 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
18922 canonical_name
= 1;
18925 /* If there is no parent die to provide a namespace, and there are
18926 children, see if we can determine the namespace from their linkage
18928 if (cu
->language
== language_cplus
18929 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18930 && die_parent
== NULL
18932 && (tag
== DW_TAG_class_type
18933 || tag
== DW_TAG_structure_type
18934 || tag
== DW_TAG_union_type
))
18935 guess_partial_die_structure_name (this, cu
);
18937 /* GCC might emit a nameless struct or union that has a linkage
18938 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18939 if (raw_name
== NULL
18940 && (tag
== DW_TAG_class_type
18941 || tag
== DW_TAG_interface_type
18942 || tag
== DW_TAG_structure_type
18943 || tag
== DW_TAG_union_type
)
18944 && linkage_name
!= NULL
)
18946 gdb::unique_xmalloc_ptr
<char> demangled
18947 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18948 if (demangled
!= nullptr)
18952 /* Strip any leading namespaces/classes, keep only the base name.
18953 DW_AT_name for named DIEs does not contain the prefixes. */
18954 base
= strrchr (demangled
.get (), ':');
18955 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18958 base
= demangled
.get ();
18960 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18961 raw_name
= objfile
->intern (base
);
18962 canonical_name
= 1;
18969 /* Read the .debug_loclists header contents from the given SECTION in the
18972 read_loclist_header (struct loclist_header
*header
,
18973 struct dwarf2_section_info
*section
)
18975 unsigned int bytes_read
;
18976 bfd
*abfd
= section
->get_bfd_owner ();
18977 const gdb_byte
*info_ptr
= section
->buffer
;
18978 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18979 info_ptr
+= bytes_read
;
18980 header
->version
= read_2_bytes (abfd
, info_ptr
);
18982 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18984 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18986 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18989 /* Return the DW_AT_loclists_base value for the CU. */
18991 lookup_loclist_base (struct dwarf2_cu
*cu
)
18993 /* For the .dwo unit, the loclist_base points to the first offset following
18994 the header. The header consists of the following entities-
18995 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18997 2. version (2 bytes)
18998 3. address size (1 byte)
18999 4. segment selector size (1 byte)
19000 5. offset entry count (4 bytes)
19001 These sizes are derived as per the DWARFv5 standard. */
19002 if (cu
->dwo_unit
!= nullptr)
19004 if (cu
->header
.initial_length_size
== 4)
19005 return LOCLIST_HEADER_SIZE32
;
19006 return LOCLIST_HEADER_SIZE64
;
19008 return cu
->loclist_base
;
19011 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19012 array of offsets in the .debug_loclists section. */
19014 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19016 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19017 struct objfile
*objfile
= per_objfile
->objfile
;
19018 bfd
*abfd
= objfile
->obfd
;
19019 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19020 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19022 section
->read (objfile
);
19023 if (section
->buffer
== NULL
)
19024 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19025 "section [in module %s]"), objfile_name (objfile
));
19026 struct loclist_header header
;
19027 read_loclist_header (&header
, section
);
19028 if (loclist_index
>= header
.offset_entry_count
)
19029 complaint (_("DW_FORM_loclistx pointing outside of "
19030 ".debug_loclists offset array [in module %s]"),
19031 objfile_name (objfile
));
19032 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19034 complaint (_("DW_FORM_loclistx pointing outside of "
19035 ".debug_loclists section [in module %s]"),
19036 objfile_name (objfile
));
19037 const gdb_byte
*info_ptr
19038 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19040 if (cu
->header
.offset_size
== 4)
19041 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19043 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19046 /* Process the attributes that had to be skipped in the first round. These
19047 attributes are the ones that need str_offsets_base or addr_base attributes.
19048 They could not have been processed in the first round, because at the time
19049 the values of str_offsets_base or addr_base may not have been known. */
19051 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19052 struct attribute
*attr
)
19054 struct dwarf2_cu
*cu
= reader
->cu
;
19055 switch (attr
->form
)
19057 case DW_FORM_addrx
:
19058 case DW_FORM_GNU_addr_index
:
19059 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19061 case DW_FORM_loclistx
:
19062 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19065 case DW_FORM_strx1
:
19066 case DW_FORM_strx2
:
19067 case DW_FORM_strx3
:
19068 case DW_FORM_strx4
:
19069 case DW_FORM_GNU_str_index
:
19071 unsigned int str_index
= DW_UNSND (attr
);
19072 if (reader
->dwo_file
!= NULL
)
19074 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19075 DW_STRING_IS_CANONICAL (attr
) = 0;
19079 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19080 DW_STRING_IS_CANONICAL (attr
) = 0;
19085 gdb_assert_not_reached (_("Unexpected DWARF form."));
19089 /* Read an attribute value described by an attribute form. */
19091 static const gdb_byte
*
19092 read_attribute_value (const struct die_reader_specs
*reader
,
19093 struct attribute
*attr
, unsigned form
,
19094 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19095 bool *need_reprocess
)
19097 struct dwarf2_cu
*cu
= reader
->cu
;
19098 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19099 struct objfile
*objfile
= per_objfile
->objfile
;
19100 bfd
*abfd
= reader
->abfd
;
19101 struct comp_unit_head
*cu_header
= &cu
->header
;
19102 unsigned int bytes_read
;
19103 struct dwarf_block
*blk
;
19104 *need_reprocess
= false;
19106 attr
->form
= (enum dwarf_form
) form
;
19109 case DW_FORM_ref_addr
:
19110 if (cu
->header
.version
== 2)
19111 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19114 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19116 info_ptr
+= bytes_read
;
19118 case DW_FORM_GNU_ref_alt
:
19119 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19120 info_ptr
+= bytes_read
;
19124 struct gdbarch
*gdbarch
= objfile
->arch ();
19125 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19126 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19127 info_ptr
+= bytes_read
;
19130 case DW_FORM_block2
:
19131 blk
= dwarf_alloc_block (cu
);
19132 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19134 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19135 info_ptr
+= blk
->size
;
19136 DW_BLOCK (attr
) = blk
;
19138 case DW_FORM_block4
:
19139 blk
= dwarf_alloc_block (cu
);
19140 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19142 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19143 info_ptr
+= blk
->size
;
19144 DW_BLOCK (attr
) = blk
;
19146 case DW_FORM_data2
:
19147 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19150 case DW_FORM_data4
:
19151 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19154 case DW_FORM_data8
:
19155 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19158 case DW_FORM_data16
:
19159 blk
= dwarf_alloc_block (cu
);
19161 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19163 DW_BLOCK (attr
) = blk
;
19165 case DW_FORM_sec_offset
:
19166 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19167 info_ptr
+= bytes_read
;
19169 case DW_FORM_loclistx
:
19171 *need_reprocess
= true;
19172 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19173 info_ptr
+= bytes_read
;
19176 case DW_FORM_string
:
19177 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19178 DW_STRING_IS_CANONICAL (attr
) = 0;
19179 info_ptr
+= bytes_read
;
19182 if (!cu
->per_cu
->is_dwz
)
19184 DW_STRING (attr
) = read_indirect_string (per_objfile
,
19185 abfd
, info_ptr
, cu_header
,
19187 DW_STRING_IS_CANONICAL (attr
) = 0;
19188 info_ptr
+= bytes_read
;
19192 case DW_FORM_line_strp
:
19193 if (!cu
->per_cu
->is_dwz
)
19195 DW_STRING (attr
) = per_objfile
->read_line_string (info_ptr
, cu_header
,
19197 DW_STRING_IS_CANONICAL (attr
) = 0;
19198 info_ptr
+= bytes_read
;
19202 case DW_FORM_GNU_strp_alt
:
19204 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19205 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19208 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19209 DW_STRING_IS_CANONICAL (attr
) = 0;
19210 info_ptr
+= bytes_read
;
19213 case DW_FORM_exprloc
:
19214 case DW_FORM_block
:
19215 blk
= dwarf_alloc_block (cu
);
19216 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19217 info_ptr
+= bytes_read
;
19218 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19219 info_ptr
+= blk
->size
;
19220 DW_BLOCK (attr
) = blk
;
19222 case DW_FORM_block1
:
19223 blk
= dwarf_alloc_block (cu
);
19224 blk
->size
= read_1_byte (abfd
, info_ptr
);
19226 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19227 info_ptr
+= blk
->size
;
19228 DW_BLOCK (attr
) = blk
;
19230 case DW_FORM_data1
:
19231 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19235 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19238 case DW_FORM_flag_present
:
19239 DW_UNSND (attr
) = 1;
19241 case DW_FORM_sdata
:
19242 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19243 info_ptr
+= bytes_read
;
19245 case DW_FORM_udata
:
19246 case DW_FORM_rnglistx
:
19247 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19248 info_ptr
+= bytes_read
;
19251 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19252 + read_1_byte (abfd
, info_ptr
));
19256 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19257 + read_2_bytes (abfd
, info_ptr
));
19261 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19262 + read_4_bytes (abfd
, info_ptr
));
19266 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19267 + read_8_bytes (abfd
, info_ptr
));
19270 case DW_FORM_ref_sig8
:
19271 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19274 case DW_FORM_ref_udata
:
19275 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19276 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19277 info_ptr
+= bytes_read
;
19279 case DW_FORM_indirect
:
19280 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19281 info_ptr
+= bytes_read
;
19282 if (form
== DW_FORM_implicit_const
)
19284 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19285 info_ptr
+= bytes_read
;
19287 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19288 info_ptr
, need_reprocess
);
19290 case DW_FORM_implicit_const
:
19291 DW_SND (attr
) = implicit_const
;
19293 case DW_FORM_addrx
:
19294 case DW_FORM_GNU_addr_index
:
19295 *need_reprocess
= true;
19296 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19297 info_ptr
+= bytes_read
;
19300 case DW_FORM_strx1
:
19301 case DW_FORM_strx2
:
19302 case DW_FORM_strx3
:
19303 case DW_FORM_strx4
:
19304 case DW_FORM_GNU_str_index
:
19306 ULONGEST str_index
;
19307 if (form
== DW_FORM_strx1
)
19309 str_index
= read_1_byte (abfd
, info_ptr
);
19312 else if (form
== DW_FORM_strx2
)
19314 str_index
= read_2_bytes (abfd
, info_ptr
);
19317 else if (form
== DW_FORM_strx3
)
19319 str_index
= read_3_bytes (abfd
, info_ptr
);
19322 else if (form
== DW_FORM_strx4
)
19324 str_index
= read_4_bytes (abfd
, info_ptr
);
19329 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19330 info_ptr
+= bytes_read
;
19332 *need_reprocess
= true;
19333 DW_UNSND (attr
) = str_index
;
19337 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19338 dwarf_form_name (form
),
19339 bfd_get_filename (abfd
));
19343 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19344 attr
->form
= DW_FORM_GNU_ref_alt
;
19346 /* We have seen instances where the compiler tried to emit a byte
19347 size attribute of -1 which ended up being encoded as an unsigned
19348 0xffffffff. Although 0xffffffff is technically a valid size value,
19349 an object of this size seems pretty unlikely so we can relatively
19350 safely treat these cases as if the size attribute was invalid and
19351 treat them as zero by default. */
19352 if (attr
->name
== DW_AT_byte_size
19353 && form
== DW_FORM_data4
19354 && DW_UNSND (attr
) >= 0xffffffff)
19357 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19358 hex_string (DW_UNSND (attr
)));
19359 DW_UNSND (attr
) = 0;
19365 /* Read an attribute described by an abbreviated attribute. */
19367 static const gdb_byte
*
19368 read_attribute (const struct die_reader_specs
*reader
,
19369 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19370 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19372 attr
->name
= abbrev
->name
;
19373 return read_attribute_value (reader
, attr
, abbrev
->form
,
19374 abbrev
->implicit_const
, info_ptr
,
19378 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19380 static const char *
19381 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
19382 LONGEST str_offset
)
19384 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
19385 str_offset
, "DW_FORM_strp");
19388 /* Return pointer to string at .debug_str offset as read from BUF.
19389 BUF is assumed to be in a compilation unit described by CU_HEADER.
19390 Return *BYTES_READ_PTR count of bytes read from BUF. */
19392 static const char *
19393 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
19394 const gdb_byte
*buf
,
19395 const struct comp_unit_head
*cu_header
,
19396 unsigned int *bytes_read_ptr
)
19398 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19400 return read_indirect_string_at_offset (per_objfile
, str_offset
);
19406 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19407 const struct comp_unit_head
*cu_header
,
19408 unsigned int *bytes_read_ptr
)
19410 bfd
*abfd
= objfile
->obfd
;
19411 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19413 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19416 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19417 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19418 ADDR_SIZE is the size of addresses from the CU header. */
19421 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
19422 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
19424 struct objfile
*objfile
= per_objfile
->objfile
;
19425 bfd
*abfd
= objfile
->obfd
;
19426 const gdb_byte
*info_ptr
;
19427 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19429 per_objfile
->per_bfd
->addr
.read (objfile
);
19430 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19431 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19432 objfile_name (objfile
));
19433 if (addr_base_or_zero
+ addr_index
* addr_size
19434 >= per_objfile
->per_bfd
->addr
.size
)
19435 error (_("DW_FORM_addr_index pointing outside of "
19436 ".debug_addr section [in module %s]"),
19437 objfile_name (objfile
));
19438 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
19439 + addr_index
* addr_size
);
19440 if (addr_size
== 4)
19441 return bfd_get_32 (abfd
, info_ptr
);
19443 return bfd_get_64 (abfd
, info_ptr
);
19446 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19449 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19451 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19452 cu
->addr_base
, cu
->header
.addr_size
);
19455 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19458 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19459 unsigned int *bytes_read
)
19461 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19462 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19464 return read_addr_index (cu
, addr_index
);
19470 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19471 dwarf2_per_objfile
*per_objfile
,
19472 unsigned int addr_index
)
19474 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
19475 gdb::optional
<ULONGEST
> addr_base
;
19478 /* We need addr_base and addr_size.
19479 If we don't have PER_CU->cu, we have to get it.
19480 Nasty, but the alternative is storing the needed info in PER_CU,
19481 which at this point doesn't seem justified: it's not clear how frequently
19482 it would get used and it would increase the size of every PER_CU.
19483 Entry points like dwarf2_per_cu_addr_size do a similar thing
19484 so we're not in uncharted territory here.
19485 Alas we need to be a bit more complicated as addr_base is contained
19488 We don't need to read the entire CU(/TU).
19489 We just need the header and top level die.
19491 IWBN to use the aging mechanism to let us lazily later discard the CU.
19492 For now we skip this optimization. */
19496 addr_base
= cu
->addr_base
;
19497 addr_size
= cu
->header
.addr_size
;
19501 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
19502 addr_base
= reader
.cu
->addr_base
;
19503 addr_size
= reader
.cu
->header
.addr_size
;
19506 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
19509 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19510 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19513 static const char *
19514 read_str_index (struct dwarf2_cu
*cu
,
19515 struct dwarf2_section_info
*str_section
,
19516 struct dwarf2_section_info
*str_offsets_section
,
19517 ULONGEST str_offsets_base
, ULONGEST str_index
)
19519 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19520 struct objfile
*objfile
= per_objfile
->objfile
;
19521 const char *objf_name
= objfile_name (objfile
);
19522 bfd
*abfd
= objfile
->obfd
;
19523 const gdb_byte
*info_ptr
;
19524 ULONGEST str_offset
;
19525 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19527 str_section
->read (objfile
);
19528 str_offsets_section
->read (objfile
);
19529 if (str_section
->buffer
== NULL
)
19530 error (_("%s used without %s section"
19531 " in CU at offset %s [in module %s]"),
19532 form_name
, str_section
->get_name (),
19533 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19534 if (str_offsets_section
->buffer
== NULL
)
19535 error (_("%s used without %s section"
19536 " in CU at offset %s [in module %s]"),
19537 form_name
, str_section
->get_name (),
19538 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19539 info_ptr
= (str_offsets_section
->buffer
19541 + str_index
* cu
->header
.offset_size
);
19542 if (cu
->header
.offset_size
== 4)
19543 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19545 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19546 if (str_offset
>= str_section
->size
)
19547 error (_("Offset from %s pointing outside of"
19548 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19549 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19550 return (const char *) (str_section
->buffer
+ str_offset
);
19553 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19555 static const char *
19556 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19558 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19559 ? reader
->cu
->header
.addr_size
: 0;
19560 return read_str_index (reader
->cu
,
19561 &reader
->dwo_file
->sections
.str
,
19562 &reader
->dwo_file
->sections
.str_offsets
,
19563 str_offsets_base
, str_index
);
19566 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19568 static const char *
19569 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19571 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19572 const char *objf_name
= objfile_name (objfile
);
19573 static const char form_name
[] = "DW_FORM_GNU_str_index";
19574 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19576 if (!cu
->str_offsets_base
.has_value ())
19577 error (_("%s used in Fission stub without %s"
19578 " in CU at offset 0x%lx [in module %s]"),
19579 form_name
, str_offsets_attr_name
,
19580 (long) cu
->header
.offset_size
, objf_name
);
19582 return read_str_index (cu
,
19583 &cu
->per_objfile
->per_bfd
->str
,
19584 &cu
->per_objfile
->per_bfd
->str_offsets
,
19585 *cu
->str_offsets_base
, str_index
);
19588 /* Return the length of an LEB128 number in BUF. */
19591 leb128_size (const gdb_byte
*buf
)
19593 const gdb_byte
*begin
= buf
;
19599 if ((byte
& 128) == 0)
19600 return buf
- begin
;
19605 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19614 cu
->language
= language_c
;
19617 case DW_LANG_C_plus_plus
:
19618 case DW_LANG_C_plus_plus_11
:
19619 case DW_LANG_C_plus_plus_14
:
19620 cu
->language
= language_cplus
;
19623 cu
->language
= language_d
;
19625 case DW_LANG_Fortran77
:
19626 case DW_LANG_Fortran90
:
19627 case DW_LANG_Fortran95
:
19628 case DW_LANG_Fortran03
:
19629 case DW_LANG_Fortran08
:
19630 cu
->language
= language_fortran
;
19633 cu
->language
= language_go
;
19635 case DW_LANG_Mips_Assembler
:
19636 cu
->language
= language_asm
;
19638 case DW_LANG_Ada83
:
19639 case DW_LANG_Ada95
:
19640 cu
->language
= language_ada
;
19642 case DW_LANG_Modula2
:
19643 cu
->language
= language_m2
;
19645 case DW_LANG_Pascal83
:
19646 cu
->language
= language_pascal
;
19649 cu
->language
= language_objc
;
19652 case DW_LANG_Rust_old
:
19653 cu
->language
= language_rust
;
19655 case DW_LANG_Cobol74
:
19656 case DW_LANG_Cobol85
:
19658 cu
->language
= language_minimal
;
19661 cu
->language_defn
= language_def (cu
->language
);
19664 /* Return the named attribute or NULL if not there. */
19666 static struct attribute
*
19667 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19672 struct attribute
*spec
= NULL
;
19674 for (i
= 0; i
< die
->num_attrs
; ++i
)
19676 if (die
->attrs
[i
].name
== name
)
19677 return &die
->attrs
[i
];
19678 if (die
->attrs
[i
].name
== DW_AT_specification
19679 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19680 spec
= &die
->attrs
[i
];
19686 die
= follow_die_ref (die
, spec
, &cu
);
19692 /* Return the string associated with a string-typed attribute, or NULL if it
19693 is either not found or is of an incorrect type. */
19695 static const char *
19696 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19698 struct attribute
*attr
;
19699 const char *str
= NULL
;
19701 attr
= dwarf2_attr (die
, name
, cu
);
19705 str
= attr
->value_as_string ();
19706 if (str
== nullptr)
19707 complaint (_("string type expected for attribute %s for "
19708 "DIE at %s in module %s"),
19709 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19710 objfile_name (cu
->per_objfile
->objfile
));
19716 /* Return the dwo name or NULL if not present. If present, it is in either
19717 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19718 static const char *
19719 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19721 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19722 if (dwo_name
== nullptr)
19723 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19727 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19728 and holds a non-zero value. This function should only be used for
19729 DW_FORM_flag or DW_FORM_flag_present attributes. */
19732 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19734 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19736 return (attr
&& DW_UNSND (attr
));
19740 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19742 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19743 which value is non-zero. However, we have to be careful with
19744 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19745 (via dwarf2_flag_true_p) follows this attribute. So we may
19746 end up accidently finding a declaration attribute that belongs
19747 to a different DIE referenced by the specification attribute,
19748 even though the given DIE does not have a declaration attribute. */
19749 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19750 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19753 /* Return the die giving the specification for DIE, if there is
19754 one. *SPEC_CU is the CU containing DIE on input, and the CU
19755 containing the return value on output. If there is no
19756 specification, but there is an abstract origin, that is
19759 static struct die_info
*
19760 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19762 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19765 if (spec_attr
== NULL
)
19766 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19768 if (spec_attr
== NULL
)
19771 return follow_die_ref (die
, spec_attr
, spec_cu
);
19774 /* Stub for free_line_header to match void * callback types. */
19777 free_line_header_voidp (void *arg
)
19779 struct line_header
*lh
= (struct line_header
*) arg
;
19784 /* A convenience function to find the proper .debug_line section for a CU. */
19786 static struct dwarf2_section_info
*
19787 get_debug_line_section (struct dwarf2_cu
*cu
)
19789 struct dwarf2_section_info
*section
;
19790 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19792 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19794 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19795 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19796 else if (cu
->per_cu
->is_dwz
)
19798 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19800 section
= &dwz
->line
;
19803 section
= &per_objfile
->per_bfd
->line
;
19808 /* Read the statement program header starting at OFFSET in
19809 .debug_line, or .debug_line.dwo. Return a pointer
19810 to a struct line_header, allocated using xmalloc.
19811 Returns NULL if there is a problem reading the header, e.g., if it
19812 has a version we don't understand.
19814 NOTE: the strings in the include directory and file name tables of
19815 the returned object point into the dwarf line section buffer,
19816 and must not be freed. */
19818 static line_header_up
19819 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19821 struct dwarf2_section_info
*section
;
19822 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19824 section
= get_debug_line_section (cu
);
19825 section
->read (per_objfile
->objfile
);
19826 if (section
->buffer
== NULL
)
19828 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19829 complaint (_("missing .debug_line.dwo section"));
19831 complaint (_("missing .debug_line section"));
19835 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19836 per_objfile
, section
, &cu
->header
);
19839 /* Subroutine of dwarf_decode_lines to simplify it.
19840 Return the file name of the psymtab for the given file_entry.
19841 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19842 If space for the result is malloc'd, *NAME_HOLDER will be set.
19843 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19845 static const char *
19846 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19847 const dwarf2_psymtab
*pst
,
19848 const char *comp_dir
,
19849 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19851 const char *include_name
= fe
.name
;
19852 const char *include_name_to_compare
= include_name
;
19853 const char *pst_filename
;
19856 const char *dir_name
= fe
.include_dir (lh
);
19858 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19859 if (!IS_ABSOLUTE_PATH (include_name
)
19860 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19862 /* Avoid creating a duplicate psymtab for PST.
19863 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19864 Before we do the comparison, however, we need to account
19865 for DIR_NAME and COMP_DIR.
19866 First prepend dir_name (if non-NULL). If we still don't
19867 have an absolute path prepend comp_dir (if non-NULL).
19868 However, the directory we record in the include-file's
19869 psymtab does not contain COMP_DIR (to match the
19870 corresponding symtab(s)).
19875 bash$ gcc -g ./hello.c
19876 include_name = "hello.c"
19878 DW_AT_comp_dir = comp_dir = "/tmp"
19879 DW_AT_name = "./hello.c"
19883 if (dir_name
!= NULL
)
19885 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19886 include_name
, (char *) NULL
));
19887 include_name
= name_holder
->get ();
19888 include_name_to_compare
= include_name
;
19890 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19892 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19893 include_name
, (char *) NULL
));
19894 include_name_to_compare
= hold_compare
.get ();
19898 pst_filename
= pst
->filename
;
19899 gdb::unique_xmalloc_ptr
<char> copied_name
;
19900 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19902 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19903 pst_filename
, (char *) NULL
));
19904 pst_filename
= copied_name
.get ();
19907 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19911 return include_name
;
19914 /* State machine to track the state of the line number program. */
19916 class lnp_state_machine
19919 /* Initialize a machine state for the start of a line number
19921 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19922 bool record_lines_p
);
19924 file_entry
*current_file ()
19926 /* lh->file_names is 0-based, but the file name numbers in the
19927 statement program are 1-based. */
19928 return m_line_header
->file_name_at (m_file
);
19931 /* Record the line in the state machine. END_SEQUENCE is true if
19932 we're processing the end of a sequence. */
19933 void record_line (bool end_sequence
);
19935 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19936 nop-out rest of the lines in this sequence. */
19937 void check_line_address (struct dwarf2_cu
*cu
,
19938 const gdb_byte
*line_ptr
,
19939 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19941 void handle_set_discriminator (unsigned int discriminator
)
19943 m_discriminator
= discriminator
;
19944 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19947 /* Handle DW_LNE_set_address. */
19948 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19951 address
+= baseaddr
;
19952 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19955 /* Handle DW_LNS_advance_pc. */
19956 void handle_advance_pc (CORE_ADDR adjust
);
19958 /* Handle a special opcode. */
19959 void handle_special_opcode (unsigned char op_code
);
19961 /* Handle DW_LNS_advance_line. */
19962 void handle_advance_line (int line_delta
)
19964 advance_line (line_delta
);
19967 /* Handle DW_LNS_set_file. */
19968 void handle_set_file (file_name_index file
);
19970 /* Handle DW_LNS_negate_stmt. */
19971 void handle_negate_stmt ()
19973 m_is_stmt
= !m_is_stmt
;
19976 /* Handle DW_LNS_const_add_pc. */
19977 void handle_const_add_pc ();
19979 /* Handle DW_LNS_fixed_advance_pc. */
19980 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19982 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19986 /* Handle DW_LNS_copy. */
19987 void handle_copy ()
19989 record_line (false);
19990 m_discriminator
= 0;
19993 /* Handle DW_LNE_end_sequence. */
19994 void handle_end_sequence ()
19996 m_currently_recording_lines
= true;
20000 /* Advance the line by LINE_DELTA. */
20001 void advance_line (int line_delta
)
20003 m_line
+= line_delta
;
20005 if (line_delta
!= 0)
20006 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20009 struct dwarf2_cu
*m_cu
;
20011 gdbarch
*m_gdbarch
;
20013 /* True if we're recording lines.
20014 Otherwise we're building partial symtabs and are just interested in
20015 finding include files mentioned by the line number program. */
20016 bool m_record_lines_p
;
20018 /* The line number header. */
20019 line_header
*m_line_header
;
20021 /* These are part of the standard DWARF line number state machine,
20022 and initialized according to the DWARF spec. */
20024 unsigned char m_op_index
= 0;
20025 /* The line table index of the current file. */
20026 file_name_index m_file
= 1;
20027 unsigned int m_line
= 1;
20029 /* These are initialized in the constructor. */
20031 CORE_ADDR m_address
;
20033 unsigned int m_discriminator
;
20035 /* Additional bits of state we need to track. */
20037 /* The last file that we called dwarf2_start_subfile for.
20038 This is only used for TLLs. */
20039 unsigned int m_last_file
= 0;
20040 /* The last file a line number was recorded for. */
20041 struct subfile
*m_last_subfile
= NULL
;
20043 /* When true, record the lines we decode. */
20044 bool m_currently_recording_lines
= false;
20046 /* The last line number that was recorded, used to coalesce
20047 consecutive entries for the same line. This can happen, for
20048 example, when discriminators are present. PR 17276. */
20049 unsigned int m_last_line
= 0;
20050 bool m_line_has_non_zero_discriminator
= false;
20054 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20056 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20057 / m_line_header
->maximum_ops_per_instruction
)
20058 * m_line_header
->minimum_instruction_length
);
20059 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20060 m_op_index
= ((m_op_index
+ adjust
)
20061 % m_line_header
->maximum_ops_per_instruction
);
20065 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20067 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20068 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20069 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20070 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20071 / m_line_header
->maximum_ops_per_instruction
)
20072 * m_line_header
->minimum_instruction_length
);
20073 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20074 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20075 % m_line_header
->maximum_ops_per_instruction
);
20077 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20078 advance_line (line_delta
);
20079 record_line (false);
20080 m_discriminator
= 0;
20084 lnp_state_machine::handle_set_file (file_name_index file
)
20088 const file_entry
*fe
= current_file ();
20090 dwarf2_debug_line_missing_file_complaint ();
20091 else if (m_record_lines_p
)
20093 const char *dir
= fe
->include_dir (m_line_header
);
20095 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20096 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20097 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20102 lnp_state_machine::handle_const_add_pc ()
20105 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20108 = (((m_op_index
+ adjust
)
20109 / m_line_header
->maximum_ops_per_instruction
)
20110 * m_line_header
->minimum_instruction_length
);
20112 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20113 m_op_index
= ((m_op_index
+ adjust
)
20114 % m_line_header
->maximum_ops_per_instruction
);
20117 /* Return non-zero if we should add LINE to the line number table.
20118 LINE is the line to add, LAST_LINE is the last line that was added,
20119 LAST_SUBFILE is the subfile for LAST_LINE.
20120 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20121 had a non-zero discriminator.
20123 We have to be careful in the presence of discriminators.
20124 E.g., for this line:
20126 for (i = 0; i < 100000; i++);
20128 clang can emit four line number entries for that one line,
20129 each with a different discriminator.
20130 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20132 However, we want gdb to coalesce all four entries into one.
20133 Otherwise the user could stepi into the middle of the line and
20134 gdb would get confused about whether the pc really was in the
20135 middle of the line.
20137 Things are further complicated by the fact that two consecutive
20138 line number entries for the same line is a heuristic used by gcc
20139 to denote the end of the prologue. So we can't just discard duplicate
20140 entries, we have to be selective about it. The heuristic we use is
20141 that we only collapse consecutive entries for the same line if at least
20142 one of those entries has a non-zero discriminator. PR 17276.
20144 Note: Addresses in the line number state machine can never go backwards
20145 within one sequence, thus this coalescing is ok. */
20148 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20149 unsigned int line
, unsigned int last_line
,
20150 int line_has_non_zero_discriminator
,
20151 struct subfile
*last_subfile
)
20153 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20155 if (line
!= last_line
)
20157 /* Same line for the same file that we've seen already.
20158 As a last check, for pr 17276, only record the line if the line
20159 has never had a non-zero discriminator. */
20160 if (!line_has_non_zero_discriminator
)
20165 /* Use the CU's builder to record line number LINE beginning at
20166 address ADDRESS in the line table of subfile SUBFILE. */
20169 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20170 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20171 struct dwarf2_cu
*cu
)
20173 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20175 if (dwarf_line_debug
)
20177 fprintf_unfiltered (gdb_stdlog
,
20178 "Recording line %u, file %s, address %s\n",
20179 line
, lbasename (subfile
->name
),
20180 paddress (gdbarch
, address
));
20184 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20187 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20188 Mark the end of a set of line number records.
20189 The arguments are the same as for dwarf_record_line_1.
20190 If SUBFILE is NULL the request is ignored. */
20193 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20194 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20196 if (subfile
== NULL
)
20199 if (dwarf_line_debug
)
20201 fprintf_unfiltered (gdb_stdlog
,
20202 "Finishing current line, file %s, address %s\n",
20203 lbasename (subfile
->name
),
20204 paddress (gdbarch
, address
));
20207 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20211 lnp_state_machine::record_line (bool end_sequence
)
20213 if (dwarf_line_debug
)
20215 fprintf_unfiltered (gdb_stdlog
,
20216 "Processing actual line %u: file %u,"
20217 " address %s, is_stmt %u, discrim %u%s\n",
20219 paddress (m_gdbarch
, m_address
),
20220 m_is_stmt
, m_discriminator
,
20221 (end_sequence
? "\t(end sequence)" : ""));
20224 file_entry
*fe
= current_file ();
20227 dwarf2_debug_line_missing_file_complaint ();
20228 /* For now we ignore lines not starting on an instruction boundary.
20229 But not when processing end_sequence for compatibility with the
20230 previous version of the code. */
20231 else if (m_op_index
== 0 || end_sequence
)
20233 fe
->included_p
= 1;
20234 if (m_record_lines_p
)
20236 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20239 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20240 m_currently_recording_lines
? m_cu
: nullptr);
20245 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20247 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20248 m_line_has_non_zero_discriminator
,
20251 buildsym_compunit
*builder
= m_cu
->get_builder ();
20252 dwarf_record_line_1 (m_gdbarch
,
20253 builder
->get_current_subfile (),
20254 m_line
, m_address
, is_stmt
,
20255 m_currently_recording_lines
? m_cu
: nullptr);
20257 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20258 m_last_line
= m_line
;
20264 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20265 line_header
*lh
, bool record_lines_p
)
20269 m_record_lines_p
= record_lines_p
;
20270 m_line_header
= lh
;
20272 m_currently_recording_lines
= true;
20274 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20275 was a line entry for it so that the backend has a chance to adjust it
20276 and also record it in case it needs it. This is currently used by MIPS
20277 code, cf. `mips_adjust_dwarf2_line'. */
20278 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20279 m_is_stmt
= lh
->default_is_stmt
;
20280 m_discriminator
= 0;
20284 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20285 const gdb_byte
*line_ptr
,
20286 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20288 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20289 the pc range of the CU. However, we restrict the test to only ADDRESS
20290 values of zero to preserve GDB's previous behaviour which is to handle
20291 the specific case of a function being GC'd by the linker. */
20293 if (address
== 0 && address
< unrelocated_lowpc
)
20295 /* This line table is for a function which has been
20296 GCd by the linker. Ignore it. PR gdb/12528 */
20298 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20299 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20301 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20302 line_offset
, objfile_name (objfile
));
20303 m_currently_recording_lines
= false;
20304 /* Note: m_currently_recording_lines is left as false until we see
20305 DW_LNE_end_sequence. */
20309 /* Subroutine of dwarf_decode_lines to simplify it.
20310 Process the line number information in LH.
20311 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20312 program in order to set included_p for every referenced header. */
20315 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20316 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20318 const gdb_byte
*line_ptr
, *extended_end
;
20319 const gdb_byte
*line_end
;
20320 unsigned int bytes_read
, extended_len
;
20321 unsigned char op_code
, extended_op
;
20322 CORE_ADDR baseaddr
;
20323 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20324 bfd
*abfd
= objfile
->obfd
;
20325 struct gdbarch
*gdbarch
= objfile
->arch ();
20326 /* True if we're recording line info (as opposed to building partial
20327 symtabs and just interested in finding include files mentioned by
20328 the line number program). */
20329 bool record_lines_p
= !decode_for_pst_p
;
20331 baseaddr
= objfile
->text_section_offset ();
20333 line_ptr
= lh
->statement_program_start
;
20334 line_end
= lh
->statement_program_end
;
20336 /* Read the statement sequences until there's nothing left. */
20337 while (line_ptr
< line_end
)
20339 /* The DWARF line number program state machine. Reset the state
20340 machine at the start of each sequence. */
20341 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20342 bool end_sequence
= false;
20344 if (record_lines_p
)
20346 /* Start a subfile for the current file of the state
20348 const file_entry
*fe
= state_machine
.current_file ();
20351 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20354 /* Decode the table. */
20355 while (line_ptr
< line_end
&& !end_sequence
)
20357 op_code
= read_1_byte (abfd
, line_ptr
);
20360 if (op_code
>= lh
->opcode_base
)
20362 /* Special opcode. */
20363 state_machine
.handle_special_opcode (op_code
);
20365 else switch (op_code
)
20367 case DW_LNS_extended_op
:
20368 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20370 line_ptr
+= bytes_read
;
20371 extended_end
= line_ptr
+ extended_len
;
20372 extended_op
= read_1_byte (abfd
, line_ptr
);
20374 switch (extended_op
)
20376 case DW_LNE_end_sequence
:
20377 state_machine
.handle_end_sequence ();
20378 end_sequence
= true;
20380 case DW_LNE_set_address
:
20383 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20384 line_ptr
+= bytes_read
;
20386 state_machine
.check_line_address (cu
, line_ptr
,
20387 lowpc
- baseaddr
, address
);
20388 state_machine
.handle_set_address (baseaddr
, address
);
20391 case DW_LNE_define_file
:
20393 const char *cur_file
;
20394 unsigned int mod_time
, length
;
20397 cur_file
= read_direct_string (abfd
, line_ptr
,
20399 line_ptr
+= bytes_read
;
20400 dindex
= (dir_index
)
20401 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20402 line_ptr
+= bytes_read
;
20404 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20405 line_ptr
+= bytes_read
;
20407 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20408 line_ptr
+= bytes_read
;
20409 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20412 case DW_LNE_set_discriminator
:
20414 /* The discriminator is not interesting to the
20415 debugger; just ignore it. We still need to
20416 check its value though:
20417 if there are consecutive entries for the same
20418 (non-prologue) line we want to coalesce them.
20421 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20422 line_ptr
+= bytes_read
;
20424 state_machine
.handle_set_discriminator (discr
);
20428 complaint (_("mangled .debug_line section"));
20431 /* Make sure that we parsed the extended op correctly. If e.g.
20432 we expected a different address size than the producer used,
20433 we may have read the wrong number of bytes. */
20434 if (line_ptr
!= extended_end
)
20436 complaint (_("mangled .debug_line section"));
20441 state_machine
.handle_copy ();
20443 case DW_LNS_advance_pc
:
20446 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20447 line_ptr
+= bytes_read
;
20449 state_machine
.handle_advance_pc (adjust
);
20452 case DW_LNS_advance_line
:
20455 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20456 line_ptr
+= bytes_read
;
20458 state_machine
.handle_advance_line (line_delta
);
20461 case DW_LNS_set_file
:
20463 file_name_index file
20464 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20466 line_ptr
+= bytes_read
;
20468 state_machine
.handle_set_file (file
);
20471 case DW_LNS_set_column
:
20472 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20473 line_ptr
+= bytes_read
;
20475 case DW_LNS_negate_stmt
:
20476 state_machine
.handle_negate_stmt ();
20478 case DW_LNS_set_basic_block
:
20480 /* Add to the address register of the state machine the
20481 address increment value corresponding to special opcode
20482 255. I.e., this value is scaled by the minimum
20483 instruction length since special opcode 255 would have
20484 scaled the increment. */
20485 case DW_LNS_const_add_pc
:
20486 state_machine
.handle_const_add_pc ();
20488 case DW_LNS_fixed_advance_pc
:
20490 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20493 state_machine
.handle_fixed_advance_pc (addr_adj
);
20498 /* Unknown standard opcode, ignore it. */
20501 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20503 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20504 line_ptr
+= bytes_read
;
20511 dwarf2_debug_line_missing_end_sequence_complaint ();
20513 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20514 in which case we still finish recording the last line). */
20515 state_machine
.record_line (true);
20519 /* Decode the Line Number Program (LNP) for the given line_header
20520 structure and CU. The actual information extracted and the type
20521 of structures created from the LNP depends on the value of PST.
20523 1. If PST is NULL, then this procedure uses the data from the program
20524 to create all necessary symbol tables, and their linetables.
20526 2. If PST is not NULL, this procedure reads the program to determine
20527 the list of files included by the unit represented by PST, and
20528 builds all the associated partial symbol tables.
20530 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20531 It is used for relative paths in the line table.
20532 NOTE: When processing partial symtabs (pst != NULL),
20533 comp_dir == pst->dirname.
20535 NOTE: It is important that psymtabs have the same file name (via strcmp)
20536 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20537 symtab we don't use it in the name of the psymtabs we create.
20538 E.g. expand_line_sal requires this when finding psymtabs to expand.
20539 A good testcase for this is mb-inline.exp.
20541 LOWPC is the lowest address in CU (or 0 if not known).
20543 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20544 for its PC<->lines mapping information. Otherwise only the filename
20545 table is read in. */
20548 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20549 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20550 CORE_ADDR lowpc
, int decode_mapping
)
20552 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20553 const int decode_for_pst_p
= (pst
!= NULL
);
20555 if (decode_mapping
)
20556 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20558 if (decode_for_pst_p
)
20560 /* Now that we're done scanning the Line Header Program, we can
20561 create the psymtab of each included file. */
20562 for (auto &file_entry
: lh
->file_names ())
20563 if (file_entry
.included_p
== 1)
20565 gdb::unique_xmalloc_ptr
<char> name_holder
;
20566 const char *include_name
=
20567 psymtab_include_file_name (lh
, file_entry
, pst
,
20568 comp_dir
, &name_holder
);
20569 if (include_name
!= NULL
)
20570 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20575 /* Make sure a symtab is created for every file, even files
20576 which contain only variables (i.e. no code with associated
20578 buildsym_compunit
*builder
= cu
->get_builder ();
20579 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20581 for (auto &fe
: lh
->file_names ())
20583 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20584 if (builder
->get_current_subfile ()->symtab
== NULL
)
20586 builder
->get_current_subfile ()->symtab
20587 = allocate_symtab (cust
,
20588 builder
->get_current_subfile ()->name
);
20590 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20595 /* Start a subfile for DWARF. FILENAME is the name of the file and
20596 DIRNAME the name of the source directory which contains FILENAME
20597 or NULL if not known.
20598 This routine tries to keep line numbers from identical absolute and
20599 relative file names in a common subfile.
20601 Using the `list' example from the GDB testsuite, which resides in
20602 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20603 of /srcdir/list0.c yields the following debugging information for list0.c:
20605 DW_AT_name: /srcdir/list0.c
20606 DW_AT_comp_dir: /compdir
20607 files.files[0].name: list0.h
20608 files.files[0].dir: /srcdir
20609 files.files[1].name: list0.c
20610 files.files[1].dir: /srcdir
20612 The line number information for list0.c has to end up in a single
20613 subfile, so that `break /srcdir/list0.c:1' works as expected.
20614 start_subfile will ensure that this happens provided that we pass the
20615 concatenation of files.files[1].dir and files.files[1].name as the
20619 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20620 const char *dirname
)
20622 gdb::unique_xmalloc_ptr
<char> copy
;
20624 /* In order not to lose the line information directory,
20625 we concatenate it to the filename when it makes sense.
20626 Note that the Dwarf3 standard says (speaking of filenames in line
20627 information): ``The directory index is ignored for file names
20628 that represent full path names''. Thus ignoring dirname in the
20629 `else' branch below isn't an issue. */
20631 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20633 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20634 filename
= copy
.get ();
20637 cu
->get_builder ()->start_subfile (filename
);
20640 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20641 buildsym_compunit constructor. */
20643 struct compunit_symtab
*
20644 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20647 gdb_assert (m_builder
== nullptr);
20649 m_builder
.reset (new struct buildsym_compunit
20650 (this->per_objfile
->objfile
,
20651 name
, comp_dir
, language
, low_pc
));
20653 list_in_scope
= get_builder ()->get_file_symbols ();
20655 get_builder ()->record_debugformat ("DWARF 2");
20656 get_builder ()->record_producer (producer
);
20658 processing_has_namespace_info
= false;
20660 return get_builder ()->get_compunit_symtab ();
20664 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20665 struct dwarf2_cu
*cu
)
20667 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20668 struct comp_unit_head
*cu_header
= &cu
->header
;
20670 /* NOTE drow/2003-01-30: There used to be a comment and some special
20671 code here to turn a symbol with DW_AT_external and a
20672 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20673 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20674 with some versions of binutils) where shared libraries could have
20675 relocations against symbols in their debug information - the
20676 minimal symbol would have the right address, but the debug info
20677 would not. It's no longer necessary, because we will explicitly
20678 apply relocations when we read in the debug information now. */
20680 /* A DW_AT_location attribute with no contents indicates that a
20681 variable has been optimized away. */
20682 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20684 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20688 /* Handle one degenerate form of location expression specially, to
20689 preserve GDB's previous behavior when section offsets are
20690 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20691 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20693 if (attr
->form_is_block ()
20694 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20695 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20696 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20697 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20698 && (DW_BLOCK (attr
)->size
20699 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20701 unsigned int dummy
;
20703 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20704 SET_SYMBOL_VALUE_ADDRESS
20705 (sym
, cu
->header
.read_address (objfile
->obfd
,
20706 DW_BLOCK (attr
)->data
+ 1,
20709 SET_SYMBOL_VALUE_ADDRESS
20710 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20712 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20713 fixup_symbol_section (sym
, objfile
);
20714 SET_SYMBOL_VALUE_ADDRESS
20716 SYMBOL_VALUE_ADDRESS (sym
)
20717 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20721 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20722 expression evaluator, and use LOC_COMPUTED only when necessary
20723 (i.e. when the value of a register or memory location is
20724 referenced, or a thread-local block, etc.). Then again, it might
20725 not be worthwhile. I'm assuming that it isn't unless performance
20726 or memory numbers show me otherwise. */
20728 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20730 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20731 cu
->has_loclist
= true;
20734 /* Given a pointer to a DWARF information entry, figure out if we need
20735 to make a symbol table entry for it, and if so, create a new entry
20736 and return a pointer to it.
20737 If TYPE is NULL, determine symbol type from the die, otherwise
20738 used the passed type.
20739 If SPACE is not NULL, use it to hold the new symbol. If it is
20740 NULL, allocate a new symbol on the objfile's obstack. */
20742 static struct symbol
*
20743 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20744 struct symbol
*space
)
20746 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20747 struct objfile
*objfile
= per_objfile
->objfile
;
20748 struct gdbarch
*gdbarch
= objfile
->arch ();
20749 struct symbol
*sym
= NULL
;
20751 struct attribute
*attr
= NULL
;
20752 struct attribute
*attr2
= NULL
;
20753 CORE_ADDR baseaddr
;
20754 struct pending
**list_to_add
= NULL
;
20756 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20758 baseaddr
= objfile
->text_section_offset ();
20760 name
= dwarf2_name (die
, cu
);
20763 int suppress_add
= 0;
20768 sym
= new (&objfile
->objfile_obstack
) symbol
;
20769 OBJSTAT (objfile
, n_syms
++);
20771 /* Cache this symbol's name and the name's demangled form (if any). */
20772 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20773 /* Fortran does not have mangling standard and the mangling does differ
20774 between gfortran, iFort etc. */
20775 const char *physname
20776 = (cu
->language
== language_fortran
20777 ? dwarf2_full_name (name
, die
, cu
)
20778 : dwarf2_physname (name
, die
, cu
));
20779 const char *linkagename
= dw2_linkage_name (die
, cu
);
20781 if (linkagename
== nullptr || cu
->language
== language_ada
)
20782 sym
->set_linkage_name (physname
);
20785 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20786 sym
->set_linkage_name (linkagename
);
20789 /* Default assumptions.
20790 Use the passed type or decode it from the die. */
20791 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20792 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20794 SYMBOL_TYPE (sym
) = type
;
20796 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20797 attr
= dwarf2_attr (die
,
20798 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20800 if (attr
!= nullptr)
20802 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20805 attr
= dwarf2_attr (die
,
20806 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20808 if (attr
!= nullptr)
20810 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20811 struct file_entry
*fe
;
20813 if (cu
->line_header
!= NULL
)
20814 fe
= cu
->line_header
->file_name_at (file_index
);
20819 complaint (_("file index out of range"));
20821 symbol_set_symtab (sym
, fe
->symtab
);
20827 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20828 if (attr
!= nullptr)
20832 addr
= attr
->value_as_address ();
20833 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20834 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20836 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20837 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20838 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20839 add_symbol_to_list (sym
, cu
->list_in_scope
);
20841 case DW_TAG_subprogram
:
20842 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20844 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20845 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20846 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20847 || cu
->language
== language_ada
20848 || cu
->language
== language_fortran
)
20850 /* Subprograms marked external are stored as a global symbol.
20851 Ada and Fortran subprograms, whether marked external or
20852 not, are always stored as a global symbol, because we want
20853 to be able to access them globally. For instance, we want
20854 to be able to break on a nested subprogram without having
20855 to specify the context. */
20856 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20860 list_to_add
= cu
->list_in_scope
;
20863 case DW_TAG_inlined_subroutine
:
20864 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20866 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20867 SYMBOL_INLINED (sym
) = 1;
20868 list_to_add
= cu
->list_in_scope
;
20870 case DW_TAG_template_value_param
:
20872 /* Fall through. */
20873 case DW_TAG_constant
:
20874 case DW_TAG_variable
:
20875 case DW_TAG_member
:
20876 /* Compilation with minimal debug info may result in
20877 variables with missing type entries. Change the
20878 misleading `void' type to something sensible. */
20879 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20880 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20882 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20883 /* In the case of DW_TAG_member, we should only be called for
20884 static const members. */
20885 if (die
->tag
== DW_TAG_member
)
20887 /* dwarf2_add_field uses die_is_declaration,
20888 so we do the same. */
20889 gdb_assert (die_is_declaration (die
, cu
));
20892 if (attr
!= nullptr)
20894 dwarf2_const_value (attr
, sym
, cu
);
20895 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20898 if (attr2
&& (DW_UNSND (attr2
) != 0))
20899 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20901 list_to_add
= cu
->list_in_scope
;
20905 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20906 if (attr
!= nullptr)
20908 var_decode_location (attr
, sym
, cu
);
20909 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20911 /* Fortran explicitly imports any global symbols to the local
20912 scope by DW_TAG_common_block. */
20913 if (cu
->language
== language_fortran
&& die
->parent
20914 && die
->parent
->tag
== DW_TAG_common_block
)
20917 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20918 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20919 && !per_objfile
->per_bfd
->has_section_at_zero
)
20921 /* When a static variable is eliminated by the linker,
20922 the corresponding debug information is not stripped
20923 out, but the variable address is set to null;
20924 do not add such variables into symbol table. */
20926 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20928 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20929 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20930 && per_objfile
->per_bfd
->can_copy
)
20932 /* A global static variable might be subject to
20933 copy relocation. We first check for a local
20934 minsym, though, because maybe the symbol was
20935 marked hidden, in which case this would not
20937 bound_minimal_symbol found
20938 = (lookup_minimal_symbol_linkage
20939 (sym
->linkage_name (), objfile
));
20940 if (found
.minsym
!= nullptr)
20941 sym
->maybe_copied
= 1;
20944 /* A variable with DW_AT_external is never static,
20945 but it may be block-scoped. */
20947 = ((cu
->list_in_scope
20948 == cu
->get_builder ()->get_file_symbols ())
20949 ? cu
->get_builder ()->get_global_symbols ()
20950 : cu
->list_in_scope
);
20953 list_to_add
= cu
->list_in_scope
;
20957 /* We do not know the address of this symbol.
20958 If it is an external symbol and we have type information
20959 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20960 The address of the variable will then be determined from
20961 the minimal symbol table whenever the variable is
20963 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20965 /* Fortran explicitly imports any global symbols to the local
20966 scope by DW_TAG_common_block. */
20967 if (cu
->language
== language_fortran
&& die
->parent
20968 && die
->parent
->tag
== DW_TAG_common_block
)
20970 /* SYMBOL_CLASS doesn't matter here because
20971 read_common_block is going to reset it. */
20973 list_to_add
= cu
->list_in_scope
;
20975 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20976 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20978 /* A variable with DW_AT_external is never static, but it
20979 may be block-scoped. */
20981 = ((cu
->list_in_scope
20982 == cu
->get_builder ()->get_file_symbols ())
20983 ? cu
->get_builder ()->get_global_symbols ()
20984 : cu
->list_in_scope
);
20986 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20988 else if (!die_is_declaration (die
, cu
))
20990 /* Use the default LOC_OPTIMIZED_OUT class. */
20991 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20993 list_to_add
= cu
->list_in_scope
;
20997 case DW_TAG_formal_parameter
:
20999 /* If we are inside a function, mark this as an argument. If
21000 not, we might be looking at an argument to an inlined function
21001 when we do not have enough information to show inlined frames;
21002 pretend it's a local variable in that case so that the user can
21004 struct context_stack
*curr
21005 = cu
->get_builder ()->get_current_context_stack ();
21006 if (curr
!= nullptr && curr
->name
!= nullptr)
21007 SYMBOL_IS_ARGUMENT (sym
) = 1;
21008 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21009 if (attr
!= nullptr)
21011 var_decode_location (attr
, sym
, cu
);
21013 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21014 if (attr
!= nullptr)
21016 dwarf2_const_value (attr
, sym
, cu
);
21019 list_to_add
= cu
->list_in_scope
;
21022 case DW_TAG_unspecified_parameters
:
21023 /* From varargs functions; gdb doesn't seem to have any
21024 interest in this information, so just ignore it for now.
21027 case DW_TAG_template_type_param
:
21029 /* Fall through. */
21030 case DW_TAG_class_type
:
21031 case DW_TAG_interface_type
:
21032 case DW_TAG_structure_type
:
21033 case DW_TAG_union_type
:
21034 case DW_TAG_set_type
:
21035 case DW_TAG_enumeration_type
:
21036 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21037 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21040 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21041 really ever be static objects: otherwise, if you try
21042 to, say, break of a class's method and you're in a file
21043 which doesn't mention that class, it won't work unless
21044 the check for all static symbols in lookup_symbol_aux
21045 saves you. See the OtherFileClass tests in
21046 gdb.c++/namespace.exp. */
21050 buildsym_compunit
*builder
= cu
->get_builder ();
21052 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21053 && cu
->language
== language_cplus
21054 ? builder
->get_global_symbols ()
21055 : cu
->list_in_scope
);
21057 /* The semantics of C++ state that "struct foo {
21058 ... }" also defines a typedef for "foo". */
21059 if (cu
->language
== language_cplus
21060 || cu
->language
== language_ada
21061 || cu
->language
== language_d
21062 || cu
->language
== language_rust
)
21064 /* The symbol's name is already allocated along
21065 with this objfile, so we don't need to
21066 duplicate it for the type. */
21067 if (SYMBOL_TYPE (sym
)->name () == 0)
21068 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21073 case DW_TAG_typedef
:
21074 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21075 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21076 list_to_add
= cu
->list_in_scope
;
21078 case DW_TAG_base_type
:
21079 case DW_TAG_subrange_type
:
21080 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21081 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21082 list_to_add
= cu
->list_in_scope
;
21084 case DW_TAG_enumerator
:
21085 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21086 if (attr
!= nullptr)
21088 dwarf2_const_value (attr
, sym
, cu
);
21091 /* NOTE: carlton/2003-11-10: See comment above in the
21092 DW_TAG_class_type, etc. block. */
21095 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21096 && cu
->language
== language_cplus
21097 ? cu
->get_builder ()->get_global_symbols ()
21098 : cu
->list_in_scope
);
21101 case DW_TAG_imported_declaration
:
21102 case DW_TAG_namespace
:
21103 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21104 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21106 case DW_TAG_module
:
21107 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21108 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21109 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21111 case DW_TAG_common_block
:
21112 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21113 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21114 add_symbol_to_list (sym
, cu
->list_in_scope
);
21117 /* Not a tag we recognize. Hopefully we aren't processing
21118 trash data, but since we must specifically ignore things
21119 we don't recognize, there is nothing else we should do at
21121 complaint (_("unsupported tag: '%s'"),
21122 dwarf_tag_name (die
->tag
));
21128 sym
->hash_next
= objfile
->template_symbols
;
21129 objfile
->template_symbols
= sym
;
21130 list_to_add
= NULL
;
21133 if (list_to_add
!= NULL
)
21134 add_symbol_to_list (sym
, list_to_add
);
21136 /* For the benefit of old versions of GCC, check for anonymous
21137 namespaces based on the demangled name. */
21138 if (!cu
->processing_has_namespace_info
21139 && cu
->language
== language_cplus
)
21140 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21145 /* Given an attr with a DW_FORM_dataN value in host byte order,
21146 zero-extend it as appropriate for the symbol's type. The DWARF
21147 standard (v4) is not entirely clear about the meaning of using
21148 DW_FORM_dataN for a constant with a signed type, where the type is
21149 wider than the data. The conclusion of a discussion on the DWARF
21150 list was that this is unspecified. We choose to always zero-extend
21151 because that is the interpretation long in use by GCC. */
21154 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21155 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21157 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21158 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21159 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21160 LONGEST l
= DW_UNSND (attr
);
21162 if (bits
< sizeof (*value
) * 8)
21164 l
&= ((LONGEST
) 1 << bits
) - 1;
21167 else if (bits
== sizeof (*value
) * 8)
21171 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21172 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21179 /* Read a constant value from an attribute. Either set *VALUE, or if
21180 the value does not fit in *VALUE, set *BYTES - either already
21181 allocated on the objfile obstack, or newly allocated on OBSTACK,
21182 or, set *BATON, if we translated the constant to a location
21186 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21187 const char *name
, struct obstack
*obstack
,
21188 struct dwarf2_cu
*cu
,
21189 LONGEST
*value
, const gdb_byte
**bytes
,
21190 struct dwarf2_locexpr_baton
**baton
)
21192 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21193 struct objfile
*objfile
= per_objfile
->objfile
;
21194 struct comp_unit_head
*cu_header
= &cu
->header
;
21195 struct dwarf_block
*blk
;
21196 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21197 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21203 switch (attr
->form
)
21206 case DW_FORM_addrx
:
21207 case DW_FORM_GNU_addr_index
:
21211 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21212 dwarf2_const_value_length_mismatch_complaint (name
,
21213 cu_header
->addr_size
,
21214 TYPE_LENGTH (type
));
21215 /* Symbols of this form are reasonably rare, so we just
21216 piggyback on the existing location code rather than writing
21217 a new implementation of symbol_computed_ops. */
21218 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21219 (*baton
)->per_objfile
= per_objfile
;
21220 (*baton
)->per_cu
= cu
->per_cu
;
21221 gdb_assert ((*baton
)->per_cu
);
21223 (*baton
)->size
= 2 + cu_header
->addr_size
;
21224 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21225 (*baton
)->data
= data
;
21227 data
[0] = DW_OP_addr
;
21228 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21229 byte_order
, DW_ADDR (attr
));
21230 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21233 case DW_FORM_string
:
21236 case DW_FORM_GNU_str_index
:
21237 case DW_FORM_GNU_strp_alt
:
21238 /* DW_STRING is already allocated on the objfile obstack, point
21240 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21242 case DW_FORM_block1
:
21243 case DW_FORM_block2
:
21244 case DW_FORM_block4
:
21245 case DW_FORM_block
:
21246 case DW_FORM_exprloc
:
21247 case DW_FORM_data16
:
21248 blk
= DW_BLOCK (attr
);
21249 if (TYPE_LENGTH (type
) != blk
->size
)
21250 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21251 TYPE_LENGTH (type
));
21252 *bytes
= blk
->data
;
21255 /* The DW_AT_const_value attributes are supposed to carry the
21256 symbol's value "represented as it would be on the target
21257 architecture." By the time we get here, it's already been
21258 converted to host endianness, so we just need to sign- or
21259 zero-extend it as appropriate. */
21260 case DW_FORM_data1
:
21261 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21263 case DW_FORM_data2
:
21264 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21266 case DW_FORM_data4
:
21267 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21269 case DW_FORM_data8
:
21270 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21273 case DW_FORM_sdata
:
21274 case DW_FORM_implicit_const
:
21275 *value
= DW_SND (attr
);
21278 case DW_FORM_udata
:
21279 *value
= DW_UNSND (attr
);
21283 complaint (_("unsupported const value attribute form: '%s'"),
21284 dwarf_form_name (attr
->form
));
21291 /* Copy constant value from an attribute to a symbol. */
21294 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21295 struct dwarf2_cu
*cu
)
21297 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21299 const gdb_byte
*bytes
;
21300 struct dwarf2_locexpr_baton
*baton
;
21302 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21303 sym
->print_name (),
21304 &objfile
->objfile_obstack
, cu
,
21305 &value
, &bytes
, &baton
);
21309 SYMBOL_LOCATION_BATON (sym
) = baton
;
21310 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21312 else if (bytes
!= NULL
)
21314 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21315 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21319 SYMBOL_VALUE (sym
) = value
;
21320 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21324 /* Return the type of the die in question using its DW_AT_type attribute. */
21326 static struct type
*
21327 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21329 struct attribute
*type_attr
;
21331 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21334 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21335 /* A missing DW_AT_type represents a void type. */
21336 return objfile_type (objfile
)->builtin_void
;
21339 return lookup_die_type (die
, type_attr
, cu
);
21342 /* True iff CU's producer generates GNAT Ada auxiliary information
21343 that allows to find parallel types through that information instead
21344 of having to do expensive parallel lookups by type name. */
21347 need_gnat_info (struct dwarf2_cu
*cu
)
21349 /* Assume that the Ada compiler was GNAT, which always produces
21350 the auxiliary information. */
21351 return (cu
->language
== language_ada
);
21354 /* Return the auxiliary type of the die in question using its
21355 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21356 attribute is not present. */
21358 static struct type
*
21359 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21361 struct attribute
*type_attr
;
21363 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21367 return lookup_die_type (die
, type_attr
, cu
);
21370 /* If DIE has a descriptive_type attribute, then set the TYPE's
21371 descriptive type accordingly. */
21374 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21375 struct dwarf2_cu
*cu
)
21377 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21379 if (descriptive_type
)
21381 ALLOCATE_GNAT_AUX_TYPE (type
);
21382 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21386 /* Return the containing type of the die in question using its
21387 DW_AT_containing_type attribute. */
21389 static struct type
*
21390 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21392 struct attribute
*type_attr
;
21393 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21395 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21397 error (_("Dwarf Error: Problem turning containing type into gdb type "
21398 "[in module %s]"), objfile_name (objfile
));
21400 return lookup_die_type (die
, type_attr
, cu
);
21403 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21405 static struct type
*
21406 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21408 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21409 struct objfile
*objfile
= per_objfile
->objfile
;
21412 std::string message
21413 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21414 objfile_name (objfile
),
21415 sect_offset_str (cu
->header
.sect_off
),
21416 sect_offset_str (die
->sect_off
));
21417 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21419 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21422 /* Look up the type of DIE in CU using its type attribute ATTR.
21423 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21424 DW_AT_containing_type.
21425 If there is no type substitute an error marker. */
21427 static struct type
*
21428 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21429 struct dwarf2_cu
*cu
)
21431 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21432 struct objfile
*objfile
= per_objfile
->objfile
;
21433 struct type
*this_type
;
21435 gdb_assert (attr
->name
== DW_AT_type
21436 || attr
->name
== DW_AT_GNAT_descriptive_type
21437 || attr
->name
== DW_AT_containing_type
);
21439 /* First see if we have it cached. */
21441 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21443 struct dwarf2_per_cu_data
*per_cu
;
21444 sect_offset sect_off
= attr
->get_ref_die_offset ();
21446 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
21447 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
21449 else if (attr
->form_is_ref ())
21451 sect_offset sect_off
= attr
->get_ref_die_offset ();
21453 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
21455 else if (attr
->form
== DW_FORM_ref_sig8
)
21457 ULONGEST signature
= DW_SIGNATURE (attr
);
21459 return get_signatured_type (die
, signature
, cu
);
21463 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21464 " at %s [in module %s]"),
21465 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21466 objfile_name (objfile
));
21467 return build_error_marker_type (cu
, die
);
21470 /* If not cached we need to read it in. */
21472 if (this_type
== NULL
)
21474 struct die_info
*type_die
= NULL
;
21475 struct dwarf2_cu
*type_cu
= cu
;
21477 if (attr
->form_is_ref ())
21478 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21479 if (type_die
== NULL
)
21480 return build_error_marker_type (cu
, die
);
21481 /* If we find the type now, it's probably because the type came
21482 from an inter-CU reference and the type's CU got expanded before
21484 this_type
= read_type_die (type_die
, type_cu
);
21487 /* If we still don't have a type use an error marker. */
21489 if (this_type
== NULL
)
21490 return build_error_marker_type (cu
, die
);
21495 /* Return the type in DIE, CU.
21496 Returns NULL for invalid types.
21498 This first does a lookup in die_type_hash,
21499 and only reads the die in if necessary.
21501 NOTE: This can be called when reading in partial or full symbols. */
21503 static struct type
*
21504 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21506 struct type
*this_type
;
21508 this_type
= get_die_type (die
, cu
);
21512 return read_type_die_1 (die
, cu
);
21515 /* Read the type in DIE, CU.
21516 Returns NULL for invalid types. */
21518 static struct type
*
21519 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21521 struct type
*this_type
= NULL
;
21525 case DW_TAG_class_type
:
21526 case DW_TAG_interface_type
:
21527 case DW_TAG_structure_type
:
21528 case DW_TAG_union_type
:
21529 this_type
= read_structure_type (die
, cu
);
21531 case DW_TAG_enumeration_type
:
21532 this_type
= read_enumeration_type (die
, cu
);
21534 case DW_TAG_subprogram
:
21535 case DW_TAG_subroutine_type
:
21536 case DW_TAG_inlined_subroutine
:
21537 this_type
= read_subroutine_type (die
, cu
);
21539 case DW_TAG_array_type
:
21540 this_type
= read_array_type (die
, cu
);
21542 case DW_TAG_set_type
:
21543 this_type
= read_set_type (die
, cu
);
21545 case DW_TAG_pointer_type
:
21546 this_type
= read_tag_pointer_type (die
, cu
);
21548 case DW_TAG_ptr_to_member_type
:
21549 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21551 case DW_TAG_reference_type
:
21552 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21554 case DW_TAG_rvalue_reference_type
:
21555 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21557 case DW_TAG_const_type
:
21558 this_type
= read_tag_const_type (die
, cu
);
21560 case DW_TAG_volatile_type
:
21561 this_type
= read_tag_volatile_type (die
, cu
);
21563 case DW_TAG_restrict_type
:
21564 this_type
= read_tag_restrict_type (die
, cu
);
21566 case DW_TAG_string_type
:
21567 this_type
= read_tag_string_type (die
, cu
);
21569 case DW_TAG_typedef
:
21570 this_type
= read_typedef (die
, cu
);
21572 case DW_TAG_subrange_type
:
21573 this_type
= read_subrange_type (die
, cu
);
21575 case DW_TAG_base_type
:
21576 this_type
= read_base_type (die
, cu
);
21578 case DW_TAG_unspecified_type
:
21579 this_type
= read_unspecified_type (die
, cu
);
21581 case DW_TAG_namespace
:
21582 this_type
= read_namespace_type (die
, cu
);
21584 case DW_TAG_module
:
21585 this_type
= read_module_type (die
, cu
);
21587 case DW_TAG_atomic_type
:
21588 this_type
= read_tag_atomic_type (die
, cu
);
21591 complaint (_("unexpected tag in read_type_die: '%s'"),
21592 dwarf_tag_name (die
->tag
));
21599 /* See if we can figure out if the class lives in a namespace. We do
21600 this by looking for a member function; its demangled name will
21601 contain namespace info, if there is any.
21602 Return the computed name or NULL.
21603 Space for the result is allocated on the objfile's obstack.
21604 This is the full-die version of guess_partial_die_structure_name.
21605 In this case we know DIE has no useful parent. */
21607 static const char *
21608 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21610 struct die_info
*spec_die
;
21611 struct dwarf2_cu
*spec_cu
;
21612 struct die_info
*child
;
21613 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21616 spec_die
= die_specification (die
, &spec_cu
);
21617 if (spec_die
!= NULL
)
21623 for (child
= die
->child
;
21625 child
= child
->sibling
)
21627 if (child
->tag
== DW_TAG_subprogram
)
21629 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21631 if (linkage_name
!= NULL
)
21633 gdb::unique_xmalloc_ptr
<char> actual_name
21634 (language_class_name_from_physname (cu
->language_defn
,
21636 const char *name
= NULL
;
21638 if (actual_name
!= NULL
)
21640 const char *die_name
= dwarf2_name (die
, cu
);
21642 if (die_name
!= NULL
21643 && strcmp (die_name
, actual_name
.get ()) != 0)
21645 /* Strip off the class name from the full name.
21646 We want the prefix. */
21647 int die_name_len
= strlen (die_name
);
21648 int actual_name_len
= strlen (actual_name
.get ());
21649 const char *ptr
= actual_name
.get ();
21651 /* Test for '::' as a sanity check. */
21652 if (actual_name_len
> die_name_len
+ 2
21653 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21654 name
= obstack_strndup (
21655 &objfile
->per_bfd
->storage_obstack
,
21656 ptr
, actual_name_len
- die_name_len
- 2);
21667 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21668 prefix part in such case. See
21669 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21671 static const char *
21672 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21674 struct attribute
*attr
;
21677 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21678 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21681 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21684 attr
= dw2_linkage_name_attr (die
, cu
);
21685 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21688 /* dwarf2_name had to be already called. */
21689 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21691 /* Strip the base name, keep any leading namespaces/classes. */
21692 base
= strrchr (DW_STRING (attr
), ':');
21693 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21696 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21697 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21699 &base
[-1] - DW_STRING (attr
));
21702 /* Return the name of the namespace/class that DIE is defined within,
21703 or "" if we can't tell. The caller should not xfree the result.
21705 For example, if we're within the method foo() in the following
21715 then determine_prefix on foo's die will return "N::C". */
21717 static const char *
21718 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21720 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21721 struct die_info
*parent
, *spec_die
;
21722 struct dwarf2_cu
*spec_cu
;
21723 struct type
*parent_type
;
21724 const char *retval
;
21726 if (cu
->language
!= language_cplus
21727 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21728 && cu
->language
!= language_rust
)
21731 retval
= anonymous_struct_prefix (die
, cu
);
21735 /* We have to be careful in the presence of DW_AT_specification.
21736 For example, with GCC 3.4, given the code
21740 // Definition of N::foo.
21744 then we'll have a tree of DIEs like this:
21746 1: DW_TAG_compile_unit
21747 2: DW_TAG_namespace // N
21748 3: DW_TAG_subprogram // declaration of N::foo
21749 4: DW_TAG_subprogram // definition of N::foo
21750 DW_AT_specification // refers to die #3
21752 Thus, when processing die #4, we have to pretend that we're in
21753 the context of its DW_AT_specification, namely the contex of die
21756 spec_die
= die_specification (die
, &spec_cu
);
21757 if (spec_die
== NULL
)
21758 parent
= die
->parent
;
21761 parent
= spec_die
->parent
;
21765 if (parent
== NULL
)
21767 else if (parent
->building_fullname
)
21770 const char *parent_name
;
21772 /* It has been seen on RealView 2.2 built binaries,
21773 DW_TAG_template_type_param types actually _defined_ as
21774 children of the parent class:
21777 template class <class Enum> Class{};
21778 Class<enum E> class_e;
21780 1: DW_TAG_class_type (Class)
21781 2: DW_TAG_enumeration_type (E)
21782 3: DW_TAG_enumerator (enum1:0)
21783 3: DW_TAG_enumerator (enum2:1)
21785 2: DW_TAG_template_type_param
21786 DW_AT_type DW_FORM_ref_udata (E)
21788 Besides being broken debug info, it can put GDB into an
21789 infinite loop. Consider:
21791 When we're building the full name for Class<E>, we'll start
21792 at Class, and go look over its template type parameters,
21793 finding E. We'll then try to build the full name of E, and
21794 reach here. We're now trying to build the full name of E,
21795 and look over the parent DIE for containing scope. In the
21796 broken case, if we followed the parent DIE of E, we'd again
21797 find Class, and once again go look at its template type
21798 arguments, etc., etc. Simply don't consider such parent die
21799 as source-level parent of this die (it can't be, the language
21800 doesn't allow it), and break the loop here. */
21801 name
= dwarf2_name (die
, cu
);
21802 parent_name
= dwarf2_name (parent
, cu
);
21803 complaint (_("template param type '%s' defined within parent '%s'"),
21804 name
? name
: "<unknown>",
21805 parent_name
? parent_name
: "<unknown>");
21809 switch (parent
->tag
)
21811 case DW_TAG_namespace
:
21812 parent_type
= read_type_die (parent
, cu
);
21813 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21814 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21815 Work around this problem here. */
21816 if (cu
->language
== language_cplus
21817 && strcmp (parent_type
->name (), "::") == 0)
21819 /* We give a name to even anonymous namespaces. */
21820 return parent_type
->name ();
21821 case DW_TAG_class_type
:
21822 case DW_TAG_interface_type
:
21823 case DW_TAG_structure_type
:
21824 case DW_TAG_union_type
:
21825 case DW_TAG_module
:
21826 parent_type
= read_type_die (parent
, cu
);
21827 if (parent_type
->name () != NULL
)
21828 return parent_type
->name ();
21830 /* An anonymous structure is only allowed non-static data
21831 members; no typedefs, no member functions, et cetera.
21832 So it does not need a prefix. */
21834 case DW_TAG_compile_unit
:
21835 case DW_TAG_partial_unit
:
21836 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21837 if (cu
->language
== language_cplus
21838 && !per_objfile
->per_bfd
->types
.empty ()
21839 && die
->child
!= NULL
21840 && (die
->tag
== DW_TAG_class_type
21841 || die
->tag
== DW_TAG_structure_type
21842 || die
->tag
== DW_TAG_union_type
))
21844 const char *name
= guess_full_die_structure_name (die
, cu
);
21849 case DW_TAG_subprogram
:
21850 /* Nested subroutines in Fortran get a prefix with the name
21851 of the parent's subroutine. */
21852 if (cu
->language
== language_fortran
)
21854 if ((die
->tag
== DW_TAG_subprogram
)
21855 && (dwarf2_name (parent
, cu
) != NULL
))
21856 return dwarf2_name (parent
, cu
);
21858 return determine_prefix (parent
, cu
);
21859 case DW_TAG_enumeration_type
:
21860 parent_type
= read_type_die (parent
, cu
);
21861 if (TYPE_DECLARED_CLASS (parent_type
))
21863 if (parent_type
->name () != NULL
)
21864 return parent_type
->name ();
21867 /* Fall through. */
21869 return determine_prefix (parent
, cu
);
21873 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21874 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21875 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21876 an obconcat, otherwise allocate storage for the result. The CU argument is
21877 used to determine the language and hence, the appropriate separator. */
21879 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21882 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21883 int physname
, struct dwarf2_cu
*cu
)
21885 const char *lead
= "";
21888 if (suffix
== NULL
|| suffix
[0] == '\0'
21889 || prefix
== NULL
|| prefix
[0] == '\0')
21891 else if (cu
->language
== language_d
)
21893 /* For D, the 'main' function could be defined in any module, but it
21894 should never be prefixed. */
21895 if (strcmp (suffix
, "D main") == 0)
21903 else if (cu
->language
== language_fortran
&& physname
)
21905 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21906 DW_AT_MIPS_linkage_name is preferred and used instead. */
21914 if (prefix
== NULL
)
21916 if (suffix
== NULL
)
21923 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21925 strcpy (retval
, lead
);
21926 strcat (retval
, prefix
);
21927 strcat (retval
, sep
);
21928 strcat (retval
, suffix
);
21933 /* We have an obstack. */
21934 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21938 /* Get name of a die, return NULL if not found. */
21940 static const char *
21941 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21942 struct objfile
*objfile
)
21944 if (name
&& cu
->language
== language_cplus
)
21946 gdb::unique_xmalloc_ptr
<char> canon_name
21947 = cp_canonicalize_string (name
);
21949 if (canon_name
!= nullptr)
21950 name
= objfile
->intern (canon_name
.get ());
21956 /* Get name of a die, return NULL if not found.
21957 Anonymous namespaces are converted to their magic string. */
21959 static const char *
21960 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21962 struct attribute
*attr
;
21963 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21965 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21966 if ((!attr
|| !DW_STRING (attr
))
21967 && die
->tag
!= DW_TAG_namespace
21968 && die
->tag
!= DW_TAG_class_type
21969 && die
->tag
!= DW_TAG_interface_type
21970 && die
->tag
!= DW_TAG_structure_type
21971 && die
->tag
!= DW_TAG_union_type
)
21976 case DW_TAG_compile_unit
:
21977 case DW_TAG_partial_unit
:
21978 /* Compilation units have a DW_AT_name that is a filename, not
21979 a source language identifier. */
21980 case DW_TAG_enumeration_type
:
21981 case DW_TAG_enumerator
:
21982 /* These tags always have simple identifiers already; no need
21983 to canonicalize them. */
21984 return DW_STRING (attr
);
21986 case DW_TAG_namespace
:
21987 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21988 return DW_STRING (attr
);
21989 return CP_ANONYMOUS_NAMESPACE_STR
;
21991 case DW_TAG_class_type
:
21992 case DW_TAG_interface_type
:
21993 case DW_TAG_structure_type
:
21994 case DW_TAG_union_type
:
21995 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21996 structures or unions. These were of the form "._%d" in GCC 4.1,
21997 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21998 and GCC 4.4. We work around this problem by ignoring these. */
21999 if (attr
&& DW_STRING (attr
)
22000 && (startswith (DW_STRING (attr
), "._")
22001 || startswith (DW_STRING (attr
), "<anonymous")))
22004 /* GCC might emit a nameless typedef that has a linkage name. See
22005 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22006 if (!attr
|| DW_STRING (attr
) == NULL
)
22008 attr
= dw2_linkage_name_attr (die
, cu
);
22009 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22012 /* Avoid demangling DW_STRING (attr) the second time on a second
22013 call for the same DIE. */
22014 if (!DW_STRING_IS_CANONICAL (attr
))
22016 gdb::unique_xmalloc_ptr
<char> demangled
22017 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22018 if (demangled
== nullptr)
22021 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
22022 DW_STRING_IS_CANONICAL (attr
) = 1;
22025 /* Strip any leading namespaces/classes, keep only the base name.
22026 DW_AT_name for named DIEs does not contain the prefixes. */
22027 const char *base
= strrchr (DW_STRING (attr
), ':');
22028 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22031 return DW_STRING (attr
);
22039 if (!DW_STRING_IS_CANONICAL (attr
))
22041 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22043 DW_STRING_IS_CANONICAL (attr
) = 1;
22045 return DW_STRING (attr
);
22048 /* Return the die that this die in an extension of, or NULL if there
22049 is none. *EXT_CU is the CU containing DIE on input, and the CU
22050 containing the return value on output. */
22052 static struct die_info
*
22053 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22055 struct attribute
*attr
;
22057 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22061 return follow_die_ref (die
, attr
, ext_cu
);
22065 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22069 print_spaces (indent
, f
);
22070 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22071 dwarf_tag_name (die
->tag
), die
->abbrev
,
22072 sect_offset_str (die
->sect_off
));
22074 if (die
->parent
!= NULL
)
22076 print_spaces (indent
, f
);
22077 fprintf_unfiltered (f
, " parent at offset: %s\n",
22078 sect_offset_str (die
->parent
->sect_off
));
22081 print_spaces (indent
, f
);
22082 fprintf_unfiltered (f
, " has children: %s\n",
22083 dwarf_bool_name (die
->child
!= NULL
));
22085 print_spaces (indent
, f
);
22086 fprintf_unfiltered (f
, " attributes:\n");
22088 for (i
= 0; i
< die
->num_attrs
; ++i
)
22090 print_spaces (indent
, f
);
22091 fprintf_unfiltered (f
, " %s (%s) ",
22092 dwarf_attr_name (die
->attrs
[i
].name
),
22093 dwarf_form_name (die
->attrs
[i
].form
));
22095 switch (die
->attrs
[i
].form
)
22098 case DW_FORM_addrx
:
22099 case DW_FORM_GNU_addr_index
:
22100 fprintf_unfiltered (f
, "address: ");
22101 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22103 case DW_FORM_block2
:
22104 case DW_FORM_block4
:
22105 case DW_FORM_block
:
22106 case DW_FORM_block1
:
22107 fprintf_unfiltered (f
, "block: size %s",
22108 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22110 case DW_FORM_exprloc
:
22111 fprintf_unfiltered (f
, "expression: size %s",
22112 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22114 case DW_FORM_data16
:
22115 fprintf_unfiltered (f
, "constant of 16 bytes");
22117 case DW_FORM_ref_addr
:
22118 fprintf_unfiltered (f
, "ref address: ");
22119 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22121 case DW_FORM_GNU_ref_alt
:
22122 fprintf_unfiltered (f
, "alt ref address: ");
22123 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22129 case DW_FORM_ref_udata
:
22130 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22131 (long) (DW_UNSND (&die
->attrs
[i
])));
22133 case DW_FORM_data1
:
22134 case DW_FORM_data2
:
22135 case DW_FORM_data4
:
22136 case DW_FORM_data8
:
22137 case DW_FORM_udata
:
22138 case DW_FORM_sdata
:
22139 fprintf_unfiltered (f
, "constant: %s",
22140 pulongest (DW_UNSND (&die
->attrs
[i
])));
22142 case DW_FORM_sec_offset
:
22143 fprintf_unfiltered (f
, "section offset: %s",
22144 pulongest (DW_UNSND (&die
->attrs
[i
])));
22146 case DW_FORM_ref_sig8
:
22147 fprintf_unfiltered (f
, "signature: %s",
22148 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22150 case DW_FORM_string
:
22152 case DW_FORM_line_strp
:
22154 case DW_FORM_GNU_str_index
:
22155 case DW_FORM_GNU_strp_alt
:
22156 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22157 DW_STRING (&die
->attrs
[i
])
22158 ? DW_STRING (&die
->attrs
[i
]) : "",
22159 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22162 if (DW_UNSND (&die
->attrs
[i
]))
22163 fprintf_unfiltered (f
, "flag: TRUE");
22165 fprintf_unfiltered (f
, "flag: FALSE");
22167 case DW_FORM_flag_present
:
22168 fprintf_unfiltered (f
, "flag: TRUE");
22170 case DW_FORM_indirect
:
22171 /* The reader will have reduced the indirect form to
22172 the "base form" so this form should not occur. */
22173 fprintf_unfiltered (f
,
22174 "unexpected attribute form: DW_FORM_indirect");
22176 case DW_FORM_implicit_const
:
22177 fprintf_unfiltered (f
, "constant: %s",
22178 plongest (DW_SND (&die
->attrs
[i
])));
22181 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22182 die
->attrs
[i
].form
);
22185 fprintf_unfiltered (f
, "\n");
22190 dump_die_for_error (struct die_info
*die
)
22192 dump_die_shallow (gdb_stderr
, 0, die
);
22196 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22198 int indent
= level
* 4;
22200 gdb_assert (die
!= NULL
);
22202 if (level
>= max_level
)
22205 dump_die_shallow (f
, indent
, die
);
22207 if (die
->child
!= NULL
)
22209 print_spaces (indent
, f
);
22210 fprintf_unfiltered (f
, " Children:");
22211 if (level
+ 1 < max_level
)
22213 fprintf_unfiltered (f
, "\n");
22214 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22218 fprintf_unfiltered (f
,
22219 " [not printed, max nesting level reached]\n");
22223 if (die
->sibling
!= NULL
&& level
> 0)
22225 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22229 /* This is called from the pdie macro in gdbinit.in.
22230 It's not static so gcc will keep a copy callable from gdb. */
22233 dump_die (struct die_info
*die
, int max_level
)
22235 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22239 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22243 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22244 to_underlying (die
->sect_off
),
22250 /* Follow reference or signature attribute ATTR of SRC_DIE.
22251 On entry *REF_CU is the CU of SRC_DIE.
22252 On exit *REF_CU is the CU of the result. */
22254 static struct die_info
*
22255 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22256 struct dwarf2_cu
**ref_cu
)
22258 struct die_info
*die
;
22260 if (attr
->form_is_ref ())
22261 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22262 else if (attr
->form
== DW_FORM_ref_sig8
)
22263 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22266 dump_die_for_error (src_die
);
22267 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22268 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22274 /* Follow reference OFFSET.
22275 On entry *REF_CU is the CU of the source die referencing OFFSET.
22276 On exit *REF_CU is the CU of the result.
22277 Returns NULL if OFFSET is invalid. */
22279 static struct die_info
*
22280 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22281 struct dwarf2_cu
**ref_cu
)
22283 struct die_info temp_die
;
22284 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22285 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22287 gdb_assert (cu
->per_cu
!= NULL
);
22291 if (cu
->per_cu
->is_debug_types
)
22293 /* .debug_types CUs cannot reference anything outside their CU.
22294 If they need to, they have to reference a signatured type via
22295 DW_FORM_ref_sig8. */
22296 if (!cu
->header
.offset_in_cu_p (sect_off
))
22299 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22300 || !cu
->header
.offset_in_cu_p (sect_off
))
22302 struct dwarf2_per_cu_data
*per_cu
;
22304 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22307 /* If necessary, add it to the queue and load its DIEs. */
22308 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
22309 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
22311 target_cu
= per_objfile
->get_cu (per_cu
);
22313 else if (cu
->dies
== NULL
)
22315 /* We're loading full DIEs during partial symbol reading. */
22316 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
22317 load_full_comp_unit (cu
->per_cu
, per_objfile
, false, language_minimal
);
22320 *ref_cu
= target_cu
;
22321 temp_die
.sect_off
= sect_off
;
22323 if (target_cu
!= cu
)
22324 target_cu
->ancestor
= cu
;
22326 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22328 to_underlying (sect_off
));
22331 /* Follow reference attribute ATTR of SRC_DIE.
22332 On entry *REF_CU is the CU of SRC_DIE.
22333 On exit *REF_CU is the CU of the result. */
22335 static struct die_info
*
22336 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22337 struct dwarf2_cu
**ref_cu
)
22339 sect_offset sect_off
= attr
->get_ref_die_offset ();
22340 struct dwarf2_cu
*cu
= *ref_cu
;
22341 struct die_info
*die
;
22343 die
= follow_die_offset (sect_off
,
22344 (attr
->form
== DW_FORM_GNU_ref_alt
22345 || cu
->per_cu
->is_dwz
),
22348 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22349 "at %s [in module %s]"),
22350 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22351 objfile_name (cu
->per_objfile
->objfile
));
22358 struct dwarf2_locexpr_baton
22359 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22360 dwarf2_per_cu_data
*per_cu
,
22361 dwarf2_per_objfile
*per_objfile
,
22362 CORE_ADDR (*get_frame_pc
) (void *baton
),
22363 void *baton
, bool resolve_abstract_p
)
22365 struct die_info
*die
;
22366 struct attribute
*attr
;
22367 struct dwarf2_locexpr_baton retval
;
22368 struct objfile
*objfile
= per_objfile
->objfile
;
22370 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22372 cu
= load_cu (per_cu
, per_objfile
, false);
22376 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22377 Instead just throw an error, not much else we can do. */
22378 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22379 sect_offset_str (sect_off
), objfile_name (objfile
));
22382 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22384 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22385 sect_offset_str (sect_off
), objfile_name (objfile
));
22387 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22388 if (!attr
&& resolve_abstract_p
22389 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22390 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22392 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22393 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22394 struct gdbarch
*gdbarch
= objfile
->arch ();
22396 for (const auto &cand_off
22397 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22399 struct dwarf2_cu
*cand_cu
= cu
;
22400 struct die_info
*cand
22401 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22404 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22407 CORE_ADDR pc_low
, pc_high
;
22408 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22409 if (pc_low
== ((CORE_ADDR
) -1))
22411 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22412 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22413 if (!(pc_low
<= pc
&& pc
< pc_high
))
22417 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22424 /* DWARF: "If there is no such attribute, then there is no effect.".
22425 DATA is ignored if SIZE is 0. */
22427 retval
.data
= NULL
;
22430 else if (attr
->form_is_section_offset ())
22432 struct dwarf2_loclist_baton loclist_baton
;
22433 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22436 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22438 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22440 retval
.size
= size
;
22444 if (!attr
->form_is_block ())
22445 error (_("Dwarf Error: DIE at %s referenced in module %s "
22446 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22447 sect_offset_str (sect_off
), objfile_name (objfile
));
22449 retval
.data
= DW_BLOCK (attr
)->data
;
22450 retval
.size
= DW_BLOCK (attr
)->size
;
22452 retval
.per_objfile
= per_objfile
;
22453 retval
.per_cu
= cu
->per_cu
;
22455 per_objfile
->age_comp_units ();
22462 struct dwarf2_locexpr_baton
22463 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22464 dwarf2_per_cu_data
*per_cu
,
22465 dwarf2_per_objfile
*per_objfile
,
22466 CORE_ADDR (*get_frame_pc
) (void *baton
),
22469 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22471 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22472 get_frame_pc
, baton
);
22475 /* Write a constant of a given type as target-ordered bytes into
22478 static const gdb_byte
*
22479 write_constant_as_bytes (struct obstack
*obstack
,
22480 enum bfd_endian byte_order
,
22487 *len
= TYPE_LENGTH (type
);
22488 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22489 store_unsigned_integer (result
, *len
, byte_order
, value
);
22497 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22498 dwarf2_per_cu_data
*per_cu
,
22499 dwarf2_per_objfile
*per_objfile
,
22503 struct die_info
*die
;
22504 struct attribute
*attr
;
22505 const gdb_byte
*result
= NULL
;
22508 enum bfd_endian byte_order
;
22509 struct objfile
*objfile
= per_objfile
->objfile
;
22511 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22513 cu
= load_cu (per_cu
, per_objfile
, false);
22517 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22518 Instead just throw an error, not much else we can do. */
22519 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22520 sect_offset_str (sect_off
), objfile_name (objfile
));
22523 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22525 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22526 sect_offset_str (sect_off
), objfile_name (objfile
));
22528 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22532 byte_order
= (bfd_big_endian (objfile
->obfd
)
22533 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22535 switch (attr
->form
)
22538 case DW_FORM_addrx
:
22539 case DW_FORM_GNU_addr_index
:
22543 *len
= cu
->header
.addr_size
;
22544 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22545 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22549 case DW_FORM_string
:
22552 case DW_FORM_GNU_str_index
:
22553 case DW_FORM_GNU_strp_alt
:
22554 /* DW_STRING is already allocated on the objfile obstack, point
22556 result
= (const gdb_byte
*) DW_STRING (attr
);
22557 *len
= strlen (DW_STRING (attr
));
22559 case DW_FORM_block1
:
22560 case DW_FORM_block2
:
22561 case DW_FORM_block4
:
22562 case DW_FORM_block
:
22563 case DW_FORM_exprloc
:
22564 case DW_FORM_data16
:
22565 result
= DW_BLOCK (attr
)->data
;
22566 *len
= DW_BLOCK (attr
)->size
;
22569 /* The DW_AT_const_value attributes are supposed to carry the
22570 symbol's value "represented as it would be on the target
22571 architecture." By the time we get here, it's already been
22572 converted to host endianness, so we just need to sign- or
22573 zero-extend it as appropriate. */
22574 case DW_FORM_data1
:
22575 type
= die_type (die
, cu
);
22576 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22577 if (result
== NULL
)
22578 result
= write_constant_as_bytes (obstack
, byte_order
,
22581 case DW_FORM_data2
:
22582 type
= die_type (die
, cu
);
22583 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22584 if (result
== NULL
)
22585 result
= write_constant_as_bytes (obstack
, byte_order
,
22588 case DW_FORM_data4
:
22589 type
= die_type (die
, cu
);
22590 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22591 if (result
== NULL
)
22592 result
= write_constant_as_bytes (obstack
, byte_order
,
22595 case DW_FORM_data8
:
22596 type
= die_type (die
, cu
);
22597 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22598 if (result
== NULL
)
22599 result
= write_constant_as_bytes (obstack
, byte_order
,
22603 case DW_FORM_sdata
:
22604 case DW_FORM_implicit_const
:
22605 type
= die_type (die
, cu
);
22606 result
= write_constant_as_bytes (obstack
, byte_order
,
22607 type
, DW_SND (attr
), len
);
22610 case DW_FORM_udata
:
22611 type
= die_type (die
, cu
);
22612 result
= write_constant_as_bytes (obstack
, byte_order
,
22613 type
, DW_UNSND (attr
), len
);
22617 complaint (_("unsupported const value attribute form: '%s'"),
22618 dwarf_form_name (attr
->form
));
22628 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22629 dwarf2_per_cu_data
*per_cu
,
22630 dwarf2_per_objfile
*per_objfile
)
22632 struct die_info
*die
;
22634 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22636 cu
= load_cu (per_cu
, per_objfile
, false);
22641 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22645 return die_type (die
, cu
);
22651 dwarf2_get_die_type (cu_offset die_offset
,
22652 dwarf2_per_cu_data
*per_cu
,
22653 dwarf2_per_objfile
*per_objfile
)
22655 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22656 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22659 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22660 On entry *REF_CU is the CU of SRC_DIE.
22661 On exit *REF_CU is the CU of the result.
22662 Returns NULL if the referenced DIE isn't found. */
22664 static struct die_info
*
22665 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22666 struct dwarf2_cu
**ref_cu
)
22668 struct die_info temp_die
;
22669 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22670 struct die_info
*die
;
22671 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
22674 /* While it might be nice to assert sig_type->type == NULL here,
22675 we can get here for DW_AT_imported_declaration where we need
22676 the DIE not the type. */
22678 /* If necessary, add it to the queue and load its DIEs. */
22680 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
22682 read_signatured_type (sig_type
, per_objfile
);
22684 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
22685 gdb_assert (sig_cu
!= NULL
);
22686 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22687 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22688 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22689 to_underlying (temp_die
.sect_off
));
22692 /* For .gdb_index version 7 keep track of included TUs.
22693 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22694 if (per_objfile
->per_bfd
->index_table
!= NULL
22695 && per_objfile
->per_bfd
->index_table
->version
<= 7)
22697 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22702 sig_cu
->ancestor
= cu
;
22710 /* Follow signatured type referenced by ATTR in SRC_DIE.
22711 On entry *REF_CU is the CU of SRC_DIE.
22712 On exit *REF_CU is the CU of the result.
22713 The result is the DIE of the type.
22714 If the referenced type cannot be found an error is thrown. */
22716 static struct die_info
*
22717 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22718 struct dwarf2_cu
**ref_cu
)
22720 ULONGEST signature
= DW_SIGNATURE (attr
);
22721 struct signatured_type
*sig_type
;
22722 struct die_info
*die
;
22724 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22726 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22727 /* sig_type will be NULL if the signatured type is missing from
22729 if (sig_type
== NULL
)
22731 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22732 " from DIE at %s [in module %s]"),
22733 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22734 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22737 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22740 dump_die_for_error (src_die
);
22741 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22742 " from DIE at %s [in module %s]"),
22743 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22744 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22750 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22751 reading in and processing the type unit if necessary. */
22753 static struct type
*
22754 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22755 struct dwarf2_cu
*cu
)
22757 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22758 struct signatured_type
*sig_type
;
22759 struct dwarf2_cu
*type_cu
;
22760 struct die_info
*type_die
;
22763 sig_type
= lookup_signatured_type (cu
, signature
);
22764 /* sig_type will be NULL if the signatured type is missing from
22766 if (sig_type
== NULL
)
22768 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22769 " from DIE at %s [in module %s]"),
22770 hex_string (signature
), sect_offset_str (die
->sect_off
),
22771 objfile_name (per_objfile
->objfile
));
22772 return build_error_marker_type (cu
, die
);
22775 /* If we already know the type we're done. */
22776 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
22777 if (type
!= nullptr)
22781 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22782 if (type_die
!= NULL
)
22784 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22785 is created. This is important, for example, because for c++ classes
22786 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22787 type
= read_type_die (type_die
, type_cu
);
22790 complaint (_("Dwarf Error: Cannot build signatured type %s"
22791 " referenced from DIE at %s [in module %s]"),
22792 hex_string (signature
), sect_offset_str (die
->sect_off
),
22793 objfile_name (per_objfile
->objfile
));
22794 type
= build_error_marker_type (cu
, die
);
22799 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22800 " from DIE at %s [in module %s]"),
22801 hex_string (signature
), sect_offset_str (die
->sect_off
),
22802 objfile_name (per_objfile
->objfile
));
22803 type
= build_error_marker_type (cu
, die
);
22806 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
22811 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22812 reading in and processing the type unit if necessary. */
22814 static struct type
*
22815 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22816 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22818 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22819 if (attr
->form_is_ref ())
22821 struct dwarf2_cu
*type_cu
= cu
;
22822 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22824 return read_type_die (type_die
, type_cu
);
22826 else if (attr
->form
== DW_FORM_ref_sig8
)
22828 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22832 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22834 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22835 " at %s [in module %s]"),
22836 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22837 objfile_name (per_objfile
->objfile
));
22838 return build_error_marker_type (cu
, die
);
22842 /* Load the DIEs associated with type unit PER_CU into memory. */
22845 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22846 dwarf2_per_objfile
*per_objfile
)
22848 struct signatured_type
*sig_type
;
22850 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22851 gdb_assert (! per_cu
->type_unit_group_p ());
22853 /* We have the per_cu, but we need the signatured_type.
22854 Fortunately this is an easy translation. */
22855 gdb_assert (per_cu
->is_debug_types
);
22856 sig_type
= (struct signatured_type
*) per_cu
;
22858 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22860 read_signatured_type (sig_type
, per_objfile
);
22862 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
22865 /* Read in a signatured type and build its CU and DIEs.
22866 If the type is a stub for the real type in a DWO file,
22867 read in the real type from the DWO file as well. */
22870 read_signatured_type (signatured_type
*sig_type
,
22871 dwarf2_per_objfile
*per_objfile
)
22873 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22875 gdb_assert (per_cu
->is_debug_types
);
22876 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22878 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
22880 if (!reader
.dummy_p
)
22882 struct dwarf2_cu
*cu
= reader
.cu
;
22883 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22885 gdb_assert (cu
->die_hash
== NULL
);
22887 htab_create_alloc_ex (cu
->header
.length
/ 12,
22891 &cu
->comp_unit_obstack
,
22892 hashtab_obstack_allocate
,
22893 dummy_obstack_deallocate
);
22895 if (reader
.comp_unit_die
->has_children
)
22896 reader
.comp_unit_die
->child
22897 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22898 reader
.comp_unit_die
);
22899 cu
->dies
= reader
.comp_unit_die
;
22900 /* comp_unit_die is not stored in die_hash, no need. */
22902 /* We try not to read any attributes in this function, because
22903 not all CUs needed for references have been loaded yet, and
22904 symbol table processing isn't initialized. But we have to
22905 set the CU language, or we won't be able to build types
22906 correctly. Similarly, if we do not read the producer, we can
22907 not apply producer-specific interpretation. */
22908 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22913 sig_type
->per_cu
.tu_read
= 1;
22916 /* Decode simple location descriptions.
22917 Given a pointer to a dwarf block that defines a location, compute
22918 the location and return the value. If COMPUTED is non-null, it is
22919 set to true to indicate that decoding was successful, and false
22920 otherwise. If COMPUTED is null, then this function may emit a
22924 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22926 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22928 size_t size
= blk
->size
;
22929 const gdb_byte
*data
= blk
->data
;
22930 CORE_ADDR stack
[64];
22932 unsigned int bytes_read
, unsnd
;
22935 if (computed
!= nullptr)
22941 stack
[++stacki
] = 0;
22980 stack
[++stacki
] = op
- DW_OP_lit0
;
23015 stack
[++stacki
] = op
- DW_OP_reg0
;
23018 if (computed
== nullptr)
23019 dwarf2_complex_location_expr_complaint ();
23026 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23028 stack
[++stacki
] = unsnd
;
23031 if (computed
== nullptr)
23032 dwarf2_complex_location_expr_complaint ();
23039 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23044 case DW_OP_const1u
:
23045 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23049 case DW_OP_const1s
:
23050 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23054 case DW_OP_const2u
:
23055 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23059 case DW_OP_const2s
:
23060 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23064 case DW_OP_const4u
:
23065 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23069 case DW_OP_const4s
:
23070 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23074 case DW_OP_const8u
:
23075 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23080 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23086 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23091 stack
[stacki
+ 1] = stack
[stacki
];
23096 stack
[stacki
- 1] += stack
[stacki
];
23100 case DW_OP_plus_uconst
:
23101 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23107 stack
[stacki
- 1] -= stack
[stacki
];
23112 /* If we're not the last op, then we definitely can't encode
23113 this using GDB's address_class enum. This is valid for partial
23114 global symbols, although the variable's address will be bogus
23118 if (computed
== nullptr)
23119 dwarf2_complex_location_expr_complaint ();
23125 case DW_OP_GNU_push_tls_address
:
23126 case DW_OP_form_tls_address
:
23127 /* The top of the stack has the offset from the beginning
23128 of the thread control block at which the variable is located. */
23129 /* Nothing should follow this operator, so the top of stack would
23131 /* This is valid for partial global symbols, but the variable's
23132 address will be bogus in the psymtab. Make it always at least
23133 non-zero to not look as a variable garbage collected by linker
23134 which have DW_OP_addr 0. */
23137 if (computed
== nullptr)
23138 dwarf2_complex_location_expr_complaint ();
23145 case DW_OP_GNU_uninit
:
23146 if (computed
!= nullptr)
23151 case DW_OP_GNU_addr_index
:
23152 case DW_OP_GNU_const_index
:
23153 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23159 if (computed
== nullptr)
23161 const char *name
= get_DW_OP_name (op
);
23164 complaint (_("unsupported stack op: '%s'"),
23167 complaint (_("unsupported stack op: '%02x'"),
23171 return (stack
[stacki
]);
23174 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23175 outside of the allocated space. Also enforce minimum>0. */
23176 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23178 if (computed
== nullptr)
23179 complaint (_("location description stack overflow"));
23185 if (computed
== nullptr)
23186 complaint (_("location description stack underflow"));
23191 if (computed
!= nullptr)
23193 return (stack
[stacki
]);
23196 /* memory allocation interface */
23198 static struct dwarf_block
*
23199 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23201 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23204 static struct die_info
*
23205 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23207 struct die_info
*die
;
23208 size_t size
= sizeof (struct die_info
);
23211 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23213 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23214 memset (die
, 0, sizeof (struct die_info
));
23220 /* Macro support. */
23222 /* An overload of dwarf_decode_macros that finds the correct section
23223 and ensures it is read in before calling the other overload. */
23226 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23227 int section_is_gnu
)
23229 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23230 struct objfile
*objfile
= per_objfile
->objfile
;
23231 const struct line_header
*lh
= cu
->line_header
;
23232 unsigned int offset_size
= cu
->header
.offset_size
;
23233 struct dwarf2_section_info
*section
;
23234 const char *section_name
;
23236 if (cu
->dwo_unit
!= nullptr)
23238 if (section_is_gnu
)
23240 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23241 section_name
= ".debug_macro.dwo";
23245 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23246 section_name
= ".debug_macinfo.dwo";
23251 if (section_is_gnu
)
23253 section
= &per_objfile
->per_bfd
->macro
;
23254 section_name
= ".debug_macro";
23258 section
= &per_objfile
->per_bfd
->macinfo
;
23259 section_name
= ".debug_macinfo";
23263 section
->read (objfile
);
23264 if (section
->buffer
== nullptr)
23266 complaint (_("missing %s section"), section_name
);
23270 buildsym_compunit
*builder
= cu
->get_builder ();
23272 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
23273 offset_size
, offset
, section_is_gnu
);
23276 /* Return the .debug_loc section to use for CU.
23277 For DWO files use .debug_loc.dwo. */
23279 static struct dwarf2_section_info
*
23280 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23282 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23286 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23288 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23290 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
23291 : &per_objfile
->per_bfd
->loc
);
23294 /* A helper function that fills in a dwarf2_loclist_baton. */
23297 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23298 struct dwarf2_loclist_baton
*baton
,
23299 const struct attribute
*attr
)
23301 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23302 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23304 section
->read (per_objfile
->objfile
);
23306 baton
->per_objfile
= per_objfile
;
23307 baton
->per_cu
= cu
->per_cu
;
23308 gdb_assert (baton
->per_cu
);
23309 /* We don't know how long the location list is, but make sure we
23310 don't run off the edge of the section. */
23311 baton
->size
= section
->size
- DW_UNSND (attr
);
23312 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23313 if (cu
->base_address
.has_value ())
23314 baton
->base_address
= *cu
->base_address
;
23316 baton
->base_address
= 0;
23317 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23321 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23322 struct dwarf2_cu
*cu
, int is_block
)
23324 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23325 struct objfile
*objfile
= per_objfile
->objfile
;
23326 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23328 if (attr
->form_is_section_offset ()
23329 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23330 the section. If so, fall through to the complaint in the
23332 && DW_UNSND (attr
) < section
->get_size (objfile
))
23334 struct dwarf2_loclist_baton
*baton
;
23336 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23338 fill_in_loclist_baton (cu
, baton
, attr
);
23340 if (!cu
->base_address
.has_value ())
23341 complaint (_("Location list used without "
23342 "specifying the CU base address."));
23344 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23345 ? dwarf2_loclist_block_index
23346 : dwarf2_loclist_index
);
23347 SYMBOL_LOCATION_BATON (sym
) = baton
;
23351 struct dwarf2_locexpr_baton
*baton
;
23353 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23354 baton
->per_objfile
= per_objfile
;
23355 baton
->per_cu
= cu
->per_cu
;
23356 gdb_assert (baton
->per_cu
);
23358 if (attr
->form_is_block ())
23360 /* Note that we're just copying the block's data pointer
23361 here, not the actual data. We're still pointing into the
23362 info_buffer for SYM's objfile; right now we never release
23363 that buffer, but when we do clean up properly this may
23365 baton
->size
= DW_BLOCK (attr
)->size
;
23366 baton
->data
= DW_BLOCK (attr
)->data
;
23370 dwarf2_invalid_attrib_class_complaint ("location description",
23371 sym
->natural_name ());
23375 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23376 ? dwarf2_locexpr_block_index
23377 : dwarf2_locexpr_index
);
23378 SYMBOL_LOCATION_BATON (sym
) = baton
;
23384 const comp_unit_head
*
23385 dwarf2_per_cu_data::get_header () const
23387 if (!m_header_read_in
)
23389 const gdb_byte
*info_ptr
23390 = this->section
->buffer
+ to_underlying (this->sect_off
);
23392 memset (&m_header
, 0, sizeof (m_header
));
23394 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
23395 rcuh_kind::COMPILE
);
23404 dwarf2_per_cu_data::addr_size () const
23406 return this->get_header ()->addr_size
;
23412 dwarf2_per_cu_data::offset_size () const
23414 return this->get_header ()->offset_size
;
23420 dwarf2_per_cu_data::ref_addr_size () const
23422 const comp_unit_head
*header
= this->get_header ();
23424 if (header
->version
== 2)
23425 return header
->addr_size
;
23427 return header
->offset_size
;
23433 dwarf2_cu::addr_type () const
23435 struct objfile
*objfile
= this->per_objfile
->objfile
;
23436 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23437 struct type
*addr_type
= lookup_pointer_type (void_type
);
23438 int addr_size
= this->per_cu
->addr_size ();
23440 if (TYPE_LENGTH (addr_type
) == addr_size
)
23443 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23447 /* A helper function for dwarf2_find_containing_comp_unit that returns
23448 the index of the result, and that searches a vector. It will
23449 return a result even if the offset in question does not actually
23450 occur in any CU. This is separate so that it can be unit
23454 dwarf2_find_containing_comp_unit
23455 (sect_offset sect_off
,
23456 unsigned int offset_in_dwz
,
23457 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23462 high
= all_comp_units
.size () - 1;
23465 struct dwarf2_per_cu_data
*mid_cu
;
23466 int mid
= low
+ (high
- low
) / 2;
23468 mid_cu
= all_comp_units
[mid
];
23469 if (mid_cu
->is_dwz
> offset_in_dwz
23470 || (mid_cu
->is_dwz
== offset_in_dwz
23471 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23476 gdb_assert (low
== high
);
23480 /* Locate the .debug_info compilation unit from CU's objfile which contains
23481 the DIE at OFFSET. Raises an error on failure. */
23483 static struct dwarf2_per_cu_data
*
23484 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23485 unsigned int offset_in_dwz
,
23486 dwarf2_per_objfile
*per_objfile
)
23488 int low
= dwarf2_find_containing_comp_unit
23489 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
23490 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
23492 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23494 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23495 error (_("Dwarf Error: could not find partial DIE containing "
23496 "offset %s [in module %s]"),
23497 sect_offset_str (sect_off
),
23498 bfd_get_filename (per_objfile
->objfile
->obfd
));
23500 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23502 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
23506 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
23507 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23508 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23509 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23516 namespace selftests
{
23517 namespace find_containing_comp_unit
{
23522 struct dwarf2_per_cu_data one
{};
23523 struct dwarf2_per_cu_data two
{};
23524 struct dwarf2_per_cu_data three
{};
23525 struct dwarf2_per_cu_data four
{};
23528 two
.sect_off
= sect_offset (one
.length
);
23533 four
.sect_off
= sect_offset (three
.length
);
23537 std::vector
<dwarf2_per_cu_data
*> units
;
23538 units
.push_back (&one
);
23539 units
.push_back (&two
);
23540 units
.push_back (&three
);
23541 units
.push_back (&four
);
23545 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23546 SELF_CHECK (units
[result
] == &one
);
23547 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23548 SELF_CHECK (units
[result
] == &one
);
23549 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23550 SELF_CHECK (units
[result
] == &two
);
23552 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23553 SELF_CHECK (units
[result
] == &three
);
23554 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23555 SELF_CHECK (units
[result
] == &three
);
23556 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23557 SELF_CHECK (units
[result
] == &four
);
23563 #endif /* GDB_SELF_TEST */
23565 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23567 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23568 dwarf2_per_objfile
*per_objfile
)
23570 per_objfile (per_objfile
),
23572 has_loclist (false),
23573 checked_producer (false),
23574 producer_is_gxx_lt_4_6 (false),
23575 producer_is_gcc_lt_4_3 (false),
23576 producer_is_icc (false),
23577 producer_is_icc_lt_14 (false),
23578 producer_is_codewarrior (false),
23579 processing_has_namespace_info (false)
23583 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23586 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23587 enum language pretend_language
)
23589 struct attribute
*attr
;
23591 /* Set the language we're debugging. */
23592 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23593 if (attr
!= nullptr)
23594 set_cu_language (DW_UNSND (attr
), cu
);
23597 cu
->language
= pretend_language
;
23598 cu
->language_defn
= language_def (cu
->language
);
23601 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23607 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
23609 auto it
= m_dwarf2_cus
.find (per_cu
);
23610 if (it
== m_dwarf2_cus
.end ())
23619 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
23621 gdb_assert (this->get_cu (per_cu
) == nullptr);
23623 m_dwarf2_cus
[per_cu
] = cu
;
23629 dwarf2_per_objfile::age_comp_units ()
23631 /* Start by clearing all marks. */
23632 for (auto pair
: m_dwarf2_cus
)
23633 pair
.second
->mark
= false;
23635 /* Traverse all CUs, mark them and their dependencies if used recently
23637 for (auto pair
: m_dwarf2_cus
)
23639 dwarf2_cu
*cu
= pair
.second
;
23642 if (cu
->last_used
<= dwarf_max_cache_age
)
23646 /* Delete all CUs still not marked. */
23647 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
23649 dwarf2_cu
*cu
= it
->second
;
23654 it
= m_dwarf2_cus
.erase (it
);
23664 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
23666 auto it
= m_dwarf2_cus
.find (per_cu
);
23667 if (it
== m_dwarf2_cus
.end ())
23672 m_dwarf2_cus
.erase (it
);
23675 dwarf2_per_objfile::~dwarf2_per_objfile ()
23680 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23681 We store these in a hash table separate from the DIEs, and preserve them
23682 when the DIEs are flushed out of cache.
23684 The CU "per_cu" pointer is needed because offset alone is not enough to
23685 uniquely identify the type. A file may have multiple .debug_types sections,
23686 or the type may come from a DWO file. Furthermore, while it's more logical
23687 to use per_cu->section+offset, with Fission the section with the data is in
23688 the DWO file but we don't know that section at the point we need it.
23689 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23690 because we can enter the lookup routine, get_die_type_at_offset, from
23691 outside this file, and thus won't necessarily have PER_CU->cu.
23692 Fortunately, PER_CU is stable for the life of the objfile. */
23694 struct dwarf2_per_cu_offset_and_type
23696 const struct dwarf2_per_cu_data
*per_cu
;
23697 sect_offset sect_off
;
23701 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23704 per_cu_offset_and_type_hash (const void *item
)
23706 const struct dwarf2_per_cu_offset_and_type
*ofs
23707 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23709 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23712 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23715 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23717 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23718 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23719 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23720 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23722 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23723 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23726 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23727 table if necessary. For convenience, return TYPE.
23729 The DIEs reading must have careful ordering to:
23730 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23731 reading current DIE.
23732 * Not trying to dereference contents of still incompletely read in types
23733 while reading in other DIEs.
23734 * Enable referencing still incompletely read in types just by a pointer to
23735 the type without accessing its fields.
23737 Therefore caller should follow these rules:
23738 * Try to fetch any prerequisite types we may need to build this DIE type
23739 before building the type and calling set_die_type.
23740 * After building type call set_die_type for current DIE as soon as
23741 possible before fetching more types to complete the current type.
23742 * Make the type as complete as possible before fetching more types. */
23744 static struct type
*
23745 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23747 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23748 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23749 struct objfile
*objfile
= per_objfile
->objfile
;
23750 struct attribute
*attr
;
23751 struct dynamic_prop prop
;
23753 /* For Ada types, make sure that the gnat-specific data is always
23754 initialized (if not already set). There are a few types where
23755 we should not be doing so, because the type-specific area is
23756 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23757 where the type-specific area is used to store the floatformat).
23758 But this is not a problem, because the gnat-specific information
23759 is actually not needed for these types. */
23760 if (need_gnat_info (cu
)
23761 && type
->code () != TYPE_CODE_FUNC
23762 && type
->code () != TYPE_CODE_FLT
23763 && type
->code () != TYPE_CODE_METHODPTR
23764 && type
->code () != TYPE_CODE_MEMBERPTR
23765 && type
->code () != TYPE_CODE_METHOD
23766 && !HAVE_GNAT_AUX_INFO (type
))
23767 INIT_GNAT_SPECIFIC (type
);
23769 /* Read DW_AT_allocated and set in type. */
23770 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23771 if (attr
!= NULL
&& attr
->form_is_block ())
23773 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23774 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23775 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23777 else if (attr
!= NULL
)
23779 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23780 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23781 sect_offset_str (die
->sect_off
));
23784 /* Read DW_AT_associated and set in type. */
23785 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23786 if (attr
!= NULL
&& attr
->form_is_block ())
23788 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23789 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23790 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23792 else if (attr
!= NULL
)
23794 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23795 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23796 sect_offset_str (die
->sect_off
));
23799 /* Read DW_AT_data_location and set in type. */
23800 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23801 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23802 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23804 if (per_objfile
->die_type_hash
== NULL
)
23805 per_objfile
->die_type_hash
23806 = htab_up (htab_create_alloc (127,
23807 per_cu_offset_and_type_hash
,
23808 per_cu_offset_and_type_eq
,
23809 NULL
, xcalloc
, xfree
));
23811 ofs
.per_cu
= cu
->per_cu
;
23812 ofs
.sect_off
= die
->sect_off
;
23814 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23815 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23817 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23818 sect_offset_str (die
->sect_off
));
23819 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23820 struct dwarf2_per_cu_offset_and_type
);
23825 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23826 or return NULL if the die does not have a saved type. */
23828 static struct type
*
23829 get_die_type_at_offset (sect_offset sect_off
,
23830 dwarf2_per_cu_data
*per_cu
,
23831 dwarf2_per_objfile
*per_objfile
)
23833 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23835 if (per_objfile
->die_type_hash
== NULL
)
23838 ofs
.per_cu
= per_cu
;
23839 ofs
.sect_off
= sect_off
;
23840 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23841 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
23848 /* Look up the type for DIE in CU in die_type_hash,
23849 or return NULL if DIE does not have a saved type. */
23851 static struct type
*
23852 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23854 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
23857 /* Add a dependence relationship from CU to REF_PER_CU. */
23860 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23861 struct dwarf2_per_cu_data
*ref_per_cu
)
23865 if (cu
->dependencies
== NULL
)
23867 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23868 NULL
, &cu
->comp_unit_obstack
,
23869 hashtab_obstack_allocate
,
23870 dummy_obstack_deallocate
);
23872 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23874 *slot
= ref_per_cu
;
23877 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23878 Set the mark field in every compilation unit in the
23879 cache that we must keep because we are keeping CU.
23881 DATA is the dwarf2_per_objfile object in which to look up CUs. */
23884 dwarf2_mark_helper (void **slot
, void *data
)
23886 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
23887 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
23888 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23890 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23891 reading of the chain. As such dependencies remain valid it is not much
23892 useful to track and undo them during QUIT cleanups. */
23901 if (cu
->dependencies
!= nullptr)
23902 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
23907 /* Set the mark field in CU and in every other compilation unit in the
23908 cache that we must keep because we are keeping CU. */
23911 dwarf2_mark (struct dwarf2_cu
*cu
)
23918 if (cu
->dependencies
!= nullptr)
23919 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
23922 /* Trivial hash function for partial_die_info: the hash value of a DIE
23923 is its offset in .debug_info for this objfile. */
23926 partial_die_hash (const void *item
)
23928 const struct partial_die_info
*part_die
23929 = (const struct partial_die_info
*) item
;
23931 return to_underlying (part_die
->sect_off
);
23934 /* Trivial comparison function for partial_die_info structures: two DIEs
23935 are equal if they have the same offset. */
23938 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23940 const struct partial_die_info
*part_die_lhs
23941 = (const struct partial_die_info
*) item_lhs
;
23942 const struct partial_die_info
*part_die_rhs
23943 = (const struct partial_die_info
*) item_rhs
;
23945 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23948 struct cmd_list_element
*set_dwarf_cmdlist
;
23949 struct cmd_list_element
*show_dwarf_cmdlist
;
23952 show_check_physname (struct ui_file
*file
, int from_tty
,
23953 struct cmd_list_element
*c
, const char *value
)
23955 fprintf_filtered (file
,
23956 _("Whether to check \"physname\" is %s.\n"),
23960 void _initialize_dwarf2_read ();
23962 _initialize_dwarf2_read ()
23964 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23965 Set DWARF specific variables.\n\
23966 Configure DWARF variables such as the cache size."),
23967 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23968 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23970 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23971 Show DWARF specific variables.\n\
23972 Show DWARF variables such as the cache size."),
23973 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23974 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23976 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23977 &dwarf_max_cache_age
, _("\
23978 Set the upper bound on the age of cached DWARF compilation units."), _("\
23979 Show the upper bound on the age of cached DWARF compilation units."), _("\
23980 A higher limit means that cached compilation units will be stored\n\
23981 in memory longer, and more total memory will be used. Zero disables\n\
23982 caching, which can slow down startup."),
23984 show_dwarf_max_cache_age
,
23985 &set_dwarf_cmdlist
,
23986 &show_dwarf_cmdlist
);
23988 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23989 Set debugging of the DWARF reader."), _("\
23990 Show debugging of the DWARF reader."), _("\
23991 When enabled (non-zero), debugging messages are printed during DWARF\n\
23992 reading and symtab expansion. A value of 1 (one) provides basic\n\
23993 information. A value greater than 1 provides more verbose information."),
23996 &setdebuglist
, &showdebuglist
);
23998 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23999 Set debugging of the DWARF DIE reader."), _("\
24000 Show debugging of the DWARF DIE reader."), _("\
24001 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24002 The value is the maximum depth to print."),
24005 &setdebuglist
, &showdebuglist
);
24007 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24008 Set debugging of the dwarf line reader."), _("\
24009 Show debugging of the dwarf line reader."), _("\
24010 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24011 A value of 1 (one) provides basic information.\n\
24012 A value greater than 1 provides more verbose information."),
24015 &setdebuglist
, &showdebuglist
);
24017 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24018 Set cross-checking of \"physname\" code against demangler."), _("\
24019 Show cross-checking of \"physname\" code against demangler."), _("\
24020 When enabled, GDB's internal \"physname\" code is checked against\n\
24022 NULL
, show_check_physname
,
24023 &setdebuglist
, &showdebuglist
);
24025 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24026 no_class
, &use_deprecated_index_sections
, _("\
24027 Set whether to use deprecated gdb_index sections."), _("\
24028 Show whether to use deprecated gdb_index sections."), _("\
24029 When enabled, deprecated .gdb_index sections are used anyway.\n\
24030 Normally they are ignored either because of a missing feature or\n\
24031 performance issue.\n\
24032 Warning: This option must be enabled before gdb reads the file."),
24035 &setlist
, &showlist
);
24037 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24038 &dwarf2_locexpr_funcs
);
24039 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24040 &dwarf2_loclist_funcs
);
24042 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24043 &dwarf2_block_frame_base_locexpr_funcs
);
24044 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24045 &dwarf2_block_frame_base_loclist_funcs
);
24048 selftests::register_test ("dw2_expand_symtabs_matching",
24049 selftests::dw2_expand_symtabs_matching::run_test
);
24050 selftests::register_test ("dwarf2_find_containing_comp_unit",
24051 selftests::find_containing_comp_unit::run_test
);