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
*,
1307 const gdb_byte
*, bool *need_reprocess
);
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
,
1610 enum language pretend_language
);
1612 static void process_full_comp_unit (dwarf2_cu
*cu
,
1613 enum language pretend_language
);
1615 static void process_full_type_unit (dwarf2_cu
*cu
,
1616 enum language pretend_language
);
1618 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1619 struct dwarf2_per_cu_data
*);
1621 static void dwarf2_mark (struct dwarf2_cu
*);
1623 static struct type
*get_die_type_at_offset (sect_offset
,
1624 dwarf2_per_cu_data
*per_cu
,
1625 dwarf2_per_objfile
*per_objfile
);
1627 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1629 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1630 dwarf2_per_objfile
*per_objfile
,
1631 enum language pretend_language
);
1633 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1635 /* Class, the destructor of which frees all allocated queue entries. This
1636 will only have work to do if an error was thrown while processing the
1637 dwarf. If no error was thrown then the queue entries should have all
1638 been processed, and freed, as we went along. */
1640 class dwarf2_queue_guard
1643 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1644 : m_per_objfile (per_objfile
)
1648 /* Free any entries remaining on the queue. There should only be
1649 entries left if we hit an error while processing the dwarf. */
1650 ~dwarf2_queue_guard ()
1652 /* Ensure that no memory is allocated by the queue. */
1653 std::queue
<dwarf2_queue_item
> empty
;
1654 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1657 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1660 dwarf2_per_objfile
*m_per_objfile
;
1663 dwarf2_queue_item::~dwarf2_queue_item ()
1665 /* Anything still marked queued is likely to be in an
1666 inconsistent state, so discard it. */
1669 per_objfile
->remove_cu (per_cu
);
1674 /* The return type of find_file_and_directory. Note, the enclosed
1675 string pointers are only valid while this object is valid. */
1677 struct file_and_directory
1679 /* The filename. This is never NULL. */
1682 /* The compilation directory. NULL if not known. If we needed to
1683 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1684 points directly to the DW_AT_comp_dir string attribute owned by
1685 the obstack that owns the DIE. */
1686 const char *comp_dir
;
1688 /* If we needed to build a new string for comp_dir, this is what
1689 owns the storage. */
1690 std::string comp_dir_storage
;
1693 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1694 struct dwarf2_cu
*cu
);
1696 static htab_up
allocate_signatured_type_table ();
1698 static htab_up
allocate_dwo_unit_table ();
1700 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1701 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1702 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1704 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1706 static struct dwo_unit
*lookup_dwo_comp_unit
1707 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1708 ULONGEST signature
);
1710 static struct dwo_unit
*lookup_dwo_type_unit
1711 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1713 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1715 /* A unique pointer to a dwo_file. */
1717 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1719 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1721 static void check_producer (struct dwarf2_cu
*cu
);
1723 static void free_line_header_voidp (void *arg
);
1725 /* Various complaints about symbol reading that don't abort the process. */
1728 dwarf2_debug_line_missing_file_complaint (void)
1730 complaint (_(".debug_line section has line data without a file"));
1734 dwarf2_debug_line_missing_end_sequence_complaint (void)
1736 complaint (_(".debug_line section has line "
1737 "program sequence without an end"));
1741 dwarf2_complex_location_expr_complaint (void)
1743 complaint (_("location expression too complex"));
1747 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1750 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1755 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1757 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1761 /* Hash function for line_header_hash. */
1764 line_header_hash (const struct line_header
*ofs
)
1766 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1769 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1772 line_header_hash_voidp (const void *item
)
1774 const struct line_header
*ofs
= (const struct line_header
*) item
;
1776 return line_header_hash (ofs
);
1779 /* Equality function for line_header_hash. */
1782 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1784 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1785 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1787 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1788 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1793 /* See declaration. */
1795 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1798 can_copy (can_copy_
)
1801 names
= &dwarf2_elf_names
;
1803 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1804 locate_sections (obfd
, sec
, *names
);
1807 dwarf2_per_bfd::~dwarf2_per_bfd ()
1809 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1810 per_cu
->imported_symtabs_free ();
1812 for (signatured_type
*sig_type
: all_type_units
)
1813 sig_type
->per_cu
.imported_symtabs_free ();
1815 /* Everything else should be on this->obstack. */
1821 dwarf2_per_objfile::remove_all_cus ()
1823 for (auto pair
: m_dwarf2_cus
)
1826 m_dwarf2_cus
.clear ();
1829 /* A helper class that calls free_cached_comp_units on
1832 class free_cached_comp_units
1836 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1837 : m_per_objfile (per_objfile
)
1841 ~free_cached_comp_units ()
1843 m_per_objfile
->remove_all_cus ();
1846 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1850 dwarf2_per_objfile
*m_per_objfile
;
1856 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1858 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1860 return this->m_symtabs
[per_cu
->index
] != nullptr;
1866 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1868 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1870 return this->m_symtabs
[per_cu
->index
];
1876 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1877 compunit_symtab
*symtab
)
1879 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1880 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1882 this->m_symtabs
[per_cu
->index
] = symtab
;
1885 /* Try to locate the sections we need for DWARF 2 debugging
1886 information and return true if we have enough to do something.
1887 NAMES points to the dwarf2 section names, or is NULL if the standard
1888 ELF names are used. CAN_COPY is true for formats where symbol
1889 interposition is possible and so symbol values must follow copy
1890 relocation rules. */
1893 dwarf2_has_info (struct objfile
*objfile
,
1894 const struct dwarf2_debug_sections
*names
,
1897 if (objfile
->flags
& OBJF_READNEVER
)
1900 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1902 if (per_objfile
== NULL
)
1904 dwarf2_per_bfd
*per_bfd
;
1906 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1907 doesn't require relocations and if there aren't partial symbols
1908 from some other reader. */
1909 if (!objfile_has_partial_symbols (objfile
)
1910 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1912 /* See if one has been created for this BFD yet. */
1913 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1915 if (per_bfd
== nullptr)
1917 /* No, create it now. */
1918 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1919 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1924 /* No sharing possible, create one specifically for this objfile. */
1925 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1926 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1929 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1932 return (!per_objfile
->per_bfd
->info
.is_virtual
1933 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1934 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1935 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1938 /* When loading sections, we look either for uncompressed section or for
1939 compressed section names. */
1942 section_is_p (const char *section_name
,
1943 const struct dwarf2_section_names
*names
)
1945 if (names
->normal
!= NULL
1946 && strcmp (section_name
, names
->normal
) == 0)
1948 if (names
->compressed
!= NULL
1949 && strcmp (section_name
, names
->compressed
) == 0)
1954 /* See declaration. */
1957 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1958 const dwarf2_debug_sections
&names
)
1960 flagword aflag
= bfd_section_flags (sectp
);
1962 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1965 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1966 > bfd_get_file_size (abfd
))
1968 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1969 warning (_("Discarding section %s which has a section size (%s"
1970 ") larger than the file size [in module %s]"),
1971 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1972 bfd_get_filename (abfd
));
1974 else if (section_is_p (sectp
->name
, &names
.info
))
1976 this->info
.s
.section
= sectp
;
1977 this->info
.size
= bfd_section_size (sectp
);
1979 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1981 this->abbrev
.s
.section
= sectp
;
1982 this->abbrev
.size
= bfd_section_size (sectp
);
1984 else if (section_is_p (sectp
->name
, &names
.line
))
1986 this->line
.s
.section
= sectp
;
1987 this->line
.size
= bfd_section_size (sectp
);
1989 else if (section_is_p (sectp
->name
, &names
.loc
))
1991 this->loc
.s
.section
= sectp
;
1992 this->loc
.size
= bfd_section_size (sectp
);
1994 else if (section_is_p (sectp
->name
, &names
.loclists
))
1996 this->loclists
.s
.section
= sectp
;
1997 this->loclists
.size
= bfd_section_size (sectp
);
1999 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2001 this->macinfo
.s
.section
= sectp
;
2002 this->macinfo
.size
= bfd_section_size (sectp
);
2004 else if (section_is_p (sectp
->name
, &names
.macro
))
2006 this->macro
.s
.section
= sectp
;
2007 this->macro
.size
= bfd_section_size (sectp
);
2009 else if (section_is_p (sectp
->name
, &names
.str
))
2011 this->str
.s
.section
= sectp
;
2012 this->str
.size
= bfd_section_size (sectp
);
2014 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2016 this->str_offsets
.s
.section
= sectp
;
2017 this->str_offsets
.size
= bfd_section_size (sectp
);
2019 else if (section_is_p (sectp
->name
, &names
.line_str
))
2021 this->line_str
.s
.section
= sectp
;
2022 this->line_str
.size
= bfd_section_size (sectp
);
2024 else if (section_is_p (sectp
->name
, &names
.addr
))
2026 this->addr
.s
.section
= sectp
;
2027 this->addr
.size
= bfd_section_size (sectp
);
2029 else if (section_is_p (sectp
->name
, &names
.frame
))
2031 this->frame
.s
.section
= sectp
;
2032 this->frame
.size
= bfd_section_size (sectp
);
2034 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2036 this->eh_frame
.s
.section
= sectp
;
2037 this->eh_frame
.size
= bfd_section_size (sectp
);
2039 else if (section_is_p (sectp
->name
, &names
.ranges
))
2041 this->ranges
.s
.section
= sectp
;
2042 this->ranges
.size
= bfd_section_size (sectp
);
2044 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2046 this->rnglists
.s
.section
= sectp
;
2047 this->rnglists
.size
= bfd_section_size (sectp
);
2049 else if (section_is_p (sectp
->name
, &names
.types
))
2051 struct dwarf2_section_info type_section
;
2053 memset (&type_section
, 0, sizeof (type_section
));
2054 type_section
.s
.section
= sectp
;
2055 type_section
.size
= bfd_section_size (sectp
);
2057 this->types
.push_back (type_section
);
2059 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2061 this->gdb_index
.s
.section
= sectp
;
2062 this->gdb_index
.size
= bfd_section_size (sectp
);
2064 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2066 this->debug_names
.s
.section
= sectp
;
2067 this->debug_names
.size
= bfd_section_size (sectp
);
2069 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2071 this->debug_aranges
.s
.section
= sectp
;
2072 this->debug_aranges
.size
= bfd_section_size (sectp
);
2075 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2076 && bfd_section_vma (sectp
) == 0)
2077 this->has_section_at_zero
= true;
2080 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2084 dwarf2_get_section_info (struct objfile
*objfile
,
2085 enum dwarf2_section_enum sect
,
2086 asection
**sectp
, const gdb_byte
**bufp
,
2087 bfd_size_type
*sizep
)
2089 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2090 struct dwarf2_section_info
*info
;
2092 /* We may see an objfile without any DWARF, in which case we just
2094 if (per_objfile
== NULL
)
2103 case DWARF2_DEBUG_FRAME
:
2104 info
= &per_objfile
->per_bfd
->frame
;
2106 case DWARF2_EH_FRAME
:
2107 info
= &per_objfile
->per_bfd
->eh_frame
;
2110 gdb_assert_not_reached ("unexpected section");
2113 info
->read (objfile
);
2115 *sectp
= info
->get_bfd_section ();
2116 *bufp
= info
->buffer
;
2117 *sizep
= info
->size
;
2120 /* A helper function to find the sections for a .dwz file. */
2123 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, dwz_file
*dwz_file
)
2125 /* Note that we only support the standard ELF names, because .dwz
2126 is ELF-only (at the time of writing). */
2127 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2129 dwz_file
->abbrev
.s
.section
= sectp
;
2130 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2132 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2134 dwz_file
->info
.s
.section
= sectp
;
2135 dwz_file
->info
.size
= bfd_section_size (sectp
);
2137 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2139 dwz_file
->str
.s
.section
= sectp
;
2140 dwz_file
->str
.size
= bfd_section_size (sectp
);
2142 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2144 dwz_file
->line
.s
.section
= sectp
;
2145 dwz_file
->line
.size
= bfd_section_size (sectp
);
2147 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2149 dwz_file
->macro
.s
.section
= sectp
;
2150 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2152 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2154 dwz_file
->gdb_index
.s
.section
= sectp
;
2155 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2157 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2159 dwz_file
->debug_names
.s
.section
= sectp
;
2160 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2164 /* See dwarf2read.h. */
2167 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2169 const char *filename
;
2170 bfd_size_type buildid_len_arg
;
2174 if (per_bfd
->dwz_file
!= NULL
)
2175 return per_bfd
->dwz_file
.get ();
2177 bfd_set_error (bfd_error_no_error
);
2178 gdb::unique_xmalloc_ptr
<char> data
2179 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2180 &buildid_len_arg
, &buildid
));
2183 if (bfd_get_error () == bfd_error_no_error
)
2185 error (_("could not read '.gnu_debugaltlink' section: %s"),
2186 bfd_errmsg (bfd_get_error ()));
2189 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2191 buildid_len
= (size_t) buildid_len_arg
;
2193 filename
= data
.get ();
2195 std::string abs_storage
;
2196 if (!IS_ABSOLUTE_PATH (filename
))
2198 gdb::unique_xmalloc_ptr
<char> abs
2199 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2201 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2202 filename
= abs_storage
.c_str ();
2205 /* First try the file name given in the section. If that doesn't
2206 work, try to use the build-id instead. */
2207 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
));
2208 if (dwz_bfd
!= NULL
)
2210 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2211 dwz_bfd
.reset (nullptr);
2214 if (dwz_bfd
== NULL
)
2215 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2217 if (dwz_bfd
== nullptr)
2219 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2220 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2222 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2229 /* File successfully retrieved from server. */
2230 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2232 if (dwz_bfd
== nullptr)
2233 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2234 alt_filename
.get ());
2235 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2236 dwz_bfd
.reset (nullptr);
2240 if (dwz_bfd
== NULL
)
2241 error (_("could not find '.gnu_debugaltlink' file for %s"),
2242 bfd_get_filename (per_bfd
->obfd
));
2244 std::unique_ptr
<struct dwz_file
> result
2245 (new struct dwz_file (std::move (dwz_bfd
)));
2247 for (asection
*sec
: gdb_bfd_sections (result
->dwz_bfd
))
2248 locate_dwz_sections (result
->dwz_bfd
.get (), sec
, result
.get ());
2250 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2251 per_bfd
->dwz_file
= std::move (result
);
2252 return per_bfd
->dwz_file
.get ();
2255 /* DWARF quick_symbols_functions support. */
2257 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2258 unique line tables, so we maintain a separate table of all .debug_line
2259 derived entries to support the sharing.
2260 All the quick functions need is the list of file names. We discard the
2261 line_header when we're done and don't need to record it here. */
2262 struct quick_file_names
2264 /* The data used to construct the hash key. */
2265 struct stmt_list_hash hash
;
2267 /* The number of entries in file_names, real_names. */
2268 unsigned int num_file_names
;
2270 /* The file names from the line table, after being run through
2272 const char **file_names
;
2274 /* The file names from the line table after being run through
2275 gdb_realpath. These are computed lazily. */
2276 const char **real_names
;
2279 /* When using the index (and thus not using psymtabs), each CU has an
2280 object of this type. This is used to hold information needed by
2281 the various "quick" methods. */
2282 struct dwarf2_per_cu_quick_data
2284 /* The file table. This can be NULL if there was no file table
2285 or it's currently not read in.
2286 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2287 struct quick_file_names
*file_names
;
2289 /* A temporary mark bit used when iterating over all CUs in
2290 expand_symtabs_matching. */
2291 unsigned int mark
: 1;
2293 /* True if we've tried to read the file table and found there isn't one.
2294 There will be no point in trying to read it again next time. */
2295 unsigned int no_file_data
: 1;
2298 /* Utility hash function for a stmt_list_hash. */
2301 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2305 if (stmt_list_hash
->dwo_unit
!= NULL
)
2306 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2307 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2311 /* Utility equality function for a stmt_list_hash. */
2314 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2315 const struct stmt_list_hash
*rhs
)
2317 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2319 if (lhs
->dwo_unit
!= NULL
2320 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2323 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2326 /* Hash function for a quick_file_names. */
2329 hash_file_name_entry (const void *e
)
2331 const struct quick_file_names
*file_data
2332 = (const struct quick_file_names
*) e
;
2334 return hash_stmt_list_entry (&file_data
->hash
);
2337 /* Equality function for a quick_file_names. */
2340 eq_file_name_entry (const void *a
, const void *b
)
2342 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2343 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2345 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2348 /* Delete function for a quick_file_names. */
2351 delete_file_name_entry (void *e
)
2353 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2356 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2358 xfree ((void*) file_data
->file_names
[i
]);
2359 if (file_data
->real_names
)
2360 xfree ((void*) file_data
->real_names
[i
]);
2363 /* The space for the struct itself lives on the obstack, so we don't
2367 /* Create a quick_file_names hash table. */
2370 create_quick_file_names_table (unsigned int nr_initial_entries
)
2372 return htab_up (htab_create_alloc (nr_initial_entries
,
2373 hash_file_name_entry
, eq_file_name_entry
,
2374 delete_file_name_entry
, xcalloc
, xfree
));
2377 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2378 function is unrelated to symtabs, symtab would have to be created afterwards.
2379 You should call age_cached_comp_units after processing the CU. */
2382 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2385 if (per_cu
->is_debug_types
)
2386 load_full_type_unit (per_cu
, per_objfile
);
2388 load_full_comp_unit (per_cu
, per_objfile
, skip_partial
, language_minimal
);
2390 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2392 return nullptr; /* Dummy CU. */
2394 dwarf2_find_base_address (cu
->dies
, cu
);
2399 /* Read in the symbols for PER_CU in the context of DWARF"_PER_OBJFILE. */
2402 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2403 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2405 /* Skip type_unit_groups, reading the type units they contain
2406 is handled elsewhere. */
2407 if (per_cu
->type_unit_group_p ())
2410 /* The destructor of dwarf2_queue_guard frees any entries left on
2411 the queue. After this point we're guaranteed to leave this function
2412 with the dwarf queue empty. */
2413 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2415 if (!per_objfile
->symtab_set_p (per_cu
))
2417 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2418 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2420 /* If we just loaded a CU from a DWO, and we're working with an index
2421 that may badly handle TUs, load all the TUs in that DWO as well.
2422 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2423 if (!per_cu
->is_debug_types
2425 && cu
->dwo_unit
!= NULL
2426 && per_objfile
->per_bfd
->index_table
!= NULL
2427 && per_objfile
->per_bfd
->index_table
->version
<= 7
2428 /* DWP files aren't supported yet. */
2429 && get_dwp_file (per_objfile
) == NULL
)
2430 queue_and_load_all_dwo_tus (cu
);
2433 process_queue (per_objfile
);
2435 /* Age the cache, releasing compilation units that have not
2436 been used recently. */
2437 per_objfile
->age_comp_units ();
2440 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2441 the per-objfile for which this symtab is instantiated.
2443 Returns the resulting symbol table. */
2445 static struct compunit_symtab
*
2446 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2447 dwarf2_per_objfile
*per_objfile
,
2450 gdb_assert (per_objfile
->per_bfd
->using_index
);
2452 if (!per_objfile
->symtab_set_p (per_cu
))
2454 free_cached_comp_units
freer (per_objfile
);
2455 scoped_restore decrementer
= increment_reading_symtab ();
2456 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2457 process_cu_includes (per_objfile
);
2460 return per_objfile
->get_symtab (per_cu
);
2463 /* See declaration. */
2465 dwarf2_per_cu_data
*
2466 dwarf2_per_bfd::get_cutu (int index
)
2468 if (index
>= this->all_comp_units
.size ())
2470 index
-= this->all_comp_units
.size ();
2471 gdb_assert (index
< this->all_type_units
.size ());
2472 return &this->all_type_units
[index
]->per_cu
;
2475 return this->all_comp_units
[index
];
2478 /* See declaration. */
2480 dwarf2_per_cu_data
*
2481 dwarf2_per_bfd::get_cu (int index
)
2483 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2485 return this->all_comp_units
[index
];
2488 /* See declaration. */
2491 dwarf2_per_bfd::get_tu (int index
)
2493 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2495 return this->all_type_units
[index
];
2500 dwarf2_per_cu_data
*
2501 dwarf2_per_bfd::allocate_per_cu ()
2503 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2504 result
->per_bfd
= this;
2505 result
->index
= m_num_psymtabs
++;
2512 dwarf2_per_bfd::allocate_signatured_type ()
2514 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2515 result
->per_cu
.per_bfd
= this;
2516 result
->per_cu
.index
= m_num_psymtabs
++;
2520 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2521 obstack, and constructed with the specified field values. */
2523 static dwarf2_per_cu_data
*
2524 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2525 struct dwarf2_section_info
*section
,
2527 sect_offset sect_off
, ULONGEST length
)
2529 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2530 the_cu
->sect_off
= sect_off
;
2531 the_cu
->length
= length
;
2532 the_cu
->section
= section
;
2533 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2534 struct dwarf2_per_cu_quick_data
);
2535 the_cu
->is_dwz
= is_dwz
;
2539 /* A helper for create_cus_from_index that handles a given list of
2543 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2544 const gdb_byte
*cu_list
, offset_type n_elements
,
2545 struct dwarf2_section_info
*section
,
2548 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2550 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2552 sect_offset sect_off
2553 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2554 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2557 dwarf2_per_cu_data
*per_cu
2558 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2560 per_bfd
->all_comp_units
.push_back (per_cu
);
2564 /* Read the CU list from the mapped index, and use it to create all
2565 the CU objects for PER_BFD. */
2568 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2569 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2570 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2572 gdb_assert (per_bfd
->all_comp_units
.empty ());
2573 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2575 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2578 if (dwz_elements
== 0)
2581 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2582 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2586 /* Create the signatured type hash table from the index. */
2589 create_signatured_type_table_from_index
2590 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2591 const gdb_byte
*bytes
, offset_type elements
)
2593 gdb_assert (per_bfd
->all_type_units
.empty ());
2594 per_bfd
->all_type_units
.reserve (elements
/ 3);
2596 htab_up sig_types_hash
= allocate_signatured_type_table ();
2598 for (offset_type i
= 0; i
< elements
; i
+= 3)
2600 struct signatured_type
*sig_type
;
2603 cu_offset type_offset_in_tu
;
2605 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2606 sect_offset sect_off
2607 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2609 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2611 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2614 sig_type
= per_bfd
->allocate_signatured_type ();
2615 sig_type
->signature
= signature
;
2616 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2617 sig_type
->per_cu
.is_debug_types
= 1;
2618 sig_type
->per_cu
.section
= section
;
2619 sig_type
->per_cu
.sect_off
= sect_off
;
2620 sig_type
->per_cu
.v
.quick
2621 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2622 struct dwarf2_per_cu_quick_data
);
2624 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2627 per_bfd
->all_type_units
.push_back (sig_type
);
2630 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2633 /* Create the signatured type hash table from .debug_names. */
2636 create_signatured_type_table_from_debug_names
2637 (dwarf2_per_objfile
*per_objfile
,
2638 const mapped_debug_names
&map
,
2639 struct dwarf2_section_info
*section
,
2640 struct dwarf2_section_info
*abbrev_section
)
2642 struct objfile
*objfile
= per_objfile
->objfile
;
2644 section
->read (objfile
);
2645 abbrev_section
->read (objfile
);
2647 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2648 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2650 htab_up sig_types_hash
= allocate_signatured_type_table ();
2652 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2654 struct signatured_type
*sig_type
;
2657 sect_offset sect_off
2658 = (sect_offset
) (extract_unsigned_integer
2659 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2661 map
.dwarf5_byte_order
));
2663 comp_unit_head cu_header
;
2664 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2666 section
->buffer
+ to_underlying (sect_off
),
2669 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2670 sig_type
->signature
= cu_header
.signature
;
2671 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2672 sig_type
->per_cu
.is_debug_types
= 1;
2673 sig_type
->per_cu
.section
= section
;
2674 sig_type
->per_cu
.sect_off
= sect_off
;
2675 sig_type
->per_cu
.v
.quick
2676 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2677 struct dwarf2_per_cu_quick_data
);
2679 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2682 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2685 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2688 /* Read the address map data from the mapped index, and use it to
2689 populate the objfile's psymtabs_addrmap. */
2692 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2693 struct mapped_index
*index
)
2695 struct objfile
*objfile
= per_objfile
->objfile
;
2696 struct gdbarch
*gdbarch
= objfile
->arch ();
2697 const gdb_byte
*iter
, *end
;
2698 struct addrmap
*mutable_map
;
2701 auto_obstack temp_obstack
;
2703 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2705 iter
= index
->address_table
.data ();
2706 end
= iter
+ index
->address_table
.size ();
2708 baseaddr
= objfile
->text_section_offset ();
2712 ULONGEST hi
, lo
, cu_index
;
2713 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2715 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2717 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2722 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2723 hex_string (lo
), hex_string (hi
));
2727 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2729 complaint (_(".gdb_index address table has invalid CU number %u"),
2730 (unsigned) cu_index
);
2734 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2735 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2736 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2737 per_objfile
->per_bfd
->get_cu (cu_index
));
2740 objfile
->partial_symtabs
->psymtabs_addrmap
2741 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2744 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2745 populate the objfile's psymtabs_addrmap. */
2748 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2749 struct dwarf2_section_info
*section
)
2751 struct objfile
*objfile
= per_objfile
->objfile
;
2752 bfd
*abfd
= objfile
->obfd
;
2753 struct gdbarch
*gdbarch
= objfile
->arch ();
2754 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2756 auto_obstack temp_obstack
;
2757 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2759 std::unordered_map
<sect_offset
,
2760 dwarf2_per_cu_data
*,
2761 gdb::hash_enum
<sect_offset
>>
2762 debug_info_offset_to_per_cu
;
2763 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2765 const auto insertpair
2766 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2767 if (!insertpair
.second
)
2769 warning (_("Section .debug_aranges in %s has duplicate "
2770 "debug_info_offset %s, ignoring .debug_aranges."),
2771 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2776 section
->read (objfile
);
2778 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2780 const gdb_byte
*addr
= section
->buffer
;
2782 while (addr
< section
->buffer
+ section
->size
)
2784 const gdb_byte
*const entry_addr
= addr
;
2785 unsigned int bytes_read
;
2787 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2791 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2792 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2793 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2794 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2796 warning (_("Section .debug_aranges in %s entry at offset %s "
2797 "length %s exceeds section length %s, "
2798 "ignoring .debug_aranges."),
2799 objfile_name (objfile
),
2800 plongest (entry_addr
- section
->buffer
),
2801 plongest (bytes_read
+ entry_length
),
2802 pulongest (section
->size
));
2806 /* The version number. */
2807 const uint16_t version
= read_2_bytes (abfd
, addr
);
2811 warning (_("Section .debug_aranges in %s entry at offset %s "
2812 "has unsupported version %d, ignoring .debug_aranges."),
2813 objfile_name (objfile
),
2814 plongest (entry_addr
- section
->buffer
), version
);
2818 const uint64_t debug_info_offset
2819 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2820 addr
+= offset_size
;
2821 const auto per_cu_it
2822 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2823 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2825 warning (_("Section .debug_aranges in %s entry at offset %s "
2826 "debug_info_offset %s does not exists, "
2827 "ignoring .debug_aranges."),
2828 objfile_name (objfile
),
2829 plongest (entry_addr
- section
->buffer
),
2830 pulongest (debug_info_offset
));
2833 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2835 const uint8_t address_size
= *addr
++;
2836 if (address_size
< 1 || address_size
> 8)
2838 warning (_("Section .debug_aranges in %s entry at offset %s "
2839 "address_size %u is invalid, ignoring .debug_aranges."),
2840 objfile_name (objfile
),
2841 plongest (entry_addr
- section
->buffer
), address_size
);
2845 const uint8_t segment_selector_size
= *addr
++;
2846 if (segment_selector_size
!= 0)
2848 warning (_("Section .debug_aranges in %s entry at offset %s "
2849 "segment_selector_size %u is not supported, "
2850 "ignoring .debug_aranges."),
2851 objfile_name (objfile
),
2852 plongest (entry_addr
- section
->buffer
),
2853 segment_selector_size
);
2857 /* Must pad to an alignment boundary that is twice the address
2858 size. It is undocumented by the DWARF standard but GCC does
2860 for (size_t padding
= ((-(addr
- section
->buffer
))
2861 & (2 * address_size
- 1));
2862 padding
> 0; padding
--)
2865 warning (_("Section .debug_aranges in %s entry at offset %s "
2866 "padding is not zero, ignoring .debug_aranges."),
2867 objfile_name (objfile
),
2868 plongest (entry_addr
- section
->buffer
));
2874 if (addr
+ 2 * address_size
> entry_end
)
2876 warning (_("Section .debug_aranges in %s entry at offset %s "
2877 "address list is not properly terminated, "
2878 "ignoring .debug_aranges."),
2879 objfile_name (objfile
),
2880 plongest (entry_addr
- section
->buffer
));
2883 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2885 addr
+= address_size
;
2886 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2888 addr
+= address_size
;
2889 if (start
== 0 && length
== 0)
2891 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
2893 /* Symbol was eliminated due to a COMDAT group. */
2896 ULONGEST end
= start
+ length
;
2897 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2899 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2901 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2905 objfile
->partial_symtabs
->psymtabs_addrmap
2906 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2909 /* Find a slot in the mapped index INDEX for the object named NAME.
2910 If NAME is found, set *VEC_OUT to point to the CU vector in the
2911 constant pool and return true. If NAME cannot be found, return
2915 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2916 offset_type
**vec_out
)
2919 offset_type slot
, step
;
2920 int (*cmp
) (const char *, const char *);
2922 gdb::unique_xmalloc_ptr
<char> without_params
;
2923 if (current_language
->la_language
== language_cplus
2924 || current_language
->la_language
== language_fortran
2925 || current_language
->la_language
== language_d
)
2927 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2930 if (strchr (name
, '(') != NULL
)
2932 without_params
= cp_remove_params (name
);
2934 if (without_params
!= NULL
)
2935 name
= without_params
.get ();
2939 /* Index version 4 did not support case insensitive searches. But the
2940 indices for case insensitive languages are built in lowercase, therefore
2941 simulate our NAME being searched is also lowercased. */
2942 hash
= mapped_index_string_hash ((index
->version
== 4
2943 && case_sensitivity
== case_sensitive_off
2944 ? 5 : index
->version
),
2947 slot
= hash
& (index
->symbol_table
.size () - 1);
2948 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2949 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2955 const auto &bucket
= index
->symbol_table
[slot
];
2956 if (bucket
.name
== 0 && bucket
.vec
== 0)
2959 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2960 if (!cmp (name
, str
))
2962 *vec_out
= (offset_type
*) (index
->constant_pool
2963 + MAYBE_SWAP (bucket
.vec
));
2967 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2971 /* A helper function that reads the .gdb_index from BUFFER and fills
2972 in MAP. FILENAME is the name of the file containing the data;
2973 it is used for error reporting. DEPRECATED_OK is true if it is
2974 ok to use deprecated sections.
2976 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2977 out parameters that are filled in with information about the CU and
2978 TU lists in the section.
2980 Returns true if all went well, false otherwise. */
2983 read_gdb_index_from_buffer (const char *filename
,
2985 gdb::array_view
<const gdb_byte
> buffer
,
2986 struct mapped_index
*map
,
2987 const gdb_byte
**cu_list
,
2988 offset_type
*cu_list_elements
,
2989 const gdb_byte
**types_list
,
2990 offset_type
*types_list_elements
)
2992 const gdb_byte
*addr
= &buffer
[0];
2994 /* Version check. */
2995 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2996 /* Versions earlier than 3 emitted every copy of a psymbol. This
2997 causes the index to behave very poorly for certain requests. Version 3
2998 contained incomplete addrmap. So, it seems better to just ignore such
3002 static int warning_printed
= 0;
3003 if (!warning_printed
)
3005 warning (_("Skipping obsolete .gdb_index section in %s."),
3007 warning_printed
= 1;
3011 /* Index version 4 uses a different hash function than index version
3014 Versions earlier than 6 did not emit psymbols for inlined
3015 functions. Using these files will cause GDB not to be able to
3016 set breakpoints on inlined functions by name, so we ignore these
3017 indices unless the user has done
3018 "set use-deprecated-index-sections on". */
3019 if (version
< 6 && !deprecated_ok
)
3021 static int warning_printed
= 0;
3022 if (!warning_printed
)
3025 Skipping deprecated .gdb_index section in %s.\n\
3026 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3027 to use the section anyway."),
3029 warning_printed
= 1;
3033 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3034 of the TU (for symbols coming from TUs),
3035 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3036 Plus gold-generated indices can have duplicate entries for global symbols,
3037 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3038 These are just performance bugs, and we can't distinguish gdb-generated
3039 indices from gold-generated ones, so issue no warning here. */
3041 /* Indexes with higher version than the one supported by GDB may be no
3042 longer backward compatible. */
3046 map
->version
= version
;
3048 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3051 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3052 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3056 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3057 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3058 - MAYBE_SWAP (metadata
[i
]))
3062 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3063 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3065 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3068 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3069 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3071 = gdb::array_view
<mapped_index::symbol_table_slot
>
3072 ((mapped_index::symbol_table_slot
*) symbol_table
,
3073 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3076 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3081 /* Callback types for dwarf2_read_gdb_index. */
3083 typedef gdb::function_view
3084 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3085 get_gdb_index_contents_ftype
;
3086 typedef gdb::function_view
3087 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3088 get_gdb_index_contents_dwz_ftype
;
3090 /* Read .gdb_index. If everything went ok, initialize the "quick"
3091 elements of all the CUs and return 1. Otherwise, return 0. */
3094 dwarf2_read_gdb_index
3095 (dwarf2_per_objfile
*per_objfile
,
3096 get_gdb_index_contents_ftype get_gdb_index_contents
,
3097 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3099 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3100 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3101 struct dwz_file
*dwz
;
3102 struct objfile
*objfile
= per_objfile
->objfile
;
3103 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3105 gdb::array_view
<const gdb_byte
> main_index_contents
3106 = get_gdb_index_contents (objfile
, per_bfd
);
3108 if (main_index_contents
.empty ())
3111 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3112 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3113 use_deprecated_index_sections
,
3114 main_index_contents
, map
.get (), &cu_list
,
3115 &cu_list_elements
, &types_list
,
3116 &types_list_elements
))
3119 /* Don't use the index if it's empty. */
3120 if (map
->symbol_table
.empty ())
3123 /* If there is a .dwz file, read it so we can get its CU list as
3125 dwz
= dwarf2_get_dwz_file (per_bfd
);
3128 struct mapped_index dwz_map
;
3129 const gdb_byte
*dwz_types_ignore
;
3130 offset_type dwz_types_elements_ignore
;
3132 gdb::array_view
<const gdb_byte
> dwz_index_content
3133 = get_gdb_index_contents_dwz (objfile
, dwz
);
3135 if (dwz_index_content
.empty ())
3138 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3139 1, dwz_index_content
, &dwz_map
,
3140 &dwz_list
, &dwz_list_elements
,
3142 &dwz_types_elements_ignore
))
3144 warning (_("could not read '.gdb_index' section from %s; skipping"),
3145 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3150 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3153 if (types_list_elements
)
3155 /* We can only handle a single .debug_types when we have an
3157 if (per_bfd
->types
.size () != 1)
3160 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3162 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3163 types_list_elements
);
3166 create_addrmap_from_index (per_objfile
, map
.get ());
3168 per_bfd
->index_table
= std::move (map
);
3169 per_bfd
->using_index
= 1;
3170 per_bfd
->quick_file_names_table
=
3171 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3173 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3174 objfiles using the same BFD. */
3175 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3176 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3181 /* die_reader_func for dw2_get_file_names. */
3184 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3185 const gdb_byte
*info_ptr
,
3186 struct die_info
*comp_unit_die
)
3188 struct dwarf2_cu
*cu
= reader
->cu
;
3189 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3190 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3191 struct dwarf2_per_cu_data
*lh_cu
;
3192 struct attribute
*attr
;
3194 struct quick_file_names
*qfn
;
3196 gdb_assert (! this_cu
->is_debug_types
);
3198 /* Our callers never want to match partial units -- instead they
3199 will match the enclosing full CU. */
3200 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3202 this_cu
->v
.quick
->no_file_data
= 1;
3210 sect_offset line_offset
{};
3212 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3213 if (attr
!= nullptr)
3215 struct quick_file_names find_entry
;
3217 line_offset
= (sect_offset
) DW_UNSND (attr
);
3219 /* We may have already read in this line header (TU line header sharing).
3220 If we have we're done. */
3221 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3222 find_entry
.hash
.line_sect_off
= line_offset
;
3223 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3224 &find_entry
, INSERT
);
3227 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3231 lh
= dwarf_decode_line_header (line_offset
, cu
);
3235 lh_cu
->v
.quick
->no_file_data
= 1;
3239 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3240 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3241 qfn
->hash
.line_sect_off
= line_offset
;
3242 gdb_assert (slot
!= NULL
);
3245 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3248 if (strcmp (fnd
.name
, "<unknown>") != 0)
3251 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3253 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3254 qfn
->num_file_names
);
3256 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3257 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3258 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3259 fnd
.comp_dir
).release ();
3260 qfn
->real_names
= NULL
;
3262 lh_cu
->v
.quick
->file_names
= qfn
;
3265 /* A helper for the "quick" functions which attempts to read the line
3266 table for THIS_CU. */
3268 static struct quick_file_names
*
3269 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3270 dwarf2_per_objfile
*per_objfile
)
3272 /* This should never be called for TUs. */
3273 gdb_assert (! this_cu
->is_debug_types
);
3274 /* Nor type unit groups. */
3275 gdb_assert (! this_cu
->type_unit_group_p ());
3277 if (this_cu
->v
.quick
->file_names
!= NULL
)
3278 return this_cu
->v
.quick
->file_names
;
3279 /* If we know there is no line data, no point in looking again. */
3280 if (this_cu
->v
.quick
->no_file_data
)
3283 cutu_reader
reader (this_cu
, per_objfile
);
3284 if (!reader
.dummy_p
)
3285 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3287 if (this_cu
->v
.quick
->no_file_data
)
3289 return this_cu
->v
.quick
->file_names
;
3292 /* A helper for the "quick" functions which computes and caches the
3293 real path for a given file name from the line table. */
3296 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3297 struct quick_file_names
*qfn
, int index
)
3299 if (qfn
->real_names
== NULL
)
3300 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3301 qfn
->num_file_names
, const char *);
3303 if (qfn
->real_names
[index
] == NULL
)
3304 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3306 return qfn
->real_names
[index
];
3309 static struct symtab
*
3310 dw2_find_last_source_symtab (struct objfile
*objfile
)
3312 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3313 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3314 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3319 return compunit_primary_filetab (cust
);
3322 /* Traversal function for dw2_forget_cached_source_info. */
3325 dw2_free_cached_file_names (void **slot
, void *info
)
3327 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3329 if (file_data
->real_names
)
3333 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3335 xfree ((void*) file_data
->real_names
[i
]);
3336 file_data
->real_names
[i
] = NULL
;
3344 dw2_forget_cached_source_info (struct objfile
*objfile
)
3346 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3348 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3349 dw2_free_cached_file_names
, NULL
);
3352 /* Helper function for dw2_map_symtabs_matching_filename that expands
3353 the symtabs and calls the iterator. */
3356 dw2_map_expand_apply (struct objfile
*objfile
,
3357 struct dwarf2_per_cu_data
*per_cu
,
3358 const char *name
, const char *real_path
,
3359 gdb::function_view
<bool (symtab
*)> callback
)
3361 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3363 /* Don't visit already-expanded CUs. */
3364 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3365 if (per_objfile
->symtab_set_p (per_cu
))
3368 /* This may expand more than one symtab, and we want to iterate over
3370 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3372 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3373 last_made
, callback
);
3376 /* Implementation of the map_symtabs_matching_filename method. */
3379 dw2_map_symtabs_matching_filename
3380 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3381 gdb::function_view
<bool (symtab
*)> callback
)
3383 const char *name_basename
= lbasename (name
);
3384 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3386 /* The rule is CUs specify all the files, including those used by
3387 any TU, so there's no need to scan TUs here. */
3389 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3391 /* We only need to look at symtabs not already expanded. */
3392 if (per_objfile
->symtab_set_p (per_cu
))
3395 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3396 if (file_data
== NULL
)
3399 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3401 const char *this_name
= file_data
->file_names
[j
];
3402 const char *this_real_name
;
3404 if (compare_filenames_for_search (this_name
, name
))
3406 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3412 /* Before we invoke realpath, which can get expensive when many
3413 files are involved, do a quick comparison of the basenames. */
3414 if (! basenames_may_differ
3415 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3418 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3419 if (compare_filenames_for_search (this_real_name
, name
))
3421 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3427 if (real_path
!= NULL
)
3429 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3430 gdb_assert (IS_ABSOLUTE_PATH (name
));
3431 if (this_real_name
!= NULL
3432 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3434 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3446 /* Struct used to manage iterating over all CUs looking for a symbol. */
3448 struct dw2_symtab_iterator
3450 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3451 dwarf2_per_objfile
*per_objfile
;
3452 /* If set, only look for symbols that match that block. Valid values are
3453 GLOBAL_BLOCK and STATIC_BLOCK. */
3454 gdb::optional
<block_enum
> block_index
;
3455 /* The kind of symbol we're looking for. */
3457 /* The list of CUs from the index entry of the symbol,
3458 or NULL if not found. */
3460 /* The next element in VEC to look at. */
3462 /* The number of elements in VEC, or zero if there is no match. */
3464 /* Have we seen a global version of the symbol?
3465 If so we can ignore all further global instances.
3466 This is to work around gold/15646, inefficient gold-generated
3471 /* Initialize the index symtab iterator ITER, common part. */
3474 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3475 dwarf2_per_objfile
*per_objfile
,
3476 gdb::optional
<block_enum
> block_index
,
3479 iter
->per_objfile
= per_objfile
;
3480 iter
->block_index
= block_index
;
3481 iter
->domain
= domain
;
3483 iter
->global_seen
= 0;
3488 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3491 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3492 dwarf2_per_objfile
*per_objfile
,
3493 gdb::optional
<block_enum
> block_index
,
3497 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3499 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3500 /* index is NULL if OBJF_READNOW. */
3504 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3505 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3508 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3511 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3512 dwarf2_per_objfile
*per_objfile
,
3513 gdb::optional
<block_enum
> block_index
,
3514 domain_enum domain
, offset_type namei
)
3516 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3518 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3519 /* index is NULL if OBJF_READNOW. */
3523 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3524 const auto &bucket
= index
->symbol_table
[namei
];
3526 iter
->vec
= (offset_type
*) (index
->constant_pool
3527 + MAYBE_SWAP (bucket
.vec
));
3528 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3531 /* Return the next matching CU or NULL if there are no more. */
3533 static struct dwarf2_per_cu_data
*
3534 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3536 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3538 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3540 offset_type cu_index_and_attrs
=
3541 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3542 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3543 gdb_index_symbol_kind symbol_kind
=
3544 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3545 /* Only check the symbol attributes if they're present.
3546 Indices prior to version 7 don't record them,
3547 and indices >= 7 may elide them for certain symbols
3548 (gold does this). */
3550 (per_objfile
->per_bfd
->index_table
->version
>= 7
3551 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3553 /* Don't crash on bad data. */
3554 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3555 + per_objfile
->per_bfd
->all_type_units
.size ()))
3557 complaint (_(".gdb_index entry has bad CU index"
3558 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3562 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3564 /* Skip if already read in. */
3565 if (per_objfile
->symtab_set_p (per_cu
))
3568 /* Check static vs global. */
3571 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3573 if (iter
->block_index
.has_value ())
3575 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3577 if (is_static
!= want_static
)
3581 /* Work around gold/15646. */
3583 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3585 if (iter
->global_seen
)
3588 iter
->global_seen
= 1;
3592 /* Only check the symbol's kind if it has one. */
3595 switch (iter
->domain
)
3598 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3599 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3600 /* Some types are also in VAR_DOMAIN. */
3601 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3605 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3609 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3613 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3628 static struct compunit_symtab
*
3629 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3630 const char *name
, domain_enum domain
)
3632 struct compunit_symtab
*stab_best
= NULL
;
3633 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3635 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3637 struct dw2_symtab_iterator iter
;
3638 struct dwarf2_per_cu_data
*per_cu
;
3640 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3642 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3644 struct symbol
*sym
, *with_opaque
= NULL
;
3645 struct compunit_symtab
*stab
3646 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3647 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3648 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3650 sym
= block_find_symbol (block
, name
, domain
,
3651 block_find_non_opaque_type_preferred
,
3654 /* Some caution must be observed with overloaded functions
3655 and methods, since the index will not contain any overload
3656 information (but NAME might contain it). */
3659 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3661 if (with_opaque
!= NULL
3662 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3665 /* Keep looking through other CUs. */
3672 dw2_print_stats (struct objfile
*objfile
)
3674 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3675 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3676 + per_objfile
->per_bfd
->all_type_units
.size ());
3679 for (int i
= 0; i
< total
; ++i
)
3681 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3683 if (!per_objfile
->symtab_set_p (per_cu
))
3686 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3687 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3690 /* This dumps minimal information about the index.
3691 It is called via "mt print objfiles".
3692 One use is to verify .gdb_index has been loaded by the
3693 gdb.dwarf2/gdb-index.exp testcase. */
3696 dw2_dump (struct objfile
*objfile
)
3698 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3700 gdb_assert (per_objfile
->per_bfd
->using_index
);
3701 printf_filtered (".gdb_index:");
3702 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3704 printf_filtered (" version %d\n",
3705 per_objfile
->per_bfd
->index_table
->version
);
3708 printf_filtered (" faked for \"readnow\"\n");
3709 printf_filtered ("\n");
3713 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3714 const char *func_name
)
3716 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3718 struct dw2_symtab_iterator iter
;
3719 struct dwarf2_per_cu_data
*per_cu
;
3721 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3723 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3724 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3729 dw2_expand_all_symtabs (struct objfile
*objfile
)
3731 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3732 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3733 + per_objfile
->per_bfd
->all_type_units
.size ());
3735 for (int i
= 0; i
< total_units
; ++i
)
3737 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3739 /* We don't want to directly expand a partial CU, because if we
3740 read it with the wrong language, then assertion failures can
3741 be triggered later on. See PR symtab/23010. So, tell
3742 dw2_instantiate_symtab to skip partial CUs -- any important
3743 partial CU will be read via DW_TAG_imported_unit anyway. */
3744 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3749 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3750 const char *fullname
)
3752 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3754 /* We don't need to consider type units here.
3755 This is only called for examining code, e.g. expand_line_sal.
3756 There can be an order of magnitude (or more) more type units
3757 than comp units, and we avoid them if we can. */
3759 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3761 /* We only need to look at symtabs not already expanded. */
3762 if (per_objfile
->symtab_set_p (per_cu
))
3765 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3766 if (file_data
== NULL
)
3769 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3771 const char *this_fullname
= file_data
->file_names
[j
];
3773 if (filename_cmp (this_fullname
, fullname
) == 0)
3775 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3783 dw2_expand_symtabs_matching_symbol
3784 (mapped_index_base
&index
,
3785 const lookup_name_info
&lookup_name_in
,
3786 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3787 enum search_domain kind
,
3788 gdb::function_view
<bool (offset_type
)> match_callback
,
3789 dwarf2_per_objfile
*per_objfile
);
3792 dw2_expand_symtabs_matching_one
3793 (dwarf2_per_cu_data
*per_cu
,
3794 dwarf2_per_objfile
*per_objfile
,
3795 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3796 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3799 dw2_map_matching_symbols
3800 (struct objfile
*objfile
,
3801 const lookup_name_info
&name
, domain_enum domain
,
3803 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3804 symbol_compare_ftype
*ordered_compare
)
3807 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3809 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3811 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3813 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3815 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3816 auto matcher
= [&] (const char *symname
)
3818 if (ordered_compare
== nullptr)
3820 return ordered_compare (symname
, match_name
) == 0;
3823 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3824 [&] (offset_type namei
)
3826 struct dw2_symtab_iterator iter
;
3827 struct dwarf2_per_cu_data
*per_cu
;
3829 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3831 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3832 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3839 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3840 proceed assuming all symtabs have been read in. */
3843 for (compunit_symtab
*cust
: objfile
->compunits ())
3845 const struct block
*block
;
3849 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3850 if (!iterate_over_symbols_terminated (block
, name
,
3856 /* Starting from a search name, return the string that finds the upper
3857 bound of all strings that start with SEARCH_NAME in a sorted name
3858 list. Returns the empty string to indicate that the upper bound is
3859 the end of the list. */
3862 make_sort_after_prefix_name (const char *search_name
)
3864 /* When looking to complete "func", we find the upper bound of all
3865 symbols that start with "func" by looking for where we'd insert
3866 the closest string that would follow "func" in lexicographical
3867 order. Usually, that's "func"-with-last-character-incremented,
3868 i.e. "fund". Mind non-ASCII characters, though. Usually those
3869 will be UTF-8 multi-byte sequences, but we can't be certain.
3870 Especially mind the 0xff character, which is a valid character in
3871 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3872 rule out compilers allowing it in identifiers. Note that
3873 conveniently, strcmp/strcasecmp are specified to compare
3874 characters interpreted as unsigned char. So what we do is treat
3875 the whole string as a base 256 number composed of a sequence of
3876 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3877 to 0, and carries 1 to the following more-significant position.
3878 If the very first character in SEARCH_NAME ends up incremented
3879 and carries/overflows, then the upper bound is the end of the
3880 list. The string after the empty string is also the empty
3883 Some examples of this operation:
3885 SEARCH_NAME => "+1" RESULT
3889 "\xff" "a" "\xff" => "\xff" "b"
3894 Then, with these symbols for example:
3900 completing "func" looks for symbols between "func" and
3901 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3902 which finds "func" and "func1", but not "fund".
3906 funcÿ (Latin1 'ÿ' [0xff])
3910 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3911 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3915 ÿÿ (Latin1 'ÿ' [0xff])
3918 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3919 the end of the list.
3921 std::string after
= search_name
;
3922 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3924 if (!after
.empty ())
3925 after
.back () = (unsigned char) after
.back () + 1;
3929 /* See declaration. */
3931 std::pair
<std::vector
<name_component
>::const_iterator
,
3932 std::vector
<name_component
>::const_iterator
>
3933 mapped_index_base::find_name_components_bounds
3934 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3935 dwarf2_per_objfile
*per_objfile
) const
3938 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3940 const char *lang_name
3941 = lookup_name_without_params
.language_lookup_name (lang
);
3943 /* Comparison function object for lower_bound that matches against a
3944 given symbol name. */
3945 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3948 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3949 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3950 return name_cmp (elem_name
, name
) < 0;
3953 /* Comparison function object for upper_bound that matches against a
3954 given symbol name. */
3955 auto lookup_compare_upper
= [&] (const char *name
,
3956 const name_component
&elem
)
3958 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3959 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3960 return name_cmp (name
, elem_name
) < 0;
3963 auto begin
= this->name_components
.begin ();
3964 auto end
= this->name_components
.end ();
3966 /* Find the lower bound. */
3969 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3972 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3975 /* Find the upper bound. */
3978 if (lookup_name_without_params
.completion_mode ())
3980 /* In completion mode, we want UPPER to point past all
3981 symbols names that have the same prefix. I.e., with
3982 these symbols, and completing "func":
3984 function << lower bound
3986 other_function << upper bound
3988 We find the upper bound by looking for the insertion
3989 point of "func"-with-last-character-incremented,
3991 std::string after
= make_sort_after_prefix_name (lang_name
);
3994 return std::lower_bound (lower
, end
, after
.c_str (),
3995 lookup_compare_lower
);
3998 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4001 return {lower
, upper
};
4004 /* See declaration. */
4007 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
4009 if (!this->name_components
.empty ())
4012 this->name_components_casing
= case_sensitivity
;
4014 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4016 /* The code below only knows how to break apart components of C++
4017 symbol names (and other languages that use '::' as
4018 namespace/module separator) and Ada symbol names. */
4019 auto count
= this->symbol_name_count ();
4020 for (offset_type idx
= 0; idx
< count
; idx
++)
4022 if (this->symbol_name_slot_invalid (idx
))
4025 const char *name
= this->symbol_name_at (idx
, per_objfile
);
4027 /* Add each name component to the name component table. */
4028 unsigned int previous_len
= 0;
4030 if (strstr (name
, "::") != nullptr)
4032 for (unsigned int current_len
= cp_find_first_component (name
);
4033 name
[current_len
] != '\0';
4034 current_len
+= cp_find_first_component (name
+ current_len
))
4036 gdb_assert (name
[current_len
] == ':');
4037 this->name_components
.push_back ({previous_len
, idx
});
4038 /* Skip the '::'. */
4040 previous_len
= current_len
;
4045 /* Handle the Ada encoded (aka mangled) form here. */
4046 for (const char *iter
= strstr (name
, "__");
4048 iter
= strstr (iter
, "__"))
4050 this->name_components
.push_back ({previous_len
, idx
});
4052 previous_len
= iter
- name
;
4056 this->name_components
.push_back ({previous_len
, idx
});
4059 /* Sort name_components elements by name. */
4060 auto name_comp_compare
= [&] (const name_component
&left
,
4061 const name_component
&right
)
4063 const char *left_qualified
4064 = this->symbol_name_at (left
.idx
, per_objfile
);
4065 const char *right_qualified
4066 = this->symbol_name_at (right
.idx
, per_objfile
);
4068 const char *left_name
= left_qualified
+ left
.name_offset
;
4069 const char *right_name
= right_qualified
+ right
.name_offset
;
4071 return name_cmp (left_name
, right_name
) < 0;
4074 std::sort (this->name_components
.begin (),
4075 this->name_components
.end (),
4079 /* Helper for dw2_expand_symtabs_matching that works with a
4080 mapped_index_base instead of the containing objfile. This is split
4081 to a separate function in order to be able to unit test the
4082 name_components matching using a mock mapped_index_base. For each
4083 symbol name that matches, calls MATCH_CALLBACK, passing it the
4084 symbol's index in the mapped_index_base symbol table. */
4087 dw2_expand_symtabs_matching_symbol
4088 (mapped_index_base
&index
,
4089 const lookup_name_info
&lookup_name_in
,
4090 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4091 enum search_domain kind
,
4092 gdb::function_view
<bool (offset_type
)> match_callback
,
4093 dwarf2_per_objfile
*per_objfile
)
4095 lookup_name_info lookup_name_without_params
4096 = lookup_name_in
.make_ignore_params ();
4098 /* Build the symbol name component sorted vector, if we haven't
4100 index
.build_name_components (per_objfile
);
4102 /* The same symbol may appear more than once in the range though.
4103 E.g., if we're looking for symbols that complete "w", and we have
4104 a symbol named "w1::w2", we'll find the two name components for
4105 that same symbol in the range. To be sure we only call the
4106 callback once per symbol, we first collect the symbol name
4107 indexes that matched in a temporary vector and ignore
4109 std::vector
<offset_type
> matches
;
4111 struct name_and_matcher
4113 symbol_name_matcher_ftype
*matcher
;
4116 bool operator== (const name_and_matcher
&other
) const
4118 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4122 /* A vector holding all the different symbol name matchers, for all
4124 std::vector
<name_and_matcher
> matchers
;
4126 for (int i
= 0; i
< nr_languages
; i
++)
4128 enum language lang_e
= (enum language
) i
;
4130 const language_defn
*lang
= language_def (lang_e
);
4131 symbol_name_matcher_ftype
*name_matcher
4132 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4134 name_and_matcher key
{
4136 lookup_name_without_params
.language_lookup_name (lang_e
)
4139 /* Don't insert the same comparison routine more than once.
4140 Note that we do this linear walk. This is not a problem in
4141 practice because the number of supported languages is
4143 if (std::find (matchers
.begin (), matchers
.end (), key
)
4146 matchers
.push_back (std::move (key
));
4149 = index
.find_name_components_bounds (lookup_name_without_params
,
4150 lang_e
, per_objfile
);
4152 /* Now for each symbol name in range, check to see if we have a name
4153 match, and if so, call the MATCH_CALLBACK callback. */
4155 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4157 const char *qualified
4158 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4160 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4161 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4164 matches
.push_back (bounds
.first
->idx
);
4168 std::sort (matches
.begin (), matches
.end ());
4170 /* Finally call the callback, once per match. */
4172 for (offset_type idx
: matches
)
4176 if (!match_callback (idx
))
4182 /* Above we use a type wider than idx's for 'prev', since 0 and
4183 (offset_type)-1 are both possible values. */
4184 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4189 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4191 /* A mock .gdb_index/.debug_names-like name index table, enough to
4192 exercise dw2_expand_symtabs_matching_symbol, which works with the
4193 mapped_index_base interface. Builds an index from the symbol list
4194 passed as parameter to the constructor. */
4195 class mock_mapped_index
: public mapped_index_base
4198 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4199 : m_symbol_table (symbols
)
4202 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4204 /* Return the number of names in the symbol table. */
4205 size_t symbol_name_count () const override
4207 return m_symbol_table
.size ();
4210 /* Get the name of the symbol at IDX in the symbol table. */
4211 const char *symbol_name_at
4212 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4214 return m_symbol_table
[idx
];
4218 gdb::array_view
<const char *> m_symbol_table
;
4221 /* Convenience function that converts a NULL pointer to a "<null>"
4222 string, to pass to print routines. */
4225 string_or_null (const char *str
)
4227 return str
!= NULL
? str
: "<null>";
4230 /* Check if a lookup_name_info built from
4231 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4232 index. EXPECTED_LIST is the list of expected matches, in expected
4233 matching order. If no match expected, then an empty list is
4234 specified. Returns true on success. On failure prints a warning
4235 indicating the file:line that failed, and returns false. */
4238 check_match (const char *file
, int line
,
4239 mock_mapped_index
&mock_index
,
4240 const char *name
, symbol_name_match_type match_type
,
4241 bool completion_mode
,
4242 std::initializer_list
<const char *> expected_list
,
4243 dwarf2_per_objfile
*per_objfile
)
4245 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4247 bool matched
= true;
4249 auto mismatch
= [&] (const char *expected_str
,
4252 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4253 "expected=\"%s\", got=\"%s\"\n"),
4255 (match_type
== symbol_name_match_type::FULL
4257 name
, string_or_null (expected_str
), string_or_null (got
));
4261 auto expected_it
= expected_list
.begin ();
4262 auto expected_end
= expected_list
.end ();
4264 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4266 [&] (offset_type idx
)
4268 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4269 const char *expected_str
4270 = expected_it
== expected_end
? NULL
: *expected_it
++;
4272 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4273 mismatch (expected_str
, matched_name
);
4277 const char *expected_str
4278 = expected_it
== expected_end
? NULL
: *expected_it
++;
4279 if (expected_str
!= NULL
)
4280 mismatch (expected_str
, NULL
);
4285 /* The symbols added to the mock mapped_index for testing (in
4287 static const char *test_symbols
[] = {
4296 "ns2::tmpl<int>::foo2",
4297 "(anonymous namespace)::A::B::C",
4299 /* These are used to check that the increment-last-char in the
4300 matching algorithm for completion doesn't match "t1_fund" when
4301 completing "t1_func". */
4307 /* A UTF-8 name with multi-byte sequences to make sure that
4308 cp-name-parser understands this as a single identifier ("função"
4309 is "function" in PT). */
4312 /* \377 (0xff) is Latin1 'ÿ'. */
4315 /* \377 (0xff) is Latin1 'ÿ'. */
4319 /* A name with all sorts of complications. Starts with "z" to make
4320 it easier for the completion tests below. */
4321 #define Z_SYM_NAME \
4322 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4323 "::tuple<(anonymous namespace)::ui*, " \
4324 "std::default_delete<(anonymous namespace)::ui>, void>"
4329 /* Returns true if the mapped_index_base::find_name_component_bounds
4330 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4331 in completion mode. */
4334 check_find_bounds_finds (mapped_index_base
&index
,
4335 const char *search_name
,
4336 gdb::array_view
<const char *> expected_syms
,
4337 dwarf2_per_objfile
*per_objfile
)
4339 lookup_name_info
lookup_name (search_name
,
4340 symbol_name_match_type::FULL
, true);
4342 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4346 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4347 if (distance
!= expected_syms
.size ())
4350 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4352 auto nc_elem
= bounds
.first
+ exp_elem
;
4353 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4354 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4361 /* Test the lower-level mapped_index::find_name_component_bounds
4365 test_mapped_index_find_name_component_bounds ()
4367 mock_mapped_index
mock_index (test_symbols
);
4369 mock_index
.build_name_components (NULL
/* per_objfile */);
4371 /* Test the lower-level mapped_index::find_name_component_bounds
4372 method in completion mode. */
4374 static const char *expected_syms
[] = {
4379 SELF_CHECK (check_find_bounds_finds
4380 (mock_index
, "t1_func", expected_syms
,
4381 NULL
/* per_objfile */));
4384 /* Check that the increment-last-char in the name matching algorithm
4385 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4387 static const char *expected_syms1
[] = {
4391 SELF_CHECK (check_find_bounds_finds
4392 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4394 static const char *expected_syms2
[] = {
4397 SELF_CHECK (check_find_bounds_finds
4398 (mock_index
, "\377\377", expected_syms2
,
4399 NULL
/* per_objfile */));
4403 /* Test dw2_expand_symtabs_matching_symbol. */
4406 test_dw2_expand_symtabs_matching_symbol ()
4408 mock_mapped_index
mock_index (test_symbols
);
4410 /* We let all tests run until the end even if some fails, for debug
4412 bool any_mismatch
= false;
4414 /* Create the expected symbols list (an initializer_list). Needed
4415 because lists have commas, and we need to pass them to CHECK,
4416 which is a macro. */
4417 #define EXPECT(...) { __VA_ARGS__ }
4419 /* Wrapper for check_match that passes down the current
4420 __FILE__/__LINE__. */
4421 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4422 any_mismatch |= !check_match (__FILE__, __LINE__, \
4424 NAME, MATCH_TYPE, COMPLETION_MODE, \
4425 EXPECTED_LIST, NULL)
4427 /* Identity checks. */
4428 for (const char *sym
: test_symbols
)
4430 /* Should be able to match all existing symbols. */
4431 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4434 /* Should be able to match all existing symbols with
4436 std::string with_params
= std::string (sym
) + "(int)";
4437 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4440 /* Should be able to match all existing symbols with
4441 parameters and qualifiers. */
4442 with_params
= std::string (sym
) + " ( int ) const";
4443 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4446 /* This should really find sym, but cp-name-parser.y doesn't
4447 know about lvalue/rvalue qualifiers yet. */
4448 with_params
= std::string (sym
) + " ( int ) &&";
4449 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4453 /* Check that the name matching algorithm for completion doesn't get
4454 confused with Latin1 'ÿ' / 0xff. */
4456 static const char str
[] = "\377";
4457 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4458 EXPECT ("\377", "\377\377123"));
4461 /* Check that the increment-last-char in the matching algorithm for
4462 completion doesn't match "t1_fund" when completing "t1_func". */
4464 static const char str
[] = "t1_func";
4465 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4466 EXPECT ("t1_func", "t1_func1"));
4469 /* Check that completion mode works at each prefix of the expected
4472 static const char str
[] = "function(int)";
4473 size_t len
= strlen (str
);
4476 for (size_t i
= 1; i
< len
; i
++)
4478 lookup
.assign (str
, i
);
4479 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4480 EXPECT ("function"));
4484 /* While "w" is a prefix of both components, the match function
4485 should still only be called once. */
4487 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4489 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4493 /* Same, with a "complicated" symbol. */
4495 static const char str
[] = Z_SYM_NAME
;
4496 size_t len
= strlen (str
);
4499 for (size_t i
= 1; i
< len
; i
++)
4501 lookup
.assign (str
, i
);
4502 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4503 EXPECT (Z_SYM_NAME
));
4507 /* In FULL mode, an incomplete symbol doesn't match. */
4509 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4513 /* A complete symbol with parameters matches any overload, since the
4514 index has no overload info. */
4516 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4517 EXPECT ("std::zfunction", "std::zfunction2"));
4518 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4519 EXPECT ("std::zfunction", "std::zfunction2"));
4520 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4521 EXPECT ("std::zfunction", "std::zfunction2"));
4524 /* Check that whitespace is ignored appropriately. A symbol with a
4525 template argument list. */
4527 static const char expected
[] = "ns::foo<int>";
4528 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4530 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4534 /* Check that whitespace is ignored appropriately. A symbol with a
4535 template argument list that includes a pointer. */
4537 static const char expected
[] = "ns::foo<char*>";
4538 /* Try both completion and non-completion modes. */
4539 static const bool completion_mode
[2] = {false, true};
4540 for (size_t i
= 0; i
< 2; i
++)
4542 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4543 completion_mode
[i
], EXPECT (expected
));
4544 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4545 completion_mode
[i
], EXPECT (expected
));
4547 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4548 completion_mode
[i
], EXPECT (expected
));
4549 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4550 completion_mode
[i
], EXPECT (expected
));
4555 /* Check method qualifiers are ignored. */
4556 static const char expected
[] = "ns::foo<char*>";
4557 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4558 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4559 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4560 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4561 CHECK_MATCH ("foo < char * > ( int ) const",
4562 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4563 CHECK_MATCH ("foo < char * > ( int ) &&",
4564 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4567 /* Test lookup names that don't match anything. */
4569 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4572 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4576 /* Some wild matching tests, exercising "(anonymous namespace)",
4577 which should not be confused with a parameter list. */
4579 static const char *syms
[] = {
4583 "A :: B :: C ( int )",
4588 for (const char *s
: syms
)
4590 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4591 EXPECT ("(anonymous namespace)::A::B::C"));
4596 static const char expected
[] = "ns2::tmpl<int>::foo2";
4597 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4599 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4603 SELF_CHECK (!any_mismatch
);
4612 test_mapped_index_find_name_component_bounds ();
4613 test_dw2_expand_symtabs_matching_symbol ();
4616 }} // namespace selftests::dw2_expand_symtabs_matching
4618 #endif /* GDB_SELF_TEST */
4620 /* If FILE_MATCHER is NULL or if PER_CU has
4621 dwarf2_per_cu_quick_data::MARK set (see
4622 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4623 EXPANSION_NOTIFY on it. */
4626 dw2_expand_symtabs_matching_one
4627 (dwarf2_per_cu_data
*per_cu
,
4628 dwarf2_per_objfile
*per_objfile
,
4629 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4630 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4632 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4634 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4636 compunit_symtab
*symtab
4637 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4638 gdb_assert (symtab
!= nullptr);
4640 if (expansion_notify
!= NULL
&& symtab_was_null
)
4641 expansion_notify (symtab
);
4645 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4646 matched, to expand corresponding CUs that were marked. IDX is the
4647 index of the symbol name that matched. */
4650 dw2_expand_marked_cus
4651 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4652 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4653 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4656 offset_type
*vec
, vec_len
, vec_idx
;
4657 bool global_seen
= false;
4658 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4660 vec
= (offset_type
*) (index
.constant_pool
4661 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4662 vec_len
= MAYBE_SWAP (vec
[0]);
4663 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4665 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4666 /* This value is only valid for index versions >= 7. */
4667 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4668 gdb_index_symbol_kind symbol_kind
=
4669 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4670 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4671 /* Only check the symbol attributes if they're present.
4672 Indices prior to version 7 don't record them,
4673 and indices >= 7 may elide them for certain symbols
4674 (gold does this). */
4677 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4679 /* Work around gold/15646. */
4682 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4690 /* Only check the symbol's kind if it has one. */
4695 case VARIABLES_DOMAIN
:
4696 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4699 case FUNCTIONS_DOMAIN
:
4700 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4704 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4707 case MODULES_DOMAIN
:
4708 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4716 /* Don't crash on bad data. */
4717 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4718 + per_objfile
->per_bfd
->all_type_units
.size ()))
4720 complaint (_(".gdb_index entry has bad CU index"
4721 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4725 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4726 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4731 /* If FILE_MATCHER is non-NULL, set all the
4732 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4733 that match FILE_MATCHER. */
4736 dw_expand_symtabs_matching_file_matcher
4737 (dwarf2_per_objfile
*per_objfile
,
4738 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4740 if (file_matcher
== NULL
)
4743 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4745 NULL
, xcalloc
, xfree
));
4746 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4748 NULL
, xcalloc
, xfree
));
4750 /* The rule is CUs specify all the files, including those used by
4751 any TU, so there's no need to scan TUs here. */
4753 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4757 per_cu
->v
.quick
->mark
= 0;
4759 /* We only need to look at symtabs not already expanded. */
4760 if (per_objfile
->symtab_set_p (per_cu
))
4763 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4764 if (file_data
== NULL
)
4767 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4769 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4771 per_cu
->v
.quick
->mark
= 1;
4775 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4777 const char *this_real_name
;
4779 if (file_matcher (file_data
->file_names
[j
], false))
4781 per_cu
->v
.quick
->mark
= 1;
4785 /* Before we invoke realpath, which can get expensive when many
4786 files are involved, do a quick comparison of the basenames. */
4787 if (!basenames_may_differ
4788 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4792 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4793 if (file_matcher (this_real_name
, false))
4795 per_cu
->v
.quick
->mark
= 1;
4800 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4801 ? visited_found
.get ()
4802 : visited_not_found
.get (),
4809 dw2_expand_symtabs_matching
4810 (struct objfile
*objfile
,
4811 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4812 const lookup_name_info
*lookup_name
,
4813 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4814 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4815 enum search_domain kind
)
4817 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4819 /* index_table is NULL if OBJF_READNOW. */
4820 if (!per_objfile
->per_bfd
->index_table
)
4823 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4825 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4827 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4831 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4832 file_matcher
, expansion_notify
);
4837 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4839 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4841 kind
, [&] (offset_type idx
)
4843 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4849 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4852 static struct compunit_symtab
*
4853 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4858 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4859 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4862 if (cust
->includes
== NULL
)
4865 for (i
= 0; cust
->includes
[i
]; ++i
)
4867 struct compunit_symtab
*s
= cust
->includes
[i
];
4869 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4877 static struct compunit_symtab
*
4878 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4879 struct bound_minimal_symbol msymbol
,
4881 struct obj_section
*section
,
4884 struct dwarf2_per_cu_data
*data
;
4885 struct compunit_symtab
*result
;
4887 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4890 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4891 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4892 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4896 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4897 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4898 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4899 paddress (objfile
->arch (), pc
));
4901 result
= recursively_find_pc_sect_compunit_symtab
4902 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4904 gdb_assert (result
!= NULL
);
4909 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4910 void *data
, int need_fullname
)
4912 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4914 if (!per_objfile
->per_bfd
->filenames_cache
)
4916 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4918 htab_up
visited (htab_create_alloc (10,
4919 htab_hash_pointer
, htab_eq_pointer
,
4920 NULL
, xcalloc
, xfree
));
4922 /* The rule is CUs specify all the files, including those used
4923 by any TU, so there's no need to scan TUs here. We can
4924 ignore file names coming from already-expanded CUs. */
4926 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4928 if (per_objfile
->symtab_set_p (per_cu
))
4930 void **slot
= htab_find_slot (visited
.get (),
4931 per_cu
->v
.quick
->file_names
,
4934 *slot
= per_cu
->v
.quick
->file_names
;
4938 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4940 /* We only need to look at symtabs not already expanded. */
4941 if (per_objfile
->symtab_set_p (per_cu
))
4944 quick_file_names
*file_data
4945 = dw2_get_file_names (per_cu
, per_objfile
);
4946 if (file_data
== NULL
)
4949 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4952 /* Already visited. */
4957 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4959 const char *filename
= file_data
->file_names
[j
];
4960 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4965 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4967 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4970 this_real_name
= gdb_realpath (filename
);
4971 (*fun
) (filename
, this_real_name
.get (), data
);
4976 dw2_has_symbols (struct objfile
*objfile
)
4981 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4984 dw2_find_last_source_symtab
,
4985 dw2_forget_cached_source_info
,
4986 dw2_map_symtabs_matching_filename
,
4991 dw2_expand_symtabs_for_function
,
4992 dw2_expand_all_symtabs
,
4993 dw2_expand_symtabs_with_fullname
,
4994 dw2_map_matching_symbols
,
4995 dw2_expand_symtabs_matching
,
4996 dw2_find_pc_sect_compunit_symtab
,
4998 dw2_map_symbol_filenames
5001 /* DWARF-5 debug_names reader. */
5003 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5004 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5006 /* A helper function that reads the .debug_names section in SECTION
5007 and fills in MAP. FILENAME is the name of the file containing the
5008 section; it is used for error reporting.
5010 Returns true if all went well, false otherwise. */
5013 read_debug_names_from_section (struct objfile
*objfile
,
5014 const char *filename
,
5015 struct dwarf2_section_info
*section
,
5016 mapped_debug_names
&map
)
5018 if (section
->empty ())
5021 /* Older elfutils strip versions could keep the section in the main
5022 executable while splitting it for the separate debug info file. */
5023 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5026 section
->read (objfile
);
5028 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
5030 const gdb_byte
*addr
= section
->buffer
;
5032 bfd
*const abfd
= section
->get_bfd_owner ();
5034 unsigned int bytes_read
;
5035 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5038 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5039 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5040 if (bytes_read
+ length
!= section
->size
)
5042 /* There may be multiple per-CU indices. */
5043 warning (_("Section .debug_names in %s length %s does not match "
5044 "section length %s, ignoring .debug_names."),
5045 filename
, plongest (bytes_read
+ length
),
5046 pulongest (section
->size
));
5050 /* The version number. */
5051 uint16_t version
= read_2_bytes (abfd
, addr
);
5055 warning (_("Section .debug_names in %s has unsupported version %d, "
5056 "ignoring .debug_names."),
5062 uint16_t padding
= read_2_bytes (abfd
, addr
);
5066 warning (_("Section .debug_names in %s has unsupported padding %d, "
5067 "ignoring .debug_names."),
5072 /* comp_unit_count - The number of CUs in the CU list. */
5073 map
.cu_count
= read_4_bytes (abfd
, addr
);
5076 /* local_type_unit_count - The number of TUs in the local TU
5078 map
.tu_count
= read_4_bytes (abfd
, addr
);
5081 /* foreign_type_unit_count - The number of TUs in the foreign TU
5083 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5085 if (foreign_tu_count
!= 0)
5087 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5088 "ignoring .debug_names."),
5089 filename
, static_cast<unsigned long> (foreign_tu_count
));
5093 /* bucket_count - The number of hash buckets in the hash lookup
5095 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5098 /* name_count - The number of unique names in the index. */
5099 map
.name_count
= read_4_bytes (abfd
, addr
);
5102 /* abbrev_table_size - The size in bytes of the abbreviations
5104 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5107 /* augmentation_string_size - The size in bytes of the augmentation
5108 string. This value is rounded up to a multiple of 4. */
5109 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5111 map
.augmentation_is_gdb
= ((augmentation_string_size
5112 == sizeof (dwarf5_augmentation
))
5113 && memcmp (addr
, dwarf5_augmentation
,
5114 sizeof (dwarf5_augmentation
)) == 0);
5115 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5116 addr
+= augmentation_string_size
;
5119 map
.cu_table_reordered
= addr
;
5120 addr
+= map
.cu_count
* map
.offset_size
;
5122 /* List of Local TUs */
5123 map
.tu_table_reordered
= addr
;
5124 addr
+= map
.tu_count
* map
.offset_size
;
5126 /* Hash Lookup Table */
5127 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5128 addr
+= map
.bucket_count
* 4;
5129 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5130 addr
+= map
.name_count
* 4;
5133 map
.name_table_string_offs_reordered
= addr
;
5134 addr
+= map
.name_count
* map
.offset_size
;
5135 map
.name_table_entry_offs_reordered
= addr
;
5136 addr
+= map
.name_count
* map
.offset_size
;
5138 const gdb_byte
*abbrev_table_start
= addr
;
5141 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5146 const auto insertpair
5147 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5148 if (!insertpair
.second
)
5150 warning (_("Section .debug_names in %s has duplicate index %s, "
5151 "ignoring .debug_names."),
5152 filename
, pulongest (index_num
));
5155 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5156 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5161 mapped_debug_names::index_val::attr attr
;
5162 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5164 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5166 if (attr
.form
== DW_FORM_implicit_const
)
5168 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5172 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5174 indexval
.attr_vec
.push_back (std::move (attr
));
5177 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5179 warning (_("Section .debug_names in %s has abbreviation_table "
5180 "of size %s vs. written as %u, ignoring .debug_names."),
5181 filename
, plongest (addr
- abbrev_table_start
),
5185 map
.entry_pool
= addr
;
5190 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5194 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5195 const mapped_debug_names
&map
,
5196 dwarf2_section_info
§ion
,
5199 if (!map
.augmentation_is_gdb
)
5201 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5203 sect_offset sect_off
5204 = (sect_offset
) (extract_unsigned_integer
5205 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5207 map
.dwarf5_byte_order
));
5208 /* We don't know the length of the CU, because the CU list in a
5209 .debug_names index can be incomplete, so we can't use the start of
5210 the next CU as end of this CU. We create the CUs here with length 0,
5211 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5212 dwarf2_per_cu_data
*per_cu
5213 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5214 per_bfd
->all_comp_units
.push_back (per_cu
);
5218 sect_offset sect_off_prev
;
5219 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5221 sect_offset sect_off_next
;
5222 if (i
< map
.cu_count
)
5225 = (sect_offset
) (extract_unsigned_integer
5226 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5228 map
.dwarf5_byte_order
));
5231 sect_off_next
= (sect_offset
) section
.size
;
5234 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5235 dwarf2_per_cu_data
*per_cu
5236 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5237 sect_off_prev
, length
);
5238 per_bfd
->all_comp_units
.push_back (per_cu
);
5240 sect_off_prev
= sect_off_next
;
5244 /* Read the CU list from the mapped index, and use it to create all
5245 the CU objects for this dwarf2_per_objfile. */
5248 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5249 const mapped_debug_names
&map
,
5250 const mapped_debug_names
&dwz_map
)
5252 gdb_assert (per_bfd
->all_comp_units
.empty ());
5253 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5255 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5256 false /* is_dwz */);
5258 if (dwz_map
.cu_count
== 0)
5261 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5262 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5266 /* Read .debug_names. If everything went ok, initialize the "quick"
5267 elements of all the CUs and return true. Otherwise, return false. */
5270 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5272 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5273 mapped_debug_names dwz_map
;
5274 struct objfile
*objfile
= per_objfile
->objfile
;
5275 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5277 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5278 &per_objfile
->per_bfd
->debug_names
, *map
))
5281 /* Don't use the index if it's empty. */
5282 if (map
->name_count
== 0)
5285 /* If there is a .dwz file, read it so we can get its CU list as
5287 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5290 if (!read_debug_names_from_section (objfile
,
5291 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5292 &dwz
->debug_names
, dwz_map
))
5294 warning (_("could not read '.debug_names' section from %s; skipping"),
5295 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5300 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5302 if (map
->tu_count
!= 0)
5304 /* We can only handle a single .debug_types when we have an
5306 if (per_bfd
->types
.size () != 1)
5309 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5311 create_signatured_type_table_from_debug_names
5312 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5315 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5317 per_bfd
->debug_names_table
= std::move (map
);
5318 per_bfd
->using_index
= 1;
5319 per_bfd
->quick_file_names_table
=
5320 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5322 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5323 objfiles using the same BFD. */
5324 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5325 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5330 /* Type used to manage iterating over all CUs looking for a symbol for
5333 class dw2_debug_names_iterator
5336 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5337 gdb::optional
<block_enum
> block_index
,
5339 const char *name
, dwarf2_per_objfile
*per_objfile
)
5340 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5341 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5342 m_per_objfile (per_objfile
)
5345 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5346 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5349 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5350 m_per_objfile (per_objfile
)
5353 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5354 block_enum block_index
, domain_enum domain
,
5355 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5356 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5357 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5358 m_per_objfile (per_objfile
)
5361 /* Return the next matching CU or NULL if there are no more. */
5362 dwarf2_per_cu_data
*next ();
5365 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5367 dwarf2_per_objfile
*per_objfile
);
5368 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5370 dwarf2_per_objfile
*per_objfile
);
5372 /* The internalized form of .debug_names. */
5373 const mapped_debug_names
&m_map
;
5375 /* If set, only look for symbols that match that block. Valid values are
5376 GLOBAL_BLOCK and STATIC_BLOCK. */
5377 const gdb::optional
<block_enum
> m_block_index
;
5379 /* The kind of symbol we're looking for. */
5380 const domain_enum m_domain
= UNDEF_DOMAIN
;
5381 const search_domain m_search
= ALL_DOMAIN
;
5383 /* The list of CUs from the index entry of the symbol, or NULL if
5385 const gdb_byte
*m_addr
;
5387 dwarf2_per_objfile
*m_per_objfile
;
5391 mapped_debug_names::namei_to_name
5392 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5394 const ULONGEST namei_string_offs
5395 = extract_unsigned_integer ((name_table_string_offs_reordered
5396 + namei
* offset_size
),
5399 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5402 /* Find a slot in .debug_names for the object named NAME. If NAME is
5403 found, return pointer to its pool data. If NAME cannot be found,
5407 dw2_debug_names_iterator::find_vec_in_debug_names
5408 (const mapped_debug_names
&map
, const char *name
,
5409 dwarf2_per_objfile
*per_objfile
)
5411 int (*cmp
) (const char *, const char *);
5413 gdb::unique_xmalloc_ptr
<char> without_params
;
5414 if (current_language
->la_language
== language_cplus
5415 || current_language
->la_language
== language_fortran
5416 || current_language
->la_language
== language_d
)
5418 /* NAME is already canonical. Drop any qualifiers as
5419 .debug_names does not contain any. */
5421 if (strchr (name
, '(') != NULL
)
5423 without_params
= cp_remove_params (name
);
5424 if (without_params
!= NULL
)
5425 name
= without_params
.get ();
5429 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5431 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5433 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5434 (map
.bucket_table_reordered
5435 + (full_hash
% map
.bucket_count
)), 4,
5436 map
.dwarf5_byte_order
);
5440 if (namei
>= map
.name_count
)
5442 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5444 namei
, map
.name_count
,
5445 objfile_name (per_objfile
->objfile
));
5451 const uint32_t namei_full_hash
5452 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5453 (map
.hash_table_reordered
+ namei
), 4,
5454 map
.dwarf5_byte_order
);
5455 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5458 if (full_hash
== namei_full_hash
)
5460 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5462 #if 0 /* An expensive sanity check. */
5463 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5465 complaint (_("Wrong .debug_names hash for string at index %u "
5467 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5472 if (cmp (namei_string
, name
) == 0)
5474 const ULONGEST namei_entry_offs
5475 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5476 + namei
* map
.offset_size
),
5477 map
.offset_size
, map
.dwarf5_byte_order
);
5478 return map
.entry_pool
+ namei_entry_offs
;
5483 if (namei
>= map
.name_count
)
5489 dw2_debug_names_iterator::find_vec_in_debug_names
5490 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5492 if (namei
>= map
.name_count
)
5494 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5496 namei
, map
.name_count
,
5497 objfile_name (per_objfile
->objfile
));
5501 const ULONGEST namei_entry_offs
5502 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5503 + namei
* map
.offset_size
),
5504 map
.offset_size
, map
.dwarf5_byte_order
);
5505 return map
.entry_pool
+ namei_entry_offs
;
5508 /* See dw2_debug_names_iterator. */
5510 dwarf2_per_cu_data
*
5511 dw2_debug_names_iterator::next ()
5516 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5517 struct objfile
*objfile
= m_per_objfile
->objfile
;
5518 bfd
*const abfd
= objfile
->obfd
;
5522 unsigned int bytes_read
;
5523 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5524 m_addr
+= bytes_read
;
5528 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5529 if (indexval_it
== m_map
.abbrev_map
.cend ())
5531 complaint (_("Wrong .debug_names undefined abbrev code %s "
5533 pulongest (abbrev
), objfile_name (objfile
));
5536 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5537 enum class symbol_linkage
{
5541 } symbol_linkage_
= symbol_linkage::unknown
;
5542 dwarf2_per_cu_data
*per_cu
= NULL
;
5543 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5548 case DW_FORM_implicit_const
:
5549 ull
= attr
.implicit_const
;
5551 case DW_FORM_flag_present
:
5555 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5556 m_addr
+= bytes_read
;
5559 ull
= read_4_bytes (abfd
, m_addr
);
5563 ull
= read_8_bytes (abfd
, m_addr
);
5566 case DW_FORM_ref_sig8
:
5567 ull
= read_8_bytes (abfd
, m_addr
);
5571 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5572 dwarf_form_name (attr
.form
),
5573 objfile_name (objfile
));
5576 switch (attr
.dw_idx
)
5578 case DW_IDX_compile_unit
:
5579 /* Don't crash on bad data. */
5580 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5582 complaint (_(".debug_names entry has bad CU index %s"
5585 objfile_name (objfile
));
5588 per_cu
= per_bfd
->get_cutu (ull
);
5590 case DW_IDX_type_unit
:
5591 /* Don't crash on bad data. */
5592 if (ull
>= per_bfd
->all_type_units
.size ())
5594 complaint (_(".debug_names entry has bad TU index %s"
5597 objfile_name (objfile
));
5600 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5602 case DW_IDX_die_offset
:
5603 /* In a per-CU index (as opposed to a per-module index), index
5604 entries without CU attribute implicitly refer to the single CU. */
5606 per_cu
= per_bfd
->get_cu (0);
5608 case DW_IDX_GNU_internal
:
5609 if (!m_map
.augmentation_is_gdb
)
5611 symbol_linkage_
= symbol_linkage::static_
;
5613 case DW_IDX_GNU_external
:
5614 if (!m_map
.augmentation_is_gdb
)
5616 symbol_linkage_
= symbol_linkage::extern_
;
5621 /* Skip if already read in. */
5622 if (m_per_objfile
->symtab_set_p (per_cu
))
5625 /* Check static vs global. */
5626 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5628 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5629 const bool symbol_is_static
=
5630 symbol_linkage_
== symbol_linkage::static_
;
5631 if (want_static
!= symbol_is_static
)
5635 /* Match dw2_symtab_iter_next, symbol_kind
5636 and debug_names::psymbol_tag. */
5640 switch (indexval
.dwarf_tag
)
5642 case DW_TAG_variable
:
5643 case DW_TAG_subprogram
:
5644 /* Some types are also in VAR_DOMAIN. */
5645 case DW_TAG_typedef
:
5646 case DW_TAG_structure_type
:
5653 switch (indexval
.dwarf_tag
)
5655 case DW_TAG_typedef
:
5656 case DW_TAG_structure_type
:
5663 switch (indexval
.dwarf_tag
)
5666 case DW_TAG_variable
:
5673 switch (indexval
.dwarf_tag
)
5685 /* Match dw2_expand_symtabs_matching, symbol_kind and
5686 debug_names::psymbol_tag. */
5689 case VARIABLES_DOMAIN
:
5690 switch (indexval
.dwarf_tag
)
5692 case DW_TAG_variable
:
5698 case FUNCTIONS_DOMAIN
:
5699 switch (indexval
.dwarf_tag
)
5701 case DW_TAG_subprogram
:
5708 switch (indexval
.dwarf_tag
)
5710 case DW_TAG_typedef
:
5711 case DW_TAG_structure_type
:
5717 case MODULES_DOMAIN
:
5718 switch (indexval
.dwarf_tag
)
5732 static struct compunit_symtab
*
5733 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5734 const char *name
, domain_enum domain
)
5736 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5738 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5741 /* index is NULL if OBJF_READNOW. */
5744 const auto &map
= *mapp
;
5746 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5748 struct compunit_symtab
*stab_best
= NULL
;
5749 struct dwarf2_per_cu_data
*per_cu
;
5750 while ((per_cu
= iter
.next ()) != NULL
)
5752 struct symbol
*sym
, *with_opaque
= NULL
;
5753 compunit_symtab
*stab
5754 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5755 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5756 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5758 sym
= block_find_symbol (block
, name
, domain
,
5759 block_find_non_opaque_type_preferred
,
5762 /* Some caution must be observed with overloaded functions and
5763 methods, since the index will not contain any overload
5764 information (but NAME might contain it). */
5767 && strcmp_iw (sym
->search_name (), name
) == 0)
5769 if (with_opaque
!= NULL
5770 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5773 /* Keep looking through other CUs. */
5779 /* This dumps minimal information about .debug_names. It is called
5780 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5781 uses this to verify that .debug_names has been loaded. */
5784 dw2_debug_names_dump (struct objfile
*objfile
)
5786 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5788 gdb_assert (per_objfile
->per_bfd
->using_index
);
5789 printf_filtered (".debug_names:");
5790 if (per_objfile
->per_bfd
->debug_names_table
)
5791 printf_filtered (" exists\n");
5793 printf_filtered (" faked for \"readnow\"\n");
5794 printf_filtered ("\n");
5798 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5799 const char *func_name
)
5801 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5803 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5804 if (per_objfile
->per_bfd
->debug_names_table
)
5806 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5808 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5811 struct dwarf2_per_cu_data
*per_cu
;
5812 while ((per_cu
= iter
.next ()) != NULL
)
5813 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5818 dw2_debug_names_map_matching_symbols
5819 (struct objfile
*objfile
,
5820 const lookup_name_info
&name
, domain_enum domain
,
5822 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5823 symbol_compare_ftype
*ordered_compare
)
5825 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5827 /* debug_names_table is NULL if OBJF_READNOW. */
5828 if (!per_objfile
->per_bfd
->debug_names_table
)
5831 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5832 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5834 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5835 auto matcher
= [&] (const char *symname
)
5837 if (ordered_compare
== nullptr)
5839 return ordered_compare (symname
, match_name
) == 0;
5842 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5843 [&] (offset_type namei
)
5845 /* The name was matched, now expand corresponding CUs that were
5847 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5850 struct dwarf2_per_cu_data
*per_cu
;
5851 while ((per_cu
= iter
.next ()) != NULL
)
5852 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5857 /* It's a shame we couldn't do this inside the
5858 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5859 that have already been expanded. Instead, this loop matches what
5860 the psymtab code does. */
5861 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5863 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5864 if (symtab
!= nullptr)
5866 const struct block
*block
5867 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5868 if (!iterate_over_symbols_terminated (block
, name
,
5876 dw2_debug_names_expand_symtabs_matching
5877 (struct objfile
*objfile
,
5878 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5879 const lookup_name_info
*lookup_name
,
5880 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5881 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5882 enum search_domain kind
)
5884 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5886 /* debug_names_table is NULL if OBJF_READNOW. */
5887 if (!per_objfile
->per_bfd
->debug_names_table
)
5890 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5892 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5894 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5898 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5904 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5906 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5908 kind
, [&] (offset_type namei
)
5910 /* The name was matched, now expand corresponding CUs that were
5912 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5914 struct dwarf2_per_cu_data
*per_cu
;
5915 while ((per_cu
= iter
.next ()) != NULL
)
5916 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5922 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5925 dw2_find_last_source_symtab
,
5926 dw2_forget_cached_source_info
,
5927 dw2_map_symtabs_matching_filename
,
5928 dw2_debug_names_lookup_symbol
,
5931 dw2_debug_names_dump
,
5932 dw2_debug_names_expand_symtabs_for_function
,
5933 dw2_expand_all_symtabs
,
5934 dw2_expand_symtabs_with_fullname
,
5935 dw2_debug_names_map_matching_symbols
,
5936 dw2_debug_names_expand_symtabs_matching
,
5937 dw2_find_pc_sect_compunit_symtab
,
5939 dw2_map_symbol_filenames
5942 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5943 to either a dwarf2_per_bfd or dwz_file object. */
5945 template <typename T
>
5946 static gdb::array_view
<const gdb_byte
>
5947 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5949 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5951 if (section
->empty ())
5954 /* Older elfutils strip versions could keep the section in the main
5955 executable while splitting it for the separate debug info file. */
5956 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5959 section
->read (obj
);
5961 /* dwarf2_section_info::size is a bfd_size_type, while
5962 gdb::array_view works with size_t. On 32-bit hosts, with
5963 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5964 is 32-bit. So we need an explicit narrowing conversion here.
5965 This is fine, because it's impossible to allocate or mmap an
5966 array/buffer larger than what size_t can represent. */
5967 return gdb::make_array_view (section
->buffer
, section
->size
);
5970 /* Lookup the index cache for the contents of the index associated to
5973 static gdb::array_view
<const gdb_byte
>
5974 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5976 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5977 if (build_id
== nullptr)
5980 return global_index_cache
.lookup_gdb_index (build_id
,
5981 &dwarf2_per_bfd
->index_cache_res
);
5984 /* Same as the above, but for DWZ. */
5986 static gdb::array_view
<const gdb_byte
>
5987 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5989 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5990 if (build_id
== nullptr)
5993 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5996 /* See symfile.h. */
5999 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6001 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6002 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6004 /* If we're about to read full symbols, don't bother with the
6005 indices. In this case we also don't care if some other debug
6006 format is making psymtabs, because they are all about to be
6008 if ((objfile
->flags
& OBJF_READNOW
))
6010 /* When using READNOW, the using_index flag (set below) indicates that
6011 PER_BFD was already initialized, when we loaded some other objfile. */
6012 if (per_bfd
->using_index
)
6014 *index_kind
= dw_index_kind::GDB_INDEX
;
6015 per_objfile
->resize_symtabs ();
6019 per_bfd
->using_index
= 1;
6020 create_all_comp_units (per_objfile
);
6021 create_all_type_units (per_objfile
);
6022 per_bfd
->quick_file_names_table
6023 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
6024 per_objfile
->resize_symtabs ();
6026 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
6027 + per_bfd
->all_type_units
.size ()); ++i
)
6029 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
6031 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6032 struct dwarf2_per_cu_quick_data
);
6035 /* Return 1 so that gdb sees the "quick" functions. However,
6036 these functions will be no-ops because we will have expanded
6038 *index_kind
= dw_index_kind::GDB_INDEX
;
6042 /* Was a debug names index already read when we processed an objfile sharing
6044 if (per_bfd
->debug_names_table
!= nullptr)
6046 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6047 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6048 per_objfile
->resize_symtabs ();
6052 /* Was a GDB index already read when we processed an objfile sharing
6054 if (per_bfd
->index_table
!= nullptr)
6056 *index_kind
= dw_index_kind::GDB_INDEX
;
6057 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6058 per_objfile
->resize_symtabs ();
6062 /* There might already be partial symtabs built for this BFD. This happens
6063 when loading the same binary twice with the index-cache enabled. If so,
6064 don't try to read an index. The objfile / per_objfile initialization will
6065 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
6067 if (per_bfd
->partial_symtabs
!= nullptr)
6070 if (dwarf2_read_debug_names (per_objfile
))
6072 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6073 per_objfile
->resize_symtabs ();
6077 if (dwarf2_read_gdb_index (per_objfile
,
6078 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6079 get_gdb_index_contents_from_section
<dwz_file
>))
6081 *index_kind
= dw_index_kind::GDB_INDEX
;
6082 per_objfile
->resize_symtabs ();
6086 /* ... otherwise, try to find the index in the index cache. */
6087 if (dwarf2_read_gdb_index (per_objfile
,
6088 get_gdb_index_contents_from_cache
,
6089 get_gdb_index_contents_from_cache_dwz
))
6091 global_index_cache
.hit ();
6092 *index_kind
= dw_index_kind::GDB_INDEX
;
6093 per_objfile
->resize_symtabs ();
6097 global_index_cache
.miss ();
6103 /* Build a partial symbol table. */
6106 dwarf2_build_psymtabs (struct objfile
*objfile
)
6108 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6109 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6111 if (per_bfd
->partial_symtabs
!= nullptr)
6113 /* Partial symbols were already read, so now we can simply
6115 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6116 per_objfile
->resize_symtabs ();
6120 init_psymbol_list (objfile
, 1024);
6124 /* This isn't really ideal: all the data we allocate on the
6125 objfile's obstack is still uselessly kept around. However,
6126 freeing it seems unsafe. */
6127 psymtab_discarder
psymtabs (objfile
);
6128 dwarf2_build_psymtabs_hard (per_objfile
);
6131 per_objfile
->resize_symtabs ();
6133 /* (maybe) store an index in the cache. */
6134 global_index_cache
.store (per_objfile
);
6136 catch (const gdb_exception_error
&except
)
6138 exception_print (gdb_stderr
, except
);
6141 /* Finish by setting the local reference to partial symtabs, so that
6142 we don't try to read them again if reading another objfile with the same
6143 BFD. If we can't in fact share, this won't make a difference anyway as
6144 the dwarf2_per_bfd object won't be shared. */
6145 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6148 /* Find the base address of the compilation unit for range lists and
6149 location lists. It will normally be specified by DW_AT_low_pc.
6150 In DWARF-3 draft 4, the base address could be overridden by
6151 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6152 compilation units with discontinuous ranges. */
6155 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6157 struct attribute
*attr
;
6159 cu
->base_address
.reset ();
6161 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6162 if (attr
!= nullptr)
6163 cu
->base_address
= attr
->as_address ();
6166 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6167 if (attr
!= nullptr)
6168 cu
->base_address
= attr
->as_address ();
6172 /* Helper function that returns the proper abbrev section for
6175 static struct dwarf2_section_info
*
6176 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6178 struct dwarf2_section_info
*abbrev
;
6179 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6181 if (this_cu
->is_dwz
)
6182 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6184 abbrev
= &per_bfd
->abbrev
;
6189 /* Fetch the abbreviation table offset from a comp or type unit header. */
6192 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6193 struct dwarf2_section_info
*section
,
6194 sect_offset sect_off
)
6196 bfd
*abfd
= section
->get_bfd_owner ();
6197 const gdb_byte
*info_ptr
;
6198 unsigned int initial_length_size
, offset_size
;
6201 section
->read (per_objfile
->objfile
);
6202 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6203 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6204 offset_size
= initial_length_size
== 4 ? 4 : 8;
6205 info_ptr
+= initial_length_size
;
6207 version
= read_2_bytes (abfd
, info_ptr
);
6211 /* Skip unit type and address size. */
6215 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6218 /* A partial symtab that is used only for include files. */
6219 struct dwarf2_include_psymtab
: public partial_symtab
6221 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6222 : partial_symtab (filename
, objfile
)
6226 void read_symtab (struct objfile
*objfile
) override
6228 /* It's an include file, no symbols to read for it.
6229 Everything is in the includer symtab. */
6231 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6232 expansion of the includer psymtab. We use the dependencies[0] field to
6233 model the includer. But if we go the regular route of calling
6234 expand_psymtab here, and having expand_psymtab call expand_dependencies
6235 to expand the includer, we'll only use expand_psymtab on the includer
6236 (making it a non-toplevel psymtab), while if we expand the includer via
6237 another path, we'll use read_symtab (making it a toplevel psymtab).
6238 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6239 psymtab, and trigger read_symtab on the includer here directly. */
6240 includer ()->read_symtab (objfile
);
6243 void expand_psymtab (struct objfile
*objfile
) override
6245 /* This is not called by read_symtab, and should not be called by any
6246 expand_dependencies. */
6250 bool readin_p (struct objfile
*objfile
) const override
6252 return includer ()->readin_p (objfile
);
6255 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6261 partial_symtab
*includer () const
6263 /* An include psymtab has exactly one dependency: the psymtab that
6265 gdb_assert (this->number_of_dependencies
== 1);
6266 return this->dependencies
[0];
6270 /* Allocate a new partial symtab for file named NAME and mark this new
6271 partial symtab as being an include of PST. */
6274 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6275 struct objfile
*objfile
)
6277 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6279 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6280 subpst
->dirname
= pst
->dirname
;
6282 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6283 subpst
->dependencies
[0] = pst
;
6284 subpst
->number_of_dependencies
= 1;
6287 /* Read the Line Number Program data and extract the list of files
6288 included by the source file represented by PST. Build an include
6289 partial symtab for each of these included files. */
6292 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6293 struct die_info
*die
,
6294 dwarf2_psymtab
*pst
)
6297 struct attribute
*attr
;
6299 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6300 if (attr
!= nullptr)
6301 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6303 return; /* No linetable, so no includes. */
6305 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6306 that we pass in the raw text_low here; that is ok because we're
6307 only decoding the line table to make include partial symtabs, and
6308 so the addresses aren't really used. */
6309 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6310 pst
->raw_text_low (), 1);
6314 hash_signatured_type (const void *item
)
6316 const struct signatured_type
*sig_type
6317 = (const struct signatured_type
*) item
;
6319 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6320 return sig_type
->signature
;
6324 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6326 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6327 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6329 return lhs
->signature
== rhs
->signature
;
6332 /* Allocate a hash table for signatured types. */
6335 allocate_signatured_type_table ()
6337 return htab_up (htab_create_alloc (41,
6338 hash_signatured_type
,
6340 NULL
, xcalloc
, xfree
));
6343 /* A helper function to add a signatured type CU to a table. */
6346 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6348 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6349 std::vector
<signatured_type
*> *all_type_units
6350 = (std::vector
<signatured_type
*> *) datum
;
6352 all_type_units
->push_back (sigt
);
6357 /* A helper for create_debug_types_hash_table. Read types from SECTION
6358 and fill them into TYPES_HTAB. It will process only type units,
6359 therefore DW_UT_type. */
6362 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6363 struct dwo_file
*dwo_file
,
6364 dwarf2_section_info
*section
, htab_up
&types_htab
,
6365 rcuh_kind section_kind
)
6367 struct objfile
*objfile
= per_objfile
->objfile
;
6368 struct dwarf2_section_info
*abbrev_section
;
6370 const gdb_byte
*info_ptr
, *end_ptr
;
6372 abbrev_section
= (dwo_file
!= NULL
6373 ? &dwo_file
->sections
.abbrev
6374 : &per_objfile
->per_bfd
->abbrev
);
6376 if (dwarf_read_debug
)
6377 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6378 section
->get_name (),
6379 abbrev_section
->get_file_name ());
6381 section
->read (objfile
);
6382 info_ptr
= section
->buffer
;
6384 if (info_ptr
== NULL
)
6387 /* We can't set abfd until now because the section may be empty or
6388 not present, in which case the bfd is unknown. */
6389 abfd
= section
->get_bfd_owner ();
6391 /* We don't use cutu_reader here because we don't need to read
6392 any dies: the signature is in the header. */
6394 end_ptr
= info_ptr
+ section
->size
;
6395 while (info_ptr
< end_ptr
)
6397 struct signatured_type
*sig_type
;
6398 struct dwo_unit
*dwo_tu
;
6400 const gdb_byte
*ptr
= info_ptr
;
6401 struct comp_unit_head header
;
6402 unsigned int length
;
6404 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6406 /* Initialize it due to a false compiler warning. */
6407 header
.signature
= -1;
6408 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6410 /* We need to read the type's signature in order to build the hash
6411 table, but we don't need anything else just yet. */
6413 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6414 abbrev_section
, ptr
, section_kind
);
6416 length
= header
.get_length ();
6418 /* Skip dummy type units. */
6419 if (ptr
>= info_ptr
+ length
6420 || peek_abbrev_code (abfd
, ptr
) == 0
6421 || (header
.unit_type
!= DW_UT_type
6422 && header
.unit_type
!= DW_UT_split_type
))
6428 if (types_htab
== NULL
)
6431 types_htab
= allocate_dwo_unit_table ();
6433 types_htab
= allocate_signatured_type_table ();
6439 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6440 dwo_tu
->dwo_file
= dwo_file
;
6441 dwo_tu
->signature
= header
.signature
;
6442 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6443 dwo_tu
->section
= section
;
6444 dwo_tu
->sect_off
= sect_off
;
6445 dwo_tu
->length
= length
;
6449 /* N.B.: type_offset is not usable if this type uses a DWO file.
6450 The real type_offset is in the DWO file. */
6452 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6453 sig_type
->signature
= header
.signature
;
6454 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6455 sig_type
->per_cu
.is_debug_types
= 1;
6456 sig_type
->per_cu
.section
= section
;
6457 sig_type
->per_cu
.sect_off
= sect_off
;
6458 sig_type
->per_cu
.length
= length
;
6461 slot
= htab_find_slot (types_htab
.get (),
6462 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6464 gdb_assert (slot
!= NULL
);
6467 sect_offset dup_sect_off
;
6471 const struct dwo_unit
*dup_tu
6472 = (const struct dwo_unit
*) *slot
;
6474 dup_sect_off
= dup_tu
->sect_off
;
6478 const struct signatured_type
*dup_tu
6479 = (const struct signatured_type
*) *slot
;
6481 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6484 complaint (_("debug type entry at offset %s is duplicate to"
6485 " the entry at offset %s, signature %s"),
6486 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6487 hex_string (header
.signature
));
6489 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6491 if (dwarf_read_debug
> 1)
6492 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6493 sect_offset_str (sect_off
),
6494 hex_string (header
.signature
));
6500 /* Create the hash table of all entries in the .debug_types
6501 (or .debug_types.dwo) section(s).
6502 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6503 otherwise it is NULL.
6505 The result is a pointer to the hash table or NULL if there are no types.
6507 Note: This function processes DWO files only, not DWP files. */
6510 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6511 struct dwo_file
*dwo_file
,
6512 gdb::array_view
<dwarf2_section_info
> type_sections
,
6513 htab_up
&types_htab
)
6515 for (dwarf2_section_info
§ion
: type_sections
)
6516 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6520 /* Create the hash table of all entries in the .debug_types section,
6521 and initialize all_type_units.
6522 The result is zero if there is an error (e.g. missing .debug_types section),
6523 otherwise non-zero. */
6526 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6530 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6531 types_htab
, rcuh_kind::COMPILE
);
6532 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6534 if (types_htab
== NULL
)
6536 per_objfile
->per_bfd
->signatured_types
= NULL
;
6540 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6542 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6543 per_objfile
->per_bfd
->all_type_units
.reserve
6544 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6546 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6547 add_signatured_type_cu_to_table
,
6548 &per_objfile
->per_bfd
->all_type_units
);
6553 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6554 If SLOT is non-NULL, it is the entry to use in the hash table.
6555 Otherwise we find one. */
6557 static struct signatured_type
*
6558 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6560 if (per_objfile
->per_bfd
->all_type_units
.size ()
6561 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6562 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6564 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6566 per_objfile
->resize_symtabs ();
6568 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6569 sig_type
->signature
= sig
;
6570 sig_type
->per_cu
.is_debug_types
= 1;
6571 if (per_objfile
->per_bfd
->using_index
)
6573 sig_type
->per_cu
.v
.quick
=
6574 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6575 struct dwarf2_per_cu_quick_data
);
6580 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6583 gdb_assert (*slot
== NULL
);
6585 /* The rest of sig_type must be filled in by the caller. */
6589 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6590 Fill in SIG_ENTRY with DWO_ENTRY. */
6593 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6594 struct signatured_type
*sig_entry
,
6595 struct dwo_unit
*dwo_entry
)
6597 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6599 /* Make sure we're not clobbering something we don't expect to. */
6600 gdb_assert (! sig_entry
->per_cu
.queued
);
6601 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6602 if (per_bfd
->using_index
)
6604 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6605 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6608 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6609 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6610 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6611 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6612 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6614 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6615 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6616 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6617 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6618 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6619 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6620 sig_entry
->dwo_unit
= dwo_entry
;
6623 /* Subroutine of lookup_signatured_type.
6624 If we haven't read the TU yet, create the signatured_type data structure
6625 for a TU to be read in directly from a DWO file, bypassing the stub.
6626 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6627 using .gdb_index, then when reading a CU we want to stay in the DWO file
6628 containing that CU. Otherwise we could end up reading several other DWO
6629 files (due to comdat folding) to process the transitive closure of all the
6630 mentioned TUs, and that can be slow. The current DWO file will have every
6631 type signature that it needs.
6632 We only do this for .gdb_index because in the psymtab case we already have
6633 to read all the DWOs to build the type unit groups. */
6635 static struct signatured_type
*
6636 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6638 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6639 struct dwo_file
*dwo_file
;
6640 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6641 struct signatured_type find_sig_entry
, *sig_entry
;
6644 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6646 /* If TU skeletons have been removed then we may not have read in any
6648 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6649 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6651 /* We only ever need to read in one copy of a signatured type.
6652 Use the global signatured_types array to do our own comdat-folding
6653 of types. If this is the first time we're reading this TU, and
6654 the TU has an entry in .gdb_index, replace the recorded data from
6655 .gdb_index with this TU. */
6657 find_sig_entry
.signature
= sig
;
6658 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6659 &find_sig_entry
, INSERT
);
6660 sig_entry
= (struct signatured_type
*) *slot
;
6662 /* We can get here with the TU already read, *or* in the process of being
6663 read. Don't reassign the global entry to point to this DWO if that's
6664 the case. Also note that if the TU is already being read, it may not
6665 have come from a DWO, the program may be a mix of Fission-compiled
6666 code and non-Fission-compiled code. */
6668 /* Have we already tried to read this TU?
6669 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6670 needn't exist in the global table yet). */
6671 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6674 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6675 dwo_unit of the TU itself. */
6676 dwo_file
= cu
->dwo_unit
->dwo_file
;
6678 /* Ok, this is the first time we're reading this TU. */
6679 if (dwo_file
->tus
== NULL
)
6681 find_dwo_entry
.signature
= sig
;
6682 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6684 if (dwo_entry
== NULL
)
6687 /* If the global table doesn't have an entry for this TU, add one. */
6688 if (sig_entry
== NULL
)
6689 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6691 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6692 sig_entry
->per_cu
.tu_read
= 1;
6696 /* Subroutine of lookup_signatured_type.
6697 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6698 then try the DWP file. If the TU stub (skeleton) has been removed then
6699 it won't be in .gdb_index. */
6701 static struct signatured_type
*
6702 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6704 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6705 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6706 struct dwo_unit
*dwo_entry
;
6707 struct signatured_type find_sig_entry
, *sig_entry
;
6710 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6711 gdb_assert (dwp_file
!= NULL
);
6713 /* If TU skeletons have been removed then we may not have read in any
6715 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6716 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6718 find_sig_entry
.signature
= sig
;
6719 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6720 &find_sig_entry
, INSERT
);
6721 sig_entry
= (struct signatured_type
*) *slot
;
6723 /* Have we already tried to read this TU?
6724 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6725 needn't exist in the global table yet). */
6726 if (sig_entry
!= NULL
)
6729 if (dwp_file
->tus
== NULL
)
6731 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6732 1 /* is_debug_types */);
6733 if (dwo_entry
== NULL
)
6736 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6737 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6742 /* Lookup a signature based type for DW_FORM_ref_sig8.
6743 Returns NULL if signature SIG is not present in the table.
6744 It is up to the caller to complain about this. */
6746 static struct signatured_type
*
6747 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6749 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6751 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6753 /* We're in a DWO/DWP file, and we're using .gdb_index.
6754 These cases require special processing. */
6755 if (get_dwp_file (per_objfile
) == NULL
)
6756 return lookup_dwo_signatured_type (cu
, sig
);
6758 return lookup_dwp_signatured_type (cu
, sig
);
6762 struct signatured_type find_entry
, *entry
;
6764 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6766 find_entry
.signature
= sig
;
6767 entry
= ((struct signatured_type
*)
6768 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6774 /* Low level DIE reading support. */
6776 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6779 init_cu_die_reader (struct die_reader_specs
*reader
,
6780 struct dwarf2_cu
*cu
,
6781 struct dwarf2_section_info
*section
,
6782 struct dwo_file
*dwo_file
,
6783 struct abbrev_table
*abbrev_table
)
6785 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6786 reader
->abfd
= section
->get_bfd_owner ();
6788 reader
->dwo_file
= dwo_file
;
6789 reader
->die_section
= section
;
6790 reader
->buffer
= section
->buffer
;
6791 reader
->buffer_end
= section
->buffer
+ section
->size
;
6792 reader
->abbrev_table
= abbrev_table
;
6795 /* Subroutine of cutu_reader to simplify it.
6796 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6797 There's just a lot of work to do, and cutu_reader is big enough
6800 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6801 from it to the DIE in the DWO. If NULL we are skipping the stub.
6802 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6803 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6804 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6805 STUB_COMP_DIR may be non-NULL.
6806 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6807 are filled in with the info of the DIE from the DWO file.
6808 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6809 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6810 kept around for at least as long as *RESULT_READER.
6812 The result is non-zero if a valid (non-dummy) DIE was found. */
6815 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6816 struct dwo_unit
*dwo_unit
,
6817 struct die_info
*stub_comp_unit_die
,
6818 const char *stub_comp_dir
,
6819 struct die_reader_specs
*result_reader
,
6820 const gdb_byte
**result_info_ptr
,
6821 struct die_info
**result_comp_unit_die
,
6822 abbrev_table_up
*result_dwo_abbrev_table
)
6824 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6825 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6826 struct objfile
*objfile
= per_objfile
->objfile
;
6828 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6829 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6830 int i
,num_extra_attrs
;
6831 struct dwarf2_section_info
*dwo_abbrev_section
;
6832 struct die_info
*comp_unit_die
;
6834 /* At most one of these may be provided. */
6835 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6837 /* These attributes aren't processed until later:
6838 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6839 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6840 referenced later. However, these attributes are found in the stub
6841 which we won't have later. In order to not impose this complication
6842 on the rest of the code, we read them here and copy them to the
6851 if (stub_comp_unit_die
!= NULL
)
6853 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6855 if (!per_cu
->is_debug_types
)
6856 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6857 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6858 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6859 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6860 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6862 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6864 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6865 here (if needed). We need the value before we can process
6867 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6869 else if (stub_comp_dir
!= NULL
)
6871 /* Reconstruct the comp_dir attribute to simplify the code below. */
6872 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6873 comp_dir
->name
= DW_AT_comp_dir
;
6874 comp_dir
->form
= DW_FORM_string
;
6875 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6878 /* Set up for reading the DWO CU/TU. */
6879 cu
->dwo_unit
= dwo_unit
;
6880 dwarf2_section_info
*section
= dwo_unit
->section
;
6881 section
->read (objfile
);
6882 abfd
= section
->get_bfd_owner ();
6883 begin_info_ptr
= info_ptr
= (section
->buffer
6884 + to_underlying (dwo_unit
->sect_off
));
6885 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6887 if (per_cu
->is_debug_types
)
6889 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6891 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6892 section
, dwo_abbrev_section
,
6893 info_ptr
, rcuh_kind::TYPE
);
6894 /* This is not an assert because it can be caused by bad debug info. */
6895 if (sig_type
->signature
!= cu
->header
.signature
)
6897 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6898 " TU at offset %s [in module %s]"),
6899 hex_string (sig_type
->signature
),
6900 hex_string (cu
->header
.signature
),
6901 sect_offset_str (dwo_unit
->sect_off
),
6902 bfd_get_filename (abfd
));
6904 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6905 /* For DWOs coming from DWP files, we don't know the CU length
6906 nor the type's offset in the TU until now. */
6907 dwo_unit
->length
= cu
->header
.get_length ();
6908 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6910 /* Establish the type offset that can be used to lookup the type.
6911 For DWO files, we don't know it until now. */
6912 sig_type
->type_offset_in_section
6913 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6917 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6918 section
, dwo_abbrev_section
,
6919 info_ptr
, rcuh_kind::COMPILE
);
6920 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6921 /* For DWOs coming from DWP files, we don't know the CU length
6923 dwo_unit
->length
= cu
->header
.get_length ();
6926 *result_dwo_abbrev_table
6927 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6928 cu
->header
.abbrev_sect_off
);
6929 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6930 result_dwo_abbrev_table
->get ());
6932 /* Read in the die, but leave space to copy over the attributes
6933 from the stub. This has the benefit of simplifying the rest of
6934 the code - all the work to maintain the illusion of a single
6935 DW_TAG_{compile,type}_unit DIE is done here. */
6936 num_extra_attrs
= ((stmt_list
!= NULL
)
6940 + (comp_dir
!= NULL
));
6941 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6944 /* Copy over the attributes from the stub to the DIE we just read in. */
6945 comp_unit_die
= *result_comp_unit_die
;
6946 i
= comp_unit_die
->num_attrs
;
6947 if (stmt_list
!= NULL
)
6948 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6950 comp_unit_die
->attrs
[i
++] = *low_pc
;
6951 if (high_pc
!= NULL
)
6952 comp_unit_die
->attrs
[i
++] = *high_pc
;
6954 comp_unit_die
->attrs
[i
++] = *ranges
;
6955 if (comp_dir
!= NULL
)
6956 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6957 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6959 if (dwarf_die_debug
)
6961 fprintf_unfiltered (gdb_stdlog
,
6962 "Read die from %s@0x%x of %s:\n",
6963 section
->get_name (),
6964 (unsigned) (begin_info_ptr
- section
->buffer
),
6965 bfd_get_filename (abfd
));
6966 dump_die (comp_unit_die
, dwarf_die_debug
);
6969 /* Skip dummy compilation units. */
6970 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6971 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6974 *result_info_ptr
= info_ptr
;
6978 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6979 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6980 signature is part of the header. */
6981 static gdb::optional
<ULONGEST
>
6982 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6984 if (cu
->header
.version
>= 5)
6985 return cu
->header
.signature
;
6986 struct attribute
*attr
;
6987 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6988 if (attr
== nullptr)
6989 return gdb::optional
<ULONGEST
> ();
6990 return DW_UNSND (attr
);
6993 /* Subroutine of cutu_reader to simplify it.
6994 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6995 Returns NULL if the specified DWO unit cannot be found. */
6997 static struct dwo_unit
*
6998 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
7000 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7001 struct dwo_unit
*dwo_unit
;
7002 const char *comp_dir
;
7004 gdb_assert (cu
!= NULL
);
7006 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7007 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7008 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7010 if (per_cu
->is_debug_types
)
7011 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
7014 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7016 if (!signature
.has_value ())
7017 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7019 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
7021 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
7027 /* Subroutine of cutu_reader to simplify it.
7028 See it for a description of the parameters.
7029 Read a TU directly from a DWO file, bypassing the stub. */
7032 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
7033 dwarf2_per_objfile
*per_objfile
,
7034 dwarf2_cu
*existing_cu
)
7036 struct signatured_type
*sig_type
;
7038 /* Verify we can do the following downcast, and that we have the
7040 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7041 sig_type
= (struct signatured_type
*) this_cu
;
7042 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7046 if (existing_cu
!= nullptr)
7049 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7050 /* There's no need to do the rereading_dwo_cu handling that
7051 cutu_reader does since we don't read the stub. */
7055 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7056 in per_objfile yet. */
7057 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7058 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7059 cu
= m_new_cu
.get ();
7062 /* A future optimization, if needed, would be to use an existing
7063 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7064 could share abbrev tables. */
7066 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7067 NULL
/* stub_comp_unit_die */,
7068 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7071 &m_dwo_abbrev_table
) == 0)
7078 /* Initialize a CU (or TU) and read its DIEs.
7079 If the CU defers to a DWO file, read the DWO file as well.
7081 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7082 Otherwise the table specified in the comp unit header is read in and used.
7083 This is an optimization for when we already have the abbrev table.
7085 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7088 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7089 dwarf2_per_objfile
*per_objfile
,
7090 struct abbrev_table
*abbrev_table
,
7091 dwarf2_cu
*existing_cu
,
7093 : die_reader_specs
{},
7096 struct objfile
*objfile
= per_objfile
->objfile
;
7097 struct dwarf2_section_info
*section
= this_cu
->section
;
7098 bfd
*abfd
= section
->get_bfd_owner ();
7099 const gdb_byte
*begin_info_ptr
;
7100 struct signatured_type
*sig_type
= NULL
;
7101 struct dwarf2_section_info
*abbrev_section
;
7102 /* Non-zero if CU currently points to a DWO file and we need to
7103 reread it. When this happens we need to reread the skeleton die
7104 before we can reread the DWO file (this only applies to CUs, not TUs). */
7105 int rereading_dwo_cu
= 0;
7107 if (dwarf_die_debug
)
7108 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7109 this_cu
->is_debug_types
? "type" : "comp",
7110 sect_offset_str (this_cu
->sect_off
));
7112 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7113 file (instead of going through the stub), short-circuit all of this. */
7114 if (this_cu
->reading_dwo_directly
)
7116 /* Narrow down the scope of possibilities to have to understand. */
7117 gdb_assert (this_cu
->is_debug_types
);
7118 gdb_assert (abbrev_table
== NULL
);
7119 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7123 /* This is cheap if the section is already read in. */
7124 section
->read (objfile
);
7126 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7128 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7132 if (existing_cu
!= nullptr)
7135 /* If this CU is from a DWO file we need to start over, we need to
7136 refetch the attributes from the skeleton CU.
7137 This could be optimized by retrieving those attributes from when we
7138 were here the first time: the previous comp_unit_die was stored in
7139 comp_unit_obstack. But there's no data yet that we need this
7141 if (cu
->dwo_unit
!= NULL
)
7142 rereading_dwo_cu
= 1;
7146 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7147 in per_objfile yet. */
7148 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7149 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7150 cu
= m_new_cu
.get ();
7153 /* Get the header. */
7154 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7156 /* We already have the header, there's no need to read it in again. */
7157 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7161 if (this_cu
->is_debug_types
)
7163 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7164 section
, abbrev_section
,
7165 info_ptr
, rcuh_kind::TYPE
);
7167 /* Since per_cu is the first member of struct signatured_type,
7168 we can go from a pointer to one to a pointer to the other. */
7169 sig_type
= (struct signatured_type
*) this_cu
;
7170 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7171 gdb_assert (sig_type
->type_offset_in_tu
7172 == cu
->header
.type_cu_offset_in_tu
);
7173 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7175 /* LENGTH has not been set yet for type units if we're
7176 using .gdb_index. */
7177 this_cu
->length
= cu
->header
.get_length ();
7179 /* Establish the type offset that can be used to lookup the type. */
7180 sig_type
->type_offset_in_section
=
7181 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7183 this_cu
->dwarf_version
= cu
->header
.version
;
7187 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7188 section
, abbrev_section
,
7190 rcuh_kind::COMPILE
);
7192 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7193 if (this_cu
->length
== 0)
7194 this_cu
->length
= cu
->header
.get_length ();
7196 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7197 this_cu
->dwarf_version
= cu
->header
.version
;
7201 /* Skip dummy compilation units. */
7202 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7203 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7209 /* If we don't have them yet, read the abbrevs for this compilation unit.
7210 And if we need to read them now, make sure they're freed when we're
7212 if (abbrev_table
!= NULL
)
7213 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7216 m_abbrev_table_holder
7217 = abbrev_table::read (objfile
, abbrev_section
,
7218 cu
->header
.abbrev_sect_off
);
7219 abbrev_table
= m_abbrev_table_holder
.get ();
7222 /* Read the top level CU/TU die. */
7223 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7224 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7226 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7232 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7233 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7234 table from the DWO file and pass the ownership over to us. It will be
7235 referenced from READER, so we must make sure to free it after we're done
7238 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7239 DWO CU, that this test will fail (the attribute will not be present). */
7240 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7241 if (dwo_name
!= nullptr)
7243 struct dwo_unit
*dwo_unit
;
7244 struct die_info
*dwo_comp_unit_die
;
7246 if (comp_unit_die
->has_children
)
7248 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7249 " has children (offset %s) [in module %s]"),
7250 sect_offset_str (this_cu
->sect_off
),
7251 bfd_get_filename (abfd
));
7253 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7254 if (dwo_unit
!= NULL
)
7256 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7257 comp_unit_die
, NULL
,
7260 &m_dwo_abbrev_table
) == 0)
7266 comp_unit_die
= dwo_comp_unit_die
;
7270 /* Yikes, we couldn't find the rest of the DIE, we only have
7271 the stub. A complaint has already been logged. There's
7272 not much more we can do except pass on the stub DIE to
7273 die_reader_func. We don't want to throw an error on bad
7280 cutu_reader::keep ()
7282 /* Done, clean up. */
7283 gdb_assert (!dummy_p
);
7284 if (m_new_cu
!= NULL
)
7286 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7288 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7289 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7293 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7294 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7295 assumed to have already done the lookup to find the DWO file).
7297 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7298 THIS_CU->is_debug_types, but nothing else.
7300 We fill in THIS_CU->length.
7302 THIS_CU->cu is always freed when done.
7303 This is done in order to not leave THIS_CU->cu in a state where we have
7304 to care whether it refers to the "main" CU or the DWO CU.
7306 When parent_cu is passed, it is used to provide a default value for
7307 str_offsets_base and addr_base from the parent. */
7309 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7310 dwarf2_per_objfile
*per_objfile
,
7311 struct dwarf2_cu
*parent_cu
,
7312 struct dwo_file
*dwo_file
)
7313 : die_reader_specs
{},
7316 struct objfile
*objfile
= per_objfile
->objfile
;
7317 struct dwarf2_section_info
*section
= this_cu
->section
;
7318 bfd
*abfd
= section
->get_bfd_owner ();
7319 struct dwarf2_section_info
*abbrev_section
;
7320 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7322 if (dwarf_die_debug
)
7323 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7324 this_cu
->is_debug_types
? "type" : "comp",
7325 sect_offset_str (this_cu
->sect_off
));
7327 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7329 abbrev_section
= (dwo_file
!= NULL
7330 ? &dwo_file
->sections
.abbrev
7331 : get_abbrev_section_for_cu (this_cu
));
7333 /* This is cheap if the section is already read in. */
7334 section
->read (objfile
);
7336 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7338 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7339 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7340 section
, abbrev_section
, info_ptr
,
7341 (this_cu
->is_debug_types
7343 : rcuh_kind::COMPILE
));
7345 if (parent_cu
!= nullptr)
7347 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7348 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7350 this_cu
->length
= m_new_cu
->header
.get_length ();
7352 /* Skip dummy compilation units. */
7353 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7354 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7360 m_abbrev_table_holder
7361 = abbrev_table::read (objfile
, abbrev_section
,
7362 m_new_cu
->header
.abbrev_sect_off
);
7364 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7365 m_abbrev_table_holder
.get ());
7366 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7370 /* Type Unit Groups.
7372 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7373 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7374 so that all types coming from the same compilation (.o file) are grouped
7375 together. A future step could be to put the types in the same symtab as
7376 the CU the types ultimately came from. */
7379 hash_type_unit_group (const void *item
)
7381 const struct type_unit_group
*tu_group
7382 = (const struct type_unit_group
*) item
;
7384 return hash_stmt_list_entry (&tu_group
->hash
);
7388 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7390 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7391 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7393 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7396 /* Allocate a hash table for type unit groups. */
7399 allocate_type_unit_groups_table ()
7401 return htab_up (htab_create_alloc (3,
7402 hash_type_unit_group
,
7404 NULL
, xcalloc
, xfree
));
7407 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7408 partial symtabs. We combine several TUs per psymtab to not let the size
7409 of any one psymtab grow too big. */
7410 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7411 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7413 /* Helper routine for get_type_unit_group.
7414 Create the type_unit_group object used to hold one or more TUs. */
7416 static struct type_unit_group
*
7417 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7419 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7420 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7421 struct dwarf2_per_cu_data
*per_cu
;
7422 struct type_unit_group
*tu_group
;
7424 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7425 per_cu
= &tu_group
->per_cu
;
7426 per_cu
->per_bfd
= per_bfd
;
7428 if (per_bfd
->using_index
)
7430 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7431 struct dwarf2_per_cu_quick_data
);
7435 unsigned int line_offset
= to_underlying (line_offset_struct
);
7436 dwarf2_psymtab
*pst
;
7439 /* Give the symtab a useful name for debug purposes. */
7440 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7441 name
= string_printf ("<type_units_%d>",
7442 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7444 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7446 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7447 pst
->anonymous
= true;
7450 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7451 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7456 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7457 STMT_LIST is a DW_AT_stmt_list attribute. */
7459 static struct type_unit_group
*
7460 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7462 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7463 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7464 struct type_unit_group
*tu_group
;
7466 unsigned int line_offset
;
7467 struct type_unit_group type_unit_group_for_lookup
;
7469 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7470 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7472 /* Do we need to create a new group, or can we use an existing one? */
7476 line_offset
= DW_UNSND (stmt_list
);
7477 ++tu_stats
->nr_symtab_sharers
;
7481 /* Ugh, no stmt_list. Rare, but we have to handle it.
7482 We can do various things here like create one group per TU or
7483 spread them over multiple groups to split up the expansion work.
7484 To avoid worst case scenarios (too many groups or too large groups)
7485 we, umm, group them in bunches. */
7486 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7487 | (tu_stats
->nr_stmt_less_type_units
7488 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7489 ++tu_stats
->nr_stmt_less_type_units
;
7492 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7493 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7494 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7495 &type_unit_group_for_lookup
, INSERT
);
7498 tu_group
= (struct type_unit_group
*) *slot
;
7499 gdb_assert (tu_group
!= NULL
);
7503 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7504 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7506 ++tu_stats
->nr_symtabs
;
7512 /* Partial symbol tables. */
7514 /* Create a psymtab named NAME and assign it to PER_CU.
7516 The caller must fill in the following details:
7517 dirname, textlow, texthigh. */
7519 static dwarf2_psymtab
*
7520 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7521 dwarf2_per_objfile
*per_objfile
,
7524 struct objfile
*objfile
= per_objfile
->objfile
;
7525 dwarf2_psymtab
*pst
;
7527 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7529 pst
->psymtabs_addrmap_supported
= true;
7531 /* This is the glue that links PST into GDB's symbol API. */
7532 per_cu
->v
.psymtab
= pst
;
7537 /* DIE reader function for process_psymtab_comp_unit. */
7540 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7541 const gdb_byte
*info_ptr
,
7542 struct die_info
*comp_unit_die
,
7543 enum language pretend_language
)
7545 struct dwarf2_cu
*cu
= reader
->cu
;
7546 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7547 struct objfile
*objfile
= per_objfile
->objfile
;
7548 struct gdbarch
*gdbarch
= objfile
->arch ();
7549 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7551 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7552 dwarf2_psymtab
*pst
;
7553 enum pc_bounds_kind cu_bounds_kind
;
7554 const char *filename
;
7556 gdb_assert (! per_cu
->is_debug_types
);
7558 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7560 /* Allocate a new partial symbol table structure. */
7561 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7562 static const char artificial
[] = "<artificial>";
7563 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7564 if (filename
== NULL
)
7566 else if (strcmp (filename
, artificial
) == 0)
7568 debug_filename
.reset (concat (artificial
, "@",
7569 sect_offset_str (per_cu
->sect_off
),
7571 filename
= debug_filename
.get ();
7574 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7576 /* This must be done before calling dwarf2_build_include_psymtabs. */
7577 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7579 baseaddr
= objfile
->text_section_offset ();
7581 dwarf2_find_base_address (comp_unit_die
, cu
);
7583 /* Possibly set the default values of LOWPC and HIGHPC from
7585 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7586 &best_highpc
, cu
, pst
);
7587 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7590 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7593 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7595 /* Store the contiguous range if it is not empty; it can be
7596 empty for CUs with no code. */
7597 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7601 /* Check if comp unit has_children.
7602 If so, read the rest of the partial symbols from this comp unit.
7603 If not, there's no more debug_info for this comp unit. */
7604 if (comp_unit_die
->has_children
)
7606 struct partial_die_info
*first_die
;
7607 CORE_ADDR lowpc
, highpc
;
7609 lowpc
= ((CORE_ADDR
) -1);
7610 highpc
= ((CORE_ADDR
) 0);
7612 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7614 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7615 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7617 /* If we didn't find a lowpc, set it to highpc to avoid
7618 complaints from `maint check'. */
7619 if (lowpc
== ((CORE_ADDR
) -1))
7622 /* If the compilation unit didn't have an explicit address range,
7623 then use the information extracted from its child dies. */
7624 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7627 best_highpc
= highpc
;
7630 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7631 best_lowpc
+ baseaddr
)
7633 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7634 best_highpc
+ baseaddr
)
7637 end_psymtab_common (objfile
, pst
);
7639 if (!cu
->per_cu
->imported_symtabs_empty ())
7642 int len
= cu
->per_cu
->imported_symtabs_size ();
7644 /* Fill in 'dependencies' here; we fill in 'users' in a
7646 pst
->number_of_dependencies
= len
;
7648 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7649 for (i
= 0; i
< len
; ++i
)
7651 pst
->dependencies
[i
]
7652 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7655 cu
->per_cu
->imported_symtabs_free ();
7658 /* Get the list of files included in the current compilation unit,
7659 and build a psymtab for each of them. */
7660 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7662 if (dwarf_read_debug
)
7663 fprintf_unfiltered (gdb_stdlog
,
7664 "Psymtab for %s unit @%s: %s - %s"
7665 ", %d global, %d static syms\n",
7666 per_cu
->is_debug_types
? "type" : "comp",
7667 sect_offset_str (per_cu
->sect_off
),
7668 paddress (gdbarch
, pst
->text_low (objfile
)),
7669 paddress (gdbarch
, pst
->text_high (objfile
)),
7670 pst
->n_global_syms
, pst
->n_static_syms
);
7673 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7674 Process compilation unit THIS_CU for a psymtab. */
7677 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7678 dwarf2_per_objfile
*per_objfile
,
7679 bool want_partial_unit
,
7680 enum language pretend_language
)
7682 /* If this compilation unit was already read in, free the
7683 cached copy in order to read it in again. This is
7684 necessary because we skipped some symbols when we first
7685 read in the compilation unit (see load_partial_dies).
7686 This problem could be avoided, but the benefit is unclear. */
7687 per_objfile
->remove_cu (this_cu
);
7689 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7691 switch (reader
.comp_unit_die
->tag
)
7693 case DW_TAG_compile_unit
:
7694 this_cu
->unit_type
= DW_UT_compile
;
7696 case DW_TAG_partial_unit
:
7697 this_cu
->unit_type
= DW_UT_partial
;
7707 else if (this_cu
->is_debug_types
)
7708 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7709 reader
.comp_unit_die
);
7710 else if (want_partial_unit
7711 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7712 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7713 reader
.comp_unit_die
,
7716 this_cu
->lang
= reader
.cu
->language
;
7718 /* Age out any secondary CUs. */
7719 per_objfile
->age_comp_units ();
7722 /* Reader function for build_type_psymtabs. */
7725 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7726 const gdb_byte
*info_ptr
,
7727 struct die_info
*type_unit_die
)
7729 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7730 struct objfile
*objfile
= per_objfile
->objfile
;
7731 struct dwarf2_cu
*cu
= reader
->cu
;
7732 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7733 struct signatured_type
*sig_type
;
7734 struct type_unit_group
*tu_group
;
7735 struct attribute
*attr
;
7736 struct partial_die_info
*first_die
;
7737 CORE_ADDR lowpc
, highpc
;
7738 dwarf2_psymtab
*pst
;
7740 gdb_assert (per_cu
->is_debug_types
);
7741 sig_type
= (struct signatured_type
*) per_cu
;
7743 if (! type_unit_die
->has_children
)
7746 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7747 tu_group
= get_type_unit_group (cu
, attr
);
7749 if (tu_group
->tus
== nullptr)
7750 tu_group
->tus
= new std::vector
<signatured_type
*>;
7751 tu_group
->tus
->push_back (sig_type
);
7753 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7754 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7755 pst
->anonymous
= true;
7757 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7759 lowpc
= (CORE_ADDR
) -1;
7760 highpc
= (CORE_ADDR
) 0;
7761 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7763 end_psymtab_common (objfile
, pst
);
7766 /* Struct used to sort TUs by their abbreviation table offset. */
7768 struct tu_abbrev_offset
7770 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7771 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7774 signatured_type
*sig_type
;
7775 sect_offset abbrev_offset
;
7778 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7781 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7782 const struct tu_abbrev_offset
&b
)
7784 return a
.abbrev_offset
< b
.abbrev_offset
;
7787 /* Efficiently read all the type units.
7788 This does the bulk of the work for build_type_psymtabs.
7790 The efficiency is because we sort TUs by the abbrev table they use and
7791 only read each abbrev table once. In one program there are 200K TUs
7792 sharing 8K abbrev tables.
7794 The main purpose of this function is to support building the
7795 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7796 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7797 can collapse the search space by grouping them by stmt_list.
7798 The savings can be significant, in the same program from above the 200K TUs
7799 share 8K stmt_list tables.
7801 FUNC is expected to call get_type_unit_group, which will create the
7802 struct type_unit_group if necessary and add it to
7803 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7806 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7808 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7809 abbrev_table_up abbrev_table
;
7810 sect_offset abbrev_offset
;
7812 /* It's up to the caller to not call us multiple times. */
7813 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7815 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7818 /* TUs typically share abbrev tables, and there can be way more TUs than
7819 abbrev tables. Sort by abbrev table to reduce the number of times we
7820 read each abbrev table in.
7821 Alternatives are to punt or to maintain a cache of abbrev tables.
7822 This is simpler and efficient enough for now.
7824 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7825 symtab to use). Typically TUs with the same abbrev offset have the same
7826 stmt_list value too so in practice this should work well.
7828 The basic algorithm here is:
7830 sort TUs by abbrev table
7831 for each TU with same abbrev table:
7832 read abbrev table if first user
7833 read TU top level DIE
7834 [IWBN if DWO skeletons had DW_AT_stmt_list]
7837 if (dwarf_read_debug
)
7838 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7840 /* Sort in a separate table to maintain the order of all_type_units
7841 for .gdb_index: TU indices directly index all_type_units. */
7842 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7843 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7845 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7846 sorted_by_abbrev
.emplace_back
7847 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7848 sig_type
->per_cu
.sect_off
));
7850 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7851 sort_tu_by_abbrev_offset
);
7853 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7855 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7857 /* Switch to the next abbrev table if necessary. */
7858 if (abbrev_table
== NULL
7859 || tu
.abbrev_offset
!= abbrev_offset
)
7861 abbrev_offset
= tu
.abbrev_offset
;
7863 abbrev_table::read (per_objfile
->objfile
,
7864 &per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7865 ++tu_stats
->nr_uniq_abbrev_tables
;
7868 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7869 abbrev_table
.get (), nullptr, false);
7870 if (!reader
.dummy_p
)
7871 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7872 reader
.comp_unit_die
);
7876 /* Print collected type unit statistics. */
7879 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7881 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7883 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7884 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7885 per_objfile
->per_bfd
->all_type_units
.size ());
7886 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7887 tu_stats
->nr_uniq_abbrev_tables
);
7888 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7889 tu_stats
->nr_symtabs
);
7890 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7891 tu_stats
->nr_symtab_sharers
);
7892 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7893 tu_stats
->nr_stmt_less_type_units
);
7894 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7895 tu_stats
->nr_all_type_units_reallocs
);
7898 /* Traversal function for build_type_psymtabs. */
7901 build_type_psymtab_dependencies (void **slot
, void *info
)
7903 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7904 struct objfile
*objfile
= per_objfile
->objfile
;
7905 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7906 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7907 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7908 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7911 gdb_assert (len
> 0);
7912 gdb_assert (per_cu
->type_unit_group_p ());
7914 pst
->number_of_dependencies
= len
;
7915 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7916 for (i
= 0; i
< len
; ++i
)
7918 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7919 gdb_assert (iter
->per_cu
.is_debug_types
);
7920 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7921 iter
->type_unit_group
= tu_group
;
7924 delete tu_group
->tus
;
7925 tu_group
->tus
= nullptr;
7930 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7931 Build partial symbol tables for the .debug_types comp-units. */
7934 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7936 if (! create_all_type_units (per_objfile
))
7939 build_type_psymtabs_1 (per_objfile
);
7942 /* Traversal function for process_skeletonless_type_unit.
7943 Read a TU in a DWO file and build partial symbols for it. */
7946 process_skeletonless_type_unit (void **slot
, void *info
)
7948 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7949 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7950 struct signatured_type find_entry
, *entry
;
7952 /* If this TU doesn't exist in the global table, add it and read it in. */
7954 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7955 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7957 find_entry
.signature
= dwo_unit
->signature
;
7958 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7959 &find_entry
, INSERT
);
7960 /* If we've already seen this type there's nothing to do. What's happening
7961 is we're doing our own version of comdat-folding here. */
7965 /* This does the job that create_all_type_units would have done for
7967 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7968 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7971 /* This does the job that build_type_psymtabs_1 would have done. */
7972 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7973 if (!reader
.dummy_p
)
7974 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7975 reader
.comp_unit_die
);
7980 /* Traversal function for process_skeletonless_type_units. */
7983 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7985 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7987 if (dwo_file
->tus
!= NULL
)
7988 htab_traverse_noresize (dwo_file
->tus
.get (),
7989 process_skeletonless_type_unit
, info
);
7994 /* Scan all TUs of DWO files, verifying we've processed them.
7995 This is needed in case a TU was emitted without its skeleton.
7996 Note: This can't be done until we know what all the DWO files are. */
7999 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
8001 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8002 if (get_dwp_file (per_objfile
) == NULL
8003 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
8005 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
8006 process_dwo_file_for_skeletonless_type_units
,
8011 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8014 set_partial_user (dwarf2_per_objfile
*per_objfile
)
8016 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8018 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8023 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8025 /* Set the 'user' field only if it is not already set. */
8026 if (pst
->dependencies
[j
]->user
== NULL
)
8027 pst
->dependencies
[j
]->user
= pst
;
8032 /* Build the partial symbol table by doing a quick pass through the
8033 .debug_info and .debug_abbrev sections. */
8036 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
8038 struct objfile
*objfile
= per_objfile
->objfile
;
8040 if (dwarf_read_debug
)
8042 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8043 objfile_name (objfile
));
8046 scoped_restore restore_reading_psyms
8047 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8050 per_objfile
->per_bfd
->info
.read (objfile
);
8052 /* Any cached compilation units will be linked by the per-objfile
8053 read_in_chain. Make sure to free them when we're done. */
8054 free_cached_comp_units
freer (per_objfile
);
8056 build_type_psymtabs (per_objfile
);
8058 create_all_comp_units (per_objfile
);
8060 /* Create a temporary address map on a temporary obstack. We later
8061 copy this to the final obstack. */
8062 auto_obstack temp_obstack
;
8064 scoped_restore save_psymtabs_addrmap
8065 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8066 addrmap_create_mutable (&temp_obstack
));
8068 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8070 if (per_cu
->v
.psymtab
!= NULL
)
8071 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8073 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8077 /* This has to wait until we read the CUs, we need the list of DWOs. */
8078 process_skeletonless_type_units (per_objfile
);
8080 /* Now that all TUs have been processed we can fill in the dependencies. */
8081 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8083 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8084 build_type_psymtab_dependencies
, per_objfile
);
8087 if (dwarf_read_debug
)
8088 print_tu_stats (per_objfile
);
8090 set_partial_user (per_objfile
);
8092 objfile
->partial_symtabs
->psymtabs_addrmap
8093 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8094 objfile
->partial_symtabs
->obstack ());
8095 /* At this point we want to keep the address map. */
8096 save_psymtabs_addrmap
.release ();
8098 if (dwarf_read_debug
)
8099 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8100 objfile_name (objfile
));
8103 /* Load the partial DIEs for a secondary CU into memory.
8104 This is also used when rereading a primary CU with load_all_dies. */
8107 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8108 dwarf2_per_objfile
*per_objfile
,
8109 dwarf2_cu
*existing_cu
)
8111 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8113 if (!reader
.dummy_p
)
8115 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8118 /* Check if comp unit has_children.
8119 If so, read the rest of the partial symbols from this comp unit.
8120 If not, there's no more debug_info for this comp unit. */
8121 if (reader
.comp_unit_die
->has_children
)
8122 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8129 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8130 struct dwarf2_section_info
*section
,
8131 struct dwarf2_section_info
*abbrev_section
,
8132 unsigned int is_dwz
)
8134 const gdb_byte
*info_ptr
;
8135 struct objfile
*objfile
= per_objfile
->objfile
;
8137 if (dwarf_read_debug
)
8138 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8139 section
->get_name (),
8140 section
->get_file_name ());
8142 section
->read (objfile
);
8144 info_ptr
= section
->buffer
;
8146 while (info_ptr
< section
->buffer
+ section
->size
)
8148 struct dwarf2_per_cu_data
*this_cu
;
8150 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8152 comp_unit_head cu_header
;
8153 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8154 abbrev_section
, info_ptr
,
8155 rcuh_kind::COMPILE
);
8157 /* Save the compilation unit for later lookup. */
8158 if (cu_header
.unit_type
!= DW_UT_type
)
8159 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8162 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8163 sig_type
->signature
= cu_header
.signature
;
8164 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8165 this_cu
= &sig_type
->per_cu
;
8167 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8168 this_cu
->sect_off
= sect_off
;
8169 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8170 this_cu
->is_dwz
= is_dwz
;
8171 this_cu
->section
= section
;
8173 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8175 info_ptr
= info_ptr
+ this_cu
->length
;
8179 /* Create a list of all compilation units in OBJFILE.
8180 This is only done for -readnow and building partial symtabs. */
8183 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8185 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8186 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8187 &per_objfile
->per_bfd
->abbrev
, 0);
8189 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8191 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8194 /* Process all loaded DIEs for compilation unit CU, starting at
8195 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8196 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8197 DW_AT_ranges). See the comments of add_partial_subprogram on how
8198 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8201 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8202 CORE_ADDR
*highpc
, int set_addrmap
,
8203 struct dwarf2_cu
*cu
)
8205 struct partial_die_info
*pdi
;
8207 /* Now, march along the PDI's, descending into ones which have
8208 interesting children but skipping the children of the other ones,
8209 until we reach the end of the compilation unit. */
8217 /* Anonymous namespaces or modules have no name but have interesting
8218 children, so we need to look at them. Ditto for anonymous
8221 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8222 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8223 || pdi
->tag
== DW_TAG_imported_unit
8224 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8228 case DW_TAG_subprogram
:
8229 case DW_TAG_inlined_subroutine
:
8230 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8231 if (cu
->language
== language_cplus
)
8232 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8235 case DW_TAG_constant
:
8236 case DW_TAG_variable
:
8237 case DW_TAG_typedef
:
8238 case DW_TAG_union_type
:
8239 if (!pdi
->is_declaration
8240 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8242 add_partial_symbol (pdi
, cu
);
8245 case DW_TAG_class_type
:
8246 case DW_TAG_interface_type
:
8247 case DW_TAG_structure_type
:
8248 if (!pdi
->is_declaration
)
8250 add_partial_symbol (pdi
, cu
);
8252 if ((cu
->language
== language_rust
8253 || cu
->language
== language_cplus
) && pdi
->has_children
)
8254 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8257 case DW_TAG_enumeration_type
:
8258 if (!pdi
->is_declaration
)
8259 add_partial_enumeration (pdi
, cu
);
8261 case DW_TAG_base_type
:
8262 case DW_TAG_subrange_type
:
8263 /* File scope base type definitions are added to the partial
8265 add_partial_symbol (pdi
, cu
);
8267 case DW_TAG_namespace
:
8268 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8271 if (!pdi
->is_declaration
)
8272 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8274 case DW_TAG_imported_unit
:
8276 struct dwarf2_per_cu_data
*per_cu
;
8278 /* For now we don't handle imported units in type units. */
8279 if (cu
->per_cu
->is_debug_types
)
8281 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8282 " supported in type units [in module %s]"),
8283 objfile_name (cu
->per_objfile
->objfile
));
8286 per_cu
= dwarf2_find_containing_comp_unit
8287 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8289 /* Go read the partial unit, if needed. */
8290 if (per_cu
->v
.psymtab
== NULL
)
8291 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8294 cu
->per_cu
->imported_symtabs_push (per_cu
);
8297 case DW_TAG_imported_declaration
:
8298 add_partial_symbol (pdi
, cu
);
8305 /* If the die has a sibling, skip to the sibling. */
8307 pdi
= pdi
->die_sibling
;
8311 /* Functions used to compute the fully scoped name of a partial DIE.
8313 Normally, this is simple. For C++, the parent DIE's fully scoped
8314 name is concatenated with "::" and the partial DIE's name.
8315 Enumerators are an exception; they use the scope of their parent
8316 enumeration type, i.e. the name of the enumeration type is not
8317 prepended to the enumerator.
8319 There are two complexities. One is DW_AT_specification; in this
8320 case "parent" means the parent of the target of the specification,
8321 instead of the direct parent of the DIE. The other is compilers
8322 which do not emit DW_TAG_namespace; in this case we try to guess
8323 the fully qualified name of structure types from their members'
8324 linkage names. This must be done using the DIE's children rather
8325 than the children of any DW_AT_specification target. We only need
8326 to do this for structures at the top level, i.e. if the target of
8327 any DW_AT_specification (if any; otherwise the DIE itself) does not
8330 /* Compute the scope prefix associated with PDI's parent, in
8331 compilation unit CU. The result will be allocated on CU's
8332 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8333 field. NULL is returned if no prefix is necessary. */
8335 partial_die_parent_scope (struct partial_die_info
*pdi
,
8336 struct dwarf2_cu
*cu
)
8338 const char *grandparent_scope
;
8339 struct partial_die_info
*parent
, *real_pdi
;
8341 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8342 then this means the parent of the specification DIE. */
8345 while (real_pdi
->has_specification
)
8347 auto res
= find_partial_die (real_pdi
->spec_offset
,
8348 real_pdi
->spec_is_dwz
, cu
);
8353 parent
= real_pdi
->die_parent
;
8357 if (parent
->scope_set
)
8358 return parent
->scope
;
8362 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8364 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8365 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8366 Work around this problem here. */
8367 if (cu
->language
== language_cplus
8368 && parent
->tag
== DW_TAG_namespace
8369 && strcmp (parent
->name (cu
), "::") == 0
8370 && grandparent_scope
== NULL
)
8372 parent
->scope
= NULL
;
8373 parent
->scope_set
= 1;
8377 /* Nested subroutines in Fortran get a prefix. */
8378 if (pdi
->tag
== DW_TAG_enumerator
)
8379 /* Enumerators should not get the name of the enumeration as a prefix. */
8380 parent
->scope
= grandparent_scope
;
8381 else if (parent
->tag
== DW_TAG_namespace
8382 || parent
->tag
== DW_TAG_module
8383 || parent
->tag
== DW_TAG_structure_type
8384 || parent
->tag
== DW_TAG_class_type
8385 || parent
->tag
== DW_TAG_interface_type
8386 || parent
->tag
== DW_TAG_union_type
8387 || parent
->tag
== DW_TAG_enumeration_type
8388 || (cu
->language
== language_fortran
8389 && parent
->tag
== DW_TAG_subprogram
8390 && pdi
->tag
== DW_TAG_subprogram
))
8392 if (grandparent_scope
== NULL
)
8393 parent
->scope
= parent
->name (cu
);
8395 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8397 parent
->name (cu
), 0, cu
);
8401 /* FIXME drow/2004-04-01: What should we be doing with
8402 function-local names? For partial symbols, we should probably be
8404 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8405 dwarf_tag_name (parent
->tag
),
8406 sect_offset_str (pdi
->sect_off
));
8407 parent
->scope
= grandparent_scope
;
8410 parent
->scope_set
= 1;
8411 return parent
->scope
;
8414 /* Return the fully scoped name associated with PDI, from compilation unit
8415 CU. The result will be allocated with malloc. */
8417 static gdb::unique_xmalloc_ptr
<char>
8418 partial_die_full_name (struct partial_die_info
*pdi
,
8419 struct dwarf2_cu
*cu
)
8421 const char *parent_scope
;
8423 /* If this is a template instantiation, we can not work out the
8424 template arguments from partial DIEs. So, unfortunately, we have
8425 to go through the full DIEs. At least any work we do building
8426 types here will be reused if full symbols are loaded later. */
8427 if (pdi
->has_template_arguments
)
8431 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8433 struct die_info
*die
;
8434 struct attribute attr
;
8435 struct dwarf2_cu
*ref_cu
= cu
;
8437 /* DW_FORM_ref_addr is using section offset. */
8438 attr
.name
= (enum dwarf_attribute
) 0;
8439 attr
.form
= DW_FORM_ref_addr
;
8440 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8441 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8443 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8447 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8448 if (parent_scope
== NULL
)
8451 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8457 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8459 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8460 struct objfile
*objfile
= per_objfile
->objfile
;
8461 struct gdbarch
*gdbarch
= objfile
->arch ();
8463 const char *actual_name
= NULL
;
8466 baseaddr
= objfile
->text_section_offset ();
8468 gdb::unique_xmalloc_ptr
<char> built_actual_name
8469 = partial_die_full_name (pdi
, cu
);
8470 if (built_actual_name
!= NULL
)
8471 actual_name
= built_actual_name
.get ();
8473 if (actual_name
== NULL
)
8474 actual_name
= pdi
->name (cu
);
8476 partial_symbol psymbol
;
8477 memset (&psymbol
, 0, sizeof (psymbol
));
8478 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8479 psymbol
.ginfo
.section
= -1;
8481 /* The code below indicates that the psymbol should be installed by
8483 gdb::optional
<psymbol_placement
> where
;
8487 case DW_TAG_inlined_subroutine
:
8488 case DW_TAG_subprogram
:
8489 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8491 if (pdi
->is_external
8492 || cu
->language
== language_ada
8493 || (cu
->language
== language_fortran
8494 && pdi
->die_parent
!= NULL
8495 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8497 /* Normally, only "external" DIEs are part of the global scope.
8498 But in Ada and Fortran, we want to be able to access nested
8499 procedures globally. So all Ada and Fortran subprograms are
8500 stored in the global scope. */
8501 where
= psymbol_placement::GLOBAL
;
8504 where
= psymbol_placement::STATIC
;
8506 psymbol
.domain
= VAR_DOMAIN
;
8507 psymbol
.aclass
= LOC_BLOCK
;
8508 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8509 psymbol
.ginfo
.value
.address
= addr
;
8511 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8512 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8514 case DW_TAG_constant
:
8515 psymbol
.domain
= VAR_DOMAIN
;
8516 psymbol
.aclass
= LOC_STATIC
;
8517 where
= (pdi
->is_external
8518 ? psymbol_placement::GLOBAL
8519 : psymbol_placement::STATIC
);
8521 case DW_TAG_variable
:
8523 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8527 && !per_objfile
->per_bfd
->has_section_at_zero
)
8529 /* A global or static variable may also have been stripped
8530 out by the linker if unused, in which case its address
8531 will be nullified; do not add such variables into partial
8532 symbol table then. */
8534 else if (pdi
->is_external
)
8537 Don't enter into the minimal symbol tables as there is
8538 a minimal symbol table entry from the ELF symbols already.
8539 Enter into partial symbol table if it has a location
8540 descriptor or a type.
8541 If the location descriptor is missing, new_symbol will create
8542 a LOC_UNRESOLVED symbol, the address of the variable will then
8543 be determined from the minimal symbol table whenever the variable
8545 The address for the partial symbol table entry is not
8546 used by GDB, but it comes in handy for debugging partial symbol
8549 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8551 psymbol
.domain
= VAR_DOMAIN
;
8552 psymbol
.aclass
= LOC_STATIC
;
8553 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8554 psymbol
.ginfo
.value
.address
= addr
;
8555 where
= psymbol_placement::GLOBAL
;
8560 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8562 /* Static Variable. Skip symbols whose value we cannot know (those
8563 without location descriptors or constant values). */
8564 if (!has_loc
&& !pdi
->has_const_value
)
8567 psymbol
.domain
= VAR_DOMAIN
;
8568 psymbol
.aclass
= LOC_STATIC
;
8569 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8571 psymbol
.ginfo
.value
.address
= addr
;
8572 where
= psymbol_placement::STATIC
;
8575 case DW_TAG_typedef
:
8576 case DW_TAG_base_type
:
8577 case DW_TAG_subrange_type
:
8578 psymbol
.domain
= VAR_DOMAIN
;
8579 psymbol
.aclass
= LOC_TYPEDEF
;
8580 where
= psymbol_placement::STATIC
;
8582 case DW_TAG_imported_declaration
:
8583 case DW_TAG_namespace
:
8584 psymbol
.domain
= VAR_DOMAIN
;
8585 psymbol
.aclass
= LOC_TYPEDEF
;
8586 where
= psymbol_placement::GLOBAL
;
8589 /* With Fortran 77 there might be a "BLOCK DATA" module
8590 available without any name. If so, we skip the module as it
8591 doesn't bring any value. */
8592 if (actual_name
!= nullptr)
8594 psymbol
.domain
= MODULE_DOMAIN
;
8595 psymbol
.aclass
= LOC_TYPEDEF
;
8596 where
= psymbol_placement::GLOBAL
;
8599 case DW_TAG_class_type
:
8600 case DW_TAG_interface_type
:
8601 case DW_TAG_structure_type
:
8602 case DW_TAG_union_type
:
8603 case DW_TAG_enumeration_type
:
8604 /* Skip external references. The DWARF standard says in the section
8605 about "Structure, Union, and Class Type Entries": "An incomplete
8606 structure, union or class type is represented by a structure,
8607 union or class entry that does not have a byte size attribute
8608 and that has a DW_AT_declaration attribute." */
8609 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8612 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8613 static vs. global. */
8614 psymbol
.domain
= STRUCT_DOMAIN
;
8615 psymbol
.aclass
= LOC_TYPEDEF
;
8616 where
= (cu
->language
== language_cplus
8617 ? psymbol_placement::GLOBAL
8618 : psymbol_placement::STATIC
);
8620 case DW_TAG_enumerator
:
8621 psymbol
.domain
= VAR_DOMAIN
;
8622 psymbol
.aclass
= LOC_CONST
;
8623 where
= (cu
->language
== language_cplus
8624 ? psymbol_placement::GLOBAL
8625 : psymbol_placement::STATIC
);
8631 if (where
.has_value ())
8633 if (built_actual_name
!= nullptr)
8634 actual_name
= objfile
->intern (actual_name
);
8635 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8636 psymbol
.ginfo
.set_linkage_name (actual_name
);
8639 psymbol
.ginfo
.set_demangled_name (actual_name
,
8640 &objfile
->objfile_obstack
);
8641 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8643 add_psymbol_to_list (psymbol
, *where
, objfile
);
8647 /* Read a partial die corresponding to a namespace; also, add a symbol
8648 corresponding to that namespace to the symbol table. NAMESPACE is
8649 the name of the enclosing namespace. */
8652 add_partial_namespace (struct partial_die_info
*pdi
,
8653 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8654 int set_addrmap
, struct dwarf2_cu
*cu
)
8656 /* Add a symbol for the namespace. */
8658 add_partial_symbol (pdi
, cu
);
8660 /* Now scan partial symbols in that namespace. */
8662 if (pdi
->has_children
)
8663 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8666 /* Read a partial die corresponding to a Fortran module. */
8669 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8670 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8672 /* Add a symbol for the namespace. */
8674 add_partial_symbol (pdi
, cu
);
8676 /* Now scan partial symbols in that module. */
8678 if (pdi
->has_children
)
8679 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8682 /* Read a partial die corresponding to a subprogram or an inlined
8683 subprogram and create a partial symbol for that subprogram.
8684 When the CU language allows it, this routine also defines a partial
8685 symbol for each nested subprogram that this subprogram contains.
8686 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8687 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8689 PDI may also be a lexical block, in which case we simply search
8690 recursively for subprograms defined inside that lexical block.
8691 Again, this is only performed when the CU language allows this
8692 type of definitions. */
8695 add_partial_subprogram (struct partial_die_info
*pdi
,
8696 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8697 int set_addrmap
, struct dwarf2_cu
*cu
)
8699 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8701 if (pdi
->has_pc_info
)
8703 if (pdi
->lowpc
< *lowpc
)
8704 *lowpc
= pdi
->lowpc
;
8705 if (pdi
->highpc
> *highpc
)
8706 *highpc
= pdi
->highpc
;
8709 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8710 struct gdbarch
*gdbarch
= objfile
->arch ();
8712 CORE_ADDR this_highpc
;
8713 CORE_ADDR this_lowpc
;
8715 baseaddr
= objfile
->text_section_offset ();
8717 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8718 pdi
->lowpc
+ baseaddr
)
8721 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8722 pdi
->highpc
+ baseaddr
)
8724 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8725 this_lowpc
, this_highpc
- 1,
8726 cu
->per_cu
->v
.psymtab
);
8730 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8732 if (!pdi
->is_declaration
)
8733 /* Ignore subprogram DIEs that do not have a name, they are
8734 illegal. Do not emit a complaint at this point, we will
8735 do so when we convert this psymtab into a symtab. */
8737 add_partial_symbol (pdi
, cu
);
8741 if (! pdi
->has_children
)
8744 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8746 pdi
= pdi
->die_child
;
8750 if (pdi
->tag
== DW_TAG_subprogram
8751 || pdi
->tag
== DW_TAG_inlined_subroutine
8752 || pdi
->tag
== DW_TAG_lexical_block
)
8753 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8754 pdi
= pdi
->die_sibling
;
8759 /* Read a partial die corresponding to an enumeration type. */
8762 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8763 struct dwarf2_cu
*cu
)
8765 struct partial_die_info
*pdi
;
8767 if (enum_pdi
->name (cu
) != NULL
)
8768 add_partial_symbol (enum_pdi
, cu
);
8770 pdi
= enum_pdi
->die_child
;
8773 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8774 complaint (_("malformed enumerator DIE ignored"));
8776 add_partial_symbol (pdi
, cu
);
8777 pdi
= pdi
->die_sibling
;
8781 /* Return the initial uleb128 in the die at INFO_PTR. */
8784 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8786 unsigned int bytes_read
;
8788 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8791 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8792 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8794 Return the corresponding abbrev, or NULL if the number is zero (indicating
8795 an empty DIE). In either case *BYTES_READ will be set to the length of
8796 the initial number. */
8798 static struct abbrev_info
*
8799 peek_die_abbrev (const die_reader_specs
&reader
,
8800 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8802 dwarf2_cu
*cu
= reader
.cu
;
8803 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8804 unsigned int abbrev_number
8805 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8807 if (abbrev_number
== 0)
8810 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8813 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8814 " at offset %s [in module %s]"),
8815 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8816 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8822 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8823 Returns a pointer to the end of a series of DIEs, terminated by an empty
8824 DIE. Any children of the skipped DIEs will also be skipped. */
8826 static const gdb_byte
*
8827 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8831 unsigned int bytes_read
;
8832 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8835 return info_ptr
+ bytes_read
;
8837 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8841 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8842 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8843 abbrev corresponding to that skipped uleb128 should be passed in
8844 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8847 static const gdb_byte
*
8848 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8849 struct abbrev_info
*abbrev
)
8851 unsigned int bytes_read
;
8852 struct attribute attr
;
8853 bfd
*abfd
= reader
->abfd
;
8854 struct dwarf2_cu
*cu
= reader
->cu
;
8855 const gdb_byte
*buffer
= reader
->buffer
;
8856 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8857 unsigned int form
, i
;
8859 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8861 /* The only abbrev we care about is DW_AT_sibling. */
8862 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8865 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8867 if (attr
.form
== DW_FORM_ref_addr
)
8868 complaint (_("ignoring absolute DW_AT_sibling"));
8871 sect_offset off
= attr
.get_ref_die_offset ();
8872 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8874 if (sibling_ptr
< info_ptr
)
8875 complaint (_("DW_AT_sibling points backwards"));
8876 else if (sibling_ptr
> reader
->buffer_end
)
8877 reader
->die_section
->overflow_complaint ();
8883 /* If it isn't DW_AT_sibling, skip this attribute. */
8884 form
= abbrev
->attrs
[i
].form
;
8888 case DW_FORM_ref_addr
:
8889 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8890 and later it is offset sized. */
8891 if (cu
->header
.version
== 2)
8892 info_ptr
+= cu
->header
.addr_size
;
8894 info_ptr
+= cu
->header
.offset_size
;
8896 case DW_FORM_GNU_ref_alt
:
8897 info_ptr
+= cu
->header
.offset_size
;
8900 info_ptr
+= cu
->header
.addr_size
;
8908 case DW_FORM_flag_present
:
8909 case DW_FORM_implicit_const
:
8926 case DW_FORM_ref_sig8
:
8929 case DW_FORM_data16
:
8932 case DW_FORM_string
:
8933 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8934 info_ptr
+= bytes_read
;
8936 case DW_FORM_sec_offset
:
8938 case DW_FORM_GNU_strp_alt
:
8939 info_ptr
+= cu
->header
.offset_size
;
8941 case DW_FORM_exprloc
:
8943 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8944 info_ptr
+= bytes_read
;
8946 case DW_FORM_block1
:
8947 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8949 case DW_FORM_block2
:
8950 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8952 case DW_FORM_block4
:
8953 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8959 case DW_FORM_ref_udata
:
8960 case DW_FORM_GNU_addr_index
:
8961 case DW_FORM_GNU_str_index
:
8962 case DW_FORM_rnglistx
:
8963 case DW_FORM_loclistx
:
8964 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8966 case DW_FORM_indirect
:
8967 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8968 info_ptr
+= bytes_read
;
8969 /* We need to continue parsing from here, so just go back to
8971 goto skip_attribute
;
8974 error (_("Dwarf Error: Cannot handle %s "
8975 "in DWARF reader [in module %s]"),
8976 dwarf_form_name (form
),
8977 bfd_get_filename (abfd
));
8981 if (abbrev
->has_children
)
8982 return skip_children (reader
, info_ptr
);
8987 /* Locate ORIG_PDI's sibling.
8988 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8990 static const gdb_byte
*
8991 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8992 struct partial_die_info
*orig_pdi
,
8993 const gdb_byte
*info_ptr
)
8995 /* Do we know the sibling already? */
8997 if (orig_pdi
->sibling
)
8998 return orig_pdi
->sibling
;
9000 /* Are there any children to deal with? */
9002 if (!orig_pdi
->has_children
)
9005 /* Skip the children the long way. */
9007 return skip_children (reader
, info_ptr
);
9010 /* Expand this partial symbol table into a full symbol table. SELF is
9014 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9016 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9018 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
9020 /* If this psymtab is constructed from a debug-only objfile, the
9021 has_section_at_zero flag will not necessarily be correct. We
9022 can get the correct value for this flag by looking at the data
9023 associated with the (presumably stripped) associated objfile. */
9024 if (objfile
->separate_debug_objfile_backlink
)
9026 dwarf2_per_objfile
*per_objfile_backlink
9027 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9029 per_objfile
->per_bfd
->has_section_at_zero
9030 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9033 expand_psymtab (objfile
);
9035 process_cu_includes (per_objfile
);
9038 /* Reading in full CUs. */
9040 /* Add PER_CU to the queue. */
9043 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9044 dwarf2_per_objfile
*per_objfile
,
9045 enum language pretend_language
)
9048 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
9051 /* If PER_CU is not yet queued, add it to the queue.
9052 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9054 The result is non-zero if PER_CU was queued, otherwise the result is zero
9055 meaning either PER_CU is already queued or it is already loaded.
9057 N.B. There is an invariant here that if a CU is queued then it is loaded.
9058 The caller is required to load PER_CU if we return non-zero. */
9061 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9062 dwarf2_per_cu_data
*per_cu
,
9063 dwarf2_per_objfile
*per_objfile
,
9064 enum language pretend_language
)
9066 /* We may arrive here during partial symbol reading, if we need full
9067 DIEs to process an unusual case (e.g. template arguments). Do
9068 not queue PER_CU, just tell our caller to load its DIEs. */
9069 if (per_cu
->per_bfd
->reading_partial_symbols
)
9071 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9073 if (cu
== NULL
|| cu
->dies
== NULL
)
9078 /* Mark the dependence relation so that we don't flush PER_CU
9080 if (dependent_cu
!= NULL
)
9081 dwarf2_add_dependence (dependent_cu
, per_cu
);
9083 /* If it's already on the queue, we have nothing to do. */
9087 /* If the compilation unit is already loaded, just mark it as
9089 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9096 /* Add it to the queue. */
9097 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9102 /* Process the queue. */
9105 process_queue (dwarf2_per_objfile
*per_objfile
)
9107 if (dwarf_read_debug
)
9109 fprintf_unfiltered (gdb_stdlog
,
9110 "Expanding one or more symtabs of objfile %s ...\n",
9111 objfile_name (per_objfile
->objfile
));
9114 /* The queue starts out with one item, but following a DIE reference
9115 may load a new CU, adding it to the end of the queue. */
9116 while (!per_objfile
->per_bfd
->queue
.empty ())
9118 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9119 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9121 if (!per_objfile
->symtab_set_p (per_cu
))
9123 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9125 /* Skip dummy CUs. */
9128 unsigned int debug_print_threshold
;
9131 if (per_cu
->is_debug_types
)
9133 struct signatured_type
*sig_type
=
9134 (struct signatured_type
*) per_cu
;
9136 sprintf (buf
, "TU %s at offset %s",
9137 hex_string (sig_type
->signature
),
9138 sect_offset_str (per_cu
->sect_off
));
9139 /* There can be 100s of TUs.
9140 Only print them in verbose mode. */
9141 debug_print_threshold
= 2;
9145 sprintf (buf
, "CU at offset %s",
9146 sect_offset_str (per_cu
->sect_off
));
9147 debug_print_threshold
= 1;
9150 if (dwarf_read_debug
>= debug_print_threshold
)
9151 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9153 if (per_cu
->is_debug_types
)
9154 process_full_type_unit (cu
, item
.pretend_language
);
9156 process_full_comp_unit (cu
, item
.pretend_language
);
9158 if (dwarf_read_debug
>= debug_print_threshold
)
9159 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9164 per_objfile
->per_bfd
->queue
.pop ();
9167 if (dwarf_read_debug
)
9169 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9170 objfile_name (per_objfile
->objfile
));
9174 /* Read in full symbols for PST, and anything it depends on. */
9177 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9179 gdb_assert (!readin_p (objfile
));
9181 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9182 free_cached_comp_units
freer (per_objfile
);
9183 expand_dependencies (objfile
);
9185 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9186 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9189 /* See psympriv.h. */
9192 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9194 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9195 return per_objfile
->symtab_set_p (per_cu_data
);
9198 /* See psympriv.h. */
9201 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9203 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9204 return per_objfile
->get_symtab (per_cu_data
);
9207 /* Trivial hash function for die_info: the hash value of a DIE
9208 is its offset in .debug_info for this objfile. */
9211 die_hash (const void *item
)
9213 const struct die_info
*die
= (const struct die_info
*) item
;
9215 return to_underlying (die
->sect_off
);
9218 /* Trivial comparison function for die_info structures: two DIEs
9219 are equal if they have the same offset. */
9222 die_eq (const void *item_lhs
, const void *item_rhs
)
9224 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9225 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9227 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9230 /* Load the DIEs associated with PER_CU into memory. */
9233 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9234 dwarf2_per_objfile
*per_objfile
,
9236 enum language pretend_language
)
9238 gdb_assert (! this_cu
->is_debug_types
);
9240 dwarf2_cu
*existing_cu
= per_objfile
->get_cu (this_cu
);
9241 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9245 struct dwarf2_cu
*cu
= reader
.cu
;
9246 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9248 gdb_assert (cu
->die_hash
== NULL
);
9250 htab_create_alloc_ex (cu
->header
.length
/ 12,
9254 &cu
->comp_unit_obstack
,
9255 hashtab_obstack_allocate
,
9256 dummy_obstack_deallocate
);
9258 if (reader
.comp_unit_die
->has_children
)
9259 reader
.comp_unit_die
->child
9260 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9261 &info_ptr
, reader
.comp_unit_die
);
9262 cu
->dies
= reader
.comp_unit_die
;
9263 /* comp_unit_die is not stored in die_hash, no need. */
9265 /* We try not to read any attributes in this function, because not
9266 all CUs needed for references have been loaded yet, and symbol
9267 table processing isn't initialized. But we have to set the CU language,
9268 or we won't be able to build types correctly.
9269 Similarly, if we do not read the producer, we can not apply
9270 producer-specific interpretation. */
9271 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9276 /* Add a DIE to the delayed physname list. */
9279 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9280 const char *name
, struct die_info
*die
,
9281 struct dwarf2_cu
*cu
)
9283 struct delayed_method_info mi
;
9285 mi
.fnfield_index
= fnfield_index
;
9289 cu
->method_list
.push_back (mi
);
9292 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9293 "const" / "volatile". If so, decrements LEN by the length of the
9294 modifier and return true. Otherwise return false. */
9298 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9300 size_t mod_len
= sizeof (mod
) - 1;
9301 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9309 /* Compute the physnames of any methods on the CU's method list.
9311 The computation of method physnames is delayed in order to avoid the
9312 (bad) condition that one of the method's formal parameters is of an as yet
9316 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9318 /* Only C++ delays computing physnames. */
9319 if (cu
->method_list
.empty ())
9321 gdb_assert (cu
->language
== language_cplus
);
9323 for (const delayed_method_info
&mi
: cu
->method_list
)
9325 const char *physname
;
9326 struct fn_fieldlist
*fn_flp
9327 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9328 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9329 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9330 = physname
? physname
: "";
9332 /* Since there's no tag to indicate whether a method is a
9333 const/volatile overload, extract that information out of the
9335 if (physname
!= NULL
)
9337 size_t len
= strlen (physname
);
9341 if (physname
[len
] == ')') /* shortcut */
9343 else if (check_modifier (physname
, len
, " const"))
9344 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9345 else if (check_modifier (physname
, len
, " volatile"))
9346 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9353 /* The list is no longer needed. */
9354 cu
->method_list
.clear ();
9357 /* Go objects should be embedded in a DW_TAG_module DIE,
9358 and it's not clear if/how imported objects will appear.
9359 To keep Go support simple until that's worked out,
9360 go back through what we've read and create something usable.
9361 We could do this while processing each DIE, and feels kinda cleaner,
9362 but that way is more invasive.
9363 This is to, for example, allow the user to type "p var" or "b main"
9364 without having to specify the package name, and allow lookups
9365 of module.object to work in contexts that use the expression
9369 fixup_go_packaging (struct dwarf2_cu
*cu
)
9371 gdb::unique_xmalloc_ptr
<char> package_name
;
9372 struct pending
*list
;
9375 for (list
= *cu
->get_builder ()->get_global_symbols ();
9379 for (i
= 0; i
< list
->nsyms
; ++i
)
9381 struct symbol
*sym
= list
->symbol
[i
];
9383 if (sym
->language () == language_go
9384 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9386 gdb::unique_xmalloc_ptr
<char> this_package_name
9387 (go_symbol_package_name (sym
));
9389 if (this_package_name
== NULL
)
9391 if (package_name
== NULL
)
9392 package_name
= std::move (this_package_name
);
9395 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9396 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9397 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9398 (symbol_symtab (sym
) != NULL
9399 ? symtab_to_filename_for_display
9400 (symbol_symtab (sym
))
9401 : objfile_name (objfile
)),
9402 this_package_name
.get (), package_name
.get ());
9408 if (package_name
!= NULL
)
9410 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9411 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9412 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9413 saved_package_name
);
9416 sym
= new (&objfile
->objfile_obstack
) symbol
;
9417 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9418 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9419 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9420 e.g., "main" finds the "main" module and not C's main(). */
9421 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9422 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9423 SYMBOL_TYPE (sym
) = type
;
9425 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9429 /* Allocate a fully-qualified name consisting of the two parts on the
9433 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9435 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9438 /* A helper that allocates a variant part to attach to a Rust enum
9439 type. OBSTACK is where the results should be allocated. TYPE is
9440 the type we're processing. DISCRIMINANT_INDEX is the index of the
9441 discriminant. It must be the index of one of the fields of TYPE,
9442 or -1 to mean there is no discriminant (univariant enum).
9443 DEFAULT_INDEX is the index of the default field; or -1 if there is
9444 no default. RANGES is indexed by "effective" field number (the
9445 field index, but omitting the discriminant and default fields) and
9446 must hold the discriminant values used by the variants. Note that
9447 RANGES must have a lifetime at least as long as OBSTACK -- either
9448 already allocated on it, or static. */
9451 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9452 int discriminant_index
, int default_index
,
9453 gdb::array_view
<discriminant_range
> ranges
)
9455 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9456 gdb_assert (discriminant_index
== -1
9457 || (discriminant_index
>= 0
9458 && discriminant_index
< type
->num_fields ()));
9459 gdb_assert (default_index
== -1
9460 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9462 /* We have one variant for each non-discriminant field. */
9463 int n_variants
= type
->num_fields ();
9464 if (discriminant_index
!= -1)
9467 variant
*variants
= new (obstack
) variant
[n_variants
];
9470 for (int i
= 0; i
< type
->num_fields (); ++i
)
9472 if (i
== discriminant_index
)
9475 variants
[var_idx
].first_field
= i
;
9476 variants
[var_idx
].last_field
= i
+ 1;
9478 /* The default field does not need a range, but other fields do.
9479 We skipped the discriminant above. */
9480 if (i
!= default_index
)
9482 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9489 gdb_assert (range_idx
== ranges
.size ());
9490 gdb_assert (var_idx
== n_variants
);
9492 variant_part
*part
= new (obstack
) variant_part
;
9493 part
->discriminant_index
= discriminant_index
;
9494 /* If there is no discriminant, then whether it is signed is of no
9497 = (discriminant_index
== -1
9499 : type
->field (discriminant_index
).type ()->is_unsigned ());
9500 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9502 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9503 gdb::array_view
<variant_part
> *prop_value
9504 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9506 struct dynamic_prop prop
;
9507 prop
.set_variant_parts (prop_value
);
9509 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9512 /* Some versions of rustc emitted enums in an unusual way.
9514 Ordinary enums were emitted as unions. The first element of each
9515 structure in the union was named "RUST$ENUM$DISR". This element
9516 held the discriminant.
9518 These versions of Rust also implemented the "non-zero"
9519 optimization. When the enum had two values, and one is empty and
9520 the other holds a pointer that cannot be zero, the pointer is used
9521 as the discriminant, with a zero value meaning the empty variant.
9522 Here, the union's first member is of the form
9523 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9524 where the fieldnos are the indices of the fields that should be
9525 traversed in order to find the field (which may be several fields deep)
9526 and the variantname is the name of the variant of the case when the
9529 This function recognizes whether TYPE is of one of these forms,
9530 and, if so, smashes it to be a variant type. */
9533 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9535 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9537 /* We don't need to deal with empty enums. */
9538 if (type
->num_fields () == 0)
9541 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9542 if (type
->num_fields () == 1
9543 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9545 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9547 /* Decode the field name to find the offset of the
9549 ULONGEST bit_offset
= 0;
9550 struct type
*field_type
= type
->field (0).type ();
9551 while (name
[0] >= '0' && name
[0] <= '9')
9554 unsigned long index
= strtoul (name
, &tail
, 10);
9557 || index
>= field_type
->num_fields ()
9558 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9559 != FIELD_LOC_KIND_BITPOS
))
9561 complaint (_("Could not parse Rust enum encoding string \"%s\""
9563 TYPE_FIELD_NAME (type
, 0),
9564 objfile_name (objfile
));
9569 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9570 field_type
= field_type
->field (index
).type ();
9573 /* Smash this type to be a structure type. We have to do this
9574 because the type has already been recorded. */
9575 type
->set_code (TYPE_CODE_STRUCT
);
9576 type
->set_num_fields (3);
9577 /* Save the field we care about. */
9578 struct field saved_field
= type
->field (0);
9580 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9582 /* Put the discriminant at index 0. */
9583 type
->field (0).set_type (field_type
);
9584 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9585 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9586 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9588 /* The order of fields doesn't really matter, so put the real
9589 field at index 1 and the data-less field at index 2. */
9590 type
->field (1) = saved_field
;
9591 TYPE_FIELD_NAME (type
, 1)
9592 = rust_last_path_segment (type
->field (1).type ()->name ());
9593 type
->field (1).type ()->set_name
9594 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9595 TYPE_FIELD_NAME (type
, 1)));
9597 const char *dataless_name
9598 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9600 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9602 type
->field (2).set_type (dataless_type
);
9603 /* NAME points into the original discriminant name, which
9604 already has the correct lifetime. */
9605 TYPE_FIELD_NAME (type
, 2) = name
;
9606 SET_FIELD_BITPOS (type
->field (2), 0);
9608 /* Indicate that this is a variant type. */
9609 static discriminant_range ranges
[1] = { { 0, 0 } };
9610 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9612 /* A union with a single anonymous field is probably an old-style
9614 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9616 /* Smash this type to be a structure type. We have to do this
9617 because the type has already been recorded. */
9618 type
->set_code (TYPE_CODE_STRUCT
);
9620 struct type
*field_type
= type
->field (0).type ();
9621 const char *variant_name
9622 = rust_last_path_segment (field_type
->name ());
9623 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9624 field_type
->set_name
9625 (rust_fully_qualify (&objfile
->objfile_obstack
,
9626 type
->name (), variant_name
));
9628 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9632 struct type
*disr_type
= nullptr;
9633 for (int i
= 0; i
< type
->num_fields (); ++i
)
9635 disr_type
= type
->field (i
).type ();
9637 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9639 /* All fields of a true enum will be structs. */
9642 else if (disr_type
->num_fields () == 0)
9644 /* Could be data-less variant, so keep going. */
9645 disr_type
= nullptr;
9647 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9648 "RUST$ENUM$DISR") != 0)
9650 /* Not a Rust enum. */
9660 /* If we got here without a discriminant, then it's probably
9662 if (disr_type
== nullptr)
9665 /* Smash this type to be a structure type. We have to do this
9666 because the type has already been recorded. */
9667 type
->set_code (TYPE_CODE_STRUCT
);
9669 /* Make space for the discriminant field. */
9670 struct field
*disr_field
= &disr_type
->field (0);
9672 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9673 * sizeof (struct field
)));
9674 memcpy (new_fields
+ 1, type
->fields (),
9675 type
->num_fields () * sizeof (struct field
));
9676 type
->set_fields (new_fields
);
9677 type
->set_num_fields (type
->num_fields () + 1);
9679 /* Install the discriminant at index 0 in the union. */
9680 type
->field (0) = *disr_field
;
9681 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9682 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9684 /* We need a way to find the correct discriminant given a
9685 variant name. For convenience we build a map here. */
9686 struct type
*enum_type
= disr_field
->type ();
9687 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9688 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9690 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9693 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9694 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9698 int n_fields
= type
->num_fields ();
9699 /* We don't need a range entry for the discriminant, but we do
9700 need one for every other field, as there is no default
9702 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9705 /* Skip the discriminant here. */
9706 for (int i
= 1; i
< n_fields
; ++i
)
9708 /* Find the final word in the name of this variant's type.
9709 That name can be used to look up the correct
9711 const char *variant_name
9712 = rust_last_path_segment (type
->field (i
).type ()->name ());
9714 auto iter
= discriminant_map
.find (variant_name
);
9715 if (iter
!= discriminant_map
.end ())
9717 ranges
[i
- 1].low
= iter
->second
;
9718 ranges
[i
- 1].high
= iter
->second
;
9721 /* In Rust, each element should have the size of the
9723 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9725 /* Remove the discriminant field, if it exists. */
9726 struct type
*sub_type
= type
->field (i
).type ();
9727 if (sub_type
->num_fields () > 0)
9729 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9730 sub_type
->set_fields (sub_type
->fields () + 1);
9732 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9734 (rust_fully_qualify (&objfile
->objfile_obstack
,
9735 type
->name (), variant_name
));
9738 /* Indicate that this is a variant type. */
9739 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9740 gdb::array_view
<discriminant_range
> (ranges
,
9745 /* Rewrite some Rust unions to be structures with variants parts. */
9748 rust_union_quirks (struct dwarf2_cu
*cu
)
9750 gdb_assert (cu
->language
== language_rust
);
9751 for (type
*type_
: cu
->rust_unions
)
9752 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9753 /* We don't need this any more. */
9754 cu
->rust_unions
.clear ();
9759 type_unit_group_unshareable
*
9760 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9762 auto iter
= this->m_type_units
.find (tu_group
);
9763 if (iter
!= this->m_type_units
.end ())
9764 return iter
->second
.get ();
9766 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9767 type_unit_group_unshareable
*result
= uniq
.get ();
9768 this->m_type_units
[tu_group
] = std::move (uniq
);
9773 dwarf2_per_objfile::get_type_for_signatured_type
9774 (signatured_type
*sig_type
) const
9776 auto iter
= this->m_type_map
.find (sig_type
);
9777 if (iter
== this->m_type_map
.end ())
9780 return iter
->second
;
9783 void dwarf2_per_objfile::set_type_for_signatured_type
9784 (signatured_type
*sig_type
, struct type
*type
)
9786 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9788 this->m_type_map
[sig_type
] = type
;
9791 /* A helper function for computing the list of all symbol tables
9792 included by PER_CU. */
9795 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9796 htab_t all_children
, htab_t all_type_symtabs
,
9797 dwarf2_per_cu_data
*per_cu
,
9798 dwarf2_per_objfile
*per_objfile
,
9799 struct compunit_symtab
*immediate_parent
)
9801 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9804 /* This inclusion and its children have been processed. */
9810 /* Only add a CU if it has a symbol table. */
9811 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9814 /* If this is a type unit only add its symbol table if we haven't
9815 seen it yet (type unit per_cu's can share symtabs). */
9816 if (per_cu
->is_debug_types
)
9818 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9822 result
->push_back (cust
);
9823 if (cust
->user
== NULL
)
9824 cust
->user
= immediate_parent
;
9829 result
->push_back (cust
);
9830 if (cust
->user
== NULL
)
9831 cust
->user
= immediate_parent
;
9835 if (!per_cu
->imported_symtabs_empty ())
9836 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9838 recursively_compute_inclusions (result
, all_children
,
9839 all_type_symtabs
, ptr
, per_objfile
,
9844 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9848 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9849 dwarf2_per_objfile
*per_objfile
)
9851 gdb_assert (! per_cu
->is_debug_types
);
9853 if (!per_cu
->imported_symtabs_empty ())
9856 std::vector
<compunit_symtab
*> result_symtabs
;
9857 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9859 /* If we don't have a symtab, we can just skip this case. */
9863 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9865 NULL
, xcalloc
, xfree
));
9866 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9868 NULL
, xcalloc
, xfree
));
9870 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9872 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9873 all_type_symtabs
.get (), ptr
,
9877 /* Now we have a transitive closure of all the included symtabs. */
9878 len
= result_symtabs
.size ();
9880 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9881 struct compunit_symtab
*, len
+ 1);
9882 memcpy (cust
->includes
, result_symtabs
.data (),
9883 len
* sizeof (compunit_symtab
*));
9884 cust
->includes
[len
] = NULL
;
9888 /* Compute the 'includes' field for the symtabs of all the CUs we just
9892 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9894 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9896 if (! iter
->is_debug_types
)
9897 compute_compunit_symtab_includes (iter
, per_objfile
);
9900 per_objfile
->per_bfd
->just_read_cus
.clear ();
9903 /* Generate full symbol information for CU, whose DIEs have
9904 already been loaded into memory. */
9907 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9909 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9910 struct objfile
*objfile
= per_objfile
->objfile
;
9911 struct gdbarch
*gdbarch
= objfile
->arch ();
9912 CORE_ADDR lowpc
, highpc
;
9913 struct compunit_symtab
*cust
;
9915 struct block
*static_block
;
9918 baseaddr
= objfile
->text_section_offset ();
9920 /* Clear the list here in case something was left over. */
9921 cu
->method_list
.clear ();
9923 cu
->language
= pretend_language
;
9924 cu
->language_defn
= language_def (cu
->language
);
9926 /* Do line number decoding in read_file_scope () */
9927 process_die (cu
->dies
, cu
);
9929 /* For now fudge the Go package. */
9930 if (cu
->language
== language_go
)
9931 fixup_go_packaging (cu
);
9933 /* Now that we have processed all the DIEs in the CU, all the types
9934 should be complete, and it should now be safe to compute all of the
9936 compute_delayed_physnames (cu
);
9938 if (cu
->language
== language_rust
)
9939 rust_union_quirks (cu
);
9941 /* Some compilers don't define a DW_AT_high_pc attribute for the
9942 compilation unit. If the DW_AT_high_pc is missing, synthesize
9943 it, by scanning the DIE's below the compilation unit. */
9944 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9946 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9947 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9949 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9950 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9951 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9952 addrmap to help ensure it has an accurate map of pc values belonging to
9954 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9956 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9957 SECT_OFF_TEXT (objfile
),
9962 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9964 /* Set symtab language to language from DW_AT_language. If the
9965 compilation is from a C file generated by language preprocessors, do
9966 not set the language if it was already deduced by start_subfile. */
9967 if (!(cu
->language
== language_c
9968 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9969 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9971 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9972 produce DW_AT_location with location lists but it can be possibly
9973 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9974 there were bugs in prologue debug info, fixed later in GCC-4.5
9975 by "unwind info for epilogues" patch (which is not directly related).
9977 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9978 needed, it would be wrong due to missing DW_AT_producer there.
9980 Still one can confuse GDB by using non-standard GCC compilation
9981 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9983 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9984 cust
->locations_valid
= 1;
9986 if (gcc_4_minor
>= 5)
9987 cust
->epilogue_unwind_valid
= 1;
9989 cust
->call_site_htab
= cu
->call_site_htab
;
9992 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9994 /* Push it for inclusion processing later. */
9995 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9997 /* Not needed any more. */
9998 cu
->reset_builder ();
10001 /* Generate full symbol information for type unit CU, whose DIEs have
10002 already been loaded into memory. */
10005 process_full_type_unit (dwarf2_cu
*cu
,
10006 enum language pretend_language
)
10008 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10009 struct objfile
*objfile
= per_objfile
->objfile
;
10010 struct compunit_symtab
*cust
;
10011 struct signatured_type
*sig_type
;
10013 gdb_assert (cu
->per_cu
->is_debug_types
);
10014 sig_type
= (struct signatured_type
*) cu
->per_cu
;
10016 /* Clear the list here in case something was left over. */
10017 cu
->method_list
.clear ();
10019 cu
->language
= pretend_language
;
10020 cu
->language_defn
= language_def (cu
->language
);
10022 /* The symbol tables are set up in read_type_unit_scope. */
10023 process_die (cu
->dies
, cu
);
10025 /* For now fudge the Go package. */
10026 if (cu
->language
== language_go
)
10027 fixup_go_packaging (cu
);
10029 /* Now that we have processed all the DIEs in the CU, all the types
10030 should be complete, and it should now be safe to compute all of the
10032 compute_delayed_physnames (cu
);
10034 if (cu
->language
== language_rust
)
10035 rust_union_quirks (cu
);
10037 /* TUs share symbol tables.
10038 If this is the first TU to use this symtab, complete the construction
10039 of it with end_expandable_symtab. Otherwise, complete the addition of
10040 this TU's symbols to the existing symtab. */
10041 type_unit_group_unshareable
*tug_unshare
=
10042 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
10043 if (tug_unshare
->compunit_symtab
== NULL
)
10045 buildsym_compunit
*builder
= cu
->get_builder ();
10046 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10047 tug_unshare
->compunit_symtab
= cust
;
10051 /* Set symtab language to language from DW_AT_language. If the
10052 compilation is from a C file generated by language preprocessors,
10053 do not set the language if it was already deduced by
10055 if (!(cu
->language
== language_c
10056 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10057 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10062 cu
->get_builder ()->augment_type_symtab ();
10063 cust
= tug_unshare
->compunit_symtab
;
10066 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10068 /* Not needed any more. */
10069 cu
->reset_builder ();
10072 /* Process an imported unit DIE. */
10075 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10077 struct attribute
*attr
;
10079 /* For now we don't handle imported units in type units. */
10080 if (cu
->per_cu
->is_debug_types
)
10082 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10083 " supported in type units [in module %s]"),
10084 objfile_name (cu
->per_objfile
->objfile
));
10087 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10090 sect_offset sect_off
= attr
->get_ref_die_offset ();
10091 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10092 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10093 dwarf2_per_cu_data
*per_cu
10094 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10096 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10097 into another compilation unit, at root level. Regard this as a hint,
10099 if (die
->parent
&& die
->parent
->parent
== NULL
10100 && per_cu
->unit_type
== DW_UT_compile
10101 && per_cu
->lang
== language_cplus
)
10104 /* If necessary, add it to the queue and load its DIEs. */
10105 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10106 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
10108 cu
->per_cu
->imported_symtabs_push (per_cu
);
10112 /* RAII object that represents a process_die scope: i.e.,
10113 starts/finishes processing a DIE. */
10114 class process_die_scope
10117 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10118 : m_die (die
), m_cu (cu
)
10120 /* We should only be processing DIEs not already in process. */
10121 gdb_assert (!m_die
->in_process
);
10122 m_die
->in_process
= true;
10125 ~process_die_scope ()
10127 m_die
->in_process
= false;
10129 /* If we're done processing the DIE for the CU that owns the line
10130 header, we don't need the line header anymore. */
10131 if (m_cu
->line_header_die_owner
== m_die
)
10133 delete m_cu
->line_header
;
10134 m_cu
->line_header
= NULL
;
10135 m_cu
->line_header_die_owner
= NULL
;
10144 /* Process a die and its children. */
10147 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10149 process_die_scope
scope (die
, cu
);
10153 case DW_TAG_padding
:
10155 case DW_TAG_compile_unit
:
10156 case DW_TAG_partial_unit
:
10157 read_file_scope (die
, cu
);
10159 case DW_TAG_type_unit
:
10160 read_type_unit_scope (die
, cu
);
10162 case DW_TAG_subprogram
:
10163 /* Nested subprograms in Fortran get a prefix. */
10164 if (cu
->language
== language_fortran
10165 && die
->parent
!= NULL
10166 && die
->parent
->tag
== DW_TAG_subprogram
)
10167 cu
->processing_has_namespace_info
= true;
10168 /* Fall through. */
10169 case DW_TAG_inlined_subroutine
:
10170 read_func_scope (die
, cu
);
10172 case DW_TAG_lexical_block
:
10173 case DW_TAG_try_block
:
10174 case DW_TAG_catch_block
:
10175 read_lexical_block_scope (die
, cu
);
10177 case DW_TAG_call_site
:
10178 case DW_TAG_GNU_call_site
:
10179 read_call_site_scope (die
, cu
);
10181 case DW_TAG_class_type
:
10182 case DW_TAG_interface_type
:
10183 case DW_TAG_structure_type
:
10184 case DW_TAG_union_type
:
10185 process_structure_scope (die
, cu
);
10187 case DW_TAG_enumeration_type
:
10188 process_enumeration_scope (die
, cu
);
10191 /* These dies have a type, but processing them does not create
10192 a symbol or recurse to process the children. Therefore we can
10193 read them on-demand through read_type_die. */
10194 case DW_TAG_subroutine_type
:
10195 case DW_TAG_set_type
:
10196 case DW_TAG_array_type
:
10197 case DW_TAG_pointer_type
:
10198 case DW_TAG_ptr_to_member_type
:
10199 case DW_TAG_reference_type
:
10200 case DW_TAG_rvalue_reference_type
:
10201 case DW_TAG_string_type
:
10204 case DW_TAG_base_type
:
10205 case DW_TAG_subrange_type
:
10206 case DW_TAG_typedef
:
10207 /* Add a typedef symbol for the type definition, if it has a
10209 new_symbol (die
, read_type_die (die
, cu
), cu
);
10211 case DW_TAG_common_block
:
10212 read_common_block (die
, cu
);
10214 case DW_TAG_common_inclusion
:
10216 case DW_TAG_namespace
:
10217 cu
->processing_has_namespace_info
= true;
10218 read_namespace (die
, cu
);
10220 case DW_TAG_module
:
10221 cu
->processing_has_namespace_info
= true;
10222 read_module (die
, cu
);
10224 case DW_TAG_imported_declaration
:
10225 cu
->processing_has_namespace_info
= true;
10226 if (read_namespace_alias (die
, cu
))
10228 /* The declaration is not a global namespace alias. */
10229 /* Fall through. */
10230 case DW_TAG_imported_module
:
10231 cu
->processing_has_namespace_info
= true;
10232 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10233 || cu
->language
!= language_fortran
))
10234 complaint (_("Tag '%s' has unexpected children"),
10235 dwarf_tag_name (die
->tag
));
10236 read_import_statement (die
, cu
);
10239 case DW_TAG_imported_unit
:
10240 process_imported_unit_die (die
, cu
);
10243 case DW_TAG_variable
:
10244 read_variable (die
, cu
);
10248 new_symbol (die
, NULL
, cu
);
10253 /* DWARF name computation. */
10255 /* A helper function for dwarf2_compute_name which determines whether DIE
10256 needs to have the name of the scope prepended to the name listed in the
10260 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10262 struct attribute
*attr
;
10266 case DW_TAG_namespace
:
10267 case DW_TAG_typedef
:
10268 case DW_TAG_class_type
:
10269 case DW_TAG_interface_type
:
10270 case DW_TAG_structure_type
:
10271 case DW_TAG_union_type
:
10272 case DW_TAG_enumeration_type
:
10273 case DW_TAG_enumerator
:
10274 case DW_TAG_subprogram
:
10275 case DW_TAG_inlined_subroutine
:
10276 case DW_TAG_member
:
10277 case DW_TAG_imported_declaration
:
10280 case DW_TAG_variable
:
10281 case DW_TAG_constant
:
10282 /* We only need to prefix "globally" visible variables. These include
10283 any variable marked with DW_AT_external or any variable that
10284 lives in a namespace. [Variables in anonymous namespaces
10285 require prefixing, but they are not DW_AT_external.] */
10287 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10289 struct dwarf2_cu
*spec_cu
= cu
;
10291 return die_needs_namespace (die_specification (die
, &spec_cu
),
10295 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10296 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10297 && die
->parent
->tag
!= DW_TAG_module
)
10299 /* A variable in a lexical block of some kind does not need a
10300 namespace, even though in C++ such variables may be external
10301 and have a mangled name. */
10302 if (die
->parent
->tag
== DW_TAG_lexical_block
10303 || die
->parent
->tag
== DW_TAG_try_block
10304 || die
->parent
->tag
== DW_TAG_catch_block
10305 || die
->parent
->tag
== DW_TAG_subprogram
)
10314 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10315 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10316 defined for the given DIE. */
10318 static struct attribute
*
10319 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10321 struct attribute
*attr
;
10323 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10325 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10330 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10331 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10332 defined for the given DIE. */
10334 static const char *
10335 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10337 const char *linkage_name
;
10339 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10340 if (linkage_name
== NULL
)
10341 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10343 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10344 See https://github.com/rust-lang/rust/issues/32925. */
10345 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10346 && strchr (linkage_name
, '{') != NULL
)
10347 linkage_name
= NULL
;
10349 return linkage_name
;
10352 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10353 compute the physname for the object, which include a method's:
10354 - formal parameters (C++),
10355 - receiver type (Go),
10357 The term "physname" is a bit confusing.
10358 For C++, for example, it is the demangled name.
10359 For Go, for example, it's the mangled name.
10361 For Ada, return the DIE's linkage name rather than the fully qualified
10362 name. PHYSNAME is ignored..
10364 The result is allocated on the objfile->per_bfd's obstack and
10367 static const char *
10368 dwarf2_compute_name (const char *name
,
10369 struct die_info
*die
, struct dwarf2_cu
*cu
,
10372 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10375 name
= dwarf2_name (die
, cu
);
10377 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10378 but otherwise compute it by typename_concat inside GDB.
10379 FIXME: Actually this is not really true, or at least not always true.
10380 It's all very confusing. compute_and_set_names doesn't try to demangle
10381 Fortran names because there is no mangling standard. So new_symbol
10382 will set the demangled name to the result of dwarf2_full_name, and it is
10383 the demangled name that GDB uses if it exists. */
10384 if (cu
->language
== language_ada
10385 || (cu
->language
== language_fortran
&& physname
))
10387 /* For Ada unit, we prefer the linkage name over the name, as
10388 the former contains the exported name, which the user expects
10389 to be able to reference. Ideally, we want the user to be able
10390 to reference this entity using either natural or linkage name,
10391 but we haven't started looking at this enhancement yet. */
10392 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10394 if (linkage_name
!= NULL
)
10395 return linkage_name
;
10398 /* These are the only languages we know how to qualify names in. */
10400 && (cu
->language
== language_cplus
10401 || cu
->language
== language_fortran
|| cu
->language
== language_d
10402 || cu
->language
== language_rust
))
10404 if (die_needs_namespace (die
, cu
))
10406 const char *prefix
;
10407 const char *canonical_name
= NULL
;
10411 prefix
= determine_prefix (die
, cu
);
10412 if (*prefix
!= '\0')
10414 gdb::unique_xmalloc_ptr
<char> prefixed_name
10415 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10417 buf
.puts (prefixed_name
.get ());
10422 /* Template parameters may be specified in the DIE's DW_AT_name, or
10423 as children with DW_TAG_template_type_param or
10424 DW_TAG_value_type_param. If the latter, add them to the name
10425 here. If the name already has template parameters, then
10426 skip this step; some versions of GCC emit both, and
10427 it is more efficient to use the pre-computed name.
10429 Something to keep in mind about this process: it is very
10430 unlikely, or in some cases downright impossible, to produce
10431 something that will match the mangled name of a function.
10432 If the definition of the function has the same debug info,
10433 we should be able to match up with it anyway. But fallbacks
10434 using the minimal symbol, for instance to find a method
10435 implemented in a stripped copy of libstdc++, will not work.
10436 If we do not have debug info for the definition, we will have to
10437 match them up some other way.
10439 When we do name matching there is a related problem with function
10440 templates; two instantiated function templates are allowed to
10441 differ only by their return types, which we do not add here. */
10443 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10445 struct attribute
*attr
;
10446 struct die_info
*child
;
10449 die
->building_fullname
= 1;
10451 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10455 const gdb_byte
*bytes
;
10456 struct dwarf2_locexpr_baton
*baton
;
10459 if (child
->tag
!= DW_TAG_template_type_param
10460 && child
->tag
!= DW_TAG_template_value_param
)
10471 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10474 complaint (_("template parameter missing DW_AT_type"));
10475 buf
.puts ("UNKNOWN_TYPE");
10478 type
= die_type (child
, cu
);
10480 if (child
->tag
== DW_TAG_template_type_param
)
10482 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10483 &type_print_raw_options
);
10487 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10490 complaint (_("template parameter missing "
10491 "DW_AT_const_value"));
10492 buf
.puts ("UNKNOWN_VALUE");
10496 dwarf2_const_value_attr (attr
, type
, name
,
10497 &cu
->comp_unit_obstack
, cu
,
10498 &value
, &bytes
, &baton
);
10500 if (type
->has_no_signedness ())
10501 /* GDB prints characters as NUMBER 'CHAR'. If that's
10502 changed, this can use value_print instead. */
10503 c_printchar (value
, type
, &buf
);
10506 struct value_print_options opts
;
10509 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10513 baton
->per_objfile
);
10514 else if (bytes
!= NULL
)
10516 v
= allocate_value (type
);
10517 memcpy (value_contents_writeable (v
), bytes
,
10518 TYPE_LENGTH (type
));
10521 v
= value_from_longest (type
, value
);
10523 /* Specify decimal so that we do not depend on
10525 get_formatted_print_options (&opts
, 'd');
10527 value_print (v
, &buf
, &opts
);
10532 die
->building_fullname
= 0;
10536 /* Close the argument list, with a space if necessary
10537 (nested templates). */
10538 if (!buf
.empty () && buf
.string ().back () == '>')
10545 /* For C++ methods, append formal parameter type
10546 information, if PHYSNAME. */
10548 if (physname
&& die
->tag
== DW_TAG_subprogram
10549 && cu
->language
== language_cplus
)
10551 struct type
*type
= read_type_die (die
, cu
);
10553 c_type_print_args (type
, &buf
, 1, cu
->language
,
10554 &type_print_raw_options
);
10556 if (cu
->language
== language_cplus
)
10558 /* Assume that an artificial first parameter is
10559 "this", but do not crash if it is not. RealView
10560 marks unnamed (and thus unused) parameters as
10561 artificial; there is no way to differentiate
10563 if (type
->num_fields () > 0
10564 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10565 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10566 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10567 buf
.puts (" const");
10571 const std::string
&intermediate_name
= buf
.string ();
10573 if (cu
->language
== language_cplus
)
10575 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10578 /* If we only computed INTERMEDIATE_NAME, or if
10579 INTERMEDIATE_NAME is already canonical, then we need to
10581 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10582 name
= objfile
->intern (intermediate_name
);
10584 name
= canonical_name
;
10591 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10592 If scope qualifiers are appropriate they will be added. The result
10593 will be allocated on the storage_obstack, or NULL if the DIE does
10594 not have a name. NAME may either be from a previous call to
10595 dwarf2_name or NULL.
10597 The output string will be canonicalized (if C++). */
10599 static const char *
10600 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10602 return dwarf2_compute_name (name
, die
, cu
, 0);
10605 /* Construct a physname for the given DIE in CU. NAME may either be
10606 from a previous call to dwarf2_name or NULL. The result will be
10607 allocated on the objfile_objstack or NULL if the DIE does not have a
10610 The output string will be canonicalized (if C++). */
10612 static const char *
10613 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10615 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10616 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10619 /* In this case dwarf2_compute_name is just a shortcut not building anything
10621 if (!die_needs_namespace (die
, cu
))
10622 return dwarf2_compute_name (name
, die
, cu
, 1);
10624 if (cu
->language
!= language_rust
)
10625 mangled
= dw2_linkage_name (die
, cu
);
10627 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10629 gdb::unique_xmalloc_ptr
<char> demangled
;
10630 if (mangled
!= NULL
)
10633 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10635 /* Do nothing (do not demangle the symbol name). */
10639 /* Use DMGL_RET_DROP for C++ template functions to suppress
10640 their return type. It is easier for GDB users to search
10641 for such functions as `name(params)' than `long name(params)'.
10642 In such case the minimal symbol names do not match the full
10643 symbol names but for template functions there is never a need
10644 to look up their definition from their declaration so
10645 the only disadvantage remains the minimal symbol variant
10646 `long name(params)' does not have the proper inferior type. */
10647 demangled
.reset (gdb_demangle (mangled
,
10648 (DMGL_PARAMS
| DMGL_ANSI
10649 | DMGL_RET_DROP
)));
10652 canon
= demangled
.get ();
10660 if (canon
== NULL
|| check_physname
)
10662 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10664 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10666 /* It may not mean a bug in GDB. The compiler could also
10667 compute DW_AT_linkage_name incorrectly. But in such case
10668 GDB would need to be bug-to-bug compatible. */
10670 complaint (_("Computed physname <%s> does not match demangled <%s> "
10671 "(from linkage <%s>) - DIE at %s [in module %s]"),
10672 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10673 objfile_name (objfile
));
10675 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10676 is available here - over computed PHYSNAME. It is safer
10677 against both buggy GDB and buggy compilers. */
10691 retval
= objfile
->intern (retval
);
10696 /* Inspect DIE in CU for a namespace alias. If one exists, record
10697 a new symbol for it.
10699 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10702 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10704 struct attribute
*attr
;
10706 /* If the die does not have a name, this is not a namespace
10708 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10712 struct die_info
*d
= die
;
10713 struct dwarf2_cu
*imported_cu
= cu
;
10715 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10716 keep inspecting DIEs until we hit the underlying import. */
10717 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10718 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10720 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10724 d
= follow_die_ref (d
, attr
, &imported_cu
);
10725 if (d
->tag
!= DW_TAG_imported_declaration
)
10729 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10731 complaint (_("DIE at %s has too many recursively imported "
10732 "declarations"), sect_offset_str (d
->sect_off
));
10739 sect_offset sect_off
= attr
->get_ref_die_offset ();
10741 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10742 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10744 /* This declaration is a global namespace alias. Add
10745 a symbol for it whose type is the aliased namespace. */
10746 new_symbol (die
, type
, cu
);
10755 /* Return the using directives repository (global or local?) to use in the
10756 current context for CU.
10758 For Ada, imported declarations can materialize renamings, which *may* be
10759 global. However it is impossible (for now?) in DWARF to distinguish
10760 "external" imported declarations and "static" ones. As all imported
10761 declarations seem to be static in all other languages, make them all CU-wide
10762 global only in Ada. */
10764 static struct using_direct
**
10765 using_directives (struct dwarf2_cu
*cu
)
10767 if (cu
->language
== language_ada
10768 && cu
->get_builder ()->outermost_context_p ())
10769 return cu
->get_builder ()->get_global_using_directives ();
10771 return cu
->get_builder ()->get_local_using_directives ();
10774 /* Read the import statement specified by the given die and record it. */
10777 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10779 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10780 struct attribute
*import_attr
;
10781 struct die_info
*imported_die
, *child_die
;
10782 struct dwarf2_cu
*imported_cu
;
10783 const char *imported_name
;
10784 const char *imported_name_prefix
;
10785 const char *canonical_name
;
10786 const char *import_alias
;
10787 const char *imported_declaration
= NULL
;
10788 const char *import_prefix
;
10789 std::vector
<const char *> excludes
;
10791 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10792 if (import_attr
== NULL
)
10794 complaint (_("Tag '%s' has no DW_AT_import"),
10795 dwarf_tag_name (die
->tag
));
10800 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10801 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10802 if (imported_name
== NULL
)
10804 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10806 The import in the following code:
10820 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10821 <52> DW_AT_decl_file : 1
10822 <53> DW_AT_decl_line : 6
10823 <54> DW_AT_import : <0x75>
10824 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10825 <59> DW_AT_name : B
10826 <5b> DW_AT_decl_file : 1
10827 <5c> DW_AT_decl_line : 2
10828 <5d> DW_AT_type : <0x6e>
10830 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10831 <76> DW_AT_byte_size : 4
10832 <77> DW_AT_encoding : 5 (signed)
10834 imports the wrong die ( 0x75 instead of 0x58 ).
10835 This case will be ignored until the gcc bug is fixed. */
10839 /* Figure out the local name after import. */
10840 import_alias
= dwarf2_name (die
, cu
);
10842 /* Figure out where the statement is being imported to. */
10843 import_prefix
= determine_prefix (die
, cu
);
10845 /* Figure out what the scope of the imported die is and prepend it
10846 to the name of the imported die. */
10847 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10849 if (imported_die
->tag
!= DW_TAG_namespace
10850 && imported_die
->tag
!= DW_TAG_module
)
10852 imported_declaration
= imported_name
;
10853 canonical_name
= imported_name_prefix
;
10855 else if (strlen (imported_name_prefix
) > 0)
10856 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10857 imported_name_prefix
,
10858 (cu
->language
== language_d
? "." : "::"),
10859 imported_name
, (char *) NULL
);
10861 canonical_name
= imported_name
;
10863 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10864 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10865 child_die
= child_die
->sibling
)
10867 /* DWARF-4: A Fortran use statement with a “rename list” may be
10868 represented by an imported module entry with an import attribute
10869 referring to the module and owned entries corresponding to those
10870 entities that are renamed as part of being imported. */
10872 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10874 complaint (_("child DW_TAG_imported_declaration expected "
10875 "- DIE at %s [in module %s]"),
10876 sect_offset_str (child_die
->sect_off
),
10877 objfile_name (objfile
));
10881 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10882 if (import_attr
== NULL
)
10884 complaint (_("Tag '%s' has no DW_AT_import"),
10885 dwarf_tag_name (child_die
->tag
));
10890 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10892 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10893 if (imported_name
== NULL
)
10895 complaint (_("child DW_TAG_imported_declaration has unknown "
10896 "imported name - DIE at %s [in module %s]"),
10897 sect_offset_str (child_die
->sect_off
),
10898 objfile_name (objfile
));
10902 excludes
.push_back (imported_name
);
10904 process_die (child_die
, cu
);
10907 add_using_directive (using_directives (cu
),
10911 imported_declaration
,
10914 &objfile
->objfile_obstack
);
10917 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10918 types, but gives them a size of zero. Starting with version 14,
10919 ICC is compatible with GCC. */
10922 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10924 if (!cu
->checked_producer
)
10925 check_producer (cu
);
10927 return cu
->producer_is_icc_lt_14
;
10930 /* ICC generates a DW_AT_type for C void functions. This was observed on
10931 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10932 which says that void functions should not have a DW_AT_type. */
10935 producer_is_icc (struct dwarf2_cu
*cu
)
10937 if (!cu
->checked_producer
)
10938 check_producer (cu
);
10940 return cu
->producer_is_icc
;
10943 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10944 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10945 this, it was first present in GCC release 4.3.0. */
10948 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10950 if (!cu
->checked_producer
)
10951 check_producer (cu
);
10953 return cu
->producer_is_gcc_lt_4_3
;
10956 static file_and_directory
10957 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10959 file_and_directory res
;
10961 /* Find the filename. Do not use dwarf2_name here, since the filename
10962 is not a source language identifier. */
10963 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10964 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10966 if (res
.comp_dir
== NULL
10967 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10968 && IS_ABSOLUTE_PATH (res
.name
))
10970 res
.comp_dir_storage
= ldirname (res
.name
);
10971 if (!res
.comp_dir_storage
.empty ())
10972 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10974 if (res
.comp_dir
!= NULL
)
10976 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10977 directory, get rid of it. */
10978 const char *cp
= strchr (res
.comp_dir
, ':');
10980 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10981 res
.comp_dir
= cp
+ 1;
10984 if (res
.name
== NULL
)
10985 res
.name
= "<unknown>";
10990 /* Handle DW_AT_stmt_list for a compilation unit.
10991 DIE is the DW_TAG_compile_unit die for CU.
10992 COMP_DIR is the compilation directory. LOWPC is passed to
10993 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10996 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10997 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10999 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11000 struct attribute
*attr
;
11001 struct line_header line_header_local
;
11002 hashval_t line_header_local_hash
;
11004 int decode_mapping
;
11006 gdb_assert (! cu
->per_cu
->is_debug_types
);
11008 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11012 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11014 /* The line header hash table is only created if needed (it exists to
11015 prevent redundant reading of the line table for partial_units).
11016 If we're given a partial_unit, we'll need it. If we're given a
11017 compile_unit, then use the line header hash table if it's already
11018 created, but don't create one just yet. */
11020 if (per_objfile
->line_header_hash
== NULL
11021 && die
->tag
== DW_TAG_partial_unit
)
11023 per_objfile
->line_header_hash
11024 .reset (htab_create_alloc (127, line_header_hash_voidp
,
11025 line_header_eq_voidp
,
11026 free_line_header_voidp
,
11030 line_header_local
.sect_off
= line_offset
;
11031 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11032 line_header_local_hash
= line_header_hash (&line_header_local
);
11033 if (per_objfile
->line_header_hash
!= NULL
)
11035 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11036 &line_header_local
,
11037 line_header_local_hash
, NO_INSERT
);
11039 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11040 is not present in *SLOT (since if there is something in *SLOT then
11041 it will be for a partial_unit). */
11042 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11044 gdb_assert (*slot
!= NULL
);
11045 cu
->line_header
= (struct line_header
*) *slot
;
11050 /* dwarf_decode_line_header does not yet provide sufficient information.
11051 We always have to call also dwarf_decode_lines for it. */
11052 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11056 cu
->line_header
= lh
.release ();
11057 cu
->line_header_die_owner
= die
;
11059 if (per_objfile
->line_header_hash
== NULL
)
11063 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11064 &line_header_local
,
11065 line_header_local_hash
, INSERT
);
11066 gdb_assert (slot
!= NULL
);
11068 if (slot
!= NULL
&& *slot
== NULL
)
11070 /* This newly decoded line number information unit will be owned
11071 by line_header_hash hash table. */
11072 *slot
= cu
->line_header
;
11073 cu
->line_header_die_owner
= NULL
;
11077 /* We cannot free any current entry in (*slot) as that struct line_header
11078 may be already used by multiple CUs. Create only temporary decoded
11079 line_header for this CU - it may happen at most once for each line
11080 number information unit. And if we're not using line_header_hash
11081 then this is what we want as well. */
11082 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11084 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11085 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11090 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11093 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11095 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11096 struct objfile
*objfile
= per_objfile
->objfile
;
11097 struct gdbarch
*gdbarch
= objfile
->arch ();
11098 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11099 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11100 struct attribute
*attr
;
11101 struct die_info
*child_die
;
11102 CORE_ADDR baseaddr
;
11104 prepare_one_comp_unit (cu
, die
, cu
->language
);
11105 baseaddr
= objfile
->text_section_offset ();
11107 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11109 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11110 from finish_block. */
11111 if (lowpc
== ((CORE_ADDR
) -1))
11113 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11115 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11117 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11118 standardised yet. As a workaround for the language detection we fall
11119 back to the DW_AT_producer string. */
11120 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11121 cu
->language
= language_opencl
;
11123 /* Similar hack for Go. */
11124 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11125 set_cu_language (DW_LANG_Go
, cu
);
11127 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11129 /* Decode line number information if present. We do this before
11130 processing child DIEs, so that the line header table is available
11131 for DW_AT_decl_file. */
11132 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11134 /* Process all dies in compilation unit. */
11135 if (die
->child
!= NULL
)
11137 child_die
= die
->child
;
11138 while (child_die
&& child_die
->tag
)
11140 process_die (child_die
, cu
);
11141 child_die
= child_die
->sibling
;
11145 /* Decode macro information, if present. Dwarf 2 macro information
11146 refers to information in the line number info statement program
11147 header, so we can only read it if we've read the header
11149 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11151 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11152 if (attr
&& cu
->line_header
)
11154 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11155 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11157 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11161 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11162 if (attr
&& cu
->line_header
)
11164 unsigned int macro_offset
= DW_UNSND (attr
);
11166 dwarf_decode_macros (cu
, macro_offset
, 0);
11172 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11174 struct type_unit_group
*tu_group
;
11176 struct attribute
*attr
;
11178 struct signatured_type
*sig_type
;
11180 gdb_assert (per_cu
->is_debug_types
);
11181 sig_type
= (struct signatured_type
*) per_cu
;
11183 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11185 /* If we're using .gdb_index (includes -readnow) then
11186 per_cu->type_unit_group may not have been set up yet. */
11187 if (sig_type
->type_unit_group
== NULL
)
11188 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11189 tu_group
= sig_type
->type_unit_group
;
11191 /* If we've already processed this stmt_list there's no real need to
11192 do it again, we could fake it and just recreate the part we need
11193 (file name,index -> symtab mapping). If data shows this optimization
11194 is useful we can do it then. */
11195 type_unit_group_unshareable
*tug_unshare
11196 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11197 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11199 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11204 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11205 lh
= dwarf_decode_line_header (line_offset
, this);
11210 start_symtab ("", NULL
, 0);
11213 gdb_assert (tug_unshare
->symtabs
== NULL
);
11214 gdb_assert (m_builder
== nullptr);
11215 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11216 m_builder
.reset (new struct buildsym_compunit
11217 (COMPUNIT_OBJFILE (cust
), "",
11218 COMPUNIT_DIRNAME (cust
),
11219 compunit_language (cust
),
11221 list_in_scope
= get_builder ()->get_file_symbols ();
11226 line_header
= lh
.release ();
11227 line_header_die_owner
= die
;
11231 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11233 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11234 still initializing it, and our caller (a few levels up)
11235 process_full_type_unit still needs to know if this is the first
11238 tug_unshare
->symtabs
11239 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11240 struct symtab
*, line_header
->file_names_size ());
11242 auto &file_names
= line_header
->file_names ();
11243 for (i
= 0; i
< file_names
.size (); ++i
)
11245 file_entry
&fe
= file_names
[i
];
11246 dwarf2_start_subfile (this, fe
.name
,
11247 fe
.include_dir (line_header
));
11248 buildsym_compunit
*b
= get_builder ();
11249 if (b
->get_current_subfile ()->symtab
== NULL
)
11251 /* NOTE: start_subfile will recognize when it's been
11252 passed a file it has already seen. So we can't
11253 assume there's a simple mapping from
11254 cu->line_header->file_names to subfiles, plus
11255 cu->line_header->file_names may contain dups. */
11256 b
->get_current_subfile ()->symtab
11257 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11260 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11261 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11266 gdb_assert (m_builder
== nullptr);
11267 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11268 m_builder
.reset (new struct buildsym_compunit
11269 (COMPUNIT_OBJFILE (cust
), "",
11270 COMPUNIT_DIRNAME (cust
),
11271 compunit_language (cust
),
11273 list_in_scope
= get_builder ()->get_file_symbols ();
11275 auto &file_names
= line_header
->file_names ();
11276 for (i
= 0; i
< file_names
.size (); ++i
)
11278 file_entry
&fe
= file_names
[i
];
11279 fe
.symtab
= tug_unshare
->symtabs
[i
];
11283 /* The main symtab is allocated last. Type units don't have DW_AT_name
11284 so they don't have a "real" (so to speak) symtab anyway.
11285 There is later code that will assign the main symtab to all symbols
11286 that don't have one. We need to handle the case of a symbol with a
11287 missing symtab (DW_AT_decl_file) anyway. */
11290 /* Process DW_TAG_type_unit.
11291 For TUs we want to skip the first top level sibling if it's not the
11292 actual type being defined by this TU. In this case the first top
11293 level sibling is there to provide context only. */
11296 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11298 struct die_info
*child_die
;
11300 prepare_one_comp_unit (cu
, die
, language_minimal
);
11302 /* Initialize (or reinitialize) the machinery for building symtabs.
11303 We do this before processing child DIEs, so that the line header table
11304 is available for DW_AT_decl_file. */
11305 cu
->setup_type_unit_groups (die
);
11307 if (die
->child
!= NULL
)
11309 child_die
= die
->child
;
11310 while (child_die
&& child_die
->tag
)
11312 process_die (child_die
, cu
);
11313 child_die
= child_die
->sibling
;
11320 http://gcc.gnu.org/wiki/DebugFission
11321 http://gcc.gnu.org/wiki/DebugFissionDWP
11323 To simplify handling of both DWO files ("object" files with the DWARF info)
11324 and DWP files (a file with the DWOs packaged up into one file), we treat
11325 DWP files as having a collection of virtual DWO files. */
11328 hash_dwo_file (const void *item
)
11330 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11333 hash
= htab_hash_string (dwo_file
->dwo_name
);
11334 if (dwo_file
->comp_dir
!= NULL
)
11335 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11340 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11342 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11343 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11345 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11347 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11348 return lhs
->comp_dir
== rhs
->comp_dir
;
11349 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11352 /* Allocate a hash table for DWO files. */
11355 allocate_dwo_file_hash_table ()
11357 auto delete_dwo_file
= [] (void *item
)
11359 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11364 return htab_up (htab_create_alloc (41,
11371 /* Lookup DWO file DWO_NAME. */
11374 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11375 const char *dwo_name
,
11376 const char *comp_dir
)
11378 struct dwo_file find_entry
;
11381 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11382 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11384 find_entry
.dwo_name
= dwo_name
;
11385 find_entry
.comp_dir
= comp_dir
;
11386 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11393 hash_dwo_unit (const void *item
)
11395 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11397 /* This drops the top 32 bits of the id, but is ok for a hash. */
11398 return dwo_unit
->signature
;
11402 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11404 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11405 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11407 /* The signature is assumed to be unique within the DWO file.
11408 So while object file CU dwo_id's always have the value zero,
11409 that's OK, assuming each object file DWO file has only one CU,
11410 and that's the rule for now. */
11411 return lhs
->signature
== rhs
->signature
;
11414 /* Allocate a hash table for DWO CUs,TUs.
11415 There is one of these tables for each of CUs,TUs for each DWO file. */
11418 allocate_dwo_unit_table ()
11420 /* Start out with a pretty small number.
11421 Generally DWO files contain only one CU and maybe some TUs. */
11422 return htab_up (htab_create_alloc (3,
11425 NULL
, xcalloc
, xfree
));
11428 /* die_reader_func for create_dwo_cu. */
11431 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11432 const gdb_byte
*info_ptr
,
11433 struct die_info
*comp_unit_die
,
11434 struct dwo_file
*dwo_file
,
11435 struct dwo_unit
*dwo_unit
)
11437 struct dwarf2_cu
*cu
= reader
->cu
;
11438 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11439 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11441 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11442 if (!signature
.has_value ())
11444 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11445 " its dwo_id [in module %s]"),
11446 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11450 dwo_unit
->dwo_file
= dwo_file
;
11451 dwo_unit
->signature
= *signature
;
11452 dwo_unit
->section
= section
;
11453 dwo_unit
->sect_off
= sect_off
;
11454 dwo_unit
->length
= cu
->per_cu
->length
;
11456 if (dwarf_read_debug
)
11457 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11458 sect_offset_str (sect_off
),
11459 hex_string (dwo_unit
->signature
));
11462 /* Create the dwo_units for the CUs in a DWO_FILE.
11463 Note: This function processes DWO files only, not DWP files. */
11466 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11467 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11468 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11470 struct objfile
*objfile
= per_objfile
->objfile
;
11471 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11472 const gdb_byte
*info_ptr
, *end_ptr
;
11474 section
.read (objfile
);
11475 info_ptr
= section
.buffer
;
11477 if (info_ptr
== NULL
)
11480 if (dwarf_read_debug
)
11482 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11483 section
.get_name (),
11484 section
.get_file_name ());
11487 end_ptr
= info_ptr
+ section
.size
;
11488 while (info_ptr
< end_ptr
)
11490 struct dwarf2_per_cu_data per_cu
;
11491 struct dwo_unit read_unit
{};
11492 struct dwo_unit
*dwo_unit
;
11494 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11496 memset (&per_cu
, 0, sizeof (per_cu
));
11497 per_cu
.per_bfd
= per_bfd
;
11498 per_cu
.is_debug_types
= 0;
11499 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11500 per_cu
.section
= §ion
;
11502 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11503 if (!reader
.dummy_p
)
11504 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11505 &dwo_file
, &read_unit
);
11506 info_ptr
+= per_cu
.length
;
11508 // If the unit could not be parsed, skip it.
11509 if (read_unit
.dwo_file
== NULL
)
11512 if (cus_htab
== NULL
)
11513 cus_htab
= allocate_dwo_unit_table ();
11515 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11517 *dwo_unit
= read_unit
;
11518 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11519 gdb_assert (slot
!= NULL
);
11522 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11523 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11525 complaint (_("debug cu entry at offset %s is duplicate to"
11526 " the entry at offset %s, signature %s"),
11527 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11528 hex_string (dwo_unit
->signature
));
11530 *slot
= (void *)dwo_unit
;
11534 /* DWP file .debug_{cu,tu}_index section format:
11535 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11536 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11538 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11539 officially standard DWP format was published with DWARF v5 and is called
11540 Version 5. There are no versions 3 or 4.
11544 Both index sections have the same format, and serve to map a 64-bit
11545 signature to a set of section numbers. Each section begins with a header,
11546 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11547 indexes, and a pool of 32-bit section numbers. The index sections will be
11548 aligned at 8-byte boundaries in the file.
11550 The index section header consists of:
11552 V, 32 bit version number
11554 N, 32 bit number of compilation units or type units in the index
11555 M, 32 bit number of slots in the hash table
11557 Numbers are recorded using the byte order of the application binary.
11559 The hash table begins at offset 16 in the section, and consists of an array
11560 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11561 order of the application binary). Unused slots in the hash table are 0.
11562 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11564 The parallel table begins immediately after the hash table
11565 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11566 array of 32-bit indexes (using the byte order of the application binary),
11567 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11568 table contains a 32-bit index into the pool of section numbers. For unused
11569 hash table slots, the corresponding entry in the parallel table will be 0.
11571 The pool of section numbers begins immediately following the hash table
11572 (at offset 16 + 12 * M from the beginning of the section). The pool of
11573 section numbers consists of an array of 32-bit words (using the byte order
11574 of the application binary). Each item in the array is indexed starting
11575 from 0. The hash table entry provides the index of the first section
11576 number in the set. Additional section numbers in the set follow, and the
11577 set is terminated by a 0 entry (section number 0 is not used in ELF).
11579 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11580 section must be the first entry in the set, and the .debug_abbrev.dwo must
11581 be the second entry. Other members of the set may follow in any order.
11585 DWP Versions 2 and 5:
11587 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11588 and the entries in the index tables are now offsets into these sections.
11589 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11592 Index Section Contents:
11594 Hash Table of Signatures dwp_hash_table.hash_table
11595 Parallel Table of Indices dwp_hash_table.unit_table
11596 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11597 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11599 The index section header consists of:
11601 V, 32 bit version number
11602 L, 32 bit number of columns in the table of section offsets
11603 N, 32 bit number of compilation units or type units in the index
11604 M, 32 bit number of slots in the hash table
11606 Numbers are recorded using the byte order of the application binary.
11608 The hash table has the same format as version 1.
11609 The parallel table of indices has the same format as version 1,
11610 except that the entries are origin-1 indices into the table of sections
11611 offsets and the table of section sizes.
11613 The table of offsets begins immediately following the parallel table
11614 (at offset 16 + 12 * M from the beginning of the section). The table is
11615 a two-dimensional array of 32-bit words (using the byte order of the
11616 application binary), with L columns and N+1 rows, in row-major order.
11617 Each row in the array is indexed starting from 0. The first row provides
11618 a key to the remaining rows: each column in this row provides an identifier
11619 for a debug section, and the offsets in the same column of subsequent rows
11620 refer to that section. The section identifiers for Version 2 are:
11622 DW_SECT_INFO 1 .debug_info.dwo
11623 DW_SECT_TYPES 2 .debug_types.dwo
11624 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11625 DW_SECT_LINE 4 .debug_line.dwo
11626 DW_SECT_LOC 5 .debug_loc.dwo
11627 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11628 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11629 DW_SECT_MACRO 8 .debug_macro.dwo
11631 The section identifiers for Version 5 are:
11633 DW_SECT_INFO_V5 1 .debug_info.dwo
11634 DW_SECT_RESERVED_V5 2 --
11635 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11636 DW_SECT_LINE_V5 4 .debug_line.dwo
11637 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11638 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11639 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11640 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11642 The offsets provided by the CU and TU index sections are the base offsets
11643 for the contributions made by each CU or TU to the corresponding section
11644 in the package file. Each CU and TU header contains an abbrev_offset
11645 field, used to find the abbreviations table for that CU or TU within the
11646 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11647 be interpreted as relative to the base offset given in the index section.
11648 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11649 should be interpreted as relative to the base offset for .debug_line.dwo,
11650 and offsets into other debug sections obtained from DWARF attributes should
11651 also be interpreted as relative to the corresponding base offset.
11653 The table of sizes begins immediately following the table of offsets.
11654 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11655 with L columns and N rows, in row-major order. Each row in the array is
11656 indexed starting from 1 (row 0 is shared by the two tables).
11660 Hash table lookup is handled the same in version 1 and 2:
11662 We assume that N and M will not exceed 2^32 - 1.
11663 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11665 Given a 64-bit compilation unit signature or a type signature S, an entry
11666 in the hash table is located as follows:
11668 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11669 the low-order k bits all set to 1.
11671 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11673 3) If the hash table entry at index H matches the signature, use that
11674 entry. If the hash table entry at index H is unused (all zeroes),
11675 terminate the search: the signature is not present in the table.
11677 4) Let H = (H + H') modulo M. Repeat at Step 3.
11679 Because M > N and H' and M are relatively prime, the search is guaranteed
11680 to stop at an unused slot or find the match. */
11682 /* Create a hash table to map DWO IDs to their CU/TU entry in
11683 .debug_{info,types}.dwo in DWP_FILE.
11684 Returns NULL if there isn't one.
11685 Note: This function processes DWP files only, not DWO files. */
11687 static struct dwp_hash_table
*
11688 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11689 struct dwp_file
*dwp_file
, int is_debug_types
)
11691 struct objfile
*objfile
= per_objfile
->objfile
;
11692 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11693 const gdb_byte
*index_ptr
, *index_end
;
11694 struct dwarf2_section_info
*index
;
11695 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11696 struct dwp_hash_table
*htab
;
11698 if (is_debug_types
)
11699 index
= &dwp_file
->sections
.tu_index
;
11701 index
= &dwp_file
->sections
.cu_index
;
11703 if (index
->empty ())
11705 index
->read (objfile
);
11707 index_ptr
= index
->buffer
;
11708 index_end
= index_ptr
+ index
->size
;
11710 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11711 For now it's safe to just read 4 bytes (particularly as it's difficult to
11712 tell if you're dealing with Version 5 before you've read the version). */
11713 version
= read_4_bytes (dbfd
, index_ptr
);
11715 if (version
== 2 || version
== 5)
11716 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11720 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11722 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11725 if (version
!= 1 && version
!= 2 && version
!= 5)
11727 error (_("Dwarf Error: unsupported DWP file version (%s)"
11728 " [in module %s]"),
11729 pulongest (version
), dwp_file
->name
);
11731 if (nr_slots
!= (nr_slots
& -nr_slots
))
11733 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11734 " is not power of 2 [in module %s]"),
11735 pulongest (nr_slots
), dwp_file
->name
);
11738 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11739 htab
->version
= version
;
11740 htab
->nr_columns
= nr_columns
;
11741 htab
->nr_units
= nr_units
;
11742 htab
->nr_slots
= nr_slots
;
11743 htab
->hash_table
= index_ptr
;
11744 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11746 /* Exit early if the table is empty. */
11747 if (nr_slots
== 0 || nr_units
== 0
11748 || (version
== 2 && nr_columns
== 0)
11749 || (version
== 5 && nr_columns
== 0))
11751 /* All must be zero. */
11752 if (nr_slots
!= 0 || nr_units
!= 0
11753 || (version
== 2 && nr_columns
!= 0)
11754 || (version
== 5 && nr_columns
!= 0))
11756 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11757 " all zero [in modules %s]"),
11765 htab
->section_pool
.v1
.indices
=
11766 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11767 /* It's harder to decide whether the section is too small in v1.
11768 V1 is deprecated anyway so we punt. */
11770 else if (version
== 2)
11772 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11773 int *ids
= htab
->section_pool
.v2
.section_ids
;
11774 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11775 /* Reverse map for error checking. */
11776 int ids_seen
[DW_SECT_MAX
+ 1];
11779 if (nr_columns
< 2)
11781 error (_("Dwarf Error: bad DWP hash table, too few columns"
11782 " in section table [in module %s]"),
11785 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11787 error (_("Dwarf Error: bad DWP hash table, too many columns"
11788 " in section table [in module %s]"),
11791 memset (ids
, 255, sizeof_ids
);
11792 memset (ids_seen
, 255, sizeof (ids_seen
));
11793 for (i
= 0; i
< nr_columns
; ++i
)
11795 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11797 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11799 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11800 " in section table [in module %s]"),
11801 id
, dwp_file
->name
);
11803 if (ids_seen
[id
] != -1)
11805 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11806 " id %d in section table [in module %s]"),
11807 id
, dwp_file
->name
);
11812 /* Must have exactly one info or types section. */
11813 if (((ids_seen
[DW_SECT_INFO
] != -1)
11814 + (ids_seen
[DW_SECT_TYPES
] != -1))
11817 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11818 " DWO info/types section [in module %s]"),
11821 /* Must have an abbrev section. */
11822 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11824 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11825 " section [in module %s]"),
11828 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11829 htab
->section_pool
.v2
.sizes
=
11830 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11831 * nr_units
* nr_columns
);
11832 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11833 * nr_units
* nr_columns
))
11836 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11837 " [in module %s]"),
11841 else /* version == 5 */
11843 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11844 int *ids
= htab
->section_pool
.v5
.section_ids
;
11845 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11846 /* Reverse map for error checking. */
11847 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11849 if (nr_columns
< 2)
11851 error (_("Dwarf Error: bad DWP hash table, too few columns"
11852 " in section table [in module %s]"),
11855 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11857 error (_("Dwarf Error: bad DWP hash table, too many columns"
11858 " in section table [in module %s]"),
11861 memset (ids
, 255, sizeof_ids
);
11862 memset (ids_seen
, 255, sizeof (ids_seen
));
11863 for (int i
= 0; i
< nr_columns
; ++i
)
11865 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11867 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11869 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11870 " in section table [in module %s]"),
11871 id
, dwp_file
->name
);
11873 if (ids_seen
[id
] != -1)
11875 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11876 " id %d in section table [in module %s]"),
11877 id
, dwp_file
->name
);
11882 /* Must have seen an info section. */
11883 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11885 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11886 " DWO info/types section [in module %s]"),
11889 /* Must have an abbrev section. */
11890 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11892 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11893 " section [in module %s]"),
11896 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11897 htab
->section_pool
.v5
.sizes
11898 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11899 * nr_units
* nr_columns
);
11900 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11901 * nr_units
* nr_columns
))
11904 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11905 " [in module %s]"),
11913 /* Update SECTIONS with the data from SECTP.
11915 This function is like the other "locate" section routines, but in
11916 this context the sections to read comes from the DWP V1 hash table,
11917 not the full ELF section table.
11919 The result is non-zero for success, or zero if an error was found. */
11922 locate_v1_virtual_dwo_sections (asection
*sectp
,
11923 struct virtual_v1_dwo_sections
*sections
)
11925 const struct dwop_section_names
*names
= &dwop_section_names
;
11927 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11929 /* There can be only one. */
11930 if (sections
->abbrev
.s
.section
!= NULL
)
11932 sections
->abbrev
.s
.section
= sectp
;
11933 sections
->abbrev
.size
= bfd_section_size (sectp
);
11935 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11936 || section_is_p (sectp
->name
, &names
->types_dwo
))
11938 /* There can be only one. */
11939 if (sections
->info_or_types
.s
.section
!= NULL
)
11941 sections
->info_or_types
.s
.section
= sectp
;
11942 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11944 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11946 /* There can be only one. */
11947 if (sections
->line
.s
.section
!= NULL
)
11949 sections
->line
.s
.section
= sectp
;
11950 sections
->line
.size
= bfd_section_size (sectp
);
11952 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11954 /* There can be only one. */
11955 if (sections
->loc
.s
.section
!= NULL
)
11957 sections
->loc
.s
.section
= sectp
;
11958 sections
->loc
.size
= bfd_section_size (sectp
);
11960 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11962 /* There can be only one. */
11963 if (sections
->macinfo
.s
.section
!= NULL
)
11965 sections
->macinfo
.s
.section
= sectp
;
11966 sections
->macinfo
.size
= bfd_section_size (sectp
);
11968 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11970 /* There can be only one. */
11971 if (sections
->macro
.s
.section
!= NULL
)
11973 sections
->macro
.s
.section
= sectp
;
11974 sections
->macro
.size
= bfd_section_size (sectp
);
11976 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11978 /* There can be only one. */
11979 if (sections
->str_offsets
.s
.section
!= NULL
)
11981 sections
->str_offsets
.s
.section
= sectp
;
11982 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11986 /* No other kind of section is valid. */
11993 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11994 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11995 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11996 This is for DWP version 1 files. */
11998 static struct dwo_unit
*
11999 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
12000 struct dwp_file
*dwp_file
,
12001 uint32_t unit_index
,
12002 const char *comp_dir
,
12003 ULONGEST signature
, int is_debug_types
)
12005 const struct dwp_hash_table
*dwp_htab
=
12006 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12007 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12008 const char *kind
= is_debug_types
? "TU" : "CU";
12009 struct dwo_file
*dwo_file
;
12010 struct dwo_unit
*dwo_unit
;
12011 struct virtual_v1_dwo_sections sections
;
12012 void **dwo_file_slot
;
12015 gdb_assert (dwp_file
->version
== 1);
12017 if (dwarf_read_debug
)
12019 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12021 pulongest (unit_index
), hex_string (signature
),
12025 /* Fetch the sections of this DWO unit.
12026 Put a limit on the number of sections we look for so that bad data
12027 doesn't cause us to loop forever. */
12029 #define MAX_NR_V1_DWO_SECTIONS \
12030 (1 /* .debug_info or .debug_types */ \
12031 + 1 /* .debug_abbrev */ \
12032 + 1 /* .debug_line */ \
12033 + 1 /* .debug_loc */ \
12034 + 1 /* .debug_str_offsets */ \
12035 + 1 /* .debug_macro or .debug_macinfo */ \
12036 + 1 /* trailing zero */)
12038 memset (§ions
, 0, sizeof (sections
));
12040 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12043 uint32_t section_nr
=
12044 read_4_bytes (dbfd
,
12045 dwp_htab
->section_pool
.v1
.indices
12046 + (unit_index
+ i
) * sizeof (uint32_t));
12048 if (section_nr
== 0)
12050 if (section_nr
>= dwp_file
->num_sections
)
12052 error (_("Dwarf Error: bad DWP hash table, section number too large"
12053 " [in module %s]"),
12057 sectp
= dwp_file
->elf_sections
[section_nr
];
12058 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12060 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12061 " [in module %s]"),
12067 || sections
.info_or_types
.empty ()
12068 || sections
.abbrev
.empty ())
12070 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12071 " [in module %s]"),
12074 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12076 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12077 " [in module %s]"),
12081 /* It's easier for the rest of the code if we fake a struct dwo_file and
12082 have dwo_unit "live" in that. At least for now.
12084 The DWP file can be made up of a random collection of CUs and TUs.
12085 However, for each CU + set of TUs that came from the same original DWO
12086 file, we can combine them back into a virtual DWO file to save space
12087 (fewer struct dwo_file objects to allocate). Remember that for really
12088 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12090 std::string virtual_dwo_name
=
12091 string_printf ("virtual-dwo/%d-%d-%d-%d",
12092 sections
.abbrev
.get_id (),
12093 sections
.line
.get_id (),
12094 sections
.loc
.get_id (),
12095 sections
.str_offsets
.get_id ());
12096 /* Can we use an existing virtual DWO file? */
12097 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12099 /* Create one if necessary. */
12100 if (*dwo_file_slot
== NULL
)
12102 if (dwarf_read_debug
)
12104 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12105 virtual_dwo_name
.c_str ());
12107 dwo_file
= new struct dwo_file
;
12108 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12109 dwo_file
->comp_dir
= comp_dir
;
12110 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12111 dwo_file
->sections
.line
= sections
.line
;
12112 dwo_file
->sections
.loc
= sections
.loc
;
12113 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12114 dwo_file
->sections
.macro
= sections
.macro
;
12115 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12116 /* The "str" section is global to the entire DWP file. */
12117 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12118 /* The info or types section is assigned below to dwo_unit,
12119 there's no need to record it in dwo_file.
12120 Also, we can't simply record type sections in dwo_file because
12121 we record a pointer into the vector in dwo_unit. As we collect more
12122 types we'll grow the vector and eventually have to reallocate space
12123 for it, invalidating all copies of pointers into the previous
12125 *dwo_file_slot
= dwo_file
;
12129 if (dwarf_read_debug
)
12131 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12132 virtual_dwo_name
.c_str ());
12134 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12137 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12138 dwo_unit
->dwo_file
= dwo_file
;
12139 dwo_unit
->signature
= signature
;
12140 dwo_unit
->section
=
12141 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12142 *dwo_unit
->section
= sections
.info_or_types
;
12143 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12148 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
12149 simplify them. Given a pointer to the containing section SECTION, and
12150 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
12151 virtual section of just that piece. */
12153 static struct dwarf2_section_info
12154 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
12155 struct dwarf2_section_info
*section
,
12156 bfd_size_type offset
, bfd_size_type size
)
12158 struct dwarf2_section_info result
;
12161 gdb_assert (section
!= NULL
);
12162 gdb_assert (!section
->is_virtual
);
12164 memset (&result
, 0, sizeof (result
));
12165 result
.s
.containing_section
= section
;
12166 result
.is_virtual
= true;
12171 sectp
= section
->get_bfd_section ();
12173 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12174 bounds of the real section. This is a pretty-rare event, so just
12175 flag an error (easier) instead of a warning and trying to cope. */
12177 || offset
+ size
> bfd_section_size (sectp
))
12179 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
12180 " in section %s [in module %s]"),
12181 sectp
? bfd_section_name (sectp
) : "<unknown>",
12182 objfile_name (per_objfile
->objfile
));
12185 result
.virtual_offset
= offset
;
12186 result
.size
= size
;
12190 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12191 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12192 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12193 This is for DWP version 2 files. */
12195 static struct dwo_unit
*
12196 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12197 struct dwp_file
*dwp_file
,
12198 uint32_t unit_index
,
12199 const char *comp_dir
,
12200 ULONGEST signature
, int is_debug_types
)
12202 const struct dwp_hash_table
*dwp_htab
=
12203 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12204 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12205 const char *kind
= is_debug_types
? "TU" : "CU";
12206 struct dwo_file
*dwo_file
;
12207 struct dwo_unit
*dwo_unit
;
12208 struct virtual_v2_or_v5_dwo_sections sections
;
12209 void **dwo_file_slot
;
12212 gdb_assert (dwp_file
->version
== 2);
12214 if (dwarf_read_debug
)
12216 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12218 pulongest (unit_index
), hex_string (signature
),
12222 /* Fetch the section offsets of this DWO unit. */
12224 memset (§ions
, 0, sizeof (sections
));
12226 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12228 uint32_t offset
= read_4_bytes (dbfd
,
12229 dwp_htab
->section_pool
.v2
.offsets
12230 + (((unit_index
- 1) * dwp_htab
->nr_columns
12232 * sizeof (uint32_t)));
12233 uint32_t size
= read_4_bytes (dbfd
,
12234 dwp_htab
->section_pool
.v2
.sizes
12235 + (((unit_index
- 1) * dwp_htab
->nr_columns
12237 * sizeof (uint32_t)));
12239 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12242 case DW_SECT_TYPES
:
12243 sections
.info_or_types_offset
= offset
;
12244 sections
.info_or_types_size
= size
;
12246 case DW_SECT_ABBREV
:
12247 sections
.abbrev_offset
= offset
;
12248 sections
.abbrev_size
= size
;
12251 sections
.line_offset
= offset
;
12252 sections
.line_size
= size
;
12255 sections
.loc_offset
= offset
;
12256 sections
.loc_size
= size
;
12258 case DW_SECT_STR_OFFSETS
:
12259 sections
.str_offsets_offset
= offset
;
12260 sections
.str_offsets_size
= size
;
12262 case DW_SECT_MACINFO
:
12263 sections
.macinfo_offset
= offset
;
12264 sections
.macinfo_size
= size
;
12266 case DW_SECT_MACRO
:
12267 sections
.macro_offset
= offset
;
12268 sections
.macro_size
= size
;
12273 /* It's easier for the rest of the code if we fake a struct dwo_file and
12274 have dwo_unit "live" in that. At least for now.
12276 The DWP file can be made up of a random collection of CUs and TUs.
12277 However, for each CU + set of TUs that came from the same original DWO
12278 file, we can combine them back into a virtual DWO file to save space
12279 (fewer struct dwo_file objects to allocate). Remember that for really
12280 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12282 std::string virtual_dwo_name
=
12283 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12284 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12285 (long) (sections
.line_size
? sections
.line_offset
: 0),
12286 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12287 (long) (sections
.str_offsets_size
12288 ? sections
.str_offsets_offset
: 0));
12289 /* Can we use an existing virtual DWO file? */
12290 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12292 /* Create one if necessary. */
12293 if (*dwo_file_slot
== NULL
)
12295 if (dwarf_read_debug
)
12297 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12298 virtual_dwo_name
.c_str ());
12300 dwo_file
= new struct dwo_file
;
12301 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12302 dwo_file
->comp_dir
= comp_dir
;
12303 dwo_file
->sections
.abbrev
=
12304 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12305 sections
.abbrev_offset
,
12306 sections
.abbrev_size
);
12307 dwo_file
->sections
.line
=
12308 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12309 sections
.line_offset
,
12310 sections
.line_size
);
12311 dwo_file
->sections
.loc
=
12312 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12313 sections
.loc_offset
, sections
.loc_size
);
12314 dwo_file
->sections
.macinfo
=
12315 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12316 sections
.macinfo_offset
,
12317 sections
.macinfo_size
);
12318 dwo_file
->sections
.macro
=
12319 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12320 sections
.macro_offset
,
12321 sections
.macro_size
);
12322 dwo_file
->sections
.str_offsets
=
12323 create_dwp_v2_or_v5_section (per_objfile
,
12324 &dwp_file
->sections
.str_offsets
,
12325 sections
.str_offsets_offset
,
12326 sections
.str_offsets_size
);
12327 /* The "str" section is global to the entire DWP file. */
12328 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12329 /* The info or types section is assigned below to dwo_unit,
12330 there's no need to record it in dwo_file.
12331 Also, we can't simply record type sections in dwo_file because
12332 we record a pointer into the vector in dwo_unit. As we collect more
12333 types we'll grow the vector and eventually have to reallocate space
12334 for it, invalidating all copies of pointers into the previous
12336 *dwo_file_slot
= dwo_file
;
12340 if (dwarf_read_debug
)
12342 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12343 virtual_dwo_name
.c_str ());
12345 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12348 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12349 dwo_unit
->dwo_file
= dwo_file
;
12350 dwo_unit
->signature
= signature
;
12351 dwo_unit
->section
=
12352 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12353 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12356 ? &dwp_file
->sections
.types
12357 : &dwp_file
->sections
.info
,
12358 sections
.info_or_types_offset
,
12359 sections
.info_or_types_size
);
12360 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12365 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12366 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12367 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12368 This is for DWP version 5 files. */
12370 static struct dwo_unit
*
12371 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12372 struct dwp_file
*dwp_file
,
12373 uint32_t unit_index
,
12374 const char *comp_dir
,
12375 ULONGEST signature
, int is_debug_types
)
12377 const struct dwp_hash_table
*dwp_htab
12378 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12379 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12380 const char *kind
= is_debug_types
? "TU" : "CU";
12381 struct dwo_file
*dwo_file
;
12382 struct dwo_unit
*dwo_unit
;
12383 struct virtual_v2_or_v5_dwo_sections sections
{};
12384 void **dwo_file_slot
;
12386 gdb_assert (dwp_file
->version
== 5);
12388 if (dwarf_read_debug
)
12390 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V5 file: %s\n",
12392 pulongest (unit_index
), hex_string (signature
),
12396 /* Fetch the section offsets of this DWO unit. */
12398 /* memset (§ions, 0, sizeof (sections)); */
12400 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12402 uint32_t offset
= read_4_bytes (dbfd
,
12403 dwp_htab
->section_pool
.v5
.offsets
12404 + (((unit_index
- 1)
12405 * dwp_htab
->nr_columns
12407 * sizeof (uint32_t)));
12408 uint32_t size
= read_4_bytes (dbfd
,
12409 dwp_htab
->section_pool
.v5
.sizes
12410 + (((unit_index
- 1) * dwp_htab
->nr_columns
12412 * sizeof (uint32_t)));
12414 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12416 case DW_SECT_ABBREV_V5
:
12417 sections
.abbrev_offset
= offset
;
12418 sections
.abbrev_size
= size
;
12420 case DW_SECT_INFO_V5
:
12421 sections
.info_or_types_offset
= offset
;
12422 sections
.info_or_types_size
= size
;
12424 case DW_SECT_LINE_V5
:
12425 sections
.line_offset
= offset
;
12426 sections
.line_size
= size
;
12428 case DW_SECT_LOCLISTS_V5
:
12429 sections
.loclists_offset
= offset
;
12430 sections
.loclists_size
= size
;
12432 case DW_SECT_MACRO_V5
:
12433 sections
.macro_offset
= offset
;
12434 sections
.macro_size
= size
;
12436 case DW_SECT_RNGLISTS_V5
:
12437 sections
.rnglists_offset
= offset
;
12438 sections
.rnglists_size
= size
;
12440 case DW_SECT_STR_OFFSETS_V5
:
12441 sections
.str_offsets_offset
= offset
;
12442 sections
.str_offsets_size
= size
;
12444 case DW_SECT_RESERVED_V5
:
12450 /* It's easier for the rest of the code if we fake a struct dwo_file and
12451 have dwo_unit "live" in that. At least for now.
12453 The DWP file can be made up of a random collection of CUs and TUs.
12454 However, for each CU + set of TUs that came from the same original DWO
12455 file, we can combine them back into a virtual DWO file to save space
12456 (fewer struct dwo_file objects to allocate). Remember that for really
12457 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12459 std::string virtual_dwo_name
=
12460 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12461 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12462 (long) (sections
.line_size
? sections
.line_offset
: 0),
12463 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12464 (long) (sections
.str_offsets_size
12465 ? sections
.str_offsets_offset
: 0),
12466 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12467 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12468 /* Can we use an existing virtual DWO file? */
12469 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12470 virtual_dwo_name
.c_str (),
12472 /* Create one if necessary. */
12473 if (*dwo_file_slot
== NULL
)
12475 if (dwarf_read_debug
)
12477 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12478 virtual_dwo_name
.c_str ());
12480 dwo_file
= new struct dwo_file
;
12481 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12482 dwo_file
->comp_dir
= comp_dir
;
12483 dwo_file
->sections
.abbrev
=
12484 create_dwp_v2_or_v5_section (per_objfile
,
12485 &dwp_file
->sections
.abbrev
,
12486 sections
.abbrev_offset
,
12487 sections
.abbrev_size
);
12488 dwo_file
->sections
.line
=
12489 create_dwp_v2_or_v5_section (per_objfile
,
12490 &dwp_file
->sections
.line
,
12491 sections
.line_offset
, sections
.line_size
);
12492 dwo_file
->sections
.macro
=
12493 create_dwp_v2_or_v5_section (per_objfile
,
12494 &dwp_file
->sections
.macro
,
12495 sections
.macro_offset
,
12496 sections
.macro_size
);
12497 dwo_file
->sections
.loclists
=
12498 create_dwp_v2_or_v5_section (per_objfile
,
12499 &dwp_file
->sections
.loclists
,
12500 sections
.loclists_offset
,
12501 sections
.loclists_size
);
12502 dwo_file
->sections
.rnglists
=
12503 create_dwp_v2_or_v5_section (per_objfile
,
12504 &dwp_file
->sections
.rnglists
,
12505 sections
.rnglists_offset
,
12506 sections
.rnglists_size
);
12507 dwo_file
->sections
.str_offsets
=
12508 create_dwp_v2_or_v5_section (per_objfile
,
12509 &dwp_file
->sections
.str_offsets
,
12510 sections
.str_offsets_offset
,
12511 sections
.str_offsets_size
);
12512 /* The "str" section is global to the entire DWP file. */
12513 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12514 /* The info or types section is assigned below to dwo_unit,
12515 there's no need to record it in dwo_file.
12516 Also, we can't simply record type sections in dwo_file because
12517 we record a pointer into the vector in dwo_unit. As we collect more
12518 types we'll grow the vector and eventually have to reallocate space
12519 for it, invalidating all copies of pointers into the previous
12521 *dwo_file_slot
= dwo_file
;
12525 if (dwarf_read_debug
)
12527 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12528 virtual_dwo_name
.c_str ());
12530 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12533 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12534 dwo_unit
->dwo_file
= dwo_file
;
12535 dwo_unit
->signature
= signature
;
12537 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12538 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12539 &dwp_file
->sections
.info
,
12540 sections
.info_or_types_offset
,
12541 sections
.info_or_types_size
);
12542 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12547 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12548 Returns NULL if the signature isn't found. */
12550 static struct dwo_unit
*
12551 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12552 struct dwp_file
*dwp_file
, const char *comp_dir
,
12553 ULONGEST signature
, int is_debug_types
)
12555 const struct dwp_hash_table
*dwp_htab
=
12556 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12557 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12558 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12559 uint32_t hash
= signature
& mask
;
12560 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12563 struct dwo_unit find_dwo_cu
;
12565 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12566 find_dwo_cu
.signature
= signature
;
12567 slot
= htab_find_slot (is_debug_types
12568 ? dwp_file
->loaded_tus
.get ()
12569 : dwp_file
->loaded_cus
.get (),
12570 &find_dwo_cu
, INSERT
);
12573 return (struct dwo_unit
*) *slot
;
12575 /* Use a for loop so that we don't loop forever on bad debug info. */
12576 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12578 ULONGEST signature_in_table
;
12580 signature_in_table
=
12581 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12582 if (signature_in_table
== signature
)
12584 uint32_t unit_index
=
12585 read_4_bytes (dbfd
,
12586 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12588 if (dwp_file
->version
== 1)
12590 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12591 unit_index
, comp_dir
,
12592 signature
, is_debug_types
);
12594 else if (dwp_file
->version
== 2)
12596 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12597 unit_index
, comp_dir
,
12598 signature
, is_debug_types
);
12600 else /* version == 5 */
12602 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12603 unit_index
, comp_dir
,
12604 signature
, is_debug_types
);
12606 return (struct dwo_unit
*) *slot
;
12608 if (signature_in_table
== 0)
12610 hash
= (hash
+ hash2
) & mask
;
12613 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12614 " [in module %s]"),
12618 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12619 Open the file specified by FILE_NAME and hand it off to BFD for
12620 preliminary analysis. Return a newly initialized bfd *, which
12621 includes a canonicalized copy of FILE_NAME.
12622 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12623 SEARCH_CWD is true if the current directory is to be searched.
12624 It will be searched before debug-file-directory.
12625 If successful, the file is added to the bfd include table of the
12626 objfile's bfd (see gdb_bfd_record_inclusion).
12627 If unable to find/open the file, return NULL.
12628 NOTE: This function is derived from symfile_bfd_open. */
12630 static gdb_bfd_ref_ptr
12631 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12632 const char *file_name
, int is_dwp
, int search_cwd
)
12635 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12636 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12637 to debug_file_directory. */
12638 const char *search_path
;
12639 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12641 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12644 if (*debug_file_directory
!= '\0')
12646 search_path_holder
.reset (concat (".", dirname_separator_string
,
12647 debug_file_directory
,
12649 search_path
= search_path_holder
.get ();
12655 search_path
= debug_file_directory
;
12657 openp_flags flags
= OPF_RETURN_REALPATH
;
12659 flags
|= OPF_SEARCH_IN_PATH
;
12661 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12662 desc
= openp (search_path
, flags
, file_name
,
12663 O_RDONLY
| O_BINARY
, &absolute_name
);
12667 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12669 if (sym_bfd
== NULL
)
12671 bfd_set_cacheable (sym_bfd
.get (), 1);
12673 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12676 /* Success. Record the bfd as having been included by the objfile's bfd.
12677 This is important because things like demangled_names_hash lives in the
12678 objfile's per_bfd space and may have references to things like symbol
12679 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12680 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12685 /* Try to open DWO file FILE_NAME.
12686 COMP_DIR is the DW_AT_comp_dir attribute.
12687 The result is the bfd handle of the file.
12688 If there is a problem finding or opening the file, return NULL.
12689 Upon success, the canonicalized path of the file is stored in the bfd,
12690 same as symfile_bfd_open. */
12692 static gdb_bfd_ref_ptr
12693 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12694 const char *file_name
, const char *comp_dir
)
12696 if (IS_ABSOLUTE_PATH (file_name
))
12697 return try_open_dwop_file (per_objfile
, file_name
,
12698 0 /*is_dwp*/, 0 /*search_cwd*/);
12700 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12702 if (comp_dir
!= NULL
)
12704 gdb::unique_xmalloc_ptr
<char> path_to_try
12705 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12707 /* NOTE: If comp_dir is a relative path, this will also try the
12708 search path, which seems useful. */
12709 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12711 1 /*search_cwd*/));
12716 /* That didn't work, try debug-file-directory, which, despite its name,
12717 is a list of paths. */
12719 if (*debug_file_directory
== '\0')
12722 return try_open_dwop_file (per_objfile
, file_name
,
12723 0 /*is_dwp*/, 1 /*search_cwd*/);
12726 /* This function is mapped across the sections and remembers the offset and
12727 size of each of the DWO debugging sections we are interested in. */
12730 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12731 dwo_sections
*dwo_sections
)
12733 const struct dwop_section_names
*names
= &dwop_section_names
;
12735 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12737 dwo_sections
->abbrev
.s
.section
= sectp
;
12738 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12740 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12742 dwo_sections
->info
.s
.section
= sectp
;
12743 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12745 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12747 dwo_sections
->line
.s
.section
= sectp
;
12748 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12750 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12752 dwo_sections
->loc
.s
.section
= sectp
;
12753 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12755 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12757 dwo_sections
->loclists
.s
.section
= sectp
;
12758 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12760 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12762 dwo_sections
->macinfo
.s
.section
= sectp
;
12763 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12765 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12767 dwo_sections
->macro
.s
.section
= sectp
;
12768 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12770 else if (section_is_p (sectp
->name
, &names
->rnglists_dwo
))
12772 dwo_sections
->rnglists
.s
.section
= sectp
;
12773 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12775 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12777 dwo_sections
->str
.s
.section
= sectp
;
12778 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12780 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12782 dwo_sections
->str_offsets
.s
.section
= sectp
;
12783 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12785 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12787 struct dwarf2_section_info type_section
;
12789 memset (&type_section
, 0, sizeof (type_section
));
12790 type_section
.s
.section
= sectp
;
12791 type_section
.size
= bfd_section_size (sectp
);
12792 dwo_sections
->types
.push_back (type_section
);
12796 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12797 by PER_CU. This is for the non-DWP case.
12798 The result is NULL if DWO_NAME can't be found. */
12800 static struct dwo_file
*
12801 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12802 const char *comp_dir
)
12804 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12806 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12809 if (dwarf_read_debug
)
12810 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12814 dwo_file_up
dwo_file (new struct dwo_file
);
12815 dwo_file
->dwo_name
= dwo_name
;
12816 dwo_file
->comp_dir
= comp_dir
;
12817 dwo_file
->dbfd
= std::move (dbfd
);
12819 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12820 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12821 &dwo_file
->sections
);
12823 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12826 if (cu
->per_cu
->dwarf_version
< 5)
12828 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12829 dwo_file
->sections
.types
, dwo_file
->tus
);
12833 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12834 &dwo_file
->sections
.info
, dwo_file
->tus
,
12838 if (dwarf_read_debug
)
12839 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12841 return dwo_file
.release ();
12844 /* This function is mapped across the sections and remembers the offset and
12845 size of each of the DWP debugging sections common to version 1 and 2 that
12846 we are interested in. */
12849 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12850 dwp_file
*dwp_file
)
12852 const struct dwop_section_names
*names
= &dwop_section_names
;
12853 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12855 /* Record the ELF section number for later lookup: this is what the
12856 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12857 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12858 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12860 /* Look for specific sections that we need. */
12861 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12863 dwp_file
->sections
.str
.s
.section
= sectp
;
12864 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12866 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12868 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12869 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12871 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12873 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12874 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12878 /* This function is mapped across the sections and remembers the offset and
12879 size of each of the DWP version 2 debugging sections that we are interested
12880 in. This is split into a separate function because we don't know if we
12881 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12884 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12886 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12887 const struct dwop_section_names
*names
= &dwop_section_names
;
12888 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12890 /* Record the ELF section number for later lookup: this is what the
12891 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12892 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12893 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12895 /* Look for specific sections that we need. */
12896 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12898 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12899 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12901 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12903 dwp_file
->sections
.info
.s
.section
= sectp
;
12904 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12906 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12908 dwp_file
->sections
.line
.s
.section
= sectp
;
12909 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12911 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12913 dwp_file
->sections
.loc
.s
.section
= sectp
;
12914 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12916 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12918 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12919 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12921 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12923 dwp_file
->sections
.macro
.s
.section
= sectp
;
12924 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12926 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12928 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12929 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12931 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12933 dwp_file
->sections
.types
.s
.section
= sectp
;
12934 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12938 /* This function is mapped across the sections and remembers the offset and
12939 size of each of the DWP version 5 debugging sections that we are interested
12940 in. This is split into a separate function because we don't know if we
12941 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12944 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12946 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12947 const struct dwop_section_names
*names
= &dwop_section_names
;
12948 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12950 /* Record the ELF section number for later lookup: this is what the
12951 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12952 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12953 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12955 /* Look for specific sections that we need. */
12956 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12958 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12959 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12961 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12963 dwp_file
->sections
.info
.s
.section
= sectp
;
12964 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12966 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12968 dwp_file
->sections
.line
.s
.section
= sectp
;
12969 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12971 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12973 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12974 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12976 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12978 dwp_file
->sections
.macro
.s
.section
= sectp
;
12979 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12981 else if (section_is_p (sectp
->name
, &names
->rnglists_dwo
))
12983 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12984 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12986 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12988 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12989 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12993 /* Hash function for dwp_file loaded CUs/TUs. */
12996 hash_dwp_loaded_cutus (const void *item
)
12998 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13000 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13001 return dwo_unit
->signature
;
13004 /* Equality function for dwp_file loaded CUs/TUs. */
13007 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13009 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13010 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13012 return dua
->signature
== dub
->signature
;
13015 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13018 allocate_dwp_loaded_cutus_table ()
13020 return htab_up (htab_create_alloc (3,
13021 hash_dwp_loaded_cutus
,
13022 eq_dwp_loaded_cutus
,
13023 NULL
, xcalloc
, xfree
));
13026 /* Try to open DWP file FILE_NAME.
13027 The result is the bfd handle of the file.
13028 If there is a problem finding or opening the file, return NULL.
13029 Upon success, the canonicalized path of the file is stored in the bfd,
13030 same as symfile_bfd_open. */
13032 static gdb_bfd_ref_ptr
13033 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
13035 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
13037 1 /*search_cwd*/));
13041 /* Work around upstream bug 15652.
13042 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13043 [Whether that's a "bug" is debatable, but it is getting in our way.]
13044 We have no real idea where the dwp file is, because gdb's realpath-ing
13045 of the executable's path may have discarded the needed info.
13046 [IWBN if the dwp file name was recorded in the executable, akin to
13047 .gnu_debuglink, but that doesn't exist yet.]
13048 Strip the directory from FILE_NAME and search again. */
13049 if (*debug_file_directory
!= '\0')
13051 /* Don't implicitly search the current directory here.
13052 If the user wants to search "." to handle this case,
13053 it must be added to debug-file-directory. */
13054 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
13062 /* Initialize the use of the DWP file for the current objfile.
13063 By convention the name of the DWP file is ${objfile}.dwp.
13064 The result is NULL if it can't be found. */
13066 static std::unique_ptr
<struct dwp_file
>
13067 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
13069 struct objfile
*objfile
= per_objfile
->objfile
;
13071 /* Try to find first .dwp for the binary file before any symbolic links
13074 /* If the objfile is a debug file, find the name of the real binary
13075 file and get the name of dwp file from there. */
13076 std::string dwp_name
;
13077 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13079 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13080 const char *backlink_basename
= lbasename (backlink
->original_name
);
13082 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13085 dwp_name
= objfile
->original_name
;
13087 dwp_name
+= ".dwp";
13089 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
13091 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13093 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13094 dwp_name
= objfile_name (objfile
);
13095 dwp_name
+= ".dwp";
13096 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
13101 if (dwarf_read_debug
)
13102 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13103 return std::unique_ptr
<dwp_file
> ();
13106 const char *name
= bfd_get_filename (dbfd
.get ());
13107 std::unique_ptr
<struct dwp_file
> dwp_file
13108 (new struct dwp_file (name
, std::move (dbfd
)));
13110 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13111 dwp_file
->elf_sections
=
13112 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
13113 dwp_file
->num_sections
, asection
*);
13115 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13116 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13119 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
13121 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
13123 /* The DWP file version is stored in the hash table. Oh well. */
13124 if (dwp_file
->cus
&& dwp_file
->tus
13125 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13127 /* Technically speaking, we should try to limp along, but this is
13128 pretty bizarre. We use pulongest here because that's the established
13129 portability solution (e.g, we cannot use %u for uint32_t). */
13130 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13131 " TU version %s [in DWP file %s]"),
13132 pulongest (dwp_file
->cus
->version
),
13133 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13137 dwp_file
->version
= dwp_file
->cus
->version
;
13138 else if (dwp_file
->tus
)
13139 dwp_file
->version
= dwp_file
->tus
->version
;
13141 dwp_file
->version
= 2;
13143 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13145 if (dwp_file
->version
== 2)
13146 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13149 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13153 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
13154 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
13156 if (dwarf_read_debug
)
13158 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13159 fprintf_unfiltered (gdb_stdlog
,
13160 " %s CUs, %s TUs\n",
13161 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13162 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13168 /* Wrapper around open_and_init_dwp_file, only open it once. */
13170 static struct dwp_file
*
13171 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
13173 if (!per_objfile
->per_bfd
->dwp_checked
)
13175 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
13176 per_objfile
->per_bfd
->dwp_checked
= 1;
13178 return per_objfile
->per_bfd
->dwp_file
.get ();
13181 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13182 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13183 or in the DWP file for the objfile, referenced by THIS_UNIT.
13184 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13185 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13187 This is called, for example, when wanting to read a variable with a
13188 complex location. Therefore we don't want to do file i/o for every call.
13189 Therefore we don't want to look for a DWO file on every call.
13190 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13191 then we check if we've already seen DWO_NAME, and only THEN do we check
13194 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13195 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13197 static struct dwo_unit
*
13198 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13199 ULONGEST signature
, int is_debug_types
)
13201 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13202 struct objfile
*objfile
= per_objfile
->objfile
;
13203 const char *kind
= is_debug_types
? "TU" : "CU";
13204 void **dwo_file_slot
;
13205 struct dwo_file
*dwo_file
;
13206 struct dwp_file
*dwp_file
;
13208 /* First see if there's a DWP file.
13209 If we have a DWP file but didn't find the DWO inside it, don't
13210 look for the original DWO file. It makes gdb behave differently
13211 depending on whether one is debugging in the build tree. */
13213 dwp_file
= get_dwp_file (per_objfile
);
13214 if (dwp_file
!= NULL
)
13216 const struct dwp_hash_table
*dwp_htab
=
13217 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13219 if (dwp_htab
!= NULL
)
13221 struct dwo_unit
*dwo_cutu
=
13222 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
13225 if (dwo_cutu
!= NULL
)
13227 if (dwarf_read_debug
)
13229 fprintf_unfiltered (gdb_stdlog
,
13230 "Virtual DWO %s %s found: @%s\n",
13231 kind
, hex_string (signature
),
13232 host_address_to_string (dwo_cutu
));
13240 /* No DWP file, look for the DWO file. */
13242 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13243 if (*dwo_file_slot
== NULL
)
13245 /* Read in the file and build a table of the CUs/TUs it contains. */
13246 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13248 /* NOTE: This will be NULL if unable to open the file. */
13249 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13251 if (dwo_file
!= NULL
)
13253 struct dwo_unit
*dwo_cutu
= NULL
;
13255 if (is_debug_types
&& dwo_file
->tus
)
13257 struct dwo_unit find_dwo_cutu
;
13259 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13260 find_dwo_cutu
.signature
= signature
;
13262 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13265 else if (!is_debug_types
&& dwo_file
->cus
)
13267 struct dwo_unit find_dwo_cutu
;
13269 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13270 find_dwo_cutu
.signature
= signature
;
13271 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13275 if (dwo_cutu
!= NULL
)
13277 if (dwarf_read_debug
)
13279 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13280 kind
, dwo_name
, hex_string (signature
),
13281 host_address_to_string (dwo_cutu
));
13288 /* We didn't find it. This could mean a dwo_id mismatch, or
13289 someone deleted the DWO/DWP file, or the search path isn't set up
13290 correctly to find the file. */
13292 if (dwarf_read_debug
)
13294 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13295 kind
, dwo_name
, hex_string (signature
));
13298 /* This is a warning and not a complaint because it can be caused by
13299 pilot error (e.g., user accidentally deleting the DWO). */
13301 /* Print the name of the DWP file if we looked there, helps the user
13302 better diagnose the problem. */
13303 std::string dwp_text
;
13305 if (dwp_file
!= NULL
)
13306 dwp_text
= string_printf (" [in DWP file %s]",
13307 lbasename (dwp_file
->name
));
13309 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13310 " [in module %s]"),
13311 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13312 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13317 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13318 See lookup_dwo_cutu_unit for details. */
13320 static struct dwo_unit
*
13321 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13322 ULONGEST signature
)
13324 gdb_assert (!cu
->per_cu
->is_debug_types
);
13326 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13329 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13330 See lookup_dwo_cutu_unit for details. */
13332 static struct dwo_unit
*
13333 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13335 gdb_assert (cu
->per_cu
->is_debug_types
);
13337 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13339 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13342 /* Traversal function for queue_and_load_all_dwo_tus. */
13345 queue_and_load_dwo_tu (void **slot
, void *info
)
13347 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13348 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13349 ULONGEST signature
= dwo_unit
->signature
;
13350 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13352 if (sig_type
!= NULL
)
13354 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13356 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13357 a real dependency of PER_CU on SIG_TYPE. That is detected later
13358 while processing PER_CU. */
13359 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
13360 load_full_type_unit (sig_cu
, cu
->per_objfile
);
13361 cu
->per_cu
->imported_symtabs_push (sig_cu
);
13367 /* Queue all TUs contained in the DWO of CU to be read in.
13368 The DWO may have the only definition of the type, though it may not be
13369 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13370 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13373 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13375 struct dwo_unit
*dwo_unit
;
13376 struct dwo_file
*dwo_file
;
13378 gdb_assert (cu
!= nullptr);
13379 gdb_assert (!cu
->per_cu
->is_debug_types
);
13380 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13382 dwo_unit
= cu
->dwo_unit
;
13383 gdb_assert (dwo_unit
!= NULL
);
13385 dwo_file
= dwo_unit
->dwo_file
;
13386 if (dwo_file
->tus
!= NULL
)
13387 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13390 /* Read in various DIEs. */
13392 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13393 Inherit only the children of the DW_AT_abstract_origin DIE not being
13394 already referenced by DW_AT_abstract_origin from the children of the
13398 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13400 struct die_info
*child_die
;
13401 sect_offset
*offsetp
;
13402 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13403 struct die_info
*origin_die
;
13404 /* Iterator of the ORIGIN_DIE children. */
13405 struct die_info
*origin_child_die
;
13406 struct attribute
*attr
;
13407 struct dwarf2_cu
*origin_cu
;
13408 struct pending
**origin_previous_list_in_scope
;
13410 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13414 /* Note that following die references may follow to a die in a
13418 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13420 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13422 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13423 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13425 if (die
->tag
!= origin_die
->tag
13426 && !(die
->tag
== DW_TAG_inlined_subroutine
13427 && origin_die
->tag
== DW_TAG_subprogram
))
13428 complaint (_("DIE %s and its abstract origin %s have different tags"),
13429 sect_offset_str (die
->sect_off
),
13430 sect_offset_str (origin_die
->sect_off
));
13432 std::vector
<sect_offset
> offsets
;
13434 for (child_die
= die
->child
;
13435 child_die
&& child_die
->tag
;
13436 child_die
= child_die
->sibling
)
13438 struct die_info
*child_origin_die
;
13439 struct dwarf2_cu
*child_origin_cu
;
13441 /* We are trying to process concrete instance entries:
13442 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13443 it's not relevant to our analysis here. i.e. detecting DIEs that are
13444 present in the abstract instance but not referenced in the concrete
13446 if (child_die
->tag
== DW_TAG_call_site
13447 || child_die
->tag
== DW_TAG_GNU_call_site
)
13450 /* For each CHILD_DIE, find the corresponding child of
13451 ORIGIN_DIE. If there is more than one layer of
13452 DW_AT_abstract_origin, follow them all; there shouldn't be,
13453 but GCC versions at least through 4.4 generate this (GCC PR
13455 child_origin_die
= child_die
;
13456 child_origin_cu
= cu
;
13459 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13463 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13467 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13468 counterpart may exist. */
13469 if (child_origin_die
!= child_die
)
13471 if (child_die
->tag
!= child_origin_die
->tag
13472 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13473 && child_origin_die
->tag
== DW_TAG_subprogram
))
13474 complaint (_("Child DIE %s and its abstract origin %s have "
13476 sect_offset_str (child_die
->sect_off
),
13477 sect_offset_str (child_origin_die
->sect_off
));
13478 if (child_origin_die
->parent
!= origin_die
)
13479 complaint (_("Child DIE %s and its abstract origin %s have "
13480 "different parents"),
13481 sect_offset_str (child_die
->sect_off
),
13482 sect_offset_str (child_origin_die
->sect_off
));
13484 offsets
.push_back (child_origin_die
->sect_off
);
13487 std::sort (offsets
.begin (), offsets
.end ());
13488 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13489 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13490 if (offsetp
[-1] == *offsetp
)
13491 complaint (_("Multiple children of DIE %s refer "
13492 "to DIE %s as their abstract origin"),
13493 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13495 offsetp
= offsets
.data ();
13496 origin_child_die
= origin_die
->child
;
13497 while (origin_child_die
&& origin_child_die
->tag
)
13499 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13500 while (offsetp
< offsets_end
13501 && *offsetp
< origin_child_die
->sect_off
)
13503 if (offsetp
>= offsets_end
13504 || *offsetp
> origin_child_die
->sect_off
)
13506 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13507 Check whether we're already processing ORIGIN_CHILD_DIE.
13508 This can happen with mutually referenced abstract_origins.
13510 if (!origin_child_die
->in_process
)
13511 process_die (origin_child_die
, origin_cu
);
13513 origin_child_die
= origin_child_die
->sibling
;
13515 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13517 if (cu
!= origin_cu
)
13518 compute_delayed_physnames (origin_cu
);
13522 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13524 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13525 struct gdbarch
*gdbarch
= objfile
->arch ();
13526 struct context_stack
*newobj
;
13529 struct die_info
*child_die
;
13530 struct attribute
*attr
, *call_line
, *call_file
;
13532 CORE_ADDR baseaddr
;
13533 struct block
*block
;
13534 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13535 std::vector
<struct symbol
*> template_args
;
13536 struct template_symbol
*templ_func
= NULL
;
13540 /* If we do not have call site information, we can't show the
13541 caller of this inlined function. That's too confusing, so
13542 only use the scope for local variables. */
13543 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13544 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13545 if (call_line
== NULL
|| call_file
== NULL
)
13547 read_lexical_block_scope (die
, cu
);
13552 baseaddr
= objfile
->text_section_offset ();
13554 name
= dwarf2_name (die
, cu
);
13556 /* Ignore functions with missing or empty names. These are actually
13557 illegal according to the DWARF standard. */
13560 complaint (_("missing name for subprogram DIE at %s"),
13561 sect_offset_str (die
->sect_off
));
13565 /* Ignore functions with missing or invalid low and high pc attributes. */
13566 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13567 <= PC_BOUNDS_INVALID
)
13569 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13570 if (!attr
|| !DW_UNSND (attr
))
13571 complaint (_("cannot get low and high bounds "
13572 "for subprogram DIE at %s"),
13573 sect_offset_str (die
->sect_off
));
13577 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13578 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13580 /* If we have any template arguments, then we must allocate a
13581 different sort of symbol. */
13582 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13584 if (child_die
->tag
== DW_TAG_template_type_param
13585 || child_die
->tag
== DW_TAG_template_value_param
)
13587 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13588 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13593 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13594 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13595 (struct symbol
*) templ_func
);
13597 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13598 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13601 /* If there is a location expression for DW_AT_frame_base, record
13603 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13604 if (attr
!= nullptr)
13605 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13607 /* If there is a location for the static link, record it. */
13608 newobj
->static_link
= NULL
;
13609 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13610 if (attr
!= nullptr)
13612 newobj
->static_link
13613 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13614 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13618 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13620 if (die
->child
!= NULL
)
13622 child_die
= die
->child
;
13623 while (child_die
&& child_die
->tag
)
13625 if (child_die
->tag
== DW_TAG_template_type_param
13626 || child_die
->tag
== DW_TAG_template_value_param
)
13628 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13631 template_args
.push_back (arg
);
13634 process_die (child_die
, cu
);
13635 child_die
= child_die
->sibling
;
13639 inherit_abstract_dies (die
, cu
);
13641 /* If we have a DW_AT_specification, we might need to import using
13642 directives from the context of the specification DIE. See the
13643 comment in determine_prefix. */
13644 if (cu
->language
== language_cplus
13645 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13647 struct dwarf2_cu
*spec_cu
= cu
;
13648 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13652 child_die
= spec_die
->child
;
13653 while (child_die
&& child_die
->tag
)
13655 if (child_die
->tag
== DW_TAG_imported_module
)
13656 process_die (child_die
, spec_cu
);
13657 child_die
= child_die
->sibling
;
13660 /* In some cases, GCC generates specification DIEs that
13661 themselves contain DW_AT_specification attributes. */
13662 spec_die
= die_specification (spec_die
, &spec_cu
);
13666 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13667 /* Make a block for the local symbols within. */
13668 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13669 cstk
.static_link
, lowpc
, highpc
);
13671 /* For C++, set the block's scope. */
13672 if ((cu
->language
== language_cplus
13673 || cu
->language
== language_fortran
13674 || cu
->language
== language_d
13675 || cu
->language
== language_rust
)
13676 && cu
->processing_has_namespace_info
)
13677 block_set_scope (block
, determine_prefix (die
, cu
),
13678 &objfile
->objfile_obstack
);
13680 /* If we have address ranges, record them. */
13681 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13683 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13685 /* Attach template arguments to function. */
13686 if (!template_args
.empty ())
13688 gdb_assert (templ_func
!= NULL
);
13690 templ_func
->n_template_arguments
= template_args
.size ();
13691 templ_func
->template_arguments
13692 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13693 templ_func
->n_template_arguments
);
13694 memcpy (templ_func
->template_arguments
,
13695 template_args
.data (),
13696 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13698 /* Make sure that the symtab is set on the new symbols. Even
13699 though they don't appear in this symtab directly, other parts
13700 of gdb assume that symbols do, and this is reasonably
13702 for (symbol
*sym
: template_args
)
13703 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13706 /* In C++, we can have functions nested inside functions (e.g., when
13707 a function declares a class that has methods). This means that
13708 when we finish processing a function scope, we may need to go
13709 back to building a containing block's symbol lists. */
13710 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13711 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13713 /* If we've finished processing a top-level function, subsequent
13714 symbols go in the file symbol list. */
13715 if (cu
->get_builder ()->outermost_context_p ())
13716 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13719 /* Process all the DIES contained within a lexical block scope. Start
13720 a new scope, process the dies, and then close the scope. */
13723 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13725 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13726 struct gdbarch
*gdbarch
= objfile
->arch ();
13727 CORE_ADDR lowpc
, highpc
;
13728 struct die_info
*child_die
;
13729 CORE_ADDR baseaddr
;
13731 baseaddr
= objfile
->text_section_offset ();
13733 /* Ignore blocks with missing or invalid low and high pc attributes. */
13734 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13735 as multiple lexical blocks? Handling children in a sane way would
13736 be nasty. Might be easier to properly extend generic blocks to
13737 describe ranges. */
13738 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13740 case PC_BOUNDS_NOT_PRESENT
:
13741 /* DW_TAG_lexical_block has no attributes, process its children as if
13742 there was no wrapping by that DW_TAG_lexical_block.
13743 GCC does no longer produces such DWARF since GCC r224161. */
13744 for (child_die
= die
->child
;
13745 child_die
!= NULL
&& child_die
->tag
;
13746 child_die
= child_die
->sibling
)
13748 /* We might already be processing this DIE. This can happen
13749 in an unusual circumstance -- where a subroutine A
13750 appears lexically in another subroutine B, but A actually
13751 inlines B. The recursion is broken here, rather than in
13752 inherit_abstract_dies, because it seems better to simply
13753 drop concrete children here. */
13754 if (!child_die
->in_process
)
13755 process_die (child_die
, cu
);
13758 case PC_BOUNDS_INVALID
:
13761 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13762 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13764 cu
->get_builder ()->push_context (0, lowpc
);
13765 if (die
->child
!= NULL
)
13767 child_die
= die
->child
;
13768 while (child_die
&& child_die
->tag
)
13770 process_die (child_die
, cu
);
13771 child_die
= child_die
->sibling
;
13774 inherit_abstract_dies (die
, cu
);
13775 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13777 if (*cu
->get_builder ()->get_local_symbols () != NULL
13778 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13780 struct block
*block
13781 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13782 cstk
.start_addr
, highpc
);
13784 /* Note that recording ranges after traversing children, as we
13785 do here, means that recording a parent's ranges entails
13786 walking across all its children's ranges as they appear in
13787 the address map, which is quadratic behavior.
13789 It would be nicer to record the parent's ranges before
13790 traversing its children, simply overriding whatever you find
13791 there. But since we don't even decide whether to create a
13792 block until after we've traversed its children, that's hard
13794 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13796 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13797 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13800 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13803 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13805 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13806 struct objfile
*objfile
= per_objfile
->objfile
;
13807 struct gdbarch
*gdbarch
= objfile
->arch ();
13808 CORE_ADDR pc
, baseaddr
;
13809 struct attribute
*attr
;
13810 struct call_site
*call_site
, call_site_local
;
13813 struct die_info
*child_die
;
13815 baseaddr
= objfile
->text_section_offset ();
13817 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13820 /* This was a pre-DWARF-5 GNU extension alias
13821 for DW_AT_call_return_pc. */
13822 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13826 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13827 "DIE %s [in module %s]"),
13828 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13831 pc
= attr
->as_address () + baseaddr
;
13832 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13834 if (cu
->call_site_htab
== NULL
)
13835 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13836 NULL
, &objfile
->objfile_obstack
,
13837 hashtab_obstack_allocate
, NULL
);
13838 call_site_local
.pc
= pc
;
13839 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13842 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13843 "DIE %s [in module %s]"),
13844 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13845 objfile_name (objfile
));
13849 /* Count parameters at the caller. */
13852 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13853 child_die
= child_die
->sibling
)
13855 if (child_die
->tag
!= DW_TAG_call_site_parameter
13856 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13858 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13859 "DW_TAG_call_site child DIE %s [in module %s]"),
13860 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13861 objfile_name (objfile
));
13869 = ((struct call_site
*)
13870 obstack_alloc (&objfile
->objfile_obstack
,
13871 sizeof (*call_site
)
13872 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13874 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13875 call_site
->pc
= pc
;
13877 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13878 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13880 struct die_info
*func_die
;
13882 /* Skip also over DW_TAG_inlined_subroutine. */
13883 for (func_die
= die
->parent
;
13884 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13885 && func_die
->tag
!= DW_TAG_subroutine_type
;
13886 func_die
= func_die
->parent
);
13888 /* DW_AT_call_all_calls is a superset
13889 of DW_AT_call_all_tail_calls. */
13891 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13892 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13893 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13894 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13896 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13897 not complete. But keep CALL_SITE for look ups via call_site_htab,
13898 both the initial caller containing the real return address PC and
13899 the final callee containing the current PC of a chain of tail
13900 calls do not need to have the tail call list complete. But any
13901 function candidate for a virtual tail call frame searched via
13902 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13903 determined unambiguously. */
13907 struct type
*func_type
= NULL
;
13910 func_type
= get_die_type (func_die
, cu
);
13911 if (func_type
!= NULL
)
13913 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13915 /* Enlist this call site to the function. */
13916 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13917 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13920 complaint (_("Cannot find function owning DW_TAG_call_site "
13921 "DIE %s [in module %s]"),
13922 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13926 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13928 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13930 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13933 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13934 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13936 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13937 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13938 /* Keep NULL DWARF_BLOCK. */;
13939 else if (attr
->form_is_block ())
13941 struct dwarf2_locexpr_baton
*dlbaton
;
13942 struct dwarf_block
*block
= attr
->as_block ();
13944 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13945 dlbaton
->data
= block
->data
;
13946 dlbaton
->size
= block
->size
;
13947 dlbaton
->per_objfile
= per_objfile
;
13948 dlbaton
->per_cu
= cu
->per_cu
;
13950 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13952 else if (attr
->form_is_ref ())
13954 struct dwarf2_cu
*target_cu
= cu
;
13955 struct die_info
*target_die
;
13957 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13958 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13959 if (die_is_declaration (target_die
, target_cu
))
13961 const char *target_physname
;
13963 /* Prefer the mangled name; otherwise compute the demangled one. */
13964 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13965 if (target_physname
== NULL
)
13966 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13967 if (target_physname
== NULL
)
13968 complaint (_("DW_AT_call_target target DIE has invalid "
13969 "physname, for referencing DIE %s [in module %s]"),
13970 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13972 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13978 /* DW_AT_entry_pc should be preferred. */
13979 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13980 <= PC_BOUNDS_INVALID
)
13981 complaint (_("DW_AT_call_target target DIE has invalid "
13982 "low pc, for referencing DIE %s [in module %s]"),
13983 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13986 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13987 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13992 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13993 "block nor reference, for DIE %s [in module %s]"),
13994 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13996 call_site
->per_cu
= cu
->per_cu
;
13997 call_site
->per_objfile
= per_objfile
;
13999 for (child_die
= die
->child
;
14000 child_die
&& child_die
->tag
;
14001 child_die
= child_die
->sibling
)
14003 struct call_site_parameter
*parameter
;
14004 struct attribute
*loc
, *origin
;
14006 if (child_die
->tag
!= DW_TAG_call_site_parameter
14007 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14009 /* Already printed the complaint above. */
14013 gdb_assert (call_site
->parameter_count
< nparams
);
14014 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14016 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14017 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14018 register is contained in DW_AT_call_value. */
14020 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14021 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14022 if (origin
== NULL
)
14024 /* This was a pre-DWARF-5 GNU extension alias
14025 for DW_AT_call_parameter. */
14026 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14028 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
14030 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14032 sect_offset sect_off
= origin
->get_ref_die_offset ();
14033 if (!cu
->header
.offset_in_cu_p (sect_off
))
14035 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14036 binding can be done only inside one CU. Such referenced DIE
14037 therefore cannot be even moved to DW_TAG_partial_unit. */
14038 complaint (_("DW_AT_call_parameter offset is not in CU for "
14039 "DW_TAG_call_site child DIE %s [in module %s]"),
14040 sect_offset_str (child_die
->sect_off
),
14041 objfile_name (objfile
));
14044 parameter
->u
.param_cu_off
14045 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14047 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
14049 complaint (_("No DW_FORM_block* DW_AT_location for "
14050 "DW_TAG_call_site child DIE %s [in module %s]"),
14051 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14056 struct dwarf_block
*block
= loc
->as_block ();
14058 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14059 (block
->data
, &block
->data
[block
->size
]);
14060 if (parameter
->u
.dwarf_reg
!= -1)
14061 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14062 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
14063 &block
->data
[block
->size
],
14064 ¶meter
->u
.fb_offset
))
14065 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14068 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14069 "for DW_FORM_block* DW_AT_location is supported for "
14070 "DW_TAG_call_site child DIE %s "
14072 sect_offset_str (child_die
->sect_off
),
14073 objfile_name (objfile
));
14078 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14080 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14081 if (attr
== NULL
|| !attr
->form_is_block ())
14083 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14084 "DW_TAG_call_site child DIE %s [in module %s]"),
14085 sect_offset_str (child_die
->sect_off
),
14086 objfile_name (objfile
));
14090 struct dwarf_block
*block
= attr
->as_block ();
14091 parameter
->value
= block
->data
;
14092 parameter
->value_size
= block
->size
;
14094 /* Parameters are not pre-cleared by memset above. */
14095 parameter
->data_value
= NULL
;
14096 parameter
->data_value_size
= 0;
14097 call_site
->parameter_count
++;
14099 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14101 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14102 if (attr
!= nullptr)
14104 if (!attr
->form_is_block ())
14105 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14106 "DW_TAG_call_site child DIE %s [in module %s]"),
14107 sect_offset_str (child_die
->sect_off
),
14108 objfile_name (objfile
));
14111 block
= attr
->as_block ();
14112 parameter
->data_value
= block
->data
;
14113 parameter
->data_value_size
= block
->size
;
14119 /* Helper function for read_variable. If DIE represents a virtual
14120 table, then return the type of the concrete object that is
14121 associated with the virtual table. Otherwise, return NULL. */
14123 static struct type
*
14124 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14126 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14130 /* Find the type DIE. */
14131 struct die_info
*type_die
= NULL
;
14132 struct dwarf2_cu
*type_cu
= cu
;
14134 if (attr
->form_is_ref ())
14135 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14136 if (type_die
== NULL
)
14139 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14141 return die_containing_type (type_die
, type_cu
);
14144 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14147 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14149 struct rust_vtable_symbol
*storage
= NULL
;
14151 if (cu
->language
== language_rust
)
14153 struct type
*containing_type
= rust_containing_type (die
, cu
);
14155 if (containing_type
!= NULL
)
14157 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14159 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
14160 storage
->concrete_type
= containing_type
;
14161 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14165 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14166 struct attribute
*abstract_origin
14167 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14168 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14169 if (res
== NULL
&& loc
&& abstract_origin
)
14171 /* We have a variable without a name, but with a location and an abstract
14172 origin. This may be a concrete instance of an abstract variable
14173 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14175 struct dwarf2_cu
*origin_cu
= cu
;
14176 struct die_info
*origin_die
14177 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14178 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14179 per_objfile
->per_bfd
->abstract_to_concrete
14180 [origin_die
->sect_off
].push_back (die
->sect_off
);
14184 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14185 reading .debug_rnglists.
14186 Callback's type should be:
14187 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14188 Return true if the attributes are present and valid, otherwise,
14191 template <typename Callback
>
14193 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14194 dwarf_tag tag
, Callback
&&callback
)
14196 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14197 struct objfile
*objfile
= per_objfile
->objfile
;
14198 bfd
*obfd
= objfile
->obfd
;
14199 /* Base address selection entry. */
14200 gdb::optional
<CORE_ADDR
> base
;
14201 const gdb_byte
*buffer
;
14202 CORE_ADDR baseaddr
;
14203 bool overflow
= false;
14204 ULONGEST addr_index
;
14205 struct dwarf2_section_info
*rnglists_section
;
14207 base
= cu
->base_address
;
14208 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14209 rnglists_section
->read (objfile
);
14211 if (offset
>= rnglists_section
->size
)
14213 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14217 buffer
= rnglists_section
->buffer
+ offset
;
14219 baseaddr
= objfile
->text_section_offset ();
14223 /* Initialize it due to a false compiler warning. */
14224 CORE_ADDR range_beginning
= 0, range_end
= 0;
14225 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14226 + rnglists_section
->size
);
14227 unsigned int bytes_read
;
14229 if (buffer
== buf_end
)
14234 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14237 case DW_RLE_end_of_list
:
14239 case DW_RLE_base_address
:
14240 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14245 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14246 buffer
+= bytes_read
;
14248 case DW_RLE_base_addressx
:
14249 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14250 buffer
+= bytes_read
;
14251 base
= read_addr_index (cu
, addr_index
);
14253 case DW_RLE_start_length
:
14254 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14259 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14261 buffer
+= bytes_read
;
14262 range_end
= (range_beginning
14263 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14264 buffer
+= bytes_read
;
14265 if (buffer
> buf_end
)
14271 case DW_RLE_startx_length
:
14272 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14273 buffer
+= bytes_read
;
14274 range_beginning
= read_addr_index (cu
, addr_index
);
14275 if (buffer
> buf_end
)
14280 range_end
= (range_beginning
14281 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14282 buffer
+= bytes_read
;
14284 case DW_RLE_offset_pair
:
14285 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14286 buffer
+= bytes_read
;
14287 if (buffer
> buf_end
)
14292 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14293 buffer
+= bytes_read
;
14294 if (buffer
> buf_end
)
14300 case DW_RLE_start_end
:
14301 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14306 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14308 buffer
+= bytes_read
;
14309 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14310 buffer
+= bytes_read
;
14312 case DW_RLE_startx_endx
:
14313 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14314 buffer
+= bytes_read
;
14315 range_beginning
= read_addr_index (cu
, addr_index
);
14316 if (buffer
> buf_end
)
14321 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14322 buffer
+= bytes_read
;
14323 range_end
= read_addr_index (cu
, addr_index
);
14326 complaint (_("Invalid .debug_rnglists data (no base address)"));
14329 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14331 if (rlet
== DW_RLE_base_address
)
14334 if (range_beginning
> range_end
)
14336 /* Inverted range entries are invalid. */
14337 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14341 /* Empty range entries have no effect. */
14342 if (range_beginning
== range_end
)
14345 /* Only DW_RLE_offset_pair needs the base address added. */
14346 if (rlet
== DW_RLE_offset_pair
)
14348 if (!base
.has_value ())
14350 /* We have no valid base address for the DW_RLE_offset_pair. */
14351 complaint (_("Invalid .debug_rnglists data (no base address for "
14352 "DW_RLE_offset_pair)"));
14356 range_beginning
+= *base
;
14357 range_end
+= *base
;
14360 /* A not-uncommon case of bad debug info.
14361 Don't pollute the addrmap with bad data. */
14362 if (range_beginning
+ baseaddr
== 0
14363 && !per_objfile
->per_bfd
->has_section_at_zero
)
14365 complaint (_(".debug_rnglists entry has start address of zero"
14366 " [in module %s]"), objfile_name (objfile
));
14370 callback (range_beginning
, range_end
);
14375 complaint (_("Offset %d is not terminated "
14376 "for DW_AT_ranges attribute"),
14384 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14385 Callback's type should be:
14386 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14387 Return 1 if the attributes are present and valid, otherwise, return 0. */
14389 template <typename Callback
>
14391 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14392 Callback
&&callback
)
14394 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14395 struct objfile
*objfile
= per_objfile
->objfile
;
14396 struct comp_unit_head
*cu_header
= &cu
->header
;
14397 bfd
*obfd
= objfile
->obfd
;
14398 unsigned int addr_size
= cu_header
->addr_size
;
14399 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14400 /* Base address selection entry. */
14401 gdb::optional
<CORE_ADDR
> base
;
14402 unsigned int dummy
;
14403 const gdb_byte
*buffer
;
14404 CORE_ADDR baseaddr
;
14406 if (cu_header
->version
>= 5)
14407 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14409 base
= cu
->base_address
;
14411 per_objfile
->per_bfd
->ranges
.read (objfile
);
14412 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14414 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14418 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14420 baseaddr
= objfile
->text_section_offset ();
14424 CORE_ADDR range_beginning
, range_end
;
14426 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14427 buffer
+= addr_size
;
14428 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14429 buffer
+= addr_size
;
14430 offset
+= 2 * addr_size
;
14432 /* An end of list marker is a pair of zero addresses. */
14433 if (range_beginning
== 0 && range_end
== 0)
14434 /* Found the end of list entry. */
14437 /* Each base address selection entry is a pair of 2 values.
14438 The first is the largest possible address, the second is
14439 the base address. Check for a base address here. */
14440 if ((range_beginning
& mask
) == mask
)
14442 /* If we found the largest possible address, then we already
14443 have the base address in range_end. */
14448 if (!base
.has_value ())
14450 /* We have no valid base address for the ranges
14452 complaint (_("Invalid .debug_ranges data (no base address)"));
14456 if (range_beginning
> range_end
)
14458 /* Inverted range entries are invalid. */
14459 complaint (_("Invalid .debug_ranges data (inverted range)"));
14463 /* Empty range entries have no effect. */
14464 if (range_beginning
== range_end
)
14467 range_beginning
+= *base
;
14468 range_end
+= *base
;
14470 /* A not-uncommon case of bad debug info.
14471 Don't pollute the addrmap with bad data. */
14472 if (range_beginning
+ baseaddr
== 0
14473 && !per_objfile
->per_bfd
->has_section_at_zero
)
14475 complaint (_(".debug_ranges entry has start address of zero"
14476 " [in module %s]"), objfile_name (objfile
));
14480 callback (range_beginning
, range_end
);
14486 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14487 Return 1 if the attributes are present and valid, otherwise, return 0.
14488 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14491 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14492 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14493 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14495 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14496 struct gdbarch
*gdbarch
= objfile
->arch ();
14497 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14500 CORE_ADDR high
= 0;
14503 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14504 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14506 if (ranges_pst
!= NULL
)
14511 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14512 range_beginning
+ baseaddr
)
14514 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14515 range_end
+ baseaddr
)
14517 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14518 lowpc
, highpc
- 1, ranges_pst
);
14521 /* FIXME: This is recording everything as a low-high
14522 segment of consecutive addresses. We should have a
14523 data structure for discontiguous block ranges
14527 low
= range_beginning
;
14533 if (range_beginning
< low
)
14534 low
= range_beginning
;
14535 if (range_end
> high
)
14543 /* If the first entry is an end-of-list marker, the range
14544 describes an empty scope, i.e. no instructions. */
14550 *high_return
= high
;
14554 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14555 definition for the return value. *LOWPC and *HIGHPC are set iff
14556 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14558 static enum pc_bounds_kind
14559 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14560 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14561 dwarf2_psymtab
*pst
)
14563 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14564 struct attribute
*attr
;
14565 struct attribute
*attr_high
;
14567 CORE_ADDR high
= 0;
14568 enum pc_bounds_kind ret
;
14570 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14573 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14574 if (attr
!= nullptr)
14576 low
= attr
->as_address ();
14577 high
= attr_high
->as_address ();
14578 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14582 /* Found high w/o low attribute. */
14583 return PC_BOUNDS_INVALID
;
14585 /* Found consecutive range of addresses. */
14586 ret
= PC_BOUNDS_HIGH_LOW
;
14590 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14593 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14594 We take advantage of the fact that DW_AT_ranges does not appear
14595 in DW_TAG_compile_unit of DWO files.
14597 Attributes of the form DW_FORM_rnglistx have already had their
14598 value changed by read_rnglist_index and already include
14599 DW_AT_rnglists_base, so don't need to add the ranges base,
14601 int need_ranges_base
= (die
->tag
!= DW_TAG_compile_unit
14602 && attr
->form
!= DW_FORM_rnglistx
);
14603 unsigned int ranges_offset
= (DW_UNSND (attr
)
14604 + (need_ranges_base
14608 /* Value of the DW_AT_ranges attribute is the offset in the
14609 .debug_ranges section. */
14610 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14612 return PC_BOUNDS_INVALID
;
14613 /* Found discontinuous range of addresses. */
14614 ret
= PC_BOUNDS_RANGES
;
14617 return PC_BOUNDS_NOT_PRESENT
;
14620 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14622 return PC_BOUNDS_INVALID
;
14624 /* When using the GNU linker, .gnu.linkonce. sections are used to
14625 eliminate duplicate copies of functions and vtables and such.
14626 The linker will arbitrarily choose one and discard the others.
14627 The AT_*_pc values for such functions refer to local labels in
14628 these sections. If the section from that file was discarded, the
14629 labels are not in the output, so the relocs get a value of 0.
14630 If this is a discarded function, mark the pc bounds as invalid,
14631 so that GDB will ignore it. */
14632 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14633 return PC_BOUNDS_INVALID
;
14641 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14642 its low and high PC addresses. Do nothing if these addresses could not
14643 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14644 and HIGHPC to the high address if greater than HIGHPC. */
14647 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14648 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14649 struct dwarf2_cu
*cu
)
14651 CORE_ADDR low
, high
;
14652 struct die_info
*child
= die
->child
;
14654 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14656 *lowpc
= std::min (*lowpc
, low
);
14657 *highpc
= std::max (*highpc
, high
);
14660 /* If the language does not allow nested subprograms (either inside
14661 subprograms or lexical blocks), we're done. */
14662 if (cu
->language
!= language_ada
)
14665 /* Check all the children of the given DIE. If it contains nested
14666 subprograms, then check their pc bounds. Likewise, we need to
14667 check lexical blocks as well, as they may also contain subprogram
14669 while (child
&& child
->tag
)
14671 if (child
->tag
== DW_TAG_subprogram
14672 || child
->tag
== DW_TAG_lexical_block
)
14673 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14674 child
= child
->sibling
;
14678 /* Get the low and high pc's represented by the scope DIE, and store
14679 them in *LOWPC and *HIGHPC. If the correct values can't be
14680 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14683 get_scope_pc_bounds (struct die_info
*die
,
14684 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14685 struct dwarf2_cu
*cu
)
14687 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14688 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14689 CORE_ADDR current_low
, current_high
;
14691 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14692 >= PC_BOUNDS_RANGES
)
14694 best_low
= current_low
;
14695 best_high
= current_high
;
14699 struct die_info
*child
= die
->child
;
14701 while (child
&& child
->tag
)
14703 switch (child
->tag
) {
14704 case DW_TAG_subprogram
:
14705 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14707 case DW_TAG_namespace
:
14708 case DW_TAG_module
:
14709 /* FIXME: carlton/2004-01-16: Should we do this for
14710 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14711 that current GCC's always emit the DIEs corresponding
14712 to definitions of methods of classes as children of a
14713 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14714 the DIEs giving the declarations, which could be
14715 anywhere). But I don't see any reason why the
14716 standards says that they have to be there. */
14717 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14719 if (current_low
!= ((CORE_ADDR
) -1))
14721 best_low
= std::min (best_low
, current_low
);
14722 best_high
= std::max (best_high
, current_high
);
14730 child
= child
->sibling
;
14735 *highpc
= best_high
;
14738 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14742 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14743 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14745 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14746 struct gdbarch
*gdbarch
= objfile
->arch ();
14747 struct attribute
*attr
;
14748 struct attribute
*attr_high
;
14750 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14753 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14754 if (attr
!= nullptr)
14756 CORE_ADDR low
= attr
->as_address ();
14757 CORE_ADDR high
= attr_high
->as_address ();
14759 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14762 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14763 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14764 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14768 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14769 if (attr
!= nullptr)
14771 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14772 We take advantage of the fact that DW_AT_ranges does not appear
14773 in DW_TAG_compile_unit of DWO files.
14775 Attributes of the form DW_FORM_rnglistx have already had their
14776 value changed by read_rnglist_index and already include
14777 DW_AT_rnglists_base, so don't need to add the ranges base,
14779 int need_ranges_base
= (die
->tag
!= DW_TAG_compile_unit
14780 && attr
->form
!= DW_FORM_rnglistx
);
14782 /* The value of the DW_AT_ranges attribute is the offset of the
14783 address range list in the .debug_ranges section. */
14784 unsigned long offset
= (DW_UNSND (attr
)
14785 + (need_ranges_base
? cu
->ranges_base
: 0));
14787 std::vector
<blockrange
> blockvec
;
14788 dwarf2_ranges_process (offset
, cu
, die
->tag
,
14789 [&] (CORE_ADDR start
, CORE_ADDR end
)
14793 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14794 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14795 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14796 blockvec
.emplace_back (start
, end
);
14799 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14803 /* Check whether the producer field indicates either of GCC < 4.6, or the
14804 Intel C/C++ compiler, and cache the result in CU. */
14807 check_producer (struct dwarf2_cu
*cu
)
14811 if (cu
->producer
== NULL
)
14813 /* For unknown compilers expect their behavior is DWARF version
14816 GCC started to support .debug_types sections by -gdwarf-4 since
14817 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14818 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14819 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14820 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14822 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14824 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14825 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14827 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14829 cu
->producer_is_icc
= true;
14830 cu
->producer_is_icc_lt_14
= major
< 14;
14832 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14833 cu
->producer_is_codewarrior
= true;
14836 /* For other non-GCC compilers, expect their behavior is DWARF version
14840 cu
->checked_producer
= true;
14843 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14844 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14845 during 4.6.0 experimental. */
14848 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14850 if (!cu
->checked_producer
)
14851 check_producer (cu
);
14853 return cu
->producer_is_gxx_lt_4_6
;
14857 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14858 with incorrect is_stmt attributes. */
14861 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14863 if (!cu
->checked_producer
)
14864 check_producer (cu
);
14866 return cu
->producer_is_codewarrior
;
14869 /* Return the default accessibility type if it is not overridden by
14870 DW_AT_accessibility. */
14872 static enum dwarf_access_attribute
14873 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14875 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14877 /* The default DWARF 2 accessibility for members is public, the default
14878 accessibility for inheritance is private. */
14880 if (die
->tag
!= DW_TAG_inheritance
)
14881 return DW_ACCESS_public
;
14883 return DW_ACCESS_private
;
14887 /* DWARF 3+ defines the default accessibility a different way. The same
14888 rules apply now for DW_TAG_inheritance as for the members and it only
14889 depends on the container kind. */
14891 if (die
->parent
->tag
== DW_TAG_class_type
)
14892 return DW_ACCESS_private
;
14894 return DW_ACCESS_public
;
14898 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14899 offset. If the attribute was not found return 0, otherwise return
14900 1. If it was found but could not properly be handled, set *OFFSET
14904 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14907 struct attribute
*attr
;
14909 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14914 /* Note that we do not check for a section offset first here.
14915 This is because DW_AT_data_member_location is new in DWARF 4,
14916 so if we see it, we can assume that a constant form is really
14917 a constant and not a section offset. */
14918 if (attr
->form_is_constant ())
14919 *offset
= attr
->constant_value (0);
14920 else if (attr
->form_is_section_offset ())
14921 dwarf2_complex_location_expr_complaint ();
14922 else if (attr
->form_is_block ())
14923 *offset
= decode_locdesc (attr
->as_block (), cu
);
14925 dwarf2_complex_location_expr_complaint ();
14933 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14936 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14937 struct field
*field
)
14939 struct attribute
*attr
;
14941 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14944 if (attr
->form_is_constant ())
14946 LONGEST offset
= attr
->constant_value (0);
14947 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14949 else if (attr
->form_is_section_offset ())
14950 dwarf2_complex_location_expr_complaint ();
14951 else if (attr
->form_is_block ())
14954 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14956 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14959 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14960 struct objfile
*objfile
= per_objfile
->objfile
;
14961 struct dwarf2_locexpr_baton
*dlbaton
14962 = XOBNEW (&objfile
->objfile_obstack
,
14963 struct dwarf2_locexpr_baton
);
14964 dlbaton
->data
= attr
->as_block ()->data
;
14965 dlbaton
->size
= attr
->as_block ()->size
;
14966 /* When using this baton, we want to compute the address
14967 of the field, not the value. This is why
14968 is_reference is set to false here. */
14969 dlbaton
->is_reference
= false;
14970 dlbaton
->per_objfile
= per_objfile
;
14971 dlbaton
->per_cu
= cu
->per_cu
;
14973 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14977 dwarf2_complex_location_expr_complaint ();
14981 /* Add an aggregate field to the field list. */
14984 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14985 struct dwarf2_cu
*cu
)
14987 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14988 struct gdbarch
*gdbarch
= objfile
->arch ();
14989 struct nextfield
*new_field
;
14990 struct attribute
*attr
;
14992 const char *fieldname
= "";
14994 if (die
->tag
== DW_TAG_inheritance
)
14996 fip
->baseclasses
.emplace_back ();
14997 new_field
= &fip
->baseclasses
.back ();
15001 fip
->fields
.emplace_back ();
15002 new_field
= &fip
->fields
.back ();
15005 new_field
->offset
= die
->sect_off
;
15007 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15008 if (attr
!= nullptr)
15009 new_field
->accessibility
= DW_UNSND (attr
);
15011 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15012 if (new_field
->accessibility
!= DW_ACCESS_public
)
15013 fip
->non_public_fields
= true;
15015 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15016 if (attr
!= nullptr)
15017 new_field
->virtuality
= DW_UNSND (attr
);
15019 new_field
->virtuality
= DW_VIRTUALITY_none
;
15021 fp
= &new_field
->field
;
15023 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15025 /* Data member other than a C++ static data member. */
15027 /* Get type of field. */
15028 fp
->set_type (die_type (die
, cu
));
15030 SET_FIELD_BITPOS (*fp
, 0);
15032 /* Get bit size of field (zero if none). */
15033 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15034 if (attr
!= nullptr)
15036 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15040 FIELD_BITSIZE (*fp
) = 0;
15043 /* Get bit offset of field. */
15044 handle_data_member_location (die
, cu
, fp
);
15045 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15046 if (attr
!= nullptr)
15048 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15050 /* For big endian bits, the DW_AT_bit_offset gives the
15051 additional bit offset from the MSB of the containing
15052 anonymous object to the MSB of the field. We don't
15053 have to do anything special since we don't need to
15054 know the size of the anonymous object. */
15055 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15059 /* For little endian bits, compute the bit offset to the
15060 MSB of the anonymous object, subtract off the number of
15061 bits from the MSB of the field to the MSB of the
15062 object, and then subtract off the number of bits of
15063 the field itself. The result is the bit offset of
15064 the LSB of the field. */
15065 int anonymous_size
;
15066 int bit_offset
= DW_UNSND (attr
);
15068 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15069 if (attr
!= nullptr)
15071 /* The size of the anonymous object containing
15072 the bit field is explicit, so use the
15073 indicated size (in bytes). */
15074 anonymous_size
= DW_UNSND (attr
);
15078 /* The size of the anonymous object containing
15079 the bit field must be inferred from the type
15080 attribute of the data member containing the
15082 anonymous_size
= TYPE_LENGTH (fp
->type ());
15084 SET_FIELD_BITPOS (*fp
,
15085 (FIELD_BITPOS (*fp
)
15086 + anonymous_size
* bits_per_byte
15087 - bit_offset
- FIELD_BITSIZE (*fp
)));
15090 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15092 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15093 + attr
->constant_value (0)));
15095 /* Get name of field. */
15096 fieldname
= dwarf2_name (die
, cu
);
15097 if (fieldname
== NULL
)
15100 /* The name is already allocated along with this objfile, so we don't
15101 need to duplicate it for the type. */
15102 fp
->name
= fieldname
;
15104 /* Change accessibility for artificial fields (e.g. virtual table
15105 pointer or virtual base class pointer) to private. */
15106 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15108 FIELD_ARTIFICIAL (*fp
) = 1;
15109 new_field
->accessibility
= DW_ACCESS_private
;
15110 fip
->non_public_fields
= true;
15113 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15115 /* C++ static member. */
15117 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15118 is a declaration, but all versions of G++ as of this writing
15119 (so through at least 3.2.1) incorrectly generate
15120 DW_TAG_variable tags. */
15122 const char *physname
;
15124 /* Get name of field. */
15125 fieldname
= dwarf2_name (die
, cu
);
15126 if (fieldname
== NULL
)
15129 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15131 /* Only create a symbol if this is an external value.
15132 new_symbol checks this and puts the value in the global symbol
15133 table, which we want. If it is not external, new_symbol
15134 will try to put the value in cu->list_in_scope which is wrong. */
15135 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15137 /* A static const member, not much different than an enum as far as
15138 we're concerned, except that we can support more types. */
15139 new_symbol (die
, NULL
, cu
);
15142 /* Get physical name. */
15143 physname
= dwarf2_physname (fieldname
, die
, cu
);
15145 /* The name is already allocated along with this objfile, so we don't
15146 need to duplicate it for the type. */
15147 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15148 fp
->set_type (die_type (die
, cu
));
15149 FIELD_NAME (*fp
) = fieldname
;
15151 else if (die
->tag
== DW_TAG_inheritance
)
15153 /* C++ base class field. */
15154 handle_data_member_location (die
, cu
, fp
);
15155 FIELD_BITSIZE (*fp
) = 0;
15156 fp
->set_type (die_type (die
, cu
));
15157 FIELD_NAME (*fp
) = fp
->type ()->name ();
15160 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15163 /* Can the type given by DIE define another type? */
15166 type_can_define_types (const struct die_info
*die
)
15170 case DW_TAG_typedef
:
15171 case DW_TAG_class_type
:
15172 case DW_TAG_structure_type
:
15173 case DW_TAG_union_type
:
15174 case DW_TAG_enumeration_type
:
15182 /* Add a type definition defined in the scope of the FIP's class. */
15185 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15186 struct dwarf2_cu
*cu
)
15188 struct decl_field fp
;
15189 memset (&fp
, 0, sizeof (fp
));
15191 gdb_assert (type_can_define_types (die
));
15193 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15194 fp
.name
= dwarf2_name (die
, cu
);
15195 fp
.type
= read_type_die (die
, cu
);
15197 /* Save accessibility. */
15198 enum dwarf_access_attribute accessibility
;
15199 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15201 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15203 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15204 switch (accessibility
)
15206 case DW_ACCESS_public
:
15207 /* The assumed value if neither private nor protected. */
15209 case DW_ACCESS_private
:
15212 case DW_ACCESS_protected
:
15213 fp
.is_protected
= 1;
15216 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15219 if (die
->tag
== DW_TAG_typedef
)
15220 fip
->typedef_field_list
.push_back (fp
);
15222 fip
->nested_types_list
.push_back (fp
);
15225 /* A convenience typedef that's used when finding the discriminant
15226 field for a variant part. */
15227 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15230 /* Compute the discriminant range for a given variant. OBSTACK is
15231 where the results will be stored. VARIANT is the variant to
15232 process. IS_UNSIGNED indicates whether the discriminant is signed
15235 static const gdb::array_view
<discriminant_range
>
15236 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15239 std::vector
<discriminant_range
> ranges
;
15241 if (variant
.default_branch
)
15244 if (variant
.discr_list_data
== nullptr)
15246 discriminant_range r
15247 = {variant
.discriminant_value
, variant
.discriminant_value
};
15248 ranges
.push_back (r
);
15252 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15253 variant
.discr_list_data
->size
);
15254 while (!data
.empty ())
15256 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15258 complaint (_("invalid discriminant marker: %d"), data
[0]);
15261 bool is_range
= data
[0] == DW_DSC_range
;
15262 data
= data
.slice (1);
15264 ULONGEST low
, high
;
15265 unsigned int bytes_read
;
15269 complaint (_("DW_AT_discr_list missing low value"));
15273 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15275 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15277 data
= data
.slice (bytes_read
);
15283 complaint (_("DW_AT_discr_list missing high value"));
15287 high
= read_unsigned_leb128 (nullptr, data
.data (),
15290 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15292 data
= data
.slice (bytes_read
);
15297 ranges
.push_back ({ low
, high
});
15301 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15303 std::copy (ranges
.begin (), ranges
.end (), result
);
15304 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15307 static const gdb::array_view
<variant_part
> create_variant_parts
15308 (struct obstack
*obstack
,
15309 const offset_map_type
&offset_map
,
15310 struct field_info
*fi
,
15311 const std::vector
<variant_part_builder
> &variant_parts
);
15313 /* Fill in a "struct variant" for a given variant field. RESULT is
15314 the variant to fill in. OBSTACK is where any needed allocations
15315 will be done. OFFSET_MAP holds the mapping from section offsets to
15316 fields for the type. FI describes the fields of the type we're
15317 processing. FIELD is the variant field we're converting. */
15320 create_one_variant (variant
&result
, struct obstack
*obstack
,
15321 const offset_map_type
&offset_map
,
15322 struct field_info
*fi
, const variant_field
&field
)
15324 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15325 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15326 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15327 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15328 field
.variant_parts
);
15331 /* Fill in a "struct variant_part" for a given variant part. RESULT
15332 is the variant part to fill in. OBSTACK is where any needed
15333 allocations will be done. OFFSET_MAP holds the mapping from
15334 section offsets to fields for the type. FI describes the fields of
15335 the type we're processing. BUILDER is the variant part to be
15339 create_one_variant_part (variant_part
&result
,
15340 struct obstack
*obstack
,
15341 const offset_map_type
&offset_map
,
15342 struct field_info
*fi
,
15343 const variant_part_builder
&builder
)
15345 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15346 if (iter
== offset_map
.end ())
15348 result
.discriminant_index
= -1;
15349 /* Doesn't matter. */
15350 result
.is_unsigned
= false;
15354 result
.discriminant_index
= iter
->second
;
15356 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15359 size_t n
= builder
.variants
.size ();
15360 variant
*output
= new (obstack
) variant
[n
];
15361 for (size_t i
= 0; i
< n
; ++i
)
15362 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15363 builder
.variants
[i
]);
15365 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15368 /* Create a vector of variant parts that can be attached to a type.
15369 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15370 holds the mapping from section offsets to fields for the type. FI
15371 describes the fields of the type we're processing. VARIANT_PARTS
15372 is the vector to convert. */
15374 static const gdb::array_view
<variant_part
>
15375 create_variant_parts (struct obstack
*obstack
,
15376 const offset_map_type
&offset_map
,
15377 struct field_info
*fi
,
15378 const std::vector
<variant_part_builder
> &variant_parts
)
15380 if (variant_parts
.empty ())
15383 size_t n
= variant_parts
.size ();
15384 variant_part
*result
= new (obstack
) variant_part
[n
];
15385 for (size_t i
= 0; i
< n
; ++i
)
15386 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15389 return gdb::array_view
<variant_part
> (result
, n
);
15392 /* Compute the variant part vector for FIP, attaching it to TYPE when
15396 add_variant_property (struct field_info
*fip
, struct type
*type
,
15397 struct dwarf2_cu
*cu
)
15399 /* Map section offsets of fields to their field index. Note the
15400 field index here does not take the number of baseclasses into
15402 offset_map_type offset_map
;
15403 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15404 offset_map
[fip
->fields
[i
].offset
] = i
;
15406 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15407 gdb::array_view
<variant_part
> parts
15408 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15409 fip
->variant_parts
);
15411 struct dynamic_prop prop
;
15412 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15413 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15416 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15419 /* Create the vector of fields, and attach it to the type. */
15422 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15423 struct dwarf2_cu
*cu
)
15425 int nfields
= fip
->nfields ();
15427 /* Record the field count, allocate space for the array of fields,
15428 and create blank accessibility bitfields if necessary. */
15429 type
->set_num_fields (nfields
);
15431 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15433 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15435 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15437 TYPE_FIELD_PRIVATE_BITS (type
) =
15438 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15439 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15441 TYPE_FIELD_PROTECTED_BITS (type
) =
15442 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15443 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15445 TYPE_FIELD_IGNORE_BITS (type
) =
15446 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15447 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15450 /* If the type has baseclasses, allocate and clear a bit vector for
15451 TYPE_FIELD_VIRTUAL_BITS. */
15452 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15454 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15455 unsigned char *pointer
;
15457 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15458 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15459 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15460 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15461 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15464 if (!fip
->variant_parts
.empty ())
15465 add_variant_property (fip
, type
, cu
);
15467 /* Copy the saved-up fields into the field vector. */
15468 for (int i
= 0; i
< nfields
; ++i
)
15470 struct nextfield
&field
15471 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15472 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15474 type
->field (i
) = field
.field
;
15475 switch (field
.accessibility
)
15477 case DW_ACCESS_private
:
15478 if (cu
->language
!= language_ada
)
15479 SET_TYPE_FIELD_PRIVATE (type
, i
);
15482 case DW_ACCESS_protected
:
15483 if (cu
->language
!= language_ada
)
15484 SET_TYPE_FIELD_PROTECTED (type
, i
);
15487 case DW_ACCESS_public
:
15491 /* Unknown accessibility. Complain and treat it as public. */
15493 complaint (_("unsupported accessibility %d"),
15494 field
.accessibility
);
15498 if (i
< fip
->baseclasses
.size ())
15500 switch (field
.virtuality
)
15502 case DW_VIRTUALITY_virtual
:
15503 case DW_VIRTUALITY_pure_virtual
:
15504 if (cu
->language
== language_ada
)
15505 error (_("unexpected virtuality in component of Ada type"));
15506 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15513 /* Return true if this member function is a constructor, false
15517 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15519 const char *fieldname
;
15520 const char *type_name
;
15523 if (die
->parent
== NULL
)
15526 if (die
->parent
->tag
!= DW_TAG_structure_type
15527 && die
->parent
->tag
!= DW_TAG_union_type
15528 && die
->parent
->tag
!= DW_TAG_class_type
)
15531 fieldname
= dwarf2_name (die
, cu
);
15532 type_name
= dwarf2_name (die
->parent
, cu
);
15533 if (fieldname
== NULL
|| type_name
== NULL
)
15536 len
= strlen (fieldname
);
15537 return (strncmp (fieldname
, type_name
, len
) == 0
15538 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15541 /* Check if the given VALUE is a recognized enum
15542 dwarf_defaulted_attribute constant according to DWARF5 spec,
15546 is_valid_DW_AT_defaulted (ULONGEST value
)
15550 case DW_DEFAULTED_no
:
15551 case DW_DEFAULTED_in_class
:
15552 case DW_DEFAULTED_out_of_class
:
15556 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15560 /* Add a member function to the proper fieldlist. */
15563 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15564 struct type
*type
, struct dwarf2_cu
*cu
)
15566 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15567 struct attribute
*attr
;
15569 struct fnfieldlist
*flp
= nullptr;
15570 struct fn_field
*fnp
;
15571 const char *fieldname
;
15572 struct type
*this_type
;
15573 enum dwarf_access_attribute accessibility
;
15575 if (cu
->language
== language_ada
)
15576 error (_("unexpected member function in Ada type"));
15578 /* Get name of member function. */
15579 fieldname
= dwarf2_name (die
, cu
);
15580 if (fieldname
== NULL
)
15583 /* Look up member function name in fieldlist. */
15584 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15586 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15588 flp
= &fip
->fnfieldlists
[i
];
15593 /* Create a new fnfieldlist if necessary. */
15594 if (flp
== nullptr)
15596 fip
->fnfieldlists
.emplace_back ();
15597 flp
= &fip
->fnfieldlists
.back ();
15598 flp
->name
= fieldname
;
15599 i
= fip
->fnfieldlists
.size () - 1;
15602 /* Create a new member function field and add it to the vector of
15604 flp
->fnfields
.emplace_back ();
15605 fnp
= &flp
->fnfields
.back ();
15607 /* Delay processing of the physname until later. */
15608 if (cu
->language
== language_cplus
)
15609 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15613 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15614 fnp
->physname
= physname
? physname
: "";
15617 fnp
->type
= alloc_type (objfile
);
15618 this_type
= read_type_die (die
, cu
);
15619 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15621 int nparams
= this_type
->num_fields ();
15623 /* TYPE is the domain of this method, and THIS_TYPE is the type
15624 of the method itself (TYPE_CODE_METHOD). */
15625 smash_to_method_type (fnp
->type
, type
,
15626 TYPE_TARGET_TYPE (this_type
),
15627 this_type
->fields (),
15628 this_type
->num_fields (),
15629 this_type
->has_varargs ());
15631 /* Handle static member functions.
15632 Dwarf2 has no clean way to discern C++ static and non-static
15633 member functions. G++ helps GDB by marking the first
15634 parameter for non-static member functions (which is the this
15635 pointer) as artificial. We obtain this information from
15636 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15637 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15638 fnp
->voffset
= VOFFSET_STATIC
;
15641 complaint (_("member function type missing for '%s'"),
15642 dwarf2_full_name (fieldname
, die
, cu
));
15644 /* Get fcontext from DW_AT_containing_type if present. */
15645 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15646 fnp
->fcontext
= die_containing_type (die
, cu
);
15648 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15649 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15651 /* Get accessibility. */
15652 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15653 if (attr
!= nullptr)
15654 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15656 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15657 switch (accessibility
)
15659 case DW_ACCESS_private
:
15660 fnp
->is_private
= 1;
15662 case DW_ACCESS_protected
:
15663 fnp
->is_protected
= 1;
15667 /* Check for artificial methods. */
15668 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15669 if (attr
&& DW_UNSND (attr
) != 0)
15670 fnp
->is_artificial
= 1;
15672 /* Check for defaulted methods. */
15673 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15674 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15675 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15677 /* Check for deleted methods. */
15678 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15679 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15680 fnp
->is_deleted
= 1;
15682 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15684 /* Get index in virtual function table if it is a virtual member
15685 function. For older versions of GCC, this is an offset in the
15686 appropriate virtual table, as specified by DW_AT_containing_type.
15687 For everyone else, it is an expression to be evaluated relative
15688 to the object address. */
15690 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15691 if (attr
!= nullptr)
15693 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15695 struct dwarf_block
*block
= attr
->as_block ();
15697 if (block
->data
[0] == DW_OP_constu
)
15699 /* Old-style GCC. */
15700 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15702 else if (block
->data
[0] == DW_OP_deref
15703 || (block
->size
> 1
15704 && block
->data
[0] == DW_OP_deref_size
15705 && block
->data
[1] == cu
->header
.addr_size
))
15707 fnp
->voffset
= decode_locdesc (block
, cu
);
15708 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15709 dwarf2_complex_location_expr_complaint ();
15711 fnp
->voffset
/= cu
->header
.addr_size
;
15715 dwarf2_complex_location_expr_complaint ();
15717 if (!fnp
->fcontext
)
15719 /* If there is no `this' field and no DW_AT_containing_type,
15720 we cannot actually find a base class context for the
15722 if (this_type
->num_fields () == 0
15723 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15725 complaint (_("cannot determine context for virtual member "
15726 "function \"%s\" (offset %s)"),
15727 fieldname
, sect_offset_str (die
->sect_off
));
15732 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15736 else if (attr
->form_is_section_offset ())
15738 dwarf2_complex_location_expr_complaint ();
15742 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15748 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15749 if (attr
&& DW_UNSND (attr
))
15751 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15752 complaint (_("Member function \"%s\" (offset %s) is virtual "
15753 "but the vtable offset is not specified"),
15754 fieldname
, sect_offset_str (die
->sect_off
));
15755 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15756 TYPE_CPLUS_DYNAMIC (type
) = 1;
15761 /* Create the vector of member function fields, and attach it to the type. */
15764 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15765 struct dwarf2_cu
*cu
)
15767 if (cu
->language
== language_ada
)
15768 error (_("unexpected member functions in Ada type"));
15770 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15771 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15773 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15775 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15777 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15778 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15780 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15781 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15782 fn_flp
->fn_fields
= (struct fn_field
*)
15783 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15785 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15786 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15789 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15792 /* Returns non-zero if NAME is the name of a vtable member in CU's
15793 language, zero otherwise. */
15795 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15797 static const char vptr
[] = "_vptr";
15799 /* Look for the C++ form of the vtable. */
15800 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15806 /* GCC outputs unnamed structures that are really pointers to member
15807 functions, with the ABI-specified layout. If TYPE describes
15808 such a structure, smash it into a member function type.
15810 GCC shouldn't do this; it should just output pointer to member DIEs.
15811 This is GCC PR debug/28767. */
15814 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15816 struct type
*pfn_type
, *self_type
, *new_type
;
15818 /* Check for a structure with no name and two children. */
15819 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15822 /* Check for __pfn and __delta members. */
15823 if (TYPE_FIELD_NAME (type
, 0) == NULL
15824 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15825 || TYPE_FIELD_NAME (type
, 1) == NULL
15826 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15829 /* Find the type of the method. */
15830 pfn_type
= type
->field (0).type ();
15831 if (pfn_type
== NULL
15832 || pfn_type
->code () != TYPE_CODE_PTR
15833 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15836 /* Look for the "this" argument. */
15837 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15838 if (pfn_type
->num_fields () == 0
15839 /* || pfn_type->field (0).type () == NULL */
15840 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15843 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15844 new_type
= alloc_type (objfile
);
15845 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15846 pfn_type
->fields (), pfn_type
->num_fields (),
15847 pfn_type
->has_varargs ());
15848 smash_to_methodptr_type (type
, new_type
);
15851 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15852 appropriate error checking and issuing complaints if there is a
15856 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15858 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15860 if (attr
== nullptr)
15863 if (!attr
->form_is_constant ())
15865 complaint (_("DW_AT_alignment must have constant form"
15866 " - DIE at %s [in module %s]"),
15867 sect_offset_str (die
->sect_off
),
15868 objfile_name (cu
->per_objfile
->objfile
));
15873 if (attr
->form
== DW_FORM_sdata
)
15875 LONGEST val
= DW_SND (attr
);
15878 complaint (_("DW_AT_alignment value must not be negative"
15879 " - DIE at %s [in module %s]"),
15880 sect_offset_str (die
->sect_off
),
15881 objfile_name (cu
->per_objfile
->objfile
));
15887 align
= DW_UNSND (attr
);
15891 complaint (_("DW_AT_alignment value must not be zero"
15892 " - DIE at %s [in module %s]"),
15893 sect_offset_str (die
->sect_off
),
15894 objfile_name (cu
->per_objfile
->objfile
));
15897 if ((align
& (align
- 1)) != 0)
15899 complaint (_("DW_AT_alignment value must be a power of 2"
15900 " - DIE at %s [in module %s]"),
15901 sect_offset_str (die
->sect_off
),
15902 objfile_name (cu
->per_objfile
->objfile
));
15909 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15910 the alignment for TYPE. */
15913 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15916 if (!set_type_align (type
, get_alignment (cu
, die
)))
15917 complaint (_("DW_AT_alignment value too large"
15918 " - DIE at %s [in module %s]"),
15919 sect_offset_str (die
->sect_off
),
15920 objfile_name (cu
->per_objfile
->objfile
));
15923 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15924 constant for a type, according to DWARF5 spec, Table 5.5. */
15927 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15932 case DW_CC_pass_by_reference
:
15933 case DW_CC_pass_by_value
:
15937 complaint (_("unrecognized DW_AT_calling_convention value "
15938 "(%s) for a type"), pulongest (value
));
15943 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15944 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15945 also according to GNU-specific values (see include/dwarf2.h). */
15948 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15953 case DW_CC_program
:
15957 case DW_CC_GNU_renesas_sh
:
15958 case DW_CC_GNU_borland_fastcall_i386
:
15959 case DW_CC_GDB_IBM_OpenCL
:
15963 complaint (_("unrecognized DW_AT_calling_convention value "
15964 "(%s) for a subroutine"), pulongest (value
));
15969 /* Called when we find the DIE that starts a structure or union scope
15970 (definition) to create a type for the structure or union. Fill in
15971 the type's name and general properties; the members will not be
15972 processed until process_structure_scope. A symbol table entry for
15973 the type will also not be done until process_structure_scope (assuming
15974 the type has a name).
15976 NOTE: we need to call these functions regardless of whether or not the
15977 DIE has a DW_AT_name attribute, since it might be an anonymous
15978 structure or union. This gets the type entered into our set of
15979 user defined types. */
15981 static struct type
*
15982 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15984 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15986 struct attribute
*attr
;
15989 /* If the definition of this type lives in .debug_types, read that type.
15990 Don't follow DW_AT_specification though, that will take us back up
15991 the chain and we want to go down. */
15992 attr
= die
->attr (DW_AT_signature
);
15993 if (attr
!= nullptr)
15995 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15997 /* The type's CU may not be the same as CU.
15998 Ensure TYPE is recorded with CU in die_type_hash. */
15999 return set_die_type (die
, type
, cu
);
16002 type
= alloc_type (objfile
);
16003 INIT_CPLUS_SPECIFIC (type
);
16005 name
= dwarf2_name (die
, cu
);
16008 if (cu
->language
== language_cplus
16009 || cu
->language
== language_d
16010 || cu
->language
== language_rust
)
16012 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16014 /* dwarf2_full_name might have already finished building the DIE's
16015 type. If so, there is no need to continue. */
16016 if (get_die_type (die
, cu
) != NULL
)
16017 return get_die_type (die
, cu
);
16019 type
->set_name (full_name
);
16023 /* The name is already allocated along with this objfile, so
16024 we don't need to duplicate it for the type. */
16025 type
->set_name (name
);
16029 if (die
->tag
== DW_TAG_structure_type
)
16031 type
->set_code (TYPE_CODE_STRUCT
);
16033 else if (die
->tag
== DW_TAG_union_type
)
16035 type
->set_code (TYPE_CODE_UNION
);
16039 type
->set_code (TYPE_CODE_STRUCT
);
16042 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16043 TYPE_DECLARED_CLASS (type
) = 1;
16045 /* Store the calling convention in the type if it's available in
16046 the die. Otherwise the calling convention remains set to
16047 the default value DW_CC_normal. */
16048 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16049 if (attr
!= nullptr
16050 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
16052 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16053 TYPE_CPLUS_CALLING_CONVENTION (type
)
16054 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16057 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16058 if (attr
!= nullptr)
16060 if (attr
->form_is_constant ())
16061 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16064 struct dynamic_prop prop
;
16065 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
16066 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
16067 TYPE_LENGTH (type
) = 0;
16072 TYPE_LENGTH (type
) = 0;
16075 maybe_set_alignment (cu
, die
, type
);
16077 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16079 /* ICC<14 does not output the required DW_AT_declaration on
16080 incomplete types, but gives them a size of zero. */
16081 type
->set_is_stub (true);
16084 type
->set_stub_is_supported (true);
16086 if (die_is_declaration (die
, cu
))
16087 type
->set_is_stub (true);
16088 else if (attr
== NULL
&& die
->child
== NULL
16089 && producer_is_realview (cu
->producer
))
16090 /* RealView does not output the required DW_AT_declaration
16091 on incomplete types. */
16092 type
->set_is_stub (true);
16094 /* We need to add the type field to the die immediately so we don't
16095 infinitely recurse when dealing with pointers to the structure
16096 type within the structure itself. */
16097 set_die_type (die
, type
, cu
);
16099 /* set_die_type should be already done. */
16100 set_descriptive_type (type
, die
, cu
);
16105 static void handle_struct_member_die
16106 (struct die_info
*child_die
,
16108 struct field_info
*fi
,
16109 std::vector
<struct symbol
*> *template_args
,
16110 struct dwarf2_cu
*cu
);
16112 /* A helper for handle_struct_member_die that handles
16113 DW_TAG_variant_part. */
16116 handle_variant_part (struct die_info
*die
, struct type
*type
,
16117 struct field_info
*fi
,
16118 std::vector
<struct symbol
*> *template_args
,
16119 struct dwarf2_cu
*cu
)
16121 variant_part_builder
*new_part
;
16122 if (fi
->current_variant_part
== nullptr)
16124 fi
->variant_parts
.emplace_back ();
16125 new_part
= &fi
->variant_parts
.back ();
16127 else if (!fi
->current_variant_part
->processing_variant
)
16129 complaint (_("nested DW_TAG_variant_part seen "
16130 "- DIE at %s [in module %s]"),
16131 sect_offset_str (die
->sect_off
),
16132 objfile_name (cu
->per_objfile
->objfile
));
16137 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
16138 current
.variant_parts
.emplace_back ();
16139 new_part
= ¤t
.variant_parts
.back ();
16142 /* When we recurse, we want callees to add to this new variant
16144 scoped_restore save_current_variant_part
16145 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
16147 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16150 /* It's a univariant form, an extension we support. */
16152 else if (discr
->form_is_ref ())
16154 struct dwarf2_cu
*target_cu
= cu
;
16155 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16157 new_part
->discriminant_offset
= target_die
->sect_off
;
16161 complaint (_("DW_AT_discr does not have DIE reference form"
16162 " - DIE at %s [in module %s]"),
16163 sect_offset_str (die
->sect_off
),
16164 objfile_name (cu
->per_objfile
->objfile
));
16167 for (die_info
*child_die
= die
->child
;
16169 child_die
= child_die
->sibling
)
16170 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16173 /* A helper for handle_struct_member_die that handles
16177 handle_variant (struct die_info
*die
, struct type
*type
,
16178 struct field_info
*fi
,
16179 std::vector
<struct symbol
*> *template_args
,
16180 struct dwarf2_cu
*cu
)
16182 if (fi
->current_variant_part
== nullptr)
16184 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16185 "- DIE at %s [in module %s]"),
16186 sect_offset_str (die
->sect_off
),
16187 objfile_name (cu
->per_objfile
->objfile
));
16190 if (fi
->current_variant_part
->processing_variant
)
16192 complaint (_("nested DW_TAG_variant seen "
16193 "- DIE at %s [in module %s]"),
16194 sect_offset_str (die
->sect_off
),
16195 objfile_name (cu
->per_objfile
->objfile
));
16199 scoped_restore save_processing_variant
16200 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16203 fi
->current_variant_part
->variants
.emplace_back ();
16204 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16205 variant
.first_field
= fi
->fields
.size ();
16207 /* In a variant we want to get the discriminant and also add a
16208 field for our sole member child. */
16209 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16210 if (discr
== nullptr)
16212 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16213 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16214 variant
.default_branch
= true;
16216 variant
.discr_list_data
= discr
->as_block ();
16219 variant
.discriminant_value
= DW_UNSND (discr
);
16221 for (die_info
*variant_child
= die
->child
;
16222 variant_child
!= NULL
;
16223 variant_child
= variant_child
->sibling
)
16224 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16226 variant
.last_field
= fi
->fields
.size ();
16229 /* A helper for process_structure_scope that handles a single member
16233 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16234 struct field_info
*fi
,
16235 std::vector
<struct symbol
*> *template_args
,
16236 struct dwarf2_cu
*cu
)
16238 if (child_die
->tag
== DW_TAG_member
16239 || child_die
->tag
== DW_TAG_variable
)
16241 /* NOTE: carlton/2002-11-05: A C++ static data member
16242 should be a DW_TAG_member that is a declaration, but
16243 all versions of G++ as of this writing (so through at
16244 least 3.2.1) incorrectly generate DW_TAG_variable
16245 tags for them instead. */
16246 dwarf2_add_field (fi
, child_die
, cu
);
16248 else if (child_die
->tag
== DW_TAG_subprogram
)
16250 /* Rust doesn't have member functions in the C++ sense.
16251 However, it does emit ordinary functions as children
16252 of a struct DIE. */
16253 if (cu
->language
== language_rust
)
16254 read_func_scope (child_die
, cu
);
16257 /* C++ member function. */
16258 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16261 else if (child_die
->tag
== DW_TAG_inheritance
)
16263 /* C++ base class field. */
16264 dwarf2_add_field (fi
, child_die
, cu
);
16266 else if (type_can_define_types (child_die
))
16267 dwarf2_add_type_defn (fi
, child_die
, cu
);
16268 else if (child_die
->tag
== DW_TAG_template_type_param
16269 || child_die
->tag
== DW_TAG_template_value_param
)
16271 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16274 template_args
->push_back (arg
);
16276 else if (child_die
->tag
== DW_TAG_variant_part
)
16277 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16278 else if (child_die
->tag
== DW_TAG_variant
)
16279 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16282 /* Finish creating a structure or union type, including filling in
16283 its members and creating a symbol for it. */
16286 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16288 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16289 struct die_info
*child_die
;
16292 type
= get_die_type (die
, cu
);
16294 type
= read_structure_type (die
, cu
);
16296 bool has_template_parameters
= false;
16297 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16299 struct field_info fi
;
16300 std::vector
<struct symbol
*> template_args
;
16302 child_die
= die
->child
;
16304 while (child_die
&& child_die
->tag
)
16306 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16307 child_die
= child_die
->sibling
;
16310 /* Attach template arguments to type. */
16311 if (!template_args
.empty ())
16313 has_template_parameters
= true;
16314 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16315 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16316 TYPE_TEMPLATE_ARGUMENTS (type
)
16317 = XOBNEWVEC (&objfile
->objfile_obstack
,
16319 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16320 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16321 template_args
.data (),
16322 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16323 * sizeof (struct symbol
*)));
16326 /* Attach fields and member functions to the type. */
16327 if (fi
.nfields () > 0)
16328 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16329 if (!fi
.fnfieldlists
.empty ())
16331 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16333 /* Get the type which refers to the base class (possibly this
16334 class itself) which contains the vtable pointer for the current
16335 class from the DW_AT_containing_type attribute. This use of
16336 DW_AT_containing_type is a GNU extension. */
16338 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16340 struct type
*t
= die_containing_type (die
, cu
);
16342 set_type_vptr_basetype (type
, t
);
16347 /* Our own class provides vtbl ptr. */
16348 for (i
= t
->num_fields () - 1;
16349 i
>= TYPE_N_BASECLASSES (t
);
16352 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16354 if (is_vtable_name (fieldname
, cu
))
16356 set_type_vptr_fieldno (type
, i
);
16361 /* Complain if virtual function table field not found. */
16362 if (i
< TYPE_N_BASECLASSES (t
))
16363 complaint (_("virtual function table pointer "
16364 "not found when defining class '%s'"),
16365 type
->name () ? type
->name () : "");
16369 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16372 else if (cu
->producer
16373 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16375 /* The IBM XLC compiler does not provide direct indication
16376 of the containing type, but the vtable pointer is
16377 always named __vfp. */
16381 for (i
= type
->num_fields () - 1;
16382 i
>= TYPE_N_BASECLASSES (type
);
16385 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16387 set_type_vptr_fieldno (type
, i
);
16388 set_type_vptr_basetype (type
, type
);
16395 /* Copy fi.typedef_field_list linked list elements content into the
16396 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16397 if (!fi
.typedef_field_list
.empty ())
16399 int count
= fi
.typedef_field_list
.size ();
16401 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16402 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16403 = ((struct decl_field
*)
16405 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16406 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16408 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16409 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16412 /* Copy fi.nested_types_list linked list elements content into the
16413 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16414 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16416 int count
= fi
.nested_types_list
.size ();
16418 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16419 TYPE_NESTED_TYPES_ARRAY (type
)
16420 = ((struct decl_field
*)
16421 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16422 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16424 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16425 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16429 quirk_gcc_member_function_pointer (type
, objfile
);
16430 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16431 cu
->rust_unions
.push_back (type
);
16433 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16434 snapshots) has been known to create a die giving a declaration
16435 for a class that has, as a child, a die giving a definition for a
16436 nested class. So we have to process our children even if the
16437 current die is a declaration. Normally, of course, a declaration
16438 won't have any children at all. */
16440 child_die
= die
->child
;
16442 while (child_die
!= NULL
&& child_die
->tag
)
16444 if (child_die
->tag
== DW_TAG_member
16445 || child_die
->tag
== DW_TAG_variable
16446 || child_die
->tag
== DW_TAG_inheritance
16447 || child_die
->tag
== DW_TAG_template_value_param
16448 || child_die
->tag
== DW_TAG_template_type_param
)
16453 process_die (child_die
, cu
);
16455 child_die
= child_die
->sibling
;
16458 /* Do not consider external references. According to the DWARF standard,
16459 these DIEs are identified by the fact that they have no byte_size
16460 attribute, and a declaration attribute. */
16461 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16462 || !die_is_declaration (die
, cu
)
16463 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16465 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16467 if (has_template_parameters
)
16469 struct symtab
*symtab
;
16470 if (sym
!= nullptr)
16471 symtab
= symbol_symtab (sym
);
16472 else if (cu
->line_header
!= nullptr)
16474 /* Any related symtab will do. */
16476 = cu
->line_header
->file_names ()[0].symtab
;
16481 complaint (_("could not find suitable "
16482 "symtab for template parameter"
16483 " - DIE at %s [in module %s]"),
16484 sect_offset_str (die
->sect_off
),
16485 objfile_name (objfile
));
16488 if (symtab
!= nullptr)
16490 /* Make sure that the symtab is set on the new symbols.
16491 Even though they don't appear in this symtab directly,
16492 other parts of gdb assume that symbols do, and this is
16493 reasonably true. */
16494 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16495 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16501 /* Assuming DIE is an enumeration type, and TYPE is its associated
16502 type, update TYPE using some information only available in DIE's
16503 children. In particular, the fields are computed. */
16506 update_enumeration_type_from_children (struct die_info
*die
,
16508 struct dwarf2_cu
*cu
)
16510 struct die_info
*child_die
;
16511 int unsigned_enum
= 1;
16514 auto_obstack obstack
;
16515 std::vector
<struct field
> fields
;
16517 for (child_die
= die
->child
;
16518 child_die
!= NULL
&& child_die
->tag
;
16519 child_die
= child_die
->sibling
)
16521 struct attribute
*attr
;
16523 const gdb_byte
*bytes
;
16524 struct dwarf2_locexpr_baton
*baton
;
16527 if (child_die
->tag
!= DW_TAG_enumerator
)
16530 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16534 name
= dwarf2_name (child_die
, cu
);
16536 name
= "<anonymous enumerator>";
16538 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16539 &value
, &bytes
, &baton
);
16547 if (count_one_bits_ll (value
) >= 2)
16551 fields
.emplace_back ();
16552 struct field
&field
= fields
.back ();
16553 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16554 SET_FIELD_ENUMVAL (field
, value
);
16557 if (!fields
.empty ())
16559 type
->set_num_fields (fields
.size ());
16562 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16563 memcpy (type
->fields (), fields
.data (),
16564 sizeof (struct field
) * fields
.size ());
16568 type
->set_is_unsigned (true);
16571 TYPE_FLAG_ENUM (type
) = 1;
16574 /* Given a DW_AT_enumeration_type die, set its type. We do not
16575 complete the type's fields yet, or create any symbols. */
16577 static struct type
*
16578 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16580 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16582 struct attribute
*attr
;
16585 /* If the definition of this type lives in .debug_types, read that type.
16586 Don't follow DW_AT_specification though, that will take us back up
16587 the chain and we want to go down. */
16588 attr
= die
->attr (DW_AT_signature
);
16589 if (attr
!= nullptr)
16591 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16593 /* The type's CU may not be the same as CU.
16594 Ensure TYPE is recorded with CU in die_type_hash. */
16595 return set_die_type (die
, type
, cu
);
16598 type
= alloc_type (objfile
);
16600 type
->set_code (TYPE_CODE_ENUM
);
16601 name
= dwarf2_full_name (NULL
, die
, cu
);
16603 type
->set_name (name
);
16605 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16608 struct type
*underlying_type
= die_type (die
, cu
);
16610 TYPE_TARGET_TYPE (type
) = underlying_type
;
16613 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16614 if (attr
!= nullptr)
16616 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16620 TYPE_LENGTH (type
) = 0;
16623 maybe_set_alignment (cu
, die
, type
);
16625 /* The enumeration DIE can be incomplete. In Ada, any type can be
16626 declared as private in the package spec, and then defined only
16627 inside the package body. Such types are known as Taft Amendment
16628 Types. When another package uses such a type, an incomplete DIE
16629 may be generated by the compiler. */
16630 if (die_is_declaration (die
, cu
))
16631 type
->set_is_stub (true);
16633 /* If this type has an underlying type that is not a stub, then we
16634 may use its attributes. We always use the "unsigned" attribute
16635 in this situation, because ordinarily we guess whether the type
16636 is unsigned -- but the guess can be wrong and the underlying type
16637 can tell us the reality. However, we defer to a local size
16638 attribute if one exists, because this lets the compiler override
16639 the underlying type if needed. */
16640 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16642 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16643 underlying_type
= check_typedef (underlying_type
);
16645 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16647 if (TYPE_LENGTH (type
) == 0)
16648 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16650 if (TYPE_RAW_ALIGN (type
) == 0
16651 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16652 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16655 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16657 set_die_type (die
, type
, cu
);
16659 /* Finish the creation of this type by using the enum's children.
16660 Note that, as usual, this must come after set_die_type to avoid
16661 infinite recursion when trying to compute the names of the
16663 update_enumeration_type_from_children (die
, type
, cu
);
16668 /* Given a pointer to a die which begins an enumeration, process all
16669 the dies that define the members of the enumeration, and create the
16670 symbol for the enumeration type.
16672 NOTE: We reverse the order of the element list. */
16675 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16677 struct type
*this_type
;
16679 this_type
= get_die_type (die
, cu
);
16680 if (this_type
== NULL
)
16681 this_type
= read_enumeration_type (die
, cu
);
16683 if (die
->child
!= NULL
)
16685 struct die_info
*child_die
;
16688 child_die
= die
->child
;
16689 while (child_die
&& child_die
->tag
)
16691 if (child_die
->tag
!= DW_TAG_enumerator
)
16693 process_die (child_die
, cu
);
16697 name
= dwarf2_name (child_die
, cu
);
16699 new_symbol (child_die
, this_type
, cu
);
16702 child_die
= child_die
->sibling
;
16706 /* If we are reading an enum from a .debug_types unit, and the enum
16707 is a declaration, and the enum is not the signatured type in the
16708 unit, then we do not want to add a symbol for it. Adding a
16709 symbol would in some cases obscure the true definition of the
16710 enum, giving users an incomplete type when the definition is
16711 actually available. Note that we do not want to do this for all
16712 enums which are just declarations, because C++0x allows forward
16713 enum declarations. */
16714 if (cu
->per_cu
->is_debug_types
16715 && die_is_declaration (die
, cu
))
16717 struct signatured_type
*sig_type
;
16719 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16720 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16721 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16725 new_symbol (die
, this_type
, cu
);
16728 /* Extract all information from a DW_TAG_array_type DIE and put it in
16729 the DIE's type field. For now, this only handles one dimensional
16732 static struct type
*
16733 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16735 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16736 struct die_info
*child_die
;
16738 struct type
*element_type
, *range_type
, *index_type
;
16739 struct attribute
*attr
;
16741 struct dynamic_prop
*byte_stride_prop
= NULL
;
16742 unsigned int bit_stride
= 0;
16744 element_type
= die_type (die
, cu
);
16746 /* The die_type call above may have already set the type for this DIE. */
16747 type
= get_die_type (die
, cu
);
16751 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16755 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16758 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16759 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16763 complaint (_("unable to read array DW_AT_byte_stride "
16764 " - DIE at %s [in module %s]"),
16765 sect_offset_str (die
->sect_off
),
16766 objfile_name (cu
->per_objfile
->objfile
));
16767 /* Ignore this attribute. We will likely not be able to print
16768 arrays of this type correctly, but there is little we can do
16769 to help if we cannot read the attribute's value. */
16770 byte_stride_prop
= NULL
;
16774 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16776 bit_stride
= DW_UNSND (attr
);
16778 /* Irix 6.2 native cc creates array types without children for
16779 arrays with unspecified length. */
16780 if (die
->child
== NULL
)
16782 index_type
= objfile_type (objfile
)->builtin_int
;
16783 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16784 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16785 byte_stride_prop
, bit_stride
);
16786 return set_die_type (die
, type
, cu
);
16789 std::vector
<struct type
*> range_types
;
16790 child_die
= die
->child
;
16791 while (child_die
&& child_die
->tag
)
16793 if (child_die
->tag
== DW_TAG_subrange_type
)
16795 struct type
*child_type
= read_type_die (child_die
, cu
);
16797 if (child_type
!= NULL
)
16799 /* The range type was succesfully read. Save it for the
16800 array type creation. */
16801 range_types
.push_back (child_type
);
16804 child_die
= child_die
->sibling
;
16807 /* Dwarf2 dimensions are output from left to right, create the
16808 necessary array types in backwards order. */
16810 type
= element_type
;
16812 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16816 while (i
< range_types
.size ())
16817 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16818 byte_stride_prop
, bit_stride
);
16822 size_t ndim
= range_types
.size ();
16824 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16825 byte_stride_prop
, bit_stride
);
16828 /* Understand Dwarf2 support for vector types (like they occur on
16829 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16830 array type. This is not part of the Dwarf2/3 standard yet, but a
16831 custom vendor extension. The main difference between a regular
16832 array and the vector variant is that vectors are passed by value
16834 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16835 if (attr
!= nullptr)
16836 make_vector_type (type
);
16838 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16839 implementation may choose to implement triple vectors using this
16841 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16842 if (attr
!= nullptr)
16844 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16845 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16847 complaint (_("DW_AT_byte_size for array type smaller "
16848 "than the total size of elements"));
16851 name
= dwarf2_name (die
, cu
);
16853 type
->set_name (name
);
16855 maybe_set_alignment (cu
, die
, type
);
16857 /* Install the type in the die. */
16858 set_die_type (die
, type
, cu
);
16860 /* set_die_type should be already done. */
16861 set_descriptive_type (type
, die
, cu
);
16866 static enum dwarf_array_dim_ordering
16867 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16869 struct attribute
*attr
;
16871 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16873 if (attr
!= nullptr)
16874 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16876 /* GNU F77 is a special case, as at 08/2004 array type info is the
16877 opposite order to the dwarf2 specification, but data is still
16878 laid out as per normal fortran.
16880 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16881 version checking. */
16883 if (cu
->language
== language_fortran
16884 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16886 return DW_ORD_row_major
;
16889 switch (cu
->language_defn
->array_ordering ())
16891 case array_column_major
:
16892 return DW_ORD_col_major
;
16893 case array_row_major
:
16895 return DW_ORD_row_major
;
16899 /* Extract all information from a DW_TAG_set_type DIE and put it in
16900 the DIE's type field. */
16902 static struct type
*
16903 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16905 struct type
*domain_type
, *set_type
;
16906 struct attribute
*attr
;
16908 domain_type
= die_type (die
, cu
);
16910 /* The die_type call above may have already set the type for this DIE. */
16911 set_type
= get_die_type (die
, cu
);
16915 set_type
= create_set_type (NULL
, domain_type
);
16917 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16918 if (attr
!= nullptr)
16919 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16921 maybe_set_alignment (cu
, die
, set_type
);
16923 return set_die_type (die
, set_type
, cu
);
16926 /* A helper for read_common_block that creates a locexpr baton.
16927 SYM is the symbol which we are marking as computed.
16928 COMMON_DIE is the DIE for the common block.
16929 COMMON_LOC is the location expression attribute for the common
16931 MEMBER_LOC is the location expression attribute for the particular
16932 member of the common block that we are processing.
16933 CU is the CU from which the above come. */
16936 mark_common_block_symbol_computed (struct symbol
*sym
,
16937 struct die_info
*common_die
,
16938 struct attribute
*common_loc
,
16939 struct attribute
*member_loc
,
16940 struct dwarf2_cu
*cu
)
16942 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16943 struct objfile
*objfile
= per_objfile
->objfile
;
16944 struct dwarf2_locexpr_baton
*baton
;
16946 unsigned int cu_off
;
16947 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16948 LONGEST offset
= 0;
16950 gdb_assert (common_loc
&& member_loc
);
16951 gdb_assert (common_loc
->form_is_block ());
16952 gdb_assert (member_loc
->form_is_block ()
16953 || member_loc
->form_is_constant ());
16955 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16956 baton
->per_objfile
= per_objfile
;
16957 baton
->per_cu
= cu
->per_cu
;
16958 gdb_assert (baton
->per_cu
);
16960 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16962 if (member_loc
->form_is_constant ())
16964 offset
= member_loc
->constant_value (0);
16965 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16968 baton
->size
+= member_loc
->as_block ()->size
;
16970 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16973 *ptr
++ = DW_OP_call4
;
16974 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16975 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16978 if (member_loc
->form_is_constant ())
16980 *ptr
++ = DW_OP_addr
;
16981 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16982 ptr
+= cu
->header
.addr_size
;
16986 /* We have to copy the data here, because DW_OP_call4 will only
16987 use a DW_AT_location attribute. */
16988 struct dwarf_block
*block
= member_loc
->as_block ();
16989 memcpy (ptr
, block
->data
, block
->size
);
16990 ptr
+= block
->size
;
16993 *ptr
++ = DW_OP_plus
;
16994 gdb_assert (ptr
- baton
->data
== baton
->size
);
16996 SYMBOL_LOCATION_BATON (sym
) = baton
;
16997 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17000 /* Create appropriate locally-scoped variables for all the
17001 DW_TAG_common_block entries. Also create a struct common_block
17002 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17003 is used to separate the common blocks name namespace from regular
17007 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17009 struct attribute
*attr
;
17011 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17012 if (attr
!= nullptr)
17014 /* Support the .debug_loc offsets. */
17015 if (attr
->form_is_block ())
17019 else if (attr
->form_is_section_offset ())
17021 dwarf2_complex_location_expr_complaint ();
17026 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17027 "common block member");
17032 if (die
->child
!= NULL
)
17034 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17035 struct die_info
*child_die
;
17036 size_t n_entries
= 0, size
;
17037 struct common_block
*common_block
;
17038 struct symbol
*sym
;
17040 for (child_die
= die
->child
;
17041 child_die
&& child_die
->tag
;
17042 child_die
= child_die
->sibling
)
17045 size
= (sizeof (struct common_block
)
17046 + (n_entries
- 1) * sizeof (struct symbol
*));
17048 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17050 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17051 common_block
->n_entries
= 0;
17053 for (child_die
= die
->child
;
17054 child_die
&& child_die
->tag
;
17055 child_die
= child_die
->sibling
)
17057 /* Create the symbol in the DW_TAG_common_block block in the current
17059 sym
= new_symbol (child_die
, NULL
, cu
);
17062 struct attribute
*member_loc
;
17064 common_block
->contents
[common_block
->n_entries
++] = sym
;
17066 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17070 /* GDB has handled this for a long time, but it is
17071 not specified by DWARF. It seems to have been
17072 emitted by gfortran at least as recently as:
17073 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17074 complaint (_("Variable in common block has "
17075 "DW_AT_data_member_location "
17076 "- DIE at %s [in module %s]"),
17077 sect_offset_str (child_die
->sect_off
),
17078 objfile_name (objfile
));
17080 if (member_loc
->form_is_section_offset ())
17081 dwarf2_complex_location_expr_complaint ();
17082 else if (member_loc
->form_is_constant ()
17083 || member_loc
->form_is_block ())
17085 if (attr
!= nullptr)
17086 mark_common_block_symbol_computed (sym
, die
, attr
,
17090 dwarf2_complex_location_expr_complaint ();
17095 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17096 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17100 /* Create a type for a C++ namespace. */
17102 static struct type
*
17103 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17105 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17106 const char *previous_prefix
, *name
;
17110 /* For extensions, reuse the type of the original namespace. */
17111 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17113 struct die_info
*ext_die
;
17114 struct dwarf2_cu
*ext_cu
= cu
;
17116 ext_die
= dwarf2_extension (die
, &ext_cu
);
17117 type
= read_type_die (ext_die
, ext_cu
);
17119 /* EXT_CU may not be the same as CU.
17120 Ensure TYPE is recorded with CU in die_type_hash. */
17121 return set_die_type (die
, type
, cu
);
17124 name
= namespace_name (die
, &is_anonymous
, cu
);
17126 /* Now build the name of the current namespace. */
17128 previous_prefix
= determine_prefix (die
, cu
);
17129 if (previous_prefix
[0] != '\0')
17130 name
= typename_concat (&objfile
->objfile_obstack
,
17131 previous_prefix
, name
, 0, cu
);
17133 /* Create the type. */
17134 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17136 return set_die_type (die
, type
, cu
);
17139 /* Read a namespace scope. */
17142 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17144 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17147 /* Add a symbol associated to this if we haven't seen the namespace
17148 before. Also, add a using directive if it's an anonymous
17151 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17155 type
= read_type_die (die
, cu
);
17156 new_symbol (die
, type
, cu
);
17158 namespace_name (die
, &is_anonymous
, cu
);
17161 const char *previous_prefix
= determine_prefix (die
, cu
);
17163 std::vector
<const char *> excludes
;
17164 add_using_directive (using_directives (cu
),
17165 previous_prefix
, type
->name (), NULL
,
17166 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17170 if (die
->child
!= NULL
)
17172 struct die_info
*child_die
= die
->child
;
17174 while (child_die
&& child_die
->tag
)
17176 process_die (child_die
, cu
);
17177 child_die
= child_die
->sibling
;
17182 /* Read a Fortran module as type. This DIE can be only a declaration used for
17183 imported module. Still we need that type as local Fortran "use ... only"
17184 declaration imports depend on the created type in determine_prefix. */
17186 static struct type
*
17187 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17189 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17190 const char *module_name
;
17193 module_name
= dwarf2_name (die
, cu
);
17194 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17196 return set_die_type (die
, type
, cu
);
17199 /* Read a Fortran module. */
17202 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17204 struct die_info
*child_die
= die
->child
;
17207 type
= read_type_die (die
, cu
);
17208 new_symbol (die
, type
, cu
);
17210 while (child_die
&& child_die
->tag
)
17212 process_die (child_die
, cu
);
17213 child_die
= child_die
->sibling
;
17217 /* Return the name of the namespace represented by DIE. Set
17218 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17221 static const char *
17222 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17224 struct die_info
*current_die
;
17225 const char *name
= NULL
;
17227 /* Loop through the extensions until we find a name. */
17229 for (current_die
= die
;
17230 current_die
!= NULL
;
17231 current_die
= dwarf2_extension (die
, &cu
))
17233 /* We don't use dwarf2_name here so that we can detect the absence
17234 of a name -> anonymous namespace. */
17235 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17241 /* Is it an anonymous namespace? */
17243 *is_anonymous
= (name
== NULL
);
17245 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17250 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17251 the user defined type vector. */
17253 static struct type
*
17254 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17256 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17257 struct comp_unit_head
*cu_header
= &cu
->header
;
17259 struct attribute
*attr_byte_size
;
17260 struct attribute
*attr_address_class
;
17261 int byte_size
, addr_class
;
17262 struct type
*target_type
;
17264 target_type
= die_type (die
, cu
);
17266 /* The die_type call above may have already set the type for this DIE. */
17267 type
= get_die_type (die
, cu
);
17271 type
= lookup_pointer_type (target_type
);
17273 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17274 if (attr_byte_size
)
17275 byte_size
= DW_UNSND (attr_byte_size
);
17277 byte_size
= cu_header
->addr_size
;
17279 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17280 if (attr_address_class
)
17281 addr_class
= DW_UNSND (attr_address_class
);
17283 addr_class
= DW_ADDR_none
;
17285 ULONGEST alignment
= get_alignment (cu
, die
);
17287 /* If the pointer size, alignment, or address class is different
17288 than the default, create a type variant marked as such and set
17289 the length accordingly. */
17290 if (TYPE_LENGTH (type
) != byte_size
17291 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17292 && alignment
!= TYPE_RAW_ALIGN (type
))
17293 || addr_class
!= DW_ADDR_none
)
17295 if (gdbarch_address_class_type_flags_p (gdbarch
))
17297 type_instance_flags type_flags
17298 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17300 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17302 type
= make_type_with_address_space (type
, type_flags
);
17304 else if (TYPE_LENGTH (type
) != byte_size
)
17306 complaint (_("invalid pointer size %d"), byte_size
);
17308 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17310 complaint (_("Invalid DW_AT_alignment"
17311 " - DIE at %s [in module %s]"),
17312 sect_offset_str (die
->sect_off
),
17313 objfile_name (cu
->per_objfile
->objfile
));
17317 /* Should we also complain about unhandled address classes? */
17321 TYPE_LENGTH (type
) = byte_size
;
17322 set_type_align (type
, alignment
);
17323 return set_die_type (die
, type
, cu
);
17326 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17327 the user defined type vector. */
17329 static struct type
*
17330 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17333 struct type
*to_type
;
17334 struct type
*domain
;
17336 to_type
= die_type (die
, cu
);
17337 domain
= die_containing_type (die
, cu
);
17339 /* The calls above may have already set the type for this DIE. */
17340 type
= get_die_type (die
, cu
);
17344 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17345 type
= lookup_methodptr_type (to_type
);
17346 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17348 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17350 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17351 to_type
->fields (), to_type
->num_fields (),
17352 to_type
->has_varargs ());
17353 type
= lookup_methodptr_type (new_type
);
17356 type
= lookup_memberptr_type (to_type
, domain
);
17358 return set_die_type (die
, type
, cu
);
17361 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17362 the user defined type vector. */
17364 static struct type
*
17365 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17366 enum type_code refcode
)
17368 struct comp_unit_head
*cu_header
= &cu
->header
;
17369 struct type
*type
, *target_type
;
17370 struct attribute
*attr
;
17372 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17374 target_type
= die_type (die
, cu
);
17376 /* The die_type call above may have already set the type for this DIE. */
17377 type
= get_die_type (die
, cu
);
17381 type
= lookup_reference_type (target_type
, refcode
);
17382 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17383 if (attr
!= nullptr)
17385 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17389 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17391 maybe_set_alignment (cu
, die
, type
);
17392 return set_die_type (die
, type
, cu
);
17395 /* Add the given cv-qualifiers to the element type of the array. GCC
17396 outputs DWARF type qualifiers that apply to an array, not the
17397 element type. But GDB relies on the array element type to carry
17398 the cv-qualifiers. This mimics section 6.7.3 of the C99
17401 static struct type
*
17402 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17403 struct type
*base_type
, int cnst
, int voltl
)
17405 struct type
*el_type
, *inner_array
;
17407 base_type
= copy_type (base_type
);
17408 inner_array
= base_type
;
17410 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17412 TYPE_TARGET_TYPE (inner_array
) =
17413 copy_type (TYPE_TARGET_TYPE (inner_array
));
17414 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17417 el_type
= TYPE_TARGET_TYPE (inner_array
);
17418 cnst
|= TYPE_CONST (el_type
);
17419 voltl
|= TYPE_VOLATILE (el_type
);
17420 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17422 return set_die_type (die
, base_type
, cu
);
17425 static struct type
*
17426 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17428 struct type
*base_type
, *cv_type
;
17430 base_type
= die_type (die
, cu
);
17432 /* The die_type call above may have already set the type for this DIE. */
17433 cv_type
= get_die_type (die
, cu
);
17437 /* In case the const qualifier is applied to an array type, the element type
17438 is so qualified, not the array type (section 6.7.3 of C99). */
17439 if (base_type
->code () == TYPE_CODE_ARRAY
)
17440 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17442 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17443 return set_die_type (die
, cv_type
, cu
);
17446 static struct type
*
17447 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17449 struct type
*base_type
, *cv_type
;
17451 base_type
= die_type (die
, cu
);
17453 /* The die_type call above may have already set the type for this DIE. */
17454 cv_type
= get_die_type (die
, cu
);
17458 /* In case the volatile qualifier is applied to an array type, the
17459 element type is so qualified, not the array type (section 6.7.3
17461 if (base_type
->code () == TYPE_CODE_ARRAY
)
17462 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17464 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17465 return set_die_type (die
, cv_type
, cu
);
17468 /* Handle DW_TAG_restrict_type. */
17470 static struct type
*
17471 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17473 struct type
*base_type
, *cv_type
;
17475 base_type
= die_type (die
, cu
);
17477 /* The die_type call above may have already set the type for this DIE. */
17478 cv_type
= get_die_type (die
, cu
);
17482 cv_type
= make_restrict_type (base_type
);
17483 return set_die_type (die
, cv_type
, cu
);
17486 /* Handle DW_TAG_atomic_type. */
17488 static struct type
*
17489 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17491 struct type
*base_type
, *cv_type
;
17493 base_type
= die_type (die
, cu
);
17495 /* The die_type call above may have already set the type for this DIE. */
17496 cv_type
= get_die_type (die
, cu
);
17500 cv_type
= make_atomic_type (base_type
);
17501 return set_die_type (die
, cv_type
, cu
);
17504 /* Extract all information from a DW_TAG_string_type DIE and add to
17505 the user defined type vector. It isn't really a user defined type,
17506 but it behaves like one, with other DIE's using an AT_user_def_type
17507 attribute to reference it. */
17509 static struct type
*
17510 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17512 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17513 struct gdbarch
*gdbarch
= objfile
->arch ();
17514 struct type
*type
, *range_type
, *index_type
, *char_type
;
17515 struct attribute
*attr
;
17516 struct dynamic_prop prop
;
17517 bool length_is_constant
= true;
17520 /* There are a couple of places where bit sizes might be made use of
17521 when parsing a DW_TAG_string_type, however, no producer that we know
17522 of make use of these. Handling bit sizes that are a multiple of the
17523 byte size is easy enough, but what about other bit sizes? Lets deal
17524 with that problem when we have to. Warn about these attributes being
17525 unsupported, then parse the type and ignore them like we always
17527 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17528 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17530 static bool warning_printed
= false;
17531 if (!warning_printed
)
17533 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17534 "currently supported on DW_TAG_string_type."));
17535 warning_printed
= true;
17539 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17540 if (attr
!= nullptr && !attr
->form_is_constant ())
17542 /* The string length describes the location at which the length of
17543 the string can be found. The size of the length field can be
17544 specified with one of the attributes below. */
17545 struct type
*prop_type
;
17546 struct attribute
*len
17547 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17548 if (len
== nullptr)
17549 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17550 if (len
!= nullptr && len
->form_is_constant ())
17552 /* Pass 0 as the default as we know this attribute is constant
17553 and the default value will not be returned. */
17554 LONGEST sz
= len
->constant_value (0);
17555 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17559 /* If the size is not specified then we assume it is the size of
17560 an address on this target. */
17561 prop_type
= cu
->addr_sized_int_type (true);
17564 /* Convert the attribute into a dynamic property. */
17565 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17568 length_is_constant
= false;
17570 else if (attr
!= nullptr)
17572 /* This DW_AT_string_length just contains the length with no
17573 indirection. There's no need to create a dynamic property in this
17574 case. Pass 0 for the default value as we know it will not be
17575 returned in this case. */
17576 length
= attr
->constant_value (0);
17578 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17580 /* We don't currently support non-constant byte sizes for strings. */
17581 length
= attr
->constant_value (1);
17585 /* Use 1 as a fallback length if we have nothing else. */
17589 index_type
= objfile_type (objfile
)->builtin_int
;
17590 if (length_is_constant
)
17591 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17594 struct dynamic_prop low_bound
;
17596 low_bound
.set_const_val (1);
17597 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17599 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17600 type
= create_string_type (NULL
, char_type
, range_type
);
17602 return set_die_type (die
, type
, cu
);
17605 /* Assuming that DIE corresponds to a function, returns nonzero
17606 if the function is prototyped. */
17609 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17611 struct attribute
*attr
;
17613 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17614 if (attr
&& (DW_UNSND (attr
) != 0))
17617 /* The DWARF standard implies that the DW_AT_prototyped attribute
17618 is only meaningful for C, but the concept also extends to other
17619 languages that allow unprototyped functions (Eg: Objective C).
17620 For all other languages, assume that functions are always
17622 if (cu
->language
!= language_c
17623 && cu
->language
!= language_objc
17624 && cu
->language
!= language_opencl
)
17627 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17628 prototyped and unprototyped functions; default to prototyped,
17629 since that is more common in modern code (and RealView warns
17630 about unprototyped functions). */
17631 if (producer_is_realview (cu
->producer
))
17637 /* Handle DIES due to C code like:
17641 int (*funcp)(int a, long l);
17645 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17647 static struct type
*
17648 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17650 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17651 struct type
*type
; /* Type that this function returns. */
17652 struct type
*ftype
; /* Function that returns above type. */
17653 struct attribute
*attr
;
17655 type
= die_type (die
, cu
);
17657 /* The die_type call above may have already set the type for this DIE. */
17658 ftype
= get_die_type (die
, cu
);
17662 ftype
= lookup_function_type (type
);
17664 if (prototyped_function_p (die
, cu
))
17665 ftype
->set_is_prototyped (true);
17667 /* Store the calling convention in the type if it's available in
17668 the subroutine die. Otherwise set the calling convention to
17669 the default value DW_CC_normal. */
17670 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17671 if (attr
!= nullptr
17672 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17673 TYPE_CALLING_CONVENTION (ftype
)
17674 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17675 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17676 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17678 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17680 /* Record whether the function returns normally to its caller or not
17681 if the DWARF producer set that information. */
17682 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17683 if (attr
&& (DW_UNSND (attr
) != 0))
17684 TYPE_NO_RETURN (ftype
) = 1;
17686 /* We need to add the subroutine type to the die immediately so
17687 we don't infinitely recurse when dealing with parameters
17688 declared as the same subroutine type. */
17689 set_die_type (die
, ftype
, cu
);
17691 if (die
->child
!= NULL
)
17693 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17694 struct die_info
*child_die
;
17695 int nparams
, iparams
;
17697 /* Count the number of parameters.
17698 FIXME: GDB currently ignores vararg functions, but knows about
17699 vararg member functions. */
17701 child_die
= die
->child
;
17702 while (child_die
&& child_die
->tag
)
17704 if (child_die
->tag
== DW_TAG_formal_parameter
)
17706 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17707 ftype
->set_has_varargs (true);
17709 child_die
= child_die
->sibling
;
17712 /* Allocate storage for parameters and fill them in. */
17713 ftype
->set_num_fields (nparams
);
17715 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17717 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17718 even if we error out during the parameters reading below. */
17719 for (iparams
= 0; iparams
< nparams
; iparams
++)
17720 ftype
->field (iparams
).set_type (void_type
);
17723 child_die
= die
->child
;
17724 while (child_die
&& child_die
->tag
)
17726 if (child_die
->tag
== DW_TAG_formal_parameter
)
17728 struct type
*arg_type
;
17730 /* DWARF version 2 has no clean way to discern C++
17731 static and non-static member functions. G++ helps
17732 GDB by marking the first parameter for non-static
17733 member functions (which is the this pointer) as
17734 artificial. We pass this information to
17735 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17737 DWARF version 3 added DW_AT_object_pointer, which GCC
17738 4.5 does not yet generate. */
17739 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17740 if (attr
!= nullptr)
17741 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17743 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17744 arg_type
= die_type (child_die
, cu
);
17746 /* RealView does not mark THIS as const, which the testsuite
17747 expects. GCC marks THIS as const in method definitions,
17748 but not in the class specifications (GCC PR 43053). */
17749 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17750 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17753 struct dwarf2_cu
*arg_cu
= cu
;
17754 const char *name
= dwarf2_name (child_die
, cu
);
17756 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17757 if (attr
!= nullptr)
17759 /* If the compiler emits this, use it. */
17760 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17763 else if (name
&& strcmp (name
, "this") == 0)
17764 /* Function definitions will have the argument names. */
17766 else if (name
== NULL
&& iparams
== 0)
17767 /* Declarations may not have the names, so like
17768 elsewhere in GDB, assume an artificial first
17769 argument is "this". */
17773 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17777 ftype
->field (iparams
).set_type (arg_type
);
17780 child_die
= child_die
->sibling
;
17787 static struct type
*
17788 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17790 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17791 const char *name
= NULL
;
17792 struct type
*this_type
, *target_type
;
17794 name
= dwarf2_full_name (NULL
, die
, cu
);
17795 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17796 this_type
->set_target_is_stub (true);
17797 set_die_type (die
, this_type
, cu
);
17798 target_type
= die_type (die
, cu
);
17799 if (target_type
!= this_type
)
17800 TYPE_TARGET_TYPE (this_type
) = target_type
;
17803 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17804 spec and cause infinite loops in GDB. */
17805 complaint (_("Self-referential DW_TAG_typedef "
17806 "- DIE at %s [in module %s]"),
17807 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17808 TYPE_TARGET_TYPE (this_type
) = NULL
;
17812 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17813 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17814 Handle these by just returning the target type, rather than
17815 constructing an anonymous typedef type and trying to handle this
17817 set_die_type (die
, target_type
, cu
);
17818 return target_type
;
17823 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17824 (which may be different from NAME) to the architecture back-end to allow
17825 it to guess the correct format if necessary. */
17827 static struct type
*
17828 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17829 const char *name_hint
, enum bfd_endian byte_order
)
17831 struct gdbarch
*gdbarch
= objfile
->arch ();
17832 const struct floatformat
**format
;
17835 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17837 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17839 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17844 /* Allocate an integer type of size BITS and name NAME. */
17846 static struct type
*
17847 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17848 int bits
, int unsigned_p
, const char *name
)
17852 /* Versions of Intel's C Compiler generate an integer type called "void"
17853 instead of using DW_TAG_unspecified_type. This has been seen on
17854 at least versions 14, 17, and 18. */
17855 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17856 && strcmp (name
, "void") == 0)
17857 type
= objfile_type (objfile
)->builtin_void
;
17859 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17864 /* Initialise and return a floating point type of size BITS suitable for
17865 use as a component of a complex number. The NAME_HINT is passed through
17866 when initialising the floating point type and is the name of the complex
17869 As DWARF doesn't currently provide an explicit name for the components
17870 of a complex number, but it can be helpful to have these components
17871 named, we try to select a suitable name based on the size of the
17873 static struct type
*
17874 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17875 struct objfile
*objfile
,
17876 int bits
, const char *name_hint
,
17877 enum bfd_endian byte_order
)
17879 gdbarch
*gdbarch
= objfile
->arch ();
17880 struct type
*tt
= nullptr;
17882 /* Try to find a suitable floating point builtin type of size BITS.
17883 We're going to use the name of this type as the name for the complex
17884 target type that we are about to create. */
17885 switch (cu
->language
)
17887 case language_fortran
:
17891 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17894 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17896 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17898 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17906 tt
= builtin_type (gdbarch
)->builtin_float
;
17909 tt
= builtin_type (gdbarch
)->builtin_double
;
17911 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17913 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17919 /* If the type we found doesn't match the size we were looking for, then
17920 pretend we didn't find a type at all, the complex target type we
17921 create will then be nameless. */
17922 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17925 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17926 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17929 /* Find a representation of a given base type and install
17930 it in the TYPE field of the die. */
17932 static struct type
*
17933 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17935 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17937 struct attribute
*attr
;
17938 int encoding
= 0, bits
= 0;
17942 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17943 if (attr
!= nullptr)
17944 encoding
= DW_UNSND (attr
);
17945 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17946 if (attr
!= nullptr)
17947 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17948 name
= dwarf2_name (die
, cu
);
17950 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17952 arch
= objfile
->arch ();
17953 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17955 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17958 int endianity
= DW_UNSND (attr
);
17963 byte_order
= BFD_ENDIAN_BIG
;
17965 case DW_END_little
:
17966 byte_order
= BFD_ENDIAN_LITTLE
;
17969 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17976 case DW_ATE_address
:
17977 /* Turn DW_ATE_address into a void * pointer. */
17978 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17979 type
= init_pointer_type (objfile
, bits
, name
, type
);
17981 case DW_ATE_boolean
:
17982 type
= init_boolean_type (objfile
, bits
, 1, name
);
17984 case DW_ATE_complex_float
:
17985 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17987 if (type
->code () == TYPE_CODE_ERROR
)
17989 if (name
== nullptr)
17991 struct obstack
*obstack
17992 = &cu
->per_objfile
->objfile
->objfile_obstack
;
17993 name
= obconcat (obstack
, "_Complex ", type
->name (),
17996 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17999 type
= init_complex_type (name
, type
);
18001 case DW_ATE_decimal_float
:
18002 type
= init_decfloat_type (objfile
, bits
, name
);
18005 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18007 case DW_ATE_signed
:
18008 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18010 case DW_ATE_unsigned
:
18011 if (cu
->language
== language_fortran
18013 && startswith (name
, "character("))
18014 type
= init_character_type (objfile
, bits
, 1, name
);
18016 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18018 case DW_ATE_signed_char
:
18019 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18020 || cu
->language
== language_pascal
18021 || cu
->language
== language_fortran
)
18022 type
= init_character_type (objfile
, bits
, 0, name
);
18024 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18026 case DW_ATE_unsigned_char
:
18027 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18028 || cu
->language
== language_pascal
18029 || cu
->language
== language_fortran
18030 || cu
->language
== language_rust
)
18031 type
= init_character_type (objfile
, bits
, 1, name
);
18033 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18038 type
= builtin_type (arch
)->builtin_char16
;
18039 else if (bits
== 32)
18040 type
= builtin_type (arch
)->builtin_char32
;
18043 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18045 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18047 return set_die_type (die
, type
, cu
);
18052 complaint (_("unsupported DW_AT_encoding: '%s'"),
18053 dwarf_type_encoding_name (encoding
));
18054 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18058 if (name
&& strcmp (name
, "char") == 0)
18059 type
->set_has_no_signedness (true);
18061 maybe_set_alignment (cu
, die
, type
);
18063 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18065 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18067 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18068 if (attr
!= nullptr && DW_UNSND (attr
) <= 8 * TYPE_LENGTH (type
))
18070 unsigned real_bit_size
= DW_UNSND (attr
);
18071 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18072 /* Only use the attributes if they make sense together. */
18073 if (attr
== nullptr
18074 || DW_UNSND (attr
) + real_bit_size
<= 8 * TYPE_LENGTH (type
))
18076 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18078 if (attr
!= nullptr)
18079 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18085 return set_die_type (die
, type
, cu
);
18088 /* Parse dwarf attribute if it's a block, reference or constant and put the
18089 resulting value of the attribute into struct bound_prop.
18090 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18093 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18094 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18095 struct type
*default_type
)
18097 struct dwarf2_property_baton
*baton
;
18098 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18099 struct objfile
*objfile
= per_objfile
->objfile
;
18100 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18102 gdb_assert (default_type
!= NULL
);
18104 if (attr
== NULL
|| prop
== NULL
)
18107 if (attr
->form_is_block ())
18109 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18110 baton
->property_type
= default_type
;
18111 baton
->locexpr
.per_cu
= cu
->per_cu
;
18112 baton
->locexpr
.per_objfile
= per_objfile
;
18114 struct dwarf_block
*block
= attr
->as_block ();
18115 baton
->locexpr
.size
= block
->size
;
18116 baton
->locexpr
.data
= block
->data
;
18117 switch (attr
->name
)
18119 case DW_AT_string_length
:
18120 baton
->locexpr
.is_reference
= true;
18123 baton
->locexpr
.is_reference
= false;
18127 prop
->set_locexpr (baton
);
18128 gdb_assert (prop
->baton () != NULL
);
18130 else if (attr
->form_is_ref ())
18132 struct dwarf2_cu
*target_cu
= cu
;
18133 struct die_info
*target_die
;
18134 struct attribute
*target_attr
;
18136 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18137 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18138 if (target_attr
== NULL
)
18139 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18141 if (target_attr
== NULL
)
18144 switch (target_attr
->name
)
18146 case DW_AT_location
:
18147 if (target_attr
->form_is_section_offset ())
18149 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18150 baton
->property_type
= die_type (target_die
, target_cu
);
18151 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18152 prop
->set_loclist (baton
);
18153 gdb_assert (prop
->baton () != NULL
);
18155 else if (target_attr
->form_is_block ())
18157 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18158 baton
->property_type
= die_type (target_die
, target_cu
);
18159 baton
->locexpr
.per_cu
= cu
->per_cu
;
18160 baton
->locexpr
.per_objfile
= per_objfile
;
18161 struct dwarf_block
*block
= target_attr
->as_block ();
18162 baton
->locexpr
.size
= block
->size
;
18163 baton
->locexpr
.data
= block
->data
;
18164 baton
->locexpr
.is_reference
= true;
18165 prop
->set_locexpr (baton
);
18166 gdb_assert (prop
->baton () != NULL
);
18170 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18171 "dynamic property");
18175 case DW_AT_data_member_location
:
18179 if (!handle_data_member_location (target_die
, target_cu
,
18183 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18184 baton
->property_type
= read_type_die (target_die
->parent
,
18186 baton
->offset_info
.offset
= offset
;
18187 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18188 prop
->set_addr_offset (baton
);
18193 else if (attr
->form_is_constant ())
18194 prop
->set_const_val (attr
->constant_value (0));
18197 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18198 dwarf2_name (die
, cu
));
18208 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18210 struct type
*int_type
;
18212 /* Helper macro to examine the various builtin types. */
18213 #define TRY_TYPE(F) \
18214 int_type = (unsigned_p \
18215 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18216 : objfile_type (objfile)->builtin_ ## F); \
18217 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18224 TRY_TYPE (long_long
);
18228 gdb_assert_not_reached ("unable to find suitable integer type");
18234 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18236 int addr_size
= this->per_cu
->addr_size ();
18237 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18240 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18241 present (which is valid) then compute the default type based on the
18242 compilation units address size. */
18244 static struct type
*
18245 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18247 struct type
*index_type
= die_type (die
, cu
);
18249 /* Dwarf-2 specifications explicitly allows to create subrange types
18250 without specifying a base type.
18251 In that case, the base type must be set to the type of
18252 the lower bound, upper bound or count, in that order, if any of these
18253 three attributes references an object that has a type.
18254 If no base type is found, the Dwarf-2 specifications say that
18255 a signed integer type of size equal to the size of an address should
18257 For the following C code: `extern char gdb_int [];'
18258 GCC produces an empty range DIE.
18259 FIXME: muller/2010-05-28: Possible references to object for low bound,
18260 high bound or count are not yet handled by this code. */
18261 if (index_type
->code () == TYPE_CODE_VOID
)
18262 index_type
= cu
->addr_sized_int_type (false);
18267 /* Read the given DW_AT_subrange DIE. */
18269 static struct type
*
18270 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18272 struct type
*base_type
, *orig_base_type
;
18273 struct type
*range_type
;
18274 struct attribute
*attr
;
18275 struct dynamic_prop low
, high
;
18276 int low_default_is_valid
;
18277 int high_bound_is_count
= 0;
18279 ULONGEST negative_mask
;
18281 orig_base_type
= read_subrange_index_type (die
, cu
);
18283 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18284 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18285 creating the range type, but we use the result of check_typedef
18286 when examining properties of the type. */
18287 base_type
= check_typedef (orig_base_type
);
18289 /* The die_type call above may have already set the type for this DIE. */
18290 range_type
= get_die_type (die
, cu
);
18294 high
.set_const_val (0);
18296 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18297 omitting DW_AT_lower_bound. */
18298 switch (cu
->language
)
18301 case language_cplus
:
18302 low
.set_const_val (0);
18303 low_default_is_valid
= 1;
18305 case language_fortran
:
18306 low
.set_const_val (1);
18307 low_default_is_valid
= 1;
18310 case language_objc
:
18311 case language_rust
:
18312 low
.set_const_val (0);
18313 low_default_is_valid
= (cu
->header
.version
>= 4);
18317 case language_pascal
:
18318 low
.set_const_val (1);
18319 low_default_is_valid
= (cu
->header
.version
>= 4);
18322 low
.set_const_val (0);
18323 low_default_is_valid
= 0;
18327 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18328 if (attr
!= nullptr)
18329 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18330 else if (!low_default_is_valid
)
18331 complaint (_("Missing DW_AT_lower_bound "
18332 "- DIE at %s [in module %s]"),
18333 sect_offset_str (die
->sect_off
),
18334 objfile_name (cu
->per_objfile
->objfile
));
18336 struct attribute
*attr_ub
, *attr_count
;
18337 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18338 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18340 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18341 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18343 /* If bounds are constant do the final calculation here. */
18344 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18345 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18347 high_bound_is_count
= 1;
18351 if (attr_ub
!= NULL
)
18352 complaint (_("Unresolved DW_AT_upper_bound "
18353 "- DIE at %s [in module %s]"),
18354 sect_offset_str (die
->sect_off
),
18355 objfile_name (cu
->per_objfile
->objfile
));
18356 if (attr_count
!= NULL
)
18357 complaint (_("Unresolved DW_AT_count "
18358 "- DIE at %s [in module %s]"),
18359 sect_offset_str (die
->sect_off
),
18360 objfile_name (cu
->per_objfile
->objfile
));
18365 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18366 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18367 bias
= bias_attr
->constant_value (0);
18369 /* Normally, the DWARF producers are expected to use a signed
18370 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18371 But this is unfortunately not always the case, as witnessed
18372 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18373 is used instead. To work around that ambiguity, we treat
18374 the bounds as signed, and thus sign-extend their values, when
18375 the base type is signed. */
18377 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18378 if (low
.kind () == PROP_CONST
18379 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18380 low
.set_const_val (low
.const_val () | negative_mask
);
18381 if (high
.kind () == PROP_CONST
18382 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18383 high
.set_const_val (high
.const_val () | negative_mask
);
18385 /* Check for bit and byte strides. */
18386 struct dynamic_prop byte_stride_prop
;
18387 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18388 if (attr_byte_stride
!= nullptr)
18390 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18391 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18395 struct dynamic_prop bit_stride_prop
;
18396 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18397 if (attr_bit_stride
!= nullptr)
18399 /* It only makes sense to have either a bit or byte stride. */
18400 if (attr_byte_stride
!= nullptr)
18402 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18403 "- DIE at %s [in module %s]"),
18404 sect_offset_str (die
->sect_off
),
18405 objfile_name (cu
->per_objfile
->objfile
));
18406 attr_bit_stride
= nullptr;
18410 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18411 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18416 if (attr_byte_stride
!= nullptr
18417 || attr_bit_stride
!= nullptr)
18419 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18420 struct dynamic_prop
*stride
18421 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18424 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18425 &high
, bias
, stride
, byte_stride_p
);
18428 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18430 if (high_bound_is_count
)
18431 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18433 /* Ada expects an empty array on no boundary attributes. */
18434 if (attr
== NULL
&& cu
->language
!= language_ada
)
18435 range_type
->bounds ()->high
.set_undefined ();
18437 name
= dwarf2_name (die
, cu
);
18439 range_type
->set_name (name
);
18441 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18442 if (attr
!= nullptr)
18443 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18445 maybe_set_alignment (cu
, die
, range_type
);
18447 set_die_type (die
, range_type
, cu
);
18449 /* set_die_type should be already done. */
18450 set_descriptive_type (range_type
, die
, cu
);
18455 static struct type
*
18456 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18460 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18461 type
->set_name (dwarf2_name (die
, cu
));
18463 /* In Ada, an unspecified type is typically used when the description
18464 of the type is deferred to a different unit. When encountering
18465 such a type, we treat it as a stub, and try to resolve it later on,
18467 if (cu
->language
== language_ada
)
18468 type
->set_is_stub (true);
18470 return set_die_type (die
, type
, cu
);
18473 /* Read a single die and all its descendents. Set the die's sibling
18474 field to NULL; set other fields in the die correctly, and set all
18475 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18476 location of the info_ptr after reading all of those dies. PARENT
18477 is the parent of the die in question. */
18479 static struct die_info
*
18480 read_die_and_children (const struct die_reader_specs
*reader
,
18481 const gdb_byte
*info_ptr
,
18482 const gdb_byte
**new_info_ptr
,
18483 struct die_info
*parent
)
18485 struct die_info
*die
;
18486 const gdb_byte
*cur_ptr
;
18488 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18491 *new_info_ptr
= cur_ptr
;
18494 store_in_ref_table (die
, reader
->cu
);
18496 if (die
->has_children
)
18497 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18501 *new_info_ptr
= cur_ptr
;
18504 die
->sibling
= NULL
;
18505 die
->parent
= parent
;
18509 /* Read a die, all of its descendents, and all of its siblings; set
18510 all of the fields of all of the dies correctly. Arguments are as
18511 in read_die_and_children. */
18513 static struct die_info
*
18514 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18515 const gdb_byte
*info_ptr
,
18516 const gdb_byte
**new_info_ptr
,
18517 struct die_info
*parent
)
18519 struct die_info
*first_die
, *last_sibling
;
18520 const gdb_byte
*cur_ptr
;
18522 cur_ptr
= info_ptr
;
18523 first_die
= last_sibling
= NULL
;
18527 struct die_info
*die
18528 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18532 *new_info_ptr
= cur_ptr
;
18539 last_sibling
->sibling
= die
;
18541 last_sibling
= die
;
18545 /* Read a die, all of its descendents, and all of its siblings; set
18546 all of the fields of all of the dies correctly. Arguments are as
18547 in read_die_and_children.
18548 This the main entry point for reading a DIE and all its children. */
18550 static struct die_info
*
18551 read_die_and_siblings (const struct die_reader_specs
*reader
,
18552 const gdb_byte
*info_ptr
,
18553 const gdb_byte
**new_info_ptr
,
18554 struct die_info
*parent
)
18556 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18557 new_info_ptr
, parent
);
18559 if (dwarf_die_debug
)
18561 fprintf_unfiltered (gdb_stdlog
,
18562 "Read die from %s@0x%x of %s:\n",
18563 reader
->die_section
->get_name (),
18564 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18565 bfd_get_filename (reader
->abfd
));
18566 dump_die (die
, dwarf_die_debug
);
18572 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18574 The caller is responsible for filling in the extra attributes
18575 and updating (*DIEP)->num_attrs.
18576 Set DIEP to point to a newly allocated die with its information,
18577 except for its child, sibling, and parent fields. */
18579 static const gdb_byte
*
18580 read_full_die_1 (const struct die_reader_specs
*reader
,
18581 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18582 int num_extra_attrs
)
18584 unsigned int abbrev_number
, bytes_read
, i
;
18585 struct abbrev_info
*abbrev
;
18586 struct die_info
*die
;
18587 struct dwarf2_cu
*cu
= reader
->cu
;
18588 bfd
*abfd
= reader
->abfd
;
18590 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18591 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18592 info_ptr
+= bytes_read
;
18593 if (!abbrev_number
)
18599 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18601 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18603 bfd_get_filename (abfd
));
18605 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18606 die
->sect_off
= sect_off
;
18607 die
->tag
= abbrev
->tag
;
18608 die
->abbrev
= abbrev_number
;
18609 die
->has_children
= abbrev
->has_children
;
18611 /* Make the result usable.
18612 The caller needs to update num_attrs after adding the extra
18614 die
->num_attrs
= abbrev
->num_attrs
;
18616 std::vector
<int> indexes_that_need_reprocess
;
18617 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18619 bool need_reprocess
;
18621 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18622 info_ptr
, &need_reprocess
);
18623 if (need_reprocess
)
18624 indexes_that_need_reprocess
.push_back (i
);
18627 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18628 if (attr
!= nullptr)
18629 cu
->str_offsets_base
= DW_UNSND (attr
);
18631 attr
= die
->attr (DW_AT_loclists_base
);
18632 if (attr
!= nullptr)
18633 cu
->loclist_base
= DW_UNSND (attr
);
18635 auto maybe_addr_base
= die
->addr_base ();
18636 if (maybe_addr_base
.has_value ())
18637 cu
->addr_base
= *maybe_addr_base
;
18639 attr
= die
->attr (DW_AT_rnglists_base
);
18640 if (attr
!= nullptr)
18641 cu
->ranges_base
= DW_UNSND (attr
);
18643 for (int index
: indexes_that_need_reprocess
)
18644 read_attribute_reprocess (reader
, &die
->attrs
[index
], die
->tag
);
18649 /* Read a die and all its attributes.
18650 Set DIEP to point to a newly allocated die with its information,
18651 except for its child, sibling, and parent fields. */
18653 static const gdb_byte
*
18654 read_full_die (const struct die_reader_specs
*reader
,
18655 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18657 const gdb_byte
*result
;
18659 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18661 if (dwarf_die_debug
)
18663 fprintf_unfiltered (gdb_stdlog
,
18664 "Read die from %s@0x%x of %s:\n",
18665 reader
->die_section
->get_name (),
18666 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18667 bfd_get_filename (reader
->abfd
));
18668 dump_die (*diep
, dwarf_die_debug
);
18675 /* Returns nonzero if TAG represents a type that we might generate a partial
18679 is_type_tag_for_partial (int tag
)
18684 /* Some types that would be reasonable to generate partial symbols for,
18685 that we don't at present. */
18686 case DW_TAG_array_type
:
18687 case DW_TAG_file_type
:
18688 case DW_TAG_ptr_to_member_type
:
18689 case DW_TAG_set_type
:
18690 case DW_TAG_string_type
:
18691 case DW_TAG_subroutine_type
:
18693 case DW_TAG_base_type
:
18694 case DW_TAG_class_type
:
18695 case DW_TAG_interface_type
:
18696 case DW_TAG_enumeration_type
:
18697 case DW_TAG_structure_type
:
18698 case DW_TAG_subrange_type
:
18699 case DW_TAG_typedef
:
18700 case DW_TAG_union_type
:
18707 /* Load all DIEs that are interesting for partial symbols into memory. */
18709 static struct partial_die_info
*
18710 load_partial_dies (const struct die_reader_specs
*reader
,
18711 const gdb_byte
*info_ptr
, int building_psymtab
)
18713 struct dwarf2_cu
*cu
= reader
->cu
;
18714 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18715 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18716 unsigned int bytes_read
;
18717 unsigned int load_all
= 0;
18718 int nesting_level
= 1;
18723 gdb_assert (cu
->per_cu
!= NULL
);
18724 if (cu
->per_cu
->load_all_dies
)
18728 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18732 &cu
->comp_unit_obstack
,
18733 hashtab_obstack_allocate
,
18734 dummy_obstack_deallocate
);
18738 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18740 /* A NULL abbrev means the end of a series of children. */
18741 if (abbrev
== NULL
)
18743 if (--nesting_level
== 0)
18746 info_ptr
+= bytes_read
;
18747 last_die
= parent_die
;
18748 parent_die
= parent_die
->die_parent
;
18752 /* Check for template arguments. We never save these; if
18753 they're seen, we just mark the parent, and go on our way. */
18754 if (parent_die
!= NULL
18755 && cu
->language
== language_cplus
18756 && (abbrev
->tag
== DW_TAG_template_type_param
18757 || abbrev
->tag
== DW_TAG_template_value_param
))
18759 parent_die
->has_template_arguments
= 1;
18763 /* We don't need a partial DIE for the template argument. */
18764 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18769 /* We only recurse into c++ subprograms looking for template arguments.
18770 Skip their other children. */
18772 && cu
->language
== language_cplus
18773 && parent_die
!= NULL
18774 && parent_die
->tag
== DW_TAG_subprogram
18775 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18777 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18781 /* Check whether this DIE is interesting enough to save. Normally
18782 we would not be interested in members here, but there may be
18783 later variables referencing them via DW_AT_specification (for
18784 static members). */
18786 && !is_type_tag_for_partial (abbrev
->tag
)
18787 && abbrev
->tag
!= DW_TAG_constant
18788 && abbrev
->tag
!= DW_TAG_enumerator
18789 && abbrev
->tag
!= DW_TAG_subprogram
18790 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18791 && abbrev
->tag
!= DW_TAG_lexical_block
18792 && abbrev
->tag
!= DW_TAG_variable
18793 && abbrev
->tag
!= DW_TAG_namespace
18794 && abbrev
->tag
!= DW_TAG_module
18795 && abbrev
->tag
!= DW_TAG_member
18796 && abbrev
->tag
!= DW_TAG_imported_unit
18797 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18799 /* Otherwise we skip to the next sibling, if any. */
18800 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18804 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18807 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18809 /* This two-pass algorithm for processing partial symbols has a
18810 high cost in cache pressure. Thus, handle some simple cases
18811 here which cover the majority of C partial symbols. DIEs
18812 which neither have specification tags in them, nor could have
18813 specification tags elsewhere pointing at them, can simply be
18814 processed and discarded.
18816 This segment is also optional; scan_partial_symbols and
18817 add_partial_symbol will handle these DIEs if we chain
18818 them in normally. When compilers which do not emit large
18819 quantities of duplicate debug information are more common,
18820 this code can probably be removed. */
18822 /* Any complete simple types at the top level (pretty much all
18823 of them, for a language without namespaces), can be processed
18825 if (parent_die
== NULL
18826 && pdi
.has_specification
== 0
18827 && pdi
.is_declaration
== 0
18828 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18829 || pdi
.tag
== DW_TAG_base_type
18830 || pdi
.tag
== DW_TAG_subrange_type
))
18832 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18833 add_partial_symbol (&pdi
, cu
);
18835 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18839 /* The exception for DW_TAG_typedef with has_children above is
18840 a workaround of GCC PR debug/47510. In the case of this complaint
18841 type_name_or_error will error on such types later.
18843 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18844 it could not find the child DIEs referenced later, this is checked
18845 above. In correct DWARF DW_TAG_typedef should have no children. */
18847 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18848 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18849 "- DIE at %s [in module %s]"),
18850 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18852 /* If we're at the second level, and we're an enumerator, and
18853 our parent has no specification (meaning possibly lives in a
18854 namespace elsewhere), then we can add the partial symbol now
18855 instead of queueing it. */
18856 if (pdi
.tag
== DW_TAG_enumerator
18857 && parent_die
!= NULL
18858 && parent_die
->die_parent
== NULL
18859 && parent_die
->tag
== DW_TAG_enumeration_type
18860 && parent_die
->has_specification
== 0)
18862 if (pdi
.raw_name
== NULL
)
18863 complaint (_("malformed enumerator DIE ignored"));
18864 else if (building_psymtab
)
18865 add_partial_symbol (&pdi
, cu
);
18867 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18871 struct partial_die_info
*part_die
18872 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18874 /* We'll save this DIE so link it in. */
18875 part_die
->die_parent
= parent_die
;
18876 part_die
->die_sibling
= NULL
;
18877 part_die
->die_child
= NULL
;
18879 if (last_die
&& last_die
== parent_die
)
18880 last_die
->die_child
= part_die
;
18882 last_die
->die_sibling
= part_die
;
18884 last_die
= part_die
;
18886 if (first_die
== NULL
)
18887 first_die
= part_die
;
18889 /* Maybe add the DIE to the hash table. Not all DIEs that we
18890 find interesting need to be in the hash table, because we
18891 also have the parent/sibling/child chains; only those that we
18892 might refer to by offset later during partial symbol reading.
18894 For now this means things that might have be the target of a
18895 DW_AT_specification, DW_AT_abstract_origin, or
18896 DW_AT_extension. DW_AT_extension will refer only to
18897 namespaces; DW_AT_abstract_origin refers to functions (and
18898 many things under the function DIE, but we do not recurse
18899 into function DIEs during partial symbol reading) and
18900 possibly variables as well; DW_AT_specification refers to
18901 declarations. Declarations ought to have the DW_AT_declaration
18902 flag. It happens that GCC forgets to put it in sometimes, but
18903 only for functions, not for types.
18905 Adding more things than necessary to the hash table is harmless
18906 except for the performance cost. Adding too few will result in
18907 wasted time in find_partial_die, when we reread the compilation
18908 unit with load_all_dies set. */
18911 || abbrev
->tag
== DW_TAG_constant
18912 || abbrev
->tag
== DW_TAG_subprogram
18913 || abbrev
->tag
== DW_TAG_variable
18914 || abbrev
->tag
== DW_TAG_namespace
18915 || part_die
->is_declaration
)
18919 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18920 to_underlying (part_die
->sect_off
),
18925 /* For some DIEs we want to follow their children (if any). For C
18926 we have no reason to follow the children of structures; for other
18927 languages we have to, so that we can get at method physnames
18928 to infer fully qualified class names, for DW_AT_specification,
18929 and for C++ template arguments. For C++, we also look one level
18930 inside functions to find template arguments (if the name of the
18931 function does not already contain the template arguments).
18933 For Ada and Fortran, we need to scan the children of subprograms
18934 and lexical blocks as well because these languages allow the
18935 definition of nested entities that could be interesting for the
18936 debugger, such as nested subprograms for instance. */
18937 if (last_die
->has_children
18939 || last_die
->tag
== DW_TAG_namespace
18940 || last_die
->tag
== DW_TAG_module
18941 || last_die
->tag
== DW_TAG_enumeration_type
18942 || (cu
->language
== language_cplus
18943 && last_die
->tag
== DW_TAG_subprogram
18944 && (last_die
->raw_name
== NULL
18945 || strchr (last_die
->raw_name
, '<') == NULL
))
18946 || (cu
->language
!= language_c
18947 && (last_die
->tag
== DW_TAG_class_type
18948 || last_die
->tag
== DW_TAG_interface_type
18949 || last_die
->tag
== DW_TAG_structure_type
18950 || last_die
->tag
== DW_TAG_union_type
))
18951 || ((cu
->language
== language_ada
18952 || cu
->language
== language_fortran
)
18953 && (last_die
->tag
== DW_TAG_subprogram
18954 || last_die
->tag
== DW_TAG_lexical_block
))))
18957 parent_die
= last_die
;
18961 /* Otherwise we skip to the next sibling, if any. */
18962 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18964 /* Back to the top, do it again. */
18968 partial_die_info::partial_die_info (sect_offset sect_off_
,
18969 struct abbrev_info
*abbrev
)
18970 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18974 /* See class definition. */
18977 partial_die_info::name (dwarf2_cu
*cu
)
18979 if (!canonical_name
&& raw_name
!= nullptr)
18981 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18982 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
18983 canonical_name
= 1;
18989 /* Read a minimal amount of information into the minimal die structure.
18990 INFO_PTR should point just after the initial uleb128 of a DIE. */
18993 partial_die_info::read (const struct die_reader_specs
*reader
,
18994 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18996 struct dwarf2_cu
*cu
= reader
->cu
;
18997 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18999 int has_low_pc_attr
= 0;
19000 int has_high_pc_attr
= 0;
19001 int high_pc_relative
= 0;
19003 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19006 bool need_reprocess
;
19007 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
19008 info_ptr
, &need_reprocess
);
19009 /* String and address offsets that need to do the reprocessing have
19010 already been read at this point, so there is no need to wait until
19011 the loop terminates to do the reprocessing. */
19012 if (need_reprocess
)
19013 read_attribute_reprocess (reader
, &attr
, tag
);
19014 /* Store the data if it is of an attribute we want to keep in a
19015 partial symbol table. */
19021 case DW_TAG_compile_unit
:
19022 case DW_TAG_partial_unit
:
19023 case DW_TAG_type_unit
:
19024 /* Compilation units have a DW_AT_name that is a filename, not
19025 a source language identifier. */
19026 case DW_TAG_enumeration_type
:
19027 case DW_TAG_enumerator
:
19028 /* These tags always have simple identifiers already; no need
19029 to canonicalize them. */
19030 canonical_name
= 1;
19031 raw_name
= attr
.as_string ();
19034 canonical_name
= 0;
19035 raw_name
= attr
.as_string ();
19039 case DW_AT_linkage_name
:
19040 case DW_AT_MIPS_linkage_name
:
19041 /* Note that both forms of linkage name might appear. We
19042 assume they will be the same, and we only store the last
19044 linkage_name
= attr
.as_string ();
19047 has_low_pc_attr
= 1;
19048 lowpc
= attr
.as_address ();
19050 case DW_AT_high_pc
:
19051 has_high_pc_attr
= 1;
19052 highpc
= attr
.as_address ();
19053 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19054 high_pc_relative
= 1;
19056 case DW_AT_location
:
19057 /* Support the .debug_loc offsets. */
19058 if (attr
.form_is_block ())
19060 d
.locdesc
= attr
.as_block ();
19062 else if (attr
.form_is_section_offset ())
19064 dwarf2_complex_location_expr_complaint ();
19068 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19069 "partial symbol information");
19072 case DW_AT_external
:
19073 is_external
= DW_UNSND (&attr
);
19075 case DW_AT_declaration
:
19076 is_declaration
= DW_UNSND (&attr
);
19081 case DW_AT_abstract_origin
:
19082 case DW_AT_specification
:
19083 case DW_AT_extension
:
19084 has_specification
= 1;
19085 spec_offset
= attr
.get_ref_die_offset ();
19086 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19087 || cu
->per_cu
->is_dwz
);
19089 case DW_AT_sibling
:
19090 /* Ignore absolute siblings, they might point outside of
19091 the current compile unit. */
19092 if (attr
.form
== DW_FORM_ref_addr
)
19093 complaint (_("ignoring absolute DW_AT_sibling"));
19096 const gdb_byte
*buffer
= reader
->buffer
;
19097 sect_offset off
= attr
.get_ref_die_offset ();
19098 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19100 if (sibling_ptr
< info_ptr
)
19101 complaint (_("DW_AT_sibling points backwards"));
19102 else if (sibling_ptr
> reader
->buffer_end
)
19103 reader
->die_section
->overflow_complaint ();
19105 sibling
= sibling_ptr
;
19108 case DW_AT_byte_size
:
19111 case DW_AT_const_value
:
19112 has_const_value
= 1;
19114 case DW_AT_calling_convention
:
19115 /* DWARF doesn't provide a way to identify a program's source-level
19116 entry point. DW_AT_calling_convention attributes are only meant
19117 to describe functions' calling conventions.
19119 However, because it's a necessary piece of information in
19120 Fortran, and before DWARF 4 DW_CC_program was the only
19121 piece of debugging information whose definition refers to
19122 a 'main program' at all, several compilers marked Fortran
19123 main programs with DW_CC_program --- even when those
19124 functions use the standard calling conventions.
19126 Although DWARF now specifies a way to provide this
19127 information, we support this practice for backward
19129 if (DW_UNSND (&attr
) == DW_CC_program
19130 && cu
->language
== language_fortran
)
19131 main_subprogram
= 1;
19134 if (DW_UNSND (&attr
) == DW_INL_inlined
19135 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19136 may_be_inlined
= 1;
19140 if (tag
== DW_TAG_imported_unit
)
19142 d
.sect_off
= attr
.get_ref_die_offset ();
19143 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19144 || cu
->per_cu
->is_dwz
);
19148 case DW_AT_main_subprogram
:
19149 main_subprogram
= DW_UNSND (&attr
);
19154 /* DW_AT_rnglists_base does not apply to DIEs from the DWO
19155 skeleton. We take advantage of the fact the DW_AT_ranges
19156 does not appear in DW_TAG_compile_unit of DWO files.
19158 Attributes of the form DW_FORM_rnglistx have already had
19159 their value changed by read_rnglist_index and already
19160 include DW_AT_rnglists_base, so don't need to add the ranges
19162 int need_ranges_base
= (tag
!= DW_TAG_compile_unit
19163 && attr
.form
!= DW_FORM_rnglistx
);
19164 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19165 + (need_ranges_base
19169 /* Value of the DW_AT_ranges attribute is the offset in the
19170 .debug_ranges section. */
19171 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19182 /* For Ada, if both the name and the linkage name appear, we prefer
19183 the latter. This lets "catch exception" work better, regardless
19184 of the order in which the name and linkage name were emitted.
19185 Really, though, this is just a workaround for the fact that gdb
19186 doesn't store both the name and the linkage name. */
19187 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19188 raw_name
= linkage_name
;
19190 if (high_pc_relative
)
19193 if (has_low_pc_attr
&& has_high_pc_attr
)
19195 /* When using the GNU linker, .gnu.linkonce. sections are used to
19196 eliminate duplicate copies of functions and vtables and such.
19197 The linker will arbitrarily choose one and discard the others.
19198 The AT_*_pc values for such functions refer to local labels in
19199 these sections. If the section from that file was discarded, the
19200 labels are not in the output, so the relocs get a value of 0.
19201 If this is a discarded function, mark the pc bounds as invalid,
19202 so that GDB will ignore it. */
19203 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19205 struct objfile
*objfile
= per_objfile
->objfile
;
19206 struct gdbarch
*gdbarch
= objfile
->arch ();
19208 complaint (_("DW_AT_low_pc %s is zero "
19209 "for DIE at %s [in module %s]"),
19210 paddress (gdbarch
, lowpc
),
19211 sect_offset_str (sect_off
),
19212 objfile_name (objfile
));
19214 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19215 else if (lowpc
>= highpc
)
19217 struct objfile
*objfile
= per_objfile
->objfile
;
19218 struct gdbarch
*gdbarch
= objfile
->arch ();
19220 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19221 "for DIE at %s [in module %s]"),
19222 paddress (gdbarch
, lowpc
),
19223 paddress (gdbarch
, highpc
),
19224 sect_offset_str (sect_off
),
19225 objfile_name (objfile
));
19234 /* Find a cached partial DIE at OFFSET in CU. */
19236 struct partial_die_info
*
19237 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19239 struct partial_die_info
*lookup_die
= NULL
;
19240 struct partial_die_info
part_die (sect_off
);
19242 lookup_die
= ((struct partial_die_info
*)
19243 htab_find_with_hash (partial_dies
, &part_die
,
19244 to_underlying (sect_off
)));
19249 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19250 except in the case of .debug_types DIEs which do not reference
19251 outside their CU (they do however referencing other types via
19252 DW_FORM_ref_sig8). */
19254 static const struct cu_partial_die_info
19255 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19257 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19258 struct objfile
*objfile
= per_objfile
->objfile
;
19259 struct partial_die_info
*pd
= NULL
;
19261 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19262 && cu
->header
.offset_in_cu_p (sect_off
))
19264 pd
= cu
->find_partial_die (sect_off
);
19267 /* We missed recording what we needed.
19268 Load all dies and try again. */
19272 /* TUs don't reference other CUs/TUs (except via type signatures). */
19273 if (cu
->per_cu
->is_debug_types
)
19275 error (_("Dwarf Error: Type Unit at offset %s contains"
19276 " external reference to offset %s [in module %s].\n"),
19277 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19278 bfd_get_filename (objfile
->obfd
));
19280 dwarf2_per_cu_data
*per_cu
19281 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19284 cu
= per_objfile
->get_cu (per_cu
);
19285 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19286 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19288 cu
= per_objfile
->get_cu (per_cu
);
19291 pd
= cu
->find_partial_die (sect_off
);
19294 /* If we didn't find it, and not all dies have been loaded,
19295 load them all and try again. */
19297 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19299 cu
->per_cu
->load_all_dies
= 1;
19301 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19302 THIS_CU->cu may already be in use. So we can't just free it and
19303 replace its DIEs with the ones we read in. Instead, we leave those
19304 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19305 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19307 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19309 pd
= cu
->find_partial_die (sect_off
);
19313 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19314 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19318 /* See if we can figure out if the class lives in a namespace. We do
19319 this by looking for a member function; its demangled name will
19320 contain namespace info, if there is any. */
19323 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19324 struct dwarf2_cu
*cu
)
19326 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19327 what template types look like, because the demangler
19328 frequently doesn't give the same name as the debug info. We
19329 could fix this by only using the demangled name to get the
19330 prefix (but see comment in read_structure_type). */
19332 struct partial_die_info
*real_pdi
;
19333 struct partial_die_info
*child_pdi
;
19335 /* If this DIE (this DIE's specification, if any) has a parent, then
19336 we should not do this. We'll prepend the parent's fully qualified
19337 name when we create the partial symbol. */
19339 real_pdi
= struct_pdi
;
19340 while (real_pdi
->has_specification
)
19342 auto res
= find_partial_die (real_pdi
->spec_offset
,
19343 real_pdi
->spec_is_dwz
, cu
);
19344 real_pdi
= res
.pdi
;
19348 if (real_pdi
->die_parent
!= NULL
)
19351 for (child_pdi
= struct_pdi
->die_child
;
19353 child_pdi
= child_pdi
->die_sibling
)
19355 if (child_pdi
->tag
== DW_TAG_subprogram
19356 && child_pdi
->linkage_name
!= NULL
)
19358 gdb::unique_xmalloc_ptr
<char> actual_class_name
19359 (cu
->language_defn
->class_name_from_physname
19360 (child_pdi
->linkage_name
));
19361 if (actual_class_name
!= NULL
)
19363 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19364 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19365 struct_pdi
->canonical_name
= 1;
19372 /* Return true if a DIE with TAG may have the DW_AT_const_value
19376 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19380 case DW_TAG_constant
:
19381 case DW_TAG_enumerator
:
19382 case DW_TAG_formal_parameter
:
19383 case DW_TAG_template_value_param
:
19384 case DW_TAG_variable
:
19392 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19394 /* Once we've fixed up a die, there's no point in doing so again.
19395 This also avoids a memory leak if we were to call
19396 guess_partial_die_structure_name multiple times. */
19400 /* If we found a reference attribute and the DIE has no name, try
19401 to find a name in the referred to DIE. */
19403 if (raw_name
== NULL
&& has_specification
)
19405 struct partial_die_info
*spec_die
;
19407 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19408 spec_die
= res
.pdi
;
19411 spec_die
->fixup (cu
);
19413 if (spec_die
->raw_name
)
19415 raw_name
= spec_die
->raw_name
;
19416 canonical_name
= spec_die
->canonical_name
;
19418 /* Copy DW_AT_external attribute if it is set. */
19419 if (spec_die
->is_external
)
19420 is_external
= spec_die
->is_external
;
19424 if (!has_const_value
&& has_specification
19425 && can_have_DW_AT_const_value_p (tag
))
19427 struct partial_die_info
*spec_die
;
19429 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19430 spec_die
= res
.pdi
;
19433 spec_die
->fixup (cu
);
19435 if (spec_die
->has_const_value
)
19437 /* Copy DW_AT_const_value attribute if it is set. */
19438 has_const_value
= spec_die
->has_const_value
;
19442 /* Set default names for some unnamed DIEs. */
19444 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19446 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19447 canonical_name
= 1;
19450 /* If there is no parent die to provide a namespace, and there are
19451 children, see if we can determine the namespace from their linkage
19453 if (cu
->language
== language_cplus
19454 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19455 && die_parent
== NULL
19457 && (tag
== DW_TAG_class_type
19458 || tag
== DW_TAG_structure_type
19459 || tag
== DW_TAG_union_type
))
19460 guess_partial_die_structure_name (this, cu
);
19462 /* GCC might emit a nameless struct or union that has a linkage
19463 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19464 if (raw_name
== NULL
19465 && (tag
== DW_TAG_class_type
19466 || tag
== DW_TAG_interface_type
19467 || tag
== DW_TAG_structure_type
19468 || tag
== DW_TAG_union_type
)
19469 && linkage_name
!= NULL
)
19471 gdb::unique_xmalloc_ptr
<char> demangled
19472 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19473 if (demangled
!= nullptr)
19477 /* Strip any leading namespaces/classes, keep only the base name.
19478 DW_AT_name for named DIEs does not contain the prefixes. */
19479 base
= strrchr (demangled
.get (), ':');
19480 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19483 base
= demangled
.get ();
19485 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19486 raw_name
= objfile
->intern (base
);
19487 canonical_name
= 1;
19494 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19495 contents from the given SECTION in the HEADER. */
19497 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19498 struct dwarf2_section_info
*section
)
19500 unsigned int bytes_read
;
19501 bfd
*abfd
= section
->get_bfd_owner ();
19502 const gdb_byte
*info_ptr
= section
->buffer
;
19503 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19504 info_ptr
+= bytes_read
;
19505 header
->version
= read_2_bytes (abfd
, info_ptr
);
19507 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19509 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19511 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19514 /* Return the DW_AT_loclists_base value for the CU. */
19516 lookup_loclist_base (struct dwarf2_cu
*cu
)
19518 /* For the .dwo unit, the loclist_base points to the first offset following
19519 the header. The header consists of the following entities-
19520 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19522 2. version (2 bytes)
19523 3. address size (1 byte)
19524 4. segment selector size (1 byte)
19525 5. offset entry count (4 bytes)
19526 These sizes are derived as per the DWARFv5 standard. */
19527 if (cu
->dwo_unit
!= nullptr)
19529 if (cu
->header
.initial_length_size
== 4)
19530 return LOCLIST_HEADER_SIZE32
;
19531 return LOCLIST_HEADER_SIZE64
;
19533 return cu
->loclist_base
;
19536 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19537 array of offsets in the .debug_loclists section. */
19539 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19541 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19542 struct objfile
*objfile
= per_objfile
->objfile
;
19543 bfd
*abfd
= objfile
->obfd
;
19544 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19545 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19547 section
->read (objfile
);
19548 if (section
->buffer
== NULL
)
19549 complaint (_("DW_FORM_loclistx used without .debug_loclists "
19550 "section [in module %s]"), objfile_name (objfile
));
19551 struct loclists_rnglists_header header
;
19552 read_loclists_rnglists_header (&header
, section
);
19553 if (loclist_index
>= header
.offset_entry_count
)
19554 complaint (_("DW_FORM_loclistx pointing outside of "
19555 ".debug_loclists offset array [in module %s]"),
19556 objfile_name (objfile
));
19557 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
19559 complaint (_("DW_FORM_loclistx pointing outside of "
19560 ".debug_loclists section [in module %s]"),
19561 objfile_name (objfile
));
19562 const gdb_byte
*info_ptr
19563 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19565 if (cu
->header
.offset_size
== 4)
19566 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
19568 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
19571 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19572 array of offsets in the .debug_rnglists section. */
19574 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19577 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19578 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19579 bfd
*abfd
= objfile
->obfd
;
19580 ULONGEST rnglist_header_size
=
19581 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19582 : RNGLIST_HEADER_SIZE64
);
19583 ULONGEST rnglist_base
=
19584 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->ranges_base
;
19585 ULONGEST start_offset
=
19586 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19588 /* Get rnglists section. */
19589 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19591 /* Read the rnglists section content. */
19592 section
->read (objfile
);
19593 if (section
->buffer
== nullptr)
19594 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19596 objfile_name (objfile
));
19598 /* Verify the rnglist index is valid. */
19599 struct loclists_rnglists_header header
;
19600 read_loclists_rnglists_header (&header
, section
);
19601 if (rnglist_index
>= header
.offset_entry_count
)
19602 error (_("DW_FORM_rnglistx index pointing outside of "
19603 ".debug_rnglists offset array [in module %s]"),
19604 objfile_name (objfile
));
19606 /* Validate that the offset is within the section's range. */
19607 if (start_offset
>= section
->size
)
19608 error (_("DW_FORM_rnglistx pointing outside of "
19609 ".debug_rnglists section [in module %s]"),
19610 objfile_name (objfile
));
19612 /* Validate that reading won't go beyond the end of the section. */
19613 if (start_offset
+ cu
->header
.offset_size
> rnglist_base
+ section
->size
)
19614 error (_("Reading DW_FORM_rnglistx index beyond end of"
19615 ".debug_rnglists section [in module %s]"),
19616 objfile_name (objfile
));
19618 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19620 if (cu
->header
.offset_size
== 4)
19621 return read_4_bytes (abfd
, info_ptr
) + rnglist_base
;
19623 return read_8_bytes (abfd
, info_ptr
) + rnglist_base
;
19626 /* Process the attributes that had to be skipped in the first round. These
19627 attributes are the ones that need str_offsets_base or addr_base attributes.
19628 They could not have been processed in the first round, because at the time
19629 the values of str_offsets_base or addr_base may not have been known. */
19631 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19632 struct attribute
*attr
, dwarf_tag tag
)
19634 struct dwarf2_cu
*cu
= reader
->cu
;
19635 switch (attr
->form
)
19637 case DW_FORM_addrx
:
19638 case DW_FORM_GNU_addr_index
:
19639 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19641 case DW_FORM_loclistx
:
19642 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
19644 case DW_FORM_rnglistx
:
19645 DW_UNSND (attr
) = read_rnglist_index (cu
, DW_UNSND (attr
), tag
);
19648 case DW_FORM_strx1
:
19649 case DW_FORM_strx2
:
19650 case DW_FORM_strx3
:
19651 case DW_FORM_strx4
:
19652 case DW_FORM_GNU_str_index
:
19654 unsigned int str_index
= DW_UNSND (attr
);
19655 gdb_assert (!attr
->canonical_string_p ());
19656 if (reader
->dwo_file
!= NULL
)
19657 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19660 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19665 gdb_assert_not_reached (_("Unexpected DWARF form."));
19669 /* Read an attribute value described by an attribute form. */
19671 static const gdb_byte
*
19672 read_attribute_value (const struct die_reader_specs
*reader
,
19673 struct attribute
*attr
, unsigned form
,
19674 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19675 bool *need_reprocess
)
19677 struct dwarf2_cu
*cu
= reader
->cu
;
19678 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19679 struct objfile
*objfile
= per_objfile
->objfile
;
19680 bfd
*abfd
= reader
->abfd
;
19681 struct comp_unit_head
*cu_header
= &cu
->header
;
19682 unsigned int bytes_read
;
19683 struct dwarf_block
*blk
;
19684 *need_reprocess
= false;
19686 attr
->form
= (enum dwarf_form
) form
;
19689 case DW_FORM_ref_addr
:
19690 if (cu
->header
.version
== 2)
19691 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
19694 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
19696 info_ptr
+= bytes_read
;
19698 case DW_FORM_GNU_ref_alt
:
19699 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19700 info_ptr
+= bytes_read
;
19704 struct gdbarch
*gdbarch
= objfile
->arch ();
19705 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
19706 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19707 info_ptr
+= bytes_read
;
19710 case DW_FORM_block2
:
19711 blk
= dwarf_alloc_block (cu
);
19712 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19714 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19715 info_ptr
+= blk
->size
;
19716 attr
->set_block (blk
);
19718 case DW_FORM_block4
:
19719 blk
= dwarf_alloc_block (cu
);
19720 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19722 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19723 info_ptr
+= blk
->size
;
19724 attr
->set_block (blk
);
19726 case DW_FORM_data2
:
19727 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19730 case DW_FORM_data4
:
19731 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19734 case DW_FORM_data8
:
19735 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19738 case DW_FORM_data16
:
19739 blk
= dwarf_alloc_block (cu
);
19741 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19743 attr
->set_block (blk
);
19745 case DW_FORM_sec_offset
:
19746 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
19747 info_ptr
+= bytes_read
;
19749 case DW_FORM_loclistx
:
19751 *need_reprocess
= true;
19752 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19753 info_ptr
+= bytes_read
;
19756 case DW_FORM_string
:
19757 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
19759 info_ptr
+= bytes_read
;
19762 if (!cu
->per_cu
->is_dwz
)
19764 attr
->set_string_noncanonical
19765 (read_indirect_string (per_objfile
,
19766 abfd
, info_ptr
, cu_header
,
19768 info_ptr
+= bytes_read
;
19772 case DW_FORM_line_strp
:
19773 if (!cu
->per_cu
->is_dwz
)
19775 attr
->set_string_noncanonical
19776 (per_objfile
->read_line_string (info_ptr
, cu_header
,
19778 info_ptr
+= bytes_read
;
19782 case DW_FORM_GNU_strp_alt
:
19784 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
19785 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19788 attr
->set_string_noncanonical
19789 (dwz
->read_string (objfile
, str_offset
));
19790 info_ptr
+= bytes_read
;
19793 case DW_FORM_exprloc
:
19794 case DW_FORM_block
:
19795 blk
= dwarf_alloc_block (cu
);
19796 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19797 info_ptr
+= bytes_read
;
19798 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19799 info_ptr
+= blk
->size
;
19800 attr
->set_block (blk
);
19802 case DW_FORM_block1
:
19803 blk
= dwarf_alloc_block (cu
);
19804 blk
->size
= read_1_byte (abfd
, info_ptr
);
19806 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19807 info_ptr
+= blk
->size
;
19808 attr
->set_block (blk
);
19810 case DW_FORM_data1
:
19811 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19815 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19818 case DW_FORM_flag_present
:
19819 DW_UNSND (attr
) = 1;
19821 case DW_FORM_sdata
:
19822 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19823 info_ptr
+= bytes_read
;
19825 case DW_FORM_rnglistx
:
19826 *need_reprocess
= true;
19828 case DW_FORM_udata
:
19829 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19830 info_ptr
+= bytes_read
;
19833 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19834 + read_1_byte (abfd
, info_ptr
));
19838 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19839 + read_2_bytes (abfd
, info_ptr
));
19843 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19844 + read_4_bytes (abfd
, info_ptr
));
19848 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19849 + read_8_bytes (abfd
, info_ptr
));
19852 case DW_FORM_ref_sig8
:
19853 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19856 case DW_FORM_ref_udata
:
19857 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19858 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19859 info_ptr
+= bytes_read
;
19861 case DW_FORM_indirect
:
19862 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19863 info_ptr
+= bytes_read
;
19864 if (form
== DW_FORM_implicit_const
)
19866 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19867 info_ptr
+= bytes_read
;
19869 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19870 info_ptr
, need_reprocess
);
19872 case DW_FORM_implicit_const
:
19873 DW_SND (attr
) = implicit_const
;
19875 case DW_FORM_addrx
:
19876 case DW_FORM_GNU_addr_index
:
19877 *need_reprocess
= true;
19878 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19879 info_ptr
+= bytes_read
;
19882 case DW_FORM_strx1
:
19883 case DW_FORM_strx2
:
19884 case DW_FORM_strx3
:
19885 case DW_FORM_strx4
:
19886 case DW_FORM_GNU_str_index
:
19888 ULONGEST str_index
;
19889 if (form
== DW_FORM_strx1
)
19891 str_index
= read_1_byte (abfd
, info_ptr
);
19894 else if (form
== DW_FORM_strx2
)
19896 str_index
= read_2_bytes (abfd
, info_ptr
);
19899 else if (form
== DW_FORM_strx3
)
19901 str_index
= read_3_bytes (abfd
, info_ptr
);
19904 else if (form
== DW_FORM_strx4
)
19906 str_index
= read_4_bytes (abfd
, info_ptr
);
19911 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19912 info_ptr
+= bytes_read
;
19914 *need_reprocess
= true;
19915 DW_UNSND (attr
) = str_index
;
19919 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19920 dwarf_form_name (form
),
19921 bfd_get_filename (abfd
));
19925 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19926 attr
->form
= DW_FORM_GNU_ref_alt
;
19928 /* We have seen instances where the compiler tried to emit a byte
19929 size attribute of -1 which ended up being encoded as an unsigned
19930 0xffffffff. Although 0xffffffff is technically a valid size value,
19931 an object of this size seems pretty unlikely so we can relatively
19932 safely treat these cases as if the size attribute was invalid and
19933 treat them as zero by default. */
19934 if (attr
->name
== DW_AT_byte_size
19935 && form
== DW_FORM_data4
19936 && DW_UNSND (attr
) >= 0xffffffff)
19939 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19940 hex_string (DW_UNSND (attr
)));
19941 DW_UNSND (attr
) = 0;
19947 /* Read an attribute described by an abbreviated attribute. */
19949 static const gdb_byte
*
19950 read_attribute (const struct die_reader_specs
*reader
,
19951 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19952 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19954 attr
->name
= abbrev
->name
;
19955 attr
->string_is_canonical
= 0;
19956 return read_attribute_value (reader
, attr
, abbrev
->form
,
19957 abbrev
->implicit_const
, info_ptr
,
19961 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19963 static const char *
19964 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
19965 LONGEST str_offset
)
19967 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
19968 str_offset
, "DW_FORM_strp");
19971 /* Return pointer to string at .debug_str offset as read from BUF.
19972 BUF is assumed to be in a compilation unit described by CU_HEADER.
19973 Return *BYTES_READ_PTR count of bytes read from BUF. */
19975 static const char *
19976 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
19977 const gdb_byte
*buf
,
19978 const struct comp_unit_head
*cu_header
,
19979 unsigned int *bytes_read_ptr
)
19981 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19983 return read_indirect_string_at_offset (per_objfile
, str_offset
);
19989 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
19990 const struct comp_unit_head
*cu_header
,
19991 unsigned int *bytes_read_ptr
)
19993 bfd
*abfd
= objfile
->obfd
;
19994 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
19996 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
19999 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20000 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20001 ADDR_SIZE is the size of addresses from the CU header. */
20004 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20005 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20007 struct objfile
*objfile
= per_objfile
->objfile
;
20008 bfd
*abfd
= objfile
->obfd
;
20009 const gdb_byte
*info_ptr
;
20010 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20012 per_objfile
->per_bfd
->addr
.read (objfile
);
20013 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20014 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20015 objfile_name (objfile
));
20016 if (addr_base_or_zero
+ addr_index
* addr_size
20017 >= per_objfile
->per_bfd
->addr
.size
)
20018 error (_("DW_FORM_addr_index pointing outside of "
20019 ".debug_addr section [in module %s]"),
20020 objfile_name (objfile
));
20021 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20022 + addr_index
* addr_size
);
20023 if (addr_size
== 4)
20024 return bfd_get_32 (abfd
, info_ptr
);
20026 return bfd_get_64 (abfd
, info_ptr
);
20029 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20032 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20034 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20035 cu
->addr_base
, cu
->header
.addr_size
);
20038 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20041 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20042 unsigned int *bytes_read
)
20044 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20045 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20047 return read_addr_index (cu
, addr_index
);
20053 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20054 dwarf2_per_objfile
*per_objfile
,
20055 unsigned int addr_index
)
20057 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20058 gdb::optional
<ULONGEST
> addr_base
;
20061 /* We need addr_base and addr_size.
20062 If we don't have PER_CU->cu, we have to get it.
20063 Nasty, but the alternative is storing the needed info in PER_CU,
20064 which at this point doesn't seem justified: it's not clear how frequently
20065 it would get used and it would increase the size of every PER_CU.
20066 Entry points like dwarf2_per_cu_addr_size do a similar thing
20067 so we're not in uncharted territory here.
20068 Alas we need to be a bit more complicated as addr_base is contained
20071 We don't need to read the entire CU(/TU).
20072 We just need the header and top level die.
20074 IWBN to use the aging mechanism to let us lazily later discard the CU.
20075 For now we skip this optimization. */
20079 addr_base
= cu
->addr_base
;
20080 addr_size
= cu
->header
.addr_size
;
20084 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20085 addr_base
= reader
.cu
->addr_base
;
20086 addr_size
= reader
.cu
->header
.addr_size
;
20089 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20092 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20093 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20096 static const char *
20097 read_str_index (struct dwarf2_cu
*cu
,
20098 struct dwarf2_section_info
*str_section
,
20099 struct dwarf2_section_info
*str_offsets_section
,
20100 ULONGEST str_offsets_base
, ULONGEST str_index
)
20102 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20103 struct objfile
*objfile
= per_objfile
->objfile
;
20104 const char *objf_name
= objfile_name (objfile
);
20105 bfd
*abfd
= objfile
->obfd
;
20106 const gdb_byte
*info_ptr
;
20107 ULONGEST str_offset
;
20108 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20110 str_section
->read (objfile
);
20111 str_offsets_section
->read (objfile
);
20112 if (str_section
->buffer
== NULL
)
20113 error (_("%s used without %s section"
20114 " in CU at offset %s [in module %s]"),
20115 form_name
, str_section
->get_name (),
20116 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20117 if (str_offsets_section
->buffer
== NULL
)
20118 error (_("%s used without %s section"
20119 " in CU at offset %s [in module %s]"),
20120 form_name
, str_section
->get_name (),
20121 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20122 info_ptr
= (str_offsets_section
->buffer
20124 + str_index
* cu
->header
.offset_size
);
20125 if (cu
->header
.offset_size
== 4)
20126 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20128 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20129 if (str_offset
>= str_section
->size
)
20130 error (_("Offset from %s pointing outside of"
20131 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20132 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20133 return (const char *) (str_section
->buffer
+ str_offset
);
20136 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20138 static const char *
20139 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20141 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20142 ? reader
->cu
->header
.addr_size
: 0;
20143 return read_str_index (reader
->cu
,
20144 &reader
->dwo_file
->sections
.str
,
20145 &reader
->dwo_file
->sections
.str_offsets
,
20146 str_offsets_base
, str_index
);
20149 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20151 static const char *
20152 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20154 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20155 const char *objf_name
= objfile_name (objfile
);
20156 static const char form_name
[] = "DW_FORM_GNU_str_index";
20157 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20159 if (!cu
->str_offsets_base
.has_value ())
20160 error (_("%s used in Fission stub without %s"
20161 " in CU at offset 0x%lx [in module %s]"),
20162 form_name
, str_offsets_attr_name
,
20163 (long) cu
->header
.offset_size
, objf_name
);
20165 return read_str_index (cu
,
20166 &cu
->per_objfile
->per_bfd
->str
,
20167 &cu
->per_objfile
->per_bfd
->str_offsets
,
20168 *cu
->str_offsets_base
, str_index
);
20171 /* Return the length of an LEB128 number in BUF. */
20174 leb128_size (const gdb_byte
*buf
)
20176 const gdb_byte
*begin
= buf
;
20182 if ((byte
& 128) == 0)
20183 return buf
- begin
;
20188 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20197 cu
->language
= language_c
;
20200 case DW_LANG_C_plus_plus
:
20201 case DW_LANG_C_plus_plus_11
:
20202 case DW_LANG_C_plus_plus_14
:
20203 cu
->language
= language_cplus
;
20206 cu
->language
= language_d
;
20208 case DW_LANG_Fortran77
:
20209 case DW_LANG_Fortran90
:
20210 case DW_LANG_Fortran95
:
20211 case DW_LANG_Fortran03
:
20212 case DW_LANG_Fortran08
:
20213 cu
->language
= language_fortran
;
20216 cu
->language
= language_go
;
20218 case DW_LANG_Mips_Assembler
:
20219 cu
->language
= language_asm
;
20221 case DW_LANG_Ada83
:
20222 case DW_LANG_Ada95
:
20223 cu
->language
= language_ada
;
20225 case DW_LANG_Modula2
:
20226 cu
->language
= language_m2
;
20228 case DW_LANG_Pascal83
:
20229 cu
->language
= language_pascal
;
20232 cu
->language
= language_objc
;
20235 case DW_LANG_Rust_old
:
20236 cu
->language
= language_rust
;
20238 case DW_LANG_Cobol74
:
20239 case DW_LANG_Cobol85
:
20241 cu
->language
= language_minimal
;
20244 cu
->language_defn
= language_def (cu
->language
);
20247 /* Return the named attribute or NULL if not there. */
20249 static struct attribute
*
20250 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20255 struct attribute
*spec
= NULL
;
20257 for (i
= 0; i
< die
->num_attrs
; ++i
)
20259 if (die
->attrs
[i
].name
== name
)
20260 return &die
->attrs
[i
];
20261 if (die
->attrs
[i
].name
== DW_AT_specification
20262 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20263 spec
= &die
->attrs
[i
];
20269 die
= follow_die_ref (die
, spec
, &cu
);
20275 /* Return the string associated with a string-typed attribute, or NULL if it
20276 is either not found or is of an incorrect type. */
20278 static const char *
20279 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20281 struct attribute
*attr
;
20282 const char *str
= NULL
;
20284 attr
= dwarf2_attr (die
, name
, cu
);
20288 str
= attr
->as_string ();
20289 if (str
== nullptr)
20290 complaint (_("string type expected for attribute %s for "
20291 "DIE at %s in module %s"),
20292 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20293 objfile_name (cu
->per_objfile
->objfile
));
20299 /* Return the dwo name or NULL if not present. If present, it is in either
20300 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20301 static const char *
20302 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20304 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20305 if (dwo_name
== nullptr)
20306 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20310 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20311 and holds a non-zero value. This function should only be used for
20312 DW_FORM_flag or DW_FORM_flag_present attributes. */
20315 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20317 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20319 return (attr
&& DW_UNSND (attr
));
20323 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20325 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20326 which value is non-zero. However, we have to be careful with
20327 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20328 (via dwarf2_flag_true_p) follows this attribute. So we may
20329 end up accidently finding a declaration attribute that belongs
20330 to a different DIE referenced by the specification attribute,
20331 even though the given DIE does not have a declaration attribute. */
20332 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20333 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20336 /* Return the die giving the specification for DIE, if there is
20337 one. *SPEC_CU is the CU containing DIE on input, and the CU
20338 containing the return value on output. If there is no
20339 specification, but there is an abstract origin, that is
20342 static struct die_info
*
20343 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20345 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20348 if (spec_attr
== NULL
)
20349 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20351 if (spec_attr
== NULL
)
20354 return follow_die_ref (die
, spec_attr
, spec_cu
);
20357 /* Stub for free_line_header to match void * callback types. */
20360 free_line_header_voidp (void *arg
)
20362 struct line_header
*lh
= (struct line_header
*) arg
;
20367 /* A convenience function to find the proper .debug_line section for a CU. */
20369 static struct dwarf2_section_info
*
20370 get_debug_line_section (struct dwarf2_cu
*cu
)
20372 struct dwarf2_section_info
*section
;
20373 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20375 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20377 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20378 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20379 else if (cu
->per_cu
->is_dwz
)
20381 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
20383 section
= &dwz
->line
;
20386 section
= &per_objfile
->per_bfd
->line
;
20391 /* Read the statement program header starting at OFFSET in
20392 .debug_line, or .debug_line.dwo. Return a pointer
20393 to a struct line_header, allocated using xmalloc.
20394 Returns NULL if there is a problem reading the header, e.g., if it
20395 has a version we don't understand.
20397 NOTE: the strings in the include directory and file name tables of
20398 the returned object point into the dwarf line section buffer,
20399 and must not be freed. */
20401 static line_header_up
20402 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20404 struct dwarf2_section_info
*section
;
20405 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20407 section
= get_debug_line_section (cu
);
20408 section
->read (per_objfile
->objfile
);
20409 if (section
->buffer
== NULL
)
20411 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20412 complaint (_("missing .debug_line.dwo section"));
20414 complaint (_("missing .debug_line section"));
20418 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20419 per_objfile
, section
, &cu
->header
);
20422 /* Subroutine of dwarf_decode_lines to simplify it.
20423 Return the file name of the psymtab for the given file_entry.
20424 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20425 If space for the result is malloc'd, *NAME_HOLDER will be set.
20426 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20428 static const char *
20429 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20430 const dwarf2_psymtab
*pst
,
20431 const char *comp_dir
,
20432 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20434 const char *include_name
= fe
.name
;
20435 const char *include_name_to_compare
= include_name
;
20436 const char *pst_filename
;
20439 const char *dir_name
= fe
.include_dir (lh
);
20441 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20442 if (!IS_ABSOLUTE_PATH (include_name
)
20443 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20445 /* Avoid creating a duplicate psymtab for PST.
20446 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20447 Before we do the comparison, however, we need to account
20448 for DIR_NAME and COMP_DIR.
20449 First prepend dir_name (if non-NULL). If we still don't
20450 have an absolute path prepend comp_dir (if non-NULL).
20451 However, the directory we record in the include-file's
20452 psymtab does not contain COMP_DIR (to match the
20453 corresponding symtab(s)).
20458 bash$ gcc -g ./hello.c
20459 include_name = "hello.c"
20461 DW_AT_comp_dir = comp_dir = "/tmp"
20462 DW_AT_name = "./hello.c"
20466 if (dir_name
!= NULL
)
20468 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20469 include_name
, (char *) NULL
));
20470 include_name
= name_holder
->get ();
20471 include_name_to_compare
= include_name
;
20473 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20475 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20476 include_name
, (char *) NULL
));
20477 include_name_to_compare
= hold_compare
.get ();
20481 pst_filename
= pst
->filename
;
20482 gdb::unique_xmalloc_ptr
<char> copied_name
;
20483 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20485 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20486 pst_filename
, (char *) NULL
));
20487 pst_filename
= copied_name
.get ();
20490 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20494 return include_name
;
20497 /* State machine to track the state of the line number program. */
20499 class lnp_state_machine
20502 /* Initialize a machine state for the start of a line number
20504 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20505 bool record_lines_p
);
20507 file_entry
*current_file ()
20509 /* lh->file_names is 0-based, but the file name numbers in the
20510 statement program are 1-based. */
20511 return m_line_header
->file_name_at (m_file
);
20514 /* Record the line in the state machine. END_SEQUENCE is true if
20515 we're processing the end of a sequence. */
20516 void record_line (bool end_sequence
);
20518 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20519 nop-out rest of the lines in this sequence. */
20520 void check_line_address (struct dwarf2_cu
*cu
,
20521 const gdb_byte
*line_ptr
,
20522 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20524 void handle_set_discriminator (unsigned int discriminator
)
20526 m_discriminator
= discriminator
;
20527 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20530 /* Handle DW_LNE_set_address. */
20531 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20534 address
+= baseaddr
;
20535 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20538 /* Handle DW_LNS_advance_pc. */
20539 void handle_advance_pc (CORE_ADDR adjust
);
20541 /* Handle a special opcode. */
20542 void handle_special_opcode (unsigned char op_code
);
20544 /* Handle DW_LNS_advance_line. */
20545 void handle_advance_line (int line_delta
)
20547 advance_line (line_delta
);
20550 /* Handle DW_LNS_set_file. */
20551 void handle_set_file (file_name_index file
);
20553 /* Handle DW_LNS_negate_stmt. */
20554 void handle_negate_stmt ()
20556 m_is_stmt
= !m_is_stmt
;
20559 /* Handle DW_LNS_const_add_pc. */
20560 void handle_const_add_pc ();
20562 /* Handle DW_LNS_fixed_advance_pc. */
20563 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20565 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20569 /* Handle DW_LNS_copy. */
20570 void handle_copy ()
20572 record_line (false);
20573 m_discriminator
= 0;
20576 /* Handle DW_LNE_end_sequence. */
20577 void handle_end_sequence ()
20579 m_currently_recording_lines
= true;
20583 /* Advance the line by LINE_DELTA. */
20584 void advance_line (int line_delta
)
20586 m_line
+= line_delta
;
20588 if (line_delta
!= 0)
20589 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20592 struct dwarf2_cu
*m_cu
;
20594 gdbarch
*m_gdbarch
;
20596 /* True if we're recording lines.
20597 Otherwise we're building partial symtabs and are just interested in
20598 finding include files mentioned by the line number program. */
20599 bool m_record_lines_p
;
20601 /* The line number header. */
20602 line_header
*m_line_header
;
20604 /* These are part of the standard DWARF line number state machine,
20605 and initialized according to the DWARF spec. */
20607 unsigned char m_op_index
= 0;
20608 /* The line table index of the current file. */
20609 file_name_index m_file
= 1;
20610 unsigned int m_line
= 1;
20612 /* These are initialized in the constructor. */
20614 CORE_ADDR m_address
;
20616 unsigned int m_discriminator
;
20618 /* Additional bits of state we need to track. */
20620 /* The last file that we called dwarf2_start_subfile for.
20621 This is only used for TLLs. */
20622 unsigned int m_last_file
= 0;
20623 /* The last file a line number was recorded for. */
20624 struct subfile
*m_last_subfile
= NULL
;
20626 /* The address of the last line entry. */
20627 CORE_ADDR m_last_address
;
20629 /* Set to true when a previous line at the same address (using
20630 m_last_address) had m_is_stmt true. This is reset to false when a
20631 line entry at a new address (m_address different to m_last_address) is
20633 bool m_stmt_at_address
= false;
20635 /* When true, record the lines we decode. */
20636 bool m_currently_recording_lines
= false;
20638 /* The last line number that was recorded, used to coalesce
20639 consecutive entries for the same line. This can happen, for
20640 example, when discriminators are present. PR 17276. */
20641 unsigned int m_last_line
= 0;
20642 bool m_line_has_non_zero_discriminator
= false;
20646 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20648 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20649 / m_line_header
->maximum_ops_per_instruction
)
20650 * m_line_header
->minimum_instruction_length
);
20651 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20652 m_op_index
= ((m_op_index
+ adjust
)
20653 % m_line_header
->maximum_ops_per_instruction
);
20657 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20659 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20660 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20661 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20662 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20663 / m_line_header
->maximum_ops_per_instruction
)
20664 * m_line_header
->minimum_instruction_length
);
20665 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20666 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20667 % m_line_header
->maximum_ops_per_instruction
);
20669 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20670 advance_line (line_delta
);
20671 record_line (false);
20672 m_discriminator
= 0;
20676 lnp_state_machine::handle_set_file (file_name_index file
)
20680 const file_entry
*fe
= current_file ();
20682 dwarf2_debug_line_missing_file_complaint ();
20683 else if (m_record_lines_p
)
20685 const char *dir
= fe
->include_dir (m_line_header
);
20687 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20688 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20689 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20694 lnp_state_machine::handle_const_add_pc ()
20697 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20700 = (((m_op_index
+ adjust
)
20701 / m_line_header
->maximum_ops_per_instruction
)
20702 * m_line_header
->minimum_instruction_length
);
20704 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20705 m_op_index
= ((m_op_index
+ adjust
)
20706 % m_line_header
->maximum_ops_per_instruction
);
20709 /* Return non-zero if we should add LINE to the line number table.
20710 LINE is the line to add, LAST_LINE is the last line that was added,
20711 LAST_SUBFILE is the subfile for LAST_LINE.
20712 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20713 had a non-zero discriminator.
20715 We have to be careful in the presence of discriminators.
20716 E.g., for this line:
20718 for (i = 0; i < 100000; i++);
20720 clang can emit four line number entries for that one line,
20721 each with a different discriminator.
20722 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20724 However, we want gdb to coalesce all four entries into one.
20725 Otherwise the user could stepi into the middle of the line and
20726 gdb would get confused about whether the pc really was in the
20727 middle of the line.
20729 Things are further complicated by the fact that two consecutive
20730 line number entries for the same line is a heuristic used by gcc
20731 to denote the end of the prologue. So we can't just discard duplicate
20732 entries, we have to be selective about it. The heuristic we use is
20733 that we only collapse consecutive entries for the same line if at least
20734 one of those entries has a non-zero discriminator. PR 17276.
20736 Note: Addresses in the line number state machine can never go backwards
20737 within one sequence, thus this coalescing is ok. */
20740 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20741 unsigned int line
, unsigned int last_line
,
20742 int line_has_non_zero_discriminator
,
20743 struct subfile
*last_subfile
)
20745 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20747 if (line
!= last_line
)
20749 /* Same line for the same file that we've seen already.
20750 As a last check, for pr 17276, only record the line if the line
20751 has never had a non-zero discriminator. */
20752 if (!line_has_non_zero_discriminator
)
20757 /* Use the CU's builder to record line number LINE beginning at
20758 address ADDRESS in the line table of subfile SUBFILE. */
20761 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20762 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20763 struct dwarf2_cu
*cu
)
20765 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20767 if (dwarf_line_debug
)
20769 fprintf_unfiltered (gdb_stdlog
,
20770 "Recording line %u, file %s, address %s\n",
20771 line
, lbasename (subfile
->name
),
20772 paddress (gdbarch
, address
));
20776 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20779 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20780 Mark the end of a set of line number records.
20781 The arguments are the same as for dwarf_record_line_1.
20782 If SUBFILE is NULL the request is ignored. */
20785 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20786 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20788 if (subfile
== NULL
)
20791 if (dwarf_line_debug
)
20793 fprintf_unfiltered (gdb_stdlog
,
20794 "Finishing current line, file %s, address %s\n",
20795 lbasename (subfile
->name
),
20796 paddress (gdbarch
, address
));
20799 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20803 lnp_state_machine::record_line (bool end_sequence
)
20805 if (dwarf_line_debug
)
20807 fprintf_unfiltered (gdb_stdlog
,
20808 "Processing actual line %u: file %u,"
20809 " address %s, is_stmt %u, discrim %u%s\n",
20811 paddress (m_gdbarch
, m_address
),
20812 m_is_stmt
, m_discriminator
,
20813 (end_sequence
? "\t(end sequence)" : ""));
20816 file_entry
*fe
= current_file ();
20819 dwarf2_debug_line_missing_file_complaint ();
20820 /* For now we ignore lines not starting on an instruction boundary.
20821 But not when processing end_sequence for compatibility with the
20822 previous version of the code. */
20823 else if (m_op_index
== 0 || end_sequence
)
20825 fe
->included_p
= 1;
20826 if (m_record_lines_p
)
20828 /* When we switch files we insert an end maker in the first file,
20829 switch to the second file and add a new line entry. The
20830 problem is that the end marker inserted in the first file will
20831 discard any previous line entries at the same address. If the
20832 line entries in the first file are marked as is-stmt, while
20833 the new line in the second file is non-stmt, then this means
20834 the end marker will discard is-stmt lines so we can have a
20835 non-stmt line. This means that there are less addresses at
20836 which the user can insert a breakpoint.
20838 To improve this we track the last address in m_last_address,
20839 and whether we have seen an is-stmt at this address. Then
20840 when switching files, if we have seen a stmt at the current
20841 address, and we are switching to create a non-stmt line, then
20842 discard the new line. */
20844 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
20845 bool ignore_this_line
20846 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
20847 && !m_is_stmt
&& m_stmt_at_address
)
20848 || (!end_sequence
&& m_line
== 0));
20850 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
20852 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20853 m_currently_recording_lines
? m_cu
: nullptr);
20856 if (!end_sequence
&& !ignore_this_line
)
20858 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20860 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20861 m_line_has_non_zero_discriminator
,
20864 buildsym_compunit
*builder
= m_cu
->get_builder ();
20865 dwarf_record_line_1 (m_gdbarch
,
20866 builder
->get_current_subfile (),
20867 m_line
, m_address
, is_stmt
,
20868 m_currently_recording_lines
? m_cu
: nullptr);
20870 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20871 m_last_line
= m_line
;
20876 /* Track whether we have seen any m_is_stmt true at m_address in case we
20877 have multiple line table entries all at m_address. */
20878 if (m_last_address
!= m_address
)
20880 m_stmt_at_address
= false;
20881 m_last_address
= m_address
;
20883 m_stmt_at_address
|= m_is_stmt
;
20886 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20887 line_header
*lh
, bool record_lines_p
)
20891 m_record_lines_p
= record_lines_p
;
20892 m_line_header
= lh
;
20894 m_currently_recording_lines
= true;
20896 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20897 was a line entry for it so that the backend has a chance to adjust it
20898 and also record it in case it needs it. This is currently used by MIPS
20899 code, cf. `mips_adjust_dwarf2_line'. */
20900 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20901 m_is_stmt
= lh
->default_is_stmt
;
20902 m_discriminator
= 0;
20904 m_last_address
= m_address
;
20905 m_stmt_at_address
= false;
20909 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20910 const gdb_byte
*line_ptr
,
20911 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20913 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
20914 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
20915 located at 0x0. In this case, additionally check that if
20916 ADDRESS < UNRELOCATED_LOWPC. */
20918 if ((address
== 0 && address
< unrelocated_lowpc
)
20919 || address
== (CORE_ADDR
) -1)
20921 /* This line table is for a function which has been
20922 GCd by the linker. Ignore it. PR gdb/12528 */
20924 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20925 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20927 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20928 line_offset
, objfile_name (objfile
));
20929 m_currently_recording_lines
= false;
20930 /* Note: m_currently_recording_lines is left as false until we see
20931 DW_LNE_end_sequence. */
20935 /* Subroutine of dwarf_decode_lines to simplify it.
20936 Process the line number information in LH.
20937 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20938 program in order to set included_p for every referenced header. */
20941 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20942 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20944 const gdb_byte
*line_ptr
, *extended_end
;
20945 const gdb_byte
*line_end
;
20946 unsigned int bytes_read
, extended_len
;
20947 unsigned char op_code
, extended_op
;
20948 CORE_ADDR baseaddr
;
20949 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20950 bfd
*abfd
= objfile
->obfd
;
20951 struct gdbarch
*gdbarch
= objfile
->arch ();
20952 /* True if we're recording line info (as opposed to building partial
20953 symtabs and just interested in finding include files mentioned by
20954 the line number program). */
20955 bool record_lines_p
= !decode_for_pst_p
;
20957 baseaddr
= objfile
->text_section_offset ();
20959 line_ptr
= lh
->statement_program_start
;
20960 line_end
= lh
->statement_program_end
;
20962 /* Read the statement sequences until there's nothing left. */
20963 while (line_ptr
< line_end
)
20965 /* The DWARF line number program state machine. Reset the state
20966 machine at the start of each sequence. */
20967 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20968 bool end_sequence
= false;
20970 if (record_lines_p
)
20972 /* Start a subfile for the current file of the state
20974 const file_entry
*fe
= state_machine
.current_file ();
20977 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20980 /* Decode the table. */
20981 while (line_ptr
< line_end
&& !end_sequence
)
20983 op_code
= read_1_byte (abfd
, line_ptr
);
20986 if (op_code
>= lh
->opcode_base
)
20988 /* Special opcode. */
20989 state_machine
.handle_special_opcode (op_code
);
20991 else switch (op_code
)
20993 case DW_LNS_extended_op
:
20994 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20996 line_ptr
+= bytes_read
;
20997 extended_end
= line_ptr
+ extended_len
;
20998 extended_op
= read_1_byte (abfd
, line_ptr
);
21000 if (DW_LNE_lo_user
<= extended_op
21001 && extended_op
<= DW_LNE_hi_user
)
21003 /* Vendor extension, ignore. */
21004 line_ptr
= extended_end
;
21007 switch (extended_op
)
21009 case DW_LNE_end_sequence
:
21010 state_machine
.handle_end_sequence ();
21011 end_sequence
= true;
21013 case DW_LNE_set_address
:
21016 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21017 line_ptr
+= bytes_read
;
21019 state_machine
.check_line_address (cu
, line_ptr
,
21020 lowpc
- baseaddr
, address
);
21021 state_machine
.handle_set_address (baseaddr
, address
);
21024 case DW_LNE_define_file
:
21026 const char *cur_file
;
21027 unsigned int mod_time
, length
;
21030 cur_file
= read_direct_string (abfd
, line_ptr
,
21032 line_ptr
+= bytes_read
;
21033 dindex
= (dir_index
)
21034 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21035 line_ptr
+= bytes_read
;
21037 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21038 line_ptr
+= bytes_read
;
21040 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21041 line_ptr
+= bytes_read
;
21042 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21045 case DW_LNE_set_discriminator
:
21047 /* The discriminator is not interesting to the
21048 debugger; just ignore it. We still need to
21049 check its value though:
21050 if there are consecutive entries for the same
21051 (non-prologue) line we want to coalesce them.
21054 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21055 line_ptr
+= bytes_read
;
21057 state_machine
.handle_set_discriminator (discr
);
21061 complaint (_("mangled .debug_line section"));
21064 /* Make sure that we parsed the extended op correctly. If e.g.
21065 we expected a different address size than the producer used,
21066 we may have read the wrong number of bytes. */
21067 if (line_ptr
!= extended_end
)
21069 complaint (_("mangled .debug_line section"));
21074 state_machine
.handle_copy ();
21076 case DW_LNS_advance_pc
:
21079 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21080 line_ptr
+= bytes_read
;
21082 state_machine
.handle_advance_pc (adjust
);
21085 case DW_LNS_advance_line
:
21088 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21089 line_ptr
+= bytes_read
;
21091 state_machine
.handle_advance_line (line_delta
);
21094 case DW_LNS_set_file
:
21096 file_name_index file
21097 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21099 line_ptr
+= bytes_read
;
21101 state_machine
.handle_set_file (file
);
21104 case DW_LNS_set_column
:
21105 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21106 line_ptr
+= bytes_read
;
21108 case DW_LNS_negate_stmt
:
21109 state_machine
.handle_negate_stmt ();
21111 case DW_LNS_set_basic_block
:
21113 /* Add to the address register of the state machine the
21114 address increment value corresponding to special opcode
21115 255. I.e., this value is scaled by the minimum
21116 instruction length since special opcode 255 would have
21117 scaled the increment. */
21118 case DW_LNS_const_add_pc
:
21119 state_machine
.handle_const_add_pc ();
21121 case DW_LNS_fixed_advance_pc
:
21123 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21126 state_machine
.handle_fixed_advance_pc (addr_adj
);
21131 /* Unknown standard opcode, ignore it. */
21134 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21136 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21137 line_ptr
+= bytes_read
;
21144 dwarf2_debug_line_missing_end_sequence_complaint ();
21146 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21147 in which case we still finish recording the last line). */
21148 state_machine
.record_line (true);
21152 /* Decode the Line Number Program (LNP) for the given line_header
21153 structure and CU. The actual information extracted and the type
21154 of structures created from the LNP depends on the value of PST.
21156 1. If PST is NULL, then this procedure uses the data from the program
21157 to create all necessary symbol tables, and their linetables.
21159 2. If PST is not NULL, this procedure reads the program to determine
21160 the list of files included by the unit represented by PST, and
21161 builds all the associated partial symbol tables.
21163 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21164 It is used for relative paths in the line table.
21165 NOTE: When processing partial symtabs (pst != NULL),
21166 comp_dir == pst->dirname.
21168 NOTE: It is important that psymtabs have the same file name (via strcmp)
21169 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21170 symtab we don't use it in the name of the psymtabs we create.
21171 E.g. expand_line_sal requires this when finding psymtabs to expand.
21172 A good testcase for this is mb-inline.exp.
21174 LOWPC is the lowest address in CU (or 0 if not known).
21176 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21177 for its PC<->lines mapping information. Otherwise only the filename
21178 table is read in. */
21181 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21182 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21183 CORE_ADDR lowpc
, int decode_mapping
)
21185 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21186 const int decode_for_pst_p
= (pst
!= NULL
);
21188 if (decode_mapping
)
21189 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21191 if (decode_for_pst_p
)
21193 /* Now that we're done scanning the Line Header Program, we can
21194 create the psymtab of each included file. */
21195 for (auto &file_entry
: lh
->file_names ())
21196 if (file_entry
.included_p
== 1)
21198 gdb::unique_xmalloc_ptr
<char> name_holder
;
21199 const char *include_name
=
21200 psymtab_include_file_name (lh
, file_entry
, pst
,
21201 comp_dir
, &name_holder
);
21202 if (include_name
!= NULL
)
21203 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21208 /* Make sure a symtab is created for every file, even files
21209 which contain only variables (i.e. no code with associated
21211 buildsym_compunit
*builder
= cu
->get_builder ();
21212 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21214 for (auto &fe
: lh
->file_names ())
21216 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21217 if (builder
->get_current_subfile ()->symtab
== NULL
)
21219 builder
->get_current_subfile ()->symtab
21220 = allocate_symtab (cust
,
21221 builder
->get_current_subfile ()->name
);
21223 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21228 /* Start a subfile for DWARF. FILENAME is the name of the file and
21229 DIRNAME the name of the source directory which contains FILENAME
21230 or NULL if not known.
21231 This routine tries to keep line numbers from identical absolute and
21232 relative file names in a common subfile.
21234 Using the `list' example from the GDB testsuite, which resides in
21235 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21236 of /srcdir/list0.c yields the following debugging information for list0.c:
21238 DW_AT_name: /srcdir/list0.c
21239 DW_AT_comp_dir: /compdir
21240 files.files[0].name: list0.h
21241 files.files[0].dir: /srcdir
21242 files.files[1].name: list0.c
21243 files.files[1].dir: /srcdir
21245 The line number information for list0.c has to end up in a single
21246 subfile, so that `break /srcdir/list0.c:1' works as expected.
21247 start_subfile will ensure that this happens provided that we pass the
21248 concatenation of files.files[1].dir and files.files[1].name as the
21252 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21253 const char *dirname
)
21255 gdb::unique_xmalloc_ptr
<char> copy
;
21257 /* In order not to lose the line information directory,
21258 we concatenate it to the filename when it makes sense.
21259 Note that the Dwarf3 standard says (speaking of filenames in line
21260 information): ``The directory index is ignored for file names
21261 that represent full path names''. Thus ignoring dirname in the
21262 `else' branch below isn't an issue. */
21264 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21266 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21267 filename
= copy
.get ();
21270 cu
->get_builder ()->start_subfile (filename
);
21273 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21274 buildsym_compunit constructor. */
21276 struct compunit_symtab
*
21277 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21280 gdb_assert (m_builder
== nullptr);
21282 m_builder
.reset (new struct buildsym_compunit
21283 (this->per_objfile
->objfile
,
21284 name
, comp_dir
, language
, low_pc
));
21286 list_in_scope
= get_builder ()->get_file_symbols ();
21288 get_builder ()->record_debugformat ("DWARF 2");
21289 get_builder ()->record_producer (producer
);
21291 processing_has_namespace_info
= false;
21293 return get_builder ()->get_compunit_symtab ();
21297 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21298 struct dwarf2_cu
*cu
)
21300 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21301 struct comp_unit_head
*cu_header
= &cu
->header
;
21303 /* NOTE drow/2003-01-30: There used to be a comment and some special
21304 code here to turn a symbol with DW_AT_external and a
21305 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21306 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21307 with some versions of binutils) where shared libraries could have
21308 relocations against symbols in their debug information - the
21309 minimal symbol would have the right address, but the debug info
21310 would not. It's no longer necessary, because we will explicitly
21311 apply relocations when we read in the debug information now. */
21313 /* A DW_AT_location attribute with no contents indicates that a
21314 variable has been optimized away. */
21315 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21317 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21321 /* Handle one degenerate form of location expression specially, to
21322 preserve GDB's previous behavior when section offsets are
21323 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21324 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21326 if (attr
->form_is_block ())
21328 struct dwarf_block
*block
= attr
->as_block ();
21330 if ((block
->data
[0] == DW_OP_addr
21331 && block
->size
== 1 + cu_header
->addr_size
)
21332 || ((block
->data
[0] == DW_OP_GNU_addr_index
21333 || block
->data
[0] == DW_OP_addrx
)
21335 == 1 + leb128_size (&block
->data
[1]))))
21337 unsigned int dummy
;
21339 if (block
->data
[0] == DW_OP_addr
)
21340 SET_SYMBOL_VALUE_ADDRESS
21341 (sym
, cu
->header
.read_address (objfile
->obfd
,
21345 SET_SYMBOL_VALUE_ADDRESS
21346 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21348 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21349 fixup_symbol_section (sym
, objfile
);
21350 SET_SYMBOL_VALUE_ADDRESS
21352 SYMBOL_VALUE_ADDRESS (sym
)
21353 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21358 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21359 expression evaluator, and use LOC_COMPUTED only when necessary
21360 (i.e. when the value of a register or memory location is
21361 referenced, or a thread-local block, etc.). Then again, it might
21362 not be worthwhile. I'm assuming that it isn't unless performance
21363 or memory numbers show me otherwise. */
21365 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21367 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21368 cu
->has_loclist
= true;
21371 /* Given a pointer to a DWARF information entry, figure out if we need
21372 to make a symbol table entry for it, and if so, create a new entry
21373 and return a pointer to it.
21374 If TYPE is NULL, determine symbol type from the die, otherwise
21375 used the passed type.
21376 If SPACE is not NULL, use it to hold the new symbol. If it is
21377 NULL, allocate a new symbol on the objfile's obstack. */
21379 static struct symbol
*
21380 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21381 struct symbol
*space
)
21383 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21384 struct objfile
*objfile
= per_objfile
->objfile
;
21385 struct gdbarch
*gdbarch
= objfile
->arch ();
21386 struct symbol
*sym
= NULL
;
21388 struct attribute
*attr
= NULL
;
21389 struct attribute
*attr2
= NULL
;
21390 CORE_ADDR baseaddr
;
21391 struct pending
**list_to_add
= NULL
;
21393 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21395 baseaddr
= objfile
->text_section_offset ();
21397 name
= dwarf2_name (die
, cu
);
21400 int suppress_add
= 0;
21405 sym
= new (&objfile
->objfile_obstack
) symbol
;
21406 OBJSTAT (objfile
, n_syms
++);
21408 /* Cache this symbol's name and the name's demangled form (if any). */
21409 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21410 /* Fortran does not have mangling standard and the mangling does differ
21411 between gfortran, iFort etc. */
21412 const char *physname
21413 = (cu
->language
== language_fortran
21414 ? dwarf2_full_name (name
, die
, cu
)
21415 : dwarf2_physname (name
, die
, cu
));
21416 const char *linkagename
= dw2_linkage_name (die
, cu
);
21418 if (linkagename
== nullptr || cu
->language
== language_ada
)
21419 sym
->set_linkage_name (physname
);
21422 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21423 sym
->set_linkage_name (linkagename
);
21426 /* Default assumptions.
21427 Use the passed type or decode it from the die. */
21428 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21429 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21431 SYMBOL_TYPE (sym
) = type
;
21433 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21434 attr
= dwarf2_attr (die
,
21435 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21437 if (attr
!= nullptr)
21439 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21442 attr
= dwarf2_attr (die
,
21443 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21445 if (attr
!= nullptr)
21447 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21448 struct file_entry
*fe
;
21450 if (cu
->line_header
!= NULL
)
21451 fe
= cu
->line_header
->file_name_at (file_index
);
21456 complaint (_("file index out of range"));
21458 symbol_set_symtab (sym
, fe
->symtab
);
21464 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21465 if (attr
!= nullptr)
21469 addr
= attr
->as_address ();
21470 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21471 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21472 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21475 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21476 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21477 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21478 add_symbol_to_list (sym
, cu
->list_in_scope
);
21480 case DW_TAG_subprogram
:
21481 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21483 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21484 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21485 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21486 || cu
->language
== language_ada
21487 || cu
->language
== language_fortran
)
21489 /* Subprograms marked external are stored as a global symbol.
21490 Ada and Fortran subprograms, whether marked external or
21491 not, are always stored as a global symbol, because we want
21492 to be able to access them globally. For instance, we want
21493 to be able to break on a nested subprogram without having
21494 to specify the context. */
21495 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21499 list_to_add
= cu
->list_in_scope
;
21502 case DW_TAG_inlined_subroutine
:
21503 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21505 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21506 SYMBOL_INLINED (sym
) = 1;
21507 list_to_add
= cu
->list_in_scope
;
21509 case DW_TAG_template_value_param
:
21511 /* Fall through. */
21512 case DW_TAG_constant
:
21513 case DW_TAG_variable
:
21514 case DW_TAG_member
:
21515 /* Compilation with minimal debug info may result in
21516 variables with missing type entries. Change the
21517 misleading `void' type to something sensible. */
21518 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21519 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21521 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21522 /* In the case of DW_TAG_member, we should only be called for
21523 static const members. */
21524 if (die
->tag
== DW_TAG_member
)
21526 /* dwarf2_add_field uses die_is_declaration,
21527 so we do the same. */
21528 gdb_assert (die_is_declaration (die
, cu
));
21531 if (attr
!= nullptr)
21533 dwarf2_const_value (attr
, sym
, cu
);
21534 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21537 if (attr2
&& (DW_UNSND (attr2
) != 0))
21538 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21540 list_to_add
= cu
->list_in_scope
;
21544 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21545 if (attr
!= nullptr)
21547 var_decode_location (attr
, sym
, cu
);
21548 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21550 /* Fortran explicitly imports any global symbols to the local
21551 scope by DW_TAG_common_block. */
21552 if (cu
->language
== language_fortran
&& die
->parent
21553 && die
->parent
->tag
== DW_TAG_common_block
)
21556 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21557 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21558 && !per_objfile
->per_bfd
->has_section_at_zero
)
21560 /* When a static variable is eliminated by the linker,
21561 the corresponding debug information is not stripped
21562 out, but the variable address is set to null;
21563 do not add such variables into symbol table. */
21565 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21567 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21568 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21569 && per_objfile
->per_bfd
->can_copy
)
21571 /* A global static variable might be subject to
21572 copy relocation. We first check for a local
21573 minsym, though, because maybe the symbol was
21574 marked hidden, in which case this would not
21576 bound_minimal_symbol found
21577 = (lookup_minimal_symbol_linkage
21578 (sym
->linkage_name (), objfile
));
21579 if (found
.minsym
!= nullptr)
21580 sym
->maybe_copied
= 1;
21583 /* A variable with DW_AT_external is never static,
21584 but it may be block-scoped. */
21586 = ((cu
->list_in_scope
21587 == cu
->get_builder ()->get_file_symbols ())
21588 ? cu
->get_builder ()->get_global_symbols ()
21589 : cu
->list_in_scope
);
21592 list_to_add
= cu
->list_in_scope
;
21596 /* We do not know the address of this symbol.
21597 If it is an external symbol and we have type information
21598 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21599 The address of the variable will then be determined from
21600 the minimal symbol table whenever the variable is
21602 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21604 /* Fortran explicitly imports any global symbols to the local
21605 scope by DW_TAG_common_block. */
21606 if (cu
->language
== language_fortran
&& die
->parent
21607 && die
->parent
->tag
== DW_TAG_common_block
)
21609 /* SYMBOL_CLASS doesn't matter here because
21610 read_common_block is going to reset it. */
21612 list_to_add
= cu
->list_in_scope
;
21614 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21615 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21617 /* A variable with DW_AT_external is never static, but it
21618 may be block-scoped. */
21620 = ((cu
->list_in_scope
21621 == cu
->get_builder ()->get_file_symbols ())
21622 ? cu
->get_builder ()->get_global_symbols ()
21623 : cu
->list_in_scope
);
21625 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21627 else if (!die_is_declaration (die
, cu
))
21629 /* Use the default LOC_OPTIMIZED_OUT class. */
21630 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21632 list_to_add
= cu
->list_in_scope
;
21636 case DW_TAG_formal_parameter
:
21638 /* If we are inside a function, mark this as an argument. If
21639 not, we might be looking at an argument to an inlined function
21640 when we do not have enough information to show inlined frames;
21641 pretend it's a local variable in that case so that the user can
21643 struct context_stack
*curr
21644 = cu
->get_builder ()->get_current_context_stack ();
21645 if (curr
!= nullptr && curr
->name
!= nullptr)
21646 SYMBOL_IS_ARGUMENT (sym
) = 1;
21647 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21648 if (attr
!= nullptr)
21650 var_decode_location (attr
, sym
, cu
);
21652 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21653 if (attr
!= nullptr)
21655 dwarf2_const_value (attr
, sym
, cu
);
21658 list_to_add
= cu
->list_in_scope
;
21661 case DW_TAG_unspecified_parameters
:
21662 /* From varargs functions; gdb doesn't seem to have any
21663 interest in this information, so just ignore it for now.
21666 case DW_TAG_template_type_param
:
21668 /* Fall through. */
21669 case DW_TAG_class_type
:
21670 case DW_TAG_interface_type
:
21671 case DW_TAG_structure_type
:
21672 case DW_TAG_union_type
:
21673 case DW_TAG_set_type
:
21674 case DW_TAG_enumeration_type
:
21675 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21676 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21679 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21680 really ever be static objects: otherwise, if you try
21681 to, say, break of a class's method and you're in a file
21682 which doesn't mention that class, it won't work unless
21683 the check for all static symbols in lookup_symbol_aux
21684 saves you. See the OtherFileClass tests in
21685 gdb.c++/namespace.exp. */
21689 buildsym_compunit
*builder
= cu
->get_builder ();
21691 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21692 && cu
->language
== language_cplus
21693 ? builder
->get_global_symbols ()
21694 : cu
->list_in_scope
);
21696 /* The semantics of C++ state that "struct foo {
21697 ... }" also defines a typedef for "foo". */
21698 if (cu
->language
== language_cplus
21699 || cu
->language
== language_ada
21700 || cu
->language
== language_d
21701 || cu
->language
== language_rust
)
21703 /* The symbol's name is already allocated along
21704 with this objfile, so we don't need to
21705 duplicate it for the type. */
21706 if (SYMBOL_TYPE (sym
)->name () == 0)
21707 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21712 case DW_TAG_typedef
:
21713 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21714 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21715 list_to_add
= cu
->list_in_scope
;
21717 case DW_TAG_base_type
:
21718 case DW_TAG_subrange_type
:
21719 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21720 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21721 list_to_add
= cu
->list_in_scope
;
21723 case DW_TAG_enumerator
:
21724 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21725 if (attr
!= nullptr)
21727 dwarf2_const_value (attr
, sym
, cu
);
21730 /* NOTE: carlton/2003-11-10: See comment above in the
21731 DW_TAG_class_type, etc. block. */
21734 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21735 && cu
->language
== language_cplus
21736 ? cu
->get_builder ()->get_global_symbols ()
21737 : cu
->list_in_scope
);
21740 case DW_TAG_imported_declaration
:
21741 case DW_TAG_namespace
:
21742 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21743 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21745 case DW_TAG_module
:
21746 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21747 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21748 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21750 case DW_TAG_common_block
:
21751 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21752 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21753 add_symbol_to_list (sym
, cu
->list_in_scope
);
21756 /* Not a tag we recognize. Hopefully we aren't processing
21757 trash data, but since we must specifically ignore things
21758 we don't recognize, there is nothing else we should do at
21760 complaint (_("unsupported tag: '%s'"),
21761 dwarf_tag_name (die
->tag
));
21767 sym
->hash_next
= objfile
->template_symbols
;
21768 objfile
->template_symbols
= sym
;
21769 list_to_add
= NULL
;
21772 if (list_to_add
!= NULL
)
21773 add_symbol_to_list (sym
, list_to_add
);
21775 /* For the benefit of old versions of GCC, check for anonymous
21776 namespaces based on the demangled name. */
21777 if (!cu
->processing_has_namespace_info
21778 && cu
->language
== language_cplus
)
21779 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21784 /* Given an attr with a DW_FORM_dataN value in host byte order,
21785 zero-extend it as appropriate for the symbol's type. The DWARF
21786 standard (v4) is not entirely clear about the meaning of using
21787 DW_FORM_dataN for a constant with a signed type, where the type is
21788 wider than the data. The conclusion of a discussion on the DWARF
21789 list was that this is unspecified. We choose to always zero-extend
21790 because that is the interpretation long in use by GCC. */
21793 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21794 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21796 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21797 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21798 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21799 LONGEST l
= DW_UNSND (attr
);
21801 if (bits
< sizeof (*value
) * 8)
21803 l
&= ((LONGEST
) 1 << bits
) - 1;
21806 else if (bits
== sizeof (*value
) * 8)
21810 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21811 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21818 /* Read a constant value from an attribute. Either set *VALUE, or if
21819 the value does not fit in *VALUE, set *BYTES - either already
21820 allocated on the objfile obstack, or newly allocated on OBSTACK,
21821 or, set *BATON, if we translated the constant to a location
21825 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21826 const char *name
, struct obstack
*obstack
,
21827 struct dwarf2_cu
*cu
,
21828 LONGEST
*value
, const gdb_byte
**bytes
,
21829 struct dwarf2_locexpr_baton
**baton
)
21831 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21832 struct objfile
*objfile
= per_objfile
->objfile
;
21833 struct comp_unit_head
*cu_header
= &cu
->header
;
21834 struct dwarf_block
*blk
;
21835 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21836 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21842 switch (attr
->form
)
21845 case DW_FORM_addrx
:
21846 case DW_FORM_GNU_addr_index
:
21850 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21851 dwarf2_const_value_length_mismatch_complaint (name
,
21852 cu_header
->addr_size
,
21853 TYPE_LENGTH (type
));
21854 /* Symbols of this form are reasonably rare, so we just
21855 piggyback on the existing location code rather than writing
21856 a new implementation of symbol_computed_ops. */
21857 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21858 (*baton
)->per_objfile
= per_objfile
;
21859 (*baton
)->per_cu
= cu
->per_cu
;
21860 gdb_assert ((*baton
)->per_cu
);
21862 (*baton
)->size
= 2 + cu_header
->addr_size
;
21863 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21864 (*baton
)->data
= data
;
21866 data
[0] = DW_OP_addr
;
21867 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21868 byte_order
, DW_ADDR (attr
));
21869 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21872 case DW_FORM_string
:
21875 case DW_FORM_GNU_str_index
:
21876 case DW_FORM_GNU_strp_alt
:
21877 /* The string is already allocated on the objfile obstack, point
21879 *bytes
= (const gdb_byte
*) attr
->as_string ();
21881 case DW_FORM_block1
:
21882 case DW_FORM_block2
:
21883 case DW_FORM_block4
:
21884 case DW_FORM_block
:
21885 case DW_FORM_exprloc
:
21886 case DW_FORM_data16
:
21887 blk
= attr
->as_block ();
21888 if (TYPE_LENGTH (type
) != blk
->size
)
21889 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21890 TYPE_LENGTH (type
));
21891 *bytes
= blk
->data
;
21894 /* The DW_AT_const_value attributes are supposed to carry the
21895 symbol's value "represented as it would be on the target
21896 architecture." By the time we get here, it's already been
21897 converted to host endianness, so we just need to sign- or
21898 zero-extend it as appropriate. */
21899 case DW_FORM_data1
:
21900 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21902 case DW_FORM_data2
:
21903 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21905 case DW_FORM_data4
:
21906 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21908 case DW_FORM_data8
:
21909 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21912 case DW_FORM_sdata
:
21913 case DW_FORM_implicit_const
:
21914 *value
= DW_SND (attr
);
21917 case DW_FORM_udata
:
21918 *value
= DW_UNSND (attr
);
21922 complaint (_("unsupported const value attribute form: '%s'"),
21923 dwarf_form_name (attr
->form
));
21930 /* Copy constant value from an attribute to a symbol. */
21933 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21934 struct dwarf2_cu
*cu
)
21936 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21938 const gdb_byte
*bytes
;
21939 struct dwarf2_locexpr_baton
*baton
;
21941 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21942 sym
->print_name (),
21943 &objfile
->objfile_obstack
, cu
,
21944 &value
, &bytes
, &baton
);
21948 SYMBOL_LOCATION_BATON (sym
) = baton
;
21949 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21951 else if (bytes
!= NULL
)
21953 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21954 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21958 SYMBOL_VALUE (sym
) = value
;
21959 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21963 /* Return the type of the die in question using its DW_AT_type attribute. */
21965 static struct type
*
21966 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21968 struct attribute
*type_attr
;
21970 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21973 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21974 /* A missing DW_AT_type represents a void type. */
21975 return objfile_type (objfile
)->builtin_void
;
21978 return lookup_die_type (die
, type_attr
, cu
);
21981 /* True iff CU's producer generates GNAT Ada auxiliary information
21982 that allows to find parallel types through that information instead
21983 of having to do expensive parallel lookups by type name. */
21986 need_gnat_info (struct dwarf2_cu
*cu
)
21988 /* Assume that the Ada compiler was GNAT, which always produces
21989 the auxiliary information. */
21990 return (cu
->language
== language_ada
);
21993 /* Return the auxiliary type of the die in question using its
21994 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21995 attribute is not present. */
21997 static struct type
*
21998 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22000 struct attribute
*type_attr
;
22002 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22006 return lookup_die_type (die
, type_attr
, cu
);
22009 /* If DIE has a descriptive_type attribute, then set the TYPE's
22010 descriptive type accordingly. */
22013 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22014 struct dwarf2_cu
*cu
)
22016 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22018 if (descriptive_type
)
22020 ALLOCATE_GNAT_AUX_TYPE (type
);
22021 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22025 /* Return the containing type of the die in question using its
22026 DW_AT_containing_type attribute. */
22028 static struct type
*
22029 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22031 struct attribute
*type_attr
;
22032 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22034 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22036 error (_("Dwarf Error: Problem turning containing type into gdb type "
22037 "[in module %s]"), objfile_name (objfile
));
22039 return lookup_die_type (die
, type_attr
, cu
);
22042 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22044 static struct type
*
22045 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22047 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22048 struct objfile
*objfile
= per_objfile
->objfile
;
22051 std::string message
22052 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22053 objfile_name (objfile
),
22054 sect_offset_str (cu
->header
.sect_off
),
22055 sect_offset_str (die
->sect_off
));
22056 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22058 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22061 /* Look up the type of DIE in CU using its type attribute ATTR.
22062 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22063 DW_AT_containing_type.
22064 If there is no type substitute an error marker. */
22066 static struct type
*
22067 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22068 struct dwarf2_cu
*cu
)
22070 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22071 struct objfile
*objfile
= per_objfile
->objfile
;
22072 struct type
*this_type
;
22074 gdb_assert (attr
->name
== DW_AT_type
22075 || attr
->name
== DW_AT_GNAT_descriptive_type
22076 || attr
->name
== DW_AT_containing_type
);
22078 /* First see if we have it cached. */
22080 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22082 struct dwarf2_per_cu_data
*per_cu
;
22083 sect_offset sect_off
= attr
->get_ref_die_offset ();
22085 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22086 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22088 else if (attr
->form_is_ref ())
22090 sect_offset sect_off
= attr
->get_ref_die_offset ();
22092 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22094 else if (attr
->form
== DW_FORM_ref_sig8
)
22096 ULONGEST signature
= DW_SIGNATURE (attr
);
22098 return get_signatured_type (die
, signature
, cu
);
22102 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22103 " at %s [in module %s]"),
22104 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22105 objfile_name (objfile
));
22106 return build_error_marker_type (cu
, die
);
22109 /* If not cached we need to read it in. */
22111 if (this_type
== NULL
)
22113 struct die_info
*type_die
= NULL
;
22114 struct dwarf2_cu
*type_cu
= cu
;
22116 if (attr
->form_is_ref ())
22117 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22118 if (type_die
== NULL
)
22119 return build_error_marker_type (cu
, die
);
22120 /* If we find the type now, it's probably because the type came
22121 from an inter-CU reference and the type's CU got expanded before
22123 this_type
= read_type_die (type_die
, type_cu
);
22126 /* If we still don't have a type use an error marker. */
22128 if (this_type
== NULL
)
22129 return build_error_marker_type (cu
, die
);
22134 /* Return the type in DIE, CU.
22135 Returns NULL for invalid types.
22137 This first does a lookup in die_type_hash,
22138 and only reads the die in if necessary.
22140 NOTE: This can be called when reading in partial or full symbols. */
22142 static struct type
*
22143 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22145 struct type
*this_type
;
22147 this_type
= get_die_type (die
, cu
);
22151 return read_type_die_1 (die
, cu
);
22154 /* Read the type in DIE, CU.
22155 Returns NULL for invalid types. */
22157 static struct type
*
22158 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22160 struct type
*this_type
= NULL
;
22164 case DW_TAG_class_type
:
22165 case DW_TAG_interface_type
:
22166 case DW_TAG_structure_type
:
22167 case DW_TAG_union_type
:
22168 this_type
= read_structure_type (die
, cu
);
22170 case DW_TAG_enumeration_type
:
22171 this_type
= read_enumeration_type (die
, cu
);
22173 case DW_TAG_subprogram
:
22174 case DW_TAG_subroutine_type
:
22175 case DW_TAG_inlined_subroutine
:
22176 this_type
= read_subroutine_type (die
, cu
);
22178 case DW_TAG_array_type
:
22179 this_type
= read_array_type (die
, cu
);
22181 case DW_TAG_set_type
:
22182 this_type
= read_set_type (die
, cu
);
22184 case DW_TAG_pointer_type
:
22185 this_type
= read_tag_pointer_type (die
, cu
);
22187 case DW_TAG_ptr_to_member_type
:
22188 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22190 case DW_TAG_reference_type
:
22191 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22193 case DW_TAG_rvalue_reference_type
:
22194 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22196 case DW_TAG_const_type
:
22197 this_type
= read_tag_const_type (die
, cu
);
22199 case DW_TAG_volatile_type
:
22200 this_type
= read_tag_volatile_type (die
, cu
);
22202 case DW_TAG_restrict_type
:
22203 this_type
= read_tag_restrict_type (die
, cu
);
22205 case DW_TAG_string_type
:
22206 this_type
= read_tag_string_type (die
, cu
);
22208 case DW_TAG_typedef
:
22209 this_type
= read_typedef (die
, cu
);
22211 case DW_TAG_subrange_type
:
22212 this_type
= read_subrange_type (die
, cu
);
22214 case DW_TAG_base_type
:
22215 this_type
= read_base_type (die
, cu
);
22217 case DW_TAG_unspecified_type
:
22218 this_type
= read_unspecified_type (die
, cu
);
22220 case DW_TAG_namespace
:
22221 this_type
= read_namespace_type (die
, cu
);
22223 case DW_TAG_module
:
22224 this_type
= read_module_type (die
, cu
);
22226 case DW_TAG_atomic_type
:
22227 this_type
= read_tag_atomic_type (die
, cu
);
22230 complaint (_("unexpected tag in read_type_die: '%s'"),
22231 dwarf_tag_name (die
->tag
));
22238 /* See if we can figure out if the class lives in a namespace. We do
22239 this by looking for a member function; its demangled name will
22240 contain namespace info, if there is any.
22241 Return the computed name or NULL.
22242 Space for the result is allocated on the objfile's obstack.
22243 This is the full-die version of guess_partial_die_structure_name.
22244 In this case we know DIE has no useful parent. */
22246 static const char *
22247 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22249 struct die_info
*spec_die
;
22250 struct dwarf2_cu
*spec_cu
;
22251 struct die_info
*child
;
22252 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22255 spec_die
= die_specification (die
, &spec_cu
);
22256 if (spec_die
!= NULL
)
22262 for (child
= die
->child
;
22264 child
= child
->sibling
)
22266 if (child
->tag
== DW_TAG_subprogram
)
22268 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22270 if (linkage_name
!= NULL
)
22272 gdb::unique_xmalloc_ptr
<char> actual_name
22273 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22274 const char *name
= NULL
;
22276 if (actual_name
!= NULL
)
22278 const char *die_name
= dwarf2_name (die
, cu
);
22280 if (die_name
!= NULL
22281 && strcmp (die_name
, actual_name
.get ()) != 0)
22283 /* Strip off the class name from the full name.
22284 We want the prefix. */
22285 int die_name_len
= strlen (die_name
);
22286 int actual_name_len
= strlen (actual_name
.get ());
22287 const char *ptr
= actual_name
.get ();
22289 /* Test for '::' as a sanity check. */
22290 if (actual_name_len
> die_name_len
+ 2
22291 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22292 name
= obstack_strndup (
22293 &objfile
->per_bfd
->storage_obstack
,
22294 ptr
, actual_name_len
- die_name_len
- 2);
22305 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22306 prefix part in such case. See
22307 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22309 static const char *
22310 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22312 struct attribute
*attr
;
22315 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22316 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22319 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22322 attr
= dw2_linkage_name_attr (die
, cu
);
22323 const char *attr_name
= attr
->as_string ();
22324 if (attr
== NULL
|| attr_name
== NULL
)
22327 /* dwarf2_name had to be already called. */
22328 gdb_assert (attr
->canonical_string_p ());
22330 /* Strip the base name, keep any leading namespaces/classes. */
22331 base
= strrchr (attr_name
, ':');
22332 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22335 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22336 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22338 &base
[-1] - attr_name
);
22341 /* Return the name of the namespace/class that DIE is defined within,
22342 or "" if we can't tell. The caller should not xfree the result.
22344 For example, if we're within the method foo() in the following
22354 then determine_prefix on foo's die will return "N::C". */
22356 static const char *
22357 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22359 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22360 struct die_info
*parent
, *spec_die
;
22361 struct dwarf2_cu
*spec_cu
;
22362 struct type
*parent_type
;
22363 const char *retval
;
22365 if (cu
->language
!= language_cplus
22366 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22367 && cu
->language
!= language_rust
)
22370 retval
= anonymous_struct_prefix (die
, cu
);
22374 /* We have to be careful in the presence of DW_AT_specification.
22375 For example, with GCC 3.4, given the code
22379 // Definition of N::foo.
22383 then we'll have a tree of DIEs like this:
22385 1: DW_TAG_compile_unit
22386 2: DW_TAG_namespace // N
22387 3: DW_TAG_subprogram // declaration of N::foo
22388 4: DW_TAG_subprogram // definition of N::foo
22389 DW_AT_specification // refers to die #3
22391 Thus, when processing die #4, we have to pretend that we're in
22392 the context of its DW_AT_specification, namely the contex of die
22395 spec_die
= die_specification (die
, &spec_cu
);
22396 if (spec_die
== NULL
)
22397 parent
= die
->parent
;
22400 parent
= spec_die
->parent
;
22404 if (parent
== NULL
)
22406 else if (parent
->building_fullname
)
22409 const char *parent_name
;
22411 /* It has been seen on RealView 2.2 built binaries,
22412 DW_TAG_template_type_param types actually _defined_ as
22413 children of the parent class:
22416 template class <class Enum> Class{};
22417 Class<enum E> class_e;
22419 1: DW_TAG_class_type (Class)
22420 2: DW_TAG_enumeration_type (E)
22421 3: DW_TAG_enumerator (enum1:0)
22422 3: DW_TAG_enumerator (enum2:1)
22424 2: DW_TAG_template_type_param
22425 DW_AT_type DW_FORM_ref_udata (E)
22427 Besides being broken debug info, it can put GDB into an
22428 infinite loop. Consider:
22430 When we're building the full name for Class<E>, we'll start
22431 at Class, and go look over its template type parameters,
22432 finding E. We'll then try to build the full name of E, and
22433 reach here. We're now trying to build the full name of E,
22434 and look over the parent DIE for containing scope. In the
22435 broken case, if we followed the parent DIE of E, we'd again
22436 find Class, and once again go look at its template type
22437 arguments, etc., etc. Simply don't consider such parent die
22438 as source-level parent of this die (it can't be, the language
22439 doesn't allow it), and break the loop here. */
22440 name
= dwarf2_name (die
, cu
);
22441 parent_name
= dwarf2_name (parent
, cu
);
22442 complaint (_("template param type '%s' defined within parent '%s'"),
22443 name
? name
: "<unknown>",
22444 parent_name
? parent_name
: "<unknown>");
22448 switch (parent
->tag
)
22450 case DW_TAG_namespace
:
22451 parent_type
= read_type_die (parent
, cu
);
22452 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22453 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22454 Work around this problem here. */
22455 if (cu
->language
== language_cplus
22456 && strcmp (parent_type
->name (), "::") == 0)
22458 /* We give a name to even anonymous namespaces. */
22459 return parent_type
->name ();
22460 case DW_TAG_class_type
:
22461 case DW_TAG_interface_type
:
22462 case DW_TAG_structure_type
:
22463 case DW_TAG_union_type
:
22464 case DW_TAG_module
:
22465 parent_type
= read_type_die (parent
, cu
);
22466 if (parent_type
->name () != NULL
)
22467 return parent_type
->name ();
22469 /* An anonymous structure is only allowed non-static data
22470 members; no typedefs, no member functions, et cetera.
22471 So it does not need a prefix. */
22473 case DW_TAG_compile_unit
:
22474 case DW_TAG_partial_unit
:
22475 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22476 if (cu
->language
== language_cplus
22477 && !per_objfile
->per_bfd
->types
.empty ()
22478 && die
->child
!= NULL
22479 && (die
->tag
== DW_TAG_class_type
22480 || die
->tag
== DW_TAG_structure_type
22481 || die
->tag
== DW_TAG_union_type
))
22483 const char *name
= guess_full_die_structure_name (die
, cu
);
22488 case DW_TAG_subprogram
:
22489 /* Nested subroutines in Fortran get a prefix with the name
22490 of the parent's subroutine. */
22491 if (cu
->language
== language_fortran
)
22493 if ((die
->tag
== DW_TAG_subprogram
)
22494 && (dwarf2_name (parent
, cu
) != NULL
))
22495 return dwarf2_name (parent
, cu
);
22497 return determine_prefix (parent
, cu
);
22498 case DW_TAG_enumeration_type
:
22499 parent_type
= read_type_die (parent
, cu
);
22500 if (TYPE_DECLARED_CLASS (parent_type
))
22502 if (parent_type
->name () != NULL
)
22503 return parent_type
->name ();
22506 /* Fall through. */
22508 return determine_prefix (parent
, cu
);
22512 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22513 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22514 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22515 an obconcat, otherwise allocate storage for the result. The CU argument is
22516 used to determine the language and hence, the appropriate separator. */
22518 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22521 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22522 int physname
, struct dwarf2_cu
*cu
)
22524 const char *lead
= "";
22527 if (suffix
== NULL
|| suffix
[0] == '\0'
22528 || prefix
== NULL
|| prefix
[0] == '\0')
22530 else if (cu
->language
== language_d
)
22532 /* For D, the 'main' function could be defined in any module, but it
22533 should never be prefixed. */
22534 if (strcmp (suffix
, "D main") == 0)
22542 else if (cu
->language
== language_fortran
&& physname
)
22544 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22545 DW_AT_MIPS_linkage_name is preferred and used instead. */
22553 if (prefix
== NULL
)
22555 if (suffix
== NULL
)
22562 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22564 strcpy (retval
, lead
);
22565 strcat (retval
, prefix
);
22566 strcat (retval
, sep
);
22567 strcat (retval
, suffix
);
22572 /* We have an obstack. */
22573 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22577 /* Get name of a die, return NULL if not found. */
22579 static const char *
22580 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22581 struct objfile
*objfile
)
22583 if (name
&& cu
->language
== language_cplus
)
22585 gdb::unique_xmalloc_ptr
<char> canon_name
22586 = cp_canonicalize_string (name
);
22588 if (canon_name
!= nullptr)
22589 name
= objfile
->intern (canon_name
.get ());
22595 /* Get name of a die, return NULL if not found.
22596 Anonymous namespaces are converted to their magic string. */
22598 static const char *
22599 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22601 struct attribute
*attr
;
22602 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22604 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22605 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22606 if (attr_name
== nullptr
22607 && die
->tag
!= DW_TAG_namespace
22608 && die
->tag
!= DW_TAG_class_type
22609 && die
->tag
!= DW_TAG_interface_type
22610 && die
->tag
!= DW_TAG_structure_type
22611 && die
->tag
!= DW_TAG_union_type
)
22616 case DW_TAG_compile_unit
:
22617 case DW_TAG_partial_unit
:
22618 /* Compilation units have a DW_AT_name that is a filename, not
22619 a source language identifier. */
22620 case DW_TAG_enumeration_type
:
22621 case DW_TAG_enumerator
:
22622 /* These tags always have simple identifiers already; no need
22623 to canonicalize them. */
22626 case DW_TAG_namespace
:
22627 if (attr_name
!= nullptr)
22629 return CP_ANONYMOUS_NAMESPACE_STR
;
22631 case DW_TAG_class_type
:
22632 case DW_TAG_interface_type
:
22633 case DW_TAG_structure_type
:
22634 case DW_TAG_union_type
:
22635 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22636 structures or unions. These were of the form "._%d" in GCC 4.1,
22637 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22638 and GCC 4.4. We work around this problem by ignoring these. */
22639 if (attr_name
!= nullptr
22640 && (startswith (attr_name
, "._")
22641 || startswith (attr_name
, "<anonymous")))
22644 /* GCC might emit a nameless typedef that has a linkage name. See
22645 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22646 if (!attr
|| attr_name
== NULL
)
22648 attr
= dw2_linkage_name_attr (die
, cu
);
22649 if (attr
== NULL
|| attr_name
== NULL
)
22652 /* Avoid demangling attr_name the second time on a second
22653 call for the same DIE. */
22654 if (!attr
->canonical_string_p ())
22656 gdb::unique_xmalloc_ptr
<char> demangled
22657 (gdb_demangle (attr_name
, DMGL_TYPES
));
22658 if (demangled
== nullptr)
22661 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22664 /* Strip any leading namespaces/classes, keep only the
22665 base name. DW_AT_name for named DIEs does not
22666 contain the prefixes. */
22667 const char *base
= strrchr (attr_name
, ':');
22668 if (base
&& base
> attr_name
&& base
[-1] == ':')
22679 if (!attr
->canonical_string_p ())
22680 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22682 return attr
->as_string ();
22685 /* Return the die that this die in an extension of, or NULL if there
22686 is none. *EXT_CU is the CU containing DIE on input, and the CU
22687 containing the return value on output. */
22689 static struct die_info
*
22690 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22692 struct attribute
*attr
;
22694 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22698 return follow_die_ref (die
, attr
, ext_cu
);
22702 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22706 print_spaces (indent
, f
);
22707 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22708 dwarf_tag_name (die
->tag
), die
->abbrev
,
22709 sect_offset_str (die
->sect_off
));
22711 if (die
->parent
!= NULL
)
22713 print_spaces (indent
, f
);
22714 fprintf_unfiltered (f
, " parent at offset: %s\n",
22715 sect_offset_str (die
->parent
->sect_off
));
22718 print_spaces (indent
, f
);
22719 fprintf_unfiltered (f
, " has children: %s\n",
22720 dwarf_bool_name (die
->child
!= NULL
));
22722 print_spaces (indent
, f
);
22723 fprintf_unfiltered (f
, " attributes:\n");
22725 for (i
= 0; i
< die
->num_attrs
; ++i
)
22727 print_spaces (indent
, f
);
22728 fprintf_unfiltered (f
, " %s (%s) ",
22729 dwarf_attr_name (die
->attrs
[i
].name
),
22730 dwarf_form_name (die
->attrs
[i
].form
));
22732 switch (die
->attrs
[i
].form
)
22735 case DW_FORM_addrx
:
22736 case DW_FORM_GNU_addr_index
:
22737 fprintf_unfiltered (f
, "address: ");
22738 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22740 case DW_FORM_block2
:
22741 case DW_FORM_block4
:
22742 case DW_FORM_block
:
22743 case DW_FORM_block1
:
22744 fprintf_unfiltered (f
, "block: size %s",
22745 pulongest (die
->attrs
[i
].as_block ()->size
));
22747 case DW_FORM_exprloc
:
22748 fprintf_unfiltered (f
, "expression: size %s",
22749 pulongest (die
->attrs
[i
].as_block ()->size
));
22751 case DW_FORM_data16
:
22752 fprintf_unfiltered (f
, "constant of 16 bytes");
22754 case DW_FORM_ref_addr
:
22755 fprintf_unfiltered (f
, "ref address: ");
22756 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22758 case DW_FORM_GNU_ref_alt
:
22759 fprintf_unfiltered (f
, "alt ref address: ");
22760 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22766 case DW_FORM_ref_udata
:
22767 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22768 (long) (DW_UNSND (&die
->attrs
[i
])));
22770 case DW_FORM_data1
:
22771 case DW_FORM_data2
:
22772 case DW_FORM_data4
:
22773 case DW_FORM_data8
:
22774 case DW_FORM_udata
:
22775 case DW_FORM_sdata
:
22776 fprintf_unfiltered (f
, "constant: %s",
22777 pulongest (DW_UNSND (&die
->attrs
[i
])));
22779 case DW_FORM_sec_offset
:
22780 fprintf_unfiltered (f
, "section offset: %s",
22781 pulongest (DW_UNSND (&die
->attrs
[i
])));
22783 case DW_FORM_ref_sig8
:
22784 fprintf_unfiltered (f
, "signature: %s",
22785 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22787 case DW_FORM_string
:
22789 case DW_FORM_line_strp
:
22791 case DW_FORM_GNU_str_index
:
22792 case DW_FORM_GNU_strp_alt
:
22793 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22794 die
->attrs
[i
].as_string ()
22795 ? die
->attrs
[i
].as_string () : "",
22796 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
22799 if (DW_UNSND (&die
->attrs
[i
]))
22800 fprintf_unfiltered (f
, "flag: TRUE");
22802 fprintf_unfiltered (f
, "flag: FALSE");
22804 case DW_FORM_flag_present
:
22805 fprintf_unfiltered (f
, "flag: TRUE");
22807 case DW_FORM_indirect
:
22808 /* The reader will have reduced the indirect form to
22809 the "base form" so this form should not occur. */
22810 fprintf_unfiltered (f
,
22811 "unexpected attribute form: DW_FORM_indirect");
22813 case DW_FORM_implicit_const
:
22814 fprintf_unfiltered (f
, "constant: %s",
22815 plongest (DW_SND (&die
->attrs
[i
])));
22818 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22819 die
->attrs
[i
].form
);
22822 fprintf_unfiltered (f
, "\n");
22827 dump_die_for_error (struct die_info
*die
)
22829 dump_die_shallow (gdb_stderr
, 0, die
);
22833 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22835 int indent
= level
* 4;
22837 gdb_assert (die
!= NULL
);
22839 if (level
>= max_level
)
22842 dump_die_shallow (f
, indent
, die
);
22844 if (die
->child
!= NULL
)
22846 print_spaces (indent
, f
);
22847 fprintf_unfiltered (f
, " Children:");
22848 if (level
+ 1 < max_level
)
22850 fprintf_unfiltered (f
, "\n");
22851 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22855 fprintf_unfiltered (f
,
22856 " [not printed, max nesting level reached]\n");
22860 if (die
->sibling
!= NULL
&& level
> 0)
22862 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22866 /* This is called from the pdie macro in gdbinit.in.
22867 It's not static so gcc will keep a copy callable from gdb. */
22870 dump_die (struct die_info
*die
, int max_level
)
22872 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22876 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22880 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22881 to_underlying (die
->sect_off
),
22887 /* Follow reference or signature attribute ATTR of SRC_DIE.
22888 On entry *REF_CU is the CU of SRC_DIE.
22889 On exit *REF_CU is the CU of the result. */
22891 static struct die_info
*
22892 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22893 struct dwarf2_cu
**ref_cu
)
22895 struct die_info
*die
;
22897 if (attr
->form_is_ref ())
22898 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22899 else if (attr
->form
== DW_FORM_ref_sig8
)
22900 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22903 dump_die_for_error (src_die
);
22904 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22905 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
22911 /* Follow reference OFFSET.
22912 On entry *REF_CU is the CU of the source die referencing OFFSET.
22913 On exit *REF_CU is the CU of the result.
22914 Returns NULL if OFFSET is invalid. */
22916 static struct die_info
*
22917 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22918 struct dwarf2_cu
**ref_cu
)
22920 struct die_info temp_die
;
22921 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22922 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22924 gdb_assert (cu
->per_cu
!= NULL
);
22928 if (cu
->per_cu
->is_debug_types
)
22930 /* .debug_types CUs cannot reference anything outside their CU.
22931 If they need to, they have to reference a signatured type via
22932 DW_FORM_ref_sig8. */
22933 if (!cu
->header
.offset_in_cu_p (sect_off
))
22936 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22937 || !cu
->header
.offset_in_cu_p (sect_off
))
22939 struct dwarf2_per_cu_data
*per_cu
;
22941 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22944 /* If necessary, add it to the queue and load its DIEs. */
22945 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
22946 load_full_comp_unit (per_cu
, per_objfile
, false, cu
->language
);
22948 target_cu
= per_objfile
->get_cu (per_cu
);
22950 else if (cu
->dies
== NULL
)
22952 /* We're loading full DIEs during partial symbol reading. */
22953 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
22954 load_full_comp_unit (cu
->per_cu
, per_objfile
, false, language_minimal
);
22957 *ref_cu
= target_cu
;
22958 temp_die
.sect_off
= sect_off
;
22960 if (target_cu
!= cu
)
22961 target_cu
->ancestor
= cu
;
22963 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22965 to_underlying (sect_off
));
22968 /* Follow reference attribute ATTR of SRC_DIE.
22969 On entry *REF_CU is the CU of SRC_DIE.
22970 On exit *REF_CU is the CU of the result. */
22972 static struct die_info
*
22973 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22974 struct dwarf2_cu
**ref_cu
)
22976 sect_offset sect_off
= attr
->get_ref_die_offset ();
22977 struct dwarf2_cu
*cu
= *ref_cu
;
22978 struct die_info
*die
;
22980 die
= follow_die_offset (sect_off
,
22981 (attr
->form
== DW_FORM_GNU_ref_alt
22982 || cu
->per_cu
->is_dwz
),
22985 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22986 "at %s [in module %s]"),
22987 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22988 objfile_name (cu
->per_objfile
->objfile
));
22995 struct dwarf2_locexpr_baton
22996 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22997 dwarf2_per_cu_data
*per_cu
,
22998 dwarf2_per_objfile
*per_objfile
,
22999 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23000 bool resolve_abstract_p
)
23002 struct die_info
*die
;
23003 struct attribute
*attr
;
23004 struct dwarf2_locexpr_baton retval
;
23005 struct objfile
*objfile
= per_objfile
->objfile
;
23007 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23009 cu
= load_cu (per_cu
, per_objfile
, false);
23013 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23014 Instead just throw an error, not much else we can do. */
23015 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23016 sect_offset_str (sect_off
), objfile_name (objfile
));
23019 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23021 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23022 sect_offset_str (sect_off
), objfile_name (objfile
));
23024 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23025 if (!attr
&& resolve_abstract_p
23026 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23027 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23029 CORE_ADDR pc
= get_frame_pc ();
23030 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23031 struct gdbarch
*gdbarch
= objfile
->arch ();
23033 for (const auto &cand_off
23034 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23036 struct dwarf2_cu
*cand_cu
= cu
;
23037 struct die_info
*cand
23038 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23041 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23044 CORE_ADDR pc_low
, pc_high
;
23045 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23046 if (pc_low
== ((CORE_ADDR
) -1))
23048 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23049 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23050 if (!(pc_low
<= pc
&& pc
< pc_high
))
23054 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23061 /* DWARF: "If there is no such attribute, then there is no effect.".
23062 DATA is ignored if SIZE is 0. */
23064 retval
.data
= NULL
;
23067 else if (attr
->form_is_section_offset ())
23069 struct dwarf2_loclist_baton loclist_baton
;
23070 CORE_ADDR pc
= get_frame_pc ();
23073 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23075 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23077 retval
.size
= size
;
23081 if (!attr
->form_is_block ())
23082 error (_("Dwarf Error: DIE at %s referenced in module %s "
23083 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23084 sect_offset_str (sect_off
), objfile_name (objfile
));
23086 struct dwarf_block
*block
= attr
->as_block ();
23087 retval
.data
= block
->data
;
23088 retval
.size
= block
->size
;
23090 retval
.per_objfile
= per_objfile
;
23091 retval
.per_cu
= cu
->per_cu
;
23093 per_objfile
->age_comp_units ();
23100 struct dwarf2_locexpr_baton
23101 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23102 dwarf2_per_cu_data
*per_cu
,
23103 dwarf2_per_objfile
*per_objfile
,
23104 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23106 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23108 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23112 /* Write a constant of a given type as target-ordered bytes into
23115 static const gdb_byte
*
23116 write_constant_as_bytes (struct obstack
*obstack
,
23117 enum bfd_endian byte_order
,
23124 *len
= TYPE_LENGTH (type
);
23125 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23126 store_unsigned_integer (result
, *len
, byte_order
, value
);
23134 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23135 dwarf2_per_cu_data
*per_cu
,
23136 dwarf2_per_objfile
*per_objfile
,
23140 struct die_info
*die
;
23141 struct attribute
*attr
;
23142 const gdb_byte
*result
= NULL
;
23145 enum bfd_endian byte_order
;
23146 struct objfile
*objfile
= per_objfile
->objfile
;
23148 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23150 cu
= load_cu (per_cu
, per_objfile
, false);
23154 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23155 Instead just throw an error, not much else we can do. */
23156 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23157 sect_offset_str (sect_off
), objfile_name (objfile
));
23160 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23162 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23163 sect_offset_str (sect_off
), objfile_name (objfile
));
23165 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23169 byte_order
= (bfd_big_endian (objfile
->obfd
)
23170 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23172 switch (attr
->form
)
23175 case DW_FORM_addrx
:
23176 case DW_FORM_GNU_addr_index
:
23180 *len
= cu
->header
.addr_size
;
23181 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23182 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23186 case DW_FORM_string
:
23189 case DW_FORM_GNU_str_index
:
23190 case DW_FORM_GNU_strp_alt
:
23191 /* The string is already allocated on the objfile obstack, point
23194 const char *attr_name
= attr
->as_string ();
23195 result
= (const gdb_byte
*) attr_name
;
23196 *len
= strlen (attr_name
);
23199 case DW_FORM_block1
:
23200 case DW_FORM_block2
:
23201 case DW_FORM_block4
:
23202 case DW_FORM_block
:
23203 case DW_FORM_exprloc
:
23204 case DW_FORM_data16
:
23206 struct dwarf_block
*block
= attr
->as_block ();
23207 result
= block
->data
;
23208 *len
= block
->size
;
23212 /* The DW_AT_const_value attributes are supposed to carry the
23213 symbol's value "represented as it would be on the target
23214 architecture." By the time we get here, it's already been
23215 converted to host endianness, so we just need to sign- or
23216 zero-extend it as appropriate. */
23217 case DW_FORM_data1
:
23218 type
= die_type (die
, cu
);
23219 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23220 if (result
== NULL
)
23221 result
= write_constant_as_bytes (obstack
, byte_order
,
23224 case DW_FORM_data2
:
23225 type
= die_type (die
, cu
);
23226 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23227 if (result
== NULL
)
23228 result
= write_constant_as_bytes (obstack
, byte_order
,
23231 case DW_FORM_data4
:
23232 type
= die_type (die
, cu
);
23233 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23234 if (result
== NULL
)
23235 result
= write_constant_as_bytes (obstack
, byte_order
,
23238 case DW_FORM_data8
:
23239 type
= die_type (die
, cu
);
23240 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23241 if (result
== NULL
)
23242 result
= write_constant_as_bytes (obstack
, byte_order
,
23246 case DW_FORM_sdata
:
23247 case DW_FORM_implicit_const
:
23248 type
= die_type (die
, cu
);
23249 result
= write_constant_as_bytes (obstack
, byte_order
,
23250 type
, DW_SND (attr
), len
);
23253 case DW_FORM_udata
:
23254 type
= die_type (die
, cu
);
23255 result
= write_constant_as_bytes (obstack
, byte_order
,
23256 type
, DW_UNSND (attr
), len
);
23260 complaint (_("unsupported const value attribute form: '%s'"),
23261 dwarf_form_name (attr
->form
));
23271 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23272 dwarf2_per_cu_data
*per_cu
,
23273 dwarf2_per_objfile
*per_objfile
)
23275 struct die_info
*die
;
23277 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23279 cu
= load_cu (per_cu
, per_objfile
, false);
23284 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23288 return die_type (die
, cu
);
23294 dwarf2_get_die_type (cu_offset die_offset
,
23295 dwarf2_per_cu_data
*per_cu
,
23296 dwarf2_per_objfile
*per_objfile
)
23298 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23299 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23302 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23303 On entry *REF_CU is the CU of SRC_DIE.
23304 On exit *REF_CU is the CU of the result.
23305 Returns NULL if the referenced DIE isn't found. */
23307 static struct die_info
*
23308 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23309 struct dwarf2_cu
**ref_cu
)
23311 struct die_info temp_die
;
23312 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23313 struct die_info
*die
;
23314 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23317 /* While it might be nice to assert sig_type->type == NULL here,
23318 we can get here for DW_AT_imported_declaration where we need
23319 the DIE not the type. */
23321 /* If necessary, add it to the queue and load its DIEs. */
23323 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
23325 read_signatured_type (sig_type
, per_objfile
);
23327 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
23328 gdb_assert (sig_cu
!= NULL
);
23329 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23330 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23331 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23332 to_underlying (temp_die
.sect_off
));
23335 /* For .gdb_index version 7 keep track of included TUs.
23336 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23337 if (per_objfile
->per_bfd
->index_table
!= NULL
23338 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23340 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23345 sig_cu
->ancestor
= cu
;
23353 /* Follow signatured type referenced by ATTR in SRC_DIE.
23354 On entry *REF_CU is the CU of SRC_DIE.
23355 On exit *REF_CU is the CU of the result.
23356 The result is the DIE of the type.
23357 If the referenced type cannot be found an error is thrown. */
23359 static struct die_info
*
23360 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23361 struct dwarf2_cu
**ref_cu
)
23363 ULONGEST signature
= DW_SIGNATURE (attr
);
23364 struct signatured_type
*sig_type
;
23365 struct die_info
*die
;
23367 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23369 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23370 /* sig_type will be NULL if the signatured type is missing from
23372 if (sig_type
== NULL
)
23374 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23375 " from DIE at %s [in module %s]"),
23376 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23377 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23380 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23383 dump_die_for_error (src_die
);
23384 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23385 " from DIE at %s [in module %s]"),
23386 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23387 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23393 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23394 reading in and processing the type unit if necessary. */
23396 static struct type
*
23397 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23398 struct dwarf2_cu
*cu
)
23400 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23401 struct signatured_type
*sig_type
;
23402 struct dwarf2_cu
*type_cu
;
23403 struct die_info
*type_die
;
23406 sig_type
= lookup_signatured_type (cu
, signature
);
23407 /* sig_type will be NULL if the signatured type is missing from
23409 if (sig_type
== NULL
)
23411 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23412 " from DIE at %s [in module %s]"),
23413 hex_string (signature
), sect_offset_str (die
->sect_off
),
23414 objfile_name (per_objfile
->objfile
));
23415 return build_error_marker_type (cu
, die
);
23418 /* If we already know the type we're done. */
23419 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23420 if (type
!= nullptr)
23424 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23425 if (type_die
!= NULL
)
23427 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23428 is created. This is important, for example, because for c++ classes
23429 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23430 type
= read_type_die (type_die
, type_cu
);
23433 complaint (_("Dwarf Error: Cannot build signatured type %s"
23434 " referenced from DIE at %s [in module %s]"),
23435 hex_string (signature
), sect_offset_str (die
->sect_off
),
23436 objfile_name (per_objfile
->objfile
));
23437 type
= build_error_marker_type (cu
, die
);
23442 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23443 " from DIE at %s [in module %s]"),
23444 hex_string (signature
), sect_offset_str (die
->sect_off
),
23445 objfile_name (per_objfile
->objfile
));
23446 type
= build_error_marker_type (cu
, die
);
23449 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23454 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23455 reading in and processing the type unit if necessary. */
23457 static struct type
*
23458 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23459 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23461 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23462 if (attr
->form_is_ref ())
23464 struct dwarf2_cu
*type_cu
= cu
;
23465 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23467 return read_type_die (type_die
, type_cu
);
23469 else if (attr
->form
== DW_FORM_ref_sig8
)
23471 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23475 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23477 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23478 " at %s [in module %s]"),
23479 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23480 objfile_name (per_objfile
->objfile
));
23481 return build_error_marker_type (cu
, die
);
23485 /* Load the DIEs associated with type unit PER_CU into memory. */
23488 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23489 dwarf2_per_objfile
*per_objfile
)
23491 struct signatured_type
*sig_type
;
23493 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23494 gdb_assert (! per_cu
->type_unit_group_p ());
23496 /* We have the per_cu, but we need the signatured_type.
23497 Fortunately this is an easy translation. */
23498 gdb_assert (per_cu
->is_debug_types
);
23499 sig_type
= (struct signatured_type
*) per_cu
;
23501 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23503 read_signatured_type (sig_type
, per_objfile
);
23505 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23508 /* Read in a signatured type and build its CU and DIEs.
23509 If the type is a stub for the real type in a DWO file,
23510 read in the real type from the DWO file as well. */
23513 read_signatured_type (signatured_type
*sig_type
,
23514 dwarf2_per_objfile
*per_objfile
)
23516 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23518 gdb_assert (per_cu
->is_debug_types
);
23519 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23521 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
23523 if (!reader
.dummy_p
)
23525 struct dwarf2_cu
*cu
= reader
.cu
;
23526 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23528 gdb_assert (cu
->die_hash
== NULL
);
23530 htab_create_alloc_ex (cu
->header
.length
/ 12,
23534 &cu
->comp_unit_obstack
,
23535 hashtab_obstack_allocate
,
23536 dummy_obstack_deallocate
);
23538 if (reader
.comp_unit_die
->has_children
)
23539 reader
.comp_unit_die
->child
23540 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23541 reader
.comp_unit_die
);
23542 cu
->dies
= reader
.comp_unit_die
;
23543 /* comp_unit_die is not stored in die_hash, no need. */
23545 /* We try not to read any attributes in this function, because
23546 not all CUs needed for references have been loaded yet, and
23547 symbol table processing isn't initialized. But we have to
23548 set the CU language, or we won't be able to build types
23549 correctly. Similarly, if we do not read the producer, we can
23550 not apply producer-specific interpretation. */
23551 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23556 sig_type
->per_cu
.tu_read
= 1;
23559 /* Decode simple location descriptions.
23560 Given a pointer to a dwarf block that defines a location, compute
23561 the location and return the value. If COMPUTED is non-null, it is
23562 set to true to indicate that decoding was successful, and false
23563 otherwise. If COMPUTED is null, then this function may emit a
23567 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23569 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23571 size_t size
= blk
->size
;
23572 const gdb_byte
*data
= blk
->data
;
23573 CORE_ADDR stack
[64];
23575 unsigned int bytes_read
, unsnd
;
23578 if (computed
!= nullptr)
23584 stack
[++stacki
] = 0;
23623 stack
[++stacki
] = op
- DW_OP_lit0
;
23658 stack
[++stacki
] = op
- DW_OP_reg0
;
23661 if (computed
== nullptr)
23662 dwarf2_complex_location_expr_complaint ();
23669 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23671 stack
[++stacki
] = unsnd
;
23674 if (computed
== nullptr)
23675 dwarf2_complex_location_expr_complaint ();
23682 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23687 case DW_OP_const1u
:
23688 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23692 case DW_OP_const1s
:
23693 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23697 case DW_OP_const2u
:
23698 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23702 case DW_OP_const2s
:
23703 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23707 case DW_OP_const4u
:
23708 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23712 case DW_OP_const4s
:
23713 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23717 case DW_OP_const8u
:
23718 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23723 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23729 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23734 stack
[stacki
+ 1] = stack
[stacki
];
23739 stack
[stacki
- 1] += stack
[stacki
];
23743 case DW_OP_plus_uconst
:
23744 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23750 stack
[stacki
- 1] -= stack
[stacki
];
23755 /* If we're not the last op, then we definitely can't encode
23756 this using GDB's address_class enum. This is valid for partial
23757 global symbols, although the variable's address will be bogus
23761 if (computed
== nullptr)
23762 dwarf2_complex_location_expr_complaint ();
23768 case DW_OP_GNU_push_tls_address
:
23769 case DW_OP_form_tls_address
:
23770 /* The top of the stack has the offset from the beginning
23771 of the thread control block at which the variable is located. */
23772 /* Nothing should follow this operator, so the top of stack would
23774 /* This is valid for partial global symbols, but the variable's
23775 address will be bogus in the psymtab. Make it always at least
23776 non-zero to not look as a variable garbage collected by linker
23777 which have DW_OP_addr 0. */
23780 if (computed
== nullptr)
23781 dwarf2_complex_location_expr_complaint ();
23788 case DW_OP_GNU_uninit
:
23789 if (computed
!= nullptr)
23794 case DW_OP_GNU_addr_index
:
23795 case DW_OP_GNU_const_index
:
23796 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23802 if (computed
== nullptr)
23804 const char *name
= get_DW_OP_name (op
);
23807 complaint (_("unsupported stack op: '%s'"),
23810 complaint (_("unsupported stack op: '%02x'"),
23814 return (stack
[stacki
]);
23817 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23818 outside of the allocated space. Also enforce minimum>0. */
23819 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23821 if (computed
== nullptr)
23822 complaint (_("location description stack overflow"));
23828 if (computed
== nullptr)
23829 complaint (_("location description stack underflow"));
23834 if (computed
!= nullptr)
23836 return (stack
[stacki
]);
23839 /* memory allocation interface */
23841 static struct dwarf_block
*
23842 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23844 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23847 static struct die_info
*
23848 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23850 struct die_info
*die
;
23851 size_t size
= sizeof (struct die_info
);
23854 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23856 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23857 memset (die
, 0, sizeof (struct die_info
));
23863 /* Macro support. */
23865 /* An overload of dwarf_decode_macros that finds the correct section
23866 and ensures it is read in before calling the other overload. */
23869 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23870 int section_is_gnu
)
23872 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23873 struct objfile
*objfile
= per_objfile
->objfile
;
23874 const struct line_header
*lh
= cu
->line_header
;
23875 unsigned int offset_size
= cu
->header
.offset_size
;
23876 struct dwarf2_section_info
*section
;
23877 const char *section_name
;
23879 if (cu
->dwo_unit
!= nullptr)
23881 if (section_is_gnu
)
23883 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23884 section_name
= ".debug_macro.dwo";
23888 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23889 section_name
= ".debug_macinfo.dwo";
23894 if (section_is_gnu
)
23896 section
= &per_objfile
->per_bfd
->macro
;
23897 section_name
= ".debug_macro";
23901 section
= &per_objfile
->per_bfd
->macinfo
;
23902 section_name
= ".debug_macinfo";
23906 section
->read (objfile
);
23907 if (section
->buffer
== nullptr)
23909 complaint (_("missing %s section"), section_name
);
23913 buildsym_compunit
*builder
= cu
->get_builder ();
23915 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
23916 offset_size
, offset
, section_is_gnu
);
23919 /* Return the .debug_loc section to use for CU.
23920 For DWO files use .debug_loc.dwo. */
23922 static struct dwarf2_section_info
*
23923 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23925 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23929 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23931 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23933 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
23934 : &per_objfile
->per_bfd
->loc
);
23937 /* Return the .debug_rnglists section to use for CU. */
23938 static struct dwarf2_section_info
*
23939 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
23941 if (cu
->header
.version
< 5)
23942 error (_(".debug_rnglists section cannot be used in DWARF %d"),
23943 cu
->header
.version
);
23944 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
23946 /* Make sure we read the .debug_rnglists section from the file that
23947 contains the DW_AT_ranges attribute we are reading. Normally that
23948 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
23949 or DW_TAG_skeleton unit, we always want to read from objfile/linked
23951 if (cu
->dwo_unit
!= nullptr
23952 && tag
!= DW_TAG_compile_unit
23953 && tag
!= DW_TAG_skeleton_unit
)
23955 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23957 if (sections
->rnglists
.size
> 0)
23958 return §ions
->rnglists
;
23960 error (_(".debug_rnglists section is missing from .dwo file."));
23962 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
23965 /* A helper function that fills in a dwarf2_loclist_baton. */
23968 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23969 struct dwarf2_loclist_baton
*baton
,
23970 const struct attribute
*attr
)
23972 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23973 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23975 section
->read (per_objfile
->objfile
);
23977 baton
->per_objfile
= per_objfile
;
23978 baton
->per_cu
= cu
->per_cu
;
23979 gdb_assert (baton
->per_cu
);
23980 /* We don't know how long the location list is, but make sure we
23981 don't run off the edge of the section. */
23982 baton
->size
= section
->size
- DW_UNSND (attr
);
23983 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23984 if (cu
->base_address
.has_value ())
23985 baton
->base_address
= *cu
->base_address
;
23987 baton
->base_address
= 0;
23988 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23992 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23993 struct dwarf2_cu
*cu
, int is_block
)
23995 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23996 struct objfile
*objfile
= per_objfile
->objfile
;
23997 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23999 if (attr
->form_is_section_offset ()
24000 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24001 the section. If so, fall through to the complaint in the
24003 && DW_UNSND (attr
) < section
->get_size (objfile
))
24005 struct dwarf2_loclist_baton
*baton
;
24007 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24009 fill_in_loclist_baton (cu
, baton
, attr
);
24011 if (!cu
->base_address
.has_value ())
24012 complaint (_("Location list used without "
24013 "specifying the CU base address."));
24015 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24016 ? dwarf2_loclist_block_index
24017 : dwarf2_loclist_index
);
24018 SYMBOL_LOCATION_BATON (sym
) = baton
;
24022 struct dwarf2_locexpr_baton
*baton
;
24024 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24025 baton
->per_objfile
= per_objfile
;
24026 baton
->per_cu
= cu
->per_cu
;
24027 gdb_assert (baton
->per_cu
);
24029 if (attr
->form_is_block ())
24031 /* Note that we're just copying the block's data pointer
24032 here, not the actual data. We're still pointing into the
24033 info_buffer for SYM's objfile; right now we never release
24034 that buffer, but when we do clean up properly this may
24036 struct dwarf_block
*block
= attr
->as_block ();
24037 baton
->size
= block
->size
;
24038 baton
->data
= block
->data
;
24042 dwarf2_invalid_attrib_class_complaint ("location description",
24043 sym
->natural_name ());
24047 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24048 ? dwarf2_locexpr_block_index
24049 : dwarf2_locexpr_index
);
24050 SYMBOL_LOCATION_BATON (sym
) = baton
;
24056 const comp_unit_head
*
24057 dwarf2_per_cu_data::get_header () const
24059 if (!m_header_read_in
)
24061 const gdb_byte
*info_ptr
24062 = this->section
->buffer
+ to_underlying (this->sect_off
);
24064 memset (&m_header
, 0, sizeof (m_header
));
24066 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24067 rcuh_kind::COMPILE
);
24076 dwarf2_per_cu_data::addr_size () const
24078 return this->get_header ()->addr_size
;
24084 dwarf2_per_cu_data::offset_size () const
24086 return this->get_header ()->offset_size
;
24092 dwarf2_per_cu_data::ref_addr_size () const
24094 const comp_unit_head
*header
= this->get_header ();
24096 if (header
->version
== 2)
24097 return header
->addr_size
;
24099 return header
->offset_size
;
24105 dwarf2_cu::addr_type () const
24107 struct objfile
*objfile
= this->per_objfile
->objfile
;
24108 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24109 struct type
*addr_type
= lookup_pointer_type (void_type
);
24110 int addr_size
= this->per_cu
->addr_size ();
24112 if (TYPE_LENGTH (addr_type
) == addr_size
)
24115 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24119 /* A helper function for dwarf2_find_containing_comp_unit that returns
24120 the index of the result, and that searches a vector. It will
24121 return a result even if the offset in question does not actually
24122 occur in any CU. This is separate so that it can be unit
24126 dwarf2_find_containing_comp_unit
24127 (sect_offset sect_off
,
24128 unsigned int offset_in_dwz
,
24129 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24134 high
= all_comp_units
.size () - 1;
24137 struct dwarf2_per_cu_data
*mid_cu
;
24138 int mid
= low
+ (high
- low
) / 2;
24140 mid_cu
= all_comp_units
[mid
];
24141 if (mid_cu
->is_dwz
> offset_in_dwz
24142 || (mid_cu
->is_dwz
== offset_in_dwz
24143 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24148 gdb_assert (low
== high
);
24152 /* Locate the .debug_info compilation unit from CU's objfile which contains
24153 the DIE at OFFSET. Raises an error on failure. */
24155 static struct dwarf2_per_cu_data
*
24156 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24157 unsigned int offset_in_dwz
,
24158 dwarf2_per_objfile
*per_objfile
)
24160 int low
= dwarf2_find_containing_comp_unit
24161 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24162 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
24164 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24166 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24167 error (_("Dwarf Error: could not find partial DIE containing "
24168 "offset %s [in module %s]"),
24169 sect_offset_str (sect_off
),
24170 bfd_get_filename (per_objfile
->objfile
->obfd
));
24172 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24174 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
24178 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24179 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24180 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24181 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24188 namespace selftests
{
24189 namespace find_containing_comp_unit
{
24194 struct dwarf2_per_cu_data one
{};
24195 struct dwarf2_per_cu_data two
{};
24196 struct dwarf2_per_cu_data three
{};
24197 struct dwarf2_per_cu_data four
{};
24200 two
.sect_off
= sect_offset (one
.length
);
24205 four
.sect_off
= sect_offset (three
.length
);
24209 std::vector
<dwarf2_per_cu_data
*> units
;
24210 units
.push_back (&one
);
24211 units
.push_back (&two
);
24212 units
.push_back (&three
);
24213 units
.push_back (&four
);
24217 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24218 SELF_CHECK (units
[result
] == &one
);
24219 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24220 SELF_CHECK (units
[result
] == &one
);
24221 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24222 SELF_CHECK (units
[result
] == &two
);
24224 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24225 SELF_CHECK (units
[result
] == &three
);
24226 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24227 SELF_CHECK (units
[result
] == &three
);
24228 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24229 SELF_CHECK (units
[result
] == &four
);
24235 #endif /* GDB_SELF_TEST */
24237 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
24239 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
24240 dwarf2_per_objfile
*per_objfile
)
24242 per_objfile (per_objfile
),
24244 has_loclist (false),
24245 checked_producer (false),
24246 producer_is_gxx_lt_4_6 (false),
24247 producer_is_gcc_lt_4_3 (false),
24248 producer_is_icc (false),
24249 producer_is_icc_lt_14 (false),
24250 producer_is_codewarrior (false),
24251 processing_has_namespace_info (false)
24255 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24258 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24259 enum language pretend_language
)
24261 struct attribute
*attr
;
24263 /* Set the language we're debugging. */
24264 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24265 if (attr
!= nullptr)
24266 set_cu_language (DW_UNSND (attr
), cu
);
24269 cu
->language
= pretend_language
;
24270 cu
->language_defn
= language_def (cu
->language
);
24273 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24279 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24281 auto it
= m_dwarf2_cus
.find (per_cu
);
24282 if (it
== m_dwarf2_cus
.end ())
24291 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24293 gdb_assert (this->get_cu (per_cu
) == nullptr);
24295 m_dwarf2_cus
[per_cu
] = cu
;
24301 dwarf2_per_objfile::age_comp_units ()
24303 /* Start by clearing all marks. */
24304 for (auto pair
: m_dwarf2_cus
)
24305 pair
.second
->mark
= false;
24307 /* Traverse all CUs, mark them and their dependencies if used recently
24309 for (auto pair
: m_dwarf2_cus
)
24311 dwarf2_cu
*cu
= pair
.second
;
24314 if (cu
->last_used
<= dwarf_max_cache_age
)
24318 /* Delete all CUs still not marked. */
24319 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24321 dwarf2_cu
*cu
= it
->second
;
24326 it
= m_dwarf2_cus
.erase (it
);
24336 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24338 auto it
= m_dwarf2_cus
.find (per_cu
);
24339 if (it
== m_dwarf2_cus
.end ())
24344 m_dwarf2_cus
.erase (it
);
24347 dwarf2_per_objfile::~dwarf2_per_objfile ()
24352 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24353 We store these in a hash table separate from the DIEs, and preserve them
24354 when the DIEs are flushed out of cache.
24356 The CU "per_cu" pointer is needed because offset alone is not enough to
24357 uniquely identify the type. A file may have multiple .debug_types sections,
24358 or the type may come from a DWO file. Furthermore, while it's more logical
24359 to use per_cu->section+offset, with Fission the section with the data is in
24360 the DWO file but we don't know that section at the point we need it.
24361 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24362 because we can enter the lookup routine, get_die_type_at_offset, from
24363 outside this file, and thus won't necessarily have PER_CU->cu.
24364 Fortunately, PER_CU is stable for the life of the objfile. */
24366 struct dwarf2_per_cu_offset_and_type
24368 const struct dwarf2_per_cu_data
*per_cu
;
24369 sect_offset sect_off
;
24373 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24376 per_cu_offset_and_type_hash (const void *item
)
24378 const struct dwarf2_per_cu_offset_and_type
*ofs
24379 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24381 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24384 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24387 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24389 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24390 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24391 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24392 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24394 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24395 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24398 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24399 table if necessary. For convenience, return TYPE.
24401 The DIEs reading must have careful ordering to:
24402 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24403 reading current DIE.
24404 * Not trying to dereference contents of still incompletely read in types
24405 while reading in other DIEs.
24406 * Enable referencing still incompletely read in types just by a pointer to
24407 the type without accessing its fields.
24409 Therefore caller should follow these rules:
24410 * Try to fetch any prerequisite types we may need to build this DIE type
24411 before building the type and calling set_die_type.
24412 * After building type call set_die_type for current DIE as soon as
24413 possible before fetching more types to complete the current type.
24414 * Make the type as complete as possible before fetching more types. */
24416 static struct type
*
24417 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24419 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24420 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24421 struct objfile
*objfile
= per_objfile
->objfile
;
24422 struct attribute
*attr
;
24423 struct dynamic_prop prop
;
24425 /* For Ada types, make sure that the gnat-specific data is always
24426 initialized (if not already set). There are a few types where
24427 we should not be doing so, because the type-specific area is
24428 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24429 where the type-specific area is used to store the floatformat).
24430 But this is not a problem, because the gnat-specific information
24431 is actually not needed for these types. */
24432 if (need_gnat_info (cu
)
24433 && type
->code () != TYPE_CODE_FUNC
24434 && type
->code () != TYPE_CODE_FLT
24435 && type
->code () != TYPE_CODE_METHODPTR
24436 && type
->code () != TYPE_CODE_MEMBERPTR
24437 && type
->code () != TYPE_CODE_METHOD
24438 && !HAVE_GNAT_AUX_INFO (type
))
24439 INIT_GNAT_SPECIFIC (type
);
24441 /* Read DW_AT_allocated and set in type. */
24442 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24445 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24446 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24447 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24450 /* Read DW_AT_associated and set in type. */
24451 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24454 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24455 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24456 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24459 /* Read DW_AT_data_location and set in type. */
24460 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24461 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24462 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24464 if (per_objfile
->die_type_hash
== NULL
)
24465 per_objfile
->die_type_hash
24466 = htab_up (htab_create_alloc (127,
24467 per_cu_offset_and_type_hash
,
24468 per_cu_offset_and_type_eq
,
24469 NULL
, xcalloc
, xfree
));
24471 ofs
.per_cu
= cu
->per_cu
;
24472 ofs
.sect_off
= die
->sect_off
;
24474 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24475 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24477 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24478 sect_offset_str (die
->sect_off
));
24479 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24480 struct dwarf2_per_cu_offset_and_type
);
24485 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24486 or return NULL if the die does not have a saved type. */
24488 static struct type
*
24489 get_die_type_at_offset (sect_offset sect_off
,
24490 dwarf2_per_cu_data
*per_cu
,
24491 dwarf2_per_objfile
*per_objfile
)
24493 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24495 if (per_objfile
->die_type_hash
== NULL
)
24498 ofs
.per_cu
= per_cu
;
24499 ofs
.sect_off
= sect_off
;
24500 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24501 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24508 /* Look up the type for DIE in CU in die_type_hash,
24509 or return NULL if DIE does not have a saved type. */
24511 static struct type
*
24512 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24514 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24517 /* Add a dependence relationship from CU to REF_PER_CU. */
24520 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24521 struct dwarf2_per_cu_data
*ref_per_cu
)
24525 if (cu
->dependencies
== NULL
)
24527 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24528 NULL
, &cu
->comp_unit_obstack
,
24529 hashtab_obstack_allocate
,
24530 dummy_obstack_deallocate
);
24532 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24534 *slot
= ref_per_cu
;
24537 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24538 Set the mark field in every compilation unit in the
24539 cache that we must keep because we are keeping CU.
24541 DATA is the dwarf2_per_objfile object in which to look up CUs. */
24544 dwarf2_mark_helper (void **slot
, void *data
)
24546 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
24547 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
24548 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
24550 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24551 reading of the chain. As such dependencies remain valid it is not much
24552 useful to track and undo them during QUIT cleanups. */
24561 if (cu
->dependencies
!= nullptr)
24562 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
24567 /* Set the mark field in CU and in every other compilation unit in the
24568 cache that we must keep because we are keeping CU. */
24571 dwarf2_mark (struct dwarf2_cu
*cu
)
24578 if (cu
->dependencies
!= nullptr)
24579 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
24582 /* Trivial hash function for partial_die_info: the hash value of a DIE
24583 is its offset in .debug_info for this objfile. */
24586 partial_die_hash (const void *item
)
24588 const struct partial_die_info
*part_die
24589 = (const struct partial_die_info
*) item
;
24591 return to_underlying (part_die
->sect_off
);
24594 /* Trivial comparison function for partial_die_info structures: two DIEs
24595 are equal if they have the same offset. */
24598 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24600 const struct partial_die_info
*part_die_lhs
24601 = (const struct partial_die_info
*) item_lhs
;
24602 const struct partial_die_info
*part_die_rhs
24603 = (const struct partial_die_info
*) item_rhs
;
24605 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24608 struct cmd_list_element
*set_dwarf_cmdlist
;
24609 struct cmd_list_element
*show_dwarf_cmdlist
;
24612 show_check_physname (struct ui_file
*file
, int from_tty
,
24613 struct cmd_list_element
*c
, const char *value
)
24615 fprintf_filtered (file
,
24616 _("Whether to check \"physname\" is %s.\n"),
24620 void _initialize_dwarf2_read ();
24622 _initialize_dwarf2_read ()
24624 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24625 Set DWARF specific variables.\n\
24626 Configure DWARF variables such as the cache size."),
24627 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24628 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24630 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24631 Show DWARF specific variables.\n\
24632 Show DWARF variables such as the cache size."),
24633 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24634 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24636 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24637 &dwarf_max_cache_age
, _("\
24638 Set the upper bound on the age of cached DWARF compilation units."), _("\
24639 Show the upper bound on the age of cached DWARF compilation units."), _("\
24640 A higher limit means that cached compilation units will be stored\n\
24641 in memory longer, and more total memory will be used. Zero disables\n\
24642 caching, which can slow down startup."),
24644 show_dwarf_max_cache_age
,
24645 &set_dwarf_cmdlist
,
24646 &show_dwarf_cmdlist
);
24648 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24649 Set debugging of the DWARF reader."), _("\
24650 Show debugging of the DWARF reader."), _("\
24651 When enabled (non-zero), debugging messages are printed during DWARF\n\
24652 reading and symtab expansion. A value of 1 (one) provides basic\n\
24653 information. A value greater than 1 provides more verbose information."),
24656 &setdebuglist
, &showdebuglist
);
24658 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24659 Set debugging of the DWARF DIE reader."), _("\
24660 Show debugging of the DWARF DIE reader."), _("\
24661 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24662 The value is the maximum depth to print."),
24665 &setdebuglist
, &showdebuglist
);
24667 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24668 Set debugging of the dwarf line reader."), _("\
24669 Show debugging of the dwarf line reader."), _("\
24670 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24671 A value of 1 (one) provides basic information.\n\
24672 A value greater than 1 provides more verbose information."),
24675 &setdebuglist
, &showdebuglist
);
24677 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24678 Set cross-checking of \"physname\" code against demangler."), _("\
24679 Show cross-checking of \"physname\" code against demangler."), _("\
24680 When enabled, GDB's internal \"physname\" code is checked against\n\
24682 NULL
, show_check_physname
,
24683 &setdebuglist
, &showdebuglist
);
24685 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24686 no_class
, &use_deprecated_index_sections
, _("\
24687 Set whether to use deprecated gdb_index sections."), _("\
24688 Show whether to use deprecated gdb_index sections."), _("\
24689 When enabled, deprecated .gdb_index sections are used anyway.\n\
24690 Normally they are ignored either because of a missing feature or\n\
24691 performance issue.\n\
24692 Warning: This option must be enabled before gdb reads the file."),
24695 &setlist
, &showlist
);
24697 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24698 &dwarf2_locexpr_funcs
);
24699 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24700 &dwarf2_loclist_funcs
);
24702 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24703 &dwarf2_block_frame_base_locexpr_funcs
);
24704 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24705 &dwarf2_block_frame_base_loclist_funcs
);
24708 selftests::register_test ("dw2_expand_symtabs_matching",
24709 selftests::dw2_expand_symtabs_matching::run_test
);
24710 selftests::register_test ("dwarf2_find_containing_comp_unit",
24711 selftests::find_containing_comp_unit::run_test
);