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 struct 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 /* Offset of this DIE. */
975 const sect_offset sect_off
;
977 /* DWARF-2 tag for this DIE. */
978 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
980 /* Assorted flags describing the data found in this DIE. */
981 const unsigned int has_children
: 1;
983 unsigned int is_external
: 1;
984 unsigned int is_declaration
: 1;
985 unsigned int has_type
: 1;
986 unsigned int has_specification
: 1;
987 unsigned int has_pc_info
: 1;
988 unsigned int may_be_inlined
: 1;
990 /* This DIE has been marked DW_AT_main_subprogram. */
991 unsigned int main_subprogram
: 1;
993 /* Flag set if the SCOPE field of this structure has been
995 unsigned int scope_set
: 1;
997 /* Flag set if the DIE has a byte_size attribute. */
998 unsigned int has_byte_size
: 1;
1000 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1001 unsigned int has_const_value
: 1;
1003 /* Flag set if any of the DIE's children are template arguments. */
1004 unsigned int has_template_arguments
: 1;
1006 /* Flag set if fixup has been called on this die. */
1007 unsigned int fixup_called
: 1;
1009 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1010 unsigned int is_dwz
: 1;
1012 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1013 unsigned int spec_is_dwz
: 1;
1015 /* The name of this DIE. Normally the value of DW_AT_name, but
1016 sometimes a default name for unnamed DIEs. */
1017 const char *name
= nullptr;
1019 /* The linkage name, if present. */
1020 const char *linkage_name
= nullptr;
1022 /* The scope to prepend to our children. This is generally
1023 allocated on the comp_unit_obstack, so will disappear
1024 when this compilation unit leaves the cache. */
1025 const char *scope
= nullptr;
1027 /* Some data associated with the partial DIE. The tag determines
1028 which field is live. */
1031 /* The location description associated with this DIE, if any. */
1032 struct dwarf_block
*locdesc
;
1033 /* The offset of an import, for DW_TAG_imported_unit. */
1034 sect_offset sect_off
;
1037 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1038 CORE_ADDR lowpc
= 0;
1039 CORE_ADDR highpc
= 0;
1041 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1042 DW_AT_sibling, if any. */
1043 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1044 could return DW_AT_sibling values to its caller load_partial_dies. */
1045 const gdb_byte
*sibling
= nullptr;
1047 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1048 DW_AT_specification (or DW_AT_abstract_origin or
1049 DW_AT_extension). */
1050 sect_offset spec_offset
{};
1052 /* Pointers to this DIE's parent, first child, and next sibling,
1054 struct partial_die_info
*die_parent
= nullptr;
1055 struct partial_die_info
*die_child
= nullptr;
1056 struct partial_die_info
*die_sibling
= nullptr;
1058 friend struct partial_die_info
*
1059 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1062 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1063 partial_die_info (sect_offset sect_off
)
1064 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1068 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1070 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1075 has_specification
= 0;
1078 main_subprogram
= 0;
1081 has_const_value
= 0;
1082 has_template_arguments
= 0;
1089 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1090 but this would require a corresponding change in unpack_field_as_long
1092 static int bits_per_byte
= 8;
1094 struct variant_part_builder
;
1096 /* When reading a variant, we track a bit more information about the
1097 field, and store it in an object of this type. */
1099 struct variant_field
1101 int first_field
= -1;
1102 int last_field
= -1;
1104 /* A variant can contain other variant parts. */
1105 std::vector
<variant_part_builder
> variant_parts
;
1107 /* If we see a DW_TAG_variant, then this will be set if this is the
1109 bool default_branch
= false;
1110 /* If we see a DW_AT_discr_value, then this will be the discriminant
1112 ULONGEST discriminant_value
= 0;
1113 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1115 struct dwarf_block
*discr_list_data
= nullptr;
1118 /* This represents a DW_TAG_variant_part. */
1120 struct variant_part_builder
1122 /* The offset of the discriminant field. */
1123 sect_offset discriminant_offset
{};
1125 /* Variants that are direct children of this variant part. */
1126 std::vector
<variant_field
> variants
;
1128 /* True if we're currently reading a variant. */
1129 bool processing_variant
= false;
1134 int accessibility
= 0;
1136 /* Variant parts need to find the discriminant, which is a DIE
1137 reference. We track the section offset of each field to make
1140 struct field field
{};
1145 const char *name
= nullptr;
1146 std::vector
<struct fn_field
> fnfields
;
1149 /* The routines that read and process dies for a C struct or C++ class
1150 pass lists of data member fields and lists of member function fields
1151 in an instance of a field_info structure, as defined below. */
1154 /* List of data member and baseclasses fields. */
1155 std::vector
<struct nextfield
> fields
;
1156 std::vector
<struct nextfield
> baseclasses
;
1158 /* Set if the accessibility of one of the fields is not public. */
1159 int non_public_fields
= 0;
1161 /* Member function fieldlist array, contains name of possibly overloaded
1162 member function, number of overloaded member functions and a pointer
1163 to the head of the member function field chain. */
1164 std::vector
<struct fnfieldlist
> fnfieldlists
;
1166 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1167 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1168 std::vector
<struct decl_field
> typedef_field_list
;
1170 /* Nested types defined by this class and the number of elements in this
1172 std::vector
<struct decl_field
> nested_types_list
;
1174 /* If non-null, this is the variant part we are currently
1176 variant_part_builder
*current_variant_part
= nullptr;
1177 /* This holds all the top-level variant parts attached to the type
1179 std::vector
<variant_part_builder
> variant_parts
;
1181 /* Return the total number of fields (including baseclasses). */
1182 int nfields () const
1184 return fields
.size () + baseclasses
.size ();
1188 /* Loaded secondary compilation units are kept in memory until they
1189 have not been referenced for the processing of this many
1190 compilation units. Set this to zero to disable caching. Cache
1191 sizes of up to at least twenty will improve startup time for
1192 typical inter-CU-reference binaries, at an obvious memory cost. */
1193 static int dwarf_max_cache_age
= 5;
1195 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1196 struct cmd_list_element
*c
, const char *value
)
1198 fprintf_filtered (file
, _("The upper bound on the age of cached "
1199 "DWARF compilation units is %s.\n"),
1203 /* local function prototypes */
1205 static void dwarf2_find_base_address (struct die_info
*die
,
1206 struct dwarf2_cu
*cu
);
1208 static dwarf2_psymtab
*create_partial_symtab
1209 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1212 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1213 const gdb_byte
*info_ptr
,
1214 struct die_info
*type_unit_die
);
1216 static void dwarf2_build_psymtabs_hard
1217 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1219 static void scan_partial_symbols (struct partial_die_info
*,
1220 CORE_ADDR
*, CORE_ADDR
*,
1221 int, struct dwarf2_cu
*);
1223 static void add_partial_symbol (struct partial_die_info
*,
1224 struct dwarf2_cu
*);
1226 static void add_partial_namespace (struct partial_die_info
*pdi
,
1227 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1228 int set_addrmap
, struct dwarf2_cu
*cu
);
1230 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1231 CORE_ADDR
*highpc
, int set_addrmap
,
1232 struct dwarf2_cu
*cu
);
1234 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1235 struct dwarf2_cu
*cu
);
1237 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1238 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1239 int need_pc
, struct dwarf2_cu
*cu
);
1241 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1243 static struct partial_die_info
*load_partial_dies
1244 (const struct die_reader_specs
*, const gdb_byte
*, int);
1246 /* A pair of partial_die_info and compilation unit. */
1247 struct cu_partial_die_info
1249 /* The compilation unit of the partial_die_info. */
1250 struct dwarf2_cu
*cu
;
1251 /* A partial_die_info. */
1252 struct partial_die_info
*pdi
;
1254 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1260 cu_partial_die_info () = delete;
1263 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1264 struct dwarf2_cu
*);
1266 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1267 struct attribute
*, struct attr_abbrev
*,
1268 const gdb_byte
*, bool *need_reprocess
);
1270 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1271 struct attribute
*attr
);
1273 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1275 static sect_offset read_abbrev_offset
1276 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1277 struct dwarf2_section_info
*, sect_offset
);
1279 static const char *read_indirect_string
1280 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1281 const struct comp_unit_head
*, unsigned int *);
1283 static const char *read_indirect_string_at_offset
1284 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1286 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1290 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1291 ULONGEST str_index
);
1293 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1294 ULONGEST str_index
);
1296 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1298 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1299 struct dwarf2_cu
*);
1301 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1302 struct dwarf2_cu
*cu
);
1304 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1306 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1307 struct dwarf2_cu
*cu
);
1309 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1311 static struct die_info
*die_specification (struct die_info
*die
,
1312 struct dwarf2_cu
**);
1314 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1315 struct dwarf2_cu
*cu
);
1317 static void dwarf_decode_lines (struct line_header
*, const char *,
1318 struct dwarf2_cu
*, dwarf2_psymtab
*,
1319 CORE_ADDR
, int decode_mapping
);
1321 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1324 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1325 struct dwarf2_cu
*, struct symbol
* = NULL
);
1327 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1328 struct dwarf2_cu
*);
1330 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1333 struct obstack
*obstack
,
1334 struct dwarf2_cu
*cu
, LONGEST
*value
,
1335 const gdb_byte
**bytes
,
1336 struct dwarf2_locexpr_baton
**baton
);
1338 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1340 static int need_gnat_info (struct dwarf2_cu
*);
1342 static struct type
*die_descriptive_type (struct die_info
*,
1343 struct dwarf2_cu
*);
1345 static void set_descriptive_type (struct type
*, struct die_info
*,
1346 struct dwarf2_cu
*);
1348 static struct type
*die_containing_type (struct die_info
*,
1349 struct dwarf2_cu
*);
1351 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1352 struct dwarf2_cu
*);
1354 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1356 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1358 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1360 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1361 const char *suffix
, int physname
,
1362 struct dwarf2_cu
*cu
);
1364 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1366 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1368 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1370 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1372 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1374 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1376 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1377 struct dwarf2_cu
*, dwarf2_psymtab
*);
1379 /* Return the .debug_loclists section to use for cu. */
1380 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1382 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1383 values. Keep the items ordered with increasing constraints compliance. */
1386 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1387 PC_BOUNDS_NOT_PRESENT
,
1389 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1390 were present but they do not form a valid range of PC addresses. */
1393 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1396 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1400 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1401 CORE_ADDR
*, CORE_ADDR
*,
1405 static void get_scope_pc_bounds (struct die_info
*,
1406 CORE_ADDR
*, CORE_ADDR
*,
1407 struct dwarf2_cu
*);
1409 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1410 CORE_ADDR
, struct dwarf2_cu
*);
1412 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1413 struct dwarf2_cu
*);
1415 static void dwarf2_attach_fields_to_type (struct field_info
*,
1416 struct type
*, struct dwarf2_cu
*);
1418 static void dwarf2_add_member_fn (struct field_info
*,
1419 struct die_info
*, struct type
*,
1420 struct dwarf2_cu
*);
1422 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1424 struct dwarf2_cu
*);
1426 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1428 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1430 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1432 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1434 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1436 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1438 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1440 static struct type
*read_module_type (struct die_info
*die
,
1441 struct dwarf2_cu
*cu
);
1443 static const char *namespace_name (struct die_info
*die
,
1444 int *is_anonymous
, struct dwarf2_cu
*);
1446 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1448 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1451 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1452 struct dwarf2_cu
*);
1454 static struct die_info
*read_die_and_siblings_1
1455 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1458 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1459 const gdb_byte
*info_ptr
,
1460 const gdb_byte
**new_info_ptr
,
1461 struct die_info
*parent
);
1463 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1464 struct die_info
**, const gdb_byte
*,
1467 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1468 struct die_info
**, const gdb_byte
*);
1470 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1472 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1475 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1477 static const char *dwarf2_full_name (const char *name
,
1478 struct die_info
*die
,
1479 struct dwarf2_cu
*cu
);
1481 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1482 struct dwarf2_cu
*cu
);
1484 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1485 struct dwarf2_cu
**);
1487 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1489 static void dump_die_for_error (struct die_info
*);
1491 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1494 /*static*/ void dump_die (struct die_info
*, int max_level
);
1496 static void store_in_ref_table (struct die_info
*,
1497 struct dwarf2_cu
*);
1499 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1500 const struct attribute
*,
1501 struct dwarf2_cu
**);
1503 static struct die_info
*follow_die_ref (struct die_info
*,
1504 const struct attribute
*,
1505 struct dwarf2_cu
**);
1507 static struct die_info
*follow_die_sig (struct die_info
*,
1508 const struct attribute
*,
1509 struct dwarf2_cu
**);
1511 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1512 struct dwarf2_cu
*);
1514 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1515 const struct attribute
*,
1516 struct dwarf2_cu
*);
1518 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1519 dwarf2_per_objfile
*per_objfile
);
1521 static void read_signatured_type (signatured_type
*sig_type
,
1522 dwarf2_per_objfile
*per_objfile
);
1524 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1525 struct die_info
*die
, struct dwarf2_cu
*cu
,
1526 struct dynamic_prop
*prop
, struct type
*type
);
1528 /* memory allocation interface */
1530 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1532 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1534 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1536 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1537 struct dwarf2_loclist_baton
*baton
,
1538 const struct attribute
*attr
);
1540 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1542 struct dwarf2_cu
*cu
,
1545 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1546 const gdb_byte
*info_ptr
,
1547 struct abbrev_info
*abbrev
);
1549 static hashval_t
partial_die_hash (const void *item
);
1551 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1553 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1554 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1555 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1557 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1558 struct die_info
*comp_unit_die
,
1559 enum language pretend_language
);
1561 static struct type
*set_die_type (struct die_info
*, struct type
*,
1562 struct dwarf2_cu
*);
1564 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1566 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1568 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1569 dwarf2_per_objfile
*per_objfile
,
1571 enum language pretend_language
);
1573 static void process_full_comp_unit (dwarf2_cu
*cu
,
1574 enum language pretend_language
);
1576 static void process_full_type_unit (dwarf2_cu
*cu
,
1577 enum language pretend_language
);
1579 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1580 struct dwarf2_per_cu_data
*);
1582 static void dwarf2_mark (struct dwarf2_cu
*);
1584 static struct type
*get_die_type_at_offset (sect_offset
,
1585 dwarf2_per_cu_data
*per_cu
,
1586 dwarf2_per_objfile
*per_objfile
);
1588 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1590 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1591 dwarf2_per_objfile
*per_objfile
,
1592 enum language pretend_language
);
1594 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1596 /* Class, the destructor of which frees all allocated queue entries. This
1597 will only have work to do if an error was thrown while processing the
1598 dwarf. If no error was thrown then the queue entries should have all
1599 been processed, and freed, as we went along. */
1601 class dwarf2_queue_guard
1604 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1605 : m_per_objfile (per_objfile
)
1609 /* Free any entries remaining on the queue. There should only be
1610 entries left if we hit an error while processing the dwarf. */
1611 ~dwarf2_queue_guard ()
1613 /* Ensure that no memory is allocated by the queue. */
1614 std::queue
<dwarf2_queue_item
> empty
;
1615 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1618 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1621 dwarf2_per_objfile
*m_per_objfile
;
1624 dwarf2_queue_item::~dwarf2_queue_item ()
1626 /* Anything still marked queued is likely to be in an
1627 inconsistent state, so discard it. */
1630 per_objfile
->remove_cu (per_cu
);
1635 /* The return type of find_file_and_directory. Note, the enclosed
1636 string pointers are only valid while this object is valid. */
1638 struct file_and_directory
1640 /* The filename. This is never NULL. */
1643 /* The compilation directory. NULL if not known. If we needed to
1644 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1645 points directly to the DW_AT_comp_dir string attribute owned by
1646 the obstack that owns the DIE. */
1647 const char *comp_dir
;
1649 /* If we needed to build a new string for comp_dir, this is what
1650 owns the storage. */
1651 std::string comp_dir_storage
;
1654 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1655 struct dwarf2_cu
*cu
);
1657 static htab_up
allocate_signatured_type_table ();
1659 static htab_up
allocate_dwo_unit_table ();
1661 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1662 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1663 struct dwp_file
*dwp_file
, const char *comp_dir
,
1664 ULONGEST signature
, int is_debug_types
);
1666 static struct dwp_file
*get_dwp_file
1667 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1669 static struct dwo_unit
*lookup_dwo_comp_unit
1670 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1671 ULONGEST signature
);
1673 static struct dwo_unit
*lookup_dwo_type_unit
1674 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1676 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1678 /* A unique pointer to a dwo_file. */
1680 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1682 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1684 static void check_producer (struct dwarf2_cu
*cu
);
1686 static void free_line_header_voidp (void *arg
);
1688 /* Various complaints about symbol reading that don't abort the process. */
1691 dwarf2_debug_line_missing_file_complaint (void)
1693 complaint (_(".debug_line section has line data without a file"));
1697 dwarf2_debug_line_missing_end_sequence_complaint (void)
1699 complaint (_(".debug_line section has line "
1700 "program sequence without an end"));
1704 dwarf2_complex_location_expr_complaint (void)
1706 complaint (_("location expression too complex"));
1710 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1713 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1718 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1720 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1724 /* Hash function for line_header_hash. */
1727 line_header_hash (const struct line_header
*ofs
)
1729 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1732 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1735 line_header_hash_voidp (const void *item
)
1737 const struct line_header
*ofs
= (const struct line_header
*) item
;
1739 return line_header_hash (ofs
);
1742 /* Equality function for line_header_hash. */
1745 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1747 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1748 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1750 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1751 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1756 /* See declaration. */
1758 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1761 can_copy (can_copy_
)
1764 names
= &dwarf2_elf_names
;
1766 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1767 locate_sections (obfd
, sec
, *names
);
1770 dwarf2_per_bfd::~dwarf2_per_bfd ()
1772 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1773 per_cu
->imported_symtabs_free ();
1775 for (signatured_type
*sig_type
: all_type_units
)
1776 sig_type
->per_cu
.imported_symtabs_free ();
1778 /* Everything else should be on this->obstack. */
1784 dwarf2_per_objfile::remove_all_cus ()
1786 for (auto pair
: m_dwarf2_cus
)
1789 m_dwarf2_cus
.clear ();
1792 /* A helper class that calls free_cached_comp_units on
1795 class free_cached_comp_units
1799 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1800 : m_per_objfile (per_objfile
)
1804 ~free_cached_comp_units ()
1806 m_per_objfile
->remove_all_cus ();
1809 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1813 dwarf2_per_objfile
*m_per_objfile
;
1819 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1821 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1823 return this->m_symtabs
[per_cu
->index
] != nullptr;
1829 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1831 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1833 return this->m_symtabs
[per_cu
->index
];
1839 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1840 compunit_symtab
*symtab
)
1842 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1843 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1845 this->m_symtabs
[per_cu
->index
] = symtab
;
1848 /* Try to locate the sections we need for DWARF 2 debugging
1849 information and return true if we have enough to do something.
1850 NAMES points to the dwarf2 section names, or is NULL if the standard
1851 ELF names are used. CAN_COPY is true for formats where symbol
1852 interposition is possible and so symbol values must follow copy
1853 relocation rules. */
1856 dwarf2_has_info (struct objfile
*objfile
,
1857 const struct dwarf2_debug_sections
*names
,
1860 if (objfile
->flags
& OBJF_READNEVER
)
1863 struct dwarf2_per_objfile
*dwarf2_per_objfile
1864 = get_dwarf2_per_objfile (objfile
);
1866 if (dwarf2_per_objfile
== NULL
)
1868 dwarf2_per_bfd
*per_bfd
;
1870 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1871 doesn't require relocations and if there aren't partial symbols
1872 from some other reader. */
1873 if (!objfile_has_partial_symbols (objfile
)
1874 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1876 /* See if one has been created for this BFD yet. */
1877 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1879 if (per_bfd
== nullptr)
1881 /* No, create it now. */
1882 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1883 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1888 /* No sharing possible, create one specifically for this objfile. */
1889 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1890 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1893 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1896 return (!dwarf2_per_objfile
->per_bfd
->info
.is_virtual
1897 && dwarf2_per_objfile
->per_bfd
->info
.s
.section
!= NULL
1898 && !dwarf2_per_objfile
->per_bfd
->abbrev
.is_virtual
1899 && dwarf2_per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1902 /* When loading sections, we look either for uncompressed section or for
1903 compressed section names. */
1906 section_is_p (const char *section_name
,
1907 const struct dwarf2_section_names
*names
)
1909 if (names
->normal
!= NULL
1910 && strcmp (section_name
, names
->normal
) == 0)
1912 if (names
->compressed
!= NULL
1913 && strcmp (section_name
, names
->compressed
) == 0)
1918 /* See declaration. */
1921 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1922 const dwarf2_debug_sections
&names
)
1924 flagword aflag
= bfd_section_flags (sectp
);
1926 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1929 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1930 > bfd_get_file_size (abfd
))
1932 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1933 warning (_("Discarding section %s which has a section size (%s"
1934 ") larger than the file size [in module %s]"),
1935 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1936 bfd_get_filename (abfd
));
1938 else if (section_is_p (sectp
->name
, &names
.info
))
1940 this->info
.s
.section
= sectp
;
1941 this->info
.size
= bfd_section_size (sectp
);
1943 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1945 this->abbrev
.s
.section
= sectp
;
1946 this->abbrev
.size
= bfd_section_size (sectp
);
1948 else if (section_is_p (sectp
->name
, &names
.line
))
1950 this->line
.s
.section
= sectp
;
1951 this->line
.size
= bfd_section_size (sectp
);
1953 else if (section_is_p (sectp
->name
, &names
.loc
))
1955 this->loc
.s
.section
= sectp
;
1956 this->loc
.size
= bfd_section_size (sectp
);
1958 else if (section_is_p (sectp
->name
, &names
.loclists
))
1960 this->loclists
.s
.section
= sectp
;
1961 this->loclists
.size
= bfd_section_size (sectp
);
1963 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1965 this->macinfo
.s
.section
= sectp
;
1966 this->macinfo
.size
= bfd_section_size (sectp
);
1968 else if (section_is_p (sectp
->name
, &names
.macro
))
1970 this->macro
.s
.section
= sectp
;
1971 this->macro
.size
= bfd_section_size (sectp
);
1973 else if (section_is_p (sectp
->name
, &names
.str
))
1975 this->str
.s
.section
= sectp
;
1976 this->str
.size
= bfd_section_size (sectp
);
1978 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1980 this->str_offsets
.s
.section
= sectp
;
1981 this->str_offsets
.size
= bfd_section_size (sectp
);
1983 else if (section_is_p (sectp
->name
, &names
.line_str
))
1985 this->line_str
.s
.section
= sectp
;
1986 this->line_str
.size
= bfd_section_size (sectp
);
1988 else if (section_is_p (sectp
->name
, &names
.addr
))
1990 this->addr
.s
.section
= sectp
;
1991 this->addr
.size
= bfd_section_size (sectp
);
1993 else if (section_is_p (sectp
->name
, &names
.frame
))
1995 this->frame
.s
.section
= sectp
;
1996 this->frame
.size
= bfd_section_size (sectp
);
1998 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2000 this->eh_frame
.s
.section
= sectp
;
2001 this->eh_frame
.size
= bfd_section_size (sectp
);
2003 else if (section_is_p (sectp
->name
, &names
.ranges
))
2005 this->ranges
.s
.section
= sectp
;
2006 this->ranges
.size
= bfd_section_size (sectp
);
2008 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2010 this->rnglists
.s
.section
= sectp
;
2011 this->rnglists
.size
= bfd_section_size (sectp
);
2013 else if (section_is_p (sectp
->name
, &names
.types
))
2015 struct dwarf2_section_info type_section
;
2017 memset (&type_section
, 0, sizeof (type_section
));
2018 type_section
.s
.section
= sectp
;
2019 type_section
.size
= bfd_section_size (sectp
);
2021 this->types
.push_back (type_section
);
2023 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2025 this->gdb_index
.s
.section
= sectp
;
2026 this->gdb_index
.size
= bfd_section_size (sectp
);
2028 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2030 this->debug_names
.s
.section
= sectp
;
2031 this->debug_names
.size
= bfd_section_size (sectp
);
2033 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2035 this->debug_aranges
.s
.section
= sectp
;
2036 this->debug_aranges
.size
= bfd_section_size (sectp
);
2039 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2040 && bfd_section_vma (sectp
) == 0)
2041 this->has_section_at_zero
= true;
2044 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2048 dwarf2_get_section_info (struct objfile
*objfile
,
2049 enum dwarf2_section_enum sect
,
2050 asection
**sectp
, const gdb_byte
**bufp
,
2051 bfd_size_type
*sizep
)
2053 struct dwarf2_per_objfile
*data
= get_dwarf2_per_objfile (objfile
);
2054 struct dwarf2_section_info
*info
;
2056 /* We may see an objfile without any DWARF, in which case we just
2067 case DWARF2_DEBUG_FRAME
:
2068 info
= &data
->per_bfd
->frame
;
2070 case DWARF2_EH_FRAME
:
2071 info
= &data
->per_bfd
->eh_frame
;
2074 gdb_assert_not_reached ("unexpected section");
2077 info
->read (objfile
);
2079 *sectp
= info
->get_bfd_section ();
2080 *bufp
= info
->buffer
;
2081 *sizep
= info
->size
;
2084 /* A helper function to find the sections for a .dwz file. */
2087 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2089 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2091 /* Note that we only support the standard ELF names, because .dwz
2092 is ELF-only (at the time of writing). */
2093 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2095 dwz_file
->abbrev
.s
.section
= sectp
;
2096 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2098 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2100 dwz_file
->info
.s
.section
= sectp
;
2101 dwz_file
->info
.size
= bfd_section_size (sectp
);
2103 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2105 dwz_file
->str
.s
.section
= sectp
;
2106 dwz_file
->str
.size
= bfd_section_size (sectp
);
2108 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2110 dwz_file
->line
.s
.section
= sectp
;
2111 dwz_file
->line
.size
= bfd_section_size (sectp
);
2113 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2115 dwz_file
->macro
.s
.section
= sectp
;
2116 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2118 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2120 dwz_file
->gdb_index
.s
.section
= sectp
;
2121 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2123 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2125 dwz_file
->debug_names
.s
.section
= sectp
;
2126 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2130 /* See dwarf2read.h. */
2133 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2135 const char *filename
;
2136 bfd_size_type buildid_len_arg
;
2140 if (per_bfd
->dwz_file
!= NULL
)
2141 return per_bfd
->dwz_file
.get ();
2143 bfd_set_error (bfd_error_no_error
);
2144 gdb::unique_xmalloc_ptr
<char> data
2145 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2146 &buildid_len_arg
, &buildid
));
2149 if (bfd_get_error () == bfd_error_no_error
)
2151 error (_("could not read '.gnu_debugaltlink' section: %s"),
2152 bfd_errmsg (bfd_get_error ()));
2155 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2157 buildid_len
= (size_t) buildid_len_arg
;
2159 filename
= data
.get ();
2161 std::string abs_storage
;
2162 if (!IS_ABSOLUTE_PATH (filename
))
2164 gdb::unique_xmalloc_ptr
<char> abs
2165 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2167 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2168 filename
= abs_storage
.c_str ();
2171 /* First try the file name given in the section. If that doesn't
2172 work, try to use the build-id instead. */
2173 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2174 if (dwz_bfd
!= NULL
)
2176 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2177 dwz_bfd
.reset (nullptr);
2180 if (dwz_bfd
== NULL
)
2181 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2183 if (dwz_bfd
== nullptr)
2185 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2186 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2188 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2195 /* File successfully retrieved from server. */
2196 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2198 if (dwz_bfd
== nullptr)
2199 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2200 alt_filename
.get ());
2201 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2202 dwz_bfd
.reset (nullptr);
2206 if (dwz_bfd
== NULL
)
2207 error (_("could not find '.gnu_debugaltlink' file for %s"),
2208 bfd_get_filename (per_bfd
->obfd
));
2210 std::unique_ptr
<struct dwz_file
> result
2211 (new struct dwz_file (std::move (dwz_bfd
)));
2213 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2216 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2217 per_bfd
->dwz_file
= std::move (result
);
2218 return per_bfd
->dwz_file
.get ();
2221 /* DWARF quick_symbols_functions support. */
2223 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2224 unique line tables, so we maintain a separate table of all .debug_line
2225 derived entries to support the sharing.
2226 All the quick functions need is the list of file names. We discard the
2227 line_header when we're done and don't need to record it here. */
2228 struct quick_file_names
2230 /* The data used to construct the hash key. */
2231 struct stmt_list_hash hash
;
2233 /* The number of entries in file_names, real_names. */
2234 unsigned int num_file_names
;
2236 /* The file names from the line table, after being run through
2238 const char **file_names
;
2240 /* The file names from the line table after being run through
2241 gdb_realpath. These are computed lazily. */
2242 const char **real_names
;
2245 /* When using the index (and thus not using psymtabs), each CU has an
2246 object of this type. This is used to hold information needed by
2247 the various "quick" methods. */
2248 struct dwarf2_per_cu_quick_data
2250 /* The file table. This can be NULL if there was no file table
2251 or it's currently not read in.
2252 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2253 struct quick_file_names
*file_names
;
2255 /* A temporary mark bit used when iterating over all CUs in
2256 expand_symtabs_matching. */
2257 unsigned int mark
: 1;
2259 /* True if we've tried to read the file table and found there isn't one.
2260 There will be no point in trying to read it again next time. */
2261 unsigned int no_file_data
: 1;
2264 /* Utility hash function for a stmt_list_hash. */
2267 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2271 if (stmt_list_hash
->dwo_unit
!= NULL
)
2272 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2273 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2277 /* Utility equality function for a stmt_list_hash. */
2280 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2281 const struct stmt_list_hash
*rhs
)
2283 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2285 if (lhs
->dwo_unit
!= NULL
2286 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2289 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2292 /* Hash function for a quick_file_names. */
2295 hash_file_name_entry (const void *e
)
2297 const struct quick_file_names
*file_data
2298 = (const struct quick_file_names
*) e
;
2300 return hash_stmt_list_entry (&file_data
->hash
);
2303 /* Equality function for a quick_file_names. */
2306 eq_file_name_entry (const void *a
, const void *b
)
2308 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2309 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2311 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2314 /* Delete function for a quick_file_names. */
2317 delete_file_name_entry (void *e
)
2319 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2322 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2324 xfree ((void*) file_data
->file_names
[i
]);
2325 if (file_data
->real_names
)
2326 xfree ((void*) file_data
->real_names
[i
]);
2329 /* The space for the struct itself lives on the obstack, so we don't
2333 /* Create a quick_file_names hash table. */
2336 create_quick_file_names_table (unsigned int nr_initial_entries
)
2338 return htab_up (htab_create_alloc (nr_initial_entries
,
2339 hash_file_name_entry
, eq_file_name_entry
,
2340 delete_file_name_entry
, xcalloc
, xfree
));
2343 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2344 function is unrelated to symtabs, symtab would have to be created afterwards.
2345 You should call age_cached_comp_units after processing the CU. */
2348 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2351 if (per_cu
->is_debug_types
)
2352 load_full_type_unit (per_cu
, per_objfile
);
2354 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2356 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2358 return nullptr; /* Dummy CU. */
2360 dwarf2_find_base_address (cu
->dies
, cu
);
2365 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2368 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2369 dwarf2_per_objfile
*dwarf2_per_objfile
,
2372 /* Skip type_unit_groups, reading the type units they contain
2373 is handled elsewhere. */
2374 if (per_cu
->type_unit_group_p ())
2377 /* The destructor of dwarf2_queue_guard frees any entries left on
2378 the queue. After this point we're guaranteed to leave this function
2379 with the dwarf queue empty. */
2380 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2382 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2384 queue_comp_unit (per_cu
, dwarf2_per_objfile
, language_minimal
);
2385 dwarf2_cu
*cu
= load_cu (per_cu
, dwarf2_per_objfile
, skip_partial
);
2387 /* If we just loaded a CU from a DWO, and we're working with an index
2388 that may badly handle TUs, load all the TUs in that DWO as well.
2389 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2390 if (!per_cu
->is_debug_types
2392 && cu
->dwo_unit
!= NULL
2393 && dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
2394 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7
2395 /* DWP files aren't supported yet. */
2396 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2397 queue_and_load_all_dwo_tus (cu
);
2400 process_queue (dwarf2_per_objfile
);
2402 /* Age the cache, releasing compilation units that have not
2403 been used recently. */
2404 dwarf2_per_objfile
->age_comp_units ();
2407 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2408 the per-objfile for which this symtab is instantiated.
2410 Returns the resulting symbol table. */
2412 static struct compunit_symtab
*
2413 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2414 dwarf2_per_objfile
*dwarf2_per_objfile
,
2417 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
2419 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2421 free_cached_comp_units
freer (dwarf2_per_objfile
);
2422 scoped_restore decrementer
= increment_reading_symtab ();
2423 dw2_do_instantiate_symtab (per_cu
, dwarf2_per_objfile
, skip_partial
);
2424 process_cu_includes (dwarf2_per_objfile
);
2427 return dwarf2_per_objfile
->get_symtab (per_cu
);
2430 /* See declaration. */
2432 dwarf2_per_cu_data
*
2433 dwarf2_per_bfd::get_cutu (int index
)
2435 if (index
>= this->all_comp_units
.size ())
2437 index
-= this->all_comp_units
.size ();
2438 gdb_assert (index
< this->all_type_units
.size ());
2439 return &this->all_type_units
[index
]->per_cu
;
2442 return this->all_comp_units
[index
];
2445 /* See declaration. */
2447 dwarf2_per_cu_data
*
2448 dwarf2_per_bfd::get_cu (int index
)
2450 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2452 return this->all_comp_units
[index
];
2455 /* See declaration. */
2458 dwarf2_per_bfd::get_tu (int index
)
2460 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2462 return this->all_type_units
[index
];
2467 dwarf2_per_cu_data
*
2468 dwarf2_per_bfd::allocate_per_cu ()
2470 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2471 result
->per_bfd
= this;
2472 result
->index
= m_num_psymtabs
++;
2479 dwarf2_per_bfd::allocate_signatured_type ()
2481 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2482 result
->per_cu
.per_bfd
= this;
2483 result
->per_cu
.index
= m_num_psymtabs
++;
2487 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2488 obstack, and constructed with the specified field values. */
2490 static dwarf2_per_cu_data
*
2491 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2492 struct dwarf2_section_info
*section
,
2494 sect_offset sect_off
, ULONGEST length
)
2496 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2497 the_cu
->sect_off
= sect_off
;
2498 the_cu
->length
= length
;
2499 the_cu
->section
= section
;
2500 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2501 struct dwarf2_per_cu_quick_data
);
2502 the_cu
->is_dwz
= is_dwz
;
2506 /* A helper for create_cus_from_index that handles a given list of
2510 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2511 const gdb_byte
*cu_list
, offset_type n_elements
,
2512 struct dwarf2_section_info
*section
,
2515 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2517 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2519 sect_offset sect_off
2520 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2521 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2524 dwarf2_per_cu_data
*per_cu
2525 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2527 per_bfd
->all_comp_units
.push_back (per_cu
);
2531 /* Read the CU list from the mapped index, and use it to create all
2532 the CU objects for PER_BFD. */
2535 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2536 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2537 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2539 gdb_assert (per_bfd
->all_comp_units
.empty ());
2540 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2542 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2545 if (dwz_elements
== 0)
2548 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2549 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2553 /* Create the signatured type hash table from the index. */
2556 create_signatured_type_table_from_index
2557 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2558 const gdb_byte
*bytes
, offset_type elements
)
2560 gdb_assert (per_bfd
->all_type_units
.empty ());
2561 per_bfd
->all_type_units
.reserve (elements
/ 3);
2563 htab_up sig_types_hash
= allocate_signatured_type_table ();
2565 for (offset_type i
= 0; i
< elements
; i
+= 3)
2567 struct signatured_type
*sig_type
;
2570 cu_offset type_offset_in_tu
;
2572 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2573 sect_offset sect_off
2574 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2576 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2578 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2581 sig_type
= per_bfd
->allocate_signatured_type ();
2582 sig_type
->signature
= signature
;
2583 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2584 sig_type
->per_cu
.is_debug_types
= 1;
2585 sig_type
->per_cu
.section
= section
;
2586 sig_type
->per_cu
.sect_off
= sect_off
;
2587 sig_type
->per_cu
.v
.quick
2588 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2589 struct dwarf2_per_cu_quick_data
);
2591 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2594 per_bfd
->all_type_units
.push_back (sig_type
);
2597 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2600 /* Create the signatured type hash table from .debug_names. */
2603 create_signatured_type_table_from_debug_names
2604 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2605 const mapped_debug_names
&map
,
2606 struct dwarf2_section_info
*section
,
2607 struct dwarf2_section_info
*abbrev_section
)
2609 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2611 section
->read (objfile
);
2612 abbrev_section
->read (objfile
);
2614 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2615 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2617 htab_up sig_types_hash
= allocate_signatured_type_table ();
2619 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2621 struct signatured_type
*sig_type
;
2624 sect_offset sect_off
2625 = (sect_offset
) (extract_unsigned_integer
2626 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2628 map
.dwarf5_byte_order
));
2630 comp_unit_head cu_header
;
2631 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2633 section
->buffer
+ to_underlying (sect_off
),
2636 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2637 sig_type
->signature
= cu_header
.signature
;
2638 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2639 sig_type
->per_cu
.is_debug_types
= 1;
2640 sig_type
->per_cu
.section
= section
;
2641 sig_type
->per_cu
.sect_off
= sect_off
;
2642 sig_type
->per_cu
.v
.quick
2643 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2644 struct dwarf2_per_cu_quick_data
);
2646 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2649 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2652 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2655 /* Read the address map data from the mapped index, and use it to
2656 populate the objfile's psymtabs_addrmap. */
2659 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2660 struct mapped_index
*index
)
2662 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2663 struct gdbarch
*gdbarch
= objfile
->arch ();
2664 const gdb_byte
*iter
, *end
;
2665 struct addrmap
*mutable_map
;
2668 auto_obstack temp_obstack
;
2670 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2672 iter
= index
->address_table
.data ();
2673 end
= iter
+ index
->address_table
.size ();
2675 baseaddr
= objfile
->text_section_offset ();
2679 ULONGEST hi
, lo
, cu_index
;
2680 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2682 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2684 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2689 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2690 hex_string (lo
), hex_string (hi
));
2694 if (cu_index
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
2696 complaint (_(".gdb_index address table has invalid CU number %u"),
2697 (unsigned) cu_index
);
2701 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2702 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2703 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2704 dwarf2_per_objfile
->per_bfd
->get_cu (cu_index
));
2707 objfile
->partial_symtabs
->psymtabs_addrmap
2708 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2711 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2712 populate the objfile's psymtabs_addrmap. */
2715 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2716 struct dwarf2_section_info
*section
)
2718 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2719 bfd
*abfd
= objfile
->obfd
;
2720 struct gdbarch
*gdbarch
= objfile
->arch ();
2721 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2723 auto_obstack temp_obstack
;
2724 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2726 std::unordered_map
<sect_offset
,
2727 dwarf2_per_cu_data
*,
2728 gdb::hash_enum
<sect_offset
>>
2729 debug_info_offset_to_per_cu
;
2730 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
2732 const auto insertpair
2733 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2734 if (!insertpair
.second
)
2736 warning (_("Section .debug_aranges in %s has duplicate "
2737 "debug_info_offset %s, ignoring .debug_aranges."),
2738 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2743 section
->read (objfile
);
2745 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2747 const gdb_byte
*addr
= section
->buffer
;
2749 while (addr
< section
->buffer
+ section
->size
)
2751 const gdb_byte
*const entry_addr
= addr
;
2752 unsigned int bytes_read
;
2754 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2758 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2759 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2760 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2761 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2763 warning (_("Section .debug_aranges in %s entry at offset %s "
2764 "length %s exceeds section length %s, "
2765 "ignoring .debug_aranges."),
2766 objfile_name (objfile
),
2767 plongest (entry_addr
- section
->buffer
),
2768 plongest (bytes_read
+ entry_length
),
2769 pulongest (section
->size
));
2773 /* The version number. */
2774 const uint16_t version
= read_2_bytes (abfd
, addr
);
2778 warning (_("Section .debug_aranges in %s entry at offset %s "
2779 "has unsupported version %d, ignoring .debug_aranges."),
2780 objfile_name (objfile
),
2781 plongest (entry_addr
- section
->buffer
), version
);
2785 const uint64_t debug_info_offset
2786 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2787 addr
+= offset_size
;
2788 const auto per_cu_it
2789 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2790 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2792 warning (_("Section .debug_aranges in %s entry at offset %s "
2793 "debug_info_offset %s does not exists, "
2794 "ignoring .debug_aranges."),
2795 objfile_name (objfile
),
2796 plongest (entry_addr
- section
->buffer
),
2797 pulongest (debug_info_offset
));
2800 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2802 const uint8_t address_size
= *addr
++;
2803 if (address_size
< 1 || address_size
> 8)
2805 warning (_("Section .debug_aranges in %s entry at offset %s "
2806 "address_size %u is invalid, ignoring .debug_aranges."),
2807 objfile_name (objfile
),
2808 plongest (entry_addr
- section
->buffer
), address_size
);
2812 const uint8_t segment_selector_size
= *addr
++;
2813 if (segment_selector_size
!= 0)
2815 warning (_("Section .debug_aranges in %s entry at offset %s "
2816 "segment_selector_size %u is not supported, "
2817 "ignoring .debug_aranges."),
2818 objfile_name (objfile
),
2819 plongest (entry_addr
- section
->buffer
),
2820 segment_selector_size
);
2824 /* Must pad to an alignment boundary that is twice the address
2825 size. It is undocumented by the DWARF standard but GCC does
2827 for (size_t padding
= ((-(addr
- section
->buffer
))
2828 & (2 * address_size
- 1));
2829 padding
> 0; padding
--)
2832 warning (_("Section .debug_aranges in %s entry at offset %s "
2833 "padding is not zero, ignoring .debug_aranges."),
2834 objfile_name (objfile
),
2835 plongest (entry_addr
- section
->buffer
));
2841 if (addr
+ 2 * address_size
> entry_end
)
2843 warning (_("Section .debug_aranges in %s entry at offset %s "
2844 "address list is not properly terminated, "
2845 "ignoring .debug_aranges."),
2846 objfile_name (objfile
),
2847 plongest (entry_addr
- section
->buffer
));
2850 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2852 addr
+= address_size
;
2853 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2855 addr
+= address_size
;
2856 if (start
== 0 && length
== 0)
2858 if (start
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
2860 /* Symbol was eliminated due to a COMDAT group. */
2863 ULONGEST end
= start
+ length
;
2864 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2866 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2868 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2872 objfile
->partial_symtabs
->psymtabs_addrmap
2873 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2876 /* Find a slot in the mapped index INDEX for the object named NAME.
2877 If NAME is found, set *VEC_OUT to point to the CU vector in the
2878 constant pool and return true. If NAME cannot be found, return
2882 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2883 offset_type
**vec_out
)
2886 offset_type slot
, step
;
2887 int (*cmp
) (const char *, const char *);
2889 gdb::unique_xmalloc_ptr
<char> without_params
;
2890 if (current_language
->la_language
== language_cplus
2891 || current_language
->la_language
== language_fortran
2892 || current_language
->la_language
== language_d
)
2894 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2897 if (strchr (name
, '(') != NULL
)
2899 without_params
= cp_remove_params (name
);
2901 if (without_params
!= NULL
)
2902 name
= without_params
.get ();
2906 /* Index version 4 did not support case insensitive searches. But the
2907 indices for case insensitive languages are built in lowercase, therefore
2908 simulate our NAME being searched is also lowercased. */
2909 hash
= mapped_index_string_hash ((index
->version
== 4
2910 && case_sensitivity
== case_sensitive_off
2911 ? 5 : index
->version
),
2914 slot
= hash
& (index
->symbol_table
.size () - 1);
2915 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2916 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2922 const auto &bucket
= index
->symbol_table
[slot
];
2923 if (bucket
.name
== 0 && bucket
.vec
== 0)
2926 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2927 if (!cmp (name
, str
))
2929 *vec_out
= (offset_type
*) (index
->constant_pool
2930 + MAYBE_SWAP (bucket
.vec
));
2934 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2938 /* A helper function that reads the .gdb_index from BUFFER and fills
2939 in MAP. FILENAME is the name of the file containing the data;
2940 it is used for error reporting. DEPRECATED_OK is true if it is
2941 ok to use deprecated sections.
2943 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2944 out parameters that are filled in with information about the CU and
2945 TU lists in the section.
2947 Returns true if all went well, false otherwise. */
2950 read_gdb_index_from_buffer (const char *filename
,
2952 gdb::array_view
<const gdb_byte
> buffer
,
2953 struct mapped_index
*map
,
2954 const gdb_byte
**cu_list
,
2955 offset_type
*cu_list_elements
,
2956 const gdb_byte
**types_list
,
2957 offset_type
*types_list_elements
)
2959 const gdb_byte
*addr
= &buffer
[0];
2961 /* Version check. */
2962 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2963 /* Versions earlier than 3 emitted every copy of a psymbol. This
2964 causes the index to behave very poorly for certain requests. Version 3
2965 contained incomplete addrmap. So, it seems better to just ignore such
2969 static int warning_printed
= 0;
2970 if (!warning_printed
)
2972 warning (_("Skipping obsolete .gdb_index section in %s."),
2974 warning_printed
= 1;
2978 /* Index version 4 uses a different hash function than index version
2981 Versions earlier than 6 did not emit psymbols for inlined
2982 functions. Using these files will cause GDB not to be able to
2983 set breakpoints on inlined functions by name, so we ignore these
2984 indices unless the user has done
2985 "set use-deprecated-index-sections on". */
2986 if (version
< 6 && !deprecated_ok
)
2988 static int warning_printed
= 0;
2989 if (!warning_printed
)
2992 Skipping deprecated .gdb_index section in %s.\n\
2993 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2994 to use the section anyway."),
2996 warning_printed
= 1;
3000 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3001 of the TU (for symbols coming from TUs),
3002 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3003 Plus gold-generated indices can have duplicate entries for global symbols,
3004 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3005 These are just performance bugs, and we can't distinguish gdb-generated
3006 indices from gold-generated ones, so issue no warning here. */
3008 /* Indexes with higher version than the one supported by GDB may be no
3009 longer backward compatible. */
3013 map
->version
= version
;
3015 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3018 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3019 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3023 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3024 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3025 - MAYBE_SWAP (metadata
[i
]))
3029 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3030 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3032 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3035 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3036 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3038 = gdb::array_view
<mapped_index::symbol_table_slot
>
3039 ((mapped_index::symbol_table_slot
*) symbol_table
,
3040 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3043 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3048 /* Callback types for dwarf2_read_gdb_index. */
3050 typedef gdb::function_view
3051 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3052 get_gdb_index_contents_ftype
;
3053 typedef gdb::function_view
3054 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3055 get_gdb_index_contents_dwz_ftype
;
3057 /* Read .gdb_index. If everything went ok, initialize the "quick"
3058 elements of all the CUs and return 1. Otherwise, return 0. */
3061 dwarf2_read_gdb_index
3062 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3063 get_gdb_index_contents_ftype get_gdb_index_contents
,
3064 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3066 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3067 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3068 struct dwz_file
*dwz
;
3069 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3071 gdb::array_view
<const gdb_byte
> main_index_contents
3072 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
->per_bfd
);
3074 if (main_index_contents
.empty ())
3077 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3078 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3079 use_deprecated_index_sections
,
3080 main_index_contents
, map
.get (), &cu_list
,
3081 &cu_list_elements
, &types_list
,
3082 &types_list_elements
))
3085 /* Don't use the index if it's empty. */
3086 if (map
->symbol_table
.empty ())
3089 /* If there is a .dwz file, read it so we can get its CU list as
3091 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
3094 struct mapped_index dwz_map
;
3095 const gdb_byte
*dwz_types_ignore
;
3096 offset_type dwz_types_elements_ignore
;
3098 gdb::array_view
<const gdb_byte
> dwz_index_content
3099 = get_gdb_index_contents_dwz (objfile
, dwz
);
3101 if (dwz_index_content
.empty ())
3104 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3105 1, dwz_index_content
, &dwz_map
,
3106 &dwz_list
, &dwz_list_elements
,
3108 &dwz_types_elements_ignore
))
3110 warning (_("could not read '.gdb_index' section from %s; skipping"),
3111 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3116 create_cus_from_index (dwarf2_per_objfile
->per_bfd
, cu_list
, cu_list_elements
,
3117 dwz_list
, dwz_list_elements
);
3119 if (types_list_elements
)
3121 /* We can only handle a single .debug_types when we have an
3123 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
3126 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
3128 create_signatured_type_table_from_index (dwarf2_per_objfile
->per_bfd
,
3129 section
, types_list
,
3130 types_list_elements
);
3133 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3135 dwarf2_per_objfile
->per_bfd
->index_table
= std::move (map
);
3136 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
3137 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
3138 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
3143 /* die_reader_func for dw2_get_file_names. */
3146 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3147 const gdb_byte
*info_ptr
,
3148 struct die_info
*comp_unit_die
)
3150 struct dwarf2_cu
*cu
= reader
->cu
;
3151 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3152 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
3153 struct dwarf2_per_cu_data
*lh_cu
;
3154 struct attribute
*attr
;
3156 struct quick_file_names
*qfn
;
3158 gdb_assert (! this_cu
->is_debug_types
);
3160 /* Our callers never want to match partial units -- instead they
3161 will match the enclosing full CU. */
3162 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3164 this_cu
->v
.quick
->no_file_data
= 1;
3172 sect_offset line_offset
{};
3174 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3175 if (attr
!= nullptr)
3177 struct quick_file_names find_entry
;
3179 line_offset
= (sect_offset
) DW_UNSND (attr
);
3181 /* We may have already read in this line header (TU line header sharing).
3182 If we have we're done. */
3183 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3184 find_entry
.hash
.line_sect_off
= line_offset
;
3185 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3186 &find_entry
, INSERT
);
3189 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3193 lh
= dwarf_decode_line_header (line_offset
, cu
);
3197 lh_cu
->v
.quick
->no_file_data
= 1;
3201 qfn
= XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3202 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3203 qfn
->hash
.line_sect_off
= line_offset
;
3204 gdb_assert (slot
!= NULL
);
3207 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3210 if (strcmp (fnd
.name
, "<unknown>") != 0)
3213 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3215 XOBNEWVEC (&dwarf2_per_objfile
->per_bfd
->obstack
, const char *,
3216 qfn
->num_file_names
);
3218 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3219 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3220 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3221 fnd
.comp_dir
).release ();
3222 qfn
->real_names
= NULL
;
3224 lh_cu
->v
.quick
->file_names
= qfn
;
3227 /* A helper for the "quick" functions which attempts to read the line
3228 table for THIS_CU. */
3230 static struct quick_file_names
*
3231 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3232 dwarf2_per_objfile
*per_objfile
)
3234 /* This should never be called for TUs. */
3235 gdb_assert (! this_cu
->is_debug_types
);
3236 /* Nor type unit groups. */
3237 gdb_assert (! this_cu
->type_unit_group_p ());
3239 if (this_cu
->v
.quick
->file_names
!= NULL
)
3240 return this_cu
->v
.quick
->file_names
;
3241 /* If we know there is no line data, no point in looking again. */
3242 if (this_cu
->v
.quick
->no_file_data
)
3245 cutu_reader
reader (this_cu
, per_objfile
);
3246 if (!reader
.dummy_p
)
3247 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3249 if (this_cu
->v
.quick
->no_file_data
)
3251 return this_cu
->v
.quick
->file_names
;
3254 /* A helper for the "quick" functions which computes and caches the
3255 real path for a given file name from the line table. */
3258 dw2_get_real_path (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3259 struct quick_file_names
*qfn
, int index
)
3261 if (qfn
->real_names
== NULL
)
3262 qfn
->real_names
= OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
3263 qfn
->num_file_names
, const char *);
3265 if (qfn
->real_names
[index
] == NULL
)
3266 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3268 return qfn
->real_names
[index
];
3271 static struct symtab
*
3272 dw2_find_last_source_symtab (struct objfile
*objfile
)
3274 struct dwarf2_per_objfile
*dwarf2_per_objfile
3275 = get_dwarf2_per_objfile (objfile
);
3276 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->per_bfd
->all_comp_units
.back ();
3277 compunit_symtab
*cust
3278 = dw2_instantiate_symtab (dwarf_cu
, dwarf2_per_objfile
, false);
3283 return compunit_primary_filetab (cust
);
3286 /* Traversal function for dw2_forget_cached_source_info. */
3289 dw2_free_cached_file_names (void **slot
, void *info
)
3291 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3293 if (file_data
->real_names
)
3297 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3299 xfree ((void*) file_data
->real_names
[i
]);
3300 file_data
->real_names
[i
] = NULL
;
3308 dw2_forget_cached_source_info (struct objfile
*objfile
)
3310 struct dwarf2_per_objfile
*dwarf2_per_objfile
3311 = get_dwarf2_per_objfile (objfile
);
3313 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3314 dw2_free_cached_file_names
, NULL
);
3317 /* Helper function for dw2_map_symtabs_matching_filename that expands
3318 the symtabs and calls the iterator. */
3321 dw2_map_expand_apply (struct objfile
*objfile
,
3322 struct dwarf2_per_cu_data
*per_cu
,
3323 const char *name
, const char *real_path
,
3324 gdb::function_view
<bool (symtab
*)> callback
)
3326 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3328 /* Don't visit already-expanded CUs. */
3329 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3330 if (per_objfile
->symtab_set_p (per_cu
))
3333 /* This may expand more than one symtab, and we want to iterate over
3335 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3337 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3338 last_made
, callback
);
3341 /* Implementation of the map_symtabs_matching_filename method. */
3344 dw2_map_symtabs_matching_filename
3345 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3346 gdb::function_view
<bool (symtab
*)> callback
)
3348 const char *name_basename
= lbasename (name
);
3349 struct dwarf2_per_objfile
*dwarf2_per_objfile
3350 = get_dwarf2_per_objfile (objfile
);
3352 /* The rule is CUs specify all the files, including those used by
3353 any TU, so there's no need to scan TUs here. */
3355 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3357 /* We only need to look at symtabs not already expanded. */
3358 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3361 quick_file_names
*file_data
3362 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3363 if (file_data
== NULL
)
3366 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3368 const char *this_name
= file_data
->file_names
[j
];
3369 const char *this_real_name
;
3371 if (compare_filenames_for_search (this_name
, name
))
3373 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3379 /* Before we invoke realpath, which can get expensive when many
3380 files are involved, do a quick comparison of the basenames. */
3381 if (! basenames_may_differ
3382 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3385 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
3387 if (compare_filenames_for_search (this_real_name
, name
))
3389 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3395 if (real_path
!= NULL
)
3397 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3398 gdb_assert (IS_ABSOLUTE_PATH (name
));
3399 if (this_real_name
!= NULL
3400 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3402 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3414 /* Struct used to manage iterating over all CUs looking for a symbol. */
3416 struct dw2_symtab_iterator
3418 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3419 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3420 /* If set, only look for symbols that match that block. Valid values are
3421 GLOBAL_BLOCK and STATIC_BLOCK. */
3422 gdb::optional
<block_enum
> block_index
;
3423 /* The kind of symbol we're looking for. */
3425 /* The list of CUs from the index entry of the symbol,
3426 or NULL if not found. */
3428 /* The next element in VEC to look at. */
3430 /* The number of elements in VEC, or zero if there is no match. */
3432 /* Have we seen a global version of the symbol?
3433 If so we can ignore all further global instances.
3434 This is to work around gold/15646, inefficient gold-generated
3439 /* Initialize the index symtab iterator ITER. */
3442 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3443 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3444 gdb::optional
<block_enum
> block_index
,
3448 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3449 iter
->block_index
= block_index
;
3450 iter
->domain
= domain
;
3452 iter
->global_seen
= 0;
3454 mapped_index
*index
= dwarf2_per_objfile
->per_bfd
->index_table
.get ();
3456 /* index is NULL if OBJF_READNOW. */
3457 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3458 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3466 /* Return the next matching CU or NULL if there are no more. */
3468 static struct dwarf2_per_cu_data
*
3469 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3471 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3473 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3475 offset_type cu_index_and_attrs
=
3476 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3477 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3478 gdb_index_symbol_kind symbol_kind
=
3479 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3480 /* Only check the symbol attributes if they're present.
3481 Indices prior to version 7 don't record them,
3482 and indices >= 7 may elide them for certain symbols
3483 (gold does this). */
3485 (dwarf2_per_objfile
->per_bfd
->index_table
->version
>= 7
3486 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3488 /* Don't crash on bad data. */
3489 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3490 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
3492 complaint (_(".gdb_index entry has bad CU index"
3494 objfile_name (dwarf2_per_objfile
->objfile
));
3498 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
3500 /* Skip if already read in. */
3501 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3504 /* Check static vs global. */
3507 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3509 if (iter
->block_index
.has_value ())
3511 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3513 if (is_static
!= want_static
)
3517 /* Work around gold/15646. */
3518 if (!is_static
&& iter
->global_seen
)
3521 iter
->global_seen
= 1;
3524 /* Only check the symbol's kind if it has one. */
3527 switch (iter
->domain
)
3530 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3531 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3532 /* Some types are also in VAR_DOMAIN. */
3533 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3537 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3541 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3545 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3560 static struct compunit_symtab
*
3561 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3562 const char *name
, domain_enum domain
)
3564 struct compunit_symtab
*stab_best
= NULL
;
3565 struct dwarf2_per_objfile
*dwarf2_per_objfile
3566 = get_dwarf2_per_objfile (objfile
);
3568 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3570 struct dw2_symtab_iterator iter
;
3571 struct dwarf2_per_cu_data
*per_cu
;
3573 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3575 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3577 struct symbol
*sym
, *with_opaque
= NULL
;
3578 struct compunit_symtab
*stab
3579 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3580 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3581 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3583 sym
= block_find_symbol (block
, name
, domain
,
3584 block_find_non_opaque_type_preferred
,
3587 /* Some caution must be observed with overloaded functions
3588 and methods, since the index will not contain any overload
3589 information (but NAME might contain it). */
3592 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3594 if (with_opaque
!= NULL
3595 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3598 /* Keep looking through other CUs. */
3605 dw2_print_stats (struct objfile
*objfile
)
3607 struct dwarf2_per_objfile
*dwarf2_per_objfile
3608 = get_dwarf2_per_objfile (objfile
);
3609 int total
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3610 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3613 for (int i
= 0; i
< total
; ++i
)
3615 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3617 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
3620 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3621 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3624 /* This dumps minimal information about the index.
3625 It is called via "mt print objfiles".
3626 One use is to verify .gdb_index has been loaded by the
3627 gdb.dwarf2/gdb-index.exp testcase. */
3630 dw2_dump (struct objfile
*objfile
)
3632 struct dwarf2_per_objfile
*dwarf2_per_objfile
3633 = get_dwarf2_per_objfile (objfile
);
3635 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
3636 printf_filtered (".gdb_index:");
3637 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
)
3639 printf_filtered (" version %d\n",
3640 dwarf2_per_objfile
->per_bfd
->index_table
->version
);
3643 printf_filtered (" faked for \"readnow\"\n");
3644 printf_filtered ("\n");
3648 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3649 const char *func_name
)
3651 struct dwarf2_per_objfile
*dwarf2_per_objfile
3652 = get_dwarf2_per_objfile (objfile
);
3654 struct dw2_symtab_iterator iter
;
3655 struct dwarf2_per_cu_data
*per_cu
;
3657 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3659 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3660 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3665 dw2_expand_all_symtabs (struct objfile
*objfile
)
3667 struct dwarf2_per_objfile
*dwarf2_per_objfile
3668 = get_dwarf2_per_objfile (objfile
);
3669 int total_units
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3670 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3672 for (int i
= 0; i
< total_units
; ++i
)
3674 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3676 /* We don't want to directly expand a partial CU, because if we
3677 read it with the wrong language, then assertion failures can
3678 be triggered later on. See PR symtab/23010. So, tell
3679 dw2_instantiate_symtab to skip partial CUs -- any important
3680 partial CU will be read via DW_TAG_imported_unit anyway. */
3681 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, true);
3686 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3687 const char *fullname
)
3689 struct dwarf2_per_objfile
*dwarf2_per_objfile
3690 = get_dwarf2_per_objfile (objfile
);
3692 /* We don't need to consider type units here.
3693 This is only called for examining code, e.g. expand_line_sal.
3694 There can be an order of magnitude (or more) more type units
3695 than comp units, and we avoid them if we can. */
3697 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3699 /* We only need to look at symtabs not already expanded. */
3700 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3703 quick_file_names
*file_data
3704 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
3705 if (file_data
== NULL
)
3708 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3710 const char *this_fullname
= file_data
->file_names
[j
];
3712 if (filename_cmp (this_fullname
, fullname
) == 0)
3714 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
3722 dw2_expand_symtabs_matching_symbol
3723 (mapped_index_base
&index
,
3724 const lookup_name_info
&lookup_name_in
,
3725 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3726 enum search_domain kind
,
3727 gdb::function_view
<bool (offset_type
)> match_callback
,
3728 dwarf2_per_objfile
*per_objfile
);
3731 dw2_expand_symtabs_matching_one
3732 (dwarf2_per_cu_data
*per_cu
,
3733 dwarf2_per_objfile
*per_objfile
,
3734 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3735 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3738 dw2_map_matching_symbols
3739 (struct objfile
*objfile
,
3740 const lookup_name_info
&name
, domain_enum domain
,
3742 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3743 symbol_compare_ftype
*ordered_compare
)
3746 struct dwarf2_per_objfile
*dwarf2_per_objfile
3747 = get_dwarf2_per_objfile (objfile
);
3749 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3751 if (dwarf2_per_objfile
->per_bfd
->index_table
!= nullptr)
3753 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3754 here though if the current language is Ada for a non-Ada objfile
3756 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
3758 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3759 auto matcher
= [&] (const char *symname
)
3761 if (ordered_compare
== nullptr)
3763 return ordered_compare (symname
, match_name
) == 0;
3766 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3767 [&] (offset_type namei
)
3769 struct dw2_symtab_iterator iter
;
3770 struct dwarf2_per_cu_data
*per_cu
;
3772 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_kind
, domain
,
3774 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3775 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
3778 }, dwarf2_per_objfile
);
3782 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3783 proceed assuming all symtabs have been read in. */
3786 for (compunit_symtab
*cust
: objfile
->compunits ())
3788 const struct block
*block
;
3792 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3793 if (!iterate_over_symbols_terminated (block
, name
,
3799 /* Starting from a search name, return the string that finds the upper
3800 bound of all strings that start with SEARCH_NAME in a sorted name
3801 list. Returns the empty string to indicate that the upper bound is
3802 the end of the list. */
3805 make_sort_after_prefix_name (const char *search_name
)
3807 /* When looking to complete "func", we find the upper bound of all
3808 symbols that start with "func" by looking for where we'd insert
3809 the closest string that would follow "func" in lexicographical
3810 order. Usually, that's "func"-with-last-character-incremented,
3811 i.e. "fund". Mind non-ASCII characters, though. Usually those
3812 will be UTF-8 multi-byte sequences, but we can't be certain.
3813 Especially mind the 0xff character, which is a valid character in
3814 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3815 rule out compilers allowing it in identifiers. Note that
3816 conveniently, strcmp/strcasecmp are specified to compare
3817 characters interpreted as unsigned char. So what we do is treat
3818 the whole string as a base 256 number composed of a sequence of
3819 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3820 to 0, and carries 1 to the following more-significant position.
3821 If the very first character in SEARCH_NAME ends up incremented
3822 and carries/overflows, then the upper bound is the end of the
3823 list. The string after the empty string is also the empty
3826 Some examples of this operation:
3828 SEARCH_NAME => "+1" RESULT
3832 "\xff" "a" "\xff" => "\xff" "b"
3837 Then, with these symbols for example:
3843 completing "func" looks for symbols between "func" and
3844 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3845 which finds "func" and "func1", but not "fund".
3849 funcÿ (Latin1 'ÿ' [0xff])
3853 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3854 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3858 ÿÿ (Latin1 'ÿ' [0xff])
3861 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3862 the end of the list.
3864 std::string after
= search_name
;
3865 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3867 if (!after
.empty ())
3868 after
.back () = (unsigned char) after
.back () + 1;
3872 /* See declaration. */
3874 std::pair
<std::vector
<name_component
>::const_iterator
,
3875 std::vector
<name_component
>::const_iterator
>
3876 mapped_index_base::find_name_components_bounds
3877 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3878 dwarf2_per_objfile
*per_objfile
) const
3881 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3883 const char *lang_name
3884 = lookup_name_without_params
.language_lookup_name (lang
);
3886 /* Comparison function object for lower_bound that matches against a
3887 given symbol name. */
3888 auto lookup_compare_lower
= [&] (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 (elem_name
, name
) < 0;
3896 /* Comparison function object for upper_bound that matches against a
3897 given symbol name. */
3898 auto lookup_compare_upper
= [&] (const char *name
,
3899 const name_component
&elem
)
3901 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3902 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3903 return name_cmp (name
, elem_name
) < 0;
3906 auto begin
= this->name_components
.begin ();
3907 auto end
= this->name_components
.end ();
3909 /* Find the lower bound. */
3912 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3915 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3918 /* Find the upper bound. */
3921 if (lookup_name_without_params
.completion_mode ())
3923 /* In completion mode, we want UPPER to point past all
3924 symbols names that have the same prefix. I.e., with
3925 these symbols, and completing "func":
3927 function << lower bound
3929 other_function << upper bound
3931 We find the upper bound by looking for the insertion
3932 point of "func"-with-last-character-incremented,
3934 std::string after
= make_sort_after_prefix_name (lang_name
);
3937 return std::lower_bound (lower
, end
, after
.c_str (),
3938 lookup_compare_lower
);
3941 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3944 return {lower
, upper
};
3947 /* See declaration. */
3950 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3952 if (!this->name_components
.empty ())
3955 this->name_components_casing
= case_sensitivity
;
3957 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3959 /* The code below only knows how to break apart components of C++
3960 symbol names (and other languages that use '::' as
3961 namespace/module separator) and Ada symbol names. */
3962 auto count
= this->symbol_name_count ();
3963 for (offset_type idx
= 0; idx
< count
; idx
++)
3965 if (this->symbol_name_slot_invalid (idx
))
3968 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3970 /* Add each name component to the name component table. */
3971 unsigned int previous_len
= 0;
3973 if (strstr (name
, "::") != nullptr)
3975 for (unsigned int current_len
= cp_find_first_component (name
);
3976 name
[current_len
] != '\0';
3977 current_len
+= cp_find_first_component (name
+ current_len
))
3979 gdb_assert (name
[current_len
] == ':');
3980 this->name_components
.push_back ({previous_len
, idx
});
3981 /* Skip the '::'. */
3983 previous_len
= current_len
;
3988 /* Handle the Ada encoded (aka mangled) form here. */
3989 for (const char *iter
= strstr (name
, "__");
3991 iter
= strstr (iter
, "__"))
3993 this->name_components
.push_back ({previous_len
, idx
});
3995 previous_len
= iter
- name
;
3999 this->name_components
.push_back ({previous_len
, idx
});
4002 /* Sort name_components elements by name. */
4003 auto name_comp_compare
= [&] (const name_component
&left
,
4004 const name_component
&right
)
4006 const char *left_qualified
4007 = this->symbol_name_at (left
.idx
, per_objfile
);
4008 const char *right_qualified
4009 = this->symbol_name_at (right
.idx
, per_objfile
);
4011 const char *left_name
= left_qualified
+ left
.name_offset
;
4012 const char *right_name
= right_qualified
+ right
.name_offset
;
4014 return name_cmp (left_name
, right_name
) < 0;
4017 std::sort (this->name_components
.begin (),
4018 this->name_components
.end (),
4022 /* Helper for dw2_expand_symtabs_matching that works with a
4023 mapped_index_base instead of the containing objfile. This is split
4024 to a separate function in order to be able to unit test the
4025 name_components matching using a mock mapped_index_base. For each
4026 symbol name that matches, calls MATCH_CALLBACK, passing it the
4027 symbol's index in the mapped_index_base symbol table. */
4030 dw2_expand_symtabs_matching_symbol
4031 (mapped_index_base
&index
,
4032 const lookup_name_info
&lookup_name_in
,
4033 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4034 enum search_domain kind
,
4035 gdb::function_view
<bool (offset_type
)> match_callback
,
4036 dwarf2_per_objfile
*per_objfile
)
4038 lookup_name_info lookup_name_without_params
4039 = lookup_name_in
.make_ignore_params ();
4041 /* Build the symbol name component sorted vector, if we haven't
4043 index
.build_name_components (per_objfile
);
4045 /* The same symbol may appear more than once in the range though.
4046 E.g., if we're looking for symbols that complete "w", and we have
4047 a symbol named "w1::w2", we'll find the two name components for
4048 that same symbol in the range. To be sure we only call the
4049 callback once per symbol, we first collect the symbol name
4050 indexes that matched in a temporary vector and ignore
4052 std::vector
<offset_type
> matches
;
4054 struct name_and_matcher
4056 symbol_name_matcher_ftype
*matcher
;
4059 bool operator== (const name_and_matcher
&other
) const
4061 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4065 /* A vector holding all the different symbol name matchers, for all
4067 std::vector
<name_and_matcher
> matchers
;
4069 for (int i
= 0; i
< nr_languages
; i
++)
4071 enum language lang_e
= (enum language
) i
;
4073 const language_defn
*lang
= language_def (lang_e
);
4074 symbol_name_matcher_ftype
*name_matcher
4075 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4077 name_and_matcher key
{
4079 lookup_name_without_params
.language_lookup_name (lang_e
)
4082 /* Don't insert the same comparison routine more than once.
4083 Note that we do this linear walk. This is not a problem in
4084 practice because the number of supported languages is
4086 if (std::find (matchers
.begin (), matchers
.end (), key
)
4089 matchers
.push_back (std::move (key
));
4092 = index
.find_name_components_bounds (lookup_name_without_params
,
4093 lang_e
, per_objfile
);
4095 /* Now for each symbol name in range, check to see if we have a name
4096 match, and if so, call the MATCH_CALLBACK callback. */
4098 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4100 const char *qualified
4101 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4103 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4104 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4107 matches
.push_back (bounds
.first
->idx
);
4111 std::sort (matches
.begin (), matches
.end ());
4113 /* Finally call the callback, once per match. */
4115 for (offset_type idx
: matches
)
4119 if (!match_callback (idx
))
4125 /* Above we use a type wider than idx's for 'prev', since 0 and
4126 (offset_type)-1 are both possible values. */
4127 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4132 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4134 /* A mock .gdb_index/.debug_names-like name index table, enough to
4135 exercise dw2_expand_symtabs_matching_symbol, which works with the
4136 mapped_index_base interface. Builds an index from the symbol list
4137 passed as parameter to the constructor. */
4138 class mock_mapped_index
: public mapped_index_base
4141 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4142 : m_symbol_table (symbols
)
4145 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4147 /* Return the number of names in the symbol table. */
4148 size_t symbol_name_count () const override
4150 return m_symbol_table
.size ();
4153 /* Get the name of the symbol at IDX in the symbol table. */
4154 const char *symbol_name_at
4155 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4157 return m_symbol_table
[idx
];
4161 gdb::array_view
<const char *> m_symbol_table
;
4164 /* Convenience function that converts a NULL pointer to a "<null>"
4165 string, to pass to print routines. */
4168 string_or_null (const char *str
)
4170 return str
!= NULL
? str
: "<null>";
4173 /* Check if a lookup_name_info built from
4174 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4175 index. EXPECTED_LIST is the list of expected matches, in expected
4176 matching order. If no match expected, then an empty list is
4177 specified. Returns true on success. On failure prints a warning
4178 indicating the file:line that failed, and returns false. */
4181 check_match (const char *file
, int line
,
4182 mock_mapped_index
&mock_index
,
4183 const char *name
, symbol_name_match_type match_type
,
4184 bool completion_mode
,
4185 std::initializer_list
<const char *> expected_list
,
4186 dwarf2_per_objfile
*per_objfile
)
4188 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4190 bool matched
= true;
4192 auto mismatch
= [&] (const char *expected_str
,
4195 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4196 "expected=\"%s\", got=\"%s\"\n"),
4198 (match_type
== symbol_name_match_type::FULL
4200 name
, string_or_null (expected_str
), string_or_null (got
));
4204 auto expected_it
= expected_list
.begin ();
4205 auto expected_end
= expected_list
.end ();
4207 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4209 [&] (offset_type idx
)
4211 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4212 const char *expected_str
4213 = expected_it
== expected_end
? NULL
: *expected_it
++;
4215 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4216 mismatch (expected_str
, matched_name
);
4220 const char *expected_str
4221 = expected_it
== expected_end
? NULL
: *expected_it
++;
4222 if (expected_str
!= NULL
)
4223 mismatch (expected_str
, NULL
);
4228 /* The symbols added to the mock mapped_index for testing (in
4230 static const char *test_symbols
[] = {
4239 "ns2::tmpl<int>::foo2",
4240 "(anonymous namespace)::A::B::C",
4242 /* These are used to check that the increment-last-char in the
4243 matching algorithm for completion doesn't match "t1_fund" when
4244 completing "t1_func". */
4250 /* A UTF-8 name with multi-byte sequences to make sure that
4251 cp-name-parser understands this as a single identifier ("função"
4252 is "function" in PT). */
4255 /* \377 (0xff) is Latin1 'ÿ'. */
4258 /* \377 (0xff) is Latin1 'ÿ'. */
4262 /* A name with all sorts of complications. Starts with "z" to make
4263 it easier for the completion tests below. */
4264 #define Z_SYM_NAME \
4265 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4266 "::tuple<(anonymous namespace)::ui*, " \
4267 "std::default_delete<(anonymous namespace)::ui>, void>"
4272 /* Returns true if the mapped_index_base::find_name_component_bounds
4273 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4274 in completion mode. */
4277 check_find_bounds_finds (mapped_index_base
&index
,
4278 const char *search_name
,
4279 gdb::array_view
<const char *> expected_syms
,
4280 dwarf2_per_objfile
*per_objfile
)
4282 lookup_name_info
lookup_name (search_name
,
4283 symbol_name_match_type::FULL
, true);
4285 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4289 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4290 if (distance
!= expected_syms
.size ())
4293 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4295 auto nc_elem
= bounds
.first
+ exp_elem
;
4296 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4297 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4304 /* Test the lower-level mapped_index::find_name_component_bounds
4308 test_mapped_index_find_name_component_bounds ()
4310 mock_mapped_index
mock_index (test_symbols
);
4312 mock_index
.build_name_components (NULL
/* per_objfile */);
4314 /* Test the lower-level mapped_index::find_name_component_bounds
4315 method in completion mode. */
4317 static const char *expected_syms
[] = {
4322 SELF_CHECK (check_find_bounds_finds
4323 (mock_index
, "t1_func", expected_syms
,
4324 NULL
/* per_objfile */));
4327 /* Check that the increment-last-char in the name matching algorithm
4328 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4330 static const char *expected_syms1
[] = {
4334 SELF_CHECK (check_find_bounds_finds
4335 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4337 static const char *expected_syms2
[] = {
4340 SELF_CHECK (check_find_bounds_finds
4341 (mock_index
, "\377\377", expected_syms2
,
4342 NULL
/* per_objfile */));
4346 /* Test dw2_expand_symtabs_matching_symbol. */
4349 test_dw2_expand_symtabs_matching_symbol ()
4351 mock_mapped_index
mock_index (test_symbols
);
4353 /* We let all tests run until the end even if some fails, for debug
4355 bool any_mismatch
= false;
4357 /* Create the expected symbols list (an initializer_list). Needed
4358 because lists have commas, and we need to pass them to CHECK,
4359 which is a macro. */
4360 #define EXPECT(...) { __VA_ARGS__ }
4362 /* Wrapper for check_match that passes down the current
4363 __FILE__/__LINE__. */
4364 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4365 any_mismatch |= !check_match (__FILE__, __LINE__, \
4367 NAME, MATCH_TYPE, COMPLETION_MODE, \
4368 EXPECTED_LIST, NULL)
4370 /* Identity checks. */
4371 for (const char *sym
: test_symbols
)
4373 /* Should be able to match all existing symbols. */
4374 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4377 /* Should be able to match all existing symbols with
4379 std::string with_params
= std::string (sym
) + "(int)";
4380 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4383 /* Should be able to match all existing symbols with
4384 parameters and qualifiers. */
4385 with_params
= std::string (sym
) + " ( int ) const";
4386 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4389 /* This should really find sym, but cp-name-parser.y doesn't
4390 know about lvalue/rvalue qualifiers yet. */
4391 with_params
= std::string (sym
) + " ( int ) &&";
4392 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4396 /* Check that the name matching algorithm for completion doesn't get
4397 confused with Latin1 'ÿ' / 0xff. */
4399 static const char str
[] = "\377";
4400 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4401 EXPECT ("\377", "\377\377123"));
4404 /* Check that the increment-last-char in the matching algorithm for
4405 completion doesn't match "t1_fund" when completing "t1_func". */
4407 static const char str
[] = "t1_func";
4408 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4409 EXPECT ("t1_func", "t1_func1"));
4412 /* Check that completion mode works at each prefix of the expected
4415 static const char str
[] = "function(int)";
4416 size_t len
= strlen (str
);
4419 for (size_t i
= 1; i
< len
; i
++)
4421 lookup
.assign (str
, i
);
4422 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4423 EXPECT ("function"));
4427 /* While "w" is a prefix of both components, the match function
4428 should still only be called once. */
4430 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4432 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4436 /* Same, with a "complicated" symbol. */
4438 static const char str
[] = Z_SYM_NAME
;
4439 size_t len
= strlen (str
);
4442 for (size_t i
= 1; i
< len
; i
++)
4444 lookup
.assign (str
, i
);
4445 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4446 EXPECT (Z_SYM_NAME
));
4450 /* In FULL mode, an incomplete symbol doesn't match. */
4452 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4456 /* A complete symbol with parameters matches any overload, since the
4457 index has no overload info. */
4459 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4460 EXPECT ("std::zfunction", "std::zfunction2"));
4461 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4462 EXPECT ("std::zfunction", "std::zfunction2"));
4463 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4464 EXPECT ("std::zfunction", "std::zfunction2"));
4467 /* Check that whitespace is ignored appropriately. A symbol with a
4468 template argument list. */
4470 static const char expected
[] = "ns::foo<int>";
4471 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4473 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4477 /* Check that whitespace is ignored appropriately. A symbol with a
4478 template argument list that includes a pointer. */
4480 static const char expected
[] = "ns::foo<char*>";
4481 /* Try both completion and non-completion modes. */
4482 static const bool completion_mode
[2] = {false, true};
4483 for (size_t i
= 0; i
< 2; i
++)
4485 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4486 completion_mode
[i
], EXPECT (expected
));
4487 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4488 completion_mode
[i
], EXPECT (expected
));
4490 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4491 completion_mode
[i
], EXPECT (expected
));
4492 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4493 completion_mode
[i
], EXPECT (expected
));
4498 /* Check method qualifiers are ignored. */
4499 static const char expected
[] = "ns::foo<char*>";
4500 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4501 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4502 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4503 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4504 CHECK_MATCH ("foo < char * > ( int ) const",
4505 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4506 CHECK_MATCH ("foo < char * > ( int ) &&",
4507 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4510 /* Test lookup names that don't match anything. */
4512 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4515 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4519 /* Some wild matching tests, exercising "(anonymous namespace)",
4520 which should not be confused with a parameter list. */
4522 static const char *syms
[] = {
4526 "A :: B :: C ( int )",
4531 for (const char *s
: syms
)
4533 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4534 EXPECT ("(anonymous namespace)::A::B::C"));
4539 static const char expected
[] = "ns2::tmpl<int>::foo2";
4540 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4542 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4546 SELF_CHECK (!any_mismatch
);
4555 test_mapped_index_find_name_component_bounds ();
4556 test_dw2_expand_symtabs_matching_symbol ();
4559 }} // namespace selftests::dw2_expand_symtabs_matching
4561 #endif /* GDB_SELF_TEST */
4563 /* If FILE_MATCHER is NULL or if PER_CU has
4564 dwarf2_per_cu_quick_data::MARK set (see
4565 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4566 EXPANSION_NOTIFY on it. */
4569 dw2_expand_symtabs_matching_one
4570 (dwarf2_per_cu_data
*per_cu
,
4571 dwarf2_per_objfile
*per_objfile
,
4572 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4573 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4575 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4577 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4579 compunit_symtab
*symtab
4580 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4581 gdb_assert (symtab
!= nullptr);
4583 if (expansion_notify
!= NULL
&& symtab_was_null
)
4584 expansion_notify (symtab
);
4588 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4589 matched, to expand corresponding CUs that were marked. IDX is the
4590 index of the symbol name that matched. */
4593 dw2_expand_marked_cus
4594 (dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4595 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4596 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4599 offset_type
*vec
, vec_len
, vec_idx
;
4600 bool global_seen
= false;
4601 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4603 vec
= (offset_type
*) (index
.constant_pool
4604 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4605 vec_len
= MAYBE_SWAP (vec
[0]);
4606 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4608 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4609 /* This value is only valid for index versions >= 7. */
4610 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4611 gdb_index_symbol_kind symbol_kind
=
4612 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4613 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4614 /* Only check the symbol attributes if they're present.
4615 Indices prior to version 7 don't record them,
4616 and indices >= 7 may elide them for certain symbols
4617 (gold does this). */
4620 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4622 /* Work around gold/15646. */
4625 if (!is_static
&& global_seen
)
4631 /* Only check the symbol's kind if it has one. */
4636 case VARIABLES_DOMAIN
:
4637 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4640 case FUNCTIONS_DOMAIN
:
4641 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4645 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4648 case MODULES_DOMAIN
:
4649 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4657 /* Don't crash on bad data. */
4658 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
4659 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
4661 complaint (_(".gdb_index entry has bad CU index"
4663 objfile_name (dwarf2_per_objfile
->objfile
));
4667 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
4668 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, file_matcher
,
4673 /* If FILE_MATCHER is non-NULL, set all the
4674 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4675 that match FILE_MATCHER. */
4678 dw_expand_symtabs_matching_file_matcher
4679 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4680 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4682 if (file_matcher
== NULL
)
4685 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4687 NULL
, xcalloc
, xfree
));
4688 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4690 NULL
, xcalloc
, xfree
));
4692 /* The rule is CUs specify all the files, including those used by
4693 any TU, so there's no need to scan TUs here. */
4695 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4699 per_cu
->v
.quick
->mark
= 0;
4701 /* We only need to look at symtabs not already expanded. */
4702 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4705 quick_file_names
*file_data
4706 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4707 if (file_data
== NULL
)
4710 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4712 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4714 per_cu
->v
.quick
->mark
= 1;
4718 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4720 const char *this_real_name
;
4722 if (file_matcher (file_data
->file_names
[j
], false))
4724 per_cu
->v
.quick
->mark
= 1;
4728 /* Before we invoke realpath, which can get expensive when many
4729 files are involved, do a quick comparison of the basenames. */
4730 if (!basenames_may_differ
4731 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4735 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
4737 if (file_matcher (this_real_name
, false))
4739 per_cu
->v
.quick
->mark
= 1;
4744 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4745 ? visited_found
.get ()
4746 : visited_not_found
.get (),
4753 dw2_expand_symtabs_matching
4754 (struct objfile
*objfile
,
4755 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4756 const lookup_name_info
*lookup_name
,
4757 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4758 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4759 enum search_domain kind
)
4761 struct dwarf2_per_objfile
*dwarf2_per_objfile
4762 = get_dwarf2_per_objfile (objfile
);
4764 /* index_table is NULL if OBJF_READNOW. */
4765 if (!dwarf2_per_objfile
->per_bfd
->index_table
)
4768 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4770 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4772 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4776 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
4777 file_matcher
, expansion_notify
);
4782 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4784 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4786 kind
, [&] (offset_type idx
)
4788 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4789 expansion_notify
, kind
);
4791 }, dwarf2_per_objfile
);
4794 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4797 static struct compunit_symtab
*
4798 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4803 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4804 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4807 if (cust
->includes
== NULL
)
4810 for (i
= 0; cust
->includes
[i
]; ++i
)
4812 struct compunit_symtab
*s
= cust
->includes
[i
];
4814 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4822 static struct compunit_symtab
*
4823 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4824 struct bound_minimal_symbol msymbol
,
4826 struct obj_section
*section
,
4829 struct dwarf2_per_cu_data
*data
;
4830 struct compunit_symtab
*result
;
4832 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4835 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4836 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4837 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4841 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4842 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4843 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4844 paddress (objfile
->arch (), pc
));
4846 result
= recursively_find_pc_sect_compunit_symtab
4847 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4849 gdb_assert (result
!= NULL
);
4854 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4855 void *data
, int need_fullname
)
4857 struct dwarf2_per_objfile
*dwarf2_per_objfile
4858 = get_dwarf2_per_objfile (objfile
);
4860 if (!dwarf2_per_objfile
->per_bfd
->filenames_cache
)
4862 dwarf2_per_objfile
->per_bfd
->filenames_cache
.emplace ();
4864 htab_up
visited (htab_create_alloc (10,
4865 htab_hash_pointer
, htab_eq_pointer
,
4866 NULL
, xcalloc
, xfree
));
4868 /* The rule is CUs specify all the files, including those used
4869 by any TU, so there's no need to scan TUs here. We can
4870 ignore file names coming from already-expanded CUs. */
4872 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4874 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4876 void **slot
= htab_find_slot (visited
.get (),
4877 per_cu
->v
.quick
->file_names
,
4880 *slot
= per_cu
->v
.quick
->file_names
;
4884 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4886 /* We only need to look at symtabs not already expanded. */
4887 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4890 quick_file_names
*file_data
4891 = dw2_get_file_names (per_cu
, dwarf2_per_objfile
);
4892 if (file_data
== NULL
)
4895 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4898 /* Already visited. */
4903 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4905 const char *filename
= file_data
->file_names
[j
];
4906 dwarf2_per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4911 dwarf2_per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4913 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4916 this_real_name
= gdb_realpath (filename
);
4917 (*fun
) (filename
, this_real_name
.get (), data
);
4922 dw2_has_symbols (struct objfile
*objfile
)
4927 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4930 dw2_find_last_source_symtab
,
4931 dw2_forget_cached_source_info
,
4932 dw2_map_symtabs_matching_filename
,
4937 dw2_expand_symtabs_for_function
,
4938 dw2_expand_all_symtabs
,
4939 dw2_expand_symtabs_with_fullname
,
4940 dw2_map_matching_symbols
,
4941 dw2_expand_symtabs_matching
,
4942 dw2_find_pc_sect_compunit_symtab
,
4944 dw2_map_symbol_filenames
4947 /* DWARF-5 debug_names reader. */
4949 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4950 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4952 /* A helper function that reads the .debug_names section in SECTION
4953 and fills in MAP. FILENAME is the name of the file containing the
4954 section; it is used for error reporting.
4956 Returns true if all went well, false otherwise. */
4959 read_debug_names_from_section (struct objfile
*objfile
,
4960 const char *filename
,
4961 struct dwarf2_section_info
*section
,
4962 mapped_debug_names
&map
)
4964 if (section
->empty ())
4967 /* Older elfutils strip versions could keep the section in the main
4968 executable while splitting it for the separate debug info file. */
4969 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4972 section
->read (objfile
);
4974 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4976 const gdb_byte
*addr
= section
->buffer
;
4978 bfd
*const abfd
= section
->get_bfd_owner ();
4980 unsigned int bytes_read
;
4981 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4984 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4985 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4986 if (bytes_read
+ length
!= section
->size
)
4988 /* There may be multiple per-CU indices. */
4989 warning (_("Section .debug_names in %s length %s does not match "
4990 "section length %s, ignoring .debug_names."),
4991 filename
, plongest (bytes_read
+ length
),
4992 pulongest (section
->size
));
4996 /* The version number. */
4997 uint16_t version
= read_2_bytes (abfd
, addr
);
5001 warning (_("Section .debug_names in %s has unsupported version %d, "
5002 "ignoring .debug_names."),
5008 uint16_t padding
= read_2_bytes (abfd
, addr
);
5012 warning (_("Section .debug_names in %s has unsupported padding %d, "
5013 "ignoring .debug_names."),
5018 /* comp_unit_count - The number of CUs in the CU list. */
5019 map
.cu_count
= read_4_bytes (abfd
, addr
);
5022 /* local_type_unit_count - The number of TUs in the local TU
5024 map
.tu_count
= read_4_bytes (abfd
, addr
);
5027 /* foreign_type_unit_count - The number of TUs in the foreign TU
5029 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5031 if (foreign_tu_count
!= 0)
5033 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5034 "ignoring .debug_names."),
5035 filename
, static_cast<unsigned long> (foreign_tu_count
));
5039 /* bucket_count - The number of hash buckets in the hash lookup
5041 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5044 /* name_count - The number of unique names in the index. */
5045 map
.name_count
= read_4_bytes (abfd
, addr
);
5048 /* abbrev_table_size - The size in bytes of the abbreviations
5050 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5053 /* augmentation_string_size - The size in bytes of the augmentation
5054 string. This value is rounded up to a multiple of 4. */
5055 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5057 map
.augmentation_is_gdb
= ((augmentation_string_size
5058 == sizeof (dwarf5_augmentation
))
5059 && memcmp (addr
, dwarf5_augmentation
,
5060 sizeof (dwarf5_augmentation
)) == 0);
5061 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5062 addr
+= augmentation_string_size
;
5065 map
.cu_table_reordered
= addr
;
5066 addr
+= map
.cu_count
* map
.offset_size
;
5068 /* List of Local TUs */
5069 map
.tu_table_reordered
= addr
;
5070 addr
+= map
.tu_count
* map
.offset_size
;
5072 /* Hash Lookup Table */
5073 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5074 addr
+= map
.bucket_count
* 4;
5075 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5076 addr
+= map
.name_count
* 4;
5079 map
.name_table_string_offs_reordered
= addr
;
5080 addr
+= map
.name_count
* map
.offset_size
;
5081 map
.name_table_entry_offs_reordered
= addr
;
5082 addr
+= map
.name_count
* map
.offset_size
;
5084 const gdb_byte
*abbrev_table_start
= addr
;
5087 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5092 const auto insertpair
5093 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5094 if (!insertpair
.second
)
5096 warning (_("Section .debug_names in %s has duplicate index %s, "
5097 "ignoring .debug_names."),
5098 filename
, pulongest (index_num
));
5101 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5102 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5107 mapped_debug_names::index_val::attr attr
;
5108 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5110 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5112 if (attr
.form
== DW_FORM_implicit_const
)
5114 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5118 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5120 indexval
.attr_vec
.push_back (std::move (attr
));
5123 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5125 warning (_("Section .debug_names in %s has abbreviation_table "
5126 "of size %s vs. written as %u, ignoring .debug_names."),
5127 filename
, plongest (addr
- abbrev_table_start
),
5131 map
.entry_pool
= addr
;
5136 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5140 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5141 const mapped_debug_names
&map
,
5142 dwarf2_section_info
§ion
,
5145 if (!map
.augmentation_is_gdb
)
5147 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5149 sect_offset sect_off
5150 = (sect_offset
) (extract_unsigned_integer
5151 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5153 map
.dwarf5_byte_order
));
5154 /* We don't know the length of the CU, because the CU list in a
5155 .debug_names index can be incomplete, so we can't use the start of
5156 the next CU as end of this CU. We create the CUs here with length 0,
5157 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5158 dwarf2_per_cu_data
*per_cu
5159 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5160 per_bfd
->all_comp_units
.push_back (per_cu
);
5164 sect_offset sect_off_prev
;
5165 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5167 sect_offset sect_off_next
;
5168 if (i
< map
.cu_count
)
5171 = (sect_offset
) (extract_unsigned_integer
5172 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5174 map
.dwarf5_byte_order
));
5177 sect_off_next
= (sect_offset
) section
.size
;
5180 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5181 dwarf2_per_cu_data
*per_cu
5182 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5183 sect_off_prev
, length
);
5184 per_bfd
->all_comp_units
.push_back (per_cu
);
5186 sect_off_prev
= sect_off_next
;
5190 /* Read the CU list from the mapped index, and use it to create all
5191 the CU objects for this dwarf2_per_objfile. */
5194 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5195 const mapped_debug_names
&map
,
5196 const mapped_debug_names
&dwz_map
)
5198 gdb_assert (per_bfd
->all_comp_units
.empty ());
5199 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5201 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5202 false /* is_dwz */);
5204 if (dwz_map
.cu_count
== 0)
5207 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5208 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5212 /* Read .debug_names. If everything went ok, initialize the "quick"
5213 elements of all the CUs and return true. Otherwise, return false. */
5216 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5218 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5219 mapped_debug_names dwz_map
;
5220 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5222 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5223 &dwarf2_per_objfile
->per_bfd
->debug_names
,
5227 /* Don't use the index if it's empty. */
5228 if (map
->name_count
== 0)
5231 /* If there is a .dwz file, read it so we can get its CU list as
5233 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
5236 if (!read_debug_names_from_section (objfile
,
5237 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5238 &dwz
->debug_names
, dwz_map
))
5240 warning (_("could not read '.debug_names' section from %s; skipping"),
5241 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5246 create_cus_from_debug_names (dwarf2_per_objfile
->per_bfd
, *map
, dwz_map
);
5248 if (map
->tu_count
!= 0)
5250 /* We can only handle a single .debug_types when we have an
5252 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
5255 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
5257 create_signatured_type_table_from_debug_names
5258 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->per_bfd
->abbrev
);
5261 create_addrmap_from_aranges (dwarf2_per_objfile
,
5262 &dwarf2_per_objfile
->per_bfd
->debug_aranges
);
5264 dwarf2_per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5265 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5266 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
5267 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5272 /* Type used to manage iterating over all CUs looking for a symbol for
5275 class dw2_debug_names_iterator
5278 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5279 gdb::optional
<block_enum
> block_index
,
5281 const char *name
, dwarf2_per_objfile
*per_objfile
)
5282 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5283 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5284 m_per_objfile (per_objfile
)
5287 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5288 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5291 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5292 m_per_objfile (per_objfile
)
5295 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5296 block_enum block_index
, domain_enum domain
,
5297 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5298 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5299 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5300 m_per_objfile (per_objfile
)
5303 /* Return the next matching CU or NULL if there are no more. */
5304 dwarf2_per_cu_data
*next ();
5307 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5308 const char *name
, dwarf2_per_objfile
*per_objfile
);
5309 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5310 uint32_t namei
, dwarf2_per_objfile
*per_objfile
);
5312 /* The internalized form of .debug_names. */
5313 const mapped_debug_names
&m_map
;
5315 /* If set, only look for symbols that match that block. Valid values are
5316 GLOBAL_BLOCK and STATIC_BLOCK. */
5317 const gdb::optional
<block_enum
> m_block_index
;
5319 /* The kind of symbol we're looking for. */
5320 const domain_enum m_domain
= UNDEF_DOMAIN
;
5321 const search_domain m_search
= ALL_DOMAIN
;
5323 /* The list of CUs from the index entry of the symbol, or NULL if
5325 const gdb_byte
*m_addr
;
5327 dwarf2_per_objfile
*m_per_objfile
;
5331 mapped_debug_names::namei_to_name
5332 (uint32_t namei
, dwarf2_per_objfile
*dwarf2_per_objfile
) const
5334 const ULONGEST namei_string_offs
5335 = extract_unsigned_integer ((name_table_string_offs_reordered
5336 + namei
* offset_size
),
5339 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5343 /* Find a slot in .debug_names for the object named NAME. If NAME is
5344 found, return pointer to its pool data. If NAME cannot be found,
5348 dw2_debug_names_iterator::find_vec_in_debug_names
5349 (const mapped_debug_names
&map
, const char *name
, dwarf2_per_objfile
*per_objfile
)
5351 int (*cmp
) (const char *, const char *);
5353 gdb::unique_xmalloc_ptr
<char> without_params
;
5354 if (current_language
->la_language
== language_cplus
5355 || current_language
->la_language
== language_fortran
5356 || current_language
->la_language
== language_d
)
5358 /* NAME is already canonical. Drop any qualifiers as
5359 .debug_names does not contain any. */
5361 if (strchr (name
, '(') != NULL
)
5363 without_params
= cp_remove_params (name
);
5364 if (without_params
!= NULL
)
5365 name
= without_params
.get ();
5369 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5371 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5373 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5374 (map
.bucket_table_reordered
5375 + (full_hash
% map
.bucket_count
)), 4,
5376 map
.dwarf5_byte_order
);
5380 if (namei
>= map
.name_count
)
5382 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5384 namei
, map
.name_count
,
5385 objfile_name (per_objfile
->objfile
));
5391 const uint32_t namei_full_hash
5392 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5393 (map
.hash_table_reordered
+ namei
), 4,
5394 map
.dwarf5_byte_order
);
5395 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5398 if (full_hash
== namei_full_hash
)
5400 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5402 #if 0 /* An expensive sanity check. */
5403 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5405 complaint (_("Wrong .debug_names hash for string at index %u "
5407 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5412 if (cmp (namei_string
, name
) == 0)
5414 const ULONGEST namei_entry_offs
5415 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5416 + namei
* map
.offset_size
),
5417 map
.offset_size
, map
.dwarf5_byte_order
);
5418 return map
.entry_pool
+ namei_entry_offs
;
5423 if (namei
>= map
.name_count
)
5429 dw2_debug_names_iterator::find_vec_in_debug_names
5430 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5432 if (namei
>= map
.name_count
)
5434 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5436 namei
, map
.name_count
,
5437 objfile_name (per_objfile
->objfile
));
5441 const ULONGEST namei_entry_offs
5442 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5443 + namei
* map
.offset_size
),
5444 map
.offset_size
, map
.dwarf5_byte_order
);
5445 return map
.entry_pool
+ namei_entry_offs
;
5448 /* See dw2_debug_names_iterator. */
5450 dwarf2_per_cu_data
*
5451 dw2_debug_names_iterator::next ()
5456 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5457 struct objfile
*objfile
= m_per_objfile
->objfile
;
5458 bfd
*const abfd
= objfile
->obfd
;
5462 unsigned int bytes_read
;
5463 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5464 m_addr
+= bytes_read
;
5468 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5469 if (indexval_it
== m_map
.abbrev_map
.cend ())
5471 complaint (_("Wrong .debug_names undefined abbrev code %s "
5473 pulongest (abbrev
), objfile_name (objfile
));
5476 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5477 enum class symbol_linkage
{
5481 } symbol_linkage_
= symbol_linkage::unknown
;
5482 dwarf2_per_cu_data
*per_cu
= NULL
;
5483 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5488 case DW_FORM_implicit_const
:
5489 ull
= attr
.implicit_const
;
5491 case DW_FORM_flag_present
:
5495 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5496 m_addr
+= bytes_read
;
5499 ull
= read_4_bytes (abfd
, m_addr
);
5503 ull
= read_8_bytes (abfd
, m_addr
);
5506 case DW_FORM_ref_sig8
:
5507 ull
= read_8_bytes (abfd
, m_addr
);
5511 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5512 dwarf_form_name (attr
.form
),
5513 objfile_name (objfile
));
5516 switch (attr
.dw_idx
)
5518 case DW_IDX_compile_unit
:
5519 /* Don't crash on bad data. */
5520 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5522 complaint (_(".debug_names entry has bad CU index %s"
5525 objfile_name (objfile
));
5528 per_cu
= per_bfd
->get_cutu (ull
);
5530 case DW_IDX_type_unit
:
5531 /* Don't crash on bad data. */
5532 if (ull
>= per_bfd
->all_type_units
.size ())
5534 complaint (_(".debug_names entry has bad TU index %s"
5537 objfile_name (objfile
));
5540 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5542 case DW_IDX_die_offset
:
5543 /* In a per-CU index (as opposed to a per-module index), index
5544 entries without CU attribute implicitly refer to the single CU. */
5546 per_cu
= per_bfd
->get_cu (0);
5548 case DW_IDX_GNU_internal
:
5549 if (!m_map
.augmentation_is_gdb
)
5551 symbol_linkage_
= symbol_linkage::static_
;
5553 case DW_IDX_GNU_external
:
5554 if (!m_map
.augmentation_is_gdb
)
5556 symbol_linkage_
= symbol_linkage::extern_
;
5561 /* Skip if already read in. */
5562 if (m_per_objfile
->symtab_set_p (per_cu
))
5565 /* Check static vs global. */
5566 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5568 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5569 const bool symbol_is_static
=
5570 symbol_linkage_
== symbol_linkage::static_
;
5571 if (want_static
!= symbol_is_static
)
5575 /* Match dw2_symtab_iter_next, symbol_kind
5576 and debug_names::psymbol_tag. */
5580 switch (indexval
.dwarf_tag
)
5582 case DW_TAG_variable
:
5583 case DW_TAG_subprogram
:
5584 /* Some types are also in VAR_DOMAIN. */
5585 case DW_TAG_typedef
:
5586 case DW_TAG_structure_type
:
5593 switch (indexval
.dwarf_tag
)
5595 case DW_TAG_typedef
:
5596 case DW_TAG_structure_type
:
5603 switch (indexval
.dwarf_tag
)
5606 case DW_TAG_variable
:
5613 switch (indexval
.dwarf_tag
)
5625 /* Match dw2_expand_symtabs_matching, symbol_kind and
5626 debug_names::psymbol_tag. */
5629 case VARIABLES_DOMAIN
:
5630 switch (indexval
.dwarf_tag
)
5632 case DW_TAG_variable
:
5638 case FUNCTIONS_DOMAIN
:
5639 switch (indexval
.dwarf_tag
)
5641 case DW_TAG_subprogram
:
5648 switch (indexval
.dwarf_tag
)
5650 case DW_TAG_typedef
:
5651 case DW_TAG_structure_type
:
5657 case MODULES_DOMAIN
:
5658 switch (indexval
.dwarf_tag
)
5672 static struct compunit_symtab
*
5673 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5674 const char *name
, domain_enum domain
)
5676 struct dwarf2_per_objfile
*dwarf2_per_objfile
5677 = get_dwarf2_per_objfile (objfile
);
5679 const auto &mapp
= dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5682 /* index is NULL if OBJF_READNOW. */
5685 const auto &map
= *mapp
;
5687 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
,
5688 dwarf2_per_objfile
);
5690 struct compunit_symtab
*stab_best
= NULL
;
5691 struct dwarf2_per_cu_data
*per_cu
;
5692 while ((per_cu
= iter
.next ()) != NULL
)
5694 struct symbol
*sym
, *with_opaque
= NULL
;
5695 compunit_symtab
*stab
5696 = dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5697 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5698 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5700 sym
= block_find_symbol (block
, name
, domain
,
5701 block_find_non_opaque_type_preferred
,
5704 /* Some caution must be observed with overloaded functions and
5705 methods, since the index will not contain any overload
5706 information (but NAME might contain it). */
5709 && strcmp_iw (sym
->search_name (), name
) == 0)
5711 if (with_opaque
!= NULL
5712 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5715 /* Keep looking through other CUs. */
5721 /* This dumps minimal information about .debug_names. It is called
5722 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5723 uses this to verify that .debug_names has been loaded. */
5726 dw2_debug_names_dump (struct objfile
*objfile
)
5728 struct dwarf2_per_objfile
*dwarf2_per_objfile
5729 = get_dwarf2_per_objfile (objfile
);
5731 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
5732 printf_filtered (".debug_names:");
5733 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5734 printf_filtered (" exists\n");
5736 printf_filtered (" faked for \"readnow\"\n");
5737 printf_filtered ("\n");
5741 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5742 const char *func_name
)
5744 struct dwarf2_per_objfile
*dwarf2_per_objfile
5745 = get_dwarf2_per_objfile (objfile
);
5747 /* dwarf2_per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5748 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5750 const mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5752 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5753 dwarf2_per_objfile
);
5755 struct dwarf2_per_cu_data
*per_cu
;
5756 while ((per_cu
= iter
.next ()) != NULL
)
5757 dw2_instantiate_symtab (per_cu
, dwarf2_per_objfile
, false);
5762 dw2_debug_names_map_matching_symbols
5763 (struct objfile
*objfile
,
5764 const lookup_name_info
&name
, domain_enum domain
,
5766 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5767 symbol_compare_ftype
*ordered_compare
)
5769 struct dwarf2_per_objfile
*dwarf2_per_objfile
5770 = get_dwarf2_per_objfile (objfile
);
5772 /* debug_names_table is NULL if OBJF_READNOW. */
5773 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5776 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5777 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5779 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5780 auto matcher
= [&] (const char *symname
)
5782 if (ordered_compare
== nullptr)
5784 return ordered_compare (symname
, match_name
) == 0;
5787 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5788 [&] (offset_type namei
)
5790 /* The name was matched, now expand corresponding CUs that were
5792 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5793 dwarf2_per_objfile
);
5795 struct dwarf2_per_cu_data
*per_cu
;
5796 while ((per_cu
= iter
.next ()) != NULL
)
5797 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
, nullptr,
5800 }, dwarf2_per_objfile
);
5802 /* It's a shame we couldn't do this inside the
5803 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5804 that have already been expanded. Instead, this loop matches what
5805 the psymtab code does. */
5806 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5808 compunit_symtab
*symtab
= dwarf2_per_objfile
->get_symtab (per_cu
);
5809 if (symtab
!= nullptr)
5811 const struct block
*block
5812 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5813 if (!iterate_over_symbols_terminated (block
, name
,
5821 dw2_debug_names_expand_symtabs_matching
5822 (struct objfile
*objfile
,
5823 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5824 const lookup_name_info
*lookup_name
,
5825 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5826 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5827 enum search_domain kind
)
5829 struct dwarf2_per_objfile
*dwarf2_per_objfile
5830 = get_dwarf2_per_objfile (objfile
);
5832 /* debug_names_table is NULL if OBJF_READNOW. */
5833 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5836 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5838 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5840 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5844 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5845 file_matcher
, expansion_notify
);
5850 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5852 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5854 kind
, [&] (offset_type namei
)
5856 /* The name was matched, now expand corresponding CUs that were
5858 dw2_debug_names_iterator
iter (map
, kind
, namei
, dwarf2_per_objfile
);
5860 struct dwarf2_per_cu_data
*per_cu
;
5861 while ((per_cu
= iter
.next ()) != NULL
)
5862 dw2_expand_symtabs_matching_one (per_cu
, dwarf2_per_objfile
,
5863 file_matcher
, expansion_notify
);
5865 }, dwarf2_per_objfile
);
5868 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5871 dw2_find_last_source_symtab
,
5872 dw2_forget_cached_source_info
,
5873 dw2_map_symtabs_matching_filename
,
5874 dw2_debug_names_lookup_symbol
,
5877 dw2_debug_names_dump
,
5878 dw2_debug_names_expand_symtabs_for_function
,
5879 dw2_expand_all_symtabs
,
5880 dw2_expand_symtabs_with_fullname
,
5881 dw2_debug_names_map_matching_symbols
,
5882 dw2_debug_names_expand_symtabs_matching
,
5883 dw2_find_pc_sect_compunit_symtab
,
5885 dw2_map_symbol_filenames
5888 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5889 to either a dwarf2_per_bfd or dwz_file object. */
5891 template <typename T
>
5892 static gdb::array_view
<const gdb_byte
>
5893 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5895 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5897 if (section
->empty ())
5900 /* Older elfutils strip versions could keep the section in the main
5901 executable while splitting it for the separate debug info file. */
5902 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5905 section
->read (obj
);
5907 /* dwarf2_section_info::size is a bfd_size_type, while
5908 gdb::array_view works with size_t. On 32-bit hosts, with
5909 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5910 is 32-bit. So we need an explicit narrowing conversion here.
5911 This is fine, because it's impossible to allocate or mmap an
5912 array/buffer larger than what size_t can represent. */
5913 return gdb::make_array_view (section
->buffer
, section
->size
);
5916 /* Lookup the index cache for the contents of the index associated to
5919 static gdb::array_view
<const gdb_byte
>
5920 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5922 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5923 if (build_id
== nullptr)
5926 return global_index_cache
.lookup_gdb_index (build_id
,
5927 &dwarf2_per_bfd
->index_cache_res
);
5930 /* Same as the above, but for DWZ. */
5932 static gdb::array_view
<const gdb_byte
>
5933 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5935 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5936 if (build_id
== nullptr)
5939 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5942 /* See symfile.h. */
5945 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5947 struct dwarf2_per_objfile
*dwarf2_per_objfile
5948 = get_dwarf2_per_objfile (objfile
);
5949 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
5951 /* If we're about to read full symbols, don't bother with the
5952 indices. In this case we also don't care if some other debug
5953 format is making psymtabs, because they are all about to be
5955 if ((objfile
->flags
& OBJF_READNOW
))
5957 /* When using READNOW, the using_index flag (set below) indicates that
5958 PER_BFD was already initialized, when we loaded some other objfile. */
5959 if (per_bfd
->using_index
)
5961 *index_kind
= dw_index_kind::GDB_INDEX
;
5962 dwarf2_per_objfile
->resize_symtabs ();
5966 per_bfd
->using_index
= 1;
5967 create_all_comp_units (dwarf2_per_objfile
);
5968 create_all_type_units (dwarf2_per_objfile
);
5969 per_bfd
->quick_file_names_table
5970 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5971 dwarf2_per_objfile
->resize_symtabs ();
5973 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
5974 + per_bfd
->all_type_units
.size ()); ++i
)
5976 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
5978 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5979 struct dwarf2_per_cu_quick_data
);
5982 /* Return 1 so that gdb sees the "quick" functions. However,
5983 these functions will be no-ops because we will have expanded
5985 *index_kind
= dw_index_kind::GDB_INDEX
;
5989 /* Was a debug names index already read when we processed an objfile sharing
5991 if (per_bfd
->debug_names_table
!= nullptr)
5993 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5994 dwarf2_per_objfile
->resize_symtabs ();
5998 /* Was a GDB index already read when we processed an objfile sharing
6000 if (per_bfd
->index_table
!= nullptr)
6002 *index_kind
= dw_index_kind::GDB_INDEX
;
6003 dwarf2_per_objfile
->resize_symtabs ();
6007 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6009 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6010 dwarf2_per_objfile
->resize_symtabs ();
6014 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6015 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6016 get_gdb_index_contents_from_section
<dwz_file
>))
6018 *index_kind
= dw_index_kind::GDB_INDEX
;
6019 dwarf2_per_objfile
->resize_symtabs ();
6023 /* ... otherwise, try to find the index in the index cache. */
6024 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6025 get_gdb_index_contents_from_cache
,
6026 get_gdb_index_contents_from_cache_dwz
))
6028 global_index_cache
.hit ();
6029 *index_kind
= dw_index_kind::GDB_INDEX
;
6030 dwarf2_per_objfile
->resize_symtabs ();
6034 global_index_cache
.miss ();
6040 /* Build a partial symbol table. */
6043 dwarf2_build_psymtabs (struct objfile
*objfile
)
6045 struct dwarf2_per_objfile
*dwarf2_per_objfile
6046 = get_dwarf2_per_objfile (objfile
);
6047 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
6049 if (per_bfd
->partial_symtabs
!= nullptr)
6051 /* Partial symbols were already read, so now we can simply
6053 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6054 dwarf2_per_objfile
->resize_symtabs ();
6058 init_psymbol_list (objfile
, 1024);
6062 /* This isn't really ideal: all the data we allocate on the
6063 objfile's obstack is still uselessly kept around. However,
6064 freeing it seems unsafe. */
6065 psymtab_discarder
psymtabs (objfile
);
6066 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6069 dwarf2_per_objfile
->resize_symtabs ();
6071 /* (maybe) store an index in the cache. */
6072 global_index_cache
.store (dwarf2_per_objfile
);
6074 catch (const gdb_exception_error
&except
)
6076 exception_print (gdb_stderr
, except
);
6079 /* Finish by setting the local reference to partial symtabs, so that
6080 we don't try to read them again if reading another objfile with the same
6081 BFD. If we can't in fact share, this won't make a difference anyway as
6082 the dwarf2_per_bfd object won't be shared. */
6083 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6086 /* Find the base address of the compilation unit for range lists and
6087 location lists. It will normally be specified by DW_AT_low_pc.
6088 In DWARF-3 draft 4, the base address could be overridden by
6089 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6090 compilation units with discontinuous ranges. */
6093 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6095 struct attribute
*attr
;
6097 cu
->base_address
.reset ();
6099 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6100 if (attr
!= nullptr)
6101 cu
->base_address
= attr
->value_as_address ();
6104 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6105 if (attr
!= nullptr)
6106 cu
->base_address
= attr
->value_as_address ();
6110 /* Helper function that returns the proper abbrev section for
6113 static struct dwarf2_section_info
*
6114 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6116 struct dwarf2_section_info
*abbrev
;
6117 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6119 if (this_cu
->is_dwz
)
6120 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6122 abbrev
= &per_bfd
->abbrev
;
6127 /* Fetch the abbreviation table offset from a comp or type unit header. */
6130 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6131 struct dwarf2_section_info
*section
,
6132 sect_offset sect_off
)
6134 bfd
*abfd
= section
->get_bfd_owner ();
6135 const gdb_byte
*info_ptr
;
6136 unsigned int initial_length_size
, offset_size
;
6139 section
->read (dwarf2_per_objfile
->objfile
);
6140 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6141 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6142 offset_size
= initial_length_size
== 4 ? 4 : 8;
6143 info_ptr
+= initial_length_size
;
6145 version
= read_2_bytes (abfd
, info_ptr
);
6149 /* Skip unit type and address size. */
6153 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6156 /* A partial symtab that is used only for include files. */
6157 struct dwarf2_include_psymtab
: public partial_symtab
6159 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6160 : partial_symtab (filename
, objfile
)
6164 void read_symtab (struct objfile
*objfile
) override
6166 /* It's an include file, no symbols to read for it.
6167 Everything is in the includer symtab. */
6169 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6170 expansion of the includer psymtab. We use the dependencies[0] field to
6171 model the includer. But if we go the regular route of calling
6172 expand_psymtab here, and having expand_psymtab call expand_dependencies
6173 to expand the includer, we'll only use expand_psymtab on the includer
6174 (making it a non-toplevel psymtab), while if we expand the includer via
6175 another path, we'll use read_symtab (making it a toplevel psymtab).
6176 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6177 psymtab, and trigger read_symtab on the includer here directly. */
6178 includer ()->read_symtab (objfile
);
6181 void expand_psymtab (struct objfile
*objfile
) override
6183 /* This is not called by read_symtab, and should not be called by any
6184 expand_dependencies. */
6188 bool readin_p (struct objfile
*objfile
) const override
6190 return includer ()->readin_p (objfile
);
6193 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6199 partial_symtab
*includer () const
6201 /* An include psymtab has exactly one dependency: the psymtab that
6203 gdb_assert (this->number_of_dependencies
== 1);
6204 return this->dependencies
[0];
6208 /* Allocate a new partial symtab for file named NAME and mark this new
6209 partial symtab as being an include of PST. */
6212 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6213 struct objfile
*objfile
)
6215 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6217 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6218 subpst
->dirname
= pst
->dirname
;
6220 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6221 subpst
->dependencies
[0] = pst
;
6222 subpst
->number_of_dependencies
= 1;
6225 /* Read the Line Number Program data and extract the list of files
6226 included by the source file represented by PST. Build an include
6227 partial symtab for each of these included files. */
6230 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6231 struct die_info
*die
,
6232 dwarf2_psymtab
*pst
)
6235 struct attribute
*attr
;
6237 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6238 if (attr
!= nullptr)
6239 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6241 return; /* No linetable, so no includes. */
6243 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6244 that we pass in the raw text_low here; that is ok because we're
6245 only decoding the line table to make include partial symtabs, and
6246 so the addresses aren't really used. */
6247 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6248 pst
->raw_text_low (), 1);
6252 hash_signatured_type (const void *item
)
6254 const struct signatured_type
*sig_type
6255 = (const struct signatured_type
*) item
;
6257 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6258 return sig_type
->signature
;
6262 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6264 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6265 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6267 return lhs
->signature
== rhs
->signature
;
6270 /* Allocate a hash table for signatured types. */
6273 allocate_signatured_type_table ()
6275 return htab_up (htab_create_alloc (41,
6276 hash_signatured_type
,
6278 NULL
, xcalloc
, xfree
));
6281 /* A helper function to add a signatured type CU to a table. */
6284 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6286 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6287 std::vector
<signatured_type
*> *all_type_units
6288 = (std::vector
<signatured_type
*> *) datum
;
6290 all_type_units
->push_back (sigt
);
6295 /* A helper for create_debug_types_hash_table. Read types from SECTION
6296 and fill them into TYPES_HTAB. It will process only type units,
6297 therefore DW_UT_type. */
6300 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6301 struct dwo_file
*dwo_file
,
6302 dwarf2_section_info
*section
, htab_up
&types_htab
,
6303 rcuh_kind section_kind
)
6305 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6306 struct dwarf2_section_info
*abbrev_section
;
6308 const gdb_byte
*info_ptr
, *end_ptr
;
6310 abbrev_section
= (dwo_file
!= NULL
6311 ? &dwo_file
->sections
.abbrev
6312 : &dwarf2_per_objfile
->per_bfd
->abbrev
);
6314 if (dwarf_read_debug
)
6315 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6316 section
->get_name (),
6317 abbrev_section
->get_file_name ());
6319 section
->read (objfile
);
6320 info_ptr
= section
->buffer
;
6322 if (info_ptr
== NULL
)
6325 /* We can't set abfd until now because the section may be empty or
6326 not present, in which case the bfd is unknown. */
6327 abfd
= section
->get_bfd_owner ();
6329 /* We don't use cutu_reader here because we don't need to read
6330 any dies: the signature is in the header. */
6332 end_ptr
= info_ptr
+ section
->size
;
6333 while (info_ptr
< end_ptr
)
6335 struct signatured_type
*sig_type
;
6336 struct dwo_unit
*dwo_tu
;
6338 const gdb_byte
*ptr
= info_ptr
;
6339 struct comp_unit_head header
;
6340 unsigned int length
;
6342 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6344 /* Initialize it due to a false compiler warning. */
6345 header
.signature
= -1;
6346 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6348 /* We need to read the type's signature in order to build the hash
6349 table, but we don't need anything else just yet. */
6351 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6352 abbrev_section
, ptr
, section_kind
);
6354 length
= header
.get_length ();
6356 /* Skip dummy type units. */
6357 if (ptr
>= info_ptr
+ length
6358 || peek_abbrev_code (abfd
, ptr
) == 0
6359 || header
.unit_type
!= DW_UT_type
)
6365 if (types_htab
== NULL
)
6368 types_htab
= allocate_dwo_unit_table ();
6370 types_htab
= allocate_signatured_type_table ();
6376 dwo_tu
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6378 dwo_tu
->dwo_file
= dwo_file
;
6379 dwo_tu
->signature
= header
.signature
;
6380 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6381 dwo_tu
->section
= section
;
6382 dwo_tu
->sect_off
= sect_off
;
6383 dwo_tu
->length
= length
;
6387 /* N.B.: type_offset is not usable if this type uses a DWO file.
6388 The real type_offset is in the DWO file. */
6390 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6391 sig_type
->signature
= header
.signature
;
6392 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6393 sig_type
->per_cu
.is_debug_types
= 1;
6394 sig_type
->per_cu
.section
= section
;
6395 sig_type
->per_cu
.sect_off
= sect_off
;
6396 sig_type
->per_cu
.length
= length
;
6399 slot
= htab_find_slot (types_htab
.get (),
6400 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6402 gdb_assert (slot
!= NULL
);
6405 sect_offset dup_sect_off
;
6409 const struct dwo_unit
*dup_tu
6410 = (const struct dwo_unit
*) *slot
;
6412 dup_sect_off
= dup_tu
->sect_off
;
6416 const struct signatured_type
*dup_tu
6417 = (const struct signatured_type
*) *slot
;
6419 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6422 complaint (_("debug type entry at offset %s is duplicate to"
6423 " the entry at offset %s, signature %s"),
6424 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6425 hex_string (header
.signature
));
6427 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6429 if (dwarf_read_debug
> 1)
6430 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6431 sect_offset_str (sect_off
),
6432 hex_string (header
.signature
));
6438 /* Create the hash table of all entries in the .debug_types
6439 (or .debug_types.dwo) section(s).
6440 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6441 otherwise it is NULL.
6443 The result is a pointer to the hash table or NULL if there are no types.
6445 Note: This function processes DWO files only, not DWP files. */
6448 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6449 struct dwo_file
*dwo_file
,
6450 gdb::array_view
<dwarf2_section_info
> type_sections
,
6451 htab_up
&types_htab
)
6453 for (dwarf2_section_info
§ion
: type_sections
)
6454 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6455 types_htab
, rcuh_kind::TYPE
);
6458 /* Create the hash table of all entries in the .debug_types section,
6459 and initialize all_type_units.
6460 The result is zero if there is an error (e.g. missing .debug_types section),
6461 otherwise non-zero. */
6464 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6468 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6469 &dwarf2_per_objfile
->per_bfd
->info
, types_htab
,
6470 rcuh_kind::COMPILE
);
6471 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6472 dwarf2_per_objfile
->per_bfd
->types
, types_htab
);
6473 if (types_htab
== NULL
)
6475 dwarf2_per_objfile
->per_bfd
->signatured_types
= NULL
;
6479 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6481 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
6482 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve
6483 (htab_elements (dwarf2_per_objfile
->per_bfd
->signatured_types
.get ()));
6485 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6486 add_signatured_type_cu_to_table
,
6487 &dwarf2_per_objfile
->per_bfd
->all_type_units
);
6492 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6493 If SLOT is non-NULL, it is the entry to use in the hash table.
6494 Otherwise we find one. */
6496 static struct signatured_type
*
6497 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6500 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()
6501 == dwarf2_per_objfile
->per_bfd
->all_type_units
.capacity ())
6502 ++dwarf2_per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6504 signatured_type
*sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6506 dwarf2_per_objfile
->resize_symtabs ();
6508 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6509 sig_type
->signature
= sig
;
6510 sig_type
->per_cu
.is_debug_types
= 1;
6511 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6513 sig_type
->per_cu
.v
.quick
=
6514 OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6515 struct dwarf2_per_cu_quick_data
);
6520 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6523 gdb_assert (*slot
== NULL
);
6525 /* The rest of sig_type must be filled in by the caller. */
6529 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6530 Fill in SIG_ENTRY with DWO_ENTRY. */
6533 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6534 struct signatured_type
*sig_entry
,
6535 struct dwo_unit
*dwo_entry
)
6537 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
6539 /* Make sure we're not clobbering something we don't expect to. */
6540 gdb_assert (! sig_entry
->per_cu
.queued
);
6541 gdb_assert (dwarf2_per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6542 if (per_bfd
->using_index
)
6544 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6545 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6548 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6549 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6550 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6551 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6552 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6554 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6555 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6556 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6557 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6558 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6559 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6560 sig_entry
->dwo_unit
= dwo_entry
;
6563 /* Subroutine of lookup_signatured_type.
6564 If we haven't read the TU yet, create the signatured_type data structure
6565 for a TU to be read in directly from a DWO file, bypassing the stub.
6566 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6567 using .gdb_index, then when reading a CU we want to stay in the DWO file
6568 containing that CU. Otherwise we could end up reading several other DWO
6569 files (due to comdat folding) to process the transitive closure of all the
6570 mentioned TUs, and that can be slow. The current DWO file will have every
6571 type signature that it needs.
6572 We only do this for .gdb_index because in the psymtab case we already have
6573 to read all the DWOs to build the type unit groups. */
6575 static struct signatured_type
*
6576 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6578 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6579 struct dwo_file
*dwo_file
;
6580 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6581 struct signatured_type find_sig_entry
, *sig_entry
;
6584 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6586 /* If TU skeletons have been removed then we may not have read in any
6588 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6589 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6591 /* We only ever need to read in one copy of a signatured type.
6592 Use the global signatured_types array to do our own comdat-folding
6593 of types. If this is the first time we're reading this TU, and
6594 the TU has an entry in .gdb_index, replace the recorded data from
6595 .gdb_index with this TU. */
6597 find_sig_entry
.signature
= sig
;
6598 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6599 &find_sig_entry
, INSERT
);
6600 sig_entry
= (struct signatured_type
*) *slot
;
6602 /* We can get here with the TU already read, *or* in the process of being
6603 read. Don't reassign the global entry to point to this DWO if that's
6604 the case. Also note that if the TU is already being read, it may not
6605 have come from a DWO, the program may be a mix of Fission-compiled
6606 code and non-Fission-compiled code. */
6608 /* Have we already tried to read this TU?
6609 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6610 needn't exist in the global table yet). */
6611 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6614 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6615 dwo_unit of the TU itself. */
6616 dwo_file
= cu
->dwo_unit
->dwo_file
;
6618 /* Ok, this is the first time we're reading this TU. */
6619 if (dwo_file
->tus
== NULL
)
6621 find_dwo_entry
.signature
= sig
;
6622 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6624 if (dwo_entry
== NULL
)
6627 /* If the global table doesn't have an entry for this TU, add one. */
6628 if (sig_entry
== NULL
)
6629 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6631 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6632 sig_entry
->per_cu
.tu_read
= 1;
6636 /* Subroutine of lookup_signatured_type.
6637 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6638 then try the DWP file. If the TU stub (skeleton) has been removed then
6639 it won't be in .gdb_index. */
6641 static struct signatured_type
*
6642 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6644 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6645 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6646 struct dwo_unit
*dwo_entry
;
6647 struct signatured_type find_sig_entry
, *sig_entry
;
6650 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6651 gdb_assert (dwp_file
!= NULL
);
6653 /* If TU skeletons have been removed then we may not have read in any
6655 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6656 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6658 find_sig_entry
.signature
= sig
;
6659 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6660 &find_sig_entry
, INSERT
);
6661 sig_entry
= (struct signatured_type
*) *slot
;
6663 /* Have we already tried to read this TU?
6664 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6665 needn't exist in the global table yet). */
6666 if (sig_entry
!= NULL
)
6669 if (dwp_file
->tus
== NULL
)
6671 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6672 sig
, 1 /* is_debug_types */);
6673 if (dwo_entry
== NULL
)
6676 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6677 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6682 /* Lookup a signature based type for DW_FORM_ref_sig8.
6683 Returns NULL if signature SIG is not present in the table.
6684 It is up to the caller to complain about this. */
6686 static struct signatured_type
*
6687 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6689 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6692 && dwarf2_per_objfile
->per_bfd
->using_index
)
6694 /* We're in a DWO/DWP file, and we're using .gdb_index.
6695 These cases require special processing. */
6696 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6697 return lookup_dwo_signatured_type (cu
, sig
);
6699 return lookup_dwp_signatured_type (cu
, sig
);
6703 struct signatured_type find_entry
, *entry
;
6705 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6707 find_entry
.signature
= sig
;
6708 entry
= ((struct signatured_type
*)
6709 htab_find (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6715 /* Low level DIE reading support. */
6717 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6720 init_cu_die_reader (struct die_reader_specs
*reader
,
6721 struct dwarf2_cu
*cu
,
6722 struct dwarf2_section_info
*section
,
6723 struct dwo_file
*dwo_file
,
6724 struct abbrev_table
*abbrev_table
)
6726 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6727 reader
->abfd
= section
->get_bfd_owner ();
6729 reader
->dwo_file
= dwo_file
;
6730 reader
->die_section
= section
;
6731 reader
->buffer
= section
->buffer
;
6732 reader
->buffer_end
= section
->buffer
+ section
->size
;
6733 reader
->abbrev_table
= abbrev_table
;
6736 /* Subroutine of cutu_reader to simplify it.
6737 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6738 There's just a lot of work to do, and cutu_reader is big enough
6741 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6742 from it to the DIE in the DWO. If NULL we are skipping the stub.
6743 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6744 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6745 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6746 STUB_COMP_DIR may be non-NULL.
6747 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6748 are filled in with the info of the DIE from the DWO file.
6749 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6750 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6751 kept around for at least as long as *RESULT_READER.
6753 The result is non-zero if a valid (non-dummy) DIE was found. */
6756 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6757 struct dwo_unit
*dwo_unit
,
6758 struct die_info
*stub_comp_unit_die
,
6759 const char *stub_comp_dir
,
6760 struct die_reader_specs
*result_reader
,
6761 const gdb_byte
**result_info_ptr
,
6762 struct die_info
**result_comp_unit_die
,
6763 abbrev_table_up
*result_dwo_abbrev_table
)
6765 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
6766 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6767 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6769 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6770 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6771 int i
,num_extra_attrs
;
6772 struct dwarf2_section_info
*dwo_abbrev_section
;
6773 struct die_info
*comp_unit_die
;
6775 /* At most one of these may be provided. */
6776 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6778 /* These attributes aren't processed until later:
6779 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6780 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6781 referenced later. However, these attributes are found in the stub
6782 which we won't have later. In order to not impose this complication
6783 on the rest of the code, we read them here and copy them to the
6792 if (stub_comp_unit_die
!= NULL
)
6794 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6796 if (!per_cu
->is_debug_types
)
6797 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6798 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6799 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6800 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6801 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6803 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6805 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6806 here (if needed). We need the value before we can process
6808 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6810 else if (stub_comp_dir
!= NULL
)
6812 /* Reconstruct the comp_dir attribute to simplify the code below. */
6813 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6814 comp_dir
->name
= DW_AT_comp_dir
;
6815 comp_dir
->form
= DW_FORM_string
;
6816 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6817 DW_STRING (comp_dir
) = stub_comp_dir
;
6820 /* Set up for reading the DWO CU/TU. */
6821 cu
->dwo_unit
= dwo_unit
;
6822 dwarf2_section_info
*section
= dwo_unit
->section
;
6823 section
->read (objfile
);
6824 abfd
= section
->get_bfd_owner ();
6825 begin_info_ptr
= info_ptr
= (section
->buffer
6826 + to_underlying (dwo_unit
->sect_off
));
6827 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6829 if (per_cu
->is_debug_types
)
6831 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6833 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6834 &cu
->header
, section
,
6836 info_ptr
, rcuh_kind::TYPE
);
6837 /* This is not an assert because it can be caused by bad debug info. */
6838 if (sig_type
->signature
!= cu
->header
.signature
)
6840 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6841 " TU at offset %s [in module %s]"),
6842 hex_string (sig_type
->signature
),
6843 hex_string (cu
->header
.signature
),
6844 sect_offset_str (dwo_unit
->sect_off
),
6845 bfd_get_filename (abfd
));
6847 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6848 /* For DWOs coming from DWP files, we don't know the CU length
6849 nor the type's offset in the TU until now. */
6850 dwo_unit
->length
= cu
->header
.get_length ();
6851 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6853 /* Establish the type offset that can be used to lookup the type.
6854 For DWO files, we don't know it until now. */
6855 sig_type
->type_offset_in_section
6856 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6860 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6861 &cu
->header
, section
,
6863 info_ptr
, rcuh_kind::COMPILE
);
6864 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6865 /* For DWOs coming from DWP files, we don't know the CU length
6867 dwo_unit
->length
= cu
->header
.get_length ();
6870 *result_dwo_abbrev_table
6871 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6872 cu
->header
.abbrev_sect_off
);
6873 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6874 result_dwo_abbrev_table
->get ());
6876 /* Read in the die, but leave space to copy over the attributes
6877 from the stub. This has the benefit of simplifying the rest of
6878 the code - all the work to maintain the illusion of a single
6879 DW_TAG_{compile,type}_unit DIE is done here. */
6880 num_extra_attrs
= ((stmt_list
!= NULL
)
6884 + (comp_dir
!= NULL
));
6885 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6888 /* Copy over the attributes from the stub to the DIE we just read in. */
6889 comp_unit_die
= *result_comp_unit_die
;
6890 i
= comp_unit_die
->num_attrs
;
6891 if (stmt_list
!= NULL
)
6892 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6894 comp_unit_die
->attrs
[i
++] = *low_pc
;
6895 if (high_pc
!= NULL
)
6896 comp_unit_die
->attrs
[i
++] = *high_pc
;
6898 comp_unit_die
->attrs
[i
++] = *ranges
;
6899 if (comp_dir
!= NULL
)
6900 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6901 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6903 if (dwarf_die_debug
)
6905 fprintf_unfiltered (gdb_stdlog
,
6906 "Read die from %s@0x%x of %s:\n",
6907 section
->get_name (),
6908 (unsigned) (begin_info_ptr
- section
->buffer
),
6909 bfd_get_filename (abfd
));
6910 dump_die (comp_unit_die
, dwarf_die_debug
);
6913 /* Skip dummy compilation units. */
6914 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6915 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6918 *result_info_ptr
= info_ptr
;
6922 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6923 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6924 signature is part of the header. */
6925 static gdb::optional
<ULONGEST
>
6926 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6928 if (cu
->header
.version
>= 5)
6929 return cu
->header
.signature
;
6930 struct attribute
*attr
;
6931 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6932 if (attr
== nullptr)
6933 return gdb::optional
<ULONGEST
> ();
6934 return DW_UNSND (attr
);
6937 /* Subroutine of cutu_reader to simplify it.
6938 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6939 Returns NULL if the specified DWO unit cannot be found. */
6941 static struct dwo_unit
*
6942 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6944 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6945 struct dwo_unit
*dwo_unit
;
6946 const char *comp_dir
;
6948 gdb_assert (cu
!= NULL
);
6950 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6951 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6952 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6954 if (per_cu
->is_debug_types
)
6955 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6958 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6960 if (!signature
.has_value ())
6961 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6963 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6965 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6971 /* Subroutine of cutu_reader to simplify it.
6972 See it for a description of the parameters.
6973 Read a TU directly from a DWO file, bypassing the stub. */
6976 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6977 dwarf2_per_objfile
*per_objfile
,
6978 dwarf2_cu
*existing_cu
)
6980 struct signatured_type
*sig_type
;
6982 /* Verify we can do the following downcast, and that we have the
6984 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6985 sig_type
= (struct signatured_type
*) this_cu
;
6986 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6990 if (existing_cu
!= nullptr)
6993 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6994 /* There's no need to do the rereading_dwo_cu handling that
6995 cutu_reader does since we don't read the stub. */
6999 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7000 in per_objfile yet. */
7001 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7002 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7003 cu
= m_new_cu
.get ();
7006 /* A future optimization, if needed, would be to use an existing
7007 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7008 could share abbrev tables. */
7010 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7011 NULL
/* stub_comp_unit_die */,
7012 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7015 &m_dwo_abbrev_table
) == 0)
7022 /* Initialize a CU (or TU) and read its DIEs.
7023 If the CU defers to a DWO file, read the DWO file as well.
7025 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7026 Otherwise the table specified in the comp unit header is read in and used.
7027 This is an optimization for when we already have the abbrev table.
7029 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7032 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7033 dwarf2_per_objfile
*dwarf2_per_objfile
,
7034 struct abbrev_table
*abbrev_table
,
7035 dwarf2_cu
*existing_cu
,
7037 : die_reader_specs
{},
7040 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7041 struct dwarf2_section_info
*section
= this_cu
->section
;
7042 bfd
*abfd
= section
->get_bfd_owner ();
7043 const gdb_byte
*begin_info_ptr
;
7044 struct signatured_type
*sig_type
= NULL
;
7045 struct dwarf2_section_info
*abbrev_section
;
7046 /* Non-zero if CU currently points to a DWO file and we need to
7047 reread it. When this happens we need to reread the skeleton die
7048 before we can reread the DWO file (this only applies to CUs, not TUs). */
7049 int rereading_dwo_cu
= 0;
7051 if (dwarf_die_debug
)
7052 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7053 this_cu
->is_debug_types
? "type" : "comp",
7054 sect_offset_str (this_cu
->sect_off
));
7056 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7057 file (instead of going through the stub), short-circuit all of this. */
7058 if (this_cu
->reading_dwo_directly
)
7060 /* Narrow down the scope of possibilities to have to understand. */
7061 gdb_assert (this_cu
->is_debug_types
);
7062 gdb_assert (abbrev_table
== NULL
);
7063 init_tu_and_read_dwo_dies (this_cu
, dwarf2_per_objfile
, existing_cu
);
7067 /* This is cheap if the section is already read in. */
7068 section
->read (objfile
);
7070 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7072 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7076 if (existing_cu
!= nullptr)
7079 /* If this CU is from a DWO file we need to start over, we need to
7080 refetch the attributes from the skeleton CU.
7081 This could be optimized by retrieving those attributes from when we
7082 were here the first time: the previous comp_unit_die was stored in
7083 comp_unit_obstack. But there's no data yet that we need this
7085 if (cu
->dwo_unit
!= NULL
)
7086 rereading_dwo_cu
= 1;
7090 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7091 in per_objfile yet. */
7092 gdb_assert (dwarf2_per_objfile
->get_cu (this_cu
) == nullptr);
7093 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7094 cu
= m_new_cu
.get ();
7097 /* Get the header. */
7098 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7100 /* We already have the header, there's no need to read it in again. */
7101 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7105 if (this_cu
->is_debug_types
)
7107 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7108 &cu
->header
, section
,
7109 abbrev_section
, info_ptr
,
7112 /* Since per_cu is the first member of struct signatured_type,
7113 we can go from a pointer to one to a pointer to the other. */
7114 sig_type
= (struct signatured_type
*) this_cu
;
7115 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7116 gdb_assert (sig_type
->type_offset_in_tu
7117 == cu
->header
.type_cu_offset_in_tu
);
7118 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7120 /* LENGTH has not been set yet for type units if we're
7121 using .gdb_index. */
7122 this_cu
->length
= cu
->header
.get_length ();
7124 /* Establish the type offset that can be used to lookup the type. */
7125 sig_type
->type_offset_in_section
=
7126 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7128 this_cu
->dwarf_version
= cu
->header
.version
;
7132 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7133 &cu
->header
, section
,
7136 rcuh_kind::COMPILE
);
7138 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7139 if (this_cu
->length
== 0)
7140 this_cu
->length
= cu
->header
.get_length ();
7142 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7143 this_cu
->dwarf_version
= cu
->header
.version
;
7147 /* Skip dummy compilation units. */
7148 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7149 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7155 /* If we don't have them yet, read the abbrevs for this compilation unit.
7156 And if we need to read them now, make sure they're freed when we're
7158 if (abbrev_table
!= NULL
)
7159 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7162 m_abbrev_table_holder
7163 = abbrev_table::read (objfile
, abbrev_section
,
7164 cu
->header
.abbrev_sect_off
);
7165 abbrev_table
= m_abbrev_table_holder
.get ();
7168 /* Read the top level CU/TU die. */
7169 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7170 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7172 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7178 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7179 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7180 table from the DWO file and pass the ownership over to us. It will be
7181 referenced from READER, so we must make sure to free it after we're done
7184 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7185 DWO CU, that this test will fail (the attribute will not be present). */
7186 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7187 if (dwo_name
!= nullptr)
7189 struct dwo_unit
*dwo_unit
;
7190 struct die_info
*dwo_comp_unit_die
;
7192 if (comp_unit_die
->has_children
)
7194 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7195 " has children (offset %s) [in module %s]"),
7196 sect_offset_str (this_cu
->sect_off
),
7197 bfd_get_filename (abfd
));
7199 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7200 if (dwo_unit
!= NULL
)
7202 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7203 comp_unit_die
, NULL
,
7206 &m_dwo_abbrev_table
) == 0)
7212 comp_unit_die
= dwo_comp_unit_die
;
7216 /* Yikes, we couldn't find the rest of the DIE, we only have
7217 the stub. A complaint has already been logged. There's
7218 not much more we can do except pass on the stub DIE to
7219 die_reader_func. We don't want to throw an error on bad
7226 cutu_reader::keep ()
7228 /* Done, clean up. */
7229 gdb_assert (!dummy_p
);
7230 if (m_new_cu
!= NULL
)
7232 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7234 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7235 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7239 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7240 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7241 assumed to have already done the lookup to find the DWO file).
7243 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7244 THIS_CU->is_debug_types, but nothing else.
7246 We fill in THIS_CU->length.
7248 THIS_CU->cu is always freed when done.
7249 This is done in order to not leave THIS_CU->cu in a state where we have
7250 to care whether it refers to the "main" CU or the DWO CU.
7252 When parent_cu is passed, it is used to provide a default value for
7253 str_offsets_base and addr_base from the parent. */
7255 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7256 dwarf2_per_objfile
*dwarf2_per_objfile
,
7257 struct dwarf2_cu
*parent_cu
,
7258 struct dwo_file
*dwo_file
)
7259 : die_reader_specs
{},
7262 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7263 struct dwarf2_section_info
*section
= this_cu
->section
;
7264 bfd
*abfd
= section
->get_bfd_owner ();
7265 struct dwarf2_section_info
*abbrev_section
;
7266 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7268 if (dwarf_die_debug
)
7269 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7270 this_cu
->is_debug_types
? "type" : "comp",
7271 sect_offset_str (this_cu
->sect_off
));
7273 gdb_assert (dwarf2_per_objfile
->get_cu (this_cu
) == nullptr);
7275 abbrev_section
= (dwo_file
!= NULL
7276 ? &dwo_file
->sections
.abbrev
7277 : get_abbrev_section_for_cu (this_cu
));
7279 /* This is cheap if the section is already read in. */
7280 section
->read (objfile
);
7282 m_new_cu
.reset (new dwarf2_cu (this_cu
, dwarf2_per_objfile
));
7284 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7285 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7286 &m_new_cu
->header
, section
,
7287 abbrev_section
, info_ptr
,
7288 (this_cu
->is_debug_types
7290 : rcuh_kind::COMPILE
));
7292 if (parent_cu
!= nullptr)
7294 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7295 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7297 this_cu
->length
= m_new_cu
->header
.get_length ();
7299 /* Skip dummy compilation units. */
7300 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7301 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7307 m_abbrev_table_holder
7308 = abbrev_table::read (objfile
, abbrev_section
,
7309 m_new_cu
->header
.abbrev_sect_off
);
7311 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7312 m_abbrev_table_holder
.get ());
7313 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7317 /* Type Unit Groups.
7319 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7320 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7321 so that all types coming from the same compilation (.o file) are grouped
7322 together. A future step could be to put the types in the same symtab as
7323 the CU the types ultimately came from. */
7326 hash_type_unit_group (const void *item
)
7328 const struct type_unit_group
*tu_group
7329 = (const struct type_unit_group
*) item
;
7331 return hash_stmt_list_entry (&tu_group
->hash
);
7335 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7337 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7338 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7340 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7343 /* Allocate a hash table for type unit groups. */
7346 allocate_type_unit_groups_table ()
7348 return htab_up (htab_create_alloc (3,
7349 hash_type_unit_group
,
7351 NULL
, xcalloc
, xfree
));
7354 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7355 partial symtabs. We combine several TUs per psymtab to not let the size
7356 of any one psymtab grow too big. */
7357 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7358 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7360 /* Helper routine for get_type_unit_group.
7361 Create the type_unit_group object used to hold one or more TUs. */
7363 static struct type_unit_group
*
7364 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7366 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7367 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
7368 struct dwarf2_per_cu_data
*per_cu
;
7369 struct type_unit_group
*tu_group
;
7371 tu_group
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7372 struct type_unit_group
);
7373 per_cu
= &tu_group
->per_cu
;
7374 per_cu
->per_bfd
= per_bfd
;
7376 if (per_bfd
->using_index
)
7378 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7379 struct dwarf2_per_cu_quick_data
);
7383 unsigned int line_offset
= to_underlying (line_offset_struct
);
7384 dwarf2_psymtab
*pst
;
7387 /* Give the symtab a useful name for debug purposes. */
7388 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7389 name
= string_printf ("<type_units_%d>",
7390 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7392 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7394 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, name
.c_str ());
7395 pst
->anonymous
= true;
7398 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7399 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7404 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7405 STMT_LIST is a DW_AT_stmt_list attribute. */
7407 static struct type_unit_group
*
7408 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7410 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
7411 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7412 struct type_unit_group
*tu_group
;
7414 unsigned int line_offset
;
7415 struct type_unit_group type_unit_group_for_lookup
;
7417 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7418 dwarf2_per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7420 /* Do we need to create a new group, or can we use an existing one? */
7424 line_offset
= DW_UNSND (stmt_list
);
7425 ++tu_stats
->nr_symtab_sharers
;
7429 /* Ugh, no stmt_list. Rare, but we have to handle it.
7430 We can do various things here like create one group per TU or
7431 spread them over multiple groups to split up the expansion work.
7432 To avoid worst case scenarios (too many groups or too large groups)
7433 we, umm, group them in bunches. */
7434 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7435 | (tu_stats
->nr_stmt_less_type_units
7436 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7437 ++tu_stats
->nr_stmt_less_type_units
;
7440 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7441 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7442 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7443 &type_unit_group_for_lookup
, INSERT
);
7446 tu_group
= (struct type_unit_group
*) *slot
;
7447 gdb_assert (tu_group
!= NULL
);
7451 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7452 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7454 ++tu_stats
->nr_symtabs
;
7460 /* Partial symbol tables. */
7462 /* Create a psymtab named NAME and assign it to PER_CU.
7464 The caller must fill in the following details:
7465 dirname, textlow, texthigh. */
7467 static dwarf2_psymtab
*
7468 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7469 dwarf2_per_objfile
*per_objfile
,
7472 struct objfile
*objfile
= per_objfile
->objfile
;
7473 dwarf2_psymtab
*pst
;
7475 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7477 pst
->psymtabs_addrmap_supported
= true;
7479 /* This is the glue that links PST into GDB's symbol API. */
7480 per_cu
->v
.psymtab
= pst
;
7485 /* DIE reader function for process_psymtab_comp_unit. */
7488 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7489 const gdb_byte
*info_ptr
,
7490 struct die_info
*comp_unit_die
,
7491 enum language pretend_language
)
7493 struct dwarf2_cu
*cu
= reader
->cu
;
7494 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7495 struct objfile
*objfile
= per_objfile
->objfile
;
7496 struct gdbarch
*gdbarch
= objfile
->arch ();
7497 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7499 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7500 dwarf2_psymtab
*pst
;
7501 enum pc_bounds_kind cu_bounds_kind
;
7502 const char *filename
;
7504 gdb_assert (! per_cu
->is_debug_types
);
7506 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7508 /* Allocate a new partial symbol table structure. */
7509 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7510 static const char artificial
[] = "<artificial>";
7511 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7512 if (filename
== NULL
)
7514 else if (strcmp (filename
, artificial
) == 0)
7516 debug_filename
.reset (concat (artificial
, "@",
7517 sect_offset_str (per_cu
->sect_off
),
7519 filename
= debug_filename
.get ();
7522 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7524 /* This must be done before calling dwarf2_build_include_psymtabs. */
7525 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7527 baseaddr
= objfile
->text_section_offset ();
7529 dwarf2_find_base_address (comp_unit_die
, cu
);
7531 /* Possibly set the default values of LOWPC and HIGHPC from
7533 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7534 &best_highpc
, cu
, pst
);
7535 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7538 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7541 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7543 /* Store the contiguous range if it is not empty; it can be
7544 empty for CUs with no code. */
7545 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7549 /* Check if comp unit has_children.
7550 If so, read the rest of the partial symbols from this comp unit.
7551 If not, there's no more debug_info for this comp unit. */
7552 if (comp_unit_die
->has_children
)
7554 struct partial_die_info
*first_die
;
7555 CORE_ADDR lowpc
, highpc
;
7557 lowpc
= ((CORE_ADDR
) -1);
7558 highpc
= ((CORE_ADDR
) 0);
7560 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7562 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7563 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7565 /* If we didn't find a lowpc, set it to highpc to avoid
7566 complaints from `maint check'. */
7567 if (lowpc
== ((CORE_ADDR
) -1))
7570 /* If the compilation unit didn't have an explicit address range,
7571 then use the information extracted from its child dies. */
7572 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7575 best_highpc
= highpc
;
7578 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7579 best_lowpc
+ baseaddr
)
7581 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7582 best_highpc
+ baseaddr
)
7585 end_psymtab_common (objfile
, pst
);
7587 if (!cu
->per_cu
->imported_symtabs_empty ())
7590 int len
= cu
->per_cu
->imported_symtabs_size ();
7592 /* Fill in 'dependencies' here; we fill in 'users' in a
7594 pst
->number_of_dependencies
= len
;
7596 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7597 for (i
= 0; i
< len
; ++i
)
7599 pst
->dependencies
[i
]
7600 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7603 cu
->per_cu
->imported_symtabs_free ();
7606 /* Get the list of files included in the current compilation unit,
7607 and build a psymtab for each of them. */
7608 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7610 if (dwarf_read_debug
)
7611 fprintf_unfiltered (gdb_stdlog
,
7612 "Psymtab for %s unit @%s: %s - %s"
7613 ", %d global, %d static syms\n",
7614 per_cu
->is_debug_types
? "type" : "comp",
7615 sect_offset_str (per_cu
->sect_off
),
7616 paddress (gdbarch
, pst
->text_low (objfile
)),
7617 paddress (gdbarch
, pst
->text_high (objfile
)),
7618 pst
->n_global_syms
, pst
->n_static_syms
);
7621 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7622 Process compilation unit THIS_CU for a psymtab. */
7625 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7626 dwarf2_per_objfile
*per_objfile
,
7627 bool want_partial_unit
,
7628 enum language pretend_language
)
7630 /* If this compilation unit was already read in, free the
7631 cached copy in order to read it in again. This is
7632 necessary because we skipped some symbols when we first
7633 read in the compilation unit (see load_partial_dies).
7634 This problem could be avoided, but the benefit is unclear. */
7635 per_objfile
->remove_cu (this_cu
);
7637 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7639 switch (reader
.comp_unit_die
->tag
)
7641 case DW_TAG_compile_unit
:
7642 this_cu
->unit_type
= DW_UT_compile
;
7644 case DW_TAG_partial_unit
:
7645 this_cu
->unit_type
= DW_UT_partial
;
7655 else if (this_cu
->is_debug_types
)
7656 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7657 reader
.comp_unit_die
);
7658 else if (want_partial_unit
7659 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7660 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7661 reader
.comp_unit_die
,
7664 this_cu
->lang
= reader
.cu
->language
;
7666 /* Age out any secondary CUs. */
7667 per_objfile
->age_comp_units ();
7670 /* Reader function for build_type_psymtabs. */
7673 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7674 const gdb_byte
*info_ptr
,
7675 struct die_info
*type_unit_die
)
7677 struct dwarf2_per_objfile
*dwarf2_per_objfile
= reader
->cu
->per_objfile
;
7678 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7679 struct dwarf2_cu
*cu
= reader
->cu
;
7680 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7681 struct signatured_type
*sig_type
;
7682 struct type_unit_group
*tu_group
;
7683 struct attribute
*attr
;
7684 struct partial_die_info
*first_die
;
7685 CORE_ADDR lowpc
, highpc
;
7686 dwarf2_psymtab
*pst
;
7688 gdb_assert (per_cu
->is_debug_types
);
7689 sig_type
= (struct signatured_type
*) per_cu
;
7691 if (! type_unit_die
->has_children
)
7694 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7695 tu_group
= get_type_unit_group (cu
, attr
);
7697 if (tu_group
->tus
== nullptr)
7698 tu_group
->tus
= new std::vector
<signatured_type
*>;
7699 tu_group
->tus
->push_back (sig_type
);
7701 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7702 pst
= create_partial_symtab (per_cu
, dwarf2_per_objfile
, "");
7703 pst
->anonymous
= true;
7705 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7707 lowpc
= (CORE_ADDR
) -1;
7708 highpc
= (CORE_ADDR
) 0;
7709 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7711 end_psymtab_common (objfile
, pst
);
7714 /* Struct used to sort TUs by their abbreviation table offset. */
7716 struct tu_abbrev_offset
7718 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7719 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7722 signatured_type
*sig_type
;
7723 sect_offset abbrev_offset
;
7726 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7729 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7730 const struct tu_abbrev_offset
&b
)
7732 return a
.abbrev_offset
< b
.abbrev_offset
;
7735 /* Efficiently read all the type units.
7736 This does the bulk of the work for build_type_psymtabs.
7738 The efficiency is because we sort TUs by the abbrev table they use and
7739 only read each abbrev table once. In one program there are 200K TUs
7740 sharing 8K abbrev tables.
7742 The main purpose of this function is to support building the
7743 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7744 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7745 can collapse the search space by grouping them by stmt_list.
7746 The savings can be significant, in the same program from above the 200K TUs
7747 share 8K stmt_list tables.
7749 FUNC is expected to call get_type_unit_group, which will create the
7750 struct type_unit_group if necessary and add it to
7751 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7754 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7756 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7757 abbrev_table_up abbrev_table
;
7758 sect_offset abbrev_offset
;
7760 /* It's up to the caller to not call us multiple times. */
7761 gdb_assert (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7763 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ())
7766 /* TUs typically share abbrev tables, and there can be way more TUs than
7767 abbrev tables. Sort by abbrev table to reduce the number of times we
7768 read each abbrev table in.
7769 Alternatives are to punt or to maintain a cache of abbrev tables.
7770 This is simpler and efficient enough for now.
7772 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7773 symtab to use). Typically TUs with the same abbrev offset have the same
7774 stmt_list value too so in practice this should work well.
7776 The basic algorithm here is:
7778 sort TUs by abbrev table
7779 for each TU with same abbrev table:
7780 read abbrev table if first user
7781 read TU top level DIE
7782 [IWBN if DWO skeletons had DW_AT_stmt_list]
7785 if (dwarf_read_debug
)
7786 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7788 /* Sort in a separate table to maintain the order of all_type_units
7789 for .gdb_index: TU indices directly index all_type_units. */
7790 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7791 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7793 for (signatured_type
*sig_type
: dwarf2_per_objfile
->per_bfd
->all_type_units
)
7794 sorted_by_abbrev
.emplace_back
7795 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7796 sig_type
->per_cu
.section
,
7797 sig_type
->per_cu
.sect_off
));
7799 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7800 sort_tu_by_abbrev_offset
);
7802 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7804 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7806 /* Switch to the next abbrev table if necessary. */
7807 if (abbrev_table
== NULL
7808 || tu
.abbrev_offset
!= abbrev_offset
)
7810 abbrev_offset
= tu
.abbrev_offset
;
7812 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7813 &dwarf2_per_objfile
->per_bfd
->abbrev
,
7815 ++tu_stats
->nr_uniq_abbrev_tables
;
7818 cutu_reader
reader (&tu
.sig_type
->per_cu
, dwarf2_per_objfile
,
7819 abbrev_table
.get (), nullptr, false);
7820 if (!reader
.dummy_p
)
7821 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7822 reader
.comp_unit_die
);
7826 /* Print collected type unit statistics. */
7829 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7831 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7833 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7834 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7835 dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7836 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7837 tu_stats
->nr_uniq_abbrev_tables
);
7838 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7839 tu_stats
->nr_symtabs
);
7840 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7841 tu_stats
->nr_symtab_sharers
);
7842 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7843 tu_stats
->nr_stmt_less_type_units
);
7844 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7845 tu_stats
->nr_all_type_units_reallocs
);
7848 /* Traversal function for build_type_psymtabs. */
7851 build_type_psymtab_dependencies (void **slot
, void *info
)
7853 struct dwarf2_per_objfile
*dwarf2_per_objfile
7854 = (struct dwarf2_per_objfile
*) info
;
7855 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7856 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7857 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7858 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7859 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7862 gdb_assert (len
> 0);
7863 gdb_assert (per_cu
->type_unit_group_p ());
7865 pst
->number_of_dependencies
= len
;
7866 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7867 for (i
= 0; i
< len
; ++i
)
7869 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7870 gdb_assert (iter
->per_cu
.is_debug_types
);
7871 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7872 iter
->type_unit_group
= tu_group
;
7875 delete tu_group
->tus
;
7876 tu_group
->tus
= nullptr;
7881 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7882 Build partial symbol tables for the .debug_types comp-units. */
7885 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7887 if (! create_all_type_units (dwarf2_per_objfile
))
7890 build_type_psymtabs_1 (dwarf2_per_objfile
);
7893 /* Traversal function for process_skeletonless_type_unit.
7894 Read a TU in a DWO file and build partial symbols for it. */
7897 process_skeletonless_type_unit (void **slot
, void *info
)
7899 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7900 struct dwarf2_per_objfile
*dwarf2_per_objfile
7901 = (struct dwarf2_per_objfile
*) info
;
7902 struct signatured_type find_entry
, *entry
;
7904 /* If this TU doesn't exist in the global table, add it and read it in. */
7906 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
7907 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7909 find_entry
.signature
= dwo_unit
->signature
;
7910 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
7911 &find_entry
, INSERT
);
7912 /* If we've already seen this type there's nothing to do. What's happening
7913 is we're doing our own version of comdat-folding here. */
7917 /* This does the job that create_all_type_units would have done for
7919 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7920 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7923 /* This does the job that build_type_psymtabs_1 would have done. */
7924 cutu_reader
reader (&entry
->per_cu
, dwarf2_per_objfile
, nullptr, nullptr,
7926 if (!reader
.dummy_p
)
7927 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7928 reader
.comp_unit_die
);
7933 /* Traversal function for process_skeletonless_type_units. */
7936 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7938 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7940 if (dwo_file
->tus
!= NULL
)
7941 htab_traverse_noresize (dwo_file
->tus
.get (),
7942 process_skeletonless_type_unit
, info
);
7947 /* Scan all TUs of DWO files, verifying we've processed them.
7948 This is needed in case a TU was emitted without its skeleton.
7949 Note: This can't be done until we know what all the DWO files are. */
7952 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7954 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7955 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7956 && dwarf2_per_objfile
->per_bfd
->dwo_files
!= NULL
)
7958 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (),
7959 process_dwo_file_for_skeletonless_type_units
,
7960 dwarf2_per_objfile
);
7964 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7967 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7969 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7971 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7976 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7978 /* Set the 'user' field only if it is not already set. */
7979 if (pst
->dependencies
[j
]->user
== NULL
)
7980 pst
->dependencies
[j
]->user
= pst
;
7985 /* Build the partial symbol table by doing a quick pass through the
7986 .debug_info and .debug_abbrev sections. */
7989 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7991 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7993 if (dwarf_read_debug
)
7995 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7996 objfile_name (objfile
));
7999 scoped_restore restore_reading_psyms
8000 = make_scoped_restore (&dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
,
8003 dwarf2_per_objfile
->per_bfd
->info
.read (objfile
);
8005 /* Any cached compilation units will be linked by the per-objfile
8006 read_in_chain. Make sure to free them when we're done. */
8007 free_cached_comp_units
freer (dwarf2_per_objfile
);
8009 build_type_psymtabs (dwarf2_per_objfile
);
8011 create_all_comp_units (dwarf2_per_objfile
);
8013 /* Create a temporary address map on a temporary obstack. We later
8014 copy this to the final obstack. */
8015 auto_obstack temp_obstack
;
8017 scoped_restore save_psymtabs_addrmap
8018 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8019 addrmap_create_mutable (&temp_obstack
));
8021 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
8023 if (per_cu
->v
.psymtab
!= NULL
)
8024 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8026 process_psymtab_comp_unit (per_cu
, dwarf2_per_objfile
, false,
8030 /* This has to wait until we read the CUs, we need the list of DWOs. */
8031 process_skeletonless_type_units (dwarf2_per_objfile
);
8033 /* Now that all TUs have been processed we can fill in the dependencies. */
8034 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8036 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
8037 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8040 if (dwarf_read_debug
)
8041 print_tu_stats (dwarf2_per_objfile
);
8043 set_partial_user (dwarf2_per_objfile
);
8045 objfile
->partial_symtabs
->psymtabs_addrmap
8046 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8047 objfile
->partial_symtabs
->obstack ());
8048 /* At this point we want to keep the address map. */
8049 save_psymtabs_addrmap
.release ();
8051 if (dwarf_read_debug
)
8052 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8053 objfile_name (objfile
));
8056 /* Load the partial DIEs for a secondary CU into memory.
8057 This is also used when rereading a primary CU with load_all_dies. */
8060 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8061 dwarf2_per_objfile
*per_objfile
,
8062 dwarf2_cu
*existing_cu
)
8064 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8066 if (!reader
.dummy_p
)
8068 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8071 /* Check if comp unit has_children.
8072 If so, read the rest of the partial symbols from this comp unit.
8073 If not, there's no more debug_info for this comp unit. */
8074 if (reader
.comp_unit_die
->has_children
)
8075 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8082 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8083 struct dwarf2_section_info
*section
,
8084 struct dwarf2_section_info
*abbrev_section
,
8085 unsigned int is_dwz
)
8087 const gdb_byte
*info_ptr
;
8088 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8090 if (dwarf_read_debug
)
8091 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8092 section
->get_name (),
8093 section
->get_file_name ());
8095 section
->read (objfile
);
8097 info_ptr
= section
->buffer
;
8099 while (info_ptr
< section
->buffer
+ section
->size
)
8101 struct dwarf2_per_cu_data
*this_cu
;
8103 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8105 comp_unit_head cu_header
;
8106 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8107 abbrev_section
, info_ptr
,
8108 rcuh_kind::COMPILE
);
8110 /* Save the compilation unit for later lookup. */
8111 if (cu_header
.unit_type
!= DW_UT_type
)
8112 this_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
8115 auto sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
8116 sig_type
->signature
= cu_header
.signature
;
8117 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8118 this_cu
= &sig_type
->per_cu
;
8120 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8121 this_cu
->sect_off
= sect_off
;
8122 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8123 this_cu
->is_dwz
= is_dwz
;
8124 this_cu
->section
= section
;
8126 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8128 info_ptr
= info_ptr
+ this_cu
->length
;
8132 /* Create a list of all compilation units in OBJFILE.
8133 This is only done for -readnow and building partial symtabs. */
8136 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8138 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
8139 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->per_bfd
->info
,
8140 &dwarf2_per_objfile
->per_bfd
->abbrev
, 0);
8142 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
8144 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8148 /* Process all loaded DIEs for compilation unit CU, starting at
8149 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8150 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8151 DW_AT_ranges). See the comments of add_partial_subprogram on how
8152 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8155 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8156 CORE_ADDR
*highpc
, int set_addrmap
,
8157 struct dwarf2_cu
*cu
)
8159 struct partial_die_info
*pdi
;
8161 /* Now, march along the PDI's, descending into ones which have
8162 interesting children but skipping the children of the other ones,
8163 until we reach the end of the compilation unit. */
8171 /* Anonymous namespaces or modules have no name but have interesting
8172 children, so we need to look at them. Ditto for anonymous
8175 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8176 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8177 || pdi
->tag
== DW_TAG_imported_unit
8178 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8182 case DW_TAG_subprogram
:
8183 case DW_TAG_inlined_subroutine
:
8184 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8186 case DW_TAG_constant
:
8187 case DW_TAG_variable
:
8188 case DW_TAG_typedef
:
8189 case DW_TAG_union_type
:
8190 if (!pdi
->is_declaration
8191 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8193 add_partial_symbol (pdi
, cu
);
8196 case DW_TAG_class_type
:
8197 case DW_TAG_interface_type
:
8198 case DW_TAG_structure_type
:
8199 if (!pdi
->is_declaration
)
8201 add_partial_symbol (pdi
, cu
);
8203 if ((cu
->language
== language_rust
8204 || cu
->language
== language_cplus
) && pdi
->has_children
)
8205 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8208 case DW_TAG_enumeration_type
:
8209 if (!pdi
->is_declaration
)
8210 add_partial_enumeration (pdi
, cu
);
8212 case DW_TAG_base_type
:
8213 case DW_TAG_subrange_type
:
8214 /* File scope base type definitions are added to the partial
8216 add_partial_symbol (pdi
, cu
);
8218 case DW_TAG_namespace
:
8219 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8222 if (!pdi
->is_declaration
)
8223 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8225 case DW_TAG_imported_unit
:
8227 struct dwarf2_per_cu_data
*per_cu
;
8229 /* For now we don't handle imported units in type units. */
8230 if (cu
->per_cu
->is_debug_types
)
8232 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8233 " supported in type units [in module %s]"),
8234 objfile_name (cu
->per_objfile
->objfile
));
8237 per_cu
= dwarf2_find_containing_comp_unit
8238 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8240 /* Go read the partial unit, if needed. */
8241 if (per_cu
->v
.psymtab
== NULL
)
8242 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8245 cu
->per_cu
->imported_symtabs_push (per_cu
);
8248 case DW_TAG_imported_declaration
:
8249 add_partial_symbol (pdi
, cu
);
8256 /* If the die has a sibling, skip to the sibling. */
8258 pdi
= pdi
->die_sibling
;
8262 /* Functions used to compute the fully scoped name of a partial DIE.
8264 Normally, this is simple. For C++, the parent DIE's fully scoped
8265 name is concatenated with "::" and the partial DIE's name.
8266 Enumerators are an exception; they use the scope of their parent
8267 enumeration type, i.e. the name of the enumeration type is not
8268 prepended to the enumerator.
8270 There are two complexities. One is DW_AT_specification; in this
8271 case "parent" means the parent of the target of the specification,
8272 instead of the direct parent of the DIE. The other is compilers
8273 which do not emit DW_TAG_namespace; in this case we try to guess
8274 the fully qualified name of structure types from their members'
8275 linkage names. This must be done using the DIE's children rather
8276 than the children of any DW_AT_specification target. We only need
8277 to do this for structures at the top level, i.e. if the target of
8278 any DW_AT_specification (if any; otherwise the DIE itself) does not
8281 /* Compute the scope prefix associated with PDI's parent, in
8282 compilation unit CU. The result will be allocated on CU's
8283 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8284 field. NULL is returned if no prefix is necessary. */
8286 partial_die_parent_scope (struct partial_die_info
*pdi
,
8287 struct dwarf2_cu
*cu
)
8289 const char *grandparent_scope
;
8290 struct partial_die_info
*parent
, *real_pdi
;
8292 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8293 then this means the parent of the specification DIE. */
8296 while (real_pdi
->has_specification
)
8298 auto res
= find_partial_die (real_pdi
->spec_offset
,
8299 real_pdi
->spec_is_dwz
, cu
);
8304 parent
= real_pdi
->die_parent
;
8308 if (parent
->scope_set
)
8309 return parent
->scope
;
8313 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8315 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8316 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8317 Work around this problem here. */
8318 if (cu
->language
== language_cplus
8319 && parent
->tag
== DW_TAG_namespace
8320 && strcmp (parent
->name
, "::") == 0
8321 && grandparent_scope
== NULL
)
8323 parent
->scope
= NULL
;
8324 parent
->scope_set
= 1;
8328 /* Nested subroutines in Fortran get a prefix. */
8329 if (pdi
->tag
== DW_TAG_enumerator
)
8330 /* Enumerators should not get the name of the enumeration as a prefix. */
8331 parent
->scope
= grandparent_scope
;
8332 else if (parent
->tag
== DW_TAG_namespace
8333 || parent
->tag
== DW_TAG_module
8334 || parent
->tag
== DW_TAG_structure_type
8335 || parent
->tag
== DW_TAG_class_type
8336 || parent
->tag
== DW_TAG_interface_type
8337 || parent
->tag
== DW_TAG_union_type
8338 || parent
->tag
== DW_TAG_enumeration_type
8339 || (cu
->language
== language_fortran
8340 && parent
->tag
== DW_TAG_subprogram
8341 && pdi
->tag
== DW_TAG_subprogram
))
8343 if (grandparent_scope
== NULL
)
8344 parent
->scope
= parent
->name
;
8346 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8348 parent
->name
, 0, cu
);
8352 /* FIXME drow/2004-04-01: What should we be doing with
8353 function-local names? For partial symbols, we should probably be
8355 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8356 dwarf_tag_name (parent
->tag
),
8357 sect_offset_str (pdi
->sect_off
));
8358 parent
->scope
= grandparent_scope
;
8361 parent
->scope_set
= 1;
8362 return parent
->scope
;
8365 /* Return the fully scoped name associated with PDI, from compilation unit
8366 CU. The result will be allocated with malloc. */
8368 static gdb::unique_xmalloc_ptr
<char>
8369 partial_die_full_name (struct partial_die_info
*pdi
,
8370 struct dwarf2_cu
*cu
)
8372 const char *parent_scope
;
8374 /* If this is a template instantiation, we can not work out the
8375 template arguments from partial DIEs. So, unfortunately, we have
8376 to go through the full DIEs. At least any work we do building
8377 types here will be reused if full symbols are loaded later. */
8378 if (pdi
->has_template_arguments
)
8382 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8384 struct die_info
*die
;
8385 struct attribute attr
;
8386 struct dwarf2_cu
*ref_cu
= cu
;
8388 /* DW_FORM_ref_addr is using section offset. */
8389 attr
.name
= (enum dwarf_attribute
) 0;
8390 attr
.form
= DW_FORM_ref_addr
;
8391 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8392 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8394 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8398 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8399 if (parent_scope
== NULL
)
8402 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8407 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8409 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
8410 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8411 struct gdbarch
*gdbarch
= objfile
->arch ();
8413 const char *actual_name
= NULL
;
8416 baseaddr
= objfile
->text_section_offset ();
8418 gdb::unique_xmalloc_ptr
<char> built_actual_name
8419 = partial_die_full_name (pdi
, cu
);
8420 if (built_actual_name
!= NULL
)
8421 actual_name
= built_actual_name
.get ();
8423 if (actual_name
== NULL
)
8424 actual_name
= pdi
->name
;
8426 partial_symbol psymbol
;
8427 memset (&psymbol
, 0, sizeof (psymbol
));
8428 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8429 psymbol
.ginfo
.section
= -1;
8431 /* The code below indicates that the psymbol should be installed by
8433 gdb::optional
<psymbol_placement
> where
;
8437 case DW_TAG_inlined_subroutine
:
8438 case DW_TAG_subprogram
:
8439 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8441 if (pdi
->is_external
8442 || cu
->language
== language_ada
8443 || (cu
->language
== language_fortran
8444 && pdi
->die_parent
!= NULL
8445 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8447 /* Normally, only "external" DIEs are part of the global scope.
8448 But in Ada and Fortran, we want to be able to access nested
8449 procedures globally. So all Ada and Fortran subprograms are
8450 stored in the global scope. */
8451 where
= psymbol_placement::GLOBAL
;
8454 where
= psymbol_placement::STATIC
;
8456 psymbol
.domain
= VAR_DOMAIN
;
8457 psymbol
.aclass
= LOC_BLOCK
;
8458 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8459 psymbol
.ginfo
.value
.address
= addr
;
8461 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8462 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8464 case DW_TAG_constant
:
8465 psymbol
.domain
= VAR_DOMAIN
;
8466 psymbol
.aclass
= LOC_STATIC
;
8467 where
= (pdi
->is_external
8468 ? psymbol_placement::GLOBAL
8469 : psymbol_placement::STATIC
);
8471 case DW_TAG_variable
:
8473 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8477 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
8479 /* A global or static variable may also have been stripped
8480 out by the linker if unused, in which case its address
8481 will be nullified; do not add such variables into partial
8482 symbol table then. */
8484 else if (pdi
->is_external
)
8487 Don't enter into the minimal symbol tables as there is
8488 a minimal symbol table entry from the ELF symbols already.
8489 Enter into partial symbol table if it has a location
8490 descriptor or a type.
8491 If the location descriptor is missing, new_symbol will create
8492 a LOC_UNRESOLVED symbol, the address of the variable will then
8493 be determined from the minimal symbol table whenever the variable
8495 The address for the partial symbol table entry is not
8496 used by GDB, but it comes in handy for debugging partial symbol
8499 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8501 psymbol
.domain
= VAR_DOMAIN
;
8502 psymbol
.aclass
= LOC_STATIC
;
8503 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8504 psymbol
.ginfo
.value
.address
= addr
;
8505 where
= psymbol_placement::GLOBAL
;
8510 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8512 /* Static Variable. Skip symbols whose value we cannot know (those
8513 without location descriptors or constant values). */
8514 if (!has_loc
&& !pdi
->has_const_value
)
8517 psymbol
.domain
= VAR_DOMAIN
;
8518 psymbol
.aclass
= LOC_STATIC
;
8519 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8521 psymbol
.ginfo
.value
.address
= addr
;
8522 where
= psymbol_placement::STATIC
;
8525 case DW_TAG_typedef
:
8526 case DW_TAG_base_type
:
8527 case DW_TAG_subrange_type
:
8528 psymbol
.domain
= VAR_DOMAIN
;
8529 psymbol
.aclass
= LOC_TYPEDEF
;
8530 where
= psymbol_placement::STATIC
;
8532 case DW_TAG_imported_declaration
:
8533 case DW_TAG_namespace
:
8534 psymbol
.domain
= VAR_DOMAIN
;
8535 psymbol
.aclass
= LOC_TYPEDEF
;
8536 where
= psymbol_placement::GLOBAL
;
8539 /* With Fortran 77 there might be a "BLOCK DATA" module
8540 available without any name. If so, we skip the module as it
8541 doesn't bring any value. */
8542 if (actual_name
!= nullptr)
8544 psymbol
.domain
= MODULE_DOMAIN
;
8545 psymbol
.aclass
= LOC_TYPEDEF
;
8546 where
= psymbol_placement::GLOBAL
;
8549 case DW_TAG_class_type
:
8550 case DW_TAG_interface_type
:
8551 case DW_TAG_structure_type
:
8552 case DW_TAG_union_type
:
8553 case DW_TAG_enumeration_type
:
8554 /* Skip external references. The DWARF standard says in the section
8555 about "Structure, Union, and Class Type Entries": "An incomplete
8556 structure, union or class type is represented by a structure,
8557 union or class entry that does not have a byte size attribute
8558 and that has a DW_AT_declaration attribute." */
8559 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8562 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8563 static vs. global. */
8564 psymbol
.domain
= STRUCT_DOMAIN
;
8565 psymbol
.aclass
= LOC_TYPEDEF
;
8566 where
= (cu
->language
== language_cplus
8567 ? psymbol_placement::GLOBAL
8568 : psymbol_placement::STATIC
);
8570 case DW_TAG_enumerator
:
8571 psymbol
.domain
= VAR_DOMAIN
;
8572 psymbol
.aclass
= LOC_CONST
;
8573 where
= (cu
->language
== language_cplus
8574 ? psymbol_placement::GLOBAL
8575 : psymbol_placement::STATIC
);
8581 if (where
.has_value ())
8583 if (built_actual_name
!= nullptr)
8584 actual_name
= objfile
->intern (actual_name
);
8585 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8586 psymbol
.ginfo
.set_linkage_name (actual_name
);
8589 psymbol
.ginfo
.set_demangled_name (actual_name
,
8590 &objfile
->objfile_obstack
);
8591 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8593 add_psymbol_to_list (psymbol
, *where
, objfile
);
8597 /* Read a partial die corresponding to a namespace; also, add a symbol
8598 corresponding to that namespace to the symbol table. NAMESPACE is
8599 the name of the enclosing namespace. */
8602 add_partial_namespace (struct partial_die_info
*pdi
,
8603 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8604 int set_addrmap
, struct dwarf2_cu
*cu
)
8606 /* Add a symbol for the namespace. */
8608 add_partial_symbol (pdi
, cu
);
8610 /* Now scan partial symbols in that namespace. */
8612 if (pdi
->has_children
)
8613 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8616 /* Read a partial die corresponding to a Fortran module. */
8619 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8620 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8622 /* Add a symbol for the namespace. */
8624 add_partial_symbol (pdi
, cu
);
8626 /* Now scan partial symbols in that module. */
8628 if (pdi
->has_children
)
8629 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8632 /* Read a partial die corresponding to a subprogram or an inlined
8633 subprogram and create a partial symbol for that subprogram.
8634 When the CU language allows it, this routine also defines a partial
8635 symbol for each nested subprogram that this subprogram contains.
8636 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8637 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8639 PDI may also be a lexical block, in which case we simply search
8640 recursively for subprograms defined inside that lexical block.
8641 Again, this is only performed when the CU language allows this
8642 type of definitions. */
8645 add_partial_subprogram (struct partial_die_info
*pdi
,
8646 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8647 int set_addrmap
, struct dwarf2_cu
*cu
)
8649 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8651 if (pdi
->has_pc_info
)
8653 if (pdi
->lowpc
< *lowpc
)
8654 *lowpc
= pdi
->lowpc
;
8655 if (pdi
->highpc
> *highpc
)
8656 *highpc
= pdi
->highpc
;
8659 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8660 struct gdbarch
*gdbarch
= objfile
->arch ();
8662 CORE_ADDR this_highpc
;
8663 CORE_ADDR this_lowpc
;
8665 baseaddr
= objfile
->text_section_offset ();
8667 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8668 pdi
->lowpc
+ baseaddr
)
8671 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8672 pdi
->highpc
+ baseaddr
)
8674 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8675 this_lowpc
, this_highpc
- 1,
8676 cu
->per_cu
->v
.psymtab
);
8680 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8682 if (!pdi
->is_declaration
)
8683 /* Ignore subprogram DIEs that do not have a name, they are
8684 illegal. Do not emit a complaint at this point, we will
8685 do so when we convert this psymtab into a symtab. */
8687 add_partial_symbol (pdi
, cu
);
8691 if (! pdi
->has_children
)
8694 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8696 pdi
= pdi
->die_child
;
8700 if (pdi
->tag
== DW_TAG_subprogram
8701 || pdi
->tag
== DW_TAG_inlined_subroutine
8702 || pdi
->tag
== DW_TAG_lexical_block
)
8703 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8704 pdi
= pdi
->die_sibling
;
8709 /* Read a partial die corresponding to an enumeration type. */
8712 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8713 struct dwarf2_cu
*cu
)
8715 struct partial_die_info
*pdi
;
8717 if (enum_pdi
->name
!= NULL
)
8718 add_partial_symbol (enum_pdi
, cu
);
8720 pdi
= enum_pdi
->die_child
;
8723 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8724 complaint (_("malformed enumerator DIE ignored"));
8726 add_partial_symbol (pdi
, cu
);
8727 pdi
= pdi
->die_sibling
;
8731 /* Return the initial uleb128 in the die at INFO_PTR. */
8734 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8736 unsigned int bytes_read
;
8738 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8741 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8742 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8744 Return the corresponding abbrev, or NULL if the number is zero (indicating
8745 an empty DIE). In either case *BYTES_READ will be set to the length of
8746 the initial number. */
8748 static struct abbrev_info
*
8749 peek_die_abbrev (const die_reader_specs
&reader
,
8750 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8752 dwarf2_cu
*cu
= reader
.cu
;
8753 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8754 unsigned int abbrev_number
8755 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8757 if (abbrev_number
== 0)
8760 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8763 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8764 " at offset %s [in module %s]"),
8765 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8766 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8772 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8773 Returns a pointer to the end of a series of DIEs, terminated by an empty
8774 DIE. Any children of the skipped DIEs will also be skipped. */
8776 static const gdb_byte
*
8777 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8781 unsigned int bytes_read
;
8782 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8785 return info_ptr
+ bytes_read
;
8787 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8791 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8792 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8793 abbrev corresponding to that skipped uleb128 should be passed in
8794 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8797 static const gdb_byte
*
8798 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8799 struct abbrev_info
*abbrev
)
8801 unsigned int bytes_read
;
8802 struct attribute attr
;
8803 bfd
*abfd
= reader
->abfd
;
8804 struct dwarf2_cu
*cu
= reader
->cu
;
8805 const gdb_byte
*buffer
= reader
->buffer
;
8806 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8807 unsigned int form
, i
;
8809 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8811 /* The only abbrev we care about is DW_AT_sibling. */
8812 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8815 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8817 if (attr
.form
== DW_FORM_ref_addr
)
8818 complaint (_("ignoring absolute DW_AT_sibling"));
8821 sect_offset off
= attr
.get_ref_die_offset ();
8822 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8824 if (sibling_ptr
< info_ptr
)
8825 complaint (_("DW_AT_sibling points backwards"));
8826 else if (sibling_ptr
> reader
->buffer_end
)
8827 reader
->die_section
->overflow_complaint ();
8833 /* If it isn't DW_AT_sibling, skip this attribute. */
8834 form
= abbrev
->attrs
[i
].form
;
8838 case DW_FORM_ref_addr
:
8839 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8840 and later it is offset sized. */
8841 if (cu
->header
.version
== 2)
8842 info_ptr
+= cu
->header
.addr_size
;
8844 info_ptr
+= cu
->header
.offset_size
;
8846 case DW_FORM_GNU_ref_alt
:
8847 info_ptr
+= cu
->header
.offset_size
;
8850 info_ptr
+= cu
->header
.addr_size
;
8858 case DW_FORM_flag_present
:
8859 case DW_FORM_implicit_const
:
8876 case DW_FORM_ref_sig8
:
8879 case DW_FORM_data16
:
8882 case DW_FORM_string
:
8883 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8884 info_ptr
+= bytes_read
;
8886 case DW_FORM_sec_offset
:
8888 case DW_FORM_GNU_strp_alt
:
8889 info_ptr
+= cu
->header
.offset_size
;
8891 case DW_FORM_exprloc
:
8893 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8894 info_ptr
+= bytes_read
;
8896 case DW_FORM_block1
:
8897 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8899 case DW_FORM_block2
:
8900 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8902 case DW_FORM_block4
:
8903 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8909 case DW_FORM_ref_udata
:
8910 case DW_FORM_GNU_addr_index
:
8911 case DW_FORM_GNU_str_index
:
8912 case DW_FORM_rnglistx
:
8913 case DW_FORM_loclistx
:
8914 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8916 case DW_FORM_indirect
:
8917 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8918 info_ptr
+= bytes_read
;
8919 /* We need to continue parsing from here, so just go back to
8921 goto skip_attribute
;
8924 error (_("Dwarf Error: Cannot handle %s "
8925 "in DWARF reader [in module %s]"),
8926 dwarf_form_name (form
),
8927 bfd_get_filename (abfd
));
8931 if (abbrev
->has_children
)
8932 return skip_children (reader
, info_ptr
);
8937 /* Locate ORIG_PDI's sibling.
8938 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8940 static const gdb_byte
*
8941 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8942 struct partial_die_info
*orig_pdi
,
8943 const gdb_byte
*info_ptr
)
8945 /* Do we know the sibling already? */
8947 if (orig_pdi
->sibling
)
8948 return orig_pdi
->sibling
;
8950 /* Are there any children to deal with? */
8952 if (!orig_pdi
->has_children
)
8955 /* Skip the children the long way. */
8957 return skip_children (reader
, info_ptr
);
8960 /* Expand this partial symbol table into a full symbol table. SELF is
8964 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8966 struct dwarf2_per_objfile
*dwarf2_per_objfile
8967 = get_dwarf2_per_objfile (objfile
);
8969 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (per_cu_data
));
8971 /* If this psymtab is constructed from a debug-only objfile, the
8972 has_section_at_zero flag will not necessarily be correct. We
8973 can get the correct value for this flag by looking at the data
8974 associated with the (presumably stripped) associated objfile. */
8975 if (objfile
->separate_debug_objfile_backlink
)
8977 struct dwarf2_per_objfile
*dpo_backlink
8978 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8980 dwarf2_per_objfile
->per_bfd
->has_section_at_zero
8981 = dpo_backlink
->per_bfd
->has_section_at_zero
;
8984 expand_psymtab (objfile
);
8986 process_cu_includes (dwarf2_per_objfile
);
8989 /* Reading in full CUs. */
8991 /* Add PER_CU to the queue. */
8994 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8995 dwarf2_per_objfile
*per_objfile
,
8996 enum language pretend_language
)
8999 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
9002 /* If PER_CU is not yet queued, add it to the queue.
9003 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9005 The result is non-zero if PER_CU was queued, otherwise the result is zero
9006 meaning either PER_CU is already queued or it is already loaded.
9008 N.B. There is an invariant here that if a CU is queued then it is loaded.
9009 The caller is required to load PER_CU if we return non-zero. */
9012 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9013 dwarf2_per_cu_data
*per_cu
,
9014 dwarf2_per_objfile
*per_objfile
,
9015 enum language pretend_language
)
9017 /* We may arrive here during partial symbol reading, if we need full
9018 DIEs to process an unusual case (e.g. template arguments). Do
9019 not queue PER_CU, just tell our caller to load its DIEs. */
9020 if (per_cu
->per_bfd
->reading_partial_symbols
)
9022 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9024 if (cu
== NULL
|| cu
->dies
== NULL
)
9029 /* Mark the dependence relation so that we don't flush PER_CU
9031 if (dependent_cu
!= NULL
)
9032 dwarf2_add_dependence (dependent_cu
, per_cu
);
9034 /* If it's already on the queue, we have nothing to do. */
9038 /* If the compilation unit is already loaded, just mark it as
9040 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9047 /* Add it to the queue. */
9048 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9053 /* Process the queue. */
9056 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9058 if (dwarf_read_debug
)
9060 fprintf_unfiltered (gdb_stdlog
,
9061 "Expanding one or more symtabs of objfile %s ...\n",
9062 objfile_name (dwarf2_per_objfile
->objfile
));
9065 /* The queue starts out with one item, but following a DIE reference
9066 may load a new CU, adding it to the end of the queue. */
9067 while (!dwarf2_per_objfile
->per_bfd
->queue
.empty ())
9069 dwarf2_queue_item
&item
= dwarf2_per_objfile
->per_bfd
->queue
.front ();
9070 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9072 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
9074 dwarf2_cu
*cu
= dwarf2_per_objfile
->get_cu (per_cu
);
9076 /* Skip dummy CUs. */
9079 unsigned int debug_print_threshold
;
9082 if (per_cu
->is_debug_types
)
9084 struct signatured_type
*sig_type
=
9085 (struct signatured_type
*) per_cu
;
9087 sprintf (buf
, "TU %s at offset %s",
9088 hex_string (sig_type
->signature
),
9089 sect_offset_str (per_cu
->sect_off
));
9090 /* There can be 100s of TUs.
9091 Only print them in verbose mode. */
9092 debug_print_threshold
= 2;
9096 sprintf (buf
, "CU at offset %s",
9097 sect_offset_str (per_cu
->sect_off
));
9098 debug_print_threshold
= 1;
9101 if (dwarf_read_debug
>= debug_print_threshold
)
9102 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9104 if (per_cu
->is_debug_types
)
9105 process_full_type_unit (cu
, item
.pretend_language
);
9107 process_full_comp_unit (cu
, item
.pretend_language
);
9109 if (dwarf_read_debug
>= debug_print_threshold
)
9110 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9115 dwarf2_per_objfile
->per_bfd
->queue
.pop ();
9118 if (dwarf_read_debug
)
9120 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9121 objfile_name (dwarf2_per_objfile
->objfile
));
9125 /* Read in full symbols for PST, and anything it depends on. */
9128 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9130 gdb_assert (!readin_p (objfile
));
9132 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9133 free_cached_comp_units
freer (per_objfile
);
9134 expand_dependencies (objfile
);
9136 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9137 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9140 /* See psympriv.h. */
9143 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9145 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9146 return per_objfile
->symtab_set_p (per_cu_data
);
9149 /* See psympriv.h. */
9152 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9154 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9155 return per_objfile
->get_symtab (per_cu_data
);
9158 /* Trivial hash function for die_info: the hash value of a DIE
9159 is its offset in .debug_info for this objfile. */
9162 die_hash (const void *item
)
9164 const struct die_info
*die
= (const struct die_info
*) item
;
9166 return to_underlying (die
->sect_off
);
9169 /* Trivial comparison function for die_info structures: two DIEs
9170 are equal if they have the same offset. */
9173 die_eq (const void *item_lhs
, const void *item_rhs
)
9175 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9176 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9178 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9181 /* Load the DIEs associated with PER_CU into memory. */
9184 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9185 dwarf2_per_objfile
*per_objfile
,
9187 enum language pretend_language
)
9189 gdb_assert (! this_cu
->is_debug_types
);
9191 dwarf2_cu
*existing_cu
= per_objfile
->get_cu (this_cu
);
9192 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9196 struct dwarf2_cu
*cu
= reader
.cu
;
9197 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9199 gdb_assert (cu
->die_hash
== NULL
);
9201 htab_create_alloc_ex (cu
->header
.length
/ 12,
9205 &cu
->comp_unit_obstack
,
9206 hashtab_obstack_allocate
,
9207 dummy_obstack_deallocate
);
9209 if (reader
.comp_unit_die
->has_children
)
9210 reader
.comp_unit_die
->child
9211 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9212 &info_ptr
, reader
.comp_unit_die
);
9213 cu
->dies
= reader
.comp_unit_die
;
9214 /* comp_unit_die is not stored in die_hash, no need. */
9216 /* We try not to read any attributes in this function, because not
9217 all CUs needed for references have been loaded yet, and symbol
9218 table processing isn't initialized. But we have to set the CU language,
9219 or we won't be able to build types correctly.
9220 Similarly, if we do not read the producer, we can not apply
9221 producer-specific interpretation. */
9222 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9227 /* Add a DIE to the delayed physname list. */
9230 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9231 const char *name
, struct die_info
*die
,
9232 struct dwarf2_cu
*cu
)
9234 struct delayed_method_info mi
;
9236 mi
.fnfield_index
= fnfield_index
;
9240 cu
->method_list
.push_back (mi
);
9243 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9244 "const" / "volatile". If so, decrements LEN by the length of the
9245 modifier and return true. Otherwise return false. */
9249 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9251 size_t mod_len
= sizeof (mod
) - 1;
9252 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9260 /* Compute the physnames of any methods on the CU's method list.
9262 The computation of method physnames is delayed in order to avoid the
9263 (bad) condition that one of the method's formal parameters is of an as yet
9267 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9269 /* Only C++ delays computing physnames. */
9270 if (cu
->method_list
.empty ())
9272 gdb_assert (cu
->language
== language_cplus
);
9274 for (const delayed_method_info
&mi
: cu
->method_list
)
9276 const char *physname
;
9277 struct fn_fieldlist
*fn_flp
9278 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9279 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9280 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9281 = physname
? physname
: "";
9283 /* Since there's no tag to indicate whether a method is a
9284 const/volatile overload, extract that information out of the
9286 if (physname
!= NULL
)
9288 size_t len
= strlen (physname
);
9292 if (physname
[len
] == ')') /* shortcut */
9294 else if (check_modifier (physname
, len
, " const"))
9295 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9296 else if (check_modifier (physname
, len
, " volatile"))
9297 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9304 /* The list is no longer needed. */
9305 cu
->method_list
.clear ();
9308 /* Go objects should be embedded in a DW_TAG_module DIE,
9309 and it's not clear if/how imported objects will appear.
9310 To keep Go support simple until that's worked out,
9311 go back through what we've read and create something usable.
9312 We could do this while processing each DIE, and feels kinda cleaner,
9313 but that way is more invasive.
9314 This is to, for example, allow the user to type "p var" or "b main"
9315 without having to specify the package name, and allow lookups
9316 of module.object to work in contexts that use the expression
9320 fixup_go_packaging (struct dwarf2_cu
*cu
)
9322 gdb::unique_xmalloc_ptr
<char> package_name
;
9323 struct pending
*list
;
9326 for (list
= *cu
->get_builder ()->get_global_symbols ();
9330 for (i
= 0; i
< list
->nsyms
; ++i
)
9332 struct symbol
*sym
= list
->symbol
[i
];
9334 if (sym
->language () == language_go
9335 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9337 gdb::unique_xmalloc_ptr
<char> this_package_name
9338 (go_symbol_package_name (sym
));
9340 if (this_package_name
== NULL
)
9342 if (package_name
== NULL
)
9343 package_name
= std::move (this_package_name
);
9346 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9347 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9348 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9349 (symbol_symtab (sym
) != NULL
9350 ? symtab_to_filename_for_display
9351 (symbol_symtab (sym
))
9352 : objfile_name (objfile
)),
9353 this_package_name
.get (), package_name
.get ());
9359 if (package_name
!= NULL
)
9361 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9362 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9363 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9364 saved_package_name
);
9367 sym
= new (&objfile
->objfile_obstack
) symbol
;
9368 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9369 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9370 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9371 e.g., "main" finds the "main" module and not C's main(). */
9372 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9373 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9374 SYMBOL_TYPE (sym
) = type
;
9376 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9380 /* Allocate a fully-qualified name consisting of the two parts on the
9384 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9386 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9389 /* A helper that allocates a variant part to attach to a Rust enum
9390 type. OBSTACK is where the results should be allocated. TYPE is
9391 the type we're processing. DISCRIMINANT_INDEX is the index of the
9392 discriminant. It must be the index of one of the fields of TYPE.
9393 DEFAULT_INDEX is the index of the default field; or -1 if there is
9394 no default. RANGES is indexed by "effective" field number (the
9395 field index, but omitting the discriminant and default fields) and
9396 must hold the discriminant values used by the variants. Note that
9397 RANGES must have a lifetime at least as long as OBSTACK -- either
9398 already allocated on it, or static. */
9401 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9402 int discriminant_index
, int default_index
,
9403 gdb::array_view
<discriminant_range
> ranges
)
9405 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9406 must be handled by the caller. */
9407 gdb_assert (discriminant_index
>= 0
9408 && discriminant_index
< type
->num_fields ());
9409 gdb_assert (default_index
== -1
9410 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9412 /* We have one variant for each non-discriminant field. */
9413 int n_variants
= type
->num_fields () - 1;
9415 variant
*variants
= new (obstack
) variant
[n_variants
];
9418 for (int i
= 0; i
< type
->num_fields (); ++i
)
9420 if (i
== discriminant_index
)
9423 variants
[var_idx
].first_field
= i
;
9424 variants
[var_idx
].last_field
= i
+ 1;
9426 /* The default field does not need a range, but other fields do.
9427 We skipped the discriminant above. */
9428 if (i
!= default_index
)
9430 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9437 gdb_assert (range_idx
== ranges
.size ());
9438 gdb_assert (var_idx
== n_variants
);
9440 variant_part
*part
= new (obstack
) variant_part
;
9441 part
->discriminant_index
= discriminant_index
;
9442 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9443 discriminant_index
));
9444 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9446 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9447 gdb::array_view
<variant_part
> *prop_value
9448 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9450 struct dynamic_prop prop
;
9451 prop
.kind
= PROP_VARIANT_PARTS
;
9452 prop
.data
.variant_parts
= prop_value
;
9454 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9457 /* Some versions of rustc emitted enums in an unusual way.
9459 Ordinary enums were emitted as unions. The first element of each
9460 structure in the union was named "RUST$ENUM$DISR". This element
9461 held the discriminant.
9463 These versions of Rust also implemented the "non-zero"
9464 optimization. When the enum had two values, and one is empty and
9465 the other holds a pointer that cannot be zero, the pointer is used
9466 as the discriminant, with a zero value meaning the empty variant.
9467 Here, the union's first member is of the form
9468 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9469 where the fieldnos are the indices of the fields that should be
9470 traversed in order to find the field (which may be several fields deep)
9471 and the variantname is the name of the variant of the case when the
9474 This function recognizes whether TYPE is of one of these forms,
9475 and, if so, smashes it to be a variant type. */
9478 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9480 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9482 /* We don't need to deal with empty enums. */
9483 if (type
->num_fields () == 0)
9486 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9487 if (type
->num_fields () == 1
9488 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9490 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9492 /* Decode the field name to find the offset of the
9494 ULONGEST bit_offset
= 0;
9495 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9496 while (name
[0] >= '0' && name
[0] <= '9')
9499 unsigned long index
= strtoul (name
, &tail
, 10);
9502 || index
>= field_type
->num_fields ()
9503 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9504 != FIELD_LOC_KIND_BITPOS
))
9506 complaint (_("Could not parse Rust enum encoding string \"%s\""
9508 TYPE_FIELD_NAME (type
, 0),
9509 objfile_name (objfile
));
9514 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9515 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9518 /* Smash this type to be a structure type. We have to do this
9519 because the type has already been recorded. */
9520 type
->set_code (TYPE_CODE_STRUCT
);
9521 type
->set_num_fields (3);
9522 /* Save the field we care about. */
9523 struct field saved_field
= type
->field (0);
9525 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9527 /* Put the discriminant at index 0. */
9528 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9529 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9530 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9531 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9533 /* The order of fields doesn't really matter, so put the real
9534 field at index 1 and the data-less field at index 2. */
9535 type
->field (1) = saved_field
;
9536 TYPE_FIELD_NAME (type
, 1)
9537 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9538 TYPE_FIELD_TYPE (type
, 1)->set_name
9539 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9540 TYPE_FIELD_NAME (type
, 1)));
9542 const char *dataless_name
9543 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9545 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9547 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9548 /* NAME points into the original discriminant name, which
9549 already has the correct lifetime. */
9550 TYPE_FIELD_NAME (type
, 2) = name
;
9551 SET_FIELD_BITPOS (type
->field (2), 0);
9553 /* Indicate that this is a variant type. */
9554 static discriminant_range ranges
[1] = { { 0, 0 } };
9555 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9557 /* A union with a single anonymous field is probably an old-style
9559 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9561 /* Smash this type to be a structure type. We have to do this
9562 because the type has already been recorded. */
9563 type
->set_code (TYPE_CODE_STRUCT
);
9565 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9566 const char *variant_name
9567 = rust_last_path_segment (field_type
->name ());
9568 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9569 field_type
->set_name
9570 (rust_fully_qualify (&objfile
->objfile_obstack
,
9571 type
->name (), variant_name
));
9575 struct type
*disr_type
= nullptr;
9576 for (int i
= 0; i
< type
->num_fields (); ++i
)
9578 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9580 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9582 /* All fields of a true enum will be structs. */
9585 else if (disr_type
->num_fields () == 0)
9587 /* Could be data-less variant, so keep going. */
9588 disr_type
= nullptr;
9590 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9591 "RUST$ENUM$DISR") != 0)
9593 /* Not a Rust enum. */
9603 /* If we got here without a discriminant, then it's probably
9605 if (disr_type
== nullptr)
9608 /* Smash this type to be a structure type. We have to do this
9609 because the type has already been recorded. */
9610 type
->set_code (TYPE_CODE_STRUCT
);
9612 /* Make space for the discriminant field. */
9613 struct field
*disr_field
= &disr_type
->field (0);
9615 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9616 * sizeof (struct field
)));
9617 memcpy (new_fields
+ 1, type
->fields (),
9618 type
->num_fields () * sizeof (struct field
));
9619 type
->set_fields (new_fields
);
9620 type
->set_num_fields (type
->num_fields () + 1);
9622 /* Install the discriminant at index 0 in the union. */
9623 type
->field (0) = *disr_field
;
9624 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9625 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9627 /* We need a way to find the correct discriminant given a
9628 variant name. For convenience we build a map here. */
9629 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9630 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9631 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9633 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9636 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9637 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9641 int n_fields
= type
->num_fields ();
9642 /* We don't need a range entry for the discriminant, but we do
9643 need one for every other field, as there is no default
9645 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9648 /* Skip the discriminant here. */
9649 for (int i
= 1; i
< n_fields
; ++i
)
9651 /* Find the final word in the name of this variant's type.
9652 That name can be used to look up the correct
9654 const char *variant_name
9655 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9657 auto iter
= discriminant_map
.find (variant_name
);
9658 if (iter
!= discriminant_map
.end ())
9660 ranges
[i
].low
= iter
->second
;
9661 ranges
[i
].high
= iter
->second
;
9664 /* Remove the discriminant field, if it exists. */
9665 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9666 if (sub_type
->num_fields () > 0)
9668 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9669 sub_type
->set_fields (sub_type
->fields () + 1);
9671 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9673 (rust_fully_qualify (&objfile
->objfile_obstack
,
9674 type
->name (), variant_name
));
9677 /* Indicate that this is a variant type. */
9678 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9679 gdb::array_view
<discriminant_range
> (ranges
,
9684 /* Rewrite some Rust unions to be structures with variants parts. */
9687 rust_union_quirks (struct dwarf2_cu
*cu
)
9689 gdb_assert (cu
->language
== language_rust
);
9690 for (type
*type_
: cu
->rust_unions
)
9691 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9692 /* We don't need this any more. */
9693 cu
->rust_unions
.clear ();
9698 type_unit_group_unshareable
*
9699 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9701 auto iter
= this->m_type_units
.find (tu_group
);
9702 if (iter
!= this->m_type_units
.end ())
9703 return iter
->second
.get ();
9705 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9706 type_unit_group_unshareable
*result
= uniq
.get ();
9707 this->m_type_units
[tu_group
] = std::move (uniq
);
9712 dwarf2_per_objfile::get_type_for_signatured_type
9713 (signatured_type
*sig_type
) const
9715 auto iter
= this->m_type_map
.find (sig_type
);
9716 if (iter
== this->m_type_map
.end ())
9719 return iter
->second
;
9722 void dwarf2_per_objfile::set_type_for_signatured_type
9723 (signatured_type
*sig_type
, struct type
*type
)
9725 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9727 this->m_type_map
[sig_type
] = type
;
9730 /* A helper function for computing the list of all symbol tables
9731 included by PER_CU. */
9734 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9735 htab_t all_children
, htab_t all_type_symtabs
,
9736 dwarf2_per_cu_data
*per_cu
,
9737 dwarf2_per_objfile
*per_objfile
,
9738 struct compunit_symtab
*immediate_parent
)
9740 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9743 /* This inclusion and its children have been processed. */
9749 /* Only add a CU if it has a symbol table. */
9750 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9753 /* If this is a type unit only add its symbol table if we haven't
9754 seen it yet (type unit per_cu's can share symtabs). */
9755 if (per_cu
->is_debug_types
)
9757 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9761 result
->push_back (cust
);
9762 if (cust
->user
== NULL
)
9763 cust
->user
= immediate_parent
;
9768 result
->push_back (cust
);
9769 if (cust
->user
== NULL
)
9770 cust
->user
= immediate_parent
;
9774 if (!per_cu
->imported_symtabs_empty ())
9775 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9777 recursively_compute_inclusions (result
, all_children
,
9778 all_type_symtabs
, ptr
, per_objfile
,
9783 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9787 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9788 dwarf2_per_objfile
*per_objfile
)
9790 gdb_assert (! per_cu
->is_debug_types
);
9792 if (!per_cu
->imported_symtabs_empty ())
9795 std::vector
<compunit_symtab
*> result_symtabs
;
9796 htab_t all_children
, all_type_symtabs
;
9797 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9799 /* If we don't have a symtab, we can just skip this case. */
9803 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9804 NULL
, xcalloc
, xfree
);
9805 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9806 NULL
, xcalloc
, xfree
);
9808 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9810 recursively_compute_inclusions (&result_symtabs
, all_children
,
9811 all_type_symtabs
, ptr
, per_objfile
,
9815 /* Now we have a transitive closure of all the included symtabs. */
9816 len
= result_symtabs
.size ();
9818 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9819 struct compunit_symtab
*, len
+ 1);
9820 memcpy (cust
->includes
, result_symtabs
.data (),
9821 len
* sizeof (compunit_symtab
*));
9822 cust
->includes
[len
] = NULL
;
9824 htab_delete (all_children
);
9825 htab_delete (all_type_symtabs
);
9829 /* Compute the 'includes' field for the symtabs of all the CUs we just
9833 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9835 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->per_bfd
->just_read_cus
)
9837 if (! iter
->is_debug_types
)
9838 compute_compunit_symtab_includes (iter
, dwarf2_per_objfile
);
9841 dwarf2_per_objfile
->per_bfd
->just_read_cus
.clear ();
9844 /* Generate full symbol information for CU, whose DIEs have
9845 already been loaded into memory. */
9848 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9850 dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
9851 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9852 struct gdbarch
*gdbarch
= objfile
->arch ();
9853 CORE_ADDR lowpc
, highpc
;
9854 struct compunit_symtab
*cust
;
9856 struct block
*static_block
;
9859 baseaddr
= objfile
->text_section_offset ();
9861 /* Clear the list here in case something was left over. */
9862 cu
->method_list
.clear ();
9864 cu
->language
= pretend_language
;
9865 cu
->language_defn
= language_def (cu
->language
);
9867 /* Do line number decoding in read_file_scope () */
9868 process_die (cu
->dies
, cu
);
9870 /* For now fudge the Go package. */
9871 if (cu
->language
== language_go
)
9872 fixup_go_packaging (cu
);
9874 /* Now that we have processed all the DIEs in the CU, all the types
9875 should be complete, and it should now be safe to compute all of the
9877 compute_delayed_physnames (cu
);
9879 if (cu
->language
== language_rust
)
9880 rust_union_quirks (cu
);
9882 /* Some compilers don't define a DW_AT_high_pc attribute for the
9883 compilation unit. If the DW_AT_high_pc is missing, synthesize
9884 it, by scanning the DIE's below the compilation unit. */
9885 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9887 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9888 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9890 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9891 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9892 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9893 addrmap to help ensure it has an accurate map of pc values belonging to
9895 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9897 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9898 SECT_OFF_TEXT (objfile
),
9903 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9905 /* Set symtab language to language from DW_AT_language. If the
9906 compilation is from a C file generated by language preprocessors, do
9907 not set the language if it was already deduced by start_subfile. */
9908 if (!(cu
->language
== language_c
9909 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9910 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9912 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9913 produce DW_AT_location with location lists but it can be possibly
9914 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9915 there were bugs in prologue debug info, fixed later in GCC-4.5
9916 by "unwind info for epilogues" patch (which is not directly related).
9918 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9919 needed, it would be wrong due to missing DW_AT_producer there.
9921 Still one can confuse GDB by using non-standard GCC compilation
9922 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9924 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9925 cust
->locations_valid
= 1;
9927 if (gcc_4_minor
>= 5)
9928 cust
->epilogue_unwind_valid
= 1;
9930 cust
->call_site_htab
= cu
->call_site_htab
;
9933 dwarf2_per_objfile
->set_symtab (cu
->per_cu
, cust
);
9935 /* Push it for inclusion processing later. */
9936 dwarf2_per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9938 /* Not needed any more. */
9939 cu
->reset_builder ();
9942 /* Generate full symbol information for type unit CU, whose DIEs have
9943 already been loaded into memory. */
9946 process_full_type_unit (dwarf2_cu
*cu
,
9947 enum language pretend_language
)
9949 dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
9950 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9951 struct compunit_symtab
*cust
;
9952 struct signatured_type
*sig_type
;
9954 gdb_assert (cu
->per_cu
->is_debug_types
);
9955 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9957 /* Clear the list here in case something was left over. */
9958 cu
->method_list
.clear ();
9960 cu
->language
= pretend_language
;
9961 cu
->language_defn
= language_def (cu
->language
);
9963 /* The symbol tables are set up in read_type_unit_scope. */
9964 process_die (cu
->dies
, cu
);
9966 /* For now fudge the Go package. */
9967 if (cu
->language
== language_go
)
9968 fixup_go_packaging (cu
);
9970 /* Now that we have processed all the DIEs in the CU, all the types
9971 should be complete, and it should now be safe to compute all of the
9973 compute_delayed_physnames (cu
);
9975 if (cu
->language
== language_rust
)
9976 rust_union_quirks (cu
);
9978 /* TUs share symbol tables.
9979 If this is the first TU to use this symtab, complete the construction
9980 of it with end_expandable_symtab. Otherwise, complete the addition of
9981 this TU's symbols to the existing symtab. */
9982 type_unit_group_unshareable
*tug_unshare
=
9983 dwarf2_per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9984 if (tug_unshare
->compunit_symtab
== NULL
)
9986 buildsym_compunit
*builder
= cu
->get_builder ();
9987 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9988 tug_unshare
->compunit_symtab
= cust
;
9992 /* Set symtab language to language from DW_AT_language. If the
9993 compilation is from a C file generated by language preprocessors,
9994 do not set the language if it was already deduced by
9996 if (!(cu
->language
== language_c
9997 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9998 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10003 cu
->get_builder ()->augment_type_symtab ();
10004 cust
= tug_unshare
->compunit_symtab
;
10007 dwarf2_per_objfile
->set_symtab (cu
->per_cu
, cust
);
10009 /* Not needed any more. */
10010 cu
->reset_builder ();
10013 /* Process an imported unit DIE. */
10016 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10018 struct attribute
*attr
;
10020 /* For now we don't handle imported units in type units. */
10021 if (cu
->per_cu
->is_debug_types
)
10023 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10024 " supported in type units [in module %s]"),
10025 objfile_name (cu
->per_objfile
->objfile
));
10028 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10031 sect_offset sect_off
= attr
->get_ref_die_offset ();
10032 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10033 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10034 dwarf2_per_cu_data
*per_cu
10035 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10037 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10038 into another compilation unit, at root level. Regard this as a hint,
10040 if (die
->parent
&& die
->parent
->parent
== NULL
10041 && per_cu
->unit_type
== DW_UT_compile
10042 && per_cu
->lang
== language_cplus
)
10045 /* If necessary, add it to the queue and load its DIEs. */
10046 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10047 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
10049 cu
->per_cu
->imported_symtabs_push (per_cu
);
10053 /* RAII object that represents a process_die scope: i.e.,
10054 starts/finishes processing a DIE. */
10055 class process_die_scope
10058 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10059 : m_die (die
), m_cu (cu
)
10061 /* We should only be processing DIEs not already in process. */
10062 gdb_assert (!m_die
->in_process
);
10063 m_die
->in_process
= true;
10066 ~process_die_scope ()
10068 m_die
->in_process
= false;
10070 /* If we're done processing the DIE for the CU that owns the line
10071 header, we don't need the line header anymore. */
10072 if (m_cu
->line_header_die_owner
== m_die
)
10074 delete m_cu
->line_header
;
10075 m_cu
->line_header
= NULL
;
10076 m_cu
->line_header_die_owner
= NULL
;
10085 /* Process a die and its children. */
10088 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10090 process_die_scope
scope (die
, cu
);
10094 case DW_TAG_padding
:
10096 case DW_TAG_compile_unit
:
10097 case DW_TAG_partial_unit
:
10098 read_file_scope (die
, cu
);
10100 case DW_TAG_type_unit
:
10101 read_type_unit_scope (die
, cu
);
10103 case DW_TAG_subprogram
:
10104 /* Nested subprograms in Fortran get a prefix. */
10105 if (cu
->language
== language_fortran
10106 && die
->parent
!= NULL
10107 && die
->parent
->tag
== DW_TAG_subprogram
)
10108 cu
->processing_has_namespace_info
= true;
10109 /* Fall through. */
10110 case DW_TAG_inlined_subroutine
:
10111 read_func_scope (die
, cu
);
10113 case DW_TAG_lexical_block
:
10114 case DW_TAG_try_block
:
10115 case DW_TAG_catch_block
:
10116 read_lexical_block_scope (die
, cu
);
10118 case DW_TAG_call_site
:
10119 case DW_TAG_GNU_call_site
:
10120 read_call_site_scope (die
, cu
);
10122 case DW_TAG_class_type
:
10123 case DW_TAG_interface_type
:
10124 case DW_TAG_structure_type
:
10125 case DW_TAG_union_type
:
10126 process_structure_scope (die
, cu
);
10128 case DW_TAG_enumeration_type
:
10129 process_enumeration_scope (die
, cu
);
10132 /* These dies have a type, but processing them does not create
10133 a symbol or recurse to process the children. Therefore we can
10134 read them on-demand through read_type_die. */
10135 case DW_TAG_subroutine_type
:
10136 case DW_TAG_set_type
:
10137 case DW_TAG_array_type
:
10138 case DW_TAG_pointer_type
:
10139 case DW_TAG_ptr_to_member_type
:
10140 case DW_TAG_reference_type
:
10141 case DW_TAG_rvalue_reference_type
:
10142 case DW_TAG_string_type
:
10145 case DW_TAG_base_type
:
10146 case DW_TAG_subrange_type
:
10147 case DW_TAG_typedef
:
10148 /* Add a typedef symbol for the type definition, if it has a
10150 new_symbol (die
, read_type_die (die
, cu
), cu
);
10152 case DW_TAG_common_block
:
10153 read_common_block (die
, cu
);
10155 case DW_TAG_common_inclusion
:
10157 case DW_TAG_namespace
:
10158 cu
->processing_has_namespace_info
= true;
10159 read_namespace (die
, cu
);
10161 case DW_TAG_module
:
10162 cu
->processing_has_namespace_info
= true;
10163 read_module (die
, cu
);
10165 case DW_TAG_imported_declaration
:
10166 cu
->processing_has_namespace_info
= true;
10167 if (read_namespace_alias (die
, cu
))
10169 /* The declaration is not a global namespace alias. */
10170 /* Fall through. */
10171 case DW_TAG_imported_module
:
10172 cu
->processing_has_namespace_info
= true;
10173 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10174 || cu
->language
!= language_fortran
))
10175 complaint (_("Tag '%s' has unexpected children"),
10176 dwarf_tag_name (die
->tag
));
10177 read_import_statement (die
, cu
);
10180 case DW_TAG_imported_unit
:
10181 process_imported_unit_die (die
, cu
);
10184 case DW_TAG_variable
:
10185 read_variable (die
, cu
);
10189 new_symbol (die
, NULL
, cu
);
10194 /* DWARF name computation. */
10196 /* A helper function for dwarf2_compute_name which determines whether DIE
10197 needs to have the name of the scope prepended to the name listed in the
10201 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10203 struct attribute
*attr
;
10207 case DW_TAG_namespace
:
10208 case DW_TAG_typedef
:
10209 case DW_TAG_class_type
:
10210 case DW_TAG_interface_type
:
10211 case DW_TAG_structure_type
:
10212 case DW_TAG_union_type
:
10213 case DW_TAG_enumeration_type
:
10214 case DW_TAG_enumerator
:
10215 case DW_TAG_subprogram
:
10216 case DW_TAG_inlined_subroutine
:
10217 case DW_TAG_member
:
10218 case DW_TAG_imported_declaration
:
10221 case DW_TAG_variable
:
10222 case DW_TAG_constant
:
10223 /* We only need to prefix "globally" visible variables. These include
10224 any variable marked with DW_AT_external or any variable that
10225 lives in a namespace. [Variables in anonymous namespaces
10226 require prefixing, but they are not DW_AT_external.] */
10228 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10230 struct dwarf2_cu
*spec_cu
= cu
;
10232 return die_needs_namespace (die_specification (die
, &spec_cu
),
10236 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10237 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10238 && die
->parent
->tag
!= DW_TAG_module
)
10240 /* A variable in a lexical block of some kind does not need a
10241 namespace, even though in C++ such variables may be external
10242 and have a mangled name. */
10243 if (die
->parent
->tag
== DW_TAG_lexical_block
10244 || die
->parent
->tag
== DW_TAG_try_block
10245 || die
->parent
->tag
== DW_TAG_catch_block
10246 || die
->parent
->tag
== DW_TAG_subprogram
)
10255 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10256 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10257 defined for the given DIE. */
10259 static struct attribute
*
10260 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10262 struct attribute
*attr
;
10264 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10266 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10271 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10272 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10273 defined for the given DIE. */
10275 static const char *
10276 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10278 const char *linkage_name
;
10280 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10281 if (linkage_name
== NULL
)
10282 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10284 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10285 See https://github.com/rust-lang/rust/issues/32925. */
10286 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10287 && strchr (linkage_name
, '{') != NULL
)
10288 linkage_name
= NULL
;
10290 return linkage_name
;
10293 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10294 compute the physname for the object, which include a method's:
10295 - formal parameters (C++),
10296 - receiver type (Go),
10298 The term "physname" is a bit confusing.
10299 For C++, for example, it is the demangled name.
10300 For Go, for example, it's the mangled name.
10302 For Ada, return the DIE's linkage name rather than the fully qualified
10303 name. PHYSNAME is ignored..
10305 The result is allocated on the objfile->per_bfd's obstack and
10308 static const char *
10309 dwarf2_compute_name (const char *name
,
10310 struct die_info
*die
, struct dwarf2_cu
*cu
,
10313 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10316 name
= dwarf2_name (die
, cu
);
10318 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10319 but otherwise compute it by typename_concat inside GDB.
10320 FIXME: Actually this is not really true, or at least not always true.
10321 It's all very confusing. compute_and_set_names doesn't try to demangle
10322 Fortran names because there is no mangling standard. So new_symbol
10323 will set the demangled name to the result of dwarf2_full_name, and it is
10324 the demangled name that GDB uses if it exists. */
10325 if (cu
->language
== language_ada
10326 || (cu
->language
== language_fortran
&& physname
))
10328 /* For Ada unit, we prefer the linkage name over the name, as
10329 the former contains the exported name, which the user expects
10330 to be able to reference. Ideally, we want the user to be able
10331 to reference this entity using either natural or linkage name,
10332 but we haven't started looking at this enhancement yet. */
10333 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10335 if (linkage_name
!= NULL
)
10336 return linkage_name
;
10339 /* These are the only languages we know how to qualify names in. */
10341 && (cu
->language
== language_cplus
10342 || cu
->language
== language_fortran
|| cu
->language
== language_d
10343 || cu
->language
== language_rust
))
10345 if (die_needs_namespace (die
, cu
))
10347 const char *prefix
;
10348 const char *canonical_name
= NULL
;
10352 prefix
= determine_prefix (die
, cu
);
10353 if (*prefix
!= '\0')
10355 gdb::unique_xmalloc_ptr
<char> prefixed_name
10356 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10358 buf
.puts (prefixed_name
.get ());
10363 /* Template parameters may be specified in the DIE's DW_AT_name, or
10364 as children with DW_TAG_template_type_param or
10365 DW_TAG_value_type_param. If the latter, add them to the name
10366 here. If the name already has template parameters, then
10367 skip this step; some versions of GCC emit both, and
10368 it is more efficient to use the pre-computed name.
10370 Something to keep in mind about this process: it is very
10371 unlikely, or in some cases downright impossible, to produce
10372 something that will match the mangled name of a function.
10373 If the definition of the function has the same debug info,
10374 we should be able to match up with it anyway. But fallbacks
10375 using the minimal symbol, for instance to find a method
10376 implemented in a stripped copy of libstdc++, will not work.
10377 If we do not have debug info for the definition, we will have to
10378 match them up some other way.
10380 When we do name matching there is a related problem with function
10381 templates; two instantiated function templates are allowed to
10382 differ only by their return types, which we do not add here. */
10384 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10386 struct attribute
*attr
;
10387 struct die_info
*child
;
10390 die
->building_fullname
= 1;
10392 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10396 const gdb_byte
*bytes
;
10397 struct dwarf2_locexpr_baton
*baton
;
10400 if (child
->tag
!= DW_TAG_template_type_param
10401 && child
->tag
!= DW_TAG_template_value_param
)
10412 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10415 complaint (_("template parameter missing DW_AT_type"));
10416 buf
.puts ("UNKNOWN_TYPE");
10419 type
= die_type (child
, cu
);
10421 if (child
->tag
== DW_TAG_template_type_param
)
10423 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10424 &type_print_raw_options
);
10428 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10431 complaint (_("template parameter missing "
10432 "DW_AT_const_value"));
10433 buf
.puts ("UNKNOWN_VALUE");
10437 dwarf2_const_value_attr (attr
, type
, name
,
10438 &cu
->comp_unit_obstack
, cu
,
10439 &value
, &bytes
, &baton
);
10441 if (TYPE_NOSIGN (type
))
10442 /* GDB prints characters as NUMBER 'CHAR'. If that's
10443 changed, this can use value_print instead. */
10444 c_printchar (value
, type
, &buf
);
10447 struct value_print_options opts
;
10450 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10454 baton
->per_objfile
);
10455 else if (bytes
!= NULL
)
10457 v
= allocate_value (type
);
10458 memcpy (value_contents_writeable (v
), bytes
,
10459 TYPE_LENGTH (type
));
10462 v
= value_from_longest (type
, value
);
10464 /* Specify decimal so that we do not depend on
10466 get_formatted_print_options (&opts
, 'd');
10468 value_print (v
, &buf
, &opts
);
10473 die
->building_fullname
= 0;
10477 /* Close the argument list, with a space if necessary
10478 (nested templates). */
10479 if (!buf
.empty () && buf
.string ().back () == '>')
10486 /* For C++ methods, append formal parameter type
10487 information, if PHYSNAME. */
10489 if (physname
&& die
->tag
== DW_TAG_subprogram
10490 && cu
->language
== language_cplus
)
10492 struct type
*type
= read_type_die (die
, cu
);
10494 c_type_print_args (type
, &buf
, 1, cu
->language
,
10495 &type_print_raw_options
);
10497 if (cu
->language
== language_cplus
)
10499 /* Assume that an artificial first parameter is
10500 "this", but do not crash if it is not. RealView
10501 marks unnamed (and thus unused) parameters as
10502 artificial; there is no way to differentiate
10504 if (type
->num_fields () > 0
10505 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10506 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10507 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10509 buf
.puts (" const");
10513 const std::string
&intermediate_name
= buf
.string ();
10515 if (cu
->language
== language_cplus
)
10517 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10520 /* If we only computed INTERMEDIATE_NAME, or if
10521 INTERMEDIATE_NAME is already canonical, then we need to
10523 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10524 name
= objfile
->intern (intermediate_name
);
10526 name
= canonical_name
;
10533 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10534 If scope qualifiers are appropriate they will be added. The result
10535 will be allocated on the storage_obstack, or NULL if the DIE does
10536 not have a name. NAME may either be from a previous call to
10537 dwarf2_name or NULL.
10539 The output string will be canonicalized (if C++). */
10541 static const char *
10542 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10544 return dwarf2_compute_name (name
, die
, cu
, 0);
10547 /* Construct a physname for the given DIE in CU. NAME may either be
10548 from a previous call to dwarf2_name or NULL. The result will be
10549 allocated on the objfile_objstack or NULL if the DIE does not have a
10552 The output string will be canonicalized (if C++). */
10554 static const char *
10555 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10557 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10558 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10561 /* In this case dwarf2_compute_name is just a shortcut not building anything
10563 if (!die_needs_namespace (die
, cu
))
10564 return dwarf2_compute_name (name
, die
, cu
, 1);
10566 if (cu
->language
!= language_rust
)
10567 mangled
= dw2_linkage_name (die
, cu
);
10569 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10571 gdb::unique_xmalloc_ptr
<char> demangled
;
10572 if (mangled
!= NULL
)
10575 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10577 /* Do nothing (do not demangle the symbol name). */
10579 else if (cu
->language
== language_go
)
10581 /* This is a lie, but we already lie to the caller new_symbol.
10582 new_symbol assumes we return the mangled name.
10583 This just undoes that lie until things are cleaned up. */
10587 /* Use DMGL_RET_DROP for C++ template functions to suppress
10588 their return type. It is easier for GDB users to search
10589 for such functions as `name(params)' than `long name(params)'.
10590 In such case the minimal symbol names do not match the full
10591 symbol names but for template functions there is never a need
10592 to look up their definition from their declaration so
10593 the only disadvantage remains the minimal symbol variant
10594 `long name(params)' does not have the proper inferior type. */
10595 demangled
.reset (gdb_demangle (mangled
,
10596 (DMGL_PARAMS
| DMGL_ANSI
10597 | DMGL_RET_DROP
)));
10600 canon
= demangled
.get ();
10608 if (canon
== NULL
|| check_physname
)
10610 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10612 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10614 /* It may not mean a bug in GDB. The compiler could also
10615 compute DW_AT_linkage_name incorrectly. But in such case
10616 GDB would need to be bug-to-bug compatible. */
10618 complaint (_("Computed physname <%s> does not match demangled <%s> "
10619 "(from linkage <%s>) - DIE at %s [in module %s]"),
10620 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10621 objfile_name (objfile
));
10623 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10624 is available here - over computed PHYSNAME. It is safer
10625 against both buggy GDB and buggy compilers. */
10639 retval
= objfile
->intern (retval
);
10644 /* Inspect DIE in CU for a namespace alias. If one exists, record
10645 a new symbol for it.
10647 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10650 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10652 struct attribute
*attr
;
10654 /* If the die does not have a name, this is not a namespace
10656 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10660 struct die_info
*d
= die
;
10661 struct dwarf2_cu
*imported_cu
= cu
;
10663 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10664 keep inspecting DIEs until we hit the underlying import. */
10665 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10666 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10668 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10672 d
= follow_die_ref (d
, attr
, &imported_cu
);
10673 if (d
->tag
!= DW_TAG_imported_declaration
)
10677 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10679 complaint (_("DIE at %s has too many recursively imported "
10680 "declarations"), sect_offset_str (d
->sect_off
));
10687 sect_offset sect_off
= attr
->get_ref_die_offset ();
10689 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10690 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10692 /* This declaration is a global namespace alias. Add
10693 a symbol for it whose type is the aliased namespace. */
10694 new_symbol (die
, type
, cu
);
10703 /* Return the using directives repository (global or local?) to use in the
10704 current context for CU.
10706 For Ada, imported declarations can materialize renamings, which *may* be
10707 global. However it is impossible (for now?) in DWARF to distinguish
10708 "external" imported declarations and "static" ones. As all imported
10709 declarations seem to be static in all other languages, make them all CU-wide
10710 global only in Ada. */
10712 static struct using_direct
**
10713 using_directives (struct dwarf2_cu
*cu
)
10715 if (cu
->language
== language_ada
10716 && cu
->get_builder ()->outermost_context_p ())
10717 return cu
->get_builder ()->get_global_using_directives ();
10719 return cu
->get_builder ()->get_local_using_directives ();
10722 /* Read the import statement specified by the given die and record it. */
10725 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10727 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10728 struct attribute
*import_attr
;
10729 struct die_info
*imported_die
, *child_die
;
10730 struct dwarf2_cu
*imported_cu
;
10731 const char *imported_name
;
10732 const char *imported_name_prefix
;
10733 const char *canonical_name
;
10734 const char *import_alias
;
10735 const char *imported_declaration
= NULL
;
10736 const char *import_prefix
;
10737 std::vector
<const char *> excludes
;
10739 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10740 if (import_attr
== NULL
)
10742 complaint (_("Tag '%s' has no DW_AT_import"),
10743 dwarf_tag_name (die
->tag
));
10748 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10749 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10750 if (imported_name
== NULL
)
10752 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10754 The import in the following code:
10768 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10769 <52> DW_AT_decl_file : 1
10770 <53> DW_AT_decl_line : 6
10771 <54> DW_AT_import : <0x75>
10772 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10773 <59> DW_AT_name : B
10774 <5b> DW_AT_decl_file : 1
10775 <5c> DW_AT_decl_line : 2
10776 <5d> DW_AT_type : <0x6e>
10778 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10779 <76> DW_AT_byte_size : 4
10780 <77> DW_AT_encoding : 5 (signed)
10782 imports the wrong die ( 0x75 instead of 0x58 ).
10783 This case will be ignored until the gcc bug is fixed. */
10787 /* Figure out the local name after import. */
10788 import_alias
= dwarf2_name (die
, cu
);
10790 /* Figure out where the statement is being imported to. */
10791 import_prefix
= determine_prefix (die
, cu
);
10793 /* Figure out what the scope of the imported die is and prepend it
10794 to the name of the imported die. */
10795 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10797 if (imported_die
->tag
!= DW_TAG_namespace
10798 && imported_die
->tag
!= DW_TAG_module
)
10800 imported_declaration
= imported_name
;
10801 canonical_name
= imported_name_prefix
;
10803 else if (strlen (imported_name_prefix
) > 0)
10804 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10805 imported_name_prefix
,
10806 (cu
->language
== language_d
? "." : "::"),
10807 imported_name
, (char *) NULL
);
10809 canonical_name
= imported_name
;
10811 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10812 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10813 child_die
= child_die
->sibling
)
10815 /* DWARF-4: A Fortran use statement with a “rename list” may be
10816 represented by an imported module entry with an import attribute
10817 referring to the module and owned entries corresponding to those
10818 entities that are renamed as part of being imported. */
10820 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10822 complaint (_("child DW_TAG_imported_declaration expected "
10823 "- DIE at %s [in module %s]"),
10824 sect_offset_str (child_die
->sect_off
),
10825 objfile_name (objfile
));
10829 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10830 if (import_attr
== NULL
)
10832 complaint (_("Tag '%s' has no DW_AT_import"),
10833 dwarf_tag_name (child_die
->tag
));
10838 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10840 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10841 if (imported_name
== NULL
)
10843 complaint (_("child DW_TAG_imported_declaration has unknown "
10844 "imported name - DIE at %s [in module %s]"),
10845 sect_offset_str (child_die
->sect_off
),
10846 objfile_name (objfile
));
10850 excludes
.push_back (imported_name
);
10852 process_die (child_die
, cu
);
10855 add_using_directive (using_directives (cu
),
10859 imported_declaration
,
10862 &objfile
->objfile_obstack
);
10865 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10866 types, but gives them a size of zero. Starting with version 14,
10867 ICC is compatible with GCC. */
10870 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10872 if (!cu
->checked_producer
)
10873 check_producer (cu
);
10875 return cu
->producer_is_icc_lt_14
;
10878 /* ICC generates a DW_AT_type for C void functions. This was observed on
10879 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10880 which says that void functions should not have a DW_AT_type. */
10883 producer_is_icc (struct dwarf2_cu
*cu
)
10885 if (!cu
->checked_producer
)
10886 check_producer (cu
);
10888 return cu
->producer_is_icc
;
10891 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10892 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10893 this, it was first present in GCC release 4.3.0. */
10896 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10898 if (!cu
->checked_producer
)
10899 check_producer (cu
);
10901 return cu
->producer_is_gcc_lt_4_3
;
10904 static file_and_directory
10905 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10907 file_and_directory res
;
10909 /* Find the filename. Do not use dwarf2_name here, since the filename
10910 is not a source language identifier. */
10911 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10912 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10914 if (res
.comp_dir
== NULL
10915 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10916 && IS_ABSOLUTE_PATH (res
.name
))
10918 res
.comp_dir_storage
= ldirname (res
.name
);
10919 if (!res
.comp_dir_storage
.empty ())
10920 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10922 if (res
.comp_dir
!= NULL
)
10924 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10925 directory, get rid of it. */
10926 const char *cp
= strchr (res
.comp_dir
, ':');
10928 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10929 res
.comp_dir
= cp
+ 1;
10932 if (res
.name
== NULL
)
10933 res
.name
= "<unknown>";
10938 /* Handle DW_AT_stmt_list for a compilation unit.
10939 DIE is the DW_TAG_compile_unit die for CU.
10940 COMP_DIR is the compilation directory. LOWPC is passed to
10941 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10944 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10945 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10947 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
10948 struct attribute
*attr
;
10949 struct line_header line_header_local
;
10950 hashval_t line_header_local_hash
;
10952 int decode_mapping
;
10954 gdb_assert (! cu
->per_cu
->is_debug_types
);
10956 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10960 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10962 /* The line header hash table is only created if needed (it exists to
10963 prevent redundant reading of the line table for partial_units).
10964 If we're given a partial_unit, we'll need it. If we're given a
10965 compile_unit, then use the line header hash table if it's already
10966 created, but don't create one just yet. */
10968 if (dwarf2_per_objfile
->line_header_hash
== NULL
10969 && die
->tag
== DW_TAG_partial_unit
)
10971 dwarf2_per_objfile
->line_header_hash
10972 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10973 line_header_eq_voidp
,
10974 free_line_header_voidp
,
10978 line_header_local
.sect_off
= line_offset
;
10979 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10980 line_header_local_hash
= line_header_hash (&line_header_local
);
10981 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10983 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10984 &line_header_local
,
10985 line_header_local_hash
, NO_INSERT
);
10987 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10988 is not present in *SLOT (since if there is something in *SLOT then
10989 it will be for a partial_unit). */
10990 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10992 gdb_assert (*slot
!= NULL
);
10993 cu
->line_header
= (struct line_header
*) *slot
;
10998 /* dwarf_decode_line_header does not yet provide sufficient information.
10999 We always have to call also dwarf_decode_lines for it. */
11000 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11004 cu
->line_header
= lh
.release ();
11005 cu
->line_header_die_owner
= die
;
11007 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11011 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
11012 &line_header_local
,
11013 line_header_local_hash
, INSERT
);
11014 gdb_assert (slot
!= NULL
);
11016 if (slot
!= NULL
&& *slot
== NULL
)
11018 /* This newly decoded line number information unit will be owned
11019 by line_header_hash hash table. */
11020 *slot
= cu
->line_header
;
11021 cu
->line_header_die_owner
= NULL
;
11025 /* We cannot free any current entry in (*slot) as that struct line_header
11026 may be already used by multiple CUs. Create only temporary decoded
11027 line_header for this CU - it may happen at most once for each line
11028 number information unit. And if we're not using line_header_hash
11029 then this is what we want as well. */
11030 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11032 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11033 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11038 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11041 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11043 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
11044 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11045 struct gdbarch
*gdbarch
= objfile
->arch ();
11046 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11047 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11048 struct attribute
*attr
;
11049 struct die_info
*child_die
;
11050 CORE_ADDR baseaddr
;
11052 prepare_one_comp_unit (cu
, die
, cu
->language
);
11053 baseaddr
= objfile
->text_section_offset ();
11055 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11057 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11058 from finish_block. */
11059 if (lowpc
== ((CORE_ADDR
) -1))
11061 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11063 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11065 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11066 standardised yet. As a workaround for the language detection we fall
11067 back to the DW_AT_producer string. */
11068 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11069 cu
->language
= language_opencl
;
11071 /* Similar hack for Go. */
11072 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11073 set_cu_language (DW_LANG_Go
, cu
);
11075 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11077 /* Decode line number information if present. We do this before
11078 processing child DIEs, so that the line header table is available
11079 for DW_AT_decl_file. */
11080 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11082 /* Process all dies in compilation unit. */
11083 if (die
->child
!= NULL
)
11085 child_die
= die
->child
;
11086 while (child_die
&& child_die
->tag
)
11088 process_die (child_die
, cu
);
11089 child_die
= child_die
->sibling
;
11093 /* Decode macro information, if present. Dwarf 2 macro information
11094 refers to information in the line number info statement program
11095 header, so we can only read it if we've read the header
11097 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11099 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11100 if (attr
&& cu
->line_header
)
11102 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11103 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11105 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11109 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11110 if (attr
&& cu
->line_header
)
11112 unsigned int macro_offset
= DW_UNSND (attr
);
11114 dwarf_decode_macros (cu
, macro_offset
, 0);
11120 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11122 struct type_unit_group
*tu_group
;
11124 struct attribute
*attr
;
11126 struct signatured_type
*sig_type
;
11128 gdb_assert (per_cu
->is_debug_types
);
11129 sig_type
= (struct signatured_type
*) per_cu
;
11131 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11133 /* If we're using .gdb_index (includes -readnow) then
11134 per_cu->type_unit_group may not have been set up yet. */
11135 if (sig_type
->type_unit_group
== NULL
)
11136 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11137 tu_group
= sig_type
->type_unit_group
;
11139 /* If we've already processed this stmt_list there's no real need to
11140 do it again, we could fake it and just recreate the part we need
11141 (file name,index -> symtab mapping). If data shows this optimization
11142 is useful we can do it then. */
11143 type_unit_group_unshareable
*tug_unshare
11144 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11145 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11147 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11152 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11153 lh
= dwarf_decode_line_header (line_offset
, this);
11158 start_symtab ("", NULL
, 0);
11161 gdb_assert (tug_unshare
->symtabs
== NULL
);
11162 gdb_assert (m_builder
== nullptr);
11163 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11164 m_builder
.reset (new struct buildsym_compunit
11165 (COMPUNIT_OBJFILE (cust
), "",
11166 COMPUNIT_DIRNAME (cust
),
11167 compunit_language (cust
),
11169 list_in_scope
= get_builder ()->get_file_symbols ();
11174 line_header
= lh
.release ();
11175 line_header_die_owner
= die
;
11179 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11181 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11182 still initializing it, and our caller (a few levels up)
11183 process_full_type_unit still needs to know if this is the first
11186 tug_unshare
->symtabs
11187 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11188 struct symtab
*, line_header
->file_names_size ());
11190 auto &file_names
= line_header
->file_names ();
11191 for (i
= 0; i
< file_names
.size (); ++i
)
11193 file_entry
&fe
= file_names
[i
];
11194 dwarf2_start_subfile (this, fe
.name
,
11195 fe
.include_dir (line_header
));
11196 buildsym_compunit
*b
= get_builder ();
11197 if (b
->get_current_subfile ()->symtab
== NULL
)
11199 /* NOTE: start_subfile will recognize when it's been
11200 passed a file it has already seen. So we can't
11201 assume there's a simple mapping from
11202 cu->line_header->file_names to subfiles, plus
11203 cu->line_header->file_names may contain dups. */
11204 b
->get_current_subfile ()->symtab
11205 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11208 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11209 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11214 gdb_assert (m_builder
== nullptr);
11215 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11216 m_builder
.reset (new struct buildsym_compunit
11217 (COMPUNIT_OBJFILE (cust
), "",
11218 COMPUNIT_DIRNAME (cust
),
11219 compunit_language (cust
),
11221 list_in_scope
= get_builder ()->get_file_symbols ();
11223 auto &file_names
= line_header
->file_names ();
11224 for (i
= 0; i
< file_names
.size (); ++i
)
11226 file_entry
&fe
= file_names
[i
];
11227 fe
.symtab
= tug_unshare
->symtabs
[i
];
11231 /* The main symtab is allocated last. Type units don't have DW_AT_name
11232 so they don't have a "real" (so to speak) symtab anyway.
11233 There is later code that will assign the main symtab to all symbols
11234 that don't have one. We need to handle the case of a symbol with a
11235 missing symtab (DW_AT_decl_file) anyway. */
11238 /* Process DW_TAG_type_unit.
11239 For TUs we want to skip the first top level sibling if it's not the
11240 actual type being defined by this TU. In this case the first top
11241 level sibling is there to provide context only. */
11244 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11246 struct die_info
*child_die
;
11248 prepare_one_comp_unit (cu
, die
, language_minimal
);
11250 /* Initialize (or reinitialize) the machinery for building symtabs.
11251 We do this before processing child DIEs, so that the line header table
11252 is available for DW_AT_decl_file. */
11253 cu
->setup_type_unit_groups (die
);
11255 if (die
->child
!= NULL
)
11257 child_die
= die
->child
;
11258 while (child_die
&& child_die
->tag
)
11260 process_die (child_die
, cu
);
11261 child_die
= child_die
->sibling
;
11268 http://gcc.gnu.org/wiki/DebugFission
11269 http://gcc.gnu.org/wiki/DebugFissionDWP
11271 To simplify handling of both DWO files ("object" files with the DWARF info)
11272 and DWP files (a file with the DWOs packaged up into one file), we treat
11273 DWP files as having a collection of virtual DWO files. */
11276 hash_dwo_file (const void *item
)
11278 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11281 hash
= htab_hash_string (dwo_file
->dwo_name
);
11282 if (dwo_file
->comp_dir
!= NULL
)
11283 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11288 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11290 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11291 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11293 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11295 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11296 return lhs
->comp_dir
== rhs
->comp_dir
;
11297 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11300 /* Allocate a hash table for DWO files. */
11303 allocate_dwo_file_hash_table ()
11305 auto delete_dwo_file
= [] (void *item
)
11307 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11312 return htab_up (htab_create_alloc (41,
11319 /* Lookup DWO file DWO_NAME. */
11322 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11323 const char *dwo_name
,
11324 const char *comp_dir
)
11326 struct dwo_file find_entry
;
11329 if (dwarf2_per_objfile
->per_bfd
->dwo_files
== NULL
)
11330 dwarf2_per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11332 find_entry
.dwo_name
= dwo_name
;
11333 find_entry
.comp_dir
= comp_dir
;
11334 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11341 hash_dwo_unit (const void *item
)
11343 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11345 /* This drops the top 32 bits of the id, but is ok for a hash. */
11346 return dwo_unit
->signature
;
11350 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11352 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11353 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11355 /* The signature is assumed to be unique within the DWO file.
11356 So while object file CU dwo_id's always have the value zero,
11357 that's OK, assuming each object file DWO file has only one CU,
11358 and that's the rule for now. */
11359 return lhs
->signature
== rhs
->signature
;
11362 /* Allocate a hash table for DWO CUs,TUs.
11363 There is one of these tables for each of CUs,TUs for each DWO file. */
11366 allocate_dwo_unit_table ()
11368 /* Start out with a pretty small number.
11369 Generally DWO files contain only one CU and maybe some TUs. */
11370 return htab_up (htab_create_alloc (3,
11373 NULL
, xcalloc
, xfree
));
11376 /* die_reader_func for create_dwo_cu. */
11379 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11380 const gdb_byte
*info_ptr
,
11381 struct die_info
*comp_unit_die
,
11382 struct dwo_file
*dwo_file
,
11383 struct dwo_unit
*dwo_unit
)
11385 struct dwarf2_cu
*cu
= reader
->cu
;
11386 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11387 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11389 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11390 if (!signature
.has_value ())
11392 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11393 " its dwo_id [in module %s]"),
11394 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11398 dwo_unit
->dwo_file
= dwo_file
;
11399 dwo_unit
->signature
= *signature
;
11400 dwo_unit
->section
= section
;
11401 dwo_unit
->sect_off
= sect_off
;
11402 dwo_unit
->length
= cu
->per_cu
->length
;
11404 if (dwarf_read_debug
)
11405 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11406 sect_offset_str (sect_off
),
11407 hex_string (dwo_unit
->signature
));
11410 /* Create the dwo_units for the CUs in a DWO_FILE.
11411 Note: This function processes DWO files only, not DWP files. */
11414 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11415 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11416 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11418 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11419 dwarf2_per_bfd
*per_bfd
= dwarf2_per_objfile
->per_bfd
;
11420 const gdb_byte
*info_ptr
, *end_ptr
;
11422 section
.read (objfile
);
11423 info_ptr
= section
.buffer
;
11425 if (info_ptr
== NULL
)
11428 if (dwarf_read_debug
)
11430 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11431 section
.get_name (),
11432 section
.get_file_name ());
11435 end_ptr
= info_ptr
+ section
.size
;
11436 while (info_ptr
< end_ptr
)
11438 struct dwarf2_per_cu_data per_cu
;
11439 struct dwo_unit read_unit
{};
11440 struct dwo_unit
*dwo_unit
;
11442 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11444 memset (&per_cu
, 0, sizeof (per_cu
));
11445 per_cu
.per_bfd
= per_bfd
;
11446 per_cu
.is_debug_types
= 0;
11447 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11448 per_cu
.section
= §ion
;
11450 cutu_reader
reader (&per_cu
, dwarf2_per_objfile
, cu
, &dwo_file
);
11451 if (!reader
.dummy_p
)
11452 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11453 &dwo_file
, &read_unit
);
11454 info_ptr
+= per_cu
.length
;
11456 // If the unit could not be parsed, skip it.
11457 if (read_unit
.dwo_file
== NULL
)
11460 if (cus_htab
== NULL
)
11461 cus_htab
= allocate_dwo_unit_table ();
11463 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11465 *dwo_unit
= read_unit
;
11466 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11467 gdb_assert (slot
!= NULL
);
11470 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11471 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11473 complaint (_("debug cu entry at offset %s is duplicate to"
11474 " the entry at offset %s, signature %s"),
11475 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11476 hex_string (dwo_unit
->signature
));
11478 *slot
= (void *)dwo_unit
;
11482 /* DWP file .debug_{cu,tu}_index section format:
11483 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11487 Both index sections have the same format, and serve to map a 64-bit
11488 signature to a set of section numbers. Each section begins with a header,
11489 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11490 indexes, and a pool of 32-bit section numbers. The index sections will be
11491 aligned at 8-byte boundaries in the file.
11493 The index section header consists of:
11495 V, 32 bit version number
11497 N, 32 bit number of compilation units or type units in the index
11498 M, 32 bit number of slots in the hash table
11500 Numbers are recorded using the byte order of the application binary.
11502 The hash table begins at offset 16 in the section, and consists of an array
11503 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11504 order of the application binary). Unused slots in the hash table are 0.
11505 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11507 The parallel table begins immediately after the hash table
11508 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11509 array of 32-bit indexes (using the byte order of the application binary),
11510 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11511 table contains a 32-bit index into the pool of section numbers. For unused
11512 hash table slots, the corresponding entry in the parallel table will be 0.
11514 The pool of section numbers begins immediately following the hash table
11515 (at offset 16 + 12 * M from the beginning of the section). The pool of
11516 section numbers consists of an array of 32-bit words (using the byte order
11517 of the application binary). Each item in the array is indexed starting
11518 from 0. The hash table entry provides the index of the first section
11519 number in the set. Additional section numbers in the set follow, and the
11520 set is terminated by a 0 entry (section number 0 is not used in ELF).
11522 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11523 section must be the first entry in the set, and the .debug_abbrev.dwo must
11524 be the second entry. Other members of the set may follow in any order.
11530 DWP Version 2 combines all the .debug_info, etc. sections into one,
11531 and the entries in the index tables are now offsets into these sections.
11532 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11535 Index Section Contents:
11537 Hash Table of Signatures dwp_hash_table.hash_table
11538 Parallel Table of Indices dwp_hash_table.unit_table
11539 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11540 Table of Section Sizes dwp_hash_table.v2.sizes
11542 The index section header consists of:
11544 V, 32 bit version number
11545 L, 32 bit number of columns in the table of section offsets
11546 N, 32 bit number of compilation units or type units in the index
11547 M, 32 bit number of slots in the hash table
11549 Numbers are recorded using the byte order of the application binary.
11551 The hash table has the same format as version 1.
11552 The parallel table of indices has the same format as version 1,
11553 except that the entries are origin-1 indices into the table of sections
11554 offsets and the table of section sizes.
11556 The table of offsets begins immediately following the parallel table
11557 (at offset 16 + 12 * M from the beginning of the section). The table is
11558 a two-dimensional array of 32-bit words (using the byte order of the
11559 application binary), with L columns and N+1 rows, in row-major order.
11560 Each row in the array is indexed starting from 0. The first row provides
11561 a key to the remaining rows: each column in this row provides an identifier
11562 for a debug section, and the offsets in the same column of subsequent rows
11563 refer to that section. The section identifiers are:
11565 DW_SECT_INFO 1 .debug_info.dwo
11566 DW_SECT_TYPES 2 .debug_types.dwo
11567 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11568 DW_SECT_LINE 4 .debug_line.dwo
11569 DW_SECT_LOC 5 .debug_loc.dwo
11570 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11571 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11572 DW_SECT_MACRO 8 .debug_macro.dwo
11574 The offsets provided by the CU and TU index sections are the base offsets
11575 for the contributions made by each CU or TU to the corresponding section
11576 in the package file. Each CU and TU header contains an abbrev_offset
11577 field, used to find the abbreviations table for that CU or TU within the
11578 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11579 be interpreted as relative to the base offset given in the index section.
11580 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11581 should be interpreted as relative to the base offset for .debug_line.dwo,
11582 and offsets into other debug sections obtained from DWARF attributes should
11583 also be interpreted as relative to the corresponding base offset.
11585 The table of sizes begins immediately following the table of offsets.
11586 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11587 with L columns and N rows, in row-major order. Each row in the array is
11588 indexed starting from 1 (row 0 is shared by the two tables).
11592 Hash table lookup is handled the same in version 1 and 2:
11594 We assume that N and M will not exceed 2^32 - 1.
11595 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11597 Given a 64-bit compilation unit signature or a type signature S, an entry
11598 in the hash table is located as follows:
11600 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11601 the low-order k bits all set to 1.
11603 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11605 3) If the hash table entry at index H matches the signature, use that
11606 entry. If the hash table entry at index H is unused (all zeroes),
11607 terminate the search: the signature is not present in the table.
11609 4) Let H = (H + H') modulo M. Repeat at Step 3.
11611 Because M > N and H' and M are relatively prime, the search is guaranteed
11612 to stop at an unused slot or find the match. */
11614 /* Create a hash table to map DWO IDs to their CU/TU entry in
11615 .debug_{info,types}.dwo in DWP_FILE.
11616 Returns NULL if there isn't one.
11617 Note: This function processes DWP files only, not DWO files. */
11619 static struct dwp_hash_table
*
11620 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11621 struct dwp_file
*dwp_file
, int is_debug_types
)
11623 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11624 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11625 const gdb_byte
*index_ptr
, *index_end
;
11626 struct dwarf2_section_info
*index
;
11627 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11628 struct dwp_hash_table
*htab
;
11630 if (is_debug_types
)
11631 index
= &dwp_file
->sections
.tu_index
;
11633 index
= &dwp_file
->sections
.cu_index
;
11635 if (index
->empty ())
11637 index
->read (objfile
);
11639 index_ptr
= index
->buffer
;
11640 index_end
= index_ptr
+ index
->size
;
11642 version
= read_4_bytes (dbfd
, index_ptr
);
11645 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11649 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11651 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11654 if (version
!= 1 && version
!= 2)
11656 error (_("Dwarf Error: unsupported DWP file version (%s)"
11657 " [in module %s]"),
11658 pulongest (version
), dwp_file
->name
);
11660 if (nr_slots
!= (nr_slots
& -nr_slots
))
11662 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11663 " is not power of 2 [in module %s]"),
11664 pulongest (nr_slots
), dwp_file
->name
);
11667 htab
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11668 htab
->version
= version
;
11669 htab
->nr_columns
= nr_columns
;
11670 htab
->nr_units
= nr_units
;
11671 htab
->nr_slots
= nr_slots
;
11672 htab
->hash_table
= index_ptr
;
11673 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11675 /* Exit early if the table is empty. */
11676 if (nr_slots
== 0 || nr_units
== 0
11677 || (version
== 2 && nr_columns
== 0))
11679 /* All must be zero. */
11680 if (nr_slots
!= 0 || nr_units
!= 0
11681 || (version
== 2 && nr_columns
!= 0))
11683 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11684 " all zero [in modules %s]"),
11692 htab
->section_pool
.v1
.indices
=
11693 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11694 /* It's harder to decide whether the section is too small in v1.
11695 V1 is deprecated anyway so we punt. */
11699 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11700 int *ids
= htab
->section_pool
.v2
.section_ids
;
11701 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11702 /* Reverse map for error checking. */
11703 int ids_seen
[DW_SECT_MAX
+ 1];
11706 if (nr_columns
< 2)
11708 error (_("Dwarf Error: bad DWP hash table, too few columns"
11709 " in section table [in module %s]"),
11712 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11714 error (_("Dwarf Error: bad DWP hash table, too many columns"
11715 " in section table [in module %s]"),
11718 memset (ids
, 255, sizeof_ids
);
11719 memset (ids_seen
, 255, sizeof (ids_seen
));
11720 for (i
= 0; i
< nr_columns
; ++i
)
11722 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11724 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11726 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11727 " in section table [in module %s]"),
11728 id
, dwp_file
->name
);
11730 if (ids_seen
[id
] != -1)
11732 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11733 " id %d in section table [in module %s]"),
11734 id
, dwp_file
->name
);
11739 /* Must have exactly one info or types section. */
11740 if (((ids_seen
[DW_SECT_INFO
] != -1)
11741 + (ids_seen
[DW_SECT_TYPES
] != -1))
11744 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11745 " DWO info/types section [in module %s]"),
11748 /* Must have an abbrev section. */
11749 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11751 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11752 " section [in module %s]"),
11755 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11756 htab
->section_pool
.v2
.sizes
=
11757 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11758 * nr_units
* nr_columns
);
11759 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11760 * nr_units
* nr_columns
))
11763 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11764 " [in module %s]"),
11772 /* Update SECTIONS with the data from SECTP.
11774 This function is like the other "locate" section routines that are
11775 passed to bfd_map_over_sections, but in this context the sections to
11776 read comes from the DWP V1 hash table, not the full ELF section table.
11778 The result is non-zero for success, or zero if an error was found. */
11781 locate_v1_virtual_dwo_sections (asection
*sectp
,
11782 struct virtual_v1_dwo_sections
*sections
)
11784 const struct dwop_section_names
*names
= &dwop_section_names
;
11786 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11788 /* There can be only one. */
11789 if (sections
->abbrev
.s
.section
!= NULL
)
11791 sections
->abbrev
.s
.section
= sectp
;
11792 sections
->abbrev
.size
= bfd_section_size (sectp
);
11794 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11795 || section_is_p (sectp
->name
, &names
->types_dwo
))
11797 /* There can be only one. */
11798 if (sections
->info_or_types
.s
.section
!= NULL
)
11800 sections
->info_or_types
.s
.section
= sectp
;
11801 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11803 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11805 /* There can be only one. */
11806 if (sections
->line
.s
.section
!= NULL
)
11808 sections
->line
.s
.section
= sectp
;
11809 sections
->line
.size
= bfd_section_size (sectp
);
11811 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11813 /* There can be only one. */
11814 if (sections
->loc
.s
.section
!= NULL
)
11816 sections
->loc
.s
.section
= sectp
;
11817 sections
->loc
.size
= bfd_section_size (sectp
);
11819 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11821 /* There can be only one. */
11822 if (sections
->macinfo
.s
.section
!= NULL
)
11824 sections
->macinfo
.s
.section
= sectp
;
11825 sections
->macinfo
.size
= bfd_section_size (sectp
);
11827 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11829 /* There can be only one. */
11830 if (sections
->macro
.s
.section
!= NULL
)
11832 sections
->macro
.s
.section
= sectp
;
11833 sections
->macro
.size
= bfd_section_size (sectp
);
11835 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11837 /* There can be only one. */
11838 if (sections
->str_offsets
.s
.section
!= NULL
)
11840 sections
->str_offsets
.s
.section
= sectp
;
11841 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11845 /* No other kind of section is valid. */
11852 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11853 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11854 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11855 This is for DWP version 1 files. */
11857 static struct dwo_unit
*
11858 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11859 struct dwp_file
*dwp_file
,
11860 uint32_t unit_index
,
11861 const char *comp_dir
,
11862 ULONGEST signature
, int is_debug_types
)
11864 const struct dwp_hash_table
*dwp_htab
=
11865 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11866 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11867 const char *kind
= is_debug_types
? "TU" : "CU";
11868 struct dwo_file
*dwo_file
;
11869 struct dwo_unit
*dwo_unit
;
11870 struct virtual_v1_dwo_sections sections
;
11871 void **dwo_file_slot
;
11874 gdb_assert (dwp_file
->version
== 1);
11876 if (dwarf_read_debug
)
11878 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11880 pulongest (unit_index
), hex_string (signature
),
11884 /* Fetch the sections of this DWO unit.
11885 Put a limit on the number of sections we look for so that bad data
11886 doesn't cause us to loop forever. */
11888 #define MAX_NR_V1_DWO_SECTIONS \
11889 (1 /* .debug_info or .debug_types */ \
11890 + 1 /* .debug_abbrev */ \
11891 + 1 /* .debug_line */ \
11892 + 1 /* .debug_loc */ \
11893 + 1 /* .debug_str_offsets */ \
11894 + 1 /* .debug_macro or .debug_macinfo */ \
11895 + 1 /* trailing zero */)
11897 memset (§ions
, 0, sizeof (sections
));
11899 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11902 uint32_t section_nr
=
11903 read_4_bytes (dbfd
,
11904 dwp_htab
->section_pool
.v1
.indices
11905 + (unit_index
+ i
) * sizeof (uint32_t));
11907 if (section_nr
== 0)
11909 if (section_nr
>= dwp_file
->num_sections
)
11911 error (_("Dwarf Error: bad DWP hash table, section number too large"
11912 " [in module %s]"),
11916 sectp
= dwp_file
->elf_sections
[section_nr
];
11917 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11919 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11920 " [in module %s]"),
11926 || sections
.info_or_types
.empty ()
11927 || sections
.abbrev
.empty ())
11929 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11930 " [in module %s]"),
11933 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11935 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11936 " [in module %s]"),
11940 /* It's easier for the rest of the code if we fake a struct dwo_file and
11941 have dwo_unit "live" in that. At least for now.
11943 The DWP file can be made up of a random collection of CUs and TUs.
11944 However, for each CU + set of TUs that came from the same original DWO
11945 file, we can combine them back into a virtual DWO file to save space
11946 (fewer struct dwo_file objects to allocate). Remember that for really
11947 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11949 std::string virtual_dwo_name
=
11950 string_printf ("virtual-dwo/%d-%d-%d-%d",
11951 sections
.abbrev
.get_id (),
11952 sections
.line
.get_id (),
11953 sections
.loc
.get_id (),
11954 sections
.str_offsets
.get_id ());
11955 /* Can we use an existing virtual DWO file? */
11956 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11957 virtual_dwo_name
.c_str (),
11959 /* Create one if necessary. */
11960 if (*dwo_file_slot
== NULL
)
11962 if (dwarf_read_debug
)
11964 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11965 virtual_dwo_name
.c_str ());
11967 dwo_file
= new struct dwo_file
;
11968 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
11969 dwo_file
->comp_dir
= comp_dir
;
11970 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11971 dwo_file
->sections
.line
= sections
.line
;
11972 dwo_file
->sections
.loc
= sections
.loc
;
11973 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11974 dwo_file
->sections
.macro
= sections
.macro
;
11975 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11976 /* The "str" section is global to the entire DWP file. */
11977 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11978 /* The info or types section is assigned below to dwo_unit,
11979 there's no need to record it in dwo_file.
11980 Also, we can't simply record type sections in dwo_file because
11981 we record a pointer into the vector in dwo_unit. As we collect more
11982 types we'll grow the vector and eventually have to reallocate space
11983 for it, invalidating all copies of pointers into the previous
11985 *dwo_file_slot
= dwo_file
;
11989 if (dwarf_read_debug
)
11991 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11992 virtual_dwo_name
.c_str ());
11994 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11997 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11998 dwo_unit
->dwo_file
= dwo_file
;
11999 dwo_unit
->signature
= signature
;
12000 dwo_unit
->section
=
12001 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12002 *dwo_unit
->section
= sections
.info_or_types
;
12003 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12008 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12009 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12010 piece within that section used by a TU/CU, return a virtual section
12011 of just that piece. */
12013 static struct dwarf2_section_info
12014 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12015 struct dwarf2_section_info
*section
,
12016 bfd_size_type offset
, bfd_size_type size
)
12018 struct dwarf2_section_info result
;
12021 gdb_assert (section
!= NULL
);
12022 gdb_assert (!section
->is_virtual
);
12024 memset (&result
, 0, sizeof (result
));
12025 result
.s
.containing_section
= section
;
12026 result
.is_virtual
= true;
12031 sectp
= section
->get_bfd_section ();
12033 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12034 bounds of the real section. This is a pretty-rare event, so just
12035 flag an error (easier) instead of a warning and trying to cope. */
12037 || offset
+ size
> bfd_section_size (sectp
))
12039 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12040 " in section %s [in module %s]"),
12041 sectp
? bfd_section_name (sectp
) : "<unknown>",
12042 objfile_name (dwarf2_per_objfile
->objfile
));
12045 result
.virtual_offset
= offset
;
12046 result
.size
= size
;
12050 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12051 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12052 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12053 This is for DWP version 2 files. */
12055 static struct dwo_unit
*
12056 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12057 struct dwp_file
*dwp_file
,
12058 uint32_t unit_index
,
12059 const char *comp_dir
,
12060 ULONGEST signature
, int is_debug_types
)
12062 const struct dwp_hash_table
*dwp_htab
=
12063 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12064 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12065 const char *kind
= is_debug_types
? "TU" : "CU";
12066 struct dwo_file
*dwo_file
;
12067 struct dwo_unit
*dwo_unit
;
12068 struct virtual_v2_dwo_sections sections
;
12069 void **dwo_file_slot
;
12072 gdb_assert (dwp_file
->version
== 2);
12074 if (dwarf_read_debug
)
12076 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12078 pulongest (unit_index
), hex_string (signature
),
12082 /* Fetch the section offsets of this DWO unit. */
12084 memset (§ions
, 0, sizeof (sections
));
12086 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12088 uint32_t offset
= read_4_bytes (dbfd
,
12089 dwp_htab
->section_pool
.v2
.offsets
12090 + (((unit_index
- 1) * dwp_htab
->nr_columns
12092 * sizeof (uint32_t)));
12093 uint32_t size
= read_4_bytes (dbfd
,
12094 dwp_htab
->section_pool
.v2
.sizes
12095 + (((unit_index
- 1) * dwp_htab
->nr_columns
12097 * sizeof (uint32_t)));
12099 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12102 case DW_SECT_TYPES
:
12103 sections
.info_or_types_offset
= offset
;
12104 sections
.info_or_types_size
= size
;
12106 case DW_SECT_ABBREV
:
12107 sections
.abbrev_offset
= offset
;
12108 sections
.abbrev_size
= size
;
12111 sections
.line_offset
= offset
;
12112 sections
.line_size
= size
;
12115 sections
.loc_offset
= offset
;
12116 sections
.loc_size
= size
;
12118 case DW_SECT_STR_OFFSETS
:
12119 sections
.str_offsets_offset
= offset
;
12120 sections
.str_offsets_size
= size
;
12122 case DW_SECT_MACINFO
:
12123 sections
.macinfo_offset
= offset
;
12124 sections
.macinfo_size
= size
;
12126 case DW_SECT_MACRO
:
12127 sections
.macro_offset
= offset
;
12128 sections
.macro_size
= size
;
12133 /* It's easier for the rest of the code if we fake a struct dwo_file and
12134 have dwo_unit "live" in that. At least for now.
12136 The DWP file can be made up of a random collection of CUs and TUs.
12137 However, for each CU + set of TUs that came from the same original DWO
12138 file, we can combine them back into a virtual DWO file to save space
12139 (fewer struct dwo_file objects to allocate). Remember that for really
12140 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12142 std::string virtual_dwo_name
=
12143 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12144 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12145 (long) (sections
.line_size
? sections
.line_offset
: 0),
12146 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12147 (long) (sections
.str_offsets_size
12148 ? sections
.str_offsets_offset
: 0));
12149 /* Can we use an existing virtual DWO file? */
12150 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12151 virtual_dwo_name
.c_str (),
12153 /* Create one if necessary. */
12154 if (*dwo_file_slot
== NULL
)
12156 if (dwarf_read_debug
)
12158 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12159 virtual_dwo_name
.c_str ());
12161 dwo_file
= new struct dwo_file
;
12162 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
12163 dwo_file
->comp_dir
= comp_dir
;
12164 dwo_file
->sections
.abbrev
=
12165 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12166 sections
.abbrev_offset
, sections
.abbrev_size
);
12167 dwo_file
->sections
.line
=
12168 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12169 sections
.line_offset
, sections
.line_size
);
12170 dwo_file
->sections
.loc
=
12171 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12172 sections
.loc_offset
, sections
.loc_size
);
12173 dwo_file
->sections
.macinfo
=
12174 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12175 sections
.macinfo_offset
, sections
.macinfo_size
);
12176 dwo_file
->sections
.macro
=
12177 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12178 sections
.macro_offset
, sections
.macro_size
);
12179 dwo_file
->sections
.str_offsets
=
12180 create_dwp_v2_section (dwarf2_per_objfile
,
12181 &dwp_file
->sections
.str_offsets
,
12182 sections
.str_offsets_offset
,
12183 sections
.str_offsets_size
);
12184 /* The "str" section is global to the entire DWP file. */
12185 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12186 /* The info or types section is assigned below to dwo_unit,
12187 there's no need to record it in dwo_file.
12188 Also, we can't simply record type sections in dwo_file because
12189 we record a pointer into the vector in dwo_unit. As we collect more
12190 types we'll grow the vector and eventually have to reallocate space
12191 for it, invalidating all copies of pointers into the previous
12193 *dwo_file_slot
= dwo_file
;
12197 if (dwarf_read_debug
)
12199 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12200 virtual_dwo_name
.c_str ());
12202 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12205 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12206 dwo_unit
->dwo_file
= dwo_file
;
12207 dwo_unit
->signature
= signature
;
12208 dwo_unit
->section
=
12209 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12210 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12212 ? &dwp_file
->sections
.types
12213 : &dwp_file
->sections
.info
,
12214 sections
.info_or_types_offset
,
12215 sections
.info_or_types_size
);
12216 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12221 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12222 Returns NULL if the signature isn't found. */
12224 static struct dwo_unit
*
12225 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12226 struct dwp_file
*dwp_file
, const char *comp_dir
,
12227 ULONGEST signature
, int is_debug_types
)
12229 const struct dwp_hash_table
*dwp_htab
=
12230 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12231 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12232 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12233 uint32_t hash
= signature
& mask
;
12234 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12237 struct dwo_unit find_dwo_cu
;
12239 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12240 find_dwo_cu
.signature
= signature
;
12241 slot
= htab_find_slot (is_debug_types
12242 ? dwp_file
->loaded_tus
.get ()
12243 : dwp_file
->loaded_cus
.get (),
12244 &find_dwo_cu
, INSERT
);
12247 return (struct dwo_unit
*) *slot
;
12249 /* Use a for loop so that we don't loop forever on bad debug info. */
12250 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12252 ULONGEST signature_in_table
;
12254 signature_in_table
=
12255 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12256 if (signature_in_table
== signature
)
12258 uint32_t unit_index
=
12259 read_4_bytes (dbfd
,
12260 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12262 if (dwp_file
->version
== 1)
12264 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12265 dwp_file
, unit_index
,
12266 comp_dir
, signature
,
12271 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12272 dwp_file
, unit_index
,
12273 comp_dir
, signature
,
12276 return (struct dwo_unit
*) *slot
;
12278 if (signature_in_table
== 0)
12280 hash
= (hash
+ hash2
) & mask
;
12283 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12284 " [in module %s]"),
12288 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12289 Open the file specified by FILE_NAME and hand it off to BFD for
12290 preliminary analysis. Return a newly initialized bfd *, which
12291 includes a canonicalized copy of FILE_NAME.
12292 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12293 SEARCH_CWD is true if the current directory is to be searched.
12294 It will be searched before debug-file-directory.
12295 If successful, the file is added to the bfd include table of the
12296 objfile's bfd (see gdb_bfd_record_inclusion).
12297 If unable to find/open the file, return NULL.
12298 NOTE: This function is derived from symfile_bfd_open. */
12300 static gdb_bfd_ref_ptr
12301 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12302 const char *file_name
, int is_dwp
, int search_cwd
)
12305 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12306 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12307 to debug_file_directory. */
12308 const char *search_path
;
12309 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12311 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12314 if (*debug_file_directory
!= '\0')
12316 search_path_holder
.reset (concat (".", dirname_separator_string
,
12317 debug_file_directory
,
12319 search_path
= search_path_holder
.get ();
12325 search_path
= debug_file_directory
;
12327 openp_flags flags
= OPF_RETURN_REALPATH
;
12329 flags
|= OPF_SEARCH_IN_PATH
;
12331 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12332 desc
= openp (search_path
, flags
, file_name
,
12333 O_RDONLY
| O_BINARY
, &absolute_name
);
12337 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12339 if (sym_bfd
== NULL
)
12341 bfd_set_cacheable (sym_bfd
.get (), 1);
12343 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12346 /* Success. Record the bfd as having been included by the objfile's bfd.
12347 This is important because things like demangled_names_hash lives in the
12348 objfile's per_bfd space and may have references to things like symbol
12349 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12350 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12355 /* Try to open DWO file FILE_NAME.
12356 COMP_DIR is the DW_AT_comp_dir attribute.
12357 The result is the bfd handle of the file.
12358 If there is a problem finding or opening the file, return NULL.
12359 Upon success, the canonicalized path of the file is stored in the bfd,
12360 same as symfile_bfd_open. */
12362 static gdb_bfd_ref_ptr
12363 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12364 const char *file_name
, const char *comp_dir
)
12366 if (IS_ABSOLUTE_PATH (file_name
))
12367 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12368 0 /*is_dwp*/, 0 /*search_cwd*/);
12370 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12372 if (comp_dir
!= NULL
)
12374 gdb::unique_xmalloc_ptr
<char> path_to_try
12375 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12377 /* NOTE: If comp_dir is a relative path, this will also try the
12378 search path, which seems useful. */
12379 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12380 path_to_try
.get (),
12382 1 /*search_cwd*/));
12387 /* That didn't work, try debug-file-directory, which, despite its name,
12388 is a list of paths. */
12390 if (*debug_file_directory
== '\0')
12393 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12394 0 /*is_dwp*/, 1 /*search_cwd*/);
12397 /* This function is mapped across the sections and remembers the offset and
12398 size of each of the DWO debugging sections we are interested in. */
12401 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12403 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12404 const struct dwop_section_names
*names
= &dwop_section_names
;
12406 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12408 dwo_sections
->abbrev
.s
.section
= sectp
;
12409 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12411 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12413 dwo_sections
->info
.s
.section
= sectp
;
12414 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12416 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12418 dwo_sections
->line
.s
.section
= sectp
;
12419 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12421 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12423 dwo_sections
->loc
.s
.section
= sectp
;
12424 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12426 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12428 dwo_sections
->loclists
.s
.section
= sectp
;
12429 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12431 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12433 dwo_sections
->macinfo
.s
.section
= sectp
;
12434 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12436 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12438 dwo_sections
->macro
.s
.section
= sectp
;
12439 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12441 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12443 dwo_sections
->str
.s
.section
= sectp
;
12444 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12446 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12448 dwo_sections
->str_offsets
.s
.section
= sectp
;
12449 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12451 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12453 struct dwarf2_section_info type_section
;
12455 memset (&type_section
, 0, sizeof (type_section
));
12456 type_section
.s
.section
= sectp
;
12457 type_section
.size
= bfd_section_size (sectp
);
12458 dwo_sections
->types
.push_back (type_section
);
12462 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12463 by PER_CU. This is for the non-DWP case.
12464 The result is NULL if DWO_NAME can't be found. */
12466 static struct dwo_file
*
12467 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12468 const char *comp_dir
)
12470 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12472 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12475 if (dwarf_read_debug
)
12476 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12480 dwo_file_up
dwo_file (new struct dwo_file
);
12481 dwo_file
->dwo_name
= dwo_name
;
12482 dwo_file
->comp_dir
= comp_dir
;
12483 dwo_file
->dbfd
= std::move (dbfd
);
12485 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12486 &dwo_file
->sections
);
12488 create_cus_hash_table (dwarf2_per_objfile
, cu
, *dwo_file
,
12489 dwo_file
->sections
.info
, dwo_file
->cus
);
12491 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12492 dwo_file
->sections
.types
, dwo_file
->tus
);
12494 if (dwarf_read_debug
)
12495 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12497 return dwo_file
.release ();
12500 /* This function is mapped across the sections and remembers the offset and
12501 size of each of the DWP debugging sections common to version 1 and 2 that
12502 we are interested in. */
12505 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12506 void *dwp_file_ptr
)
12508 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12509 const struct dwop_section_names
*names
= &dwop_section_names
;
12510 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12512 /* Record the ELF section number for later lookup: this is what the
12513 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12514 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12515 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12517 /* Look for specific sections that we need. */
12518 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12520 dwp_file
->sections
.str
.s
.section
= sectp
;
12521 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12523 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12525 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12526 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12528 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12530 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12531 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12535 /* This function is mapped across the sections and remembers the offset and
12536 size of each of the DWP version 2 debugging sections that we are interested
12537 in. This is split into a separate function because we don't know if we
12538 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12541 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12543 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12544 const struct dwop_section_names
*names
= &dwop_section_names
;
12545 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12547 /* Record the ELF section number for later lookup: this is what the
12548 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12549 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12550 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12552 /* Look for specific sections that we need. */
12553 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12555 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12556 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12558 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12560 dwp_file
->sections
.info
.s
.section
= sectp
;
12561 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12563 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12565 dwp_file
->sections
.line
.s
.section
= sectp
;
12566 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12568 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12570 dwp_file
->sections
.loc
.s
.section
= sectp
;
12571 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12573 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12575 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12576 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12578 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12580 dwp_file
->sections
.macro
.s
.section
= sectp
;
12581 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12583 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12585 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12586 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12588 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12590 dwp_file
->sections
.types
.s
.section
= sectp
;
12591 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12595 /* Hash function for dwp_file loaded CUs/TUs. */
12598 hash_dwp_loaded_cutus (const void *item
)
12600 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12602 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12603 return dwo_unit
->signature
;
12606 /* Equality function for dwp_file loaded CUs/TUs. */
12609 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12611 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12612 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12614 return dua
->signature
== dub
->signature
;
12617 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12620 allocate_dwp_loaded_cutus_table ()
12622 return htab_up (htab_create_alloc (3,
12623 hash_dwp_loaded_cutus
,
12624 eq_dwp_loaded_cutus
,
12625 NULL
, xcalloc
, xfree
));
12628 /* Try to open DWP file FILE_NAME.
12629 The result is the bfd handle of the file.
12630 If there is a problem finding or opening the file, return NULL.
12631 Upon success, the canonicalized path of the file is stored in the bfd,
12632 same as symfile_bfd_open. */
12634 static gdb_bfd_ref_ptr
12635 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12636 const char *file_name
)
12638 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12640 1 /*search_cwd*/));
12644 /* Work around upstream bug 15652.
12645 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12646 [Whether that's a "bug" is debatable, but it is getting in our way.]
12647 We have no real idea where the dwp file is, because gdb's realpath-ing
12648 of the executable's path may have discarded the needed info.
12649 [IWBN if the dwp file name was recorded in the executable, akin to
12650 .gnu_debuglink, but that doesn't exist yet.]
12651 Strip the directory from FILE_NAME and search again. */
12652 if (*debug_file_directory
!= '\0')
12654 /* Don't implicitly search the current directory here.
12655 If the user wants to search "." to handle this case,
12656 it must be added to debug-file-directory. */
12657 return try_open_dwop_file (dwarf2_per_objfile
,
12658 lbasename (file_name
), 1 /*is_dwp*/,
12665 /* Initialize the use of the DWP file for the current objfile.
12666 By convention the name of the DWP file is ${objfile}.dwp.
12667 The result is NULL if it can't be found. */
12669 static std::unique_ptr
<struct dwp_file
>
12670 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12672 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12674 /* Try to find first .dwp for the binary file before any symbolic links
12677 /* If the objfile is a debug file, find the name of the real binary
12678 file and get the name of dwp file from there. */
12679 std::string dwp_name
;
12680 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12682 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12683 const char *backlink_basename
= lbasename (backlink
->original_name
);
12685 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12688 dwp_name
= objfile
->original_name
;
12690 dwp_name
+= ".dwp";
12692 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12694 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12696 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12697 dwp_name
= objfile_name (objfile
);
12698 dwp_name
+= ".dwp";
12699 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12704 if (dwarf_read_debug
)
12705 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12706 return std::unique_ptr
<dwp_file
> ();
12709 const char *name
= bfd_get_filename (dbfd
.get ());
12710 std::unique_ptr
<struct dwp_file
> dwp_file
12711 (new struct dwp_file (name
, std::move (dbfd
)));
12713 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12714 dwp_file
->elf_sections
=
12715 OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
12716 dwp_file
->num_sections
, asection
*);
12718 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12719 dwarf2_locate_common_dwp_sections
,
12722 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12725 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12728 /* The DWP file version is stored in the hash table. Oh well. */
12729 if (dwp_file
->cus
&& dwp_file
->tus
12730 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12732 /* Technically speaking, we should try to limp along, but this is
12733 pretty bizarre. We use pulongest here because that's the established
12734 portability solution (e.g, we cannot use %u for uint32_t). */
12735 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12736 " TU version %s [in DWP file %s]"),
12737 pulongest (dwp_file
->cus
->version
),
12738 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12742 dwp_file
->version
= dwp_file
->cus
->version
;
12743 else if (dwp_file
->tus
)
12744 dwp_file
->version
= dwp_file
->tus
->version
;
12746 dwp_file
->version
= 2;
12748 if (dwp_file
->version
== 2)
12749 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12750 dwarf2_locate_v2_dwp_sections
,
12753 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12754 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12756 if (dwarf_read_debug
)
12758 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12759 fprintf_unfiltered (gdb_stdlog
,
12760 " %s CUs, %s TUs\n",
12761 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12762 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12768 /* Wrapper around open_and_init_dwp_file, only open it once. */
12770 static struct dwp_file
*
12771 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12773 if (! dwarf2_per_objfile
->per_bfd
->dwp_checked
)
12775 dwarf2_per_objfile
->per_bfd
->dwp_file
12776 = open_and_init_dwp_file (dwarf2_per_objfile
);
12777 dwarf2_per_objfile
->per_bfd
->dwp_checked
= 1;
12779 return dwarf2_per_objfile
->per_bfd
->dwp_file
.get ();
12782 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12783 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12784 or in the DWP file for the objfile, referenced by THIS_UNIT.
12785 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12786 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12788 This is called, for example, when wanting to read a variable with a
12789 complex location. Therefore we don't want to do file i/o for every call.
12790 Therefore we don't want to look for a DWO file on every call.
12791 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12792 then we check if we've already seen DWO_NAME, and only THEN do we check
12795 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12796 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12798 static struct dwo_unit
*
12799 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12800 ULONGEST signature
, int is_debug_types
)
12802 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
12803 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12804 const char *kind
= is_debug_types
? "TU" : "CU";
12805 void **dwo_file_slot
;
12806 struct dwo_file
*dwo_file
;
12807 struct dwp_file
*dwp_file
;
12809 /* First see if there's a DWP file.
12810 If we have a DWP file but didn't find the DWO inside it, don't
12811 look for the original DWO file. It makes gdb behave differently
12812 depending on whether one is debugging in the build tree. */
12814 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12815 if (dwp_file
!= NULL
)
12817 const struct dwp_hash_table
*dwp_htab
=
12818 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12820 if (dwp_htab
!= NULL
)
12822 struct dwo_unit
*dwo_cutu
=
12823 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12824 signature
, is_debug_types
);
12826 if (dwo_cutu
!= NULL
)
12828 if (dwarf_read_debug
)
12830 fprintf_unfiltered (gdb_stdlog
,
12831 "Virtual DWO %s %s found: @%s\n",
12832 kind
, hex_string (signature
),
12833 host_address_to_string (dwo_cutu
));
12841 /* No DWP file, look for the DWO file. */
12843 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12844 dwo_name
, comp_dir
);
12845 if (*dwo_file_slot
== NULL
)
12847 /* Read in the file and build a table of the CUs/TUs it contains. */
12848 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12850 /* NOTE: This will be NULL if unable to open the file. */
12851 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12853 if (dwo_file
!= NULL
)
12855 struct dwo_unit
*dwo_cutu
= NULL
;
12857 if (is_debug_types
&& dwo_file
->tus
)
12859 struct dwo_unit find_dwo_cutu
;
12861 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12862 find_dwo_cutu
.signature
= signature
;
12864 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12867 else if (!is_debug_types
&& dwo_file
->cus
)
12869 struct dwo_unit find_dwo_cutu
;
12871 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12872 find_dwo_cutu
.signature
= signature
;
12873 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12877 if (dwo_cutu
!= NULL
)
12879 if (dwarf_read_debug
)
12881 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12882 kind
, dwo_name
, hex_string (signature
),
12883 host_address_to_string (dwo_cutu
));
12890 /* We didn't find it. This could mean a dwo_id mismatch, or
12891 someone deleted the DWO/DWP file, or the search path isn't set up
12892 correctly to find the file. */
12894 if (dwarf_read_debug
)
12896 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12897 kind
, dwo_name
, hex_string (signature
));
12900 /* This is a warning and not a complaint because it can be caused by
12901 pilot error (e.g., user accidentally deleting the DWO). */
12903 /* Print the name of the DWP file if we looked there, helps the user
12904 better diagnose the problem. */
12905 std::string dwp_text
;
12907 if (dwp_file
!= NULL
)
12908 dwp_text
= string_printf (" [in DWP file %s]",
12909 lbasename (dwp_file
->name
));
12911 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12912 " [in module %s]"),
12913 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12914 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12919 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12920 See lookup_dwo_cutu_unit for details. */
12922 static struct dwo_unit
*
12923 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12924 ULONGEST signature
)
12926 gdb_assert (!cu
->per_cu
->is_debug_types
);
12928 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12931 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12932 See lookup_dwo_cutu_unit for details. */
12934 static struct dwo_unit
*
12935 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12937 gdb_assert (cu
->per_cu
->is_debug_types
);
12939 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12941 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12944 /* Traversal function for queue_and_load_all_dwo_tus. */
12947 queue_and_load_dwo_tu (void **slot
, void *info
)
12949 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12950 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12951 ULONGEST signature
= dwo_unit
->signature
;
12952 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12954 if (sig_type
!= NULL
)
12956 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12958 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12959 a real dependency of PER_CU on SIG_TYPE. That is detected later
12960 while processing PER_CU. */
12961 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
12962 load_full_type_unit (sig_cu
, cu
->per_objfile
);
12963 cu
->per_cu
->imported_symtabs_push (sig_cu
);
12969 /* Queue all TUs contained in the DWO of CU to be read in.
12970 The DWO may have the only definition of the type, though it may not be
12971 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12972 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12975 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12977 struct dwo_unit
*dwo_unit
;
12978 struct dwo_file
*dwo_file
;
12980 gdb_assert (cu
!= nullptr);
12981 gdb_assert (!cu
->per_cu
->is_debug_types
);
12982 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12984 dwo_unit
= cu
->dwo_unit
;
12985 gdb_assert (dwo_unit
!= NULL
);
12987 dwo_file
= dwo_unit
->dwo_file
;
12988 if (dwo_file
->tus
!= NULL
)
12989 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12992 /* Read in various DIEs. */
12994 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12995 Inherit only the children of the DW_AT_abstract_origin DIE not being
12996 already referenced by DW_AT_abstract_origin from the children of the
13000 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13002 struct die_info
*child_die
;
13003 sect_offset
*offsetp
;
13004 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13005 struct die_info
*origin_die
;
13006 /* Iterator of the ORIGIN_DIE children. */
13007 struct die_info
*origin_child_die
;
13008 struct attribute
*attr
;
13009 struct dwarf2_cu
*origin_cu
;
13010 struct pending
**origin_previous_list_in_scope
;
13012 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13016 /* Note that following die references may follow to a die in a
13020 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13022 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13024 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13025 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13027 if (die
->tag
!= origin_die
->tag
13028 && !(die
->tag
== DW_TAG_inlined_subroutine
13029 && origin_die
->tag
== DW_TAG_subprogram
))
13030 complaint (_("DIE %s and its abstract origin %s have different tags"),
13031 sect_offset_str (die
->sect_off
),
13032 sect_offset_str (origin_die
->sect_off
));
13034 std::vector
<sect_offset
> offsets
;
13036 for (child_die
= die
->child
;
13037 child_die
&& child_die
->tag
;
13038 child_die
= child_die
->sibling
)
13040 struct die_info
*child_origin_die
;
13041 struct dwarf2_cu
*child_origin_cu
;
13043 /* We are trying to process concrete instance entries:
13044 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13045 it's not relevant to our analysis here. i.e. detecting DIEs that are
13046 present in the abstract instance but not referenced in the concrete
13048 if (child_die
->tag
== DW_TAG_call_site
13049 || child_die
->tag
== DW_TAG_GNU_call_site
)
13052 /* For each CHILD_DIE, find the corresponding child of
13053 ORIGIN_DIE. If there is more than one layer of
13054 DW_AT_abstract_origin, follow them all; there shouldn't be,
13055 but GCC versions at least through 4.4 generate this (GCC PR
13057 child_origin_die
= child_die
;
13058 child_origin_cu
= cu
;
13061 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13065 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13069 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13070 counterpart may exist. */
13071 if (child_origin_die
!= child_die
)
13073 if (child_die
->tag
!= child_origin_die
->tag
13074 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13075 && child_origin_die
->tag
== DW_TAG_subprogram
))
13076 complaint (_("Child DIE %s and its abstract origin %s have "
13078 sect_offset_str (child_die
->sect_off
),
13079 sect_offset_str (child_origin_die
->sect_off
));
13080 if (child_origin_die
->parent
!= origin_die
)
13081 complaint (_("Child DIE %s and its abstract origin %s have "
13082 "different parents"),
13083 sect_offset_str (child_die
->sect_off
),
13084 sect_offset_str (child_origin_die
->sect_off
));
13086 offsets
.push_back (child_origin_die
->sect_off
);
13089 std::sort (offsets
.begin (), offsets
.end ());
13090 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13091 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13092 if (offsetp
[-1] == *offsetp
)
13093 complaint (_("Multiple children of DIE %s refer "
13094 "to DIE %s as their abstract origin"),
13095 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13097 offsetp
= offsets
.data ();
13098 origin_child_die
= origin_die
->child
;
13099 while (origin_child_die
&& origin_child_die
->tag
)
13101 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13102 while (offsetp
< offsets_end
13103 && *offsetp
< origin_child_die
->sect_off
)
13105 if (offsetp
>= offsets_end
13106 || *offsetp
> origin_child_die
->sect_off
)
13108 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13109 Check whether we're already processing ORIGIN_CHILD_DIE.
13110 This can happen with mutually referenced abstract_origins.
13112 if (!origin_child_die
->in_process
)
13113 process_die (origin_child_die
, origin_cu
);
13115 origin_child_die
= origin_child_die
->sibling
;
13117 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13119 if (cu
!= origin_cu
)
13120 compute_delayed_physnames (origin_cu
);
13124 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13126 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13127 struct gdbarch
*gdbarch
= objfile
->arch ();
13128 struct context_stack
*newobj
;
13131 struct die_info
*child_die
;
13132 struct attribute
*attr
, *call_line
, *call_file
;
13134 CORE_ADDR baseaddr
;
13135 struct block
*block
;
13136 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13137 std::vector
<struct symbol
*> template_args
;
13138 struct template_symbol
*templ_func
= NULL
;
13142 /* If we do not have call site information, we can't show the
13143 caller of this inlined function. That's too confusing, so
13144 only use the scope for local variables. */
13145 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13146 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13147 if (call_line
== NULL
|| call_file
== NULL
)
13149 read_lexical_block_scope (die
, cu
);
13154 baseaddr
= objfile
->text_section_offset ();
13156 name
= dwarf2_name (die
, cu
);
13158 /* Ignore functions with missing or empty names. These are actually
13159 illegal according to the DWARF standard. */
13162 complaint (_("missing name for subprogram DIE at %s"),
13163 sect_offset_str (die
->sect_off
));
13167 /* Ignore functions with missing or invalid low and high pc attributes. */
13168 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13169 <= PC_BOUNDS_INVALID
)
13171 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13172 if (!attr
|| !DW_UNSND (attr
))
13173 complaint (_("cannot get low and high bounds "
13174 "for subprogram DIE at %s"),
13175 sect_offset_str (die
->sect_off
));
13179 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13180 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13182 /* If we have any template arguments, then we must allocate a
13183 different sort of symbol. */
13184 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13186 if (child_die
->tag
== DW_TAG_template_type_param
13187 || child_die
->tag
== DW_TAG_template_value_param
)
13189 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13190 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13195 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13196 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13197 (struct symbol
*) templ_func
);
13199 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13200 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13203 /* If there is a location expression for DW_AT_frame_base, record
13205 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13206 if (attr
!= nullptr)
13207 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13209 /* If there is a location for the static link, record it. */
13210 newobj
->static_link
= NULL
;
13211 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13212 if (attr
!= nullptr)
13214 newobj
->static_link
13215 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13216 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13220 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13222 if (die
->child
!= NULL
)
13224 child_die
= die
->child
;
13225 while (child_die
&& child_die
->tag
)
13227 if (child_die
->tag
== DW_TAG_template_type_param
13228 || child_die
->tag
== DW_TAG_template_value_param
)
13230 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13233 template_args
.push_back (arg
);
13236 process_die (child_die
, cu
);
13237 child_die
= child_die
->sibling
;
13241 inherit_abstract_dies (die
, cu
);
13243 /* If we have a DW_AT_specification, we might need to import using
13244 directives from the context of the specification DIE. See the
13245 comment in determine_prefix. */
13246 if (cu
->language
== language_cplus
13247 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13249 struct dwarf2_cu
*spec_cu
= cu
;
13250 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13254 child_die
= spec_die
->child
;
13255 while (child_die
&& child_die
->tag
)
13257 if (child_die
->tag
== DW_TAG_imported_module
)
13258 process_die (child_die
, spec_cu
);
13259 child_die
= child_die
->sibling
;
13262 /* In some cases, GCC generates specification DIEs that
13263 themselves contain DW_AT_specification attributes. */
13264 spec_die
= die_specification (spec_die
, &spec_cu
);
13268 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13269 /* Make a block for the local symbols within. */
13270 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13271 cstk
.static_link
, lowpc
, highpc
);
13273 /* For C++, set the block's scope. */
13274 if ((cu
->language
== language_cplus
13275 || cu
->language
== language_fortran
13276 || cu
->language
== language_d
13277 || cu
->language
== language_rust
)
13278 && cu
->processing_has_namespace_info
)
13279 block_set_scope (block
, determine_prefix (die
, cu
),
13280 &objfile
->objfile_obstack
);
13282 /* If we have address ranges, record them. */
13283 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13285 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13287 /* Attach template arguments to function. */
13288 if (!template_args
.empty ())
13290 gdb_assert (templ_func
!= NULL
);
13292 templ_func
->n_template_arguments
= template_args
.size ();
13293 templ_func
->template_arguments
13294 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13295 templ_func
->n_template_arguments
);
13296 memcpy (templ_func
->template_arguments
,
13297 template_args
.data (),
13298 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13300 /* Make sure that the symtab is set on the new symbols. Even
13301 though they don't appear in this symtab directly, other parts
13302 of gdb assume that symbols do, and this is reasonably
13304 for (symbol
*sym
: template_args
)
13305 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13308 /* In C++, we can have functions nested inside functions (e.g., when
13309 a function declares a class that has methods). This means that
13310 when we finish processing a function scope, we may need to go
13311 back to building a containing block's symbol lists. */
13312 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13313 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13315 /* If we've finished processing a top-level function, subsequent
13316 symbols go in the file symbol list. */
13317 if (cu
->get_builder ()->outermost_context_p ())
13318 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13321 /* Process all the DIES contained within a lexical block scope. Start
13322 a new scope, process the dies, and then close the scope. */
13325 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13327 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13328 struct gdbarch
*gdbarch
= objfile
->arch ();
13329 CORE_ADDR lowpc
, highpc
;
13330 struct die_info
*child_die
;
13331 CORE_ADDR baseaddr
;
13333 baseaddr
= objfile
->text_section_offset ();
13335 /* Ignore blocks with missing or invalid low and high pc attributes. */
13336 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13337 as multiple lexical blocks? Handling children in a sane way would
13338 be nasty. Might be easier to properly extend generic blocks to
13339 describe ranges. */
13340 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13342 case PC_BOUNDS_NOT_PRESENT
:
13343 /* DW_TAG_lexical_block has no attributes, process its children as if
13344 there was no wrapping by that DW_TAG_lexical_block.
13345 GCC does no longer produces such DWARF since GCC r224161. */
13346 for (child_die
= die
->child
;
13347 child_die
!= NULL
&& child_die
->tag
;
13348 child_die
= child_die
->sibling
)
13350 /* We might already be processing this DIE. This can happen
13351 in an unusual circumstance -- where a subroutine A
13352 appears lexically in another subroutine B, but A actually
13353 inlines B. The recursion is broken here, rather than in
13354 inherit_abstract_dies, because it seems better to simply
13355 drop concrete children here. */
13356 if (!child_die
->in_process
)
13357 process_die (child_die
, cu
);
13360 case PC_BOUNDS_INVALID
:
13363 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13364 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13366 cu
->get_builder ()->push_context (0, lowpc
);
13367 if (die
->child
!= NULL
)
13369 child_die
= die
->child
;
13370 while (child_die
&& child_die
->tag
)
13372 process_die (child_die
, cu
);
13373 child_die
= child_die
->sibling
;
13376 inherit_abstract_dies (die
, cu
);
13377 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13379 if (*cu
->get_builder ()->get_local_symbols () != NULL
13380 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13382 struct block
*block
13383 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13384 cstk
.start_addr
, highpc
);
13386 /* Note that recording ranges after traversing children, as we
13387 do here, means that recording a parent's ranges entails
13388 walking across all its children's ranges as they appear in
13389 the address map, which is quadratic behavior.
13391 It would be nicer to record the parent's ranges before
13392 traversing its children, simply overriding whatever you find
13393 there. But since we don't even decide whether to create a
13394 block until after we've traversed its children, that's hard
13396 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13398 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13399 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13402 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13405 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13407 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13408 struct objfile
*objfile
= per_objfile
->objfile
;
13409 struct gdbarch
*gdbarch
= objfile
->arch ();
13410 CORE_ADDR pc
, baseaddr
;
13411 struct attribute
*attr
;
13412 struct call_site
*call_site
, call_site_local
;
13415 struct die_info
*child_die
;
13417 baseaddr
= objfile
->text_section_offset ();
13419 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13422 /* This was a pre-DWARF-5 GNU extension alias
13423 for DW_AT_call_return_pc. */
13424 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13428 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13429 "DIE %s [in module %s]"),
13430 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13433 pc
= attr
->value_as_address () + baseaddr
;
13434 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13436 if (cu
->call_site_htab
== NULL
)
13437 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13438 NULL
, &objfile
->objfile_obstack
,
13439 hashtab_obstack_allocate
, NULL
);
13440 call_site_local
.pc
= pc
;
13441 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13444 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13445 "DIE %s [in module %s]"),
13446 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13447 objfile_name (objfile
));
13451 /* Count parameters at the caller. */
13454 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13455 child_die
= child_die
->sibling
)
13457 if (child_die
->tag
!= DW_TAG_call_site_parameter
13458 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13460 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13461 "DW_TAG_call_site child DIE %s [in module %s]"),
13462 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13463 objfile_name (objfile
));
13471 = ((struct call_site
*)
13472 obstack_alloc (&objfile
->objfile_obstack
,
13473 sizeof (*call_site
)
13474 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13476 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13477 call_site
->pc
= pc
;
13479 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13480 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13482 struct die_info
*func_die
;
13484 /* Skip also over DW_TAG_inlined_subroutine. */
13485 for (func_die
= die
->parent
;
13486 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13487 && func_die
->tag
!= DW_TAG_subroutine_type
;
13488 func_die
= func_die
->parent
);
13490 /* DW_AT_call_all_calls is a superset
13491 of DW_AT_call_all_tail_calls. */
13493 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13494 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13495 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13496 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13498 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13499 not complete. But keep CALL_SITE for look ups via call_site_htab,
13500 both the initial caller containing the real return address PC and
13501 the final callee containing the current PC of a chain of tail
13502 calls do not need to have the tail call list complete. But any
13503 function candidate for a virtual tail call frame searched via
13504 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13505 determined unambiguously. */
13509 struct type
*func_type
= NULL
;
13512 func_type
= get_die_type (func_die
, cu
);
13513 if (func_type
!= NULL
)
13515 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13517 /* Enlist this call site to the function. */
13518 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13519 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13522 complaint (_("Cannot find function owning DW_TAG_call_site "
13523 "DIE %s [in module %s]"),
13524 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13528 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13530 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13532 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13535 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13536 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13538 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13539 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13540 /* Keep NULL DWARF_BLOCK. */;
13541 else if (attr
->form_is_block ())
13543 struct dwarf2_locexpr_baton
*dlbaton
;
13545 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13546 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13547 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13548 dlbaton
->per_objfile
= per_objfile
;
13549 dlbaton
->per_cu
= cu
->per_cu
;
13551 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13553 else if (attr
->form_is_ref ())
13555 struct dwarf2_cu
*target_cu
= cu
;
13556 struct die_info
*target_die
;
13558 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13559 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13560 if (die_is_declaration (target_die
, target_cu
))
13562 const char *target_physname
;
13564 /* Prefer the mangled name; otherwise compute the demangled one. */
13565 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13566 if (target_physname
== NULL
)
13567 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13568 if (target_physname
== NULL
)
13569 complaint (_("DW_AT_call_target target DIE has invalid "
13570 "physname, for referencing DIE %s [in module %s]"),
13571 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13573 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13579 /* DW_AT_entry_pc should be preferred. */
13580 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13581 <= PC_BOUNDS_INVALID
)
13582 complaint (_("DW_AT_call_target target DIE has invalid "
13583 "low pc, for referencing DIE %s [in module %s]"),
13584 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13587 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13588 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13593 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13594 "block nor reference, for DIE %s [in module %s]"),
13595 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13597 call_site
->per_cu
= cu
->per_cu
;
13598 call_site
->per_objfile
= per_objfile
;
13600 for (child_die
= die
->child
;
13601 child_die
&& child_die
->tag
;
13602 child_die
= child_die
->sibling
)
13604 struct call_site_parameter
*parameter
;
13605 struct attribute
*loc
, *origin
;
13607 if (child_die
->tag
!= DW_TAG_call_site_parameter
13608 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13610 /* Already printed the complaint above. */
13614 gdb_assert (call_site
->parameter_count
< nparams
);
13615 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13617 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13618 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13619 register is contained in DW_AT_call_value. */
13621 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13622 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13623 if (origin
== NULL
)
13625 /* This was a pre-DWARF-5 GNU extension alias
13626 for DW_AT_call_parameter. */
13627 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13629 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13631 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13633 sect_offset sect_off
= origin
->get_ref_die_offset ();
13634 if (!cu
->header
.offset_in_cu_p (sect_off
))
13636 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13637 binding can be done only inside one CU. Such referenced DIE
13638 therefore cannot be even moved to DW_TAG_partial_unit. */
13639 complaint (_("DW_AT_call_parameter offset is not in CU for "
13640 "DW_TAG_call_site child DIE %s [in module %s]"),
13641 sect_offset_str (child_die
->sect_off
),
13642 objfile_name (objfile
));
13645 parameter
->u
.param_cu_off
13646 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13648 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13650 complaint (_("No DW_FORM_block* DW_AT_location for "
13651 "DW_TAG_call_site child DIE %s [in module %s]"),
13652 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13657 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13658 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13659 if (parameter
->u
.dwarf_reg
!= -1)
13660 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13661 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13662 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13663 ¶meter
->u
.fb_offset
))
13664 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13667 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13668 "for DW_FORM_block* DW_AT_location is supported for "
13669 "DW_TAG_call_site child DIE %s "
13671 sect_offset_str (child_die
->sect_off
),
13672 objfile_name (objfile
));
13677 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13679 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13680 if (attr
== NULL
|| !attr
->form_is_block ())
13682 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13683 "DW_TAG_call_site child DIE %s [in module %s]"),
13684 sect_offset_str (child_die
->sect_off
),
13685 objfile_name (objfile
));
13688 parameter
->value
= DW_BLOCK (attr
)->data
;
13689 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13691 /* Parameters are not pre-cleared by memset above. */
13692 parameter
->data_value
= NULL
;
13693 parameter
->data_value_size
= 0;
13694 call_site
->parameter_count
++;
13696 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13698 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13699 if (attr
!= nullptr)
13701 if (!attr
->form_is_block ())
13702 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13703 "DW_TAG_call_site child DIE %s [in module %s]"),
13704 sect_offset_str (child_die
->sect_off
),
13705 objfile_name (objfile
));
13708 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13709 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13715 /* Helper function for read_variable. If DIE represents a virtual
13716 table, then return the type of the concrete object that is
13717 associated with the virtual table. Otherwise, return NULL. */
13719 static struct type
*
13720 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13722 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13726 /* Find the type DIE. */
13727 struct die_info
*type_die
= NULL
;
13728 struct dwarf2_cu
*type_cu
= cu
;
13730 if (attr
->form_is_ref ())
13731 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13732 if (type_die
== NULL
)
13735 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13737 return die_containing_type (type_die
, type_cu
);
13740 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13743 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13745 struct rust_vtable_symbol
*storage
= NULL
;
13747 if (cu
->language
== language_rust
)
13749 struct type
*containing_type
= rust_containing_type (die
, cu
);
13751 if (containing_type
!= NULL
)
13753 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13755 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13756 storage
->concrete_type
= containing_type
;
13757 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13761 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13762 struct attribute
*abstract_origin
13763 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13764 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13765 if (res
== NULL
&& loc
&& abstract_origin
)
13767 /* We have a variable without a name, but with a location and an abstract
13768 origin. This may be a concrete instance of an abstract variable
13769 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13771 struct dwarf2_cu
*origin_cu
= cu
;
13772 struct die_info
*origin_die
13773 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13774 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13775 per_objfile
->per_bfd
->abstract_to_concrete
13776 [origin_die
->sect_off
].push_back (die
->sect_off
);
13780 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13781 reading .debug_rnglists.
13782 Callback's type should be:
13783 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13784 Return true if the attributes are present and valid, otherwise,
13787 template <typename Callback
>
13789 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13790 Callback
&&callback
)
13792 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
13793 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13794 bfd
*obfd
= objfile
->obfd
;
13795 /* Base address selection entry. */
13796 gdb::optional
<CORE_ADDR
> base
;
13797 const gdb_byte
*buffer
;
13798 CORE_ADDR baseaddr
;
13799 bool overflow
= false;
13801 base
= cu
->base_address
;
13803 dwarf2_per_objfile
->per_bfd
->rnglists
.read (objfile
);
13804 if (offset
>= dwarf2_per_objfile
->per_bfd
->rnglists
.size
)
13806 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13810 buffer
= dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13812 baseaddr
= objfile
->text_section_offset ();
13816 /* Initialize it due to a false compiler warning. */
13817 CORE_ADDR range_beginning
= 0, range_end
= 0;
13818 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
13819 + dwarf2_per_objfile
->per_bfd
->rnglists
.size
);
13820 unsigned int bytes_read
;
13822 if (buffer
== buf_end
)
13827 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13830 case DW_RLE_end_of_list
:
13832 case DW_RLE_base_address
:
13833 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13838 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13839 buffer
+= bytes_read
;
13841 case DW_RLE_start_length
:
13842 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13847 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13849 buffer
+= bytes_read
;
13850 range_end
= (range_beginning
13851 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13852 buffer
+= bytes_read
;
13853 if (buffer
> buf_end
)
13859 case DW_RLE_offset_pair
:
13860 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13861 buffer
+= bytes_read
;
13862 if (buffer
> buf_end
)
13867 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13868 buffer
+= bytes_read
;
13869 if (buffer
> buf_end
)
13875 case DW_RLE_start_end
:
13876 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13881 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13883 buffer
+= bytes_read
;
13884 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13885 buffer
+= bytes_read
;
13888 complaint (_("Invalid .debug_rnglists data (no base address)"));
13891 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13893 if (rlet
== DW_RLE_base_address
)
13896 if (!base
.has_value ())
13898 /* We have no valid base address for the ranges
13900 complaint (_("Invalid .debug_rnglists data (no base address)"));
13904 if (range_beginning
> range_end
)
13906 /* Inverted range entries are invalid. */
13907 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13911 /* Empty range entries have no effect. */
13912 if (range_beginning
== range_end
)
13915 range_beginning
+= *base
;
13916 range_end
+= *base
;
13918 /* A not-uncommon case of bad debug info.
13919 Don't pollute the addrmap with bad data. */
13920 if (range_beginning
+ baseaddr
== 0
13921 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
13923 complaint (_(".debug_rnglists entry has start address of zero"
13924 " [in module %s]"), objfile_name (objfile
));
13928 callback (range_beginning
, range_end
);
13933 complaint (_("Offset %d is not terminated "
13934 "for DW_AT_ranges attribute"),
13942 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13943 Callback's type should be:
13944 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13945 Return 1 if the attributes are present and valid, otherwise, return 0. */
13947 template <typename Callback
>
13949 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13950 Callback
&&callback
)
13952 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13953 struct objfile
*objfile
= per_objfile
->objfile
;
13954 struct comp_unit_head
*cu_header
= &cu
->header
;
13955 bfd
*obfd
= objfile
->obfd
;
13956 unsigned int addr_size
= cu_header
->addr_size
;
13957 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13958 /* Base address selection entry. */
13959 gdb::optional
<CORE_ADDR
> base
;
13960 unsigned int dummy
;
13961 const gdb_byte
*buffer
;
13962 CORE_ADDR baseaddr
;
13964 if (cu_header
->version
>= 5)
13965 return dwarf2_rnglists_process (offset
, cu
, callback
);
13967 base
= cu
->base_address
;
13969 per_objfile
->per_bfd
->ranges
.read (objfile
);
13970 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13972 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13976 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13978 baseaddr
= objfile
->text_section_offset ();
13982 CORE_ADDR range_beginning
, range_end
;
13984 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13985 buffer
+= addr_size
;
13986 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13987 buffer
+= addr_size
;
13988 offset
+= 2 * addr_size
;
13990 /* An end of list marker is a pair of zero addresses. */
13991 if (range_beginning
== 0 && range_end
== 0)
13992 /* Found the end of list entry. */
13995 /* Each base address selection entry is a pair of 2 values.
13996 The first is the largest possible address, the second is
13997 the base address. Check for a base address here. */
13998 if ((range_beginning
& mask
) == mask
)
14000 /* If we found the largest possible address, then we already
14001 have the base address in range_end. */
14006 if (!base
.has_value ())
14008 /* We have no valid base address for the ranges
14010 complaint (_("Invalid .debug_ranges data (no base address)"));
14014 if (range_beginning
> range_end
)
14016 /* Inverted range entries are invalid. */
14017 complaint (_("Invalid .debug_ranges data (inverted range)"));
14021 /* Empty range entries have no effect. */
14022 if (range_beginning
== range_end
)
14025 range_beginning
+= *base
;
14026 range_end
+= *base
;
14028 /* A not-uncommon case of bad debug info.
14029 Don't pollute the addrmap with bad data. */
14030 if (range_beginning
+ baseaddr
== 0
14031 && !per_objfile
->per_bfd
->has_section_at_zero
)
14033 complaint (_(".debug_ranges entry has start address of zero"
14034 " [in module %s]"), objfile_name (objfile
));
14038 callback (range_beginning
, range_end
);
14044 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14045 Return 1 if the attributes are present and valid, otherwise, return 0.
14046 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14049 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14050 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14051 dwarf2_psymtab
*ranges_pst
)
14053 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14054 struct gdbarch
*gdbarch
= objfile
->arch ();
14055 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14058 CORE_ADDR high
= 0;
14061 retval
= dwarf2_ranges_process (offset
, cu
,
14062 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14064 if (ranges_pst
!= NULL
)
14069 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14070 range_beginning
+ baseaddr
)
14072 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14073 range_end
+ baseaddr
)
14075 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14076 lowpc
, highpc
- 1, ranges_pst
);
14079 /* FIXME: This is recording everything as a low-high
14080 segment of consecutive addresses. We should have a
14081 data structure for discontiguous block ranges
14085 low
= range_beginning
;
14091 if (range_beginning
< low
)
14092 low
= range_beginning
;
14093 if (range_end
> high
)
14101 /* If the first entry is an end-of-list marker, the range
14102 describes an empty scope, i.e. no instructions. */
14108 *high_return
= high
;
14112 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14113 definition for the return value. *LOWPC and *HIGHPC are set iff
14114 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14116 static enum pc_bounds_kind
14117 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14118 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14119 dwarf2_psymtab
*pst
)
14121 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
14122 struct attribute
*attr
;
14123 struct attribute
*attr_high
;
14125 CORE_ADDR high
= 0;
14126 enum pc_bounds_kind ret
;
14128 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14131 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14132 if (attr
!= nullptr)
14134 low
= attr
->value_as_address ();
14135 high
= attr_high
->value_as_address ();
14136 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14140 /* Found high w/o low attribute. */
14141 return PC_BOUNDS_INVALID
;
14143 /* Found consecutive range of addresses. */
14144 ret
= PC_BOUNDS_HIGH_LOW
;
14148 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14151 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14152 We take advantage of the fact that DW_AT_ranges does not appear
14153 in DW_TAG_compile_unit of DWO files. */
14154 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14155 unsigned int ranges_offset
= (DW_UNSND (attr
)
14156 + (need_ranges_base
14160 /* Value of the DW_AT_ranges attribute is the offset in the
14161 .debug_ranges section. */
14162 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14163 return PC_BOUNDS_INVALID
;
14164 /* Found discontinuous range of addresses. */
14165 ret
= PC_BOUNDS_RANGES
;
14168 return PC_BOUNDS_NOT_PRESENT
;
14171 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14173 return PC_BOUNDS_INVALID
;
14175 /* When using the GNU linker, .gnu.linkonce. sections are used to
14176 eliminate duplicate copies of functions and vtables and such.
14177 The linker will arbitrarily choose one and discard the others.
14178 The AT_*_pc values for such functions refer to local labels in
14179 these sections. If the section from that file was discarded, the
14180 labels are not in the output, so the relocs get a value of 0.
14181 If this is a discarded function, mark the pc bounds as invalid,
14182 so that GDB will ignore it. */
14183 if (low
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
14184 return PC_BOUNDS_INVALID
;
14192 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14193 its low and high PC addresses. Do nothing if these addresses could not
14194 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14195 and HIGHPC to the high address if greater than HIGHPC. */
14198 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14199 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14200 struct dwarf2_cu
*cu
)
14202 CORE_ADDR low
, high
;
14203 struct die_info
*child
= die
->child
;
14205 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14207 *lowpc
= std::min (*lowpc
, low
);
14208 *highpc
= std::max (*highpc
, high
);
14211 /* If the language does not allow nested subprograms (either inside
14212 subprograms or lexical blocks), we're done. */
14213 if (cu
->language
!= language_ada
)
14216 /* Check all the children of the given DIE. If it contains nested
14217 subprograms, then check their pc bounds. Likewise, we need to
14218 check lexical blocks as well, as they may also contain subprogram
14220 while (child
&& child
->tag
)
14222 if (child
->tag
== DW_TAG_subprogram
14223 || child
->tag
== DW_TAG_lexical_block
)
14224 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14225 child
= child
->sibling
;
14229 /* Get the low and high pc's represented by the scope DIE, and store
14230 them in *LOWPC and *HIGHPC. If the correct values can't be
14231 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14234 get_scope_pc_bounds (struct die_info
*die
,
14235 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14236 struct dwarf2_cu
*cu
)
14238 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14239 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14240 CORE_ADDR current_low
, current_high
;
14242 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14243 >= PC_BOUNDS_RANGES
)
14245 best_low
= current_low
;
14246 best_high
= current_high
;
14250 struct die_info
*child
= die
->child
;
14252 while (child
&& child
->tag
)
14254 switch (child
->tag
) {
14255 case DW_TAG_subprogram
:
14256 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14258 case DW_TAG_namespace
:
14259 case DW_TAG_module
:
14260 /* FIXME: carlton/2004-01-16: Should we do this for
14261 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14262 that current GCC's always emit the DIEs corresponding
14263 to definitions of methods of classes as children of a
14264 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14265 the DIEs giving the declarations, which could be
14266 anywhere). But I don't see any reason why the
14267 standards says that they have to be there. */
14268 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14270 if (current_low
!= ((CORE_ADDR
) -1))
14272 best_low
= std::min (best_low
, current_low
);
14273 best_high
= std::max (best_high
, current_high
);
14281 child
= child
->sibling
;
14286 *highpc
= best_high
;
14289 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14293 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14294 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14296 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14297 struct gdbarch
*gdbarch
= objfile
->arch ();
14298 struct attribute
*attr
;
14299 struct attribute
*attr_high
;
14301 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14304 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14305 if (attr
!= nullptr)
14307 CORE_ADDR low
= attr
->value_as_address ();
14308 CORE_ADDR high
= attr_high
->value_as_address ();
14310 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14313 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14314 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14315 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14319 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14320 if (attr
!= nullptr)
14322 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14323 We take advantage of the fact that DW_AT_ranges does not appear
14324 in DW_TAG_compile_unit of DWO files. */
14325 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14327 /* The value of the DW_AT_ranges attribute is the offset of the
14328 address range list in the .debug_ranges section. */
14329 unsigned long offset
= (DW_UNSND (attr
)
14330 + (need_ranges_base
? cu
->ranges_base
: 0));
14332 std::vector
<blockrange
> blockvec
;
14333 dwarf2_ranges_process (offset
, cu
,
14334 [&] (CORE_ADDR start
, CORE_ADDR end
)
14338 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14339 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14340 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14341 blockvec
.emplace_back (start
, end
);
14344 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14348 /* Check whether the producer field indicates either of GCC < 4.6, or the
14349 Intel C/C++ compiler, and cache the result in CU. */
14352 check_producer (struct dwarf2_cu
*cu
)
14356 if (cu
->producer
== NULL
)
14358 /* For unknown compilers expect their behavior is DWARF version
14361 GCC started to support .debug_types sections by -gdwarf-4 since
14362 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14363 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14364 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14365 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14367 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14369 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14370 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14372 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14374 cu
->producer_is_icc
= true;
14375 cu
->producer_is_icc_lt_14
= major
< 14;
14377 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14378 cu
->producer_is_codewarrior
= true;
14381 /* For other non-GCC compilers, expect their behavior is DWARF version
14385 cu
->checked_producer
= true;
14388 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14389 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14390 during 4.6.0 experimental. */
14393 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14395 if (!cu
->checked_producer
)
14396 check_producer (cu
);
14398 return cu
->producer_is_gxx_lt_4_6
;
14402 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14403 with incorrect is_stmt attributes. */
14406 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14408 if (!cu
->checked_producer
)
14409 check_producer (cu
);
14411 return cu
->producer_is_codewarrior
;
14414 /* Return the default accessibility type if it is not overridden by
14415 DW_AT_accessibility. */
14417 static enum dwarf_access_attribute
14418 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14420 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14422 /* The default DWARF 2 accessibility for members is public, the default
14423 accessibility for inheritance is private. */
14425 if (die
->tag
!= DW_TAG_inheritance
)
14426 return DW_ACCESS_public
;
14428 return DW_ACCESS_private
;
14432 /* DWARF 3+ defines the default accessibility a different way. The same
14433 rules apply now for DW_TAG_inheritance as for the members and it only
14434 depends on the container kind. */
14436 if (die
->parent
->tag
== DW_TAG_class_type
)
14437 return DW_ACCESS_private
;
14439 return DW_ACCESS_public
;
14443 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14444 offset. If the attribute was not found return 0, otherwise return
14445 1. If it was found but could not properly be handled, set *OFFSET
14449 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14452 struct attribute
*attr
;
14454 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14459 /* Note that we do not check for a section offset first here.
14460 This is because DW_AT_data_member_location is new in DWARF 4,
14461 so if we see it, we can assume that a constant form is really
14462 a constant and not a section offset. */
14463 if (attr
->form_is_constant ())
14464 *offset
= attr
->constant_value (0);
14465 else if (attr
->form_is_section_offset ())
14466 dwarf2_complex_location_expr_complaint ();
14467 else if (attr
->form_is_block ())
14468 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14470 dwarf2_complex_location_expr_complaint ();
14478 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14481 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14482 struct field
*field
)
14484 struct attribute
*attr
;
14486 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14489 if (attr
->form_is_constant ())
14491 LONGEST offset
= attr
->constant_value (0);
14492 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14494 else if (attr
->form_is_section_offset ())
14495 dwarf2_complex_location_expr_complaint ();
14496 else if (attr
->form_is_block ())
14499 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14501 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14504 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14505 struct objfile
*objfile
= per_objfile
->objfile
;
14506 struct dwarf2_locexpr_baton
*dlbaton
14507 = XOBNEW (&objfile
->objfile_obstack
,
14508 struct dwarf2_locexpr_baton
);
14509 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14510 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14511 /* When using this baton, we want to compute the address
14512 of the field, not the value. This is why
14513 is_reference is set to false here. */
14514 dlbaton
->is_reference
= false;
14515 dlbaton
->per_objfile
= per_objfile
;
14516 dlbaton
->per_cu
= cu
->per_cu
;
14518 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14522 dwarf2_complex_location_expr_complaint ();
14526 /* Add an aggregate field to the field list. */
14529 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14530 struct dwarf2_cu
*cu
)
14532 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14533 struct gdbarch
*gdbarch
= objfile
->arch ();
14534 struct nextfield
*new_field
;
14535 struct attribute
*attr
;
14537 const char *fieldname
= "";
14539 if (die
->tag
== DW_TAG_inheritance
)
14541 fip
->baseclasses
.emplace_back ();
14542 new_field
= &fip
->baseclasses
.back ();
14546 fip
->fields
.emplace_back ();
14547 new_field
= &fip
->fields
.back ();
14550 new_field
->offset
= die
->sect_off
;
14552 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14553 if (attr
!= nullptr)
14554 new_field
->accessibility
= DW_UNSND (attr
);
14556 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14557 if (new_field
->accessibility
!= DW_ACCESS_public
)
14558 fip
->non_public_fields
= 1;
14560 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14561 if (attr
!= nullptr)
14562 new_field
->virtuality
= DW_UNSND (attr
);
14564 new_field
->virtuality
= DW_VIRTUALITY_none
;
14566 fp
= &new_field
->field
;
14568 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14570 /* Data member other than a C++ static data member. */
14572 /* Get type of field. */
14573 fp
->type
= die_type (die
, cu
);
14575 SET_FIELD_BITPOS (*fp
, 0);
14577 /* Get bit size of field (zero if none). */
14578 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14579 if (attr
!= nullptr)
14581 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14585 FIELD_BITSIZE (*fp
) = 0;
14588 /* Get bit offset of field. */
14589 handle_data_member_location (die
, cu
, fp
);
14590 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14591 if (attr
!= nullptr)
14593 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14595 /* For big endian bits, the DW_AT_bit_offset gives the
14596 additional bit offset from the MSB of the containing
14597 anonymous object to the MSB of the field. We don't
14598 have to do anything special since we don't need to
14599 know the size of the anonymous object. */
14600 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14604 /* For little endian bits, compute the bit offset to the
14605 MSB of the anonymous object, subtract off the number of
14606 bits from the MSB of the field to the MSB of the
14607 object, and then subtract off the number of bits of
14608 the field itself. The result is the bit offset of
14609 the LSB of the field. */
14610 int anonymous_size
;
14611 int bit_offset
= DW_UNSND (attr
);
14613 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14614 if (attr
!= nullptr)
14616 /* The size of the anonymous object containing
14617 the bit field is explicit, so use the
14618 indicated size (in bytes). */
14619 anonymous_size
= DW_UNSND (attr
);
14623 /* The size of the anonymous object containing
14624 the bit field must be inferred from the type
14625 attribute of the data member containing the
14627 anonymous_size
= TYPE_LENGTH (fp
->type
);
14629 SET_FIELD_BITPOS (*fp
,
14630 (FIELD_BITPOS (*fp
)
14631 + anonymous_size
* bits_per_byte
14632 - bit_offset
- FIELD_BITSIZE (*fp
)));
14635 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14637 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14638 + attr
->constant_value (0)));
14640 /* Get name of field. */
14641 fieldname
= dwarf2_name (die
, cu
);
14642 if (fieldname
== NULL
)
14645 /* The name is already allocated along with this objfile, so we don't
14646 need to duplicate it for the type. */
14647 fp
->name
= fieldname
;
14649 /* Change accessibility for artificial fields (e.g. virtual table
14650 pointer or virtual base class pointer) to private. */
14651 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14653 FIELD_ARTIFICIAL (*fp
) = 1;
14654 new_field
->accessibility
= DW_ACCESS_private
;
14655 fip
->non_public_fields
= 1;
14658 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14660 /* C++ static member. */
14662 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14663 is a declaration, but all versions of G++ as of this writing
14664 (so through at least 3.2.1) incorrectly generate
14665 DW_TAG_variable tags. */
14667 const char *physname
;
14669 /* Get name of field. */
14670 fieldname
= dwarf2_name (die
, cu
);
14671 if (fieldname
== NULL
)
14674 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14676 /* Only create a symbol if this is an external value.
14677 new_symbol checks this and puts the value in the global symbol
14678 table, which we want. If it is not external, new_symbol
14679 will try to put the value in cu->list_in_scope which is wrong. */
14680 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14682 /* A static const member, not much different than an enum as far as
14683 we're concerned, except that we can support more types. */
14684 new_symbol (die
, NULL
, cu
);
14687 /* Get physical name. */
14688 physname
= dwarf2_physname (fieldname
, die
, cu
);
14690 /* The name is already allocated along with this objfile, so we don't
14691 need to duplicate it for the type. */
14692 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14693 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14694 FIELD_NAME (*fp
) = fieldname
;
14696 else if (die
->tag
== DW_TAG_inheritance
)
14698 /* C++ base class field. */
14699 handle_data_member_location (die
, cu
, fp
);
14700 FIELD_BITSIZE (*fp
) = 0;
14701 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14702 FIELD_NAME (*fp
) = fp
->type
->name ();
14705 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14708 /* Can the type given by DIE define another type? */
14711 type_can_define_types (const struct die_info
*die
)
14715 case DW_TAG_typedef
:
14716 case DW_TAG_class_type
:
14717 case DW_TAG_structure_type
:
14718 case DW_TAG_union_type
:
14719 case DW_TAG_enumeration_type
:
14727 /* Add a type definition defined in the scope of the FIP's class. */
14730 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14731 struct dwarf2_cu
*cu
)
14733 struct decl_field fp
;
14734 memset (&fp
, 0, sizeof (fp
));
14736 gdb_assert (type_can_define_types (die
));
14738 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14739 fp
.name
= dwarf2_name (die
, cu
);
14740 fp
.type
= read_type_die (die
, cu
);
14742 /* Save accessibility. */
14743 enum dwarf_access_attribute accessibility
;
14744 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14746 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14748 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14749 switch (accessibility
)
14751 case DW_ACCESS_public
:
14752 /* The assumed value if neither private nor protected. */
14754 case DW_ACCESS_private
:
14757 case DW_ACCESS_protected
:
14758 fp
.is_protected
= 1;
14761 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14764 if (die
->tag
== DW_TAG_typedef
)
14765 fip
->typedef_field_list
.push_back (fp
);
14767 fip
->nested_types_list
.push_back (fp
);
14770 /* A convenience typedef that's used when finding the discriminant
14771 field for a variant part. */
14772 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14775 /* Compute the discriminant range for a given variant. OBSTACK is
14776 where the results will be stored. VARIANT is the variant to
14777 process. IS_UNSIGNED indicates whether the discriminant is signed
14780 static const gdb::array_view
<discriminant_range
>
14781 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14784 std::vector
<discriminant_range
> ranges
;
14786 if (variant
.default_branch
)
14789 if (variant
.discr_list_data
== nullptr)
14791 discriminant_range r
14792 = {variant
.discriminant_value
, variant
.discriminant_value
};
14793 ranges
.push_back (r
);
14797 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14798 variant
.discr_list_data
->size
);
14799 while (!data
.empty ())
14801 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14803 complaint (_("invalid discriminant marker: %d"), data
[0]);
14806 bool is_range
= data
[0] == DW_DSC_range
;
14807 data
= data
.slice (1);
14809 ULONGEST low
, high
;
14810 unsigned int bytes_read
;
14814 complaint (_("DW_AT_discr_list missing low value"));
14818 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14820 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14822 data
= data
.slice (bytes_read
);
14828 complaint (_("DW_AT_discr_list missing high value"));
14832 high
= read_unsigned_leb128 (nullptr, data
.data (),
14835 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14837 data
= data
.slice (bytes_read
);
14842 ranges
.push_back ({ low
, high
});
14846 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14848 std::copy (ranges
.begin (), ranges
.end (), result
);
14849 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14852 static const gdb::array_view
<variant_part
> create_variant_parts
14853 (struct obstack
*obstack
,
14854 const offset_map_type
&offset_map
,
14855 struct field_info
*fi
,
14856 const std::vector
<variant_part_builder
> &variant_parts
);
14858 /* Fill in a "struct variant" for a given variant field. RESULT is
14859 the variant to fill in. OBSTACK is where any needed allocations
14860 will be done. OFFSET_MAP holds the mapping from section offsets to
14861 fields for the type. FI describes the fields of the type we're
14862 processing. FIELD is the variant field we're converting. */
14865 create_one_variant (variant
&result
, struct obstack
*obstack
,
14866 const offset_map_type
&offset_map
,
14867 struct field_info
*fi
, const variant_field
&field
)
14869 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14870 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14871 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14872 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14873 field
.variant_parts
);
14876 /* Fill in a "struct variant_part" for a given variant part. RESULT
14877 is the variant part to fill in. OBSTACK is where any needed
14878 allocations will be done. OFFSET_MAP holds the mapping from
14879 section offsets to fields for the type. FI describes the fields of
14880 the type we're processing. BUILDER is the variant part to be
14884 create_one_variant_part (variant_part
&result
,
14885 struct obstack
*obstack
,
14886 const offset_map_type
&offset_map
,
14887 struct field_info
*fi
,
14888 const variant_part_builder
&builder
)
14890 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14891 if (iter
== offset_map
.end ())
14893 result
.discriminant_index
= -1;
14894 /* Doesn't matter. */
14895 result
.is_unsigned
= false;
14899 result
.discriminant_index
= iter
->second
;
14901 = TYPE_UNSIGNED (FIELD_TYPE
14902 (fi
->fields
[result
.discriminant_index
].field
));
14905 size_t n
= builder
.variants
.size ();
14906 variant
*output
= new (obstack
) variant
[n
];
14907 for (size_t i
= 0; i
< n
; ++i
)
14908 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14909 builder
.variants
[i
]);
14911 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14914 /* Create a vector of variant parts that can be attached to a type.
14915 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14916 holds the mapping from section offsets to fields for the type. FI
14917 describes the fields of the type we're processing. VARIANT_PARTS
14918 is the vector to convert. */
14920 static const gdb::array_view
<variant_part
>
14921 create_variant_parts (struct obstack
*obstack
,
14922 const offset_map_type
&offset_map
,
14923 struct field_info
*fi
,
14924 const std::vector
<variant_part_builder
> &variant_parts
)
14926 if (variant_parts
.empty ())
14929 size_t n
= variant_parts
.size ();
14930 variant_part
*result
= new (obstack
) variant_part
[n
];
14931 for (size_t i
= 0; i
< n
; ++i
)
14932 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14935 return gdb::array_view
<variant_part
> (result
, n
);
14938 /* Compute the variant part vector for FIP, attaching it to TYPE when
14942 add_variant_property (struct field_info
*fip
, struct type
*type
,
14943 struct dwarf2_cu
*cu
)
14945 /* Map section offsets of fields to their field index. Note the
14946 field index here does not take the number of baseclasses into
14948 offset_map_type offset_map
;
14949 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14950 offset_map
[fip
->fields
[i
].offset
] = i
;
14952 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14953 gdb::array_view
<variant_part
> parts
14954 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14955 fip
->variant_parts
);
14957 struct dynamic_prop prop
;
14958 prop
.kind
= PROP_VARIANT_PARTS
;
14959 prop
.data
.variant_parts
14960 = ((gdb::array_view
<variant_part
> *)
14961 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14963 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14966 /* Create the vector of fields, and attach it to the type. */
14969 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14970 struct dwarf2_cu
*cu
)
14972 int nfields
= fip
->nfields ();
14974 /* Record the field count, allocate space for the array of fields,
14975 and create blank accessibility bitfields if necessary. */
14976 type
->set_num_fields (nfields
);
14978 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14980 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14982 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14984 TYPE_FIELD_PRIVATE_BITS (type
) =
14985 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14986 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14988 TYPE_FIELD_PROTECTED_BITS (type
) =
14989 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14990 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14992 TYPE_FIELD_IGNORE_BITS (type
) =
14993 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14994 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14997 /* If the type has baseclasses, allocate and clear a bit vector for
14998 TYPE_FIELD_VIRTUAL_BITS. */
14999 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15001 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15002 unsigned char *pointer
;
15004 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15005 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15006 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15007 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15008 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15011 if (!fip
->variant_parts
.empty ())
15012 add_variant_property (fip
, type
, cu
);
15014 /* Copy the saved-up fields into the field vector. */
15015 for (int i
= 0; i
< nfields
; ++i
)
15017 struct nextfield
&field
15018 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15019 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15021 type
->field (i
) = field
.field
;
15022 switch (field
.accessibility
)
15024 case DW_ACCESS_private
:
15025 if (cu
->language
!= language_ada
)
15026 SET_TYPE_FIELD_PRIVATE (type
, i
);
15029 case DW_ACCESS_protected
:
15030 if (cu
->language
!= language_ada
)
15031 SET_TYPE_FIELD_PROTECTED (type
, i
);
15034 case DW_ACCESS_public
:
15038 /* Unknown accessibility. Complain and treat it as public. */
15040 complaint (_("unsupported accessibility %d"),
15041 field
.accessibility
);
15045 if (i
< fip
->baseclasses
.size ())
15047 switch (field
.virtuality
)
15049 case DW_VIRTUALITY_virtual
:
15050 case DW_VIRTUALITY_pure_virtual
:
15051 if (cu
->language
== language_ada
)
15052 error (_("unexpected virtuality in component of Ada type"));
15053 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15060 /* Return true if this member function is a constructor, false
15064 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15066 const char *fieldname
;
15067 const char *type_name
;
15070 if (die
->parent
== NULL
)
15073 if (die
->parent
->tag
!= DW_TAG_structure_type
15074 && die
->parent
->tag
!= DW_TAG_union_type
15075 && die
->parent
->tag
!= DW_TAG_class_type
)
15078 fieldname
= dwarf2_name (die
, cu
);
15079 type_name
= dwarf2_name (die
->parent
, cu
);
15080 if (fieldname
== NULL
|| type_name
== NULL
)
15083 len
= strlen (fieldname
);
15084 return (strncmp (fieldname
, type_name
, len
) == 0
15085 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15088 /* Check if the given VALUE is a recognized enum
15089 dwarf_defaulted_attribute constant according to DWARF5 spec,
15093 is_valid_DW_AT_defaulted (ULONGEST value
)
15097 case DW_DEFAULTED_no
:
15098 case DW_DEFAULTED_in_class
:
15099 case DW_DEFAULTED_out_of_class
:
15103 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15107 /* Add a member function to the proper fieldlist. */
15110 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15111 struct type
*type
, struct dwarf2_cu
*cu
)
15113 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15114 struct attribute
*attr
;
15116 struct fnfieldlist
*flp
= nullptr;
15117 struct fn_field
*fnp
;
15118 const char *fieldname
;
15119 struct type
*this_type
;
15120 enum dwarf_access_attribute accessibility
;
15122 if (cu
->language
== language_ada
)
15123 error (_("unexpected member function in Ada type"));
15125 /* Get name of member function. */
15126 fieldname
= dwarf2_name (die
, cu
);
15127 if (fieldname
== NULL
)
15130 /* Look up member function name in fieldlist. */
15131 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15133 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15135 flp
= &fip
->fnfieldlists
[i
];
15140 /* Create a new fnfieldlist if necessary. */
15141 if (flp
== nullptr)
15143 fip
->fnfieldlists
.emplace_back ();
15144 flp
= &fip
->fnfieldlists
.back ();
15145 flp
->name
= fieldname
;
15146 i
= fip
->fnfieldlists
.size () - 1;
15149 /* Create a new member function field and add it to the vector of
15151 flp
->fnfields
.emplace_back ();
15152 fnp
= &flp
->fnfields
.back ();
15154 /* Delay processing of the physname until later. */
15155 if (cu
->language
== language_cplus
)
15156 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15160 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15161 fnp
->physname
= physname
? physname
: "";
15164 fnp
->type
= alloc_type (objfile
);
15165 this_type
= read_type_die (die
, cu
);
15166 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15168 int nparams
= this_type
->num_fields ();
15170 /* TYPE is the domain of this method, and THIS_TYPE is the type
15171 of the method itself (TYPE_CODE_METHOD). */
15172 smash_to_method_type (fnp
->type
, type
,
15173 TYPE_TARGET_TYPE (this_type
),
15174 this_type
->fields (),
15175 this_type
->num_fields (),
15176 TYPE_VARARGS (this_type
));
15178 /* Handle static member functions.
15179 Dwarf2 has no clean way to discern C++ static and non-static
15180 member functions. G++ helps GDB by marking the first
15181 parameter for non-static member functions (which is the this
15182 pointer) as artificial. We obtain this information from
15183 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15184 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15185 fnp
->voffset
= VOFFSET_STATIC
;
15188 complaint (_("member function type missing for '%s'"),
15189 dwarf2_full_name (fieldname
, die
, cu
));
15191 /* Get fcontext from DW_AT_containing_type if present. */
15192 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15193 fnp
->fcontext
= die_containing_type (die
, cu
);
15195 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15196 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15198 /* Get accessibility. */
15199 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15200 if (attr
!= nullptr)
15201 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15203 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15204 switch (accessibility
)
15206 case DW_ACCESS_private
:
15207 fnp
->is_private
= 1;
15209 case DW_ACCESS_protected
:
15210 fnp
->is_protected
= 1;
15214 /* Check for artificial methods. */
15215 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15216 if (attr
&& DW_UNSND (attr
) != 0)
15217 fnp
->is_artificial
= 1;
15219 /* Check for defaulted methods. */
15220 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15221 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15222 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15224 /* Check for deleted methods. */
15225 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15226 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15227 fnp
->is_deleted
= 1;
15229 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15231 /* Get index in virtual function table if it is a virtual member
15232 function. For older versions of GCC, this is an offset in the
15233 appropriate virtual table, as specified by DW_AT_containing_type.
15234 For everyone else, it is an expression to be evaluated relative
15235 to the object address. */
15237 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15238 if (attr
!= nullptr)
15240 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15242 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15244 /* Old-style GCC. */
15245 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15247 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15248 || (DW_BLOCK (attr
)->size
> 1
15249 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15250 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15252 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15253 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15254 dwarf2_complex_location_expr_complaint ();
15256 fnp
->voffset
/= cu
->header
.addr_size
;
15260 dwarf2_complex_location_expr_complaint ();
15262 if (!fnp
->fcontext
)
15264 /* If there is no `this' field and no DW_AT_containing_type,
15265 we cannot actually find a base class context for the
15267 if (this_type
->num_fields () == 0
15268 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15270 complaint (_("cannot determine context for virtual member "
15271 "function \"%s\" (offset %s)"),
15272 fieldname
, sect_offset_str (die
->sect_off
));
15277 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15281 else if (attr
->form_is_section_offset ())
15283 dwarf2_complex_location_expr_complaint ();
15287 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15293 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15294 if (attr
&& DW_UNSND (attr
))
15296 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15297 complaint (_("Member function \"%s\" (offset %s) is virtual "
15298 "but the vtable offset is not specified"),
15299 fieldname
, sect_offset_str (die
->sect_off
));
15300 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15301 TYPE_CPLUS_DYNAMIC (type
) = 1;
15306 /* Create the vector of member function fields, and attach it to the type. */
15309 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15310 struct dwarf2_cu
*cu
)
15312 if (cu
->language
== language_ada
)
15313 error (_("unexpected member functions in Ada type"));
15315 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15316 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15318 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15320 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15322 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15323 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15325 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15326 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15327 fn_flp
->fn_fields
= (struct fn_field
*)
15328 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15330 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15331 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15334 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15337 /* Returns non-zero if NAME is the name of a vtable member in CU's
15338 language, zero otherwise. */
15340 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15342 static const char vptr
[] = "_vptr";
15344 /* Look for the C++ form of the vtable. */
15345 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15351 /* GCC outputs unnamed structures that are really pointers to member
15352 functions, with the ABI-specified layout. If TYPE describes
15353 such a structure, smash it into a member function type.
15355 GCC shouldn't do this; it should just output pointer to member DIEs.
15356 This is GCC PR debug/28767. */
15359 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15361 struct type
*pfn_type
, *self_type
, *new_type
;
15363 /* Check for a structure with no name and two children. */
15364 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15367 /* Check for __pfn and __delta members. */
15368 if (TYPE_FIELD_NAME (type
, 0) == NULL
15369 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15370 || TYPE_FIELD_NAME (type
, 1) == NULL
15371 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15374 /* Find the type of the method. */
15375 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15376 if (pfn_type
== NULL
15377 || pfn_type
->code () != TYPE_CODE_PTR
15378 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15381 /* Look for the "this" argument. */
15382 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15383 if (pfn_type
->num_fields () == 0
15384 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15385 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15388 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15389 new_type
= alloc_type (objfile
);
15390 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15391 pfn_type
->fields (), pfn_type
->num_fields (),
15392 TYPE_VARARGS (pfn_type
));
15393 smash_to_methodptr_type (type
, new_type
);
15396 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15397 appropriate error checking and issuing complaints if there is a
15401 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15403 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15405 if (attr
== nullptr)
15408 if (!attr
->form_is_constant ())
15410 complaint (_("DW_AT_alignment must have constant form"
15411 " - DIE at %s [in module %s]"),
15412 sect_offset_str (die
->sect_off
),
15413 objfile_name (cu
->per_objfile
->objfile
));
15418 if (attr
->form
== DW_FORM_sdata
)
15420 LONGEST val
= DW_SND (attr
);
15423 complaint (_("DW_AT_alignment value must not be negative"
15424 " - DIE at %s [in module %s]"),
15425 sect_offset_str (die
->sect_off
),
15426 objfile_name (cu
->per_objfile
->objfile
));
15432 align
= DW_UNSND (attr
);
15436 complaint (_("DW_AT_alignment value must not be zero"
15437 " - DIE at %s [in module %s]"),
15438 sect_offset_str (die
->sect_off
),
15439 objfile_name (cu
->per_objfile
->objfile
));
15442 if ((align
& (align
- 1)) != 0)
15444 complaint (_("DW_AT_alignment value must be a power of 2"
15445 " - DIE at %s [in module %s]"),
15446 sect_offset_str (die
->sect_off
),
15447 objfile_name (cu
->per_objfile
->objfile
));
15454 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15455 the alignment for TYPE. */
15458 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15461 if (!set_type_align (type
, get_alignment (cu
, die
)))
15462 complaint (_("DW_AT_alignment value too large"
15463 " - DIE at %s [in module %s]"),
15464 sect_offset_str (die
->sect_off
),
15465 objfile_name (cu
->per_objfile
->objfile
));
15468 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15469 constant for a type, according to DWARF5 spec, Table 5.5. */
15472 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15477 case DW_CC_pass_by_reference
:
15478 case DW_CC_pass_by_value
:
15482 complaint (_("unrecognized DW_AT_calling_convention value "
15483 "(%s) for a type"), pulongest (value
));
15488 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15489 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15490 also according to GNU-specific values (see include/dwarf2.h). */
15493 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15498 case DW_CC_program
:
15502 case DW_CC_GNU_renesas_sh
:
15503 case DW_CC_GNU_borland_fastcall_i386
:
15504 case DW_CC_GDB_IBM_OpenCL
:
15508 complaint (_("unrecognized DW_AT_calling_convention value "
15509 "(%s) for a subroutine"), pulongest (value
));
15514 /* Called when we find the DIE that starts a structure or union scope
15515 (definition) to create a type for the structure or union. Fill in
15516 the type's name and general properties; the members will not be
15517 processed until process_structure_scope. A symbol table entry for
15518 the type will also not be done until process_structure_scope (assuming
15519 the type has a name).
15521 NOTE: we need to call these functions regardless of whether or not the
15522 DIE has a DW_AT_name attribute, since it might be an anonymous
15523 structure or union. This gets the type entered into our set of
15524 user defined types. */
15526 static struct type
*
15527 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15529 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15531 struct attribute
*attr
;
15534 /* If the definition of this type lives in .debug_types, read that type.
15535 Don't follow DW_AT_specification though, that will take us back up
15536 the chain and we want to go down. */
15537 attr
= die
->attr (DW_AT_signature
);
15538 if (attr
!= nullptr)
15540 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15542 /* The type's CU may not be the same as CU.
15543 Ensure TYPE is recorded with CU in die_type_hash. */
15544 return set_die_type (die
, type
, cu
);
15547 type
= alloc_type (objfile
);
15548 INIT_CPLUS_SPECIFIC (type
);
15550 name
= dwarf2_name (die
, cu
);
15553 if (cu
->language
== language_cplus
15554 || cu
->language
== language_d
15555 || cu
->language
== language_rust
)
15557 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15559 /* dwarf2_full_name might have already finished building the DIE's
15560 type. If so, there is no need to continue. */
15561 if (get_die_type (die
, cu
) != NULL
)
15562 return get_die_type (die
, cu
);
15564 type
->set_name (full_name
);
15568 /* The name is already allocated along with this objfile, so
15569 we don't need to duplicate it for the type. */
15570 type
->set_name (name
);
15574 if (die
->tag
== DW_TAG_structure_type
)
15576 type
->set_code (TYPE_CODE_STRUCT
);
15578 else if (die
->tag
== DW_TAG_union_type
)
15580 type
->set_code (TYPE_CODE_UNION
);
15584 type
->set_code (TYPE_CODE_STRUCT
);
15587 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15588 TYPE_DECLARED_CLASS (type
) = 1;
15590 /* Store the calling convention in the type if it's available in
15591 the die. Otherwise the calling convention remains set to
15592 the default value DW_CC_normal. */
15593 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15594 if (attr
!= nullptr
15595 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15597 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15598 TYPE_CPLUS_CALLING_CONVENTION (type
)
15599 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15602 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15603 if (attr
!= nullptr)
15605 if (attr
->form_is_constant ())
15606 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15609 struct dynamic_prop prop
;
15610 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15611 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15612 TYPE_LENGTH (type
) = 0;
15617 TYPE_LENGTH (type
) = 0;
15620 maybe_set_alignment (cu
, die
, type
);
15622 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15624 /* ICC<14 does not output the required DW_AT_declaration on
15625 incomplete types, but gives them a size of zero. */
15626 TYPE_STUB (type
) = 1;
15629 TYPE_STUB_SUPPORTED (type
) = 1;
15631 if (die_is_declaration (die
, cu
))
15632 TYPE_STUB (type
) = 1;
15633 else if (attr
== NULL
&& die
->child
== NULL
15634 && producer_is_realview (cu
->producer
))
15635 /* RealView does not output the required DW_AT_declaration
15636 on incomplete types. */
15637 TYPE_STUB (type
) = 1;
15639 /* We need to add the type field to the die immediately so we don't
15640 infinitely recurse when dealing with pointers to the structure
15641 type within the structure itself. */
15642 set_die_type (die
, type
, cu
);
15644 /* set_die_type should be already done. */
15645 set_descriptive_type (type
, die
, cu
);
15650 static void handle_struct_member_die
15651 (struct die_info
*child_die
,
15653 struct field_info
*fi
,
15654 std::vector
<struct symbol
*> *template_args
,
15655 struct dwarf2_cu
*cu
);
15657 /* A helper for handle_struct_member_die that handles
15658 DW_TAG_variant_part. */
15661 handle_variant_part (struct die_info
*die
, struct type
*type
,
15662 struct field_info
*fi
,
15663 std::vector
<struct symbol
*> *template_args
,
15664 struct dwarf2_cu
*cu
)
15666 variant_part_builder
*new_part
;
15667 if (fi
->current_variant_part
== nullptr)
15669 fi
->variant_parts
.emplace_back ();
15670 new_part
= &fi
->variant_parts
.back ();
15672 else if (!fi
->current_variant_part
->processing_variant
)
15674 complaint (_("nested DW_TAG_variant_part seen "
15675 "- DIE at %s [in module %s]"),
15676 sect_offset_str (die
->sect_off
),
15677 objfile_name (cu
->per_objfile
->objfile
));
15682 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15683 current
.variant_parts
.emplace_back ();
15684 new_part
= ¤t
.variant_parts
.back ();
15687 /* When we recurse, we want callees to add to this new variant
15689 scoped_restore save_current_variant_part
15690 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15692 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15695 /* It's a univariant form, an extension we support. */
15697 else if (discr
->form_is_ref ())
15699 struct dwarf2_cu
*target_cu
= cu
;
15700 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15702 new_part
->discriminant_offset
= target_die
->sect_off
;
15706 complaint (_("DW_AT_discr does not have DIE reference form"
15707 " - DIE at %s [in module %s]"),
15708 sect_offset_str (die
->sect_off
),
15709 objfile_name (cu
->per_objfile
->objfile
));
15712 for (die_info
*child_die
= die
->child
;
15714 child_die
= child_die
->sibling
)
15715 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15718 /* A helper for handle_struct_member_die that handles
15722 handle_variant (struct die_info
*die
, struct type
*type
,
15723 struct field_info
*fi
,
15724 std::vector
<struct symbol
*> *template_args
,
15725 struct dwarf2_cu
*cu
)
15727 if (fi
->current_variant_part
== nullptr)
15729 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15730 "- DIE at %s [in module %s]"),
15731 sect_offset_str (die
->sect_off
),
15732 objfile_name (cu
->per_objfile
->objfile
));
15735 if (fi
->current_variant_part
->processing_variant
)
15737 complaint (_("nested DW_TAG_variant seen "
15738 "- DIE at %s [in module %s]"),
15739 sect_offset_str (die
->sect_off
),
15740 objfile_name (cu
->per_objfile
->objfile
));
15744 scoped_restore save_processing_variant
15745 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15748 fi
->current_variant_part
->variants
.emplace_back ();
15749 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15750 variant
.first_field
= fi
->fields
.size ();
15752 /* In a variant we want to get the discriminant and also add a
15753 field for our sole member child. */
15754 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15755 if (discr
== nullptr)
15757 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15758 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15759 variant
.default_branch
= true;
15761 variant
.discr_list_data
= DW_BLOCK (discr
);
15764 variant
.discriminant_value
= DW_UNSND (discr
);
15766 for (die_info
*variant_child
= die
->child
;
15767 variant_child
!= NULL
;
15768 variant_child
= variant_child
->sibling
)
15769 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15771 variant
.last_field
= fi
->fields
.size ();
15774 /* A helper for process_structure_scope that handles a single member
15778 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15779 struct field_info
*fi
,
15780 std::vector
<struct symbol
*> *template_args
,
15781 struct dwarf2_cu
*cu
)
15783 if (child_die
->tag
== DW_TAG_member
15784 || child_die
->tag
== DW_TAG_variable
)
15786 /* NOTE: carlton/2002-11-05: A C++ static data member
15787 should be a DW_TAG_member that is a declaration, but
15788 all versions of G++ as of this writing (so through at
15789 least 3.2.1) incorrectly generate DW_TAG_variable
15790 tags for them instead. */
15791 dwarf2_add_field (fi
, child_die
, cu
);
15793 else if (child_die
->tag
== DW_TAG_subprogram
)
15795 /* Rust doesn't have member functions in the C++ sense.
15796 However, it does emit ordinary functions as children
15797 of a struct DIE. */
15798 if (cu
->language
== language_rust
)
15799 read_func_scope (child_die
, cu
);
15802 /* C++ member function. */
15803 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15806 else if (child_die
->tag
== DW_TAG_inheritance
)
15808 /* C++ base class field. */
15809 dwarf2_add_field (fi
, child_die
, cu
);
15811 else if (type_can_define_types (child_die
))
15812 dwarf2_add_type_defn (fi
, child_die
, cu
);
15813 else if (child_die
->tag
== DW_TAG_template_type_param
15814 || child_die
->tag
== DW_TAG_template_value_param
)
15816 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15819 template_args
->push_back (arg
);
15821 else if (child_die
->tag
== DW_TAG_variant_part
)
15822 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15823 else if (child_die
->tag
== DW_TAG_variant
)
15824 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15827 /* Finish creating a structure or union type, including filling in
15828 its members and creating a symbol for it. */
15831 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15833 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15834 struct die_info
*child_die
;
15837 type
= get_die_type (die
, cu
);
15839 type
= read_structure_type (die
, cu
);
15841 bool has_template_parameters
= false;
15842 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15844 struct field_info fi
;
15845 std::vector
<struct symbol
*> template_args
;
15847 child_die
= die
->child
;
15849 while (child_die
&& child_die
->tag
)
15851 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15852 child_die
= child_die
->sibling
;
15855 /* Attach template arguments to type. */
15856 if (!template_args
.empty ())
15858 has_template_parameters
= true;
15859 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15860 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15861 TYPE_TEMPLATE_ARGUMENTS (type
)
15862 = XOBNEWVEC (&objfile
->objfile_obstack
,
15864 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15865 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15866 template_args
.data (),
15867 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15868 * sizeof (struct symbol
*)));
15871 /* Attach fields and member functions to the type. */
15872 if (fi
.nfields () > 0)
15873 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15874 if (!fi
.fnfieldlists
.empty ())
15876 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15878 /* Get the type which refers to the base class (possibly this
15879 class itself) which contains the vtable pointer for the current
15880 class from the DW_AT_containing_type attribute. This use of
15881 DW_AT_containing_type is a GNU extension. */
15883 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15885 struct type
*t
= die_containing_type (die
, cu
);
15887 set_type_vptr_basetype (type
, t
);
15892 /* Our own class provides vtbl ptr. */
15893 for (i
= t
->num_fields () - 1;
15894 i
>= TYPE_N_BASECLASSES (t
);
15897 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15899 if (is_vtable_name (fieldname
, cu
))
15901 set_type_vptr_fieldno (type
, i
);
15906 /* Complain if virtual function table field not found. */
15907 if (i
< TYPE_N_BASECLASSES (t
))
15908 complaint (_("virtual function table pointer "
15909 "not found when defining class '%s'"),
15910 type
->name () ? type
->name () : "");
15914 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15917 else if (cu
->producer
15918 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15920 /* The IBM XLC compiler does not provide direct indication
15921 of the containing type, but the vtable pointer is
15922 always named __vfp. */
15926 for (i
= type
->num_fields () - 1;
15927 i
>= TYPE_N_BASECLASSES (type
);
15930 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15932 set_type_vptr_fieldno (type
, i
);
15933 set_type_vptr_basetype (type
, type
);
15940 /* Copy fi.typedef_field_list linked list elements content into the
15941 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15942 if (!fi
.typedef_field_list
.empty ())
15944 int count
= fi
.typedef_field_list
.size ();
15946 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15947 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15948 = ((struct decl_field
*)
15950 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15951 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15953 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15954 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15957 /* Copy fi.nested_types_list linked list elements content into the
15958 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15959 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15961 int count
= fi
.nested_types_list
.size ();
15963 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15964 TYPE_NESTED_TYPES_ARRAY (type
)
15965 = ((struct decl_field
*)
15966 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15967 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15969 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15970 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15974 quirk_gcc_member_function_pointer (type
, objfile
);
15975 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15976 cu
->rust_unions
.push_back (type
);
15978 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15979 snapshots) has been known to create a die giving a declaration
15980 for a class that has, as a child, a die giving a definition for a
15981 nested class. So we have to process our children even if the
15982 current die is a declaration. Normally, of course, a declaration
15983 won't have any children at all. */
15985 child_die
= die
->child
;
15987 while (child_die
!= NULL
&& child_die
->tag
)
15989 if (child_die
->tag
== DW_TAG_member
15990 || child_die
->tag
== DW_TAG_variable
15991 || child_die
->tag
== DW_TAG_inheritance
15992 || child_die
->tag
== DW_TAG_template_value_param
15993 || child_die
->tag
== DW_TAG_template_type_param
)
15998 process_die (child_die
, cu
);
16000 child_die
= child_die
->sibling
;
16003 /* Do not consider external references. According to the DWARF standard,
16004 these DIEs are identified by the fact that they have no byte_size
16005 attribute, and a declaration attribute. */
16006 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16007 || !die_is_declaration (die
, cu
)
16008 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16010 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16012 if (has_template_parameters
)
16014 struct symtab
*symtab
;
16015 if (sym
!= nullptr)
16016 symtab
= symbol_symtab (sym
);
16017 else if (cu
->line_header
!= nullptr)
16019 /* Any related symtab will do. */
16021 = cu
->line_header
->file_names ()[0].symtab
;
16026 complaint (_("could not find suitable "
16027 "symtab for template parameter"
16028 " - DIE at %s [in module %s]"),
16029 sect_offset_str (die
->sect_off
),
16030 objfile_name (objfile
));
16033 if (symtab
!= nullptr)
16035 /* Make sure that the symtab is set on the new symbols.
16036 Even though they don't appear in this symtab directly,
16037 other parts of gdb assume that symbols do, and this is
16038 reasonably true. */
16039 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16040 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16046 /* Assuming DIE is an enumeration type, and TYPE is its associated
16047 type, update TYPE using some information only available in DIE's
16048 children. In particular, the fields are computed. */
16051 update_enumeration_type_from_children (struct die_info
*die
,
16053 struct dwarf2_cu
*cu
)
16055 struct die_info
*child_die
;
16056 int unsigned_enum
= 1;
16059 auto_obstack obstack
;
16060 std::vector
<struct field
> fields
;
16062 for (child_die
= die
->child
;
16063 child_die
!= NULL
&& child_die
->tag
;
16064 child_die
= child_die
->sibling
)
16066 struct attribute
*attr
;
16068 const gdb_byte
*bytes
;
16069 struct dwarf2_locexpr_baton
*baton
;
16072 if (child_die
->tag
!= DW_TAG_enumerator
)
16075 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16079 name
= dwarf2_name (child_die
, cu
);
16081 name
= "<anonymous enumerator>";
16083 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16084 &value
, &bytes
, &baton
);
16092 if (count_one_bits_ll (value
) >= 2)
16096 fields
.emplace_back ();
16097 struct field
&field
= fields
.back ();
16098 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16099 SET_FIELD_ENUMVAL (field
, value
);
16102 if (!fields
.empty ())
16104 type
->set_num_fields (fields
.size ());
16107 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16108 memcpy (type
->fields (), fields
.data (),
16109 sizeof (struct field
) * fields
.size ());
16113 TYPE_UNSIGNED (type
) = 1;
16115 TYPE_FLAG_ENUM (type
) = 1;
16118 /* Given a DW_AT_enumeration_type die, set its type. We do not
16119 complete the type's fields yet, or create any symbols. */
16121 static struct type
*
16122 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16124 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16126 struct attribute
*attr
;
16129 /* If the definition of this type lives in .debug_types, read that type.
16130 Don't follow DW_AT_specification though, that will take us back up
16131 the chain and we want to go down. */
16132 attr
= die
->attr (DW_AT_signature
);
16133 if (attr
!= nullptr)
16135 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16137 /* The type's CU may not be the same as CU.
16138 Ensure TYPE is recorded with CU in die_type_hash. */
16139 return set_die_type (die
, type
, cu
);
16142 type
= alloc_type (objfile
);
16144 type
->set_code (TYPE_CODE_ENUM
);
16145 name
= dwarf2_full_name (NULL
, die
, cu
);
16147 type
->set_name (name
);
16149 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16152 struct type
*underlying_type
= die_type (die
, cu
);
16154 TYPE_TARGET_TYPE (type
) = underlying_type
;
16157 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16158 if (attr
!= nullptr)
16160 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16164 TYPE_LENGTH (type
) = 0;
16167 maybe_set_alignment (cu
, die
, type
);
16169 /* The enumeration DIE can be incomplete. In Ada, any type can be
16170 declared as private in the package spec, and then defined only
16171 inside the package body. Such types are known as Taft Amendment
16172 Types. When another package uses such a type, an incomplete DIE
16173 may be generated by the compiler. */
16174 if (die_is_declaration (die
, cu
))
16175 TYPE_STUB (type
) = 1;
16177 /* If this type has an underlying type that is not a stub, then we
16178 may use its attributes. We always use the "unsigned" attribute
16179 in this situation, because ordinarily we guess whether the type
16180 is unsigned -- but the guess can be wrong and the underlying type
16181 can tell us the reality. However, we defer to a local size
16182 attribute if one exists, because this lets the compiler override
16183 the underlying type if needed. */
16184 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16186 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16187 underlying_type
= check_typedef (underlying_type
);
16188 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16189 if (TYPE_LENGTH (type
) == 0)
16190 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16191 if (TYPE_RAW_ALIGN (type
) == 0
16192 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16193 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16196 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16198 set_die_type (die
, type
, cu
);
16200 /* Finish the creation of this type by using the enum's children.
16201 Note that, as usual, this must come after set_die_type to avoid
16202 infinite recursion when trying to compute the names of the
16204 update_enumeration_type_from_children (die
, type
, cu
);
16209 /* Given a pointer to a die which begins an enumeration, process all
16210 the dies that define the members of the enumeration, and create the
16211 symbol for the enumeration type.
16213 NOTE: We reverse the order of the element list. */
16216 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16218 struct type
*this_type
;
16220 this_type
= get_die_type (die
, cu
);
16221 if (this_type
== NULL
)
16222 this_type
= read_enumeration_type (die
, cu
);
16224 if (die
->child
!= NULL
)
16226 struct die_info
*child_die
;
16229 child_die
= die
->child
;
16230 while (child_die
&& child_die
->tag
)
16232 if (child_die
->tag
!= DW_TAG_enumerator
)
16234 process_die (child_die
, cu
);
16238 name
= dwarf2_name (child_die
, cu
);
16240 new_symbol (child_die
, this_type
, cu
);
16243 child_die
= child_die
->sibling
;
16247 /* If we are reading an enum from a .debug_types unit, and the enum
16248 is a declaration, and the enum is not the signatured type in the
16249 unit, then we do not want to add a symbol for it. Adding a
16250 symbol would in some cases obscure the true definition of the
16251 enum, giving users an incomplete type when the definition is
16252 actually available. Note that we do not want to do this for all
16253 enums which are just declarations, because C++0x allows forward
16254 enum declarations. */
16255 if (cu
->per_cu
->is_debug_types
16256 && die_is_declaration (die
, cu
))
16258 struct signatured_type
*sig_type
;
16260 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16261 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16262 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16266 new_symbol (die
, this_type
, cu
);
16269 /* Extract all information from a DW_TAG_array_type DIE and put it in
16270 the DIE's type field. For now, this only handles one dimensional
16273 static struct type
*
16274 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16276 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16277 struct die_info
*child_die
;
16279 struct type
*element_type
, *range_type
, *index_type
;
16280 struct attribute
*attr
;
16282 struct dynamic_prop
*byte_stride_prop
= NULL
;
16283 unsigned int bit_stride
= 0;
16285 element_type
= die_type (die
, cu
);
16287 /* The die_type call above may have already set the type for this DIE. */
16288 type
= get_die_type (die
, cu
);
16292 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16296 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16299 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16300 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16304 complaint (_("unable to read array DW_AT_byte_stride "
16305 " - DIE at %s [in module %s]"),
16306 sect_offset_str (die
->sect_off
),
16307 objfile_name (cu
->per_objfile
->objfile
));
16308 /* Ignore this attribute. We will likely not be able to print
16309 arrays of this type correctly, but there is little we can do
16310 to help if we cannot read the attribute's value. */
16311 byte_stride_prop
= NULL
;
16315 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16317 bit_stride
= DW_UNSND (attr
);
16319 /* Irix 6.2 native cc creates array types without children for
16320 arrays with unspecified length. */
16321 if (die
->child
== NULL
)
16323 index_type
= objfile_type (objfile
)->builtin_int
;
16324 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16325 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16326 byte_stride_prop
, bit_stride
);
16327 return set_die_type (die
, type
, cu
);
16330 std::vector
<struct type
*> range_types
;
16331 child_die
= die
->child
;
16332 while (child_die
&& child_die
->tag
)
16334 if (child_die
->tag
== DW_TAG_subrange_type
)
16336 struct type
*child_type
= read_type_die (child_die
, cu
);
16338 if (child_type
!= NULL
)
16340 /* The range type was succesfully read. Save it for the
16341 array type creation. */
16342 range_types
.push_back (child_type
);
16345 child_die
= child_die
->sibling
;
16348 /* Dwarf2 dimensions are output from left to right, create the
16349 necessary array types in backwards order. */
16351 type
= element_type
;
16353 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16357 while (i
< range_types
.size ())
16358 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16359 byte_stride_prop
, bit_stride
);
16363 size_t ndim
= range_types
.size ();
16365 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16366 byte_stride_prop
, bit_stride
);
16369 /* Understand Dwarf2 support for vector types (like they occur on
16370 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16371 array type. This is not part of the Dwarf2/3 standard yet, but a
16372 custom vendor extension. The main difference between a regular
16373 array and the vector variant is that vectors are passed by value
16375 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16376 if (attr
!= nullptr)
16377 make_vector_type (type
);
16379 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16380 implementation may choose to implement triple vectors using this
16382 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16383 if (attr
!= nullptr)
16385 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16386 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16388 complaint (_("DW_AT_byte_size for array type smaller "
16389 "than the total size of elements"));
16392 name
= dwarf2_name (die
, cu
);
16394 type
->set_name (name
);
16396 maybe_set_alignment (cu
, die
, type
);
16398 /* Install the type in the die. */
16399 set_die_type (die
, type
, cu
);
16401 /* set_die_type should be already done. */
16402 set_descriptive_type (type
, die
, cu
);
16407 static enum dwarf_array_dim_ordering
16408 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16410 struct attribute
*attr
;
16412 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16414 if (attr
!= nullptr)
16415 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16417 /* GNU F77 is a special case, as at 08/2004 array type info is the
16418 opposite order to the dwarf2 specification, but data is still
16419 laid out as per normal fortran.
16421 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16422 version checking. */
16424 if (cu
->language
== language_fortran
16425 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16427 return DW_ORD_row_major
;
16430 switch (cu
->language_defn
->la_array_ordering
)
16432 case array_column_major
:
16433 return DW_ORD_col_major
;
16434 case array_row_major
:
16436 return DW_ORD_row_major
;
16440 /* Extract all information from a DW_TAG_set_type DIE and put it in
16441 the DIE's type field. */
16443 static struct type
*
16444 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16446 struct type
*domain_type
, *set_type
;
16447 struct attribute
*attr
;
16449 domain_type
= die_type (die
, cu
);
16451 /* The die_type call above may have already set the type for this DIE. */
16452 set_type
= get_die_type (die
, cu
);
16456 set_type
= create_set_type (NULL
, domain_type
);
16458 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16459 if (attr
!= nullptr)
16460 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16462 maybe_set_alignment (cu
, die
, set_type
);
16464 return set_die_type (die
, set_type
, cu
);
16467 /* A helper for read_common_block that creates a locexpr baton.
16468 SYM is the symbol which we are marking as computed.
16469 COMMON_DIE is the DIE for the common block.
16470 COMMON_LOC is the location expression attribute for the common
16472 MEMBER_LOC is the location expression attribute for the particular
16473 member of the common block that we are processing.
16474 CU is the CU from which the above come. */
16477 mark_common_block_symbol_computed (struct symbol
*sym
,
16478 struct die_info
*common_die
,
16479 struct attribute
*common_loc
,
16480 struct attribute
*member_loc
,
16481 struct dwarf2_cu
*cu
)
16483 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16484 struct objfile
*objfile
= per_objfile
->objfile
;
16485 struct dwarf2_locexpr_baton
*baton
;
16487 unsigned int cu_off
;
16488 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16489 LONGEST offset
= 0;
16491 gdb_assert (common_loc
&& member_loc
);
16492 gdb_assert (common_loc
->form_is_block ());
16493 gdb_assert (member_loc
->form_is_block ()
16494 || member_loc
->form_is_constant ());
16496 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16497 baton
->per_objfile
= per_objfile
;
16498 baton
->per_cu
= cu
->per_cu
;
16499 gdb_assert (baton
->per_cu
);
16501 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16503 if (member_loc
->form_is_constant ())
16505 offset
= member_loc
->constant_value (0);
16506 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16509 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16511 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16514 *ptr
++ = DW_OP_call4
;
16515 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16516 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16519 if (member_loc
->form_is_constant ())
16521 *ptr
++ = DW_OP_addr
;
16522 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16523 ptr
+= cu
->header
.addr_size
;
16527 /* We have to copy the data here, because DW_OP_call4 will only
16528 use a DW_AT_location attribute. */
16529 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16530 ptr
+= DW_BLOCK (member_loc
)->size
;
16533 *ptr
++ = DW_OP_plus
;
16534 gdb_assert (ptr
- baton
->data
== baton
->size
);
16536 SYMBOL_LOCATION_BATON (sym
) = baton
;
16537 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16540 /* Create appropriate locally-scoped variables for all the
16541 DW_TAG_common_block entries. Also create a struct common_block
16542 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16543 is used to separate the common blocks name namespace from regular
16547 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16549 struct attribute
*attr
;
16551 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16552 if (attr
!= nullptr)
16554 /* Support the .debug_loc offsets. */
16555 if (attr
->form_is_block ())
16559 else if (attr
->form_is_section_offset ())
16561 dwarf2_complex_location_expr_complaint ();
16566 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16567 "common block member");
16572 if (die
->child
!= NULL
)
16574 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16575 struct die_info
*child_die
;
16576 size_t n_entries
= 0, size
;
16577 struct common_block
*common_block
;
16578 struct symbol
*sym
;
16580 for (child_die
= die
->child
;
16581 child_die
&& child_die
->tag
;
16582 child_die
= child_die
->sibling
)
16585 size
= (sizeof (struct common_block
)
16586 + (n_entries
- 1) * sizeof (struct symbol
*));
16588 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16590 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16591 common_block
->n_entries
= 0;
16593 for (child_die
= die
->child
;
16594 child_die
&& child_die
->tag
;
16595 child_die
= child_die
->sibling
)
16597 /* Create the symbol in the DW_TAG_common_block block in the current
16599 sym
= new_symbol (child_die
, NULL
, cu
);
16602 struct attribute
*member_loc
;
16604 common_block
->contents
[common_block
->n_entries
++] = sym
;
16606 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16610 /* GDB has handled this for a long time, but it is
16611 not specified by DWARF. It seems to have been
16612 emitted by gfortran at least as recently as:
16613 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16614 complaint (_("Variable in common block has "
16615 "DW_AT_data_member_location "
16616 "- DIE at %s [in module %s]"),
16617 sect_offset_str (child_die
->sect_off
),
16618 objfile_name (objfile
));
16620 if (member_loc
->form_is_section_offset ())
16621 dwarf2_complex_location_expr_complaint ();
16622 else if (member_loc
->form_is_constant ()
16623 || member_loc
->form_is_block ())
16625 if (attr
!= nullptr)
16626 mark_common_block_symbol_computed (sym
, die
, attr
,
16630 dwarf2_complex_location_expr_complaint ();
16635 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16636 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16640 /* Create a type for a C++ namespace. */
16642 static struct type
*
16643 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16645 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16646 const char *previous_prefix
, *name
;
16650 /* For extensions, reuse the type of the original namespace. */
16651 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16653 struct die_info
*ext_die
;
16654 struct dwarf2_cu
*ext_cu
= cu
;
16656 ext_die
= dwarf2_extension (die
, &ext_cu
);
16657 type
= read_type_die (ext_die
, ext_cu
);
16659 /* EXT_CU may not be the same as CU.
16660 Ensure TYPE is recorded with CU in die_type_hash. */
16661 return set_die_type (die
, type
, cu
);
16664 name
= namespace_name (die
, &is_anonymous
, cu
);
16666 /* Now build the name of the current namespace. */
16668 previous_prefix
= determine_prefix (die
, cu
);
16669 if (previous_prefix
[0] != '\0')
16670 name
= typename_concat (&objfile
->objfile_obstack
,
16671 previous_prefix
, name
, 0, cu
);
16673 /* Create the type. */
16674 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16676 return set_die_type (die
, type
, cu
);
16679 /* Read a namespace scope. */
16682 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16684 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16687 /* Add a symbol associated to this if we haven't seen the namespace
16688 before. Also, add a using directive if it's an anonymous
16691 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16695 type
= read_type_die (die
, cu
);
16696 new_symbol (die
, type
, cu
);
16698 namespace_name (die
, &is_anonymous
, cu
);
16701 const char *previous_prefix
= determine_prefix (die
, cu
);
16703 std::vector
<const char *> excludes
;
16704 add_using_directive (using_directives (cu
),
16705 previous_prefix
, type
->name (), NULL
,
16706 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16710 if (die
->child
!= NULL
)
16712 struct die_info
*child_die
= die
->child
;
16714 while (child_die
&& child_die
->tag
)
16716 process_die (child_die
, cu
);
16717 child_die
= child_die
->sibling
;
16722 /* Read a Fortran module as type. This DIE can be only a declaration used for
16723 imported module. Still we need that type as local Fortran "use ... only"
16724 declaration imports depend on the created type in determine_prefix. */
16726 static struct type
*
16727 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16729 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16730 const char *module_name
;
16733 module_name
= dwarf2_name (die
, cu
);
16734 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16736 return set_die_type (die
, type
, cu
);
16739 /* Read a Fortran module. */
16742 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16744 struct die_info
*child_die
= die
->child
;
16747 type
= read_type_die (die
, cu
);
16748 new_symbol (die
, type
, cu
);
16750 while (child_die
&& child_die
->tag
)
16752 process_die (child_die
, cu
);
16753 child_die
= child_die
->sibling
;
16757 /* Return the name of the namespace represented by DIE. Set
16758 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16761 static const char *
16762 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16764 struct die_info
*current_die
;
16765 const char *name
= NULL
;
16767 /* Loop through the extensions until we find a name. */
16769 for (current_die
= die
;
16770 current_die
!= NULL
;
16771 current_die
= dwarf2_extension (die
, &cu
))
16773 /* We don't use dwarf2_name here so that we can detect the absence
16774 of a name -> anonymous namespace. */
16775 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16781 /* Is it an anonymous namespace? */
16783 *is_anonymous
= (name
== NULL
);
16785 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16790 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16791 the user defined type vector. */
16793 static struct type
*
16794 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16796 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16797 struct comp_unit_head
*cu_header
= &cu
->header
;
16799 struct attribute
*attr_byte_size
;
16800 struct attribute
*attr_address_class
;
16801 int byte_size
, addr_class
;
16802 struct type
*target_type
;
16804 target_type
= die_type (die
, cu
);
16806 /* The die_type call above may have already set the type for this DIE. */
16807 type
= get_die_type (die
, cu
);
16811 type
= lookup_pointer_type (target_type
);
16813 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16814 if (attr_byte_size
)
16815 byte_size
= DW_UNSND (attr_byte_size
);
16817 byte_size
= cu_header
->addr_size
;
16819 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16820 if (attr_address_class
)
16821 addr_class
= DW_UNSND (attr_address_class
);
16823 addr_class
= DW_ADDR_none
;
16825 ULONGEST alignment
= get_alignment (cu
, die
);
16827 /* If the pointer size, alignment, or address class is different
16828 than the default, create a type variant marked as such and set
16829 the length accordingly. */
16830 if (TYPE_LENGTH (type
) != byte_size
16831 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16832 && alignment
!= TYPE_RAW_ALIGN (type
))
16833 || addr_class
!= DW_ADDR_none
)
16835 if (gdbarch_address_class_type_flags_p (gdbarch
))
16839 type_flags
= gdbarch_address_class_type_flags
16840 (gdbarch
, byte_size
, addr_class
);
16841 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16843 type
= make_type_with_address_space (type
, type_flags
);
16845 else if (TYPE_LENGTH (type
) != byte_size
)
16847 complaint (_("invalid pointer size %d"), byte_size
);
16849 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16851 complaint (_("Invalid DW_AT_alignment"
16852 " - DIE at %s [in module %s]"),
16853 sect_offset_str (die
->sect_off
),
16854 objfile_name (cu
->per_objfile
->objfile
));
16858 /* Should we also complain about unhandled address classes? */
16862 TYPE_LENGTH (type
) = byte_size
;
16863 set_type_align (type
, alignment
);
16864 return set_die_type (die
, type
, cu
);
16867 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16868 the user defined type vector. */
16870 static struct type
*
16871 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16874 struct type
*to_type
;
16875 struct type
*domain
;
16877 to_type
= die_type (die
, cu
);
16878 domain
= die_containing_type (die
, cu
);
16880 /* The calls above may have already set the type for this DIE. */
16881 type
= get_die_type (die
, cu
);
16885 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16886 type
= lookup_methodptr_type (to_type
);
16887 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16889 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
16891 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16892 to_type
->fields (), to_type
->num_fields (),
16893 TYPE_VARARGS (to_type
));
16894 type
= lookup_methodptr_type (new_type
);
16897 type
= lookup_memberptr_type (to_type
, domain
);
16899 return set_die_type (die
, type
, cu
);
16902 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16903 the user defined type vector. */
16905 static struct type
*
16906 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16907 enum type_code refcode
)
16909 struct comp_unit_head
*cu_header
= &cu
->header
;
16910 struct type
*type
, *target_type
;
16911 struct attribute
*attr
;
16913 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16915 target_type
= die_type (die
, cu
);
16917 /* The die_type call above may have already set the type for this DIE. */
16918 type
= get_die_type (die
, cu
);
16922 type
= lookup_reference_type (target_type
, refcode
);
16923 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16924 if (attr
!= nullptr)
16926 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16930 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16932 maybe_set_alignment (cu
, die
, type
);
16933 return set_die_type (die
, type
, cu
);
16936 /* Add the given cv-qualifiers to the element type of the array. GCC
16937 outputs DWARF type qualifiers that apply to an array, not the
16938 element type. But GDB relies on the array element type to carry
16939 the cv-qualifiers. This mimics section 6.7.3 of the C99
16942 static struct type
*
16943 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16944 struct type
*base_type
, int cnst
, int voltl
)
16946 struct type
*el_type
, *inner_array
;
16948 base_type
= copy_type (base_type
);
16949 inner_array
= base_type
;
16951 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16953 TYPE_TARGET_TYPE (inner_array
) =
16954 copy_type (TYPE_TARGET_TYPE (inner_array
));
16955 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16958 el_type
= TYPE_TARGET_TYPE (inner_array
);
16959 cnst
|= TYPE_CONST (el_type
);
16960 voltl
|= TYPE_VOLATILE (el_type
);
16961 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16963 return set_die_type (die
, base_type
, cu
);
16966 static struct type
*
16967 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16969 struct type
*base_type
, *cv_type
;
16971 base_type
= die_type (die
, cu
);
16973 /* The die_type call above may have already set the type for this DIE. */
16974 cv_type
= get_die_type (die
, cu
);
16978 /* In case the const qualifier is applied to an array type, the element type
16979 is so qualified, not the array type (section 6.7.3 of C99). */
16980 if (base_type
->code () == TYPE_CODE_ARRAY
)
16981 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16983 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16984 return set_die_type (die
, cv_type
, cu
);
16987 static struct type
*
16988 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16990 struct type
*base_type
, *cv_type
;
16992 base_type
= die_type (die
, cu
);
16994 /* The die_type call above may have already set the type for this DIE. */
16995 cv_type
= get_die_type (die
, cu
);
16999 /* In case the volatile qualifier is applied to an array type, the
17000 element type is so qualified, not the array type (section 6.7.3
17002 if (base_type
->code () == TYPE_CODE_ARRAY
)
17003 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17005 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17006 return set_die_type (die
, cv_type
, cu
);
17009 /* Handle DW_TAG_restrict_type. */
17011 static struct type
*
17012 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17014 struct type
*base_type
, *cv_type
;
17016 base_type
= die_type (die
, cu
);
17018 /* The die_type call above may have already set the type for this DIE. */
17019 cv_type
= get_die_type (die
, cu
);
17023 cv_type
= make_restrict_type (base_type
);
17024 return set_die_type (die
, cv_type
, cu
);
17027 /* Handle DW_TAG_atomic_type. */
17029 static struct type
*
17030 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17032 struct type
*base_type
, *cv_type
;
17034 base_type
= die_type (die
, cu
);
17036 /* The die_type call above may have already set the type for this DIE. */
17037 cv_type
= get_die_type (die
, cu
);
17041 cv_type
= make_atomic_type (base_type
);
17042 return set_die_type (die
, cv_type
, cu
);
17045 /* Extract all information from a DW_TAG_string_type DIE and add to
17046 the user defined type vector. It isn't really a user defined type,
17047 but it behaves like one, with other DIE's using an AT_user_def_type
17048 attribute to reference it. */
17050 static struct type
*
17051 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17053 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17054 struct gdbarch
*gdbarch
= objfile
->arch ();
17055 struct type
*type
, *range_type
, *index_type
, *char_type
;
17056 struct attribute
*attr
;
17057 struct dynamic_prop prop
;
17058 bool length_is_constant
= true;
17061 /* There are a couple of places where bit sizes might be made use of
17062 when parsing a DW_TAG_string_type, however, no producer that we know
17063 of make use of these. Handling bit sizes that are a multiple of the
17064 byte size is easy enough, but what about other bit sizes? Lets deal
17065 with that problem when we have to. Warn about these attributes being
17066 unsupported, then parse the type and ignore them like we always
17068 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17069 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17071 static bool warning_printed
= false;
17072 if (!warning_printed
)
17074 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17075 "currently supported on DW_TAG_string_type."));
17076 warning_printed
= true;
17080 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17081 if (attr
!= nullptr && !attr
->form_is_constant ())
17083 /* The string length describes the location at which the length of
17084 the string can be found. The size of the length field can be
17085 specified with one of the attributes below. */
17086 struct type
*prop_type
;
17087 struct attribute
*len
17088 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17089 if (len
== nullptr)
17090 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17091 if (len
!= nullptr && len
->form_is_constant ())
17093 /* Pass 0 as the default as we know this attribute is constant
17094 and the default value will not be returned. */
17095 LONGEST sz
= len
->constant_value (0);
17096 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17100 /* If the size is not specified then we assume it is the size of
17101 an address on this target. */
17102 prop_type
= cu
->addr_sized_int_type (true);
17105 /* Convert the attribute into a dynamic property. */
17106 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17109 length_is_constant
= false;
17111 else if (attr
!= nullptr)
17113 /* This DW_AT_string_length just contains the length with no
17114 indirection. There's no need to create a dynamic property in this
17115 case. Pass 0 for the default value as we know it will not be
17116 returned in this case. */
17117 length
= attr
->constant_value (0);
17119 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17121 /* We don't currently support non-constant byte sizes for strings. */
17122 length
= attr
->constant_value (1);
17126 /* Use 1 as a fallback length if we have nothing else. */
17130 index_type
= objfile_type (objfile
)->builtin_int
;
17131 if (length_is_constant
)
17132 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17135 struct dynamic_prop low_bound
;
17137 low_bound
.kind
= PROP_CONST
;
17138 low_bound
.data
.const_val
= 1;
17139 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17141 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17142 type
= create_string_type (NULL
, char_type
, range_type
);
17144 return set_die_type (die
, type
, cu
);
17147 /* Assuming that DIE corresponds to a function, returns nonzero
17148 if the function is prototyped. */
17151 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17153 struct attribute
*attr
;
17155 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17156 if (attr
&& (DW_UNSND (attr
) != 0))
17159 /* The DWARF standard implies that the DW_AT_prototyped attribute
17160 is only meaningful for C, but the concept also extends to other
17161 languages that allow unprototyped functions (Eg: Objective C).
17162 For all other languages, assume that functions are always
17164 if (cu
->language
!= language_c
17165 && cu
->language
!= language_objc
17166 && cu
->language
!= language_opencl
)
17169 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17170 prototyped and unprototyped functions; default to prototyped,
17171 since that is more common in modern code (and RealView warns
17172 about unprototyped functions). */
17173 if (producer_is_realview (cu
->producer
))
17179 /* Handle DIES due to C code like:
17183 int (*funcp)(int a, long l);
17187 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17189 static struct type
*
17190 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17192 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17193 struct type
*type
; /* Type that this function returns. */
17194 struct type
*ftype
; /* Function that returns above type. */
17195 struct attribute
*attr
;
17197 type
= die_type (die
, cu
);
17199 /* The die_type call above may have already set the type for this DIE. */
17200 ftype
= get_die_type (die
, cu
);
17204 ftype
= lookup_function_type (type
);
17206 if (prototyped_function_p (die
, cu
))
17207 TYPE_PROTOTYPED (ftype
) = 1;
17209 /* Store the calling convention in the type if it's available in
17210 the subroutine die. Otherwise set the calling convention to
17211 the default value DW_CC_normal. */
17212 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17213 if (attr
!= nullptr
17214 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17215 TYPE_CALLING_CONVENTION (ftype
)
17216 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17217 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17218 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17220 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17222 /* Record whether the function returns normally to its caller or not
17223 if the DWARF producer set that information. */
17224 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17225 if (attr
&& (DW_UNSND (attr
) != 0))
17226 TYPE_NO_RETURN (ftype
) = 1;
17228 /* We need to add the subroutine type to the die immediately so
17229 we don't infinitely recurse when dealing with parameters
17230 declared as the same subroutine type. */
17231 set_die_type (die
, ftype
, cu
);
17233 if (die
->child
!= NULL
)
17235 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17236 struct die_info
*child_die
;
17237 int nparams
, iparams
;
17239 /* Count the number of parameters.
17240 FIXME: GDB currently ignores vararg functions, but knows about
17241 vararg member functions. */
17243 child_die
= die
->child
;
17244 while (child_die
&& child_die
->tag
)
17246 if (child_die
->tag
== DW_TAG_formal_parameter
)
17248 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17249 TYPE_VARARGS (ftype
) = 1;
17250 child_die
= child_die
->sibling
;
17253 /* Allocate storage for parameters and fill them in. */
17254 ftype
->set_num_fields (nparams
);
17256 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17258 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17259 even if we error out during the parameters reading below. */
17260 for (iparams
= 0; iparams
< nparams
; iparams
++)
17261 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17264 child_die
= die
->child
;
17265 while (child_die
&& child_die
->tag
)
17267 if (child_die
->tag
== DW_TAG_formal_parameter
)
17269 struct type
*arg_type
;
17271 /* DWARF version 2 has no clean way to discern C++
17272 static and non-static member functions. G++ helps
17273 GDB by marking the first parameter for non-static
17274 member functions (which is the this pointer) as
17275 artificial. We pass this information to
17276 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17278 DWARF version 3 added DW_AT_object_pointer, which GCC
17279 4.5 does not yet generate. */
17280 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17281 if (attr
!= nullptr)
17282 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17284 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17285 arg_type
= die_type (child_die
, cu
);
17287 /* RealView does not mark THIS as const, which the testsuite
17288 expects. GCC marks THIS as const in method definitions,
17289 but not in the class specifications (GCC PR 43053). */
17290 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17291 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17294 struct dwarf2_cu
*arg_cu
= cu
;
17295 const char *name
= dwarf2_name (child_die
, cu
);
17297 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17298 if (attr
!= nullptr)
17300 /* If the compiler emits this, use it. */
17301 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17304 else if (name
&& strcmp (name
, "this") == 0)
17305 /* Function definitions will have the argument names. */
17307 else if (name
== NULL
&& iparams
== 0)
17308 /* Declarations may not have the names, so like
17309 elsewhere in GDB, assume an artificial first
17310 argument is "this". */
17314 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17318 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17321 child_die
= child_die
->sibling
;
17328 static struct type
*
17329 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17331 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17332 const char *name
= NULL
;
17333 struct type
*this_type
, *target_type
;
17335 name
= dwarf2_full_name (NULL
, die
, cu
);
17336 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17337 TYPE_TARGET_STUB (this_type
) = 1;
17338 set_die_type (die
, this_type
, cu
);
17339 target_type
= die_type (die
, cu
);
17340 if (target_type
!= this_type
)
17341 TYPE_TARGET_TYPE (this_type
) = target_type
;
17344 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17345 spec and cause infinite loops in GDB. */
17346 complaint (_("Self-referential DW_TAG_typedef "
17347 "- DIE at %s [in module %s]"),
17348 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17349 TYPE_TARGET_TYPE (this_type
) = NULL
;
17353 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17354 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17355 Handle these by just returning the target type, rather than
17356 constructing an anonymous typedef type and trying to handle this
17358 set_die_type (die
, target_type
, cu
);
17359 return target_type
;
17364 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17365 (which may be different from NAME) to the architecture back-end to allow
17366 it to guess the correct format if necessary. */
17368 static struct type
*
17369 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17370 const char *name_hint
, enum bfd_endian byte_order
)
17372 struct gdbarch
*gdbarch
= objfile
->arch ();
17373 const struct floatformat
**format
;
17376 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17378 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17380 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17385 /* Allocate an integer type of size BITS and name NAME. */
17387 static struct type
*
17388 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17389 int bits
, int unsigned_p
, const char *name
)
17393 /* Versions of Intel's C Compiler generate an integer type called "void"
17394 instead of using DW_TAG_unspecified_type. This has been seen on
17395 at least versions 14, 17, and 18. */
17396 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17397 && strcmp (name
, "void") == 0)
17398 type
= objfile_type (objfile
)->builtin_void
;
17400 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17405 /* Initialise and return a floating point type of size BITS suitable for
17406 use as a component of a complex number. The NAME_HINT is passed through
17407 when initialising the floating point type and is the name of the complex
17410 As DWARF doesn't currently provide an explicit name for the components
17411 of a complex number, but it can be helpful to have these components
17412 named, we try to select a suitable name based on the size of the
17414 static struct type
*
17415 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17416 struct objfile
*objfile
,
17417 int bits
, const char *name_hint
,
17418 enum bfd_endian byte_order
)
17420 gdbarch
*gdbarch
= objfile
->arch ();
17421 struct type
*tt
= nullptr;
17423 /* Try to find a suitable floating point builtin type of size BITS.
17424 We're going to use the name of this type as the name for the complex
17425 target type that we are about to create. */
17426 switch (cu
->language
)
17428 case language_fortran
:
17432 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17435 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17437 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17439 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17447 tt
= builtin_type (gdbarch
)->builtin_float
;
17450 tt
= builtin_type (gdbarch
)->builtin_double
;
17452 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17454 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17460 /* If the type we found doesn't match the size we were looking for, then
17461 pretend we didn't find a type at all, the complex target type we
17462 create will then be nameless. */
17463 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17466 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17467 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17470 /* Find a representation of a given base type and install
17471 it in the TYPE field of the die. */
17473 static struct type
*
17474 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17476 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17478 struct attribute
*attr
;
17479 int encoding
= 0, bits
= 0;
17483 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17484 if (attr
!= nullptr)
17485 encoding
= DW_UNSND (attr
);
17486 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17487 if (attr
!= nullptr)
17488 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17489 name
= dwarf2_name (die
, cu
);
17491 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17493 arch
= objfile
->arch ();
17494 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17496 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17499 int endianity
= DW_UNSND (attr
);
17504 byte_order
= BFD_ENDIAN_BIG
;
17506 case DW_END_little
:
17507 byte_order
= BFD_ENDIAN_LITTLE
;
17510 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17517 case DW_ATE_address
:
17518 /* Turn DW_ATE_address into a void * pointer. */
17519 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17520 type
= init_pointer_type (objfile
, bits
, name
, type
);
17522 case DW_ATE_boolean
:
17523 type
= init_boolean_type (objfile
, bits
, 1, name
);
17525 case DW_ATE_complex_float
:
17526 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17528 if (type
->code () == TYPE_CODE_ERROR
)
17530 if (name
== nullptr)
17532 struct obstack
*obstack
17533 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17534 name
= obconcat (obstack
, "_Complex ", type
->name (),
17537 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17540 type
= init_complex_type (name
, type
);
17542 case DW_ATE_decimal_float
:
17543 type
= init_decfloat_type (objfile
, bits
, name
);
17546 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17548 case DW_ATE_signed
:
17549 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17551 case DW_ATE_unsigned
:
17552 if (cu
->language
== language_fortran
17554 && startswith (name
, "character("))
17555 type
= init_character_type (objfile
, bits
, 1, name
);
17557 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17559 case DW_ATE_signed_char
:
17560 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17561 || cu
->language
== language_pascal
17562 || cu
->language
== language_fortran
)
17563 type
= init_character_type (objfile
, bits
, 0, name
);
17565 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17567 case DW_ATE_unsigned_char
:
17568 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17569 || cu
->language
== language_pascal
17570 || cu
->language
== language_fortran
17571 || cu
->language
== language_rust
)
17572 type
= init_character_type (objfile
, bits
, 1, name
);
17574 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17579 type
= builtin_type (arch
)->builtin_char16
;
17580 else if (bits
== 32)
17581 type
= builtin_type (arch
)->builtin_char32
;
17584 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17586 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17588 return set_die_type (die
, type
, cu
);
17593 complaint (_("unsupported DW_AT_encoding: '%s'"),
17594 dwarf_type_encoding_name (encoding
));
17595 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17599 if (name
&& strcmp (name
, "char") == 0)
17600 TYPE_NOSIGN (type
) = 1;
17602 maybe_set_alignment (cu
, die
, type
);
17604 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17606 return set_die_type (die
, type
, cu
);
17609 /* Parse dwarf attribute if it's a block, reference or constant and put the
17610 resulting value of the attribute into struct bound_prop.
17611 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17614 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17615 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17616 struct type
*default_type
)
17618 struct dwarf2_property_baton
*baton
;
17619 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17620 struct objfile
*objfile
= per_objfile
->objfile
;
17621 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17623 gdb_assert (default_type
!= NULL
);
17625 if (attr
== NULL
|| prop
== NULL
)
17628 if (attr
->form_is_block ())
17630 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17631 baton
->property_type
= default_type
;
17632 baton
->locexpr
.per_cu
= cu
->per_cu
;
17633 baton
->locexpr
.per_objfile
= per_objfile
;
17634 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17635 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17636 switch (attr
->name
)
17638 case DW_AT_string_length
:
17639 baton
->locexpr
.is_reference
= true;
17642 baton
->locexpr
.is_reference
= false;
17645 prop
->data
.baton
= baton
;
17646 prop
->kind
= PROP_LOCEXPR
;
17647 gdb_assert (prop
->data
.baton
!= NULL
);
17649 else if (attr
->form_is_ref ())
17651 struct dwarf2_cu
*target_cu
= cu
;
17652 struct die_info
*target_die
;
17653 struct attribute
*target_attr
;
17655 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17656 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17657 if (target_attr
== NULL
)
17658 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17660 if (target_attr
== NULL
)
17663 switch (target_attr
->name
)
17665 case DW_AT_location
:
17666 if (target_attr
->form_is_section_offset ())
17668 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17669 baton
->property_type
= die_type (target_die
, target_cu
);
17670 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17671 prop
->data
.baton
= baton
;
17672 prop
->kind
= PROP_LOCLIST
;
17673 gdb_assert (prop
->data
.baton
!= NULL
);
17675 else if (target_attr
->form_is_block ())
17677 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17678 baton
->property_type
= die_type (target_die
, target_cu
);
17679 baton
->locexpr
.per_cu
= cu
->per_cu
;
17680 baton
->locexpr
.per_objfile
= per_objfile
;
17681 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17682 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17683 baton
->locexpr
.is_reference
= true;
17684 prop
->data
.baton
= baton
;
17685 prop
->kind
= PROP_LOCEXPR
;
17686 gdb_assert (prop
->data
.baton
!= NULL
);
17690 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17691 "dynamic property");
17695 case DW_AT_data_member_location
:
17699 if (!handle_data_member_location (target_die
, target_cu
,
17703 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17704 baton
->property_type
= read_type_die (target_die
->parent
,
17706 baton
->offset_info
.offset
= offset
;
17707 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17708 prop
->data
.baton
= baton
;
17709 prop
->kind
= PROP_ADDR_OFFSET
;
17714 else if (attr
->form_is_constant ())
17716 prop
->data
.const_val
= attr
->constant_value (0);
17717 prop
->kind
= PROP_CONST
;
17721 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17722 dwarf2_name (die
, cu
));
17732 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
17734 struct type
*int_type
;
17736 /* Helper macro to examine the various builtin types. */
17737 #define TRY_TYPE(F) \
17738 int_type = (unsigned_p \
17739 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17740 : objfile_type (objfile)->builtin_ ## F); \
17741 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17748 TRY_TYPE (long_long
);
17752 gdb_assert_not_reached ("unable to find suitable integer type");
17758 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
17760 int addr_size
= this->per_cu
->addr_size ();
17761 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
17764 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17765 present (which is valid) then compute the default type based on the
17766 compilation units address size. */
17768 static struct type
*
17769 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17771 struct type
*index_type
= die_type (die
, cu
);
17773 /* Dwarf-2 specifications explicitly allows to create subrange types
17774 without specifying a base type.
17775 In that case, the base type must be set to the type of
17776 the lower bound, upper bound or count, in that order, if any of these
17777 three attributes references an object that has a type.
17778 If no base type is found, the Dwarf-2 specifications say that
17779 a signed integer type of size equal to the size of an address should
17781 For the following C code: `extern char gdb_int [];'
17782 GCC produces an empty range DIE.
17783 FIXME: muller/2010-05-28: Possible references to object for low bound,
17784 high bound or count are not yet handled by this code. */
17785 if (index_type
->code () == TYPE_CODE_VOID
)
17786 index_type
= cu
->addr_sized_int_type (false);
17791 /* Read the given DW_AT_subrange DIE. */
17793 static struct type
*
17794 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17796 struct type
*base_type
, *orig_base_type
;
17797 struct type
*range_type
;
17798 struct attribute
*attr
;
17799 struct dynamic_prop low
, high
;
17800 int low_default_is_valid
;
17801 int high_bound_is_count
= 0;
17803 ULONGEST negative_mask
;
17805 orig_base_type
= read_subrange_index_type (die
, cu
);
17807 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17808 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17809 creating the range type, but we use the result of check_typedef
17810 when examining properties of the type. */
17811 base_type
= check_typedef (orig_base_type
);
17813 /* The die_type call above may have already set the type for this DIE. */
17814 range_type
= get_die_type (die
, cu
);
17818 low
.kind
= PROP_CONST
;
17819 high
.kind
= PROP_CONST
;
17820 high
.data
.const_val
= 0;
17822 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17823 omitting DW_AT_lower_bound. */
17824 switch (cu
->language
)
17827 case language_cplus
:
17828 low
.data
.const_val
= 0;
17829 low_default_is_valid
= 1;
17831 case language_fortran
:
17832 low
.data
.const_val
= 1;
17833 low_default_is_valid
= 1;
17836 case language_objc
:
17837 case language_rust
:
17838 low
.data
.const_val
= 0;
17839 low_default_is_valid
= (cu
->header
.version
>= 4);
17843 case language_pascal
:
17844 low
.data
.const_val
= 1;
17845 low_default_is_valid
= (cu
->header
.version
>= 4);
17848 low
.data
.const_val
= 0;
17849 low_default_is_valid
= 0;
17853 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17854 if (attr
!= nullptr)
17855 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17856 else if (!low_default_is_valid
)
17857 complaint (_("Missing DW_AT_lower_bound "
17858 "- DIE at %s [in module %s]"),
17859 sect_offset_str (die
->sect_off
),
17860 objfile_name (cu
->per_objfile
->objfile
));
17862 struct attribute
*attr_ub
, *attr_count
;
17863 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17864 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17866 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17867 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17869 /* If bounds are constant do the final calculation here. */
17870 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17871 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17873 high_bound_is_count
= 1;
17877 if (attr_ub
!= NULL
)
17878 complaint (_("Unresolved DW_AT_upper_bound "
17879 "- DIE at %s [in module %s]"),
17880 sect_offset_str (die
->sect_off
),
17881 objfile_name (cu
->per_objfile
->objfile
));
17882 if (attr_count
!= NULL
)
17883 complaint (_("Unresolved DW_AT_count "
17884 "- DIE at %s [in module %s]"),
17885 sect_offset_str (die
->sect_off
),
17886 objfile_name (cu
->per_objfile
->objfile
));
17891 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17892 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17893 bias
= bias_attr
->constant_value (0);
17895 /* Normally, the DWARF producers are expected to use a signed
17896 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17897 But this is unfortunately not always the case, as witnessed
17898 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17899 is used instead. To work around that ambiguity, we treat
17900 the bounds as signed, and thus sign-extend their values, when
17901 the base type is signed. */
17903 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17904 if (low
.kind
== PROP_CONST
17905 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17906 low
.data
.const_val
|= negative_mask
;
17907 if (high
.kind
== PROP_CONST
17908 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17909 high
.data
.const_val
|= negative_mask
;
17911 /* Check for bit and byte strides. */
17912 struct dynamic_prop byte_stride_prop
;
17913 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17914 if (attr_byte_stride
!= nullptr)
17916 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17917 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17921 struct dynamic_prop bit_stride_prop
;
17922 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17923 if (attr_bit_stride
!= nullptr)
17925 /* It only makes sense to have either a bit or byte stride. */
17926 if (attr_byte_stride
!= nullptr)
17928 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17929 "- DIE at %s [in module %s]"),
17930 sect_offset_str (die
->sect_off
),
17931 objfile_name (cu
->per_objfile
->objfile
));
17932 attr_bit_stride
= nullptr;
17936 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17937 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17942 if (attr_byte_stride
!= nullptr
17943 || attr_bit_stride
!= nullptr)
17945 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17946 struct dynamic_prop
*stride
17947 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17950 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17951 &high
, bias
, stride
, byte_stride_p
);
17954 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17956 if (high_bound_is_count
)
17957 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17959 /* Ada expects an empty array on no boundary attributes. */
17960 if (attr
== NULL
&& cu
->language
!= language_ada
)
17961 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17963 name
= dwarf2_name (die
, cu
);
17965 range_type
->set_name (name
);
17967 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17968 if (attr
!= nullptr)
17969 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17971 maybe_set_alignment (cu
, die
, range_type
);
17973 set_die_type (die
, range_type
, cu
);
17975 /* set_die_type should be already done. */
17976 set_descriptive_type (range_type
, die
, cu
);
17981 static struct type
*
17982 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17986 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
17987 type
->set_name (dwarf2_name (die
, cu
));
17989 /* In Ada, an unspecified type is typically used when the description
17990 of the type is deferred to a different unit. When encountering
17991 such a type, we treat it as a stub, and try to resolve it later on,
17993 if (cu
->language
== language_ada
)
17994 TYPE_STUB (type
) = 1;
17996 return set_die_type (die
, type
, cu
);
17999 /* Read a single die and all its descendents. Set the die's sibling
18000 field to NULL; set other fields in the die correctly, and set all
18001 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18002 location of the info_ptr after reading all of those dies. PARENT
18003 is the parent of the die in question. */
18005 static struct die_info
*
18006 read_die_and_children (const struct die_reader_specs
*reader
,
18007 const gdb_byte
*info_ptr
,
18008 const gdb_byte
**new_info_ptr
,
18009 struct die_info
*parent
)
18011 struct die_info
*die
;
18012 const gdb_byte
*cur_ptr
;
18014 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18017 *new_info_ptr
= cur_ptr
;
18020 store_in_ref_table (die
, reader
->cu
);
18022 if (die
->has_children
)
18023 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18027 *new_info_ptr
= cur_ptr
;
18030 die
->sibling
= NULL
;
18031 die
->parent
= parent
;
18035 /* Read a die, all of its descendents, and all of its siblings; set
18036 all of the fields of all of the dies correctly. Arguments are as
18037 in read_die_and_children. */
18039 static struct die_info
*
18040 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18041 const gdb_byte
*info_ptr
,
18042 const gdb_byte
**new_info_ptr
,
18043 struct die_info
*parent
)
18045 struct die_info
*first_die
, *last_sibling
;
18046 const gdb_byte
*cur_ptr
;
18048 cur_ptr
= info_ptr
;
18049 first_die
= last_sibling
= NULL
;
18053 struct die_info
*die
18054 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18058 *new_info_ptr
= cur_ptr
;
18065 last_sibling
->sibling
= die
;
18067 last_sibling
= die
;
18071 /* Read a die, all of its descendents, and all of its siblings; set
18072 all of the fields of all of the dies correctly. Arguments are as
18073 in read_die_and_children.
18074 This the main entry point for reading a DIE and all its children. */
18076 static struct die_info
*
18077 read_die_and_siblings (const struct die_reader_specs
*reader
,
18078 const gdb_byte
*info_ptr
,
18079 const gdb_byte
**new_info_ptr
,
18080 struct die_info
*parent
)
18082 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18083 new_info_ptr
, parent
);
18085 if (dwarf_die_debug
)
18087 fprintf_unfiltered (gdb_stdlog
,
18088 "Read die from %s@0x%x of %s:\n",
18089 reader
->die_section
->get_name (),
18090 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18091 bfd_get_filename (reader
->abfd
));
18092 dump_die (die
, dwarf_die_debug
);
18098 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18100 The caller is responsible for filling in the extra attributes
18101 and updating (*DIEP)->num_attrs.
18102 Set DIEP to point to a newly allocated die with its information,
18103 except for its child, sibling, and parent fields. */
18105 static const gdb_byte
*
18106 read_full_die_1 (const struct die_reader_specs
*reader
,
18107 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18108 int num_extra_attrs
)
18110 unsigned int abbrev_number
, bytes_read
, i
;
18111 struct abbrev_info
*abbrev
;
18112 struct die_info
*die
;
18113 struct dwarf2_cu
*cu
= reader
->cu
;
18114 bfd
*abfd
= reader
->abfd
;
18116 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18117 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18118 info_ptr
+= bytes_read
;
18119 if (!abbrev_number
)
18125 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18127 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18129 bfd_get_filename (abfd
));
18131 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18132 die
->sect_off
= sect_off
;
18133 die
->tag
= abbrev
->tag
;
18134 die
->abbrev
= abbrev_number
;
18135 die
->has_children
= abbrev
->has_children
;
18137 /* Make the result usable.
18138 The caller needs to update num_attrs after adding the extra
18140 die
->num_attrs
= abbrev
->num_attrs
;
18142 std::vector
<int> indexes_that_need_reprocess
;
18143 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18145 bool need_reprocess
;
18147 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18148 info_ptr
, &need_reprocess
);
18149 if (need_reprocess
)
18150 indexes_that_need_reprocess
.push_back (i
);
18153 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18154 if (attr
!= nullptr)
18155 cu
->str_offsets_base
= DW_UNSND (attr
);
18157 attr
= die
->attr (DW_AT_loclists_base
);
18158 if (attr
!= nullptr)
18159 cu
->loclist_base
= DW_UNSND (attr
);
18161 auto maybe_addr_base
= die
->addr_base ();
18162 if (maybe_addr_base
.has_value ())
18163 cu
->addr_base
= *maybe_addr_base
;
18164 for (int index
: indexes_that_need_reprocess
)
18165 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18170 /* Read a die and all its attributes.
18171 Set DIEP to point to a newly allocated die with its information,
18172 except for its child, sibling, and parent fields. */
18174 static const gdb_byte
*
18175 read_full_die (const struct die_reader_specs
*reader
,
18176 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18178 const gdb_byte
*result
;
18180 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18182 if (dwarf_die_debug
)
18184 fprintf_unfiltered (gdb_stdlog
,
18185 "Read die from %s@0x%x of %s:\n",
18186 reader
->die_section
->get_name (),
18187 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18188 bfd_get_filename (reader
->abfd
));
18189 dump_die (*diep
, dwarf_die_debug
);
18196 /* Returns nonzero if TAG represents a type that we might generate a partial
18200 is_type_tag_for_partial (int tag
)
18205 /* Some types that would be reasonable to generate partial symbols for,
18206 that we don't at present. */
18207 case DW_TAG_array_type
:
18208 case DW_TAG_file_type
:
18209 case DW_TAG_ptr_to_member_type
:
18210 case DW_TAG_set_type
:
18211 case DW_TAG_string_type
:
18212 case DW_TAG_subroutine_type
:
18214 case DW_TAG_base_type
:
18215 case DW_TAG_class_type
:
18216 case DW_TAG_interface_type
:
18217 case DW_TAG_enumeration_type
:
18218 case DW_TAG_structure_type
:
18219 case DW_TAG_subrange_type
:
18220 case DW_TAG_typedef
:
18221 case DW_TAG_union_type
:
18228 /* Load all DIEs that are interesting for partial symbols into memory. */
18230 static struct partial_die_info
*
18231 load_partial_dies (const struct die_reader_specs
*reader
,
18232 const gdb_byte
*info_ptr
, int building_psymtab
)
18234 struct dwarf2_cu
*cu
= reader
->cu
;
18235 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18236 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18237 unsigned int bytes_read
;
18238 unsigned int load_all
= 0;
18239 int nesting_level
= 1;
18244 gdb_assert (cu
->per_cu
!= NULL
);
18245 if (cu
->per_cu
->load_all_dies
)
18249 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18253 &cu
->comp_unit_obstack
,
18254 hashtab_obstack_allocate
,
18255 dummy_obstack_deallocate
);
18259 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18261 /* A NULL abbrev means the end of a series of children. */
18262 if (abbrev
== NULL
)
18264 if (--nesting_level
== 0)
18267 info_ptr
+= bytes_read
;
18268 last_die
= parent_die
;
18269 parent_die
= parent_die
->die_parent
;
18273 /* Check for template arguments. We never save these; if
18274 they're seen, we just mark the parent, and go on our way. */
18275 if (parent_die
!= NULL
18276 && cu
->language
== language_cplus
18277 && (abbrev
->tag
== DW_TAG_template_type_param
18278 || abbrev
->tag
== DW_TAG_template_value_param
))
18280 parent_die
->has_template_arguments
= 1;
18284 /* We don't need a partial DIE for the template argument. */
18285 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18290 /* We only recurse into c++ subprograms looking for template arguments.
18291 Skip their other children. */
18293 && cu
->language
== language_cplus
18294 && parent_die
!= NULL
18295 && parent_die
->tag
== DW_TAG_subprogram
)
18297 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18301 /* Check whether this DIE is interesting enough to save. Normally
18302 we would not be interested in members here, but there may be
18303 later variables referencing them via DW_AT_specification (for
18304 static members). */
18306 && !is_type_tag_for_partial (abbrev
->tag
)
18307 && abbrev
->tag
!= DW_TAG_constant
18308 && abbrev
->tag
!= DW_TAG_enumerator
18309 && abbrev
->tag
!= DW_TAG_subprogram
18310 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18311 && abbrev
->tag
!= DW_TAG_lexical_block
18312 && abbrev
->tag
!= DW_TAG_variable
18313 && abbrev
->tag
!= DW_TAG_namespace
18314 && abbrev
->tag
!= DW_TAG_module
18315 && abbrev
->tag
!= DW_TAG_member
18316 && abbrev
->tag
!= DW_TAG_imported_unit
18317 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18319 /* Otherwise we skip to the next sibling, if any. */
18320 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18324 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18327 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18329 /* This two-pass algorithm for processing partial symbols has a
18330 high cost in cache pressure. Thus, handle some simple cases
18331 here which cover the majority of C partial symbols. DIEs
18332 which neither have specification tags in them, nor could have
18333 specification tags elsewhere pointing at them, can simply be
18334 processed and discarded.
18336 This segment is also optional; scan_partial_symbols and
18337 add_partial_symbol will handle these DIEs if we chain
18338 them in normally. When compilers which do not emit large
18339 quantities of duplicate debug information are more common,
18340 this code can probably be removed. */
18342 /* Any complete simple types at the top level (pretty much all
18343 of them, for a language without namespaces), can be processed
18345 if (parent_die
== NULL
18346 && pdi
.has_specification
== 0
18347 && pdi
.is_declaration
== 0
18348 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18349 || pdi
.tag
== DW_TAG_base_type
18350 || pdi
.tag
== DW_TAG_subrange_type
))
18352 if (building_psymtab
&& pdi
.name
!= NULL
)
18353 add_psymbol_to_list (pdi
.name
, false,
18354 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18355 psymbol_placement::STATIC
,
18356 0, cu
->language
, objfile
);
18357 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18361 /* The exception for DW_TAG_typedef with has_children above is
18362 a workaround of GCC PR debug/47510. In the case of this complaint
18363 type_name_or_error will error on such types later.
18365 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18366 it could not find the child DIEs referenced later, this is checked
18367 above. In correct DWARF DW_TAG_typedef should have no children. */
18369 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18370 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18371 "- DIE at %s [in module %s]"),
18372 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18374 /* If we're at the second level, and we're an enumerator, and
18375 our parent has no specification (meaning possibly lives in a
18376 namespace elsewhere), then we can add the partial symbol now
18377 instead of queueing it. */
18378 if (pdi
.tag
== DW_TAG_enumerator
18379 && parent_die
!= NULL
18380 && parent_die
->die_parent
== NULL
18381 && parent_die
->tag
== DW_TAG_enumeration_type
18382 && parent_die
->has_specification
== 0)
18384 if (pdi
.name
== NULL
)
18385 complaint (_("malformed enumerator DIE ignored"));
18386 else if (building_psymtab
)
18387 add_psymbol_to_list (pdi
.name
, false,
18388 VAR_DOMAIN
, LOC_CONST
, -1,
18389 cu
->language
== language_cplus
18390 ? psymbol_placement::GLOBAL
18391 : psymbol_placement::STATIC
,
18392 0, cu
->language
, objfile
);
18394 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18398 struct partial_die_info
*part_die
18399 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18401 /* We'll save this DIE so link it in. */
18402 part_die
->die_parent
= parent_die
;
18403 part_die
->die_sibling
= NULL
;
18404 part_die
->die_child
= NULL
;
18406 if (last_die
&& last_die
== parent_die
)
18407 last_die
->die_child
= part_die
;
18409 last_die
->die_sibling
= part_die
;
18411 last_die
= part_die
;
18413 if (first_die
== NULL
)
18414 first_die
= part_die
;
18416 /* Maybe add the DIE to the hash table. Not all DIEs that we
18417 find interesting need to be in the hash table, because we
18418 also have the parent/sibling/child chains; only those that we
18419 might refer to by offset later during partial symbol reading.
18421 For now this means things that might have be the target of a
18422 DW_AT_specification, DW_AT_abstract_origin, or
18423 DW_AT_extension. DW_AT_extension will refer only to
18424 namespaces; DW_AT_abstract_origin refers to functions (and
18425 many things under the function DIE, but we do not recurse
18426 into function DIEs during partial symbol reading) and
18427 possibly variables as well; DW_AT_specification refers to
18428 declarations. Declarations ought to have the DW_AT_declaration
18429 flag. It happens that GCC forgets to put it in sometimes, but
18430 only for functions, not for types.
18432 Adding more things than necessary to the hash table is harmless
18433 except for the performance cost. Adding too few will result in
18434 wasted time in find_partial_die, when we reread the compilation
18435 unit with load_all_dies set. */
18438 || abbrev
->tag
== DW_TAG_constant
18439 || abbrev
->tag
== DW_TAG_subprogram
18440 || abbrev
->tag
== DW_TAG_variable
18441 || abbrev
->tag
== DW_TAG_namespace
18442 || part_die
->is_declaration
)
18446 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18447 to_underlying (part_die
->sect_off
),
18452 /* For some DIEs we want to follow their children (if any). For C
18453 we have no reason to follow the children of structures; for other
18454 languages we have to, so that we can get at method physnames
18455 to infer fully qualified class names, for DW_AT_specification,
18456 and for C++ template arguments. For C++, we also look one level
18457 inside functions to find template arguments (if the name of the
18458 function does not already contain the template arguments).
18460 For Ada and Fortran, we need to scan the children of subprograms
18461 and lexical blocks as well because these languages allow the
18462 definition of nested entities that could be interesting for the
18463 debugger, such as nested subprograms for instance. */
18464 if (last_die
->has_children
18466 || last_die
->tag
== DW_TAG_namespace
18467 || last_die
->tag
== DW_TAG_module
18468 || last_die
->tag
== DW_TAG_enumeration_type
18469 || (cu
->language
== language_cplus
18470 && last_die
->tag
== DW_TAG_subprogram
18471 && (last_die
->name
== NULL
18472 || strchr (last_die
->name
, '<') == NULL
))
18473 || (cu
->language
!= language_c
18474 && (last_die
->tag
== DW_TAG_class_type
18475 || last_die
->tag
== DW_TAG_interface_type
18476 || last_die
->tag
== DW_TAG_structure_type
18477 || last_die
->tag
== DW_TAG_union_type
))
18478 || ((cu
->language
== language_ada
18479 || cu
->language
== language_fortran
)
18480 && (last_die
->tag
== DW_TAG_subprogram
18481 || last_die
->tag
== DW_TAG_lexical_block
))))
18484 parent_die
= last_die
;
18488 /* Otherwise we skip to the next sibling, if any. */
18489 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18491 /* Back to the top, do it again. */
18495 partial_die_info::partial_die_info (sect_offset sect_off_
,
18496 struct abbrev_info
*abbrev
)
18497 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18501 /* Read a minimal amount of information into the minimal die structure.
18502 INFO_PTR should point just after the initial uleb128 of a DIE. */
18505 partial_die_info::read (const struct die_reader_specs
*reader
,
18506 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18508 struct dwarf2_cu
*cu
= reader
->cu
;
18509 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18511 int has_low_pc_attr
= 0;
18512 int has_high_pc_attr
= 0;
18513 int high_pc_relative
= 0;
18515 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18518 bool need_reprocess
;
18519 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18520 info_ptr
, &need_reprocess
);
18521 /* String and address offsets that need to do the reprocessing have
18522 already been read at this point, so there is no need to wait until
18523 the loop terminates to do the reprocessing. */
18524 if (need_reprocess
)
18525 read_attribute_reprocess (reader
, &attr
);
18526 /* Store the data if it is of an attribute we want to keep in a
18527 partial symbol table. */
18533 case DW_TAG_compile_unit
:
18534 case DW_TAG_partial_unit
:
18535 case DW_TAG_type_unit
:
18536 /* Compilation units have a DW_AT_name that is a filename, not
18537 a source language identifier. */
18538 case DW_TAG_enumeration_type
:
18539 case DW_TAG_enumerator
:
18540 /* These tags always have simple identifiers already; no need
18541 to canonicalize them. */
18542 name
= DW_STRING (&attr
);
18546 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18549 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18554 case DW_AT_linkage_name
:
18555 case DW_AT_MIPS_linkage_name
:
18556 /* Note that both forms of linkage name might appear. We
18557 assume they will be the same, and we only store the last
18559 linkage_name
= attr
.value_as_string ();
18560 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18561 See https://github.com/rust-lang/rust/issues/32925. */
18562 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18563 && strchr (linkage_name
, '{') != NULL
)
18564 linkage_name
= NULL
;
18567 has_low_pc_attr
= 1;
18568 lowpc
= attr
.value_as_address ();
18570 case DW_AT_high_pc
:
18571 has_high_pc_attr
= 1;
18572 highpc
= attr
.value_as_address ();
18573 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18574 high_pc_relative
= 1;
18576 case DW_AT_location
:
18577 /* Support the .debug_loc offsets. */
18578 if (attr
.form_is_block ())
18580 d
.locdesc
= DW_BLOCK (&attr
);
18582 else if (attr
.form_is_section_offset ())
18584 dwarf2_complex_location_expr_complaint ();
18588 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18589 "partial symbol information");
18592 case DW_AT_external
:
18593 is_external
= DW_UNSND (&attr
);
18595 case DW_AT_declaration
:
18596 is_declaration
= DW_UNSND (&attr
);
18601 case DW_AT_abstract_origin
:
18602 case DW_AT_specification
:
18603 case DW_AT_extension
:
18604 has_specification
= 1;
18605 spec_offset
= attr
.get_ref_die_offset ();
18606 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18607 || cu
->per_cu
->is_dwz
);
18609 case DW_AT_sibling
:
18610 /* Ignore absolute siblings, they might point outside of
18611 the current compile unit. */
18612 if (attr
.form
== DW_FORM_ref_addr
)
18613 complaint (_("ignoring absolute DW_AT_sibling"));
18616 const gdb_byte
*buffer
= reader
->buffer
;
18617 sect_offset off
= attr
.get_ref_die_offset ();
18618 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18620 if (sibling_ptr
< info_ptr
)
18621 complaint (_("DW_AT_sibling points backwards"));
18622 else if (sibling_ptr
> reader
->buffer_end
)
18623 reader
->die_section
->overflow_complaint ();
18625 sibling
= sibling_ptr
;
18628 case DW_AT_byte_size
:
18631 case DW_AT_const_value
:
18632 has_const_value
= 1;
18634 case DW_AT_calling_convention
:
18635 /* DWARF doesn't provide a way to identify a program's source-level
18636 entry point. DW_AT_calling_convention attributes are only meant
18637 to describe functions' calling conventions.
18639 However, because it's a necessary piece of information in
18640 Fortran, and before DWARF 4 DW_CC_program was the only
18641 piece of debugging information whose definition refers to
18642 a 'main program' at all, several compilers marked Fortran
18643 main programs with DW_CC_program --- even when those
18644 functions use the standard calling conventions.
18646 Although DWARF now specifies a way to provide this
18647 information, we support this practice for backward
18649 if (DW_UNSND (&attr
) == DW_CC_program
18650 && cu
->language
== language_fortran
)
18651 main_subprogram
= 1;
18654 if (DW_UNSND (&attr
) == DW_INL_inlined
18655 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18656 may_be_inlined
= 1;
18660 if (tag
== DW_TAG_imported_unit
)
18662 d
.sect_off
= attr
.get_ref_die_offset ();
18663 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18664 || cu
->per_cu
->is_dwz
);
18668 case DW_AT_main_subprogram
:
18669 main_subprogram
= DW_UNSND (&attr
);
18674 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18675 but that requires a full DIE, so instead we just
18677 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18678 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18679 + (need_ranges_base
18683 /* Value of the DW_AT_ranges attribute is the offset in the
18684 .debug_ranges section. */
18685 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18696 /* For Ada, if both the name and the linkage name appear, we prefer
18697 the latter. This lets "catch exception" work better, regardless
18698 of the order in which the name and linkage name were emitted.
18699 Really, though, this is just a workaround for the fact that gdb
18700 doesn't store both the name and the linkage name. */
18701 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18702 name
= linkage_name
;
18704 if (high_pc_relative
)
18707 if (has_low_pc_attr
&& has_high_pc_attr
)
18709 /* When using the GNU linker, .gnu.linkonce. sections are used to
18710 eliminate duplicate copies of functions and vtables and such.
18711 The linker will arbitrarily choose one and discard the others.
18712 The AT_*_pc values for such functions refer to local labels in
18713 these sections. If the section from that file was discarded, the
18714 labels are not in the output, so the relocs get a value of 0.
18715 If this is a discarded function, mark the pc bounds as invalid,
18716 so that GDB will ignore it. */
18717 if (lowpc
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
18719 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18720 struct gdbarch
*gdbarch
= objfile
->arch ();
18722 complaint (_("DW_AT_low_pc %s is zero "
18723 "for DIE at %s [in module %s]"),
18724 paddress (gdbarch
, lowpc
),
18725 sect_offset_str (sect_off
),
18726 objfile_name (objfile
));
18728 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18729 else if (lowpc
>= highpc
)
18731 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18732 struct gdbarch
*gdbarch
= objfile
->arch ();
18734 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18735 "for DIE at %s [in module %s]"),
18736 paddress (gdbarch
, lowpc
),
18737 paddress (gdbarch
, highpc
),
18738 sect_offset_str (sect_off
),
18739 objfile_name (objfile
));
18748 /* Find a cached partial DIE at OFFSET in CU. */
18750 struct partial_die_info
*
18751 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18753 struct partial_die_info
*lookup_die
= NULL
;
18754 struct partial_die_info
part_die (sect_off
);
18756 lookup_die
= ((struct partial_die_info
*)
18757 htab_find_with_hash (partial_dies
, &part_die
,
18758 to_underlying (sect_off
)));
18763 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18764 except in the case of .debug_types DIEs which do not reference
18765 outside their CU (they do however referencing other types via
18766 DW_FORM_ref_sig8). */
18768 static const struct cu_partial_die_info
18769 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18771 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
18772 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18773 struct partial_die_info
*pd
= NULL
;
18775 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18776 && cu
->header
.offset_in_cu_p (sect_off
))
18778 pd
= cu
->find_partial_die (sect_off
);
18781 /* We missed recording what we needed.
18782 Load all dies and try again. */
18786 /* TUs don't reference other CUs/TUs (except via type signatures). */
18787 if (cu
->per_cu
->is_debug_types
)
18789 error (_("Dwarf Error: Type Unit at offset %s contains"
18790 " external reference to offset %s [in module %s].\n"),
18791 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18792 bfd_get_filename (objfile
->obfd
));
18794 dwarf2_per_cu_data
*per_cu
18795 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18796 dwarf2_per_objfile
);
18798 cu
= dwarf2_per_objfile
->get_cu (per_cu
);
18799 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
18800 load_partial_comp_unit (per_cu
, dwarf2_per_objfile
, nullptr);
18802 cu
= dwarf2_per_objfile
->get_cu (per_cu
);
18805 pd
= cu
->find_partial_die (sect_off
);
18808 /* If we didn't find it, and not all dies have been loaded,
18809 load them all and try again. */
18811 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
18813 cu
->per_cu
->load_all_dies
= 1;
18815 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18816 THIS_CU->cu may already be in use. So we can't just free it and
18817 replace its DIEs with the ones we read in. Instead, we leave those
18818 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18819 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18821 load_partial_comp_unit (cu
->per_cu
, dwarf2_per_objfile
, cu
);
18823 pd
= cu
->find_partial_die (sect_off
);
18827 internal_error (__FILE__
, __LINE__
,
18828 _("could not find partial DIE %s "
18829 "in cache [from module %s]\n"),
18830 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18834 /* See if we can figure out if the class lives in a namespace. We do
18835 this by looking for a member function; its demangled name will
18836 contain namespace info, if there is any. */
18839 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18840 struct dwarf2_cu
*cu
)
18842 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18843 what template types look like, because the demangler
18844 frequently doesn't give the same name as the debug info. We
18845 could fix this by only using the demangled name to get the
18846 prefix (but see comment in read_structure_type). */
18848 struct partial_die_info
*real_pdi
;
18849 struct partial_die_info
*child_pdi
;
18851 /* If this DIE (this DIE's specification, if any) has a parent, then
18852 we should not do this. We'll prepend the parent's fully qualified
18853 name when we create the partial symbol. */
18855 real_pdi
= struct_pdi
;
18856 while (real_pdi
->has_specification
)
18858 auto res
= find_partial_die (real_pdi
->spec_offset
,
18859 real_pdi
->spec_is_dwz
, cu
);
18860 real_pdi
= res
.pdi
;
18864 if (real_pdi
->die_parent
!= NULL
)
18867 for (child_pdi
= struct_pdi
->die_child
;
18869 child_pdi
= child_pdi
->die_sibling
)
18871 if (child_pdi
->tag
== DW_TAG_subprogram
18872 && child_pdi
->linkage_name
!= NULL
)
18874 gdb::unique_xmalloc_ptr
<char> actual_class_name
18875 (language_class_name_from_physname (cu
->language_defn
,
18876 child_pdi
->linkage_name
));
18877 if (actual_class_name
!= NULL
)
18879 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18880 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18887 /* Return true if a DIE with TAG may have the DW_AT_const_value
18891 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18895 case DW_TAG_constant
:
18896 case DW_TAG_enumerator
:
18897 case DW_TAG_formal_parameter
:
18898 case DW_TAG_template_value_param
:
18899 case DW_TAG_variable
:
18907 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18909 /* Once we've fixed up a die, there's no point in doing so again.
18910 This also avoids a memory leak if we were to call
18911 guess_partial_die_structure_name multiple times. */
18915 /* If we found a reference attribute and the DIE has no name, try
18916 to find a name in the referred to DIE. */
18918 if (name
== NULL
&& has_specification
)
18920 struct partial_die_info
*spec_die
;
18922 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18923 spec_die
= res
.pdi
;
18926 spec_die
->fixup (cu
);
18928 if (spec_die
->name
)
18930 name
= spec_die
->name
;
18932 /* Copy DW_AT_external attribute if it is set. */
18933 if (spec_die
->is_external
)
18934 is_external
= spec_die
->is_external
;
18938 if (!has_const_value
&& has_specification
18939 && can_have_DW_AT_const_value_p (tag
))
18941 struct partial_die_info
*spec_die
;
18943 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18944 spec_die
= res
.pdi
;
18947 spec_die
->fixup (cu
);
18949 if (spec_die
->has_const_value
)
18951 /* Copy DW_AT_const_value attribute if it is set. */
18952 has_const_value
= spec_die
->has_const_value
;
18956 /* Set default names for some unnamed DIEs. */
18958 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18959 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18961 /* If there is no parent die to provide a namespace, and there are
18962 children, see if we can determine the namespace from their linkage
18964 if (cu
->language
== language_cplus
18965 && !cu
->per_objfile
->per_bfd
->types
.empty ()
18966 && die_parent
== NULL
18968 && (tag
== DW_TAG_class_type
18969 || tag
== DW_TAG_structure_type
18970 || tag
== DW_TAG_union_type
))
18971 guess_partial_die_structure_name (this, cu
);
18973 /* GCC might emit a nameless struct or union that has a linkage
18974 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18976 && (tag
== DW_TAG_class_type
18977 || tag
== DW_TAG_interface_type
18978 || tag
== DW_TAG_structure_type
18979 || tag
== DW_TAG_union_type
)
18980 && linkage_name
!= NULL
)
18982 gdb::unique_xmalloc_ptr
<char> demangled
18983 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18984 if (demangled
!= nullptr)
18988 /* Strip any leading namespaces/classes, keep only the base name.
18989 DW_AT_name for named DIEs does not contain the prefixes. */
18990 base
= strrchr (demangled
.get (), ':');
18991 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18994 base
= demangled
.get ();
18996 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18997 name
= objfile
->intern (base
);
19004 /* Read the .debug_loclists header contents from the given SECTION in the
19007 read_loclist_header (struct loclist_header
*header
,
19008 struct dwarf2_section_info
*section
)
19010 unsigned int bytes_read
;
19011 bfd
*abfd
= section
->get_bfd_owner ();
19012 const gdb_byte
*info_ptr
= section
->buffer
;
19013 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19014 info_ptr
+= bytes_read
;
19015 header
->version
= read_2_bytes (abfd
, info_ptr
);
19017 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19019 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19021 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19024 /* Return the DW_AT_loclists_base value for the CU. */
19026 lookup_loclist_base (struct dwarf2_cu
*cu
)
19028 /* For the .dwo unit, the loclist_base points to the first offset following
19029 the header. The header consists of the following entities-
19030 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19032 2. version (2 bytes)
19033 3. address size (1 byte)
19034 4. segment selector size (1 byte)
19035 5. offset entry count (4 bytes)
19036 These sizes are derived as per the DWARFv5 standard. */
19037 if (cu
->dwo_unit
!= nullptr)
19039 if (cu
->header
.initial_length_size
== 4)
19040 return LOCLIST_HEADER_SIZE32
;
19041 return LOCLIST_HEADER_SIZE64
;
19043 return cu
->loclist_base
;
19046 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19047 array of offsets in the .debug_loclists section. */
19049 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19051 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19053 bfd
*abfd
= objfile
->obfd
;
19054 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19055 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19057 section
->read (objfile
);
19058 if (section
->buffer
== NULL
)
19059 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19060 "section [in module %s]"), objfile_name (objfile
));
19061 struct loclist_header header
;
19062 read_loclist_header (&header
, section
);
19063 if (loclist_index
>= header
.offset_entry_count
)
19064 complaint (_("DW_FORM_loclistx pointing outside of "
19065 ".debug_loclists offset array [in module %s]"),
19066 objfile_name (objfile
));
19067 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19069 complaint (_("DW_FORM_loclistx pointing outside of "
19070 ".debug_loclists section [in module %s]"),
19071 objfile_name (objfile
));
19072 const gdb_byte
*info_ptr
19073 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19075 if (cu
->header
.offset_size
== 4)
19076 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19078 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19081 /* Process the attributes that had to be skipped in the first round. These
19082 attributes are the ones that need str_offsets_base or addr_base attributes.
19083 They could not have been processed in the first round, because at the time
19084 the values of str_offsets_base or addr_base may not have been known. */
19086 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19087 struct attribute
*attr
)
19089 struct dwarf2_cu
*cu
= reader
->cu
;
19090 switch (attr
->form
)
19092 case DW_FORM_addrx
:
19093 case DW_FORM_GNU_addr_index
:
19094 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19096 case DW_FORM_loclistx
:
19097 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19100 case DW_FORM_strx1
:
19101 case DW_FORM_strx2
:
19102 case DW_FORM_strx3
:
19103 case DW_FORM_strx4
:
19104 case DW_FORM_GNU_str_index
:
19106 unsigned int str_index
= DW_UNSND (attr
);
19107 if (reader
->dwo_file
!= NULL
)
19109 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19110 DW_STRING_IS_CANONICAL (attr
) = 0;
19114 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19115 DW_STRING_IS_CANONICAL (attr
) = 0;
19120 gdb_assert_not_reached (_("Unexpected DWARF form."));
19124 /* Read an attribute value described by an attribute form. */
19126 static const gdb_byte
*
19127 read_attribute_value (const struct die_reader_specs
*reader
,
19128 struct attribute
*attr
, unsigned form
,
19129 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19130 bool *need_reprocess
)
19132 struct dwarf2_cu
*cu
= reader
->cu
;
19133 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19134 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19135 bfd
*abfd
= reader
->abfd
;
19136 struct comp_unit_head
*cu_header
= &cu
->header
;
19137 unsigned int bytes_read
;
19138 struct dwarf_block
*blk
;
19139 *need_reprocess
= false;
19141 attr
->form
= (enum dwarf_form
) form
;
19144 case DW_FORM_ref_addr
:
19145 if (cu
->header
.version
== 2)
19146 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19149 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19151 info_ptr
+= bytes_read
;
19153 case DW_FORM_GNU_ref_alt
:
19154 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19155 info_ptr
+= bytes_read
;
19159 struct gdbarch
*gdbarch
= objfile
->arch ();
19160 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19161 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19162 info_ptr
+= bytes_read
;
19165 case DW_FORM_block2
:
19166 blk
= dwarf_alloc_block (cu
);
19167 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19169 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19170 info_ptr
+= blk
->size
;
19171 DW_BLOCK (attr
) = blk
;
19173 case DW_FORM_block4
:
19174 blk
= dwarf_alloc_block (cu
);
19175 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19177 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19178 info_ptr
+= blk
->size
;
19179 DW_BLOCK (attr
) = blk
;
19181 case DW_FORM_data2
:
19182 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19185 case DW_FORM_data4
:
19186 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19189 case DW_FORM_data8
:
19190 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19193 case DW_FORM_data16
:
19194 blk
= dwarf_alloc_block (cu
);
19196 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19198 DW_BLOCK (attr
) = blk
;
19200 case DW_FORM_sec_offset
:
19201 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19202 info_ptr
+= bytes_read
;
19204 case DW_FORM_loclistx
:
19206 *need_reprocess
= true;
19207 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19208 info_ptr
+= bytes_read
;
19211 case DW_FORM_string
:
19212 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19213 DW_STRING_IS_CANONICAL (attr
) = 0;
19214 info_ptr
+= bytes_read
;
19217 if (!cu
->per_cu
->is_dwz
)
19219 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19220 abfd
, info_ptr
, cu_header
,
19222 DW_STRING_IS_CANONICAL (attr
) = 0;
19223 info_ptr
+= bytes_read
;
19227 case DW_FORM_line_strp
:
19228 if (!cu
->per_cu
->is_dwz
)
19231 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
19233 DW_STRING_IS_CANONICAL (attr
) = 0;
19234 info_ptr
+= bytes_read
;
19238 case DW_FORM_GNU_strp_alt
:
19240 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19241 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19244 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19245 DW_STRING_IS_CANONICAL (attr
) = 0;
19246 info_ptr
+= bytes_read
;
19249 case DW_FORM_exprloc
:
19250 case DW_FORM_block
:
19251 blk
= dwarf_alloc_block (cu
);
19252 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19253 info_ptr
+= bytes_read
;
19254 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19255 info_ptr
+= blk
->size
;
19256 DW_BLOCK (attr
) = blk
;
19258 case DW_FORM_block1
:
19259 blk
= dwarf_alloc_block (cu
);
19260 blk
->size
= read_1_byte (abfd
, info_ptr
);
19262 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19263 info_ptr
+= blk
->size
;
19264 DW_BLOCK (attr
) = blk
;
19266 case DW_FORM_data1
:
19267 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19271 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19274 case DW_FORM_flag_present
:
19275 DW_UNSND (attr
) = 1;
19277 case DW_FORM_sdata
:
19278 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19279 info_ptr
+= bytes_read
;
19281 case DW_FORM_udata
:
19282 case DW_FORM_rnglistx
:
19283 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19284 info_ptr
+= bytes_read
;
19287 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19288 + read_1_byte (abfd
, info_ptr
));
19292 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19293 + read_2_bytes (abfd
, info_ptr
));
19297 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19298 + read_4_bytes (abfd
, info_ptr
));
19302 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19303 + read_8_bytes (abfd
, info_ptr
));
19306 case DW_FORM_ref_sig8
:
19307 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19310 case DW_FORM_ref_udata
:
19311 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19312 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19313 info_ptr
+= bytes_read
;
19315 case DW_FORM_indirect
:
19316 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19317 info_ptr
+= bytes_read
;
19318 if (form
== DW_FORM_implicit_const
)
19320 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19321 info_ptr
+= bytes_read
;
19323 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19324 info_ptr
, need_reprocess
);
19326 case DW_FORM_implicit_const
:
19327 DW_SND (attr
) = implicit_const
;
19329 case DW_FORM_addrx
:
19330 case DW_FORM_GNU_addr_index
:
19331 *need_reprocess
= true;
19332 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19333 info_ptr
+= bytes_read
;
19336 case DW_FORM_strx1
:
19337 case DW_FORM_strx2
:
19338 case DW_FORM_strx3
:
19339 case DW_FORM_strx4
:
19340 case DW_FORM_GNU_str_index
:
19342 ULONGEST str_index
;
19343 if (form
== DW_FORM_strx1
)
19345 str_index
= read_1_byte (abfd
, info_ptr
);
19348 else if (form
== DW_FORM_strx2
)
19350 str_index
= read_2_bytes (abfd
, info_ptr
);
19353 else if (form
== DW_FORM_strx3
)
19355 str_index
= read_3_bytes (abfd
, info_ptr
);
19358 else if (form
== DW_FORM_strx4
)
19360 str_index
= read_4_bytes (abfd
, info_ptr
);
19365 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19366 info_ptr
+= bytes_read
;
19368 *need_reprocess
= true;
19369 DW_UNSND (attr
) = str_index
;
19373 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19374 dwarf_form_name (form
),
19375 bfd_get_filename (abfd
));
19379 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19380 attr
->form
= DW_FORM_GNU_ref_alt
;
19382 /* We have seen instances where the compiler tried to emit a byte
19383 size attribute of -1 which ended up being encoded as an unsigned
19384 0xffffffff. Although 0xffffffff is technically a valid size value,
19385 an object of this size seems pretty unlikely so we can relatively
19386 safely treat these cases as if the size attribute was invalid and
19387 treat them as zero by default. */
19388 if (attr
->name
== DW_AT_byte_size
19389 && form
== DW_FORM_data4
19390 && DW_UNSND (attr
) >= 0xffffffff)
19393 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19394 hex_string (DW_UNSND (attr
)));
19395 DW_UNSND (attr
) = 0;
19401 /* Read an attribute described by an abbreviated attribute. */
19403 static const gdb_byte
*
19404 read_attribute (const struct die_reader_specs
*reader
,
19405 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19406 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19408 attr
->name
= abbrev
->name
;
19409 return read_attribute_value (reader
, attr
, abbrev
->form
,
19410 abbrev
->implicit_const
, info_ptr
,
19414 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19416 static const char *
19417 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19418 LONGEST str_offset
)
19420 return dwarf2_per_objfile
->per_bfd
->str
.read_string
19421 (dwarf2_per_objfile
->objfile
, str_offset
, "DW_FORM_strp");
19424 /* Return pointer to string at .debug_str offset as read from BUF.
19425 BUF is assumed to be in a compilation unit described by CU_HEADER.
19426 Return *BYTES_READ_PTR count of bytes read from BUF. */
19428 static const char *
19429 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19430 const gdb_byte
*buf
,
19431 const struct comp_unit_head
*cu_header
,
19432 unsigned int *bytes_read_ptr
)
19434 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19436 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19442 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19443 const struct comp_unit_head
*cu_header
,
19444 unsigned int *bytes_read_ptr
)
19446 bfd
*abfd
= objfile
->obfd
;
19447 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19449 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19452 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19453 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19454 ADDR_SIZE is the size of addresses from the CU header. */
19457 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19458 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19461 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19462 bfd
*abfd
= objfile
->obfd
;
19463 const gdb_byte
*info_ptr
;
19464 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19466 dwarf2_per_objfile
->per_bfd
->addr
.read (objfile
);
19467 if (dwarf2_per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19468 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19469 objfile_name (objfile
));
19470 if (addr_base_or_zero
+ addr_index
* addr_size
19471 >= dwarf2_per_objfile
->per_bfd
->addr
.size
)
19472 error (_("DW_FORM_addr_index pointing outside of "
19473 ".debug_addr section [in module %s]"),
19474 objfile_name (objfile
));
19475 info_ptr
= (dwarf2_per_objfile
->per_bfd
->addr
.buffer
19476 + addr_base_or_zero
+ addr_index
* addr_size
);
19477 if (addr_size
== 4)
19478 return bfd_get_32 (abfd
, info_ptr
);
19480 return bfd_get_64 (abfd
, info_ptr
);
19483 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19486 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19488 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
19489 cu
->addr_base
, cu
->header
.addr_size
);
19492 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19495 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19496 unsigned int *bytes_read
)
19498 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
19499 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19501 return read_addr_index (cu
, addr_index
);
19507 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
19508 dwarf2_per_objfile
*dwarf2_per_objfile
,
19509 unsigned int addr_index
)
19511 struct dwarf2_cu
*cu
= dwarf2_per_objfile
->get_cu (per_cu
);
19512 gdb::optional
<ULONGEST
> addr_base
;
19515 /* We need addr_base and addr_size.
19516 If we don't have PER_CU->cu, we have to get it.
19517 Nasty, but the alternative is storing the needed info in PER_CU,
19518 which at this point doesn't seem justified: it's not clear how frequently
19519 it would get used and it would increase the size of every PER_CU.
19520 Entry points like dwarf2_per_cu_addr_size do a similar thing
19521 so we're not in uncharted territory here.
19522 Alas we need to be a bit more complicated as addr_base is contained
19525 We don't need to read the entire CU(/TU).
19526 We just need the header and top level die.
19528 IWBN to use the aging mechanism to let us lazily later discard the CU.
19529 For now we skip this optimization. */
19533 addr_base
= cu
->addr_base
;
19534 addr_size
= cu
->header
.addr_size
;
19538 cutu_reader
reader (per_cu
, dwarf2_per_objfile
, nullptr, nullptr, false);
19539 addr_base
= reader
.cu
->addr_base
;
19540 addr_size
= reader
.cu
->header
.addr_size
;
19543 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19547 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19548 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19551 static const char *
19552 read_str_index (struct dwarf2_cu
*cu
,
19553 struct dwarf2_section_info
*str_section
,
19554 struct dwarf2_section_info
*str_offsets_section
,
19555 ULONGEST str_offsets_base
, ULONGEST str_index
)
19557 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19558 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19559 const char *objf_name
= objfile_name (objfile
);
19560 bfd
*abfd
= objfile
->obfd
;
19561 const gdb_byte
*info_ptr
;
19562 ULONGEST str_offset
;
19563 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19565 str_section
->read (objfile
);
19566 str_offsets_section
->read (objfile
);
19567 if (str_section
->buffer
== NULL
)
19568 error (_("%s used without %s section"
19569 " in CU at offset %s [in module %s]"),
19570 form_name
, str_section
->get_name (),
19571 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19572 if (str_offsets_section
->buffer
== NULL
)
19573 error (_("%s used without %s section"
19574 " in CU at offset %s [in module %s]"),
19575 form_name
, str_section
->get_name (),
19576 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19577 info_ptr
= (str_offsets_section
->buffer
19579 + str_index
* cu
->header
.offset_size
);
19580 if (cu
->header
.offset_size
== 4)
19581 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19583 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19584 if (str_offset
>= str_section
->size
)
19585 error (_("Offset from %s pointing outside of"
19586 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19587 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19588 return (const char *) (str_section
->buffer
+ str_offset
);
19591 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19593 static const char *
19594 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19596 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19597 ? reader
->cu
->header
.addr_size
: 0;
19598 return read_str_index (reader
->cu
,
19599 &reader
->dwo_file
->sections
.str
,
19600 &reader
->dwo_file
->sections
.str_offsets
,
19601 str_offsets_base
, str_index
);
19604 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19606 static const char *
19607 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19609 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19610 const char *objf_name
= objfile_name (objfile
);
19611 static const char form_name
[] = "DW_FORM_GNU_str_index";
19612 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19614 if (!cu
->str_offsets_base
.has_value ())
19615 error (_("%s used in Fission stub without %s"
19616 " in CU at offset 0x%lx [in module %s]"),
19617 form_name
, str_offsets_attr_name
,
19618 (long) cu
->header
.offset_size
, objf_name
);
19620 return read_str_index (cu
,
19621 &cu
->per_objfile
->per_bfd
->str
,
19622 &cu
->per_objfile
->per_bfd
->str_offsets
,
19623 *cu
->str_offsets_base
, str_index
);
19626 /* Return the length of an LEB128 number in BUF. */
19629 leb128_size (const gdb_byte
*buf
)
19631 const gdb_byte
*begin
= buf
;
19637 if ((byte
& 128) == 0)
19638 return buf
- begin
;
19643 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19652 cu
->language
= language_c
;
19655 case DW_LANG_C_plus_plus
:
19656 case DW_LANG_C_plus_plus_11
:
19657 case DW_LANG_C_plus_plus_14
:
19658 cu
->language
= language_cplus
;
19661 cu
->language
= language_d
;
19663 case DW_LANG_Fortran77
:
19664 case DW_LANG_Fortran90
:
19665 case DW_LANG_Fortran95
:
19666 case DW_LANG_Fortran03
:
19667 case DW_LANG_Fortran08
:
19668 cu
->language
= language_fortran
;
19671 cu
->language
= language_go
;
19673 case DW_LANG_Mips_Assembler
:
19674 cu
->language
= language_asm
;
19676 case DW_LANG_Ada83
:
19677 case DW_LANG_Ada95
:
19678 cu
->language
= language_ada
;
19680 case DW_LANG_Modula2
:
19681 cu
->language
= language_m2
;
19683 case DW_LANG_Pascal83
:
19684 cu
->language
= language_pascal
;
19687 cu
->language
= language_objc
;
19690 case DW_LANG_Rust_old
:
19691 cu
->language
= language_rust
;
19693 case DW_LANG_Cobol74
:
19694 case DW_LANG_Cobol85
:
19696 cu
->language
= language_minimal
;
19699 cu
->language_defn
= language_def (cu
->language
);
19702 /* Return the named attribute or NULL if not there. */
19704 static struct attribute
*
19705 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19710 struct attribute
*spec
= NULL
;
19712 for (i
= 0; i
< die
->num_attrs
; ++i
)
19714 if (die
->attrs
[i
].name
== name
)
19715 return &die
->attrs
[i
];
19716 if (die
->attrs
[i
].name
== DW_AT_specification
19717 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19718 spec
= &die
->attrs
[i
];
19724 die
= follow_die_ref (die
, spec
, &cu
);
19730 /* Return the string associated with a string-typed attribute, or NULL if it
19731 is either not found or is of an incorrect type. */
19733 static const char *
19734 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19736 struct attribute
*attr
;
19737 const char *str
= NULL
;
19739 attr
= dwarf2_attr (die
, name
, cu
);
19743 str
= attr
->value_as_string ();
19744 if (str
== nullptr)
19745 complaint (_("string type expected for attribute %s for "
19746 "DIE at %s in module %s"),
19747 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19748 objfile_name (cu
->per_objfile
->objfile
));
19754 /* Return the dwo name or NULL if not present. If present, it is in either
19755 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19756 static const char *
19757 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19759 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19760 if (dwo_name
== nullptr)
19761 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19765 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19766 and holds a non-zero value. This function should only be used for
19767 DW_FORM_flag or DW_FORM_flag_present attributes. */
19770 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19772 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19774 return (attr
&& DW_UNSND (attr
));
19778 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19780 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19781 which value is non-zero. However, we have to be careful with
19782 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19783 (via dwarf2_flag_true_p) follows this attribute. So we may
19784 end up accidently finding a declaration attribute that belongs
19785 to a different DIE referenced by the specification attribute,
19786 even though the given DIE does not have a declaration attribute. */
19787 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19788 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19791 /* Return the die giving the specification for DIE, if there is
19792 one. *SPEC_CU is the CU containing DIE on input, and the CU
19793 containing the return value on output. If there is no
19794 specification, but there is an abstract origin, that is
19797 static struct die_info
*
19798 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19800 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19803 if (spec_attr
== NULL
)
19804 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19806 if (spec_attr
== NULL
)
19809 return follow_die_ref (die
, spec_attr
, spec_cu
);
19812 /* Stub for free_line_header to match void * callback types. */
19815 free_line_header_voidp (void *arg
)
19817 struct line_header
*lh
= (struct line_header
*) arg
;
19822 /* A convenience function to find the proper .debug_line section for a CU. */
19824 static struct dwarf2_section_info
*
19825 get_debug_line_section (struct dwarf2_cu
*cu
)
19827 struct dwarf2_section_info
*section
;
19828 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19830 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19832 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19833 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19834 else if (cu
->per_cu
->is_dwz
)
19836 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
->per_bfd
);
19838 section
= &dwz
->line
;
19841 section
= &dwarf2_per_objfile
->per_bfd
->line
;
19846 /* Read the statement program header starting at OFFSET in
19847 .debug_line, or .debug_line.dwo. Return a pointer
19848 to a struct line_header, allocated using xmalloc.
19849 Returns NULL if there is a problem reading the header, e.g., if it
19850 has a version we don't understand.
19852 NOTE: the strings in the include directory and file name tables of
19853 the returned object point into the dwarf line section buffer,
19854 and must not be freed. */
19856 static line_header_up
19857 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19859 struct dwarf2_section_info
*section
;
19860 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19862 section
= get_debug_line_section (cu
);
19863 section
->read (dwarf2_per_objfile
->objfile
);
19864 if (section
->buffer
== NULL
)
19866 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19867 complaint (_("missing .debug_line.dwo section"));
19869 complaint (_("missing .debug_line section"));
19873 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19874 dwarf2_per_objfile
, section
,
19878 /* Subroutine of dwarf_decode_lines to simplify it.
19879 Return the file name of the psymtab for the given file_entry.
19880 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19881 If space for the result is malloc'd, *NAME_HOLDER will be set.
19882 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19884 static const char *
19885 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19886 const dwarf2_psymtab
*pst
,
19887 const char *comp_dir
,
19888 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19890 const char *include_name
= fe
.name
;
19891 const char *include_name_to_compare
= include_name
;
19892 const char *pst_filename
;
19895 const char *dir_name
= fe
.include_dir (lh
);
19897 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19898 if (!IS_ABSOLUTE_PATH (include_name
)
19899 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19901 /* Avoid creating a duplicate psymtab for PST.
19902 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19903 Before we do the comparison, however, we need to account
19904 for DIR_NAME and COMP_DIR.
19905 First prepend dir_name (if non-NULL). If we still don't
19906 have an absolute path prepend comp_dir (if non-NULL).
19907 However, the directory we record in the include-file's
19908 psymtab does not contain COMP_DIR (to match the
19909 corresponding symtab(s)).
19914 bash$ gcc -g ./hello.c
19915 include_name = "hello.c"
19917 DW_AT_comp_dir = comp_dir = "/tmp"
19918 DW_AT_name = "./hello.c"
19922 if (dir_name
!= NULL
)
19924 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19925 include_name
, (char *) NULL
));
19926 include_name
= name_holder
->get ();
19927 include_name_to_compare
= include_name
;
19929 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19931 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19932 include_name
, (char *) NULL
));
19933 include_name_to_compare
= hold_compare
.get ();
19937 pst_filename
= pst
->filename
;
19938 gdb::unique_xmalloc_ptr
<char> copied_name
;
19939 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19941 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19942 pst_filename
, (char *) NULL
));
19943 pst_filename
= copied_name
.get ();
19946 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19950 return include_name
;
19953 /* State machine to track the state of the line number program. */
19955 class lnp_state_machine
19958 /* Initialize a machine state for the start of a line number
19960 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19961 bool record_lines_p
);
19963 file_entry
*current_file ()
19965 /* lh->file_names is 0-based, but the file name numbers in the
19966 statement program are 1-based. */
19967 return m_line_header
->file_name_at (m_file
);
19970 /* Record the line in the state machine. END_SEQUENCE is true if
19971 we're processing the end of a sequence. */
19972 void record_line (bool end_sequence
);
19974 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19975 nop-out rest of the lines in this sequence. */
19976 void check_line_address (struct dwarf2_cu
*cu
,
19977 const gdb_byte
*line_ptr
,
19978 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19980 void handle_set_discriminator (unsigned int discriminator
)
19982 m_discriminator
= discriminator
;
19983 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19986 /* Handle DW_LNE_set_address. */
19987 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19990 address
+= baseaddr
;
19991 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19994 /* Handle DW_LNS_advance_pc. */
19995 void handle_advance_pc (CORE_ADDR adjust
);
19997 /* Handle a special opcode. */
19998 void handle_special_opcode (unsigned char op_code
);
20000 /* Handle DW_LNS_advance_line. */
20001 void handle_advance_line (int line_delta
)
20003 advance_line (line_delta
);
20006 /* Handle DW_LNS_set_file. */
20007 void handle_set_file (file_name_index file
);
20009 /* Handle DW_LNS_negate_stmt. */
20010 void handle_negate_stmt ()
20012 m_is_stmt
= !m_is_stmt
;
20015 /* Handle DW_LNS_const_add_pc. */
20016 void handle_const_add_pc ();
20018 /* Handle DW_LNS_fixed_advance_pc. */
20019 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20021 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20025 /* Handle DW_LNS_copy. */
20026 void handle_copy ()
20028 record_line (false);
20029 m_discriminator
= 0;
20032 /* Handle DW_LNE_end_sequence. */
20033 void handle_end_sequence ()
20035 m_currently_recording_lines
= true;
20039 /* Advance the line by LINE_DELTA. */
20040 void advance_line (int line_delta
)
20042 m_line
+= line_delta
;
20044 if (line_delta
!= 0)
20045 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20048 struct dwarf2_cu
*m_cu
;
20050 gdbarch
*m_gdbarch
;
20052 /* True if we're recording lines.
20053 Otherwise we're building partial symtabs and are just interested in
20054 finding include files mentioned by the line number program. */
20055 bool m_record_lines_p
;
20057 /* The line number header. */
20058 line_header
*m_line_header
;
20060 /* These are part of the standard DWARF line number state machine,
20061 and initialized according to the DWARF spec. */
20063 unsigned char m_op_index
= 0;
20064 /* The line table index of the current file. */
20065 file_name_index m_file
= 1;
20066 unsigned int m_line
= 1;
20068 /* These are initialized in the constructor. */
20070 CORE_ADDR m_address
;
20072 unsigned int m_discriminator
;
20074 /* Additional bits of state we need to track. */
20076 /* The last file that we called dwarf2_start_subfile for.
20077 This is only used for TLLs. */
20078 unsigned int m_last_file
= 0;
20079 /* The last file a line number was recorded for. */
20080 struct subfile
*m_last_subfile
= NULL
;
20082 /* When true, record the lines we decode. */
20083 bool m_currently_recording_lines
= false;
20085 /* The last line number that was recorded, used to coalesce
20086 consecutive entries for the same line. This can happen, for
20087 example, when discriminators are present. PR 17276. */
20088 unsigned int m_last_line
= 0;
20089 bool m_line_has_non_zero_discriminator
= false;
20093 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20095 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20096 / m_line_header
->maximum_ops_per_instruction
)
20097 * m_line_header
->minimum_instruction_length
);
20098 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20099 m_op_index
= ((m_op_index
+ adjust
)
20100 % m_line_header
->maximum_ops_per_instruction
);
20104 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20106 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20107 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20108 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20109 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20110 / m_line_header
->maximum_ops_per_instruction
)
20111 * 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
+ adj_opcode_d
)
20114 % m_line_header
->maximum_ops_per_instruction
);
20116 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20117 advance_line (line_delta
);
20118 record_line (false);
20119 m_discriminator
= 0;
20123 lnp_state_machine::handle_set_file (file_name_index file
)
20127 const file_entry
*fe
= current_file ();
20129 dwarf2_debug_line_missing_file_complaint ();
20130 else if (m_record_lines_p
)
20132 const char *dir
= fe
->include_dir (m_line_header
);
20134 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20135 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20136 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20141 lnp_state_machine::handle_const_add_pc ()
20144 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20147 = (((m_op_index
+ adjust
)
20148 / m_line_header
->maximum_ops_per_instruction
)
20149 * m_line_header
->minimum_instruction_length
);
20151 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20152 m_op_index
= ((m_op_index
+ adjust
)
20153 % m_line_header
->maximum_ops_per_instruction
);
20156 /* Return non-zero if we should add LINE to the line number table.
20157 LINE is the line to add, LAST_LINE is the last line that was added,
20158 LAST_SUBFILE is the subfile for LAST_LINE.
20159 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20160 had a non-zero discriminator.
20162 We have to be careful in the presence of discriminators.
20163 E.g., for this line:
20165 for (i = 0; i < 100000; i++);
20167 clang can emit four line number entries for that one line,
20168 each with a different discriminator.
20169 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20171 However, we want gdb to coalesce all four entries into one.
20172 Otherwise the user could stepi into the middle of the line and
20173 gdb would get confused about whether the pc really was in the
20174 middle of the line.
20176 Things are further complicated by the fact that two consecutive
20177 line number entries for the same line is a heuristic used by gcc
20178 to denote the end of the prologue. So we can't just discard duplicate
20179 entries, we have to be selective about it. The heuristic we use is
20180 that we only collapse consecutive entries for the same line if at least
20181 one of those entries has a non-zero discriminator. PR 17276.
20183 Note: Addresses in the line number state machine can never go backwards
20184 within one sequence, thus this coalescing is ok. */
20187 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20188 unsigned int line
, unsigned int last_line
,
20189 int line_has_non_zero_discriminator
,
20190 struct subfile
*last_subfile
)
20192 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20194 if (line
!= last_line
)
20196 /* Same line for the same file that we've seen already.
20197 As a last check, for pr 17276, only record the line if the line
20198 has never had a non-zero discriminator. */
20199 if (!line_has_non_zero_discriminator
)
20204 /* Use the CU's builder to record line number LINE beginning at
20205 address ADDRESS in the line table of subfile SUBFILE. */
20208 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20209 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20210 struct dwarf2_cu
*cu
)
20212 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20214 if (dwarf_line_debug
)
20216 fprintf_unfiltered (gdb_stdlog
,
20217 "Recording line %u, file %s, address %s\n",
20218 line
, lbasename (subfile
->name
),
20219 paddress (gdbarch
, address
));
20223 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20226 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20227 Mark the end of a set of line number records.
20228 The arguments are the same as for dwarf_record_line_1.
20229 If SUBFILE is NULL the request is ignored. */
20232 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20233 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20235 if (subfile
== NULL
)
20238 if (dwarf_line_debug
)
20240 fprintf_unfiltered (gdb_stdlog
,
20241 "Finishing current line, file %s, address %s\n",
20242 lbasename (subfile
->name
),
20243 paddress (gdbarch
, address
));
20246 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20250 lnp_state_machine::record_line (bool end_sequence
)
20252 if (dwarf_line_debug
)
20254 fprintf_unfiltered (gdb_stdlog
,
20255 "Processing actual line %u: file %u,"
20256 " address %s, is_stmt %u, discrim %u%s\n",
20258 paddress (m_gdbarch
, m_address
),
20259 m_is_stmt
, m_discriminator
,
20260 (end_sequence
? "\t(end sequence)" : ""));
20263 file_entry
*fe
= current_file ();
20266 dwarf2_debug_line_missing_file_complaint ();
20267 /* For now we ignore lines not starting on an instruction boundary.
20268 But not when processing end_sequence for compatibility with the
20269 previous version of the code. */
20270 else if (m_op_index
== 0 || end_sequence
)
20272 fe
->included_p
= 1;
20273 if (m_record_lines_p
)
20275 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20278 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20279 m_currently_recording_lines
? m_cu
: nullptr);
20284 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20286 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20287 m_line_has_non_zero_discriminator
,
20290 buildsym_compunit
*builder
= m_cu
->get_builder ();
20291 dwarf_record_line_1 (m_gdbarch
,
20292 builder
->get_current_subfile (),
20293 m_line
, m_address
, is_stmt
,
20294 m_currently_recording_lines
? m_cu
: nullptr);
20296 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20297 m_last_line
= m_line
;
20303 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20304 line_header
*lh
, bool record_lines_p
)
20308 m_record_lines_p
= record_lines_p
;
20309 m_line_header
= lh
;
20311 m_currently_recording_lines
= true;
20313 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20314 was a line entry for it so that the backend has a chance to adjust it
20315 and also record it in case it needs it. This is currently used by MIPS
20316 code, cf. `mips_adjust_dwarf2_line'. */
20317 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20318 m_is_stmt
= lh
->default_is_stmt
;
20319 m_discriminator
= 0;
20323 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20324 const gdb_byte
*line_ptr
,
20325 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20327 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20328 the pc range of the CU. However, we restrict the test to only ADDRESS
20329 values of zero to preserve GDB's previous behaviour which is to handle
20330 the specific case of a function being GC'd by the linker. */
20332 if (address
== 0 && address
< unrelocated_lowpc
)
20334 /* This line table is for a function which has been
20335 GCd by the linker. Ignore it. PR gdb/12528 */
20337 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20338 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20340 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20341 line_offset
, objfile_name (objfile
));
20342 m_currently_recording_lines
= false;
20343 /* Note: m_currently_recording_lines is left as false until we see
20344 DW_LNE_end_sequence. */
20348 /* Subroutine of dwarf_decode_lines to simplify it.
20349 Process the line number information in LH.
20350 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20351 program in order to set included_p for every referenced header. */
20354 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20355 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20357 const gdb_byte
*line_ptr
, *extended_end
;
20358 const gdb_byte
*line_end
;
20359 unsigned int bytes_read
, extended_len
;
20360 unsigned char op_code
, extended_op
;
20361 CORE_ADDR baseaddr
;
20362 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20363 bfd
*abfd
= objfile
->obfd
;
20364 struct gdbarch
*gdbarch
= objfile
->arch ();
20365 /* True if we're recording line info (as opposed to building partial
20366 symtabs and just interested in finding include files mentioned by
20367 the line number program). */
20368 bool record_lines_p
= !decode_for_pst_p
;
20370 baseaddr
= objfile
->text_section_offset ();
20372 line_ptr
= lh
->statement_program_start
;
20373 line_end
= lh
->statement_program_end
;
20375 /* Read the statement sequences until there's nothing left. */
20376 while (line_ptr
< line_end
)
20378 /* The DWARF line number program state machine. Reset the state
20379 machine at the start of each sequence. */
20380 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20381 bool end_sequence
= false;
20383 if (record_lines_p
)
20385 /* Start a subfile for the current file of the state
20387 const file_entry
*fe
= state_machine
.current_file ();
20390 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20393 /* Decode the table. */
20394 while (line_ptr
< line_end
&& !end_sequence
)
20396 op_code
= read_1_byte (abfd
, line_ptr
);
20399 if (op_code
>= lh
->opcode_base
)
20401 /* Special opcode. */
20402 state_machine
.handle_special_opcode (op_code
);
20404 else switch (op_code
)
20406 case DW_LNS_extended_op
:
20407 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20409 line_ptr
+= bytes_read
;
20410 extended_end
= line_ptr
+ extended_len
;
20411 extended_op
= read_1_byte (abfd
, line_ptr
);
20413 switch (extended_op
)
20415 case DW_LNE_end_sequence
:
20416 state_machine
.handle_end_sequence ();
20417 end_sequence
= true;
20419 case DW_LNE_set_address
:
20422 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20423 line_ptr
+= bytes_read
;
20425 state_machine
.check_line_address (cu
, line_ptr
,
20426 lowpc
- baseaddr
, address
);
20427 state_machine
.handle_set_address (baseaddr
, address
);
20430 case DW_LNE_define_file
:
20432 const char *cur_file
;
20433 unsigned int mod_time
, length
;
20436 cur_file
= read_direct_string (abfd
, line_ptr
,
20438 line_ptr
+= bytes_read
;
20439 dindex
= (dir_index
)
20440 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20441 line_ptr
+= bytes_read
;
20443 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20444 line_ptr
+= bytes_read
;
20446 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20447 line_ptr
+= bytes_read
;
20448 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20451 case DW_LNE_set_discriminator
:
20453 /* The discriminator is not interesting to the
20454 debugger; just ignore it. We still need to
20455 check its value though:
20456 if there are consecutive entries for the same
20457 (non-prologue) line we want to coalesce them.
20460 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20461 line_ptr
+= bytes_read
;
20463 state_machine
.handle_set_discriminator (discr
);
20467 complaint (_("mangled .debug_line section"));
20470 /* Make sure that we parsed the extended op correctly. If e.g.
20471 we expected a different address size than the producer used,
20472 we may have read the wrong number of bytes. */
20473 if (line_ptr
!= extended_end
)
20475 complaint (_("mangled .debug_line section"));
20480 state_machine
.handle_copy ();
20482 case DW_LNS_advance_pc
:
20485 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20486 line_ptr
+= bytes_read
;
20488 state_machine
.handle_advance_pc (adjust
);
20491 case DW_LNS_advance_line
:
20494 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20495 line_ptr
+= bytes_read
;
20497 state_machine
.handle_advance_line (line_delta
);
20500 case DW_LNS_set_file
:
20502 file_name_index file
20503 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20505 line_ptr
+= bytes_read
;
20507 state_machine
.handle_set_file (file
);
20510 case DW_LNS_set_column
:
20511 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20512 line_ptr
+= bytes_read
;
20514 case DW_LNS_negate_stmt
:
20515 state_machine
.handle_negate_stmt ();
20517 case DW_LNS_set_basic_block
:
20519 /* Add to the address register of the state machine the
20520 address increment value corresponding to special opcode
20521 255. I.e., this value is scaled by the minimum
20522 instruction length since special opcode 255 would have
20523 scaled the increment. */
20524 case DW_LNS_const_add_pc
:
20525 state_machine
.handle_const_add_pc ();
20527 case DW_LNS_fixed_advance_pc
:
20529 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20532 state_machine
.handle_fixed_advance_pc (addr_adj
);
20537 /* Unknown standard opcode, ignore it. */
20540 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20542 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20543 line_ptr
+= bytes_read
;
20550 dwarf2_debug_line_missing_end_sequence_complaint ();
20552 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20553 in which case we still finish recording the last line). */
20554 state_machine
.record_line (true);
20558 /* Decode the Line Number Program (LNP) for the given line_header
20559 structure and CU. The actual information extracted and the type
20560 of structures created from the LNP depends on the value of PST.
20562 1. If PST is NULL, then this procedure uses the data from the program
20563 to create all necessary symbol tables, and their linetables.
20565 2. If PST is not NULL, this procedure reads the program to determine
20566 the list of files included by the unit represented by PST, and
20567 builds all the associated partial symbol tables.
20569 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20570 It is used for relative paths in the line table.
20571 NOTE: When processing partial symtabs (pst != NULL),
20572 comp_dir == pst->dirname.
20574 NOTE: It is important that psymtabs have the same file name (via strcmp)
20575 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20576 symtab we don't use it in the name of the psymtabs we create.
20577 E.g. expand_line_sal requires this when finding psymtabs to expand.
20578 A good testcase for this is mb-inline.exp.
20580 LOWPC is the lowest address in CU (or 0 if not known).
20582 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20583 for its PC<->lines mapping information. Otherwise only the filename
20584 table is read in. */
20587 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20588 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20589 CORE_ADDR lowpc
, int decode_mapping
)
20591 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20592 const int decode_for_pst_p
= (pst
!= NULL
);
20594 if (decode_mapping
)
20595 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20597 if (decode_for_pst_p
)
20599 /* Now that we're done scanning the Line Header Program, we can
20600 create the psymtab of each included file. */
20601 for (auto &file_entry
: lh
->file_names ())
20602 if (file_entry
.included_p
== 1)
20604 gdb::unique_xmalloc_ptr
<char> name_holder
;
20605 const char *include_name
=
20606 psymtab_include_file_name (lh
, file_entry
, pst
,
20607 comp_dir
, &name_holder
);
20608 if (include_name
!= NULL
)
20609 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20614 /* Make sure a symtab is created for every file, even files
20615 which contain only variables (i.e. no code with associated
20617 buildsym_compunit
*builder
= cu
->get_builder ();
20618 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20620 for (auto &fe
: lh
->file_names ())
20622 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20623 if (builder
->get_current_subfile ()->symtab
== NULL
)
20625 builder
->get_current_subfile ()->symtab
20626 = allocate_symtab (cust
,
20627 builder
->get_current_subfile ()->name
);
20629 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20634 /* Start a subfile for DWARF. FILENAME is the name of the file and
20635 DIRNAME the name of the source directory which contains FILENAME
20636 or NULL if not known.
20637 This routine tries to keep line numbers from identical absolute and
20638 relative file names in a common subfile.
20640 Using the `list' example from the GDB testsuite, which resides in
20641 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20642 of /srcdir/list0.c yields the following debugging information for list0.c:
20644 DW_AT_name: /srcdir/list0.c
20645 DW_AT_comp_dir: /compdir
20646 files.files[0].name: list0.h
20647 files.files[0].dir: /srcdir
20648 files.files[1].name: list0.c
20649 files.files[1].dir: /srcdir
20651 The line number information for list0.c has to end up in a single
20652 subfile, so that `break /srcdir/list0.c:1' works as expected.
20653 start_subfile will ensure that this happens provided that we pass the
20654 concatenation of files.files[1].dir and files.files[1].name as the
20658 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20659 const char *dirname
)
20661 gdb::unique_xmalloc_ptr
<char> copy
;
20663 /* In order not to lose the line information directory,
20664 we concatenate it to the filename when it makes sense.
20665 Note that the Dwarf3 standard says (speaking of filenames in line
20666 information): ``The directory index is ignored for file names
20667 that represent full path names''. Thus ignoring dirname in the
20668 `else' branch below isn't an issue. */
20670 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20672 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20673 filename
= copy
.get ();
20676 cu
->get_builder ()->start_subfile (filename
);
20679 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20680 buildsym_compunit constructor. */
20682 struct compunit_symtab
*
20683 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20686 gdb_assert (m_builder
== nullptr);
20688 m_builder
.reset (new struct buildsym_compunit
20689 (this->per_objfile
->objfile
,
20690 name
, comp_dir
, language
, low_pc
));
20692 list_in_scope
= get_builder ()->get_file_symbols ();
20694 get_builder ()->record_debugformat ("DWARF 2");
20695 get_builder ()->record_producer (producer
);
20697 processing_has_namespace_info
= false;
20699 return get_builder ()->get_compunit_symtab ();
20703 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20704 struct dwarf2_cu
*cu
)
20706 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20707 struct comp_unit_head
*cu_header
= &cu
->header
;
20709 /* NOTE drow/2003-01-30: There used to be a comment and some special
20710 code here to turn a symbol with DW_AT_external and a
20711 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20712 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20713 with some versions of binutils) where shared libraries could have
20714 relocations against symbols in their debug information - the
20715 minimal symbol would have the right address, but the debug info
20716 would not. It's no longer necessary, because we will explicitly
20717 apply relocations when we read in the debug information now. */
20719 /* A DW_AT_location attribute with no contents indicates that a
20720 variable has been optimized away. */
20721 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20723 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20727 /* Handle one degenerate form of location expression specially, to
20728 preserve GDB's previous behavior when section offsets are
20729 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20730 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20732 if (attr
->form_is_block ()
20733 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20734 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20735 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20736 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20737 && (DW_BLOCK (attr
)->size
20738 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20740 unsigned int dummy
;
20742 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20743 SET_SYMBOL_VALUE_ADDRESS
20744 (sym
, cu
->header
.read_address (objfile
->obfd
,
20745 DW_BLOCK (attr
)->data
+ 1,
20748 SET_SYMBOL_VALUE_ADDRESS
20749 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20751 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20752 fixup_symbol_section (sym
, objfile
);
20753 SET_SYMBOL_VALUE_ADDRESS
20755 SYMBOL_VALUE_ADDRESS (sym
)
20756 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20760 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20761 expression evaluator, and use LOC_COMPUTED only when necessary
20762 (i.e. when the value of a register or memory location is
20763 referenced, or a thread-local block, etc.). Then again, it might
20764 not be worthwhile. I'm assuming that it isn't unless performance
20765 or memory numbers show me otherwise. */
20767 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20769 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20770 cu
->has_loclist
= true;
20773 /* Given a pointer to a DWARF information entry, figure out if we need
20774 to make a symbol table entry for it, and if so, create a new entry
20775 and return a pointer to it.
20776 If TYPE is NULL, determine symbol type from the die, otherwise
20777 used the passed type.
20778 If SPACE is not NULL, use it to hold the new symbol. If it is
20779 NULL, allocate a new symbol on the objfile's obstack. */
20781 static struct symbol
*
20782 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20783 struct symbol
*space
)
20785 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20786 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20787 struct gdbarch
*gdbarch
= objfile
->arch ();
20788 struct symbol
*sym
= NULL
;
20790 struct attribute
*attr
= NULL
;
20791 struct attribute
*attr2
= NULL
;
20792 CORE_ADDR baseaddr
;
20793 struct pending
**list_to_add
= NULL
;
20795 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20797 baseaddr
= objfile
->text_section_offset ();
20799 name
= dwarf2_name (die
, cu
);
20802 int suppress_add
= 0;
20807 sym
= new (&objfile
->objfile_obstack
) symbol
;
20808 OBJSTAT (objfile
, n_syms
++);
20810 /* Cache this symbol's name and the name's demangled form (if any). */
20811 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20812 /* Fortran does not have mangling standard and the mangling does differ
20813 between gfortran, iFort etc. */
20814 const char *physname
20815 = (cu
->language
== language_fortran
20816 ? dwarf2_full_name (name
, die
, cu
)
20817 : dwarf2_physname (name
, die
, cu
));
20818 const char *linkagename
= dw2_linkage_name (die
, cu
);
20820 if (linkagename
== nullptr || cu
->language
== language_ada
)
20821 sym
->set_linkage_name (physname
);
20824 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20825 sym
->set_linkage_name (linkagename
);
20828 /* Default assumptions.
20829 Use the passed type or decode it from the die. */
20830 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20831 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20833 SYMBOL_TYPE (sym
) = type
;
20835 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20836 attr
= dwarf2_attr (die
,
20837 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20839 if (attr
!= nullptr)
20841 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20844 attr
= dwarf2_attr (die
,
20845 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20847 if (attr
!= nullptr)
20849 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20850 struct file_entry
*fe
;
20852 if (cu
->line_header
!= NULL
)
20853 fe
= cu
->line_header
->file_name_at (file_index
);
20858 complaint (_("file index out of range"));
20860 symbol_set_symtab (sym
, fe
->symtab
);
20866 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20867 if (attr
!= nullptr)
20871 addr
= attr
->value_as_address ();
20872 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20873 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20875 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20876 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20877 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20878 add_symbol_to_list (sym
, cu
->list_in_scope
);
20880 case DW_TAG_subprogram
:
20881 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20883 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20884 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20885 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20886 || cu
->language
== language_ada
20887 || cu
->language
== language_fortran
)
20889 /* Subprograms marked external are stored as a global symbol.
20890 Ada and Fortran subprograms, whether marked external or
20891 not, are always stored as a global symbol, because we want
20892 to be able to access them globally. For instance, we want
20893 to be able to break on a nested subprogram without having
20894 to specify the context. */
20895 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20899 list_to_add
= cu
->list_in_scope
;
20902 case DW_TAG_inlined_subroutine
:
20903 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20905 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20906 SYMBOL_INLINED (sym
) = 1;
20907 list_to_add
= cu
->list_in_scope
;
20909 case DW_TAG_template_value_param
:
20911 /* Fall through. */
20912 case DW_TAG_constant
:
20913 case DW_TAG_variable
:
20914 case DW_TAG_member
:
20915 /* Compilation with minimal debug info may result in
20916 variables with missing type entries. Change the
20917 misleading `void' type to something sensible. */
20918 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20919 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20921 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20922 /* In the case of DW_TAG_member, we should only be called for
20923 static const members. */
20924 if (die
->tag
== DW_TAG_member
)
20926 /* dwarf2_add_field uses die_is_declaration,
20927 so we do the same. */
20928 gdb_assert (die_is_declaration (die
, cu
));
20931 if (attr
!= nullptr)
20933 dwarf2_const_value (attr
, sym
, cu
);
20934 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20937 if (attr2
&& (DW_UNSND (attr2
) != 0))
20938 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20940 list_to_add
= cu
->list_in_scope
;
20944 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20945 if (attr
!= nullptr)
20947 var_decode_location (attr
, sym
, cu
);
20948 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20950 /* Fortran explicitly imports any global symbols to the local
20951 scope by DW_TAG_common_block. */
20952 if (cu
->language
== language_fortran
&& die
->parent
20953 && die
->parent
->tag
== DW_TAG_common_block
)
20956 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20957 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20958 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
20960 /* When a static variable is eliminated by the linker,
20961 the corresponding debug information is not stripped
20962 out, but the variable address is set to null;
20963 do not add such variables into symbol table. */
20965 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20967 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20968 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20969 && dwarf2_per_objfile
->per_bfd
->can_copy
)
20971 /* A global static variable might be subject to
20972 copy relocation. We first check for a local
20973 minsym, though, because maybe the symbol was
20974 marked hidden, in which case this would not
20976 bound_minimal_symbol found
20977 = (lookup_minimal_symbol_linkage
20978 (sym
->linkage_name (), objfile
));
20979 if (found
.minsym
!= nullptr)
20980 sym
->maybe_copied
= 1;
20983 /* A variable with DW_AT_external is never static,
20984 but it may be block-scoped. */
20986 = ((cu
->list_in_scope
20987 == cu
->get_builder ()->get_file_symbols ())
20988 ? cu
->get_builder ()->get_global_symbols ()
20989 : cu
->list_in_scope
);
20992 list_to_add
= cu
->list_in_scope
;
20996 /* We do not know the address of this symbol.
20997 If it is an external symbol and we have type information
20998 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20999 The address of the variable will then be determined from
21000 the minimal symbol table whenever the variable is
21002 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21004 /* Fortran explicitly imports any global symbols to the local
21005 scope by DW_TAG_common_block. */
21006 if (cu
->language
== language_fortran
&& die
->parent
21007 && die
->parent
->tag
== DW_TAG_common_block
)
21009 /* SYMBOL_CLASS doesn't matter here because
21010 read_common_block is going to reset it. */
21012 list_to_add
= cu
->list_in_scope
;
21014 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21015 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21017 /* A variable with DW_AT_external is never static, but it
21018 may be block-scoped. */
21020 = ((cu
->list_in_scope
21021 == cu
->get_builder ()->get_file_symbols ())
21022 ? cu
->get_builder ()->get_global_symbols ()
21023 : cu
->list_in_scope
);
21025 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21027 else if (!die_is_declaration (die
, cu
))
21029 /* Use the default LOC_OPTIMIZED_OUT class. */
21030 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21032 list_to_add
= cu
->list_in_scope
;
21036 case DW_TAG_formal_parameter
:
21038 /* If we are inside a function, mark this as an argument. If
21039 not, we might be looking at an argument to an inlined function
21040 when we do not have enough information to show inlined frames;
21041 pretend it's a local variable in that case so that the user can
21043 struct context_stack
*curr
21044 = cu
->get_builder ()->get_current_context_stack ();
21045 if (curr
!= nullptr && curr
->name
!= nullptr)
21046 SYMBOL_IS_ARGUMENT (sym
) = 1;
21047 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21048 if (attr
!= nullptr)
21050 var_decode_location (attr
, sym
, cu
);
21052 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21053 if (attr
!= nullptr)
21055 dwarf2_const_value (attr
, sym
, cu
);
21058 list_to_add
= cu
->list_in_scope
;
21061 case DW_TAG_unspecified_parameters
:
21062 /* From varargs functions; gdb doesn't seem to have any
21063 interest in this information, so just ignore it for now.
21066 case DW_TAG_template_type_param
:
21068 /* Fall through. */
21069 case DW_TAG_class_type
:
21070 case DW_TAG_interface_type
:
21071 case DW_TAG_structure_type
:
21072 case DW_TAG_union_type
:
21073 case DW_TAG_set_type
:
21074 case DW_TAG_enumeration_type
:
21075 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21076 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21079 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21080 really ever be static objects: otherwise, if you try
21081 to, say, break of a class's method and you're in a file
21082 which doesn't mention that class, it won't work unless
21083 the check for all static symbols in lookup_symbol_aux
21084 saves you. See the OtherFileClass tests in
21085 gdb.c++/namespace.exp. */
21089 buildsym_compunit
*builder
= cu
->get_builder ();
21091 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21092 && cu
->language
== language_cplus
21093 ? builder
->get_global_symbols ()
21094 : cu
->list_in_scope
);
21096 /* The semantics of C++ state that "struct foo {
21097 ... }" also defines a typedef for "foo". */
21098 if (cu
->language
== language_cplus
21099 || cu
->language
== language_ada
21100 || cu
->language
== language_d
21101 || cu
->language
== language_rust
)
21103 /* The symbol's name is already allocated along
21104 with this objfile, so we don't need to
21105 duplicate it for the type. */
21106 if (SYMBOL_TYPE (sym
)->name () == 0)
21107 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21112 case DW_TAG_typedef
:
21113 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21114 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21115 list_to_add
= cu
->list_in_scope
;
21117 case DW_TAG_base_type
:
21118 case DW_TAG_subrange_type
:
21119 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21120 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21121 list_to_add
= cu
->list_in_scope
;
21123 case DW_TAG_enumerator
:
21124 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21125 if (attr
!= nullptr)
21127 dwarf2_const_value (attr
, sym
, cu
);
21130 /* NOTE: carlton/2003-11-10: See comment above in the
21131 DW_TAG_class_type, etc. block. */
21134 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21135 && cu
->language
== language_cplus
21136 ? cu
->get_builder ()->get_global_symbols ()
21137 : cu
->list_in_scope
);
21140 case DW_TAG_imported_declaration
:
21141 case DW_TAG_namespace
:
21142 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21143 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21145 case DW_TAG_module
:
21146 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21147 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21148 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21150 case DW_TAG_common_block
:
21151 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21152 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21153 add_symbol_to_list (sym
, cu
->list_in_scope
);
21156 /* Not a tag we recognize. Hopefully we aren't processing
21157 trash data, but since we must specifically ignore things
21158 we don't recognize, there is nothing else we should do at
21160 complaint (_("unsupported tag: '%s'"),
21161 dwarf_tag_name (die
->tag
));
21167 sym
->hash_next
= objfile
->template_symbols
;
21168 objfile
->template_symbols
= sym
;
21169 list_to_add
= NULL
;
21172 if (list_to_add
!= NULL
)
21173 add_symbol_to_list (sym
, list_to_add
);
21175 /* For the benefit of old versions of GCC, check for anonymous
21176 namespaces based on the demangled name. */
21177 if (!cu
->processing_has_namespace_info
21178 && cu
->language
== language_cplus
)
21179 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21184 /* Given an attr with a DW_FORM_dataN value in host byte order,
21185 zero-extend it as appropriate for the symbol's type. The DWARF
21186 standard (v4) is not entirely clear about the meaning of using
21187 DW_FORM_dataN for a constant with a signed type, where the type is
21188 wider than the data. The conclusion of a discussion on the DWARF
21189 list was that this is unspecified. We choose to always zero-extend
21190 because that is the interpretation long in use by GCC. */
21193 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21194 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21196 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21197 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21198 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21199 LONGEST l
= DW_UNSND (attr
);
21201 if (bits
< sizeof (*value
) * 8)
21203 l
&= ((LONGEST
) 1 << bits
) - 1;
21206 else if (bits
== sizeof (*value
) * 8)
21210 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21211 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21218 /* Read a constant value from an attribute. Either set *VALUE, or if
21219 the value does not fit in *VALUE, set *BYTES - either already
21220 allocated on the objfile obstack, or newly allocated on OBSTACK,
21221 or, set *BATON, if we translated the constant to a location
21225 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21226 const char *name
, struct obstack
*obstack
,
21227 struct dwarf2_cu
*cu
,
21228 LONGEST
*value
, const gdb_byte
**bytes
,
21229 struct dwarf2_locexpr_baton
**baton
)
21231 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21232 struct objfile
*objfile
= per_objfile
->objfile
;
21233 struct comp_unit_head
*cu_header
= &cu
->header
;
21234 struct dwarf_block
*blk
;
21235 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21236 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21242 switch (attr
->form
)
21245 case DW_FORM_addrx
:
21246 case DW_FORM_GNU_addr_index
:
21250 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21251 dwarf2_const_value_length_mismatch_complaint (name
,
21252 cu_header
->addr_size
,
21253 TYPE_LENGTH (type
));
21254 /* Symbols of this form are reasonably rare, so we just
21255 piggyback on the existing location code rather than writing
21256 a new implementation of symbol_computed_ops. */
21257 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21258 (*baton
)->per_objfile
= per_objfile
;
21259 (*baton
)->per_cu
= cu
->per_cu
;
21260 gdb_assert ((*baton
)->per_cu
);
21262 (*baton
)->size
= 2 + cu_header
->addr_size
;
21263 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21264 (*baton
)->data
= data
;
21266 data
[0] = DW_OP_addr
;
21267 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21268 byte_order
, DW_ADDR (attr
));
21269 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21272 case DW_FORM_string
:
21275 case DW_FORM_GNU_str_index
:
21276 case DW_FORM_GNU_strp_alt
:
21277 /* DW_STRING is already allocated on the objfile obstack, point
21279 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21281 case DW_FORM_block1
:
21282 case DW_FORM_block2
:
21283 case DW_FORM_block4
:
21284 case DW_FORM_block
:
21285 case DW_FORM_exprloc
:
21286 case DW_FORM_data16
:
21287 blk
= DW_BLOCK (attr
);
21288 if (TYPE_LENGTH (type
) != blk
->size
)
21289 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21290 TYPE_LENGTH (type
));
21291 *bytes
= blk
->data
;
21294 /* The DW_AT_const_value attributes are supposed to carry the
21295 symbol's value "represented as it would be on the target
21296 architecture." By the time we get here, it's already been
21297 converted to host endianness, so we just need to sign- or
21298 zero-extend it as appropriate. */
21299 case DW_FORM_data1
:
21300 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21302 case DW_FORM_data2
:
21303 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21305 case DW_FORM_data4
:
21306 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21308 case DW_FORM_data8
:
21309 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21312 case DW_FORM_sdata
:
21313 case DW_FORM_implicit_const
:
21314 *value
= DW_SND (attr
);
21317 case DW_FORM_udata
:
21318 *value
= DW_UNSND (attr
);
21322 complaint (_("unsupported const value attribute form: '%s'"),
21323 dwarf_form_name (attr
->form
));
21330 /* Copy constant value from an attribute to a symbol. */
21333 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21334 struct dwarf2_cu
*cu
)
21336 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21338 const gdb_byte
*bytes
;
21339 struct dwarf2_locexpr_baton
*baton
;
21341 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21342 sym
->print_name (),
21343 &objfile
->objfile_obstack
, cu
,
21344 &value
, &bytes
, &baton
);
21348 SYMBOL_LOCATION_BATON (sym
) = baton
;
21349 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21351 else if (bytes
!= NULL
)
21353 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21354 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21358 SYMBOL_VALUE (sym
) = value
;
21359 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21363 /* Return the type of the die in question using its DW_AT_type attribute. */
21365 static struct type
*
21366 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21368 struct attribute
*type_attr
;
21370 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21373 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21374 /* A missing DW_AT_type represents a void type. */
21375 return objfile_type (objfile
)->builtin_void
;
21378 return lookup_die_type (die
, type_attr
, cu
);
21381 /* True iff CU's producer generates GNAT Ada auxiliary information
21382 that allows to find parallel types through that information instead
21383 of having to do expensive parallel lookups by type name. */
21386 need_gnat_info (struct dwarf2_cu
*cu
)
21388 /* Assume that the Ada compiler was GNAT, which always produces
21389 the auxiliary information. */
21390 return (cu
->language
== language_ada
);
21393 /* Return the auxiliary type of the die in question using its
21394 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21395 attribute is not present. */
21397 static struct type
*
21398 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21400 struct attribute
*type_attr
;
21402 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21406 return lookup_die_type (die
, type_attr
, cu
);
21409 /* If DIE has a descriptive_type attribute, then set the TYPE's
21410 descriptive type accordingly. */
21413 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21414 struct dwarf2_cu
*cu
)
21416 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21418 if (descriptive_type
)
21420 ALLOCATE_GNAT_AUX_TYPE (type
);
21421 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21425 /* Return the containing type of the die in question using its
21426 DW_AT_containing_type attribute. */
21428 static struct type
*
21429 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21431 struct attribute
*type_attr
;
21432 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21434 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21436 error (_("Dwarf Error: Problem turning containing type into gdb type "
21437 "[in module %s]"), objfile_name (objfile
));
21439 return lookup_die_type (die
, type_attr
, cu
);
21442 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21444 static struct type
*
21445 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21447 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21448 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21451 std::string message
21452 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21453 objfile_name (objfile
),
21454 sect_offset_str (cu
->header
.sect_off
),
21455 sect_offset_str (die
->sect_off
));
21456 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21458 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21461 /* Look up the type of DIE in CU using its type attribute ATTR.
21462 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21463 DW_AT_containing_type.
21464 If there is no type substitute an error marker. */
21466 static struct type
*
21467 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21468 struct dwarf2_cu
*cu
)
21470 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21471 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21472 struct type
*this_type
;
21474 gdb_assert (attr
->name
== DW_AT_type
21475 || attr
->name
== DW_AT_GNAT_descriptive_type
21476 || attr
->name
== DW_AT_containing_type
);
21478 /* First see if we have it cached. */
21480 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21482 struct dwarf2_per_cu_data
*per_cu
;
21483 sect_offset sect_off
= attr
->get_ref_die_offset ();
21485 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21486 dwarf2_per_objfile
);
21487 this_type
= get_die_type_at_offset (sect_off
, per_cu
, dwarf2_per_objfile
);
21489 else if (attr
->form_is_ref ())
21491 sect_offset sect_off
= attr
->get_ref_die_offset ();
21493 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
,
21494 dwarf2_per_objfile
);
21496 else if (attr
->form
== DW_FORM_ref_sig8
)
21498 ULONGEST signature
= DW_SIGNATURE (attr
);
21500 return get_signatured_type (die
, signature
, cu
);
21504 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21505 " at %s [in module %s]"),
21506 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21507 objfile_name (objfile
));
21508 return build_error_marker_type (cu
, die
);
21511 /* If not cached we need to read it in. */
21513 if (this_type
== NULL
)
21515 struct die_info
*type_die
= NULL
;
21516 struct dwarf2_cu
*type_cu
= cu
;
21518 if (attr
->form_is_ref ())
21519 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21520 if (type_die
== NULL
)
21521 return build_error_marker_type (cu
, die
);
21522 /* If we find the type now, it's probably because the type came
21523 from an inter-CU reference and the type's CU got expanded before
21525 this_type
= read_type_die (type_die
, type_cu
);
21528 /* If we still don't have a type use an error marker. */
21530 if (this_type
== NULL
)
21531 return build_error_marker_type (cu
, die
);
21536 /* Return the type in DIE, CU.
21537 Returns NULL for invalid types.
21539 This first does a lookup in die_type_hash,
21540 and only reads the die in if necessary.
21542 NOTE: This can be called when reading in partial or full symbols. */
21544 static struct type
*
21545 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21547 struct type
*this_type
;
21549 this_type
= get_die_type (die
, cu
);
21553 return read_type_die_1 (die
, cu
);
21556 /* Read the type in DIE, CU.
21557 Returns NULL for invalid types. */
21559 static struct type
*
21560 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21562 struct type
*this_type
= NULL
;
21566 case DW_TAG_class_type
:
21567 case DW_TAG_interface_type
:
21568 case DW_TAG_structure_type
:
21569 case DW_TAG_union_type
:
21570 this_type
= read_structure_type (die
, cu
);
21572 case DW_TAG_enumeration_type
:
21573 this_type
= read_enumeration_type (die
, cu
);
21575 case DW_TAG_subprogram
:
21576 case DW_TAG_subroutine_type
:
21577 case DW_TAG_inlined_subroutine
:
21578 this_type
= read_subroutine_type (die
, cu
);
21580 case DW_TAG_array_type
:
21581 this_type
= read_array_type (die
, cu
);
21583 case DW_TAG_set_type
:
21584 this_type
= read_set_type (die
, cu
);
21586 case DW_TAG_pointer_type
:
21587 this_type
= read_tag_pointer_type (die
, cu
);
21589 case DW_TAG_ptr_to_member_type
:
21590 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21592 case DW_TAG_reference_type
:
21593 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21595 case DW_TAG_rvalue_reference_type
:
21596 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21598 case DW_TAG_const_type
:
21599 this_type
= read_tag_const_type (die
, cu
);
21601 case DW_TAG_volatile_type
:
21602 this_type
= read_tag_volatile_type (die
, cu
);
21604 case DW_TAG_restrict_type
:
21605 this_type
= read_tag_restrict_type (die
, cu
);
21607 case DW_TAG_string_type
:
21608 this_type
= read_tag_string_type (die
, cu
);
21610 case DW_TAG_typedef
:
21611 this_type
= read_typedef (die
, cu
);
21613 case DW_TAG_subrange_type
:
21614 this_type
= read_subrange_type (die
, cu
);
21616 case DW_TAG_base_type
:
21617 this_type
= read_base_type (die
, cu
);
21619 case DW_TAG_unspecified_type
:
21620 this_type
= read_unspecified_type (die
, cu
);
21622 case DW_TAG_namespace
:
21623 this_type
= read_namespace_type (die
, cu
);
21625 case DW_TAG_module
:
21626 this_type
= read_module_type (die
, cu
);
21628 case DW_TAG_atomic_type
:
21629 this_type
= read_tag_atomic_type (die
, cu
);
21632 complaint (_("unexpected tag in read_type_die: '%s'"),
21633 dwarf_tag_name (die
->tag
));
21640 /* See if we can figure out if the class lives in a namespace. We do
21641 this by looking for a member function; its demangled name will
21642 contain namespace info, if there is any.
21643 Return the computed name or NULL.
21644 Space for the result is allocated on the objfile's obstack.
21645 This is the full-die version of guess_partial_die_structure_name.
21646 In this case we know DIE has no useful parent. */
21648 static const char *
21649 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21651 struct die_info
*spec_die
;
21652 struct dwarf2_cu
*spec_cu
;
21653 struct die_info
*child
;
21654 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21657 spec_die
= die_specification (die
, &spec_cu
);
21658 if (spec_die
!= NULL
)
21664 for (child
= die
->child
;
21666 child
= child
->sibling
)
21668 if (child
->tag
== DW_TAG_subprogram
)
21670 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21672 if (linkage_name
!= NULL
)
21674 gdb::unique_xmalloc_ptr
<char> actual_name
21675 (language_class_name_from_physname (cu
->language_defn
,
21677 const char *name
= NULL
;
21679 if (actual_name
!= NULL
)
21681 const char *die_name
= dwarf2_name (die
, cu
);
21683 if (die_name
!= NULL
21684 && strcmp (die_name
, actual_name
.get ()) != 0)
21686 /* Strip off the class name from the full name.
21687 We want the prefix. */
21688 int die_name_len
= strlen (die_name
);
21689 int actual_name_len
= strlen (actual_name
.get ());
21690 const char *ptr
= actual_name
.get ();
21692 /* Test for '::' as a sanity check. */
21693 if (actual_name_len
> die_name_len
+ 2
21694 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21695 name
= obstack_strndup (
21696 &objfile
->per_bfd
->storage_obstack
,
21697 ptr
, actual_name_len
- die_name_len
- 2);
21708 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21709 prefix part in such case. See
21710 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21712 static const char *
21713 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21715 struct attribute
*attr
;
21718 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21719 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21722 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21725 attr
= dw2_linkage_name_attr (die
, cu
);
21726 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21729 /* dwarf2_name had to be already called. */
21730 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21732 /* Strip the base name, keep any leading namespaces/classes. */
21733 base
= strrchr (DW_STRING (attr
), ':');
21734 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21737 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21738 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21740 &base
[-1] - DW_STRING (attr
));
21743 /* Return the name of the namespace/class that DIE is defined within,
21744 or "" if we can't tell. The caller should not xfree the result.
21746 For example, if we're within the method foo() in the following
21756 then determine_prefix on foo's die will return "N::C". */
21758 static const char *
21759 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21761 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21762 struct die_info
*parent
, *spec_die
;
21763 struct dwarf2_cu
*spec_cu
;
21764 struct type
*parent_type
;
21765 const char *retval
;
21767 if (cu
->language
!= language_cplus
21768 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21769 && cu
->language
!= language_rust
)
21772 retval
= anonymous_struct_prefix (die
, cu
);
21776 /* We have to be careful in the presence of DW_AT_specification.
21777 For example, with GCC 3.4, given the code
21781 // Definition of N::foo.
21785 then we'll have a tree of DIEs like this:
21787 1: DW_TAG_compile_unit
21788 2: DW_TAG_namespace // N
21789 3: DW_TAG_subprogram // declaration of N::foo
21790 4: DW_TAG_subprogram // definition of N::foo
21791 DW_AT_specification // refers to die #3
21793 Thus, when processing die #4, we have to pretend that we're in
21794 the context of its DW_AT_specification, namely the contex of die
21797 spec_die
= die_specification (die
, &spec_cu
);
21798 if (spec_die
== NULL
)
21799 parent
= die
->parent
;
21802 parent
= spec_die
->parent
;
21806 if (parent
== NULL
)
21808 else if (parent
->building_fullname
)
21811 const char *parent_name
;
21813 /* It has been seen on RealView 2.2 built binaries,
21814 DW_TAG_template_type_param types actually _defined_ as
21815 children of the parent class:
21818 template class <class Enum> Class{};
21819 Class<enum E> class_e;
21821 1: DW_TAG_class_type (Class)
21822 2: DW_TAG_enumeration_type (E)
21823 3: DW_TAG_enumerator (enum1:0)
21824 3: DW_TAG_enumerator (enum2:1)
21826 2: DW_TAG_template_type_param
21827 DW_AT_type DW_FORM_ref_udata (E)
21829 Besides being broken debug info, it can put GDB into an
21830 infinite loop. Consider:
21832 When we're building the full name for Class<E>, we'll start
21833 at Class, and go look over its template type parameters,
21834 finding E. We'll then try to build the full name of E, and
21835 reach here. We're now trying to build the full name of E,
21836 and look over the parent DIE for containing scope. In the
21837 broken case, if we followed the parent DIE of E, we'd again
21838 find Class, and once again go look at its template type
21839 arguments, etc., etc. Simply don't consider such parent die
21840 as source-level parent of this die (it can't be, the language
21841 doesn't allow it), and break the loop here. */
21842 name
= dwarf2_name (die
, cu
);
21843 parent_name
= dwarf2_name (parent
, cu
);
21844 complaint (_("template param type '%s' defined within parent '%s'"),
21845 name
? name
: "<unknown>",
21846 parent_name
? parent_name
: "<unknown>");
21850 switch (parent
->tag
)
21852 case DW_TAG_namespace
:
21853 parent_type
= read_type_die (parent
, cu
);
21854 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21855 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21856 Work around this problem here. */
21857 if (cu
->language
== language_cplus
21858 && strcmp (parent_type
->name (), "::") == 0)
21860 /* We give a name to even anonymous namespaces. */
21861 return parent_type
->name ();
21862 case DW_TAG_class_type
:
21863 case DW_TAG_interface_type
:
21864 case DW_TAG_structure_type
:
21865 case DW_TAG_union_type
:
21866 case DW_TAG_module
:
21867 parent_type
= read_type_die (parent
, cu
);
21868 if (parent_type
->name () != NULL
)
21869 return parent_type
->name ();
21871 /* An anonymous structure is only allowed non-static data
21872 members; no typedefs, no member functions, et cetera.
21873 So it does not need a prefix. */
21875 case DW_TAG_compile_unit
:
21876 case DW_TAG_partial_unit
:
21877 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21878 if (cu
->language
== language_cplus
21879 && !dwarf2_per_objfile
->per_bfd
->types
.empty ()
21880 && die
->child
!= NULL
21881 && (die
->tag
== DW_TAG_class_type
21882 || die
->tag
== DW_TAG_structure_type
21883 || die
->tag
== DW_TAG_union_type
))
21885 const char *name
= guess_full_die_structure_name (die
, cu
);
21890 case DW_TAG_subprogram
:
21891 /* Nested subroutines in Fortran get a prefix with the name
21892 of the parent's subroutine. */
21893 if (cu
->language
== language_fortran
)
21895 if ((die
->tag
== DW_TAG_subprogram
)
21896 && (dwarf2_name (parent
, cu
) != NULL
))
21897 return dwarf2_name (parent
, cu
);
21899 return determine_prefix (parent
, cu
);
21900 case DW_TAG_enumeration_type
:
21901 parent_type
= read_type_die (parent
, cu
);
21902 if (TYPE_DECLARED_CLASS (parent_type
))
21904 if (parent_type
->name () != NULL
)
21905 return parent_type
->name ();
21908 /* Fall through. */
21910 return determine_prefix (parent
, cu
);
21914 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21915 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21916 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21917 an obconcat, otherwise allocate storage for the result. The CU argument is
21918 used to determine the language and hence, the appropriate separator. */
21920 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21923 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21924 int physname
, struct dwarf2_cu
*cu
)
21926 const char *lead
= "";
21929 if (suffix
== NULL
|| suffix
[0] == '\0'
21930 || prefix
== NULL
|| prefix
[0] == '\0')
21932 else if (cu
->language
== language_d
)
21934 /* For D, the 'main' function could be defined in any module, but it
21935 should never be prefixed. */
21936 if (strcmp (suffix
, "D main") == 0)
21944 else if (cu
->language
== language_fortran
&& physname
)
21946 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21947 DW_AT_MIPS_linkage_name is preferred and used instead. */
21955 if (prefix
== NULL
)
21957 if (suffix
== NULL
)
21964 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21966 strcpy (retval
, lead
);
21967 strcat (retval
, prefix
);
21968 strcat (retval
, sep
);
21969 strcat (retval
, suffix
);
21974 /* We have an obstack. */
21975 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21979 /* Get name of a die, return NULL if not found. */
21981 static const char *
21982 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21983 struct objfile
*objfile
)
21985 if (name
&& cu
->language
== language_cplus
)
21987 gdb::unique_xmalloc_ptr
<char> canon_name
21988 = cp_canonicalize_string (name
);
21990 if (canon_name
!= nullptr)
21991 name
= objfile
->intern (canon_name
.get ());
21997 /* Get name of a die, return NULL if not found.
21998 Anonymous namespaces are converted to their magic string. */
22000 static const char *
22001 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22003 struct attribute
*attr
;
22004 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22006 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22007 if ((!attr
|| !DW_STRING (attr
))
22008 && die
->tag
!= DW_TAG_namespace
22009 && die
->tag
!= DW_TAG_class_type
22010 && die
->tag
!= DW_TAG_interface_type
22011 && die
->tag
!= DW_TAG_structure_type
22012 && die
->tag
!= DW_TAG_union_type
)
22017 case DW_TAG_compile_unit
:
22018 case DW_TAG_partial_unit
:
22019 /* Compilation units have a DW_AT_name that is a filename, not
22020 a source language identifier. */
22021 case DW_TAG_enumeration_type
:
22022 case DW_TAG_enumerator
:
22023 /* These tags always have simple identifiers already; no need
22024 to canonicalize them. */
22025 return DW_STRING (attr
);
22027 case DW_TAG_namespace
:
22028 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22029 return DW_STRING (attr
);
22030 return CP_ANONYMOUS_NAMESPACE_STR
;
22032 case DW_TAG_class_type
:
22033 case DW_TAG_interface_type
:
22034 case DW_TAG_structure_type
:
22035 case DW_TAG_union_type
:
22036 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22037 structures or unions. These were of the form "._%d" in GCC 4.1,
22038 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22039 and GCC 4.4. We work around this problem by ignoring these. */
22040 if (attr
&& DW_STRING (attr
)
22041 && (startswith (DW_STRING (attr
), "._")
22042 || startswith (DW_STRING (attr
), "<anonymous")))
22045 /* GCC might emit a nameless typedef that has a linkage name. See
22046 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22047 if (!attr
|| DW_STRING (attr
) == NULL
)
22049 attr
= dw2_linkage_name_attr (die
, cu
);
22050 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22053 /* Avoid demangling DW_STRING (attr) the second time on a second
22054 call for the same DIE. */
22055 if (!DW_STRING_IS_CANONICAL (attr
))
22057 gdb::unique_xmalloc_ptr
<char> demangled
22058 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22059 if (demangled
== nullptr)
22062 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
22063 DW_STRING_IS_CANONICAL (attr
) = 1;
22066 /* Strip any leading namespaces/classes, keep only the base name.
22067 DW_AT_name for named DIEs does not contain the prefixes. */
22068 const char *base
= strrchr (DW_STRING (attr
), ':');
22069 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22072 return DW_STRING (attr
);
22080 if (!DW_STRING_IS_CANONICAL (attr
))
22082 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22084 DW_STRING_IS_CANONICAL (attr
) = 1;
22086 return DW_STRING (attr
);
22089 /* Return the die that this die in an extension of, or NULL if there
22090 is none. *EXT_CU is the CU containing DIE on input, and the CU
22091 containing the return value on output. */
22093 static struct die_info
*
22094 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22096 struct attribute
*attr
;
22098 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22102 return follow_die_ref (die
, attr
, ext_cu
);
22106 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22110 print_spaces (indent
, f
);
22111 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22112 dwarf_tag_name (die
->tag
), die
->abbrev
,
22113 sect_offset_str (die
->sect_off
));
22115 if (die
->parent
!= NULL
)
22117 print_spaces (indent
, f
);
22118 fprintf_unfiltered (f
, " parent at offset: %s\n",
22119 sect_offset_str (die
->parent
->sect_off
));
22122 print_spaces (indent
, f
);
22123 fprintf_unfiltered (f
, " has children: %s\n",
22124 dwarf_bool_name (die
->child
!= NULL
));
22126 print_spaces (indent
, f
);
22127 fprintf_unfiltered (f
, " attributes:\n");
22129 for (i
= 0; i
< die
->num_attrs
; ++i
)
22131 print_spaces (indent
, f
);
22132 fprintf_unfiltered (f
, " %s (%s) ",
22133 dwarf_attr_name (die
->attrs
[i
].name
),
22134 dwarf_form_name (die
->attrs
[i
].form
));
22136 switch (die
->attrs
[i
].form
)
22139 case DW_FORM_addrx
:
22140 case DW_FORM_GNU_addr_index
:
22141 fprintf_unfiltered (f
, "address: ");
22142 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22144 case DW_FORM_block2
:
22145 case DW_FORM_block4
:
22146 case DW_FORM_block
:
22147 case DW_FORM_block1
:
22148 fprintf_unfiltered (f
, "block: size %s",
22149 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22151 case DW_FORM_exprloc
:
22152 fprintf_unfiltered (f
, "expression: size %s",
22153 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22155 case DW_FORM_data16
:
22156 fprintf_unfiltered (f
, "constant of 16 bytes");
22158 case DW_FORM_ref_addr
:
22159 fprintf_unfiltered (f
, "ref address: ");
22160 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22162 case DW_FORM_GNU_ref_alt
:
22163 fprintf_unfiltered (f
, "alt ref address: ");
22164 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22170 case DW_FORM_ref_udata
:
22171 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22172 (long) (DW_UNSND (&die
->attrs
[i
])));
22174 case DW_FORM_data1
:
22175 case DW_FORM_data2
:
22176 case DW_FORM_data4
:
22177 case DW_FORM_data8
:
22178 case DW_FORM_udata
:
22179 case DW_FORM_sdata
:
22180 fprintf_unfiltered (f
, "constant: %s",
22181 pulongest (DW_UNSND (&die
->attrs
[i
])));
22183 case DW_FORM_sec_offset
:
22184 fprintf_unfiltered (f
, "section offset: %s",
22185 pulongest (DW_UNSND (&die
->attrs
[i
])));
22187 case DW_FORM_ref_sig8
:
22188 fprintf_unfiltered (f
, "signature: %s",
22189 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22191 case DW_FORM_string
:
22193 case DW_FORM_line_strp
:
22195 case DW_FORM_GNU_str_index
:
22196 case DW_FORM_GNU_strp_alt
:
22197 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22198 DW_STRING (&die
->attrs
[i
])
22199 ? DW_STRING (&die
->attrs
[i
]) : "",
22200 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22203 if (DW_UNSND (&die
->attrs
[i
]))
22204 fprintf_unfiltered (f
, "flag: TRUE");
22206 fprintf_unfiltered (f
, "flag: FALSE");
22208 case DW_FORM_flag_present
:
22209 fprintf_unfiltered (f
, "flag: TRUE");
22211 case DW_FORM_indirect
:
22212 /* The reader will have reduced the indirect form to
22213 the "base form" so this form should not occur. */
22214 fprintf_unfiltered (f
,
22215 "unexpected attribute form: DW_FORM_indirect");
22217 case DW_FORM_implicit_const
:
22218 fprintf_unfiltered (f
, "constant: %s",
22219 plongest (DW_SND (&die
->attrs
[i
])));
22222 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22223 die
->attrs
[i
].form
);
22226 fprintf_unfiltered (f
, "\n");
22231 dump_die_for_error (struct die_info
*die
)
22233 dump_die_shallow (gdb_stderr
, 0, die
);
22237 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22239 int indent
= level
* 4;
22241 gdb_assert (die
!= NULL
);
22243 if (level
>= max_level
)
22246 dump_die_shallow (f
, indent
, die
);
22248 if (die
->child
!= NULL
)
22250 print_spaces (indent
, f
);
22251 fprintf_unfiltered (f
, " Children:");
22252 if (level
+ 1 < max_level
)
22254 fprintf_unfiltered (f
, "\n");
22255 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22259 fprintf_unfiltered (f
,
22260 " [not printed, max nesting level reached]\n");
22264 if (die
->sibling
!= NULL
&& level
> 0)
22266 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22270 /* This is called from the pdie macro in gdbinit.in.
22271 It's not static so gcc will keep a copy callable from gdb. */
22274 dump_die (struct die_info
*die
, int max_level
)
22276 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22280 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22284 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22285 to_underlying (die
->sect_off
),
22291 /* Follow reference or signature attribute ATTR of SRC_DIE.
22292 On entry *REF_CU is the CU of SRC_DIE.
22293 On exit *REF_CU is the CU of the result. */
22295 static struct die_info
*
22296 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22297 struct dwarf2_cu
**ref_cu
)
22299 struct die_info
*die
;
22301 if (attr
->form_is_ref ())
22302 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22303 else if (attr
->form
== DW_FORM_ref_sig8
)
22304 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22307 dump_die_for_error (src_die
);
22308 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22309 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22315 /* Follow reference OFFSET.
22316 On entry *REF_CU is the CU of the source die referencing OFFSET.
22317 On exit *REF_CU is the CU of the result.
22318 Returns NULL if OFFSET is invalid. */
22320 static struct die_info
*
22321 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22322 struct dwarf2_cu
**ref_cu
)
22324 struct die_info temp_die
;
22325 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22326 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22328 gdb_assert (cu
->per_cu
!= NULL
);
22332 if (cu
->per_cu
->is_debug_types
)
22334 /* .debug_types CUs cannot reference anything outside their CU.
22335 If they need to, they have to reference a signatured type via
22336 DW_FORM_ref_sig8. */
22337 if (!cu
->header
.offset_in_cu_p (sect_off
))
22340 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22341 || !cu
->header
.offset_in_cu_p (sect_off
))
22343 struct dwarf2_per_cu_data
*per_cu
;
22345 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22346 dwarf2_per_objfile
);
22348 /* If necessary, add it to the queue and load its DIEs. */
22349 if (maybe_queue_comp_unit (cu
, per_cu
, dwarf2_per_objfile
, cu
->language
))
22350 load_full_comp_unit (per_cu
, dwarf2_per_objfile
, false, cu
->language
);
22352 target_cu
= dwarf2_per_objfile
->get_cu (per_cu
);
22354 else if (cu
->dies
== NULL
)
22356 /* We're loading full DIEs during partial symbol reading. */
22357 gdb_assert (dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
);
22358 load_full_comp_unit (cu
->per_cu
, dwarf2_per_objfile
, false,
22362 *ref_cu
= target_cu
;
22363 temp_die
.sect_off
= sect_off
;
22365 if (target_cu
!= cu
)
22366 target_cu
->ancestor
= cu
;
22368 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22370 to_underlying (sect_off
));
22373 /* Follow reference attribute ATTR of SRC_DIE.
22374 On entry *REF_CU is the CU of SRC_DIE.
22375 On exit *REF_CU is the CU of the result. */
22377 static struct die_info
*
22378 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22379 struct dwarf2_cu
**ref_cu
)
22381 sect_offset sect_off
= attr
->get_ref_die_offset ();
22382 struct dwarf2_cu
*cu
= *ref_cu
;
22383 struct die_info
*die
;
22385 die
= follow_die_offset (sect_off
,
22386 (attr
->form
== DW_FORM_GNU_ref_alt
22387 || cu
->per_cu
->is_dwz
),
22390 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22391 "at %s [in module %s]"),
22392 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22393 objfile_name (cu
->per_objfile
->objfile
));
22400 struct dwarf2_locexpr_baton
22401 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22402 dwarf2_per_cu_data
*per_cu
,
22403 dwarf2_per_objfile
*dwarf2_per_objfile
,
22404 CORE_ADDR (*get_frame_pc
) (void *baton
),
22405 void *baton
, bool resolve_abstract_p
)
22407 struct die_info
*die
;
22408 struct attribute
*attr
;
22409 struct dwarf2_locexpr_baton retval
;
22410 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22412 dwarf2_cu
*cu
= dwarf2_per_objfile
->get_cu (per_cu
);
22414 cu
= load_cu (per_cu
, dwarf2_per_objfile
, false);
22418 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22419 Instead just throw an error, not much else we can do. */
22420 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22421 sect_offset_str (sect_off
), objfile_name (objfile
));
22424 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22426 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22427 sect_offset_str (sect_off
), objfile_name (objfile
));
22429 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22430 if (!attr
&& resolve_abstract_p
22431 && (dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22432 != dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22434 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22435 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22436 struct gdbarch
*gdbarch
= objfile
->arch ();
22438 for (const auto &cand_off
22439 : dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22441 struct dwarf2_cu
*cand_cu
= cu
;
22442 struct die_info
*cand
22443 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22446 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22449 CORE_ADDR pc_low
, pc_high
;
22450 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22451 if (pc_low
== ((CORE_ADDR
) -1))
22453 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22454 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22455 if (!(pc_low
<= pc
&& pc
< pc_high
))
22459 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22466 /* DWARF: "If there is no such attribute, then there is no effect.".
22467 DATA is ignored if SIZE is 0. */
22469 retval
.data
= NULL
;
22472 else if (attr
->form_is_section_offset ())
22474 struct dwarf2_loclist_baton loclist_baton
;
22475 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22478 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22480 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22482 retval
.size
= size
;
22486 if (!attr
->form_is_block ())
22487 error (_("Dwarf Error: DIE at %s referenced in module %s "
22488 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22489 sect_offset_str (sect_off
), objfile_name (objfile
));
22491 retval
.data
= DW_BLOCK (attr
)->data
;
22492 retval
.size
= DW_BLOCK (attr
)->size
;
22494 retval
.per_objfile
= dwarf2_per_objfile
;
22495 retval
.per_cu
= cu
->per_cu
;
22497 dwarf2_per_objfile
->age_comp_units ();
22504 struct dwarf2_locexpr_baton
22505 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22506 dwarf2_per_cu_data
*per_cu
,
22507 dwarf2_per_objfile
*per_objfile
,
22508 CORE_ADDR (*get_frame_pc
) (void *baton
),
22511 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22513 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
22514 get_frame_pc
, baton
);
22517 /* Write a constant of a given type as target-ordered bytes into
22520 static const gdb_byte
*
22521 write_constant_as_bytes (struct obstack
*obstack
,
22522 enum bfd_endian byte_order
,
22529 *len
= TYPE_LENGTH (type
);
22530 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22531 store_unsigned_integer (result
, *len
, byte_order
, value
);
22539 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22540 dwarf2_per_cu_data
*per_cu
,
22541 dwarf2_per_objfile
*per_objfile
,
22545 struct die_info
*die
;
22546 struct attribute
*attr
;
22547 const gdb_byte
*result
= NULL
;
22550 enum bfd_endian byte_order
;
22551 struct objfile
*objfile
= per_objfile
->objfile
;
22553 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22555 cu
= load_cu (per_cu
, per_objfile
, false);
22559 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22560 Instead just throw an error, not much else we can do. */
22561 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22562 sect_offset_str (sect_off
), objfile_name (objfile
));
22565 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22567 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22568 sect_offset_str (sect_off
), objfile_name (objfile
));
22570 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22574 byte_order
= (bfd_big_endian (objfile
->obfd
)
22575 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22577 switch (attr
->form
)
22580 case DW_FORM_addrx
:
22581 case DW_FORM_GNU_addr_index
:
22585 *len
= cu
->header
.addr_size
;
22586 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22587 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22591 case DW_FORM_string
:
22594 case DW_FORM_GNU_str_index
:
22595 case DW_FORM_GNU_strp_alt
:
22596 /* DW_STRING is already allocated on the objfile obstack, point
22598 result
= (const gdb_byte
*) DW_STRING (attr
);
22599 *len
= strlen (DW_STRING (attr
));
22601 case DW_FORM_block1
:
22602 case DW_FORM_block2
:
22603 case DW_FORM_block4
:
22604 case DW_FORM_block
:
22605 case DW_FORM_exprloc
:
22606 case DW_FORM_data16
:
22607 result
= DW_BLOCK (attr
)->data
;
22608 *len
= DW_BLOCK (attr
)->size
;
22611 /* The DW_AT_const_value attributes are supposed to carry the
22612 symbol's value "represented as it would be on the target
22613 architecture." By the time we get here, it's already been
22614 converted to host endianness, so we just need to sign- or
22615 zero-extend it as appropriate. */
22616 case DW_FORM_data1
:
22617 type
= die_type (die
, cu
);
22618 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22619 if (result
== NULL
)
22620 result
= write_constant_as_bytes (obstack
, byte_order
,
22623 case DW_FORM_data2
:
22624 type
= die_type (die
, cu
);
22625 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22626 if (result
== NULL
)
22627 result
= write_constant_as_bytes (obstack
, byte_order
,
22630 case DW_FORM_data4
:
22631 type
= die_type (die
, cu
);
22632 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22633 if (result
== NULL
)
22634 result
= write_constant_as_bytes (obstack
, byte_order
,
22637 case DW_FORM_data8
:
22638 type
= die_type (die
, cu
);
22639 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22640 if (result
== NULL
)
22641 result
= write_constant_as_bytes (obstack
, byte_order
,
22645 case DW_FORM_sdata
:
22646 case DW_FORM_implicit_const
:
22647 type
= die_type (die
, cu
);
22648 result
= write_constant_as_bytes (obstack
, byte_order
,
22649 type
, DW_SND (attr
), len
);
22652 case DW_FORM_udata
:
22653 type
= die_type (die
, cu
);
22654 result
= write_constant_as_bytes (obstack
, byte_order
,
22655 type
, DW_UNSND (attr
), len
);
22659 complaint (_("unsupported const value attribute form: '%s'"),
22660 dwarf_form_name (attr
->form
));
22670 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22671 dwarf2_per_cu_data
*per_cu
,
22672 dwarf2_per_objfile
*per_objfile
)
22674 struct die_info
*die
;
22676 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
22678 cu
= load_cu (per_cu
, per_objfile
, false);
22683 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22687 return die_type (die
, cu
);
22693 dwarf2_get_die_type (cu_offset die_offset
,
22694 dwarf2_per_cu_data
*per_cu
,
22695 dwarf2_per_objfile
*per_objfile
)
22697 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22698 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
22701 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22702 On entry *REF_CU is the CU of SRC_DIE.
22703 On exit *REF_CU is the CU of the result.
22704 Returns NULL if the referenced DIE isn't found. */
22706 static struct die_info
*
22707 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22708 struct dwarf2_cu
**ref_cu
)
22710 struct die_info temp_die
;
22711 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22712 struct die_info
*die
;
22713 dwarf2_per_objfile
*dwarf2_per_objfile
= (*ref_cu
)->per_objfile
;
22716 /* While it might be nice to assert sig_type->type == NULL here,
22717 we can get here for DW_AT_imported_declaration where we need
22718 the DIE not the type. */
22720 /* If necessary, add it to the queue and load its DIEs. */
22722 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, dwarf2_per_objfile
,
22724 read_signatured_type (sig_type
, dwarf2_per_objfile
);
22726 sig_cu
= dwarf2_per_objfile
->get_cu (&sig_type
->per_cu
);
22727 gdb_assert (sig_cu
!= NULL
);
22728 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22729 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22730 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22731 to_underlying (temp_die
.sect_off
));
22734 /* For .gdb_index version 7 keep track of included TUs.
22735 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22736 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
22737 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7)
22739 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22744 sig_cu
->ancestor
= cu
;
22752 /* Follow signatured type referenced by ATTR in SRC_DIE.
22753 On entry *REF_CU is the CU of SRC_DIE.
22754 On exit *REF_CU is the CU of the result.
22755 The result is the DIE of the type.
22756 If the referenced type cannot be found an error is thrown. */
22758 static struct die_info
*
22759 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22760 struct dwarf2_cu
**ref_cu
)
22762 ULONGEST signature
= DW_SIGNATURE (attr
);
22763 struct signatured_type
*sig_type
;
22764 struct die_info
*die
;
22766 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22768 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22769 /* sig_type will be NULL if the signatured type is missing from
22771 if (sig_type
== NULL
)
22773 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22774 " from DIE at %s [in module %s]"),
22775 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22776 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22779 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22782 dump_die_for_error (src_die
);
22783 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22784 " from DIE at %s [in module %s]"),
22785 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22786 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22792 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22793 reading in and processing the type unit if necessary. */
22795 static struct type
*
22796 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22797 struct dwarf2_cu
*cu
)
22799 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22800 struct signatured_type
*sig_type
;
22801 struct dwarf2_cu
*type_cu
;
22802 struct die_info
*type_die
;
22805 sig_type
= lookup_signatured_type (cu
, signature
);
22806 /* sig_type will be NULL if the signatured type is missing from
22808 if (sig_type
== NULL
)
22810 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22811 " from DIE at %s [in module %s]"),
22812 hex_string (signature
), sect_offset_str (die
->sect_off
),
22813 objfile_name (dwarf2_per_objfile
->objfile
));
22814 return build_error_marker_type (cu
, die
);
22817 /* If we already know the type we're done. */
22818 type
= dwarf2_per_objfile
->get_type_for_signatured_type (sig_type
);
22819 if (type
!= nullptr)
22823 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22824 if (type_die
!= NULL
)
22826 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22827 is created. This is important, for example, because for c++ classes
22828 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22829 type
= read_type_die (type_die
, type_cu
);
22832 complaint (_("Dwarf Error: Cannot build signatured type %s"
22833 " referenced from DIE at %s [in module %s]"),
22834 hex_string (signature
), sect_offset_str (die
->sect_off
),
22835 objfile_name (dwarf2_per_objfile
->objfile
));
22836 type
= build_error_marker_type (cu
, die
);
22841 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22842 " from DIE at %s [in module %s]"),
22843 hex_string (signature
), sect_offset_str (die
->sect_off
),
22844 objfile_name (dwarf2_per_objfile
->objfile
));
22845 type
= build_error_marker_type (cu
, die
);
22848 dwarf2_per_objfile
->set_type_for_signatured_type (sig_type
, type
);
22853 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22854 reading in and processing the type unit if necessary. */
22856 static struct type
*
22857 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22858 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22860 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22861 if (attr
->form_is_ref ())
22863 struct dwarf2_cu
*type_cu
= cu
;
22864 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22866 return read_type_die (type_die
, type_cu
);
22868 else if (attr
->form
== DW_FORM_ref_sig8
)
22870 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22874 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
22876 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22877 " at %s [in module %s]"),
22878 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22879 objfile_name (dwarf2_per_objfile
->objfile
));
22880 return build_error_marker_type (cu
, die
);
22884 /* Load the DIEs associated with type unit PER_CU into memory. */
22887 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
22888 dwarf2_per_objfile
*per_objfile
)
22890 struct signatured_type
*sig_type
;
22892 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22893 gdb_assert (! per_cu
->type_unit_group_p ());
22895 /* We have the per_cu, but we need the signatured_type.
22896 Fortunately this is an easy translation. */
22897 gdb_assert (per_cu
->is_debug_types
);
22898 sig_type
= (struct signatured_type
*) per_cu
;
22900 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22902 read_signatured_type (sig_type
, per_objfile
);
22904 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
22907 /* Read in a signatured type and build its CU and DIEs.
22908 If the type is a stub for the real type in a DWO file,
22909 read in the real type from the DWO file as well. */
22912 read_signatured_type (signatured_type
*sig_type
,
22913 dwarf2_per_objfile
*per_objfile
)
22915 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22917 gdb_assert (per_cu
->is_debug_types
);
22918 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
22920 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
22922 if (!reader
.dummy_p
)
22924 struct dwarf2_cu
*cu
= reader
.cu
;
22925 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22927 gdb_assert (cu
->die_hash
== NULL
);
22929 htab_create_alloc_ex (cu
->header
.length
/ 12,
22933 &cu
->comp_unit_obstack
,
22934 hashtab_obstack_allocate
,
22935 dummy_obstack_deallocate
);
22937 if (reader
.comp_unit_die
->has_children
)
22938 reader
.comp_unit_die
->child
22939 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22940 reader
.comp_unit_die
);
22941 cu
->dies
= reader
.comp_unit_die
;
22942 /* comp_unit_die is not stored in die_hash, no need. */
22944 /* We try not to read any attributes in this function, because
22945 not all CUs needed for references have been loaded yet, and
22946 symbol table processing isn't initialized. But we have to
22947 set the CU language, or we won't be able to build types
22948 correctly. Similarly, if we do not read the producer, we can
22949 not apply producer-specific interpretation. */
22950 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22955 sig_type
->per_cu
.tu_read
= 1;
22958 /* Decode simple location descriptions.
22959 Given a pointer to a dwarf block that defines a location, compute
22960 the location and return the value. If COMPUTED is non-null, it is
22961 set to true to indicate that decoding was successful, and false
22962 otherwise. If COMPUTED is null, then this function may emit a
22966 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22968 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22970 size_t size
= blk
->size
;
22971 const gdb_byte
*data
= blk
->data
;
22972 CORE_ADDR stack
[64];
22974 unsigned int bytes_read
, unsnd
;
22977 if (computed
!= nullptr)
22983 stack
[++stacki
] = 0;
23022 stack
[++stacki
] = op
- DW_OP_lit0
;
23057 stack
[++stacki
] = op
- DW_OP_reg0
;
23060 if (computed
== nullptr)
23061 dwarf2_complex_location_expr_complaint ();
23068 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23070 stack
[++stacki
] = unsnd
;
23073 if (computed
== nullptr)
23074 dwarf2_complex_location_expr_complaint ();
23081 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23086 case DW_OP_const1u
:
23087 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23091 case DW_OP_const1s
:
23092 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23096 case DW_OP_const2u
:
23097 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23101 case DW_OP_const2s
:
23102 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23106 case DW_OP_const4u
:
23107 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23111 case DW_OP_const4s
:
23112 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23116 case DW_OP_const8u
:
23117 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23122 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23128 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23133 stack
[stacki
+ 1] = stack
[stacki
];
23138 stack
[stacki
- 1] += stack
[stacki
];
23142 case DW_OP_plus_uconst
:
23143 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23149 stack
[stacki
- 1] -= stack
[stacki
];
23154 /* If we're not the last op, then we definitely can't encode
23155 this using GDB's address_class enum. This is valid for partial
23156 global symbols, although the variable's address will be bogus
23160 if (computed
== nullptr)
23161 dwarf2_complex_location_expr_complaint ();
23167 case DW_OP_GNU_push_tls_address
:
23168 case DW_OP_form_tls_address
:
23169 /* The top of the stack has the offset from the beginning
23170 of the thread control block at which the variable is located. */
23171 /* Nothing should follow this operator, so the top of stack would
23173 /* This is valid for partial global symbols, but the variable's
23174 address will be bogus in the psymtab. Make it always at least
23175 non-zero to not look as a variable garbage collected by linker
23176 which have DW_OP_addr 0. */
23179 if (computed
== nullptr)
23180 dwarf2_complex_location_expr_complaint ();
23187 case DW_OP_GNU_uninit
:
23188 if (computed
!= nullptr)
23193 case DW_OP_GNU_addr_index
:
23194 case DW_OP_GNU_const_index
:
23195 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23201 if (computed
== nullptr)
23203 const char *name
= get_DW_OP_name (op
);
23206 complaint (_("unsupported stack op: '%s'"),
23209 complaint (_("unsupported stack op: '%02x'"),
23213 return (stack
[stacki
]);
23216 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23217 outside of the allocated space. Also enforce minimum>0. */
23218 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23220 if (computed
== nullptr)
23221 complaint (_("location description stack overflow"));
23227 if (computed
== nullptr)
23228 complaint (_("location description stack underflow"));
23233 if (computed
!= nullptr)
23235 return (stack
[stacki
]);
23238 /* memory allocation interface */
23240 static struct dwarf_block
*
23241 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23243 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23246 static struct die_info
*
23247 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23249 struct die_info
*die
;
23250 size_t size
= sizeof (struct die_info
);
23253 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23255 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23256 memset (die
, 0, sizeof (struct die_info
));
23262 /* Macro support. */
23264 /* An overload of dwarf_decode_macros that finds the correct section
23265 and ensures it is read in before calling the other overload. */
23268 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23269 int section_is_gnu
)
23271 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23272 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23273 const struct line_header
*lh
= cu
->line_header
;
23274 unsigned int offset_size
= cu
->header
.offset_size
;
23275 struct dwarf2_section_info
*section
;
23276 const char *section_name
;
23278 if (cu
->dwo_unit
!= nullptr)
23280 if (section_is_gnu
)
23282 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23283 section_name
= ".debug_macro.dwo";
23287 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23288 section_name
= ".debug_macinfo.dwo";
23293 if (section_is_gnu
)
23295 section
= &dwarf2_per_objfile
->per_bfd
->macro
;
23296 section_name
= ".debug_macro";
23300 section
= &dwarf2_per_objfile
->per_bfd
->macinfo
;
23301 section_name
= ".debug_macinfo";
23305 section
->read (objfile
);
23306 if (section
->buffer
== nullptr)
23308 complaint (_("missing %s section"), section_name
);
23312 buildsym_compunit
*builder
= cu
->get_builder ();
23314 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23315 offset_size
, offset
, section_is_gnu
);
23318 /* Return the .debug_loc section to use for CU.
23319 For DWO files use .debug_loc.dwo. */
23321 static struct dwarf2_section_info
*
23322 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23324 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23328 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23330 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23332 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->per_bfd
->loclists
23333 : &dwarf2_per_objfile
->per_bfd
->loc
);
23336 /* A helper function that fills in a dwarf2_loclist_baton. */
23339 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23340 struct dwarf2_loclist_baton
*baton
,
23341 const struct attribute
*attr
)
23343 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23344 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23346 section
->read (dwarf2_per_objfile
->objfile
);
23348 baton
->per_objfile
= dwarf2_per_objfile
;
23349 baton
->per_cu
= cu
->per_cu
;
23350 gdb_assert (baton
->per_cu
);
23351 /* We don't know how long the location list is, but make sure we
23352 don't run off the edge of the section. */
23353 baton
->size
= section
->size
- DW_UNSND (attr
);
23354 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23355 if (cu
->base_address
.has_value ())
23356 baton
->base_address
= *cu
->base_address
;
23358 baton
->base_address
= 0;
23359 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23363 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23364 struct dwarf2_cu
*cu
, int is_block
)
23366 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23367 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23368 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23370 if (attr
->form_is_section_offset ()
23371 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23372 the section. If so, fall through to the complaint in the
23374 && DW_UNSND (attr
) < section
->get_size (objfile
))
23376 struct dwarf2_loclist_baton
*baton
;
23378 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23380 fill_in_loclist_baton (cu
, baton
, attr
);
23382 if (!cu
->base_address
.has_value ())
23383 complaint (_("Location list used without "
23384 "specifying the CU base address."));
23386 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23387 ? dwarf2_loclist_block_index
23388 : dwarf2_loclist_index
);
23389 SYMBOL_LOCATION_BATON (sym
) = baton
;
23393 struct dwarf2_locexpr_baton
*baton
;
23395 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23396 baton
->per_objfile
= dwarf2_per_objfile
;
23397 baton
->per_cu
= cu
->per_cu
;
23398 gdb_assert (baton
->per_cu
);
23400 if (attr
->form_is_block ())
23402 /* Note that we're just copying the block's data pointer
23403 here, not the actual data. We're still pointing into the
23404 info_buffer for SYM's objfile; right now we never release
23405 that buffer, but when we do clean up properly this may
23407 baton
->size
= DW_BLOCK (attr
)->size
;
23408 baton
->data
= DW_BLOCK (attr
)->data
;
23412 dwarf2_invalid_attrib_class_complaint ("location description",
23413 sym
->natural_name ());
23417 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23418 ? dwarf2_locexpr_block_index
23419 : dwarf2_locexpr_index
);
23420 SYMBOL_LOCATION_BATON (sym
) = baton
;
23426 const comp_unit_head
*
23427 dwarf2_per_cu_data::get_header () const
23429 if (!m_header_read_in
)
23431 const gdb_byte
*info_ptr
23432 = this->section
->buffer
+ to_underlying (this->sect_off
);
23434 memset (&m_header
, 0, sizeof (m_header
));
23436 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
23437 rcuh_kind::COMPILE
);
23446 dwarf2_per_cu_data::addr_size () const
23448 return this->get_header ()->addr_size
;
23454 dwarf2_per_cu_data::offset_size () const
23456 return this->get_header ()->offset_size
;
23462 dwarf2_per_cu_data::ref_addr_size () const
23464 const comp_unit_head
*header
= this->get_header ();
23466 if (header
->version
== 2)
23467 return header
->addr_size
;
23469 return header
->offset_size
;
23475 dwarf2_cu::addr_type () const
23477 struct objfile
*objfile
= this->per_objfile
->objfile
;
23478 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23479 struct type
*addr_type
= lookup_pointer_type (void_type
);
23480 int addr_size
= this->per_cu
->addr_size ();
23482 if (TYPE_LENGTH (addr_type
) == addr_size
)
23485 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23489 /* A helper function for dwarf2_find_containing_comp_unit that returns
23490 the index of the result, and that searches a vector. It will
23491 return a result even if the offset in question does not actually
23492 occur in any CU. This is separate so that it can be unit
23496 dwarf2_find_containing_comp_unit
23497 (sect_offset sect_off
,
23498 unsigned int offset_in_dwz
,
23499 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23504 high
= all_comp_units
.size () - 1;
23507 struct dwarf2_per_cu_data
*mid_cu
;
23508 int mid
= low
+ (high
- low
) / 2;
23510 mid_cu
= all_comp_units
[mid
];
23511 if (mid_cu
->is_dwz
> offset_in_dwz
23512 || (mid_cu
->is_dwz
== offset_in_dwz
23513 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23518 gdb_assert (low
== high
);
23522 /* Locate the .debug_info compilation unit from CU's objfile which contains
23523 the DIE at OFFSET. Raises an error on failure. */
23525 static struct dwarf2_per_cu_data
*
23526 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23527 unsigned int offset_in_dwz
,
23528 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23531 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23532 dwarf2_per_objfile
->per_bfd
->all_comp_units
);
23533 struct dwarf2_per_cu_data
*this_cu
23534 = dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
];
23536 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23538 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23539 error (_("Dwarf Error: could not find partial DIE containing "
23540 "offset %s [in module %s]"),
23541 sect_offset_str (sect_off
),
23542 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23544 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23546 return dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1];
23550 if (low
== dwarf2_per_objfile
->per_bfd
->all_comp_units
.size () - 1
23551 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23552 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23553 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23560 namespace selftests
{
23561 namespace find_containing_comp_unit
{
23566 struct dwarf2_per_cu_data one
{};
23567 struct dwarf2_per_cu_data two
{};
23568 struct dwarf2_per_cu_data three
{};
23569 struct dwarf2_per_cu_data four
{};
23572 two
.sect_off
= sect_offset (one
.length
);
23577 four
.sect_off
= sect_offset (three
.length
);
23581 std::vector
<dwarf2_per_cu_data
*> units
;
23582 units
.push_back (&one
);
23583 units
.push_back (&two
);
23584 units
.push_back (&three
);
23585 units
.push_back (&four
);
23589 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23590 SELF_CHECK (units
[result
] == &one
);
23591 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23592 SELF_CHECK (units
[result
] == &one
);
23593 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23594 SELF_CHECK (units
[result
] == &two
);
23596 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23597 SELF_CHECK (units
[result
] == &three
);
23598 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23599 SELF_CHECK (units
[result
] == &three
);
23600 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23601 SELF_CHECK (units
[result
] == &four
);
23607 #endif /* GDB_SELF_TEST */
23609 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
23611 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
23612 dwarf2_per_objfile
*per_objfile
)
23614 per_objfile (per_objfile
),
23616 has_loclist (false),
23617 checked_producer (false),
23618 producer_is_gxx_lt_4_6 (false),
23619 producer_is_gcc_lt_4_3 (false),
23620 producer_is_icc (false),
23621 producer_is_icc_lt_14 (false),
23622 producer_is_codewarrior (false),
23623 processing_has_namespace_info (false)
23627 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23630 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23631 enum language pretend_language
)
23633 struct attribute
*attr
;
23635 /* Set the language we're debugging. */
23636 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23637 if (attr
!= nullptr)
23638 set_cu_language (DW_UNSND (attr
), cu
);
23641 cu
->language
= pretend_language
;
23642 cu
->language_defn
= language_def (cu
->language
);
23645 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23651 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
23653 auto it
= m_dwarf2_cus
.find (per_cu
);
23654 if (it
== m_dwarf2_cus
.end ())
23663 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
23665 gdb_assert (this->get_cu (per_cu
) == nullptr);
23667 m_dwarf2_cus
[per_cu
] = cu
;
23673 dwarf2_per_objfile::age_comp_units ()
23675 /* Start by clearing all marks. */
23676 for (auto pair
: m_dwarf2_cus
)
23677 pair
.second
->mark
= false;
23679 /* Traverse all CUs, mark them and their dependencies if used recently
23681 for (auto pair
: m_dwarf2_cus
)
23683 dwarf2_cu
*cu
= pair
.second
;
23686 if (cu
->last_used
<= dwarf_max_cache_age
)
23690 /* Delete all CUs still not marked. */
23691 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
23693 dwarf2_cu
*cu
= it
->second
;
23698 it
= m_dwarf2_cus
.erase (it
);
23708 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
23710 auto it
= m_dwarf2_cus
.find (per_cu
);
23711 if (it
== m_dwarf2_cus
.end ())
23716 m_dwarf2_cus
.erase (it
);
23719 dwarf2_per_objfile::~dwarf2_per_objfile ()
23724 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23725 We store these in a hash table separate from the DIEs, and preserve them
23726 when the DIEs are flushed out of cache.
23728 The CU "per_cu" pointer is needed because offset alone is not enough to
23729 uniquely identify the type. A file may have multiple .debug_types sections,
23730 or the type may come from a DWO file. Furthermore, while it's more logical
23731 to use per_cu->section+offset, with Fission the section with the data is in
23732 the DWO file but we don't know that section at the point we need it.
23733 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23734 because we can enter the lookup routine, get_die_type_at_offset, from
23735 outside this file, and thus won't necessarily have PER_CU->cu.
23736 Fortunately, PER_CU is stable for the life of the objfile. */
23738 struct dwarf2_per_cu_offset_and_type
23740 const struct dwarf2_per_cu_data
*per_cu
;
23741 sect_offset sect_off
;
23745 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23748 per_cu_offset_and_type_hash (const void *item
)
23750 const struct dwarf2_per_cu_offset_and_type
*ofs
23751 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23753 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23756 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23759 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23761 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23762 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23763 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23764 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23766 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23767 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23770 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23771 table if necessary. For convenience, return TYPE.
23773 The DIEs reading must have careful ordering to:
23774 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23775 reading current DIE.
23776 * Not trying to dereference contents of still incompletely read in types
23777 while reading in other DIEs.
23778 * Enable referencing still incompletely read in types just by a pointer to
23779 the type without accessing its fields.
23781 Therefore caller should follow these rules:
23782 * Try to fetch any prerequisite types we may need to build this DIE type
23783 before building the type and calling set_die_type.
23784 * After building type call set_die_type for current DIE as soon as
23785 possible before fetching more types to complete the current type.
23786 * Make the type as complete as possible before fetching more types. */
23788 static struct type
*
23789 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23791 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23792 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23793 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23794 struct attribute
*attr
;
23795 struct dynamic_prop prop
;
23797 /* For Ada types, make sure that the gnat-specific data is always
23798 initialized (if not already set). There are a few types where
23799 we should not be doing so, because the type-specific area is
23800 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23801 where the type-specific area is used to store the floatformat).
23802 But this is not a problem, because the gnat-specific information
23803 is actually not needed for these types. */
23804 if (need_gnat_info (cu
)
23805 && type
->code () != TYPE_CODE_FUNC
23806 && type
->code () != TYPE_CODE_FLT
23807 && type
->code () != TYPE_CODE_METHODPTR
23808 && type
->code () != TYPE_CODE_MEMBERPTR
23809 && type
->code () != TYPE_CODE_METHOD
23810 && !HAVE_GNAT_AUX_INFO (type
))
23811 INIT_GNAT_SPECIFIC (type
);
23813 /* Read DW_AT_allocated and set in type. */
23814 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23815 if (attr
!= NULL
&& attr
->form_is_block ())
23817 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23818 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23819 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23821 else if (attr
!= NULL
)
23823 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23824 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23825 sect_offset_str (die
->sect_off
));
23828 /* Read DW_AT_associated and set in type. */
23829 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23830 if (attr
!= NULL
&& attr
->form_is_block ())
23832 struct type
*prop_type
= cu
->addr_sized_int_type (false);
23833 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23834 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23836 else if (attr
!= NULL
)
23838 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23839 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23840 sect_offset_str (die
->sect_off
));
23843 /* Read DW_AT_data_location and set in type. */
23844 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23845 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
23846 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23848 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23849 dwarf2_per_objfile
->die_type_hash
23850 = htab_up (htab_create_alloc (127,
23851 per_cu_offset_and_type_hash
,
23852 per_cu_offset_and_type_eq
,
23853 NULL
, xcalloc
, xfree
));
23855 ofs
.per_cu
= cu
->per_cu
;
23856 ofs
.sect_off
= die
->sect_off
;
23858 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23859 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23861 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23862 sect_offset_str (die
->sect_off
));
23863 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23864 struct dwarf2_per_cu_offset_and_type
);
23869 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23870 or return NULL if the die does not have a saved type. */
23872 static struct type
*
23873 get_die_type_at_offset (sect_offset sect_off
,
23874 dwarf2_per_cu_data
*per_cu
,
23875 dwarf2_per_objfile
*dwarf2_per_objfile
)
23877 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23879 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23882 ofs
.per_cu
= per_cu
;
23883 ofs
.sect_off
= sect_off
;
23884 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23885 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23892 /* Look up the type for DIE in CU in die_type_hash,
23893 or return NULL if DIE does not have a saved type. */
23895 static struct type
*
23896 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23898 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
23901 /* Add a dependence relationship from CU to REF_PER_CU. */
23904 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23905 struct dwarf2_per_cu_data
*ref_per_cu
)
23909 if (cu
->dependencies
== NULL
)
23911 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23912 NULL
, &cu
->comp_unit_obstack
,
23913 hashtab_obstack_allocate
,
23914 dummy_obstack_deallocate
);
23916 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23918 *slot
= ref_per_cu
;
23921 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23922 Set the mark field in every compilation unit in the
23923 cache that we must keep because we are keeping CU.
23925 DATA is the dwarf2_per_objfile object in which to look up CUs. */
23928 dwarf2_mark_helper (void **slot
, void *data
)
23930 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
23931 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
23932 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23934 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23935 reading of the chain. As such dependencies remain valid it is not much
23936 useful to track and undo them during QUIT cleanups. */
23945 if (cu
->dependencies
!= nullptr)
23946 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
23951 /* Set the mark field in CU and in every other compilation unit in the
23952 cache that we must keep because we are keeping CU. */
23955 dwarf2_mark (struct dwarf2_cu
*cu
)
23962 if (cu
->dependencies
!= nullptr)
23963 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
23966 /* Trivial hash function for partial_die_info: the hash value of a DIE
23967 is its offset in .debug_info for this objfile. */
23970 partial_die_hash (const void *item
)
23972 const struct partial_die_info
*part_die
23973 = (const struct partial_die_info
*) item
;
23975 return to_underlying (part_die
->sect_off
);
23978 /* Trivial comparison function for partial_die_info structures: two DIEs
23979 are equal if they have the same offset. */
23982 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23984 const struct partial_die_info
*part_die_lhs
23985 = (const struct partial_die_info
*) item_lhs
;
23986 const struct partial_die_info
*part_die_rhs
23987 = (const struct partial_die_info
*) item_rhs
;
23989 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23992 struct cmd_list_element
*set_dwarf_cmdlist
;
23993 struct cmd_list_element
*show_dwarf_cmdlist
;
23996 show_check_physname (struct ui_file
*file
, int from_tty
,
23997 struct cmd_list_element
*c
, const char *value
)
23999 fprintf_filtered (file
,
24000 _("Whether to check \"physname\" is %s.\n"),
24004 void _initialize_dwarf2_read ();
24006 _initialize_dwarf2_read ()
24008 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24009 Set DWARF specific variables.\n\
24010 Configure DWARF variables such as the cache size."),
24011 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24012 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24014 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24015 Show DWARF specific variables.\n\
24016 Show DWARF variables such as the cache size."),
24017 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24018 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24020 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24021 &dwarf_max_cache_age
, _("\
24022 Set the upper bound on the age of cached DWARF compilation units."), _("\
24023 Show the upper bound on the age of cached DWARF compilation units."), _("\
24024 A higher limit means that cached compilation units will be stored\n\
24025 in memory longer, and more total memory will be used. Zero disables\n\
24026 caching, which can slow down startup."),
24028 show_dwarf_max_cache_age
,
24029 &set_dwarf_cmdlist
,
24030 &show_dwarf_cmdlist
);
24032 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24033 Set debugging of the DWARF reader."), _("\
24034 Show debugging of the DWARF reader."), _("\
24035 When enabled (non-zero), debugging messages are printed during DWARF\n\
24036 reading and symtab expansion. A value of 1 (one) provides basic\n\
24037 information. A value greater than 1 provides more verbose information."),
24040 &setdebuglist
, &showdebuglist
);
24042 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24043 Set debugging of the DWARF DIE reader."), _("\
24044 Show debugging of the DWARF DIE reader."), _("\
24045 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24046 The value is the maximum depth to print."),
24049 &setdebuglist
, &showdebuglist
);
24051 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24052 Set debugging of the dwarf line reader."), _("\
24053 Show debugging of the dwarf line reader."), _("\
24054 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24055 A value of 1 (one) provides basic information.\n\
24056 A value greater than 1 provides more verbose information."),
24059 &setdebuglist
, &showdebuglist
);
24061 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24062 Set cross-checking of \"physname\" code against demangler."), _("\
24063 Show cross-checking of \"physname\" code against demangler."), _("\
24064 When enabled, GDB's internal \"physname\" code is checked against\n\
24066 NULL
, show_check_physname
,
24067 &setdebuglist
, &showdebuglist
);
24069 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24070 no_class
, &use_deprecated_index_sections
, _("\
24071 Set whether to use deprecated gdb_index sections."), _("\
24072 Show whether to use deprecated gdb_index sections."), _("\
24073 When enabled, deprecated .gdb_index sections are used anyway.\n\
24074 Normally they are ignored either because of a missing feature or\n\
24075 performance issue.\n\
24076 Warning: This option must be enabled before gdb reads the file."),
24079 &setlist
, &showlist
);
24081 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24082 &dwarf2_locexpr_funcs
);
24083 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24084 &dwarf2_loclist_funcs
);
24086 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24087 &dwarf2_block_frame_base_locexpr_funcs
);
24088 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24089 &dwarf2_block_frame_base_loclist_funcs
);
24092 selftests::register_test ("dw2_expand_symtabs_matching",
24093 selftests::dw2_expand_symtabs_matching::run_test
);
24094 selftests::register_test ("dwarf2_find_containing_comp_unit",
24095 selftests::find_containing_comp_unit::run_test
);