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 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
110 /* The "aclass" indices for various kinds of computed DWARF symbols. */
112 static int dwarf2_locexpr_index
;
113 static int dwarf2_loclist_index
;
114 static int dwarf2_locexpr_block_index
;
115 static int dwarf2_loclist_block_index
;
117 /* Size of .debug_loclists section header for 32-bit DWARF format. */
118 #define LOCLIST_HEADER_SIZE32 12
120 /* Size of .debug_loclists section header for 64-bit DWARF format. */
121 #define LOCLIST_HEADER_SIZE64 20
123 /* An index into a (C++) symbol name component in a symbol name as
124 recorded in the mapped_index's symbol table. For each C++ symbol
125 in the symbol table, we record one entry for the start of each
126 component in the symbol in a table of name components, and then
127 sort the table, in order to be able to binary search symbol names,
128 ignoring leading namespaces, both completion and regular look up.
129 For example, for symbol "A::B::C", we'll have an entry that points
130 to "A::B::C", another that points to "B::C", and another for "C".
131 Note that function symbols in GDB index have no parameter
132 information, just the function/method names. You can convert a
133 name_component to a "const char *" using the
134 'mapped_index::symbol_name_at(offset_type)' method. */
136 struct name_component
138 /* Offset in the symbol name where the component starts. Stored as
139 a (32-bit) offset instead of a pointer to save memory and improve
140 locality on 64-bit architectures. */
141 offset_type name_offset
;
143 /* The symbol's index in the symbol and constant pool tables of a
148 /* Base class containing bits shared by both .gdb_index and
149 .debug_name indexes. */
151 struct mapped_index_base
153 mapped_index_base () = default;
154 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
156 /* The name_component table (a sorted vector). See name_component's
157 description above. */
158 std::vector
<name_component
> name_components
;
160 /* How NAME_COMPONENTS is sorted. */
161 enum case_sensitivity name_components_casing
;
163 /* Return the number of names in the symbol table. */
164 virtual size_t symbol_name_count () const = 0;
166 /* Get the name of the symbol at IDX in the symbol table. */
167 virtual const char *symbol_name_at (offset_type idx
) const = 0;
169 /* Return whether the name at IDX in the symbol table should be
171 virtual bool symbol_name_slot_invalid (offset_type idx
) const
176 /* Build the symbol name component sorted vector, if we haven't
178 void build_name_components ();
180 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
181 possible matches for LN_NO_PARAMS in the name component
183 std::pair
<std::vector
<name_component
>::const_iterator
,
184 std::vector
<name_component
>::const_iterator
>
185 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
186 enum language lang
) const;
188 /* Prevent deleting/destroying via a base class pointer. */
190 ~mapped_index_base() = default;
193 /* A description of the mapped index. The file format is described in
194 a comment by the code that writes the index. */
195 struct mapped_index final
: public mapped_index_base
197 /* A slot/bucket in the symbol table hash. */
198 struct symbol_table_slot
200 const offset_type name
;
201 const offset_type vec
;
204 /* Index data format version. */
207 /* The address table data. */
208 gdb::array_view
<const gdb_byte
> address_table
;
210 /* The symbol table, implemented as a hash table. */
211 gdb::array_view
<symbol_table_slot
> symbol_table
;
213 /* A pointer to the constant pool. */
214 const char *constant_pool
= nullptr;
216 bool symbol_name_slot_invalid (offset_type idx
) const override
218 const auto &bucket
= this->symbol_table
[idx
];
219 return bucket
.name
== 0 && bucket
.vec
== 0;
222 /* Convenience method to get at the name of the symbol at IDX in the
224 const char *symbol_name_at (offset_type idx
) const override
225 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
227 size_t symbol_name_count () const override
228 { return this->symbol_table
.size (); }
231 /* A description of the mapped .debug_names.
232 Uninitialized map has CU_COUNT 0. */
233 struct mapped_debug_names final
: public mapped_index_base
235 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
236 : dwarf2_per_objfile (dwarf2_per_objfile_
)
239 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
240 bfd_endian dwarf5_byte_order
;
241 bool dwarf5_is_dwarf64
;
242 bool augmentation_is_gdb
;
244 uint32_t cu_count
= 0;
245 uint32_t tu_count
, bucket_count
, name_count
;
246 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
247 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
248 const gdb_byte
*name_table_string_offs_reordered
;
249 const gdb_byte
*name_table_entry_offs_reordered
;
250 const gdb_byte
*entry_pool
;
257 /* Attribute name DW_IDX_*. */
260 /* Attribute form DW_FORM_*. */
263 /* Value if FORM is DW_FORM_implicit_const. */
264 LONGEST implicit_const
;
266 std::vector
<attr
> attr_vec
;
269 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
271 const char *namei_to_name (uint32_t namei
) const;
273 /* Implementation of the mapped_index_base virtual interface, for
274 the name_components cache. */
276 const char *symbol_name_at (offset_type idx
) const override
277 { return namei_to_name (idx
); }
279 size_t symbol_name_count () const override
280 { return this->name_count
; }
283 /* See dwarf2read.h. */
286 get_dwarf2_per_objfile (struct objfile
*objfile
)
288 return dwarf2_objfile_data_key
.get (objfile
);
291 /* Default names of the debugging sections. */
293 /* Note that if the debugging section has been compressed, it might
294 have a name like .zdebug_info. */
296 static const struct dwarf2_debug_sections dwarf2_elf_names
=
298 { ".debug_info", ".zdebug_info" },
299 { ".debug_abbrev", ".zdebug_abbrev" },
300 { ".debug_line", ".zdebug_line" },
301 { ".debug_loc", ".zdebug_loc" },
302 { ".debug_loclists", ".zdebug_loclists" },
303 { ".debug_macinfo", ".zdebug_macinfo" },
304 { ".debug_macro", ".zdebug_macro" },
305 { ".debug_str", ".zdebug_str" },
306 { ".debug_str_offsets", ".zdebug_str_offsets" },
307 { ".debug_line_str", ".zdebug_line_str" },
308 { ".debug_ranges", ".zdebug_ranges" },
309 { ".debug_rnglists", ".zdebug_rnglists" },
310 { ".debug_types", ".zdebug_types" },
311 { ".debug_addr", ".zdebug_addr" },
312 { ".debug_frame", ".zdebug_frame" },
313 { ".eh_frame", NULL
},
314 { ".gdb_index", ".zgdb_index" },
315 { ".debug_names", ".zdebug_names" },
316 { ".debug_aranges", ".zdebug_aranges" },
320 /* List of DWO/DWP sections. */
322 static const struct dwop_section_names
324 struct dwarf2_section_names abbrev_dwo
;
325 struct dwarf2_section_names info_dwo
;
326 struct dwarf2_section_names line_dwo
;
327 struct dwarf2_section_names loc_dwo
;
328 struct dwarf2_section_names loclists_dwo
;
329 struct dwarf2_section_names macinfo_dwo
;
330 struct dwarf2_section_names macro_dwo
;
331 struct dwarf2_section_names str_dwo
;
332 struct dwarf2_section_names str_offsets_dwo
;
333 struct dwarf2_section_names types_dwo
;
334 struct dwarf2_section_names cu_index
;
335 struct dwarf2_section_names tu_index
;
339 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
340 { ".debug_info.dwo", ".zdebug_info.dwo" },
341 { ".debug_line.dwo", ".zdebug_line.dwo" },
342 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
343 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
344 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
345 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
346 { ".debug_str.dwo", ".zdebug_str.dwo" },
347 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
348 { ".debug_types.dwo", ".zdebug_types.dwo" },
349 { ".debug_cu_index", ".zdebug_cu_index" },
350 { ".debug_tu_index", ".zdebug_tu_index" },
353 /* local data types */
355 /* The location list section (.debug_loclists) begins with a header,
356 which contains the following information. */
357 struct loclist_header
359 /* A 4-byte or 12-byte length containing the length of the
360 set of entries for this compilation unit, not including the
361 length field itself. */
364 /* A 2-byte version identifier. */
367 /* A 1-byte unsigned integer containing the size in bytes of an address on
368 the target system. */
369 unsigned char addr_size
;
371 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
372 on the target system. */
373 unsigned char segment_collector_size
;
375 /* A 4-byte count of the number of offsets that follow the header. */
376 unsigned int offset_entry_count
;
379 /* Type used for delaying computation of method physnames.
380 See comments for compute_delayed_physnames. */
381 struct delayed_method_info
383 /* The type to which the method is attached, i.e., its parent class. */
386 /* The index of the method in the type's function fieldlists. */
389 /* The index of the method in the fieldlist. */
392 /* The name of the DIE. */
395 /* The DIE associated with this method. */
396 struct die_info
*die
;
399 /* Internal state when decoding a particular compilation unit. */
402 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
405 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
407 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
408 Create the set of symtabs used by this TU, or if this TU is sharing
409 symtabs with another TU and the symtabs have already been created
410 then restore those symtabs in the line header.
411 We don't need the pc/line-number mapping for type units. */
412 void setup_type_unit_groups (struct die_info
*die
);
414 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
415 buildsym_compunit constructor. */
416 struct compunit_symtab
*start_symtab (const char *name
,
417 const char *comp_dir
,
420 /* Reset the builder. */
421 void reset_builder () { m_builder
.reset (); }
423 /* The header of the compilation unit. */
424 struct comp_unit_head header
{};
426 /* Base address of this compilation unit. */
427 gdb::optional
<CORE_ADDR
> base_address
;
429 /* The language we are debugging. */
430 enum language language
= language_unknown
;
431 const struct language_defn
*language_defn
= nullptr;
433 const char *producer
= nullptr;
436 /* The symtab builder for this CU. This is only non-NULL when full
437 symbols are being read. */
438 std::unique_ptr
<buildsym_compunit
> m_builder
;
441 /* The generic symbol table building routines have separate lists for
442 file scope symbols and all all other scopes (local scopes). So
443 we need to select the right one to pass to add_symbol_to_list().
444 We do it by keeping a pointer to the correct list in list_in_scope.
446 FIXME: The original dwarf code just treated the file scope as the
447 first local scope, and all other local scopes as nested local
448 scopes, and worked fine. Check to see if we really need to
449 distinguish these in buildsym.c. */
450 struct pending
**list_in_scope
= nullptr;
452 /* Hash table holding all the loaded partial DIEs
453 with partial_die->offset.SECT_OFF as hash. */
454 htab_t partial_dies
= nullptr;
456 /* Storage for things with the same lifetime as this read-in compilation
457 unit, including partial DIEs. */
458 auto_obstack comp_unit_obstack
;
460 /* When multiple dwarf2_cu structures are living in memory, this field
461 chains them all together, so that they can be released efficiently.
462 We will probably also want a generation counter so that most-recently-used
463 compilation units are cached... */
464 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
466 /* Backlink to our per_cu entry. */
467 struct dwarf2_per_cu_data
*per_cu
;
469 /* How many compilation units ago was this CU last referenced? */
472 /* A hash table of DIE cu_offset for following references with
473 die_info->offset.sect_off as hash. */
474 htab_t die_hash
= nullptr;
476 /* Full DIEs if read in. */
477 struct die_info
*dies
= nullptr;
479 /* A set of pointers to dwarf2_per_cu_data objects for compilation
480 units referenced by this one. Only set during full symbol processing;
481 partial symbol tables do not have dependencies. */
482 htab_t dependencies
= nullptr;
484 /* Header data from the line table, during full symbol processing. */
485 struct line_header
*line_header
= nullptr;
486 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
487 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
488 this is the DW_TAG_compile_unit die for this CU. We'll hold on
489 to the line header as long as this DIE is being processed. See
490 process_die_scope. */
491 die_info
*line_header_die_owner
= nullptr;
493 /* A list of methods which need to have physnames computed
494 after all type information has been read. */
495 std::vector
<delayed_method_info
> method_list
;
497 /* To be copied to symtab->call_site_htab. */
498 htab_t call_site_htab
= nullptr;
500 /* Non-NULL if this CU came from a DWO file.
501 There is an invariant here that is important to remember:
502 Except for attributes copied from the top level DIE in the "main"
503 (or "stub") file in preparation for reading the DWO file
504 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
505 Either there isn't a DWO file (in which case this is NULL and the point
506 is moot), or there is and either we're not going to read it (in which
507 case this is NULL) or there is and we are reading it (in which case this
509 struct dwo_unit
*dwo_unit
= nullptr;
511 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
512 Note this value comes from the Fission stub CU/TU's DIE. */
513 gdb::optional
<ULONGEST
> addr_base
;
515 /* The DW_AT_rnglists_base attribute if present.
516 Note this value comes from the Fission stub CU/TU's DIE.
517 Also note that the value is zero in the non-DWO case so this value can
518 be used without needing to know whether DWO files are in use or not.
519 N.B. This does not apply to DW_AT_ranges appearing in
520 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
521 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
522 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
523 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
524 ULONGEST ranges_base
= 0;
526 /* The DW_AT_loclists_base attribute if present. */
527 ULONGEST loclist_base
= 0;
529 /* When reading debug info generated by older versions of rustc, we
530 have to rewrite some union types to be struct types with a
531 variant part. This rewriting must be done after the CU is fully
532 read in, because otherwise at the point of rewriting some struct
533 type might not have been fully processed. So, we keep a list of
534 all such types here and process them after expansion. */
535 std::vector
<struct type
*> rust_unions
;
537 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
538 files, the value is implicitly zero. For DWARF 5 version DWO files, the
539 value is often implicit and is the size of the header of
540 .debug_str_offsets section (8 or 4, depending on the address size). */
541 gdb::optional
<ULONGEST
> str_offsets_base
;
543 /* Mark used when releasing cached dies. */
546 /* This CU references .debug_loc. See the symtab->locations_valid field.
547 This test is imperfect as there may exist optimized debug code not using
548 any location list and still facing inlining issues if handled as
549 unoptimized code. For a future better test see GCC PR other/32998. */
550 bool has_loclist
: 1;
552 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
553 if all the producer_is_* fields are valid. This information is cached
554 because profiling CU expansion showed excessive time spent in
555 producer_is_gxx_lt_4_6. */
556 bool checked_producer
: 1;
557 bool producer_is_gxx_lt_4_6
: 1;
558 bool producer_is_gcc_lt_4_3
: 1;
559 bool producer_is_icc
: 1;
560 bool producer_is_icc_lt_14
: 1;
561 bool producer_is_codewarrior
: 1;
563 /* When true, the file that we're processing is known to have
564 debugging info for C++ namespaces. GCC 3.3.x did not produce
565 this information, but later versions do. */
567 bool processing_has_namespace_info
: 1;
569 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
571 /* If this CU was inherited by another CU (via specification,
572 abstract_origin, etc), this is the ancestor CU. */
575 /* Get the buildsym_compunit for this CU. */
576 buildsym_compunit
*get_builder ()
578 /* If this CU has a builder associated with it, use that. */
579 if (m_builder
!= nullptr)
580 return m_builder
.get ();
582 /* Otherwise, search ancestors for a valid builder. */
583 if (ancestor
!= nullptr)
584 return ancestor
->get_builder ();
590 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
591 This includes type_unit_group and quick_file_names. */
593 struct stmt_list_hash
595 /* The DWO unit this table is from or NULL if there is none. */
596 struct dwo_unit
*dwo_unit
;
598 /* Offset in .debug_line or .debug_line.dwo. */
599 sect_offset line_sect_off
;
602 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
603 an object of this type. */
605 struct type_unit_group
607 /* dwarf2read.c's main "handle" on a TU symtab.
608 To simplify things we create an artificial CU that "includes" all the
609 type units using this stmt_list so that the rest of the code still has
610 a "per_cu" handle on the symtab. */
611 struct dwarf2_per_cu_data per_cu
;
613 /* The TUs that share this DW_AT_stmt_list entry.
614 This is added to while parsing type units to build partial symtabs,
615 and is deleted afterwards and not used again. */
616 std::vector
<signatured_type
*> *tus
;
618 /* The compunit symtab.
619 Type units in a group needn't all be defined in the same source file,
620 so we create an essentially anonymous symtab as the compunit symtab. */
621 struct compunit_symtab
*compunit_symtab
;
623 /* The data used to construct the hash key. */
624 struct stmt_list_hash hash
;
626 /* The symbol tables for this TU (obtained from the files listed in
628 WARNING: The order of entries here must match the order of entries
629 in the line header. After the first TU using this type_unit_group, the
630 line header for the subsequent TUs is recreated from this. This is done
631 because we need to use the same symtabs for each TU using the same
632 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
633 there's no guarantee the line header doesn't have duplicate entries. */
634 struct symtab
**symtabs
;
637 /* These sections are what may appear in a (real or virtual) DWO file. */
641 struct dwarf2_section_info abbrev
;
642 struct dwarf2_section_info line
;
643 struct dwarf2_section_info loc
;
644 struct dwarf2_section_info loclists
;
645 struct dwarf2_section_info macinfo
;
646 struct dwarf2_section_info macro
;
647 struct dwarf2_section_info str
;
648 struct dwarf2_section_info str_offsets
;
649 /* In the case of a virtual DWO file, these two are unused. */
650 struct dwarf2_section_info info
;
651 std::vector
<dwarf2_section_info
> types
;
654 /* CUs/TUs in DWP/DWO files. */
658 /* Backlink to the containing struct dwo_file. */
659 struct dwo_file
*dwo_file
;
661 /* The "id" that distinguishes this CU/TU.
662 .debug_info calls this "dwo_id", .debug_types calls this "signature".
663 Since signatures came first, we stick with it for consistency. */
666 /* The section this CU/TU lives in, in the DWO file. */
667 struct dwarf2_section_info
*section
;
669 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
670 sect_offset sect_off
;
673 /* For types, offset in the type's DIE of the type defined by this TU. */
674 cu_offset type_offset_in_tu
;
677 /* include/dwarf2.h defines the DWP section codes.
678 It defines a max value but it doesn't define a min value, which we
679 use for error checking, so provide one. */
681 enum dwp_v2_section_ids
686 /* Data for one DWO file.
688 This includes virtual DWO files (a virtual DWO file is a DWO file as it
689 appears in a DWP file). DWP files don't really have DWO files per se -
690 comdat folding of types "loses" the DWO file they came from, and from
691 a high level view DWP files appear to contain a mass of random types.
692 However, to maintain consistency with the non-DWP case we pretend DWP
693 files contain virtual DWO files, and we assign each TU with one virtual
694 DWO file (generally based on the line and abbrev section offsets -
695 a heuristic that seems to work in practice). */
699 dwo_file () = default;
700 DISABLE_COPY_AND_ASSIGN (dwo_file
);
702 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
703 For virtual DWO files the name is constructed from the section offsets
704 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
705 from related CU+TUs. */
706 const char *dwo_name
= nullptr;
708 /* The DW_AT_comp_dir attribute. */
709 const char *comp_dir
= nullptr;
711 /* The bfd, when the file is open. Otherwise this is NULL.
712 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
713 gdb_bfd_ref_ptr dbfd
;
715 /* The sections that make up this DWO file.
716 Remember that for virtual DWO files in DWP V2, these are virtual
717 sections (for lack of a better name). */
718 struct dwo_sections sections
{};
720 /* The CUs in the file.
721 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
722 an extension to handle LLVM's Link Time Optimization output (where
723 multiple source files may be compiled into a single object/dwo pair). */
726 /* Table of TUs in the file.
727 Each element is a struct dwo_unit. */
731 /* These sections are what may appear in a DWP file. */
735 /* These are used by both DWP version 1 and 2. */
736 struct dwarf2_section_info str
;
737 struct dwarf2_section_info cu_index
;
738 struct dwarf2_section_info tu_index
;
740 /* These are only used by DWP version 2 files.
741 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
742 sections are referenced by section number, and are not recorded here.
743 In DWP version 2 there is at most one copy of all these sections, each
744 section being (effectively) comprised of the concatenation of all of the
745 individual sections that exist in the version 1 format.
746 To keep the code simple we treat each of these concatenated pieces as a
747 section itself (a virtual section?). */
748 struct dwarf2_section_info abbrev
;
749 struct dwarf2_section_info info
;
750 struct dwarf2_section_info line
;
751 struct dwarf2_section_info loc
;
752 struct dwarf2_section_info macinfo
;
753 struct dwarf2_section_info macro
;
754 struct dwarf2_section_info str_offsets
;
755 struct dwarf2_section_info types
;
758 /* These sections are what may appear in a virtual DWO file in DWP version 1.
759 A virtual DWO file is a DWO file as it appears in a DWP file. */
761 struct virtual_v1_dwo_sections
763 struct dwarf2_section_info abbrev
;
764 struct dwarf2_section_info line
;
765 struct dwarf2_section_info loc
;
766 struct dwarf2_section_info macinfo
;
767 struct dwarf2_section_info macro
;
768 struct dwarf2_section_info str_offsets
;
769 /* Each DWP hash table entry records one CU or one TU.
770 That is recorded here, and copied to dwo_unit.section. */
771 struct dwarf2_section_info info_or_types
;
774 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
775 In version 2, the sections of the DWO files are concatenated together
776 and stored in one section of that name. Thus each ELF section contains
777 several "virtual" sections. */
779 struct virtual_v2_dwo_sections
781 bfd_size_type abbrev_offset
;
782 bfd_size_type abbrev_size
;
784 bfd_size_type line_offset
;
785 bfd_size_type line_size
;
787 bfd_size_type loc_offset
;
788 bfd_size_type loc_size
;
790 bfd_size_type macinfo_offset
;
791 bfd_size_type macinfo_size
;
793 bfd_size_type macro_offset
;
794 bfd_size_type macro_size
;
796 bfd_size_type str_offsets_offset
;
797 bfd_size_type str_offsets_size
;
799 /* Each DWP hash table entry records one CU or one TU.
800 That is recorded here, and copied to dwo_unit.section. */
801 bfd_size_type info_or_types_offset
;
802 bfd_size_type info_or_types_size
;
805 /* Contents of DWP hash tables. */
807 struct dwp_hash_table
809 uint32_t version
, nr_columns
;
810 uint32_t nr_units
, nr_slots
;
811 const gdb_byte
*hash_table
, *unit_table
;
816 const gdb_byte
*indices
;
820 /* This is indexed by column number and gives the id of the section
822 #define MAX_NR_V2_DWO_SECTIONS \
823 (1 /* .debug_info or .debug_types */ \
824 + 1 /* .debug_abbrev */ \
825 + 1 /* .debug_line */ \
826 + 1 /* .debug_loc */ \
827 + 1 /* .debug_str_offsets */ \
828 + 1 /* .debug_macro or .debug_macinfo */)
829 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
830 const gdb_byte
*offsets
;
831 const gdb_byte
*sizes
;
836 /* Data for one DWP file. */
840 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
842 dbfd (std::move (abfd
))
846 /* Name of the file. */
849 /* File format version. */
853 gdb_bfd_ref_ptr dbfd
;
855 /* Section info for this file. */
856 struct dwp_sections sections
{};
858 /* Table of CUs in the file. */
859 const struct dwp_hash_table
*cus
= nullptr;
861 /* Table of TUs in the file. */
862 const struct dwp_hash_table
*tus
= nullptr;
864 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
868 /* Table to map ELF section numbers to their sections.
869 This is only needed for the DWP V1 file format. */
870 unsigned int num_sections
= 0;
871 asection
**elf_sections
= nullptr;
874 /* Struct used to pass misc. parameters to read_die_and_children, et
875 al. which are used for both .debug_info and .debug_types dies.
876 All parameters here are unchanging for the life of the call. This
877 struct exists to abstract away the constant parameters of die reading. */
879 struct die_reader_specs
881 /* The bfd of die_section. */
884 /* The CU of the DIE we are parsing. */
885 struct dwarf2_cu
*cu
;
887 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
888 struct dwo_file
*dwo_file
;
890 /* The section the die comes from.
891 This is either .debug_info or .debug_types, or the .dwo variants. */
892 struct dwarf2_section_info
*die_section
;
894 /* die_section->buffer. */
895 const gdb_byte
*buffer
;
897 /* The end of the buffer. */
898 const gdb_byte
*buffer_end
;
900 /* The abbreviation table to use when reading the DIEs. */
901 struct abbrev_table
*abbrev_table
;
904 /* A subclass of die_reader_specs that holds storage and has complex
905 constructor and destructor behavior. */
907 class cutu_reader
: public die_reader_specs
911 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
912 struct abbrev_table
*abbrev_table
,
916 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
917 struct dwarf2_cu
*parent_cu
= nullptr,
918 struct dwo_file
*dwo_file
= nullptr);
920 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
922 const gdb_byte
*info_ptr
= nullptr;
923 struct die_info
*comp_unit_die
= nullptr;
924 bool dummy_p
= false;
926 /* Release the new CU, putting it on the chain. This cannot be done
931 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
932 int use_existing_cu
);
934 struct dwarf2_per_cu_data
*m_this_cu
;
935 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
937 /* The ordinary abbreviation table. */
938 abbrev_table_up m_abbrev_table_holder
;
940 /* The DWO abbreviation table. */
941 abbrev_table_up m_dwo_abbrev_table
;
944 /* When we construct a partial symbol table entry we only
945 need this much information. */
946 struct partial_die_info
: public allocate_on_obstack
948 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
950 /* Disable assign but still keep copy ctor, which is needed
951 load_partial_dies. */
952 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
954 /* Adjust the partial die before generating a symbol for it. This
955 function may set the is_external flag or change the DIE's
957 void fixup (struct dwarf2_cu
*cu
);
959 /* Read a minimal amount of information into the minimal die
961 const gdb_byte
*read (const struct die_reader_specs
*reader
,
962 const struct abbrev_info
&abbrev
,
963 const gdb_byte
*info_ptr
);
965 /* Offset of this DIE. */
966 const sect_offset sect_off
;
968 /* DWARF-2 tag for this DIE. */
969 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
971 /* Assorted flags describing the data found in this DIE. */
972 const unsigned int has_children
: 1;
974 unsigned int is_external
: 1;
975 unsigned int is_declaration
: 1;
976 unsigned int has_type
: 1;
977 unsigned int has_specification
: 1;
978 unsigned int has_pc_info
: 1;
979 unsigned int may_be_inlined
: 1;
981 /* This DIE has been marked DW_AT_main_subprogram. */
982 unsigned int main_subprogram
: 1;
984 /* Flag set if the SCOPE field of this structure has been
986 unsigned int scope_set
: 1;
988 /* Flag set if the DIE has a byte_size attribute. */
989 unsigned int has_byte_size
: 1;
991 /* Flag set if the DIE has a DW_AT_const_value attribute. */
992 unsigned int has_const_value
: 1;
994 /* Flag set if any of the DIE's children are template arguments. */
995 unsigned int has_template_arguments
: 1;
997 /* Flag set if fixup has been called on this die. */
998 unsigned int fixup_called
: 1;
1000 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1001 unsigned int is_dwz
: 1;
1003 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1004 unsigned int spec_is_dwz
: 1;
1006 /* The name of this DIE. Normally the value of DW_AT_name, but
1007 sometimes a default name for unnamed DIEs. */
1008 const char *name
= nullptr;
1010 /* The linkage name, if present. */
1011 const char *linkage_name
= nullptr;
1013 /* The scope to prepend to our children. This is generally
1014 allocated on the comp_unit_obstack, so will disappear
1015 when this compilation unit leaves the cache. */
1016 const char *scope
= nullptr;
1018 /* Some data associated with the partial DIE. The tag determines
1019 which field is live. */
1022 /* The location description associated with this DIE, if any. */
1023 struct dwarf_block
*locdesc
;
1024 /* The offset of an import, for DW_TAG_imported_unit. */
1025 sect_offset sect_off
;
1028 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1029 CORE_ADDR lowpc
= 0;
1030 CORE_ADDR highpc
= 0;
1032 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1033 DW_AT_sibling, if any. */
1034 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1035 could return DW_AT_sibling values to its caller load_partial_dies. */
1036 const gdb_byte
*sibling
= nullptr;
1038 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1039 DW_AT_specification (or DW_AT_abstract_origin or
1040 DW_AT_extension). */
1041 sect_offset spec_offset
{};
1043 /* Pointers to this DIE's parent, first child, and next sibling,
1045 struct partial_die_info
*die_parent
= nullptr;
1046 struct partial_die_info
*die_child
= nullptr;
1047 struct partial_die_info
*die_sibling
= nullptr;
1049 friend struct partial_die_info
*
1050 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1053 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1054 partial_die_info (sect_offset sect_off
)
1055 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1059 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1061 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1066 has_specification
= 0;
1069 main_subprogram
= 0;
1072 has_const_value
= 0;
1073 has_template_arguments
= 0;
1080 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1081 but this would require a corresponding change in unpack_field_as_long
1083 static int bits_per_byte
= 8;
1085 struct variant_part_builder
;
1087 /* When reading a variant, we track a bit more information about the
1088 field, and store it in an object of this type. */
1090 struct variant_field
1092 int first_field
= -1;
1093 int last_field
= -1;
1095 /* A variant can contain other variant parts. */
1096 std::vector
<variant_part_builder
> variant_parts
;
1098 /* If we see a DW_TAG_variant, then this will be set if this is the
1100 bool default_branch
= false;
1101 /* If we see a DW_AT_discr_value, then this will be the discriminant
1103 ULONGEST discriminant_value
= 0;
1104 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1106 struct dwarf_block
*discr_list_data
= nullptr;
1109 /* This represents a DW_TAG_variant_part. */
1111 struct variant_part_builder
1113 /* The offset of the discriminant field. */
1114 sect_offset discriminant_offset
{};
1116 /* Variants that are direct children of this variant part. */
1117 std::vector
<variant_field
> variants
;
1119 /* True if we're currently reading a variant. */
1120 bool processing_variant
= false;
1125 int accessibility
= 0;
1127 /* Variant parts need to find the discriminant, which is a DIE
1128 reference. We track the section offset of each field to make
1131 struct field field
{};
1136 const char *name
= nullptr;
1137 std::vector
<struct fn_field
> fnfields
;
1140 /* The routines that read and process dies for a C struct or C++ class
1141 pass lists of data member fields and lists of member function fields
1142 in an instance of a field_info structure, as defined below. */
1145 /* List of data member and baseclasses fields. */
1146 std::vector
<struct nextfield
> fields
;
1147 std::vector
<struct nextfield
> baseclasses
;
1149 /* Set if the accessibility of one of the fields is not public. */
1150 int non_public_fields
= 0;
1152 /* Member function fieldlist array, contains name of possibly overloaded
1153 member function, number of overloaded member functions and a pointer
1154 to the head of the member function field chain. */
1155 std::vector
<struct fnfieldlist
> fnfieldlists
;
1157 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1158 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1159 std::vector
<struct decl_field
> typedef_field_list
;
1161 /* Nested types defined by this class and the number of elements in this
1163 std::vector
<struct decl_field
> nested_types_list
;
1165 /* If non-null, this is the variant part we are currently
1167 variant_part_builder
*current_variant_part
= nullptr;
1168 /* This holds all the top-level variant parts attached to the type
1170 std::vector
<variant_part_builder
> variant_parts
;
1172 /* Return the total number of fields (including baseclasses). */
1173 int nfields () const
1175 return fields
.size () + baseclasses
.size ();
1179 /* Loaded secondary compilation units are kept in memory until they
1180 have not been referenced for the processing of this many
1181 compilation units. Set this to zero to disable caching. Cache
1182 sizes of up to at least twenty will improve startup time for
1183 typical inter-CU-reference binaries, at an obvious memory cost. */
1184 static int dwarf_max_cache_age
= 5;
1186 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1187 struct cmd_list_element
*c
, const char *value
)
1189 fprintf_filtered (file
, _("The upper bound on the age of cached "
1190 "DWARF compilation units is %s.\n"),
1194 /* local function prototypes */
1196 static void dwarf2_find_base_address (struct die_info
*die
,
1197 struct dwarf2_cu
*cu
);
1199 static dwarf2_psymtab
*create_partial_symtab
1200 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1202 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1203 const gdb_byte
*info_ptr
,
1204 struct die_info
*type_unit_die
);
1206 static void dwarf2_build_psymtabs_hard
1207 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1209 static void scan_partial_symbols (struct partial_die_info
*,
1210 CORE_ADDR
*, CORE_ADDR
*,
1211 int, struct dwarf2_cu
*);
1213 static void add_partial_symbol (struct partial_die_info
*,
1214 struct dwarf2_cu
*);
1216 static void add_partial_namespace (struct partial_die_info
*pdi
,
1217 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1218 int set_addrmap
, struct dwarf2_cu
*cu
);
1220 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1221 CORE_ADDR
*highpc
, int set_addrmap
,
1222 struct dwarf2_cu
*cu
);
1224 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1225 struct dwarf2_cu
*cu
);
1227 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1228 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1229 int need_pc
, struct dwarf2_cu
*cu
);
1231 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1233 static struct partial_die_info
*load_partial_dies
1234 (const struct die_reader_specs
*, const gdb_byte
*, int);
1236 /* A pair of partial_die_info and compilation unit. */
1237 struct cu_partial_die_info
1239 /* The compilation unit of the partial_die_info. */
1240 struct dwarf2_cu
*cu
;
1241 /* A partial_die_info. */
1242 struct partial_die_info
*pdi
;
1244 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1250 cu_partial_die_info () = delete;
1253 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1254 struct dwarf2_cu
*);
1256 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1257 struct attribute
*, struct attr_abbrev
*,
1258 const gdb_byte
*, bool *need_reprocess
);
1260 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1261 struct attribute
*attr
);
1263 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1265 static sect_offset read_abbrev_offset
1266 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1267 struct dwarf2_section_info
*, sect_offset
);
1269 static const char *read_indirect_string
1270 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1271 const struct comp_unit_head
*, unsigned int *);
1273 static const char *read_indirect_string_at_offset
1274 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1276 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1280 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1281 ULONGEST str_index
);
1283 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1284 ULONGEST str_index
);
1286 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1288 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1289 struct dwarf2_cu
*);
1291 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1292 struct dwarf2_cu
*cu
);
1294 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1296 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1297 struct dwarf2_cu
*cu
);
1299 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1301 static struct die_info
*die_specification (struct die_info
*die
,
1302 struct dwarf2_cu
**);
1304 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1305 struct dwarf2_cu
*cu
);
1307 static void dwarf_decode_lines (struct line_header
*, const char *,
1308 struct dwarf2_cu
*, dwarf2_psymtab
*,
1309 CORE_ADDR
, int decode_mapping
);
1311 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1314 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1315 struct dwarf2_cu
*, struct symbol
* = NULL
);
1317 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1318 struct dwarf2_cu
*);
1320 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1323 struct obstack
*obstack
,
1324 struct dwarf2_cu
*cu
, LONGEST
*value
,
1325 const gdb_byte
**bytes
,
1326 struct dwarf2_locexpr_baton
**baton
);
1328 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1330 static int need_gnat_info (struct dwarf2_cu
*);
1332 static struct type
*die_descriptive_type (struct die_info
*,
1333 struct dwarf2_cu
*);
1335 static void set_descriptive_type (struct type
*, struct die_info
*,
1336 struct dwarf2_cu
*);
1338 static struct type
*die_containing_type (struct die_info
*,
1339 struct dwarf2_cu
*);
1341 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1342 struct dwarf2_cu
*);
1344 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1346 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1348 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1350 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1351 const char *suffix
, int physname
,
1352 struct dwarf2_cu
*cu
);
1354 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1356 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1358 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1360 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1362 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1364 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1366 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1367 struct dwarf2_cu
*, dwarf2_psymtab
*);
1369 /* Return the .debug_loclists section to use for cu. */
1370 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1372 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1373 values. Keep the items ordered with increasing constraints compliance. */
1376 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1377 PC_BOUNDS_NOT_PRESENT
,
1379 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1380 were present but they do not form a valid range of PC addresses. */
1383 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1386 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1390 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1391 CORE_ADDR
*, CORE_ADDR
*,
1395 static void get_scope_pc_bounds (struct die_info
*,
1396 CORE_ADDR
*, CORE_ADDR
*,
1397 struct dwarf2_cu
*);
1399 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1400 CORE_ADDR
, struct dwarf2_cu
*);
1402 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1403 struct dwarf2_cu
*);
1405 static void dwarf2_attach_fields_to_type (struct field_info
*,
1406 struct type
*, struct dwarf2_cu
*);
1408 static void dwarf2_add_member_fn (struct field_info
*,
1409 struct die_info
*, struct type
*,
1410 struct dwarf2_cu
*);
1412 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1414 struct dwarf2_cu
*);
1416 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1418 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1420 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1422 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1424 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1426 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1428 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1430 static struct type
*read_module_type (struct die_info
*die
,
1431 struct dwarf2_cu
*cu
);
1433 static const char *namespace_name (struct die_info
*die
,
1434 int *is_anonymous
, struct dwarf2_cu
*);
1436 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1438 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1441 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1442 struct dwarf2_cu
*);
1444 static struct die_info
*read_die_and_siblings_1
1445 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1448 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1449 const gdb_byte
*info_ptr
,
1450 const gdb_byte
**new_info_ptr
,
1451 struct die_info
*parent
);
1453 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1454 struct die_info
**, const gdb_byte
*,
1457 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1458 struct die_info
**, const gdb_byte
*);
1460 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1462 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1465 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1467 static const char *dwarf2_full_name (const char *name
,
1468 struct die_info
*die
,
1469 struct dwarf2_cu
*cu
);
1471 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1472 struct dwarf2_cu
*cu
);
1474 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1475 struct dwarf2_cu
**);
1477 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1479 static void dump_die_for_error (struct die_info
*);
1481 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1484 /*static*/ void dump_die (struct die_info
*, int max_level
);
1486 static void store_in_ref_table (struct die_info
*,
1487 struct dwarf2_cu
*);
1489 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1490 const struct attribute
*,
1491 struct dwarf2_cu
**);
1493 static struct die_info
*follow_die_ref (struct die_info
*,
1494 const struct attribute
*,
1495 struct dwarf2_cu
**);
1497 static struct die_info
*follow_die_sig (struct die_info
*,
1498 const struct attribute
*,
1499 struct dwarf2_cu
**);
1501 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1502 struct dwarf2_cu
*);
1504 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1505 const struct attribute
*,
1506 struct dwarf2_cu
*);
1508 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1510 static void read_signatured_type (struct signatured_type
*);
1512 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1513 struct die_info
*die
, struct dwarf2_cu
*cu
,
1514 struct dynamic_prop
*prop
, struct type
*type
);
1516 /* memory allocation interface */
1518 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1520 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1522 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1524 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1525 struct dwarf2_loclist_baton
*baton
,
1526 const struct attribute
*attr
);
1528 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1530 struct dwarf2_cu
*cu
,
1533 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1534 const gdb_byte
*info_ptr
,
1535 struct abbrev_info
*abbrev
);
1537 static hashval_t
partial_die_hash (const void *item
);
1539 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1541 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1542 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1543 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1545 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1546 struct die_info
*comp_unit_die
,
1547 enum language pretend_language
);
1549 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1551 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1553 static struct type
*set_die_type (struct die_info
*, struct type
*,
1554 struct dwarf2_cu
*);
1556 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1558 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1560 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1563 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1566 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1569 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1570 struct dwarf2_per_cu_data
*);
1572 static void dwarf2_mark (struct dwarf2_cu
*);
1574 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1576 static struct type
*get_die_type_at_offset (sect_offset
,
1577 struct dwarf2_per_cu_data
*);
1579 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1581 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1582 enum language pretend_language
);
1584 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1586 /* Class, the destructor of which frees all allocated queue entries. This
1587 will only have work to do if an error was thrown while processing the
1588 dwarf. If no error was thrown then the queue entries should have all
1589 been processed, and freed, as we went along. */
1591 class dwarf2_queue_guard
1594 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1595 : m_per_objfile (per_objfile
)
1599 /* Free any entries remaining on the queue. There should only be
1600 entries left if we hit an error while processing the dwarf. */
1601 ~dwarf2_queue_guard ()
1603 /* Ensure that no memory is allocated by the queue. */
1604 std::queue
<dwarf2_queue_item
> empty
;
1605 std::swap (m_per_objfile
->queue
, empty
);
1608 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1611 dwarf2_per_objfile
*m_per_objfile
;
1614 dwarf2_queue_item::~dwarf2_queue_item ()
1616 /* Anything still marked queued is likely to be in an
1617 inconsistent state, so discard it. */
1620 if (per_cu
->cu
!= NULL
)
1621 free_one_cached_comp_unit (per_cu
);
1626 /* The return type of find_file_and_directory. Note, the enclosed
1627 string pointers are only valid while this object is valid. */
1629 struct file_and_directory
1631 /* The filename. This is never NULL. */
1634 /* The compilation directory. NULL if not known. If we needed to
1635 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1636 points directly to the DW_AT_comp_dir string attribute owned by
1637 the obstack that owns the DIE. */
1638 const char *comp_dir
;
1640 /* If we needed to build a new string for comp_dir, this is what
1641 owns the storage. */
1642 std::string comp_dir_storage
;
1645 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1646 struct dwarf2_cu
*cu
);
1648 static htab_up
allocate_signatured_type_table ();
1650 static htab_up
allocate_dwo_unit_table ();
1652 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1653 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1654 struct dwp_file
*dwp_file
, const char *comp_dir
,
1655 ULONGEST signature
, int is_debug_types
);
1657 static struct dwp_file
*get_dwp_file
1658 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1660 static struct dwo_unit
*lookup_dwo_comp_unit
1661 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1663 static struct dwo_unit
*lookup_dwo_type_unit
1664 (struct signatured_type
*, const char *, const char *);
1666 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1668 /* A unique pointer to a dwo_file. */
1670 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1672 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1674 static void check_producer (struct dwarf2_cu
*cu
);
1676 static void free_line_header_voidp (void *arg
);
1678 /* Various complaints about symbol reading that don't abort the process. */
1681 dwarf2_debug_line_missing_file_complaint (void)
1683 complaint (_(".debug_line section has line data without a file"));
1687 dwarf2_debug_line_missing_end_sequence_complaint (void)
1689 complaint (_(".debug_line section has line "
1690 "program sequence without an end"));
1694 dwarf2_complex_location_expr_complaint (void)
1696 complaint (_("location expression too complex"));
1700 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1703 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1708 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1710 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1714 /* Hash function for line_header_hash. */
1717 line_header_hash (const struct line_header
*ofs
)
1719 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1722 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1725 line_header_hash_voidp (const void *item
)
1727 const struct line_header
*ofs
= (const struct line_header
*) item
;
1729 return line_header_hash (ofs
);
1732 /* Equality function for line_header_hash. */
1735 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1737 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1738 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1740 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1741 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1746 /* See declaration. */
1748 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1749 const dwarf2_debug_sections
*names
,
1751 : objfile (objfile_
),
1752 can_copy (can_copy_
)
1755 names
= &dwarf2_elf_names
;
1757 bfd
*obfd
= objfile
->obfd
;
1759 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1760 locate_sections (obfd
, sec
, *names
);
1763 dwarf2_per_objfile::~dwarf2_per_objfile ()
1765 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1766 free_cached_comp_units ();
1768 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1769 per_cu
->imported_symtabs_free ();
1771 for (signatured_type
*sig_type
: all_type_units
)
1772 sig_type
->per_cu
.imported_symtabs_free ();
1774 /* Everything else should be on the objfile obstack. */
1777 /* See declaration. */
1780 dwarf2_per_objfile::free_cached_comp_units ()
1782 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1783 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1784 while (per_cu
!= NULL
)
1786 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1789 *last_chain
= next_cu
;
1794 /* A helper class that calls free_cached_comp_units on
1797 class free_cached_comp_units
1801 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1802 : m_per_objfile (per_objfile
)
1806 ~free_cached_comp_units ()
1808 m_per_objfile
->free_cached_comp_units ();
1811 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1815 dwarf2_per_objfile
*m_per_objfile
;
1818 /* Try to locate the sections we need for DWARF 2 debugging
1819 information and return true if we have enough to do something.
1820 NAMES points to the dwarf2 section names, or is NULL if the standard
1821 ELF names are used. CAN_COPY is true for formats where symbol
1822 interposition is possible and so symbol values must follow copy
1823 relocation rules. */
1826 dwarf2_has_info (struct objfile
*objfile
,
1827 const struct dwarf2_debug_sections
*names
,
1830 if (objfile
->flags
& OBJF_READNEVER
)
1833 struct dwarf2_per_objfile
*dwarf2_per_objfile
1834 = get_dwarf2_per_objfile (objfile
);
1836 if (dwarf2_per_objfile
== NULL
)
1837 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1841 return (!dwarf2_per_objfile
->info
.is_virtual
1842 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1843 && !dwarf2_per_objfile
->abbrev
.is_virtual
1844 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1847 /* When loading sections, we look either for uncompressed section or for
1848 compressed section names. */
1851 section_is_p (const char *section_name
,
1852 const struct dwarf2_section_names
*names
)
1854 if (names
->normal
!= NULL
1855 && strcmp (section_name
, names
->normal
) == 0)
1857 if (names
->compressed
!= NULL
1858 && strcmp (section_name
, names
->compressed
) == 0)
1863 /* See declaration. */
1866 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1867 const dwarf2_debug_sections
&names
)
1869 flagword aflag
= bfd_section_flags (sectp
);
1871 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1874 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1875 > bfd_get_file_size (abfd
))
1877 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1878 warning (_("Discarding section %s which has a section size (%s"
1879 ") larger than the file size [in module %s]"),
1880 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1881 bfd_get_filename (abfd
));
1883 else if (section_is_p (sectp
->name
, &names
.info
))
1885 this->info
.s
.section
= sectp
;
1886 this->info
.size
= bfd_section_size (sectp
);
1888 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1890 this->abbrev
.s
.section
= sectp
;
1891 this->abbrev
.size
= bfd_section_size (sectp
);
1893 else if (section_is_p (sectp
->name
, &names
.line
))
1895 this->line
.s
.section
= sectp
;
1896 this->line
.size
= bfd_section_size (sectp
);
1898 else if (section_is_p (sectp
->name
, &names
.loc
))
1900 this->loc
.s
.section
= sectp
;
1901 this->loc
.size
= bfd_section_size (sectp
);
1903 else if (section_is_p (sectp
->name
, &names
.loclists
))
1905 this->loclists
.s
.section
= sectp
;
1906 this->loclists
.size
= bfd_section_size (sectp
);
1908 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1910 this->macinfo
.s
.section
= sectp
;
1911 this->macinfo
.size
= bfd_section_size (sectp
);
1913 else if (section_is_p (sectp
->name
, &names
.macro
))
1915 this->macro
.s
.section
= sectp
;
1916 this->macro
.size
= bfd_section_size (sectp
);
1918 else if (section_is_p (sectp
->name
, &names
.str
))
1920 this->str
.s
.section
= sectp
;
1921 this->str
.size
= bfd_section_size (sectp
);
1923 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1925 this->str_offsets
.s
.section
= sectp
;
1926 this->str_offsets
.size
= bfd_section_size (sectp
);
1928 else if (section_is_p (sectp
->name
, &names
.line_str
))
1930 this->line_str
.s
.section
= sectp
;
1931 this->line_str
.size
= bfd_section_size (sectp
);
1933 else if (section_is_p (sectp
->name
, &names
.addr
))
1935 this->addr
.s
.section
= sectp
;
1936 this->addr
.size
= bfd_section_size (sectp
);
1938 else if (section_is_p (sectp
->name
, &names
.frame
))
1940 this->frame
.s
.section
= sectp
;
1941 this->frame
.size
= bfd_section_size (sectp
);
1943 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1945 this->eh_frame
.s
.section
= sectp
;
1946 this->eh_frame
.size
= bfd_section_size (sectp
);
1948 else if (section_is_p (sectp
->name
, &names
.ranges
))
1950 this->ranges
.s
.section
= sectp
;
1951 this->ranges
.size
= bfd_section_size (sectp
);
1953 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1955 this->rnglists
.s
.section
= sectp
;
1956 this->rnglists
.size
= bfd_section_size (sectp
);
1958 else if (section_is_p (sectp
->name
, &names
.types
))
1960 struct dwarf2_section_info type_section
;
1962 memset (&type_section
, 0, sizeof (type_section
));
1963 type_section
.s
.section
= sectp
;
1964 type_section
.size
= bfd_section_size (sectp
);
1966 this->types
.push_back (type_section
);
1968 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1970 this->gdb_index
.s
.section
= sectp
;
1971 this->gdb_index
.size
= bfd_section_size (sectp
);
1973 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1975 this->debug_names
.s
.section
= sectp
;
1976 this->debug_names
.size
= bfd_section_size (sectp
);
1978 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1980 this->debug_aranges
.s
.section
= sectp
;
1981 this->debug_aranges
.size
= bfd_section_size (sectp
);
1984 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1985 && bfd_section_vma (sectp
) == 0)
1986 this->has_section_at_zero
= true;
1989 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1993 dwarf2_get_section_info (struct objfile
*objfile
,
1994 enum dwarf2_section_enum sect
,
1995 asection
**sectp
, const gdb_byte
**bufp
,
1996 bfd_size_type
*sizep
)
1998 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
1999 struct dwarf2_section_info
*info
;
2001 /* We may see an objfile without any DWARF, in which case we just
2012 case DWARF2_DEBUG_FRAME
:
2013 info
= &data
->frame
;
2015 case DWARF2_EH_FRAME
:
2016 info
= &data
->eh_frame
;
2019 gdb_assert_not_reached ("unexpected section");
2022 info
->read (objfile
);
2024 *sectp
= info
->get_bfd_section ();
2025 *bufp
= info
->buffer
;
2026 *sizep
= info
->size
;
2029 /* A helper function to find the sections for a .dwz file. */
2032 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2034 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2036 /* Note that we only support the standard ELF names, because .dwz
2037 is ELF-only (at the time of writing). */
2038 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2040 dwz_file
->abbrev
.s
.section
= sectp
;
2041 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2043 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2045 dwz_file
->info
.s
.section
= sectp
;
2046 dwz_file
->info
.size
= bfd_section_size (sectp
);
2048 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2050 dwz_file
->str
.s
.section
= sectp
;
2051 dwz_file
->str
.size
= bfd_section_size (sectp
);
2053 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2055 dwz_file
->line
.s
.section
= sectp
;
2056 dwz_file
->line
.size
= bfd_section_size (sectp
);
2058 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2060 dwz_file
->macro
.s
.section
= sectp
;
2061 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2063 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2065 dwz_file
->gdb_index
.s
.section
= sectp
;
2066 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2068 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2070 dwz_file
->debug_names
.s
.section
= sectp
;
2071 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2075 /* See dwarf2read.h. */
2078 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2080 const char *filename
;
2081 bfd_size_type buildid_len_arg
;
2085 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2086 return dwarf2_per_objfile
->dwz_file
.get ();
2088 bfd_set_error (bfd_error_no_error
);
2089 gdb::unique_xmalloc_ptr
<char> data
2090 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2091 &buildid_len_arg
, &buildid
));
2094 if (bfd_get_error () == bfd_error_no_error
)
2096 error (_("could not read '.gnu_debugaltlink' section: %s"),
2097 bfd_errmsg (bfd_get_error ()));
2100 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2102 buildid_len
= (size_t) buildid_len_arg
;
2104 filename
= data
.get ();
2106 std::string abs_storage
;
2107 if (!IS_ABSOLUTE_PATH (filename
))
2109 gdb::unique_xmalloc_ptr
<char> abs
2110 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2112 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2113 filename
= abs_storage
.c_str ();
2116 /* First try the file name given in the section. If that doesn't
2117 work, try to use the build-id instead. */
2118 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2119 if (dwz_bfd
!= NULL
)
2121 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2122 dwz_bfd
.reset (nullptr);
2125 if (dwz_bfd
== NULL
)
2126 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2128 if (dwz_bfd
== nullptr)
2130 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2131 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2133 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2140 /* File successfully retrieved from server. */
2141 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2143 if (dwz_bfd
== nullptr)
2144 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2145 alt_filename
.get ());
2146 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2147 dwz_bfd
.reset (nullptr);
2151 if (dwz_bfd
== NULL
)
2152 error (_("could not find '.gnu_debugaltlink' file for %s"),
2153 objfile_name (dwarf2_per_objfile
->objfile
));
2155 std::unique_ptr
<struct dwz_file
> result
2156 (new struct dwz_file (std::move (dwz_bfd
)));
2158 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2161 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2162 result
->dwz_bfd
.get ());
2163 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2164 return dwarf2_per_objfile
->dwz_file
.get ();
2167 /* DWARF quick_symbols_functions support. */
2169 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2170 unique line tables, so we maintain a separate table of all .debug_line
2171 derived entries to support the sharing.
2172 All the quick functions need is the list of file names. We discard the
2173 line_header when we're done and don't need to record it here. */
2174 struct quick_file_names
2176 /* The data used to construct the hash key. */
2177 struct stmt_list_hash hash
;
2179 /* The number of entries in file_names, real_names. */
2180 unsigned int num_file_names
;
2182 /* The file names from the line table, after being run through
2184 const char **file_names
;
2186 /* The file names from the line table after being run through
2187 gdb_realpath. These are computed lazily. */
2188 const char **real_names
;
2191 /* When using the index (and thus not using psymtabs), each CU has an
2192 object of this type. This is used to hold information needed by
2193 the various "quick" methods. */
2194 struct dwarf2_per_cu_quick_data
2196 /* The file table. This can be NULL if there was no file table
2197 or it's currently not read in.
2198 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2199 struct quick_file_names
*file_names
;
2201 /* The corresponding symbol table. This is NULL if symbols for this
2202 CU have not yet been read. */
2203 struct compunit_symtab
*compunit_symtab
;
2205 /* A temporary mark bit used when iterating over all CUs in
2206 expand_symtabs_matching. */
2207 unsigned int mark
: 1;
2209 /* True if we've tried to read the file table and found there isn't one.
2210 There will be no point in trying to read it again next time. */
2211 unsigned int no_file_data
: 1;
2214 /* Utility hash function for a stmt_list_hash. */
2217 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2221 if (stmt_list_hash
->dwo_unit
!= NULL
)
2222 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2223 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2227 /* Utility equality function for a stmt_list_hash. */
2230 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2231 const struct stmt_list_hash
*rhs
)
2233 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2235 if (lhs
->dwo_unit
!= NULL
2236 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2239 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2242 /* Hash function for a quick_file_names. */
2245 hash_file_name_entry (const void *e
)
2247 const struct quick_file_names
*file_data
2248 = (const struct quick_file_names
*) e
;
2250 return hash_stmt_list_entry (&file_data
->hash
);
2253 /* Equality function for a quick_file_names. */
2256 eq_file_name_entry (const void *a
, const void *b
)
2258 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2259 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2261 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2264 /* Delete function for a quick_file_names. */
2267 delete_file_name_entry (void *e
)
2269 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2272 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2274 xfree ((void*) file_data
->file_names
[i
]);
2275 if (file_data
->real_names
)
2276 xfree ((void*) file_data
->real_names
[i
]);
2279 /* The space for the struct itself lives on objfile_obstack,
2280 so we don't free it here. */
2283 /* Create a quick_file_names hash table. */
2286 create_quick_file_names_table (unsigned int nr_initial_entries
)
2288 return htab_up (htab_create_alloc (nr_initial_entries
,
2289 hash_file_name_entry
, eq_file_name_entry
,
2290 delete_file_name_entry
, xcalloc
, xfree
));
2293 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2294 have to be created afterwards. You should call age_cached_comp_units after
2295 processing PER_CU->CU. dw2_setup must have been already called. */
2298 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2300 if (per_cu
->is_debug_types
)
2301 load_full_type_unit (per_cu
);
2303 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2305 if (per_cu
->cu
== NULL
)
2306 return; /* Dummy CU. */
2308 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2311 /* Read in the symbols for PER_CU. */
2314 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2316 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2318 /* Skip type_unit_groups, reading the type units they contain
2319 is handled elsewhere. */
2320 if (per_cu
->type_unit_group_p ())
2323 /* The destructor of dwarf2_queue_guard frees any entries left on
2324 the queue. After this point we're guaranteed to leave this function
2325 with the dwarf queue empty. */
2326 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2328 if (dwarf2_per_objfile
->using_index
2329 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2330 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2332 queue_comp_unit (per_cu
, language_minimal
);
2333 load_cu (per_cu
, skip_partial
);
2335 /* If we just loaded a CU from a DWO, and we're working with an index
2336 that may badly handle TUs, load all the TUs in that DWO as well.
2337 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2338 if (!per_cu
->is_debug_types
2339 && per_cu
->cu
!= NULL
2340 && per_cu
->cu
->dwo_unit
!= NULL
2341 && dwarf2_per_objfile
->index_table
!= NULL
2342 && dwarf2_per_objfile
->index_table
->version
<= 7
2343 /* DWP files aren't supported yet. */
2344 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2345 queue_and_load_all_dwo_tus (per_cu
);
2348 process_queue (dwarf2_per_objfile
);
2350 /* Age the cache, releasing compilation units that have not
2351 been used recently. */
2352 age_cached_comp_units (dwarf2_per_objfile
);
2355 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2356 the objfile from which this CU came. Returns the resulting symbol
2359 static struct compunit_symtab
*
2360 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2362 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2364 gdb_assert (dwarf2_per_objfile
->using_index
);
2365 if (!per_cu
->v
.quick
->compunit_symtab
)
2367 free_cached_comp_units
freer (dwarf2_per_objfile
);
2368 scoped_restore decrementer
= increment_reading_symtab ();
2369 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2370 process_cu_includes (dwarf2_per_objfile
);
2373 return per_cu
->v
.quick
->compunit_symtab
;
2376 /* See declaration. */
2378 dwarf2_per_cu_data
*
2379 dwarf2_per_objfile::get_cutu (int index
)
2381 if (index
>= this->all_comp_units
.size ())
2383 index
-= this->all_comp_units
.size ();
2384 gdb_assert (index
< this->all_type_units
.size ());
2385 return &this->all_type_units
[index
]->per_cu
;
2388 return this->all_comp_units
[index
];
2391 /* See declaration. */
2393 dwarf2_per_cu_data
*
2394 dwarf2_per_objfile::get_cu (int index
)
2396 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2398 return this->all_comp_units
[index
];
2401 /* See declaration. */
2404 dwarf2_per_objfile::get_tu (int index
)
2406 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2408 return this->all_type_units
[index
];
2411 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2412 objfile_obstack, and constructed with the specified field
2415 static dwarf2_per_cu_data
*
2416 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2417 struct dwarf2_section_info
*section
,
2419 sect_offset sect_off
, ULONGEST length
)
2421 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2422 dwarf2_per_cu_data
*the_cu
2423 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2424 struct dwarf2_per_cu_data
);
2425 the_cu
->sect_off
= sect_off
;
2426 the_cu
->length
= length
;
2427 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2428 the_cu
->section
= section
;
2429 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2430 struct dwarf2_per_cu_quick_data
);
2431 the_cu
->is_dwz
= is_dwz
;
2435 /* A helper for create_cus_from_index that handles a given list of
2439 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2440 const gdb_byte
*cu_list
, offset_type n_elements
,
2441 struct dwarf2_section_info
*section
,
2444 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2446 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2448 sect_offset sect_off
2449 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2450 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2453 dwarf2_per_cu_data
*per_cu
2454 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2456 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2460 /* Read the CU list from the mapped index, and use it to create all
2461 the CU objects for this objfile. */
2464 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2465 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2466 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2468 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2469 dwarf2_per_objfile
->all_comp_units
.reserve
2470 ((cu_list_elements
+ dwz_elements
) / 2);
2472 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2473 &dwarf2_per_objfile
->info
, 0);
2475 if (dwz_elements
== 0)
2478 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2479 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2483 /* Create the signatured type hash table from the index. */
2486 create_signatured_type_table_from_index
2487 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2488 struct dwarf2_section_info
*section
,
2489 const gdb_byte
*bytes
,
2490 offset_type elements
)
2492 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2494 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2495 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2497 htab_up sig_types_hash
= allocate_signatured_type_table ();
2499 for (offset_type i
= 0; i
< elements
; i
+= 3)
2501 struct signatured_type
*sig_type
;
2504 cu_offset type_offset_in_tu
;
2506 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2507 sect_offset sect_off
2508 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2510 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2512 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2515 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2516 struct signatured_type
);
2517 sig_type
->signature
= signature
;
2518 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2519 sig_type
->per_cu
.is_debug_types
= 1;
2520 sig_type
->per_cu
.section
= section
;
2521 sig_type
->per_cu
.sect_off
= sect_off
;
2522 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2523 sig_type
->per_cu
.v
.quick
2524 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2525 struct dwarf2_per_cu_quick_data
);
2527 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2530 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2533 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2536 /* Create the signatured type hash table from .debug_names. */
2539 create_signatured_type_table_from_debug_names
2540 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2541 const mapped_debug_names
&map
,
2542 struct dwarf2_section_info
*section
,
2543 struct dwarf2_section_info
*abbrev_section
)
2545 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2547 section
->read (objfile
);
2548 abbrev_section
->read (objfile
);
2550 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2551 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2553 htab_up sig_types_hash
= allocate_signatured_type_table ();
2555 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2557 struct signatured_type
*sig_type
;
2560 sect_offset sect_off
2561 = (sect_offset
) (extract_unsigned_integer
2562 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2564 map
.dwarf5_byte_order
));
2566 comp_unit_head cu_header
;
2567 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2569 section
->buffer
+ to_underlying (sect_off
),
2572 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2573 struct signatured_type
);
2574 sig_type
->signature
= cu_header
.signature
;
2575 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2576 sig_type
->per_cu
.is_debug_types
= 1;
2577 sig_type
->per_cu
.section
= section
;
2578 sig_type
->per_cu
.sect_off
= sect_off
;
2579 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2580 sig_type
->per_cu
.v
.quick
2581 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2582 struct dwarf2_per_cu_quick_data
);
2584 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2587 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2590 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2593 /* Read the address map data from the mapped index, and use it to
2594 populate the objfile's psymtabs_addrmap. */
2597 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2598 struct mapped_index
*index
)
2600 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2601 struct gdbarch
*gdbarch
= objfile
->arch ();
2602 const gdb_byte
*iter
, *end
;
2603 struct addrmap
*mutable_map
;
2606 auto_obstack temp_obstack
;
2608 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2610 iter
= index
->address_table
.data ();
2611 end
= iter
+ index
->address_table
.size ();
2613 baseaddr
= objfile
->text_section_offset ();
2617 ULONGEST hi
, lo
, cu_index
;
2618 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2620 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2622 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2627 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2628 hex_string (lo
), hex_string (hi
));
2632 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2634 complaint (_(".gdb_index address table has invalid CU number %u"),
2635 (unsigned) cu_index
);
2639 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2640 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2641 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2642 dwarf2_per_objfile
->get_cu (cu_index
));
2645 objfile
->partial_symtabs
->psymtabs_addrmap
2646 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2649 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2650 populate the objfile's psymtabs_addrmap. */
2653 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2654 struct dwarf2_section_info
*section
)
2656 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2657 bfd
*abfd
= objfile
->obfd
;
2658 struct gdbarch
*gdbarch
= objfile
->arch ();
2659 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2661 auto_obstack temp_obstack
;
2662 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2664 std::unordered_map
<sect_offset
,
2665 dwarf2_per_cu_data
*,
2666 gdb::hash_enum
<sect_offset
>>
2667 debug_info_offset_to_per_cu
;
2668 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2670 const auto insertpair
2671 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2672 if (!insertpair
.second
)
2674 warning (_("Section .debug_aranges in %s has duplicate "
2675 "debug_info_offset %s, ignoring .debug_aranges."),
2676 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2681 section
->read (objfile
);
2683 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2685 const gdb_byte
*addr
= section
->buffer
;
2687 while (addr
< section
->buffer
+ section
->size
)
2689 const gdb_byte
*const entry_addr
= addr
;
2690 unsigned int bytes_read
;
2692 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2696 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2697 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2698 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2699 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2701 warning (_("Section .debug_aranges in %s entry at offset %s "
2702 "length %s exceeds section length %s, "
2703 "ignoring .debug_aranges."),
2704 objfile_name (objfile
),
2705 plongest (entry_addr
- section
->buffer
),
2706 plongest (bytes_read
+ entry_length
),
2707 pulongest (section
->size
));
2711 /* The version number. */
2712 const uint16_t version
= read_2_bytes (abfd
, addr
);
2716 warning (_("Section .debug_aranges in %s entry at offset %s "
2717 "has unsupported version %d, ignoring .debug_aranges."),
2718 objfile_name (objfile
),
2719 plongest (entry_addr
- section
->buffer
), version
);
2723 const uint64_t debug_info_offset
2724 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2725 addr
+= offset_size
;
2726 const auto per_cu_it
2727 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2728 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2730 warning (_("Section .debug_aranges in %s entry at offset %s "
2731 "debug_info_offset %s does not exists, "
2732 "ignoring .debug_aranges."),
2733 objfile_name (objfile
),
2734 plongest (entry_addr
- section
->buffer
),
2735 pulongest (debug_info_offset
));
2738 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2740 const uint8_t address_size
= *addr
++;
2741 if (address_size
< 1 || address_size
> 8)
2743 warning (_("Section .debug_aranges in %s entry at offset %s "
2744 "address_size %u is invalid, ignoring .debug_aranges."),
2745 objfile_name (objfile
),
2746 plongest (entry_addr
- section
->buffer
), address_size
);
2750 const uint8_t segment_selector_size
= *addr
++;
2751 if (segment_selector_size
!= 0)
2753 warning (_("Section .debug_aranges in %s entry at offset %s "
2754 "segment_selector_size %u is not supported, "
2755 "ignoring .debug_aranges."),
2756 objfile_name (objfile
),
2757 plongest (entry_addr
- section
->buffer
),
2758 segment_selector_size
);
2762 /* Must pad to an alignment boundary that is twice the address
2763 size. It is undocumented by the DWARF standard but GCC does
2765 for (size_t padding
= ((-(addr
- section
->buffer
))
2766 & (2 * address_size
- 1));
2767 padding
> 0; padding
--)
2770 warning (_("Section .debug_aranges in %s entry at offset %s "
2771 "padding is not zero, ignoring .debug_aranges."),
2772 objfile_name (objfile
),
2773 plongest (entry_addr
- section
->buffer
));
2779 if (addr
+ 2 * address_size
> entry_end
)
2781 warning (_("Section .debug_aranges in %s entry at offset %s "
2782 "address list is not properly terminated, "
2783 "ignoring .debug_aranges."),
2784 objfile_name (objfile
),
2785 plongest (entry_addr
- section
->buffer
));
2788 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2790 addr
+= address_size
;
2791 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2793 addr
+= address_size
;
2794 if (start
== 0 && length
== 0)
2796 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2798 /* Symbol was eliminated due to a COMDAT group. */
2801 ULONGEST end
= start
+ length
;
2802 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2804 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2806 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2810 objfile
->partial_symtabs
->psymtabs_addrmap
2811 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2814 /* Find a slot in the mapped index INDEX for the object named NAME.
2815 If NAME is found, set *VEC_OUT to point to the CU vector in the
2816 constant pool and return true. If NAME cannot be found, return
2820 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2821 offset_type
**vec_out
)
2824 offset_type slot
, step
;
2825 int (*cmp
) (const char *, const char *);
2827 gdb::unique_xmalloc_ptr
<char> without_params
;
2828 if (current_language
->la_language
== language_cplus
2829 || current_language
->la_language
== language_fortran
2830 || current_language
->la_language
== language_d
)
2832 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2835 if (strchr (name
, '(') != NULL
)
2837 without_params
= cp_remove_params (name
);
2839 if (without_params
!= NULL
)
2840 name
= without_params
.get ();
2844 /* Index version 4 did not support case insensitive searches. But the
2845 indices for case insensitive languages are built in lowercase, therefore
2846 simulate our NAME being searched is also lowercased. */
2847 hash
= mapped_index_string_hash ((index
->version
== 4
2848 && case_sensitivity
== case_sensitive_off
2849 ? 5 : index
->version
),
2852 slot
= hash
& (index
->symbol_table
.size () - 1);
2853 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2854 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2860 const auto &bucket
= index
->symbol_table
[slot
];
2861 if (bucket
.name
== 0 && bucket
.vec
== 0)
2864 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2865 if (!cmp (name
, str
))
2867 *vec_out
= (offset_type
*) (index
->constant_pool
2868 + MAYBE_SWAP (bucket
.vec
));
2872 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2876 /* A helper function that reads the .gdb_index from BUFFER and fills
2877 in MAP. FILENAME is the name of the file containing the data;
2878 it is used for error reporting. DEPRECATED_OK is true if it is
2879 ok to use deprecated sections.
2881 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2882 out parameters that are filled in with information about the CU and
2883 TU lists in the section.
2885 Returns true if all went well, false otherwise. */
2888 read_gdb_index_from_buffer (const char *filename
,
2890 gdb::array_view
<const gdb_byte
> buffer
,
2891 struct mapped_index
*map
,
2892 const gdb_byte
**cu_list
,
2893 offset_type
*cu_list_elements
,
2894 const gdb_byte
**types_list
,
2895 offset_type
*types_list_elements
)
2897 const gdb_byte
*addr
= &buffer
[0];
2899 /* Version check. */
2900 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2901 /* Versions earlier than 3 emitted every copy of a psymbol. This
2902 causes the index to behave very poorly for certain requests. Version 3
2903 contained incomplete addrmap. So, it seems better to just ignore such
2907 static int warning_printed
= 0;
2908 if (!warning_printed
)
2910 warning (_("Skipping obsolete .gdb_index section in %s."),
2912 warning_printed
= 1;
2916 /* Index version 4 uses a different hash function than index version
2919 Versions earlier than 6 did not emit psymbols for inlined
2920 functions. Using these files will cause GDB not to be able to
2921 set breakpoints on inlined functions by name, so we ignore these
2922 indices unless the user has done
2923 "set use-deprecated-index-sections on". */
2924 if (version
< 6 && !deprecated_ok
)
2926 static int warning_printed
= 0;
2927 if (!warning_printed
)
2930 Skipping deprecated .gdb_index section in %s.\n\
2931 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2932 to use the section anyway."),
2934 warning_printed
= 1;
2938 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2939 of the TU (for symbols coming from TUs),
2940 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2941 Plus gold-generated indices can have duplicate entries for global symbols,
2942 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2943 These are just performance bugs, and we can't distinguish gdb-generated
2944 indices from gold-generated ones, so issue no warning here. */
2946 /* Indexes with higher version than the one supported by GDB may be no
2947 longer backward compatible. */
2951 map
->version
= version
;
2953 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2956 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2957 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2961 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2962 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2963 - MAYBE_SWAP (metadata
[i
]))
2967 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2968 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2970 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2973 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2974 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2976 = gdb::array_view
<mapped_index::symbol_table_slot
>
2977 ((mapped_index::symbol_table_slot
*) symbol_table
,
2978 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2981 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2986 /* Callback types for dwarf2_read_gdb_index. */
2988 typedef gdb::function_view
2989 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2990 get_gdb_index_contents_ftype
;
2991 typedef gdb::function_view
2992 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2993 get_gdb_index_contents_dwz_ftype
;
2995 /* Read .gdb_index. If everything went ok, initialize the "quick"
2996 elements of all the CUs and return 1. Otherwise, return 0. */
2999 dwarf2_read_gdb_index
3000 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3001 get_gdb_index_contents_ftype get_gdb_index_contents
,
3002 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3004 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3005 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3006 struct dwz_file
*dwz
;
3007 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3009 gdb::array_view
<const gdb_byte
> main_index_contents
3010 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3012 if (main_index_contents
.empty ())
3015 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3016 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3017 use_deprecated_index_sections
,
3018 main_index_contents
, map
.get (), &cu_list
,
3019 &cu_list_elements
, &types_list
,
3020 &types_list_elements
))
3023 /* Don't use the index if it's empty. */
3024 if (map
->symbol_table
.empty ())
3027 /* If there is a .dwz file, read it so we can get its CU list as
3029 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3032 struct mapped_index dwz_map
;
3033 const gdb_byte
*dwz_types_ignore
;
3034 offset_type dwz_types_elements_ignore
;
3036 gdb::array_view
<const gdb_byte
> dwz_index_content
3037 = get_gdb_index_contents_dwz (objfile
, dwz
);
3039 if (dwz_index_content
.empty ())
3042 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3043 1, dwz_index_content
, &dwz_map
,
3044 &dwz_list
, &dwz_list_elements
,
3046 &dwz_types_elements_ignore
))
3048 warning (_("could not read '.gdb_index' section from %s; skipping"),
3049 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3054 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3055 dwz_list
, dwz_list_elements
);
3057 if (types_list_elements
)
3059 /* We can only handle a single .debug_types when we have an
3061 if (dwarf2_per_objfile
->types
.size () != 1)
3064 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3066 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3067 types_list
, types_list_elements
);
3070 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3072 dwarf2_per_objfile
->index_table
= std::move (map
);
3073 dwarf2_per_objfile
->using_index
= 1;
3074 dwarf2_per_objfile
->quick_file_names_table
=
3075 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3080 /* die_reader_func for dw2_get_file_names. */
3083 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3084 const gdb_byte
*info_ptr
,
3085 struct die_info
*comp_unit_die
)
3087 struct dwarf2_cu
*cu
= reader
->cu
;
3088 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3089 struct dwarf2_per_objfile
*dwarf2_per_objfile
3090 = cu
->per_cu
->dwarf2_per_objfile
;
3091 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3092 struct dwarf2_per_cu_data
*lh_cu
;
3093 struct attribute
*attr
;
3095 struct quick_file_names
*qfn
;
3097 gdb_assert (! this_cu
->is_debug_types
);
3099 /* Our callers never want to match partial units -- instead they
3100 will match the enclosing full CU. */
3101 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3103 this_cu
->v
.quick
->no_file_data
= 1;
3111 sect_offset line_offset
{};
3113 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3114 if (attr
!= nullptr)
3116 struct quick_file_names find_entry
;
3118 line_offset
= (sect_offset
) DW_UNSND (attr
);
3120 /* We may have already read in this line header (TU line header sharing).
3121 If we have we're done. */
3122 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3123 find_entry
.hash
.line_sect_off
= line_offset
;
3124 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3125 &find_entry
, INSERT
);
3128 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3132 lh
= dwarf_decode_line_header (line_offset
, cu
);
3136 lh_cu
->v
.quick
->no_file_data
= 1;
3140 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3141 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3142 qfn
->hash
.line_sect_off
= line_offset
;
3143 gdb_assert (slot
!= NULL
);
3146 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3149 if (strcmp (fnd
.name
, "<unknown>") != 0)
3152 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3154 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3156 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3157 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3158 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3159 fnd
.comp_dir
).release ();
3160 qfn
->real_names
= NULL
;
3162 lh_cu
->v
.quick
->file_names
= qfn
;
3165 /* A helper for the "quick" functions which attempts to read the line
3166 table for THIS_CU. */
3168 static struct quick_file_names
*
3169 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3171 /* This should never be called for TUs. */
3172 gdb_assert (! this_cu
->is_debug_types
);
3173 /* Nor type unit groups. */
3174 gdb_assert (! this_cu
->type_unit_group_p ());
3176 if (this_cu
->v
.quick
->file_names
!= NULL
)
3177 return this_cu
->v
.quick
->file_names
;
3178 /* If we know there is no line data, no point in looking again. */
3179 if (this_cu
->v
.quick
->no_file_data
)
3182 cutu_reader
reader (this_cu
);
3183 if (!reader
.dummy_p
)
3184 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3186 if (this_cu
->v
.quick
->no_file_data
)
3188 return this_cu
->v
.quick
->file_names
;
3191 /* A helper for the "quick" functions which computes and caches the
3192 real path for a given file name from the line table. */
3195 dw2_get_real_path (struct objfile
*objfile
,
3196 struct quick_file_names
*qfn
, int index
)
3198 if (qfn
->real_names
== NULL
)
3199 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3200 qfn
->num_file_names
, const char *);
3202 if (qfn
->real_names
[index
] == NULL
)
3203 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3205 return qfn
->real_names
[index
];
3208 static struct symtab
*
3209 dw2_find_last_source_symtab (struct objfile
*objfile
)
3211 struct dwarf2_per_objfile
*dwarf2_per_objfile
3212 = get_dwarf2_per_objfile (objfile
);
3213 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3214 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3219 return compunit_primary_filetab (cust
);
3222 /* Traversal function for dw2_forget_cached_source_info. */
3225 dw2_free_cached_file_names (void **slot
, void *info
)
3227 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3229 if (file_data
->real_names
)
3233 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3235 xfree ((void*) file_data
->real_names
[i
]);
3236 file_data
->real_names
[i
] = NULL
;
3244 dw2_forget_cached_source_info (struct objfile
*objfile
)
3246 struct dwarf2_per_objfile
*dwarf2_per_objfile
3247 = get_dwarf2_per_objfile (objfile
);
3249 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3250 dw2_free_cached_file_names
, NULL
);
3253 /* Helper function for dw2_map_symtabs_matching_filename that expands
3254 the symtabs and calls the iterator. */
3257 dw2_map_expand_apply (struct objfile
*objfile
,
3258 struct dwarf2_per_cu_data
*per_cu
,
3259 const char *name
, const char *real_path
,
3260 gdb::function_view
<bool (symtab
*)> callback
)
3262 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3264 /* Don't visit already-expanded CUs. */
3265 if (per_cu
->v
.quick
->compunit_symtab
)
3268 /* This may expand more than one symtab, and we want to iterate over
3270 dw2_instantiate_symtab (per_cu
, false);
3272 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3273 last_made
, callback
);
3276 /* Implementation of the map_symtabs_matching_filename method. */
3279 dw2_map_symtabs_matching_filename
3280 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3281 gdb::function_view
<bool (symtab
*)> callback
)
3283 const char *name_basename
= lbasename (name
);
3284 struct dwarf2_per_objfile
*dwarf2_per_objfile
3285 = get_dwarf2_per_objfile (objfile
);
3287 /* The rule is CUs specify all the files, including those used by
3288 any TU, so there's no need to scan TUs here. */
3290 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3292 /* We only need to look at symtabs not already expanded. */
3293 if (per_cu
->v
.quick
->compunit_symtab
)
3296 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3297 if (file_data
== NULL
)
3300 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3302 const char *this_name
= file_data
->file_names
[j
];
3303 const char *this_real_name
;
3305 if (compare_filenames_for_search (this_name
, name
))
3307 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3313 /* Before we invoke realpath, which can get expensive when many
3314 files are involved, do a quick comparison of the basenames. */
3315 if (! basenames_may_differ
3316 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3319 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3320 if (compare_filenames_for_search (this_real_name
, name
))
3322 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3328 if (real_path
!= NULL
)
3330 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3331 gdb_assert (IS_ABSOLUTE_PATH (name
));
3332 if (this_real_name
!= NULL
3333 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3335 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3347 /* Struct used to manage iterating over all CUs looking for a symbol. */
3349 struct dw2_symtab_iterator
3351 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3352 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3353 /* If set, only look for symbols that match that block. Valid values are
3354 GLOBAL_BLOCK and STATIC_BLOCK. */
3355 gdb::optional
<block_enum
> block_index
;
3356 /* The kind of symbol we're looking for. */
3358 /* The list of CUs from the index entry of the symbol,
3359 or NULL if not found. */
3361 /* The next element in VEC to look at. */
3363 /* The number of elements in VEC, or zero if there is no match. */
3365 /* Have we seen a global version of the symbol?
3366 If so we can ignore all further global instances.
3367 This is to work around gold/15646, inefficient gold-generated
3372 /* Initialize the index symtab iterator ITER. */
3375 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3376 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3377 gdb::optional
<block_enum
> block_index
,
3381 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3382 iter
->block_index
= block_index
;
3383 iter
->domain
= domain
;
3385 iter
->global_seen
= 0;
3387 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3389 /* index is NULL if OBJF_READNOW. */
3390 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3391 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3399 /* Return the next matching CU or NULL if there are no more. */
3401 static struct dwarf2_per_cu_data
*
3402 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3404 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3406 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3408 offset_type cu_index_and_attrs
=
3409 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3410 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3411 gdb_index_symbol_kind symbol_kind
=
3412 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3413 /* Only check the symbol attributes if they're present.
3414 Indices prior to version 7 don't record them,
3415 and indices >= 7 may elide them for certain symbols
3416 (gold does this). */
3418 (dwarf2_per_objfile
->index_table
->version
>= 7
3419 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3421 /* Don't crash on bad data. */
3422 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3423 + dwarf2_per_objfile
->all_type_units
.size ()))
3425 complaint (_(".gdb_index entry has bad CU index"
3427 objfile_name (dwarf2_per_objfile
->objfile
));
3431 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3433 /* Skip if already read in. */
3434 if (per_cu
->v
.quick
->compunit_symtab
)
3437 /* Check static vs global. */
3440 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3442 if (iter
->block_index
.has_value ())
3444 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3446 if (is_static
!= want_static
)
3450 /* Work around gold/15646. */
3451 if (!is_static
&& iter
->global_seen
)
3454 iter
->global_seen
= 1;
3457 /* Only check the symbol's kind if it has one. */
3460 switch (iter
->domain
)
3463 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3464 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3465 /* Some types are also in VAR_DOMAIN. */
3466 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3470 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3474 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3478 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3493 static struct compunit_symtab
*
3494 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3495 const char *name
, domain_enum domain
)
3497 struct compunit_symtab
*stab_best
= NULL
;
3498 struct dwarf2_per_objfile
*dwarf2_per_objfile
3499 = get_dwarf2_per_objfile (objfile
);
3501 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3503 struct dw2_symtab_iterator iter
;
3504 struct dwarf2_per_cu_data
*per_cu
;
3506 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3508 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3510 struct symbol
*sym
, *with_opaque
= NULL
;
3511 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3512 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3513 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3515 sym
= block_find_symbol (block
, name
, domain
,
3516 block_find_non_opaque_type_preferred
,
3519 /* Some caution must be observed with overloaded functions
3520 and methods, since the index will not contain any overload
3521 information (but NAME might contain it). */
3524 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3526 if (with_opaque
!= NULL
3527 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3530 /* Keep looking through other CUs. */
3537 dw2_print_stats (struct objfile
*objfile
)
3539 struct dwarf2_per_objfile
*dwarf2_per_objfile
3540 = get_dwarf2_per_objfile (objfile
);
3541 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3542 + dwarf2_per_objfile
->all_type_units
.size ());
3545 for (int i
= 0; i
< total
; ++i
)
3547 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3549 if (!per_cu
->v
.quick
->compunit_symtab
)
3552 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3553 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3556 /* This dumps minimal information about the index.
3557 It is called via "mt print objfiles".
3558 One use is to verify .gdb_index has been loaded by the
3559 gdb.dwarf2/gdb-index.exp testcase. */
3562 dw2_dump (struct objfile
*objfile
)
3564 struct dwarf2_per_objfile
*dwarf2_per_objfile
3565 = get_dwarf2_per_objfile (objfile
);
3567 gdb_assert (dwarf2_per_objfile
->using_index
);
3568 printf_filtered (".gdb_index:");
3569 if (dwarf2_per_objfile
->index_table
!= NULL
)
3571 printf_filtered (" version %d\n",
3572 dwarf2_per_objfile
->index_table
->version
);
3575 printf_filtered (" faked for \"readnow\"\n");
3576 printf_filtered ("\n");
3580 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3581 const char *func_name
)
3583 struct dwarf2_per_objfile
*dwarf2_per_objfile
3584 = get_dwarf2_per_objfile (objfile
);
3586 struct dw2_symtab_iterator iter
;
3587 struct dwarf2_per_cu_data
*per_cu
;
3589 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3591 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3592 dw2_instantiate_symtab (per_cu
, false);
3597 dw2_expand_all_symtabs (struct objfile
*objfile
)
3599 struct dwarf2_per_objfile
*dwarf2_per_objfile
3600 = get_dwarf2_per_objfile (objfile
);
3601 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3602 + dwarf2_per_objfile
->all_type_units
.size ());
3604 for (int i
= 0; i
< total_units
; ++i
)
3606 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3608 /* We don't want to directly expand a partial CU, because if we
3609 read it with the wrong language, then assertion failures can
3610 be triggered later on. See PR symtab/23010. So, tell
3611 dw2_instantiate_symtab to skip partial CUs -- any important
3612 partial CU will be read via DW_TAG_imported_unit anyway. */
3613 dw2_instantiate_symtab (per_cu
, true);
3618 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3619 const char *fullname
)
3621 struct dwarf2_per_objfile
*dwarf2_per_objfile
3622 = get_dwarf2_per_objfile (objfile
);
3624 /* We don't need to consider type units here.
3625 This is only called for examining code, e.g. expand_line_sal.
3626 There can be an order of magnitude (or more) more type units
3627 than comp units, and we avoid them if we can. */
3629 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3631 /* We only need to look at symtabs not already expanded. */
3632 if (per_cu
->v
.quick
->compunit_symtab
)
3635 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3636 if (file_data
== NULL
)
3639 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3641 const char *this_fullname
= file_data
->file_names
[j
];
3643 if (filename_cmp (this_fullname
, fullname
) == 0)
3645 dw2_instantiate_symtab (per_cu
, false);
3653 dw2_map_matching_symbols
3654 (struct objfile
*objfile
,
3655 const lookup_name_info
&name
, domain_enum domain
,
3657 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3658 symbol_compare_ftype
*ordered_compare
)
3661 struct dwarf2_per_objfile
*dwarf2_per_objfile
3662 = get_dwarf2_per_objfile (objfile
);
3664 if (dwarf2_per_objfile
->index_table
!= nullptr)
3666 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3667 here though if the current language is Ada for a non-Ada objfile
3668 using GNU index. As Ada does not look for non-Ada symbols this
3669 function should just return. */
3673 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3674 inline psym_map_matching_symbols here, assuming all partial symtabs have
3676 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3678 for (compunit_symtab
*cust
: objfile
->compunits ())
3680 const struct block
*block
;
3684 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3685 if (!iterate_over_symbols_terminated (block
, name
,
3691 /* Starting from a search name, return the string that finds the upper
3692 bound of all strings that start with SEARCH_NAME in a sorted name
3693 list. Returns the empty string to indicate that the upper bound is
3694 the end of the list. */
3697 make_sort_after_prefix_name (const char *search_name
)
3699 /* When looking to complete "func", we find the upper bound of all
3700 symbols that start with "func" by looking for where we'd insert
3701 the closest string that would follow "func" in lexicographical
3702 order. Usually, that's "func"-with-last-character-incremented,
3703 i.e. "fund". Mind non-ASCII characters, though. Usually those
3704 will be UTF-8 multi-byte sequences, but we can't be certain.
3705 Especially mind the 0xff character, which is a valid character in
3706 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3707 rule out compilers allowing it in identifiers. Note that
3708 conveniently, strcmp/strcasecmp are specified to compare
3709 characters interpreted as unsigned char. So what we do is treat
3710 the whole string as a base 256 number composed of a sequence of
3711 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3712 to 0, and carries 1 to the following more-significant position.
3713 If the very first character in SEARCH_NAME ends up incremented
3714 and carries/overflows, then the upper bound is the end of the
3715 list. The string after the empty string is also the empty
3718 Some examples of this operation:
3720 SEARCH_NAME => "+1" RESULT
3724 "\xff" "a" "\xff" => "\xff" "b"
3729 Then, with these symbols for example:
3735 completing "func" looks for symbols between "func" and
3736 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3737 which finds "func" and "func1", but not "fund".
3741 funcÿ (Latin1 'ÿ' [0xff])
3745 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3746 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3750 ÿÿ (Latin1 'ÿ' [0xff])
3753 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3754 the end of the list.
3756 std::string after
= search_name
;
3757 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3759 if (!after
.empty ())
3760 after
.back () = (unsigned char) after
.back () + 1;
3764 /* See declaration. */
3766 std::pair
<std::vector
<name_component
>::const_iterator
,
3767 std::vector
<name_component
>::const_iterator
>
3768 mapped_index_base::find_name_components_bounds
3769 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3772 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3774 const char *lang_name
3775 = lookup_name_without_params
.language_lookup_name (lang
);
3777 /* Comparison function object for lower_bound that matches against a
3778 given symbol name. */
3779 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3782 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3783 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3784 return name_cmp (elem_name
, name
) < 0;
3787 /* Comparison function object for upper_bound that matches against a
3788 given symbol name. */
3789 auto lookup_compare_upper
= [&] (const char *name
,
3790 const name_component
&elem
)
3792 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3793 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3794 return name_cmp (name
, elem_name
) < 0;
3797 auto begin
= this->name_components
.begin ();
3798 auto end
= this->name_components
.end ();
3800 /* Find the lower bound. */
3803 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3806 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3809 /* Find the upper bound. */
3812 if (lookup_name_without_params
.completion_mode ())
3814 /* In completion mode, we want UPPER to point past all
3815 symbols names that have the same prefix. I.e., with
3816 these symbols, and completing "func":
3818 function << lower bound
3820 other_function << upper bound
3822 We find the upper bound by looking for the insertion
3823 point of "func"-with-last-character-incremented,
3825 std::string after
= make_sort_after_prefix_name (lang_name
);
3828 return std::lower_bound (lower
, end
, after
.c_str (),
3829 lookup_compare_lower
);
3832 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3835 return {lower
, upper
};
3838 /* See declaration. */
3841 mapped_index_base::build_name_components ()
3843 if (!this->name_components
.empty ())
3846 this->name_components_casing
= case_sensitivity
;
3848 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3850 /* The code below only knows how to break apart components of C++
3851 symbol names (and other languages that use '::' as
3852 namespace/module separator) and Ada symbol names. */
3853 auto count
= this->symbol_name_count ();
3854 for (offset_type idx
= 0; idx
< count
; idx
++)
3856 if (this->symbol_name_slot_invalid (idx
))
3859 const char *name
= this->symbol_name_at (idx
);
3861 /* Add each name component to the name component table. */
3862 unsigned int previous_len
= 0;
3864 if (strstr (name
, "::") != nullptr)
3866 for (unsigned int current_len
= cp_find_first_component (name
);
3867 name
[current_len
] != '\0';
3868 current_len
+= cp_find_first_component (name
+ current_len
))
3870 gdb_assert (name
[current_len
] == ':');
3871 this->name_components
.push_back ({previous_len
, idx
});
3872 /* Skip the '::'. */
3874 previous_len
= current_len
;
3879 /* Handle the Ada encoded (aka mangled) form here. */
3880 for (const char *iter
= strstr (name
, "__");
3882 iter
= strstr (iter
, "__"))
3884 this->name_components
.push_back ({previous_len
, idx
});
3886 previous_len
= iter
- name
;
3890 this->name_components
.push_back ({previous_len
, idx
});
3893 /* Sort name_components elements by name. */
3894 auto name_comp_compare
= [&] (const name_component
&left
,
3895 const name_component
&right
)
3897 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3898 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3900 const char *left_name
= left_qualified
+ left
.name_offset
;
3901 const char *right_name
= right_qualified
+ right
.name_offset
;
3903 return name_cmp (left_name
, right_name
) < 0;
3906 std::sort (this->name_components
.begin (),
3907 this->name_components
.end (),
3911 /* Helper for dw2_expand_symtabs_matching that works with a
3912 mapped_index_base instead of the containing objfile. This is split
3913 to a separate function in order to be able to unit test the
3914 name_components matching using a mock mapped_index_base. For each
3915 symbol name that matches, calls MATCH_CALLBACK, passing it the
3916 symbol's index in the mapped_index_base symbol table. */
3919 dw2_expand_symtabs_matching_symbol
3920 (mapped_index_base
&index
,
3921 const lookup_name_info
&lookup_name_in
,
3922 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3923 enum search_domain kind
,
3924 gdb::function_view
<bool (offset_type
)> match_callback
)
3926 lookup_name_info lookup_name_without_params
3927 = lookup_name_in
.make_ignore_params ();
3929 /* Build the symbol name component sorted vector, if we haven't
3931 index
.build_name_components ();
3933 /* The same symbol may appear more than once in the range though.
3934 E.g., if we're looking for symbols that complete "w", and we have
3935 a symbol named "w1::w2", we'll find the two name components for
3936 that same symbol in the range. To be sure we only call the
3937 callback once per symbol, we first collect the symbol name
3938 indexes that matched in a temporary vector and ignore
3940 std::vector
<offset_type
> matches
;
3942 struct name_and_matcher
3944 symbol_name_matcher_ftype
*matcher
;
3947 bool operator== (const name_and_matcher
&other
) const
3949 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3953 /* A vector holding all the different symbol name matchers, for all
3955 std::vector
<name_and_matcher
> matchers
;
3957 for (int i
= 0; i
< nr_languages
; i
++)
3959 enum language lang_e
= (enum language
) i
;
3961 const language_defn
*lang
= language_def (lang_e
);
3962 symbol_name_matcher_ftype
*name_matcher
3963 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3965 name_and_matcher key
{
3967 lookup_name_without_params
.language_lookup_name (lang_e
)
3970 /* Don't insert the same comparison routine more than once.
3971 Note that we do this linear walk. This is not a problem in
3972 practice because the number of supported languages is
3974 if (std::find (matchers
.begin (), matchers
.end (), key
)
3977 matchers
.push_back (std::move (key
));
3980 = index
.find_name_components_bounds (lookup_name_without_params
,
3983 /* Now for each symbol name in range, check to see if we have a name
3984 match, and if so, call the MATCH_CALLBACK callback. */
3986 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3988 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3990 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3991 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3994 matches
.push_back (bounds
.first
->idx
);
3998 std::sort (matches
.begin (), matches
.end ());
4000 /* Finally call the callback, once per match. */
4002 for (offset_type idx
: matches
)
4006 if (!match_callback (idx
))
4012 /* Above we use a type wider than idx's for 'prev', since 0 and
4013 (offset_type)-1 are both possible values. */
4014 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4019 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4021 /* A mock .gdb_index/.debug_names-like name index table, enough to
4022 exercise dw2_expand_symtabs_matching_symbol, which works with the
4023 mapped_index_base interface. Builds an index from the symbol list
4024 passed as parameter to the constructor. */
4025 class mock_mapped_index
: public mapped_index_base
4028 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4029 : m_symbol_table (symbols
)
4032 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4034 /* Return the number of names in the symbol table. */
4035 size_t symbol_name_count () const override
4037 return m_symbol_table
.size ();
4040 /* Get the name of the symbol at IDX in the symbol table. */
4041 const char *symbol_name_at (offset_type idx
) const override
4043 return m_symbol_table
[idx
];
4047 gdb::array_view
<const char *> m_symbol_table
;
4050 /* Convenience function that converts a NULL pointer to a "<null>"
4051 string, to pass to print routines. */
4054 string_or_null (const char *str
)
4056 return str
!= NULL
? str
: "<null>";
4059 /* Check if a lookup_name_info built from
4060 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4061 index. EXPECTED_LIST is the list of expected matches, in expected
4062 matching order. If no match expected, then an empty list is
4063 specified. Returns true on success. On failure prints a warning
4064 indicating the file:line that failed, and returns false. */
4067 check_match (const char *file
, int line
,
4068 mock_mapped_index
&mock_index
,
4069 const char *name
, symbol_name_match_type match_type
,
4070 bool completion_mode
,
4071 std::initializer_list
<const char *> expected_list
)
4073 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4075 bool matched
= true;
4077 auto mismatch
= [&] (const char *expected_str
,
4080 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4081 "expected=\"%s\", got=\"%s\"\n"),
4083 (match_type
== symbol_name_match_type::FULL
4085 name
, string_or_null (expected_str
), string_or_null (got
));
4089 auto expected_it
= expected_list
.begin ();
4090 auto expected_end
= expected_list
.end ();
4092 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4094 [&] (offset_type idx
)
4096 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4097 const char *expected_str
4098 = expected_it
== expected_end
? NULL
: *expected_it
++;
4100 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4101 mismatch (expected_str
, matched_name
);
4105 const char *expected_str
4106 = expected_it
== expected_end
? NULL
: *expected_it
++;
4107 if (expected_str
!= NULL
)
4108 mismatch (expected_str
, NULL
);
4113 /* The symbols added to the mock mapped_index for testing (in
4115 static const char *test_symbols
[] = {
4124 "ns2::tmpl<int>::foo2",
4125 "(anonymous namespace)::A::B::C",
4127 /* These are used to check that the increment-last-char in the
4128 matching algorithm for completion doesn't match "t1_fund" when
4129 completing "t1_func". */
4135 /* A UTF-8 name with multi-byte sequences to make sure that
4136 cp-name-parser understands this as a single identifier ("função"
4137 is "function" in PT). */
4140 /* \377 (0xff) is Latin1 'ÿ'. */
4143 /* \377 (0xff) is Latin1 'ÿ'. */
4147 /* A name with all sorts of complications. Starts with "z" to make
4148 it easier for the completion tests below. */
4149 #define Z_SYM_NAME \
4150 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4151 "::tuple<(anonymous namespace)::ui*, " \
4152 "std::default_delete<(anonymous namespace)::ui>, void>"
4157 /* Returns true if the mapped_index_base::find_name_component_bounds
4158 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4159 in completion mode. */
4162 check_find_bounds_finds (mapped_index_base
&index
,
4163 const char *search_name
,
4164 gdb::array_view
<const char *> expected_syms
)
4166 lookup_name_info
lookup_name (search_name
,
4167 symbol_name_match_type::FULL
, true);
4169 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4172 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4173 if (distance
!= expected_syms
.size ())
4176 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4178 auto nc_elem
= bounds
.first
+ exp_elem
;
4179 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4180 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4187 /* Test the lower-level mapped_index::find_name_component_bounds
4191 test_mapped_index_find_name_component_bounds ()
4193 mock_mapped_index
mock_index (test_symbols
);
4195 mock_index
.build_name_components ();
4197 /* Test the lower-level mapped_index::find_name_component_bounds
4198 method in completion mode. */
4200 static const char *expected_syms
[] = {
4205 SELF_CHECK (check_find_bounds_finds (mock_index
,
4206 "t1_func", expected_syms
));
4209 /* Check that the increment-last-char in the name matching algorithm
4210 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4212 static const char *expected_syms1
[] = {
4216 SELF_CHECK (check_find_bounds_finds (mock_index
,
4217 "\377", expected_syms1
));
4219 static const char *expected_syms2
[] = {
4222 SELF_CHECK (check_find_bounds_finds (mock_index
,
4223 "\377\377", expected_syms2
));
4227 /* Test dw2_expand_symtabs_matching_symbol. */
4230 test_dw2_expand_symtabs_matching_symbol ()
4232 mock_mapped_index
mock_index (test_symbols
);
4234 /* We let all tests run until the end even if some fails, for debug
4236 bool any_mismatch
= false;
4238 /* Create the expected symbols list (an initializer_list). Needed
4239 because lists have commas, and we need to pass them to CHECK,
4240 which is a macro. */
4241 #define EXPECT(...) { __VA_ARGS__ }
4243 /* Wrapper for check_match that passes down the current
4244 __FILE__/__LINE__. */
4245 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4246 any_mismatch |= !check_match (__FILE__, __LINE__, \
4248 NAME, MATCH_TYPE, COMPLETION_MODE, \
4251 /* Identity checks. */
4252 for (const char *sym
: test_symbols
)
4254 /* Should be able to match all existing symbols. */
4255 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4258 /* Should be able to match all existing symbols with
4260 std::string with_params
= std::string (sym
) + "(int)";
4261 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4264 /* Should be able to match all existing symbols with
4265 parameters and qualifiers. */
4266 with_params
= std::string (sym
) + " ( int ) const";
4267 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4270 /* This should really find sym, but cp-name-parser.y doesn't
4271 know about lvalue/rvalue qualifiers yet. */
4272 with_params
= std::string (sym
) + " ( int ) &&";
4273 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4277 /* Check that the name matching algorithm for completion doesn't get
4278 confused with Latin1 'ÿ' / 0xff. */
4280 static const char str
[] = "\377";
4281 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4282 EXPECT ("\377", "\377\377123"));
4285 /* Check that the increment-last-char in the matching algorithm for
4286 completion doesn't match "t1_fund" when completing "t1_func". */
4288 static const char str
[] = "t1_func";
4289 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4290 EXPECT ("t1_func", "t1_func1"));
4293 /* Check that completion mode works at each prefix of the expected
4296 static const char str
[] = "function(int)";
4297 size_t len
= strlen (str
);
4300 for (size_t i
= 1; i
< len
; i
++)
4302 lookup
.assign (str
, i
);
4303 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4304 EXPECT ("function"));
4308 /* While "w" is a prefix of both components, the match function
4309 should still only be called once. */
4311 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4313 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4317 /* Same, with a "complicated" symbol. */
4319 static const char str
[] = Z_SYM_NAME
;
4320 size_t len
= strlen (str
);
4323 for (size_t i
= 1; i
< len
; i
++)
4325 lookup
.assign (str
, i
);
4326 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4327 EXPECT (Z_SYM_NAME
));
4331 /* In FULL mode, an incomplete symbol doesn't match. */
4333 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4337 /* A complete symbol with parameters matches any overload, since the
4338 index has no overload info. */
4340 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4341 EXPECT ("std::zfunction", "std::zfunction2"));
4342 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4343 EXPECT ("std::zfunction", "std::zfunction2"));
4344 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4345 EXPECT ("std::zfunction", "std::zfunction2"));
4348 /* Check that whitespace is ignored appropriately. A symbol with a
4349 template argument list. */
4351 static const char expected
[] = "ns::foo<int>";
4352 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4354 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4358 /* Check that whitespace is ignored appropriately. A symbol with a
4359 template argument list that includes a pointer. */
4361 static const char expected
[] = "ns::foo<char*>";
4362 /* Try both completion and non-completion modes. */
4363 static const bool completion_mode
[2] = {false, true};
4364 for (size_t i
= 0; i
< 2; i
++)
4366 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4367 completion_mode
[i
], EXPECT (expected
));
4368 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4369 completion_mode
[i
], EXPECT (expected
));
4371 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4372 completion_mode
[i
], EXPECT (expected
));
4373 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4374 completion_mode
[i
], EXPECT (expected
));
4379 /* Check method qualifiers are ignored. */
4380 static const char expected
[] = "ns::foo<char*>";
4381 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4382 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4383 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4384 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4385 CHECK_MATCH ("foo < char * > ( int ) const",
4386 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4387 CHECK_MATCH ("foo < char * > ( int ) &&",
4388 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4391 /* Test lookup names that don't match anything. */
4393 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4396 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4400 /* Some wild matching tests, exercising "(anonymous namespace)",
4401 which should not be confused with a parameter list. */
4403 static const char *syms
[] = {
4407 "A :: B :: C ( int )",
4412 for (const char *s
: syms
)
4414 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4415 EXPECT ("(anonymous namespace)::A::B::C"));
4420 static const char expected
[] = "ns2::tmpl<int>::foo2";
4421 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4423 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4427 SELF_CHECK (!any_mismatch
);
4436 test_mapped_index_find_name_component_bounds ();
4437 test_dw2_expand_symtabs_matching_symbol ();
4440 }} // namespace selftests::dw2_expand_symtabs_matching
4442 #endif /* GDB_SELF_TEST */
4444 /* If FILE_MATCHER is NULL or if PER_CU has
4445 dwarf2_per_cu_quick_data::MARK set (see
4446 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4447 EXPANSION_NOTIFY on it. */
4450 dw2_expand_symtabs_matching_one
4451 (struct dwarf2_per_cu_data
*per_cu
,
4452 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4453 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4455 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4457 bool symtab_was_null
4458 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4460 dw2_instantiate_symtab (per_cu
, false);
4462 if (expansion_notify
!= NULL
4464 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4465 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4469 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4470 matched, to expand corresponding CUs that were marked. IDX is the
4471 index of the symbol name that matched. */
4474 dw2_expand_marked_cus
4475 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4476 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4477 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4480 offset_type
*vec
, vec_len
, vec_idx
;
4481 bool global_seen
= false;
4482 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4484 vec
= (offset_type
*) (index
.constant_pool
4485 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4486 vec_len
= MAYBE_SWAP (vec
[0]);
4487 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4489 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4490 /* This value is only valid for index versions >= 7. */
4491 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4492 gdb_index_symbol_kind symbol_kind
=
4493 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4494 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4495 /* Only check the symbol attributes if they're present.
4496 Indices prior to version 7 don't record them,
4497 and indices >= 7 may elide them for certain symbols
4498 (gold does this). */
4501 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4503 /* Work around gold/15646. */
4506 if (!is_static
&& global_seen
)
4512 /* Only check the symbol's kind if it has one. */
4517 case VARIABLES_DOMAIN
:
4518 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4521 case FUNCTIONS_DOMAIN
:
4522 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4526 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4529 case MODULES_DOMAIN
:
4530 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4538 /* Don't crash on bad data. */
4539 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4540 + dwarf2_per_objfile
->all_type_units
.size ()))
4542 complaint (_(".gdb_index entry has bad CU index"
4544 objfile_name (dwarf2_per_objfile
->objfile
));
4548 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4549 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4554 /* If FILE_MATCHER is non-NULL, set all the
4555 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4556 that match FILE_MATCHER. */
4559 dw_expand_symtabs_matching_file_matcher
4560 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4561 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4563 if (file_matcher
== NULL
)
4566 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4568 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4570 NULL
, xcalloc
, xfree
));
4571 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4573 NULL
, xcalloc
, xfree
));
4575 /* The rule is CUs specify all the files, including those used by
4576 any TU, so there's no need to scan TUs here. */
4578 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4582 per_cu
->v
.quick
->mark
= 0;
4584 /* We only need to look at symtabs not already expanded. */
4585 if (per_cu
->v
.quick
->compunit_symtab
)
4588 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4589 if (file_data
== NULL
)
4592 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4594 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4596 per_cu
->v
.quick
->mark
= 1;
4600 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4602 const char *this_real_name
;
4604 if (file_matcher (file_data
->file_names
[j
], false))
4606 per_cu
->v
.quick
->mark
= 1;
4610 /* Before we invoke realpath, which can get expensive when many
4611 files are involved, do a quick comparison of the basenames. */
4612 if (!basenames_may_differ
4613 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4617 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4618 if (file_matcher (this_real_name
, false))
4620 per_cu
->v
.quick
->mark
= 1;
4625 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4626 ? visited_found
.get ()
4627 : visited_not_found
.get (),
4634 dw2_expand_symtabs_matching
4635 (struct objfile
*objfile
,
4636 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4637 const lookup_name_info
*lookup_name
,
4638 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4639 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4640 enum search_domain kind
)
4642 struct dwarf2_per_objfile
*dwarf2_per_objfile
4643 = get_dwarf2_per_objfile (objfile
);
4645 /* index_table is NULL if OBJF_READNOW. */
4646 if (!dwarf2_per_objfile
->index_table
)
4649 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4651 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4653 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4657 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4663 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4665 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4667 kind
, [&] (offset_type idx
)
4669 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4670 expansion_notify
, kind
);
4675 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4678 static struct compunit_symtab
*
4679 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4684 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4685 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4688 if (cust
->includes
== NULL
)
4691 for (i
= 0; cust
->includes
[i
]; ++i
)
4693 struct compunit_symtab
*s
= cust
->includes
[i
];
4695 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4703 static struct compunit_symtab
*
4704 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4705 struct bound_minimal_symbol msymbol
,
4707 struct obj_section
*section
,
4710 struct dwarf2_per_cu_data
*data
;
4711 struct compunit_symtab
*result
;
4713 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4716 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4717 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4718 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4722 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4723 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4724 paddress (objfile
->arch (), pc
));
4727 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4730 gdb_assert (result
!= NULL
);
4735 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4736 void *data
, int need_fullname
)
4738 struct dwarf2_per_objfile
*dwarf2_per_objfile
4739 = get_dwarf2_per_objfile (objfile
);
4741 if (!dwarf2_per_objfile
->filenames_cache
)
4743 dwarf2_per_objfile
->filenames_cache
.emplace ();
4745 htab_up
visited (htab_create_alloc (10,
4746 htab_hash_pointer
, htab_eq_pointer
,
4747 NULL
, xcalloc
, xfree
));
4749 /* The rule is CUs specify all the files, including those used
4750 by any TU, so there's no need to scan TUs here. We can
4751 ignore file names coming from already-expanded CUs. */
4753 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4755 if (per_cu
->v
.quick
->compunit_symtab
)
4757 void **slot
= htab_find_slot (visited
.get (),
4758 per_cu
->v
.quick
->file_names
,
4761 *slot
= per_cu
->v
.quick
->file_names
;
4765 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4767 /* We only need to look at symtabs not already expanded. */
4768 if (per_cu
->v
.quick
->compunit_symtab
)
4771 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4772 if (file_data
== NULL
)
4775 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4778 /* Already visited. */
4783 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4785 const char *filename
= file_data
->file_names
[j
];
4786 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4791 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4793 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4796 this_real_name
= gdb_realpath (filename
);
4797 (*fun
) (filename
, this_real_name
.get (), data
);
4802 dw2_has_symbols (struct objfile
*objfile
)
4807 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4810 dw2_find_last_source_symtab
,
4811 dw2_forget_cached_source_info
,
4812 dw2_map_symtabs_matching_filename
,
4817 dw2_expand_symtabs_for_function
,
4818 dw2_expand_all_symtabs
,
4819 dw2_expand_symtabs_with_fullname
,
4820 dw2_map_matching_symbols
,
4821 dw2_expand_symtabs_matching
,
4822 dw2_find_pc_sect_compunit_symtab
,
4824 dw2_map_symbol_filenames
4827 /* DWARF-5 debug_names reader. */
4829 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4830 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4832 /* A helper function that reads the .debug_names section in SECTION
4833 and fills in MAP. FILENAME is the name of the file containing the
4834 section; it is used for error reporting.
4836 Returns true if all went well, false otherwise. */
4839 read_debug_names_from_section (struct objfile
*objfile
,
4840 const char *filename
,
4841 struct dwarf2_section_info
*section
,
4842 mapped_debug_names
&map
)
4844 if (section
->empty ())
4847 /* Older elfutils strip versions could keep the section in the main
4848 executable while splitting it for the separate debug info file. */
4849 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4852 section
->read (objfile
);
4854 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4856 const gdb_byte
*addr
= section
->buffer
;
4858 bfd
*const abfd
= section
->get_bfd_owner ();
4860 unsigned int bytes_read
;
4861 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4864 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4865 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4866 if (bytes_read
+ length
!= section
->size
)
4868 /* There may be multiple per-CU indices. */
4869 warning (_("Section .debug_names in %s length %s does not match "
4870 "section length %s, ignoring .debug_names."),
4871 filename
, plongest (bytes_read
+ length
),
4872 pulongest (section
->size
));
4876 /* The version number. */
4877 uint16_t version
= read_2_bytes (abfd
, addr
);
4881 warning (_("Section .debug_names in %s has unsupported version %d, "
4882 "ignoring .debug_names."),
4888 uint16_t padding
= read_2_bytes (abfd
, addr
);
4892 warning (_("Section .debug_names in %s has unsupported padding %d, "
4893 "ignoring .debug_names."),
4898 /* comp_unit_count - The number of CUs in the CU list. */
4899 map
.cu_count
= read_4_bytes (abfd
, addr
);
4902 /* local_type_unit_count - The number of TUs in the local TU
4904 map
.tu_count
= read_4_bytes (abfd
, addr
);
4907 /* foreign_type_unit_count - The number of TUs in the foreign TU
4909 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4911 if (foreign_tu_count
!= 0)
4913 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4914 "ignoring .debug_names."),
4915 filename
, static_cast<unsigned long> (foreign_tu_count
));
4919 /* bucket_count - The number of hash buckets in the hash lookup
4921 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4924 /* name_count - The number of unique names in the index. */
4925 map
.name_count
= read_4_bytes (abfd
, addr
);
4928 /* abbrev_table_size - The size in bytes of the abbreviations
4930 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4933 /* augmentation_string_size - The size in bytes of the augmentation
4934 string. This value is rounded up to a multiple of 4. */
4935 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4937 map
.augmentation_is_gdb
= ((augmentation_string_size
4938 == sizeof (dwarf5_augmentation
))
4939 && memcmp (addr
, dwarf5_augmentation
,
4940 sizeof (dwarf5_augmentation
)) == 0);
4941 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4942 addr
+= augmentation_string_size
;
4945 map
.cu_table_reordered
= addr
;
4946 addr
+= map
.cu_count
* map
.offset_size
;
4948 /* List of Local TUs */
4949 map
.tu_table_reordered
= addr
;
4950 addr
+= map
.tu_count
* map
.offset_size
;
4952 /* Hash Lookup Table */
4953 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4954 addr
+= map
.bucket_count
* 4;
4955 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4956 addr
+= map
.name_count
* 4;
4959 map
.name_table_string_offs_reordered
= addr
;
4960 addr
+= map
.name_count
* map
.offset_size
;
4961 map
.name_table_entry_offs_reordered
= addr
;
4962 addr
+= map
.name_count
* map
.offset_size
;
4964 const gdb_byte
*abbrev_table_start
= addr
;
4967 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4972 const auto insertpair
4973 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4974 if (!insertpair
.second
)
4976 warning (_("Section .debug_names in %s has duplicate index %s, "
4977 "ignoring .debug_names."),
4978 filename
, pulongest (index_num
));
4981 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4982 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4987 mapped_debug_names::index_val::attr attr
;
4988 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4990 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4992 if (attr
.form
== DW_FORM_implicit_const
)
4994 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4998 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5000 indexval
.attr_vec
.push_back (std::move (attr
));
5003 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5005 warning (_("Section .debug_names in %s has abbreviation_table "
5006 "of size %s vs. written as %u, ignoring .debug_names."),
5007 filename
, plongest (addr
- abbrev_table_start
),
5011 map
.entry_pool
= addr
;
5016 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5020 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5021 const mapped_debug_names
&map
,
5022 dwarf2_section_info
§ion
,
5025 sect_offset sect_off_prev
;
5026 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5028 sect_offset sect_off_next
;
5029 if (i
< map
.cu_count
)
5032 = (sect_offset
) (extract_unsigned_integer
5033 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5035 map
.dwarf5_byte_order
));
5038 sect_off_next
= (sect_offset
) section
.size
;
5041 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5042 dwarf2_per_cu_data
*per_cu
5043 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5044 sect_off_prev
, length
);
5045 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5047 sect_off_prev
= sect_off_next
;
5051 /* Read the CU list from the mapped index, and use it to create all
5052 the CU objects for this dwarf2_per_objfile. */
5055 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5056 const mapped_debug_names
&map
,
5057 const mapped_debug_names
&dwz_map
)
5059 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5060 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5062 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5063 dwarf2_per_objfile
->info
,
5064 false /* is_dwz */);
5066 if (dwz_map
.cu_count
== 0)
5069 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5070 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5074 /* Read .debug_names. If everything went ok, initialize the "quick"
5075 elements of all the CUs and return true. Otherwise, return false. */
5078 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5080 std::unique_ptr
<mapped_debug_names
> map
5081 (new mapped_debug_names (dwarf2_per_objfile
));
5082 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5083 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5085 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5086 &dwarf2_per_objfile
->debug_names
,
5090 /* Don't use the index if it's empty. */
5091 if (map
->name_count
== 0)
5094 /* If there is a .dwz file, read it so we can get its CU list as
5096 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5099 if (!read_debug_names_from_section (objfile
,
5100 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5101 &dwz
->debug_names
, dwz_map
))
5103 warning (_("could not read '.debug_names' section from %s; skipping"),
5104 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5109 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5111 if (map
->tu_count
!= 0)
5113 /* We can only handle a single .debug_types when we have an
5115 if (dwarf2_per_objfile
->types
.size () != 1)
5118 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5120 create_signatured_type_table_from_debug_names
5121 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5124 create_addrmap_from_aranges (dwarf2_per_objfile
,
5125 &dwarf2_per_objfile
->debug_aranges
);
5127 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5128 dwarf2_per_objfile
->using_index
= 1;
5129 dwarf2_per_objfile
->quick_file_names_table
=
5130 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5135 /* Type used to manage iterating over all CUs looking for a symbol for
5138 class dw2_debug_names_iterator
5141 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5142 gdb::optional
<block_enum
> block_index
,
5145 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5146 m_addr (find_vec_in_debug_names (map
, name
))
5149 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5150 search_domain search
, uint32_t namei
)
5153 m_addr (find_vec_in_debug_names (map
, namei
))
5156 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5157 block_enum block_index
, domain_enum domain
,
5159 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5160 m_addr (find_vec_in_debug_names (map
, namei
))
5163 /* Return the next matching CU or NULL if there are no more. */
5164 dwarf2_per_cu_data
*next ();
5167 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5169 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5172 /* The internalized form of .debug_names. */
5173 const mapped_debug_names
&m_map
;
5175 /* If set, only look for symbols that match that block. Valid values are
5176 GLOBAL_BLOCK and STATIC_BLOCK. */
5177 const gdb::optional
<block_enum
> m_block_index
;
5179 /* The kind of symbol we're looking for. */
5180 const domain_enum m_domain
= UNDEF_DOMAIN
;
5181 const search_domain m_search
= ALL_DOMAIN
;
5183 /* The list of CUs from the index entry of the symbol, or NULL if
5185 const gdb_byte
*m_addr
;
5189 mapped_debug_names::namei_to_name (uint32_t namei
) const
5191 const ULONGEST namei_string_offs
5192 = extract_unsigned_integer ((name_table_string_offs_reordered
5193 + namei
* offset_size
),
5196 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5200 /* Find a slot in .debug_names for the object named NAME. If NAME is
5201 found, return pointer to its pool data. If NAME cannot be found,
5205 dw2_debug_names_iterator::find_vec_in_debug_names
5206 (const mapped_debug_names
&map
, const char *name
)
5208 int (*cmp
) (const char *, const char *);
5210 gdb::unique_xmalloc_ptr
<char> without_params
;
5211 if (current_language
->la_language
== language_cplus
5212 || current_language
->la_language
== language_fortran
5213 || current_language
->la_language
== language_d
)
5215 /* NAME is already canonical. Drop any qualifiers as
5216 .debug_names does not contain any. */
5218 if (strchr (name
, '(') != NULL
)
5220 without_params
= cp_remove_params (name
);
5221 if (without_params
!= NULL
)
5222 name
= without_params
.get ();
5226 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5228 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5230 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5231 (map
.bucket_table_reordered
5232 + (full_hash
% map
.bucket_count
)), 4,
5233 map
.dwarf5_byte_order
);
5237 if (namei
>= map
.name_count
)
5239 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5241 namei
, map
.name_count
,
5242 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5248 const uint32_t namei_full_hash
5249 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5250 (map
.hash_table_reordered
+ namei
), 4,
5251 map
.dwarf5_byte_order
);
5252 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5255 if (full_hash
== namei_full_hash
)
5257 const char *const namei_string
= map
.namei_to_name (namei
);
5259 #if 0 /* An expensive sanity check. */
5260 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5262 complaint (_("Wrong .debug_names hash for string at index %u "
5264 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5269 if (cmp (namei_string
, name
) == 0)
5271 const ULONGEST namei_entry_offs
5272 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5273 + namei
* map
.offset_size
),
5274 map
.offset_size
, map
.dwarf5_byte_order
);
5275 return map
.entry_pool
+ namei_entry_offs
;
5280 if (namei
>= map
.name_count
)
5286 dw2_debug_names_iterator::find_vec_in_debug_names
5287 (const mapped_debug_names
&map
, uint32_t namei
)
5289 if (namei
>= map
.name_count
)
5291 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5293 namei
, map
.name_count
,
5294 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5298 const ULONGEST namei_entry_offs
5299 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5300 + namei
* map
.offset_size
),
5301 map
.offset_size
, map
.dwarf5_byte_order
);
5302 return map
.entry_pool
+ namei_entry_offs
;
5305 /* See dw2_debug_names_iterator. */
5307 dwarf2_per_cu_data
*
5308 dw2_debug_names_iterator::next ()
5313 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5314 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5315 bfd
*const abfd
= objfile
->obfd
;
5319 unsigned int bytes_read
;
5320 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5321 m_addr
+= bytes_read
;
5325 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5326 if (indexval_it
== m_map
.abbrev_map
.cend ())
5328 complaint (_("Wrong .debug_names undefined abbrev code %s "
5330 pulongest (abbrev
), objfile_name (objfile
));
5333 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5334 enum class symbol_linkage
{
5338 } symbol_linkage_
= symbol_linkage::unknown
;
5339 dwarf2_per_cu_data
*per_cu
= NULL
;
5340 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5345 case DW_FORM_implicit_const
:
5346 ull
= attr
.implicit_const
;
5348 case DW_FORM_flag_present
:
5352 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5353 m_addr
+= bytes_read
;
5356 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5357 dwarf_form_name (attr
.form
),
5358 objfile_name (objfile
));
5361 switch (attr
.dw_idx
)
5363 case DW_IDX_compile_unit
:
5364 /* Don't crash on bad data. */
5365 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5367 complaint (_(".debug_names entry has bad CU index %s"
5370 objfile_name (dwarf2_per_objfile
->objfile
));
5373 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5375 case DW_IDX_type_unit
:
5376 /* Don't crash on bad data. */
5377 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5379 complaint (_(".debug_names entry has bad TU index %s"
5382 objfile_name (dwarf2_per_objfile
->objfile
));
5385 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5387 case DW_IDX_GNU_internal
:
5388 if (!m_map
.augmentation_is_gdb
)
5390 symbol_linkage_
= symbol_linkage::static_
;
5392 case DW_IDX_GNU_external
:
5393 if (!m_map
.augmentation_is_gdb
)
5395 symbol_linkage_
= symbol_linkage::extern_
;
5400 /* Skip if already read in. */
5401 if (per_cu
->v
.quick
->compunit_symtab
)
5404 /* Check static vs global. */
5405 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5407 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5408 const bool symbol_is_static
=
5409 symbol_linkage_
== symbol_linkage::static_
;
5410 if (want_static
!= symbol_is_static
)
5414 /* Match dw2_symtab_iter_next, symbol_kind
5415 and debug_names::psymbol_tag. */
5419 switch (indexval
.dwarf_tag
)
5421 case DW_TAG_variable
:
5422 case DW_TAG_subprogram
:
5423 /* Some types are also in VAR_DOMAIN. */
5424 case DW_TAG_typedef
:
5425 case DW_TAG_structure_type
:
5432 switch (indexval
.dwarf_tag
)
5434 case DW_TAG_typedef
:
5435 case DW_TAG_structure_type
:
5442 switch (indexval
.dwarf_tag
)
5445 case DW_TAG_variable
:
5452 switch (indexval
.dwarf_tag
)
5464 /* Match dw2_expand_symtabs_matching, symbol_kind and
5465 debug_names::psymbol_tag. */
5468 case VARIABLES_DOMAIN
:
5469 switch (indexval
.dwarf_tag
)
5471 case DW_TAG_variable
:
5477 case FUNCTIONS_DOMAIN
:
5478 switch (indexval
.dwarf_tag
)
5480 case DW_TAG_subprogram
:
5487 switch (indexval
.dwarf_tag
)
5489 case DW_TAG_typedef
:
5490 case DW_TAG_structure_type
:
5496 case MODULES_DOMAIN
:
5497 switch (indexval
.dwarf_tag
)
5511 static struct compunit_symtab
*
5512 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5513 const char *name
, domain_enum domain
)
5515 struct dwarf2_per_objfile
*dwarf2_per_objfile
5516 = get_dwarf2_per_objfile (objfile
);
5518 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5521 /* index is NULL if OBJF_READNOW. */
5524 const auto &map
= *mapp
;
5526 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5528 struct compunit_symtab
*stab_best
= NULL
;
5529 struct dwarf2_per_cu_data
*per_cu
;
5530 while ((per_cu
= iter
.next ()) != NULL
)
5532 struct symbol
*sym
, *with_opaque
= NULL
;
5533 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5534 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5535 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5537 sym
= block_find_symbol (block
, name
, domain
,
5538 block_find_non_opaque_type_preferred
,
5541 /* Some caution must be observed with overloaded functions and
5542 methods, since the index will not contain any overload
5543 information (but NAME might contain it). */
5546 && strcmp_iw (sym
->search_name (), name
) == 0)
5548 if (with_opaque
!= NULL
5549 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5552 /* Keep looking through other CUs. */
5558 /* This dumps minimal information about .debug_names. It is called
5559 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5560 uses this to verify that .debug_names has been loaded. */
5563 dw2_debug_names_dump (struct objfile
*objfile
)
5565 struct dwarf2_per_objfile
*dwarf2_per_objfile
5566 = get_dwarf2_per_objfile (objfile
);
5568 gdb_assert (dwarf2_per_objfile
->using_index
);
5569 printf_filtered (".debug_names:");
5570 if (dwarf2_per_objfile
->debug_names_table
)
5571 printf_filtered (" exists\n");
5573 printf_filtered (" faked for \"readnow\"\n");
5574 printf_filtered ("\n");
5578 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5579 const char *func_name
)
5581 struct dwarf2_per_objfile
*dwarf2_per_objfile
5582 = get_dwarf2_per_objfile (objfile
);
5584 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5585 if (dwarf2_per_objfile
->debug_names_table
)
5587 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5589 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5591 struct dwarf2_per_cu_data
*per_cu
;
5592 while ((per_cu
= iter
.next ()) != NULL
)
5593 dw2_instantiate_symtab (per_cu
, false);
5598 dw2_debug_names_map_matching_symbols
5599 (struct objfile
*objfile
,
5600 const lookup_name_info
&name
, domain_enum domain
,
5602 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5603 symbol_compare_ftype
*ordered_compare
)
5605 struct dwarf2_per_objfile
*dwarf2_per_objfile
5606 = get_dwarf2_per_objfile (objfile
);
5608 /* debug_names_table is NULL if OBJF_READNOW. */
5609 if (!dwarf2_per_objfile
->debug_names_table
)
5612 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5613 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5615 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5616 auto matcher
= [&] (const char *symname
)
5618 if (ordered_compare
== nullptr)
5620 return ordered_compare (symname
, match_name
) == 0;
5623 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5624 [&] (offset_type namei
)
5626 /* The name was matched, now expand corresponding CUs that were
5628 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5630 struct dwarf2_per_cu_data
*per_cu
;
5631 while ((per_cu
= iter
.next ()) != NULL
)
5632 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5636 /* It's a shame we couldn't do this inside the
5637 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5638 that have already been expanded. Instead, this loop matches what
5639 the psymtab code does. */
5640 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5642 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5643 if (cust
!= nullptr)
5645 const struct block
*block
5646 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5647 if (!iterate_over_symbols_terminated (block
, name
,
5655 dw2_debug_names_expand_symtabs_matching
5656 (struct objfile
*objfile
,
5657 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5658 const lookup_name_info
*lookup_name
,
5659 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5660 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5661 enum search_domain kind
)
5663 struct dwarf2_per_objfile
*dwarf2_per_objfile
5664 = get_dwarf2_per_objfile (objfile
);
5666 /* debug_names_table is NULL if OBJF_READNOW. */
5667 if (!dwarf2_per_objfile
->debug_names_table
)
5670 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5672 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5674 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5678 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5684 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5686 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5688 kind
, [&] (offset_type namei
)
5690 /* The name was matched, now expand corresponding CUs that were
5692 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5694 struct dwarf2_per_cu_data
*per_cu
;
5695 while ((per_cu
= iter
.next ()) != NULL
)
5696 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5702 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5705 dw2_find_last_source_symtab
,
5706 dw2_forget_cached_source_info
,
5707 dw2_map_symtabs_matching_filename
,
5708 dw2_debug_names_lookup_symbol
,
5711 dw2_debug_names_dump
,
5712 dw2_debug_names_expand_symtabs_for_function
,
5713 dw2_expand_all_symtabs
,
5714 dw2_expand_symtabs_with_fullname
,
5715 dw2_debug_names_map_matching_symbols
,
5716 dw2_debug_names_expand_symtabs_matching
,
5717 dw2_find_pc_sect_compunit_symtab
,
5719 dw2_map_symbol_filenames
5722 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5723 to either a dwarf2_per_objfile or dwz_file object. */
5725 template <typename T
>
5726 static gdb::array_view
<const gdb_byte
>
5727 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5729 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5731 if (section
->empty ())
5734 /* Older elfutils strip versions could keep the section in the main
5735 executable while splitting it for the separate debug info file. */
5736 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5739 section
->read (obj
);
5741 /* dwarf2_section_info::size is a bfd_size_type, while
5742 gdb::array_view works with size_t. On 32-bit hosts, with
5743 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5744 is 32-bit. So we need an explicit narrowing conversion here.
5745 This is fine, because it's impossible to allocate or mmap an
5746 array/buffer larger than what size_t can represent. */
5747 return gdb::make_array_view (section
->buffer
, section
->size
);
5750 /* Lookup the index cache for the contents of the index associated to
5753 static gdb::array_view
<const gdb_byte
>
5754 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5756 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5757 if (build_id
== nullptr)
5760 return global_index_cache
.lookup_gdb_index (build_id
,
5761 &dwarf2_obj
->index_cache_res
);
5764 /* Same as the above, but for DWZ. */
5766 static gdb::array_view
<const gdb_byte
>
5767 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5769 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5770 if (build_id
== nullptr)
5773 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5776 /* See symfile.h. */
5779 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5781 struct dwarf2_per_objfile
*dwarf2_per_objfile
5782 = get_dwarf2_per_objfile (objfile
);
5784 /* If we're about to read full symbols, don't bother with the
5785 indices. In this case we also don't care if some other debug
5786 format is making psymtabs, because they are all about to be
5788 if ((objfile
->flags
& OBJF_READNOW
))
5790 dwarf2_per_objfile
->using_index
= 1;
5791 create_all_comp_units (dwarf2_per_objfile
);
5792 create_all_type_units (dwarf2_per_objfile
);
5793 dwarf2_per_objfile
->quick_file_names_table
5794 = create_quick_file_names_table
5795 (dwarf2_per_objfile
->all_comp_units
.size ());
5797 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5798 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5800 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5802 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5803 struct dwarf2_per_cu_quick_data
);
5806 /* Return 1 so that gdb sees the "quick" functions. However,
5807 these functions will be no-ops because we will have expanded
5809 *index_kind
= dw_index_kind::GDB_INDEX
;
5813 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5815 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5819 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5820 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5821 get_gdb_index_contents_from_section
<dwz_file
>))
5823 *index_kind
= dw_index_kind::GDB_INDEX
;
5827 /* ... otherwise, try to find the index in the index cache. */
5828 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5829 get_gdb_index_contents_from_cache
,
5830 get_gdb_index_contents_from_cache_dwz
))
5832 global_index_cache
.hit ();
5833 *index_kind
= dw_index_kind::GDB_INDEX
;
5837 global_index_cache
.miss ();
5843 /* Build a partial symbol table. */
5846 dwarf2_build_psymtabs (struct objfile
*objfile
)
5848 struct dwarf2_per_objfile
*dwarf2_per_objfile
5849 = get_dwarf2_per_objfile (objfile
);
5851 init_psymbol_list (objfile
, 1024);
5855 /* This isn't really ideal: all the data we allocate on the
5856 objfile's obstack is still uselessly kept around. However,
5857 freeing it seems unsafe. */
5858 psymtab_discarder
psymtabs (objfile
);
5859 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5862 /* (maybe) store an index in the cache. */
5863 global_index_cache
.store (dwarf2_per_objfile
);
5865 catch (const gdb_exception_error
&except
)
5867 exception_print (gdb_stderr
, except
);
5871 /* Find the base address of the compilation unit for range lists and
5872 location lists. It will normally be specified by DW_AT_low_pc.
5873 In DWARF-3 draft 4, the base address could be overridden by
5874 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5875 compilation units with discontinuous ranges. */
5878 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5880 struct attribute
*attr
;
5882 cu
->base_address
.reset ();
5884 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5885 if (attr
!= nullptr)
5886 cu
->base_address
= attr
->value_as_address ();
5889 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5890 if (attr
!= nullptr)
5891 cu
->base_address
= attr
->value_as_address ();
5895 /* Helper function that returns the proper abbrev section for
5898 static struct dwarf2_section_info
*
5899 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5901 struct dwarf2_section_info
*abbrev
;
5902 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5904 if (this_cu
->is_dwz
)
5905 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5907 abbrev
= &dwarf2_per_objfile
->abbrev
;
5912 /* Fetch the abbreviation table offset from a comp or type unit header. */
5915 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5916 struct dwarf2_section_info
*section
,
5917 sect_offset sect_off
)
5919 bfd
*abfd
= section
->get_bfd_owner ();
5920 const gdb_byte
*info_ptr
;
5921 unsigned int initial_length_size
, offset_size
;
5924 section
->read (dwarf2_per_objfile
->objfile
);
5925 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5926 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5927 offset_size
= initial_length_size
== 4 ? 4 : 8;
5928 info_ptr
+= initial_length_size
;
5930 version
= read_2_bytes (abfd
, info_ptr
);
5934 /* Skip unit type and address size. */
5938 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5941 /* A partial symtab that is used only for include files. */
5942 struct dwarf2_include_psymtab
: public partial_symtab
5944 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5945 : partial_symtab (filename
, objfile
)
5949 void read_symtab (struct objfile
*objfile
) override
5951 /* It's an include file, no symbols to read for it.
5952 Everything is in the includer symtab. */
5954 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5955 expansion of the includer psymtab. We use the dependencies[0] field to
5956 model the includer. But if we go the regular route of calling
5957 expand_psymtab here, and having expand_psymtab call expand_dependencies
5958 to expand the includer, we'll only use expand_psymtab on the includer
5959 (making it a non-toplevel psymtab), while if we expand the includer via
5960 another path, we'll use read_symtab (making it a toplevel psymtab).
5961 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5962 psymtab, and trigger read_symtab on the includer here directly. */
5963 includer ()->read_symtab (objfile
);
5966 void expand_psymtab (struct objfile
*objfile
) override
5968 /* This is not called by read_symtab, and should not be called by any
5969 expand_dependencies. */
5973 bool readin_p () const override
5975 return includer ()->readin_p ();
5978 struct compunit_symtab
*get_compunit_symtab () const override
5984 partial_symtab
*includer () const
5986 /* An include psymtab has exactly one dependency: the psymtab that
5988 gdb_assert (this->number_of_dependencies
== 1);
5989 return this->dependencies
[0];
5993 /* Allocate a new partial symtab for file named NAME and mark this new
5994 partial symtab as being an include of PST. */
5997 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5998 struct objfile
*objfile
)
6000 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6002 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6004 /* It shares objfile->objfile_obstack. */
6005 subpst
->dirname
= pst
->dirname
;
6008 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6009 subpst
->dependencies
[0] = pst
;
6010 subpst
->number_of_dependencies
= 1;
6013 /* Read the Line Number Program data and extract the list of files
6014 included by the source file represented by PST. Build an include
6015 partial symtab for each of these included files. */
6018 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6019 struct die_info
*die
,
6020 dwarf2_psymtab
*pst
)
6023 struct attribute
*attr
;
6025 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6026 if (attr
!= nullptr)
6027 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6029 return; /* No linetable, so no includes. */
6031 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6032 that we pass in the raw text_low here; that is ok because we're
6033 only decoding the line table to make include partial symtabs, and
6034 so the addresses aren't really used. */
6035 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6036 pst
->raw_text_low (), 1);
6040 hash_signatured_type (const void *item
)
6042 const struct signatured_type
*sig_type
6043 = (const struct signatured_type
*) item
;
6045 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6046 return sig_type
->signature
;
6050 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6052 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6053 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6055 return lhs
->signature
== rhs
->signature
;
6058 /* Allocate a hash table for signatured types. */
6061 allocate_signatured_type_table ()
6063 return htab_up (htab_create_alloc (41,
6064 hash_signatured_type
,
6066 NULL
, xcalloc
, xfree
));
6069 /* A helper function to add a signatured type CU to a table. */
6072 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6074 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6075 std::vector
<signatured_type
*> *all_type_units
6076 = (std::vector
<signatured_type
*> *) datum
;
6078 all_type_units
->push_back (sigt
);
6083 /* A helper for create_debug_types_hash_table. Read types from SECTION
6084 and fill them into TYPES_HTAB. It will process only type units,
6085 therefore DW_UT_type. */
6088 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6089 struct dwo_file
*dwo_file
,
6090 dwarf2_section_info
*section
, htab_up
&types_htab
,
6091 rcuh_kind section_kind
)
6093 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6094 struct dwarf2_section_info
*abbrev_section
;
6096 const gdb_byte
*info_ptr
, *end_ptr
;
6098 abbrev_section
= (dwo_file
!= NULL
6099 ? &dwo_file
->sections
.abbrev
6100 : &dwarf2_per_objfile
->abbrev
);
6102 if (dwarf_read_debug
)
6103 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6104 section
->get_name (),
6105 abbrev_section
->get_file_name ());
6107 section
->read (objfile
);
6108 info_ptr
= section
->buffer
;
6110 if (info_ptr
== NULL
)
6113 /* We can't set abfd until now because the section may be empty or
6114 not present, in which case the bfd is unknown. */
6115 abfd
= section
->get_bfd_owner ();
6117 /* We don't use cutu_reader here because we don't need to read
6118 any dies: the signature is in the header. */
6120 end_ptr
= info_ptr
+ section
->size
;
6121 while (info_ptr
< end_ptr
)
6123 struct signatured_type
*sig_type
;
6124 struct dwo_unit
*dwo_tu
;
6126 const gdb_byte
*ptr
= info_ptr
;
6127 struct comp_unit_head header
;
6128 unsigned int length
;
6130 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6132 /* Initialize it due to a false compiler warning. */
6133 header
.signature
= -1;
6134 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6136 /* We need to read the type's signature in order to build the hash
6137 table, but we don't need anything else just yet. */
6139 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6140 abbrev_section
, ptr
, section_kind
);
6142 length
= header
.get_length ();
6144 /* Skip dummy type units. */
6145 if (ptr
>= info_ptr
+ length
6146 || peek_abbrev_code (abfd
, ptr
) == 0
6147 || header
.unit_type
!= DW_UT_type
)
6153 if (types_htab
== NULL
)
6156 types_htab
= allocate_dwo_unit_table ();
6158 types_htab
= allocate_signatured_type_table ();
6164 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6166 dwo_tu
->dwo_file
= dwo_file
;
6167 dwo_tu
->signature
= header
.signature
;
6168 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6169 dwo_tu
->section
= section
;
6170 dwo_tu
->sect_off
= sect_off
;
6171 dwo_tu
->length
= length
;
6175 /* N.B.: type_offset is not usable if this type uses a DWO file.
6176 The real type_offset is in the DWO file. */
6178 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6179 struct signatured_type
);
6180 sig_type
->signature
= header
.signature
;
6181 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6182 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6183 sig_type
->per_cu
.is_debug_types
= 1;
6184 sig_type
->per_cu
.section
= section
;
6185 sig_type
->per_cu
.sect_off
= sect_off
;
6186 sig_type
->per_cu
.length
= length
;
6189 slot
= htab_find_slot (types_htab
.get (),
6190 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6192 gdb_assert (slot
!= NULL
);
6195 sect_offset dup_sect_off
;
6199 const struct dwo_unit
*dup_tu
6200 = (const struct dwo_unit
*) *slot
;
6202 dup_sect_off
= dup_tu
->sect_off
;
6206 const struct signatured_type
*dup_tu
6207 = (const struct signatured_type
*) *slot
;
6209 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6212 complaint (_("debug type entry at offset %s is duplicate to"
6213 " the entry at offset %s, signature %s"),
6214 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6215 hex_string (header
.signature
));
6217 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6219 if (dwarf_read_debug
> 1)
6220 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6221 sect_offset_str (sect_off
),
6222 hex_string (header
.signature
));
6228 /* Create the hash table of all entries in the .debug_types
6229 (or .debug_types.dwo) section(s).
6230 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6231 otherwise it is NULL.
6233 The result is a pointer to the hash table or NULL if there are no types.
6235 Note: This function processes DWO files only, not DWP files. */
6238 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6239 struct dwo_file
*dwo_file
,
6240 gdb::array_view
<dwarf2_section_info
> type_sections
,
6241 htab_up
&types_htab
)
6243 for (dwarf2_section_info
§ion
: type_sections
)
6244 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6245 types_htab
, rcuh_kind::TYPE
);
6248 /* Create the hash table of all entries in the .debug_types section,
6249 and initialize all_type_units.
6250 The result is zero if there is an error (e.g. missing .debug_types section),
6251 otherwise non-zero. */
6254 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6258 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6259 &dwarf2_per_objfile
->info
, types_htab
,
6260 rcuh_kind::COMPILE
);
6261 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6262 dwarf2_per_objfile
->types
, types_htab
);
6263 if (types_htab
== NULL
)
6265 dwarf2_per_objfile
->signatured_types
= NULL
;
6269 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6271 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6272 dwarf2_per_objfile
->all_type_units
.reserve
6273 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6275 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6276 add_signatured_type_cu_to_table
,
6277 &dwarf2_per_objfile
->all_type_units
);
6282 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6283 If SLOT is non-NULL, it is the entry to use in the hash table.
6284 Otherwise we find one. */
6286 static struct signatured_type
*
6287 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6290 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6292 if (dwarf2_per_objfile
->all_type_units
.size ()
6293 == dwarf2_per_objfile
->all_type_units
.capacity ())
6294 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6296 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6297 struct signatured_type
);
6299 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6300 sig_type
->signature
= sig
;
6301 sig_type
->per_cu
.is_debug_types
= 1;
6302 if (dwarf2_per_objfile
->using_index
)
6304 sig_type
->per_cu
.v
.quick
=
6305 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6306 struct dwarf2_per_cu_quick_data
);
6311 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6314 gdb_assert (*slot
== NULL
);
6316 /* The rest of sig_type must be filled in by the caller. */
6320 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6321 Fill in SIG_ENTRY with DWO_ENTRY. */
6324 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6325 struct signatured_type
*sig_entry
,
6326 struct dwo_unit
*dwo_entry
)
6328 /* Make sure we're not clobbering something we don't expect to. */
6329 gdb_assert (! sig_entry
->per_cu
.queued
);
6330 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6331 if (dwarf2_per_objfile
->using_index
)
6333 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6334 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6337 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6338 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6339 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6340 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6341 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6343 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6344 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6345 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6346 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6347 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6348 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6349 sig_entry
->dwo_unit
= dwo_entry
;
6352 /* Subroutine of lookup_signatured_type.
6353 If we haven't read the TU yet, create the signatured_type data structure
6354 for a TU to be read in directly from a DWO file, bypassing the stub.
6355 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6356 using .gdb_index, then when reading a CU we want to stay in the DWO file
6357 containing that CU. Otherwise we could end up reading several other DWO
6358 files (due to comdat folding) to process the transitive closure of all the
6359 mentioned TUs, and that can be slow. The current DWO file will have every
6360 type signature that it needs.
6361 We only do this for .gdb_index because in the psymtab case we already have
6362 to read all the DWOs to build the type unit groups. */
6364 static struct signatured_type
*
6365 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6367 struct dwarf2_per_objfile
*dwarf2_per_objfile
6368 = cu
->per_cu
->dwarf2_per_objfile
;
6369 struct dwo_file
*dwo_file
;
6370 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6371 struct signatured_type find_sig_entry
, *sig_entry
;
6374 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6376 /* If TU skeletons have been removed then we may not have read in any
6378 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6379 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6381 /* We only ever need to read in one copy of a signatured type.
6382 Use the global signatured_types array to do our own comdat-folding
6383 of types. If this is the first time we're reading this TU, and
6384 the TU has an entry in .gdb_index, replace the recorded data from
6385 .gdb_index with this TU. */
6387 find_sig_entry
.signature
= sig
;
6388 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6389 &find_sig_entry
, INSERT
);
6390 sig_entry
= (struct signatured_type
*) *slot
;
6392 /* We can get here with the TU already read, *or* in the process of being
6393 read. Don't reassign the global entry to point to this DWO if that's
6394 the case. Also note that if the TU is already being read, it may not
6395 have come from a DWO, the program may be a mix of Fission-compiled
6396 code and non-Fission-compiled code. */
6398 /* Have we already tried to read this TU?
6399 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6400 needn't exist in the global table yet). */
6401 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6404 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6405 dwo_unit of the TU itself. */
6406 dwo_file
= cu
->dwo_unit
->dwo_file
;
6408 /* Ok, this is the first time we're reading this TU. */
6409 if (dwo_file
->tus
== NULL
)
6411 find_dwo_entry
.signature
= sig
;
6412 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6414 if (dwo_entry
== NULL
)
6417 /* If the global table doesn't have an entry for this TU, add one. */
6418 if (sig_entry
== NULL
)
6419 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6421 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6422 sig_entry
->per_cu
.tu_read
= 1;
6426 /* Subroutine of lookup_signatured_type.
6427 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6428 then try the DWP file. If the TU stub (skeleton) has been removed then
6429 it won't be in .gdb_index. */
6431 static struct signatured_type
*
6432 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6434 struct dwarf2_per_objfile
*dwarf2_per_objfile
6435 = cu
->per_cu
->dwarf2_per_objfile
;
6436 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6437 struct dwo_unit
*dwo_entry
;
6438 struct signatured_type find_sig_entry
, *sig_entry
;
6441 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6442 gdb_assert (dwp_file
!= NULL
);
6444 /* If TU skeletons have been removed then we may not have read in any
6446 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6447 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6449 find_sig_entry
.signature
= sig
;
6450 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6451 &find_sig_entry
, INSERT
);
6452 sig_entry
= (struct signatured_type
*) *slot
;
6454 /* Have we already tried to read this TU?
6455 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6456 needn't exist in the global table yet). */
6457 if (sig_entry
!= NULL
)
6460 if (dwp_file
->tus
== NULL
)
6462 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6463 sig
, 1 /* is_debug_types */);
6464 if (dwo_entry
== NULL
)
6467 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6468 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6473 /* Lookup a signature based type for DW_FORM_ref_sig8.
6474 Returns NULL if signature SIG is not present in the table.
6475 It is up to the caller to complain about this. */
6477 static struct signatured_type
*
6478 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6480 struct dwarf2_per_objfile
*dwarf2_per_objfile
6481 = cu
->per_cu
->dwarf2_per_objfile
;
6484 && dwarf2_per_objfile
->using_index
)
6486 /* We're in a DWO/DWP file, and we're using .gdb_index.
6487 These cases require special processing. */
6488 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6489 return lookup_dwo_signatured_type (cu
, sig
);
6491 return lookup_dwp_signatured_type (cu
, sig
);
6495 struct signatured_type find_entry
, *entry
;
6497 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6499 find_entry
.signature
= sig
;
6500 entry
= ((struct signatured_type
*)
6501 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6507 /* Low level DIE reading support. */
6509 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6512 init_cu_die_reader (struct die_reader_specs
*reader
,
6513 struct dwarf2_cu
*cu
,
6514 struct dwarf2_section_info
*section
,
6515 struct dwo_file
*dwo_file
,
6516 struct abbrev_table
*abbrev_table
)
6518 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6519 reader
->abfd
= section
->get_bfd_owner ();
6521 reader
->dwo_file
= dwo_file
;
6522 reader
->die_section
= section
;
6523 reader
->buffer
= section
->buffer
;
6524 reader
->buffer_end
= section
->buffer
+ section
->size
;
6525 reader
->abbrev_table
= abbrev_table
;
6528 /* Subroutine of cutu_reader to simplify it.
6529 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6530 There's just a lot of work to do, and cutu_reader is big enough
6533 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6534 from it to the DIE in the DWO. If NULL we are skipping the stub.
6535 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6536 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6537 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6538 STUB_COMP_DIR may be non-NULL.
6539 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6540 are filled in with the info of the DIE from the DWO file.
6541 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6542 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6543 kept around for at least as long as *RESULT_READER.
6545 The result is non-zero if a valid (non-dummy) DIE was found. */
6548 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6549 struct dwo_unit
*dwo_unit
,
6550 struct die_info
*stub_comp_unit_die
,
6551 const char *stub_comp_dir
,
6552 struct die_reader_specs
*result_reader
,
6553 const gdb_byte
**result_info_ptr
,
6554 struct die_info
**result_comp_unit_die
,
6555 abbrev_table_up
*result_dwo_abbrev_table
)
6557 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6558 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6559 struct dwarf2_cu
*cu
= this_cu
->cu
;
6561 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6562 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6563 int i
,num_extra_attrs
;
6564 struct dwarf2_section_info
*dwo_abbrev_section
;
6565 struct die_info
*comp_unit_die
;
6567 /* At most one of these may be provided. */
6568 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6570 /* These attributes aren't processed until later:
6571 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6572 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6573 referenced later. However, these attributes are found in the stub
6574 which we won't have later. In order to not impose this complication
6575 on the rest of the code, we read them here and copy them to the
6584 if (stub_comp_unit_die
!= NULL
)
6586 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6588 if (! this_cu
->is_debug_types
)
6589 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6590 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6591 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6592 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6593 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6595 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6597 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6598 here (if needed). We need the value before we can process
6600 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6602 else if (stub_comp_dir
!= NULL
)
6604 /* Reconstruct the comp_dir attribute to simplify the code below. */
6605 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6606 comp_dir
->name
= DW_AT_comp_dir
;
6607 comp_dir
->form
= DW_FORM_string
;
6608 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6609 DW_STRING (comp_dir
) = stub_comp_dir
;
6612 /* Set up for reading the DWO CU/TU. */
6613 cu
->dwo_unit
= dwo_unit
;
6614 dwarf2_section_info
*section
= dwo_unit
->section
;
6615 section
->read (objfile
);
6616 abfd
= section
->get_bfd_owner ();
6617 begin_info_ptr
= info_ptr
= (section
->buffer
6618 + to_underlying (dwo_unit
->sect_off
));
6619 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6621 if (this_cu
->is_debug_types
)
6623 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6625 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6626 &cu
->header
, section
,
6628 info_ptr
, rcuh_kind::TYPE
);
6629 /* This is not an assert because it can be caused by bad debug info. */
6630 if (sig_type
->signature
!= cu
->header
.signature
)
6632 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6633 " TU at offset %s [in module %s]"),
6634 hex_string (sig_type
->signature
),
6635 hex_string (cu
->header
.signature
),
6636 sect_offset_str (dwo_unit
->sect_off
),
6637 bfd_get_filename (abfd
));
6639 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6640 /* For DWOs coming from DWP files, we don't know the CU length
6641 nor the type's offset in the TU until now. */
6642 dwo_unit
->length
= cu
->header
.get_length ();
6643 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6645 /* Establish the type offset that can be used to lookup the type.
6646 For DWO files, we don't know it until now. */
6647 sig_type
->type_offset_in_section
6648 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6652 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6653 &cu
->header
, section
,
6655 info_ptr
, rcuh_kind::COMPILE
);
6656 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6657 /* For DWOs coming from DWP files, we don't know the CU length
6659 dwo_unit
->length
= cu
->header
.get_length ();
6662 *result_dwo_abbrev_table
6663 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6664 cu
->header
.abbrev_sect_off
);
6665 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6666 result_dwo_abbrev_table
->get ());
6668 /* Read in the die, but leave space to copy over the attributes
6669 from the stub. This has the benefit of simplifying the rest of
6670 the code - all the work to maintain the illusion of a single
6671 DW_TAG_{compile,type}_unit DIE is done here. */
6672 num_extra_attrs
= ((stmt_list
!= NULL
)
6676 + (comp_dir
!= NULL
));
6677 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6680 /* Copy over the attributes from the stub to the DIE we just read in. */
6681 comp_unit_die
= *result_comp_unit_die
;
6682 i
= comp_unit_die
->num_attrs
;
6683 if (stmt_list
!= NULL
)
6684 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6686 comp_unit_die
->attrs
[i
++] = *low_pc
;
6687 if (high_pc
!= NULL
)
6688 comp_unit_die
->attrs
[i
++] = *high_pc
;
6690 comp_unit_die
->attrs
[i
++] = *ranges
;
6691 if (comp_dir
!= NULL
)
6692 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6693 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6695 if (dwarf_die_debug
)
6697 fprintf_unfiltered (gdb_stdlog
,
6698 "Read die from %s@0x%x of %s:\n",
6699 section
->get_name (),
6700 (unsigned) (begin_info_ptr
- section
->buffer
),
6701 bfd_get_filename (abfd
));
6702 dump_die (comp_unit_die
, dwarf_die_debug
);
6705 /* Skip dummy compilation units. */
6706 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6707 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6710 *result_info_ptr
= info_ptr
;
6714 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6715 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6716 signature is part of the header. */
6717 static gdb::optional
<ULONGEST
>
6718 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6720 if (cu
->header
.version
>= 5)
6721 return cu
->header
.signature
;
6722 struct attribute
*attr
;
6723 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6724 if (attr
== nullptr)
6725 return gdb::optional
<ULONGEST
> ();
6726 return DW_UNSND (attr
);
6729 /* Subroutine of cutu_reader to simplify it.
6730 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6731 Returns NULL if the specified DWO unit cannot be found. */
6733 static struct dwo_unit
*
6734 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6735 struct die_info
*comp_unit_die
,
6736 const char *dwo_name
)
6738 struct dwarf2_cu
*cu
= this_cu
->cu
;
6739 struct dwo_unit
*dwo_unit
;
6740 const char *comp_dir
;
6742 gdb_assert (cu
!= NULL
);
6744 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6745 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6746 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6748 if (this_cu
->is_debug_types
)
6750 struct signatured_type
*sig_type
;
6752 /* Since this_cu is the first member of struct signatured_type,
6753 we can go from a pointer to one to a pointer to the other. */
6754 sig_type
= (struct signatured_type
*) this_cu
;
6755 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6759 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6760 if (!signature
.has_value ())
6761 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6763 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6764 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6771 /* Subroutine of cutu_reader to simplify it.
6772 See it for a description of the parameters.
6773 Read a TU directly from a DWO file, bypassing the stub. */
6776 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6777 int use_existing_cu
)
6779 struct signatured_type
*sig_type
;
6781 /* Verify we can do the following downcast, and that we have the
6783 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6784 sig_type
= (struct signatured_type
*) this_cu
;
6785 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6787 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6789 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6790 /* There's no need to do the rereading_dwo_cu handling that
6791 cutu_reader does since we don't read the stub. */
6795 /* If !use_existing_cu, this_cu->cu must be NULL. */
6796 gdb_assert (this_cu
->cu
== NULL
);
6797 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6800 /* A future optimization, if needed, would be to use an existing
6801 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6802 could share abbrev tables. */
6804 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6805 NULL
/* stub_comp_unit_die */,
6806 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6809 &m_dwo_abbrev_table
) == 0)
6816 /* Initialize a CU (or TU) and read its DIEs.
6817 If the CU defers to a DWO file, read the DWO file as well.
6819 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6820 Otherwise the table specified in the comp unit header is read in and used.
6821 This is an optimization for when we already have the abbrev table.
6823 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6824 Otherwise, a new CU is allocated with xmalloc. */
6826 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6827 struct abbrev_table
*abbrev_table
,
6828 int use_existing_cu
,
6830 : die_reader_specs
{},
6833 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6834 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6835 struct dwarf2_section_info
*section
= this_cu
->section
;
6836 bfd
*abfd
= section
->get_bfd_owner ();
6837 struct dwarf2_cu
*cu
;
6838 const gdb_byte
*begin_info_ptr
;
6839 struct signatured_type
*sig_type
= NULL
;
6840 struct dwarf2_section_info
*abbrev_section
;
6841 /* Non-zero if CU currently points to a DWO file and we need to
6842 reread it. When this happens we need to reread the skeleton die
6843 before we can reread the DWO file (this only applies to CUs, not TUs). */
6844 int rereading_dwo_cu
= 0;
6846 if (dwarf_die_debug
)
6847 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6848 this_cu
->is_debug_types
? "type" : "comp",
6849 sect_offset_str (this_cu
->sect_off
));
6851 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6852 file (instead of going through the stub), short-circuit all of this. */
6853 if (this_cu
->reading_dwo_directly
)
6855 /* Narrow down the scope of possibilities to have to understand. */
6856 gdb_assert (this_cu
->is_debug_types
);
6857 gdb_assert (abbrev_table
== NULL
);
6858 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6862 /* This is cheap if the section is already read in. */
6863 section
->read (objfile
);
6865 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6867 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6869 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6872 /* If this CU is from a DWO file we need to start over, we need to
6873 refetch the attributes from the skeleton CU.
6874 This could be optimized by retrieving those attributes from when we
6875 were here the first time: the previous comp_unit_die was stored in
6876 comp_unit_obstack. But there's no data yet that we need this
6878 if (cu
->dwo_unit
!= NULL
)
6879 rereading_dwo_cu
= 1;
6883 /* If !use_existing_cu, this_cu->cu must be NULL. */
6884 gdb_assert (this_cu
->cu
== NULL
);
6885 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6886 cu
= m_new_cu
.get ();
6889 /* Get the header. */
6890 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6892 /* We already have the header, there's no need to read it in again. */
6893 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6897 if (this_cu
->is_debug_types
)
6899 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6900 &cu
->header
, section
,
6901 abbrev_section
, info_ptr
,
6904 /* Since per_cu is the first member of struct signatured_type,
6905 we can go from a pointer to one to a pointer to the other. */
6906 sig_type
= (struct signatured_type
*) this_cu
;
6907 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6908 gdb_assert (sig_type
->type_offset_in_tu
6909 == cu
->header
.type_cu_offset_in_tu
);
6910 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6912 /* LENGTH has not been set yet for type units if we're
6913 using .gdb_index. */
6914 this_cu
->length
= cu
->header
.get_length ();
6916 /* Establish the type offset that can be used to lookup the type. */
6917 sig_type
->type_offset_in_section
=
6918 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6920 this_cu
->dwarf_version
= cu
->header
.version
;
6924 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6925 &cu
->header
, section
,
6928 rcuh_kind::COMPILE
);
6930 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6931 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6932 this_cu
->dwarf_version
= cu
->header
.version
;
6936 /* Skip dummy compilation units. */
6937 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6938 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6944 /* If we don't have them yet, read the abbrevs for this compilation unit.
6945 And if we need to read them now, make sure they're freed when we're
6947 if (abbrev_table
!= NULL
)
6948 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6951 m_abbrev_table_holder
6952 = abbrev_table::read (objfile
, abbrev_section
,
6953 cu
->header
.abbrev_sect_off
);
6954 abbrev_table
= m_abbrev_table_holder
.get ();
6957 /* Read the top level CU/TU die. */
6958 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6959 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6961 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6967 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6968 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6969 table from the DWO file and pass the ownership over to us. It will be
6970 referenced from READER, so we must make sure to free it after we're done
6973 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6974 DWO CU, that this test will fail (the attribute will not be present). */
6975 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6976 if (dwo_name
!= nullptr)
6978 struct dwo_unit
*dwo_unit
;
6979 struct die_info
*dwo_comp_unit_die
;
6981 if (comp_unit_die
->has_children
)
6983 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6984 " has children (offset %s) [in module %s]"),
6985 sect_offset_str (this_cu
->sect_off
),
6986 bfd_get_filename (abfd
));
6988 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6989 if (dwo_unit
!= NULL
)
6991 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6992 comp_unit_die
, NULL
,
6995 &m_dwo_abbrev_table
) == 0)
7001 comp_unit_die
= dwo_comp_unit_die
;
7005 /* Yikes, we couldn't find the rest of the DIE, we only have
7006 the stub. A complaint has already been logged. There's
7007 not much more we can do except pass on the stub DIE to
7008 die_reader_func. We don't want to throw an error on bad
7015 cutu_reader::keep ()
7017 /* Done, clean up. */
7018 gdb_assert (!dummy_p
);
7019 if (m_new_cu
!= NULL
)
7021 struct dwarf2_per_objfile
*dwarf2_per_objfile
7022 = m_this_cu
->dwarf2_per_objfile
;
7023 /* Link this CU into read_in_chain. */
7024 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7025 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7026 /* The chain owns it now. */
7027 m_new_cu
.release ();
7031 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7032 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7033 assumed to have already done the lookup to find the DWO file).
7035 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7036 THIS_CU->is_debug_types, but nothing else.
7038 We fill in THIS_CU->length.
7040 THIS_CU->cu is always freed when done.
7041 This is done in order to not leave THIS_CU->cu in a state where we have
7042 to care whether it refers to the "main" CU or the DWO CU.
7044 When parent_cu is passed, it is used to provide a default value for
7045 str_offsets_base and addr_base from the parent. */
7047 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7048 struct dwarf2_cu
*parent_cu
,
7049 struct dwo_file
*dwo_file
)
7050 : die_reader_specs
{},
7053 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7054 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7055 struct dwarf2_section_info
*section
= this_cu
->section
;
7056 bfd
*abfd
= section
->get_bfd_owner ();
7057 struct dwarf2_section_info
*abbrev_section
;
7058 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7060 if (dwarf_die_debug
)
7061 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7062 this_cu
->is_debug_types
? "type" : "comp",
7063 sect_offset_str (this_cu
->sect_off
));
7065 gdb_assert (this_cu
->cu
== NULL
);
7067 abbrev_section
= (dwo_file
!= NULL
7068 ? &dwo_file
->sections
.abbrev
7069 : get_abbrev_section_for_cu (this_cu
));
7071 /* This is cheap if the section is already read in. */
7072 section
->read (objfile
);
7074 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7076 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7077 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7078 &m_new_cu
->header
, section
,
7079 abbrev_section
, info_ptr
,
7080 (this_cu
->is_debug_types
7082 : rcuh_kind::COMPILE
));
7084 if (parent_cu
!= nullptr)
7086 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7087 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7089 this_cu
->length
= m_new_cu
->header
.get_length ();
7091 /* Skip dummy compilation units. */
7092 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7093 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7099 m_abbrev_table_holder
7100 = abbrev_table::read (objfile
, abbrev_section
,
7101 m_new_cu
->header
.abbrev_sect_off
);
7103 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7104 m_abbrev_table_holder
.get ());
7105 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7109 /* Type Unit Groups.
7111 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7112 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7113 so that all types coming from the same compilation (.o file) are grouped
7114 together. A future step could be to put the types in the same symtab as
7115 the CU the types ultimately came from. */
7118 hash_type_unit_group (const void *item
)
7120 const struct type_unit_group
*tu_group
7121 = (const struct type_unit_group
*) item
;
7123 return hash_stmt_list_entry (&tu_group
->hash
);
7127 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7129 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7130 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7132 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7135 /* Allocate a hash table for type unit groups. */
7138 allocate_type_unit_groups_table ()
7140 return htab_up (htab_create_alloc (3,
7141 hash_type_unit_group
,
7143 NULL
, xcalloc
, xfree
));
7146 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7147 partial symtabs. We combine several TUs per psymtab to not let the size
7148 of any one psymtab grow too big. */
7149 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7150 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7152 /* Helper routine for get_type_unit_group.
7153 Create the type_unit_group object used to hold one or more TUs. */
7155 static struct type_unit_group
*
7156 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7158 struct dwarf2_per_objfile
*dwarf2_per_objfile
7159 = cu
->per_cu
->dwarf2_per_objfile
;
7160 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7161 struct dwarf2_per_cu_data
*per_cu
;
7162 struct type_unit_group
*tu_group
;
7164 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7165 struct type_unit_group
);
7166 per_cu
= &tu_group
->per_cu
;
7167 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7169 if (dwarf2_per_objfile
->using_index
)
7171 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7172 struct dwarf2_per_cu_quick_data
);
7176 unsigned int line_offset
= to_underlying (line_offset_struct
);
7177 dwarf2_psymtab
*pst
;
7180 /* Give the symtab a useful name for debug purposes. */
7181 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7182 name
= string_printf ("<type_units_%d>",
7183 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7185 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7187 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7188 pst
->anonymous
= true;
7191 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7192 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7197 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7198 STMT_LIST is a DW_AT_stmt_list attribute. */
7200 static struct type_unit_group
*
7201 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7203 struct dwarf2_per_objfile
*dwarf2_per_objfile
7204 = cu
->per_cu
->dwarf2_per_objfile
;
7205 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7206 struct type_unit_group
*tu_group
;
7208 unsigned int line_offset
;
7209 struct type_unit_group type_unit_group_for_lookup
;
7211 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7212 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7214 /* Do we need to create a new group, or can we use an existing one? */
7218 line_offset
= DW_UNSND (stmt_list
);
7219 ++tu_stats
->nr_symtab_sharers
;
7223 /* Ugh, no stmt_list. Rare, but we have to handle it.
7224 We can do various things here like create one group per TU or
7225 spread them over multiple groups to split up the expansion work.
7226 To avoid worst case scenarios (too many groups or too large groups)
7227 we, umm, group them in bunches. */
7228 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7229 | (tu_stats
->nr_stmt_less_type_units
7230 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7231 ++tu_stats
->nr_stmt_less_type_units
;
7234 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7235 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7236 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7237 &type_unit_group_for_lookup
, INSERT
);
7240 tu_group
= (struct type_unit_group
*) *slot
;
7241 gdb_assert (tu_group
!= NULL
);
7245 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7246 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7248 ++tu_stats
->nr_symtabs
;
7254 /* Partial symbol tables. */
7256 /* Create a psymtab named NAME and assign it to PER_CU.
7258 The caller must fill in the following details:
7259 dirname, textlow, texthigh. */
7261 static dwarf2_psymtab
*
7262 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7264 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7265 dwarf2_psymtab
*pst
;
7267 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7269 pst
->psymtabs_addrmap_supported
= true;
7271 /* This is the glue that links PST into GDB's symbol API. */
7272 per_cu
->v
.psymtab
= pst
;
7277 /* DIE reader function for process_psymtab_comp_unit. */
7280 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7281 const gdb_byte
*info_ptr
,
7282 struct die_info
*comp_unit_die
,
7283 enum language pretend_language
)
7285 struct dwarf2_cu
*cu
= reader
->cu
;
7286 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7287 struct gdbarch
*gdbarch
= objfile
->arch ();
7288 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7290 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7291 dwarf2_psymtab
*pst
;
7292 enum pc_bounds_kind cu_bounds_kind
;
7293 const char *filename
;
7295 gdb_assert (! per_cu
->is_debug_types
);
7297 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7299 /* Allocate a new partial symbol table structure. */
7300 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7301 static const char artificial
[] = "<artificial>";
7302 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7303 if (filename
== NULL
)
7305 else if (strcmp (filename
, artificial
) == 0)
7307 debug_filename
.reset (concat (artificial
, "@",
7308 sect_offset_str (per_cu
->sect_off
),
7310 filename
= debug_filename
.get ();
7313 pst
= create_partial_symtab (per_cu
, filename
);
7315 /* This must be done before calling dwarf2_build_include_psymtabs. */
7316 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7318 baseaddr
= objfile
->text_section_offset ();
7320 dwarf2_find_base_address (comp_unit_die
, cu
);
7322 /* Possibly set the default values of LOWPC and HIGHPC from
7324 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7325 &best_highpc
, cu
, pst
);
7326 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7329 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7332 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7334 /* Store the contiguous range if it is not empty; it can be
7335 empty for CUs with no code. */
7336 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7340 /* Check if comp unit has_children.
7341 If so, read the rest of the partial symbols from this comp unit.
7342 If not, there's no more debug_info for this comp unit. */
7343 if (comp_unit_die
->has_children
)
7345 struct partial_die_info
*first_die
;
7346 CORE_ADDR lowpc
, highpc
;
7348 lowpc
= ((CORE_ADDR
) -1);
7349 highpc
= ((CORE_ADDR
) 0);
7351 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7353 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7354 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7356 /* If we didn't find a lowpc, set it to highpc to avoid
7357 complaints from `maint check'. */
7358 if (lowpc
== ((CORE_ADDR
) -1))
7361 /* If the compilation unit didn't have an explicit address range,
7362 then use the information extracted from its child dies. */
7363 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7366 best_highpc
= highpc
;
7369 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7370 best_lowpc
+ baseaddr
)
7372 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7373 best_highpc
+ baseaddr
)
7376 end_psymtab_common (objfile
, pst
);
7378 if (!cu
->per_cu
->imported_symtabs_empty ())
7381 int len
= cu
->per_cu
->imported_symtabs_size ();
7383 /* Fill in 'dependencies' here; we fill in 'users' in a
7385 pst
->number_of_dependencies
= len
;
7387 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7388 for (i
= 0; i
< len
; ++i
)
7390 pst
->dependencies
[i
]
7391 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7394 cu
->per_cu
->imported_symtabs_free ();
7397 /* Get the list of files included in the current compilation unit,
7398 and build a psymtab for each of them. */
7399 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7401 if (dwarf_read_debug
)
7402 fprintf_unfiltered (gdb_stdlog
,
7403 "Psymtab for %s unit @%s: %s - %s"
7404 ", %d global, %d static syms\n",
7405 per_cu
->is_debug_types
? "type" : "comp",
7406 sect_offset_str (per_cu
->sect_off
),
7407 paddress (gdbarch
, pst
->text_low (objfile
)),
7408 paddress (gdbarch
, pst
->text_high (objfile
)),
7409 pst
->n_global_syms
, pst
->n_static_syms
);
7412 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7413 Process compilation unit THIS_CU for a psymtab. */
7416 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7417 bool want_partial_unit
,
7418 enum language pretend_language
)
7420 /* If this compilation unit was already read in, free the
7421 cached copy in order to read it in again. This is
7422 necessary because we skipped some symbols when we first
7423 read in the compilation unit (see load_partial_dies).
7424 This problem could be avoided, but the benefit is unclear. */
7425 if (this_cu
->cu
!= NULL
)
7426 free_one_cached_comp_unit (this_cu
);
7428 cutu_reader
reader (this_cu
, NULL
, 0, false);
7430 switch (reader
.comp_unit_die
->tag
)
7432 case DW_TAG_compile_unit
:
7433 this_cu
->unit_type
= DW_UT_compile
;
7435 case DW_TAG_partial_unit
:
7436 this_cu
->unit_type
= DW_UT_partial
;
7446 else if (this_cu
->is_debug_types
)
7447 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7448 reader
.comp_unit_die
);
7449 else if (want_partial_unit
7450 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7451 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7452 reader
.comp_unit_die
,
7455 this_cu
->lang
= this_cu
->cu
->language
;
7457 /* Age out any secondary CUs. */
7458 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7461 /* Reader function for build_type_psymtabs. */
7464 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7465 const gdb_byte
*info_ptr
,
7466 struct die_info
*type_unit_die
)
7468 struct dwarf2_per_objfile
*dwarf2_per_objfile
7469 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7470 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7471 struct dwarf2_cu
*cu
= reader
->cu
;
7472 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7473 struct signatured_type
*sig_type
;
7474 struct type_unit_group
*tu_group
;
7475 struct attribute
*attr
;
7476 struct partial_die_info
*first_die
;
7477 CORE_ADDR lowpc
, highpc
;
7478 dwarf2_psymtab
*pst
;
7480 gdb_assert (per_cu
->is_debug_types
);
7481 sig_type
= (struct signatured_type
*) per_cu
;
7483 if (! type_unit_die
->has_children
)
7486 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7487 tu_group
= get_type_unit_group (cu
, attr
);
7489 if (tu_group
->tus
== nullptr)
7490 tu_group
->tus
= new std::vector
<signatured_type
*>;
7491 tu_group
->tus
->push_back (sig_type
);
7493 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7494 pst
= create_partial_symtab (per_cu
, "");
7495 pst
->anonymous
= true;
7497 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7499 lowpc
= (CORE_ADDR
) -1;
7500 highpc
= (CORE_ADDR
) 0;
7501 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7503 end_psymtab_common (objfile
, pst
);
7506 /* Struct used to sort TUs by their abbreviation table offset. */
7508 struct tu_abbrev_offset
7510 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7511 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7514 signatured_type
*sig_type
;
7515 sect_offset abbrev_offset
;
7518 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7521 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7522 const struct tu_abbrev_offset
&b
)
7524 return a
.abbrev_offset
< b
.abbrev_offset
;
7527 /* Efficiently read all the type units.
7528 This does the bulk of the work for build_type_psymtabs.
7530 The efficiency is because we sort TUs by the abbrev table they use and
7531 only read each abbrev table once. In one program there are 200K TUs
7532 sharing 8K abbrev tables.
7534 The main purpose of this function is to support building the
7535 dwarf2_per_objfile->type_unit_groups table.
7536 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7537 can collapse the search space by grouping them by stmt_list.
7538 The savings can be significant, in the same program from above the 200K TUs
7539 share 8K stmt_list tables.
7541 FUNC is expected to call get_type_unit_group, which will create the
7542 struct type_unit_group if necessary and add it to
7543 dwarf2_per_objfile->type_unit_groups. */
7546 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7548 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7549 abbrev_table_up abbrev_table
;
7550 sect_offset abbrev_offset
;
7552 /* It's up to the caller to not call us multiple times. */
7553 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7555 if (dwarf2_per_objfile
->all_type_units
.empty ())
7558 /* TUs typically share abbrev tables, and there can be way more TUs than
7559 abbrev tables. Sort by abbrev table to reduce the number of times we
7560 read each abbrev table in.
7561 Alternatives are to punt or to maintain a cache of abbrev tables.
7562 This is simpler and efficient enough for now.
7564 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7565 symtab to use). Typically TUs with the same abbrev offset have the same
7566 stmt_list value too so in practice this should work well.
7568 The basic algorithm here is:
7570 sort TUs by abbrev table
7571 for each TU with same abbrev table:
7572 read abbrev table if first user
7573 read TU top level DIE
7574 [IWBN if DWO skeletons had DW_AT_stmt_list]
7577 if (dwarf_read_debug
)
7578 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7580 /* Sort in a separate table to maintain the order of all_type_units
7581 for .gdb_index: TU indices directly index all_type_units. */
7582 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7583 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7585 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7586 sorted_by_abbrev
.emplace_back
7587 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7588 sig_type
->per_cu
.section
,
7589 sig_type
->per_cu
.sect_off
));
7591 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7592 sort_tu_by_abbrev_offset
);
7594 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7596 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7598 /* Switch to the next abbrev table if necessary. */
7599 if (abbrev_table
== NULL
7600 || tu
.abbrev_offset
!= abbrev_offset
)
7602 abbrev_offset
= tu
.abbrev_offset
;
7604 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7605 &dwarf2_per_objfile
->abbrev
,
7607 ++tu_stats
->nr_uniq_abbrev_tables
;
7610 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7612 if (!reader
.dummy_p
)
7613 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7614 reader
.comp_unit_die
);
7618 /* Print collected type unit statistics. */
7621 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7623 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7625 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7626 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7627 dwarf2_per_objfile
->all_type_units
.size ());
7628 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7629 tu_stats
->nr_uniq_abbrev_tables
);
7630 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7631 tu_stats
->nr_symtabs
);
7632 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7633 tu_stats
->nr_symtab_sharers
);
7634 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7635 tu_stats
->nr_stmt_less_type_units
);
7636 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7637 tu_stats
->nr_all_type_units_reallocs
);
7640 /* Traversal function for build_type_psymtabs. */
7643 build_type_psymtab_dependencies (void **slot
, void *info
)
7645 struct dwarf2_per_objfile
*dwarf2_per_objfile
7646 = (struct dwarf2_per_objfile
*) info
;
7647 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7648 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7649 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7650 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7651 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7654 gdb_assert (len
> 0);
7655 gdb_assert (per_cu
->type_unit_group_p ());
7657 pst
->number_of_dependencies
= len
;
7658 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7659 for (i
= 0; i
< len
; ++i
)
7661 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7662 gdb_assert (iter
->per_cu
.is_debug_types
);
7663 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7664 iter
->type_unit_group
= tu_group
;
7667 delete tu_group
->tus
;
7668 tu_group
->tus
= nullptr;
7673 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7674 Build partial symbol tables for the .debug_types comp-units. */
7677 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7679 if (! create_all_type_units (dwarf2_per_objfile
))
7682 build_type_psymtabs_1 (dwarf2_per_objfile
);
7685 /* Traversal function for process_skeletonless_type_unit.
7686 Read a TU in a DWO file and build partial symbols for it. */
7689 process_skeletonless_type_unit (void **slot
, void *info
)
7691 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7692 struct dwarf2_per_objfile
*dwarf2_per_objfile
7693 = (struct dwarf2_per_objfile
*) info
;
7694 struct signatured_type find_entry
, *entry
;
7696 /* If this TU doesn't exist in the global table, add it and read it in. */
7698 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7699 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7701 find_entry
.signature
= dwo_unit
->signature
;
7702 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7703 &find_entry
, INSERT
);
7704 /* If we've already seen this type there's nothing to do. What's happening
7705 is we're doing our own version of comdat-folding here. */
7709 /* This does the job that create_all_type_units would have done for
7711 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7712 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7715 /* This does the job that build_type_psymtabs_1 would have done. */
7716 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7717 if (!reader
.dummy_p
)
7718 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7719 reader
.comp_unit_die
);
7724 /* Traversal function for process_skeletonless_type_units. */
7727 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7729 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7731 if (dwo_file
->tus
!= NULL
)
7732 htab_traverse_noresize (dwo_file
->tus
.get (),
7733 process_skeletonless_type_unit
, info
);
7738 /* Scan all TUs of DWO files, verifying we've processed them.
7739 This is needed in case a TU was emitted without its skeleton.
7740 Note: This can't be done until we know what all the DWO files are. */
7743 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7745 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7746 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7747 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7749 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7750 process_dwo_file_for_skeletonless_type_units
,
7751 dwarf2_per_objfile
);
7755 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7758 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7760 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7762 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7767 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7769 /* Set the 'user' field only if it is not already set. */
7770 if (pst
->dependencies
[j
]->user
== NULL
)
7771 pst
->dependencies
[j
]->user
= pst
;
7776 /* Build the partial symbol table by doing a quick pass through the
7777 .debug_info and .debug_abbrev sections. */
7780 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7782 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7784 if (dwarf_read_debug
)
7786 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7787 objfile_name (objfile
));
7790 scoped_restore restore_reading_psyms
7791 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7794 dwarf2_per_objfile
->info
.read (objfile
);
7796 /* Any cached compilation units will be linked by the per-objfile
7797 read_in_chain. Make sure to free them when we're done. */
7798 free_cached_comp_units
freer (dwarf2_per_objfile
);
7800 build_type_psymtabs (dwarf2_per_objfile
);
7802 create_all_comp_units (dwarf2_per_objfile
);
7804 /* Create a temporary address map on a temporary obstack. We later
7805 copy this to the final obstack. */
7806 auto_obstack temp_obstack
;
7808 scoped_restore save_psymtabs_addrmap
7809 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7810 addrmap_create_mutable (&temp_obstack
));
7812 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7814 if (per_cu
->v
.psymtab
!= NULL
)
7815 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7817 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7820 /* This has to wait until we read the CUs, we need the list of DWOs. */
7821 process_skeletonless_type_units (dwarf2_per_objfile
);
7823 /* Now that all TUs have been processed we can fill in the dependencies. */
7824 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7826 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7827 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7830 if (dwarf_read_debug
)
7831 print_tu_stats (dwarf2_per_objfile
);
7833 set_partial_user (dwarf2_per_objfile
);
7835 objfile
->partial_symtabs
->psymtabs_addrmap
7836 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7837 objfile
->partial_symtabs
->obstack ());
7838 /* At this point we want to keep the address map. */
7839 save_psymtabs_addrmap
.release ();
7841 if (dwarf_read_debug
)
7842 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7843 objfile_name (objfile
));
7846 /* Load the partial DIEs for a secondary CU into memory.
7847 This is also used when rereading a primary CU with load_all_dies. */
7850 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7852 cutu_reader
reader (this_cu
, NULL
, 1, false);
7854 if (!reader
.dummy_p
)
7856 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7859 /* Check if comp unit has_children.
7860 If so, read the rest of the partial symbols from this comp unit.
7861 If not, there's no more debug_info for this comp unit. */
7862 if (reader
.comp_unit_die
->has_children
)
7863 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7870 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7871 struct dwarf2_section_info
*section
,
7872 struct dwarf2_section_info
*abbrev_section
,
7873 unsigned int is_dwz
)
7875 const gdb_byte
*info_ptr
;
7876 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7878 if (dwarf_read_debug
)
7879 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7880 section
->get_name (),
7881 section
->get_file_name ());
7883 section
->read (objfile
);
7885 info_ptr
= section
->buffer
;
7887 while (info_ptr
< section
->buffer
+ section
->size
)
7889 struct dwarf2_per_cu_data
*this_cu
;
7891 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7893 comp_unit_head cu_header
;
7894 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7895 abbrev_section
, info_ptr
,
7896 rcuh_kind::COMPILE
);
7898 /* Save the compilation unit for later lookup. */
7899 if (cu_header
.unit_type
!= DW_UT_type
)
7901 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7902 struct dwarf2_per_cu_data
);
7903 memset (this_cu
, 0, sizeof (*this_cu
));
7907 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7908 struct signatured_type
);
7909 memset (sig_type
, 0, sizeof (*sig_type
));
7910 sig_type
->signature
= cu_header
.signature
;
7911 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7912 this_cu
= &sig_type
->per_cu
;
7914 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7915 this_cu
->sect_off
= sect_off
;
7916 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7917 this_cu
->is_dwz
= is_dwz
;
7918 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7919 this_cu
->section
= section
;
7921 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7923 info_ptr
= info_ptr
+ this_cu
->length
;
7927 /* Create a list of all compilation units in OBJFILE.
7928 This is only done for -readnow and building partial symtabs. */
7931 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7933 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7934 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7935 &dwarf2_per_objfile
->abbrev
, 0);
7937 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7939 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7943 /* Process all loaded DIEs for compilation unit CU, starting at
7944 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7945 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7946 DW_AT_ranges). See the comments of add_partial_subprogram on how
7947 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7950 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7951 CORE_ADDR
*highpc
, int set_addrmap
,
7952 struct dwarf2_cu
*cu
)
7954 struct partial_die_info
*pdi
;
7956 /* Now, march along the PDI's, descending into ones which have
7957 interesting children but skipping the children of the other ones,
7958 until we reach the end of the compilation unit. */
7966 /* Anonymous namespaces or modules have no name but have interesting
7967 children, so we need to look at them. Ditto for anonymous
7970 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7971 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7972 || pdi
->tag
== DW_TAG_imported_unit
7973 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7977 case DW_TAG_subprogram
:
7978 case DW_TAG_inlined_subroutine
:
7979 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7981 case DW_TAG_constant
:
7982 case DW_TAG_variable
:
7983 case DW_TAG_typedef
:
7984 case DW_TAG_union_type
:
7985 if (!pdi
->is_declaration
7986 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7988 add_partial_symbol (pdi
, cu
);
7991 case DW_TAG_class_type
:
7992 case DW_TAG_interface_type
:
7993 case DW_TAG_structure_type
:
7994 if (!pdi
->is_declaration
)
7996 add_partial_symbol (pdi
, cu
);
7998 if ((cu
->language
== language_rust
7999 || cu
->language
== language_cplus
) && pdi
->has_children
)
8000 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8003 case DW_TAG_enumeration_type
:
8004 if (!pdi
->is_declaration
)
8005 add_partial_enumeration (pdi
, cu
);
8007 case DW_TAG_base_type
:
8008 case DW_TAG_subrange_type
:
8009 /* File scope base type definitions are added to the partial
8011 add_partial_symbol (pdi
, cu
);
8013 case DW_TAG_namespace
:
8014 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8017 if (!pdi
->is_declaration
)
8018 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8020 case DW_TAG_imported_unit
:
8022 struct dwarf2_per_cu_data
*per_cu
;
8024 /* For now we don't handle imported units in type units. */
8025 if (cu
->per_cu
->is_debug_types
)
8027 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8028 " supported in type units [in module %s]"),
8029 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8032 per_cu
= dwarf2_find_containing_comp_unit
8033 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8034 cu
->per_cu
->dwarf2_per_objfile
);
8036 /* Go read the partial unit, if needed. */
8037 if (per_cu
->v
.psymtab
== NULL
)
8038 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
8040 cu
->per_cu
->imported_symtabs_push (per_cu
);
8043 case DW_TAG_imported_declaration
:
8044 add_partial_symbol (pdi
, cu
);
8051 /* If the die has a sibling, skip to the sibling. */
8053 pdi
= pdi
->die_sibling
;
8057 /* Functions used to compute the fully scoped name of a partial DIE.
8059 Normally, this is simple. For C++, the parent DIE's fully scoped
8060 name is concatenated with "::" and the partial DIE's name.
8061 Enumerators are an exception; they use the scope of their parent
8062 enumeration type, i.e. the name of the enumeration type is not
8063 prepended to the enumerator.
8065 There are two complexities. One is DW_AT_specification; in this
8066 case "parent" means the parent of the target of the specification,
8067 instead of the direct parent of the DIE. The other is compilers
8068 which do not emit DW_TAG_namespace; in this case we try to guess
8069 the fully qualified name of structure types from their members'
8070 linkage names. This must be done using the DIE's children rather
8071 than the children of any DW_AT_specification target. We only need
8072 to do this for structures at the top level, i.e. if the target of
8073 any DW_AT_specification (if any; otherwise the DIE itself) does not
8076 /* Compute the scope prefix associated with PDI's parent, in
8077 compilation unit CU. The result will be allocated on CU's
8078 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8079 field. NULL is returned if no prefix is necessary. */
8081 partial_die_parent_scope (struct partial_die_info
*pdi
,
8082 struct dwarf2_cu
*cu
)
8084 const char *grandparent_scope
;
8085 struct partial_die_info
*parent
, *real_pdi
;
8087 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8088 then this means the parent of the specification DIE. */
8091 while (real_pdi
->has_specification
)
8093 auto res
= find_partial_die (real_pdi
->spec_offset
,
8094 real_pdi
->spec_is_dwz
, cu
);
8099 parent
= real_pdi
->die_parent
;
8103 if (parent
->scope_set
)
8104 return parent
->scope
;
8108 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8110 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8111 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8112 Work around this problem here. */
8113 if (cu
->language
== language_cplus
8114 && parent
->tag
== DW_TAG_namespace
8115 && strcmp (parent
->name
, "::") == 0
8116 && grandparent_scope
== NULL
)
8118 parent
->scope
= NULL
;
8119 parent
->scope_set
= 1;
8123 /* Nested subroutines in Fortran get a prefix. */
8124 if (pdi
->tag
== DW_TAG_enumerator
)
8125 /* Enumerators should not get the name of the enumeration as a prefix. */
8126 parent
->scope
= grandparent_scope
;
8127 else if (parent
->tag
== DW_TAG_namespace
8128 || parent
->tag
== DW_TAG_module
8129 || parent
->tag
== DW_TAG_structure_type
8130 || parent
->tag
== DW_TAG_class_type
8131 || parent
->tag
== DW_TAG_interface_type
8132 || parent
->tag
== DW_TAG_union_type
8133 || parent
->tag
== DW_TAG_enumeration_type
8134 || (cu
->language
== language_fortran
8135 && parent
->tag
== DW_TAG_subprogram
8136 && pdi
->tag
== DW_TAG_subprogram
))
8138 if (grandparent_scope
== NULL
)
8139 parent
->scope
= parent
->name
;
8141 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8143 parent
->name
, 0, cu
);
8147 /* FIXME drow/2004-04-01: What should we be doing with
8148 function-local names? For partial symbols, we should probably be
8150 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8151 dwarf_tag_name (parent
->tag
),
8152 sect_offset_str (pdi
->sect_off
));
8153 parent
->scope
= grandparent_scope
;
8156 parent
->scope_set
= 1;
8157 return parent
->scope
;
8160 /* Return the fully scoped name associated with PDI, from compilation unit
8161 CU. The result will be allocated with malloc. */
8163 static gdb::unique_xmalloc_ptr
<char>
8164 partial_die_full_name (struct partial_die_info
*pdi
,
8165 struct dwarf2_cu
*cu
)
8167 const char *parent_scope
;
8169 /* If this is a template instantiation, we can not work out the
8170 template arguments from partial DIEs. So, unfortunately, we have
8171 to go through the full DIEs. At least any work we do building
8172 types here will be reused if full symbols are loaded later. */
8173 if (pdi
->has_template_arguments
)
8177 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8179 struct die_info
*die
;
8180 struct attribute attr
;
8181 struct dwarf2_cu
*ref_cu
= cu
;
8183 /* DW_FORM_ref_addr is using section offset. */
8184 attr
.name
= (enum dwarf_attribute
) 0;
8185 attr
.form
= DW_FORM_ref_addr
;
8186 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8187 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8189 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8193 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8194 if (parent_scope
== NULL
)
8197 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8202 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8204 struct dwarf2_per_objfile
*dwarf2_per_objfile
8205 = cu
->per_cu
->dwarf2_per_objfile
;
8206 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8207 struct gdbarch
*gdbarch
= objfile
->arch ();
8209 const char *actual_name
= NULL
;
8212 baseaddr
= objfile
->text_section_offset ();
8214 gdb::unique_xmalloc_ptr
<char> built_actual_name
8215 = partial_die_full_name (pdi
, cu
);
8216 if (built_actual_name
!= NULL
)
8217 actual_name
= built_actual_name
.get ();
8219 if (actual_name
== NULL
)
8220 actual_name
= pdi
->name
;
8222 partial_symbol psymbol
;
8223 memset (&psymbol
, 0, sizeof (psymbol
));
8224 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8225 psymbol
.ginfo
.section
= -1;
8227 /* The code below indicates that the psymbol should be installed by
8229 gdb::optional
<psymbol_placement
> where
;
8233 case DW_TAG_inlined_subroutine
:
8234 case DW_TAG_subprogram
:
8235 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8237 if (pdi
->is_external
8238 || cu
->language
== language_ada
8239 || (cu
->language
== language_fortran
8240 && pdi
->die_parent
!= NULL
8241 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8243 /* Normally, only "external" DIEs are part of the global scope.
8244 But in Ada and Fortran, we want to be able to access nested
8245 procedures globally. So all Ada and Fortran subprograms are
8246 stored in the global scope. */
8247 where
= psymbol_placement::GLOBAL
;
8250 where
= psymbol_placement::STATIC
;
8252 psymbol
.domain
= VAR_DOMAIN
;
8253 psymbol
.aclass
= LOC_BLOCK
;
8254 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8255 psymbol
.ginfo
.value
.address
= addr
;
8257 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8258 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8260 case DW_TAG_constant
:
8261 psymbol
.domain
= VAR_DOMAIN
;
8262 psymbol
.aclass
= LOC_STATIC
;
8263 where
= (pdi
->is_external
8264 ? psymbol_placement::GLOBAL
8265 : psymbol_placement::STATIC
);
8267 case DW_TAG_variable
:
8269 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8273 && !dwarf2_per_objfile
->has_section_at_zero
)
8275 /* A global or static variable may also have been stripped
8276 out by the linker if unused, in which case its address
8277 will be nullified; do not add such variables into partial
8278 symbol table then. */
8280 else if (pdi
->is_external
)
8283 Don't enter into the minimal symbol tables as there is
8284 a minimal symbol table entry from the ELF symbols already.
8285 Enter into partial symbol table if it has a location
8286 descriptor or a type.
8287 If the location descriptor is missing, new_symbol will create
8288 a LOC_UNRESOLVED symbol, the address of the variable will then
8289 be determined from the minimal symbol table whenever the variable
8291 The address for the partial symbol table entry is not
8292 used by GDB, but it comes in handy for debugging partial symbol
8295 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8297 psymbol
.domain
= VAR_DOMAIN
;
8298 psymbol
.aclass
= LOC_STATIC
;
8299 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8300 psymbol
.ginfo
.value
.address
= addr
;
8301 where
= psymbol_placement::GLOBAL
;
8306 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8308 /* Static Variable. Skip symbols whose value we cannot know (those
8309 without location descriptors or constant values). */
8310 if (!has_loc
&& !pdi
->has_const_value
)
8313 psymbol
.domain
= VAR_DOMAIN
;
8314 psymbol
.aclass
= LOC_STATIC
;
8315 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8317 psymbol
.ginfo
.value
.address
= addr
;
8318 where
= psymbol_placement::STATIC
;
8321 case DW_TAG_typedef
:
8322 case DW_TAG_base_type
:
8323 case DW_TAG_subrange_type
:
8324 psymbol
.domain
= VAR_DOMAIN
;
8325 psymbol
.aclass
= LOC_TYPEDEF
;
8326 where
= psymbol_placement::STATIC
;
8328 case DW_TAG_imported_declaration
:
8329 case DW_TAG_namespace
:
8330 psymbol
.domain
= VAR_DOMAIN
;
8331 psymbol
.aclass
= LOC_TYPEDEF
;
8332 where
= psymbol_placement::GLOBAL
;
8335 /* With Fortran 77 there might be a "BLOCK DATA" module
8336 available without any name. If so, we skip the module as it
8337 doesn't bring any value. */
8338 if (actual_name
!= nullptr)
8340 psymbol
.domain
= MODULE_DOMAIN
;
8341 psymbol
.aclass
= LOC_TYPEDEF
;
8342 where
= psymbol_placement::GLOBAL
;
8345 case DW_TAG_class_type
:
8346 case DW_TAG_interface_type
:
8347 case DW_TAG_structure_type
:
8348 case DW_TAG_union_type
:
8349 case DW_TAG_enumeration_type
:
8350 /* Skip external references. The DWARF standard says in the section
8351 about "Structure, Union, and Class Type Entries": "An incomplete
8352 structure, union or class type is represented by a structure,
8353 union or class entry that does not have a byte size attribute
8354 and that has a DW_AT_declaration attribute." */
8355 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8358 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8359 static vs. global. */
8360 psymbol
.domain
= STRUCT_DOMAIN
;
8361 psymbol
.aclass
= LOC_TYPEDEF
;
8362 where
= (cu
->language
== language_cplus
8363 ? psymbol_placement::GLOBAL
8364 : psymbol_placement::STATIC
);
8366 case DW_TAG_enumerator
:
8367 psymbol
.domain
= VAR_DOMAIN
;
8368 psymbol
.aclass
= LOC_CONST
;
8369 where
= (cu
->language
== language_cplus
8370 ? psymbol_placement::GLOBAL
8371 : psymbol_placement::STATIC
);
8377 if (where
.has_value ())
8379 if (built_actual_name
!= nullptr)
8380 actual_name
= objfile
->intern (actual_name
);
8381 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8382 psymbol
.ginfo
.set_linkage_name (actual_name
);
8385 psymbol
.ginfo
.set_demangled_name (actual_name
,
8386 &objfile
->objfile_obstack
);
8387 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8389 add_psymbol_to_list (psymbol
, *where
, objfile
);
8393 /* Read a partial die corresponding to a namespace; also, add a symbol
8394 corresponding to that namespace to the symbol table. NAMESPACE is
8395 the name of the enclosing namespace. */
8398 add_partial_namespace (struct partial_die_info
*pdi
,
8399 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8400 int set_addrmap
, struct dwarf2_cu
*cu
)
8402 /* Add a symbol for the namespace. */
8404 add_partial_symbol (pdi
, cu
);
8406 /* Now scan partial symbols in that namespace. */
8408 if (pdi
->has_children
)
8409 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8412 /* Read a partial die corresponding to a Fortran module. */
8415 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8416 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8418 /* Add a symbol for the namespace. */
8420 add_partial_symbol (pdi
, cu
);
8422 /* Now scan partial symbols in that module. */
8424 if (pdi
->has_children
)
8425 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8428 /* Read a partial die corresponding to a subprogram or an inlined
8429 subprogram and create a partial symbol for that subprogram.
8430 When the CU language allows it, this routine also defines a partial
8431 symbol for each nested subprogram that this subprogram contains.
8432 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8433 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8435 PDI may also be a lexical block, in which case we simply search
8436 recursively for subprograms defined inside that lexical block.
8437 Again, this is only performed when the CU language allows this
8438 type of definitions. */
8441 add_partial_subprogram (struct partial_die_info
*pdi
,
8442 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8443 int set_addrmap
, struct dwarf2_cu
*cu
)
8445 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8447 if (pdi
->has_pc_info
)
8449 if (pdi
->lowpc
< *lowpc
)
8450 *lowpc
= pdi
->lowpc
;
8451 if (pdi
->highpc
> *highpc
)
8452 *highpc
= pdi
->highpc
;
8455 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8456 struct gdbarch
*gdbarch
= objfile
->arch ();
8458 CORE_ADDR this_highpc
;
8459 CORE_ADDR this_lowpc
;
8461 baseaddr
= objfile
->text_section_offset ();
8463 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8464 pdi
->lowpc
+ baseaddr
)
8467 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8468 pdi
->highpc
+ baseaddr
)
8470 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8471 this_lowpc
, this_highpc
- 1,
8472 cu
->per_cu
->v
.psymtab
);
8476 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8478 if (!pdi
->is_declaration
)
8479 /* Ignore subprogram DIEs that do not have a name, they are
8480 illegal. Do not emit a complaint at this point, we will
8481 do so when we convert this psymtab into a symtab. */
8483 add_partial_symbol (pdi
, cu
);
8487 if (! pdi
->has_children
)
8490 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8492 pdi
= pdi
->die_child
;
8496 if (pdi
->tag
== DW_TAG_subprogram
8497 || pdi
->tag
== DW_TAG_inlined_subroutine
8498 || pdi
->tag
== DW_TAG_lexical_block
)
8499 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8500 pdi
= pdi
->die_sibling
;
8505 /* Read a partial die corresponding to an enumeration type. */
8508 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8509 struct dwarf2_cu
*cu
)
8511 struct partial_die_info
*pdi
;
8513 if (enum_pdi
->name
!= NULL
)
8514 add_partial_symbol (enum_pdi
, cu
);
8516 pdi
= enum_pdi
->die_child
;
8519 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8520 complaint (_("malformed enumerator DIE ignored"));
8522 add_partial_symbol (pdi
, cu
);
8523 pdi
= pdi
->die_sibling
;
8527 /* Return the initial uleb128 in the die at INFO_PTR. */
8530 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8532 unsigned int bytes_read
;
8534 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8537 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8538 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8540 Return the corresponding abbrev, or NULL if the number is zero (indicating
8541 an empty DIE). In either case *BYTES_READ will be set to the length of
8542 the initial number. */
8544 static struct abbrev_info
*
8545 peek_die_abbrev (const die_reader_specs
&reader
,
8546 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8548 dwarf2_cu
*cu
= reader
.cu
;
8549 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8550 unsigned int abbrev_number
8551 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8553 if (abbrev_number
== 0)
8556 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8559 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8560 " at offset %s [in module %s]"),
8561 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8562 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8568 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8569 Returns a pointer to the end of a series of DIEs, terminated by an empty
8570 DIE. Any children of the skipped DIEs will also be skipped. */
8572 static const gdb_byte
*
8573 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8577 unsigned int bytes_read
;
8578 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8581 return info_ptr
+ bytes_read
;
8583 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8587 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8588 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8589 abbrev corresponding to that skipped uleb128 should be passed in
8590 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8593 static const gdb_byte
*
8594 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8595 struct abbrev_info
*abbrev
)
8597 unsigned int bytes_read
;
8598 struct attribute attr
;
8599 bfd
*abfd
= reader
->abfd
;
8600 struct dwarf2_cu
*cu
= reader
->cu
;
8601 const gdb_byte
*buffer
= reader
->buffer
;
8602 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8603 unsigned int form
, i
;
8605 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8607 /* The only abbrev we care about is DW_AT_sibling. */
8608 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8611 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8613 if (attr
.form
== DW_FORM_ref_addr
)
8614 complaint (_("ignoring absolute DW_AT_sibling"));
8617 sect_offset off
= attr
.get_ref_die_offset ();
8618 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8620 if (sibling_ptr
< info_ptr
)
8621 complaint (_("DW_AT_sibling points backwards"));
8622 else if (sibling_ptr
> reader
->buffer_end
)
8623 reader
->die_section
->overflow_complaint ();
8629 /* If it isn't DW_AT_sibling, skip this attribute. */
8630 form
= abbrev
->attrs
[i
].form
;
8634 case DW_FORM_ref_addr
:
8635 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8636 and later it is offset sized. */
8637 if (cu
->header
.version
== 2)
8638 info_ptr
+= cu
->header
.addr_size
;
8640 info_ptr
+= cu
->header
.offset_size
;
8642 case DW_FORM_GNU_ref_alt
:
8643 info_ptr
+= cu
->header
.offset_size
;
8646 info_ptr
+= cu
->header
.addr_size
;
8654 case DW_FORM_flag_present
:
8655 case DW_FORM_implicit_const
:
8672 case DW_FORM_ref_sig8
:
8675 case DW_FORM_data16
:
8678 case DW_FORM_string
:
8679 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8680 info_ptr
+= bytes_read
;
8682 case DW_FORM_sec_offset
:
8684 case DW_FORM_GNU_strp_alt
:
8685 info_ptr
+= cu
->header
.offset_size
;
8687 case DW_FORM_exprloc
:
8689 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8690 info_ptr
+= bytes_read
;
8692 case DW_FORM_block1
:
8693 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8695 case DW_FORM_block2
:
8696 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8698 case DW_FORM_block4
:
8699 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8705 case DW_FORM_ref_udata
:
8706 case DW_FORM_GNU_addr_index
:
8707 case DW_FORM_GNU_str_index
:
8708 case DW_FORM_rnglistx
:
8709 case DW_FORM_loclistx
:
8710 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8712 case DW_FORM_indirect
:
8713 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8714 info_ptr
+= bytes_read
;
8715 /* We need to continue parsing from here, so just go back to
8717 goto skip_attribute
;
8720 error (_("Dwarf Error: Cannot handle %s "
8721 "in DWARF reader [in module %s]"),
8722 dwarf_form_name (form
),
8723 bfd_get_filename (abfd
));
8727 if (abbrev
->has_children
)
8728 return skip_children (reader
, info_ptr
);
8733 /* Locate ORIG_PDI's sibling.
8734 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8736 static const gdb_byte
*
8737 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8738 struct partial_die_info
*orig_pdi
,
8739 const gdb_byte
*info_ptr
)
8741 /* Do we know the sibling already? */
8743 if (orig_pdi
->sibling
)
8744 return orig_pdi
->sibling
;
8746 /* Are there any children to deal with? */
8748 if (!orig_pdi
->has_children
)
8751 /* Skip the children the long way. */
8753 return skip_children (reader
, info_ptr
);
8756 /* Expand this partial symbol table into a full symbol table. SELF is
8760 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8762 struct dwarf2_per_objfile
*dwarf2_per_objfile
8763 = get_dwarf2_per_objfile (objfile
);
8765 gdb_assert (!readin
);
8766 /* If this psymtab is constructed from a debug-only objfile, the
8767 has_section_at_zero flag will not necessarily be correct. We
8768 can get the correct value for this flag by looking at the data
8769 associated with the (presumably stripped) associated objfile. */
8770 if (objfile
->separate_debug_objfile_backlink
)
8772 struct dwarf2_per_objfile
*dpo_backlink
8773 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8775 dwarf2_per_objfile
->has_section_at_zero
8776 = dpo_backlink
->has_section_at_zero
;
8779 expand_psymtab (objfile
);
8781 process_cu_includes (dwarf2_per_objfile
);
8784 /* Reading in full CUs. */
8786 /* Add PER_CU to the queue. */
8789 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8790 enum language pretend_language
)
8793 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8796 /* If PER_CU is not yet queued, add it to the queue.
8797 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8799 The result is non-zero if PER_CU was queued, otherwise the result is zero
8800 meaning either PER_CU is already queued or it is already loaded.
8802 N.B. There is an invariant here that if a CU is queued then it is loaded.
8803 The caller is required to load PER_CU if we return non-zero. */
8806 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8807 struct dwarf2_per_cu_data
*per_cu
,
8808 enum language pretend_language
)
8810 /* We may arrive here during partial symbol reading, if we need full
8811 DIEs to process an unusual case (e.g. template arguments). Do
8812 not queue PER_CU, just tell our caller to load its DIEs. */
8813 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8815 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8820 /* Mark the dependence relation so that we don't flush PER_CU
8822 if (dependent_cu
!= NULL
)
8823 dwarf2_add_dependence (dependent_cu
, per_cu
);
8825 /* If it's already on the queue, we have nothing to do. */
8829 /* If the compilation unit is already loaded, just mark it as
8831 if (per_cu
->cu
!= NULL
)
8833 per_cu
->cu
->last_used
= 0;
8837 /* Add it to the queue. */
8838 queue_comp_unit (per_cu
, pretend_language
);
8843 /* Process the queue. */
8846 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8848 if (dwarf_read_debug
)
8850 fprintf_unfiltered (gdb_stdlog
,
8851 "Expanding one or more symtabs of objfile %s ...\n",
8852 objfile_name (dwarf2_per_objfile
->objfile
));
8855 /* The queue starts out with one item, but following a DIE reference
8856 may load a new CU, adding it to the end of the queue. */
8857 while (!dwarf2_per_objfile
->queue
.empty ())
8859 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8861 if ((dwarf2_per_objfile
->using_index
8862 ? !item
.per_cu
->v
.quick
->compunit_symtab
8863 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8864 /* Skip dummy CUs. */
8865 && item
.per_cu
->cu
!= NULL
)
8867 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8868 unsigned int debug_print_threshold
;
8871 if (per_cu
->is_debug_types
)
8873 struct signatured_type
*sig_type
=
8874 (struct signatured_type
*) per_cu
;
8876 sprintf (buf
, "TU %s at offset %s",
8877 hex_string (sig_type
->signature
),
8878 sect_offset_str (per_cu
->sect_off
));
8879 /* There can be 100s of TUs.
8880 Only print them in verbose mode. */
8881 debug_print_threshold
= 2;
8885 sprintf (buf
, "CU at offset %s",
8886 sect_offset_str (per_cu
->sect_off
));
8887 debug_print_threshold
= 1;
8890 if (dwarf_read_debug
>= debug_print_threshold
)
8891 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8893 if (per_cu
->is_debug_types
)
8894 process_full_type_unit (per_cu
, item
.pretend_language
);
8896 process_full_comp_unit (per_cu
, item
.pretend_language
);
8898 if (dwarf_read_debug
>= debug_print_threshold
)
8899 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8902 item
.per_cu
->queued
= 0;
8903 dwarf2_per_objfile
->queue
.pop ();
8906 if (dwarf_read_debug
)
8908 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8909 objfile_name (dwarf2_per_objfile
->objfile
));
8913 /* Read in full symbols for PST, and anything it depends on. */
8916 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8918 gdb_assert (!readin
);
8920 expand_dependencies (objfile
);
8922 dw2_do_instantiate_symtab (per_cu_data
, false);
8923 gdb_assert (get_compunit_symtab () != nullptr);
8926 /* Trivial hash function for die_info: the hash value of a DIE
8927 is its offset in .debug_info for this objfile. */
8930 die_hash (const void *item
)
8932 const struct die_info
*die
= (const struct die_info
*) item
;
8934 return to_underlying (die
->sect_off
);
8937 /* Trivial comparison function for die_info structures: two DIEs
8938 are equal if they have the same offset. */
8941 die_eq (const void *item_lhs
, const void *item_rhs
)
8943 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8944 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8946 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8949 /* Load the DIEs associated with PER_CU into memory. */
8952 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8954 enum language pretend_language
)
8956 gdb_assert (! this_cu
->is_debug_types
);
8958 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8962 struct dwarf2_cu
*cu
= reader
.cu
;
8963 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8965 gdb_assert (cu
->die_hash
== NULL
);
8967 htab_create_alloc_ex (cu
->header
.length
/ 12,
8971 &cu
->comp_unit_obstack
,
8972 hashtab_obstack_allocate
,
8973 dummy_obstack_deallocate
);
8975 if (reader
.comp_unit_die
->has_children
)
8976 reader
.comp_unit_die
->child
8977 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8978 &info_ptr
, reader
.comp_unit_die
);
8979 cu
->dies
= reader
.comp_unit_die
;
8980 /* comp_unit_die is not stored in die_hash, no need. */
8982 /* We try not to read any attributes in this function, because not
8983 all CUs needed for references have been loaded yet, and symbol
8984 table processing isn't initialized. But we have to set the CU language,
8985 or we won't be able to build types correctly.
8986 Similarly, if we do not read the producer, we can not apply
8987 producer-specific interpretation. */
8988 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8993 /* Add a DIE to the delayed physname list. */
8996 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8997 const char *name
, struct die_info
*die
,
8998 struct dwarf2_cu
*cu
)
9000 struct delayed_method_info mi
;
9002 mi
.fnfield_index
= fnfield_index
;
9006 cu
->method_list
.push_back (mi
);
9009 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9010 "const" / "volatile". If so, decrements LEN by the length of the
9011 modifier and return true. Otherwise return false. */
9015 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9017 size_t mod_len
= sizeof (mod
) - 1;
9018 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9026 /* Compute the physnames of any methods on the CU's method list.
9028 The computation of method physnames is delayed in order to avoid the
9029 (bad) condition that one of the method's formal parameters is of an as yet
9033 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9035 /* Only C++ delays computing physnames. */
9036 if (cu
->method_list
.empty ())
9038 gdb_assert (cu
->language
== language_cplus
);
9040 for (const delayed_method_info
&mi
: cu
->method_list
)
9042 const char *physname
;
9043 struct fn_fieldlist
*fn_flp
9044 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9045 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9046 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9047 = physname
? physname
: "";
9049 /* Since there's no tag to indicate whether a method is a
9050 const/volatile overload, extract that information out of the
9052 if (physname
!= NULL
)
9054 size_t len
= strlen (physname
);
9058 if (physname
[len
] == ')') /* shortcut */
9060 else if (check_modifier (physname
, len
, " const"))
9061 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9062 else if (check_modifier (physname
, len
, " volatile"))
9063 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9070 /* The list is no longer needed. */
9071 cu
->method_list
.clear ();
9074 /* Go objects should be embedded in a DW_TAG_module DIE,
9075 and it's not clear if/how imported objects will appear.
9076 To keep Go support simple until that's worked out,
9077 go back through what we've read and create something usable.
9078 We could do this while processing each DIE, and feels kinda cleaner,
9079 but that way is more invasive.
9080 This is to, for example, allow the user to type "p var" or "b main"
9081 without having to specify the package name, and allow lookups
9082 of module.object to work in contexts that use the expression
9086 fixup_go_packaging (struct dwarf2_cu
*cu
)
9088 gdb::unique_xmalloc_ptr
<char> package_name
;
9089 struct pending
*list
;
9092 for (list
= *cu
->get_builder ()->get_global_symbols ();
9096 for (i
= 0; i
< list
->nsyms
; ++i
)
9098 struct symbol
*sym
= list
->symbol
[i
];
9100 if (sym
->language () == language_go
9101 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9103 gdb::unique_xmalloc_ptr
<char> this_package_name
9104 (go_symbol_package_name (sym
));
9106 if (this_package_name
== NULL
)
9108 if (package_name
== NULL
)
9109 package_name
= std::move (this_package_name
);
9112 struct objfile
*objfile
9113 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9114 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9115 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9116 (symbol_symtab (sym
) != NULL
9117 ? symtab_to_filename_for_display
9118 (symbol_symtab (sym
))
9119 : objfile_name (objfile
)),
9120 this_package_name
.get (), package_name
.get ());
9126 if (package_name
!= NULL
)
9128 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9129 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9130 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9131 saved_package_name
);
9134 sym
= allocate_symbol (objfile
);
9135 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9136 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9137 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9138 e.g., "main" finds the "main" module and not C's main(). */
9139 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9140 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9141 SYMBOL_TYPE (sym
) = type
;
9143 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9147 /* Allocate a fully-qualified name consisting of the two parts on the
9151 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9153 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9156 /* A helper that allocates a variant part to attach to a Rust enum
9157 type. OBSTACK is where the results should be allocated. TYPE is
9158 the type we're processing. DISCRIMINANT_INDEX is the index of the
9159 discriminant. It must be the index of one of the fields of TYPE.
9160 DEFAULT_INDEX is the index of the default field; or -1 if there is
9161 no default. RANGES is indexed by "effective" field number (the
9162 field index, but omitting the discriminant and default fields) and
9163 must hold the discriminant values used by the variants. Note that
9164 RANGES must have a lifetime at least as long as OBSTACK -- either
9165 already allocated on it, or static. */
9168 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9169 int discriminant_index
, int default_index
,
9170 gdb::array_view
<discriminant_range
> ranges
)
9172 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9173 must be handled by the caller. */
9174 gdb_assert (discriminant_index
>= 0
9175 && discriminant_index
< TYPE_NFIELDS (type
));
9176 gdb_assert (default_index
== -1
9177 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9179 /* We have one variant for each non-discriminant field. */
9180 int n_variants
= TYPE_NFIELDS (type
) - 1;
9182 variant
*variants
= new (obstack
) variant
[n_variants
];
9185 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9187 if (i
== discriminant_index
)
9190 variants
[var_idx
].first_field
= i
;
9191 variants
[var_idx
].last_field
= i
+ 1;
9193 /* The default field does not need a range, but other fields do.
9194 We skipped the discriminant above. */
9195 if (i
!= default_index
)
9197 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9204 gdb_assert (range_idx
== ranges
.size ());
9205 gdb_assert (var_idx
== n_variants
);
9207 variant_part
*part
= new (obstack
) variant_part
;
9208 part
->discriminant_index
= discriminant_index
;
9209 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9210 discriminant_index
));
9211 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9213 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9214 gdb::array_view
<variant_part
> *prop_value
9215 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9217 struct dynamic_prop prop
;
9218 prop
.kind
= PROP_VARIANT_PARTS
;
9219 prop
.data
.variant_parts
= prop_value
;
9221 add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
, type
);
9224 /* Some versions of rustc emitted enums in an unusual way.
9226 Ordinary enums were emitted as unions. The first element of each
9227 structure in the union was named "RUST$ENUM$DISR". This element
9228 held the discriminant.
9230 These versions of Rust also implemented the "non-zero"
9231 optimization. When the enum had two values, and one is empty and
9232 the other holds a pointer that cannot be zero, the pointer is used
9233 as the discriminant, with a zero value meaning the empty variant.
9234 Here, the union's first member is of the form
9235 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9236 where the fieldnos are the indices of the fields that should be
9237 traversed in order to find the field (which may be several fields deep)
9238 and the variantname is the name of the variant of the case when the
9241 This function recognizes whether TYPE is of one of these forms,
9242 and, if so, smashes it to be a variant type. */
9245 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9247 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9249 /* We don't need to deal with empty enums. */
9250 if (TYPE_NFIELDS (type
) == 0)
9253 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9254 if (TYPE_NFIELDS (type
) == 1
9255 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9257 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9259 /* Decode the field name to find the offset of the
9261 ULONGEST bit_offset
= 0;
9262 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9263 while (name
[0] >= '0' && name
[0] <= '9')
9266 unsigned long index
= strtoul (name
, &tail
, 10);
9269 || index
>= TYPE_NFIELDS (field_type
)
9270 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9271 != FIELD_LOC_KIND_BITPOS
))
9273 complaint (_("Could not parse Rust enum encoding string \"%s\""
9275 TYPE_FIELD_NAME (type
, 0),
9276 objfile_name (objfile
));
9281 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9282 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9285 /* Smash this type to be a structure type. We have to do this
9286 because the type has already been recorded. */
9287 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9288 TYPE_NFIELDS (type
) = 3;
9289 /* Save the field we care about. */
9290 struct field saved_field
= TYPE_FIELD (type
, 0);
9292 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9294 /* Put the discriminant at index 0. */
9295 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9296 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9297 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9298 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), bit_offset
);
9300 /* The order of fields doesn't really matter, so put the real
9301 field at index 1 and the data-less field at index 2. */
9302 TYPE_FIELD (type
, 1) = saved_field
;
9303 TYPE_FIELD_NAME (type
, 1)
9304 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (type
, 1)));
9305 TYPE_NAME (TYPE_FIELD_TYPE (type
, 1))
9306 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9307 TYPE_FIELD_NAME (type
, 1));
9309 const char *dataless_name
9310 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9312 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9314 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9315 /* NAME points into the original discriminant name, which
9316 already has the correct lifetime. */
9317 TYPE_FIELD_NAME (type
, 2) = name
;
9318 SET_FIELD_BITPOS (TYPE_FIELD (type
, 2), 0);
9320 /* Indicate that this is a variant type. */
9321 static discriminant_range ranges
[1] = { { 0, 0 } };
9322 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9324 /* A union with a single anonymous field is probably an old-style
9326 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9328 /* Smash this type to be a structure type. We have to do this
9329 because the type has already been recorded. */
9330 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9332 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9333 const char *variant_name
9334 = rust_last_path_segment (TYPE_NAME (field_type
));
9335 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9336 TYPE_NAME (field_type
)
9337 = rust_fully_qualify (&objfile
->objfile_obstack
,
9338 TYPE_NAME (type
), variant_name
);
9342 struct type
*disr_type
= nullptr;
9343 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9345 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9347 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9349 /* All fields of a true enum will be structs. */
9352 else if (TYPE_NFIELDS (disr_type
) == 0)
9354 /* Could be data-less variant, so keep going. */
9355 disr_type
= nullptr;
9357 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9358 "RUST$ENUM$DISR") != 0)
9360 /* Not a Rust enum. */
9370 /* If we got here without a discriminant, then it's probably
9372 if (disr_type
== nullptr)
9375 /* Smash this type to be a structure type. We have to do this
9376 because the type has already been recorded. */
9377 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9379 /* Make space for the discriminant field. */
9380 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9382 = (struct field
*) TYPE_ZALLOC (type
, (TYPE_NFIELDS (type
)
9383 * sizeof (struct field
)));
9384 memcpy (new_fields
+ 1, TYPE_FIELDS (type
),
9385 TYPE_NFIELDS (type
) * sizeof (struct field
));
9386 TYPE_FIELDS (type
) = new_fields
;
9387 TYPE_NFIELDS (type
) = TYPE_NFIELDS (type
) + 1;
9389 /* Install the discriminant at index 0 in the union. */
9390 TYPE_FIELD (type
, 0) = *disr_field
;
9391 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9392 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9394 /* We need a way to find the correct discriminant given a
9395 variant name. For convenience we build a map here. */
9396 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9397 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9398 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9400 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9403 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9404 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9408 int n_fields
= TYPE_NFIELDS (type
);
9409 /* We don't need a range entry for the discriminant, but we do
9410 need one for every other field, as there is no default
9412 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9415 /* Skip the discriminant here. */
9416 for (int i
= 1; i
< n_fields
; ++i
)
9418 /* Find the final word in the name of this variant's type.
9419 That name can be used to look up the correct
9421 const char *variant_name
9422 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (type
, i
)));
9424 auto iter
= discriminant_map
.find (variant_name
);
9425 if (iter
!= discriminant_map
.end ())
9427 ranges
[i
].low
= iter
->second
;
9428 ranges
[i
].high
= iter
->second
;
9431 /* Remove the discriminant field, if it exists. */
9432 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9433 if (TYPE_NFIELDS (sub_type
) > 0)
9435 --TYPE_NFIELDS (sub_type
);
9436 ++TYPE_FIELDS (sub_type
);
9438 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9439 TYPE_NAME (sub_type
)
9440 = rust_fully_qualify (&objfile
->objfile_obstack
,
9441 TYPE_NAME (type
), variant_name
);
9444 /* Indicate that this is a variant type. */
9445 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9446 gdb::array_view
<discriminant_range
> (ranges
,
9451 /* Rewrite some Rust unions to be structures with variants parts. */
9454 rust_union_quirks (struct dwarf2_cu
*cu
)
9456 gdb_assert (cu
->language
== language_rust
);
9457 for (type
*type_
: cu
->rust_unions
)
9458 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9459 /* We don't need this any more. */
9460 cu
->rust_unions
.clear ();
9463 /* Return the symtab for PER_CU. This works properly regardless of
9464 whether we're using the index or psymtabs. */
9466 static struct compunit_symtab
*
9467 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9469 return (per_cu
->dwarf2_per_objfile
->using_index
9470 ? per_cu
->v
.quick
->compunit_symtab
9471 : per_cu
->v
.psymtab
->compunit_symtab
);
9474 /* A helper function for computing the list of all symbol tables
9475 included by PER_CU. */
9478 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9479 htab_t all_children
, htab_t all_type_symtabs
,
9480 struct dwarf2_per_cu_data
*per_cu
,
9481 struct compunit_symtab
*immediate_parent
)
9484 struct compunit_symtab
*cust
;
9486 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9489 /* This inclusion and its children have been processed. */
9494 /* Only add a CU if it has a symbol table. */
9495 cust
= get_compunit_symtab (per_cu
);
9498 /* If this is a type unit only add its symbol table if we haven't
9499 seen it yet (type unit per_cu's can share symtabs). */
9500 if (per_cu
->is_debug_types
)
9502 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9506 result
->push_back (cust
);
9507 if (cust
->user
== NULL
)
9508 cust
->user
= immediate_parent
;
9513 result
->push_back (cust
);
9514 if (cust
->user
== NULL
)
9515 cust
->user
= immediate_parent
;
9519 if (!per_cu
->imported_symtabs_empty ())
9520 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9522 recursively_compute_inclusions (result
, all_children
,
9523 all_type_symtabs
, ptr
, cust
);
9527 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9531 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9533 gdb_assert (! per_cu
->is_debug_types
);
9535 if (!per_cu
->imported_symtabs_empty ())
9538 std::vector
<compunit_symtab
*> result_symtabs
;
9539 htab_t all_children
, all_type_symtabs
;
9540 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9542 /* If we don't have a symtab, we can just skip this case. */
9546 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9547 NULL
, xcalloc
, xfree
);
9548 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9549 NULL
, xcalloc
, xfree
);
9551 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9553 recursively_compute_inclusions (&result_symtabs
, all_children
,
9554 all_type_symtabs
, ptr
, cust
);
9557 /* Now we have a transitive closure of all the included symtabs. */
9558 len
= result_symtabs
.size ();
9560 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9561 struct compunit_symtab
*, len
+ 1);
9562 memcpy (cust
->includes
, result_symtabs
.data (),
9563 len
* sizeof (compunit_symtab
*));
9564 cust
->includes
[len
] = NULL
;
9566 htab_delete (all_children
);
9567 htab_delete (all_type_symtabs
);
9571 /* Compute the 'includes' field for the symtabs of all the CUs we just
9575 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9577 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9579 if (! iter
->is_debug_types
)
9580 compute_compunit_symtab_includes (iter
);
9583 dwarf2_per_objfile
->just_read_cus
.clear ();
9586 /* Generate full symbol information for PER_CU, whose DIEs have
9587 already been loaded into memory. */
9590 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9591 enum language pretend_language
)
9593 struct dwarf2_cu
*cu
= per_cu
->cu
;
9594 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9595 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9596 struct gdbarch
*gdbarch
= objfile
->arch ();
9597 CORE_ADDR lowpc
, highpc
;
9598 struct compunit_symtab
*cust
;
9600 struct block
*static_block
;
9603 baseaddr
= objfile
->text_section_offset ();
9605 /* Clear the list here in case something was left over. */
9606 cu
->method_list
.clear ();
9608 cu
->language
= pretend_language
;
9609 cu
->language_defn
= language_def (cu
->language
);
9611 /* Do line number decoding in read_file_scope () */
9612 process_die (cu
->dies
, cu
);
9614 /* For now fudge the Go package. */
9615 if (cu
->language
== language_go
)
9616 fixup_go_packaging (cu
);
9618 /* Now that we have processed all the DIEs in the CU, all the types
9619 should be complete, and it should now be safe to compute all of the
9621 compute_delayed_physnames (cu
);
9623 if (cu
->language
== language_rust
)
9624 rust_union_quirks (cu
);
9626 /* Some compilers don't define a DW_AT_high_pc attribute for the
9627 compilation unit. If the DW_AT_high_pc is missing, synthesize
9628 it, by scanning the DIE's below the compilation unit. */
9629 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9631 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9632 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9634 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9635 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9636 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9637 addrmap to help ensure it has an accurate map of pc values belonging to
9639 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9641 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9642 SECT_OFF_TEXT (objfile
),
9647 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9649 /* Set symtab language to language from DW_AT_language. If the
9650 compilation is from a C file generated by language preprocessors, do
9651 not set the language if it was already deduced by start_subfile. */
9652 if (!(cu
->language
== language_c
9653 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9654 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9656 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9657 produce DW_AT_location with location lists but it can be possibly
9658 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9659 there were bugs in prologue debug info, fixed later in GCC-4.5
9660 by "unwind info for epilogues" patch (which is not directly related).
9662 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9663 needed, it would be wrong due to missing DW_AT_producer there.
9665 Still one can confuse GDB by using non-standard GCC compilation
9666 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9668 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9669 cust
->locations_valid
= 1;
9671 if (gcc_4_minor
>= 5)
9672 cust
->epilogue_unwind_valid
= 1;
9674 cust
->call_site_htab
= cu
->call_site_htab
;
9677 if (dwarf2_per_objfile
->using_index
)
9678 per_cu
->v
.quick
->compunit_symtab
= cust
;
9681 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9682 pst
->compunit_symtab
= cust
;
9686 /* Push it for inclusion processing later. */
9687 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9689 /* Not needed any more. */
9690 cu
->reset_builder ();
9693 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9694 already been loaded into memory. */
9697 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9698 enum language pretend_language
)
9700 struct dwarf2_cu
*cu
= per_cu
->cu
;
9701 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9702 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9703 struct compunit_symtab
*cust
;
9704 struct signatured_type
*sig_type
;
9706 gdb_assert (per_cu
->is_debug_types
);
9707 sig_type
= (struct signatured_type
*) per_cu
;
9709 /* Clear the list here in case something was left over. */
9710 cu
->method_list
.clear ();
9712 cu
->language
= pretend_language
;
9713 cu
->language_defn
= language_def (cu
->language
);
9715 /* The symbol tables are set up in read_type_unit_scope. */
9716 process_die (cu
->dies
, cu
);
9718 /* For now fudge the Go package. */
9719 if (cu
->language
== language_go
)
9720 fixup_go_packaging (cu
);
9722 /* Now that we have processed all the DIEs in the CU, all the types
9723 should be complete, and it should now be safe to compute all of the
9725 compute_delayed_physnames (cu
);
9727 if (cu
->language
== language_rust
)
9728 rust_union_quirks (cu
);
9730 /* TUs share symbol tables.
9731 If this is the first TU to use this symtab, complete the construction
9732 of it with end_expandable_symtab. Otherwise, complete the addition of
9733 this TU's symbols to the existing symtab. */
9734 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9736 buildsym_compunit
*builder
= cu
->get_builder ();
9737 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9738 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9742 /* Set symtab language to language from DW_AT_language. If the
9743 compilation is from a C file generated by language preprocessors,
9744 do not set the language if it was already deduced by
9746 if (!(cu
->language
== language_c
9747 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9748 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9753 cu
->get_builder ()->augment_type_symtab ();
9754 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9757 if (dwarf2_per_objfile
->using_index
)
9758 per_cu
->v
.quick
->compunit_symtab
= cust
;
9761 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9762 pst
->compunit_symtab
= cust
;
9766 /* Not needed any more. */
9767 cu
->reset_builder ();
9770 /* Process an imported unit DIE. */
9773 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9775 struct attribute
*attr
;
9777 /* For now we don't handle imported units in type units. */
9778 if (cu
->per_cu
->is_debug_types
)
9780 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9781 " supported in type units [in module %s]"),
9782 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9785 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9788 sect_offset sect_off
= attr
->get_ref_die_offset ();
9789 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9790 dwarf2_per_cu_data
*per_cu
9791 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9792 cu
->per_cu
->dwarf2_per_objfile
);
9794 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9795 into another compilation unit, at root level. Regard this as a hint,
9797 if (die
->parent
&& die
->parent
->parent
== NULL
9798 && per_cu
->unit_type
== DW_UT_compile
9799 && per_cu
->lang
== language_cplus
)
9802 /* If necessary, add it to the queue and load its DIEs. */
9803 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9804 load_full_comp_unit (per_cu
, false, cu
->language
);
9806 cu
->per_cu
->imported_symtabs_push (per_cu
);
9810 /* RAII object that represents a process_die scope: i.e.,
9811 starts/finishes processing a DIE. */
9812 class process_die_scope
9815 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9816 : m_die (die
), m_cu (cu
)
9818 /* We should only be processing DIEs not already in process. */
9819 gdb_assert (!m_die
->in_process
);
9820 m_die
->in_process
= true;
9823 ~process_die_scope ()
9825 m_die
->in_process
= false;
9827 /* If we're done processing the DIE for the CU that owns the line
9828 header, we don't need the line header anymore. */
9829 if (m_cu
->line_header_die_owner
== m_die
)
9831 delete m_cu
->line_header
;
9832 m_cu
->line_header
= NULL
;
9833 m_cu
->line_header_die_owner
= NULL
;
9842 /* Process a die and its children. */
9845 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9847 process_die_scope
scope (die
, cu
);
9851 case DW_TAG_padding
:
9853 case DW_TAG_compile_unit
:
9854 case DW_TAG_partial_unit
:
9855 read_file_scope (die
, cu
);
9857 case DW_TAG_type_unit
:
9858 read_type_unit_scope (die
, cu
);
9860 case DW_TAG_subprogram
:
9861 /* Nested subprograms in Fortran get a prefix. */
9862 if (cu
->language
== language_fortran
9863 && die
->parent
!= NULL
9864 && die
->parent
->tag
== DW_TAG_subprogram
)
9865 cu
->processing_has_namespace_info
= true;
9867 case DW_TAG_inlined_subroutine
:
9868 read_func_scope (die
, cu
);
9870 case DW_TAG_lexical_block
:
9871 case DW_TAG_try_block
:
9872 case DW_TAG_catch_block
:
9873 read_lexical_block_scope (die
, cu
);
9875 case DW_TAG_call_site
:
9876 case DW_TAG_GNU_call_site
:
9877 read_call_site_scope (die
, cu
);
9879 case DW_TAG_class_type
:
9880 case DW_TAG_interface_type
:
9881 case DW_TAG_structure_type
:
9882 case DW_TAG_union_type
:
9883 process_structure_scope (die
, cu
);
9885 case DW_TAG_enumeration_type
:
9886 process_enumeration_scope (die
, cu
);
9889 /* These dies have a type, but processing them does not create
9890 a symbol or recurse to process the children. Therefore we can
9891 read them on-demand through read_type_die. */
9892 case DW_TAG_subroutine_type
:
9893 case DW_TAG_set_type
:
9894 case DW_TAG_array_type
:
9895 case DW_TAG_pointer_type
:
9896 case DW_TAG_ptr_to_member_type
:
9897 case DW_TAG_reference_type
:
9898 case DW_TAG_rvalue_reference_type
:
9899 case DW_TAG_string_type
:
9902 case DW_TAG_base_type
:
9903 case DW_TAG_subrange_type
:
9904 case DW_TAG_typedef
:
9905 /* Add a typedef symbol for the type definition, if it has a
9907 new_symbol (die
, read_type_die (die
, cu
), cu
);
9909 case DW_TAG_common_block
:
9910 read_common_block (die
, cu
);
9912 case DW_TAG_common_inclusion
:
9914 case DW_TAG_namespace
:
9915 cu
->processing_has_namespace_info
= true;
9916 read_namespace (die
, cu
);
9919 cu
->processing_has_namespace_info
= true;
9920 read_module (die
, cu
);
9922 case DW_TAG_imported_declaration
:
9923 cu
->processing_has_namespace_info
= true;
9924 if (read_namespace_alias (die
, cu
))
9926 /* The declaration is not a global namespace alias. */
9928 case DW_TAG_imported_module
:
9929 cu
->processing_has_namespace_info
= true;
9930 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9931 || cu
->language
!= language_fortran
))
9932 complaint (_("Tag '%s' has unexpected children"),
9933 dwarf_tag_name (die
->tag
));
9934 read_import_statement (die
, cu
);
9937 case DW_TAG_imported_unit
:
9938 process_imported_unit_die (die
, cu
);
9941 case DW_TAG_variable
:
9942 read_variable (die
, cu
);
9946 new_symbol (die
, NULL
, cu
);
9951 /* DWARF name computation. */
9953 /* A helper function for dwarf2_compute_name which determines whether DIE
9954 needs to have the name of the scope prepended to the name listed in the
9958 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9960 struct attribute
*attr
;
9964 case DW_TAG_namespace
:
9965 case DW_TAG_typedef
:
9966 case DW_TAG_class_type
:
9967 case DW_TAG_interface_type
:
9968 case DW_TAG_structure_type
:
9969 case DW_TAG_union_type
:
9970 case DW_TAG_enumeration_type
:
9971 case DW_TAG_enumerator
:
9972 case DW_TAG_subprogram
:
9973 case DW_TAG_inlined_subroutine
:
9975 case DW_TAG_imported_declaration
:
9978 case DW_TAG_variable
:
9979 case DW_TAG_constant
:
9980 /* We only need to prefix "globally" visible variables. These include
9981 any variable marked with DW_AT_external or any variable that
9982 lives in a namespace. [Variables in anonymous namespaces
9983 require prefixing, but they are not DW_AT_external.] */
9985 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9987 struct dwarf2_cu
*spec_cu
= cu
;
9989 return die_needs_namespace (die_specification (die
, &spec_cu
),
9993 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9994 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9995 && die
->parent
->tag
!= DW_TAG_module
)
9997 /* A variable in a lexical block of some kind does not need a
9998 namespace, even though in C++ such variables may be external
9999 and have a mangled name. */
10000 if (die
->parent
->tag
== DW_TAG_lexical_block
10001 || die
->parent
->tag
== DW_TAG_try_block
10002 || die
->parent
->tag
== DW_TAG_catch_block
10003 || die
->parent
->tag
== DW_TAG_subprogram
)
10012 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10013 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10014 defined for the given DIE. */
10016 static struct attribute
*
10017 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10019 struct attribute
*attr
;
10021 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10023 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10028 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10029 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10030 defined for the given DIE. */
10032 static const char *
10033 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10035 const char *linkage_name
;
10037 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10038 if (linkage_name
== NULL
)
10039 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10041 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10042 See https://github.com/rust-lang/rust/issues/32925. */
10043 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10044 && strchr (linkage_name
, '{') != NULL
)
10045 linkage_name
= NULL
;
10047 return linkage_name
;
10050 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10051 compute the physname for the object, which include a method's:
10052 - formal parameters (C++),
10053 - receiver type (Go),
10055 The term "physname" is a bit confusing.
10056 For C++, for example, it is the demangled name.
10057 For Go, for example, it's the mangled name.
10059 For Ada, return the DIE's linkage name rather than the fully qualified
10060 name. PHYSNAME is ignored..
10062 The result is allocated on the objfile_obstack and canonicalized. */
10064 static const char *
10065 dwarf2_compute_name (const char *name
,
10066 struct die_info
*die
, struct dwarf2_cu
*cu
,
10069 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10072 name
= dwarf2_name (die
, cu
);
10074 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10075 but otherwise compute it by typename_concat inside GDB.
10076 FIXME: Actually this is not really true, or at least not always true.
10077 It's all very confusing. compute_and_set_names doesn't try to demangle
10078 Fortran names because there is no mangling standard. So new_symbol
10079 will set the demangled name to the result of dwarf2_full_name, and it is
10080 the demangled name that GDB uses if it exists. */
10081 if (cu
->language
== language_ada
10082 || (cu
->language
== language_fortran
&& physname
))
10084 /* For Ada unit, we prefer the linkage name over the name, as
10085 the former contains the exported name, which the user expects
10086 to be able to reference. Ideally, we want the user to be able
10087 to reference this entity using either natural or linkage name,
10088 but we haven't started looking at this enhancement yet. */
10089 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10091 if (linkage_name
!= NULL
)
10092 return linkage_name
;
10095 /* These are the only languages we know how to qualify names in. */
10097 && (cu
->language
== language_cplus
10098 || cu
->language
== language_fortran
|| cu
->language
== language_d
10099 || cu
->language
== language_rust
))
10101 if (die_needs_namespace (die
, cu
))
10103 const char *prefix
;
10104 const char *canonical_name
= NULL
;
10108 prefix
= determine_prefix (die
, cu
);
10109 if (*prefix
!= '\0')
10111 gdb::unique_xmalloc_ptr
<char> prefixed_name
10112 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10114 buf
.puts (prefixed_name
.get ());
10119 /* Template parameters may be specified in the DIE's DW_AT_name, or
10120 as children with DW_TAG_template_type_param or
10121 DW_TAG_value_type_param. If the latter, add them to the name
10122 here. If the name already has template parameters, then
10123 skip this step; some versions of GCC emit both, and
10124 it is more efficient to use the pre-computed name.
10126 Something to keep in mind about this process: it is very
10127 unlikely, or in some cases downright impossible, to produce
10128 something that will match the mangled name of a function.
10129 If the definition of the function has the same debug info,
10130 we should be able to match up with it anyway. But fallbacks
10131 using the minimal symbol, for instance to find a method
10132 implemented in a stripped copy of libstdc++, will not work.
10133 If we do not have debug info for the definition, we will have to
10134 match them up some other way.
10136 When we do name matching there is a related problem with function
10137 templates; two instantiated function templates are allowed to
10138 differ only by their return types, which we do not add here. */
10140 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10142 struct attribute
*attr
;
10143 struct die_info
*child
;
10146 die
->building_fullname
= 1;
10148 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10152 const gdb_byte
*bytes
;
10153 struct dwarf2_locexpr_baton
*baton
;
10156 if (child
->tag
!= DW_TAG_template_type_param
10157 && child
->tag
!= DW_TAG_template_value_param
)
10168 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10171 complaint (_("template parameter missing DW_AT_type"));
10172 buf
.puts ("UNKNOWN_TYPE");
10175 type
= die_type (child
, cu
);
10177 if (child
->tag
== DW_TAG_template_type_param
)
10179 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10180 &type_print_raw_options
);
10184 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10187 complaint (_("template parameter missing "
10188 "DW_AT_const_value"));
10189 buf
.puts ("UNKNOWN_VALUE");
10193 dwarf2_const_value_attr (attr
, type
, name
,
10194 &cu
->comp_unit_obstack
, cu
,
10195 &value
, &bytes
, &baton
);
10197 if (TYPE_NOSIGN (type
))
10198 /* GDB prints characters as NUMBER 'CHAR'. If that's
10199 changed, this can use value_print instead. */
10200 c_printchar (value
, type
, &buf
);
10203 struct value_print_options opts
;
10206 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10210 else if (bytes
!= NULL
)
10212 v
= allocate_value (type
);
10213 memcpy (value_contents_writeable (v
), bytes
,
10214 TYPE_LENGTH (type
));
10217 v
= value_from_longest (type
, value
);
10219 /* Specify decimal so that we do not depend on
10221 get_formatted_print_options (&opts
, 'd');
10223 value_print (v
, &buf
, &opts
);
10228 die
->building_fullname
= 0;
10232 /* Close the argument list, with a space if necessary
10233 (nested templates). */
10234 if (!buf
.empty () && buf
.string ().back () == '>')
10241 /* For C++ methods, append formal parameter type
10242 information, if PHYSNAME. */
10244 if (physname
&& die
->tag
== DW_TAG_subprogram
10245 && cu
->language
== language_cplus
)
10247 struct type
*type
= read_type_die (die
, cu
);
10249 c_type_print_args (type
, &buf
, 1, cu
->language
,
10250 &type_print_raw_options
);
10252 if (cu
->language
== language_cplus
)
10254 /* Assume that an artificial first parameter is
10255 "this", but do not crash if it is not. RealView
10256 marks unnamed (and thus unused) parameters as
10257 artificial; there is no way to differentiate
10259 if (TYPE_NFIELDS (type
) > 0
10260 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10261 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10262 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10264 buf
.puts (" const");
10268 const std::string
&intermediate_name
= buf
.string ();
10270 if (cu
->language
== language_cplus
)
10272 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10275 /* If we only computed INTERMEDIATE_NAME, or if
10276 INTERMEDIATE_NAME is already canonical, then we need to
10278 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10279 name
= objfile
->intern (intermediate_name
);
10281 name
= canonical_name
;
10288 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10289 If scope qualifiers are appropriate they will be added. The result
10290 will be allocated on the storage_obstack, or NULL if the DIE does
10291 not have a name. NAME may either be from a previous call to
10292 dwarf2_name or NULL.
10294 The output string will be canonicalized (if C++). */
10296 static const char *
10297 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10299 return dwarf2_compute_name (name
, die
, cu
, 0);
10302 /* Construct a physname for the given DIE in CU. NAME may either be
10303 from a previous call to dwarf2_name or NULL. The result will be
10304 allocated on the objfile_objstack or NULL if the DIE does not have a
10307 The output string will be canonicalized (if C++). */
10309 static const char *
10310 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10312 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10313 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10316 /* In this case dwarf2_compute_name is just a shortcut not building anything
10318 if (!die_needs_namespace (die
, cu
))
10319 return dwarf2_compute_name (name
, die
, cu
, 1);
10321 if (cu
->language
!= language_rust
)
10322 mangled
= dw2_linkage_name (die
, cu
);
10324 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10326 gdb::unique_xmalloc_ptr
<char> demangled
;
10327 if (mangled
!= NULL
)
10330 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10332 /* Do nothing (do not demangle the symbol name). */
10334 else if (cu
->language
== language_go
)
10336 /* This is a lie, but we already lie to the caller new_symbol.
10337 new_symbol assumes we return the mangled name.
10338 This just undoes that lie until things are cleaned up. */
10342 /* Use DMGL_RET_DROP for C++ template functions to suppress
10343 their return type. It is easier for GDB users to search
10344 for such functions as `name(params)' than `long name(params)'.
10345 In such case the minimal symbol names do not match the full
10346 symbol names but for template functions there is never a need
10347 to look up their definition from their declaration so
10348 the only disadvantage remains the minimal symbol variant
10349 `long name(params)' does not have the proper inferior type. */
10350 demangled
.reset (gdb_demangle (mangled
,
10351 (DMGL_PARAMS
| DMGL_ANSI
10352 | DMGL_RET_DROP
)));
10355 canon
= demangled
.get ();
10363 if (canon
== NULL
|| check_physname
)
10365 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10367 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10369 /* It may not mean a bug in GDB. The compiler could also
10370 compute DW_AT_linkage_name incorrectly. But in such case
10371 GDB would need to be bug-to-bug compatible. */
10373 complaint (_("Computed physname <%s> does not match demangled <%s> "
10374 "(from linkage <%s>) - DIE at %s [in module %s]"),
10375 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10376 objfile_name (objfile
));
10378 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10379 is available here - over computed PHYSNAME. It is safer
10380 against both buggy GDB and buggy compilers. */
10394 retval
= objfile
->intern (retval
);
10399 /* Inspect DIE in CU for a namespace alias. If one exists, record
10400 a new symbol for it.
10402 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10405 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10407 struct attribute
*attr
;
10409 /* If the die does not have a name, this is not a namespace
10411 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10415 struct die_info
*d
= die
;
10416 struct dwarf2_cu
*imported_cu
= cu
;
10418 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10419 keep inspecting DIEs until we hit the underlying import. */
10420 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10421 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10423 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10427 d
= follow_die_ref (d
, attr
, &imported_cu
);
10428 if (d
->tag
!= DW_TAG_imported_declaration
)
10432 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10434 complaint (_("DIE at %s has too many recursively imported "
10435 "declarations"), sect_offset_str (d
->sect_off
));
10442 sect_offset sect_off
= attr
->get_ref_die_offset ();
10444 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10445 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10447 /* This declaration is a global namespace alias. Add
10448 a symbol for it whose type is the aliased namespace. */
10449 new_symbol (die
, type
, cu
);
10458 /* Return the using directives repository (global or local?) to use in the
10459 current context for CU.
10461 For Ada, imported declarations can materialize renamings, which *may* be
10462 global. However it is impossible (for now?) in DWARF to distinguish
10463 "external" imported declarations and "static" ones. As all imported
10464 declarations seem to be static in all other languages, make them all CU-wide
10465 global only in Ada. */
10467 static struct using_direct
**
10468 using_directives (struct dwarf2_cu
*cu
)
10470 if (cu
->language
== language_ada
10471 && cu
->get_builder ()->outermost_context_p ())
10472 return cu
->get_builder ()->get_global_using_directives ();
10474 return cu
->get_builder ()->get_local_using_directives ();
10477 /* Read the import statement specified by the given die and record it. */
10480 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10482 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10483 struct attribute
*import_attr
;
10484 struct die_info
*imported_die
, *child_die
;
10485 struct dwarf2_cu
*imported_cu
;
10486 const char *imported_name
;
10487 const char *imported_name_prefix
;
10488 const char *canonical_name
;
10489 const char *import_alias
;
10490 const char *imported_declaration
= NULL
;
10491 const char *import_prefix
;
10492 std::vector
<const char *> excludes
;
10494 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10495 if (import_attr
== NULL
)
10497 complaint (_("Tag '%s' has no DW_AT_import"),
10498 dwarf_tag_name (die
->tag
));
10503 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10504 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10505 if (imported_name
== NULL
)
10507 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10509 The import in the following code:
10523 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10524 <52> DW_AT_decl_file : 1
10525 <53> DW_AT_decl_line : 6
10526 <54> DW_AT_import : <0x75>
10527 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10528 <59> DW_AT_name : B
10529 <5b> DW_AT_decl_file : 1
10530 <5c> DW_AT_decl_line : 2
10531 <5d> DW_AT_type : <0x6e>
10533 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10534 <76> DW_AT_byte_size : 4
10535 <77> DW_AT_encoding : 5 (signed)
10537 imports the wrong die ( 0x75 instead of 0x58 ).
10538 This case will be ignored until the gcc bug is fixed. */
10542 /* Figure out the local name after import. */
10543 import_alias
= dwarf2_name (die
, cu
);
10545 /* Figure out where the statement is being imported to. */
10546 import_prefix
= determine_prefix (die
, cu
);
10548 /* Figure out what the scope of the imported die is and prepend it
10549 to the name of the imported die. */
10550 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10552 if (imported_die
->tag
!= DW_TAG_namespace
10553 && imported_die
->tag
!= DW_TAG_module
)
10555 imported_declaration
= imported_name
;
10556 canonical_name
= imported_name_prefix
;
10558 else if (strlen (imported_name_prefix
) > 0)
10559 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10560 imported_name_prefix
,
10561 (cu
->language
== language_d
? "." : "::"),
10562 imported_name
, (char *) NULL
);
10564 canonical_name
= imported_name
;
10566 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10567 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10568 child_die
= child_die
->sibling
)
10570 /* DWARF-4: A Fortran use statement with a “rename list” may be
10571 represented by an imported module entry with an import attribute
10572 referring to the module and owned entries corresponding to those
10573 entities that are renamed as part of being imported. */
10575 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10577 complaint (_("child DW_TAG_imported_declaration expected "
10578 "- DIE at %s [in module %s]"),
10579 sect_offset_str (child_die
->sect_off
),
10580 objfile_name (objfile
));
10584 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10585 if (import_attr
== NULL
)
10587 complaint (_("Tag '%s' has no DW_AT_import"),
10588 dwarf_tag_name (child_die
->tag
));
10593 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10595 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10596 if (imported_name
== NULL
)
10598 complaint (_("child DW_TAG_imported_declaration has unknown "
10599 "imported name - DIE at %s [in module %s]"),
10600 sect_offset_str (child_die
->sect_off
),
10601 objfile_name (objfile
));
10605 excludes
.push_back (imported_name
);
10607 process_die (child_die
, cu
);
10610 add_using_directive (using_directives (cu
),
10614 imported_declaration
,
10617 &objfile
->objfile_obstack
);
10620 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10621 types, but gives them a size of zero. Starting with version 14,
10622 ICC is compatible with GCC. */
10625 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10627 if (!cu
->checked_producer
)
10628 check_producer (cu
);
10630 return cu
->producer_is_icc_lt_14
;
10633 /* ICC generates a DW_AT_type for C void functions. This was observed on
10634 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10635 which says that void functions should not have a DW_AT_type. */
10638 producer_is_icc (struct dwarf2_cu
*cu
)
10640 if (!cu
->checked_producer
)
10641 check_producer (cu
);
10643 return cu
->producer_is_icc
;
10646 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10647 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10648 this, it was first present in GCC release 4.3.0. */
10651 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10653 if (!cu
->checked_producer
)
10654 check_producer (cu
);
10656 return cu
->producer_is_gcc_lt_4_3
;
10659 static file_and_directory
10660 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10662 file_and_directory res
;
10664 /* Find the filename. Do not use dwarf2_name here, since the filename
10665 is not a source language identifier. */
10666 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10667 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10669 if (res
.comp_dir
== NULL
10670 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10671 && IS_ABSOLUTE_PATH (res
.name
))
10673 res
.comp_dir_storage
= ldirname (res
.name
);
10674 if (!res
.comp_dir_storage
.empty ())
10675 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10677 if (res
.comp_dir
!= NULL
)
10679 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10680 directory, get rid of it. */
10681 const char *cp
= strchr (res
.comp_dir
, ':');
10683 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10684 res
.comp_dir
= cp
+ 1;
10687 if (res
.name
== NULL
)
10688 res
.name
= "<unknown>";
10693 /* Handle DW_AT_stmt_list for a compilation unit.
10694 DIE is the DW_TAG_compile_unit die for CU.
10695 COMP_DIR is the compilation directory. LOWPC is passed to
10696 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10699 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10700 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10702 struct dwarf2_per_objfile
*dwarf2_per_objfile
10703 = cu
->per_cu
->dwarf2_per_objfile
;
10704 struct attribute
*attr
;
10705 struct line_header line_header_local
;
10706 hashval_t line_header_local_hash
;
10708 int decode_mapping
;
10710 gdb_assert (! cu
->per_cu
->is_debug_types
);
10712 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10716 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10718 /* The line header hash table is only created if needed (it exists to
10719 prevent redundant reading of the line table for partial_units).
10720 If we're given a partial_unit, we'll need it. If we're given a
10721 compile_unit, then use the line header hash table if it's already
10722 created, but don't create one just yet. */
10724 if (dwarf2_per_objfile
->line_header_hash
== NULL
10725 && die
->tag
== DW_TAG_partial_unit
)
10727 dwarf2_per_objfile
->line_header_hash
10728 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10729 line_header_eq_voidp
,
10730 free_line_header_voidp
,
10734 line_header_local
.sect_off
= line_offset
;
10735 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10736 line_header_local_hash
= line_header_hash (&line_header_local
);
10737 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10739 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10740 &line_header_local
,
10741 line_header_local_hash
, NO_INSERT
);
10743 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10744 is not present in *SLOT (since if there is something in *SLOT then
10745 it will be for a partial_unit). */
10746 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10748 gdb_assert (*slot
!= NULL
);
10749 cu
->line_header
= (struct line_header
*) *slot
;
10754 /* dwarf_decode_line_header does not yet provide sufficient information.
10755 We always have to call also dwarf_decode_lines for it. */
10756 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10760 cu
->line_header
= lh
.release ();
10761 cu
->line_header_die_owner
= die
;
10763 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10767 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10768 &line_header_local
,
10769 line_header_local_hash
, INSERT
);
10770 gdb_assert (slot
!= NULL
);
10772 if (slot
!= NULL
&& *slot
== NULL
)
10774 /* This newly decoded line number information unit will be owned
10775 by line_header_hash hash table. */
10776 *slot
= cu
->line_header
;
10777 cu
->line_header_die_owner
= NULL
;
10781 /* We cannot free any current entry in (*slot) as that struct line_header
10782 may be already used by multiple CUs. Create only temporary decoded
10783 line_header for this CU - it may happen at most once for each line
10784 number information unit. And if we're not using line_header_hash
10785 then this is what we want as well. */
10786 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10788 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10789 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10794 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10797 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10799 struct dwarf2_per_objfile
*dwarf2_per_objfile
10800 = cu
->per_cu
->dwarf2_per_objfile
;
10801 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10802 struct gdbarch
*gdbarch
= objfile
->arch ();
10803 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10804 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10805 struct attribute
*attr
;
10806 struct die_info
*child_die
;
10807 CORE_ADDR baseaddr
;
10809 prepare_one_comp_unit (cu
, die
, cu
->language
);
10810 baseaddr
= objfile
->text_section_offset ();
10812 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10814 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10815 from finish_block. */
10816 if (lowpc
== ((CORE_ADDR
) -1))
10818 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10820 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10822 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10823 standardised yet. As a workaround for the language detection we fall
10824 back to the DW_AT_producer string. */
10825 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10826 cu
->language
= language_opencl
;
10828 /* Similar hack for Go. */
10829 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10830 set_cu_language (DW_LANG_Go
, cu
);
10832 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10834 /* Decode line number information if present. We do this before
10835 processing child DIEs, so that the line header table is available
10836 for DW_AT_decl_file. */
10837 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10839 /* Process all dies in compilation unit. */
10840 if (die
->child
!= NULL
)
10842 child_die
= die
->child
;
10843 while (child_die
&& child_die
->tag
)
10845 process_die (child_die
, cu
);
10846 child_die
= child_die
->sibling
;
10850 /* Decode macro information, if present. Dwarf 2 macro information
10851 refers to information in the line number info statement program
10852 header, so we can only read it if we've read the header
10854 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10856 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10857 if (attr
&& cu
->line_header
)
10859 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10860 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10862 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10866 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10867 if (attr
&& cu
->line_header
)
10869 unsigned int macro_offset
= DW_UNSND (attr
);
10871 dwarf_decode_macros (cu
, macro_offset
, 0);
10877 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10879 struct type_unit_group
*tu_group
;
10881 struct attribute
*attr
;
10883 struct signatured_type
*sig_type
;
10885 gdb_assert (per_cu
->is_debug_types
);
10886 sig_type
= (struct signatured_type
*) per_cu
;
10888 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10890 /* If we're using .gdb_index (includes -readnow) then
10891 per_cu->type_unit_group may not have been set up yet. */
10892 if (sig_type
->type_unit_group
== NULL
)
10893 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10894 tu_group
= sig_type
->type_unit_group
;
10896 /* If we've already processed this stmt_list there's no real need to
10897 do it again, we could fake it and just recreate the part we need
10898 (file name,index -> symtab mapping). If data shows this optimization
10899 is useful we can do it then. */
10900 first_time
= tu_group
->compunit_symtab
== NULL
;
10902 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10907 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10908 lh
= dwarf_decode_line_header (line_offset
, this);
10913 start_symtab ("", NULL
, 0);
10916 gdb_assert (tu_group
->symtabs
== NULL
);
10917 gdb_assert (m_builder
== nullptr);
10918 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10919 m_builder
.reset (new struct buildsym_compunit
10920 (COMPUNIT_OBJFILE (cust
), "",
10921 COMPUNIT_DIRNAME (cust
),
10922 compunit_language (cust
),
10928 line_header
= lh
.release ();
10929 line_header_die_owner
= die
;
10933 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10935 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10936 still initializing it, and our caller (a few levels up)
10937 process_full_type_unit still needs to know if this is the first
10941 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10942 struct symtab
*, line_header
->file_names_size ());
10944 auto &file_names
= line_header
->file_names ();
10945 for (i
= 0; i
< file_names
.size (); ++i
)
10947 file_entry
&fe
= file_names
[i
];
10948 dwarf2_start_subfile (this, fe
.name
,
10949 fe
.include_dir (line_header
));
10950 buildsym_compunit
*b
= get_builder ();
10951 if (b
->get_current_subfile ()->symtab
== NULL
)
10953 /* NOTE: start_subfile will recognize when it's been
10954 passed a file it has already seen. So we can't
10955 assume there's a simple mapping from
10956 cu->line_header->file_names to subfiles, plus
10957 cu->line_header->file_names may contain dups. */
10958 b
->get_current_subfile ()->symtab
10959 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10962 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10963 tu_group
->symtabs
[i
] = fe
.symtab
;
10968 gdb_assert (m_builder
== nullptr);
10969 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10970 m_builder
.reset (new struct buildsym_compunit
10971 (COMPUNIT_OBJFILE (cust
), "",
10972 COMPUNIT_DIRNAME (cust
),
10973 compunit_language (cust
),
10976 auto &file_names
= line_header
->file_names ();
10977 for (i
= 0; i
< file_names
.size (); ++i
)
10979 file_entry
&fe
= file_names
[i
];
10980 fe
.symtab
= tu_group
->symtabs
[i
];
10984 /* The main symtab is allocated last. Type units don't have DW_AT_name
10985 so they don't have a "real" (so to speak) symtab anyway.
10986 There is later code that will assign the main symtab to all symbols
10987 that don't have one. We need to handle the case of a symbol with a
10988 missing symtab (DW_AT_decl_file) anyway. */
10991 /* Process DW_TAG_type_unit.
10992 For TUs we want to skip the first top level sibling if it's not the
10993 actual type being defined by this TU. In this case the first top
10994 level sibling is there to provide context only. */
10997 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10999 struct die_info
*child_die
;
11001 prepare_one_comp_unit (cu
, die
, language_minimal
);
11003 /* Initialize (or reinitialize) the machinery for building symtabs.
11004 We do this before processing child DIEs, so that the line header table
11005 is available for DW_AT_decl_file. */
11006 cu
->setup_type_unit_groups (die
);
11008 if (die
->child
!= NULL
)
11010 child_die
= die
->child
;
11011 while (child_die
&& child_die
->tag
)
11013 process_die (child_die
, cu
);
11014 child_die
= child_die
->sibling
;
11021 http://gcc.gnu.org/wiki/DebugFission
11022 http://gcc.gnu.org/wiki/DebugFissionDWP
11024 To simplify handling of both DWO files ("object" files with the DWARF info)
11025 and DWP files (a file with the DWOs packaged up into one file), we treat
11026 DWP files as having a collection of virtual DWO files. */
11029 hash_dwo_file (const void *item
)
11031 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11034 hash
= htab_hash_string (dwo_file
->dwo_name
);
11035 if (dwo_file
->comp_dir
!= NULL
)
11036 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11041 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11043 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11044 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11046 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11048 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11049 return lhs
->comp_dir
== rhs
->comp_dir
;
11050 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11053 /* Allocate a hash table for DWO files. */
11056 allocate_dwo_file_hash_table ()
11058 auto delete_dwo_file
= [] (void *item
)
11060 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11065 return htab_up (htab_create_alloc (41,
11072 /* Lookup DWO file DWO_NAME. */
11075 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11076 const char *dwo_name
,
11077 const char *comp_dir
)
11079 struct dwo_file find_entry
;
11082 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11083 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11085 find_entry
.dwo_name
= dwo_name
;
11086 find_entry
.comp_dir
= comp_dir
;
11087 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11094 hash_dwo_unit (const void *item
)
11096 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11098 /* This drops the top 32 bits of the id, but is ok for a hash. */
11099 return dwo_unit
->signature
;
11103 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11105 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11106 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11108 /* The signature is assumed to be unique within the DWO file.
11109 So while object file CU dwo_id's always have the value zero,
11110 that's OK, assuming each object file DWO file has only one CU,
11111 and that's the rule for now. */
11112 return lhs
->signature
== rhs
->signature
;
11115 /* Allocate a hash table for DWO CUs,TUs.
11116 There is one of these tables for each of CUs,TUs for each DWO file. */
11119 allocate_dwo_unit_table ()
11121 /* Start out with a pretty small number.
11122 Generally DWO files contain only one CU and maybe some TUs. */
11123 return htab_up (htab_create_alloc (3,
11126 NULL
, xcalloc
, xfree
));
11129 /* die_reader_func for create_dwo_cu. */
11132 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11133 const gdb_byte
*info_ptr
,
11134 struct die_info
*comp_unit_die
,
11135 struct dwo_file
*dwo_file
,
11136 struct dwo_unit
*dwo_unit
)
11138 struct dwarf2_cu
*cu
= reader
->cu
;
11139 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11140 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11142 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11143 if (!signature
.has_value ())
11145 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11146 " its dwo_id [in module %s]"),
11147 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11151 dwo_unit
->dwo_file
= dwo_file
;
11152 dwo_unit
->signature
= *signature
;
11153 dwo_unit
->section
= section
;
11154 dwo_unit
->sect_off
= sect_off
;
11155 dwo_unit
->length
= cu
->per_cu
->length
;
11157 if (dwarf_read_debug
)
11158 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11159 sect_offset_str (sect_off
),
11160 hex_string (dwo_unit
->signature
));
11163 /* Create the dwo_units for the CUs in a DWO_FILE.
11164 Note: This function processes DWO files only, not DWP files. */
11167 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11168 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11169 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11171 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11172 const gdb_byte
*info_ptr
, *end_ptr
;
11174 section
.read (objfile
);
11175 info_ptr
= section
.buffer
;
11177 if (info_ptr
== NULL
)
11180 if (dwarf_read_debug
)
11182 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11183 section
.get_name (),
11184 section
.get_file_name ());
11187 end_ptr
= info_ptr
+ section
.size
;
11188 while (info_ptr
< end_ptr
)
11190 struct dwarf2_per_cu_data per_cu
;
11191 struct dwo_unit read_unit
{};
11192 struct dwo_unit
*dwo_unit
;
11194 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11196 memset (&per_cu
, 0, sizeof (per_cu
));
11197 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11198 per_cu
.is_debug_types
= 0;
11199 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11200 per_cu
.section
= §ion
;
11202 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11203 if (!reader
.dummy_p
)
11204 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11205 &dwo_file
, &read_unit
);
11206 info_ptr
+= per_cu
.length
;
11208 // If the unit could not be parsed, skip it.
11209 if (read_unit
.dwo_file
== NULL
)
11212 if (cus_htab
== NULL
)
11213 cus_htab
= allocate_dwo_unit_table ();
11215 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11216 *dwo_unit
= read_unit
;
11217 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11218 gdb_assert (slot
!= NULL
);
11221 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11222 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11224 complaint (_("debug cu entry at offset %s is duplicate to"
11225 " the entry at offset %s, signature %s"),
11226 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11227 hex_string (dwo_unit
->signature
));
11229 *slot
= (void *)dwo_unit
;
11233 /* DWP file .debug_{cu,tu}_index section format:
11234 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11238 Both index sections have the same format, and serve to map a 64-bit
11239 signature to a set of section numbers. Each section begins with a header,
11240 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11241 indexes, and a pool of 32-bit section numbers. The index sections will be
11242 aligned at 8-byte boundaries in the file.
11244 The index section header consists of:
11246 V, 32 bit version number
11248 N, 32 bit number of compilation units or type units in the index
11249 M, 32 bit number of slots in the hash table
11251 Numbers are recorded using the byte order of the application binary.
11253 The hash table begins at offset 16 in the section, and consists of an array
11254 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11255 order of the application binary). Unused slots in the hash table are 0.
11256 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11258 The parallel table begins immediately after the hash table
11259 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11260 array of 32-bit indexes (using the byte order of the application binary),
11261 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11262 table contains a 32-bit index into the pool of section numbers. For unused
11263 hash table slots, the corresponding entry in the parallel table will be 0.
11265 The pool of section numbers begins immediately following the hash table
11266 (at offset 16 + 12 * M from the beginning of the section). The pool of
11267 section numbers consists of an array of 32-bit words (using the byte order
11268 of the application binary). Each item in the array is indexed starting
11269 from 0. The hash table entry provides the index of the first section
11270 number in the set. Additional section numbers in the set follow, and the
11271 set is terminated by a 0 entry (section number 0 is not used in ELF).
11273 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11274 section must be the first entry in the set, and the .debug_abbrev.dwo must
11275 be the second entry. Other members of the set may follow in any order.
11281 DWP Version 2 combines all the .debug_info, etc. sections into one,
11282 and the entries in the index tables are now offsets into these sections.
11283 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11286 Index Section Contents:
11288 Hash Table of Signatures dwp_hash_table.hash_table
11289 Parallel Table of Indices dwp_hash_table.unit_table
11290 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11291 Table of Section Sizes dwp_hash_table.v2.sizes
11293 The index section header consists of:
11295 V, 32 bit version number
11296 L, 32 bit number of columns in the table of section offsets
11297 N, 32 bit number of compilation units or type units in the index
11298 M, 32 bit number of slots in the hash table
11300 Numbers are recorded using the byte order of the application binary.
11302 The hash table has the same format as version 1.
11303 The parallel table of indices has the same format as version 1,
11304 except that the entries are origin-1 indices into the table of sections
11305 offsets and the table of section sizes.
11307 The table of offsets begins immediately following the parallel table
11308 (at offset 16 + 12 * M from the beginning of the section). The table is
11309 a two-dimensional array of 32-bit words (using the byte order of the
11310 application binary), with L columns and N+1 rows, in row-major order.
11311 Each row in the array is indexed starting from 0. The first row provides
11312 a key to the remaining rows: each column in this row provides an identifier
11313 for a debug section, and the offsets in the same column of subsequent rows
11314 refer to that section. The section identifiers are:
11316 DW_SECT_INFO 1 .debug_info.dwo
11317 DW_SECT_TYPES 2 .debug_types.dwo
11318 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11319 DW_SECT_LINE 4 .debug_line.dwo
11320 DW_SECT_LOC 5 .debug_loc.dwo
11321 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11322 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11323 DW_SECT_MACRO 8 .debug_macro.dwo
11325 The offsets provided by the CU and TU index sections are the base offsets
11326 for the contributions made by each CU or TU to the corresponding section
11327 in the package file. Each CU and TU header contains an abbrev_offset
11328 field, used to find the abbreviations table for that CU or TU within the
11329 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11330 be interpreted as relative to the base offset given in the index section.
11331 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11332 should be interpreted as relative to the base offset for .debug_line.dwo,
11333 and offsets into other debug sections obtained from DWARF attributes should
11334 also be interpreted as relative to the corresponding base offset.
11336 The table of sizes begins immediately following the table of offsets.
11337 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11338 with L columns and N rows, in row-major order. Each row in the array is
11339 indexed starting from 1 (row 0 is shared by the two tables).
11343 Hash table lookup is handled the same in version 1 and 2:
11345 We assume that N and M will not exceed 2^32 - 1.
11346 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11348 Given a 64-bit compilation unit signature or a type signature S, an entry
11349 in the hash table is located as follows:
11351 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11352 the low-order k bits all set to 1.
11354 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11356 3) If the hash table entry at index H matches the signature, use that
11357 entry. If the hash table entry at index H is unused (all zeroes),
11358 terminate the search: the signature is not present in the table.
11360 4) Let H = (H + H') modulo M. Repeat at Step 3.
11362 Because M > N and H' and M are relatively prime, the search is guaranteed
11363 to stop at an unused slot or find the match. */
11365 /* Create a hash table to map DWO IDs to their CU/TU entry in
11366 .debug_{info,types}.dwo in DWP_FILE.
11367 Returns NULL if there isn't one.
11368 Note: This function processes DWP files only, not DWO files. */
11370 static struct dwp_hash_table
*
11371 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11372 struct dwp_file
*dwp_file
, int is_debug_types
)
11374 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11375 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11376 const gdb_byte
*index_ptr
, *index_end
;
11377 struct dwarf2_section_info
*index
;
11378 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11379 struct dwp_hash_table
*htab
;
11381 if (is_debug_types
)
11382 index
= &dwp_file
->sections
.tu_index
;
11384 index
= &dwp_file
->sections
.cu_index
;
11386 if (index
->empty ())
11388 index
->read (objfile
);
11390 index_ptr
= index
->buffer
;
11391 index_end
= index_ptr
+ index
->size
;
11393 version
= read_4_bytes (dbfd
, index_ptr
);
11396 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11400 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11402 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11405 if (version
!= 1 && version
!= 2)
11407 error (_("Dwarf Error: unsupported DWP file version (%s)"
11408 " [in module %s]"),
11409 pulongest (version
), dwp_file
->name
);
11411 if (nr_slots
!= (nr_slots
& -nr_slots
))
11413 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11414 " is not power of 2 [in module %s]"),
11415 pulongest (nr_slots
), dwp_file
->name
);
11418 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11419 htab
->version
= version
;
11420 htab
->nr_columns
= nr_columns
;
11421 htab
->nr_units
= nr_units
;
11422 htab
->nr_slots
= nr_slots
;
11423 htab
->hash_table
= index_ptr
;
11424 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11426 /* Exit early if the table is empty. */
11427 if (nr_slots
== 0 || nr_units
== 0
11428 || (version
== 2 && nr_columns
== 0))
11430 /* All must be zero. */
11431 if (nr_slots
!= 0 || nr_units
!= 0
11432 || (version
== 2 && nr_columns
!= 0))
11434 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11435 " all zero [in modules %s]"),
11443 htab
->section_pool
.v1
.indices
=
11444 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11445 /* It's harder to decide whether the section is too small in v1.
11446 V1 is deprecated anyway so we punt. */
11450 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11451 int *ids
= htab
->section_pool
.v2
.section_ids
;
11452 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11453 /* Reverse map for error checking. */
11454 int ids_seen
[DW_SECT_MAX
+ 1];
11457 if (nr_columns
< 2)
11459 error (_("Dwarf Error: bad DWP hash table, too few columns"
11460 " in section table [in module %s]"),
11463 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11465 error (_("Dwarf Error: bad DWP hash table, too many columns"
11466 " in section table [in module %s]"),
11469 memset (ids
, 255, sizeof_ids
);
11470 memset (ids_seen
, 255, sizeof (ids_seen
));
11471 for (i
= 0; i
< nr_columns
; ++i
)
11473 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11475 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11477 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11478 " in section table [in module %s]"),
11479 id
, dwp_file
->name
);
11481 if (ids_seen
[id
] != -1)
11483 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11484 " id %d in section table [in module %s]"),
11485 id
, dwp_file
->name
);
11490 /* Must have exactly one info or types section. */
11491 if (((ids_seen
[DW_SECT_INFO
] != -1)
11492 + (ids_seen
[DW_SECT_TYPES
] != -1))
11495 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11496 " DWO info/types section [in module %s]"),
11499 /* Must have an abbrev section. */
11500 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11502 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11503 " section [in module %s]"),
11506 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11507 htab
->section_pool
.v2
.sizes
=
11508 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11509 * nr_units
* nr_columns
);
11510 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11511 * nr_units
* nr_columns
))
11514 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11515 " [in module %s]"),
11523 /* Update SECTIONS with the data from SECTP.
11525 This function is like the other "locate" section routines that are
11526 passed to bfd_map_over_sections, but in this context the sections to
11527 read comes from the DWP V1 hash table, not the full ELF section table.
11529 The result is non-zero for success, or zero if an error was found. */
11532 locate_v1_virtual_dwo_sections (asection
*sectp
,
11533 struct virtual_v1_dwo_sections
*sections
)
11535 const struct dwop_section_names
*names
= &dwop_section_names
;
11537 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11539 /* There can be only one. */
11540 if (sections
->abbrev
.s
.section
!= NULL
)
11542 sections
->abbrev
.s
.section
= sectp
;
11543 sections
->abbrev
.size
= bfd_section_size (sectp
);
11545 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11546 || section_is_p (sectp
->name
, &names
->types_dwo
))
11548 /* There can be only one. */
11549 if (sections
->info_or_types
.s
.section
!= NULL
)
11551 sections
->info_or_types
.s
.section
= sectp
;
11552 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11554 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11556 /* There can be only one. */
11557 if (sections
->line
.s
.section
!= NULL
)
11559 sections
->line
.s
.section
= sectp
;
11560 sections
->line
.size
= bfd_section_size (sectp
);
11562 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11564 /* There can be only one. */
11565 if (sections
->loc
.s
.section
!= NULL
)
11567 sections
->loc
.s
.section
= sectp
;
11568 sections
->loc
.size
= bfd_section_size (sectp
);
11570 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11572 /* There can be only one. */
11573 if (sections
->macinfo
.s
.section
!= NULL
)
11575 sections
->macinfo
.s
.section
= sectp
;
11576 sections
->macinfo
.size
= bfd_section_size (sectp
);
11578 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11580 /* There can be only one. */
11581 if (sections
->macro
.s
.section
!= NULL
)
11583 sections
->macro
.s
.section
= sectp
;
11584 sections
->macro
.size
= bfd_section_size (sectp
);
11586 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11588 /* There can be only one. */
11589 if (sections
->str_offsets
.s
.section
!= NULL
)
11591 sections
->str_offsets
.s
.section
= sectp
;
11592 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11596 /* No other kind of section is valid. */
11603 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11604 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11605 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11606 This is for DWP version 1 files. */
11608 static struct dwo_unit
*
11609 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11610 struct dwp_file
*dwp_file
,
11611 uint32_t unit_index
,
11612 const char *comp_dir
,
11613 ULONGEST signature
, int is_debug_types
)
11615 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11616 const struct dwp_hash_table
*dwp_htab
=
11617 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11618 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11619 const char *kind
= is_debug_types
? "TU" : "CU";
11620 struct dwo_file
*dwo_file
;
11621 struct dwo_unit
*dwo_unit
;
11622 struct virtual_v1_dwo_sections sections
;
11623 void **dwo_file_slot
;
11626 gdb_assert (dwp_file
->version
== 1);
11628 if (dwarf_read_debug
)
11630 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11632 pulongest (unit_index
), hex_string (signature
),
11636 /* Fetch the sections of this DWO unit.
11637 Put a limit on the number of sections we look for so that bad data
11638 doesn't cause us to loop forever. */
11640 #define MAX_NR_V1_DWO_SECTIONS \
11641 (1 /* .debug_info or .debug_types */ \
11642 + 1 /* .debug_abbrev */ \
11643 + 1 /* .debug_line */ \
11644 + 1 /* .debug_loc */ \
11645 + 1 /* .debug_str_offsets */ \
11646 + 1 /* .debug_macro or .debug_macinfo */ \
11647 + 1 /* trailing zero */)
11649 memset (§ions
, 0, sizeof (sections
));
11651 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11654 uint32_t section_nr
=
11655 read_4_bytes (dbfd
,
11656 dwp_htab
->section_pool
.v1
.indices
11657 + (unit_index
+ i
) * sizeof (uint32_t));
11659 if (section_nr
== 0)
11661 if (section_nr
>= dwp_file
->num_sections
)
11663 error (_("Dwarf Error: bad DWP hash table, section number too large"
11664 " [in module %s]"),
11668 sectp
= dwp_file
->elf_sections
[section_nr
];
11669 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11671 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11672 " [in module %s]"),
11678 || sections
.info_or_types
.empty ()
11679 || sections
.abbrev
.empty ())
11681 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11682 " [in module %s]"),
11685 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11687 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11688 " [in module %s]"),
11692 /* It's easier for the rest of the code if we fake a struct dwo_file and
11693 have dwo_unit "live" in that. At least for now.
11695 The DWP file can be made up of a random collection of CUs and TUs.
11696 However, for each CU + set of TUs that came from the same original DWO
11697 file, we can combine them back into a virtual DWO file to save space
11698 (fewer struct dwo_file objects to allocate). Remember that for really
11699 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11701 std::string virtual_dwo_name
=
11702 string_printf ("virtual-dwo/%d-%d-%d-%d",
11703 sections
.abbrev
.get_id (),
11704 sections
.line
.get_id (),
11705 sections
.loc
.get_id (),
11706 sections
.str_offsets
.get_id ());
11707 /* Can we use an existing virtual DWO file? */
11708 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11709 virtual_dwo_name
.c_str (),
11711 /* Create one if necessary. */
11712 if (*dwo_file_slot
== NULL
)
11714 if (dwarf_read_debug
)
11716 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11717 virtual_dwo_name
.c_str ());
11719 dwo_file
= new struct dwo_file
;
11720 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11721 dwo_file
->comp_dir
= comp_dir
;
11722 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11723 dwo_file
->sections
.line
= sections
.line
;
11724 dwo_file
->sections
.loc
= sections
.loc
;
11725 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11726 dwo_file
->sections
.macro
= sections
.macro
;
11727 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11728 /* The "str" section is global to the entire DWP file. */
11729 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11730 /* The info or types section is assigned below to dwo_unit,
11731 there's no need to record it in dwo_file.
11732 Also, we can't simply record type sections in dwo_file because
11733 we record a pointer into the vector in dwo_unit. As we collect more
11734 types we'll grow the vector and eventually have to reallocate space
11735 for it, invalidating all copies of pointers into the previous
11737 *dwo_file_slot
= dwo_file
;
11741 if (dwarf_read_debug
)
11743 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11744 virtual_dwo_name
.c_str ());
11746 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11749 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11750 dwo_unit
->dwo_file
= dwo_file
;
11751 dwo_unit
->signature
= signature
;
11752 dwo_unit
->section
=
11753 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11754 *dwo_unit
->section
= sections
.info_or_types
;
11755 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11760 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11761 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11762 piece within that section used by a TU/CU, return a virtual section
11763 of just that piece. */
11765 static struct dwarf2_section_info
11766 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11767 struct dwarf2_section_info
*section
,
11768 bfd_size_type offset
, bfd_size_type size
)
11770 struct dwarf2_section_info result
;
11773 gdb_assert (section
!= NULL
);
11774 gdb_assert (!section
->is_virtual
);
11776 memset (&result
, 0, sizeof (result
));
11777 result
.s
.containing_section
= section
;
11778 result
.is_virtual
= true;
11783 sectp
= section
->get_bfd_section ();
11785 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11786 bounds of the real section. This is a pretty-rare event, so just
11787 flag an error (easier) instead of a warning and trying to cope. */
11789 || offset
+ size
> bfd_section_size (sectp
))
11791 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11792 " in section %s [in module %s]"),
11793 sectp
? bfd_section_name (sectp
) : "<unknown>",
11794 objfile_name (dwarf2_per_objfile
->objfile
));
11797 result
.virtual_offset
= offset
;
11798 result
.size
= size
;
11802 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11803 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11804 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11805 This is for DWP version 2 files. */
11807 static struct dwo_unit
*
11808 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11809 struct dwp_file
*dwp_file
,
11810 uint32_t unit_index
,
11811 const char *comp_dir
,
11812 ULONGEST signature
, int is_debug_types
)
11814 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11815 const struct dwp_hash_table
*dwp_htab
=
11816 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11817 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11818 const char *kind
= is_debug_types
? "TU" : "CU";
11819 struct dwo_file
*dwo_file
;
11820 struct dwo_unit
*dwo_unit
;
11821 struct virtual_v2_dwo_sections sections
;
11822 void **dwo_file_slot
;
11825 gdb_assert (dwp_file
->version
== 2);
11827 if (dwarf_read_debug
)
11829 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11831 pulongest (unit_index
), hex_string (signature
),
11835 /* Fetch the section offsets of this DWO unit. */
11837 memset (§ions
, 0, sizeof (sections
));
11839 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11841 uint32_t offset
= read_4_bytes (dbfd
,
11842 dwp_htab
->section_pool
.v2
.offsets
11843 + (((unit_index
- 1) * dwp_htab
->nr_columns
11845 * sizeof (uint32_t)));
11846 uint32_t size
= read_4_bytes (dbfd
,
11847 dwp_htab
->section_pool
.v2
.sizes
11848 + (((unit_index
- 1) * dwp_htab
->nr_columns
11850 * sizeof (uint32_t)));
11852 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11855 case DW_SECT_TYPES
:
11856 sections
.info_or_types_offset
= offset
;
11857 sections
.info_or_types_size
= size
;
11859 case DW_SECT_ABBREV
:
11860 sections
.abbrev_offset
= offset
;
11861 sections
.abbrev_size
= size
;
11864 sections
.line_offset
= offset
;
11865 sections
.line_size
= size
;
11868 sections
.loc_offset
= offset
;
11869 sections
.loc_size
= size
;
11871 case DW_SECT_STR_OFFSETS
:
11872 sections
.str_offsets_offset
= offset
;
11873 sections
.str_offsets_size
= size
;
11875 case DW_SECT_MACINFO
:
11876 sections
.macinfo_offset
= offset
;
11877 sections
.macinfo_size
= size
;
11879 case DW_SECT_MACRO
:
11880 sections
.macro_offset
= offset
;
11881 sections
.macro_size
= size
;
11886 /* It's easier for the rest of the code if we fake a struct dwo_file and
11887 have dwo_unit "live" in that. At least for now.
11889 The DWP file can be made up of a random collection of CUs and TUs.
11890 However, for each CU + set of TUs that came from the same original DWO
11891 file, we can combine them back into a virtual DWO file to save space
11892 (fewer struct dwo_file objects to allocate). Remember that for really
11893 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11895 std::string virtual_dwo_name
=
11896 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11897 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11898 (long) (sections
.line_size
? sections
.line_offset
: 0),
11899 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11900 (long) (sections
.str_offsets_size
11901 ? sections
.str_offsets_offset
: 0));
11902 /* Can we use an existing virtual DWO file? */
11903 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11904 virtual_dwo_name
.c_str (),
11906 /* Create one if necessary. */
11907 if (*dwo_file_slot
== NULL
)
11909 if (dwarf_read_debug
)
11911 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11912 virtual_dwo_name
.c_str ());
11914 dwo_file
= new struct dwo_file
;
11915 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11916 dwo_file
->comp_dir
= comp_dir
;
11917 dwo_file
->sections
.abbrev
=
11918 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11919 sections
.abbrev_offset
, sections
.abbrev_size
);
11920 dwo_file
->sections
.line
=
11921 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11922 sections
.line_offset
, sections
.line_size
);
11923 dwo_file
->sections
.loc
=
11924 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11925 sections
.loc_offset
, sections
.loc_size
);
11926 dwo_file
->sections
.macinfo
=
11927 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11928 sections
.macinfo_offset
, sections
.macinfo_size
);
11929 dwo_file
->sections
.macro
=
11930 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11931 sections
.macro_offset
, sections
.macro_size
);
11932 dwo_file
->sections
.str_offsets
=
11933 create_dwp_v2_section (dwarf2_per_objfile
,
11934 &dwp_file
->sections
.str_offsets
,
11935 sections
.str_offsets_offset
,
11936 sections
.str_offsets_size
);
11937 /* The "str" section is global to the entire DWP file. */
11938 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11939 /* The info or types section is assigned below to dwo_unit,
11940 there's no need to record it in dwo_file.
11941 Also, we can't simply record type sections in dwo_file because
11942 we record a pointer into the vector in dwo_unit. As we collect more
11943 types we'll grow the vector and eventually have to reallocate space
11944 for it, invalidating all copies of pointers into the previous
11946 *dwo_file_slot
= dwo_file
;
11950 if (dwarf_read_debug
)
11952 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11953 virtual_dwo_name
.c_str ());
11955 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11958 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11959 dwo_unit
->dwo_file
= dwo_file
;
11960 dwo_unit
->signature
= signature
;
11961 dwo_unit
->section
=
11962 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11963 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11965 ? &dwp_file
->sections
.types
11966 : &dwp_file
->sections
.info
,
11967 sections
.info_or_types_offset
,
11968 sections
.info_or_types_size
);
11969 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11974 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11975 Returns NULL if the signature isn't found. */
11977 static struct dwo_unit
*
11978 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11979 struct dwp_file
*dwp_file
, const char *comp_dir
,
11980 ULONGEST signature
, int is_debug_types
)
11982 const struct dwp_hash_table
*dwp_htab
=
11983 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11984 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11985 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11986 uint32_t hash
= signature
& mask
;
11987 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11990 struct dwo_unit find_dwo_cu
;
11992 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11993 find_dwo_cu
.signature
= signature
;
11994 slot
= htab_find_slot (is_debug_types
11995 ? dwp_file
->loaded_tus
.get ()
11996 : dwp_file
->loaded_cus
.get (),
11997 &find_dwo_cu
, INSERT
);
12000 return (struct dwo_unit
*) *slot
;
12002 /* Use a for loop so that we don't loop forever on bad debug info. */
12003 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12005 ULONGEST signature_in_table
;
12007 signature_in_table
=
12008 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12009 if (signature_in_table
== signature
)
12011 uint32_t unit_index
=
12012 read_4_bytes (dbfd
,
12013 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12015 if (dwp_file
->version
== 1)
12017 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12018 dwp_file
, unit_index
,
12019 comp_dir
, signature
,
12024 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12025 dwp_file
, unit_index
,
12026 comp_dir
, signature
,
12029 return (struct dwo_unit
*) *slot
;
12031 if (signature_in_table
== 0)
12033 hash
= (hash
+ hash2
) & mask
;
12036 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12037 " [in module %s]"),
12041 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12042 Open the file specified by FILE_NAME and hand it off to BFD for
12043 preliminary analysis. Return a newly initialized bfd *, which
12044 includes a canonicalized copy of FILE_NAME.
12045 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12046 SEARCH_CWD is true if the current directory is to be searched.
12047 It will be searched before debug-file-directory.
12048 If successful, the file is added to the bfd include table of the
12049 objfile's bfd (see gdb_bfd_record_inclusion).
12050 If unable to find/open the file, return NULL.
12051 NOTE: This function is derived from symfile_bfd_open. */
12053 static gdb_bfd_ref_ptr
12054 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12055 const char *file_name
, int is_dwp
, int search_cwd
)
12058 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12059 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12060 to debug_file_directory. */
12061 const char *search_path
;
12062 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12064 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12067 if (*debug_file_directory
!= '\0')
12069 search_path_holder
.reset (concat (".", dirname_separator_string
,
12070 debug_file_directory
,
12072 search_path
= search_path_holder
.get ();
12078 search_path
= debug_file_directory
;
12080 openp_flags flags
= OPF_RETURN_REALPATH
;
12082 flags
|= OPF_SEARCH_IN_PATH
;
12084 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12085 desc
= openp (search_path
, flags
, file_name
,
12086 O_RDONLY
| O_BINARY
, &absolute_name
);
12090 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12092 if (sym_bfd
== NULL
)
12094 bfd_set_cacheable (sym_bfd
.get (), 1);
12096 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12099 /* Success. Record the bfd as having been included by the objfile's bfd.
12100 This is important because things like demangled_names_hash lives in the
12101 objfile's per_bfd space and may have references to things like symbol
12102 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12103 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12108 /* Try to open DWO file FILE_NAME.
12109 COMP_DIR is the DW_AT_comp_dir attribute.
12110 The result is the bfd handle of the file.
12111 If there is a problem finding or opening the file, return NULL.
12112 Upon success, the canonicalized path of the file is stored in the bfd,
12113 same as symfile_bfd_open. */
12115 static gdb_bfd_ref_ptr
12116 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12117 const char *file_name
, const char *comp_dir
)
12119 if (IS_ABSOLUTE_PATH (file_name
))
12120 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12121 0 /*is_dwp*/, 0 /*search_cwd*/);
12123 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12125 if (comp_dir
!= NULL
)
12127 gdb::unique_xmalloc_ptr
<char> path_to_try
12128 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12130 /* NOTE: If comp_dir is a relative path, this will also try the
12131 search path, which seems useful. */
12132 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12133 path_to_try
.get (),
12135 1 /*search_cwd*/));
12140 /* That didn't work, try debug-file-directory, which, despite its name,
12141 is a list of paths. */
12143 if (*debug_file_directory
== '\0')
12146 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12147 0 /*is_dwp*/, 1 /*search_cwd*/);
12150 /* This function is mapped across the sections and remembers the offset and
12151 size of each of the DWO debugging sections we are interested in. */
12154 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12156 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12157 const struct dwop_section_names
*names
= &dwop_section_names
;
12159 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12161 dwo_sections
->abbrev
.s
.section
= sectp
;
12162 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12164 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12166 dwo_sections
->info
.s
.section
= sectp
;
12167 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12169 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12171 dwo_sections
->line
.s
.section
= sectp
;
12172 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12174 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12176 dwo_sections
->loc
.s
.section
= sectp
;
12177 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12179 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12181 dwo_sections
->loclists
.s
.section
= sectp
;
12182 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12184 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12186 dwo_sections
->macinfo
.s
.section
= sectp
;
12187 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12189 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12191 dwo_sections
->macro
.s
.section
= sectp
;
12192 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12194 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12196 dwo_sections
->str
.s
.section
= sectp
;
12197 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12199 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12201 dwo_sections
->str_offsets
.s
.section
= sectp
;
12202 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12204 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12206 struct dwarf2_section_info type_section
;
12208 memset (&type_section
, 0, sizeof (type_section
));
12209 type_section
.s
.section
= sectp
;
12210 type_section
.size
= bfd_section_size (sectp
);
12211 dwo_sections
->types
.push_back (type_section
);
12215 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12216 by PER_CU. This is for the non-DWP case.
12217 The result is NULL if DWO_NAME can't be found. */
12219 static struct dwo_file
*
12220 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12221 const char *dwo_name
, const char *comp_dir
)
12223 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12225 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12228 if (dwarf_read_debug
)
12229 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12233 dwo_file_up
dwo_file (new struct dwo_file
);
12234 dwo_file
->dwo_name
= dwo_name
;
12235 dwo_file
->comp_dir
= comp_dir
;
12236 dwo_file
->dbfd
= std::move (dbfd
);
12238 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12239 &dwo_file
->sections
);
12241 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12242 dwo_file
->sections
.info
, dwo_file
->cus
);
12244 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12245 dwo_file
->sections
.types
, dwo_file
->tus
);
12247 if (dwarf_read_debug
)
12248 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12250 return dwo_file
.release ();
12253 /* This function is mapped across the sections and remembers the offset and
12254 size of each of the DWP debugging sections common to version 1 and 2 that
12255 we are interested in. */
12258 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12259 void *dwp_file_ptr
)
12261 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12262 const struct dwop_section_names
*names
= &dwop_section_names
;
12263 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12265 /* Record the ELF section number for later lookup: this is what the
12266 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12267 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12268 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12270 /* Look for specific sections that we need. */
12271 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12273 dwp_file
->sections
.str
.s
.section
= sectp
;
12274 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12276 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12278 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12279 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12281 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12283 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12284 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12288 /* This function is mapped across the sections and remembers the offset and
12289 size of each of the DWP version 2 debugging sections that we are interested
12290 in. This is split into a separate function because we don't know if we
12291 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12294 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12296 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12297 const struct dwop_section_names
*names
= &dwop_section_names
;
12298 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12300 /* Record the ELF section number for later lookup: this is what the
12301 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12302 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12303 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12305 /* Look for specific sections that we need. */
12306 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12308 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12309 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12311 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12313 dwp_file
->sections
.info
.s
.section
= sectp
;
12314 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12316 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12318 dwp_file
->sections
.line
.s
.section
= sectp
;
12319 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12321 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12323 dwp_file
->sections
.loc
.s
.section
= sectp
;
12324 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12326 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12328 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12329 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12331 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12333 dwp_file
->sections
.macro
.s
.section
= sectp
;
12334 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12336 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12338 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12339 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12341 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12343 dwp_file
->sections
.types
.s
.section
= sectp
;
12344 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12348 /* Hash function for dwp_file loaded CUs/TUs. */
12351 hash_dwp_loaded_cutus (const void *item
)
12353 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12355 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12356 return dwo_unit
->signature
;
12359 /* Equality function for dwp_file loaded CUs/TUs. */
12362 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12364 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12365 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12367 return dua
->signature
== dub
->signature
;
12370 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12373 allocate_dwp_loaded_cutus_table ()
12375 return htab_up (htab_create_alloc (3,
12376 hash_dwp_loaded_cutus
,
12377 eq_dwp_loaded_cutus
,
12378 NULL
, xcalloc
, xfree
));
12381 /* Try to open DWP file FILE_NAME.
12382 The result is the bfd handle of the file.
12383 If there is a problem finding or opening the file, return NULL.
12384 Upon success, the canonicalized path of the file is stored in the bfd,
12385 same as symfile_bfd_open. */
12387 static gdb_bfd_ref_ptr
12388 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12389 const char *file_name
)
12391 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12393 1 /*search_cwd*/));
12397 /* Work around upstream bug 15652.
12398 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12399 [Whether that's a "bug" is debatable, but it is getting in our way.]
12400 We have no real idea where the dwp file is, because gdb's realpath-ing
12401 of the executable's path may have discarded the needed info.
12402 [IWBN if the dwp file name was recorded in the executable, akin to
12403 .gnu_debuglink, but that doesn't exist yet.]
12404 Strip the directory from FILE_NAME and search again. */
12405 if (*debug_file_directory
!= '\0')
12407 /* Don't implicitly search the current directory here.
12408 If the user wants to search "." to handle this case,
12409 it must be added to debug-file-directory. */
12410 return try_open_dwop_file (dwarf2_per_objfile
,
12411 lbasename (file_name
), 1 /*is_dwp*/,
12418 /* Initialize the use of the DWP file for the current objfile.
12419 By convention the name of the DWP file is ${objfile}.dwp.
12420 The result is NULL if it can't be found. */
12422 static std::unique_ptr
<struct dwp_file
>
12423 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12425 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12427 /* Try to find first .dwp for the binary file before any symbolic links
12430 /* If the objfile is a debug file, find the name of the real binary
12431 file and get the name of dwp file from there. */
12432 std::string dwp_name
;
12433 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12435 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12436 const char *backlink_basename
= lbasename (backlink
->original_name
);
12438 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12441 dwp_name
= objfile
->original_name
;
12443 dwp_name
+= ".dwp";
12445 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12447 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12449 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12450 dwp_name
= objfile_name (objfile
);
12451 dwp_name
+= ".dwp";
12452 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12457 if (dwarf_read_debug
)
12458 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12459 return std::unique_ptr
<dwp_file
> ();
12462 const char *name
= bfd_get_filename (dbfd
.get ());
12463 std::unique_ptr
<struct dwp_file
> dwp_file
12464 (new struct dwp_file (name
, std::move (dbfd
)));
12466 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12467 dwp_file
->elf_sections
=
12468 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12469 dwp_file
->num_sections
, asection
*);
12471 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12472 dwarf2_locate_common_dwp_sections
,
12475 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12478 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12481 /* The DWP file version is stored in the hash table. Oh well. */
12482 if (dwp_file
->cus
&& dwp_file
->tus
12483 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12485 /* Technically speaking, we should try to limp along, but this is
12486 pretty bizarre. We use pulongest here because that's the established
12487 portability solution (e.g, we cannot use %u for uint32_t). */
12488 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12489 " TU version %s [in DWP file %s]"),
12490 pulongest (dwp_file
->cus
->version
),
12491 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12495 dwp_file
->version
= dwp_file
->cus
->version
;
12496 else if (dwp_file
->tus
)
12497 dwp_file
->version
= dwp_file
->tus
->version
;
12499 dwp_file
->version
= 2;
12501 if (dwp_file
->version
== 2)
12502 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12503 dwarf2_locate_v2_dwp_sections
,
12506 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12507 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12509 if (dwarf_read_debug
)
12511 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12512 fprintf_unfiltered (gdb_stdlog
,
12513 " %s CUs, %s TUs\n",
12514 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12515 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12521 /* Wrapper around open_and_init_dwp_file, only open it once. */
12523 static struct dwp_file
*
12524 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12526 if (! dwarf2_per_objfile
->dwp_checked
)
12528 dwarf2_per_objfile
->dwp_file
12529 = open_and_init_dwp_file (dwarf2_per_objfile
);
12530 dwarf2_per_objfile
->dwp_checked
= 1;
12532 return dwarf2_per_objfile
->dwp_file
.get ();
12535 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12536 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12537 or in the DWP file for the objfile, referenced by THIS_UNIT.
12538 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12539 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12541 This is called, for example, when wanting to read a variable with a
12542 complex location. Therefore we don't want to do file i/o for every call.
12543 Therefore we don't want to look for a DWO file on every call.
12544 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12545 then we check if we've already seen DWO_NAME, and only THEN do we check
12548 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12549 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12551 static struct dwo_unit
*
12552 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12553 const char *dwo_name
, const char *comp_dir
,
12554 ULONGEST signature
, int is_debug_types
)
12556 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12557 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12558 const char *kind
= is_debug_types
? "TU" : "CU";
12559 void **dwo_file_slot
;
12560 struct dwo_file
*dwo_file
;
12561 struct dwp_file
*dwp_file
;
12563 /* First see if there's a DWP file.
12564 If we have a DWP file but didn't find the DWO inside it, don't
12565 look for the original DWO file. It makes gdb behave differently
12566 depending on whether one is debugging in the build tree. */
12568 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12569 if (dwp_file
!= NULL
)
12571 const struct dwp_hash_table
*dwp_htab
=
12572 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12574 if (dwp_htab
!= NULL
)
12576 struct dwo_unit
*dwo_cutu
=
12577 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12578 signature
, is_debug_types
);
12580 if (dwo_cutu
!= NULL
)
12582 if (dwarf_read_debug
)
12584 fprintf_unfiltered (gdb_stdlog
,
12585 "Virtual DWO %s %s found: @%s\n",
12586 kind
, hex_string (signature
),
12587 host_address_to_string (dwo_cutu
));
12595 /* No DWP file, look for the DWO file. */
12597 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12598 dwo_name
, comp_dir
);
12599 if (*dwo_file_slot
== NULL
)
12601 /* Read in the file and build a table of the CUs/TUs it contains. */
12602 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12604 /* NOTE: This will be NULL if unable to open the file. */
12605 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12607 if (dwo_file
!= NULL
)
12609 struct dwo_unit
*dwo_cutu
= NULL
;
12611 if (is_debug_types
&& dwo_file
->tus
)
12613 struct dwo_unit find_dwo_cutu
;
12615 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12616 find_dwo_cutu
.signature
= signature
;
12618 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12621 else if (!is_debug_types
&& dwo_file
->cus
)
12623 struct dwo_unit find_dwo_cutu
;
12625 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12626 find_dwo_cutu
.signature
= signature
;
12627 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12631 if (dwo_cutu
!= NULL
)
12633 if (dwarf_read_debug
)
12635 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12636 kind
, dwo_name
, hex_string (signature
),
12637 host_address_to_string (dwo_cutu
));
12644 /* We didn't find it. This could mean a dwo_id mismatch, or
12645 someone deleted the DWO/DWP file, or the search path isn't set up
12646 correctly to find the file. */
12648 if (dwarf_read_debug
)
12650 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12651 kind
, dwo_name
, hex_string (signature
));
12654 /* This is a warning and not a complaint because it can be caused by
12655 pilot error (e.g., user accidentally deleting the DWO). */
12657 /* Print the name of the DWP file if we looked there, helps the user
12658 better diagnose the problem. */
12659 std::string dwp_text
;
12661 if (dwp_file
!= NULL
)
12662 dwp_text
= string_printf (" [in DWP file %s]",
12663 lbasename (dwp_file
->name
));
12665 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12666 " [in module %s]"),
12667 kind
, dwo_name
, hex_string (signature
),
12669 this_unit
->is_debug_types
? "TU" : "CU",
12670 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12675 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12676 See lookup_dwo_cutu_unit for details. */
12678 static struct dwo_unit
*
12679 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12680 const char *dwo_name
, const char *comp_dir
,
12681 ULONGEST signature
)
12683 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12686 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12687 See lookup_dwo_cutu_unit for details. */
12689 static struct dwo_unit
*
12690 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12691 const char *dwo_name
, const char *comp_dir
)
12693 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12696 /* Traversal function for queue_and_load_all_dwo_tus. */
12699 queue_and_load_dwo_tu (void **slot
, void *info
)
12701 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12702 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12703 ULONGEST signature
= dwo_unit
->signature
;
12704 struct signatured_type
*sig_type
=
12705 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12707 if (sig_type
!= NULL
)
12709 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12711 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12712 a real dependency of PER_CU on SIG_TYPE. That is detected later
12713 while processing PER_CU. */
12714 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12715 load_full_type_unit (sig_cu
);
12716 per_cu
->imported_symtabs_push (sig_cu
);
12722 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12723 The DWO may have the only definition of the type, though it may not be
12724 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12725 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12728 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12730 struct dwo_unit
*dwo_unit
;
12731 struct dwo_file
*dwo_file
;
12733 gdb_assert (!per_cu
->is_debug_types
);
12734 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12735 gdb_assert (per_cu
->cu
!= NULL
);
12737 dwo_unit
= per_cu
->cu
->dwo_unit
;
12738 gdb_assert (dwo_unit
!= NULL
);
12740 dwo_file
= dwo_unit
->dwo_file
;
12741 if (dwo_file
->tus
!= NULL
)
12742 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12746 /* Read in various DIEs. */
12748 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12749 Inherit only the children of the DW_AT_abstract_origin DIE not being
12750 already referenced by DW_AT_abstract_origin from the children of the
12754 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12756 struct die_info
*child_die
;
12757 sect_offset
*offsetp
;
12758 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12759 struct die_info
*origin_die
;
12760 /* Iterator of the ORIGIN_DIE children. */
12761 struct die_info
*origin_child_die
;
12762 struct attribute
*attr
;
12763 struct dwarf2_cu
*origin_cu
;
12764 struct pending
**origin_previous_list_in_scope
;
12766 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12770 /* Note that following die references may follow to a die in a
12774 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12776 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12778 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12779 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12781 if (die
->tag
!= origin_die
->tag
12782 && !(die
->tag
== DW_TAG_inlined_subroutine
12783 && origin_die
->tag
== DW_TAG_subprogram
))
12784 complaint (_("DIE %s and its abstract origin %s have different tags"),
12785 sect_offset_str (die
->sect_off
),
12786 sect_offset_str (origin_die
->sect_off
));
12788 std::vector
<sect_offset
> offsets
;
12790 for (child_die
= die
->child
;
12791 child_die
&& child_die
->tag
;
12792 child_die
= child_die
->sibling
)
12794 struct die_info
*child_origin_die
;
12795 struct dwarf2_cu
*child_origin_cu
;
12797 /* We are trying to process concrete instance entries:
12798 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12799 it's not relevant to our analysis here. i.e. detecting DIEs that are
12800 present in the abstract instance but not referenced in the concrete
12802 if (child_die
->tag
== DW_TAG_call_site
12803 || child_die
->tag
== DW_TAG_GNU_call_site
)
12806 /* For each CHILD_DIE, find the corresponding child of
12807 ORIGIN_DIE. If there is more than one layer of
12808 DW_AT_abstract_origin, follow them all; there shouldn't be,
12809 but GCC versions at least through 4.4 generate this (GCC PR
12811 child_origin_die
= child_die
;
12812 child_origin_cu
= cu
;
12815 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12819 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12823 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12824 counterpart may exist. */
12825 if (child_origin_die
!= child_die
)
12827 if (child_die
->tag
!= child_origin_die
->tag
12828 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12829 && child_origin_die
->tag
== DW_TAG_subprogram
))
12830 complaint (_("Child DIE %s and its abstract origin %s have "
12832 sect_offset_str (child_die
->sect_off
),
12833 sect_offset_str (child_origin_die
->sect_off
));
12834 if (child_origin_die
->parent
!= origin_die
)
12835 complaint (_("Child DIE %s and its abstract origin %s have "
12836 "different parents"),
12837 sect_offset_str (child_die
->sect_off
),
12838 sect_offset_str (child_origin_die
->sect_off
));
12840 offsets
.push_back (child_origin_die
->sect_off
);
12843 std::sort (offsets
.begin (), offsets
.end ());
12844 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12845 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12846 if (offsetp
[-1] == *offsetp
)
12847 complaint (_("Multiple children of DIE %s refer "
12848 "to DIE %s as their abstract origin"),
12849 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12851 offsetp
= offsets
.data ();
12852 origin_child_die
= origin_die
->child
;
12853 while (origin_child_die
&& origin_child_die
->tag
)
12855 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12856 while (offsetp
< offsets_end
12857 && *offsetp
< origin_child_die
->sect_off
)
12859 if (offsetp
>= offsets_end
12860 || *offsetp
> origin_child_die
->sect_off
)
12862 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12863 Check whether we're already processing ORIGIN_CHILD_DIE.
12864 This can happen with mutually referenced abstract_origins.
12866 if (!origin_child_die
->in_process
)
12867 process_die (origin_child_die
, origin_cu
);
12869 origin_child_die
= origin_child_die
->sibling
;
12871 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12873 if (cu
!= origin_cu
)
12874 compute_delayed_physnames (origin_cu
);
12878 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12880 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12881 struct gdbarch
*gdbarch
= objfile
->arch ();
12882 struct context_stack
*newobj
;
12885 struct die_info
*child_die
;
12886 struct attribute
*attr
, *call_line
, *call_file
;
12888 CORE_ADDR baseaddr
;
12889 struct block
*block
;
12890 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12891 std::vector
<struct symbol
*> template_args
;
12892 struct template_symbol
*templ_func
= NULL
;
12896 /* If we do not have call site information, we can't show the
12897 caller of this inlined function. That's too confusing, so
12898 only use the scope for local variables. */
12899 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12900 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12901 if (call_line
== NULL
|| call_file
== NULL
)
12903 read_lexical_block_scope (die
, cu
);
12908 baseaddr
= objfile
->text_section_offset ();
12910 name
= dwarf2_name (die
, cu
);
12912 /* Ignore functions with missing or empty names. These are actually
12913 illegal according to the DWARF standard. */
12916 complaint (_("missing name for subprogram DIE at %s"),
12917 sect_offset_str (die
->sect_off
));
12921 /* Ignore functions with missing or invalid low and high pc attributes. */
12922 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12923 <= PC_BOUNDS_INVALID
)
12925 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12926 if (!attr
|| !DW_UNSND (attr
))
12927 complaint (_("cannot get low and high bounds "
12928 "for subprogram DIE at %s"),
12929 sect_offset_str (die
->sect_off
));
12933 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12934 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12936 /* If we have any template arguments, then we must allocate a
12937 different sort of symbol. */
12938 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12940 if (child_die
->tag
== DW_TAG_template_type_param
12941 || child_die
->tag
== DW_TAG_template_value_param
)
12943 templ_func
= allocate_template_symbol (objfile
);
12944 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12949 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12950 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12951 (struct symbol
*) templ_func
);
12953 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12954 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12957 /* If there is a location expression for DW_AT_frame_base, record
12959 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12960 if (attr
!= nullptr)
12961 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12963 /* If there is a location for the static link, record it. */
12964 newobj
->static_link
= NULL
;
12965 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12966 if (attr
!= nullptr)
12968 newobj
->static_link
12969 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12970 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12971 cu
->per_cu
->addr_type ());
12974 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12976 if (die
->child
!= NULL
)
12978 child_die
= die
->child
;
12979 while (child_die
&& child_die
->tag
)
12981 if (child_die
->tag
== DW_TAG_template_type_param
12982 || child_die
->tag
== DW_TAG_template_value_param
)
12984 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12987 template_args
.push_back (arg
);
12990 process_die (child_die
, cu
);
12991 child_die
= child_die
->sibling
;
12995 inherit_abstract_dies (die
, cu
);
12997 /* If we have a DW_AT_specification, we might need to import using
12998 directives from the context of the specification DIE. See the
12999 comment in determine_prefix. */
13000 if (cu
->language
== language_cplus
13001 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13003 struct dwarf2_cu
*spec_cu
= cu
;
13004 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13008 child_die
= spec_die
->child
;
13009 while (child_die
&& child_die
->tag
)
13011 if (child_die
->tag
== DW_TAG_imported_module
)
13012 process_die (child_die
, spec_cu
);
13013 child_die
= child_die
->sibling
;
13016 /* In some cases, GCC generates specification DIEs that
13017 themselves contain DW_AT_specification attributes. */
13018 spec_die
= die_specification (spec_die
, &spec_cu
);
13022 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13023 /* Make a block for the local symbols within. */
13024 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13025 cstk
.static_link
, lowpc
, highpc
);
13027 /* For C++, set the block's scope. */
13028 if ((cu
->language
== language_cplus
13029 || cu
->language
== language_fortran
13030 || cu
->language
== language_d
13031 || cu
->language
== language_rust
)
13032 && cu
->processing_has_namespace_info
)
13033 block_set_scope (block
, determine_prefix (die
, cu
),
13034 &objfile
->objfile_obstack
);
13036 /* If we have address ranges, record them. */
13037 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13039 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13041 /* Attach template arguments to function. */
13042 if (!template_args
.empty ())
13044 gdb_assert (templ_func
!= NULL
);
13046 templ_func
->n_template_arguments
= template_args
.size ();
13047 templ_func
->template_arguments
13048 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13049 templ_func
->n_template_arguments
);
13050 memcpy (templ_func
->template_arguments
,
13051 template_args
.data (),
13052 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13054 /* Make sure that the symtab is set on the new symbols. Even
13055 though they don't appear in this symtab directly, other parts
13056 of gdb assume that symbols do, and this is reasonably
13058 for (symbol
*sym
: template_args
)
13059 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13062 /* In C++, we can have functions nested inside functions (e.g., when
13063 a function declares a class that has methods). This means that
13064 when we finish processing a function scope, we may need to go
13065 back to building a containing block's symbol lists. */
13066 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13067 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13069 /* If we've finished processing a top-level function, subsequent
13070 symbols go in the file symbol list. */
13071 if (cu
->get_builder ()->outermost_context_p ())
13072 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13075 /* Process all the DIES contained within a lexical block scope. Start
13076 a new scope, process the dies, and then close the scope. */
13079 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13081 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13082 struct gdbarch
*gdbarch
= objfile
->arch ();
13083 CORE_ADDR lowpc
, highpc
;
13084 struct die_info
*child_die
;
13085 CORE_ADDR baseaddr
;
13087 baseaddr
= objfile
->text_section_offset ();
13089 /* Ignore blocks with missing or invalid low and high pc attributes. */
13090 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13091 as multiple lexical blocks? Handling children in a sane way would
13092 be nasty. Might be easier to properly extend generic blocks to
13093 describe ranges. */
13094 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13096 case PC_BOUNDS_NOT_PRESENT
:
13097 /* DW_TAG_lexical_block has no attributes, process its children as if
13098 there was no wrapping by that DW_TAG_lexical_block.
13099 GCC does no longer produces such DWARF since GCC r224161. */
13100 for (child_die
= die
->child
;
13101 child_die
!= NULL
&& child_die
->tag
;
13102 child_die
= child_die
->sibling
)
13103 process_die (child_die
, cu
);
13105 case PC_BOUNDS_INVALID
:
13108 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13109 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13111 cu
->get_builder ()->push_context (0, lowpc
);
13112 if (die
->child
!= NULL
)
13114 child_die
= die
->child
;
13115 while (child_die
&& child_die
->tag
)
13117 process_die (child_die
, cu
);
13118 child_die
= child_die
->sibling
;
13121 inherit_abstract_dies (die
, cu
);
13122 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13124 if (*cu
->get_builder ()->get_local_symbols () != NULL
13125 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13127 struct block
*block
13128 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13129 cstk
.start_addr
, highpc
);
13131 /* Note that recording ranges after traversing children, as we
13132 do here, means that recording a parent's ranges entails
13133 walking across all its children's ranges as they appear in
13134 the address map, which is quadratic behavior.
13136 It would be nicer to record the parent's ranges before
13137 traversing its children, simply overriding whatever you find
13138 there. But since we don't even decide whether to create a
13139 block until after we've traversed its children, that's hard
13141 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13143 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13144 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13147 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13150 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13152 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13153 struct gdbarch
*gdbarch
= objfile
->arch ();
13154 CORE_ADDR pc
, baseaddr
;
13155 struct attribute
*attr
;
13156 struct call_site
*call_site
, call_site_local
;
13159 struct die_info
*child_die
;
13161 baseaddr
= objfile
->text_section_offset ();
13163 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13166 /* This was a pre-DWARF-5 GNU extension alias
13167 for DW_AT_call_return_pc. */
13168 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13172 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13173 "DIE %s [in module %s]"),
13174 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13177 pc
= attr
->value_as_address () + baseaddr
;
13178 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13180 if (cu
->call_site_htab
== NULL
)
13181 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13182 NULL
, &objfile
->objfile_obstack
,
13183 hashtab_obstack_allocate
, NULL
);
13184 call_site_local
.pc
= pc
;
13185 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13188 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13189 "DIE %s [in module %s]"),
13190 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13191 objfile_name (objfile
));
13195 /* Count parameters at the caller. */
13198 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13199 child_die
= child_die
->sibling
)
13201 if (child_die
->tag
!= DW_TAG_call_site_parameter
13202 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13204 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13205 "DW_TAG_call_site child DIE %s [in module %s]"),
13206 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13207 objfile_name (objfile
));
13215 = ((struct call_site
*)
13216 obstack_alloc (&objfile
->objfile_obstack
,
13217 sizeof (*call_site
)
13218 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13220 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13221 call_site
->pc
= pc
;
13223 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13224 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13226 struct die_info
*func_die
;
13228 /* Skip also over DW_TAG_inlined_subroutine. */
13229 for (func_die
= die
->parent
;
13230 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13231 && func_die
->tag
!= DW_TAG_subroutine_type
;
13232 func_die
= func_die
->parent
);
13234 /* DW_AT_call_all_calls is a superset
13235 of DW_AT_call_all_tail_calls. */
13237 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13238 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13239 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13240 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13242 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13243 not complete. But keep CALL_SITE for look ups via call_site_htab,
13244 both the initial caller containing the real return address PC and
13245 the final callee containing the current PC of a chain of tail
13246 calls do not need to have the tail call list complete. But any
13247 function candidate for a virtual tail call frame searched via
13248 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13249 determined unambiguously. */
13253 struct type
*func_type
= NULL
;
13256 func_type
= get_die_type (func_die
, cu
);
13257 if (func_type
!= NULL
)
13259 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13261 /* Enlist this call site to the function. */
13262 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13263 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13266 complaint (_("Cannot find function owning DW_TAG_call_site "
13267 "DIE %s [in module %s]"),
13268 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13272 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13274 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13276 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13279 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13280 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13282 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13283 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13284 /* Keep NULL DWARF_BLOCK. */;
13285 else if (attr
->form_is_block ())
13287 struct dwarf2_locexpr_baton
*dlbaton
;
13289 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13290 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13291 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13292 dlbaton
->per_cu
= cu
->per_cu
;
13294 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13296 else if (attr
->form_is_ref ())
13298 struct dwarf2_cu
*target_cu
= cu
;
13299 struct die_info
*target_die
;
13301 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13302 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13303 if (die_is_declaration (target_die
, target_cu
))
13305 const char *target_physname
;
13307 /* Prefer the mangled name; otherwise compute the demangled one. */
13308 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13309 if (target_physname
== NULL
)
13310 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13311 if (target_physname
== NULL
)
13312 complaint (_("DW_AT_call_target target DIE has invalid "
13313 "physname, for referencing DIE %s [in module %s]"),
13314 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13316 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13322 /* DW_AT_entry_pc should be preferred. */
13323 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13324 <= PC_BOUNDS_INVALID
)
13325 complaint (_("DW_AT_call_target target DIE has invalid "
13326 "low pc, for referencing DIE %s [in module %s]"),
13327 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13330 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13331 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13336 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13337 "block nor reference, for DIE %s [in module %s]"),
13338 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13340 call_site
->per_cu
= cu
->per_cu
;
13342 for (child_die
= die
->child
;
13343 child_die
&& child_die
->tag
;
13344 child_die
= child_die
->sibling
)
13346 struct call_site_parameter
*parameter
;
13347 struct attribute
*loc
, *origin
;
13349 if (child_die
->tag
!= DW_TAG_call_site_parameter
13350 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13352 /* Already printed the complaint above. */
13356 gdb_assert (call_site
->parameter_count
< nparams
);
13357 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13359 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13360 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13361 register is contained in DW_AT_call_value. */
13363 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13364 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13365 if (origin
== NULL
)
13367 /* This was a pre-DWARF-5 GNU extension alias
13368 for DW_AT_call_parameter. */
13369 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13371 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13373 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13375 sect_offset sect_off
= origin
->get_ref_die_offset ();
13376 if (!cu
->header
.offset_in_cu_p (sect_off
))
13378 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13379 binding can be done only inside one CU. Such referenced DIE
13380 therefore cannot be even moved to DW_TAG_partial_unit. */
13381 complaint (_("DW_AT_call_parameter offset is not in CU for "
13382 "DW_TAG_call_site child DIE %s [in module %s]"),
13383 sect_offset_str (child_die
->sect_off
),
13384 objfile_name (objfile
));
13387 parameter
->u
.param_cu_off
13388 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13390 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13392 complaint (_("No DW_FORM_block* DW_AT_location for "
13393 "DW_TAG_call_site child DIE %s [in module %s]"),
13394 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13399 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13400 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13401 if (parameter
->u
.dwarf_reg
!= -1)
13402 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13403 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13404 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13405 ¶meter
->u
.fb_offset
))
13406 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13409 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13410 "for DW_FORM_block* DW_AT_location is supported for "
13411 "DW_TAG_call_site child DIE %s "
13413 sect_offset_str (child_die
->sect_off
),
13414 objfile_name (objfile
));
13419 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13421 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13422 if (attr
== NULL
|| !attr
->form_is_block ())
13424 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13425 "DW_TAG_call_site child DIE %s [in module %s]"),
13426 sect_offset_str (child_die
->sect_off
),
13427 objfile_name (objfile
));
13430 parameter
->value
= DW_BLOCK (attr
)->data
;
13431 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13433 /* Parameters are not pre-cleared by memset above. */
13434 parameter
->data_value
= NULL
;
13435 parameter
->data_value_size
= 0;
13436 call_site
->parameter_count
++;
13438 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13440 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13441 if (attr
!= nullptr)
13443 if (!attr
->form_is_block ())
13444 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13445 "DW_TAG_call_site child DIE %s [in module %s]"),
13446 sect_offset_str (child_die
->sect_off
),
13447 objfile_name (objfile
));
13450 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13451 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13457 /* Helper function for read_variable. If DIE represents a virtual
13458 table, then return the type of the concrete object that is
13459 associated with the virtual table. Otherwise, return NULL. */
13461 static struct type
*
13462 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13464 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13468 /* Find the type DIE. */
13469 struct die_info
*type_die
= NULL
;
13470 struct dwarf2_cu
*type_cu
= cu
;
13472 if (attr
->form_is_ref ())
13473 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13474 if (type_die
== NULL
)
13477 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13479 return die_containing_type (type_die
, type_cu
);
13482 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13485 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13487 struct rust_vtable_symbol
*storage
= NULL
;
13489 if (cu
->language
== language_rust
)
13491 struct type
*containing_type
= rust_containing_type (die
, cu
);
13493 if (containing_type
!= NULL
)
13495 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13497 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13498 initialize_objfile_symbol (storage
);
13499 storage
->concrete_type
= containing_type
;
13500 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13504 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13505 struct attribute
*abstract_origin
13506 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13507 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13508 if (res
== NULL
&& loc
&& abstract_origin
)
13510 /* We have a variable without a name, but with a location and an abstract
13511 origin. This may be a concrete instance of an abstract variable
13512 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13514 struct dwarf2_cu
*origin_cu
= cu
;
13515 struct die_info
*origin_die
13516 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13517 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13518 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13522 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13523 reading .debug_rnglists.
13524 Callback's type should be:
13525 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13526 Return true if the attributes are present and valid, otherwise,
13529 template <typename Callback
>
13531 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13532 Callback
&&callback
)
13534 struct dwarf2_per_objfile
*dwarf2_per_objfile
13535 = cu
->per_cu
->dwarf2_per_objfile
;
13536 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13537 bfd
*obfd
= objfile
->obfd
;
13538 /* Base address selection entry. */
13539 gdb::optional
<CORE_ADDR
> base
;
13540 const gdb_byte
*buffer
;
13541 CORE_ADDR baseaddr
;
13542 bool overflow
= false;
13544 base
= cu
->base_address
;
13546 dwarf2_per_objfile
->rnglists
.read (objfile
);
13547 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13549 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13553 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13555 baseaddr
= objfile
->text_section_offset ();
13559 /* Initialize it due to a false compiler warning. */
13560 CORE_ADDR range_beginning
= 0, range_end
= 0;
13561 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13562 + dwarf2_per_objfile
->rnglists
.size
);
13563 unsigned int bytes_read
;
13565 if (buffer
== buf_end
)
13570 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13573 case DW_RLE_end_of_list
:
13575 case DW_RLE_base_address
:
13576 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13581 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13582 buffer
+= bytes_read
;
13584 case DW_RLE_start_length
:
13585 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13590 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13592 buffer
+= bytes_read
;
13593 range_end
= (range_beginning
13594 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13595 buffer
+= bytes_read
;
13596 if (buffer
> buf_end
)
13602 case DW_RLE_offset_pair
:
13603 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13604 buffer
+= bytes_read
;
13605 if (buffer
> buf_end
)
13610 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13611 buffer
+= bytes_read
;
13612 if (buffer
> buf_end
)
13618 case DW_RLE_start_end
:
13619 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13624 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13626 buffer
+= bytes_read
;
13627 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13628 buffer
+= bytes_read
;
13631 complaint (_("Invalid .debug_rnglists data (no base address)"));
13634 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13636 if (rlet
== DW_RLE_base_address
)
13639 if (!base
.has_value ())
13641 /* We have no valid base address for the ranges
13643 complaint (_("Invalid .debug_rnglists data (no base address)"));
13647 if (range_beginning
> range_end
)
13649 /* Inverted range entries are invalid. */
13650 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13654 /* Empty range entries have no effect. */
13655 if (range_beginning
== range_end
)
13658 range_beginning
+= *base
;
13659 range_end
+= *base
;
13661 /* A not-uncommon case of bad debug info.
13662 Don't pollute the addrmap with bad data. */
13663 if (range_beginning
+ baseaddr
== 0
13664 && !dwarf2_per_objfile
->has_section_at_zero
)
13666 complaint (_(".debug_rnglists entry has start address of zero"
13667 " [in module %s]"), objfile_name (objfile
));
13671 callback (range_beginning
, range_end
);
13676 complaint (_("Offset %d is not terminated "
13677 "for DW_AT_ranges attribute"),
13685 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13686 Callback's type should be:
13687 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13688 Return 1 if the attributes are present and valid, otherwise, return 0. */
13690 template <typename Callback
>
13692 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13693 Callback
&&callback
)
13695 struct dwarf2_per_objfile
*dwarf2_per_objfile
13696 = cu
->per_cu
->dwarf2_per_objfile
;
13697 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13698 struct comp_unit_head
*cu_header
= &cu
->header
;
13699 bfd
*obfd
= objfile
->obfd
;
13700 unsigned int addr_size
= cu_header
->addr_size
;
13701 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13702 /* Base address selection entry. */
13703 gdb::optional
<CORE_ADDR
> base
;
13704 unsigned int dummy
;
13705 const gdb_byte
*buffer
;
13706 CORE_ADDR baseaddr
;
13708 if (cu_header
->version
>= 5)
13709 return dwarf2_rnglists_process (offset
, cu
, callback
);
13711 base
= cu
->base_address
;
13713 dwarf2_per_objfile
->ranges
.read (objfile
);
13714 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13716 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13720 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13722 baseaddr
= objfile
->text_section_offset ();
13726 CORE_ADDR range_beginning
, range_end
;
13728 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13729 buffer
+= addr_size
;
13730 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13731 buffer
+= addr_size
;
13732 offset
+= 2 * addr_size
;
13734 /* An end of list marker is a pair of zero addresses. */
13735 if (range_beginning
== 0 && range_end
== 0)
13736 /* Found the end of list entry. */
13739 /* Each base address selection entry is a pair of 2 values.
13740 The first is the largest possible address, the second is
13741 the base address. Check for a base address here. */
13742 if ((range_beginning
& mask
) == mask
)
13744 /* If we found the largest possible address, then we already
13745 have the base address in range_end. */
13750 if (!base
.has_value ())
13752 /* We have no valid base address for the ranges
13754 complaint (_("Invalid .debug_ranges data (no base address)"));
13758 if (range_beginning
> range_end
)
13760 /* Inverted range entries are invalid. */
13761 complaint (_("Invalid .debug_ranges data (inverted range)"));
13765 /* Empty range entries have no effect. */
13766 if (range_beginning
== range_end
)
13769 range_beginning
+= *base
;
13770 range_end
+= *base
;
13772 /* A not-uncommon case of bad debug info.
13773 Don't pollute the addrmap with bad data. */
13774 if (range_beginning
+ baseaddr
== 0
13775 && !dwarf2_per_objfile
->has_section_at_zero
)
13777 complaint (_(".debug_ranges entry has start address of zero"
13778 " [in module %s]"), objfile_name (objfile
));
13782 callback (range_beginning
, range_end
);
13788 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13789 Return 1 if the attributes are present and valid, otherwise, return 0.
13790 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13793 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13794 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13795 dwarf2_psymtab
*ranges_pst
)
13797 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13798 struct gdbarch
*gdbarch
= objfile
->arch ();
13799 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13802 CORE_ADDR high
= 0;
13805 retval
= dwarf2_ranges_process (offset
, cu
,
13806 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13808 if (ranges_pst
!= NULL
)
13813 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13814 range_beginning
+ baseaddr
)
13816 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13817 range_end
+ baseaddr
)
13819 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13820 lowpc
, highpc
- 1, ranges_pst
);
13823 /* FIXME: This is recording everything as a low-high
13824 segment of consecutive addresses. We should have a
13825 data structure for discontiguous block ranges
13829 low
= range_beginning
;
13835 if (range_beginning
< low
)
13836 low
= range_beginning
;
13837 if (range_end
> high
)
13845 /* If the first entry is an end-of-list marker, the range
13846 describes an empty scope, i.e. no instructions. */
13852 *high_return
= high
;
13856 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13857 definition for the return value. *LOWPC and *HIGHPC are set iff
13858 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13860 static enum pc_bounds_kind
13861 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13862 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13863 dwarf2_psymtab
*pst
)
13865 struct dwarf2_per_objfile
*dwarf2_per_objfile
13866 = cu
->per_cu
->dwarf2_per_objfile
;
13867 struct attribute
*attr
;
13868 struct attribute
*attr_high
;
13870 CORE_ADDR high
= 0;
13871 enum pc_bounds_kind ret
;
13873 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13876 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13877 if (attr
!= nullptr)
13879 low
= attr
->value_as_address ();
13880 high
= attr_high
->value_as_address ();
13881 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13885 /* Found high w/o low attribute. */
13886 return PC_BOUNDS_INVALID
;
13888 /* Found consecutive range of addresses. */
13889 ret
= PC_BOUNDS_HIGH_LOW
;
13893 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13896 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13897 We take advantage of the fact that DW_AT_ranges does not appear
13898 in DW_TAG_compile_unit of DWO files. */
13899 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13900 unsigned int ranges_offset
= (DW_UNSND (attr
)
13901 + (need_ranges_base
13905 /* Value of the DW_AT_ranges attribute is the offset in the
13906 .debug_ranges section. */
13907 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13908 return PC_BOUNDS_INVALID
;
13909 /* Found discontinuous range of addresses. */
13910 ret
= PC_BOUNDS_RANGES
;
13913 return PC_BOUNDS_NOT_PRESENT
;
13916 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13918 return PC_BOUNDS_INVALID
;
13920 /* When using the GNU linker, .gnu.linkonce. sections are used to
13921 eliminate duplicate copies of functions and vtables and such.
13922 The linker will arbitrarily choose one and discard the others.
13923 The AT_*_pc values for such functions refer to local labels in
13924 these sections. If the section from that file was discarded, the
13925 labels are not in the output, so the relocs get a value of 0.
13926 If this is a discarded function, mark the pc bounds as invalid,
13927 so that GDB will ignore it. */
13928 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13929 return PC_BOUNDS_INVALID
;
13937 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13938 its low and high PC addresses. Do nothing if these addresses could not
13939 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13940 and HIGHPC to the high address if greater than HIGHPC. */
13943 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13944 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13945 struct dwarf2_cu
*cu
)
13947 CORE_ADDR low
, high
;
13948 struct die_info
*child
= die
->child
;
13950 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13952 *lowpc
= std::min (*lowpc
, low
);
13953 *highpc
= std::max (*highpc
, high
);
13956 /* If the language does not allow nested subprograms (either inside
13957 subprograms or lexical blocks), we're done. */
13958 if (cu
->language
!= language_ada
)
13961 /* Check all the children of the given DIE. If it contains nested
13962 subprograms, then check their pc bounds. Likewise, we need to
13963 check lexical blocks as well, as they may also contain subprogram
13965 while (child
&& child
->tag
)
13967 if (child
->tag
== DW_TAG_subprogram
13968 || child
->tag
== DW_TAG_lexical_block
)
13969 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13970 child
= child
->sibling
;
13974 /* Get the low and high pc's represented by the scope DIE, and store
13975 them in *LOWPC and *HIGHPC. If the correct values can't be
13976 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13979 get_scope_pc_bounds (struct die_info
*die
,
13980 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13981 struct dwarf2_cu
*cu
)
13983 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13984 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13985 CORE_ADDR current_low
, current_high
;
13987 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13988 >= PC_BOUNDS_RANGES
)
13990 best_low
= current_low
;
13991 best_high
= current_high
;
13995 struct die_info
*child
= die
->child
;
13997 while (child
&& child
->tag
)
13999 switch (child
->tag
) {
14000 case DW_TAG_subprogram
:
14001 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14003 case DW_TAG_namespace
:
14004 case DW_TAG_module
:
14005 /* FIXME: carlton/2004-01-16: Should we do this for
14006 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14007 that current GCC's always emit the DIEs corresponding
14008 to definitions of methods of classes as children of a
14009 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14010 the DIEs giving the declarations, which could be
14011 anywhere). But I don't see any reason why the
14012 standards says that they have to be there. */
14013 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14015 if (current_low
!= ((CORE_ADDR
) -1))
14017 best_low
= std::min (best_low
, current_low
);
14018 best_high
= std::max (best_high
, current_high
);
14026 child
= child
->sibling
;
14031 *highpc
= best_high
;
14034 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14038 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14039 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14041 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14042 struct gdbarch
*gdbarch
= objfile
->arch ();
14043 struct attribute
*attr
;
14044 struct attribute
*attr_high
;
14046 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14049 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14050 if (attr
!= nullptr)
14052 CORE_ADDR low
= attr
->value_as_address ();
14053 CORE_ADDR high
= attr_high
->value_as_address ();
14055 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14058 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14059 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14060 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14064 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14065 if (attr
!= nullptr)
14067 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14068 We take advantage of the fact that DW_AT_ranges does not appear
14069 in DW_TAG_compile_unit of DWO files. */
14070 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14072 /* The value of the DW_AT_ranges attribute is the offset of the
14073 address range list in the .debug_ranges section. */
14074 unsigned long offset
= (DW_UNSND (attr
)
14075 + (need_ranges_base
? cu
->ranges_base
: 0));
14077 std::vector
<blockrange
> blockvec
;
14078 dwarf2_ranges_process (offset
, cu
,
14079 [&] (CORE_ADDR start
, CORE_ADDR end
)
14083 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14084 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14085 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14086 blockvec
.emplace_back (start
, end
);
14089 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14093 /* Check whether the producer field indicates either of GCC < 4.6, or the
14094 Intel C/C++ compiler, and cache the result in CU. */
14097 check_producer (struct dwarf2_cu
*cu
)
14101 if (cu
->producer
== NULL
)
14103 /* For unknown compilers expect their behavior is DWARF version
14106 GCC started to support .debug_types sections by -gdwarf-4 since
14107 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14108 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14109 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14110 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14112 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14114 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14115 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14117 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14119 cu
->producer_is_icc
= true;
14120 cu
->producer_is_icc_lt_14
= major
< 14;
14122 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14123 cu
->producer_is_codewarrior
= true;
14126 /* For other non-GCC compilers, expect their behavior is DWARF version
14130 cu
->checked_producer
= true;
14133 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14134 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14135 during 4.6.0 experimental. */
14138 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14140 if (!cu
->checked_producer
)
14141 check_producer (cu
);
14143 return cu
->producer_is_gxx_lt_4_6
;
14147 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14148 with incorrect is_stmt attributes. */
14151 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14153 if (!cu
->checked_producer
)
14154 check_producer (cu
);
14156 return cu
->producer_is_codewarrior
;
14159 /* Return the default accessibility type if it is not overridden by
14160 DW_AT_accessibility. */
14162 static enum dwarf_access_attribute
14163 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14165 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14167 /* The default DWARF 2 accessibility for members is public, the default
14168 accessibility for inheritance is private. */
14170 if (die
->tag
!= DW_TAG_inheritance
)
14171 return DW_ACCESS_public
;
14173 return DW_ACCESS_private
;
14177 /* DWARF 3+ defines the default accessibility a different way. The same
14178 rules apply now for DW_TAG_inheritance as for the members and it only
14179 depends on the container kind. */
14181 if (die
->parent
->tag
== DW_TAG_class_type
)
14182 return DW_ACCESS_private
;
14184 return DW_ACCESS_public
;
14188 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14189 offset. If the attribute was not found return 0, otherwise return
14190 1. If it was found but could not properly be handled, set *OFFSET
14194 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14197 struct attribute
*attr
;
14199 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14204 /* Note that we do not check for a section offset first here.
14205 This is because DW_AT_data_member_location is new in DWARF 4,
14206 so if we see it, we can assume that a constant form is really
14207 a constant and not a section offset. */
14208 if (attr
->form_is_constant ())
14209 *offset
= attr
->constant_value (0);
14210 else if (attr
->form_is_section_offset ())
14211 dwarf2_complex_location_expr_complaint ();
14212 else if (attr
->form_is_block ())
14213 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14215 dwarf2_complex_location_expr_complaint ();
14223 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14226 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14227 struct field
*field
)
14229 struct attribute
*attr
;
14231 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14234 if (attr
->form_is_constant ())
14236 LONGEST offset
= attr
->constant_value (0);
14237 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14239 else if (attr
->form_is_section_offset ())
14240 dwarf2_complex_location_expr_complaint ();
14241 else if (attr
->form_is_block ())
14244 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14246 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14249 struct objfile
*objfile
14250 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14251 struct dwarf2_locexpr_baton
*dlbaton
14252 = XOBNEW (&objfile
->objfile_obstack
,
14253 struct dwarf2_locexpr_baton
);
14254 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14255 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14256 /* When using this baton, we want to compute the address
14257 of the field, not the value. This is why
14258 is_reference is set to false here. */
14259 dlbaton
->is_reference
= false;
14260 dlbaton
->per_cu
= cu
->per_cu
;
14262 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14266 dwarf2_complex_location_expr_complaint ();
14270 /* Add an aggregate field to the field list. */
14273 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14274 struct dwarf2_cu
*cu
)
14276 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14277 struct gdbarch
*gdbarch
= objfile
->arch ();
14278 struct nextfield
*new_field
;
14279 struct attribute
*attr
;
14281 const char *fieldname
= "";
14283 if (die
->tag
== DW_TAG_inheritance
)
14285 fip
->baseclasses
.emplace_back ();
14286 new_field
= &fip
->baseclasses
.back ();
14290 fip
->fields
.emplace_back ();
14291 new_field
= &fip
->fields
.back ();
14294 new_field
->offset
= die
->sect_off
;
14296 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14297 if (attr
!= nullptr)
14298 new_field
->accessibility
= DW_UNSND (attr
);
14300 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14301 if (new_field
->accessibility
!= DW_ACCESS_public
)
14302 fip
->non_public_fields
= 1;
14304 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14305 if (attr
!= nullptr)
14306 new_field
->virtuality
= DW_UNSND (attr
);
14308 new_field
->virtuality
= DW_VIRTUALITY_none
;
14310 fp
= &new_field
->field
;
14312 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14314 /* Data member other than a C++ static data member. */
14316 /* Get type of field. */
14317 fp
->type
= die_type (die
, cu
);
14319 SET_FIELD_BITPOS (*fp
, 0);
14321 /* Get bit size of field (zero if none). */
14322 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14323 if (attr
!= nullptr)
14325 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14329 FIELD_BITSIZE (*fp
) = 0;
14332 /* Get bit offset of field. */
14333 handle_data_member_location (die
, cu
, fp
);
14334 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14335 if (attr
!= nullptr)
14337 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14339 /* For big endian bits, the DW_AT_bit_offset gives the
14340 additional bit offset from the MSB of the containing
14341 anonymous object to the MSB of the field. We don't
14342 have to do anything special since we don't need to
14343 know the size of the anonymous object. */
14344 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14348 /* For little endian bits, compute the bit offset to the
14349 MSB of the anonymous object, subtract off the number of
14350 bits from the MSB of the field to the MSB of the
14351 object, and then subtract off the number of bits of
14352 the field itself. The result is the bit offset of
14353 the LSB of the field. */
14354 int anonymous_size
;
14355 int bit_offset
= DW_UNSND (attr
);
14357 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14358 if (attr
!= nullptr)
14360 /* The size of the anonymous object containing
14361 the bit field is explicit, so use the
14362 indicated size (in bytes). */
14363 anonymous_size
= DW_UNSND (attr
);
14367 /* The size of the anonymous object containing
14368 the bit field must be inferred from the type
14369 attribute of the data member containing the
14371 anonymous_size
= TYPE_LENGTH (fp
->type
);
14373 SET_FIELD_BITPOS (*fp
,
14374 (FIELD_BITPOS (*fp
)
14375 + anonymous_size
* bits_per_byte
14376 - bit_offset
- FIELD_BITSIZE (*fp
)));
14379 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14381 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14382 + attr
->constant_value (0)));
14384 /* Get name of field. */
14385 fieldname
= dwarf2_name (die
, cu
);
14386 if (fieldname
== NULL
)
14389 /* The name is already allocated along with this objfile, so we don't
14390 need to duplicate it for the type. */
14391 fp
->name
= fieldname
;
14393 /* Change accessibility for artificial fields (e.g. virtual table
14394 pointer or virtual base class pointer) to private. */
14395 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14397 FIELD_ARTIFICIAL (*fp
) = 1;
14398 new_field
->accessibility
= DW_ACCESS_private
;
14399 fip
->non_public_fields
= 1;
14402 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14404 /* C++ static member. */
14406 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14407 is a declaration, but all versions of G++ as of this writing
14408 (so through at least 3.2.1) incorrectly generate
14409 DW_TAG_variable tags. */
14411 const char *physname
;
14413 /* Get name of field. */
14414 fieldname
= dwarf2_name (die
, cu
);
14415 if (fieldname
== NULL
)
14418 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14420 /* Only create a symbol if this is an external value.
14421 new_symbol checks this and puts the value in the global symbol
14422 table, which we want. If it is not external, new_symbol
14423 will try to put the value in cu->list_in_scope which is wrong. */
14424 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14426 /* A static const member, not much different than an enum as far as
14427 we're concerned, except that we can support more types. */
14428 new_symbol (die
, NULL
, cu
);
14431 /* Get physical name. */
14432 physname
= dwarf2_physname (fieldname
, die
, cu
);
14434 /* The name is already allocated along with this objfile, so we don't
14435 need to duplicate it for the type. */
14436 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14437 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14438 FIELD_NAME (*fp
) = fieldname
;
14440 else if (die
->tag
== DW_TAG_inheritance
)
14442 /* C++ base class field. */
14443 handle_data_member_location (die
, cu
, fp
);
14444 FIELD_BITSIZE (*fp
) = 0;
14445 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14446 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14449 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14452 /* Can the type given by DIE define another type? */
14455 type_can_define_types (const struct die_info
*die
)
14459 case DW_TAG_typedef
:
14460 case DW_TAG_class_type
:
14461 case DW_TAG_structure_type
:
14462 case DW_TAG_union_type
:
14463 case DW_TAG_enumeration_type
:
14471 /* Add a type definition defined in the scope of the FIP's class. */
14474 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14475 struct dwarf2_cu
*cu
)
14477 struct decl_field fp
;
14478 memset (&fp
, 0, sizeof (fp
));
14480 gdb_assert (type_can_define_types (die
));
14482 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14483 fp
.name
= dwarf2_name (die
, cu
);
14484 fp
.type
= read_type_die (die
, cu
);
14486 /* Save accessibility. */
14487 enum dwarf_access_attribute accessibility
;
14488 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14490 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14492 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14493 switch (accessibility
)
14495 case DW_ACCESS_public
:
14496 /* The assumed value if neither private nor protected. */
14498 case DW_ACCESS_private
:
14501 case DW_ACCESS_protected
:
14502 fp
.is_protected
= 1;
14505 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14508 if (die
->tag
== DW_TAG_typedef
)
14509 fip
->typedef_field_list
.push_back (fp
);
14511 fip
->nested_types_list
.push_back (fp
);
14514 /* A convenience typedef that's used when finding the discriminant
14515 field for a variant part. */
14516 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14519 /* Compute the discriminant range for a given variant. OBSTACK is
14520 where the results will be stored. VARIANT is the variant to
14521 process. IS_UNSIGNED indicates whether the discriminant is signed
14524 static const gdb::array_view
<discriminant_range
>
14525 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14528 std::vector
<discriminant_range
> ranges
;
14530 if (variant
.default_branch
)
14533 if (variant
.discr_list_data
== nullptr)
14535 discriminant_range r
14536 = {variant
.discriminant_value
, variant
.discriminant_value
};
14537 ranges
.push_back (r
);
14541 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14542 variant
.discr_list_data
->size
);
14543 while (!data
.empty ())
14545 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14547 complaint (_("invalid discriminant marker: %d"), data
[0]);
14550 bool is_range
= data
[0] == DW_DSC_range
;
14551 data
= data
.slice (1);
14553 ULONGEST low
, high
;
14554 unsigned int bytes_read
;
14558 complaint (_("DW_AT_discr_list missing low value"));
14562 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14564 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14566 data
= data
.slice (bytes_read
);
14572 complaint (_("DW_AT_discr_list missing high value"));
14576 high
= read_unsigned_leb128 (nullptr, data
.data (),
14579 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14581 data
= data
.slice (bytes_read
);
14586 ranges
.push_back ({ low
, high
});
14590 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14592 std::copy (ranges
.begin (), ranges
.end (), result
);
14593 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14596 static const gdb::array_view
<variant_part
> create_variant_parts
14597 (struct obstack
*obstack
,
14598 const offset_map_type
&offset_map
,
14599 struct field_info
*fi
,
14600 const std::vector
<variant_part_builder
> &variant_parts
);
14602 /* Fill in a "struct variant" for a given variant field. RESULT is
14603 the variant to fill in. OBSTACK is where any needed allocations
14604 will be done. OFFSET_MAP holds the mapping from section offsets to
14605 fields for the type. FI describes the fields of the type we're
14606 processing. FIELD is the variant field we're converting. */
14609 create_one_variant (variant
&result
, struct obstack
*obstack
,
14610 const offset_map_type
&offset_map
,
14611 struct field_info
*fi
, const variant_field
&field
)
14613 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14614 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14615 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14616 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14617 field
.variant_parts
);
14620 /* Fill in a "struct variant_part" for a given variant part. RESULT
14621 is the variant part to fill in. OBSTACK is where any needed
14622 allocations will be done. OFFSET_MAP holds the mapping from
14623 section offsets to fields for the type. FI describes the fields of
14624 the type we're processing. BUILDER is the variant part to be
14628 create_one_variant_part (variant_part
&result
,
14629 struct obstack
*obstack
,
14630 const offset_map_type
&offset_map
,
14631 struct field_info
*fi
,
14632 const variant_part_builder
&builder
)
14634 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14635 if (iter
== offset_map
.end ())
14637 result
.discriminant_index
= -1;
14638 /* Doesn't matter. */
14639 result
.is_unsigned
= false;
14643 result
.discriminant_index
= iter
->second
;
14645 = TYPE_UNSIGNED (FIELD_TYPE
14646 (fi
->fields
[result
.discriminant_index
].field
));
14649 size_t n
= builder
.variants
.size ();
14650 variant
*output
= new (obstack
) variant
[n
];
14651 for (size_t i
= 0; i
< n
; ++i
)
14652 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14653 builder
.variants
[i
]);
14655 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14658 /* Create a vector of variant parts that can be attached to a type.
14659 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14660 holds the mapping from section offsets to fields for the type. FI
14661 describes the fields of the type we're processing. VARIANT_PARTS
14662 is the vector to convert. */
14664 static const gdb::array_view
<variant_part
>
14665 create_variant_parts (struct obstack
*obstack
,
14666 const offset_map_type
&offset_map
,
14667 struct field_info
*fi
,
14668 const std::vector
<variant_part_builder
> &variant_parts
)
14670 if (variant_parts
.empty ())
14673 size_t n
= variant_parts
.size ();
14674 variant_part
*result
= new (obstack
) variant_part
[n
];
14675 for (size_t i
= 0; i
< n
; ++i
)
14676 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14679 return gdb::array_view
<variant_part
> (result
, n
);
14682 /* Compute the variant part vector for FIP, attaching it to TYPE when
14686 add_variant_property (struct field_info
*fip
, struct type
*type
,
14687 struct dwarf2_cu
*cu
)
14689 /* Map section offsets of fields to their field index. Note the
14690 field index here does not take the number of baseclasses into
14692 offset_map_type offset_map
;
14693 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14694 offset_map
[fip
->fields
[i
].offset
] = i
;
14696 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14697 gdb::array_view
<variant_part
> parts
14698 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14699 fip
->variant_parts
);
14701 struct dynamic_prop prop
;
14702 prop
.kind
= PROP_VARIANT_PARTS
;
14703 prop
.data
.variant_parts
14704 = ((gdb::array_view
<variant_part
> *)
14705 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14707 add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
, type
);
14710 /* Create the vector of fields, and attach it to the type. */
14713 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14714 struct dwarf2_cu
*cu
)
14716 int nfields
= fip
->nfields ();
14718 /* Record the field count, allocate space for the array of fields,
14719 and create blank accessibility bitfields if necessary. */
14720 TYPE_NFIELDS (type
) = nfields
;
14721 TYPE_FIELDS (type
) = (struct field
*)
14722 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14724 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14726 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14728 TYPE_FIELD_PRIVATE_BITS (type
) =
14729 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14730 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14732 TYPE_FIELD_PROTECTED_BITS (type
) =
14733 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14734 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14736 TYPE_FIELD_IGNORE_BITS (type
) =
14737 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14738 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14741 /* If the type has baseclasses, allocate and clear a bit vector for
14742 TYPE_FIELD_VIRTUAL_BITS. */
14743 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14745 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14746 unsigned char *pointer
;
14748 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14749 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14750 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14751 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14752 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14755 if (!fip
->variant_parts
.empty ())
14756 add_variant_property (fip
, type
, cu
);
14758 /* Copy the saved-up fields into the field vector. */
14759 for (int i
= 0; i
< nfields
; ++i
)
14761 struct nextfield
&field
14762 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14763 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14765 TYPE_FIELD (type
, i
) = field
.field
;
14766 switch (field
.accessibility
)
14768 case DW_ACCESS_private
:
14769 if (cu
->language
!= language_ada
)
14770 SET_TYPE_FIELD_PRIVATE (type
, i
);
14773 case DW_ACCESS_protected
:
14774 if (cu
->language
!= language_ada
)
14775 SET_TYPE_FIELD_PROTECTED (type
, i
);
14778 case DW_ACCESS_public
:
14782 /* Unknown accessibility. Complain and treat it as public. */
14784 complaint (_("unsupported accessibility %d"),
14785 field
.accessibility
);
14789 if (i
< fip
->baseclasses
.size ())
14791 switch (field
.virtuality
)
14793 case DW_VIRTUALITY_virtual
:
14794 case DW_VIRTUALITY_pure_virtual
:
14795 if (cu
->language
== language_ada
)
14796 error (_("unexpected virtuality in component of Ada type"));
14797 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14804 /* Return true if this member function is a constructor, false
14808 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14810 const char *fieldname
;
14811 const char *type_name
;
14814 if (die
->parent
== NULL
)
14817 if (die
->parent
->tag
!= DW_TAG_structure_type
14818 && die
->parent
->tag
!= DW_TAG_union_type
14819 && die
->parent
->tag
!= DW_TAG_class_type
)
14822 fieldname
= dwarf2_name (die
, cu
);
14823 type_name
= dwarf2_name (die
->parent
, cu
);
14824 if (fieldname
== NULL
|| type_name
== NULL
)
14827 len
= strlen (fieldname
);
14828 return (strncmp (fieldname
, type_name
, len
) == 0
14829 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14832 /* Check if the given VALUE is a recognized enum
14833 dwarf_defaulted_attribute constant according to DWARF5 spec,
14837 is_valid_DW_AT_defaulted (ULONGEST value
)
14841 case DW_DEFAULTED_no
:
14842 case DW_DEFAULTED_in_class
:
14843 case DW_DEFAULTED_out_of_class
:
14847 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14851 /* Add a member function to the proper fieldlist. */
14854 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14855 struct type
*type
, struct dwarf2_cu
*cu
)
14857 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14858 struct attribute
*attr
;
14860 struct fnfieldlist
*flp
= nullptr;
14861 struct fn_field
*fnp
;
14862 const char *fieldname
;
14863 struct type
*this_type
;
14864 enum dwarf_access_attribute accessibility
;
14866 if (cu
->language
== language_ada
)
14867 error (_("unexpected member function in Ada type"));
14869 /* Get name of member function. */
14870 fieldname
= dwarf2_name (die
, cu
);
14871 if (fieldname
== NULL
)
14874 /* Look up member function name in fieldlist. */
14875 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14877 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14879 flp
= &fip
->fnfieldlists
[i
];
14884 /* Create a new fnfieldlist if necessary. */
14885 if (flp
== nullptr)
14887 fip
->fnfieldlists
.emplace_back ();
14888 flp
= &fip
->fnfieldlists
.back ();
14889 flp
->name
= fieldname
;
14890 i
= fip
->fnfieldlists
.size () - 1;
14893 /* Create a new member function field and add it to the vector of
14895 flp
->fnfields
.emplace_back ();
14896 fnp
= &flp
->fnfields
.back ();
14898 /* Delay processing of the physname until later. */
14899 if (cu
->language
== language_cplus
)
14900 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14904 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14905 fnp
->physname
= physname
? physname
: "";
14908 fnp
->type
= alloc_type (objfile
);
14909 this_type
= read_type_die (die
, cu
);
14910 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14912 int nparams
= TYPE_NFIELDS (this_type
);
14914 /* TYPE is the domain of this method, and THIS_TYPE is the type
14915 of the method itself (TYPE_CODE_METHOD). */
14916 smash_to_method_type (fnp
->type
, type
,
14917 TYPE_TARGET_TYPE (this_type
),
14918 TYPE_FIELDS (this_type
),
14919 TYPE_NFIELDS (this_type
),
14920 TYPE_VARARGS (this_type
));
14922 /* Handle static member functions.
14923 Dwarf2 has no clean way to discern C++ static and non-static
14924 member functions. G++ helps GDB by marking the first
14925 parameter for non-static member functions (which is the this
14926 pointer) as artificial. We obtain this information from
14927 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14928 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14929 fnp
->voffset
= VOFFSET_STATIC
;
14932 complaint (_("member function type missing for '%s'"),
14933 dwarf2_full_name (fieldname
, die
, cu
));
14935 /* Get fcontext from DW_AT_containing_type if present. */
14936 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14937 fnp
->fcontext
= die_containing_type (die
, cu
);
14939 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14940 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14942 /* Get accessibility. */
14943 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14944 if (attr
!= nullptr)
14945 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14947 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14948 switch (accessibility
)
14950 case DW_ACCESS_private
:
14951 fnp
->is_private
= 1;
14953 case DW_ACCESS_protected
:
14954 fnp
->is_protected
= 1;
14958 /* Check for artificial methods. */
14959 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14960 if (attr
&& DW_UNSND (attr
) != 0)
14961 fnp
->is_artificial
= 1;
14963 /* Check for defaulted methods. */
14964 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14965 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14966 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14968 /* Check for deleted methods. */
14969 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14970 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14971 fnp
->is_deleted
= 1;
14973 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14975 /* Get index in virtual function table if it is a virtual member
14976 function. For older versions of GCC, this is an offset in the
14977 appropriate virtual table, as specified by DW_AT_containing_type.
14978 For everyone else, it is an expression to be evaluated relative
14979 to the object address. */
14981 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14982 if (attr
!= nullptr)
14984 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14986 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14988 /* Old-style GCC. */
14989 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14991 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14992 || (DW_BLOCK (attr
)->size
> 1
14993 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14994 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14996 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14997 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14998 dwarf2_complex_location_expr_complaint ();
15000 fnp
->voffset
/= cu
->header
.addr_size
;
15004 dwarf2_complex_location_expr_complaint ();
15006 if (!fnp
->fcontext
)
15008 /* If there is no `this' field and no DW_AT_containing_type,
15009 we cannot actually find a base class context for the
15011 if (TYPE_NFIELDS (this_type
) == 0
15012 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15014 complaint (_("cannot determine context for virtual member "
15015 "function \"%s\" (offset %s)"),
15016 fieldname
, sect_offset_str (die
->sect_off
));
15021 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15025 else if (attr
->form_is_section_offset ())
15027 dwarf2_complex_location_expr_complaint ();
15031 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15037 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15038 if (attr
&& DW_UNSND (attr
))
15040 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15041 complaint (_("Member function \"%s\" (offset %s) is virtual "
15042 "but the vtable offset is not specified"),
15043 fieldname
, sect_offset_str (die
->sect_off
));
15044 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15045 TYPE_CPLUS_DYNAMIC (type
) = 1;
15050 /* Create the vector of member function fields, and attach it to the type. */
15053 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15054 struct dwarf2_cu
*cu
)
15056 if (cu
->language
== language_ada
)
15057 error (_("unexpected member functions in Ada type"));
15059 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15060 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15062 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15064 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15066 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15067 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15069 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15070 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15071 fn_flp
->fn_fields
= (struct fn_field
*)
15072 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15074 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15075 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15078 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15081 /* Returns non-zero if NAME is the name of a vtable member in CU's
15082 language, zero otherwise. */
15084 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15086 static const char vptr
[] = "_vptr";
15088 /* Look for the C++ form of the vtable. */
15089 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15095 /* GCC outputs unnamed structures that are really pointers to member
15096 functions, with the ABI-specified layout. If TYPE describes
15097 such a structure, smash it into a member function type.
15099 GCC shouldn't do this; it should just output pointer to member DIEs.
15100 This is GCC PR debug/28767. */
15103 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15105 struct type
*pfn_type
, *self_type
, *new_type
;
15107 /* Check for a structure with no name and two children. */
15108 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15111 /* Check for __pfn and __delta members. */
15112 if (TYPE_FIELD_NAME (type
, 0) == NULL
15113 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15114 || TYPE_FIELD_NAME (type
, 1) == NULL
15115 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15118 /* Find the type of the method. */
15119 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15120 if (pfn_type
== NULL
15121 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15122 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15125 /* Look for the "this" argument. */
15126 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15127 if (TYPE_NFIELDS (pfn_type
) == 0
15128 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15129 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15132 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15133 new_type
= alloc_type (objfile
);
15134 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15135 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15136 TYPE_VARARGS (pfn_type
));
15137 smash_to_methodptr_type (type
, new_type
);
15140 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15141 appropriate error checking and issuing complaints if there is a
15145 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15147 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15149 if (attr
== nullptr)
15152 if (!attr
->form_is_constant ())
15154 complaint (_("DW_AT_alignment must have constant form"
15155 " - DIE at %s [in module %s]"),
15156 sect_offset_str (die
->sect_off
),
15157 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15162 if (attr
->form
== DW_FORM_sdata
)
15164 LONGEST val
= DW_SND (attr
);
15167 complaint (_("DW_AT_alignment value must not be negative"
15168 " - DIE at %s [in module %s]"),
15169 sect_offset_str (die
->sect_off
),
15170 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15176 align
= DW_UNSND (attr
);
15180 complaint (_("DW_AT_alignment value must not be zero"
15181 " - DIE at %s [in module %s]"),
15182 sect_offset_str (die
->sect_off
),
15183 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15186 if ((align
& (align
- 1)) != 0)
15188 complaint (_("DW_AT_alignment value must be a power of 2"
15189 " - DIE at %s [in module %s]"),
15190 sect_offset_str (die
->sect_off
),
15191 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15198 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15199 the alignment for TYPE. */
15202 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15205 if (!set_type_align (type
, get_alignment (cu
, die
)))
15206 complaint (_("DW_AT_alignment value too large"
15207 " - DIE at %s [in module %s]"),
15208 sect_offset_str (die
->sect_off
),
15209 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15212 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15213 constant for a type, according to DWARF5 spec, Table 5.5. */
15216 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15221 case DW_CC_pass_by_reference
:
15222 case DW_CC_pass_by_value
:
15226 complaint (_("unrecognized DW_AT_calling_convention value "
15227 "(%s) for a type"), pulongest (value
));
15232 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15233 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15234 also according to GNU-specific values (see include/dwarf2.h). */
15237 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15242 case DW_CC_program
:
15246 case DW_CC_GNU_renesas_sh
:
15247 case DW_CC_GNU_borland_fastcall_i386
:
15248 case DW_CC_GDB_IBM_OpenCL
:
15252 complaint (_("unrecognized DW_AT_calling_convention value "
15253 "(%s) for a subroutine"), pulongest (value
));
15258 /* Called when we find the DIE that starts a structure or union scope
15259 (definition) to create a type for the structure or union. Fill in
15260 the type's name and general properties; the members will not be
15261 processed until process_structure_scope. A symbol table entry for
15262 the type will also not be done until process_structure_scope (assuming
15263 the type has a name).
15265 NOTE: we need to call these functions regardless of whether or not the
15266 DIE has a DW_AT_name attribute, since it might be an anonymous
15267 structure or union. This gets the type entered into our set of
15268 user defined types. */
15270 static struct type
*
15271 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15273 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15275 struct attribute
*attr
;
15278 /* If the definition of this type lives in .debug_types, read that type.
15279 Don't follow DW_AT_specification though, that will take us back up
15280 the chain and we want to go down. */
15281 attr
= die
->attr (DW_AT_signature
);
15282 if (attr
!= nullptr)
15284 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15286 /* The type's CU may not be the same as CU.
15287 Ensure TYPE is recorded with CU in die_type_hash. */
15288 return set_die_type (die
, type
, cu
);
15291 type
= alloc_type (objfile
);
15292 INIT_CPLUS_SPECIFIC (type
);
15294 name
= dwarf2_name (die
, cu
);
15297 if (cu
->language
== language_cplus
15298 || cu
->language
== language_d
15299 || cu
->language
== language_rust
)
15301 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15303 /* dwarf2_full_name might have already finished building the DIE's
15304 type. If so, there is no need to continue. */
15305 if (get_die_type (die
, cu
) != NULL
)
15306 return get_die_type (die
, cu
);
15308 TYPE_NAME (type
) = full_name
;
15312 /* The name is already allocated along with this objfile, so
15313 we don't need to duplicate it for the type. */
15314 TYPE_NAME (type
) = name
;
15318 if (die
->tag
== DW_TAG_structure_type
)
15320 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15322 else if (die
->tag
== DW_TAG_union_type
)
15324 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15328 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15331 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15332 TYPE_DECLARED_CLASS (type
) = 1;
15334 /* Store the calling convention in the type if it's available in
15335 the die. Otherwise the calling convention remains set to
15336 the default value DW_CC_normal. */
15337 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15338 if (attr
!= nullptr
15339 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15341 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15342 TYPE_CPLUS_CALLING_CONVENTION (type
)
15343 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15346 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15347 if (attr
!= nullptr)
15349 if (attr
->form_is_constant ())
15350 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15353 struct dynamic_prop prop
;
15354 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
15355 cu
->per_cu
->addr_type ()))
15356 add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
, type
);
15357 TYPE_LENGTH (type
) = 0;
15362 TYPE_LENGTH (type
) = 0;
15365 maybe_set_alignment (cu
, die
, type
);
15367 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15369 /* ICC<14 does not output the required DW_AT_declaration on
15370 incomplete types, but gives them a size of zero. */
15371 TYPE_STUB (type
) = 1;
15374 TYPE_STUB_SUPPORTED (type
) = 1;
15376 if (die_is_declaration (die
, cu
))
15377 TYPE_STUB (type
) = 1;
15378 else if (attr
== NULL
&& die
->child
== NULL
15379 && producer_is_realview (cu
->producer
))
15380 /* RealView does not output the required DW_AT_declaration
15381 on incomplete types. */
15382 TYPE_STUB (type
) = 1;
15384 /* We need to add the type field to the die immediately so we don't
15385 infinitely recurse when dealing with pointers to the structure
15386 type within the structure itself. */
15387 set_die_type (die
, type
, cu
);
15389 /* set_die_type should be already done. */
15390 set_descriptive_type (type
, die
, cu
);
15395 static void handle_struct_member_die
15396 (struct die_info
*child_die
,
15398 struct field_info
*fi
,
15399 std::vector
<struct symbol
*> *template_args
,
15400 struct dwarf2_cu
*cu
);
15402 /* A helper for handle_struct_member_die that handles
15403 DW_TAG_variant_part. */
15406 handle_variant_part (struct die_info
*die
, struct type
*type
,
15407 struct field_info
*fi
,
15408 std::vector
<struct symbol
*> *template_args
,
15409 struct dwarf2_cu
*cu
)
15411 variant_part_builder
*new_part
;
15412 if (fi
->current_variant_part
== nullptr)
15414 fi
->variant_parts
.emplace_back ();
15415 new_part
= &fi
->variant_parts
.back ();
15417 else if (!fi
->current_variant_part
->processing_variant
)
15419 complaint (_("nested DW_TAG_variant_part seen "
15420 "- DIE at %s [in module %s]"),
15421 sect_offset_str (die
->sect_off
),
15422 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15427 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15428 current
.variant_parts
.emplace_back ();
15429 new_part
= ¤t
.variant_parts
.back ();
15432 /* When we recurse, we want callees to add to this new variant
15434 scoped_restore save_current_variant_part
15435 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15437 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15440 /* It's a univariant form, an extension we support. */
15442 else if (discr
->form_is_ref ())
15444 struct dwarf2_cu
*target_cu
= cu
;
15445 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15447 new_part
->discriminant_offset
= target_die
->sect_off
;
15451 complaint (_("DW_AT_discr does not have DIE reference form"
15452 " - DIE at %s [in module %s]"),
15453 sect_offset_str (die
->sect_off
),
15454 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15457 for (die_info
*child_die
= die
->child
;
15459 child_die
= child_die
->sibling
)
15460 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15463 /* A helper for handle_struct_member_die that handles
15467 handle_variant (struct die_info
*die
, struct type
*type
,
15468 struct field_info
*fi
,
15469 std::vector
<struct symbol
*> *template_args
,
15470 struct dwarf2_cu
*cu
)
15472 if (fi
->current_variant_part
== nullptr)
15474 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15475 "- DIE at %s [in module %s]"),
15476 sect_offset_str (die
->sect_off
),
15477 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15480 if (fi
->current_variant_part
->processing_variant
)
15482 complaint (_("nested DW_TAG_variant seen "
15483 "- DIE at %s [in module %s]"),
15484 sect_offset_str (die
->sect_off
),
15485 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15489 scoped_restore save_processing_variant
15490 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15493 fi
->current_variant_part
->variants
.emplace_back ();
15494 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15495 variant
.first_field
= fi
->fields
.size ();
15497 /* In a variant we want to get the discriminant and also add a
15498 field for our sole member child. */
15499 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15500 if (discr
== nullptr)
15502 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15503 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15504 variant
.default_branch
= true;
15506 variant
.discr_list_data
= DW_BLOCK (discr
);
15509 variant
.discriminant_value
= DW_UNSND (discr
);
15511 for (die_info
*variant_child
= die
->child
;
15512 variant_child
!= NULL
;
15513 variant_child
= variant_child
->sibling
)
15514 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15516 variant
.last_field
= fi
->fields
.size ();
15519 /* A helper for process_structure_scope that handles a single member
15523 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15524 struct field_info
*fi
,
15525 std::vector
<struct symbol
*> *template_args
,
15526 struct dwarf2_cu
*cu
)
15528 if (child_die
->tag
== DW_TAG_member
15529 || child_die
->tag
== DW_TAG_variable
)
15531 /* NOTE: carlton/2002-11-05: A C++ static data member
15532 should be a DW_TAG_member that is a declaration, but
15533 all versions of G++ as of this writing (so through at
15534 least 3.2.1) incorrectly generate DW_TAG_variable
15535 tags for them instead. */
15536 dwarf2_add_field (fi
, child_die
, cu
);
15538 else if (child_die
->tag
== DW_TAG_subprogram
)
15540 /* Rust doesn't have member functions in the C++ sense.
15541 However, it does emit ordinary functions as children
15542 of a struct DIE. */
15543 if (cu
->language
== language_rust
)
15544 read_func_scope (child_die
, cu
);
15547 /* C++ member function. */
15548 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15551 else if (child_die
->tag
== DW_TAG_inheritance
)
15553 /* C++ base class field. */
15554 dwarf2_add_field (fi
, child_die
, cu
);
15556 else if (type_can_define_types (child_die
))
15557 dwarf2_add_type_defn (fi
, child_die
, cu
);
15558 else if (child_die
->tag
== DW_TAG_template_type_param
15559 || child_die
->tag
== DW_TAG_template_value_param
)
15561 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15564 template_args
->push_back (arg
);
15566 else if (child_die
->tag
== DW_TAG_variant_part
)
15567 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15568 else if (child_die
->tag
== DW_TAG_variant
)
15569 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15572 /* Finish creating a structure or union type, including filling in
15573 its members and creating a symbol for it. */
15576 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15578 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15579 struct die_info
*child_die
;
15582 type
= get_die_type (die
, cu
);
15584 type
= read_structure_type (die
, cu
);
15586 bool has_template_parameters
= false;
15587 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15589 struct field_info fi
;
15590 std::vector
<struct symbol
*> template_args
;
15592 child_die
= die
->child
;
15594 while (child_die
&& child_die
->tag
)
15596 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15597 child_die
= child_die
->sibling
;
15600 /* Attach template arguments to type. */
15601 if (!template_args
.empty ())
15603 has_template_parameters
= true;
15604 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15605 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15606 TYPE_TEMPLATE_ARGUMENTS (type
)
15607 = XOBNEWVEC (&objfile
->objfile_obstack
,
15609 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15610 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15611 template_args
.data (),
15612 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15613 * sizeof (struct symbol
*)));
15616 /* Attach fields and member functions to the type. */
15617 if (fi
.nfields () > 0)
15618 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15619 if (!fi
.fnfieldlists
.empty ())
15621 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15623 /* Get the type which refers to the base class (possibly this
15624 class itself) which contains the vtable pointer for the current
15625 class from the DW_AT_containing_type attribute. This use of
15626 DW_AT_containing_type is a GNU extension. */
15628 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15630 struct type
*t
= die_containing_type (die
, cu
);
15632 set_type_vptr_basetype (type
, t
);
15637 /* Our own class provides vtbl ptr. */
15638 for (i
= TYPE_NFIELDS (t
) - 1;
15639 i
>= TYPE_N_BASECLASSES (t
);
15642 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15644 if (is_vtable_name (fieldname
, cu
))
15646 set_type_vptr_fieldno (type
, i
);
15651 /* Complain if virtual function table field not found. */
15652 if (i
< TYPE_N_BASECLASSES (t
))
15653 complaint (_("virtual function table pointer "
15654 "not found when defining class '%s'"),
15655 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15659 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15662 else if (cu
->producer
15663 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15665 /* The IBM XLC compiler does not provide direct indication
15666 of the containing type, but the vtable pointer is
15667 always named __vfp. */
15671 for (i
= TYPE_NFIELDS (type
) - 1;
15672 i
>= TYPE_N_BASECLASSES (type
);
15675 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15677 set_type_vptr_fieldno (type
, i
);
15678 set_type_vptr_basetype (type
, type
);
15685 /* Copy fi.typedef_field_list linked list elements content into the
15686 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15687 if (!fi
.typedef_field_list
.empty ())
15689 int count
= fi
.typedef_field_list
.size ();
15691 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15692 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15693 = ((struct decl_field
*)
15695 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15696 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15698 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15699 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15702 /* Copy fi.nested_types_list linked list elements content into the
15703 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15704 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15706 int count
= fi
.nested_types_list
.size ();
15708 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15709 TYPE_NESTED_TYPES_ARRAY (type
)
15710 = ((struct decl_field
*)
15711 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15712 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15714 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15715 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15719 quirk_gcc_member_function_pointer (type
, objfile
);
15720 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15721 cu
->rust_unions
.push_back (type
);
15723 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15724 snapshots) has been known to create a die giving a declaration
15725 for a class that has, as a child, a die giving a definition for a
15726 nested class. So we have to process our children even if the
15727 current die is a declaration. Normally, of course, a declaration
15728 won't have any children at all. */
15730 child_die
= die
->child
;
15732 while (child_die
!= NULL
&& child_die
->tag
)
15734 if (child_die
->tag
== DW_TAG_member
15735 || child_die
->tag
== DW_TAG_variable
15736 || child_die
->tag
== DW_TAG_inheritance
15737 || child_die
->tag
== DW_TAG_template_value_param
15738 || child_die
->tag
== DW_TAG_template_type_param
)
15743 process_die (child_die
, cu
);
15745 child_die
= child_die
->sibling
;
15748 /* Do not consider external references. According to the DWARF standard,
15749 these DIEs are identified by the fact that they have no byte_size
15750 attribute, and a declaration attribute. */
15751 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15752 || !die_is_declaration (die
, cu
)
15753 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15755 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15757 if (has_template_parameters
)
15759 struct symtab
*symtab
;
15760 if (sym
!= nullptr)
15761 symtab
= symbol_symtab (sym
);
15762 else if (cu
->line_header
!= nullptr)
15764 /* Any related symtab will do. */
15766 = cu
->line_header
->file_names ()[0].symtab
;
15771 complaint (_("could not find suitable "
15772 "symtab for template parameter"
15773 " - DIE at %s [in module %s]"),
15774 sect_offset_str (die
->sect_off
),
15775 objfile_name (objfile
));
15778 if (symtab
!= nullptr)
15780 /* Make sure that the symtab is set on the new symbols.
15781 Even though they don't appear in this symtab directly,
15782 other parts of gdb assume that symbols do, and this is
15783 reasonably true. */
15784 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15785 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15791 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15792 update TYPE using some information only available in DIE's children. */
15795 update_enumeration_type_from_children (struct die_info
*die
,
15797 struct dwarf2_cu
*cu
)
15799 struct die_info
*child_die
;
15800 int unsigned_enum
= 1;
15803 auto_obstack obstack
;
15805 for (child_die
= die
->child
;
15806 child_die
!= NULL
&& child_die
->tag
;
15807 child_die
= child_die
->sibling
)
15809 struct attribute
*attr
;
15811 const gdb_byte
*bytes
;
15812 struct dwarf2_locexpr_baton
*baton
;
15815 if (child_die
->tag
!= DW_TAG_enumerator
)
15818 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15822 name
= dwarf2_name (child_die
, cu
);
15824 name
= "<anonymous enumerator>";
15826 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15827 &value
, &bytes
, &baton
);
15835 if (count_one_bits_ll (value
) >= 2)
15839 /* If we already know that the enum type is neither unsigned, nor
15840 a flag type, no need to look at the rest of the enumerates. */
15841 if (!unsigned_enum
&& !flag_enum
)
15846 TYPE_UNSIGNED (type
) = 1;
15848 TYPE_FLAG_ENUM (type
) = 1;
15851 /* Given a DW_AT_enumeration_type die, set its type. We do not
15852 complete the type's fields yet, or create any symbols. */
15854 static struct type
*
15855 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15857 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15859 struct attribute
*attr
;
15862 /* If the definition of this type lives in .debug_types, read that type.
15863 Don't follow DW_AT_specification though, that will take us back up
15864 the chain and we want to go down. */
15865 attr
= die
->attr (DW_AT_signature
);
15866 if (attr
!= nullptr)
15868 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15870 /* The type's CU may not be the same as CU.
15871 Ensure TYPE is recorded with CU in die_type_hash. */
15872 return set_die_type (die
, type
, cu
);
15875 type
= alloc_type (objfile
);
15877 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15878 name
= dwarf2_full_name (NULL
, die
, cu
);
15880 TYPE_NAME (type
) = name
;
15882 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15885 struct type
*underlying_type
= die_type (die
, cu
);
15887 TYPE_TARGET_TYPE (type
) = underlying_type
;
15890 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15891 if (attr
!= nullptr)
15893 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15897 TYPE_LENGTH (type
) = 0;
15900 maybe_set_alignment (cu
, die
, type
);
15902 /* The enumeration DIE can be incomplete. In Ada, any type can be
15903 declared as private in the package spec, and then defined only
15904 inside the package body. Such types are known as Taft Amendment
15905 Types. When another package uses such a type, an incomplete DIE
15906 may be generated by the compiler. */
15907 if (die_is_declaration (die
, cu
))
15908 TYPE_STUB (type
) = 1;
15910 /* Finish the creation of this type by using the enum's children.
15911 We must call this even when the underlying type has been provided
15912 so that we can determine if we're looking at a "flag" enum. */
15913 update_enumeration_type_from_children (die
, type
, cu
);
15915 /* If this type has an underlying type that is not a stub, then we
15916 may use its attributes. We always use the "unsigned" attribute
15917 in this situation, because ordinarily we guess whether the type
15918 is unsigned -- but the guess can be wrong and the underlying type
15919 can tell us the reality. However, we defer to a local size
15920 attribute if one exists, because this lets the compiler override
15921 the underlying type if needed. */
15922 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15924 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
15925 underlying_type
= check_typedef (underlying_type
);
15926 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
15927 if (TYPE_LENGTH (type
) == 0)
15928 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
15929 if (TYPE_RAW_ALIGN (type
) == 0
15930 && TYPE_RAW_ALIGN (underlying_type
) != 0)
15931 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
15934 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15936 return set_die_type (die
, type
, cu
);
15939 /* Given a pointer to a die which begins an enumeration, process all
15940 the dies that define the members of the enumeration, and create the
15941 symbol for the enumeration type.
15943 NOTE: We reverse the order of the element list. */
15946 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15948 struct type
*this_type
;
15950 this_type
= get_die_type (die
, cu
);
15951 if (this_type
== NULL
)
15952 this_type
= read_enumeration_type (die
, cu
);
15954 if (die
->child
!= NULL
)
15956 struct die_info
*child_die
;
15957 struct symbol
*sym
;
15958 std::vector
<struct field
> fields
;
15961 child_die
= die
->child
;
15962 while (child_die
&& child_die
->tag
)
15964 if (child_die
->tag
!= DW_TAG_enumerator
)
15966 process_die (child_die
, cu
);
15970 name
= dwarf2_name (child_die
, cu
);
15973 sym
= new_symbol (child_die
, this_type
, cu
);
15975 fields
.emplace_back ();
15976 struct field
&field
= fields
.back ();
15978 FIELD_NAME (field
) = sym
->linkage_name ();
15979 FIELD_TYPE (field
) = NULL
;
15980 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15981 FIELD_BITSIZE (field
) = 0;
15985 child_die
= child_die
->sibling
;
15988 if (!fields
.empty ())
15990 TYPE_NFIELDS (this_type
) = fields
.size ();
15991 TYPE_FIELDS (this_type
) = (struct field
*)
15992 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15993 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15994 sizeof (struct field
) * fields
.size ());
15998 /* If we are reading an enum from a .debug_types unit, and the enum
15999 is a declaration, and the enum is not the signatured type in the
16000 unit, then we do not want to add a symbol for it. Adding a
16001 symbol would in some cases obscure the true definition of the
16002 enum, giving users an incomplete type when the definition is
16003 actually available. Note that we do not want to do this for all
16004 enums which are just declarations, because C++0x allows forward
16005 enum declarations. */
16006 if (cu
->per_cu
->is_debug_types
16007 && die_is_declaration (die
, cu
))
16009 struct signatured_type
*sig_type
;
16011 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16012 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16013 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16017 new_symbol (die
, this_type
, cu
);
16020 /* Extract all information from a DW_TAG_array_type DIE and put it in
16021 the DIE's type field. For now, this only handles one dimensional
16024 static struct type
*
16025 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16027 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16028 struct die_info
*child_die
;
16030 struct type
*element_type
, *range_type
, *index_type
;
16031 struct attribute
*attr
;
16033 struct dynamic_prop
*byte_stride_prop
= NULL
;
16034 unsigned int bit_stride
= 0;
16036 element_type
= die_type (die
, cu
);
16038 /* The die_type call above may have already set the type for this DIE. */
16039 type
= get_die_type (die
, cu
);
16043 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16047 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
16050 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16051 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16055 complaint (_("unable to read array DW_AT_byte_stride "
16056 " - DIE at %s [in module %s]"),
16057 sect_offset_str (die
->sect_off
),
16058 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16059 /* Ignore this attribute. We will likely not be able to print
16060 arrays of this type correctly, but there is little we can do
16061 to help if we cannot read the attribute's value. */
16062 byte_stride_prop
= NULL
;
16066 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16068 bit_stride
= DW_UNSND (attr
);
16070 /* Irix 6.2 native cc creates array types without children for
16071 arrays with unspecified length. */
16072 if (die
->child
== NULL
)
16074 index_type
= objfile_type (objfile
)->builtin_int
;
16075 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16076 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16077 byte_stride_prop
, bit_stride
);
16078 return set_die_type (die
, type
, cu
);
16081 std::vector
<struct type
*> range_types
;
16082 child_die
= die
->child
;
16083 while (child_die
&& child_die
->tag
)
16085 if (child_die
->tag
== DW_TAG_subrange_type
)
16087 struct type
*child_type
= read_type_die (child_die
, cu
);
16089 if (child_type
!= NULL
)
16091 /* The range type was succesfully read. Save it for the
16092 array type creation. */
16093 range_types
.push_back (child_type
);
16096 child_die
= child_die
->sibling
;
16099 /* Dwarf2 dimensions are output from left to right, create the
16100 necessary array types in backwards order. */
16102 type
= element_type
;
16104 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16108 while (i
< range_types
.size ())
16109 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16110 byte_stride_prop
, bit_stride
);
16114 size_t ndim
= range_types
.size ();
16116 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16117 byte_stride_prop
, bit_stride
);
16120 /* Understand Dwarf2 support for vector types (like they occur on
16121 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16122 array type. This is not part of the Dwarf2/3 standard yet, but a
16123 custom vendor extension. The main difference between a regular
16124 array and the vector variant is that vectors are passed by value
16126 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16127 if (attr
!= nullptr)
16128 make_vector_type (type
);
16130 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16131 implementation may choose to implement triple vectors using this
16133 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16134 if (attr
!= nullptr)
16136 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16137 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16139 complaint (_("DW_AT_byte_size for array type smaller "
16140 "than the total size of elements"));
16143 name
= dwarf2_name (die
, cu
);
16145 TYPE_NAME (type
) = name
;
16147 maybe_set_alignment (cu
, die
, type
);
16149 /* Install the type in the die. */
16150 set_die_type (die
, type
, cu
);
16152 /* set_die_type should be already done. */
16153 set_descriptive_type (type
, die
, cu
);
16158 static enum dwarf_array_dim_ordering
16159 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16161 struct attribute
*attr
;
16163 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16165 if (attr
!= nullptr)
16166 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16168 /* GNU F77 is a special case, as at 08/2004 array type info is the
16169 opposite order to the dwarf2 specification, but data is still
16170 laid out as per normal fortran.
16172 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16173 version checking. */
16175 if (cu
->language
== language_fortran
16176 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16178 return DW_ORD_row_major
;
16181 switch (cu
->language_defn
->la_array_ordering
)
16183 case array_column_major
:
16184 return DW_ORD_col_major
;
16185 case array_row_major
:
16187 return DW_ORD_row_major
;
16191 /* Extract all information from a DW_TAG_set_type DIE and put it in
16192 the DIE's type field. */
16194 static struct type
*
16195 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16197 struct type
*domain_type
, *set_type
;
16198 struct attribute
*attr
;
16200 domain_type
= die_type (die
, cu
);
16202 /* The die_type call above may have already set the type for this DIE. */
16203 set_type
= get_die_type (die
, cu
);
16207 set_type
= create_set_type (NULL
, domain_type
);
16209 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16210 if (attr
!= nullptr)
16211 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16213 maybe_set_alignment (cu
, die
, set_type
);
16215 return set_die_type (die
, set_type
, cu
);
16218 /* A helper for read_common_block that creates a locexpr baton.
16219 SYM is the symbol which we are marking as computed.
16220 COMMON_DIE is the DIE for the common block.
16221 COMMON_LOC is the location expression attribute for the common
16223 MEMBER_LOC is the location expression attribute for the particular
16224 member of the common block that we are processing.
16225 CU is the CU from which the above come. */
16228 mark_common_block_symbol_computed (struct symbol
*sym
,
16229 struct die_info
*common_die
,
16230 struct attribute
*common_loc
,
16231 struct attribute
*member_loc
,
16232 struct dwarf2_cu
*cu
)
16234 struct dwarf2_per_objfile
*dwarf2_per_objfile
16235 = cu
->per_cu
->dwarf2_per_objfile
;
16236 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16237 struct dwarf2_locexpr_baton
*baton
;
16239 unsigned int cu_off
;
16240 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16241 LONGEST offset
= 0;
16243 gdb_assert (common_loc
&& member_loc
);
16244 gdb_assert (common_loc
->form_is_block ());
16245 gdb_assert (member_loc
->form_is_block ()
16246 || member_loc
->form_is_constant ());
16248 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16249 baton
->per_cu
= cu
->per_cu
;
16250 gdb_assert (baton
->per_cu
);
16252 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16254 if (member_loc
->form_is_constant ())
16256 offset
= member_loc
->constant_value (0);
16257 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16260 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16262 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16265 *ptr
++ = DW_OP_call4
;
16266 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16267 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16270 if (member_loc
->form_is_constant ())
16272 *ptr
++ = DW_OP_addr
;
16273 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16274 ptr
+= cu
->header
.addr_size
;
16278 /* We have to copy the data here, because DW_OP_call4 will only
16279 use a DW_AT_location attribute. */
16280 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16281 ptr
+= DW_BLOCK (member_loc
)->size
;
16284 *ptr
++ = DW_OP_plus
;
16285 gdb_assert (ptr
- baton
->data
== baton
->size
);
16287 SYMBOL_LOCATION_BATON (sym
) = baton
;
16288 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16291 /* Create appropriate locally-scoped variables for all the
16292 DW_TAG_common_block entries. Also create a struct common_block
16293 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16294 is used to separate the common blocks name namespace from regular
16298 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16300 struct attribute
*attr
;
16302 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16303 if (attr
!= nullptr)
16305 /* Support the .debug_loc offsets. */
16306 if (attr
->form_is_block ())
16310 else if (attr
->form_is_section_offset ())
16312 dwarf2_complex_location_expr_complaint ();
16317 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16318 "common block member");
16323 if (die
->child
!= NULL
)
16325 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16326 struct die_info
*child_die
;
16327 size_t n_entries
= 0, size
;
16328 struct common_block
*common_block
;
16329 struct symbol
*sym
;
16331 for (child_die
= die
->child
;
16332 child_die
&& child_die
->tag
;
16333 child_die
= child_die
->sibling
)
16336 size
= (sizeof (struct common_block
)
16337 + (n_entries
- 1) * sizeof (struct symbol
*));
16339 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16341 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16342 common_block
->n_entries
= 0;
16344 for (child_die
= die
->child
;
16345 child_die
&& child_die
->tag
;
16346 child_die
= child_die
->sibling
)
16348 /* Create the symbol in the DW_TAG_common_block block in the current
16350 sym
= new_symbol (child_die
, NULL
, cu
);
16353 struct attribute
*member_loc
;
16355 common_block
->contents
[common_block
->n_entries
++] = sym
;
16357 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16361 /* GDB has handled this for a long time, but it is
16362 not specified by DWARF. It seems to have been
16363 emitted by gfortran at least as recently as:
16364 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16365 complaint (_("Variable in common block has "
16366 "DW_AT_data_member_location "
16367 "- DIE at %s [in module %s]"),
16368 sect_offset_str (child_die
->sect_off
),
16369 objfile_name (objfile
));
16371 if (member_loc
->form_is_section_offset ())
16372 dwarf2_complex_location_expr_complaint ();
16373 else if (member_loc
->form_is_constant ()
16374 || member_loc
->form_is_block ())
16376 if (attr
!= nullptr)
16377 mark_common_block_symbol_computed (sym
, die
, attr
,
16381 dwarf2_complex_location_expr_complaint ();
16386 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16387 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16391 /* Create a type for a C++ namespace. */
16393 static struct type
*
16394 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16396 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16397 const char *previous_prefix
, *name
;
16401 /* For extensions, reuse the type of the original namespace. */
16402 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16404 struct die_info
*ext_die
;
16405 struct dwarf2_cu
*ext_cu
= cu
;
16407 ext_die
= dwarf2_extension (die
, &ext_cu
);
16408 type
= read_type_die (ext_die
, ext_cu
);
16410 /* EXT_CU may not be the same as CU.
16411 Ensure TYPE is recorded with CU in die_type_hash. */
16412 return set_die_type (die
, type
, cu
);
16415 name
= namespace_name (die
, &is_anonymous
, cu
);
16417 /* Now build the name of the current namespace. */
16419 previous_prefix
= determine_prefix (die
, cu
);
16420 if (previous_prefix
[0] != '\0')
16421 name
= typename_concat (&objfile
->objfile_obstack
,
16422 previous_prefix
, name
, 0, cu
);
16424 /* Create the type. */
16425 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16427 return set_die_type (die
, type
, cu
);
16430 /* Read a namespace scope. */
16433 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16435 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16438 /* Add a symbol associated to this if we haven't seen the namespace
16439 before. Also, add a using directive if it's an anonymous
16442 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16446 type
= read_type_die (die
, cu
);
16447 new_symbol (die
, type
, cu
);
16449 namespace_name (die
, &is_anonymous
, cu
);
16452 const char *previous_prefix
= determine_prefix (die
, cu
);
16454 std::vector
<const char *> excludes
;
16455 add_using_directive (using_directives (cu
),
16456 previous_prefix
, TYPE_NAME (type
), NULL
,
16457 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16461 if (die
->child
!= NULL
)
16463 struct die_info
*child_die
= die
->child
;
16465 while (child_die
&& child_die
->tag
)
16467 process_die (child_die
, cu
);
16468 child_die
= child_die
->sibling
;
16473 /* Read a Fortran module as type. This DIE can be only a declaration used for
16474 imported module. Still we need that type as local Fortran "use ... only"
16475 declaration imports depend on the created type in determine_prefix. */
16477 static struct type
*
16478 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16480 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16481 const char *module_name
;
16484 module_name
= dwarf2_name (die
, cu
);
16485 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16487 return set_die_type (die
, type
, cu
);
16490 /* Read a Fortran module. */
16493 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16495 struct die_info
*child_die
= die
->child
;
16498 type
= read_type_die (die
, cu
);
16499 new_symbol (die
, type
, cu
);
16501 while (child_die
&& child_die
->tag
)
16503 process_die (child_die
, cu
);
16504 child_die
= child_die
->sibling
;
16508 /* Return the name of the namespace represented by DIE. Set
16509 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16512 static const char *
16513 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16515 struct die_info
*current_die
;
16516 const char *name
= NULL
;
16518 /* Loop through the extensions until we find a name. */
16520 for (current_die
= die
;
16521 current_die
!= NULL
;
16522 current_die
= dwarf2_extension (die
, &cu
))
16524 /* We don't use dwarf2_name here so that we can detect the absence
16525 of a name -> anonymous namespace. */
16526 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16532 /* Is it an anonymous namespace? */
16534 *is_anonymous
= (name
== NULL
);
16536 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16541 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16542 the user defined type vector. */
16544 static struct type
*
16545 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16547 struct gdbarch
*gdbarch
16548 = cu
->per_cu
->dwarf2_per_objfile
->objfile
->arch ();
16549 struct comp_unit_head
*cu_header
= &cu
->header
;
16551 struct attribute
*attr_byte_size
;
16552 struct attribute
*attr_address_class
;
16553 int byte_size
, addr_class
;
16554 struct type
*target_type
;
16556 target_type
= die_type (die
, cu
);
16558 /* The die_type call above may have already set the type for this DIE. */
16559 type
= get_die_type (die
, cu
);
16563 type
= lookup_pointer_type (target_type
);
16565 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16566 if (attr_byte_size
)
16567 byte_size
= DW_UNSND (attr_byte_size
);
16569 byte_size
= cu_header
->addr_size
;
16571 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16572 if (attr_address_class
)
16573 addr_class
= DW_UNSND (attr_address_class
);
16575 addr_class
= DW_ADDR_none
;
16577 ULONGEST alignment
= get_alignment (cu
, die
);
16579 /* If the pointer size, alignment, or address class is different
16580 than the default, create a type variant marked as such and set
16581 the length accordingly. */
16582 if (TYPE_LENGTH (type
) != byte_size
16583 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16584 && alignment
!= TYPE_RAW_ALIGN (type
))
16585 || addr_class
!= DW_ADDR_none
)
16587 if (gdbarch_address_class_type_flags_p (gdbarch
))
16591 type_flags
= gdbarch_address_class_type_flags
16592 (gdbarch
, byte_size
, addr_class
);
16593 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16595 type
= make_type_with_address_space (type
, type_flags
);
16597 else if (TYPE_LENGTH (type
) != byte_size
)
16599 complaint (_("invalid pointer size %d"), byte_size
);
16601 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16603 complaint (_("Invalid DW_AT_alignment"
16604 " - DIE at %s [in module %s]"),
16605 sect_offset_str (die
->sect_off
),
16606 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16610 /* Should we also complain about unhandled address classes? */
16614 TYPE_LENGTH (type
) = byte_size
;
16615 set_type_align (type
, alignment
);
16616 return set_die_type (die
, type
, cu
);
16619 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16620 the user defined type vector. */
16622 static struct type
*
16623 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16626 struct type
*to_type
;
16627 struct type
*domain
;
16629 to_type
= die_type (die
, cu
);
16630 domain
= die_containing_type (die
, cu
);
16632 /* The calls above may have already set the type for this DIE. */
16633 type
= get_die_type (die
, cu
);
16637 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16638 type
= lookup_methodptr_type (to_type
);
16639 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16641 struct type
*new_type
16642 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16644 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16645 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16646 TYPE_VARARGS (to_type
));
16647 type
= lookup_methodptr_type (new_type
);
16650 type
= lookup_memberptr_type (to_type
, domain
);
16652 return set_die_type (die
, type
, cu
);
16655 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16656 the user defined type vector. */
16658 static struct type
*
16659 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16660 enum type_code refcode
)
16662 struct comp_unit_head
*cu_header
= &cu
->header
;
16663 struct type
*type
, *target_type
;
16664 struct attribute
*attr
;
16666 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16668 target_type
= die_type (die
, cu
);
16670 /* The die_type call above may have already set the type for this DIE. */
16671 type
= get_die_type (die
, cu
);
16675 type
= lookup_reference_type (target_type
, refcode
);
16676 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16677 if (attr
!= nullptr)
16679 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16683 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16685 maybe_set_alignment (cu
, die
, type
);
16686 return set_die_type (die
, type
, cu
);
16689 /* Add the given cv-qualifiers to the element type of the array. GCC
16690 outputs DWARF type qualifiers that apply to an array, not the
16691 element type. But GDB relies on the array element type to carry
16692 the cv-qualifiers. This mimics section 6.7.3 of the C99
16695 static struct type
*
16696 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16697 struct type
*base_type
, int cnst
, int voltl
)
16699 struct type
*el_type
, *inner_array
;
16701 base_type
= copy_type (base_type
);
16702 inner_array
= base_type
;
16704 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16706 TYPE_TARGET_TYPE (inner_array
) =
16707 copy_type (TYPE_TARGET_TYPE (inner_array
));
16708 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16711 el_type
= TYPE_TARGET_TYPE (inner_array
);
16712 cnst
|= TYPE_CONST (el_type
);
16713 voltl
|= TYPE_VOLATILE (el_type
);
16714 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16716 return set_die_type (die
, base_type
, cu
);
16719 static struct type
*
16720 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16722 struct type
*base_type
, *cv_type
;
16724 base_type
= die_type (die
, cu
);
16726 /* The die_type call above may have already set the type for this DIE. */
16727 cv_type
= get_die_type (die
, cu
);
16731 /* In case the const qualifier is applied to an array type, the element type
16732 is so qualified, not the array type (section 6.7.3 of C99). */
16733 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16734 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16736 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16737 return set_die_type (die
, cv_type
, cu
);
16740 static struct type
*
16741 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16743 struct type
*base_type
, *cv_type
;
16745 base_type
= die_type (die
, cu
);
16747 /* The die_type call above may have already set the type for this DIE. */
16748 cv_type
= get_die_type (die
, cu
);
16752 /* In case the volatile qualifier is applied to an array type, the
16753 element type is so qualified, not the array type (section 6.7.3
16755 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16756 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16758 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16759 return set_die_type (die
, cv_type
, cu
);
16762 /* Handle DW_TAG_restrict_type. */
16764 static struct type
*
16765 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16767 struct type
*base_type
, *cv_type
;
16769 base_type
= die_type (die
, cu
);
16771 /* The die_type call above may have already set the type for this DIE. */
16772 cv_type
= get_die_type (die
, cu
);
16776 cv_type
= make_restrict_type (base_type
);
16777 return set_die_type (die
, cv_type
, cu
);
16780 /* Handle DW_TAG_atomic_type. */
16782 static struct type
*
16783 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16785 struct type
*base_type
, *cv_type
;
16787 base_type
= die_type (die
, cu
);
16789 /* The die_type call above may have already set the type for this DIE. */
16790 cv_type
= get_die_type (die
, cu
);
16794 cv_type
= make_atomic_type (base_type
);
16795 return set_die_type (die
, cv_type
, cu
);
16798 /* Extract all information from a DW_TAG_string_type DIE and add to
16799 the user defined type vector. It isn't really a user defined type,
16800 but it behaves like one, with other DIE's using an AT_user_def_type
16801 attribute to reference it. */
16803 static struct type
*
16804 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16806 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16807 struct gdbarch
*gdbarch
= objfile
->arch ();
16808 struct type
*type
, *range_type
, *index_type
, *char_type
;
16809 struct attribute
*attr
;
16810 struct dynamic_prop prop
;
16811 bool length_is_constant
= true;
16814 /* There are a couple of places where bit sizes might be made use of
16815 when parsing a DW_TAG_string_type, however, no producer that we know
16816 of make use of these. Handling bit sizes that are a multiple of the
16817 byte size is easy enough, but what about other bit sizes? Lets deal
16818 with that problem when we have to. Warn about these attributes being
16819 unsupported, then parse the type and ignore them like we always
16821 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16822 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16824 static bool warning_printed
= false;
16825 if (!warning_printed
)
16827 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16828 "currently supported on DW_TAG_string_type."));
16829 warning_printed
= true;
16833 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16834 if (attr
!= nullptr && !attr
->form_is_constant ())
16836 /* The string length describes the location at which the length of
16837 the string can be found. The size of the length field can be
16838 specified with one of the attributes below. */
16839 struct type
*prop_type
;
16840 struct attribute
*len
16841 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16842 if (len
== nullptr)
16843 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16844 if (len
!= nullptr && len
->form_is_constant ())
16846 /* Pass 0 as the default as we know this attribute is constant
16847 and the default value will not be returned. */
16848 LONGEST sz
= len
->constant_value (0);
16849 prop_type
= cu
->per_cu
->int_type (sz
, true);
16853 /* If the size is not specified then we assume it is the size of
16854 an address on this target. */
16855 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16858 /* Convert the attribute into a dynamic property. */
16859 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16862 length_is_constant
= false;
16864 else if (attr
!= nullptr)
16866 /* This DW_AT_string_length just contains the length with no
16867 indirection. There's no need to create a dynamic property in this
16868 case. Pass 0 for the default value as we know it will not be
16869 returned in this case. */
16870 length
= attr
->constant_value (0);
16872 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16874 /* We don't currently support non-constant byte sizes for strings. */
16875 length
= attr
->constant_value (1);
16879 /* Use 1 as a fallback length if we have nothing else. */
16883 index_type
= objfile_type (objfile
)->builtin_int
;
16884 if (length_is_constant
)
16885 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16888 struct dynamic_prop low_bound
;
16890 low_bound
.kind
= PROP_CONST
;
16891 low_bound
.data
.const_val
= 1;
16892 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16894 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16895 type
= create_string_type (NULL
, char_type
, range_type
);
16897 return set_die_type (die
, type
, cu
);
16900 /* Assuming that DIE corresponds to a function, returns nonzero
16901 if the function is prototyped. */
16904 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16906 struct attribute
*attr
;
16908 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16909 if (attr
&& (DW_UNSND (attr
) != 0))
16912 /* The DWARF standard implies that the DW_AT_prototyped attribute
16913 is only meaningful for C, but the concept also extends to other
16914 languages that allow unprototyped functions (Eg: Objective C).
16915 For all other languages, assume that functions are always
16917 if (cu
->language
!= language_c
16918 && cu
->language
!= language_objc
16919 && cu
->language
!= language_opencl
)
16922 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16923 prototyped and unprototyped functions; default to prototyped,
16924 since that is more common in modern code (and RealView warns
16925 about unprototyped functions). */
16926 if (producer_is_realview (cu
->producer
))
16932 /* Handle DIES due to C code like:
16936 int (*funcp)(int a, long l);
16940 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16942 static struct type
*
16943 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16945 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16946 struct type
*type
; /* Type that this function returns. */
16947 struct type
*ftype
; /* Function that returns above type. */
16948 struct attribute
*attr
;
16950 type
= die_type (die
, cu
);
16952 /* The die_type call above may have already set the type for this DIE. */
16953 ftype
= get_die_type (die
, cu
);
16957 ftype
= lookup_function_type (type
);
16959 if (prototyped_function_p (die
, cu
))
16960 TYPE_PROTOTYPED (ftype
) = 1;
16962 /* Store the calling convention in the type if it's available in
16963 the subroutine die. Otherwise set the calling convention to
16964 the default value DW_CC_normal. */
16965 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16966 if (attr
!= nullptr
16967 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16968 TYPE_CALLING_CONVENTION (ftype
)
16969 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16970 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16971 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16973 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16975 /* Record whether the function returns normally to its caller or not
16976 if the DWARF producer set that information. */
16977 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16978 if (attr
&& (DW_UNSND (attr
) != 0))
16979 TYPE_NO_RETURN (ftype
) = 1;
16981 /* We need to add the subroutine type to the die immediately so
16982 we don't infinitely recurse when dealing with parameters
16983 declared as the same subroutine type. */
16984 set_die_type (die
, ftype
, cu
);
16986 if (die
->child
!= NULL
)
16988 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16989 struct die_info
*child_die
;
16990 int nparams
, iparams
;
16992 /* Count the number of parameters.
16993 FIXME: GDB currently ignores vararg functions, but knows about
16994 vararg member functions. */
16996 child_die
= die
->child
;
16997 while (child_die
&& child_die
->tag
)
16999 if (child_die
->tag
== DW_TAG_formal_parameter
)
17001 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17002 TYPE_VARARGS (ftype
) = 1;
17003 child_die
= child_die
->sibling
;
17006 /* Allocate storage for parameters and fill them in. */
17007 TYPE_NFIELDS (ftype
) = nparams
;
17008 TYPE_FIELDS (ftype
) = (struct field
*)
17009 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17011 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17012 even if we error out during the parameters reading below. */
17013 for (iparams
= 0; iparams
< nparams
; iparams
++)
17014 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17017 child_die
= die
->child
;
17018 while (child_die
&& child_die
->tag
)
17020 if (child_die
->tag
== DW_TAG_formal_parameter
)
17022 struct type
*arg_type
;
17024 /* DWARF version 2 has no clean way to discern C++
17025 static and non-static member functions. G++ helps
17026 GDB by marking the first parameter for non-static
17027 member functions (which is the this pointer) as
17028 artificial. We pass this information to
17029 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17031 DWARF version 3 added DW_AT_object_pointer, which GCC
17032 4.5 does not yet generate. */
17033 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17034 if (attr
!= nullptr)
17035 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17037 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17038 arg_type
= die_type (child_die
, cu
);
17040 /* RealView does not mark THIS as const, which the testsuite
17041 expects. GCC marks THIS as const in method definitions,
17042 but not in the class specifications (GCC PR 43053). */
17043 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17044 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17047 struct dwarf2_cu
*arg_cu
= cu
;
17048 const char *name
= dwarf2_name (child_die
, cu
);
17050 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17051 if (attr
!= nullptr)
17053 /* If the compiler emits this, use it. */
17054 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17057 else if (name
&& strcmp (name
, "this") == 0)
17058 /* Function definitions will have the argument names. */
17060 else if (name
== NULL
&& iparams
== 0)
17061 /* Declarations may not have the names, so like
17062 elsewhere in GDB, assume an artificial first
17063 argument is "this". */
17067 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17071 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17074 child_die
= child_die
->sibling
;
17081 static struct type
*
17082 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17084 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17085 const char *name
= NULL
;
17086 struct type
*this_type
, *target_type
;
17088 name
= dwarf2_full_name (NULL
, die
, cu
);
17089 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17090 TYPE_TARGET_STUB (this_type
) = 1;
17091 set_die_type (die
, this_type
, cu
);
17092 target_type
= die_type (die
, cu
);
17093 if (target_type
!= this_type
)
17094 TYPE_TARGET_TYPE (this_type
) = target_type
;
17097 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17098 spec and cause infinite loops in GDB. */
17099 complaint (_("Self-referential DW_TAG_typedef "
17100 "- DIE at %s [in module %s]"),
17101 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17102 TYPE_TARGET_TYPE (this_type
) = NULL
;
17106 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17107 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17108 Handle these by just returning the target type, rather than
17109 constructing an anonymous typedef type and trying to handle this
17111 set_die_type (die
, target_type
, cu
);
17112 return target_type
;
17117 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17118 (which may be different from NAME) to the architecture back-end to allow
17119 it to guess the correct format if necessary. */
17121 static struct type
*
17122 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17123 const char *name_hint
, enum bfd_endian byte_order
)
17125 struct gdbarch
*gdbarch
= objfile
->arch ();
17126 const struct floatformat
**format
;
17129 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17131 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17133 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17138 /* Allocate an integer type of size BITS and name NAME. */
17140 static struct type
*
17141 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17142 int bits
, int unsigned_p
, const char *name
)
17146 /* Versions of Intel's C Compiler generate an integer type called "void"
17147 instead of using DW_TAG_unspecified_type. This has been seen on
17148 at least versions 14, 17, and 18. */
17149 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17150 && strcmp (name
, "void") == 0)
17151 type
= objfile_type (objfile
)->builtin_void
;
17153 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17158 /* Initialise and return a floating point type of size BITS suitable for
17159 use as a component of a complex number. The NAME_HINT is passed through
17160 when initialising the floating point type and is the name of the complex
17163 As DWARF doesn't currently provide an explicit name for the components
17164 of a complex number, but it can be helpful to have these components
17165 named, we try to select a suitable name based on the size of the
17167 static struct type
*
17168 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17169 struct objfile
*objfile
,
17170 int bits
, const char *name_hint
,
17171 enum bfd_endian byte_order
)
17173 gdbarch
*gdbarch
= objfile
->arch ();
17174 struct type
*tt
= nullptr;
17176 /* Try to find a suitable floating point builtin type of size BITS.
17177 We're going to use the name of this type as the name for the complex
17178 target type that we are about to create. */
17179 switch (cu
->language
)
17181 case language_fortran
:
17185 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17188 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17190 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17192 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17200 tt
= builtin_type (gdbarch
)->builtin_float
;
17203 tt
= builtin_type (gdbarch
)->builtin_double
;
17205 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17207 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17213 /* If the type we found doesn't match the size we were looking for, then
17214 pretend we didn't find a type at all, the complex target type we
17215 create will then be nameless. */
17216 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17219 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17220 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17223 /* Find a representation of a given base type and install
17224 it in the TYPE field of the die. */
17226 static struct type
*
17227 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17229 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17231 struct attribute
*attr
;
17232 int encoding
= 0, bits
= 0;
17236 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17237 if (attr
!= nullptr)
17238 encoding
= DW_UNSND (attr
);
17239 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17240 if (attr
!= nullptr)
17241 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17242 name
= dwarf2_name (die
, cu
);
17244 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17246 arch
= objfile
->arch ();
17247 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17249 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17252 int endianity
= DW_UNSND (attr
);
17257 byte_order
= BFD_ENDIAN_BIG
;
17259 case DW_END_little
:
17260 byte_order
= BFD_ENDIAN_LITTLE
;
17263 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17270 case DW_ATE_address
:
17271 /* Turn DW_ATE_address into a void * pointer. */
17272 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17273 type
= init_pointer_type (objfile
, bits
, name
, type
);
17275 case DW_ATE_boolean
:
17276 type
= init_boolean_type (objfile
, bits
, 1, name
);
17278 case DW_ATE_complex_float
:
17279 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17281 if (TYPE_CODE (type
) == TYPE_CODE_ERROR
)
17283 if (name
== nullptr)
17285 struct obstack
*obstack
17286 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17287 name
= obconcat (obstack
, "_Complex ", TYPE_NAME (type
),
17290 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17293 type
= init_complex_type (name
, type
);
17295 case DW_ATE_decimal_float
:
17296 type
= init_decfloat_type (objfile
, bits
, name
);
17299 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17301 case DW_ATE_signed
:
17302 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17304 case DW_ATE_unsigned
:
17305 if (cu
->language
== language_fortran
17307 && startswith (name
, "character("))
17308 type
= init_character_type (objfile
, bits
, 1, name
);
17310 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17312 case DW_ATE_signed_char
:
17313 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17314 || cu
->language
== language_pascal
17315 || cu
->language
== language_fortran
)
17316 type
= init_character_type (objfile
, bits
, 0, name
);
17318 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17320 case DW_ATE_unsigned_char
:
17321 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17322 || cu
->language
== language_pascal
17323 || cu
->language
== language_fortran
17324 || cu
->language
== language_rust
)
17325 type
= init_character_type (objfile
, bits
, 1, name
);
17327 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17332 type
= builtin_type (arch
)->builtin_char16
;
17333 else if (bits
== 32)
17334 type
= builtin_type (arch
)->builtin_char32
;
17337 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17339 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17341 return set_die_type (die
, type
, cu
);
17346 complaint (_("unsupported DW_AT_encoding: '%s'"),
17347 dwarf_type_encoding_name (encoding
));
17348 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17352 if (name
&& strcmp (name
, "char") == 0)
17353 TYPE_NOSIGN (type
) = 1;
17355 maybe_set_alignment (cu
, die
, type
);
17357 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17359 return set_die_type (die
, type
, cu
);
17362 /* Parse dwarf attribute if it's a block, reference or constant and put the
17363 resulting value of the attribute into struct bound_prop.
17364 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17367 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17368 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17369 struct type
*default_type
)
17371 struct dwarf2_property_baton
*baton
;
17372 struct obstack
*obstack
17373 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17375 gdb_assert (default_type
!= NULL
);
17377 if (attr
== NULL
|| prop
== NULL
)
17380 if (attr
->form_is_block ())
17382 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17383 baton
->property_type
= default_type
;
17384 baton
->locexpr
.per_cu
= cu
->per_cu
;
17385 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17386 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17387 switch (attr
->name
)
17389 case DW_AT_string_length
:
17390 baton
->locexpr
.is_reference
= true;
17393 baton
->locexpr
.is_reference
= false;
17396 prop
->data
.baton
= baton
;
17397 prop
->kind
= PROP_LOCEXPR
;
17398 gdb_assert (prop
->data
.baton
!= NULL
);
17400 else if (attr
->form_is_ref ())
17402 struct dwarf2_cu
*target_cu
= cu
;
17403 struct die_info
*target_die
;
17404 struct attribute
*target_attr
;
17406 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17407 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17408 if (target_attr
== NULL
)
17409 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17411 if (target_attr
== NULL
)
17414 switch (target_attr
->name
)
17416 case DW_AT_location
:
17417 if (target_attr
->form_is_section_offset ())
17419 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17420 baton
->property_type
= die_type (target_die
, target_cu
);
17421 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17422 prop
->data
.baton
= baton
;
17423 prop
->kind
= PROP_LOCLIST
;
17424 gdb_assert (prop
->data
.baton
!= NULL
);
17426 else if (target_attr
->form_is_block ())
17428 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17429 baton
->property_type
= die_type (target_die
, target_cu
);
17430 baton
->locexpr
.per_cu
= cu
->per_cu
;
17431 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17432 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17433 baton
->locexpr
.is_reference
= true;
17434 prop
->data
.baton
= baton
;
17435 prop
->kind
= PROP_LOCEXPR
;
17436 gdb_assert (prop
->data
.baton
!= NULL
);
17440 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17441 "dynamic property");
17445 case DW_AT_data_member_location
:
17449 if (!handle_data_member_location (target_die
, target_cu
,
17453 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17454 baton
->property_type
= read_type_die (target_die
->parent
,
17456 baton
->offset_info
.offset
= offset
;
17457 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17458 prop
->data
.baton
= baton
;
17459 prop
->kind
= PROP_ADDR_OFFSET
;
17464 else if (attr
->form_is_constant ())
17466 prop
->data
.const_val
= attr
->constant_value (0);
17467 prop
->kind
= PROP_CONST
;
17471 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17472 dwarf2_name (die
, cu
));
17482 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17484 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17485 struct type
*int_type
;
17487 /* Helper macro to examine the various builtin types. */
17488 #define TRY_TYPE(F) \
17489 int_type = (unsigned_p \
17490 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17491 : objfile_type (objfile)->builtin_ ## F); \
17492 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17499 TRY_TYPE (long_long
);
17503 gdb_assert_not_reached ("unable to find suitable integer type");
17509 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17511 int addr_size
= this->addr_size ();
17512 return int_type (addr_size
, unsigned_p
);
17515 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17516 present (which is valid) then compute the default type based on the
17517 compilation units address size. */
17519 static struct type
*
17520 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17522 struct type
*index_type
= die_type (die
, cu
);
17524 /* Dwarf-2 specifications explicitly allows to create subrange types
17525 without specifying a base type.
17526 In that case, the base type must be set to the type of
17527 the lower bound, upper bound or count, in that order, if any of these
17528 three attributes references an object that has a type.
17529 If no base type is found, the Dwarf-2 specifications say that
17530 a signed integer type of size equal to the size of an address should
17532 For the following C code: `extern char gdb_int [];'
17533 GCC produces an empty range DIE.
17534 FIXME: muller/2010-05-28: Possible references to object for low bound,
17535 high bound or count are not yet handled by this code. */
17536 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17537 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17542 /* Read the given DW_AT_subrange DIE. */
17544 static struct type
*
17545 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17547 struct type
*base_type
, *orig_base_type
;
17548 struct type
*range_type
;
17549 struct attribute
*attr
;
17550 struct dynamic_prop low
, high
;
17551 int low_default_is_valid
;
17552 int high_bound_is_count
= 0;
17554 ULONGEST negative_mask
;
17556 orig_base_type
= read_subrange_index_type (die
, cu
);
17558 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17559 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17560 creating the range type, but we use the result of check_typedef
17561 when examining properties of the type. */
17562 base_type
= check_typedef (orig_base_type
);
17564 /* The die_type call above may have already set the type for this DIE. */
17565 range_type
= get_die_type (die
, cu
);
17569 low
.kind
= PROP_CONST
;
17570 high
.kind
= PROP_CONST
;
17571 high
.data
.const_val
= 0;
17573 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17574 omitting DW_AT_lower_bound. */
17575 switch (cu
->language
)
17578 case language_cplus
:
17579 low
.data
.const_val
= 0;
17580 low_default_is_valid
= 1;
17582 case language_fortran
:
17583 low
.data
.const_val
= 1;
17584 low_default_is_valid
= 1;
17587 case language_objc
:
17588 case language_rust
:
17589 low
.data
.const_val
= 0;
17590 low_default_is_valid
= (cu
->header
.version
>= 4);
17594 case language_pascal
:
17595 low
.data
.const_val
= 1;
17596 low_default_is_valid
= (cu
->header
.version
>= 4);
17599 low
.data
.const_val
= 0;
17600 low_default_is_valid
= 0;
17604 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17605 if (attr
!= nullptr)
17606 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17607 else if (!low_default_is_valid
)
17608 complaint (_("Missing DW_AT_lower_bound "
17609 "- DIE at %s [in module %s]"),
17610 sect_offset_str (die
->sect_off
),
17611 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17613 struct attribute
*attr_ub
, *attr_count
;
17614 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17615 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17617 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17618 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17620 /* If bounds are constant do the final calculation here. */
17621 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17622 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17624 high_bound_is_count
= 1;
17628 if (attr_ub
!= NULL
)
17629 complaint (_("Unresolved DW_AT_upper_bound "
17630 "- DIE at %s [in module %s]"),
17631 sect_offset_str (die
->sect_off
),
17632 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17633 if (attr_count
!= NULL
)
17634 complaint (_("Unresolved DW_AT_count "
17635 "- DIE at %s [in module %s]"),
17636 sect_offset_str (die
->sect_off
),
17637 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17642 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17643 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17644 bias
= bias_attr
->constant_value (0);
17646 /* Normally, the DWARF producers are expected to use a signed
17647 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17648 But this is unfortunately not always the case, as witnessed
17649 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17650 is used instead. To work around that ambiguity, we treat
17651 the bounds as signed, and thus sign-extend their values, when
17652 the base type is signed. */
17654 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17655 if (low
.kind
== PROP_CONST
17656 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17657 low
.data
.const_val
|= negative_mask
;
17658 if (high
.kind
== PROP_CONST
17659 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17660 high
.data
.const_val
|= negative_mask
;
17662 /* Check for bit and byte strides. */
17663 struct dynamic_prop byte_stride_prop
;
17664 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17665 if (attr_byte_stride
!= nullptr)
17667 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17668 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17672 struct dynamic_prop bit_stride_prop
;
17673 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17674 if (attr_bit_stride
!= nullptr)
17676 /* It only makes sense to have either a bit or byte stride. */
17677 if (attr_byte_stride
!= nullptr)
17679 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17680 "- DIE at %s [in module %s]"),
17681 sect_offset_str (die
->sect_off
),
17682 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17683 attr_bit_stride
= nullptr;
17687 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17688 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17693 if (attr_byte_stride
!= nullptr
17694 || attr_bit_stride
!= nullptr)
17696 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17697 struct dynamic_prop
*stride
17698 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17701 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17702 &high
, bias
, stride
, byte_stride_p
);
17705 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17707 if (high_bound_is_count
)
17708 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17710 /* Ada expects an empty array on no boundary attributes. */
17711 if (attr
== NULL
&& cu
->language
!= language_ada
)
17712 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17714 name
= dwarf2_name (die
, cu
);
17716 TYPE_NAME (range_type
) = name
;
17718 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17719 if (attr
!= nullptr)
17720 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17722 maybe_set_alignment (cu
, die
, range_type
);
17724 set_die_type (die
, range_type
, cu
);
17726 /* set_die_type should be already done. */
17727 set_descriptive_type (range_type
, die
, cu
);
17732 static struct type
*
17733 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17737 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17739 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17741 /* In Ada, an unspecified type is typically used when the description
17742 of the type is deferred to a different unit. When encountering
17743 such a type, we treat it as a stub, and try to resolve it later on,
17745 if (cu
->language
== language_ada
)
17746 TYPE_STUB (type
) = 1;
17748 return set_die_type (die
, type
, cu
);
17751 /* Read a single die and all its descendents. Set the die's sibling
17752 field to NULL; set other fields in the die correctly, and set all
17753 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17754 location of the info_ptr after reading all of those dies. PARENT
17755 is the parent of the die in question. */
17757 static struct die_info
*
17758 read_die_and_children (const struct die_reader_specs
*reader
,
17759 const gdb_byte
*info_ptr
,
17760 const gdb_byte
**new_info_ptr
,
17761 struct die_info
*parent
)
17763 struct die_info
*die
;
17764 const gdb_byte
*cur_ptr
;
17766 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17769 *new_info_ptr
= cur_ptr
;
17772 store_in_ref_table (die
, reader
->cu
);
17774 if (die
->has_children
)
17775 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17779 *new_info_ptr
= cur_ptr
;
17782 die
->sibling
= NULL
;
17783 die
->parent
= parent
;
17787 /* Read a die, all of its descendents, and all of its siblings; set
17788 all of the fields of all of the dies correctly. Arguments are as
17789 in read_die_and_children. */
17791 static struct die_info
*
17792 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17793 const gdb_byte
*info_ptr
,
17794 const gdb_byte
**new_info_ptr
,
17795 struct die_info
*parent
)
17797 struct die_info
*first_die
, *last_sibling
;
17798 const gdb_byte
*cur_ptr
;
17800 cur_ptr
= info_ptr
;
17801 first_die
= last_sibling
= NULL
;
17805 struct die_info
*die
17806 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17810 *new_info_ptr
= cur_ptr
;
17817 last_sibling
->sibling
= die
;
17819 last_sibling
= die
;
17823 /* Read a die, all of its descendents, and all of its siblings; set
17824 all of the fields of all of the dies correctly. Arguments are as
17825 in read_die_and_children.
17826 This the main entry point for reading a DIE and all its children. */
17828 static struct die_info
*
17829 read_die_and_siblings (const struct die_reader_specs
*reader
,
17830 const gdb_byte
*info_ptr
,
17831 const gdb_byte
**new_info_ptr
,
17832 struct die_info
*parent
)
17834 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17835 new_info_ptr
, parent
);
17837 if (dwarf_die_debug
)
17839 fprintf_unfiltered (gdb_stdlog
,
17840 "Read die from %s@0x%x of %s:\n",
17841 reader
->die_section
->get_name (),
17842 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17843 bfd_get_filename (reader
->abfd
));
17844 dump_die (die
, dwarf_die_debug
);
17850 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17852 The caller is responsible for filling in the extra attributes
17853 and updating (*DIEP)->num_attrs.
17854 Set DIEP to point to a newly allocated die with its information,
17855 except for its child, sibling, and parent fields. */
17857 static const gdb_byte
*
17858 read_full_die_1 (const struct die_reader_specs
*reader
,
17859 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17860 int num_extra_attrs
)
17862 unsigned int abbrev_number
, bytes_read
, i
;
17863 struct abbrev_info
*abbrev
;
17864 struct die_info
*die
;
17865 struct dwarf2_cu
*cu
= reader
->cu
;
17866 bfd
*abfd
= reader
->abfd
;
17868 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17869 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17870 info_ptr
+= bytes_read
;
17871 if (!abbrev_number
)
17877 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17879 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17881 bfd_get_filename (abfd
));
17883 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17884 die
->sect_off
= sect_off
;
17885 die
->tag
= abbrev
->tag
;
17886 die
->abbrev
= abbrev_number
;
17887 die
->has_children
= abbrev
->has_children
;
17889 /* Make the result usable.
17890 The caller needs to update num_attrs after adding the extra
17892 die
->num_attrs
= abbrev
->num_attrs
;
17894 std::vector
<int> indexes_that_need_reprocess
;
17895 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17897 bool need_reprocess
;
17899 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17900 info_ptr
, &need_reprocess
);
17901 if (need_reprocess
)
17902 indexes_that_need_reprocess
.push_back (i
);
17905 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17906 if (attr
!= nullptr)
17907 cu
->str_offsets_base
= DW_UNSND (attr
);
17909 attr
= die
->attr (DW_AT_loclists_base
);
17910 if (attr
!= nullptr)
17911 cu
->loclist_base
= DW_UNSND (attr
);
17913 auto maybe_addr_base
= die
->addr_base ();
17914 if (maybe_addr_base
.has_value ())
17915 cu
->addr_base
= *maybe_addr_base
;
17916 for (int index
: indexes_that_need_reprocess
)
17917 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17922 /* Read a die and all its attributes.
17923 Set DIEP to point to a newly allocated die with its information,
17924 except for its child, sibling, and parent fields. */
17926 static const gdb_byte
*
17927 read_full_die (const struct die_reader_specs
*reader
,
17928 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17930 const gdb_byte
*result
;
17932 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17934 if (dwarf_die_debug
)
17936 fprintf_unfiltered (gdb_stdlog
,
17937 "Read die from %s@0x%x of %s:\n",
17938 reader
->die_section
->get_name (),
17939 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17940 bfd_get_filename (reader
->abfd
));
17941 dump_die (*diep
, dwarf_die_debug
);
17948 /* Returns nonzero if TAG represents a type that we might generate a partial
17952 is_type_tag_for_partial (int tag
)
17957 /* Some types that would be reasonable to generate partial symbols for,
17958 that we don't at present. */
17959 case DW_TAG_array_type
:
17960 case DW_TAG_file_type
:
17961 case DW_TAG_ptr_to_member_type
:
17962 case DW_TAG_set_type
:
17963 case DW_TAG_string_type
:
17964 case DW_TAG_subroutine_type
:
17966 case DW_TAG_base_type
:
17967 case DW_TAG_class_type
:
17968 case DW_TAG_interface_type
:
17969 case DW_TAG_enumeration_type
:
17970 case DW_TAG_structure_type
:
17971 case DW_TAG_subrange_type
:
17972 case DW_TAG_typedef
:
17973 case DW_TAG_union_type
:
17980 /* Load all DIEs that are interesting for partial symbols into memory. */
17982 static struct partial_die_info
*
17983 load_partial_dies (const struct die_reader_specs
*reader
,
17984 const gdb_byte
*info_ptr
, int building_psymtab
)
17986 struct dwarf2_cu
*cu
= reader
->cu
;
17987 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17988 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17989 unsigned int bytes_read
;
17990 unsigned int load_all
= 0;
17991 int nesting_level
= 1;
17996 gdb_assert (cu
->per_cu
!= NULL
);
17997 if (cu
->per_cu
->load_all_dies
)
18001 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18005 &cu
->comp_unit_obstack
,
18006 hashtab_obstack_allocate
,
18007 dummy_obstack_deallocate
);
18011 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18013 /* A NULL abbrev means the end of a series of children. */
18014 if (abbrev
== NULL
)
18016 if (--nesting_level
== 0)
18019 info_ptr
+= bytes_read
;
18020 last_die
= parent_die
;
18021 parent_die
= parent_die
->die_parent
;
18025 /* Check for template arguments. We never save these; if
18026 they're seen, we just mark the parent, and go on our way. */
18027 if (parent_die
!= NULL
18028 && cu
->language
== language_cplus
18029 && (abbrev
->tag
== DW_TAG_template_type_param
18030 || abbrev
->tag
== DW_TAG_template_value_param
))
18032 parent_die
->has_template_arguments
= 1;
18036 /* We don't need a partial DIE for the template argument. */
18037 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18042 /* We only recurse into c++ subprograms looking for template arguments.
18043 Skip their other children. */
18045 && cu
->language
== language_cplus
18046 && parent_die
!= NULL
18047 && parent_die
->tag
== DW_TAG_subprogram
)
18049 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18053 /* Check whether this DIE is interesting enough to save. Normally
18054 we would not be interested in members here, but there may be
18055 later variables referencing them via DW_AT_specification (for
18056 static members). */
18058 && !is_type_tag_for_partial (abbrev
->tag
)
18059 && abbrev
->tag
!= DW_TAG_constant
18060 && abbrev
->tag
!= DW_TAG_enumerator
18061 && abbrev
->tag
!= DW_TAG_subprogram
18062 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18063 && abbrev
->tag
!= DW_TAG_lexical_block
18064 && abbrev
->tag
!= DW_TAG_variable
18065 && abbrev
->tag
!= DW_TAG_namespace
18066 && abbrev
->tag
!= DW_TAG_module
18067 && abbrev
->tag
!= DW_TAG_member
18068 && abbrev
->tag
!= DW_TAG_imported_unit
18069 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18071 /* Otherwise we skip to the next sibling, if any. */
18072 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18076 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18079 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18081 /* This two-pass algorithm for processing partial symbols has a
18082 high cost in cache pressure. Thus, handle some simple cases
18083 here which cover the majority of C partial symbols. DIEs
18084 which neither have specification tags in them, nor could have
18085 specification tags elsewhere pointing at them, can simply be
18086 processed and discarded.
18088 This segment is also optional; scan_partial_symbols and
18089 add_partial_symbol will handle these DIEs if we chain
18090 them in normally. When compilers which do not emit large
18091 quantities of duplicate debug information are more common,
18092 this code can probably be removed. */
18094 /* Any complete simple types at the top level (pretty much all
18095 of them, for a language without namespaces), can be processed
18097 if (parent_die
== NULL
18098 && pdi
.has_specification
== 0
18099 && pdi
.is_declaration
== 0
18100 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18101 || pdi
.tag
== DW_TAG_base_type
18102 || pdi
.tag
== DW_TAG_subrange_type
))
18104 if (building_psymtab
&& pdi
.name
!= NULL
)
18105 add_psymbol_to_list (pdi
.name
, false,
18106 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18107 psymbol_placement::STATIC
,
18108 0, cu
->language
, objfile
);
18109 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18113 /* The exception for DW_TAG_typedef with has_children above is
18114 a workaround of GCC PR debug/47510. In the case of this complaint
18115 type_name_or_error will error on such types later.
18117 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18118 it could not find the child DIEs referenced later, this is checked
18119 above. In correct DWARF DW_TAG_typedef should have no children. */
18121 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18122 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18123 "- DIE at %s [in module %s]"),
18124 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18126 /* If we're at the second level, and we're an enumerator, and
18127 our parent has no specification (meaning possibly lives in a
18128 namespace elsewhere), then we can add the partial symbol now
18129 instead of queueing it. */
18130 if (pdi
.tag
== DW_TAG_enumerator
18131 && parent_die
!= NULL
18132 && parent_die
->die_parent
== NULL
18133 && parent_die
->tag
== DW_TAG_enumeration_type
18134 && parent_die
->has_specification
== 0)
18136 if (pdi
.name
== NULL
)
18137 complaint (_("malformed enumerator DIE ignored"));
18138 else if (building_psymtab
)
18139 add_psymbol_to_list (pdi
.name
, false,
18140 VAR_DOMAIN
, LOC_CONST
, -1,
18141 cu
->language
== language_cplus
18142 ? psymbol_placement::GLOBAL
18143 : psymbol_placement::STATIC
,
18144 0, cu
->language
, objfile
);
18146 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18150 struct partial_die_info
*part_die
18151 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18153 /* We'll save this DIE so link it in. */
18154 part_die
->die_parent
= parent_die
;
18155 part_die
->die_sibling
= NULL
;
18156 part_die
->die_child
= NULL
;
18158 if (last_die
&& last_die
== parent_die
)
18159 last_die
->die_child
= part_die
;
18161 last_die
->die_sibling
= part_die
;
18163 last_die
= part_die
;
18165 if (first_die
== NULL
)
18166 first_die
= part_die
;
18168 /* Maybe add the DIE to the hash table. Not all DIEs that we
18169 find interesting need to be in the hash table, because we
18170 also have the parent/sibling/child chains; only those that we
18171 might refer to by offset later during partial symbol reading.
18173 For now this means things that might have be the target of a
18174 DW_AT_specification, DW_AT_abstract_origin, or
18175 DW_AT_extension. DW_AT_extension will refer only to
18176 namespaces; DW_AT_abstract_origin refers to functions (and
18177 many things under the function DIE, but we do not recurse
18178 into function DIEs during partial symbol reading) and
18179 possibly variables as well; DW_AT_specification refers to
18180 declarations. Declarations ought to have the DW_AT_declaration
18181 flag. It happens that GCC forgets to put it in sometimes, but
18182 only for functions, not for types.
18184 Adding more things than necessary to the hash table is harmless
18185 except for the performance cost. Adding too few will result in
18186 wasted time in find_partial_die, when we reread the compilation
18187 unit with load_all_dies set. */
18190 || abbrev
->tag
== DW_TAG_constant
18191 || abbrev
->tag
== DW_TAG_subprogram
18192 || abbrev
->tag
== DW_TAG_variable
18193 || abbrev
->tag
== DW_TAG_namespace
18194 || part_die
->is_declaration
)
18198 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18199 to_underlying (part_die
->sect_off
),
18204 /* For some DIEs we want to follow their children (if any). For C
18205 we have no reason to follow the children of structures; for other
18206 languages we have to, so that we can get at method physnames
18207 to infer fully qualified class names, for DW_AT_specification,
18208 and for C++ template arguments. For C++, we also look one level
18209 inside functions to find template arguments (if the name of the
18210 function does not already contain the template arguments).
18212 For Ada and Fortran, we need to scan the children of subprograms
18213 and lexical blocks as well because these languages allow the
18214 definition of nested entities that could be interesting for the
18215 debugger, such as nested subprograms for instance. */
18216 if (last_die
->has_children
18218 || last_die
->tag
== DW_TAG_namespace
18219 || last_die
->tag
== DW_TAG_module
18220 || last_die
->tag
== DW_TAG_enumeration_type
18221 || (cu
->language
== language_cplus
18222 && last_die
->tag
== DW_TAG_subprogram
18223 && (last_die
->name
== NULL
18224 || strchr (last_die
->name
, '<') == NULL
))
18225 || (cu
->language
!= language_c
18226 && (last_die
->tag
== DW_TAG_class_type
18227 || last_die
->tag
== DW_TAG_interface_type
18228 || last_die
->tag
== DW_TAG_structure_type
18229 || last_die
->tag
== DW_TAG_union_type
))
18230 || ((cu
->language
== language_ada
18231 || cu
->language
== language_fortran
)
18232 && (last_die
->tag
== DW_TAG_subprogram
18233 || last_die
->tag
== DW_TAG_lexical_block
))))
18236 parent_die
= last_die
;
18240 /* Otherwise we skip to the next sibling, if any. */
18241 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18243 /* Back to the top, do it again. */
18247 partial_die_info::partial_die_info (sect_offset sect_off_
,
18248 struct abbrev_info
*abbrev
)
18249 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18253 /* Read a minimal amount of information into the minimal die structure.
18254 INFO_PTR should point just after the initial uleb128 of a DIE. */
18257 partial_die_info::read (const struct die_reader_specs
*reader
,
18258 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18260 struct dwarf2_cu
*cu
= reader
->cu
;
18261 struct dwarf2_per_objfile
*dwarf2_per_objfile
18262 = cu
->per_cu
->dwarf2_per_objfile
;
18264 int has_low_pc_attr
= 0;
18265 int has_high_pc_attr
= 0;
18266 int high_pc_relative
= 0;
18268 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18271 bool need_reprocess
;
18272 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18273 info_ptr
, &need_reprocess
);
18274 /* String and address offsets that need to do the reprocessing have
18275 already been read at this point, so there is no need to wait until
18276 the loop terminates to do the reprocessing. */
18277 if (need_reprocess
)
18278 read_attribute_reprocess (reader
, &attr
);
18279 /* Store the data if it is of an attribute we want to keep in a
18280 partial symbol table. */
18286 case DW_TAG_compile_unit
:
18287 case DW_TAG_partial_unit
:
18288 case DW_TAG_type_unit
:
18289 /* Compilation units have a DW_AT_name that is a filename, not
18290 a source language identifier. */
18291 case DW_TAG_enumeration_type
:
18292 case DW_TAG_enumerator
:
18293 /* These tags always have simple identifiers already; no need
18294 to canonicalize them. */
18295 name
= DW_STRING (&attr
);
18299 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18302 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18307 case DW_AT_linkage_name
:
18308 case DW_AT_MIPS_linkage_name
:
18309 /* Note that both forms of linkage name might appear. We
18310 assume they will be the same, and we only store the last
18312 linkage_name
= attr
.value_as_string ();
18313 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18314 See https://github.com/rust-lang/rust/issues/32925. */
18315 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18316 && strchr (linkage_name
, '{') != NULL
)
18317 linkage_name
= NULL
;
18320 has_low_pc_attr
= 1;
18321 lowpc
= attr
.value_as_address ();
18323 case DW_AT_high_pc
:
18324 has_high_pc_attr
= 1;
18325 highpc
= attr
.value_as_address ();
18326 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18327 high_pc_relative
= 1;
18329 case DW_AT_location
:
18330 /* Support the .debug_loc offsets. */
18331 if (attr
.form_is_block ())
18333 d
.locdesc
= DW_BLOCK (&attr
);
18335 else if (attr
.form_is_section_offset ())
18337 dwarf2_complex_location_expr_complaint ();
18341 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18342 "partial symbol information");
18345 case DW_AT_external
:
18346 is_external
= DW_UNSND (&attr
);
18348 case DW_AT_declaration
:
18349 is_declaration
= DW_UNSND (&attr
);
18354 case DW_AT_abstract_origin
:
18355 case DW_AT_specification
:
18356 case DW_AT_extension
:
18357 has_specification
= 1;
18358 spec_offset
= attr
.get_ref_die_offset ();
18359 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18360 || cu
->per_cu
->is_dwz
);
18362 case DW_AT_sibling
:
18363 /* Ignore absolute siblings, they might point outside of
18364 the current compile unit. */
18365 if (attr
.form
== DW_FORM_ref_addr
)
18366 complaint (_("ignoring absolute DW_AT_sibling"));
18369 const gdb_byte
*buffer
= reader
->buffer
;
18370 sect_offset off
= attr
.get_ref_die_offset ();
18371 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18373 if (sibling_ptr
< info_ptr
)
18374 complaint (_("DW_AT_sibling points backwards"));
18375 else if (sibling_ptr
> reader
->buffer_end
)
18376 reader
->die_section
->overflow_complaint ();
18378 sibling
= sibling_ptr
;
18381 case DW_AT_byte_size
:
18384 case DW_AT_const_value
:
18385 has_const_value
= 1;
18387 case DW_AT_calling_convention
:
18388 /* DWARF doesn't provide a way to identify a program's source-level
18389 entry point. DW_AT_calling_convention attributes are only meant
18390 to describe functions' calling conventions.
18392 However, because it's a necessary piece of information in
18393 Fortran, and before DWARF 4 DW_CC_program was the only
18394 piece of debugging information whose definition refers to
18395 a 'main program' at all, several compilers marked Fortran
18396 main programs with DW_CC_program --- even when those
18397 functions use the standard calling conventions.
18399 Although DWARF now specifies a way to provide this
18400 information, we support this practice for backward
18402 if (DW_UNSND (&attr
) == DW_CC_program
18403 && cu
->language
== language_fortran
)
18404 main_subprogram
= 1;
18407 if (DW_UNSND (&attr
) == DW_INL_inlined
18408 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18409 may_be_inlined
= 1;
18413 if (tag
== DW_TAG_imported_unit
)
18415 d
.sect_off
= attr
.get_ref_die_offset ();
18416 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18417 || cu
->per_cu
->is_dwz
);
18421 case DW_AT_main_subprogram
:
18422 main_subprogram
= DW_UNSND (&attr
);
18427 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18428 but that requires a full DIE, so instead we just
18430 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18431 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18432 + (need_ranges_base
18436 /* Value of the DW_AT_ranges attribute is the offset in the
18437 .debug_ranges section. */
18438 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18449 /* For Ada, if both the name and the linkage name appear, we prefer
18450 the latter. This lets "catch exception" work better, regardless
18451 of the order in which the name and linkage name were emitted.
18452 Really, though, this is just a workaround for the fact that gdb
18453 doesn't store both the name and the linkage name. */
18454 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18455 name
= linkage_name
;
18457 if (high_pc_relative
)
18460 if (has_low_pc_attr
&& has_high_pc_attr
)
18462 /* When using the GNU linker, .gnu.linkonce. sections are used to
18463 eliminate duplicate copies of functions and vtables and such.
18464 The linker will arbitrarily choose one and discard the others.
18465 The AT_*_pc values for such functions refer to local labels in
18466 these sections. If the section from that file was discarded, the
18467 labels are not in the output, so the relocs get a value of 0.
18468 If this is a discarded function, mark the pc bounds as invalid,
18469 so that GDB will ignore it. */
18470 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18472 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18473 struct gdbarch
*gdbarch
= objfile
->arch ();
18475 complaint (_("DW_AT_low_pc %s is zero "
18476 "for DIE at %s [in module %s]"),
18477 paddress (gdbarch
, lowpc
),
18478 sect_offset_str (sect_off
),
18479 objfile_name (objfile
));
18481 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18482 else if (lowpc
>= highpc
)
18484 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18485 struct gdbarch
*gdbarch
= objfile
->arch ();
18487 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18488 "for DIE at %s [in module %s]"),
18489 paddress (gdbarch
, lowpc
),
18490 paddress (gdbarch
, highpc
),
18491 sect_offset_str (sect_off
),
18492 objfile_name (objfile
));
18501 /* Find a cached partial DIE at OFFSET in CU. */
18503 struct partial_die_info
*
18504 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18506 struct partial_die_info
*lookup_die
= NULL
;
18507 struct partial_die_info
part_die (sect_off
);
18509 lookup_die
= ((struct partial_die_info
*)
18510 htab_find_with_hash (partial_dies
, &part_die
,
18511 to_underlying (sect_off
)));
18516 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18517 except in the case of .debug_types DIEs which do not reference
18518 outside their CU (they do however referencing other types via
18519 DW_FORM_ref_sig8). */
18521 static const struct cu_partial_die_info
18522 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18524 struct dwarf2_per_objfile
*dwarf2_per_objfile
18525 = cu
->per_cu
->dwarf2_per_objfile
;
18526 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18527 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18528 struct partial_die_info
*pd
= NULL
;
18530 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18531 && cu
->header
.offset_in_cu_p (sect_off
))
18533 pd
= cu
->find_partial_die (sect_off
);
18536 /* We missed recording what we needed.
18537 Load all dies and try again. */
18538 per_cu
= cu
->per_cu
;
18542 /* TUs don't reference other CUs/TUs (except via type signatures). */
18543 if (cu
->per_cu
->is_debug_types
)
18545 error (_("Dwarf Error: Type Unit at offset %s contains"
18546 " external reference to offset %s [in module %s].\n"),
18547 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18548 bfd_get_filename (objfile
->obfd
));
18550 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18551 dwarf2_per_objfile
);
18553 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18554 load_partial_comp_unit (per_cu
);
18556 per_cu
->cu
->last_used
= 0;
18557 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18560 /* If we didn't find it, and not all dies have been loaded,
18561 load them all and try again. */
18563 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18565 per_cu
->load_all_dies
= 1;
18567 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18568 THIS_CU->cu may already be in use. So we can't just free it and
18569 replace its DIEs with the ones we read in. Instead, we leave those
18570 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18571 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18573 load_partial_comp_unit (per_cu
);
18575 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18579 internal_error (__FILE__
, __LINE__
,
18580 _("could not find partial DIE %s "
18581 "in cache [from module %s]\n"),
18582 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18583 return { per_cu
->cu
, pd
};
18586 /* See if we can figure out if the class lives in a namespace. We do
18587 this by looking for a member function; its demangled name will
18588 contain namespace info, if there is any. */
18591 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18592 struct dwarf2_cu
*cu
)
18594 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18595 what template types look like, because the demangler
18596 frequently doesn't give the same name as the debug info. We
18597 could fix this by only using the demangled name to get the
18598 prefix (but see comment in read_structure_type). */
18600 struct partial_die_info
*real_pdi
;
18601 struct partial_die_info
*child_pdi
;
18603 /* If this DIE (this DIE's specification, if any) has a parent, then
18604 we should not do this. We'll prepend the parent's fully qualified
18605 name when we create the partial symbol. */
18607 real_pdi
= struct_pdi
;
18608 while (real_pdi
->has_specification
)
18610 auto res
= find_partial_die (real_pdi
->spec_offset
,
18611 real_pdi
->spec_is_dwz
, cu
);
18612 real_pdi
= res
.pdi
;
18616 if (real_pdi
->die_parent
!= NULL
)
18619 for (child_pdi
= struct_pdi
->die_child
;
18621 child_pdi
= child_pdi
->die_sibling
)
18623 if (child_pdi
->tag
== DW_TAG_subprogram
18624 && child_pdi
->linkage_name
!= NULL
)
18626 gdb::unique_xmalloc_ptr
<char> actual_class_name
18627 (language_class_name_from_physname (cu
->language_defn
,
18628 child_pdi
->linkage_name
));
18629 if (actual_class_name
!= NULL
)
18631 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18632 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18639 /* Return true if a DIE with TAG may have the DW_AT_const_value
18643 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18647 case DW_TAG_constant
:
18648 case DW_TAG_enumerator
:
18649 case DW_TAG_formal_parameter
:
18650 case DW_TAG_template_value_param
:
18651 case DW_TAG_variable
:
18659 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18661 /* Once we've fixed up a die, there's no point in doing so again.
18662 This also avoids a memory leak if we were to call
18663 guess_partial_die_structure_name multiple times. */
18667 /* If we found a reference attribute and the DIE has no name, try
18668 to find a name in the referred to DIE. */
18670 if (name
== NULL
&& has_specification
)
18672 struct partial_die_info
*spec_die
;
18674 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18675 spec_die
= res
.pdi
;
18678 spec_die
->fixup (cu
);
18680 if (spec_die
->name
)
18682 name
= spec_die
->name
;
18684 /* Copy DW_AT_external attribute if it is set. */
18685 if (spec_die
->is_external
)
18686 is_external
= spec_die
->is_external
;
18690 if (!has_const_value
&& has_specification
18691 && can_have_DW_AT_const_value_p (tag
))
18693 struct partial_die_info
*spec_die
;
18695 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18696 spec_die
= res
.pdi
;
18699 spec_die
->fixup (cu
);
18701 if (spec_die
->has_const_value
)
18703 /* Copy DW_AT_const_value attribute if it is set. */
18704 has_const_value
= spec_die
->has_const_value
;
18708 /* Set default names for some unnamed DIEs. */
18710 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18711 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18713 /* If there is no parent die to provide a namespace, and there are
18714 children, see if we can determine the namespace from their linkage
18716 if (cu
->language
== language_cplus
18717 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18718 && die_parent
== NULL
18720 && (tag
== DW_TAG_class_type
18721 || tag
== DW_TAG_structure_type
18722 || tag
== DW_TAG_union_type
))
18723 guess_partial_die_structure_name (this, cu
);
18725 /* GCC might emit a nameless struct or union that has a linkage
18726 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18728 && (tag
== DW_TAG_class_type
18729 || tag
== DW_TAG_interface_type
18730 || tag
== DW_TAG_structure_type
18731 || tag
== DW_TAG_union_type
)
18732 && linkage_name
!= NULL
)
18734 gdb::unique_xmalloc_ptr
<char> demangled
18735 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18736 if (demangled
!= nullptr)
18740 /* Strip any leading namespaces/classes, keep only the base name.
18741 DW_AT_name for named DIEs does not contain the prefixes. */
18742 base
= strrchr (demangled
.get (), ':');
18743 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18746 base
= demangled
.get ();
18748 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18749 name
= objfile
->intern (base
);
18756 /* Read the .debug_loclists header contents from the given SECTION in the
18759 read_loclist_header (struct loclist_header
*header
,
18760 struct dwarf2_section_info
*section
)
18762 unsigned int bytes_read
;
18763 bfd
*abfd
= section
->get_bfd_owner ();
18764 const gdb_byte
*info_ptr
= section
->buffer
;
18765 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18766 info_ptr
+= bytes_read
;
18767 header
->version
= read_2_bytes (abfd
, info_ptr
);
18769 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18771 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18773 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18776 /* Return the DW_AT_loclists_base value for the CU. */
18778 lookup_loclist_base (struct dwarf2_cu
*cu
)
18780 /* For the .dwo unit, the loclist_base points to the first offset following
18781 the header. The header consists of the following entities-
18782 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18784 2. version (2 bytes)
18785 3. address size (1 byte)
18786 4. segment selector size (1 byte)
18787 5. offset entry count (4 bytes)
18788 These sizes are derived as per the DWARFv5 standard. */
18789 if (cu
->dwo_unit
!= nullptr)
18791 if (cu
->header
.initial_length_size
== 4)
18792 return LOCLIST_HEADER_SIZE32
;
18793 return LOCLIST_HEADER_SIZE64
;
18795 return cu
->loclist_base
;
18798 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18799 array of offsets in the .debug_loclists section. */
18801 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18803 struct dwarf2_per_objfile
*dwarf2_per_objfile
18804 = cu
->per_cu
->dwarf2_per_objfile
;
18805 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18806 bfd
*abfd
= objfile
->obfd
;
18807 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18808 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18810 section
->read (objfile
);
18811 if (section
->buffer
== NULL
)
18812 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18813 "section [in module %s]"), objfile_name (objfile
));
18814 struct loclist_header header
;
18815 read_loclist_header (&header
, section
);
18816 if (loclist_index
>= header
.offset_entry_count
)
18817 complaint (_("DW_FORM_loclistx pointing outside of "
18818 ".debug_loclists offset array [in module %s]"),
18819 objfile_name (objfile
));
18820 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18822 complaint (_("DW_FORM_loclistx pointing outside of "
18823 ".debug_loclists section [in module %s]"),
18824 objfile_name (objfile
));
18825 const gdb_byte
*info_ptr
18826 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18828 if (cu
->header
.offset_size
== 4)
18829 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18831 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18834 /* Process the attributes that had to be skipped in the first round. These
18835 attributes are the ones that need str_offsets_base or addr_base attributes.
18836 They could not have been processed in the first round, because at the time
18837 the values of str_offsets_base or addr_base may not have been known. */
18839 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18840 struct attribute
*attr
)
18842 struct dwarf2_cu
*cu
= reader
->cu
;
18843 switch (attr
->form
)
18845 case DW_FORM_addrx
:
18846 case DW_FORM_GNU_addr_index
:
18847 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18849 case DW_FORM_loclistx
:
18850 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
18853 case DW_FORM_strx1
:
18854 case DW_FORM_strx2
:
18855 case DW_FORM_strx3
:
18856 case DW_FORM_strx4
:
18857 case DW_FORM_GNU_str_index
:
18859 unsigned int str_index
= DW_UNSND (attr
);
18860 if (reader
->dwo_file
!= NULL
)
18862 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18863 DW_STRING_IS_CANONICAL (attr
) = 0;
18867 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18868 DW_STRING_IS_CANONICAL (attr
) = 0;
18873 gdb_assert_not_reached (_("Unexpected DWARF form."));
18877 /* Read an attribute value described by an attribute form. */
18879 static const gdb_byte
*
18880 read_attribute_value (const struct die_reader_specs
*reader
,
18881 struct attribute
*attr
, unsigned form
,
18882 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18883 bool *need_reprocess
)
18885 struct dwarf2_cu
*cu
= reader
->cu
;
18886 struct dwarf2_per_objfile
*dwarf2_per_objfile
18887 = cu
->per_cu
->dwarf2_per_objfile
;
18888 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18889 bfd
*abfd
= reader
->abfd
;
18890 struct comp_unit_head
*cu_header
= &cu
->header
;
18891 unsigned int bytes_read
;
18892 struct dwarf_block
*blk
;
18893 *need_reprocess
= false;
18895 attr
->form
= (enum dwarf_form
) form
;
18898 case DW_FORM_ref_addr
:
18899 if (cu
->header
.version
== 2)
18900 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18903 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18905 info_ptr
+= bytes_read
;
18907 case DW_FORM_GNU_ref_alt
:
18908 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18909 info_ptr
+= bytes_read
;
18913 struct gdbarch
*gdbarch
= objfile
->arch ();
18914 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18915 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18916 info_ptr
+= bytes_read
;
18919 case DW_FORM_block2
:
18920 blk
= dwarf_alloc_block (cu
);
18921 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18923 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18924 info_ptr
+= blk
->size
;
18925 DW_BLOCK (attr
) = blk
;
18927 case DW_FORM_block4
:
18928 blk
= dwarf_alloc_block (cu
);
18929 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18931 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18932 info_ptr
+= blk
->size
;
18933 DW_BLOCK (attr
) = blk
;
18935 case DW_FORM_data2
:
18936 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18939 case DW_FORM_data4
:
18940 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18943 case DW_FORM_data8
:
18944 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18947 case DW_FORM_data16
:
18948 blk
= dwarf_alloc_block (cu
);
18950 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18952 DW_BLOCK (attr
) = blk
;
18954 case DW_FORM_sec_offset
:
18955 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18956 info_ptr
+= bytes_read
;
18958 case DW_FORM_loclistx
:
18960 *need_reprocess
= true;
18961 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18962 info_ptr
+= bytes_read
;
18965 case DW_FORM_string
:
18966 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18967 DW_STRING_IS_CANONICAL (attr
) = 0;
18968 info_ptr
+= bytes_read
;
18971 if (!cu
->per_cu
->is_dwz
)
18973 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18974 abfd
, info_ptr
, cu_header
,
18976 DW_STRING_IS_CANONICAL (attr
) = 0;
18977 info_ptr
+= bytes_read
;
18981 case DW_FORM_line_strp
:
18982 if (!cu
->per_cu
->is_dwz
)
18985 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18987 DW_STRING_IS_CANONICAL (attr
) = 0;
18988 info_ptr
+= bytes_read
;
18992 case DW_FORM_GNU_strp_alt
:
18994 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18995 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18998 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18999 DW_STRING_IS_CANONICAL (attr
) = 0;
19000 info_ptr
+= bytes_read
;
19003 case DW_FORM_exprloc
:
19004 case DW_FORM_block
:
19005 blk
= dwarf_alloc_block (cu
);
19006 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19007 info_ptr
+= bytes_read
;
19008 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19009 info_ptr
+= blk
->size
;
19010 DW_BLOCK (attr
) = blk
;
19012 case DW_FORM_block1
:
19013 blk
= dwarf_alloc_block (cu
);
19014 blk
->size
= read_1_byte (abfd
, info_ptr
);
19016 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19017 info_ptr
+= blk
->size
;
19018 DW_BLOCK (attr
) = blk
;
19020 case DW_FORM_data1
:
19021 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19025 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19028 case DW_FORM_flag_present
:
19029 DW_UNSND (attr
) = 1;
19031 case DW_FORM_sdata
:
19032 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19033 info_ptr
+= bytes_read
;
19035 case DW_FORM_udata
:
19036 case DW_FORM_rnglistx
:
19037 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19038 info_ptr
+= bytes_read
;
19041 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19042 + read_1_byte (abfd
, info_ptr
));
19046 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19047 + read_2_bytes (abfd
, info_ptr
));
19051 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19052 + read_4_bytes (abfd
, info_ptr
));
19056 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19057 + read_8_bytes (abfd
, info_ptr
));
19060 case DW_FORM_ref_sig8
:
19061 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19064 case DW_FORM_ref_udata
:
19065 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19066 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19067 info_ptr
+= bytes_read
;
19069 case DW_FORM_indirect
:
19070 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19071 info_ptr
+= bytes_read
;
19072 if (form
== DW_FORM_implicit_const
)
19074 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19075 info_ptr
+= bytes_read
;
19077 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19078 info_ptr
, need_reprocess
);
19080 case DW_FORM_implicit_const
:
19081 DW_SND (attr
) = implicit_const
;
19083 case DW_FORM_addrx
:
19084 case DW_FORM_GNU_addr_index
:
19085 *need_reprocess
= true;
19086 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19087 info_ptr
+= bytes_read
;
19090 case DW_FORM_strx1
:
19091 case DW_FORM_strx2
:
19092 case DW_FORM_strx3
:
19093 case DW_FORM_strx4
:
19094 case DW_FORM_GNU_str_index
:
19096 ULONGEST str_index
;
19097 if (form
== DW_FORM_strx1
)
19099 str_index
= read_1_byte (abfd
, info_ptr
);
19102 else if (form
== DW_FORM_strx2
)
19104 str_index
= read_2_bytes (abfd
, info_ptr
);
19107 else if (form
== DW_FORM_strx3
)
19109 str_index
= read_3_bytes (abfd
, info_ptr
);
19112 else if (form
== DW_FORM_strx4
)
19114 str_index
= read_4_bytes (abfd
, info_ptr
);
19119 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19120 info_ptr
+= bytes_read
;
19122 *need_reprocess
= true;
19123 DW_UNSND (attr
) = str_index
;
19127 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19128 dwarf_form_name (form
),
19129 bfd_get_filename (abfd
));
19133 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19134 attr
->form
= DW_FORM_GNU_ref_alt
;
19136 /* We have seen instances where the compiler tried to emit a byte
19137 size attribute of -1 which ended up being encoded as an unsigned
19138 0xffffffff. Although 0xffffffff is technically a valid size value,
19139 an object of this size seems pretty unlikely so we can relatively
19140 safely treat these cases as if the size attribute was invalid and
19141 treat them as zero by default. */
19142 if (attr
->name
== DW_AT_byte_size
19143 && form
== DW_FORM_data4
19144 && DW_UNSND (attr
) >= 0xffffffff)
19147 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19148 hex_string (DW_UNSND (attr
)));
19149 DW_UNSND (attr
) = 0;
19155 /* Read an attribute described by an abbreviated attribute. */
19157 static const gdb_byte
*
19158 read_attribute (const struct die_reader_specs
*reader
,
19159 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19160 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19162 attr
->name
= abbrev
->name
;
19163 return read_attribute_value (reader
, attr
, abbrev
->form
,
19164 abbrev
->implicit_const
, info_ptr
,
19168 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19170 static const char *
19171 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19172 LONGEST str_offset
)
19174 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
19175 str_offset
, "DW_FORM_strp");
19178 /* Return pointer to string at .debug_str offset as read from BUF.
19179 BUF is assumed to be in a compilation unit described by CU_HEADER.
19180 Return *BYTES_READ_PTR count of bytes read from BUF. */
19182 static const char *
19183 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19184 const gdb_byte
*buf
,
19185 const struct comp_unit_head
*cu_header
,
19186 unsigned int *bytes_read_ptr
)
19188 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19190 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19196 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19197 const struct comp_unit_head
*cu_header
,
19198 unsigned int *bytes_read_ptr
)
19200 bfd
*abfd
= objfile
->obfd
;
19201 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19203 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19206 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19207 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19208 ADDR_SIZE is the size of addresses from the CU header. */
19211 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19212 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19215 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19216 bfd
*abfd
= objfile
->obfd
;
19217 const gdb_byte
*info_ptr
;
19218 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19220 dwarf2_per_objfile
->addr
.read (objfile
);
19221 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19222 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19223 objfile_name (objfile
));
19224 if (addr_base_or_zero
+ addr_index
* addr_size
19225 >= dwarf2_per_objfile
->addr
.size
)
19226 error (_("DW_FORM_addr_index pointing outside of "
19227 ".debug_addr section [in module %s]"),
19228 objfile_name (objfile
));
19229 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19230 + addr_base_or_zero
+ addr_index
* addr_size
);
19231 if (addr_size
== 4)
19232 return bfd_get_32 (abfd
, info_ptr
);
19234 return bfd_get_64 (abfd
, info_ptr
);
19237 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19240 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19242 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19243 cu
->addr_base
, cu
->header
.addr_size
);
19246 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19249 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19250 unsigned int *bytes_read
)
19252 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19253 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19255 return read_addr_index (cu
, addr_index
);
19261 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
19263 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19264 struct dwarf2_cu
*cu
= per_cu
->cu
;
19265 gdb::optional
<ULONGEST
> addr_base
;
19268 /* We need addr_base and addr_size.
19269 If we don't have PER_CU->cu, we have to get it.
19270 Nasty, but the alternative is storing the needed info in PER_CU,
19271 which at this point doesn't seem justified: it's not clear how frequently
19272 it would get used and it would increase the size of every PER_CU.
19273 Entry points like dwarf2_per_cu_addr_size do a similar thing
19274 so we're not in uncharted territory here.
19275 Alas we need to be a bit more complicated as addr_base is contained
19278 We don't need to read the entire CU(/TU).
19279 We just need the header and top level die.
19281 IWBN to use the aging mechanism to let us lazily later discard the CU.
19282 For now we skip this optimization. */
19286 addr_base
= cu
->addr_base
;
19287 addr_size
= cu
->header
.addr_size
;
19291 cutu_reader
reader (per_cu
, NULL
, 0, false);
19292 addr_base
= reader
.cu
->addr_base
;
19293 addr_size
= reader
.cu
->header
.addr_size
;
19296 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19300 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19301 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19304 static const char *
19305 read_str_index (struct dwarf2_cu
*cu
,
19306 struct dwarf2_section_info
*str_section
,
19307 struct dwarf2_section_info
*str_offsets_section
,
19308 ULONGEST str_offsets_base
, ULONGEST str_index
)
19310 struct dwarf2_per_objfile
*dwarf2_per_objfile
19311 = cu
->per_cu
->dwarf2_per_objfile
;
19312 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19313 const char *objf_name
= objfile_name (objfile
);
19314 bfd
*abfd
= objfile
->obfd
;
19315 const gdb_byte
*info_ptr
;
19316 ULONGEST str_offset
;
19317 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19319 str_section
->read (objfile
);
19320 str_offsets_section
->read (objfile
);
19321 if (str_section
->buffer
== NULL
)
19322 error (_("%s used without %s section"
19323 " in CU at offset %s [in module %s]"),
19324 form_name
, str_section
->get_name (),
19325 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19326 if (str_offsets_section
->buffer
== NULL
)
19327 error (_("%s used without %s section"
19328 " in CU at offset %s [in module %s]"),
19329 form_name
, str_section
->get_name (),
19330 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19331 info_ptr
= (str_offsets_section
->buffer
19333 + str_index
* cu
->header
.offset_size
);
19334 if (cu
->header
.offset_size
== 4)
19335 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19337 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19338 if (str_offset
>= str_section
->size
)
19339 error (_("Offset from %s pointing outside of"
19340 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19341 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19342 return (const char *) (str_section
->buffer
+ str_offset
);
19345 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19347 static const char *
19348 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19350 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19351 ? reader
->cu
->header
.addr_size
: 0;
19352 return read_str_index (reader
->cu
,
19353 &reader
->dwo_file
->sections
.str
,
19354 &reader
->dwo_file
->sections
.str_offsets
,
19355 str_offsets_base
, str_index
);
19358 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19360 static const char *
19361 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19363 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19364 const char *objf_name
= objfile_name (objfile
);
19365 static const char form_name
[] = "DW_FORM_GNU_str_index";
19366 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19368 if (!cu
->str_offsets_base
.has_value ())
19369 error (_("%s used in Fission stub without %s"
19370 " in CU at offset 0x%lx [in module %s]"),
19371 form_name
, str_offsets_attr_name
,
19372 (long) cu
->header
.offset_size
, objf_name
);
19374 return read_str_index (cu
,
19375 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19376 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19377 *cu
->str_offsets_base
, str_index
);
19380 /* Return the length of an LEB128 number in BUF. */
19383 leb128_size (const gdb_byte
*buf
)
19385 const gdb_byte
*begin
= buf
;
19391 if ((byte
& 128) == 0)
19392 return buf
- begin
;
19397 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19406 cu
->language
= language_c
;
19409 case DW_LANG_C_plus_plus
:
19410 case DW_LANG_C_plus_plus_11
:
19411 case DW_LANG_C_plus_plus_14
:
19412 cu
->language
= language_cplus
;
19415 cu
->language
= language_d
;
19417 case DW_LANG_Fortran77
:
19418 case DW_LANG_Fortran90
:
19419 case DW_LANG_Fortran95
:
19420 case DW_LANG_Fortran03
:
19421 case DW_LANG_Fortran08
:
19422 cu
->language
= language_fortran
;
19425 cu
->language
= language_go
;
19427 case DW_LANG_Mips_Assembler
:
19428 cu
->language
= language_asm
;
19430 case DW_LANG_Ada83
:
19431 case DW_LANG_Ada95
:
19432 cu
->language
= language_ada
;
19434 case DW_LANG_Modula2
:
19435 cu
->language
= language_m2
;
19437 case DW_LANG_Pascal83
:
19438 cu
->language
= language_pascal
;
19441 cu
->language
= language_objc
;
19444 case DW_LANG_Rust_old
:
19445 cu
->language
= language_rust
;
19447 case DW_LANG_Cobol74
:
19448 case DW_LANG_Cobol85
:
19450 cu
->language
= language_minimal
;
19453 cu
->language_defn
= language_def (cu
->language
);
19456 /* Return the named attribute or NULL if not there. */
19458 static struct attribute
*
19459 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19464 struct attribute
*spec
= NULL
;
19466 for (i
= 0; i
< die
->num_attrs
; ++i
)
19468 if (die
->attrs
[i
].name
== name
)
19469 return &die
->attrs
[i
];
19470 if (die
->attrs
[i
].name
== DW_AT_specification
19471 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19472 spec
= &die
->attrs
[i
];
19478 die
= follow_die_ref (die
, spec
, &cu
);
19484 /* Return the string associated with a string-typed attribute, or NULL if it
19485 is either not found or is of an incorrect type. */
19487 static const char *
19488 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19490 struct attribute
*attr
;
19491 const char *str
= NULL
;
19493 attr
= dwarf2_attr (die
, name
, cu
);
19497 str
= attr
->value_as_string ();
19498 if (str
== nullptr)
19499 complaint (_("string type expected for attribute %s for "
19500 "DIE at %s in module %s"),
19501 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19502 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19508 /* Return the dwo name or NULL if not present. If present, it is in either
19509 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19510 static const char *
19511 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19513 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19514 if (dwo_name
== nullptr)
19515 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19519 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19520 and holds a non-zero value. This function should only be used for
19521 DW_FORM_flag or DW_FORM_flag_present attributes. */
19524 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19526 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19528 return (attr
&& DW_UNSND (attr
));
19532 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19534 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19535 which value is non-zero. However, we have to be careful with
19536 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19537 (via dwarf2_flag_true_p) follows this attribute. So we may
19538 end up accidently finding a declaration attribute that belongs
19539 to a different DIE referenced by the specification attribute,
19540 even though the given DIE does not have a declaration attribute. */
19541 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19542 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19545 /* Return the die giving the specification for DIE, if there is
19546 one. *SPEC_CU is the CU containing DIE on input, and the CU
19547 containing the return value on output. If there is no
19548 specification, but there is an abstract origin, that is
19551 static struct die_info
*
19552 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19554 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19557 if (spec_attr
== NULL
)
19558 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19560 if (spec_attr
== NULL
)
19563 return follow_die_ref (die
, spec_attr
, spec_cu
);
19566 /* Stub for free_line_header to match void * callback types. */
19569 free_line_header_voidp (void *arg
)
19571 struct line_header
*lh
= (struct line_header
*) arg
;
19576 /* A convenience function to find the proper .debug_line section for a CU. */
19578 static struct dwarf2_section_info
*
19579 get_debug_line_section (struct dwarf2_cu
*cu
)
19581 struct dwarf2_section_info
*section
;
19582 struct dwarf2_per_objfile
*dwarf2_per_objfile
19583 = cu
->per_cu
->dwarf2_per_objfile
;
19585 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19587 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19588 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19589 else if (cu
->per_cu
->is_dwz
)
19591 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19593 section
= &dwz
->line
;
19596 section
= &dwarf2_per_objfile
->line
;
19601 /* Read the statement program header starting at OFFSET in
19602 .debug_line, or .debug_line.dwo. Return a pointer
19603 to a struct line_header, allocated using xmalloc.
19604 Returns NULL if there is a problem reading the header, e.g., if it
19605 has a version we don't understand.
19607 NOTE: the strings in the include directory and file name tables of
19608 the returned object point into the dwarf line section buffer,
19609 and must not be freed. */
19611 static line_header_up
19612 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19614 struct dwarf2_section_info
*section
;
19615 struct dwarf2_per_objfile
*dwarf2_per_objfile
19616 = cu
->per_cu
->dwarf2_per_objfile
;
19618 section
= get_debug_line_section (cu
);
19619 section
->read (dwarf2_per_objfile
->objfile
);
19620 if (section
->buffer
== NULL
)
19622 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19623 complaint (_("missing .debug_line.dwo section"));
19625 complaint (_("missing .debug_line section"));
19629 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19630 dwarf2_per_objfile
, section
,
19634 /* Subroutine of dwarf_decode_lines to simplify it.
19635 Return the file name of the psymtab for the given file_entry.
19636 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19637 If space for the result is malloc'd, *NAME_HOLDER will be set.
19638 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19640 static const char *
19641 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19642 const dwarf2_psymtab
*pst
,
19643 const char *comp_dir
,
19644 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19646 const char *include_name
= fe
.name
;
19647 const char *include_name_to_compare
= include_name
;
19648 const char *pst_filename
;
19651 const char *dir_name
= fe
.include_dir (lh
);
19653 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19654 if (!IS_ABSOLUTE_PATH (include_name
)
19655 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19657 /* Avoid creating a duplicate psymtab for PST.
19658 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19659 Before we do the comparison, however, we need to account
19660 for DIR_NAME and COMP_DIR.
19661 First prepend dir_name (if non-NULL). If we still don't
19662 have an absolute path prepend comp_dir (if non-NULL).
19663 However, the directory we record in the include-file's
19664 psymtab does not contain COMP_DIR (to match the
19665 corresponding symtab(s)).
19670 bash$ gcc -g ./hello.c
19671 include_name = "hello.c"
19673 DW_AT_comp_dir = comp_dir = "/tmp"
19674 DW_AT_name = "./hello.c"
19678 if (dir_name
!= NULL
)
19680 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19681 include_name
, (char *) NULL
));
19682 include_name
= name_holder
->get ();
19683 include_name_to_compare
= include_name
;
19685 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19687 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19688 include_name
, (char *) NULL
));
19689 include_name_to_compare
= hold_compare
.get ();
19693 pst_filename
= pst
->filename
;
19694 gdb::unique_xmalloc_ptr
<char> copied_name
;
19695 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19697 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19698 pst_filename
, (char *) NULL
));
19699 pst_filename
= copied_name
.get ();
19702 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19706 return include_name
;
19709 /* State machine to track the state of the line number program. */
19711 class lnp_state_machine
19714 /* Initialize a machine state for the start of a line number
19716 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19717 bool record_lines_p
);
19719 file_entry
*current_file ()
19721 /* lh->file_names is 0-based, but the file name numbers in the
19722 statement program are 1-based. */
19723 return m_line_header
->file_name_at (m_file
);
19726 /* Record the line in the state machine. END_SEQUENCE is true if
19727 we're processing the end of a sequence. */
19728 void record_line (bool end_sequence
);
19730 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19731 nop-out rest of the lines in this sequence. */
19732 void check_line_address (struct dwarf2_cu
*cu
,
19733 const gdb_byte
*line_ptr
,
19734 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19736 void handle_set_discriminator (unsigned int discriminator
)
19738 m_discriminator
= discriminator
;
19739 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19742 /* Handle DW_LNE_set_address. */
19743 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19746 address
+= baseaddr
;
19747 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19750 /* Handle DW_LNS_advance_pc. */
19751 void handle_advance_pc (CORE_ADDR adjust
);
19753 /* Handle a special opcode. */
19754 void handle_special_opcode (unsigned char op_code
);
19756 /* Handle DW_LNS_advance_line. */
19757 void handle_advance_line (int line_delta
)
19759 advance_line (line_delta
);
19762 /* Handle DW_LNS_set_file. */
19763 void handle_set_file (file_name_index file
);
19765 /* Handle DW_LNS_negate_stmt. */
19766 void handle_negate_stmt ()
19768 m_is_stmt
= !m_is_stmt
;
19771 /* Handle DW_LNS_const_add_pc. */
19772 void handle_const_add_pc ();
19774 /* Handle DW_LNS_fixed_advance_pc. */
19775 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19777 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19781 /* Handle DW_LNS_copy. */
19782 void handle_copy ()
19784 record_line (false);
19785 m_discriminator
= 0;
19788 /* Handle DW_LNE_end_sequence. */
19789 void handle_end_sequence ()
19791 m_currently_recording_lines
= true;
19795 /* Advance the line by LINE_DELTA. */
19796 void advance_line (int line_delta
)
19798 m_line
+= line_delta
;
19800 if (line_delta
!= 0)
19801 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19804 struct dwarf2_cu
*m_cu
;
19806 gdbarch
*m_gdbarch
;
19808 /* True if we're recording lines.
19809 Otherwise we're building partial symtabs and are just interested in
19810 finding include files mentioned by the line number program. */
19811 bool m_record_lines_p
;
19813 /* The line number header. */
19814 line_header
*m_line_header
;
19816 /* These are part of the standard DWARF line number state machine,
19817 and initialized according to the DWARF spec. */
19819 unsigned char m_op_index
= 0;
19820 /* The line table index of the current file. */
19821 file_name_index m_file
= 1;
19822 unsigned int m_line
= 1;
19824 /* These are initialized in the constructor. */
19826 CORE_ADDR m_address
;
19828 unsigned int m_discriminator
;
19830 /* Additional bits of state we need to track. */
19832 /* The last file that we called dwarf2_start_subfile for.
19833 This is only used for TLLs. */
19834 unsigned int m_last_file
= 0;
19835 /* The last file a line number was recorded for. */
19836 struct subfile
*m_last_subfile
= NULL
;
19838 /* When true, record the lines we decode. */
19839 bool m_currently_recording_lines
= false;
19841 /* The last line number that was recorded, used to coalesce
19842 consecutive entries for the same line. This can happen, for
19843 example, when discriminators are present. PR 17276. */
19844 unsigned int m_last_line
= 0;
19845 bool m_line_has_non_zero_discriminator
= false;
19849 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19851 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19852 / m_line_header
->maximum_ops_per_instruction
)
19853 * m_line_header
->minimum_instruction_length
);
19854 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19855 m_op_index
= ((m_op_index
+ adjust
)
19856 % m_line_header
->maximum_ops_per_instruction
);
19860 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19862 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19863 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19864 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19865 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19866 / m_line_header
->maximum_ops_per_instruction
)
19867 * m_line_header
->minimum_instruction_length
);
19868 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19869 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19870 % m_line_header
->maximum_ops_per_instruction
);
19872 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19873 advance_line (line_delta
);
19874 record_line (false);
19875 m_discriminator
= 0;
19879 lnp_state_machine::handle_set_file (file_name_index file
)
19883 const file_entry
*fe
= current_file ();
19885 dwarf2_debug_line_missing_file_complaint ();
19886 else if (m_record_lines_p
)
19888 const char *dir
= fe
->include_dir (m_line_header
);
19890 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19891 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19892 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19897 lnp_state_machine::handle_const_add_pc ()
19900 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19903 = (((m_op_index
+ adjust
)
19904 / m_line_header
->maximum_ops_per_instruction
)
19905 * m_line_header
->minimum_instruction_length
);
19907 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19908 m_op_index
= ((m_op_index
+ adjust
)
19909 % m_line_header
->maximum_ops_per_instruction
);
19912 /* Return non-zero if we should add LINE to the line number table.
19913 LINE is the line to add, LAST_LINE is the last line that was added,
19914 LAST_SUBFILE is the subfile for LAST_LINE.
19915 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19916 had a non-zero discriminator.
19918 We have to be careful in the presence of discriminators.
19919 E.g., for this line:
19921 for (i = 0; i < 100000; i++);
19923 clang can emit four line number entries for that one line,
19924 each with a different discriminator.
19925 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19927 However, we want gdb to coalesce all four entries into one.
19928 Otherwise the user could stepi into the middle of the line and
19929 gdb would get confused about whether the pc really was in the
19930 middle of the line.
19932 Things are further complicated by the fact that two consecutive
19933 line number entries for the same line is a heuristic used by gcc
19934 to denote the end of the prologue. So we can't just discard duplicate
19935 entries, we have to be selective about it. The heuristic we use is
19936 that we only collapse consecutive entries for the same line if at least
19937 one of those entries has a non-zero discriminator. PR 17276.
19939 Note: Addresses in the line number state machine can never go backwards
19940 within one sequence, thus this coalescing is ok. */
19943 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19944 unsigned int line
, unsigned int last_line
,
19945 int line_has_non_zero_discriminator
,
19946 struct subfile
*last_subfile
)
19948 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19950 if (line
!= last_line
)
19952 /* Same line for the same file that we've seen already.
19953 As a last check, for pr 17276, only record the line if the line
19954 has never had a non-zero discriminator. */
19955 if (!line_has_non_zero_discriminator
)
19960 /* Use the CU's builder to record line number LINE beginning at
19961 address ADDRESS in the line table of subfile SUBFILE. */
19964 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19965 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19966 struct dwarf2_cu
*cu
)
19968 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19970 if (dwarf_line_debug
)
19972 fprintf_unfiltered (gdb_stdlog
,
19973 "Recording line %u, file %s, address %s\n",
19974 line
, lbasename (subfile
->name
),
19975 paddress (gdbarch
, address
));
19979 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19982 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19983 Mark the end of a set of line number records.
19984 The arguments are the same as for dwarf_record_line_1.
19985 If SUBFILE is NULL the request is ignored. */
19988 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19989 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19991 if (subfile
== NULL
)
19994 if (dwarf_line_debug
)
19996 fprintf_unfiltered (gdb_stdlog
,
19997 "Finishing current line, file %s, address %s\n",
19998 lbasename (subfile
->name
),
19999 paddress (gdbarch
, address
));
20002 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20006 lnp_state_machine::record_line (bool end_sequence
)
20008 if (dwarf_line_debug
)
20010 fprintf_unfiltered (gdb_stdlog
,
20011 "Processing actual line %u: file %u,"
20012 " address %s, is_stmt %u, discrim %u%s\n",
20014 paddress (m_gdbarch
, m_address
),
20015 m_is_stmt
, m_discriminator
,
20016 (end_sequence
? "\t(end sequence)" : ""));
20019 file_entry
*fe
= current_file ();
20022 dwarf2_debug_line_missing_file_complaint ();
20023 /* For now we ignore lines not starting on an instruction boundary.
20024 But not when processing end_sequence for compatibility with the
20025 previous version of the code. */
20026 else if (m_op_index
== 0 || end_sequence
)
20028 fe
->included_p
= 1;
20029 if (m_record_lines_p
)
20031 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20034 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20035 m_currently_recording_lines
? m_cu
: nullptr);
20040 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20042 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20043 m_line_has_non_zero_discriminator
,
20046 buildsym_compunit
*builder
= m_cu
->get_builder ();
20047 dwarf_record_line_1 (m_gdbarch
,
20048 builder
->get_current_subfile (),
20049 m_line
, m_address
, is_stmt
,
20050 m_currently_recording_lines
? m_cu
: nullptr);
20052 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20053 m_last_line
= m_line
;
20059 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20060 line_header
*lh
, bool record_lines_p
)
20064 m_record_lines_p
= record_lines_p
;
20065 m_line_header
= lh
;
20067 m_currently_recording_lines
= true;
20069 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20070 was a line entry for it so that the backend has a chance to adjust it
20071 and also record it in case it needs it. This is currently used by MIPS
20072 code, cf. `mips_adjust_dwarf2_line'. */
20073 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20074 m_is_stmt
= lh
->default_is_stmt
;
20075 m_discriminator
= 0;
20079 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20080 const gdb_byte
*line_ptr
,
20081 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20083 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20084 the pc range of the CU. However, we restrict the test to only ADDRESS
20085 values of zero to preserve GDB's previous behaviour which is to handle
20086 the specific case of a function being GC'd by the linker. */
20088 if (address
== 0 && address
< unrelocated_lowpc
)
20090 /* This line table is for a function which has been
20091 GCd by the linker. Ignore it. PR gdb/12528 */
20093 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20094 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20096 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20097 line_offset
, objfile_name (objfile
));
20098 m_currently_recording_lines
= false;
20099 /* Note: m_currently_recording_lines is left as false until we see
20100 DW_LNE_end_sequence. */
20104 /* Subroutine of dwarf_decode_lines to simplify it.
20105 Process the line number information in LH.
20106 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20107 program in order to set included_p for every referenced header. */
20110 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20111 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20113 const gdb_byte
*line_ptr
, *extended_end
;
20114 const gdb_byte
*line_end
;
20115 unsigned int bytes_read
, extended_len
;
20116 unsigned char op_code
, extended_op
;
20117 CORE_ADDR baseaddr
;
20118 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20119 bfd
*abfd
= objfile
->obfd
;
20120 struct gdbarch
*gdbarch
= objfile
->arch ();
20121 /* True if we're recording line info (as opposed to building partial
20122 symtabs and just interested in finding include files mentioned by
20123 the line number program). */
20124 bool record_lines_p
= !decode_for_pst_p
;
20126 baseaddr
= objfile
->text_section_offset ();
20128 line_ptr
= lh
->statement_program_start
;
20129 line_end
= lh
->statement_program_end
;
20131 /* Read the statement sequences until there's nothing left. */
20132 while (line_ptr
< line_end
)
20134 /* The DWARF line number program state machine. Reset the state
20135 machine at the start of each sequence. */
20136 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20137 bool end_sequence
= false;
20139 if (record_lines_p
)
20141 /* Start a subfile for the current file of the state
20143 const file_entry
*fe
= state_machine
.current_file ();
20146 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20149 /* Decode the table. */
20150 while (line_ptr
< line_end
&& !end_sequence
)
20152 op_code
= read_1_byte (abfd
, line_ptr
);
20155 if (op_code
>= lh
->opcode_base
)
20157 /* Special opcode. */
20158 state_machine
.handle_special_opcode (op_code
);
20160 else switch (op_code
)
20162 case DW_LNS_extended_op
:
20163 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20165 line_ptr
+= bytes_read
;
20166 extended_end
= line_ptr
+ extended_len
;
20167 extended_op
= read_1_byte (abfd
, line_ptr
);
20169 switch (extended_op
)
20171 case DW_LNE_end_sequence
:
20172 state_machine
.handle_end_sequence ();
20173 end_sequence
= true;
20175 case DW_LNE_set_address
:
20178 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20179 line_ptr
+= bytes_read
;
20181 state_machine
.check_line_address (cu
, line_ptr
,
20182 lowpc
- baseaddr
, address
);
20183 state_machine
.handle_set_address (baseaddr
, address
);
20186 case DW_LNE_define_file
:
20188 const char *cur_file
;
20189 unsigned int mod_time
, length
;
20192 cur_file
= read_direct_string (abfd
, line_ptr
,
20194 line_ptr
+= bytes_read
;
20195 dindex
= (dir_index
)
20196 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20197 line_ptr
+= bytes_read
;
20199 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20200 line_ptr
+= bytes_read
;
20202 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20203 line_ptr
+= bytes_read
;
20204 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20207 case DW_LNE_set_discriminator
:
20209 /* The discriminator is not interesting to the
20210 debugger; just ignore it. We still need to
20211 check its value though:
20212 if there are consecutive entries for the same
20213 (non-prologue) line we want to coalesce them.
20216 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20217 line_ptr
+= bytes_read
;
20219 state_machine
.handle_set_discriminator (discr
);
20223 complaint (_("mangled .debug_line section"));
20226 /* Make sure that we parsed the extended op correctly. If e.g.
20227 we expected a different address size than the producer used,
20228 we may have read the wrong number of bytes. */
20229 if (line_ptr
!= extended_end
)
20231 complaint (_("mangled .debug_line section"));
20236 state_machine
.handle_copy ();
20238 case DW_LNS_advance_pc
:
20241 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20242 line_ptr
+= bytes_read
;
20244 state_machine
.handle_advance_pc (adjust
);
20247 case DW_LNS_advance_line
:
20250 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20251 line_ptr
+= bytes_read
;
20253 state_machine
.handle_advance_line (line_delta
);
20256 case DW_LNS_set_file
:
20258 file_name_index file
20259 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20261 line_ptr
+= bytes_read
;
20263 state_machine
.handle_set_file (file
);
20266 case DW_LNS_set_column
:
20267 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20268 line_ptr
+= bytes_read
;
20270 case DW_LNS_negate_stmt
:
20271 state_machine
.handle_negate_stmt ();
20273 case DW_LNS_set_basic_block
:
20275 /* Add to the address register of the state machine the
20276 address increment value corresponding to special opcode
20277 255. I.e., this value is scaled by the minimum
20278 instruction length since special opcode 255 would have
20279 scaled the increment. */
20280 case DW_LNS_const_add_pc
:
20281 state_machine
.handle_const_add_pc ();
20283 case DW_LNS_fixed_advance_pc
:
20285 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20288 state_machine
.handle_fixed_advance_pc (addr_adj
);
20293 /* Unknown standard opcode, ignore it. */
20296 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20298 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20299 line_ptr
+= bytes_read
;
20306 dwarf2_debug_line_missing_end_sequence_complaint ();
20308 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20309 in which case we still finish recording the last line). */
20310 state_machine
.record_line (true);
20314 /* Decode the Line Number Program (LNP) for the given line_header
20315 structure and CU. The actual information extracted and the type
20316 of structures created from the LNP depends on the value of PST.
20318 1. If PST is NULL, then this procedure uses the data from the program
20319 to create all necessary symbol tables, and their linetables.
20321 2. If PST is not NULL, this procedure reads the program to determine
20322 the list of files included by the unit represented by PST, and
20323 builds all the associated partial symbol tables.
20325 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20326 It is used for relative paths in the line table.
20327 NOTE: When processing partial symtabs (pst != NULL),
20328 comp_dir == pst->dirname.
20330 NOTE: It is important that psymtabs have the same file name (via strcmp)
20331 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20332 symtab we don't use it in the name of the psymtabs we create.
20333 E.g. expand_line_sal requires this when finding psymtabs to expand.
20334 A good testcase for this is mb-inline.exp.
20336 LOWPC is the lowest address in CU (or 0 if not known).
20338 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20339 for its PC<->lines mapping information. Otherwise only the filename
20340 table is read in. */
20343 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20344 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20345 CORE_ADDR lowpc
, int decode_mapping
)
20347 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20348 const int decode_for_pst_p
= (pst
!= NULL
);
20350 if (decode_mapping
)
20351 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20353 if (decode_for_pst_p
)
20355 /* Now that we're done scanning the Line Header Program, we can
20356 create the psymtab of each included file. */
20357 for (auto &file_entry
: lh
->file_names ())
20358 if (file_entry
.included_p
== 1)
20360 gdb::unique_xmalloc_ptr
<char> name_holder
;
20361 const char *include_name
=
20362 psymtab_include_file_name (lh
, file_entry
, pst
,
20363 comp_dir
, &name_holder
);
20364 if (include_name
!= NULL
)
20365 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20370 /* Make sure a symtab is created for every file, even files
20371 which contain only variables (i.e. no code with associated
20373 buildsym_compunit
*builder
= cu
->get_builder ();
20374 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20376 for (auto &fe
: lh
->file_names ())
20378 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20379 if (builder
->get_current_subfile ()->symtab
== NULL
)
20381 builder
->get_current_subfile ()->symtab
20382 = allocate_symtab (cust
,
20383 builder
->get_current_subfile ()->name
);
20385 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20390 /* Start a subfile for DWARF. FILENAME is the name of the file and
20391 DIRNAME the name of the source directory which contains FILENAME
20392 or NULL if not known.
20393 This routine tries to keep line numbers from identical absolute and
20394 relative file names in a common subfile.
20396 Using the `list' example from the GDB testsuite, which resides in
20397 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20398 of /srcdir/list0.c yields the following debugging information for list0.c:
20400 DW_AT_name: /srcdir/list0.c
20401 DW_AT_comp_dir: /compdir
20402 files.files[0].name: list0.h
20403 files.files[0].dir: /srcdir
20404 files.files[1].name: list0.c
20405 files.files[1].dir: /srcdir
20407 The line number information for list0.c has to end up in a single
20408 subfile, so that `break /srcdir/list0.c:1' works as expected.
20409 start_subfile will ensure that this happens provided that we pass the
20410 concatenation of files.files[1].dir and files.files[1].name as the
20414 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20415 const char *dirname
)
20417 gdb::unique_xmalloc_ptr
<char> copy
;
20419 /* In order not to lose the line information directory,
20420 we concatenate it to the filename when it makes sense.
20421 Note that the Dwarf3 standard says (speaking of filenames in line
20422 information): ``The directory index is ignored for file names
20423 that represent full path names''. Thus ignoring dirname in the
20424 `else' branch below isn't an issue. */
20426 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20428 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20429 filename
= copy
.get ();
20432 cu
->get_builder ()->start_subfile (filename
);
20435 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20436 buildsym_compunit constructor. */
20438 struct compunit_symtab
*
20439 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20442 gdb_assert (m_builder
== nullptr);
20444 m_builder
.reset (new struct buildsym_compunit
20445 (per_cu
->dwarf2_per_objfile
->objfile
,
20446 name
, comp_dir
, language
, low_pc
));
20448 list_in_scope
= get_builder ()->get_file_symbols ();
20450 get_builder ()->record_debugformat ("DWARF 2");
20451 get_builder ()->record_producer (producer
);
20453 processing_has_namespace_info
= false;
20455 return get_builder ()->get_compunit_symtab ();
20459 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20460 struct dwarf2_cu
*cu
)
20462 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20463 struct comp_unit_head
*cu_header
= &cu
->header
;
20465 /* NOTE drow/2003-01-30: There used to be a comment and some special
20466 code here to turn a symbol with DW_AT_external and a
20467 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20468 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20469 with some versions of binutils) where shared libraries could have
20470 relocations against symbols in their debug information - the
20471 minimal symbol would have the right address, but the debug info
20472 would not. It's no longer necessary, because we will explicitly
20473 apply relocations when we read in the debug information now. */
20475 /* A DW_AT_location attribute with no contents indicates that a
20476 variable has been optimized away. */
20477 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20479 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20483 /* Handle one degenerate form of location expression specially, to
20484 preserve GDB's previous behavior when section offsets are
20485 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20486 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20488 if (attr
->form_is_block ()
20489 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20490 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20491 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20492 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20493 && (DW_BLOCK (attr
)->size
20494 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20496 unsigned int dummy
;
20498 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20499 SET_SYMBOL_VALUE_ADDRESS
20500 (sym
, cu
->header
.read_address (objfile
->obfd
,
20501 DW_BLOCK (attr
)->data
+ 1,
20504 SET_SYMBOL_VALUE_ADDRESS
20505 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20507 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20508 fixup_symbol_section (sym
, objfile
);
20509 SET_SYMBOL_VALUE_ADDRESS
20511 SYMBOL_VALUE_ADDRESS (sym
)
20512 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20516 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20517 expression evaluator, and use LOC_COMPUTED only when necessary
20518 (i.e. when the value of a register or memory location is
20519 referenced, or a thread-local block, etc.). Then again, it might
20520 not be worthwhile. I'm assuming that it isn't unless performance
20521 or memory numbers show me otherwise. */
20523 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20525 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20526 cu
->has_loclist
= true;
20529 /* Given a pointer to a DWARF information entry, figure out if we need
20530 to make a symbol table entry for it, and if so, create a new entry
20531 and return a pointer to it.
20532 If TYPE is NULL, determine symbol type from the die, otherwise
20533 used the passed type.
20534 If SPACE is not NULL, use it to hold the new symbol. If it is
20535 NULL, allocate a new symbol on the objfile's obstack. */
20537 static struct symbol
*
20538 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20539 struct symbol
*space
)
20541 struct dwarf2_per_objfile
*dwarf2_per_objfile
20542 = cu
->per_cu
->dwarf2_per_objfile
;
20543 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20544 struct gdbarch
*gdbarch
= objfile
->arch ();
20545 struct symbol
*sym
= NULL
;
20547 struct attribute
*attr
= NULL
;
20548 struct attribute
*attr2
= NULL
;
20549 CORE_ADDR baseaddr
;
20550 struct pending
**list_to_add
= NULL
;
20552 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20554 baseaddr
= objfile
->text_section_offset ();
20556 name
= dwarf2_name (die
, cu
);
20559 int suppress_add
= 0;
20564 sym
= allocate_symbol (objfile
);
20565 OBJSTAT (objfile
, n_syms
++);
20567 /* Cache this symbol's name and the name's demangled form (if any). */
20568 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20569 /* Fortran does not have mangling standard and the mangling does differ
20570 between gfortran, iFort etc. */
20571 const char *physname
20572 = (cu
->language
== language_fortran
20573 ? dwarf2_full_name (name
, die
, cu
)
20574 : dwarf2_physname (name
, die
, cu
));
20575 const char *linkagename
= dw2_linkage_name (die
, cu
);
20577 if (linkagename
== nullptr || cu
->language
== language_ada
)
20578 sym
->set_linkage_name (physname
);
20581 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20582 sym
->set_linkage_name (linkagename
);
20585 /* Default assumptions.
20586 Use the passed type or decode it from the die. */
20587 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20588 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20590 SYMBOL_TYPE (sym
) = type
;
20592 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20593 attr
= dwarf2_attr (die
,
20594 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20596 if (attr
!= nullptr)
20598 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20601 attr
= dwarf2_attr (die
,
20602 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20604 if (attr
!= nullptr)
20606 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20607 struct file_entry
*fe
;
20609 if (cu
->line_header
!= NULL
)
20610 fe
= cu
->line_header
->file_name_at (file_index
);
20615 complaint (_("file index out of range"));
20617 symbol_set_symtab (sym
, fe
->symtab
);
20623 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20624 if (attr
!= nullptr)
20628 addr
= attr
->value_as_address ();
20629 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20630 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20632 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20633 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20634 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20635 add_symbol_to_list (sym
, cu
->list_in_scope
);
20637 case DW_TAG_subprogram
:
20638 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20640 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20641 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20642 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20643 || cu
->language
== language_ada
20644 || cu
->language
== language_fortran
)
20646 /* Subprograms marked external are stored as a global symbol.
20647 Ada and Fortran subprograms, whether marked external or
20648 not, are always stored as a global symbol, because we want
20649 to be able to access them globally. For instance, we want
20650 to be able to break on a nested subprogram without having
20651 to specify the context. */
20652 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20656 list_to_add
= cu
->list_in_scope
;
20659 case DW_TAG_inlined_subroutine
:
20660 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20662 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20663 SYMBOL_INLINED (sym
) = 1;
20664 list_to_add
= cu
->list_in_scope
;
20666 case DW_TAG_template_value_param
:
20668 /* Fall through. */
20669 case DW_TAG_constant
:
20670 case DW_TAG_variable
:
20671 case DW_TAG_member
:
20672 /* Compilation with minimal debug info may result in
20673 variables with missing type entries. Change the
20674 misleading `void' type to something sensible. */
20675 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20676 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20678 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20679 /* In the case of DW_TAG_member, we should only be called for
20680 static const members. */
20681 if (die
->tag
== DW_TAG_member
)
20683 /* dwarf2_add_field uses die_is_declaration,
20684 so we do the same. */
20685 gdb_assert (die_is_declaration (die
, cu
));
20688 if (attr
!= nullptr)
20690 dwarf2_const_value (attr
, sym
, cu
);
20691 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20694 if (attr2
&& (DW_UNSND (attr2
) != 0))
20695 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20697 list_to_add
= cu
->list_in_scope
;
20701 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20702 if (attr
!= nullptr)
20704 var_decode_location (attr
, sym
, cu
);
20705 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20707 /* Fortran explicitly imports any global symbols to the local
20708 scope by DW_TAG_common_block. */
20709 if (cu
->language
== language_fortran
&& die
->parent
20710 && die
->parent
->tag
== DW_TAG_common_block
)
20713 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20714 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20715 && !dwarf2_per_objfile
->has_section_at_zero
)
20717 /* When a static variable is eliminated by the linker,
20718 the corresponding debug information is not stripped
20719 out, but the variable address is set to null;
20720 do not add such variables into symbol table. */
20722 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20724 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20725 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20726 && dwarf2_per_objfile
->can_copy
)
20728 /* A global static variable might be subject to
20729 copy relocation. We first check for a local
20730 minsym, though, because maybe the symbol was
20731 marked hidden, in which case this would not
20733 bound_minimal_symbol found
20734 = (lookup_minimal_symbol_linkage
20735 (sym
->linkage_name (), objfile
));
20736 if (found
.minsym
!= nullptr)
20737 sym
->maybe_copied
= 1;
20740 /* A variable with DW_AT_external is never static,
20741 but it may be block-scoped. */
20743 = ((cu
->list_in_scope
20744 == cu
->get_builder ()->get_file_symbols ())
20745 ? cu
->get_builder ()->get_global_symbols ()
20746 : cu
->list_in_scope
);
20749 list_to_add
= cu
->list_in_scope
;
20753 /* We do not know the address of this symbol.
20754 If it is an external symbol and we have type information
20755 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20756 The address of the variable will then be determined from
20757 the minimal symbol table whenever the variable is
20759 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20761 /* Fortran explicitly imports any global symbols to the local
20762 scope by DW_TAG_common_block. */
20763 if (cu
->language
== language_fortran
&& die
->parent
20764 && die
->parent
->tag
== DW_TAG_common_block
)
20766 /* SYMBOL_CLASS doesn't matter here because
20767 read_common_block is going to reset it. */
20769 list_to_add
= cu
->list_in_scope
;
20771 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20772 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20774 /* A variable with DW_AT_external is never static, but it
20775 may be block-scoped. */
20777 = ((cu
->list_in_scope
20778 == cu
->get_builder ()->get_file_symbols ())
20779 ? cu
->get_builder ()->get_global_symbols ()
20780 : cu
->list_in_scope
);
20782 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20784 else if (!die_is_declaration (die
, cu
))
20786 /* Use the default LOC_OPTIMIZED_OUT class. */
20787 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20789 list_to_add
= cu
->list_in_scope
;
20793 case DW_TAG_formal_parameter
:
20795 /* If we are inside a function, mark this as an argument. If
20796 not, we might be looking at an argument to an inlined function
20797 when we do not have enough information to show inlined frames;
20798 pretend it's a local variable in that case so that the user can
20800 struct context_stack
*curr
20801 = cu
->get_builder ()->get_current_context_stack ();
20802 if (curr
!= nullptr && curr
->name
!= nullptr)
20803 SYMBOL_IS_ARGUMENT (sym
) = 1;
20804 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20805 if (attr
!= nullptr)
20807 var_decode_location (attr
, sym
, cu
);
20809 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20810 if (attr
!= nullptr)
20812 dwarf2_const_value (attr
, sym
, cu
);
20815 list_to_add
= cu
->list_in_scope
;
20818 case DW_TAG_unspecified_parameters
:
20819 /* From varargs functions; gdb doesn't seem to have any
20820 interest in this information, so just ignore it for now.
20823 case DW_TAG_template_type_param
:
20825 /* Fall through. */
20826 case DW_TAG_class_type
:
20827 case DW_TAG_interface_type
:
20828 case DW_TAG_structure_type
:
20829 case DW_TAG_union_type
:
20830 case DW_TAG_set_type
:
20831 case DW_TAG_enumeration_type
:
20832 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20833 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20836 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20837 really ever be static objects: otherwise, if you try
20838 to, say, break of a class's method and you're in a file
20839 which doesn't mention that class, it won't work unless
20840 the check for all static symbols in lookup_symbol_aux
20841 saves you. See the OtherFileClass tests in
20842 gdb.c++/namespace.exp. */
20846 buildsym_compunit
*builder
= cu
->get_builder ();
20848 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20849 && cu
->language
== language_cplus
20850 ? builder
->get_global_symbols ()
20851 : cu
->list_in_scope
);
20853 /* The semantics of C++ state that "struct foo {
20854 ... }" also defines a typedef for "foo". */
20855 if (cu
->language
== language_cplus
20856 || cu
->language
== language_ada
20857 || cu
->language
== language_d
20858 || cu
->language
== language_rust
)
20860 /* The symbol's name is already allocated along
20861 with this objfile, so we don't need to
20862 duplicate it for the type. */
20863 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20864 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20869 case DW_TAG_typedef
:
20870 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20871 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20872 list_to_add
= cu
->list_in_scope
;
20874 case DW_TAG_base_type
:
20875 case DW_TAG_subrange_type
:
20876 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20877 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20878 list_to_add
= cu
->list_in_scope
;
20880 case DW_TAG_enumerator
:
20881 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20882 if (attr
!= nullptr)
20884 dwarf2_const_value (attr
, sym
, cu
);
20887 /* NOTE: carlton/2003-11-10: See comment above in the
20888 DW_TAG_class_type, etc. block. */
20891 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20892 && cu
->language
== language_cplus
20893 ? cu
->get_builder ()->get_global_symbols ()
20894 : cu
->list_in_scope
);
20897 case DW_TAG_imported_declaration
:
20898 case DW_TAG_namespace
:
20899 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20900 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20902 case DW_TAG_module
:
20903 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20904 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20905 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20907 case DW_TAG_common_block
:
20908 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20909 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20910 add_symbol_to_list (sym
, cu
->list_in_scope
);
20913 /* Not a tag we recognize. Hopefully we aren't processing
20914 trash data, but since we must specifically ignore things
20915 we don't recognize, there is nothing else we should do at
20917 complaint (_("unsupported tag: '%s'"),
20918 dwarf_tag_name (die
->tag
));
20924 sym
->hash_next
= objfile
->template_symbols
;
20925 objfile
->template_symbols
= sym
;
20926 list_to_add
= NULL
;
20929 if (list_to_add
!= NULL
)
20930 add_symbol_to_list (sym
, list_to_add
);
20932 /* For the benefit of old versions of GCC, check for anonymous
20933 namespaces based on the demangled name. */
20934 if (!cu
->processing_has_namespace_info
20935 && cu
->language
== language_cplus
)
20936 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20941 /* Given an attr with a DW_FORM_dataN value in host byte order,
20942 zero-extend it as appropriate for the symbol's type. The DWARF
20943 standard (v4) is not entirely clear about the meaning of using
20944 DW_FORM_dataN for a constant with a signed type, where the type is
20945 wider than the data. The conclusion of a discussion on the DWARF
20946 list was that this is unspecified. We choose to always zero-extend
20947 because that is the interpretation long in use by GCC. */
20950 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20951 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20953 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20954 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20955 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20956 LONGEST l
= DW_UNSND (attr
);
20958 if (bits
< sizeof (*value
) * 8)
20960 l
&= ((LONGEST
) 1 << bits
) - 1;
20963 else if (bits
== sizeof (*value
) * 8)
20967 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20968 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20975 /* Read a constant value from an attribute. Either set *VALUE, or if
20976 the value does not fit in *VALUE, set *BYTES - either already
20977 allocated on the objfile obstack, or newly allocated on OBSTACK,
20978 or, set *BATON, if we translated the constant to a location
20982 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20983 const char *name
, struct obstack
*obstack
,
20984 struct dwarf2_cu
*cu
,
20985 LONGEST
*value
, const gdb_byte
**bytes
,
20986 struct dwarf2_locexpr_baton
**baton
)
20988 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20989 struct comp_unit_head
*cu_header
= &cu
->header
;
20990 struct dwarf_block
*blk
;
20991 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20992 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20998 switch (attr
->form
)
21001 case DW_FORM_addrx
:
21002 case DW_FORM_GNU_addr_index
:
21006 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21007 dwarf2_const_value_length_mismatch_complaint (name
,
21008 cu_header
->addr_size
,
21009 TYPE_LENGTH (type
));
21010 /* Symbols of this form are reasonably rare, so we just
21011 piggyback on the existing location code rather than writing
21012 a new implementation of symbol_computed_ops. */
21013 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21014 (*baton
)->per_cu
= cu
->per_cu
;
21015 gdb_assert ((*baton
)->per_cu
);
21017 (*baton
)->size
= 2 + cu_header
->addr_size
;
21018 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21019 (*baton
)->data
= data
;
21021 data
[0] = DW_OP_addr
;
21022 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21023 byte_order
, DW_ADDR (attr
));
21024 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21027 case DW_FORM_string
:
21030 case DW_FORM_GNU_str_index
:
21031 case DW_FORM_GNU_strp_alt
:
21032 /* DW_STRING is already allocated on the objfile obstack, point
21034 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21036 case DW_FORM_block1
:
21037 case DW_FORM_block2
:
21038 case DW_FORM_block4
:
21039 case DW_FORM_block
:
21040 case DW_FORM_exprloc
:
21041 case DW_FORM_data16
:
21042 blk
= DW_BLOCK (attr
);
21043 if (TYPE_LENGTH (type
) != blk
->size
)
21044 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21045 TYPE_LENGTH (type
));
21046 *bytes
= blk
->data
;
21049 /* The DW_AT_const_value attributes are supposed to carry the
21050 symbol's value "represented as it would be on the target
21051 architecture." By the time we get here, it's already been
21052 converted to host endianness, so we just need to sign- or
21053 zero-extend it as appropriate. */
21054 case DW_FORM_data1
:
21055 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21057 case DW_FORM_data2
:
21058 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21060 case DW_FORM_data4
:
21061 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21063 case DW_FORM_data8
:
21064 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21067 case DW_FORM_sdata
:
21068 case DW_FORM_implicit_const
:
21069 *value
= DW_SND (attr
);
21072 case DW_FORM_udata
:
21073 *value
= DW_UNSND (attr
);
21077 complaint (_("unsupported const value attribute form: '%s'"),
21078 dwarf_form_name (attr
->form
));
21085 /* Copy constant value from an attribute to a symbol. */
21088 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21089 struct dwarf2_cu
*cu
)
21091 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21093 const gdb_byte
*bytes
;
21094 struct dwarf2_locexpr_baton
*baton
;
21096 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21097 sym
->print_name (),
21098 &objfile
->objfile_obstack
, cu
,
21099 &value
, &bytes
, &baton
);
21103 SYMBOL_LOCATION_BATON (sym
) = baton
;
21104 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21106 else if (bytes
!= NULL
)
21108 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21109 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21113 SYMBOL_VALUE (sym
) = value
;
21114 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21118 /* Return the type of the die in question using its DW_AT_type attribute. */
21120 static struct type
*
21121 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21123 struct attribute
*type_attr
;
21125 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21128 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21129 /* A missing DW_AT_type represents a void type. */
21130 return objfile_type (objfile
)->builtin_void
;
21133 return lookup_die_type (die
, type_attr
, cu
);
21136 /* True iff CU's producer generates GNAT Ada auxiliary information
21137 that allows to find parallel types through that information instead
21138 of having to do expensive parallel lookups by type name. */
21141 need_gnat_info (struct dwarf2_cu
*cu
)
21143 /* Assume that the Ada compiler was GNAT, which always produces
21144 the auxiliary information. */
21145 return (cu
->language
== language_ada
);
21148 /* Return the auxiliary type of the die in question using its
21149 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21150 attribute is not present. */
21152 static struct type
*
21153 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21155 struct attribute
*type_attr
;
21157 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21161 return lookup_die_type (die
, type_attr
, cu
);
21164 /* If DIE has a descriptive_type attribute, then set the TYPE's
21165 descriptive type accordingly. */
21168 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21169 struct dwarf2_cu
*cu
)
21171 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21173 if (descriptive_type
)
21175 ALLOCATE_GNAT_AUX_TYPE (type
);
21176 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21180 /* Return the containing type of the die in question using its
21181 DW_AT_containing_type attribute. */
21183 static struct type
*
21184 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21186 struct attribute
*type_attr
;
21187 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21189 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21191 error (_("Dwarf Error: Problem turning containing type into gdb type "
21192 "[in module %s]"), objfile_name (objfile
));
21194 return lookup_die_type (die
, type_attr
, cu
);
21197 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21199 static struct type
*
21200 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21202 struct dwarf2_per_objfile
*dwarf2_per_objfile
21203 = cu
->per_cu
->dwarf2_per_objfile
;
21204 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21207 std::string message
21208 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21209 objfile_name (objfile
),
21210 sect_offset_str (cu
->header
.sect_off
),
21211 sect_offset_str (die
->sect_off
));
21212 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21214 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21217 /* Look up the type of DIE in CU using its type attribute ATTR.
21218 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21219 DW_AT_containing_type.
21220 If there is no type substitute an error marker. */
21222 static struct type
*
21223 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21224 struct dwarf2_cu
*cu
)
21226 struct dwarf2_per_objfile
*dwarf2_per_objfile
21227 = cu
->per_cu
->dwarf2_per_objfile
;
21228 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21229 struct type
*this_type
;
21231 gdb_assert (attr
->name
== DW_AT_type
21232 || attr
->name
== DW_AT_GNAT_descriptive_type
21233 || attr
->name
== DW_AT_containing_type
);
21235 /* First see if we have it cached. */
21237 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21239 struct dwarf2_per_cu_data
*per_cu
;
21240 sect_offset sect_off
= attr
->get_ref_die_offset ();
21242 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21243 dwarf2_per_objfile
);
21244 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21246 else if (attr
->form_is_ref ())
21248 sect_offset sect_off
= attr
->get_ref_die_offset ();
21250 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21252 else if (attr
->form
== DW_FORM_ref_sig8
)
21254 ULONGEST signature
= DW_SIGNATURE (attr
);
21256 return get_signatured_type (die
, signature
, cu
);
21260 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21261 " at %s [in module %s]"),
21262 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21263 objfile_name (objfile
));
21264 return build_error_marker_type (cu
, die
);
21267 /* If not cached we need to read it in. */
21269 if (this_type
== NULL
)
21271 struct die_info
*type_die
= NULL
;
21272 struct dwarf2_cu
*type_cu
= cu
;
21274 if (attr
->form_is_ref ())
21275 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21276 if (type_die
== NULL
)
21277 return build_error_marker_type (cu
, die
);
21278 /* If we find the type now, it's probably because the type came
21279 from an inter-CU reference and the type's CU got expanded before
21281 this_type
= read_type_die (type_die
, type_cu
);
21284 /* If we still don't have a type use an error marker. */
21286 if (this_type
== NULL
)
21287 return build_error_marker_type (cu
, die
);
21292 /* Return the type in DIE, CU.
21293 Returns NULL for invalid types.
21295 This first does a lookup in die_type_hash,
21296 and only reads the die in if necessary.
21298 NOTE: This can be called when reading in partial or full symbols. */
21300 static struct type
*
21301 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21303 struct type
*this_type
;
21305 this_type
= get_die_type (die
, cu
);
21309 return read_type_die_1 (die
, cu
);
21312 /* Read the type in DIE, CU.
21313 Returns NULL for invalid types. */
21315 static struct type
*
21316 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21318 struct type
*this_type
= NULL
;
21322 case DW_TAG_class_type
:
21323 case DW_TAG_interface_type
:
21324 case DW_TAG_structure_type
:
21325 case DW_TAG_union_type
:
21326 this_type
= read_structure_type (die
, cu
);
21328 case DW_TAG_enumeration_type
:
21329 this_type
= read_enumeration_type (die
, cu
);
21331 case DW_TAG_subprogram
:
21332 case DW_TAG_subroutine_type
:
21333 case DW_TAG_inlined_subroutine
:
21334 this_type
= read_subroutine_type (die
, cu
);
21336 case DW_TAG_array_type
:
21337 this_type
= read_array_type (die
, cu
);
21339 case DW_TAG_set_type
:
21340 this_type
= read_set_type (die
, cu
);
21342 case DW_TAG_pointer_type
:
21343 this_type
= read_tag_pointer_type (die
, cu
);
21345 case DW_TAG_ptr_to_member_type
:
21346 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21348 case DW_TAG_reference_type
:
21349 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21351 case DW_TAG_rvalue_reference_type
:
21352 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21354 case DW_TAG_const_type
:
21355 this_type
= read_tag_const_type (die
, cu
);
21357 case DW_TAG_volatile_type
:
21358 this_type
= read_tag_volatile_type (die
, cu
);
21360 case DW_TAG_restrict_type
:
21361 this_type
= read_tag_restrict_type (die
, cu
);
21363 case DW_TAG_string_type
:
21364 this_type
= read_tag_string_type (die
, cu
);
21366 case DW_TAG_typedef
:
21367 this_type
= read_typedef (die
, cu
);
21369 case DW_TAG_subrange_type
:
21370 this_type
= read_subrange_type (die
, cu
);
21372 case DW_TAG_base_type
:
21373 this_type
= read_base_type (die
, cu
);
21375 case DW_TAG_unspecified_type
:
21376 this_type
= read_unspecified_type (die
, cu
);
21378 case DW_TAG_namespace
:
21379 this_type
= read_namespace_type (die
, cu
);
21381 case DW_TAG_module
:
21382 this_type
= read_module_type (die
, cu
);
21384 case DW_TAG_atomic_type
:
21385 this_type
= read_tag_atomic_type (die
, cu
);
21388 complaint (_("unexpected tag in read_type_die: '%s'"),
21389 dwarf_tag_name (die
->tag
));
21396 /* See if we can figure out if the class lives in a namespace. We do
21397 this by looking for a member function; its demangled name will
21398 contain namespace info, if there is any.
21399 Return the computed name or NULL.
21400 Space for the result is allocated on the objfile's obstack.
21401 This is the full-die version of guess_partial_die_structure_name.
21402 In this case we know DIE has no useful parent. */
21404 static const char *
21405 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21407 struct die_info
*spec_die
;
21408 struct dwarf2_cu
*spec_cu
;
21409 struct die_info
*child
;
21410 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21413 spec_die
= die_specification (die
, &spec_cu
);
21414 if (spec_die
!= NULL
)
21420 for (child
= die
->child
;
21422 child
= child
->sibling
)
21424 if (child
->tag
== DW_TAG_subprogram
)
21426 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21428 if (linkage_name
!= NULL
)
21430 gdb::unique_xmalloc_ptr
<char> actual_name
21431 (language_class_name_from_physname (cu
->language_defn
,
21433 const char *name
= NULL
;
21435 if (actual_name
!= NULL
)
21437 const char *die_name
= dwarf2_name (die
, cu
);
21439 if (die_name
!= NULL
21440 && strcmp (die_name
, actual_name
.get ()) != 0)
21442 /* Strip off the class name from the full name.
21443 We want the prefix. */
21444 int die_name_len
= strlen (die_name
);
21445 int actual_name_len
= strlen (actual_name
.get ());
21446 const char *ptr
= actual_name
.get ();
21448 /* Test for '::' as a sanity check. */
21449 if (actual_name_len
> die_name_len
+ 2
21450 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21451 name
= obstack_strndup (
21452 &objfile
->per_bfd
->storage_obstack
,
21453 ptr
, actual_name_len
- die_name_len
- 2);
21464 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21465 prefix part in such case. See
21466 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21468 static const char *
21469 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21471 struct attribute
*attr
;
21474 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21475 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21478 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21481 attr
= dw2_linkage_name_attr (die
, cu
);
21482 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21485 /* dwarf2_name had to be already called. */
21486 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21488 /* Strip the base name, keep any leading namespaces/classes. */
21489 base
= strrchr (DW_STRING (attr
), ':');
21490 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21493 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21494 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21496 &base
[-1] - DW_STRING (attr
));
21499 /* Return the name of the namespace/class that DIE is defined within,
21500 or "" if we can't tell. The caller should not xfree the result.
21502 For example, if we're within the method foo() in the following
21512 then determine_prefix on foo's die will return "N::C". */
21514 static const char *
21515 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21517 struct dwarf2_per_objfile
*dwarf2_per_objfile
21518 = cu
->per_cu
->dwarf2_per_objfile
;
21519 struct die_info
*parent
, *spec_die
;
21520 struct dwarf2_cu
*spec_cu
;
21521 struct type
*parent_type
;
21522 const char *retval
;
21524 if (cu
->language
!= language_cplus
21525 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21526 && cu
->language
!= language_rust
)
21529 retval
= anonymous_struct_prefix (die
, cu
);
21533 /* We have to be careful in the presence of DW_AT_specification.
21534 For example, with GCC 3.4, given the code
21538 // Definition of N::foo.
21542 then we'll have a tree of DIEs like this:
21544 1: DW_TAG_compile_unit
21545 2: DW_TAG_namespace // N
21546 3: DW_TAG_subprogram // declaration of N::foo
21547 4: DW_TAG_subprogram // definition of N::foo
21548 DW_AT_specification // refers to die #3
21550 Thus, when processing die #4, we have to pretend that we're in
21551 the context of its DW_AT_specification, namely the contex of die
21554 spec_die
= die_specification (die
, &spec_cu
);
21555 if (spec_die
== NULL
)
21556 parent
= die
->parent
;
21559 parent
= spec_die
->parent
;
21563 if (parent
== NULL
)
21565 else if (parent
->building_fullname
)
21568 const char *parent_name
;
21570 /* It has been seen on RealView 2.2 built binaries,
21571 DW_TAG_template_type_param types actually _defined_ as
21572 children of the parent class:
21575 template class <class Enum> Class{};
21576 Class<enum E> class_e;
21578 1: DW_TAG_class_type (Class)
21579 2: DW_TAG_enumeration_type (E)
21580 3: DW_TAG_enumerator (enum1:0)
21581 3: DW_TAG_enumerator (enum2:1)
21583 2: DW_TAG_template_type_param
21584 DW_AT_type DW_FORM_ref_udata (E)
21586 Besides being broken debug info, it can put GDB into an
21587 infinite loop. Consider:
21589 When we're building the full name for Class<E>, we'll start
21590 at Class, and go look over its template type parameters,
21591 finding E. We'll then try to build the full name of E, and
21592 reach here. We're now trying to build the full name of E,
21593 and look over the parent DIE for containing scope. In the
21594 broken case, if we followed the parent DIE of E, we'd again
21595 find Class, and once again go look at its template type
21596 arguments, etc., etc. Simply don't consider such parent die
21597 as source-level parent of this die (it can't be, the language
21598 doesn't allow it), and break the loop here. */
21599 name
= dwarf2_name (die
, cu
);
21600 parent_name
= dwarf2_name (parent
, cu
);
21601 complaint (_("template param type '%s' defined within parent '%s'"),
21602 name
? name
: "<unknown>",
21603 parent_name
? parent_name
: "<unknown>");
21607 switch (parent
->tag
)
21609 case DW_TAG_namespace
:
21610 parent_type
= read_type_die (parent
, cu
);
21611 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21612 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21613 Work around this problem here. */
21614 if (cu
->language
== language_cplus
21615 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21617 /* We give a name to even anonymous namespaces. */
21618 return TYPE_NAME (parent_type
);
21619 case DW_TAG_class_type
:
21620 case DW_TAG_interface_type
:
21621 case DW_TAG_structure_type
:
21622 case DW_TAG_union_type
:
21623 case DW_TAG_module
:
21624 parent_type
= read_type_die (parent
, cu
);
21625 if (TYPE_NAME (parent_type
) != NULL
)
21626 return TYPE_NAME (parent_type
);
21628 /* An anonymous structure is only allowed non-static data
21629 members; no typedefs, no member functions, et cetera.
21630 So it does not need a prefix. */
21632 case DW_TAG_compile_unit
:
21633 case DW_TAG_partial_unit
:
21634 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21635 if (cu
->language
== language_cplus
21636 && !dwarf2_per_objfile
->types
.empty ()
21637 && die
->child
!= NULL
21638 && (die
->tag
== DW_TAG_class_type
21639 || die
->tag
== DW_TAG_structure_type
21640 || die
->tag
== DW_TAG_union_type
))
21642 const char *name
= guess_full_die_structure_name (die
, cu
);
21647 case DW_TAG_subprogram
:
21648 /* Nested subroutines in Fortran get a prefix with the name
21649 of the parent's subroutine. */
21650 if (cu
->language
== language_fortran
)
21652 if ((die
->tag
== DW_TAG_subprogram
)
21653 && (dwarf2_name (parent
, cu
) != NULL
))
21654 return dwarf2_name (parent
, cu
);
21656 return determine_prefix (parent
, cu
);
21657 case DW_TAG_enumeration_type
:
21658 parent_type
= read_type_die (parent
, cu
);
21659 if (TYPE_DECLARED_CLASS (parent_type
))
21661 if (TYPE_NAME (parent_type
) != NULL
)
21662 return TYPE_NAME (parent_type
);
21665 /* Fall through. */
21667 return determine_prefix (parent
, cu
);
21671 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21672 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21673 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21674 an obconcat, otherwise allocate storage for the result. The CU argument is
21675 used to determine the language and hence, the appropriate separator. */
21677 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21680 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21681 int physname
, struct dwarf2_cu
*cu
)
21683 const char *lead
= "";
21686 if (suffix
== NULL
|| suffix
[0] == '\0'
21687 || prefix
== NULL
|| prefix
[0] == '\0')
21689 else if (cu
->language
== language_d
)
21691 /* For D, the 'main' function could be defined in any module, but it
21692 should never be prefixed. */
21693 if (strcmp (suffix
, "D main") == 0)
21701 else if (cu
->language
== language_fortran
&& physname
)
21703 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21704 DW_AT_MIPS_linkage_name is preferred and used instead. */
21712 if (prefix
== NULL
)
21714 if (suffix
== NULL
)
21721 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21723 strcpy (retval
, lead
);
21724 strcat (retval
, prefix
);
21725 strcat (retval
, sep
);
21726 strcat (retval
, suffix
);
21731 /* We have an obstack. */
21732 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21736 /* Get name of a die, return NULL if not found. */
21738 static const char *
21739 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21740 struct objfile
*objfile
)
21742 if (name
&& cu
->language
== language_cplus
)
21744 std::string canon_name
= cp_canonicalize_string (name
);
21746 if (!canon_name
.empty ())
21748 if (canon_name
!= name
)
21749 name
= objfile
->intern (canon_name
);
21756 /* Get name of a die, return NULL if not found.
21757 Anonymous namespaces are converted to their magic string. */
21759 static const char *
21760 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21762 struct attribute
*attr
;
21763 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21765 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21766 if ((!attr
|| !DW_STRING (attr
))
21767 && die
->tag
!= DW_TAG_namespace
21768 && die
->tag
!= DW_TAG_class_type
21769 && die
->tag
!= DW_TAG_interface_type
21770 && die
->tag
!= DW_TAG_structure_type
21771 && die
->tag
!= DW_TAG_union_type
)
21776 case DW_TAG_compile_unit
:
21777 case DW_TAG_partial_unit
:
21778 /* Compilation units have a DW_AT_name that is a filename, not
21779 a source language identifier. */
21780 case DW_TAG_enumeration_type
:
21781 case DW_TAG_enumerator
:
21782 /* These tags always have simple identifiers already; no need
21783 to canonicalize them. */
21784 return DW_STRING (attr
);
21786 case DW_TAG_namespace
:
21787 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21788 return DW_STRING (attr
);
21789 return CP_ANONYMOUS_NAMESPACE_STR
;
21791 case DW_TAG_class_type
:
21792 case DW_TAG_interface_type
:
21793 case DW_TAG_structure_type
:
21794 case DW_TAG_union_type
:
21795 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21796 structures or unions. These were of the form "._%d" in GCC 4.1,
21797 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21798 and GCC 4.4. We work around this problem by ignoring these. */
21799 if (attr
&& DW_STRING (attr
)
21800 && (startswith (DW_STRING (attr
), "._")
21801 || startswith (DW_STRING (attr
), "<anonymous")))
21804 /* GCC might emit a nameless typedef that has a linkage name. See
21805 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21806 if (!attr
|| DW_STRING (attr
) == NULL
)
21808 attr
= dw2_linkage_name_attr (die
, cu
);
21809 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21812 /* Avoid demangling DW_STRING (attr) the second time on a second
21813 call for the same DIE. */
21814 if (!DW_STRING_IS_CANONICAL (attr
))
21816 gdb::unique_xmalloc_ptr
<char> demangled
21817 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21818 if (demangled
== nullptr)
21821 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21822 DW_STRING_IS_CANONICAL (attr
) = 1;
21825 /* Strip any leading namespaces/classes, keep only the base name.
21826 DW_AT_name for named DIEs does not contain the prefixes. */
21827 const char *base
= strrchr (DW_STRING (attr
), ':');
21828 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21831 return DW_STRING (attr
);
21839 if (!DW_STRING_IS_CANONICAL (attr
))
21841 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21843 DW_STRING_IS_CANONICAL (attr
) = 1;
21845 return DW_STRING (attr
);
21848 /* Return the die that this die in an extension of, or NULL if there
21849 is none. *EXT_CU is the CU containing DIE on input, and the CU
21850 containing the return value on output. */
21852 static struct die_info
*
21853 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21855 struct attribute
*attr
;
21857 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21861 return follow_die_ref (die
, attr
, ext_cu
);
21865 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21869 print_spaces (indent
, f
);
21870 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21871 dwarf_tag_name (die
->tag
), die
->abbrev
,
21872 sect_offset_str (die
->sect_off
));
21874 if (die
->parent
!= NULL
)
21876 print_spaces (indent
, f
);
21877 fprintf_unfiltered (f
, " parent at offset: %s\n",
21878 sect_offset_str (die
->parent
->sect_off
));
21881 print_spaces (indent
, f
);
21882 fprintf_unfiltered (f
, " has children: %s\n",
21883 dwarf_bool_name (die
->child
!= NULL
));
21885 print_spaces (indent
, f
);
21886 fprintf_unfiltered (f
, " attributes:\n");
21888 for (i
= 0; i
< die
->num_attrs
; ++i
)
21890 print_spaces (indent
, f
);
21891 fprintf_unfiltered (f
, " %s (%s) ",
21892 dwarf_attr_name (die
->attrs
[i
].name
),
21893 dwarf_form_name (die
->attrs
[i
].form
));
21895 switch (die
->attrs
[i
].form
)
21898 case DW_FORM_addrx
:
21899 case DW_FORM_GNU_addr_index
:
21900 fprintf_unfiltered (f
, "address: ");
21901 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21903 case DW_FORM_block2
:
21904 case DW_FORM_block4
:
21905 case DW_FORM_block
:
21906 case DW_FORM_block1
:
21907 fprintf_unfiltered (f
, "block: size %s",
21908 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21910 case DW_FORM_exprloc
:
21911 fprintf_unfiltered (f
, "expression: size %s",
21912 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21914 case DW_FORM_data16
:
21915 fprintf_unfiltered (f
, "constant of 16 bytes");
21917 case DW_FORM_ref_addr
:
21918 fprintf_unfiltered (f
, "ref address: ");
21919 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21921 case DW_FORM_GNU_ref_alt
:
21922 fprintf_unfiltered (f
, "alt ref address: ");
21923 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21929 case DW_FORM_ref_udata
:
21930 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21931 (long) (DW_UNSND (&die
->attrs
[i
])));
21933 case DW_FORM_data1
:
21934 case DW_FORM_data2
:
21935 case DW_FORM_data4
:
21936 case DW_FORM_data8
:
21937 case DW_FORM_udata
:
21938 case DW_FORM_sdata
:
21939 fprintf_unfiltered (f
, "constant: %s",
21940 pulongest (DW_UNSND (&die
->attrs
[i
])));
21942 case DW_FORM_sec_offset
:
21943 fprintf_unfiltered (f
, "section offset: %s",
21944 pulongest (DW_UNSND (&die
->attrs
[i
])));
21946 case DW_FORM_ref_sig8
:
21947 fprintf_unfiltered (f
, "signature: %s",
21948 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21950 case DW_FORM_string
:
21952 case DW_FORM_line_strp
:
21954 case DW_FORM_GNU_str_index
:
21955 case DW_FORM_GNU_strp_alt
:
21956 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21957 DW_STRING (&die
->attrs
[i
])
21958 ? DW_STRING (&die
->attrs
[i
]) : "",
21959 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21962 if (DW_UNSND (&die
->attrs
[i
]))
21963 fprintf_unfiltered (f
, "flag: TRUE");
21965 fprintf_unfiltered (f
, "flag: FALSE");
21967 case DW_FORM_flag_present
:
21968 fprintf_unfiltered (f
, "flag: TRUE");
21970 case DW_FORM_indirect
:
21971 /* The reader will have reduced the indirect form to
21972 the "base form" so this form should not occur. */
21973 fprintf_unfiltered (f
,
21974 "unexpected attribute form: DW_FORM_indirect");
21976 case DW_FORM_implicit_const
:
21977 fprintf_unfiltered (f
, "constant: %s",
21978 plongest (DW_SND (&die
->attrs
[i
])));
21981 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21982 die
->attrs
[i
].form
);
21985 fprintf_unfiltered (f
, "\n");
21990 dump_die_for_error (struct die_info
*die
)
21992 dump_die_shallow (gdb_stderr
, 0, die
);
21996 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21998 int indent
= level
* 4;
22000 gdb_assert (die
!= NULL
);
22002 if (level
>= max_level
)
22005 dump_die_shallow (f
, indent
, die
);
22007 if (die
->child
!= NULL
)
22009 print_spaces (indent
, f
);
22010 fprintf_unfiltered (f
, " Children:");
22011 if (level
+ 1 < max_level
)
22013 fprintf_unfiltered (f
, "\n");
22014 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22018 fprintf_unfiltered (f
,
22019 " [not printed, max nesting level reached]\n");
22023 if (die
->sibling
!= NULL
&& level
> 0)
22025 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22029 /* This is called from the pdie macro in gdbinit.in.
22030 It's not static so gcc will keep a copy callable from gdb. */
22033 dump_die (struct die_info
*die
, int max_level
)
22035 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22039 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22043 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22044 to_underlying (die
->sect_off
),
22050 /* Follow reference or signature attribute ATTR of SRC_DIE.
22051 On entry *REF_CU is the CU of SRC_DIE.
22052 On exit *REF_CU is the CU of the result. */
22054 static struct die_info
*
22055 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22056 struct dwarf2_cu
**ref_cu
)
22058 struct die_info
*die
;
22060 if (attr
->form_is_ref ())
22061 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22062 else if (attr
->form
== DW_FORM_ref_sig8
)
22063 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22066 dump_die_for_error (src_die
);
22067 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22068 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22074 /* Follow reference OFFSET.
22075 On entry *REF_CU is the CU of the source die referencing OFFSET.
22076 On exit *REF_CU is the CU of the result.
22077 Returns NULL if OFFSET is invalid. */
22079 static struct die_info
*
22080 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22081 struct dwarf2_cu
**ref_cu
)
22083 struct die_info temp_die
;
22084 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22085 struct dwarf2_per_objfile
*dwarf2_per_objfile
22086 = cu
->per_cu
->dwarf2_per_objfile
;
22088 gdb_assert (cu
->per_cu
!= NULL
);
22092 if (cu
->per_cu
->is_debug_types
)
22094 /* .debug_types CUs cannot reference anything outside their CU.
22095 If they need to, they have to reference a signatured type via
22096 DW_FORM_ref_sig8. */
22097 if (!cu
->header
.offset_in_cu_p (sect_off
))
22100 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22101 || !cu
->header
.offset_in_cu_p (sect_off
))
22103 struct dwarf2_per_cu_data
*per_cu
;
22105 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22106 dwarf2_per_objfile
);
22108 /* If necessary, add it to the queue and load its DIEs. */
22109 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22110 load_full_comp_unit (per_cu
, false, cu
->language
);
22112 target_cu
= per_cu
->cu
;
22114 else if (cu
->dies
== NULL
)
22116 /* We're loading full DIEs during partial symbol reading. */
22117 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22118 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22121 *ref_cu
= target_cu
;
22122 temp_die
.sect_off
= sect_off
;
22124 if (target_cu
!= cu
)
22125 target_cu
->ancestor
= cu
;
22127 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22129 to_underlying (sect_off
));
22132 /* Follow reference attribute ATTR of SRC_DIE.
22133 On entry *REF_CU is the CU of SRC_DIE.
22134 On exit *REF_CU is the CU of the result. */
22136 static struct die_info
*
22137 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22138 struct dwarf2_cu
**ref_cu
)
22140 sect_offset sect_off
= attr
->get_ref_die_offset ();
22141 struct dwarf2_cu
*cu
= *ref_cu
;
22142 struct die_info
*die
;
22144 die
= follow_die_offset (sect_off
,
22145 (attr
->form
== DW_FORM_GNU_ref_alt
22146 || cu
->per_cu
->is_dwz
),
22149 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22150 "at %s [in module %s]"),
22151 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22152 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22159 struct dwarf2_locexpr_baton
22160 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22161 dwarf2_per_cu_data
*per_cu
,
22162 CORE_ADDR (*get_frame_pc
) (void *baton
),
22163 void *baton
, bool resolve_abstract_p
)
22165 struct dwarf2_cu
*cu
;
22166 struct die_info
*die
;
22167 struct attribute
*attr
;
22168 struct dwarf2_locexpr_baton retval
;
22169 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22170 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22172 if (per_cu
->cu
== NULL
)
22173 load_cu (per_cu
, false);
22177 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22178 Instead just throw an error, not much else we can do. */
22179 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22180 sect_offset_str (sect_off
), objfile_name (objfile
));
22183 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22185 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22186 sect_offset_str (sect_off
), objfile_name (objfile
));
22188 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22189 if (!attr
&& resolve_abstract_p
22190 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22191 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22193 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22194 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22195 struct gdbarch
*gdbarch
= objfile
->arch ();
22197 for (const auto &cand_off
22198 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22200 struct dwarf2_cu
*cand_cu
= cu
;
22201 struct die_info
*cand
22202 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22205 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22208 CORE_ADDR pc_low
, pc_high
;
22209 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22210 if (pc_low
== ((CORE_ADDR
) -1))
22212 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22213 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22214 if (!(pc_low
<= pc
&& pc
< pc_high
))
22218 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22225 /* DWARF: "If there is no such attribute, then there is no effect.".
22226 DATA is ignored if SIZE is 0. */
22228 retval
.data
= NULL
;
22231 else if (attr
->form_is_section_offset ())
22233 struct dwarf2_loclist_baton loclist_baton
;
22234 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22237 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22239 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22241 retval
.size
= size
;
22245 if (!attr
->form_is_block ())
22246 error (_("Dwarf Error: DIE at %s referenced in module %s "
22247 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22248 sect_offset_str (sect_off
), objfile_name (objfile
));
22250 retval
.data
= DW_BLOCK (attr
)->data
;
22251 retval
.size
= DW_BLOCK (attr
)->size
;
22253 retval
.per_cu
= cu
->per_cu
;
22255 age_cached_comp_units (dwarf2_per_objfile
);
22262 struct dwarf2_locexpr_baton
22263 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22264 dwarf2_per_cu_data
*per_cu
,
22265 CORE_ADDR (*get_frame_pc
) (void *baton
),
22268 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22270 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22273 /* Write a constant of a given type as target-ordered bytes into
22276 static const gdb_byte
*
22277 write_constant_as_bytes (struct obstack
*obstack
,
22278 enum bfd_endian byte_order
,
22285 *len
= TYPE_LENGTH (type
);
22286 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22287 store_unsigned_integer (result
, *len
, byte_order
, value
);
22295 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22296 dwarf2_per_cu_data
*per_cu
,
22300 struct dwarf2_cu
*cu
;
22301 struct die_info
*die
;
22302 struct attribute
*attr
;
22303 const gdb_byte
*result
= NULL
;
22306 enum bfd_endian byte_order
;
22307 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22309 if (per_cu
->cu
== NULL
)
22310 load_cu (per_cu
, false);
22314 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22315 Instead just throw an error, not much else we can do. */
22316 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22317 sect_offset_str (sect_off
), objfile_name (objfile
));
22320 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22322 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22323 sect_offset_str (sect_off
), objfile_name (objfile
));
22325 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22329 byte_order
= (bfd_big_endian (objfile
->obfd
)
22330 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22332 switch (attr
->form
)
22335 case DW_FORM_addrx
:
22336 case DW_FORM_GNU_addr_index
:
22340 *len
= cu
->header
.addr_size
;
22341 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22342 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22346 case DW_FORM_string
:
22349 case DW_FORM_GNU_str_index
:
22350 case DW_FORM_GNU_strp_alt
:
22351 /* DW_STRING is already allocated on the objfile obstack, point
22353 result
= (const gdb_byte
*) DW_STRING (attr
);
22354 *len
= strlen (DW_STRING (attr
));
22356 case DW_FORM_block1
:
22357 case DW_FORM_block2
:
22358 case DW_FORM_block4
:
22359 case DW_FORM_block
:
22360 case DW_FORM_exprloc
:
22361 case DW_FORM_data16
:
22362 result
= DW_BLOCK (attr
)->data
;
22363 *len
= DW_BLOCK (attr
)->size
;
22366 /* The DW_AT_const_value attributes are supposed to carry the
22367 symbol's value "represented as it would be on the target
22368 architecture." By the time we get here, it's already been
22369 converted to host endianness, so we just need to sign- or
22370 zero-extend it as appropriate. */
22371 case DW_FORM_data1
:
22372 type
= die_type (die
, cu
);
22373 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22374 if (result
== NULL
)
22375 result
= write_constant_as_bytes (obstack
, byte_order
,
22378 case DW_FORM_data2
:
22379 type
= die_type (die
, cu
);
22380 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22381 if (result
== NULL
)
22382 result
= write_constant_as_bytes (obstack
, byte_order
,
22385 case DW_FORM_data4
:
22386 type
= die_type (die
, cu
);
22387 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22388 if (result
== NULL
)
22389 result
= write_constant_as_bytes (obstack
, byte_order
,
22392 case DW_FORM_data8
:
22393 type
= die_type (die
, cu
);
22394 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22395 if (result
== NULL
)
22396 result
= write_constant_as_bytes (obstack
, byte_order
,
22400 case DW_FORM_sdata
:
22401 case DW_FORM_implicit_const
:
22402 type
= die_type (die
, cu
);
22403 result
= write_constant_as_bytes (obstack
, byte_order
,
22404 type
, DW_SND (attr
), len
);
22407 case DW_FORM_udata
:
22408 type
= die_type (die
, cu
);
22409 result
= write_constant_as_bytes (obstack
, byte_order
,
22410 type
, DW_UNSND (attr
), len
);
22414 complaint (_("unsupported const value attribute form: '%s'"),
22415 dwarf_form_name (attr
->form
));
22425 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22426 dwarf2_per_cu_data
*per_cu
)
22428 struct dwarf2_cu
*cu
;
22429 struct die_info
*die
;
22431 if (per_cu
->cu
== NULL
)
22432 load_cu (per_cu
, false);
22437 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22441 return die_type (die
, cu
);
22447 dwarf2_get_die_type (cu_offset die_offset
,
22448 struct dwarf2_per_cu_data
*per_cu
)
22450 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22451 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22454 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22455 On entry *REF_CU is the CU of SRC_DIE.
22456 On exit *REF_CU is the CU of the result.
22457 Returns NULL if the referenced DIE isn't found. */
22459 static struct die_info
*
22460 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22461 struct dwarf2_cu
**ref_cu
)
22463 struct die_info temp_die
;
22464 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22465 struct die_info
*die
;
22467 /* While it might be nice to assert sig_type->type == NULL here,
22468 we can get here for DW_AT_imported_declaration where we need
22469 the DIE not the type. */
22471 /* If necessary, add it to the queue and load its DIEs. */
22473 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22474 read_signatured_type (sig_type
);
22476 sig_cu
= sig_type
->per_cu
.cu
;
22477 gdb_assert (sig_cu
!= NULL
);
22478 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22479 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22480 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22481 to_underlying (temp_die
.sect_off
));
22484 struct dwarf2_per_objfile
*dwarf2_per_objfile
22485 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22487 /* For .gdb_index version 7 keep track of included TUs.
22488 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22489 if (dwarf2_per_objfile
->index_table
!= NULL
22490 && dwarf2_per_objfile
->index_table
->version
<= 7)
22492 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22497 sig_cu
->ancestor
= cu
;
22505 /* Follow signatured type referenced by ATTR in SRC_DIE.
22506 On entry *REF_CU is the CU of SRC_DIE.
22507 On exit *REF_CU is the CU of the result.
22508 The result is the DIE of the type.
22509 If the referenced type cannot be found an error is thrown. */
22511 static struct die_info
*
22512 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22513 struct dwarf2_cu
**ref_cu
)
22515 ULONGEST signature
= DW_SIGNATURE (attr
);
22516 struct signatured_type
*sig_type
;
22517 struct die_info
*die
;
22519 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22521 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22522 /* sig_type will be NULL if the signatured type is missing from
22524 if (sig_type
== NULL
)
22526 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22527 " from DIE at %s [in module %s]"),
22528 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22529 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22532 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22535 dump_die_for_error (src_die
);
22536 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22537 " from DIE at %s [in module %s]"),
22538 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22539 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22545 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22546 reading in and processing the type unit if necessary. */
22548 static struct type
*
22549 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22550 struct dwarf2_cu
*cu
)
22552 struct dwarf2_per_objfile
*dwarf2_per_objfile
22553 = cu
->per_cu
->dwarf2_per_objfile
;
22554 struct signatured_type
*sig_type
;
22555 struct dwarf2_cu
*type_cu
;
22556 struct die_info
*type_die
;
22559 sig_type
= lookup_signatured_type (cu
, signature
);
22560 /* sig_type will be NULL if the signatured type is missing from
22562 if (sig_type
== NULL
)
22564 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22565 " from DIE at %s [in module %s]"),
22566 hex_string (signature
), sect_offset_str (die
->sect_off
),
22567 objfile_name (dwarf2_per_objfile
->objfile
));
22568 return build_error_marker_type (cu
, die
);
22571 /* If we already know the type we're done. */
22572 if (sig_type
->type
!= NULL
)
22573 return sig_type
->type
;
22576 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22577 if (type_die
!= NULL
)
22579 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22580 is created. This is important, for example, because for c++ classes
22581 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22582 type
= read_type_die (type_die
, type_cu
);
22585 complaint (_("Dwarf Error: Cannot build signatured type %s"
22586 " referenced from DIE at %s [in module %s]"),
22587 hex_string (signature
), sect_offset_str (die
->sect_off
),
22588 objfile_name (dwarf2_per_objfile
->objfile
));
22589 type
= build_error_marker_type (cu
, die
);
22594 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22595 " from DIE at %s [in module %s]"),
22596 hex_string (signature
), sect_offset_str (die
->sect_off
),
22597 objfile_name (dwarf2_per_objfile
->objfile
));
22598 type
= build_error_marker_type (cu
, die
);
22600 sig_type
->type
= type
;
22605 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22606 reading in and processing the type unit if necessary. */
22608 static struct type
*
22609 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22610 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22612 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22613 if (attr
->form_is_ref ())
22615 struct dwarf2_cu
*type_cu
= cu
;
22616 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22618 return read_type_die (type_die
, type_cu
);
22620 else if (attr
->form
== DW_FORM_ref_sig8
)
22622 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22626 struct dwarf2_per_objfile
*dwarf2_per_objfile
22627 = cu
->per_cu
->dwarf2_per_objfile
;
22629 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22630 " at %s [in module %s]"),
22631 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22632 objfile_name (dwarf2_per_objfile
->objfile
));
22633 return build_error_marker_type (cu
, die
);
22637 /* Load the DIEs associated with type unit PER_CU into memory. */
22640 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22642 struct signatured_type
*sig_type
;
22644 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22645 gdb_assert (! per_cu
->type_unit_group_p ());
22647 /* We have the per_cu, but we need the signatured_type.
22648 Fortunately this is an easy translation. */
22649 gdb_assert (per_cu
->is_debug_types
);
22650 sig_type
= (struct signatured_type
*) per_cu
;
22652 gdb_assert (per_cu
->cu
== NULL
);
22654 read_signatured_type (sig_type
);
22656 gdb_assert (per_cu
->cu
!= NULL
);
22659 /* Read in a signatured type and build its CU and DIEs.
22660 If the type is a stub for the real type in a DWO file,
22661 read in the real type from the DWO file as well. */
22664 read_signatured_type (struct signatured_type
*sig_type
)
22666 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22668 gdb_assert (per_cu
->is_debug_types
);
22669 gdb_assert (per_cu
->cu
== NULL
);
22671 cutu_reader
reader (per_cu
, NULL
, 0, false);
22673 if (!reader
.dummy_p
)
22675 struct dwarf2_cu
*cu
= reader
.cu
;
22676 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22678 gdb_assert (cu
->die_hash
== NULL
);
22680 htab_create_alloc_ex (cu
->header
.length
/ 12,
22684 &cu
->comp_unit_obstack
,
22685 hashtab_obstack_allocate
,
22686 dummy_obstack_deallocate
);
22688 if (reader
.comp_unit_die
->has_children
)
22689 reader
.comp_unit_die
->child
22690 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22691 reader
.comp_unit_die
);
22692 cu
->dies
= reader
.comp_unit_die
;
22693 /* comp_unit_die is not stored in die_hash, no need. */
22695 /* We try not to read any attributes in this function, because
22696 not all CUs needed for references have been loaded yet, and
22697 symbol table processing isn't initialized. But we have to
22698 set the CU language, or we won't be able to build types
22699 correctly. Similarly, if we do not read the producer, we can
22700 not apply producer-specific interpretation. */
22701 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22706 sig_type
->per_cu
.tu_read
= 1;
22709 /* Decode simple location descriptions.
22710 Given a pointer to a dwarf block that defines a location, compute
22711 the location and return the value. If COMPUTED is non-null, it is
22712 set to true to indicate that decoding was successful, and false
22713 otherwise. If COMPUTED is null, then this function may emit a
22717 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22719 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22721 size_t size
= blk
->size
;
22722 const gdb_byte
*data
= blk
->data
;
22723 CORE_ADDR stack
[64];
22725 unsigned int bytes_read
, unsnd
;
22728 if (computed
!= nullptr)
22734 stack
[++stacki
] = 0;
22773 stack
[++stacki
] = op
- DW_OP_lit0
;
22808 stack
[++stacki
] = op
- DW_OP_reg0
;
22811 if (computed
== nullptr)
22812 dwarf2_complex_location_expr_complaint ();
22819 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22821 stack
[++stacki
] = unsnd
;
22824 if (computed
== nullptr)
22825 dwarf2_complex_location_expr_complaint ();
22832 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22837 case DW_OP_const1u
:
22838 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22842 case DW_OP_const1s
:
22843 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22847 case DW_OP_const2u
:
22848 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22852 case DW_OP_const2s
:
22853 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22857 case DW_OP_const4u
:
22858 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22862 case DW_OP_const4s
:
22863 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22867 case DW_OP_const8u
:
22868 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22873 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22879 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22884 stack
[stacki
+ 1] = stack
[stacki
];
22889 stack
[stacki
- 1] += stack
[stacki
];
22893 case DW_OP_plus_uconst
:
22894 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22900 stack
[stacki
- 1] -= stack
[stacki
];
22905 /* If we're not the last op, then we definitely can't encode
22906 this using GDB's address_class enum. This is valid for partial
22907 global symbols, although the variable's address will be bogus
22911 if (computed
== nullptr)
22912 dwarf2_complex_location_expr_complaint ();
22918 case DW_OP_GNU_push_tls_address
:
22919 case DW_OP_form_tls_address
:
22920 /* The top of the stack has the offset from the beginning
22921 of the thread control block at which the variable is located. */
22922 /* Nothing should follow this operator, so the top of stack would
22924 /* This is valid for partial global symbols, but the variable's
22925 address will be bogus in the psymtab. Make it always at least
22926 non-zero to not look as a variable garbage collected by linker
22927 which have DW_OP_addr 0. */
22930 if (computed
== nullptr)
22931 dwarf2_complex_location_expr_complaint ();
22938 case DW_OP_GNU_uninit
:
22939 if (computed
!= nullptr)
22944 case DW_OP_GNU_addr_index
:
22945 case DW_OP_GNU_const_index
:
22946 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22952 if (computed
== nullptr)
22954 const char *name
= get_DW_OP_name (op
);
22957 complaint (_("unsupported stack op: '%s'"),
22960 complaint (_("unsupported stack op: '%02x'"),
22964 return (stack
[stacki
]);
22967 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22968 outside of the allocated space. Also enforce minimum>0. */
22969 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22971 if (computed
== nullptr)
22972 complaint (_("location description stack overflow"));
22978 if (computed
== nullptr)
22979 complaint (_("location description stack underflow"));
22984 if (computed
!= nullptr)
22986 return (stack
[stacki
]);
22989 /* memory allocation interface */
22991 static struct dwarf_block
*
22992 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22994 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22997 static struct die_info
*
22998 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23000 struct die_info
*die
;
23001 size_t size
= sizeof (struct die_info
);
23004 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23006 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23007 memset (die
, 0, sizeof (struct die_info
));
23013 /* Macro support. */
23015 /* An overload of dwarf_decode_macros that finds the correct section
23016 and ensures it is read in before calling the other overload. */
23019 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23020 int section_is_gnu
)
23022 struct dwarf2_per_objfile
*dwarf2_per_objfile
23023 = cu
->per_cu
->dwarf2_per_objfile
;
23024 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23025 const struct line_header
*lh
= cu
->line_header
;
23026 unsigned int offset_size
= cu
->header
.offset_size
;
23027 struct dwarf2_section_info
*section
;
23028 const char *section_name
;
23030 if (cu
->dwo_unit
!= nullptr)
23032 if (section_is_gnu
)
23034 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23035 section_name
= ".debug_macro.dwo";
23039 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23040 section_name
= ".debug_macinfo.dwo";
23045 if (section_is_gnu
)
23047 section
= &dwarf2_per_objfile
->macro
;
23048 section_name
= ".debug_macro";
23052 section
= &dwarf2_per_objfile
->macinfo
;
23053 section_name
= ".debug_macinfo";
23057 section
->read (objfile
);
23058 if (section
->buffer
== nullptr)
23060 complaint (_("missing %s section"), section_name
);
23064 buildsym_compunit
*builder
= cu
->get_builder ();
23066 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23067 offset_size
, offset
, section_is_gnu
);
23070 /* Return the .debug_loc section to use for CU.
23071 For DWO files use .debug_loc.dwo. */
23073 static struct dwarf2_section_info
*
23074 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23076 struct dwarf2_per_objfile
*dwarf2_per_objfile
23077 = cu
->per_cu
->dwarf2_per_objfile
;
23081 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23083 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23085 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23086 : &dwarf2_per_objfile
->loc
);
23089 /* A helper function that fills in a dwarf2_loclist_baton. */
23092 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23093 struct dwarf2_loclist_baton
*baton
,
23094 const struct attribute
*attr
)
23096 struct dwarf2_per_objfile
*dwarf2_per_objfile
23097 = cu
->per_cu
->dwarf2_per_objfile
;
23098 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23100 section
->read (dwarf2_per_objfile
->objfile
);
23102 baton
->per_cu
= cu
->per_cu
;
23103 gdb_assert (baton
->per_cu
);
23104 /* We don't know how long the location list is, but make sure we
23105 don't run off the edge of the section. */
23106 baton
->size
= section
->size
- DW_UNSND (attr
);
23107 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23108 if (cu
->base_address
.has_value ())
23109 baton
->base_address
= *cu
->base_address
;
23111 baton
->base_address
= 0;
23112 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23116 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23117 struct dwarf2_cu
*cu
, int is_block
)
23119 struct dwarf2_per_objfile
*dwarf2_per_objfile
23120 = cu
->per_cu
->dwarf2_per_objfile
;
23121 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23122 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23124 if (attr
->form_is_section_offset ()
23125 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23126 the section. If so, fall through to the complaint in the
23128 && DW_UNSND (attr
) < section
->get_size (objfile
))
23130 struct dwarf2_loclist_baton
*baton
;
23132 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23134 fill_in_loclist_baton (cu
, baton
, attr
);
23136 if (!cu
->base_address
.has_value ())
23137 complaint (_("Location list used without "
23138 "specifying the CU base address."));
23140 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23141 ? dwarf2_loclist_block_index
23142 : dwarf2_loclist_index
);
23143 SYMBOL_LOCATION_BATON (sym
) = baton
;
23147 struct dwarf2_locexpr_baton
*baton
;
23149 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23150 baton
->per_cu
= cu
->per_cu
;
23151 gdb_assert (baton
->per_cu
);
23153 if (attr
->form_is_block ())
23155 /* Note that we're just copying the block's data pointer
23156 here, not the actual data. We're still pointing into the
23157 info_buffer for SYM's objfile; right now we never release
23158 that buffer, but when we do clean up properly this may
23160 baton
->size
= DW_BLOCK (attr
)->size
;
23161 baton
->data
= DW_BLOCK (attr
)->data
;
23165 dwarf2_invalid_attrib_class_complaint ("location description",
23166 sym
->natural_name ());
23170 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23171 ? dwarf2_locexpr_block_index
23172 : dwarf2_locexpr_index
);
23173 SYMBOL_LOCATION_BATON (sym
) = baton
;
23180 dwarf2_per_cu_data::objfile () const
23182 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23184 /* Return the master objfile, so that we can report and look up the
23185 correct file containing this variable. */
23186 if (objfile
->separate_debug_objfile_backlink
)
23187 objfile
= objfile
->separate_debug_objfile_backlink
;
23192 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23193 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23194 CU_HEADERP first. */
23196 static const struct comp_unit_head
*
23197 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23198 const struct dwarf2_per_cu_data
*per_cu
)
23200 const gdb_byte
*info_ptr
;
23203 return &per_cu
->cu
->header
;
23205 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23207 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23208 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23209 rcuh_kind::COMPILE
);
23217 dwarf2_per_cu_data::addr_size () const
23219 struct comp_unit_head cu_header_local
;
23220 const struct comp_unit_head
*cu_headerp
;
23222 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23224 return cu_headerp
->addr_size
;
23230 dwarf2_per_cu_data::offset_size () const
23232 struct comp_unit_head cu_header_local
;
23233 const struct comp_unit_head
*cu_headerp
;
23235 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23237 return cu_headerp
->offset_size
;
23243 dwarf2_per_cu_data::ref_addr_size () const
23245 struct comp_unit_head cu_header_local
;
23246 const struct comp_unit_head
*cu_headerp
;
23248 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23250 if (cu_headerp
->version
== 2)
23251 return cu_headerp
->addr_size
;
23253 return cu_headerp
->offset_size
;
23259 dwarf2_per_cu_data::text_offset () const
23261 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23263 return objfile
->text_section_offset ();
23269 dwarf2_per_cu_data::addr_type () const
23271 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23272 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23273 struct type
*addr_type
= lookup_pointer_type (void_type
);
23274 int addr_size
= this->addr_size ();
23276 if (TYPE_LENGTH (addr_type
) == addr_size
)
23279 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23283 /* A helper function for dwarf2_find_containing_comp_unit that returns
23284 the index of the result, and that searches a vector. It will
23285 return a result even if the offset in question does not actually
23286 occur in any CU. This is separate so that it can be unit
23290 dwarf2_find_containing_comp_unit
23291 (sect_offset sect_off
,
23292 unsigned int offset_in_dwz
,
23293 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23298 high
= all_comp_units
.size () - 1;
23301 struct dwarf2_per_cu_data
*mid_cu
;
23302 int mid
= low
+ (high
- low
) / 2;
23304 mid_cu
= all_comp_units
[mid
];
23305 if (mid_cu
->is_dwz
> offset_in_dwz
23306 || (mid_cu
->is_dwz
== offset_in_dwz
23307 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23312 gdb_assert (low
== high
);
23316 /* Locate the .debug_info compilation unit from CU's objfile which contains
23317 the DIE at OFFSET. Raises an error on failure. */
23319 static struct dwarf2_per_cu_data
*
23320 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23321 unsigned int offset_in_dwz
,
23322 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23325 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23326 dwarf2_per_objfile
->all_comp_units
);
23327 struct dwarf2_per_cu_data
*this_cu
23328 = dwarf2_per_objfile
->all_comp_units
[low
];
23330 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23332 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23333 error (_("Dwarf Error: could not find partial DIE containing "
23334 "offset %s [in module %s]"),
23335 sect_offset_str (sect_off
),
23336 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23338 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
23340 return dwarf2_per_objfile
->all_comp_units
[low
-1];
23344 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
23345 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23346 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23347 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23354 namespace selftests
{
23355 namespace find_containing_comp_unit
{
23360 struct dwarf2_per_cu_data one
{};
23361 struct dwarf2_per_cu_data two
{};
23362 struct dwarf2_per_cu_data three
{};
23363 struct dwarf2_per_cu_data four
{};
23366 two
.sect_off
= sect_offset (one
.length
);
23371 four
.sect_off
= sect_offset (three
.length
);
23375 std::vector
<dwarf2_per_cu_data
*> units
;
23376 units
.push_back (&one
);
23377 units
.push_back (&two
);
23378 units
.push_back (&three
);
23379 units
.push_back (&four
);
23383 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23384 SELF_CHECK (units
[result
] == &one
);
23385 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23386 SELF_CHECK (units
[result
] == &one
);
23387 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23388 SELF_CHECK (units
[result
] == &two
);
23390 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23391 SELF_CHECK (units
[result
] == &three
);
23392 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23393 SELF_CHECK (units
[result
] == &three
);
23394 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23395 SELF_CHECK (units
[result
] == &four
);
23401 #endif /* GDB_SELF_TEST */
23403 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23405 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23406 : per_cu (per_cu_
),
23408 has_loclist (false),
23409 checked_producer (false),
23410 producer_is_gxx_lt_4_6 (false),
23411 producer_is_gcc_lt_4_3 (false),
23412 producer_is_icc (false),
23413 producer_is_icc_lt_14 (false),
23414 producer_is_codewarrior (false),
23415 processing_has_namespace_info (false)
23420 /* Destroy a dwarf2_cu. */
23422 dwarf2_cu::~dwarf2_cu ()
23427 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23430 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23431 enum language pretend_language
)
23433 struct attribute
*attr
;
23435 /* Set the language we're debugging. */
23436 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23437 if (attr
!= nullptr)
23438 set_cu_language (DW_UNSND (attr
), cu
);
23441 cu
->language
= pretend_language
;
23442 cu
->language_defn
= language_def (cu
->language
);
23445 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23448 /* Increase the age counter on each cached compilation unit, and free
23449 any that are too old. */
23452 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23454 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23456 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23457 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23458 while (per_cu
!= NULL
)
23460 per_cu
->cu
->last_used
++;
23461 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23462 dwarf2_mark (per_cu
->cu
);
23463 per_cu
= per_cu
->cu
->read_in_chain
;
23466 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23467 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23468 while (per_cu
!= NULL
)
23470 struct dwarf2_per_cu_data
*next_cu
;
23472 next_cu
= per_cu
->cu
->read_in_chain
;
23474 if (!per_cu
->cu
->mark
)
23477 *last_chain
= next_cu
;
23480 last_chain
= &per_cu
->cu
->read_in_chain
;
23486 /* Remove a single compilation unit from the cache. */
23489 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23491 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23492 struct dwarf2_per_objfile
*dwarf2_per_objfile
23493 = target_per_cu
->dwarf2_per_objfile
;
23495 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23496 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23497 while (per_cu
!= NULL
)
23499 struct dwarf2_per_cu_data
*next_cu
;
23501 next_cu
= per_cu
->cu
->read_in_chain
;
23503 if (per_cu
== target_per_cu
)
23507 *last_chain
= next_cu
;
23511 last_chain
= &per_cu
->cu
->read_in_chain
;
23517 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23518 We store these in a hash table separate from the DIEs, and preserve them
23519 when the DIEs are flushed out of cache.
23521 The CU "per_cu" pointer is needed because offset alone is not enough to
23522 uniquely identify the type. A file may have multiple .debug_types sections,
23523 or the type may come from a DWO file. Furthermore, while it's more logical
23524 to use per_cu->section+offset, with Fission the section with the data is in
23525 the DWO file but we don't know that section at the point we need it.
23526 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23527 because we can enter the lookup routine, get_die_type_at_offset, from
23528 outside this file, and thus won't necessarily have PER_CU->cu.
23529 Fortunately, PER_CU is stable for the life of the objfile. */
23531 struct dwarf2_per_cu_offset_and_type
23533 const struct dwarf2_per_cu_data
*per_cu
;
23534 sect_offset sect_off
;
23538 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23541 per_cu_offset_and_type_hash (const void *item
)
23543 const struct dwarf2_per_cu_offset_and_type
*ofs
23544 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23546 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23549 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23552 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23554 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23555 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23556 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23557 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23559 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23560 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23563 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23564 table if necessary. For convenience, return TYPE.
23566 The DIEs reading must have careful ordering to:
23567 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23568 reading current DIE.
23569 * Not trying to dereference contents of still incompletely read in types
23570 while reading in other DIEs.
23571 * Enable referencing still incompletely read in types just by a pointer to
23572 the type without accessing its fields.
23574 Therefore caller should follow these rules:
23575 * Try to fetch any prerequisite types we may need to build this DIE type
23576 before building the type and calling set_die_type.
23577 * After building type call set_die_type for current DIE as soon as
23578 possible before fetching more types to complete the current type.
23579 * Make the type as complete as possible before fetching more types. */
23581 static struct type
*
23582 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23584 struct dwarf2_per_objfile
*dwarf2_per_objfile
23585 = cu
->per_cu
->dwarf2_per_objfile
;
23586 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23587 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23588 struct attribute
*attr
;
23589 struct dynamic_prop prop
;
23591 /* For Ada types, make sure that the gnat-specific data is always
23592 initialized (if not already set). There are a few types where
23593 we should not be doing so, because the type-specific area is
23594 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23595 where the type-specific area is used to store the floatformat).
23596 But this is not a problem, because the gnat-specific information
23597 is actually not needed for these types. */
23598 if (need_gnat_info (cu
)
23599 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23600 && TYPE_CODE (type
) != TYPE_CODE_FLT
23601 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23602 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23603 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23604 && !HAVE_GNAT_AUX_INFO (type
))
23605 INIT_GNAT_SPECIFIC (type
);
23607 /* Read DW_AT_allocated and set in type. */
23608 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23609 if (attr
!= NULL
&& attr
->form_is_block ())
23611 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23612 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23613 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23615 else if (attr
!= NULL
)
23617 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23618 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23619 sect_offset_str (die
->sect_off
));
23622 /* Read DW_AT_associated and set in type. */
23623 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23624 if (attr
!= NULL
&& attr
->form_is_block ())
23626 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23627 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23628 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23630 else if (attr
!= NULL
)
23632 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23633 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23634 sect_offset_str (die
->sect_off
));
23637 /* Read DW_AT_data_location and set in type. */
23638 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23639 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23640 cu
->per_cu
->addr_type ()))
23641 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23643 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23644 dwarf2_per_objfile
->die_type_hash
23645 = htab_up (htab_create_alloc (127,
23646 per_cu_offset_and_type_hash
,
23647 per_cu_offset_and_type_eq
,
23648 NULL
, xcalloc
, xfree
));
23650 ofs
.per_cu
= cu
->per_cu
;
23651 ofs
.sect_off
= die
->sect_off
;
23653 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23654 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23656 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23657 sect_offset_str (die
->sect_off
));
23658 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23659 struct dwarf2_per_cu_offset_and_type
);
23664 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23665 or return NULL if the die does not have a saved type. */
23667 static struct type
*
23668 get_die_type_at_offset (sect_offset sect_off
,
23669 struct dwarf2_per_cu_data
*per_cu
)
23671 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23672 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23674 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23677 ofs
.per_cu
= per_cu
;
23678 ofs
.sect_off
= sect_off
;
23679 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23680 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23687 /* Look up the type for DIE in CU in die_type_hash,
23688 or return NULL if DIE does not have a saved type. */
23690 static struct type
*
23691 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23693 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23696 /* Add a dependence relationship from CU to REF_PER_CU. */
23699 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23700 struct dwarf2_per_cu_data
*ref_per_cu
)
23704 if (cu
->dependencies
== NULL
)
23706 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23707 NULL
, &cu
->comp_unit_obstack
,
23708 hashtab_obstack_allocate
,
23709 dummy_obstack_deallocate
);
23711 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23713 *slot
= ref_per_cu
;
23716 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23717 Set the mark field in every compilation unit in the
23718 cache that we must keep because we are keeping CU. */
23721 dwarf2_mark_helper (void **slot
, void *data
)
23723 struct dwarf2_per_cu_data
*per_cu
;
23725 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23727 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23728 reading of the chain. As such dependencies remain valid it is not much
23729 useful to track and undo them during QUIT cleanups. */
23730 if (per_cu
->cu
== NULL
)
23733 if (per_cu
->cu
->mark
)
23735 per_cu
->cu
->mark
= true;
23737 if (per_cu
->cu
->dependencies
!= NULL
)
23738 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23743 /* Set the mark field in CU and in every other compilation unit in the
23744 cache that we must keep because we are keeping CU. */
23747 dwarf2_mark (struct dwarf2_cu
*cu
)
23752 if (cu
->dependencies
!= NULL
)
23753 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23757 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23761 per_cu
->cu
->mark
= false;
23762 per_cu
= per_cu
->cu
->read_in_chain
;
23766 /* Trivial hash function for partial_die_info: the hash value of a DIE
23767 is its offset in .debug_info for this objfile. */
23770 partial_die_hash (const void *item
)
23772 const struct partial_die_info
*part_die
23773 = (const struct partial_die_info
*) item
;
23775 return to_underlying (part_die
->sect_off
);
23778 /* Trivial comparison function for partial_die_info structures: two DIEs
23779 are equal if they have the same offset. */
23782 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23784 const struct partial_die_info
*part_die_lhs
23785 = (const struct partial_die_info
*) item_lhs
;
23786 const struct partial_die_info
*part_die_rhs
23787 = (const struct partial_die_info
*) item_rhs
;
23789 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23792 struct cmd_list_element
*set_dwarf_cmdlist
;
23793 struct cmd_list_element
*show_dwarf_cmdlist
;
23796 show_check_physname (struct ui_file
*file
, int from_tty
,
23797 struct cmd_list_element
*c
, const char *value
)
23799 fprintf_filtered (file
,
23800 _("Whether to check \"physname\" is %s.\n"),
23804 void _initialize_dwarf2_read ();
23806 _initialize_dwarf2_read ()
23808 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23809 Set DWARF specific variables.\n\
23810 Configure DWARF variables such as the cache size."),
23811 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23812 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23814 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23815 Show DWARF specific variables.\n\
23816 Show DWARF variables such as the cache size."),
23817 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23818 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23820 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23821 &dwarf_max_cache_age
, _("\
23822 Set the upper bound on the age of cached DWARF compilation units."), _("\
23823 Show the upper bound on the age of cached DWARF compilation units."), _("\
23824 A higher limit means that cached compilation units will be stored\n\
23825 in memory longer, and more total memory will be used. Zero disables\n\
23826 caching, which can slow down startup."),
23828 show_dwarf_max_cache_age
,
23829 &set_dwarf_cmdlist
,
23830 &show_dwarf_cmdlist
);
23832 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23833 Set debugging of the DWARF reader."), _("\
23834 Show debugging of the DWARF reader."), _("\
23835 When enabled (non-zero), debugging messages are printed during DWARF\n\
23836 reading and symtab expansion. A value of 1 (one) provides basic\n\
23837 information. A value greater than 1 provides more verbose information."),
23840 &setdebuglist
, &showdebuglist
);
23842 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23843 Set debugging of the DWARF DIE reader."), _("\
23844 Show debugging of the DWARF DIE reader."), _("\
23845 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23846 The value is the maximum depth to print."),
23849 &setdebuglist
, &showdebuglist
);
23851 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23852 Set debugging of the dwarf line reader."), _("\
23853 Show debugging of the dwarf line reader."), _("\
23854 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23855 A value of 1 (one) provides basic information.\n\
23856 A value greater than 1 provides more verbose information."),
23859 &setdebuglist
, &showdebuglist
);
23861 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23862 Set cross-checking of \"physname\" code against demangler."), _("\
23863 Show cross-checking of \"physname\" code against demangler."), _("\
23864 When enabled, GDB's internal \"physname\" code is checked against\n\
23866 NULL
, show_check_physname
,
23867 &setdebuglist
, &showdebuglist
);
23869 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23870 no_class
, &use_deprecated_index_sections
, _("\
23871 Set whether to use deprecated gdb_index sections."), _("\
23872 Show whether to use deprecated gdb_index sections."), _("\
23873 When enabled, deprecated .gdb_index sections are used anyway.\n\
23874 Normally they are ignored either because of a missing feature or\n\
23875 performance issue.\n\
23876 Warning: This option must be enabled before gdb reads the file."),
23879 &setlist
, &showlist
);
23881 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23882 &dwarf2_locexpr_funcs
);
23883 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23884 &dwarf2_loclist_funcs
);
23886 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23887 &dwarf2_block_frame_base_locexpr_funcs
);
23888 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23889 &dwarf2_block_frame_base_loclist_funcs
);
23892 selftests::register_test ("dw2_expand_symtabs_matching",
23893 selftests::dw2_expand_symtabs_matching::run_test
);
23894 selftests::register_test ("dwarf2_find_containing_comp_unit",
23895 selftests::find_containing_comp_unit::run_test
);