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_bfd::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_bfd->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
->per_bfd
->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_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1750 : can_copy (can_copy_
)
1753 names
= &dwarf2_elf_names
;
1755 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1756 locate_sections (obfd
, sec
, *names
);
1759 dwarf2_per_bfd::~dwarf2_per_bfd ()
1761 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1762 free_cached_comp_units ();
1764 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1765 per_cu
->imported_symtabs_free ();
1767 for (signatured_type
*sig_type
: all_type_units
)
1768 sig_type
->per_cu
.imported_symtabs_free ();
1770 /* Everything else should be on this->obstack. */
1773 /* See declaration. */
1776 dwarf2_per_bfd::free_cached_comp_units ()
1778 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1779 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1780 while (per_cu
!= NULL
)
1782 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1785 *last_chain
= next_cu
;
1790 /* A helper class that calls free_cached_comp_units on
1793 class free_cached_comp_units
1797 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1798 : m_per_objfile (per_objfile
)
1802 ~free_cached_comp_units ()
1804 m_per_objfile
->per_bfd
->free_cached_comp_units ();
1807 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1811 dwarf2_per_objfile
*m_per_objfile
;
1817 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1819 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1821 return this->m_symtabs
[per_cu
->index
] != nullptr;
1827 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1829 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1831 return this->m_symtabs
[per_cu
->index
];
1837 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1838 compunit_symtab
*symtab
)
1840 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1841 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1843 this->m_symtabs
[per_cu
->index
] = symtab
;
1846 /* Try to locate the sections we need for DWARF 2 debugging
1847 information and return true if we have enough to do something.
1848 NAMES points to the dwarf2 section names, or is NULL if the standard
1849 ELF names are used. CAN_COPY is true for formats where symbol
1850 interposition is possible and so symbol values must follow copy
1851 relocation rules. */
1854 dwarf2_has_info (struct objfile
*objfile
,
1855 const struct dwarf2_debug_sections
*names
,
1858 if (objfile
->flags
& OBJF_READNEVER
)
1861 struct dwarf2_per_objfile
*dwarf2_per_objfile
1862 = get_dwarf2_per_objfile (objfile
);
1864 if (dwarf2_per_objfile
== NULL
)
1866 /* For now, each dwarf2_per_objfile owns its own dwarf2_per_bfd (no
1868 dwarf2_per_bfd
*per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1870 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1873 return (!dwarf2_per_objfile
->per_bfd
->info
.is_virtual
1874 && dwarf2_per_objfile
->per_bfd
->info
.s
.section
!= NULL
1875 && !dwarf2_per_objfile
->per_bfd
->abbrev
.is_virtual
1876 && dwarf2_per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1879 /* When loading sections, we look either for uncompressed section or for
1880 compressed section names. */
1883 section_is_p (const char *section_name
,
1884 const struct dwarf2_section_names
*names
)
1886 if (names
->normal
!= NULL
1887 && strcmp (section_name
, names
->normal
) == 0)
1889 if (names
->compressed
!= NULL
1890 && strcmp (section_name
, names
->compressed
) == 0)
1895 /* See declaration. */
1898 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1899 const dwarf2_debug_sections
&names
)
1901 flagword aflag
= bfd_section_flags (sectp
);
1903 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1906 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1907 > bfd_get_file_size (abfd
))
1909 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1910 warning (_("Discarding section %s which has a section size (%s"
1911 ") larger than the file size [in module %s]"),
1912 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1913 bfd_get_filename (abfd
));
1915 else if (section_is_p (sectp
->name
, &names
.info
))
1917 this->info
.s
.section
= sectp
;
1918 this->info
.size
= bfd_section_size (sectp
);
1920 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1922 this->abbrev
.s
.section
= sectp
;
1923 this->abbrev
.size
= bfd_section_size (sectp
);
1925 else if (section_is_p (sectp
->name
, &names
.line
))
1927 this->line
.s
.section
= sectp
;
1928 this->line
.size
= bfd_section_size (sectp
);
1930 else if (section_is_p (sectp
->name
, &names
.loc
))
1932 this->loc
.s
.section
= sectp
;
1933 this->loc
.size
= bfd_section_size (sectp
);
1935 else if (section_is_p (sectp
->name
, &names
.loclists
))
1937 this->loclists
.s
.section
= sectp
;
1938 this->loclists
.size
= bfd_section_size (sectp
);
1940 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1942 this->macinfo
.s
.section
= sectp
;
1943 this->macinfo
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.macro
))
1947 this->macro
.s
.section
= sectp
;
1948 this->macro
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.str
))
1952 this->str
.s
.section
= sectp
;
1953 this->str
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1957 this->str_offsets
.s
.section
= sectp
;
1958 this->str_offsets
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.line_str
))
1962 this->line_str
.s
.section
= sectp
;
1963 this->line_str
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.addr
))
1967 this->addr
.s
.section
= sectp
;
1968 this->addr
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.frame
))
1972 this->frame
.s
.section
= sectp
;
1973 this->frame
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1977 this->eh_frame
.s
.section
= sectp
;
1978 this->eh_frame
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.ranges
))
1982 this->ranges
.s
.section
= sectp
;
1983 this->ranges
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1987 this->rnglists
.s
.section
= sectp
;
1988 this->rnglists
.size
= bfd_section_size (sectp
);
1990 else if (section_is_p (sectp
->name
, &names
.types
))
1992 struct dwarf2_section_info type_section
;
1994 memset (&type_section
, 0, sizeof (type_section
));
1995 type_section
.s
.section
= sectp
;
1996 type_section
.size
= bfd_section_size (sectp
);
1998 this->types
.push_back (type_section
);
2000 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2002 this->gdb_index
.s
.section
= sectp
;
2003 this->gdb_index
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2007 this->debug_names
.s
.section
= sectp
;
2008 this->debug_names
.size
= bfd_section_size (sectp
);
2010 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2012 this->debug_aranges
.s
.section
= sectp
;
2013 this->debug_aranges
.size
= bfd_section_size (sectp
);
2016 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2017 && bfd_section_vma (sectp
) == 0)
2018 this->has_section_at_zero
= true;
2021 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2025 dwarf2_get_section_info (struct objfile
*objfile
,
2026 enum dwarf2_section_enum sect
,
2027 asection
**sectp
, const gdb_byte
**bufp
,
2028 bfd_size_type
*sizep
)
2030 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2031 struct dwarf2_section_info
*info
;
2033 /* We may see an objfile without any DWARF, in which case we just
2044 case DWARF2_DEBUG_FRAME
:
2045 info
= &data
->per_bfd
->frame
;
2047 case DWARF2_EH_FRAME
:
2048 info
= &data
->per_bfd
->eh_frame
;
2051 gdb_assert_not_reached ("unexpected section");
2054 info
->read (objfile
);
2056 *sectp
= info
->get_bfd_section ();
2057 *bufp
= info
->buffer
;
2058 *sizep
= info
->size
;
2061 /* A helper function to find the sections for a .dwz file. */
2064 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2066 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2068 /* Note that we only support the standard ELF names, because .dwz
2069 is ELF-only (at the time of writing). */
2070 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2072 dwz_file
->abbrev
.s
.section
= sectp
;
2073 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2075 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2077 dwz_file
->info
.s
.section
= sectp
;
2078 dwz_file
->info
.size
= bfd_section_size (sectp
);
2080 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2082 dwz_file
->str
.s
.section
= sectp
;
2083 dwz_file
->str
.size
= bfd_section_size (sectp
);
2085 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2087 dwz_file
->line
.s
.section
= sectp
;
2088 dwz_file
->line
.size
= bfd_section_size (sectp
);
2090 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2092 dwz_file
->macro
.s
.section
= sectp
;
2093 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2095 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2097 dwz_file
->gdb_index
.s
.section
= sectp
;
2098 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2100 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2102 dwz_file
->debug_names
.s
.section
= sectp
;
2103 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2107 /* See dwarf2read.h. */
2110 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2112 const char *filename
;
2113 bfd_size_type buildid_len_arg
;
2117 if (dwarf2_per_objfile
->per_bfd
->dwz_file
!= NULL
)
2118 return dwarf2_per_objfile
->per_bfd
->dwz_file
.get ();
2120 bfd_set_error (bfd_error_no_error
);
2121 gdb::unique_xmalloc_ptr
<char> data
2122 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2123 &buildid_len_arg
, &buildid
));
2126 if (bfd_get_error () == bfd_error_no_error
)
2128 error (_("could not read '.gnu_debugaltlink' section: %s"),
2129 bfd_errmsg (bfd_get_error ()));
2132 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2134 buildid_len
= (size_t) buildid_len_arg
;
2136 filename
= data
.get ();
2138 std::string abs_storage
;
2139 if (!IS_ABSOLUTE_PATH (filename
))
2141 gdb::unique_xmalloc_ptr
<char> abs
2142 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2144 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2145 filename
= abs_storage
.c_str ();
2148 /* First try the file name given in the section. If that doesn't
2149 work, try to use the build-id instead. */
2150 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2151 if (dwz_bfd
!= NULL
)
2153 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2154 dwz_bfd
.reset (nullptr);
2157 if (dwz_bfd
== NULL
)
2158 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2160 if (dwz_bfd
== nullptr)
2162 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2163 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2165 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2172 /* File successfully retrieved from server. */
2173 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2175 if (dwz_bfd
== nullptr)
2176 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2177 alt_filename
.get ());
2178 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2179 dwz_bfd
.reset (nullptr);
2183 if (dwz_bfd
== NULL
)
2184 error (_("could not find '.gnu_debugaltlink' file for %s"),
2185 objfile_name (dwarf2_per_objfile
->objfile
));
2187 std::unique_ptr
<struct dwz_file
> result
2188 (new struct dwz_file (std::move (dwz_bfd
)));
2190 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2193 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2194 result
->dwz_bfd
.get ());
2195 dwarf2_per_objfile
->per_bfd
->dwz_file
= std::move (result
);
2196 return dwarf2_per_objfile
->per_bfd
->dwz_file
.get ();
2199 /* DWARF quick_symbols_functions support. */
2201 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2202 unique line tables, so we maintain a separate table of all .debug_line
2203 derived entries to support the sharing.
2204 All the quick functions need is the list of file names. We discard the
2205 line_header when we're done and don't need to record it here. */
2206 struct quick_file_names
2208 /* The data used to construct the hash key. */
2209 struct stmt_list_hash hash
;
2211 /* The number of entries in file_names, real_names. */
2212 unsigned int num_file_names
;
2214 /* The file names from the line table, after being run through
2216 const char **file_names
;
2218 /* The file names from the line table after being run through
2219 gdb_realpath. These are computed lazily. */
2220 const char **real_names
;
2223 /* When using the index (and thus not using psymtabs), each CU has an
2224 object of this type. This is used to hold information needed by
2225 the various "quick" methods. */
2226 struct dwarf2_per_cu_quick_data
2228 /* The file table. This can be NULL if there was no file table
2229 or it's currently not read in.
2230 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2231 struct quick_file_names
*file_names
;
2233 /* A temporary mark bit used when iterating over all CUs in
2234 expand_symtabs_matching. */
2235 unsigned int mark
: 1;
2237 /* True if we've tried to read the file table and found there isn't one.
2238 There will be no point in trying to read it again next time. */
2239 unsigned int no_file_data
: 1;
2242 /* Utility hash function for a stmt_list_hash. */
2245 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2249 if (stmt_list_hash
->dwo_unit
!= NULL
)
2250 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2251 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2255 /* Utility equality function for a stmt_list_hash. */
2258 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2259 const struct stmt_list_hash
*rhs
)
2261 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2263 if (lhs
->dwo_unit
!= NULL
2264 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2267 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2270 /* Hash function for a quick_file_names. */
2273 hash_file_name_entry (const void *e
)
2275 const struct quick_file_names
*file_data
2276 = (const struct quick_file_names
*) e
;
2278 return hash_stmt_list_entry (&file_data
->hash
);
2281 /* Equality function for a quick_file_names. */
2284 eq_file_name_entry (const void *a
, const void *b
)
2286 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2287 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2289 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2292 /* Delete function for a quick_file_names. */
2295 delete_file_name_entry (void *e
)
2297 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2300 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2302 xfree ((void*) file_data
->file_names
[i
]);
2303 if (file_data
->real_names
)
2304 xfree ((void*) file_data
->real_names
[i
]);
2307 /* The space for the struct itself lives on the obstack, so we don't
2311 /* Create a quick_file_names hash table. */
2314 create_quick_file_names_table (unsigned int nr_initial_entries
)
2316 return htab_up (htab_create_alloc (nr_initial_entries
,
2317 hash_file_name_entry
, eq_file_name_entry
,
2318 delete_file_name_entry
, xcalloc
, xfree
));
2321 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2322 have to be created afterwards. You should call age_cached_comp_units after
2323 processing PER_CU->CU. dw2_setup must have been already called. */
2326 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2328 if (per_cu
->is_debug_types
)
2329 load_full_type_unit (per_cu
);
2331 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2333 if (per_cu
->cu
== NULL
)
2334 return; /* Dummy CU. */
2336 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2339 /* Read in the symbols for PER_CU. */
2342 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2344 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2346 /* Skip type_unit_groups, reading the type units they contain
2347 is handled elsewhere. */
2348 if (per_cu
->type_unit_group_p ())
2351 /* The destructor of dwarf2_queue_guard frees any entries left on
2352 the queue. After this point we're guaranteed to leave this function
2353 with the dwarf queue empty. */
2354 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2356 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2358 queue_comp_unit (per_cu
, language_minimal
);
2359 load_cu (per_cu
, skip_partial
);
2361 /* If we just loaded a CU from a DWO, and we're working with an index
2362 that may badly handle TUs, load all the TUs in that DWO as well.
2363 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2364 if (!per_cu
->is_debug_types
2365 && per_cu
->cu
!= NULL
2366 && per_cu
->cu
->dwo_unit
!= NULL
2367 && dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
2368 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7
2369 /* DWP files aren't supported yet. */
2370 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2371 queue_and_load_all_dwo_tus (per_cu
);
2374 process_queue (dwarf2_per_objfile
);
2376 /* Age the cache, releasing compilation units that have not
2377 been used recently. */
2378 age_cached_comp_units (dwarf2_per_objfile
);
2381 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2382 the objfile from which this CU came. Returns the resulting symbol
2385 static struct compunit_symtab
*
2386 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2388 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2390 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
2392 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
2394 free_cached_comp_units
freer (dwarf2_per_objfile
);
2395 scoped_restore decrementer
= increment_reading_symtab ();
2396 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2397 process_cu_includes (dwarf2_per_objfile
);
2400 return dwarf2_per_objfile
->get_symtab (per_cu
);
2403 /* See declaration. */
2405 dwarf2_per_cu_data
*
2406 dwarf2_per_bfd::get_cutu (int index
)
2408 if (index
>= this->all_comp_units
.size ())
2410 index
-= this->all_comp_units
.size ();
2411 gdb_assert (index
< this->all_type_units
.size ());
2412 return &this->all_type_units
[index
]->per_cu
;
2415 return this->all_comp_units
[index
];
2418 /* See declaration. */
2420 dwarf2_per_cu_data
*
2421 dwarf2_per_bfd::get_cu (int index
)
2423 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2425 return this->all_comp_units
[index
];
2428 /* See declaration. */
2431 dwarf2_per_bfd::get_tu (int index
)
2433 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2435 return this->all_type_units
[index
];
2440 dwarf2_per_cu_data
*
2441 dwarf2_per_bfd::allocate_per_cu ()
2443 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2444 result
->index
= m_num_psymtabs
++;
2451 dwarf2_per_bfd::allocate_signatured_type ()
2453 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2454 result
->per_cu
.index
= m_num_psymtabs
++;
2458 /* Return a new dwarf2_per_cu_data allocated on the dwarf2_per_objfile
2459 obstack, and constructed with the specified field values. */
2461 static dwarf2_per_cu_data
*
2462 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2463 struct dwarf2_section_info
*section
,
2465 sect_offset sect_off
, ULONGEST length
)
2467 dwarf2_per_cu_data
*the_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
2468 the_cu
->sect_off
= sect_off
;
2469 the_cu
->length
= length
;
2470 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2471 the_cu
->section
= section
;
2472 the_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2473 struct dwarf2_per_cu_quick_data
);
2474 the_cu
->is_dwz
= is_dwz
;
2478 /* A helper for create_cus_from_index that handles a given list of
2482 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2483 const gdb_byte
*cu_list
, offset_type n_elements
,
2484 struct dwarf2_section_info
*section
,
2487 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2489 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2491 sect_offset sect_off
2492 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2493 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2496 dwarf2_per_cu_data
*per_cu
2497 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2499 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
2503 /* Read the CU list from the mapped index, and use it to create all
2504 the CU objects for this objfile. */
2507 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2508 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2509 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2511 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
2512 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve
2513 ((cu_list_elements
+ dwz_elements
) / 2);
2515 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2516 &dwarf2_per_objfile
->per_bfd
->info
, 0);
2518 if (dwz_elements
== 0)
2521 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2522 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2526 /* Create the signatured type hash table from the index. */
2529 create_signatured_type_table_from_index
2530 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2531 struct dwarf2_section_info
*section
,
2532 const gdb_byte
*bytes
,
2533 offset_type elements
)
2535 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2536 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (elements
/ 3);
2538 htab_up sig_types_hash
= allocate_signatured_type_table ();
2540 for (offset_type i
= 0; i
< elements
; i
+= 3)
2542 struct signatured_type
*sig_type
;
2545 cu_offset type_offset_in_tu
;
2547 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2548 sect_offset sect_off
2549 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2551 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2553 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2556 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2557 sig_type
->signature
= signature
;
2558 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2559 sig_type
->per_cu
.is_debug_types
= 1;
2560 sig_type
->per_cu
.section
= section
;
2561 sig_type
->per_cu
.sect_off
= sect_off
;
2562 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2563 sig_type
->per_cu
.v
.quick
2564 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2565 struct dwarf2_per_cu_quick_data
);
2567 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2570 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2573 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2576 /* Create the signatured type hash table from .debug_names. */
2579 create_signatured_type_table_from_debug_names
2580 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2581 const mapped_debug_names
&map
,
2582 struct dwarf2_section_info
*section
,
2583 struct dwarf2_section_info
*abbrev_section
)
2585 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2587 section
->read (objfile
);
2588 abbrev_section
->read (objfile
);
2590 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
2591 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2593 htab_up sig_types_hash
= allocate_signatured_type_table ();
2595 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2597 struct signatured_type
*sig_type
;
2600 sect_offset sect_off
2601 = (sect_offset
) (extract_unsigned_integer
2602 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2604 map
.dwarf5_byte_order
));
2606 comp_unit_head cu_header
;
2607 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2609 section
->buffer
+ to_underlying (sect_off
),
2612 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
2613 sig_type
->signature
= cu_header
.signature
;
2614 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2615 sig_type
->per_cu
.is_debug_types
= 1;
2616 sig_type
->per_cu
.section
= section
;
2617 sig_type
->per_cu
.sect_off
= sect_off
;
2618 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2619 sig_type
->per_cu
.v
.quick
2620 = OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
2621 struct dwarf2_per_cu_quick_data
);
2623 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2626 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2629 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2632 /* Read the address map data from the mapped index, and use it to
2633 populate the objfile's psymtabs_addrmap. */
2636 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2637 struct mapped_index
*index
)
2639 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2640 struct gdbarch
*gdbarch
= objfile
->arch ();
2641 const gdb_byte
*iter
, *end
;
2642 struct addrmap
*mutable_map
;
2645 auto_obstack temp_obstack
;
2647 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2649 iter
= index
->address_table
.data ();
2650 end
= iter
+ index
->address_table
.size ();
2652 baseaddr
= objfile
->text_section_offset ();
2656 ULONGEST hi
, lo
, cu_index
;
2657 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2659 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2661 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2666 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2667 hex_string (lo
), hex_string (hi
));
2671 if (cu_index
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
2673 complaint (_(".gdb_index address table has invalid CU number %u"),
2674 (unsigned) cu_index
);
2678 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2679 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2680 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2681 dwarf2_per_objfile
->per_bfd
->get_cu (cu_index
));
2684 objfile
->partial_symtabs
->psymtabs_addrmap
2685 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2688 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2689 populate the objfile's psymtabs_addrmap. */
2692 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2693 struct dwarf2_section_info
*section
)
2695 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2696 bfd
*abfd
= objfile
->obfd
;
2697 struct gdbarch
*gdbarch
= objfile
->arch ();
2698 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2700 auto_obstack temp_obstack
;
2701 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2703 std::unordered_map
<sect_offset
,
2704 dwarf2_per_cu_data
*,
2705 gdb::hash_enum
<sect_offset
>>
2706 debug_info_offset_to_per_cu
;
2707 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
2709 const auto insertpair
2710 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2711 if (!insertpair
.second
)
2713 warning (_("Section .debug_aranges in %s has duplicate "
2714 "debug_info_offset %s, ignoring .debug_aranges."),
2715 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2720 section
->read (objfile
);
2722 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2724 const gdb_byte
*addr
= section
->buffer
;
2726 while (addr
< section
->buffer
+ section
->size
)
2728 const gdb_byte
*const entry_addr
= addr
;
2729 unsigned int bytes_read
;
2731 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2735 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2736 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2737 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2738 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2740 warning (_("Section .debug_aranges in %s entry at offset %s "
2741 "length %s exceeds section length %s, "
2742 "ignoring .debug_aranges."),
2743 objfile_name (objfile
),
2744 plongest (entry_addr
- section
->buffer
),
2745 plongest (bytes_read
+ entry_length
),
2746 pulongest (section
->size
));
2750 /* The version number. */
2751 const uint16_t version
= read_2_bytes (abfd
, addr
);
2755 warning (_("Section .debug_aranges in %s entry at offset %s "
2756 "has unsupported version %d, ignoring .debug_aranges."),
2757 objfile_name (objfile
),
2758 plongest (entry_addr
- section
->buffer
), version
);
2762 const uint64_t debug_info_offset
2763 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2764 addr
+= offset_size
;
2765 const auto per_cu_it
2766 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2767 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2769 warning (_("Section .debug_aranges in %s entry at offset %s "
2770 "debug_info_offset %s does not exists, "
2771 "ignoring .debug_aranges."),
2772 objfile_name (objfile
),
2773 plongest (entry_addr
- section
->buffer
),
2774 pulongest (debug_info_offset
));
2777 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2779 const uint8_t address_size
= *addr
++;
2780 if (address_size
< 1 || address_size
> 8)
2782 warning (_("Section .debug_aranges in %s entry at offset %s "
2783 "address_size %u is invalid, ignoring .debug_aranges."),
2784 objfile_name (objfile
),
2785 plongest (entry_addr
- section
->buffer
), address_size
);
2789 const uint8_t segment_selector_size
= *addr
++;
2790 if (segment_selector_size
!= 0)
2792 warning (_("Section .debug_aranges in %s entry at offset %s "
2793 "segment_selector_size %u is not supported, "
2794 "ignoring .debug_aranges."),
2795 objfile_name (objfile
),
2796 plongest (entry_addr
- section
->buffer
),
2797 segment_selector_size
);
2801 /* Must pad to an alignment boundary that is twice the address
2802 size. It is undocumented by the DWARF standard but GCC does
2804 for (size_t padding
= ((-(addr
- section
->buffer
))
2805 & (2 * address_size
- 1));
2806 padding
> 0; padding
--)
2809 warning (_("Section .debug_aranges in %s entry at offset %s "
2810 "padding is not zero, ignoring .debug_aranges."),
2811 objfile_name (objfile
),
2812 plongest (entry_addr
- section
->buffer
));
2818 if (addr
+ 2 * address_size
> entry_end
)
2820 warning (_("Section .debug_aranges in %s entry at offset %s "
2821 "address list is not properly terminated, "
2822 "ignoring .debug_aranges."),
2823 objfile_name (objfile
),
2824 plongest (entry_addr
- section
->buffer
));
2827 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2829 addr
+= address_size
;
2830 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2832 addr
+= address_size
;
2833 if (start
== 0 && length
== 0)
2835 if (start
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
2837 /* Symbol was eliminated due to a COMDAT group. */
2840 ULONGEST end
= start
+ length
;
2841 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2843 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2845 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2849 objfile
->partial_symtabs
->psymtabs_addrmap
2850 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2853 /* Find a slot in the mapped index INDEX for the object named NAME.
2854 If NAME is found, set *VEC_OUT to point to the CU vector in the
2855 constant pool and return true. If NAME cannot be found, return
2859 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2860 offset_type
**vec_out
)
2863 offset_type slot
, step
;
2864 int (*cmp
) (const char *, const char *);
2866 gdb::unique_xmalloc_ptr
<char> without_params
;
2867 if (current_language
->la_language
== language_cplus
2868 || current_language
->la_language
== language_fortran
2869 || current_language
->la_language
== language_d
)
2871 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2874 if (strchr (name
, '(') != NULL
)
2876 without_params
= cp_remove_params (name
);
2878 if (without_params
!= NULL
)
2879 name
= without_params
.get ();
2883 /* Index version 4 did not support case insensitive searches. But the
2884 indices for case insensitive languages are built in lowercase, therefore
2885 simulate our NAME being searched is also lowercased. */
2886 hash
= mapped_index_string_hash ((index
->version
== 4
2887 && case_sensitivity
== case_sensitive_off
2888 ? 5 : index
->version
),
2891 slot
= hash
& (index
->symbol_table
.size () - 1);
2892 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2893 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2899 const auto &bucket
= index
->symbol_table
[slot
];
2900 if (bucket
.name
== 0 && bucket
.vec
== 0)
2903 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2904 if (!cmp (name
, str
))
2906 *vec_out
= (offset_type
*) (index
->constant_pool
2907 + MAYBE_SWAP (bucket
.vec
));
2911 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2915 /* A helper function that reads the .gdb_index from BUFFER and fills
2916 in MAP. FILENAME is the name of the file containing the data;
2917 it is used for error reporting. DEPRECATED_OK is true if it is
2918 ok to use deprecated sections.
2920 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2921 out parameters that are filled in with information about the CU and
2922 TU lists in the section.
2924 Returns true if all went well, false otherwise. */
2927 read_gdb_index_from_buffer (const char *filename
,
2929 gdb::array_view
<const gdb_byte
> buffer
,
2930 struct mapped_index
*map
,
2931 const gdb_byte
**cu_list
,
2932 offset_type
*cu_list_elements
,
2933 const gdb_byte
**types_list
,
2934 offset_type
*types_list_elements
)
2936 const gdb_byte
*addr
= &buffer
[0];
2938 /* Version check. */
2939 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2940 /* Versions earlier than 3 emitted every copy of a psymbol. This
2941 causes the index to behave very poorly for certain requests. Version 3
2942 contained incomplete addrmap. So, it seems better to just ignore such
2946 static int warning_printed
= 0;
2947 if (!warning_printed
)
2949 warning (_("Skipping obsolete .gdb_index section in %s."),
2951 warning_printed
= 1;
2955 /* Index version 4 uses a different hash function than index version
2958 Versions earlier than 6 did not emit psymbols for inlined
2959 functions. Using these files will cause GDB not to be able to
2960 set breakpoints on inlined functions by name, so we ignore these
2961 indices unless the user has done
2962 "set use-deprecated-index-sections on". */
2963 if (version
< 6 && !deprecated_ok
)
2965 static int warning_printed
= 0;
2966 if (!warning_printed
)
2969 Skipping deprecated .gdb_index section in %s.\n\
2970 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2971 to use the section anyway."),
2973 warning_printed
= 1;
2977 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2978 of the TU (for symbols coming from TUs),
2979 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2980 Plus gold-generated indices can have duplicate entries for global symbols,
2981 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2982 These are just performance bugs, and we can't distinguish gdb-generated
2983 indices from gold-generated ones, so issue no warning here. */
2985 /* Indexes with higher version than the one supported by GDB may be no
2986 longer backward compatible. */
2990 map
->version
= version
;
2992 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2995 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2996 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3000 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3001 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3002 - MAYBE_SWAP (metadata
[i
]))
3006 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3007 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3009 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3012 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3013 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3015 = gdb::array_view
<mapped_index::symbol_table_slot
>
3016 ((mapped_index::symbol_table_slot
*) symbol_table
,
3017 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3020 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3025 /* Callback types for dwarf2_read_gdb_index. */
3027 typedef gdb::function_view
3028 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3029 get_gdb_index_contents_ftype
;
3030 typedef gdb::function_view
3031 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3032 get_gdb_index_contents_dwz_ftype
;
3034 /* Read .gdb_index. If everything went ok, initialize the "quick"
3035 elements of all the CUs and return 1. Otherwise, return 0. */
3038 dwarf2_read_gdb_index
3039 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3040 get_gdb_index_contents_ftype get_gdb_index_contents
,
3041 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3043 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3044 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3045 struct dwz_file
*dwz
;
3046 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3048 gdb::array_view
<const gdb_byte
> main_index_contents
3049 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
->per_bfd
);
3051 if (main_index_contents
.empty ())
3054 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3055 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3056 use_deprecated_index_sections
,
3057 main_index_contents
, map
.get (), &cu_list
,
3058 &cu_list_elements
, &types_list
,
3059 &types_list_elements
))
3062 /* Don't use the index if it's empty. */
3063 if (map
->symbol_table
.empty ())
3066 /* If there is a .dwz file, read it so we can get its CU list as
3068 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3071 struct mapped_index dwz_map
;
3072 const gdb_byte
*dwz_types_ignore
;
3073 offset_type dwz_types_elements_ignore
;
3075 gdb::array_view
<const gdb_byte
> dwz_index_content
3076 = get_gdb_index_contents_dwz (objfile
, dwz
);
3078 if (dwz_index_content
.empty ())
3081 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3082 1, dwz_index_content
, &dwz_map
,
3083 &dwz_list
, &dwz_list_elements
,
3085 &dwz_types_elements_ignore
))
3087 warning (_("could not read '.gdb_index' section from %s; skipping"),
3088 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3093 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3094 dwz_list
, dwz_list_elements
);
3096 if (types_list_elements
)
3098 /* We can only handle a single .debug_types when we have an
3100 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
3103 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
3105 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3106 types_list
, types_list_elements
);
3109 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3111 dwarf2_per_objfile
->per_bfd
->index_table
= std::move (map
);
3112 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
3113 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
3114 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
3119 /* die_reader_func for dw2_get_file_names. */
3122 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3123 const gdb_byte
*info_ptr
,
3124 struct die_info
*comp_unit_die
)
3126 struct dwarf2_cu
*cu
= reader
->cu
;
3127 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3128 struct dwarf2_per_objfile
*dwarf2_per_objfile
3129 = cu
->per_cu
->dwarf2_per_objfile
;
3130 struct dwarf2_per_cu_data
*lh_cu
;
3131 struct attribute
*attr
;
3133 struct quick_file_names
*qfn
;
3135 gdb_assert (! this_cu
->is_debug_types
);
3137 /* Our callers never want to match partial units -- instead they
3138 will match the enclosing full CU. */
3139 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3141 this_cu
->v
.quick
->no_file_data
= 1;
3149 sect_offset line_offset
{};
3151 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3152 if (attr
!= nullptr)
3154 struct quick_file_names find_entry
;
3156 line_offset
= (sect_offset
) DW_UNSND (attr
);
3158 /* We may have already read in this line header (TU line header sharing).
3159 If we have we're done. */
3160 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3161 find_entry
.hash
.line_sect_off
= line_offset
;
3162 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3163 &find_entry
, INSERT
);
3166 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3170 lh
= dwarf_decode_line_header (line_offset
, cu
);
3174 lh_cu
->v
.quick
->no_file_data
= 1;
3178 qfn
= XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3179 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3180 qfn
->hash
.line_sect_off
= line_offset
;
3181 gdb_assert (slot
!= NULL
);
3184 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3187 if (strcmp (fnd
.name
, "<unknown>") != 0)
3190 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3192 XOBNEWVEC (&dwarf2_per_objfile
->per_bfd
->obstack
, const char *,
3193 qfn
->num_file_names
);
3195 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3196 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3197 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3198 fnd
.comp_dir
).release ();
3199 qfn
->real_names
= NULL
;
3201 lh_cu
->v
.quick
->file_names
= qfn
;
3204 /* A helper for the "quick" functions which attempts to read the line
3205 table for THIS_CU. */
3207 static struct quick_file_names
*
3208 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3210 /* This should never be called for TUs. */
3211 gdb_assert (! this_cu
->is_debug_types
);
3212 /* Nor type unit groups. */
3213 gdb_assert (! this_cu
->type_unit_group_p ());
3215 if (this_cu
->v
.quick
->file_names
!= NULL
)
3216 return this_cu
->v
.quick
->file_names
;
3217 /* If we know there is no line data, no point in looking again. */
3218 if (this_cu
->v
.quick
->no_file_data
)
3221 cutu_reader
reader (this_cu
);
3222 if (!reader
.dummy_p
)
3223 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3225 if (this_cu
->v
.quick
->no_file_data
)
3227 return this_cu
->v
.quick
->file_names
;
3230 /* A helper for the "quick" functions which computes and caches the
3231 real path for a given file name from the line table. */
3234 dw2_get_real_path (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3235 struct quick_file_names
*qfn
, int index
)
3237 if (qfn
->real_names
== NULL
)
3238 qfn
->real_names
= OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
3239 qfn
->num_file_names
, const char *);
3241 if (qfn
->real_names
[index
] == NULL
)
3242 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3244 return qfn
->real_names
[index
];
3247 static struct symtab
*
3248 dw2_find_last_source_symtab (struct objfile
*objfile
)
3250 struct dwarf2_per_objfile
*dwarf2_per_objfile
3251 = get_dwarf2_per_objfile (objfile
);
3252 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->per_bfd
->all_comp_units
.back ();
3253 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3258 return compunit_primary_filetab (cust
);
3261 /* Traversal function for dw2_forget_cached_source_info. */
3264 dw2_free_cached_file_names (void **slot
, void *info
)
3266 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3268 if (file_data
->real_names
)
3272 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3274 xfree ((void*) file_data
->real_names
[i
]);
3275 file_data
->real_names
[i
] = NULL
;
3283 dw2_forget_cached_source_info (struct objfile
*objfile
)
3285 struct dwarf2_per_objfile
*dwarf2_per_objfile
3286 = get_dwarf2_per_objfile (objfile
);
3288 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->quick_file_names_table
.get (),
3289 dw2_free_cached_file_names
, NULL
);
3292 /* Helper function for dw2_map_symtabs_matching_filename that expands
3293 the symtabs and calls the iterator. */
3296 dw2_map_expand_apply (struct objfile
*objfile
,
3297 struct dwarf2_per_cu_data
*per_cu
,
3298 const char *name
, const char *real_path
,
3299 gdb::function_view
<bool (symtab
*)> callback
)
3301 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3303 /* Don't visit already-expanded CUs. */
3304 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3305 if (per_objfile
->symtab_set_p (per_cu
))
3308 /* This may expand more than one symtab, and we want to iterate over
3310 dw2_instantiate_symtab (per_cu
, false);
3312 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3313 last_made
, callback
);
3316 /* Implementation of the map_symtabs_matching_filename method. */
3319 dw2_map_symtabs_matching_filename
3320 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3321 gdb::function_view
<bool (symtab
*)> callback
)
3323 const char *name_basename
= lbasename (name
);
3324 struct dwarf2_per_objfile
*dwarf2_per_objfile
3325 = get_dwarf2_per_objfile (objfile
);
3327 /* The rule is CUs specify all the files, including those used by
3328 any TU, so there's no need to scan TUs here. */
3330 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3332 /* We only need to look at symtabs not already expanded. */
3333 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3336 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3337 if (file_data
== NULL
)
3340 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3342 const char *this_name
= file_data
->file_names
[j
];
3343 const char *this_real_name
;
3345 if (compare_filenames_for_search (this_name
, name
))
3347 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3353 /* Before we invoke realpath, which can get expensive when many
3354 files are involved, do a quick comparison of the basenames. */
3355 if (! basenames_may_differ
3356 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3359 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
3361 if (compare_filenames_for_search (this_real_name
, name
))
3363 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3369 if (real_path
!= NULL
)
3371 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3372 gdb_assert (IS_ABSOLUTE_PATH (name
));
3373 if (this_real_name
!= NULL
3374 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3376 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3388 /* Struct used to manage iterating over all CUs looking for a symbol. */
3390 struct dw2_symtab_iterator
3392 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3393 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3394 /* If set, only look for symbols that match that block. Valid values are
3395 GLOBAL_BLOCK and STATIC_BLOCK. */
3396 gdb::optional
<block_enum
> block_index
;
3397 /* The kind of symbol we're looking for. */
3399 /* The list of CUs from the index entry of the symbol,
3400 or NULL if not found. */
3402 /* The next element in VEC to look at. */
3404 /* The number of elements in VEC, or zero if there is no match. */
3406 /* Have we seen a global version of the symbol?
3407 If so we can ignore all further global instances.
3408 This is to work around gold/15646, inefficient gold-generated
3413 /* Initialize the index symtab iterator ITER. */
3416 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3417 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3418 gdb::optional
<block_enum
> block_index
,
3422 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3423 iter
->block_index
= block_index
;
3424 iter
->domain
= domain
;
3426 iter
->global_seen
= 0;
3428 mapped_index
*index
= dwarf2_per_objfile
->per_bfd
->index_table
.get ();
3430 /* index is NULL if OBJF_READNOW. */
3431 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3432 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3440 /* Return the next matching CU or NULL if there are no more. */
3442 static struct dwarf2_per_cu_data
*
3443 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3445 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3447 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3449 offset_type cu_index_and_attrs
=
3450 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3451 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3452 gdb_index_symbol_kind symbol_kind
=
3453 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3454 /* Only check the symbol attributes if they're present.
3455 Indices prior to version 7 don't record them,
3456 and indices >= 7 may elide them for certain symbols
3457 (gold does this). */
3459 (dwarf2_per_objfile
->per_bfd
->index_table
->version
>= 7
3460 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3462 /* Don't crash on bad data. */
3463 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3464 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
3466 complaint (_(".gdb_index entry has bad CU index"
3468 objfile_name (dwarf2_per_objfile
->objfile
));
3472 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
3474 /* Skip if already read in. */
3475 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3478 /* Check static vs global. */
3481 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3483 if (iter
->block_index
.has_value ())
3485 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3487 if (is_static
!= want_static
)
3491 /* Work around gold/15646. */
3492 if (!is_static
&& iter
->global_seen
)
3495 iter
->global_seen
= 1;
3498 /* Only check the symbol's kind if it has one. */
3501 switch (iter
->domain
)
3504 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3505 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3506 /* Some types are also in VAR_DOMAIN. */
3507 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3511 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3515 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3519 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3534 static struct compunit_symtab
*
3535 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3536 const char *name
, domain_enum domain
)
3538 struct compunit_symtab
*stab_best
= NULL
;
3539 struct dwarf2_per_objfile
*dwarf2_per_objfile
3540 = get_dwarf2_per_objfile (objfile
);
3542 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3544 struct dw2_symtab_iterator iter
;
3545 struct dwarf2_per_cu_data
*per_cu
;
3547 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3549 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3551 struct symbol
*sym
, *with_opaque
= NULL
;
3552 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3553 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3554 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3556 sym
= block_find_symbol (block
, name
, domain
,
3557 block_find_non_opaque_type_preferred
,
3560 /* Some caution must be observed with overloaded functions
3561 and methods, since the index will not contain any overload
3562 information (but NAME might contain it). */
3565 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3567 if (with_opaque
!= NULL
3568 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3571 /* Keep looking through other CUs. */
3578 dw2_print_stats (struct objfile
*objfile
)
3580 struct dwarf2_per_objfile
*dwarf2_per_objfile
3581 = get_dwarf2_per_objfile (objfile
);
3582 int total
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3583 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3586 for (int i
= 0; i
< total
; ++i
)
3588 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3590 if (!dwarf2_per_objfile
->symtab_set_p (per_cu
))
3593 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3594 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3597 /* This dumps minimal information about the index.
3598 It is called via "mt print objfiles".
3599 One use is to verify .gdb_index has been loaded by the
3600 gdb.dwarf2/gdb-index.exp testcase. */
3603 dw2_dump (struct objfile
*objfile
)
3605 struct dwarf2_per_objfile
*dwarf2_per_objfile
3606 = get_dwarf2_per_objfile (objfile
);
3608 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
3609 printf_filtered (".gdb_index:");
3610 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
)
3612 printf_filtered (" version %d\n",
3613 dwarf2_per_objfile
->per_bfd
->index_table
->version
);
3616 printf_filtered (" faked for \"readnow\"\n");
3617 printf_filtered ("\n");
3621 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3622 const char *func_name
)
3624 struct dwarf2_per_objfile
*dwarf2_per_objfile
3625 = get_dwarf2_per_objfile (objfile
);
3627 struct dw2_symtab_iterator iter
;
3628 struct dwarf2_per_cu_data
*per_cu
;
3630 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3632 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3633 dw2_instantiate_symtab (per_cu
, false);
3638 dw2_expand_all_symtabs (struct objfile
*objfile
)
3640 struct dwarf2_per_objfile
*dwarf2_per_objfile
3641 = get_dwarf2_per_objfile (objfile
);
3642 int total_units
= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
3643 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
3645 for (int i
= 0; i
< total_units
; ++i
)
3647 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
3649 /* We don't want to directly expand a partial CU, because if we
3650 read it with the wrong language, then assertion failures can
3651 be triggered later on. See PR symtab/23010. So, tell
3652 dw2_instantiate_symtab to skip partial CUs -- any important
3653 partial CU will be read via DW_TAG_imported_unit anyway. */
3654 dw2_instantiate_symtab (per_cu
, true);
3659 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3660 const char *fullname
)
3662 struct dwarf2_per_objfile
*dwarf2_per_objfile
3663 = get_dwarf2_per_objfile (objfile
);
3665 /* We don't need to consider type units here.
3666 This is only called for examining code, e.g. expand_line_sal.
3667 There can be an order of magnitude (or more) more type units
3668 than comp units, and we avoid them if we can. */
3670 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
3672 /* We only need to look at symtabs not already expanded. */
3673 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
3676 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3677 if (file_data
== NULL
)
3680 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3682 const char *this_fullname
= file_data
->file_names
[j
];
3684 if (filename_cmp (this_fullname
, fullname
) == 0)
3686 dw2_instantiate_symtab (per_cu
, false);
3694 dw2_expand_symtabs_matching_symbol
3695 (mapped_index_base
&index
,
3696 const lookup_name_info
&lookup_name_in
,
3697 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3698 enum search_domain kind
,
3699 gdb::function_view
<bool (offset_type
)> match_callback
);
3702 dw2_expand_symtabs_matching_one
3703 (struct dwarf2_per_cu_data
*per_cu
,
3704 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3705 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3708 dw2_map_matching_symbols
3709 (struct objfile
*objfile
,
3710 const lookup_name_info
&name
, domain_enum domain
,
3712 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3713 symbol_compare_ftype
*ordered_compare
)
3716 struct dwarf2_per_objfile
*dwarf2_per_objfile
3717 = get_dwarf2_per_objfile (objfile
);
3719 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3721 if (dwarf2_per_objfile
->per_bfd
->index_table
!= nullptr)
3723 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3724 here though if the current language is Ada for a non-Ada objfile
3726 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
3728 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3729 auto matcher
= [&] (const char *symname
)
3731 if (ordered_compare
== nullptr)
3733 return ordered_compare (symname
, match_name
) == 0;
3736 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3737 [&] (offset_type namei
)
3739 struct dw2_symtab_iterator iter
;
3740 struct dwarf2_per_cu_data
*per_cu
;
3742 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_kind
, domain
,
3744 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3745 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
3751 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3752 proceed assuming all symtabs have been read in. */
3755 for (compunit_symtab
*cust
: objfile
->compunits ())
3757 const struct block
*block
;
3761 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3762 if (!iterate_over_symbols_terminated (block
, name
,
3768 /* Starting from a search name, return the string that finds the upper
3769 bound of all strings that start with SEARCH_NAME in a sorted name
3770 list. Returns the empty string to indicate that the upper bound is
3771 the end of the list. */
3774 make_sort_after_prefix_name (const char *search_name
)
3776 /* When looking to complete "func", we find the upper bound of all
3777 symbols that start with "func" by looking for where we'd insert
3778 the closest string that would follow "func" in lexicographical
3779 order. Usually, that's "func"-with-last-character-incremented,
3780 i.e. "fund". Mind non-ASCII characters, though. Usually those
3781 will be UTF-8 multi-byte sequences, but we can't be certain.
3782 Especially mind the 0xff character, which is a valid character in
3783 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3784 rule out compilers allowing it in identifiers. Note that
3785 conveniently, strcmp/strcasecmp are specified to compare
3786 characters interpreted as unsigned char. So what we do is treat
3787 the whole string as a base 256 number composed of a sequence of
3788 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3789 to 0, and carries 1 to the following more-significant position.
3790 If the very first character in SEARCH_NAME ends up incremented
3791 and carries/overflows, then the upper bound is the end of the
3792 list. The string after the empty string is also the empty
3795 Some examples of this operation:
3797 SEARCH_NAME => "+1" RESULT
3801 "\xff" "a" "\xff" => "\xff" "b"
3806 Then, with these symbols for example:
3812 completing "func" looks for symbols between "func" and
3813 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3814 which finds "func" and "func1", but not "fund".
3818 funcÿ (Latin1 'ÿ' [0xff])
3822 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3823 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3827 ÿÿ (Latin1 'ÿ' [0xff])
3830 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3831 the end of the list.
3833 std::string after
= search_name
;
3834 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3836 if (!after
.empty ())
3837 after
.back () = (unsigned char) after
.back () + 1;
3841 /* See declaration. */
3843 std::pair
<std::vector
<name_component
>::const_iterator
,
3844 std::vector
<name_component
>::const_iterator
>
3845 mapped_index_base::find_name_components_bounds
3846 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3849 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3851 const char *lang_name
3852 = lookup_name_without_params
.language_lookup_name (lang
);
3854 /* Comparison function object for lower_bound that matches against a
3855 given symbol name. */
3856 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3859 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3860 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3861 return name_cmp (elem_name
, name
) < 0;
3864 /* Comparison function object for upper_bound that matches against a
3865 given symbol name. */
3866 auto lookup_compare_upper
= [&] (const char *name
,
3867 const name_component
&elem
)
3869 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3870 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3871 return name_cmp (name
, elem_name
) < 0;
3874 auto begin
= this->name_components
.begin ();
3875 auto end
= this->name_components
.end ();
3877 /* Find the lower bound. */
3880 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3883 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3886 /* Find the upper bound. */
3889 if (lookup_name_without_params
.completion_mode ())
3891 /* In completion mode, we want UPPER to point past all
3892 symbols names that have the same prefix. I.e., with
3893 these symbols, and completing "func":
3895 function << lower bound
3897 other_function << upper bound
3899 We find the upper bound by looking for the insertion
3900 point of "func"-with-last-character-incremented,
3902 std::string after
= make_sort_after_prefix_name (lang_name
);
3905 return std::lower_bound (lower
, end
, after
.c_str (),
3906 lookup_compare_lower
);
3909 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3912 return {lower
, upper
};
3915 /* See declaration. */
3918 mapped_index_base::build_name_components ()
3920 if (!this->name_components
.empty ())
3923 this->name_components_casing
= case_sensitivity
;
3925 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3927 /* The code below only knows how to break apart components of C++
3928 symbol names (and other languages that use '::' as
3929 namespace/module separator) and Ada symbol names. */
3930 auto count
= this->symbol_name_count ();
3931 for (offset_type idx
= 0; idx
< count
; idx
++)
3933 if (this->symbol_name_slot_invalid (idx
))
3936 const char *name
= this->symbol_name_at (idx
);
3938 /* Add each name component to the name component table. */
3939 unsigned int previous_len
= 0;
3941 if (strstr (name
, "::") != nullptr)
3943 for (unsigned int current_len
= cp_find_first_component (name
);
3944 name
[current_len
] != '\0';
3945 current_len
+= cp_find_first_component (name
+ current_len
))
3947 gdb_assert (name
[current_len
] == ':');
3948 this->name_components
.push_back ({previous_len
, idx
});
3949 /* Skip the '::'. */
3951 previous_len
= current_len
;
3956 /* Handle the Ada encoded (aka mangled) form here. */
3957 for (const char *iter
= strstr (name
, "__");
3959 iter
= strstr (iter
, "__"))
3961 this->name_components
.push_back ({previous_len
, idx
});
3963 previous_len
= iter
- name
;
3967 this->name_components
.push_back ({previous_len
, idx
});
3970 /* Sort name_components elements by name. */
3971 auto name_comp_compare
= [&] (const name_component
&left
,
3972 const name_component
&right
)
3974 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3975 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3977 const char *left_name
= left_qualified
+ left
.name_offset
;
3978 const char *right_name
= right_qualified
+ right
.name_offset
;
3980 return name_cmp (left_name
, right_name
) < 0;
3983 std::sort (this->name_components
.begin (),
3984 this->name_components
.end (),
3988 /* Helper for dw2_expand_symtabs_matching that works with a
3989 mapped_index_base instead of the containing objfile. This is split
3990 to a separate function in order to be able to unit test the
3991 name_components matching using a mock mapped_index_base. For each
3992 symbol name that matches, calls MATCH_CALLBACK, passing it the
3993 symbol's index in the mapped_index_base symbol table. */
3996 dw2_expand_symtabs_matching_symbol
3997 (mapped_index_base
&index
,
3998 const lookup_name_info
&lookup_name_in
,
3999 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4000 enum search_domain kind
,
4001 gdb::function_view
<bool (offset_type
)> match_callback
)
4003 lookup_name_info lookup_name_without_params
4004 = lookup_name_in
.make_ignore_params ();
4006 /* Build the symbol name component sorted vector, if we haven't
4008 index
.build_name_components ();
4010 /* The same symbol may appear more than once in the range though.
4011 E.g., if we're looking for symbols that complete "w", and we have
4012 a symbol named "w1::w2", we'll find the two name components for
4013 that same symbol in the range. To be sure we only call the
4014 callback once per symbol, we first collect the symbol name
4015 indexes that matched in a temporary vector and ignore
4017 std::vector
<offset_type
> matches
;
4019 struct name_and_matcher
4021 symbol_name_matcher_ftype
*matcher
;
4024 bool operator== (const name_and_matcher
&other
) const
4026 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4030 /* A vector holding all the different symbol name matchers, for all
4032 std::vector
<name_and_matcher
> matchers
;
4034 for (int i
= 0; i
< nr_languages
; i
++)
4036 enum language lang_e
= (enum language
) i
;
4038 const language_defn
*lang
= language_def (lang_e
);
4039 symbol_name_matcher_ftype
*name_matcher
4040 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4042 name_and_matcher key
{
4044 lookup_name_without_params
.language_lookup_name (lang_e
)
4047 /* Don't insert the same comparison routine more than once.
4048 Note that we do this linear walk. This is not a problem in
4049 practice because the number of supported languages is
4051 if (std::find (matchers
.begin (), matchers
.end (), key
)
4054 matchers
.push_back (std::move (key
));
4057 = index
.find_name_components_bounds (lookup_name_without_params
,
4060 /* Now for each symbol name in range, check to see if we have a name
4061 match, and if so, call the MATCH_CALLBACK callback. */
4063 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4065 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4067 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4068 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4071 matches
.push_back (bounds
.first
->idx
);
4075 std::sort (matches
.begin (), matches
.end ());
4077 /* Finally call the callback, once per match. */
4079 for (offset_type idx
: matches
)
4083 if (!match_callback (idx
))
4089 /* Above we use a type wider than idx's for 'prev', since 0 and
4090 (offset_type)-1 are both possible values. */
4091 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4096 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4098 /* A mock .gdb_index/.debug_names-like name index table, enough to
4099 exercise dw2_expand_symtabs_matching_symbol, which works with the
4100 mapped_index_base interface. Builds an index from the symbol list
4101 passed as parameter to the constructor. */
4102 class mock_mapped_index
: public mapped_index_base
4105 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4106 : m_symbol_table (symbols
)
4109 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4111 /* Return the number of names in the symbol table. */
4112 size_t symbol_name_count () const override
4114 return m_symbol_table
.size ();
4117 /* Get the name of the symbol at IDX in the symbol table. */
4118 const char *symbol_name_at (offset_type idx
) const override
4120 return m_symbol_table
[idx
];
4124 gdb::array_view
<const char *> m_symbol_table
;
4127 /* Convenience function that converts a NULL pointer to a "<null>"
4128 string, to pass to print routines. */
4131 string_or_null (const char *str
)
4133 return str
!= NULL
? str
: "<null>";
4136 /* Check if a lookup_name_info built from
4137 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4138 index. EXPECTED_LIST is the list of expected matches, in expected
4139 matching order. If no match expected, then an empty list is
4140 specified. Returns true on success. On failure prints a warning
4141 indicating the file:line that failed, and returns false. */
4144 check_match (const char *file
, int line
,
4145 mock_mapped_index
&mock_index
,
4146 const char *name
, symbol_name_match_type match_type
,
4147 bool completion_mode
,
4148 std::initializer_list
<const char *> expected_list
)
4150 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4152 bool matched
= true;
4154 auto mismatch
= [&] (const char *expected_str
,
4157 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4158 "expected=\"%s\", got=\"%s\"\n"),
4160 (match_type
== symbol_name_match_type::FULL
4162 name
, string_or_null (expected_str
), string_or_null (got
));
4166 auto expected_it
= expected_list
.begin ();
4167 auto expected_end
= expected_list
.end ();
4169 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4171 [&] (offset_type idx
)
4173 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4174 const char *expected_str
4175 = expected_it
== expected_end
? NULL
: *expected_it
++;
4177 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4178 mismatch (expected_str
, matched_name
);
4182 const char *expected_str
4183 = expected_it
== expected_end
? NULL
: *expected_it
++;
4184 if (expected_str
!= NULL
)
4185 mismatch (expected_str
, NULL
);
4190 /* The symbols added to the mock mapped_index for testing (in
4192 static const char *test_symbols
[] = {
4201 "ns2::tmpl<int>::foo2",
4202 "(anonymous namespace)::A::B::C",
4204 /* These are used to check that the increment-last-char in the
4205 matching algorithm for completion doesn't match "t1_fund" when
4206 completing "t1_func". */
4212 /* A UTF-8 name with multi-byte sequences to make sure that
4213 cp-name-parser understands this as a single identifier ("função"
4214 is "function" in PT). */
4217 /* \377 (0xff) is Latin1 'ÿ'. */
4220 /* \377 (0xff) is Latin1 'ÿ'. */
4224 /* A name with all sorts of complications. Starts with "z" to make
4225 it easier for the completion tests below. */
4226 #define Z_SYM_NAME \
4227 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4228 "::tuple<(anonymous namespace)::ui*, " \
4229 "std::default_delete<(anonymous namespace)::ui>, void>"
4234 /* Returns true if the mapped_index_base::find_name_component_bounds
4235 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4236 in completion mode. */
4239 check_find_bounds_finds (mapped_index_base
&index
,
4240 const char *search_name
,
4241 gdb::array_view
<const char *> expected_syms
)
4243 lookup_name_info
lookup_name (search_name
,
4244 symbol_name_match_type::FULL
, true);
4246 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4249 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4250 if (distance
!= expected_syms
.size ())
4253 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4255 auto nc_elem
= bounds
.first
+ exp_elem
;
4256 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4257 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4264 /* Test the lower-level mapped_index::find_name_component_bounds
4268 test_mapped_index_find_name_component_bounds ()
4270 mock_mapped_index
mock_index (test_symbols
);
4272 mock_index
.build_name_components ();
4274 /* Test the lower-level mapped_index::find_name_component_bounds
4275 method in completion mode. */
4277 static const char *expected_syms
[] = {
4282 SELF_CHECK (check_find_bounds_finds (mock_index
,
4283 "t1_func", expected_syms
));
4286 /* Check that the increment-last-char in the name matching algorithm
4287 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4289 static const char *expected_syms1
[] = {
4293 SELF_CHECK (check_find_bounds_finds (mock_index
,
4294 "\377", expected_syms1
));
4296 static const char *expected_syms2
[] = {
4299 SELF_CHECK (check_find_bounds_finds (mock_index
,
4300 "\377\377", expected_syms2
));
4304 /* Test dw2_expand_symtabs_matching_symbol. */
4307 test_dw2_expand_symtabs_matching_symbol ()
4309 mock_mapped_index
mock_index (test_symbols
);
4311 /* We let all tests run until the end even if some fails, for debug
4313 bool any_mismatch
= false;
4315 /* Create the expected symbols list (an initializer_list). Needed
4316 because lists have commas, and we need to pass them to CHECK,
4317 which is a macro. */
4318 #define EXPECT(...) { __VA_ARGS__ }
4320 /* Wrapper for check_match that passes down the current
4321 __FILE__/__LINE__. */
4322 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4323 any_mismatch |= !check_match (__FILE__, __LINE__, \
4325 NAME, MATCH_TYPE, COMPLETION_MODE, \
4328 /* Identity checks. */
4329 for (const char *sym
: test_symbols
)
4331 /* Should be able to match all existing symbols. */
4332 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4335 /* Should be able to match all existing symbols with
4337 std::string with_params
= std::string (sym
) + "(int)";
4338 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4341 /* Should be able to match all existing symbols with
4342 parameters and qualifiers. */
4343 with_params
= std::string (sym
) + " ( int ) const";
4344 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4347 /* This should really find sym, but cp-name-parser.y doesn't
4348 know about lvalue/rvalue qualifiers yet. */
4349 with_params
= std::string (sym
) + " ( int ) &&";
4350 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4354 /* Check that the name matching algorithm for completion doesn't get
4355 confused with Latin1 'ÿ' / 0xff. */
4357 static const char str
[] = "\377";
4358 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4359 EXPECT ("\377", "\377\377123"));
4362 /* Check that the increment-last-char in the matching algorithm for
4363 completion doesn't match "t1_fund" when completing "t1_func". */
4365 static const char str
[] = "t1_func";
4366 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4367 EXPECT ("t1_func", "t1_func1"));
4370 /* Check that completion mode works at each prefix of the expected
4373 static const char str
[] = "function(int)";
4374 size_t len
= strlen (str
);
4377 for (size_t i
= 1; i
< len
; i
++)
4379 lookup
.assign (str
, i
);
4380 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4381 EXPECT ("function"));
4385 /* While "w" is a prefix of both components, the match function
4386 should still only be called once. */
4388 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4390 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4394 /* Same, with a "complicated" symbol. */
4396 static const char str
[] = Z_SYM_NAME
;
4397 size_t len
= strlen (str
);
4400 for (size_t i
= 1; i
< len
; i
++)
4402 lookup
.assign (str
, i
);
4403 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4404 EXPECT (Z_SYM_NAME
));
4408 /* In FULL mode, an incomplete symbol doesn't match. */
4410 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4414 /* A complete symbol with parameters matches any overload, since the
4415 index has no overload info. */
4417 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4418 EXPECT ("std::zfunction", "std::zfunction2"));
4419 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4420 EXPECT ("std::zfunction", "std::zfunction2"));
4421 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4422 EXPECT ("std::zfunction", "std::zfunction2"));
4425 /* Check that whitespace is ignored appropriately. A symbol with a
4426 template argument list. */
4428 static const char expected
[] = "ns::foo<int>";
4429 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4431 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4435 /* Check that whitespace is ignored appropriately. A symbol with a
4436 template argument list that includes a pointer. */
4438 static const char expected
[] = "ns::foo<char*>";
4439 /* Try both completion and non-completion modes. */
4440 static const bool completion_mode
[2] = {false, true};
4441 for (size_t i
= 0; i
< 2; i
++)
4443 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4444 completion_mode
[i
], EXPECT (expected
));
4445 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4446 completion_mode
[i
], EXPECT (expected
));
4448 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4449 completion_mode
[i
], EXPECT (expected
));
4450 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4451 completion_mode
[i
], EXPECT (expected
));
4456 /* Check method qualifiers are ignored. */
4457 static const char expected
[] = "ns::foo<char*>";
4458 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4459 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4460 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4461 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4462 CHECK_MATCH ("foo < char * > ( int ) const",
4463 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4464 CHECK_MATCH ("foo < char * > ( int ) &&",
4465 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4468 /* Test lookup names that don't match anything. */
4470 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4473 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4477 /* Some wild matching tests, exercising "(anonymous namespace)",
4478 which should not be confused with a parameter list. */
4480 static const char *syms
[] = {
4484 "A :: B :: C ( int )",
4489 for (const char *s
: syms
)
4491 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4492 EXPECT ("(anonymous namespace)::A::B::C"));
4497 static const char expected
[] = "ns2::tmpl<int>::foo2";
4498 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4500 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4504 SELF_CHECK (!any_mismatch
);
4513 test_mapped_index_find_name_component_bounds ();
4514 test_dw2_expand_symtabs_matching_symbol ();
4517 }} // namespace selftests::dw2_expand_symtabs_matching
4519 #endif /* GDB_SELF_TEST */
4521 /* If FILE_MATCHER is NULL or if PER_CU has
4522 dwarf2_per_cu_quick_data::MARK set (see
4523 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4524 EXPANSION_NOTIFY on it. */
4527 dw2_expand_symtabs_matching_one
4528 (struct dwarf2_per_cu_data
*per_cu
,
4529 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4530 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4532 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4534 dwarf2_per_objfile
*per_objfile
= per_cu
->dwarf2_per_objfile
;
4535 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4537 compunit_symtab
*symtab
= dw2_instantiate_symtab (per_cu
, false);
4538 gdb_assert (symtab
!= nullptr);
4540 if (expansion_notify
!= NULL
&& symtab_was_null
)
4541 expansion_notify (symtab
);
4545 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4546 matched, to expand corresponding CUs that were marked. IDX is the
4547 index of the symbol name that matched. */
4550 dw2_expand_marked_cus
4551 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4552 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4553 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4556 offset_type
*vec
, vec_len
, vec_idx
;
4557 bool global_seen
= false;
4558 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4560 vec
= (offset_type
*) (index
.constant_pool
4561 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4562 vec_len
= MAYBE_SWAP (vec
[0]);
4563 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4565 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4566 /* This value is only valid for index versions >= 7. */
4567 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4568 gdb_index_symbol_kind symbol_kind
=
4569 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4570 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4571 /* Only check the symbol attributes if they're present.
4572 Indices prior to version 7 don't record them,
4573 and indices >= 7 may elide them for certain symbols
4574 (gold does this). */
4577 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4579 /* Work around gold/15646. */
4582 if (!is_static
&& global_seen
)
4588 /* Only check the symbol's kind if it has one. */
4593 case VARIABLES_DOMAIN
:
4594 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4597 case FUNCTIONS_DOMAIN
:
4598 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4602 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4605 case MODULES_DOMAIN
:
4606 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4614 /* Don't crash on bad data. */
4615 if (cu_index
>= (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
4616 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()))
4618 complaint (_(".gdb_index entry has bad CU index"
4620 objfile_name (dwarf2_per_objfile
->objfile
));
4624 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (cu_index
);
4625 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4630 /* If FILE_MATCHER is non-NULL, set all the
4631 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4632 that match FILE_MATCHER. */
4635 dw_expand_symtabs_matching_file_matcher
4636 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4637 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4639 if (file_matcher
== NULL
)
4642 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4644 NULL
, xcalloc
, xfree
));
4645 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4647 NULL
, xcalloc
, xfree
));
4649 /* The rule is CUs specify all the files, including those used by
4650 any TU, so there's no need to scan TUs here. */
4652 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4656 per_cu
->v
.quick
->mark
= 0;
4658 /* We only need to look at symtabs not already expanded. */
4659 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4662 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4663 if (file_data
== NULL
)
4666 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4668 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4670 per_cu
->v
.quick
->mark
= 1;
4674 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4676 const char *this_real_name
;
4678 if (file_matcher (file_data
->file_names
[j
], false))
4680 per_cu
->v
.quick
->mark
= 1;
4684 /* Before we invoke realpath, which can get expensive when many
4685 files are involved, do a quick comparison of the basenames. */
4686 if (!basenames_may_differ
4687 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4691 this_real_name
= dw2_get_real_path (dwarf2_per_objfile
,
4693 if (file_matcher (this_real_name
, false))
4695 per_cu
->v
.quick
->mark
= 1;
4700 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4701 ? visited_found
.get ()
4702 : visited_not_found
.get (),
4709 dw2_expand_symtabs_matching
4710 (struct objfile
*objfile
,
4711 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4712 const lookup_name_info
*lookup_name
,
4713 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4714 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4715 enum search_domain kind
)
4717 struct dwarf2_per_objfile
*dwarf2_per_objfile
4718 = get_dwarf2_per_objfile (objfile
);
4720 /* index_table is NULL if OBJF_READNOW. */
4721 if (!dwarf2_per_objfile
->per_bfd
->index_table
)
4724 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4726 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4728 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4732 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4738 mapped_index
&index
= *dwarf2_per_objfile
->per_bfd
->index_table
;
4740 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4742 kind
, [&] (offset_type idx
)
4744 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4745 expansion_notify
, kind
);
4750 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4753 static struct compunit_symtab
*
4754 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4759 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4760 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4763 if (cust
->includes
== NULL
)
4766 for (i
= 0; cust
->includes
[i
]; ++i
)
4768 struct compunit_symtab
*s
= cust
->includes
[i
];
4770 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4778 static struct compunit_symtab
*
4779 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4780 struct bound_minimal_symbol msymbol
,
4782 struct obj_section
*section
,
4785 struct dwarf2_per_cu_data
*data
;
4786 struct compunit_symtab
*result
;
4788 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4791 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4792 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4793 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4797 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4798 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4799 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4800 paddress (objfile
->arch (), pc
));
4803 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4806 gdb_assert (result
!= NULL
);
4811 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4812 void *data
, int need_fullname
)
4814 struct dwarf2_per_objfile
*dwarf2_per_objfile
4815 = get_dwarf2_per_objfile (objfile
);
4817 if (!dwarf2_per_objfile
->per_bfd
->filenames_cache
)
4819 dwarf2_per_objfile
->per_bfd
->filenames_cache
.emplace ();
4821 htab_up
visited (htab_create_alloc (10,
4822 htab_hash_pointer
, htab_eq_pointer
,
4823 NULL
, xcalloc
, xfree
));
4825 /* The rule is CUs specify all the files, including those used
4826 by any TU, so there's no need to scan TUs here. We can
4827 ignore file names coming from already-expanded CUs. */
4829 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4831 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4833 void **slot
= htab_find_slot (visited
.get (),
4834 per_cu
->v
.quick
->file_names
,
4837 *slot
= per_cu
->v
.quick
->file_names
;
4841 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
4843 /* We only need to look at symtabs not already expanded. */
4844 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
4847 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4848 if (file_data
== NULL
)
4851 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4854 /* Already visited. */
4859 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4861 const char *filename
= file_data
->file_names
[j
];
4862 dwarf2_per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4867 dwarf2_per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4869 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4872 this_real_name
= gdb_realpath (filename
);
4873 (*fun
) (filename
, this_real_name
.get (), data
);
4878 dw2_has_symbols (struct objfile
*objfile
)
4883 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4886 dw2_find_last_source_symtab
,
4887 dw2_forget_cached_source_info
,
4888 dw2_map_symtabs_matching_filename
,
4893 dw2_expand_symtabs_for_function
,
4894 dw2_expand_all_symtabs
,
4895 dw2_expand_symtabs_with_fullname
,
4896 dw2_map_matching_symbols
,
4897 dw2_expand_symtabs_matching
,
4898 dw2_find_pc_sect_compunit_symtab
,
4900 dw2_map_symbol_filenames
4903 /* DWARF-5 debug_names reader. */
4905 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4906 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4908 /* A helper function that reads the .debug_names section in SECTION
4909 and fills in MAP. FILENAME is the name of the file containing the
4910 section; it is used for error reporting.
4912 Returns true if all went well, false otherwise. */
4915 read_debug_names_from_section (struct objfile
*objfile
,
4916 const char *filename
,
4917 struct dwarf2_section_info
*section
,
4918 mapped_debug_names
&map
)
4920 if (section
->empty ())
4923 /* Older elfutils strip versions could keep the section in the main
4924 executable while splitting it for the separate debug info file. */
4925 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4928 section
->read (objfile
);
4930 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4932 const gdb_byte
*addr
= section
->buffer
;
4934 bfd
*const abfd
= section
->get_bfd_owner ();
4936 unsigned int bytes_read
;
4937 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4940 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4941 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4942 if (bytes_read
+ length
!= section
->size
)
4944 /* There may be multiple per-CU indices. */
4945 warning (_("Section .debug_names in %s length %s does not match "
4946 "section length %s, ignoring .debug_names."),
4947 filename
, plongest (bytes_read
+ length
),
4948 pulongest (section
->size
));
4952 /* The version number. */
4953 uint16_t version
= read_2_bytes (abfd
, addr
);
4957 warning (_("Section .debug_names in %s has unsupported version %d, "
4958 "ignoring .debug_names."),
4964 uint16_t padding
= read_2_bytes (abfd
, addr
);
4968 warning (_("Section .debug_names in %s has unsupported padding %d, "
4969 "ignoring .debug_names."),
4974 /* comp_unit_count - The number of CUs in the CU list. */
4975 map
.cu_count
= read_4_bytes (abfd
, addr
);
4978 /* local_type_unit_count - The number of TUs in the local TU
4980 map
.tu_count
= read_4_bytes (abfd
, addr
);
4983 /* foreign_type_unit_count - The number of TUs in the foreign TU
4985 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4987 if (foreign_tu_count
!= 0)
4989 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4990 "ignoring .debug_names."),
4991 filename
, static_cast<unsigned long> (foreign_tu_count
));
4995 /* bucket_count - The number of hash buckets in the hash lookup
4997 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5000 /* name_count - The number of unique names in the index. */
5001 map
.name_count
= read_4_bytes (abfd
, addr
);
5004 /* abbrev_table_size - The size in bytes of the abbreviations
5006 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5009 /* augmentation_string_size - The size in bytes of the augmentation
5010 string. This value is rounded up to a multiple of 4. */
5011 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5013 map
.augmentation_is_gdb
= ((augmentation_string_size
5014 == sizeof (dwarf5_augmentation
))
5015 && memcmp (addr
, dwarf5_augmentation
,
5016 sizeof (dwarf5_augmentation
)) == 0);
5017 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5018 addr
+= augmentation_string_size
;
5021 map
.cu_table_reordered
= addr
;
5022 addr
+= map
.cu_count
* map
.offset_size
;
5024 /* List of Local TUs */
5025 map
.tu_table_reordered
= addr
;
5026 addr
+= map
.tu_count
* map
.offset_size
;
5028 /* Hash Lookup Table */
5029 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5030 addr
+= map
.bucket_count
* 4;
5031 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5032 addr
+= map
.name_count
* 4;
5035 map
.name_table_string_offs_reordered
= addr
;
5036 addr
+= map
.name_count
* map
.offset_size
;
5037 map
.name_table_entry_offs_reordered
= addr
;
5038 addr
+= map
.name_count
* map
.offset_size
;
5040 const gdb_byte
*abbrev_table_start
= addr
;
5043 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5048 const auto insertpair
5049 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5050 if (!insertpair
.second
)
5052 warning (_("Section .debug_names in %s has duplicate index %s, "
5053 "ignoring .debug_names."),
5054 filename
, pulongest (index_num
));
5057 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5058 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5063 mapped_debug_names::index_val::attr attr
;
5064 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5066 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5068 if (attr
.form
== DW_FORM_implicit_const
)
5070 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5074 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5076 indexval
.attr_vec
.push_back (std::move (attr
));
5079 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5081 warning (_("Section .debug_names in %s has abbreviation_table "
5082 "of size %s vs. written as %u, ignoring .debug_names."),
5083 filename
, plongest (addr
- abbrev_table_start
),
5087 map
.entry_pool
= addr
;
5092 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5096 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5097 const mapped_debug_names
&map
,
5098 dwarf2_section_info
§ion
,
5101 if (!map
.augmentation_is_gdb
)
5103 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5105 sect_offset sect_off
5106 = (sect_offset
) (extract_unsigned_integer
5107 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5109 map
.dwarf5_byte_order
));
5110 /* We don't know the length of the CU, because the CU list in a
5111 .debug_names index can be incomplete, so we can't use the start of
5112 the next CU as end of this CU. We create the CUs here with length 0,
5113 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5114 dwarf2_per_cu_data
*per_cu
5115 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5117 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5121 sect_offset sect_off_prev
;
5122 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5124 sect_offset sect_off_next
;
5125 if (i
< map
.cu_count
)
5128 = (sect_offset
) (extract_unsigned_integer
5129 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5131 map
.dwarf5_byte_order
));
5134 sect_off_next
= (sect_offset
) section
.size
;
5137 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5138 dwarf2_per_cu_data
*per_cu
5139 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5140 sect_off_prev
, length
);
5141 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (per_cu
);
5143 sect_off_prev
= sect_off_next
;
5147 /* Read the CU list from the mapped index, and use it to create all
5148 the CU objects for this dwarf2_per_objfile. */
5151 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5152 const mapped_debug_names
&map
,
5153 const mapped_debug_names
&dwz_map
)
5155 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
5156 dwarf2_per_objfile
->per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5158 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5159 dwarf2_per_objfile
->per_bfd
->info
,
5160 false /* is_dwz */);
5162 if (dwz_map
.cu_count
== 0)
5165 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5166 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5170 /* Read .debug_names. If everything went ok, initialize the "quick"
5171 elements of all the CUs and return true. Otherwise, return false. */
5174 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5176 std::unique_ptr
<mapped_debug_names
> map
5177 (new mapped_debug_names (dwarf2_per_objfile
));
5178 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5179 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5181 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5182 &dwarf2_per_objfile
->per_bfd
->debug_names
,
5186 /* Don't use the index if it's empty. */
5187 if (map
->name_count
== 0)
5190 /* If there is a .dwz file, read it so we can get its CU list as
5192 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5195 if (!read_debug_names_from_section (objfile
,
5196 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5197 &dwz
->debug_names
, dwz_map
))
5199 warning (_("could not read '.debug_names' section from %s; skipping"),
5200 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5205 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5207 if (map
->tu_count
!= 0)
5209 /* We can only handle a single .debug_types when we have an
5211 if (dwarf2_per_objfile
->per_bfd
->types
.size () != 1)
5214 dwarf2_section_info
*section
= &dwarf2_per_objfile
->per_bfd
->types
[0];
5216 create_signatured_type_table_from_debug_names
5217 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->per_bfd
->abbrev
);
5220 create_addrmap_from_aranges (dwarf2_per_objfile
,
5221 &dwarf2_per_objfile
->per_bfd
->debug_aranges
);
5223 dwarf2_per_objfile
->per_bfd
->debug_names_table
= std::move (map
);
5224 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5225 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
=
5226 create_quick_file_names_table (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5231 /* Type used to manage iterating over all CUs looking for a symbol for
5234 class dw2_debug_names_iterator
5237 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5238 gdb::optional
<block_enum
> block_index
,
5241 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5242 m_addr (find_vec_in_debug_names (map
, name
))
5245 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5246 search_domain search
, uint32_t namei
)
5249 m_addr (find_vec_in_debug_names (map
, namei
))
5252 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5253 block_enum block_index
, domain_enum domain
,
5255 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5256 m_addr (find_vec_in_debug_names (map
, namei
))
5259 /* Return the next matching CU or NULL if there are no more. */
5260 dwarf2_per_cu_data
*next ();
5263 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5265 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5268 /* The internalized form of .debug_names. */
5269 const mapped_debug_names
&m_map
;
5271 /* If set, only look for symbols that match that block. Valid values are
5272 GLOBAL_BLOCK and STATIC_BLOCK. */
5273 const gdb::optional
<block_enum
> m_block_index
;
5275 /* The kind of symbol we're looking for. */
5276 const domain_enum m_domain
= UNDEF_DOMAIN
;
5277 const search_domain m_search
= ALL_DOMAIN
;
5279 /* The list of CUs from the index entry of the symbol, or NULL if
5281 const gdb_byte
*m_addr
;
5285 mapped_debug_names::namei_to_name (uint32_t namei
) const
5287 const ULONGEST namei_string_offs
5288 = extract_unsigned_integer ((name_table_string_offs_reordered
5289 + namei
* offset_size
),
5292 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5296 /* Find a slot in .debug_names for the object named NAME. If NAME is
5297 found, return pointer to its pool data. If NAME cannot be found,
5301 dw2_debug_names_iterator::find_vec_in_debug_names
5302 (const mapped_debug_names
&map
, const char *name
)
5304 int (*cmp
) (const char *, const char *);
5306 gdb::unique_xmalloc_ptr
<char> without_params
;
5307 if (current_language
->la_language
== language_cplus
5308 || current_language
->la_language
== language_fortran
5309 || current_language
->la_language
== language_d
)
5311 /* NAME is already canonical. Drop any qualifiers as
5312 .debug_names does not contain any. */
5314 if (strchr (name
, '(') != NULL
)
5316 without_params
= cp_remove_params (name
);
5317 if (without_params
!= NULL
)
5318 name
= without_params
.get ();
5322 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5324 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5326 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5327 (map
.bucket_table_reordered
5328 + (full_hash
% map
.bucket_count
)), 4,
5329 map
.dwarf5_byte_order
);
5333 if (namei
>= map
.name_count
)
5335 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5337 namei
, map
.name_count
,
5338 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5344 const uint32_t namei_full_hash
5345 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5346 (map
.hash_table_reordered
+ namei
), 4,
5347 map
.dwarf5_byte_order
);
5348 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5351 if (full_hash
== namei_full_hash
)
5353 const char *const namei_string
= map
.namei_to_name (namei
);
5355 #if 0 /* An expensive sanity check. */
5356 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5358 complaint (_("Wrong .debug_names hash for string at index %u "
5360 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5365 if (cmp (namei_string
, name
) == 0)
5367 const ULONGEST namei_entry_offs
5368 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5369 + namei
* map
.offset_size
),
5370 map
.offset_size
, map
.dwarf5_byte_order
);
5371 return map
.entry_pool
+ namei_entry_offs
;
5376 if (namei
>= map
.name_count
)
5382 dw2_debug_names_iterator::find_vec_in_debug_names
5383 (const mapped_debug_names
&map
, uint32_t namei
)
5385 if (namei
>= map
.name_count
)
5387 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5389 namei
, map
.name_count
,
5390 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5394 const ULONGEST namei_entry_offs
5395 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5396 + namei
* map
.offset_size
),
5397 map
.offset_size
, map
.dwarf5_byte_order
);
5398 return map
.entry_pool
+ namei_entry_offs
;
5401 /* See dw2_debug_names_iterator. */
5403 dwarf2_per_cu_data
*
5404 dw2_debug_names_iterator::next ()
5409 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5410 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5411 bfd
*const abfd
= objfile
->obfd
;
5415 unsigned int bytes_read
;
5416 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5417 m_addr
+= bytes_read
;
5421 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5422 if (indexval_it
== m_map
.abbrev_map
.cend ())
5424 complaint (_("Wrong .debug_names undefined abbrev code %s "
5426 pulongest (abbrev
), objfile_name (objfile
));
5429 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5430 enum class symbol_linkage
{
5434 } symbol_linkage_
= symbol_linkage::unknown
;
5435 dwarf2_per_cu_data
*per_cu
= NULL
;
5436 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5441 case DW_FORM_implicit_const
:
5442 ull
= attr
.implicit_const
;
5444 case DW_FORM_flag_present
:
5448 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5449 m_addr
+= bytes_read
;
5452 ull
= read_4_bytes (abfd
, m_addr
);
5456 ull
= read_8_bytes (abfd
, m_addr
);
5459 case DW_FORM_ref_sig8
:
5460 ull
= read_8_bytes (abfd
, m_addr
);
5464 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5465 dwarf_form_name (attr
.form
),
5466 objfile_name (objfile
));
5469 switch (attr
.dw_idx
)
5471 case DW_IDX_compile_unit
:
5472 /* Don't crash on bad data. */
5473 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ())
5475 complaint (_(".debug_names entry has bad CU index %s"
5478 objfile_name (dwarf2_per_objfile
->objfile
));
5481 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (ull
);
5483 case DW_IDX_type_unit
:
5484 /* Don't crash on bad data. */
5485 if (ull
>= dwarf2_per_objfile
->per_bfd
->all_type_units
.size ())
5487 complaint (_(".debug_names entry has bad TU index %s"
5490 objfile_name (dwarf2_per_objfile
->objfile
));
5493 per_cu
= &dwarf2_per_objfile
->per_bfd
->get_tu (ull
)->per_cu
;
5495 case DW_IDX_die_offset
:
5496 /* In a per-CU index (as opposed to a per-module index), index
5497 entries without CU attribute implicitly refer to the single CU. */
5499 per_cu
= dwarf2_per_objfile
->per_bfd
->get_cu (0);
5501 case DW_IDX_GNU_internal
:
5502 if (!m_map
.augmentation_is_gdb
)
5504 symbol_linkage_
= symbol_linkage::static_
;
5506 case DW_IDX_GNU_external
:
5507 if (!m_map
.augmentation_is_gdb
)
5509 symbol_linkage_
= symbol_linkage::extern_
;
5514 /* Skip if already read in. */
5515 if (dwarf2_per_objfile
->symtab_set_p (per_cu
))
5518 /* Check static vs global. */
5519 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5521 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5522 const bool symbol_is_static
=
5523 symbol_linkage_
== symbol_linkage::static_
;
5524 if (want_static
!= symbol_is_static
)
5528 /* Match dw2_symtab_iter_next, symbol_kind
5529 and debug_names::psymbol_tag. */
5533 switch (indexval
.dwarf_tag
)
5535 case DW_TAG_variable
:
5536 case DW_TAG_subprogram
:
5537 /* Some types are also in VAR_DOMAIN. */
5538 case DW_TAG_typedef
:
5539 case DW_TAG_structure_type
:
5546 switch (indexval
.dwarf_tag
)
5548 case DW_TAG_typedef
:
5549 case DW_TAG_structure_type
:
5556 switch (indexval
.dwarf_tag
)
5559 case DW_TAG_variable
:
5566 switch (indexval
.dwarf_tag
)
5578 /* Match dw2_expand_symtabs_matching, symbol_kind and
5579 debug_names::psymbol_tag. */
5582 case VARIABLES_DOMAIN
:
5583 switch (indexval
.dwarf_tag
)
5585 case DW_TAG_variable
:
5591 case FUNCTIONS_DOMAIN
:
5592 switch (indexval
.dwarf_tag
)
5594 case DW_TAG_subprogram
:
5601 switch (indexval
.dwarf_tag
)
5603 case DW_TAG_typedef
:
5604 case DW_TAG_structure_type
:
5610 case MODULES_DOMAIN
:
5611 switch (indexval
.dwarf_tag
)
5625 static struct compunit_symtab
*
5626 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5627 const char *name
, domain_enum domain
)
5629 struct dwarf2_per_objfile
*dwarf2_per_objfile
5630 = get_dwarf2_per_objfile (objfile
);
5632 const auto &mapp
= dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5635 /* index is NULL if OBJF_READNOW. */
5638 const auto &map
= *mapp
;
5640 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5642 struct compunit_symtab
*stab_best
= NULL
;
5643 struct dwarf2_per_cu_data
*per_cu
;
5644 while ((per_cu
= iter
.next ()) != NULL
)
5646 struct symbol
*sym
, *with_opaque
= NULL
;
5647 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5648 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5649 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5651 sym
= block_find_symbol (block
, name
, domain
,
5652 block_find_non_opaque_type_preferred
,
5655 /* Some caution must be observed with overloaded functions and
5656 methods, since the index will not contain any overload
5657 information (but NAME might contain it). */
5660 && strcmp_iw (sym
->search_name (), name
) == 0)
5662 if (with_opaque
!= NULL
5663 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5666 /* Keep looking through other CUs. */
5672 /* This dumps minimal information about .debug_names. It is called
5673 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5674 uses this to verify that .debug_names has been loaded. */
5677 dw2_debug_names_dump (struct objfile
*objfile
)
5679 struct dwarf2_per_objfile
*dwarf2_per_objfile
5680 = get_dwarf2_per_objfile (objfile
);
5682 gdb_assert (dwarf2_per_objfile
->per_bfd
->using_index
);
5683 printf_filtered (".debug_names:");
5684 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5685 printf_filtered (" exists\n");
5687 printf_filtered (" faked for \"readnow\"\n");
5688 printf_filtered ("\n");
5692 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5693 const char *func_name
)
5695 struct dwarf2_per_objfile
*dwarf2_per_objfile
5696 = get_dwarf2_per_objfile (objfile
);
5698 /* dwarf2_per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5699 if (dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5701 const mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5703 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5705 struct dwarf2_per_cu_data
*per_cu
;
5706 while ((per_cu
= iter
.next ()) != NULL
)
5707 dw2_instantiate_symtab (per_cu
, false);
5712 dw2_debug_names_map_matching_symbols
5713 (struct objfile
*objfile
,
5714 const lookup_name_info
&name
, domain_enum domain
,
5716 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5717 symbol_compare_ftype
*ordered_compare
)
5719 struct dwarf2_per_objfile
*dwarf2_per_objfile
5720 = get_dwarf2_per_objfile (objfile
);
5722 /* debug_names_table is NULL if OBJF_READNOW. */
5723 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5726 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5727 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5729 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5730 auto matcher
= [&] (const char *symname
)
5732 if (ordered_compare
== nullptr)
5734 return ordered_compare (symname
, match_name
) == 0;
5737 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5738 [&] (offset_type namei
)
5740 /* The name was matched, now expand corresponding CUs that were
5742 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5744 struct dwarf2_per_cu_data
*per_cu
;
5745 while ((per_cu
= iter
.next ()) != NULL
)
5746 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5750 /* It's a shame we couldn't do this inside the
5751 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5752 that have already been expanded. Instead, this loop matches what
5753 the psymtab code does. */
5754 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5756 compunit_symtab
*symtab
= dwarf2_per_objfile
->get_symtab (per_cu
);
5757 if (symtab
!= nullptr)
5759 const struct block
*block
5760 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5761 if (!iterate_over_symbols_terminated (block
, name
,
5769 dw2_debug_names_expand_symtabs_matching
5770 (struct objfile
*objfile
,
5771 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5772 const lookup_name_info
*lookup_name
,
5773 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5774 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5775 enum search_domain kind
)
5777 struct dwarf2_per_objfile
*dwarf2_per_objfile
5778 = get_dwarf2_per_objfile (objfile
);
5780 /* debug_names_table is NULL if OBJF_READNOW. */
5781 if (!dwarf2_per_objfile
->per_bfd
->debug_names_table
)
5784 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5786 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5788 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
5792 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5798 mapped_debug_names
&map
= *dwarf2_per_objfile
->per_bfd
->debug_names_table
;
5800 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5802 kind
, [&] (offset_type namei
)
5804 /* The name was matched, now expand corresponding CUs that were
5806 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5808 struct dwarf2_per_cu_data
*per_cu
;
5809 while ((per_cu
= iter
.next ()) != NULL
)
5810 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5816 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5819 dw2_find_last_source_symtab
,
5820 dw2_forget_cached_source_info
,
5821 dw2_map_symtabs_matching_filename
,
5822 dw2_debug_names_lookup_symbol
,
5825 dw2_debug_names_dump
,
5826 dw2_debug_names_expand_symtabs_for_function
,
5827 dw2_expand_all_symtabs
,
5828 dw2_expand_symtabs_with_fullname
,
5829 dw2_debug_names_map_matching_symbols
,
5830 dw2_debug_names_expand_symtabs_matching
,
5831 dw2_find_pc_sect_compunit_symtab
,
5833 dw2_map_symbol_filenames
5836 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5837 to either a dwarf2_per_bfd or dwz_file object. */
5839 template <typename T
>
5840 static gdb::array_view
<const gdb_byte
>
5841 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5843 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5845 if (section
->empty ())
5848 /* Older elfutils strip versions could keep the section in the main
5849 executable while splitting it for the separate debug info file. */
5850 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5853 section
->read (obj
);
5855 /* dwarf2_section_info::size is a bfd_size_type, while
5856 gdb::array_view works with size_t. On 32-bit hosts, with
5857 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5858 is 32-bit. So we need an explicit narrowing conversion here.
5859 This is fine, because it's impossible to allocate or mmap an
5860 array/buffer larger than what size_t can represent. */
5861 return gdb::make_array_view (section
->buffer
, section
->size
);
5864 /* Lookup the index cache for the contents of the index associated to
5867 static gdb::array_view
<const gdb_byte
>
5868 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5870 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5871 if (build_id
== nullptr)
5874 return global_index_cache
.lookup_gdb_index (build_id
,
5875 &dwarf2_per_bfd
->index_cache_res
);
5878 /* Same as the above, but for DWZ. */
5880 static gdb::array_view
<const gdb_byte
>
5881 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5883 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5884 if (build_id
== nullptr)
5887 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5890 /* See symfile.h. */
5893 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5895 struct dwarf2_per_objfile
*dwarf2_per_objfile
5896 = get_dwarf2_per_objfile (objfile
);
5898 /* If we're about to read full symbols, don't bother with the
5899 indices. In this case we also don't care if some other debug
5900 format is making psymtabs, because they are all about to be
5902 if ((objfile
->flags
& OBJF_READNOW
))
5904 dwarf2_per_objfile
->per_bfd
->using_index
= 1;
5905 create_all_comp_units (dwarf2_per_objfile
);
5906 create_all_type_units (dwarf2_per_objfile
);
5907 dwarf2_per_objfile
->per_bfd
->quick_file_names_table
5908 = create_quick_file_names_table
5909 (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ());
5910 dwarf2_per_objfile
->resize_symtabs ();
5912 for (int i
= 0; i
< (dwarf2_per_objfile
->per_bfd
->all_comp_units
.size ()
5913 + dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()); ++i
)
5915 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->per_bfd
->get_cutu (i
);
5917 per_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
5918 struct dwarf2_per_cu_quick_data
);
5921 /* Return 1 so that gdb sees the "quick" functions. However,
5922 these functions will be no-ops because we will have expanded
5924 *index_kind
= dw_index_kind::GDB_INDEX
;
5928 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5930 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5931 dwarf2_per_objfile
->resize_symtabs ();
5935 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5936 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5937 get_gdb_index_contents_from_section
<dwz_file
>))
5939 *index_kind
= dw_index_kind::GDB_INDEX
;
5940 dwarf2_per_objfile
->resize_symtabs ();
5944 /* ... otherwise, try to find the index in the index cache. */
5945 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5946 get_gdb_index_contents_from_cache
,
5947 get_gdb_index_contents_from_cache_dwz
))
5949 global_index_cache
.hit ();
5950 *index_kind
= dw_index_kind::GDB_INDEX
;
5951 dwarf2_per_objfile
->resize_symtabs ();
5955 global_index_cache
.miss ();
5961 /* Build a partial symbol table. */
5964 dwarf2_build_psymtabs (struct objfile
*objfile
)
5966 struct dwarf2_per_objfile
*dwarf2_per_objfile
5967 = get_dwarf2_per_objfile (objfile
);
5969 init_psymbol_list (objfile
, 1024);
5973 /* This isn't really ideal: all the data we allocate on the
5974 objfile's obstack is still uselessly kept around. However,
5975 freeing it seems unsafe. */
5976 psymtab_discarder
psymtabs (objfile
);
5977 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5980 dwarf2_per_objfile
->resize_symtabs ();
5982 /* (maybe) store an index in the cache. */
5983 global_index_cache
.store (dwarf2_per_objfile
);
5985 catch (const gdb_exception_error
&except
)
5987 exception_print (gdb_stderr
, except
);
5991 /* Find the base address of the compilation unit for range lists and
5992 location lists. It will normally be specified by DW_AT_low_pc.
5993 In DWARF-3 draft 4, the base address could be overridden by
5994 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5995 compilation units with discontinuous ranges. */
5998 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6000 struct attribute
*attr
;
6002 cu
->base_address
.reset ();
6004 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6005 if (attr
!= nullptr)
6006 cu
->base_address
= attr
->value_as_address ();
6009 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6010 if (attr
!= nullptr)
6011 cu
->base_address
= attr
->value_as_address ();
6015 /* Helper function that returns the proper abbrev section for
6018 static struct dwarf2_section_info
*
6019 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6021 struct dwarf2_section_info
*abbrev
;
6022 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6024 if (this_cu
->is_dwz
)
6025 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6027 abbrev
= &dwarf2_per_objfile
->per_bfd
->abbrev
;
6032 /* Fetch the abbreviation table offset from a comp or type unit header. */
6035 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6036 struct dwarf2_section_info
*section
,
6037 sect_offset sect_off
)
6039 bfd
*abfd
= section
->get_bfd_owner ();
6040 const gdb_byte
*info_ptr
;
6041 unsigned int initial_length_size
, offset_size
;
6044 section
->read (dwarf2_per_objfile
->objfile
);
6045 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6046 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6047 offset_size
= initial_length_size
== 4 ? 4 : 8;
6048 info_ptr
+= initial_length_size
;
6050 version
= read_2_bytes (abfd
, info_ptr
);
6054 /* Skip unit type and address size. */
6058 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6061 /* A partial symtab that is used only for include files. */
6062 struct dwarf2_include_psymtab
: public partial_symtab
6064 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6065 : partial_symtab (filename
, objfile
)
6069 void read_symtab (struct objfile
*objfile
) override
6071 /* It's an include file, no symbols to read for it.
6072 Everything is in the includer symtab. */
6074 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6075 expansion of the includer psymtab. We use the dependencies[0] field to
6076 model the includer. But if we go the regular route of calling
6077 expand_psymtab here, and having expand_psymtab call expand_dependencies
6078 to expand the includer, we'll only use expand_psymtab on the includer
6079 (making it a non-toplevel psymtab), while if we expand the includer via
6080 another path, we'll use read_symtab (making it a toplevel psymtab).
6081 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6082 psymtab, and trigger read_symtab on the includer here directly. */
6083 includer ()->read_symtab (objfile
);
6086 void expand_psymtab (struct objfile
*objfile
) override
6088 /* This is not called by read_symtab, and should not be called by any
6089 expand_dependencies. */
6093 bool readin_p (struct objfile
*objfile
) const override
6095 return includer ()->readin_p (objfile
);
6098 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6104 partial_symtab
*includer () const
6106 /* An include psymtab has exactly one dependency: the psymtab that
6108 gdb_assert (this->number_of_dependencies
== 1);
6109 return this->dependencies
[0];
6113 /* Allocate a new partial symtab for file named NAME and mark this new
6114 partial symtab as being an include of PST. */
6117 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6118 struct objfile
*objfile
)
6120 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6122 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6123 subpst
->dirname
= pst
->dirname
;
6125 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6126 subpst
->dependencies
[0] = pst
;
6127 subpst
->number_of_dependencies
= 1;
6130 /* Read the Line Number Program data and extract the list of files
6131 included by the source file represented by PST. Build an include
6132 partial symtab for each of these included files. */
6135 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6136 struct die_info
*die
,
6137 dwarf2_psymtab
*pst
)
6140 struct attribute
*attr
;
6142 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6143 if (attr
!= nullptr)
6144 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6146 return; /* No linetable, so no includes. */
6148 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6149 that we pass in the raw text_low here; that is ok because we're
6150 only decoding the line table to make include partial symtabs, and
6151 so the addresses aren't really used. */
6152 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6153 pst
->raw_text_low (), 1);
6157 hash_signatured_type (const void *item
)
6159 const struct signatured_type
*sig_type
6160 = (const struct signatured_type
*) item
;
6162 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6163 return sig_type
->signature
;
6167 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6169 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6170 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6172 return lhs
->signature
== rhs
->signature
;
6175 /* Allocate a hash table for signatured types. */
6178 allocate_signatured_type_table ()
6180 return htab_up (htab_create_alloc (41,
6181 hash_signatured_type
,
6183 NULL
, xcalloc
, xfree
));
6186 /* A helper function to add a signatured type CU to a table. */
6189 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6191 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6192 std::vector
<signatured_type
*> *all_type_units
6193 = (std::vector
<signatured_type
*> *) datum
;
6195 all_type_units
->push_back (sigt
);
6200 /* A helper for create_debug_types_hash_table. Read types from SECTION
6201 and fill them into TYPES_HTAB. It will process only type units,
6202 therefore DW_UT_type. */
6205 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6206 struct dwo_file
*dwo_file
,
6207 dwarf2_section_info
*section
, htab_up
&types_htab
,
6208 rcuh_kind section_kind
)
6210 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6211 struct dwarf2_section_info
*abbrev_section
;
6213 const gdb_byte
*info_ptr
, *end_ptr
;
6215 abbrev_section
= (dwo_file
!= NULL
6216 ? &dwo_file
->sections
.abbrev
6217 : &dwarf2_per_objfile
->per_bfd
->abbrev
);
6219 if (dwarf_read_debug
)
6220 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6221 section
->get_name (),
6222 abbrev_section
->get_file_name ());
6224 section
->read (objfile
);
6225 info_ptr
= section
->buffer
;
6227 if (info_ptr
== NULL
)
6230 /* We can't set abfd until now because the section may be empty or
6231 not present, in which case the bfd is unknown. */
6232 abfd
= section
->get_bfd_owner ();
6234 /* We don't use cutu_reader here because we don't need to read
6235 any dies: the signature is in the header. */
6237 end_ptr
= info_ptr
+ section
->size
;
6238 while (info_ptr
< end_ptr
)
6240 struct signatured_type
*sig_type
;
6241 struct dwo_unit
*dwo_tu
;
6243 const gdb_byte
*ptr
= info_ptr
;
6244 struct comp_unit_head header
;
6245 unsigned int length
;
6247 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6249 /* Initialize it due to a false compiler warning. */
6250 header
.signature
= -1;
6251 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6253 /* We need to read the type's signature in order to build the hash
6254 table, but we don't need anything else just yet. */
6256 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6257 abbrev_section
, ptr
, section_kind
);
6259 length
= header
.get_length ();
6261 /* Skip dummy type units. */
6262 if (ptr
>= info_ptr
+ length
6263 || peek_abbrev_code (abfd
, ptr
) == 0
6264 || header
.unit_type
!= DW_UT_type
)
6270 if (types_htab
== NULL
)
6273 types_htab
= allocate_dwo_unit_table ();
6275 types_htab
= allocate_signatured_type_table ();
6281 dwo_tu
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6283 dwo_tu
->dwo_file
= dwo_file
;
6284 dwo_tu
->signature
= header
.signature
;
6285 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6286 dwo_tu
->section
= section
;
6287 dwo_tu
->sect_off
= sect_off
;
6288 dwo_tu
->length
= length
;
6292 /* N.B.: type_offset is not usable if this type uses a DWO file.
6293 The real type_offset is in the DWO file. */
6295 sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6296 sig_type
->signature
= header
.signature
;
6297 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6298 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6299 sig_type
->per_cu
.is_debug_types
= 1;
6300 sig_type
->per_cu
.section
= section
;
6301 sig_type
->per_cu
.sect_off
= sect_off
;
6302 sig_type
->per_cu
.length
= length
;
6305 slot
= htab_find_slot (types_htab
.get (),
6306 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6308 gdb_assert (slot
!= NULL
);
6311 sect_offset dup_sect_off
;
6315 const struct dwo_unit
*dup_tu
6316 = (const struct dwo_unit
*) *slot
;
6318 dup_sect_off
= dup_tu
->sect_off
;
6322 const struct signatured_type
*dup_tu
6323 = (const struct signatured_type
*) *slot
;
6325 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6328 complaint (_("debug type entry at offset %s is duplicate to"
6329 " the entry at offset %s, signature %s"),
6330 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6331 hex_string (header
.signature
));
6333 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6335 if (dwarf_read_debug
> 1)
6336 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6337 sect_offset_str (sect_off
),
6338 hex_string (header
.signature
));
6344 /* Create the hash table of all entries in the .debug_types
6345 (or .debug_types.dwo) section(s).
6346 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6347 otherwise it is NULL.
6349 The result is a pointer to the hash table or NULL if there are no types.
6351 Note: This function processes DWO files only, not DWP files. */
6354 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6355 struct dwo_file
*dwo_file
,
6356 gdb::array_view
<dwarf2_section_info
> type_sections
,
6357 htab_up
&types_htab
)
6359 for (dwarf2_section_info
§ion
: type_sections
)
6360 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6361 types_htab
, rcuh_kind::TYPE
);
6364 /* Create the hash table of all entries in the .debug_types section,
6365 and initialize all_type_units.
6366 The result is zero if there is an error (e.g. missing .debug_types section),
6367 otherwise non-zero. */
6370 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6374 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6375 &dwarf2_per_objfile
->per_bfd
->info
, types_htab
,
6376 rcuh_kind::COMPILE
);
6377 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6378 dwarf2_per_objfile
->per_bfd
->types
, types_htab
);
6379 if (types_htab
== NULL
)
6381 dwarf2_per_objfile
->per_bfd
->signatured_types
= NULL
;
6385 dwarf2_per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6387 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ());
6388 dwarf2_per_objfile
->per_bfd
->all_type_units
.reserve
6389 (htab_elements (dwarf2_per_objfile
->per_bfd
->signatured_types
.get ()));
6391 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6392 add_signatured_type_cu_to_table
,
6393 &dwarf2_per_objfile
->per_bfd
->all_type_units
);
6398 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6399 If SLOT is non-NULL, it is the entry to use in the hash table.
6400 Otherwise we find one. */
6402 static struct signatured_type
*
6403 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6406 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ()
6407 == dwarf2_per_objfile
->per_bfd
->all_type_units
.capacity ())
6408 ++dwarf2_per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6410 signatured_type
*sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
6412 dwarf2_per_objfile
->resize_symtabs ();
6414 dwarf2_per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6415 sig_type
->signature
= sig
;
6416 sig_type
->per_cu
.is_debug_types
= 1;
6417 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6419 sig_type
->per_cu
.v
.quick
=
6420 OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
6421 struct dwarf2_per_cu_quick_data
);
6426 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6429 gdb_assert (*slot
== NULL
);
6431 /* The rest of sig_type must be filled in by the caller. */
6435 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6436 Fill in SIG_ENTRY with DWO_ENTRY. */
6439 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6440 struct signatured_type
*sig_entry
,
6441 struct dwo_unit
*dwo_entry
)
6443 /* Make sure we're not clobbering something we don't expect to. */
6444 gdb_assert (! sig_entry
->per_cu
.queued
);
6445 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6446 if (dwarf2_per_objfile
->per_bfd
->using_index
)
6448 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6449 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6452 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6453 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6454 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6455 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6456 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6458 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6459 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6460 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6461 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6462 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6463 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6464 sig_entry
->dwo_unit
= dwo_entry
;
6467 /* Subroutine of lookup_signatured_type.
6468 If we haven't read the TU yet, create the signatured_type data structure
6469 for a TU to be read in directly from a DWO file, bypassing the stub.
6470 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6471 using .gdb_index, then when reading a CU we want to stay in the DWO file
6472 containing that CU. Otherwise we could end up reading several other DWO
6473 files (due to comdat folding) to process the transitive closure of all the
6474 mentioned TUs, and that can be slow. The current DWO file will have every
6475 type signature that it needs.
6476 We only do this for .gdb_index because in the psymtab case we already have
6477 to read all the DWOs to build the type unit groups. */
6479 static struct signatured_type
*
6480 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6482 struct dwarf2_per_objfile
*dwarf2_per_objfile
6483 = cu
->per_cu
->dwarf2_per_objfile
;
6484 struct dwo_file
*dwo_file
;
6485 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6486 struct signatured_type find_sig_entry
, *sig_entry
;
6489 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6491 /* If TU skeletons have been removed then we may not have read in any
6493 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6494 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6496 /* We only ever need to read in one copy of a signatured type.
6497 Use the global signatured_types array to do our own comdat-folding
6498 of types. If this is the first time we're reading this TU, and
6499 the TU has an entry in .gdb_index, replace the recorded data from
6500 .gdb_index with this TU. */
6502 find_sig_entry
.signature
= sig
;
6503 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6504 &find_sig_entry
, INSERT
);
6505 sig_entry
= (struct signatured_type
*) *slot
;
6507 /* We can get here with the TU already read, *or* in the process of being
6508 read. Don't reassign the global entry to point to this DWO if that's
6509 the case. Also note that if the TU is already being read, it may not
6510 have come from a DWO, the program may be a mix of Fission-compiled
6511 code and non-Fission-compiled code. */
6513 /* Have we already tried to read this TU?
6514 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6515 needn't exist in the global table yet). */
6516 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6519 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6520 dwo_unit of the TU itself. */
6521 dwo_file
= cu
->dwo_unit
->dwo_file
;
6523 /* Ok, this is the first time we're reading this TU. */
6524 if (dwo_file
->tus
== NULL
)
6526 find_dwo_entry
.signature
= sig
;
6527 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6529 if (dwo_entry
== NULL
)
6532 /* If the global table doesn't have an entry for this TU, add one. */
6533 if (sig_entry
== NULL
)
6534 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6536 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6537 sig_entry
->per_cu
.tu_read
= 1;
6541 /* Subroutine of lookup_signatured_type.
6542 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6543 then try the DWP file. If the TU stub (skeleton) has been removed then
6544 it won't be in .gdb_index. */
6546 static struct signatured_type
*
6547 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6549 struct dwarf2_per_objfile
*dwarf2_per_objfile
6550 = cu
->per_cu
->dwarf2_per_objfile
;
6551 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6552 struct dwo_unit
*dwo_entry
;
6553 struct signatured_type find_sig_entry
, *sig_entry
;
6556 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->per_bfd
->using_index
);
6557 gdb_assert (dwp_file
!= NULL
);
6559 /* If TU skeletons have been removed then we may not have read in any
6561 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6562 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6564 find_sig_entry
.signature
= sig
;
6565 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6566 &find_sig_entry
, INSERT
);
6567 sig_entry
= (struct signatured_type
*) *slot
;
6569 /* Have we already tried to read this TU?
6570 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6571 needn't exist in the global table yet). */
6572 if (sig_entry
!= NULL
)
6575 if (dwp_file
->tus
== NULL
)
6577 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6578 sig
, 1 /* is_debug_types */);
6579 if (dwo_entry
== NULL
)
6582 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6583 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6588 /* Lookup a signature based type for DW_FORM_ref_sig8.
6589 Returns NULL if signature SIG is not present in the table.
6590 It is up to the caller to complain about this. */
6592 static struct signatured_type
*
6593 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6595 struct dwarf2_per_objfile
*dwarf2_per_objfile
6596 = cu
->per_cu
->dwarf2_per_objfile
;
6599 && dwarf2_per_objfile
->per_bfd
->using_index
)
6601 /* We're in a DWO/DWP file, and we're using .gdb_index.
6602 These cases require special processing. */
6603 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6604 return lookup_dwo_signatured_type (cu
, sig
);
6606 return lookup_dwp_signatured_type (cu
, sig
);
6610 struct signatured_type find_entry
, *entry
;
6612 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
6614 find_entry
.signature
= sig
;
6615 entry
= ((struct signatured_type
*)
6616 htab_find (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
6622 /* Low level DIE reading support. */
6624 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6627 init_cu_die_reader (struct die_reader_specs
*reader
,
6628 struct dwarf2_cu
*cu
,
6629 struct dwarf2_section_info
*section
,
6630 struct dwo_file
*dwo_file
,
6631 struct abbrev_table
*abbrev_table
)
6633 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6634 reader
->abfd
= section
->get_bfd_owner ();
6636 reader
->dwo_file
= dwo_file
;
6637 reader
->die_section
= section
;
6638 reader
->buffer
= section
->buffer
;
6639 reader
->buffer_end
= section
->buffer
+ section
->size
;
6640 reader
->abbrev_table
= abbrev_table
;
6643 /* Subroutine of cutu_reader to simplify it.
6644 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6645 There's just a lot of work to do, and cutu_reader is big enough
6648 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6649 from it to the DIE in the DWO. If NULL we are skipping the stub.
6650 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6651 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6652 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6653 STUB_COMP_DIR may be non-NULL.
6654 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6655 are filled in with the info of the DIE from the DWO file.
6656 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6657 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6658 kept around for at least as long as *RESULT_READER.
6660 The result is non-zero if a valid (non-dummy) DIE was found. */
6663 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6664 struct dwo_unit
*dwo_unit
,
6665 struct die_info
*stub_comp_unit_die
,
6666 const char *stub_comp_dir
,
6667 struct die_reader_specs
*result_reader
,
6668 const gdb_byte
**result_info_ptr
,
6669 struct die_info
**result_comp_unit_die
,
6670 abbrev_table_up
*result_dwo_abbrev_table
)
6672 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6673 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6674 struct dwarf2_cu
*cu
= this_cu
->cu
;
6676 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6677 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6678 int i
,num_extra_attrs
;
6679 struct dwarf2_section_info
*dwo_abbrev_section
;
6680 struct die_info
*comp_unit_die
;
6682 /* At most one of these may be provided. */
6683 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6685 /* These attributes aren't processed until later:
6686 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6687 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6688 referenced later. However, these attributes are found in the stub
6689 which we won't have later. In order to not impose this complication
6690 on the rest of the code, we read them here and copy them to the
6699 if (stub_comp_unit_die
!= NULL
)
6701 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6703 if (! this_cu
->is_debug_types
)
6704 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6705 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6706 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6707 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6708 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6710 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6712 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6713 here (if needed). We need the value before we can process
6715 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6717 else if (stub_comp_dir
!= NULL
)
6719 /* Reconstruct the comp_dir attribute to simplify the code below. */
6720 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6721 comp_dir
->name
= DW_AT_comp_dir
;
6722 comp_dir
->form
= DW_FORM_string
;
6723 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6724 DW_STRING (comp_dir
) = stub_comp_dir
;
6727 /* Set up for reading the DWO CU/TU. */
6728 cu
->dwo_unit
= dwo_unit
;
6729 dwarf2_section_info
*section
= dwo_unit
->section
;
6730 section
->read (objfile
);
6731 abfd
= section
->get_bfd_owner ();
6732 begin_info_ptr
= info_ptr
= (section
->buffer
6733 + to_underlying (dwo_unit
->sect_off
));
6734 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6736 if (this_cu
->is_debug_types
)
6738 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6740 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6741 &cu
->header
, section
,
6743 info_ptr
, rcuh_kind::TYPE
);
6744 /* This is not an assert because it can be caused by bad debug info. */
6745 if (sig_type
->signature
!= cu
->header
.signature
)
6747 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6748 " TU at offset %s [in module %s]"),
6749 hex_string (sig_type
->signature
),
6750 hex_string (cu
->header
.signature
),
6751 sect_offset_str (dwo_unit
->sect_off
),
6752 bfd_get_filename (abfd
));
6754 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6755 /* For DWOs coming from DWP files, we don't know the CU length
6756 nor the type's offset in the TU until now. */
6757 dwo_unit
->length
= cu
->header
.get_length ();
6758 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6760 /* Establish the type offset that can be used to lookup the type.
6761 For DWO files, we don't know it until now. */
6762 sig_type
->type_offset_in_section
6763 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6767 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6768 &cu
->header
, section
,
6770 info_ptr
, rcuh_kind::COMPILE
);
6771 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6772 /* For DWOs coming from DWP files, we don't know the CU length
6774 dwo_unit
->length
= cu
->header
.get_length ();
6777 *result_dwo_abbrev_table
6778 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6779 cu
->header
.abbrev_sect_off
);
6780 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6781 result_dwo_abbrev_table
->get ());
6783 /* Read in the die, but leave space to copy over the attributes
6784 from the stub. This has the benefit of simplifying the rest of
6785 the code - all the work to maintain the illusion of a single
6786 DW_TAG_{compile,type}_unit DIE is done here. */
6787 num_extra_attrs
= ((stmt_list
!= NULL
)
6791 + (comp_dir
!= NULL
));
6792 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6795 /* Copy over the attributes from the stub to the DIE we just read in. */
6796 comp_unit_die
= *result_comp_unit_die
;
6797 i
= comp_unit_die
->num_attrs
;
6798 if (stmt_list
!= NULL
)
6799 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6801 comp_unit_die
->attrs
[i
++] = *low_pc
;
6802 if (high_pc
!= NULL
)
6803 comp_unit_die
->attrs
[i
++] = *high_pc
;
6805 comp_unit_die
->attrs
[i
++] = *ranges
;
6806 if (comp_dir
!= NULL
)
6807 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6808 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6810 if (dwarf_die_debug
)
6812 fprintf_unfiltered (gdb_stdlog
,
6813 "Read die from %s@0x%x of %s:\n",
6814 section
->get_name (),
6815 (unsigned) (begin_info_ptr
- section
->buffer
),
6816 bfd_get_filename (abfd
));
6817 dump_die (comp_unit_die
, dwarf_die_debug
);
6820 /* Skip dummy compilation units. */
6821 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6822 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6825 *result_info_ptr
= info_ptr
;
6829 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6830 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6831 signature is part of the header. */
6832 static gdb::optional
<ULONGEST
>
6833 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6835 if (cu
->header
.version
>= 5)
6836 return cu
->header
.signature
;
6837 struct attribute
*attr
;
6838 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6839 if (attr
== nullptr)
6840 return gdb::optional
<ULONGEST
> ();
6841 return DW_UNSND (attr
);
6844 /* Subroutine of cutu_reader to simplify it.
6845 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6846 Returns NULL if the specified DWO unit cannot be found. */
6848 static struct dwo_unit
*
6849 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6850 struct die_info
*comp_unit_die
,
6851 const char *dwo_name
)
6853 struct dwarf2_cu
*cu
= this_cu
->cu
;
6854 struct dwo_unit
*dwo_unit
;
6855 const char *comp_dir
;
6857 gdb_assert (cu
!= NULL
);
6859 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6860 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6861 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6863 if (this_cu
->is_debug_types
)
6865 struct signatured_type
*sig_type
;
6867 /* Since this_cu is the first member of struct signatured_type,
6868 we can go from a pointer to one to a pointer to the other. */
6869 sig_type
= (struct signatured_type
*) this_cu
;
6870 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6874 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6875 if (!signature
.has_value ())
6876 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6878 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6879 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6886 /* Subroutine of cutu_reader to simplify it.
6887 See it for a description of the parameters.
6888 Read a TU directly from a DWO file, bypassing the stub. */
6891 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6892 int use_existing_cu
)
6894 struct signatured_type
*sig_type
;
6896 /* Verify we can do the following downcast, and that we have the
6898 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6899 sig_type
= (struct signatured_type
*) this_cu
;
6900 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6902 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6904 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6905 /* There's no need to do the rereading_dwo_cu handling that
6906 cutu_reader does since we don't read the stub. */
6910 /* If !use_existing_cu, this_cu->cu must be NULL. */
6911 gdb_assert (this_cu
->cu
== NULL
);
6912 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6915 /* A future optimization, if needed, would be to use an existing
6916 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6917 could share abbrev tables. */
6919 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6920 NULL
/* stub_comp_unit_die */,
6921 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6924 &m_dwo_abbrev_table
) == 0)
6931 /* Initialize a CU (or TU) and read its DIEs.
6932 If the CU defers to a DWO file, read the DWO file as well.
6934 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6935 Otherwise the table specified in the comp unit header is read in and used.
6936 This is an optimization for when we already have the abbrev table.
6938 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6939 Otherwise, a new CU is allocated with xmalloc. */
6941 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6942 struct abbrev_table
*abbrev_table
,
6943 int use_existing_cu
,
6945 : die_reader_specs
{},
6948 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6949 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6950 struct dwarf2_section_info
*section
= this_cu
->section
;
6951 bfd
*abfd
= section
->get_bfd_owner ();
6952 struct dwarf2_cu
*cu
;
6953 const gdb_byte
*begin_info_ptr
;
6954 struct signatured_type
*sig_type
= NULL
;
6955 struct dwarf2_section_info
*abbrev_section
;
6956 /* Non-zero if CU currently points to a DWO file and we need to
6957 reread it. When this happens we need to reread the skeleton die
6958 before we can reread the DWO file (this only applies to CUs, not TUs). */
6959 int rereading_dwo_cu
= 0;
6961 if (dwarf_die_debug
)
6962 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6963 this_cu
->is_debug_types
? "type" : "comp",
6964 sect_offset_str (this_cu
->sect_off
));
6966 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6967 file (instead of going through the stub), short-circuit all of this. */
6968 if (this_cu
->reading_dwo_directly
)
6970 /* Narrow down the scope of possibilities to have to understand. */
6971 gdb_assert (this_cu
->is_debug_types
);
6972 gdb_assert (abbrev_table
== NULL
);
6973 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6977 /* This is cheap if the section is already read in. */
6978 section
->read (objfile
);
6980 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6982 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6984 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6987 /* If this CU is from a DWO file we need to start over, we need to
6988 refetch the attributes from the skeleton CU.
6989 This could be optimized by retrieving those attributes from when we
6990 were here the first time: the previous comp_unit_die was stored in
6991 comp_unit_obstack. But there's no data yet that we need this
6993 if (cu
->dwo_unit
!= NULL
)
6994 rereading_dwo_cu
= 1;
6998 /* If !use_existing_cu, this_cu->cu must be NULL. */
6999 gdb_assert (this_cu
->cu
== NULL
);
7000 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7001 cu
= m_new_cu
.get ();
7004 /* Get the header. */
7005 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7007 /* We already have the header, there's no need to read it in again. */
7008 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7012 if (this_cu
->is_debug_types
)
7014 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7015 &cu
->header
, section
,
7016 abbrev_section
, info_ptr
,
7019 /* Since per_cu is the first member of struct signatured_type,
7020 we can go from a pointer to one to a pointer to the other. */
7021 sig_type
= (struct signatured_type
*) this_cu
;
7022 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7023 gdb_assert (sig_type
->type_offset_in_tu
7024 == cu
->header
.type_cu_offset_in_tu
);
7025 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7027 /* LENGTH has not been set yet for type units if we're
7028 using .gdb_index. */
7029 this_cu
->length
= cu
->header
.get_length ();
7031 /* Establish the type offset that can be used to lookup the type. */
7032 sig_type
->type_offset_in_section
=
7033 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7035 this_cu
->dwarf_version
= cu
->header
.version
;
7039 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7040 &cu
->header
, section
,
7043 rcuh_kind::COMPILE
);
7045 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7046 if (this_cu
->length
== 0)
7047 this_cu
->length
= cu
->header
.get_length ();
7049 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7050 this_cu
->dwarf_version
= cu
->header
.version
;
7054 /* Skip dummy compilation units. */
7055 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7056 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7062 /* If we don't have them yet, read the abbrevs for this compilation unit.
7063 And if we need to read them now, make sure they're freed when we're
7065 if (abbrev_table
!= NULL
)
7066 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7069 m_abbrev_table_holder
7070 = abbrev_table::read (objfile
, abbrev_section
,
7071 cu
->header
.abbrev_sect_off
);
7072 abbrev_table
= m_abbrev_table_holder
.get ();
7075 /* Read the top level CU/TU die. */
7076 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7077 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7079 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7085 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7086 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7087 table from the DWO file and pass the ownership over to us. It will be
7088 referenced from READER, so we must make sure to free it after we're done
7091 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7092 DWO CU, that this test will fail (the attribute will not be present). */
7093 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7094 if (dwo_name
!= nullptr)
7096 struct dwo_unit
*dwo_unit
;
7097 struct die_info
*dwo_comp_unit_die
;
7099 if (comp_unit_die
->has_children
)
7101 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7102 " has children (offset %s) [in module %s]"),
7103 sect_offset_str (this_cu
->sect_off
),
7104 bfd_get_filename (abfd
));
7106 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7107 if (dwo_unit
!= NULL
)
7109 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7110 comp_unit_die
, NULL
,
7113 &m_dwo_abbrev_table
) == 0)
7119 comp_unit_die
= dwo_comp_unit_die
;
7123 /* Yikes, we couldn't find the rest of the DIE, we only have
7124 the stub. A complaint has already been logged. There's
7125 not much more we can do except pass on the stub DIE to
7126 die_reader_func. We don't want to throw an error on bad
7133 cutu_reader::keep ()
7135 /* Done, clean up. */
7136 gdb_assert (!dummy_p
);
7137 if (m_new_cu
!= NULL
)
7139 struct dwarf2_per_objfile
*dwarf2_per_objfile
7140 = m_this_cu
->dwarf2_per_objfile
;
7141 /* Link this CU into read_in_chain. */
7142 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
7143 dwarf2_per_objfile
->per_bfd
->read_in_chain
= m_this_cu
;
7144 /* The chain owns it now. */
7145 m_new_cu
.release ();
7149 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7150 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7151 assumed to have already done the lookup to find the DWO file).
7153 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7154 THIS_CU->is_debug_types, but nothing else.
7156 We fill in THIS_CU->length.
7158 THIS_CU->cu is always freed when done.
7159 This is done in order to not leave THIS_CU->cu in a state where we have
7160 to care whether it refers to the "main" CU or the DWO CU.
7162 When parent_cu is passed, it is used to provide a default value for
7163 str_offsets_base and addr_base from the parent. */
7165 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7166 struct dwarf2_cu
*parent_cu
,
7167 struct dwo_file
*dwo_file
)
7168 : die_reader_specs
{},
7171 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7172 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7173 struct dwarf2_section_info
*section
= this_cu
->section
;
7174 bfd
*abfd
= section
->get_bfd_owner ();
7175 struct dwarf2_section_info
*abbrev_section
;
7176 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7178 if (dwarf_die_debug
)
7179 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7180 this_cu
->is_debug_types
? "type" : "comp",
7181 sect_offset_str (this_cu
->sect_off
));
7183 gdb_assert (this_cu
->cu
== NULL
);
7185 abbrev_section
= (dwo_file
!= NULL
7186 ? &dwo_file
->sections
.abbrev
7187 : get_abbrev_section_for_cu (this_cu
));
7189 /* This is cheap if the section is already read in. */
7190 section
->read (objfile
);
7192 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7194 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7195 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7196 &m_new_cu
->header
, section
,
7197 abbrev_section
, info_ptr
,
7198 (this_cu
->is_debug_types
7200 : rcuh_kind::COMPILE
));
7202 if (parent_cu
!= nullptr)
7204 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7205 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7207 this_cu
->length
= m_new_cu
->header
.get_length ();
7209 /* Skip dummy compilation units. */
7210 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7211 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7217 m_abbrev_table_holder
7218 = abbrev_table::read (objfile
, abbrev_section
,
7219 m_new_cu
->header
.abbrev_sect_off
);
7221 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7222 m_abbrev_table_holder
.get ());
7223 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7227 /* Type Unit Groups.
7229 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7230 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7231 so that all types coming from the same compilation (.o file) are grouped
7232 together. A future step could be to put the types in the same symtab as
7233 the CU the types ultimately came from. */
7236 hash_type_unit_group (const void *item
)
7238 const struct type_unit_group
*tu_group
7239 = (const struct type_unit_group
*) item
;
7241 return hash_stmt_list_entry (&tu_group
->hash
);
7245 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7247 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7248 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7250 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7253 /* Allocate a hash table for type unit groups. */
7256 allocate_type_unit_groups_table ()
7258 return htab_up (htab_create_alloc (3,
7259 hash_type_unit_group
,
7261 NULL
, xcalloc
, xfree
));
7264 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7265 partial symtabs. We combine several TUs per psymtab to not let the size
7266 of any one psymtab grow too big. */
7267 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7268 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7270 /* Helper routine for get_type_unit_group.
7271 Create the type_unit_group object used to hold one or more TUs. */
7273 static struct type_unit_group
*
7274 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7276 struct dwarf2_per_objfile
*dwarf2_per_objfile
7277 = cu
->per_cu
->dwarf2_per_objfile
;
7278 struct dwarf2_per_cu_data
*per_cu
;
7279 struct type_unit_group
*tu_group
;
7281 tu_group
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7282 struct type_unit_group
);
7283 per_cu
= &tu_group
->per_cu
;
7284 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7286 if (dwarf2_per_objfile
->per_bfd
->using_index
)
7288 per_cu
->v
.quick
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
7289 struct dwarf2_per_cu_quick_data
);
7293 unsigned int line_offset
= to_underlying (line_offset_struct
);
7294 dwarf2_psymtab
*pst
;
7297 /* Give the symtab a useful name for debug purposes. */
7298 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7299 name
= string_printf ("<type_units_%d>",
7300 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7302 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7304 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7305 pst
->anonymous
= true;
7308 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7309 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7314 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7315 STMT_LIST is a DW_AT_stmt_list attribute. */
7317 static struct type_unit_group
*
7318 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7320 struct dwarf2_per_objfile
*dwarf2_per_objfile
7321 = cu
->per_cu
->dwarf2_per_objfile
;
7322 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7323 struct type_unit_group
*tu_group
;
7325 unsigned int line_offset
;
7326 struct type_unit_group type_unit_group_for_lookup
;
7328 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7329 dwarf2_per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7331 /* Do we need to create a new group, or can we use an existing one? */
7335 line_offset
= DW_UNSND (stmt_list
);
7336 ++tu_stats
->nr_symtab_sharers
;
7340 /* Ugh, no stmt_list. Rare, but we have to handle it.
7341 We can do various things here like create one group per TU or
7342 spread them over multiple groups to split up the expansion work.
7343 To avoid worst case scenarios (too many groups or too large groups)
7344 we, umm, group them in bunches. */
7345 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7346 | (tu_stats
->nr_stmt_less_type_units
7347 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7348 ++tu_stats
->nr_stmt_less_type_units
;
7351 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7352 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7353 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7354 &type_unit_group_for_lookup
, INSERT
);
7357 tu_group
= (struct type_unit_group
*) *slot
;
7358 gdb_assert (tu_group
!= NULL
);
7362 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7363 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7365 ++tu_stats
->nr_symtabs
;
7371 /* Partial symbol tables. */
7373 /* Create a psymtab named NAME and assign it to PER_CU.
7375 The caller must fill in the following details:
7376 dirname, textlow, texthigh. */
7378 static dwarf2_psymtab
*
7379 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7381 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7382 dwarf2_psymtab
*pst
;
7384 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7386 pst
->psymtabs_addrmap_supported
= true;
7388 /* This is the glue that links PST into GDB's symbol API. */
7389 per_cu
->v
.psymtab
= pst
;
7394 /* DIE reader function for process_psymtab_comp_unit. */
7397 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7398 const gdb_byte
*info_ptr
,
7399 struct die_info
*comp_unit_die
,
7400 enum language pretend_language
)
7402 struct dwarf2_cu
*cu
= reader
->cu
;
7403 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7404 struct gdbarch
*gdbarch
= objfile
->arch ();
7405 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7407 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7408 dwarf2_psymtab
*pst
;
7409 enum pc_bounds_kind cu_bounds_kind
;
7410 const char *filename
;
7412 gdb_assert (! per_cu
->is_debug_types
);
7414 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7416 /* Allocate a new partial symbol table structure. */
7417 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7418 static const char artificial
[] = "<artificial>";
7419 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7420 if (filename
== NULL
)
7422 else if (strcmp (filename
, artificial
) == 0)
7424 debug_filename
.reset (concat (artificial
, "@",
7425 sect_offset_str (per_cu
->sect_off
),
7427 filename
= debug_filename
.get ();
7430 pst
= create_partial_symtab (per_cu
, filename
);
7432 /* This must be done before calling dwarf2_build_include_psymtabs. */
7433 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7435 baseaddr
= objfile
->text_section_offset ();
7437 dwarf2_find_base_address (comp_unit_die
, cu
);
7439 /* Possibly set the default values of LOWPC and HIGHPC from
7441 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7442 &best_highpc
, cu
, pst
);
7443 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7446 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7449 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7451 /* Store the contiguous range if it is not empty; it can be
7452 empty for CUs with no code. */
7453 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7457 /* Check if comp unit has_children.
7458 If so, read the rest of the partial symbols from this comp unit.
7459 If not, there's no more debug_info for this comp unit. */
7460 if (comp_unit_die
->has_children
)
7462 struct partial_die_info
*first_die
;
7463 CORE_ADDR lowpc
, highpc
;
7465 lowpc
= ((CORE_ADDR
) -1);
7466 highpc
= ((CORE_ADDR
) 0);
7468 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7470 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7471 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7473 /* If we didn't find a lowpc, set it to highpc to avoid
7474 complaints from `maint check'. */
7475 if (lowpc
== ((CORE_ADDR
) -1))
7478 /* If the compilation unit didn't have an explicit address range,
7479 then use the information extracted from its child dies. */
7480 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7483 best_highpc
= highpc
;
7486 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7487 best_lowpc
+ baseaddr
)
7489 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7490 best_highpc
+ baseaddr
)
7493 end_psymtab_common (objfile
, pst
);
7495 if (!cu
->per_cu
->imported_symtabs_empty ())
7498 int len
= cu
->per_cu
->imported_symtabs_size ();
7500 /* Fill in 'dependencies' here; we fill in 'users' in a
7502 pst
->number_of_dependencies
= len
;
7504 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7505 for (i
= 0; i
< len
; ++i
)
7507 pst
->dependencies
[i
]
7508 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7511 cu
->per_cu
->imported_symtabs_free ();
7514 /* Get the list of files included in the current compilation unit,
7515 and build a psymtab for each of them. */
7516 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7518 if (dwarf_read_debug
)
7519 fprintf_unfiltered (gdb_stdlog
,
7520 "Psymtab for %s unit @%s: %s - %s"
7521 ", %d global, %d static syms\n",
7522 per_cu
->is_debug_types
? "type" : "comp",
7523 sect_offset_str (per_cu
->sect_off
),
7524 paddress (gdbarch
, pst
->text_low (objfile
)),
7525 paddress (gdbarch
, pst
->text_high (objfile
)),
7526 pst
->n_global_syms
, pst
->n_static_syms
);
7529 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7530 Process compilation unit THIS_CU for a psymtab. */
7533 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7534 bool want_partial_unit
,
7535 enum language pretend_language
)
7537 /* If this compilation unit was already read in, free the
7538 cached copy in order to read it in again. This is
7539 necessary because we skipped some symbols when we first
7540 read in the compilation unit (see load_partial_dies).
7541 This problem could be avoided, but the benefit is unclear. */
7542 if (this_cu
->cu
!= NULL
)
7543 free_one_cached_comp_unit (this_cu
);
7545 cutu_reader
reader (this_cu
, NULL
, 0, false);
7547 switch (reader
.comp_unit_die
->tag
)
7549 case DW_TAG_compile_unit
:
7550 this_cu
->unit_type
= DW_UT_compile
;
7552 case DW_TAG_partial_unit
:
7553 this_cu
->unit_type
= DW_UT_partial
;
7563 else if (this_cu
->is_debug_types
)
7564 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7565 reader
.comp_unit_die
);
7566 else if (want_partial_unit
7567 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7568 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7569 reader
.comp_unit_die
,
7572 this_cu
->lang
= this_cu
->cu
->language
;
7574 /* Age out any secondary CUs. */
7575 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7578 /* Reader function for build_type_psymtabs. */
7581 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7582 const gdb_byte
*info_ptr
,
7583 struct die_info
*type_unit_die
)
7585 struct dwarf2_per_objfile
*dwarf2_per_objfile
7586 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7587 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7588 struct dwarf2_cu
*cu
= reader
->cu
;
7589 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7590 struct signatured_type
*sig_type
;
7591 struct type_unit_group
*tu_group
;
7592 struct attribute
*attr
;
7593 struct partial_die_info
*first_die
;
7594 CORE_ADDR lowpc
, highpc
;
7595 dwarf2_psymtab
*pst
;
7597 gdb_assert (per_cu
->is_debug_types
);
7598 sig_type
= (struct signatured_type
*) per_cu
;
7600 if (! type_unit_die
->has_children
)
7603 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7604 tu_group
= get_type_unit_group (cu
, attr
);
7606 if (tu_group
->tus
== nullptr)
7607 tu_group
->tus
= new std::vector
<signatured_type
*>;
7608 tu_group
->tus
->push_back (sig_type
);
7610 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7611 pst
= create_partial_symtab (per_cu
, "");
7612 pst
->anonymous
= true;
7614 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7616 lowpc
= (CORE_ADDR
) -1;
7617 highpc
= (CORE_ADDR
) 0;
7618 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7620 end_psymtab_common (objfile
, pst
);
7623 /* Struct used to sort TUs by their abbreviation table offset. */
7625 struct tu_abbrev_offset
7627 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7628 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7631 signatured_type
*sig_type
;
7632 sect_offset abbrev_offset
;
7635 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7638 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7639 const struct tu_abbrev_offset
&b
)
7641 return a
.abbrev_offset
< b
.abbrev_offset
;
7644 /* Efficiently read all the type units.
7645 This does the bulk of the work for build_type_psymtabs.
7647 The efficiency is because we sort TUs by the abbrev table they use and
7648 only read each abbrev table once. In one program there are 200K TUs
7649 sharing 8K abbrev tables.
7651 The main purpose of this function is to support building the
7652 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7653 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7654 can collapse the search space by grouping them by stmt_list.
7655 The savings can be significant, in the same program from above the 200K TUs
7656 share 8K stmt_list tables.
7658 FUNC is expected to call get_type_unit_group, which will create the
7659 struct type_unit_group if necessary and add it to
7660 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7663 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7665 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7666 abbrev_table_up abbrev_table
;
7667 sect_offset abbrev_offset
;
7669 /* It's up to the caller to not call us multiple times. */
7670 gdb_assert (dwarf2_per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7672 if (dwarf2_per_objfile
->per_bfd
->all_type_units
.empty ())
7675 /* TUs typically share abbrev tables, and there can be way more TUs than
7676 abbrev tables. Sort by abbrev table to reduce the number of times we
7677 read each abbrev table in.
7678 Alternatives are to punt or to maintain a cache of abbrev tables.
7679 This is simpler and efficient enough for now.
7681 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7682 symtab to use). Typically TUs with the same abbrev offset have the same
7683 stmt_list value too so in practice this should work well.
7685 The basic algorithm here is:
7687 sort TUs by abbrev table
7688 for each TU with same abbrev table:
7689 read abbrev table if first user
7690 read TU top level DIE
7691 [IWBN if DWO skeletons had DW_AT_stmt_list]
7694 if (dwarf_read_debug
)
7695 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7697 /* Sort in a separate table to maintain the order of all_type_units
7698 for .gdb_index: TU indices directly index all_type_units. */
7699 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7700 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7702 for (signatured_type
*sig_type
: dwarf2_per_objfile
->per_bfd
->all_type_units
)
7703 sorted_by_abbrev
.emplace_back
7704 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7705 sig_type
->per_cu
.section
,
7706 sig_type
->per_cu
.sect_off
));
7708 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7709 sort_tu_by_abbrev_offset
);
7711 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7713 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7715 /* Switch to the next abbrev table if necessary. */
7716 if (abbrev_table
== NULL
7717 || tu
.abbrev_offset
!= abbrev_offset
)
7719 abbrev_offset
= tu
.abbrev_offset
;
7721 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7722 &dwarf2_per_objfile
->per_bfd
->abbrev
,
7724 ++tu_stats
->nr_uniq_abbrev_tables
;
7727 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7729 if (!reader
.dummy_p
)
7730 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7731 reader
.comp_unit_die
);
7735 /* Print collected type unit statistics. */
7738 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7740 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->per_bfd
->tu_stats
;
7742 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7743 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7744 dwarf2_per_objfile
->per_bfd
->all_type_units
.size ());
7745 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7746 tu_stats
->nr_uniq_abbrev_tables
);
7747 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7748 tu_stats
->nr_symtabs
);
7749 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7750 tu_stats
->nr_symtab_sharers
);
7751 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7752 tu_stats
->nr_stmt_less_type_units
);
7753 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7754 tu_stats
->nr_all_type_units_reallocs
);
7757 /* Traversal function for build_type_psymtabs. */
7760 build_type_psymtab_dependencies (void **slot
, void *info
)
7762 struct dwarf2_per_objfile
*dwarf2_per_objfile
7763 = (struct dwarf2_per_objfile
*) info
;
7764 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7765 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7766 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7767 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7768 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7771 gdb_assert (len
> 0);
7772 gdb_assert (per_cu
->type_unit_group_p ());
7774 pst
->number_of_dependencies
= len
;
7775 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7776 for (i
= 0; i
< len
; ++i
)
7778 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7779 gdb_assert (iter
->per_cu
.is_debug_types
);
7780 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7781 iter
->type_unit_group
= tu_group
;
7784 delete tu_group
->tus
;
7785 tu_group
->tus
= nullptr;
7790 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7791 Build partial symbol tables for the .debug_types comp-units. */
7794 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7796 if (! create_all_type_units (dwarf2_per_objfile
))
7799 build_type_psymtabs_1 (dwarf2_per_objfile
);
7802 /* Traversal function for process_skeletonless_type_unit.
7803 Read a TU in a DWO file and build partial symbols for it. */
7806 process_skeletonless_type_unit (void **slot
, void *info
)
7808 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7809 struct dwarf2_per_objfile
*dwarf2_per_objfile
7810 = (struct dwarf2_per_objfile
*) info
;
7811 struct signatured_type find_entry
, *entry
;
7813 /* If this TU doesn't exist in the global table, add it and read it in. */
7815 if (dwarf2_per_objfile
->per_bfd
->signatured_types
== NULL
)
7816 dwarf2_per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7818 find_entry
.signature
= dwo_unit
->signature
;
7819 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->signatured_types
.get (),
7820 &find_entry
, INSERT
);
7821 /* If we've already seen this type there's nothing to do. What's happening
7822 is we're doing our own version of comdat-folding here. */
7826 /* This does the job that create_all_type_units would have done for
7828 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7829 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7832 /* This does the job that build_type_psymtabs_1 would have done. */
7833 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7834 if (!reader
.dummy_p
)
7835 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7836 reader
.comp_unit_die
);
7841 /* Traversal function for process_skeletonless_type_units. */
7844 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7846 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7848 if (dwo_file
->tus
!= NULL
)
7849 htab_traverse_noresize (dwo_file
->tus
.get (),
7850 process_skeletonless_type_unit
, info
);
7855 /* Scan all TUs of DWO files, verifying we've processed them.
7856 This is needed in case a TU was emitted without its skeleton.
7857 Note: This can't be done until we know what all the DWO files are. */
7860 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7862 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7863 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7864 && dwarf2_per_objfile
->per_bfd
->dwo_files
!= NULL
)
7866 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (),
7867 process_dwo_file_for_skeletonless_type_units
,
7868 dwarf2_per_objfile
);
7872 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7875 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7877 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7879 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7884 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7886 /* Set the 'user' field only if it is not already set. */
7887 if (pst
->dependencies
[j
]->user
== NULL
)
7888 pst
->dependencies
[j
]->user
= pst
;
7893 /* Build the partial symbol table by doing a quick pass through the
7894 .debug_info and .debug_abbrev sections. */
7897 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7899 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7901 if (dwarf_read_debug
)
7903 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7904 objfile_name (objfile
));
7907 scoped_restore restore_reading_psyms
7908 = make_scoped_restore (&dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
,
7911 dwarf2_per_objfile
->per_bfd
->info
.read (objfile
);
7913 /* Any cached compilation units will be linked by the per-objfile
7914 read_in_chain. Make sure to free them when we're done. */
7915 free_cached_comp_units
freer (dwarf2_per_objfile
);
7917 build_type_psymtabs (dwarf2_per_objfile
);
7919 create_all_comp_units (dwarf2_per_objfile
);
7921 /* Create a temporary address map on a temporary obstack. We later
7922 copy this to the final obstack. */
7923 auto_obstack temp_obstack
;
7925 scoped_restore save_psymtabs_addrmap
7926 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7927 addrmap_create_mutable (&temp_obstack
));
7929 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->per_bfd
->all_comp_units
)
7931 if (per_cu
->v
.psymtab
!= NULL
)
7932 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7934 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7937 /* This has to wait until we read the CUs, we need the list of DWOs. */
7938 process_skeletonless_type_units (dwarf2_per_objfile
);
7940 /* Now that all TUs have been processed we can fill in the dependencies. */
7941 if (dwarf2_per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
7943 htab_traverse_noresize (dwarf2_per_objfile
->per_bfd
->type_unit_groups
.get (),
7944 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7947 if (dwarf_read_debug
)
7948 print_tu_stats (dwarf2_per_objfile
);
7950 set_partial_user (dwarf2_per_objfile
);
7952 objfile
->partial_symtabs
->psymtabs_addrmap
7953 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7954 objfile
->partial_symtabs
->obstack ());
7955 /* At this point we want to keep the address map. */
7956 save_psymtabs_addrmap
.release ();
7958 if (dwarf_read_debug
)
7959 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7960 objfile_name (objfile
));
7963 /* Load the partial DIEs for a secondary CU into memory.
7964 This is also used when rereading a primary CU with load_all_dies. */
7967 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7969 cutu_reader
reader (this_cu
, NULL
, 1, false);
7971 if (!reader
.dummy_p
)
7973 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7976 /* Check if comp unit has_children.
7977 If so, read the rest of the partial symbols from this comp unit.
7978 If not, there's no more debug_info for this comp unit. */
7979 if (reader
.comp_unit_die
->has_children
)
7980 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7987 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7988 struct dwarf2_section_info
*section
,
7989 struct dwarf2_section_info
*abbrev_section
,
7990 unsigned int is_dwz
)
7992 const gdb_byte
*info_ptr
;
7993 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7995 if (dwarf_read_debug
)
7996 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7997 section
->get_name (),
7998 section
->get_file_name ());
8000 section
->read (objfile
);
8002 info_ptr
= section
->buffer
;
8004 while (info_ptr
< section
->buffer
+ section
->size
)
8006 struct dwarf2_per_cu_data
*this_cu
;
8008 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8010 comp_unit_head cu_header
;
8011 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8012 abbrev_section
, info_ptr
,
8013 rcuh_kind::COMPILE
);
8015 /* Save the compilation unit for later lookup. */
8016 if (cu_header
.unit_type
!= DW_UT_type
)
8017 this_cu
= dwarf2_per_objfile
->per_bfd
->allocate_per_cu ();
8020 auto sig_type
= dwarf2_per_objfile
->per_bfd
->allocate_signatured_type ();
8021 sig_type
->signature
= cu_header
.signature
;
8022 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8023 this_cu
= &sig_type
->per_cu
;
8025 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8026 this_cu
->sect_off
= sect_off
;
8027 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8028 this_cu
->is_dwz
= is_dwz
;
8029 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8030 this_cu
->section
= section
;
8032 dwarf2_per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8034 info_ptr
= info_ptr
+ this_cu
->length
;
8038 /* Create a list of all compilation units in OBJFILE.
8039 This is only done for -readnow and building partial symtabs. */
8042 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8044 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
.empty ());
8045 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->per_bfd
->info
,
8046 &dwarf2_per_objfile
->per_bfd
->abbrev
, 0);
8048 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8050 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8054 /* Process all loaded DIEs for compilation unit CU, starting at
8055 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8056 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8057 DW_AT_ranges). See the comments of add_partial_subprogram on how
8058 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8061 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8062 CORE_ADDR
*highpc
, int set_addrmap
,
8063 struct dwarf2_cu
*cu
)
8065 struct partial_die_info
*pdi
;
8067 /* Now, march along the PDI's, descending into ones which have
8068 interesting children but skipping the children of the other ones,
8069 until we reach the end of the compilation unit. */
8077 /* Anonymous namespaces or modules have no name but have interesting
8078 children, so we need to look at them. Ditto for anonymous
8081 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8082 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8083 || pdi
->tag
== DW_TAG_imported_unit
8084 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8088 case DW_TAG_subprogram
:
8089 case DW_TAG_inlined_subroutine
:
8090 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8092 case DW_TAG_constant
:
8093 case DW_TAG_variable
:
8094 case DW_TAG_typedef
:
8095 case DW_TAG_union_type
:
8096 if (!pdi
->is_declaration
8097 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8099 add_partial_symbol (pdi
, cu
);
8102 case DW_TAG_class_type
:
8103 case DW_TAG_interface_type
:
8104 case DW_TAG_structure_type
:
8105 if (!pdi
->is_declaration
)
8107 add_partial_symbol (pdi
, cu
);
8109 if ((cu
->language
== language_rust
8110 || cu
->language
== language_cplus
) && pdi
->has_children
)
8111 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8114 case DW_TAG_enumeration_type
:
8115 if (!pdi
->is_declaration
)
8116 add_partial_enumeration (pdi
, cu
);
8118 case DW_TAG_base_type
:
8119 case DW_TAG_subrange_type
:
8120 /* File scope base type definitions are added to the partial
8122 add_partial_symbol (pdi
, cu
);
8124 case DW_TAG_namespace
:
8125 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8128 if (!pdi
->is_declaration
)
8129 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8131 case DW_TAG_imported_unit
:
8133 struct dwarf2_per_cu_data
*per_cu
;
8135 /* For now we don't handle imported units in type units. */
8136 if (cu
->per_cu
->is_debug_types
)
8138 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8139 " supported in type units [in module %s]"),
8140 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8143 per_cu
= dwarf2_find_containing_comp_unit
8144 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8145 cu
->per_cu
->dwarf2_per_objfile
);
8147 /* Go read the partial unit, if needed. */
8148 if (per_cu
->v
.psymtab
== NULL
)
8149 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
8151 cu
->per_cu
->imported_symtabs_push (per_cu
);
8154 case DW_TAG_imported_declaration
:
8155 add_partial_symbol (pdi
, cu
);
8162 /* If the die has a sibling, skip to the sibling. */
8164 pdi
= pdi
->die_sibling
;
8168 /* Functions used to compute the fully scoped name of a partial DIE.
8170 Normally, this is simple. For C++, the parent DIE's fully scoped
8171 name is concatenated with "::" and the partial DIE's name.
8172 Enumerators are an exception; they use the scope of their parent
8173 enumeration type, i.e. the name of the enumeration type is not
8174 prepended to the enumerator.
8176 There are two complexities. One is DW_AT_specification; in this
8177 case "parent" means the parent of the target of the specification,
8178 instead of the direct parent of the DIE. The other is compilers
8179 which do not emit DW_TAG_namespace; in this case we try to guess
8180 the fully qualified name of structure types from their members'
8181 linkage names. This must be done using the DIE's children rather
8182 than the children of any DW_AT_specification target. We only need
8183 to do this for structures at the top level, i.e. if the target of
8184 any DW_AT_specification (if any; otherwise the DIE itself) does not
8187 /* Compute the scope prefix associated with PDI's parent, in
8188 compilation unit CU. The result will be allocated on CU's
8189 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8190 field. NULL is returned if no prefix is necessary. */
8192 partial_die_parent_scope (struct partial_die_info
*pdi
,
8193 struct dwarf2_cu
*cu
)
8195 const char *grandparent_scope
;
8196 struct partial_die_info
*parent
, *real_pdi
;
8198 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8199 then this means the parent of the specification DIE. */
8202 while (real_pdi
->has_specification
)
8204 auto res
= find_partial_die (real_pdi
->spec_offset
,
8205 real_pdi
->spec_is_dwz
, cu
);
8210 parent
= real_pdi
->die_parent
;
8214 if (parent
->scope_set
)
8215 return parent
->scope
;
8219 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8221 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8222 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8223 Work around this problem here. */
8224 if (cu
->language
== language_cplus
8225 && parent
->tag
== DW_TAG_namespace
8226 && strcmp (parent
->name
, "::") == 0
8227 && grandparent_scope
== NULL
)
8229 parent
->scope
= NULL
;
8230 parent
->scope_set
= 1;
8234 /* Nested subroutines in Fortran get a prefix. */
8235 if (pdi
->tag
== DW_TAG_enumerator
)
8236 /* Enumerators should not get the name of the enumeration as a prefix. */
8237 parent
->scope
= grandparent_scope
;
8238 else if (parent
->tag
== DW_TAG_namespace
8239 || parent
->tag
== DW_TAG_module
8240 || parent
->tag
== DW_TAG_structure_type
8241 || parent
->tag
== DW_TAG_class_type
8242 || parent
->tag
== DW_TAG_interface_type
8243 || parent
->tag
== DW_TAG_union_type
8244 || parent
->tag
== DW_TAG_enumeration_type
8245 || (cu
->language
== language_fortran
8246 && parent
->tag
== DW_TAG_subprogram
8247 && pdi
->tag
== DW_TAG_subprogram
))
8249 if (grandparent_scope
== NULL
)
8250 parent
->scope
= parent
->name
;
8252 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8254 parent
->name
, 0, cu
);
8258 /* FIXME drow/2004-04-01: What should we be doing with
8259 function-local names? For partial symbols, we should probably be
8261 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8262 dwarf_tag_name (parent
->tag
),
8263 sect_offset_str (pdi
->sect_off
));
8264 parent
->scope
= grandparent_scope
;
8267 parent
->scope_set
= 1;
8268 return parent
->scope
;
8271 /* Return the fully scoped name associated with PDI, from compilation unit
8272 CU. The result will be allocated with malloc. */
8274 static gdb::unique_xmalloc_ptr
<char>
8275 partial_die_full_name (struct partial_die_info
*pdi
,
8276 struct dwarf2_cu
*cu
)
8278 const char *parent_scope
;
8280 /* If this is a template instantiation, we can not work out the
8281 template arguments from partial DIEs. So, unfortunately, we have
8282 to go through the full DIEs. At least any work we do building
8283 types here will be reused if full symbols are loaded later. */
8284 if (pdi
->has_template_arguments
)
8288 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8290 struct die_info
*die
;
8291 struct attribute attr
;
8292 struct dwarf2_cu
*ref_cu
= cu
;
8294 /* DW_FORM_ref_addr is using section offset. */
8295 attr
.name
= (enum dwarf_attribute
) 0;
8296 attr
.form
= DW_FORM_ref_addr
;
8297 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8298 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8300 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8304 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8305 if (parent_scope
== NULL
)
8308 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8313 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8315 struct dwarf2_per_objfile
*dwarf2_per_objfile
8316 = cu
->per_cu
->dwarf2_per_objfile
;
8317 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8318 struct gdbarch
*gdbarch
= objfile
->arch ();
8320 const char *actual_name
= NULL
;
8323 baseaddr
= objfile
->text_section_offset ();
8325 gdb::unique_xmalloc_ptr
<char> built_actual_name
8326 = partial_die_full_name (pdi
, cu
);
8327 if (built_actual_name
!= NULL
)
8328 actual_name
= built_actual_name
.get ();
8330 if (actual_name
== NULL
)
8331 actual_name
= pdi
->name
;
8333 partial_symbol psymbol
;
8334 memset (&psymbol
, 0, sizeof (psymbol
));
8335 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8336 psymbol
.ginfo
.section
= -1;
8338 /* The code below indicates that the psymbol should be installed by
8340 gdb::optional
<psymbol_placement
> where
;
8344 case DW_TAG_inlined_subroutine
:
8345 case DW_TAG_subprogram
:
8346 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8348 if (pdi
->is_external
8349 || cu
->language
== language_ada
8350 || (cu
->language
== language_fortran
8351 && pdi
->die_parent
!= NULL
8352 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8354 /* Normally, only "external" DIEs are part of the global scope.
8355 But in Ada and Fortran, we want to be able to access nested
8356 procedures globally. So all Ada and Fortran subprograms are
8357 stored in the global scope. */
8358 where
= psymbol_placement::GLOBAL
;
8361 where
= psymbol_placement::STATIC
;
8363 psymbol
.domain
= VAR_DOMAIN
;
8364 psymbol
.aclass
= LOC_BLOCK
;
8365 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8366 psymbol
.ginfo
.value
.address
= addr
;
8368 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8369 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8371 case DW_TAG_constant
:
8372 psymbol
.domain
= VAR_DOMAIN
;
8373 psymbol
.aclass
= LOC_STATIC
;
8374 where
= (pdi
->is_external
8375 ? psymbol_placement::GLOBAL
8376 : psymbol_placement::STATIC
);
8378 case DW_TAG_variable
:
8380 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8384 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
8386 /* A global or static variable may also have been stripped
8387 out by the linker if unused, in which case its address
8388 will be nullified; do not add such variables into partial
8389 symbol table then. */
8391 else if (pdi
->is_external
)
8394 Don't enter into the minimal symbol tables as there is
8395 a minimal symbol table entry from the ELF symbols already.
8396 Enter into partial symbol table if it has a location
8397 descriptor or a type.
8398 If the location descriptor is missing, new_symbol will create
8399 a LOC_UNRESOLVED symbol, the address of the variable will then
8400 be determined from the minimal symbol table whenever the variable
8402 The address for the partial symbol table entry is not
8403 used by GDB, but it comes in handy for debugging partial symbol
8406 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8408 psymbol
.domain
= VAR_DOMAIN
;
8409 psymbol
.aclass
= LOC_STATIC
;
8410 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8411 psymbol
.ginfo
.value
.address
= addr
;
8412 where
= psymbol_placement::GLOBAL
;
8417 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8419 /* Static Variable. Skip symbols whose value we cannot know (those
8420 without location descriptors or constant values). */
8421 if (!has_loc
&& !pdi
->has_const_value
)
8424 psymbol
.domain
= VAR_DOMAIN
;
8425 psymbol
.aclass
= LOC_STATIC
;
8426 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8428 psymbol
.ginfo
.value
.address
= addr
;
8429 where
= psymbol_placement::STATIC
;
8432 case DW_TAG_typedef
:
8433 case DW_TAG_base_type
:
8434 case DW_TAG_subrange_type
:
8435 psymbol
.domain
= VAR_DOMAIN
;
8436 psymbol
.aclass
= LOC_TYPEDEF
;
8437 where
= psymbol_placement::STATIC
;
8439 case DW_TAG_imported_declaration
:
8440 case DW_TAG_namespace
:
8441 psymbol
.domain
= VAR_DOMAIN
;
8442 psymbol
.aclass
= LOC_TYPEDEF
;
8443 where
= psymbol_placement::GLOBAL
;
8446 /* With Fortran 77 there might be a "BLOCK DATA" module
8447 available without any name. If so, we skip the module as it
8448 doesn't bring any value. */
8449 if (actual_name
!= nullptr)
8451 psymbol
.domain
= MODULE_DOMAIN
;
8452 psymbol
.aclass
= LOC_TYPEDEF
;
8453 where
= psymbol_placement::GLOBAL
;
8456 case DW_TAG_class_type
:
8457 case DW_TAG_interface_type
:
8458 case DW_TAG_structure_type
:
8459 case DW_TAG_union_type
:
8460 case DW_TAG_enumeration_type
:
8461 /* Skip external references. The DWARF standard says in the section
8462 about "Structure, Union, and Class Type Entries": "An incomplete
8463 structure, union or class type is represented by a structure,
8464 union or class entry that does not have a byte size attribute
8465 and that has a DW_AT_declaration attribute." */
8466 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8469 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8470 static vs. global. */
8471 psymbol
.domain
= STRUCT_DOMAIN
;
8472 psymbol
.aclass
= LOC_TYPEDEF
;
8473 where
= (cu
->language
== language_cplus
8474 ? psymbol_placement::GLOBAL
8475 : psymbol_placement::STATIC
);
8477 case DW_TAG_enumerator
:
8478 psymbol
.domain
= VAR_DOMAIN
;
8479 psymbol
.aclass
= LOC_CONST
;
8480 where
= (cu
->language
== language_cplus
8481 ? psymbol_placement::GLOBAL
8482 : psymbol_placement::STATIC
);
8488 if (where
.has_value ())
8490 if (built_actual_name
!= nullptr)
8491 actual_name
= objfile
->intern (actual_name
);
8492 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8493 psymbol
.ginfo
.set_linkage_name (actual_name
);
8496 psymbol
.ginfo
.set_demangled_name (actual_name
,
8497 &objfile
->objfile_obstack
);
8498 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8500 add_psymbol_to_list (psymbol
, *where
, objfile
);
8504 /* Read a partial die corresponding to a namespace; also, add a symbol
8505 corresponding to that namespace to the symbol table. NAMESPACE is
8506 the name of the enclosing namespace. */
8509 add_partial_namespace (struct partial_die_info
*pdi
,
8510 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8511 int set_addrmap
, struct dwarf2_cu
*cu
)
8513 /* Add a symbol for the namespace. */
8515 add_partial_symbol (pdi
, cu
);
8517 /* Now scan partial symbols in that namespace. */
8519 if (pdi
->has_children
)
8520 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8523 /* Read a partial die corresponding to a Fortran module. */
8526 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8527 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8529 /* Add a symbol for the namespace. */
8531 add_partial_symbol (pdi
, cu
);
8533 /* Now scan partial symbols in that module. */
8535 if (pdi
->has_children
)
8536 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8539 /* Read a partial die corresponding to a subprogram or an inlined
8540 subprogram and create a partial symbol for that subprogram.
8541 When the CU language allows it, this routine also defines a partial
8542 symbol for each nested subprogram that this subprogram contains.
8543 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8544 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8546 PDI may also be a lexical block, in which case we simply search
8547 recursively for subprograms defined inside that lexical block.
8548 Again, this is only performed when the CU language allows this
8549 type of definitions. */
8552 add_partial_subprogram (struct partial_die_info
*pdi
,
8553 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8554 int set_addrmap
, struct dwarf2_cu
*cu
)
8556 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8558 if (pdi
->has_pc_info
)
8560 if (pdi
->lowpc
< *lowpc
)
8561 *lowpc
= pdi
->lowpc
;
8562 if (pdi
->highpc
> *highpc
)
8563 *highpc
= pdi
->highpc
;
8566 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8567 struct gdbarch
*gdbarch
= objfile
->arch ();
8569 CORE_ADDR this_highpc
;
8570 CORE_ADDR this_lowpc
;
8572 baseaddr
= objfile
->text_section_offset ();
8574 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8575 pdi
->lowpc
+ baseaddr
)
8578 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8579 pdi
->highpc
+ baseaddr
)
8581 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8582 this_lowpc
, this_highpc
- 1,
8583 cu
->per_cu
->v
.psymtab
);
8587 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8589 if (!pdi
->is_declaration
)
8590 /* Ignore subprogram DIEs that do not have a name, they are
8591 illegal. Do not emit a complaint at this point, we will
8592 do so when we convert this psymtab into a symtab. */
8594 add_partial_symbol (pdi
, cu
);
8598 if (! pdi
->has_children
)
8601 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8603 pdi
= pdi
->die_child
;
8607 if (pdi
->tag
== DW_TAG_subprogram
8608 || pdi
->tag
== DW_TAG_inlined_subroutine
8609 || pdi
->tag
== DW_TAG_lexical_block
)
8610 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8611 pdi
= pdi
->die_sibling
;
8616 /* Read a partial die corresponding to an enumeration type. */
8619 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8620 struct dwarf2_cu
*cu
)
8622 struct partial_die_info
*pdi
;
8624 if (enum_pdi
->name
!= NULL
)
8625 add_partial_symbol (enum_pdi
, cu
);
8627 pdi
= enum_pdi
->die_child
;
8630 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8631 complaint (_("malformed enumerator DIE ignored"));
8633 add_partial_symbol (pdi
, cu
);
8634 pdi
= pdi
->die_sibling
;
8638 /* Return the initial uleb128 in the die at INFO_PTR. */
8641 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8643 unsigned int bytes_read
;
8645 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8648 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8649 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8651 Return the corresponding abbrev, or NULL if the number is zero (indicating
8652 an empty DIE). In either case *BYTES_READ will be set to the length of
8653 the initial number. */
8655 static struct abbrev_info
*
8656 peek_die_abbrev (const die_reader_specs
&reader
,
8657 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8659 dwarf2_cu
*cu
= reader
.cu
;
8660 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8661 unsigned int abbrev_number
8662 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8664 if (abbrev_number
== 0)
8667 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8670 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8671 " at offset %s [in module %s]"),
8672 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8673 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8679 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8680 Returns a pointer to the end of a series of DIEs, terminated by an empty
8681 DIE. Any children of the skipped DIEs will also be skipped. */
8683 static const gdb_byte
*
8684 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8688 unsigned int bytes_read
;
8689 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8692 return info_ptr
+ bytes_read
;
8694 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8698 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8699 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8700 abbrev corresponding to that skipped uleb128 should be passed in
8701 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8704 static const gdb_byte
*
8705 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8706 struct abbrev_info
*abbrev
)
8708 unsigned int bytes_read
;
8709 struct attribute attr
;
8710 bfd
*abfd
= reader
->abfd
;
8711 struct dwarf2_cu
*cu
= reader
->cu
;
8712 const gdb_byte
*buffer
= reader
->buffer
;
8713 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8714 unsigned int form
, i
;
8716 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8718 /* The only abbrev we care about is DW_AT_sibling. */
8719 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8722 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8724 if (attr
.form
== DW_FORM_ref_addr
)
8725 complaint (_("ignoring absolute DW_AT_sibling"));
8728 sect_offset off
= attr
.get_ref_die_offset ();
8729 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8731 if (sibling_ptr
< info_ptr
)
8732 complaint (_("DW_AT_sibling points backwards"));
8733 else if (sibling_ptr
> reader
->buffer_end
)
8734 reader
->die_section
->overflow_complaint ();
8740 /* If it isn't DW_AT_sibling, skip this attribute. */
8741 form
= abbrev
->attrs
[i
].form
;
8745 case DW_FORM_ref_addr
:
8746 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8747 and later it is offset sized. */
8748 if (cu
->header
.version
== 2)
8749 info_ptr
+= cu
->header
.addr_size
;
8751 info_ptr
+= cu
->header
.offset_size
;
8753 case DW_FORM_GNU_ref_alt
:
8754 info_ptr
+= cu
->header
.offset_size
;
8757 info_ptr
+= cu
->header
.addr_size
;
8765 case DW_FORM_flag_present
:
8766 case DW_FORM_implicit_const
:
8783 case DW_FORM_ref_sig8
:
8786 case DW_FORM_data16
:
8789 case DW_FORM_string
:
8790 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8791 info_ptr
+= bytes_read
;
8793 case DW_FORM_sec_offset
:
8795 case DW_FORM_GNU_strp_alt
:
8796 info_ptr
+= cu
->header
.offset_size
;
8798 case DW_FORM_exprloc
:
8800 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8801 info_ptr
+= bytes_read
;
8803 case DW_FORM_block1
:
8804 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8806 case DW_FORM_block2
:
8807 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8809 case DW_FORM_block4
:
8810 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8816 case DW_FORM_ref_udata
:
8817 case DW_FORM_GNU_addr_index
:
8818 case DW_FORM_GNU_str_index
:
8819 case DW_FORM_rnglistx
:
8820 case DW_FORM_loclistx
:
8821 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8823 case DW_FORM_indirect
:
8824 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8825 info_ptr
+= bytes_read
;
8826 /* We need to continue parsing from here, so just go back to
8828 goto skip_attribute
;
8831 error (_("Dwarf Error: Cannot handle %s "
8832 "in DWARF reader [in module %s]"),
8833 dwarf_form_name (form
),
8834 bfd_get_filename (abfd
));
8838 if (abbrev
->has_children
)
8839 return skip_children (reader
, info_ptr
);
8844 /* Locate ORIG_PDI's sibling.
8845 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8847 static const gdb_byte
*
8848 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8849 struct partial_die_info
*orig_pdi
,
8850 const gdb_byte
*info_ptr
)
8852 /* Do we know the sibling already? */
8854 if (orig_pdi
->sibling
)
8855 return orig_pdi
->sibling
;
8857 /* Are there any children to deal with? */
8859 if (!orig_pdi
->has_children
)
8862 /* Skip the children the long way. */
8864 return skip_children (reader
, info_ptr
);
8867 /* Expand this partial symbol table into a full symbol table. SELF is
8871 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8873 struct dwarf2_per_objfile
*dwarf2_per_objfile
8874 = get_dwarf2_per_objfile (objfile
);
8876 gdb_assert (!dwarf2_per_objfile
->symtab_set_p (per_cu_data
));
8878 /* If this psymtab is constructed from a debug-only objfile, the
8879 has_section_at_zero flag will not necessarily be correct. We
8880 can get the correct value for this flag by looking at the data
8881 associated with the (presumably stripped) associated objfile. */
8882 if (objfile
->separate_debug_objfile_backlink
)
8884 struct dwarf2_per_objfile
*dpo_backlink
8885 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8887 dwarf2_per_objfile
->per_bfd
->has_section_at_zero
8888 = dpo_backlink
->per_bfd
->has_section_at_zero
;
8891 expand_psymtab (objfile
);
8893 process_cu_includes (dwarf2_per_objfile
);
8896 /* Reading in full CUs. */
8898 /* Add PER_CU to the queue. */
8901 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8902 enum language pretend_language
)
8905 per_cu
->dwarf2_per_objfile
->per_bfd
->queue
.emplace (per_cu
, pretend_language
);
8908 /* If PER_CU is not yet queued, add it to the queue.
8909 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8911 The result is non-zero if PER_CU was queued, otherwise the result is zero
8912 meaning either PER_CU is already queued or it is already loaded.
8914 N.B. There is an invariant here that if a CU is queued then it is loaded.
8915 The caller is required to load PER_CU if we return non-zero. */
8918 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8919 struct dwarf2_per_cu_data
*per_cu
,
8920 enum language pretend_language
)
8922 /* We may arrive here during partial symbol reading, if we need full
8923 DIEs to process an unusual case (e.g. template arguments). Do
8924 not queue PER_CU, just tell our caller to load its DIEs. */
8925 if (per_cu
->dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
)
8927 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8932 /* Mark the dependence relation so that we don't flush PER_CU
8934 if (dependent_cu
!= NULL
)
8935 dwarf2_add_dependence (dependent_cu
, per_cu
);
8937 /* If it's already on the queue, we have nothing to do. */
8941 /* If the compilation unit is already loaded, just mark it as
8943 if (per_cu
->cu
!= NULL
)
8945 per_cu
->cu
->last_used
= 0;
8949 /* Add it to the queue. */
8950 queue_comp_unit (per_cu
, pretend_language
);
8955 /* Process the queue. */
8958 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8960 if (dwarf_read_debug
)
8962 fprintf_unfiltered (gdb_stdlog
,
8963 "Expanding one or more symtabs of objfile %s ...\n",
8964 objfile_name (dwarf2_per_objfile
->objfile
));
8967 /* The queue starts out with one item, but following a DIE reference
8968 may load a new CU, adding it to the end of the queue. */
8969 while (!dwarf2_per_objfile
->per_bfd
->queue
.empty ())
8971 dwarf2_queue_item
&item
= dwarf2_per_objfile
->per_bfd
->queue
.front ();
8973 if (!dwarf2_per_objfile
->symtab_set_p (item
.per_cu
)
8974 /* Skip dummy CUs. */
8975 && item
.per_cu
->cu
!= NULL
)
8977 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8978 unsigned int debug_print_threshold
;
8981 if (per_cu
->is_debug_types
)
8983 struct signatured_type
*sig_type
=
8984 (struct signatured_type
*) per_cu
;
8986 sprintf (buf
, "TU %s at offset %s",
8987 hex_string (sig_type
->signature
),
8988 sect_offset_str (per_cu
->sect_off
));
8989 /* There can be 100s of TUs.
8990 Only print them in verbose mode. */
8991 debug_print_threshold
= 2;
8995 sprintf (buf
, "CU at offset %s",
8996 sect_offset_str (per_cu
->sect_off
));
8997 debug_print_threshold
= 1;
9000 if (dwarf_read_debug
>= debug_print_threshold
)
9001 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9003 if (per_cu
->is_debug_types
)
9004 process_full_type_unit (per_cu
, item
.pretend_language
);
9006 process_full_comp_unit (per_cu
, item
.pretend_language
);
9008 if (dwarf_read_debug
>= debug_print_threshold
)
9009 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9012 item
.per_cu
->queued
= 0;
9013 dwarf2_per_objfile
->per_bfd
->queue
.pop ();
9016 if (dwarf_read_debug
)
9018 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9019 objfile_name (dwarf2_per_objfile
->objfile
));
9023 /* Read in full symbols for PST, and anything it depends on. */
9026 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9028 gdb_assert (!readin_p (objfile
));
9030 expand_dependencies (objfile
);
9032 dw2_do_instantiate_symtab (per_cu_data
, false);
9033 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9036 /* See psympriv.h. */
9039 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9041 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9042 return per_objfile
->symtab_set_p (per_cu_data
);
9045 /* See psympriv.h. */
9048 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9050 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9051 return per_objfile
->get_symtab (per_cu_data
);
9054 /* Trivial hash function for die_info: the hash value of a DIE
9055 is its offset in .debug_info for this objfile. */
9058 die_hash (const void *item
)
9060 const struct die_info
*die
= (const struct die_info
*) item
;
9062 return to_underlying (die
->sect_off
);
9065 /* Trivial comparison function for die_info structures: two DIEs
9066 are equal if they have the same offset. */
9069 die_eq (const void *item_lhs
, const void *item_rhs
)
9071 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9072 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9074 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9077 /* Load the DIEs associated with PER_CU into memory. */
9080 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9082 enum language pretend_language
)
9084 gdb_assert (! this_cu
->is_debug_types
);
9086 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
9090 struct dwarf2_cu
*cu
= reader
.cu
;
9091 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9093 gdb_assert (cu
->die_hash
== NULL
);
9095 htab_create_alloc_ex (cu
->header
.length
/ 12,
9099 &cu
->comp_unit_obstack
,
9100 hashtab_obstack_allocate
,
9101 dummy_obstack_deallocate
);
9103 if (reader
.comp_unit_die
->has_children
)
9104 reader
.comp_unit_die
->child
9105 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9106 &info_ptr
, reader
.comp_unit_die
);
9107 cu
->dies
= reader
.comp_unit_die
;
9108 /* comp_unit_die is not stored in die_hash, no need. */
9110 /* We try not to read any attributes in this function, because not
9111 all CUs needed for references have been loaded yet, and symbol
9112 table processing isn't initialized. But we have to set the CU language,
9113 or we won't be able to build types correctly.
9114 Similarly, if we do not read the producer, we can not apply
9115 producer-specific interpretation. */
9116 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9121 /* Add a DIE to the delayed physname list. */
9124 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9125 const char *name
, struct die_info
*die
,
9126 struct dwarf2_cu
*cu
)
9128 struct delayed_method_info mi
;
9130 mi
.fnfield_index
= fnfield_index
;
9134 cu
->method_list
.push_back (mi
);
9137 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9138 "const" / "volatile". If so, decrements LEN by the length of the
9139 modifier and return true. Otherwise return false. */
9143 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9145 size_t mod_len
= sizeof (mod
) - 1;
9146 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9154 /* Compute the physnames of any methods on the CU's method list.
9156 The computation of method physnames is delayed in order to avoid the
9157 (bad) condition that one of the method's formal parameters is of an as yet
9161 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9163 /* Only C++ delays computing physnames. */
9164 if (cu
->method_list
.empty ())
9166 gdb_assert (cu
->language
== language_cplus
);
9168 for (const delayed_method_info
&mi
: cu
->method_list
)
9170 const char *physname
;
9171 struct fn_fieldlist
*fn_flp
9172 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9173 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9174 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9175 = physname
? physname
: "";
9177 /* Since there's no tag to indicate whether a method is a
9178 const/volatile overload, extract that information out of the
9180 if (physname
!= NULL
)
9182 size_t len
= strlen (physname
);
9186 if (physname
[len
] == ')') /* shortcut */
9188 else if (check_modifier (physname
, len
, " const"))
9189 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9190 else if (check_modifier (physname
, len
, " volatile"))
9191 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9198 /* The list is no longer needed. */
9199 cu
->method_list
.clear ();
9202 /* Go objects should be embedded in a DW_TAG_module DIE,
9203 and it's not clear if/how imported objects will appear.
9204 To keep Go support simple until that's worked out,
9205 go back through what we've read and create something usable.
9206 We could do this while processing each DIE, and feels kinda cleaner,
9207 but that way is more invasive.
9208 This is to, for example, allow the user to type "p var" or "b main"
9209 without having to specify the package name, and allow lookups
9210 of module.object to work in contexts that use the expression
9214 fixup_go_packaging (struct dwarf2_cu
*cu
)
9216 gdb::unique_xmalloc_ptr
<char> package_name
;
9217 struct pending
*list
;
9220 for (list
= *cu
->get_builder ()->get_global_symbols ();
9224 for (i
= 0; i
< list
->nsyms
; ++i
)
9226 struct symbol
*sym
= list
->symbol
[i
];
9228 if (sym
->language () == language_go
9229 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9231 gdb::unique_xmalloc_ptr
<char> this_package_name
9232 (go_symbol_package_name (sym
));
9234 if (this_package_name
== NULL
)
9236 if (package_name
== NULL
)
9237 package_name
= std::move (this_package_name
);
9240 struct objfile
*objfile
9241 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9242 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9243 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9244 (symbol_symtab (sym
) != NULL
9245 ? symtab_to_filename_for_display
9246 (symbol_symtab (sym
))
9247 : objfile_name (objfile
)),
9248 this_package_name
.get (), package_name
.get ());
9254 if (package_name
!= NULL
)
9256 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9257 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9258 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9259 saved_package_name
);
9262 sym
= new (&objfile
->objfile_obstack
) symbol
;
9263 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9264 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9265 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9266 e.g., "main" finds the "main" module and not C's main(). */
9267 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9268 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9269 SYMBOL_TYPE (sym
) = type
;
9271 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9275 /* Allocate a fully-qualified name consisting of the two parts on the
9279 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9281 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9284 /* A helper that allocates a variant part to attach to a Rust enum
9285 type. OBSTACK is where the results should be allocated. TYPE is
9286 the type we're processing. DISCRIMINANT_INDEX is the index of the
9287 discriminant. It must be the index of one of the fields of TYPE.
9288 DEFAULT_INDEX is the index of the default field; or -1 if there is
9289 no default. RANGES is indexed by "effective" field number (the
9290 field index, but omitting the discriminant and default fields) and
9291 must hold the discriminant values used by the variants. Note that
9292 RANGES must have a lifetime at least as long as OBSTACK -- either
9293 already allocated on it, or static. */
9296 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9297 int discriminant_index
, int default_index
,
9298 gdb::array_view
<discriminant_range
> ranges
)
9300 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. Those
9301 must be handled by the caller. */
9302 gdb_assert (discriminant_index
>= 0
9303 && discriminant_index
< type
->num_fields ());
9304 gdb_assert (default_index
== -1
9305 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9307 /* We have one variant for each non-discriminant field. */
9308 int n_variants
= type
->num_fields () - 1;
9310 variant
*variants
= new (obstack
) variant
[n_variants
];
9313 for (int i
= 0; i
< type
->num_fields (); ++i
)
9315 if (i
== discriminant_index
)
9318 variants
[var_idx
].first_field
= i
;
9319 variants
[var_idx
].last_field
= i
+ 1;
9321 /* The default field does not need a range, but other fields do.
9322 We skipped the discriminant above. */
9323 if (i
!= default_index
)
9325 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9332 gdb_assert (range_idx
== ranges
.size ());
9333 gdb_assert (var_idx
== n_variants
);
9335 variant_part
*part
= new (obstack
) variant_part
;
9336 part
->discriminant_index
= discriminant_index
;
9337 part
->is_unsigned
= TYPE_UNSIGNED (TYPE_FIELD_TYPE (type
,
9338 discriminant_index
));
9339 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9341 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9342 gdb::array_view
<variant_part
> *prop_value
9343 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9345 struct dynamic_prop prop
;
9346 prop
.kind
= PROP_VARIANT_PARTS
;
9347 prop
.data
.variant_parts
= prop_value
;
9349 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9352 /* Some versions of rustc emitted enums in an unusual way.
9354 Ordinary enums were emitted as unions. The first element of each
9355 structure in the union was named "RUST$ENUM$DISR". This element
9356 held the discriminant.
9358 These versions of Rust also implemented the "non-zero"
9359 optimization. When the enum had two values, and one is empty and
9360 the other holds a pointer that cannot be zero, the pointer is used
9361 as the discriminant, with a zero value meaning the empty variant.
9362 Here, the union's first member is of the form
9363 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9364 where the fieldnos are the indices of the fields that should be
9365 traversed in order to find the field (which may be several fields deep)
9366 and the variantname is the name of the variant of the case when the
9369 This function recognizes whether TYPE is of one of these forms,
9370 and, if so, smashes it to be a variant type. */
9373 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9375 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9377 /* We don't need to deal with empty enums. */
9378 if (type
->num_fields () == 0)
9381 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9382 if (type
->num_fields () == 1
9383 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9385 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9387 /* Decode the field name to find the offset of the
9389 ULONGEST bit_offset
= 0;
9390 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9391 while (name
[0] >= '0' && name
[0] <= '9')
9394 unsigned long index
= strtoul (name
, &tail
, 10);
9397 || index
>= field_type
->num_fields ()
9398 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9399 != FIELD_LOC_KIND_BITPOS
))
9401 complaint (_("Could not parse Rust enum encoding string \"%s\""
9403 TYPE_FIELD_NAME (type
, 0),
9404 objfile_name (objfile
));
9409 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9410 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9413 /* Smash this type to be a structure type. We have to do this
9414 because the type has already been recorded. */
9415 type
->set_code (TYPE_CODE_STRUCT
);
9416 type
->set_num_fields (3);
9417 /* Save the field we care about. */
9418 struct field saved_field
= type
->field (0);
9420 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9422 /* Put the discriminant at index 0. */
9423 TYPE_FIELD_TYPE (type
, 0) = field_type
;
9424 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9425 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9426 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9428 /* The order of fields doesn't really matter, so put the real
9429 field at index 1 and the data-less field at index 2. */
9430 type
->field (1) = saved_field
;
9431 TYPE_FIELD_NAME (type
, 1)
9432 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, 1)->name ());
9433 TYPE_FIELD_TYPE (type
, 1)->set_name
9434 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9435 TYPE_FIELD_NAME (type
, 1)));
9437 const char *dataless_name
9438 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9440 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9442 TYPE_FIELD_TYPE (type
, 2) = dataless_type
;
9443 /* NAME points into the original discriminant name, which
9444 already has the correct lifetime. */
9445 TYPE_FIELD_NAME (type
, 2) = name
;
9446 SET_FIELD_BITPOS (type
->field (2), 0);
9448 /* Indicate that this is a variant type. */
9449 static discriminant_range ranges
[1] = { { 0, 0 } };
9450 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9452 /* A union with a single anonymous field is probably an old-style
9454 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9456 /* Smash this type to be a structure type. We have to do this
9457 because the type has already been recorded. */
9458 type
->set_code (TYPE_CODE_STRUCT
);
9460 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9461 const char *variant_name
9462 = rust_last_path_segment (field_type
->name ());
9463 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9464 field_type
->set_name
9465 (rust_fully_qualify (&objfile
->objfile_obstack
,
9466 type
->name (), variant_name
));
9470 struct type
*disr_type
= nullptr;
9471 for (int i
= 0; i
< type
->num_fields (); ++i
)
9473 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9475 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9477 /* All fields of a true enum will be structs. */
9480 else if (disr_type
->num_fields () == 0)
9482 /* Could be data-less variant, so keep going. */
9483 disr_type
= nullptr;
9485 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9486 "RUST$ENUM$DISR") != 0)
9488 /* Not a Rust enum. */
9498 /* If we got here without a discriminant, then it's probably
9500 if (disr_type
== nullptr)
9503 /* Smash this type to be a structure type. We have to do this
9504 because the type has already been recorded. */
9505 type
->set_code (TYPE_CODE_STRUCT
);
9507 /* Make space for the discriminant field. */
9508 struct field
*disr_field
= &disr_type
->field (0);
9510 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9511 * sizeof (struct field
)));
9512 memcpy (new_fields
+ 1, type
->fields (),
9513 type
->num_fields () * sizeof (struct field
));
9514 type
->set_fields (new_fields
);
9515 type
->set_num_fields (type
->num_fields () + 1);
9517 /* Install the discriminant at index 0 in the union. */
9518 type
->field (0) = *disr_field
;
9519 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9520 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9522 /* We need a way to find the correct discriminant given a
9523 variant name. For convenience we build a map here. */
9524 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9525 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9526 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9528 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9531 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9532 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9536 int n_fields
= type
->num_fields ();
9537 /* We don't need a range entry for the discriminant, but we do
9538 need one for every other field, as there is no default
9540 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9543 /* Skip the discriminant here. */
9544 for (int i
= 1; i
< n_fields
; ++i
)
9546 /* Find the final word in the name of this variant's type.
9547 That name can be used to look up the correct
9549 const char *variant_name
9550 = rust_last_path_segment (TYPE_FIELD_TYPE (type
, i
)->name ());
9552 auto iter
= discriminant_map
.find (variant_name
);
9553 if (iter
!= discriminant_map
.end ())
9555 ranges
[i
].low
= iter
->second
;
9556 ranges
[i
].high
= iter
->second
;
9559 /* Remove the discriminant field, if it exists. */
9560 struct type
*sub_type
= TYPE_FIELD_TYPE (type
, i
);
9561 if (sub_type
->num_fields () > 0)
9563 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9564 sub_type
->set_fields (sub_type
->fields () + 1);
9566 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9568 (rust_fully_qualify (&objfile
->objfile_obstack
,
9569 type
->name (), variant_name
));
9572 /* Indicate that this is a variant type. */
9573 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1,
9574 gdb::array_view
<discriminant_range
> (ranges
,
9579 /* Rewrite some Rust unions to be structures with variants parts. */
9582 rust_union_quirks (struct dwarf2_cu
*cu
)
9584 gdb_assert (cu
->language
== language_rust
);
9585 for (type
*type_
: cu
->rust_unions
)
9586 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9587 /* We don't need this any more. */
9588 cu
->rust_unions
.clear ();
9591 /* A helper function for computing the list of all symbol tables
9592 included by PER_CU. */
9595 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9596 htab_t all_children
, htab_t all_type_symtabs
,
9597 struct dwarf2_per_cu_data
*per_cu
,
9598 struct compunit_symtab
*immediate_parent
)
9600 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9603 /* This inclusion and its children have been processed. */
9609 /* Only add a CU if it has a symbol table. */
9610 compunit_symtab
*cust
= per_cu
->dwarf2_per_objfile
->get_symtab (per_cu
);
9613 /* If this is a type unit only add its symbol table if we haven't
9614 seen it yet (type unit per_cu's can share symtabs). */
9615 if (per_cu
->is_debug_types
)
9617 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9621 result
->push_back (cust
);
9622 if (cust
->user
== NULL
)
9623 cust
->user
= immediate_parent
;
9628 result
->push_back (cust
);
9629 if (cust
->user
== NULL
)
9630 cust
->user
= immediate_parent
;
9634 if (!per_cu
->imported_symtabs_empty ())
9635 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9637 recursively_compute_inclusions (result
, all_children
,
9638 all_type_symtabs
, ptr
, cust
);
9642 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9646 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9648 gdb_assert (! per_cu
->is_debug_types
);
9650 if (!per_cu
->imported_symtabs_empty ())
9653 std::vector
<compunit_symtab
*> result_symtabs
;
9654 htab_t all_children
, all_type_symtabs
;
9655 compunit_symtab
*cust
= per_cu
->dwarf2_per_objfile
->get_symtab (per_cu
);
9657 /* If we don't have a symtab, we can just skip this case. */
9661 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9662 NULL
, xcalloc
, xfree
);
9663 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9664 NULL
, xcalloc
, xfree
);
9666 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9668 recursively_compute_inclusions (&result_symtabs
, all_children
,
9669 all_type_symtabs
, ptr
, cust
);
9672 /* Now we have a transitive closure of all the included symtabs. */
9673 len
= result_symtabs
.size ();
9675 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9676 struct compunit_symtab
*, len
+ 1);
9677 memcpy (cust
->includes
, result_symtabs
.data (),
9678 len
* sizeof (compunit_symtab
*));
9679 cust
->includes
[len
] = NULL
;
9681 htab_delete (all_children
);
9682 htab_delete (all_type_symtabs
);
9686 /* Compute the 'includes' field for the symtabs of all the CUs we just
9690 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9692 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->per_bfd
->just_read_cus
)
9694 if (! iter
->is_debug_types
)
9695 compute_compunit_symtab_includes (iter
);
9698 dwarf2_per_objfile
->per_bfd
->just_read_cus
.clear ();
9701 /* Generate full symbol information for PER_CU, whose DIEs have
9702 already been loaded into memory. */
9705 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9706 enum language pretend_language
)
9708 struct dwarf2_cu
*cu
= per_cu
->cu
;
9709 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9710 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9711 struct gdbarch
*gdbarch
= objfile
->arch ();
9712 CORE_ADDR lowpc
, highpc
;
9713 struct compunit_symtab
*cust
;
9715 struct block
*static_block
;
9718 baseaddr
= objfile
->text_section_offset ();
9720 /* Clear the list here in case something was left over. */
9721 cu
->method_list
.clear ();
9723 cu
->language
= pretend_language
;
9724 cu
->language_defn
= language_def (cu
->language
);
9726 /* Do line number decoding in read_file_scope () */
9727 process_die (cu
->dies
, cu
);
9729 /* For now fudge the Go package. */
9730 if (cu
->language
== language_go
)
9731 fixup_go_packaging (cu
);
9733 /* Now that we have processed all the DIEs in the CU, all the types
9734 should be complete, and it should now be safe to compute all of the
9736 compute_delayed_physnames (cu
);
9738 if (cu
->language
== language_rust
)
9739 rust_union_quirks (cu
);
9741 /* Some compilers don't define a DW_AT_high_pc attribute for the
9742 compilation unit. If the DW_AT_high_pc is missing, synthesize
9743 it, by scanning the DIE's below the compilation unit. */
9744 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9746 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9747 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9749 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9750 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9751 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9752 addrmap to help ensure it has an accurate map of pc values belonging to
9754 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9756 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9757 SECT_OFF_TEXT (objfile
),
9762 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9764 /* Set symtab language to language from DW_AT_language. If the
9765 compilation is from a C file generated by language preprocessors, do
9766 not set the language if it was already deduced by start_subfile. */
9767 if (!(cu
->language
== language_c
9768 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9769 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9771 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9772 produce DW_AT_location with location lists but it can be possibly
9773 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9774 there were bugs in prologue debug info, fixed later in GCC-4.5
9775 by "unwind info for epilogues" patch (which is not directly related).
9777 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9778 needed, it would be wrong due to missing DW_AT_producer there.
9780 Still one can confuse GDB by using non-standard GCC compilation
9781 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9783 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9784 cust
->locations_valid
= 1;
9786 if (gcc_4_minor
>= 5)
9787 cust
->epilogue_unwind_valid
= 1;
9789 cust
->call_site_htab
= cu
->call_site_htab
;
9792 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9794 /* Push it for inclusion processing later. */
9795 dwarf2_per_objfile
->per_bfd
->just_read_cus
.push_back (per_cu
);
9797 /* Not needed any more. */
9798 cu
->reset_builder ();
9801 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9802 already been loaded into memory. */
9805 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9806 enum language pretend_language
)
9808 struct dwarf2_cu
*cu
= per_cu
->cu
;
9809 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9810 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9811 struct compunit_symtab
*cust
;
9812 struct signatured_type
*sig_type
;
9814 gdb_assert (per_cu
->is_debug_types
);
9815 sig_type
= (struct signatured_type
*) per_cu
;
9817 /* Clear the list here in case something was left over. */
9818 cu
->method_list
.clear ();
9820 cu
->language
= pretend_language
;
9821 cu
->language_defn
= language_def (cu
->language
);
9823 /* The symbol tables are set up in read_type_unit_scope. */
9824 process_die (cu
->dies
, cu
);
9826 /* For now fudge the Go package. */
9827 if (cu
->language
== language_go
)
9828 fixup_go_packaging (cu
);
9830 /* Now that we have processed all the DIEs in the CU, all the types
9831 should be complete, and it should now be safe to compute all of the
9833 compute_delayed_physnames (cu
);
9835 if (cu
->language
== language_rust
)
9836 rust_union_quirks (cu
);
9838 /* TUs share symbol tables.
9839 If this is the first TU to use this symtab, complete the construction
9840 of it with end_expandable_symtab. Otherwise, complete the addition of
9841 this TU's symbols to the existing symtab. */
9842 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9844 buildsym_compunit
*builder
= cu
->get_builder ();
9845 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9846 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9850 /* Set symtab language to language from DW_AT_language. If the
9851 compilation is from a C file generated by language preprocessors,
9852 do not set the language if it was already deduced by
9854 if (!(cu
->language
== language_c
9855 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9856 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9861 cu
->get_builder ()->augment_type_symtab ();
9862 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9865 dwarf2_per_objfile
->set_symtab (per_cu
, cust
);
9867 /* Not needed any more. */
9868 cu
->reset_builder ();
9871 /* Process an imported unit DIE. */
9874 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9876 struct attribute
*attr
;
9878 /* For now we don't handle imported units in type units. */
9879 if (cu
->per_cu
->is_debug_types
)
9881 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9882 " supported in type units [in module %s]"),
9883 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9886 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9889 sect_offset sect_off
= attr
->get_ref_die_offset ();
9890 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9891 dwarf2_per_cu_data
*per_cu
9892 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9893 cu
->per_cu
->dwarf2_per_objfile
);
9895 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9896 into another compilation unit, at root level. Regard this as a hint,
9898 if (die
->parent
&& die
->parent
->parent
== NULL
9899 && per_cu
->unit_type
== DW_UT_compile
9900 && per_cu
->lang
== language_cplus
)
9903 /* If necessary, add it to the queue and load its DIEs. */
9904 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9905 load_full_comp_unit (per_cu
, false, cu
->language
);
9907 cu
->per_cu
->imported_symtabs_push (per_cu
);
9911 /* RAII object that represents a process_die scope: i.e.,
9912 starts/finishes processing a DIE. */
9913 class process_die_scope
9916 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9917 : m_die (die
), m_cu (cu
)
9919 /* We should only be processing DIEs not already in process. */
9920 gdb_assert (!m_die
->in_process
);
9921 m_die
->in_process
= true;
9924 ~process_die_scope ()
9926 m_die
->in_process
= false;
9928 /* If we're done processing the DIE for the CU that owns the line
9929 header, we don't need the line header anymore. */
9930 if (m_cu
->line_header_die_owner
== m_die
)
9932 delete m_cu
->line_header
;
9933 m_cu
->line_header
= NULL
;
9934 m_cu
->line_header_die_owner
= NULL
;
9943 /* Process a die and its children. */
9946 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9948 process_die_scope
scope (die
, cu
);
9952 case DW_TAG_padding
:
9954 case DW_TAG_compile_unit
:
9955 case DW_TAG_partial_unit
:
9956 read_file_scope (die
, cu
);
9958 case DW_TAG_type_unit
:
9959 read_type_unit_scope (die
, cu
);
9961 case DW_TAG_subprogram
:
9962 /* Nested subprograms in Fortran get a prefix. */
9963 if (cu
->language
== language_fortran
9964 && die
->parent
!= NULL
9965 && die
->parent
->tag
== DW_TAG_subprogram
)
9966 cu
->processing_has_namespace_info
= true;
9968 case DW_TAG_inlined_subroutine
:
9969 read_func_scope (die
, cu
);
9971 case DW_TAG_lexical_block
:
9972 case DW_TAG_try_block
:
9973 case DW_TAG_catch_block
:
9974 read_lexical_block_scope (die
, cu
);
9976 case DW_TAG_call_site
:
9977 case DW_TAG_GNU_call_site
:
9978 read_call_site_scope (die
, cu
);
9980 case DW_TAG_class_type
:
9981 case DW_TAG_interface_type
:
9982 case DW_TAG_structure_type
:
9983 case DW_TAG_union_type
:
9984 process_structure_scope (die
, cu
);
9986 case DW_TAG_enumeration_type
:
9987 process_enumeration_scope (die
, cu
);
9990 /* These dies have a type, but processing them does not create
9991 a symbol or recurse to process the children. Therefore we can
9992 read them on-demand through read_type_die. */
9993 case DW_TAG_subroutine_type
:
9994 case DW_TAG_set_type
:
9995 case DW_TAG_array_type
:
9996 case DW_TAG_pointer_type
:
9997 case DW_TAG_ptr_to_member_type
:
9998 case DW_TAG_reference_type
:
9999 case DW_TAG_rvalue_reference_type
:
10000 case DW_TAG_string_type
:
10003 case DW_TAG_base_type
:
10004 case DW_TAG_subrange_type
:
10005 case DW_TAG_typedef
:
10006 /* Add a typedef symbol for the type definition, if it has a
10008 new_symbol (die
, read_type_die (die
, cu
), cu
);
10010 case DW_TAG_common_block
:
10011 read_common_block (die
, cu
);
10013 case DW_TAG_common_inclusion
:
10015 case DW_TAG_namespace
:
10016 cu
->processing_has_namespace_info
= true;
10017 read_namespace (die
, cu
);
10019 case DW_TAG_module
:
10020 cu
->processing_has_namespace_info
= true;
10021 read_module (die
, cu
);
10023 case DW_TAG_imported_declaration
:
10024 cu
->processing_has_namespace_info
= true;
10025 if (read_namespace_alias (die
, cu
))
10027 /* The declaration is not a global namespace alias. */
10028 /* Fall through. */
10029 case DW_TAG_imported_module
:
10030 cu
->processing_has_namespace_info
= true;
10031 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10032 || cu
->language
!= language_fortran
))
10033 complaint (_("Tag '%s' has unexpected children"),
10034 dwarf_tag_name (die
->tag
));
10035 read_import_statement (die
, cu
);
10038 case DW_TAG_imported_unit
:
10039 process_imported_unit_die (die
, cu
);
10042 case DW_TAG_variable
:
10043 read_variable (die
, cu
);
10047 new_symbol (die
, NULL
, cu
);
10052 /* DWARF name computation. */
10054 /* A helper function for dwarf2_compute_name which determines whether DIE
10055 needs to have the name of the scope prepended to the name listed in the
10059 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10061 struct attribute
*attr
;
10065 case DW_TAG_namespace
:
10066 case DW_TAG_typedef
:
10067 case DW_TAG_class_type
:
10068 case DW_TAG_interface_type
:
10069 case DW_TAG_structure_type
:
10070 case DW_TAG_union_type
:
10071 case DW_TAG_enumeration_type
:
10072 case DW_TAG_enumerator
:
10073 case DW_TAG_subprogram
:
10074 case DW_TAG_inlined_subroutine
:
10075 case DW_TAG_member
:
10076 case DW_TAG_imported_declaration
:
10079 case DW_TAG_variable
:
10080 case DW_TAG_constant
:
10081 /* We only need to prefix "globally" visible variables. These include
10082 any variable marked with DW_AT_external or any variable that
10083 lives in a namespace. [Variables in anonymous namespaces
10084 require prefixing, but they are not DW_AT_external.] */
10086 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10088 struct dwarf2_cu
*spec_cu
= cu
;
10090 return die_needs_namespace (die_specification (die
, &spec_cu
),
10094 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10095 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10096 && die
->parent
->tag
!= DW_TAG_module
)
10098 /* A variable in a lexical block of some kind does not need a
10099 namespace, even though in C++ such variables may be external
10100 and have a mangled name. */
10101 if (die
->parent
->tag
== DW_TAG_lexical_block
10102 || die
->parent
->tag
== DW_TAG_try_block
10103 || die
->parent
->tag
== DW_TAG_catch_block
10104 || die
->parent
->tag
== DW_TAG_subprogram
)
10113 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10114 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10115 defined for the given DIE. */
10117 static struct attribute
*
10118 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10120 struct attribute
*attr
;
10122 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10124 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10129 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10130 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10131 defined for the given DIE. */
10133 static const char *
10134 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10136 const char *linkage_name
;
10138 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10139 if (linkage_name
== NULL
)
10140 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10142 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10143 See https://github.com/rust-lang/rust/issues/32925. */
10144 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10145 && strchr (linkage_name
, '{') != NULL
)
10146 linkage_name
= NULL
;
10148 return linkage_name
;
10151 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10152 compute the physname for the object, which include a method's:
10153 - formal parameters (C++),
10154 - receiver type (Go),
10156 The term "physname" is a bit confusing.
10157 For C++, for example, it is the demangled name.
10158 For Go, for example, it's the mangled name.
10160 For Ada, return the DIE's linkage name rather than the fully qualified
10161 name. PHYSNAME is ignored..
10163 The result is allocated on the objfile->per_bfd's obstack and
10166 static const char *
10167 dwarf2_compute_name (const char *name
,
10168 struct die_info
*die
, struct dwarf2_cu
*cu
,
10171 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10174 name
= dwarf2_name (die
, cu
);
10176 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10177 but otherwise compute it by typename_concat inside GDB.
10178 FIXME: Actually this is not really true, or at least not always true.
10179 It's all very confusing. compute_and_set_names doesn't try to demangle
10180 Fortran names because there is no mangling standard. So new_symbol
10181 will set the demangled name to the result of dwarf2_full_name, and it is
10182 the demangled name that GDB uses if it exists. */
10183 if (cu
->language
== language_ada
10184 || (cu
->language
== language_fortran
&& physname
))
10186 /* For Ada unit, we prefer the linkage name over the name, as
10187 the former contains the exported name, which the user expects
10188 to be able to reference. Ideally, we want the user to be able
10189 to reference this entity using either natural or linkage name,
10190 but we haven't started looking at this enhancement yet. */
10191 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10193 if (linkage_name
!= NULL
)
10194 return linkage_name
;
10197 /* These are the only languages we know how to qualify names in. */
10199 && (cu
->language
== language_cplus
10200 || cu
->language
== language_fortran
|| cu
->language
== language_d
10201 || cu
->language
== language_rust
))
10203 if (die_needs_namespace (die
, cu
))
10205 const char *prefix
;
10206 const char *canonical_name
= NULL
;
10210 prefix
= determine_prefix (die
, cu
);
10211 if (*prefix
!= '\0')
10213 gdb::unique_xmalloc_ptr
<char> prefixed_name
10214 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10216 buf
.puts (prefixed_name
.get ());
10221 /* Template parameters may be specified in the DIE's DW_AT_name, or
10222 as children with DW_TAG_template_type_param or
10223 DW_TAG_value_type_param. If the latter, add them to the name
10224 here. If the name already has template parameters, then
10225 skip this step; some versions of GCC emit both, and
10226 it is more efficient to use the pre-computed name.
10228 Something to keep in mind about this process: it is very
10229 unlikely, or in some cases downright impossible, to produce
10230 something that will match the mangled name of a function.
10231 If the definition of the function has the same debug info,
10232 we should be able to match up with it anyway. But fallbacks
10233 using the minimal symbol, for instance to find a method
10234 implemented in a stripped copy of libstdc++, will not work.
10235 If we do not have debug info for the definition, we will have to
10236 match them up some other way.
10238 When we do name matching there is a related problem with function
10239 templates; two instantiated function templates are allowed to
10240 differ only by their return types, which we do not add here. */
10242 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10244 struct attribute
*attr
;
10245 struct die_info
*child
;
10248 die
->building_fullname
= 1;
10250 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10254 const gdb_byte
*bytes
;
10255 struct dwarf2_locexpr_baton
*baton
;
10258 if (child
->tag
!= DW_TAG_template_type_param
10259 && child
->tag
!= DW_TAG_template_value_param
)
10270 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10273 complaint (_("template parameter missing DW_AT_type"));
10274 buf
.puts ("UNKNOWN_TYPE");
10277 type
= die_type (child
, cu
);
10279 if (child
->tag
== DW_TAG_template_type_param
)
10281 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10282 &type_print_raw_options
);
10286 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10289 complaint (_("template parameter missing "
10290 "DW_AT_const_value"));
10291 buf
.puts ("UNKNOWN_VALUE");
10295 dwarf2_const_value_attr (attr
, type
, name
,
10296 &cu
->comp_unit_obstack
, cu
,
10297 &value
, &bytes
, &baton
);
10299 if (TYPE_NOSIGN (type
))
10300 /* GDB prints characters as NUMBER 'CHAR'. If that's
10301 changed, this can use value_print instead. */
10302 c_printchar (value
, type
, &buf
);
10305 struct value_print_options opts
;
10308 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10312 else if (bytes
!= NULL
)
10314 v
= allocate_value (type
);
10315 memcpy (value_contents_writeable (v
), bytes
,
10316 TYPE_LENGTH (type
));
10319 v
= value_from_longest (type
, value
);
10321 /* Specify decimal so that we do not depend on
10323 get_formatted_print_options (&opts
, 'd');
10325 value_print (v
, &buf
, &opts
);
10330 die
->building_fullname
= 0;
10334 /* Close the argument list, with a space if necessary
10335 (nested templates). */
10336 if (!buf
.empty () && buf
.string ().back () == '>')
10343 /* For C++ methods, append formal parameter type
10344 information, if PHYSNAME. */
10346 if (physname
&& die
->tag
== DW_TAG_subprogram
10347 && cu
->language
== language_cplus
)
10349 struct type
*type
= read_type_die (die
, cu
);
10351 c_type_print_args (type
, &buf
, 1, cu
->language
,
10352 &type_print_raw_options
);
10354 if (cu
->language
== language_cplus
)
10356 /* Assume that an artificial first parameter is
10357 "this", but do not crash if it is not. RealView
10358 marks unnamed (and thus unused) parameters as
10359 artificial; there is no way to differentiate
10361 if (type
->num_fields () > 0
10362 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10363 && TYPE_FIELD_TYPE (type
, 0)->code () == TYPE_CODE_PTR
10364 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10366 buf
.puts (" const");
10370 const std::string
&intermediate_name
= buf
.string ();
10372 if (cu
->language
== language_cplus
)
10374 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10377 /* If we only computed INTERMEDIATE_NAME, or if
10378 INTERMEDIATE_NAME is already canonical, then we need to
10380 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10381 name
= objfile
->intern (intermediate_name
);
10383 name
= canonical_name
;
10390 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10391 If scope qualifiers are appropriate they will be added. The result
10392 will be allocated on the storage_obstack, or NULL if the DIE does
10393 not have a name. NAME may either be from a previous call to
10394 dwarf2_name or NULL.
10396 The output string will be canonicalized (if C++). */
10398 static const char *
10399 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10401 return dwarf2_compute_name (name
, die
, cu
, 0);
10404 /* Construct a physname for the given DIE in CU. NAME may either be
10405 from a previous call to dwarf2_name or NULL. The result will be
10406 allocated on the objfile_objstack or NULL if the DIE does not have a
10409 The output string will be canonicalized (if C++). */
10411 static const char *
10412 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10414 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10415 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10418 /* In this case dwarf2_compute_name is just a shortcut not building anything
10420 if (!die_needs_namespace (die
, cu
))
10421 return dwarf2_compute_name (name
, die
, cu
, 1);
10423 if (cu
->language
!= language_rust
)
10424 mangled
= dw2_linkage_name (die
, cu
);
10426 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10428 gdb::unique_xmalloc_ptr
<char> demangled
;
10429 if (mangled
!= NULL
)
10432 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10434 /* Do nothing (do not demangle the symbol name). */
10436 else if (cu
->language
== language_go
)
10438 /* This is a lie, but we already lie to the caller new_symbol.
10439 new_symbol assumes we return the mangled name.
10440 This just undoes that lie until things are cleaned up. */
10444 /* Use DMGL_RET_DROP for C++ template functions to suppress
10445 their return type. It is easier for GDB users to search
10446 for such functions as `name(params)' than `long name(params)'.
10447 In such case the minimal symbol names do not match the full
10448 symbol names but for template functions there is never a need
10449 to look up their definition from their declaration so
10450 the only disadvantage remains the minimal symbol variant
10451 `long name(params)' does not have the proper inferior type. */
10452 demangled
.reset (gdb_demangle (mangled
,
10453 (DMGL_PARAMS
| DMGL_ANSI
10454 | DMGL_RET_DROP
)));
10457 canon
= demangled
.get ();
10465 if (canon
== NULL
|| check_physname
)
10467 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10469 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10471 /* It may not mean a bug in GDB. The compiler could also
10472 compute DW_AT_linkage_name incorrectly. But in such case
10473 GDB would need to be bug-to-bug compatible. */
10475 complaint (_("Computed physname <%s> does not match demangled <%s> "
10476 "(from linkage <%s>) - DIE at %s [in module %s]"),
10477 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10478 objfile_name (objfile
));
10480 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10481 is available here - over computed PHYSNAME. It is safer
10482 against both buggy GDB and buggy compilers. */
10496 retval
= objfile
->intern (retval
);
10501 /* Inspect DIE in CU for a namespace alias. If one exists, record
10502 a new symbol for it.
10504 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10507 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10509 struct attribute
*attr
;
10511 /* If the die does not have a name, this is not a namespace
10513 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10517 struct die_info
*d
= die
;
10518 struct dwarf2_cu
*imported_cu
= cu
;
10520 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10521 keep inspecting DIEs until we hit the underlying import. */
10522 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10523 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10525 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10529 d
= follow_die_ref (d
, attr
, &imported_cu
);
10530 if (d
->tag
!= DW_TAG_imported_declaration
)
10534 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10536 complaint (_("DIE at %s has too many recursively imported "
10537 "declarations"), sect_offset_str (d
->sect_off
));
10544 sect_offset sect_off
= attr
->get_ref_die_offset ();
10546 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10547 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10549 /* This declaration is a global namespace alias. Add
10550 a symbol for it whose type is the aliased namespace. */
10551 new_symbol (die
, type
, cu
);
10560 /* Return the using directives repository (global or local?) to use in the
10561 current context for CU.
10563 For Ada, imported declarations can materialize renamings, which *may* be
10564 global. However it is impossible (for now?) in DWARF to distinguish
10565 "external" imported declarations and "static" ones. As all imported
10566 declarations seem to be static in all other languages, make them all CU-wide
10567 global only in Ada. */
10569 static struct using_direct
**
10570 using_directives (struct dwarf2_cu
*cu
)
10572 if (cu
->language
== language_ada
10573 && cu
->get_builder ()->outermost_context_p ())
10574 return cu
->get_builder ()->get_global_using_directives ();
10576 return cu
->get_builder ()->get_local_using_directives ();
10579 /* Read the import statement specified by the given die and record it. */
10582 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10584 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10585 struct attribute
*import_attr
;
10586 struct die_info
*imported_die
, *child_die
;
10587 struct dwarf2_cu
*imported_cu
;
10588 const char *imported_name
;
10589 const char *imported_name_prefix
;
10590 const char *canonical_name
;
10591 const char *import_alias
;
10592 const char *imported_declaration
= NULL
;
10593 const char *import_prefix
;
10594 std::vector
<const char *> excludes
;
10596 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10597 if (import_attr
== NULL
)
10599 complaint (_("Tag '%s' has no DW_AT_import"),
10600 dwarf_tag_name (die
->tag
));
10605 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10606 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10607 if (imported_name
== NULL
)
10609 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10611 The import in the following code:
10625 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10626 <52> DW_AT_decl_file : 1
10627 <53> DW_AT_decl_line : 6
10628 <54> DW_AT_import : <0x75>
10629 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10630 <59> DW_AT_name : B
10631 <5b> DW_AT_decl_file : 1
10632 <5c> DW_AT_decl_line : 2
10633 <5d> DW_AT_type : <0x6e>
10635 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10636 <76> DW_AT_byte_size : 4
10637 <77> DW_AT_encoding : 5 (signed)
10639 imports the wrong die ( 0x75 instead of 0x58 ).
10640 This case will be ignored until the gcc bug is fixed. */
10644 /* Figure out the local name after import. */
10645 import_alias
= dwarf2_name (die
, cu
);
10647 /* Figure out where the statement is being imported to. */
10648 import_prefix
= determine_prefix (die
, cu
);
10650 /* Figure out what the scope of the imported die is and prepend it
10651 to the name of the imported die. */
10652 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10654 if (imported_die
->tag
!= DW_TAG_namespace
10655 && imported_die
->tag
!= DW_TAG_module
)
10657 imported_declaration
= imported_name
;
10658 canonical_name
= imported_name_prefix
;
10660 else if (strlen (imported_name_prefix
) > 0)
10661 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10662 imported_name_prefix
,
10663 (cu
->language
== language_d
? "." : "::"),
10664 imported_name
, (char *) NULL
);
10666 canonical_name
= imported_name
;
10668 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10669 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10670 child_die
= child_die
->sibling
)
10672 /* DWARF-4: A Fortran use statement with a “rename list” may be
10673 represented by an imported module entry with an import attribute
10674 referring to the module and owned entries corresponding to those
10675 entities that are renamed as part of being imported. */
10677 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10679 complaint (_("child DW_TAG_imported_declaration expected "
10680 "- DIE at %s [in module %s]"),
10681 sect_offset_str (child_die
->sect_off
),
10682 objfile_name (objfile
));
10686 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10687 if (import_attr
== NULL
)
10689 complaint (_("Tag '%s' has no DW_AT_import"),
10690 dwarf_tag_name (child_die
->tag
));
10695 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10697 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10698 if (imported_name
== NULL
)
10700 complaint (_("child DW_TAG_imported_declaration has unknown "
10701 "imported name - DIE at %s [in module %s]"),
10702 sect_offset_str (child_die
->sect_off
),
10703 objfile_name (objfile
));
10707 excludes
.push_back (imported_name
);
10709 process_die (child_die
, cu
);
10712 add_using_directive (using_directives (cu
),
10716 imported_declaration
,
10719 &objfile
->objfile_obstack
);
10722 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10723 types, but gives them a size of zero. Starting with version 14,
10724 ICC is compatible with GCC. */
10727 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10729 if (!cu
->checked_producer
)
10730 check_producer (cu
);
10732 return cu
->producer_is_icc_lt_14
;
10735 /* ICC generates a DW_AT_type for C void functions. This was observed on
10736 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10737 which says that void functions should not have a DW_AT_type. */
10740 producer_is_icc (struct dwarf2_cu
*cu
)
10742 if (!cu
->checked_producer
)
10743 check_producer (cu
);
10745 return cu
->producer_is_icc
;
10748 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10749 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10750 this, it was first present in GCC release 4.3.0. */
10753 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10755 if (!cu
->checked_producer
)
10756 check_producer (cu
);
10758 return cu
->producer_is_gcc_lt_4_3
;
10761 static file_and_directory
10762 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10764 file_and_directory res
;
10766 /* Find the filename. Do not use dwarf2_name here, since the filename
10767 is not a source language identifier. */
10768 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10769 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10771 if (res
.comp_dir
== NULL
10772 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10773 && IS_ABSOLUTE_PATH (res
.name
))
10775 res
.comp_dir_storage
= ldirname (res
.name
);
10776 if (!res
.comp_dir_storage
.empty ())
10777 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10779 if (res
.comp_dir
!= NULL
)
10781 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10782 directory, get rid of it. */
10783 const char *cp
= strchr (res
.comp_dir
, ':');
10785 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10786 res
.comp_dir
= cp
+ 1;
10789 if (res
.name
== NULL
)
10790 res
.name
= "<unknown>";
10795 /* Handle DW_AT_stmt_list for a compilation unit.
10796 DIE is the DW_TAG_compile_unit die for CU.
10797 COMP_DIR is the compilation directory. LOWPC is passed to
10798 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10801 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10802 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10804 struct dwarf2_per_objfile
*dwarf2_per_objfile
10805 = cu
->per_cu
->dwarf2_per_objfile
;
10806 struct attribute
*attr
;
10807 struct line_header line_header_local
;
10808 hashval_t line_header_local_hash
;
10810 int decode_mapping
;
10812 gdb_assert (! cu
->per_cu
->is_debug_types
);
10814 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10818 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10820 /* The line header hash table is only created if needed (it exists to
10821 prevent redundant reading of the line table for partial_units).
10822 If we're given a partial_unit, we'll need it. If we're given a
10823 compile_unit, then use the line header hash table if it's already
10824 created, but don't create one just yet. */
10826 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
10827 && die
->tag
== DW_TAG_partial_unit
)
10829 dwarf2_per_objfile
->per_bfd
->line_header_hash
10830 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10831 line_header_eq_voidp
,
10832 free_line_header_voidp
,
10836 line_header_local
.sect_off
= line_offset
;
10837 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10838 line_header_local_hash
= line_header_hash (&line_header_local
);
10839 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
!= NULL
)
10841 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10842 &line_header_local
,
10843 line_header_local_hash
, NO_INSERT
);
10845 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10846 is not present in *SLOT (since if there is something in *SLOT then
10847 it will be for a partial_unit). */
10848 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10850 gdb_assert (*slot
!= NULL
);
10851 cu
->line_header
= (struct line_header
*) *slot
;
10856 /* dwarf_decode_line_header does not yet provide sufficient information.
10857 We always have to call also dwarf_decode_lines for it. */
10858 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10862 cu
->line_header
= lh
.release ();
10863 cu
->line_header_die_owner
= die
;
10865 if (dwarf2_per_objfile
->per_bfd
->line_header_hash
== NULL
)
10869 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->per_bfd
->line_header_hash
.get (),
10870 &line_header_local
,
10871 line_header_local_hash
, INSERT
);
10872 gdb_assert (slot
!= NULL
);
10874 if (slot
!= NULL
&& *slot
== NULL
)
10876 /* This newly decoded line number information unit will be owned
10877 by line_header_hash hash table. */
10878 *slot
= cu
->line_header
;
10879 cu
->line_header_die_owner
= NULL
;
10883 /* We cannot free any current entry in (*slot) as that struct line_header
10884 may be already used by multiple CUs. Create only temporary decoded
10885 line_header for this CU - it may happen at most once for each line
10886 number information unit. And if we're not using line_header_hash
10887 then this is what we want as well. */
10888 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10890 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10891 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10896 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10899 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10901 struct dwarf2_per_objfile
*dwarf2_per_objfile
10902 = cu
->per_cu
->dwarf2_per_objfile
;
10903 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10904 struct gdbarch
*gdbarch
= objfile
->arch ();
10905 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10906 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10907 struct attribute
*attr
;
10908 struct die_info
*child_die
;
10909 CORE_ADDR baseaddr
;
10911 prepare_one_comp_unit (cu
, die
, cu
->language
);
10912 baseaddr
= objfile
->text_section_offset ();
10914 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10916 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10917 from finish_block. */
10918 if (lowpc
== ((CORE_ADDR
) -1))
10920 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10922 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10924 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10925 standardised yet. As a workaround for the language detection we fall
10926 back to the DW_AT_producer string. */
10927 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10928 cu
->language
= language_opencl
;
10930 /* Similar hack for Go. */
10931 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10932 set_cu_language (DW_LANG_Go
, cu
);
10934 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10936 /* Decode line number information if present. We do this before
10937 processing child DIEs, so that the line header table is available
10938 for DW_AT_decl_file. */
10939 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10941 /* Process all dies in compilation unit. */
10942 if (die
->child
!= NULL
)
10944 child_die
= die
->child
;
10945 while (child_die
&& child_die
->tag
)
10947 process_die (child_die
, cu
);
10948 child_die
= child_die
->sibling
;
10952 /* Decode macro information, if present. Dwarf 2 macro information
10953 refers to information in the line number info statement program
10954 header, so we can only read it if we've read the header
10956 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10958 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10959 if (attr
&& cu
->line_header
)
10961 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10962 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10964 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10968 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10969 if (attr
&& cu
->line_header
)
10971 unsigned int macro_offset
= DW_UNSND (attr
);
10973 dwarf_decode_macros (cu
, macro_offset
, 0);
10979 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10981 struct type_unit_group
*tu_group
;
10983 struct attribute
*attr
;
10985 struct signatured_type
*sig_type
;
10987 gdb_assert (per_cu
->is_debug_types
);
10988 sig_type
= (struct signatured_type
*) per_cu
;
10990 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10992 /* If we're using .gdb_index (includes -readnow) then
10993 per_cu->type_unit_group may not have been set up yet. */
10994 if (sig_type
->type_unit_group
== NULL
)
10995 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10996 tu_group
= sig_type
->type_unit_group
;
10998 /* If we've already processed this stmt_list there's no real need to
10999 do it again, we could fake it and just recreate the part we need
11000 (file name,index -> symtab mapping). If data shows this optimization
11001 is useful we can do it then. */
11002 first_time
= tu_group
->compunit_symtab
== NULL
;
11004 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11009 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11010 lh
= dwarf_decode_line_header (line_offset
, this);
11015 start_symtab ("", NULL
, 0);
11018 gdb_assert (tu_group
->symtabs
== NULL
);
11019 gdb_assert (m_builder
== nullptr);
11020 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11021 m_builder
.reset (new struct buildsym_compunit
11022 (COMPUNIT_OBJFILE (cust
), "",
11023 COMPUNIT_DIRNAME (cust
),
11024 compunit_language (cust
),
11026 list_in_scope
= get_builder ()->get_file_symbols ();
11031 line_header
= lh
.release ();
11032 line_header_die_owner
= die
;
11036 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11038 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11039 still initializing it, and our caller (a few levels up)
11040 process_full_type_unit still needs to know if this is the first
11044 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11045 struct symtab
*, line_header
->file_names_size ());
11047 auto &file_names
= line_header
->file_names ();
11048 for (i
= 0; i
< file_names
.size (); ++i
)
11050 file_entry
&fe
= file_names
[i
];
11051 dwarf2_start_subfile (this, fe
.name
,
11052 fe
.include_dir (line_header
));
11053 buildsym_compunit
*b
= get_builder ();
11054 if (b
->get_current_subfile ()->symtab
== NULL
)
11056 /* NOTE: start_subfile will recognize when it's been
11057 passed a file it has already seen. So we can't
11058 assume there's a simple mapping from
11059 cu->line_header->file_names to subfiles, plus
11060 cu->line_header->file_names may contain dups. */
11061 b
->get_current_subfile ()->symtab
11062 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11065 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11066 tu_group
->symtabs
[i
] = fe
.symtab
;
11071 gdb_assert (m_builder
== nullptr);
11072 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11073 m_builder
.reset (new struct buildsym_compunit
11074 (COMPUNIT_OBJFILE (cust
), "",
11075 COMPUNIT_DIRNAME (cust
),
11076 compunit_language (cust
),
11078 list_in_scope
= get_builder ()->get_file_symbols ();
11080 auto &file_names
= line_header
->file_names ();
11081 for (i
= 0; i
< file_names
.size (); ++i
)
11083 file_entry
&fe
= file_names
[i
];
11084 fe
.symtab
= tu_group
->symtabs
[i
];
11088 /* The main symtab is allocated last. Type units don't have DW_AT_name
11089 so they don't have a "real" (so to speak) symtab anyway.
11090 There is later code that will assign the main symtab to all symbols
11091 that don't have one. We need to handle the case of a symbol with a
11092 missing symtab (DW_AT_decl_file) anyway. */
11095 /* Process DW_TAG_type_unit.
11096 For TUs we want to skip the first top level sibling if it's not the
11097 actual type being defined by this TU. In this case the first top
11098 level sibling is there to provide context only. */
11101 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11103 struct die_info
*child_die
;
11105 prepare_one_comp_unit (cu
, die
, language_minimal
);
11107 /* Initialize (or reinitialize) the machinery for building symtabs.
11108 We do this before processing child DIEs, so that the line header table
11109 is available for DW_AT_decl_file. */
11110 cu
->setup_type_unit_groups (die
);
11112 if (die
->child
!= NULL
)
11114 child_die
= die
->child
;
11115 while (child_die
&& child_die
->tag
)
11117 process_die (child_die
, cu
);
11118 child_die
= child_die
->sibling
;
11125 http://gcc.gnu.org/wiki/DebugFission
11126 http://gcc.gnu.org/wiki/DebugFissionDWP
11128 To simplify handling of both DWO files ("object" files with the DWARF info)
11129 and DWP files (a file with the DWOs packaged up into one file), we treat
11130 DWP files as having a collection of virtual DWO files. */
11133 hash_dwo_file (const void *item
)
11135 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11138 hash
= htab_hash_string (dwo_file
->dwo_name
);
11139 if (dwo_file
->comp_dir
!= NULL
)
11140 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11145 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11147 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11148 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11150 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11152 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11153 return lhs
->comp_dir
== rhs
->comp_dir
;
11154 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11157 /* Allocate a hash table for DWO files. */
11160 allocate_dwo_file_hash_table ()
11162 auto delete_dwo_file
= [] (void *item
)
11164 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11169 return htab_up (htab_create_alloc (41,
11176 /* Lookup DWO file DWO_NAME. */
11179 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11180 const char *dwo_name
,
11181 const char *comp_dir
)
11183 struct dwo_file find_entry
;
11186 if (dwarf2_per_objfile
->per_bfd
->dwo_files
== NULL
)
11187 dwarf2_per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11189 find_entry
.dwo_name
= dwo_name
;
11190 find_entry
.comp_dir
= comp_dir
;
11191 slot
= htab_find_slot (dwarf2_per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11198 hash_dwo_unit (const void *item
)
11200 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11202 /* This drops the top 32 bits of the id, but is ok for a hash. */
11203 return dwo_unit
->signature
;
11207 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11209 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11210 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11212 /* The signature is assumed to be unique within the DWO file.
11213 So while object file CU dwo_id's always have the value zero,
11214 that's OK, assuming each object file DWO file has only one CU,
11215 and that's the rule for now. */
11216 return lhs
->signature
== rhs
->signature
;
11219 /* Allocate a hash table for DWO CUs,TUs.
11220 There is one of these tables for each of CUs,TUs for each DWO file. */
11223 allocate_dwo_unit_table ()
11225 /* Start out with a pretty small number.
11226 Generally DWO files contain only one CU and maybe some TUs. */
11227 return htab_up (htab_create_alloc (3,
11230 NULL
, xcalloc
, xfree
));
11233 /* die_reader_func for create_dwo_cu. */
11236 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11237 const gdb_byte
*info_ptr
,
11238 struct die_info
*comp_unit_die
,
11239 struct dwo_file
*dwo_file
,
11240 struct dwo_unit
*dwo_unit
)
11242 struct dwarf2_cu
*cu
= reader
->cu
;
11243 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11244 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11246 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11247 if (!signature
.has_value ())
11249 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11250 " its dwo_id [in module %s]"),
11251 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11255 dwo_unit
->dwo_file
= dwo_file
;
11256 dwo_unit
->signature
= *signature
;
11257 dwo_unit
->section
= section
;
11258 dwo_unit
->sect_off
= sect_off
;
11259 dwo_unit
->length
= cu
->per_cu
->length
;
11261 if (dwarf_read_debug
)
11262 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11263 sect_offset_str (sect_off
),
11264 hex_string (dwo_unit
->signature
));
11267 /* Create the dwo_units for the CUs in a DWO_FILE.
11268 Note: This function processes DWO files only, not DWP files. */
11271 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11272 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11273 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11275 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11276 const gdb_byte
*info_ptr
, *end_ptr
;
11278 section
.read (objfile
);
11279 info_ptr
= section
.buffer
;
11281 if (info_ptr
== NULL
)
11284 if (dwarf_read_debug
)
11286 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11287 section
.get_name (),
11288 section
.get_file_name ());
11291 end_ptr
= info_ptr
+ section
.size
;
11292 while (info_ptr
< end_ptr
)
11294 struct dwarf2_per_cu_data per_cu
;
11295 struct dwo_unit read_unit
{};
11296 struct dwo_unit
*dwo_unit
;
11298 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11300 memset (&per_cu
, 0, sizeof (per_cu
));
11301 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11302 per_cu
.is_debug_types
= 0;
11303 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11304 per_cu
.section
= §ion
;
11306 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11307 if (!reader
.dummy_p
)
11308 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11309 &dwo_file
, &read_unit
);
11310 info_ptr
+= per_cu
.length
;
11312 // If the unit could not be parsed, skip it.
11313 if (read_unit
.dwo_file
== NULL
)
11316 if (cus_htab
== NULL
)
11317 cus_htab
= allocate_dwo_unit_table ();
11319 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
11321 *dwo_unit
= read_unit
;
11322 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11323 gdb_assert (slot
!= NULL
);
11326 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11327 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11329 complaint (_("debug cu entry at offset %s is duplicate to"
11330 " the entry at offset %s, signature %s"),
11331 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11332 hex_string (dwo_unit
->signature
));
11334 *slot
= (void *)dwo_unit
;
11338 /* DWP file .debug_{cu,tu}_index section format:
11339 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11343 Both index sections have the same format, and serve to map a 64-bit
11344 signature to a set of section numbers. Each section begins with a header,
11345 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11346 indexes, and a pool of 32-bit section numbers. The index sections will be
11347 aligned at 8-byte boundaries in the file.
11349 The index section header consists of:
11351 V, 32 bit version number
11353 N, 32 bit number of compilation units or type units in the index
11354 M, 32 bit number of slots in the hash table
11356 Numbers are recorded using the byte order of the application binary.
11358 The hash table begins at offset 16 in the section, and consists of an array
11359 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11360 order of the application binary). Unused slots in the hash table are 0.
11361 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11363 The parallel table begins immediately after the hash table
11364 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11365 array of 32-bit indexes (using the byte order of the application binary),
11366 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11367 table contains a 32-bit index into the pool of section numbers. For unused
11368 hash table slots, the corresponding entry in the parallel table will be 0.
11370 The pool of section numbers begins immediately following the hash table
11371 (at offset 16 + 12 * M from the beginning of the section). The pool of
11372 section numbers consists of an array of 32-bit words (using the byte order
11373 of the application binary). Each item in the array is indexed starting
11374 from 0. The hash table entry provides the index of the first section
11375 number in the set. Additional section numbers in the set follow, and the
11376 set is terminated by a 0 entry (section number 0 is not used in ELF).
11378 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11379 section must be the first entry in the set, and the .debug_abbrev.dwo must
11380 be the second entry. Other members of the set may follow in any order.
11386 DWP Version 2 combines all the .debug_info, etc. sections into one,
11387 and the entries in the index tables are now offsets into these sections.
11388 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11391 Index Section Contents:
11393 Hash Table of Signatures dwp_hash_table.hash_table
11394 Parallel Table of Indices dwp_hash_table.unit_table
11395 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11396 Table of Section Sizes dwp_hash_table.v2.sizes
11398 The index section header consists of:
11400 V, 32 bit version number
11401 L, 32 bit number of columns in the table of section offsets
11402 N, 32 bit number of compilation units or type units in the index
11403 M, 32 bit number of slots in the hash table
11405 Numbers are recorded using the byte order of the application binary.
11407 The hash table has the same format as version 1.
11408 The parallel table of indices has the same format as version 1,
11409 except that the entries are origin-1 indices into the table of sections
11410 offsets and the table of section sizes.
11412 The table of offsets begins immediately following the parallel table
11413 (at offset 16 + 12 * M from the beginning of the section). The table is
11414 a two-dimensional array of 32-bit words (using the byte order of the
11415 application binary), with L columns and N+1 rows, in row-major order.
11416 Each row in the array is indexed starting from 0. The first row provides
11417 a key to the remaining rows: each column in this row provides an identifier
11418 for a debug section, and the offsets in the same column of subsequent rows
11419 refer to that section. The section identifiers are:
11421 DW_SECT_INFO 1 .debug_info.dwo
11422 DW_SECT_TYPES 2 .debug_types.dwo
11423 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11424 DW_SECT_LINE 4 .debug_line.dwo
11425 DW_SECT_LOC 5 .debug_loc.dwo
11426 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11427 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11428 DW_SECT_MACRO 8 .debug_macro.dwo
11430 The offsets provided by the CU and TU index sections are the base offsets
11431 for the contributions made by each CU or TU to the corresponding section
11432 in the package file. Each CU and TU header contains an abbrev_offset
11433 field, used to find the abbreviations table for that CU or TU within the
11434 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11435 be interpreted as relative to the base offset given in the index section.
11436 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11437 should be interpreted as relative to the base offset for .debug_line.dwo,
11438 and offsets into other debug sections obtained from DWARF attributes should
11439 also be interpreted as relative to the corresponding base offset.
11441 The table of sizes begins immediately following the table of offsets.
11442 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11443 with L columns and N rows, in row-major order. Each row in the array is
11444 indexed starting from 1 (row 0 is shared by the two tables).
11448 Hash table lookup is handled the same in version 1 and 2:
11450 We assume that N and M will not exceed 2^32 - 1.
11451 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11453 Given a 64-bit compilation unit signature or a type signature S, an entry
11454 in the hash table is located as follows:
11456 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11457 the low-order k bits all set to 1.
11459 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11461 3) If the hash table entry at index H matches the signature, use that
11462 entry. If the hash table entry at index H is unused (all zeroes),
11463 terminate the search: the signature is not present in the table.
11465 4) Let H = (H + H') modulo M. Repeat at Step 3.
11467 Because M > N and H' and M are relatively prime, the search is guaranteed
11468 to stop at an unused slot or find the match. */
11470 /* Create a hash table to map DWO IDs to their CU/TU entry in
11471 .debug_{info,types}.dwo in DWP_FILE.
11472 Returns NULL if there isn't one.
11473 Note: This function processes DWP files only, not DWO files. */
11475 static struct dwp_hash_table
*
11476 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11477 struct dwp_file
*dwp_file
, int is_debug_types
)
11479 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11480 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11481 const gdb_byte
*index_ptr
, *index_end
;
11482 struct dwarf2_section_info
*index
;
11483 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11484 struct dwp_hash_table
*htab
;
11486 if (is_debug_types
)
11487 index
= &dwp_file
->sections
.tu_index
;
11489 index
= &dwp_file
->sections
.cu_index
;
11491 if (index
->empty ())
11493 index
->read (objfile
);
11495 index_ptr
= index
->buffer
;
11496 index_end
= index_ptr
+ index
->size
;
11498 version
= read_4_bytes (dbfd
, index_ptr
);
11501 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11505 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11507 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11510 if (version
!= 1 && version
!= 2)
11512 error (_("Dwarf Error: unsupported DWP file version (%s)"
11513 " [in module %s]"),
11514 pulongest (version
), dwp_file
->name
);
11516 if (nr_slots
!= (nr_slots
& -nr_slots
))
11518 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11519 " is not power of 2 [in module %s]"),
11520 pulongest (nr_slots
), dwp_file
->name
);
11523 htab
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11524 htab
->version
= version
;
11525 htab
->nr_columns
= nr_columns
;
11526 htab
->nr_units
= nr_units
;
11527 htab
->nr_slots
= nr_slots
;
11528 htab
->hash_table
= index_ptr
;
11529 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11531 /* Exit early if the table is empty. */
11532 if (nr_slots
== 0 || nr_units
== 0
11533 || (version
== 2 && nr_columns
== 0))
11535 /* All must be zero. */
11536 if (nr_slots
!= 0 || nr_units
!= 0
11537 || (version
== 2 && nr_columns
!= 0))
11539 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11540 " all zero [in modules %s]"),
11548 htab
->section_pool
.v1
.indices
=
11549 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11550 /* It's harder to decide whether the section is too small in v1.
11551 V1 is deprecated anyway so we punt. */
11555 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11556 int *ids
= htab
->section_pool
.v2
.section_ids
;
11557 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11558 /* Reverse map for error checking. */
11559 int ids_seen
[DW_SECT_MAX
+ 1];
11562 if (nr_columns
< 2)
11564 error (_("Dwarf Error: bad DWP hash table, too few columns"
11565 " in section table [in module %s]"),
11568 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11570 error (_("Dwarf Error: bad DWP hash table, too many columns"
11571 " in section table [in module %s]"),
11574 memset (ids
, 255, sizeof_ids
);
11575 memset (ids_seen
, 255, sizeof (ids_seen
));
11576 for (i
= 0; i
< nr_columns
; ++i
)
11578 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11580 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11582 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11583 " in section table [in module %s]"),
11584 id
, dwp_file
->name
);
11586 if (ids_seen
[id
] != -1)
11588 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11589 " id %d in section table [in module %s]"),
11590 id
, dwp_file
->name
);
11595 /* Must have exactly one info or types section. */
11596 if (((ids_seen
[DW_SECT_INFO
] != -1)
11597 + (ids_seen
[DW_SECT_TYPES
] != -1))
11600 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11601 " DWO info/types section [in module %s]"),
11604 /* Must have an abbrev section. */
11605 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11607 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11608 " section [in module %s]"),
11611 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11612 htab
->section_pool
.v2
.sizes
=
11613 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11614 * nr_units
* nr_columns
);
11615 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11616 * nr_units
* nr_columns
))
11619 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11620 " [in module %s]"),
11628 /* Update SECTIONS with the data from SECTP.
11630 This function is like the other "locate" section routines that are
11631 passed to bfd_map_over_sections, but in this context the sections to
11632 read comes from the DWP V1 hash table, not the full ELF section table.
11634 The result is non-zero for success, or zero if an error was found. */
11637 locate_v1_virtual_dwo_sections (asection
*sectp
,
11638 struct virtual_v1_dwo_sections
*sections
)
11640 const struct dwop_section_names
*names
= &dwop_section_names
;
11642 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11644 /* There can be only one. */
11645 if (sections
->abbrev
.s
.section
!= NULL
)
11647 sections
->abbrev
.s
.section
= sectp
;
11648 sections
->abbrev
.size
= bfd_section_size (sectp
);
11650 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11651 || section_is_p (sectp
->name
, &names
->types_dwo
))
11653 /* There can be only one. */
11654 if (sections
->info_or_types
.s
.section
!= NULL
)
11656 sections
->info_or_types
.s
.section
= sectp
;
11657 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11659 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11661 /* There can be only one. */
11662 if (sections
->line
.s
.section
!= NULL
)
11664 sections
->line
.s
.section
= sectp
;
11665 sections
->line
.size
= bfd_section_size (sectp
);
11667 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11669 /* There can be only one. */
11670 if (sections
->loc
.s
.section
!= NULL
)
11672 sections
->loc
.s
.section
= sectp
;
11673 sections
->loc
.size
= bfd_section_size (sectp
);
11675 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11677 /* There can be only one. */
11678 if (sections
->macinfo
.s
.section
!= NULL
)
11680 sections
->macinfo
.s
.section
= sectp
;
11681 sections
->macinfo
.size
= bfd_section_size (sectp
);
11683 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11685 /* There can be only one. */
11686 if (sections
->macro
.s
.section
!= NULL
)
11688 sections
->macro
.s
.section
= sectp
;
11689 sections
->macro
.size
= bfd_section_size (sectp
);
11691 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11693 /* There can be only one. */
11694 if (sections
->str_offsets
.s
.section
!= NULL
)
11696 sections
->str_offsets
.s
.section
= sectp
;
11697 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11701 /* No other kind of section is valid. */
11708 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11709 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11710 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11711 This is for DWP version 1 files. */
11713 static struct dwo_unit
*
11714 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11715 struct dwp_file
*dwp_file
,
11716 uint32_t unit_index
,
11717 const char *comp_dir
,
11718 ULONGEST signature
, int is_debug_types
)
11720 const struct dwp_hash_table
*dwp_htab
=
11721 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11722 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11723 const char *kind
= is_debug_types
? "TU" : "CU";
11724 struct dwo_file
*dwo_file
;
11725 struct dwo_unit
*dwo_unit
;
11726 struct virtual_v1_dwo_sections sections
;
11727 void **dwo_file_slot
;
11730 gdb_assert (dwp_file
->version
== 1);
11732 if (dwarf_read_debug
)
11734 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11736 pulongest (unit_index
), hex_string (signature
),
11740 /* Fetch the sections of this DWO unit.
11741 Put a limit on the number of sections we look for so that bad data
11742 doesn't cause us to loop forever. */
11744 #define MAX_NR_V1_DWO_SECTIONS \
11745 (1 /* .debug_info or .debug_types */ \
11746 + 1 /* .debug_abbrev */ \
11747 + 1 /* .debug_line */ \
11748 + 1 /* .debug_loc */ \
11749 + 1 /* .debug_str_offsets */ \
11750 + 1 /* .debug_macro or .debug_macinfo */ \
11751 + 1 /* trailing zero */)
11753 memset (§ions
, 0, sizeof (sections
));
11755 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11758 uint32_t section_nr
=
11759 read_4_bytes (dbfd
,
11760 dwp_htab
->section_pool
.v1
.indices
11761 + (unit_index
+ i
) * sizeof (uint32_t));
11763 if (section_nr
== 0)
11765 if (section_nr
>= dwp_file
->num_sections
)
11767 error (_("Dwarf Error: bad DWP hash table, section number too large"
11768 " [in module %s]"),
11772 sectp
= dwp_file
->elf_sections
[section_nr
];
11773 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11775 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11776 " [in module %s]"),
11782 || sections
.info_or_types
.empty ()
11783 || sections
.abbrev
.empty ())
11785 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11786 " [in module %s]"),
11789 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11791 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11792 " [in module %s]"),
11796 /* It's easier for the rest of the code if we fake a struct dwo_file and
11797 have dwo_unit "live" in that. At least for now.
11799 The DWP file can be made up of a random collection of CUs and TUs.
11800 However, for each CU + set of TUs that came from the same original DWO
11801 file, we can combine them back into a virtual DWO file to save space
11802 (fewer struct dwo_file objects to allocate). Remember that for really
11803 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11805 std::string virtual_dwo_name
=
11806 string_printf ("virtual-dwo/%d-%d-%d-%d",
11807 sections
.abbrev
.get_id (),
11808 sections
.line
.get_id (),
11809 sections
.loc
.get_id (),
11810 sections
.str_offsets
.get_id ());
11811 /* Can we use an existing virtual DWO file? */
11812 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11813 virtual_dwo_name
.c_str (),
11815 /* Create one if necessary. */
11816 if (*dwo_file_slot
== NULL
)
11818 if (dwarf_read_debug
)
11820 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11821 virtual_dwo_name
.c_str ());
11823 dwo_file
= new struct dwo_file
;
11824 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
11825 dwo_file
->comp_dir
= comp_dir
;
11826 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11827 dwo_file
->sections
.line
= sections
.line
;
11828 dwo_file
->sections
.loc
= sections
.loc
;
11829 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11830 dwo_file
->sections
.macro
= sections
.macro
;
11831 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11832 /* The "str" section is global to the entire DWP file. */
11833 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11834 /* The info or types section is assigned below to dwo_unit,
11835 there's no need to record it in dwo_file.
11836 Also, we can't simply record type sections in dwo_file because
11837 we record a pointer into the vector in dwo_unit. As we collect more
11838 types we'll grow the vector and eventually have to reallocate space
11839 for it, invalidating all copies of pointers into the previous
11841 *dwo_file_slot
= dwo_file
;
11845 if (dwarf_read_debug
)
11847 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11848 virtual_dwo_name
.c_str ());
11850 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11853 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11854 dwo_unit
->dwo_file
= dwo_file
;
11855 dwo_unit
->signature
= signature
;
11856 dwo_unit
->section
=
11857 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11858 *dwo_unit
->section
= sections
.info_or_types
;
11859 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11864 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11865 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11866 piece within that section used by a TU/CU, return a virtual section
11867 of just that piece. */
11869 static struct dwarf2_section_info
11870 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11871 struct dwarf2_section_info
*section
,
11872 bfd_size_type offset
, bfd_size_type size
)
11874 struct dwarf2_section_info result
;
11877 gdb_assert (section
!= NULL
);
11878 gdb_assert (!section
->is_virtual
);
11880 memset (&result
, 0, sizeof (result
));
11881 result
.s
.containing_section
= section
;
11882 result
.is_virtual
= true;
11887 sectp
= section
->get_bfd_section ();
11889 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11890 bounds of the real section. This is a pretty-rare event, so just
11891 flag an error (easier) instead of a warning and trying to cope. */
11893 || offset
+ size
> bfd_section_size (sectp
))
11895 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11896 " in section %s [in module %s]"),
11897 sectp
? bfd_section_name (sectp
) : "<unknown>",
11898 objfile_name (dwarf2_per_objfile
->objfile
));
11901 result
.virtual_offset
= offset
;
11902 result
.size
= size
;
11906 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11907 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11908 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11909 This is for DWP version 2 files. */
11911 static struct dwo_unit
*
11912 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11913 struct dwp_file
*dwp_file
,
11914 uint32_t unit_index
,
11915 const char *comp_dir
,
11916 ULONGEST signature
, int is_debug_types
)
11918 const struct dwp_hash_table
*dwp_htab
=
11919 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11920 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11921 const char *kind
= is_debug_types
? "TU" : "CU";
11922 struct dwo_file
*dwo_file
;
11923 struct dwo_unit
*dwo_unit
;
11924 struct virtual_v2_dwo_sections sections
;
11925 void **dwo_file_slot
;
11928 gdb_assert (dwp_file
->version
== 2);
11930 if (dwarf_read_debug
)
11932 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11934 pulongest (unit_index
), hex_string (signature
),
11938 /* Fetch the section offsets of this DWO unit. */
11940 memset (§ions
, 0, sizeof (sections
));
11942 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11944 uint32_t offset
= read_4_bytes (dbfd
,
11945 dwp_htab
->section_pool
.v2
.offsets
11946 + (((unit_index
- 1) * dwp_htab
->nr_columns
11948 * sizeof (uint32_t)));
11949 uint32_t size
= read_4_bytes (dbfd
,
11950 dwp_htab
->section_pool
.v2
.sizes
11951 + (((unit_index
- 1) * dwp_htab
->nr_columns
11953 * sizeof (uint32_t)));
11955 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11958 case DW_SECT_TYPES
:
11959 sections
.info_or_types_offset
= offset
;
11960 sections
.info_or_types_size
= size
;
11962 case DW_SECT_ABBREV
:
11963 sections
.abbrev_offset
= offset
;
11964 sections
.abbrev_size
= size
;
11967 sections
.line_offset
= offset
;
11968 sections
.line_size
= size
;
11971 sections
.loc_offset
= offset
;
11972 sections
.loc_size
= size
;
11974 case DW_SECT_STR_OFFSETS
:
11975 sections
.str_offsets_offset
= offset
;
11976 sections
.str_offsets_size
= size
;
11978 case DW_SECT_MACINFO
:
11979 sections
.macinfo_offset
= offset
;
11980 sections
.macinfo_size
= size
;
11982 case DW_SECT_MACRO
:
11983 sections
.macro_offset
= offset
;
11984 sections
.macro_size
= size
;
11989 /* It's easier for the rest of the code if we fake a struct dwo_file and
11990 have dwo_unit "live" in that. At least for now.
11992 The DWP file can be made up of a random collection of CUs and TUs.
11993 However, for each CU + set of TUs that came from the same original DWO
11994 file, we can combine them back into a virtual DWO file to save space
11995 (fewer struct dwo_file objects to allocate). Remember that for really
11996 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11998 std::string virtual_dwo_name
=
11999 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12000 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12001 (long) (sections
.line_size
? sections
.line_offset
: 0),
12002 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12003 (long) (sections
.str_offsets_size
12004 ? sections
.str_offsets_offset
: 0));
12005 /* Can we use an existing virtual DWO file? */
12006 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12007 virtual_dwo_name
.c_str (),
12009 /* Create one if necessary. */
12010 if (*dwo_file_slot
== NULL
)
12012 if (dwarf_read_debug
)
12014 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12015 virtual_dwo_name
.c_str ());
12017 dwo_file
= new struct dwo_file
;
12018 dwo_file
->dwo_name
= dwarf2_per_objfile
->objfile
->intern (virtual_dwo_name
);
12019 dwo_file
->comp_dir
= comp_dir
;
12020 dwo_file
->sections
.abbrev
=
12021 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12022 sections
.abbrev_offset
, sections
.abbrev_size
);
12023 dwo_file
->sections
.line
=
12024 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12025 sections
.line_offset
, sections
.line_size
);
12026 dwo_file
->sections
.loc
=
12027 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12028 sections
.loc_offset
, sections
.loc_size
);
12029 dwo_file
->sections
.macinfo
=
12030 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12031 sections
.macinfo_offset
, sections
.macinfo_size
);
12032 dwo_file
->sections
.macro
=
12033 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12034 sections
.macro_offset
, sections
.macro_size
);
12035 dwo_file
->sections
.str_offsets
=
12036 create_dwp_v2_section (dwarf2_per_objfile
,
12037 &dwp_file
->sections
.str_offsets
,
12038 sections
.str_offsets_offset
,
12039 sections
.str_offsets_size
);
12040 /* The "str" section is global to the entire DWP file. */
12041 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12042 /* The info or types section is assigned below to dwo_unit,
12043 there's no need to record it in dwo_file.
12044 Also, we can't simply record type sections in dwo_file because
12045 we record a pointer into the vector in dwo_unit. As we collect more
12046 types we'll grow the vector and eventually have to reallocate space
12047 for it, invalidating all copies of pointers into the previous
12049 *dwo_file_slot
= dwo_file
;
12053 if (dwarf_read_debug
)
12055 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12056 virtual_dwo_name
.c_str ());
12058 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12061 dwo_unit
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12062 dwo_unit
->dwo_file
= dwo_file
;
12063 dwo_unit
->signature
= signature
;
12064 dwo_unit
->section
=
12065 XOBNEW (&dwarf2_per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12066 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12068 ? &dwp_file
->sections
.types
12069 : &dwp_file
->sections
.info
,
12070 sections
.info_or_types_offset
,
12071 sections
.info_or_types_size
);
12072 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12077 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12078 Returns NULL if the signature isn't found. */
12080 static struct dwo_unit
*
12081 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12082 struct dwp_file
*dwp_file
, const char *comp_dir
,
12083 ULONGEST signature
, int is_debug_types
)
12085 const struct dwp_hash_table
*dwp_htab
=
12086 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12087 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12088 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12089 uint32_t hash
= signature
& mask
;
12090 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12093 struct dwo_unit find_dwo_cu
;
12095 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12096 find_dwo_cu
.signature
= signature
;
12097 slot
= htab_find_slot (is_debug_types
12098 ? dwp_file
->loaded_tus
.get ()
12099 : dwp_file
->loaded_cus
.get (),
12100 &find_dwo_cu
, INSERT
);
12103 return (struct dwo_unit
*) *slot
;
12105 /* Use a for loop so that we don't loop forever on bad debug info. */
12106 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12108 ULONGEST signature_in_table
;
12110 signature_in_table
=
12111 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12112 if (signature_in_table
== signature
)
12114 uint32_t unit_index
=
12115 read_4_bytes (dbfd
,
12116 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12118 if (dwp_file
->version
== 1)
12120 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12121 dwp_file
, unit_index
,
12122 comp_dir
, signature
,
12127 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12128 dwp_file
, unit_index
,
12129 comp_dir
, signature
,
12132 return (struct dwo_unit
*) *slot
;
12134 if (signature_in_table
== 0)
12136 hash
= (hash
+ hash2
) & mask
;
12139 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12140 " [in module %s]"),
12144 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12145 Open the file specified by FILE_NAME and hand it off to BFD for
12146 preliminary analysis. Return a newly initialized bfd *, which
12147 includes a canonicalized copy of FILE_NAME.
12148 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12149 SEARCH_CWD is true if the current directory is to be searched.
12150 It will be searched before debug-file-directory.
12151 If successful, the file is added to the bfd include table of the
12152 objfile's bfd (see gdb_bfd_record_inclusion).
12153 If unable to find/open the file, return NULL.
12154 NOTE: This function is derived from symfile_bfd_open. */
12156 static gdb_bfd_ref_ptr
12157 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12158 const char *file_name
, int is_dwp
, int search_cwd
)
12161 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12162 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12163 to debug_file_directory. */
12164 const char *search_path
;
12165 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12167 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12170 if (*debug_file_directory
!= '\0')
12172 search_path_holder
.reset (concat (".", dirname_separator_string
,
12173 debug_file_directory
,
12175 search_path
= search_path_holder
.get ();
12181 search_path
= debug_file_directory
;
12183 openp_flags flags
= OPF_RETURN_REALPATH
;
12185 flags
|= OPF_SEARCH_IN_PATH
;
12187 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12188 desc
= openp (search_path
, flags
, file_name
,
12189 O_RDONLY
| O_BINARY
, &absolute_name
);
12193 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12195 if (sym_bfd
== NULL
)
12197 bfd_set_cacheable (sym_bfd
.get (), 1);
12199 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12202 /* Success. Record the bfd as having been included by the objfile's bfd.
12203 This is important because things like demangled_names_hash lives in the
12204 objfile's per_bfd space and may have references to things like symbol
12205 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12206 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12211 /* Try to open DWO file FILE_NAME.
12212 COMP_DIR is the DW_AT_comp_dir attribute.
12213 The result is the bfd handle of the file.
12214 If there is a problem finding or opening the file, return NULL.
12215 Upon success, the canonicalized path of the file is stored in the bfd,
12216 same as symfile_bfd_open. */
12218 static gdb_bfd_ref_ptr
12219 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12220 const char *file_name
, const char *comp_dir
)
12222 if (IS_ABSOLUTE_PATH (file_name
))
12223 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12224 0 /*is_dwp*/, 0 /*search_cwd*/);
12226 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12228 if (comp_dir
!= NULL
)
12230 gdb::unique_xmalloc_ptr
<char> path_to_try
12231 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12233 /* NOTE: If comp_dir is a relative path, this will also try the
12234 search path, which seems useful. */
12235 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12236 path_to_try
.get (),
12238 1 /*search_cwd*/));
12243 /* That didn't work, try debug-file-directory, which, despite its name,
12244 is a list of paths. */
12246 if (*debug_file_directory
== '\0')
12249 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12250 0 /*is_dwp*/, 1 /*search_cwd*/);
12253 /* This function is mapped across the sections and remembers the offset and
12254 size of each of the DWO debugging sections we are interested in. */
12257 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12259 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12260 const struct dwop_section_names
*names
= &dwop_section_names
;
12262 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12264 dwo_sections
->abbrev
.s
.section
= sectp
;
12265 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12267 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12269 dwo_sections
->info
.s
.section
= sectp
;
12270 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12272 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12274 dwo_sections
->line
.s
.section
= sectp
;
12275 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12277 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12279 dwo_sections
->loc
.s
.section
= sectp
;
12280 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12282 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12284 dwo_sections
->loclists
.s
.section
= sectp
;
12285 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12287 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12289 dwo_sections
->macinfo
.s
.section
= sectp
;
12290 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12292 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12294 dwo_sections
->macro
.s
.section
= sectp
;
12295 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12297 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12299 dwo_sections
->str
.s
.section
= sectp
;
12300 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12302 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12304 dwo_sections
->str_offsets
.s
.section
= sectp
;
12305 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12307 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12309 struct dwarf2_section_info type_section
;
12311 memset (&type_section
, 0, sizeof (type_section
));
12312 type_section
.s
.section
= sectp
;
12313 type_section
.size
= bfd_section_size (sectp
);
12314 dwo_sections
->types
.push_back (type_section
);
12318 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12319 by PER_CU. This is for the non-DWP case.
12320 The result is NULL if DWO_NAME can't be found. */
12322 static struct dwo_file
*
12323 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12324 const char *dwo_name
, const char *comp_dir
)
12326 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12328 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12331 if (dwarf_read_debug
)
12332 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12336 dwo_file_up
dwo_file (new struct dwo_file
);
12337 dwo_file
->dwo_name
= dwo_name
;
12338 dwo_file
->comp_dir
= comp_dir
;
12339 dwo_file
->dbfd
= std::move (dbfd
);
12341 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12342 &dwo_file
->sections
);
12344 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12345 dwo_file
->sections
.info
, dwo_file
->cus
);
12347 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12348 dwo_file
->sections
.types
, dwo_file
->tus
);
12350 if (dwarf_read_debug
)
12351 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12353 return dwo_file
.release ();
12356 /* This function is mapped across the sections and remembers the offset and
12357 size of each of the DWP debugging sections common to version 1 and 2 that
12358 we are interested in. */
12361 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12362 void *dwp_file_ptr
)
12364 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12365 const struct dwop_section_names
*names
= &dwop_section_names
;
12366 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12368 /* Record the ELF section number for later lookup: this is what the
12369 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12370 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12371 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12373 /* Look for specific sections that we need. */
12374 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12376 dwp_file
->sections
.str
.s
.section
= sectp
;
12377 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12379 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12381 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12382 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12384 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12386 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12387 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12391 /* This function is mapped across the sections and remembers the offset and
12392 size of each of the DWP version 2 debugging sections that we are interested
12393 in. This is split into a separate function because we don't know if we
12394 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12397 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12399 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12400 const struct dwop_section_names
*names
= &dwop_section_names
;
12401 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12403 /* Record the ELF section number for later lookup: this is what the
12404 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12405 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12406 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12408 /* Look for specific sections that we need. */
12409 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12411 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12412 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12414 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12416 dwp_file
->sections
.info
.s
.section
= sectp
;
12417 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12419 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12421 dwp_file
->sections
.line
.s
.section
= sectp
;
12422 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12424 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12426 dwp_file
->sections
.loc
.s
.section
= sectp
;
12427 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12429 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12431 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12432 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12434 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12436 dwp_file
->sections
.macro
.s
.section
= sectp
;
12437 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12439 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12441 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12442 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12444 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12446 dwp_file
->sections
.types
.s
.section
= sectp
;
12447 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12451 /* Hash function for dwp_file loaded CUs/TUs. */
12454 hash_dwp_loaded_cutus (const void *item
)
12456 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12458 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12459 return dwo_unit
->signature
;
12462 /* Equality function for dwp_file loaded CUs/TUs. */
12465 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12467 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12468 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12470 return dua
->signature
== dub
->signature
;
12473 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12476 allocate_dwp_loaded_cutus_table ()
12478 return htab_up (htab_create_alloc (3,
12479 hash_dwp_loaded_cutus
,
12480 eq_dwp_loaded_cutus
,
12481 NULL
, xcalloc
, xfree
));
12484 /* Try to open DWP file FILE_NAME.
12485 The result is the bfd handle of the file.
12486 If there is a problem finding or opening the file, return NULL.
12487 Upon success, the canonicalized path of the file is stored in the bfd,
12488 same as symfile_bfd_open. */
12490 static gdb_bfd_ref_ptr
12491 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12492 const char *file_name
)
12494 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12496 1 /*search_cwd*/));
12500 /* Work around upstream bug 15652.
12501 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12502 [Whether that's a "bug" is debatable, but it is getting in our way.]
12503 We have no real idea where the dwp file is, because gdb's realpath-ing
12504 of the executable's path may have discarded the needed info.
12505 [IWBN if the dwp file name was recorded in the executable, akin to
12506 .gnu_debuglink, but that doesn't exist yet.]
12507 Strip the directory from FILE_NAME and search again. */
12508 if (*debug_file_directory
!= '\0')
12510 /* Don't implicitly search the current directory here.
12511 If the user wants to search "." to handle this case,
12512 it must be added to debug-file-directory. */
12513 return try_open_dwop_file (dwarf2_per_objfile
,
12514 lbasename (file_name
), 1 /*is_dwp*/,
12521 /* Initialize the use of the DWP file for the current objfile.
12522 By convention the name of the DWP file is ${objfile}.dwp.
12523 The result is NULL if it can't be found. */
12525 static std::unique_ptr
<struct dwp_file
>
12526 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12528 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12530 /* Try to find first .dwp for the binary file before any symbolic links
12533 /* If the objfile is a debug file, find the name of the real binary
12534 file and get the name of dwp file from there. */
12535 std::string dwp_name
;
12536 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12538 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12539 const char *backlink_basename
= lbasename (backlink
->original_name
);
12541 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12544 dwp_name
= objfile
->original_name
;
12546 dwp_name
+= ".dwp";
12548 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12550 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12552 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12553 dwp_name
= objfile_name (objfile
);
12554 dwp_name
+= ".dwp";
12555 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12560 if (dwarf_read_debug
)
12561 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12562 return std::unique_ptr
<dwp_file
> ();
12565 const char *name
= bfd_get_filename (dbfd
.get ());
12566 std::unique_ptr
<struct dwp_file
> dwp_file
12567 (new struct dwp_file (name
, std::move (dbfd
)));
12569 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12570 dwp_file
->elf_sections
=
12571 OBSTACK_CALLOC (&dwarf2_per_objfile
->per_bfd
->obstack
,
12572 dwp_file
->num_sections
, asection
*);
12574 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12575 dwarf2_locate_common_dwp_sections
,
12578 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12581 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12584 /* The DWP file version is stored in the hash table. Oh well. */
12585 if (dwp_file
->cus
&& dwp_file
->tus
12586 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12588 /* Technically speaking, we should try to limp along, but this is
12589 pretty bizarre. We use pulongest here because that's the established
12590 portability solution (e.g, we cannot use %u for uint32_t). */
12591 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12592 " TU version %s [in DWP file %s]"),
12593 pulongest (dwp_file
->cus
->version
),
12594 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12598 dwp_file
->version
= dwp_file
->cus
->version
;
12599 else if (dwp_file
->tus
)
12600 dwp_file
->version
= dwp_file
->tus
->version
;
12602 dwp_file
->version
= 2;
12604 if (dwp_file
->version
== 2)
12605 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12606 dwarf2_locate_v2_dwp_sections
,
12609 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12610 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12612 if (dwarf_read_debug
)
12614 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12615 fprintf_unfiltered (gdb_stdlog
,
12616 " %s CUs, %s TUs\n",
12617 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12618 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12624 /* Wrapper around open_and_init_dwp_file, only open it once. */
12626 static struct dwp_file
*
12627 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12629 if (! dwarf2_per_objfile
->per_bfd
->dwp_checked
)
12631 dwarf2_per_objfile
->per_bfd
->dwp_file
12632 = open_and_init_dwp_file (dwarf2_per_objfile
);
12633 dwarf2_per_objfile
->per_bfd
->dwp_checked
= 1;
12635 return dwarf2_per_objfile
->per_bfd
->dwp_file
.get ();
12638 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12639 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12640 or in the DWP file for the objfile, referenced by THIS_UNIT.
12641 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12642 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12644 This is called, for example, when wanting to read a variable with a
12645 complex location. Therefore we don't want to do file i/o for every call.
12646 Therefore we don't want to look for a DWO file on every call.
12647 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12648 then we check if we've already seen DWO_NAME, and only THEN do we check
12651 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12652 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12654 static struct dwo_unit
*
12655 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12656 const char *dwo_name
, const char *comp_dir
,
12657 ULONGEST signature
, int is_debug_types
)
12659 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12661 const char *kind
= is_debug_types
? "TU" : "CU";
12662 void **dwo_file_slot
;
12663 struct dwo_file
*dwo_file
;
12664 struct dwp_file
*dwp_file
;
12666 /* First see if there's a DWP file.
12667 If we have a DWP file but didn't find the DWO inside it, don't
12668 look for the original DWO file. It makes gdb behave differently
12669 depending on whether one is debugging in the build tree. */
12671 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12672 if (dwp_file
!= NULL
)
12674 const struct dwp_hash_table
*dwp_htab
=
12675 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12677 if (dwp_htab
!= NULL
)
12679 struct dwo_unit
*dwo_cutu
=
12680 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12681 signature
, is_debug_types
);
12683 if (dwo_cutu
!= NULL
)
12685 if (dwarf_read_debug
)
12687 fprintf_unfiltered (gdb_stdlog
,
12688 "Virtual DWO %s %s found: @%s\n",
12689 kind
, hex_string (signature
),
12690 host_address_to_string (dwo_cutu
));
12698 /* No DWP file, look for the DWO file. */
12700 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12701 dwo_name
, comp_dir
);
12702 if (*dwo_file_slot
== NULL
)
12704 /* Read in the file and build a table of the CUs/TUs it contains. */
12705 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12707 /* NOTE: This will be NULL if unable to open the file. */
12708 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12710 if (dwo_file
!= NULL
)
12712 struct dwo_unit
*dwo_cutu
= NULL
;
12714 if (is_debug_types
&& dwo_file
->tus
)
12716 struct dwo_unit find_dwo_cutu
;
12718 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12719 find_dwo_cutu
.signature
= signature
;
12721 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12724 else if (!is_debug_types
&& dwo_file
->cus
)
12726 struct dwo_unit find_dwo_cutu
;
12728 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12729 find_dwo_cutu
.signature
= signature
;
12730 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12734 if (dwo_cutu
!= NULL
)
12736 if (dwarf_read_debug
)
12738 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12739 kind
, dwo_name
, hex_string (signature
),
12740 host_address_to_string (dwo_cutu
));
12747 /* We didn't find it. This could mean a dwo_id mismatch, or
12748 someone deleted the DWO/DWP file, or the search path isn't set up
12749 correctly to find the file. */
12751 if (dwarf_read_debug
)
12753 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12754 kind
, dwo_name
, hex_string (signature
));
12757 /* This is a warning and not a complaint because it can be caused by
12758 pilot error (e.g., user accidentally deleting the DWO). */
12760 /* Print the name of the DWP file if we looked there, helps the user
12761 better diagnose the problem. */
12762 std::string dwp_text
;
12764 if (dwp_file
!= NULL
)
12765 dwp_text
= string_printf (" [in DWP file %s]",
12766 lbasename (dwp_file
->name
));
12768 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12769 " [in module %s]"),
12770 kind
, dwo_name
, hex_string (signature
),
12772 this_unit
->is_debug_types
? "TU" : "CU",
12773 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12778 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12779 See lookup_dwo_cutu_unit for details. */
12781 static struct dwo_unit
*
12782 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12783 const char *dwo_name
, const char *comp_dir
,
12784 ULONGEST signature
)
12786 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12789 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12790 See lookup_dwo_cutu_unit for details. */
12792 static struct dwo_unit
*
12793 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12794 const char *dwo_name
, const char *comp_dir
)
12796 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12799 /* Traversal function for queue_and_load_all_dwo_tus. */
12802 queue_and_load_dwo_tu (void **slot
, void *info
)
12804 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12805 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12806 ULONGEST signature
= dwo_unit
->signature
;
12807 struct signatured_type
*sig_type
=
12808 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12810 if (sig_type
!= NULL
)
12812 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12814 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12815 a real dependency of PER_CU on SIG_TYPE. That is detected later
12816 while processing PER_CU. */
12817 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12818 load_full_type_unit (sig_cu
);
12819 per_cu
->imported_symtabs_push (sig_cu
);
12825 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12826 The DWO may have the only definition of the type, though it may not be
12827 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12828 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12831 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12833 struct dwo_unit
*dwo_unit
;
12834 struct dwo_file
*dwo_file
;
12836 gdb_assert (!per_cu
->is_debug_types
);
12837 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12838 gdb_assert (per_cu
->cu
!= NULL
);
12840 dwo_unit
= per_cu
->cu
->dwo_unit
;
12841 gdb_assert (dwo_unit
!= NULL
);
12843 dwo_file
= dwo_unit
->dwo_file
;
12844 if (dwo_file
->tus
!= NULL
)
12845 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12849 /* Read in various DIEs. */
12851 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12852 Inherit only the children of the DW_AT_abstract_origin DIE not being
12853 already referenced by DW_AT_abstract_origin from the children of the
12857 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12859 struct die_info
*child_die
;
12860 sect_offset
*offsetp
;
12861 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12862 struct die_info
*origin_die
;
12863 /* Iterator of the ORIGIN_DIE children. */
12864 struct die_info
*origin_child_die
;
12865 struct attribute
*attr
;
12866 struct dwarf2_cu
*origin_cu
;
12867 struct pending
**origin_previous_list_in_scope
;
12869 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12873 /* Note that following die references may follow to a die in a
12877 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12879 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12881 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12882 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12884 if (die
->tag
!= origin_die
->tag
12885 && !(die
->tag
== DW_TAG_inlined_subroutine
12886 && origin_die
->tag
== DW_TAG_subprogram
))
12887 complaint (_("DIE %s and its abstract origin %s have different tags"),
12888 sect_offset_str (die
->sect_off
),
12889 sect_offset_str (origin_die
->sect_off
));
12891 std::vector
<sect_offset
> offsets
;
12893 for (child_die
= die
->child
;
12894 child_die
&& child_die
->tag
;
12895 child_die
= child_die
->sibling
)
12897 struct die_info
*child_origin_die
;
12898 struct dwarf2_cu
*child_origin_cu
;
12900 /* We are trying to process concrete instance entries:
12901 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12902 it's not relevant to our analysis here. i.e. detecting DIEs that are
12903 present in the abstract instance but not referenced in the concrete
12905 if (child_die
->tag
== DW_TAG_call_site
12906 || child_die
->tag
== DW_TAG_GNU_call_site
)
12909 /* For each CHILD_DIE, find the corresponding child of
12910 ORIGIN_DIE. If there is more than one layer of
12911 DW_AT_abstract_origin, follow them all; there shouldn't be,
12912 but GCC versions at least through 4.4 generate this (GCC PR
12914 child_origin_die
= child_die
;
12915 child_origin_cu
= cu
;
12918 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12922 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12926 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12927 counterpart may exist. */
12928 if (child_origin_die
!= child_die
)
12930 if (child_die
->tag
!= child_origin_die
->tag
12931 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12932 && child_origin_die
->tag
== DW_TAG_subprogram
))
12933 complaint (_("Child DIE %s and its abstract origin %s have "
12935 sect_offset_str (child_die
->sect_off
),
12936 sect_offset_str (child_origin_die
->sect_off
));
12937 if (child_origin_die
->parent
!= origin_die
)
12938 complaint (_("Child DIE %s and its abstract origin %s have "
12939 "different parents"),
12940 sect_offset_str (child_die
->sect_off
),
12941 sect_offset_str (child_origin_die
->sect_off
));
12943 offsets
.push_back (child_origin_die
->sect_off
);
12946 std::sort (offsets
.begin (), offsets
.end ());
12947 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12948 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12949 if (offsetp
[-1] == *offsetp
)
12950 complaint (_("Multiple children of DIE %s refer "
12951 "to DIE %s as their abstract origin"),
12952 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12954 offsetp
= offsets
.data ();
12955 origin_child_die
= origin_die
->child
;
12956 while (origin_child_die
&& origin_child_die
->tag
)
12958 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12959 while (offsetp
< offsets_end
12960 && *offsetp
< origin_child_die
->sect_off
)
12962 if (offsetp
>= offsets_end
12963 || *offsetp
> origin_child_die
->sect_off
)
12965 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12966 Check whether we're already processing ORIGIN_CHILD_DIE.
12967 This can happen with mutually referenced abstract_origins.
12969 if (!origin_child_die
->in_process
)
12970 process_die (origin_child_die
, origin_cu
);
12972 origin_child_die
= origin_child_die
->sibling
;
12974 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12976 if (cu
!= origin_cu
)
12977 compute_delayed_physnames (origin_cu
);
12981 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12983 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12984 struct gdbarch
*gdbarch
= objfile
->arch ();
12985 struct context_stack
*newobj
;
12988 struct die_info
*child_die
;
12989 struct attribute
*attr
, *call_line
, *call_file
;
12991 CORE_ADDR baseaddr
;
12992 struct block
*block
;
12993 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12994 std::vector
<struct symbol
*> template_args
;
12995 struct template_symbol
*templ_func
= NULL
;
12999 /* If we do not have call site information, we can't show the
13000 caller of this inlined function. That's too confusing, so
13001 only use the scope for local variables. */
13002 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13003 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13004 if (call_line
== NULL
|| call_file
== NULL
)
13006 read_lexical_block_scope (die
, cu
);
13011 baseaddr
= objfile
->text_section_offset ();
13013 name
= dwarf2_name (die
, cu
);
13015 /* Ignore functions with missing or empty names. These are actually
13016 illegal according to the DWARF standard. */
13019 complaint (_("missing name for subprogram DIE at %s"),
13020 sect_offset_str (die
->sect_off
));
13024 /* Ignore functions with missing or invalid low and high pc attributes. */
13025 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13026 <= PC_BOUNDS_INVALID
)
13028 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13029 if (!attr
|| !DW_UNSND (attr
))
13030 complaint (_("cannot get low and high bounds "
13031 "for subprogram DIE at %s"),
13032 sect_offset_str (die
->sect_off
));
13036 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13037 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13039 /* If we have any template arguments, then we must allocate a
13040 different sort of symbol. */
13041 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13043 if (child_die
->tag
== DW_TAG_template_type_param
13044 || child_die
->tag
== DW_TAG_template_value_param
)
13046 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13047 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13052 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13053 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13054 (struct symbol
*) templ_func
);
13056 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13057 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13060 /* If there is a location expression for DW_AT_frame_base, record
13062 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13063 if (attr
!= nullptr)
13064 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13066 /* If there is a location for the static link, record it. */
13067 newobj
->static_link
= NULL
;
13068 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13069 if (attr
!= nullptr)
13071 newobj
->static_link
13072 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13073 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13074 cu
->per_cu
->addr_type ());
13077 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13079 if (die
->child
!= NULL
)
13081 child_die
= die
->child
;
13082 while (child_die
&& child_die
->tag
)
13084 if (child_die
->tag
== DW_TAG_template_type_param
13085 || child_die
->tag
== DW_TAG_template_value_param
)
13087 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13090 template_args
.push_back (arg
);
13093 process_die (child_die
, cu
);
13094 child_die
= child_die
->sibling
;
13098 inherit_abstract_dies (die
, cu
);
13100 /* If we have a DW_AT_specification, we might need to import using
13101 directives from the context of the specification DIE. See the
13102 comment in determine_prefix. */
13103 if (cu
->language
== language_cplus
13104 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13106 struct dwarf2_cu
*spec_cu
= cu
;
13107 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13111 child_die
= spec_die
->child
;
13112 while (child_die
&& child_die
->tag
)
13114 if (child_die
->tag
== DW_TAG_imported_module
)
13115 process_die (child_die
, spec_cu
);
13116 child_die
= child_die
->sibling
;
13119 /* In some cases, GCC generates specification DIEs that
13120 themselves contain DW_AT_specification attributes. */
13121 spec_die
= die_specification (spec_die
, &spec_cu
);
13125 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13126 /* Make a block for the local symbols within. */
13127 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13128 cstk
.static_link
, lowpc
, highpc
);
13130 /* For C++, set the block's scope. */
13131 if ((cu
->language
== language_cplus
13132 || cu
->language
== language_fortran
13133 || cu
->language
== language_d
13134 || cu
->language
== language_rust
)
13135 && cu
->processing_has_namespace_info
)
13136 block_set_scope (block
, determine_prefix (die
, cu
),
13137 &objfile
->objfile_obstack
);
13139 /* If we have address ranges, record them. */
13140 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13142 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13144 /* Attach template arguments to function. */
13145 if (!template_args
.empty ())
13147 gdb_assert (templ_func
!= NULL
);
13149 templ_func
->n_template_arguments
= template_args
.size ();
13150 templ_func
->template_arguments
13151 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13152 templ_func
->n_template_arguments
);
13153 memcpy (templ_func
->template_arguments
,
13154 template_args
.data (),
13155 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13157 /* Make sure that the symtab is set on the new symbols. Even
13158 though they don't appear in this symtab directly, other parts
13159 of gdb assume that symbols do, and this is reasonably
13161 for (symbol
*sym
: template_args
)
13162 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13165 /* In C++, we can have functions nested inside functions (e.g., when
13166 a function declares a class that has methods). This means that
13167 when we finish processing a function scope, we may need to go
13168 back to building a containing block's symbol lists. */
13169 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13170 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13172 /* If we've finished processing a top-level function, subsequent
13173 symbols go in the file symbol list. */
13174 if (cu
->get_builder ()->outermost_context_p ())
13175 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13178 /* Process all the DIES contained within a lexical block scope. Start
13179 a new scope, process the dies, and then close the scope. */
13182 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13184 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13185 struct gdbarch
*gdbarch
= objfile
->arch ();
13186 CORE_ADDR lowpc
, highpc
;
13187 struct die_info
*child_die
;
13188 CORE_ADDR baseaddr
;
13190 baseaddr
= objfile
->text_section_offset ();
13192 /* Ignore blocks with missing or invalid low and high pc attributes. */
13193 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13194 as multiple lexical blocks? Handling children in a sane way would
13195 be nasty. Might be easier to properly extend generic blocks to
13196 describe ranges. */
13197 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13199 case PC_BOUNDS_NOT_PRESENT
:
13200 /* DW_TAG_lexical_block has no attributes, process its children as if
13201 there was no wrapping by that DW_TAG_lexical_block.
13202 GCC does no longer produces such DWARF since GCC r224161. */
13203 for (child_die
= die
->child
;
13204 child_die
!= NULL
&& child_die
->tag
;
13205 child_die
= child_die
->sibling
)
13207 /* We might already be processing this DIE. This can happen
13208 in an unusual circumstance -- where a subroutine A
13209 appears lexically in another subroutine B, but A actually
13210 inlines B. The recursion is broken here, rather than in
13211 inherit_abstract_dies, because it seems better to simply
13212 drop concrete children here. */
13213 if (!child_die
->in_process
)
13214 process_die (child_die
, cu
);
13217 case PC_BOUNDS_INVALID
:
13220 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13221 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13223 cu
->get_builder ()->push_context (0, lowpc
);
13224 if (die
->child
!= NULL
)
13226 child_die
= die
->child
;
13227 while (child_die
&& child_die
->tag
)
13229 process_die (child_die
, cu
);
13230 child_die
= child_die
->sibling
;
13233 inherit_abstract_dies (die
, cu
);
13234 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13236 if (*cu
->get_builder ()->get_local_symbols () != NULL
13237 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13239 struct block
*block
13240 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13241 cstk
.start_addr
, highpc
);
13243 /* Note that recording ranges after traversing children, as we
13244 do here, means that recording a parent's ranges entails
13245 walking across all its children's ranges as they appear in
13246 the address map, which is quadratic behavior.
13248 It would be nicer to record the parent's ranges before
13249 traversing its children, simply overriding whatever you find
13250 there. But since we don't even decide whether to create a
13251 block until after we've traversed its children, that's hard
13253 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13255 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13256 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13259 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13262 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13264 dwarf2_per_objfile
*per_objfile
= cu
->per_cu
->dwarf2_per_objfile
;
13265 struct objfile
*objfile
= per_objfile
->objfile
;
13266 struct gdbarch
*gdbarch
= objfile
->arch ();
13267 CORE_ADDR pc
, baseaddr
;
13268 struct attribute
*attr
;
13269 struct call_site
*call_site
, call_site_local
;
13272 struct die_info
*child_die
;
13274 baseaddr
= objfile
->text_section_offset ();
13276 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13279 /* This was a pre-DWARF-5 GNU extension alias
13280 for DW_AT_call_return_pc. */
13281 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13285 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13286 "DIE %s [in module %s]"),
13287 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13290 pc
= attr
->value_as_address () + baseaddr
;
13291 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13293 if (cu
->call_site_htab
== NULL
)
13294 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13295 NULL
, &objfile
->objfile_obstack
,
13296 hashtab_obstack_allocate
, NULL
);
13297 call_site_local
.pc
= pc
;
13298 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13301 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13302 "DIE %s [in module %s]"),
13303 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13304 objfile_name (objfile
));
13308 /* Count parameters at the caller. */
13311 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13312 child_die
= child_die
->sibling
)
13314 if (child_die
->tag
!= DW_TAG_call_site_parameter
13315 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13317 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13318 "DW_TAG_call_site child DIE %s [in module %s]"),
13319 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13320 objfile_name (objfile
));
13328 = ((struct call_site
*)
13329 obstack_alloc (&objfile
->objfile_obstack
,
13330 sizeof (*call_site
)
13331 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13333 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13334 call_site
->pc
= pc
;
13336 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13337 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13339 struct die_info
*func_die
;
13341 /* Skip also over DW_TAG_inlined_subroutine. */
13342 for (func_die
= die
->parent
;
13343 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13344 && func_die
->tag
!= DW_TAG_subroutine_type
;
13345 func_die
= func_die
->parent
);
13347 /* DW_AT_call_all_calls is a superset
13348 of DW_AT_call_all_tail_calls. */
13350 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13351 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13352 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13353 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13355 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13356 not complete. But keep CALL_SITE for look ups via call_site_htab,
13357 both the initial caller containing the real return address PC and
13358 the final callee containing the current PC of a chain of tail
13359 calls do not need to have the tail call list complete. But any
13360 function candidate for a virtual tail call frame searched via
13361 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13362 determined unambiguously. */
13366 struct type
*func_type
= NULL
;
13369 func_type
= get_die_type (func_die
, cu
);
13370 if (func_type
!= NULL
)
13372 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13374 /* Enlist this call site to the function. */
13375 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13376 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13379 complaint (_("Cannot find function owning DW_TAG_call_site "
13380 "DIE %s [in module %s]"),
13381 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13385 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13387 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13389 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13392 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13393 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13395 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13396 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13397 /* Keep NULL DWARF_BLOCK. */;
13398 else if (attr
->form_is_block ())
13400 struct dwarf2_locexpr_baton
*dlbaton
;
13402 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13403 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13404 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13405 dlbaton
->per_objfile
= per_objfile
;
13406 dlbaton
->per_cu
= cu
->per_cu
;
13408 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13410 else if (attr
->form_is_ref ())
13412 struct dwarf2_cu
*target_cu
= cu
;
13413 struct die_info
*target_die
;
13415 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13416 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13417 if (die_is_declaration (target_die
, target_cu
))
13419 const char *target_physname
;
13421 /* Prefer the mangled name; otherwise compute the demangled one. */
13422 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13423 if (target_physname
== NULL
)
13424 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13425 if (target_physname
== NULL
)
13426 complaint (_("DW_AT_call_target target DIE has invalid "
13427 "physname, for referencing DIE %s [in module %s]"),
13428 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13430 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13436 /* DW_AT_entry_pc should be preferred. */
13437 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13438 <= PC_BOUNDS_INVALID
)
13439 complaint (_("DW_AT_call_target target DIE has invalid "
13440 "low pc, for referencing DIE %s [in module %s]"),
13441 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13444 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13445 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13450 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13451 "block nor reference, for DIE %s [in module %s]"),
13452 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13454 call_site
->per_cu
= cu
->per_cu
;
13456 for (child_die
= die
->child
;
13457 child_die
&& child_die
->tag
;
13458 child_die
= child_die
->sibling
)
13460 struct call_site_parameter
*parameter
;
13461 struct attribute
*loc
, *origin
;
13463 if (child_die
->tag
!= DW_TAG_call_site_parameter
13464 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13466 /* Already printed the complaint above. */
13470 gdb_assert (call_site
->parameter_count
< nparams
);
13471 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13473 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13474 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13475 register is contained in DW_AT_call_value. */
13477 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13478 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13479 if (origin
== NULL
)
13481 /* This was a pre-DWARF-5 GNU extension alias
13482 for DW_AT_call_parameter. */
13483 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13485 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13487 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13489 sect_offset sect_off
= origin
->get_ref_die_offset ();
13490 if (!cu
->header
.offset_in_cu_p (sect_off
))
13492 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13493 binding can be done only inside one CU. Such referenced DIE
13494 therefore cannot be even moved to DW_TAG_partial_unit. */
13495 complaint (_("DW_AT_call_parameter offset is not in CU for "
13496 "DW_TAG_call_site child DIE %s [in module %s]"),
13497 sect_offset_str (child_die
->sect_off
),
13498 objfile_name (objfile
));
13501 parameter
->u
.param_cu_off
13502 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13504 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13506 complaint (_("No DW_FORM_block* DW_AT_location for "
13507 "DW_TAG_call_site child DIE %s [in module %s]"),
13508 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13513 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13514 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13515 if (parameter
->u
.dwarf_reg
!= -1)
13516 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13517 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13518 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13519 ¶meter
->u
.fb_offset
))
13520 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13523 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13524 "for DW_FORM_block* DW_AT_location is supported for "
13525 "DW_TAG_call_site child DIE %s "
13527 sect_offset_str (child_die
->sect_off
),
13528 objfile_name (objfile
));
13533 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13535 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13536 if (attr
== NULL
|| !attr
->form_is_block ())
13538 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13539 "DW_TAG_call_site child DIE %s [in module %s]"),
13540 sect_offset_str (child_die
->sect_off
),
13541 objfile_name (objfile
));
13544 parameter
->value
= DW_BLOCK (attr
)->data
;
13545 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13547 /* Parameters are not pre-cleared by memset above. */
13548 parameter
->data_value
= NULL
;
13549 parameter
->data_value_size
= 0;
13550 call_site
->parameter_count
++;
13552 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13554 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13555 if (attr
!= nullptr)
13557 if (!attr
->form_is_block ())
13558 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13559 "DW_TAG_call_site child DIE %s [in module %s]"),
13560 sect_offset_str (child_die
->sect_off
),
13561 objfile_name (objfile
));
13564 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13565 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13571 /* Helper function for read_variable. If DIE represents a virtual
13572 table, then return the type of the concrete object that is
13573 associated with the virtual table. Otherwise, return NULL. */
13575 static struct type
*
13576 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13578 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13582 /* Find the type DIE. */
13583 struct die_info
*type_die
= NULL
;
13584 struct dwarf2_cu
*type_cu
= cu
;
13586 if (attr
->form_is_ref ())
13587 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13588 if (type_die
== NULL
)
13591 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13593 return die_containing_type (type_die
, type_cu
);
13596 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13599 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13601 struct rust_vtable_symbol
*storage
= NULL
;
13603 if (cu
->language
== language_rust
)
13605 struct type
*containing_type
= rust_containing_type (die
, cu
);
13607 if (containing_type
!= NULL
)
13609 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13611 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13612 storage
->concrete_type
= containing_type
;
13613 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13617 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13618 struct attribute
*abstract_origin
13619 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13620 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13621 if (res
== NULL
&& loc
&& abstract_origin
)
13623 /* We have a variable without a name, but with a location and an abstract
13624 origin. This may be a concrete instance of an abstract variable
13625 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13627 struct dwarf2_cu
*origin_cu
= cu
;
13628 struct die_info
*origin_die
13629 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13630 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13631 dpo
->per_bfd
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13635 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13636 reading .debug_rnglists.
13637 Callback's type should be:
13638 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13639 Return true if the attributes are present and valid, otherwise,
13642 template <typename Callback
>
13644 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13645 Callback
&&callback
)
13647 struct dwarf2_per_objfile
*dwarf2_per_objfile
13648 = cu
->per_cu
->dwarf2_per_objfile
;
13649 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13650 bfd
*obfd
= objfile
->obfd
;
13651 /* Base address selection entry. */
13652 gdb::optional
<CORE_ADDR
> base
;
13653 const gdb_byte
*buffer
;
13654 CORE_ADDR baseaddr
;
13655 bool overflow
= false;
13657 base
= cu
->base_address
;
13659 dwarf2_per_objfile
->per_bfd
->rnglists
.read (objfile
);
13660 if (offset
>= dwarf2_per_objfile
->per_bfd
->rnglists
.size
)
13662 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13666 buffer
= dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
+ offset
;
13668 baseaddr
= objfile
->text_section_offset ();
13672 /* Initialize it due to a false compiler warning. */
13673 CORE_ADDR range_beginning
= 0, range_end
= 0;
13674 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->per_bfd
->rnglists
.buffer
13675 + dwarf2_per_objfile
->per_bfd
->rnglists
.size
);
13676 unsigned int bytes_read
;
13678 if (buffer
== buf_end
)
13683 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13686 case DW_RLE_end_of_list
:
13688 case DW_RLE_base_address
:
13689 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13694 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13695 buffer
+= bytes_read
;
13697 case DW_RLE_start_length
:
13698 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13703 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13705 buffer
+= bytes_read
;
13706 range_end
= (range_beginning
13707 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13708 buffer
+= bytes_read
;
13709 if (buffer
> buf_end
)
13715 case DW_RLE_offset_pair
:
13716 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13717 buffer
+= bytes_read
;
13718 if (buffer
> buf_end
)
13723 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13724 buffer
+= bytes_read
;
13725 if (buffer
> buf_end
)
13731 case DW_RLE_start_end
:
13732 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13737 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13739 buffer
+= bytes_read
;
13740 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13741 buffer
+= bytes_read
;
13744 complaint (_("Invalid .debug_rnglists data (no base address)"));
13747 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13749 if (rlet
== DW_RLE_base_address
)
13752 if (!base
.has_value ())
13754 /* We have no valid base address for the ranges
13756 complaint (_("Invalid .debug_rnglists data (no base address)"));
13760 if (range_beginning
> range_end
)
13762 /* Inverted range entries are invalid. */
13763 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13767 /* Empty range entries have no effect. */
13768 if (range_beginning
== range_end
)
13771 range_beginning
+= *base
;
13772 range_end
+= *base
;
13774 /* A not-uncommon case of bad debug info.
13775 Don't pollute the addrmap with bad data. */
13776 if (range_beginning
+ baseaddr
== 0
13777 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
13779 complaint (_(".debug_rnglists entry has start address of zero"
13780 " [in module %s]"), objfile_name (objfile
));
13784 callback (range_beginning
, range_end
);
13789 complaint (_("Offset %d is not terminated "
13790 "for DW_AT_ranges attribute"),
13798 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13799 Callback's type should be:
13800 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13801 Return 1 if the attributes are present and valid, otherwise, return 0. */
13803 template <typename Callback
>
13805 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13806 Callback
&&callback
)
13808 struct dwarf2_per_objfile
*dwarf2_per_objfile
13809 = cu
->per_cu
->dwarf2_per_objfile
;
13810 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13811 struct comp_unit_head
*cu_header
= &cu
->header
;
13812 bfd
*obfd
= objfile
->obfd
;
13813 unsigned int addr_size
= cu_header
->addr_size
;
13814 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13815 /* Base address selection entry. */
13816 gdb::optional
<CORE_ADDR
> base
;
13817 unsigned int dummy
;
13818 const gdb_byte
*buffer
;
13819 CORE_ADDR baseaddr
;
13821 if (cu_header
->version
>= 5)
13822 return dwarf2_rnglists_process (offset
, cu
, callback
);
13824 base
= cu
->base_address
;
13826 dwarf2_per_objfile
->per_bfd
->ranges
.read (objfile
);
13827 if (offset
>= dwarf2_per_objfile
->per_bfd
->ranges
.size
)
13829 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13833 buffer
= dwarf2_per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13835 baseaddr
= objfile
->text_section_offset ();
13839 CORE_ADDR range_beginning
, range_end
;
13841 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13842 buffer
+= addr_size
;
13843 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13844 buffer
+= addr_size
;
13845 offset
+= 2 * addr_size
;
13847 /* An end of list marker is a pair of zero addresses. */
13848 if (range_beginning
== 0 && range_end
== 0)
13849 /* Found the end of list entry. */
13852 /* Each base address selection entry is a pair of 2 values.
13853 The first is the largest possible address, the second is
13854 the base address. Check for a base address here. */
13855 if ((range_beginning
& mask
) == mask
)
13857 /* If we found the largest possible address, then we already
13858 have the base address in range_end. */
13863 if (!base
.has_value ())
13865 /* We have no valid base address for the ranges
13867 complaint (_("Invalid .debug_ranges data (no base address)"));
13871 if (range_beginning
> range_end
)
13873 /* Inverted range entries are invalid. */
13874 complaint (_("Invalid .debug_ranges data (inverted range)"));
13878 /* Empty range entries have no effect. */
13879 if (range_beginning
== range_end
)
13882 range_beginning
+= *base
;
13883 range_end
+= *base
;
13885 /* A not-uncommon case of bad debug info.
13886 Don't pollute the addrmap with bad data. */
13887 if (range_beginning
+ baseaddr
== 0
13888 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
13890 complaint (_(".debug_ranges entry has start address of zero"
13891 " [in module %s]"), objfile_name (objfile
));
13895 callback (range_beginning
, range_end
);
13901 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13902 Return 1 if the attributes are present and valid, otherwise, return 0.
13903 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13906 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13907 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13908 dwarf2_psymtab
*ranges_pst
)
13910 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13911 struct gdbarch
*gdbarch
= objfile
->arch ();
13912 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13915 CORE_ADDR high
= 0;
13918 retval
= dwarf2_ranges_process (offset
, cu
,
13919 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13921 if (ranges_pst
!= NULL
)
13926 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13927 range_beginning
+ baseaddr
)
13929 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13930 range_end
+ baseaddr
)
13932 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13933 lowpc
, highpc
- 1, ranges_pst
);
13936 /* FIXME: This is recording everything as a low-high
13937 segment of consecutive addresses. We should have a
13938 data structure for discontiguous block ranges
13942 low
= range_beginning
;
13948 if (range_beginning
< low
)
13949 low
= range_beginning
;
13950 if (range_end
> high
)
13958 /* If the first entry is an end-of-list marker, the range
13959 describes an empty scope, i.e. no instructions. */
13965 *high_return
= high
;
13969 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13970 definition for the return value. *LOWPC and *HIGHPC are set iff
13971 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13973 static enum pc_bounds_kind
13974 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13975 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13976 dwarf2_psymtab
*pst
)
13978 struct dwarf2_per_objfile
*dwarf2_per_objfile
13979 = cu
->per_cu
->dwarf2_per_objfile
;
13980 struct attribute
*attr
;
13981 struct attribute
*attr_high
;
13983 CORE_ADDR high
= 0;
13984 enum pc_bounds_kind ret
;
13986 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13989 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13990 if (attr
!= nullptr)
13992 low
= attr
->value_as_address ();
13993 high
= attr_high
->value_as_address ();
13994 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13998 /* Found high w/o low attribute. */
13999 return PC_BOUNDS_INVALID
;
14001 /* Found consecutive range of addresses. */
14002 ret
= PC_BOUNDS_HIGH_LOW
;
14006 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14009 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14010 We take advantage of the fact that DW_AT_ranges does not appear
14011 in DW_TAG_compile_unit of DWO files. */
14012 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14013 unsigned int ranges_offset
= (DW_UNSND (attr
)
14014 + (need_ranges_base
14018 /* Value of the DW_AT_ranges attribute is the offset in the
14019 .debug_ranges section. */
14020 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14021 return PC_BOUNDS_INVALID
;
14022 /* Found discontinuous range of addresses. */
14023 ret
= PC_BOUNDS_RANGES
;
14026 return PC_BOUNDS_NOT_PRESENT
;
14029 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14031 return PC_BOUNDS_INVALID
;
14033 /* When using the GNU linker, .gnu.linkonce. sections are used to
14034 eliminate duplicate copies of functions and vtables and such.
14035 The linker will arbitrarily choose one and discard the others.
14036 The AT_*_pc values for such functions refer to local labels in
14037 these sections. If the section from that file was discarded, the
14038 labels are not in the output, so the relocs get a value of 0.
14039 If this is a discarded function, mark the pc bounds as invalid,
14040 so that GDB will ignore it. */
14041 if (low
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
14042 return PC_BOUNDS_INVALID
;
14050 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14051 its low and high PC addresses. Do nothing if these addresses could not
14052 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14053 and HIGHPC to the high address if greater than HIGHPC. */
14056 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14057 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14058 struct dwarf2_cu
*cu
)
14060 CORE_ADDR low
, high
;
14061 struct die_info
*child
= die
->child
;
14063 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14065 *lowpc
= std::min (*lowpc
, low
);
14066 *highpc
= std::max (*highpc
, high
);
14069 /* If the language does not allow nested subprograms (either inside
14070 subprograms or lexical blocks), we're done. */
14071 if (cu
->language
!= language_ada
)
14074 /* Check all the children of the given DIE. If it contains nested
14075 subprograms, then check their pc bounds. Likewise, we need to
14076 check lexical blocks as well, as they may also contain subprogram
14078 while (child
&& child
->tag
)
14080 if (child
->tag
== DW_TAG_subprogram
14081 || child
->tag
== DW_TAG_lexical_block
)
14082 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14083 child
= child
->sibling
;
14087 /* Get the low and high pc's represented by the scope DIE, and store
14088 them in *LOWPC and *HIGHPC. If the correct values can't be
14089 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14092 get_scope_pc_bounds (struct die_info
*die
,
14093 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14094 struct dwarf2_cu
*cu
)
14096 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14097 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14098 CORE_ADDR current_low
, current_high
;
14100 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14101 >= PC_BOUNDS_RANGES
)
14103 best_low
= current_low
;
14104 best_high
= current_high
;
14108 struct die_info
*child
= die
->child
;
14110 while (child
&& child
->tag
)
14112 switch (child
->tag
) {
14113 case DW_TAG_subprogram
:
14114 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14116 case DW_TAG_namespace
:
14117 case DW_TAG_module
:
14118 /* FIXME: carlton/2004-01-16: Should we do this for
14119 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14120 that current GCC's always emit the DIEs corresponding
14121 to definitions of methods of classes as children of a
14122 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14123 the DIEs giving the declarations, which could be
14124 anywhere). But I don't see any reason why the
14125 standards says that they have to be there. */
14126 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14128 if (current_low
!= ((CORE_ADDR
) -1))
14130 best_low
= std::min (best_low
, current_low
);
14131 best_high
= std::max (best_high
, current_high
);
14139 child
= child
->sibling
;
14144 *highpc
= best_high
;
14147 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14151 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14152 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14154 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14155 struct gdbarch
*gdbarch
= objfile
->arch ();
14156 struct attribute
*attr
;
14157 struct attribute
*attr_high
;
14159 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14162 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14163 if (attr
!= nullptr)
14165 CORE_ADDR low
= attr
->value_as_address ();
14166 CORE_ADDR high
= attr_high
->value_as_address ();
14168 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14171 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14172 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14173 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14177 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14178 if (attr
!= nullptr)
14180 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14181 We take advantage of the fact that DW_AT_ranges does not appear
14182 in DW_TAG_compile_unit of DWO files. */
14183 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14185 /* The value of the DW_AT_ranges attribute is the offset of the
14186 address range list in the .debug_ranges section. */
14187 unsigned long offset
= (DW_UNSND (attr
)
14188 + (need_ranges_base
? cu
->ranges_base
: 0));
14190 std::vector
<blockrange
> blockvec
;
14191 dwarf2_ranges_process (offset
, cu
,
14192 [&] (CORE_ADDR start
, CORE_ADDR end
)
14196 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14197 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14198 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14199 blockvec
.emplace_back (start
, end
);
14202 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14206 /* Check whether the producer field indicates either of GCC < 4.6, or the
14207 Intel C/C++ compiler, and cache the result in CU. */
14210 check_producer (struct dwarf2_cu
*cu
)
14214 if (cu
->producer
== NULL
)
14216 /* For unknown compilers expect their behavior is DWARF version
14219 GCC started to support .debug_types sections by -gdwarf-4 since
14220 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14221 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14222 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14223 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14225 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14227 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14228 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14230 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14232 cu
->producer_is_icc
= true;
14233 cu
->producer_is_icc_lt_14
= major
< 14;
14235 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14236 cu
->producer_is_codewarrior
= true;
14239 /* For other non-GCC compilers, expect their behavior is DWARF version
14243 cu
->checked_producer
= true;
14246 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14247 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14248 during 4.6.0 experimental. */
14251 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14253 if (!cu
->checked_producer
)
14254 check_producer (cu
);
14256 return cu
->producer_is_gxx_lt_4_6
;
14260 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14261 with incorrect is_stmt attributes. */
14264 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14266 if (!cu
->checked_producer
)
14267 check_producer (cu
);
14269 return cu
->producer_is_codewarrior
;
14272 /* Return the default accessibility type if it is not overridden by
14273 DW_AT_accessibility. */
14275 static enum dwarf_access_attribute
14276 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14278 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14280 /* The default DWARF 2 accessibility for members is public, the default
14281 accessibility for inheritance is private. */
14283 if (die
->tag
!= DW_TAG_inheritance
)
14284 return DW_ACCESS_public
;
14286 return DW_ACCESS_private
;
14290 /* DWARF 3+ defines the default accessibility a different way. The same
14291 rules apply now for DW_TAG_inheritance as for the members and it only
14292 depends on the container kind. */
14294 if (die
->parent
->tag
== DW_TAG_class_type
)
14295 return DW_ACCESS_private
;
14297 return DW_ACCESS_public
;
14301 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14302 offset. If the attribute was not found return 0, otherwise return
14303 1. If it was found but could not properly be handled, set *OFFSET
14307 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14310 struct attribute
*attr
;
14312 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14317 /* Note that we do not check for a section offset first here.
14318 This is because DW_AT_data_member_location is new in DWARF 4,
14319 so if we see it, we can assume that a constant form is really
14320 a constant and not a section offset. */
14321 if (attr
->form_is_constant ())
14322 *offset
= attr
->constant_value (0);
14323 else if (attr
->form_is_section_offset ())
14324 dwarf2_complex_location_expr_complaint ();
14325 else if (attr
->form_is_block ())
14326 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14328 dwarf2_complex_location_expr_complaint ();
14336 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14339 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14340 struct field
*field
)
14342 struct attribute
*attr
;
14344 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14347 if (attr
->form_is_constant ())
14349 LONGEST offset
= attr
->constant_value (0);
14350 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14352 else if (attr
->form_is_section_offset ())
14353 dwarf2_complex_location_expr_complaint ();
14354 else if (attr
->form_is_block ())
14357 CORE_ADDR offset
= decode_locdesc (DW_BLOCK (attr
), cu
, &handled
);
14359 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14362 struct objfile
*objfile
14363 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14364 struct dwarf2_locexpr_baton
*dlbaton
14365 = XOBNEW (&objfile
->objfile_obstack
,
14366 struct dwarf2_locexpr_baton
);
14367 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14368 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14369 /* When using this baton, we want to compute the address
14370 of the field, not the value. This is why
14371 is_reference is set to false here. */
14372 dlbaton
->is_reference
= false;
14373 dlbaton
->per_objfile
= cu
->per_cu
->dwarf2_per_objfile
;
14374 dlbaton
->per_cu
= cu
->per_cu
;
14376 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14380 dwarf2_complex_location_expr_complaint ();
14384 /* Add an aggregate field to the field list. */
14387 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14388 struct dwarf2_cu
*cu
)
14390 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14391 struct gdbarch
*gdbarch
= objfile
->arch ();
14392 struct nextfield
*new_field
;
14393 struct attribute
*attr
;
14395 const char *fieldname
= "";
14397 if (die
->tag
== DW_TAG_inheritance
)
14399 fip
->baseclasses
.emplace_back ();
14400 new_field
= &fip
->baseclasses
.back ();
14404 fip
->fields
.emplace_back ();
14405 new_field
= &fip
->fields
.back ();
14408 new_field
->offset
= die
->sect_off
;
14410 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14411 if (attr
!= nullptr)
14412 new_field
->accessibility
= DW_UNSND (attr
);
14414 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14415 if (new_field
->accessibility
!= DW_ACCESS_public
)
14416 fip
->non_public_fields
= 1;
14418 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14419 if (attr
!= nullptr)
14420 new_field
->virtuality
= DW_UNSND (attr
);
14422 new_field
->virtuality
= DW_VIRTUALITY_none
;
14424 fp
= &new_field
->field
;
14426 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14428 /* Data member other than a C++ static data member. */
14430 /* Get type of field. */
14431 fp
->type
= die_type (die
, cu
);
14433 SET_FIELD_BITPOS (*fp
, 0);
14435 /* Get bit size of field (zero if none). */
14436 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14437 if (attr
!= nullptr)
14439 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14443 FIELD_BITSIZE (*fp
) = 0;
14446 /* Get bit offset of field. */
14447 handle_data_member_location (die
, cu
, fp
);
14448 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14449 if (attr
!= nullptr)
14451 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14453 /* For big endian bits, the DW_AT_bit_offset gives the
14454 additional bit offset from the MSB of the containing
14455 anonymous object to the MSB of the field. We don't
14456 have to do anything special since we don't need to
14457 know the size of the anonymous object. */
14458 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14462 /* For little endian bits, compute the bit offset to the
14463 MSB of the anonymous object, subtract off the number of
14464 bits from the MSB of the field to the MSB of the
14465 object, and then subtract off the number of bits of
14466 the field itself. The result is the bit offset of
14467 the LSB of the field. */
14468 int anonymous_size
;
14469 int bit_offset
= DW_UNSND (attr
);
14471 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14472 if (attr
!= nullptr)
14474 /* The size of the anonymous object containing
14475 the bit field is explicit, so use the
14476 indicated size (in bytes). */
14477 anonymous_size
= DW_UNSND (attr
);
14481 /* The size of the anonymous object containing
14482 the bit field must be inferred from the type
14483 attribute of the data member containing the
14485 anonymous_size
= TYPE_LENGTH (fp
->type
);
14487 SET_FIELD_BITPOS (*fp
,
14488 (FIELD_BITPOS (*fp
)
14489 + anonymous_size
* bits_per_byte
14490 - bit_offset
- FIELD_BITSIZE (*fp
)));
14493 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14495 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14496 + attr
->constant_value (0)));
14498 /* Get name of field. */
14499 fieldname
= dwarf2_name (die
, cu
);
14500 if (fieldname
== NULL
)
14503 /* The name is already allocated along with this objfile, so we don't
14504 need to duplicate it for the type. */
14505 fp
->name
= fieldname
;
14507 /* Change accessibility for artificial fields (e.g. virtual table
14508 pointer or virtual base class pointer) to private. */
14509 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14511 FIELD_ARTIFICIAL (*fp
) = 1;
14512 new_field
->accessibility
= DW_ACCESS_private
;
14513 fip
->non_public_fields
= 1;
14516 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14518 /* C++ static member. */
14520 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14521 is a declaration, but all versions of G++ as of this writing
14522 (so through at least 3.2.1) incorrectly generate
14523 DW_TAG_variable tags. */
14525 const char *physname
;
14527 /* Get name of field. */
14528 fieldname
= dwarf2_name (die
, cu
);
14529 if (fieldname
== NULL
)
14532 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14534 /* Only create a symbol if this is an external value.
14535 new_symbol checks this and puts the value in the global symbol
14536 table, which we want. If it is not external, new_symbol
14537 will try to put the value in cu->list_in_scope which is wrong. */
14538 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14540 /* A static const member, not much different than an enum as far as
14541 we're concerned, except that we can support more types. */
14542 new_symbol (die
, NULL
, cu
);
14545 /* Get physical name. */
14546 physname
= dwarf2_physname (fieldname
, die
, cu
);
14548 /* The name is already allocated along with this objfile, so we don't
14549 need to duplicate it for the type. */
14550 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14551 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14552 FIELD_NAME (*fp
) = fieldname
;
14554 else if (die
->tag
== DW_TAG_inheritance
)
14556 /* C++ base class field. */
14557 handle_data_member_location (die
, cu
, fp
);
14558 FIELD_BITSIZE (*fp
) = 0;
14559 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14560 FIELD_NAME (*fp
) = fp
->type
->name ();
14563 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14566 /* Can the type given by DIE define another type? */
14569 type_can_define_types (const struct die_info
*die
)
14573 case DW_TAG_typedef
:
14574 case DW_TAG_class_type
:
14575 case DW_TAG_structure_type
:
14576 case DW_TAG_union_type
:
14577 case DW_TAG_enumeration_type
:
14585 /* Add a type definition defined in the scope of the FIP's class. */
14588 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14589 struct dwarf2_cu
*cu
)
14591 struct decl_field fp
;
14592 memset (&fp
, 0, sizeof (fp
));
14594 gdb_assert (type_can_define_types (die
));
14596 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14597 fp
.name
= dwarf2_name (die
, cu
);
14598 fp
.type
= read_type_die (die
, cu
);
14600 /* Save accessibility. */
14601 enum dwarf_access_attribute accessibility
;
14602 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14604 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14606 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14607 switch (accessibility
)
14609 case DW_ACCESS_public
:
14610 /* The assumed value if neither private nor protected. */
14612 case DW_ACCESS_private
:
14615 case DW_ACCESS_protected
:
14616 fp
.is_protected
= 1;
14619 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14622 if (die
->tag
== DW_TAG_typedef
)
14623 fip
->typedef_field_list
.push_back (fp
);
14625 fip
->nested_types_list
.push_back (fp
);
14628 /* A convenience typedef that's used when finding the discriminant
14629 field for a variant part. */
14630 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14633 /* Compute the discriminant range for a given variant. OBSTACK is
14634 where the results will be stored. VARIANT is the variant to
14635 process. IS_UNSIGNED indicates whether the discriminant is signed
14638 static const gdb::array_view
<discriminant_range
>
14639 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14642 std::vector
<discriminant_range
> ranges
;
14644 if (variant
.default_branch
)
14647 if (variant
.discr_list_data
== nullptr)
14649 discriminant_range r
14650 = {variant
.discriminant_value
, variant
.discriminant_value
};
14651 ranges
.push_back (r
);
14655 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14656 variant
.discr_list_data
->size
);
14657 while (!data
.empty ())
14659 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14661 complaint (_("invalid discriminant marker: %d"), data
[0]);
14664 bool is_range
= data
[0] == DW_DSC_range
;
14665 data
= data
.slice (1);
14667 ULONGEST low
, high
;
14668 unsigned int bytes_read
;
14672 complaint (_("DW_AT_discr_list missing low value"));
14676 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14678 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14680 data
= data
.slice (bytes_read
);
14686 complaint (_("DW_AT_discr_list missing high value"));
14690 high
= read_unsigned_leb128 (nullptr, data
.data (),
14693 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14695 data
= data
.slice (bytes_read
);
14700 ranges
.push_back ({ low
, high
});
14704 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14706 std::copy (ranges
.begin (), ranges
.end (), result
);
14707 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14710 static const gdb::array_view
<variant_part
> create_variant_parts
14711 (struct obstack
*obstack
,
14712 const offset_map_type
&offset_map
,
14713 struct field_info
*fi
,
14714 const std::vector
<variant_part_builder
> &variant_parts
);
14716 /* Fill in a "struct variant" for a given variant field. RESULT is
14717 the variant to fill in. OBSTACK is where any needed allocations
14718 will be done. OFFSET_MAP holds the mapping from section offsets to
14719 fields for the type. FI describes the fields of the type we're
14720 processing. FIELD is the variant field we're converting. */
14723 create_one_variant (variant
&result
, struct obstack
*obstack
,
14724 const offset_map_type
&offset_map
,
14725 struct field_info
*fi
, const variant_field
&field
)
14727 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14728 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14729 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14730 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14731 field
.variant_parts
);
14734 /* Fill in a "struct variant_part" for a given variant part. RESULT
14735 is the variant part to fill in. OBSTACK is where any needed
14736 allocations will be done. OFFSET_MAP holds the mapping from
14737 section offsets to fields for the type. FI describes the fields of
14738 the type we're processing. BUILDER is the variant part to be
14742 create_one_variant_part (variant_part
&result
,
14743 struct obstack
*obstack
,
14744 const offset_map_type
&offset_map
,
14745 struct field_info
*fi
,
14746 const variant_part_builder
&builder
)
14748 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14749 if (iter
== offset_map
.end ())
14751 result
.discriminant_index
= -1;
14752 /* Doesn't matter. */
14753 result
.is_unsigned
= false;
14757 result
.discriminant_index
= iter
->second
;
14759 = TYPE_UNSIGNED (FIELD_TYPE
14760 (fi
->fields
[result
.discriminant_index
].field
));
14763 size_t n
= builder
.variants
.size ();
14764 variant
*output
= new (obstack
) variant
[n
];
14765 for (size_t i
= 0; i
< n
; ++i
)
14766 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14767 builder
.variants
[i
]);
14769 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14772 /* Create a vector of variant parts that can be attached to a type.
14773 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14774 holds the mapping from section offsets to fields for the type. FI
14775 describes the fields of the type we're processing. VARIANT_PARTS
14776 is the vector to convert. */
14778 static const gdb::array_view
<variant_part
>
14779 create_variant_parts (struct obstack
*obstack
,
14780 const offset_map_type
&offset_map
,
14781 struct field_info
*fi
,
14782 const std::vector
<variant_part_builder
> &variant_parts
)
14784 if (variant_parts
.empty ())
14787 size_t n
= variant_parts
.size ();
14788 variant_part
*result
= new (obstack
) variant_part
[n
];
14789 for (size_t i
= 0; i
< n
; ++i
)
14790 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14793 return gdb::array_view
<variant_part
> (result
, n
);
14796 /* Compute the variant part vector for FIP, attaching it to TYPE when
14800 add_variant_property (struct field_info
*fip
, struct type
*type
,
14801 struct dwarf2_cu
*cu
)
14803 /* Map section offsets of fields to their field index. Note the
14804 field index here does not take the number of baseclasses into
14806 offset_map_type offset_map
;
14807 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14808 offset_map
[fip
->fields
[i
].offset
] = i
;
14810 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14811 gdb::array_view
<variant_part
> parts
14812 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14813 fip
->variant_parts
);
14815 struct dynamic_prop prop
;
14816 prop
.kind
= PROP_VARIANT_PARTS
;
14817 prop
.data
.variant_parts
14818 = ((gdb::array_view
<variant_part
> *)
14819 obstack_copy (&objfile
->objfile_obstack
, &parts
, sizeof (parts
)));
14821 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14824 /* Create the vector of fields, and attach it to the type. */
14827 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14828 struct dwarf2_cu
*cu
)
14830 int nfields
= fip
->nfields ();
14832 /* Record the field count, allocate space for the array of fields,
14833 and create blank accessibility bitfields if necessary. */
14834 type
->set_num_fields (nfields
);
14836 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14838 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14840 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14842 TYPE_FIELD_PRIVATE_BITS (type
) =
14843 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14844 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14846 TYPE_FIELD_PROTECTED_BITS (type
) =
14847 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14848 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14850 TYPE_FIELD_IGNORE_BITS (type
) =
14851 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14852 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14855 /* If the type has baseclasses, allocate and clear a bit vector for
14856 TYPE_FIELD_VIRTUAL_BITS. */
14857 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14859 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14860 unsigned char *pointer
;
14862 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14863 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14864 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14865 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14866 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14869 if (!fip
->variant_parts
.empty ())
14870 add_variant_property (fip
, type
, cu
);
14872 /* Copy the saved-up fields into the field vector. */
14873 for (int i
= 0; i
< nfields
; ++i
)
14875 struct nextfield
&field
14876 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14877 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14879 type
->field (i
) = field
.field
;
14880 switch (field
.accessibility
)
14882 case DW_ACCESS_private
:
14883 if (cu
->language
!= language_ada
)
14884 SET_TYPE_FIELD_PRIVATE (type
, i
);
14887 case DW_ACCESS_protected
:
14888 if (cu
->language
!= language_ada
)
14889 SET_TYPE_FIELD_PROTECTED (type
, i
);
14892 case DW_ACCESS_public
:
14896 /* Unknown accessibility. Complain and treat it as public. */
14898 complaint (_("unsupported accessibility %d"),
14899 field
.accessibility
);
14903 if (i
< fip
->baseclasses
.size ())
14905 switch (field
.virtuality
)
14907 case DW_VIRTUALITY_virtual
:
14908 case DW_VIRTUALITY_pure_virtual
:
14909 if (cu
->language
== language_ada
)
14910 error (_("unexpected virtuality in component of Ada type"));
14911 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14918 /* Return true if this member function is a constructor, false
14922 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14924 const char *fieldname
;
14925 const char *type_name
;
14928 if (die
->parent
== NULL
)
14931 if (die
->parent
->tag
!= DW_TAG_structure_type
14932 && die
->parent
->tag
!= DW_TAG_union_type
14933 && die
->parent
->tag
!= DW_TAG_class_type
)
14936 fieldname
= dwarf2_name (die
, cu
);
14937 type_name
= dwarf2_name (die
->parent
, cu
);
14938 if (fieldname
== NULL
|| type_name
== NULL
)
14941 len
= strlen (fieldname
);
14942 return (strncmp (fieldname
, type_name
, len
) == 0
14943 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14946 /* Check if the given VALUE is a recognized enum
14947 dwarf_defaulted_attribute constant according to DWARF5 spec,
14951 is_valid_DW_AT_defaulted (ULONGEST value
)
14955 case DW_DEFAULTED_no
:
14956 case DW_DEFAULTED_in_class
:
14957 case DW_DEFAULTED_out_of_class
:
14961 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14965 /* Add a member function to the proper fieldlist. */
14968 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14969 struct type
*type
, struct dwarf2_cu
*cu
)
14971 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14972 struct attribute
*attr
;
14974 struct fnfieldlist
*flp
= nullptr;
14975 struct fn_field
*fnp
;
14976 const char *fieldname
;
14977 struct type
*this_type
;
14978 enum dwarf_access_attribute accessibility
;
14980 if (cu
->language
== language_ada
)
14981 error (_("unexpected member function in Ada type"));
14983 /* Get name of member function. */
14984 fieldname
= dwarf2_name (die
, cu
);
14985 if (fieldname
== NULL
)
14988 /* Look up member function name in fieldlist. */
14989 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14991 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14993 flp
= &fip
->fnfieldlists
[i
];
14998 /* Create a new fnfieldlist if necessary. */
14999 if (flp
== nullptr)
15001 fip
->fnfieldlists
.emplace_back ();
15002 flp
= &fip
->fnfieldlists
.back ();
15003 flp
->name
= fieldname
;
15004 i
= fip
->fnfieldlists
.size () - 1;
15007 /* Create a new member function field and add it to the vector of
15009 flp
->fnfields
.emplace_back ();
15010 fnp
= &flp
->fnfields
.back ();
15012 /* Delay processing of the physname until later. */
15013 if (cu
->language
== language_cplus
)
15014 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15018 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15019 fnp
->physname
= physname
? physname
: "";
15022 fnp
->type
= alloc_type (objfile
);
15023 this_type
= read_type_die (die
, cu
);
15024 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15026 int nparams
= this_type
->num_fields ();
15028 /* TYPE is the domain of this method, and THIS_TYPE is the type
15029 of the method itself (TYPE_CODE_METHOD). */
15030 smash_to_method_type (fnp
->type
, type
,
15031 TYPE_TARGET_TYPE (this_type
),
15032 this_type
->fields (),
15033 this_type
->num_fields (),
15034 TYPE_VARARGS (this_type
));
15036 /* Handle static member functions.
15037 Dwarf2 has no clean way to discern C++ static and non-static
15038 member functions. G++ helps GDB by marking the first
15039 parameter for non-static member functions (which is the this
15040 pointer) as artificial. We obtain this information from
15041 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15042 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15043 fnp
->voffset
= VOFFSET_STATIC
;
15046 complaint (_("member function type missing for '%s'"),
15047 dwarf2_full_name (fieldname
, die
, cu
));
15049 /* Get fcontext from DW_AT_containing_type if present. */
15050 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15051 fnp
->fcontext
= die_containing_type (die
, cu
);
15053 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15054 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15056 /* Get accessibility. */
15057 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15058 if (attr
!= nullptr)
15059 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15061 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15062 switch (accessibility
)
15064 case DW_ACCESS_private
:
15065 fnp
->is_private
= 1;
15067 case DW_ACCESS_protected
:
15068 fnp
->is_protected
= 1;
15072 /* Check for artificial methods. */
15073 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15074 if (attr
&& DW_UNSND (attr
) != 0)
15075 fnp
->is_artificial
= 1;
15077 /* Check for defaulted methods. */
15078 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15079 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15080 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15082 /* Check for deleted methods. */
15083 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15084 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15085 fnp
->is_deleted
= 1;
15087 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15089 /* Get index in virtual function table if it is a virtual member
15090 function. For older versions of GCC, this is an offset in the
15091 appropriate virtual table, as specified by DW_AT_containing_type.
15092 For everyone else, it is an expression to be evaluated relative
15093 to the object address. */
15095 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15096 if (attr
!= nullptr)
15098 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15100 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15102 /* Old-style GCC. */
15103 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15105 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15106 || (DW_BLOCK (attr
)->size
> 1
15107 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15108 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15110 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15111 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15112 dwarf2_complex_location_expr_complaint ();
15114 fnp
->voffset
/= cu
->header
.addr_size
;
15118 dwarf2_complex_location_expr_complaint ();
15120 if (!fnp
->fcontext
)
15122 /* If there is no `this' field and no DW_AT_containing_type,
15123 we cannot actually find a base class context for the
15125 if (this_type
->num_fields () == 0
15126 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15128 complaint (_("cannot determine context for virtual member "
15129 "function \"%s\" (offset %s)"),
15130 fieldname
, sect_offset_str (die
->sect_off
));
15135 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15139 else if (attr
->form_is_section_offset ())
15141 dwarf2_complex_location_expr_complaint ();
15145 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15151 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15152 if (attr
&& DW_UNSND (attr
))
15154 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15155 complaint (_("Member function \"%s\" (offset %s) is virtual "
15156 "but the vtable offset is not specified"),
15157 fieldname
, sect_offset_str (die
->sect_off
));
15158 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15159 TYPE_CPLUS_DYNAMIC (type
) = 1;
15164 /* Create the vector of member function fields, and attach it to the type. */
15167 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15168 struct dwarf2_cu
*cu
)
15170 if (cu
->language
== language_ada
)
15171 error (_("unexpected member functions in Ada type"));
15173 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15174 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15176 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15178 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15180 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15181 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15183 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15184 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15185 fn_flp
->fn_fields
= (struct fn_field
*)
15186 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15188 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15189 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15192 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15195 /* Returns non-zero if NAME is the name of a vtable member in CU's
15196 language, zero otherwise. */
15198 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15200 static const char vptr
[] = "_vptr";
15202 /* Look for the C++ form of the vtable. */
15203 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15209 /* GCC outputs unnamed structures that are really pointers to member
15210 functions, with the ABI-specified layout. If TYPE describes
15211 such a structure, smash it into a member function type.
15213 GCC shouldn't do this; it should just output pointer to member DIEs.
15214 This is GCC PR debug/28767. */
15217 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15219 struct type
*pfn_type
, *self_type
, *new_type
;
15221 /* Check for a structure with no name and two children. */
15222 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15225 /* Check for __pfn and __delta members. */
15226 if (TYPE_FIELD_NAME (type
, 0) == NULL
15227 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15228 || TYPE_FIELD_NAME (type
, 1) == NULL
15229 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15232 /* Find the type of the method. */
15233 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15234 if (pfn_type
== NULL
15235 || pfn_type
->code () != TYPE_CODE_PTR
15236 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15239 /* Look for the "this" argument. */
15240 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15241 if (pfn_type
->num_fields () == 0
15242 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15243 || TYPE_FIELD_TYPE (pfn_type
, 0)->code () != TYPE_CODE_PTR
)
15246 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15247 new_type
= alloc_type (objfile
);
15248 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15249 pfn_type
->fields (), pfn_type
->num_fields (),
15250 TYPE_VARARGS (pfn_type
));
15251 smash_to_methodptr_type (type
, new_type
);
15254 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15255 appropriate error checking and issuing complaints if there is a
15259 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15261 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15263 if (attr
== nullptr)
15266 if (!attr
->form_is_constant ())
15268 complaint (_("DW_AT_alignment must have constant form"
15269 " - DIE at %s [in module %s]"),
15270 sect_offset_str (die
->sect_off
),
15271 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15276 if (attr
->form
== DW_FORM_sdata
)
15278 LONGEST val
= DW_SND (attr
);
15281 complaint (_("DW_AT_alignment value must not be negative"
15282 " - DIE at %s [in module %s]"),
15283 sect_offset_str (die
->sect_off
),
15284 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15290 align
= DW_UNSND (attr
);
15294 complaint (_("DW_AT_alignment value must not be zero"
15295 " - DIE at %s [in module %s]"),
15296 sect_offset_str (die
->sect_off
),
15297 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15300 if ((align
& (align
- 1)) != 0)
15302 complaint (_("DW_AT_alignment value must be a power of 2"
15303 " - DIE at %s [in module %s]"),
15304 sect_offset_str (die
->sect_off
),
15305 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15312 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15313 the alignment for TYPE. */
15316 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15319 if (!set_type_align (type
, get_alignment (cu
, die
)))
15320 complaint (_("DW_AT_alignment value too large"
15321 " - DIE at %s [in module %s]"),
15322 sect_offset_str (die
->sect_off
),
15323 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15326 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15327 constant for a type, according to DWARF5 spec, Table 5.5. */
15330 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15335 case DW_CC_pass_by_reference
:
15336 case DW_CC_pass_by_value
:
15340 complaint (_("unrecognized DW_AT_calling_convention value "
15341 "(%s) for a type"), pulongest (value
));
15346 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15347 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15348 also according to GNU-specific values (see include/dwarf2.h). */
15351 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15356 case DW_CC_program
:
15360 case DW_CC_GNU_renesas_sh
:
15361 case DW_CC_GNU_borland_fastcall_i386
:
15362 case DW_CC_GDB_IBM_OpenCL
:
15366 complaint (_("unrecognized DW_AT_calling_convention value "
15367 "(%s) for a subroutine"), pulongest (value
));
15372 /* Called when we find the DIE that starts a structure or union scope
15373 (definition) to create a type for the structure or union. Fill in
15374 the type's name and general properties; the members will not be
15375 processed until process_structure_scope. A symbol table entry for
15376 the type will also not be done until process_structure_scope (assuming
15377 the type has a name).
15379 NOTE: we need to call these functions regardless of whether or not the
15380 DIE has a DW_AT_name attribute, since it might be an anonymous
15381 structure or union. This gets the type entered into our set of
15382 user defined types. */
15384 static struct type
*
15385 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15387 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15389 struct attribute
*attr
;
15392 /* If the definition of this type lives in .debug_types, read that type.
15393 Don't follow DW_AT_specification though, that will take us back up
15394 the chain and we want to go down. */
15395 attr
= die
->attr (DW_AT_signature
);
15396 if (attr
!= nullptr)
15398 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15400 /* The type's CU may not be the same as CU.
15401 Ensure TYPE is recorded with CU in die_type_hash. */
15402 return set_die_type (die
, type
, cu
);
15405 type
= alloc_type (objfile
);
15406 INIT_CPLUS_SPECIFIC (type
);
15408 name
= dwarf2_name (die
, cu
);
15411 if (cu
->language
== language_cplus
15412 || cu
->language
== language_d
15413 || cu
->language
== language_rust
)
15415 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15417 /* dwarf2_full_name might have already finished building the DIE's
15418 type. If so, there is no need to continue. */
15419 if (get_die_type (die
, cu
) != NULL
)
15420 return get_die_type (die
, cu
);
15422 type
->set_name (full_name
);
15426 /* The name is already allocated along with this objfile, so
15427 we don't need to duplicate it for the type. */
15428 type
->set_name (name
);
15432 if (die
->tag
== DW_TAG_structure_type
)
15434 type
->set_code (TYPE_CODE_STRUCT
);
15436 else if (die
->tag
== DW_TAG_union_type
)
15438 type
->set_code (TYPE_CODE_UNION
);
15442 type
->set_code (TYPE_CODE_STRUCT
);
15445 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15446 TYPE_DECLARED_CLASS (type
) = 1;
15448 /* Store the calling convention in the type if it's available in
15449 the die. Otherwise the calling convention remains set to
15450 the default value DW_CC_normal. */
15451 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15452 if (attr
!= nullptr
15453 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15455 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15456 TYPE_CPLUS_CALLING_CONVENTION (type
)
15457 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15460 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15461 if (attr
!= nullptr)
15463 if (attr
->form_is_constant ())
15464 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15467 struct dynamic_prop prop
;
15468 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
15469 cu
->per_cu
->addr_type ()))
15470 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15471 TYPE_LENGTH (type
) = 0;
15476 TYPE_LENGTH (type
) = 0;
15479 maybe_set_alignment (cu
, die
, type
);
15481 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15483 /* ICC<14 does not output the required DW_AT_declaration on
15484 incomplete types, but gives them a size of zero. */
15485 TYPE_STUB (type
) = 1;
15488 TYPE_STUB_SUPPORTED (type
) = 1;
15490 if (die_is_declaration (die
, cu
))
15491 TYPE_STUB (type
) = 1;
15492 else if (attr
== NULL
&& die
->child
== NULL
15493 && producer_is_realview (cu
->producer
))
15494 /* RealView does not output the required DW_AT_declaration
15495 on incomplete types. */
15496 TYPE_STUB (type
) = 1;
15498 /* We need to add the type field to the die immediately so we don't
15499 infinitely recurse when dealing with pointers to the structure
15500 type within the structure itself. */
15501 set_die_type (die
, type
, cu
);
15503 /* set_die_type should be already done. */
15504 set_descriptive_type (type
, die
, cu
);
15509 static void handle_struct_member_die
15510 (struct die_info
*child_die
,
15512 struct field_info
*fi
,
15513 std::vector
<struct symbol
*> *template_args
,
15514 struct dwarf2_cu
*cu
);
15516 /* A helper for handle_struct_member_die that handles
15517 DW_TAG_variant_part. */
15520 handle_variant_part (struct die_info
*die
, struct type
*type
,
15521 struct field_info
*fi
,
15522 std::vector
<struct symbol
*> *template_args
,
15523 struct dwarf2_cu
*cu
)
15525 variant_part_builder
*new_part
;
15526 if (fi
->current_variant_part
== nullptr)
15528 fi
->variant_parts
.emplace_back ();
15529 new_part
= &fi
->variant_parts
.back ();
15531 else if (!fi
->current_variant_part
->processing_variant
)
15533 complaint (_("nested DW_TAG_variant_part seen "
15534 "- DIE at %s [in module %s]"),
15535 sect_offset_str (die
->sect_off
),
15536 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15541 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15542 current
.variant_parts
.emplace_back ();
15543 new_part
= ¤t
.variant_parts
.back ();
15546 /* When we recurse, we want callees to add to this new variant
15548 scoped_restore save_current_variant_part
15549 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15551 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15554 /* It's a univariant form, an extension we support. */
15556 else if (discr
->form_is_ref ())
15558 struct dwarf2_cu
*target_cu
= cu
;
15559 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15561 new_part
->discriminant_offset
= target_die
->sect_off
;
15565 complaint (_("DW_AT_discr does not have DIE reference form"
15566 " - DIE at %s [in module %s]"),
15567 sect_offset_str (die
->sect_off
),
15568 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15571 for (die_info
*child_die
= die
->child
;
15573 child_die
= child_die
->sibling
)
15574 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15577 /* A helper for handle_struct_member_die that handles
15581 handle_variant (struct die_info
*die
, struct type
*type
,
15582 struct field_info
*fi
,
15583 std::vector
<struct symbol
*> *template_args
,
15584 struct dwarf2_cu
*cu
)
15586 if (fi
->current_variant_part
== nullptr)
15588 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15589 "- DIE at %s [in module %s]"),
15590 sect_offset_str (die
->sect_off
),
15591 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15594 if (fi
->current_variant_part
->processing_variant
)
15596 complaint (_("nested DW_TAG_variant seen "
15597 "- DIE at %s [in module %s]"),
15598 sect_offset_str (die
->sect_off
),
15599 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15603 scoped_restore save_processing_variant
15604 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15607 fi
->current_variant_part
->variants
.emplace_back ();
15608 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15609 variant
.first_field
= fi
->fields
.size ();
15611 /* In a variant we want to get the discriminant and also add a
15612 field for our sole member child. */
15613 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15614 if (discr
== nullptr)
15616 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15617 if (discr
== nullptr || DW_BLOCK (discr
)->size
== 0)
15618 variant
.default_branch
= true;
15620 variant
.discr_list_data
= DW_BLOCK (discr
);
15623 variant
.discriminant_value
= DW_UNSND (discr
);
15625 for (die_info
*variant_child
= die
->child
;
15626 variant_child
!= NULL
;
15627 variant_child
= variant_child
->sibling
)
15628 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15630 variant
.last_field
= fi
->fields
.size ();
15633 /* A helper for process_structure_scope that handles a single member
15637 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15638 struct field_info
*fi
,
15639 std::vector
<struct symbol
*> *template_args
,
15640 struct dwarf2_cu
*cu
)
15642 if (child_die
->tag
== DW_TAG_member
15643 || child_die
->tag
== DW_TAG_variable
)
15645 /* NOTE: carlton/2002-11-05: A C++ static data member
15646 should be a DW_TAG_member that is a declaration, but
15647 all versions of G++ as of this writing (so through at
15648 least 3.2.1) incorrectly generate DW_TAG_variable
15649 tags for them instead. */
15650 dwarf2_add_field (fi
, child_die
, cu
);
15652 else if (child_die
->tag
== DW_TAG_subprogram
)
15654 /* Rust doesn't have member functions in the C++ sense.
15655 However, it does emit ordinary functions as children
15656 of a struct DIE. */
15657 if (cu
->language
== language_rust
)
15658 read_func_scope (child_die
, cu
);
15661 /* C++ member function. */
15662 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15665 else if (child_die
->tag
== DW_TAG_inheritance
)
15667 /* C++ base class field. */
15668 dwarf2_add_field (fi
, child_die
, cu
);
15670 else if (type_can_define_types (child_die
))
15671 dwarf2_add_type_defn (fi
, child_die
, cu
);
15672 else if (child_die
->tag
== DW_TAG_template_type_param
15673 || child_die
->tag
== DW_TAG_template_value_param
)
15675 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15678 template_args
->push_back (arg
);
15680 else if (child_die
->tag
== DW_TAG_variant_part
)
15681 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15682 else if (child_die
->tag
== DW_TAG_variant
)
15683 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15686 /* Finish creating a structure or union type, including filling in
15687 its members and creating a symbol for it. */
15690 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15692 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15693 struct die_info
*child_die
;
15696 type
= get_die_type (die
, cu
);
15698 type
= read_structure_type (die
, cu
);
15700 bool has_template_parameters
= false;
15701 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15703 struct field_info fi
;
15704 std::vector
<struct symbol
*> template_args
;
15706 child_die
= die
->child
;
15708 while (child_die
&& child_die
->tag
)
15710 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15711 child_die
= child_die
->sibling
;
15714 /* Attach template arguments to type. */
15715 if (!template_args
.empty ())
15717 has_template_parameters
= true;
15718 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15719 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15720 TYPE_TEMPLATE_ARGUMENTS (type
)
15721 = XOBNEWVEC (&objfile
->objfile_obstack
,
15723 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15724 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15725 template_args
.data (),
15726 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15727 * sizeof (struct symbol
*)));
15730 /* Attach fields and member functions to the type. */
15731 if (fi
.nfields () > 0)
15732 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15733 if (!fi
.fnfieldlists
.empty ())
15735 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15737 /* Get the type which refers to the base class (possibly this
15738 class itself) which contains the vtable pointer for the current
15739 class from the DW_AT_containing_type attribute. This use of
15740 DW_AT_containing_type is a GNU extension. */
15742 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15744 struct type
*t
= die_containing_type (die
, cu
);
15746 set_type_vptr_basetype (type
, t
);
15751 /* Our own class provides vtbl ptr. */
15752 for (i
= t
->num_fields () - 1;
15753 i
>= TYPE_N_BASECLASSES (t
);
15756 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15758 if (is_vtable_name (fieldname
, cu
))
15760 set_type_vptr_fieldno (type
, i
);
15765 /* Complain if virtual function table field not found. */
15766 if (i
< TYPE_N_BASECLASSES (t
))
15767 complaint (_("virtual function table pointer "
15768 "not found when defining class '%s'"),
15769 type
->name () ? type
->name () : "");
15773 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15776 else if (cu
->producer
15777 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15779 /* The IBM XLC compiler does not provide direct indication
15780 of the containing type, but the vtable pointer is
15781 always named __vfp. */
15785 for (i
= type
->num_fields () - 1;
15786 i
>= TYPE_N_BASECLASSES (type
);
15789 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15791 set_type_vptr_fieldno (type
, i
);
15792 set_type_vptr_basetype (type
, type
);
15799 /* Copy fi.typedef_field_list linked list elements content into the
15800 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15801 if (!fi
.typedef_field_list
.empty ())
15803 int count
= fi
.typedef_field_list
.size ();
15805 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15806 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15807 = ((struct decl_field
*)
15809 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15810 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15812 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15813 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15816 /* Copy fi.nested_types_list linked list elements content into the
15817 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15818 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15820 int count
= fi
.nested_types_list
.size ();
15822 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15823 TYPE_NESTED_TYPES_ARRAY (type
)
15824 = ((struct decl_field
*)
15825 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15826 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15828 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15829 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15833 quirk_gcc_member_function_pointer (type
, objfile
);
15834 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15835 cu
->rust_unions
.push_back (type
);
15837 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15838 snapshots) has been known to create a die giving a declaration
15839 for a class that has, as a child, a die giving a definition for a
15840 nested class. So we have to process our children even if the
15841 current die is a declaration. Normally, of course, a declaration
15842 won't have any children at all. */
15844 child_die
= die
->child
;
15846 while (child_die
!= NULL
&& child_die
->tag
)
15848 if (child_die
->tag
== DW_TAG_member
15849 || child_die
->tag
== DW_TAG_variable
15850 || child_die
->tag
== DW_TAG_inheritance
15851 || child_die
->tag
== DW_TAG_template_value_param
15852 || child_die
->tag
== DW_TAG_template_type_param
)
15857 process_die (child_die
, cu
);
15859 child_die
= child_die
->sibling
;
15862 /* Do not consider external references. According to the DWARF standard,
15863 these DIEs are identified by the fact that they have no byte_size
15864 attribute, and a declaration attribute. */
15865 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15866 || !die_is_declaration (die
, cu
)
15867 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15869 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15871 if (has_template_parameters
)
15873 struct symtab
*symtab
;
15874 if (sym
!= nullptr)
15875 symtab
= symbol_symtab (sym
);
15876 else if (cu
->line_header
!= nullptr)
15878 /* Any related symtab will do. */
15880 = cu
->line_header
->file_names ()[0].symtab
;
15885 complaint (_("could not find suitable "
15886 "symtab for template parameter"
15887 " - DIE at %s [in module %s]"),
15888 sect_offset_str (die
->sect_off
),
15889 objfile_name (objfile
));
15892 if (symtab
!= nullptr)
15894 /* Make sure that the symtab is set on the new symbols.
15895 Even though they don't appear in this symtab directly,
15896 other parts of gdb assume that symbols do, and this is
15897 reasonably true. */
15898 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15899 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15905 /* Assuming DIE is an enumeration type, and TYPE is its associated
15906 type, update TYPE using some information only available in DIE's
15907 children. In particular, the fields are computed. */
15910 update_enumeration_type_from_children (struct die_info
*die
,
15912 struct dwarf2_cu
*cu
)
15914 struct die_info
*child_die
;
15915 int unsigned_enum
= 1;
15918 auto_obstack obstack
;
15919 std::vector
<struct field
> fields
;
15921 for (child_die
= die
->child
;
15922 child_die
!= NULL
&& child_die
->tag
;
15923 child_die
= child_die
->sibling
)
15925 struct attribute
*attr
;
15927 const gdb_byte
*bytes
;
15928 struct dwarf2_locexpr_baton
*baton
;
15931 if (child_die
->tag
!= DW_TAG_enumerator
)
15934 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15938 name
= dwarf2_name (child_die
, cu
);
15940 name
= "<anonymous enumerator>";
15942 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15943 &value
, &bytes
, &baton
);
15951 if (count_one_bits_ll (value
) >= 2)
15955 fields
.emplace_back ();
15956 struct field
&field
= fields
.back ();
15957 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
15958 SET_FIELD_ENUMVAL (field
, value
);
15961 if (!fields
.empty ())
15963 type
->set_num_fields (fields
.size ());
15966 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
15967 memcpy (type
->fields (), fields
.data (),
15968 sizeof (struct field
) * fields
.size ());
15972 TYPE_UNSIGNED (type
) = 1;
15974 TYPE_FLAG_ENUM (type
) = 1;
15977 /* Given a DW_AT_enumeration_type die, set its type. We do not
15978 complete the type's fields yet, or create any symbols. */
15980 static struct type
*
15981 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15983 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15985 struct attribute
*attr
;
15988 /* If the definition of this type lives in .debug_types, read that type.
15989 Don't follow DW_AT_specification though, that will take us back up
15990 the chain and we want to go down. */
15991 attr
= die
->attr (DW_AT_signature
);
15992 if (attr
!= nullptr)
15994 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15996 /* The type's CU may not be the same as CU.
15997 Ensure TYPE is recorded with CU in die_type_hash. */
15998 return set_die_type (die
, type
, cu
);
16001 type
= alloc_type (objfile
);
16003 type
->set_code (TYPE_CODE_ENUM
);
16004 name
= dwarf2_full_name (NULL
, die
, cu
);
16006 type
->set_name (name
);
16008 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16011 struct type
*underlying_type
= die_type (die
, cu
);
16013 TYPE_TARGET_TYPE (type
) = underlying_type
;
16016 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16017 if (attr
!= nullptr)
16019 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16023 TYPE_LENGTH (type
) = 0;
16026 maybe_set_alignment (cu
, die
, type
);
16028 /* The enumeration DIE can be incomplete. In Ada, any type can be
16029 declared as private in the package spec, and then defined only
16030 inside the package body. Such types are known as Taft Amendment
16031 Types. When another package uses such a type, an incomplete DIE
16032 may be generated by the compiler. */
16033 if (die_is_declaration (die
, cu
))
16034 TYPE_STUB (type
) = 1;
16036 /* If this type has an underlying type that is not a stub, then we
16037 may use its attributes. We always use the "unsigned" attribute
16038 in this situation, because ordinarily we guess whether the type
16039 is unsigned -- but the guess can be wrong and the underlying type
16040 can tell us the reality. However, we defer to a local size
16041 attribute if one exists, because this lets the compiler override
16042 the underlying type if needed. */
16043 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16045 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16046 underlying_type
= check_typedef (underlying_type
);
16047 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
16048 if (TYPE_LENGTH (type
) == 0)
16049 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16050 if (TYPE_RAW_ALIGN (type
) == 0
16051 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16052 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16055 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16057 set_die_type (die
, type
, cu
);
16059 /* Finish the creation of this type by using the enum's children.
16060 Note that, as usual, this must come after set_die_type to avoid
16061 infinite recursion when trying to compute the names of the
16063 update_enumeration_type_from_children (die
, type
, cu
);
16068 /* Given a pointer to a die which begins an enumeration, process all
16069 the dies that define the members of the enumeration, and create the
16070 symbol for the enumeration type.
16072 NOTE: We reverse the order of the element list. */
16075 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16077 struct type
*this_type
;
16079 this_type
= get_die_type (die
, cu
);
16080 if (this_type
== NULL
)
16081 this_type
= read_enumeration_type (die
, cu
);
16083 if (die
->child
!= NULL
)
16085 struct die_info
*child_die
;
16088 child_die
= die
->child
;
16089 while (child_die
&& child_die
->tag
)
16091 if (child_die
->tag
!= DW_TAG_enumerator
)
16093 process_die (child_die
, cu
);
16097 name
= dwarf2_name (child_die
, cu
);
16099 new_symbol (child_die
, this_type
, cu
);
16102 child_die
= child_die
->sibling
;
16106 /* If we are reading an enum from a .debug_types unit, and the enum
16107 is a declaration, and the enum is not the signatured type in the
16108 unit, then we do not want to add a symbol for it. Adding a
16109 symbol would in some cases obscure the true definition of the
16110 enum, giving users an incomplete type when the definition is
16111 actually available. Note that we do not want to do this for all
16112 enums which are just declarations, because C++0x allows forward
16113 enum declarations. */
16114 if (cu
->per_cu
->is_debug_types
16115 && die_is_declaration (die
, cu
))
16117 struct signatured_type
*sig_type
;
16119 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16120 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16121 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16125 new_symbol (die
, this_type
, cu
);
16128 /* Extract all information from a DW_TAG_array_type DIE and put it in
16129 the DIE's type field. For now, this only handles one dimensional
16132 static struct type
*
16133 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16135 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16136 struct die_info
*child_die
;
16138 struct type
*element_type
, *range_type
, *index_type
;
16139 struct attribute
*attr
;
16141 struct dynamic_prop
*byte_stride_prop
= NULL
;
16142 unsigned int bit_stride
= 0;
16144 element_type
= die_type (die
, cu
);
16146 /* The die_type call above may have already set the type for this DIE. */
16147 type
= get_die_type (die
, cu
);
16151 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16155 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
16158 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16159 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16163 complaint (_("unable to read array DW_AT_byte_stride "
16164 " - DIE at %s [in module %s]"),
16165 sect_offset_str (die
->sect_off
),
16166 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16167 /* Ignore this attribute. We will likely not be able to print
16168 arrays of this type correctly, but there is little we can do
16169 to help if we cannot read the attribute's value. */
16170 byte_stride_prop
= NULL
;
16174 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16176 bit_stride
= DW_UNSND (attr
);
16178 /* Irix 6.2 native cc creates array types without children for
16179 arrays with unspecified length. */
16180 if (die
->child
== NULL
)
16182 index_type
= objfile_type (objfile
)->builtin_int
;
16183 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16184 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16185 byte_stride_prop
, bit_stride
);
16186 return set_die_type (die
, type
, cu
);
16189 std::vector
<struct type
*> range_types
;
16190 child_die
= die
->child
;
16191 while (child_die
&& child_die
->tag
)
16193 if (child_die
->tag
== DW_TAG_subrange_type
)
16195 struct type
*child_type
= read_type_die (child_die
, cu
);
16197 if (child_type
!= NULL
)
16199 /* The range type was succesfully read. Save it for the
16200 array type creation. */
16201 range_types
.push_back (child_type
);
16204 child_die
= child_die
->sibling
;
16207 /* Dwarf2 dimensions are output from left to right, create the
16208 necessary array types in backwards order. */
16210 type
= element_type
;
16212 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16216 while (i
< range_types
.size ())
16217 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16218 byte_stride_prop
, bit_stride
);
16222 size_t ndim
= range_types
.size ();
16224 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16225 byte_stride_prop
, bit_stride
);
16228 /* Understand Dwarf2 support for vector types (like they occur on
16229 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16230 array type. This is not part of the Dwarf2/3 standard yet, but a
16231 custom vendor extension. The main difference between a regular
16232 array and the vector variant is that vectors are passed by value
16234 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16235 if (attr
!= nullptr)
16236 make_vector_type (type
);
16238 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16239 implementation may choose to implement triple vectors using this
16241 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16242 if (attr
!= nullptr)
16244 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16245 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16247 complaint (_("DW_AT_byte_size for array type smaller "
16248 "than the total size of elements"));
16251 name
= dwarf2_name (die
, cu
);
16253 type
->set_name (name
);
16255 maybe_set_alignment (cu
, die
, type
);
16257 /* Install the type in the die. */
16258 set_die_type (die
, type
, cu
);
16260 /* set_die_type should be already done. */
16261 set_descriptive_type (type
, die
, cu
);
16266 static enum dwarf_array_dim_ordering
16267 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16269 struct attribute
*attr
;
16271 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16273 if (attr
!= nullptr)
16274 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16276 /* GNU F77 is a special case, as at 08/2004 array type info is the
16277 opposite order to the dwarf2 specification, but data is still
16278 laid out as per normal fortran.
16280 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16281 version checking. */
16283 if (cu
->language
== language_fortran
16284 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16286 return DW_ORD_row_major
;
16289 switch (cu
->language_defn
->la_array_ordering
)
16291 case array_column_major
:
16292 return DW_ORD_col_major
;
16293 case array_row_major
:
16295 return DW_ORD_row_major
;
16299 /* Extract all information from a DW_TAG_set_type DIE and put it in
16300 the DIE's type field. */
16302 static struct type
*
16303 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16305 struct type
*domain_type
, *set_type
;
16306 struct attribute
*attr
;
16308 domain_type
= die_type (die
, cu
);
16310 /* The die_type call above may have already set the type for this DIE. */
16311 set_type
= get_die_type (die
, cu
);
16315 set_type
= create_set_type (NULL
, domain_type
);
16317 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16318 if (attr
!= nullptr)
16319 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16321 maybe_set_alignment (cu
, die
, set_type
);
16323 return set_die_type (die
, set_type
, cu
);
16326 /* A helper for read_common_block that creates a locexpr baton.
16327 SYM is the symbol which we are marking as computed.
16328 COMMON_DIE is the DIE for the common block.
16329 COMMON_LOC is the location expression attribute for the common
16331 MEMBER_LOC is the location expression attribute for the particular
16332 member of the common block that we are processing.
16333 CU is the CU from which the above come. */
16336 mark_common_block_symbol_computed (struct symbol
*sym
,
16337 struct die_info
*common_die
,
16338 struct attribute
*common_loc
,
16339 struct attribute
*member_loc
,
16340 struct dwarf2_cu
*cu
)
16342 dwarf2_per_objfile
*per_objfile
= cu
->per_cu
->dwarf2_per_objfile
;
16343 struct objfile
*objfile
= per_objfile
->objfile
;
16344 struct dwarf2_locexpr_baton
*baton
;
16346 unsigned int cu_off
;
16347 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16348 LONGEST offset
= 0;
16350 gdb_assert (common_loc
&& member_loc
);
16351 gdb_assert (common_loc
->form_is_block ());
16352 gdb_assert (member_loc
->form_is_block ()
16353 || member_loc
->form_is_constant ());
16355 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16356 baton
->per_objfile
= per_objfile
;
16357 baton
->per_cu
= cu
->per_cu
;
16358 gdb_assert (baton
->per_cu
);
16360 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16362 if (member_loc
->form_is_constant ())
16364 offset
= member_loc
->constant_value (0);
16365 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16368 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16370 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16373 *ptr
++ = DW_OP_call4
;
16374 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16375 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16378 if (member_loc
->form_is_constant ())
16380 *ptr
++ = DW_OP_addr
;
16381 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16382 ptr
+= cu
->header
.addr_size
;
16386 /* We have to copy the data here, because DW_OP_call4 will only
16387 use a DW_AT_location attribute. */
16388 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16389 ptr
+= DW_BLOCK (member_loc
)->size
;
16392 *ptr
++ = DW_OP_plus
;
16393 gdb_assert (ptr
- baton
->data
== baton
->size
);
16395 SYMBOL_LOCATION_BATON (sym
) = baton
;
16396 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16399 /* Create appropriate locally-scoped variables for all the
16400 DW_TAG_common_block entries. Also create a struct common_block
16401 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16402 is used to separate the common blocks name namespace from regular
16406 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16408 struct attribute
*attr
;
16410 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16411 if (attr
!= nullptr)
16413 /* Support the .debug_loc offsets. */
16414 if (attr
->form_is_block ())
16418 else if (attr
->form_is_section_offset ())
16420 dwarf2_complex_location_expr_complaint ();
16425 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16426 "common block member");
16431 if (die
->child
!= NULL
)
16433 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16434 struct die_info
*child_die
;
16435 size_t n_entries
= 0, size
;
16436 struct common_block
*common_block
;
16437 struct symbol
*sym
;
16439 for (child_die
= die
->child
;
16440 child_die
&& child_die
->tag
;
16441 child_die
= child_die
->sibling
)
16444 size
= (sizeof (struct common_block
)
16445 + (n_entries
- 1) * sizeof (struct symbol
*));
16447 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16449 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16450 common_block
->n_entries
= 0;
16452 for (child_die
= die
->child
;
16453 child_die
&& child_die
->tag
;
16454 child_die
= child_die
->sibling
)
16456 /* Create the symbol in the DW_TAG_common_block block in the current
16458 sym
= new_symbol (child_die
, NULL
, cu
);
16461 struct attribute
*member_loc
;
16463 common_block
->contents
[common_block
->n_entries
++] = sym
;
16465 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16469 /* GDB has handled this for a long time, but it is
16470 not specified by DWARF. It seems to have been
16471 emitted by gfortran at least as recently as:
16472 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16473 complaint (_("Variable in common block has "
16474 "DW_AT_data_member_location "
16475 "- DIE at %s [in module %s]"),
16476 sect_offset_str (child_die
->sect_off
),
16477 objfile_name (objfile
));
16479 if (member_loc
->form_is_section_offset ())
16480 dwarf2_complex_location_expr_complaint ();
16481 else if (member_loc
->form_is_constant ()
16482 || member_loc
->form_is_block ())
16484 if (attr
!= nullptr)
16485 mark_common_block_symbol_computed (sym
, die
, attr
,
16489 dwarf2_complex_location_expr_complaint ();
16494 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16495 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16499 /* Create a type for a C++ namespace. */
16501 static struct type
*
16502 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16504 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16505 const char *previous_prefix
, *name
;
16509 /* For extensions, reuse the type of the original namespace. */
16510 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16512 struct die_info
*ext_die
;
16513 struct dwarf2_cu
*ext_cu
= cu
;
16515 ext_die
= dwarf2_extension (die
, &ext_cu
);
16516 type
= read_type_die (ext_die
, ext_cu
);
16518 /* EXT_CU may not be the same as CU.
16519 Ensure TYPE is recorded with CU in die_type_hash. */
16520 return set_die_type (die
, type
, cu
);
16523 name
= namespace_name (die
, &is_anonymous
, cu
);
16525 /* Now build the name of the current namespace. */
16527 previous_prefix
= determine_prefix (die
, cu
);
16528 if (previous_prefix
[0] != '\0')
16529 name
= typename_concat (&objfile
->objfile_obstack
,
16530 previous_prefix
, name
, 0, cu
);
16532 /* Create the type. */
16533 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16535 return set_die_type (die
, type
, cu
);
16538 /* Read a namespace scope. */
16541 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16543 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16546 /* Add a symbol associated to this if we haven't seen the namespace
16547 before. Also, add a using directive if it's an anonymous
16550 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16554 type
= read_type_die (die
, cu
);
16555 new_symbol (die
, type
, cu
);
16557 namespace_name (die
, &is_anonymous
, cu
);
16560 const char *previous_prefix
= determine_prefix (die
, cu
);
16562 std::vector
<const char *> excludes
;
16563 add_using_directive (using_directives (cu
),
16564 previous_prefix
, type
->name (), NULL
,
16565 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16569 if (die
->child
!= NULL
)
16571 struct die_info
*child_die
= die
->child
;
16573 while (child_die
&& child_die
->tag
)
16575 process_die (child_die
, cu
);
16576 child_die
= child_die
->sibling
;
16581 /* Read a Fortran module as type. This DIE can be only a declaration used for
16582 imported module. Still we need that type as local Fortran "use ... only"
16583 declaration imports depend on the created type in determine_prefix. */
16585 static struct type
*
16586 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16588 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16589 const char *module_name
;
16592 module_name
= dwarf2_name (die
, cu
);
16593 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16595 return set_die_type (die
, type
, cu
);
16598 /* Read a Fortran module. */
16601 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16603 struct die_info
*child_die
= die
->child
;
16606 type
= read_type_die (die
, cu
);
16607 new_symbol (die
, type
, cu
);
16609 while (child_die
&& child_die
->tag
)
16611 process_die (child_die
, cu
);
16612 child_die
= child_die
->sibling
;
16616 /* Return the name of the namespace represented by DIE. Set
16617 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16620 static const char *
16621 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16623 struct die_info
*current_die
;
16624 const char *name
= NULL
;
16626 /* Loop through the extensions until we find a name. */
16628 for (current_die
= die
;
16629 current_die
!= NULL
;
16630 current_die
= dwarf2_extension (die
, &cu
))
16632 /* We don't use dwarf2_name here so that we can detect the absence
16633 of a name -> anonymous namespace. */
16634 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16640 /* Is it an anonymous namespace? */
16642 *is_anonymous
= (name
== NULL
);
16644 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16649 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16650 the user defined type vector. */
16652 static struct type
*
16653 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16655 struct gdbarch
*gdbarch
16656 = cu
->per_cu
->dwarf2_per_objfile
->objfile
->arch ();
16657 struct comp_unit_head
*cu_header
= &cu
->header
;
16659 struct attribute
*attr_byte_size
;
16660 struct attribute
*attr_address_class
;
16661 int byte_size
, addr_class
;
16662 struct type
*target_type
;
16664 target_type
= die_type (die
, cu
);
16666 /* The die_type call above may have already set the type for this DIE. */
16667 type
= get_die_type (die
, cu
);
16671 type
= lookup_pointer_type (target_type
);
16673 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16674 if (attr_byte_size
)
16675 byte_size
= DW_UNSND (attr_byte_size
);
16677 byte_size
= cu_header
->addr_size
;
16679 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16680 if (attr_address_class
)
16681 addr_class
= DW_UNSND (attr_address_class
);
16683 addr_class
= DW_ADDR_none
;
16685 ULONGEST alignment
= get_alignment (cu
, die
);
16687 /* If the pointer size, alignment, or address class is different
16688 than the default, create a type variant marked as such and set
16689 the length accordingly. */
16690 if (TYPE_LENGTH (type
) != byte_size
16691 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16692 && alignment
!= TYPE_RAW_ALIGN (type
))
16693 || addr_class
!= DW_ADDR_none
)
16695 if (gdbarch_address_class_type_flags_p (gdbarch
))
16699 type_flags
= gdbarch_address_class_type_flags
16700 (gdbarch
, byte_size
, addr_class
);
16701 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16703 type
= make_type_with_address_space (type
, type_flags
);
16705 else if (TYPE_LENGTH (type
) != byte_size
)
16707 complaint (_("invalid pointer size %d"), byte_size
);
16709 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16711 complaint (_("Invalid DW_AT_alignment"
16712 " - DIE at %s [in module %s]"),
16713 sect_offset_str (die
->sect_off
),
16714 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16718 /* Should we also complain about unhandled address classes? */
16722 TYPE_LENGTH (type
) = byte_size
;
16723 set_type_align (type
, alignment
);
16724 return set_die_type (die
, type
, cu
);
16727 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16728 the user defined type vector. */
16730 static struct type
*
16731 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16734 struct type
*to_type
;
16735 struct type
*domain
;
16737 to_type
= die_type (die
, cu
);
16738 domain
= die_containing_type (die
, cu
);
16740 /* The calls above may have already set the type for this DIE. */
16741 type
= get_die_type (die
, cu
);
16745 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
16746 type
= lookup_methodptr_type (to_type
);
16747 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
16749 struct type
*new_type
16750 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16752 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16753 to_type
->fields (), to_type
->num_fields (),
16754 TYPE_VARARGS (to_type
));
16755 type
= lookup_methodptr_type (new_type
);
16758 type
= lookup_memberptr_type (to_type
, domain
);
16760 return set_die_type (die
, type
, cu
);
16763 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16764 the user defined type vector. */
16766 static struct type
*
16767 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16768 enum type_code refcode
)
16770 struct comp_unit_head
*cu_header
= &cu
->header
;
16771 struct type
*type
, *target_type
;
16772 struct attribute
*attr
;
16774 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16776 target_type
= die_type (die
, cu
);
16778 /* The die_type call above may have already set the type for this DIE. */
16779 type
= get_die_type (die
, cu
);
16783 type
= lookup_reference_type (target_type
, refcode
);
16784 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16785 if (attr
!= nullptr)
16787 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16791 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16793 maybe_set_alignment (cu
, die
, type
);
16794 return set_die_type (die
, type
, cu
);
16797 /* Add the given cv-qualifiers to the element type of the array. GCC
16798 outputs DWARF type qualifiers that apply to an array, not the
16799 element type. But GDB relies on the array element type to carry
16800 the cv-qualifiers. This mimics section 6.7.3 of the C99
16803 static struct type
*
16804 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16805 struct type
*base_type
, int cnst
, int voltl
)
16807 struct type
*el_type
, *inner_array
;
16809 base_type
= copy_type (base_type
);
16810 inner_array
= base_type
;
16812 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
16814 TYPE_TARGET_TYPE (inner_array
) =
16815 copy_type (TYPE_TARGET_TYPE (inner_array
));
16816 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16819 el_type
= TYPE_TARGET_TYPE (inner_array
);
16820 cnst
|= TYPE_CONST (el_type
);
16821 voltl
|= TYPE_VOLATILE (el_type
);
16822 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16824 return set_die_type (die
, base_type
, cu
);
16827 static struct type
*
16828 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16830 struct type
*base_type
, *cv_type
;
16832 base_type
= die_type (die
, cu
);
16834 /* The die_type call above may have already set the type for this DIE. */
16835 cv_type
= get_die_type (die
, cu
);
16839 /* In case the const qualifier is applied to an array type, the element type
16840 is so qualified, not the array type (section 6.7.3 of C99). */
16841 if (base_type
->code () == TYPE_CODE_ARRAY
)
16842 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16844 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16845 return set_die_type (die
, cv_type
, cu
);
16848 static struct type
*
16849 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16851 struct type
*base_type
, *cv_type
;
16853 base_type
= die_type (die
, cu
);
16855 /* The die_type call above may have already set the type for this DIE. */
16856 cv_type
= get_die_type (die
, cu
);
16860 /* In case the volatile qualifier is applied to an array type, the
16861 element type is so qualified, not the array type (section 6.7.3
16863 if (base_type
->code () == TYPE_CODE_ARRAY
)
16864 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16866 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16867 return set_die_type (die
, cv_type
, cu
);
16870 /* Handle DW_TAG_restrict_type. */
16872 static struct type
*
16873 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16875 struct type
*base_type
, *cv_type
;
16877 base_type
= die_type (die
, cu
);
16879 /* The die_type call above may have already set the type for this DIE. */
16880 cv_type
= get_die_type (die
, cu
);
16884 cv_type
= make_restrict_type (base_type
);
16885 return set_die_type (die
, cv_type
, cu
);
16888 /* Handle DW_TAG_atomic_type. */
16890 static struct type
*
16891 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16893 struct type
*base_type
, *cv_type
;
16895 base_type
= die_type (die
, cu
);
16897 /* The die_type call above may have already set the type for this DIE. */
16898 cv_type
= get_die_type (die
, cu
);
16902 cv_type
= make_atomic_type (base_type
);
16903 return set_die_type (die
, cv_type
, cu
);
16906 /* Extract all information from a DW_TAG_string_type DIE and add to
16907 the user defined type vector. It isn't really a user defined type,
16908 but it behaves like one, with other DIE's using an AT_user_def_type
16909 attribute to reference it. */
16911 static struct type
*
16912 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16914 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16915 struct gdbarch
*gdbarch
= objfile
->arch ();
16916 struct type
*type
, *range_type
, *index_type
, *char_type
;
16917 struct attribute
*attr
;
16918 struct dynamic_prop prop
;
16919 bool length_is_constant
= true;
16922 /* There are a couple of places where bit sizes might be made use of
16923 when parsing a DW_TAG_string_type, however, no producer that we know
16924 of make use of these. Handling bit sizes that are a multiple of the
16925 byte size is easy enough, but what about other bit sizes? Lets deal
16926 with that problem when we have to. Warn about these attributes being
16927 unsupported, then parse the type and ignore them like we always
16929 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16930 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16932 static bool warning_printed
= false;
16933 if (!warning_printed
)
16935 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16936 "currently supported on DW_TAG_string_type."));
16937 warning_printed
= true;
16941 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16942 if (attr
!= nullptr && !attr
->form_is_constant ())
16944 /* The string length describes the location at which the length of
16945 the string can be found. The size of the length field can be
16946 specified with one of the attributes below. */
16947 struct type
*prop_type
;
16948 struct attribute
*len
16949 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16950 if (len
== nullptr)
16951 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16952 if (len
!= nullptr && len
->form_is_constant ())
16954 /* Pass 0 as the default as we know this attribute is constant
16955 and the default value will not be returned. */
16956 LONGEST sz
= len
->constant_value (0);
16957 prop_type
= cu
->per_cu
->int_type (sz
, true);
16961 /* If the size is not specified then we assume it is the size of
16962 an address on this target. */
16963 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16966 /* Convert the attribute into a dynamic property. */
16967 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16970 length_is_constant
= false;
16972 else if (attr
!= nullptr)
16974 /* This DW_AT_string_length just contains the length with no
16975 indirection. There's no need to create a dynamic property in this
16976 case. Pass 0 for the default value as we know it will not be
16977 returned in this case. */
16978 length
= attr
->constant_value (0);
16980 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16982 /* We don't currently support non-constant byte sizes for strings. */
16983 length
= attr
->constant_value (1);
16987 /* Use 1 as a fallback length if we have nothing else. */
16991 index_type
= objfile_type (objfile
)->builtin_int
;
16992 if (length_is_constant
)
16993 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16996 struct dynamic_prop low_bound
;
16998 low_bound
.kind
= PROP_CONST
;
16999 low_bound
.data
.const_val
= 1;
17000 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17002 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17003 type
= create_string_type (NULL
, char_type
, range_type
);
17005 return set_die_type (die
, type
, cu
);
17008 /* Assuming that DIE corresponds to a function, returns nonzero
17009 if the function is prototyped. */
17012 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17014 struct attribute
*attr
;
17016 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17017 if (attr
&& (DW_UNSND (attr
) != 0))
17020 /* The DWARF standard implies that the DW_AT_prototyped attribute
17021 is only meaningful for C, but the concept also extends to other
17022 languages that allow unprototyped functions (Eg: Objective C).
17023 For all other languages, assume that functions are always
17025 if (cu
->language
!= language_c
17026 && cu
->language
!= language_objc
17027 && cu
->language
!= language_opencl
)
17030 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17031 prototyped and unprototyped functions; default to prototyped,
17032 since that is more common in modern code (and RealView warns
17033 about unprototyped functions). */
17034 if (producer_is_realview (cu
->producer
))
17040 /* Handle DIES due to C code like:
17044 int (*funcp)(int a, long l);
17048 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17050 static struct type
*
17051 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17053 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17054 struct type
*type
; /* Type that this function returns. */
17055 struct type
*ftype
; /* Function that returns above type. */
17056 struct attribute
*attr
;
17058 type
= die_type (die
, cu
);
17060 /* The die_type call above may have already set the type for this DIE. */
17061 ftype
= get_die_type (die
, cu
);
17065 ftype
= lookup_function_type (type
);
17067 if (prototyped_function_p (die
, cu
))
17068 TYPE_PROTOTYPED (ftype
) = 1;
17070 /* Store the calling convention in the type if it's available in
17071 the subroutine die. Otherwise set the calling convention to
17072 the default value DW_CC_normal. */
17073 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17074 if (attr
!= nullptr
17075 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17076 TYPE_CALLING_CONVENTION (ftype
)
17077 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17078 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17079 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17081 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17083 /* Record whether the function returns normally to its caller or not
17084 if the DWARF producer set that information. */
17085 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17086 if (attr
&& (DW_UNSND (attr
) != 0))
17087 TYPE_NO_RETURN (ftype
) = 1;
17089 /* We need to add the subroutine type to the die immediately so
17090 we don't infinitely recurse when dealing with parameters
17091 declared as the same subroutine type. */
17092 set_die_type (die
, ftype
, cu
);
17094 if (die
->child
!= NULL
)
17096 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17097 struct die_info
*child_die
;
17098 int nparams
, iparams
;
17100 /* Count the number of parameters.
17101 FIXME: GDB currently ignores vararg functions, but knows about
17102 vararg member functions. */
17104 child_die
= die
->child
;
17105 while (child_die
&& child_die
->tag
)
17107 if (child_die
->tag
== DW_TAG_formal_parameter
)
17109 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17110 TYPE_VARARGS (ftype
) = 1;
17111 child_die
= child_die
->sibling
;
17114 /* Allocate storage for parameters and fill them in. */
17115 ftype
->set_num_fields (nparams
);
17117 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17119 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17120 even if we error out during the parameters reading below. */
17121 for (iparams
= 0; iparams
< nparams
; iparams
++)
17122 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17125 child_die
= die
->child
;
17126 while (child_die
&& child_die
->tag
)
17128 if (child_die
->tag
== DW_TAG_formal_parameter
)
17130 struct type
*arg_type
;
17132 /* DWARF version 2 has no clean way to discern C++
17133 static and non-static member functions. G++ helps
17134 GDB by marking the first parameter for non-static
17135 member functions (which is the this pointer) as
17136 artificial. We pass this information to
17137 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17139 DWARF version 3 added DW_AT_object_pointer, which GCC
17140 4.5 does not yet generate. */
17141 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17142 if (attr
!= nullptr)
17143 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17145 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17146 arg_type
= die_type (child_die
, cu
);
17148 /* RealView does not mark THIS as const, which the testsuite
17149 expects. GCC marks THIS as const in method definitions,
17150 but not in the class specifications (GCC PR 43053). */
17151 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17152 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17155 struct dwarf2_cu
*arg_cu
= cu
;
17156 const char *name
= dwarf2_name (child_die
, cu
);
17158 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17159 if (attr
!= nullptr)
17161 /* If the compiler emits this, use it. */
17162 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17165 else if (name
&& strcmp (name
, "this") == 0)
17166 /* Function definitions will have the argument names. */
17168 else if (name
== NULL
&& iparams
== 0)
17169 /* Declarations may not have the names, so like
17170 elsewhere in GDB, assume an artificial first
17171 argument is "this". */
17175 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17179 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17182 child_die
= child_die
->sibling
;
17189 static struct type
*
17190 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17192 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17193 const char *name
= NULL
;
17194 struct type
*this_type
, *target_type
;
17196 name
= dwarf2_full_name (NULL
, die
, cu
);
17197 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17198 TYPE_TARGET_STUB (this_type
) = 1;
17199 set_die_type (die
, this_type
, cu
);
17200 target_type
= die_type (die
, cu
);
17201 if (target_type
!= this_type
)
17202 TYPE_TARGET_TYPE (this_type
) = target_type
;
17205 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17206 spec and cause infinite loops in GDB. */
17207 complaint (_("Self-referential DW_TAG_typedef "
17208 "- DIE at %s [in module %s]"),
17209 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17210 TYPE_TARGET_TYPE (this_type
) = NULL
;
17214 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17215 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17216 Handle these by just returning the target type, rather than
17217 constructing an anonymous typedef type and trying to handle this
17219 set_die_type (die
, target_type
, cu
);
17220 return target_type
;
17225 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17226 (which may be different from NAME) to the architecture back-end to allow
17227 it to guess the correct format if necessary. */
17229 static struct type
*
17230 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17231 const char *name_hint
, enum bfd_endian byte_order
)
17233 struct gdbarch
*gdbarch
= objfile
->arch ();
17234 const struct floatformat
**format
;
17237 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17239 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17241 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17246 /* Allocate an integer type of size BITS and name NAME. */
17248 static struct type
*
17249 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17250 int bits
, int unsigned_p
, const char *name
)
17254 /* Versions of Intel's C Compiler generate an integer type called "void"
17255 instead of using DW_TAG_unspecified_type. This has been seen on
17256 at least versions 14, 17, and 18. */
17257 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17258 && strcmp (name
, "void") == 0)
17259 type
= objfile_type (objfile
)->builtin_void
;
17261 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17266 /* Initialise and return a floating point type of size BITS suitable for
17267 use as a component of a complex number. The NAME_HINT is passed through
17268 when initialising the floating point type and is the name of the complex
17271 As DWARF doesn't currently provide an explicit name for the components
17272 of a complex number, but it can be helpful to have these components
17273 named, we try to select a suitable name based on the size of the
17275 static struct type
*
17276 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17277 struct objfile
*objfile
,
17278 int bits
, const char *name_hint
,
17279 enum bfd_endian byte_order
)
17281 gdbarch
*gdbarch
= objfile
->arch ();
17282 struct type
*tt
= nullptr;
17284 /* Try to find a suitable floating point builtin type of size BITS.
17285 We're going to use the name of this type as the name for the complex
17286 target type that we are about to create. */
17287 switch (cu
->language
)
17289 case language_fortran
:
17293 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17296 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17298 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17300 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17308 tt
= builtin_type (gdbarch
)->builtin_float
;
17311 tt
= builtin_type (gdbarch
)->builtin_double
;
17313 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17315 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17321 /* If the type we found doesn't match the size we were looking for, then
17322 pretend we didn't find a type at all, the complex target type we
17323 create will then be nameless. */
17324 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17327 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17328 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17331 /* Find a representation of a given base type and install
17332 it in the TYPE field of the die. */
17334 static struct type
*
17335 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17337 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17339 struct attribute
*attr
;
17340 int encoding
= 0, bits
= 0;
17344 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17345 if (attr
!= nullptr)
17346 encoding
= DW_UNSND (attr
);
17347 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17348 if (attr
!= nullptr)
17349 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17350 name
= dwarf2_name (die
, cu
);
17352 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17354 arch
= objfile
->arch ();
17355 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17357 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17360 int endianity
= DW_UNSND (attr
);
17365 byte_order
= BFD_ENDIAN_BIG
;
17367 case DW_END_little
:
17368 byte_order
= BFD_ENDIAN_LITTLE
;
17371 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17378 case DW_ATE_address
:
17379 /* Turn DW_ATE_address into a void * pointer. */
17380 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17381 type
= init_pointer_type (objfile
, bits
, name
, type
);
17383 case DW_ATE_boolean
:
17384 type
= init_boolean_type (objfile
, bits
, 1, name
);
17386 case DW_ATE_complex_float
:
17387 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17389 if (type
->code () == TYPE_CODE_ERROR
)
17391 if (name
== nullptr)
17393 struct obstack
*obstack
17394 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17395 name
= obconcat (obstack
, "_Complex ", type
->name (),
17398 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17401 type
= init_complex_type (name
, type
);
17403 case DW_ATE_decimal_float
:
17404 type
= init_decfloat_type (objfile
, bits
, name
);
17407 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17409 case DW_ATE_signed
:
17410 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17412 case DW_ATE_unsigned
:
17413 if (cu
->language
== language_fortran
17415 && startswith (name
, "character("))
17416 type
= init_character_type (objfile
, bits
, 1, name
);
17418 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17420 case DW_ATE_signed_char
:
17421 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17422 || cu
->language
== language_pascal
17423 || cu
->language
== language_fortran
)
17424 type
= init_character_type (objfile
, bits
, 0, name
);
17426 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17428 case DW_ATE_unsigned_char
:
17429 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17430 || cu
->language
== language_pascal
17431 || cu
->language
== language_fortran
17432 || cu
->language
== language_rust
)
17433 type
= init_character_type (objfile
, bits
, 1, name
);
17435 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17440 type
= builtin_type (arch
)->builtin_char16
;
17441 else if (bits
== 32)
17442 type
= builtin_type (arch
)->builtin_char32
;
17445 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17447 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17449 return set_die_type (die
, type
, cu
);
17454 complaint (_("unsupported DW_AT_encoding: '%s'"),
17455 dwarf_type_encoding_name (encoding
));
17456 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17460 if (name
&& strcmp (name
, "char") == 0)
17461 TYPE_NOSIGN (type
) = 1;
17463 maybe_set_alignment (cu
, die
, type
);
17465 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17467 return set_die_type (die
, type
, cu
);
17470 /* Parse dwarf attribute if it's a block, reference or constant and put the
17471 resulting value of the attribute into struct bound_prop.
17472 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17475 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17476 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17477 struct type
*default_type
)
17479 struct dwarf2_property_baton
*baton
;
17480 dwarf2_per_objfile
*per_objfile
= cu
->per_cu
->dwarf2_per_objfile
;
17481 struct objfile
*objfile
= per_objfile
->objfile
;
17482 struct obstack
*obstack
= &objfile
->objfile_obstack
;
17484 gdb_assert (default_type
!= NULL
);
17486 if (attr
== NULL
|| prop
== NULL
)
17489 if (attr
->form_is_block ())
17491 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17492 baton
->property_type
= default_type
;
17493 baton
->locexpr
.per_cu
= cu
->per_cu
;
17494 baton
->locexpr
.per_objfile
= per_objfile
;
17495 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17496 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17497 switch (attr
->name
)
17499 case DW_AT_string_length
:
17500 baton
->locexpr
.is_reference
= true;
17503 baton
->locexpr
.is_reference
= false;
17506 prop
->data
.baton
= baton
;
17507 prop
->kind
= PROP_LOCEXPR
;
17508 gdb_assert (prop
->data
.baton
!= NULL
);
17510 else if (attr
->form_is_ref ())
17512 struct dwarf2_cu
*target_cu
= cu
;
17513 struct die_info
*target_die
;
17514 struct attribute
*target_attr
;
17516 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17517 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17518 if (target_attr
== NULL
)
17519 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17521 if (target_attr
== NULL
)
17524 switch (target_attr
->name
)
17526 case DW_AT_location
:
17527 if (target_attr
->form_is_section_offset ())
17529 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17530 baton
->property_type
= die_type (target_die
, target_cu
);
17531 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17532 prop
->data
.baton
= baton
;
17533 prop
->kind
= PROP_LOCLIST
;
17534 gdb_assert (prop
->data
.baton
!= NULL
);
17536 else if (target_attr
->form_is_block ())
17538 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17539 baton
->property_type
= die_type (target_die
, target_cu
);
17540 baton
->locexpr
.per_cu
= cu
->per_cu
;
17541 baton
->locexpr
.per_objfile
= per_objfile
;
17542 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17543 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17544 baton
->locexpr
.is_reference
= true;
17545 prop
->data
.baton
= baton
;
17546 prop
->kind
= PROP_LOCEXPR
;
17547 gdb_assert (prop
->data
.baton
!= NULL
);
17551 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17552 "dynamic property");
17556 case DW_AT_data_member_location
:
17560 if (!handle_data_member_location (target_die
, target_cu
,
17564 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17565 baton
->property_type
= read_type_die (target_die
->parent
,
17567 baton
->offset_info
.offset
= offset
;
17568 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17569 prop
->data
.baton
= baton
;
17570 prop
->kind
= PROP_ADDR_OFFSET
;
17575 else if (attr
->form_is_constant ())
17577 prop
->data
.const_val
= attr
->constant_value (0);
17578 prop
->kind
= PROP_CONST
;
17582 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17583 dwarf2_name (die
, cu
));
17593 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17595 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17596 struct type
*int_type
;
17598 /* Helper macro to examine the various builtin types. */
17599 #define TRY_TYPE(F) \
17600 int_type = (unsigned_p \
17601 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17602 : objfile_type (objfile)->builtin_ ## F); \
17603 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17610 TRY_TYPE (long_long
);
17614 gdb_assert_not_reached ("unable to find suitable integer type");
17620 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17622 int addr_size
= this->addr_size ();
17623 return int_type (addr_size
, unsigned_p
);
17626 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17627 present (which is valid) then compute the default type based on the
17628 compilation units address size. */
17630 static struct type
*
17631 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17633 struct type
*index_type
= die_type (die
, cu
);
17635 /* Dwarf-2 specifications explicitly allows to create subrange types
17636 without specifying a base type.
17637 In that case, the base type must be set to the type of
17638 the lower bound, upper bound or count, in that order, if any of these
17639 three attributes references an object that has a type.
17640 If no base type is found, the Dwarf-2 specifications say that
17641 a signed integer type of size equal to the size of an address should
17643 For the following C code: `extern char gdb_int [];'
17644 GCC produces an empty range DIE.
17645 FIXME: muller/2010-05-28: Possible references to object for low bound,
17646 high bound or count are not yet handled by this code. */
17647 if (index_type
->code () == TYPE_CODE_VOID
)
17648 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17653 /* Read the given DW_AT_subrange DIE. */
17655 static struct type
*
17656 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17658 struct type
*base_type
, *orig_base_type
;
17659 struct type
*range_type
;
17660 struct attribute
*attr
;
17661 struct dynamic_prop low
, high
;
17662 int low_default_is_valid
;
17663 int high_bound_is_count
= 0;
17665 ULONGEST negative_mask
;
17667 orig_base_type
= read_subrange_index_type (die
, cu
);
17669 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17670 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17671 creating the range type, but we use the result of check_typedef
17672 when examining properties of the type. */
17673 base_type
= check_typedef (orig_base_type
);
17675 /* The die_type call above may have already set the type for this DIE. */
17676 range_type
= get_die_type (die
, cu
);
17680 low
.kind
= PROP_CONST
;
17681 high
.kind
= PROP_CONST
;
17682 high
.data
.const_val
= 0;
17684 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17685 omitting DW_AT_lower_bound. */
17686 switch (cu
->language
)
17689 case language_cplus
:
17690 low
.data
.const_val
= 0;
17691 low_default_is_valid
= 1;
17693 case language_fortran
:
17694 low
.data
.const_val
= 1;
17695 low_default_is_valid
= 1;
17698 case language_objc
:
17699 case language_rust
:
17700 low
.data
.const_val
= 0;
17701 low_default_is_valid
= (cu
->header
.version
>= 4);
17705 case language_pascal
:
17706 low
.data
.const_val
= 1;
17707 low_default_is_valid
= (cu
->header
.version
>= 4);
17710 low
.data
.const_val
= 0;
17711 low_default_is_valid
= 0;
17715 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17716 if (attr
!= nullptr)
17717 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17718 else if (!low_default_is_valid
)
17719 complaint (_("Missing DW_AT_lower_bound "
17720 "- DIE at %s [in module %s]"),
17721 sect_offset_str (die
->sect_off
),
17722 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17724 struct attribute
*attr_ub
, *attr_count
;
17725 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17726 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17728 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17729 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17731 /* If bounds are constant do the final calculation here. */
17732 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17733 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17735 high_bound_is_count
= 1;
17739 if (attr_ub
!= NULL
)
17740 complaint (_("Unresolved DW_AT_upper_bound "
17741 "- DIE at %s [in module %s]"),
17742 sect_offset_str (die
->sect_off
),
17743 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17744 if (attr_count
!= NULL
)
17745 complaint (_("Unresolved DW_AT_count "
17746 "- DIE at %s [in module %s]"),
17747 sect_offset_str (die
->sect_off
),
17748 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17753 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17754 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17755 bias
= bias_attr
->constant_value (0);
17757 /* Normally, the DWARF producers are expected to use a signed
17758 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17759 But this is unfortunately not always the case, as witnessed
17760 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17761 is used instead. To work around that ambiguity, we treat
17762 the bounds as signed, and thus sign-extend their values, when
17763 the base type is signed. */
17765 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17766 if (low
.kind
== PROP_CONST
17767 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17768 low
.data
.const_val
|= negative_mask
;
17769 if (high
.kind
== PROP_CONST
17770 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17771 high
.data
.const_val
|= negative_mask
;
17773 /* Check for bit and byte strides. */
17774 struct dynamic_prop byte_stride_prop
;
17775 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17776 if (attr_byte_stride
!= nullptr)
17778 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17779 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17783 struct dynamic_prop bit_stride_prop
;
17784 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17785 if (attr_bit_stride
!= nullptr)
17787 /* It only makes sense to have either a bit or byte stride. */
17788 if (attr_byte_stride
!= nullptr)
17790 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17791 "- DIE at %s [in module %s]"),
17792 sect_offset_str (die
->sect_off
),
17793 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17794 attr_bit_stride
= nullptr;
17798 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17799 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17804 if (attr_byte_stride
!= nullptr
17805 || attr_bit_stride
!= nullptr)
17807 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17808 struct dynamic_prop
*stride
17809 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17812 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17813 &high
, bias
, stride
, byte_stride_p
);
17816 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17818 if (high_bound_is_count
)
17819 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17821 /* Ada expects an empty array on no boundary attributes. */
17822 if (attr
== NULL
&& cu
->language
!= language_ada
)
17823 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17825 name
= dwarf2_name (die
, cu
);
17827 range_type
->set_name (name
);
17829 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17830 if (attr
!= nullptr)
17831 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17833 maybe_set_alignment (cu
, die
, range_type
);
17835 set_die_type (die
, range_type
, cu
);
17837 /* set_die_type should be already done. */
17838 set_descriptive_type (range_type
, die
, cu
);
17843 static struct type
*
17844 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17848 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17850 type
->set_name (dwarf2_name (die
, cu
));
17852 /* In Ada, an unspecified type is typically used when the description
17853 of the type is deferred to a different unit. When encountering
17854 such a type, we treat it as a stub, and try to resolve it later on,
17856 if (cu
->language
== language_ada
)
17857 TYPE_STUB (type
) = 1;
17859 return set_die_type (die
, type
, cu
);
17862 /* Read a single die and all its descendents. Set the die's sibling
17863 field to NULL; set other fields in the die correctly, and set all
17864 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17865 location of the info_ptr after reading all of those dies. PARENT
17866 is the parent of the die in question. */
17868 static struct die_info
*
17869 read_die_and_children (const struct die_reader_specs
*reader
,
17870 const gdb_byte
*info_ptr
,
17871 const gdb_byte
**new_info_ptr
,
17872 struct die_info
*parent
)
17874 struct die_info
*die
;
17875 const gdb_byte
*cur_ptr
;
17877 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17880 *new_info_ptr
= cur_ptr
;
17883 store_in_ref_table (die
, reader
->cu
);
17885 if (die
->has_children
)
17886 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17890 *new_info_ptr
= cur_ptr
;
17893 die
->sibling
= NULL
;
17894 die
->parent
= parent
;
17898 /* Read a die, all of its descendents, and all of its siblings; set
17899 all of the fields of all of the dies correctly. Arguments are as
17900 in read_die_and_children. */
17902 static struct die_info
*
17903 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17904 const gdb_byte
*info_ptr
,
17905 const gdb_byte
**new_info_ptr
,
17906 struct die_info
*parent
)
17908 struct die_info
*first_die
, *last_sibling
;
17909 const gdb_byte
*cur_ptr
;
17911 cur_ptr
= info_ptr
;
17912 first_die
= last_sibling
= NULL
;
17916 struct die_info
*die
17917 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17921 *new_info_ptr
= cur_ptr
;
17928 last_sibling
->sibling
= die
;
17930 last_sibling
= die
;
17934 /* Read a die, all of its descendents, and all of its siblings; set
17935 all of the fields of all of the dies correctly. Arguments are as
17936 in read_die_and_children.
17937 This the main entry point for reading a DIE and all its children. */
17939 static struct die_info
*
17940 read_die_and_siblings (const struct die_reader_specs
*reader
,
17941 const gdb_byte
*info_ptr
,
17942 const gdb_byte
**new_info_ptr
,
17943 struct die_info
*parent
)
17945 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17946 new_info_ptr
, parent
);
17948 if (dwarf_die_debug
)
17950 fprintf_unfiltered (gdb_stdlog
,
17951 "Read die from %s@0x%x of %s:\n",
17952 reader
->die_section
->get_name (),
17953 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17954 bfd_get_filename (reader
->abfd
));
17955 dump_die (die
, dwarf_die_debug
);
17961 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17963 The caller is responsible for filling in the extra attributes
17964 and updating (*DIEP)->num_attrs.
17965 Set DIEP to point to a newly allocated die with its information,
17966 except for its child, sibling, and parent fields. */
17968 static const gdb_byte
*
17969 read_full_die_1 (const struct die_reader_specs
*reader
,
17970 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17971 int num_extra_attrs
)
17973 unsigned int abbrev_number
, bytes_read
, i
;
17974 struct abbrev_info
*abbrev
;
17975 struct die_info
*die
;
17976 struct dwarf2_cu
*cu
= reader
->cu
;
17977 bfd
*abfd
= reader
->abfd
;
17979 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17980 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17981 info_ptr
+= bytes_read
;
17982 if (!abbrev_number
)
17988 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17990 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17992 bfd_get_filename (abfd
));
17994 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17995 die
->sect_off
= sect_off
;
17996 die
->tag
= abbrev
->tag
;
17997 die
->abbrev
= abbrev_number
;
17998 die
->has_children
= abbrev
->has_children
;
18000 /* Make the result usable.
18001 The caller needs to update num_attrs after adding the extra
18003 die
->num_attrs
= abbrev
->num_attrs
;
18005 std::vector
<int> indexes_that_need_reprocess
;
18006 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18008 bool need_reprocess
;
18010 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18011 info_ptr
, &need_reprocess
);
18012 if (need_reprocess
)
18013 indexes_that_need_reprocess
.push_back (i
);
18016 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18017 if (attr
!= nullptr)
18018 cu
->str_offsets_base
= DW_UNSND (attr
);
18020 attr
= die
->attr (DW_AT_loclists_base
);
18021 if (attr
!= nullptr)
18022 cu
->loclist_base
= DW_UNSND (attr
);
18024 auto maybe_addr_base
= die
->addr_base ();
18025 if (maybe_addr_base
.has_value ())
18026 cu
->addr_base
= *maybe_addr_base
;
18027 for (int index
: indexes_that_need_reprocess
)
18028 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18033 /* Read a die and all its attributes.
18034 Set DIEP to point to a newly allocated die with its information,
18035 except for its child, sibling, and parent fields. */
18037 static const gdb_byte
*
18038 read_full_die (const struct die_reader_specs
*reader
,
18039 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18041 const gdb_byte
*result
;
18043 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18045 if (dwarf_die_debug
)
18047 fprintf_unfiltered (gdb_stdlog
,
18048 "Read die from %s@0x%x of %s:\n",
18049 reader
->die_section
->get_name (),
18050 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18051 bfd_get_filename (reader
->abfd
));
18052 dump_die (*diep
, dwarf_die_debug
);
18059 /* Returns nonzero if TAG represents a type that we might generate a partial
18063 is_type_tag_for_partial (int tag
)
18068 /* Some types that would be reasonable to generate partial symbols for,
18069 that we don't at present. */
18070 case DW_TAG_array_type
:
18071 case DW_TAG_file_type
:
18072 case DW_TAG_ptr_to_member_type
:
18073 case DW_TAG_set_type
:
18074 case DW_TAG_string_type
:
18075 case DW_TAG_subroutine_type
:
18077 case DW_TAG_base_type
:
18078 case DW_TAG_class_type
:
18079 case DW_TAG_interface_type
:
18080 case DW_TAG_enumeration_type
:
18081 case DW_TAG_structure_type
:
18082 case DW_TAG_subrange_type
:
18083 case DW_TAG_typedef
:
18084 case DW_TAG_union_type
:
18091 /* Load all DIEs that are interesting for partial symbols into memory. */
18093 static struct partial_die_info
*
18094 load_partial_dies (const struct die_reader_specs
*reader
,
18095 const gdb_byte
*info_ptr
, int building_psymtab
)
18097 struct dwarf2_cu
*cu
= reader
->cu
;
18098 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18099 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18100 unsigned int bytes_read
;
18101 unsigned int load_all
= 0;
18102 int nesting_level
= 1;
18107 gdb_assert (cu
->per_cu
!= NULL
);
18108 if (cu
->per_cu
->load_all_dies
)
18112 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18116 &cu
->comp_unit_obstack
,
18117 hashtab_obstack_allocate
,
18118 dummy_obstack_deallocate
);
18122 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18124 /* A NULL abbrev means the end of a series of children. */
18125 if (abbrev
== NULL
)
18127 if (--nesting_level
== 0)
18130 info_ptr
+= bytes_read
;
18131 last_die
= parent_die
;
18132 parent_die
= parent_die
->die_parent
;
18136 /* Check for template arguments. We never save these; if
18137 they're seen, we just mark the parent, and go on our way. */
18138 if (parent_die
!= NULL
18139 && cu
->language
== language_cplus
18140 && (abbrev
->tag
== DW_TAG_template_type_param
18141 || abbrev
->tag
== DW_TAG_template_value_param
))
18143 parent_die
->has_template_arguments
= 1;
18147 /* We don't need a partial DIE for the template argument. */
18148 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18153 /* We only recurse into c++ subprograms looking for template arguments.
18154 Skip their other children. */
18156 && cu
->language
== language_cplus
18157 && parent_die
!= NULL
18158 && parent_die
->tag
== DW_TAG_subprogram
)
18160 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18164 /* Check whether this DIE is interesting enough to save. Normally
18165 we would not be interested in members here, but there may be
18166 later variables referencing them via DW_AT_specification (for
18167 static members). */
18169 && !is_type_tag_for_partial (abbrev
->tag
)
18170 && abbrev
->tag
!= DW_TAG_constant
18171 && abbrev
->tag
!= DW_TAG_enumerator
18172 && abbrev
->tag
!= DW_TAG_subprogram
18173 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18174 && abbrev
->tag
!= DW_TAG_lexical_block
18175 && abbrev
->tag
!= DW_TAG_variable
18176 && abbrev
->tag
!= DW_TAG_namespace
18177 && abbrev
->tag
!= DW_TAG_module
18178 && abbrev
->tag
!= DW_TAG_member
18179 && abbrev
->tag
!= DW_TAG_imported_unit
18180 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18182 /* Otherwise we skip to the next sibling, if any. */
18183 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18187 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18190 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18192 /* This two-pass algorithm for processing partial symbols has a
18193 high cost in cache pressure. Thus, handle some simple cases
18194 here which cover the majority of C partial symbols. DIEs
18195 which neither have specification tags in them, nor could have
18196 specification tags elsewhere pointing at them, can simply be
18197 processed and discarded.
18199 This segment is also optional; scan_partial_symbols and
18200 add_partial_symbol will handle these DIEs if we chain
18201 them in normally. When compilers which do not emit large
18202 quantities of duplicate debug information are more common,
18203 this code can probably be removed. */
18205 /* Any complete simple types at the top level (pretty much all
18206 of them, for a language without namespaces), can be processed
18208 if (parent_die
== NULL
18209 && pdi
.has_specification
== 0
18210 && pdi
.is_declaration
== 0
18211 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18212 || pdi
.tag
== DW_TAG_base_type
18213 || pdi
.tag
== DW_TAG_subrange_type
))
18215 if (building_psymtab
&& pdi
.name
!= NULL
)
18216 add_psymbol_to_list (pdi
.name
, false,
18217 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18218 psymbol_placement::STATIC
,
18219 0, cu
->language
, objfile
);
18220 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18224 /* The exception for DW_TAG_typedef with has_children above is
18225 a workaround of GCC PR debug/47510. In the case of this complaint
18226 type_name_or_error will error on such types later.
18228 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18229 it could not find the child DIEs referenced later, this is checked
18230 above. In correct DWARF DW_TAG_typedef should have no children. */
18232 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18233 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18234 "- DIE at %s [in module %s]"),
18235 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18237 /* If we're at the second level, and we're an enumerator, and
18238 our parent has no specification (meaning possibly lives in a
18239 namespace elsewhere), then we can add the partial symbol now
18240 instead of queueing it. */
18241 if (pdi
.tag
== DW_TAG_enumerator
18242 && parent_die
!= NULL
18243 && parent_die
->die_parent
== NULL
18244 && parent_die
->tag
== DW_TAG_enumeration_type
18245 && parent_die
->has_specification
== 0)
18247 if (pdi
.name
== NULL
)
18248 complaint (_("malformed enumerator DIE ignored"));
18249 else if (building_psymtab
)
18250 add_psymbol_to_list (pdi
.name
, false,
18251 VAR_DOMAIN
, LOC_CONST
, -1,
18252 cu
->language
== language_cplus
18253 ? psymbol_placement::GLOBAL
18254 : psymbol_placement::STATIC
,
18255 0, cu
->language
, objfile
);
18257 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18261 struct partial_die_info
*part_die
18262 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18264 /* We'll save this DIE so link it in. */
18265 part_die
->die_parent
= parent_die
;
18266 part_die
->die_sibling
= NULL
;
18267 part_die
->die_child
= NULL
;
18269 if (last_die
&& last_die
== parent_die
)
18270 last_die
->die_child
= part_die
;
18272 last_die
->die_sibling
= part_die
;
18274 last_die
= part_die
;
18276 if (first_die
== NULL
)
18277 first_die
= part_die
;
18279 /* Maybe add the DIE to the hash table. Not all DIEs that we
18280 find interesting need to be in the hash table, because we
18281 also have the parent/sibling/child chains; only those that we
18282 might refer to by offset later during partial symbol reading.
18284 For now this means things that might have be the target of a
18285 DW_AT_specification, DW_AT_abstract_origin, or
18286 DW_AT_extension. DW_AT_extension will refer only to
18287 namespaces; DW_AT_abstract_origin refers to functions (and
18288 many things under the function DIE, but we do not recurse
18289 into function DIEs during partial symbol reading) and
18290 possibly variables as well; DW_AT_specification refers to
18291 declarations. Declarations ought to have the DW_AT_declaration
18292 flag. It happens that GCC forgets to put it in sometimes, but
18293 only for functions, not for types.
18295 Adding more things than necessary to the hash table is harmless
18296 except for the performance cost. Adding too few will result in
18297 wasted time in find_partial_die, when we reread the compilation
18298 unit with load_all_dies set. */
18301 || abbrev
->tag
== DW_TAG_constant
18302 || abbrev
->tag
== DW_TAG_subprogram
18303 || abbrev
->tag
== DW_TAG_variable
18304 || abbrev
->tag
== DW_TAG_namespace
18305 || part_die
->is_declaration
)
18309 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18310 to_underlying (part_die
->sect_off
),
18315 /* For some DIEs we want to follow their children (if any). For C
18316 we have no reason to follow the children of structures; for other
18317 languages we have to, so that we can get at method physnames
18318 to infer fully qualified class names, for DW_AT_specification,
18319 and for C++ template arguments. For C++, we also look one level
18320 inside functions to find template arguments (if the name of the
18321 function does not already contain the template arguments).
18323 For Ada and Fortran, we need to scan the children of subprograms
18324 and lexical blocks as well because these languages allow the
18325 definition of nested entities that could be interesting for the
18326 debugger, such as nested subprograms for instance. */
18327 if (last_die
->has_children
18329 || last_die
->tag
== DW_TAG_namespace
18330 || last_die
->tag
== DW_TAG_module
18331 || last_die
->tag
== DW_TAG_enumeration_type
18332 || (cu
->language
== language_cplus
18333 && last_die
->tag
== DW_TAG_subprogram
18334 && (last_die
->name
== NULL
18335 || strchr (last_die
->name
, '<') == NULL
))
18336 || (cu
->language
!= language_c
18337 && (last_die
->tag
== DW_TAG_class_type
18338 || last_die
->tag
== DW_TAG_interface_type
18339 || last_die
->tag
== DW_TAG_structure_type
18340 || last_die
->tag
== DW_TAG_union_type
))
18341 || ((cu
->language
== language_ada
18342 || cu
->language
== language_fortran
)
18343 && (last_die
->tag
== DW_TAG_subprogram
18344 || last_die
->tag
== DW_TAG_lexical_block
))))
18347 parent_die
= last_die
;
18351 /* Otherwise we skip to the next sibling, if any. */
18352 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18354 /* Back to the top, do it again. */
18358 partial_die_info::partial_die_info (sect_offset sect_off_
,
18359 struct abbrev_info
*abbrev
)
18360 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18364 /* Read a minimal amount of information into the minimal die structure.
18365 INFO_PTR should point just after the initial uleb128 of a DIE. */
18368 partial_die_info::read (const struct die_reader_specs
*reader
,
18369 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18371 struct dwarf2_cu
*cu
= reader
->cu
;
18372 struct dwarf2_per_objfile
*dwarf2_per_objfile
18373 = cu
->per_cu
->dwarf2_per_objfile
;
18375 int has_low_pc_attr
= 0;
18376 int has_high_pc_attr
= 0;
18377 int high_pc_relative
= 0;
18379 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18382 bool need_reprocess
;
18383 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
18384 info_ptr
, &need_reprocess
);
18385 /* String and address offsets that need to do the reprocessing have
18386 already been read at this point, so there is no need to wait until
18387 the loop terminates to do the reprocessing. */
18388 if (need_reprocess
)
18389 read_attribute_reprocess (reader
, &attr
);
18390 /* Store the data if it is of an attribute we want to keep in a
18391 partial symbol table. */
18397 case DW_TAG_compile_unit
:
18398 case DW_TAG_partial_unit
:
18399 case DW_TAG_type_unit
:
18400 /* Compilation units have a DW_AT_name that is a filename, not
18401 a source language identifier. */
18402 case DW_TAG_enumeration_type
:
18403 case DW_TAG_enumerator
:
18404 /* These tags always have simple identifiers already; no need
18405 to canonicalize them. */
18406 name
= DW_STRING (&attr
);
18410 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18413 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18418 case DW_AT_linkage_name
:
18419 case DW_AT_MIPS_linkage_name
:
18420 /* Note that both forms of linkage name might appear. We
18421 assume they will be the same, and we only store the last
18423 linkage_name
= attr
.value_as_string ();
18424 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
18425 See https://github.com/rust-lang/rust/issues/32925. */
18426 if (cu
->language
== language_rust
&& linkage_name
!= NULL
18427 && strchr (linkage_name
, '{') != NULL
)
18428 linkage_name
= NULL
;
18431 has_low_pc_attr
= 1;
18432 lowpc
= attr
.value_as_address ();
18434 case DW_AT_high_pc
:
18435 has_high_pc_attr
= 1;
18436 highpc
= attr
.value_as_address ();
18437 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18438 high_pc_relative
= 1;
18440 case DW_AT_location
:
18441 /* Support the .debug_loc offsets. */
18442 if (attr
.form_is_block ())
18444 d
.locdesc
= DW_BLOCK (&attr
);
18446 else if (attr
.form_is_section_offset ())
18448 dwarf2_complex_location_expr_complaint ();
18452 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18453 "partial symbol information");
18456 case DW_AT_external
:
18457 is_external
= DW_UNSND (&attr
);
18459 case DW_AT_declaration
:
18460 is_declaration
= DW_UNSND (&attr
);
18465 case DW_AT_abstract_origin
:
18466 case DW_AT_specification
:
18467 case DW_AT_extension
:
18468 has_specification
= 1;
18469 spec_offset
= attr
.get_ref_die_offset ();
18470 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18471 || cu
->per_cu
->is_dwz
);
18473 case DW_AT_sibling
:
18474 /* Ignore absolute siblings, they might point outside of
18475 the current compile unit. */
18476 if (attr
.form
== DW_FORM_ref_addr
)
18477 complaint (_("ignoring absolute DW_AT_sibling"));
18480 const gdb_byte
*buffer
= reader
->buffer
;
18481 sect_offset off
= attr
.get_ref_die_offset ();
18482 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18484 if (sibling_ptr
< info_ptr
)
18485 complaint (_("DW_AT_sibling points backwards"));
18486 else if (sibling_ptr
> reader
->buffer_end
)
18487 reader
->die_section
->overflow_complaint ();
18489 sibling
= sibling_ptr
;
18492 case DW_AT_byte_size
:
18495 case DW_AT_const_value
:
18496 has_const_value
= 1;
18498 case DW_AT_calling_convention
:
18499 /* DWARF doesn't provide a way to identify a program's source-level
18500 entry point. DW_AT_calling_convention attributes are only meant
18501 to describe functions' calling conventions.
18503 However, because it's a necessary piece of information in
18504 Fortran, and before DWARF 4 DW_CC_program was the only
18505 piece of debugging information whose definition refers to
18506 a 'main program' at all, several compilers marked Fortran
18507 main programs with DW_CC_program --- even when those
18508 functions use the standard calling conventions.
18510 Although DWARF now specifies a way to provide this
18511 information, we support this practice for backward
18513 if (DW_UNSND (&attr
) == DW_CC_program
18514 && cu
->language
== language_fortran
)
18515 main_subprogram
= 1;
18518 if (DW_UNSND (&attr
) == DW_INL_inlined
18519 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18520 may_be_inlined
= 1;
18524 if (tag
== DW_TAG_imported_unit
)
18526 d
.sect_off
= attr
.get_ref_die_offset ();
18527 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18528 || cu
->per_cu
->is_dwz
);
18532 case DW_AT_main_subprogram
:
18533 main_subprogram
= DW_UNSND (&attr
);
18538 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18539 but that requires a full DIE, so instead we just
18541 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18542 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18543 + (need_ranges_base
18547 /* Value of the DW_AT_ranges attribute is the offset in the
18548 .debug_ranges section. */
18549 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18560 /* For Ada, if both the name and the linkage name appear, we prefer
18561 the latter. This lets "catch exception" work better, regardless
18562 of the order in which the name and linkage name were emitted.
18563 Really, though, this is just a workaround for the fact that gdb
18564 doesn't store both the name and the linkage name. */
18565 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18566 name
= linkage_name
;
18568 if (high_pc_relative
)
18571 if (has_low_pc_attr
&& has_high_pc_attr
)
18573 /* When using the GNU linker, .gnu.linkonce. sections are used to
18574 eliminate duplicate copies of functions and vtables and such.
18575 The linker will arbitrarily choose one and discard the others.
18576 The AT_*_pc values for such functions refer to local labels in
18577 these sections. If the section from that file was discarded, the
18578 labels are not in the output, so the relocs get a value of 0.
18579 If this is a discarded function, mark the pc bounds as invalid,
18580 so that GDB will ignore it. */
18581 if (lowpc
== 0 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
18583 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18584 struct gdbarch
*gdbarch
= objfile
->arch ();
18586 complaint (_("DW_AT_low_pc %s is zero "
18587 "for DIE at %s [in module %s]"),
18588 paddress (gdbarch
, lowpc
),
18589 sect_offset_str (sect_off
),
18590 objfile_name (objfile
));
18592 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18593 else if (lowpc
>= highpc
)
18595 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18596 struct gdbarch
*gdbarch
= objfile
->arch ();
18598 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18599 "for DIE at %s [in module %s]"),
18600 paddress (gdbarch
, lowpc
),
18601 paddress (gdbarch
, highpc
),
18602 sect_offset_str (sect_off
),
18603 objfile_name (objfile
));
18612 /* Find a cached partial DIE at OFFSET in CU. */
18614 struct partial_die_info
*
18615 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18617 struct partial_die_info
*lookup_die
= NULL
;
18618 struct partial_die_info
part_die (sect_off
);
18620 lookup_die
= ((struct partial_die_info
*)
18621 htab_find_with_hash (partial_dies
, &part_die
,
18622 to_underlying (sect_off
)));
18627 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18628 except in the case of .debug_types DIEs which do not reference
18629 outside their CU (they do however referencing other types via
18630 DW_FORM_ref_sig8). */
18632 static const struct cu_partial_die_info
18633 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18635 struct dwarf2_per_objfile
*dwarf2_per_objfile
18636 = cu
->per_cu
->dwarf2_per_objfile
;
18637 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18638 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18639 struct partial_die_info
*pd
= NULL
;
18641 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18642 && cu
->header
.offset_in_cu_p (sect_off
))
18644 pd
= cu
->find_partial_die (sect_off
);
18647 /* We missed recording what we needed.
18648 Load all dies and try again. */
18649 per_cu
= cu
->per_cu
;
18653 /* TUs don't reference other CUs/TUs (except via type signatures). */
18654 if (cu
->per_cu
->is_debug_types
)
18656 error (_("Dwarf Error: Type Unit at offset %s contains"
18657 " external reference to offset %s [in module %s].\n"),
18658 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18659 bfd_get_filename (objfile
->obfd
));
18661 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18662 dwarf2_per_objfile
);
18664 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18665 load_partial_comp_unit (per_cu
);
18667 per_cu
->cu
->last_used
= 0;
18668 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18671 /* If we didn't find it, and not all dies have been loaded,
18672 load them all and try again. */
18674 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18676 per_cu
->load_all_dies
= 1;
18678 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18679 THIS_CU->cu may already be in use. So we can't just free it and
18680 replace its DIEs with the ones we read in. Instead, we leave those
18681 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18682 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18684 load_partial_comp_unit (per_cu
);
18686 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18690 internal_error (__FILE__
, __LINE__
,
18691 _("could not find partial DIE %s "
18692 "in cache [from module %s]\n"),
18693 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18694 return { per_cu
->cu
, pd
};
18697 /* See if we can figure out if the class lives in a namespace. We do
18698 this by looking for a member function; its demangled name will
18699 contain namespace info, if there is any. */
18702 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18703 struct dwarf2_cu
*cu
)
18705 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18706 what template types look like, because the demangler
18707 frequently doesn't give the same name as the debug info. We
18708 could fix this by only using the demangled name to get the
18709 prefix (but see comment in read_structure_type). */
18711 struct partial_die_info
*real_pdi
;
18712 struct partial_die_info
*child_pdi
;
18714 /* If this DIE (this DIE's specification, if any) has a parent, then
18715 we should not do this. We'll prepend the parent's fully qualified
18716 name when we create the partial symbol. */
18718 real_pdi
= struct_pdi
;
18719 while (real_pdi
->has_specification
)
18721 auto res
= find_partial_die (real_pdi
->spec_offset
,
18722 real_pdi
->spec_is_dwz
, cu
);
18723 real_pdi
= res
.pdi
;
18727 if (real_pdi
->die_parent
!= NULL
)
18730 for (child_pdi
= struct_pdi
->die_child
;
18732 child_pdi
= child_pdi
->die_sibling
)
18734 if (child_pdi
->tag
== DW_TAG_subprogram
18735 && child_pdi
->linkage_name
!= NULL
)
18737 gdb::unique_xmalloc_ptr
<char> actual_class_name
18738 (language_class_name_from_physname (cu
->language_defn
,
18739 child_pdi
->linkage_name
));
18740 if (actual_class_name
!= NULL
)
18742 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18743 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18750 /* Return true if a DIE with TAG may have the DW_AT_const_value
18754 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18758 case DW_TAG_constant
:
18759 case DW_TAG_enumerator
:
18760 case DW_TAG_formal_parameter
:
18761 case DW_TAG_template_value_param
:
18762 case DW_TAG_variable
:
18770 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18772 /* Once we've fixed up a die, there's no point in doing so again.
18773 This also avoids a memory leak if we were to call
18774 guess_partial_die_structure_name multiple times. */
18778 /* If we found a reference attribute and the DIE has no name, try
18779 to find a name in the referred to DIE. */
18781 if (name
== NULL
&& has_specification
)
18783 struct partial_die_info
*spec_die
;
18785 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18786 spec_die
= res
.pdi
;
18789 spec_die
->fixup (cu
);
18791 if (spec_die
->name
)
18793 name
= spec_die
->name
;
18795 /* Copy DW_AT_external attribute if it is set. */
18796 if (spec_die
->is_external
)
18797 is_external
= spec_die
->is_external
;
18801 if (!has_const_value
&& has_specification
18802 && can_have_DW_AT_const_value_p (tag
))
18804 struct partial_die_info
*spec_die
;
18806 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18807 spec_die
= res
.pdi
;
18810 spec_die
->fixup (cu
);
18812 if (spec_die
->has_const_value
)
18814 /* Copy DW_AT_const_value attribute if it is set. */
18815 has_const_value
= spec_die
->has_const_value
;
18819 /* Set default names for some unnamed DIEs. */
18821 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18822 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18824 /* If there is no parent die to provide a namespace, and there are
18825 children, see if we can determine the namespace from their linkage
18827 if (cu
->language
== language_cplus
18828 && !cu
->per_cu
->dwarf2_per_objfile
->per_bfd
->types
.empty ()
18829 && die_parent
== NULL
18831 && (tag
== DW_TAG_class_type
18832 || tag
== DW_TAG_structure_type
18833 || tag
== DW_TAG_union_type
))
18834 guess_partial_die_structure_name (this, cu
);
18836 /* GCC might emit a nameless struct or union that has a linkage
18837 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18839 && (tag
== DW_TAG_class_type
18840 || tag
== DW_TAG_interface_type
18841 || tag
== DW_TAG_structure_type
18842 || tag
== DW_TAG_union_type
)
18843 && linkage_name
!= NULL
)
18845 gdb::unique_xmalloc_ptr
<char> demangled
18846 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18847 if (demangled
!= nullptr)
18851 /* Strip any leading namespaces/classes, keep only the base name.
18852 DW_AT_name for named DIEs does not contain the prefixes. */
18853 base
= strrchr (demangled
.get (), ':');
18854 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18857 base
= demangled
.get ();
18859 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18860 name
= objfile
->intern (base
);
18867 /* Read the .debug_loclists header contents from the given SECTION in the
18870 read_loclist_header (struct loclist_header
*header
,
18871 struct dwarf2_section_info
*section
)
18873 unsigned int bytes_read
;
18874 bfd
*abfd
= section
->get_bfd_owner ();
18875 const gdb_byte
*info_ptr
= section
->buffer
;
18876 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18877 info_ptr
+= bytes_read
;
18878 header
->version
= read_2_bytes (abfd
, info_ptr
);
18880 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18882 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18884 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18887 /* Return the DW_AT_loclists_base value for the CU. */
18889 lookup_loclist_base (struct dwarf2_cu
*cu
)
18891 /* For the .dwo unit, the loclist_base points to the first offset following
18892 the header. The header consists of the following entities-
18893 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18895 2. version (2 bytes)
18896 3. address size (1 byte)
18897 4. segment selector size (1 byte)
18898 5. offset entry count (4 bytes)
18899 These sizes are derived as per the DWARFv5 standard. */
18900 if (cu
->dwo_unit
!= nullptr)
18902 if (cu
->header
.initial_length_size
== 4)
18903 return LOCLIST_HEADER_SIZE32
;
18904 return LOCLIST_HEADER_SIZE64
;
18906 return cu
->loclist_base
;
18909 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18910 array of offsets in the .debug_loclists section. */
18912 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18914 struct dwarf2_per_objfile
*dwarf2_per_objfile
18915 = cu
->per_cu
->dwarf2_per_objfile
;
18916 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18917 bfd
*abfd
= objfile
->obfd
;
18918 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18919 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18921 section
->read (objfile
);
18922 if (section
->buffer
== NULL
)
18923 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18924 "section [in module %s]"), objfile_name (objfile
));
18925 struct loclist_header header
;
18926 read_loclist_header (&header
, section
);
18927 if (loclist_index
>= header
.offset_entry_count
)
18928 complaint (_("DW_FORM_loclistx pointing outside of "
18929 ".debug_loclists offset array [in module %s]"),
18930 objfile_name (objfile
));
18931 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18933 complaint (_("DW_FORM_loclistx pointing outside of "
18934 ".debug_loclists section [in module %s]"),
18935 objfile_name (objfile
));
18936 const gdb_byte
*info_ptr
18937 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18939 if (cu
->header
.offset_size
== 4)
18940 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18942 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18945 /* Process the attributes that had to be skipped in the first round. These
18946 attributes are the ones that need str_offsets_base or addr_base attributes.
18947 They could not have been processed in the first round, because at the time
18948 the values of str_offsets_base or addr_base may not have been known. */
18950 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18951 struct attribute
*attr
)
18953 struct dwarf2_cu
*cu
= reader
->cu
;
18954 switch (attr
->form
)
18956 case DW_FORM_addrx
:
18957 case DW_FORM_GNU_addr_index
:
18958 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18960 case DW_FORM_loclistx
:
18961 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
18964 case DW_FORM_strx1
:
18965 case DW_FORM_strx2
:
18966 case DW_FORM_strx3
:
18967 case DW_FORM_strx4
:
18968 case DW_FORM_GNU_str_index
:
18970 unsigned int str_index
= DW_UNSND (attr
);
18971 if (reader
->dwo_file
!= NULL
)
18973 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18974 DW_STRING_IS_CANONICAL (attr
) = 0;
18978 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18979 DW_STRING_IS_CANONICAL (attr
) = 0;
18984 gdb_assert_not_reached (_("Unexpected DWARF form."));
18988 /* Read an attribute value described by an attribute form. */
18990 static const gdb_byte
*
18991 read_attribute_value (const struct die_reader_specs
*reader
,
18992 struct attribute
*attr
, unsigned form
,
18993 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18994 bool *need_reprocess
)
18996 struct dwarf2_cu
*cu
= reader
->cu
;
18997 struct dwarf2_per_objfile
*dwarf2_per_objfile
18998 = cu
->per_cu
->dwarf2_per_objfile
;
18999 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19000 bfd
*abfd
= reader
->abfd
;
19001 struct comp_unit_head
*cu_header
= &cu
->header
;
19002 unsigned int bytes_read
;
19003 struct dwarf_block
*blk
;
19004 *need_reprocess
= false;
19006 attr
->form
= (enum dwarf_form
) form
;
19009 case DW_FORM_ref_addr
:
19010 if (cu
->header
.version
== 2)
19011 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19014 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19016 info_ptr
+= bytes_read
;
19018 case DW_FORM_GNU_ref_alt
:
19019 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19020 info_ptr
+= bytes_read
;
19024 struct gdbarch
*gdbarch
= objfile
->arch ();
19025 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19026 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19027 info_ptr
+= bytes_read
;
19030 case DW_FORM_block2
:
19031 blk
= dwarf_alloc_block (cu
);
19032 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19034 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19035 info_ptr
+= blk
->size
;
19036 DW_BLOCK (attr
) = blk
;
19038 case DW_FORM_block4
:
19039 blk
= dwarf_alloc_block (cu
);
19040 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19042 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19043 info_ptr
+= blk
->size
;
19044 DW_BLOCK (attr
) = blk
;
19046 case DW_FORM_data2
:
19047 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19050 case DW_FORM_data4
:
19051 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19054 case DW_FORM_data8
:
19055 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19058 case DW_FORM_data16
:
19059 blk
= dwarf_alloc_block (cu
);
19061 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19063 DW_BLOCK (attr
) = blk
;
19065 case DW_FORM_sec_offset
:
19066 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19067 info_ptr
+= bytes_read
;
19069 case DW_FORM_loclistx
:
19071 *need_reprocess
= true;
19072 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19073 info_ptr
+= bytes_read
;
19076 case DW_FORM_string
:
19077 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19078 DW_STRING_IS_CANONICAL (attr
) = 0;
19079 info_ptr
+= bytes_read
;
19082 if (!cu
->per_cu
->is_dwz
)
19084 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19085 abfd
, info_ptr
, cu_header
,
19087 DW_STRING_IS_CANONICAL (attr
) = 0;
19088 info_ptr
+= bytes_read
;
19092 case DW_FORM_line_strp
:
19093 if (!cu
->per_cu
->is_dwz
)
19096 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
19098 DW_STRING_IS_CANONICAL (attr
) = 0;
19099 info_ptr
+= bytes_read
;
19103 case DW_FORM_GNU_strp_alt
:
19105 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19106 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19109 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
19110 DW_STRING_IS_CANONICAL (attr
) = 0;
19111 info_ptr
+= bytes_read
;
19114 case DW_FORM_exprloc
:
19115 case DW_FORM_block
:
19116 blk
= dwarf_alloc_block (cu
);
19117 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19118 info_ptr
+= bytes_read
;
19119 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19120 info_ptr
+= blk
->size
;
19121 DW_BLOCK (attr
) = blk
;
19123 case DW_FORM_block1
:
19124 blk
= dwarf_alloc_block (cu
);
19125 blk
->size
= read_1_byte (abfd
, info_ptr
);
19127 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19128 info_ptr
+= blk
->size
;
19129 DW_BLOCK (attr
) = blk
;
19131 case DW_FORM_data1
:
19132 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19136 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19139 case DW_FORM_flag_present
:
19140 DW_UNSND (attr
) = 1;
19142 case DW_FORM_sdata
:
19143 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19144 info_ptr
+= bytes_read
;
19146 case DW_FORM_udata
:
19147 case DW_FORM_rnglistx
:
19148 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19149 info_ptr
+= bytes_read
;
19152 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19153 + read_1_byte (abfd
, info_ptr
));
19157 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19158 + read_2_bytes (abfd
, info_ptr
));
19162 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19163 + read_4_bytes (abfd
, info_ptr
));
19167 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19168 + read_8_bytes (abfd
, info_ptr
));
19171 case DW_FORM_ref_sig8
:
19172 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19175 case DW_FORM_ref_udata
:
19176 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19177 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19178 info_ptr
+= bytes_read
;
19180 case DW_FORM_indirect
:
19181 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19182 info_ptr
+= bytes_read
;
19183 if (form
== DW_FORM_implicit_const
)
19185 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19186 info_ptr
+= bytes_read
;
19188 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19189 info_ptr
, need_reprocess
);
19191 case DW_FORM_implicit_const
:
19192 DW_SND (attr
) = implicit_const
;
19194 case DW_FORM_addrx
:
19195 case DW_FORM_GNU_addr_index
:
19196 *need_reprocess
= true;
19197 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19198 info_ptr
+= bytes_read
;
19201 case DW_FORM_strx1
:
19202 case DW_FORM_strx2
:
19203 case DW_FORM_strx3
:
19204 case DW_FORM_strx4
:
19205 case DW_FORM_GNU_str_index
:
19207 ULONGEST str_index
;
19208 if (form
== DW_FORM_strx1
)
19210 str_index
= read_1_byte (abfd
, info_ptr
);
19213 else if (form
== DW_FORM_strx2
)
19215 str_index
= read_2_bytes (abfd
, info_ptr
);
19218 else if (form
== DW_FORM_strx3
)
19220 str_index
= read_3_bytes (abfd
, info_ptr
);
19223 else if (form
== DW_FORM_strx4
)
19225 str_index
= read_4_bytes (abfd
, info_ptr
);
19230 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19231 info_ptr
+= bytes_read
;
19233 *need_reprocess
= true;
19234 DW_UNSND (attr
) = str_index
;
19238 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19239 dwarf_form_name (form
),
19240 bfd_get_filename (abfd
));
19244 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19245 attr
->form
= DW_FORM_GNU_ref_alt
;
19247 /* We have seen instances where the compiler tried to emit a byte
19248 size attribute of -1 which ended up being encoded as an unsigned
19249 0xffffffff. Although 0xffffffff is technically a valid size value,
19250 an object of this size seems pretty unlikely so we can relatively
19251 safely treat these cases as if the size attribute was invalid and
19252 treat them as zero by default. */
19253 if (attr
->name
== DW_AT_byte_size
19254 && form
== DW_FORM_data4
19255 && DW_UNSND (attr
) >= 0xffffffff)
19258 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19259 hex_string (DW_UNSND (attr
)));
19260 DW_UNSND (attr
) = 0;
19266 /* Read an attribute described by an abbreviated attribute. */
19268 static const gdb_byte
*
19269 read_attribute (const struct die_reader_specs
*reader
,
19270 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19271 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19273 attr
->name
= abbrev
->name
;
19274 return read_attribute_value (reader
, attr
, abbrev
->form
,
19275 abbrev
->implicit_const
, info_ptr
,
19279 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19281 static const char *
19282 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19283 LONGEST str_offset
)
19285 return dwarf2_per_objfile
->per_bfd
->str
.read_string
19286 (dwarf2_per_objfile
->objfile
, str_offset
, "DW_FORM_strp");
19289 /* Return pointer to string at .debug_str offset as read from BUF.
19290 BUF is assumed to be in a compilation unit described by CU_HEADER.
19291 Return *BYTES_READ_PTR count of bytes read from BUF. */
19293 static const char *
19294 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19295 const gdb_byte
*buf
,
19296 const struct comp_unit_head
*cu_header
,
19297 unsigned int *bytes_read_ptr
)
19299 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19301 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
19307 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19308 const struct comp_unit_head
*cu_header
,
19309 unsigned int *bytes_read_ptr
)
19311 bfd
*abfd
= objfile
->obfd
;
19312 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19314 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19317 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19318 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19319 ADDR_SIZE is the size of addresses from the CU header. */
19322 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19323 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19326 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19327 bfd
*abfd
= objfile
->obfd
;
19328 const gdb_byte
*info_ptr
;
19329 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19331 dwarf2_per_objfile
->per_bfd
->addr
.read (objfile
);
19332 if (dwarf2_per_objfile
->per_bfd
->addr
.buffer
== NULL
)
19333 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19334 objfile_name (objfile
));
19335 if (addr_base_or_zero
+ addr_index
* addr_size
19336 >= dwarf2_per_objfile
->per_bfd
->addr
.size
)
19337 error (_("DW_FORM_addr_index pointing outside of "
19338 ".debug_addr section [in module %s]"),
19339 objfile_name (objfile
));
19340 info_ptr
= (dwarf2_per_objfile
->per_bfd
->addr
.buffer
19341 + addr_base_or_zero
+ addr_index
* addr_size
);
19342 if (addr_size
== 4)
19343 return bfd_get_32 (abfd
, info_ptr
);
19345 return bfd_get_64 (abfd
, info_ptr
);
19348 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19351 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19353 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19354 cu
->addr_base
, cu
->header
.addr_size
);
19357 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19360 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19361 unsigned int *bytes_read
)
19363 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19364 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19366 return read_addr_index (cu
, addr_index
);
19372 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
19374 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19375 struct dwarf2_cu
*cu
= per_cu
->cu
;
19376 gdb::optional
<ULONGEST
> addr_base
;
19379 /* We need addr_base and addr_size.
19380 If we don't have PER_CU->cu, we have to get it.
19381 Nasty, but the alternative is storing the needed info in PER_CU,
19382 which at this point doesn't seem justified: it's not clear how frequently
19383 it would get used and it would increase the size of every PER_CU.
19384 Entry points like dwarf2_per_cu_addr_size do a similar thing
19385 so we're not in uncharted territory here.
19386 Alas we need to be a bit more complicated as addr_base is contained
19389 We don't need to read the entire CU(/TU).
19390 We just need the header and top level die.
19392 IWBN to use the aging mechanism to let us lazily later discard the CU.
19393 For now we skip this optimization. */
19397 addr_base
= cu
->addr_base
;
19398 addr_size
= cu
->header
.addr_size
;
19402 cutu_reader
reader (per_cu
, NULL
, 0, false);
19403 addr_base
= reader
.cu
->addr_base
;
19404 addr_size
= reader
.cu
->header
.addr_size
;
19407 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19411 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19412 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19415 static const char *
19416 read_str_index (struct dwarf2_cu
*cu
,
19417 struct dwarf2_section_info
*str_section
,
19418 struct dwarf2_section_info
*str_offsets_section
,
19419 ULONGEST str_offsets_base
, ULONGEST str_index
)
19421 struct dwarf2_per_objfile
*dwarf2_per_objfile
19422 = cu
->per_cu
->dwarf2_per_objfile
;
19423 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19424 const char *objf_name
= objfile_name (objfile
);
19425 bfd
*abfd
= objfile
->obfd
;
19426 const gdb_byte
*info_ptr
;
19427 ULONGEST str_offset
;
19428 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19430 str_section
->read (objfile
);
19431 str_offsets_section
->read (objfile
);
19432 if (str_section
->buffer
== NULL
)
19433 error (_("%s used without %s section"
19434 " in CU at offset %s [in module %s]"),
19435 form_name
, str_section
->get_name (),
19436 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19437 if (str_offsets_section
->buffer
== NULL
)
19438 error (_("%s used without %s section"
19439 " in CU at offset %s [in module %s]"),
19440 form_name
, str_section
->get_name (),
19441 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19442 info_ptr
= (str_offsets_section
->buffer
19444 + str_index
* cu
->header
.offset_size
);
19445 if (cu
->header
.offset_size
== 4)
19446 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19448 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19449 if (str_offset
>= str_section
->size
)
19450 error (_("Offset from %s pointing outside of"
19451 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19452 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19453 return (const char *) (str_section
->buffer
+ str_offset
);
19456 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19458 static const char *
19459 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19461 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19462 ? reader
->cu
->header
.addr_size
: 0;
19463 return read_str_index (reader
->cu
,
19464 &reader
->dwo_file
->sections
.str
,
19465 &reader
->dwo_file
->sections
.str_offsets
,
19466 str_offsets_base
, str_index
);
19469 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19471 static const char *
19472 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19474 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19475 const char *objf_name
= objfile_name (objfile
);
19476 static const char form_name
[] = "DW_FORM_GNU_str_index";
19477 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19479 if (!cu
->str_offsets_base
.has_value ())
19480 error (_("%s used in Fission stub without %s"
19481 " in CU at offset 0x%lx [in module %s]"),
19482 form_name
, str_offsets_attr_name
,
19483 (long) cu
->header
.offset_size
, objf_name
);
19485 return read_str_index (cu
,
19486 &cu
->per_cu
->dwarf2_per_objfile
->per_bfd
->str
,
19487 &cu
->per_cu
->dwarf2_per_objfile
->per_bfd
->str_offsets
,
19488 *cu
->str_offsets_base
, str_index
);
19491 /* Return the length of an LEB128 number in BUF. */
19494 leb128_size (const gdb_byte
*buf
)
19496 const gdb_byte
*begin
= buf
;
19502 if ((byte
& 128) == 0)
19503 return buf
- begin
;
19508 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19517 cu
->language
= language_c
;
19520 case DW_LANG_C_plus_plus
:
19521 case DW_LANG_C_plus_plus_11
:
19522 case DW_LANG_C_plus_plus_14
:
19523 cu
->language
= language_cplus
;
19526 cu
->language
= language_d
;
19528 case DW_LANG_Fortran77
:
19529 case DW_LANG_Fortran90
:
19530 case DW_LANG_Fortran95
:
19531 case DW_LANG_Fortran03
:
19532 case DW_LANG_Fortran08
:
19533 cu
->language
= language_fortran
;
19536 cu
->language
= language_go
;
19538 case DW_LANG_Mips_Assembler
:
19539 cu
->language
= language_asm
;
19541 case DW_LANG_Ada83
:
19542 case DW_LANG_Ada95
:
19543 cu
->language
= language_ada
;
19545 case DW_LANG_Modula2
:
19546 cu
->language
= language_m2
;
19548 case DW_LANG_Pascal83
:
19549 cu
->language
= language_pascal
;
19552 cu
->language
= language_objc
;
19555 case DW_LANG_Rust_old
:
19556 cu
->language
= language_rust
;
19558 case DW_LANG_Cobol74
:
19559 case DW_LANG_Cobol85
:
19561 cu
->language
= language_minimal
;
19564 cu
->language_defn
= language_def (cu
->language
);
19567 /* Return the named attribute or NULL if not there. */
19569 static struct attribute
*
19570 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19575 struct attribute
*spec
= NULL
;
19577 for (i
= 0; i
< die
->num_attrs
; ++i
)
19579 if (die
->attrs
[i
].name
== name
)
19580 return &die
->attrs
[i
];
19581 if (die
->attrs
[i
].name
== DW_AT_specification
19582 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19583 spec
= &die
->attrs
[i
];
19589 die
= follow_die_ref (die
, spec
, &cu
);
19595 /* Return the string associated with a string-typed attribute, or NULL if it
19596 is either not found or is of an incorrect type. */
19598 static const char *
19599 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19601 struct attribute
*attr
;
19602 const char *str
= NULL
;
19604 attr
= dwarf2_attr (die
, name
, cu
);
19608 str
= attr
->value_as_string ();
19609 if (str
== nullptr)
19610 complaint (_("string type expected for attribute %s for "
19611 "DIE at %s in module %s"),
19612 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19613 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19619 /* Return the dwo name or NULL if not present. If present, it is in either
19620 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19621 static const char *
19622 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19624 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19625 if (dwo_name
== nullptr)
19626 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19630 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19631 and holds a non-zero value. This function should only be used for
19632 DW_FORM_flag or DW_FORM_flag_present attributes. */
19635 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19637 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19639 return (attr
&& DW_UNSND (attr
));
19643 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19645 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19646 which value is non-zero. However, we have to be careful with
19647 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19648 (via dwarf2_flag_true_p) follows this attribute. So we may
19649 end up accidently finding a declaration attribute that belongs
19650 to a different DIE referenced by the specification attribute,
19651 even though the given DIE does not have a declaration attribute. */
19652 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19653 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19656 /* Return the die giving the specification for DIE, if there is
19657 one. *SPEC_CU is the CU containing DIE on input, and the CU
19658 containing the return value on output. If there is no
19659 specification, but there is an abstract origin, that is
19662 static struct die_info
*
19663 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19665 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19668 if (spec_attr
== NULL
)
19669 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19671 if (spec_attr
== NULL
)
19674 return follow_die_ref (die
, spec_attr
, spec_cu
);
19677 /* Stub for free_line_header to match void * callback types. */
19680 free_line_header_voidp (void *arg
)
19682 struct line_header
*lh
= (struct line_header
*) arg
;
19687 /* A convenience function to find the proper .debug_line section for a CU. */
19689 static struct dwarf2_section_info
*
19690 get_debug_line_section (struct dwarf2_cu
*cu
)
19692 struct dwarf2_section_info
*section
;
19693 struct dwarf2_per_objfile
*dwarf2_per_objfile
19694 = cu
->per_cu
->dwarf2_per_objfile
;
19696 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19698 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19699 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19700 else if (cu
->per_cu
->is_dwz
)
19702 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19704 section
= &dwz
->line
;
19707 section
= &dwarf2_per_objfile
->per_bfd
->line
;
19712 /* Read the statement program header starting at OFFSET in
19713 .debug_line, or .debug_line.dwo. Return a pointer
19714 to a struct line_header, allocated using xmalloc.
19715 Returns NULL if there is a problem reading the header, e.g., if it
19716 has a version we don't understand.
19718 NOTE: the strings in the include directory and file name tables of
19719 the returned object point into the dwarf line section buffer,
19720 and must not be freed. */
19722 static line_header_up
19723 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19725 struct dwarf2_section_info
*section
;
19726 struct dwarf2_per_objfile
*dwarf2_per_objfile
19727 = cu
->per_cu
->dwarf2_per_objfile
;
19729 section
= get_debug_line_section (cu
);
19730 section
->read (dwarf2_per_objfile
->objfile
);
19731 if (section
->buffer
== NULL
)
19733 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19734 complaint (_("missing .debug_line.dwo section"));
19736 complaint (_("missing .debug_line section"));
19740 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19741 dwarf2_per_objfile
, section
,
19745 /* Subroutine of dwarf_decode_lines to simplify it.
19746 Return the file name of the psymtab for the given file_entry.
19747 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19748 If space for the result is malloc'd, *NAME_HOLDER will be set.
19749 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19751 static const char *
19752 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19753 const dwarf2_psymtab
*pst
,
19754 const char *comp_dir
,
19755 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19757 const char *include_name
= fe
.name
;
19758 const char *include_name_to_compare
= include_name
;
19759 const char *pst_filename
;
19762 const char *dir_name
= fe
.include_dir (lh
);
19764 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19765 if (!IS_ABSOLUTE_PATH (include_name
)
19766 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19768 /* Avoid creating a duplicate psymtab for PST.
19769 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19770 Before we do the comparison, however, we need to account
19771 for DIR_NAME and COMP_DIR.
19772 First prepend dir_name (if non-NULL). If we still don't
19773 have an absolute path prepend comp_dir (if non-NULL).
19774 However, the directory we record in the include-file's
19775 psymtab does not contain COMP_DIR (to match the
19776 corresponding symtab(s)).
19781 bash$ gcc -g ./hello.c
19782 include_name = "hello.c"
19784 DW_AT_comp_dir = comp_dir = "/tmp"
19785 DW_AT_name = "./hello.c"
19789 if (dir_name
!= NULL
)
19791 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19792 include_name
, (char *) NULL
));
19793 include_name
= name_holder
->get ();
19794 include_name_to_compare
= include_name
;
19796 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19798 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19799 include_name
, (char *) NULL
));
19800 include_name_to_compare
= hold_compare
.get ();
19804 pst_filename
= pst
->filename
;
19805 gdb::unique_xmalloc_ptr
<char> copied_name
;
19806 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19808 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19809 pst_filename
, (char *) NULL
));
19810 pst_filename
= copied_name
.get ();
19813 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19817 return include_name
;
19820 /* State machine to track the state of the line number program. */
19822 class lnp_state_machine
19825 /* Initialize a machine state for the start of a line number
19827 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19828 bool record_lines_p
);
19830 file_entry
*current_file ()
19832 /* lh->file_names is 0-based, but the file name numbers in the
19833 statement program are 1-based. */
19834 return m_line_header
->file_name_at (m_file
);
19837 /* Record the line in the state machine. END_SEQUENCE is true if
19838 we're processing the end of a sequence. */
19839 void record_line (bool end_sequence
);
19841 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19842 nop-out rest of the lines in this sequence. */
19843 void check_line_address (struct dwarf2_cu
*cu
,
19844 const gdb_byte
*line_ptr
,
19845 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19847 void handle_set_discriminator (unsigned int discriminator
)
19849 m_discriminator
= discriminator
;
19850 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19853 /* Handle DW_LNE_set_address. */
19854 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19857 address
+= baseaddr
;
19858 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19861 /* Handle DW_LNS_advance_pc. */
19862 void handle_advance_pc (CORE_ADDR adjust
);
19864 /* Handle a special opcode. */
19865 void handle_special_opcode (unsigned char op_code
);
19867 /* Handle DW_LNS_advance_line. */
19868 void handle_advance_line (int line_delta
)
19870 advance_line (line_delta
);
19873 /* Handle DW_LNS_set_file. */
19874 void handle_set_file (file_name_index file
);
19876 /* Handle DW_LNS_negate_stmt. */
19877 void handle_negate_stmt ()
19879 m_is_stmt
= !m_is_stmt
;
19882 /* Handle DW_LNS_const_add_pc. */
19883 void handle_const_add_pc ();
19885 /* Handle DW_LNS_fixed_advance_pc. */
19886 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19888 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19892 /* Handle DW_LNS_copy. */
19893 void handle_copy ()
19895 record_line (false);
19896 m_discriminator
= 0;
19899 /* Handle DW_LNE_end_sequence. */
19900 void handle_end_sequence ()
19902 m_currently_recording_lines
= true;
19906 /* Advance the line by LINE_DELTA. */
19907 void advance_line (int line_delta
)
19909 m_line
+= line_delta
;
19911 if (line_delta
!= 0)
19912 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19915 struct dwarf2_cu
*m_cu
;
19917 gdbarch
*m_gdbarch
;
19919 /* True if we're recording lines.
19920 Otherwise we're building partial symtabs and are just interested in
19921 finding include files mentioned by the line number program. */
19922 bool m_record_lines_p
;
19924 /* The line number header. */
19925 line_header
*m_line_header
;
19927 /* These are part of the standard DWARF line number state machine,
19928 and initialized according to the DWARF spec. */
19930 unsigned char m_op_index
= 0;
19931 /* The line table index of the current file. */
19932 file_name_index m_file
= 1;
19933 unsigned int m_line
= 1;
19935 /* These are initialized in the constructor. */
19937 CORE_ADDR m_address
;
19939 unsigned int m_discriminator
;
19941 /* Additional bits of state we need to track. */
19943 /* The last file that we called dwarf2_start_subfile for.
19944 This is only used for TLLs. */
19945 unsigned int m_last_file
= 0;
19946 /* The last file a line number was recorded for. */
19947 struct subfile
*m_last_subfile
= NULL
;
19949 /* When true, record the lines we decode. */
19950 bool m_currently_recording_lines
= false;
19952 /* The last line number that was recorded, used to coalesce
19953 consecutive entries for the same line. This can happen, for
19954 example, when discriminators are present. PR 17276. */
19955 unsigned int m_last_line
= 0;
19956 bool m_line_has_non_zero_discriminator
= false;
19960 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19962 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19963 / m_line_header
->maximum_ops_per_instruction
)
19964 * m_line_header
->minimum_instruction_length
);
19965 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19966 m_op_index
= ((m_op_index
+ adjust
)
19967 % m_line_header
->maximum_ops_per_instruction
);
19971 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19973 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19974 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19975 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19976 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19977 / m_line_header
->maximum_ops_per_instruction
)
19978 * m_line_header
->minimum_instruction_length
);
19979 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19980 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19981 % m_line_header
->maximum_ops_per_instruction
);
19983 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19984 advance_line (line_delta
);
19985 record_line (false);
19986 m_discriminator
= 0;
19990 lnp_state_machine::handle_set_file (file_name_index file
)
19994 const file_entry
*fe
= current_file ();
19996 dwarf2_debug_line_missing_file_complaint ();
19997 else if (m_record_lines_p
)
19999 const char *dir
= fe
->include_dir (m_line_header
);
20001 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20002 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20003 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20008 lnp_state_machine::handle_const_add_pc ()
20011 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20014 = (((m_op_index
+ adjust
)
20015 / m_line_header
->maximum_ops_per_instruction
)
20016 * m_line_header
->minimum_instruction_length
);
20018 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20019 m_op_index
= ((m_op_index
+ adjust
)
20020 % m_line_header
->maximum_ops_per_instruction
);
20023 /* Return non-zero if we should add LINE to the line number table.
20024 LINE is the line to add, LAST_LINE is the last line that was added,
20025 LAST_SUBFILE is the subfile for LAST_LINE.
20026 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20027 had a non-zero discriminator.
20029 We have to be careful in the presence of discriminators.
20030 E.g., for this line:
20032 for (i = 0; i < 100000; i++);
20034 clang can emit four line number entries for that one line,
20035 each with a different discriminator.
20036 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20038 However, we want gdb to coalesce all four entries into one.
20039 Otherwise the user could stepi into the middle of the line and
20040 gdb would get confused about whether the pc really was in the
20041 middle of the line.
20043 Things are further complicated by the fact that two consecutive
20044 line number entries for the same line is a heuristic used by gcc
20045 to denote the end of the prologue. So we can't just discard duplicate
20046 entries, we have to be selective about it. The heuristic we use is
20047 that we only collapse consecutive entries for the same line if at least
20048 one of those entries has a non-zero discriminator. PR 17276.
20050 Note: Addresses in the line number state machine can never go backwards
20051 within one sequence, thus this coalescing is ok. */
20054 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20055 unsigned int line
, unsigned int last_line
,
20056 int line_has_non_zero_discriminator
,
20057 struct subfile
*last_subfile
)
20059 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20061 if (line
!= last_line
)
20063 /* Same line for the same file that we've seen already.
20064 As a last check, for pr 17276, only record the line if the line
20065 has never had a non-zero discriminator. */
20066 if (!line_has_non_zero_discriminator
)
20071 /* Use the CU's builder to record line number LINE beginning at
20072 address ADDRESS in the line table of subfile SUBFILE. */
20075 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20076 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20077 struct dwarf2_cu
*cu
)
20079 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20081 if (dwarf_line_debug
)
20083 fprintf_unfiltered (gdb_stdlog
,
20084 "Recording line %u, file %s, address %s\n",
20085 line
, lbasename (subfile
->name
),
20086 paddress (gdbarch
, address
));
20090 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20093 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20094 Mark the end of a set of line number records.
20095 The arguments are the same as for dwarf_record_line_1.
20096 If SUBFILE is NULL the request is ignored. */
20099 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20100 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20102 if (subfile
== NULL
)
20105 if (dwarf_line_debug
)
20107 fprintf_unfiltered (gdb_stdlog
,
20108 "Finishing current line, file %s, address %s\n",
20109 lbasename (subfile
->name
),
20110 paddress (gdbarch
, address
));
20113 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20117 lnp_state_machine::record_line (bool end_sequence
)
20119 if (dwarf_line_debug
)
20121 fprintf_unfiltered (gdb_stdlog
,
20122 "Processing actual line %u: file %u,"
20123 " address %s, is_stmt %u, discrim %u%s\n",
20125 paddress (m_gdbarch
, m_address
),
20126 m_is_stmt
, m_discriminator
,
20127 (end_sequence
? "\t(end sequence)" : ""));
20130 file_entry
*fe
= current_file ();
20133 dwarf2_debug_line_missing_file_complaint ();
20134 /* For now we ignore lines not starting on an instruction boundary.
20135 But not when processing end_sequence for compatibility with the
20136 previous version of the code. */
20137 else if (m_op_index
== 0 || end_sequence
)
20139 fe
->included_p
= 1;
20140 if (m_record_lines_p
)
20142 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20145 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20146 m_currently_recording_lines
? m_cu
: nullptr);
20151 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20153 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20154 m_line_has_non_zero_discriminator
,
20157 buildsym_compunit
*builder
= m_cu
->get_builder ();
20158 dwarf_record_line_1 (m_gdbarch
,
20159 builder
->get_current_subfile (),
20160 m_line
, m_address
, is_stmt
,
20161 m_currently_recording_lines
? m_cu
: nullptr);
20163 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20164 m_last_line
= m_line
;
20170 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20171 line_header
*lh
, bool record_lines_p
)
20175 m_record_lines_p
= record_lines_p
;
20176 m_line_header
= lh
;
20178 m_currently_recording_lines
= true;
20180 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20181 was a line entry for it so that the backend has a chance to adjust it
20182 and also record it in case it needs it. This is currently used by MIPS
20183 code, cf. `mips_adjust_dwarf2_line'. */
20184 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20185 m_is_stmt
= lh
->default_is_stmt
;
20186 m_discriminator
= 0;
20190 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20191 const gdb_byte
*line_ptr
,
20192 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20194 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20195 the pc range of the CU. However, we restrict the test to only ADDRESS
20196 values of zero to preserve GDB's previous behaviour which is to handle
20197 the specific case of a function being GC'd by the linker. */
20199 if (address
== 0 && address
< unrelocated_lowpc
)
20201 /* This line table is for a function which has been
20202 GCd by the linker. Ignore it. PR gdb/12528 */
20204 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20205 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20207 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20208 line_offset
, objfile_name (objfile
));
20209 m_currently_recording_lines
= false;
20210 /* Note: m_currently_recording_lines is left as false until we see
20211 DW_LNE_end_sequence. */
20215 /* Subroutine of dwarf_decode_lines to simplify it.
20216 Process the line number information in LH.
20217 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20218 program in order to set included_p for every referenced header. */
20221 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20222 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20224 const gdb_byte
*line_ptr
, *extended_end
;
20225 const gdb_byte
*line_end
;
20226 unsigned int bytes_read
, extended_len
;
20227 unsigned char op_code
, extended_op
;
20228 CORE_ADDR baseaddr
;
20229 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20230 bfd
*abfd
= objfile
->obfd
;
20231 struct gdbarch
*gdbarch
= objfile
->arch ();
20232 /* True if we're recording line info (as opposed to building partial
20233 symtabs and just interested in finding include files mentioned by
20234 the line number program). */
20235 bool record_lines_p
= !decode_for_pst_p
;
20237 baseaddr
= objfile
->text_section_offset ();
20239 line_ptr
= lh
->statement_program_start
;
20240 line_end
= lh
->statement_program_end
;
20242 /* Read the statement sequences until there's nothing left. */
20243 while (line_ptr
< line_end
)
20245 /* The DWARF line number program state machine. Reset the state
20246 machine at the start of each sequence. */
20247 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20248 bool end_sequence
= false;
20250 if (record_lines_p
)
20252 /* Start a subfile for the current file of the state
20254 const file_entry
*fe
= state_machine
.current_file ();
20257 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20260 /* Decode the table. */
20261 while (line_ptr
< line_end
&& !end_sequence
)
20263 op_code
= read_1_byte (abfd
, line_ptr
);
20266 if (op_code
>= lh
->opcode_base
)
20268 /* Special opcode. */
20269 state_machine
.handle_special_opcode (op_code
);
20271 else switch (op_code
)
20273 case DW_LNS_extended_op
:
20274 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20276 line_ptr
+= bytes_read
;
20277 extended_end
= line_ptr
+ extended_len
;
20278 extended_op
= read_1_byte (abfd
, line_ptr
);
20280 switch (extended_op
)
20282 case DW_LNE_end_sequence
:
20283 state_machine
.handle_end_sequence ();
20284 end_sequence
= true;
20286 case DW_LNE_set_address
:
20289 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20290 line_ptr
+= bytes_read
;
20292 state_machine
.check_line_address (cu
, line_ptr
,
20293 lowpc
- baseaddr
, address
);
20294 state_machine
.handle_set_address (baseaddr
, address
);
20297 case DW_LNE_define_file
:
20299 const char *cur_file
;
20300 unsigned int mod_time
, length
;
20303 cur_file
= read_direct_string (abfd
, line_ptr
,
20305 line_ptr
+= bytes_read
;
20306 dindex
= (dir_index
)
20307 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20308 line_ptr
+= bytes_read
;
20310 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20311 line_ptr
+= bytes_read
;
20313 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20314 line_ptr
+= bytes_read
;
20315 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20318 case DW_LNE_set_discriminator
:
20320 /* The discriminator is not interesting to the
20321 debugger; just ignore it. We still need to
20322 check its value though:
20323 if there are consecutive entries for the same
20324 (non-prologue) line we want to coalesce them.
20327 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20328 line_ptr
+= bytes_read
;
20330 state_machine
.handle_set_discriminator (discr
);
20334 complaint (_("mangled .debug_line section"));
20337 /* Make sure that we parsed the extended op correctly. If e.g.
20338 we expected a different address size than the producer used,
20339 we may have read the wrong number of bytes. */
20340 if (line_ptr
!= extended_end
)
20342 complaint (_("mangled .debug_line section"));
20347 state_machine
.handle_copy ();
20349 case DW_LNS_advance_pc
:
20352 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20353 line_ptr
+= bytes_read
;
20355 state_machine
.handle_advance_pc (adjust
);
20358 case DW_LNS_advance_line
:
20361 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20362 line_ptr
+= bytes_read
;
20364 state_machine
.handle_advance_line (line_delta
);
20367 case DW_LNS_set_file
:
20369 file_name_index file
20370 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20372 line_ptr
+= bytes_read
;
20374 state_machine
.handle_set_file (file
);
20377 case DW_LNS_set_column
:
20378 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20379 line_ptr
+= bytes_read
;
20381 case DW_LNS_negate_stmt
:
20382 state_machine
.handle_negate_stmt ();
20384 case DW_LNS_set_basic_block
:
20386 /* Add to the address register of the state machine the
20387 address increment value corresponding to special opcode
20388 255. I.e., this value is scaled by the minimum
20389 instruction length since special opcode 255 would have
20390 scaled the increment. */
20391 case DW_LNS_const_add_pc
:
20392 state_machine
.handle_const_add_pc ();
20394 case DW_LNS_fixed_advance_pc
:
20396 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20399 state_machine
.handle_fixed_advance_pc (addr_adj
);
20404 /* Unknown standard opcode, ignore it. */
20407 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20409 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20410 line_ptr
+= bytes_read
;
20417 dwarf2_debug_line_missing_end_sequence_complaint ();
20419 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20420 in which case we still finish recording the last line). */
20421 state_machine
.record_line (true);
20425 /* Decode the Line Number Program (LNP) for the given line_header
20426 structure and CU. The actual information extracted and the type
20427 of structures created from the LNP depends on the value of PST.
20429 1. If PST is NULL, then this procedure uses the data from the program
20430 to create all necessary symbol tables, and their linetables.
20432 2. If PST is not NULL, this procedure reads the program to determine
20433 the list of files included by the unit represented by PST, and
20434 builds all the associated partial symbol tables.
20436 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20437 It is used for relative paths in the line table.
20438 NOTE: When processing partial symtabs (pst != NULL),
20439 comp_dir == pst->dirname.
20441 NOTE: It is important that psymtabs have the same file name (via strcmp)
20442 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20443 symtab we don't use it in the name of the psymtabs we create.
20444 E.g. expand_line_sal requires this when finding psymtabs to expand.
20445 A good testcase for this is mb-inline.exp.
20447 LOWPC is the lowest address in CU (or 0 if not known).
20449 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20450 for its PC<->lines mapping information. Otherwise only the filename
20451 table is read in. */
20454 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20455 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20456 CORE_ADDR lowpc
, int decode_mapping
)
20458 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20459 const int decode_for_pst_p
= (pst
!= NULL
);
20461 if (decode_mapping
)
20462 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20464 if (decode_for_pst_p
)
20466 /* Now that we're done scanning the Line Header Program, we can
20467 create the psymtab of each included file. */
20468 for (auto &file_entry
: lh
->file_names ())
20469 if (file_entry
.included_p
== 1)
20471 gdb::unique_xmalloc_ptr
<char> name_holder
;
20472 const char *include_name
=
20473 psymtab_include_file_name (lh
, file_entry
, pst
,
20474 comp_dir
, &name_holder
);
20475 if (include_name
!= NULL
)
20476 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20481 /* Make sure a symtab is created for every file, even files
20482 which contain only variables (i.e. no code with associated
20484 buildsym_compunit
*builder
= cu
->get_builder ();
20485 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20487 for (auto &fe
: lh
->file_names ())
20489 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20490 if (builder
->get_current_subfile ()->symtab
== NULL
)
20492 builder
->get_current_subfile ()->symtab
20493 = allocate_symtab (cust
,
20494 builder
->get_current_subfile ()->name
);
20496 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20501 /* Start a subfile for DWARF. FILENAME is the name of the file and
20502 DIRNAME the name of the source directory which contains FILENAME
20503 or NULL if not known.
20504 This routine tries to keep line numbers from identical absolute and
20505 relative file names in a common subfile.
20507 Using the `list' example from the GDB testsuite, which resides in
20508 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20509 of /srcdir/list0.c yields the following debugging information for list0.c:
20511 DW_AT_name: /srcdir/list0.c
20512 DW_AT_comp_dir: /compdir
20513 files.files[0].name: list0.h
20514 files.files[0].dir: /srcdir
20515 files.files[1].name: list0.c
20516 files.files[1].dir: /srcdir
20518 The line number information for list0.c has to end up in a single
20519 subfile, so that `break /srcdir/list0.c:1' works as expected.
20520 start_subfile will ensure that this happens provided that we pass the
20521 concatenation of files.files[1].dir and files.files[1].name as the
20525 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20526 const char *dirname
)
20528 gdb::unique_xmalloc_ptr
<char> copy
;
20530 /* In order not to lose the line information directory,
20531 we concatenate it to the filename when it makes sense.
20532 Note that the Dwarf3 standard says (speaking of filenames in line
20533 information): ``The directory index is ignored for file names
20534 that represent full path names''. Thus ignoring dirname in the
20535 `else' branch below isn't an issue. */
20537 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20539 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20540 filename
= copy
.get ();
20543 cu
->get_builder ()->start_subfile (filename
);
20546 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20547 buildsym_compunit constructor. */
20549 struct compunit_symtab
*
20550 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20553 gdb_assert (m_builder
== nullptr);
20555 m_builder
.reset (new struct buildsym_compunit
20556 (per_cu
->dwarf2_per_objfile
->objfile
,
20557 name
, comp_dir
, language
, low_pc
));
20559 list_in_scope
= get_builder ()->get_file_symbols ();
20561 get_builder ()->record_debugformat ("DWARF 2");
20562 get_builder ()->record_producer (producer
);
20564 processing_has_namespace_info
= false;
20566 return get_builder ()->get_compunit_symtab ();
20570 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20571 struct dwarf2_cu
*cu
)
20573 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20574 struct comp_unit_head
*cu_header
= &cu
->header
;
20576 /* NOTE drow/2003-01-30: There used to be a comment and some special
20577 code here to turn a symbol with DW_AT_external and a
20578 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20579 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20580 with some versions of binutils) where shared libraries could have
20581 relocations against symbols in their debug information - the
20582 minimal symbol would have the right address, but the debug info
20583 would not. It's no longer necessary, because we will explicitly
20584 apply relocations when we read in the debug information now. */
20586 /* A DW_AT_location attribute with no contents indicates that a
20587 variable has been optimized away. */
20588 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20590 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20594 /* Handle one degenerate form of location expression specially, to
20595 preserve GDB's previous behavior when section offsets are
20596 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20597 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20599 if (attr
->form_is_block ()
20600 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20601 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20602 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20603 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20604 && (DW_BLOCK (attr
)->size
20605 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20607 unsigned int dummy
;
20609 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20610 SET_SYMBOL_VALUE_ADDRESS
20611 (sym
, cu
->header
.read_address (objfile
->obfd
,
20612 DW_BLOCK (attr
)->data
+ 1,
20615 SET_SYMBOL_VALUE_ADDRESS
20616 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20618 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20619 fixup_symbol_section (sym
, objfile
);
20620 SET_SYMBOL_VALUE_ADDRESS
20622 SYMBOL_VALUE_ADDRESS (sym
)
20623 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20627 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20628 expression evaluator, and use LOC_COMPUTED only when necessary
20629 (i.e. when the value of a register or memory location is
20630 referenced, or a thread-local block, etc.). Then again, it might
20631 not be worthwhile. I'm assuming that it isn't unless performance
20632 or memory numbers show me otherwise. */
20634 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20636 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20637 cu
->has_loclist
= true;
20640 /* Given a pointer to a DWARF information entry, figure out if we need
20641 to make a symbol table entry for it, and if so, create a new entry
20642 and return a pointer to it.
20643 If TYPE is NULL, determine symbol type from the die, otherwise
20644 used the passed type.
20645 If SPACE is not NULL, use it to hold the new symbol. If it is
20646 NULL, allocate a new symbol on the objfile's obstack. */
20648 static struct symbol
*
20649 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20650 struct symbol
*space
)
20652 struct dwarf2_per_objfile
*dwarf2_per_objfile
20653 = cu
->per_cu
->dwarf2_per_objfile
;
20654 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20655 struct gdbarch
*gdbarch
= objfile
->arch ();
20656 struct symbol
*sym
= NULL
;
20658 struct attribute
*attr
= NULL
;
20659 struct attribute
*attr2
= NULL
;
20660 CORE_ADDR baseaddr
;
20661 struct pending
**list_to_add
= NULL
;
20663 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20665 baseaddr
= objfile
->text_section_offset ();
20667 name
= dwarf2_name (die
, cu
);
20670 int suppress_add
= 0;
20675 sym
= new (&objfile
->objfile_obstack
) symbol
;
20676 OBJSTAT (objfile
, n_syms
++);
20678 /* Cache this symbol's name and the name's demangled form (if any). */
20679 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20680 /* Fortran does not have mangling standard and the mangling does differ
20681 between gfortran, iFort etc. */
20682 const char *physname
20683 = (cu
->language
== language_fortran
20684 ? dwarf2_full_name (name
, die
, cu
)
20685 : dwarf2_physname (name
, die
, cu
));
20686 const char *linkagename
= dw2_linkage_name (die
, cu
);
20688 if (linkagename
== nullptr || cu
->language
== language_ada
)
20689 sym
->set_linkage_name (physname
);
20692 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
20693 sym
->set_linkage_name (linkagename
);
20696 /* Default assumptions.
20697 Use the passed type or decode it from the die. */
20698 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20699 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20701 SYMBOL_TYPE (sym
) = type
;
20703 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20704 attr
= dwarf2_attr (die
,
20705 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20707 if (attr
!= nullptr)
20709 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20712 attr
= dwarf2_attr (die
,
20713 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20715 if (attr
!= nullptr)
20717 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20718 struct file_entry
*fe
;
20720 if (cu
->line_header
!= NULL
)
20721 fe
= cu
->line_header
->file_name_at (file_index
);
20726 complaint (_("file index out of range"));
20728 symbol_set_symtab (sym
, fe
->symtab
);
20734 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20735 if (attr
!= nullptr)
20739 addr
= attr
->value_as_address ();
20740 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20741 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20743 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20744 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20745 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20746 add_symbol_to_list (sym
, cu
->list_in_scope
);
20748 case DW_TAG_subprogram
:
20749 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20751 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20752 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20753 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20754 || cu
->language
== language_ada
20755 || cu
->language
== language_fortran
)
20757 /* Subprograms marked external are stored as a global symbol.
20758 Ada and Fortran subprograms, whether marked external or
20759 not, are always stored as a global symbol, because we want
20760 to be able to access them globally. For instance, we want
20761 to be able to break on a nested subprogram without having
20762 to specify the context. */
20763 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20767 list_to_add
= cu
->list_in_scope
;
20770 case DW_TAG_inlined_subroutine
:
20771 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20773 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20774 SYMBOL_INLINED (sym
) = 1;
20775 list_to_add
= cu
->list_in_scope
;
20777 case DW_TAG_template_value_param
:
20779 /* Fall through. */
20780 case DW_TAG_constant
:
20781 case DW_TAG_variable
:
20782 case DW_TAG_member
:
20783 /* Compilation with minimal debug info may result in
20784 variables with missing type entries. Change the
20785 misleading `void' type to something sensible. */
20786 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
20787 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20789 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20790 /* In the case of DW_TAG_member, we should only be called for
20791 static const members. */
20792 if (die
->tag
== DW_TAG_member
)
20794 /* dwarf2_add_field uses die_is_declaration,
20795 so we do the same. */
20796 gdb_assert (die_is_declaration (die
, cu
));
20799 if (attr
!= nullptr)
20801 dwarf2_const_value (attr
, sym
, cu
);
20802 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20805 if (attr2
&& (DW_UNSND (attr2
) != 0))
20806 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20808 list_to_add
= cu
->list_in_scope
;
20812 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20813 if (attr
!= nullptr)
20815 var_decode_location (attr
, sym
, cu
);
20816 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20818 /* Fortran explicitly imports any global symbols to the local
20819 scope by DW_TAG_common_block. */
20820 if (cu
->language
== language_fortran
&& die
->parent
20821 && die
->parent
->tag
== DW_TAG_common_block
)
20824 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20825 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20826 && !dwarf2_per_objfile
->per_bfd
->has_section_at_zero
)
20828 /* When a static variable is eliminated by the linker,
20829 the corresponding debug information is not stripped
20830 out, but the variable address is set to null;
20831 do not add such variables into symbol table. */
20833 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20835 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20836 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20837 && dwarf2_per_objfile
->per_bfd
->can_copy
)
20839 /* A global static variable might be subject to
20840 copy relocation. We first check for a local
20841 minsym, though, because maybe the symbol was
20842 marked hidden, in which case this would not
20844 bound_minimal_symbol found
20845 = (lookup_minimal_symbol_linkage
20846 (sym
->linkage_name (), objfile
));
20847 if (found
.minsym
!= nullptr)
20848 sym
->maybe_copied
= 1;
20851 /* A variable with DW_AT_external is never static,
20852 but it may be block-scoped. */
20854 = ((cu
->list_in_scope
20855 == cu
->get_builder ()->get_file_symbols ())
20856 ? cu
->get_builder ()->get_global_symbols ()
20857 : cu
->list_in_scope
);
20860 list_to_add
= cu
->list_in_scope
;
20864 /* We do not know the address of this symbol.
20865 If it is an external symbol and we have type information
20866 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20867 The address of the variable will then be determined from
20868 the minimal symbol table whenever the variable is
20870 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20872 /* Fortran explicitly imports any global symbols to the local
20873 scope by DW_TAG_common_block. */
20874 if (cu
->language
== language_fortran
&& die
->parent
20875 && die
->parent
->tag
== DW_TAG_common_block
)
20877 /* SYMBOL_CLASS doesn't matter here because
20878 read_common_block is going to reset it. */
20880 list_to_add
= cu
->list_in_scope
;
20882 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20883 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20885 /* A variable with DW_AT_external is never static, but it
20886 may be block-scoped. */
20888 = ((cu
->list_in_scope
20889 == cu
->get_builder ()->get_file_symbols ())
20890 ? cu
->get_builder ()->get_global_symbols ()
20891 : cu
->list_in_scope
);
20893 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20895 else if (!die_is_declaration (die
, cu
))
20897 /* Use the default LOC_OPTIMIZED_OUT class. */
20898 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20900 list_to_add
= cu
->list_in_scope
;
20904 case DW_TAG_formal_parameter
:
20906 /* If we are inside a function, mark this as an argument. If
20907 not, we might be looking at an argument to an inlined function
20908 when we do not have enough information to show inlined frames;
20909 pretend it's a local variable in that case so that the user can
20911 struct context_stack
*curr
20912 = cu
->get_builder ()->get_current_context_stack ();
20913 if (curr
!= nullptr && curr
->name
!= nullptr)
20914 SYMBOL_IS_ARGUMENT (sym
) = 1;
20915 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20916 if (attr
!= nullptr)
20918 var_decode_location (attr
, sym
, cu
);
20920 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20921 if (attr
!= nullptr)
20923 dwarf2_const_value (attr
, sym
, cu
);
20926 list_to_add
= cu
->list_in_scope
;
20929 case DW_TAG_unspecified_parameters
:
20930 /* From varargs functions; gdb doesn't seem to have any
20931 interest in this information, so just ignore it for now.
20934 case DW_TAG_template_type_param
:
20936 /* Fall through. */
20937 case DW_TAG_class_type
:
20938 case DW_TAG_interface_type
:
20939 case DW_TAG_structure_type
:
20940 case DW_TAG_union_type
:
20941 case DW_TAG_set_type
:
20942 case DW_TAG_enumeration_type
:
20943 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20944 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20947 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20948 really ever be static objects: otherwise, if you try
20949 to, say, break of a class's method and you're in a file
20950 which doesn't mention that class, it won't work unless
20951 the check for all static symbols in lookup_symbol_aux
20952 saves you. See the OtherFileClass tests in
20953 gdb.c++/namespace.exp. */
20957 buildsym_compunit
*builder
= cu
->get_builder ();
20959 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20960 && cu
->language
== language_cplus
20961 ? builder
->get_global_symbols ()
20962 : cu
->list_in_scope
);
20964 /* The semantics of C++ state that "struct foo {
20965 ... }" also defines a typedef for "foo". */
20966 if (cu
->language
== language_cplus
20967 || cu
->language
== language_ada
20968 || cu
->language
== language_d
20969 || cu
->language
== language_rust
)
20971 /* The symbol's name is already allocated along
20972 with this objfile, so we don't need to
20973 duplicate it for the type. */
20974 if (SYMBOL_TYPE (sym
)->name () == 0)
20975 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
20980 case DW_TAG_typedef
:
20981 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20982 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20983 list_to_add
= cu
->list_in_scope
;
20985 case DW_TAG_base_type
:
20986 case DW_TAG_subrange_type
:
20987 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20988 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20989 list_to_add
= cu
->list_in_scope
;
20991 case DW_TAG_enumerator
:
20992 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20993 if (attr
!= nullptr)
20995 dwarf2_const_value (attr
, sym
, cu
);
20998 /* NOTE: carlton/2003-11-10: See comment above in the
20999 DW_TAG_class_type, etc. block. */
21002 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21003 && cu
->language
== language_cplus
21004 ? cu
->get_builder ()->get_global_symbols ()
21005 : cu
->list_in_scope
);
21008 case DW_TAG_imported_declaration
:
21009 case DW_TAG_namespace
:
21010 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21011 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21013 case DW_TAG_module
:
21014 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21015 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21016 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21018 case DW_TAG_common_block
:
21019 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21020 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21021 add_symbol_to_list (sym
, cu
->list_in_scope
);
21024 /* Not a tag we recognize. Hopefully we aren't processing
21025 trash data, but since we must specifically ignore things
21026 we don't recognize, there is nothing else we should do at
21028 complaint (_("unsupported tag: '%s'"),
21029 dwarf_tag_name (die
->tag
));
21035 sym
->hash_next
= objfile
->template_symbols
;
21036 objfile
->template_symbols
= sym
;
21037 list_to_add
= NULL
;
21040 if (list_to_add
!= NULL
)
21041 add_symbol_to_list (sym
, list_to_add
);
21043 /* For the benefit of old versions of GCC, check for anonymous
21044 namespaces based on the demangled name. */
21045 if (!cu
->processing_has_namespace_info
21046 && cu
->language
== language_cplus
)
21047 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21052 /* Given an attr with a DW_FORM_dataN value in host byte order,
21053 zero-extend it as appropriate for the symbol's type. The DWARF
21054 standard (v4) is not entirely clear about the meaning of using
21055 DW_FORM_dataN for a constant with a signed type, where the type is
21056 wider than the data. The conclusion of a discussion on the DWARF
21057 list was that this is unspecified. We choose to always zero-extend
21058 because that is the interpretation long in use by GCC. */
21061 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21062 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21064 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21065 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21066 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21067 LONGEST l
= DW_UNSND (attr
);
21069 if (bits
< sizeof (*value
) * 8)
21071 l
&= ((LONGEST
) 1 << bits
) - 1;
21074 else if (bits
== sizeof (*value
) * 8)
21078 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21079 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21086 /* Read a constant value from an attribute. Either set *VALUE, or if
21087 the value does not fit in *VALUE, set *BYTES - either already
21088 allocated on the objfile obstack, or newly allocated on OBSTACK,
21089 or, set *BATON, if we translated the constant to a location
21093 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21094 const char *name
, struct obstack
*obstack
,
21095 struct dwarf2_cu
*cu
,
21096 LONGEST
*value
, const gdb_byte
**bytes
,
21097 struct dwarf2_locexpr_baton
**baton
)
21099 dwarf2_per_objfile
*per_objfile
= cu
->per_cu
->dwarf2_per_objfile
;
21100 struct objfile
*objfile
= per_objfile
->objfile
;
21101 struct comp_unit_head
*cu_header
= &cu
->header
;
21102 struct dwarf_block
*blk
;
21103 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21104 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21110 switch (attr
->form
)
21113 case DW_FORM_addrx
:
21114 case DW_FORM_GNU_addr_index
:
21118 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21119 dwarf2_const_value_length_mismatch_complaint (name
,
21120 cu_header
->addr_size
,
21121 TYPE_LENGTH (type
));
21122 /* Symbols of this form are reasonably rare, so we just
21123 piggyback on the existing location code rather than writing
21124 a new implementation of symbol_computed_ops. */
21125 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21126 (*baton
)->per_objfile
= per_objfile
;
21127 (*baton
)->per_cu
= cu
->per_cu
;
21128 gdb_assert ((*baton
)->per_cu
);
21130 (*baton
)->size
= 2 + cu_header
->addr_size
;
21131 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21132 (*baton
)->data
= data
;
21134 data
[0] = DW_OP_addr
;
21135 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21136 byte_order
, DW_ADDR (attr
));
21137 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21140 case DW_FORM_string
:
21143 case DW_FORM_GNU_str_index
:
21144 case DW_FORM_GNU_strp_alt
:
21145 /* DW_STRING is already allocated on the objfile obstack, point
21147 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21149 case DW_FORM_block1
:
21150 case DW_FORM_block2
:
21151 case DW_FORM_block4
:
21152 case DW_FORM_block
:
21153 case DW_FORM_exprloc
:
21154 case DW_FORM_data16
:
21155 blk
= DW_BLOCK (attr
);
21156 if (TYPE_LENGTH (type
) != blk
->size
)
21157 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21158 TYPE_LENGTH (type
));
21159 *bytes
= blk
->data
;
21162 /* The DW_AT_const_value attributes are supposed to carry the
21163 symbol's value "represented as it would be on the target
21164 architecture." By the time we get here, it's already been
21165 converted to host endianness, so we just need to sign- or
21166 zero-extend it as appropriate. */
21167 case DW_FORM_data1
:
21168 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21170 case DW_FORM_data2
:
21171 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21173 case DW_FORM_data4
:
21174 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21176 case DW_FORM_data8
:
21177 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21180 case DW_FORM_sdata
:
21181 case DW_FORM_implicit_const
:
21182 *value
= DW_SND (attr
);
21185 case DW_FORM_udata
:
21186 *value
= DW_UNSND (attr
);
21190 complaint (_("unsupported const value attribute form: '%s'"),
21191 dwarf_form_name (attr
->form
));
21198 /* Copy constant value from an attribute to a symbol. */
21201 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21202 struct dwarf2_cu
*cu
)
21204 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21206 const gdb_byte
*bytes
;
21207 struct dwarf2_locexpr_baton
*baton
;
21209 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21210 sym
->print_name (),
21211 &objfile
->objfile_obstack
, cu
,
21212 &value
, &bytes
, &baton
);
21216 SYMBOL_LOCATION_BATON (sym
) = baton
;
21217 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21219 else if (bytes
!= NULL
)
21221 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21222 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21226 SYMBOL_VALUE (sym
) = value
;
21227 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21231 /* Return the type of the die in question using its DW_AT_type attribute. */
21233 static struct type
*
21234 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21236 struct attribute
*type_attr
;
21238 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21241 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21242 /* A missing DW_AT_type represents a void type. */
21243 return objfile_type (objfile
)->builtin_void
;
21246 return lookup_die_type (die
, type_attr
, cu
);
21249 /* True iff CU's producer generates GNAT Ada auxiliary information
21250 that allows to find parallel types through that information instead
21251 of having to do expensive parallel lookups by type name. */
21254 need_gnat_info (struct dwarf2_cu
*cu
)
21256 /* Assume that the Ada compiler was GNAT, which always produces
21257 the auxiliary information. */
21258 return (cu
->language
== language_ada
);
21261 /* Return the auxiliary type of the die in question using its
21262 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21263 attribute is not present. */
21265 static struct type
*
21266 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21268 struct attribute
*type_attr
;
21270 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21274 return lookup_die_type (die
, type_attr
, cu
);
21277 /* If DIE has a descriptive_type attribute, then set the TYPE's
21278 descriptive type accordingly. */
21281 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21282 struct dwarf2_cu
*cu
)
21284 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21286 if (descriptive_type
)
21288 ALLOCATE_GNAT_AUX_TYPE (type
);
21289 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21293 /* Return the containing type of the die in question using its
21294 DW_AT_containing_type attribute. */
21296 static struct type
*
21297 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21299 struct attribute
*type_attr
;
21300 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21302 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21304 error (_("Dwarf Error: Problem turning containing type into gdb type "
21305 "[in module %s]"), objfile_name (objfile
));
21307 return lookup_die_type (die
, type_attr
, cu
);
21310 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21312 static struct type
*
21313 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21315 struct dwarf2_per_objfile
*dwarf2_per_objfile
21316 = cu
->per_cu
->dwarf2_per_objfile
;
21317 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21320 std::string message
21321 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21322 objfile_name (objfile
),
21323 sect_offset_str (cu
->header
.sect_off
),
21324 sect_offset_str (die
->sect_off
));
21325 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21327 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21330 /* Look up the type of DIE in CU using its type attribute ATTR.
21331 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21332 DW_AT_containing_type.
21333 If there is no type substitute an error marker. */
21335 static struct type
*
21336 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21337 struct dwarf2_cu
*cu
)
21339 struct dwarf2_per_objfile
*dwarf2_per_objfile
21340 = cu
->per_cu
->dwarf2_per_objfile
;
21341 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21342 struct type
*this_type
;
21344 gdb_assert (attr
->name
== DW_AT_type
21345 || attr
->name
== DW_AT_GNAT_descriptive_type
21346 || attr
->name
== DW_AT_containing_type
);
21348 /* First see if we have it cached. */
21350 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21352 struct dwarf2_per_cu_data
*per_cu
;
21353 sect_offset sect_off
= attr
->get_ref_die_offset ();
21355 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21356 dwarf2_per_objfile
);
21357 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21359 else if (attr
->form_is_ref ())
21361 sect_offset sect_off
= attr
->get_ref_die_offset ();
21363 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21365 else if (attr
->form
== DW_FORM_ref_sig8
)
21367 ULONGEST signature
= DW_SIGNATURE (attr
);
21369 return get_signatured_type (die
, signature
, cu
);
21373 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21374 " at %s [in module %s]"),
21375 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21376 objfile_name (objfile
));
21377 return build_error_marker_type (cu
, die
);
21380 /* If not cached we need to read it in. */
21382 if (this_type
== NULL
)
21384 struct die_info
*type_die
= NULL
;
21385 struct dwarf2_cu
*type_cu
= cu
;
21387 if (attr
->form_is_ref ())
21388 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21389 if (type_die
== NULL
)
21390 return build_error_marker_type (cu
, die
);
21391 /* If we find the type now, it's probably because the type came
21392 from an inter-CU reference and the type's CU got expanded before
21394 this_type
= read_type_die (type_die
, type_cu
);
21397 /* If we still don't have a type use an error marker. */
21399 if (this_type
== NULL
)
21400 return build_error_marker_type (cu
, die
);
21405 /* Return the type in DIE, CU.
21406 Returns NULL for invalid types.
21408 This first does a lookup in die_type_hash,
21409 and only reads the die in if necessary.
21411 NOTE: This can be called when reading in partial or full symbols. */
21413 static struct type
*
21414 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21416 struct type
*this_type
;
21418 this_type
= get_die_type (die
, cu
);
21422 return read_type_die_1 (die
, cu
);
21425 /* Read the type in DIE, CU.
21426 Returns NULL for invalid types. */
21428 static struct type
*
21429 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21431 struct type
*this_type
= NULL
;
21435 case DW_TAG_class_type
:
21436 case DW_TAG_interface_type
:
21437 case DW_TAG_structure_type
:
21438 case DW_TAG_union_type
:
21439 this_type
= read_structure_type (die
, cu
);
21441 case DW_TAG_enumeration_type
:
21442 this_type
= read_enumeration_type (die
, cu
);
21444 case DW_TAG_subprogram
:
21445 case DW_TAG_subroutine_type
:
21446 case DW_TAG_inlined_subroutine
:
21447 this_type
= read_subroutine_type (die
, cu
);
21449 case DW_TAG_array_type
:
21450 this_type
= read_array_type (die
, cu
);
21452 case DW_TAG_set_type
:
21453 this_type
= read_set_type (die
, cu
);
21455 case DW_TAG_pointer_type
:
21456 this_type
= read_tag_pointer_type (die
, cu
);
21458 case DW_TAG_ptr_to_member_type
:
21459 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21461 case DW_TAG_reference_type
:
21462 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21464 case DW_TAG_rvalue_reference_type
:
21465 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21467 case DW_TAG_const_type
:
21468 this_type
= read_tag_const_type (die
, cu
);
21470 case DW_TAG_volatile_type
:
21471 this_type
= read_tag_volatile_type (die
, cu
);
21473 case DW_TAG_restrict_type
:
21474 this_type
= read_tag_restrict_type (die
, cu
);
21476 case DW_TAG_string_type
:
21477 this_type
= read_tag_string_type (die
, cu
);
21479 case DW_TAG_typedef
:
21480 this_type
= read_typedef (die
, cu
);
21482 case DW_TAG_subrange_type
:
21483 this_type
= read_subrange_type (die
, cu
);
21485 case DW_TAG_base_type
:
21486 this_type
= read_base_type (die
, cu
);
21488 case DW_TAG_unspecified_type
:
21489 this_type
= read_unspecified_type (die
, cu
);
21491 case DW_TAG_namespace
:
21492 this_type
= read_namespace_type (die
, cu
);
21494 case DW_TAG_module
:
21495 this_type
= read_module_type (die
, cu
);
21497 case DW_TAG_atomic_type
:
21498 this_type
= read_tag_atomic_type (die
, cu
);
21501 complaint (_("unexpected tag in read_type_die: '%s'"),
21502 dwarf_tag_name (die
->tag
));
21509 /* See if we can figure out if the class lives in a namespace. We do
21510 this by looking for a member function; its demangled name will
21511 contain namespace info, if there is any.
21512 Return the computed name or NULL.
21513 Space for the result is allocated on the objfile's obstack.
21514 This is the full-die version of guess_partial_die_structure_name.
21515 In this case we know DIE has no useful parent. */
21517 static const char *
21518 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21520 struct die_info
*spec_die
;
21521 struct dwarf2_cu
*spec_cu
;
21522 struct die_info
*child
;
21523 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21526 spec_die
= die_specification (die
, &spec_cu
);
21527 if (spec_die
!= NULL
)
21533 for (child
= die
->child
;
21535 child
= child
->sibling
)
21537 if (child
->tag
== DW_TAG_subprogram
)
21539 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21541 if (linkage_name
!= NULL
)
21543 gdb::unique_xmalloc_ptr
<char> actual_name
21544 (language_class_name_from_physname (cu
->language_defn
,
21546 const char *name
= NULL
;
21548 if (actual_name
!= NULL
)
21550 const char *die_name
= dwarf2_name (die
, cu
);
21552 if (die_name
!= NULL
21553 && strcmp (die_name
, actual_name
.get ()) != 0)
21555 /* Strip off the class name from the full name.
21556 We want the prefix. */
21557 int die_name_len
= strlen (die_name
);
21558 int actual_name_len
= strlen (actual_name
.get ());
21559 const char *ptr
= actual_name
.get ();
21561 /* Test for '::' as a sanity check. */
21562 if (actual_name_len
> die_name_len
+ 2
21563 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21564 name
= obstack_strndup (
21565 &objfile
->per_bfd
->storage_obstack
,
21566 ptr
, actual_name_len
- die_name_len
- 2);
21577 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21578 prefix part in such case. See
21579 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21581 static const char *
21582 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21584 struct attribute
*attr
;
21587 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21588 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21591 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21594 attr
= dw2_linkage_name_attr (die
, cu
);
21595 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21598 /* dwarf2_name had to be already called. */
21599 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21601 /* Strip the base name, keep any leading namespaces/classes. */
21602 base
= strrchr (DW_STRING (attr
), ':');
21603 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21606 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21607 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21609 &base
[-1] - DW_STRING (attr
));
21612 /* Return the name of the namespace/class that DIE is defined within,
21613 or "" if we can't tell. The caller should not xfree the result.
21615 For example, if we're within the method foo() in the following
21625 then determine_prefix on foo's die will return "N::C". */
21627 static const char *
21628 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21630 struct dwarf2_per_objfile
*dwarf2_per_objfile
21631 = cu
->per_cu
->dwarf2_per_objfile
;
21632 struct die_info
*parent
, *spec_die
;
21633 struct dwarf2_cu
*spec_cu
;
21634 struct type
*parent_type
;
21635 const char *retval
;
21637 if (cu
->language
!= language_cplus
21638 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21639 && cu
->language
!= language_rust
)
21642 retval
= anonymous_struct_prefix (die
, cu
);
21646 /* We have to be careful in the presence of DW_AT_specification.
21647 For example, with GCC 3.4, given the code
21651 // Definition of N::foo.
21655 then we'll have a tree of DIEs like this:
21657 1: DW_TAG_compile_unit
21658 2: DW_TAG_namespace // N
21659 3: DW_TAG_subprogram // declaration of N::foo
21660 4: DW_TAG_subprogram // definition of N::foo
21661 DW_AT_specification // refers to die #3
21663 Thus, when processing die #4, we have to pretend that we're in
21664 the context of its DW_AT_specification, namely the contex of die
21667 spec_die
= die_specification (die
, &spec_cu
);
21668 if (spec_die
== NULL
)
21669 parent
= die
->parent
;
21672 parent
= spec_die
->parent
;
21676 if (parent
== NULL
)
21678 else if (parent
->building_fullname
)
21681 const char *parent_name
;
21683 /* It has been seen on RealView 2.2 built binaries,
21684 DW_TAG_template_type_param types actually _defined_ as
21685 children of the parent class:
21688 template class <class Enum> Class{};
21689 Class<enum E> class_e;
21691 1: DW_TAG_class_type (Class)
21692 2: DW_TAG_enumeration_type (E)
21693 3: DW_TAG_enumerator (enum1:0)
21694 3: DW_TAG_enumerator (enum2:1)
21696 2: DW_TAG_template_type_param
21697 DW_AT_type DW_FORM_ref_udata (E)
21699 Besides being broken debug info, it can put GDB into an
21700 infinite loop. Consider:
21702 When we're building the full name for Class<E>, we'll start
21703 at Class, and go look over its template type parameters,
21704 finding E. We'll then try to build the full name of E, and
21705 reach here. We're now trying to build the full name of E,
21706 and look over the parent DIE for containing scope. In the
21707 broken case, if we followed the parent DIE of E, we'd again
21708 find Class, and once again go look at its template type
21709 arguments, etc., etc. Simply don't consider such parent die
21710 as source-level parent of this die (it can't be, the language
21711 doesn't allow it), and break the loop here. */
21712 name
= dwarf2_name (die
, cu
);
21713 parent_name
= dwarf2_name (parent
, cu
);
21714 complaint (_("template param type '%s' defined within parent '%s'"),
21715 name
? name
: "<unknown>",
21716 parent_name
? parent_name
: "<unknown>");
21720 switch (parent
->tag
)
21722 case DW_TAG_namespace
:
21723 parent_type
= read_type_die (parent
, cu
);
21724 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21725 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21726 Work around this problem here. */
21727 if (cu
->language
== language_cplus
21728 && strcmp (parent_type
->name (), "::") == 0)
21730 /* We give a name to even anonymous namespaces. */
21731 return parent_type
->name ();
21732 case DW_TAG_class_type
:
21733 case DW_TAG_interface_type
:
21734 case DW_TAG_structure_type
:
21735 case DW_TAG_union_type
:
21736 case DW_TAG_module
:
21737 parent_type
= read_type_die (parent
, cu
);
21738 if (parent_type
->name () != NULL
)
21739 return parent_type
->name ();
21741 /* An anonymous structure is only allowed non-static data
21742 members; no typedefs, no member functions, et cetera.
21743 So it does not need a prefix. */
21745 case DW_TAG_compile_unit
:
21746 case DW_TAG_partial_unit
:
21747 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21748 if (cu
->language
== language_cplus
21749 && !dwarf2_per_objfile
->per_bfd
->types
.empty ()
21750 && die
->child
!= NULL
21751 && (die
->tag
== DW_TAG_class_type
21752 || die
->tag
== DW_TAG_structure_type
21753 || die
->tag
== DW_TAG_union_type
))
21755 const char *name
= guess_full_die_structure_name (die
, cu
);
21760 case DW_TAG_subprogram
:
21761 /* Nested subroutines in Fortran get a prefix with the name
21762 of the parent's subroutine. */
21763 if (cu
->language
== language_fortran
)
21765 if ((die
->tag
== DW_TAG_subprogram
)
21766 && (dwarf2_name (parent
, cu
) != NULL
))
21767 return dwarf2_name (parent
, cu
);
21769 return determine_prefix (parent
, cu
);
21770 case DW_TAG_enumeration_type
:
21771 parent_type
= read_type_die (parent
, cu
);
21772 if (TYPE_DECLARED_CLASS (parent_type
))
21774 if (parent_type
->name () != NULL
)
21775 return parent_type
->name ();
21778 /* Fall through. */
21780 return determine_prefix (parent
, cu
);
21784 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21785 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21786 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21787 an obconcat, otherwise allocate storage for the result. The CU argument is
21788 used to determine the language and hence, the appropriate separator. */
21790 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21793 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21794 int physname
, struct dwarf2_cu
*cu
)
21796 const char *lead
= "";
21799 if (suffix
== NULL
|| suffix
[0] == '\0'
21800 || prefix
== NULL
|| prefix
[0] == '\0')
21802 else if (cu
->language
== language_d
)
21804 /* For D, the 'main' function could be defined in any module, but it
21805 should never be prefixed. */
21806 if (strcmp (suffix
, "D main") == 0)
21814 else if (cu
->language
== language_fortran
&& physname
)
21816 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21817 DW_AT_MIPS_linkage_name is preferred and used instead. */
21825 if (prefix
== NULL
)
21827 if (suffix
== NULL
)
21834 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21836 strcpy (retval
, lead
);
21837 strcat (retval
, prefix
);
21838 strcat (retval
, sep
);
21839 strcat (retval
, suffix
);
21844 /* We have an obstack. */
21845 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21849 /* Get name of a die, return NULL if not found. */
21851 static const char *
21852 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21853 struct objfile
*objfile
)
21855 if (name
&& cu
->language
== language_cplus
)
21857 gdb::unique_xmalloc_ptr
<char> canon_name
21858 = cp_canonicalize_string (name
);
21860 if (canon_name
!= nullptr)
21861 name
= objfile
->intern (canon_name
.get ());
21867 /* Get name of a die, return NULL if not found.
21868 Anonymous namespaces are converted to their magic string. */
21870 static const char *
21871 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21873 struct attribute
*attr
;
21874 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21876 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21877 if ((!attr
|| !DW_STRING (attr
))
21878 && die
->tag
!= DW_TAG_namespace
21879 && die
->tag
!= DW_TAG_class_type
21880 && die
->tag
!= DW_TAG_interface_type
21881 && die
->tag
!= DW_TAG_structure_type
21882 && die
->tag
!= DW_TAG_union_type
)
21887 case DW_TAG_compile_unit
:
21888 case DW_TAG_partial_unit
:
21889 /* Compilation units have a DW_AT_name that is a filename, not
21890 a source language identifier. */
21891 case DW_TAG_enumeration_type
:
21892 case DW_TAG_enumerator
:
21893 /* These tags always have simple identifiers already; no need
21894 to canonicalize them. */
21895 return DW_STRING (attr
);
21897 case DW_TAG_namespace
:
21898 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21899 return DW_STRING (attr
);
21900 return CP_ANONYMOUS_NAMESPACE_STR
;
21902 case DW_TAG_class_type
:
21903 case DW_TAG_interface_type
:
21904 case DW_TAG_structure_type
:
21905 case DW_TAG_union_type
:
21906 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21907 structures or unions. These were of the form "._%d" in GCC 4.1,
21908 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21909 and GCC 4.4. We work around this problem by ignoring these. */
21910 if (attr
&& DW_STRING (attr
)
21911 && (startswith (DW_STRING (attr
), "._")
21912 || startswith (DW_STRING (attr
), "<anonymous")))
21915 /* GCC might emit a nameless typedef that has a linkage name. See
21916 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21917 if (!attr
|| DW_STRING (attr
) == NULL
)
21919 attr
= dw2_linkage_name_attr (die
, cu
);
21920 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21923 /* Avoid demangling DW_STRING (attr) the second time on a second
21924 call for the same DIE. */
21925 if (!DW_STRING_IS_CANONICAL (attr
))
21927 gdb::unique_xmalloc_ptr
<char> demangled
21928 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21929 if (demangled
== nullptr)
21932 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21933 DW_STRING_IS_CANONICAL (attr
) = 1;
21936 /* Strip any leading namespaces/classes, keep only the base name.
21937 DW_AT_name for named DIEs does not contain the prefixes. */
21938 const char *base
= strrchr (DW_STRING (attr
), ':');
21939 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21942 return DW_STRING (attr
);
21950 if (!DW_STRING_IS_CANONICAL (attr
))
21952 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21954 DW_STRING_IS_CANONICAL (attr
) = 1;
21956 return DW_STRING (attr
);
21959 /* Return the die that this die in an extension of, or NULL if there
21960 is none. *EXT_CU is the CU containing DIE on input, and the CU
21961 containing the return value on output. */
21963 static struct die_info
*
21964 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21966 struct attribute
*attr
;
21968 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21972 return follow_die_ref (die
, attr
, ext_cu
);
21976 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21980 print_spaces (indent
, f
);
21981 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21982 dwarf_tag_name (die
->tag
), die
->abbrev
,
21983 sect_offset_str (die
->sect_off
));
21985 if (die
->parent
!= NULL
)
21987 print_spaces (indent
, f
);
21988 fprintf_unfiltered (f
, " parent at offset: %s\n",
21989 sect_offset_str (die
->parent
->sect_off
));
21992 print_spaces (indent
, f
);
21993 fprintf_unfiltered (f
, " has children: %s\n",
21994 dwarf_bool_name (die
->child
!= NULL
));
21996 print_spaces (indent
, f
);
21997 fprintf_unfiltered (f
, " attributes:\n");
21999 for (i
= 0; i
< die
->num_attrs
; ++i
)
22001 print_spaces (indent
, f
);
22002 fprintf_unfiltered (f
, " %s (%s) ",
22003 dwarf_attr_name (die
->attrs
[i
].name
),
22004 dwarf_form_name (die
->attrs
[i
].form
));
22006 switch (die
->attrs
[i
].form
)
22009 case DW_FORM_addrx
:
22010 case DW_FORM_GNU_addr_index
:
22011 fprintf_unfiltered (f
, "address: ");
22012 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22014 case DW_FORM_block2
:
22015 case DW_FORM_block4
:
22016 case DW_FORM_block
:
22017 case DW_FORM_block1
:
22018 fprintf_unfiltered (f
, "block: size %s",
22019 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22021 case DW_FORM_exprloc
:
22022 fprintf_unfiltered (f
, "expression: size %s",
22023 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22025 case DW_FORM_data16
:
22026 fprintf_unfiltered (f
, "constant of 16 bytes");
22028 case DW_FORM_ref_addr
:
22029 fprintf_unfiltered (f
, "ref address: ");
22030 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22032 case DW_FORM_GNU_ref_alt
:
22033 fprintf_unfiltered (f
, "alt ref address: ");
22034 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22040 case DW_FORM_ref_udata
:
22041 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22042 (long) (DW_UNSND (&die
->attrs
[i
])));
22044 case DW_FORM_data1
:
22045 case DW_FORM_data2
:
22046 case DW_FORM_data4
:
22047 case DW_FORM_data8
:
22048 case DW_FORM_udata
:
22049 case DW_FORM_sdata
:
22050 fprintf_unfiltered (f
, "constant: %s",
22051 pulongest (DW_UNSND (&die
->attrs
[i
])));
22053 case DW_FORM_sec_offset
:
22054 fprintf_unfiltered (f
, "section offset: %s",
22055 pulongest (DW_UNSND (&die
->attrs
[i
])));
22057 case DW_FORM_ref_sig8
:
22058 fprintf_unfiltered (f
, "signature: %s",
22059 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22061 case DW_FORM_string
:
22063 case DW_FORM_line_strp
:
22065 case DW_FORM_GNU_str_index
:
22066 case DW_FORM_GNU_strp_alt
:
22067 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22068 DW_STRING (&die
->attrs
[i
])
22069 ? DW_STRING (&die
->attrs
[i
]) : "",
22070 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22073 if (DW_UNSND (&die
->attrs
[i
]))
22074 fprintf_unfiltered (f
, "flag: TRUE");
22076 fprintf_unfiltered (f
, "flag: FALSE");
22078 case DW_FORM_flag_present
:
22079 fprintf_unfiltered (f
, "flag: TRUE");
22081 case DW_FORM_indirect
:
22082 /* The reader will have reduced the indirect form to
22083 the "base form" so this form should not occur. */
22084 fprintf_unfiltered (f
,
22085 "unexpected attribute form: DW_FORM_indirect");
22087 case DW_FORM_implicit_const
:
22088 fprintf_unfiltered (f
, "constant: %s",
22089 plongest (DW_SND (&die
->attrs
[i
])));
22092 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22093 die
->attrs
[i
].form
);
22096 fprintf_unfiltered (f
, "\n");
22101 dump_die_for_error (struct die_info
*die
)
22103 dump_die_shallow (gdb_stderr
, 0, die
);
22107 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22109 int indent
= level
* 4;
22111 gdb_assert (die
!= NULL
);
22113 if (level
>= max_level
)
22116 dump_die_shallow (f
, indent
, die
);
22118 if (die
->child
!= NULL
)
22120 print_spaces (indent
, f
);
22121 fprintf_unfiltered (f
, " Children:");
22122 if (level
+ 1 < max_level
)
22124 fprintf_unfiltered (f
, "\n");
22125 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22129 fprintf_unfiltered (f
,
22130 " [not printed, max nesting level reached]\n");
22134 if (die
->sibling
!= NULL
&& level
> 0)
22136 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22140 /* This is called from the pdie macro in gdbinit.in.
22141 It's not static so gcc will keep a copy callable from gdb. */
22144 dump_die (struct die_info
*die
, int max_level
)
22146 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22150 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22154 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22155 to_underlying (die
->sect_off
),
22161 /* Follow reference or signature attribute ATTR of SRC_DIE.
22162 On entry *REF_CU is the CU of SRC_DIE.
22163 On exit *REF_CU is the CU of the result. */
22165 static struct die_info
*
22166 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22167 struct dwarf2_cu
**ref_cu
)
22169 struct die_info
*die
;
22171 if (attr
->form_is_ref ())
22172 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22173 else if (attr
->form
== DW_FORM_ref_sig8
)
22174 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22177 dump_die_for_error (src_die
);
22178 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22179 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22185 /* Follow reference OFFSET.
22186 On entry *REF_CU is the CU of the source die referencing OFFSET.
22187 On exit *REF_CU is the CU of the result.
22188 Returns NULL if OFFSET is invalid. */
22190 static struct die_info
*
22191 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22192 struct dwarf2_cu
**ref_cu
)
22194 struct die_info temp_die
;
22195 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22196 struct dwarf2_per_objfile
*dwarf2_per_objfile
22197 = cu
->per_cu
->dwarf2_per_objfile
;
22199 gdb_assert (cu
->per_cu
!= NULL
);
22203 if (cu
->per_cu
->is_debug_types
)
22205 /* .debug_types CUs cannot reference anything outside their CU.
22206 If they need to, they have to reference a signatured type via
22207 DW_FORM_ref_sig8. */
22208 if (!cu
->header
.offset_in_cu_p (sect_off
))
22211 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22212 || !cu
->header
.offset_in_cu_p (sect_off
))
22214 struct dwarf2_per_cu_data
*per_cu
;
22216 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22217 dwarf2_per_objfile
);
22219 /* If necessary, add it to the queue and load its DIEs. */
22220 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22221 load_full_comp_unit (per_cu
, false, cu
->language
);
22223 target_cu
= per_cu
->cu
;
22225 else if (cu
->dies
== NULL
)
22227 /* We're loading full DIEs during partial symbol reading. */
22228 gdb_assert (dwarf2_per_objfile
->per_bfd
->reading_partial_symbols
);
22229 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22232 *ref_cu
= target_cu
;
22233 temp_die
.sect_off
= sect_off
;
22235 if (target_cu
!= cu
)
22236 target_cu
->ancestor
= cu
;
22238 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22240 to_underlying (sect_off
));
22243 /* Follow reference attribute ATTR of SRC_DIE.
22244 On entry *REF_CU is the CU of SRC_DIE.
22245 On exit *REF_CU is the CU of the result. */
22247 static struct die_info
*
22248 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22249 struct dwarf2_cu
**ref_cu
)
22251 sect_offset sect_off
= attr
->get_ref_die_offset ();
22252 struct dwarf2_cu
*cu
= *ref_cu
;
22253 struct die_info
*die
;
22255 die
= follow_die_offset (sect_off
,
22256 (attr
->form
== DW_FORM_GNU_ref_alt
22257 || cu
->per_cu
->is_dwz
),
22260 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22261 "at %s [in module %s]"),
22262 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22263 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22270 struct dwarf2_locexpr_baton
22271 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22272 dwarf2_per_cu_data
*per_cu
,
22273 CORE_ADDR (*get_frame_pc
) (void *baton
),
22274 void *baton
, bool resolve_abstract_p
)
22276 struct dwarf2_cu
*cu
;
22277 struct die_info
*die
;
22278 struct attribute
*attr
;
22279 struct dwarf2_locexpr_baton retval
;
22280 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22281 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22283 if (per_cu
->cu
== NULL
)
22284 load_cu (per_cu
, false);
22288 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22289 Instead just throw an error, not much else we can do. */
22290 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22291 sect_offset_str (sect_off
), objfile_name (objfile
));
22294 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22296 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22297 sect_offset_str (sect_off
), objfile_name (objfile
));
22299 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22300 if (!attr
&& resolve_abstract_p
22301 && (dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
22302 != dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
22304 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22305 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22306 struct gdbarch
*gdbarch
= objfile
->arch ();
22308 for (const auto &cand_off
22309 : dwarf2_per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
22311 struct dwarf2_cu
*cand_cu
= cu
;
22312 struct die_info
*cand
22313 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22316 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22319 CORE_ADDR pc_low
, pc_high
;
22320 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22321 if (pc_low
== ((CORE_ADDR
) -1))
22323 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22324 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22325 if (!(pc_low
<= pc
&& pc
< pc_high
))
22329 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22336 /* DWARF: "If there is no such attribute, then there is no effect.".
22337 DATA is ignored if SIZE is 0. */
22339 retval
.data
= NULL
;
22342 else if (attr
->form_is_section_offset ())
22344 struct dwarf2_loclist_baton loclist_baton
;
22345 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22348 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22350 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22352 retval
.size
= size
;
22356 if (!attr
->form_is_block ())
22357 error (_("Dwarf Error: DIE at %s referenced in module %s "
22358 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22359 sect_offset_str (sect_off
), objfile_name (objfile
));
22361 retval
.data
= DW_BLOCK (attr
)->data
;
22362 retval
.size
= DW_BLOCK (attr
)->size
;
22364 retval
.per_objfile
= dwarf2_per_objfile
;
22365 retval
.per_cu
= cu
->per_cu
;
22367 age_cached_comp_units (dwarf2_per_objfile
);
22374 struct dwarf2_locexpr_baton
22375 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22376 dwarf2_per_cu_data
*per_cu
,
22377 CORE_ADDR (*get_frame_pc
) (void *baton
),
22380 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22382 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22385 /* Write a constant of a given type as target-ordered bytes into
22388 static const gdb_byte
*
22389 write_constant_as_bytes (struct obstack
*obstack
,
22390 enum bfd_endian byte_order
,
22397 *len
= TYPE_LENGTH (type
);
22398 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22399 store_unsigned_integer (result
, *len
, byte_order
, value
);
22407 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22408 dwarf2_per_cu_data
*per_cu
,
22412 struct dwarf2_cu
*cu
;
22413 struct die_info
*die
;
22414 struct attribute
*attr
;
22415 const gdb_byte
*result
= NULL
;
22418 enum bfd_endian byte_order
;
22419 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22421 if (per_cu
->cu
== NULL
)
22422 load_cu (per_cu
, false);
22426 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22427 Instead just throw an error, not much else we can do. */
22428 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22429 sect_offset_str (sect_off
), objfile_name (objfile
));
22432 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22434 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22435 sect_offset_str (sect_off
), objfile_name (objfile
));
22437 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22441 byte_order
= (bfd_big_endian (objfile
->obfd
)
22442 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22444 switch (attr
->form
)
22447 case DW_FORM_addrx
:
22448 case DW_FORM_GNU_addr_index
:
22452 *len
= cu
->header
.addr_size
;
22453 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22454 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22458 case DW_FORM_string
:
22461 case DW_FORM_GNU_str_index
:
22462 case DW_FORM_GNU_strp_alt
:
22463 /* DW_STRING is already allocated on the objfile obstack, point
22465 result
= (const gdb_byte
*) DW_STRING (attr
);
22466 *len
= strlen (DW_STRING (attr
));
22468 case DW_FORM_block1
:
22469 case DW_FORM_block2
:
22470 case DW_FORM_block4
:
22471 case DW_FORM_block
:
22472 case DW_FORM_exprloc
:
22473 case DW_FORM_data16
:
22474 result
= DW_BLOCK (attr
)->data
;
22475 *len
= DW_BLOCK (attr
)->size
;
22478 /* The DW_AT_const_value attributes are supposed to carry the
22479 symbol's value "represented as it would be on the target
22480 architecture." By the time we get here, it's already been
22481 converted to host endianness, so we just need to sign- or
22482 zero-extend it as appropriate. */
22483 case DW_FORM_data1
:
22484 type
= die_type (die
, cu
);
22485 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22486 if (result
== NULL
)
22487 result
= write_constant_as_bytes (obstack
, byte_order
,
22490 case DW_FORM_data2
:
22491 type
= die_type (die
, cu
);
22492 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22493 if (result
== NULL
)
22494 result
= write_constant_as_bytes (obstack
, byte_order
,
22497 case DW_FORM_data4
:
22498 type
= die_type (die
, cu
);
22499 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22500 if (result
== NULL
)
22501 result
= write_constant_as_bytes (obstack
, byte_order
,
22504 case DW_FORM_data8
:
22505 type
= die_type (die
, cu
);
22506 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22507 if (result
== NULL
)
22508 result
= write_constant_as_bytes (obstack
, byte_order
,
22512 case DW_FORM_sdata
:
22513 case DW_FORM_implicit_const
:
22514 type
= die_type (die
, cu
);
22515 result
= write_constant_as_bytes (obstack
, byte_order
,
22516 type
, DW_SND (attr
), len
);
22519 case DW_FORM_udata
:
22520 type
= die_type (die
, cu
);
22521 result
= write_constant_as_bytes (obstack
, byte_order
,
22522 type
, DW_UNSND (attr
), len
);
22526 complaint (_("unsupported const value attribute form: '%s'"),
22527 dwarf_form_name (attr
->form
));
22537 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22538 dwarf2_per_cu_data
*per_cu
)
22540 struct dwarf2_cu
*cu
;
22541 struct die_info
*die
;
22543 if (per_cu
->cu
== NULL
)
22544 load_cu (per_cu
, false);
22549 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22553 return die_type (die
, cu
);
22559 dwarf2_get_die_type (cu_offset die_offset
,
22560 struct dwarf2_per_cu_data
*per_cu
)
22562 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22563 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22566 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22567 On entry *REF_CU is the CU of SRC_DIE.
22568 On exit *REF_CU is the CU of the result.
22569 Returns NULL if the referenced DIE isn't found. */
22571 static struct die_info
*
22572 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22573 struct dwarf2_cu
**ref_cu
)
22575 struct die_info temp_die
;
22576 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22577 struct die_info
*die
;
22579 /* While it might be nice to assert sig_type->type == NULL here,
22580 we can get here for DW_AT_imported_declaration where we need
22581 the DIE not the type. */
22583 /* If necessary, add it to the queue and load its DIEs. */
22585 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22586 read_signatured_type (sig_type
);
22588 sig_cu
= sig_type
->per_cu
.cu
;
22589 gdb_assert (sig_cu
!= NULL
);
22590 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22591 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22592 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22593 to_underlying (temp_die
.sect_off
));
22596 struct dwarf2_per_objfile
*dwarf2_per_objfile
22597 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22599 /* For .gdb_index version 7 keep track of included TUs.
22600 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22601 if (dwarf2_per_objfile
->per_bfd
->index_table
!= NULL
22602 && dwarf2_per_objfile
->per_bfd
->index_table
->version
<= 7)
22604 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22609 sig_cu
->ancestor
= cu
;
22617 /* Follow signatured type referenced by ATTR in SRC_DIE.
22618 On entry *REF_CU is the CU of SRC_DIE.
22619 On exit *REF_CU is the CU of the result.
22620 The result is the DIE of the type.
22621 If the referenced type cannot be found an error is thrown. */
22623 static struct die_info
*
22624 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22625 struct dwarf2_cu
**ref_cu
)
22627 ULONGEST signature
= DW_SIGNATURE (attr
);
22628 struct signatured_type
*sig_type
;
22629 struct die_info
*die
;
22631 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22633 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22634 /* sig_type will be NULL if the signatured type is missing from
22636 if (sig_type
== NULL
)
22638 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22639 " from DIE at %s [in module %s]"),
22640 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22641 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22644 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22647 dump_die_for_error (src_die
);
22648 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22649 " from DIE at %s [in module %s]"),
22650 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22651 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22657 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22658 reading in and processing the type unit if necessary. */
22660 static struct type
*
22661 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22662 struct dwarf2_cu
*cu
)
22664 struct dwarf2_per_objfile
*dwarf2_per_objfile
22665 = cu
->per_cu
->dwarf2_per_objfile
;
22666 struct signatured_type
*sig_type
;
22667 struct dwarf2_cu
*type_cu
;
22668 struct die_info
*type_die
;
22671 sig_type
= lookup_signatured_type (cu
, signature
);
22672 /* sig_type will be NULL if the signatured type is missing from
22674 if (sig_type
== NULL
)
22676 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22677 " from DIE at %s [in module %s]"),
22678 hex_string (signature
), sect_offset_str (die
->sect_off
),
22679 objfile_name (dwarf2_per_objfile
->objfile
));
22680 return build_error_marker_type (cu
, die
);
22683 /* If we already know the type we're done. */
22684 if (sig_type
->type
!= NULL
)
22685 return sig_type
->type
;
22688 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22689 if (type_die
!= NULL
)
22691 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22692 is created. This is important, for example, because for c++ classes
22693 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22694 type
= read_type_die (type_die
, type_cu
);
22697 complaint (_("Dwarf Error: Cannot build signatured type %s"
22698 " referenced from DIE at %s [in module %s]"),
22699 hex_string (signature
), sect_offset_str (die
->sect_off
),
22700 objfile_name (dwarf2_per_objfile
->objfile
));
22701 type
= build_error_marker_type (cu
, die
);
22706 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22707 " from DIE at %s [in module %s]"),
22708 hex_string (signature
), sect_offset_str (die
->sect_off
),
22709 objfile_name (dwarf2_per_objfile
->objfile
));
22710 type
= build_error_marker_type (cu
, die
);
22712 sig_type
->type
= type
;
22717 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22718 reading in and processing the type unit if necessary. */
22720 static struct type
*
22721 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22722 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22724 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22725 if (attr
->form_is_ref ())
22727 struct dwarf2_cu
*type_cu
= cu
;
22728 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22730 return read_type_die (type_die
, type_cu
);
22732 else if (attr
->form
== DW_FORM_ref_sig8
)
22734 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22738 struct dwarf2_per_objfile
*dwarf2_per_objfile
22739 = cu
->per_cu
->dwarf2_per_objfile
;
22741 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22742 " at %s [in module %s]"),
22743 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22744 objfile_name (dwarf2_per_objfile
->objfile
));
22745 return build_error_marker_type (cu
, die
);
22749 /* Load the DIEs associated with type unit PER_CU into memory. */
22752 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22754 struct signatured_type
*sig_type
;
22756 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22757 gdb_assert (! per_cu
->type_unit_group_p ());
22759 /* We have the per_cu, but we need the signatured_type.
22760 Fortunately this is an easy translation. */
22761 gdb_assert (per_cu
->is_debug_types
);
22762 sig_type
= (struct signatured_type
*) per_cu
;
22764 gdb_assert (per_cu
->cu
== NULL
);
22766 read_signatured_type (sig_type
);
22768 gdb_assert (per_cu
->cu
!= NULL
);
22771 /* Read in a signatured type and build its CU and DIEs.
22772 If the type is a stub for the real type in a DWO file,
22773 read in the real type from the DWO file as well. */
22776 read_signatured_type (struct signatured_type
*sig_type
)
22778 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22780 gdb_assert (per_cu
->is_debug_types
);
22781 gdb_assert (per_cu
->cu
== NULL
);
22783 cutu_reader
reader (per_cu
, NULL
, 0, false);
22785 if (!reader
.dummy_p
)
22787 struct dwarf2_cu
*cu
= reader
.cu
;
22788 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22790 gdb_assert (cu
->die_hash
== NULL
);
22792 htab_create_alloc_ex (cu
->header
.length
/ 12,
22796 &cu
->comp_unit_obstack
,
22797 hashtab_obstack_allocate
,
22798 dummy_obstack_deallocate
);
22800 if (reader
.comp_unit_die
->has_children
)
22801 reader
.comp_unit_die
->child
22802 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22803 reader
.comp_unit_die
);
22804 cu
->dies
= reader
.comp_unit_die
;
22805 /* comp_unit_die is not stored in die_hash, no need. */
22807 /* We try not to read any attributes in this function, because
22808 not all CUs needed for references have been loaded yet, and
22809 symbol table processing isn't initialized. But we have to
22810 set the CU language, or we won't be able to build types
22811 correctly. Similarly, if we do not read the producer, we can
22812 not apply producer-specific interpretation. */
22813 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22818 sig_type
->per_cu
.tu_read
= 1;
22821 /* Decode simple location descriptions.
22822 Given a pointer to a dwarf block that defines a location, compute
22823 the location and return the value. If COMPUTED is non-null, it is
22824 set to true to indicate that decoding was successful, and false
22825 otherwise. If COMPUTED is null, then this function may emit a
22829 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
22831 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22833 size_t size
= blk
->size
;
22834 const gdb_byte
*data
= blk
->data
;
22835 CORE_ADDR stack
[64];
22837 unsigned int bytes_read
, unsnd
;
22840 if (computed
!= nullptr)
22846 stack
[++stacki
] = 0;
22885 stack
[++stacki
] = op
- DW_OP_lit0
;
22920 stack
[++stacki
] = op
- DW_OP_reg0
;
22923 if (computed
== nullptr)
22924 dwarf2_complex_location_expr_complaint ();
22931 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22933 stack
[++stacki
] = unsnd
;
22936 if (computed
== nullptr)
22937 dwarf2_complex_location_expr_complaint ();
22944 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22949 case DW_OP_const1u
:
22950 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22954 case DW_OP_const1s
:
22955 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22959 case DW_OP_const2u
:
22960 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22964 case DW_OP_const2s
:
22965 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22969 case DW_OP_const4u
:
22970 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22974 case DW_OP_const4s
:
22975 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22979 case DW_OP_const8u
:
22980 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22985 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22991 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22996 stack
[stacki
+ 1] = stack
[stacki
];
23001 stack
[stacki
- 1] += stack
[stacki
];
23005 case DW_OP_plus_uconst
:
23006 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23012 stack
[stacki
- 1] -= stack
[stacki
];
23017 /* If we're not the last op, then we definitely can't encode
23018 this using GDB's address_class enum. This is valid for partial
23019 global symbols, although the variable's address will be bogus
23023 if (computed
== nullptr)
23024 dwarf2_complex_location_expr_complaint ();
23030 case DW_OP_GNU_push_tls_address
:
23031 case DW_OP_form_tls_address
:
23032 /* The top of the stack has the offset from the beginning
23033 of the thread control block at which the variable is located. */
23034 /* Nothing should follow this operator, so the top of stack would
23036 /* This is valid for partial global symbols, but the variable's
23037 address will be bogus in the psymtab. Make it always at least
23038 non-zero to not look as a variable garbage collected by linker
23039 which have DW_OP_addr 0. */
23042 if (computed
== nullptr)
23043 dwarf2_complex_location_expr_complaint ();
23050 case DW_OP_GNU_uninit
:
23051 if (computed
!= nullptr)
23056 case DW_OP_GNU_addr_index
:
23057 case DW_OP_GNU_const_index
:
23058 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23064 if (computed
== nullptr)
23066 const char *name
= get_DW_OP_name (op
);
23069 complaint (_("unsupported stack op: '%s'"),
23072 complaint (_("unsupported stack op: '%02x'"),
23076 return (stack
[stacki
]);
23079 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23080 outside of the allocated space. Also enforce minimum>0. */
23081 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23083 if (computed
== nullptr)
23084 complaint (_("location description stack overflow"));
23090 if (computed
== nullptr)
23091 complaint (_("location description stack underflow"));
23096 if (computed
!= nullptr)
23098 return (stack
[stacki
]);
23101 /* memory allocation interface */
23103 static struct dwarf_block
*
23104 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23106 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23109 static struct die_info
*
23110 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23112 struct die_info
*die
;
23113 size_t size
= sizeof (struct die_info
);
23116 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23118 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23119 memset (die
, 0, sizeof (struct die_info
));
23125 /* Macro support. */
23127 /* An overload of dwarf_decode_macros that finds the correct section
23128 and ensures it is read in before calling the other overload. */
23131 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23132 int section_is_gnu
)
23134 struct dwarf2_per_objfile
*dwarf2_per_objfile
23135 = cu
->per_cu
->dwarf2_per_objfile
;
23136 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23137 const struct line_header
*lh
= cu
->line_header
;
23138 unsigned int offset_size
= cu
->header
.offset_size
;
23139 struct dwarf2_section_info
*section
;
23140 const char *section_name
;
23142 if (cu
->dwo_unit
!= nullptr)
23144 if (section_is_gnu
)
23146 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23147 section_name
= ".debug_macro.dwo";
23151 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23152 section_name
= ".debug_macinfo.dwo";
23157 if (section_is_gnu
)
23159 section
= &dwarf2_per_objfile
->per_bfd
->macro
;
23160 section_name
= ".debug_macro";
23164 section
= &dwarf2_per_objfile
->per_bfd
->macinfo
;
23165 section_name
= ".debug_macinfo";
23169 section
->read (objfile
);
23170 if (section
->buffer
== nullptr)
23172 complaint (_("missing %s section"), section_name
);
23176 buildsym_compunit
*builder
= cu
->get_builder ();
23178 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
23179 offset_size
, offset
, section_is_gnu
);
23182 /* Return the .debug_loc section to use for CU.
23183 For DWO files use .debug_loc.dwo. */
23185 static struct dwarf2_section_info
*
23186 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23188 struct dwarf2_per_objfile
*dwarf2_per_objfile
23189 = cu
->per_cu
->dwarf2_per_objfile
;
23193 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23195 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23197 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->per_bfd
->loclists
23198 : &dwarf2_per_objfile
->per_bfd
->loc
);
23201 /* A helper function that fills in a dwarf2_loclist_baton. */
23204 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23205 struct dwarf2_loclist_baton
*baton
,
23206 const struct attribute
*attr
)
23208 struct dwarf2_per_objfile
*dwarf2_per_objfile
23209 = cu
->per_cu
->dwarf2_per_objfile
;
23210 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23212 section
->read (dwarf2_per_objfile
->objfile
);
23214 baton
->per_objfile
= dwarf2_per_objfile
;
23215 baton
->per_cu
= cu
->per_cu
;
23216 gdb_assert (baton
->per_cu
);
23217 /* We don't know how long the location list is, but make sure we
23218 don't run off the edge of the section. */
23219 baton
->size
= section
->size
- DW_UNSND (attr
);
23220 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23221 if (cu
->base_address
.has_value ())
23222 baton
->base_address
= *cu
->base_address
;
23224 baton
->base_address
= 0;
23225 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23229 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23230 struct dwarf2_cu
*cu
, int is_block
)
23232 struct dwarf2_per_objfile
*dwarf2_per_objfile
23233 = cu
->per_cu
->dwarf2_per_objfile
;
23234 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23235 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23237 if (attr
->form_is_section_offset ()
23238 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23239 the section. If so, fall through to the complaint in the
23241 && DW_UNSND (attr
) < section
->get_size (objfile
))
23243 struct dwarf2_loclist_baton
*baton
;
23245 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23247 fill_in_loclist_baton (cu
, baton
, attr
);
23249 if (!cu
->base_address
.has_value ())
23250 complaint (_("Location list used without "
23251 "specifying the CU base address."));
23253 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23254 ? dwarf2_loclist_block_index
23255 : dwarf2_loclist_index
);
23256 SYMBOL_LOCATION_BATON (sym
) = baton
;
23260 struct dwarf2_locexpr_baton
*baton
;
23262 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
23263 baton
->per_objfile
= dwarf2_per_objfile
;
23264 baton
->per_cu
= cu
->per_cu
;
23265 gdb_assert (baton
->per_cu
);
23267 if (attr
->form_is_block ())
23269 /* Note that we're just copying the block's data pointer
23270 here, not the actual data. We're still pointing into the
23271 info_buffer for SYM's objfile; right now we never release
23272 that buffer, but when we do clean up properly this may
23274 baton
->size
= DW_BLOCK (attr
)->size
;
23275 baton
->data
= DW_BLOCK (attr
)->data
;
23279 dwarf2_invalid_attrib_class_complaint ("location description",
23280 sym
->natural_name ());
23284 SYMBOL_ACLASS_INDEX (sym
) = (is_block
23285 ? dwarf2_locexpr_block_index
23286 : dwarf2_locexpr_index
);
23287 SYMBOL_LOCATION_BATON (sym
) = baton
;
23294 dwarf2_per_cu_data::objfile () const
23296 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23298 /* Return the master objfile, so that we can report and look up the
23299 correct file containing this variable. */
23300 if (objfile
->separate_debug_objfile_backlink
)
23301 objfile
= objfile
->separate_debug_objfile_backlink
;
23306 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
23307 (CU_HEADERP is unused in such case) or prepare a temporary copy at
23308 CU_HEADERP first. */
23310 static const struct comp_unit_head
*
23311 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
23312 const struct dwarf2_per_cu_data
*per_cu
)
23314 const gdb_byte
*info_ptr
;
23317 return &per_cu
->cu
->header
;
23319 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
23321 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
23322 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
23323 rcuh_kind::COMPILE
);
23331 dwarf2_per_cu_data::addr_size () const
23333 struct comp_unit_head cu_header_local
;
23334 const struct comp_unit_head
*cu_headerp
;
23336 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23338 return cu_headerp
->addr_size
;
23344 dwarf2_per_cu_data::offset_size () const
23346 struct comp_unit_head cu_header_local
;
23347 const struct comp_unit_head
*cu_headerp
;
23349 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23351 return cu_headerp
->offset_size
;
23357 dwarf2_per_cu_data::ref_addr_size () const
23359 struct comp_unit_head cu_header_local
;
23360 const struct comp_unit_head
*cu_headerp
;
23362 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
23364 if (cu_headerp
->version
== 2)
23365 return cu_headerp
->addr_size
;
23367 return cu_headerp
->offset_size
;
23373 dwarf2_per_cu_data::text_offset () const
23375 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23377 return objfile
->text_section_offset ();
23383 dwarf2_per_cu_data::addr_type () const
23385 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23386 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
23387 struct type
*addr_type
= lookup_pointer_type (void_type
);
23388 int addr_size
= this->addr_size ();
23390 if (TYPE_LENGTH (addr_type
) == addr_size
)
23393 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
23397 /* A helper function for dwarf2_find_containing_comp_unit that returns
23398 the index of the result, and that searches a vector. It will
23399 return a result even if the offset in question does not actually
23400 occur in any CU. This is separate so that it can be unit
23404 dwarf2_find_containing_comp_unit
23405 (sect_offset sect_off
,
23406 unsigned int offset_in_dwz
,
23407 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
23412 high
= all_comp_units
.size () - 1;
23415 struct dwarf2_per_cu_data
*mid_cu
;
23416 int mid
= low
+ (high
- low
) / 2;
23418 mid_cu
= all_comp_units
[mid
];
23419 if (mid_cu
->is_dwz
> offset_in_dwz
23420 || (mid_cu
->is_dwz
== offset_in_dwz
23421 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23426 gdb_assert (low
== high
);
23430 /* Locate the .debug_info compilation unit from CU's objfile which contains
23431 the DIE at OFFSET. Raises an error on failure. */
23433 static struct dwarf2_per_cu_data
*
23434 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23435 unsigned int offset_in_dwz
,
23436 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23439 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23440 dwarf2_per_objfile
->per_bfd
->all_comp_units
);
23441 struct dwarf2_per_cu_data
*this_cu
23442 = dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
];
23444 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23446 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23447 error (_("Dwarf Error: could not find partial DIE containing "
23448 "offset %s [in module %s]"),
23449 sect_offset_str (sect_off
),
23450 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23452 gdb_assert (dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
23454 return dwarf2_per_objfile
->per_bfd
->all_comp_units
[low
-1];
23458 if (low
== dwarf2_per_objfile
->per_bfd
->all_comp_units
.size () - 1
23459 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23460 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23461 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23468 namespace selftests
{
23469 namespace find_containing_comp_unit
{
23474 struct dwarf2_per_cu_data one
{};
23475 struct dwarf2_per_cu_data two
{};
23476 struct dwarf2_per_cu_data three
{};
23477 struct dwarf2_per_cu_data four
{};
23480 two
.sect_off
= sect_offset (one
.length
);
23485 four
.sect_off
= sect_offset (three
.length
);
23489 std::vector
<dwarf2_per_cu_data
*> units
;
23490 units
.push_back (&one
);
23491 units
.push_back (&two
);
23492 units
.push_back (&three
);
23493 units
.push_back (&four
);
23497 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23498 SELF_CHECK (units
[result
] == &one
);
23499 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23500 SELF_CHECK (units
[result
] == &one
);
23501 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23502 SELF_CHECK (units
[result
] == &two
);
23504 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23505 SELF_CHECK (units
[result
] == &three
);
23506 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23507 SELF_CHECK (units
[result
] == &three
);
23508 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23509 SELF_CHECK (units
[result
] == &four
);
23515 #endif /* GDB_SELF_TEST */
23517 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23519 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23520 : per_cu (per_cu_
),
23522 has_loclist (false),
23523 checked_producer (false),
23524 producer_is_gxx_lt_4_6 (false),
23525 producer_is_gcc_lt_4_3 (false),
23526 producer_is_icc (false),
23527 producer_is_icc_lt_14 (false),
23528 producer_is_codewarrior (false),
23529 processing_has_namespace_info (false)
23534 /* Destroy a dwarf2_cu. */
23536 dwarf2_cu::~dwarf2_cu ()
23541 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23544 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23545 enum language pretend_language
)
23547 struct attribute
*attr
;
23549 /* Set the language we're debugging. */
23550 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23551 if (attr
!= nullptr)
23552 set_cu_language (DW_UNSND (attr
), cu
);
23555 cu
->language
= pretend_language
;
23556 cu
->language_defn
= language_def (cu
->language
);
23559 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23562 /* Increase the age counter on each cached compilation unit, and free
23563 any that are too old. */
23566 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23568 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23570 dwarf2_clear_marks (dwarf2_per_objfile
->per_bfd
->read_in_chain
);
23571 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23572 while (per_cu
!= NULL
)
23574 per_cu
->cu
->last_used
++;
23575 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23576 dwarf2_mark (per_cu
->cu
);
23577 per_cu
= per_cu
->cu
->read_in_chain
;
23580 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23581 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23582 while (per_cu
!= NULL
)
23584 struct dwarf2_per_cu_data
*next_cu
;
23586 next_cu
= per_cu
->cu
->read_in_chain
;
23588 if (!per_cu
->cu
->mark
)
23591 *last_chain
= next_cu
;
23594 last_chain
= &per_cu
->cu
->read_in_chain
;
23600 /* Remove a single compilation unit from the cache. */
23603 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23605 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23606 struct dwarf2_per_objfile
*dwarf2_per_objfile
23607 = target_per_cu
->dwarf2_per_objfile
;
23609 per_cu
= dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23610 last_chain
= &dwarf2_per_objfile
->per_bfd
->read_in_chain
;
23611 while (per_cu
!= NULL
)
23613 struct dwarf2_per_cu_data
*next_cu
;
23615 next_cu
= per_cu
->cu
->read_in_chain
;
23617 if (per_cu
== target_per_cu
)
23621 *last_chain
= next_cu
;
23625 last_chain
= &per_cu
->cu
->read_in_chain
;
23631 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23632 We store these in a hash table separate from the DIEs, and preserve them
23633 when the DIEs are flushed out of cache.
23635 The CU "per_cu" pointer is needed because offset alone is not enough to
23636 uniquely identify the type. A file may have multiple .debug_types sections,
23637 or the type may come from a DWO file. Furthermore, while it's more logical
23638 to use per_cu->section+offset, with Fission the section with the data is in
23639 the DWO file but we don't know that section at the point we need it.
23640 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23641 because we can enter the lookup routine, get_die_type_at_offset, from
23642 outside this file, and thus won't necessarily have PER_CU->cu.
23643 Fortunately, PER_CU is stable for the life of the objfile. */
23645 struct dwarf2_per_cu_offset_and_type
23647 const struct dwarf2_per_cu_data
*per_cu
;
23648 sect_offset sect_off
;
23652 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23655 per_cu_offset_and_type_hash (const void *item
)
23657 const struct dwarf2_per_cu_offset_and_type
*ofs
23658 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23660 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23663 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23666 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23668 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23669 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23670 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23671 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23673 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23674 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23677 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23678 table if necessary. For convenience, return TYPE.
23680 The DIEs reading must have careful ordering to:
23681 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23682 reading current DIE.
23683 * Not trying to dereference contents of still incompletely read in types
23684 while reading in other DIEs.
23685 * Enable referencing still incompletely read in types just by a pointer to
23686 the type without accessing its fields.
23688 Therefore caller should follow these rules:
23689 * Try to fetch any prerequisite types we may need to build this DIE type
23690 before building the type and calling set_die_type.
23691 * After building type call set_die_type for current DIE as soon as
23692 possible before fetching more types to complete the current type.
23693 * Make the type as complete as possible before fetching more types. */
23695 static struct type
*
23696 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23698 struct dwarf2_per_objfile
*dwarf2_per_objfile
23699 = cu
->per_cu
->dwarf2_per_objfile
;
23700 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23701 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23702 struct attribute
*attr
;
23703 struct dynamic_prop prop
;
23705 /* For Ada types, make sure that the gnat-specific data is always
23706 initialized (if not already set). There are a few types where
23707 we should not be doing so, because the type-specific area is
23708 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23709 where the type-specific area is used to store the floatformat).
23710 But this is not a problem, because the gnat-specific information
23711 is actually not needed for these types. */
23712 if (need_gnat_info (cu
)
23713 && type
->code () != TYPE_CODE_FUNC
23714 && type
->code () != TYPE_CODE_FLT
23715 && type
->code () != TYPE_CODE_METHODPTR
23716 && type
->code () != TYPE_CODE_MEMBERPTR
23717 && type
->code () != TYPE_CODE_METHOD
23718 && !HAVE_GNAT_AUX_INFO (type
))
23719 INIT_GNAT_SPECIFIC (type
);
23721 /* Read DW_AT_allocated and set in type. */
23722 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23723 if (attr
!= NULL
&& attr
->form_is_block ())
23725 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23726 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23727 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
23729 else if (attr
!= NULL
)
23731 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23732 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23733 sect_offset_str (die
->sect_off
));
23736 /* Read DW_AT_associated and set in type. */
23737 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23738 if (attr
!= NULL
&& attr
->form_is_block ())
23740 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23741 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23742 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
23744 else if (attr
!= NULL
)
23746 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23747 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23748 sect_offset_str (die
->sect_off
));
23751 /* Read DW_AT_data_location and set in type. */
23752 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23753 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23754 cu
->per_cu
->addr_type ()))
23755 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
23757 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23758 dwarf2_per_objfile
->die_type_hash
23759 = htab_up (htab_create_alloc (127,
23760 per_cu_offset_and_type_hash
,
23761 per_cu_offset_and_type_eq
,
23762 NULL
, xcalloc
, xfree
));
23764 ofs
.per_cu
= cu
->per_cu
;
23765 ofs
.sect_off
= die
->sect_off
;
23767 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23768 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23770 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23771 sect_offset_str (die
->sect_off
));
23772 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23773 struct dwarf2_per_cu_offset_and_type
);
23778 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23779 or return NULL if the die does not have a saved type. */
23781 static struct type
*
23782 get_die_type_at_offset (sect_offset sect_off
,
23783 struct dwarf2_per_cu_data
*per_cu
)
23785 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23786 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23788 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23791 ofs
.per_cu
= per_cu
;
23792 ofs
.sect_off
= sect_off
;
23793 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23794 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23801 /* Look up the type for DIE in CU in die_type_hash,
23802 or return NULL if DIE does not have a saved type. */
23804 static struct type
*
23805 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23807 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23810 /* Add a dependence relationship from CU to REF_PER_CU. */
23813 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23814 struct dwarf2_per_cu_data
*ref_per_cu
)
23818 if (cu
->dependencies
== NULL
)
23820 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23821 NULL
, &cu
->comp_unit_obstack
,
23822 hashtab_obstack_allocate
,
23823 dummy_obstack_deallocate
);
23825 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23827 *slot
= ref_per_cu
;
23830 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23831 Set the mark field in every compilation unit in the
23832 cache that we must keep because we are keeping CU. */
23835 dwarf2_mark_helper (void **slot
, void *data
)
23837 struct dwarf2_per_cu_data
*per_cu
;
23839 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23841 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23842 reading of the chain. As such dependencies remain valid it is not much
23843 useful to track and undo them during QUIT cleanups. */
23844 if (per_cu
->cu
== NULL
)
23847 if (per_cu
->cu
->mark
)
23849 per_cu
->cu
->mark
= true;
23851 if (per_cu
->cu
->dependencies
!= NULL
)
23852 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23857 /* Set the mark field in CU and in every other compilation unit in the
23858 cache that we must keep because we are keeping CU. */
23861 dwarf2_mark (struct dwarf2_cu
*cu
)
23866 if (cu
->dependencies
!= NULL
)
23867 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23871 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23875 per_cu
->cu
->mark
= false;
23876 per_cu
= per_cu
->cu
->read_in_chain
;
23880 /* Trivial hash function for partial_die_info: the hash value of a DIE
23881 is its offset in .debug_info for this objfile. */
23884 partial_die_hash (const void *item
)
23886 const struct partial_die_info
*part_die
23887 = (const struct partial_die_info
*) item
;
23889 return to_underlying (part_die
->sect_off
);
23892 /* Trivial comparison function for partial_die_info structures: two DIEs
23893 are equal if they have the same offset. */
23896 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23898 const struct partial_die_info
*part_die_lhs
23899 = (const struct partial_die_info
*) item_lhs
;
23900 const struct partial_die_info
*part_die_rhs
23901 = (const struct partial_die_info
*) item_rhs
;
23903 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23906 struct cmd_list_element
*set_dwarf_cmdlist
;
23907 struct cmd_list_element
*show_dwarf_cmdlist
;
23910 show_check_physname (struct ui_file
*file
, int from_tty
,
23911 struct cmd_list_element
*c
, const char *value
)
23913 fprintf_filtered (file
,
23914 _("Whether to check \"physname\" is %s.\n"),
23918 void _initialize_dwarf2_read ();
23920 _initialize_dwarf2_read ()
23922 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23923 Set DWARF specific variables.\n\
23924 Configure DWARF variables such as the cache size."),
23925 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23926 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23928 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23929 Show DWARF specific variables.\n\
23930 Show DWARF variables such as the cache size."),
23931 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23932 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23934 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23935 &dwarf_max_cache_age
, _("\
23936 Set the upper bound on the age of cached DWARF compilation units."), _("\
23937 Show the upper bound on the age of cached DWARF compilation units."), _("\
23938 A higher limit means that cached compilation units will be stored\n\
23939 in memory longer, and more total memory will be used. Zero disables\n\
23940 caching, which can slow down startup."),
23942 show_dwarf_max_cache_age
,
23943 &set_dwarf_cmdlist
,
23944 &show_dwarf_cmdlist
);
23946 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23947 Set debugging of the DWARF reader."), _("\
23948 Show debugging of the DWARF reader."), _("\
23949 When enabled (non-zero), debugging messages are printed during DWARF\n\
23950 reading and symtab expansion. A value of 1 (one) provides basic\n\
23951 information. A value greater than 1 provides more verbose information."),
23954 &setdebuglist
, &showdebuglist
);
23956 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23957 Set debugging of the DWARF DIE reader."), _("\
23958 Show debugging of the DWARF DIE reader."), _("\
23959 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23960 The value is the maximum depth to print."),
23963 &setdebuglist
, &showdebuglist
);
23965 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23966 Set debugging of the dwarf line reader."), _("\
23967 Show debugging of the dwarf line reader."), _("\
23968 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23969 A value of 1 (one) provides basic information.\n\
23970 A value greater than 1 provides more verbose information."),
23973 &setdebuglist
, &showdebuglist
);
23975 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23976 Set cross-checking of \"physname\" code against demangler."), _("\
23977 Show cross-checking of \"physname\" code against demangler."), _("\
23978 When enabled, GDB's internal \"physname\" code is checked against\n\
23980 NULL
, show_check_physname
,
23981 &setdebuglist
, &showdebuglist
);
23983 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23984 no_class
, &use_deprecated_index_sections
, _("\
23985 Set whether to use deprecated gdb_index sections."), _("\
23986 Show whether to use deprecated gdb_index sections."), _("\
23987 When enabled, deprecated .gdb_index sections are used anyway.\n\
23988 Normally they are ignored either because of a missing feature or\n\
23989 performance issue.\n\
23990 Warning: This option must be enabled before gdb reads the file."),
23993 &setlist
, &showlist
);
23995 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23996 &dwarf2_locexpr_funcs
);
23997 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23998 &dwarf2_loclist_funcs
);
24000 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24001 &dwarf2_block_frame_base_locexpr_funcs
);
24002 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24003 &dwarf2_block_frame_base_loclist_funcs
);
24006 selftests::register_test ("dw2_expand_symtabs_matching",
24007 selftests::dw2_expand_symtabs_matching::run_test
);
24008 selftests::register_test ("dwarf2_find_containing_comp_unit",
24009 selftests::find_containing_comp_unit::run_test
);