1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/stringify.h"
52 #include "gdb-demangle.h"
53 #include "filenames.h" /* for DOSish file names */
55 #include "complaints.h"
56 #include "dwarf2/expr.h"
57 #include "dwarf2/loc.h"
58 #include "cp-support.h"
64 #include "typeprint.h"
69 #include "gdbcore.h" /* for gnutarget */
70 #include "gdb/gdb-index.h"
75 #include "namespace.h"
76 #include "gdbsupport/function-view.h"
77 #include "gdbsupport/gdb_optional.h"
78 #include "gdbsupport/underlying.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
84 #include <unordered_map>
85 #include "gdbsupport/selftest.h"
86 #include "rust-lang.h"
87 #include "gdbsupport/pathstuff.h"
88 #include "count-one-bits.h"
89 #include "debuginfod-support.h"
91 /* When == 1, print basic high level tracing messages.
92 When > 1, be more verbose.
93 This is in contrast to the low level DIE reading of dwarf_die_debug. */
94 static unsigned int dwarf_read_debug
= 0;
96 /* When non-zero, dump DIEs after they are read in. */
97 static unsigned int dwarf_die_debug
= 0;
99 /* When non-zero, dump line number entries as they are read in. */
100 unsigned int dwarf_line_debug
= 0;
102 /* When true, cross-check physname against demangler. */
103 static bool check_physname
= false;
105 /* When true, do not reject deprecated .gdb_index sections. */
106 static bool use_deprecated_index_sections
= false;
108 /* This is used to store the data that is always per objfile. */
109 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
111 /* These are used to store the dwarf2_per_bfd objects.
113 objfiles having the same BFD, which doesn't require relocations, are going to
114 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
116 Other objfiles are not going to share a dwarf2_per_bfd with any other
117 objfiles, so they'll have their own version kept in the _objfile_data_key
119 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
120 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
122 /* The "aclass" indices for various kinds of computed DWARF symbols. */
124 static int dwarf2_locexpr_index
;
125 static int dwarf2_loclist_index
;
126 static int dwarf2_locexpr_block_index
;
127 static int dwarf2_loclist_block_index
;
129 /* Size of .debug_loclists section header for 32-bit DWARF format. */
130 #define LOCLIST_HEADER_SIZE32 12
132 /* Size of .debug_loclists section header for 64-bit DWARF format. */
133 #define LOCLIST_HEADER_SIZE64 20
135 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
136 #define RNGLIST_HEADER_SIZE32 12
138 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
139 #define RNGLIST_HEADER_SIZE64 20
141 /* An index into a (C++) symbol name component in a symbol name as
142 recorded in the mapped_index's symbol table. For each C++ symbol
143 in the symbol table, we record one entry for the start of each
144 component in the symbol in a table of name components, and then
145 sort the table, in order to be able to binary search symbol names,
146 ignoring leading namespaces, both completion and regular look up.
147 For example, for symbol "A::B::C", we'll have an entry that points
148 to "A::B::C", another that points to "B::C", and another for "C".
149 Note that function symbols in GDB index have no parameter
150 information, just the function/method names. You can convert a
151 name_component to a "const char *" using the
152 'mapped_index::symbol_name_at(offset_type)' method. */
154 struct name_component
156 /* Offset in the symbol name where the component starts. Stored as
157 a (32-bit) offset instead of a pointer to save memory and improve
158 locality on 64-bit architectures. */
159 offset_type name_offset
;
161 /* The symbol's index in the symbol and constant pool tables of a
166 /* Base class containing bits shared by both .gdb_index and
167 .debug_name indexes. */
169 struct mapped_index_base
171 mapped_index_base () = default;
172 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
174 /* The name_component table (a sorted vector). See name_component's
175 description above. */
176 std::vector
<name_component
> name_components
;
178 /* How NAME_COMPONENTS is sorted. */
179 enum case_sensitivity name_components_casing
;
181 /* Return the number of names in the symbol table. */
182 virtual size_t symbol_name_count () const = 0;
184 /* Get the name of the symbol at IDX in the symbol table. */
185 virtual const char *symbol_name_at
186 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
188 /* Return whether the name at IDX in the symbol table should be
190 virtual bool symbol_name_slot_invalid (offset_type idx
) const
195 /* Build the symbol name component sorted vector, if we haven't
197 void build_name_components (dwarf2_per_objfile
*per_objfile
);
199 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
200 possible matches for LN_NO_PARAMS in the name component
202 std::pair
<std::vector
<name_component
>::const_iterator
,
203 std::vector
<name_component
>::const_iterator
>
204 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
206 dwarf2_per_objfile
*per_objfile
) const;
208 /* Prevent deleting/destroying via a base class pointer. */
210 ~mapped_index_base() = default;
213 /* A description of the mapped index. The file format is described in
214 a comment by the code that writes the index. */
215 struct mapped_index final
: public mapped_index_base
217 /* A slot/bucket in the symbol table hash. */
218 struct symbol_table_slot
220 const offset_type name
;
221 const offset_type vec
;
224 /* Index data format version. */
227 /* The address table data. */
228 gdb::array_view
<const gdb_byte
> address_table
;
230 /* The symbol table, implemented as a hash table. */
231 gdb::array_view
<symbol_table_slot
> symbol_table
;
233 /* A pointer to the constant pool. */
234 const char *constant_pool
= nullptr;
236 bool symbol_name_slot_invalid (offset_type idx
) const override
238 const auto &bucket
= this->symbol_table
[idx
];
239 return bucket
.name
== 0 && bucket
.vec
== 0;
242 /* Convenience method to get at the name of the symbol at IDX in the
244 const char *symbol_name_at
245 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
246 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
248 size_t symbol_name_count () const override
249 { return this->symbol_table
.size (); }
252 /* A description of the mapped .debug_names.
253 Uninitialized map has CU_COUNT 0. */
254 struct mapped_debug_names final
: public mapped_index_base
256 bfd_endian dwarf5_byte_order
;
257 bool dwarf5_is_dwarf64
;
258 bool augmentation_is_gdb
;
260 uint32_t cu_count
= 0;
261 uint32_t tu_count
, bucket_count
, name_count
;
262 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
263 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
264 const gdb_byte
*name_table_string_offs_reordered
;
265 const gdb_byte
*name_table_entry_offs_reordered
;
266 const gdb_byte
*entry_pool
;
273 /* Attribute name DW_IDX_*. */
276 /* Attribute form DW_FORM_*. */
279 /* Value if FORM is DW_FORM_implicit_const. */
280 LONGEST implicit_const
;
282 std::vector
<attr
> attr_vec
;
285 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
287 const char *namei_to_name
288 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
290 /* Implementation of the mapped_index_base virtual interface, for
291 the name_components cache. */
293 const char *symbol_name_at
294 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
295 { return namei_to_name (idx
, per_objfile
); }
297 size_t symbol_name_count () const override
298 { return this->name_count
; }
301 /* See dwarf2read.h. */
304 get_dwarf2_per_objfile (struct objfile
*objfile
)
306 return dwarf2_objfile_data_key
.get (objfile
);
309 /* Default names of the debugging sections. */
311 /* Note that if the debugging section has been compressed, it might
312 have a name like .zdebug_info. */
314 static const struct dwarf2_debug_sections dwarf2_elf_names
=
316 { ".debug_info", ".zdebug_info" },
317 { ".debug_abbrev", ".zdebug_abbrev" },
318 { ".debug_line", ".zdebug_line" },
319 { ".debug_loc", ".zdebug_loc" },
320 { ".debug_loclists", ".zdebug_loclists" },
321 { ".debug_macinfo", ".zdebug_macinfo" },
322 { ".debug_macro", ".zdebug_macro" },
323 { ".debug_str", ".zdebug_str" },
324 { ".debug_str_offsets", ".zdebug_str_offsets" },
325 { ".debug_line_str", ".zdebug_line_str" },
326 { ".debug_ranges", ".zdebug_ranges" },
327 { ".debug_rnglists", ".zdebug_rnglists" },
328 { ".debug_types", ".zdebug_types" },
329 { ".debug_addr", ".zdebug_addr" },
330 { ".debug_frame", ".zdebug_frame" },
331 { ".eh_frame", NULL
},
332 { ".gdb_index", ".zgdb_index" },
333 { ".debug_names", ".zdebug_names" },
334 { ".debug_aranges", ".zdebug_aranges" },
338 /* List of DWO/DWP sections. */
340 static const struct dwop_section_names
342 struct dwarf2_section_names abbrev_dwo
;
343 struct dwarf2_section_names info_dwo
;
344 struct dwarf2_section_names line_dwo
;
345 struct dwarf2_section_names loc_dwo
;
346 struct dwarf2_section_names loclists_dwo
;
347 struct dwarf2_section_names macinfo_dwo
;
348 struct dwarf2_section_names macro_dwo
;
349 struct dwarf2_section_names rnglists_dwo
;
350 struct dwarf2_section_names str_dwo
;
351 struct dwarf2_section_names str_offsets_dwo
;
352 struct dwarf2_section_names types_dwo
;
353 struct dwarf2_section_names cu_index
;
354 struct dwarf2_section_names tu_index
;
358 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
359 { ".debug_info.dwo", ".zdebug_info.dwo" },
360 { ".debug_line.dwo", ".zdebug_line.dwo" },
361 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
362 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
363 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
364 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
365 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
366 { ".debug_str.dwo", ".zdebug_str.dwo" },
367 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
368 { ".debug_types.dwo", ".zdebug_types.dwo" },
369 { ".debug_cu_index", ".zdebug_cu_index" },
370 { ".debug_tu_index", ".zdebug_tu_index" },
373 /* local data types */
375 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
376 begin with a header, which contains the following information. */
377 struct loclists_rnglists_header
379 /* A 4-byte or 12-byte length containing the length of the
380 set of entries for this compilation unit, not including the
381 length field itself. */
384 /* A 2-byte version identifier. */
387 /* A 1-byte unsigned integer containing the size in bytes of an address on
388 the target system. */
389 unsigned char addr_size
;
391 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
392 on the target system. */
393 unsigned char segment_collector_size
;
395 /* A 4-byte count of the number of offsets that follow the header. */
396 unsigned int offset_entry_count
;
399 /* Type used for delaying computation of method physnames.
400 See comments for compute_delayed_physnames. */
401 struct delayed_method_info
403 /* The type to which the method is attached, i.e., its parent class. */
406 /* The index of the method in the type's function fieldlists. */
409 /* The index of the method in the fieldlist. */
412 /* The name of the DIE. */
415 /* The DIE associated with this method. */
416 struct die_info
*die
;
419 /* Internal state when decoding a particular compilation unit. */
422 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
423 dwarf2_per_objfile
*per_objfile
);
425 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
427 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
428 Create the set of symtabs used by this TU, or if this TU is sharing
429 symtabs with another TU and the symtabs have already been created
430 then restore those symtabs in the line header.
431 We don't need the pc/line-number mapping for type units. */
432 void setup_type_unit_groups (struct die_info
*die
);
434 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
435 buildsym_compunit constructor. */
436 struct compunit_symtab
*start_symtab (const char *name
,
437 const char *comp_dir
,
440 /* Reset the builder. */
441 void reset_builder () { m_builder
.reset (); }
443 /* Return a type that is a generic pointer type, the size of which
444 matches the address size given in the compilation unit header for
446 struct type
*addr_type () const;
448 /* Find an integer type the same size as the address size given in
449 the compilation unit header for this CU. UNSIGNED_P controls if
450 the integer is unsigned or not. */
451 struct type
*addr_sized_int_type (bool unsigned_p
) const;
453 /* The header of the compilation unit. */
454 struct comp_unit_head header
{};
456 /* Base address of this compilation unit. */
457 gdb::optional
<CORE_ADDR
> base_address
;
459 /* The language we are debugging. */
460 enum language language
= language_unknown
;
461 const struct language_defn
*language_defn
= nullptr;
463 const char *producer
= nullptr;
466 /* The symtab builder for this CU. This is only non-NULL when full
467 symbols are being read. */
468 std::unique_ptr
<buildsym_compunit
> m_builder
;
471 /* The generic symbol table building routines have separate lists for
472 file scope symbols and all all other scopes (local scopes). So
473 we need to select the right one to pass to add_symbol_to_list().
474 We do it by keeping a pointer to the correct list in list_in_scope.
476 FIXME: The original dwarf code just treated the file scope as the
477 first local scope, and all other local scopes as nested local
478 scopes, and worked fine. Check to see if we really need to
479 distinguish these in buildsym.c. */
480 struct pending
**list_in_scope
= nullptr;
482 /* Hash table holding all the loaded partial DIEs
483 with partial_die->offset.SECT_OFF as hash. */
484 htab_t partial_dies
= nullptr;
486 /* Storage for things with the same lifetime as this read-in compilation
487 unit, including partial DIEs. */
488 auto_obstack comp_unit_obstack
;
490 /* Backlink to our per_cu entry. */
491 struct dwarf2_per_cu_data
*per_cu
;
493 /* The dwarf2_per_objfile that owns this. */
494 dwarf2_per_objfile
*per_objfile
;
496 /* How many compilation units ago was this CU last referenced? */
499 /* A hash table of DIE cu_offset for following references with
500 die_info->offset.sect_off as hash. */
501 htab_t die_hash
= nullptr;
503 /* Full DIEs if read in. */
504 struct die_info
*dies
= nullptr;
506 /* A set of pointers to dwarf2_per_cu_data objects for compilation
507 units referenced by this one. Only set during full symbol processing;
508 partial symbol tables do not have dependencies. */
509 htab_t dependencies
= nullptr;
511 /* Header data from the line table, during full symbol processing. */
512 struct line_header
*line_header
= nullptr;
513 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
514 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
515 this is the DW_TAG_compile_unit die for this CU. We'll hold on
516 to the line header as long as this DIE is being processed. See
517 process_die_scope. */
518 die_info
*line_header_die_owner
= nullptr;
520 /* A list of methods which need to have physnames computed
521 after all type information has been read. */
522 std::vector
<delayed_method_info
> method_list
;
524 /* To be copied to symtab->call_site_htab. */
525 htab_t call_site_htab
= nullptr;
527 /* Non-NULL if this CU came from a DWO file.
528 There is an invariant here that is important to remember:
529 Except for attributes copied from the top level DIE in the "main"
530 (or "stub") file in preparation for reading the DWO file
531 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
532 Either there isn't a DWO file (in which case this is NULL and the point
533 is moot), or there is and either we're not going to read it (in which
534 case this is NULL) or there is and we are reading it (in which case this
536 struct dwo_unit
*dwo_unit
= nullptr;
538 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
539 Note this value comes from the Fission stub CU/TU's DIE. */
540 gdb::optional
<ULONGEST
> addr_base
;
542 /* The DW_AT_rnglists_base attribute if present.
543 Note this value comes from the Fission stub CU/TU's DIE.
544 Also note that the value is zero in the non-DWO case so this value can
545 be used without needing to know whether DWO files are in use or not.
546 N.B. This does not apply to DW_AT_ranges appearing in
547 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
548 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
549 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
550 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
551 ULONGEST ranges_base
= 0;
553 /* The DW_AT_loclists_base attribute if present. */
554 ULONGEST loclist_base
= 0;
556 /* When reading debug info generated by older versions of rustc, we
557 have to rewrite some union types to be struct types with a
558 variant part. This rewriting must be done after the CU is fully
559 read in, because otherwise at the point of rewriting some struct
560 type might not have been fully processed. So, we keep a list of
561 all such types here and process them after expansion. */
562 std::vector
<struct type
*> rust_unions
;
564 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
565 files, the value is implicitly zero. For DWARF 5 version DWO files, the
566 value is often implicit and is the size of the header of
567 .debug_str_offsets section (8 or 4, depending on the address size). */
568 gdb::optional
<ULONGEST
> str_offsets_base
;
570 /* Mark used when releasing cached dies. */
573 /* This CU references .debug_loc. See the symtab->locations_valid field.
574 This test is imperfect as there may exist optimized debug code not using
575 any location list and still facing inlining issues if handled as
576 unoptimized code. For a future better test see GCC PR other/32998. */
577 bool has_loclist
: 1;
579 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
580 if all the producer_is_* fields are valid. This information is cached
581 because profiling CU expansion showed excessive time spent in
582 producer_is_gxx_lt_4_6. */
583 bool checked_producer
: 1;
584 bool producer_is_gxx_lt_4_6
: 1;
585 bool producer_is_gcc_lt_4_3
: 1;
586 bool producer_is_icc
: 1;
587 bool producer_is_icc_lt_14
: 1;
588 bool producer_is_codewarrior
: 1;
590 /* When true, the file that we're processing is known to have
591 debugging info for C++ namespaces. GCC 3.3.x did not produce
592 this information, but later versions do. */
594 bool processing_has_namespace_info
: 1;
596 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
598 /* If this CU was inherited by another CU (via specification,
599 abstract_origin, etc), this is the ancestor CU. */
602 /* Get the buildsym_compunit for this CU. */
603 buildsym_compunit
*get_builder ()
605 /* If this CU has a builder associated with it, use that. */
606 if (m_builder
!= nullptr)
607 return m_builder
.get ();
609 /* Otherwise, search ancestors for a valid builder. */
610 if (ancestor
!= nullptr)
611 return ancestor
->get_builder ();
617 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
618 This includes type_unit_group and quick_file_names. */
620 struct stmt_list_hash
622 /* The DWO unit this table is from or NULL if there is none. */
623 struct dwo_unit
*dwo_unit
;
625 /* Offset in .debug_line or .debug_line.dwo. */
626 sect_offset line_sect_off
;
629 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
630 an object of this type. This contains elements of type unit groups
631 that can be shared across objfiles. The non-shareable parts are in
632 type_unit_group_unshareable. */
634 struct type_unit_group
636 /* dwarf2read.c's main "handle" on a TU symtab.
637 To simplify things we create an artificial CU that "includes" all the
638 type units using this stmt_list so that the rest of the code still has
639 a "per_cu" handle on the symtab. */
640 struct dwarf2_per_cu_data per_cu
;
642 /* The TUs that share this DW_AT_stmt_list entry.
643 This is added to while parsing type units to build partial symtabs,
644 and is deleted afterwards and not used again. */
645 std::vector
<signatured_type
*> *tus
;
647 /* The data used to construct the hash key. */
648 struct stmt_list_hash hash
;
651 /* These sections are what may appear in a (real or virtual) DWO file. */
655 struct dwarf2_section_info abbrev
;
656 struct dwarf2_section_info line
;
657 struct dwarf2_section_info loc
;
658 struct dwarf2_section_info loclists
;
659 struct dwarf2_section_info macinfo
;
660 struct dwarf2_section_info macro
;
661 struct dwarf2_section_info rnglists
;
662 struct dwarf2_section_info str
;
663 struct dwarf2_section_info str_offsets
;
664 /* In the case of a virtual DWO file, these two are unused. */
665 struct dwarf2_section_info info
;
666 std::vector
<dwarf2_section_info
> types
;
669 /* CUs/TUs in DWP/DWO files. */
673 /* Backlink to the containing struct dwo_file. */
674 struct dwo_file
*dwo_file
;
676 /* The "id" that distinguishes this CU/TU.
677 .debug_info calls this "dwo_id", .debug_types calls this "signature".
678 Since signatures came first, we stick with it for consistency. */
681 /* The section this CU/TU lives in, in the DWO file. */
682 struct dwarf2_section_info
*section
;
684 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
685 sect_offset sect_off
;
688 /* For types, offset in the type's DIE of the type defined by this TU. */
689 cu_offset type_offset_in_tu
;
692 /* include/dwarf2.h defines the DWP section codes.
693 It defines a max value but it doesn't define a min value, which we
694 use for error checking, so provide one. */
696 enum dwp_v2_section_ids
701 /* Data for one DWO file.
703 This includes virtual DWO files (a virtual DWO file is a DWO file as it
704 appears in a DWP file). DWP files don't really have DWO files per se -
705 comdat folding of types "loses" the DWO file they came from, and from
706 a high level view DWP files appear to contain a mass of random types.
707 However, to maintain consistency with the non-DWP case we pretend DWP
708 files contain virtual DWO files, and we assign each TU with one virtual
709 DWO file (generally based on the line and abbrev section offsets -
710 a heuristic that seems to work in practice). */
714 dwo_file () = default;
715 DISABLE_COPY_AND_ASSIGN (dwo_file
);
717 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
718 For virtual DWO files the name is constructed from the section offsets
719 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
720 from related CU+TUs. */
721 const char *dwo_name
= nullptr;
723 /* The DW_AT_comp_dir attribute. */
724 const char *comp_dir
= nullptr;
726 /* The bfd, when the file is open. Otherwise this is NULL.
727 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
728 gdb_bfd_ref_ptr dbfd
;
730 /* The sections that make up this DWO file.
731 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
732 sections (for lack of a better name). */
733 struct dwo_sections sections
{};
735 /* The CUs in the file.
736 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
737 an extension to handle LLVM's Link Time Optimization output (where
738 multiple source files may be compiled into a single object/dwo pair). */
741 /* Table of TUs in the file.
742 Each element is a struct dwo_unit. */
746 /* These sections are what may appear in a DWP file. */
750 /* These are used by all DWP versions (1, 2 and 5). */
751 struct dwarf2_section_info str
;
752 struct dwarf2_section_info cu_index
;
753 struct dwarf2_section_info tu_index
;
755 /* These are only used by DWP version 2 and version 5 files.
756 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
757 sections are referenced by section number, and are not recorded here.
758 In DWP version 2 or 5 there is at most one copy of all these sections,
759 each section being (effectively) comprised of the concatenation of all of
760 the individual sections that exist in the version 1 format.
761 To keep the code simple we treat each of these concatenated pieces as a
762 section itself (a virtual section?). */
763 struct dwarf2_section_info abbrev
;
764 struct dwarf2_section_info info
;
765 struct dwarf2_section_info line
;
766 struct dwarf2_section_info loc
;
767 struct dwarf2_section_info loclists
;
768 struct dwarf2_section_info macinfo
;
769 struct dwarf2_section_info macro
;
770 struct dwarf2_section_info rnglists
;
771 struct dwarf2_section_info str_offsets
;
772 struct dwarf2_section_info types
;
775 /* These sections are what may appear in a virtual DWO file in DWP version 1.
776 A virtual DWO file is a DWO file as it appears in a DWP file. */
778 struct virtual_v1_dwo_sections
780 struct dwarf2_section_info abbrev
;
781 struct dwarf2_section_info line
;
782 struct dwarf2_section_info loc
;
783 struct dwarf2_section_info macinfo
;
784 struct dwarf2_section_info macro
;
785 struct dwarf2_section_info str_offsets
;
786 /* Each DWP hash table entry records one CU or one TU.
787 That is recorded here, and copied to dwo_unit.section. */
788 struct dwarf2_section_info info_or_types
;
791 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
792 In version 2, the sections of the DWO files are concatenated together
793 and stored in one section of that name. Thus each ELF section contains
794 several "virtual" sections. */
796 struct virtual_v2_or_v5_dwo_sections
798 bfd_size_type abbrev_offset
;
799 bfd_size_type abbrev_size
;
801 bfd_size_type line_offset
;
802 bfd_size_type line_size
;
804 bfd_size_type loc_offset
;
805 bfd_size_type loc_size
;
807 bfd_size_type loclists_offset
;
808 bfd_size_type loclists_size
;
810 bfd_size_type macinfo_offset
;
811 bfd_size_type macinfo_size
;
813 bfd_size_type macro_offset
;
814 bfd_size_type macro_size
;
816 bfd_size_type rnglists_offset
;
817 bfd_size_type rnglists_size
;
819 bfd_size_type str_offsets_offset
;
820 bfd_size_type str_offsets_size
;
822 /* Each DWP hash table entry records one CU or one TU.
823 That is recorded here, and copied to dwo_unit.section. */
824 bfd_size_type info_or_types_offset
;
825 bfd_size_type info_or_types_size
;
828 /* Contents of DWP hash tables. */
830 struct dwp_hash_table
832 uint32_t version
, nr_columns
;
833 uint32_t nr_units
, nr_slots
;
834 const gdb_byte
*hash_table
, *unit_table
;
839 const gdb_byte
*indices
;
843 /* This is indexed by column number and gives the id of the section
845 #define MAX_NR_V2_DWO_SECTIONS \
846 (1 /* .debug_info or .debug_types */ \
847 + 1 /* .debug_abbrev */ \
848 + 1 /* .debug_line */ \
849 + 1 /* .debug_loc */ \
850 + 1 /* .debug_str_offsets */ \
851 + 1 /* .debug_macro or .debug_macinfo */)
852 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
853 const gdb_byte
*offsets
;
854 const gdb_byte
*sizes
;
858 /* This is indexed by column number and gives the id of the section
860 #define MAX_NR_V5_DWO_SECTIONS \
861 (1 /* .debug_info */ \
862 + 1 /* .debug_abbrev */ \
863 + 1 /* .debug_line */ \
864 + 1 /* .debug_loclists */ \
865 + 1 /* .debug_str_offsets */ \
866 + 1 /* .debug_macro */ \
867 + 1 /* .debug_rnglists */)
868 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
869 const gdb_byte
*offsets
;
870 const gdb_byte
*sizes
;
875 /* Data for one DWP file. */
879 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
881 dbfd (std::move (abfd
))
885 /* Name of the file. */
888 /* File format version. */
892 gdb_bfd_ref_ptr dbfd
;
894 /* Section info for this file. */
895 struct dwp_sections sections
{};
897 /* Table of CUs in the file. */
898 const struct dwp_hash_table
*cus
= nullptr;
900 /* Table of TUs in the file. */
901 const struct dwp_hash_table
*tus
= nullptr;
903 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
907 /* Table to map ELF section numbers to their sections.
908 This is only needed for the DWP V1 file format. */
909 unsigned int num_sections
= 0;
910 asection
**elf_sections
= nullptr;
913 /* Struct used to pass misc. parameters to read_die_and_children, et
914 al. which are used for both .debug_info and .debug_types dies.
915 All parameters here are unchanging for the life of the call. This
916 struct exists to abstract away the constant parameters of die reading. */
918 struct die_reader_specs
920 /* The bfd of die_section. */
923 /* The CU of the DIE we are parsing. */
924 struct dwarf2_cu
*cu
;
926 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
927 struct dwo_file
*dwo_file
;
929 /* The section the die comes from.
930 This is either .debug_info or .debug_types, or the .dwo variants. */
931 struct dwarf2_section_info
*die_section
;
933 /* die_section->buffer. */
934 const gdb_byte
*buffer
;
936 /* The end of the buffer. */
937 const gdb_byte
*buffer_end
;
939 /* The abbreviation table to use when reading the DIEs. */
940 struct abbrev_table
*abbrev_table
;
943 /* A subclass of die_reader_specs that holds storage and has complex
944 constructor and destructor behavior. */
946 class cutu_reader
: public die_reader_specs
950 cutu_reader (dwarf2_per_cu_data
*this_cu
,
951 dwarf2_per_objfile
*per_objfile
,
952 struct abbrev_table
*abbrev_table
,
953 dwarf2_cu
*existing_cu
,
956 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
957 dwarf2_per_objfile
*per_objfile
,
958 struct dwarf2_cu
*parent_cu
= nullptr,
959 struct dwo_file
*dwo_file
= nullptr);
961 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
963 const gdb_byte
*info_ptr
= nullptr;
964 struct die_info
*comp_unit_die
= nullptr;
965 bool dummy_p
= false;
967 /* Release the new CU, putting it on the chain. This cannot be done
972 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
973 dwarf2_per_objfile
*per_objfile
,
974 dwarf2_cu
*existing_cu
);
976 struct dwarf2_per_cu_data
*m_this_cu
;
977 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
979 /* The ordinary abbreviation table. */
980 abbrev_table_up m_abbrev_table_holder
;
982 /* The DWO abbreviation table. */
983 abbrev_table_up m_dwo_abbrev_table
;
986 /* When we construct a partial symbol table entry we only
987 need this much information. */
988 struct partial_die_info
: public allocate_on_obstack
990 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
992 /* Disable assign but still keep copy ctor, which is needed
993 load_partial_dies. */
994 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
996 /* Adjust the partial die before generating a symbol for it. This
997 function may set the is_external flag or change the DIE's
999 void fixup (struct dwarf2_cu
*cu
);
1001 /* Read a minimal amount of information into the minimal die
1003 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1004 const struct abbrev_info
&abbrev
,
1005 const gdb_byte
*info_ptr
);
1007 /* Compute the name of this partial DIE. This memoizes the
1008 result, so it is safe to call multiple times. */
1009 const char *name (dwarf2_cu
*cu
);
1011 /* Offset of this DIE. */
1012 const sect_offset sect_off
;
1014 /* DWARF-2 tag for this DIE. */
1015 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1017 /* Assorted flags describing the data found in this DIE. */
1018 const unsigned int has_children
: 1;
1020 unsigned int is_external
: 1;
1021 unsigned int is_declaration
: 1;
1022 unsigned int has_type
: 1;
1023 unsigned int has_specification
: 1;
1024 unsigned int has_pc_info
: 1;
1025 unsigned int may_be_inlined
: 1;
1027 /* This DIE has been marked DW_AT_main_subprogram. */
1028 unsigned int main_subprogram
: 1;
1030 /* Flag set if the SCOPE field of this structure has been
1032 unsigned int scope_set
: 1;
1034 /* Flag set if the DIE has a byte_size attribute. */
1035 unsigned int has_byte_size
: 1;
1037 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1038 unsigned int has_const_value
: 1;
1040 /* Flag set if any of the DIE's children are template arguments. */
1041 unsigned int has_template_arguments
: 1;
1043 /* Flag set if fixup has been called on this die. */
1044 unsigned int fixup_called
: 1;
1046 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1047 unsigned int is_dwz
: 1;
1049 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1050 unsigned int spec_is_dwz
: 1;
1052 unsigned int canonical_name
: 1;
1054 /* The name of this DIE. Normally the value of DW_AT_name, but
1055 sometimes a default name for unnamed DIEs. */
1056 const char *raw_name
= nullptr;
1058 /* The linkage name, if present. */
1059 const char *linkage_name
= nullptr;
1061 /* The scope to prepend to our children. This is generally
1062 allocated on the comp_unit_obstack, so will disappear
1063 when this compilation unit leaves the cache. */
1064 const char *scope
= nullptr;
1066 /* Some data associated with the partial DIE. The tag determines
1067 which field is live. */
1070 /* The location description associated with this DIE, if any. */
1071 struct dwarf_block
*locdesc
;
1072 /* The offset of an import, for DW_TAG_imported_unit. */
1073 sect_offset sect_off
;
1076 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1077 CORE_ADDR lowpc
= 0;
1078 CORE_ADDR highpc
= 0;
1080 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1081 DW_AT_sibling, if any. */
1082 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1083 could return DW_AT_sibling values to its caller load_partial_dies. */
1084 const gdb_byte
*sibling
= nullptr;
1086 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1087 DW_AT_specification (or DW_AT_abstract_origin or
1088 DW_AT_extension). */
1089 sect_offset spec_offset
{};
1091 /* Pointers to this DIE's parent, first child, and next sibling,
1093 struct partial_die_info
*die_parent
= nullptr;
1094 struct partial_die_info
*die_child
= nullptr;
1095 struct partial_die_info
*die_sibling
= nullptr;
1097 friend struct partial_die_info
*
1098 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1101 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1102 partial_die_info (sect_offset sect_off
)
1103 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1107 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1109 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1114 has_specification
= 0;
1117 main_subprogram
= 0;
1120 has_const_value
= 0;
1121 has_template_arguments
= 0;
1129 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1130 but this would require a corresponding change in unpack_field_as_long
1132 static int bits_per_byte
= 8;
1134 struct variant_part_builder
;
1136 /* When reading a variant, we track a bit more information about the
1137 field, and store it in an object of this type. */
1139 struct variant_field
1141 int first_field
= -1;
1142 int last_field
= -1;
1144 /* A variant can contain other variant parts. */
1145 std::vector
<variant_part_builder
> variant_parts
;
1147 /* If we see a DW_TAG_variant, then this will be set if this is the
1149 bool default_branch
= false;
1150 /* If we see a DW_AT_discr_value, then this will be the discriminant
1152 ULONGEST discriminant_value
= 0;
1153 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1155 struct dwarf_block
*discr_list_data
= nullptr;
1158 /* This represents a DW_TAG_variant_part. */
1160 struct variant_part_builder
1162 /* The offset of the discriminant field. */
1163 sect_offset discriminant_offset
{};
1165 /* Variants that are direct children of this variant part. */
1166 std::vector
<variant_field
> variants
;
1168 /* True if we're currently reading a variant. */
1169 bool processing_variant
= false;
1174 int accessibility
= 0;
1176 /* Variant parts need to find the discriminant, which is a DIE
1177 reference. We track the section offset of each field to make
1180 struct field field
{};
1185 const char *name
= nullptr;
1186 std::vector
<struct fn_field
> fnfields
;
1189 /* The routines that read and process dies for a C struct or C++ class
1190 pass lists of data member fields and lists of member function fields
1191 in an instance of a field_info structure, as defined below. */
1194 /* List of data member and baseclasses fields. */
1195 std::vector
<struct nextfield
> fields
;
1196 std::vector
<struct nextfield
> baseclasses
;
1198 /* Set if the accessibility of one of the fields is not public. */
1199 bool non_public_fields
= false;
1201 /* Member function fieldlist array, contains name of possibly overloaded
1202 member function, number of overloaded member functions and a pointer
1203 to the head of the member function field chain. */
1204 std::vector
<struct fnfieldlist
> fnfieldlists
;
1206 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1207 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1208 std::vector
<struct decl_field
> typedef_field_list
;
1210 /* Nested types defined by this class and the number of elements in this
1212 std::vector
<struct decl_field
> nested_types_list
;
1214 /* If non-null, this is the variant part we are currently
1216 variant_part_builder
*current_variant_part
= nullptr;
1217 /* This holds all the top-level variant parts attached to the type
1219 std::vector
<variant_part_builder
> variant_parts
;
1221 /* Return the total number of fields (including baseclasses). */
1222 int nfields () const
1224 return fields
.size () + baseclasses
.size ();
1228 /* Loaded secondary compilation units are kept in memory until they
1229 have not been referenced for the processing of this many
1230 compilation units. Set this to zero to disable caching. Cache
1231 sizes of up to at least twenty will improve startup time for
1232 typical inter-CU-reference binaries, at an obvious memory cost. */
1233 static int dwarf_max_cache_age
= 5;
1235 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1236 struct cmd_list_element
*c
, const char *value
)
1238 fprintf_filtered (file
, _("The upper bound on the age of cached "
1239 "DWARF compilation units is %s.\n"),
1243 /* local function prototypes */
1245 static void dwarf2_find_base_address (struct die_info
*die
,
1246 struct dwarf2_cu
*cu
);
1248 static dwarf2_psymtab
*create_partial_symtab
1249 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1252 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1253 const gdb_byte
*info_ptr
,
1254 struct die_info
*type_unit_die
);
1256 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1258 static void scan_partial_symbols (struct partial_die_info
*,
1259 CORE_ADDR
*, CORE_ADDR
*,
1260 int, struct dwarf2_cu
*);
1262 static void add_partial_symbol (struct partial_die_info
*,
1263 struct dwarf2_cu
*);
1265 static void add_partial_namespace (struct partial_die_info
*pdi
,
1266 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1267 int set_addrmap
, struct dwarf2_cu
*cu
);
1269 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1270 CORE_ADDR
*highpc
, int set_addrmap
,
1271 struct dwarf2_cu
*cu
);
1273 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1274 struct dwarf2_cu
*cu
);
1276 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1277 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1278 int need_pc
, struct dwarf2_cu
*cu
);
1280 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1282 static struct partial_die_info
*load_partial_dies
1283 (const struct die_reader_specs
*, const gdb_byte
*, int);
1285 /* A pair of partial_die_info and compilation unit. */
1286 struct cu_partial_die_info
1288 /* The compilation unit of the partial_die_info. */
1289 struct dwarf2_cu
*cu
;
1290 /* A partial_die_info. */
1291 struct partial_die_info
*pdi
;
1293 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1299 cu_partial_die_info () = delete;
1302 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1303 struct dwarf2_cu
*);
1305 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1306 struct attribute
*, struct attr_abbrev
*,
1309 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1310 struct attribute
*attr
, dwarf_tag tag
);
1312 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1314 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1315 dwarf2_section_info
*, sect_offset
);
1317 static const char *read_indirect_string
1318 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1319 const struct comp_unit_head
*, unsigned int *);
1321 static const char *read_indirect_string_at_offset
1322 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1324 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1328 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1329 ULONGEST str_index
);
1331 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1332 ULONGEST str_index
);
1334 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1336 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1337 struct dwarf2_cu
*);
1339 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1340 struct dwarf2_cu
*cu
);
1342 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1344 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1345 struct dwarf2_cu
*cu
);
1347 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1349 static struct die_info
*die_specification (struct die_info
*die
,
1350 struct dwarf2_cu
**);
1352 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1353 struct dwarf2_cu
*cu
);
1355 static void dwarf_decode_lines (struct line_header
*, const char *,
1356 struct dwarf2_cu
*, dwarf2_psymtab
*,
1357 CORE_ADDR
, int decode_mapping
);
1359 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1362 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1363 struct dwarf2_cu
*, struct symbol
* = NULL
);
1365 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1366 struct dwarf2_cu
*);
1368 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1371 struct obstack
*obstack
,
1372 struct dwarf2_cu
*cu
, LONGEST
*value
,
1373 const gdb_byte
**bytes
,
1374 struct dwarf2_locexpr_baton
**baton
);
1376 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1378 static int need_gnat_info (struct dwarf2_cu
*);
1380 static struct type
*die_descriptive_type (struct die_info
*,
1381 struct dwarf2_cu
*);
1383 static void set_descriptive_type (struct type
*, struct die_info
*,
1384 struct dwarf2_cu
*);
1386 static struct type
*die_containing_type (struct die_info
*,
1387 struct dwarf2_cu
*);
1389 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1390 struct dwarf2_cu
*);
1392 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1394 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1396 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1398 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1399 const char *suffix
, int physname
,
1400 struct dwarf2_cu
*cu
);
1402 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1404 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1406 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1408 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1410 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1412 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1414 /* Return the .debug_loclists section to use for cu. */
1415 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1417 /* Return the .debug_rnglists section to use for cu. */
1418 static struct dwarf2_section_info
*cu_debug_rnglists_section
1419 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1421 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1422 values. Keep the items ordered with increasing constraints compliance. */
1425 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1426 PC_BOUNDS_NOT_PRESENT
,
1428 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1429 were present but they do not form a valid range of PC addresses. */
1432 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1435 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1439 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1440 CORE_ADDR
*, CORE_ADDR
*,
1444 static void get_scope_pc_bounds (struct die_info
*,
1445 CORE_ADDR
*, CORE_ADDR
*,
1446 struct dwarf2_cu
*);
1448 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1449 CORE_ADDR
, struct dwarf2_cu
*);
1451 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1452 struct dwarf2_cu
*);
1454 static void dwarf2_attach_fields_to_type (struct field_info
*,
1455 struct type
*, struct dwarf2_cu
*);
1457 static void dwarf2_add_member_fn (struct field_info
*,
1458 struct die_info
*, struct type
*,
1459 struct dwarf2_cu
*);
1461 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1463 struct dwarf2_cu
*);
1465 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1467 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1469 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1471 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1473 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1475 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1477 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1479 static struct type
*read_module_type (struct die_info
*die
,
1480 struct dwarf2_cu
*cu
);
1482 static const char *namespace_name (struct die_info
*die
,
1483 int *is_anonymous
, struct dwarf2_cu
*);
1485 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1487 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1490 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1491 struct dwarf2_cu
*);
1493 static struct die_info
*read_die_and_siblings_1
1494 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1497 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1498 const gdb_byte
*info_ptr
,
1499 const gdb_byte
**new_info_ptr
,
1500 struct die_info
*parent
);
1502 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1503 struct die_info
**, const gdb_byte
*,
1506 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1507 struct die_info
**, const gdb_byte
*);
1509 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1511 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1514 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1516 static const char *dwarf2_full_name (const char *name
,
1517 struct die_info
*die
,
1518 struct dwarf2_cu
*cu
);
1520 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1521 struct dwarf2_cu
*cu
);
1523 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1524 struct dwarf2_cu
**);
1526 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1528 static void dump_die_for_error (struct die_info
*);
1530 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1533 /*static*/ void dump_die (struct die_info
*, int max_level
);
1535 static void store_in_ref_table (struct die_info
*,
1536 struct dwarf2_cu
*);
1538 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1539 const struct attribute
*,
1540 struct dwarf2_cu
**);
1542 static struct die_info
*follow_die_ref (struct die_info
*,
1543 const struct attribute
*,
1544 struct dwarf2_cu
**);
1546 static struct die_info
*follow_die_sig (struct die_info
*,
1547 const struct attribute
*,
1548 struct dwarf2_cu
**);
1550 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1551 struct dwarf2_cu
*);
1553 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1554 const struct attribute
*,
1555 struct dwarf2_cu
*);
1557 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1558 dwarf2_per_objfile
*per_objfile
);
1560 static void read_signatured_type (signatured_type
*sig_type
,
1561 dwarf2_per_objfile
*per_objfile
);
1563 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1564 struct die_info
*die
, struct dwarf2_cu
*cu
,
1565 struct dynamic_prop
*prop
, struct type
*type
);
1567 /* memory allocation interface */
1569 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1571 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1573 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1575 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1576 struct dwarf2_loclist_baton
*baton
,
1577 const struct attribute
*attr
);
1579 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1581 struct dwarf2_cu
*cu
,
1584 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1585 const gdb_byte
*info_ptr
,
1586 struct abbrev_info
*abbrev
);
1588 static hashval_t
partial_die_hash (const void *item
);
1590 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1592 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1593 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1594 dwarf2_per_objfile
*per_objfile
);
1596 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1597 struct die_info
*comp_unit_die
,
1598 enum language pretend_language
);
1600 static struct type
*set_die_type (struct die_info
*, struct type
*,
1601 struct dwarf2_cu
*);
1603 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1605 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1607 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1608 dwarf2_per_objfile
*per_objfile
,
1609 dwarf2_cu
*existing_cu
,
1611 enum language pretend_language
);
1613 static void process_full_comp_unit (dwarf2_cu
*cu
,
1614 enum language pretend_language
);
1616 static void process_full_type_unit (dwarf2_cu
*cu
,
1617 enum language pretend_language
);
1619 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1620 struct dwarf2_per_cu_data
*);
1622 static void dwarf2_mark (struct dwarf2_cu
*);
1624 static struct type
*get_die_type_at_offset (sect_offset
,
1625 dwarf2_per_cu_data
*per_cu
,
1626 dwarf2_per_objfile
*per_objfile
);
1628 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1630 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1631 dwarf2_per_objfile
*per_objfile
,
1632 enum language pretend_language
);
1634 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1636 /* Class, the destructor of which frees all allocated queue entries. This
1637 will only have work to do if an error was thrown while processing the
1638 dwarf. If no error was thrown then the queue entries should have all
1639 been processed, and freed, as we went along. */
1641 class dwarf2_queue_guard
1644 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1645 : m_per_objfile (per_objfile
)
1649 /* Free any entries remaining on the queue. There should only be
1650 entries left if we hit an error while processing the dwarf. */
1651 ~dwarf2_queue_guard ()
1653 /* Ensure that no memory is allocated by the queue. */
1654 std::queue
<dwarf2_queue_item
> empty
;
1655 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1658 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1661 dwarf2_per_objfile
*m_per_objfile
;
1664 dwarf2_queue_item::~dwarf2_queue_item ()
1666 /* Anything still marked queued is likely to be in an
1667 inconsistent state, so discard it. */
1670 per_objfile
->remove_cu (per_cu
);
1675 /* The return type of find_file_and_directory. Note, the enclosed
1676 string pointers are only valid while this object is valid. */
1678 struct file_and_directory
1680 /* The filename. This is never NULL. */
1683 /* The compilation directory. NULL if not known. If we needed to
1684 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1685 points directly to the DW_AT_comp_dir string attribute owned by
1686 the obstack that owns the DIE. */
1687 const char *comp_dir
;
1689 /* If we needed to build a new string for comp_dir, this is what
1690 owns the storage. */
1691 std::string comp_dir_storage
;
1694 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1695 struct dwarf2_cu
*cu
);
1697 static htab_up
allocate_signatured_type_table ();
1699 static htab_up
allocate_dwo_unit_table ();
1701 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1702 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1703 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1705 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1707 static struct dwo_unit
*lookup_dwo_comp_unit
1708 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1709 ULONGEST signature
);
1711 static struct dwo_unit
*lookup_dwo_type_unit
1712 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1714 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1716 /* A unique pointer to a dwo_file. */
1718 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1720 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1722 static void check_producer (struct dwarf2_cu
*cu
);
1724 static void free_line_header_voidp (void *arg
);
1726 /* Various complaints about symbol reading that don't abort the process. */
1729 dwarf2_debug_line_missing_file_complaint (void)
1731 complaint (_(".debug_line section has line data without a file"));
1735 dwarf2_debug_line_missing_end_sequence_complaint (void)
1737 complaint (_(".debug_line section has line "
1738 "program sequence without an end"));
1742 dwarf2_complex_location_expr_complaint (void)
1744 complaint (_("location expression too complex"));
1748 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1751 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1756 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1758 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1762 /* Hash function for line_header_hash. */
1765 line_header_hash (const struct line_header
*ofs
)
1767 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1770 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1773 line_header_hash_voidp (const void *item
)
1775 const struct line_header
*ofs
= (const struct line_header
*) item
;
1777 return line_header_hash (ofs
);
1780 /* Equality function for line_header_hash. */
1783 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1785 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1786 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1788 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1789 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1794 /* See declaration. */
1796 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1799 can_copy (can_copy_
)
1802 names
= &dwarf2_elf_names
;
1804 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1805 locate_sections (obfd
, sec
, *names
);
1808 dwarf2_per_bfd::~dwarf2_per_bfd ()
1810 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1811 per_cu
->imported_symtabs_free ();
1813 for (signatured_type
*sig_type
: all_type_units
)
1814 sig_type
->per_cu
.imported_symtabs_free ();
1816 /* Everything else should be on this->obstack. */
1822 dwarf2_per_objfile::remove_all_cus ()
1824 for (auto pair
: m_dwarf2_cus
)
1827 m_dwarf2_cus
.clear ();
1830 /* A helper class that calls free_cached_comp_units on
1833 class free_cached_comp_units
1837 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1838 : m_per_objfile (per_objfile
)
1842 ~free_cached_comp_units ()
1844 m_per_objfile
->remove_all_cus ();
1847 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1851 dwarf2_per_objfile
*m_per_objfile
;
1857 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1859 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1861 return this->m_symtabs
[per_cu
->index
] != nullptr;
1867 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1869 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1871 return this->m_symtabs
[per_cu
->index
];
1877 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1878 compunit_symtab
*symtab
)
1880 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1881 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1883 this->m_symtabs
[per_cu
->index
] = symtab
;
1886 /* Try to locate the sections we need for DWARF 2 debugging
1887 information and return true if we have enough to do something.
1888 NAMES points to the dwarf2 section names, or is NULL if the standard
1889 ELF names are used. CAN_COPY is true for formats where symbol
1890 interposition is possible and so symbol values must follow copy
1891 relocation rules. */
1894 dwarf2_has_info (struct objfile
*objfile
,
1895 const struct dwarf2_debug_sections
*names
,
1898 if (objfile
->flags
& OBJF_READNEVER
)
1901 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1903 if (per_objfile
== NULL
)
1905 dwarf2_per_bfd
*per_bfd
;
1907 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1908 doesn't require relocations and if there aren't partial symbols
1909 from some other reader. */
1910 if (!objfile_has_partial_symbols (objfile
)
1911 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1913 /* See if one has been created for this BFD yet. */
1914 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1916 if (per_bfd
== nullptr)
1918 /* No, create it now. */
1919 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1920 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1925 /* No sharing possible, create one specifically for this objfile. */
1926 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1927 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1930 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1933 return (!per_objfile
->per_bfd
->info
.is_virtual
1934 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1935 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1936 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1939 /* When loading sections, we look either for uncompressed section or for
1940 compressed section names. */
1943 section_is_p (const char *section_name
,
1944 const struct dwarf2_section_names
*names
)
1946 if (names
->normal
!= NULL
1947 && strcmp (section_name
, names
->normal
) == 0)
1949 if (names
->compressed
!= NULL
1950 && strcmp (section_name
, names
->compressed
) == 0)
1955 /* See declaration. */
1958 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1959 const dwarf2_debug_sections
&names
)
1961 flagword aflag
= bfd_section_flags (sectp
);
1963 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1966 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1967 > bfd_get_file_size (abfd
))
1969 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1970 warning (_("Discarding section %s which has a section size (%s"
1971 ") larger than the file size [in module %s]"),
1972 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1973 bfd_get_filename (abfd
));
1975 else if (section_is_p (sectp
->name
, &names
.info
))
1977 this->info
.s
.section
= sectp
;
1978 this->info
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1982 this->abbrev
.s
.section
= sectp
;
1983 this->abbrev
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.line
))
1987 this->line
.s
.section
= sectp
;
1988 this->line
.size
= bfd_section_size (sectp
);
1990 else if (section_is_p (sectp
->name
, &names
.loc
))
1992 this->loc
.s
.section
= sectp
;
1993 this->loc
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.loclists
))
1997 this->loclists
.s
.section
= sectp
;
1998 this->loclists
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2002 this->macinfo
.s
.section
= sectp
;
2003 this->macinfo
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.macro
))
2007 this->macro
.s
.section
= sectp
;
2008 this->macro
.size
= bfd_section_size (sectp
);
2010 else if (section_is_p (sectp
->name
, &names
.str
))
2012 this->str
.s
.section
= sectp
;
2013 this->str
.size
= bfd_section_size (sectp
);
2015 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2017 this->str_offsets
.s
.section
= sectp
;
2018 this->str_offsets
.size
= bfd_section_size (sectp
);
2020 else if (section_is_p (sectp
->name
, &names
.line_str
))
2022 this->line_str
.s
.section
= sectp
;
2023 this->line_str
.size
= bfd_section_size (sectp
);
2025 else if (section_is_p (sectp
->name
, &names
.addr
))
2027 this->addr
.s
.section
= sectp
;
2028 this->addr
.size
= bfd_section_size (sectp
);
2030 else if (section_is_p (sectp
->name
, &names
.frame
))
2032 this->frame
.s
.section
= sectp
;
2033 this->frame
.size
= bfd_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2037 this->eh_frame
.s
.section
= sectp
;
2038 this->eh_frame
.size
= bfd_section_size (sectp
);
2040 else if (section_is_p (sectp
->name
, &names
.ranges
))
2042 this->ranges
.s
.section
= sectp
;
2043 this->ranges
.size
= bfd_section_size (sectp
);
2045 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2047 this->rnglists
.s
.section
= sectp
;
2048 this->rnglists
.size
= bfd_section_size (sectp
);
2050 else if (section_is_p (sectp
->name
, &names
.types
))
2052 struct dwarf2_section_info type_section
;
2054 memset (&type_section
, 0, sizeof (type_section
));
2055 type_section
.s
.section
= sectp
;
2056 type_section
.size
= bfd_section_size (sectp
);
2058 this->types
.push_back (type_section
);
2060 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2062 this->gdb_index
.s
.section
= sectp
;
2063 this->gdb_index
.size
= bfd_section_size (sectp
);
2065 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2067 this->debug_names
.s
.section
= sectp
;
2068 this->debug_names
.size
= bfd_section_size (sectp
);
2070 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2072 this->debug_aranges
.s
.section
= sectp
;
2073 this->debug_aranges
.size
= bfd_section_size (sectp
);
2076 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2077 && bfd_section_vma (sectp
) == 0)
2078 this->has_section_at_zero
= true;
2081 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2085 dwarf2_get_section_info (struct objfile
*objfile
,
2086 enum dwarf2_section_enum sect
,
2087 asection
**sectp
, const gdb_byte
**bufp
,
2088 bfd_size_type
*sizep
)
2090 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2091 struct dwarf2_section_info
*info
;
2093 /* We may see an objfile without any DWARF, in which case we just
2095 if (per_objfile
== NULL
)
2104 case DWARF2_DEBUG_FRAME
:
2105 info
= &per_objfile
->per_bfd
->frame
;
2107 case DWARF2_EH_FRAME
:
2108 info
= &per_objfile
->per_bfd
->eh_frame
;
2111 gdb_assert_not_reached ("unexpected section");
2114 info
->read (objfile
);
2116 *sectp
= info
->get_bfd_section ();
2117 *bufp
= info
->buffer
;
2118 *sizep
= info
->size
;
2121 /* A helper function to find the sections for a .dwz file. */
2124 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, dwz_file
*dwz_file
)
2126 /* Note that we only support the standard ELF names, because .dwz
2127 is ELF-only (at the time of writing). */
2128 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2130 dwz_file
->abbrev
.s
.section
= sectp
;
2131 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2133 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2135 dwz_file
->info
.s
.section
= sectp
;
2136 dwz_file
->info
.size
= bfd_section_size (sectp
);
2138 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2140 dwz_file
->str
.s
.section
= sectp
;
2141 dwz_file
->str
.size
= bfd_section_size (sectp
);
2143 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2145 dwz_file
->line
.s
.section
= sectp
;
2146 dwz_file
->line
.size
= bfd_section_size (sectp
);
2148 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2150 dwz_file
->macro
.s
.section
= sectp
;
2151 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2153 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2155 dwz_file
->gdb_index
.s
.section
= sectp
;
2156 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2158 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2160 dwz_file
->debug_names
.s
.section
= sectp
;
2161 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2165 /* See dwarf2read.h. */
2168 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2170 const char *filename
;
2171 bfd_size_type buildid_len_arg
;
2175 if (per_bfd
->dwz_file
!= NULL
)
2176 return per_bfd
->dwz_file
.get ();
2178 bfd_set_error (bfd_error_no_error
);
2179 gdb::unique_xmalloc_ptr
<char> data
2180 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2181 &buildid_len_arg
, &buildid
));
2184 if (bfd_get_error () == bfd_error_no_error
)
2186 error (_("could not read '.gnu_debugaltlink' section: %s"),
2187 bfd_errmsg (bfd_get_error ()));
2190 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2192 buildid_len
= (size_t) buildid_len_arg
;
2194 filename
= data
.get ();
2196 std::string abs_storage
;
2197 if (!IS_ABSOLUTE_PATH (filename
))
2199 gdb::unique_xmalloc_ptr
<char> abs
2200 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2202 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2203 filename
= abs_storage
.c_str ();
2206 /* First try the file name given in the section. If that doesn't
2207 work, try to use the build-id instead. */
2208 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2209 if (dwz_bfd
!= NULL
)
2211 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2212 dwz_bfd
.reset (nullptr);
2215 if (dwz_bfd
== NULL
)
2216 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2218 if (dwz_bfd
== nullptr)
2220 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2221 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2223 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2230 /* File successfully retrieved from server. */
2231 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2233 if (dwz_bfd
== nullptr)
2234 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2235 alt_filename
.get ());
2236 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2237 dwz_bfd
.reset (nullptr);
2241 if (dwz_bfd
== NULL
)
2242 error (_("could not find '.gnu_debugaltlink' file for %s"),
2243 bfd_get_filename (per_bfd
->obfd
));
2245 std::unique_ptr
<struct dwz_file
> result
2246 (new struct dwz_file (std::move (dwz_bfd
)));
2248 for (asection
*sec
: gdb_bfd_sections (result
->dwz_bfd
))
2249 locate_dwz_sections (result
->dwz_bfd
.get (), sec
, result
.get ());
2251 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2252 per_bfd
->dwz_file
= std::move (result
);
2253 return per_bfd
->dwz_file
.get ();
2256 /* DWARF quick_symbols_functions support. */
2258 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2259 unique line tables, so we maintain a separate table of all .debug_line
2260 derived entries to support the sharing.
2261 All the quick functions need is the list of file names. We discard the
2262 line_header when we're done and don't need to record it here. */
2263 struct quick_file_names
2265 /* The data used to construct the hash key. */
2266 struct stmt_list_hash hash
;
2268 /* The number of entries in file_names, real_names. */
2269 unsigned int num_file_names
;
2271 /* The file names from the line table, after being run through
2273 const char **file_names
;
2275 /* The file names from the line table after being run through
2276 gdb_realpath. These are computed lazily. */
2277 const char **real_names
;
2280 /* When using the index (and thus not using psymtabs), each CU has an
2281 object of this type. This is used to hold information needed by
2282 the various "quick" methods. */
2283 struct dwarf2_per_cu_quick_data
2285 /* The file table. This can be NULL if there was no file table
2286 or it's currently not read in.
2287 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2288 struct quick_file_names
*file_names
;
2290 /* A temporary mark bit used when iterating over all CUs in
2291 expand_symtabs_matching. */
2292 unsigned int mark
: 1;
2294 /* True if we've tried to read the file table and found there isn't one.
2295 There will be no point in trying to read it again next time. */
2296 unsigned int no_file_data
: 1;
2299 /* Utility hash function for a stmt_list_hash. */
2302 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2306 if (stmt_list_hash
->dwo_unit
!= NULL
)
2307 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2308 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2312 /* Utility equality function for a stmt_list_hash. */
2315 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2316 const struct stmt_list_hash
*rhs
)
2318 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2320 if (lhs
->dwo_unit
!= NULL
2321 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2324 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2327 /* Hash function for a quick_file_names. */
2330 hash_file_name_entry (const void *e
)
2332 const struct quick_file_names
*file_data
2333 = (const struct quick_file_names
*) e
;
2335 return hash_stmt_list_entry (&file_data
->hash
);
2338 /* Equality function for a quick_file_names. */
2341 eq_file_name_entry (const void *a
, const void *b
)
2343 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2344 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2346 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2349 /* Delete function for a quick_file_names. */
2352 delete_file_name_entry (void *e
)
2354 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2357 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2359 xfree ((void*) file_data
->file_names
[i
]);
2360 if (file_data
->real_names
)
2361 xfree ((void*) file_data
->real_names
[i
]);
2364 /* The space for the struct itself lives on the obstack, so we don't
2368 /* Create a quick_file_names hash table. */
2371 create_quick_file_names_table (unsigned int nr_initial_entries
)
2373 return htab_up (htab_create_alloc (nr_initial_entries
,
2374 hash_file_name_entry
, eq_file_name_entry
,
2375 delete_file_name_entry
, xcalloc
, xfree
));
2378 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2379 function is unrelated to symtabs, symtab would have to be created afterwards.
2380 You should call age_cached_comp_units after processing the CU. */
2383 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2386 if (per_cu
->is_debug_types
)
2387 load_full_type_unit (per_cu
, per_objfile
);
2389 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2390 skip_partial
, language_minimal
);
2392 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2394 return nullptr; /* Dummy CU. */
2396 dwarf2_find_base_address (cu
->dies
, cu
);
2401 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2404 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2405 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2407 /* Skip type_unit_groups, reading the type units they contain
2408 is handled elsewhere. */
2409 if (per_cu
->type_unit_group_p ())
2412 /* The destructor of dwarf2_queue_guard frees any entries left on
2413 the queue. After this point we're guaranteed to leave this function
2414 with the dwarf queue empty. */
2415 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2417 if (!per_objfile
->symtab_set_p (per_cu
))
2419 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2420 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2422 /* If we just loaded a CU from a DWO, and we're working with an index
2423 that may badly handle TUs, load all the TUs in that DWO as well.
2424 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2425 if (!per_cu
->is_debug_types
2427 && cu
->dwo_unit
!= NULL
2428 && per_objfile
->per_bfd
->index_table
!= NULL
2429 && per_objfile
->per_bfd
->index_table
->version
<= 7
2430 /* DWP files aren't supported yet. */
2431 && get_dwp_file (per_objfile
) == NULL
)
2432 queue_and_load_all_dwo_tus (cu
);
2435 process_queue (per_objfile
);
2437 /* Age the cache, releasing compilation units that have not
2438 been used recently. */
2439 per_objfile
->age_comp_units ();
2442 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2443 the per-objfile for which this symtab is instantiated.
2445 Returns the resulting symbol table. */
2447 static struct compunit_symtab
*
2448 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2449 dwarf2_per_objfile
*per_objfile
,
2452 gdb_assert (per_objfile
->per_bfd
->using_index
);
2454 if (!per_objfile
->symtab_set_p (per_cu
))
2456 free_cached_comp_units
freer (per_objfile
);
2457 scoped_restore decrementer
= increment_reading_symtab ();
2458 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2459 process_cu_includes (per_objfile
);
2462 return per_objfile
->get_symtab (per_cu
);
2465 /* See declaration. */
2467 dwarf2_per_cu_data
*
2468 dwarf2_per_bfd::get_cutu (int index
)
2470 if (index
>= this->all_comp_units
.size ())
2472 index
-= this->all_comp_units
.size ();
2473 gdb_assert (index
< this->all_type_units
.size ());
2474 return &this->all_type_units
[index
]->per_cu
;
2477 return this->all_comp_units
[index
];
2480 /* See declaration. */
2482 dwarf2_per_cu_data
*
2483 dwarf2_per_bfd::get_cu (int index
)
2485 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2487 return this->all_comp_units
[index
];
2490 /* See declaration. */
2493 dwarf2_per_bfd::get_tu (int index
)
2495 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2497 return this->all_type_units
[index
];
2502 dwarf2_per_cu_data
*
2503 dwarf2_per_bfd::allocate_per_cu ()
2505 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2506 result
->per_bfd
= this;
2507 result
->index
= m_num_psymtabs
++;
2514 dwarf2_per_bfd::allocate_signatured_type ()
2516 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2517 result
->per_cu
.per_bfd
= this;
2518 result
->per_cu
.index
= m_num_psymtabs
++;
2522 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2523 obstack, and constructed with the specified field values. */
2525 static dwarf2_per_cu_data
*
2526 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2527 struct dwarf2_section_info
*section
,
2529 sect_offset sect_off
, ULONGEST length
)
2531 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2532 the_cu
->sect_off
= sect_off
;
2533 the_cu
->length
= length
;
2534 the_cu
->section
= section
;
2535 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2536 struct dwarf2_per_cu_quick_data
);
2537 the_cu
->is_dwz
= is_dwz
;
2541 /* A helper for create_cus_from_index that handles a given list of
2545 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2546 const gdb_byte
*cu_list
, offset_type n_elements
,
2547 struct dwarf2_section_info
*section
,
2550 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2552 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2554 sect_offset sect_off
2555 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2556 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2559 dwarf2_per_cu_data
*per_cu
2560 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2562 per_bfd
->all_comp_units
.push_back (per_cu
);
2566 /* Read the CU list from the mapped index, and use it to create all
2567 the CU objects for PER_BFD. */
2570 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2571 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2572 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2574 gdb_assert (per_bfd
->all_comp_units
.empty ());
2575 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2577 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2580 if (dwz_elements
== 0)
2583 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2584 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2588 /* Create the signatured type hash table from the index. */
2591 create_signatured_type_table_from_index
2592 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2593 const gdb_byte
*bytes
, offset_type elements
)
2595 gdb_assert (per_bfd
->all_type_units
.empty ());
2596 per_bfd
->all_type_units
.reserve (elements
/ 3);
2598 htab_up sig_types_hash
= allocate_signatured_type_table ();
2600 for (offset_type i
= 0; i
< elements
; i
+= 3)
2602 struct signatured_type
*sig_type
;
2605 cu_offset type_offset_in_tu
;
2607 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2608 sect_offset sect_off
2609 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2611 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2613 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2616 sig_type
= per_bfd
->allocate_signatured_type ();
2617 sig_type
->signature
= signature
;
2618 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2619 sig_type
->per_cu
.is_debug_types
= 1;
2620 sig_type
->per_cu
.section
= section
;
2621 sig_type
->per_cu
.sect_off
= sect_off
;
2622 sig_type
->per_cu
.v
.quick
2623 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2624 struct dwarf2_per_cu_quick_data
);
2626 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2629 per_bfd
->all_type_units
.push_back (sig_type
);
2632 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2635 /* Create the signatured type hash table from .debug_names. */
2638 create_signatured_type_table_from_debug_names
2639 (dwarf2_per_objfile
*per_objfile
,
2640 const mapped_debug_names
&map
,
2641 struct dwarf2_section_info
*section
,
2642 struct dwarf2_section_info
*abbrev_section
)
2644 struct objfile
*objfile
= per_objfile
->objfile
;
2646 section
->read (objfile
);
2647 abbrev_section
->read (objfile
);
2649 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2650 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2652 htab_up sig_types_hash
= allocate_signatured_type_table ();
2654 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2656 struct signatured_type
*sig_type
;
2659 sect_offset sect_off
2660 = (sect_offset
) (extract_unsigned_integer
2661 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2663 map
.dwarf5_byte_order
));
2665 comp_unit_head cu_header
;
2666 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2668 section
->buffer
+ to_underlying (sect_off
),
2671 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2672 sig_type
->signature
= cu_header
.signature
;
2673 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2674 sig_type
->per_cu
.is_debug_types
= 1;
2675 sig_type
->per_cu
.section
= section
;
2676 sig_type
->per_cu
.sect_off
= sect_off
;
2677 sig_type
->per_cu
.v
.quick
2678 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2679 struct dwarf2_per_cu_quick_data
);
2681 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2684 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2687 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2690 /* Read the address map data from the mapped index, and use it to
2691 populate the objfile's psymtabs_addrmap. */
2694 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2695 struct mapped_index
*index
)
2697 struct objfile
*objfile
= per_objfile
->objfile
;
2698 struct gdbarch
*gdbarch
= objfile
->arch ();
2699 const gdb_byte
*iter
, *end
;
2700 struct addrmap
*mutable_map
;
2703 auto_obstack temp_obstack
;
2705 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2707 iter
= index
->address_table
.data ();
2708 end
= iter
+ index
->address_table
.size ();
2710 baseaddr
= objfile
->text_section_offset ();
2714 ULONGEST hi
, lo
, cu_index
;
2715 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2717 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2719 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2724 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2725 hex_string (lo
), hex_string (hi
));
2729 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2731 complaint (_(".gdb_index address table has invalid CU number %u"),
2732 (unsigned) cu_index
);
2736 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2737 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2738 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2739 per_objfile
->per_bfd
->get_cu (cu_index
));
2742 objfile
->partial_symtabs
->psymtabs_addrmap
2743 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2746 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2747 populate the objfile's psymtabs_addrmap. */
2750 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2751 struct dwarf2_section_info
*section
)
2753 struct objfile
*objfile
= per_objfile
->objfile
;
2754 bfd
*abfd
= objfile
->obfd
;
2755 struct gdbarch
*gdbarch
= objfile
->arch ();
2756 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2758 auto_obstack temp_obstack
;
2759 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2761 std::unordered_map
<sect_offset
,
2762 dwarf2_per_cu_data
*,
2763 gdb::hash_enum
<sect_offset
>>
2764 debug_info_offset_to_per_cu
;
2765 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2767 const auto insertpair
2768 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2769 if (!insertpair
.second
)
2771 warning (_("Section .debug_aranges in %s has duplicate "
2772 "debug_info_offset %s, ignoring .debug_aranges."),
2773 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2778 section
->read (objfile
);
2780 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2782 const gdb_byte
*addr
= section
->buffer
;
2784 while (addr
< section
->buffer
+ section
->size
)
2786 const gdb_byte
*const entry_addr
= addr
;
2787 unsigned int bytes_read
;
2789 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2793 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2794 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2795 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2796 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2798 warning (_("Section .debug_aranges in %s entry at offset %s "
2799 "length %s exceeds section length %s, "
2800 "ignoring .debug_aranges."),
2801 objfile_name (objfile
),
2802 plongest (entry_addr
- section
->buffer
),
2803 plongest (bytes_read
+ entry_length
),
2804 pulongest (section
->size
));
2808 /* The version number. */
2809 const uint16_t version
= read_2_bytes (abfd
, addr
);
2813 warning (_("Section .debug_aranges in %s entry at offset %s "
2814 "has unsupported version %d, ignoring .debug_aranges."),
2815 objfile_name (objfile
),
2816 plongest (entry_addr
- section
->buffer
), version
);
2820 const uint64_t debug_info_offset
2821 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2822 addr
+= offset_size
;
2823 const auto per_cu_it
2824 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2825 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2827 warning (_("Section .debug_aranges in %s entry at offset %s "
2828 "debug_info_offset %s does not exists, "
2829 "ignoring .debug_aranges."),
2830 objfile_name (objfile
),
2831 plongest (entry_addr
- section
->buffer
),
2832 pulongest (debug_info_offset
));
2835 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2837 const uint8_t address_size
= *addr
++;
2838 if (address_size
< 1 || address_size
> 8)
2840 warning (_("Section .debug_aranges in %s entry at offset %s "
2841 "address_size %u is invalid, ignoring .debug_aranges."),
2842 objfile_name (objfile
),
2843 plongest (entry_addr
- section
->buffer
), address_size
);
2847 const uint8_t segment_selector_size
= *addr
++;
2848 if (segment_selector_size
!= 0)
2850 warning (_("Section .debug_aranges in %s entry at offset %s "
2851 "segment_selector_size %u is not supported, "
2852 "ignoring .debug_aranges."),
2853 objfile_name (objfile
),
2854 plongest (entry_addr
- section
->buffer
),
2855 segment_selector_size
);
2859 /* Must pad to an alignment boundary that is twice the address
2860 size. It is undocumented by the DWARF standard but GCC does
2862 for (size_t padding
= ((-(addr
- section
->buffer
))
2863 & (2 * address_size
- 1));
2864 padding
> 0; padding
--)
2867 warning (_("Section .debug_aranges in %s entry at offset %s "
2868 "padding is not zero, ignoring .debug_aranges."),
2869 objfile_name (objfile
),
2870 plongest (entry_addr
- section
->buffer
));
2876 if (addr
+ 2 * address_size
> entry_end
)
2878 warning (_("Section .debug_aranges in %s entry at offset %s "
2879 "address list is not properly terminated, "
2880 "ignoring .debug_aranges."),
2881 objfile_name (objfile
),
2882 plongest (entry_addr
- section
->buffer
));
2885 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2887 addr
+= address_size
;
2888 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2890 addr
+= address_size
;
2891 if (start
== 0 && length
== 0)
2893 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
2895 /* Symbol was eliminated due to a COMDAT group. */
2898 ULONGEST end
= start
+ length
;
2899 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2901 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2903 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2907 objfile
->partial_symtabs
->psymtabs_addrmap
2908 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2911 /* Find a slot in the mapped index INDEX for the object named NAME.
2912 If NAME is found, set *VEC_OUT to point to the CU vector in the
2913 constant pool and return true. If NAME cannot be found, return
2917 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2918 offset_type
**vec_out
)
2921 offset_type slot
, step
;
2922 int (*cmp
) (const char *, const char *);
2924 gdb::unique_xmalloc_ptr
<char> without_params
;
2925 if (current_language
->la_language
== language_cplus
2926 || current_language
->la_language
== language_fortran
2927 || current_language
->la_language
== language_d
)
2929 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2932 if (strchr (name
, '(') != NULL
)
2934 without_params
= cp_remove_params (name
);
2936 if (without_params
!= NULL
)
2937 name
= without_params
.get ();
2941 /* Index version 4 did not support case insensitive searches. But the
2942 indices for case insensitive languages are built in lowercase, therefore
2943 simulate our NAME being searched is also lowercased. */
2944 hash
= mapped_index_string_hash ((index
->version
== 4
2945 && case_sensitivity
== case_sensitive_off
2946 ? 5 : index
->version
),
2949 slot
= hash
& (index
->symbol_table
.size () - 1);
2950 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2951 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2957 const auto &bucket
= index
->symbol_table
[slot
];
2958 if (bucket
.name
== 0 && bucket
.vec
== 0)
2961 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2962 if (!cmp (name
, str
))
2964 *vec_out
= (offset_type
*) (index
->constant_pool
2965 + MAYBE_SWAP (bucket
.vec
));
2969 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2973 /* A helper function that reads the .gdb_index from BUFFER and fills
2974 in MAP. FILENAME is the name of the file containing the data;
2975 it is used for error reporting. DEPRECATED_OK is true if it is
2976 ok to use deprecated sections.
2978 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2979 out parameters that are filled in with information about the CU and
2980 TU lists in the section.
2982 Returns true if all went well, false otherwise. */
2985 read_gdb_index_from_buffer (const char *filename
,
2987 gdb::array_view
<const gdb_byte
> buffer
,
2988 struct mapped_index
*map
,
2989 const gdb_byte
**cu_list
,
2990 offset_type
*cu_list_elements
,
2991 const gdb_byte
**types_list
,
2992 offset_type
*types_list_elements
)
2994 const gdb_byte
*addr
= &buffer
[0];
2996 /* Version check. */
2997 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2998 /* Versions earlier than 3 emitted every copy of a psymbol. This
2999 causes the index to behave very poorly for certain requests. Version 3
3000 contained incomplete addrmap. So, it seems better to just ignore such
3004 static int warning_printed
= 0;
3005 if (!warning_printed
)
3007 warning (_("Skipping obsolete .gdb_index section in %s."),
3009 warning_printed
= 1;
3013 /* Index version 4 uses a different hash function than index version
3016 Versions earlier than 6 did not emit psymbols for inlined
3017 functions. Using these files will cause GDB not to be able to
3018 set breakpoints on inlined functions by name, so we ignore these
3019 indices unless the user has done
3020 "set use-deprecated-index-sections on". */
3021 if (version
< 6 && !deprecated_ok
)
3023 static int warning_printed
= 0;
3024 if (!warning_printed
)
3027 Skipping deprecated .gdb_index section in %s.\n\
3028 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3029 to use the section anyway."),
3031 warning_printed
= 1;
3035 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3036 of the TU (for symbols coming from TUs),
3037 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3038 Plus gold-generated indices can have duplicate entries for global symbols,
3039 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3040 These are just performance bugs, and we can't distinguish gdb-generated
3041 indices from gold-generated ones, so issue no warning here. */
3043 /* Indexes with higher version than the one supported by GDB may be no
3044 longer backward compatible. */
3048 map
->version
= version
;
3050 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3053 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3054 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3058 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3059 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3060 - MAYBE_SWAP (metadata
[i
]))
3064 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3065 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3067 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3070 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3071 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3073 = gdb::array_view
<mapped_index::symbol_table_slot
>
3074 ((mapped_index::symbol_table_slot
*) symbol_table
,
3075 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3078 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3083 /* Callback types for dwarf2_read_gdb_index. */
3085 typedef gdb::function_view
3086 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3087 get_gdb_index_contents_ftype
;
3088 typedef gdb::function_view
3089 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3090 get_gdb_index_contents_dwz_ftype
;
3092 /* Read .gdb_index. If everything went ok, initialize the "quick"
3093 elements of all the CUs and return 1. Otherwise, return 0. */
3096 dwarf2_read_gdb_index
3097 (dwarf2_per_objfile
*per_objfile
,
3098 get_gdb_index_contents_ftype get_gdb_index_contents
,
3099 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3101 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3102 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3103 struct dwz_file
*dwz
;
3104 struct objfile
*objfile
= per_objfile
->objfile
;
3105 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3107 gdb::array_view
<const gdb_byte
> main_index_contents
3108 = get_gdb_index_contents (objfile
, per_bfd
);
3110 if (main_index_contents
.empty ())
3113 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3114 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3115 use_deprecated_index_sections
,
3116 main_index_contents
, map
.get (), &cu_list
,
3117 &cu_list_elements
, &types_list
,
3118 &types_list_elements
))
3121 /* Don't use the index if it's empty. */
3122 if (map
->symbol_table
.empty ())
3125 /* If there is a .dwz file, read it so we can get its CU list as
3127 dwz
= dwarf2_get_dwz_file (per_bfd
);
3130 struct mapped_index dwz_map
;
3131 const gdb_byte
*dwz_types_ignore
;
3132 offset_type dwz_types_elements_ignore
;
3134 gdb::array_view
<const gdb_byte
> dwz_index_content
3135 = get_gdb_index_contents_dwz (objfile
, dwz
);
3137 if (dwz_index_content
.empty ())
3140 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3141 1, dwz_index_content
, &dwz_map
,
3142 &dwz_list
, &dwz_list_elements
,
3144 &dwz_types_elements_ignore
))
3146 warning (_("could not read '.gdb_index' section from %s; skipping"),
3147 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3152 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3155 if (types_list_elements
)
3157 /* We can only handle a single .debug_types when we have an
3159 if (per_bfd
->types
.size () != 1)
3162 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3164 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3165 types_list_elements
);
3168 create_addrmap_from_index (per_objfile
, map
.get ());
3170 per_bfd
->index_table
= std::move (map
);
3171 per_bfd
->using_index
= 1;
3172 per_bfd
->quick_file_names_table
=
3173 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3175 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3176 objfiles using the same BFD. */
3177 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3178 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3183 /* die_reader_func for dw2_get_file_names. */
3186 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3187 const gdb_byte
*info_ptr
,
3188 struct die_info
*comp_unit_die
)
3190 struct dwarf2_cu
*cu
= reader
->cu
;
3191 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3192 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3193 struct dwarf2_per_cu_data
*lh_cu
;
3194 struct attribute
*attr
;
3196 struct quick_file_names
*qfn
;
3198 gdb_assert (! this_cu
->is_debug_types
);
3200 /* Our callers never want to match partial units -- instead they
3201 will match the enclosing full CU. */
3202 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3204 this_cu
->v
.quick
->no_file_data
= 1;
3212 sect_offset line_offset
{};
3214 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3215 if (attr
!= nullptr && attr
->form_is_unsigned ())
3217 struct quick_file_names find_entry
;
3219 line_offset
= (sect_offset
) attr
->as_unsigned ();
3221 /* We may have already read in this line header (TU line header sharing).
3222 If we have we're done. */
3223 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3224 find_entry
.hash
.line_sect_off
= line_offset
;
3225 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3226 &find_entry
, INSERT
);
3229 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3233 lh
= dwarf_decode_line_header (line_offset
, cu
);
3237 lh_cu
->v
.quick
->no_file_data
= 1;
3241 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3242 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3243 qfn
->hash
.line_sect_off
= line_offset
;
3244 gdb_assert (slot
!= NULL
);
3247 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3250 if (strcmp (fnd
.name
, "<unknown>") != 0)
3253 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3255 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3256 qfn
->num_file_names
);
3258 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3259 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3260 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3261 fnd
.comp_dir
).release ();
3262 qfn
->real_names
= NULL
;
3264 lh_cu
->v
.quick
->file_names
= qfn
;
3267 /* A helper for the "quick" functions which attempts to read the line
3268 table for THIS_CU. */
3270 static struct quick_file_names
*
3271 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3272 dwarf2_per_objfile
*per_objfile
)
3274 /* This should never be called for TUs. */
3275 gdb_assert (! this_cu
->is_debug_types
);
3276 /* Nor type unit groups. */
3277 gdb_assert (! this_cu
->type_unit_group_p ());
3279 if (this_cu
->v
.quick
->file_names
!= NULL
)
3280 return this_cu
->v
.quick
->file_names
;
3281 /* If we know there is no line data, no point in looking again. */
3282 if (this_cu
->v
.quick
->no_file_data
)
3285 cutu_reader
reader (this_cu
, per_objfile
);
3286 if (!reader
.dummy_p
)
3287 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3289 if (this_cu
->v
.quick
->no_file_data
)
3291 return this_cu
->v
.quick
->file_names
;
3294 /* A helper for the "quick" functions which computes and caches the
3295 real path for a given file name from the line table. */
3298 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3299 struct quick_file_names
*qfn
, int index
)
3301 if (qfn
->real_names
== NULL
)
3302 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3303 qfn
->num_file_names
, const char *);
3305 if (qfn
->real_names
[index
] == NULL
)
3306 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3308 return qfn
->real_names
[index
];
3311 static struct symtab
*
3312 dw2_find_last_source_symtab (struct objfile
*objfile
)
3314 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3315 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3316 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3321 return compunit_primary_filetab (cust
);
3324 /* Traversal function for dw2_forget_cached_source_info. */
3327 dw2_free_cached_file_names (void **slot
, void *info
)
3329 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3331 if (file_data
->real_names
)
3335 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3337 xfree ((void*) file_data
->real_names
[i
]);
3338 file_data
->real_names
[i
] = NULL
;
3346 dw2_forget_cached_source_info (struct objfile
*objfile
)
3348 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3350 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3351 dw2_free_cached_file_names
, NULL
);
3354 /* Helper function for dw2_map_symtabs_matching_filename that expands
3355 the symtabs and calls the iterator. */
3358 dw2_map_expand_apply (struct objfile
*objfile
,
3359 struct dwarf2_per_cu_data
*per_cu
,
3360 const char *name
, const char *real_path
,
3361 gdb::function_view
<bool (symtab
*)> callback
)
3363 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3365 /* Don't visit already-expanded CUs. */
3366 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3367 if (per_objfile
->symtab_set_p (per_cu
))
3370 /* This may expand more than one symtab, and we want to iterate over
3372 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3374 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3375 last_made
, callback
);
3378 /* Implementation of the map_symtabs_matching_filename method. */
3381 dw2_map_symtabs_matching_filename
3382 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3383 gdb::function_view
<bool (symtab
*)> callback
)
3385 const char *name_basename
= lbasename (name
);
3386 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3388 /* The rule is CUs specify all the files, including those used by
3389 any TU, so there's no need to scan TUs here. */
3391 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3393 /* We only need to look at symtabs not already expanded. */
3394 if (per_objfile
->symtab_set_p (per_cu
))
3397 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3398 if (file_data
== NULL
)
3401 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3403 const char *this_name
= file_data
->file_names
[j
];
3404 const char *this_real_name
;
3406 if (compare_filenames_for_search (this_name
, name
))
3408 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3414 /* Before we invoke realpath, which can get expensive when many
3415 files are involved, do a quick comparison of the basenames. */
3416 if (! basenames_may_differ
3417 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3420 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3421 if (compare_filenames_for_search (this_real_name
, name
))
3423 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3429 if (real_path
!= NULL
)
3431 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3432 gdb_assert (IS_ABSOLUTE_PATH (name
));
3433 if (this_real_name
!= NULL
3434 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3436 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3448 /* Struct used to manage iterating over all CUs looking for a symbol. */
3450 struct dw2_symtab_iterator
3452 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3453 dwarf2_per_objfile
*per_objfile
;
3454 /* If set, only look for symbols that match that block. Valid values are
3455 GLOBAL_BLOCK and STATIC_BLOCK. */
3456 gdb::optional
<block_enum
> block_index
;
3457 /* The kind of symbol we're looking for. */
3459 /* The list of CUs from the index entry of the symbol,
3460 or NULL if not found. */
3462 /* The next element in VEC to look at. */
3464 /* The number of elements in VEC, or zero if there is no match. */
3466 /* Have we seen a global version of the symbol?
3467 If so we can ignore all further global instances.
3468 This is to work around gold/15646, inefficient gold-generated
3473 /* Initialize the index symtab iterator ITER, common part. */
3476 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3477 dwarf2_per_objfile
*per_objfile
,
3478 gdb::optional
<block_enum
> block_index
,
3481 iter
->per_objfile
= per_objfile
;
3482 iter
->block_index
= block_index
;
3483 iter
->domain
= domain
;
3485 iter
->global_seen
= 0;
3490 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3493 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3494 dwarf2_per_objfile
*per_objfile
,
3495 gdb::optional
<block_enum
> block_index
,
3499 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3501 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3502 /* index is NULL if OBJF_READNOW. */
3506 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3507 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3510 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3513 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3514 dwarf2_per_objfile
*per_objfile
,
3515 gdb::optional
<block_enum
> block_index
,
3516 domain_enum domain
, offset_type namei
)
3518 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3520 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3521 /* index is NULL if OBJF_READNOW. */
3525 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3526 const auto &bucket
= index
->symbol_table
[namei
];
3528 iter
->vec
= (offset_type
*) (index
->constant_pool
3529 + MAYBE_SWAP (bucket
.vec
));
3530 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3533 /* Return the next matching CU or NULL if there are no more. */
3535 static struct dwarf2_per_cu_data
*
3536 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3538 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3540 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3542 offset_type cu_index_and_attrs
=
3543 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3544 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3545 gdb_index_symbol_kind symbol_kind
=
3546 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3547 /* Only check the symbol attributes if they're present.
3548 Indices prior to version 7 don't record them,
3549 and indices >= 7 may elide them for certain symbols
3550 (gold does this). */
3552 (per_objfile
->per_bfd
->index_table
->version
>= 7
3553 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3555 /* Don't crash on bad data. */
3556 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3557 + per_objfile
->per_bfd
->all_type_units
.size ()))
3559 complaint (_(".gdb_index entry has bad CU index"
3560 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3564 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3566 /* Skip if already read in. */
3567 if (per_objfile
->symtab_set_p (per_cu
))
3570 /* Check static vs global. */
3573 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3575 if (iter
->block_index
.has_value ())
3577 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3579 if (is_static
!= want_static
)
3583 /* Work around gold/15646. */
3585 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3587 if (iter
->global_seen
)
3590 iter
->global_seen
= 1;
3594 /* Only check the symbol's kind if it has one. */
3597 switch (iter
->domain
)
3600 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3601 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3602 /* Some types are also in VAR_DOMAIN. */
3603 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3607 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3611 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3615 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3630 static struct compunit_symtab
*
3631 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3632 const char *name
, domain_enum domain
)
3634 struct compunit_symtab
*stab_best
= NULL
;
3635 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3637 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3639 struct dw2_symtab_iterator iter
;
3640 struct dwarf2_per_cu_data
*per_cu
;
3642 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3644 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3646 struct symbol
*sym
, *with_opaque
= NULL
;
3647 struct compunit_symtab
*stab
3648 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3649 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3650 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3652 sym
= block_find_symbol (block
, name
, domain
,
3653 block_find_non_opaque_type_preferred
,
3656 /* Some caution must be observed with overloaded functions
3657 and methods, since the index will not contain any overload
3658 information (but NAME might contain it). */
3661 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3663 if (with_opaque
!= NULL
3664 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3667 /* Keep looking through other CUs. */
3674 dw2_print_stats (struct objfile
*objfile
)
3676 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3677 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3678 + per_objfile
->per_bfd
->all_type_units
.size ());
3681 for (int i
= 0; i
< total
; ++i
)
3683 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3685 if (!per_objfile
->symtab_set_p (per_cu
))
3688 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3689 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3692 /* This dumps minimal information about the index.
3693 It is called via "mt print objfiles".
3694 One use is to verify .gdb_index has been loaded by the
3695 gdb.dwarf2/gdb-index.exp testcase. */
3698 dw2_dump (struct objfile
*objfile
)
3700 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3702 gdb_assert (per_objfile
->per_bfd
->using_index
);
3703 printf_filtered (".gdb_index:");
3704 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3706 printf_filtered (" version %d\n",
3707 per_objfile
->per_bfd
->index_table
->version
);
3710 printf_filtered (" faked for \"readnow\"\n");
3711 printf_filtered ("\n");
3715 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3716 const char *func_name
)
3718 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3720 struct dw2_symtab_iterator iter
;
3721 struct dwarf2_per_cu_data
*per_cu
;
3723 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3725 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3726 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3731 dw2_expand_all_symtabs (struct objfile
*objfile
)
3733 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3734 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3735 + per_objfile
->per_bfd
->all_type_units
.size ());
3737 for (int i
= 0; i
< total_units
; ++i
)
3739 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3741 /* We don't want to directly expand a partial CU, because if we
3742 read it with the wrong language, then assertion failures can
3743 be triggered later on. See PR symtab/23010. So, tell
3744 dw2_instantiate_symtab to skip partial CUs -- any important
3745 partial CU will be read via DW_TAG_imported_unit anyway. */
3746 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3751 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3752 const char *fullname
)
3754 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3756 /* We don't need to consider type units here.
3757 This is only called for examining code, e.g. expand_line_sal.
3758 There can be an order of magnitude (or more) more type units
3759 than comp units, and we avoid them if we can. */
3761 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3763 /* We only need to look at symtabs not already expanded. */
3764 if (per_objfile
->symtab_set_p (per_cu
))
3767 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3768 if (file_data
== NULL
)
3771 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3773 const char *this_fullname
= file_data
->file_names
[j
];
3775 if (filename_cmp (this_fullname
, fullname
) == 0)
3777 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3785 dw2_expand_symtabs_matching_symbol
3786 (mapped_index_base
&index
,
3787 const lookup_name_info
&lookup_name_in
,
3788 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3789 enum search_domain kind
,
3790 gdb::function_view
<bool (offset_type
)> match_callback
,
3791 dwarf2_per_objfile
*per_objfile
);
3794 dw2_expand_symtabs_matching_one
3795 (dwarf2_per_cu_data
*per_cu
,
3796 dwarf2_per_objfile
*per_objfile
,
3797 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3798 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3801 dw2_map_matching_symbols
3802 (struct objfile
*objfile
,
3803 const lookup_name_info
&name
, domain_enum domain
,
3805 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3806 symbol_compare_ftype
*ordered_compare
)
3809 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3811 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3813 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3815 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3817 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3818 auto matcher
= [&] (const char *symname
)
3820 if (ordered_compare
== nullptr)
3822 return ordered_compare (symname
, match_name
) == 0;
3825 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3826 [&] (offset_type namei
)
3828 struct dw2_symtab_iterator iter
;
3829 struct dwarf2_per_cu_data
*per_cu
;
3831 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3833 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3834 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3841 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3842 proceed assuming all symtabs have been read in. */
3845 for (compunit_symtab
*cust
: objfile
->compunits ())
3847 const struct block
*block
;
3851 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3852 if (!iterate_over_symbols_terminated (block
, name
,
3858 /* Starting from a search name, return the string that finds the upper
3859 bound of all strings that start with SEARCH_NAME in a sorted name
3860 list. Returns the empty string to indicate that the upper bound is
3861 the end of the list. */
3864 make_sort_after_prefix_name (const char *search_name
)
3866 /* When looking to complete "func", we find the upper bound of all
3867 symbols that start with "func" by looking for where we'd insert
3868 the closest string that would follow "func" in lexicographical
3869 order. Usually, that's "func"-with-last-character-incremented,
3870 i.e. "fund". Mind non-ASCII characters, though. Usually those
3871 will be UTF-8 multi-byte sequences, but we can't be certain.
3872 Especially mind the 0xff character, which is a valid character in
3873 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3874 rule out compilers allowing it in identifiers. Note that
3875 conveniently, strcmp/strcasecmp are specified to compare
3876 characters interpreted as unsigned char. So what we do is treat
3877 the whole string as a base 256 number composed of a sequence of
3878 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3879 to 0, and carries 1 to the following more-significant position.
3880 If the very first character in SEARCH_NAME ends up incremented
3881 and carries/overflows, then the upper bound is the end of the
3882 list. The string after the empty string is also the empty
3885 Some examples of this operation:
3887 SEARCH_NAME => "+1" RESULT
3891 "\xff" "a" "\xff" => "\xff" "b"
3896 Then, with these symbols for example:
3902 completing "func" looks for symbols between "func" and
3903 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3904 which finds "func" and "func1", but not "fund".
3908 funcÿ (Latin1 'ÿ' [0xff])
3912 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3913 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3917 ÿÿ (Latin1 'ÿ' [0xff])
3920 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3921 the end of the list.
3923 std::string after
= search_name
;
3924 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3926 if (!after
.empty ())
3927 after
.back () = (unsigned char) after
.back () + 1;
3931 /* See declaration. */
3933 std::pair
<std::vector
<name_component
>::const_iterator
,
3934 std::vector
<name_component
>::const_iterator
>
3935 mapped_index_base::find_name_components_bounds
3936 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3937 dwarf2_per_objfile
*per_objfile
) const
3940 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3942 const char *lang_name
3943 = lookup_name_without_params
.language_lookup_name (lang
);
3945 /* Comparison function object for lower_bound that matches against a
3946 given symbol name. */
3947 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3950 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3951 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3952 return name_cmp (elem_name
, name
) < 0;
3955 /* Comparison function object for upper_bound that matches against a
3956 given symbol name. */
3957 auto lookup_compare_upper
= [&] (const char *name
,
3958 const name_component
&elem
)
3960 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3961 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3962 return name_cmp (name
, elem_name
) < 0;
3965 auto begin
= this->name_components
.begin ();
3966 auto end
= this->name_components
.end ();
3968 /* Find the lower bound. */
3971 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3974 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3977 /* Find the upper bound. */
3980 if (lookup_name_without_params
.completion_mode ())
3982 /* In completion mode, we want UPPER to point past all
3983 symbols names that have the same prefix. I.e., with
3984 these symbols, and completing "func":
3986 function << lower bound
3988 other_function << upper bound
3990 We find the upper bound by looking for the insertion
3991 point of "func"-with-last-character-incremented,
3993 std::string after
= make_sort_after_prefix_name (lang_name
);
3996 return std::lower_bound (lower
, end
, after
.c_str (),
3997 lookup_compare_lower
);
4000 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4003 return {lower
, upper
};
4006 /* See declaration. */
4009 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
4011 if (!this->name_components
.empty ())
4014 this->name_components_casing
= case_sensitivity
;
4016 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4018 /* The code below only knows how to break apart components of C++
4019 symbol names (and other languages that use '::' as
4020 namespace/module separator) and Ada symbol names. */
4021 auto count
= this->symbol_name_count ();
4022 for (offset_type idx
= 0; idx
< count
; idx
++)
4024 if (this->symbol_name_slot_invalid (idx
))
4027 const char *name
= this->symbol_name_at (idx
, per_objfile
);
4029 /* Add each name component to the name component table. */
4030 unsigned int previous_len
= 0;
4032 if (strstr (name
, "::") != nullptr)
4034 for (unsigned int current_len
= cp_find_first_component (name
);
4035 name
[current_len
] != '\0';
4036 current_len
+= cp_find_first_component (name
+ current_len
))
4038 gdb_assert (name
[current_len
] == ':');
4039 this->name_components
.push_back ({previous_len
, idx
});
4040 /* Skip the '::'. */
4042 previous_len
= current_len
;
4047 /* Handle the Ada encoded (aka mangled) form here. */
4048 for (const char *iter
= strstr (name
, "__");
4050 iter
= strstr (iter
, "__"))
4052 this->name_components
.push_back ({previous_len
, idx
});
4054 previous_len
= iter
- name
;
4058 this->name_components
.push_back ({previous_len
, idx
});
4061 /* Sort name_components elements by name. */
4062 auto name_comp_compare
= [&] (const name_component
&left
,
4063 const name_component
&right
)
4065 const char *left_qualified
4066 = this->symbol_name_at (left
.idx
, per_objfile
);
4067 const char *right_qualified
4068 = this->symbol_name_at (right
.idx
, per_objfile
);
4070 const char *left_name
= left_qualified
+ left
.name_offset
;
4071 const char *right_name
= right_qualified
+ right
.name_offset
;
4073 return name_cmp (left_name
, right_name
) < 0;
4076 std::sort (this->name_components
.begin (),
4077 this->name_components
.end (),
4081 /* Helper for dw2_expand_symtabs_matching that works with a
4082 mapped_index_base instead of the containing objfile. This is split
4083 to a separate function in order to be able to unit test the
4084 name_components matching using a mock mapped_index_base. For each
4085 symbol name that matches, calls MATCH_CALLBACK, passing it the
4086 symbol's index in the mapped_index_base symbol table. */
4089 dw2_expand_symtabs_matching_symbol
4090 (mapped_index_base
&index
,
4091 const lookup_name_info
&lookup_name_in
,
4092 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4093 enum search_domain kind
,
4094 gdb::function_view
<bool (offset_type
)> match_callback
,
4095 dwarf2_per_objfile
*per_objfile
)
4097 lookup_name_info lookup_name_without_params
4098 = lookup_name_in
.make_ignore_params ();
4100 /* Build the symbol name component sorted vector, if we haven't
4102 index
.build_name_components (per_objfile
);
4104 /* The same symbol may appear more than once in the range though.
4105 E.g., if we're looking for symbols that complete "w", and we have
4106 a symbol named "w1::w2", we'll find the two name components for
4107 that same symbol in the range. To be sure we only call the
4108 callback once per symbol, we first collect the symbol name
4109 indexes that matched in a temporary vector and ignore
4111 std::vector
<offset_type
> matches
;
4113 struct name_and_matcher
4115 symbol_name_matcher_ftype
*matcher
;
4118 bool operator== (const name_and_matcher
&other
) const
4120 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4124 /* A vector holding all the different symbol name matchers, for all
4126 std::vector
<name_and_matcher
> matchers
;
4128 for (int i
= 0; i
< nr_languages
; i
++)
4130 enum language lang_e
= (enum language
) i
;
4132 const language_defn
*lang
= language_def (lang_e
);
4133 symbol_name_matcher_ftype
*name_matcher
4134 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4136 name_and_matcher key
{
4138 lookup_name_without_params
.language_lookup_name (lang_e
)
4141 /* Don't insert the same comparison routine more than once.
4142 Note that we do this linear walk. This is not a problem in
4143 practice because the number of supported languages is
4145 if (std::find (matchers
.begin (), matchers
.end (), key
)
4148 matchers
.push_back (std::move (key
));
4151 = index
.find_name_components_bounds (lookup_name_without_params
,
4152 lang_e
, per_objfile
);
4154 /* Now for each symbol name in range, check to see if we have a name
4155 match, and if so, call the MATCH_CALLBACK callback. */
4157 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4159 const char *qualified
4160 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4162 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4163 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4166 matches
.push_back (bounds
.first
->idx
);
4170 std::sort (matches
.begin (), matches
.end ());
4172 /* Finally call the callback, once per match. */
4174 for (offset_type idx
: matches
)
4178 if (!match_callback (idx
))
4184 /* Above we use a type wider than idx's for 'prev', since 0 and
4185 (offset_type)-1 are both possible values. */
4186 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4191 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4193 /* A mock .gdb_index/.debug_names-like name index table, enough to
4194 exercise dw2_expand_symtabs_matching_symbol, which works with the
4195 mapped_index_base interface. Builds an index from the symbol list
4196 passed as parameter to the constructor. */
4197 class mock_mapped_index
: public mapped_index_base
4200 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4201 : m_symbol_table (symbols
)
4204 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4206 /* Return the number of names in the symbol table. */
4207 size_t symbol_name_count () const override
4209 return m_symbol_table
.size ();
4212 /* Get the name of the symbol at IDX in the symbol table. */
4213 const char *symbol_name_at
4214 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4216 return m_symbol_table
[idx
];
4220 gdb::array_view
<const char *> m_symbol_table
;
4223 /* Convenience function that converts a NULL pointer to a "<null>"
4224 string, to pass to print routines. */
4227 string_or_null (const char *str
)
4229 return str
!= NULL
? str
: "<null>";
4232 /* Check if a lookup_name_info built from
4233 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4234 index. EXPECTED_LIST is the list of expected matches, in expected
4235 matching order. If no match expected, then an empty list is
4236 specified. Returns true on success. On failure prints a warning
4237 indicating the file:line that failed, and returns false. */
4240 check_match (const char *file
, int line
,
4241 mock_mapped_index
&mock_index
,
4242 const char *name
, symbol_name_match_type match_type
,
4243 bool completion_mode
,
4244 std::initializer_list
<const char *> expected_list
,
4245 dwarf2_per_objfile
*per_objfile
)
4247 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4249 bool matched
= true;
4251 auto mismatch
= [&] (const char *expected_str
,
4254 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4255 "expected=\"%s\", got=\"%s\"\n"),
4257 (match_type
== symbol_name_match_type::FULL
4259 name
, string_or_null (expected_str
), string_or_null (got
));
4263 auto expected_it
= expected_list
.begin ();
4264 auto expected_end
= expected_list
.end ();
4266 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4268 [&] (offset_type idx
)
4270 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4271 const char *expected_str
4272 = expected_it
== expected_end
? NULL
: *expected_it
++;
4274 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4275 mismatch (expected_str
, matched_name
);
4279 const char *expected_str
4280 = expected_it
== expected_end
? NULL
: *expected_it
++;
4281 if (expected_str
!= NULL
)
4282 mismatch (expected_str
, NULL
);
4287 /* The symbols added to the mock mapped_index for testing (in
4289 static const char *test_symbols
[] = {
4298 "ns2::tmpl<int>::foo2",
4299 "(anonymous namespace)::A::B::C",
4301 /* These are used to check that the increment-last-char in the
4302 matching algorithm for completion doesn't match "t1_fund" when
4303 completing "t1_func". */
4309 /* A UTF-8 name with multi-byte sequences to make sure that
4310 cp-name-parser understands this as a single identifier ("função"
4311 is "function" in PT). */
4314 /* \377 (0xff) is Latin1 'ÿ'. */
4317 /* \377 (0xff) is Latin1 'ÿ'. */
4321 /* A name with all sorts of complications. Starts with "z" to make
4322 it easier for the completion tests below. */
4323 #define Z_SYM_NAME \
4324 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4325 "::tuple<(anonymous namespace)::ui*, " \
4326 "std::default_delete<(anonymous namespace)::ui>, void>"
4331 /* Returns true if the mapped_index_base::find_name_component_bounds
4332 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4333 in completion mode. */
4336 check_find_bounds_finds (mapped_index_base
&index
,
4337 const char *search_name
,
4338 gdb::array_view
<const char *> expected_syms
,
4339 dwarf2_per_objfile
*per_objfile
)
4341 lookup_name_info
lookup_name (search_name
,
4342 symbol_name_match_type::FULL
, true);
4344 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4348 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4349 if (distance
!= expected_syms
.size ())
4352 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4354 auto nc_elem
= bounds
.first
+ exp_elem
;
4355 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4356 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4363 /* Test the lower-level mapped_index::find_name_component_bounds
4367 test_mapped_index_find_name_component_bounds ()
4369 mock_mapped_index
mock_index (test_symbols
);
4371 mock_index
.build_name_components (NULL
/* per_objfile */);
4373 /* Test the lower-level mapped_index::find_name_component_bounds
4374 method in completion mode. */
4376 static const char *expected_syms
[] = {
4381 SELF_CHECK (check_find_bounds_finds
4382 (mock_index
, "t1_func", expected_syms
,
4383 NULL
/* per_objfile */));
4386 /* Check that the increment-last-char in the name matching algorithm
4387 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4389 static const char *expected_syms1
[] = {
4393 SELF_CHECK (check_find_bounds_finds
4394 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4396 static const char *expected_syms2
[] = {
4399 SELF_CHECK (check_find_bounds_finds
4400 (mock_index
, "\377\377", expected_syms2
,
4401 NULL
/* per_objfile */));
4405 /* Test dw2_expand_symtabs_matching_symbol. */
4408 test_dw2_expand_symtabs_matching_symbol ()
4410 mock_mapped_index
mock_index (test_symbols
);
4412 /* We let all tests run until the end even if some fails, for debug
4414 bool any_mismatch
= false;
4416 /* Create the expected symbols list (an initializer_list). Needed
4417 because lists have commas, and we need to pass them to CHECK,
4418 which is a macro. */
4419 #define EXPECT(...) { __VA_ARGS__ }
4421 /* Wrapper for check_match that passes down the current
4422 __FILE__/__LINE__. */
4423 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4424 any_mismatch |= !check_match (__FILE__, __LINE__, \
4426 NAME, MATCH_TYPE, COMPLETION_MODE, \
4427 EXPECTED_LIST, NULL)
4429 /* Identity checks. */
4430 for (const char *sym
: test_symbols
)
4432 /* Should be able to match all existing symbols. */
4433 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4436 /* Should be able to match all existing symbols with
4438 std::string with_params
= std::string (sym
) + "(int)";
4439 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4442 /* Should be able to match all existing symbols with
4443 parameters and qualifiers. */
4444 with_params
= std::string (sym
) + " ( int ) const";
4445 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4448 /* This should really find sym, but cp-name-parser.y doesn't
4449 know about lvalue/rvalue qualifiers yet. */
4450 with_params
= std::string (sym
) + " ( int ) &&";
4451 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4455 /* Check that the name matching algorithm for completion doesn't get
4456 confused with Latin1 'ÿ' / 0xff. */
4458 static const char str
[] = "\377";
4459 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4460 EXPECT ("\377", "\377\377123"));
4463 /* Check that the increment-last-char in the matching algorithm for
4464 completion doesn't match "t1_fund" when completing "t1_func". */
4466 static const char str
[] = "t1_func";
4467 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4468 EXPECT ("t1_func", "t1_func1"));
4471 /* Check that completion mode works at each prefix of the expected
4474 static const char str
[] = "function(int)";
4475 size_t len
= strlen (str
);
4478 for (size_t i
= 1; i
< len
; i
++)
4480 lookup
.assign (str
, i
);
4481 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4482 EXPECT ("function"));
4486 /* While "w" is a prefix of both components, the match function
4487 should still only be called once. */
4489 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4491 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4495 /* Same, with a "complicated" symbol. */
4497 static const char str
[] = Z_SYM_NAME
;
4498 size_t len
= strlen (str
);
4501 for (size_t i
= 1; i
< len
; i
++)
4503 lookup
.assign (str
, i
);
4504 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4505 EXPECT (Z_SYM_NAME
));
4509 /* In FULL mode, an incomplete symbol doesn't match. */
4511 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4515 /* A complete symbol with parameters matches any overload, since the
4516 index has no overload info. */
4518 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4519 EXPECT ("std::zfunction", "std::zfunction2"));
4520 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4521 EXPECT ("std::zfunction", "std::zfunction2"));
4522 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4523 EXPECT ("std::zfunction", "std::zfunction2"));
4526 /* Check that whitespace is ignored appropriately. A symbol with a
4527 template argument list. */
4529 static const char expected
[] = "ns::foo<int>";
4530 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4532 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4536 /* Check that whitespace is ignored appropriately. A symbol with a
4537 template argument list that includes a pointer. */
4539 static const char expected
[] = "ns::foo<char*>";
4540 /* Try both completion and non-completion modes. */
4541 static const bool completion_mode
[2] = {false, true};
4542 for (size_t i
= 0; i
< 2; i
++)
4544 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4545 completion_mode
[i
], EXPECT (expected
));
4546 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4547 completion_mode
[i
], EXPECT (expected
));
4549 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4550 completion_mode
[i
], EXPECT (expected
));
4551 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4552 completion_mode
[i
], EXPECT (expected
));
4557 /* Check method qualifiers are ignored. */
4558 static const char expected
[] = "ns::foo<char*>";
4559 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4560 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4561 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4562 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4563 CHECK_MATCH ("foo < char * > ( int ) const",
4564 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4565 CHECK_MATCH ("foo < char * > ( int ) &&",
4566 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4569 /* Test lookup names that don't match anything. */
4571 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4574 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4578 /* Some wild matching tests, exercising "(anonymous namespace)",
4579 which should not be confused with a parameter list. */
4581 static const char *syms
[] = {
4585 "A :: B :: C ( int )",
4590 for (const char *s
: syms
)
4592 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4593 EXPECT ("(anonymous namespace)::A::B::C"));
4598 static const char expected
[] = "ns2::tmpl<int>::foo2";
4599 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4601 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4605 SELF_CHECK (!any_mismatch
);
4614 test_mapped_index_find_name_component_bounds ();
4615 test_dw2_expand_symtabs_matching_symbol ();
4618 }} // namespace selftests::dw2_expand_symtabs_matching
4620 #endif /* GDB_SELF_TEST */
4622 /* If FILE_MATCHER is NULL or if PER_CU has
4623 dwarf2_per_cu_quick_data::MARK set (see
4624 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4625 EXPANSION_NOTIFY on it. */
4628 dw2_expand_symtabs_matching_one
4629 (dwarf2_per_cu_data
*per_cu
,
4630 dwarf2_per_objfile
*per_objfile
,
4631 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4632 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4634 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4636 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4638 compunit_symtab
*symtab
4639 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4640 gdb_assert (symtab
!= nullptr);
4642 if (expansion_notify
!= NULL
&& symtab_was_null
)
4643 expansion_notify (symtab
);
4647 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4648 matched, to expand corresponding CUs that were marked. IDX is the
4649 index of the symbol name that matched. */
4652 dw2_expand_marked_cus
4653 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4654 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4655 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4658 offset_type
*vec
, vec_len
, vec_idx
;
4659 bool global_seen
= false;
4660 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4662 vec
= (offset_type
*) (index
.constant_pool
4663 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4664 vec_len
= MAYBE_SWAP (vec
[0]);
4665 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4667 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4668 /* This value is only valid for index versions >= 7. */
4669 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4670 gdb_index_symbol_kind symbol_kind
=
4671 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4672 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4673 /* Only check the symbol attributes if they're present.
4674 Indices prior to version 7 don't record them,
4675 and indices >= 7 may elide them for certain symbols
4676 (gold does this). */
4679 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4681 /* Work around gold/15646. */
4684 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4692 /* Only check the symbol's kind if it has one. */
4697 case VARIABLES_DOMAIN
:
4698 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4701 case FUNCTIONS_DOMAIN
:
4702 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4706 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4709 case MODULES_DOMAIN
:
4710 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4718 /* Don't crash on bad data. */
4719 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4720 + per_objfile
->per_bfd
->all_type_units
.size ()))
4722 complaint (_(".gdb_index entry has bad CU index"
4723 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4727 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4728 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4733 /* If FILE_MATCHER is non-NULL, set all the
4734 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4735 that match FILE_MATCHER. */
4738 dw_expand_symtabs_matching_file_matcher
4739 (dwarf2_per_objfile
*per_objfile
,
4740 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4742 if (file_matcher
== NULL
)
4745 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4747 NULL
, xcalloc
, xfree
));
4748 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4750 NULL
, xcalloc
, xfree
));
4752 /* The rule is CUs specify all the files, including those used by
4753 any TU, so there's no need to scan TUs here. */
4755 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4759 per_cu
->v
.quick
->mark
= 0;
4761 /* We only need to look at symtabs not already expanded. */
4762 if (per_objfile
->symtab_set_p (per_cu
))
4765 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4766 if (file_data
== NULL
)
4769 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4771 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4773 per_cu
->v
.quick
->mark
= 1;
4777 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4779 const char *this_real_name
;
4781 if (file_matcher (file_data
->file_names
[j
], false))
4783 per_cu
->v
.quick
->mark
= 1;
4787 /* Before we invoke realpath, which can get expensive when many
4788 files are involved, do a quick comparison of the basenames. */
4789 if (!basenames_may_differ
4790 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4794 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4795 if (file_matcher (this_real_name
, false))
4797 per_cu
->v
.quick
->mark
= 1;
4802 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4803 ? visited_found
.get ()
4804 : visited_not_found
.get (),
4811 dw2_expand_symtabs_matching
4812 (struct objfile
*objfile
,
4813 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4814 const lookup_name_info
*lookup_name
,
4815 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4816 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4817 enum search_domain kind
)
4819 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4821 /* index_table is NULL if OBJF_READNOW. */
4822 if (!per_objfile
->per_bfd
->index_table
)
4825 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4827 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4829 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4833 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4834 file_matcher
, expansion_notify
);
4839 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4841 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4843 kind
, [&] (offset_type idx
)
4845 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4851 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4854 static struct compunit_symtab
*
4855 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4860 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4861 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4864 if (cust
->includes
== NULL
)
4867 for (i
= 0; cust
->includes
[i
]; ++i
)
4869 struct compunit_symtab
*s
= cust
->includes
[i
];
4871 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4879 static struct compunit_symtab
*
4880 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4881 struct bound_minimal_symbol msymbol
,
4883 struct obj_section
*section
,
4886 struct dwarf2_per_cu_data
*data
;
4887 struct compunit_symtab
*result
;
4889 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4892 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4893 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4894 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4898 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4899 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4900 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4901 paddress (objfile
->arch (), pc
));
4903 result
= recursively_find_pc_sect_compunit_symtab
4904 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4906 gdb_assert (result
!= NULL
);
4911 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4912 void *data
, int need_fullname
)
4914 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4916 if (!per_objfile
->per_bfd
->filenames_cache
)
4918 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4920 htab_up
visited (htab_create_alloc (10,
4921 htab_hash_pointer
, htab_eq_pointer
,
4922 NULL
, xcalloc
, xfree
));
4924 /* The rule is CUs specify all the files, including those used
4925 by any TU, so there's no need to scan TUs here. We can
4926 ignore file names coming from already-expanded CUs. */
4928 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4930 if (per_objfile
->symtab_set_p (per_cu
))
4932 void **slot
= htab_find_slot (visited
.get (),
4933 per_cu
->v
.quick
->file_names
,
4936 *slot
= per_cu
->v
.quick
->file_names
;
4940 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4942 /* We only need to look at symtabs not already expanded. */
4943 if (per_objfile
->symtab_set_p (per_cu
))
4946 quick_file_names
*file_data
4947 = dw2_get_file_names (per_cu
, per_objfile
);
4948 if (file_data
== NULL
)
4951 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4954 /* Already visited. */
4959 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4961 const char *filename
= file_data
->file_names
[j
];
4962 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4967 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4969 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4972 this_real_name
= gdb_realpath (filename
);
4973 (*fun
) (filename
, this_real_name
.get (), data
);
4978 dw2_has_symbols (struct objfile
*objfile
)
4983 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4986 dw2_find_last_source_symtab
,
4987 dw2_forget_cached_source_info
,
4988 dw2_map_symtabs_matching_filename
,
4993 dw2_expand_symtabs_for_function
,
4994 dw2_expand_all_symtabs
,
4995 dw2_expand_symtabs_with_fullname
,
4996 dw2_map_matching_symbols
,
4997 dw2_expand_symtabs_matching
,
4998 dw2_find_pc_sect_compunit_symtab
,
5000 dw2_map_symbol_filenames
5003 /* DWARF-5 debug_names reader. */
5005 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5006 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5008 /* A helper function that reads the .debug_names section in SECTION
5009 and fills in MAP. FILENAME is the name of the file containing the
5010 section; it is used for error reporting.
5012 Returns true if all went well, false otherwise. */
5015 read_debug_names_from_section (struct objfile
*objfile
,
5016 const char *filename
,
5017 struct dwarf2_section_info
*section
,
5018 mapped_debug_names
&map
)
5020 if (section
->empty ())
5023 /* Older elfutils strip versions could keep the section in the main
5024 executable while splitting it for the separate debug info file. */
5025 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5028 section
->read (objfile
);
5030 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
5032 const gdb_byte
*addr
= section
->buffer
;
5034 bfd
*const abfd
= section
->get_bfd_owner ();
5036 unsigned int bytes_read
;
5037 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5040 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5041 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5042 if (bytes_read
+ length
!= section
->size
)
5044 /* There may be multiple per-CU indices. */
5045 warning (_("Section .debug_names in %s length %s does not match "
5046 "section length %s, ignoring .debug_names."),
5047 filename
, plongest (bytes_read
+ length
),
5048 pulongest (section
->size
));
5052 /* The version number. */
5053 uint16_t version
= read_2_bytes (abfd
, addr
);
5057 warning (_("Section .debug_names in %s has unsupported version %d, "
5058 "ignoring .debug_names."),
5064 uint16_t padding
= read_2_bytes (abfd
, addr
);
5068 warning (_("Section .debug_names in %s has unsupported padding %d, "
5069 "ignoring .debug_names."),
5074 /* comp_unit_count - The number of CUs in the CU list. */
5075 map
.cu_count
= read_4_bytes (abfd
, addr
);
5078 /* local_type_unit_count - The number of TUs in the local TU
5080 map
.tu_count
= read_4_bytes (abfd
, addr
);
5083 /* foreign_type_unit_count - The number of TUs in the foreign TU
5085 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5087 if (foreign_tu_count
!= 0)
5089 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5090 "ignoring .debug_names."),
5091 filename
, static_cast<unsigned long> (foreign_tu_count
));
5095 /* bucket_count - The number of hash buckets in the hash lookup
5097 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5100 /* name_count - The number of unique names in the index. */
5101 map
.name_count
= read_4_bytes (abfd
, addr
);
5104 /* abbrev_table_size - The size in bytes of the abbreviations
5106 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5109 /* augmentation_string_size - The size in bytes of the augmentation
5110 string. This value is rounded up to a multiple of 4. */
5111 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5113 map
.augmentation_is_gdb
= ((augmentation_string_size
5114 == sizeof (dwarf5_augmentation
))
5115 && memcmp (addr
, dwarf5_augmentation
,
5116 sizeof (dwarf5_augmentation
)) == 0);
5117 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5118 addr
+= augmentation_string_size
;
5121 map
.cu_table_reordered
= addr
;
5122 addr
+= map
.cu_count
* map
.offset_size
;
5124 /* List of Local TUs */
5125 map
.tu_table_reordered
= addr
;
5126 addr
+= map
.tu_count
* map
.offset_size
;
5128 /* Hash Lookup Table */
5129 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5130 addr
+= map
.bucket_count
* 4;
5131 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5132 addr
+= map
.name_count
* 4;
5135 map
.name_table_string_offs_reordered
= addr
;
5136 addr
+= map
.name_count
* map
.offset_size
;
5137 map
.name_table_entry_offs_reordered
= addr
;
5138 addr
+= map
.name_count
* map
.offset_size
;
5140 const gdb_byte
*abbrev_table_start
= addr
;
5143 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5148 const auto insertpair
5149 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5150 if (!insertpair
.second
)
5152 warning (_("Section .debug_names in %s has duplicate index %s, "
5153 "ignoring .debug_names."),
5154 filename
, pulongest (index_num
));
5157 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5158 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5163 mapped_debug_names::index_val::attr attr
;
5164 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5166 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5168 if (attr
.form
== DW_FORM_implicit_const
)
5170 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5174 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5176 indexval
.attr_vec
.push_back (std::move (attr
));
5179 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5181 warning (_("Section .debug_names in %s has abbreviation_table "
5182 "of size %s vs. written as %u, ignoring .debug_names."),
5183 filename
, plongest (addr
- abbrev_table_start
),
5187 map
.entry_pool
= addr
;
5192 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5196 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5197 const mapped_debug_names
&map
,
5198 dwarf2_section_info
§ion
,
5201 if (!map
.augmentation_is_gdb
)
5203 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5205 sect_offset sect_off
5206 = (sect_offset
) (extract_unsigned_integer
5207 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5209 map
.dwarf5_byte_order
));
5210 /* We don't know the length of the CU, because the CU list in a
5211 .debug_names index can be incomplete, so we can't use the start of
5212 the next CU as end of this CU. We create the CUs here with length 0,
5213 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5214 dwarf2_per_cu_data
*per_cu
5215 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5216 per_bfd
->all_comp_units
.push_back (per_cu
);
5220 sect_offset sect_off_prev
;
5221 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5223 sect_offset sect_off_next
;
5224 if (i
< map
.cu_count
)
5227 = (sect_offset
) (extract_unsigned_integer
5228 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5230 map
.dwarf5_byte_order
));
5233 sect_off_next
= (sect_offset
) section
.size
;
5236 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5237 dwarf2_per_cu_data
*per_cu
5238 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5239 sect_off_prev
, length
);
5240 per_bfd
->all_comp_units
.push_back (per_cu
);
5242 sect_off_prev
= sect_off_next
;
5246 /* Read the CU list from the mapped index, and use it to create all
5247 the CU objects for this dwarf2_per_objfile. */
5250 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5251 const mapped_debug_names
&map
,
5252 const mapped_debug_names
&dwz_map
)
5254 gdb_assert (per_bfd
->all_comp_units
.empty ());
5255 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5257 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5258 false /* is_dwz */);
5260 if (dwz_map
.cu_count
== 0)
5263 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5264 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5268 /* Read .debug_names. If everything went ok, initialize the "quick"
5269 elements of all the CUs and return true. Otherwise, return false. */
5272 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5274 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5275 mapped_debug_names dwz_map
;
5276 struct objfile
*objfile
= per_objfile
->objfile
;
5277 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5279 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5280 &per_objfile
->per_bfd
->debug_names
, *map
))
5283 /* Don't use the index if it's empty. */
5284 if (map
->name_count
== 0)
5287 /* If there is a .dwz file, read it so we can get its CU list as
5289 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5292 if (!read_debug_names_from_section (objfile
,
5293 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5294 &dwz
->debug_names
, dwz_map
))
5296 warning (_("could not read '.debug_names' section from %s; skipping"),
5297 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5302 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5304 if (map
->tu_count
!= 0)
5306 /* We can only handle a single .debug_types when we have an
5308 if (per_bfd
->types
.size () != 1)
5311 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5313 create_signatured_type_table_from_debug_names
5314 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5317 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5319 per_bfd
->debug_names_table
= std::move (map
);
5320 per_bfd
->using_index
= 1;
5321 per_bfd
->quick_file_names_table
=
5322 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5324 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5325 objfiles using the same BFD. */
5326 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5327 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5332 /* Type used to manage iterating over all CUs looking for a symbol for
5335 class dw2_debug_names_iterator
5338 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5339 gdb::optional
<block_enum
> block_index
,
5341 const char *name
, dwarf2_per_objfile
*per_objfile
)
5342 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5343 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5344 m_per_objfile (per_objfile
)
5347 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5348 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5351 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5352 m_per_objfile (per_objfile
)
5355 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5356 block_enum block_index
, domain_enum domain
,
5357 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5358 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5359 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5360 m_per_objfile (per_objfile
)
5363 /* Return the next matching CU or NULL if there are no more. */
5364 dwarf2_per_cu_data
*next ();
5367 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5369 dwarf2_per_objfile
*per_objfile
);
5370 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5372 dwarf2_per_objfile
*per_objfile
);
5374 /* The internalized form of .debug_names. */
5375 const mapped_debug_names
&m_map
;
5377 /* If set, only look for symbols that match that block. Valid values are
5378 GLOBAL_BLOCK and STATIC_BLOCK. */
5379 const gdb::optional
<block_enum
> m_block_index
;
5381 /* The kind of symbol we're looking for. */
5382 const domain_enum m_domain
= UNDEF_DOMAIN
;
5383 const search_domain m_search
= ALL_DOMAIN
;
5385 /* The list of CUs from the index entry of the symbol, or NULL if
5387 const gdb_byte
*m_addr
;
5389 dwarf2_per_objfile
*m_per_objfile
;
5393 mapped_debug_names::namei_to_name
5394 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5396 const ULONGEST namei_string_offs
5397 = extract_unsigned_integer ((name_table_string_offs_reordered
5398 + namei
* offset_size
),
5401 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5404 /* Find a slot in .debug_names for the object named NAME. If NAME is
5405 found, return pointer to its pool data. If NAME cannot be found,
5409 dw2_debug_names_iterator::find_vec_in_debug_names
5410 (const mapped_debug_names
&map
, const char *name
,
5411 dwarf2_per_objfile
*per_objfile
)
5413 int (*cmp
) (const char *, const char *);
5415 gdb::unique_xmalloc_ptr
<char> without_params
;
5416 if (current_language
->la_language
== language_cplus
5417 || current_language
->la_language
== language_fortran
5418 || current_language
->la_language
== language_d
)
5420 /* NAME is already canonical. Drop any qualifiers as
5421 .debug_names does not contain any. */
5423 if (strchr (name
, '(') != NULL
)
5425 without_params
= cp_remove_params (name
);
5426 if (without_params
!= NULL
)
5427 name
= without_params
.get ();
5431 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5433 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5435 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5436 (map
.bucket_table_reordered
5437 + (full_hash
% map
.bucket_count
)), 4,
5438 map
.dwarf5_byte_order
);
5442 if (namei
>= map
.name_count
)
5444 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5446 namei
, map
.name_count
,
5447 objfile_name (per_objfile
->objfile
));
5453 const uint32_t namei_full_hash
5454 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5455 (map
.hash_table_reordered
+ namei
), 4,
5456 map
.dwarf5_byte_order
);
5457 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5460 if (full_hash
== namei_full_hash
)
5462 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5464 #if 0 /* An expensive sanity check. */
5465 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5467 complaint (_("Wrong .debug_names hash for string at index %u "
5469 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5474 if (cmp (namei_string
, name
) == 0)
5476 const ULONGEST namei_entry_offs
5477 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5478 + namei
* map
.offset_size
),
5479 map
.offset_size
, map
.dwarf5_byte_order
);
5480 return map
.entry_pool
+ namei_entry_offs
;
5485 if (namei
>= map
.name_count
)
5491 dw2_debug_names_iterator::find_vec_in_debug_names
5492 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5494 if (namei
>= map
.name_count
)
5496 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5498 namei
, map
.name_count
,
5499 objfile_name (per_objfile
->objfile
));
5503 const ULONGEST namei_entry_offs
5504 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5505 + namei
* map
.offset_size
),
5506 map
.offset_size
, map
.dwarf5_byte_order
);
5507 return map
.entry_pool
+ namei_entry_offs
;
5510 /* See dw2_debug_names_iterator. */
5512 dwarf2_per_cu_data
*
5513 dw2_debug_names_iterator::next ()
5518 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5519 struct objfile
*objfile
= m_per_objfile
->objfile
;
5520 bfd
*const abfd
= objfile
->obfd
;
5524 unsigned int bytes_read
;
5525 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5526 m_addr
+= bytes_read
;
5530 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5531 if (indexval_it
== m_map
.abbrev_map
.cend ())
5533 complaint (_("Wrong .debug_names undefined abbrev code %s "
5535 pulongest (abbrev
), objfile_name (objfile
));
5538 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5539 enum class symbol_linkage
{
5543 } symbol_linkage_
= symbol_linkage::unknown
;
5544 dwarf2_per_cu_data
*per_cu
= NULL
;
5545 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5550 case DW_FORM_implicit_const
:
5551 ull
= attr
.implicit_const
;
5553 case DW_FORM_flag_present
:
5557 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5558 m_addr
+= bytes_read
;
5561 ull
= read_4_bytes (abfd
, m_addr
);
5565 ull
= read_8_bytes (abfd
, m_addr
);
5568 case DW_FORM_ref_sig8
:
5569 ull
= read_8_bytes (abfd
, m_addr
);
5573 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5574 dwarf_form_name (attr
.form
),
5575 objfile_name (objfile
));
5578 switch (attr
.dw_idx
)
5580 case DW_IDX_compile_unit
:
5581 /* Don't crash on bad data. */
5582 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5584 complaint (_(".debug_names entry has bad CU index %s"
5587 objfile_name (objfile
));
5590 per_cu
= per_bfd
->get_cutu (ull
);
5592 case DW_IDX_type_unit
:
5593 /* Don't crash on bad data. */
5594 if (ull
>= per_bfd
->all_type_units
.size ())
5596 complaint (_(".debug_names entry has bad TU index %s"
5599 objfile_name (objfile
));
5602 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5604 case DW_IDX_die_offset
:
5605 /* In a per-CU index (as opposed to a per-module index), index
5606 entries without CU attribute implicitly refer to the single CU. */
5608 per_cu
= per_bfd
->get_cu (0);
5610 case DW_IDX_GNU_internal
:
5611 if (!m_map
.augmentation_is_gdb
)
5613 symbol_linkage_
= symbol_linkage::static_
;
5615 case DW_IDX_GNU_external
:
5616 if (!m_map
.augmentation_is_gdb
)
5618 symbol_linkage_
= symbol_linkage::extern_
;
5623 /* Skip if already read in. */
5624 if (m_per_objfile
->symtab_set_p (per_cu
))
5627 /* Check static vs global. */
5628 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5630 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5631 const bool symbol_is_static
=
5632 symbol_linkage_
== symbol_linkage::static_
;
5633 if (want_static
!= symbol_is_static
)
5637 /* Match dw2_symtab_iter_next, symbol_kind
5638 and debug_names::psymbol_tag. */
5642 switch (indexval
.dwarf_tag
)
5644 case DW_TAG_variable
:
5645 case DW_TAG_subprogram
:
5646 /* Some types are also in VAR_DOMAIN. */
5647 case DW_TAG_typedef
:
5648 case DW_TAG_structure_type
:
5655 switch (indexval
.dwarf_tag
)
5657 case DW_TAG_typedef
:
5658 case DW_TAG_structure_type
:
5665 switch (indexval
.dwarf_tag
)
5668 case DW_TAG_variable
:
5675 switch (indexval
.dwarf_tag
)
5687 /* Match dw2_expand_symtabs_matching, symbol_kind and
5688 debug_names::psymbol_tag. */
5691 case VARIABLES_DOMAIN
:
5692 switch (indexval
.dwarf_tag
)
5694 case DW_TAG_variable
:
5700 case FUNCTIONS_DOMAIN
:
5701 switch (indexval
.dwarf_tag
)
5703 case DW_TAG_subprogram
:
5710 switch (indexval
.dwarf_tag
)
5712 case DW_TAG_typedef
:
5713 case DW_TAG_structure_type
:
5719 case MODULES_DOMAIN
:
5720 switch (indexval
.dwarf_tag
)
5734 static struct compunit_symtab
*
5735 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5736 const char *name
, domain_enum domain
)
5738 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5740 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5743 /* index is NULL if OBJF_READNOW. */
5746 const auto &map
= *mapp
;
5748 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5750 struct compunit_symtab
*stab_best
= NULL
;
5751 struct dwarf2_per_cu_data
*per_cu
;
5752 while ((per_cu
= iter
.next ()) != NULL
)
5754 struct symbol
*sym
, *with_opaque
= NULL
;
5755 compunit_symtab
*stab
5756 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5757 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5758 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5760 sym
= block_find_symbol (block
, name
, domain
,
5761 block_find_non_opaque_type_preferred
,
5764 /* Some caution must be observed with overloaded functions and
5765 methods, since the index will not contain any overload
5766 information (but NAME might contain it). */
5769 && strcmp_iw (sym
->search_name (), name
) == 0)
5771 if (with_opaque
!= NULL
5772 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5775 /* Keep looking through other CUs. */
5781 /* This dumps minimal information about .debug_names. It is called
5782 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5783 uses this to verify that .debug_names has been loaded. */
5786 dw2_debug_names_dump (struct objfile
*objfile
)
5788 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5790 gdb_assert (per_objfile
->per_bfd
->using_index
);
5791 printf_filtered (".debug_names:");
5792 if (per_objfile
->per_bfd
->debug_names_table
)
5793 printf_filtered (" exists\n");
5795 printf_filtered (" faked for \"readnow\"\n");
5796 printf_filtered ("\n");
5800 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5801 const char *func_name
)
5803 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5805 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5806 if (per_objfile
->per_bfd
->debug_names_table
)
5808 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5810 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5813 struct dwarf2_per_cu_data
*per_cu
;
5814 while ((per_cu
= iter
.next ()) != NULL
)
5815 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5820 dw2_debug_names_map_matching_symbols
5821 (struct objfile
*objfile
,
5822 const lookup_name_info
&name
, domain_enum domain
,
5824 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5825 symbol_compare_ftype
*ordered_compare
)
5827 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5829 /* debug_names_table is NULL if OBJF_READNOW. */
5830 if (!per_objfile
->per_bfd
->debug_names_table
)
5833 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5834 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5836 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5837 auto matcher
= [&] (const char *symname
)
5839 if (ordered_compare
== nullptr)
5841 return ordered_compare (symname
, match_name
) == 0;
5844 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5845 [&] (offset_type namei
)
5847 /* The name was matched, now expand corresponding CUs that were
5849 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5852 struct dwarf2_per_cu_data
*per_cu
;
5853 while ((per_cu
= iter
.next ()) != NULL
)
5854 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5859 /* It's a shame we couldn't do this inside the
5860 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5861 that have already been expanded. Instead, this loop matches what
5862 the psymtab code does. */
5863 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5865 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5866 if (symtab
!= nullptr)
5868 const struct block
*block
5869 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5870 if (!iterate_over_symbols_terminated (block
, name
,
5878 dw2_debug_names_expand_symtabs_matching
5879 (struct objfile
*objfile
,
5880 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5881 const lookup_name_info
*lookup_name
,
5882 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5883 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5884 enum search_domain kind
)
5886 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5888 /* debug_names_table is NULL if OBJF_READNOW. */
5889 if (!per_objfile
->per_bfd
->debug_names_table
)
5892 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5894 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5896 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5900 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5906 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5908 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5910 kind
, [&] (offset_type namei
)
5912 /* The name was matched, now expand corresponding CUs that were
5914 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5916 struct dwarf2_per_cu_data
*per_cu
;
5917 while ((per_cu
= iter
.next ()) != NULL
)
5918 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5924 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5927 dw2_find_last_source_symtab
,
5928 dw2_forget_cached_source_info
,
5929 dw2_map_symtabs_matching_filename
,
5930 dw2_debug_names_lookup_symbol
,
5933 dw2_debug_names_dump
,
5934 dw2_debug_names_expand_symtabs_for_function
,
5935 dw2_expand_all_symtabs
,
5936 dw2_expand_symtabs_with_fullname
,
5937 dw2_debug_names_map_matching_symbols
,
5938 dw2_debug_names_expand_symtabs_matching
,
5939 dw2_find_pc_sect_compunit_symtab
,
5941 dw2_map_symbol_filenames
5944 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5945 to either a dwarf2_per_bfd or dwz_file object. */
5947 template <typename T
>
5948 static gdb::array_view
<const gdb_byte
>
5949 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5951 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5953 if (section
->empty ())
5956 /* Older elfutils strip versions could keep the section in the main
5957 executable while splitting it for the separate debug info file. */
5958 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5961 section
->read (obj
);
5963 /* dwarf2_section_info::size is a bfd_size_type, while
5964 gdb::array_view works with size_t. On 32-bit hosts, with
5965 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5966 is 32-bit. So we need an explicit narrowing conversion here.
5967 This is fine, because it's impossible to allocate or mmap an
5968 array/buffer larger than what size_t can represent. */
5969 return gdb::make_array_view (section
->buffer
, section
->size
);
5972 /* Lookup the index cache for the contents of the index associated to
5975 static gdb::array_view
<const gdb_byte
>
5976 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5978 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5979 if (build_id
== nullptr)
5982 return global_index_cache
.lookup_gdb_index (build_id
,
5983 &dwarf2_per_bfd
->index_cache_res
);
5986 /* Same as the above, but for DWZ. */
5988 static gdb::array_view
<const gdb_byte
>
5989 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5991 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5992 if (build_id
== nullptr)
5995 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5998 /* See symfile.h. */
6001 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6003 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6004 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6006 /* If we're about to read full symbols, don't bother with the
6007 indices. In this case we also don't care if some other debug
6008 format is making psymtabs, because they are all about to be
6010 if ((objfile
->flags
& OBJF_READNOW
))
6012 /* When using READNOW, the using_index flag (set below) indicates that
6013 PER_BFD was already initialized, when we loaded some other objfile. */
6014 if (per_bfd
->using_index
)
6016 *index_kind
= dw_index_kind::GDB_INDEX
;
6017 per_objfile
->resize_symtabs ();
6021 per_bfd
->using_index
= 1;
6022 create_all_comp_units (per_objfile
);
6023 create_all_type_units (per_objfile
);
6024 per_bfd
->quick_file_names_table
6025 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
6026 per_objfile
->resize_symtabs ();
6028 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
6029 + per_bfd
->all_type_units
.size ()); ++i
)
6031 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
6033 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6034 struct dwarf2_per_cu_quick_data
);
6037 /* Return 1 so that gdb sees the "quick" functions. However,
6038 these functions will be no-ops because we will have expanded
6040 *index_kind
= dw_index_kind::GDB_INDEX
;
6044 /* Was a debug names index already read when we processed an objfile sharing
6046 if (per_bfd
->debug_names_table
!= nullptr)
6048 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6049 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6050 per_objfile
->resize_symtabs ();
6054 /* Was a GDB index already read when we processed an objfile sharing
6056 if (per_bfd
->index_table
!= nullptr)
6058 *index_kind
= dw_index_kind::GDB_INDEX
;
6059 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6060 per_objfile
->resize_symtabs ();
6064 /* There might already be partial symtabs built for this BFD. This happens
6065 when loading the same binary twice with the index-cache enabled. If so,
6066 don't try to read an index. The objfile / per_objfile initialization will
6067 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
6069 if (per_bfd
->partial_symtabs
!= nullptr)
6072 if (dwarf2_read_debug_names (per_objfile
))
6074 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6075 per_objfile
->resize_symtabs ();
6079 if (dwarf2_read_gdb_index (per_objfile
,
6080 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6081 get_gdb_index_contents_from_section
<dwz_file
>))
6083 *index_kind
= dw_index_kind::GDB_INDEX
;
6084 per_objfile
->resize_symtabs ();
6088 /* ... otherwise, try to find the index in the index cache. */
6089 if (dwarf2_read_gdb_index (per_objfile
,
6090 get_gdb_index_contents_from_cache
,
6091 get_gdb_index_contents_from_cache_dwz
))
6093 global_index_cache
.hit ();
6094 *index_kind
= dw_index_kind::GDB_INDEX
;
6095 per_objfile
->resize_symtabs ();
6099 global_index_cache
.miss ();
6105 /* Build a partial symbol table. */
6108 dwarf2_build_psymtabs (struct objfile
*objfile
)
6110 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6111 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6113 if (per_bfd
->partial_symtabs
!= nullptr)
6115 /* Partial symbols were already read, so now we can simply
6117 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6118 per_objfile
->resize_symtabs ();
6122 init_psymbol_list (objfile
, 1024);
6126 /* This isn't really ideal: all the data we allocate on the
6127 objfile's obstack is still uselessly kept around. However,
6128 freeing it seems unsafe. */
6129 psymtab_discarder
psymtabs (objfile
);
6130 dwarf2_build_psymtabs_hard (per_objfile
);
6133 per_objfile
->resize_symtabs ();
6135 /* (maybe) store an index in the cache. */
6136 global_index_cache
.store (per_objfile
);
6138 catch (const gdb_exception_error
&except
)
6140 exception_print (gdb_stderr
, except
);
6143 /* Finish by setting the local reference to partial symtabs, so that
6144 we don't try to read them again if reading another objfile with the same
6145 BFD. If we can't in fact share, this won't make a difference anyway as
6146 the dwarf2_per_bfd object won't be shared. */
6147 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6150 /* Find the base address of the compilation unit for range lists and
6151 location lists. It will normally be specified by DW_AT_low_pc.
6152 In DWARF-3 draft 4, the base address could be overridden by
6153 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6154 compilation units with discontinuous ranges. */
6157 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6159 struct attribute
*attr
;
6161 cu
->base_address
.reset ();
6163 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6164 if (attr
!= nullptr)
6165 cu
->base_address
= attr
->as_address ();
6168 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6169 if (attr
!= nullptr)
6170 cu
->base_address
= attr
->as_address ();
6174 /* Helper function that returns the proper abbrev section for
6177 static struct dwarf2_section_info
*
6178 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6180 struct dwarf2_section_info
*abbrev
;
6181 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6183 if (this_cu
->is_dwz
)
6184 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6186 abbrev
= &per_bfd
->abbrev
;
6191 /* Fetch the abbreviation table offset from a comp or type unit header. */
6194 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6195 struct dwarf2_section_info
*section
,
6196 sect_offset sect_off
)
6198 bfd
*abfd
= section
->get_bfd_owner ();
6199 const gdb_byte
*info_ptr
;
6200 unsigned int initial_length_size
, offset_size
;
6203 section
->read (per_objfile
->objfile
);
6204 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6205 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6206 offset_size
= initial_length_size
== 4 ? 4 : 8;
6207 info_ptr
+= initial_length_size
;
6209 version
= read_2_bytes (abfd
, info_ptr
);
6213 /* Skip unit type and address size. */
6217 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6220 /* A partial symtab that is used only for include files. */
6221 struct dwarf2_include_psymtab
: public partial_symtab
6223 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6224 : partial_symtab (filename
, objfile
)
6228 void read_symtab (struct objfile
*objfile
) override
6230 /* It's an include file, no symbols to read for it.
6231 Everything is in the includer symtab. */
6233 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6234 expansion of the includer psymtab. We use the dependencies[0] field to
6235 model the includer. But if we go the regular route of calling
6236 expand_psymtab here, and having expand_psymtab call expand_dependencies
6237 to expand the includer, we'll only use expand_psymtab on the includer
6238 (making it a non-toplevel psymtab), while if we expand the includer via
6239 another path, we'll use read_symtab (making it a toplevel psymtab).
6240 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6241 psymtab, and trigger read_symtab on the includer here directly. */
6242 includer ()->read_symtab (objfile
);
6245 void expand_psymtab (struct objfile
*objfile
) override
6247 /* This is not called by read_symtab, and should not be called by any
6248 expand_dependencies. */
6252 bool readin_p (struct objfile
*objfile
) const override
6254 return includer ()->readin_p (objfile
);
6257 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6263 partial_symtab
*includer () const
6265 /* An include psymtab has exactly one dependency: the psymtab that
6267 gdb_assert (this->number_of_dependencies
== 1);
6268 return this->dependencies
[0];
6272 /* Allocate a new partial symtab for file named NAME and mark this new
6273 partial symtab as being an include of PST. */
6276 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6277 struct objfile
*objfile
)
6279 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6281 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6282 subpst
->dirname
= pst
->dirname
;
6284 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6285 subpst
->dependencies
[0] = pst
;
6286 subpst
->number_of_dependencies
= 1;
6289 /* Read the Line Number Program data and extract the list of files
6290 included by the source file represented by PST. Build an include
6291 partial symtab for each of these included files. */
6294 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6295 struct die_info
*die
,
6296 dwarf2_psymtab
*pst
)
6299 struct attribute
*attr
;
6301 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6302 if (attr
!= nullptr && attr
->form_is_unsigned ())
6303 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
6305 return; /* No linetable, so no includes. */
6307 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6308 that we pass in the raw text_low here; that is ok because we're
6309 only decoding the line table to make include partial symtabs, and
6310 so the addresses aren't really used. */
6311 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6312 pst
->raw_text_low (), 1);
6316 hash_signatured_type (const void *item
)
6318 const struct signatured_type
*sig_type
6319 = (const struct signatured_type
*) item
;
6321 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6322 return sig_type
->signature
;
6326 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6328 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6329 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6331 return lhs
->signature
== rhs
->signature
;
6334 /* Allocate a hash table for signatured types. */
6337 allocate_signatured_type_table ()
6339 return htab_up (htab_create_alloc (41,
6340 hash_signatured_type
,
6342 NULL
, xcalloc
, xfree
));
6345 /* A helper function to add a signatured type CU to a table. */
6348 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6350 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6351 std::vector
<signatured_type
*> *all_type_units
6352 = (std::vector
<signatured_type
*> *) datum
;
6354 all_type_units
->push_back (sigt
);
6359 /* A helper for create_debug_types_hash_table. Read types from SECTION
6360 and fill them into TYPES_HTAB. It will process only type units,
6361 therefore DW_UT_type. */
6364 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6365 struct dwo_file
*dwo_file
,
6366 dwarf2_section_info
*section
, htab_up
&types_htab
,
6367 rcuh_kind section_kind
)
6369 struct objfile
*objfile
= per_objfile
->objfile
;
6370 struct dwarf2_section_info
*abbrev_section
;
6372 const gdb_byte
*info_ptr
, *end_ptr
;
6374 abbrev_section
= (dwo_file
!= NULL
6375 ? &dwo_file
->sections
.abbrev
6376 : &per_objfile
->per_bfd
->abbrev
);
6378 if (dwarf_read_debug
)
6379 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6380 section
->get_name (),
6381 abbrev_section
->get_file_name ());
6383 section
->read (objfile
);
6384 info_ptr
= section
->buffer
;
6386 if (info_ptr
== NULL
)
6389 /* We can't set abfd until now because the section may be empty or
6390 not present, in which case the bfd is unknown. */
6391 abfd
= section
->get_bfd_owner ();
6393 /* We don't use cutu_reader here because we don't need to read
6394 any dies: the signature is in the header. */
6396 end_ptr
= info_ptr
+ section
->size
;
6397 while (info_ptr
< end_ptr
)
6399 struct signatured_type
*sig_type
;
6400 struct dwo_unit
*dwo_tu
;
6402 const gdb_byte
*ptr
= info_ptr
;
6403 struct comp_unit_head header
;
6404 unsigned int length
;
6406 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6408 /* Initialize it due to a false compiler warning. */
6409 header
.signature
= -1;
6410 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6412 /* We need to read the type's signature in order to build the hash
6413 table, but we don't need anything else just yet. */
6415 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6416 abbrev_section
, ptr
, section_kind
);
6418 length
= header
.get_length ();
6420 /* Skip dummy type units. */
6421 if (ptr
>= info_ptr
+ length
6422 || peek_abbrev_code (abfd
, ptr
) == 0
6423 || (header
.unit_type
!= DW_UT_type
6424 && header
.unit_type
!= DW_UT_split_type
))
6430 if (types_htab
== NULL
)
6433 types_htab
= allocate_dwo_unit_table ();
6435 types_htab
= allocate_signatured_type_table ();
6441 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6442 dwo_tu
->dwo_file
= dwo_file
;
6443 dwo_tu
->signature
= header
.signature
;
6444 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6445 dwo_tu
->section
= section
;
6446 dwo_tu
->sect_off
= sect_off
;
6447 dwo_tu
->length
= length
;
6451 /* N.B.: type_offset is not usable if this type uses a DWO file.
6452 The real type_offset is in the DWO file. */
6454 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6455 sig_type
->signature
= header
.signature
;
6456 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6457 sig_type
->per_cu
.is_debug_types
= 1;
6458 sig_type
->per_cu
.section
= section
;
6459 sig_type
->per_cu
.sect_off
= sect_off
;
6460 sig_type
->per_cu
.length
= length
;
6463 slot
= htab_find_slot (types_htab
.get (),
6464 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6466 gdb_assert (slot
!= NULL
);
6469 sect_offset dup_sect_off
;
6473 const struct dwo_unit
*dup_tu
6474 = (const struct dwo_unit
*) *slot
;
6476 dup_sect_off
= dup_tu
->sect_off
;
6480 const struct signatured_type
*dup_tu
6481 = (const struct signatured_type
*) *slot
;
6483 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6486 complaint (_("debug type entry at offset %s is duplicate to"
6487 " the entry at offset %s, signature %s"),
6488 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6489 hex_string (header
.signature
));
6491 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6493 if (dwarf_read_debug
> 1)
6494 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6495 sect_offset_str (sect_off
),
6496 hex_string (header
.signature
));
6502 /* Create the hash table of all entries in the .debug_types
6503 (or .debug_types.dwo) section(s).
6504 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6505 otherwise it is NULL.
6507 The result is a pointer to the hash table or NULL if there are no types.
6509 Note: This function processes DWO files only, not DWP files. */
6512 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6513 struct dwo_file
*dwo_file
,
6514 gdb::array_view
<dwarf2_section_info
> type_sections
,
6515 htab_up
&types_htab
)
6517 for (dwarf2_section_info
§ion
: type_sections
)
6518 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6522 /* Create the hash table of all entries in the .debug_types section,
6523 and initialize all_type_units.
6524 The result is zero if there is an error (e.g. missing .debug_types section),
6525 otherwise non-zero. */
6528 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6532 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6533 types_htab
, rcuh_kind::COMPILE
);
6534 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6536 if (types_htab
== NULL
)
6538 per_objfile
->per_bfd
->signatured_types
= NULL
;
6542 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6544 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6545 per_objfile
->per_bfd
->all_type_units
.reserve
6546 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6548 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6549 add_signatured_type_cu_to_table
,
6550 &per_objfile
->per_bfd
->all_type_units
);
6555 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6556 If SLOT is non-NULL, it is the entry to use in the hash table.
6557 Otherwise we find one. */
6559 static struct signatured_type
*
6560 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6562 if (per_objfile
->per_bfd
->all_type_units
.size ()
6563 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6564 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6566 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6568 per_objfile
->resize_symtabs ();
6570 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6571 sig_type
->signature
= sig
;
6572 sig_type
->per_cu
.is_debug_types
= 1;
6573 if (per_objfile
->per_bfd
->using_index
)
6575 sig_type
->per_cu
.v
.quick
=
6576 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6577 struct dwarf2_per_cu_quick_data
);
6582 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6585 gdb_assert (*slot
== NULL
);
6587 /* The rest of sig_type must be filled in by the caller. */
6591 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6592 Fill in SIG_ENTRY with DWO_ENTRY. */
6595 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6596 struct signatured_type
*sig_entry
,
6597 struct dwo_unit
*dwo_entry
)
6599 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6601 /* Make sure we're not clobbering something we don't expect to. */
6602 gdb_assert (! sig_entry
->per_cu
.queued
);
6603 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6604 if (per_bfd
->using_index
)
6606 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6607 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6610 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6611 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6612 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6613 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6614 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6616 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6617 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6618 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6619 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6620 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6621 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6622 sig_entry
->dwo_unit
= dwo_entry
;
6625 /* Subroutine of lookup_signatured_type.
6626 If we haven't read the TU yet, create the signatured_type data structure
6627 for a TU to be read in directly from a DWO file, bypassing the stub.
6628 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6629 using .gdb_index, then when reading a CU we want to stay in the DWO file
6630 containing that CU. Otherwise we could end up reading several other DWO
6631 files (due to comdat folding) to process the transitive closure of all the
6632 mentioned TUs, and that can be slow. The current DWO file will have every
6633 type signature that it needs.
6634 We only do this for .gdb_index because in the psymtab case we already have
6635 to read all the DWOs to build the type unit groups. */
6637 static struct signatured_type
*
6638 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6640 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6641 struct dwo_file
*dwo_file
;
6642 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6643 struct signatured_type find_sig_entry
, *sig_entry
;
6646 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6648 /* If TU skeletons have been removed then we may not have read in any
6650 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6651 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6653 /* We only ever need to read in one copy of a signatured type.
6654 Use the global signatured_types array to do our own comdat-folding
6655 of types. If this is the first time we're reading this TU, and
6656 the TU has an entry in .gdb_index, replace the recorded data from
6657 .gdb_index with this TU. */
6659 find_sig_entry
.signature
= sig
;
6660 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6661 &find_sig_entry
, INSERT
);
6662 sig_entry
= (struct signatured_type
*) *slot
;
6664 /* We can get here with the TU already read, *or* in the process of being
6665 read. Don't reassign the global entry to point to this DWO if that's
6666 the case. Also note that if the TU is already being read, it may not
6667 have come from a DWO, the program may be a mix of Fission-compiled
6668 code and non-Fission-compiled code. */
6670 /* Have we already tried to read this TU?
6671 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6672 needn't exist in the global table yet). */
6673 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6676 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6677 dwo_unit of the TU itself. */
6678 dwo_file
= cu
->dwo_unit
->dwo_file
;
6680 /* Ok, this is the first time we're reading this TU. */
6681 if (dwo_file
->tus
== NULL
)
6683 find_dwo_entry
.signature
= sig
;
6684 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6686 if (dwo_entry
== NULL
)
6689 /* If the global table doesn't have an entry for this TU, add one. */
6690 if (sig_entry
== NULL
)
6691 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6693 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6694 sig_entry
->per_cu
.tu_read
= 1;
6698 /* Subroutine of lookup_signatured_type.
6699 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6700 then try the DWP file. If the TU stub (skeleton) has been removed then
6701 it won't be in .gdb_index. */
6703 static struct signatured_type
*
6704 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6706 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6707 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6708 struct dwo_unit
*dwo_entry
;
6709 struct signatured_type find_sig_entry
, *sig_entry
;
6712 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6713 gdb_assert (dwp_file
!= NULL
);
6715 /* If TU skeletons have been removed then we may not have read in any
6717 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6718 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6720 find_sig_entry
.signature
= sig
;
6721 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6722 &find_sig_entry
, INSERT
);
6723 sig_entry
= (struct signatured_type
*) *slot
;
6725 /* Have we already tried to read this TU?
6726 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6727 needn't exist in the global table yet). */
6728 if (sig_entry
!= NULL
)
6731 if (dwp_file
->tus
== NULL
)
6733 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6734 1 /* is_debug_types */);
6735 if (dwo_entry
== NULL
)
6738 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6739 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6744 /* Lookup a signature based type for DW_FORM_ref_sig8.
6745 Returns NULL if signature SIG is not present in the table.
6746 It is up to the caller to complain about this. */
6748 static struct signatured_type
*
6749 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6751 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6753 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6755 /* We're in a DWO/DWP file, and we're using .gdb_index.
6756 These cases require special processing. */
6757 if (get_dwp_file (per_objfile
) == NULL
)
6758 return lookup_dwo_signatured_type (cu
, sig
);
6760 return lookup_dwp_signatured_type (cu
, sig
);
6764 struct signatured_type find_entry
, *entry
;
6766 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6768 find_entry
.signature
= sig
;
6769 entry
= ((struct signatured_type
*)
6770 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6776 /* Low level DIE reading support. */
6778 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6781 init_cu_die_reader (struct die_reader_specs
*reader
,
6782 struct dwarf2_cu
*cu
,
6783 struct dwarf2_section_info
*section
,
6784 struct dwo_file
*dwo_file
,
6785 struct abbrev_table
*abbrev_table
)
6787 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6788 reader
->abfd
= section
->get_bfd_owner ();
6790 reader
->dwo_file
= dwo_file
;
6791 reader
->die_section
= section
;
6792 reader
->buffer
= section
->buffer
;
6793 reader
->buffer_end
= section
->buffer
+ section
->size
;
6794 reader
->abbrev_table
= abbrev_table
;
6797 /* Subroutine of cutu_reader to simplify it.
6798 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6799 There's just a lot of work to do, and cutu_reader is big enough
6802 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6803 from it to the DIE in the DWO. If NULL we are skipping the stub.
6804 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6805 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6806 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6807 STUB_COMP_DIR may be non-NULL.
6808 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6809 are filled in with the info of the DIE from the DWO file.
6810 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6811 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6812 kept around for at least as long as *RESULT_READER.
6814 The result is non-zero if a valid (non-dummy) DIE was found. */
6817 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6818 struct dwo_unit
*dwo_unit
,
6819 struct die_info
*stub_comp_unit_die
,
6820 const char *stub_comp_dir
,
6821 struct die_reader_specs
*result_reader
,
6822 const gdb_byte
**result_info_ptr
,
6823 struct die_info
**result_comp_unit_die
,
6824 abbrev_table_up
*result_dwo_abbrev_table
)
6826 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6827 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6828 struct objfile
*objfile
= per_objfile
->objfile
;
6830 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6831 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6832 int i
,num_extra_attrs
;
6833 struct dwarf2_section_info
*dwo_abbrev_section
;
6834 struct die_info
*comp_unit_die
;
6836 /* At most one of these may be provided. */
6837 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6839 /* These attributes aren't processed until later:
6840 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6841 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6842 referenced later. However, these attributes are found in the stub
6843 which we won't have later. In order to not impose this complication
6844 on the rest of the code, we read them here and copy them to the
6853 if (stub_comp_unit_die
!= NULL
)
6855 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6857 if (!per_cu
->is_debug_types
)
6858 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6859 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6860 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6861 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6862 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6864 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6866 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6867 here (if needed). We need the value before we can process
6869 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6871 else if (stub_comp_dir
!= NULL
)
6873 /* Reconstruct the comp_dir attribute to simplify the code below. */
6874 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6875 comp_dir
->name
= DW_AT_comp_dir
;
6876 comp_dir
->form
= DW_FORM_string
;
6877 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6880 /* Set up for reading the DWO CU/TU. */
6881 cu
->dwo_unit
= dwo_unit
;
6882 dwarf2_section_info
*section
= dwo_unit
->section
;
6883 section
->read (objfile
);
6884 abfd
= section
->get_bfd_owner ();
6885 begin_info_ptr
= info_ptr
= (section
->buffer
6886 + to_underlying (dwo_unit
->sect_off
));
6887 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6889 if (per_cu
->is_debug_types
)
6891 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6893 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6894 section
, dwo_abbrev_section
,
6895 info_ptr
, rcuh_kind::TYPE
);
6896 /* This is not an assert because it can be caused by bad debug info. */
6897 if (sig_type
->signature
!= cu
->header
.signature
)
6899 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6900 " TU at offset %s [in module %s]"),
6901 hex_string (sig_type
->signature
),
6902 hex_string (cu
->header
.signature
),
6903 sect_offset_str (dwo_unit
->sect_off
),
6904 bfd_get_filename (abfd
));
6906 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6907 /* For DWOs coming from DWP files, we don't know the CU length
6908 nor the type's offset in the TU until now. */
6909 dwo_unit
->length
= cu
->header
.get_length ();
6910 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6912 /* Establish the type offset that can be used to lookup the type.
6913 For DWO files, we don't know it until now. */
6914 sig_type
->type_offset_in_section
6915 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6919 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6920 section
, dwo_abbrev_section
,
6921 info_ptr
, rcuh_kind::COMPILE
);
6922 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6923 /* For DWOs coming from DWP files, we don't know the CU length
6925 dwo_unit
->length
= cu
->header
.get_length ();
6928 *result_dwo_abbrev_table
6929 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6930 cu
->header
.abbrev_sect_off
);
6931 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6932 result_dwo_abbrev_table
->get ());
6934 /* Read in the die, but leave space to copy over the attributes
6935 from the stub. This has the benefit of simplifying the rest of
6936 the code - all the work to maintain the illusion of a single
6937 DW_TAG_{compile,type}_unit DIE is done here. */
6938 num_extra_attrs
= ((stmt_list
!= NULL
)
6942 + (comp_dir
!= NULL
));
6943 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6946 /* Copy over the attributes from the stub to the DIE we just read in. */
6947 comp_unit_die
= *result_comp_unit_die
;
6948 i
= comp_unit_die
->num_attrs
;
6949 if (stmt_list
!= NULL
)
6950 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6952 comp_unit_die
->attrs
[i
++] = *low_pc
;
6953 if (high_pc
!= NULL
)
6954 comp_unit_die
->attrs
[i
++] = *high_pc
;
6956 comp_unit_die
->attrs
[i
++] = *ranges
;
6957 if (comp_dir
!= NULL
)
6958 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6959 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6961 if (dwarf_die_debug
)
6963 fprintf_unfiltered (gdb_stdlog
,
6964 "Read die from %s@0x%x of %s:\n",
6965 section
->get_name (),
6966 (unsigned) (begin_info_ptr
- section
->buffer
),
6967 bfd_get_filename (abfd
));
6968 dump_die (comp_unit_die
, dwarf_die_debug
);
6971 /* Skip dummy compilation units. */
6972 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6973 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6976 *result_info_ptr
= info_ptr
;
6980 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6981 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6982 signature is part of the header. */
6983 static gdb::optional
<ULONGEST
>
6984 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6986 if (cu
->header
.version
>= 5)
6987 return cu
->header
.signature
;
6988 struct attribute
*attr
;
6989 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6990 if (attr
== nullptr || !attr
->form_is_unsigned ())
6991 return gdb::optional
<ULONGEST
> ();
6992 return attr
->as_unsigned ();
6995 /* Subroutine of cutu_reader to simplify it.
6996 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6997 Returns NULL if the specified DWO unit cannot be found. */
6999 static struct dwo_unit
*
7000 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
7002 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7003 struct dwo_unit
*dwo_unit
;
7004 const char *comp_dir
;
7006 gdb_assert (cu
!= NULL
);
7008 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7009 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7010 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7012 if (per_cu
->is_debug_types
)
7013 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
7016 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7018 if (!signature
.has_value ())
7019 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7021 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
7023 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
7029 /* Subroutine of cutu_reader to simplify it.
7030 See it for a description of the parameters.
7031 Read a TU directly from a DWO file, bypassing the stub. */
7034 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
7035 dwarf2_per_objfile
*per_objfile
,
7036 dwarf2_cu
*existing_cu
)
7038 struct signatured_type
*sig_type
;
7040 /* Verify we can do the following downcast, and that we have the
7042 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7043 sig_type
= (struct signatured_type
*) this_cu
;
7044 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7048 if (existing_cu
!= nullptr)
7051 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7052 /* There's no need to do the rereading_dwo_cu handling that
7053 cutu_reader does since we don't read the stub. */
7057 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7058 in per_objfile yet. */
7059 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7060 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7061 cu
= m_new_cu
.get ();
7064 /* A future optimization, if needed, would be to use an existing
7065 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7066 could share abbrev tables. */
7068 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7069 NULL
/* stub_comp_unit_die */,
7070 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7073 &m_dwo_abbrev_table
) == 0)
7080 /* Initialize a CU (or TU) and read its DIEs.
7081 If the CU defers to a DWO file, read the DWO file as well.
7083 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7084 Otherwise the table specified in the comp unit header is read in and used.
7085 This is an optimization for when we already have the abbrev table.
7087 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7090 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7091 dwarf2_per_objfile
*per_objfile
,
7092 struct abbrev_table
*abbrev_table
,
7093 dwarf2_cu
*existing_cu
,
7095 : die_reader_specs
{},
7098 struct objfile
*objfile
= per_objfile
->objfile
;
7099 struct dwarf2_section_info
*section
= this_cu
->section
;
7100 bfd
*abfd
= section
->get_bfd_owner ();
7101 const gdb_byte
*begin_info_ptr
;
7102 struct signatured_type
*sig_type
= NULL
;
7103 struct dwarf2_section_info
*abbrev_section
;
7104 /* Non-zero if CU currently points to a DWO file and we need to
7105 reread it. When this happens we need to reread the skeleton die
7106 before we can reread the DWO file (this only applies to CUs, not TUs). */
7107 int rereading_dwo_cu
= 0;
7109 if (dwarf_die_debug
)
7110 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7111 this_cu
->is_debug_types
? "type" : "comp",
7112 sect_offset_str (this_cu
->sect_off
));
7114 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7115 file (instead of going through the stub), short-circuit all of this. */
7116 if (this_cu
->reading_dwo_directly
)
7118 /* Narrow down the scope of possibilities to have to understand. */
7119 gdb_assert (this_cu
->is_debug_types
);
7120 gdb_assert (abbrev_table
== NULL
);
7121 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7125 /* This is cheap if the section is already read in. */
7126 section
->read (objfile
);
7128 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7130 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7134 if (existing_cu
!= nullptr)
7137 /* If this CU is from a DWO file we need to start over, we need to
7138 refetch the attributes from the skeleton CU.
7139 This could be optimized by retrieving those attributes from when we
7140 were here the first time: the previous comp_unit_die was stored in
7141 comp_unit_obstack. But there's no data yet that we need this
7143 if (cu
->dwo_unit
!= NULL
)
7144 rereading_dwo_cu
= 1;
7148 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7149 in per_objfile yet. */
7150 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7151 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7152 cu
= m_new_cu
.get ();
7155 /* Get the header. */
7156 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7158 /* We already have the header, there's no need to read it in again. */
7159 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7163 if (this_cu
->is_debug_types
)
7165 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7166 section
, abbrev_section
,
7167 info_ptr
, rcuh_kind::TYPE
);
7169 /* Since per_cu is the first member of struct signatured_type,
7170 we can go from a pointer to one to a pointer to the other. */
7171 sig_type
= (struct signatured_type
*) this_cu
;
7172 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7173 gdb_assert (sig_type
->type_offset_in_tu
7174 == cu
->header
.type_cu_offset_in_tu
);
7175 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7177 /* LENGTH has not been set yet for type units if we're
7178 using .gdb_index. */
7179 this_cu
->length
= cu
->header
.get_length ();
7181 /* Establish the type offset that can be used to lookup the type. */
7182 sig_type
->type_offset_in_section
=
7183 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7185 this_cu
->dwarf_version
= cu
->header
.version
;
7189 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7190 section
, abbrev_section
,
7192 rcuh_kind::COMPILE
);
7194 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7195 if (this_cu
->length
== 0)
7196 this_cu
->length
= cu
->header
.get_length ();
7198 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7199 this_cu
->dwarf_version
= cu
->header
.version
;
7203 /* Skip dummy compilation units. */
7204 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7205 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7211 /* If we don't have them yet, read the abbrevs for this compilation unit.
7212 And if we need to read them now, make sure they're freed when we're
7214 if (abbrev_table
!= NULL
)
7215 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7218 m_abbrev_table_holder
7219 = abbrev_table::read (objfile
, abbrev_section
,
7220 cu
->header
.abbrev_sect_off
);
7221 abbrev_table
= m_abbrev_table_holder
.get ();
7224 /* Read the top level CU/TU die. */
7225 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7226 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7228 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7234 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7235 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7236 table from the DWO file and pass the ownership over to us. It will be
7237 referenced from READER, so we must make sure to free it after we're done
7240 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7241 DWO CU, that this test will fail (the attribute will not be present). */
7242 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7243 if (dwo_name
!= nullptr)
7245 struct dwo_unit
*dwo_unit
;
7246 struct die_info
*dwo_comp_unit_die
;
7248 if (comp_unit_die
->has_children
)
7250 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7251 " has children (offset %s) [in module %s]"),
7252 sect_offset_str (this_cu
->sect_off
),
7253 bfd_get_filename (abfd
));
7255 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7256 if (dwo_unit
!= NULL
)
7258 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7259 comp_unit_die
, NULL
,
7262 &m_dwo_abbrev_table
) == 0)
7268 comp_unit_die
= dwo_comp_unit_die
;
7272 /* Yikes, we couldn't find the rest of the DIE, we only have
7273 the stub. A complaint has already been logged. There's
7274 not much more we can do except pass on the stub DIE to
7275 die_reader_func. We don't want to throw an error on bad
7282 cutu_reader::keep ()
7284 /* Done, clean up. */
7285 gdb_assert (!dummy_p
);
7286 if (m_new_cu
!= NULL
)
7288 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7290 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7291 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7295 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7296 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7297 assumed to have already done the lookup to find the DWO file).
7299 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7300 THIS_CU->is_debug_types, but nothing else.
7302 We fill in THIS_CU->length.
7304 THIS_CU->cu is always freed when done.
7305 This is done in order to not leave THIS_CU->cu in a state where we have
7306 to care whether it refers to the "main" CU or the DWO CU.
7308 When parent_cu is passed, it is used to provide a default value for
7309 str_offsets_base and addr_base from the parent. */
7311 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7312 dwarf2_per_objfile
*per_objfile
,
7313 struct dwarf2_cu
*parent_cu
,
7314 struct dwo_file
*dwo_file
)
7315 : die_reader_specs
{},
7318 struct objfile
*objfile
= per_objfile
->objfile
;
7319 struct dwarf2_section_info
*section
= this_cu
->section
;
7320 bfd
*abfd
= section
->get_bfd_owner ();
7321 struct dwarf2_section_info
*abbrev_section
;
7322 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7324 if (dwarf_die_debug
)
7325 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7326 this_cu
->is_debug_types
? "type" : "comp",
7327 sect_offset_str (this_cu
->sect_off
));
7329 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7331 abbrev_section
= (dwo_file
!= NULL
7332 ? &dwo_file
->sections
.abbrev
7333 : get_abbrev_section_for_cu (this_cu
));
7335 /* This is cheap if the section is already read in. */
7336 section
->read (objfile
);
7338 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7340 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7341 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7342 section
, abbrev_section
, info_ptr
,
7343 (this_cu
->is_debug_types
7345 : rcuh_kind::COMPILE
));
7347 if (parent_cu
!= nullptr)
7349 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7350 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7352 this_cu
->length
= m_new_cu
->header
.get_length ();
7354 /* Skip dummy compilation units. */
7355 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7356 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7362 m_abbrev_table_holder
7363 = abbrev_table::read (objfile
, abbrev_section
,
7364 m_new_cu
->header
.abbrev_sect_off
);
7366 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7367 m_abbrev_table_holder
.get ());
7368 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7372 /* Type Unit Groups.
7374 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7375 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7376 so that all types coming from the same compilation (.o file) are grouped
7377 together. A future step could be to put the types in the same symtab as
7378 the CU the types ultimately came from. */
7381 hash_type_unit_group (const void *item
)
7383 const struct type_unit_group
*tu_group
7384 = (const struct type_unit_group
*) item
;
7386 return hash_stmt_list_entry (&tu_group
->hash
);
7390 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7392 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7393 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7395 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7398 /* Allocate a hash table for type unit groups. */
7401 allocate_type_unit_groups_table ()
7403 return htab_up (htab_create_alloc (3,
7404 hash_type_unit_group
,
7406 NULL
, xcalloc
, xfree
));
7409 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7410 partial symtabs. We combine several TUs per psymtab to not let the size
7411 of any one psymtab grow too big. */
7412 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7413 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7415 /* Helper routine for get_type_unit_group.
7416 Create the type_unit_group object used to hold one or more TUs. */
7418 static struct type_unit_group
*
7419 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7421 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7422 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7423 struct dwarf2_per_cu_data
*per_cu
;
7424 struct type_unit_group
*tu_group
;
7426 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7427 per_cu
= &tu_group
->per_cu
;
7428 per_cu
->per_bfd
= per_bfd
;
7430 if (per_bfd
->using_index
)
7432 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7433 struct dwarf2_per_cu_quick_data
);
7437 unsigned int line_offset
= to_underlying (line_offset_struct
);
7438 dwarf2_psymtab
*pst
;
7441 /* Give the symtab a useful name for debug purposes. */
7442 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7443 name
= string_printf ("<type_units_%d>",
7444 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7446 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7448 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7449 pst
->anonymous
= true;
7452 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7453 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7458 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7459 STMT_LIST is a DW_AT_stmt_list attribute. */
7461 static struct type_unit_group
*
7462 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7464 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7465 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7466 struct type_unit_group
*tu_group
;
7468 unsigned int line_offset
;
7469 struct type_unit_group type_unit_group_for_lookup
;
7471 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7472 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7474 /* Do we need to create a new group, or can we use an existing one? */
7476 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7478 line_offset
= stmt_list
->as_unsigned ();
7479 ++tu_stats
->nr_symtab_sharers
;
7483 /* Ugh, no stmt_list. Rare, but we have to handle it.
7484 We can do various things here like create one group per TU or
7485 spread them over multiple groups to split up the expansion work.
7486 To avoid worst case scenarios (too many groups or too large groups)
7487 we, umm, group them in bunches. */
7488 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7489 | (tu_stats
->nr_stmt_less_type_units
7490 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7491 ++tu_stats
->nr_stmt_less_type_units
;
7494 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7495 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7496 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7497 &type_unit_group_for_lookup
, INSERT
);
7500 tu_group
= (struct type_unit_group
*) *slot
;
7501 gdb_assert (tu_group
!= NULL
);
7505 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7506 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7508 ++tu_stats
->nr_symtabs
;
7514 /* Partial symbol tables. */
7516 /* Create a psymtab named NAME and assign it to PER_CU.
7518 The caller must fill in the following details:
7519 dirname, textlow, texthigh. */
7521 static dwarf2_psymtab
*
7522 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7523 dwarf2_per_objfile
*per_objfile
,
7526 struct objfile
*objfile
= per_objfile
->objfile
;
7527 dwarf2_psymtab
*pst
;
7529 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7531 pst
->psymtabs_addrmap_supported
= true;
7533 /* This is the glue that links PST into GDB's symbol API. */
7534 per_cu
->v
.psymtab
= pst
;
7539 /* DIE reader function for process_psymtab_comp_unit. */
7542 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7543 const gdb_byte
*info_ptr
,
7544 struct die_info
*comp_unit_die
,
7545 enum language pretend_language
)
7547 struct dwarf2_cu
*cu
= reader
->cu
;
7548 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7549 struct objfile
*objfile
= per_objfile
->objfile
;
7550 struct gdbarch
*gdbarch
= objfile
->arch ();
7551 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7553 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7554 dwarf2_psymtab
*pst
;
7555 enum pc_bounds_kind cu_bounds_kind
;
7556 const char *filename
;
7558 gdb_assert (! per_cu
->is_debug_types
);
7560 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7562 /* Allocate a new partial symbol table structure. */
7563 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7564 static const char artificial
[] = "<artificial>";
7565 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7566 if (filename
== NULL
)
7568 else if (strcmp (filename
, artificial
) == 0)
7570 debug_filename
.reset (concat (artificial
, "@",
7571 sect_offset_str (per_cu
->sect_off
),
7573 filename
= debug_filename
.get ();
7576 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7578 /* This must be done before calling dwarf2_build_include_psymtabs. */
7579 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7581 baseaddr
= objfile
->text_section_offset ();
7583 dwarf2_find_base_address (comp_unit_die
, cu
);
7585 /* Possibly set the default values of LOWPC and HIGHPC from
7587 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7588 &best_highpc
, cu
, pst
);
7589 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7592 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7595 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7597 /* Store the contiguous range if it is not empty; it can be
7598 empty for CUs with no code. */
7599 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7603 /* Check if comp unit has_children.
7604 If so, read the rest of the partial symbols from this comp unit.
7605 If not, there's no more debug_info for this comp unit. */
7606 if (comp_unit_die
->has_children
)
7608 struct partial_die_info
*first_die
;
7609 CORE_ADDR lowpc
, highpc
;
7611 lowpc
= ((CORE_ADDR
) -1);
7612 highpc
= ((CORE_ADDR
) 0);
7614 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7616 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7617 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7619 /* If we didn't find a lowpc, set it to highpc to avoid
7620 complaints from `maint check'. */
7621 if (lowpc
== ((CORE_ADDR
) -1))
7624 /* If the compilation unit didn't have an explicit address range,
7625 then use the information extracted from its child dies. */
7626 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7629 best_highpc
= highpc
;
7632 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7633 best_lowpc
+ baseaddr
)
7635 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7636 best_highpc
+ baseaddr
)
7639 end_psymtab_common (objfile
, pst
);
7641 if (!cu
->per_cu
->imported_symtabs_empty ())
7644 int len
= cu
->per_cu
->imported_symtabs_size ();
7646 /* Fill in 'dependencies' here; we fill in 'users' in a
7648 pst
->number_of_dependencies
= len
;
7650 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7651 for (i
= 0; i
< len
; ++i
)
7653 pst
->dependencies
[i
]
7654 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7657 cu
->per_cu
->imported_symtabs_free ();
7660 /* Get the list of files included in the current compilation unit,
7661 and build a psymtab for each of them. */
7662 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7664 if (dwarf_read_debug
)
7665 fprintf_unfiltered (gdb_stdlog
,
7666 "Psymtab for %s unit @%s: %s - %s"
7667 ", %d global, %d static syms\n",
7668 per_cu
->is_debug_types
? "type" : "comp",
7669 sect_offset_str (per_cu
->sect_off
),
7670 paddress (gdbarch
, pst
->text_low (objfile
)),
7671 paddress (gdbarch
, pst
->text_high (objfile
)),
7672 (int) pst
->global_psymbols
.size (),
7673 (int) pst
->static_psymbols
.size ());
7676 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7677 Process compilation unit THIS_CU for a psymtab. */
7680 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7681 dwarf2_per_objfile
*per_objfile
,
7682 bool want_partial_unit
,
7683 enum language pretend_language
)
7685 /* If this compilation unit was already read in, free the
7686 cached copy in order to read it in again. This is
7687 necessary because we skipped some symbols when we first
7688 read in the compilation unit (see load_partial_dies).
7689 This problem could be avoided, but the benefit is unclear. */
7690 per_objfile
->remove_cu (this_cu
);
7692 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7694 switch (reader
.comp_unit_die
->tag
)
7696 case DW_TAG_compile_unit
:
7697 this_cu
->unit_type
= DW_UT_compile
;
7699 case DW_TAG_partial_unit
:
7700 this_cu
->unit_type
= DW_UT_partial
;
7710 else if (this_cu
->is_debug_types
)
7711 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7712 reader
.comp_unit_die
);
7713 else if (want_partial_unit
7714 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7715 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7716 reader
.comp_unit_die
,
7719 this_cu
->lang
= reader
.cu
->language
;
7721 /* Age out any secondary CUs. */
7722 per_objfile
->age_comp_units ();
7725 /* Reader function for build_type_psymtabs. */
7728 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7729 const gdb_byte
*info_ptr
,
7730 struct die_info
*type_unit_die
)
7732 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7733 struct objfile
*objfile
= per_objfile
->objfile
;
7734 struct dwarf2_cu
*cu
= reader
->cu
;
7735 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7736 struct signatured_type
*sig_type
;
7737 struct type_unit_group
*tu_group
;
7738 struct attribute
*attr
;
7739 struct partial_die_info
*first_die
;
7740 CORE_ADDR lowpc
, highpc
;
7741 dwarf2_psymtab
*pst
;
7743 gdb_assert (per_cu
->is_debug_types
);
7744 sig_type
= (struct signatured_type
*) per_cu
;
7746 if (! type_unit_die
->has_children
)
7749 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7750 tu_group
= get_type_unit_group (cu
, attr
);
7752 if (tu_group
->tus
== nullptr)
7753 tu_group
->tus
= new std::vector
<signatured_type
*>;
7754 tu_group
->tus
->push_back (sig_type
);
7756 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7757 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7758 pst
->anonymous
= true;
7760 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7762 lowpc
= (CORE_ADDR
) -1;
7763 highpc
= (CORE_ADDR
) 0;
7764 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7766 end_psymtab_common (objfile
, pst
);
7769 /* Struct used to sort TUs by their abbreviation table offset. */
7771 struct tu_abbrev_offset
7773 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7774 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7777 signatured_type
*sig_type
;
7778 sect_offset abbrev_offset
;
7781 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7784 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7785 const struct tu_abbrev_offset
&b
)
7787 return a
.abbrev_offset
< b
.abbrev_offset
;
7790 /* Efficiently read all the type units.
7791 This does the bulk of the work for build_type_psymtabs.
7793 The efficiency is because we sort TUs by the abbrev table they use and
7794 only read each abbrev table once. In one program there are 200K TUs
7795 sharing 8K abbrev tables.
7797 The main purpose of this function is to support building the
7798 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7799 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7800 can collapse the search space by grouping them by stmt_list.
7801 The savings can be significant, in the same program from above the 200K TUs
7802 share 8K stmt_list tables.
7804 FUNC is expected to call get_type_unit_group, which will create the
7805 struct type_unit_group if necessary and add it to
7806 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7809 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7811 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7812 abbrev_table_up abbrev_table
;
7813 sect_offset abbrev_offset
;
7815 /* It's up to the caller to not call us multiple times. */
7816 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7818 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7821 /* TUs typically share abbrev tables, and there can be way more TUs than
7822 abbrev tables. Sort by abbrev table to reduce the number of times we
7823 read each abbrev table in.
7824 Alternatives are to punt or to maintain a cache of abbrev tables.
7825 This is simpler and efficient enough for now.
7827 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7828 symtab to use). Typically TUs with the same abbrev offset have the same
7829 stmt_list value too so in practice this should work well.
7831 The basic algorithm here is:
7833 sort TUs by abbrev table
7834 for each TU with same abbrev table:
7835 read abbrev table if first user
7836 read TU top level DIE
7837 [IWBN if DWO skeletons had DW_AT_stmt_list]
7840 if (dwarf_read_debug
)
7841 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7843 /* Sort in a separate table to maintain the order of all_type_units
7844 for .gdb_index: TU indices directly index all_type_units. */
7845 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7846 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7848 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7849 sorted_by_abbrev
.emplace_back
7850 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7851 sig_type
->per_cu
.sect_off
));
7853 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7854 sort_tu_by_abbrev_offset
);
7856 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7858 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7860 /* Switch to the next abbrev table if necessary. */
7861 if (abbrev_table
== NULL
7862 || tu
.abbrev_offset
!= abbrev_offset
)
7864 abbrev_offset
= tu
.abbrev_offset
;
7866 abbrev_table::read (per_objfile
->objfile
,
7867 &per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7868 ++tu_stats
->nr_uniq_abbrev_tables
;
7871 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7872 abbrev_table
.get (), nullptr, false);
7873 if (!reader
.dummy_p
)
7874 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7875 reader
.comp_unit_die
);
7879 /* Print collected type unit statistics. */
7882 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7884 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7886 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7887 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7888 per_objfile
->per_bfd
->all_type_units
.size ());
7889 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7890 tu_stats
->nr_uniq_abbrev_tables
);
7891 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7892 tu_stats
->nr_symtabs
);
7893 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7894 tu_stats
->nr_symtab_sharers
);
7895 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7896 tu_stats
->nr_stmt_less_type_units
);
7897 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7898 tu_stats
->nr_all_type_units_reallocs
);
7901 /* Traversal function for build_type_psymtabs. */
7904 build_type_psymtab_dependencies (void **slot
, void *info
)
7906 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7907 struct objfile
*objfile
= per_objfile
->objfile
;
7908 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7909 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7910 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7911 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7914 gdb_assert (len
> 0);
7915 gdb_assert (per_cu
->type_unit_group_p ());
7917 pst
->number_of_dependencies
= len
;
7918 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7919 for (i
= 0; i
< len
; ++i
)
7921 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7922 gdb_assert (iter
->per_cu
.is_debug_types
);
7923 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7924 iter
->type_unit_group
= tu_group
;
7927 delete tu_group
->tus
;
7928 tu_group
->tus
= nullptr;
7933 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7934 Build partial symbol tables for the .debug_types comp-units. */
7937 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7939 if (! create_all_type_units (per_objfile
))
7942 build_type_psymtabs_1 (per_objfile
);
7945 /* Traversal function for process_skeletonless_type_unit.
7946 Read a TU in a DWO file and build partial symbols for it. */
7949 process_skeletonless_type_unit (void **slot
, void *info
)
7951 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7952 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7953 struct signatured_type find_entry
, *entry
;
7955 /* If this TU doesn't exist in the global table, add it and read it in. */
7957 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7958 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7960 find_entry
.signature
= dwo_unit
->signature
;
7961 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7962 &find_entry
, INSERT
);
7963 /* If we've already seen this type there's nothing to do. What's happening
7964 is we're doing our own version of comdat-folding here. */
7968 /* This does the job that create_all_type_units would have done for
7970 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7971 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7974 /* This does the job that build_type_psymtabs_1 would have done. */
7975 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7976 if (!reader
.dummy_p
)
7977 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7978 reader
.comp_unit_die
);
7983 /* Traversal function for process_skeletonless_type_units. */
7986 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7988 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7990 if (dwo_file
->tus
!= NULL
)
7991 htab_traverse_noresize (dwo_file
->tus
.get (),
7992 process_skeletonless_type_unit
, info
);
7997 /* Scan all TUs of DWO files, verifying we've processed them.
7998 This is needed in case a TU was emitted without its skeleton.
7999 Note: This can't be done until we know what all the DWO files are. */
8002 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
8004 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8005 if (get_dwp_file (per_objfile
) == NULL
8006 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
8008 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
8009 process_dwo_file_for_skeletonless_type_units
,
8014 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8017 set_partial_user (dwarf2_per_objfile
*per_objfile
)
8019 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8021 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8026 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8028 /* Set the 'user' field only if it is not already set. */
8029 if (pst
->dependencies
[j
]->user
== NULL
)
8030 pst
->dependencies
[j
]->user
= pst
;
8035 /* Build the partial symbol table by doing a quick pass through the
8036 .debug_info and .debug_abbrev sections. */
8039 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
8041 struct objfile
*objfile
= per_objfile
->objfile
;
8043 if (dwarf_read_debug
)
8045 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8046 objfile_name (objfile
));
8049 scoped_restore restore_reading_psyms
8050 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8053 per_objfile
->per_bfd
->info
.read (objfile
);
8055 /* Any cached compilation units will be linked by the per-objfile
8056 read_in_chain. Make sure to free them when we're done. */
8057 free_cached_comp_units
freer (per_objfile
);
8059 build_type_psymtabs (per_objfile
);
8061 create_all_comp_units (per_objfile
);
8063 /* Create a temporary address map on a temporary obstack. We later
8064 copy this to the final obstack. */
8065 auto_obstack temp_obstack
;
8067 scoped_restore save_psymtabs_addrmap
8068 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8069 addrmap_create_mutable (&temp_obstack
));
8071 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8073 if (per_cu
->v
.psymtab
!= NULL
)
8074 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8076 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8080 /* This has to wait until we read the CUs, we need the list of DWOs. */
8081 process_skeletonless_type_units (per_objfile
);
8083 /* Now that all TUs have been processed we can fill in the dependencies. */
8084 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8086 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8087 build_type_psymtab_dependencies
, per_objfile
);
8090 if (dwarf_read_debug
)
8091 print_tu_stats (per_objfile
);
8093 set_partial_user (per_objfile
);
8095 objfile
->partial_symtabs
->psymtabs_addrmap
8096 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8097 objfile
->partial_symtabs
->obstack ());
8098 /* At this point we want to keep the address map. */
8099 save_psymtabs_addrmap
.release ();
8101 if (dwarf_read_debug
)
8102 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8103 objfile_name (objfile
));
8106 /* Load the partial DIEs for a secondary CU into memory.
8107 This is also used when rereading a primary CU with load_all_dies. */
8110 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8111 dwarf2_per_objfile
*per_objfile
,
8112 dwarf2_cu
*existing_cu
)
8114 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8116 if (!reader
.dummy_p
)
8118 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8121 /* Check if comp unit has_children.
8122 If so, read the rest of the partial symbols from this comp unit.
8123 If not, there's no more debug_info for this comp unit. */
8124 if (reader
.comp_unit_die
->has_children
)
8125 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8132 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8133 struct dwarf2_section_info
*section
,
8134 struct dwarf2_section_info
*abbrev_section
,
8135 unsigned int is_dwz
)
8137 const gdb_byte
*info_ptr
;
8138 struct objfile
*objfile
= per_objfile
->objfile
;
8140 if (dwarf_read_debug
)
8141 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8142 section
->get_name (),
8143 section
->get_file_name ());
8145 section
->read (objfile
);
8147 info_ptr
= section
->buffer
;
8149 while (info_ptr
< section
->buffer
+ section
->size
)
8151 struct dwarf2_per_cu_data
*this_cu
;
8153 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8155 comp_unit_head cu_header
;
8156 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8157 abbrev_section
, info_ptr
,
8158 rcuh_kind::COMPILE
);
8160 /* Save the compilation unit for later lookup. */
8161 if (cu_header
.unit_type
!= DW_UT_type
)
8162 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8165 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8166 sig_type
->signature
= cu_header
.signature
;
8167 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8168 this_cu
= &sig_type
->per_cu
;
8170 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8171 this_cu
->sect_off
= sect_off
;
8172 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8173 this_cu
->is_dwz
= is_dwz
;
8174 this_cu
->section
= section
;
8176 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8178 info_ptr
= info_ptr
+ this_cu
->length
;
8182 /* Create a list of all compilation units in OBJFILE.
8183 This is only done for -readnow and building partial symtabs. */
8186 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8188 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8189 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8190 &per_objfile
->per_bfd
->abbrev
, 0);
8192 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8194 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8197 /* Process all loaded DIEs for compilation unit CU, starting at
8198 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8199 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8200 DW_AT_ranges). See the comments of add_partial_subprogram on how
8201 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8204 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8205 CORE_ADDR
*highpc
, int set_addrmap
,
8206 struct dwarf2_cu
*cu
)
8208 struct partial_die_info
*pdi
;
8210 /* Now, march along the PDI's, descending into ones which have
8211 interesting children but skipping the children of the other ones,
8212 until we reach the end of the compilation unit. */
8220 /* Anonymous namespaces or modules have no name but have interesting
8221 children, so we need to look at them. Ditto for anonymous
8224 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8225 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8226 || pdi
->tag
== DW_TAG_imported_unit
8227 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8231 case DW_TAG_subprogram
:
8232 case DW_TAG_inlined_subroutine
:
8233 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8234 if (cu
->language
== language_cplus
)
8235 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8238 case DW_TAG_constant
:
8239 case DW_TAG_variable
:
8240 case DW_TAG_typedef
:
8241 case DW_TAG_union_type
:
8242 if (!pdi
->is_declaration
8243 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8245 add_partial_symbol (pdi
, cu
);
8248 case DW_TAG_class_type
:
8249 case DW_TAG_interface_type
:
8250 case DW_TAG_structure_type
:
8251 if (!pdi
->is_declaration
)
8253 add_partial_symbol (pdi
, cu
);
8255 if ((cu
->language
== language_rust
8256 || cu
->language
== language_cplus
) && pdi
->has_children
)
8257 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8260 case DW_TAG_enumeration_type
:
8261 if (!pdi
->is_declaration
)
8262 add_partial_enumeration (pdi
, cu
);
8264 case DW_TAG_base_type
:
8265 case DW_TAG_subrange_type
:
8266 /* File scope base type definitions are added to the partial
8268 add_partial_symbol (pdi
, cu
);
8270 case DW_TAG_namespace
:
8271 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8274 if (!pdi
->is_declaration
)
8275 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8277 case DW_TAG_imported_unit
:
8279 struct dwarf2_per_cu_data
*per_cu
;
8281 /* For now we don't handle imported units in type units. */
8282 if (cu
->per_cu
->is_debug_types
)
8284 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8285 " supported in type units [in module %s]"),
8286 objfile_name (cu
->per_objfile
->objfile
));
8289 per_cu
= dwarf2_find_containing_comp_unit
8290 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8292 /* Go read the partial unit, if needed. */
8293 if (per_cu
->v
.psymtab
== NULL
)
8294 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8297 cu
->per_cu
->imported_symtabs_push (per_cu
);
8300 case DW_TAG_imported_declaration
:
8301 add_partial_symbol (pdi
, cu
);
8308 /* If the die has a sibling, skip to the sibling. */
8310 pdi
= pdi
->die_sibling
;
8314 /* Functions used to compute the fully scoped name of a partial DIE.
8316 Normally, this is simple. For C++, the parent DIE's fully scoped
8317 name is concatenated with "::" and the partial DIE's name.
8318 Enumerators are an exception; they use the scope of their parent
8319 enumeration type, i.e. the name of the enumeration type is not
8320 prepended to the enumerator.
8322 There are two complexities. One is DW_AT_specification; in this
8323 case "parent" means the parent of the target of the specification,
8324 instead of the direct parent of the DIE. The other is compilers
8325 which do not emit DW_TAG_namespace; in this case we try to guess
8326 the fully qualified name of structure types from their members'
8327 linkage names. This must be done using the DIE's children rather
8328 than the children of any DW_AT_specification target. We only need
8329 to do this for structures at the top level, i.e. if the target of
8330 any DW_AT_specification (if any; otherwise the DIE itself) does not
8333 /* Compute the scope prefix associated with PDI's parent, in
8334 compilation unit CU. The result will be allocated on CU's
8335 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8336 field. NULL is returned if no prefix is necessary. */
8338 partial_die_parent_scope (struct partial_die_info
*pdi
,
8339 struct dwarf2_cu
*cu
)
8341 const char *grandparent_scope
;
8342 struct partial_die_info
*parent
, *real_pdi
;
8344 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8345 then this means the parent of the specification DIE. */
8348 while (real_pdi
->has_specification
)
8350 auto res
= find_partial_die (real_pdi
->spec_offset
,
8351 real_pdi
->spec_is_dwz
, cu
);
8356 parent
= real_pdi
->die_parent
;
8360 if (parent
->scope_set
)
8361 return parent
->scope
;
8365 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8367 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8368 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8369 Work around this problem here. */
8370 if (cu
->language
== language_cplus
8371 && parent
->tag
== DW_TAG_namespace
8372 && strcmp (parent
->name (cu
), "::") == 0
8373 && grandparent_scope
== NULL
)
8375 parent
->scope
= NULL
;
8376 parent
->scope_set
= 1;
8380 /* Nested subroutines in Fortran get a prefix. */
8381 if (pdi
->tag
== DW_TAG_enumerator
)
8382 /* Enumerators should not get the name of the enumeration as a prefix. */
8383 parent
->scope
= grandparent_scope
;
8384 else if (parent
->tag
== DW_TAG_namespace
8385 || parent
->tag
== DW_TAG_module
8386 || parent
->tag
== DW_TAG_structure_type
8387 || parent
->tag
== DW_TAG_class_type
8388 || parent
->tag
== DW_TAG_interface_type
8389 || parent
->tag
== DW_TAG_union_type
8390 || parent
->tag
== DW_TAG_enumeration_type
8391 || (cu
->language
== language_fortran
8392 && parent
->tag
== DW_TAG_subprogram
8393 && pdi
->tag
== DW_TAG_subprogram
))
8395 if (grandparent_scope
== NULL
)
8396 parent
->scope
= parent
->name (cu
);
8398 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8400 parent
->name (cu
), 0, cu
);
8404 /* FIXME drow/2004-04-01: What should we be doing with
8405 function-local names? For partial symbols, we should probably be
8407 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8408 dwarf_tag_name (parent
->tag
),
8409 sect_offset_str (pdi
->sect_off
));
8410 parent
->scope
= grandparent_scope
;
8413 parent
->scope_set
= 1;
8414 return parent
->scope
;
8417 /* Return the fully scoped name associated with PDI, from compilation unit
8418 CU. The result will be allocated with malloc. */
8420 static gdb::unique_xmalloc_ptr
<char>
8421 partial_die_full_name (struct partial_die_info
*pdi
,
8422 struct dwarf2_cu
*cu
)
8424 const char *parent_scope
;
8426 /* If this is a template instantiation, we can not work out the
8427 template arguments from partial DIEs. So, unfortunately, we have
8428 to go through the full DIEs. At least any work we do building
8429 types here will be reused if full symbols are loaded later. */
8430 if (pdi
->has_template_arguments
)
8434 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8436 struct die_info
*die
;
8437 struct attribute attr
;
8438 struct dwarf2_cu
*ref_cu
= cu
;
8440 /* DW_FORM_ref_addr is using section offset. */
8441 attr
.name
= (enum dwarf_attribute
) 0;
8442 attr
.form
= DW_FORM_ref_addr
;
8443 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8444 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8446 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8450 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8451 if (parent_scope
== NULL
)
8454 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8460 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8462 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8463 struct objfile
*objfile
= per_objfile
->objfile
;
8464 struct gdbarch
*gdbarch
= objfile
->arch ();
8466 const char *actual_name
= NULL
;
8469 baseaddr
= objfile
->text_section_offset ();
8471 gdb::unique_xmalloc_ptr
<char> built_actual_name
8472 = partial_die_full_name (pdi
, cu
);
8473 if (built_actual_name
!= NULL
)
8474 actual_name
= built_actual_name
.get ();
8476 if (actual_name
== NULL
)
8477 actual_name
= pdi
->name (cu
);
8479 partial_symbol psymbol
;
8480 memset (&psymbol
, 0, sizeof (psymbol
));
8481 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8482 psymbol
.ginfo
.section
= -1;
8484 /* The code below indicates that the psymbol should be installed by
8486 gdb::optional
<psymbol_placement
> where
;
8490 case DW_TAG_inlined_subroutine
:
8491 case DW_TAG_subprogram
:
8492 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8494 if (pdi
->is_external
8495 || cu
->language
== language_ada
8496 || (cu
->language
== language_fortran
8497 && pdi
->die_parent
!= NULL
8498 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8500 /* Normally, only "external" DIEs are part of the global scope.
8501 But in Ada and Fortran, we want to be able to access nested
8502 procedures globally. So all Ada and Fortran subprograms are
8503 stored in the global scope. */
8504 where
= psymbol_placement::GLOBAL
;
8507 where
= psymbol_placement::STATIC
;
8509 psymbol
.domain
= VAR_DOMAIN
;
8510 psymbol
.aclass
= LOC_BLOCK
;
8511 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8512 psymbol
.ginfo
.value
.address
= addr
;
8514 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8515 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8517 case DW_TAG_constant
:
8518 psymbol
.domain
= VAR_DOMAIN
;
8519 psymbol
.aclass
= LOC_STATIC
;
8520 where
= (pdi
->is_external
8521 ? psymbol_placement::GLOBAL
8522 : psymbol_placement::STATIC
);
8524 case DW_TAG_variable
:
8526 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8530 && !per_objfile
->per_bfd
->has_section_at_zero
)
8532 /* A global or static variable may also have been stripped
8533 out by the linker if unused, in which case its address
8534 will be nullified; do not add such variables into partial
8535 symbol table then. */
8537 else if (pdi
->is_external
)
8540 Don't enter into the minimal symbol tables as there is
8541 a minimal symbol table entry from the ELF symbols already.
8542 Enter into partial symbol table if it has a location
8543 descriptor or a type.
8544 If the location descriptor is missing, new_symbol will create
8545 a LOC_UNRESOLVED symbol, the address of the variable will then
8546 be determined from the minimal symbol table whenever the variable
8548 The address for the partial symbol table entry is not
8549 used by GDB, but it comes in handy for debugging partial symbol
8552 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8554 psymbol
.domain
= VAR_DOMAIN
;
8555 psymbol
.aclass
= LOC_STATIC
;
8556 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8557 psymbol
.ginfo
.value
.address
= addr
;
8558 where
= psymbol_placement::GLOBAL
;
8563 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8565 /* Static Variable. Skip symbols whose value we cannot know (those
8566 without location descriptors or constant values). */
8567 if (!has_loc
&& !pdi
->has_const_value
)
8570 psymbol
.domain
= VAR_DOMAIN
;
8571 psymbol
.aclass
= LOC_STATIC
;
8572 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8574 psymbol
.ginfo
.value
.address
= addr
;
8575 where
= psymbol_placement::STATIC
;
8578 case DW_TAG_typedef
:
8579 case DW_TAG_base_type
:
8580 case DW_TAG_subrange_type
:
8581 psymbol
.domain
= VAR_DOMAIN
;
8582 psymbol
.aclass
= LOC_TYPEDEF
;
8583 where
= psymbol_placement::STATIC
;
8585 case DW_TAG_imported_declaration
:
8586 case DW_TAG_namespace
:
8587 psymbol
.domain
= VAR_DOMAIN
;
8588 psymbol
.aclass
= LOC_TYPEDEF
;
8589 where
= psymbol_placement::GLOBAL
;
8592 /* With Fortran 77 there might be a "BLOCK DATA" module
8593 available without any name. If so, we skip the module as it
8594 doesn't bring any value. */
8595 if (actual_name
!= nullptr)
8597 psymbol
.domain
= MODULE_DOMAIN
;
8598 psymbol
.aclass
= LOC_TYPEDEF
;
8599 where
= psymbol_placement::GLOBAL
;
8602 case DW_TAG_class_type
:
8603 case DW_TAG_interface_type
:
8604 case DW_TAG_structure_type
:
8605 case DW_TAG_union_type
:
8606 case DW_TAG_enumeration_type
:
8607 /* Skip external references. The DWARF standard says in the section
8608 about "Structure, Union, and Class Type Entries": "An incomplete
8609 structure, union or class type is represented by a structure,
8610 union or class entry that does not have a byte size attribute
8611 and that has a DW_AT_declaration attribute." */
8612 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8615 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8616 static vs. global. */
8617 psymbol
.domain
= STRUCT_DOMAIN
;
8618 psymbol
.aclass
= LOC_TYPEDEF
;
8619 where
= (cu
->language
== language_cplus
8620 ? psymbol_placement::GLOBAL
8621 : psymbol_placement::STATIC
);
8623 case DW_TAG_enumerator
:
8624 psymbol
.domain
= VAR_DOMAIN
;
8625 psymbol
.aclass
= LOC_CONST
;
8626 where
= (cu
->language
== language_cplus
8627 ? psymbol_placement::GLOBAL
8628 : psymbol_placement::STATIC
);
8634 if (where
.has_value ())
8636 if (built_actual_name
!= nullptr)
8637 actual_name
= objfile
->intern (actual_name
);
8638 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8639 psymbol
.ginfo
.set_linkage_name (actual_name
);
8642 psymbol
.ginfo
.set_demangled_name (actual_name
,
8643 &objfile
->objfile_obstack
);
8644 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8646 cu
->per_cu
->v
.psymtab
->add_psymbol (psymbol
, *where
, objfile
);
8650 /* Read a partial die corresponding to a namespace; also, add a symbol
8651 corresponding to that namespace to the symbol table. NAMESPACE is
8652 the name of the enclosing namespace. */
8655 add_partial_namespace (struct partial_die_info
*pdi
,
8656 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8657 int set_addrmap
, struct dwarf2_cu
*cu
)
8659 /* Add a symbol for the namespace. */
8661 add_partial_symbol (pdi
, cu
);
8663 /* Now scan partial symbols in that namespace. */
8665 if (pdi
->has_children
)
8666 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8669 /* Read a partial die corresponding to a Fortran module. */
8672 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8673 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8675 /* Add a symbol for the namespace. */
8677 add_partial_symbol (pdi
, cu
);
8679 /* Now scan partial symbols in that module. */
8681 if (pdi
->has_children
)
8682 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8685 /* Read a partial die corresponding to a subprogram or an inlined
8686 subprogram and create a partial symbol for that subprogram.
8687 When the CU language allows it, this routine also defines a partial
8688 symbol for each nested subprogram that this subprogram contains.
8689 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8690 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8692 PDI may also be a lexical block, in which case we simply search
8693 recursively for subprograms defined inside that lexical block.
8694 Again, this is only performed when the CU language allows this
8695 type of definitions. */
8698 add_partial_subprogram (struct partial_die_info
*pdi
,
8699 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8700 int set_addrmap
, struct dwarf2_cu
*cu
)
8702 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8704 if (pdi
->has_pc_info
)
8706 if (pdi
->lowpc
< *lowpc
)
8707 *lowpc
= pdi
->lowpc
;
8708 if (pdi
->highpc
> *highpc
)
8709 *highpc
= pdi
->highpc
;
8712 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8713 struct gdbarch
*gdbarch
= objfile
->arch ();
8715 CORE_ADDR this_highpc
;
8716 CORE_ADDR this_lowpc
;
8718 baseaddr
= objfile
->text_section_offset ();
8720 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8721 pdi
->lowpc
+ baseaddr
)
8724 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8725 pdi
->highpc
+ baseaddr
)
8727 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8728 this_lowpc
, this_highpc
- 1,
8729 cu
->per_cu
->v
.psymtab
);
8733 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8735 if (!pdi
->is_declaration
)
8736 /* Ignore subprogram DIEs that do not have a name, they are
8737 illegal. Do not emit a complaint at this point, we will
8738 do so when we convert this psymtab into a symtab. */
8740 add_partial_symbol (pdi
, cu
);
8744 if (! pdi
->has_children
)
8747 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8749 pdi
= pdi
->die_child
;
8753 if (pdi
->tag
== DW_TAG_subprogram
8754 || pdi
->tag
== DW_TAG_inlined_subroutine
8755 || pdi
->tag
== DW_TAG_lexical_block
)
8756 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8757 pdi
= pdi
->die_sibling
;
8762 /* Read a partial die corresponding to an enumeration type. */
8765 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8766 struct dwarf2_cu
*cu
)
8768 struct partial_die_info
*pdi
;
8770 if (enum_pdi
->name (cu
) != NULL
)
8771 add_partial_symbol (enum_pdi
, cu
);
8773 pdi
= enum_pdi
->die_child
;
8776 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8777 complaint (_("malformed enumerator DIE ignored"));
8779 add_partial_symbol (pdi
, cu
);
8780 pdi
= pdi
->die_sibling
;
8784 /* Return the initial uleb128 in the die at INFO_PTR. */
8787 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8789 unsigned int bytes_read
;
8791 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8794 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8795 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8797 Return the corresponding abbrev, or NULL if the number is zero (indicating
8798 an empty DIE). In either case *BYTES_READ will be set to the length of
8799 the initial number. */
8801 static struct abbrev_info
*
8802 peek_die_abbrev (const die_reader_specs
&reader
,
8803 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8805 dwarf2_cu
*cu
= reader
.cu
;
8806 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8807 unsigned int abbrev_number
8808 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8810 if (abbrev_number
== 0)
8813 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8816 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8817 " at offset %s [in module %s]"),
8818 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8819 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8825 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8826 Returns a pointer to the end of a series of DIEs, terminated by an empty
8827 DIE. Any children of the skipped DIEs will also be skipped. */
8829 static const gdb_byte
*
8830 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8834 unsigned int bytes_read
;
8835 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8838 return info_ptr
+ bytes_read
;
8840 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8844 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8845 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8846 abbrev corresponding to that skipped uleb128 should be passed in
8847 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8850 static const gdb_byte
*
8851 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8852 struct abbrev_info
*abbrev
)
8854 unsigned int bytes_read
;
8855 struct attribute attr
;
8856 bfd
*abfd
= reader
->abfd
;
8857 struct dwarf2_cu
*cu
= reader
->cu
;
8858 const gdb_byte
*buffer
= reader
->buffer
;
8859 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8860 unsigned int form
, i
;
8862 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8864 /* The only abbrev we care about is DW_AT_sibling. */
8865 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8867 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8868 if (attr
.form
== DW_FORM_ref_addr
)
8869 complaint (_("ignoring absolute DW_AT_sibling"));
8872 sect_offset off
= attr
.get_ref_die_offset ();
8873 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8875 if (sibling_ptr
< info_ptr
)
8876 complaint (_("DW_AT_sibling points backwards"));
8877 else if (sibling_ptr
> reader
->buffer_end
)
8878 reader
->die_section
->overflow_complaint ();
8884 /* If it isn't DW_AT_sibling, skip this attribute. */
8885 form
= abbrev
->attrs
[i
].form
;
8889 case DW_FORM_ref_addr
:
8890 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8891 and later it is offset sized. */
8892 if (cu
->header
.version
== 2)
8893 info_ptr
+= cu
->header
.addr_size
;
8895 info_ptr
+= cu
->header
.offset_size
;
8897 case DW_FORM_GNU_ref_alt
:
8898 info_ptr
+= cu
->header
.offset_size
;
8901 info_ptr
+= cu
->header
.addr_size
;
8909 case DW_FORM_flag_present
:
8910 case DW_FORM_implicit_const
:
8927 case DW_FORM_ref_sig8
:
8930 case DW_FORM_data16
:
8933 case DW_FORM_string
:
8934 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8935 info_ptr
+= bytes_read
;
8937 case DW_FORM_sec_offset
:
8939 case DW_FORM_GNU_strp_alt
:
8940 info_ptr
+= cu
->header
.offset_size
;
8942 case DW_FORM_exprloc
:
8944 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8945 info_ptr
+= bytes_read
;
8947 case DW_FORM_block1
:
8948 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8950 case DW_FORM_block2
:
8951 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8953 case DW_FORM_block4
:
8954 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8960 case DW_FORM_ref_udata
:
8961 case DW_FORM_GNU_addr_index
:
8962 case DW_FORM_GNU_str_index
:
8963 case DW_FORM_rnglistx
:
8964 case DW_FORM_loclistx
:
8965 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8967 case DW_FORM_indirect
:
8968 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8969 info_ptr
+= bytes_read
;
8970 /* We need to continue parsing from here, so just go back to
8972 goto skip_attribute
;
8975 error (_("Dwarf Error: Cannot handle %s "
8976 "in DWARF reader [in module %s]"),
8977 dwarf_form_name (form
),
8978 bfd_get_filename (abfd
));
8982 if (abbrev
->has_children
)
8983 return skip_children (reader
, info_ptr
);
8988 /* Locate ORIG_PDI's sibling.
8989 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8991 static const gdb_byte
*
8992 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8993 struct partial_die_info
*orig_pdi
,
8994 const gdb_byte
*info_ptr
)
8996 /* Do we know the sibling already? */
8998 if (orig_pdi
->sibling
)
8999 return orig_pdi
->sibling
;
9001 /* Are there any children to deal with? */
9003 if (!orig_pdi
->has_children
)
9006 /* Skip the children the long way. */
9008 return skip_children (reader
, info_ptr
);
9011 /* Expand this partial symbol table into a full symbol table. SELF is
9015 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9017 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9019 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
9021 /* If this psymtab is constructed from a debug-only objfile, the
9022 has_section_at_zero flag will not necessarily be correct. We
9023 can get the correct value for this flag by looking at the data
9024 associated with the (presumably stripped) associated objfile. */
9025 if (objfile
->separate_debug_objfile_backlink
)
9027 dwarf2_per_objfile
*per_objfile_backlink
9028 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9030 per_objfile
->per_bfd
->has_section_at_zero
9031 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9034 expand_psymtab (objfile
);
9036 process_cu_includes (per_objfile
);
9039 /* Reading in full CUs. */
9041 /* Add PER_CU to the queue. */
9044 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9045 dwarf2_per_objfile
*per_objfile
,
9046 enum language pretend_language
)
9049 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
9052 /* If PER_CU is not yet queued, add it to the queue.
9053 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9055 The result is non-zero if PER_CU was queued, otherwise the result is zero
9056 meaning either PER_CU is already queued or it is already loaded.
9058 N.B. There is an invariant here that if a CU is queued then it is loaded.
9059 The caller is required to load PER_CU if we return non-zero. */
9062 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9063 dwarf2_per_cu_data
*per_cu
,
9064 dwarf2_per_objfile
*per_objfile
,
9065 enum language pretend_language
)
9067 /* We may arrive here during partial symbol reading, if we need full
9068 DIEs to process an unusual case (e.g. template arguments). Do
9069 not queue PER_CU, just tell our caller to load its DIEs. */
9070 if (per_cu
->per_bfd
->reading_partial_symbols
)
9072 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9074 if (cu
== NULL
|| cu
->dies
== NULL
)
9079 /* Mark the dependence relation so that we don't flush PER_CU
9081 if (dependent_cu
!= NULL
)
9082 dwarf2_add_dependence (dependent_cu
, per_cu
);
9084 /* If it's already on the queue, we have nothing to do. */
9088 /* If the compilation unit is already loaded, just mark it as
9090 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9097 /* Add it to the queue. */
9098 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9103 /* Process the queue. */
9106 process_queue (dwarf2_per_objfile
*per_objfile
)
9108 if (dwarf_read_debug
)
9110 fprintf_unfiltered (gdb_stdlog
,
9111 "Expanding one or more symtabs of objfile %s ...\n",
9112 objfile_name (per_objfile
->objfile
));
9115 /* The queue starts out with one item, but following a DIE reference
9116 may load a new CU, adding it to the end of the queue. */
9117 while (!per_objfile
->per_bfd
->queue
.empty ())
9119 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9120 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9122 if (!per_objfile
->symtab_set_p (per_cu
))
9124 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9126 /* Skip dummy CUs. */
9129 unsigned int debug_print_threshold
;
9132 if (per_cu
->is_debug_types
)
9134 struct signatured_type
*sig_type
=
9135 (struct signatured_type
*) per_cu
;
9137 sprintf (buf
, "TU %s at offset %s",
9138 hex_string (sig_type
->signature
),
9139 sect_offset_str (per_cu
->sect_off
));
9140 /* There can be 100s of TUs.
9141 Only print them in verbose mode. */
9142 debug_print_threshold
= 2;
9146 sprintf (buf
, "CU at offset %s",
9147 sect_offset_str (per_cu
->sect_off
));
9148 debug_print_threshold
= 1;
9151 if (dwarf_read_debug
>= debug_print_threshold
)
9152 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9154 if (per_cu
->is_debug_types
)
9155 process_full_type_unit (cu
, item
.pretend_language
);
9157 process_full_comp_unit (cu
, item
.pretend_language
);
9159 if (dwarf_read_debug
>= debug_print_threshold
)
9160 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9165 per_objfile
->per_bfd
->queue
.pop ();
9168 if (dwarf_read_debug
)
9170 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9171 objfile_name (per_objfile
->objfile
));
9175 /* Read in full symbols for PST, and anything it depends on. */
9178 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9180 gdb_assert (!readin_p (objfile
));
9182 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9183 free_cached_comp_units
freer (per_objfile
);
9184 expand_dependencies (objfile
);
9186 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9187 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9190 /* See psympriv.h. */
9193 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9195 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9196 return per_objfile
->symtab_set_p (per_cu_data
);
9199 /* See psympriv.h. */
9202 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9204 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9205 return per_objfile
->get_symtab (per_cu_data
);
9208 /* Trivial hash function for die_info: the hash value of a DIE
9209 is its offset in .debug_info for this objfile. */
9212 die_hash (const void *item
)
9214 const struct die_info
*die
= (const struct die_info
*) item
;
9216 return to_underlying (die
->sect_off
);
9219 /* Trivial comparison function for die_info structures: two DIEs
9220 are equal if they have the same offset. */
9223 die_eq (const void *item_lhs
, const void *item_rhs
)
9225 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9226 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9228 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9231 /* Load the DIEs associated with PER_CU into memory.
9233 In some cases, the caller, while reading partial symbols, will need to load
9234 the full symbols for the CU for some reason. It will already have a
9235 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
9236 rather than creating a new one. */
9239 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9240 dwarf2_per_objfile
*per_objfile
,
9241 dwarf2_cu
*existing_cu
,
9243 enum language pretend_language
)
9245 gdb_assert (! this_cu
->is_debug_types
);
9247 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9251 struct dwarf2_cu
*cu
= reader
.cu
;
9252 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9254 gdb_assert (cu
->die_hash
== NULL
);
9256 htab_create_alloc_ex (cu
->header
.length
/ 12,
9260 &cu
->comp_unit_obstack
,
9261 hashtab_obstack_allocate
,
9262 dummy_obstack_deallocate
);
9264 if (reader
.comp_unit_die
->has_children
)
9265 reader
.comp_unit_die
->child
9266 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9267 &info_ptr
, reader
.comp_unit_die
);
9268 cu
->dies
= reader
.comp_unit_die
;
9269 /* comp_unit_die is not stored in die_hash, no need. */
9271 /* We try not to read any attributes in this function, because not
9272 all CUs needed for references have been loaded yet, and symbol
9273 table processing isn't initialized. But we have to set the CU language,
9274 or we won't be able to build types correctly.
9275 Similarly, if we do not read the producer, we can not apply
9276 producer-specific interpretation. */
9277 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9282 /* Add a DIE to the delayed physname list. */
9285 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9286 const char *name
, struct die_info
*die
,
9287 struct dwarf2_cu
*cu
)
9289 struct delayed_method_info mi
;
9291 mi
.fnfield_index
= fnfield_index
;
9295 cu
->method_list
.push_back (mi
);
9298 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9299 "const" / "volatile". If so, decrements LEN by the length of the
9300 modifier and return true. Otherwise return false. */
9304 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9306 size_t mod_len
= sizeof (mod
) - 1;
9307 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9315 /* Compute the physnames of any methods on the CU's method list.
9317 The computation of method physnames is delayed in order to avoid the
9318 (bad) condition that one of the method's formal parameters is of an as yet
9322 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9324 /* Only C++ delays computing physnames. */
9325 if (cu
->method_list
.empty ())
9327 gdb_assert (cu
->language
== language_cplus
);
9329 for (const delayed_method_info
&mi
: cu
->method_list
)
9331 const char *physname
;
9332 struct fn_fieldlist
*fn_flp
9333 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9334 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9335 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9336 = physname
? physname
: "";
9338 /* Since there's no tag to indicate whether a method is a
9339 const/volatile overload, extract that information out of the
9341 if (physname
!= NULL
)
9343 size_t len
= strlen (physname
);
9347 if (physname
[len
] == ')') /* shortcut */
9349 else if (check_modifier (physname
, len
, " const"))
9350 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9351 else if (check_modifier (physname
, len
, " volatile"))
9352 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9359 /* The list is no longer needed. */
9360 cu
->method_list
.clear ();
9363 /* Go objects should be embedded in a DW_TAG_module DIE,
9364 and it's not clear if/how imported objects will appear.
9365 To keep Go support simple until that's worked out,
9366 go back through what we've read and create something usable.
9367 We could do this while processing each DIE, and feels kinda cleaner,
9368 but that way is more invasive.
9369 This is to, for example, allow the user to type "p var" or "b main"
9370 without having to specify the package name, and allow lookups
9371 of module.object to work in contexts that use the expression
9375 fixup_go_packaging (struct dwarf2_cu
*cu
)
9377 gdb::unique_xmalloc_ptr
<char> package_name
;
9378 struct pending
*list
;
9381 for (list
= *cu
->get_builder ()->get_global_symbols ();
9385 for (i
= 0; i
< list
->nsyms
; ++i
)
9387 struct symbol
*sym
= list
->symbol
[i
];
9389 if (sym
->language () == language_go
9390 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9392 gdb::unique_xmalloc_ptr
<char> this_package_name
9393 (go_symbol_package_name (sym
));
9395 if (this_package_name
== NULL
)
9397 if (package_name
== NULL
)
9398 package_name
= std::move (this_package_name
);
9401 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9402 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9403 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9404 (symbol_symtab (sym
) != NULL
9405 ? symtab_to_filename_for_display
9406 (symbol_symtab (sym
))
9407 : objfile_name (objfile
)),
9408 this_package_name
.get (), package_name
.get ());
9414 if (package_name
!= NULL
)
9416 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9417 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9418 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9419 saved_package_name
);
9422 sym
= new (&objfile
->objfile_obstack
) symbol
;
9423 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9424 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9425 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9426 e.g., "main" finds the "main" module and not C's main(). */
9427 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9428 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9429 SYMBOL_TYPE (sym
) = type
;
9431 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9435 /* Allocate a fully-qualified name consisting of the two parts on the
9439 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9441 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9444 /* A helper that allocates a variant part to attach to a Rust enum
9445 type. OBSTACK is where the results should be allocated. TYPE is
9446 the type we're processing. DISCRIMINANT_INDEX is the index of the
9447 discriminant. It must be the index of one of the fields of TYPE,
9448 or -1 to mean there is no discriminant (univariant enum).
9449 DEFAULT_INDEX is the index of the default field; or -1 if there is
9450 no default. RANGES is indexed by "effective" field number (the
9451 field index, but omitting the discriminant and default fields) and
9452 must hold the discriminant values used by the variants. Note that
9453 RANGES must have a lifetime at least as long as OBSTACK -- either
9454 already allocated on it, or static. */
9457 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9458 int discriminant_index
, int default_index
,
9459 gdb::array_view
<discriminant_range
> ranges
)
9461 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9462 gdb_assert (discriminant_index
== -1
9463 || (discriminant_index
>= 0
9464 && discriminant_index
< type
->num_fields ()));
9465 gdb_assert (default_index
== -1
9466 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9468 /* We have one variant for each non-discriminant field. */
9469 int n_variants
= type
->num_fields ();
9470 if (discriminant_index
!= -1)
9473 variant
*variants
= new (obstack
) variant
[n_variants
];
9476 for (int i
= 0; i
< type
->num_fields (); ++i
)
9478 if (i
== discriminant_index
)
9481 variants
[var_idx
].first_field
= i
;
9482 variants
[var_idx
].last_field
= i
+ 1;
9484 /* The default field does not need a range, but other fields do.
9485 We skipped the discriminant above. */
9486 if (i
!= default_index
)
9488 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9495 gdb_assert (range_idx
== ranges
.size ());
9496 gdb_assert (var_idx
== n_variants
);
9498 variant_part
*part
= new (obstack
) variant_part
;
9499 part
->discriminant_index
= discriminant_index
;
9500 /* If there is no discriminant, then whether it is signed is of no
9503 = (discriminant_index
== -1
9505 : type
->field (discriminant_index
).type ()->is_unsigned ());
9506 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9508 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9509 gdb::array_view
<variant_part
> *prop_value
9510 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9512 struct dynamic_prop prop
;
9513 prop
.set_variant_parts (prop_value
);
9515 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9518 /* Some versions of rustc emitted enums in an unusual way.
9520 Ordinary enums were emitted as unions. The first element of each
9521 structure in the union was named "RUST$ENUM$DISR". This element
9522 held the discriminant.
9524 These versions of Rust also implemented the "non-zero"
9525 optimization. When the enum had two values, and one is empty and
9526 the other holds a pointer that cannot be zero, the pointer is used
9527 as the discriminant, with a zero value meaning the empty variant.
9528 Here, the union's first member is of the form
9529 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9530 where the fieldnos are the indices of the fields that should be
9531 traversed in order to find the field (which may be several fields deep)
9532 and the variantname is the name of the variant of the case when the
9535 This function recognizes whether TYPE is of one of these forms,
9536 and, if so, smashes it to be a variant type. */
9539 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9541 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9543 /* We don't need to deal with empty enums. */
9544 if (type
->num_fields () == 0)
9547 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9548 if (type
->num_fields () == 1
9549 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9551 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9553 /* Decode the field name to find the offset of the
9555 ULONGEST bit_offset
= 0;
9556 struct type
*field_type
= type
->field (0).type ();
9557 while (name
[0] >= '0' && name
[0] <= '9')
9560 unsigned long index
= strtoul (name
, &tail
, 10);
9563 || index
>= field_type
->num_fields ()
9564 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9565 != FIELD_LOC_KIND_BITPOS
))
9567 complaint (_("Could not parse Rust enum encoding string \"%s\""
9569 TYPE_FIELD_NAME (type
, 0),
9570 objfile_name (objfile
));
9575 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9576 field_type
= field_type
->field (index
).type ();
9579 /* Smash this type to be a structure type. We have to do this
9580 because the type has already been recorded. */
9581 type
->set_code (TYPE_CODE_STRUCT
);
9582 type
->set_num_fields (3);
9583 /* Save the field we care about. */
9584 struct field saved_field
= type
->field (0);
9586 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9588 /* Put the discriminant at index 0. */
9589 type
->field (0).set_type (field_type
);
9590 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9591 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9592 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9594 /* The order of fields doesn't really matter, so put the real
9595 field at index 1 and the data-less field at index 2. */
9596 type
->field (1) = saved_field
;
9597 TYPE_FIELD_NAME (type
, 1)
9598 = rust_last_path_segment (type
->field (1).type ()->name ());
9599 type
->field (1).type ()->set_name
9600 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9601 TYPE_FIELD_NAME (type
, 1)));
9603 const char *dataless_name
9604 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9606 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9608 type
->field (2).set_type (dataless_type
);
9609 /* NAME points into the original discriminant name, which
9610 already has the correct lifetime. */
9611 TYPE_FIELD_NAME (type
, 2) = name
;
9612 SET_FIELD_BITPOS (type
->field (2), 0);
9614 /* Indicate that this is a variant type. */
9615 static discriminant_range ranges
[1] = { { 0, 0 } };
9616 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9618 /* A union with a single anonymous field is probably an old-style
9620 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9622 /* Smash this type to be a structure type. We have to do this
9623 because the type has already been recorded. */
9624 type
->set_code (TYPE_CODE_STRUCT
);
9626 struct type
*field_type
= type
->field (0).type ();
9627 const char *variant_name
9628 = rust_last_path_segment (field_type
->name ());
9629 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9630 field_type
->set_name
9631 (rust_fully_qualify (&objfile
->objfile_obstack
,
9632 type
->name (), variant_name
));
9634 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9638 struct type
*disr_type
= nullptr;
9639 for (int i
= 0; i
< type
->num_fields (); ++i
)
9641 disr_type
= type
->field (i
).type ();
9643 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9645 /* All fields of a true enum will be structs. */
9648 else if (disr_type
->num_fields () == 0)
9650 /* Could be data-less variant, so keep going. */
9651 disr_type
= nullptr;
9653 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9654 "RUST$ENUM$DISR") != 0)
9656 /* Not a Rust enum. */
9666 /* If we got here without a discriminant, then it's probably
9668 if (disr_type
== nullptr)
9671 /* Smash this type to be a structure type. We have to do this
9672 because the type has already been recorded. */
9673 type
->set_code (TYPE_CODE_STRUCT
);
9675 /* Make space for the discriminant field. */
9676 struct field
*disr_field
= &disr_type
->field (0);
9678 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9679 * sizeof (struct field
)));
9680 memcpy (new_fields
+ 1, type
->fields (),
9681 type
->num_fields () * sizeof (struct field
));
9682 type
->set_fields (new_fields
);
9683 type
->set_num_fields (type
->num_fields () + 1);
9685 /* Install the discriminant at index 0 in the union. */
9686 type
->field (0) = *disr_field
;
9687 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9688 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9690 /* We need a way to find the correct discriminant given a
9691 variant name. For convenience we build a map here. */
9692 struct type
*enum_type
= disr_field
->type ();
9693 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9694 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9696 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9699 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9700 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9704 int n_fields
= type
->num_fields ();
9705 /* We don't need a range entry for the discriminant, but we do
9706 need one for every other field, as there is no default
9708 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9711 /* Skip the discriminant here. */
9712 for (int i
= 1; i
< n_fields
; ++i
)
9714 /* Find the final word in the name of this variant's type.
9715 That name can be used to look up the correct
9717 const char *variant_name
9718 = rust_last_path_segment (type
->field (i
).type ()->name ());
9720 auto iter
= discriminant_map
.find (variant_name
);
9721 if (iter
!= discriminant_map
.end ())
9723 ranges
[i
- 1].low
= iter
->second
;
9724 ranges
[i
- 1].high
= iter
->second
;
9727 /* In Rust, each element should have the size of the
9729 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9731 /* Remove the discriminant field, if it exists. */
9732 struct type
*sub_type
= type
->field (i
).type ();
9733 if (sub_type
->num_fields () > 0)
9735 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9736 sub_type
->set_fields (sub_type
->fields () + 1);
9738 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9740 (rust_fully_qualify (&objfile
->objfile_obstack
,
9741 type
->name (), variant_name
));
9744 /* Indicate that this is a variant type. */
9745 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9746 gdb::array_view
<discriminant_range
> (ranges
,
9751 /* Rewrite some Rust unions to be structures with variants parts. */
9754 rust_union_quirks (struct dwarf2_cu
*cu
)
9756 gdb_assert (cu
->language
== language_rust
);
9757 for (type
*type_
: cu
->rust_unions
)
9758 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9759 /* We don't need this any more. */
9760 cu
->rust_unions
.clear ();
9765 type_unit_group_unshareable
*
9766 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9768 auto iter
= this->m_type_units
.find (tu_group
);
9769 if (iter
!= this->m_type_units
.end ())
9770 return iter
->second
.get ();
9772 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9773 type_unit_group_unshareable
*result
= uniq
.get ();
9774 this->m_type_units
[tu_group
] = std::move (uniq
);
9779 dwarf2_per_objfile::get_type_for_signatured_type
9780 (signatured_type
*sig_type
) const
9782 auto iter
= this->m_type_map
.find (sig_type
);
9783 if (iter
== this->m_type_map
.end ())
9786 return iter
->second
;
9789 void dwarf2_per_objfile::set_type_for_signatured_type
9790 (signatured_type
*sig_type
, struct type
*type
)
9792 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9794 this->m_type_map
[sig_type
] = type
;
9797 /* A helper function for computing the list of all symbol tables
9798 included by PER_CU. */
9801 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9802 htab_t all_children
, htab_t all_type_symtabs
,
9803 dwarf2_per_cu_data
*per_cu
,
9804 dwarf2_per_objfile
*per_objfile
,
9805 struct compunit_symtab
*immediate_parent
)
9807 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9810 /* This inclusion and its children have been processed. */
9816 /* Only add a CU if it has a symbol table. */
9817 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9820 /* If this is a type unit only add its symbol table if we haven't
9821 seen it yet (type unit per_cu's can share symtabs). */
9822 if (per_cu
->is_debug_types
)
9824 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9828 result
->push_back (cust
);
9829 if (cust
->user
== NULL
)
9830 cust
->user
= immediate_parent
;
9835 result
->push_back (cust
);
9836 if (cust
->user
== NULL
)
9837 cust
->user
= immediate_parent
;
9841 if (!per_cu
->imported_symtabs_empty ())
9842 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9844 recursively_compute_inclusions (result
, all_children
,
9845 all_type_symtabs
, ptr
, per_objfile
,
9850 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9854 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9855 dwarf2_per_objfile
*per_objfile
)
9857 gdb_assert (! per_cu
->is_debug_types
);
9859 if (!per_cu
->imported_symtabs_empty ())
9862 std::vector
<compunit_symtab
*> result_symtabs
;
9863 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9865 /* If we don't have a symtab, we can just skip this case. */
9869 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9871 NULL
, xcalloc
, xfree
));
9872 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9874 NULL
, xcalloc
, xfree
));
9876 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9878 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9879 all_type_symtabs
.get (), ptr
,
9883 /* Now we have a transitive closure of all the included symtabs. */
9884 len
= result_symtabs
.size ();
9886 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9887 struct compunit_symtab
*, len
+ 1);
9888 memcpy (cust
->includes
, result_symtabs
.data (),
9889 len
* sizeof (compunit_symtab
*));
9890 cust
->includes
[len
] = NULL
;
9894 /* Compute the 'includes' field for the symtabs of all the CUs we just
9898 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9900 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9902 if (! iter
->is_debug_types
)
9903 compute_compunit_symtab_includes (iter
, per_objfile
);
9906 per_objfile
->per_bfd
->just_read_cus
.clear ();
9909 /* Generate full symbol information for CU, whose DIEs have
9910 already been loaded into memory. */
9913 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9915 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9916 struct objfile
*objfile
= per_objfile
->objfile
;
9917 struct gdbarch
*gdbarch
= objfile
->arch ();
9918 CORE_ADDR lowpc
, highpc
;
9919 struct compunit_symtab
*cust
;
9921 struct block
*static_block
;
9924 baseaddr
= objfile
->text_section_offset ();
9926 /* Clear the list here in case something was left over. */
9927 cu
->method_list
.clear ();
9929 cu
->language
= pretend_language
;
9930 cu
->language_defn
= language_def (cu
->language
);
9932 /* Do line number decoding in read_file_scope () */
9933 process_die (cu
->dies
, cu
);
9935 /* For now fudge the Go package. */
9936 if (cu
->language
== language_go
)
9937 fixup_go_packaging (cu
);
9939 /* Now that we have processed all the DIEs in the CU, all the types
9940 should be complete, and it should now be safe to compute all of the
9942 compute_delayed_physnames (cu
);
9944 if (cu
->language
== language_rust
)
9945 rust_union_quirks (cu
);
9947 /* Some compilers don't define a DW_AT_high_pc attribute for the
9948 compilation unit. If the DW_AT_high_pc is missing, synthesize
9949 it, by scanning the DIE's below the compilation unit. */
9950 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9952 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9953 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9955 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9956 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9957 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9958 addrmap to help ensure it has an accurate map of pc values belonging to
9960 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9962 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9963 SECT_OFF_TEXT (objfile
),
9968 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9970 /* Set symtab language to language from DW_AT_language. If the
9971 compilation is from a C file generated by language preprocessors, do
9972 not set the language if it was already deduced by start_subfile. */
9973 if (!(cu
->language
== language_c
9974 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9975 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9977 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9978 produce DW_AT_location with location lists but it can be possibly
9979 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9980 there were bugs in prologue debug info, fixed later in GCC-4.5
9981 by "unwind info for epilogues" patch (which is not directly related).
9983 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9984 needed, it would be wrong due to missing DW_AT_producer there.
9986 Still one can confuse GDB by using non-standard GCC compilation
9987 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9989 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9990 cust
->locations_valid
= 1;
9992 if (gcc_4_minor
>= 5)
9993 cust
->epilogue_unwind_valid
= 1;
9995 cust
->call_site_htab
= cu
->call_site_htab
;
9998 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10000 /* Push it for inclusion processing later. */
10001 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
10003 /* Not needed any more. */
10004 cu
->reset_builder ();
10007 /* Generate full symbol information for type unit CU, whose DIEs have
10008 already been loaded into memory. */
10011 process_full_type_unit (dwarf2_cu
*cu
,
10012 enum language pretend_language
)
10014 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10015 struct objfile
*objfile
= per_objfile
->objfile
;
10016 struct compunit_symtab
*cust
;
10017 struct signatured_type
*sig_type
;
10019 gdb_assert (cu
->per_cu
->is_debug_types
);
10020 sig_type
= (struct signatured_type
*) cu
->per_cu
;
10022 /* Clear the list here in case something was left over. */
10023 cu
->method_list
.clear ();
10025 cu
->language
= pretend_language
;
10026 cu
->language_defn
= language_def (cu
->language
);
10028 /* The symbol tables are set up in read_type_unit_scope. */
10029 process_die (cu
->dies
, cu
);
10031 /* For now fudge the Go package. */
10032 if (cu
->language
== language_go
)
10033 fixup_go_packaging (cu
);
10035 /* Now that we have processed all the DIEs in the CU, all the types
10036 should be complete, and it should now be safe to compute all of the
10038 compute_delayed_physnames (cu
);
10040 if (cu
->language
== language_rust
)
10041 rust_union_quirks (cu
);
10043 /* TUs share symbol tables.
10044 If this is the first TU to use this symtab, complete the construction
10045 of it with end_expandable_symtab. Otherwise, complete the addition of
10046 this TU's symbols to the existing symtab. */
10047 type_unit_group_unshareable
*tug_unshare
=
10048 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
10049 if (tug_unshare
->compunit_symtab
== NULL
)
10051 buildsym_compunit
*builder
= cu
->get_builder ();
10052 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10053 tug_unshare
->compunit_symtab
= cust
;
10057 /* Set symtab language to language from DW_AT_language. If the
10058 compilation is from a C file generated by language preprocessors,
10059 do not set the language if it was already deduced by
10061 if (!(cu
->language
== language_c
10062 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10063 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10068 cu
->get_builder ()->augment_type_symtab ();
10069 cust
= tug_unshare
->compunit_symtab
;
10072 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10074 /* Not needed any more. */
10075 cu
->reset_builder ();
10078 /* Process an imported unit DIE. */
10081 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10083 struct attribute
*attr
;
10085 /* For now we don't handle imported units in type units. */
10086 if (cu
->per_cu
->is_debug_types
)
10088 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10089 " supported in type units [in module %s]"),
10090 objfile_name (cu
->per_objfile
->objfile
));
10093 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10096 sect_offset sect_off
= attr
->get_ref_die_offset ();
10097 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10098 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10099 dwarf2_per_cu_data
*per_cu
10100 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10102 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10103 into another compilation unit, at root level. Regard this as a hint,
10105 if (die
->parent
&& die
->parent
->parent
== NULL
10106 && per_cu
->unit_type
== DW_UT_compile
10107 && per_cu
->lang
== language_cplus
)
10110 /* If necessary, add it to the queue and load its DIEs. */
10111 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10112 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
10113 false, cu
->language
);
10115 cu
->per_cu
->imported_symtabs_push (per_cu
);
10119 /* RAII object that represents a process_die scope: i.e.,
10120 starts/finishes processing a DIE. */
10121 class process_die_scope
10124 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10125 : m_die (die
), m_cu (cu
)
10127 /* We should only be processing DIEs not already in process. */
10128 gdb_assert (!m_die
->in_process
);
10129 m_die
->in_process
= true;
10132 ~process_die_scope ()
10134 m_die
->in_process
= false;
10136 /* If we're done processing the DIE for the CU that owns the line
10137 header, we don't need the line header anymore. */
10138 if (m_cu
->line_header_die_owner
== m_die
)
10140 delete m_cu
->line_header
;
10141 m_cu
->line_header
= NULL
;
10142 m_cu
->line_header_die_owner
= NULL
;
10151 /* Process a die and its children. */
10154 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10156 process_die_scope
scope (die
, cu
);
10160 case DW_TAG_padding
:
10162 case DW_TAG_compile_unit
:
10163 case DW_TAG_partial_unit
:
10164 read_file_scope (die
, cu
);
10166 case DW_TAG_type_unit
:
10167 read_type_unit_scope (die
, cu
);
10169 case DW_TAG_subprogram
:
10170 /* Nested subprograms in Fortran get a prefix. */
10171 if (cu
->language
== language_fortran
10172 && die
->parent
!= NULL
10173 && die
->parent
->tag
== DW_TAG_subprogram
)
10174 cu
->processing_has_namespace_info
= true;
10175 /* Fall through. */
10176 case DW_TAG_inlined_subroutine
:
10177 read_func_scope (die
, cu
);
10179 case DW_TAG_lexical_block
:
10180 case DW_TAG_try_block
:
10181 case DW_TAG_catch_block
:
10182 read_lexical_block_scope (die
, cu
);
10184 case DW_TAG_call_site
:
10185 case DW_TAG_GNU_call_site
:
10186 read_call_site_scope (die
, cu
);
10188 case DW_TAG_class_type
:
10189 case DW_TAG_interface_type
:
10190 case DW_TAG_structure_type
:
10191 case DW_TAG_union_type
:
10192 process_structure_scope (die
, cu
);
10194 case DW_TAG_enumeration_type
:
10195 process_enumeration_scope (die
, cu
);
10198 /* These dies have a type, but processing them does not create
10199 a symbol or recurse to process the children. Therefore we can
10200 read them on-demand through read_type_die. */
10201 case DW_TAG_subroutine_type
:
10202 case DW_TAG_set_type
:
10203 case DW_TAG_array_type
:
10204 case DW_TAG_pointer_type
:
10205 case DW_TAG_ptr_to_member_type
:
10206 case DW_TAG_reference_type
:
10207 case DW_TAG_rvalue_reference_type
:
10208 case DW_TAG_string_type
:
10211 case DW_TAG_base_type
:
10212 case DW_TAG_subrange_type
:
10213 case DW_TAG_typedef
:
10214 /* Add a typedef symbol for the type definition, if it has a
10216 new_symbol (die
, read_type_die (die
, cu
), cu
);
10218 case DW_TAG_common_block
:
10219 read_common_block (die
, cu
);
10221 case DW_TAG_common_inclusion
:
10223 case DW_TAG_namespace
:
10224 cu
->processing_has_namespace_info
= true;
10225 read_namespace (die
, cu
);
10227 case DW_TAG_module
:
10228 cu
->processing_has_namespace_info
= true;
10229 read_module (die
, cu
);
10231 case DW_TAG_imported_declaration
:
10232 cu
->processing_has_namespace_info
= true;
10233 if (read_namespace_alias (die
, cu
))
10235 /* The declaration is not a global namespace alias. */
10236 /* Fall through. */
10237 case DW_TAG_imported_module
:
10238 cu
->processing_has_namespace_info
= true;
10239 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10240 || cu
->language
!= language_fortran
))
10241 complaint (_("Tag '%s' has unexpected children"),
10242 dwarf_tag_name (die
->tag
));
10243 read_import_statement (die
, cu
);
10246 case DW_TAG_imported_unit
:
10247 process_imported_unit_die (die
, cu
);
10250 case DW_TAG_variable
:
10251 read_variable (die
, cu
);
10255 new_symbol (die
, NULL
, cu
);
10260 /* DWARF name computation. */
10262 /* A helper function for dwarf2_compute_name which determines whether DIE
10263 needs to have the name of the scope prepended to the name listed in the
10267 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10269 struct attribute
*attr
;
10273 case DW_TAG_namespace
:
10274 case DW_TAG_typedef
:
10275 case DW_TAG_class_type
:
10276 case DW_TAG_interface_type
:
10277 case DW_TAG_structure_type
:
10278 case DW_TAG_union_type
:
10279 case DW_TAG_enumeration_type
:
10280 case DW_TAG_enumerator
:
10281 case DW_TAG_subprogram
:
10282 case DW_TAG_inlined_subroutine
:
10283 case DW_TAG_member
:
10284 case DW_TAG_imported_declaration
:
10287 case DW_TAG_variable
:
10288 case DW_TAG_constant
:
10289 /* We only need to prefix "globally" visible variables. These include
10290 any variable marked with DW_AT_external or any variable that
10291 lives in a namespace. [Variables in anonymous namespaces
10292 require prefixing, but they are not DW_AT_external.] */
10294 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10296 struct dwarf2_cu
*spec_cu
= cu
;
10298 return die_needs_namespace (die_specification (die
, &spec_cu
),
10302 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10303 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10304 && die
->parent
->tag
!= DW_TAG_module
)
10306 /* A variable in a lexical block of some kind does not need a
10307 namespace, even though in C++ such variables may be external
10308 and have a mangled name. */
10309 if (die
->parent
->tag
== DW_TAG_lexical_block
10310 || die
->parent
->tag
== DW_TAG_try_block
10311 || die
->parent
->tag
== DW_TAG_catch_block
10312 || die
->parent
->tag
== DW_TAG_subprogram
)
10321 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10322 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10323 defined for the given DIE. */
10325 static struct attribute
*
10326 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10328 struct attribute
*attr
;
10330 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10332 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10337 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10338 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10339 defined for the given DIE. */
10341 static const char *
10342 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10344 const char *linkage_name
;
10346 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10347 if (linkage_name
== NULL
)
10348 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10350 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10351 See https://github.com/rust-lang/rust/issues/32925. */
10352 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10353 && strchr (linkage_name
, '{') != NULL
)
10354 linkage_name
= NULL
;
10356 return linkage_name
;
10359 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10360 compute the physname for the object, which include a method's:
10361 - formal parameters (C++),
10362 - receiver type (Go),
10364 The term "physname" is a bit confusing.
10365 For C++, for example, it is the demangled name.
10366 For Go, for example, it's the mangled name.
10368 For Ada, return the DIE's linkage name rather than the fully qualified
10369 name. PHYSNAME is ignored..
10371 The result is allocated on the objfile->per_bfd's obstack and
10374 static const char *
10375 dwarf2_compute_name (const char *name
,
10376 struct die_info
*die
, struct dwarf2_cu
*cu
,
10379 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10382 name
= dwarf2_name (die
, cu
);
10384 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10385 but otherwise compute it by typename_concat inside GDB.
10386 FIXME: Actually this is not really true, or at least not always true.
10387 It's all very confusing. compute_and_set_names doesn't try to demangle
10388 Fortran names because there is no mangling standard. So new_symbol
10389 will set the demangled name to the result of dwarf2_full_name, and it is
10390 the demangled name that GDB uses if it exists. */
10391 if (cu
->language
== language_ada
10392 || (cu
->language
== language_fortran
&& physname
))
10394 /* For Ada unit, we prefer the linkage name over the name, as
10395 the former contains the exported name, which the user expects
10396 to be able to reference. Ideally, we want the user to be able
10397 to reference this entity using either natural or linkage name,
10398 but we haven't started looking at this enhancement yet. */
10399 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10401 if (linkage_name
!= NULL
)
10402 return linkage_name
;
10405 /* These are the only languages we know how to qualify names in. */
10407 && (cu
->language
== language_cplus
10408 || cu
->language
== language_fortran
|| cu
->language
== language_d
10409 || cu
->language
== language_rust
))
10411 if (die_needs_namespace (die
, cu
))
10413 const char *prefix
;
10414 const char *canonical_name
= NULL
;
10418 prefix
= determine_prefix (die
, cu
);
10419 if (*prefix
!= '\0')
10421 gdb::unique_xmalloc_ptr
<char> prefixed_name
10422 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10424 buf
.puts (prefixed_name
.get ());
10429 /* Template parameters may be specified in the DIE's DW_AT_name, or
10430 as children with DW_TAG_template_type_param or
10431 DW_TAG_value_type_param. If the latter, add them to the name
10432 here. If the name already has template parameters, then
10433 skip this step; some versions of GCC emit both, and
10434 it is more efficient to use the pre-computed name.
10436 Something to keep in mind about this process: it is very
10437 unlikely, or in some cases downright impossible, to produce
10438 something that will match the mangled name of a function.
10439 If the definition of the function has the same debug info,
10440 we should be able to match up with it anyway. But fallbacks
10441 using the minimal symbol, for instance to find a method
10442 implemented in a stripped copy of libstdc++, will not work.
10443 If we do not have debug info for the definition, we will have to
10444 match them up some other way.
10446 When we do name matching there is a related problem with function
10447 templates; two instantiated function templates are allowed to
10448 differ only by their return types, which we do not add here. */
10450 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10452 struct attribute
*attr
;
10453 struct die_info
*child
;
10456 die
->building_fullname
= 1;
10458 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10462 const gdb_byte
*bytes
;
10463 struct dwarf2_locexpr_baton
*baton
;
10466 if (child
->tag
!= DW_TAG_template_type_param
10467 && child
->tag
!= DW_TAG_template_value_param
)
10478 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10481 complaint (_("template parameter missing DW_AT_type"));
10482 buf
.puts ("UNKNOWN_TYPE");
10485 type
= die_type (child
, cu
);
10487 if (child
->tag
== DW_TAG_template_type_param
)
10489 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10490 &type_print_raw_options
);
10494 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10497 complaint (_("template parameter missing "
10498 "DW_AT_const_value"));
10499 buf
.puts ("UNKNOWN_VALUE");
10503 dwarf2_const_value_attr (attr
, type
, name
,
10504 &cu
->comp_unit_obstack
, cu
,
10505 &value
, &bytes
, &baton
);
10507 if (type
->has_no_signedness ())
10508 /* GDB prints characters as NUMBER 'CHAR'. If that's
10509 changed, this can use value_print instead. */
10510 c_printchar (value
, type
, &buf
);
10513 struct value_print_options opts
;
10516 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10520 baton
->per_objfile
);
10521 else if (bytes
!= NULL
)
10523 v
= allocate_value (type
);
10524 memcpy (value_contents_writeable (v
), bytes
,
10525 TYPE_LENGTH (type
));
10528 v
= value_from_longest (type
, value
);
10530 /* Specify decimal so that we do not depend on
10532 get_formatted_print_options (&opts
, 'd');
10534 value_print (v
, &buf
, &opts
);
10539 die
->building_fullname
= 0;
10543 /* Close the argument list, with a space if necessary
10544 (nested templates). */
10545 if (!buf
.empty () && buf
.string ().back () == '>')
10552 /* For C++ methods, append formal parameter type
10553 information, if PHYSNAME. */
10555 if (physname
&& die
->tag
== DW_TAG_subprogram
10556 && cu
->language
== language_cplus
)
10558 struct type
*type
= read_type_die (die
, cu
);
10560 c_type_print_args (type
, &buf
, 1, cu
->language
,
10561 &type_print_raw_options
);
10563 if (cu
->language
== language_cplus
)
10565 /* Assume that an artificial first parameter is
10566 "this", but do not crash if it is not. RealView
10567 marks unnamed (and thus unused) parameters as
10568 artificial; there is no way to differentiate
10570 if (type
->num_fields () > 0
10571 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10572 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10573 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10574 buf
.puts (" const");
10578 const std::string
&intermediate_name
= buf
.string ();
10580 if (cu
->language
== language_cplus
)
10582 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10585 /* If we only computed INTERMEDIATE_NAME, or if
10586 INTERMEDIATE_NAME is already canonical, then we need to
10588 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10589 name
= objfile
->intern (intermediate_name
);
10591 name
= canonical_name
;
10598 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10599 If scope qualifiers are appropriate they will be added. The result
10600 will be allocated on the storage_obstack, or NULL if the DIE does
10601 not have a name. NAME may either be from a previous call to
10602 dwarf2_name or NULL.
10604 The output string will be canonicalized (if C++). */
10606 static const char *
10607 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10609 return dwarf2_compute_name (name
, die
, cu
, 0);
10612 /* Construct a physname for the given DIE in CU. NAME may either be
10613 from a previous call to dwarf2_name or NULL. The result will be
10614 allocated on the objfile_objstack or NULL if the DIE does not have a
10617 The output string will be canonicalized (if C++). */
10619 static const char *
10620 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10622 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10623 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10626 /* In this case dwarf2_compute_name is just a shortcut not building anything
10628 if (!die_needs_namespace (die
, cu
))
10629 return dwarf2_compute_name (name
, die
, cu
, 1);
10631 if (cu
->language
!= language_rust
)
10632 mangled
= dw2_linkage_name (die
, cu
);
10634 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10636 gdb::unique_xmalloc_ptr
<char> demangled
;
10637 if (mangled
!= NULL
)
10640 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10642 /* Do nothing (do not demangle the symbol name). */
10646 /* Use DMGL_RET_DROP for C++ template functions to suppress
10647 their return type. It is easier for GDB users to search
10648 for such functions as `name(params)' than `long name(params)'.
10649 In such case the minimal symbol names do not match the full
10650 symbol names but for template functions there is never a need
10651 to look up their definition from their declaration so
10652 the only disadvantage remains the minimal symbol variant
10653 `long name(params)' does not have the proper inferior type. */
10654 demangled
.reset (gdb_demangle (mangled
,
10655 (DMGL_PARAMS
| DMGL_ANSI
10656 | DMGL_RET_DROP
)));
10659 canon
= demangled
.get ();
10667 if (canon
== NULL
|| check_physname
)
10669 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10671 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10673 /* It may not mean a bug in GDB. The compiler could also
10674 compute DW_AT_linkage_name incorrectly. But in such case
10675 GDB would need to be bug-to-bug compatible. */
10677 complaint (_("Computed physname <%s> does not match demangled <%s> "
10678 "(from linkage <%s>) - DIE at %s [in module %s]"),
10679 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10680 objfile_name (objfile
));
10682 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10683 is available here - over computed PHYSNAME. It is safer
10684 against both buggy GDB and buggy compilers. */
10698 retval
= objfile
->intern (retval
);
10703 /* Inspect DIE in CU for a namespace alias. If one exists, record
10704 a new symbol for it.
10706 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10709 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10711 struct attribute
*attr
;
10713 /* If the die does not have a name, this is not a namespace
10715 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10719 struct die_info
*d
= die
;
10720 struct dwarf2_cu
*imported_cu
= cu
;
10722 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10723 keep inspecting DIEs until we hit the underlying import. */
10724 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10725 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10727 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10731 d
= follow_die_ref (d
, attr
, &imported_cu
);
10732 if (d
->tag
!= DW_TAG_imported_declaration
)
10736 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10738 complaint (_("DIE at %s has too many recursively imported "
10739 "declarations"), sect_offset_str (d
->sect_off
));
10746 sect_offset sect_off
= attr
->get_ref_die_offset ();
10748 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10749 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10751 /* This declaration is a global namespace alias. Add
10752 a symbol for it whose type is the aliased namespace. */
10753 new_symbol (die
, type
, cu
);
10762 /* Return the using directives repository (global or local?) to use in the
10763 current context for CU.
10765 For Ada, imported declarations can materialize renamings, which *may* be
10766 global. However it is impossible (for now?) in DWARF to distinguish
10767 "external" imported declarations and "static" ones. As all imported
10768 declarations seem to be static in all other languages, make them all CU-wide
10769 global only in Ada. */
10771 static struct using_direct
**
10772 using_directives (struct dwarf2_cu
*cu
)
10774 if (cu
->language
== language_ada
10775 && cu
->get_builder ()->outermost_context_p ())
10776 return cu
->get_builder ()->get_global_using_directives ();
10778 return cu
->get_builder ()->get_local_using_directives ();
10781 /* Read the import statement specified by the given die and record it. */
10784 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10786 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10787 struct attribute
*import_attr
;
10788 struct die_info
*imported_die
, *child_die
;
10789 struct dwarf2_cu
*imported_cu
;
10790 const char *imported_name
;
10791 const char *imported_name_prefix
;
10792 const char *canonical_name
;
10793 const char *import_alias
;
10794 const char *imported_declaration
= NULL
;
10795 const char *import_prefix
;
10796 std::vector
<const char *> excludes
;
10798 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10799 if (import_attr
== NULL
)
10801 complaint (_("Tag '%s' has no DW_AT_import"),
10802 dwarf_tag_name (die
->tag
));
10807 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10808 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10809 if (imported_name
== NULL
)
10811 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10813 The import in the following code:
10827 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10828 <52> DW_AT_decl_file : 1
10829 <53> DW_AT_decl_line : 6
10830 <54> DW_AT_import : <0x75>
10831 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10832 <59> DW_AT_name : B
10833 <5b> DW_AT_decl_file : 1
10834 <5c> DW_AT_decl_line : 2
10835 <5d> DW_AT_type : <0x6e>
10837 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10838 <76> DW_AT_byte_size : 4
10839 <77> DW_AT_encoding : 5 (signed)
10841 imports the wrong die ( 0x75 instead of 0x58 ).
10842 This case will be ignored until the gcc bug is fixed. */
10846 /* Figure out the local name after import. */
10847 import_alias
= dwarf2_name (die
, cu
);
10849 /* Figure out where the statement is being imported to. */
10850 import_prefix
= determine_prefix (die
, cu
);
10852 /* Figure out what the scope of the imported die is and prepend it
10853 to the name of the imported die. */
10854 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10856 if (imported_die
->tag
!= DW_TAG_namespace
10857 && imported_die
->tag
!= DW_TAG_module
)
10859 imported_declaration
= imported_name
;
10860 canonical_name
= imported_name_prefix
;
10862 else if (strlen (imported_name_prefix
) > 0)
10863 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10864 imported_name_prefix
,
10865 (cu
->language
== language_d
? "." : "::"),
10866 imported_name
, (char *) NULL
);
10868 canonical_name
= imported_name
;
10870 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10871 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10872 child_die
= child_die
->sibling
)
10874 /* DWARF-4: A Fortran use statement with a “rename list” may be
10875 represented by an imported module entry with an import attribute
10876 referring to the module and owned entries corresponding to those
10877 entities that are renamed as part of being imported. */
10879 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10881 complaint (_("child DW_TAG_imported_declaration expected "
10882 "- DIE at %s [in module %s]"),
10883 sect_offset_str (child_die
->sect_off
),
10884 objfile_name (objfile
));
10888 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10889 if (import_attr
== NULL
)
10891 complaint (_("Tag '%s' has no DW_AT_import"),
10892 dwarf_tag_name (child_die
->tag
));
10897 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10899 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10900 if (imported_name
== NULL
)
10902 complaint (_("child DW_TAG_imported_declaration has unknown "
10903 "imported name - DIE at %s [in module %s]"),
10904 sect_offset_str (child_die
->sect_off
),
10905 objfile_name (objfile
));
10909 excludes
.push_back (imported_name
);
10911 process_die (child_die
, cu
);
10914 add_using_directive (using_directives (cu
),
10918 imported_declaration
,
10921 &objfile
->objfile_obstack
);
10924 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10925 types, but gives them a size of zero. Starting with version 14,
10926 ICC is compatible with GCC. */
10929 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10931 if (!cu
->checked_producer
)
10932 check_producer (cu
);
10934 return cu
->producer_is_icc_lt_14
;
10937 /* ICC generates a DW_AT_type for C void functions. This was observed on
10938 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10939 which says that void functions should not have a DW_AT_type. */
10942 producer_is_icc (struct dwarf2_cu
*cu
)
10944 if (!cu
->checked_producer
)
10945 check_producer (cu
);
10947 return cu
->producer_is_icc
;
10950 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10951 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10952 this, it was first present in GCC release 4.3.0. */
10955 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10957 if (!cu
->checked_producer
)
10958 check_producer (cu
);
10960 return cu
->producer_is_gcc_lt_4_3
;
10963 static file_and_directory
10964 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10966 file_and_directory res
;
10968 /* Find the filename. Do not use dwarf2_name here, since the filename
10969 is not a source language identifier. */
10970 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10971 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10973 if (res
.comp_dir
== NULL
10974 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10975 && IS_ABSOLUTE_PATH (res
.name
))
10977 res
.comp_dir_storage
= ldirname (res
.name
);
10978 if (!res
.comp_dir_storage
.empty ())
10979 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10981 if (res
.comp_dir
!= NULL
)
10983 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10984 directory, get rid of it. */
10985 const char *cp
= strchr (res
.comp_dir
, ':');
10987 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10988 res
.comp_dir
= cp
+ 1;
10991 if (res
.name
== NULL
)
10992 res
.name
= "<unknown>";
10997 /* Handle DW_AT_stmt_list for a compilation unit.
10998 DIE is the DW_TAG_compile_unit die for CU.
10999 COMP_DIR is the compilation directory. LOWPC is passed to
11000 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11003 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11004 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11006 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11007 struct attribute
*attr
;
11008 struct line_header line_header_local
;
11009 hashval_t line_header_local_hash
;
11011 int decode_mapping
;
11013 gdb_assert (! cu
->per_cu
->is_debug_types
);
11015 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11016 if (attr
== NULL
|| !attr
->form_is_unsigned ())
11019 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11021 /* The line header hash table is only created if needed (it exists to
11022 prevent redundant reading of the line table for partial_units).
11023 If we're given a partial_unit, we'll need it. If we're given a
11024 compile_unit, then use the line header hash table if it's already
11025 created, but don't create one just yet. */
11027 if (per_objfile
->line_header_hash
== NULL
11028 && die
->tag
== DW_TAG_partial_unit
)
11030 per_objfile
->line_header_hash
11031 .reset (htab_create_alloc (127, line_header_hash_voidp
,
11032 line_header_eq_voidp
,
11033 free_line_header_voidp
,
11037 line_header_local
.sect_off
= line_offset
;
11038 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11039 line_header_local_hash
= line_header_hash (&line_header_local
);
11040 if (per_objfile
->line_header_hash
!= NULL
)
11042 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11043 &line_header_local
,
11044 line_header_local_hash
, NO_INSERT
);
11046 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11047 is not present in *SLOT (since if there is something in *SLOT then
11048 it will be for a partial_unit). */
11049 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11051 gdb_assert (*slot
!= NULL
);
11052 cu
->line_header
= (struct line_header
*) *slot
;
11057 /* dwarf_decode_line_header does not yet provide sufficient information.
11058 We always have to call also dwarf_decode_lines for it. */
11059 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11063 cu
->line_header
= lh
.release ();
11064 cu
->line_header_die_owner
= die
;
11066 if (per_objfile
->line_header_hash
== NULL
)
11070 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11071 &line_header_local
,
11072 line_header_local_hash
, INSERT
);
11073 gdb_assert (slot
!= NULL
);
11075 if (slot
!= NULL
&& *slot
== NULL
)
11077 /* This newly decoded line number information unit will be owned
11078 by line_header_hash hash table. */
11079 *slot
= cu
->line_header
;
11080 cu
->line_header_die_owner
= NULL
;
11084 /* We cannot free any current entry in (*slot) as that struct line_header
11085 may be already used by multiple CUs. Create only temporary decoded
11086 line_header for this CU - it may happen at most once for each line
11087 number information unit. And if we're not using line_header_hash
11088 then this is what we want as well. */
11089 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11091 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11092 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11097 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11100 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11102 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11103 struct objfile
*objfile
= per_objfile
->objfile
;
11104 struct gdbarch
*gdbarch
= objfile
->arch ();
11105 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11106 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11107 struct attribute
*attr
;
11108 struct die_info
*child_die
;
11109 CORE_ADDR baseaddr
;
11111 prepare_one_comp_unit (cu
, die
, cu
->language
);
11112 baseaddr
= objfile
->text_section_offset ();
11114 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11116 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11117 from finish_block. */
11118 if (lowpc
== ((CORE_ADDR
) -1))
11120 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11122 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11124 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11125 standardised yet. As a workaround for the language detection we fall
11126 back to the DW_AT_producer string. */
11127 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11128 cu
->language
= language_opencl
;
11130 /* Similar hack for Go. */
11131 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11132 set_cu_language (DW_LANG_Go
, cu
);
11134 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11136 /* Decode line number information if present. We do this before
11137 processing child DIEs, so that the line header table is available
11138 for DW_AT_decl_file. */
11139 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11141 /* Process all dies in compilation unit. */
11142 if (die
->child
!= NULL
)
11144 child_die
= die
->child
;
11145 while (child_die
&& child_die
->tag
)
11147 process_die (child_die
, cu
);
11148 child_die
= child_die
->sibling
;
11152 /* Decode macro information, if present. Dwarf 2 macro information
11153 refers to information in the line number info statement program
11154 header, so we can only read it if we've read the header
11156 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11158 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11159 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11161 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11162 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11164 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
11168 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11169 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11171 unsigned int macro_offset
= attr
->as_unsigned ();
11173 dwarf_decode_macros (cu
, macro_offset
, 0);
11179 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11181 struct type_unit_group
*tu_group
;
11183 struct attribute
*attr
;
11185 struct signatured_type
*sig_type
;
11187 gdb_assert (per_cu
->is_debug_types
);
11188 sig_type
= (struct signatured_type
*) per_cu
;
11190 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11192 /* If we're using .gdb_index (includes -readnow) then
11193 per_cu->type_unit_group may not have been set up yet. */
11194 if (sig_type
->type_unit_group
== NULL
)
11195 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11196 tu_group
= sig_type
->type_unit_group
;
11198 /* If we've already processed this stmt_list there's no real need to
11199 do it again, we could fake it and just recreate the part we need
11200 (file name,index -> symtab mapping). If data shows this optimization
11201 is useful we can do it then. */
11202 type_unit_group_unshareable
*tug_unshare
11203 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11204 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11206 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11209 if (attr
!= NULL
&& attr
->form_is_unsigned ())
11211 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11212 lh
= dwarf_decode_line_header (line_offset
, this);
11217 start_symtab ("", NULL
, 0);
11220 gdb_assert (tug_unshare
->symtabs
== NULL
);
11221 gdb_assert (m_builder
== nullptr);
11222 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11223 m_builder
.reset (new struct buildsym_compunit
11224 (COMPUNIT_OBJFILE (cust
), "",
11225 COMPUNIT_DIRNAME (cust
),
11226 compunit_language (cust
),
11228 list_in_scope
= get_builder ()->get_file_symbols ();
11233 line_header
= lh
.release ();
11234 line_header_die_owner
= die
;
11238 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11240 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11241 still initializing it, and our caller (a few levels up)
11242 process_full_type_unit still needs to know if this is the first
11245 tug_unshare
->symtabs
11246 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11247 struct symtab
*, line_header
->file_names_size ());
11249 auto &file_names
= line_header
->file_names ();
11250 for (i
= 0; i
< file_names
.size (); ++i
)
11252 file_entry
&fe
= file_names
[i
];
11253 dwarf2_start_subfile (this, fe
.name
,
11254 fe
.include_dir (line_header
));
11255 buildsym_compunit
*b
= get_builder ();
11256 if (b
->get_current_subfile ()->symtab
== NULL
)
11258 /* NOTE: start_subfile will recognize when it's been
11259 passed a file it has already seen. So we can't
11260 assume there's a simple mapping from
11261 cu->line_header->file_names to subfiles, plus
11262 cu->line_header->file_names may contain dups. */
11263 b
->get_current_subfile ()->symtab
11264 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11267 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11268 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11273 gdb_assert (m_builder
== nullptr);
11274 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11275 m_builder
.reset (new struct buildsym_compunit
11276 (COMPUNIT_OBJFILE (cust
), "",
11277 COMPUNIT_DIRNAME (cust
),
11278 compunit_language (cust
),
11280 list_in_scope
= get_builder ()->get_file_symbols ();
11282 auto &file_names
= line_header
->file_names ();
11283 for (i
= 0; i
< file_names
.size (); ++i
)
11285 file_entry
&fe
= file_names
[i
];
11286 fe
.symtab
= tug_unshare
->symtabs
[i
];
11290 /* The main symtab is allocated last. Type units don't have DW_AT_name
11291 so they don't have a "real" (so to speak) symtab anyway.
11292 There is later code that will assign the main symtab to all symbols
11293 that don't have one. We need to handle the case of a symbol with a
11294 missing symtab (DW_AT_decl_file) anyway. */
11297 /* Process DW_TAG_type_unit.
11298 For TUs we want to skip the first top level sibling if it's not the
11299 actual type being defined by this TU. In this case the first top
11300 level sibling is there to provide context only. */
11303 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11305 struct die_info
*child_die
;
11307 prepare_one_comp_unit (cu
, die
, language_minimal
);
11309 /* Initialize (or reinitialize) the machinery for building symtabs.
11310 We do this before processing child DIEs, so that the line header table
11311 is available for DW_AT_decl_file. */
11312 cu
->setup_type_unit_groups (die
);
11314 if (die
->child
!= NULL
)
11316 child_die
= die
->child
;
11317 while (child_die
&& child_die
->tag
)
11319 process_die (child_die
, cu
);
11320 child_die
= child_die
->sibling
;
11327 http://gcc.gnu.org/wiki/DebugFission
11328 http://gcc.gnu.org/wiki/DebugFissionDWP
11330 To simplify handling of both DWO files ("object" files with the DWARF info)
11331 and DWP files (a file with the DWOs packaged up into one file), we treat
11332 DWP files as having a collection of virtual DWO files. */
11335 hash_dwo_file (const void *item
)
11337 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11340 hash
= htab_hash_string (dwo_file
->dwo_name
);
11341 if (dwo_file
->comp_dir
!= NULL
)
11342 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11347 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11349 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11350 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11352 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11354 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11355 return lhs
->comp_dir
== rhs
->comp_dir
;
11356 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11359 /* Allocate a hash table for DWO files. */
11362 allocate_dwo_file_hash_table ()
11364 auto delete_dwo_file
= [] (void *item
)
11366 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11371 return htab_up (htab_create_alloc (41,
11378 /* Lookup DWO file DWO_NAME. */
11381 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11382 const char *dwo_name
,
11383 const char *comp_dir
)
11385 struct dwo_file find_entry
;
11388 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11389 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11391 find_entry
.dwo_name
= dwo_name
;
11392 find_entry
.comp_dir
= comp_dir
;
11393 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11400 hash_dwo_unit (const void *item
)
11402 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11404 /* This drops the top 32 bits of the id, but is ok for a hash. */
11405 return dwo_unit
->signature
;
11409 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11411 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11412 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11414 /* The signature is assumed to be unique within the DWO file.
11415 So while object file CU dwo_id's always have the value zero,
11416 that's OK, assuming each object file DWO file has only one CU,
11417 and that's the rule for now. */
11418 return lhs
->signature
== rhs
->signature
;
11421 /* Allocate a hash table for DWO CUs,TUs.
11422 There is one of these tables for each of CUs,TUs for each DWO file. */
11425 allocate_dwo_unit_table ()
11427 /* Start out with a pretty small number.
11428 Generally DWO files contain only one CU and maybe some TUs. */
11429 return htab_up (htab_create_alloc (3,
11432 NULL
, xcalloc
, xfree
));
11435 /* die_reader_func for create_dwo_cu. */
11438 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11439 const gdb_byte
*info_ptr
,
11440 struct die_info
*comp_unit_die
,
11441 struct dwo_file
*dwo_file
,
11442 struct dwo_unit
*dwo_unit
)
11444 struct dwarf2_cu
*cu
= reader
->cu
;
11445 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11446 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11448 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11449 if (!signature
.has_value ())
11451 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11452 " its dwo_id [in module %s]"),
11453 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11457 dwo_unit
->dwo_file
= dwo_file
;
11458 dwo_unit
->signature
= *signature
;
11459 dwo_unit
->section
= section
;
11460 dwo_unit
->sect_off
= sect_off
;
11461 dwo_unit
->length
= cu
->per_cu
->length
;
11463 if (dwarf_read_debug
)
11464 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11465 sect_offset_str (sect_off
),
11466 hex_string (dwo_unit
->signature
));
11469 /* Create the dwo_units for the CUs in a DWO_FILE.
11470 Note: This function processes DWO files only, not DWP files. */
11473 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11474 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11475 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11477 struct objfile
*objfile
= per_objfile
->objfile
;
11478 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11479 const gdb_byte
*info_ptr
, *end_ptr
;
11481 section
.read (objfile
);
11482 info_ptr
= section
.buffer
;
11484 if (info_ptr
== NULL
)
11487 if (dwarf_read_debug
)
11489 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11490 section
.get_name (),
11491 section
.get_file_name ());
11494 end_ptr
= info_ptr
+ section
.size
;
11495 while (info_ptr
< end_ptr
)
11497 struct dwarf2_per_cu_data per_cu
;
11498 struct dwo_unit read_unit
{};
11499 struct dwo_unit
*dwo_unit
;
11501 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11503 memset (&per_cu
, 0, sizeof (per_cu
));
11504 per_cu
.per_bfd
= per_bfd
;
11505 per_cu
.is_debug_types
= 0;
11506 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11507 per_cu
.section
= §ion
;
11509 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11510 if (!reader
.dummy_p
)
11511 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11512 &dwo_file
, &read_unit
);
11513 info_ptr
+= per_cu
.length
;
11515 // If the unit could not be parsed, skip it.
11516 if (read_unit
.dwo_file
== NULL
)
11519 if (cus_htab
== NULL
)
11520 cus_htab
= allocate_dwo_unit_table ();
11522 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11524 *dwo_unit
= read_unit
;
11525 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11526 gdb_assert (slot
!= NULL
);
11529 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11530 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11532 complaint (_("debug cu entry at offset %s is duplicate to"
11533 " the entry at offset %s, signature %s"),
11534 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11535 hex_string (dwo_unit
->signature
));
11537 *slot
= (void *)dwo_unit
;
11541 /* DWP file .debug_{cu,tu}_index section format:
11542 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11543 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11545 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11546 officially standard DWP format was published with DWARF v5 and is called
11547 Version 5. There are no versions 3 or 4.
11551 Both index sections have the same format, and serve to map a 64-bit
11552 signature to a set of section numbers. Each section begins with a header,
11553 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11554 indexes, and a pool of 32-bit section numbers. The index sections will be
11555 aligned at 8-byte boundaries in the file.
11557 The index section header consists of:
11559 V, 32 bit version number
11561 N, 32 bit number of compilation units or type units in the index
11562 M, 32 bit number of slots in the hash table
11564 Numbers are recorded using the byte order of the application binary.
11566 The hash table begins at offset 16 in the section, and consists of an array
11567 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11568 order of the application binary). Unused slots in the hash table are 0.
11569 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11571 The parallel table begins immediately after the hash table
11572 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11573 array of 32-bit indexes (using the byte order of the application binary),
11574 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11575 table contains a 32-bit index into the pool of section numbers. For unused
11576 hash table slots, the corresponding entry in the parallel table will be 0.
11578 The pool of section numbers begins immediately following the hash table
11579 (at offset 16 + 12 * M from the beginning of the section). The pool of
11580 section numbers consists of an array of 32-bit words (using the byte order
11581 of the application binary). Each item in the array is indexed starting
11582 from 0. The hash table entry provides the index of the first section
11583 number in the set. Additional section numbers in the set follow, and the
11584 set is terminated by a 0 entry (section number 0 is not used in ELF).
11586 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11587 section must be the first entry in the set, and the .debug_abbrev.dwo must
11588 be the second entry. Other members of the set may follow in any order.
11592 DWP Versions 2 and 5:
11594 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11595 and the entries in the index tables are now offsets into these sections.
11596 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11599 Index Section Contents:
11601 Hash Table of Signatures dwp_hash_table.hash_table
11602 Parallel Table of Indices dwp_hash_table.unit_table
11603 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11604 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11606 The index section header consists of:
11608 V, 32 bit version number
11609 L, 32 bit number of columns in the table of section offsets
11610 N, 32 bit number of compilation units or type units in the index
11611 M, 32 bit number of slots in the hash table
11613 Numbers are recorded using the byte order of the application binary.
11615 The hash table has the same format as version 1.
11616 The parallel table of indices has the same format as version 1,
11617 except that the entries are origin-1 indices into the table of sections
11618 offsets and the table of section sizes.
11620 The table of offsets begins immediately following the parallel table
11621 (at offset 16 + 12 * M from the beginning of the section). The table is
11622 a two-dimensional array of 32-bit words (using the byte order of the
11623 application binary), with L columns and N+1 rows, in row-major order.
11624 Each row in the array is indexed starting from 0. The first row provides
11625 a key to the remaining rows: each column in this row provides an identifier
11626 for a debug section, and the offsets in the same column of subsequent rows
11627 refer to that section. The section identifiers for Version 2 are:
11629 DW_SECT_INFO 1 .debug_info.dwo
11630 DW_SECT_TYPES 2 .debug_types.dwo
11631 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11632 DW_SECT_LINE 4 .debug_line.dwo
11633 DW_SECT_LOC 5 .debug_loc.dwo
11634 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11635 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11636 DW_SECT_MACRO 8 .debug_macro.dwo
11638 The section identifiers for Version 5 are:
11640 DW_SECT_INFO_V5 1 .debug_info.dwo
11641 DW_SECT_RESERVED_V5 2 --
11642 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11643 DW_SECT_LINE_V5 4 .debug_line.dwo
11644 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11645 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11646 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11647 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11649 The offsets provided by the CU and TU index sections are the base offsets
11650 for the contributions made by each CU or TU to the corresponding section
11651 in the package file. Each CU and TU header contains an abbrev_offset
11652 field, used to find the abbreviations table for that CU or TU within the
11653 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11654 be interpreted as relative to the base offset given in the index section.
11655 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11656 should be interpreted as relative to the base offset for .debug_line.dwo,
11657 and offsets into other debug sections obtained from DWARF attributes should
11658 also be interpreted as relative to the corresponding base offset.
11660 The table of sizes begins immediately following the table of offsets.
11661 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11662 with L columns and N rows, in row-major order. Each row in the array is
11663 indexed starting from 1 (row 0 is shared by the two tables).
11667 Hash table lookup is handled the same in version 1 and 2:
11669 We assume that N and M will not exceed 2^32 - 1.
11670 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11672 Given a 64-bit compilation unit signature or a type signature S, an entry
11673 in the hash table is located as follows:
11675 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11676 the low-order k bits all set to 1.
11678 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11680 3) If the hash table entry at index H matches the signature, use that
11681 entry. If the hash table entry at index H is unused (all zeroes),
11682 terminate the search: the signature is not present in the table.
11684 4) Let H = (H + H') modulo M. Repeat at Step 3.
11686 Because M > N and H' and M are relatively prime, the search is guaranteed
11687 to stop at an unused slot or find the match. */
11689 /* Create a hash table to map DWO IDs to their CU/TU entry in
11690 .debug_{info,types}.dwo in DWP_FILE.
11691 Returns NULL if there isn't one.
11692 Note: This function processes DWP files only, not DWO files. */
11694 static struct dwp_hash_table
*
11695 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11696 struct dwp_file
*dwp_file
, int is_debug_types
)
11698 struct objfile
*objfile
= per_objfile
->objfile
;
11699 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11700 const gdb_byte
*index_ptr
, *index_end
;
11701 struct dwarf2_section_info
*index
;
11702 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11703 struct dwp_hash_table
*htab
;
11705 if (is_debug_types
)
11706 index
= &dwp_file
->sections
.tu_index
;
11708 index
= &dwp_file
->sections
.cu_index
;
11710 if (index
->empty ())
11712 index
->read (objfile
);
11714 index_ptr
= index
->buffer
;
11715 index_end
= index_ptr
+ index
->size
;
11717 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11718 For now it's safe to just read 4 bytes (particularly as it's difficult to
11719 tell if you're dealing with Version 5 before you've read the version). */
11720 version
= read_4_bytes (dbfd
, index_ptr
);
11722 if (version
== 2 || version
== 5)
11723 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11727 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11729 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11732 if (version
!= 1 && version
!= 2 && version
!= 5)
11734 error (_("Dwarf Error: unsupported DWP file version (%s)"
11735 " [in module %s]"),
11736 pulongest (version
), dwp_file
->name
);
11738 if (nr_slots
!= (nr_slots
& -nr_slots
))
11740 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11741 " is not power of 2 [in module %s]"),
11742 pulongest (nr_slots
), dwp_file
->name
);
11745 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11746 htab
->version
= version
;
11747 htab
->nr_columns
= nr_columns
;
11748 htab
->nr_units
= nr_units
;
11749 htab
->nr_slots
= nr_slots
;
11750 htab
->hash_table
= index_ptr
;
11751 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11753 /* Exit early if the table is empty. */
11754 if (nr_slots
== 0 || nr_units
== 0
11755 || (version
== 2 && nr_columns
== 0)
11756 || (version
== 5 && nr_columns
== 0))
11758 /* All must be zero. */
11759 if (nr_slots
!= 0 || nr_units
!= 0
11760 || (version
== 2 && nr_columns
!= 0)
11761 || (version
== 5 && nr_columns
!= 0))
11763 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11764 " all zero [in modules %s]"),
11772 htab
->section_pool
.v1
.indices
=
11773 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11774 /* It's harder to decide whether the section is too small in v1.
11775 V1 is deprecated anyway so we punt. */
11777 else if (version
== 2)
11779 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11780 int *ids
= htab
->section_pool
.v2
.section_ids
;
11781 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11782 /* Reverse map for error checking. */
11783 int ids_seen
[DW_SECT_MAX
+ 1];
11786 if (nr_columns
< 2)
11788 error (_("Dwarf Error: bad DWP hash table, too few columns"
11789 " in section table [in module %s]"),
11792 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11794 error (_("Dwarf Error: bad DWP hash table, too many columns"
11795 " in section table [in module %s]"),
11798 memset (ids
, 255, sizeof_ids
);
11799 memset (ids_seen
, 255, sizeof (ids_seen
));
11800 for (i
= 0; i
< nr_columns
; ++i
)
11802 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11804 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11806 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11807 " in section table [in module %s]"),
11808 id
, dwp_file
->name
);
11810 if (ids_seen
[id
] != -1)
11812 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11813 " id %d in section table [in module %s]"),
11814 id
, dwp_file
->name
);
11819 /* Must have exactly one info or types section. */
11820 if (((ids_seen
[DW_SECT_INFO
] != -1)
11821 + (ids_seen
[DW_SECT_TYPES
] != -1))
11824 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11825 " DWO info/types section [in module %s]"),
11828 /* Must have an abbrev section. */
11829 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11831 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11832 " section [in module %s]"),
11835 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11836 htab
->section_pool
.v2
.sizes
=
11837 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11838 * nr_units
* nr_columns
);
11839 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11840 * nr_units
* nr_columns
))
11843 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11844 " [in module %s]"),
11848 else /* version == 5 */
11850 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11851 int *ids
= htab
->section_pool
.v5
.section_ids
;
11852 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11853 /* Reverse map for error checking. */
11854 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11856 if (nr_columns
< 2)
11858 error (_("Dwarf Error: bad DWP hash table, too few columns"
11859 " in section table [in module %s]"),
11862 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11864 error (_("Dwarf Error: bad DWP hash table, too many columns"
11865 " in section table [in module %s]"),
11868 memset (ids
, 255, sizeof_ids
);
11869 memset (ids_seen
, 255, sizeof (ids_seen
));
11870 for (int i
= 0; i
< nr_columns
; ++i
)
11872 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11874 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11876 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11877 " in section table [in module %s]"),
11878 id
, dwp_file
->name
);
11880 if (ids_seen
[id
] != -1)
11882 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11883 " id %d in section table [in module %s]"),
11884 id
, dwp_file
->name
);
11889 /* Must have seen an info section. */
11890 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11892 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11893 " DWO info/types section [in module %s]"),
11896 /* Must have an abbrev section. */
11897 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11899 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11900 " section [in module %s]"),
11903 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11904 htab
->section_pool
.v5
.sizes
11905 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11906 * nr_units
* nr_columns
);
11907 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11908 * nr_units
* nr_columns
))
11911 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11912 " [in module %s]"),
11920 /* Update SECTIONS with the data from SECTP.
11922 This function is like the other "locate" section routines, but in
11923 this context the sections to read comes from the DWP V1 hash table,
11924 not the full ELF section table.
11926 The result is non-zero for success, or zero if an error was found. */
11929 locate_v1_virtual_dwo_sections (asection
*sectp
,
11930 struct virtual_v1_dwo_sections
*sections
)
11932 const struct dwop_section_names
*names
= &dwop_section_names
;
11934 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11936 /* There can be only one. */
11937 if (sections
->abbrev
.s
.section
!= NULL
)
11939 sections
->abbrev
.s
.section
= sectp
;
11940 sections
->abbrev
.size
= bfd_section_size (sectp
);
11942 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11943 || section_is_p (sectp
->name
, &names
->types_dwo
))
11945 /* There can be only one. */
11946 if (sections
->info_or_types
.s
.section
!= NULL
)
11948 sections
->info_or_types
.s
.section
= sectp
;
11949 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11951 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11953 /* There can be only one. */
11954 if (sections
->line
.s
.section
!= NULL
)
11956 sections
->line
.s
.section
= sectp
;
11957 sections
->line
.size
= bfd_section_size (sectp
);
11959 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11961 /* There can be only one. */
11962 if (sections
->loc
.s
.section
!= NULL
)
11964 sections
->loc
.s
.section
= sectp
;
11965 sections
->loc
.size
= bfd_section_size (sectp
);
11967 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11969 /* There can be only one. */
11970 if (sections
->macinfo
.s
.section
!= NULL
)
11972 sections
->macinfo
.s
.section
= sectp
;
11973 sections
->macinfo
.size
= bfd_section_size (sectp
);
11975 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11977 /* There can be only one. */
11978 if (sections
->macro
.s
.section
!= NULL
)
11980 sections
->macro
.s
.section
= sectp
;
11981 sections
->macro
.size
= bfd_section_size (sectp
);
11983 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11985 /* There can be only one. */
11986 if (sections
->str_offsets
.s
.section
!= NULL
)
11988 sections
->str_offsets
.s
.section
= sectp
;
11989 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11993 /* No other kind of section is valid. */
12000 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12001 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12002 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12003 This is for DWP version 1 files. */
12005 static struct dwo_unit
*
12006 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
12007 struct dwp_file
*dwp_file
,
12008 uint32_t unit_index
,
12009 const char *comp_dir
,
12010 ULONGEST signature
, int is_debug_types
)
12012 const struct dwp_hash_table
*dwp_htab
=
12013 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12014 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12015 const char *kind
= is_debug_types
? "TU" : "CU";
12016 struct dwo_file
*dwo_file
;
12017 struct dwo_unit
*dwo_unit
;
12018 struct virtual_v1_dwo_sections sections
;
12019 void **dwo_file_slot
;
12022 gdb_assert (dwp_file
->version
== 1);
12024 if (dwarf_read_debug
)
12026 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12028 pulongest (unit_index
), hex_string (signature
),
12032 /* Fetch the sections of this DWO unit.
12033 Put a limit on the number of sections we look for so that bad data
12034 doesn't cause us to loop forever. */
12036 #define MAX_NR_V1_DWO_SECTIONS \
12037 (1 /* .debug_info or .debug_types */ \
12038 + 1 /* .debug_abbrev */ \
12039 + 1 /* .debug_line */ \
12040 + 1 /* .debug_loc */ \
12041 + 1 /* .debug_str_offsets */ \
12042 + 1 /* .debug_macro or .debug_macinfo */ \
12043 + 1 /* trailing zero */)
12045 memset (§ions
, 0, sizeof (sections
));
12047 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12050 uint32_t section_nr
=
12051 read_4_bytes (dbfd
,
12052 dwp_htab
->section_pool
.v1
.indices
12053 + (unit_index
+ i
) * sizeof (uint32_t));
12055 if (section_nr
== 0)
12057 if (section_nr
>= dwp_file
->num_sections
)
12059 error (_("Dwarf Error: bad DWP hash table, section number too large"
12060 " [in module %s]"),
12064 sectp
= dwp_file
->elf_sections
[section_nr
];
12065 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12067 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12068 " [in module %s]"),
12074 || sections
.info_or_types
.empty ()
12075 || sections
.abbrev
.empty ())
12077 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12078 " [in module %s]"),
12081 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12083 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12084 " [in module %s]"),
12088 /* It's easier for the rest of the code if we fake a struct dwo_file and
12089 have dwo_unit "live" in that. At least for now.
12091 The DWP file can be made up of a random collection of CUs and TUs.
12092 However, for each CU + set of TUs that came from the same original DWO
12093 file, we can combine them back into a virtual DWO file to save space
12094 (fewer struct dwo_file objects to allocate). Remember that for really
12095 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12097 std::string virtual_dwo_name
=
12098 string_printf ("virtual-dwo/%d-%d-%d-%d",
12099 sections
.abbrev
.get_id (),
12100 sections
.line
.get_id (),
12101 sections
.loc
.get_id (),
12102 sections
.str_offsets
.get_id ());
12103 /* Can we use an existing virtual DWO file? */
12104 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12106 /* Create one if necessary. */
12107 if (*dwo_file_slot
== NULL
)
12109 if (dwarf_read_debug
)
12111 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12112 virtual_dwo_name
.c_str ());
12114 dwo_file
= new struct dwo_file
;
12115 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12116 dwo_file
->comp_dir
= comp_dir
;
12117 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12118 dwo_file
->sections
.line
= sections
.line
;
12119 dwo_file
->sections
.loc
= sections
.loc
;
12120 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12121 dwo_file
->sections
.macro
= sections
.macro
;
12122 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12123 /* The "str" section is global to the entire DWP file. */
12124 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12125 /* The info or types section is assigned below to dwo_unit,
12126 there's no need to record it in dwo_file.
12127 Also, we can't simply record type sections in dwo_file because
12128 we record a pointer into the vector in dwo_unit. As we collect more
12129 types we'll grow the vector and eventually have to reallocate space
12130 for it, invalidating all copies of pointers into the previous
12132 *dwo_file_slot
= dwo_file
;
12136 if (dwarf_read_debug
)
12138 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12139 virtual_dwo_name
.c_str ());
12141 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12144 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12145 dwo_unit
->dwo_file
= dwo_file
;
12146 dwo_unit
->signature
= signature
;
12147 dwo_unit
->section
=
12148 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12149 *dwo_unit
->section
= sections
.info_or_types
;
12150 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12155 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
12156 simplify them. Given a pointer to the containing section SECTION, and
12157 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
12158 virtual section of just that piece. */
12160 static struct dwarf2_section_info
12161 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
12162 struct dwarf2_section_info
*section
,
12163 bfd_size_type offset
, bfd_size_type size
)
12165 struct dwarf2_section_info result
;
12168 gdb_assert (section
!= NULL
);
12169 gdb_assert (!section
->is_virtual
);
12171 memset (&result
, 0, sizeof (result
));
12172 result
.s
.containing_section
= section
;
12173 result
.is_virtual
= true;
12178 sectp
= section
->get_bfd_section ();
12180 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12181 bounds of the real section. This is a pretty-rare event, so just
12182 flag an error (easier) instead of a warning and trying to cope. */
12184 || offset
+ size
> bfd_section_size (sectp
))
12186 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
12187 " in section %s [in module %s]"),
12188 sectp
? bfd_section_name (sectp
) : "<unknown>",
12189 objfile_name (per_objfile
->objfile
));
12192 result
.virtual_offset
= offset
;
12193 result
.size
= size
;
12197 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12198 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12199 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12200 This is for DWP version 2 files. */
12202 static struct dwo_unit
*
12203 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12204 struct dwp_file
*dwp_file
,
12205 uint32_t unit_index
,
12206 const char *comp_dir
,
12207 ULONGEST signature
, int is_debug_types
)
12209 const struct dwp_hash_table
*dwp_htab
=
12210 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12211 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12212 const char *kind
= is_debug_types
? "TU" : "CU";
12213 struct dwo_file
*dwo_file
;
12214 struct dwo_unit
*dwo_unit
;
12215 struct virtual_v2_or_v5_dwo_sections sections
;
12216 void **dwo_file_slot
;
12219 gdb_assert (dwp_file
->version
== 2);
12221 if (dwarf_read_debug
)
12223 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12225 pulongest (unit_index
), hex_string (signature
),
12229 /* Fetch the section offsets of this DWO unit. */
12231 memset (§ions
, 0, sizeof (sections
));
12233 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12235 uint32_t offset
= read_4_bytes (dbfd
,
12236 dwp_htab
->section_pool
.v2
.offsets
12237 + (((unit_index
- 1) * dwp_htab
->nr_columns
12239 * sizeof (uint32_t)));
12240 uint32_t size
= read_4_bytes (dbfd
,
12241 dwp_htab
->section_pool
.v2
.sizes
12242 + (((unit_index
- 1) * dwp_htab
->nr_columns
12244 * sizeof (uint32_t)));
12246 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12249 case DW_SECT_TYPES
:
12250 sections
.info_or_types_offset
= offset
;
12251 sections
.info_or_types_size
= size
;
12253 case DW_SECT_ABBREV
:
12254 sections
.abbrev_offset
= offset
;
12255 sections
.abbrev_size
= size
;
12258 sections
.line_offset
= offset
;
12259 sections
.line_size
= size
;
12262 sections
.loc_offset
= offset
;
12263 sections
.loc_size
= size
;
12265 case DW_SECT_STR_OFFSETS
:
12266 sections
.str_offsets_offset
= offset
;
12267 sections
.str_offsets_size
= size
;
12269 case DW_SECT_MACINFO
:
12270 sections
.macinfo_offset
= offset
;
12271 sections
.macinfo_size
= size
;
12273 case DW_SECT_MACRO
:
12274 sections
.macro_offset
= offset
;
12275 sections
.macro_size
= size
;
12280 /* It's easier for the rest of the code if we fake a struct dwo_file and
12281 have dwo_unit "live" in that. At least for now.
12283 The DWP file can be made up of a random collection of CUs and TUs.
12284 However, for each CU + set of TUs that came from the same original DWO
12285 file, we can combine them back into a virtual DWO file to save space
12286 (fewer struct dwo_file objects to allocate). Remember that for really
12287 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12289 std::string virtual_dwo_name
=
12290 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12291 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12292 (long) (sections
.line_size
? sections
.line_offset
: 0),
12293 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12294 (long) (sections
.str_offsets_size
12295 ? sections
.str_offsets_offset
: 0));
12296 /* Can we use an existing virtual DWO file? */
12297 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12299 /* Create one if necessary. */
12300 if (*dwo_file_slot
== NULL
)
12302 if (dwarf_read_debug
)
12304 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12305 virtual_dwo_name
.c_str ());
12307 dwo_file
= new struct dwo_file
;
12308 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12309 dwo_file
->comp_dir
= comp_dir
;
12310 dwo_file
->sections
.abbrev
=
12311 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12312 sections
.abbrev_offset
,
12313 sections
.abbrev_size
);
12314 dwo_file
->sections
.line
=
12315 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12316 sections
.line_offset
,
12317 sections
.line_size
);
12318 dwo_file
->sections
.loc
=
12319 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12320 sections
.loc_offset
, sections
.loc_size
);
12321 dwo_file
->sections
.macinfo
=
12322 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12323 sections
.macinfo_offset
,
12324 sections
.macinfo_size
);
12325 dwo_file
->sections
.macro
=
12326 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12327 sections
.macro_offset
,
12328 sections
.macro_size
);
12329 dwo_file
->sections
.str_offsets
=
12330 create_dwp_v2_or_v5_section (per_objfile
,
12331 &dwp_file
->sections
.str_offsets
,
12332 sections
.str_offsets_offset
,
12333 sections
.str_offsets_size
);
12334 /* The "str" section is global to the entire DWP file. */
12335 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12336 /* The info or types section is assigned below to dwo_unit,
12337 there's no need to record it in dwo_file.
12338 Also, we can't simply record type sections in dwo_file because
12339 we record a pointer into the vector in dwo_unit. As we collect more
12340 types we'll grow the vector and eventually have to reallocate space
12341 for it, invalidating all copies of pointers into the previous
12343 *dwo_file_slot
= dwo_file
;
12347 if (dwarf_read_debug
)
12349 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12350 virtual_dwo_name
.c_str ());
12352 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12355 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12356 dwo_unit
->dwo_file
= dwo_file
;
12357 dwo_unit
->signature
= signature
;
12358 dwo_unit
->section
=
12359 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12360 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12363 ? &dwp_file
->sections
.types
12364 : &dwp_file
->sections
.info
,
12365 sections
.info_or_types_offset
,
12366 sections
.info_or_types_size
);
12367 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12372 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12373 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12374 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12375 This is for DWP version 5 files. */
12377 static struct dwo_unit
*
12378 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12379 struct dwp_file
*dwp_file
,
12380 uint32_t unit_index
,
12381 const char *comp_dir
,
12382 ULONGEST signature
, int is_debug_types
)
12384 const struct dwp_hash_table
*dwp_htab
12385 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12386 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12387 const char *kind
= is_debug_types
? "TU" : "CU";
12388 struct dwo_file
*dwo_file
;
12389 struct dwo_unit
*dwo_unit
;
12390 struct virtual_v2_or_v5_dwo_sections sections
{};
12391 void **dwo_file_slot
;
12393 gdb_assert (dwp_file
->version
== 5);
12395 if (dwarf_read_debug
)
12397 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V5 file: %s\n",
12399 pulongest (unit_index
), hex_string (signature
),
12403 /* Fetch the section offsets of this DWO unit. */
12405 /* memset (§ions, 0, sizeof (sections)); */
12407 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12409 uint32_t offset
= read_4_bytes (dbfd
,
12410 dwp_htab
->section_pool
.v5
.offsets
12411 + (((unit_index
- 1)
12412 * dwp_htab
->nr_columns
12414 * sizeof (uint32_t)));
12415 uint32_t size
= read_4_bytes (dbfd
,
12416 dwp_htab
->section_pool
.v5
.sizes
12417 + (((unit_index
- 1) * dwp_htab
->nr_columns
12419 * sizeof (uint32_t)));
12421 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12423 case DW_SECT_ABBREV_V5
:
12424 sections
.abbrev_offset
= offset
;
12425 sections
.abbrev_size
= size
;
12427 case DW_SECT_INFO_V5
:
12428 sections
.info_or_types_offset
= offset
;
12429 sections
.info_or_types_size
= size
;
12431 case DW_SECT_LINE_V5
:
12432 sections
.line_offset
= offset
;
12433 sections
.line_size
= size
;
12435 case DW_SECT_LOCLISTS_V5
:
12436 sections
.loclists_offset
= offset
;
12437 sections
.loclists_size
= size
;
12439 case DW_SECT_MACRO_V5
:
12440 sections
.macro_offset
= offset
;
12441 sections
.macro_size
= size
;
12443 case DW_SECT_RNGLISTS_V5
:
12444 sections
.rnglists_offset
= offset
;
12445 sections
.rnglists_size
= size
;
12447 case DW_SECT_STR_OFFSETS_V5
:
12448 sections
.str_offsets_offset
= offset
;
12449 sections
.str_offsets_size
= size
;
12451 case DW_SECT_RESERVED_V5
:
12457 /* It's easier for the rest of the code if we fake a struct dwo_file and
12458 have dwo_unit "live" in that. At least for now.
12460 The DWP file can be made up of a random collection of CUs and TUs.
12461 However, for each CU + set of TUs that came from the same original DWO
12462 file, we can combine them back into a virtual DWO file to save space
12463 (fewer struct dwo_file objects to allocate). Remember that for really
12464 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12466 std::string virtual_dwo_name
=
12467 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12468 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12469 (long) (sections
.line_size
? sections
.line_offset
: 0),
12470 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12471 (long) (sections
.str_offsets_size
12472 ? sections
.str_offsets_offset
: 0),
12473 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12474 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12475 /* Can we use an existing virtual DWO file? */
12476 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12477 virtual_dwo_name
.c_str (),
12479 /* Create one if necessary. */
12480 if (*dwo_file_slot
== NULL
)
12482 if (dwarf_read_debug
)
12484 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12485 virtual_dwo_name
.c_str ());
12487 dwo_file
= new struct dwo_file
;
12488 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12489 dwo_file
->comp_dir
= comp_dir
;
12490 dwo_file
->sections
.abbrev
=
12491 create_dwp_v2_or_v5_section (per_objfile
,
12492 &dwp_file
->sections
.abbrev
,
12493 sections
.abbrev_offset
,
12494 sections
.abbrev_size
);
12495 dwo_file
->sections
.line
=
12496 create_dwp_v2_or_v5_section (per_objfile
,
12497 &dwp_file
->sections
.line
,
12498 sections
.line_offset
, sections
.line_size
);
12499 dwo_file
->sections
.macro
=
12500 create_dwp_v2_or_v5_section (per_objfile
,
12501 &dwp_file
->sections
.macro
,
12502 sections
.macro_offset
,
12503 sections
.macro_size
);
12504 dwo_file
->sections
.loclists
=
12505 create_dwp_v2_or_v5_section (per_objfile
,
12506 &dwp_file
->sections
.loclists
,
12507 sections
.loclists_offset
,
12508 sections
.loclists_size
);
12509 dwo_file
->sections
.rnglists
=
12510 create_dwp_v2_or_v5_section (per_objfile
,
12511 &dwp_file
->sections
.rnglists
,
12512 sections
.rnglists_offset
,
12513 sections
.rnglists_size
);
12514 dwo_file
->sections
.str_offsets
=
12515 create_dwp_v2_or_v5_section (per_objfile
,
12516 &dwp_file
->sections
.str_offsets
,
12517 sections
.str_offsets_offset
,
12518 sections
.str_offsets_size
);
12519 /* The "str" section is global to the entire DWP file. */
12520 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12521 /* The info or types section is assigned below to dwo_unit,
12522 there's no need to record it in dwo_file.
12523 Also, we can't simply record type sections in dwo_file because
12524 we record a pointer into the vector in dwo_unit. As we collect more
12525 types we'll grow the vector and eventually have to reallocate space
12526 for it, invalidating all copies of pointers into the previous
12528 *dwo_file_slot
= dwo_file
;
12532 if (dwarf_read_debug
)
12534 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12535 virtual_dwo_name
.c_str ());
12537 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12540 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12541 dwo_unit
->dwo_file
= dwo_file
;
12542 dwo_unit
->signature
= signature
;
12544 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12545 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12546 &dwp_file
->sections
.info
,
12547 sections
.info_or_types_offset
,
12548 sections
.info_or_types_size
);
12549 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12554 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12555 Returns NULL if the signature isn't found. */
12557 static struct dwo_unit
*
12558 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12559 struct dwp_file
*dwp_file
, const char *comp_dir
,
12560 ULONGEST signature
, int is_debug_types
)
12562 const struct dwp_hash_table
*dwp_htab
=
12563 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12564 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12565 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12566 uint32_t hash
= signature
& mask
;
12567 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12570 struct dwo_unit find_dwo_cu
;
12572 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12573 find_dwo_cu
.signature
= signature
;
12574 slot
= htab_find_slot (is_debug_types
12575 ? dwp_file
->loaded_tus
.get ()
12576 : dwp_file
->loaded_cus
.get (),
12577 &find_dwo_cu
, INSERT
);
12580 return (struct dwo_unit
*) *slot
;
12582 /* Use a for loop so that we don't loop forever on bad debug info. */
12583 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12585 ULONGEST signature_in_table
;
12587 signature_in_table
=
12588 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12589 if (signature_in_table
== signature
)
12591 uint32_t unit_index
=
12592 read_4_bytes (dbfd
,
12593 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12595 if (dwp_file
->version
== 1)
12597 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12598 unit_index
, comp_dir
,
12599 signature
, is_debug_types
);
12601 else if (dwp_file
->version
== 2)
12603 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12604 unit_index
, comp_dir
,
12605 signature
, is_debug_types
);
12607 else /* version == 5 */
12609 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12610 unit_index
, comp_dir
,
12611 signature
, is_debug_types
);
12613 return (struct dwo_unit
*) *slot
;
12615 if (signature_in_table
== 0)
12617 hash
= (hash
+ hash2
) & mask
;
12620 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12621 " [in module %s]"),
12625 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12626 Open the file specified by FILE_NAME and hand it off to BFD for
12627 preliminary analysis. Return a newly initialized bfd *, which
12628 includes a canonicalized copy of FILE_NAME.
12629 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12630 SEARCH_CWD is true if the current directory is to be searched.
12631 It will be searched before debug-file-directory.
12632 If successful, the file is added to the bfd include table of the
12633 objfile's bfd (see gdb_bfd_record_inclusion).
12634 If unable to find/open the file, return NULL.
12635 NOTE: This function is derived from symfile_bfd_open. */
12637 static gdb_bfd_ref_ptr
12638 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12639 const char *file_name
, int is_dwp
, int search_cwd
)
12642 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12643 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12644 to debug_file_directory. */
12645 const char *search_path
;
12646 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12648 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12651 if (*debug_file_directory
!= '\0')
12653 search_path_holder
.reset (concat (".", dirname_separator_string
,
12654 debug_file_directory
,
12656 search_path
= search_path_holder
.get ();
12662 search_path
= debug_file_directory
;
12664 openp_flags flags
= OPF_RETURN_REALPATH
;
12666 flags
|= OPF_SEARCH_IN_PATH
;
12668 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12669 desc
= openp (search_path
, flags
, file_name
,
12670 O_RDONLY
| O_BINARY
, &absolute_name
);
12674 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12676 if (sym_bfd
== NULL
)
12678 bfd_set_cacheable (sym_bfd
.get (), 1);
12680 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12683 /* Success. Record the bfd as having been included by the objfile's bfd.
12684 This is important because things like demangled_names_hash lives in the
12685 objfile's per_bfd space and may have references to things like symbol
12686 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12687 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12692 /* Try to open DWO file FILE_NAME.
12693 COMP_DIR is the DW_AT_comp_dir attribute.
12694 The result is the bfd handle of the file.
12695 If there is a problem finding or opening the file, return NULL.
12696 Upon success, the canonicalized path of the file is stored in the bfd,
12697 same as symfile_bfd_open. */
12699 static gdb_bfd_ref_ptr
12700 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12701 const char *file_name
, const char *comp_dir
)
12703 if (IS_ABSOLUTE_PATH (file_name
))
12704 return try_open_dwop_file (per_objfile
, file_name
,
12705 0 /*is_dwp*/, 0 /*search_cwd*/);
12707 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12709 if (comp_dir
!= NULL
)
12711 gdb::unique_xmalloc_ptr
<char> path_to_try
12712 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12714 /* NOTE: If comp_dir is a relative path, this will also try the
12715 search path, which seems useful. */
12716 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12718 1 /*search_cwd*/));
12723 /* That didn't work, try debug-file-directory, which, despite its name,
12724 is a list of paths. */
12726 if (*debug_file_directory
== '\0')
12729 return try_open_dwop_file (per_objfile
, file_name
,
12730 0 /*is_dwp*/, 1 /*search_cwd*/);
12733 /* This function is mapped across the sections and remembers the offset and
12734 size of each of the DWO debugging sections we are interested in. */
12737 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12738 dwo_sections
*dwo_sections
)
12740 const struct dwop_section_names
*names
= &dwop_section_names
;
12742 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12744 dwo_sections
->abbrev
.s
.section
= sectp
;
12745 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12747 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12749 dwo_sections
->info
.s
.section
= sectp
;
12750 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12752 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12754 dwo_sections
->line
.s
.section
= sectp
;
12755 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12757 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12759 dwo_sections
->loc
.s
.section
= sectp
;
12760 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12762 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12764 dwo_sections
->loclists
.s
.section
= sectp
;
12765 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12767 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12769 dwo_sections
->macinfo
.s
.section
= sectp
;
12770 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12772 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12774 dwo_sections
->macro
.s
.section
= sectp
;
12775 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12777 else if (section_is_p (sectp
->name
, &names
->rnglists_dwo
))
12779 dwo_sections
->rnglists
.s
.section
= sectp
;
12780 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12782 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12784 dwo_sections
->str
.s
.section
= sectp
;
12785 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12787 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12789 dwo_sections
->str_offsets
.s
.section
= sectp
;
12790 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12792 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12794 struct dwarf2_section_info type_section
;
12796 memset (&type_section
, 0, sizeof (type_section
));
12797 type_section
.s
.section
= sectp
;
12798 type_section
.size
= bfd_section_size (sectp
);
12799 dwo_sections
->types
.push_back (type_section
);
12803 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12804 by PER_CU. This is for the non-DWP case.
12805 The result is NULL if DWO_NAME can't be found. */
12807 static struct dwo_file
*
12808 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12809 const char *comp_dir
)
12811 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12813 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12816 if (dwarf_read_debug
)
12817 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12821 dwo_file_up
dwo_file (new struct dwo_file
);
12822 dwo_file
->dwo_name
= dwo_name
;
12823 dwo_file
->comp_dir
= comp_dir
;
12824 dwo_file
->dbfd
= std::move (dbfd
);
12826 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12827 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12828 &dwo_file
->sections
);
12830 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12833 if (cu
->per_cu
->dwarf_version
< 5)
12835 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12836 dwo_file
->sections
.types
, dwo_file
->tus
);
12840 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12841 &dwo_file
->sections
.info
, dwo_file
->tus
,
12845 if (dwarf_read_debug
)
12846 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12848 return dwo_file
.release ();
12851 /* This function is mapped across the sections and remembers the offset and
12852 size of each of the DWP debugging sections common to version 1 and 2 that
12853 we are interested in. */
12856 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12857 dwp_file
*dwp_file
)
12859 const struct dwop_section_names
*names
= &dwop_section_names
;
12860 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12862 /* Record the ELF section number for later lookup: this is what the
12863 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12864 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12865 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12867 /* Look for specific sections that we need. */
12868 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12870 dwp_file
->sections
.str
.s
.section
= sectp
;
12871 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12873 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12875 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12876 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12878 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12880 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12881 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12885 /* This function is mapped across the sections and remembers the offset and
12886 size of each of the DWP version 2 debugging sections that we are interested
12887 in. This is split into a separate function because we don't know if we
12888 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12891 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12893 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12894 const struct dwop_section_names
*names
= &dwop_section_names
;
12895 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12897 /* Record the ELF section number for later lookup: this is what the
12898 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12899 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12900 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12902 /* Look for specific sections that we need. */
12903 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12905 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12906 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12908 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12910 dwp_file
->sections
.info
.s
.section
= sectp
;
12911 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12913 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12915 dwp_file
->sections
.line
.s
.section
= sectp
;
12916 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12918 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12920 dwp_file
->sections
.loc
.s
.section
= sectp
;
12921 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12923 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12925 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12926 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12928 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12930 dwp_file
->sections
.macro
.s
.section
= sectp
;
12931 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12933 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12935 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12936 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12938 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12940 dwp_file
->sections
.types
.s
.section
= sectp
;
12941 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12945 /* This function is mapped across the sections and remembers the offset and
12946 size of each of the DWP version 5 debugging sections that we are interested
12947 in. This is split into a separate function because we don't know if we
12948 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12951 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12953 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12954 const struct dwop_section_names
*names
= &dwop_section_names
;
12955 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12957 /* Record the ELF section number for later lookup: this is what the
12958 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12959 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12960 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12962 /* Look for specific sections that we need. */
12963 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12965 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12966 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12968 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12970 dwp_file
->sections
.info
.s
.section
= sectp
;
12971 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12973 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12975 dwp_file
->sections
.line
.s
.section
= sectp
;
12976 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12978 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12980 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12981 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12983 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12985 dwp_file
->sections
.macro
.s
.section
= sectp
;
12986 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12988 else if (section_is_p (sectp
->name
, &names
->rnglists_dwo
))
12990 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12991 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12993 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12995 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12996 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13000 /* Hash function for dwp_file loaded CUs/TUs. */
13003 hash_dwp_loaded_cutus (const void *item
)
13005 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13007 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13008 return dwo_unit
->signature
;
13011 /* Equality function for dwp_file loaded CUs/TUs. */
13014 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13016 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13017 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13019 return dua
->signature
== dub
->signature
;
13022 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13025 allocate_dwp_loaded_cutus_table ()
13027 return htab_up (htab_create_alloc (3,
13028 hash_dwp_loaded_cutus
,
13029 eq_dwp_loaded_cutus
,
13030 NULL
, xcalloc
, xfree
));
13033 /* Try to open DWP file FILE_NAME.
13034 The result is the bfd handle of the file.
13035 If there is a problem finding or opening the file, return NULL.
13036 Upon success, the canonicalized path of the file is stored in the bfd,
13037 same as symfile_bfd_open. */
13039 static gdb_bfd_ref_ptr
13040 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
13042 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
13044 1 /*search_cwd*/));
13048 /* Work around upstream bug 15652.
13049 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13050 [Whether that's a "bug" is debatable, but it is getting in our way.]
13051 We have no real idea where the dwp file is, because gdb's realpath-ing
13052 of the executable's path may have discarded the needed info.
13053 [IWBN if the dwp file name was recorded in the executable, akin to
13054 .gnu_debuglink, but that doesn't exist yet.]
13055 Strip the directory from FILE_NAME and search again. */
13056 if (*debug_file_directory
!= '\0')
13058 /* Don't implicitly search the current directory here.
13059 If the user wants to search "." to handle this case,
13060 it must be added to debug-file-directory. */
13061 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
13069 /* Initialize the use of the DWP file for the current objfile.
13070 By convention the name of the DWP file is ${objfile}.dwp.
13071 The result is NULL if it can't be found. */
13073 static std::unique_ptr
<struct dwp_file
>
13074 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
13076 struct objfile
*objfile
= per_objfile
->objfile
;
13078 /* Try to find first .dwp for the binary file before any symbolic links
13081 /* If the objfile is a debug file, find the name of the real binary
13082 file and get the name of dwp file from there. */
13083 std::string dwp_name
;
13084 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13086 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13087 const char *backlink_basename
= lbasename (backlink
->original_name
);
13089 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13092 dwp_name
= objfile
->original_name
;
13094 dwp_name
+= ".dwp";
13096 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
13098 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13100 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13101 dwp_name
= objfile_name (objfile
);
13102 dwp_name
+= ".dwp";
13103 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
13108 if (dwarf_read_debug
)
13109 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13110 return std::unique_ptr
<dwp_file
> ();
13113 const char *name
= bfd_get_filename (dbfd
.get ());
13114 std::unique_ptr
<struct dwp_file
> dwp_file
13115 (new struct dwp_file (name
, std::move (dbfd
)));
13117 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13118 dwp_file
->elf_sections
=
13119 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
13120 dwp_file
->num_sections
, asection
*);
13122 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13123 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13126 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
13128 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
13130 /* The DWP file version is stored in the hash table. Oh well. */
13131 if (dwp_file
->cus
&& dwp_file
->tus
13132 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13134 /* Technically speaking, we should try to limp along, but this is
13135 pretty bizarre. We use pulongest here because that's the established
13136 portability solution (e.g, we cannot use %u for uint32_t). */
13137 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13138 " TU version %s [in DWP file %s]"),
13139 pulongest (dwp_file
->cus
->version
),
13140 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13144 dwp_file
->version
= dwp_file
->cus
->version
;
13145 else if (dwp_file
->tus
)
13146 dwp_file
->version
= dwp_file
->tus
->version
;
13148 dwp_file
->version
= 2;
13150 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13152 if (dwp_file
->version
== 2)
13153 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13156 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13160 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
13161 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
13163 if (dwarf_read_debug
)
13165 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13166 fprintf_unfiltered (gdb_stdlog
,
13167 " %s CUs, %s TUs\n",
13168 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13169 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13175 /* Wrapper around open_and_init_dwp_file, only open it once. */
13177 static struct dwp_file
*
13178 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
13180 if (!per_objfile
->per_bfd
->dwp_checked
)
13182 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
13183 per_objfile
->per_bfd
->dwp_checked
= 1;
13185 return per_objfile
->per_bfd
->dwp_file
.get ();
13188 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13189 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13190 or in the DWP file for the objfile, referenced by THIS_UNIT.
13191 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13192 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13194 This is called, for example, when wanting to read a variable with a
13195 complex location. Therefore we don't want to do file i/o for every call.
13196 Therefore we don't want to look for a DWO file on every call.
13197 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13198 then we check if we've already seen DWO_NAME, and only THEN do we check
13201 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13202 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13204 static struct dwo_unit
*
13205 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13206 ULONGEST signature
, int is_debug_types
)
13208 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13209 struct objfile
*objfile
= per_objfile
->objfile
;
13210 const char *kind
= is_debug_types
? "TU" : "CU";
13211 void **dwo_file_slot
;
13212 struct dwo_file
*dwo_file
;
13213 struct dwp_file
*dwp_file
;
13215 /* First see if there's a DWP file.
13216 If we have a DWP file but didn't find the DWO inside it, don't
13217 look for the original DWO file. It makes gdb behave differently
13218 depending on whether one is debugging in the build tree. */
13220 dwp_file
= get_dwp_file (per_objfile
);
13221 if (dwp_file
!= NULL
)
13223 const struct dwp_hash_table
*dwp_htab
=
13224 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13226 if (dwp_htab
!= NULL
)
13228 struct dwo_unit
*dwo_cutu
=
13229 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
13232 if (dwo_cutu
!= NULL
)
13234 if (dwarf_read_debug
)
13236 fprintf_unfiltered (gdb_stdlog
,
13237 "Virtual DWO %s %s found: @%s\n",
13238 kind
, hex_string (signature
),
13239 host_address_to_string (dwo_cutu
));
13247 /* No DWP file, look for the DWO file. */
13249 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13250 if (*dwo_file_slot
== NULL
)
13252 /* Read in the file and build a table of the CUs/TUs it contains. */
13253 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13255 /* NOTE: This will be NULL if unable to open the file. */
13256 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13258 if (dwo_file
!= NULL
)
13260 struct dwo_unit
*dwo_cutu
= NULL
;
13262 if (is_debug_types
&& dwo_file
->tus
)
13264 struct dwo_unit find_dwo_cutu
;
13266 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13267 find_dwo_cutu
.signature
= signature
;
13269 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13272 else if (!is_debug_types
&& dwo_file
->cus
)
13274 struct dwo_unit find_dwo_cutu
;
13276 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13277 find_dwo_cutu
.signature
= signature
;
13278 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13282 if (dwo_cutu
!= NULL
)
13284 if (dwarf_read_debug
)
13286 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13287 kind
, dwo_name
, hex_string (signature
),
13288 host_address_to_string (dwo_cutu
));
13295 /* We didn't find it. This could mean a dwo_id mismatch, or
13296 someone deleted the DWO/DWP file, or the search path isn't set up
13297 correctly to find the file. */
13299 if (dwarf_read_debug
)
13301 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13302 kind
, dwo_name
, hex_string (signature
));
13305 /* This is a warning and not a complaint because it can be caused by
13306 pilot error (e.g., user accidentally deleting the DWO). */
13308 /* Print the name of the DWP file if we looked there, helps the user
13309 better diagnose the problem. */
13310 std::string dwp_text
;
13312 if (dwp_file
!= NULL
)
13313 dwp_text
= string_printf (" [in DWP file %s]",
13314 lbasename (dwp_file
->name
));
13316 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13317 " [in module %s]"),
13318 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13319 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13324 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13325 See lookup_dwo_cutu_unit for details. */
13327 static struct dwo_unit
*
13328 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13329 ULONGEST signature
)
13331 gdb_assert (!cu
->per_cu
->is_debug_types
);
13333 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13336 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13337 See lookup_dwo_cutu_unit for details. */
13339 static struct dwo_unit
*
13340 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13342 gdb_assert (cu
->per_cu
->is_debug_types
);
13344 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13346 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13349 /* Traversal function for queue_and_load_all_dwo_tus. */
13352 queue_and_load_dwo_tu (void **slot
, void *info
)
13354 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13355 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13356 ULONGEST signature
= dwo_unit
->signature
;
13357 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13359 if (sig_type
!= NULL
)
13361 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13363 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13364 a real dependency of PER_CU on SIG_TYPE. That is detected later
13365 while processing PER_CU. */
13366 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
13367 load_full_type_unit (sig_cu
, cu
->per_objfile
);
13368 cu
->per_cu
->imported_symtabs_push (sig_cu
);
13374 /* Queue all TUs contained in the DWO of CU to be read in.
13375 The DWO may have the only definition of the type, though it may not be
13376 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13377 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13380 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13382 struct dwo_unit
*dwo_unit
;
13383 struct dwo_file
*dwo_file
;
13385 gdb_assert (cu
!= nullptr);
13386 gdb_assert (!cu
->per_cu
->is_debug_types
);
13387 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13389 dwo_unit
= cu
->dwo_unit
;
13390 gdb_assert (dwo_unit
!= NULL
);
13392 dwo_file
= dwo_unit
->dwo_file
;
13393 if (dwo_file
->tus
!= NULL
)
13394 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13397 /* Read in various DIEs. */
13399 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13400 Inherit only the children of the DW_AT_abstract_origin DIE not being
13401 already referenced by DW_AT_abstract_origin from the children of the
13405 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13407 struct die_info
*child_die
;
13408 sect_offset
*offsetp
;
13409 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13410 struct die_info
*origin_die
;
13411 /* Iterator of the ORIGIN_DIE children. */
13412 struct die_info
*origin_child_die
;
13413 struct attribute
*attr
;
13414 struct dwarf2_cu
*origin_cu
;
13415 struct pending
**origin_previous_list_in_scope
;
13417 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13421 /* Note that following die references may follow to a die in a
13425 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13427 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13429 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13430 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13432 if (die
->tag
!= origin_die
->tag
13433 && !(die
->tag
== DW_TAG_inlined_subroutine
13434 && origin_die
->tag
== DW_TAG_subprogram
))
13435 complaint (_("DIE %s and its abstract origin %s have different tags"),
13436 sect_offset_str (die
->sect_off
),
13437 sect_offset_str (origin_die
->sect_off
));
13439 std::vector
<sect_offset
> offsets
;
13441 for (child_die
= die
->child
;
13442 child_die
&& child_die
->tag
;
13443 child_die
= child_die
->sibling
)
13445 struct die_info
*child_origin_die
;
13446 struct dwarf2_cu
*child_origin_cu
;
13448 /* We are trying to process concrete instance entries:
13449 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13450 it's not relevant to our analysis here. i.e. detecting DIEs that are
13451 present in the abstract instance but not referenced in the concrete
13453 if (child_die
->tag
== DW_TAG_call_site
13454 || child_die
->tag
== DW_TAG_GNU_call_site
)
13457 /* For each CHILD_DIE, find the corresponding child of
13458 ORIGIN_DIE. If there is more than one layer of
13459 DW_AT_abstract_origin, follow them all; there shouldn't be,
13460 but GCC versions at least through 4.4 generate this (GCC PR
13462 child_origin_die
= child_die
;
13463 child_origin_cu
= cu
;
13466 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13470 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13474 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13475 counterpart may exist. */
13476 if (child_origin_die
!= child_die
)
13478 if (child_die
->tag
!= child_origin_die
->tag
13479 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13480 && child_origin_die
->tag
== DW_TAG_subprogram
))
13481 complaint (_("Child DIE %s and its abstract origin %s have "
13483 sect_offset_str (child_die
->sect_off
),
13484 sect_offset_str (child_origin_die
->sect_off
));
13485 if (child_origin_die
->parent
!= origin_die
)
13486 complaint (_("Child DIE %s and its abstract origin %s have "
13487 "different parents"),
13488 sect_offset_str (child_die
->sect_off
),
13489 sect_offset_str (child_origin_die
->sect_off
));
13491 offsets
.push_back (child_origin_die
->sect_off
);
13494 std::sort (offsets
.begin (), offsets
.end ());
13495 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13496 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13497 if (offsetp
[-1] == *offsetp
)
13498 complaint (_("Multiple children of DIE %s refer "
13499 "to DIE %s as their abstract origin"),
13500 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13502 offsetp
= offsets
.data ();
13503 origin_child_die
= origin_die
->child
;
13504 while (origin_child_die
&& origin_child_die
->tag
)
13506 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13507 while (offsetp
< offsets_end
13508 && *offsetp
< origin_child_die
->sect_off
)
13510 if (offsetp
>= offsets_end
13511 || *offsetp
> origin_child_die
->sect_off
)
13513 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13514 Check whether we're already processing ORIGIN_CHILD_DIE.
13515 This can happen with mutually referenced abstract_origins.
13517 if (!origin_child_die
->in_process
)
13518 process_die (origin_child_die
, origin_cu
);
13520 origin_child_die
= origin_child_die
->sibling
;
13522 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13524 if (cu
!= origin_cu
)
13525 compute_delayed_physnames (origin_cu
);
13529 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13531 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13532 struct gdbarch
*gdbarch
= objfile
->arch ();
13533 struct context_stack
*newobj
;
13536 struct die_info
*child_die
;
13537 struct attribute
*attr
, *call_line
, *call_file
;
13539 CORE_ADDR baseaddr
;
13540 struct block
*block
;
13541 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13542 std::vector
<struct symbol
*> template_args
;
13543 struct template_symbol
*templ_func
= NULL
;
13547 /* If we do not have call site information, we can't show the
13548 caller of this inlined function. That's too confusing, so
13549 only use the scope for local variables. */
13550 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13551 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13552 if (call_line
== NULL
|| call_file
== NULL
)
13554 read_lexical_block_scope (die
, cu
);
13559 baseaddr
= objfile
->text_section_offset ();
13561 name
= dwarf2_name (die
, cu
);
13563 /* Ignore functions with missing or empty names. These are actually
13564 illegal according to the DWARF standard. */
13567 complaint (_("missing name for subprogram DIE at %s"),
13568 sect_offset_str (die
->sect_off
));
13572 /* Ignore functions with missing or invalid low and high pc attributes. */
13573 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13574 <= PC_BOUNDS_INVALID
)
13576 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13577 if (attr
== nullptr || !attr
->as_boolean ())
13578 complaint (_("cannot get low and high bounds "
13579 "for subprogram DIE at %s"),
13580 sect_offset_str (die
->sect_off
));
13584 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13585 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13587 /* If we have any template arguments, then we must allocate a
13588 different sort of symbol. */
13589 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13591 if (child_die
->tag
== DW_TAG_template_type_param
13592 || child_die
->tag
== DW_TAG_template_value_param
)
13594 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13595 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13600 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13601 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13602 (struct symbol
*) templ_func
);
13604 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13605 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13608 /* If there is a location expression for DW_AT_frame_base, record
13610 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13611 if (attr
!= nullptr)
13612 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13614 /* If there is a location for the static link, record it. */
13615 newobj
->static_link
= NULL
;
13616 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13617 if (attr
!= nullptr)
13619 newobj
->static_link
13620 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13621 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13625 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13627 if (die
->child
!= NULL
)
13629 child_die
= die
->child
;
13630 while (child_die
&& child_die
->tag
)
13632 if (child_die
->tag
== DW_TAG_template_type_param
13633 || child_die
->tag
== DW_TAG_template_value_param
)
13635 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13638 template_args
.push_back (arg
);
13641 process_die (child_die
, cu
);
13642 child_die
= child_die
->sibling
;
13646 inherit_abstract_dies (die
, cu
);
13648 /* If we have a DW_AT_specification, we might need to import using
13649 directives from the context of the specification DIE. See the
13650 comment in determine_prefix. */
13651 if (cu
->language
== language_cplus
13652 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13654 struct dwarf2_cu
*spec_cu
= cu
;
13655 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13659 child_die
= spec_die
->child
;
13660 while (child_die
&& child_die
->tag
)
13662 if (child_die
->tag
== DW_TAG_imported_module
)
13663 process_die (child_die
, spec_cu
);
13664 child_die
= child_die
->sibling
;
13667 /* In some cases, GCC generates specification DIEs that
13668 themselves contain DW_AT_specification attributes. */
13669 spec_die
= die_specification (spec_die
, &spec_cu
);
13673 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13674 /* Make a block for the local symbols within. */
13675 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13676 cstk
.static_link
, lowpc
, highpc
);
13678 /* For C++, set the block's scope. */
13679 if ((cu
->language
== language_cplus
13680 || cu
->language
== language_fortran
13681 || cu
->language
== language_d
13682 || cu
->language
== language_rust
)
13683 && cu
->processing_has_namespace_info
)
13684 block_set_scope (block
, determine_prefix (die
, cu
),
13685 &objfile
->objfile_obstack
);
13687 /* If we have address ranges, record them. */
13688 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13690 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13692 /* Attach template arguments to function. */
13693 if (!template_args
.empty ())
13695 gdb_assert (templ_func
!= NULL
);
13697 templ_func
->n_template_arguments
= template_args
.size ();
13698 templ_func
->template_arguments
13699 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13700 templ_func
->n_template_arguments
);
13701 memcpy (templ_func
->template_arguments
,
13702 template_args
.data (),
13703 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13705 /* Make sure that the symtab is set on the new symbols. Even
13706 though they don't appear in this symtab directly, other parts
13707 of gdb assume that symbols do, and this is reasonably
13709 for (symbol
*sym
: template_args
)
13710 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13713 /* In C++, we can have functions nested inside functions (e.g., when
13714 a function declares a class that has methods). This means that
13715 when we finish processing a function scope, we may need to go
13716 back to building a containing block's symbol lists. */
13717 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13718 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13720 /* If we've finished processing a top-level function, subsequent
13721 symbols go in the file symbol list. */
13722 if (cu
->get_builder ()->outermost_context_p ())
13723 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13726 /* Process all the DIES contained within a lexical block scope. Start
13727 a new scope, process the dies, and then close the scope. */
13730 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13732 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13733 struct gdbarch
*gdbarch
= objfile
->arch ();
13734 CORE_ADDR lowpc
, highpc
;
13735 struct die_info
*child_die
;
13736 CORE_ADDR baseaddr
;
13738 baseaddr
= objfile
->text_section_offset ();
13740 /* Ignore blocks with missing or invalid low and high pc attributes. */
13741 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13742 as multiple lexical blocks? Handling children in a sane way would
13743 be nasty. Might be easier to properly extend generic blocks to
13744 describe ranges. */
13745 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13747 case PC_BOUNDS_NOT_PRESENT
:
13748 /* DW_TAG_lexical_block has no attributes, process its children as if
13749 there was no wrapping by that DW_TAG_lexical_block.
13750 GCC does no longer produces such DWARF since GCC r224161. */
13751 for (child_die
= die
->child
;
13752 child_die
!= NULL
&& child_die
->tag
;
13753 child_die
= child_die
->sibling
)
13755 /* We might already be processing this DIE. This can happen
13756 in an unusual circumstance -- where a subroutine A
13757 appears lexically in another subroutine B, but A actually
13758 inlines B. The recursion is broken here, rather than in
13759 inherit_abstract_dies, because it seems better to simply
13760 drop concrete children here. */
13761 if (!child_die
->in_process
)
13762 process_die (child_die
, cu
);
13765 case PC_BOUNDS_INVALID
:
13768 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13769 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13771 cu
->get_builder ()->push_context (0, lowpc
);
13772 if (die
->child
!= NULL
)
13774 child_die
= die
->child
;
13775 while (child_die
&& child_die
->tag
)
13777 process_die (child_die
, cu
);
13778 child_die
= child_die
->sibling
;
13781 inherit_abstract_dies (die
, cu
);
13782 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13784 if (*cu
->get_builder ()->get_local_symbols () != NULL
13785 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13787 struct block
*block
13788 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13789 cstk
.start_addr
, highpc
);
13791 /* Note that recording ranges after traversing children, as we
13792 do here, means that recording a parent's ranges entails
13793 walking across all its children's ranges as they appear in
13794 the address map, which is quadratic behavior.
13796 It would be nicer to record the parent's ranges before
13797 traversing its children, simply overriding whatever you find
13798 there. But since we don't even decide whether to create a
13799 block until after we've traversed its children, that's hard
13801 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13803 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13804 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13807 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13810 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13812 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13813 struct objfile
*objfile
= per_objfile
->objfile
;
13814 struct gdbarch
*gdbarch
= objfile
->arch ();
13815 CORE_ADDR pc
, baseaddr
;
13816 struct attribute
*attr
;
13817 struct call_site
*call_site
, call_site_local
;
13820 struct die_info
*child_die
;
13822 baseaddr
= objfile
->text_section_offset ();
13824 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13827 /* This was a pre-DWARF-5 GNU extension alias
13828 for DW_AT_call_return_pc. */
13829 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13833 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13834 "DIE %s [in module %s]"),
13835 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13838 pc
= attr
->as_address () + baseaddr
;
13839 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13841 if (cu
->call_site_htab
== NULL
)
13842 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13843 NULL
, &objfile
->objfile_obstack
,
13844 hashtab_obstack_allocate
, NULL
);
13845 call_site_local
.pc
= pc
;
13846 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13849 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13850 "DIE %s [in module %s]"),
13851 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13852 objfile_name (objfile
));
13856 /* Count parameters at the caller. */
13859 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13860 child_die
= child_die
->sibling
)
13862 if (child_die
->tag
!= DW_TAG_call_site_parameter
13863 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13865 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13866 "DW_TAG_call_site child DIE %s [in module %s]"),
13867 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13868 objfile_name (objfile
));
13876 = ((struct call_site
*)
13877 obstack_alloc (&objfile
->objfile_obstack
,
13878 sizeof (*call_site
)
13879 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13881 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13882 call_site
->pc
= pc
;
13884 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13885 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13887 struct die_info
*func_die
;
13889 /* Skip also over DW_TAG_inlined_subroutine. */
13890 for (func_die
= die
->parent
;
13891 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13892 && func_die
->tag
!= DW_TAG_subroutine_type
;
13893 func_die
= func_die
->parent
);
13895 /* DW_AT_call_all_calls is a superset
13896 of DW_AT_call_all_tail_calls. */
13898 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13899 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13900 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13901 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13903 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13904 not complete. But keep CALL_SITE for look ups via call_site_htab,
13905 both the initial caller containing the real return address PC and
13906 the final callee containing the current PC of a chain of tail
13907 calls do not need to have the tail call list complete. But any
13908 function candidate for a virtual tail call frame searched via
13909 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13910 determined unambiguously. */
13914 struct type
*func_type
= NULL
;
13917 func_type
= get_die_type (func_die
, cu
);
13918 if (func_type
!= NULL
)
13920 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13922 /* Enlist this call site to the function. */
13923 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13924 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13927 complaint (_("Cannot find function owning DW_TAG_call_site "
13928 "DIE %s [in module %s]"),
13929 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13933 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13935 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13937 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13940 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13941 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13943 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13944 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13945 /* Keep NULL DWARF_BLOCK. */;
13946 else if (attr
->form_is_block ())
13948 struct dwarf2_locexpr_baton
*dlbaton
;
13949 struct dwarf_block
*block
= attr
->as_block ();
13951 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13952 dlbaton
->data
= block
->data
;
13953 dlbaton
->size
= block
->size
;
13954 dlbaton
->per_objfile
= per_objfile
;
13955 dlbaton
->per_cu
= cu
->per_cu
;
13957 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13959 else if (attr
->form_is_ref ())
13961 struct dwarf2_cu
*target_cu
= cu
;
13962 struct die_info
*target_die
;
13964 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13965 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13966 if (die_is_declaration (target_die
, target_cu
))
13968 const char *target_physname
;
13970 /* Prefer the mangled name; otherwise compute the demangled one. */
13971 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13972 if (target_physname
== NULL
)
13973 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13974 if (target_physname
== NULL
)
13975 complaint (_("DW_AT_call_target target DIE has invalid "
13976 "physname, for referencing DIE %s [in module %s]"),
13977 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13979 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13985 /* DW_AT_entry_pc should be preferred. */
13986 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13987 <= PC_BOUNDS_INVALID
)
13988 complaint (_("DW_AT_call_target target DIE has invalid "
13989 "low pc, for referencing DIE %s [in module %s]"),
13990 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13993 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13994 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13999 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14000 "block nor reference, for DIE %s [in module %s]"),
14001 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14003 call_site
->per_cu
= cu
->per_cu
;
14004 call_site
->per_objfile
= per_objfile
;
14006 for (child_die
= die
->child
;
14007 child_die
&& child_die
->tag
;
14008 child_die
= child_die
->sibling
)
14010 struct call_site_parameter
*parameter
;
14011 struct attribute
*loc
, *origin
;
14013 if (child_die
->tag
!= DW_TAG_call_site_parameter
14014 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14016 /* Already printed the complaint above. */
14020 gdb_assert (call_site
->parameter_count
< nparams
);
14021 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14023 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14024 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14025 register is contained in DW_AT_call_value. */
14027 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14028 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14029 if (origin
== NULL
)
14031 /* This was a pre-DWARF-5 GNU extension alias
14032 for DW_AT_call_parameter. */
14033 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14035 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
14037 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14039 sect_offset sect_off
= origin
->get_ref_die_offset ();
14040 if (!cu
->header
.offset_in_cu_p (sect_off
))
14042 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14043 binding can be done only inside one CU. Such referenced DIE
14044 therefore cannot be even moved to DW_TAG_partial_unit. */
14045 complaint (_("DW_AT_call_parameter offset is not in CU for "
14046 "DW_TAG_call_site child DIE %s [in module %s]"),
14047 sect_offset_str (child_die
->sect_off
),
14048 objfile_name (objfile
));
14051 parameter
->u
.param_cu_off
14052 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14054 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
14056 complaint (_("No DW_FORM_block* DW_AT_location for "
14057 "DW_TAG_call_site child DIE %s [in module %s]"),
14058 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14063 struct dwarf_block
*block
= loc
->as_block ();
14065 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14066 (block
->data
, &block
->data
[block
->size
]);
14067 if (parameter
->u
.dwarf_reg
!= -1)
14068 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14069 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
14070 &block
->data
[block
->size
],
14071 ¶meter
->u
.fb_offset
))
14072 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14075 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14076 "for DW_FORM_block* DW_AT_location is supported for "
14077 "DW_TAG_call_site child DIE %s "
14079 sect_offset_str (child_die
->sect_off
),
14080 objfile_name (objfile
));
14085 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14087 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14088 if (attr
== NULL
|| !attr
->form_is_block ())
14090 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14091 "DW_TAG_call_site child DIE %s [in module %s]"),
14092 sect_offset_str (child_die
->sect_off
),
14093 objfile_name (objfile
));
14097 struct dwarf_block
*block
= attr
->as_block ();
14098 parameter
->value
= block
->data
;
14099 parameter
->value_size
= block
->size
;
14101 /* Parameters are not pre-cleared by memset above. */
14102 parameter
->data_value
= NULL
;
14103 parameter
->data_value_size
= 0;
14104 call_site
->parameter_count
++;
14106 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14108 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14109 if (attr
!= nullptr)
14111 if (!attr
->form_is_block ())
14112 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14113 "DW_TAG_call_site child DIE %s [in module %s]"),
14114 sect_offset_str (child_die
->sect_off
),
14115 objfile_name (objfile
));
14118 block
= attr
->as_block ();
14119 parameter
->data_value
= block
->data
;
14120 parameter
->data_value_size
= block
->size
;
14126 /* Helper function for read_variable. If DIE represents a virtual
14127 table, then return the type of the concrete object that is
14128 associated with the virtual table. Otherwise, return NULL. */
14130 static struct type
*
14131 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14133 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14137 /* Find the type DIE. */
14138 struct die_info
*type_die
= NULL
;
14139 struct dwarf2_cu
*type_cu
= cu
;
14141 if (attr
->form_is_ref ())
14142 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14143 if (type_die
== NULL
)
14146 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14148 return die_containing_type (type_die
, type_cu
);
14151 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14154 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14156 struct rust_vtable_symbol
*storage
= NULL
;
14158 if (cu
->language
== language_rust
)
14160 struct type
*containing_type
= rust_containing_type (die
, cu
);
14162 if (containing_type
!= NULL
)
14164 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14166 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
14167 storage
->concrete_type
= containing_type
;
14168 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14172 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14173 struct attribute
*abstract_origin
14174 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14175 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14176 if (res
== NULL
&& loc
&& abstract_origin
)
14178 /* We have a variable without a name, but with a location and an abstract
14179 origin. This may be a concrete instance of an abstract variable
14180 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14182 struct dwarf2_cu
*origin_cu
= cu
;
14183 struct die_info
*origin_die
14184 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14185 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14186 per_objfile
->per_bfd
->abstract_to_concrete
14187 [origin_die
->sect_off
].push_back (die
->sect_off
);
14191 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14192 reading .debug_rnglists.
14193 Callback's type should be:
14194 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14195 Return true if the attributes are present and valid, otherwise,
14198 template <typename Callback
>
14200 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14201 dwarf_tag tag
, Callback
&&callback
)
14203 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14204 struct objfile
*objfile
= per_objfile
->objfile
;
14205 bfd
*obfd
= objfile
->obfd
;
14206 /* Base address selection entry. */
14207 gdb::optional
<CORE_ADDR
> base
;
14208 const gdb_byte
*buffer
;
14209 CORE_ADDR baseaddr
;
14210 bool overflow
= false;
14211 ULONGEST addr_index
;
14212 struct dwarf2_section_info
*rnglists_section
;
14214 base
= cu
->base_address
;
14215 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14216 rnglists_section
->read (objfile
);
14218 if (offset
>= rnglists_section
->size
)
14220 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14224 buffer
= rnglists_section
->buffer
+ offset
;
14226 baseaddr
= objfile
->text_section_offset ();
14230 /* Initialize it due to a false compiler warning. */
14231 CORE_ADDR range_beginning
= 0, range_end
= 0;
14232 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14233 + rnglists_section
->size
);
14234 unsigned int bytes_read
;
14236 if (buffer
== buf_end
)
14241 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14244 case DW_RLE_end_of_list
:
14246 case DW_RLE_base_address
:
14247 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14252 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14253 buffer
+= bytes_read
;
14255 case DW_RLE_base_addressx
:
14256 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14257 buffer
+= bytes_read
;
14258 base
= read_addr_index (cu
, addr_index
);
14260 case DW_RLE_start_length
:
14261 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14266 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14268 buffer
+= bytes_read
;
14269 range_end
= (range_beginning
14270 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14271 buffer
+= bytes_read
;
14272 if (buffer
> buf_end
)
14278 case DW_RLE_startx_length
:
14279 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14280 buffer
+= bytes_read
;
14281 range_beginning
= read_addr_index (cu
, addr_index
);
14282 if (buffer
> buf_end
)
14287 range_end
= (range_beginning
14288 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14289 buffer
+= bytes_read
;
14291 case DW_RLE_offset_pair
:
14292 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14293 buffer
+= bytes_read
;
14294 if (buffer
> buf_end
)
14299 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14300 buffer
+= bytes_read
;
14301 if (buffer
> buf_end
)
14307 case DW_RLE_start_end
:
14308 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14313 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14315 buffer
+= bytes_read
;
14316 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14317 buffer
+= bytes_read
;
14319 case DW_RLE_startx_endx
:
14320 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14321 buffer
+= bytes_read
;
14322 range_beginning
= read_addr_index (cu
, addr_index
);
14323 if (buffer
> buf_end
)
14328 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14329 buffer
+= bytes_read
;
14330 range_end
= read_addr_index (cu
, addr_index
);
14333 complaint (_("Invalid .debug_rnglists data (no base address)"));
14336 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14338 if (rlet
== DW_RLE_base_address
)
14341 if (range_beginning
> range_end
)
14343 /* Inverted range entries are invalid. */
14344 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14348 /* Empty range entries have no effect. */
14349 if (range_beginning
== range_end
)
14352 /* Only DW_RLE_offset_pair needs the base address added. */
14353 if (rlet
== DW_RLE_offset_pair
)
14355 if (!base
.has_value ())
14357 /* We have no valid base address for the DW_RLE_offset_pair. */
14358 complaint (_("Invalid .debug_rnglists data (no base address for "
14359 "DW_RLE_offset_pair)"));
14363 range_beginning
+= *base
;
14364 range_end
+= *base
;
14367 /* A not-uncommon case of bad debug info.
14368 Don't pollute the addrmap with bad data. */
14369 if (range_beginning
+ baseaddr
== 0
14370 && !per_objfile
->per_bfd
->has_section_at_zero
)
14372 complaint (_(".debug_rnglists entry has start address of zero"
14373 " [in module %s]"), objfile_name (objfile
));
14377 callback (range_beginning
, range_end
);
14382 complaint (_("Offset %d is not terminated "
14383 "for DW_AT_ranges attribute"),
14391 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14392 Callback's type should be:
14393 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14394 Return 1 if the attributes are present and valid, otherwise, return 0. */
14396 template <typename Callback
>
14398 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14399 Callback
&&callback
)
14401 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14402 struct objfile
*objfile
= per_objfile
->objfile
;
14403 struct comp_unit_head
*cu_header
= &cu
->header
;
14404 bfd
*obfd
= objfile
->obfd
;
14405 unsigned int addr_size
= cu_header
->addr_size
;
14406 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14407 /* Base address selection entry. */
14408 gdb::optional
<CORE_ADDR
> base
;
14409 unsigned int dummy
;
14410 const gdb_byte
*buffer
;
14411 CORE_ADDR baseaddr
;
14413 if (cu_header
->version
>= 5)
14414 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14416 base
= cu
->base_address
;
14418 per_objfile
->per_bfd
->ranges
.read (objfile
);
14419 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14421 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14425 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14427 baseaddr
= objfile
->text_section_offset ();
14431 CORE_ADDR range_beginning
, range_end
;
14433 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14434 buffer
+= addr_size
;
14435 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14436 buffer
+= addr_size
;
14437 offset
+= 2 * addr_size
;
14439 /* An end of list marker is a pair of zero addresses. */
14440 if (range_beginning
== 0 && range_end
== 0)
14441 /* Found the end of list entry. */
14444 /* Each base address selection entry is a pair of 2 values.
14445 The first is the largest possible address, the second is
14446 the base address. Check for a base address here. */
14447 if ((range_beginning
& mask
) == mask
)
14449 /* If we found the largest possible address, then we already
14450 have the base address in range_end. */
14455 if (!base
.has_value ())
14457 /* We have no valid base address for the ranges
14459 complaint (_("Invalid .debug_ranges data (no base address)"));
14463 if (range_beginning
> range_end
)
14465 /* Inverted range entries are invalid. */
14466 complaint (_("Invalid .debug_ranges data (inverted range)"));
14470 /* Empty range entries have no effect. */
14471 if (range_beginning
== range_end
)
14474 range_beginning
+= *base
;
14475 range_end
+= *base
;
14477 /* A not-uncommon case of bad debug info.
14478 Don't pollute the addrmap with bad data. */
14479 if (range_beginning
+ baseaddr
== 0
14480 && !per_objfile
->per_bfd
->has_section_at_zero
)
14482 complaint (_(".debug_ranges entry has start address of zero"
14483 " [in module %s]"), objfile_name (objfile
));
14487 callback (range_beginning
, range_end
);
14493 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14494 Return 1 if the attributes are present and valid, otherwise, return 0.
14495 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14498 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14499 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14500 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14502 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14503 struct gdbarch
*gdbarch
= objfile
->arch ();
14504 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14507 CORE_ADDR high
= 0;
14510 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14511 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14513 if (ranges_pst
!= NULL
)
14518 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14519 range_beginning
+ baseaddr
)
14521 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14522 range_end
+ baseaddr
)
14524 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14525 lowpc
, highpc
- 1, ranges_pst
);
14528 /* FIXME: This is recording everything as a low-high
14529 segment of consecutive addresses. We should have a
14530 data structure for discontiguous block ranges
14534 low
= range_beginning
;
14540 if (range_beginning
< low
)
14541 low
= range_beginning
;
14542 if (range_end
> high
)
14550 /* If the first entry is an end-of-list marker, the range
14551 describes an empty scope, i.e. no instructions. */
14557 *high_return
= high
;
14561 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14562 definition for the return value. *LOWPC and *HIGHPC are set iff
14563 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14565 static enum pc_bounds_kind
14566 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14567 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14568 dwarf2_psymtab
*pst
)
14570 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14571 struct attribute
*attr
;
14572 struct attribute
*attr_high
;
14574 CORE_ADDR high
= 0;
14575 enum pc_bounds_kind ret
;
14577 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14580 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14581 if (attr
!= nullptr)
14583 low
= attr
->as_address ();
14584 high
= attr_high
->as_address ();
14585 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14589 /* Found high w/o low attribute. */
14590 return PC_BOUNDS_INVALID
;
14592 /* Found consecutive range of addresses. */
14593 ret
= PC_BOUNDS_HIGH_LOW
;
14597 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14598 if (attr
!= nullptr && attr
->form_is_unsigned ())
14600 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14601 We take advantage of the fact that DW_AT_ranges does not appear
14602 in DW_TAG_compile_unit of DWO files.
14604 Attributes of the form DW_FORM_rnglistx have already had their
14605 value changed by read_rnglist_index and already include
14606 DW_AT_rnglists_base, so don't need to add the ranges base,
14608 int need_ranges_base
= (die
->tag
!= DW_TAG_compile_unit
14609 && attr
->form
!= DW_FORM_rnglistx
);
14610 unsigned int ranges_offset
= (attr
->as_unsigned ()
14611 + (need_ranges_base
14615 /* Value of the DW_AT_ranges attribute is the offset in the
14616 .debug_ranges section. */
14617 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14619 return PC_BOUNDS_INVALID
;
14620 /* Found discontinuous range of addresses. */
14621 ret
= PC_BOUNDS_RANGES
;
14624 return PC_BOUNDS_NOT_PRESENT
;
14627 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14629 return PC_BOUNDS_INVALID
;
14631 /* When using the GNU linker, .gnu.linkonce. sections are used to
14632 eliminate duplicate copies of functions and vtables and such.
14633 The linker will arbitrarily choose one and discard the others.
14634 The AT_*_pc values for such functions refer to local labels in
14635 these sections. If the section from that file was discarded, the
14636 labels are not in the output, so the relocs get a value of 0.
14637 If this is a discarded function, mark the pc bounds as invalid,
14638 so that GDB will ignore it. */
14639 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14640 return PC_BOUNDS_INVALID
;
14648 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14649 its low and high PC addresses. Do nothing if these addresses could not
14650 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14651 and HIGHPC to the high address if greater than HIGHPC. */
14654 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14655 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14656 struct dwarf2_cu
*cu
)
14658 CORE_ADDR low
, high
;
14659 struct die_info
*child
= die
->child
;
14661 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14663 *lowpc
= std::min (*lowpc
, low
);
14664 *highpc
= std::max (*highpc
, high
);
14667 /* If the language does not allow nested subprograms (either inside
14668 subprograms or lexical blocks), we're done. */
14669 if (cu
->language
!= language_ada
)
14672 /* Check all the children of the given DIE. If it contains nested
14673 subprograms, then check their pc bounds. Likewise, we need to
14674 check lexical blocks as well, as they may also contain subprogram
14676 while (child
&& child
->tag
)
14678 if (child
->tag
== DW_TAG_subprogram
14679 || child
->tag
== DW_TAG_lexical_block
)
14680 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14681 child
= child
->sibling
;
14685 /* Get the low and high pc's represented by the scope DIE, and store
14686 them in *LOWPC and *HIGHPC. If the correct values can't be
14687 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14690 get_scope_pc_bounds (struct die_info
*die
,
14691 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14692 struct dwarf2_cu
*cu
)
14694 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14695 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14696 CORE_ADDR current_low
, current_high
;
14698 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14699 >= PC_BOUNDS_RANGES
)
14701 best_low
= current_low
;
14702 best_high
= current_high
;
14706 struct die_info
*child
= die
->child
;
14708 while (child
&& child
->tag
)
14710 switch (child
->tag
) {
14711 case DW_TAG_subprogram
:
14712 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14714 case DW_TAG_namespace
:
14715 case DW_TAG_module
:
14716 /* FIXME: carlton/2004-01-16: Should we do this for
14717 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14718 that current GCC's always emit the DIEs corresponding
14719 to definitions of methods of classes as children of a
14720 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14721 the DIEs giving the declarations, which could be
14722 anywhere). But I don't see any reason why the
14723 standards says that they have to be there. */
14724 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14726 if (current_low
!= ((CORE_ADDR
) -1))
14728 best_low
= std::min (best_low
, current_low
);
14729 best_high
= std::max (best_high
, current_high
);
14737 child
= child
->sibling
;
14742 *highpc
= best_high
;
14745 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14749 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14750 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14752 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14753 struct gdbarch
*gdbarch
= objfile
->arch ();
14754 struct attribute
*attr
;
14755 struct attribute
*attr_high
;
14757 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14760 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14761 if (attr
!= nullptr)
14763 CORE_ADDR low
= attr
->as_address ();
14764 CORE_ADDR high
= attr_high
->as_address ();
14766 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14769 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14770 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14771 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14775 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14776 if (attr
!= nullptr && attr
->form_is_unsigned ())
14778 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14779 We take advantage of the fact that DW_AT_ranges does not appear
14780 in DW_TAG_compile_unit of DWO files.
14782 Attributes of the form DW_FORM_rnglistx have already had their
14783 value changed by read_rnglist_index and already include
14784 DW_AT_rnglists_base, so don't need to add the ranges base,
14786 int need_ranges_base
= (die
->tag
!= DW_TAG_compile_unit
14787 && attr
->form
!= DW_FORM_rnglistx
);
14789 /* The value of the DW_AT_ranges attribute is the offset of the
14790 address range list in the .debug_ranges section. */
14791 unsigned long offset
= (attr
->as_unsigned ()
14792 + (need_ranges_base
? cu
->ranges_base
: 0));
14794 std::vector
<blockrange
> blockvec
;
14795 dwarf2_ranges_process (offset
, cu
, die
->tag
,
14796 [&] (CORE_ADDR start
, CORE_ADDR end
)
14800 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14801 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14802 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14803 blockvec
.emplace_back (start
, end
);
14806 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14810 /* Check whether the producer field indicates either of GCC < 4.6, or the
14811 Intel C/C++ compiler, and cache the result in CU. */
14814 check_producer (struct dwarf2_cu
*cu
)
14818 if (cu
->producer
== NULL
)
14820 /* For unknown compilers expect their behavior is DWARF version
14823 GCC started to support .debug_types sections by -gdwarf-4 since
14824 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14825 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14826 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14827 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14829 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14831 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14832 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14834 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14836 cu
->producer_is_icc
= true;
14837 cu
->producer_is_icc_lt_14
= major
< 14;
14839 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14840 cu
->producer_is_codewarrior
= true;
14843 /* For other non-GCC compilers, expect their behavior is DWARF version
14847 cu
->checked_producer
= true;
14850 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14851 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14852 during 4.6.0 experimental. */
14855 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14857 if (!cu
->checked_producer
)
14858 check_producer (cu
);
14860 return cu
->producer_is_gxx_lt_4_6
;
14864 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14865 with incorrect is_stmt attributes. */
14868 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14870 if (!cu
->checked_producer
)
14871 check_producer (cu
);
14873 return cu
->producer_is_codewarrior
;
14876 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14877 If that attribute is not available, return the appropriate
14880 static enum dwarf_access_attribute
14881 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14883 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14884 if (attr
!= nullptr)
14886 LONGEST value
= attr
->constant_value (-1);
14887 if (value
== DW_ACCESS_public
14888 || value
== DW_ACCESS_protected
14889 || value
== DW_ACCESS_private
)
14890 return (dwarf_access_attribute
) value
;
14891 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14895 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14897 /* The default DWARF 2 accessibility for members is public, the default
14898 accessibility for inheritance is private. */
14900 if (die
->tag
!= DW_TAG_inheritance
)
14901 return DW_ACCESS_public
;
14903 return DW_ACCESS_private
;
14907 /* DWARF 3+ defines the default accessibility a different way. The same
14908 rules apply now for DW_TAG_inheritance as for the members and it only
14909 depends on the container kind. */
14911 if (die
->parent
->tag
== DW_TAG_class_type
)
14912 return DW_ACCESS_private
;
14914 return DW_ACCESS_public
;
14918 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14919 offset. If the attribute was not found return 0, otherwise return
14920 1. If it was found but could not properly be handled, set *OFFSET
14924 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14927 struct attribute
*attr
;
14929 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14934 /* Note that we do not check for a section offset first here.
14935 This is because DW_AT_data_member_location is new in DWARF 4,
14936 so if we see it, we can assume that a constant form is really
14937 a constant and not a section offset. */
14938 if (attr
->form_is_constant ())
14939 *offset
= attr
->constant_value (0);
14940 else if (attr
->form_is_section_offset ())
14941 dwarf2_complex_location_expr_complaint ();
14942 else if (attr
->form_is_block ())
14943 *offset
= decode_locdesc (attr
->as_block (), cu
);
14945 dwarf2_complex_location_expr_complaint ();
14953 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14956 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14957 struct field
*field
)
14959 struct attribute
*attr
;
14961 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14964 if (attr
->form_is_constant ())
14966 LONGEST offset
= attr
->constant_value (0);
14967 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14969 else if (attr
->form_is_section_offset ())
14970 dwarf2_complex_location_expr_complaint ();
14971 else if (attr
->form_is_block ())
14974 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14976 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14979 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14980 struct objfile
*objfile
= per_objfile
->objfile
;
14981 struct dwarf2_locexpr_baton
*dlbaton
14982 = XOBNEW (&objfile
->objfile_obstack
,
14983 struct dwarf2_locexpr_baton
);
14984 dlbaton
->data
= attr
->as_block ()->data
;
14985 dlbaton
->size
= attr
->as_block ()->size
;
14986 /* When using this baton, we want to compute the address
14987 of the field, not the value. This is why
14988 is_reference is set to false here. */
14989 dlbaton
->is_reference
= false;
14990 dlbaton
->per_objfile
= per_objfile
;
14991 dlbaton
->per_cu
= cu
->per_cu
;
14993 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14997 dwarf2_complex_location_expr_complaint ();
15001 /* Add an aggregate field to the field list. */
15004 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15005 struct dwarf2_cu
*cu
)
15007 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15008 struct gdbarch
*gdbarch
= objfile
->arch ();
15009 struct nextfield
*new_field
;
15010 struct attribute
*attr
;
15012 const char *fieldname
= "";
15014 if (die
->tag
== DW_TAG_inheritance
)
15016 fip
->baseclasses
.emplace_back ();
15017 new_field
= &fip
->baseclasses
.back ();
15021 fip
->fields
.emplace_back ();
15022 new_field
= &fip
->fields
.back ();
15025 new_field
->offset
= die
->sect_off
;
15027 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
15028 if (new_field
->accessibility
!= DW_ACCESS_public
)
15029 fip
->non_public_fields
= true;
15031 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15032 if (attr
!= nullptr)
15033 new_field
->virtuality
= attr
->as_virtuality ();
15035 new_field
->virtuality
= DW_VIRTUALITY_none
;
15037 fp
= &new_field
->field
;
15039 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15041 /* Data member other than a C++ static data member. */
15043 /* Get type of field. */
15044 fp
->set_type (die_type (die
, cu
));
15046 SET_FIELD_BITPOS (*fp
, 0);
15048 /* Get bit size of field (zero if none). */
15049 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15050 if (attr
!= nullptr)
15052 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
15056 FIELD_BITSIZE (*fp
) = 0;
15059 /* Get bit offset of field. */
15060 handle_data_member_location (die
, cu
, fp
);
15061 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15062 if (attr
!= nullptr && attr
->form_is_constant ())
15064 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15066 /* For big endian bits, the DW_AT_bit_offset gives the
15067 additional bit offset from the MSB of the containing
15068 anonymous object to the MSB of the field. We don't
15069 have to do anything special since we don't need to
15070 know the size of the anonymous object. */
15071 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15072 + attr
->constant_value (0)));
15076 /* For little endian bits, compute the bit offset to the
15077 MSB of the anonymous object, subtract off the number of
15078 bits from the MSB of the field to the MSB of the
15079 object, and then subtract off the number of bits of
15080 the field itself. The result is the bit offset of
15081 the LSB of the field. */
15082 int anonymous_size
;
15083 int bit_offset
= attr
->constant_value (0);
15085 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15086 if (attr
!= nullptr && attr
->form_is_constant ())
15088 /* The size of the anonymous object containing
15089 the bit field is explicit, so use the
15090 indicated size (in bytes). */
15091 anonymous_size
= attr
->constant_value (0);
15095 /* The size of the anonymous object containing
15096 the bit field must be inferred from the type
15097 attribute of the data member containing the
15099 anonymous_size
= TYPE_LENGTH (fp
->type ());
15101 SET_FIELD_BITPOS (*fp
,
15102 (FIELD_BITPOS (*fp
)
15103 + anonymous_size
* bits_per_byte
15104 - bit_offset
- FIELD_BITSIZE (*fp
)));
15107 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15109 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15110 + attr
->constant_value (0)));
15112 /* Get name of field. */
15113 fieldname
= dwarf2_name (die
, cu
);
15114 if (fieldname
== NULL
)
15117 /* The name is already allocated along with this objfile, so we don't
15118 need to duplicate it for the type. */
15119 fp
->name
= fieldname
;
15121 /* Change accessibility for artificial fields (e.g. virtual table
15122 pointer or virtual base class pointer) to private. */
15123 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15125 FIELD_ARTIFICIAL (*fp
) = 1;
15126 new_field
->accessibility
= DW_ACCESS_private
;
15127 fip
->non_public_fields
= true;
15130 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15132 /* C++ static member. */
15134 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15135 is a declaration, but all versions of G++ as of this writing
15136 (so through at least 3.2.1) incorrectly generate
15137 DW_TAG_variable tags. */
15139 const char *physname
;
15141 /* Get name of field. */
15142 fieldname
= dwarf2_name (die
, cu
);
15143 if (fieldname
== NULL
)
15146 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15148 /* Only create a symbol if this is an external value.
15149 new_symbol checks this and puts the value in the global symbol
15150 table, which we want. If it is not external, new_symbol
15151 will try to put the value in cu->list_in_scope which is wrong. */
15152 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15154 /* A static const member, not much different than an enum as far as
15155 we're concerned, except that we can support more types. */
15156 new_symbol (die
, NULL
, cu
);
15159 /* Get physical name. */
15160 physname
= dwarf2_physname (fieldname
, die
, cu
);
15162 /* The name is already allocated along with this objfile, so we don't
15163 need to duplicate it for the type. */
15164 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15165 fp
->set_type (die_type (die
, cu
));
15166 FIELD_NAME (*fp
) = fieldname
;
15168 else if (die
->tag
== DW_TAG_inheritance
)
15170 /* C++ base class field. */
15171 handle_data_member_location (die
, cu
, fp
);
15172 FIELD_BITSIZE (*fp
) = 0;
15173 fp
->set_type (die_type (die
, cu
));
15174 FIELD_NAME (*fp
) = fp
->type ()->name ();
15177 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15180 /* Can the type given by DIE define another type? */
15183 type_can_define_types (const struct die_info
*die
)
15187 case DW_TAG_typedef
:
15188 case DW_TAG_class_type
:
15189 case DW_TAG_structure_type
:
15190 case DW_TAG_union_type
:
15191 case DW_TAG_enumeration_type
:
15199 /* Add a type definition defined in the scope of the FIP's class. */
15202 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15203 struct dwarf2_cu
*cu
)
15205 struct decl_field fp
;
15206 memset (&fp
, 0, sizeof (fp
));
15208 gdb_assert (type_can_define_types (die
));
15210 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15211 fp
.name
= dwarf2_name (die
, cu
);
15212 fp
.type
= read_type_die (die
, cu
);
15214 /* Save accessibility. */
15215 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15216 switch (accessibility
)
15218 case DW_ACCESS_public
:
15219 /* The assumed value if neither private nor protected. */
15221 case DW_ACCESS_private
:
15224 case DW_ACCESS_protected
:
15225 fp
.is_protected
= 1;
15229 if (die
->tag
== DW_TAG_typedef
)
15230 fip
->typedef_field_list
.push_back (fp
);
15232 fip
->nested_types_list
.push_back (fp
);
15235 /* A convenience typedef that's used when finding the discriminant
15236 field for a variant part. */
15237 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15240 /* Compute the discriminant range for a given variant. OBSTACK is
15241 where the results will be stored. VARIANT is the variant to
15242 process. IS_UNSIGNED indicates whether the discriminant is signed
15245 static const gdb::array_view
<discriminant_range
>
15246 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15249 std::vector
<discriminant_range
> ranges
;
15251 if (variant
.default_branch
)
15254 if (variant
.discr_list_data
== nullptr)
15256 discriminant_range r
15257 = {variant
.discriminant_value
, variant
.discriminant_value
};
15258 ranges
.push_back (r
);
15262 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15263 variant
.discr_list_data
->size
);
15264 while (!data
.empty ())
15266 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15268 complaint (_("invalid discriminant marker: %d"), data
[0]);
15271 bool is_range
= data
[0] == DW_DSC_range
;
15272 data
= data
.slice (1);
15274 ULONGEST low
, high
;
15275 unsigned int bytes_read
;
15279 complaint (_("DW_AT_discr_list missing low value"));
15283 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15285 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15287 data
= data
.slice (bytes_read
);
15293 complaint (_("DW_AT_discr_list missing high value"));
15297 high
= read_unsigned_leb128 (nullptr, data
.data (),
15300 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15302 data
= data
.slice (bytes_read
);
15307 ranges
.push_back ({ low
, high
});
15311 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15313 std::copy (ranges
.begin (), ranges
.end (), result
);
15314 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15317 static const gdb::array_view
<variant_part
> create_variant_parts
15318 (struct obstack
*obstack
,
15319 const offset_map_type
&offset_map
,
15320 struct field_info
*fi
,
15321 const std::vector
<variant_part_builder
> &variant_parts
);
15323 /* Fill in a "struct variant" for a given variant field. RESULT is
15324 the variant to fill in. OBSTACK is where any needed allocations
15325 will be done. OFFSET_MAP holds the mapping from section offsets to
15326 fields for the type. FI describes the fields of the type we're
15327 processing. FIELD is the variant field we're converting. */
15330 create_one_variant (variant
&result
, struct obstack
*obstack
,
15331 const offset_map_type
&offset_map
,
15332 struct field_info
*fi
, const variant_field
&field
)
15334 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15335 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15336 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15337 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15338 field
.variant_parts
);
15341 /* Fill in a "struct variant_part" for a given variant part. RESULT
15342 is the variant part to fill in. OBSTACK is where any needed
15343 allocations will be done. OFFSET_MAP holds the mapping from
15344 section offsets to fields for the type. FI describes the fields of
15345 the type we're processing. BUILDER is the variant part to be
15349 create_one_variant_part (variant_part
&result
,
15350 struct obstack
*obstack
,
15351 const offset_map_type
&offset_map
,
15352 struct field_info
*fi
,
15353 const variant_part_builder
&builder
)
15355 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15356 if (iter
== offset_map
.end ())
15358 result
.discriminant_index
= -1;
15359 /* Doesn't matter. */
15360 result
.is_unsigned
= false;
15364 result
.discriminant_index
= iter
->second
;
15366 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15369 size_t n
= builder
.variants
.size ();
15370 variant
*output
= new (obstack
) variant
[n
];
15371 for (size_t i
= 0; i
< n
; ++i
)
15372 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15373 builder
.variants
[i
]);
15375 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15378 /* Create a vector of variant parts that can be attached to a type.
15379 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15380 holds the mapping from section offsets to fields for the type. FI
15381 describes the fields of the type we're processing. VARIANT_PARTS
15382 is the vector to convert. */
15384 static const gdb::array_view
<variant_part
>
15385 create_variant_parts (struct obstack
*obstack
,
15386 const offset_map_type
&offset_map
,
15387 struct field_info
*fi
,
15388 const std::vector
<variant_part_builder
> &variant_parts
)
15390 if (variant_parts
.empty ())
15393 size_t n
= variant_parts
.size ();
15394 variant_part
*result
= new (obstack
) variant_part
[n
];
15395 for (size_t i
= 0; i
< n
; ++i
)
15396 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15399 return gdb::array_view
<variant_part
> (result
, n
);
15402 /* Compute the variant part vector for FIP, attaching it to TYPE when
15406 add_variant_property (struct field_info
*fip
, struct type
*type
,
15407 struct dwarf2_cu
*cu
)
15409 /* Map section offsets of fields to their field index. Note the
15410 field index here does not take the number of baseclasses into
15412 offset_map_type offset_map
;
15413 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15414 offset_map
[fip
->fields
[i
].offset
] = i
;
15416 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15417 gdb::array_view
<variant_part
> parts
15418 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15419 fip
->variant_parts
);
15421 struct dynamic_prop prop
;
15422 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15423 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15426 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15429 /* Create the vector of fields, and attach it to the type. */
15432 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15433 struct dwarf2_cu
*cu
)
15435 int nfields
= fip
->nfields ();
15437 /* Record the field count, allocate space for the array of fields,
15438 and create blank accessibility bitfields if necessary. */
15439 type
->set_num_fields (nfields
);
15441 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15443 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15445 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15447 TYPE_FIELD_PRIVATE_BITS (type
) =
15448 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15449 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15451 TYPE_FIELD_PROTECTED_BITS (type
) =
15452 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15453 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15455 TYPE_FIELD_IGNORE_BITS (type
) =
15456 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15457 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15460 /* If the type has baseclasses, allocate and clear a bit vector for
15461 TYPE_FIELD_VIRTUAL_BITS. */
15462 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15464 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15465 unsigned char *pointer
;
15467 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15468 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15469 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15470 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15471 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15474 if (!fip
->variant_parts
.empty ())
15475 add_variant_property (fip
, type
, cu
);
15477 /* Copy the saved-up fields into the field vector. */
15478 for (int i
= 0; i
< nfields
; ++i
)
15480 struct nextfield
&field
15481 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15482 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15484 type
->field (i
) = field
.field
;
15485 switch (field
.accessibility
)
15487 case DW_ACCESS_private
:
15488 if (cu
->language
!= language_ada
)
15489 SET_TYPE_FIELD_PRIVATE (type
, i
);
15492 case DW_ACCESS_protected
:
15493 if (cu
->language
!= language_ada
)
15494 SET_TYPE_FIELD_PROTECTED (type
, i
);
15497 case DW_ACCESS_public
:
15501 /* Unknown accessibility. Complain and treat it as public. */
15503 complaint (_("unsupported accessibility %d"),
15504 field
.accessibility
);
15508 if (i
< fip
->baseclasses
.size ())
15510 switch (field
.virtuality
)
15512 case DW_VIRTUALITY_virtual
:
15513 case DW_VIRTUALITY_pure_virtual
:
15514 if (cu
->language
== language_ada
)
15515 error (_("unexpected virtuality in component of Ada type"));
15516 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15523 /* Return true if this member function is a constructor, false
15527 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15529 const char *fieldname
;
15530 const char *type_name
;
15533 if (die
->parent
== NULL
)
15536 if (die
->parent
->tag
!= DW_TAG_structure_type
15537 && die
->parent
->tag
!= DW_TAG_union_type
15538 && die
->parent
->tag
!= DW_TAG_class_type
)
15541 fieldname
= dwarf2_name (die
, cu
);
15542 type_name
= dwarf2_name (die
->parent
, cu
);
15543 if (fieldname
== NULL
|| type_name
== NULL
)
15546 len
= strlen (fieldname
);
15547 return (strncmp (fieldname
, type_name
, len
) == 0
15548 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15551 /* Add a member function to the proper fieldlist. */
15554 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15555 struct type
*type
, struct dwarf2_cu
*cu
)
15557 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15558 struct attribute
*attr
;
15560 struct fnfieldlist
*flp
= nullptr;
15561 struct fn_field
*fnp
;
15562 const char *fieldname
;
15563 struct type
*this_type
;
15565 if (cu
->language
== language_ada
)
15566 error (_("unexpected member function in Ada type"));
15568 /* Get name of member function. */
15569 fieldname
= dwarf2_name (die
, cu
);
15570 if (fieldname
== NULL
)
15573 /* Look up member function name in fieldlist. */
15574 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15576 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15578 flp
= &fip
->fnfieldlists
[i
];
15583 /* Create a new fnfieldlist if necessary. */
15584 if (flp
== nullptr)
15586 fip
->fnfieldlists
.emplace_back ();
15587 flp
= &fip
->fnfieldlists
.back ();
15588 flp
->name
= fieldname
;
15589 i
= fip
->fnfieldlists
.size () - 1;
15592 /* Create a new member function field and add it to the vector of
15594 flp
->fnfields
.emplace_back ();
15595 fnp
= &flp
->fnfields
.back ();
15597 /* Delay processing of the physname until later. */
15598 if (cu
->language
== language_cplus
)
15599 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15603 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15604 fnp
->physname
= physname
? physname
: "";
15607 fnp
->type
= alloc_type (objfile
);
15608 this_type
= read_type_die (die
, cu
);
15609 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15611 int nparams
= this_type
->num_fields ();
15613 /* TYPE is the domain of this method, and THIS_TYPE is the type
15614 of the method itself (TYPE_CODE_METHOD). */
15615 smash_to_method_type (fnp
->type
, type
,
15616 TYPE_TARGET_TYPE (this_type
),
15617 this_type
->fields (),
15618 this_type
->num_fields (),
15619 this_type
->has_varargs ());
15621 /* Handle static member functions.
15622 Dwarf2 has no clean way to discern C++ static and non-static
15623 member functions. G++ helps GDB by marking the first
15624 parameter for non-static member functions (which is the this
15625 pointer) as artificial. We obtain this information from
15626 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15627 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15628 fnp
->voffset
= VOFFSET_STATIC
;
15631 complaint (_("member function type missing for '%s'"),
15632 dwarf2_full_name (fieldname
, die
, cu
));
15634 /* Get fcontext from DW_AT_containing_type if present. */
15635 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15636 fnp
->fcontext
= die_containing_type (die
, cu
);
15638 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15639 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15641 /* Get accessibility. */
15642 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15643 switch (accessibility
)
15645 case DW_ACCESS_private
:
15646 fnp
->is_private
= 1;
15648 case DW_ACCESS_protected
:
15649 fnp
->is_protected
= 1;
15653 /* Check for artificial methods. */
15654 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15655 if (attr
&& attr
->as_boolean ())
15656 fnp
->is_artificial
= 1;
15658 /* Check for defaulted methods. */
15659 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15660 if (attr
!= nullptr)
15661 fnp
->defaulted
= attr
->defaulted ();
15663 /* Check for deleted methods. */
15664 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15665 if (attr
!= nullptr && attr
->as_boolean ())
15666 fnp
->is_deleted
= 1;
15668 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15670 /* Get index in virtual function table if it is a virtual member
15671 function. For older versions of GCC, this is an offset in the
15672 appropriate virtual table, as specified by DW_AT_containing_type.
15673 For everyone else, it is an expression to be evaluated relative
15674 to the object address. */
15676 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15677 if (attr
!= nullptr)
15679 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15681 struct dwarf_block
*block
= attr
->as_block ();
15683 if (block
->data
[0] == DW_OP_constu
)
15685 /* Old-style GCC. */
15686 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15688 else if (block
->data
[0] == DW_OP_deref
15689 || (block
->size
> 1
15690 && block
->data
[0] == DW_OP_deref_size
15691 && block
->data
[1] == cu
->header
.addr_size
))
15693 fnp
->voffset
= decode_locdesc (block
, cu
);
15694 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15695 dwarf2_complex_location_expr_complaint ();
15697 fnp
->voffset
/= cu
->header
.addr_size
;
15701 dwarf2_complex_location_expr_complaint ();
15703 if (!fnp
->fcontext
)
15705 /* If there is no `this' field and no DW_AT_containing_type,
15706 we cannot actually find a base class context for the
15708 if (this_type
->num_fields () == 0
15709 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15711 complaint (_("cannot determine context for virtual member "
15712 "function \"%s\" (offset %s)"),
15713 fieldname
, sect_offset_str (die
->sect_off
));
15718 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15722 else if (attr
->form_is_section_offset ())
15724 dwarf2_complex_location_expr_complaint ();
15728 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15734 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15735 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15737 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15738 complaint (_("Member function \"%s\" (offset %s) is virtual "
15739 "but the vtable offset is not specified"),
15740 fieldname
, sect_offset_str (die
->sect_off
));
15741 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15742 TYPE_CPLUS_DYNAMIC (type
) = 1;
15747 /* Create the vector of member function fields, and attach it to the type. */
15750 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15751 struct dwarf2_cu
*cu
)
15753 if (cu
->language
== language_ada
)
15754 error (_("unexpected member functions in Ada type"));
15756 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15757 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15759 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15761 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15763 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15764 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15766 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15767 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15768 fn_flp
->fn_fields
= (struct fn_field
*)
15769 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15771 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15772 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15775 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15778 /* Returns non-zero if NAME is the name of a vtable member in CU's
15779 language, zero otherwise. */
15781 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15783 static const char vptr
[] = "_vptr";
15785 /* Look for the C++ form of the vtable. */
15786 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15792 /* GCC outputs unnamed structures that are really pointers to member
15793 functions, with the ABI-specified layout. If TYPE describes
15794 such a structure, smash it into a member function type.
15796 GCC shouldn't do this; it should just output pointer to member DIEs.
15797 This is GCC PR debug/28767. */
15800 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15802 struct type
*pfn_type
, *self_type
, *new_type
;
15804 /* Check for a structure with no name and two children. */
15805 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15808 /* Check for __pfn and __delta members. */
15809 if (TYPE_FIELD_NAME (type
, 0) == NULL
15810 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15811 || TYPE_FIELD_NAME (type
, 1) == NULL
15812 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15815 /* Find the type of the method. */
15816 pfn_type
= type
->field (0).type ();
15817 if (pfn_type
== NULL
15818 || pfn_type
->code () != TYPE_CODE_PTR
15819 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15822 /* Look for the "this" argument. */
15823 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15824 if (pfn_type
->num_fields () == 0
15825 /* || pfn_type->field (0).type () == NULL */
15826 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15829 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15830 new_type
= alloc_type (objfile
);
15831 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15832 pfn_type
->fields (), pfn_type
->num_fields (),
15833 pfn_type
->has_varargs ());
15834 smash_to_methodptr_type (type
, new_type
);
15837 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15838 appropriate error checking and issuing complaints if there is a
15842 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15844 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15846 if (attr
== nullptr)
15849 if (!attr
->form_is_constant ())
15851 complaint (_("DW_AT_alignment must have constant form"
15852 " - DIE at %s [in module %s]"),
15853 sect_offset_str (die
->sect_off
),
15854 objfile_name (cu
->per_objfile
->objfile
));
15858 LONGEST val
= attr
->constant_value (0);
15861 complaint (_("DW_AT_alignment value must not be negative"
15862 " - DIE at %s [in module %s]"),
15863 sect_offset_str (die
->sect_off
),
15864 objfile_name (cu
->per_objfile
->objfile
));
15867 ULONGEST align
= val
;
15871 complaint (_("DW_AT_alignment value must not be zero"
15872 " - DIE at %s [in module %s]"),
15873 sect_offset_str (die
->sect_off
),
15874 objfile_name (cu
->per_objfile
->objfile
));
15877 if ((align
& (align
- 1)) != 0)
15879 complaint (_("DW_AT_alignment value must be a power of 2"
15880 " - DIE at %s [in module %s]"),
15881 sect_offset_str (die
->sect_off
),
15882 objfile_name (cu
->per_objfile
->objfile
));
15889 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15890 the alignment for TYPE. */
15893 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15896 if (!set_type_align (type
, get_alignment (cu
, die
)))
15897 complaint (_("DW_AT_alignment value too large"
15898 " - DIE at %s [in module %s]"),
15899 sect_offset_str (die
->sect_off
),
15900 objfile_name (cu
->per_objfile
->objfile
));
15903 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15904 constant for a type, according to DWARF5 spec, Table 5.5. */
15907 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15912 case DW_CC_pass_by_reference
:
15913 case DW_CC_pass_by_value
:
15917 complaint (_("unrecognized DW_AT_calling_convention value "
15918 "(%s) for a type"), pulongest (value
));
15923 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15924 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15925 also according to GNU-specific values (see include/dwarf2.h). */
15928 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15933 case DW_CC_program
:
15937 case DW_CC_GNU_renesas_sh
:
15938 case DW_CC_GNU_borland_fastcall_i386
:
15939 case DW_CC_GDB_IBM_OpenCL
:
15943 complaint (_("unrecognized DW_AT_calling_convention value "
15944 "(%s) for a subroutine"), pulongest (value
));
15949 /* Called when we find the DIE that starts a structure or union scope
15950 (definition) to create a type for the structure or union. Fill in
15951 the type's name and general properties; the members will not be
15952 processed until process_structure_scope. A symbol table entry for
15953 the type will also not be done until process_structure_scope (assuming
15954 the type has a name).
15956 NOTE: we need to call these functions regardless of whether or not the
15957 DIE has a DW_AT_name attribute, since it might be an anonymous
15958 structure or union. This gets the type entered into our set of
15959 user defined types. */
15961 static struct type
*
15962 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15964 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15966 struct attribute
*attr
;
15969 /* If the definition of this type lives in .debug_types, read that type.
15970 Don't follow DW_AT_specification though, that will take us back up
15971 the chain and we want to go down. */
15972 attr
= die
->attr (DW_AT_signature
);
15973 if (attr
!= nullptr)
15975 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15977 /* The type's CU may not be the same as CU.
15978 Ensure TYPE is recorded with CU in die_type_hash. */
15979 return set_die_type (die
, type
, cu
);
15982 type
= alloc_type (objfile
);
15983 INIT_CPLUS_SPECIFIC (type
);
15985 name
= dwarf2_name (die
, cu
);
15988 if (cu
->language
== language_cplus
15989 || cu
->language
== language_d
15990 || cu
->language
== language_rust
)
15992 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15994 /* dwarf2_full_name might have already finished building the DIE's
15995 type. If so, there is no need to continue. */
15996 if (get_die_type (die
, cu
) != NULL
)
15997 return get_die_type (die
, cu
);
15999 type
->set_name (full_name
);
16003 /* The name is already allocated along with this objfile, so
16004 we don't need to duplicate it for the type. */
16005 type
->set_name (name
);
16009 if (die
->tag
== DW_TAG_structure_type
)
16011 type
->set_code (TYPE_CODE_STRUCT
);
16013 else if (die
->tag
== DW_TAG_union_type
)
16015 type
->set_code (TYPE_CODE_UNION
);
16019 type
->set_code (TYPE_CODE_STRUCT
);
16022 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16023 TYPE_DECLARED_CLASS (type
) = 1;
16025 /* Store the calling convention in the type if it's available in
16026 the die. Otherwise the calling convention remains set to
16027 the default value DW_CC_normal. */
16028 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16029 if (attr
!= nullptr
16030 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
16032 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16033 TYPE_CPLUS_CALLING_CONVENTION (type
)
16034 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
16037 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16038 if (attr
!= nullptr)
16040 if (attr
->form_is_constant ())
16041 TYPE_LENGTH (type
) = attr
->constant_value (0);
16044 struct dynamic_prop prop
;
16045 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
16046 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
16047 TYPE_LENGTH (type
) = 0;
16052 TYPE_LENGTH (type
) = 0;
16055 maybe_set_alignment (cu
, die
, type
);
16057 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16059 /* ICC<14 does not output the required DW_AT_declaration on
16060 incomplete types, but gives them a size of zero. */
16061 type
->set_is_stub (true);
16064 type
->set_stub_is_supported (true);
16066 if (die_is_declaration (die
, cu
))
16067 type
->set_is_stub (true);
16068 else if (attr
== NULL
&& die
->child
== NULL
16069 && producer_is_realview (cu
->producer
))
16070 /* RealView does not output the required DW_AT_declaration
16071 on incomplete types. */
16072 type
->set_is_stub (true);
16074 /* We need to add the type field to the die immediately so we don't
16075 infinitely recurse when dealing with pointers to the structure
16076 type within the structure itself. */
16077 set_die_type (die
, type
, cu
);
16079 /* set_die_type should be already done. */
16080 set_descriptive_type (type
, die
, cu
);
16085 static void handle_struct_member_die
16086 (struct die_info
*child_die
,
16088 struct field_info
*fi
,
16089 std::vector
<struct symbol
*> *template_args
,
16090 struct dwarf2_cu
*cu
);
16092 /* A helper for handle_struct_member_die that handles
16093 DW_TAG_variant_part. */
16096 handle_variant_part (struct die_info
*die
, struct type
*type
,
16097 struct field_info
*fi
,
16098 std::vector
<struct symbol
*> *template_args
,
16099 struct dwarf2_cu
*cu
)
16101 variant_part_builder
*new_part
;
16102 if (fi
->current_variant_part
== nullptr)
16104 fi
->variant_parts
.emplace_back ();
16105 new_part
= &fi
->variant_parts
.back ();
16107 else if (!fi
->current_variant_part
->processing_variant
)
16109 complaint (_("nested DW_TAG_variant_part seen "
16110 "- DIE at %s [in module %s]"),
16111 sect_offset_str (die
->sect_off
),
16112 objfile_name (cu
->per_objfile
->objfile
));
16117 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
16118 current
.variant_parts
.emplace_back ();
16119 new_part
= ¤t
.variant_parts
.back ();
16122 /* When we recurse, we want callees to add to this new variant
16124 scoped_restore save_current_variant_part
16125 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
16127 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16130 /* It's a univariant form, an extension we support. */
16132 else if (discr
->form_is_ref ())
16134 struct dwarf2_cu
*target_cu
= cu
;
16135 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16137 new_part
->discriminant_offset
= target_die
->sect_off
;
16141 complaint (_("DW_AT_discr does not have DIE reference form"
16142 " - DIE at %s [in module %s]"),
16143 sect_offset_str (die
->sect_off
),
16144 objfile_name (cu
->per_objfile
->objfile
));
16147 for (die_info
*child_die
= die
->child
;
16149 child_die
= child_die
->sibling
)
16150 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16153 /* A helper for handle_struct_member_die that handles
16157 handle_variant (struct die_info
*die
, struct type
*type
,
16158 struct field_info
*fi
,
16159 std::vector
<struct symbol
*> *template_args
,
16160 struct dwarf2_cu
*cu
)
16162 if (fi
->current_variant_part
== nullptr)
16164 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16165 "- DIE at %s [in module %s]"),
16166 sect_offset_str (die
->sect_off
),
16167 objfile_name (cu
->per_objfile
->objfile
));
16170 if (fi
->current_variant_part
->processing_variant
)
16172 complaint (_("nested DW_TAG_variant seen "
16173 "- DIE at %s [in module %s]"),
16174 sect_offset_str (die
->sect_off
),
16175 objfile_name (cu
->per_objfile
->objfile
));
16179 scoped_restore save_processing_variant
16180 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16183 fi
->current_variant_part
->variants
.emplace_back ();
16184 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16185 variant
.first_field
= fi
->fields
.size ();
16187 /* In a variant we want to get the discriminant and also add a
16188 field for our sole member child. */
16189 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16190 if (discr
== nullptr || !discr
->form_is_constant ())
16192 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16193 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16194 variant
.default_branch
= true;
16196 variant
.discr_list_data
= discr
->as_block ();
16199 variant
.discriminant_value
= discr
->constant_value (0);
16201 for (die_info
*variant_child
= die
->child
;
16202 variant_child
!= NULL
;
16203 variant_child
= variant_child
->sibling
)
16204 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16206 variant
.last_field
= fi
->fields
.size ();
16209 /* A helper for process_structure_scope that handles a single member
16213 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16214 struct field_info
*fi
,
16215 std::vector
<struct symbol
*> *template_args
,
16216 struct dwarf2_cu
*cu
)
16218 if (child_die
->tag
== DW_TAG_member
16219 || child_die
->tag
== DW_TAG_variable
)
16221 /* NOTE: carlton/2002-11-05: A C++ static data member
16222 should be a DW_TAG_member that is a declaration, but
16223 all versions of G++ as of this writing (so through at
16224 least 3.2.1) incorrectly generate DW_TAG_variable
16225 tags for them instead. */
16226 dwarf2_add_field (fi
, child_die
, cu
);
16228 else if (child_die
->tag
== DW_TAG_subprogram
)
16230 /* Rust doesn't have member functions in the C++ sense.
16231 However, it does emit ordinary functions as children
16232 of a struct DIE. */
16233 if (cu
->language
== language_rust
)
16234 read_func_scope (child_die
, cu
);
16237 /* C++ member function. */
16238 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16241 else if (child_die
->tag
== DW_TAG_inheritance
)
16243 /* C++ base class field. */
16244 dwarf2_add_field (fi
, child_die
, cu
);
16246 else if (type_can_define_types (child_die
))
16247 dwarf2_add_type_defn (fi
, child_die
, cu
);
16248 else if (child_die
->tag
== DW_TAG_template_type_param
16249 || child_die
->tag
== DW_TAG_template_value_param
)
16251 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16254 template_args
->push_back (arg
);
16256 else if (child_die
->tag
== DW_TAG_variant_part
)
16257 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16258 else if (child_die
->tag
== DW_TAG_variant
)
16259 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16262 /* Finish creating a structure or union type, including filling in
16263 its members and creating a symbol for it. */
16266 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16268 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16269 struct die_info
*child_die
;
16272 type
= get_die_type (die
, cu
);
16274 type
= read_structure_type (die
, cu
);
16276 bool has_template_parameters
= false;
16277 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16279 struct field_info fi
;
16280 std::vector
<struct symbol
*> template_args
;
16282 child_die
= die
->child
;
16284 while (child_die
&& child_die
->tag
)
16286 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16287 child_die
= child_die
->sibling
;
16290 /* Attach template arguments to type. */
16291 if (!template_args
.empty ())
16293 has_template_parameters
= true;
16294 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16295 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16296 TYPE_TEMPLATE_ARGUMENTS (type
)
16297 = XOBNEWVEC (&objfile
->objfile_obstack
,
16299 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16300 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16301 template_args
.data (),
16302 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16303 * sizeof (struct symbol
*)));
16306 /* Attach fields and member functions to the type. */
16307 if (fi
.nfields () > 0)
16308 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16309 if (!fi
.fnfieldlists
.empty ())
16311 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16313 /* Get the type which refers to the base class (possibly this
16314 class itself) which contains the vtable pointer for the current
16315 class from the DW_AT_containing_type attribute. This use of
16316 DW_AT_containing_type is a GNU extension. */
16318 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16320 struct type
*t
= die_containing_type (die
, cu
);
16322 set_type_vptr_basetype (type
, t
);
16327 /* Our own class provides vtbl ptr. */
16328 for (i
= t
->num_fields () - 1;
16329 i
>= TYPE_N_BASECLASSES (t
);
16332 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16334 if (is_vtable_name (fieldname
, cu
))
16336 set_type_vptr_fieldno (type
, i
);
16341 /* Complain if virtual function table field not found. */
16342 if (i
< TYPE_N_BASECLASSES (t
))
16343 complaint (_("virtual function table pointer "
16344 "not found when defining class '%s'"),
16345 type
->name () ? type
->name () : "");
16349 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16352 else if (cu
->producer
16353 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16355 /* The IBM XLC compiler does not provide direct indication
16356 of the containing type, but the vtable pointer is
16357 always named __vfp. */
16361 for (i
= type
->num_fields () - 1;
16362 i
>= TYPE_N_BASECLASSES (type
);
16365 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16367 set_type_vptr_fieldno (type
, i
);
16368 set_type_vptr_basetype (type
, type
);
16375 /* Copy fi.typedef_field_list linked list elements content into the
16376 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16377 if (!fi
.typedef_field_list
.empty ())
16379 int count
= fi
.typedef_field_list
.size ();
16381 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16382 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16383 = ((struct decl_field
*)
16385 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16386 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16388 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16389 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16392 /* Copy fi.nested_types_list linked list elements content into the
16393 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16394 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16396 int count
= fi
.nested_types_list
.size ();
16398 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16399 TYPE_NESTED_TYPES_ARRAY (type
)
16400 = ((struct decl_field
*)
16401 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16402 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16404 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16405 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16409 quirk_gcc_member_function_pointer (type
, objfile
);
16410 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16411 cu
->rust_unions
.push_back (type
);
16413 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16414 snapshots) has been known to create a die giving a declaration
16415 for a class that has, as a child, a die giving a definition for a
16416 nested class. So we have to process our children even if the
16417 current die is a declaration. Normally, of course, a declaration
16418 won't have any children at all. */
16420 child_die
= die
->child
;
16422 while (child_die
!= NULL
&& child_die
->tag
)
16424 if (child_die
->tag
== DW_TAG_member
16425 || child_die
->tag
== DW_TAG_variable
16426 || child_die
->tag
== DW_TAG_inheritance
16427 || child_die
->tag
== DW_TAG_template_value_param
16428 || child_die
->tag
== DW_TAG_template_type_param
)
16433 process_die (child_die
, cu
);
16435 child_die
= child_die
->sibling
;
16438 /* Do not consider external references. According to the DWARF standard,
16439 these DIEs are identified by the fact that they have no byte_size
16440 attribute, and a declaration attribute. */
16441 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16442 || !die_is_declaration (die
, cu
)
16443 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16445 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16447 if (has_template_parameters
)
16449 struct symtab
*symtab
;
16450 if (sym
!= nullptr)
16451 symtab
= symbol_symtab (sym
);
16452 else if (cu
->line_header
!= nullptr)
16454 /* Any related symtab will do. */
16456 = cu
->line_header
->file_names ()[0].symtab
;
16461 complaint (_("could not find suitable "
16462 "symtab for template parameter"
16463 " - DIE at %s [in module %s]"),
16464 sect_offset_str (die
->sect_off
),
16465 objfile_name (objfile
));
16468 if (symtab
!= nullptr)
16470 /* Make sure that the symtab is set on the new symbols.
16471 Even though they don't appear in this symtab directly,
16472 other parts of gdb assume that symbols do, and this is
16473 reasonably true. */
16474 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16475 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16481 /* Assuming DIE is an enumeration type, and TYPE is its associated
16482 type, update TYPE using some information only available in DIE's
16483 children. In particular, the fields are computed. */
16486 update_enumeration_type_from_children (struct die_info
*die
,
16488 struct dwarf2_cu
*cu
)
16490 struct die_info
*child_die
;
16491 int unsigned_enum
= 1;
16494 auto_obstack obstack
;
16495 std::vector
<struct field
> fields
;
16497 for (child_die
= die
->child
;
16498 child_die
!= NULL
&& child_die
->tag
;
16499 child_die
= child_die
->sibling
)
16501 struct attribute
*attr
;
16503 const gdb_byte
*bytes
;
16504 struct dwarf2_locexpr_baton
*baton
;
16507 if (child_die
->tag
!= DW_TAG_enumerator
)
16510 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16514 name
= dwarf2_name (child_die
, cu
);
16516 name
= "<anonymous enumerator>";
16518 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16519 &value
, &bytes
, &baton
);
16527 if (count_one_bits_ll (value
) >= 2)
16531 fields
.emplace_back ();
16532 struct field
&field
= fields
.back ();
16533 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16534 SET_FIELD_ENUMVAL (field
, value
);
16537 if (!fields
.empty ())
16539 type
->set_num_fields (fields
.size ());
16542 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16543 memcpy (type
->fields (), fields
.data (),
16544 sizeof (struct field
) * fields
.size ());
16548 type
->set_is_unsigned (true);
16551 TYPE_FLAG_ENUM (type
) = 1;
16554 /* Given a DW_AT_enumeration_type die, set its type. We do not
16555 complete the type's fields yet, or create any symbols. */
16557 static struct type
*
16558 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16560 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16562 struct attribute
*attr
;
16565 /* If the definition of this type lives in .debug_types, read that type.
16566 Don't follow DW_AT_specification though, that will take us back up
16567 the chain and we want to go down. */
16568 attr
= die
->attr (DW_AT_signature
);
16569 if (attr
!= nullptr)
16571 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16573 /* The type's CU may not be the same as CU.
16574 Ensure TYPE is recorded with CU in die_type_hash. */
16575 return set_die_type (die
, type
, cu
);
16578 type
= alloc_type (objfile
);
16580 type
->set_code (TYPE_CODE_ENUM
);
16581 name
= dwarf2_full_name (NULL
, die
, cu
);
16583 type
->set_name (name
);
16585 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16588 struct type
*underlying_type
= die_type (die
, cu
);
16590 TYPE_TARGET_TYPE (type
) = underlying_type
;
16593 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16594 if (attr
!= nullptr)
16596 TYPE_LENGTH (type
) = attr
->constant_value (0);
16600 TYPE_LENGTH (type
) = 0;
16603 maybe_set_alignment (cu
, die
, type
);
16605 /* The enumeration DIE can be incomplete. In Ada, any type can be
16606 declared as private in the package spec, and then defined only
16607 inside the package body. Such types are known as Taft Amendment
16608 Types. When another package uses such a type, an incomplete DIE
16609 may be generated by the compiler. */
16610 if (die_is_declaration (die
, cu
))
16611 type
->set_is_stub (true);
16613 /* If this type has an underlying type that is not a stub, then we
16614 may use its attributes. We always use the "unsigned" attribute
16615 in this situation, because ordinarily we guess whether the type
16616 is unsigned -- but the guess can be wrong and the underlying type
16617 can tell us the reality. However, we defer to a local size
16618 attribute if one exists, because this lets the compiler override
16619 the underlying type if needed. */
16620 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16622 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16623 underlying_type
= check_typedef (underlying_type
);
16625 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16627 if (TYPE_LENGTH (type
) == 0)
16628 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16630 if (TYPE_RAW_ALIGN (type
) == 0
16631 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16632 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16635 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16637 set_die_type (die
, type
, cu
);
16639 /* Finish the creation of this type by using the enum's children.
16640 Note that, as usual, this must come after set_die_type to avoid
16641 infinite recursion when trying to compute the names of the
16643 update_enumeration_type_from_children (die
, type
, cu
);
16648 /* Given a pointer to a die which begins an enumeration, process all
16649 the dies that define the members of the enumeration, and create the
16650 symbol for the enumeration type.
16652 NOTE: We reverse the order of the element list. */
16655 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16657 struct type
*this_type
;
16659 this_type
= get_die_type (die
, cu
);
16660 if (this_type
== NULL
)
16661 this_type
= read_enumeration_type (die
, cu
);
16663 if (die
->child
!= NULL
)
16665 struct die_info
*child_die
;
16668 child_die
= die
->child
;
16669 while (child_die
&& child_die
->tag
)
16671 if (child_die
->tag
!= DW_TAG_enumerator
)
16673 process_die (child_die
, cu
);
16677 name
= dwarf2_name (child_die
, cu
);
16679 new_symbol (child_die
, this_type
, cu
);
16682 child_die
= child_die
->sibling
;
16686 /* If we are reading an enum from a .debug_types unit, and the enum
16687 is a declaration, and the enum is not the signatured type in the
16688 unit, then we do not want to add a symbol for it. Adding a
16689 symbol would in some cases obscure the true definition of the
16690 enum, giving users an incomplete type when the definition is
16691 actually available. Note that we do not want to do this for all
16692 enums which are just declarations, because C++0x allows forward
16693 enum declarations. */
16694 if (cu
->per_cu
->is_debug_types
16695 && die_is_declaration (die
, cu
))
16697 struct signatured_type
*sig_type
;
16699 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16700 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16701 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16705 new_symbol (die
, this_type
, cu
);
16708 /* Extract all information from a DW_TAG_array_type DIE and put it in
16709 the DIE's type field. For now, this only handles one dimensional
16712 static struct type
*
16713 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16715 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16716 struct die_info
*child_die
;
16718 struct type
*element_type
, *range_type
, *index_type
;
16719 struct attribute
*attr
;
16721 struct dynamic_prop
*byte_stride_prop
= NULL
;
16722 unsigned int bit_stride
= 0;
16724 element_type
= die_type (die
, cu
);
16726 /* The die_type call above may have already set the type for this DIE. */
16727 type
= get_die_type (die
, cu
);
16731 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16735 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16738 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16739 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16743 complaint (_("unable to read array DW_AT_byte_stride "
16744 " - DIE at %s [in module %s]"),
16745 sect_offset_str (die
->sect_off
),
16746 objfile_name (cu
->per_objfile
->objfile
));
16747 /* Ignore this attribute. We will likely not be able to print
16748 arrays of this type correctly, but there is little we can do
16749 to help if we cannot read the attribute's value. */
16750 byte_stride_prop
= NULL
;
16754 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16756 bit_stride
= attr
->constant_value (0);
16758 /* Irix 6.2 native cc creates array types without children for
16759 arrays with unspecified length. */
16760 if (die
->child
== NULL
)
16762 index_type
= objfile_type (objfile
)->builtin_int
;
16763 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16764 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16765 byte_stride_prop
, bit_stride
);
16766 return set_die_type (die
, type
, cu
);
16769 std::vector
<struct type
*> range_types
;
16770 child_die
= die
->child
;
16771 while (child_die
&& child_die
->tag
)
16773 if (child_die
->tag
== DW_TAG_subrange_type
)
16775 struct type
*child_type
= read_type_die (child_die
, cu
);
16777 if (child_type
!= NULL
)
16779 /* The range type was succesfully read. Save it for the
16780 array type creation. */
16781 range_types
.push_back (child_type
);
16784 child_die
= child_die
->sibling
;
16787 /* Dwarf2 dimensions are output from left to right, create the
16788 necessary array types in backwards order. */
16790 type
= element_type
;
16792 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16796 while (i
< range_types
.size ())
16797 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16798 byte_stride_prop
, bit_stride
);
16802 size_t ndim
= range_types
.size ();
16804 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16805 byte_stride_prop
, bit_stride
);
16808 /* Understand Dwarf2 support for vector types (like they occur on
16809 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16810 array type. This is not part of the Dwarf2/3 standard yet, but a
16811 custom vendor extension. The main difference between a regular
16812 array and the vector variant is that vectors are passed by value
16814 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16815 if (attr
!= nullptr)
16816 make_vector_type (type
);
16818 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16819 implementation may choose to implement triple vectors using this
16821 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16822 if (attr
!= nullptr && attr
->form_is_unsigned ())
16824 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16825 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16827 complaint (_("DW_AT_byte_size for array type smaller "
16828 "than the total size of elements"));
16831 name
= dwarf2_name (die
, cu
);
16833 type
->set_name (name
);
16835 maybe_set_alignment (cu
, die
, type
);
16837 /* Install the type in the die. */
16838 set_die_type (die
, type
, cu
);
16840 /* set_die_type should be already done. */
16841 set_descriptive_type (type
, die
, cu
);
16846 static enum dwarf_array_dim_ordering
16847 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16849 struct attribute
*attr
;
16851 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16853 if (attr
!= nullptr)
16855 LONGEST val
= attr
->constant_value (-1);
16856 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16857 return (enum dwarf_array_dim_ordering
) val
;
16860 /* GNU F77 is a special case, as at 08/2004 array type info is the
16861 opposite order to the dwarf2 specification, but data is still
16862 laid out as per normal fortran.
16864 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16865 version checking. */
16867 if (cu
->language
== language_fortran
16868 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16870 return DW_ORD_row_major
;
16873 switch (cu
->language_defn
->array_ordering ())
16875 case array_column_major
:
16876 return DW_ORD_col_major
;
16877 case array_row_major
:
16879 return DW_ORD_row_major
;
16883 /* Extract all information from a DW_TAG_set_type DIE and put it in
16884 the DIE's type field. */
16886 static struct type
*
16887 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16889 struct type
*domain_type
, *set_type
;
16890 struct attribute
*attr
;
16892 domain_type
= die_type (die
, cu
);
16894 /* The die_type call above may have already set the type for this DIE. */
16895 set_type
= get_die_type (die
, cu
);
16899 set_type
= create_set_type (NULL
, domain_type
);
16901 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16902 if (attr
!= nullptr && attr
->form_is_unsigned ())
16903 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16905 maybe_set_alignment (cu
, die
, set_type
);
16907 return set_die_type (die
, set_type
, cu
);
16910 /* A helper for read_common_block that creates a locexpr baton.
16911 SYM is the symbol which we are marking as computed.
16912 COMMON_DIE is the DIE for the common block.
16913 COMMON_LOC is the location expression attribute for the common
16915 MEMBER_LOC is the location expression attribute for the particular
16916 member of the common block that we are processing.
16917 CU is the CU from which the above come. */
16920 mark_common_block_symbol_computed (struct symbol
*sym
,
16921 struct die_info
*common_die
,
16922 struct attribute
*common_loc
,
16923 struct attribute
*member_loc
,
16924 struct dwarf2_cu
*cu
)
16926 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16927 struct objfile
*objfile
= per_objfile
->objfile
;
16928 struct dwarf2_locexpr_baton
*baton
;
16930 unsigned int cu_off
;
16931 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16932 LONGEST offset
= 0;
16934 gdb_assert (common_loc
&& member_loc
);
16935 gdb_assert (common_loc
->form_is_block ());
16936 gdb_assert (member_loc
->form_is_block ()
16937 || member_loc
->form_is_constant ());
16939 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16940 baton
->per_objfile
= per_objfile
;
16941 baton
->per_cu
= cu
->per_cu
;
16942 gdb_assert (baton
->per_cu
);
16944 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16946 if (member_loc
->form_is_constant ())
16948 offset
= member_loc
->constant_value (0);
16949 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16952 baton
->size
+= member_loc
->as_block ()->size
;
16954 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16957 *ptr
++ = DW_OP_call4
;
16958 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16959 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16962 if (member_loc
->form_is_constant ())
16964 *ptr
++ = DW_OP_addr
;
16965 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16966 ptr
+= cu
->header
.addr_size
;
16970 /* We have to copy the data here, because DW_OP_call4 will only
16971 use a DW_AT_location attribute. */
16972 struct dwarf_block
*block
= member_loc
->as_block ();
16973 memcpy (ptr
, block
->data
, block
->size
);
16974 ptr
+= block
->size
;
16977 *ptr
++ = DW_OP_plus
;
16978 gdb_assert (ptr
- baton
->data
== baton
->size
);
16980 SYMBOL_LOCATION_BATON (sym
) = baton
;
16981 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16984 /* Create appropriate locally-scoped variables for all the
16985 DW_TAG_common_block entries. Also create a struct common_block
16986 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16987 is used to separate the common blocks name namespace from regular
16991 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16993 struct attribute
*attr
;
16995 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16996 if (attr
!= nullptr)
16998 /* Support the .debug_loc offsets. */
16999 if (attr
->form_is_block ())
17003 else if (attr
->form_is_section_offset ())
17005 dwarf2_complex_location_expr_complaint ();
17010 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17011 "common block member");
17016 if (die
->child
!= NULL
)
17018 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17019 struct die_info
*child_die
;
17020 size_t n_entries
= 0, size
;
17021 struct common_block
*common_block
;
17022 struct symbol
*sym
;
17024 for (child_die
= die
->child
;
17025 child_die
&& child_die
->tag
;
17026 child_die
= child_die
->sibling
)
17029 size
= (sizeof (struct common_block
)
17030 + (n_entries
- 1) * sizeof (struct symbol
*));
17032 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17034 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17035 common_block
->n_entries
= 0;
17037 for (child_die
= die
->child
;
17038 child_die
&& child_die
->tag
;
17039 child_die
= child_die
->sibling
)
17041 /* Create the symbol in the DW_TAG_common_block block in the current
17043 sym
= new_symbol (child_die
, NULL
, cu
);
17046 struct attribute
*member_loc
;
17048 common_block
->contents
[common_block
->n_entries
++] = sym
;
17050 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17054 /* GDB has handled this for a long time, but it is
17055 not specified by DWARF. It seems to have been
17056 emitted by gfortran at least as recently as:
17057 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17058 complaint (_("Variable in common block has "
17059 "DW_AT_data_member_location "
17060 "- DIE at %s [in module %s]"),
17061 sect_offset_str (child_die
->sect_off
),
17062 objfile_name (objfile
));
17064 if (member_loc
->form_is_section_offset ())
17065 dwarf2_complex_location_expr_complaint ();
17066 else if (member_loc
->form_is_constant ()
17067 || member_loc
->form_is_block ())
17069 if (attr
!= nullptr)
17070 mark_common_block_symbol_computed (sym
, die
, attr
,
17074 dwarf2_complex_location_expr_complaint ();
17079 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17080 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17084 /* Create a type for a C++ namespace. */
17086 static struct type
*
17087 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17089 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17090 const char *previous_prefix
, *name
;
17094 /* For extensions, reuse the type of the original namespace. */
17095 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17097 struct die_info
*ext_die
;
17098 struct dwarf2_cu
*ext_cu
= cu
;
17100 ext_die
= dwarf2_extension (die
, &ext_cu
);
17101 type
= read_type_die (ext_die
, ext_cu
);
17103 /* EXT_CU may not be the same as CU.
17104 Ensure TYPE is recorded with CU in die_type_hash. */
17105 return set_die_type (die
, type
, cu
);
17108 name
= namespace_name (die
, &is_anonymous
, cu
);
17110 /* Now build the name of the current namespace. */
17112 previous_prefix
= determine_prefix (die
, cu
);
17113 if (previous_prefix
[0] != '\0')
17114 name
= typename_concat (&objfile
->objfile_obstack
,
17115 previous_prefix
, name
, 0, cu
);
17117 /* Create the type. */
17118 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17120 return set_die_type (die
, type
, cu
);
17123 /* Read a namespace scope. */
17126 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17128 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17131 /* Add a symbol associated to this if we haven't seen the namespace
17132 before. Also, add a using directive if it's an anonymous
17135 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17139 type
= read_type_die (die
, cu
);
17140 new_symbol (die
, type
, cu
);
17142 namespace_name (die
, &is_anonymous
, cu
);
17145 const char *previous_prefix
= determine_prefix (die
, cu
);
17147 std::vector
<const char *> excludes
;
17148 add_using_directive (using_directives (cu
),
17149 previous_prefix
, type
->name (), NULL
,
17150 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17154 if (die
->child
!= NULL
)
17156 struct die_info
*child_die
= die
->child
;
17158 while (child_die
&& child_die
->tag
)
17160 process_die (child_die
, cu
);
17161 child_die
= child_die
->sibling
;
17166 /* Read a Fortran module as type. This DIE can be only a declaration used for
17167 imported module. Still we need that type as local Fortran "use ... only"
17168 declaration imports depend on the created type in determine_prefix. */
17170 static struct type
*
17171 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17173 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17174 const char *module_name
;
17177 module_name
= dwarf2_name (die
, cu
);
17178 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17180 return set_die_type (die
, type
, cu
);
17183 /* Read a Fortran module. */
17186 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17188 struct die_info
*child_die
= die
->child
;
17191 type
= read_type_die (die
, cu
);
17192 new_symbol (die
, type
, cu
);
17194 while (child_die
&& child_die
->tag
)
17196 process_die (child_die
, cu
);
17197 child_die
= child_die
->sibling
;
17201 /* Return the name of the namespace represented by DIE. Set
17202 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17205 static const char *
17206 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17208 struct die_info
*current_die
;
17209 const char *name
= NULL
;
17211 /* Loop through the extensions until we find a name. */
17213 for (current_die
= die
;
17214 current_die
!= NULL
;
17215 current_die
= dwarf2_extension (die
, &cu
))
17217 /* We don't use dwarf2_name here so that we can detect the absence
17218 of a name -> anonymous namespace. */
17219 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17225 /* Is it an anonymous namespace? */
17227 *is_anonymous
= (name
== NULL
);
17229 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17234 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17235 the user defined type vector. */
17237 static struct type
*
17238 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17240 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17241 struct comp_unit_head
*cu_header
= &cu
->header
;
17243 struct attribute
*attr_byte_size
;
17244 struct attribute
*attr_address_class
;
17245 int byte_size
, addr_class
;
17246 struct type
*target_type
;
17248 target_type
= die_type (die
, cu
);
17250 /* The die_type call above may have already set the type for this DIE. */
17251 type
= get_die_type (die
, cu
);
17255 type
= lookup_pointer_type (target_type
);
17257 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17258 if (attr_byte_size
)
17259 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17261 byte_size
= cu_header
->addr_size
;
17263 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17264 if (attr_address_class
)
17265 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17267 addr_class
= DW_ADDR_none
;
17269 ULONGEST alignment
= get_alignment (cu
, die
);
17271 /* If the pointer size, alignment, or address class is different
17272 than the default, create a type variant marked as such and set
17273 the length accordingly. */
17274 if (TYPE_LENGTH (type
) != byte_size
17275 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17276 && alignment
!= TYPE_RAW_ALIGN (type
))
17277 || addr_class
!= DW_ADDR_none
)
17279 if (gdbarch_address_class_type_flags_p (gdbarch
))
17281 type_instance_flags type_flags
17282 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17284 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17286 type
= make_type_with_address_space (type
, type_flags
);
17288 else if (TYPE_LENGTH (type
) != byte_size
)
17290 complaint (_("invalid pointer size %d"), byte_size
);
17292 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17294 complaint (_("Invalid DW_AT_alignment"
17295 " - DIE at %s [in module %s]"),
17296 sect_offset_str (die
->sect_off
),
17297 objfile_name (cu
->per_objfile
->objfile
));
17301 /* Should we also complain about unhandled address classes? */
17305 TYPE_LENGTH (type
) = byte_size
;
17306 set_type_align (type
, alignment
);
17307 return set_die_type (die
, type
, cu
);
17310 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17311 the user defined type vector. */
17313 static struct type
*
17314 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17317 struct type
*to_type
;
17318 struct type
*domain
;
17320 to_type
= die_type (die
, cu
);
17321 domain
= die_containing_type (die
, cu
);
17323 /* The calls above may have already set the type for this DIE. */
17324 type
= get_die_type (die
, cu
);
17328 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17329 type
= lookup_methodptr_type (to_type
);
17330 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17332 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17334 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17335 to_type
->fields (), to_type
->num_fields (),
17336 to_type
->has_varargs ());
17337 type
= lookup_methodptr_type (new_type
);
17340 type
= lookup_memberptr_type (to_type
, domain
);
17342 return set_die_type (die
, type
, cu
);
17345 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17346 the user defined type vector. */
17348 static struct type
*
17349 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17350 enum type_code refcode
)
17352 struct comp_unit_head
*cu_header
= &cu
->header
;
17353 struct type
*type
, *target_type
;
17354 struct attribute
*attr
;
17356 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17358 target_type
= die_type (die
, cu
);
17360 /* The die_type call above may have already set the type for this DIE. */
17361 type
= get_die_type (die
, cu
);
17365 type
= lookup_reference_type (target_type
, refcode
);
17366 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17367 if (attr
!= nullptr)
17369 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17373 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17375 maybe_set_alignment (cu
, die
, type
);
17376 return set_die_type (die
, type
, cu
);
17379 /* Add the given cv-qualifiers to the element type of the array. GCC
17380 outputs DWARF type qualifiers that apply to an array, not the
17381 element type. But GDB relies on the array element type to carry
17382 the cv-qualifiers. This mimics section 6.7.3 of the C99
17385 static struct type
*
17386 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17387 struct type
*base_type
, int cnst
, int voltl
)
17389 struct type
*el_type
, *inner_array
;
17391 base_type
= copy_type (base_type
);
17392 inner_array
= base_type
;
17394 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17396 TYPE_TARGET_TYPE (inner_array
) =
17397 copy_type (TYPE_TARGET_TYPE (inner_array
));
17398 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17401 el_type
= TYPE_TARGET_TYPE (inner_array
);
17402 cnst
|= TYPE_CONST (el_type
);
17403 voltl
|= TYPE_VOLATILE (el_type
);
17404 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17406 return set_die_type (die
, base_type
, cu
);
17409 static struct type
*
17410 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17412 struct type
*base_type
, *cv_type
;
17414 base_type
= die_type (die
, cu
);
17416 /* The die_type call above may have already set the type for this DIE. */
17417 cv_type
= get_die_type (die
, cu
);
17421 /* In case the const qualifier is applied to an array type, the element type
17422 is so qualified, not the array type (section 6.7.3 of C99). */
17423 if (base_type
->code () == TYPE_CODE_ARRAY
)
17424 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17426 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17427 return set_die_type (die
, cv_type
, cu
);
17430 static struct type
*
17431 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17433 struct type
*base_type
, *cv_type
;
17435 base_type
= die_type (die
, cu
);
17437 /* The die_type call above may have already set the type for this DIE. */
17438 cv_type
= get_die_type (die
, cu
);
17442 /* In case the volatile qualifier is applied to an array type, the
17443 element type is so qualified, not the array type (section 6.7.3
17445 if (base_type
->code () == TYPE_CODE_ARRAY
)
17446 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17448 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17449 return set_die_type (die
, cv_type
, cu
);
17452 /* Handle DW_TAG_restrict_type. */
17454 static struct type
*
17455 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17457 struct type
*base_type
, *cv_type
;
17459 base_type
= die_type (die
, cu
);
17461 /* The die_type call above may have already set the type for this DIE. */
17462 cv_type
= get_die_type (die
, cu
);
17466 cv_type
= make_restrict_type (base_type
);
17467 return set_die_type (die
, cv_type
, cu
);
17470 /* Handle DW_TAG_atomic_type. */
17472 static struct type
*
17473 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17475 struct type
*base_type
, *cv_type
;
17477 base_type
= die_type (die
, cu
);
17479 /* The die_type call above may have already set the type for this DIE. */
17480 cv_type
= get_die_type (die
, cu
);
17484 cv_type
= make_atomic_type (base_type
);
17485 return set_die_type (die
, cv_type
, cu
);
17488 /* Extract all information from a DW_TAG_string_type DIE and add to
17489 the user defined type vector. It isn't really a user defined type,
17490 but it behaves like one, with other DIE's using an AT_user_def_type
17491 attribute to reference it. */
17493 static struct type
*
17494 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17496 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17497 struct gdbarch
*gdbarch
= objfile
->arch ();
17498 struct type
*type
, *range_type
, *index_type
, *char_type
;
17499 struct attribute
*attr
;
17500 struct dynamic_prop prop
;
17501 bool length_is_constant
= true;
17504 /* There are a couple of places where bit sizes might be made use of
17505 when parsing a DW_TAG_string_type, however, no producer that we know
17506 of make use of these. Handling bit sizes that are a multiple of the
17507 byte size is easy enough, but what about other bit sizes? Lets deal
17508 with that problem when we have to. Warn about these attributes being
17509 unsupported, then parse the type and ignore them like we always
17511 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17512 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17514 static bool warning_printed
= false;
17515 if (!warning_printed
)
17517 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17518 "currently supported on DW_TAG_string_type."));
17519 warning_printed
= true;
17523 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17524 if (attr
!= nullptr && !attr
->form_is_constant ())
17526 /* The string length describes the location at which the length of
17527 the string can be found. The size of the length field can be
17528 specified with one of the attributes below. */
17529 struct type
*prop_type
;
17530 struct attribute
*len
17531 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17532 if (len
== nullptr)
17533 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17534 if (len
!= nullptr && len
->form_is_constant ())
17536 /* Pass 0 as the default as we know this attribute is constant
17537 and the default value will not be returned. */
17538 LONGEST sz
= len
->constant_value (0);
17539 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17543 /* If the size is not specified then we assume it is the size of
17544 an address on this target. */
17545 prop_type
= cu
->addr_sized_int_type (true);
17548 /* Convert the attribute into a dynamic property. */
17549 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17552 length_is_constant
= false;
17554 else if (attr
!= nullptr)
17556 /* This DW_AT_string_length just contains the length with no
17557 indirection. There's no need to create a dynamic property in this
17558 case. Pass 0 for the default value as we know it will not be
17559 returned in this case. */
17560 length
= attr
->constant_value (0);
17562 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17564 /* We don't currently support non-constant byte sizes for strings. */
17565 length
= attr
->constant_value (1);
17569 /* Use 1 as a fallback length if we have nothing else. */
17573 index_type
= objfile_type (objfile
)->builtin_int
;
17574 if (length_is_constant
)
17575 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17578 struct dynamic_prop low_bound
;
17580 low_bound
.set_const_val (1);
17581 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17583 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17584 type
= create_string_type (NULL
, char_type
, range_type
);
17586 return set_die_type (die
, type
, cu
);
17589 /* Assuming that DIE corresponds to a function, returns nonzero
17590 if the function is prototyped. */
17593 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17595 struct attribute
*attr
;
17597 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17598 if (attr
&& attr
->as_boolean ())
17601 /* The DWARF standard implies that the DW_AT_prototyped attribute
17602 is only meaningful for C, but the concept also extends to other
17603 languages that allow unprototyped functions (Eg: Objective C).
17604 For all other languages, assume that functions are always
17606 if (cu
->language
!= language_c
17607 && cu
->language
!= language_objc
17608 && cu
->language
!= language_opencl
)
17611 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17612 prototyped and unprototyped functions; default to prototyped,
17613 since that is more common in modern code (and RealView warns
17614 about unprototyped functions). */
17615 if (producer_is_realview (cu
->producer
))
17621 /* Handle DIES due to C code like:
17625 int (*funcp)(int a, long l);
17629 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17631 static struct type
*
17632 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17634 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17635 struct type
*type
; /* Type that this function returns. */
17636 struct type
*ftype
; /* Function that returns above type. */
17637 struct attribute
*attr
;
17639 type
= die_type (die
, cu
);
17641 /* The die_type call above may have already set the type for this DIE. */
17642 ftype
= get_die_type (die
, cu
);
17646 ftype
= lookup_function_type (type
);
17648 if (prototyped_function_p (die
, cu
))
17649 ftype
->set_is_prototyped (true);
17651 /* Store the calling convention in the type if it's available in
17652 the subroutine die. Otherwise set the calling convention to
17653 the default value DW_CC_normal. */
17654 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17655 if (attr
!= nullptr
17656 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17657 TYPE_CALLING_CONVENTION (ftype
)
17658 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17659 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17660 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17662 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17664 /* Record whether the function returns normally to its caller or not
17665 if the DWARF producer set that information. */
17666 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17667 if (attr
&& attr
->as_boolean ())
17668 TYPE_NO_RETURN (ftype
) = 1;
17670 /* We need to add the subroutine type to the die immediately so
17671 we don't infinitely recurse when dealing with parameters
17672 declared as the same subroutine type. */
17673 set_die_type (die
, ftype
, cu
);
17675 if (die
->child
!= NULL
)
17677 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17678 struct die_info
*child_die
;
17679 int nparams
, iparams
;
17681 /* Count the number of parameters.
17682 FIXME: GDB currently ignores vararg functions, but knows about
17683 vararg member functions. */
17685 child_die
= die
->child
;
17686 while (child_die
&& child_die
->tag
)
17688 if (child_die
->tag
== DW_TAG_formal_parameter
)
17690 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17691 ftype
->set_has_varargs (true);
17693 child_die
= child_die
->sibling
;
17696 /* Allocate storage for parameters and fill them in. */
17697 ftype
->set_num_fields (nparams
);
17699 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17701 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17702 even if we error out during the parameters reading below. */
17703 for (iparams
= 0; iparams
< nparams
; iparams
++)
17704 ftype
->field (iparams
).set_type (void_type
);
17707 child_die
= die
->child
;
17708 while (child_die
&& child_die
->tag
)
17710 if (child_die
->tag
== DW_TAG_formal_parameter
)
17712 struct type
*arg_type
;
17714 /* DWARF version 2 has no clean way to discern C++
17715 static and non-static member functions. G++ helps
17716 GDB by marking the first parameter for non-static
17717 member functions (which is the this pointer) as
17718 artificial. We pass this information to
17719 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17721 DWARF version 3 added DW_AT_object_pointer, which GCC
17722 4.5 does not yet generate. */
17723 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17724 if (attr
!= nullptr)
17725 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17727 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17728 arg_type
= die_type (child_die
, cu
);
17730 /* RealView does not mark THIS as const, which the testsuite
17731 expects. GCC marks THIS as const in method definitions,
17732 but not in the class specifications (GCC PR 43053). */
17733 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17734 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17737 struct dwarf2_cu
*arg_cu
= cu
;
17738 const char *name
= dwarf2_name (child_die
, cu
);
17740 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17741 if (attr
!= nullptr)
17743 /* If the compiler emits this, use it. */
17744 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17747 else if (name
&& strcmp (name
, "this") == 0)
17748 /* Function definitions will have the argument names. */
17750 else if (name
== NULL
&& iparams
== 0)
17751 /* Declarations may not have the names, so like
17752 elsewhere in GDB, assume an artificial first
17753 argument is "this". */
17757 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17761 ftype
->field (iparams
).set_type (arg_type
);
17764 child_die
= child_die
->sibling
;
17771 static struct type
*
17772 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17774 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17775 const char *name
= NULL
;
17776 struct type
*this_type
, *target_type
;
17778 name
= dwarf2_full_name (NULL
, die
, cu
);
17779 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17780 this_type
->set_target_is_stub (true);
17781 set_die_type (die
, this_type
, cu
);
17782 target_type
= die_type (die
, cu
);
17783 if (target_type
!= this_type
)
17784 TYPE_TARGET_TYPE (this_type
) = target_type
;
17787 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17788 spec and cause infinite loops in GDB. */
17789 complaint (_("Self-referential DW_TAG_typedef "
17790 "- DIE at %s [in module %s]"),
17791 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17792 TYPE_TARGET_TYPE (this_type
) = NULL
;
17796 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17797 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17798 Handle these by just returning the target type, rather than
17799 constructing an anonymous typedef type and trying to handle this
17801 set_die_type (die
, target_type
, cu
);
17802 return target_type
;
17807 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17808 (which may be different from NAME) to the architecture back-end to allow
17809 it to guess the correct format if necessary. */
17811 static struct type
*
17812 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17813 const char *name_hint
, enum bfd_endian byte_order
)
17815 struct gdbarch
*gdbarch
= objfile
->arch ();
17816 const struct floatformat
**format
;
17819 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17821 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17823 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17828 /* Allocate an integer type of size BITS and name NAME. */
17830 static struct type
*
17831 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17832 int bits
, int unsigned_p
, const char *name
)
17836 /* Versions of Intel's C Compiler generate an integer type called "void"
17837 instead of using DW_TAG_unspecified_type. This has been seen on
17838 at least versions 14, 17, and 18. */
17839 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17840 && strcmp (name
, "void") == 0)
17841 type
= objfile_type (objfile
)->builtin_void
;
17843 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17848 /* Initialise and return a floating point type of size BITS suitable for
17849 use as a component of a complex number. The NAME_HINT is passed through
17850 when initialising the floating point type and is the name of the complex
17853 As DWARF doesn't currently provide an explicit name for the components
17854 of a complex number, but it can be helpful to have these components
17855 named, we try to select a suitable name based on the size of the
17857 static struct type
*
17858 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17859 struct objfile
*objfile
,
17860 int bits
, const char *name_hint
,
17861 enum bfd_endian byte_order
)
17863 gdbarch
*gdbarch
= objfile
->arch ();
17864 struct type
*tt
= nullptr;
17866 /* Try to find a suitable floating point builtin type of size BITS.
17867 We're going to use the name of this type as the name for the complex
17868 target type that we are about to create. */
17869 switch (cu
->language
)
17871 case language_fortran
:
17875 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17878 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17880 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17882 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17890 tt
= builtin_type (gdbarch
)->builtin_float
;
17893 tt
= builtin_type (gdbarch
)->builtin_double
;
17895 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17897 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17903 /* If the type we found doesn't match the size we were looking for, then
17904 pretend we didn't find a type at all, the complex target type we
17905 create will then be nameless. */
17906 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17909 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17910 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17913 /* Find a representation of a given base type and install
17914 it in the TYPE field of the die. */
17916 static struct type
*
17917 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17919 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17921 struct attribute
*attr
;
17922 int encoding
= 0, bits
= 0;
17926 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17927 if (attr
!= nullptr && attr
->form_is_constant ())
17928 encoding
= attr
->constant_value (0);
17929 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17930 if (attr
!= nullptr)
17931 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
17932 name
= dwarf2_name (die
, cu
);
17934 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17936 arch
= objfile
->arch ();
17937 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17939 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17940 if (attr
!= nullptr && attr
->form_is_constant ())
17942 int endianity
= attr
->constant_value (0);
17947 byte_order
= BFD_ENDIAN_BIG
;
17949 case DW_END_little
:
17950 byte_order
= BFD_ENDIAN_LITTLE
;
17953 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17960 case DW_ATE_address
:
17961 /* Turn DW_ATE_address into a void * pointer. */
17962 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17963 type
= init_pointer_type (objfile
, bits
, name
, type
);
17965 case DW_ATE_boolean
:
17966 type
= init_boolean_type (objfile
, bits
, 1, name
);
17968 case DW_ATE_complex_float
:
17969 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17971 if (type
->code () == TYPE_CODE_ERROR
)
17973 if (name
== nullptr)
17975 struct obstack
*obstack
17976 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17977 name
= obconcat (obstack
, "_Complex ", type
->name (),
17980 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17983 type
= init_complex_type (name
, type
);
17985 case DW_ATE_decimal_float
:
17986 type
= init_decfloat_type (objfile
, bits
, name
);
17989 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17991 case DW_ATE_signed
:
17992 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17994 case DW_ATE_unsigned
:
17995 if (cu
->language
== language_fortran
17997 && startswith (name
, "character("))
17998 type
= init_character_type (objfile
, bits
, 1, name
);
18000 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18002 case DW_ATE_signed_char
:
18003 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18004 || cu
->language
== language_pascal
18005 || cu
->language
== language_fortran
)
18006 type
= init_character_type (objfile
, bits
, 0, name
);
18008 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18010 case DW_ATE_unsigned_char
:
18011 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18012 || cu
->language
== language_pascal
18013 || cu
->language
== language_fortran
18014 || cu
->language
== language_rust
)
18015 type
= init_character_type (objfile
, bits
, 1, name
);
18017 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18022 type
= builtin_type (arch
)->builtin_char16
;
18023 else if (bits
== 32)
18024 type
= builtin_type (arch
)->builtin_char32
;
18027 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18029 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18031 return set_die_type (die
, type
, cu
);
18036 complaint (_("unsupported DW_AT_encoding: '%s'"),
18037 dwarf_type_encoding_name (encoding
));
18038 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18042 if (name
&& strcmp (name
, "char") == 0)
18043 type
->set_has_no_signedness (true);
18045 maybe_set_alignment (cu
, die
, type
);
18047 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18049 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18051 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18052 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18054 unsigned real_bit_size
= attr
->as_unsigned ();
18055 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18056 /* Only use the attributes if they make sense together. */
18057 if (attr
== nullptr
18058 || (attr
->as_unsigned () + real_bit_size
18059 <= 8 * TYPE_LENGTH (type
)))
18061 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18063 if (attr
!= nullptr)
18064 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18065 = attr
->as_unsigned ();
18070 return set_die_type (die
, type
, cu
);
18073 /* Parse dwarf attribute if it's a block, reference or constant and put the
18074 resulting value of the attribute into struct bound_prop.
18075 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18078 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18079 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18080 struct type
*default_type
)
18082 struct dwarf2_property_baton
*baton
;
18083 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18084 struct objfile
*objfile
= per_objfile
->objfile
;
18085 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18087 gdb_assert (default_type
!= NULL
);
18089 if (attr
== NULL
|| prop
== NULL
)
18092 if (attr
->form_is_block ())
18094 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18095 baton
->property_type
= default_type
;
18096 baton
->locexpr
.per_cu
= cu
->per_cu
;
18097 baton
->locexpr
.per_objfile
= per_objfile
;
18099 struct dwarf_block
*block
= attr
->as_block ();
18100 baton
->locexpr
.size
= block
->size
;
18101 baton
->locexpr
.data
= block
->data
;
18102 switch (attr
->name
)
18104 case DW_AT_string_length
:
18105 baton
->locexpr
.is_reference
= true;
18108 baton
->locexpr
.is_reference
= false;
18112 prop
->set_locexpr (baton
);
18113 gdb_assert (prop
->baton () != NULL
);
18115 else if (attr
->form_is_ref ())
18117 struct dwarf2_cu
*target_cu
= cu
;
18118 struct die_info
*target_die
;
18119 struct attribute
*target_attr
;
18121 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18122 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18123 if (target_attr
== NULL
)
18124 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18126 if (target_attr
== NULL
)
18129 switch (target_attr
->name
)
18131 case DW_AT_location
:
18132 if (target_attr
->form_is_section_offset ())
18134 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18135 baton
->property_type
= die_type (target_die
, target_cu
);
18136 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18137 prop
->set_loclist (baton
);
18138 gdb_assert (prop
->baton () != NULL
);
18140 else if (target_attr
->form_is_block ())
18142 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18143 baton
->property_type
= die_type (target_die
, target_cu
);
18144 baton
->locexpr
.per_cu
= cu
->per_cu
;
18145 baton
->locexpr
.per_objfile
= per_objfile
;
18146 struct dwarf_block
*block
= target_attr
->as_block ();
18147 baton
->locexpr
.size
= block
->size
;
18148 baton
->locexpr
.data
= block
->data
;
18149 baton
->locexpr
.is_reference
= true;
18150 prop
->set_locexpr (baton
);
18151 gdb_assert (prop
->baton () != NULL
);
18155 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18156 "dynamic property");
18160 case DW_AT_data_member_location
:
18164 if (!handle_data_member_location (target_die
, target_cu
,
18168 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18169 baton
->property_type
= read_type_die (target_die
->parent
,
18171 baton
->offset_info
.offset
= offset
;
18172 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18173 prop
->set_addr_offset (baton
);
18178 else if (attr
->form_is_constant ())
18179 prop
->set_const_val (attr
->constant_value (0));
18182 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18183 dwarf2_name (die
, cu
));
18193 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18195 struct type
*int_type
;
18197 /* Helper macro to examine the various builtin types. */
18198 #define TRY_TYPE(F) \
18199 int_type = (unsigned_p \
18200 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18201 : objfile_type (objfile)->builtin_ ## F); \
18202 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18209 TRY_TYPE (long_long
);
18213 gdb_assert_not_reached ("unable to find suitable integer type");
18219 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18221 int addr_size
= this->per_cu
->addr_size ();
18222 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18225 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18226 present (which is valid) then compute the default type based on the
18227 compilation units address size. */
18229 static struct type
*
18230 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18232 struct type
*index_type
= die_type (die
, cu
);
18234 /* Dwarf-2 specifications explicitly allows to create subrange types
18235 without specifying a base type.
18236 In that case, the base type must be set to the type of
18237 the lower bound, upper bound or count, in that order, if any of these
18238 three attributes references an object that has a type.
18239 If no base type is found, the Dwarf-2 specifications say that
18240 a signed integer type of size equal to the size of an address should
18242 For the following C code: `extern char gdb_int [];'
18243 GCC produces an empty range DIE.
18244 FIXME: muller/2010-05-28: Possible references to object for low bound,
18245 high bound or count are not yet handled by this code. */
18246 if (index_type
->code () == TYPE_CODE_VOID
)
18247 index_type
= cu
->addr_sized_int_type (false);
18252 /* Read the given DW_AT_subrange DIE. */
18254 static struct type
*
18255 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18257 struct type
*base_type
, *orig_base_type
;
18258 struct type
*range_type
;
18259 struct attribute
*attr
;
18260 struct dynamic_prop low
, high
;
18261 int low_default_is_valid
;
18262 int high_bound_is_count
= 0;
18264 ULONGEST negative_mask
;
18266 orig_base_type
= read_subrange_index_type (die
, cu
);
18268 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18269 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18270 creating the range type, but we use the result of check_typedef
18271 when examining properties of the type. */
18272 base_type
= check_typedef (orig_base_type
);
18274 /* The die_type call above may have already set the type for this DIE. */
18275 range_type
= get_die_type (die
, cu
);
18279 high
.set_const_val (0);
18281 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18282 omitting DW_AT_lower_bound. */
18283 switch (cu
->language
)
18286 case language_cplus
:
18287 low
.set_const_val (0);
18288 low_default_is_valid
= 1;
18290 case language_fortran
:
18291 low
.set_const_val (1);
18292 low_default_is_valid
= 1;
18295 case language_objc
:
18296 case language_rust
:
18297 low
.set_const_val (0);
18298 low_default_is_valid
= (cu
->header
.version
>= 4);
18302 case language_pascal
:
18303 low
.set_const_val (1);
18304 low_default_is_valid
= (cu
->header
.version
>= 4);
18307 low
.set_const_val (0);
18308 low_default_is_valid
= 0;
18312 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18313 if (attr
!= nullptr)
18314 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18315 else if (!low_default_is_valid
)
18316 complaint (_("Missing DW_AT_lower_bound "
18317 "- DIE at %s [in module %s]"),
18318 sect_offset_str (die
->sect_off
),
18319 objfile_name (cu
->per_objfile
->objfile
));
18321 struct attribute
*attr_ub
, *attr_count
;
18322 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18323 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18325 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18326 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18328 /* If bounds are constant do the final calculation here. */
18329 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18330 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18332 high_bound_is_count
= 1;
18336 if (attr_ub
!= NULL
)
18337 complaint (_("Unresolved DW_AT_upper_bound "
18338 "- DIE at %s [in module %s]"),
18339 sect_offset_str (die
->sect_off
),
18340 objfile_name (cu
->per_objfile
->objfile
));
18341 if (attr_count
!= NULL
)
18342 complaint (_("Unresolved DW_AT_count "
18343 "- DIE at %s [in module %s]"),
18344 sect_offset_str (die
->sect_off
),
18345 objfile_name (cu
->per_objfile
->objfile
));
18350 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18351 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18352 bias
= bias_attr
->constant_value (0);
18354 /* Normally, the DWARF producers are expected to use a signed
18355 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18356 But this is unfortunately not always the case, as witnessed
18357 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18358 is used instead. To work around that ambiguity, we treat
18359 the bounds as signed, and thus sign-extend their values, when
18360 the base type is signed. */
18362 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18363 if (low
.kind () == PROP_CONST
18364 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18365 low
.set_const_val (low
.const_val () | negative_mask
);
18366 if (high
.kind () == PROP_CONST
18367 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18368 high
.set_const_val (high
.const_val () | negative_mask
);
18370 /* Check for bit and byte strides. */
18371 struct dynamic_prop byte_stride_prop
;
18372 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18373 if (attr_byte_stride
!= nullptr)
18375 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18376 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18380 struct dynamic_prop bit_stride_prop
;
18381 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18382 if (attr_bit_stride
!= nullptr)
18384 /* It only makes sense to have either a bit or byte stride. */
18385 if (attr_byte_stride
!= nullptr)
18387 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18388 "- DIE at %s [in module %s]"),
18389 sect_offset_str (die
->sect_off
),
18390 objfile_name (cu
->per_objfile
->objfile
));
18391 attr_bit_stride
= nullptr;
18395 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18396 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18401 if (attr_byte_stride
!= nullptr
18402 || attr_bit_stride
!= nullptr)
18404 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18405 struct dynamic_prop
*stride
18406 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18409 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18410 &high
, bias
, stride
, byte_stride_p
);
18413 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18415 if (high_bound_is_count
)
18416 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18418 /* Ada expects an empty array on no boundary attributes. */
18419 if (attr
== NULL
&& cu
->language
!= language_ada
)
18420 range_type
->bounds ()->high
.set_undefined ();
18422 name
= dwarf2_name (die
, cu
);
18424 range_type
->set_name (name
);
18426 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18427 if (attr
!= nullptr)
18428 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18430 maybe_set_alignment (cu
, die
, range_type
);
18432 set_die_type (die
, range_type
, cu
);
18434 /* set_die_type should be already done. */
18435 set_descriptive_type (range_type
, die
, cu
);
18440 static struct type
*
18441 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18445 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18446 type
->set_name (dwarf2_name (die
, cu
));
18448 /* In Ada, an unspecified type is typically used when the description
18449 of the type is deferred to a different unit. When encountering
18450 such a type, we treat it as a stub, and try to resolve it later on,
18452 if (cu
->language
== language_ada
)
18453 type
->set_is_stub (true);
18455 return set_die_type (die
, type
, cu
);
18458 /* Read a single die and all its descendents. Set the die's sibling
18459 field to NULL; set other fields in the die correctly, and set all
18460 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18461 location of the info_ptr after reading all of those dies. PARENT
18462 is the parent of the die in question. */
18464 static struct die_info
*
18465 read_die_and_children (const struct die_reader_specs
*reader
,
18466 const gdb_byte
*info_ptr
,
18467 const gdb_byte
**new_info_ptr
,
18468 struct die_info
*parent
)
18470 struct die_info
*die
;
18471 const gdb_byte
*cur_ptr
;
18473 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18476 *new_info_ptr
= cur_ptr
;
18479 store_in_ref_table (die
, reader
->cu
);
18481 if (die
->has_children
)
18482 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18486 *new_info_ptr
= cur_ptr
;
18489 die
->sibling
= NULL
;
18490 die
->parent
= parent
;
18494 /* Read a die, all of its descendents, and all of its siblings; set
18495 all of the fields of all of the dies correctly. Arguments are as
18496 in read_die_and_children. */
18498 static struct die_info
*
18499 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18500 const gdb_byte
*info_ptr
,
18501 const gdb_byte
**new_info_ptr
,
18502 struct die_info
*parent
)
18504 struct die_info
*first_die
, *last_sibling
;
18505 const gdb_byte
*cur_ptr
;
18507 cur_ptr
= info_ptr
;
18508 first_die
= last_sibling
= NULL
;
18512 struct die_info
*die
18513 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18517 *new_info_ptr
= cur_ptr
;
18524 last_sibling
->sibling
= die
;
18526 last_sibling
= die
;
18530 /* Read a die, all of its descendents, and all of its siblings; set
18531 all of the fields of all of the dies correctly. Arguments are as
18532 in read_die_and_children.
18533 This the main entry point for reading a DIE and all its children. */
18535 static struct die_info
*
18536 read_die_and_siblings (const struct die_reader_specs
*reader
,
18537 const gdb_byte
*info_ptr
,
18538 const gdb_byte
**new_info_ptr
,
18539 struct die_info
*parent
)
18541 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18542 new_info_ptr
, parent
);
18544 if (dwarf_die_debug
)
18546 fprintf_unfiltered (gdb_stdlog
,
18547 "Read die from %s@0x%x of %s:\n",
18548 reader
->die_section
->get_name (),
18549 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18550 bfd_get_filename (reader
->abfd
));
18551 dump_die (die
, dwarf_die_debug
);
18557 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18559 The caller is responsible for filling in the extra attributes
18560 and updating (*DIEP)->num_attrs.
18561 Set DIEP to point to a newly allocated die with its information,
18562 except for its child, sibling, and parent fields. */
18564 static const gdb_byte
*
18565 read_full_die_1 (const struct die_reader_specs
*reader
,
18566 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18567 int num_extra_attrs
)
18569 unsigned int abbrev_number
, bytes_read
, i
;
18570 struct abbrev_info
*abbrev
;
18571 struct die_info
*die
;
18572 struct dwarf2_cu
*cu
= reader
->cu
;
18573 bfd
*abfd
= reader
->abfd
;
18575 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18576 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18577 info_ptr
+= bytes_read
;
18578 if (!abbrev_number
)
18584 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18586 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18588 bfd_get_filename (abfd
));
18590 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18591 die
->sect_off
= sect_off
;
18592 die
->tag
= abbrev
->tag
;
18593 die
->abbrev
= abbrev_number
;
18594 die
->has_children
= abbrev
->has_children
;
18596 /* Make the result usable.
18597 The caller needs to update num_attrs after adding the extra
18599 die
->num_attrs
= abbrev
->num_attrs
;
18601 bool any_need_reprocess
= false;
18602 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18604 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18606 if (die
->attrs
[i
].requires_reprocessing_p ())
18607 any_need_reprocess
= true;
18610 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18611 if (attr
!= nullptr && attr
->form_is_unsigned ())
18612 cu
->str_offsets_base
= attr
->as_unsigned ();
18614 attr
= die
->attr (DW_AT_loclists_base
);
18615 if (attr
!= nullptr)
18616 cu
->loclist_base
= attr
->as_unsigned ();
18618 auto maybe_addr_base
= die
->addr_base ();
18619 if (maybe_addr_base
.has_value ())
18620 cu
->addr_base
= *maybe_addr_base
;
18622 attr
= die
->attr (DW_AT_rnglists_base
);
18623 if (attr
!= nullptr)
18624 cu
->ranges_base
= attr
->as_unsigned ();
18626 if (any_need_reprocess
)
18628 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18630 if (die
->attrs
[i
].requires_reprocessing_p ())
18631 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18638 /* Read a die and all its attributes.
18639 Set DIEP to point to a newly allocated die with its information,
18640 except for its child, sibling, and parent fields. */
18642 static const gdb_byte
*
18643 read_full_die (const struct die_reader_specs
*reader
,
18644 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18646 const gdb_byte
*result
;
18648 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18650 if (dwarf_die_debug
)
18652 fprintf_unfiltered (gdb_stdlog
,
18653 "Read die from %s@0x%x of %s:\n",
18654 reader
->die_section
->get_name (),
18655 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18656 bfd_get_filename (reader
->abfd
));
18657 dump_die (*diep
, dwarf_die_debug
);
18664 /* Returns nonzero if TAG represents a type that we might generate a partial
18668 is_type_tag_for_partial (int tag
)
18673 /* Some types that would be reasonable to generate partial symbols for,
18674 that we don't at present. */
18675 case DW_TAG_array_type
:
18676 case DW_TAG_file_type
:
18677 case DW_TAG_ptr_to_member_type
:
18678 case DW_TAG_set_type
:
18679 case DW_TAG_string_type
:
18680 case DW_TAG_subroutine_type
:
18682 case DW_TAG_base_type
:
18683 case DW_TAG_class_type
:
18684 case DW_TAG_interface_type
:
18685 case DW_TAG_enumeration_type
:
18686 case DW_TAG_structure_type
:
18687 case DW_TAG_subrange_type
:
18688 case DW_TAG_typedef
:
18689 case DW_TAG_union_type
:
18696 /* Load all DIEs that are interesting for partial symbols into memory. */
18698 static struct partial_die_info
*
18699 load_partial_dies (const struct die_reader_specs
*reader
,
18700 const gdb_byte
*info_ptr
, int building_psymtab
)
18702 struct dwarf2_cu
*cu
= reader
->cu
;
18703 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18704 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18705 unsigned int bytes_read
;
18706 unsigned int load_all
= 0;
18707 int nesting_level
= 1;
18712 gdb_assert (cu
->per_cu
!= NULL
);
18713 if (cu
->per_cu
->load_all_dies
)
18717 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18721 &cu
->comp_unit_obstack
,
18722 hashtab_obstack_allocate
,
18723 dummy_obstack_deallocate
);
18727 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18729 /* A NULL abbrev means the end of a series of children. */
18730 if (abbrev
== NULL
)
18732 if (--nesting_level
== 0)
18735 info_ptr
+= bytes_read
;
18736 last_die
= parent_die
;
18737 parent_die
= parent_die
->die_parent
;
18741 /* Check for template arguments. We never save these; if
18742 they're seen, we just mark the parent, and go on our way. */
18743 if (parent_die
!= NULL
18744 && cu
->language
== language_cplus
18745 && (abbrev
->tag
== DW_TAG_template_type_param
18746 || abbrev
->tag
== DW_TAG_template_value_param
))
18748 parent_die
->has_template_arguments
= 1;
18752 /* We don't need a partial DIE for the template argument. */
18753 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18758 /* We only recurse into c++ subprograms looking for template arguments.
18759 Skip their other children. */
18761 && cu
->language
== language_cplus
18762 && parent_die
!= NULL
18763 && parent_die
->tag
== DW_TAG_subprogram
18764 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18766 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18770 /* Check whether this DIE is interesting enough to save. Normally
18771 we would not be interested in members here, but there may be
18772 later variables referencing them via DW_AT_specification (for
18773 static members). */
18775 && !is_type_tag_for_partial (abbrev
->tag
)
18776 && abbrev
->tag
!= DW_TAG_constant
18777 && abbrev
->tag
!= DW_TAG_enumerator
18778 && abbrev
->tag
!= DW_TAG_subprogram
18779 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18780 && abbrev
->tag
!= DW_TAG_lexical_block
18781 && abbrev
->tag
!= DW_TAG_variable
18782 && abbrev
->tag
!= DW_TAG_namespace
18783 && abbrev
->tag
!= DW_TAG_module
18784 && abbrev
->tag
!= DW_TAG_member
18785 && abbrev
->tag
!= DW_TAG_imported_unit
18786 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18788 /* Otherwise we skip to the next sibling, if any. */
18789 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18793 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18796 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18798 /* This two-pass algorithm for processing partial symbols has a
18799 high cost in cache pressure. Thus, handle some simple cases
18800 here which cover the majority of C partial symbols. DIEs
18801 which neither have specification tags in them, nor could have
18802 specification tags elsewhere pointing at them, can simply be
18803 processed and discarded.
18805 This segment is also optional; scan_partial_symbols and
18806 add_partial_symbol will handle these DIEs if we chain
18807 them in normally. When compilers which do not emit large
18808 quantities of duplicate debug information are more common,
18809 this code can probably be removed. */
18811 /* Any complete simple types at the top level (pretty much all
18812 of them, for a language without namespaces), can be processed
18814 if (parent_die
== NULL
18815 && pdi
.has_specification
== 0
18816 && pdi
.is_declaration
== 0
18817 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18818 || pdi
.tag
== DW_TAG_base_type
18819 || pdi
.tag
== DW_TAG_subrange_type
))
18821 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18822 add_partial_symbol (&pdi
, cu
);
18824 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18828 /* The exception for DW_TAG_typedef with has_children above is
18829 a workaround of GCC PR debug/47510. In the case of this complaint
18830 type_name_or_error will error on such types later.
18832 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18833 it could not find the child DIEs referenced later, this is checked
18834 above. In correct DWARF DW_TAG_typedef should have no children. */
18836 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18837 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18838 "- DIE at %s [in module %s]"),
18839 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18841 /* If we're at the second level, and we're an enumerator, and
18842 our parent has no specification (meaning possibly lives in a
18843 namespace elsewhere), then we can add the partial symbol now
18844 instead of queueing it. */
18845 if (pdi
.tag
== DW_TAG_enumerator
18846 && parent_die
!= NULL
18847 && parent_die
->die_parent
== NULL
18848 && parent_die
->tag
== DW_TAG_enumeration_type
18849 && parent_die
->has_specification
== 0)
18851 if (pdi
.raw_name
== NULL
)
18852 complaint (_("malformed enumerator DIE ignored"));
18853 else if (building_psymtab
)
18854 add_partial_symbol (&pdi
, cu
);
18856 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18860 struct partial_die_info
*part_die
18861 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18863 /* We'll save this DIE so link it in. */
18864 part_die
->die_parent
= parent_die
;
18865 part_die
->die_sibling
= NULL
;
18866 part_die
->die_child
= NULL
;
18868 if (last_die
&& last_die
== parent_die
)
18869 last_die
->die_child
= part_die
;
18871 last_die
->die_sibling
= part_die
;
18873 last_die
= part_die
;
18875 if (first_die
== NULL
)
18876 first_die
= part_die
;
18878 /* Maybe add the DIE to the hash table. Not all DIEs that we
18879 find interesting need to be in the hash table, because we
18880 also have the parent/sibling/child chains; only those that we
18881 might refer to by offset later during partial symbol reading.
18883 For now this means things that might have be the target of a
18884 DW_AT_specification, DW_AT_abstract_origin, or
18885 DW_AT_extension. DW_AT_extension will refer only to
18886 namespaces; DW_AT_abstract_origin refers to functions (and
18887 many things under the function DIE, but we do not recurse
18888 into function DIEs during partial symbol reading) and
18889 possibly variables as well; DW_AT_specification refers to
18890 declarations. Declarations ought to have the DW_AT_declaration
18891 flag. It happens that GCC forgets to put it in sometimes, but
18892 only for functions, not for types.
18894 Adding more things than necessary to the hash table is harmless
18895 except for the performance cost. Adding too few will result in
18896 wasted time in find_partial_die, when we reread the compilation
18897 unit with load_all_dies set. */
18900 || abbrev
->tag
== DW_TAG_constant
18901 || abbrev
->tag
== DW_TAG_subprogram
18902 || abbrev
->tag
== DW_TAG_variable
18903 || abbrev
->tag
== DW_TAG_namespace
18904 || part_die
->is_declaration
)
18908 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18909 to_underlying (part_die
->sect_off
),
18914 /* For some DIEs we want to follow their children (if any). For C
18915 we have no reason to follow the children of structures; for other
18916 languages we have to, so that we can get at method physnames
18917 to infer fully qualified class names, for DW_AT_specification,
18918 and for C++ template arguments. For C++, we also look one level
18919 inside functions to find template arguments (if the name of the
18920 function does not already contain the template arguments).
18922 For Ada and Fortran, we need to scan the children of subprograms
18923 and lexical blocks as well because these languages allow the
18924 definition of nested entities that could be interesting for the
18925 debugger, such as nested subprograms for instance. */
18926 if (last_die
->has_children
18928 || last_die
->tag
== DW_TAG_namespace
18929 || last_die
->tag
== DW_TAG_module
18930 || last_die
->tag
== DW_TAG_enumeration_type
18931 || (cu
->language
== language_cplus
18932 && last_die
->tag
== DW_TAG_subprogram
18933 && (last_die
->raw_name
== NULL
18934 || strchr (last_die
->raw_name
, '<') == NULL
))
18935 || (cu
->language
!= language_c
18936 && (last_die
->tag
== DW_TAG_class_type
18937 || last_die
->tag
== DW_TAG_interface_type
18938 || last_die
->tag
== DW_TAG_structure_type
18939 || last_die
->tag
== DW_TAG_union_type
))
18940 || ((cu
->language
== language_ada
18941 || cu
->language
== language_fortran
)
18942 && (last_die
->tag
== DW_TAG_subprogram
18943 || last_die
->tag
== DW_TAG_lexical_block
))))
18946 parent_die
= last_die
;
18950 /* Otherwise we skip to the next sibling, if any. */
18951 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18953 /* Back to the top, do it again. */
18957 partial_die_info::partial_die_info (sect_offset sect_off_
,
18958 struct abbrev_info
*abbrev
)
18959 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18963 /* See class definition. */
18966 partial_die_info::name (dwarf2_cu
*cu
)
18968 if (!canonical_name
&& raw_name
!= nullptr)
18970 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18971 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
18972 canonical_name
= 1;
18978 /* Read a minimal amount of information into the minimal die structure.
18979 INFO_PTR should point just after the initial uleb128 of a DIE. */
18982 partial_die_info::read (const struct die_reader_specs
*reader
,
18983 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18985 struct dwarf2_cu
*cu
= reader
->cu
;
18986 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18988 int has_low_pc_attr
= 0;
18989 int has_high_pc_attr
= 0;
18990 int high_pc_relative
= 0;
18992 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18995 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18996 /* String and address offsets that need to do the reprocessing have
18997 already been read at this point, so there is no need to wait until
18998 the loop terminates to do the reprocessing. */
18999 if (attr
.requires_reprocessing_p ())
19000 read_attribute_reprocess (reader
, &attr
, tag
);
19001 /* Store the data if it is of an attribute we want to keep in a
19002 partial symbol table. */
19008 case DW_TAG_compile_unit
:
19009 case DW_TAG_partial_unit
:
19010 case DW_TAG_type_unit
:
19011 /* Compilation units have a DW_AT_name that is a filename, not
19012 a source language identifier. */
19013 case DW_TAG_enumeration_type
:
19014 case DW_TAG_enumerator
:
19015 /* These tags always have simple identifiers already; no need
19016 to canonicalize them. */
19017 canonical_name
= 1;
19018 raw_name
= attr
.as_string ();
19021 canonical_name
= 0;
19022 raw_name
= attr
.as_string ();
19026 case DW_AT_linkage_name
:
19027 case DW_AT_MIPS_linkage_name
:
19028 /* Note that both forms of linkage name might appear. We
19029 assume they will be the same, and we only store the last
19031 linkage_name
= attr
.as_string ();
19034 has_low_pc_attr
= 1;
19035 lowpc
= attr
.as_address ();
19037 case DW_AT_high_pc
:
19038 has_high_pc_attr
= 1;
19039 highpc
= attr
.as_address ();
19040 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19041 high_pc_relative
= 1;
19043 case DW_AT_location
:
19044 /* Support the .debug_loc offsets. */
19045 if (attr
.form_is_block ())
19047 d
.locdesc
= attr
.as_block ();
19049 else if (attr
.form_is_section_offset ())
19051 dwarf2_complex_location_expr_complaint ();
19055 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19056 "partial symbol information");
19059 case DW_AT_external
:
19060 is_external
= attr
.as_boolean ();
19062 case DW_AT_declaration
:
19063 is_declaration
= attr
.as_boolean ();
19068 case DW_AT_abstract_origin
:
19069 case DW_AT_specification
:
19070 case DW_AT_extension
:
19071 has_specification
= 1;
19072 spec_offset
= attr
.get_ref_die_offset ();
19073 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19074 || cu
->per_cu
->is_dwz
);
19076 case DW_AT_sibling
:
19077 /* Ignore absolute siblings, they might point outside of
19078 the current compile unit. */
19079 if (attr
.form
== DW_FORM_ref_addr
)
19080 complaint (_("ignoring absolute DW_AT_sibling"));
19083 const gdb_byte
*buffer
= reader
->buffer
;
19084 sect_offset off
= attr
.get_ref_die_offset ();
19085 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19087 if (sibling_ptr
< info_ptr
)
19088 complaint (_("DW_AT_sibling points backwards"));
19089 else if (sibling_ptr
> reader
->buffer_end
)
19090 reader
->die_section
->overflow_complaint ();
19092 sibling
= sibling_ptr
;
19095 case DW_AT_byte_size
:
19098 case DW_AT_const_value
:
19099 has_const_value
= 1;
19101 case DW_AT_calling_convention
:
19102 /* DWARF doesn't provide a way to identify a program's source-level
19103 entry point. DW_AT_calling_convention attributes are only meant
19104 to describe functions' calling conventions.
19106 However, because it's a necessary piece of information in
19107 Fortran, and before DWARF 4 DW_CC_program was the only
19108 piece of debugging information whose definition refers to
19109 a 'main program' at all, several compilers marked Fortran
19110 main programs with DW_CC_program --- even when those
19111 functions use the standard calling conventions.
19113 Although DWARF now specifies a way to provide this
19114 information, we support this practice for backward
19116 if (attr
.constant_value (0) == DW_CC_program
19117 && cu
->language
== language_fortran
)
19118 main_subprogram
= 1;
19122 LONGEST value
= attr
.constant_value (-1);
19123 if (value
== DW_INL_inlined
19124 || value
== DW_INL_declared_inlined
)
19125 may_be_inlined
= 1;
19130 if (tag
== DW_TAG_imported_unit
)
19132 d
.sect_off
= attr
.get_ref_die_offset ();
19133 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19134 || cu
->per_cu
->is_dwz
);
19138 case DW_AT_main_subprogram
:
19139 main_subprogram
= attr
.as_boolean ();
19144 /* DW_AT_rnglists_base does not apply to DIEs from the DWO
19145 skeleton. We take advantage of the fact the DW_AT_ranges
19146 does not appear in DW_TAG_compile_unit of DWO files.
19148 Attributes of the form DW_FORM_rnglistx have already had
19149 their value changed by read_rnglist_index and already
19150 include DW_AT_rnglists_base, so don't need to add the ranges
19152 int need_ranges_base
= (tag
!= DW_TAG_compile_unit
19153 && attr
.form
!= DW_FORM_rnglistx
);
19154 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19155 but that requires a full DIE, so instead we just
19157 unsigned int ranges_offset
= (attr
.constant_value (0)
19158 + (need_ranges_base
19162 /* Value of the DW_AT_ranges attribute is the offset in the
19163 .debug_ranges section. */
19164 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19175 /* For Ada, if both the name and the linkage name appear, we prefer
19176 the latter. This lets "catch exception" work better, regardless
19177 of the order in which the name and linkage name were emitted.
19178 Really, though, this is just a workaround for the fact that gdb
19179 doesn't store both the name and the linkage name. */
19180 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19181 raw_name
= linkage_name
;
19183 if (high_pc_relative
)
19186 if (has_low_pc_attr
&& has_high_pc_attr
)
19188 /* When using the GNU linker, .gnu.linkonce. sections are used to
19189 eliminate duplicate copies of functions and vtables and such.
19190 The linker will arbitrarily choose one and discard the others.
19191 The AT_*_pc values for such functions refer to local labels in
19192 these sections. If the section from that file was discarded, the
19193 labels are not in the output, so the relocs get a value of 0.
19194 If this is a discarded function, mark the pc bounds as invalid,
19195 so that GDB will ignore it. */
19196 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19198 struct objfile
*objfile
= per_objfile
->objfile
;
19199 struct gdbarch
*gdbarch
= objfile
->arch ();
19201 complaint (_("DW_AT_low_pc %s is zero "
19202 "for DIE at %s [in module %s]"),
19203 paddress (gdbarch
, lowpc
),
19204 sect_offset_str (sect_off
),
19205 objfile_name (objfile
));
19207 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19208 else if (lowpc
>= highpc
)
19210 struct objfile
*objfile
= per_objfile
->objfile
;
19211 struct gdbarch
*gdbarch
= objfile
->arch ();
19213 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19214 "for DIE at %s [in module %s]"),
19215 paddress (gdbarch
, lowpc
),
19216 paddress (gdbarch
, highpc
),
19217 sect_offset_str (sect_off
),
19218 objfile_name (objfile
));
19227 /* Find a cached partial DIE at OFFSET in CU. */
19229 struct partial_die_info
*
19230 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19232 struct partial_die_info
*lookup_die
= NULL
;
19233 struct partial_die_info
part_die (sect_off
);
19235 lookup_die
= ((struct partial_die_info
*)
19236 htab_find_with_hash (partial_dies
, &part_die
,
19237 to_underlying (sect_off
)));
19242 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19243 except in the case of .debug_types DIEs which do not reference
19244 outside their CU (they do however referencing other types via
19245 DW_FORM_ref_sig8). */
19247 static const struct cu_partial_die_info
19248 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19250 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19251 struct objfile
*objfile
= per_objfile
->objfile
;
19252 struct partial_die_info
*pd
= NULL
;
19254 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19255 && cu
->header
.offset_in_cu_p (sect_off
))
19257 pd
= cu
->find_partial_die (sect_off
);
19260 /* We missed recording what we needed.
19261 Load all dies and try again. */
19265 /* TUs don't reference other CUs/TUs (except via type signatures). */
19266 if (cu
->per_cu
->is_debug_types
)
19268 error (_("Dwarf Error: Type Unit at offset %s contains"
19269 " external reference to offset %s [in module %s].\n"),
19270 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19271 bfd_get_filename (objfile
->obfd
));
19273 dwarf2_per_cu_data
*per_cu
19274 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19277 cu
= per_objfile
->get_cu (per_cu
);
19278 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19279 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19281 cu
= per_objfile
->get_cu (per_cu
);
19284 pd
= cu
->find_partial_die (sect_off
);
19287 /* If we didn't find it, and not all dies have been loaded,
19288 load them all and try again. */
19290 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19292 cu
->per_cu
->load_all_dies
= 1;
19294 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19295 THIS_CU->cu may already be in use. So we can't just free it and
19296 replace its DIEs with the ones we read in. Instead, we leave those
19297 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19298 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19300 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19302 pd
= cu
->find_partial_die (sect_off
);
19306 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19307 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19311 /* See if we can figure out if the class lives in a namespace. We do
19312 this by looking for a member function; its demangled name will
19313 contain namespace info, if there is any. */
19316 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19317 struct dwarf2_cu
*cu
)
19319 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19320 what template types look like, because the demangler
19321 frequently doesn't give the same name as the debug info. We
19322 could fix this by only using the demangled name to get the
19323 prefix (but see comment in read_structure_type). */
19325 struct partial_die_info
*real_pdi
;
19326 struct partial_die_info
*child_pdi
;
19328 /* If this DIE (this DIE's specification, if any) has a parent, then
19329 we should not do this. We'll prepend the parent's fully qualified
19330 name when we create the partial symbol. */
19332 real_pdi
= struct_pdi
;
19333 while (real_pdi
->has_specification
)
19335 auto res
= find_partial_die (real_pdi
->spec_offset
,
19336 real_pdi
->spec_is_dwz
, cu
);
19337 real_pdi
= res
.pdi
;
19341 if (real_pdi
->die_parent
!= NULL
)
19344 for (child_pdi
= struct_pdi
->die_child
;
19346 child_pdi
= child_pdi
->die_sibling
)
19348 if (child_pdi
->tag
== DW_TAG_subprogram
19349 && child_pdi
->linkage_name
!= NULL
)
19351 gdb::unique_xmalloc_ptr
<char> actual_class_name
19352 (cu
->language_defn
->class_name_from_physname
19353 (child_pdi
->linkage_name
));
19354 if (actual_class_name
!= NULL
)
19356 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19357 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19358 struct_pdi
->canonical_name
= 1;
19365 /* Return true if a DIE with TAG may have the DW_AT_const_value
19369 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19373 case DW_TAG_constant
:
19374 case DW_TAG_enumerator
:
19375 case DW_TAG_formal_parameter
:
19376 case DW_TAG_template_value_param
:
19377 case DW_TAG_variable
:
19385 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19387 /* Once we've fixed up a die, there's no point in doing so again.
19388 This also avoids a memory leak if we were to call
19389 guess_partial_die_structure_name multiple times. */
19393 /* If we found a reference attribute and the DIE has no name, try
19394 to find a name in the referred to DIE. */
19396 if (raw_name
== NULL
&& has_specification
)
19398 struct partial_die_info
*spec_die
;
19400 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19401 spec_die
= res
.pdi
;
19404 spec_die
->fixup (cu
);
19406 if (spec_die
->raw_name
)
19408 raw_name
= spec_die
->raw_name
;
19409 canonical_name
= spec_die
->canonical_name
;
19411 /* Copy DW_AT_external attribute if it is set. */
19412 if (spec_die
->is_external
)
19413 is_external
= spec_die
->is_external
;
19417 if (!has_const_value
&& has_specification
19418 && can_have_DW_AT_const_value_p (tag
))
19420 struct partial_die_info
*spec_die
;
19422 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19423 spec_die
= res
.pdi
;
19426 spec_die
->fixup (cu
);
19428 if (spec_die
->has_const_value
)
19430 /* Copy DW_AT_const_value attribute if it is set. */
19431 has_const_value
= spec_die
->has_const_value
;
19435 /* Set default names for some unnamed DIEs. */
19437 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19439 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19440 canonical_name
= 1;
19443 /* If there is no parent die to provide a namespace, and there are
19444 children, see if we can determine the namespace from their linkage
19446 if (cu
->language
== language_cplus
19447 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19448 && die_parent
== NULL
19450 && (tag
== DW_TAG_class_type
19451 || tag
== DW_TAG_structure_type
19452 || tag
== DW_TAG_union_type
))
19453 guess_partial_die_structure_name (this, cu
);
19455 /* GCC might emit a nameless struct or union that has a linkage
19456 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19457 if (raw_name
== NULL
19458 && (tag
== DW_TAG_class_type
19459 || tag
== DW_TAG_interface_type
19460 || tag
== DW_TAG_structure_type
19461 || tag
== DW_TAG_union_type
)
19462 && linkage_name
!= NULL
)
19464 gdb::unique_xmalloc_ptr
<char> demangled
19465 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19466 if (demangled
!= nullptr)
19470 /* Strip any leading namespaces/classes, keep only the base name.
19471 DW_AT_name for named DIEs does not contain the prefixes. */
19472 base
= strrchr (demangled
.get (), ':');
19473 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19476 base
= demangled
.get ();
19478 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19479 raw_name
= objfile
->intern (base
);
19480 canonical_name
= 1;
19487 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19488 contents from the given SECTION in the HEADER. */
19490 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19491 struct dwarf2_section_info
*section
)
19493 unsigned int bytes_read
;
19494 bfd
*abfd
= section
->get_bfd_owner ();
19495 const gdb_byte
*info_ptr
= section
->buffer
;
19496 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19497 info_ptr
+= bytes_read
;
19498 header
->version
= read_2_bytes (abfd
, info_ptr
);
19500 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19502 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19504 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19507 /* Return the DW_AT_loclists_base value for the CU. */
19509 lookup_loclist_base (struct dwarf2_cu
*cu
)
19511 /* For the .dwo unit, the loclist_base points to the first offset following
19512 the header. The header consists of the following entities-
19513 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19515 2. version (2 bytes)
19516 3. address size (1 byte)
19517 4. segment selector size (1 byte)
19518 5. offset entry count (4 bytes)
19519 These sizes are derived as per the DWARFv5 standard. */
19520 if (cu
->dwo_unit
!= nullptr)
19522 if (cu
->header
.initial_length_size
== 4)
19523 return LOCLIST_HEADER_SIZE32
;
19524 return LOCLIST_HEADER_SIZE64
;
19526 return cu
->loclist_base
;
19529 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19530 array of offsets in the .debug_loclists section. */
19532 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19534 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19535 struct objfile
*objfile
= per_objfile
->objfile
;
19536 bfd
*abfd
= objfile
->obfd
;
19537 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19538 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19540 section
->read (objfile
);
19541 if (section
->buffer
== NULL
)
19542 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19543 "section [in module %s]"), objfile_name (objfile
));
19544 struct loclists_rnglists_header header
;
19545 read_loclists_rnglists_header (&header
, section
);
19546 if (loclist_index
>= header
.offset_entry_count
)
19547 complaint (_("DW_FORM_loclistx pointing outside of "
19548 ".debug_loclists offset array [in module %s]"),
19549 objfile_name (objfile
));
19550 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19552 complaint (_("DW_FORM_loclistx pointing outside of "
19553 ".debug_loclists section [in module %s]"),
19554 objfile_name (objfile
));
19555 const gdb_byte
*info_ptr
19556 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19558 if (cu
->header
.offset_size
== 4)
19559 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19561 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19564 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19565 array of offsets in the .debug_rnglists section. */
19567 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19570 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19571 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19572 bfd
*abfd
= objfile
->obfd
;
19573 ULONGEST rnglist_header_size
=
19574 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19575 : RNGLIST_HEADER_SIZE64
);
19576 ULONGEST rnglist_base
=
19577 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->ranges_base
;
19578 ULONGEST start_offset
=
19579 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19581 /* Get rnglists section. */
19582 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19584 /* Read the rnglists section content. */
19585 section
->read (objfile
);
19586 if (section
->buffer
== nullptr)
19587 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19589 objfile_name (objfile
));
19591 /* Verify the rnglist index is valid. */
19592 struct loclists_rnglists_header header
;
19593 read_loclists_rnglists_header (&header
, section
);
19594 if (rnglist_index
>= header
.offset_entry_count
)
19595 error (_("DW_FORM_rnglistx index pointing outside of "
19596 ".debug_rnglists offset array [in module %s]"),
19597 objfile_name (objfile
));
19599 /* Validate that the offset is within the section's range. */
19600 if (start_offset
>= section
->size
)
19601 error (_("DW_FORM_rnglistx pointing outside of "
19602 ".debug_rnglists section [in module %s]"),
19603 objfile_name (objfile
));
19605 /* Validate that reading won't go beyond the end of the section. */
19606 if (start_offset
+ cu
->header
.offset_size
> rnglist_base
+ section
->size
)
19607 error (_("Reading DW_FORM_rnglistx index beyond end of"
19608 ".debug_rnglists section [in module %s]"),
19609 objfile_name (objfile
));
19611 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19613 if (cu
->header
.offset_size
== 4)
19614 return read_4_bytes (abfd
, info_ptr
) + rnglist_base
;
19616 return read_8_bytes (abfd
, info_ptr
) + rnglist_base
;
19619 /* Process the attributes that had to be skipped in the first round. These
19620 attributes are the ones that need str_offsets_base or addr_base attributes.
19621 They could not have been processed in the first round, because at the time
19622 the values of str_offsets_base or addr_base may not have been known. */
19624 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19625 struct attribute
*attr
, dwarf_tag tag
)
19627 struct dwarf2_cu
*cu
= reader
->cu
;
19628 switch (attr
->form
)
19630 case DW_FORM_addrx
:
19631 case DW_FORM_GNU_addr_index
:
19632 attr
->set_address (read_addr_index (cu
,
19633 attr
->as_unsigned_reprocess ()));
19635 case DW_FORM_loclistx
:
19636 attr
->set_address (read_loclist_index (cu
, attr
->as_unsigned ()));
19638 case DW_FORM_rnglistx
:
19639 attr
->set_address (read_rnglist_index (cu
, attr
->as_unsigned (), tag
));
19642 case DW_FORM_strx1
:
19643 case DW_FORM_strx2
:
19644 case DW_FORM_strx3
:
19645 case DW_FORM_strx4
:
19646 case DW_FORM_GNU_str_index
:
19648 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19649 gdb_assert (!attr
->canonical_string_p ());
19650 if (reader
->dwo_file
!= NULL
)
19651 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19654 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19659 gdb_assert_not_reached (_("Unexpected DWARF form."));
19663 /* Read an attribute value described by an attribute form. */
19665 static const gdb_byte
*
19666 read_attribute_value (const struct die_reader_specs
*reader
,
19667 struct attribute
*attr
, unsigned form
,
19668 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19670 struct dwarf2_cu
*cu
= reader
->cu
;
19671 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19672 struct objfile
*objfile
= per_objfile
->objfile
;
19673 bfd
*abfd
= reader
->abfd
;
19674 struct comp_unit_head
*cu_header
= &cu
->header
;
19675 unsigned int bytes_read
;
19676 struct dwarf_block
*blk
;
19678 attr
->form
= (enum dwarf_form
) form
;
19681 case DW_FORM_ref_addr
:
19682 if (cu
->header
.version
== 2)
19683 attr
->set_unsigned (cu
->header
.read_address (abfd
, info_ptr
,
19686 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
19688 info_ptr
+= bytes_read
;
19690 case DW_FORM_GNU_ref_alt
:
19691 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
19693 info_ptr
+= bytes_read
;
19697 struct gdbarch
*gdbarch
= objfile
->arch ();
19698 CORE_ADDR addr
= cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19699 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
19700 attr
->set_address (addr
);
19701 info_ptr
+= bytes_read
;
19704 case DW_FORM_block2
:
19705 blk
= dwarf_alloc_block (cu
);
19706 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19708 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19709 info_ptr
+= blk
->size
;
19710 attr
->set_block (blk
);
19712 case DW_FORM_block4
:
19713 blk
= dwarf_alloc_block (cu
);
19714 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19716 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19717 info_ptr
+= blk
->size
;
19718 attr
->set_block (blk
);
19720 case DW_FORM_data2
:
19721 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
19724 case DW_FORM_data4
:
19725 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
19728 case DW_FORM_data8
:
19729 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
19732 case DW_FORM_data16
:
19733 blk
= dwarf_alloc_block (cu
);
19735 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19737 attr
->set_block (blk
);
19739 case DW_FORM_sec_offset
:
19740 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
19742 info_ptr
+= bytes_read
;
19744 case DW_FORM_loclistx
:
19746 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19748 info_ptr
+= bytes_read
;
19751 case DW_FORM_string
:
19752 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
19754 info_ptr
+= bytes_read
;
19757 if (!cu
->per_cu
->is_dwz
)
19759 attr
->set_string_noncanonical
19760 (read_indirect_string (per_objfile
,
19761 abfd
, info_ptr
, cu_header
,
19763 info_ptr
+= bytes_read
;
19767 case DW_FORM_line_strp
:
19768 if (!cu
->per_cu
->is_dwz
)
19770 attr
->set_string_noncanonical
19771 (per_objfile
->read_line_string (info_ptr
, cu_header
,
19773 info_ptr
+= bytes_read
;
19777 case DW_FORM_GNU_strp_alt
:
19779 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19780 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19783 attr
->set_string_noncanonical
19784 (dwz
->read_string (objfile
, str_offset
));
19785 info_ptr
+= bytes_read
;
19788 case DW_FORM_exprloc
:
19789 case DW_FORM_block
:
19790 blk
= dwarf_alloc_block (cu
);
19791 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19792 info_ptr
+= bytes_read
;
19793 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19794 info_ptr
+= blk
->size
;
19795 attr
->set_block (blk
);
19797 case DW_FORM_block1
:
19798 blk
= dwarf_alloc_block (cu
);
19799 blk
->size
= read_1_byte (abfd
, info_ptr
);
19801 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19802 info_ptr
+= blk
->size
;
19803 attr
->set_block (blk
);
19805 case DW_FORM_data1
:
19807 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
19810 case DW_FORM_flag_present
:
19811 attr
->set_unsigned (1);
19813 case DW_FORM_sdata
:
19814 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
19815 info_ptr
+= bytes_read
;
19817 case DW_FORM_rnglistx
:
19819 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19821 info_ptr
+= bytes_read
;
19824 case DW_FORM_udata
:
19825 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19826 info_ptr
+= bytes_read
;
19829 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
19830 + read_1_byte (abfd
, info_ptr
)));
19834 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
19835 + read_2_bytes (abfd
, info_ptr
)));
19839 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
19840 + read_4_bytes (abfd
, info_ptr
)));
19844 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
19845 + read_8_bytes (abfd
, info_ptr
)));
19848 case DW_FORM_ref_sig8
:
19849 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
19852 case DW_FORM_ref_udata
:
19853 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
19854 + read_unsigned_leb128 (abfd
, info_ptr
,
19856 info_ptr
+= bytes_read
;
19858 case DW_FORM_indirect
:
19859 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19860 info_ptr
+= bytes_read
;
19861 if (form
== DW_FORM_implicit_const
)
19863 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19864 info_ptr
+= bytes_read
;
19866 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19869 case DW_FORM_implicit_const
:
19870 attr
->set_signed (implicit_const
);
19872 case DW_FORM_addrx
:
19873 case DW_FORM_GNU_addr_index
:
19874 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19876 info_ptr
+= bytes_read
;
19879 case DW_FORM_strx1
:
19880 case DW_FORM_strx2
:
19881 case DW_FORM_strx3
:
19882 case DW_FORM_strx4
:
19883 case DW_FORM_GNU_str_index
:
19885 ULONGEST str_index
;
19886 if (form
== DW_FORM_strx1
)
19888 str_index
= read_1_byte (abfd
, info_ptr
);
19891 else if (form
== DW_FORM_strx2
)
19893 str_index
= read_2_bytes (abfd
, info_ptr
);
19896 else if (form
== DW_FORM_strx3
)
19898 str_index
= read_3_bytes (abfd
, info_ptr
);
19901 else if (form
== DW_FORM_strx4
)
19903 str_index
= read_4_bytes (abfd
, info_ptr
);
19908 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19909 info_ptr
+= bytes_read
;
19911 attr
->set_unsigned_reprocess (str_index
);
19915 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19916 dwarf_form_name (form
),
19917 bfd_get_filename (abfd
));
19921 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19922 attr
->form
= DW_FORM_GNU_ref_alt
;
19924 /* We have seen instances where the compiler tried to emit a byte
19925 size attribute of -1 which ended up being encoded as an unsigned
19926 0xffffffff. Although 0xffffffff is technically a valid size value,
19927 an object of this size seems pretty unlikely so we can relatively
19928 safely treat these cases as if the size attribute was invalid and
19929 treat them as zero by default. */
19930 if (attr
->name
== DW_AT_byte_size
19931 && form
== DW_FORM_data4
19932 && attr
->as_unsigned () >= 0xffffffff)
19935 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19936 hex_string (attr
->as_unsigned ()));
19937 attr
->set_unsigned (0);
19943 /* Read an attribute described by an abbreviated attribute. */
19945 static const gdb_byte
*
19946 read_attribute (const struct die_reader_specs
*reader
,
19947 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19948 const gdb_byte
*info_ptr
)
19950 attr
->name
= abbrev
->name
;
19951 attr
->string_is_canonical
= 0;
19952 attr
->requires_reprocessing
= 0;
19953 return read_attribute_value (reader
, attr
, abbrev
->form
,
19954 abbrev
->implicit_const
, info_ptr
);
19957 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19959 static const char *
19960 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
19961 LONGEST str_offset
)
19963 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
19964 str_offset
, "DW_FORM_strp");
19967 /* Return pointer to string at .debug_str offset as read from BUF.
19968 BUF is assumed to be in a compilation unit described by CU_HEADER.
19969 Return *BYTES_READ_PTR count of bytes read from BUF. */
19971 static const char *
19972 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
19973 const gdb_byte
*buf
,
19974 const struct comp_unit_head
*cu_header
,
19975 unsigned int *bytes_read_ptr
)
19977 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19979 return read_indirect_string_at_offset (per_objfile
, str_offset
);
19985 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19986 const struct comp_unit_head
*cu_header
,
19987 unsigned int *bytes_read_ptr
)
19989 bfd
*abfd
= objfile
->obfd
;
19990 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19992 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19995 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19996 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19997 ADDR_SIZE is the size of addresses from the CU header. */
20000 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20001 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20003 struct objfile
*objfile
= per_objfile
->objfile
;
20004 bfd
*abfd
= objfile
->obfd
;
20005 const gdb_byte
*info_ptr
;
20006 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20008 per_objfile
->per_bfd
->addr
.read (objfile
);
20009 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20010 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20011 objfile_name (objfile
));
20012 if (addr_base_or_zero
+ addr_index
* addr_size
20013 >= per_objfile
->per_bfd
->addr
.size
)
20014 error (_("DW_FORM_addr_index pointing outside of "
20015 ".debug_addr section [in module %s]"),
20016 objfile_name (objfile
));
20017 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20018 + addr_index
* addr_size
);
20019 if (addr_size
== 4)
20020 return bfd_get_32 (abfd
, info_ptr
);
20022 return bfd_get_64 (abfd
, info_ptr
);
20025 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20028 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20030 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20031 cu
->addr_base
, cu
->header
.addr_size
);
20034 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20037 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20038 unsigned int *bytes_read
)
20040 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20041 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20043 return read_addr_index (cu
, addr_index
);
20049 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20050 dwarf2_per_objfile
*per_objfile
,
20051 unsigned int addr_index
)
20053 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20054 gdb::optional
<ULONGEST
> addr_base
;
20057 /* We need addr_base and addr_size.
20058 If we don't have PER_CU->cu, we have to get it.
20059 Nasty, but the alternative is storing the needed info in PER_CU,
20060 which at this point doesn't seem justified: it's not clear how frequently
20061 it would get used and it would increase the size of every PER_CU.
20062 Entry points like dwarf2_per_cu_addr_size do a similar thing
20063 so we're not in uncharted territory here.
20064 Alas we need to be a bit more complicated as addr_base is contained
20067 We don't need to read the entire CU(/TU).
20068 We just need the header and top level die.
20070 IWBN to use the aging mechanism to let us lazily later discard the CU.
20071 For now we skip this optimization. */
20075 addr_base
= cu
->addr_base
;
20076 addr_size
= cu
->header
.addr_size
;
20080 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20081 addr_base
= reader
.cu
->addr_base
;
20082 addr_size
= reader
.cu
->header
.addr_size
;
20085 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20088 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20089 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20092 static const char *
20093 read_str_index (struct dwarf2_cu
*cu
,
20094 struct dwarf2_section_info
*str_section
,
20095 struct dwarf2_section_info
*str_offsets_section
,
20096 ULONGEST str_offsets_base
, ULONGEST str_index
)
20098 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20099 struct objfile
*objfile
= per_objfile
->objfile
;
20100 const char *objf_name
= objfile_name (objfile
);
20101 bfd
*abfd
= objfile
->obfd
;
20102 const gdb_byte
*info_ptr
;
20103 ULONGEST str_offset
;
20104 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20106 str_section
->read (objfile
);
20107 str_offsets_section
->read (objfile
);
20108 if (str_section
->buffer
== NULL
)
20109 error (_("%s used without %s section"
20110 " in CU at offset %s [in module %s]"),
20111 form_name
, str_section
->get_name (),
20112 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20113 if (str_offsets_section
->buffer
== NULL
)
20114 error (_("%s used without %s section"
20115 " in CU at offset %s [in module %s]"),
20116 form_name
, str_section
->get_name (),
20117 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20118 info_ptr
= (str_offsets_section
->buffer
20120 + str_index
* cu
->header
.offset_size
);
20121 if (cu
->header
.offset_size
== 4)
20122 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20124 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20125 if (str_offset
>= str_section
->size
)
20126 error (_("Offset from %s pointing outside of"
20127 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20128 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20129 return (const char *) (str_section
->buffer
+ str_offset
);
20132 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20134 static const char *
20135 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20137 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20138 ? reader
->cu
->header
.addr_size
: 0;
20139 return read_str_index (reader
->cu
,
20140 &reader
->dwo_file
->sections
.str
,
20141 &reader
->dwo_file
->sections
.str_offsets
,
20142 str_offsets_base
, str_index
);
20145 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20147 static const char *
20148 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20150 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20151 const char *objf_name
= objfile_name (objfile
);
20152 static const char form_name
[] = "DW_FORM_GNU_str_index";
20153 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20155 if (!cu
->str_offsets_base
.has_value ())
20156 error (_("%s used in Fission stub without %s"
20157 " in CU at offset 0x%lx [in module %s]"),
20158 form_name
, str_offsets_attr_name
,
20159 (long) cu
->header
.offset_size
, objf_name
);
20161 return read_str_index (cu
,
20162 &cu
->per_objfile
->per_bfd
->str
,
20163 &cu
->per_objfile
->per_bfd
->str_offsets
,
20164 *cu
->str_offsets_base
, str_index
);
20167 /* Return the length of an LEB128 number in BUF. */
20170 leb128_size (const gdb_byte
*buf
)
20172 const gdb_byte
*begin
= buf
;
20178 if ((byte
& 128) == 0)
20179 return buf
- begin
;
20184 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20193 cu
->language
= language_c
;
20196 case DW_LANG_C_plus_plus
:
20197 case DW_LANG_C_plus_plus_11
:
20198 case DW_LANG_C_plus_plus_14
:
20199 cu
->language
= language_cplus
;
20202 cu
->language
= language_d
;
20204 case DW_LANG_Fortran77
:
20205 case DW_LANG_Fortran90
:
20206 case DW_LANG_Fortran95
:
20207 case DW_LANG_Fortran03
:
20208 case DW_LANG_Fortran08
:
20209 cu
->language
= language_fortran
;
20212 cu
->language
= language_go
;
20214 case DW_LANG_Mips_Assembler
:
20215 cu
->language
= language_asm
;
20217 case DW_LANG_Ada83
:
20218 case DW_LANG_Ada95
:
20219 cu
->language
= language_ada
;
20221 case DW_LANG_Modula2
:
20222 cu
->language
= language_m2
;
20224 case DW_LANG_Pascal83
:
20225 cu
->language
= language_pascal
;
20228 cu
->language
= language_objc
;
20231 case DW_LANG_Rust_old
:
20232 cu
->language
= language_rust
;
20234 case DW_LANG_Cobol74
:
20235 case DW_LANG_Cobol85
:
20237 cu
->language
= language_minimal
;
20240 cu
->language_defn
= language_def (cu
->language
);
20243 /* Return the named attribute or NULL if not there. */
20245 static struct attribute
*
20246 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20251 struct attribute
*spec
= NULL
;
20253 for (i
= 0; i
< die
->num_attrs
; ++i
)
20255 if (die
->attrs
[i
].name
== name
)
20256 return &die
->attrs
[i
];
20257 if (die
->attrs
[i
].name
== DW_AT_specification
20258 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20259 spec
= &die
->attrs
[i
];
20265 die
= follow_die_ref (die
, spec
, &cu
);
20271 /* Return the string associated with a string-typed attribute, or NULL if it
20272 is either not found or is of an incorrect type. */
20274 static const char *
20275 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20277 struct attribute
*attr
;
20278 const char *str
= NULL
;
20280 attr
= dwarf2_attr (die
, name
, cu
);
20284 str
= attr
->as_string ();
20285 if (str
== nullptr)
20286 complaint (_("string type expected for attribute %s for "
20287 "DIE at %s in module %s"),
20288 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20289 objfile_name (cu
->per_objfile
->objfile
));
20295 /* Return the dwo name or NULL if not present. If present, it is in either
20296 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20297 static const char *
20298 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20300 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20301 if (dwo_name
== nullptr)
20302 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20306 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20307 and holds a non-zero value. This function should only be used for
20308 DW_FORM_flag or DW_FORM_flag_present attributes. */
20311 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20313 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20315 return attr
!= nullptr && attr
->as_boolean ();
20319 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20321 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20322 which value is non-zero. However, we have to be careful with
20323 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20324 (via dwarf2_flag_true_p) follows this attribute. So we may
20325 end up accidently finding a declaration attribute that belongs
20326 to a different DIE referenced by the specification attribute,
20327 even though the given DIE does not have a declaration attribute. */
20328 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20329 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20332 /* Return the die giving the specification for DIE, if there is
20333 one. *SPEC_CU is the CU containing DIE on input, and the CU
20334 containing the return value on output. If there is no
20335 specification, but there is an abstract origin, that is
20338 static struct die_info
*
20339 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20341 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20344 if (spec_attr
== NULL
)
20345 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20347 if (spec_attr
== NULL
)
20350 return follow_die_ref (die
, spec_attr
, spec_cu
);
20353 /* Stub for free_line_header to match void * callback types. */
20356 free_line_header_voidp (void *arg
)
20358 struct line_header
*lh
= (struct line_header
*) arg
;
20363 /* A convenience function to find the proper .debug_line section for a CU. */
20365 static struct dwarf2_section_info
*
20366 get_debug_line_section (struct dwarf2_cu
*cu
)
20368 struct dwarf2_section_info
*section
;
20369 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20371 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20373 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20374 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20375 else if (cu
->per_cu
->is_dwz
)
20377 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
20379 section
= &dwz
->line
;
20382 section
= &per_objfile
->per_bfd
->line
;
20387 /* Read the statement program header starting at OFFSET in
20388 .debug_line, or .debug_line.dwo. Return a pointer
20389 to a struct line_header, allocated using xmalloc.
20390 Returns NULL if there is a problem reading the header, e.g., if it
20391 has a version we don't understand.
20393 NOTE: the strings in the include directory and file name tables of
20394 the returned object point into the dwarf line section buffer,
20395 and must not be freed. */
20397 static line_header_up
20398 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20400 struct dwarf2_section_info
*section
;
20401 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20403 section
= get_debug_line_section (cu
);
20404 section
->read (per_objfile
->objfile
);
20405 if (section
->buffer
== NULL
)
20407 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20408 complaint (_("missing .debug_line.dwo section"));
20410 complaint (_("missing .debug_line section"));
20414 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20415 per_objfile
, section
, &cu
->header
);
20418 /* Subroutine of dwarf_decode_lines to simplify it.
20419 Return the file name of the psymtab for the given file_entry.
20420 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20421 If space for the result is malloc'd, *NAME_HOLDER will be set.
20422 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20424 static const char *
20425 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20426 const dwarf2_psymtab
*pst
,
20427 const char *comp_dir
,
20428 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20430 const char *include_name
= fe
.name
;
20431 const char *include_name_to_compare
= include_name
;
20432 const char *pst_filename
;
20435 const char *dir_name
= fe
.include_dir (lh
);
20437 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20438 if (!IS_ABSOLUTE_PATH (include_name
)
20439 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20441 /* Avoid creating a duplicate psymtab for PST.
20442 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20443 Before we do the comparison, however, we need to account
20444 for DIR_NAME and COMP_DIR.
20445 First prepend dir_name (if non-NULL). If we still don't
20446 have an absolute path prepend comp_dir (if non-NULL).
20447 However, the directory we record in the include-file's
20448 psymtab does not contain COMP_DIR (to match the
20449 corresponding symtab(s)).
20454 bash$ gcc -g ./hello.c
20455 include_name = "hello.c"
20457 DW_AT_comp_dir = comp_dir = "/tmp"
20458 DW_AT_name = "./hello.c"
20462 if (dir_name
!= NULL
)
20464 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20465 include_name
, (char *) NULL
));
20466 include_name
= name_holder
->get ();
20467 include_name_to_compare
= include_name
;
20469 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20471 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20472 include_name
, (char *) NULL
));
20473 include_name_to_compare
= hold_compare
.get ();
20477 pst_filename
= pst
->filename
;
20478 gdb::unique_xmalloc_ptr
<char> copied_name
;
20479 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20481 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20482 pst_filename
, (char *) NULL
));
20483 pst_filename
= copied_name
.get ();
20486 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20490 return include_name
;
20493 /* State machine to track the state of the line number program. */
20495 class lnp_state_machine
20498 /* Initialize a machine state for the start of a line number
20500 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20501 bool record_lines_p
);
20503 file_entry
*current_file ()
20505 /* lh->file_names is 0-based, but the file name numbers in the
20506 statement program are 1-based. */
20507 return m_line_header
->file_name_at (m_file
);
20510 /* Record the line in the state machine. END_SEQUENCE is true if
20511 we're processing the end of a sequence. */
20512 void record_line (bool end_sequence
);
20514 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20515 nop-out rest of the lines in this sequence. */
20516 void check_line_address (struct dwarf2_cu
*cu
,
20517 const gdb_byte
*line_ptr
,
20518 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20520 void handle_set_discriminator (unsigned int discriminator
)
20522 m_discriminator
= discriminator
;
20523 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20526 /* Handle DW_LNE_set_address. */
20527 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20530 address
+= baseaddr
;
20531 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20534 /* Handle DW_LNS_advance_pc. */
20535 void handle_advance_pc (CORE_ADDR adjust
);
20537 /* Handle a special opcode. */
20538 void handle_special_opcode (unsigned char op_code
);
20540 /* Handle DW_LNS_advance_line. */
20541 void handle_advance_line (int line_delta
)
20543 advance_line (line_delta
);
20546 /* Handle DW_LNS_set_file. */
20547 void handle_set_file (file_name_index file
);
20549 /* Handle DW_LNS_negate_stmt. */
20550 void handle_negate_stmt ()
20552 m_is_stmt
= !m_is_stmt
;
20555 /* Handle DW_LNS_const_add_pc. */
20556 void handle_const_add_pc ();
20558 /* Handle DW_LNS_fixed_advance_pc. */
20559 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20561 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20565 /* Handle DW_LNS_copy. */
20566 void handle_copy ()
20568 record_line (false);
20569 m_discriminator
= 0;
20572 /* Handle DW_LNE_end_sequence. */
20573 void handle_end_sequence ()
20575 m_currently_recording_lines
= true;
20579 /* Advance the line by LINE_DELTA. */
20580 void advance_line (int line_delta
)
20582 m_line
+= line_delta
;
20584 if (line_delta
!= 0)
20585 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20588 struct dwarf2_cu
*m_cu
;
20590 gdbarch
*m_gdbarch
;
20592 /* True if we're recording lines.
20593 Otherwise we're building partial symtabs and are just interested in
20594 finding include files mentioned by the line number program. */
20595 bool m_record_lines_p
;
20597 /* The line number header. */
20598 line_header
*m_line_header
;
20600 /* These are part of the standard DWARF line number state machine,
20601 and initialized according to the DWARF spec. */
20603 unsigned char m_op_index
= 0;
20604 /* The line table index of the current file. */
20605 file_name_index m_file
= 1;
20606 unsigned int m_line
= 1;
20608 /* These are initialized in the constructor. */
20610 CORE_ADDR m_address
;
20612 unsigned int m_discriminator
;
20614 /* Additional bits of state we need to track. */
20616 /* The last file that we called dwarf2_start_subfile for.
20617 This is only used for TLLs. */
20618 unsigned int m_last_file
= 0;
20619 /* The last file a line number was recorded for. */
20620 struct subfile
*m_last_subfile
= NULL
;
20622 /* The address of the last line entry. */
20623 CORE_ADDR m_last_address
;
20625 /* Set to true when a previous line at the same address (using
20626 m_last_address) had m_is_stmt true. This is reset to false when a
20627 line entry at a new address (m_address different to m_last_address) is
20629 bool m_stmt_at_address
= false;
20631 /* When true, record the lines we decode. */
20632 bool m_currently_recording_lines
= false;
20634 /* The last line number that was recorded, used to coalesce
20635 consecutive entries for the same line. This can happen, for
20636 example, when discriminators are present. PR 17276. */
20637 unsigned int m_last_line
= 0;
20638 bool m_line_has_non_zero_discriminator
= false;
20642 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20644 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20645 / m_line_header
->maximum_ops_per_instruction
)
20646 * m_line_header
->minimum_instruction_length
);
20647 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20648 m_op_index
= ((m_op_index
+ adjust
)
20649 % m_line_header
->maximum_ops_per_instruction
);
20653 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20655 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20656 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20657 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20658 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20659 / m_line_header
->maximum_ops_per_instruction
)
20660 * m_line_header
->minimum_instruction_length
);
20661 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20662 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20663 % m_line_header
->maximum_ops_per_instruction
);
20665 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20666 advance_line (line_delta
);
20667 record_line (false);
20668 m_discriminator
= 0;
20672 lnp_state_machine::handle_set_file (file_name_index file
)
20676 const file_entry
*fe
= current_file ();
20678 dwarf2_debug_line_missing_file_complaint ();
20679 else if (m_record_lines_p
)
20681 const char *dir
= fe
->include_dir (m_line_header
);
20683 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20684 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20685 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20690 lnp_state_machine::handle_const_add_pc ()
20693 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20696 = (((m_op_index
+ adjust
)
20697 / m_line_header
->maximum_ops_per_instruction
)
20698 * m_line_header
->minimum_instruction_length
);
20700 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20701 m_op_index
= ((m_op_index
+ adjust
)
20702 % m_line_header
->maximum_ops_per_instruction
);
20705 /* Return non-zero if we should add LINE to the line number table.
20706 LINE is the line to add, LAST_LINE is the last line that was added,
20707 LAST_SUBFILE is the subfile for LAST_LINE.
20708 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20709 had a non-zero discriminator.
20711 We have to be careful in the presence of discriminators.
20712 E.g., for this line:
20714 for (i = 0; i < 100000; i++);
20716 clang can emit four line number entries for that one line,
20717 each with a different discriminator.
20718 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20720 However, we want gdb to coalesce all four entries into one.
20721 Otherwise the user could stepi into the middle of the line and
20722 gdb would get confused about whether the pc really was in the
20723 middle of the line.
20725 Things are further complicated by the fact that two consecutive
20726 line number entries for the same line is a heuristic used by gcc
20727 to denote the end of the prologue. So we can't just discard duplicate
20728 entries, we have to be selective about it. The heuristic we use is
20729 that we only collapse consecutive entries for the same line if at least
20730 one of those entries has a non-zero discriminator. PR 17276.
20732 Note: Addresses in the line number state machine can never go backwards
20733 within one sequence, thus this coalescing is ok. */
20736 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20737 unsigned int line
, unsigned int last_line
,
20738 int line_has_non_zero_discriminator
,
20739 struct subfile
*last_subfile
)
20741 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20743 if (line
!= last_line
)
20745 /* Same line for the same file that we've seen already.
20746 As a last check, for pr 17276, only record the line if the line
20747 has never had a non-zero discriminator. */
20748 if (!line_has_non_zero_discriminator
)
20753 /* Use the CU's builder to record line number LINE beginning at
20754 address ADDRESS in the line table of subfile SUBFILE. */
20757 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20758 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20759 struct dwarf2_cu
*cu
)
20761 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20763 if (dwarf_line_debug
)
20765 fprintf_unfiltered (gdb_stdlog
,
20766 "Recording line %u, file %s, address %s\n",
20767 line
, lbasename (subfile
->name
),
20768 paddress (gdbarch
, address
));
20772 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20775 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20776 Mark the end of a set of line number records.
20777 The arguments are the same as for dwarf_record_line_1.
20778 If SUBFILE is NULL the request is ignored. */
20781 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20782 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20784 if (subfile
== NULL
)
20787 if (dwarf_line_debug
)
20789 fprintf_unfiltered (gdb_stdlog
,
20790 "Finishing current line, file %s, address %s\n",
20791 lbasename (subfile
->name
),
20792 paddress (gdbarch
, address
));
20795 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20799 lnp_state_machine::record_line (bool end_sequence
)
20801 if (dwarf_line_debug
)
20803 fprintf_unfiltered (gdb_stdlog
,
20804 "Processing actual line %u: file %u,"
20805 " address %s, is_stmt %u, discrim %u%s\n",
20807 paddress (m_gdbarch
, m_address
),
20808 m_is_stmt
, m_discriminator
,
20809 (end_sequence
? "\t(end sequence)" : ""));
20812 file_entry
*fe
= current_file ();
20815 dwarf2_debug_line_missing_file_complaint ();
20816 /* For now we ignore lines not starting on an instruction boundary.
20817 But not when processing end_sequence for compatibility with the
20818 previous version of the code. */
20819 else if (m_op_index
== 0 || end_sequence
)
20821 fe
->included_p
= 1;
20822 if (m_record_lines_p
)
20824 /* When we switch files we insert an end maker in the first file,
20825 switch to the second file and add a new line entry. The
20826 problem is that the end marker inserted in the first file will
20827 discard any previous line entries at the same address. If the
20828 line entries in the first file are marked as is-stmt, while
20829 the new line in the second file is non-stmt, then this means
20830 the end marker will discard is-stmt lines so we can have a
20831 non-stmt line. This means that there are less addresses at
20832 which the user can insert a breakpoint.
20834 To improve this we track the last address in m_last_address,
20835 and whether we have seen an is-stmt at this address. Then
20836 when switching files, if we have seen a stmt at the current
20837 address, and we are switching to create a non-stmt line, then
20838 discard the new line. */
20840 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
20841 bool ignore_this_line
20842 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
20843 && !m_is_stmt
&& m_stmt_at_address
)
20844 || (!end_sequence
&& m_line
== 0));
20846 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
20848 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20849 m_currently_recording_lines
? m_cu
: nullptr);
20852 if (!end_sequence
&& !ignore_this_line
)
20854 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20856 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20857 m_line_has_non_zero_discriminator
,
20860 buildsym_compunit
*builder
= m_cu
->get_builder ();
20861 dwarf_record_line_1 (m_gdbarch
,
20862 builder
->get_current_subfile (),
20863 m_line
, m_address
, is_stmt
,
20864 m_currently_recording_lines
? m_cu
: nullptr);
20866 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20867 m_last_line
= m_line
;
20872 /* Track whether we have seen any m_is_stmt true at m_address in case we
20873 have multiple line table entries all at m_address. */
20874 if (m_last_address
!= m_address
)
20876 m_stmt_at_address
= false;
20877 m_last_address
= m_address
;
20879 m_stmt_at_address
|= m_is_stmt
;
20882 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20883 line_header
*lh
, bool record_lines_p
)
20887 m_record_lines_p
= record_lines_p
;
20888 m_line_header
= lh
;
20890 m_currently_recording_lines
= true;
20892 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20893 was a line entry for it so that the backend has a chance to adjust it
20894 and also record it in case it needs it. This is currently used by MIPS
20895 code, cf. `mips_adjust_dwarf2_line'. */
20896 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20897 m_is_stmt
= lh
->default_is_stmt
;
20898 m_discriminator
= 0;
20900 m_last_address
= m_address
;
20901 m_stmt_at_address
= false;
20905 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20906 const gdb_byte
*line_ptr
,
20907 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20909 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
20910 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
20911 located at 0x0. In this case, additionally check that if
20912 ADDRESS < UNRELOCATED_LOWPC. */
20914 if ((address
== 0 && address
< unrelocated_lowpc
)
20915 || address
== (CORE_ADDR
) -1)
20917 /* This line table is for a function which has been
20918 GCd by the linker. Ignore it. PR gdb/12528 */
20920 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20921 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20923 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20924 line_offset
, objfile_name (objfile
));
20925 m_currently_recording_lines
= false;
20926 /* Note: m_currently_recording_lines is left as false until we see
20927 DW_LNE_end_sequence. */
20931 /* Subroutine of dwarf_decode_lines to simplify it.
20932 Process the line number information in LH.
20933 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20934 program in order to set included_p for every referenced header. */
20937 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20938 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20940 const gdb_byte
*line_ptr
, *extended_end
;
20941 const gdb_byte
*line_end
;
20942 unsigned int bytes_read
, extended_len
;
20943 unsigned char op_code
, extended_op
;
20944 CORE_ADDR baseaddr
;
20945 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20946 bfd
*abfd
= objfile
->obfd
;
20947 struct gdbarch
*gdbarch
= objfile
->arch ();
20948 /* True if we're recording line info (as opposed to building partial
20949 symtabs and just interested in finding include files mentioned by
20950 the line number program). */
20951 bool record_lines_p
= !decode_for_pst_p
;
20953 baseaddr
= objfile
->text_section_offset ();
20955 line_ptr
= lh
->statement_program_start
;
20956 line_end
= lh
->statement_program_end
;
20958 /* Read the statement sequences until there's nothing left. */
20959 while (line_ptr
< line_end
)
20961 /* The DWARF line number program state machine. Reset the state
20962 machine at the start of each sequence. */
20963 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20964 bool end_sequence
= false;
20966 if (record_lines_p
)
20968 /* Start a subfile for the current file of the state
20970 const file_entry
*fe
= state_machine
.current_file ();
20973 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20976 /* Decode the table. */
20977 while (line_ptr
< line_end
&& !end_sequence
)
20979 op_code
= read_1_byte (abfd
, line_ptr
);
20982 if (op_code
>= lh
->opcode_base
)
20984 /* Special opcode. */
20985 state_machine
.handle_special_opcode (op_code
);
20987 else switch (op_code
)
20989 case DW_LNS_extended_op
:
20990 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20992 line_ptr
+= bytes_read
;
20993 extended_end
= line_ptr
+ extended_len
;
20994 extended_op
= read_1_byte (abfd
, line_ptr
);
20996 if (DW_LNE_lo_user
<= extended_op
20997 && extended_op
<= DW_LNE_hi_user
)
20999 /* Vendor extension, ignore. */
21000 line_ptr
= extended_end
;
21003 switch (extended_op
)
21005 case DW_LNE_end_sequence
:
21006 state_machine
.handle_end_sequence ();
21007 end_sequence
= true;
21009 case DW_LNE_set_address
:
21012 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21013 line_ptr
+= bytes_read
;
21015 state_machine
.check_line_address (cu
, line_ptr
,
21016 lowpc
- baseaddr
, address
);
21017 state_machine
.handle_set_address (baseaddr
, address
);
21020 case DW_LNE_define_file
:
21022 const char *cur_file
;
21023 unsigned int mod_time
, length
;
21026 cur_file
= read_direct_string (abfd
, line_ptr
,
21028 line_ptr
+= bytes_read
;
21029 dindex
= (dir_index
)
21030 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21031 line_ptr
+= bytes_read
;
21033 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21034 line_ptr
+= bytes_read
;
21036 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21037 line_ptr
+= bytes_read
;
21038 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21041 case DW_LNE_set_discriminator
:
21043 /* The discriminator is not interesting to the
21044 debugger; just ignore it. We still need to
21045 check its value though:
21046 if there are consecutive entries for the same
21047 (non-prologue) line we want to coalesce them.
21050 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21051 line_ptr
+= bytes_read
;
21053 state_machine
.handle_set_discriminator (discr
);
21057 complaint (_("mangled .debug_line section"));
21060 /* Make sure that we parsed the extended op correctly. If e.g.
21061 we expected a different address size than the producer used,
21062 we may have read the wrong number of bytes. */
21063 if (line_ptr
!= extended_end
)
21065 complaint (_("mangled .debug_line section"));
21070 state_machine
.handle_copy ();
21072 case DW_LNS_advance_pc
:
21075 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21076 line_ptr
+= bytes_read
;
21078 state_machine
.handle_advance_pc (adjust
);
21081 case DW_LNS_advance_line
:
21084 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21085 line_ptr
+= bytes_read
;
21087 state_machine
.handle_advance_line (line_delta
);
21090 case DW_LNS_set_file
:
21092 file_name_index file
21093 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21095 line_ptr
+= bytes_read
;
21097 state_machine
.handle_set_file (file
);
21100 case DW_LNS_set_column
:
21101 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21102 line_ptr
+= bytes_read
;
21104 case DW_LNS_negate_stmt
:
21105 state_machine
.handle_negate_stmt ();
21107 case DW_LNS_set_basic_block
:
21109 /* Add to the address register of the state machine the
21110 address increment value corresponding to special opcode
21111 255. I.e., this value is scaled by the minimum
21112 instruction length since special opcode 255 would have
21113 scaled the increment. */
21114 case DW_LNS_const_add_pc
:
21115 state_machine
.handle_const_add_pc ();
21117 case DW_LNS_fixed_advance_pc
:
21119 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21122 state_machine
.handle_fixed_advance_pc (addr_adj
);
21127 /* Unknown standard opcode, ignore it. */
21130 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21132 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21133 line_ptr
+= bytes_read
;
21140 dwarf2_debug_line_missing_end_sequence_complaint ();
21142 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21143 in which case we still finish recording the last line). */
21144 state_machine
.record_line (true);
21148 /* Decode the Line Number Program (LNP) for the given line_header
21149 structure and CU. The actual information extracted and the type
21150 of structures created from the LNP depends on the value of PST.
21152 1. If PST is NULL, then this procedure uses the data from the program
21153 to create all necessary symbol tables, and their linetables.
21155 2. If PST is not NULL, this procedure reads the program to determine
21156 the list of files included by the unit represented by PST, and
21157 builds all the associated partial symbol tables.
21159 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21160 It is used for relative paths in the line table.
21161 NOTE: When processing partial symtabs (pst != NULL),
21162 comp_dir == pst->dirname.
21164 NOTE: It is important that psymtabs have the same file name (via strcmp)
21165 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21166 symtab we don't use it in the name of the psymtabs we create.
21167 E.g. expand_line_sal requires this when finding psymtabs to expand.
21168 A good testcase for this is mb-inline.exp.
21170 LOWPC is the lowest address in CU (or 0 if not known).
21172 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21173 for its PC<->lines mapping information. Otherwise only the filename
21174 table is read in. */
21177 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21178 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21179 CORE_ADDR lowpc
, int decode_mapping
)
21181 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21182 const int decode_for_pst_p
= (pst
!= NULL
);
21184 if (decode_mapping
)
21185 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21187 if (decode_for_pst_p
)
21189 /* Now that we're done scanning the Line Header Program, we can
21190 create the psymtab of each included file. */
21191 for (auto &file_entry
: lh
->file_names ())
21192 if (file_entry
.included_p
== 1)
21194 gdb::unique_xmalloc_ptr
<char> name_holder
;
21195 const char *include_name
=
21196 psymtab_include_file_name (lh
, file_entry
, pst
,
21197 comp_dir
, &name_holder
);
21198 if (include_name
!= NULL
)
21199 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21204 /* Make sure a symtab is created for every file, even files
21205 which contain only variables (i.e. no code with associated
21207 buildsym_compunit
*builder
= cu
->get_builder ();
21208 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21210 for (auto &fe
: lh
->file_names ())
21212 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21213 if (builder
->get_current_subfile ()->symtab
== NULL
)
21215 builder
->get_current_subfile ()->symtab
21216 = allocate_symtab (cust
,
21217 builder
->get_current_subfile ()->name
);
21219 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21224 /* Start a subfile for DWARF. FILENAME is the name of the file and
21225 DIRNAME the name of the source directory which contains FILENAME
21226 or NULL if not known.
21227 This routine tries to keep line numbers from identical absolute and
21228 relative file names in a common subfile.
21230 Using the `list' example from the GDB testsuite, which resides in
21231 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21232 of /srcdir/list0.c yields the following debugging information for list0.c:
21234 DW_AT_name: /srcdir/list0.c
21235 DW_AT_comp_dir: /compdir
21236 files.files[0].name: list0.h
21237 files.files[0].dir: /srcdir
21238 files.files[1].name: list0.c
21239 files.files[1].dir: /srcdir
21241 The line number information for list0.c has to end up in a single
21242 subfile, so that `break /srcdir/list0.c:1' works as expected.
21243 start_subfile will ensure that this happens provided that we pass the
21244 concatenation of files.files[1].dir and files.files[1].name as the
21248 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21249 const char *dirname
)
21251 gdb::unique_xmalloc_ptr
<char> copy
;
21253 /* In order not to lose the line information directory,
21254 we concatenate it to the filename when it makes sense.
21255 Note that the Dwarf3 standard says (speaking of filenames in line
21256 information): ``The directory index is ignored for file names
21257 that represent full path names''. Thus ignoring dirname in the
21258 `else' branch below isn't an issue. */
21260 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21262 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21263 filename
= copy
.get ();
21266 cu
->get_builder ()->start_subfile (filename
);
21269 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21270 buildsym_compunit constructor. */
21272 struct compunit_symtab
*
21273 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21276 gdb_assert (m_builder
== nullptr);
21278 m_builder
.reset (new struct buildsym_compunit
21279 (this->per_objfile
->objfile
,
21280 name
, comp_dir
, language
, low_pc
));
21282 list_in_scope
= get_builder ()->get_file_symbols ();
21284 get_builder ()->record_debugformat ("DWARF 2");
21285 get_builder ()->record_producer (producer
);
21287 processing_has_namespace_info
= false;
21289 return get_builder ()->get_compunit_symtab ();
21293 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21294 struct dwarf2_cu
*cu
)
21296 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21297 struct comp_unit_head
*cu_header
= &cu
->header
;
21299 /* NOTE drow/2003-01-30: There used to be a comment and some special
21300 code here to turn a symbol with DW_AT_external and a
21301 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21302 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21303 with some versions of binutils) where shared libraries could have
21304 relocations against symbols in their debug information - the
21305 minimal symbol would have the right address, but the debug info
21306 would not. It's no longer necessary, because we will explicitly
21307 apply relocations when we read in the debug information now. */
21309 /* A DW_AT_location attribute with no contents indicates that a
21310 variable has been optimized away. */
21311 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21313 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21317 /* Handle one degenerate form of location expression specially, to
21318 preserve GDB's previous behavior when section offsets are
21319 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21320 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21322 if (attr
->form_is_block ())
21324 struct dwarf_block
*block
= attr
->as_block ();
21326 if ((block
->data
[0] == DW_OP_addr
21327 && block
->size
== 1 + cu_header
->addr_size
)
21328 || ((block
->data
[0] == DW_OP_GNU_addr_index
21329 || block
->data
[0] == DW_OP_addrx
)
21331 == 1 + leb128_size (&block
->data
[1]))))
21333 unsigned int dummy
;
21335 if (block
->data
[0] == DW_OP_addr
)
21336 SET_SYMBOL_VALUE_ADDRESS
21337 (sym
, cu
->header
.read_address (objfile
->obfd
,
21341 SET_SYMBOL_VALUE_ADDRESS
21342 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21344 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21345 fixup_symbol_section (sym
, objfile
);
21346 SET_SYMBOL_VALUE_ADDRESS
21348 SYMBOL_VALUE_ADDRESS (sym
)
21349 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21354 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21355 expression evaluator, and use LOC_COMPUTED only when necessary
21356 (i.e. when the value of a register or memory location is
21357 referenced, or a thread-local block, etc.). Then again, it might
21358 not be worthwhile. I'm assuming that it isn't unless performance
21359 or memory numbers show me otherwise. */
21361 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21363 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21364 cu
->has_loclist
= true;
21367 /* Given a pointer to a DWARF information entry, figure out if we need
21368 to make a symbol table entry for it, and if so, create a new entry
21369 and return a pointer to it.
21370 If TYPE is NULL, determine symbol type from the die, otherwise
21371 used the passed type.
21372 If SPACE is not NULL, use it to hold the new symbol. If it is
21373 NULL, allocate a new symbol on the objfile's obstack. */
21375 static struct symbol
*
21376 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21377 struct symbol
*space
)
21379 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21380 struct objfile
*objfile
= per_objfile
->objfile
;
21381 struct gdbarch
*gdbarch
= objfile
->arch ();
21382 struct symbol
*sym
= NULL
;
21384 struct attribute
*attr
= NULL
;
21385 struct attribute
*attr2
= NULL
;
21386 CORE_ADDR baseaddr
;
21387 struct pending
**list_to_add
= NULL
;
21389 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21391 baseaddr
= objfile
->text_section_offset ();
21393 name
= dwarf2_name (die
, cu
);
21396 int suppress_add
= 0;
21401 sym
= new (&objfile
->objfile_obstack
) symbol
;
21402 OBJSTAT (objfile
, n_syms
++);
21404 /* Cache this symbol's name and the name's demangled form (if any). */
21405 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21406 /* Fortran does not have mangling standard and the mangling does differ
21407 between gfortran, iFort etc. */
21408 const char *physname
21409 = (cu
->language
== language_fortran
21410 ? dwarf2_full_name (name
, die
, cu
)
21411 : dwarf2_physname (name
, die
, cu
));
21412 const char *linkagename
= dw2_linkage_name (die
, cu
);
21414 if (linkagename
== nullptr || cu
->language
== language_ada
)
21415 sym
->set_linkage_name (physname
);
21418 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21419 sym
->set_linkage_name (linkagename
);
21422 /* Default assumptions.
21423 Use the passed type or decode it from the die. */
21424 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21425 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21427 SYMBOL_TYPE (sym
) = type
;
21429 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21430 attr
= dwarf2_attr (die
,
21431 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21433 if (attr
!= nullptr)
21434 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21436 attr
= dwarf2_attr (die
,
21437 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21439 if (attr
!= nullptr && attr
->form_is_unsigned ())
21441 file_name_index file_index
21442 = (file_name_index
) attr
->as_unsigned ();
21443 struct file_entry
*fe
;
21445 if (cu
->line_header
!= NULL
)
21446 fe
= cu
->line_header
->file_name_at (file_index
);
21451 complaint (_("file index out of range"));
21453 symbol_set_symtab (sym
, fe
->symtab
);
21459 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21460 if (attr
!= nullptr)
21464 addr
= attr
->as_address ();
21465 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21466 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21467 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21470 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21471 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21472 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21473 add_symbol_to_list (sym
, cu
->list_in_scope
);
21475 case DW_TAG_subprogram
:
21476 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21478 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21479 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21480 if ((attr2
!= nullptr && attr2
->as_boolean ())
21481 || cu
->language
== language_ada
21482 || cu
->language
== language_fortran
)
21484 /* Subprograms marked external are stored as a global symbol.
21485 Ada and Fortran subprograms, whether marked external or
21486 not, are always stored as a global symbol, because we want
21487 to be able to access them globally. For instance, we want
21488 to be able to break on a nested subprogram without having
21489 to specify the context. */
21490 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21494 list_to_add
= cu
->list_in_scope
;
21497 case DW_TAG_inlined_subroutine
:
21498 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21500 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21501 SYMBOL_INLINED (sym
) = 1;
21502 list_to_add
= cu
->list_in_scope
;
21504 case DW_TAG_template_value_param
:
21506 /* Fall through. */
21507 case DW_TAG_constant
:
21508 case DW_TAG_variable
:
21509 case DW_TAG_member
:
21510 /* Compilation with minimal debug info may result in
21511 variables with missing type entries. Change the
21512 misleading `void' type to something sensible. */
21513 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21514 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21516 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21517 /* In the case of DW_TAG_member, we should only be called for
21518 static const members. */
21519 if (die
->tag
== DW_TAG_member
)
21521 /* dwarf2_add_field uses die_is_declaration,
21522 so we do the same. */
21523 gdb_assert (die_is_declaration (die
, cu
));
21526 if (attr
!= nullptr)
21528 dwarf2_const_value (attr
, sym
, cu
);
21529 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21532 if (attr2
!= nullptr && attr2
->as_boolean ())
21533 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21535 list_to_add
= cu
->list_in_scope
;
21539 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21540 if (attr
!= nullptr)
21542 var_decode_location (attr
, sym
, cu
);
21543 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21545 /* Fortran explicitly imports any global symbols to the local
21546 scope by DW_TAG_common_block. */
21547 if (cu
->language
== language_fortran
&& die
->parent
21548 && die
->parent
->tag
== DW_TAG_common_block
)
21551 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21552 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21553 && !per_objfile
->per_bfd
->has_section_at_zero
)
21555 /* When a static variable is eliminated by the linker,
21556 the corresponding debug information is not stripped
21557 out, but the variable address is set to null;
21558 do not add such variables into symbol table. */
21560 else if (attr2
!= nullptr && attr2
->as_boolean ())
21562 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21563 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21564 && per_objfile
->per_bfd
->can_copy
)
21566 /* A global static variable might be subject to
21567 copy relocation. We first check for a local
21568 minsym, though, because maybe the symbol was
21569 marked hidden, in which case this would not
21571 bound_minimal_symbol found
21572 = (lookup_minimal_symbol_linkage
21573 (sym
->linkage_name (), objfile
));
21574 if (found
.minsym
!= nullptr)
21575 sym
->maybe_copied
= 1;
21578 /* A variable with DW_AT_external is never static,
21579 but it may be block-scoped. */
21581 = ((cu
->list_in_scope
21582 == cu
->get_builder ()->get_file_symbols ())
21583 ? cu
->get_builder ()->get_global_symbols ()
21584 : cu
->list_in_scope
);
21587 list_to_add
= cu
->list_in_scope
;
21591 /* We do not know the address of this symbol.
21592 If it is an external symbol and we have type information
21593 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21594 The address of the variable will then be determined from
21595 the minimal symbol table whenever the variable is
21597 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21599 /* Fortran explicitly imports any global symbols to the local
21600 scope by DW_TAG_common_block. */
21601 if (cu
->language
== language_fortran
&& die
->parent
21602 && die
->parent
->tag
== DW_TAG_common_block
)
21604 /* SYMBOL_CLASS doesn't matter here because
21605 read_common_block is going to reset it. */
21607 list_to_add
= cu
->list_in_scope
;
21609 else if (attr2
!= nullptr && attr2
->as_boolean ()
21610 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21612 /* A variable with DW_AT_external is never static, but it
21613 may be block-scoped. */
21615 = ((cu
->list_in_scope
21616 == cu
->get_builder ()->get_file_symbols ())
21617 ? cu
->get_builder ()->get_global_symbols ()
21618 : cu
->list_in_scope
);
21620 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21622 else if (!die_is_declaration (die
, cu
))
21624 /* Use the default LOC_OPTIMIZED_OUT class. */
21625 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21627 list_to_add
= cu
->list_in_scope
;
21631 case DW_TAG_formal_parameter
:
21633 /* If we are inside a function, mark this as an argument. If
21634 not, we might be looking at an argument to an inlined function
21635 when we do not have enough information to show inlined frames;
21636 pretend it's a local variable in that case so that the user can
21638 struct context_stack
*curr
21639 = cu
->get_builder ()->get_current_context_stack ();
21640 if (curr
!= nullptr && curr
->name
!= nullptr)
21641 SYMBOL_IS_ARGUMENT (sym
) = 1;
21642 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21643 if (attr
!= nullptr)
21645 var_decode_location (attr
, sym
, cu
);
21647 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21648 if (attr
!= nullptr)
21650 dwarf2_const_value (attr
, sym
, cu
);
21653 list_to_add
= cu
->list_in_scope
;
21656 case DW_TAG_unspecified_parameters
:
21657 /* From varargs functions; gdb doesn't seem to have any
21658 interest in this information, so just ignore it for now.
21661 case DW_TAG_template_type_param
:
21663 /* Fall through. */
21664 case DW_TAG_class_type
:
21665 case DW_TAG_interface_type
:
21666 case DW_TAG_structure_type
:
21667 case DW_TAG_union_type
:
21668 case DW_TAG_set_type
:
21669 case DW_TAG_enumeration_type
:
21670 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21671 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21674 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21675 really ever be static objects: otherwise, if you try
21676 to, say, break of a class's method and you're in a file
21677 which doesn't mention that class, it won't work unless
21678 the check for all static symbols in lookup_symbol_aux
21679 saves you. See the OtherFileClass tests in
21680 gdb.c++/namespace.exp. */
21684 buildsym_compunit
*builder
= cu
->get_builder ();
21686 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21687 && cu
->language
== language_cplus
21688 ? builder
->get_global_symbols ()
21689 : cu
->list_in_scope
);
21691 /* The semantics of C++ state that "struct foo {
21692 ... }" also defines a typedef for "foo". */
21693 if (cu
->language
== language_cplus
21694 || cu
->language
== language_ada
21695 || cu
->language
== language_d
21696 || cu
->language
== language_rust
)
21698 /* The symbol's name is already allocated along
21699 with this objfile, so we don't need to
21700 duplicate it for the type. */
21701 if (SYMBOL_TYPE (sym
)->name () == 0)
21702 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21707 case DW_TAG_typedef
:
21708 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21709 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21710 list_to_add
= cu
->list_in_scope
;
21712 case DW_TAG_base_type
:
21713 case DW_TAG_subrange_type
:
21714 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21715 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21716 list_to_add
= cu
->list_in_scope
;
21718 case DW_TAG_enumerator
:
21719 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21720 if (attr
!= nullptr)
21722 dwarf2_const_value (attr
, sym
, cu
);
21725 /* NOTE: carlton/2003-11-10: See comment above in the
21726 DW_TAG_class_type, etc. block. */
21729 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21730 && cu
->language
== language_cplus
21731 ? cu
->get_builder ()->get_global_symbols ()
21732 : cu
->list_in_scope
);
21735 case DW_TAG_imported_declaration
:
21736 case DW_TAG_namespace
:
21737 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21738 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21740 case DW_TAG_module
:
21741 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21742 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21743 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21745 case DW_TAG_common_block
:
21746 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21747 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21748 add_symbol_to_list (sym
, cu
->list_in_scope
);
21751 /* Not a tag we recognize. Hopefully we aren't processing
21752 trash data, but since we must specifically ignore things
21753 we don't recognize, there is nothing else we should do at
21755 complaint (_("unsupported tag: '%s'"),
21756 dwarf_tag_name (die
->tag
));
21762 sym
->hash_next
= objfile
->template_symbols
;
21763 objfile
->template_symbols
= sym
;
21764 list_to_add
= NULL
;
21767 if (list_to_add
!= NULL
)
21768 add_symbol_to_list (sym
, list_to_add
);
21770 /* For the benefit of old versions of GCC, check for anonymous
21771 namespaces based on the demangled name. */
21772 if (!cu
->processing_has_namespace_info
21773 && cu
->language
== language_cplus
)
21774 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21779 /* Given an attr with a DW_FORM_dataN value in host byte order,
21780 zero-extend it as appropriate for the symbol's type. The DWARF
21781 standard (v4) is not entirely clear about the meaning of using
21782 DW_FORM_dataN for a constant with a signed type, where the type is
21783 wider than the data. The conclusion of a discussion on the DWARF
21784 list was that this is unspecified. We choose to always zero-extend
21785 because that is the interpretation long in use by GCC. */
21788 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21789 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21791 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21792 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21793 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21794 LONGEST l
= attr
->constant_value (0);
21796 if (bits
< sizeof (*value
) * 8)
21798 l
&= ((LONGEST
) 1 << bits
) - 1;
21801 else if (bits
== sizeof (*value
) * 8)
21805 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21806 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21813 /* Read a constant value from an attribute. Either set *VALUE, or if
21814 the value does not fit in *VALUE, set *BYTES - either already
21815 allocated on the objfile obstack, or newly allocated on OBSTACK,
21816 or, set *BATON, if we translated the constant to a location
21820 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21821 const char *name
, struct obstack
*obstack
,
21822 struct dwarf2_cu
*cu
,
21823 LONGEST
*value
, const gdb_byte
**bytes
,
21824 struct dwarf2_locexpr_baton
**baton
)
21826 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21827 struct objfile
*objfile
= per_objfile
->objfile
;
21828 struct comp_unit_head
*cu_header
= &cu
->header
;
21829 struct dwarf_block
*blk
;
21830 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21831 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21837 switch (attr
->form
)
21840 case DW_FORM_addrx
:
21841 case DW_FORM_GNU_addr_index
:
21845 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21846 dwarf2_const_value_length_mismatch_complaint (name
,
21847 cu_header
->addr_size
,
21848 TYPE_LENGTH (type
));
21849 /* Symbols of this form are reasonably rare, so we just
21850 piggyback on the existing location code rather than writing
21851 a new implementation of symbol_computed_ops. */
21852 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21853 (*baton
)->per_objfile
= per_objfile
;
21854 (*baton
)->per_cu
= cu
->per_cu
;
21855 gdb_assert ((*baton
)->per_cu
);
21857 (*baton
)->size
= 2 + cu_header
->addr_size
;
21858 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21859 (*baton
)->data
= data
;
21861 data
[0] = DW_OP_addr
;
21862 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21863 byte_order
, attr
->as_address ());
21864 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21867 case DW_FORM_string
:
21870 case DW_FORM_GNU_str_index
:
21871 case DW_FORM_GNU_strp_alt
:
21872 /* The string is already allocated on the objfile obstack, point
21874 *bytes
= (const gdb_byte
*) attr
->as_string ();
21876 case DW_FORM_block1
:
21877 case DW_FORM_block2
:
21878 case DW_FORM_block4
:
21879 case DW_FORM_block
:
21880 case DW_FORM_exprloc
:
21881 case DW_FORM_data16
:
21882 blk
= attr
->as_block ();
21883 if (TYPE_LENGTH (type
) != blk
->size
)
21884 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21885 TYPE_LENGTH (type
));
21886 *bytes
= blk
->data
;
21889 /* The DW_AT_const_value attributes are supposed to carry the
21890 symbol's value "represented as it would be on the target
21891 architecture." By the time we get here, it's already been
21892 converted to host endianness, so we just need to sign- or
21893 zero-extend it as appropriate. */
21894 case DW_FORM_data1
:
21895 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21897 case DW_FORM_data2
:
21898 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21900 case DW_FORM_data4
:
21901 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21903 case DW_FORM_data8
:
21904 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21907 case DW_FORM_sdata
:
21908 case DW_FORM_implicit_const
:
21909 *value
= attr
->as_signed ();
21912 case DW_FORM_udata
:
21913 *value
= attr
->as_unsigned ();
21917 complaint (_("unsupported const value attribute form: '%s'"),
21918 dwarf_form_name (attr
->form
));
21925 /* Copy constant value from an attribute to a symbol. */
21928 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21929 struct dwarf2_cu
*cu
)
21931 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21933 const gdb_byte
*bytes
;
21934 struct dwarf2_locexpr_baton
*baton
;
21936 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21937 sym
->print_name (),
21938 &objfile
->objfile_obstack
, cu
,
21939 &value
, &bytes
, &baton
);
21943 SYMBOL_LOCATION_BATON (sym
) = baton
;
21944 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21946 else if (bytes
!= NULL
)
21948 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21949 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21953 SYMBOL_VALUE (sym
) = value
;
21954 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21958 /* Return the type of the die in question using its DW_AT_type attribute. */
21960 static struct type
*
21961 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21963 struct attribute
*type_attr
;
21965 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21968 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21969 /* A missing DW_AT_type represents a void type. */
21970 return objfile_type (objfile
)->builtin_void
;
21973 return lookup_die_type (die
, type_attr
, cu
);
21976 /* True iff CU's producer generates GNAT Ada auxiliary information
21977 that allows to find parallel types through that information instead
21978 of having to do expensive parallel lookups by type name. */
21981 need_gnat_info (struct dwarf2_cu
*cu
)
21983 /* Assume that the Ada compiler was GNAT, which always produces
21984 the auxiliary information. */
21985 return (cu
->language
== language_ada
);
21988 /* Return the auxiliary type of the die in question using its
21989 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21990 attribute is not present. */
21992 static struct type
*
21993 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21995 struct attribute
*type_attr
;
21997 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22001 return lookup_die_type (die
, type_attr
, cu
);
22004 /* If DIE has a descriptive_type attribute, then set the TYPE's
22005 descriptive type accordingly. */
22008 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22009 struct dwarf2_cu
*cu
)
22011 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22013 if (descriptive_type
)
22015 ALLOCATE_GNAT_AUX_TYPE (type
);
22016 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22020 /* Return the containing type of the die in question using its
22021 DW_AT_containing_type attribute. */
22023 static struct type
*
22024 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22026 struct attribute
*type_attr
;
22027 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22029 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22031 error (_("Dwarf Error: Problem turning containing type into gdb type "
22032 "[in module %s]"), objfile_name (objfile
));
22034 return lookup_die_type (die
, type_attr
, cu
);
22037 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22039 static struct type
*
22040 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22042 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22043 struct objfile
*objfile
= per_objfile
->objfile
;
22046 std::string message
22047 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22048 objfile_name (objfile
),
22049 sect_offset_str (cu
->header
.sect_off
),
22050 sect_offset_str (die
->sect_off
));
22051 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22053 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22056 /* Look up the type of DIE in CU using its type attribute ATTR.
22057 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22058 DW_AT_containing_type.
22059 If there is no type substitute an error marker. */
22061 static struct type
*
22062 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22063 struct dwarf2_cu
*cu
)
22065 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22066 struct objfile
*objfile
= per_objfile
->objfile
;
22067 struct type
*this_type
;
22069 gdb_assert (attr
->name
== DW_AT_type
22070 || attr
->name
== DW_AT_GNAT_descriptive_type
22071 || attr
->name
== DW_AT_containing_type
);
22073 /* First see if we have it cached. */
22075 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22077 struct dwarf2_per_cu_data
*per_cu
;
22078 sect_offset sect_off
= attr
->get_ref_die_offset ();
22080 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22081 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22083 else if (attr
->form_is_ref ())
22085 sect_offset sect_off
= attr
->get_ref_die_offset ();
22087 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22089 else if (attr
->form
== DW_FORM_ref_sig8
)
22091 ULONGEST signature
= attr
->as_signature ();
22093 return get_signatured_type (die
, signature
, cu
);
22097 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22098 " at %s [in module %s]"),
22099 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22100 objfile_name (objfile
));
22101 return build_error_marker_type (cu
, die
);
22104 /* If not cached we need to read it in. */
22106 if (this_type
== NULL
)
22108 struct die_info
*type_die
= NULL
;
22109 struct dwarf2_cu
*type_cu
= cu
;
22111 if (attr
->form_is_ref ())
22112 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22113 if (type_die
== NULL
)
22114 return build_error_marker_type (cu
, die
);
22115 /* If we find the type now, it's probably because the type came
22116 from an inter-CU reference and the type's CU got expanded before
22118 this_type
= read_type_die (type_die
, type_cu
);
22121 /* If we still don't have a type use an error marker. */
22123 if (this_type
== NULL
)
22124 return build_error_marker_type (cu
, die
);
22129 /* Return the type in DIE, CU.
22130 Returns NULL for invalid types.
22132 This first does a lookup in die_type_hash,
22133 and only reads the die in if necessary.
22135 NOTE: This can be called when reading in partial or full symbols. */
22137 static struct type
*
22138 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22140 struct type
*this_type
;
22142 this_type
= get_die_type (die
, cu
);
22146 return read_type_die_1 (die
, cu
);
22149 /* Read the type in DIE, CU.
22150 Returns NULL for invalid types. */
22152 static struct type
*
22153 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22155 struct type
*this_type
= NULL
;
22159 case DW_TAG_class_type
:
22160 case DW_TAG_interface_type
:
22161 case DW_TAG_structure_type
:
22162 case DW_TAG_union_type
:
22163 this_type
= read_structure_type (die
, cu
);
22165 case DW_TAG_enumeration_type
:
22166 this_type
= read_enumeration_type (die
, cu
);
22168 case DW_TAG_subprogram
:
22169 case DW_TAG_subroutine_type
:
22170 case DW_TAG_inlined_subroutine
:
22171 this_type
= read_subroutine_type (die
, cu
);
22173 case DW_TAG_array_type
:
22174 this_type
= read_array_type (die
, cu
);
22176 case DW_TAG_set_type
:
22177 this_type
= read_set_type (die
, cu
);
22179 case DW_TAG_pointer_type
:
22180 this_type
= read_tag_pointer_type (die
, cu
);
22182 case DW_TAG_ptr_to_member_type
:
22183 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22185 case DW_TAG_reference_type
:
22186 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22188 case DW_TAG_rvalue_reference_type
:
22189 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22191 case DW_TAG_const_type
:
22192 this_type
= read_tag_const_type (die
, cu
);
22194 case DW_TAG_volatile_type
:
22195 this_type
= read_tag_volatile_type (die
, cu
);
22197 case DW_TAG_restrict_type
:
22198 this_type
= read_tag_restrict_type (die
, cu
);
22200 case DW_TAG_string_type
:
22201 this_type
= read_tag_string_type (die
, cu
);
22203 case DW_TAG_typedef
:
22204 this_type
= read_typedef (die
, cu
);
22206 case DW_TAG_subrange_type
:
22207 this_type
= read_subrange_type (die
, cu
);
22209 case DW_TAG_base_type
:
22210 this_type
= read_base_type (die
, cu
);
22212 case DW_TAG_unspecified_type
:
22213 this_type
= read_unspecified_type (die
, cu
);
22215 case DW_TAG_namespace
:
22216 this_type
= read_namespace_type (die
, cu
);
22218 case DW_TAG_module
:
22219 this_type
= read_module_type (die
, cu
);
22221 case DW_TAG_atomic_type
:
22222 this_type
= read_tag_atomic_type (die
, cu
);
22225 complaint (_("unexpected tag in read_type_die: '%s'"),
22226 dwarf_tag_name (die
->tag
));
22233 /* See if we can figure out if the class lives in a namespace. We do
22234 this by looking for a member function; its demangled name will
22235 contain namespace info, if there is any.
22236 Return the computed name or NULL.
22237 Space for the result is allocated on the objfile's obstack.
22238 This is the full-die version of guess_partial_die_structure_name.
22239 In this case we know DIE has no useful parent. */
22241 static const char *
22242 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22244 struct die_info
*spec_die
;
22245 struct dwarf2_cu
*spec_cu
;
22246 struct die_info
*child
;
22247 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22250 spec_die
= die_specification (die
, &spec_cu
);
22251 if (spec_die
!= NULL
)
22257 for (child
= die
->child
;
22259 child
= child
->sibling
)
22261 if (child
->tag
== DW_TAG_subprogram
)
22263 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22265 if (linkage_name
!= NULL
)
22267 gdb::unique_xmalloc_ptr
<char> actual_name
22268 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22269 const char *name
= NULL
;
22271 if (actual_name
!= NULL
)
22273 const char *die_name
= dwarf2_name (die
, cu
);
22275 if (die_name
!= NULL
22276 && strcmp (die_name
, actual_name
.get ()) != 0)
22278 /* Strip off the class name from the full name.
22279 We want the prefix. */
22280 int die_name_len
= strlen (die_name
);
22281 int actual_name_len
= strlen (actual_name
.get ());
22282 const char *ptr
= actual_name
.get ();
22284 /* Test for '::' as a sanity check. */
22285 if (actual_name_len
> die_name_len
+ 2
22286 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22287 name
= obstack_strndup (
22288 &objfile
->per_bfd
->storage_obstack
,
22289 ptr
, actual_name_len
- die_name_len
- 2);
22300 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22301 prefix part in such case. See
22302 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22304 static const char *
22305 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22307 struct attribute
*attr
;
22310 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22311 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22314 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22317 attr
= dw2_linkage_name_attr (die
, cu
);
22318 const char *attr_name
= attr
->as_string ();
22319 if (attr
== NULL
|| attr_name
== NULL
)
22322 /* dwarf2_name had to be already called. */
22323 gdb_assert (attr
->canonical_string_p ());
22325 /* Strip the base name, keep any leading namespaces/classes. */
22326 base
= strrchr (attr_name
, ':');
22327 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22330 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22331 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22333 &base
[-1] - attr_name
);
22336 /* Return the name of the namespace/class that DIE is defined within,
22337 or "" if we can't tell. The caller should not xfree the result.
22339 For example, if we're within the method foo() in the following
22349 then determine_prefix on foo's die will return "N::C". */
22351 static const char *
22352 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22354 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22355 struct die_info
*parent
, *spec_die
;
22356 struct dwarf2_cu
*spec_cu
;
22357 struct type
*parent_type
;
22358 const char *retval
;
22360 if (cu
->language
!= language_cplus
22361 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22362 && cu
->language
!= language_rust
)
22365 retval
= anonymous_struct_prefix (die
, cu
);
22369 /* We have to be careful in the presence of DW_AT_specification.
22370 For example, with GCC 3.4, given the code
22374 // Definition of N::foo.
22378 then we'll have a tree of DIEs like this:
22380 1: DW_TAG_compile_unit
22381 2: DW_TAG_namespace // N
22382 3: DW_TAG_subprogram // declaration of N::foo
22383 4: DW_TAG_subprogram // definition of N::foo
22384 DW_AT_specification // refers to die #3
22386 Thus, when processing die #4, we have to pretend that we're in
22387 the context of its DW_AT_specification, namely the contex of die
22390 spec_die
= die_specification (die
, &spec_cu
);
22391 if (spec_die
== NULL
)
22392 parent
= die
->parent
;
22395 parent
= spec_die
->parent
;
22399 if (parent
== NULL
)
22401 else if (parent
->building_fullname
)
22404 const char *parent_name
;
22406 /* It has been seen on RealView 2.2 built binaries,
22407 DW_TAG_template_type_param types actually _defined_ as
22408 children of the parent class:
22411 template class <class Enum> Class{};
22412 Class<enum E> class_e;
22414 1: DW_TAG_class_type (Class)
22415 2: DW_TAG_enumeration_type (E)
22416 3: DW_TAG_enumerator (enum1:0)
22417 3: DW_TAG_enumerator (enum2:1)
22419 2: DW_TAG_template_type_param
22420 DW_AT_type DW_FORM_ref_udata (E)
22422 Besides being broken debug info, it can put GDB into an
22423 infinite loop. Consider:
22425 When we're building the full name for Class<E>, we'll start
22426 at Class, and go look over its template type parameters,
22427 finding E. We'll then try to build the full name of E, and
22428 reach here. We're now trying to build the full name of E,
22429 and look over the parent DIE for containing scope. In the
22430 broken case, if we followed the parent DIE of E, we'd again
22431 find Class, and once again go look at its template type
22432 arguments, etc., etc. Simply don't consider such parent die
22433 as source-level parent of this die (it can't be, the language
22434 doesn't allow it), and break the loop here. */
22435 name
= dwarf2_name (die
, cu
);
22436 parent_name
= dwarf2_name (parent
, cu
);
22437 complaint (_("template param type '%s' defined within parent '%s'"),
22438 name
? name
: "<unknown>",
22439 parent_name
? parent_name
: "<unknown>");
22443 switch (parent
->tag
)
22445 case DW_TAG_namespace
:
22446 parent_type
= read_type_die (parent
, cu
);
22447 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22448 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22449 Work around this problem here. */
22450 if (cu
->language
== language_cplus
22451 && strcmp (parent_type
->name (), "::") == 0)
22453 /* We give a name to even anonymous namespaces. */
22454 return parent_type
->name ();
22455 case DW_TAG_class_type
:
22456 case DW_TAG_interface_type
:
22457 case DW_TAG_structure_type
:
22458 case DW_TAG_union_type
:
22459 case DW_TAG_module
:
22460 parent_type
= read_type_die (parent
, cu
);
22461 if (parent_type
->name () != NULL
)
22462 return parent_type
->name ();
22464 /* An anonymous structure is only allowed non-static data
22465 members; no typedefs, no member functions, et cetera.
22466 So it does not need a prefix. */
22468 case DW_TAG_compile_unit
:
22469 case DW_TAG_partial_unit
:
22470 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22471 if (cu
->language
== language_cplus
22472 && !per_objfile
->per_bfd
->types
.empty ()
22473 && die
->child
!= NULL
22474 && (die
->tag
== DW_TAG_class_type
22475 || die
->tag
== DW_TAG_structure_type
22476 || die
->tag
== DW_TAG_union_type
))
22478 const char *name
= guess_full_die_structure_name (die
, cu
);
22483 case DW_TAG_subprogram
:
22484 /* Nested subroutines in Fortran get a prefix with the name
22485 of the parent's subroutine. */
22486 if (cu
->language
== language_fortran
)
22488 if ((die
->tag
== DW_TAG_subprogram
)
22489 && (dwarf2_name (parent
, cu
) != NULL
))
22490 return dwarf2_name (parent
, cu
);
22492 return determine_prefix (parent
, cu
);
22493 case DW_TAG_enumeration_type
:
22494 parent_type
= read_type_die (parent
, cu
);
22495 if (TYPE_DECLARED_CLASS (parent_type
))
22497 if (parent_type
->name () != NULL
)
22498 return parent_type
->name ();
22501 /* Fall through. */
22503 return determine_prefix (parent
, cu
);
22507 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22508 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22509 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22510 an obconcat, otherwise allocate storage for the result. The CU argument is
22511 used to determine the language and hence, the appropriate separator. */
22513 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22516 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22517 int physname
, struct dwarf2_cu
*cu
)
22519 const char *lead
= "";
22522 if (suffix
== NULL
|| suffix
[0] == '\0'
22523 || prefix
== NULL
|| prefix
[0] == '\0')
22525 else if (cu
->language
== language_d
)
22527 /* For D, the 'main' function could be defined in any module, but it
22528 should never be prefixed. */
22529 if (strcmp (suffix
, "D main") == 0)
22537 else if (cu
->language
== language_fortran
&& physname
)
22539 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22540 DW_AT_MIPS_linkage_name is preferred and used instead. */
22548 if (prefix
== NULL
)
22550 if (suffix
== NULL
)
22557 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22559 strcpy (retval
, lead
);
22560 strcat (retval
, prefix
);
22561 strcat (retval
, sep
);
22562 strcat (retval
, suffix
);
22567 /* We have an obstack. */
22568 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22572 /* Get name of a die, return NULL if not found. */
22574 static const char *
22575 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22576 struct objfile
*objfile
)
22578 if (name
&& cu
->language
== language_cplus
)
22580 gdb::unique_xmalloc_ptr
<char> canon_name
22581 = cp_canonicalize_string (name
);
22583 if (canon_name
!= nullptr)
22584 name
= objfile
->intern (canon_name
.get ());
22590 /* Get name of a die, return NULL if not found.
22591 Anonymous namespaces are converted to their magic string. */
22593 static const char *
22594 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22596 struct attribute
*attr
;
22597 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22599 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22600 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22601 if (attr_name
== nullptr
22602 && die
->tag
!= DW_TAG_namespace
22603 && die
->tag
!= DW_TAG_class_type
22604 && die
->tag
!= DW_TAG_interface_type
22605 && die
->tag
!= DW_TAG_structure_type
22606 && die
->tag
!= DW_TAG_union_type
)
22611 case DW_TAG_compile_unit
:
22612 case DW_TAG_partial_unit
:
22613 /* Compilation units have a DW_AT_name that is a filename, not
22614 a source language identifier. */
22615 case DW_TAG_enumeration_type
:
22616 case DW_TAG_enumerator
:
22617 /* These tags always have simple identifiers already; no need
22618 to canonicalize them. */
22621 case DW_TAG_namespace
:
22622 if (attr_name
!= nullptr)
22624 return CP_ANONYMOUS_NAMESPACE_STR
;
22626 case DW_TAG_class_type
:
22627 case DW_TAG_interface_type
:
22628 case DW_TAG_structure_type
:
22629 case DW_TAG_union_type
:
22630 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22631 structures or unions. These were of the form "._%d" in GCC 4.1,
22632 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22633 and GCC 4.4. We work around this problem by ignoring these. */
22634 if (attr_name
!= nullptr
22635 && (startswith (attr_name
, "._")
22636 || startswith (attr_name
, "<anonymous")))
22639 /* GCC might emit a nameless typedef that has a linkage name. See
22640 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22641 if (!attr
|| attr_name
== NULL
)
22643 attr
= dw2_linkage_name_attr (die
, cu
);
22644 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22645 if (attr
== NULL
|| attr_name
== NULL
)
22648 /* Avoid demangling attr_name the second time on a second
22649 call for the same DIE. */
22650 if (!attr
->canonical_string_p ())
22652 gdb::unique_xmalloc_ptr
<char> demangled
22653 (gdb_demangle (attr_name
, DMGL_TYPES
));
22654 if (demangled
== nullptr)
22657 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22658 attr_name
= attr
->as_string ();
22661 /* Strip any leading namespaces/classes, keep only the
22662 base name. DW_AT_name for named DIEs does not
22663 contain the prefixes. */
22664 const char *base
= strrchr (attr_name
, ':');
22665 if (base
&& base
> attr_name
&& base
[-1] == ':')
22676 if (!attr
->canonical_string_p ())
22677 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22679 return attr
->as_string ();
22682 /* Return the die that this die in an extension of, or NULL if there
22683 is none. *EXT_CU is the CU containing DIE on input, and the CU
22684 containing the return value on output. */
22686 static struct die_info
*
22687 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22689 struct attribute
*attr
;
22691 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22695 return follow_die_ref (die
, attr
, ext_cu
);
22699 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22703 print_spaces (indent
, f
);
22704 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22705 dwarf_tag_name (die
->tag
), die
->abbrev
,
22706 sect_offset_str (die
->sect_off
));
22708 if (die
->parent
!= NULL
)
22710 print_spaces (indent
, f
);
22711 fprintf_unfiltered (f
, " parent at offset: %s\n",
22712 sect_offset_str (die
->parent
->sect_off
));
22715 print_spaces (indent
, f
);
22716 fprintf_unfiltered (f
, " has children: %s\n",
22717 dwarf_bool_name (die
->child
!= NULL
));
22719 print_spaces (indent
, f
);
22720 fprintf_unfiltered (f
, " attributes:\n");
22722 for (i
= 0; i
< die
->num_attrs
; ++i
)
22724 print_spaces (indent
, f
);
22725 fprintf_unfiltered (f
, " %s (%s) ",
22726 dwarf_attr_name (die
->attrs
[i
].name
),
22727 dwarf_form_name (die
->attrs
[i
].form
));
22729 switch (die
->attrs
[i
].form
)
22732 case DW_FORM_addrx
:
22733 case DW_FORM_GNU_addr_index
:
22734 fprintf_unfiltered (f
, "address: ");
22735 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
22737 case DW_FORM_block2
:
22738 case DW_FORM_block4
:
22739 case DW_FORM_block
:
22740 case DW_FORM_block1
:
22741 fprintf_unfiltered (f
, "block: size %s",
22742 pulongest (die
->attrs
[i
].as_block ()->size
));
22744 case DW_FORM_exprloc
:
22745 fprintf_unfiltered (f
, "expression: size %s",
22746 pulongest (die
->attrs
[i
].as_block ()->size
));
22748 case DW_FORM_data16
:
22749 fprintf_unfiltered (f
, "constant of 16 bytes");
22751 case DW_FORM_ref_addr
:
22752 fprintf_unfiltered (f
, "ref address: ");
22753 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22755 case DW_FORM_GNU_ref_alt
:
22756 fprintf_unfiltered (f
, "alt ref address: ");
22757 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22763 case DW_FORM_ref_udata
:
22764 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22765 (long) (die
->attrs
[i
].as_unsigned ()));
22767 case DW_FORM_data1
:
22768 case DW_FORM_data2
:
22769 case DW_FORM_data4
:
22770 case DW_FORM_data8
:
22771 case DW_FORM_udata
:
22772 fprintf_unfiltered (f
, "constant: %s",
22773 pulongest (die
->attrs
[i
].as_unsigned ()));
22775 case DW_FORM_sec_offset
:
22776 fprintf_unfiltered (f
, "section offset: %s",
22777 pulongest (die
->attrs
[i
].as_unsigned ()));
22779 case DW_FORM_ref_sig8
:
22780 fprintf_unfiltered (f
, "signature: %s",
22781 hex_string (die
->attrs
[i
].as_signature ()));
22783 case DW_FORM_string
:
22785 case DW_FORM_line_strp
:
22787 case DW_FORM_GNU_str_index
:
22788 case DW_FORM_GNU_strp_alt
:
22789 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22790 die
->attrs
[i
].as_string ()
22791 ? die
->attrs
[i
].as_string () : "",
22792 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
22795 if (die
->attrs
[i
].as_boolean ())
22796 fprintf_unfiltered (f
, "flag: TRUE");
22798 fprintf_unfiltered (f
, "flag: FALSE");
22800 case DW_FORM_flag_present
:
22801 fprintf_unfiltered (f
, "flag: TRUE");
22803 case DW_FORM_indirect
:
22804 /* The reader will have reduced the indirect form to
22805 the "base form" so this form should not occur. */
22806 fprintf_unfiltered (f
,
22807 "unexpected attribute form: DW_FORM_indirect");
22809 case DW_FORM_sdata
:
22810 case DW_FORM_implicit_const
:
22811 fprintf_unfiltered (f
, "constant: %s",
22812 plongest (die
->attrs
[i
].as_signed ()));
22815 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22816 die
->attrs
[i
].form
);
22819 fprintf_unfiltered (f
, "\n");
22824 dump_die_for_error (struct die_info
*die
)
22826 dump_die_shallow (gdb_stderr
, 0, die
);
22830 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22832 int indent
= level
* 4;
22834 gdb_assert (die
!= NULL
);
22836 if (level
>= max_level
)
22839 dump_die_shallow (f
, indent
, die
);
22841 if (die
->child
!= NULL
)
22843 print_spaces (indent
, f
);
22844 fprintf_unfiltered (f
, " Children:");
22845 if (level
+ 1 < max_level
)
22847 fprintf_unfiltered (f
, "\n");
22848 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22852 fprintf_unfiltered (f
,
22853 " [not printed, max nesting level reached]\n");
22857 if (die
->sibling
!= NULL
&& level
> 0)
22859 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22863 /* This is called from the pdie macro in gdbinit.in.
22864 It's not static so gcc will keep a copy callable from gdb. */
22867 dump_die (struct die_info
*die
, int max_level
)
22869 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22873 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22877 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22878 to_underlying (die
->sect_off
),
22884 /* Follow reference or signature attribute ATTR of SRC_DIE.
22885 On entry *REF_CU is the CU of SRC_DIE.
22886 On exit *REF_CU is the CU of the result. */
22888 static struct die_info
*
22889 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22890 struct dwarf2_cu
**ref_cu
)
22892 struct die_info
*die
;
22894 if (attr
->form_is_ref ())
22895 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22896 else if (attr
->form
== DW_FORM_ref_sig8
)
22897 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22900 dump_die_for_error (src_die
);
22901 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22902 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22908 /* Follow reference OFFSET.
22909 On entry *REF_CU is the CU of the source die referencing OFFSET.
22910 On exit *REF_CU is the CU of the result.
22911 Returns NULL if OFFSET is invalid. */
22913 static struct die_info
*
22914 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22915 struct dwarf2_cu
**ref_cu
)
22917 struct die_info temp_die
;
22918 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22919 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22921 gdb_assert (cu
->per_cu
!= NULL
);
22925 if (cu
->per_cu
->is_debug_types
)
22927 /* .debug_types CUs cannot reference anything outside their CU.
22928 If they need to, they have to reference a signatured type via
22929 DW_FORM_ref_sig8. */
22930 if (!cu
->header
.offset_in_cu_p (sect_off
))
22933 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22934 || !cu
->header
.offset_in_cu_p (sect_off
))
22936 struct dwarf2_per_cu_data
*per_cu
;
22938 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22941 /* If necessary, add it to the queue and load its DIEs. */
22942 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
22943 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
22944 false, cu
->language
);
22946 target_cu
= per_objfile
->get_cu (per_cu
);
22948 else if (cu
->dies
== NULL
)
22950 /* We're loading full DIEs during partial symbol reading. */
22951 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
22952 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
22956 *ref_cu
= target_cu
;
22957 temp_die
.sect_off
= sect_off
;
22959 if (target_cu
!= cu
)
22960 target_cu
->ancestor
= cu
;
22962 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22964 to_underlying (sect_off
));
22967 /* Follow reference attribute ATTR of SRC_DIE.
22968 On entry *REF_CU is the CU of SRC_DIE.
22969 On exit *REF_CU is the CU of the result. */
22971 static struct die_info
*
22972 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22973 struct dwarf2_cu
**ref_cu
)
22975 sect_offset sect_off
= attr
->get_ref_die_offset ();
22976 struct dwarf2_cu
*cu
= *ref_cu
;
22977 struct die_info
*die
;
22979 die
= follow_die_offset (sect_off
,
22980 (attr
->form
== DW_FORM_GNU_ref_alt
22981 || cu
->per_cu
->is_dwz
),
22984 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22985 "at %s [in module %s]"),
22986 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22987 objfile_name (cu
->per_objfile
->objfile
));
22994 struct dwarf2_locexpr_baton
22995 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22996 dwarf2_per_cu_data
*per_cu
,
22997 dwarf2_per_objfile
*per_objfile
,
22998 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
22999 bool resolve_abstract_p
)
23001 struct die_info
*die
;
23002 struct attribute
*attr
;
23003 struct dwarf2_locexpr_baton retval
;
23004 struct objfile
*objfile
= per_objfile
->objfile
;
23006 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23008 cu
= load_cu (per_cu
, per_objfile
, false);
23012 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23013 Instead just throw an error, not much else we can do. */
23014 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23015 sect_offset_str (sect_off
), objfile_name (objfile
));
23018 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23020 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23021 sect_offset_str (sect_off
), objfile_name (objfile
));
23023 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23024 if (!attr
&& resolve_abstract_p
23025 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23026 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23028 CORE_ADDR pc
= get_frame_pc ();
23029 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23030 struct gdbarch
*gdbarch
= objfile
->arch ();
23032 for (const auto &cand_off
23033 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23035 struct dwarf2_cu
*cand_cu
= cu
;
23036 struct die_info
*cand
23037 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23040 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23043 CORE_ADDR pc_low
, pc_high
;
23044 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23045 if (pc_low
== ((CORE_ADDR
) -1))
23047 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23048 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23049 if (!(pc_low
<= pc
&& pc
< pc_high
))
23053 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23060 /* DWARF: "If there is no such attribute, then there is no effect.".
23061 DATA is ignored if SIZE is 0. */
23063 retval
.data
= NULL
;
23066 else if (attr
->form_is_section_offset ())
23068 struct dwarf2_loclist_baton loclist_baton
;
23069 CORE_ADDR pc
= get_frame_pc ();
23072 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23074 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23076 retval
.size
= size
;
23080 if (!attr
->form_is_block ())
23081 error (_("Dwarf Error: DIE at %s referenced in module %s "
23082 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23083 sect_offset_str (sect_off
), objfile_name (objfile
));
23085 struct dwarf_block
*block
= attr
->as_block ();
23086 retval
.data
= block
->data
;
23087 retval
.size
= block
->size
;
23089 retval
.per_objfile
= per_objfile
;
23090 retval
.per_cu
= cu
->per_cu
;
23092 per_objfile
->age_comp_units ();
23099 struct dwarf2_locexpr_baton
23100 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23101 dwarf2_per_cu_data
*per_cu
,
23102 dwarf2_per_objfile
*per_objfile
,
23103 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23105 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23107 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23111 /* Write a constant of a given type as target-ordered bytes into
23114 static const gdb_byte
*
23115 write_constant_as_bytes (struct obstack
*obstack
,
23116 enum bfd_endian byte_order
,
23123 *len
= TYPE_LENGTH (type
);
23124 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23125 store_unsigned_integer (result
, *len
, byte_order
, value
);
23133 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23134 dwarf2_per_cu_data
*per_cu
,
23135 dwarf2_per_objfile
*per_objfile
,
23139 struct die_info
*die
;
23140 struct attribute
*attr
;
23141 const gdb_byte
*result
= NULL
;
23144 enum bfd_endian byte_order
;
23145 struct objfile
*objfile
= per_objfile
->objfile
;
23147 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23149 cu
= load_cu (per_cu
, per_objfile
, false);
23153 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23154 Instead just throw an error, not much else we can do. */
23155 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23156 sect_offset_str (sect_off
), objfile_name (objfile
));
23159 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23161 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23162 sect_offset_str (sect_off
), objfile_name (objfile
));
23164 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23168 byte_order
= (bfd_big_endian (objfile
->obfd
)
23169 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23171 switch (attr
->form
)
23174 case DW_FORM_addrx
:
23175 case DW_FORM_GNU_addr_index
:
23179 *len
= cu
->header
.addr_size
;
23180 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23181 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23185 case DW_FORM_string
:
23188 case DW_FORM_GNU_str_index
:
23189 case DW_FORM_GNU_strp_alt
:
23190 /* The string is already allocated on the objfile obstack, point
23193 const char *attr_name
= attr
->as_string ();
23194 result
= (const gdb_byte
*) attr_name
;
23195 *len
= strlen (attr_name
);
23198 case DW_FORM_block1
:
23199 case DW_FORM_block2
:
23200 case DW_FORM_block4
:
23201 case DW_FORM_block
:
23202 case DW_FORM_exprloc
:
23203 case DW_FORM_data16
:
23205 struct dwarf_block
*block
= attr
->as_block ();
23206 result
= block
->data
;
23207 *len
= block
->size
;
23211 /* The DW_AT_const_value attributes are supposed to carry the
23212 symbol's value "represented as it would be on the target
23213 architecture." By the time we get here, it's already been
23214 converted to host endianness, so we just need to sign- or
23215 zero-extend it as appropriate. */
23216 case DW_FORM_data1
:
23217 type
= die_type (die
, cu
);
23218 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23219 if (result
== NULL
)
23220 result
= write_constant_as_bytes (obstack
, byte_order
,
23223 case DW_FORM_data2
:
23224 type
= die_type (die
, cu
);
23225 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23226 if (result
== NULL
)
23227 result
= write_constant_as_bytes (obstack
, byte_order
,
23230 case DW_FORM_data4
:
23231 type
= die_type (die
, cu
);
23232 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23233 if (result
== NULL
)
23234 result
= write_constant_as_bytes (obstack
, byte_order
,
23237 case DW_FORM_data8
:
23238 type
= die_type (die
, cu
);
23239 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23240 if (result
== NULL
)
23241 result
= write_constant_as_bytes (obstack
, byte_order
,
23245 case DW_FORM_sdata
:
23246 case DW_FORM_implicit_const
:
23247 type
= die_type (die
, cu
);
23248 result
= write_constant_as_bytes (obstack
, byte_order
,
23249 type
, attr
->as_signed (), len
);
23252 case DW_FORM_udata
:
23253 type
= die_type (die
, cu
);
23254 result
= write_constant_as_bytes (obstack
, byte_order
,
23255 type
, attr
->as_unsigned (), len
);
23259 complaint (_("unsupported const value attribute form: '%s'"),
23260 dwarf_form_name (attr
->form
));
23270 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23271 dwarf2_per_cu_data
*per_cu
,
23272 dwarf2_per_objfile
*per_objfile
)
23274 struct die_info
*die
;
23276 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23278 cu
= load_cu (per_cu
, per_objfile
, false);
23283 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23287 return die_type (die
, cu
);
23293 dwarf2_get_die_type (cu_offset die_offset
,
23294 dwarf2_per_cu_data
*per_cu
,
23295 dwarf2_per_objfile
*per_objfile
)
23297 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23298 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23301 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23302 On entry *REF_CU is the CU of SRC_DIE.
23303 On exit *REF_CU is the CU of the result.
23304 Returns NULL if the referenced DIE isn't found. */
23306 static struct die_info
*
23307 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23308 struct dwarf2_cu
**ref_cu
)
23310 struct die_info temp_die
;
23311 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23312 struct die_info
*die
;
23313 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23316 /* While it might be nice to assert sig_type->type == NULL here,
23317 we can get here for DW_AT_imported_declaration where we need
23318 the DIE not the type. */
23320 /* If necessary, add it to the queue and load its DIEs. */
23322 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
23324 read_signatured_type (sig_type
, per_objfile
);
23326 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
23327 gdb_assert (sig_cu
!= NULL
);
23328 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23329 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23330 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23331 to_underlying (temp_die
.sect_off
));
23334 /* For .gdb_index version 7 keep track of included TUs.
23335 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23336 if (per_objfile
->per_bfd
->index_table
!= NULL
23337 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23339 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23344 sig_cu
->ancestor
= cu
;
23352 /* Follow signatured type referenced by ATTR in SRC_DIE.
23353 On entry *REF_CU is the CU of SRC_DIE.
23354 On exit *REF_CU is the CU of the result.
23355 The result is the DIE of the type.
23356 If the referenced type cannot be found an error is thrown. */
23358 static struct die_info
*
23359 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23360 struct dwarf2_cu
**ref_cu
)
23362 ULONGEST signature
= attr
->as_signature ();
23363 struct signatured_type
*sig_type
;
23364 struct die_info
*die
;
23366 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23368 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23369 /* sig_type will be NULL if the signatured type is missing from
23371 if (sig_type
== NULL
)
23373 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23374 " from DIE at %s [in module %s]"),
23375 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23376 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23379 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23382 dump_die_for_error (src_die
);
23383 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23384 " from DIE at %s [in module %s]"),
23385 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23386 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23392 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23393 reading in and processing the type unit if necessary. */
23395 static struct type
*
23396 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23397 struct dwarf2_cu
*cu
)
23399 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23400 struct signatured_type
*sig_type
;
23401 struct dwarf2_cu
*type_cu
;
23402 struct die_info
*type_die
;
23405 sig_type
= lookup_signatured_type (cu
, signature
);
23406 /* sig_type will be NULL if the signatured type is missing from
23408 if (sig_type
== NULL
)
23410 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23411 " from DIE at %s [in module %s]"),
23412 hex_string (signature
), sect_offset_str (die
->sect_off
),
23413 objfile_name (per_objfile
->objfile
));
23414 return build_error_marker_type (cu
, die
);
23417 /* If we already know the type we're done. */
23418 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23419 if (type
!= nullptr)
23423 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23424 if (type_die
!= NULL
)
23426 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23427 is created. This is important, for example, because for c++ classes
23428 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23429 type
= read_type_die (type_die
, type_cu
);
23432 complaint (_("Dwarf Error: Cannot build signatured type %s"
23433 " referenced from DIE at %s [in module %s]"),
23434 hex_string (signature
), sect_offset_str (die
->sect_off
),
23435 objfile_name (per_objfile
->objfile
));
23436 type
= build_error_marker_type (cu
, die
);
23441 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23442 " from DIE at %s [in module %s]"),
23443 hex_string (signature
), sect_offset_str (die
->sect_off
),
23444 objfile_name (per_objfile
->objfile
));
23445 type
= build_error_marker_type (cu
, die
);
23448 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23453 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23454 reading in and processing the type unit if necessary. */
23456 static struct type
*
23457 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23458 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23460 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23461 if (attr
->form_is_ref ())
23463 struct dwarf2_cu
*type_cu
= cu
;
23464 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23466 return read_type_die (type_die
, type_cu
);
23468 else if (attr
->form
== DW_FORM_ref_sig8
)
23470 return get_signatured_type (die
, attr
->as_signature (), cu
);
23474 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23476 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23477 " at %s [in module %s]"),
23478 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23479 objfile_name (per_objfile
->objfile
));
23480 return build_error_marker_type (cu
, die
);
23484 /* Load the DIEs associated with type unit PER_CU into memory. */
23487 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23488 dwarf2_per_objfile
*per_objfile
)
23490 struct signatured_type
*sig_type
;
23492 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23493 gdb_assert (! per_cu
->type_unit_group_p ());
23495 /* We have the per_cu, but we need the signatured_type.
23496 Fortunately this is an easy translation. */
23497 gdb_assert (per_cu
->is_debug_types
);
23498 sig_type
= (struct signatured_type
*) per_cu
;
23500 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23502 read_signatured_type (sig_type
, per_objfile
);
23504 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23507 /* Read in a signatured type and build its CU and DIEs.
23508 If the type is a stub for the real type in a DWO file,
23509 read in the real type from the DWO file as well. */
23512 read_signatured_type (signatured_type
*sig_type
,
23513 dwarf2_per_objfile
*per_objfile
)
23515 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23517 gdb_assert (per_cu
->is_debug_types
);
23518 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23520 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
23522 if (!reader
.dummy_p
)
23524 struct dwarf2_cu
*cu
= reader
.cu
;
23525 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23527 gdb_assert (cu
->die_hash
== NULL
);
23529 htab_create_alloc_ex (cu
->header
.length
/ 12,
23533 &cu
->comp_unit_obstack
,
23534 hashtab_obstack_allocate
,
23535 dummy_obstack_deallocate
);
23537 if (reader
.comp_unit_die
->has_children
)
23538 reader
.comp_unit_die
->child
23539 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23540 reader
.comp_unit_die
);
23541 cu
->dies
= reader
.comp_unit_die
;
23542 /* comp_unit_die is not stored in die_hash, no need. */
23544 /* We try not to read any attributes in this function, because
23545 not all CUs needed for references have been loaded yet, and
23546 symbol table processing isn't initialized. But we have to
23547 set the CU language, or we won't be able to build types
23548 correctly. Similarly, if we do not read the producer, we can
23549 not apply producer-specific interpretation. */
23550 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23555 sig_type
->per_cu
.tu_read
= 1;
23558 /* Decode simple location descriptions.
23559 Given a pointer to a dwarf block that defines a location, compute
23560 the location and return the value. If COMPUTED is non-null, it is
23561 set to true to indicate that decoding was successful, and false
23562 otherwise. If COMPUTED is null, then this function may emit a
23566 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23568 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23570 size_t size
= blk
->size
;
23571 const gdb_byte
*data
= blk
->data
;
23572 CORE_ADDR stack
[64];
23574 unsigned int bytes_read
, unsnd
;
23577 if (computed
!= nullptr)
23583 stack
[++stacki
] = 0;
23622 stack
[++stacki
] = op
- DW_OP_lit0
;
23657 stack
[++stacki
] = op
- DW_OP_reg0
;
23660 if (computed
== nullptr)
23661 dwarf2_complex_location_expr_complaint ();
23668 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23670 stack
[++stacki
] = unsnd
;
23673 if (computed
== nullptr)
23674 dwarf2_complex_location_expr_complaint ();
23681 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23686 case DW_OP_const1u
:
23687 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23691 case DW_OP_const1s
:
23692 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23696 case DW_OP_const2u
:
23697 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23701 case DW_OP_const2s
:
23702 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23706 case DW_OP_const4u
:
23707 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23711 case DW_OP_const4s
:
23712 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23716 case DW_OP_const8u
:
23717 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23722 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23728 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23733 stack
[stacki
+ 1] = stack
[stacki
];
23738 stack
[stacki
- 1] += stack
[stacki
];
23742 case DW_OP_plus_uconst
:
23743 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23749 stack
[stacki
- 1] -= stack
[stacki
];
23754 /* If we're not the last op, then we definitely can't encode
23755 this using GDB's address_class enum. This is valid for partial
23756 global symbols, although the variable's address will be bogus
23760 if (computed
== nullptr)
23761 dwarf2_complex_location_expr_complaint ();
23767 case DW_OP_GNU_push_tls_address
:
23768 case DW_OP_form_tls_address
:
23769 /* The top of the stack has the offset from the beginning
23770 of the thread control block at which the variable is located. */
23771 /* Nothing should follow this operator, so the top of stack would
23773 /* This is valid for partial global symbols, but the variable's
23774 address will be bogus in the psymtab. Make it always at least
23775 non-zero to not look as a variable garbage collected by linker
23776 which have DW_OP_addr 0. */
23779 if (computed
== nullptr)
23780 dwarf2_complex_location_expr_complaint ();
23787 case DW_OP_GNU_uninit
:
23788 if (computed
!= nullptr)
23793 case DW_OP_GNU_addr_index
:
23794 case DW_OP_GNU_const_index
:
23795 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23801 if (computed
== nullptr)
23803 const char *name
= get_DW_OP_name (op
);
23806 complaint (_("unsupported stack op: '%s'"),
23809 complaint (_("unsupported stack op: '%02x'"),
23813 return (stack
[stacki
]);
23816 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23817 outside of the allocated space. Also enforce minimum>0. */
23818 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23820 if (computed
== nullptr)
23821 complaint (_("location description stack overflow"));
23827 if (computed
== nullptr)
23828 complaint (_("location description stack underflow"));
23833 if (computed
!= nullptr)
23835 return (stack
[stacki
]);
23838 /* memory allocation interface */
23840 static struct dwarf_block
*
23841 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23843 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23846 static struct die_info
*
23847 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23849 struct die_info
*die
;
23850 size_t size
= sizeof (struct die_info
);
23853 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23855 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23856 memset (die
, 0, sizeof (struct die_info
));
23862 /* Macro support. */
23864 /* An overload of dwarf_decode_macros that finds the correct section
23865 and ensures it is read in before calling the other overload. */
23868 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23869 int section_is_gnu
)
23871 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23872 struct objfile
*objfile
= per_objfile
->objfile
;
23873 const struct line_header
*lh
= cu
->line_header
;
23874 unsigned int offset_size
= cu
->header
.offset_size
;
23875 struct dwarf2_section_info
*section
;
23876 const char *section_name
;
23878 if (cu
->dwo_unit
!= nullptr)
23880 if (section_is_gnu
)
23882 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23883 section_name
= ".debug_macro.dwo";
23887 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23888 section_name
= ".debug_macinfo.dwo";
23893 if (section_is_gnu
)
23895 section
= &per_objfile
->per_bfd
->macro
;
23896 section_name
= ".debug_macro";
23900 section
= &per_objfile
->per_bfd
->macinfo
;
23901 section_name
= ".debug_macinfo";
23905 section
->read (objfile
);
23906 if (section
->buffer
== nullptr)
23908 complaint (_("missing %s section"), section_name
);
23912 buildsym_compunit
*builder
= cu
->get_builder ();
23914 struct dwarf2_section_info
*str_offsets_section
;
23915 struct dwarf2_section_info
*str_section
;
23916 ULONGEST str_offsets_base
;
23918 if (cu
->dwo_unit
!= nullptr)
23920 str_offsets_section
= &cu
->dwo_unit
->dwo_file
23921 ->sections
.str_offsets
;
23922 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
23923 str_offsets_base
= cu
->header
.addr_size
;
23927 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
23928 str_section
= &per_objfile
->per_bfd
->str
;
23929 str_offsets_base
= *cu
->str_offsets_base
;
23932 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
23933 offset_size
, offset
, str_section
, str_offsets_section
,
23934 str_offsets_base
, section_is_gnu
);
23937 /* Return the .debug_loc section to use for CU.
23938 For DWO files use .debug_loc.dwo. */
23940 static struct dwarf2_section_info
*
23941 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23943 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23947 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23949 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23951 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
23952 : &per_objfile
->per_bfd
->loc
);
23955 /* Return the .debug_rnglists section to use for CU. */
23956 static struct dwarf2_section_info
*
23957 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
23959 if (cu
->header
.version
< 5)
23960 error (_(".debug_rnglists section cannot be used in DWARF %d"),
23961 cu
->header
.version
);
23962 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23964 /* Make sure we read the .debug_rnglists section from the file that
23965 contains the DW_AT_ranges attribute we are reading. Normally that
23966 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
23967 or DW_TAG_skeleton unit, we always want to read from objfile/linked
23969 if (cu
->dwo_unit
!= nullptr
23970 && tag
!= DW_TAG_compile_unit
23971 && tag
!= DW_TAG_skeleton_unit
)
23973 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23975 if (sections
->rnglists
.size
> 0)
23976 return §ions
->rnglists
;
23978 error (_(".debug_rnglists section is missing from .dwo file."));
23980 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
23983 /* A helper function that fills in a dwarf2_loclist_baton. */
23986 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23987 struct dwarf2_loclist_baton
*baton
,
23988 const struct attribute
*attr
)
23990 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23991 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23993 section
->read (per_objfile
->objfile
);
23995 baton
->per_objfile
= per_objfile
;
23996 baton
->per_cu
= cu
->per_cu
;
23997 gdb_assert (baton
->per_cu
);
23998 /* We don't know how long the location list is, but make sure we
23999 don't run off the edge of the section. */
24000 baton
->size
= section
->size
- attr
->as_unsigned ();
24001 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24002 if (cu
->base_address
.has_value ())
24003 baton
->base_address
= *cu
->base_address
;
24005 baton
->base_address
= 0;
24006 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24010 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24011 struct dwarf2_cu
*cu
, int is_block
)
24013 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24014 struct objfile
*objfile
= per_objfile
->objfile
;
24015 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24017 if (attr
->form_is_section_offset ()
24018 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24019 the section. If so, fall through to the complaint in the
24021 && attr
->as_unsigned () < section
->get_size (objfile
))
24023 struct dwarf2_loclist_baton
*baton
;
24025 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24027 fill_in_loclist_baton (cu
, baton
, attr
);
24029 if (!cu
->base_address
.has_value ())
24030 complaint (_("Location list used without "
24031 "specifying the CU base address."));
24033 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24034 ? dwarf2_loclist_block_index
24035 : dwarf2_loclist_index
);
24036 SYMBOL_LOCATION_BATON (sym
) = baton
;
24040 struct dwarf2_locexpr_baton
*baton
;
24042 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24043 baton
->per_objfile
= per_objfile
;
24044 baton
->per_cu
= cu
->per_cu
;
24045 gdb_assert (baton
->per_cu
);
24047 if (attr
->form_is_block ())
24049 /* Note that we're just copying the block's data pointer
24050 here, not the actual data. We're still pointing into the
24051 info_buffer for SYM's objfile; right now we never release
24052 that buffer, but when we do clean up properly this may
24054 struct dwarf_block
*block
= attr
->as_block ();
24055 baton
->size
= block
->size
;
24056 baton
->data
= block
->data
;
24060 dwarf2_invalid_attrib_class_complaint ("location description",
24061 sym
->natural_name ());
24065 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24066 ? dwarf2_locexpr_block_index
24067 : dwarf2_locexpr_index
);
24068 SYMBOL_LOCATION_BATON (sym
) = baton
;
24074 const comp_unit_head
*
24075 dwarf2_per_cu_data::get_header () const
24077 if (!m_header_read_in
)
24079 const gdb_byte
*info_ptr
24080 = this->section
->buffer
+ to_underlying (this->sect_off
);
24082 memset (&m_header
, 0, sizeof (m_header
));
24084 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24085 rcuh_kind::COMPILE
);
24094 dwarf2_per_cu_data::addr_size () const
24096 return this->get_header ()->addr_size
;
24102 dwarf2_per_cu_data::offset_size () const
24104 return this->get_header ()->offset_size
;
24110 dwarf2_per_cu_data::ref_addr_size () const
24112 const comp_unit_head
*header
= this->get_header ();
24114 if (header
->version
== 2)
24115 return header
->addr_size
;
24117 return header
->offset_size
;
24123 dwarf2_cu::addr_type () const
24125 struct objfile
*objfile
= this->per_objfile
->objfile
;
24126 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24127 struct type
*addr_type
= lookup_pointer_type (void_type
);
24128 int addr_size
= this->per_cu
->addr_size ();
24130 if (TYPE_LENGTH (addr_type
) == addr_size
)
24133 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24137 /* A helper function for dwarf2_find_containing_comp_unit that returns
24138 the index of the result, and that searches a vector. It will
24139 return a result even if the offset in question does not actually
24140 occur in any CU. This is separate so that it can be unit
24144 dwarf2_find_containing_comp_unit
24145 (sect_offset sect_off
,
24146 unsigned int offset_in_dwz
,
24147 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24152 high
= all_comp_units
.size () - 1;
24155 struct dwarf2_per_cu_data
*mid_cu
;
24156 int mid
= low
+ (high
- low
) / 2;
24158 mid_cu
= all_comp_units
[mid
];
24159 if (mid_cu
->is_dwz
> offset_in_dwz
24160 || (mid_cu
->is_dwz
== offset_in_dwz
24161 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24166 gdb_assert (low
== high
);
24170 /* Locate the .debug_info compilation unit from CU's objfile which contains
24171 the DIE at OFFSET. Raises an error on failure. */
24173 static struct dwarf2_per_cu_data
*
24174 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24175 unsigned int offset_in_dwz
,
24176 dwarf2_per_objfile
*per_objfile
)
24178 int low
= dwarf2_find_containing_comp_unit
24179 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24180 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
24182 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24184 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24185 error (_("Dwarf Error: could not find partial DIE containing "
24186 "offset %s [in module %s]"),
24187 sect_offset_str (sect_off
),
24188 bfd_get_filename (per_objfile
->objfile
->obfd
));
24190 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24192 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
24196 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24197 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24198 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24199 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24206 namespace selftests
{
24207 namespace find_containing_comp_unit
{
24212 struct dwarf2_per_cu_data one
{};
24213 struct dwarf2_per_cu_data two
{};
24214 struct dwarf2_per_cu_data three
{};
24215 struct dwarf2_per_cu_data four
{};
24218 two
.sect_off
= sect_offset (one
.length
);
24223 four
.sect_off
= sect_offset (three
.length
);
24227 std::vector
<dwarf2_per_cu_data
*> units
;
24228 units
.push_back (&one
);
24229 units
.push_back (&two
);
24230 units
.push_back (&three
);
24231 units
.push_back (&four
);
24235 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24236 SELF_CHECK (units
[result
] == &one
);
24237 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24238 SELF_CHECK (units
[result
] == &one
);
24239 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24240 SELF_CHECK (units
[result
] == &two
);
24242 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24243 SELF_CHECK (units
[result
] == &three
);
24244 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24245 SELF_CHECK (units
[result
] == &three
);
24246 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24247 SELF_CHECK (units
[result
] == &four
);
24253 #endif /* GDB_SELF_TEST */
24255 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
24257 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
24258 dwarf2_per_objfile
*per_objfile
)
24260 per_objfile (per_objfile
),
24262 has_loclist (false),
24263 checked_producer (false),
24264 producer_is_gxx_lt_4_6 (false),
24265 producer_is_gcc_lt_4_3 (false),
24266 producer_is_icc (false),
24267 producer_is_icc_lt_14 (false),
24268 producer_is_codewarrior (false),
24269 processing_has_namespace_info (false)
24273 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24276 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24277 enum language pretend_language
)
24279 struct attribute
*attr
;
24281 /* Set the language we're debugging. */
24282 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24283 if (attr
!= nullptr)
24284 set_cu_language (attr
->constant_value (0), cu
);
24287 cu
->language
= pretend_language
;
24288 cu
->language_defn
= language_def (cu
->language
);
24291 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24297 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24299 auto it
= m_dwarf2_cus
.find (per_cu
);
24300 if (it
== m_dwarf2_cus
.end ())
24309 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24311 gdb_assert (this->get_cu (per_cu
) == nullptr);
24313 m_dwarf2_cus
[per_cu
] = cu
;
24319 dwarf2_per_objfile::age_comp_units ()
24321 /* Start by clearing all marks. */
24322 for (auto pair
: m_dwarf2_cus
)
24323 pair
.second
->mark
= false;
24325 /* Traverse all CUs, mark them and their dependencies if used recently
24327 for (auto pair
: m_dwarf2_cus
)
24329 dwarf2_cu
*cu
= pair
.second
;
24332 if (cu
->last_used
<= dwarf_max_cache_age
)
24336 /* Delete all CUs still not marked. */
24337 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24339 dwarf2_cu
*cu
= it
->second
;
24344 it
= m_dwarf2_cus
.erase (it
);
24354 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24356 auto it
= m_dwarf2_cus
.find (per_cu
);
24357 if (it
== m_dwarf2_cus
.end ())
24362 m_dwarf2_cus
.erase (it
);
24365 dwarf2_per_objfile::~dwarf2_per_objfile ()
24370 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24371 We store these in a hash table separate from the DIEs, and preserve them
24372 when the DIEs are flushed out of cache.
24374 The CU "per_cu" pointer is needed because offset alone is not enough to
24375 uniquely identify the type. A file may have multiple .debug_types sections,
24376 or the type may come from a DWO file. Furthermore, while it's more logical
24377 to use per_cu->section+offset, with Fission the section with the data is in
24378 the DWO file but we don't know that section at the point we need it.
24379 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24380 because we can enter the lookup routine, get_die_type_at_offset, from
24381 outside this file, and thus won't necessarily have PER_CU->cu.
24382 Fortunately, PER_CU is stable for the life of the objfile. */
24384 struct dwarf2_per_cu_offset_and_type
24386 const struct dwarf2_per_cu_data
*per_cu
;
24387 sect_offset sect_off
;
24391 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24394 per_cu_offset_and_type_hash (const void *item
)
24396 const struct dwarf2_per_cu_offset_and_type
*ofs
24397 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24399 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24402 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24405 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24407 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24408 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24409 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24410 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24412 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24413 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24416 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24417 table if necessary. For convenience, return TYPE.
24419 The DIEs reading must have careful ordering to:
24420 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24421 reading current DIE.
24422 * Not trying to dereference contents of still incompletely read in types
24423 while reading in other DIEs.
24424 * Enable referencing still incompletely read in types just by a pointer to
24425 the type without accessing its fields.
24427 Therefore caller should follow these rules:
24428 * Try to fetch any prerequisite types we may need to build this DIE type
24429 before building the type and calling set_die_type.
24430 * After building type call set_die_type for current DIE as soon as
24431 possible before fetching more types to complete the current type.
24432 * Make the type as complete as possible before fetching more types. */
24434 static struct type
*
24435 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24437 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24438 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24439 struct objfile
*objfile
= per_objfile
->objfile
;
24440 struct attribute
*attr
;
24441 struct dynamic_prop prop
;
24443 /* For Ada types, make sure that the gnat-specific data is always
24444 initialized (if not already set). There are a few types where
24445 we should not be doing so, because the type-specific area is
24446 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24447 where the type-specific area is used to store the floatformat).
24448 But this is not a problem, because the gnat-specific information
24449 is actually not needed for these types. */
24450 if (need_gnat_info (cu
)
24451 && type
->code () != TYPE_CODE_FUNC
24452 && type
->code () != TYPE_CODE_FLT
24453 && type
->code () != TYPE_CODE_METHODPTR
24454 && type
->code () != TYPE_CODE_MEMBERPTR
24455 && type
->code () != TYPE_CODE_METHOD
24456 && !HAVE_GNAT_AUX_INFO (type
))
24457 INIT_GNAT_SPECIFIC (type
);
24459 /* Read DW_AT_allocated and set in type. */
24460 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24463 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24464 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24465 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24468 /* Read DW_AT_associated and set in type. */
24469 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24472 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24473 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24474 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24477 /* Read DW_AT_data_location and set in type. */
24478 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24479 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24480 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24482 if (per_objfile
->die_type_hash
== NULL
)
24483 per_objfile
->die_type_hash
24484 = htab_up (htab_create_alloc (127,
24485 per_cu_offset_and_type_hash
,
24486 per_cu_offset_and_type_eq
,
24487 NULL
, xcalloc
, xfree
));
24489 ofs
.per_cu
= cu
->per_cu
;
24490 ofs
.sect_off
= die
->sect_off
;
24492 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24493 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24495 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24496 sect_offset_str (die
->sect_off
));
24497 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24498 struct dwarf2_per_cu_offset_and_type
);
24503 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24504 or return NULL if the die does not have a saved type. */
24506 static struct type
*
24507 get_die_type_at_offset (sect_offset sect_off
,
24508 dwarf2_per_cu_data
*per_cu
,
24509 dwarf2_per_objfile
*per_objfile
)
24511 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24513 if (per_objfile
->die_type_hash
== NULL
)
24516 ofs
.per_cu
= per_cu
;
24517 ofs
.sect_off
= sect_off
;
24518 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24519 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24526 /* Look up the type for DIE in CU in die_type_hash,
24527 or return NULL if DIE does not have a saved type. */
24529 static struct type
*
24530 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24532 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24535 /* Add a dependence relationship from CU to REF_PER_CU. */
24538 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24539 struct dwarf2_per_cu_data
*ref_per_cu
)
24543 if (cu
->dependencies
== NULL
)
24545 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24546 NULL
, &cu
->comp_unit_obstack
,
24547 hashtab_obstack_allocate
,
24548 dummy_obstack_deallocate
);
24550 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24552 *slot
= ref_per_cu
;
24555 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24556 Set the mark field in every compilation unit in the
24557 cache that we must keep because we are keeping CU.
24559 DATA is the dwarf2_per_objfile object in which to look up CUs. */
24562 dwarf2_mark_helper (void **slot
, void *data
)
24564 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
24565 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
24566 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
24568 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24569 reading of the chain. As such dependencies remain valid it is not much
24570 useful to track and undo them during QUIT cleanups. */
24579 if (cu
->dependencies
!= nullptr)
24580 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
24585 /* Set the mark field in CU and in every other compilation unit in the
24586 cache that we must keep because we are keeping CU. */
24589 dwarf2_mark (struct dwarf2_cu
*cu
)
24596 if (cu
->dependencies
!= nullptr)
24597 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
24600 /* Trivial hash function for partial_die_info: the hash value of a DIE
24601 is its offset in .debug_info for this objfile. */
24604 partial_die_hash (const void *item
)
24606 const struct partial_die_info
*part_die
24607 = (const struct partial_die_info
*) item
;
24609 return to_underlying (part_die
->sect_off
);
24612 /* Trivial comparison function for partial_die_info structures: two DIEs
24613 are equal if they have the same offset. */
24616 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24618 const struct partial_die_info
*part_die_lhs
24619 = (const struct partial_die_info
*) item_lhs
;
24620 const struct partial_die_info
*part_die_rhs
24621 = (const struct partial_die_info
*) item_rhs
;
24623 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24626 struct cmd_list_element
*set_dwarf_cmdlist
;
24627 struct cmd_list_element
*show_dwarf_cmdlist
;
24630 show_check_physname (struct ui_file
*file
, int from_tty
,
24631 struct cmd_list_element
*c
, const char *value
)
24633 fprintf_filtered (file
,
24634 _("Whether to check \"physname\" is %s.\n"),
24638 void _initialize_dwarf2_read ();
24640 _initialize_dwarf2_read ()
24642 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24643 Set DWARF specific variables.\n\
24644 Configure DWARF variables such as the cache size."),
24645 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24646 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24648 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24649 Show DWARF specific variables.\n\
24650 Show DWARF variables such as the cache size."),
24651 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24652 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24654 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24655 &dwarf_max_cache_age
, _("\
24656 Set the upper bound on the age of cached DWARF compilation units."), _("\
24657 Show the upper bound on the age of cached DWARF compilation units."), _("\
24658 A higher limit means that cached compilation units will be stored\n\
24659 in memory longer, and more total memory will be used. Zero disables\n\
24660 caching, which can slow down startup."),
24662 show_dwarf_max_cache_age
,
24663 &set_dwarf_cmdlist
,
24664 &show_dwarf_cmdlist
);
24666 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24667 Set debugging of the DWARF reader."), _("\
24668 Show debugging of the DWARF reader."), _("\
24669 When enabled (non-zero), debugging messages are printed during DWARF\n\
24670 reading and symtab expansion. A value of 1 (one) provides basic\n\
24671 information. A value greater than 1 provides more verbose information."),
24674 &setdebuglist
, &showdebuglist
);
24676 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24677 Set debugging of the DWARF DIE reader."), _("\
24678 Show debugging of the DWARF DIE reader."), _("\
24679 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24680 The value is the maximum depth to print."),
24683 &setdebuglist
, &showdebuglist
);
24685 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24686 Set debugging of the dwarf line reader."), _("\
24687 Show debugging of the dwarf line reader."), _("\
24688 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24689 A value of 1 (one) provides basic information.\n\
24690 A value greater than 1 provides more verbose information."),
24693 &setdebuglist
, &showdebuglist
);
24695 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24696 Set cross-checking of \"physname\" code against demangler."), _("\
24697 Show cross-checking of \"physname\" code against demangler."), _("\
24698 When enabled, GDB's internal \"physname\" code is checked against\n\
24700 NULL
, show_check_physname
,
24701 &setdebuglist
, &showdebuglist
);
24703 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24704 no_class
, &use_deprecated_index_sections
, _("\
24705 Set whether to use deprecated gdb_index sections."), _("\
24706 Show whether to use deprecated gdb_index sections."), _("\
24707 When enabled, deprecated .gdb_index sections are used anyway.\n\
24708 Normally they are ignored either because of a missing feature or\n\
24709 performance issue.\n\
24710 Warning: This option must be enabled before gdb reads the file."),
24713 &setlist
, &showlist
);
24715 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24716 &dwarf2_locexpr_funcs
);
24717 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24718 &dwarf2_loclist_funcs
);
24720 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24721 &dwarf2_block_frame_base_locexpr_funcs
);
24722 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24723 &dwarf2_block_frame_base_loclist_funcs
);
24726 selftests::register_test ("dw2_expand_symtabs_matching",
24727 selftests::dw2_expand_symtabs_matching::run_test
);
24728 selftests::register_test ("dwarf2_find_containing_comp_unit",
24729 selftests::find_containing_comp_unit::run_test
);